diff --git a/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php b/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php index 9c6d76f3..d92e3e9a 100644 --- a/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php +++ b/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php @@ -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; } diff --git a/app/Classes/Modules/Vouchers/DataTransferObjects/CreateVoucherifyOrderObject.php b/app/Classes/Modules/Vouchers/DataTransferObjects/CreateVoucherifyOrderObject.php index 5a1e28c8..c0d02b0e 100644 --- a/app/Classes/Modules/Vouchers/DataTransferObjects/CreateVoucherifyOrderObject.php +++ b/app/Classes/Modules/Vouchers/DataTransferObjects/CreateVoucherifyOrderObject.php @@ -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; } /** diff --git a/app/Classes/Modules/Vouchers/DataTransferObjects/UpdateVoucherifyOrderObject.php b/app/Classes/Modules/Vouchers/DataTransferObjects/UpdateVoucherifyOrderObject.php index 4d051b69..72457b48 100644 --- a/app/Classes/Modules/Vouchers/DataTransferObjects/UpdateVoucherifyOrderObject.php +++ b/app/Classes/Modules/Vouchers/DataTransferObjects/UpdateVoucherifyOrderObject.php @@ -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 */ diff --git a/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php b/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php index 6d8cd82d..216f96c9 100644 --- a/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php +++ b/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php @@ -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)){ diff --git a/app/Classes/Modules/Vouchers/Processors/Voucherify/TransactionToVoucherifyProcessor.php b/app/Classes/Modules/Vouchers/Processors/Voucherify/TransactionToVoucherifyProcessor.php index d15f29a0..34ce2d2d 100644 --- a/app/Classes/Modules/Vouchers/Processors/Voucherify/TransactionToVoucherifyProcessor.php +++ b/app/Classes/Modules/Vouchers/Processors/Voucherify/TransactionToVoucherifyProcessor.php @@ -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) { diff --git a/app/Classes/Modules/Vouchers/Services/Voucherify/CreatesVoucherifyOrder.php b/app/Classes/Modules/Vouchers/Services/Voucherify/CreatesVoucherifyOrder.php index d744e06d..d62be356 100644 --- a/app/Classes/Modules/Vouchers/Services/Voucherify/CreatesVoucherifyOrder.php +++ b/app/Classes/Modules/Vouchers/Services/Voucherify/CreatesVoucherifyOrder.php @@ -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()) { diff --git a/app/Classes/Modules/Vouchers/Services/Voucherify/UpdatesVoucherifyOrder.php b/app/Classes/Modules/Vouchers/Services/Voucherify/UpdatesVoucherifyOrder.php index 7b36508f..5c83f95b 100644 --- a/app/Classes/Modules/Vouchers/Services/Voucherify/UpdatesVoucherifyOrder.php +++ b/app/Classes/Modules/Vouchers/Services/Voucherify/UpdatesVoucherifyOrder.php @@ -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);