rebelidealist/stripe-ruby-mock — pull request #69 by gyardley (2014-03-01 23:13:33+00:00)
Title: Added basic Stripe::Invoice.upcoming functionality

This pull request adds one of the most basic use cases for `Stripe::Invoice.upcoming`.

When a customer has one (or more) subscriptions, `Stripe::Invoice.upcoming` will return the next invoice, correctly totaled and dated. (For example, if a customer has an invoice for one subscription renewal coming up in five days, and another coming up in eight days, `Stripe::Invoice.upcoming` will return the invoice for the subscription coming up in five days.) It should work just fine for, say, retrieving the next subscription billing date.

This pull request does not support adding additional invoice items to a subscription's upcoming invoice -- since at the moment the invoice item API calls aren't really built out in stripe-ruby-mock. If you try to add an retrieve the next invoice with `Stripe::Invoice.upcoming`, it won't include these invoice items. I might add this in a future pull request, if it's needed by others -- I don't need it for my own development.

This pull request also doesn't support adding invoice items to a customer *without* a subscription, which Stripe will let you do -- but in this case Stripe behaves oddly and the invoice items don't ever seem to get charged, at least not in my testing (I'm guessing since they're not attached to an upcoming subscription, and that's the whole reason for invoice items).

Note that I fudged a bit when figuring out the next invoice date for a subscription that's charged monthly -- I assumed a 'month' has a uniform length of 30 days. I'm not sure what Stripe does in the case where subscriptions are charged once a month.