From 10a95f0b4d581f4a337bb5ddc2d6a7c21ece559d Mon Sep 17 00:00:00 2001 From: omair saleh Date: Tue, 20 Sep 2022 07:28:40 +0800 Subject: [PATCH] billing fix up --- .../Eloquent/Filters/PaymentReference.php | 20 ++++++++++ .../ControllersLogic/CallbackBillplzLogic.php | 37 ++++++++++++++++--- .../Billplzs/Services/CreatesBillplzBill.php | 2 +- .../CreatePaymentTransactionLogic.php | 7 ++-- .../Services/CreatesPaymentTransaction.php | 1 + app/Http/Resources/TransactionResource.php | 2 + .../elements/PaymentHistoryComponent.vue | 2 +- .../forms/PaymentFormComponent.vue | 2 +- routes/web.php | 1 + 9 files changed, 62 insertions(+), 12 deletions(-) create mode 100644 app/Classes/General/Eloquent/Filters/PaymentReference.php diff --git a/app/Classes/General/Eloquent/Filters/PaymentReference.php b/app/Classes/General/Eloquent/Filters/PaymentReference.php new file mode 100644 index 00000000..5f5d53f5 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/PaymentReference.php @@ -0,0 +1,20 @@ +where('payment_reference', '=', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php index 0f928a51..9fec8bc6 100644 --- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php @@ -2,6 +2,8 @@ namespace App\Classes\Modules\Billplzs\ControllersLogic; +use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor; +use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor; use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; use App\Classes\Modules\Wallets\Services\UpdatesWallet; @@ -35,21 +37,27 @@ class CallbackBillplzLogic /** @var UpdatesTransactionStatus */ private $updatesTransactionStatus; - /** @var UpdatesWalletBalance */ - private $updatesWalletBalance; + /** @var UpdateDoFromVTPortalProcessor */ + private $updateDoFromVTPortalProcessor; + + /** @var UpdateDoFromYDPortalProcessor */ + private $updateDoFromYDPortalProcessor ; /** * CallbackBillplzLogic constructor. * @param GetBillplzBill $getBillplzBill * @param FetchesTransaction $fetchesTransaction * @param UpdatesTransactionStatus $updatesTransactionStatus - * @param UpdatesWalletBalance $updatesWalletBalance + * @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor + * @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor */ - public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus) + public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor) { $this->getBillplzBill = $getBillplzBill; $this->fetchesTransaction = $fetchesTransaction; $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor; + $this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor; } @@ -58,6 +66,8 @@ class CallbackBillplzLogic * @return bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View * @throws MalformedRequestException * @throws ResourceNotFoundException + * @throws \App\Classes\Exceptions\InternalServerErrorException + * @throws \GuzzleHttp\Exception\GuzzleException */ public function execute(Request $request) { @@ -73,6 +83,10 @@ class CallbackBillplzLogic $transaction = $this->fetchesTransaction->execute(['payment_reference' => $billplzXSignatureObject->getBillPlzId()]); + $invoice = $transaction->owner; + $packingList = $invoice->owner; + $order = $packingList->owner; + if($billPlz->state === 'paid') { $status = ApprovalStatus::APPROVED; } @@ -84,8 +98,19 @@ class CallbackBillplzLogic $token = Auth::fromUser(User::find(1)); $request->headers->set('Authorization', 'Bearer '.$token); - $marking = $transaction->owner()->first()->owner()->first(); + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED); - return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $marking->reference, 'transaction' => $transaction, 'status' => $status]); + if($transaction->amount >= $invoice->amount) { + $this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED); + if(app()->environment('production')){ + $this->updateDoFromVTPortalProcessor->execute($packingList); + $this->updateDoFromYDPortalProcessor->execute($packingList); + } + } + + + + + return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference, 'transaction' => $transaction, 'status' => $status]); } } \ No newline at end of file diff --git a/app/Classes/Modules/Billplzs/Services/CreatesBillplzBill.php b/app/Classes/Modules/Billplzs/Services/CreatesBillplzBill.php index 1dad646c..4f40da24 100644 --- a/app/Classes/Modules/Billplzs/Services/CreatesBillplzBill.php +++ b/app/Classes/Modules/Billplzs/Services/CreatesBillplzBill.php @@ -35,7 +35,7 @@ class CreatesBillplzBill 'reference_2_label' => 'Bill Number', 'reference_2' => $billNumber ]); -dd($response); + if($response->successful()){ $data = $response->json(); diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php index 0d3b3a98..8ba7b2c8 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php @@ -18,6 +18,7 @@ use App\Classes\ValueObjects\Constants\TransactionType; use App\Classes\ValueObjects\Constants\PaymentMethodType; use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Http\Resources\TransactionResource; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; @@ -83,14 +84,14 @@ class CreatePaymentTransactionLogic extends AbstractControllerLogic $payment_method = PaymentMethodType::PAYMENT_GATEWAY; $billPlzBill = $this->createsBillplzBill->execute( $company_module->name, - (app()->environment(['production'])) ? $company_module->employees()->first()->email : '', + (app()->environment(['production'])) ? $company_module->employees()->first()->email : 'uldvstar@gmail.com', 'This payment is for the invoice number . ' . $invoice_transaction->bill_no, $amount, $billNumber, $request->input('bank_code'), true ); -dd($billPlzBill); + $payment_reference = $billPlzBill->id; } else { @@ -119,6 +120,6 @@ dd($billPlzBill); $payment_transaction = $this->createsPaymentTransaction->execute($invoice_transaction, $object); - return $this->response([]); + return $this->resourceResponse(new TransactionResource($payment_transaction)); } } diff --git a/app/Classes/Modules/Transactions/Services/CreatesPaymentTransaction.php b/app/Classes/Modules/Transactions/Services/CreatesPaymentTransaction.php index 54afd914..98e02693 100644 --- a/app/Classes/Modules/Transactions/Services/CreatesPaymentTransaction.php +++ b/app/Classes/Modules/Transactions/Services/CreatesPaymentTransaction.php @@ -22,6 +22,7 @@ class CreatesPaymentTransaction extends AbstractUpdateRelationshipRecord $model->receiver = $object->getReceiver(); $model->recipient_bank_account_id = $object->getRecipientBankAccountId(); $model->payment_method = $object->getPaymentMethod(); + $model->payment_reference = $object->getPaymentReference(); $model->amount = $object->getAmount(); $model->original_amount = $object->getOriginalAmount(); $model->currency_id = $object->getCurrencyId(); diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index 70f3c7dd..563eedf0 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -26,6 +26,8 @@ class TransactionResource extends JsonResource 'type' => (int) $this->type, 'bill_no' => $this->bill_no, 'amount' => (double) $this->amount, + 'payment_method' => (int) $this->payment_method, + 'payment_reference' => $this->payment_reference, 'outstanding' => (double) $this->amount - ($this->transactions()->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount')), 'service_charge' => (double) $this->service_charge, 'tax' => (double) $this->tax, diff --git a/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue index c76c9a07..7244fe17 100644 --- a/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue @@ -9,7 +9,7 @@
Status
- {{ item.status === 1 ? 'Pending Verification' : item.status === ( 4 || 5) ? 'Rejected' : 'Processing Payment'}} + {{ item.status === 1 ? 'Pending Verification' : item.status === ( 4 || 5) ? 'Rejected' : 'Approved'}}
diff --git a/resources/assets/vue/components/paymentsBilling/forms/PaymentFormComponent.vue b/resources/assets/vue/components/paymentsBilling/forms/PaymentFormComponent.vue index 79a67683..96c909ee 100644 --- a/resources/assets/vue/components/paymentsBilling/forms/PaymentFormComponent.vue +++ b/resources/assets/vue/components/paymentsBilling/forms/PaymentFormComponent.vue @@ -111,7 +111,7 @@ }, successHandler(response){ if (response.payload) { - if (response.payloaddata.payment_method === 5) { + if (response.payload.data.payment_method === 5) { window.location.href = this.route('billplz.bill', response.payload.data.payment_reference) + '?auto_submit=true'; } } diff --git a/routes/web.php b/routes/web.php index 7bff15fd..bbcf4939 100644 --- a/routes/web.php +++ b/routes/web.php @@ -420,4 +420,5 @@ Route::get('/notifications/list', 'Notifications\ListNotificationsController@lis Route::get('billplz/bills/{bill_no}', function($bill_no){ return redirect(env('BILLPLZ_BASE_URL').'/bills/'.$bill_no); })->name('billplz.bill'); + \ No newline at end of file