42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\CompanyStatus;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class CustomerInfoService
|
|
{
|
|
public static function get($icno, $endpoint = '/portal/customer/info')
|
|
{
|
|
$pkbUrl = rtrim(config('api.url'), '/');
|
|
$koopUrl = rtrim(config('api.url_koop'), '/');
|
|
|
|
// A shared API must only contribute once to the combined customer data.
|
|
$responses = Http::pool(function ($pool) use ($pkbUrl, $koopUrl, $icno, $endpoint) {
|
|
$requests = [
|
|
$pool->withOptions(['verify' => config('app.api_verify')])
|
|
->get($pkbUrl . $endpoint, ['ic' => $icno]),
|
|
];
|
|
|
|
if ($koopUrl !== $pkbUrl) {
|
|
$requests[] = $pool->withOptions(['verify' => config('app.api_verify')])
|
|
->get($koopUrl . $endpoint, ['ic' => $icno]);
|
|
}
|
|
|
|
return $requests;
|
|
});
|
|
|
|
$customer = $responses[0]->json();
|
|
|
|
if ($pkbUrl === $koopUrl) {
|
|
// Preserve the source company: payment rules depend on this identity.
|
|
return config('api.company') == CompanyStatus::COM_KOOPPKB
|
|
? [[], $customer]
|
|
: [$customer, []];
|
|
}
|
|
|
|
return [$customer, $responses[1]->json()];
|
|
}
|
|
}
|