pembaikan portal
This commit is contained in:
@@ -6,10 +6,32 @@ 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 = 'z0r4kjhi';
|
||||
}else{
|
||||
$this->api_key = 'f3e82fe1-a422-4660-97f0-65cc59ff6c47';
|
||||
$this->XSignature_Key = 'S-alZUbzmD2_TF3vmrRqgehQ';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function SenaraiPembayaran()
|
||||
{
|
||||
$auth_user = Auth::user();
|
||||
@@ -51,19 +73,121 @@ class BayaranController extends Controller
|
||||
|
||||
public function PembayaranEngine(Request $request)
|
||||
{
|
||||
$arraybayaran = array();
|
||||
// $arraybayaran = array();
|
||||
|
||||
// dd($request);
|
||||
// foreach($request->txtnorujukanhidden as $index1=>$norujukan)
|
||||
// {
|
||||
// // $updategadai = Http::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)
|
||||
{
|
||||
// $updategadai = Http::put(config('api.url').'/api/gadai/'. $request->txtkodcawhidden[$index1] .'/norujukan/' . $norujukan,[
|
||||
// 'bayaran' => $request->txtbayaranhidden[$index1]
|
||||
// ])->json();
|
||||
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]]);
|
||||
}
|
||||
|
||||
|
||||
array_push($arraybayaran,['norujukan' => $norujukan, 'kodcaw' => $request->txtkodcawhidden[$index1], 'bayaran' => $request->txtbayaranhidden[$index1]]);
|
||||
$total_bayaran += $request->txtbayaranhidden[$index1];
|
||||
}
|
||||
|
||||
return view('pembayaran.result.berjaya',compact('arraybayaran'));
|
||||
$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::get(config('api.url'). '/api/billplz/collectionid',[
|
||||
'kodcaw' => $kodcaw
|
||||
])->json();
|
||||
}
|
||||
array_push($arraycollection_id,$collection_id);
|
||||
}
|
||||
|
||||
|
||||
$response = $bill->create(
|
||||
$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::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::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)
|
||||
@@ -81,11 +205,137 @@ class BayaranController extends Controller
|
||||
|
||||
$gadai_details = Http::get(config('api.url') .'/api/gadai/norujukan/'.$payment_details['norujukan'])->json();
|
||||
|
||||
$baki_harga_jualan_sebelum = $gadai_details[0][0]['bakihargajualan'] + $payment_details['bayaran'];
|
||||
$baki_harga_jualan_semasa = $gadai_details[0][0]['bakihargajualan'];
|
||||
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.resit_baru',compact('customer_details','payment_details','date','baki_harga_jualan_sebelum','baki_harga_jualan_semasa'));
|
||||
}else{
|
||||
|
||||
return view('pembayaran.resit.resit_baru',compact('customer_details','payment_details','date','baki_harga_jualan_sebelum','baki_harga_jualan_semasa'));
|
||||
$gadai_details = $gadai_details[0][0];
|
||||
|
||||
dd($request->norujukan);
|
||||
$koskeuntungan = Http::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::put(config('api.url') . '/api/online/transaction',[
|
||||
'billplz_id' => $data['billplz']['id'],
|
||||
'status' => 'PAID',
|
||||
'paid_at' => $data['billplz']['paid_at']
|
||||
]);
|
||||
|
||||
$transactionOnline = Http::get(config('api.url') . '/api/transaction/online/express',[
|
||||
'billplz_id' => $data['billplz']['id']
|
||||
])->json();
|
||||
|
||||
return redirect()->route('pay.success',[
|
||||
'transactionOnline' => $transactionOnline
|
||||
]);
|
||||
|
||||
}else{
|
||||
Http::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::put(config('api.url') . '/api/online/transaction',[
|
||||
'billplz_id' => $data['billplz']['id'],
|
||||
'status' => 'PAID',
|
||||
'paid_at' => $data['billplz']['paid_at']
|
||||
]);
|
||||
|
||||
$transactionOnline = Http::get(config('api.url') . '/api/transaction/online/login',[
|
||||
'billplz_id' => $data['billplz']['id']
|
||||
])->json();
|
||||
|
||||
return redirect()->route('pay.success',[
|
||||
'transactionOnline' => $transactionOnline
|
||||
]);
|
||||
|
||||
}else{
|
||||
Http::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::get(config('api.url') . '/api/cawangan/'. $trans['kodcaw'])->json();
|
||||
$cawangan = Http::get(config('api.url') . '/api/cawangan/detail/'. $trans['kodcaw'])->json();
|
||||
$cawangan_detail = $cawangan[0];
|
||||
$nama_cawangan = $cawangan_info['details_caw'];
|
||||
$gadai = Http::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'));
|
||||
}
|
||||
|
||||
public function failedPayment(){
|
||||
return view('pembayaran.failed_express');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,4 +10,9 @@ use Illuminate\Routing\Controller as BaseController;
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user