diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php index 85c9fe77..90fbef47 100644 --- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php @@ -94,6 +94,11 @@ class CallbackBillplzLogic $status = ApprovalStatus::APPROVED; } + if ($transaction->type == 'topUp') { + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED); + $this->multipleInvoicesWithOnePaymentLogic->verifypayment($transaction->id, $transaction->amount); + } + if($billPlz->state === 'due') { $status = $billplzXSignatureObject->getStatus() === 'failed' ? ApprovalStatus::REJECTED : ApprovalStatus::PENDING_VERIFICATION; } diff --git a/app/Classes/Modules/Transactions/ControllersLogic/multipleInvoicesWithOnePaymentLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/multipleInvoicesWithOnePaymentLogic.php new file mode 100644 index 00000000..87b8531a --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/multipleInvoicesWithOnePaymentLogic.php @@ -0,0 +1,204 @@ + '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]); + + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/MultipleInvoiceOnePaymentController.php b/app/Http/Controllers/Transactions/MultipleInvoiceOnePaymentController.php new file mode 100644 index 00000000..de1c7d1b --- /dev/null +++ b/app/Http/Controllers/Transactions/MultipleInvoiceOnePaymentController.php @@ -0,0 +1,76 @@ +logic($transactionsArray); + } + + public function getallivoiceid( $transactionsArray) + { + + + // 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, $this->generatesWalletCode->execute()); + /** @var Wallet $wallet */ + $wallet = $this->createsWallet->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 ]); + + } + dd($transaction->id); + } + + +} diff --git a/app/Models/multipleInvoicesWithOnePayment.php b/app/Models/multipleInvoicesWithOnePayment.php new file mode 100644 index 00000000..51ab9127 --- /dev/null +++ b/app/Models/multipleInvoicesWithOnePayment.php @@ -0,0 +1,19 @@ + 'api', 'prefix' => 'v1', 'as' => 'api.'], function require __DIR__ . '/report.php'; }); + + require __DIR__ . '/invoice.php'; require __DIR__ . '/announcement.php'; }); diff --git a/routes/invoice.php b/routes/invoice.php new file mode 100644 index 00000000..2fc0605d --- /dev/null +++ b/routes/invoice.php @@ -0,0 +1,18 @@ +name('grouppayment'); + // Route::get('/refresh', 'RefreshAuthenticationTokenController@refresh')->name('refresh'); + + Route::get('/testgrouppayment', function () { + + $ids = array(1,2,9); + + + return redirect()->route('api.grouppayment',['transactionsArray' => json_encode($ids)]); + }); \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index f71292e9..aec149dd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -33,7 +33,7 @@ use Illuminate\Support\Facades\Route; | */ -require __DIR__ . '/template.php'; +require __DIR__ . '/template.php'; Route::domain('hywave.izyim.com')->group(function () { Route::group(['as' => 'last_mile_delivery.'], function () {