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

ruby, ruby-on-rails, stripe-payments

Solution

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 test@example.com"
)

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

Problem

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!

Original source