3

I'm following the example provided in the Stripe documentation on Previewing Proration using the Stripe.NET library to try to find the amount that will be charged when a customer upgrades from Plan A to Plan B.

However, when I use the code sample in the documentation, I get an error:

UpcomingInvoiceOptions options = new UpcomingInvoiceOptions()
{
    CustomerId = "cus_XXXXXXXXXXXXX",
    SubscriptionProrationDate = DateTime.UtcNow,
    SubscriptionItems = new List<InvoiceSubscriptionItemOptions>()
    {
        new InvoiceSubscriptionItemOptions()
        {
            Id = "si_XXXXXXXXXXXXXX", // Current Sub Item
            PlanId = "plan_XXXXXXXXXXXX" // New plan
        }
    }
};
InvoiceService service = new InvoiceService();
var result = service.Upcoming(options);

The last line throws a Stripe.StripeException: You cannot update a subscription item without a subscription.

Kcoder
  • 3,422
  • 4
  • 37
  • 56

1 Answers1

2

Turns out options.SubscriptionId is a required field for this action if you don't call service.Get first.

The following code produces the correct results:

UpcomingInvoiceOptions options = new UpcomingInvoiceOptions()
{
    CustomerId = "cus_XXXXXXXXXXXXX",
    SubscriptionId = "sub_XXXXXXXXXXXX",
    SubscriptionProrationDate = DateTime.UtcNow,
    SubscriptionItems = new List<InvoiceSubscriptionItemOptions>()
    {
        new InvoiceSubscriptionItemOptions()
        {
            Id = "si_XXXXXXXXXXXXXX", // Current Sub Item
            PlanId = "plan_XXXXXXXXXXXX" // New plan
        }
    }
};
InvoiceService service = new InvoiceService();
var result = service.Upcoming(options);
Kcoder
  • 3,422
  • 4
  • 37
  • 56