diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingLogic.php index c4f9c917..f9c79326 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingLogic.php @@ -134,7 +134,7 @@ class CreateBookingLogic extends AbstractControllerLogic $voucherify_order_id = ""; $user = $company->employees()->first(); - $createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $company->id, 0, 0, 0, false, false); + $createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $company->id, $booking->id, 0, 0, false, false); $createVoucherufyOrderResult = $this->createsVoucherifyOrder->execute($createVoucherifyOrderObject); if($createVoucherufyOrderResult && isset($createVoucherufyOrderResult->id)){ diff --git a/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php b/app/Classes/Modules/Transactions/Services/UpdatesTransactionStatus.php index d92e3e9a..9c6d76f3 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 c51807e9..5a1e28c8 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 $transactionId; + private $bookingId; /** @var float */ private $amount; @@ -33,17 +33,17 @@ class CreateVoucherifyOrderObject implements DataTransferObject * CreateVoucherifyOrderObject constructor. * @param User $employee * @param int $companyId - * @param int $transactionId + * @param int $bookingId * @param float $amount * @param float $serviceCharge * @param bool $isNoVoucher * @param bool $isTopUpWallet */ - public function __construct(User $employee, int $companyId, int $transactionId, float $amount, float $serviceCharge, bool $isNoVoucher = false, bool $isTopUpWallet = false) + public function __construct(User $employee, int $companyId, int $bookingId, float $amount, float $serviceCharge, bool $isNoVoucher = false, bool $isTopUpWallet = false) { $this->employee = $employee; $this->companyId = $companyId; - $this->transactionId = $transactionId; + $this->bookingId = $bookingId; $this->amount = $amount; $this->serviceCharge = $serviceCharge; $this->isNoVoucher = $isNoVoucher; @@ -61,9 +61,9 @@ class CreateVoucherifyOrderObject implements DataTransferObject /** * @return int */ - public function getTransactionId(): int + public function getBookingId(): int { - return $this->transactionId; + return $this->bookingId; } /** diff --git a/app/Classes/Modules/Vouchers/DataTransferObjects/UpdateVoucherifyOrderObject.php b/app/Classes/Modules/Vouchers/DataTransferObjects/UpdateVoucherifyOrderObject.php index bc49ee86..4d051b69 100644 --- a/app/Classes/Modules/Vouchers/DataTransferObjects/UpdateVoucherifyOrderObject.php +++ b/app/Classes/Modules/Vouchers/DataTransferObjects/UpdateVoucherifyOrderObject.php @@ -8,28 +8,41 @@ use App\Classes\General\Interfaces\DataTransferObject; class UpdateVoucherifyOrderObject implements DataTransferObject { /** @var string */ - private $id; + private $voucherifyOrderId; + + /** @var int */ + private $bookingId; /** @var string */ private $status; /** * UpdateVoucherifyOrderObject constructor. - * @param string $id + * @param string $voucherifyOrderId + * @param int $bookingId * @param string $status */ - public function __construct(string $id, string $status) + public function __construct(string $voucherifyOrderId, int $bookingId, string $status) { - $this->id = $id; + $this->voucherifyOrderId = $voucherifyOrderId; + $this->bookingId = $bookingId; $this->status = $status; } /** * @return string */ - public function getId(): string + public function getVoucherifyOrderId(): string { - return $this->id; + return $this->voucherifyOrderId; + } + + /** + * @return int + */ + public function getBookingId(): int + { + return $this->bookingId; } /** diff --git a/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php b/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php index d78b0dfe..6d8cd82d 100644 --- a/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php +++ b/app/Classes/Modules/Vouchers/Processors/Voucherify/BookingToVoucherifyProcessor.php @@ -145,7 +145,8 @@ class BookingToVoucherifyProcessor $this->recordVoucherForUserInfo($employeeWhoOwnsTheVoucher, $voucher); } else{ - $createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $companyId, $transaction->id, $amount, $transaction->service_charge, true, $transaction->type == TransactionType::TOP_UP); + $booking = $transaction->booking; + $createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $companyId, $booking->id, $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 46dbf7a1..d15f29a0 100644 --- a/app/Classes/Modules/Vouchers/Processors/Voucherify/TransactionToVoucherifyProcessor.php +++ b/app/Classes/Modules/Vouchers/Processors/Voucherify/TransactionToVoucherifyProcessor.php @@ -32,9 +32,10 @@ class TransactionToVoucherifyProcessor public function execute(Transaction $transaction, string $status) { try{ - $voucherify_entity = $transaction->voucherifyEntities()->first(); + $voucherify_entity = $transaction->voucherifyEntities()->first(); //cief todo: 76 could be filtered more precisely to prevent fetching wrong record if($voucherify_entity){ - $updateVoucherifyOrderObject = new UpdateVoucherifyOrderObject($voucherify_entity->voucherify_entity_id, $status); + $booking = $transaction->booking; + $updateVoucherifyOrderObject = new UpdateVoucherifyOrderObject($voucherify_entity->voucherify_entity_id, $booking->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 b6a9a119..d744e06d 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->getTransactionId(), + "source_id" => $obj->getBookingId(), "customer" => [ "source_id" => $obj->getEmployee()->id, "name" => $obj->getEmployee()->name, diff --git a/app/Classes/Modules/Vouchers/Services/Voucherify/RedeemsVoucherifyVoucher.php b/app/Classes/Modules/Vouchers/Services/Voucherify/RedeemsVoucherifyVoucher.php index c17e3e47..46f867da 100644 --- a/app/Classes/Modules/Vouchers/Services/Voucherify/RedeemsVoucherifyVoucher.php +++ b/app/Classes/Modules/Vouchers/Services/Voucherify/RedeemsVoucherifyVoucher.php @@ -41,11 +41,13 @@ class RedeemsVoucherifyVoucher ], "order" => [ "id" => $redeemVoucherifyVoucherObject->getVoucherifyOrderId(), - "source_id" => $redeemVoucherifyVoucherObject->getTransactionId(), - "amount" => $redeemVoucherifyVoucherObject->getAmount() * 100 //converting it to cents + // "source_id" => $redeemVoucherifyVoucherObject->getTransactionId(), //replaced with booking_id + "amount" => $redeemVoucherifyVoucherObject->getAmount() * 100, //converting it to cents ] ]; + $redeemVoucherObject['order']['metadata']['transaction_id'] = $redeemVoucherifyVoucherObject->getTransactionId(); + if ($redeemVoucherifyVoucherObject->getServiceCharge()) { $serviceCharge = round($redeemVoucherifyVoucherObject->getServiceCharge(), 2); $redeemVoucherObject['order']['metadata']['service_charge'] = $serviceCharge; diff --git a/app/Classes/Modules/Vouchers/Services/Voucherify/UpdatesVoucherifyOrder.php b/app/Classes/Modules/Vouchers/Services/Voucherify/UpdatesVoucherifyOrder.php index 51c6c29e..7b36508f 100644 --- a/app/Classes/Modules/Vouchers/Services/Voucherify/UpdatesVoucherifyOrder.php +++ b/app/Classes/Modules/Vouchers/Services/Voucherify/UpdatesVoucherifyOrder.php @@ -31,7 +31,8 @@ class UpdatesVoucherifyOrder { try { $result = $this->voucherifyClient->orders->update([ - "id" => $obj->getId(), + "id" => $obj->getVoucherifyOrderId(), + // "source_id" => $obj->getBookingId(), "status" => $obj->getStatus(), ]); return $result;