You've got the token for your user's credit card details, now what? Now you charge them money. This happens
on your server, and the fastest way to do it is by using one of our client libraries. If you haven't already,
install your favorite language now. In this tutorial, we'll show code for
In your web server, grab the Stripe token in the POST parameters submitted by your form. Once you do, it's one simple call to charge the card with Stripe:
Also note that we've placed your test secret API key in the code. This will authenticate you to Stripe, and it's separate from your publishable key — 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, and doesn't throw an error, the card has been successfully charged. You will receive your money in two days.
Saving credit card details for later
Stripe tokens can only be used once, but that doesn't mean you can't save payment information
for your users. Stripe provides a
Customer abstraction that makes it easy to save
this information for later.
Instead of charging the card immediately, you can create a new
object and save the card to that customer. This will let you charge the user at any point in
In this example, right after we created the customer we still created a new charge by passing in the customer, rather than the card. You can always provide either a card or a customer when creating a new charge.
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 gone through the basics of using Stripe. Some things you might want to see next: