diff --git a/app/Console/Commands/updateUnsuccess.php b/app/Console/Commands/updateUnsuccess.php index 3479973..10c769d 100644 --- a/app/Console/Commands/updateUnsuccess.php +++ b/app/Console/Commands/updateUnsuccess.php @@ -51,7 +51,7 @@ class UpdateUnsuccess extends Command return; } - $billplzUpdatedTransactionStatus = array_map(fn($x) => $billplzService->getTransactionByBillId($x), $FailedBillplzID); + $billplzUpdatedTransactionStatus = array_map(fn($x) => $billplzService->getTransactionByBillId($x,$company), $FailedBillplzID); $getCompletedBillplzTransaction = function() use($billplzUpdatedTransactionStatus){ diff --git a/app/Services/BillplzService.php b/app/Services/BillplzService.php index 782d57f..6c05cdf 100644 --- a/app/Services/BillplzService.php +++ b/app/Services/BillplzService.php @@ -240,8 +240,22 @@ class BillplzService return $summarizedBillplzTransactions; } - public function getTransactionByBillId($billId) + public function getTransactionByBillId($billId,$company) { + $appEnvironment = config('app.env'); + + $billplzEnvironments = [ + 'PKB' => ($appEnvironment === 'production') ? config('services.billplz.production') : config('services.billplz.sandbox'), + 'KOPKB' => ($appEnvironment === 'production') ? config('services.billplz.production_kopkb') : config('services.billplz.sandbox_kopkb'), + ]; + + $billplzConfig = $appEnvironment === 'production' + ? ($billplzEnvironments[$company] ?? config('services.billplz.production')) + : ($billplzEnvironments[$company] ?? config('services.billplz.sandbox')); + + $client = Client::make($billplzConfig['api_key'], ($this->isBase64($billplzConfig['x_signature'])) ? $billplzConfig['x_signature'] : base64_encode($billplzConfig['x_signature'])); + $client->useVersion('v4'); + try { return $this->client->bill()->transaction($billId)->toArray(); } catch (\Throwable $th) {