简体   繁体   中英

Stripe API Pass Dynamic Data

Is there a way to pass dynamic data to the Stripe API? I'm using the example found here: 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. 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. 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."

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.

You can achieve what I wanted through the Server + Client integration by using the client_reference_id when creating a session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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