New voucher CIEFPC30 setup with new business logic

This commit is contained in:
Dillon Ngo
2024-12-09 07:48:13 +08:00
parent 0e97a46f76
commit a3714176ff
7 changed files with 34 additions and 17 deletions
@@ -44,9 +44,9 @@ class UpdatesTransactionStatus extends AbstractUpdateRecord
$this->transactionToPerfexCRMProcessor->execute($transaction, $status);
}
// if($status == ApprovalStatus::APPROVED && ($transaction->type == TransactionType::PAYMENT || $transaction->type == TransactionType::TOP_UP)){
// $this->transactionToVoucherifyProcessor->execute($transaction, "PAID");
// }
if($status == ApprovalStatus::APPROVED && ($transaction->type == TransactionType::PAYMENT || $transaction->type == TransactionType::TOP_UP)){
$this->transactionToVoucherifyProcessor->execute($transaction, "PAID");
}
return $result;
}
@@ -15,7 +15,7 @@ class CreateVoucherifyOrderObject implements DataTransferObject
private $companyId;
/** @var int */
private $bookingId;
private $ownerId;
/** @var float */
private $amount;
@@ -33,17 +33,17 @@ class CreateVoucherifyOrderObject implements DataTransferObject
* CreateVoucherifyOrderObject constructor.
* @param User $employee
* @param int $companyId
* @param int $bookingId
* @param int $ownerId
* @param float $amount
* @param float $serviceCharge
* @param bool $isNoVoucher
* @param bool $isTopUpWallet
*/
public function __construct(User $employee, int $companyId, int $bookingId, float $amount, float $serviceCharge, bool $isNoVoucher = false, bool $isTopUpWallet = false)
public function __construct(User $employee, int $companyId, int $ownerId, float $amount, float $serviceCharge, bool $isNoVoucher = false, bool $isTopUpWallet = false)
{
$this->employee = $employee;
$this->companyId = $companyId;
$this->bookingId = $bookingId;
$this->ownerId = $ownerId;
$this->amount = $amount;
$this->serviceCharge = $serviceCharge;
$this->isNoVoucher = $isNoVoucher;
@@ -61,9 +61,9 @@ class CreateVoucherifyOrderObject implements DataTransferObject
/**
* @return int
*/
public function getBookingId(): int
public function getOwnerId(): int
{
return $this->bookingId;
return $this->ownerId;
}
/**
@@ -13,6 +13,9 @@ class UpdateVoucherifyOrderObject implements DataTransferObject
/** @var int */
private $bookingId;
/** @var int */
private $transactionId;
/** @var string */
private $status;
@@ -20,12 +23,14 @@ class UpdateVoucherifyOrderObject implements DataTransferObject
* UpdateVoucherifyOrderObject constructor.
* @param string $voucherifyOrderId
* @param int $bookingId
* @param int $transactionId
* @param string $status
*/
public function __construct(string $voucherifyOrderId, int $bookingId, string $status)
public function __construct(string $voucherifyOrderId, int $bookingId, int $transactionId, string $status)
{
$this->voucherifyOrderId = $voucherifyOrderId;
$this->bookingId = $bookingId;
$this->transactionId = $transactionId;
$this->status = $status;
}
@@ -45,6 +50,14 @@ class UpdateVoucherifyOrderObject implements DataTransferObject
return $this->bookingId;
}
/**
* @return int
*/
public function getTransactionId(): int
{
return $this->transactionId;
}
/**
* @return string
*/
@@ -145,8 +145,8 @@ class BookingToVoucherifyProcessor
$this->recordVoucherForUserInfo($employeeWhoOwnsTheVoucher, $voucher);
}
else{
$booking = $transaction->booking;
$createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $companyId, $booking->id, $amount, $transaction->service_charge, true, $transaction->type == TransactionType::TOP_UP);
$ownerId = $transaction->owner->id;
$createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $companyId, $ownerId, $amount, $transaction->service_charge, true, $transaction->type == TransactionType::TOP_UP);
$createVoucherufyOrderResult = $this->createsVoucherifyOrder->execute($createVoucherifyOrderObject);
if($createVoucherufyOrderResult && isset($createVoucherufyOrderResult->id)){
@@ -35,7 +35,7 @@ class TransactionToVoucherifyProcessor
$voucherify_entity = $transaction->voucherifyEntities()->first(); //cief todo: 76 could be filtered more precisely to prevent fetching wrong record
if($voucherify_entity){
$booking = $transaction->booking;
$updateVoucherifyOrderObject = new UpdateVoucherifyOrderObject($voucherify_entity->voucherify_entity_id, $booking->id, $status);
$updateVoucherifyOrderObject = new UpdateVoucherifyOrderObject($voucherify_entity->voucherify_entity_id, $booking->id, $transaction->id, $status);
$this->updatesVoucherifyOrder->execute($updateVoucherifyOrderObject);
}
} catch (\Exception $e) {
@@ -31,7 +31,7 @@ class CreatesVoucherifyOrder
{
try {
$orderObj = [
"source_id" => $obj->getBookingId(),
"source_id" => $obj->getIsTopUpWallet() ? 0 :$obj->getOwnerId(),
"customer" => [
"source_id" => $obj->getEmployee()->id,
"name" => $obj->getEmployee()->name,
@@ -50,6 +50,7 @@ class CreatesVoucherifyOrder
if ($obj->getIsTopUpWallet()) {
$orderObj['metadata']["is_wallet_top_up"] = true;
$orderObj['metadata']["wallet_id"] = $obj->getOwnerId();
}
if ($obj->getServiceCharge()) {
@@ -30,11 +30,14 @@ class UpdatesVoucherifyOrder
public function execute(UpdateVoucherifyOrderObject $obj)
{
try {
$result = $this->voucherifyClient->orders->update([
$updateOrderObject = [
"id" => $obj->getVoucherifyOrderId(),
// "source_id" => $obj->getBookingId(),
"status" => $obj->getStatus(),
]);
];
$updateOrderObject['metadata']['transaction_id'] = $obj->getTransactionId();
$result = $this->voucherifyClient->orders->update($updateOrderObject);
return $result;
} catch (\Voucherify\ClientException $e) {
Log::error('UpdatesVoucherifyOrder '.$e);