## Checkout actions After calling [initCheckout](/js/custom_checkout/init.md), use `loadActions()` to access methods for reading and manipulating [Checkout Sessions](/api/checkout/sessions.md). This method returns a `Promise` that resolves with an object with the following shape: * `{type: "error", error: { message: string }}` * `{type: "success", actions: object }` On success, the `actions` object provides methods to interact with the [Checkout Session](/api/checkout/sessions). **Syntax:** `checkout.loadActions(...)` ### Checkout actions ```js const checkout = stripe.initCheckout({ clientSecret: 'CLIENT_SECRET', }); checkout.loadActions().then(function(result) { if (result.type === 'success') { // Use the actions object to interact with the Checkout Session const actions = result.actions; } } ``` ```es_next const checkout = stripe.initCheckout({ clientSecret: 'CLIENT_SECRET', }); const result = await checkout.loadActions(); if (result.type === 'success') { // Use the actions object to interact with the Checkout Session const actions = result.actions; } ``` ## Read session data This method returns an object that contains data about the Checkout Session. This method returns a [Session object](/js/custom_checkout/session_object). **Syntax:** `actions.getSession(...)` ### Read session data ```js const checkout = stripe.initCheckout({ clientSecret: 'CLIENT_SECRET', }); checkout.loadActions().then(function(result) { if (result.type === 'success') { // Use the actions object to interact with the Checkout Session const actions = result.actions; var session = actions.getSession(); } } ``` ```es_next const checkout = stripe.initCheckout({ clientSecret: 'CLIENT_SECRET', }); const result = await checkout.loadActions(); if (result.type === 'success') { // Use the actions object to interact with the Checkout Session const actions = result.actions; const session = actions.getSession(); } ``` ## Apply a promotion code Use this method to apply a promotion code that your customer enters. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.applyPromotionCode(...)` - `promotionCode` (string) **required** The promotion code to apply to the Checkout Session. ### Apply a promotion code ```jsx actions.applyPromotionCode('PROMOTION_CODE'); ``` ## Remove a promotion code Use this method to remove the currently applied promotion code, if applicable. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.removePromotionCode(...)` ### Remove a promotion code ```jsx actions.removePromotionCode(); ``` ## Update the Customer's shipping address Use this method to update the Customer's shipping address. If your integration uses the [Express Checkout Element](/elements/express-checkout-element.md), the shipping address is collected directly from the wallet and the value set by `updateShippingAddress` is not used for express checkout payments. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.updateShippingAddress(...)` - `shippingAddress` (nullable object) **required** New shipping address for the Customer. - `name` (optional string) Full name. - `address` (optional object) Address. - `country` (string) **required** Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)). - `line1` (string) **required** Address line 1 (e.g., street, PO Box, or company name). - `line2` (optional string) Address line 2 (e.g., apartment, suite, unit, or building). - `city` (optional string) City, district, suburb, town, or village. - `postal_code` (optional string) ZIP or postal code. - `state` (optional string) State, county, province, or region. ### Update the Customer's shipping address ```jsx actions.updateShippingAddress({ name: 'Jenny Rosen', address: { line1: '27 Fredrick Ave', city: 'Brothers', state: 'OR', postal_code: '97712', country: 'US', } }); ``` ## Update the Customer's billing address Use this method to update the Customer's billing address. If your integration uses the [Express Checkout Element](/elements/express-checkout-element.md), the billing address is collected directly from the wallet and the value set by `updateBillingAddress` is not used for express checkout payments. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.updateBillingAddress(...)` - `billingAddress` (nullable object) **required** New billing information for the Customer. - `name` (optional string) Full name. - `address` (optional object) Address. - `country` (string) **required** Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)). - `line1` (optional string) Address line 1 (e.g., street, PO Box, or company name). - `line2` (optional string) Address line 2 (e.g., apartment, suite, unit, or building). - `city` (optional string) City, district, suburb, town, or village. - `postal_code` (optional string) ZIP or postal code. - `state` (optional string) State, county, province, or region. ### Update the Customer's billing address ```jsx actions.updateBillingAddress({ name: 'Jenny Rosen', address: { line1: '27 Fredrick Ave', city: 'Brothers', state: 'OR', postal_code: '97712', country: 'US', } }); ``` ## Update the Customer's email address Use this method to update the Customer's email address. If your integration uses [Link](/payments/link.md) and you do not provide an email during Checkout Session creation, you must call `updateEmail` for Link to appear as a payment option for returning users. If your integration uses the [Express Checkout Element](/elements/express-checkout-element.md), the email address is collected directly from the wallet and the value set by `updateEmail` is not used for express checkout payments. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.updateEmail(...)` - `email` (nullable string) **required** The Customer's email address. ### Update the Customer's email address ```jsx actions.updateEmail('jenny.rosen@example.com'); ``` ## Update the Customer's phone number Use this method to update the Customer's phone number. If your integration uses the [Express Checkout Element](/elements/express-checkout-element.md), the phone number is collected directly from the wallet and the value set by `updatePhoneNumber` is not used for express checkout payments. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.updatePhoneNumber(...)` - `phoneNumber` (nullable string) **required** The Customer's phone number. ### Update the Customer's phone number ```jsx actions.updatePhoneNumber('5554242424'); ``` ## Update the Customer's business name and tax ID Use this method to update the Customer's business name and tax ID. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.updateTaxIdInfo(...)` - `taxIdInfo` The Customer's tax ID information including the business name and tax ID. - `businessName` (nullable string) **required** The Customer's business name. - `taxId` **required** The Customer's tax ID. - `type` **required** One of [the supported tax ID types](/tax/checkout/tax-ids?payment-ui=embedded-components.md#supported-types) - `value` (nullable string) **required** The value of the tax ID. ### Update the Customer's business name and tax ID ```jsx actions.updateTaxIdInfo({ businessName: 'Acme, Inc.', taxID: { type: 'eu_vat', value: 'DK12345678' } }); ``` ## Update line item quantities Use this method to change the quantity of a line item. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.updateLineItemQuantity(...)` - `options` (object) **required** Options for `updateLineItemQuantity`. - `lineItem` (string) **required** The [ID](/js/custom_checkout/session_object.md#custom_checkout_session_object-lineItems-id) of the line item to update. - `quantity` (integer) **required** The new quantity of the line item. ### Update line item quantities ```jsx actions.updateLineItemQuantity({ lineItem: 'LINE_ITEM_ID', quantity: 2, }); ``` ## Update the selected shipping option Use this method to update the selected shipping option. See [shippingOptions](/js/custom_checkout/session_object.md#custom_checkout_session_object-shippingOptions) for a list of the available shipping options. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.updateShippingOption(...)` - `shippingOption` (string) The [ID](/js/custom_checkout/session_object.md#custom_checkout_session_object-shippingOptions-id) of the shipping option to select. ### Update the selected shipping option ```jsx actions.updateShippingOption('SHIPPING_OPTION_ID'); ``` ## Confirm the Checkout Session Use this method to confirm the Checkout Session. You must either read [total.total.amount](/js/custom_checkout/session_object.md#custom_checkout_session_object-total-total-amount) or each of [total.total.minorUnitsAmount](/js/custom_checkout/session_object.md#custom_checkout_session_object-total-total-minorUnitsAmount) and [currency](/js/custom_checkout/session_object.md#custom_checkout_session_object-currency) and [minorUnitsAmountDivisor](/js/custom_checkout/session_object.md#custom_checkout_session_object-minorUnitsAmountDivisor) from the checkout object and display in your UI, otherwise an error will be thrown. This helps keep your checkout page in sync as the Checkout Session updates, including adding future Stripe features, with minimal UI code changes. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.confirm(...)` - `options` (object) Options for `confirm`. - `returnUrl` (string) The URL to redirect your customer to after they authenticate or cancel their payment on the payment method’s app or site. This parameter is only required if you didn't specify the `return_url` when creating the Checkout Session. - `paymentMethod` (string) The ID of a previously collected [PaymentMethod](/api/payment_methods/object.md) to use for confirmation. When this option is provided, Custom Checkout will ignore the payment method collected by the PaymentElement and attempt confirmation using the provided PaymentMethod. - `savePaymentMethod` (boolean) Whether your Customer has provided consent to save the payment method for future purchases. Learn how to [save payment methods](/checkout/custom-checkout/save-payment-methods-checkout.md). - `redirect` ('always' | 'if_required') By default, `confirm` will always redirect to your `returnUrl` after a successful confirmation. If you set `redirect: "if_required"`, then `confirm` will only redirect if your user chooses a redirect-based payment method. - `email` (string) The Customer's email address. If provided, this value overrides any values previously set using [updateEmail](/js/custom_checkout/update_email.md). - `phoneNumber` (string) The Customer's phone number. If provided, this value overrides any values previously set using [updatePhoneNumber](/js/custom_checkout/update_phone_number.md). - `billingAddress` (object) The Customer's billing address. If provided, this value overrides any values previously set using [updateBillingAddress](/js/custom_checkout/update_billing_address.md). - `name` (optional string) Full name. - `address` (optional object) Address. - `country` (string) **required** Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)). - `line1` (optional string) Address line 1 (e.g., street, PO Box, or company name). - `line2` (optional string) Address line 2 (e.g., apartment, suite, unit, or building). - `city` (optional string) City, district, suburb, town, or village. - `postal_code` (optional string) ZIP or postal code. - `state` (optional string) State, county, province, or region. - `shippingAddress` (object) The Customer's shipping address. If provided, this value overrides any values previously set using [updateShippingAddress](/js/custom_checkout/update_shipping_address.md). - `name` (optional string) Full name. - `address` (optional object) Address. - `country` (string) **required** Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)). - `line1` (string) **required** Address line 1 (e.g., street, PO Box, or company name). - `line2` (optional string) Address line 2 (e.g., apartment, suite, unit, or building). - `city` (optional string) City, district, suburb, town, or village. - `postal_code` (optional string) ZIP or postal code. - `state` (optional string) State, county, province, or region. - `expressCheckoutConfirmEvent` (object) The [event object](/js/elements_object/express_checkout_element_confirm_event.md#express_checkout_element_on_confirm-handler) passed to your Express Checkout Element `confirm` handler. ### Confirm the Checkout Session ```jsx actions.confirm({ returnUrl: 'RETURN_URL', }); ``` ## Run server update Use this method to wrap an async function that makes a request to your server to update the Checkout Session. > `runServerUpdate` enforces a 20-second timeout for your update function. If your function doesn't resolve within 20 seconds, `runServerUpdate` returns an error. Wrap `runServerUpdate` calls in `try`/`catch` blocks to handle any errors. This method returns a `Promise` that resolves with an object containing the following fields: * `type`: one of either `"success"` or `"error"` * `session`: only populated when `type` is `"success"`. Contains a [Session](/js/custom_checkout/session_object) instance representing the updated state. * `error`: only populated when `type` is `"error"`. Contains an object with a string `message` field which can be displayed to your customer. **Syntax:** `actions.runServerUpdate(...)` - `userFunction` (function) **required** An async function to make a request to your server to update the Checkout Session. ### Run server update ```jsx actions.runServerUpdate( () => { return fetch('/update-checkout-session', { method: 'POST', body: JSON.stringify({checkoutSessionId: '{CHECKOUT_SESSION_ID}'}), }); } ); ```