diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php index c064cc4e..2346554f 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php @@ -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; } } diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php index ab5fa2a6..76fffd7a 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php @@ -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]); } diff --git a/resources/assets/vue/components/paymentsBilling/forms/GroupPaymentFormComponent.vue b/resources/assets/vue/components/paymentsBilling/forms/GroupPaymentFormComponent.vue index 9282c280..9050506b 100644 --- a/resources/assets/vue/components/paymentsBilling/forms/GroupPaymentFormComponent.vue +++ b/resources/assets/vue/components/paymentsBilling/forms/GroupPaymentFormComponent.vue @@ -138,7 +138,7 @@