1

当我创建会话支付时没有问题,在需要身份验证时无法进行第二次收费,当 Stripe 必须向客户发送一封带有确认链接的信时,不理解一种方法,该链接指向 Stripe 托管页面就像在文档中一样

使用 SCA 所需卡的请求我收到卡错误 (authorization_required)。

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

我在这里找到了这种方法。在 Stripe 仪表板中为电子邮件设置设置。也许必须与发票 API 有关系,但我在文档中看不到流程。

期望以 requires_confirmation 状态成功创建 paymentIndent。带有确认按钮的电子邮件发送给客户。

4

1 回答 1

1

根据 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");
    }
  }
于 2019-07-09T10:27:23.910 回答