365 lines
12 KiB
PHP
365 lines
12 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Billplz\Client;
|
|
use Session;
|
|
use Http\Client\Common\HttpMethodsClient;
|
|
use Http\Adapter\Guzzle6\Client as GuzzleHttpClient;
|
|
use Http\Message\MessageFactory\GuzzleMessageFactory;
|
|
use Money\Money;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
class BayaranController extends Controller
|
|
{
|
|
|
|
public function __construct(){
|
|
parent::__construct();
|
|
if(config('app.env') != 'production'){
|
|
$this->api_key = 'abecfd0c-98d8-4635-abc2-2fcba8c60c11';
|
|
$this->XSignature_Key = 'S-GWr7z03XjAhqPsFfu_H5nQ';
|
|
$this->collection_id = '5aosv2dg';
|
|
}else{
|
|
$this->api_key = 'f3e82fe1-a422-4660-97f0-65cc59ff6c47';
|
|
$this->XSignature_Key = 'S-alZUbzmD2_TF3vmrRqgehQ';
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function SenaraiPembayaran()
|
|
{
|
|
|
|
$api_url = config('api.url');
|
|
|
|
$arraysag = [];
|
|
|
|
$auth_user = Auth::user();
|
|
|
|
$belum_tebus = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/customers/'. $auth_user['icno'] . '/gadai/' . 'belum_tebus')->json();
|
|
|
|
if(is_array($belum_tebus))
|
|
{
|
|
if(sizeof($belum_tebus) > 0)
|
|
{
|
|
foreach($belum_tebus as $index=>$bt)
|
|
{
|
|
foreach($bt as $index1=>$bet)
|
|
{
|
|
array_push($arraysag,$bet);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$belum_tebus = $arraysag;
|
|
|
|
// return view('pembayaran.senaraibayaran', compact('belum_tebus'));
|
|
return view('includes.bayaran.senaraibayaransag', compact('belum_tebus','api_url'));
|
|
}
|
|
|
|
public function PembayaranAction(Request $request)
|
|
{
|
|
|
|
|
|
$validated = $request->validate([
|
|
'chkboxsag' => 'required',
|
|
]);
|
|
|
|
$arraybayar = array();
|
|
|
|
foreach($request->chkboxsag as $index=>$sag)
|
|
{
|
|
$gadai = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/gadai/norujukan/'. $sag)->json();
|
|
|
|
$arraybayar[] = $gadai[0][0];
|
|
}
|
|
|
|
|
|
// return view('pembayaran.checkout',compact('arraybayar'));
|
|
return view('includes.bayaran.pembayaransag',compact('arraybayar'));
|
|
}
|
|
|
|
public function PembayaranEngine(Request $request)
|
|
{
|
|
// $arraybayaran = array();
|
|
|
|
// dd($request);
|
|
// foreach($request->txtnorujukanhidden as $index1=>$norujukan)
|
|
// {
|
|
// // $updategadai = Http::withOptions(['verify' => config('app.api_verify')])->put(config('api.url').'/api/gadai/'. $request->txtkodcawhidden[$index1] .'/norujukan/' . $norujukan,[
|
|
// // 'bayaran' => $request->txtbayaranhidden[$index1]
|
|
// // ])->json();
|
|
|
|
|
|
// array_push($arraybayaran,['norujukan' => $norujukan, 'kodcaw' => $request->txtkodcawhidden[$index1], 'bayaran' => $request->txtbayaranhidden[$index1]]);
|
|
// }
|
|
|
|
// $arraycollection_id = array();
|
|
|
|
$http = new HttpMethodsClient(
|
|
new GuzzleHttpClient(),
|
|
new GuzzleMessageFactory()
|
|
);
|
|
|
|
$billplz = new Client($http, $this->api_key);
|
|
if(config('app.env') != 'production'){
|
|
$billplz->useSandbox();
|
|
}
|
|
|
|
$billplz->useVersion('v4');
|
|
|
|
$bill = $billplz->bill();
|
|
|
|
$current = Carbon::now();
|
|
$current = new Carbon();
|
|
|
|
$day = $current->day;
|
|
$month = $current->month;
|
|
$year = $current->format('y');
|
|
|
|
$array_payment = [];
|
|
|
|
$total_bayaran = 0;
|
|
|
|
foreach($request->txtnorujukanhidden as $index1=>$norujukan)
|
|
{
|
|
if($request->txtjenisbayaran[$index1] == 'arrahn')
|
|
{
|
|
array_push($array_payment,['customer_name' => Auth::user()->name,'kodcaw'=>$request->txtkodcawhidden[$index1],'norujukan'=>$norujukan,'bayaran'=>$request->txtbayaranhidden[$index1],'jbg' => $request->txtjbghidden[$index1],'upah' => $request->txtupahhidden[$index1]]);
|
|
Session::put('payment_jenis','arrahn');
|
|
}
|
|
else
|
|
{
|
|
array_push($array_payment,['customer_name' => Auth::user()->name,'nokp' => Auth::user()->icno,'kodcaw'=>$request->txtkodcawhidden[$index1],'norujukan'=>$norujukan,'bayaran'=>$request->txtbayaranhidden[$index1]]);
|
|
}
|
|
|
|
$total_bayaran += $request->txtbayaranhidden[$index1];
|
|
}
|
|
|
|
$total_bayaran = ($total_bayaran * 100) + 100;
|
|
|
|
Session::put('array_payment',$array_payment);
|
|
Session::put('payment_method','login');
|
|
Session::save();
|
|
|
|
// foreach($request->txtkodcawhidden as $index2=>$kodcaw)
|
|
// {
|
|
// if(config('app.env') != 'production'){
|
|
// $collection_id = $this->collection_id;
|
|
// }else{
|
|
// $collection_id = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url'). '/api/billplz/collectionid',[
|
|
// 'kodcaw' => $kodcaw
|
|
// ])->json();
|
|
// }
|
|
// array_push($arraycollection_id,$collection_id);
|
|
// }
|
|
|
|
|
|
$response = $bill->create(
|
|
$this->collection_id,
|
|
Auth::user()->email,
|
|
Auth::user()->notel,
|
|
Auth::user()->name,
|
|
Money::MYR($total_bayaran),
|
|
route('pay.callback'),
|
|
'Bayaran Ansuran',
|
|
['redirect_url' => route('pay.paymentStatus')]
|
|
);
|
|
|
|
$billcode = $response->toArray();
|
|
|
|
foreach($array_payment as $index1=>$arraypay)
|
|
{
|
|
$previous_siri = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/online/transaction')->json();
|
|
if($previous_siri){
|
|
$nosiri = $previous_siri['nosiri'] + 1;
|
|
}else{
|
|
$nosiri = 1;
|
|
}
|
|
|
|
$reference_no = 'APKB' . $day . $month . $year . sprintf("%08d", $nosiri);
|
|
|
|
$new_transaction = Http::withOptions(['verify' => config('app.api_verify')])->post(config('api.url') . '/api/online/transaction',[
|
|
'nokp'=> Auth::user()->icno,
|
|
'reference_no'=> $reference_no,
|
|
'nosiri'=> $nosiri,
|
|
'billplz_id' => $billcode['id'],
|
|
'norujukan' => $arraypay['norujukan'],
|
|
'kodcaw' => $arraypay['kodcaw'],
|
|
'total_payment'=> $arraypay['bayaran'],
|
|
'customer_name' => Auth::user()->name,
|
|
])->json();
|
|
|
|
}
|
|
|
|
|
|
return redirect($billcode['url'] . '?auto_submit=true');
|
|
|
|
// return view('pembayaran.result.berjaya',compact('arraybayaran'));
|
|
}
|
|
|
|
public function ResitBayaran(Request $request)
|
|
{
|
|
$payment_details = $request->payment;
|
|
|
|
$kpbaru = Auth::User()->icno;
|
|
|
|
$customer = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') .'/api/customers/'.$kpbaru)->json();
|
|
$customer_details = $customer;
|
|
|
|
$current = Carbon::now();
|
|
$current = new Carbon();
|
|
$date = $current->toDateTimeString();
|
|
|
|
$cawangan_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/'. $payment_details['kodcaw'])->json();
|
|
$cawangan = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/detail/'. $payment_details['kodcaw'])->json();
|
|
$cawangan_detail = $cawangan[0];
|
|
$nama_cawangan = $cawangan_info['details_caw'];
|
|
|
|
$gadai_details = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') .'/api/gadai/norujukan/'.$payment_details['norujukan'])->json();
|
|
$gadai = $gadai_details[0][0];
|
|
// if($gadai_details[0][0]['hargajualan'] > 0)
|
|
// {
|
|
// $baki_harga_jualan_sebelum = $gadai_details[0][0]['bakihargajualan'] + $payment_details['total_payment'];
|
|
// $baki_harga_jualan_semasa = $gadai_details[0][0]['bakihargajualan'];
|
|
|
|
return view('pembayaran.resit.resitportal',compact('customer_details','payment_details','cawangan_detail','nama_cawangan','gadai'));
|
|
// }else{
|
|
|
|
// $gadai_details = $gadai_details[0][0];
|
|
|
|
// $koskeuntungan = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/upahbukantawarruq/' . $payment_details['kodcaw'] . '/' . $payment_details['norujukan'])->json();
|
|
|
|
// $jbg = $gadai_details['jbg'];
|
|
|
|
// return view('pembayaran.resit.resit_baru_sebelum',compact('customer_details','payment_details','date','koskeuntungan','jbg'));
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
public function callback(Request $request){
|
|
$http = new HttpMethodsClient(
|
|
new GuzzleHttpClient(),
|
|
new GuzzleMessageFactory()
|
|
);
|
|
|
|
$billplz = new Client($http, $this->api_key);
|
|
if(config('app.env') != 'production'){
|
|
$billplz->useSandbox();
|
|
}
|
|
$billplz->useVersion('v4');
|
|
|
|
$bill = $billplz->bill();
|
|
|
|
$data = $bill->webhook($request->toArray());
|
|
|
|
if($data['billplz']['paid'] == 'true'){
|
|
Http::withOptions(['verify' => config('app.api_verify')])->put(config('api.url') . '/api/online/transaction',[
|
|
'billplz_id' => $data['billplz']['id'],
|
|
'status' => 'PAID',
|
|
'paid_at' => $data['billplz']['paid_at']
|
|
]);
|
|
|
|
$transactionOnline = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/transaction/online/express',[
|
|
'billplz_id' => $data['billplz']['id']
|
|
])->json();
|
|
|
|
// \Mail::to(Auth::user()->email)->send(new \App\Mail\BayaranMail($array_payment));
|
|
|
|
return redirect()->route('pay.success',[
|
|
'transactionOnline' => $transactionOnline
|
|
]);
|
|
|
|
}else{
|
|
Http::withOptions(['verify' => config('app.api_verify')])->put(config('api.url') . '/api/online/transaction',[
|
|
'billplz_id' => $data['billplz']['id'],
|
|
'status' => 'UNSUCCESSFUL',
|
|
'paid_at' => null
|
|
]);
|
|
return redirect()->route('pay.failed');
|
|
}
|
|
}
|
|
|
|
public function response(Request $request){
|
|
$http = new HttpMethodsClient(
|
|
new GuzzleHttpClient(),
|
|
new GuzzleMessageFactory()
|
|
);
|
|
|
|
$billplz = new Client($http, $this->api_key);
|
|
if(config('app.env') != 'production'){
|
|
$billplz->useSandbox();
|
|
}
|
|
$billplz->useVersion('v4');
|
|
|
|
$bill = $billplz->bill();
|
|
|
|
$data = $bill->webhook($request->toArray());
|
|
if($data['billplz']['paid'] == 'true'){
|
|
Http::withOptions(['verify' => config('app.api_verify')])->put(config('api.url') . '/api/online/transaction',[
|
|
'billplz_id' => $data['billplz']['id'],
|
|
'status' => 'PAID',
|
|
'paid_at' => $data['billplz']['paid_at']
|
|
]);
|
|
|
|
$transactionOnline = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/transaction/online/login',[
|
|
'billplz_id' => $data['billplz']['id']
|
|
])->json();
|
|
|
|
return redirect()->route('pay.success',[
|
|
'transactionOnline' => $transactionOnline
|
|
]);
|
|
|
|
}else{
|
|
Http::withOptions(['verify' => config('app.api_verify')])->put(config('api.url') . '/api/online/transaction',[
|
|
'billplz_id' => $data['billplz']['id'],
|
|
'status' => 'UNSUCCESSFUL',
|
|
'paid_at' => null
|
|
]);
|
|
return redirect()->route('pay.failed');
|
|
}
|
|
}
|
|
|
|
public function successPayment(Request $request){
|
|
$transactionOnline = $request->transactionOnline;
|
|
|
|
// dd($transactionOnline);
|
|
|
|
$arraygadai = array();
|
|
$arraycawangan = array();
|
|
// dd($transactionOnline);
|
|
foreach($transactionOnline as $index1=>$trans)
|
|
{
|
|
$cawangan_info = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/'. $trans['kodcaw'])->json();
|
|
$cawangan = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/detail/'. $trans['kodcaw'])->json();
|
|
$cawangan_detail = $cawangan[0];
|
|
$nama_cawangan = $cawangan_info['details_caw'];
|
|
$gadai = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') .'/api/gadai/norujukan/'.$trans['norujukan'])->json();
|
|
$gadai = $gadai[0][0];
|
|
|
|
array_push($arraygadai,$gadai);
|
|
array_push($arraycawangan,$cawangan_detail);
|
|
|
|
|
|
}
|
|
|
|
// dd($arraygadai,$arraycawangan);
|
|
|
|
// return view('pembayaran.result.berjaya',compact('transactionOnline','arraycawangan','arraygadai'));
|
|
return view('pembayaran.result.berjayaportal',compact('transactionOnline','arraycawangan','arraygadai'));
|
|
}
|
|
|
|
public function failedPayment(){
|
|
// return view('pembayaran.result.gagal');
|
|
return view('pembayaran.result.gagalportal');
|
|
}
|
|
|
|
}
|