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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-2
@@ -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'),
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
@@ -85,8 +85,9 @@
|
||||
{{ $t_akhir }}
|
||||
</td>
|
||||
@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;
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<form method="post" id="formtable" action="{{ route('payment.action') }}">
|
||||
@csrf
|
||||
|
||||
@error('chkboxsag')
|
||||
@error('totalSagInCart')
|
||||
<script>
|
||||
$.notify({
|
||||
icon: 'fas fa-exclamation-triangle fa-2x',
|
||||
@@ -136,12 +136,44 @@
|
||||
"scrollX": true
|
||||
});
|
||||
|
||||
// Add event listener to checkboxes to update total count customer wants to pay
|
||||
document.querySelectorAll('input[type="checkbox"][name="chkboxsag[]"]').forEach(function(el) {
|
||||
el.addEventListener('change', function(event) {
|
||||
var total = document.querySelectorAll('input[type="checkbox"][name="chkboxsag[]"]:checked').length;
|
||||
document.getElementById('totalsag').innerHTML = total;
|
||||
});
|
||||
let totalSagInCart = [];
|
||||
|
||||
let updateSagInCart = function(norujukan){
|
||||
|
||||
let isNorujukanIsAlreadyInCart = totalSagInCart.includes(norujukan);
|
||||
|
||||
if(isNorujukanIsAlreadyInCart){
|
||||
totalSagInCart = totalSagInCart.filter(x => x != norujukan);
|
||||
}
|
||||
|
||||
if(! isNorujukanIsAlreadyInCart){
|
||||
totalSagInCart.push(norujukan);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Add event listener to checkboxes to update total count customer wants to pay
|
||||
$('#main-table').on('input', 'input[type="checkbox"][name="chkboxsag[]"]', function(el) {
|
||||
let norujukan = el.target.dataset.norujukan;
|
||||
let isNorujukanIsChecked = el.target.checked;
|
||||
|
||||
updateSagInCart(norujukan);
|
||||
|
||||
document.getElementById('totalsag').innerHTML = totalSagInCart.length;
|
||||
});
|
||||
|
||||
document.querySelector('form#formtable').addEventListener('submit', function(event){
|
||||
event.preventDefault();
|
||||
|
||||
// create new input
|
||||
let totalSagInCartInput = document.createElement('input');
|
||||
totalSagInCartInput.type = 'hidden';
|
||||
totalSagInCartInput.name = 'totalSagInCartInput';
|
||||
totalSagInCartInput.value = JSON.stringify(totalSagInCart);
|
||||
event.target.appendChild(totalSagInCartInput);
|
||||
|
||||
event.target.submit();
|
||||
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
@foreach ($pembiayaan as $data)
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" onclick="tickfunc(this)" name="chkboxsag[]" value="{{ $data->norujukan }}"
|
||||
<input type="checkbox" name="chkboxsag[]" value="{{ $data->norujukan }}"
|
||||
id="sag-{{ $loop->iteration }}" data-norujukan="{{ $data->norujukan }}"
|
||||
{{ $data->disabled_payment ? 'disabled' : '' }} />
|
||||
</td>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
@foreach ($pembiayaan as $data)
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" onclick="tickfunc(this)" name="chkboxsag[]" value="{{ $data->norujukan }}"
|
||||
<input type="checkbox" name="chkboxsag[]" value="{{ $data->norujukan }}"
|
||||
id="sag-{{ $loop->iteration }}" data-norujukan="{{ $data->norujukan }}"
|
||||
{{ $data->disabled_payment ? 'disabled' : '' }} />
|
||||
</td>
|
||||
@@ -26,7 +26,7 @@
|
||||
</td>
|
||||
<td class="hide-xs">{{ $data->tempoh }}</td>
|
||||
<td>{{ $data->tarikh_akhir }}</td>
|
||||
<td>{{ $data->keuntungan_formatted }}</td>
|
||||
<td>{{ $data->upah_tawarruq_formatted }}</td>
|
||||
<td class="hide-xs">{{ $data->cawangan_name }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
||||
Reference in New Issue
Block a user