【问题标题】:Stripe .NET 39.45 - Where did the Plan class association move to on the Subscription class?Stripe .NET 39.45 - Plan 类关联在 Subscription 类上移到了哪里?
【发布时间】:2021-07-19 03:05:24
【问题描述】:

从 .Net Core 2.1 升级到 .Net 5(随后将我的 Stripe .net 库升级到 39.45)后,我注意到我的一些代码现在已损坏。我特别收到订阅对象的错误,因为它不再有“计划”对象。在下面的代码中,我有自己的名为“订阅”的内部表,为了方便起见,它实际上包含更多字段。无论如何,看起来他们从 Subscription 类中移动了“Plan”obj 类。

                var service = new SubscriptionService();
                var subscription = service.Get(successInvoice.SubscriptionId);

                if (subscription != null)
                {

                    var internalCustomer = _dbContext.Customers.First();
                    var internalSubscription = _dbContext.Subscriptions.FirstOrDefault(s => s.ExternalSubscriptionId == subscription.Id);

                    if (internalCustomer != null)
                    {
                        //If the subscription does not exist, it means this is the first time they are being charged
                        //and a new subscription must be added as well
                        if (internalSubscription == null)
                        {
                            internalSubscription = new Business.Entities.Billing.Subscription
                            {
                                CustomerId = internalCustomer.Id,
                                Customer = internalCustomer,
                                ExternalProductId = subscription.Plan.ProductId,
                                Amount = subscription.Plan.AmountDecimal.Value / 100,
                                Interval = subscription.Plan.Interval,
                                IntervalCount = subscription.Plan.IntervalCount,
                                ExternalSubscriptionId = subscription.Id
                            };

                            //Add this new subscription
                            _dbContext.Subscriptions.Add(internalSubscription);
                            _dbContext.SaveChanges();
                        }

所以这些代码行抛出了错误:

                  ExternalProductId = subscription.Plan.ProductId,
                                Amount = subscription.Plan.AmountDecimal.Value / 100,
                                Interval = subscription.Plan.Interval,
                                IntervalCount = subscription.Plan.IntervalCount,

是否有人知道他们将计划移至何处,或者如果我有订阅,具体如何检索计划?这段代码的目的是我想自己做

【问题讨论】:

    标签: c# stripe-payments .net-5


    【解决方案1】:

    Plan 已从 Subscription 中删除为 part of 39.1.2

    你现在需要这样做like this:

    var service = new PlanService();
    service.Get("price_1IjsKp2eZvKYlo2C4nz7QGls");
    

    【讨论】:

    • 很有趣,谢谢。现在再次提醒我,我从哪里得到价格(你传递给函数的字符串 ID)?此代码位于我的 if (stripeEvent.Type == "invoice.payment_succeeded") 的 webhook 中。感谢您抽出宝贵时间提供帮助!
    • 您可以使用plan_ ID 代替它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-14
    • 2010-09-16
    • 1970-01-01
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多