mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Merge branch 'dillon/68-exchange-debugging-refund' into 'master'
Fix an error with refund for transaction that used a voucher earlier, get... See merge request CIEFWorldwideSdnBhd/exchange-2.0!174
This commit is contained in:
@@ -117,18 +117,20 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
|
|||||||
$isFullyRefund = ($refund + $request->input('amount')) == $transaction->original_amount;
|
$isFullyRefund = ($refund + $request->input('amount')) == $transaction->original_amount;
|
||||||
|
|
||||||
$voucherCode = null;
|
$voucherCode = null;
|
||||||
|
$redemptionId = null;
|
||||||
|
|
||||||
if ($transaction->voucherRedemption) {
|
if ($transaction->voucherRedemption) {
|
||||||
$voucherCode = $transaction->voucherRedemption->voucher->code;
|
// $voucherCode = $transaction->voucherRedemption->voucher->code;
|
||||||
|
$redemptionId = $transaction->voucherRedemption->redemption_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$conversionObjectBeforeCurrentRefund = new CurrencyConversionObject($bookingAmountBeforeCurrentRefund, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method);
|
$conversionObjectBeforeCurrentRefund = new CurrencyConversionObject($bookingAmountBeforeCurrentRefund, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method);
|
||||||
|
|
||||||
$conversionObjectAfterRefund = new CurrencyConversionObject($isFullyRefund ? $request->input('amount') : $bookingAmountAfterRefunded, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method);
|
$conversionObjectAfterRefund = new CurrencyConversionObject($isFullyRefund ? $request->input('amount') : $bookingAmountAfterRefunded, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method);
|
||||||
|
|
||||||
$quotationBeforeCurrentRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectBeforeCurrentRefund, $voucherCode);
|
$quotationBeforeCurrentRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectBeforeCurrentRefund, $voucherCode, $redemptionId);
|
||||||
|
|
||||||
$quotationAfterRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectAfterRefund, $voucherCode);
|
$quotationAfterRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectAfterRefund, $voucherCode, $redemptionId);
|
||||||
|
|
||||||
$service_charges_to_refund = $isFullyRefund ? $quotationBeforeCurrentRefund->getServiceCharge() : $quotationBeforeCurrentRefund->getServiceCharge() - $quotationAfterRefund->getServiceCharge();
|
$service_charges_to_refund = $isFullyRefund ? $quotationBeforeCurrentRefund->getServiceCharge() : $quotationBeforeCurrentRefund->getServiceCharge() - $quotationAfterRefund->getServiceCharge();
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use App\Classes\Modules\Vouchers\DataTransferObjects\ValidatedVoucherObject;
|
|||||||
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherObject;
|
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherObject;
|
||||||
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
||||||
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
|
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
|
||||||
|
use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyRedemption;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Currency;
|
use App\Models\Currency;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@@ -27,27 +28,34 @@ class FetchesBookingQuotation
|
|||||||
/** @var ValidatesVoucherifyVoucher */
|
/** @var ValidatesVoucherifyVoucher */
|
||||||
private $validatesVoucherifyVoucher;
|
private $validatesVoucherifyVoucher;
|
||||||
|
|
||||||
|
/** @var FetchesVoucherifyRedemption */
|
||||||
|
private $fetchesVoucherifyRedemption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FetchesBookingQuotation constructor.
|
* FetchesBookingQuotation constructor.
|
||||||
* @param FetchesCompanyServiceSettings $fetchesCompanyServiceSettings
|
* @param FetchesCompanyServiceSettings $fetchesCompanyServiceSettings
|
||||||
* @param FetchesCurrency $fetchesCurrency
|
* @param FetchesCurrency $fetchesCurrency
|
||||||
|
* @param ValidatesVoucherifyVoucher $validatesVoucherifyVoucher
|
||||||
|
* @param FetchesVoucherifyRedemption $fetchesVoucherifyRedemption
|
||||||
*/
|
*/
|
||||||
public function __construct(FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher)
|
public function __construct(FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher, FetchesVoucherifyRedemption $fetchesVoucherifyRedemption)
|
||||||
{
|
{
|
||||||
$this->fetchesCompanyServiceSettings = $fetchesCompanyServiceSettings;
|
$this->fetchesCompanyServiceSettings = $fetchesCompanyServiceSettings;
|
||||||
$this->fetchesCurrency = $fetchesCurrency;
|
$this->fetchesCurrency = $fetchesCurrency;
|
||||||
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
|
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
|
||||||
|
$this->fetchesVoucherifyRedemption = $fetchesVoucherifyRedemption;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Company $company
|
* @param Company $company
|
||||||
* @param CurrencyConversionObject $conversionObject
|
* @param CurrencyConversionObject $conversionObject
|
||||||
* @param string $voucherCode
|
* @param null|string $voucherCode
|
||||||
|
* @param null|string $redemptionId
|
||||||
* @return CalculationObject
|
* @return CalculationObject
|
||||||
* @throws MalformedRequestException
|
* @throws MalformedRequestException
|
||||||
*/
|
*/
|
||||||
public function execute(Company $company, CurrencyConversionObject $conversionObject, ?string $voucherCode = null){
|
public function execute(Company $company, CurrencyConversionObject $conversionObject, ?string $voucherCode = null, ?string $redemptionId = null){
|
||||||
if($conversionObject->getAmount() <= 0) throw new MalformedRequestException('Your transfer must be greater than zero.');
|
if($conversionObject->getAmount() <= 0) throw new MalformedRequestException('Your transfer must be greater than zero.');
|
||||||
|
|
||||||
$configurations = $this->fetchesCompanyServiceSettings->execute($company, $conversionObject);
|
$configurations = $this->fetchesCompanyServiceSettings->execute($company, $conversionObject);
|
||||||
@@ -58,27 +66,37 @@ class FetchesBookingQuotation
|
|||||||
|
|
||||||
$calculationObject = new CalculationObject($conversionObject, $configurations, null);
|
$calculationObject = new CalculationObject($conversionObject, $configurations, null);
|
||||||
|
|
||||||
|
$voucher = null;
|
||||||
|
|
||||||
//Voucherify
|
//Voucherify
|
||||||
if($voucherCode){
|
if($voucherCode){
|
||||||
$employee = $company->employees()->first();
|
$employee = $company->employees()->first();
|
||||||
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($company->id, $voucherCode, $calculationObject->getSubTotal(), $employee);
|
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($company->id, $voucherCode, $calculationObject->getSubTotal(), $employee);
|
||||||
$result = $this->validatesVoucherifyVoucher->execute($validateVoucherifyVoucherObject);
|
$result = $this->validatesVoucherifyVoucher->execute($validateVoucherifyVoucherObject);
|
||||||
|
|
||||||
// //A minimum charge of RM5 applies when voucher used make price to be paid by customer RM0
|
|
||||||
// if(isset($result->order->total_amount) && $result->order->total_amount === 0){
|
|
||||||
// // $result->order->cief_original_total_amount = $result->order->total_amount;
|
|
||||||
// $result->order->total_amount = 500;
|
|
||||||
// $result->order->total_discount_amount = $result->order->total_discount_amount - $result->order->total_amount;
|
|
||||||
// Log::info('FetchesBookingQuotation order total_amount RM0 (voucher applied) for company id ' . $company->id. ' with original amount ' . $calculationObject->getSubTotal());
|
|
||||||
// }
|
|
||||||
|
|
||||||
$voucher = [
|
$voucher = [
|
||||||
"code" => $result->code,
|
"code" => $result->code,
|
||||||
"discount" => property_exists($result, 'discount') ? $result->discount : null,
|
"discount" => property_exists($result, 'discount') ? $result->discount : null,
|
||||||
"metadata" => $result->metadata,
|
"metadata" => $result->metadata,
|
||||||
"order" => $result->order,
|
"order" => $result->order,
|
||||||
];
|
];
|
||||||
$validatedVoucherObject = new ValidatedVoucherObject(isset($voucher['metadata']->name) ? $voucher['metadata']->name: "", $voucher['code'], $voucher['discount']->type ?? 'AMOUNT', $voucher['order']->total_discount_amount, $voucher['order']->total_amount);
|
}
|
||||||
|
else if($redemptionId){
|
||||||
|
$result = $this->fetchesVoucherifyRedemption->execute($redemptionId);
|
||||||
|
$voucher = [
|
||||||
|
"code" => $result->voucher->code ?? null,
|
||||||
|
"discount" => null,
|
||||||
|
"metadata" => null,
|
||||||
|
"order" => $result->order ?? null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($voucher){
|
||||||
|
$validatedVoucherObject = new ValidatedVoucherObject(
|
||||||
|
isset($voucher['metadata']->name) ? $voucher['metadata']->name : "",
|
||||||
|
$voucher['code'],
|
||||||
|
$voucher['discount']->type ?? 'AMOUNT',
|
||||||
|
$voucher['order']->total_discount_amount,
|
||||||
|
$voucher['order']->total_amount);
|
||||||
$calculationObject = new CalculationObject($conversionObject, $configurations, $validatedVoucherObject);
|
$calculationObject = new CalculationObject($conversionObject, $configurations, $validatedVoucherObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class FetchesVoucherifyRedemption
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var VoucherifyClient */
|
||||||
|
private $voucherifyClient;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FetchesVoucherifyRedemption constructor.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->voucherifyClient = createVoucherifyClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $redemptionId
|
||||||
|
* @return null|object
|
||||||
|
* @throws \Voucherify\ClientException
|
||||||
|
*/
|
||||||
|
public function execute(string $redemptionId)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$result = $this->voucherifyClient->redemptions->get($redemptionId);
|
||||||
|
return $result;
|
||||||
|
} catch (\Voucherify\ClientException $e) {
|
||||||
|
Log::error('FetchesVoucherifyRedemption '.$e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
<div class="font-heading fs-12">{{this.data.fixed_currency.short_code}} {{(Math.round((this.data.outstanding_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}</div>
|
<div class="font-heading fs-12">{{this.data.fixed_currency.short_code}} {{(Math.round((this.data.outstanding_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row m-t-20" v-if="data.company.employee.status === 2 && data.company.status === 2 && data.outstanding_amount > 0">
|
<div class="row m-t-20" v-if="data.company.employee.status === 2 && data.company.status === 2 && (Math.round((this.data.outstanding_amount + Number.EPSILON) * 100) / 100) > 0">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button id="payment-btn" class="btn btn-sm all-caps b-rad-none btn-success btn-block" @click="makePayment()">Make Payment</button>
|
<button id="payment-btn" class="btn btn-sm all-caps b-rad-none btn-success btn-block" @click="makePayment()">Make Payment</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user