Why are Invoices listed out of order when I use the List an Account's Invoices Endpoint?

The List Accounts Invoices endpoint default return is descending (new - old). You may notice that in some instance invoices are listed out of numerical order. This is specifically true for immediate subscription changes where a charge and credit invoice are generated in the same second. In this scenario, the credit invoice will have the lower number and the charge invoice the higher number. 

This is so that the credit can be applied to the charge invoice as part of the same transaction. Both the credit and charge invoice are held in a processing state until any outstanding balance owed on the charge invoice is processed through the payment gateway. The reason for this is so if there is an issue with paying for the subscription change both invoices will be rolled back and neither will be persisted. So if the customer owed additional funds and we attempt the charge that returns a decline both invoices will be rolled back and the change will not take place. Once the charge invoice is marked paid it gets persisted first as part of applying the payment and then the credit invoice is saved after that. Which is why they show out of numerical sequence in both the charges and credits section as well as in the List Invoices API return. 

You'll see this same order in the charges and credits section in the UI.