Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I have a Stripe token from a charge, how do I get its charge id?

Right now I'm making successful charges with my Rails app but I'd like to to fetch certain details about the transaction such as the description of the item purchase and the last four digits of the credit card to show the user on their receipt page.

I've been looking at the documentation but there's really nothing that explains how to give an app the token and get back the charge_id which I can then use to get a hash of other info about the charge.

Any help would be huge. Thanks!

like image 408
Zack Shapiro Avatar asked Aug 20 '12 00:08

Zack Shapiro


1 Answers

Stripe returns charge IDs in the response to a charge creation call. If you're using the Ruby library, you can do something like this to get the ID:

require "stripe"
Stripe.api_key = '<your api key>'
charge = Stripe::Charge.create(
  :amount => 400,
  :currency => "usd",
  :card => "tok_JkdcRcQfyFsoZ2", # obtained with Stripe.js
  :description => "Charge for [email protected]"
)

You can then store charge.id and use the Charge Retrieve call to look up charge details.

like image 200
anurag Avatar answered Oct 13 '22 06:10

anurag