Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
666 views
in Technique[技术] by (71.8m points)

stripe payments - Link PaymentIntent to a Product

I'm using the custom checkout flow from stripe to add online payment to my website which uses a server endpoint to create the PaymentIntent like so:

app.post("/create-payment-intent", async (req, res) => {
  const { items } = req.body;
  // Create a PaymentIntent with the order amount and currency
  const paymentIntent = await stripe.paymentIntents.create({
    amount: 499,
    currency: "usd"
  });
  res.send({
    clientSecret: paymentIntent.client_secret
  });
});

I was wondering, instead of setting the price and currency directly in the PaymentIntent, could that come from a Product created on Stripe? I understand that I can just fo it myself and fetch the associated Product and Price from the API and create my PaymentIntent from that but then Stripe will have no way to "track" that this payment was made for this product (useful for analytics).

I know that this is possible to do with Checkout where a product can be associated with it. But I couldn't find anything for a custom checkout flow.

Cheers!

question from:https://stackoverflow.com/questions/65917042/link-paymentintent-to-a-product

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

An option, until associating Prices and Products directly with PaymentIntents is supported, would be to leverage metadata on the PaymentIntent to track which Prices contribute to the final amount [1]. Then you would have the opportunity to record that in your DB or query that from the PaymentIntents API.

[1] https://stripe.com/docs/api/payment_intents/object#payment_intent_object-metadata


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...