## Confirm a setup

`stripe.confirmSetup(options: object)`

Use `stripe.confirmSetup` to confirm a [SetupIntent](https://docs.stripe.com/api/setup_intents.md) using data collected by the [Payment Element](https://docs.stripe.com/js/element/payment_element.md), or with manually provided data via `confirmParams`. When called, `stripe.confirmSetup` will attempt to complete any [required actions](https://docs.stripe.org/payments/intents.md), such as authenticating your user by displaying a 3DS dialog or redirecting them to a bank authorization page. Your user will be redirected to the `return_url` you pass once the authorization is complete.

> The `stripe.confirmSetup` might take several seconds to complete.
> During that time, disable your form from being resubmitted and show a waiting indicator, such as a spinner. If you receive an error result, show this error to the user, re-enable the form, and hide the waiting indicator.

- `options`
  - `elements`
    The [Elements](#payment_element_create) instance used to create the Payment Element. Required if you [collect payment details before creating an Intent](https://docs.stripe.com/payments/accept-a-payment-deferred.md?platform=web&type=setup). It's always required if you don't provide a `clientSecret`.
  - `clientSecret`
    The SetupIntent's client secret. Required if you [collect payment details before creating an Intent](https://docs.stripe.com/payments/accept-a-payment-deferred.md?platform=web&type=setup). It's always required if you don't provide an `elements` instance containing a [client secret](https://docs.stripe.com/api/setup_intents/object.md#setup_intent_object-client_secret).
  - `confirmParams`
    Parameters that will be passed on to the Stripe API. Refer to the [Setup Intents API](https://docs.stripe.com/api/setup_intents/confirm.md) for a full list of parameters.
  - `return_url`
    The URL that Stripe redirects your customer to after they complete authentication.
  - `confirmation_token`
    If collected previously, the ID of the ConfirmationToken to use to confirm this SetupIntent. This is mutually exclusive with the `elements` parameter.
  - `payment_method_data`
    When you call `stripe.confirmSetup`, payment details are collected from the Element and passed to the SetupIntents [confirm endpoint](https://docs.stripe.com/api/setup_intents/confirm.md) as the [payment_method_data](https://docs.stripe.com/api/setup_intents/confirm.md#confirm_setup_intent-payment_method) parameter. You can also include additional `payment_method_data` fields, which will be merged with the data collected from the Element.
  - `billing_details`
    The customer's [billing_details](https://docs.stripe.com/api/payment_methods/create.md#create_payment_method-billing_details). Details collected by Elements will override values passed here. Billing fields that are not collected by Elements will be merged with the values passed here.

### Example

```javascript
const stripe = await stripePromise;
const elements = stripe.elements();

// Fetch the SetupIntent client secret from your server
const clientSecret = 'pi_xxxxxxxxxxxxxxxxxxxx';

// Confirm the SetupIntent with the Payment Element
const { setupIntent } = await stripe.confirmSetup({
  elements,
  clientSecret,
});

// Handle the result
if (setupIntent.status === 'succeeded') {
  // Setup succeeded
}
```