如何在支付成功后将用户ID值传递给Stripe以供使用

huangapple go评论88阅读模式
英文:

How to pass user id values to Stripe for use once payment has succeeded

问题

我有一个带有Express(typescript)后端的Angular应用程序。每个用户都有唯一的用户ID,一旦付款成功,我希望更新数据库中的用户信息,以反映他们是付费会员。看起来我要在付款成功后利用Stripe事件/ Webhook,但我的问题是一旦付款成功,被调用的Webhook如何知道用户ID是什么,以便我可以记录下来?似乎当用户去付款时,我只是将用户链接到Stripe为我生成的页面,而没有传递任何元数据,所以我不确定在付款成功的Webhook被调用时如何跟踪哪些用户实际付款了。感谢任何帮助。

英文:

I have an angular app with an express (typescript) backend. Each user has a unique user id and once payment has succeeded I want to update that user in the database to reflect that they are a paying member. It seems like I am going to be wanting to make use of Stripe events/webhooks once payment has succeeded, but my question is once payment has succeeded how does the webhook that's being called know what the user id is so I can record it? It seems that I am simply linking the user to Stripes page they generated for me when users go to pay without passing any metadata to it so I'm not sure how to keep track of which user has actually paid when the webhook for payment succeeded has been called. Thanks for any help.

答案1

得分: 1

正如您提到的,您可以在PaymentIntent的创建中传递metadata。使用Metadata,您可以将键值对附加到特定对象并将此附加信息存储在其中。在您的情况下,这将是最简单的解决方案。但是,您提到您不想使用Metadata,另一种选择是创建一个customer。然后,在PaymentIntent的创建中传递客户ID 4。当您收到您的payment_intent.succeeded event时,您可以将客户对象的ID映射到数据库中的用户ID。

英文:

As you’ve mentioned, you can pass metadata, on the PaymentIntent creation. With Metadata, you can attach key-value pairs to specific objects and store this additional information on it. In your case, this would be the easiest solution. However, you mentioned you did not want to use Metadata and an alternative would be to create a customer. Then, pass the customer id on the PaymentIntent creation. When you get your payment_intent.succeeded event you’d map the customer object id to the user id in your database.

huangapple
  • 本文由 发表于 2023年7月14日 07:28:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76683845.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定