From dcf5c2e455d4e145bce87acade2658cee2d3707e Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 19 Oct 2023 20:14:59 +0800 Subject: [PATCH] show billplz failed callback command --- .../Commands/ShowFailediBllplzCallback.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 app/Console/Commands/ShowFailediBllplzCallback.php diff --git a/app/Console/Commands/ShowFailediBllplzCallback.php b/app/Console/Commands/ShowFailediBllplzCallback.php new file mode 100644 index 00000000..b6e40380 --- /dev/null +++ b/app/Console/Commands/ShowFailediBllplzCallback.php @@ -0,0 +1,84 @@ +where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->whereNotIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get(); + $totalTransactions = count($transactions); + + if ($totalTransactions) { + $this->info(Carbon::now() . ' : Fix failled callback from billplz cron started.'); + } + + $counter = 1; + $totalAmount = 0; + foreach ($transactions as $transaction){ + $response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$transaction->payment_reference); + + if($response->successful()){ + $data = $response->json(); + if($data['paid']){ + dump($transaction->payment_reference); + dump($transaction->id); + } + }else{ + $this->info("billplz error
"); + } + $counter++; + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + + if ($totalTransactions) { + $this->info(Carbon::now() . ' : Done Billplz Failled Callback. ElapsedTime: ' . $elapsedTime . '. Total: ' . $totalAmount); + } + + } +}