#jon-subscription-pendingitems

1 messages ยท Page 1 of 1 (latest)

wary pendantBOT
elder nebula
#

only other thing to note, is that I am occasionally creating a pending invoice item right before hitting the API to upgrade a subscription, in case it's maybe a timing related thing?

celest veldt
#

Are you always passing subscription: 'sub_123' when creating those?

#

if you had a clear example I could look at that would help

#

jon-subscription-pendingitems

elder nebula
#

yeah, I'm always passing it. One sec, I'll grab an example

#

here's a customer's pending invoice items:

#<Stripe::ListObject:0x11673c> JSON: {
  "object": "list",
  "data": [
    {"id":"ii_1OXAOLJuNNxW1J1aCdxPDpf7","object":"invoiceitem","amount":500,"currency":"usd","customer":"cus_PLs7zb0w4VIaIX","date":1704926217,"description":"Podcast transcriptions (300 minutes per month) paid monthly","discountable":false,"discounts":[],"invoice":null,"livemode":false,"metadata":{"addon":"transcription-300","period":"month","stuff":"from webhook"},"period":{"end":1710110172,"start":1707604572},"plan":null,"price":{"id":"price_1OWjmrJuNNxW1J1aFn2Y6KB3","object":"price","active":false,"billing_scheme":"per_unit","created":1704823949,"currency":"usd","custom_unit_amount":null,"livemode":false,"lookup_key":null,"metadata":{},"nickname":null,"product":"prod_PLQeakddl0do26","recurring":null,"tax_behavior":"unspecified","tiers_mode":null,"transform_quantity":null,"type":"one_time","unit_amount":500,"unit_amount_decimal":"500"},"proration":false,"quantity":1,"subscription":"sub_1OXANSJuNNxW1J1aqfB8jnAX","tax_rates":[],"test_clock":null,"unit_amount":500,"unit_amount_decimal":"500"}
  ],
  "has_more": false,
  "url": "/v1/invoiceitems"
#

and that customer's subscription (partial paste can't fit it all)

#<Stripe::Subscription:0x10e6f4 id=sub_1OXANSJuNNxW1J1aqfB8jnAX> JSON: {
  "id": "sub_1OXANSJuNNxW1J1aqfB8jnAX",
  "object": "subscription",
  "application": null,
  "application_fee_percent": null,
  "automatic_tax": {"enabled":false},
  "billing_cycle_anchor": 1704926172,
  "billing_thresholds": null,
  "cancel_at": null,
  "cancel_at_period_end": false,
  "canceled_at": null,
  "cancellation_details": {"comment":null,"feedback":null,"reason":null},
  "collection_method": "charge_automatically",
  "created": 1704926161,
  "currency": "usd",
  "current_period_end": 1707604572,
  "current_period_start": 1704926172,
  "customer": "cus_PLs7zb0w4VIaIX",
  "days_until_due": null,
  "default_payment_method": null,
  "default_source": null,
  "default_tax_rates": [],
  "description": null,
  "discount": null,
  "ended_at": null,
#

but if I upgrade their plan using the code I initially posted, the pending invoice items do not get charged always, but sometimes they do?

should they always be swept up and charged when changing a subscription plan?

celest veldt
#

looking, sorry was just literally expecting the two ids + the exact API requests that didn't properly include it, not the whole json

#

Do you have a clear example of the exact API request that did something to the Subscription and ignored the pending InvoiceItem?

elder nebula
#

oh yeah sure, I can get the request IDs

celest veldt
#

looking at the logs you seem to make the Subscription update maybe in parallel? It's hard to say because lots of logs and Events on that one Customer/Subscription

elder nebula
#

yeah, I was testing a bunch of times.

this is the request that created the invoice item: req_haXGwIBxeSHvz6

#

and this was for the plan upgrade: req_EUpo6YJOAhshux

celest veldt
#

ah damn you use the SubscriptionItem API which is annoying to debug as there's no Invoice info

elder nebula
#

I could do it via the Subscription API instead of would that not make a difference?

celest veldt
#

no sorry I'm just trying to make sense of what you are doing overall. It's just harder when synchronous API requests don't have the exact raw JSON of all the object like seeing the real exact Invoice and every single line as a resul of your call

elder nebula
#

ah, gotcha. and yeah, these are synchronous API calls, nothing is ever in parallel, but invoice items are occasionally created just before an upgrade

celest veldt
#

(looking will take some time)

wary pendantBOT
celest veldt
#

@elder nebula sorry still quite baffled ๐Ÿ˜…

elder nebula
#

thanks no rush!

celest veldt
#

do you ahve an example where it worked fine?

#

trying to diff the request and figure out what's causing this

elder nebula
#

can try to find some examples yeah. might take a bit

celest veldt
#

no rush, we're still digging in parallel

#

@elder nebula oooooookay so it's by design.

#

Basically paired with 2 other people on my team who were as confused and we found old jiras (from me!!!!) saying this was weird lol

#

So it seems that when an Invoice is triggered by a Subscription Update with proration_behavior we do not pull in the pending InvoiceItems.
The only case we seem to pull them in is if your reset the billing cycle via billing_cycle_anchor: 'now'

#

really surprising. A fix would be to support pending_invoice_item_behavior on those but sadly it's not something we have built yet ๐Ÿ˜ฆ

elder nebula
#

well I guess that explains that! however, here is a request that did result in those pending invoice items being charged (different customer): req_kuKxGSW0j20xlG

#

this is the event: evt_1OWnu9JuNNxW1J1ab8f0ZHxb

#

and this is the invoice: in_1OWnu6JuNNxW1J1aacXTpU1M

#

BUT that upgrade was a swap from monthly to yearly, so maybe that explains it?

#

it's confusing! and maybe a huge edgecase

celest veldt
#

yeah monthly->yearly implicitly resets the billing cycle ๐Ÿ˜ฆ

#

It's so strange. And I say this as someone whose job is to know those products inside out and help developers with this. We'll push internally to get this improved but hopefully it explains what the issue is

elder nebula
#

thanks for the help! I'll have to try to figure out a different way to do this then...

#

thought I was going crazy there for a bit ๐Ÿ˜†

celest veldt
#

yeah me too if I'm being honest, that seemed "impossible" to my brain