条带订阅 webhook
Posted
技术标签:
【中文标题】条带订阅 webhook【英文标题】:stripe subscription webhooks 【发布时间】:2018-11-29 14:53:06 【问题描述】:我正在实施订阅,但我在使用 webhook 逻辑时遇到了问题。
我首先为初始订阅创建一个发票项目,在订阅时将支付这样的费用:
var invoiceItem = await _invoiceItemRepo.CreateInitialSubscriptionPaymentAsync(product, stripeCustomer);
var plans = await _planRepo.GetAllPlansAsync();
await _subscriptionRepo.CreateSubscriptionAsync(stripeCustomer.Id, plans);
succesful case :
IiThenSub@su.su subscribed to Pro_Service 3 and 2 more…
IiThenSub@su.su was charged €3,000.00
IiThenSub@su.su's invoice for €3,000.00 was paid
IiThenSub@su.su has a new invoice for €3,000.00
IiThenSub@su.su's invoice item was added to an invoice
IiThenSub@su.su's details were updated
An invoice item for €3,000.00 was created for IiThenSub@su.su
Failed payment case:
IiThenSubFail@su.su's payment for €3,000.00 failed
IiThenSubFail@su.su's details were updated
An invoice item for €3,000.00 was created for IiThenSubFail@su.su
在成功的情况下,我看到首先创建了 Invoice 项目,然后将其添加到发票中,创建了费用,付款成功并完成了订阅。
然而,在付款失败的情况下,我只收到一个收费失败事件,其中不包含发票项目的 ID,也不包含发票的 ID。
所以我不知道如何将此失败的费用与我的订阅尝试相关联。请您指出正确的方向吗?
【问题讨论】:
【参考方案1】:我为初始付款创建发票项目, 然后我手动创建发票并付款, 收到付款后,我创建订阅。 这样我确实有一张发票,并且可以收到 invoice.payment_failed 事件。 唯一的问题(在我的情况下可以忽略不计)是它会创建 2 张发票,第一个包含发票项目,第二个是通过订阅自动创建的,但价格为 0,所以我忽略了它。
编辑:使用此方法的事件日志
SubKo2@su.su subscribed to Pro_Service 3 and 2 more…
SubKo2@su.su's invoice for €0.00 was paid
SubKo2@su.su has a new invoice for €0.00
SubKo2@su.su's invoice has changed
SubKo2@su.su's invoice for €3,000.00 was paid
SubKo2@su.su's details were updated
SubKo2@su.su was charged €3,000.00
SubKo2@su.su's default payment source changed
SubKo2@su.su added a new payment source
SubKo2@su.su's invoice has changed
SubKo2@su.su's payment for an invoice for €3,000.00 failed
SubKo2@su.su's details were updated
SubKo2@su.su's invoice has changed
SubKo2@su.su's payment for €3,000.00 failed
SubKo2@su.su has a new invoice for €3,000.00
SubKo2@su.su's invoice item was added to an invoice
SubKo2@su.su's details were updated
An invoice item for €3,000.00 was created for SubKo2@su.su
SubKo2@su.su added a new payment source
SubKo2@su.su's details were updated
所以我现在可以接收与发票相关的事件并轻松重试失败的付款
【讨论】:
【参考方案2】:这是意料之中的,因为在这种情况下订阅创建失败。由于失败,Stripe 会“回滚”任何内容,不会创建订阅,只会返回错误。因此,它也不会创建发票,因此没有什么可以“映射”到。
很遗憾,将charge.failed
事件映射到此事件的唯一方法是基于客户 ID 以及您刚刚尝试创建订阅失败的事实。
【讨论】:
以上是关于条带订阅 webhook的主要内容,如果未能解决你的问题,请参考以下文章