From 715384f4a42e35b94ec1acc2f12b77d989ac3899 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 13 Mar 2023 00:42:44 +0800 Subject: [PATCH] audit billplz --- routes/web.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/routes/web.php b/routes/web.php index a4619efc..c510eb1d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -955,3 +955,26 @@ Route::get('/packing-lists/delete-duplicated', function(Request $request){ } } }); + +Route::get('/billplz/audit', function (Request $request) { + $transactions = Transaction::where('type', TransactionType::PAYMENT)->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->whereIn('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); + + if($response->successful()){ + $data = $response->json(); + if($data['paid']){ + + } else { + $totalAmount += $transaction->amount; + echo $transaction->id." => Fraud." . $transaction->amount . "
"; + } + }else{ + echo "billplz error
"; + } + } + + echo 'Total: ' . $totalAmount; +}); \ No newline at end of file