From a36c5c3063271ed0348ce67daa3b96b3d15c3413 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 26 Jun 2024 12:47:44 +0800 Subject: [PATCH 01/21] show group-transaction-with-completed-payments --- app/Models/Group.php | 8 ++++++++ routes/web.php | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/Models/Group.php b/app/Models/Group.php index 276b0aa5..188b0fe5 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -84,4 +84,12 @@ class Group extends Model implements Documentable, Transactionable { return $this->BelongsTo(Currency::class, 'original_currency_id', 'id'); } + + /** + * @return hasOne + */ + public function payment() + { + return $this->hasOne(Transaction::class, 'payment_reference', 'reference'); + } } diff --git a/routes/web.php b/routes/web.php index bc073633..f2d6fc41 100644 --- a/routes/web.php +++ b/routes/web.php @@ -34,6 +34,7 @@ use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Crypt; use App\Models\Container; +use App\Models\Group; use App\Models\Transaction; use App\Models\Wallet; use Illuminate\Support\Facades\DB; @@ -1315,3 +1316,14 @@ Route::get('/show-all-extra-payments', function () { Route::get('/segments', function (Request $request) { return view('pages.segments.index'); })->name('segments'); + +Route::get('/group-transaction-with-completed-payments', function () { + $groups = Group::whereNotIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->whereHas('payment', function ($query) { + $query->whereIn('status', [2, 3]); + })->get(); + + foreach ($groups as $group) { + dump($group->groupTransactions->first()->transaction->owner->owner->reference); + } +}); From d7625aece7a627c26e9ac6df23844f27be070fa0 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 26 Jun 2024 13:07:30 +0800 Subject: [PATCH 02/21] update group-transaction-with-completed-payments --- routes/web.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index f2d6fc41..7e7c14f1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1324,6 +1324,20 @@ Route::get('/group-transaction-with-completed-payments', function () { })->get(); foreach ($groups as $group) { - dump($group->groupTransactions->first()->transaction->owner->owner->reference); + $groupPayment = $group->payment; + $order = $group->groupTransactions->first()->transaction->owner->owner; + $companyModule = $order->companyModule; + + $connection = $companyModule->connections()->first(); + $companyMarking = $connection ? $connection->invitee_reference : ''; + + dump([ + 'reference' => $group->reference, + 'groupPayment_id' => $groupPayment->id, + 'groupPayment_status' => $groupPayment->status, + 'order' => $order->reference, + 'companyMarking' => $companyMarking, + ]); + echo '' . $companyMarking . '
'; } }); From 669cac9bd41c4c2f861d0792ec55820d7009ac13 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 26 Jun 2024 13:47:58 +0800 Subject: [PATCH 03/21] fix-approved-payment-failed-group --- .../FixApprovedPaymentFailedGroup.php | 94 +++++++++++++++++++ .../elements/PaymentHistoryComponent.vue | 27 ++++++ 2 files changed, 121 insertions(+) create mode 100644 app/Console/Commands/FixApprovedPaymentFailedGroup.php diff --git a/app/Console/Commands/FixApprovedPaymentFailedGroup.php b/app/Console/Commands/FixApprovedPaymentFailedGroup.php new file mode 100644 index 00000000..97dfac24 --- /dev/null +++ b/app/Console/Commands/FixApprovedPaymentFailedGroup.php @@ -0,0 +1,94 @@ +callbackBillplzProcessor = $callbackBillplzProcessor; + } + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + ini_set('memory_limit', '-1'); + + $this->outputArray = []; + $start = new Carbon(); + + $groups = Group::whereNotIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->whereHas('payment', function ($query) { + $query->whereIn('status', [2, 3]); + })->get(); + + foreach ($groups as $group) { + $transaction = $group->payment; + + $response = Http::withBasicAuth(config('billplz.api_key') . ':', '')->get(config('billplz.base_url') . '/api/v3/bills/' . $transaction->payment_reference); + + dump($transaction->payment_reference); + + if ($response->successful()) { + $data = $response->json(); + if ($data['paid']) { + $status = ApprovalStatus::PENDING_VERIFICATION; + + if ($data['state'] === 'paid') { + $status = ApprovalStatus::APPROVED; + } + + $this->info(Carbon::now() . ' : Fixing ' . $transaction->payment_reference); + $this->callbackBillplzProcessor->execute($transaction, $status); + } + } else { + $this->info("billplz error
"); + } + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + + if ($groups) { + $this->info(Carbon::now() . ' : Done . ElapsedTime: ' . $elapsedTime); + } + } +} diff --git a/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue index 94f23bc5..e7a08882 100644 --- a/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/paymentsBilling/elements/PaymentHistoryComponent.vue @@ -92,6 +92,22 @@ +
+
+
Payment Method
+
+ {{ convertPaymentMethodToText(item.payment_method) }} +
+
+
+
Created At
+
{{ item.created_at }}
+
+
+
Updated At
+
{{ item.updated_at }}
+
+