简体   繁体   English

条带化 API 传递动态数据

[英]Stripe API Pass Dynamic Data

Is there a way to pass dynamic data to the Stripe API?有没有办法将动态数据传递给 Stripe API? I'm using the example found here: https://stripe.com/docs/payments/checkout/client我正在使用此处找到的示例: https://stripe.com/docs/payments/checkout/client

I'd like to be able to pass a token along with the purchase in order to link an account with that payment.我希望能够在购买时传递令牌,以便将帐户与该付款相关联。 After the client side sends the payment to the API, my backend would receive the details of the payment, including the token to link it to an account created before this.在客户端将付款发送到 API 后,我的后端将收到付款的详细信息,包括将其链接到之前创建的帐户的令牌。 I would add it as a param to to the successful redirect, but if they close the window early then the accounts will not be linked.我会将其作为参数添加到成功的重定向中,但如果他们提前关闭 window,那么这些帐户将不会被链接。 I set up my product using the dashboard.我使用仪表板设置我的产品。

I tried using metadata and description as a part of the line item, but it keeps saying "Invalid stripe.redirectToCheckout parameter: lineItems.0.description is not an accepted parameter."我尝试使用元数据和描述作为订单项的一部分,但它一直说“无效的 stripe.redirectToCheckout 参数:lineItems.0.description 不是一个可接受的参数。”

let token;
stripe.redirectToCheckout({
    lineItems: [{
      price: 'boop', // Replace with the ID of your price
      quantity: 1,
      description: token
    }],
    mode: 'payment',
    successUrl: 'http://boop.com',
    cancelUrl: 'http://boop.com',
  }).then(function (result) {
    // If `redirectToCheckout` fails due to a browser or network
    // error, display the localized error message to your customer
    // using `result.error.message`.
  });

Thank you!谢谢!

In order to pass metadata and other fields in Checkout, you need to use the Server + Client integration path instead of the client-only integration.为了在 Checkout 中传递metadata和其他字段,您需要使用服务器 + 客户端集成路径而不是仅客户端集成。

You can achieve what I wanted through the Server + Client integration by using the client_reference_id when creating a session.在创建 session 时,您可以通过使用client_reference_id通过服务器 + 客户端集成来实现我想要的。

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

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