# Accept a payment Securely accept payments online. ## Start here: Install agent skills Stripe recommends using official skills to integrate with the API using best practices. Follow the instructions below to learn how. **Tip: Use curl instead of Fetch tools.** Skills are detailed 10–20 KB markdown files. Fetch tools summarize them. `curl -sL` guarantees the full content. **Using `npx skills`**: Check if `npx` is installed on the system. If `npx` is available, run `npx skills add https://docs.stripe.com --list` to list available skills, then run `npx skills add https://docs.stripe.com --yes --skill <--skill other-skills>` to install individual skills. **If `npx skills` isn’t available**: You can use curl to fetch the index of available skills, what they do, and their files from `https://docs.stripe.com/.well-known/skills/index.json`. To download a skill and its related files, use curl to download them from `https://docs.stripe.com/.well-known/skills/`. For this article, we recommend using these skills: `stripe-best-practices` Instructions for LLMs: Stripe recommends using the Checkout Sessions API with the Payment Element over Payment Intents for most integrations. Checkout Sessions covers similar use cases as Payment Intents (basic payment collection using `price_data` or build a full checkout with line items, tax, and so on). Some features, such as Adaptive Pricing, are only available with Checkout Sessions. Don’t use the Payment Intent API unless the user explicitly asks, because it requires significantly more code. Learn more about Elements with the Checkout Sessions API: https://docs.stripe.com/payments/quickstart-checkout-sessions. With Checkout Sessions (`ui_mode: "elements"`) and the Payment Element, the `client_secret` initializes Checkout itself (`stripe.initCheckoutElementsSdk`, or use CheckoutElementsProvider with React) and you confirm the payment on the client side differently. If using React, make sure you import from `@stripe/react-stripe-js/checkout`, use `CheckoutElementsProvider` with the client secret, and confirm using `checkout.confirm`. If using HTML, make sure you use `checkout = stripe.initCheckoutElementsSdk({clientSecret: promise}); checkout.createPaymentElement(); paymentElement = checkout.createPaymentElement(); paymentElement.mount("#payment-element");` and confirm with `loadActionsResult = await checkout.loadActions(); actions = loadActionsResult.actions; error = await actions.confirm();`. Build a payment form or use a prebuilt checkout page to start accepting online payments. # In-app integration for React Native ![](https://b.stripecdn.com/docs-statics-srv/assets/ios-overview.9e0d68d009dc005f73a6f5df69e00458.png) This integration combines all of the steps required to pay, including collecting payment details and confirming the payment, into a single sheet that displays on top of your app. > #### Accounts v2 API support > > The Payment Sheet doesn’t support *customer-configured Accounts* (Account configurations represent role-based functionality that you can enable for accounts, such as merchant, customer, or recipient). It only supports `Customer` objects. ## Set up Stripe [Server-side] [Client-side] First, you need a Stripe account. [Register now](https://dashboard.stripe.com/register). ### Server-side This integration requires endpoints on your server that talk to the Stripe API. Use the official libraries for access to the Stripe API from your server: #### .NET ```bash # Install with dotnet dotnet add package Stripe.net dotnet restore ``` ```bash # Or install with NuGet Install-Package Stripe.net ``` ### Client-side The [React Native SDK](https://github.com/stripe/stripe-react-native) is open source and fully documented. Internally, it uses the [native iOS](https://github.com/stripe/stripe-ios) and [Android](https://github.com/stripe/stripe-android) SDKs. To install Stripe’s React Native SDK, run one of the following commands in your project’s directory (depending on which package manager you use): #### yarn ```bash yarn add @stripe/stripe-react-native ``` #### npm ```bash npm install @stripe/stripe-react-native ``` Next, install some other necessary dependencies: - For iOS, go to the **ios** directory and run `pod install` to ensure that you also install the required native dependencies. - For Android, there are no more dependencies to install. > We recommend following the [official TypeScript guide](https://reactnative.dev/docs/typescript#adding-typescript-to-an-existing-project) to add TypeScript support. ### Stripe initialization To initialize Stripe in your React Native app, either wrap your payment screen with the `StripeProvider` component, or use the `initStripe` initialization method. Only the API [publishable key](https://docs.stripe.com/keys.md#obtain-api-keys) in `publishableKey` is required. The following example shows how to initialize Stripe using the `StripeProvider` component. ```jsx import { useState, useEffect } from 'react'; import { StripeProvider } from '@stripe/stripe-react-native'; function App() { const [publishableKey, setPublishableKey] = useState(''); const fetchPublishableKey = async () => { const key = await fetchKey(); // fetch key from your server here setPublishableKey(key); }; useEffect(() => { fetchPublishableKey(); }, []); return ( {/* Your app code here */} ); } ``` > Use your API [test keys](https://docs.stripe.com/keys.md#obtain-api-keys) while you test and develop, and your [live mode](https://docs.stripe.com/keys.md#test-live-modes) keys when you publish your app. ## Enable payment methods View your [payment methods settings](https://dashboard.stripe.com/settings/payment_methods) and enable the payment methods you want to support. You need at least one payment method enabled to create a *PaymentIntent* (The Payment Intents API tracks the lifecycle of a customer checkout flow and triggers additional authentication steps when required by regulatory mandates, custom Radar fraud rules, or redirect-based payment methods). By default, Stripe enables cards and other prevalent payment methods that can help you reach more customers, but we recommend turning on additional payment methods that are relevant for your business and customers. See [Payment method support](https://docs.stripe.com/payments/payment-methods/payment-method-support.md) for product and payment method support, and our [pricing page](https://stripe.com/pricing/local-payment-methods) for fees. ## Add an endpoint [Server-side] > #### Note > > To display the PaymentSheet before you create a PaymentIntent, see [Collect payment details before creating an Intent](https://docs.stripe.com/payments/accept-a-payment-deferred.md?type=payment). This integration uses three Stripe API objects: 1. [PaymentIntent](https://docs.stripe.com/api/payment_intents.md): Stripe uses this to represent your intent to collect payment from a customer, tracking your charge attempts and payment state changes throughout the process. 1. (Optional) A [customer-configured Account](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-applied_configurations) or a [Customer](https://docs.stripe.com/api/customers.md) object: To set up a payment method for future payments, you must attach it to a customer. Create an object to represent your customer when they create an account with your business. If your customer makes a payment as a guest, you can create an `Account` or `Customer` object before payment and associate it with your own internal representation of the customer’s account later. 1. (Optional) [CustomerSession](https://docs.stripe.com/api/customer_sessions.md): Information on the object that represents your customer is sensitive, and can’t be retrieved directly from an app. A `CustomerSession` grants the SDK temporary scoped access to the `Account` or `Customer` and provides additional configuration options. See a complete list of [configuration options](https://docs.stripe.com/api/customer_sessions/create.md#create_customer_session-components). > If you never save cards for customers and don’t allow returning customers to reuse saved cards, you can omit the `Account` or `Customer` object and the `CustomerSession` object from your integration. For security reasons, your app can’t create these objects. Instead, add an endpoint on your server that: 1. Retrieves the `Account` or `Customer`, or creates a new one. 1. Creates a [CustomerSession](https://docs.stripe.com/api/customer_sessions.md) for the `Account` or `Customer`. 1. Creates a `PaymentIntent` with the [amount](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-amount), [currency](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-currency), and either the [customer_account](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-customer_account) or the [customer](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-customer). 1. Returns the `PaymentIntent`’s *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)), the `CustomerSession`’s `client_secret`, the ID of the `Account` or `Customer`, and your [publishable key](https://dashboard.stripe.com/apikeys) to your app. The payment methods shown to customers during the checkout process are also included on the PaymentIntent. You can let Stripe pull payment methods from your Dashboard settings or you can list them manually. Regardless of the option you choose, know that the currency passed in the PaymentIntent filters the payment methods shown to the customer. For example, if you pass `eur` on the PaymentIntent and have OXXO enabled in the Dashboard, OXXO won’t be shown to the customer because OXXO doesn’t support `eur` payments. Unless your integration requires a code-based option for offering payment methods, Stripe recommends the automated option. This is because Stripe evaluates the currency, payment method restrictions, and other parameters to determine the list of supported payment methods. Payment methods that increase conversion and that are most relevant to the currency and customer’s location are prioritized. #### Manage payment methods from the Dashboard You can manage payment methods from the [Dashboard](https://dashboard.stripe.com/settings/payment_methods). Stripe handles the return of eligible payment methods based on factors such as the transaction’s amount, currency, and payment flow. The PaymentIntent is created using the payment methods you configured in the Dashboard. If you don’t want to use the Dashboard or if you want to specify payment methods manually, you can list them using the `payment_method_types` attribute. #### .NET ```dotnet [HttpPost("payment-sheet")] public ActionResult CreatePaymentSheet([FromBody] CreatePaymentSheetRequest req) { // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. var client = new StripeClient("<>"); // Use an existing Customer ID if this is a returning customer. var customerOptions = new CustomerCreateOptions(); var requestOptions = new RequestOptions { StripeAccount = "{{CONNECTED_ACCOUNT_ID}}" }; var customer = client.V1.Customers.Create(customerOptions, requestOptions); var customerSessionOptions = new CustomerSessionCreateOptions { Customer = customer.Id, Components = new CustomerSessionComponentsOptions() } customerSessionOptions.AddExtraParam("components[mobile_payment_element][enabled]", true); customerSessionOptions.AddExtraParam( "components[mobile_payment_element][features][payment_method_save]", "enabled"); customerSessionOptions.AddExtraParam( "components[mobile_payment_element][features][payment_method_redisplay]", "enabled"); customerSessionOptions.AddExtraParam( "components[mobile_payment_element][features][payment_method_remove]", "enabled"); var customerSession = client.V1.CustomerSessions.Create(customerSessionOptions); var paymentIntentOptions = new PaymentIntentCreateOptions { Amount = 1099, Currency = "eur", Customer = customer.Id, AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions { Enabled = true, }, }; PaymentIntent paymentIntent = client.V1.PaymentIntents.Create(paymentIntentOptions); return new PaymentSheetCreateResponse { PaymentIntent = paymentIntent.ClientSecret, CustomerSessionClientSecret = customerSession.ClientSecret Customer = customer.Id, PublishableKey = "<>", }; } ``` #### Listing payment methods manually #### .NET ```dotnet [HttpPost("payment-sheet")] public ActionResult CreatePaymentSheet([FromBody] CreatePaymentSheetRequest req) { // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. var client = new StripeClient("<>"); // Use an existing Customer ID if this is a returning customer. var customerOptions = new CustomerCreateOptions(); var requestOptions = new RequestOptions { StripeAccount = "{{CONNECTED_ACCOUNT_ID}}" }; var customer = client.V1.Customers.Create(customerOptions, requestOptions); var customerSessionOptions = new CustomerSessionCreateOptions { Customer = customer.Id, Components = new CustomerSessionComponentsOptions() } customerSessionOptions.AddExtraParam("components[mobile_payment_element][enabled]", true); customerSessionOptions.AddExtraParam( "components[mobile_payment_element][features][payment_method_save]", "enabled"); customerSessionOptions.AddExtraParam( "components[mobile_payment_element][features][payment_method_redisplay]", "enabled"); customerSessionOptions.AddExtraParam( "components[mobile_payment_element][features][payment_method_remove]", "enabled"); var customerSession = client.V1.CustomerSessions.Create(customerSessionOptions); var paymentIntentOptions = new PaymentIntentCreateOptions { Amount = 1099, Currency = "eur", Customer = customer.Id, PaymentMethodTypes = new List { "bancontact", "card", "ideal", "klarna", "sepa_debit", }, }; PaymentIntent paymentIntent = client.V1.PaymentIntents.Create(paymentIntentOptions); return new PaymentSheetCreateResponse { PaymentIntent = paymentIntent.ClientSecret, CustomerSessionClientSecret = customerSession.ClientSecret Customer = customer.Id, PublishableKey = "<>", }; } ``` > Each payment method needs to support the currency passed in the PaymentIntent and your business needs to be based in one of the countries each payment method supports. See the [Payment method integration options](https://docs.stripe.com/payments/payment-methods/integration-options.md) page for more details about what’s supported. ## Collect payment details [Client-side] Before displaying the mobile Payment Element, your checkout page should: - Show the products being purchased and the total amount - Collect any required shipping information - Include a checkout button to present Stripe’s UI In the checkout of your app, make a network request to the backend endpoint you created in the previous step and call `initPaymentSheet` from the `useStripe` hook. #### Accounts v2 ```javascript export default function CheckoutScreen() { const { initPaymentSheet, presentPaymentSheet } = useStripe(); const [loading, setLoading] = useState(false); const fetchPaymentSheetParams = async () => { const response = await fetch(`${API_URL}/payment-sheet`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, }); const { paymentIntent, ephemeralKey, customer_account } = await response.json(); return { paymentIntent, ephemeralKey, customer_account, }; }; const initializePaymentSheet = async () => { const { paymentIntent, ephemeralKey, customer_account, } = await fetchPaymentSheetParams(); const { error } = await initPaymentSheet({ merchantDisplayName: "Example, Inc.", customerAccountId: customer_account, customerEphemeralKeySecret: ephemeralKey, paymentIntentClientSecret: paymentIntent, // Set `allowsDelayedPaymentMethods` to true if your business accepts payment // methods that complete payment after a delay, like SEPA Debit and Sofort. allowsDelayedPaymentMethods: true, defaultBillingDetails: { name: 'Jane Doe', } }); if (!error) { setLoading(true); } }; const openPaymentSheet = async () => { // see below }; useEffect(() => { initializePaymentSheet(); }, []); return (