Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
669 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...