我已经在我的网站上使用 Stripe 实现了 Laravel Cashier。不,在 3d Secure 失败后,我遇到了重定向问题。 在 3d Secure Auth 的测试页面上,我点击了“FAIL AUTHENTICATION”,例如:
在我点击它来模拟失败后,我被重定向到一个条纹样式的页面。这个:
但我不想向我的用户展示这个“外部”页面/布局。我想重定向到我的自定义订阅页面。
我的控制器看起来像:
public function cardOrder(Request $request)
{
$user = auth()->user();
$input = $request->all();
$token = $request->stripeToken;
$paymentMethod = $request->paymentMethod;
try {
Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
if (is_null($user->stripe_id)) {
$stripeCustomer = $user->createAsStripeCustomer();
$user_stripe_id = $stripeCustomer->id;
} else {
$user_stripe_id = $user->stripe_id;
}
\Stripe\Customer::createSource(
$user_stripe_id,
['source' => $token]
);
$aResult = $user->newSubscription('test',$input['plane'])
->create($paymentMethod, [
'email' => $user->email
], ['off_session' => true]);
return back()->with('success','Subscription is completed.');
} catch (IncompletePayment $exception) {
return redirect()->route(
'cashier.payment',
[$exception->payment->id, 'redirect' => url('/subscription/index')]
);
}
}
如果 3d Secure 被正确传递,用户将被重定向到“/subscription/index”,但在 3d Secure Auth 失败时不会。 我怎样才能做到这一点?