--- robots: noindex --- ###### tags: `レクチャー` # 【焼鳥 かわにし】 PayPay 2022-09-29 ## PayPay流れ 1. `PayPay::apply()` - PayPayの決済URLは発行 - オーダーのステータスを決済保留に 1. `OrderController::checkout` - PayPayの決済URLにリダイレクト 1. PayPay決済後、callback URLにリダイレクトされる 1. callback URL - PayPayの決済の認証 - オーダーのステータスを決済完了に 1. 決済完了画面表示 ## `OrderController::checkout` 流れ クレジットカード ```markdown * オーダーの準備 * クレジット決済 * オーダーの保存 * カートの削除 * 決済完了画面 ``` PayPay ```markdown * オーダーの準備 * PayPayの決済URLを発行 * オーダーのステータスを決済保留に * カートの削除 * PayPayの決済URLにリダイレクト ``` ```diff * オーダーの準備 - * クレジット決済 + * PayPayの決済URLは発行 - * オーダーの保存 + * オーダーのステータスを決済保留に * カートの削除 - * 決済完了画面 + * PayPayの決済URLにリダイレクト ``` ## `OrderController::checkout` ```php! <?php namespace Modules\Web\Http\Controllers\Order; // ... class OrderController extends Controller { public function checkout(OrderRequest $request): RedirectResponse { $order_step = 4; if (!OrderStep::isCurrent($order_step)) { return redirect(route('index')) ->withErrors( [ 'step' => '不正な手順です' ] ); } $cart = Cart::instance(); $shop = OrderShop::getShop(); DB::beginTransaction(); try { // カートからオーダーを準備する // オーダーを決済処理中で保存 $order = (new PrepareOrderAction($cart))($request); // 支払い処理 // \Illuminate\Http\RedirectResponse|null $reposonse = (new ApplyPaymentMethodAction())($order); DB::commit(); } catch (PaymentMethodException $e) { DB::rollback(); // 決済エラー } catch (\Throwable $e) { DB::rollback(); // 致命的なエラー } $cart->destroy(); if ($reposonse instanceof \Illuminate\Http\RedirectResponse) { // リダイレクト return $reposonse; } // TODO: 決済完了ステータスに (new CompleteOrderAction)($order); // TODO: 決済確認メール送信 (new SendOrderMailAction)($order); // FIXME: 他人のオーダーが見れる? return redirect(route('order.complete', ['order' => $order->id])); } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up