Accept a payment
Customize logo, images, and colors.
Built-in support for Apple Pay, and Google Pay.
View the demo to see a hosted example.
Set up StripeServer-side
First, register for a Stripe account and then use the Dashboard to create an account name. You can always edit your account name later.
Use our official libraries to access the Stripe API from your application:
Redirect your customer to Stripe CheckoutClient-sideServer-side
Add a checkout button to your website that calls a server-side endpoint to create a Checkout Session.
<html> <head> <title>Buy cool new product</title> </head> <body> <!-- Use action="/create-checkout-session.php" if your server is PHP based. --> <form action="/create-checkout-session" method="POST"> <button type="submit">Checkout</button> </form> </body> </html>
A Checkout Session is the programmatic representation of what your customer sees when they’re redirected to the payment form. You can configure it with options such as:
- Line items to charge
- Currencies to use
You also need to specify success_url
, a page on your website that Checkout returns your customer to after they complete the payment. You can optionally provide cancel_url
, a page on your website that Checkout returns your customer to if they cancel the payment process.
Checkout Sessions expire 24 hours after creation.
After creating a Checkout Session, redirect your customer to the URL returned in the response.
By default, Stripe enables cards and other prevalent payment methods that can help you reach more customers, and you can turn on or turn off payment methods right from the Stripe Dashboard. Stripe evaluates the currency, payment method restrictions, and other parameters to determine the list of supported payment methods to show in Checkout.
Test your endpoint by starting your web server (for example, localhost:4242
) and running the following command:
curl -X POST -is "http://localhost:4242/create-checkout-session" -d ""
You should see a response in your terminal that looks like this:
HTTP/1.1 303 See Other Location: https://checkout.stripe.com/c/pay/cs_test_... ...
Testing
You should now have a working checkout button that redirects your customer to Stripe Checkout.
- Click the checkout button.
- You’re redirected to the Stripe Checkout payment form.
If your integration isn’t working:
- Open the Network tab in your browser’s developer tools.
- Click the checkout button and confirm it sent an XHR request to your server-side endpoint (
POST /create-checkout-session
). - Verify the request is returning a 200 status.
- Use
console.log(session)
inside your button click listener to confirm the correct data returned.
Show a success pageClient-sideServer-side
It’s important for your customer to see a success page after they successfully submit the payment form. Host this success page on your site.
Create a minimal success page:
<html> <head><title>Thanks for your order!</title></head> <body> <h1>Thanks for your order!</h1> <p> We appreciate your business! If you have any questions, please email <a href="mailto:orders@example.com">orders@example.com</a>. </p> </body> </html>
Next, update the Checkout Session creation endpoint to use this new page:
If you want to customize your success page, read the custom success page guide.
Testing
- Click your checkout button.
- Fill out the payment details with the test card information:
- Enter
4242 4242 4242 4242
as the card number. - Enter any future date for card expiry.
- Enter any 3-digit number for CVC.
- Enter any billing postal code.
- Enter
- Click Pay.
- You’re redirected to your new success page.
Next, find the new payment in the Stripe Dashboard. Successful payments appear in the Dashboard’s list of payments. When you click a payment, it takes you to the payment details page. The Checkout summary section contains billing information and the list of items purchased, which you can use to manually fulfill the order.
Additional testing resources
There are several test cards you can use to make sure your integration is ready for production. Use them with any CVC, postal code, and future expiration date.
Number | Description |
---|---|
Succeeds and immediately processes the payment. | |
Complete 3D Secure 2 authentication for a successful payment. | |
Always fails with a decline code of insufficient_funds . |
For the full list of test cards see our guide on testing.
Apple Pay and Google Pay
Stripe Checkout doesn’t need configuration or integration changes to enable Apple Pay or Google Pay. Stripe handles these payments the same way as other card payments.
Now that you have your basic integration working, learn how to programmatically get a notification whenever a customer pays.