我正在使用Laravel向我的客户付款。万一他们会用3D安全卡付款(我用卡号进行测试)。从stripe的https://stripe.com/docs/testing#regulatory-cards:4,0027,6000,3184)我有以下问题:
条形弹出/模式打开,我单击“完全身份验证”。
之后,身份验证过程开始,用户被定向到http://127.0.0.1:8000/stripe/payment/pi_xxx?redirect=/home。
在这里,我得到了以下Laravel错误(在控制台或其他地方找不到其他错误原因):
我已经在stripe/*
课堂上添加了VerifyCsrfToken
.也许我需要在我的服务器上测试这个案子吗?
非常奇怪,我想这是一个迹象,表明我没有任何问题的条纹,而不是拉拉。当我删除查询参数?redirect=home
时,我得到了以下屏幕:
当我继续的时候,我不会被重定向。当然,因为没有重定向。
以前有没有人有过这个问题?
发布于 2020-11-23 12:57:11
对我来说,这是星火中的一个窃听器。我已经搜索了斯特里普使用重定向的所有事件。对我来说,这可能是一个错误的迹象之一是:
在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源代码.
支付information
我希望我能在这方面帮助别人!如果有必要的话,我也可以在评论中发布更改重定向URL的确切位置。
发布于 2020-11-22 01:22:46
我想出了一个(肮脏的?)解决办法:
在我的StripWebHookController中,有一些代码为用户发出通知:
if ($billable) {
$model = config('cashier.model');
$notifiable = $billable instanceof $model ? $billable : $billable->owner;
if (in_array(Notifiable::class, class_uses_recursive($notifiable))) {
$payment = new Payment(StripePaymentIntent::retrieve(
$payload['data']['object']['payment_intent'],
$billable->stripeOptions()
));
$notifiable->notify(new $notification($payment));
}
}
现在,这是一个通知,显然是在收银员(位于/var/www/html/site/vendor/laravel/cashier/src/Http/Controllers)的PaymentController中)中创建的StripePaymentIntent通知。
有一个VerifyRedirectUrl中间件正在正确地导致问题。所以当你把它注释掉时,403就消失了:
public function __construct()
{
//$this->middleware(VerifyRedirectUrl::class);
}
然而,“回去”按钮后,接受付款不起作用,所以我将检查。但现在,这403至少已经消失了。如果我不能找到另一个解决办法,我就用这个。
https://stackoverflow.com/questions/64828876
复制相似问题