'Created Transaction', 'message' => 'You have successfully created a transaction' ]; } /** @var GeneratesTransactionBillNumber */ private $generatesTransactionBillNo; /** @var CanCreateTransaction */ private $canCreateTransaction; private $fetchesCurrency; private $rateCalculatesCurrency; private $fetchesCompany; private $createsTransaction; private $canCreateTransactionDetail; private $createsTransactionDetail; private $fetchesTransaction; private $fetchesTransactionDetail; private $generatesReceiptBillNo; /** @var CanCreateReceipt */ private $canCreateReceipt; private $createsReceipt; private $canCreateReceiptDetail; private $createsReceiptDetail; public function __construct( GeneratesTransactionBillNumber $generatesTransactionBillNo, CanCreateTransaction $canCreateTransaction, FetchesCurrency $fetchesCurrency, RateCalculatesCurrency $rateCalculatesCurrency, FetchesCompany $fetchesCompany, CreatesTransaction $createsTransaction, CanCreateTransactionDetail $canCreateTransactionDetail, CreatesTransactionDetail $createsTransactionDetail, FetchesTransaction $fetchesTransaction , FetchesTransactionDetail $fetchesTransactionDetail, GeneratesReceiptBillNo $generatesReceiptBillNo, CanCreateReceipt $canCreateReceipt, CreatesReceipt $createsReceipt, CanCreateReceiptDetail $canCreateReceiptDetail, CreatesReceiptDetail $createsReceiptDetail ){ $this->generatesTransactionBillNo = $generatesTransactionBillNo; $this->canCreateTransaction = $canCreateTransaction; $this->fetchesCurrency = $fetchesCurrency; $this->rateCalculatesCurrency = $rateCalculatesCurrency; $this->fetchesCompany = $fetchesCompany; $this->createsTransaction =$createsTransaction; $this->canCreateTransactionDetail =$canCreateTransactionDetail; $this->createsTransactionDetail = $createsTransactionDetail; $this->fetchesTransaction = $fetchesTransaction; $this->fetchesTransactionDetail = $fetchesTransactionDetail; $this->generatesReceiptBillNo = $generatesReceiptBillNo; $this->canCreateReceipt = $canCreateReceipt; $this->createsReceipt =$createsReceipt; $this->canCreateReceiptDetail =$canCreateReceiptDetail; $this->createsReceiptDetail = $createsReceiptDetail; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic( $transactionsArray) : JsonResponse { // dd($request); try { // dd(json_decode($transactionsArray)); $transactions = Transaction::whereIn('id', json_decode($transactionsArray))->where('type', TransactionType::SHIPPING_INVOICE)->get(); $total = $transactions->sum('amount'); $packingList =$transactions[1]->owner; $order = $packingList->owner; $companyModule = $order->companyModule; $company = $companyModule->company; $wallet = $company->wallets()->first(); if (!$wallet) { $object = new WalletObject($company->id, 1, (App()->make(GeneratesWalletCode::class))->execute()); /** @var Wallet $wallet */ $wallet = (App()->make(CreatesWallet::class))->execute($object, $company); } $billNumber = (App()->make(GeneratesTransactionBillNumber::class))->execute('TOPUP-'); if($total < 0) { throw new MalformedRequestException('Top up credit value must be greater than zero.'); } $billPlzBill = (App()->make(CreatesBillplzBill::class))->execute($company->name, 'example@gmail.com', 'This payment is credit topup for company ref. ' . $company->reference, $total, $billNumber, 'bank code', true); $transaction_object = new TransactionObject($billNumber, TransactionType::TOP_UP, 1, $company->id, 1, PaymentMethodType::PAYMENT_GATEWAY, $total, $total, 1, 1, 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, [], 'test'); // $transaction = $this->createsTransaction->execute($wallet, $transaction_object); $transaction = (App()->make(CreatesTransaction::class))->execute($wallet, $transaction_object); $result= (App()->make(UpdatesWalletBalance::class))->execute($wallet, $total); foreach ($transactions as $key => $value) { multipleInvoicesWithOnePayment::create([ 'topUp_request_id' => $transaction->id, 'transaction_id' => $value->id ]); } return $this->response([]); ; } catch (\Exception $exception) { throw new ErrorException($exception->getMessage(), $exception->getCode()); } } public function verifypayment( $topUp_transaction_id, $amount) : JsonResponse { $totalamount =0; $topup = multipleInvoicesWithOnePayment::where('topUp_request_id',$topUp_transaction_id)->get(); foreach ($topup as $key => $value) { $transaction = Transaction::where('id',$value->transaction_id)->frist(); $totalamount += $transaction->amount; (App()->make(updatesTransactionStatus::class))->execute($transaction, ApprovalStatus::APPROVED); $transaction_object = new TransactionObject($transaction->bill_no, TransactionType::PAYMENT, 1, $topUp_transaction_id, 1, PaymentMethodType::PAYMENT_GATEWAY, $transaction->amount, $transaction->amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], 'test'); $transaction = (App()->make(CreatesTransaction::class))->execute($transaction, $transaction_object); } $amount = $amount - $totalamount; Transaction::where('id', $topUp_transaction_id)->update(['amount'=> $amount]); } }