mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-27 00:13:59 +00:00
add booking quotation calculation for partial refund request
This commit is contained in:
@@ -5,10 +5,15 @@ namespace App\Classes\Modules\Bookings\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Bookings\Services\FetchesBookingQuotation;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\Modules\Transactions\Services\CalculateTransactionRefundOriginalAmount;
|
||||
use App\Classes\Modules\Transactions\Services\CalculateTransactionRefundAmount;
|
||||
use App\Classes\Modules\Transactions\Services\CalculateTransactionRefundServiceCharge;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyPaymentAttemptLimit;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
@@ -32,12 +37,24 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesBookingQuotation */
|
||||
private $fetchBookingQuotation;
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus;
|
||||
|
||||
/** @var CalculateTransactionRefundOriginalAmount */
|
||||
private $calculateTransactionRefundOriginalAmount;
|
||||
|
||||
/** @var CalculateTransactionRefundAmount */
|
||||
private $calculateTransactionRefundAmount;
|
||||
|
||||
/** @var CalculateTransactionRefundServiceCharge */
|
||||
private $calculateTransactionRefundServiceCharge;
|
||||
|
||||
/** @var FetchesCompanyPaymentAttemptLimit */
|
||||
private $fetchesCompanyPaymentAttemptLimit;
|
||||
|
||||
@@ -49,16 +66,23 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
|
||||
/**
|
||||
* CreateBookingPaymentLogic constructor.
|
||||
* @param FetchesBookingQuotation $fetchBookingQuotation
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param CalculateTransactionRefundOriginalAmount $calculateTransactionRefundOriginalAmount
|
||||
* @param CalculateTransactionRefundServiceCharge $calculateTransactionRefundServiceCharge
|
||||
* @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
*/
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction)
|
||||
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CalculateTransactionRefundOriginalAmount $calculateTransactionRefundOriginalAmount, CalculateTransactionRefundAmount $calculateTransactionRefundAmount, CalculateTransactionRefundServiceCharge $calculateTransactionRefundServiceCharge, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction)
|
||||
{
|
||||
$this->fetchBookingQuotation = $fetchBookingQuotation;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->calculateTransactionRefundOriginalAmount = $calculateTransactionRefundOriginalAmount;
|
||||
$this->calculateTransactionRefundAmount = $calculateTransactionRefundAmount;
|
||||
$this->calculateTransactionRefundServiceCharge = $calculateTransactionRefundServiceCharge;
|
||||
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsTransaction = $createsTransaction;
|
||||
@@ -78,15 +102,25 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
||||
|
||||
$this->updatesTransactionStatus->execute($transaction, ApprovalStatus::REFUNDED);
|
||||
|
||||
$unrequestedAmount = $this->calculateTransactionRefundOriginalAmount->execute($transaction, $request->input('amount'));
|
||||
|
||||
$conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $unrequestedAmount)), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1);
|
||||
|
||||
$configurations = $this->fetchBookingQuotation->execute($booking->company, $conversionObject);
|
||||
|
||||
$paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company);
|
||||
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('RFD-');
|
||||
|
||||
|
||||
$totalRefundAmount = $this->calculateTransactionRefundAmount->execute($transaction, $configurations->getTotal());
|
||||
|
||||
$refundServiceCharge = $this->calculateTransactionRefundServiceCharge->execute($transaction, $configurations->getServiceCharge());
|
||||
|
||||
$object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id,
|
||||
$booking->bank_id, $transaction->payment_method,
|
||||
$transaction->amount, $transaction->original_amount, 1,
|
||||
$transaction->original_currency_id, $transaction->currency_rate,
|
||||
$transaction->tax, $transaction->service_charge, Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_VERIFICATION);
|
||||
$configurations->getConfigurations()->getBankId(), $configurations->getConversionObject()->getPaymentMethod(),
|
||||
$totalRefundAmount, $request->input('amount'), 1,
|
||||
$configurations->getConversionObject()->getCurrencyId(), $configurations->getConfigurations()->getRate(),
|
||||
$configurations->getTax(), $refundServiceCharge, Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_VERIFICATION);
|
||||
|
||||
$transaction = $this->createsTransaction->execute($booking, $object);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user