对我来说,这是 Spark 中的一个错误。我搜索了 Stripe 使用重定向的所有情况。对我来说,这可能是一个错误的一个迹象是:
subscription-notice.blade.php 文件中的链接构建如下:
{!! __('Please :linkOpen confirm your payment :linkClose to activate your subscription!', ['linkOpen' => '<a href="/'.config('cashier.path').'/payment/'.auth()->user()->subscription()->latestPayment()->id.'?redirect='.url('/home').'">', 'linkClose' => '</a>']) !!}
'?redirect='.url('/home').' 部分使用主机地址创建一个完整的有效 URL。
不仅是相对路径!在我的情况下,这些相对路径会遇到 403 错误。
就像在RegisterController:
/**
* Handle a registration request for the application.
*
* @param \Laravel\Spark\Contracts\Http\Requests\Auth\RegisterRequest $request
* @return \Illuminate\Http\Response
*/
public function register(RegisterRequest $request)
{
list($user, $paymentId) = Spark::interact(
Register::class, [$request]
);
Auth::login($user);
event(new UserRegistered($user));
if ($user instanceof MustVerifyEmail && ! $user->hasVerifiedEmail()) {
$user->sendEmailVerificationNotification();
}
return response()->json([
'redirect' => $paymentId ?
'/'.config('cashier.path').'/payment/'.$paymentId.'?redirect='.$this->redirectPath()
: $this->redirectPath(),
]);
}
$this->redirectPath() 返回一个相对路径。我已将此部分更改为:
return response()->json([
'redirect' => $paymentId ?
'/'.config('cashier.path').'/payment/'.$paymentId.'?redirect='.config('app.url').$this->redirectPath()
: $this->redirectPath(),
]);
在这种情况下,我从配置中获取主机地址并将其放在相对路径的前面。
为了更好的理解,这里使用上面返回的URL(register-stripe.js):
/*
* After obtaining the Stripe token, send the registration to Spark.
*/
sendRegistration(paymentMethod) {
this.registerForm.stripe_payment_method = paymentMethod;
Spark.post('/register', this.registerForm)
.then(response => {
window.location = response.redirect;
});
}
在某些情况下,我需要覆盖一些 JavaScript 或 PHP 源...
- 注册过程(此处显示)
- 支付信息更新流程
- 使用现有帐户创建订阅
我希望我可以帮助其他人!如有必要,我还可以发布我在 cmets 中更改重定向 URL 的确切位置。