From d4573d78ac18d0eef5d2bad95fa5e59b2f281163 Mon Sep 17 00:00:00 2001 From: Afiq Hamzah Date: Thu, 18 Jul 2024 09:15:20 +0800 Subject: [PATCH] Codebase update - Fix select sag to pay on multiple page not selected in checkout payment - Fix marhun modal data not display - Fix load upah tawarruq for jeniskeuntungan onepercent or asal - Add exception when billplz credential is incorrectly entered --- app/Http/Controllers/BayaranController.php | 39 +++++++++++++++- app/Services/BillplzService.php | 9 +++- app/Services/MarhunService.php | 37 +++++++-------- app/Services/PembiayaanService.php | 45 ++++++++++++++---- config/services.php | 4 +- .../includes/bayaran/pembayaransag.blade.php | 3 +- resources/views/includes/home.blade.php | 46 ++++++++++++++++--- .../table-pembiayaan-akan-dilelong.blade.php | 2 +- .../partials/table-pembiayaan.blade.php | 4 +- 9 files changed, 145 insertions(+), 44 deletions(-) diff --git a/app/Http/Controllers/BayaranController.php b/app/Http/Controllers/BayaranController.php index fe35372..9598d94 100644 --- a/app/Http/Controllers/BayaranController.php +++ b/app/Http/Controllers/BayaranController.php @@ -12,18 +12,22 @@ use Money\Money; class BayaranController extends Controller { + public function PembayaranAction(Request $request) { + $totalSagInCartInput = $request->totalSagInCartInput; $validated = $request->validate([ - 'chkboxsag' => 'required', + 'totalSagInCartInput' => 'required', ]); - $norujukanList = $request->chkboxsag; + $norujukanList = json_decode($request->totalSagInCartInput); $arraybayar = array_map(fn($x) => Http::arrahn()->get('/api/gadai/norujukan/' . $x)->json()[0][0], $norujukanList); + $arraybayar = $this->setUpahTawarruq($arraybayar); + $norujukanRecentlyAttemptPayment = array_map( fn($x) => Http::arrahn()->get('/portal/searchsagonline/', ['norujukan' => $x])->json(), $norujukanList @@ -83,6 +87,7 @@ class BayaranController extends Controller return Money::MYR($sum())->add($billPlzTransactionFee); }; + $bill = $billplzService->createBill([ $customerEmail, $customerPhoneNumber, @@ -281,4 +286,34 @@ class BayaranController extends Controller return view('includes.bayaran.senaraibayaransag', compact('belum_tebus', 'api_url')); } + + private function setUpahTawarruq($pembiayaan) + { + $getJenisKeuntungan = function($x){ + + $jenisKeuntungan = [ + '1' => 'onepercent', + '0' => 'asal', + ]; + + return $jenisKeuntungan[$x['tagbaru']]; + }; + + $getUpahTawarruqPerPembiayaan = function($x) use($getJenisKeuntungan){ + $jenisKeuntungan = $getJenisKeuntungan($x); + $upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/'.$x['kodcaw'].'/'.$x['norujukan'], ['jeniskeuntungan' => $jenisKeuntungan])->json(); + + if($jenisKeuntungan == 'onepercent'){ + $x['upah_tawarruq'] = $upahTawarruq['pendapatan'] + $upahTawarruq['keuntungan']; + } + + if($jenisKeuntungan == 'asal'){ + $x['upah_tawarruq'] = $upahTawarruq; + } + + return $x; + }; + + return array_map($getUpahTawarruqPerPembiayaan, $pembiayaan); + } } diff --git a/app/Services/BillplzService.php b/app/Services/BillplzService.php index 1447b6a..68f25cb 100644 --- a/app/Services/BillplzService.php +++ b/app/Services/BillplzService.php @@ -48,7 +48,14 @@ class BillplzService $this->redirectUrl, ]; - return $this->client->bill()->create(...$composed_data)->toArray(); + + try{ + return $this->client->bill()->create(...$composed_data)->toArray(); + } catch(\Exception $e){ + if($e->getCode() === 404){ + throw new \ErrorException('Please check your billplz payment gateway collection. Ensure that api_key, x_signature, and collection_id are correctly entered'); + }; + } } public function redirect($request) diff --git a/app/Services/MarhunService.php b/app/Services/MarhunService.php index 223b4a5..b114851 100644 --- a/app/Services/MarhunService.php +++ b/app/Services/MarhunService.php @@ -2,7 +2,6 @@ namespace App\Services; -use Illuminate\Http\Client\Pool; use Illuminate\Support\Facades\Http; class MarhunService @@ -15,31 +14,29 @@ class MarhunService public function getMarhunDetails() { - $getMarhunDetails = function () { - return Http::pool(function (Pool $pool) { - foreach ($this->norujukanList as $norujukan) { - $pool->get(config('api.url') . '/api/marhun/' . $norujukan); - } - }); + $getMarhunDetails = function ($x) { + return Http::arrahn()->get('/api/marhun/' . $x)->json(); }; - - $marhunDetailsResponse = array_map(fn($x) => $x->json() == null ? [] : $x->Json(), $getMarhunDetails()); - $marhunDetailsResponse = array_map(fn($x) => array_merge([], ...$x), $marhunDetailsResponse); - - $formatMarhunDetailData = function ($x) { - $getMarhunTypeFullName = function ($code) { - - $marhun = Http::get(config('api.url') . '/api/jemas/nama_marhun', ['marhun' => $code])->json()['descpt']; - return $marhun; - }; - + + $getMarhunTypeFullName = function ($code) { + return Http::arrahn()->get('/api/jemas/nama_marhun', ['marhun' => $code['marhun']])->json()['descpt']; + }; + + $formatMarhunDetailData = function ($x) use($getMarhunTypeFullName) { return array_map(function ($y) use ($getMarhunTypeFullName) { - $y['marhun'] = $getMarhunTypeFullName($y['marhun']); + $y['marhun'] = $getMarhunTypeFullName($y); return $y; }, $x); }; - return array_map($formatMarhunDetailData, $marhunDetailsResponse); + $marhunDetailPipelines = [ + fn($x) => array_map($getMarhunDetails, $x), + fn($x) => array_map(fn($y) => $x == null ? [] : $y, $x), + fn($x) => array_map(fn($y) => array_merge([], ...$y), $x), + fn($x) => array_map($formatMarhunDetailData, $x), + ]; + + return array_reduce($marhunDetailPipelines, fn($x, $y) => $y($x), $this->norujukanList); } public static function from($norujukanList) diff --git a/app/Services/PembiayaanService.php b/app/Services/PembiayaanService.php index 5398c20..9f083b1 100644 --- a/app/Services/PembiayaanService.php +++ b/app/Services/PembiayaanService.php @@ -22,19 +22,48 @@ class PembiayaanService $getPembiayaan = fn() => (new InformationController())->pembiayaanakandilelong()->getData(); } - $pembiayaan = $this->formatPembiayaanData($getPembiayaan()); + $pembiayaan = array_filter($getPembiayaan(), fn($x) => $x->hargajualan != null || $x->hargajualan != 0); + $pembiayaan = $this->setUpahTawarruq($pembiayaan); + $pembiayaan = $this->formatPembiayaanData($pembiayaan); $pembiayaan = $this->attachMarhunModalData($pembiayaan); $pembiayaan = $this->checkPembiayaanPaymentDisabled($pembiayaan); return $pembiayaan; + } + private function setUpahTawarruq($pembiayaan) + { + $getJenisKeuntungan = function($x){ + + $jenisKeuntungan = [ + '1' => 'onepercent', + '0' => 'asal', + ]; + + return $jenisKeuntungan[$x->tagbaru]; + }; + + $getUpahTawarruqPerPembiayaan = function($x) use($getJenisKeuntungan){ + $jenisKeuntungan = $getJenisKeuntungan($x); + $upahTawarruq = Http::arrahn()->get('/api/upahtawarruq/'.$x->kodcaw.'/'.$x->norujukan, ['jeniskeuntungan' => $jenisKeuntungan])->json(); + + if($jenisKeuntungan == 'onepercent'){ + $x->upah_tawarruq = $upahTawarruq['pendapatan'] + $upahTawarruq['keuntungan']; + } + + if($jenisKeuntungan == 'asal'){ + $x->upah_tawarruq = $upahTawarruq; + } + + return $x; + }; + + return array_map($getUpahTawarruqPerPembiayaan, $pembiayaan); } private function formatPembiayaanData($pembiayaan) { - $allCawangan = Http::withOptions(['verify' => config('app.api_verify')]) - ->get(config('api.url') . '/api/cawangan') - ->json(); + $allCawangan = Http::arrahn()->get('/api/cawangan')->json(); $setCawanganFullName = function ($pembiayaan) use ($allCawangan) { $cawangan = array_filter($allCawangan, fn($x) => $x['kodcaw'] === $pembiayaan->kodcaw); @@ -42,8 +71,8 @@ class PembiayaanService return $pembiayaan; }; - $setKeuntunganFormatted = function ($pembiayaan) { - $pembiayaan->keuntungan_formatted = number_format((float) $pembiayaan->keuntungan, 2, '.', ''); + $setUpahTawarruqFormatted = function ($pembiayaan) { + $pembiayaan->upah_tawarruq_formatted = number_format((float) $pembiayaan->upah_tawarruq, 2, '.', ''); return $pembiayaan; }; @@ -61,9 +90,9 @@ class PembiayaanService return $pembiayaan; }; - $formatted = array_map(function ($x) use ($setCawanganFullName, $setKeuntunganFormatted, $setTarikhAkhir, $setTLelongFormatted) { + $formatted = array_map(function ($x) use ($setCawanganFullName, $setUpahTawarruqFormatted, $setTarikhAkhir, $setTLelongFormatted) { $x = $setCawanganFullName($x); - $x = $setKeuntunganFormatted($x); + $x = $setUpahTawarruqFormatted($x); $x = $setTarikhAkhir($x); $x = $setTLelongFormatted($x); return $x; diff --git a/config/services.php b/config/services.php index 1bde05b..833feeb 100644 --- a/config/services.php +++ b/config/services.php @@ -34,12 +34,12 @@ return [ 'production' => [ 'api_key' => env('BILLPLZ_PRODUCTION_API_KEY', 'f3e82fe1-a422-4660-97f0-65cc59ff6c47'), 'x_signature' => env('BILLPLZ_PRODUCTION_X_SIGNATURE', 'S-alZUbzmD2_TF3vmrRqgehQ'), - 'collection_id' => env('BILLPLZ_PRODUCTION_COLLECTION_ID', 'z0r4kjhi'), + 'collection_id' => env('BILLPLZ_SANDBOX_COLLECTION_ID', '5aosv2dg'), ], 'sandbox' => [ 'api_key' => env('BILLPLZ_SANDBOX_API_KEY', 'abecfd0c-98d8-4635-abc2-2fcba8c60c11'), 'x_signature' => env('BILLPLZ_SANDBOX_X_SIGNATURE', 'S-GWr7z03XjAhqPsFfu_H5nQ'), - 'collection_id' => env('BILLPLZ_SANDBOX_COLLECTION_ID', '5aosv2dg'), + 'collection_id' => env('BILLPLZ_PRODUCTION_COLLECTION_ID', 'z0r4kjhi'), ], ], diff --git a/resources/views/includes/bayaran/pembayaransag.blade.php b/resources/views/includes/bayaran/pembayaransag.blade.php index 592bee5..3926492 100644 --- a/resources/views/includes/bayaran/pembayaransag.blade.php +++ b/resources/views/includes/bayaran/pembayaransag.blade.php @@ -85,8 +85,9 @@ {{ $t_akhir }} @php - $upahtawarruq = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/upahtawarruq/'. $bayar['kodcaw'] . '/' . $bayar['norujukan'])->json(); + $upahtawarruq = $bayar['upah_tawarruq']; $upahtawarruq = floatval(str_replace(',','',$upahtawarruq)); + $totalupahasal = $totalupahasal + $upahtawarruq; diff --git a/resources/views/includes/home.blade.php b/resources/views/includes/home.blade.php index ef08b1f..39a3fcd 100644 --- a/resources/views/includes/home.blade.php +++ b/resources/views/includes/home.blade.php @@ -39,7 +39,7 @@
@csrf - @error('chkboxsag') + @error('totalSagInCart') @endsection diff --git a/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php b/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php index a7e4266..b4c6648 100644 --- a/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php +++ b/resources/views/includes/partials/table-pembiayaan-akan-dilelong.blade.php @@ -12,7 +12,7 @@ @foreach ($pembiayaan as $data) - disabled_payment ? 'disabled' : '' }} /> diff --git a/resources/views/includes/partials/table-pembiayaan.blade.php b/resources/views/includes/partials/table-pembiayaan.blade.php index efcc526..c059049 100644 --- a/resources/views/includes/partials/table-pembiayaan.blade.php +++ b/resources/views/includes/partials/table-pembiayaan.blade.php @@ -14,7 +14,7 @@ @foreach ($pembiayaan as $data) - disabled_payment ? 'disabled' : '' }} /> @@ -26,7 +26,7 @@ {{ $data->tempoh }} {{ $data->tarikh_akhir }} - {{ $data->keuntungan_formatted }} + {{ $data->upah_tawarruq_formatted }} {{ $data->cawangan_name }} @endforeach