From 201a502aa8e523fbd1d5ee1149d4e3746100c30c Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 15 Mar 2023 19:19:12 +0800 Subject: [PATCH] debug billplz payment --- .../Commands/debugBillplzFailedPayment.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 app/Console/Commands/debugBillplzFailedPayment.php diff --git a/app/Console/Commands/debugBillplzFailedPayment.php b/app/Console/Commands/debugBillplzFailedPayment.php new file mode 100644 index 00000000..cf7a9664 --- /dev/null +++ b/app/Console/Commands/debugBillplzFailedPayment.php @@ -0,0 +1,71 @@ +where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->whereNotIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::APPROVED])->get(); + + $i = 0; + $totalAmount = 0; + foreach ($transactions as $transaction){ + $response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$transaction->payment_reference); + + // dd($response); + + if($response->successful()){ + $data = $response->json(); + if($data['paid']){ + if (!in_array($transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) { + echo 'Paid transaction - : id: '. $transaction->id . ' - Date: '.$transaction->created_at->format('d-m-Y').' - Amount: '. $transaction->amount . "

"; + } + } else { + $totalAmount += $transaction->amount; + $this->info('Unpaid Transaction - id:' . $transaction->id . ' - Date: '.$transaction->owner->created_at->format('d-m-Y').' - Amount: '. $transaction->amount); + } + }else{ + $this->info('billplz error'); + } + } + + echo 'Total: ' . $totalAmount; + } +}