recurly/recurly-client-java

invoices related immediately subscription change

zhuravskiy opened this issue · 10 comments

Hi!
In some cases hard to collect invoices after
https://developers.recurly.com/api/v2019-10-10/index.html#operation/create_subscription_change
with time_frame = now.

Case:
I making create_subscription change call, then collect the latest subscription invoices with a query, then filter, looks ugly and I have a risk to get wrong invoices when we have concurrent operations with account`s invoices.

Question:
Is it possible to return invoices related subscription change with timeframe now?
or maybe we have another way to find invoices related to subscription change id?

bhelx commented

@zhuravskiy Let me re-iterate how I'm reading this so we can make sure I'm understand your question correctly, you're calling create_subscription_change with timeframe=now in order to create an invoice, but you don't have a good way to reliably get that invoice? I guess because of the async nature of invoices.

then collect the latest subscription invoices with a query, then filter, looks ugly and I have a risk to get wrong invoices when we have concurrent operations with account`s invoices.

Which call are you using to find the invoice? Perhaps in the short term I can help you fix that part.

Is it possible to return invoices related subscription change with timeframe now?
or maybe we have another way to find invoices related to subscription change id?

Yes, I think we can consider altering the API to make this easier.

but you don't have a good way to reliably get that invoice?

right

I guess because of the async nature of invoices.

agree

Which call are you using to find the invoice?

I am using https://developers.recurly.com/api/v2019-10-10/index.html#operation/list_subscription_invoices
with different filter params, depends on what I've changed, and then additional in-memory filtering.

Yes, I think we can consider altering the API to make this easier.

It would be great!
if subscription change feature totally async by design, maybe possible somewhere in the API to get info about activated subscription change id -> affected/created invoice ids.
but it's up to you

bhelx commented

Okay, I'm putting this on my team's agenda to discuss tomorrow. Feels like we should be able to change the API to help here.

bhelx commented

Had a discussion with the team, we realized 2 things.

  1. If the change created any invoices, we should render the collection in the response. That would allow you to get the id for the invoice immediately.
  2. As a more generic solution to this problem, we should have an active_invoice linked on the subscription (as we do in V2) so at any point you can always determine which invoice is the active one on a subscription.

I'm planning the work for these changes now. Some of the details might change but I hope to get them started in the next couple weeks.

Great news!
@bhelx thank you!

@bhelx any updates? thanks!

bhelx commented

You can now get the InvoiceCollection on the change preview call response: https://github.com/recurly/recurly-client-java/blob/master/src/main/java/com/recurly/v3/resources/SubscriptionChangePreview.java#L157

I'm checking to see why it's not also in the create response.

bhelx commented

@zhuravskiy I passed this along to another team who was implementing the preview request, seems like it was just a missed requirement and I dropped the ball there. I'm going to make sure the collection is coming back in both responses. I will get that out next week.

bhelx commented

@zhuravskiy I got this implemented and merged and will go out in the API next Thursday. I'll push the clients out right after.

@bhelx thank you!