Accept a payment
Securely accept payments online.
Build a payment form or use a prebuilt checkout page to start accepting online payments.
Redirect to a Stripe-hosted payment page using Stripe Checkout. See how this integration compares to Stripe’s other integration types.
Integration effort
Integration type
Redirect to Stripe-hosted payment page
UI customization
First, register for a Stripe account.
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.
You can also create a Checkout Session for an existing customer, allowing you to prefill Checkout fields with known contact information and unify your purchase history for that customer.
<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 must populate success_
with the URL value of a page on your website that Checkout returns your customer to after they complete the payment. You can optionally also provide a cancel_
value of a page on your website that Checkout returns your customer to if they terminate the payment process before completion.
Note
Checkout Sessions expire 24 hours after creation by default.
After creating a Checkout Session, redirect your customer to the URL returned in the response.
Payment methods
By default, Stripe enables cards and other common payment methods. You can turn individual payment methods on or off in the Stripe Dashboard. In Checkout, Stripe evaluates the currency and any restrictions, then dynamically presents the supported payment methods to the customer.
To see how your payment methods appear to customers, enter a transaction ID or set an order amount and currency in the Dashboard.
You can enable Apple Pay and Google Pay in your payment methods settings. By default, Apple Pay is enabled and Google Pay is disabled. However, in some cases Stripe filters them out even when they’re enabled. We filter Google Pay if you enable automatic tax without collecting a shipping address.
Checkout’s Stripe-hosted pages don’t need integration changes to enable Apple Pay or Google Pay. Stripe handles these payments the same way as other card payments.
Confirm your endpoint
Confirm your endpoint is accessible 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.
inside your button click listener to confirm the correct data returned.log(session)
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:
Note
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.
Handle post-payment events
Stripe sends a checkout.session.completed event when a customer completes a Checkout Session payment. Use the Dashboard webhook tool or follow the webhook guide to receive and handle these events, which might trigger you to:
- Send an order confirmation email to your customer.
- Log the sale in a database.
- Start a shipping workflow.
Listen for these events rather than waiting for your customer to be redirected back to your website. Triggering fulfillment only from your Checkout landing page is unreliable. Setting up your integration to listen for asynchronous events allows you to accept different types of payment methods with a single integration.
Learn more in our fulfillment guide for Checkout.
Handle the following events when collecting payments with the Checkout:
Event | Description | Action |
---|---|---|
checkout.session.completed | Sent when a customer successfully completes a Checkout Session. | Send the customer an order confirmation and fulfill their order. |
checkout.session.async_payment_succeeded | Sent when a payment made with a delayed payment method, such as ACH direct debt, succeeds. | Send the customer an order confirmation and fulfill their order. |
checkout.session.async_payment_failed | Sent when a payment made with a delayed payment method, such as ACH direct debt, fails. | Notify the customer of the failure and bring them back on-session to attempt payment again. |
Test your integration
To test your Stripe-hosted payment form integration:
- Create a Checkout Session.
- Fill out the payment details with a method from the following table.
- Enter any future date for card expiry.
- Enter any 3-digit number for CVC.
- Enter any billing postal code.
- Click Pay. You’re redirected to your
success_
.url - Go to the Dashboard and look for the payment on the Transactions page. If your payment succeeded, you’ll see it in that list.
- Click your payment to see more details, like a Checkout summary with billing information and the list of purchased items. You can use this information to fulfill the order.
Learn more about testing your integration.
See Testing for additional information to test your integration.
Test cards
Number | Description |
---|---|
Succeeds and immediately processes the payment. | |
Requires 3D Secure 2 authentication for a successful payment. | |
Always fails with a decline code of insufficient_ . |
OptionalCreate products and prices
Before you create a Checkout Session, you can create Products and Prices upfront. Use products to represent different physical goods or levels of service, and Prices to represent each product’s pricing.
For example, you can create a T-shirt as a product with a price of 20 USD. This allows you to update and add prices without needing to change the details of your underlying products. You can either create products and prices with the Stripe Dashboard or API. Learn more about how products and prices work.
Each price you create has an ID. When you create a Checkout Session, reference the price ID and quantity. If you’re selling in multiple currencies, make your Price multi-currency. Checkout automatically determines the customer’s local currency and presents that currency if the Price supports it.
OptionalPrefill customer dataServer-side
If you’ve already collected your customer’s email and want to prefill it in the Checkout Session for them, pass customer_email when creating a Checkout Session.
OptionalSave payment method detailsServer-side
By default, payment methods used to make a one-time payment with Checkout aren’t available for future use.
Save payment methods to charge them off-session
You can set Checkout to save payment methods used to make a one-time payment by passing the payment_intent_data.setup_future_usage argument. This is useful if you need to capture a payment method on-file to use for future fees, such as cancellation or no-show fees.
If you use Checkout in subscription
mode, Stripe automatically saves the payment method to charge it for subsequent payments. Card payment methods saved to customers using either setup_
or subscription
mode don’t appear for return purchases in Checkout (more on this below). We recommend using custom text to link out to any relevant terms regarding the usage of saved payment information.
Caution
Global privacy laws are complicated and nuanced. We recommend contacting your legal and privacy team prior to implementing setup_future_usage because it might implicate your existing privacy compliance framework. Refer to the guidance issued by the European Protection Board to learn more about saving payment details.
Save payment methods to prefill them in Checkout
By default, Checkout uses Link to provide your customers with the option to securely save and reuse their payment information. If you prefer to manage payment methods yourself, use saved_payment_method_options.payment_method_save when creating a Checkout Session to let your customers save their payment methods for future purchases in Checkout.
Passing this parameter in either payment or subscription mode displays an optional checkbox to let customers explicitly save their payment method for future purchases. When customers check this checkbox, Checkout saves the payment method with allow_redisplay: always. Checkout uses this parameter to determine whether a payment method can be prefilled on future purchases. When using saved_
, you don’t need to pass in setup_
to save the payment method.
Using saved_payment_method_options.payment_method_save requires a Customer
. To save a new customer, set the Checkout Session’s customer_creation to always
. Otherwise, the session doesn’t save the customer or the payment method.
If payment_
isn’t passed in or if the customer doesn’t agree to save the payment method, Checkout still saves payment methods created in subscription
mode or using setup_
. These payment methods have an allow_
value of limited
, which prevents them from being prefilled for returning purchases and allows you to comply with card network rules and data protection regulations. Learn how to change the default behavior enabled by these modes and how to change or override allow_
behavior.
Note
You can use Checkout to save cards and other payment methods to charge them off-session, but Checkout only prefills saved cards. Learn how to prefill saved cards. To save a payment method without an initial payment, use Checkout in setup mode.
Let customers remove saved payment methods
To let your customers remove a saved payment method so it doesn’t resurface for future payments, use saved_payment_method_options.payment_method_remove when creating a Checkout Session.
The customer can’t remove a payment method if it’s tied to an active subscription and the customer doesn’t have a default payment method saved for invoice and subscription payments.
OptionalSeparate authorization and captureServer-side
Stripe supports two-step card payments so you can first authorize a card, then capture funds later. When Stripe authorizes a payment, the card issuer guarantees the funds and places a hold for the payment amount on the customer’s card. You then have a certain amount of time to capture the funds, depending on the card). If you don’t capture the payment before the authorization expires, the payment is cancelled and the issuer releases the held funds.
Separating authorization and capture is useful if you need to take additional actions between confirming that a customer is able to pay and collecting their payment. For example, if you’re selling stock-limited items, you may need to confirm that an item purchased by your customer using Checkout is still available before capturing their payment and fulfilling the purchase. Accomplish this using the following workflow:
- Confirm that Stripe authorized the customer’s payment method.
- Consult your inventory management system to confirm that the item is still available.
- Update your inventory management system to indicate that a customer has purchased the item.
- Capture the customer’s payment.
- Inform your customer whether their purchase was successful on your confirmation page.
To indicate that you want to separate authorization and capture, you must set the value of payment_intent_data.capture_method to manual
when creating the Checkout Session. This instructs Stripe to only authorize the amount on the customer’s card.
To capture an uncaptured payment, you can use either the Dashboard or the capture endpoint. Programmatically capturing payments requires access to the PaymentIntent created during the Checkout Session, which you can get from the Session object.
OptionalCustomer account managementNo code
Let your customers manage their own accounts by sharing a link to your customer portal. The customer portal lets customers log in with their email to manage subscriptions, update payment methods, and so on.