【问题标题】:Laravel cashier stripe issue with 3d secure cards not redirection to confirmation pageLaravel 收银员条纹问题与 3d 安全卡未重定向到确认页面
【发布时间】:2020-09-12 02:13:21
【问题描述】:

我正在努力让 Laravel Cashier Strip 集成与 3d 安全卡一起使用。 我已经进行了设置,因此订阅工作正常,并显示在我的条带仪表板中,并且所有内容都显示在我的本地数据库中。 但是,当我使用需要强身份验证的 3ds 卡进行测试时,它们会在我的条带仪表板中显示为未完成状态。

我在控制台日志中看到了 cashier.payment 响应页面。但是 Cashier 不应该重定向到这个确认窗口吗?

我的代码如下

在我的订阅控制器中,我有

public function index() {

    $data = [
        'intent' => auth()->user()->createSetupIntent(),
        // 'plans' => $available_plans
    ];

    return view('artists.subscription')->with($data);
}

public function checkout(Request $request) {
    $user = auth()->user();
    $paymentMethod = $request->payment_method;
    $planId = 'monthly_sub';

    // SCA
    try {
        $subscription = $user->newSubscription('monthly', $planId)->create($paymentMethod);
    } catch (IncompletePayment $exception) {
        return redirect()->route(
            'cashier.payment',
            [$exception->payment->id, 'redirect' => route('front')]
        );        
    }

    // return response(['status' => 'Success']);
}

在我的条纹 js 文件中我有这个

const stripe = Stripe('stripe_key'); // i have my test key here
const elements = stripe.elements();
const cardElement = elements.create('card',{hidePostalCode: true});
cardElement.mount('#card-element');
const cardHolderName = document.getElementById('card-holder-name');
const cardButton = document.getElementById('card-button');
const clientSecret = cardButton.dataset.secret;

cardButton.addEventListener('click', async (e) => {
    const { setupIntent, error } = await stripe.confirmCardSetup(
        clientSecret, {
            payment_method: {
                card: cardElement,
                billing_details: { name: cardHolderName.value }
            }
        }
    );


    axios.post('checkout', {
      payment_method: setupIntent.payment_method
    }).then(response => { 
      console.log(response.request.responseURL)
   })
   .catch(error => {
     console.log(error.response)
   });

});

我的刀片视图是

@extends('layouts.app')

@section('head')
@php 
// dd($intent);
@endphp
<script src="https://js.stripe.com/v3/"></script>
<link href="{{ asset('css/stripe.css') }}" rel="stylesheet">
@endsection

@section('content')

<input id="card-holder-name" type="text">

<!-- Stripe Elements Placeholder -->
<div id="card-element"></div>

<button id="card-button" data-secret="{{ $intent->client_secret }}">
    subscribe
</button>

@endsection

@section('js')

  <script src="{{ asset('js/stripe.js') }}" type="text/javascript"></script>
@endsection

似乎一切正常,但我只是在控制台中收到 3ds 确认页面作为响应。如何让 laravel 重定向并为用户打开该页面?

【问题讨论】:

    标签: laravel stripe-payments confirmation 3ds


    【解决方案1】:

    我认为问题在于事件的顺序,您的代码应该等待 3DS 被调用并完成,然后在结果返回给您后回调您的代码。使用这张调节卡 [1],您应该能够通过一些像这样的小改动来测试它(我不得不删除一些东西,但这应该是一个参考):

    stripe.confirmCardSetup(
      "seti_xxx", {
        payment_method: {
          card: card,
          billing_details: { name: "Name" }
        }
      }).then(function(result) {
          // Check the result status here!!
    
          axios.post('checkout', {
            payment_method: result.setupIntent.payment_method
          }).then(response => { 
            console.log(response.request.responseURL)
          }).catch(error => {
           console.log(error.response)
         });    
        });
    

    希望这会有所帮助!

    [1]https://stripe.com/docs/testing#regulatory-cards

    【讨论】:

    • 有了这段代码,我得到了 stripe.js:960 Uncaught (in promise) TypeError: Cannot read property 'setupIntent' of undefined 似乎 stripe.js 想要 setupIntent var 而不是结果变量 但也是为什么我需要事先检查 3ds ......我有检查它的代码并生成整个确认页面。它只是没有被重定向到它......整个页面在我的控制台中呈现为响应
    • 嗯....我实际上得到了它来打开带有此代码的页面...但这真的是这样做的方法吗? axios.post('checkout', { payment_method: setupIntent.payment_method }).then(response =&gt; { if(typeof(response.request.responseURL != null)) { top.location = response.request.responseURL; } // console.log(response.request.responseURL) }) .catch(error =&gt; { console.log(error.response) });
    • 代码的 axois 部分完全取决于您以及它如何与您的后端交互。为了知道 3DS 模式发生了什么(用户是否经过身份验证),代码应该真正等待解决,然后再执行任何操作,即我在上面发布的伪代码的 then() 子句中发生了什么。
    猜你喜欢
    • 2022-11-18
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    • 2021-09-18
    • 1970-01-01
    相关资源
    最近更新 更多