Long term solution to prevent customer making payment to a shipping invoice when there is a ongoing dispute

This commit is contained in:
Dillon Ngo
2024-03-14 12:32:03 +08:00
parent 27529e90ca
commit 96a089df16
4 changed files with 68 additions and 39 deletions
@@ -82,16 +82,35 @@ class CreateGroupsLogic extends AbstractControllerLogic
public function logic(Request $request) : JsonResponse
{
$payment_method = PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')];
$groupPyamentStatus = ApprovalStatus::PENDING_VERIFICATION;
$invoice_ids = json_decode($request->route('transaction_ids'));
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
// todo-new: check why is this not working
// $invoices = $this->fetchesTransaction->execute(['id_in' => $invoice_ids]);
$invoices = Transaction::whereIn('id', $invoice_ids)->get();
$isInvoicesApprove = $this->checkIfInvoicesAreApprove($invoices);
if(!$isInvoicesApprove){
$response = ['message' => 'Transaction might be suspended, check if there is any dispute in progress.'];
return $this->response(['data' => $response]);
}
else{
$paymentMethodStr = $request->input('payment_method');
$paymentMethod = PaymentMethodType::PAYMENT_METHODS[$paymentMethodStr];
$amount = $request->input('amount');
$bankCode = $request->input('bank_code');
$result = $this->processInvoices($invoices, $paymentMethodStr, $amount, $bankCode);
if ($paymentMethod === PaymentMethodType::PAYMENT_GATEWAY) {
return $this->resourceResponse(new WalletTransactionResource($result));
}
}
return $this->response([]);
}
private function processInvoices($invoices, $reqPaymentMethod, $reqAmount, $reqBankCode){
$result = [];
$payment_method = PaymentMethodType::PAYMENT_METHODS[$reqPaymentMethod];
$groupPyamentStatus = ApprovalStatus::PENDING_VERIFICATION;
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
foreach ($invoices as $invoice) {
$order = null;
if ($invoice->owner instanceof Transaction) {
@@ -118,7 +137,7 @@ class CreateGroupsLogic extends AbstractControllerLogic
$wallet = Wallet::where('owner_id', $companyModuleId)->first();
// todo-new: verify currently checking wallet amount based on 'amount' value passed by frontend
if((float) number_format(($wallet->amount - $request->input('amount')),2) < 0){
if((float) number_format(($wallet->amount - $reqAmount),2) < 0){
throw new MalformedRequestException('Insufficient wallet balance. Please Top up your wallet.');
}
@@ -154,7 +173,7 @@ class CreateGroupsLogic extends AbstractControllerLogic
foreach ($invoices as $invoice) {
if ($payment_method == PaymentMethodType::WALLET) {
$paymentTransaction = $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, $request->input('bank_code'), false);
$paymentTransaction = $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, $reqBankCode, false);
if($paymentTransaction && $paymentTransaction->status == ApprovalStatus::APPROVED){
$pL = $invoice->owner;
@@ -181,11 +200,12 @@ class CreateGroupsLogic extends AbstractControllerLogic
if (in_array($payment_method, [PaymentMethodType::PAYMENT_GATEWAY, PaymentMethodType::CASH])) {
// create only one billplz payment for wallet top up
$amount = floatval(str_replace(',', '', $request->input('amount')));
$amount = floatval(str_replace(',', '', $reqAmount));
$companyModuleId = $invoice->receiver;
$companyModule = $this->fetchesCompanyModule->execute(['id' => $companyModuleId]);
$topUpTransaction = $this->createWalletTopUpTransactionProcessor->execute($companyModule, $amount, $request->input('bank_code'), $payment_method, $billNumber, true);
$topUpTransaction = $this->createWalletTopUpTransactionProcessor->execute($companyModule, $amount, $reqBankCode, $payment_method, $billNumber, true);
$result = $topUpTransaction;
}
$group->issuer = $issuer;
@@ -201,11 +221,15 @@ class CreateGroupsLogic extends AbstractControllerLogic
$group->status = $groupPyamentStatus;
$group->save();
if ($payment_method === PaymentMethodType::PAYMENT_GATEWAY) {
return $this->resourceResponse(new WalletTransactionResource($topUpTransaction));
return $result;
}
} else {
return $this->response([]);
private function checkIfInvoicesAreApprove($invoices){
foreach ($invoices as $invoice) {
if($invoice->status !== ApprovalStatus::APPROVED && $invoice->status !== ApprovalStatus::COMPLETED){
return false;
}
}
return true;
}
}
@@ -52,28 +52,18 @@ class CreatePaymentTransactionLogic extends AbstractControllerLogic
$invoice_transaction = $this->fetchesTransaction->execute(['id' => $request->input('transaction_id')]);
$payment_transaction = $this->createPaymentTransactionProcessor->execute($invoice_transaction, $payment_method , $request->input('bank_code'), false);
if($invoice_transaction->status === ApprovalStatus::APPROVED){
$payment_transaction = $this->createPaymentTransactionProcessor->execute($invoice_transaction, $payment_method , $request->input('bank_code'), false);
if($payment_transaction && $payment_transaction->status == ApprovalStatus::APPROVED){
$pL = $invoice_transaction->owner;
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice_transaction);
if($payment_transaction && $payment_transaction->status === ApprovalStatus::APPROVED){
$pL = $invoice_transaction->owner;
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice_transaction);
}
return $this->resourceResponse(new TransactionResource($payment_transaction));
}
//cief todo: at exchange there is a transition step - starts
// if(PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')] == PaymentMethodType::PAYMENT_GATEWAY){
// $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::PENDING_VERIFICATION);
// }
// if(config('perfexcrm.is_enabled') == 'true'){
// $this->transactionToPerfexCRMV2Processor->execute($transaction, $status);
// }
//To use
//ApprovalStatus::PENDING_VERIFICATION;
//use this to trigger $this->transactionToPerfexCRMV2Processor->execute > defineTasks > defineTasks_handlePendingVerificationStatus > definePaymentTasks
//cief todo: at exchange there is a transition step - ends
return $this->resourceResponse(new TransactionResource($payment_transaction));
$response = ['message' => 'Transaction might be suspended, check if there is any dispute in progress.'];
return $this->response(['data' => $response]);
}
@@ -138,7 +138,7 @@
<div class="btn btn-sm all-caps b-rad-none btn-default bg-master-lighter btn-block" @click="expandPayment = false" data-dismiss="modal">Cancel</div>
</div>
<div class="col-8 p-l-0">
<div class="btn btn-sm all-caps b-rad-none btn-default bg-success btn-block text-white" @click="submitForm()" :class="[{'hide': paymentMethod.name === ''}]" data-dismiss="modal">Proceed</div>
<div class="btn btn-sm all-caps b-rad-none btn-default bg-success btn-block text-white" @click="submitForm()" :class="[{'hide': paymentMethod.name === ''}]">Proceed</div>
</div>
</div>
</div>
@@ -202,8 +202,9 @@
},
methods:{
submitForm(){
this.error = '';
this.parameters.payment_method = this.paymentMethod.id;
this.submit(this.route('api.transaction.group.create', JSON.stringify(this.selectedIds)), 'post', this.section, true, true);
this.submit(this.route('api.transaction.group.create', JSON.stringify(this.selectedIds)), 'post', this.section, false, true);
},
updatePaymentType(payment){
this.paymentMethod = {
@@ -224,11 +225,17 @@
// }
// }
if (response.payload.length == 0) {
let isClearToUpdateList = true;
if(response.payload.data && response.payload.data.message){
this.error = response.payload.data.message;
isClearToUpdateList = false;
}
else if (response.payload.length == 0) {
setTimeout(function() {
location.reload();
}, 2000);
} else if (response.payload) {
}
else if (response.payload) {
if (response.payload.data.payment_method === 5) {
window.location.href = this.route('billplz.bill', response.payload.data.reference) + '?auto_submit=true';
} else {
@@ -236,7 +243,9 @@
}
}
this.updateList();
if(isClearToUpdateList){
this.updateList();
}
}
},
mixins: [formHandler]
@@ -97,7 +97,7 @@
<div class="btn btn-sm all-caps b-rad-none btn-default bg-master-lighter btn-block" @click="expandPayment = false" data-dismiss="modal">Cancel</div>
</div>
<div class="col-8 p-l-0">
<div class="btn btn-sm all-caps b-rad-none btn-default bg-success btn-block text-white" @click="submitForm()" :class="[{'hide': paymentMethod.name === ''}]" data-dismiss="modal">Proceed</div>
<div class="btn btn-sm all-caps b-rad-none btn-default bg-success btn-block text-white" @click="submitForm()" :class="[{'hide': paymentMethod.name === ''}]">Proceed</div>
</div>
</div>
</div>
@@ -134,8 +134,9 @@
},
methods:{
submitForm(){
this.error = '';
this.parameters.payment_method = this.paymentMethod.id;
this.submit(this.route('api.transaction.payment.create'), 'post', 'orderProfileSection', true, true);
this.submit(this.route('api.transaction.payment.create'), 'post', 'orderProfileSection', false, true);
},
updatePaymentType(payment){
this.paymentMethod = {
@@ -152,7 +153,12 @@
}
}
this.updateList();
if(response.payload.data && response.payload.data.message){
this.error = response.payload.data.message;
}
else{
this.updateList();
}
}
},
mixins: [formHandler]