Once you've securely collected and tokenized your customer's credit card using Checkout or Stripe.js, you can charge the card. Unlike collection, which occurs in the browser, charge attempts are made from your server, normally using one of our client libraries. If you haven't already, install the library for your favorite language now. This tutorial shows code for Ruby, PHP, Python, and Node, but we also have libraries for Java and Go.
On your server, grab the Stripe token in the POST parameters submitted by your form. From there, it's one simple API call to charge the card:
As a convenience, if you're logged in while reading this page, we've pre-filled the example with your test secret API key. Only you can see this value. This will authenticate you to Stripe, so keep it secret and keep it safe. Remember to replace the test key with your live key in production. You can get all your keys from your account page.
That's it! If the charge creation request succeeds, the card has been successfully charged. You will automatically receive your money in two days. If the charge attempt fails, we'll return an error instead.
Saving credit card details for later
Stripe tokens can only be used once, but that doesn't mean you have to request your customer's card details for every payment. Stripe provides a
Customer object type that makes it easy to save
this—and other—information for later use.
Instead of charging the card immediately, create a new
Customer, saving the token on the
Customer in the process. This will let you charge the customer at any point in
After creating a customer in Stripe with a stored payment method, you can charge that customer at any point in time by passing the customer ID—instead of a card representation—in the charge request. Be certain to store the customer ID on your side for later use.
Storing information in metadata
Stripe supports adding metadata to the most common requests you'll make, such as processing charges. Metadata is for your use only: it won't be shown to customers or factored into whether or not a charge is declined.
Through metadata, you can associate other information—meaningful to you—with Stripe activity. Any metadata you include will be viewable in the Dashboard (e.g., when looking at the page for an individual charge), and will also be available in common reports and exports. As an example, your store's order ID can be attached to the charge used to pay for that order. Doing so allows you, your accountant, or your finance team to easily reconcile charges in Stripe to orders in your system.
Congrats! You've processed your first charge using Stripe. Some things you might want to see next: