Resolve conflicts
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\TransactionOnlineStatus;
|
||||
use App\Services\BillplzService;
|
||||
use App\Services\OnlineTransactionLoggerService;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
@@ -50,11 +52,22 @@ class UpdateUnsuccess extends Command
|
||||
};
|
||||
|
||||
foreach($getCompletedBillplzTransaction() as $transaction){
|
||||
Http::arrahn()->put('/api/transaction/online/unsuccesfull/update',[
|
||||
$transactionData = [
|
||||
'billplz_id' => $transaction['bill_id'],
|
||||
'status' => 'PAID',
|
||||
'paid_at' => $transaction['transactions'][0]['completed_at']
|
||||
]);
|
||||
];
|
||||
|
||||
try {
|
||||
$response = Http::arrahn()->put('/api/transaction/online/unsuccesfull/update', $transactionData);
|
||||
OnlineTransactionLoggerService::logs($transaction['bill_id'], $transactionData, $response, TransactionOnlineStatus::UPDATE_UNSUCCESSFUL_TRANSACTION );
|
||||
|
||||
} catch (\Exception $e) {
|
||||
OnlineTransactionLoggerService::logs($transaction['bill_id'], $transactionData, $e->getMessage(), TransactionOnlineStatus::UPDATE_UNSUCCESSFUL_TRANSACTION );
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,50 +2,25 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\PaymentRequest;
|
||||
use App\Models\TransactionOnlineStatus;
|
||||
use App\Services\BillplzService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Client\Pool;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Money\Money;
|
||||
use App\Services\OnlineTransactionLoggerService;
|
||||
|
||||
class BayaranController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function PembayaranAction(Request $request)
|
||||
public function PembayaranAction(PaymentRequest $request)
|
||||
{
|
||||
$totalSagInCartInput = $request->totalSagInCartInput;
|
||||
$request->validated();
|
||||
|
||||
$validated = $request->validate([
|
||||
'totalSagInCartInput' => 'required',
|
||||
]);
|
||||
|
||||
$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
|
||||
);
|
||||
|
||||
$isNorujukanRecentlyAttemptPayment = in_array(true, $norujukanRecentlyAttemptPayment);
|
||||
|
||||
if ($isNorujukanRecentlyAttemptPayment) {
|
||||
return redirect()->route('home')->with('errorsagonline', 'Sila Tunggu Sebentar!');
|
||||
}
|
||||
|
||||
$gadaiContractExceed12Month = array_filter($arraybayar, fn($x) => $x['tempoh'] >= 12);
|
||||
|
||||
$isGadaiContractExceed12Month = sizeof($gadaiContractExceed12Month) > 0;
|
||||
|
||||
if ($isGadaiContractExceed12Month) {
|
||||
return redirect()->route('home')->with('error', 'SAG Yang Dipilih Akan/Telah Tamat Kontrak 12 Bulan. Sila Hadir Ke Kaunter Cawangan Untuk Pembayaran/Penebusan.');
|
||||
}
|
||||
$arraybayar = $this->setUpahTawarruq($request->getPembiayaanFromNorujukan());
|
||||
|
||||
return view('includes.bayaran.pembayaransag', compact('arraybayar'));
|
||||
}
|
||||
@@ -87,13 +62,7 @@ class BayaranController extends Controller
|
||||
return Money::MYR($sum())->add($billPlzTransactionFee);
|
||||
};
|
||||
|
||||
|
||||
$bill = $billplzService->createBill([
|
||||
$customerEmail,
|
||||
$customerPhoneNumber,
|
||||
$customerName,
|
||||
$getPaymentSum(),
|
||||
]);
|
||||
$bill = $billplzService->createBill([$customerEmail, $customerPhoneNumber, $customerName, $getPaymentSum()]);
|
||||
|
||||
$isRecordTransactionSuccess = $this->recordTransaction($paymentArray, $bill);
|
||||
|
||||
@@ -105,12 +74,10 @@ class BayaranController extends Controller
|
||||
|
||||
return redirect($bill['url'] . '?auto_submit=true');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function recordTransaction($paymentArray, $bill)
|
||||
{
|
||||
|
||||
['name' => $customerName, 'icno' => $customerIcno] = auth()->user()->toArray();
|
||||
|
||||
$getlatestNoSiri = function () {
|
||||
@@ -125,27 +92,49 @@ class BayaranController extends Controller
|
||||
$generateTransactionReferenceNumber = function () use ($getlatestNoSiri) {
|
||||
[$day, $month, $year] = [now()->day, now()->month, now()->format('y')];
|
||||
|
||||
return 'APKB' . $day . $month . $year . sprintf("%08d", $getlatestNoSiri());
|
||||
return 'APKB' . $day . $month . $year . sprintf('%08d', $getlatestNoSiri());
|
||||
};
|
||||
|
||||
Http::pool(fn(Pool $pool) =>
|
||||
collect($paymentArray)->map(fn($payment) =>
|
||||
$pool->arrahn()->post('/api/online/transaction', [
|
||||
'nokp' => $customerIcno,
|
||||
'reference_no' => $generateTransactionReferenceNumber(),
|
||||
'nosiri' => $getlatestNoSiri(),
|
||||
'billplz_id' => $bill['id'],
|
||||
'norujukan' => $payment['norujukan'],
|
||||
'kodcaw' => $payment['kodcaw'],
|
||||
'total_payment' => $payment['bayaran'],
|
||||
'customer_name' => $customerName,
|
||||
])
|
||||
)
|
||||
);
|
||||
try {
|
||||
Http::pool(
|
||||
fn(Pool $pool) => collect($paymentArray)->map(
|
||||
fn($payment) => $pool->arrahn()->post('/api/online/transaction', [
|
||||
'nokp' => $customerIcno,
|
||||
'reference_no' => $generateTransactionReferenceNumber(),
|
||||
'nosiri' => $getlatestNoSiri(),
|
||||
'billplz_id' => $bill['id'],
|
||||
'norujukan' => $payment['norujukan'],
|
||||
'kodcaw' => $payment['kodcaw'],
|
||||
'total_payment' => $payment['bayaran'],
|
||||
'customer_name' => $customerName,
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
Http::arrahn()->put('/api/transaction/online/tagportal', [
|
||||
'billplz_id' => $bill['id'],
|
||||
])->json();
|
||||
OnlineTransactionLoggerService::logs($bill['id'], $paymentArray, 1, TransactionOnlineStatus::INITIALIZED_TRANSACTION);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
OnlineTransactionLoggerService::logs($bill['id'], $paymentArray, $e->getMessage(), TransactionOnlineStatus::INITIALIZED_TRANSACTION);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::arrahn()
|
||||
->put('/api/transaction/online/tagportal', [
|
||||
'billplz_id' => $bill['id'],
|
||||
])
|
||||
->json();
|
||||
|
||||
OnlineTransactionLoggerService::logs($bill['id'], $paymentArray, $response, TransactionOnlineStatus::UPDATED_TAG_PORTAL);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
OnlineTransactionLoggerService::logs($bill['id'], $paymentArray, $e->getMessage(), TransactionOnlineStatus::UPDATED_TAG_PORTAL);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -156,23 +145,30 @@ class BayaranController extends Controller
|
||||
|
||||
$kpbaru = Auth::User()->icno;
|
||||
|
||||
$customer = Http::arrahn()->get('/api/customers/' . $kpbaru)->json();
|
||||
$customer = Http::arrahn()
|
||||
->get('/api/customers/' . $kpbaru)
|
||||
->json();
|
||||
$customer_details = $customer;
|
||||
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
$date = $current->toDateTimeString();
|
||||
|
||||
$cawangan_info = Http::arrahn()->get('/api/cawangan/' . $payment_details['kodcaw'])->json();
|
||||
$cawangan = Http::arrahn()->get('/api/cawangan/detail/' . $payment_details['kodcaw'])->json();
|
||||
$cawangan_info = Http::arrahn()
|
||||
->get('/api/cawangan/' . $payment_details['kodcaw'])
|
||||
->json();
|
||||
$cawangan = Http::arrahn()
|
||||
->get('/api/cawangan/detail/' . $payment_details['kodcaw'])
|
||||
->json();
|
||||
$cawangan_detail = $cawangan[0];
|
||||
$nama_cawangan = $cawangan_info['details_caw'];
|
||||
|
||||
$gadai_details = Http::arrahn()->get('/api/gadai/norujukan/' . $payment_details['norujukan'])->json();
|
||||
$gadai_details = Http::arrahn()
|
||||
->get('/api/gadai/norujukan/' . $payment_details['norujukan'])
|
||||
->json();
|
||||
$gadai = $gadai_details[0][0];
|
||||
|
||||
return view('pembayaran.resit.resitportal', compact('customer_details', 'payment_details', 'cawangan_detail', 'nama_cawangan', 'gadai'));
|
||||
|
||||
}
|
||||
|
||||
public function callback(Request $request, BillplzService $billplzService)
|
||||
@@ -189,7 +185,6 @@ class BayaranController extends Controller
|
||||
]);
|
||||
|
||||
return response(200);
|
||||
|
||||
}
|
||||
|
||||
Http::arrahn()->put('/api/online/transaction', [
|
||||
@@ -203,7 +198,6 @@ class BayaranController extends Controller
|
||||
|
||||
public function response(Request $request, BillplzService $billplzService)
|
||||
{
|
||||
|
||||
$data = $billplzService->redirect($request->toArray());
|
||||
|
||||
$isBillUnpaid = $data['paid'] !== true;
|
||||
@@ -215,12 +209,13 @@ class BayaranController extends Controller
|
||||
'paid_at' => null,
|
||||
]);
|
||||
|
||||
$transactionOnline = Http::arrahn()->get('/api/transaction/online/login', [
|
||||
'billplz_id' => $data['id'],
|
||||
])->json();
|
||||
$transactionOnline = Http::arrahn()
|
||||
->get('/api/transaction/online/login', [
|
||||
'billplz_id' => $data['id'],
|
||||
])
|
||||
->json();
|
||||
|
||||
return redirect()->route('pay.failed');
|
||||
|
||||
}
|
||||
|
||||
Http::arrahn()->put('/api/online/transaction', [
|
||||
@@ -229,28 +224,33 @@ class BayaranController extends Controller
|
||||
'paid_at' => $data['paid_at']->format('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
$transactionOnline = Http::arrahn()->get('/api/transaction/online/login', [
|
||||
'billplz_id' => $data['id'],
|
||||
])->json();
|
||||
$transactionOnline = Http::arrahn()
|
||||
->get('/api/transaction/online/login', [
|
||||
'billplz_id' => $data['id'],
|
||||
])
|
||||
->json();
|
||||
|
||||
return redirect()->route('pay.success', [
|
||||
'transactionOnline' => $transactionOnline,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function successPayment(Request $request)
|
||||
{
|
||||
$transactionOnline = $request->transactionOnline;
|
||||
|
||||
|
||||
$arraygadai = array_map(
|
||||
fn($x) => Http::arrahn()->get('/api/gadai/norujukan/' . $x['norujukan'])->json()[0][0],
|
||||
$transactionOnline
|
||||
fn($x) => Http::arrahn()
|
||||
->get('/api/gadai/norujukan/' . $x['norujukan'])
|
||||
->json()[0][0],
|
||||
$transactionOnline,
|
||||
);
|
||||
|
||||
$arraycawangan = array_map(
|
||||
fn($x) => Http::arrahn()->get('/api/cawangan/detail/' . $x['kodcaw'])->json()[0],
|
||||
$transactionOnline
|
||||
fn($x) => Http::arrahn()
|
||||
->get('/api/cawangan/detail/' . $x['kodcaw'])
|
||||
->json()[0],
|
||||
$transactionOnline,
|
||||
);
|
||||
|
||||
return view('pembayaran.result.berjayaportal', compact('transactionOnline', 'arraycawangan', 'arraygadai'));
|
||||
@@ -263,14 +263,15 @@ class BayaranController extends Controller
|
||||
|
||||
public function SenaraiPembayaran()
|
||||
{
|
||||
|
||||
$api_url = config('api.url');
|
||||
|
||||
$arraysag = [];
|
||||
|
||||
$auth_user = Auth::user();
|
||||
|
||||
$belum_tebus = Http::arrahn()->get('/api/customers/' . $auth_user['icno'] . '/gadai/' . 'belum_tebus')->json();
|
||||
$belum_tebus = Http::arrahn()
|
||||
->get('/api/customers/' . $auth_user['icno'] . '/gadai/' . 'belum_tebus')
|
||||
->json();
|
||||
|
||||
if (is_array($belum_tebus)) {
|
||||
if (sizeof($belum_tebus) > 0) {
|
||||
@@ -289,31 +290,32 @@ class BayaranController extends Controller
|
||||
|
||||
private function setUpahTawarruq($pembiayaan)
|
||||
{
|
||||
$getJenisKeuntungan = function($x){
|
||||
$getJenisKeuntungan = function ($x) {
|
||||
$jenisKeuntungan = [
|
||||
'1' => 'onepercent',
|
||||
'0' => 'asal',
|
||||
];
|
||||
|
||||
$jenisKeuntungan = [
|
||||
'1' => 'onepercent',
|
||||
'0' => 'asal',
|
||||
];
|
||||
return $jenisKeuntungan[$x['tagbaru']];
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
$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['keuntungan'] + $upahTawarruq['ujrah'];
|
||||
}
|
||||
|
||||
if($jenisKeuntungan == 'onepercent'){
|
||||
$x['upah_tawarruq'] = $upahTawarruq['keuntungan'] + $upahTawarruq['ujrah'];
|
||||
}
|
||||
if ($jenisKeuntungan == 'asal') {
|
||||
$x['upah_tawarruq'] = $upahTawarruq;
|
||||
}
|
||||
|
||||
if($jenisKeuntungan == 'asal'){
|
||||
$x['upah_tawarruq'] = $upahTawarruq;
|
||||
}
|
||||
return $x;
|
||||
};
|
||||
|
||||
return $x;
|
||||
};
|
||||
|
||||
return array_map($getUpahTawarruqPerPembiayaan, $pembiayaan);
|
||||
return array_map($getUpahTawarruqPerPembiayaan, $pembiayaan);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Http\Controllers\InformationController;
|
||||
use App\Rules\PaymentRules\CawanganPermitUjrahPayment;
|
||||
use App\Rules\PaymentRules\NorujukanBukanFasa2;
|
||||
use App\Rules\PaymentRules\NorujukanContractNotExceed12Month;
|
||||
use App\Rules\PaymentRules\NorujukanNotAttemptPaymentRecently;
|
||||
use App\Rules\PaymentRules\NorujukanTidakAkanDilelong;
|
||||
use App\Rules\PaymentRules\PaymentNotUjrah;
|
||||
use App\Rules\PaymentRules\PilihMinimumSatuSAG;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class PaymentRequest extends FormRequest
|
||||
{
|
||||
public $selectedPembiayaan;
|
||||
public $pembiayaanAkanDilelong;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$this->selectedPembiayaan = $this->getPembiayaanFromNorujukan();
|
||||
$this->pembiayaanAkanDilelong = $this->getPembiayaanAkanDilelong();
|
||||
|
||||
return [
|
||||
'totalSagInCartInput' => [
|
||||
new PilihMinimumSatuSAG,
|
||||
new NorujukanTidakAkanDilelong($this->pembiayaanAkanDilelong),
|
||||
new NorujukanBukanFasa2($this->pembiayaanAkanDilelong),
|
||||
new NorujukanNotAttemptPaymentRecently,
|
||||
new CawanganPermitUjrahPayment($this->selectedPembiayaan),
|
||||
new PaymentNotUjrah($this->selectedPembiayaan),
|
||||
new NorujukanContractNotExceed12Month($this->selectedPembiayaan),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getPembiayaanFromNorujukan()
|
||||
{
|
||||
$norujukanList = json_decode($this->totalSagInCartInput);
|
||||
|
||||
return array_map(fn($x) => Http::arrahn()->get('/api/gadai/norujukan/' . $x)->json()[0][0], $norujukanList);
|
||||
}
|
||||
|
||||
public function getPembiayaanAkanDilelong()
|
||||
{
|
||||
return (new InformationController())->pembiayaanakandilelong()->getData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TransactionOnlineStatus extends Model
|
||||
{
|
||||
const BILL_CREATED = 1;
|
||||
const INITIALIZED_TRANSACTION = 2;
|
||||
const UPDATED_TAG_PORTAL = 3;
|
||||
const UPDATE_TRANSACTION_CALLBACK = 4;
|
||||
const UPDATE_TRANSACTION_REDIRECT = 5;
|
||||
const CRONJOB_UPDATE_TRANSACTION = 6;
|
||||
const CRONJOB_UPDATE_TRANSAKSI_KEUNTUNGAN = 7;
|
||||
const CRONJOB_UDPATE_GADAI = 8;
|
||||
const CRONJOB_REGISTER_AUDIT = 9;
|
||||
const CRONJOB_REGISTER_GLDETAIL = 10;
|
||||
const CRONJOB_UPDATE_TRANSAKSI_ONLINE_CRONJOB = 11;
|
||||
const UPDATE_UNSUCCESSFUL_TRANSACTION = 12;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\PaymentRules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class CawanganPermitUjrahPayment implements Rule
|
||||
{
|
||||
public $pembiayaan;
|
||||
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($pembiayaan)
|
||||
{
|
||||
$this->pembiayaan = $pembiayaan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$getPayableUjrahBranches = fn() => Http::arrahn()->get('/api/payable-ujrah-branches')->json();
|
||||
$branchesNotPermitPaymentUjrah = array_filter($getPayableUjrahBranches(), fn($x) => $x['gadaian_ujrah_payable'] == 0);
|
||||
$kodCawanganBranchesNotPermitPaymentUjrah = array_map(fn($x) => $x['kodcaw'], $branchesNotPermitPaymentUjrah);
|
||||
|
||||
$isNorujukanUjrah = fn($x) => $x['tagbaru'] === 1 ? true : false;
|
||||
|
||||
$isCawanganNotPermitUjrahPayment = function ($x) use ($kodCawanganBranchesNotPermitPaymentUjrah, $isNorujukanUjrah) {
|
||||
|
||||
if ($isNorujukanUjrah($x)) {
|
||||
return in_array($x['kodcaw'], $kodCawanganBranchesNotPermitPaymentUjrah);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
$cawanganNotPermitUjrahPayment = array_filter($this->pembiayaan, fn($x) => $isCawanganNotPermitUjrahPayment($x));
|
||||
|
||||
return sizeof($cawanganNotPermitUjrahPayment) == 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'Tidak dibenarkan pembayaran ujrah!';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\PaymentRules;
|
||||
|
||||
use App\Http\Controllers\InformationController;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class NorujukanBukanFasa2 implements Rule
|
||||
{
|
||||
public $pembiayaanAkanDilelong;
|
||||
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($pembiayaanAkanDilelong)
|
||||
{
|
||||
$this->pembiayaanAkanDilelong = $pembiayaanAkanDilelong;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$norujukanToPay = json_decode($value);
|
||||
|
||||
$setDefaultFasaIfNotAvailable = function ($x) {
|
||||
if (!isset($x->fasa)) {
|
||||
$x->fasa = 1;
|
||||
}
|
||||
return $x;
|
||||
};
|
||||
|
||||
$pembiayaanWithFasa = array_map($setDefaultFasaIfNotAvailable, $this->pembiayaanAkanDilelong);
|
||||
$pembiayaanInFasa2 = array_filter($pembiayaanWithFasa, fn($x) => $x->fasa == 2);
|
||||
$norujukanInFasa2 = array_map(fn($x) => $x->norujukan, $pembiayaanInFasa2);
|
||||
|
||||
$pembiayaanFasa2 = array_filter($norujukanToPay, fn($x) => in_array($x, $norujukanInFasa2));
|
||||
|
||||
return sizeof($pembiayaanFasa2) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'No pembiayaan dalam kategori fasa 2, sila ke kaunter';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\PaymentRules;
|
||||
|
||||
use App\Http\Controllers\InformationController;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class NorujukanContractNotExceed12Month implements Rule
|
||||
{
|
||||
public $pembiayaan;
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($pembiayaan)
|
||||
{
|
||||
$this->pembiayaan = $pembiayaan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$gadaiContractExceed12Month = array_filter($this->pembiayaan, fn($x) => $x['tempoh'] >= 12);
|
||||
|
||||
return sizeof($gadaiContractExceed12Month) == 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'SAG Yang Dipilih Akan/Telah Tamat Kontrak 12 Bulan. Sila Hadir Ke Kaunter Cawangan Untuk Pembayaran/Penebusan.';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\PaymentRules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Http\Client\Pool;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class NorujukanNotAttemptPaymentRecently implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$norujukanToPay = json_decode($value);
|
||||
|
||||
$norujukanRecentlyAttemptPayment = $this->getNorujukanRecentlyAttemptPayment($norujukanToPay);
|
||||
|
||||
return sizeof($norujukanRecentlyAttemptPayment) == 0;
|
||||
|
||||
}
|
||||
|
||||
private function getNorujukanRecentlyAttemptPayment($norujukanList)
|
||||
{
|
||||
$getRecentlyAttemptPayment = function () use ($norujukanList) {
|
||||
return Http::pool(function (Pool $pool) use ($norujukanList) {
|
||||
foreach ($norujukanList as $norujukan) {
|
||||
$pool->get(config('api.url') . '/portal/searchsagonline/', ['norujukan' => $norujukan]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$recentlyAttemptPaymentResponse = array_map(
|
||||
fn($x, $y) => ['norujukan' => $x, 'isRecentlyAttemptPayment' => $y->json()],
|
||||
$norujukanList,
|
||||
$getRecentlyAttemptPayment()
|
||||
);
|
||||
|
||||
$filterRecentlyAttemptPayment = array_filter(
|
||||
$recentlyAttemptPaymentResponse,
|
||||
fn($x) => $x['isRecentlyAttemptPayment'] === true
|
||||
);
|
||||
|
||||
return array_map(fn($x) => $x['norujukan'], $filterRecentlyAttemptPayment);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'Sila Tunggu Sebentar!';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\PaymentRules;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class NorujukanTidakAkanDilelong implements Rule
|
||||
{
|
||||
|
||||
public $pembiayaanAkanDilelong;
|
||||
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($pembiayaanAkanDilelong)
|
||||
{
|
||||
$this->pembiayaanAkanDilelong = $pembiayaanAkanDilelong;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
|
||||
$norujukanToPay = json_decode($value);
|
||||
|
||||
$isCurrentDateGreaterThanEqual3DaysBeforeLelong = function ($x) {
|
||||
$tarikhLelong = Carbon::parse($x->t_lelong);
|
||||
$currentDate = Carbon::now();
|
||||
|
||||
if ($currentDate->gte($tarikhLelong->subDays(3))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
$dataFromPembiayaanAkanDilelong = array_filter($this->pembiayaanAkanDilelong, fn($x) => in_array($x->norujukan, $norujukanToPay));
|
||||
|
||||
$pembiayaanAkanDilelong = array_filter($dataFromPembiayaanAkanDilelong, $isCurrentDateGreaterThanEqual3DaysBeforeLelong);
|
||||
|
||||
return sizeof($pembiayaanAkanDilelong) == 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'No pembiayaan akan dilelong, sila ke kaunter';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\PaymentRules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class PaymentNotUjrah implements Rule
|
||||
{
|
||||
public $pembiayaan;
|
||||
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($pembiayaan)
|
||||
{
|
||||
$this->pembiayaan = $pembiayaan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$norujukanToPay = json_decode($value);
|
||||
|
||||
$isNorujukanUjrah = fn ($x) => $x['tagbaru'] === 1 ? true : false;
|
||||
|
||||
$norujukanUjrah = array_filter($this->pembiayaan, fn($x) => $isNorujukanUjrah($x));
|
||||
|
||||
return sizeof($norujukanUjrah) == 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'Tidak dibenarkan pembayaran ujrah!';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules\PaymentRules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class PilihMinimumSatuSAG implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$norujukanToPay = json_decode($value);
|
||||
|
||||
return sizeof($norujukanToPay) > 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'Sila pilih salah satu checkbox di atas terlebih dahulu!';
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\TransactionOnlineStatus;
|
||||
use Billplz\Client;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class BillplzService
|
||||
@@ -50,23 +50,62 @@ class BillplzService
|
||||
];
|
||||
|
||||
|
||||
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');
|
||||
};
|
||||
}
|
||||
try{
|
||||
$response = $this->client->bill()->create(...$composed_data)->toArray();
|
||||
|
||||
OnlineTransactionLoggerService::logs($response['id'], $composed_data, $response, TransactionOnlineStatus::BILL_CREATED);
|
||||
|
||||
return $response;
|
||||
|
||||
} catch(\Exception $e){
|
||||
if($e->getCode() === 404){
|
||||
|
||||
$errorMessage = 'Please check your billplz payment gateway collection. Ensure that api_key, x_signature, and collection_id are correctly entered';
|
||||
|
||||
OnlineTransactionLoggerService::logs( null, $composed_data, $errorMessage, TransactionOnlineStatus::BILL_CREATED);
|
||||
|
||||
throw new \ErrorException($errorMessage);
|
||||
|
||||
} else {
|
||||
OnlineTransactionLoggerService::logs( null, $composed_data, $e->getMessage(), TransactionOnlineStatus::BILL_CREATED);
|
||||
};
|
||||
|
||||
throw $e;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function redirect($request)
|
||||
{
|
||||
return $this->client->bill()->redirect($request);
|
||||
try{
|
||||
|
||||
$response = $this->client->bill()->redirect($request);
|
||||
|
||||
OnlineTransactionLoggerService::logs($request['billplz']['id'], $request, $response, TransactionOnlineStatus::UPDATE_TRANSACTION_REDIRECT);
|
||||
|
||||
return $response;
|
||||
|
||||
} catch(\Exception $e){
|
||||
OnlineTransactionLoggerService::logs($request['billplz']['id'], $request, $e->getMessage(), TransactionOnlineStatus::UPDATE_TRANSACTION_REDIRECT);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function webhook($request)
|
||||
{
|
||||
return $this->client->webhook($request);
|
||||
try {
|
||||
$response = $this->client->webhook($request);
|
||||
|
||||
OnlineTransactionLoggerService::logs($request['billplz']['id'], $request, $response, TransactionOnlineStatus::UPDATE_TRANSACTION_CALLBACK);
|
||||
|
||||
return $response;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
OnlineTransactionLoggerService::logs($request['billplz']['id'], $request, $e->getMessage(), TransactionOnlineStatus::UPDATE_TRANSACTION_CALLBACK);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTransactions($date)
|
||||
@@ -94,7 +133,7 @@ class BillplzService
|
||||
|
||||
public function getBillplzTransactionReview($date)
|
||||
{
|
||||
$date = Carbon::now()->subDays(8)->toDateString();
|
||||
$date = Carbon::now()->toDateString();
|
||||
$arrahnTransactions = $this->getArrahnTransactions($date);
|
||||
|
||||
// sort array by tarikh desc and masa key desc
|
||||
@@ -143,6 +182,7 @@ class BillplzService
|
||||
} catch (\Throwable $th) {
|
||||
logger()->error('Error when querying billplz id : ' . $billId);
|
||||
logger()->error($th->getMessage());
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OnlineTransactionLoggerService
|
||||
{
|
||||
public static function logs($bill_id, $request, $response, $status)
|
||||
{
|
||||
try {
|
||||
Http::arrahn()->post('/api/transaction/online/log', [
|
||||
'bill_id' => $bill_id,
|
||||
'payload' => json_encode($request),
|
||||
'response' => json_encode($response),
|
||||
'status' => json_encode($status),
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
// Log the exception itself
|
||||
Log::error('Failed to log activity: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,12 +39,12 @@
|
||||
<form method="post" id="formtable" action="{{ route('payment.action') }}">
|
||||
@csrf
|
||||
|
||||
@error('totalSagInCart')
|
||||
@error('totalSagInCartInput')
|
||||
<script>
|
||||
$.notify({
|
||||
icon: 'fas fa-exclamation-triangle fa-2x',
|
||||
newest_on_top: true,
|
||||
message: "<strong style='font-size:15px;'>Sila pilih salah satu checkbox di atas terlebih dahulu!</strong>"
|
||||
message: "<strong style='font-size:15px;'>{{ $message }}</strong>"
|
||||
}, {
|
||||
type: 'danger',
|
||||
allow_dismiss: false,
|
||||
|
||||
Reference in New Issue
Block a user