Accept a card payment
We recommend that you follow the Accept a payment guide instead. Only use this guide if you need to use manual server-side confirmation or your integration requires presenting payment methods separately. If you’ve already integrated with Elements, see the Payment Element migration guide.
Set up StripeServer-side
Use our official libraries for access to the Stripe API from your application:
Create a PaymentIntentServer-side
Stripe uses a PaymentIntent object to represent your intent to collect payment from a customer, tracking charge attempts and payment state changes throughout the process.
Create a PaymentIntent on your server with an amount and currency. Always decide how much to charge on the server side, a trusted environment, as opposed to the client. This prevents malicious customers from being able to choose their own prices.
The returned PaymentIntent includes a client secret. The client side uses the client secret to securely complete the payment process instead of passing the entire PaymentIntent object. There are different approaches that you can use to pass the client secret to the client side.
Collect card detailsClient-side
You’re ready to collect card information on the client with Stripe Elements. Elements is a set of prebuilt UI components for collecting and validating card number, ZIP code, and expiration date.
A Stripe Element contains an iframe that securely sends the payment information to Stripe over an HTTPS connection. The checkout page address must also start with https://
rather than http://
for your integration to work.
You can test your integration without using HTTPS. Enable it when you’re ready to accept live payments.
Set up Stripe Elements
Submit the payment to StripeClient-side
Rather than sending the entire PaymentIntent object to the client, use its client secret from step 2. After you create the PaymentIntent, the API returns a unique client secret for it (the client secret is different from the secret key you use to make Stripe API requests).
The client secret can complete a charge, so handle it with discretion. Don’t log it, embed it in URLs, or expose it to anyone but the customer.
Test the integration
There are several test cards you can use in test mode to make sure this integration is ready. Use them with any CVC, postal code, and future expiration date.
Number | Description |
---|---|
Succeeds and immediately processes the payment. | |
Always fails with a decline code of insufficient_funds . | |
Requires authentication, which in this integration will fail with a decline code of authentication_not_handled . |
For the full list of test cards see our guide on testing.
See also
Congratulations, you’re done with your integration! Next, you can learn more about the Payment Intents API and Elements.