Determining when a charge succeeded.

191 views
Skip to first unread message

Steven

unread,
May 23, 2017, 9:06:40 AM5/23/17
to Stripe API Discussion
I get what 'pending' is for, and that it really only applies to ACH charges. But I was also curious if I understand `status: "failed"` correctly for CC charges.

For context, I'm trying to determine what attributes of the returned Charge object I should look at to determine if the charge were successful, or failed. As I understand it, the API will always return a `4XX` error in the event the charge failed. Wether it's due to an expired card, insufficient funds, fraud detection, etc... the API will return an HTTP 4XX, and a body that includes information about the error, and a `charge_id`. If we then fetch that Charge, we'd see its `status: "failed"`, yes?

If the above is true, does that means I can rely on seeing those HTTP status values to determine failure? In practice, this means `rescue Stripe::StripeError` when using the `stripe` Ruby gem. Otherwise, we'll get an HTTP 200, and no resulting exception will be raised. Is the LACK of an exception enough to know that the Charge was successful? Should I also be looking at the Charge's `status` attribute? Or some other attributes? Are there other ways for a previously "successful" charge to become "failed?"

Thank you.

Remi J.

unread,
May 23, 2017, 9:12:34 AM5/23/17
to api-d...@lists.stripe.com
Hey Steven,

When you call the Create Charge API [1] with a card as a source, you either get an error back [2] which indicates the payment failed or a Charge object [3] back which indicates that the payment succeeded. You shouldn't have to look at the HTTP status here and simply let your code catch any exception that the API would raise.

As long as you don't just create an authorization with `capture: false`, getting a Charge object indicates that the funds are yours and will be paid out to your bank account once the funds are available. If you do create an authorization, you'd need to capture the charge [4] before the 7 days limit or the funds would be automatically released to the customer.

Hope this helps!
Remi


--
You received this message because you are subscribed to the Google Groups "Stripe API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss+unsubscribe@lists.stripe.com.
To post to this group, send email to api-d...@lists.stripe.com.
Visit this group at https://groups.google.com/a/lists.stripe.com/group/api-discuss/.

Reply all
Reply to author
Forward
0 new messages