` in your payment form. This embeds an iframe with a dynamic form that displays configured payment method types available from the PaymentIntent, allowing your customer to select a payment method. The form automatically collects the associated payment details for the selected payment method type.
### ❸ Complete the payment on the client
Listen to the form's submit event to know when to confirm the payment through the Stripe API.
Call `confirmPayment` with the Element instance and a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run your server and go to `localhost:4242/checkout.html`.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
java -cp target/sample-jar-with-dependencies.jar com.stripe.sample.Server
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe PaymentMethod and Customer models. Use these models to store information about your Customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe ruby gem and require it in your code. Alternatively, if you're starting from scratch and need a Gemfile, download the project files using the link in the code editor.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem install stripe
```
**Bundler (add to Gemfile):**
```ruby theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem 'stripe'
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the ElementsConsumer instead.
Add PaymentElement to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response.
### ❺ Test the integration
Run the React app and the server. Go to localhost:3000/checkout to see your checkout page.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
ruby server.rb
```
Run the React app and go to localhost:3000/checkout.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package and import it in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the Download link in the code editor.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the ElementsConsumer instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an `Appearance` object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
**Make sure to open the preview on the right to see your changes live.**
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to localhost:3000/checkout to see your checkout page.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the library with composer and initialize with your secret API key. Alternatively, if you're starting from scratch and need a composer.json file, download the files using the link in the code editor.
**Composer:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
composer require stripe/stripe-php
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the ElementsConsumer instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
**Note:** Parts of the preview demo might not match your actual checkout page. The above settings represent only a subset of the Appearance object's variables and the Appearance object only controls certain attributes of Stripe Elements. You're responsible for styling the rest of your checkout page.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to `localhost:3000/checkout` to see your checkout page.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
php -S 127.0.0.1:4242 --docroot=public
```
Run the React app and go to `localhost:3000/checkout`.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
#### Collect billing address details
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe package and import it in your code. Alternatively, if you're starting from scratch and need a requirements.txt file, download the project files using the link in the code editor.
**pip:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
pip3 install stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the ElementsConsumer instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
**Note:** Parts of the preview demo might not match your actual checkout page. The above settings represent only a subset of the Appearance object's variables and the Appearance object only controls certain attributes of Stripe Elements. You're responsible for styling the rest of your checkout page.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to `localhost:3000/checkout` to see your checkout page.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
python3 -m flask run --port=4242
```
Run the React app and go to `localhost:3000/checkout`.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send email receipts
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a go.mod file, download the project files using the link in the code editor.
**Go:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go get -u github.com/stripe/stripe-go/v84
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the ElementsConsumer instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the return\_url.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the return\_url, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.
Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to localhost:3000/checkout to see your checkout page.
**Run the server:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go run server.go
```
Run the React app and go to localhost:3000/checkout.
**Run the client:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe customer and paymentmethod packages. Use these packages to store information about your customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package with .NET or NuGet. Alternatively, if you're starting from scratch, download the files which contains a configured .csproj file.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet add package Stripe.net
```
**NuGet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
Install-Package Stripe.net
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the `ElementsConsumer` instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to localhost:3000/checkout to see your checkout page.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet run
```
Run the React app and go to localhost:3000/checkout.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send email receipts
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a sample pom.xml file (for Maven), download the project files using the link in the code editor.
**Maven:**
```xml theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
com.stripe
stripe-java
{VERSION}
```
**Gradle:**
```gradle theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation "com.stripe:stripe-java:{VERSION}"
```
Add the following dependency to your POM and replace with the version number you want to use.
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the `ElementsConsumer` instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an `Appearance` object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
Make sure to open the preview on the right to see your changes live.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to localhost:3000/checkout to see your checkout page.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
java -cp target/sample-jar-with-dependencies.jar com.stripe.sample.Server
```
Run the React app and go to localhost:3000/checkout.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe PaymentMethod and Customer models. Use these models to store information about your Customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details. Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the packages and import them in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the link in the code editor.
**Install the libraries:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe @stripe/stripe-js next
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service through the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements through a class component, use the ElementsConsumer instead.
Add the PaymentElement to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
Make sure to open the preview on the right to see your changes live.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the Next.js app. Go to localhost:3000 to see your checkout page.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm run dev
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe ruby gem and require it in your code. Alternatively, if you're starting from scratch and need a Gemfile, download the project files using the link in the code editor.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem install stripe
```
**Bundler (add to Gemfile):**
```ruby theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem 'stripe'
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
**Swift Package Manager:**
In Xcode, select File > Add Package Dependencies… and enter `https://github.com/stripe/stripe-ios-spm` as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
To enable Apple Pay, provide your Apple Pay Merchant ID and your Stripe account's country code.
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set `NSCameraUsageDescription` in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
**Note:** Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package and import it in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the Download link in the code editor.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
**Swift Package Manager:**
In Xcode, select File > Add Package Dependencies… and enter `https://github.com/stripe/stripe-ios-spm` as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
To enable Apple Pay, provide your Apple Pay Merchant ID and your Stripe account's country code.
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set `NSCameraUsageDescription` in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
**Note:** Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the library with composer and initialize with your secret API key. Alternatively, if you're starting from scratch and need a composer.json file, download the files using the link in the code editor.
**Composer:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
composer require stripe/stripe-php
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
**Swift Package Manager:**
In Xcode, select File > Add Package Dependencies… and enter `https://github.com/stripe/stripe-ios-spm` as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
To enable Apple Pay, provide your Apple Pay Merchant ID and your Stripe account's country code.
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set `NSCameraUsageDescription` in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
Note: Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe package and import it in your code. Alternatively, if you're starting from scratch and need a requirements.txt file, download the project files using the link in the code editor.
**pip:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
pip3 install stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
**Swift Package Manager:**
In Xcode, select File > Add Package Dependencies… and enter `https://github.com/stripe/stripe-ios-spm` as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
Run your Python server and go to your iOS simulator or device.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
python3 -m flask run --port=4242
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Apple Pay
To enable Apple Pay, provide your Apple Pay Merchant ID and your Stripe account's country code.
#### Custom primary button color
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set `NSCameraUsageDescription` in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
Note: Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a go.mod file, download the project files using the link in the code editor.
**Go:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go get -u github.com/stripe/stripe-go/v84
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
In Xcode, select File > Add Package Dependencies... and enter [https://github.com/stripe/stripe-ios-spm](https://github.com/stripe/stripe-ios-spm) as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Payment customization options
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
Configure Apple Pay by setting the merchant ID and country code in the PaymentSheet configuration.
Set a custom color for the primary button in the PaymentSheet configuration.
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set NSCameraUsageDescription in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
**Note:** Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe customer and paymentmethod packages. Use these packages to store information about your customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
Configure the shipping details in the PaymentSheet configuration to collect addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package with .NET or NuGet. Alternatively, if you're starting from scratch, download the files which contains a configured .csproj file.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet add package Stripe.net
```
**NuGet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
Install-Package Stripe.net
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
In Xcode, select File > Add Package Dependencies... and enter [https://github.com/stripe/stripe-ios-spm](https://github.com/stripe/stripe-ios-spm) as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
Run your ASP.NET MVC server.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet run
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Payment customization options
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
To enable Apple Pay, provide your Apple Pay Merchant ID and your Stripe account's country code.
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set NSCameraUsageDescription in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
**Note:** Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
Collect local and international shipping or billing addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe ruby gem and require it in your code. Alternatively, if you're starting from scratch and need a Gemfile, download the project files using the link in the code editor.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem install stripe
```
**Bundler (add to Gemfile):**
```ruby theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem 'stripe'
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a `PaymentSheet.GooglePayConfiguration` object with the Google Pay environment (production or test) and the country code of your business when initializing `PaymentSheet.Configuration`.
#### Customize the primary button color
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package and import it in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the Download link in the code editor.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a `PaymentSheet.GooglePayConfiguration` object with the Google Pay environment (production or test) and the country code of your business when initializing `PaymentSheet.Configuration`.
#### Customize the primary button
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the library with composer and initialize with your secret API key. Alternatively, if you're starting from scratch and need a composer.json file, download the files using the link in the code editor.
**Composer:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
composer require stripe/stripe-php
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
Set `allowsDelayedPaymentMethods` to true to enable delayed payment methods.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Add the Google Pay API meta-data to your AndroidManifest.xml file.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize the primary button
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Customize the Payment Sheet appearance by configuring colors, fonts, and other visual properties.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect local and international addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe package and import it in your code. Alternatively, if you're starting from scratch and need a requirements.txt file, download the project files using the link in the code editor.
**pip:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
pip3 install stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
Run your Python server and go to your Android simulator or device.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
python3 -m flask run --port=4242
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details. Learn more about the most effective way to apply setup\_future\_usage. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a go.mod file, download the project files using the link in the code editor.
**Go:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go get -u github.com/stripe/stripe-go/v84
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
**To install the SDK, add stripe-android to the dependencies block of your build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry.
**To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe customer and paymentmethod packages. Use these packages to store information about your customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
**If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package with .NET or NuGet. Alternatively, if you're starting from scratch, download the files which contains a configured .csproj file.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet add package Stripe.net
```
**NuGet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
Install-Package Stripe.net
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
**To install the SDK, add stripe-android to the dependencies block of your build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry.
**To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
**If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe ruby gem and require it in your code. Alternatively, if you're starting from scratch and need a Gemfile, download the project files using the link in the code editor.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem install stripe
```
**Bundler (add to Gemfile):**
```ruby theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem 'stripe'
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a `PaymentSheet.GooglePayConfiguration` object with the Google Pay environment (production or test) and the country code of your business when initializing `PaymentSheet.Configuration`.
#### Customize the primary button color
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package and import it in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the Download link in the code editor.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a `PaymentSheet.GooglePayConfiguration` object with the Google Pay environment (production or test) and the country code of your business when initializing `PaymentSheet.Configuration`.
#### Customize the primary button
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the library with composer and initialize with your secret API key. Alternatively, if you're starting from scratch and need a composer.json file, download the files using the link in the code editor.
**Composer:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
composer require stripe/stripe-php
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
Set `allowsDelayedPaymentMethods` to true to enable delayed payment methods.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Add the Google Pay API meta-data to your AndroidManifest.xml file.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize the primary button
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Customize the Payment Sheet appearance by configuring colors, fonts, and other visual properties.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect local and international addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe package and import it in your code. Alternatively, if you're starting from scratch and need a requirements.txt file, download the project files using the link in the code editor.
**pip:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
pip3 install stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
Run your Python server and go to your Android simulator or device.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
python3 -m flask run --port=4242
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details. Learn more about the most effective way to apply setup\_future\_usage. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a go.mod file, download the project files using the link in the code editor.
**Go:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go get -u github.com/stripe/stripe-go/v84
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
**To install the SDK, add stripe-android to the dependencies block of your build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry.
**To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe customer and paymentmethod packages. Use these packages to store information about your customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
**If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package with .NET or NuGet. Alternatively, if you're starting from scratch, download the files which contains a configured .csproj file.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet add package Stripe.net
```
**NuGet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
Install-Package Stripe.net
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
**To install the SDK, add stripe-android to the dependencies block of your build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry.
**To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
**If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a sample pom.xml file (for Maven), download the project files using the link in the code editor.
**Maven:**
```xml theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
com.stripe
stripe-java
{VERSION}
```
**Gradle:**
```gradle theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation "com.stripe:stripe-java:{VERSION}"
```
Add the following dependency to your POM and replace with the version number you want to use.
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
Note: For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a `PaymentSheet.GooglePayConfiguration` object with the Google Pay environment (production or test) and the country code of your business when initializing `PaymentSheet.Configuration`.
#### Customize the primary button
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe PaymentMethod and Customer models. Use these models to store information about your Customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect local and international addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Browse sample projects
Source: https://docs.sampleapp.ai/samples/library
Explore the library of sample projects using Stripe.
# Discord
Source: https://docs.sampleapp.ai/social/discord
# Events
Source: https://docs.sampleapp.ai/social/events
# LinkedIn
Source: https://docs.sampleapp.ai/social/linkedin
# Example: Stripe-like Guided Sandbox (Accept Payments with Stripe Checkout)
Source: https://docs.sampleapp.ai/wide-samples/sandbox
Build a checkout page with Payment Intents API
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe ruby gem and require it in your code. Alternatively, if you're starting from scratch and need a Gemfile, download the project files using the link in the code editor.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem install stripe
```
**Bundler (add to Gemfile):**
```ruby theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem 'stripe'
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use Stripe.js to remain PCI compliant by ensuring that payment details are sent directly to Stripe without hitting your server. Always load Stripe.js from `js.stripe.com` to remain compliant. Don't include the script in a bundle or host it yourself.
Add one empty placeholder `div` to your checkout form for each Element that you'll mount. Stripe inserts an iframe into each `div` to securely collect the customer's email address and payment information.
Initialize Stripe.js with your publishable API key. You'll use Stripe.js to create the Payment Element and complete the payment on the client.
**Note:** This is a public sample test API key. Don't submit any personally identifiable information in requests made with this key.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Initialize the Stripe Elements UI library with the client secret. Elements manages the UI components you need to collect payment details.
Create a `PaymentElement` and mount it to the placeholder `` in your payment form. This embeds an iframe with a dynamic form that displays configured payment method types available from the PaymentIntent, allowing your customer to select a payment method. The form automatically collects the associated payment details for the selected payment method type.
### ❸ Complete the payment on the client
Listen to the form's submit event to know when to confirm the payment through the Stripe API.
Call `confirmPayment` with the Element instance and a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run your Ruby server and go to `localhost:4242/checkout.html`.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
ruby server.rb
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package and import it in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the Download link in the code editor.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use Stripe.js to remain PCI compliant by ensuring that payment details are sent directly to Stripe without hitting your server. Always load Stripe.js from `js.stripe.com` to remain compliant. Don't include the script in a bundle or host it yourself.
Add one empty placeholder `div` to your checkout form for each Element that you'll mount. Stripe inserts an iframe into each `div` to securely collect the customer's email address and payment information.
Initialize Stripe.js with your publishable API key. You'll use Stripe.js to create the Payment Element and complete the payment on the client.
**Note:** This is a public sample test API key. Don't submit any personally identifiable information in requests made with this key.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Initialize the Stripe Elements UI library with the client secret. Elements manages the UI components you need to collect payment details.
Create a `PaymentElement` and mount it to the placeholder `` in your payment form. This embeds an iframe with a dynamic form that displays configured payment method types available from the PaymentIntent, allowing your customer to select a payment method. The form automatically collects the associated payment details for the selected payment method type.
### ❸ Complete the payment on the client
Listen to the form's submit event to know when to confirm the payment through the Stripe API.
Call `confirmPayment` with the Element instance and a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run your Node server and go to `localhost:4242/checkout.html`.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the library with composer and initialize with your secret API key. Alternatively, if you're starting from scratch and need a composer.json file, download the files using the link in the code editor.
**Composer:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
composer require stripe/stripe-php
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use Stripe.js to remain PCI compliant by ensuring that payment details are sent directly to Stripe without hitting your server. Always load Stripe.js from `js.stripe.com` to remain compliant. Don't include the script in a bundle or host it yourself.
Add one empty placeholder `div` to your checkout form for each Element that you'll mount. Stripe inserts an iframe into each `div` to securely collect the customer's email address and payment information.
Initialize Stripe.js with your publishable API key. You'll use Stripe.js to create the Payment Element and complete the payment on the client.
**Note:** This is a public sample test API key. Don't submit any personally identifiable information in requests made with this key.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Initialize the Stripe Elements UI library with the client secret. Elements manages the UI components you need to collect payment details.
Create a `PaymentElement` and mount it to the placeholder `` in your payment form. This embeds an iframe with a dynamic form that displays configured payment method types available from the PaymentIntent, allowing your customer to select a payment method. The form automatically collects the associated payment details for the selected payment method type.
### ❸ Complete the payment on the client
Listen to the form's submit event to know when to confirm the payment through the Stripe API.
Call `confirmPayment` with the Element instance and a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run your PHP server and go to `localhost:4242/checkout.html`.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
php -S 127.0.0.1:4242 --docroot=public
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe package and import it in your code. Alternatively, if you're starting from scratch and need a requirements.txt file, download the project files using the link in the code editor.
**pip:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
pip3 install stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use Stripe.js to remain PCI compliant by ensuring that payment details are sent directly to Stripe without hitting your server. Always load Stripe.js from `js.stripe.com` to remain compliant. Don't include the script in a bundle or host it yourself.
Add one empty placeholder `div` to your checkout form for each Element that you'll mount. Stripe inserts an iframe into each `div` to securely collect the customer's email address and payment information.
Initialize Stripe.js with your publishable API key. You'll use Stripe.js to create the Payment Element and complete the payment on the client.
**Note:** This is a public sample test API key. Don't submit any personally identifiable information in requests made with this key.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Initialize the Stripe Elements UI library with the client secret. Elements manages the UI components you need to collect payment details.
Create a `PaymentElement` and mount it to the placeholder `` in your payment form. This embeds an iframe with a dynamic form that displays configured payment method types available from the PaymentIntent, allowing your customer to select a payment method. The form automatically collects the associated payment details for the selected payment method type.
### ❸ Complete the payment on the client
Listen to the form's submit event to know when to confirm the payment through the Stripe API.
Call `confirmPayment` with the Element instance and a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run your Python server and go to `localhost:4242/checkout.html`.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
python3 -m flask run --port=4242
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a go.mod file, download the project files using the link in the code editor.
**Go:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go get -u github.com/stripe/stripe-go/v84
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use Stripe.js to remain PCI compliant by ensuring that payment details are sent directly to Stripe without hitting your server. Always load Stripe.js from `js.stripe.com` to remain compliant. Don't include the script in a bundle or host it yourself.
Add one empty placeholder `div` to your checkout form for each Element that you'll mount. Stripe inserts an iframe into each `div` to securely collect the customer's email address and payment information.
Initialize Stripe.js with your publishable API key. You'll use Stripe.js to create the Payment Element and complete the payment on the client.
**Note:** This is a public sample test API key. Don't submit any personally identifiable information in requests made with this key.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Initialize the Stripe Elements UI library with the client secret. Elements manages the UI components you need to collect payment details.
Create a `PaymentElement` and mount it to the placeholder `` in your payment form. This embeds an iframe with a dynamic form that displays configured payment method types available from the PaymentIntent, allowing your customer to select a payment method. The form automatically collects the associated payment details for the selected payment method type.
### ❸ Complete the payment on the client
Listen to the form's submit event to know when to confirm the payment through the Stripe API.
Call `confirmPayment` with the Element instance and a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run your Go server and go to `localhost:4242/checkout.html`.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go run server.go
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe customer and paymentmethod packages. Use these packages to store information about your customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package with .NET or NuGet. Alternatively, if you're starting from scratch, download the files which contains a configured .csproj file.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet add package Stripe.net
```
**NuGet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
Install-Package Stripe.net
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use Stripe.js to remain PCI compliant by ensuring that payment details are sent directly to Stripe without hitting your server. Always load Stripe.js from `js.stripe.com` to remain compliant. Don't include the script in a bundle or host it yourself.
Add one empty placeholder `div` to your checkout form for each Element that you'll mount. Stripe inserts an iframe into each `div` to securely collect the customer's email address and payment information.
Initialize Stripe.js with your publishable API key. You'll use Stripe.js to create the Payment Element and complete the payment on the client.
**Note:** This is a public sample test API key. Don't submit any personally identifiable information in requests made with this key.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Initialize the Stripe Elements UI library with the client secret. Elements manages the UI components you need to collect payment details.
Create a `PaymentElement` and mount it to the placeholder `` in your payment form. This embeds an iframe with a dynamic form that displays configured payment method types available from the PaymentIntent, allowing your customer to select a payment method. The form automatically collects the associated payment details for the selected payment method type.
### ❸ Complete the payment on the client
Listen to the form's submit event to know when to confirm the payment through the Stripe API.
Call `confirmPayment` with the Element instance and a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run your ASP.NET MVC server and go to `localhost:4242/checkout.html`.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet run
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a sample pom.xml file (for Maven), download the project files using the link in the code editor.
**Maven:**
```xml theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
com.stripe
stripe-java
{VERSION}
```
**Gradle:**
```gradle theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation "com.stripe:stripe-java:{VERSION}"
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use Stripe.js to remain PCI compliant by ensuring that payment details are sent directly to Stripe without hitting your server. Always load Stripe.js from `js.stripe.com` to remain compliant. Don't include the script in a bundle or host it yourself.
Add one empty placeholder `div` to your checkout form for each Element that you'll mount. Stripe inserts an iframe into each `div` to securely collect the customer's email address and payment information.
Initialize Stripe.js with your publishable API key. You'll use Stripe.js to create the Payment Element and complete the payment on the client.
**Note:** This is a public sample test API key. Don't submit any personally identifiable information in requests made with this key.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Initialize the Stripe Elements UI library with the client secret. Elements manages the UI components you need to collect payment details.
Create a `PaymentElement` and mount it to the placeholder `` in your payment form. This embeds an iframe with a dynamic form that displays configured payment method types available from the PaymentIntent, allowing your customer to select a payment method. The form automatically collects the associated payment details for the selected payment method type.
### ❸ Complete the payment on the client
Listen to the form's submit event to know when to confirm the payment through the Stripe API.
Call `confirmPayment` with the Element instance and a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run your server and go to `localhost:4242/checkout.html`.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
java -cp target/sample-jar-with-dependencies.jar com.stripe.sample.Server
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe PaymentMethod and Customer models. Use these models to store information about your Customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe ruby gem and require it in your code. Alternatively, if you're starting from scratch and need a Gemfile, download the project files using the link in the code editor.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem install stripe
```
**Bundler (add to Gemfile):**
```ruby theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem 'stripe'
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the ElementsConsumer instead.
Add PaymentElement to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response.
### ❺ Test the integration
Run the React app and the server. Go to localhost:3000/checkout to see your checkout page.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
ruby server.rb
```
Run the React app and go to localhost:3000/checkout.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package and import it in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the Download link in the code editor.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the ElementsConsumer instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an `Appearance` object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
**Make sure to open the preview on the right to see your changes live.**
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to localhost:3000/checkout to see your checkout page.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the library with composer and initialize with your secret API key. Alternatively, if you're starting from scratch and need a composer.json file, download the files using the link in the code editor.
**Composer:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
composer require stripe/stripe-php
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the ElementsConsumer instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
**Note:** Parts of the preview demo might not match your actual checkout page. The above settings represent only a subset of the Appearance object's variables and the Appearance object only controls certain attributes of Stripe Elements. You're responsible for styling the rest of your checkout page.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to `localhost:3000/checkout` to see your checkout page.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
php -S 127.0.0.1:4242 --docroot=public
```
Run the React app and go to `localhost:3000/checkout`.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
#### Collect billing address details
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe package and import it in your code. Alternatively, if you're starting from scratch and need a requirements.txt file, download the project files using the link in the code editor.
**pip:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
pip3 install stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the ElementsConsumer instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
**Note:** Parts of the preview demo might not match your actual checkout page. The above settings represent only a subset of the Appearance object's variables and the Appearance object only controls certain attributes of Stripe Elements. You're responsible for styling the rest of your checkout page.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to `localhost:3000/checkout` to see your checkout page.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
python3 -m flask run --port=4242
```
Run the React app and go to `localhost:3000/checkout`.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send email receipts
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a go.mod file, download the project files using the link in the code editor.
**Go:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go get -u github.com/stripe/stripe-go/v84
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the ElementsConsumer instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the return\_url.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the return\_url, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.
Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to localhost:3000/checkout to see your checkout page.
**Run the server:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go run server.go
```
Run the React app and go to localhost:3000/checkout.
**Run the client:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe customer and paymentmethod packages. Use these packages to store information about your customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package with .NET or NuGet. Alternatively, if you're starting from scratch, download the files which contains a configured .csproj file.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet add package Stripe.net
```
**NuGet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
Install-Package Stripe.net
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the `ElementsConsumer` instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to localhost:3000/checkout to see your checkout page.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet run
```
Run the React app and go to localhost:3000/checkout.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send email receipts
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a sample pom.xml file (for Maven), download the project files using the link in the code editor.
**Maven:**
```xml theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
com.stripe
stripe-java
{VERSION}
```
**Gradle:**
```gradle theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation "com.stripe:stripe-java:{VERSION}"
```
Add the following dependency to your POM and replace with the version number you want to use.
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Immediately make a request to the endpoint on your server to create a new PaymentIntent as soon as your checkout page loads. The `clientSecret` returned by your endpoint is used to complete the payment.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service with the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements with a class component, use the `ElementsConsumer` instead.
Add `PaymentElement` to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an `Appearance` object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
Make sure to open the preview on the right to see your changes live.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent_client_secret` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the React app and the server. Go to localhost:3000/checkout to see your checkout page.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
java -cp target/sample-jar-with-dependencies.jar com.stripe.sample.Server
```
Run the React app and go to localhost:3000/checkout.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm start
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe PaymentMethod and Customer models. Use these models to store information about your Customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details. Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the packages and import them in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the link in the code editor.
**Install the libraries:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe @stripe/stripe-js next
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout page on the client
Use the Stripe.js and the Stripe Elements UI library to stay PCI compliant by ensuring that payment details go directly to Stripe and never reach your server.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save @stripe/react-stripe-js @stripe/stripe-js
```
Call `loadStripe()` with your Stripe publishable API key to configure the Stripe library.
Pass the resulting promise from `loadStripe` to the Elements provider. This allows the child components to access the Stripe service through the Elements consumer. Additionally, pass the client secret as an option to the Elements provider.
Initialize some state to keep track of the payment, show errors, and manage the user interface.
Access the Stripe library in your CheckoutForm component by using the `useStripe()` and `useElements()` hooks. If you need to access Elements through a class component, use the ElementsConsumer instead.
Add the PaymentElement to your payment form. It embeds an iframe with a dynamic form that collects payment details for a variety of payment methods. Your customer can pick a payment method type, and the form automatically collects all necessary payments details for their selection.
Customise the Payment Element UI by creating an Appearance object and passing it as an option to the Elements provider. Use your company's colour scheme and font to make it match with the rest of your checkout page. Use custom fonts (for example, from Google Fonts) by initialising Elements with a font set.
Make sure to open the preview on the right to see your changes live.
### ❸ Complete the payment on the client
When your customer clicks the pay button, call `confirmPayment` with the PaymentElement and pass a `return_url` to indicate where Stripe redirects the customer after they complete the payment. For payments that require authentication, Stripe displays a modal for 3D Secure authentication or redirects the customer to an authentication page, depending on the payment method. After the customer completes the authentication process, they're redirected to the `return_url`.
If there are any immediate errors (for example, your customer's card is declined), Stripe.js returns an error. Show that error message to your customer so they can try again.
When Stripe redirects the customer to the `return_url`, the `payment_intent` query parameter is appended by Stripe.js. Use this to retrieve the PaymentIntent status update and determine what to show to your customer.
### ❹ Handle post-payment events
Stripe sends multiple events during the payment process and after the payment is complete. Create an event destination for a webhook endpoint to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow. Stripe recommends handling the `payment_intent.succeeded`, `payment_intent.processing`, and `payment_intent.payment_failed` events.
Listen for these events rather than waiting for a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
### ❺ Test the integration
Run the Next.js app. Go to localhost:3000 to see your checkout page.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm run dev
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Send an email receipt
Stripe can send an email receipt to your customer using your brand logo and colour theme, which are configurable in the Dashboard.
Add an input field to your payment form to collect the email address.
Add a variable to keep track of the email the customer enters.
Pass the provided email address as the `receipt_email` value. Stripe sends an email receipt when the payment succeeds in live mode (but won't send one in a sandbox).
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
### Next steps
By default, the Payment Element only collects the necessary billing address details. To collect a customer's full billing address (to calculate the tax for digital goods and services, for example) or shipping address, use the Address Element.
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe ruby gem and require it in your code. Alternatively, if you're starting from scratch and need a Gemfile, download the project files using the link in the code editor.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem install stripe
```
**Bundler (add to Gemfile):**
```ruby theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem 'stripe'
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
**Swift Package Manager:**
In Xcode, select File > Add Package Dependencies… and enter `https://github.com/stripe/stripe-ios-spm` as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
To enable Apple Pay, provide your Apple Pay Merchant ID and your Stripe account's country code.
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set `NSCameraUsageDescription` in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
**Note:** Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package and import it in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the Download link in the code editor.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
**Swift Package Manager:**
In Xcode, select File > Add Package Dependencies… and enter `https://github.com/stripe/stripe-ios-spm` as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
To enable Apple Pay, provide your Apple Pay Merchant ID and your Stripe account's country code.
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set `NSCameraUsageDescription` in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
**Note:** Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the library with composer and initialize with your secret API key. Alternatively, if you're starting from scratch and need a composer.json file, download the files using the link in the code editor.
**Composer:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
composer require stripe/stripe-php
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
**Swift Package Manager:**
In Xcode, select File > Add Package Dependencies… and enter `https://github.com/stripe/stripe-ios-spm` as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
To enable Apple Pay, provide your Apple Pay Merchant ID and your Stripe account's country code.
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set `NSCameraUsageDescription` in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
Note: Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe package and import it in your code. Alternatively, if you're starting from scratch and need a requirements.txt file, download the project files using the link in the code editor.
**pip:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
pip3 install stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
**Swift Package Manager:**
In Xcode, select File > Add Package Dependencies… and enter `https://github.com/stripe/stripe-ios-spm` as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
Run your Python server and go to your iOS simulator or device.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
python3 -m flask run --port=4242
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Apple Pay
To enable Apple Pay, provide your Apple Pay Merchant ID and your Stripe account's country code.
#### Custom primary button color
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set `NSCameraUsageDescription` in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
Note: Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a go.mod file, download the project files using the link in the code editor.
**Go:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go get -u github.com/stripe/stripe-go/v84
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
In Xcode, select File > Add Package Dependencies... and enter [https://github.com/stripe/stripe-ios-spm](https://github.com/stripe/stripe-ios-spm) as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Payment customization options
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
Configure Apple Pay by setting the merchant ID and country code in the PaymentSheet configuration.
Set a custom color for the primary button in the PaymentSheet configuration.
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set NSCameraUsageDescription in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
**Note:** Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe customer and paymentmethod packages. Use these packages to store information about your customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
Configure the shipping details in the PaymentSheet configuration to collect addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package with .NET or NuGet. Alternatively, if you're starting from scratch, download the files which contains a configured .csproj file.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet add package Stripe.net
```
**NuGet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
Install-Package Stripe.net
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe iOS SDK is open source, fully documented, and compatible with apps supporting iOS 13 or above. Import the Stripe SDK into your checkout screen's View Controller.
In Xcode, select File > Add Package Dependencies... and enter [https://github.com/stripe/stripe-ios-spm](https://github.com/stripe/stripe-ios-spm) as the repository URL. Select the latest version number from our releases page, and add the StripePaymentSheet module to your app's target.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
Run your ASP.NET MVC server.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet run
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Payment customization options
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
To enable Apple Pay, provide your Apple Pay Merchant ID and your Stripe account's country code.
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, set NSCameraUsageDescription in your application's Info.plist, and provide a reason for accessing the camera (for example, "To scan cards").
**Note:** Card scanning is only supported on devices running iOS 13 or higher.
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
Collect local and international shipping or billing addresses from your customers.
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe ruby gem and require it in your code. Alternatively, if you're starting from scratch and need a Gemfile, download the project files using the link in the code editor.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem install stripe
```
**Bundler (add to Gemfile):**
```ruby theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem 'stripe'
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a `PaymentSheet.GooglePayConfiguration` object with the Google Pay environment (production or test) and the country code of your business when initializing `PaymentSheet.Configuration`.
#### Customize the primary button color
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package and import it in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the Download link in the code editor.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a `PaymentSheet.GooglePayConfiguration` object with the Google Pay environment (production or test) and the country code of your business when initializing `PaymentSheet.Configuration`.
#### Customize the primary button
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the library with composer and initialize with your secret API key. Alternatively, if you're starting from scratch and need a composer.json file, download the files using the link in the code editor.
**Composer:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
composer require stripe/stripe-php
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
Set `allowsDelayedPaymentMethods` to true to enable delayed payment methods.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Add the Google Pay API meta-data to your AndroidManifest.xml file.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize the primary button
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Customize the Payment Sheet appearance by configuring colors, fonts, and other visual properties.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect local and international addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe package and import it in your code. Alternatively, if you're starting from scratch and need a requirements.txt file, download the project files using the link in the code editor.
**pip:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
pip3 install stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
Run your Python server and go to your Android simulator or device.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
python3 -m flask run --port=4242
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details. Learn more about the most effective way to apply setup\_future\_usage. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a go.mod file, download the project files using the link in the code editor.
**Go:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go get -u github.com/stripe/stripe-go/v84
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
**To install the SDK, add stripe-android to the dependencies block of your build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry.
**To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe customer and paymentmethod packages. Use these packages to store information about your customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
**If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package with .NET or NuGet. Alternatively, if you're starting from scratch, download the files which contains a configured .csproj file.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet add package Stripe.net
```
**NuGet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
Install-Package Stripe.net
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
**To install the SDK, add stripe-android to the dependencies block of your build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry.
**To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
**If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe ruby gem and require it in your code. Alternatively, if you're starting from scratch and need a Gemfile, download the project files using the link in the code editor.
**Terminal:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem install stripe
```
**Bundler (add to Gemfile):**
```ruby theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
gem 'stripe'
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a `PaymentSheet.GooglePayConfiguration` object with the Google Pay environment (production or test) and the country code of your business when initializing `PaymentSheet.Configuration`.
#### Customize the primary button color
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package and import it in your code. Alternatively, if you're starting from scratch and need a package.json file, download the project files using the Download link in the code editor.
**npm:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
npm install --save stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a `PaymentSheet.GooglePayConfiguration` object with the Google Pay environment (production or test) and the country code of your business when initializing `PaymentSheet.Configuration`.
#### Customize the primary button
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle (Groovy):**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the library with composer and initialize with your secret API key. Alternatively, if you're starting from scratch and need a composer.json file, download the files using the link in the code editor.
**Composer:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
composer require stripe/stripe-php
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
Set `allowsDelayedPaymentMethods` to true to enable delayed payment methods.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Add the Google Pay API meta-data to your AndroidManifest.xml file.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize the primary button
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
Customize the Payment Sheet appearance by configuring colors, fonts, and other visual properties.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect local and international addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the Stripe package and import it in your code. Alternatively, if you're starting from scratch and need a requirements.txt file, download the project files using the link in the code editor.
**pip:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
pip3 install stripe
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
Run your Python server and go to your Android simulator or device.
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
python3 -m flask run --port=4242
```
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details. Learn more about the most effective way to apply setup\_future\_usage. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a go.mod file, download the project files using the link in the code editor.
**Go:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
go get -u github.com/stripe/stripe-go/v84
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
**To install the SDK, add stripe-android to the dependencies block of your build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry.
**To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe customer and paymentmethod packages. Use these packages to store information about your customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
**If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Install the package with .NET or NuGet. Alternatively, if you're starting from scratch, download the files which contains a configured .csproj file.
**dotnet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
dotnet add package Stripe.net
```
**NuGet:**
```bash theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
Install-Package Stripe.net
```
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
**To install the SDK, add stripe-android to the dependencies block of your build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
**Note:** For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the PaymentSheet.Configuration struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a PaymentSheet.GooglePayConfiguration object with the Google Pay environment (production or test) and the country code of your business when initializing PaymentSheet.Configuration.
#### Customize appearance
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry.
**To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect shipping or billing addresses
Collect local and international shipping or billing addresses from your customers.
**If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.
# Build a checkout page with Payment Intents API
Learn how to embed a custom Stripe payment form in your website or application. The client- and server-side code builds a checkout form with Stripe's Web or Mobile elements to let you accept payments. To build a custom integration that goes beyond the basics of this quickstart, see Accept a payment.
To learn about different payment scenarios, such as subscriptions, and other Stripe products, compare payment integrations.
### ❶ Set up the server
Add the dependency to your build and import the library. Alternatively, if you're starting from scratch and need a sample pom.xml file (for Maven), download the project files using the link in the code editor.
**Maven:**
```xml theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
com.stripe
stripe-java
{VERSION}
```
**Gradle:**
```gradle theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation "com.stripe:stripe-java:{VERSION}"
```
Add the following dependency to your POM and replace with the version number you want to use.
Add an endpoint on your server that creates a `PaymentIntent`. A PaymentIntent tracks the customer's payment lifecycle, keeping track of any failed payment attempts and ensuring the customer is only charged once. Return the PaymentIntent's `client_secret` in the response to finish the payment on the client.
Stripe enables cards and other common payment methods by default with dynamic payment methods. You can update and configure payment methods from the Dashboard with no code required. Stripe filters payment methods based on eligibility and payment method preferences, then orders and displays them by probability based on factors including amount, currency, and buyer location.
### ❷ Build a checkout screen on the client
The Stripe Android SDK is open source and fully documented and compatible with devices running Android 5.0 (API level 21) and above.
To install the SDK, add stripe-android to the dependencies block of your build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripe-android:22.6.1'
```
Note: For details on the latest SDK release and past versions, see the Releases page on GitHub.
Configure the Stripe SDK with your Stripe publishable API key. Hardcoding the publishable API key in the SDK is for demonstration only. In a production app, you must retrieve the API key from your server.
Make a request to your server for a PaymentIntent as soon as the view loads. Store a reference to the PaymentIntent's client secret returned by the server; the Payment Sheet uses this secret to complete the payment later.
### ❸ Complete the payment on the client
Create a PaymentSheet instance using the client secret retrieved earlier, and present it from your view controller.
Use the `PaymentSheet.Configuration` struct for customising the Payment Sheet.
Use the completion block for handling the payment result.
If payment fails with an error, display the appropriate message to your customer so they can take action and try again. If no error has occurred, tell your customer that the payment was successful.
### ❹ Test the integration
To verify that your integration works, make a test payment using test payment details.
**Payment succeeds**
`4242 4242 4242 4242`
**Payment requires authentication**
`4000 0025 0000 3155`
**Payment is declined**
`4000 0000 0000 9995`
Navigate to the Stripe Dashboard to see your test payment.
### Accept payments and enhance your integration
You're ready to accept payments with Stripe. Continue with the steps below to add more features.
#### Calculate and collect the right amount of tax
Calculate and collect the right amount of tax on your Stripe transactions. Learn more about Stripe Tax and how to add it to your Payments integration.
Use the Stripe Tax API to calculate tax on the transaction. Provide the `currency`, `customer_details`, and the `line_items` of the order in the request body.
Use the `tax_amount_exclusive` attribute of the resulting Tax Calculation to add the exclusive taxes to the order's total.
Link the tax calculation to the PaymentIntent using `hooks[inputs][tax][calculation]`.
This records the collected taxes in your Stripe account that you can later export for accounting purposes, and triggers other Stripe actions.
#### Enable delayed payment methods
Some payment methods can't guarantee that you'll receive funds from your customer at the end of the checkout because they take time to settle (for example, most bank debits, such as SEPA or ACH) or require customer action to complete (for example, OXXO, Konbini, Boleto). Use this flag to enable delayed payment methods.
If you enable this feature, make sure your server integration listens to webhooks for notifications on whether payment has succeeded or not.
#### Enable Google Pay
To use Google Pay, first enable the Google Pay API in your AndroidManifest.xml.
Enable Google Pay by passing a `PaymentSheet.GooglePayConfiguration` object with the Google Pay environment (production or test) and the country code of your business when initializing `PaymentSheet.Configuration`.
#### Customize the primary button
Consider using a custom color for the primary button that better matches your brand or app's visual identity.
#### Enable card scanning
Card scanning can help increase your conversion rate by removing the friction of manual card entry. To enable card scanning, add stripecardscan to the dependencies block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.stripe:stripecardscan:22.6.1'
```
#### Save payment details after payment
Often used by SaaS or e-commerce businesses with recurring customers.
Import the Stripe PaymentMethod and Customer models. Use these models to store information about your Customer.
Stripe stores the card on an Account object representing the customer. Create a new Account before creating a PaymentIntent. You can also store name, email, shipping address, and other details on the Account.
Pass the Account ID to the PaymentIntent and set `setup_future_usage` to `off_session`. `setup_future_usage` tells Stripe how you plan to use the payment method – certain regions, such as Europe and India, have requirements around reusing payment details.
Learn more about the most effective way to apply `setup_future_usage`. You can also view a list of supported payment methods. After the PaymentIntent succeeds, Stripe automatically attaches the payment details (in a PaymentMethod object) to the customer-configured Account.
When you're ready to charge the PaymentMethod again, create a new PaymentIntent with the Customer ID, the ID of the PaymentMethod you want to charge, and set the `off_session` and `confirm` flags to true.
#### Collect local and international addresses
Collect local and international shipping or billing addresses from your customers.
If you use the Address Element, you can optionally use the Google Places SDK to fetch address autocomplete suggestions. To enable autocomplete suggestions, add places to the dependency block of your app/build.gradle file:
**build.gradle:**
```groovy theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
implementation 'com.google.android.libraries.places:places:2.6.0'
```
### Next steps
Learn how to move funds out of your Stripe account into your bank account.
Handle requests for refunds by using the Stripe API or Dashboard.
Create an event destination to send events to your webhook endpoint to fulfil orders after a payment succeeds, and to handle other critical events.