81 lines
2.8 KiB
PHP
81 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\P1Dev;
|
|
|
|
use Error;
|
|
use GuzzleHttp\Client;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Throwable;
|
|
|
|
class DawaiService extends \App\Services\DawaiService
|
|
{
|
|
private Client $client;
|
|
|
|
public function __construct($default = 'http://172.16.40.128/')
|
|
{
|
|
parent::__construct($default);
|
|
$this->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);
|
|
}
|
|
}
|
|
}
|