New voucher CIEFPC30 setup with new business logic

This commit is contained in:
Dillon Ngo
2024-12-09 06:29:39 +08:00
parent 0ab5ed76a5
commit 0e97a46f76
9 changed files with 41 additions and 23 deletions
@@ -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)){
@@ -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 $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;
}
/**
@@ -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;
}
/**
@@ -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)){
@@ -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) {
@@ -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,
@@ -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;
@@ -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;