简体   繁体   English

Stripe js + React/JS 在条带重定向后访问数据

[英]Stripe js + React/JS accessing data after stripe redirect

In Netherlands, the popular payment method is Bancontact, and this method redirects the user to bank page where the user can either open bank app to pay or input credit card information在荷兰,流行的支付方式是 Bancontact,这种方式将用户重定向到银行页面,用户可以打开银行应用程序进行支付或输入信用卡信息

My question is the following in this example of code (this code will automatically push user to bank page):在此代码示例中,我的问题如下(此代码将自动将用户推送到银行页面):

stripe
  .confirmBancontactPayment('{PAYMENT_INTENT_CLIENT_SECRET}', {
    payment_method: {
      billing_details: {
        name: 'Jenny Rosen',
      },
    },
    // Return URL where the customer should be redirected after the authorization.
    return_url: window.location.href,
  })
  .then(function(result) {
    if (result.error) {
      // Inform the customer that there was an error.
    }
  });

After redirect, they access data inside following code:重定向后,他们访问以下代码中的数据:

.then(function(result) {
  if (result.error) {
    // Inform the customer that there was an error.
  }
});

Which doesn't make much sense because this is a refreshed page after user comes back from paying and JS state is refreshed since the这没有多大意义,因为这是用户从付款回来后刷新的页面,JS state 自

// Return URL where the customer should be redirected after the authorization.
return_url: window.location.href,

Did I miss a lesson in JS?我错过了 JS 的一堂课吗?

(code automatically redirects to bank page and brings user bank to your return url but .then() promise no longer exists) (代码自动重定向到银行页面并将用户银行带到您的退货 url 但 .then .then() promise 不再存在)

How do they access data after the user has been redirected and returned to refreshed page?在用户被重定向并返回到刷新页面后,他们如何访问数据?

Stripe page: https://stripe.com/docs/js/payment_intents/confirm_bancontact_payment条纹页面: https://stripe.com/docs/js/payment_intents/confirm_bancontact_payment

When using stripe.confirmBancontactPayment the .then at the end is used to catch errors that happen prior to the customer being redirected to their bank (such as the redirect failing).当使用stripe.confirmBancontactPayment.then最后的 .then 用于捕获在客户被重定向到他们的银行之前发生的错误(例如重定向失败)。 The .then code will not be called after a successful redirect. .then代码在重定向成功后不会被调用。

How do they access data after the user has been redirected and returned to refreshed page?在用户被重定向并返回到刷新页面后,他们如何访问数据?

When calling stripe.confirmBancontactPayment you specify a return_url your customer will be sent to after the authorize the payment at the bank's website.在调用stripe.confirmBancontactPayment时,您指定一个return_url ,您的客户将在银行网站上授权付款后发送到该地址。 The return_url will have the following query parameters added: return_url将添加以下查询参数:

  • payment_intent
  • payment_intent_client_secret

These values allow you to link the redirect back to the original Payment Intent.这些值允许您将重定向链接回原始付款意图。

For example, if you specify a return_url of https://example.com/return the customer will be sent to https://example.com/return?payment_intent=pi_123&payment_intent_client_secret=pi_123_456例如,如果您指定https://example.com/returnreturn_url ,则客户将被发送到https://example.com/return?payment_intent=pi_123&payment_intent_client_secret=pi_123_456

This entire flow is covered in more detail in Stripe's Bancontact Payments Guide .Stripe 的 Bancontact Payments Guide更详细地介绍了整个流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM