首页 > 解决方案 > Stripe .NET 39.45 - Plan 类关联在 Subscription 类上移到了哪里?

问题描述

从 .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

解决方案


PlanSubscription作为39.1.2 的一部分被删除。

您现在需要这样做

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

推荐阅读