# Checkout to purchase a subscription

Source: https://dev.arcxp.com/subscriptions/sales/learn/checkout-to-purchase-a-subscription/

The flow for purchasing a digital subscription is based on a shopping cart concept. Items are added to the cart, an order is created, and a payment is submitted.

Arc XP Subscriptions supports two checkout flows. Depending on the flow used by the end user or implemented by the customer, different steps are involved:

- **Regular checkout** to purchase a subscription: When the user initiates the order creation, the end user is already logged into the system.
- **Express checkout** to purchase a subscription: This checkout option skips required registration steps that may add friction to the process. Express checkout can be used by non-authenticated, anonymous customers. Once the checkout is complete, customers can then proceed with the account registration process.

> **Note:**
> 
> If you are using **Stripe Intents** as your payment provider, once the [payment provider](https://dev.arcxp.com/subscriptions/sales/configure/payment-gateway-providers/) is set up in the Admin tool, you can use the Theme blocks provided by Arc XP Subscriptions to integrate the payment flow into your site with just a few pages and clicks. By using the Theme blocks, the end user will be inforced to go through the `regular checkout`.
> 
> By default, Arc XP Subscriptions allows multiple items in the shopping cart. You can configure to not allow customers to add more than one item to their shopping cart during checkout. This setting default value is OFF, so the cart allows multiple products, but setting the switch to ON might be useful in preventing users from buying multiple subscriptions/products by mistake. If you want to enable this setting, please contact ACS to submit a ticket for the Subscriptions team ([arc-esc-revenue-engine](https://washpost.enterprise.slack.com/archives/C081987250T)) to turn the switch ON.

## Regular checkout

![Regular checkout](https://dev.arcxp.com/images/subscriptions/sales/learn/checkout-to-purchase-a-subscription/regular-checkout.png)

For **regular checkout**, ensure a valid [access-token](https://dev.arcxp.com/subscriptions/identity/build/connect-and-login-with-arc-xp-identity-sdks-and-apis) is being passed during during steps 2 through 7.

1. [Authenticate](https://dev.arcxp.com/subscriptions/identity/learn/manage-user-accounts-reader-experience/#user-login): The user already has an account and ask for log in.
2. [Get products and prices](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#checkout-interaction): A published offer is available, allowing the end user to access SKUs and PriceCodes (identifiers for products and prices) through the offer.
3. [Add item(s) to a cart](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#add-item-to-cart): The end user places item(s) into the cart (pairs of products and prices).  
> **Note:**  
>  
> Arc XP Supports an anonymous cart, however there is no a way to transfer an anonymous cart to a registered user’s cart. One way to tackle this is by saving the anonymous cart in the browser storage and creating a new cart once the system detects the user is logged in. This approach allows you to place `authentication` as step 3 without the need the end user needs to add the item(s) into the cart again once becomes in a logged in user.
4. [Create order](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#create-order): With at least one item in the cart, an order can be created. If you have [reCaptcha](https://dev.arcxp.com/subscriptions/identity/configure/secure-your-site-against-attacks-cors-domains-blocked-email-domains-and-recaptcha/#recaptcha) enabled for checkout, a reCAPTCHA token needs to be passed when making this call.
5. [Get payment options](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#get-list-of-available-payment-options): Retrieve the payment gateway configuration set up in the Admin tool for the tenant (organization + site) making the request.
6. [Initialize payment](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#initialize-payment): Using the information from the `payment options`, initialize communication with the selected payment gateway. Depending on the payment gateway, the end user may be redirected to a payment gateway form.

  - `Get and fill the payment form`: The end user enters their payment information. Once the payment is accepted, the payment gateway returns a token.
7. [Finalize payment](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#finalize-payment): This is a backup for the server-to-server call, ensuring that Arc XP Subscriptions recognizes the completed payment. If you have [reCAPTCHA](https://dev.arcxp.com/subscriptions/identity/configure/secure-your-site-against-attacks-cors-domains-blocked-email-domains-and-recaptcha#recaptcha) enabled for checkout, a reCAPTCHA token needs to be passed when making this call. The same reCAPTCHA token can be sent multiple times; you can use the same token that was sent when calling `create order`.

Once the call to `finalize payment` returns a successful response:

- A transaction in our system is created. You can find the order details via CSR under the [order](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-csr-perspective/#orders) tab.
- For each product and price, a new subscription is started in our system. You can find all the user’s subscriptions under the [subscriptions](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-csr-perspective/#subscriptions) tab.
- Several web socket events are triggered: ORDER\_CONFIRMATION, START\_SUBSCRIPTION.

## Express checkout

![Regular checkout](https://dev.arcxp.com/images/subscriptions/sales/learn/checkout-to-purchase-a-subscription/express-checkout.png)

For **express checkout**, a valid access-token is not present during the flow, since the end user is an anonymous user.

1. [Get products and prices](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#checkout-interaction): A published offer is available, allowing the end user to access SKUs and PriceCodes (identifiers for products and prices) through the offer.
2. [Add item(s) to a cart](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#add-item-to-cart): The end user places item(s) into the cart (pairs of products and prices).
3. [Create order](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#create-order): With at least one item in the cart, an order can be created. The end user can call `create order` passing only his/her email. If you have [reCaptcha](https://dev.arcxp.com/subscriptions/identity/configure/secure-your-site-against-attacks-cors-domains-blocked-email-domains-and-recaptcha/#recaptcha) enabled for checkout, a reCAPTCHA token needs to be passed when making this call.  
> **Note:**  
>  
> As the end user is not authenticated, express checkout allows the customer to update an anonymous cart (add and/or delete items to the cart, clean the cart). This is tracked by an _anonid cookie_. During the call to ‘create order’ Sales checks:  
>  
>  - If an existing account with that email is found then that account becomes the ‘owner’ of any items purchased during checkout.  
>  - If an existing account with that email is not found then, once the `finalize payment` is completed successfully a new account is created using that email (a password identity with that email is created).
4. [Get payment options](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#get-list-of-available-payment-options): Retrieve the payment gateway configuration set up in the Admin tool for the tenant (organization + site) making the request.
5. [Initialize payment](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#initialize-payment): Using the information from the `payment options`, initialize communication with the selected payment gateway. Depending on the payment gateway, the end user may be redirected to a payment gateway form.  
  - `Get and fill the payment form`: The end user enters payment information. Once the payment is accepted, the payment gateway returns a token.
6. [Finalize payment](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-reader-experience/#finalize-payment): This serves as a backup for the server-to-server call, ensuring that Arc XP Subscriptions recognizes the completed payment. If you have [reCaptcha](https://dev.arcxp.com/subscriptions/identity/configure/secure-your-site-against-attacks-cors-domains-blocked-email-domains-and-recaptcha/#recaptcha) enabled for checkout, a reCAPTCHA token needs to be passed when making this call. The same reCAPTCHA token can be sent multiple times; you can use the same token that was sent when calling `create order`.

Once the call to `finalize payment` returns a successful response:

- If no existing account with the provided email is found, the following WebSocket events are dispatched: [VERIFY\_EMAIL](https://dev.arcxp.com/subscriptions/identity/learn/list-of-identity-events/#email-verify-request), [EXPRESS\_CHECKOUT\_PASSWORD\_RESET\_REQUEST](https://dev.arcxp.com/subscriptions/identity/learn/list-of-identity-events/#express-checkout-password-reset-request), and [USER\_SIGN\_UP](https://dev.arcxp.com/subscriptions/identity/learn/list-of-identity-events/#user-sign-up). The customer must ensure that the _nonce_ from EXPRESS\_CHECKOUT\_PASSWORD\_RESET\_REQUEST is shared with the end user via an [email service provider](https://dev.arcxp.com/subscriptions/identity/build/ifx-email-servic-provider-integration-and-websocket-events/). This allows the end user to complete the registration process and gain access to their account.
- Depending on the [verify email setting](https://dev.arcxp.com/subscriptions/identity/learn/manage-user-accounts-reader-experience/#verify-email), account verification may be required before the user can access to the system.
- A transaction in our system is created. You can find the order details via CSR under the [order](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-csr-perspective/#orders) tab.
- For each product and price, a new subscription is started in our system. You can find all the user’s subscriptions under the [subscriptions](https://dev.arcxp.com/subscriptions/sales/learn/subscription-management-csr-perspective/#subscriptions) tab.
- Related to the purchase, additional web socket events are triggered: ORDER\_CONFIRMATION, START\_SUBSCRIPTION.

> **Note:**
> 
> In case you want to offer multiple payment options to your end users using different payment providers, if the end user decides to switch to a different payment gateway once `finalize payment` has been called, you will need to `create a new order` and grab a new order number before calling `Initialize payment` again.
