Add API error handling to Billplz Transaction Review
This commit is contained in:
@@ -4,6 +4,9 @@ namespace App\Http\Controllers;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BillplzTransactionReviewController extends Controller
|
class BillplzTransactionReviewController extends Controller
|
||||||
{
|
{
|
||||||
@@ -11,19 +14,47 @@ class BillplzTransactionReviewController extends Controller
|
|||||||
{
|
{
|
||||||
$date = request()->selectedDate ?? Carbon::now()->toDateString();
|
$date = request()->selectedDate ?? Carbon::now()->toDateString();
|
||||||
|
|
||||||
[$pkbTransactionsReview, $kopkbTransactionsReview] = Http::get(config('api.url_arrahn_portal') . '/api/billplz-transaction-review', ['date' => $date])->json();
|
try {
|
||||||
|
$response = Http::get(config('api.url_arrahn_portal') . '/api/billplz-transaction-review', ['date' => $date]);
|
||||||
|
|
||||||
|
if ($response->failed()) {
|
||||||
|
throw new \Exception('ArrahnPay portal returned ' . $response->status());
|
||||||
|
}
|
||||||
|
|
||||||
|
[$pkbTransactionsReview, $kopkbTransactionsReview] = $response->json();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Billplz transaction review index failed', [
|
||||||
|
'date' => $date,
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect()->back()->with('errormessage', 'Portal ArrahnPay kemungkinan tidak beroperasi. Waktu Operasi Portal ArrahnPay adalah dari 7.30 AM hingga 11.30 PM');
|
||||||
|
}
|
||||||
|
|
||||||
return view('online.billplz-transaction-review.index', compact('pkbTransactionsReview', 'kopkbTransactionsReview', 'date'));
|
return view('online.billplz-transaction-review.index', compact('pkbTransactionsReview', 'kopkbTransactionsReview', 'date'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($bill_id)
|
public function show($bill_id)
|
||||||
{
|
{
|
||||||
$billPlzTransactionReview = Http::get(config('api.url_arrahn_portal') . '/api/billplz-transaction-review/'. $bill_id)->json();
|
try {
|
||||||
|
$response = Http::get(config('api.url_arrahn_portal') . '/api/billplz-transaction-review/' . $bill_id);
|
||||||
|
|
||||||
$billPlzTransactionReview = array_filter($billPlzTransactionReview, fn($x) => $x[0]['billplz_latest_transaction'] !== null);
|
if ($response->failed()) {
|
||||||
|
throw new \Exception('ArrahnPay portal returned ' . $response->status());
|
||||||
|
}
|
||||||
|
|
||||||
$billPlzTransactionReview = array_pop($billPlzTransactionReview);
|
$billPlzTransactionReview = $response->json();
|
||||||
|
$billPlzTransactionReview = array_filter($billPlzTransactionReview, fn($x) => $x[0]['billplz_latest_transaction'] !== null);
|
||||||
|
$billPlzTransactionReview = array_pop($billPlzTransactionReview) ?? [];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Billplz transaction review show failed', [
|
||||||
|
'bill_id' => $bill_id,
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect()->back()->with('errormessage', 'Portal ArrahnPay kemungkinan tidak beroperasi. Waktu Operasi Portal ArrahnPay adalah dari 7.30 AM hingga 11.30 PM');
|
||||||
|
}
|
||||||
|
|
||||||
return view('online.billplz-transaction-review.show', compact('billPlzTransactionReview', 'bill_id'));
|
return view('online.billplz-transaction-review.show', compact('billPlzTransactionReview', 'bill_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
<x-filter-date-card title="Billplz Transaction Review" action="{{ route('transaction.online.billplz-transaction-review.index') }}" :selectedDate="$date"/>
|
<x-filter-date-card title="Billplz Transaction Review" action="{{ route('transaction.online.billplz-transaction-review.index') }}" :selectedDate="$date"/>
|
||||||
|
|
||||||
|
|
||||||
@if (Session::has('errormessage'))
|
@if (Session::has('errormessage'))
|
||||||
<div id="errorMessage" class="bg-red-100 border-red-500 text-red-900 text-sm p-4 rounded-lg mb-4" role="alert">
|
<div id="errorMessage" class="bg-red-100 border-red-500 text-red-900 text-sm p-4 rounded-lg mb-4" role="alert">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
|
|||||||
Reference in New Issue
Block a user