From 179e1794ddacb784f57857b7efec51ac221cee7f Mon Sep 17 00:00:00 2001 From: Azfar Arsyad <45238748+Arpax17@users.noreply.github.com> Date: Wed, 26 Jan 2022 14:54:21 +0800 Subject: [PATCH] commit --- app/Http/Controllers/ApiController.php | 35 +++++++++++++++----------- routes/api.php | 4 +-- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index 7278f59a..9cc22f7e 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -27,6 +27,7 @@ use App\Models\LelongBidMarhun; use App\Models\LelKarat; use App\Models\LelKarat_temp; use App\Models\Resit; +use App\Models\Payment; use Session; use Carbon\Carbon; @@ -149,10 +150,9 @@ class ApiController extends Controller $month = $current->month; $year = $current->format('y'); - $total_bayaran = 10; + $total_bayaran = 1000; $collection_id = $this->collection_id; - // dd($request->all()); $response = $bill->create( $collection_id, 'test@gmail.com', @@ -160,8 +160,8 @@ class ApiController extends Controller $request->name, Money::MYR($total_bayaran), route('pay.callback'), - 'Bayaran Ansuran', - ['redirect_url' => route('pay.paymentStatus')] + 'Bayaran Borang', + ['redirect_url' => 'http://192.168.0.10:8003/api/pembayaran/response'] ); $previous_siri = Resit::orderBy('id','desc')->first(); @@ -170,17 +170,21 @@ class ApiController extends Controller }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->lelongbid_id = null; $resit->reference_no = $reference_no; $resit->billplz_id = $billcode['id']; $resit->resit_type = 1; - $resit->total_payment = $total_bayaran; + $resit->total_payment = 10; $resit->save(); // foreach($array_payment as $index1=>$arraypay) @@ -214,6 +218,7 @@ class ApiController extends Controller } public function callback(Request $request){ + dd('hye'); $http = new HttpMethodsClient( new GuzzleHttpClient(), new GuzzleMessageFactory() @@ -256,6 +261,7 @@ class ApiController extends Controller } public function response(Request $request){ + // dd($request->all()); $http = new HttpMethodsClient( new GuzzleHttpClient(), new GuzzleMessageFactory() @@ -268,13 +274,14 @@ class ApiController extends Controller $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(); + $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['billplz']['paid_at']; + $resit->paid_at = $data['paid_at']; $resit->save(); // $transactionOnline = Http::get(config('api.url') . '/api/transaction/online/express',[ @@ -286,7 +293,7 @@ class ApiController extends Controller ]); }else{ - $resit = Resit::where('billplz_id','=',$data['billplz']['id'])->first(); + $resit = Resit::where('billplz_id','=',$data['id'])->first(); $resit->status = 'UNSUCCESSFUL'; $resit->paid_at = null; $resit->save(); diff --git a/routes/api.php b/routes/api.php index 93e68187..0c15c6fd 100644 --- a/routes/api.php +++ b/routes/api.php @@ -26,8 +26,8 @@ Route::post('/forgotpassword', [ResetPassword::class, 'forgotpassword']); Route::post('/addToCart', [CartController::class, 'addToCart']); Route::get('/cart/{userid}', [CartController::class, 'getCart']); -Route::post('/feepayment', [ApiController::class, 'feepayment']); -Route::get('/callback', [ApiController::class, 'feepayment']); +// Route::post('/feepayment', [ApiController::class, 'feepayment']); +// Route::get('/callback', [ApiController::class, 'feepayment']); Route::post('/feepayment', [ApiController::class, 'feepayment'])->name('feepayment'); Route::get('/pembayaran/response', [ApiController::class, 'response'])->name('pay.paymentStatus');