How to get id of newly created charge?

Jack Zabolotnyi's Avatar

Jack Zabolotnyi

30 Nov, 2016 05:52 PM

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. Support Staff 1 Posted by Marc Guyer on 30 Nov, 2016 10:01 PM

    Marc Guyer's Avatar

    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. 2 Posted by Jack Zabolotnyi on 01 Dec, 2016 09:34 AM

    Jack Zabolotnyi's Avatar

    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. Support Staff 3 Posted by Marc Guyer on 02 Dec, 2016 03:56 PM

    Marc Guyer's Avatar

    Hi Jack --

    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).

    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.

    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.

    Good catch. I appreciate you more each time we have a discussion :) Requests that modify records are generally atomic when necessary (add-item-quantity comes 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.

  4. Jack Zabolotnyi closed this discussion on 05 Dec, 2016 12:59 PM.

Discussions are closed to public comments.
If you need help with Cheddar please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

28 Mar, 2024 10:45 PM
24 Jan, 2024 08:33 AM
11 Jan, 2024 07:13 AM
30 Nov, 2023 02:07 AM
22 Nov, 2023 08:41 AM