如何使用带有条纹托管发票页面的3D Secure为付款卡创建付款缩进

时间:2019-07-05 11:44:11

标签: stripe-payments 3d-secure stripe-invoices

当我创建按期付款时没有问题,需要身份验证时无法收取第二笔费用,Stripe必须通过确认链接向客户发送信件时不理解这种方法,该链接指向条带化托管页面,如Docs

使用SCA的请求要求卡片我出现了卡片错误(authorization_required)。

        $intent = PaymentIntent::create([
            'amount'               => 1100,
            'currency'             => 'usd',
            'payment_method_types' => ['card'],
            'customer'             => $customerId,
            'payment_method'       => $paymentMethodId,
            'off_session'          => true,
            'confirm'              => true,
        ]);

我发现这种方法here。在“条纹”仪表板中设置settings,以接收电子邮件。 也许必须与发票API有关,但我看不到文档中的流程。

预期将创建具有require_confirmation状态的成功PaymentIndent。通过确认按钮发送给客户的电子邮件。

1 个答案:

答案 0 :(得分:0)

根据3D安全的新规定,需要其他付款确认。您可以使用以下代码来实现。

  

将意图传递给该功能(服务器代码)

    const generate_payment_response = (intent) => {
    if (
      intent.status === 'requires_action' &&
      intent.next_action.type === 'use_stripe_sdk'
    ) {
      // Tell the client to handle the action
      return {
        requires_action: true,
        payment_intent_client_secret: intent.client_secret
      };
    } else if (intent.status === 'succeeded') {
      // The payment didn’t need any additional actions and completed!
      // Handle post-payment fulfillment
      return {
        success: true
      };
    } else {
      // Invalid status
      return {
        error: 'Invalid PaymentIntent status'
      }
    }
  };
  

提示式3D安全弹出式窗口(前端代码)

function handleServerResponse(response) {
    console.log(response, "handling response");

    if (response.data.success) {
      // Show error from server on payment form
      alert("Paymemt successful");

    } else if (response.data.requires_action) {
        alert("require additional action");
        // Use Stripe.js to handle required card action
        stripe.handleCardAction(
            response.data.payment_intent_client_secret
            ).then(function(result) {
                if (result.error) {
                    // Show error in payment form
                } else {
                    // The card action has been handled
                    // The PaymentIntent can be confirmed again on the server
                    let data = {
                        payment_intent_id: result.paymentIntent.id 

                    }
                    axios.post(`${baseUrl}/confirmPayment`, data).then(response => {
                        handleServerResponse(response);
                    });
                }
            }).catch(error => {
                console.log(error, "error");

                alert("rejected payment");
            })
        } else {
            // Show failed
            alert("Failed transaction");
            alert(response.data.message);
            console.log(response.data, "error during payment confirmation");
    }
  }
相关问题