From 0333d62e6fc04988708e0e845efa4a7a63d9bc7b Mon Sep 17 00:00:00 2001 From: tokumeikoi Date: Wed, 28 Apr 2021 18:29:28 +0900 Subject: [PATCH] fix: payment --- app/Http/Controllers/Guest/PaymentController.php | 8 ++++---- app/Http/Routes/GuestRoute.php | 2 +- app/Services/PaymentService.php | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Guest/PaymentController.php b/app/Http/Controllers/Guest/PaymentController.php index 881ab734..2dc8ef85 100644 --- a/app/Http/Controllers/Guest/PaymentController.php +++ b/app/Http/Controllers/Guest/PaymentController.php @@ -11,11 +11,11 @@ use App\Http\Controllers\Controller; class PaymentController extends Controller { - public function notify($method, Request $request) + public function notify($method, $id, Request $request) { - $paymentService = new PaymentService($method); + $paymentService = new PaymentService($method, $id); $verify = $paymentService->notify($request->input()); - if ($verify) abort(500, 'verify error'); + if (!$verify) abort(500, 'verify error'); if (!$this->handle($verify['trade_no'], $verify['callback_no'])) { abort(500, 'handle error'); } @@ -25,10 +25,10 @@ class PaymentController extends Controller private function handle($tradeNo, $callbackNo) { $order = Order::where('trade_no', $tradeNo)->first(); - if ($order->status === 1) return true; if (!$order) { abort(500, 'order is not found'); } + if ($order->status === 1) return true; $orderService = new OrderService($order); if (!$orderService->success($callbackNo)) { return false; diff --git a/app/Http/Routes/GuestRoute.php b/app/Http/Routes/GuestRoute.php index ed08b73c..54dc7f83 100644 --- a/app/Http/Routes/GuestRoute.php +++ b/app/Http/Routes/GuestRoute.php @@ -21,7 +21,7 @@ class GuestRoute // Telegram $router->post('/telegram/webhook', 'Guest\\TelegramController@webhook'); // Payment - $router->match(['get', 'post'], '/payment/{method}', 'Guest\\PaymentController@notify'); + $router->match(['get', 'post'], '/payment/{method}/{id}', 'Guest\\PaymentController@notify'); }); } } diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 81f60744..09a55a19 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -15,6 +15,8 @@ class PaymentService if ($id) $payment = Payment::find($id)->toArray(); $this->config = []; if (isset($payment) && $payment['config']) $this->config = json_decode($payment['config'], true); + $this->config['id'] = $id; + $this->config['enable'] = $payment['enable']; $this->payment = new $this->class($this->config); } @@ -27,8 +29,8 @@ class PaymentService public function pay($order) { return $this->payment->pay([ - 'notify_url' => url('/api/v1/guest/payment/notify/' . $this->method), - 'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order', + 'notify_url' => url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['id']}"), + 'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order/' . $order['trade_no'], 'trade_no' => $order['trade_no'], 'total_amount' => $order['total_amount'], 'user_id' => $order['user_id'],