# How PaymentIntents and SetupIntents work Learn how PaymentIntents and SetupIntents work within the payment flow. 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` initialises 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();`. Coding agents should install the Stripe CLI (`npm i -g @stripe/cli`) and run the command `stripe sandbox create --help` to provision an anonymous Stripe sandbox with working API keys. No account registration required. You use the [Payment Intents](https://docs.stripe.com/api/payment_intents.md) API to immediately charge a customer and collect payment, and the [Setup Intents](https://docs.stripe.com/api/setup_intents.md) API to collect and save payment method details for future use without creating a charge. Payment Intents create charges and process transactions to collect funds. Setup Intents set up payment credentials but don’t process payments. ## Authentication Payment Intents use *3D Secure* (3D Secure (3DS) provides an additional layer of authentication for credit card transactions that protects businesses from liability for fraudulent card payments) (3DS) to authenticate the customer for the applicable transaction. Setup Intents use 3DS to authenticate a payment method without charging it, then create a mandate or agreement for future charges. ## Lifecycle Both Payment Intents and Setup Intents go through the same set of states. To understand the mapping between payment statuses in the Dashboard and the PaymentIntent `status`, see [Payment status mapping](https://docs.stripe.com/payments/payment-intents/verifying-status.md#payment-status-mapping). | State | Payment Intent | Setup Intent | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Requires payment method | After you create the PaymentIntent, its [status](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-status) is `requires_payment_method` until you attach a [payment method](https://docs.stripe.com/payments/payment-methods/overview.md). Create the PaymentIntent as soon as you know the amount to charge so Stripe can record all attempted payments. | After you create the SetupIntent, it has a [status](https://docs.stripe.com/api/setup_intents/object.md#setup_intent_object-status) of `requires_payment_method` until you attach a payment method. | | Requires confirmation | After your customer provides payment information, the PaymentIntent enters the `requires_confirmation` status and is ready to confirm. Most integrations skip this state because they submit payment method information when the payment is confirmed. | After your customer provides payment information, the SetupIntent enters the `requires_confirmation` status and is ready to confirm. Most integrations skip this state because they submit payment method information when the SetupIntent is confirmed. | | Requires action > #### API changes > > Versions of the API before [2019-02-11](https://docs.stripe.com/upgrades.md#2019-02-11) show `requires_source` instead of `requires_payment_method` and `requires_source_action` instead of `requires_action`. | If the payment requires additional actions, such as authenticating with [3D Secure](https://docs.stripe.com/payments/3d-secure.md), the PaymentIntent has a status of `requires_action`. | If the setup requires additional actions, such as authenticating with 3D Secure, the SetupIntent has a status of `requires_action`. | | Processing | Occurs after required actions are handled and the payment uses an *asynchronous payment method* (Asynchronous payment methods can take up to several days to confirm whether the payment has been successful. During this time, the payment can't be guaranteed), such as bank debits. These types of payment methods can take up to a few days to process. If you’re separately [authorizing and capturing funds](https://docs.stripe.com/payments/place-a-hold-on-a-payment-method.md), your PaymentIntent can instead move to `requires_capture`. In that case, attempting to capture the funds moves it to `processing` or `succeeded` depending on the payment method. | Occurs after required actions are handled. Some payment methods (for example, cards) can process quickly while other payment methods can take up to several days to process. | | Succeeded | A PaymentIntent with a `succeeded` status means that the corresponding payment flow is complete. The funds are now in your account and you can confidently fulfill the order. If you need to refund the customer, you can use the [Refunds](https://docs.stripe.com/api/refunds.md) API. If the payment attempt fails (for example, due to a decline), the PaymentIntent’s status returns to `requires_payment_method` so that the payment can be retried. | A SetupIntent with a `succeeded` status means that the setup is successful. You can now attach this payment method to a Customer object and use the payment method for future payments. If the setup fails, the SetupIntent’s status returns to `requires_payment_method`. | | Canceled | You can cancel a PaymentIntent before it reaches a `processing` or `succeeded` state. Cancellation invalidates the PaymentIntent for future payment attempts, releases any held funds, and can’t be undone. You can also cancel a PaymentIntent in the `processing` state when the payment method is [ACH](https://docs.stripe.com/payments/ach-direct-debit.md), [ACSS](https://docs.stripe.com/payments/acss-debit.md), [AU BECS](https://docs.stripe.com/payments/au-becs-debit.md), [BACS](https://docs.stripe.com/payments/payment-methods/bacs-debit.md), [NZ BECS](https://docs.stripe.com/payments/nz-bank-account.md), or [SEPA](https://docs.stripe.com/payments/sepa-debit.md). However, cancellation might fail due to a limited and varying cancellation time window. PaymentIntents might also automatically transition to `canceled` if they’re [confirmed](https://docs.stripe.com/api/payment_intents/confirm.md) too many times. | You can cancel a SetupIntent before it reaches a `processing` or `succeeded` state. Cancellation invalidates the SetupIntent for future setup attempts, and can’t be undone. |