diff --git a/app/Http/Controllers/BillplzController.php b/app/Http/Controllers/BillplzController.php index f26cf5a..443b6d8 100644 --- a/app/Http/Controllers/BillplzController.php +++ b/app/Http/Controllers/BillplzController.php @@ -16,16 +16,17 @@ class BillplzController extends Controller 'KOPKB', ]; - $bills = array_map(function($company_code) use($request){ + $bills = array_reduce($companyMapping, function($carry, $company_code) use($request){ $billplzService = new BillplzService($company_code); $billIdArray = json_decode($request->bill_ids); $billIdArray = $billplzService->getBills($billIdArray); - return array_filter($billIdArray, function($bill) { + $carry[$company_code] = array_filter($billIdArray, function($bill) { return $bill !== []; }); - }, $companyMapping); + return $carry; + }, []); - return array_merge(...$bills); + return $bills; } diff --git a/app/Http/Controllers/BillplzTransactionReviewController.php b/app/Http/Controllers/BillplzTransactionReviewController.php index 8bc8979..5160b32 100644 --- a/app/Http/Controllers/BillplzTransactionReviewController.php +++ b/app/Http/Controllers/BillplzTransactionReviewController.php @@ -18,13 +18,12 @@ class BillplzTransactionReviewController extends Controller 'KOPKB', ]; - $billplzTransactionReview = array_reduce($companyMapping, function($carry, $company_code) use($date){ + $billplzTransactionReview = array_map(function($company_code) use($date){ $billplzService = new BillplzService($company_code); - $carry[$company_code] = $billplzService->getBillplzTransactionReview($date)->toArray(); - return $carry; - }, []); + return $billplzService->getBillplzTransactionReview($date)->toArray(); + }, $companyMapping); - return response()->json($billplzTransactionReview, 200); + return response()->json(array_merge(...$billplzTransactionReview), 200); } public function show(Request $request)