条带订阅webhooks

时间:2018-06-20 12:55:21

标签: .net stripe-payments webhooks

我正在实现订阅,但是在webhooks逻辑上遇到了麻烦。

我首先为初始订阅创建一个发票项目,该项目将在订阅时支付:

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

在成功的情况下,我看到首先创建了发票项目,然后将其添加到发票中,创建了费用,成功付款并完成了订阅。

但是,在付款失败的情况下,我只收到一个收费失败的事件,其中不包含发票项目的ID或发票的ID。

因此,我不知道如何将失败的费用链接到我的订阅尝试。你能指出我正确的方向吗?

2 个答案:

答案 0 :(得分:0)

这是可以预期的,因为在这种情况下订阅创建失败。由于失败,Stripe会“回滚”任何内容,并且不会创建订阅,而只会返回错误。因此,它也不会创建发票,因此没有“映射”到的内容。

不幸的是,将charge.failed事件映射到此事件的唯一方法是基于客户ID和您刚刚尝试创建失败的订阅的事实。

答案 1 :(得分:0)

我为初始付款创建发票项目, 然后我手动创建发票并付款, 收到付款后,我将创建订阅。 这样,我确实有发票,并且可以收到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

所以我现在可以接收与发票有关的事件并轻松重试失败的付款