Fetching upcoming invoice's line items loses the request's original parameters
See original GitHub issueWhen you retrieve an upcoming invoice in the API, your invoice might have more than 10 items. In that case you end up having to paginate the invoice. When doing so, you want to make sure that your parameters are passed automatically so that things like proration or plan changes are still taken into account on the next page(s).
Today, this is not working properly. This was originally reported in https://github.com/stripe/stripe-java/issues/264 and fixed in https://github.com/stripe/stripe-java/pull/275 so that you could explicitly pass the parameters to autoPagingIterable()
. This was broken again in https://github.com/stripe/stripe-java/pull/294 when we removed StripeCollectionAPIResource
though.
To reproduce the issue you need to do something like this:
- Create a customer with a subscription on a $20 plan
- Create 11 invoice items on that customer
- Retrieve the upcoming invoice simulating a change to a plan for $50
- Confirm that the last line item, for next month’s subscription, is for the $50 plan
Example code:
String customerId = "cus_1234";
String newPlan = "plan_1234";
String subscriptionId = "sub_1234";
Subscription sub = Subscription.retrieve(subscriptionId);
Map<String, Object> itemNew = new HashMap<String, Object>();
itemNew.put("id", sub.getSubscriptionItems().getData().get(0).getId());
itemNew.put("plan", newPlan);
List<Object> itemsChange = new ArrayList<>();
itemsChange.add(itemNew);
Map<String, Object> invoiceParams = new HashMap<String, Object>();
invoiceParams.put("customer", customerId);
invoiceParams.put("subscription", sub.getId());
invoiceParams.put("subscription_items", itemsChange);
Invoice upcoming = Invoice.upcoming(invoiceParams);
Iterable<InvoiceLineItem> itItems = upcoming.getLines().autoPagingIterable();
for (InvoiceLineItem item : itItems) {
System.out.println(item);
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
@itgeorge Thanks for the ping and sorry for the lack of update on that one. This is not an issue we have fixed yet because it’s unfortunately a tricky edge-case that we are trying to fix another way by adding a client/service infrastructure that would let you explicitly call the endpoint you expect instead.
We’ll investigate again though to see if there’s something we can temporarily introduce to fix this.
The original issue with the upcoming invoice line item iteration should be fixed on the service side now.