card = $card; } /** * Execute the job. * * @return void */ public function handle(): void { try { if ($this->needBranchAndCurrencyUpdate()) { $accountInfo = $this->getAccountInfo($this->card->accflag); if ($accountInfo && isset($accountInfo['responseCode']) && $accountInfo['responseCode'] === '00') { $this->updateBranchAndCurrency($accountInfo); Log::info("Berhasil memperbarui branch dan currency untuk kartu {$this->card->crdno}"); } else { Log::warning("Gagal mendapatkan informasi akun untuk kartu {$this->card->crdno}. Response: " . json_encode($accountInfo ?? ['error' => 'No response'])); } } } catch (Exception $e) { Log::error("Error saat memperbarui branch dan currency untuk kartu {$this->card->crdno}: " . $e->getMessage(), [ 'file' => $e->getFile(), 'line' => $e->getLine() ]); } } /** * Check if branch and currency update is needed * * @return bool */ private function needBranchAndCurrencyUpdate(): bool { return empty($this->card->branch) || empty($this->card->currency); } /** * Get account information from Account model or API * * @param string $accountNumber * @return array|null */ private function getAccountInfo(string $accountNumber): ?array { try { // Coba dapatkan data dari model Account terlebih dahulu $account = Account::where('account_number', $accountNumber)->first(); if ($account) { // Jika account ditemukan, format data sesuai dengan format response dari API return [ 'responseCode' => '00', 'acctCompany' => $account->branch_code, 'acctCurrency' => $account->currency, 'acctType' => $account->open_category // Tambahkan field lain yang mungkin diperlukan ]; } // Jika tidak ditemukan di database, ambil dari Fiorano API $url = env('FIORANO_URL') . self::API_BASE_PATH; $path = self::API_INQUIRY_PATH; $data = [ 'accountNo' => $accountNumber, ]; $response = Http::post($url . $path, $data); return $response->json(); } catch (Exception $e) { Log::error("Gagal mendapatkan informasi akun: " . $e->getMessage()); return null; } } /** * Update branch and currency information for the card * * @param array $accountInfo * @return void */ private function updateBranchAndCurrency(array $accountInfo): void { $cardData = [ 'branch' => !empty($accountInfo['acctCompany']) ? $accountInfo['acctCompany'] : null, 'currency' => !empty($accountInfo['acctCurrency']) ? $accountInfo['acctCurrency'] : null, 'product_code' => !empty($accountInfo['acctType']) ? $accountInfo['acctType'] : null, ]; $this->card->update($cardData); } }