generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->createsPaymentTransaction = $createsPaymentTransaction; $this->createsBillplzBill = $createsBillplzBill; $this->createsTransactionableTransaction = $createsTransactionableTransaction; $this->updatesWalletBalance = $updatesWalletBalance; $this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor; $this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor; $this->updatesTransactionStatus = $updatesTransactionStatus; } /** * @throws MalformedRequestException */ public function execute(Transaction $invoice, $payment_method, $bank_code, $date, $run = true) { $amount = $invoice->amount; Log::info($invoice->owner); $company_module = $invoice->owner->owner->companyModule()->first(); $approvalStatus = ApprovalStatus::PENDING_SUBMISSION; $billNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); $payment_reference = null; if ($payment_method == PaymentMethodType::PAYMENT_GATEWAY) { // create billplz transaction $payment_method = PaymentMethodType::PAYMENT_GATEWAY; $billPlzBill = $this->createsBillplzBill->execute( $company_module->name, (app()->environment(['production'])) ? $company_module->employees()->first()->email : 'uldvstar@gmail.com', 'This payment is for the invoice number . ' . $billNumber, $amount, $billNumber, $bank_code, true ); $payment_reference = $billPlzBill->id; } else if ($payment_method === PaymentMethodType::WALLET) { /** @var Wallet $wallet */ $wallet = $company_module->wallets()->first(); // if((float) number_format(($wallet->amount - $amount),2) < 0){ // throw new MalformedRequestException('Insufficient wallet balance. Please Top up your wallet.'); // } $walletPaymentBillNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); $transaction_object = new TransactionObject($walletPaymentBillNumber, TransactionType::PAYMENT, 1, $company_module->id, 1, PaymentMethodType::WALLET, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], ''); $transaction = $this->createsTransactionableTransaction->execute($wallet, $transaction_object); $transaction->created_at = $date; $transaction->updated_at = $date; $transaction->save(); $payment_reference = $walletPaymentBillNumber; $this->updatesWalletBalance->execute($wallet, ($amount * -1)); if($run) { $packingList = $invoice->owner; $order = $packingList->owner; $packingList->status = ApprovalStatus::APPROVED; $packingList->save(); if(app()->environment('production')){ $this->updateDoFromVTPortalProcessor->execute($packingList); $this->updateDoFromYDPortalProcessor->execute($packingList); } } // later use this variabke to create a approved payment transaction $approvalStatus = ApprovalStatus::APPROVED; // update invoice to completed if($run){ $this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED); } } else { $payment_method = PaymentMethodType::CASH; } $object = new TransactionObject( $billNumber, TransactionType::PAYMENT, $company_module->id, 1, 1, $payment_method, $amount, $amount, 1, 1, 0, 0, 0, null, $approvalStatus, null, $payment_reference ); $payment_transaction = $this->createsPaymentTransaction->execute($invoice, $object); return $payment_transaction; } }