#mark-invoice-upcoming

1 messages · Page 1 of 1 (latest)

dark pasture
#

Hi!

#

So sorry, I missed this message

#

Reading!

#

So when you update a Subscription, a new invoice will always be cut if the billing cycle changes.

brave light
#

Hi. A new invoice for the proration is always created when calling update as follows:

subscription = await stripe.subscriptions.update(
  subscriptionId,
  {
    items: Object.values(updatedItems),
    payment_behavior: 'default_incomplete',
    proration_behavior: 'always_invoice',
    expand: ['latest_invoice.payment_intent'],
    proration_date: currentPeriodStart + (daysSincePeriodStart * 86400),
  },
);
#

However, if I try to preview the update via

const invoice = await stripe.invoices.retrieveUpcoming({
  customer: customerId,
  subscription: subscriptionId,
  subscription_items: Object.values(updatedItems),
  subscription_proration_behavior: 'always_invoice',
  subscription_proration_date: currentPeriodStart + (daysSincePeriodStart * 86400),
});
#

I only get the immediate invoice if there is a positive proration.

dark pasture
#

Right because otherwise the proration becomes a credit on the customer. However, there should still be a $0 invoice if I remember correctly.

#

No invoice is being generated at all?

brave light
#

For zero or negative prorations, retrieveUpcoming seems to be giving me the invoice for the next subscription cycle.

dark pasture
#

Gotcha. Let me check on something

brave light
#

thanks

daring stump
#

👋

#

if you pass proration_behavior: 'always_invoice' you explicitly say "Please make the change and invoice now (your first example). If you don't, the default is to prorate and wait for the next cycle

#

Whether it's a downgrade or upgrade doesn't matter and it always works the same way

brave light
#

But it doesn't seem to for me when using invoices.retrieveUpcoming. It does for subscriptions.update. Both have 'always_invoice' set.

daring stump
#

I'm going to need way more specific details to be able to help you debug this. I need the exact customer and subscription ids and the exact value you are passing in subscription_items and subscription_proration_date + the raw JSON you get back from that call

brave light
#

Can you do it from the request IDs?

daring stump
#

kind of

brave light
#

Successful positive proration: req_uUIZfGMHI3nQSt
Unsuccessful negative proration: req_uUIZfGMHI3nQSt

daring stump
#

those are the exact same ids

brave light
#

Sorry - give me a sec.

daring stump
#

Debugging this can be really tricky, my recommendation is to write really simple/basic code that will
1/ Create a Subscription
2/ Update that Subscription with the right settings and look at the Invoice
and do this for both changes separately

daring stump
#

@brave light did you find more details?

brave light
#

Sorry - just trying now to get the JSON output in the two situations.

daring stump
#

all good

#

I don't really need the JSON if you use the update path instead of the upcoming invoice

brave light
#

Annoyingly it seems to be behaving as expected now, so I think I'm going to have to leave this unless I can work out why it was happening. Thanks for your help though!

daring stump
#

I do think you likely were mixing up the subscription ids or not really making changes to the subscription

#

that's often what causes confusion like this

brave light
#

Yes, probably got confused. Thanks again.