client = new Client(['base_uri' => $default, 'timeout' => 0]); } public function setPembayaranP1(string $nip, int $tahun, int $bulan): bool { try { $response = $this->client->post('api/v1/update-paid-at-psatu', [ 'multipart' => [ ['name' => 'nip', 'contents' => $nip], ['name' => 'tahun', 'contents' => (string) $tahun], ['name' => 'bulan', 'contents' => (string) $bulan], ], 'connect_timeout' => 5, 'timeout' => 15, ]); $data = json_decode((string) $response->getBody(), true); if (! is_array($data) || (array_key_exists('status', $data) && ! $data['status']) || (array_key_exists('success', $data) && ! $data['success']) || (isset($data['meta']['code']) && (int) $data['meta']['code'] >= 400)) { throw new Error($data['message'] ?? $data['meta']['message'] ?? 'Respons pembayaran DAWAI tidak berhasil'); } return true; } catch (Throwable $th) { Log::error('DAWAI pembayaran P1: '.$th->getMessage(), compact('nip', 'tahun', 'bulan')); return false; } } public function getDataP1Response(?string $jenisPegawai, int $tahun, int $bulan, ?int $unit): array { try { $response = $this->client->get("api/v1/psatu/$tahun/$bulan/?id_unit=$unit&jenis_pegawai=$jenisPegawai", [ 'connect_timeout' => 3, 'timeout' => 10, ]); $data = json_decode($response->getBody()->getContents(), true); return is_array($data) ? $data : []; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function getDataP1SelisihResponse(?string $jenisPegawai, int $tahun, int $bulan, ?int $unit): array { try { $response = $this->client->get("api/v1/psatu/$tahun/$bulan/?id_unit=$unit&jenis_pegawai=$jenisPegawai&selisih=true", [ 'connect_timeout' => 3, 'timeout' => 10, ]); $data = json_decode($response->getBody()->getContents(), true); return is_array($data) ? $data : []; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } }