'Stripe Invoice. Start/created and End date are all the same for first invoice

I am getting back the invoices from my API, and I am noticing that if there are 2 full month billing cycles, all good - but I always get back one in which the start/end and created dates are the same.

So, I end up displaying it and it makes no sense.. ie.

Lets say a user created an account on July 19, 2016.. for one of the invoices (the others are good), I am getting this.

amount: 0
billingDate:"2016-07-19T23:20:33.000Z"
endDate:"2016-07-19T23:20:33.000Z"
startDate:"2016-07-19T23:20:33.000Z"

How should I handle this, or how is this a valid response? Keep in mind my billing is on the 8th. I am just a little afraid :-), to omit it if the start/end/created date are all the same.



Solution 1:[1]

The current_period_end and current_period_start corresponds to the period the invoice is for. As a rule on Stripe's end, the invoice is always for the "previous" period while the line item for the subscription is always for the new month.

This means that if you have a monthly subscription on the 1st of the month, the invoice on the 1st of November will be for the 1st of October until the 1st of November while the line item for the subscription will be for 1st of November to the 1st of December.

There is an exception which is for the first invoice. Since there is no "past" for the invoice, current_period_end and current_period_start will be equal in that situation and correspond to the date the subscription was created.

I'd recommend using the subscription's line item's period instead if you're displaying a date for the period the invoice corresponds to.

Solution 2:[2]

Indeed, stripe docs says:

period_end: End of the usage period during which invoice items were added to this invoice.

period_start: Start of the usage period during which invoice items were added to this invoice.

So they're not the subscription period at all.

To find the actual subscription periods, as described in previous answer's comment, we need to filter the line items of this invoice. Specifically, we need the non-proration ones, because this is the item describing normal subscription cycles. As in:

find item in invoice.lines.data where item.proration==False

-> item.period.end
-> item.period.start

If there are no subscription items, as is the case with a mid cycle change if we configured pending_invoice_item_interval, any item's period would do, because they will be of the period that is currently being modified.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 koopajah
Solution 2