英文:
How do I associate a checkout_session with a payment using Firebase stripe extension?
问题
如你所知,Firebase 的 Stripe 支付扩展会执行以下操作:
- 创建一个名为
products
的集合,其中包含在 Stripe 中管理的产品。 - 在
customers/{id1}/checkout_sessions/{id2}
下创建一个文档会在 Stripe 中创建一个付款。文档会随后更新,包含用户可用于支付的付款链接。 - 支付完成后,Stripe 会在
customers/{id1}/payments/{id3}
下创建一个文档。
你想要将注册的付款与 checkout_sessions
文档关联起来,正确吗?
checkout_session
文档看起来像这样:
{
cancel_url: (取消链接),
client: "web",
created: (时间戳),
mode: "payment",
price: (与产品相关的 priceId),
sessionId: (checkout_session 的会话 id),
success_url: (成功链接)
}
我自己创建了 checkout_session
文档,所以我可以在其中添加额外的元数据,但我不确定 Stripe 是否可以使用它。
payment
文档要复杂得多。但我可以关联到的唯一 id 是出现在付款文档中的客户 stripeId
,它显示为 customer
。
基本上,我试图做以下事情:
- 用户创建一个具有一些自定义属性的数字项目(名称、选项等)。
这可以在创建checkout_sessions
文档时发生。 - 他们使用提供的链接进行支付。
- 创建了
payments
文档。 - 这是你帮助我确认他们所做的付款与创建的数字项目相关联的地方。
我有一个可能会起作用的想法:与其在创建 checkout_sessions
文档时允许创建数字项目,我可以为该特定项目创建一个“凭证”。它不会包含任何个性化或选项,但我可以在付款文档上创建一个 onCreate
云函数。如果付款成功,我会允许创建数字项目。我可以根据所购买的项目查找“模板”。
我不喜欢这个选项,因为至少会有两个潜在的冷启动延迟,这可能会导致糟糕的用户体验。
英文:
As you might know, the Stripe payment extension for Firebase does the following:
- Creates a
products
collection that gets filled with products managed in Stripe. - Creating a document under
customers/{id1}/checkout_sessions/{id2}
creates a payment in stripe. The document gets updated with the payment URL that the user can use to pay. - After paying, a document gets created by Stripe at
customers/{id1}/payments/{id3}
How do you associate the payment that gets registered to the document in checkout_sessions?
The checkout_session
document looks like
{
cancel_url: (CancelUrl),
client: "web",
created: (Timestamp),
mode: "payment",
price: (The priceId associated to the product),
sessionId: (The session id of the checkout_session),
success_url: (SuccessUrl)
}
I create the checkout_session
document myself, so I can add extra meta data in there but I'm not sure if Stripe can use it.
The payment
document is significantly more complex. But the only id that I can associate to anything is the customer stripeId
which appears as customer
on the payment document.
Basically I'm trying to do the following.
- A user creates a digital item with some custom properties (name, options, etc).
This can happen during the creation of thecheckout_sessions
document. - They pay using the URL provided.
- The
payments
document is created - This is where you help me figure out to validate that the payment they made is associated with the digital item created.
One idea that I have that will probably work is to do the following: Instead of allowing the creation of the digital item during the creation of the checkout_sessions
document, I can create a "voucher" for that specific item. It won't have any personalization or options, but what I can do is create document onCreate cloud function on the payment document. If the payment is successful, allow the creation of the digital item. I can look up the 'template' based on the item purchased.
I dont like this option because there are at least 2 potential cold start delays that could make this a bad user experience.
答案1
得分: 0
你应该监听 checkout.session.completed
事件并提取结帐会话对象的 line_items
。从那里你会知道哪些商品已成功购买。
详细说明在集成文档中。
英文:
You should listen to the checkout.session.completed
event and retrieve the line_items
of the checkout session object. From there you'll know what items are purchased successfully.
The details are explained in the integration doc
答案2
得分: 0
在创建 checkout_sessions
文档时,您可以添加一个 metadata
对象,其中可以包含键值对,这些键值对将出现在在 payments
集合中创建的文档的根部。
英文:
When creating the checkout_sessions
document, you can add a metadata
object that can contain key:value pairs that will appear on the root of the document that is created in payments
collection.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论