694e1af651
- update jomweb/billplz package - refactor controllers, views with means of to simplify data fetch and manipuation
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Http\Client\Pool;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class BayaranHistoryService
|
|
{
|
|
public $norujukanList;
|
|
|
|
public function __construct($norujukanList) {
|
|
$this->norujukanList = $norujukanList;
|
|
}
|
|
|
|
public function getBayaranHistory()
|
|
{
|
|
$getBayaranHistory = function () {
|
|
return Http::pool(function (Pool $pool){
|
|
foreach ($this->norujukanList as $norujukan) {
|
|
$pool->get(config('api.url') . '/api/transaction/' . $norujukan);
|
|
}
|
|
});
|
|
};
|
|
|
|
$bayaranHistoryResponse = array_map(fn($x) => $x->json(), $getBayaranHistory());
|
|
|
|
$formatBayaranHistoryData = function ($x) {
|
|
if (sizeof($x) === 0) {
|
|
return $x;
|
|
}
|
|
|
|
$formatDate = fn($x) => Carbon::parse($x)->format('d/m/Y');
|
|
$setResitAnsuranLink = fn($x) => route("resit.ansuran", $x);
|
|
|
|
return array_map(function ($y) use ($formatDate, $setResitAnsuranLink) {
|
|
$y['created_at'] = $formatDate($y['created_at']);
|
|
$y['resit_ansuran_link'] = $setResitAnsuranLink($y['id']);
|
|
return $y;
|
|
}, $x);
|
|
};
|
|
|
|
return array_map($formatBayaranHistoryData, $bayaranHistoryResponse);
|
|
}
|
|
|
|
public static function from($norujukanList)
|
|
{
|
|
return new static($norujukanList);
|
|
}
|
|
|
|
}
|