From 8228e6c8c60bfd1c7138ba55ef48257287c65044 Mon Sep 17 00:00:00 2001 From: Azfar Arsyad <45238748+Arpax17@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:11:00 +0800 Subject: [PATCH] merge --- app/Http/Controllers/ApiController.php | 53 ++++++++++++++++---------- routes/api.php | 6 +-- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index 387dedd0..7278f59a 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -26,6 +26,7 @@ use App\Models\LelongBid; use App\Models\LelongBidMarhun; use App\Models\LelKarat; use App\Models\LelKarat_temp; +use App\Models\Resit; use Session; use Carbon\Carbon; @@ -49,7 +50,7 @@ class ApiController extends Controller * @return \Illuminate\Contracts\Support\Renderable */ public function __construct(){ - parent::__construct(); + // parent::__construct(); if(config('app.env') != 'production'){ $this->api_key = 'abecfd0c-98d8-4635-abc2-2fcba8c60c11'; $this->XSignature_Key = 'S-GWr7z03XjAhqPsFfu_H5nQ'; @@ -150,10 +151,11 @@ class ApiController extends Controller $total_bayaran = 10; - + $collection_id = $this->collection_id; + // dd($request->all()); $response = $bill->create( $collection_id, - // $request->email, + 'test@gmail.com', $request->notel, $request->name, Money::MYR($total_bayaran), @@ -162,6 +164,13 @@ class ApiController extends Controller ['redirect_url' => route('pay.paymentStatus')] ); + $previous_siri = Resit::orderBy('id','desc')->first(); + if($previous_siri){ + $nosiri = $previous_siri->id + 1; + }else{ + $nosiri = 1; + } + $billcode = $response->toArray(); $reference_no = 'LPKB' . $day . $month . $year . sprintf("%08d", $nosiri); @@ -261,28 +270,30 @@ class ApiController extends Controller $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'] - ]); + $resit = Resit::where('billplz_id','=',$data['billplz']['id'])->first(); + $resit->status = 'PAID'; + $resit->paid_at = $data['billplz']['paid_at']; + $resit->save(); - $transactionOnline = Http::get(config('api.url') . '/api/transaction/online/login',[ - 'billplz_id' => $data['billplz']['id'] - ])->json(); - - return redirect()->route('pay.success',[ - 'transactionOnline' => $transactionOnline - ]); + // $transactionOnline = Http::get(config('api.url') . '/api/transaction/online/express',[ + // 'billplz_id' => $data['billplz']['id'] + // ])->json(); + return response()->json([ + 'success' => true, + 'resit' => $resit + ]); }else{ - Http::put(config('api.url') . '/api/online/transaction',[ - 'billplz_id' => $data['billplz']['id'], - 'status' => 'UNSUCCESSFUL', - 'paid_at' => null - ]); - return redirect()->route('pay.failed'); + $resit = Resit::where('billplz_id','=',$data['billplz']['id'])->first(); + $resit->status = 'UNSUCCESSFUL'; + $resit->paid_at = null; + $resit->save(); + return response()->json([ + 'success' => false, + 'resit' => $resit + ]); } } } diff --git a/routes/api.php b/routes/api.php index 98777810..93e68187 100644 --- a/routes/api.php +++ b/routes/api.php @@ -29,9 +29,9 @@ Route::get('/cart/{userid}', [CartController::class, 'getCart']); Route::post('/feepayment', [ApiController::class, 'feepayment']); Route::get('/callback', [ApiController::class, 'feepayment']); -Route::post('/feepayment', 'App\Http\Controllers\ApiController@PembayaranEngine')->name('feepayment'); -Route::get('/pembayaran/response', 'App\Http\Controllers\ApiController@response')->name('pay.paymentStatus'); -Route::get('/pembayaran/backend', 'App\Http\Controllers\ApiController@callback')->name('pay.callback'); +Route::post('/feepayment', [ApiController::class, 'feepayment'])->name('feepayment'); +Route::get('/pembayaran/response', [ApiController::class, 'response'])->name('pay.paymentStatus'); +Route::get('/pembayaran/backend', [ApiController::class, 'callback'])->name('pay.callback'); //Protected routes Route::group(['middleware' => ['auth:sanctum']], function () {