From fb61604c88ec3689e34f200e68e16d773effa85e Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Sun, 16 Feb 2025 11:48:55 +0800 Subject: [PATCH] Fix billplz transaction summary not working --- app/Http/Controllers/BillplzController.php | 9 ++++++--- app/Services/BillplzService.php | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/BillplzController.php b/app/Http/Controllers/BillplzController.php index 898746c..f26cf5a 100644 --- a/app/Http/Controllers/BillplzController.php +++ b/app/Http/Controllers/BillplzController.php @@ -12,14 +12,17 @@ class BillplzController extends Controller public function __invoke(Request $request) { $companyMapping = [ - CompanyStatus::COM_PKB, - // CompanyStatus::COM_KOOPPKB, + 'PKB', + 'KOPKB', ]; $bills = array_map(function($company_code) use($request){ $billplzService = new BillplzService($company_code); $billIdArray = json_decode($request->bill_ids); - return $billplzService->getBills($billIdArray); + $billIdArray = $billplzService->getBills($billIdArray); + return array_filter($billIdArray, function($bill) { + return $bill !== []; + }); }, $companyMapping); return array_merge(...$bills); diff --git a/app/Services/BillplzService.php b/app/Services/BillplzService.php index 512766d..0466a49 100644 --- a/app/Services/BillplzService.php +++ b/app/Services/BillplzService.php @@ -267,7 +267,13 @@ class BillplzService public function getBills($billIds) { - return array_map(fn($x) => $this->client->bill()->get($x)->toArray(), $billIds); + return array_map(function($x){ + try{ + return $this->client->bill()->get($x)->toArray(); + }catch(\Exception $e){ + return []; + } + }, $billIds); } protected function setupBillplzClient($company)