Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Laravel Spark 403 - 3D安全支付时重定向主机错配

Laravel Spark 403 - 3D安全支付时重定向主机错配
EN

Stack Overflow用户
提问于 2020-11-13 14:32:05
回答 2查看 416关注 0票数 0

我正在使用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时,我得到了以下屏幕:

当我继续的时候,我不会被重定向。当然,因为没有重定向。

以前有没有人有过这个问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-11-23 12:57:11

对我来说,这是星火中的一个窃听器。我已经搜索了斯特里普使用重定向的所有事件。对我来说,这可能是一个错误的迹象之一是:

subscription-notice.blade.php文件中,链接构建如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
{!! __('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

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
/**
 * 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()返回一个相对路径。我把这部分改成:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
return response()->json([
        'redirect' => $paymentId ?
            '/'.config('cashier.path').'/payment/'.$paymentId.'?redirect='.config('app.url').$this->redirectPath()
            : $this->redirectPath(),
    ]);

在本例中,我从配置中获取主机地址,并将其放在相对路径的前面。

为了更好地理解,这里使用了上面返回的URL (register-stripe.js):

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
    /*
     * 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

  • create订阅的
  • 注册过程(此处显示)
  • 更新过程与现有的帐户

我希望我能在这方面帮助别人!如果有必要的话,我也可以在评论中发布更改重定向URL的确切位置。

票数 1
EN

Stack Overflow用户

发布于 2020-11-22 01:22:46

我想出了一个(肮脏的?)解决办法:

在我的StripWebHookController中,有一些代码为用户发出通知:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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就消失了:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public function __construct()
{
    //$this->middleware(VerifyRedirectUrl::class);
}

然而,“回去”按钮后,接受付款不起作用,所以我将检查。但现在,这403至少已经消失了。如果我不能找到另一个解决办法,我就用这个。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64828876

复制
相关文章

相似问题

添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文