latest api
This commit is contained in:
@@ -163,7 +163,7 @@ class ApiController extends Controller
|
||||
Money::MYR($total_bayaran),
|
||||
route('pay.callback'),
|
||||
'Bayaran Borang',
|
||||
['redirect_url' => 'http://192.168.0.88:8003/api/pembayaran/response']
|
||||
['redirect_url' => 'http://192.168.88:8003/api/pembayaran/response']
|
||||
);
|
||||
// dd($response);
|
||||
$previous_siri = Resit::orderBy('id','desc')->first();
|
||||
@@ -296,6 +296,200 @@ class ApiController extends Controller
|
||||
$resit->paid_at = null;
|
||||
$resit->save();
|
||||
|
||||
event(new PaymentNotify('UNSUCCESSFUL',$resit->user_id));
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'resit' => $resit
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function bidpayment(Request $request)
|
||||
{
|
||||
|
||||
$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');
|
||||
|
||||
$total_bayaran = ($request->total)*100;
|
||||
|
||||
$collection_id = $this->collection_id;
|
||||
$response = $bill->create(
|
||||
$collection_id,
|
||||
$request->email,
|
||||
$request->notel,
|
||||
$request->name,
|
||||
Money::MYR($total_bayaran),
|
||||
route('pay.bidcallback'),
|
||||
'Bayaran Bidaan',
|
||||
['redirect_url' => 'http://192.168.88:8003/api/pembayaran/bidresponse']
|
||||
);
|
||||
// dd($response);
|
||||
$previous_siri = Resit::orderBy('id','desc')->first();
|
||||
if($previous_siri){
|
||||
$nosiri = $previous_siri->id + 1;
|
||||
}else{
|
||||
$nosiri = 1;
|
||||
}
|
||||
|
||||
$billcode = $response->toArray();
|
||||
// dd($billcode);
|
||||
// $billcode['redirect_url'] = 'http://192.168.0.10:8003/api/pembayaran/response';
|
||||
// dd($billcode);
|
||||
$reference_no = 'LPKB' . $day . $month . $year . sprintf("%08d", $nosiri);
|
||||
// $response2 = $bill->get($billcode['id']);
|
||||
// dd($response2->toArray());
|
||||
$resit = new Resit;
|
||||
$resit->user_id = $request->user_id;
|
||||
$resit->lelong_id = $request->lelong_id;
|
||||
$resit->reference_no = $reference_no;
|
||||
$resit->billplz_id = $billcode['id'];
|
||||
$resit->resit_type = 3; //billplz resit for bid payment
|
||||
$resit->total_payment = $request->total;
|
||||
$resit->save();
|
||||
|
||||
|
||||
return redirect($billcode['url'] . '?auto_submit=true');
|
||||
|
||||
// return view('pembayaran.result.berjaya',compact('arraybayaran'));
|
||||
}
|
||||
|
||||
public function bidcallback(Request $request){
|
||||
// dd('hye callback');
|
||||
$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'){
|
||||
$resit = Resit::where('billplz_id','=',$data['billplz']['id'])->first();
|
||||
$resit->status = 'PAID';
|
||||
$resit->paid_at = $data['billplz']['paid_at'];
|
||||
$resit->save();
|
||||
|
||||
$resitoriginal = Resit::where('user_id', $resit->user_id)
|
||||
->where('lelong_id', $resit->lelong_id)
|
||||
->where('resit_type', 2)
|
||||
->first();
|
||||
$payment = $resit->total_payment;
|
||||
$resitoriginal->total_payment = $resitoriginal->total_payment + $payment;
|
||||
$resitoriginal->save();
|
||||
|
||||
$payment = new Payment;
|
||||
$payment->user_id = $resitoriginal->user_id;
|
||||
$payment->lelong_id = $resitoriginal->lelong_id;
|
||||
$payment->total_payment = $resit->total_payment;
|
||||
$payment->resit_id = $resitoriginal->id;
|
||||
$payment->status_payment_opt = 2; //bayar secara online 2
|
||||
$payment->status = 1; //fee rm10 - 1
|
||||
$payment->remark = 'BAYARAN ONLINCE';
|
||||
$payment->save();
|
||||
|
||||
event(new PaymentNotify('PAID',$resitoriginal->user_id));
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'resit' => $resitoriginal
|
||||
]);
|
||||
|
||||
}else{
|
||||
$resit = Resit::where('billplz_id','=',$data['billplz']['id'])->first();
|
||||
$resit->status = 'UNSUCCESSFUL';
|
||||
$resit->paid_at = null;
|
||||
$resit->save();
|
||||
|
||||
event(new PaymentNotify('UNSUCCESSFUL',$resit->user_id));
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'resit' => $resit
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function bidresponse(Request $request){
|
||||
// dd('hye response');
|
||||
$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();
|
||||
$req = $request->toArray();
|
||||
$response = $bill->get($req['billplz']['id']);
|
||||
$data = $response->toArray();
|
||||
// dd($data);
|
||||
if($data['paid'] == 'true'){
|
||||
$resit = Resit::where('billplz_id','=',$data['id'])->first();
|
||||
$resit->status = 'PAID';
|
||||
$resit->paid_at = $data['paid_at'];
|
||||
$resit->save();
|
||||
|
||||
$resitoriginal = Resit::where('user_id', $resit->user_id)
|
||||
->where('lelong_id', $resit->lelong_id)
|
||||
->where('resit_type', 2)
|
||||
->first();
|
||||
|
||||
$resitoriginal->total_payment = $resitoriginal->total_payment + $resit->total_payment;
|
||||
$resitoriginal->save();
|
||||
|
||||
$payment = new Payment;
|
||||
$payment->user_id = $resitoriginal->user_id;
|
||||
$payment->lelong_id = $resitoriginal->lelong_id;
|
||||
$payment->total_payment = $resit->total_payment;
|
||||
$payment->resit_id = $resitoriginal->id;
|
||||
$payment->status_payment_opt = 2; //bayar secara online 2
|
||||
$payment->status = 1; //fee rm10 - 1
|
||||
$payment->remark = 'BAYARAN ONLINCE';
|
||||
$payment->save();
|
||||
|
||||
event(new PaymentNotify('PAID',$resit->user_id));
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'resit' => $resit
|
||||
]);
|
||||
|
||||
}else{
|
||||
$resit = Resit::where('billplz_id','=',$data['id'])->first();
|
||||
$resit->status = 'UNSUCCESSFUL';
|
||||
$resit->paid_at = null;
|
||||
$resit->save();
|
||||
|
||||
event(new PaymentNotify('UNSUCCESSFUL',$resit->user_id));
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
|
||||
Reference in New Issue
Block a user