I'm creating a charge using add-charge api call. The issue is that in response i'm getting full customer details, which means that i'm unable to distinguish newly created charge from other ones.
What would be the best way to pin-point charge i've just created?

#1 Posted by Marc Guyer Support staff on 30 Nov, 2016 10:01 PM
Hi Jack -- The response includes the created charge in context with the current invoice. It will be the first charge record in the DOM. In XPath, that's
//charge[1]. Are you using a client lib of any kind? As an example, the PHP lib returns a DOM Document object which can be easily queried via XPath.#2 Posted by Jack Zabolotnyi on 01 Dec, 2016 09:34 AM
I've just tried to create several charges and looks like your answer is incorrect: newly added charge will be the last one (not the first one).
This also leads to potential race condition where one cannot be sure if he fetched charge he just created or charge that was created at the same moment by another process.
#3 Posted by Marc Guyer Support staff on 02 Dec, 2016 03:56 PM
Hi Jack --
You're correct, my mistake. The convention is to reverse order records in the API response but it seems that charges does not follow that convention.
Good catch. I appreciate you more each time we have a discussion :) Requests that modify records are generally atomic when necessary (
add-item-quantitycomes to mind). I don't recall if creating a charge is atomic but I think it is. I'll have to research that in more detail to find out for sure. If it's not, it would only be the generation of the response itself that could potentially be done concurrently with another simultaneous request. In other words, multiple charges cannot be created concurrently but the response may be created concurrently.Jack Zabolotnyi closed this discussion on 05 Dec, 2016 12:59 PM.