added split of payment

This commit is contained in:
Hafifie PKB
2024-12-08 22:00:52 +08:00
parent 4501449bb1
commit 09e0afbd84
4 changed files with 78 additions and 38 deletions
+40 -27
View File
@@ -15,9 +15,12 @@ use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Money\Money;
use App\Services\OnlineTransactionLoggerService;
use Illuminate\Support\Facades\Session;
class BayaranController extends Controller
{
public $CallableHttp;
public function PembayaranAction(PaymentRequest $request)
{
@@ -35,12 +38,7 @@ class BayaranController extends Controller
}else{
/* Doesn't Have Carts. First Timer */
$request->validated();
$request->validated();
dd($request->all());
dd($request->getPembiayaanFromNorujukan());
$request->validated();
dd($request->all());
dd($request->getPembiayaanFromNorujukan());
$arraybayar = $this->setUpahTawarruq($request->getPembiayaanFromNorujukan());
$list_pkb = array_filter(array_map(function ($x){
@@ -67,10 +65,10 @@ class BayaranController extends Controller
public function PembayaranEngine(Request $request, BillplzService $billplzService)
{
['email' => $customerEmail, 'notel' => $customerPhoneNumber, 'name' => $customerName, 'icno' => $customerIcno] = auth()->user()->toArray();
// dd($request->all());
$bayaranArrahn = array_filter($request->txtjenisbayaran, fn($x) => $x == 'arrahn');
$bayaranOthers = array_filter($request->txtjenisbayaran, fn($x) => $x != 'arrahn');
// dd('test');
$bayaranArrahnArray = array_map(function ($x) use ($customerName, $customerIcno, $request) {
return [
'customer_name' => $customerName,
@@ -104,7 +102,10 @@ class BayaranController extends Controller
$company = strtoupper($request->txtcompany);
$bill = $billplzService->createBill([$customerEmail, $customerPhoneNumber, $customerName, $getPaymentSum()],$company);
$isRecordTransactionSuccess = $this->recordTransaction($paymentArray, $bill);
Session::put('company', $company);
$this->serviceCallHttp($company);
$isRecordTransactionSuccess = $this->recordTransaction($paymentArray, $bill,$company);
if ($isRecordTransactionSuccess) {
session([
@@ -116,12 +117,12 @@ class BayaranController extends Controller
}
}
public function recordTransaction($paymentArray, $bill)
public function recordTransaction($paymentArray, $bill,$company = 'PKB')
{
['name' => $customerName, 'icno' => $customerIcno] = auth()->user()->toArray();
$getlatestNoSiri = function () {
$previous_siri = Http::arrahn()->get('/api/online/transaction')->json();
$previous_siri = $this->CallableHttp->get('/api/online/transaction')->json();
if ($previous_siri) {
return $previous_siri['nosiri'] + 1;
} else {
@@ -135,10 +136,13 @@ class BayaranController extends Controller
return 'APKB' . $day . $month . $year . sprintf('%08d', $getlatestNoSiri());
};
$serviceCallable = $company == 'PKB'
? fn(Pool $pool) => $pool->arrahn()
: fn(Pool $pool) => $pool->arrahn_koop();
try {
Http::pool(
fn(Pool $pool) => collect($paymentArray)->map(
fn($payment) => $pool->arrahn()->post('/api/online/transaction', [
fn($payment) => $serviceCallable($pool)->post('/api/online/transaction', [
'nokp' => $customerIcno,
'reference_no' => $generateTransactionReferenceNumber(),
'nosiri' => $getlatestNoSiri(),
@@ -162,7 +166,7 @@ class BayaranController extends Controller
}
try {
$response = Http::arrahn()
$response = $this->CallableHttp
->put('/api/transaction/online/tagportal', [
'billplz_id' => $bill['id'],
])
@@ -182,11 +186,12 @@ class BayaranController extends Controller
public function ResitBayaran(Request $request)
{
$this->serviceCallHttp(Session::get('company'));
$payment_details = $request->payment;
$kpbaru = Auth::User()->icno;
$customer = Http::arrahn()
$customer = $this->CallableHttp
->get('/api/customers/' . $kpbaru)
->json();
$customer_details = $customer;
@@ -195,16 +200,16 @@ class BayaranController extends Controller
$current = new Carbon();
$date = $current->toDateTimeString();
$cawangan_info = Http::arrahn()
$cawangan_info = $this->CallableHttp
->get('/api/cawangan/' . $payment_details['kodcaw'])
->json();
$cawangan = Http::arrahn()
$cawangan = $this->CallableHttp
->get('/api/cawangan/detail/' . $payment_details['kodcaw'])
->json();
$cawangan_detail = $cawangan[0];
$nama_cawangan = $cawangan_info['details_caw'];
$gadai_details = Http::arrahn()
$gadai_details = $this->CallableHttp
->get('/api/gadai/norujukan/' . $payment_details['norujukan'])
->json();
$gadai = $gadai_details[0][0];
@@ -219,7 +224,7 @@ class BayaranController extends Controller
$isBillUnpaid = $data['paid'] !== true;
if ($isBillUnpaid) {
Http::arrahn()->put('/api/online/transaction', [
$this->CallableHttp->put('/api/online/transaction', [
'billplz_id' => $data['id'],
'status' => 'UNSUCCESSFUL',
'paid_at' => null,
@@ -228,7 +233,7 @@ class BayaranController extends Controller
return response(200);
}
Http::arrahn()->put('/api/online/transaction', [
$this->CallableHttp->put('/api/online/transaction', [
'billplz_id' => $data['id'],
'status' => 'PAID',
'paid_at' => $data['paid_at']->format('Y-m-d H:i:s'),
@@ -240,17 +245,17 @@ class BayaranController extends Controller
public function response(Request $request, BillplzService $billplzService)
{
$data = $billplzService->redirect($request->toArray());
$this->serviceCallHttp($billplzService->company);
$isBillUnpaid = $data['paid'] !== true;
if ($isBillUnpaid) {
Http::arrahn()->put('/api/online/transaction', [
$this->CallableHttp->put('/api/online/transaction', [
'billplz_id' => $data['id'],
'status' => 'UNSUCCESSFUL',
'paid_at' => null,
]);
$transactionOnline = Http::arrahn()
$transactionOnline = $this->CallableHttp
->get('/api/transaction/online/login', [
'billplz_id' => $data['id'],
])
@@ -259,13 +264,13 @@ class BayaranController extends Controller
return redirect()->route('pay.failed');
}
Http::arrahn()->put('/api/online/transaction', [
$this->CallableHttp->put('/api/online/transaction', [
'billplz_id' => $data['id'],
'status' => 'PAID',
'paid_at' => $data['paid_at']->format('Y-m-d H:i:s'),
]);
$transactionOnline = Http::arrahn()
$transactionOnline = $this->CallableHttp
->get('/api/transaction/online/login', [
'billplz_id' => $data['id'],
])
@@ -278,17 +283,18 @@ class BayaranController extends Controller
public function successPayment(Request $request)
{
$this->serviceCallHttp(Session::get('company'));
$transactionOnline = $request->transactionOnline;
$arraygadai = array_map(
fn($x) => Http::arrahn()
fn($x) => $this->CallableHttp
->get('/api/gadai/norujukan/' . $x['norujukan'])
->json()[0][0],
$transactionOnline,
);
$arraycawangan = array_map(
fn($x) => Http::arrahn()
fn($x) => $this->CallableHttp
->get('/api/cawangan/detail/' . $x['kodcaw'])
->json()[0],
$transactionOnline,
@@ -310,7 +316,7 @@ class BayaranController extends Controller
$auth_user = Auth::user();
$belum_tebus = Http::arrahn()
$belum_tebus = $this->CallableHttp
->get('/api/customers/' . $auth_user['icno'] . '/gadai/' . 'belum_tebus')
->json();
@@ -383,4 +389,11 @@ class BayaranController extends Controller
return $exist_carts;
}
public function serviceCallHttp($company){
$this->CallableHttp = $company == 'PKB'
? Http::arrahn()
: Http::arrahn_koop();
}
}
+29 -5
View File
@@ -6,6 +6,8 @@ use App\Models\TransactionOnlineStatus;
use Billplz\Client;
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
class BillplzService
{
@@ -14,10 +16,12 @@ class BillplzService
public $callbackUrl;
public $paymentTitle;
public $redirectUrl;
public $company;
public function __construct()
public function __construct(string $company)
{
$this->setupBillplzClient();
$this->company = $company;
$this->setupBillplzClient($company);
$this->setupUrls();
$this->paymentTitle = config('services.billplz.paymentTitle');
}
@@ -27,9 +31,12 @@ class BillplzService
return $this->client->collection()->all()->toArray();
}
public function createBill(array $data,string $company = 'PKB')
public function createBill(array $data,string $company)
{
Session::put('company',$company);
$this->setCompany($company);
$this->setupBillplzClient($company);
// dd($company,$this->config);
$composed_data = [
$this->config['collection_id'],
@@ -67,6 +74,8 @@ class BillplzService
public function redirect($request)
{
$this->setCompany(Session::get('company'));
$this->setupBillplzClient($this->company);
try{
$response = $this->client->bill()->redirect($request);
@@ -84,6 +93,8 @@ class BillplzService
public function webhook($request)
{
$this->setCompany(Session::get('company'));
$this->setupBillplzClient($this->company);
try {
$response = $this->client->webhook($request);
@@ -243,7 +254,7 @@ class BillplzService
return array_map(fn($x) => $this->client->bill()->get($x)->toArray(), $billIds);
}
protected function setupBillplzClient($company = 'PKB')
protected function setupBillplzClient($company)
{
$appEnvironment = config('app.env');
@@ -256,7 +267,9 @@ class BillplzService
? ($billplzEnvironments[$company] ?? config('services.billplz.production'))
: ($billplzEnvironments[$company] ?? config('services.billplz.sandbox'));
$client = Client::make($billplzConfig['api_key'], $billplzConfig['x_signature']);
Log::info($company);
Log::info($this->isBase64($billplzConfig['x_signature']));
$client = Client::make($billplzConfig['api_key'], ($this->isBase64($billplzConfig['x_signature'])) ? $billplzConfig['x_signature'] : base64_encode($billplzConfig['x_signature']));
$client->useVersion('v4');
if ($appEnvironment !== 'production') {
@@ -272,4 +285,15 @@ class BillplzService
$this->callbackUrl = route('pay.callback');
$this->redirectUrl = ['redirect_url' => route('pay.paymentStatus')];
}
protected function setCompany($company = 'PKB'){
$this->company = $company;
}
protected function isBase64($string) {
if (preg_match('/^[A-Za-z0-9+\/=]+$/', $string)) {
return base64_encode(base64_decode($string, true)) === $string;
}
return false;
}
}
+3 -3
View File
@@ -48,9 +48,9 @@ return [
'collection_id' => env('BILLPLZ_SANDBOX_COLLECTION_ID', 'z0r4kjhi'),
],
'sandbox_kopkb' => [
'api_key' => env('BILLPLZ_SANDBOX_KOPKB_API_KEY', 'abecfd0c-98d8-4635-abc2-2fcba8c60c11'),
'x_signature' => env('BILLPLZ_SANDBOX_KOPKB_X_SIGNATURE', 'S-GWr7z03XjAhqPsFfu_H5nQ'),
'collection_id' => env('BILLPLZ_SANDBOX_KOPKB_COLLECTION_ID', 'z0r4kjhi'),
'api_key' => env('BILLPLZ_SANDBOX_KOPKB_API_KEY', '4b9218fd-04fb-4338-a067-982e6730d160'),
'x_signature' => env('BILLPLZ_SANDBOX_KOPKB_X_SIGNATURE', '0ac6e5438cf729754bb819860ed7de6d87d79b0d183212bf10581fca39a4c2d992697b605a706118032af37d31a85fed6637ff1233c56e6d2421bc22cca9d710'),
'collection_id' => env('BILLPLZ_SANDBOX_KOPKB_COLLECTION_ID', 'uae40muk'),
],
],
+5 -2
View File
@@ -24,10 +24,11 @@ radios.forEach((radio) => {
if (this.checked) {
if(this.value == 'kopkb'){
let inputsdisabled = document.querySelectorAll(`#divpkb input:not([type="radio"])`);
let inputenabled = document.querySelectorAll(`#divkopkb input`);
inputsdisabled.forEach(input => {
input.disabled = true;
});
inputs.forEach(input =>{
inputenabled.forEach(input =>{
input.disabled = false;
});
content1.classList.add('blurred');
@@ -37,10 +38,12 @@ radios.forEach((radio) => {
}else{
let inputsdisabled = document.querySelectorAll(`#divkopkb input:not([type="radio"])`);
let inputenabled = document.querySelectorAll(`#divpkb input`);
inputsdisabled.forEach(input => {
input.disabled = true;
});
inputs.forEach(input =>{
inputenabled.forEach(input =>{
input.disabled = false;
});
content2.classList.add('blurred');