> For the complete documentation index, see [llms.txt](https://docs.airdev.co/ecommerce-platform-template/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.airdev.co/ecommerce-platform-template/assets/pages/checkout.md).

# checkout

Page for completing an order

## Checkout Page Overview

This page is ordered to process an order on the platform. Users can use the checkout page if they have one or more items in their Cart. Non-logged in users can access the checkout page, but will be asked to sign up or log in before processing a payment. This page used several `Do when...` workflows to appropriately navigate the user through the checkout form.

## Key Workflows

#### Button Place Order is clicked

* Initiates the payment attempt by running the Charge a user using saved CC action
* If the payment is successful, the workflow will create a new `Order` instance and run the `Payment success` custom workflow
  * When creating the new Order, we refer directly to the payment action to grab a field fields - `Charge Id` and `Amount charged`&#x20;
  * All `Orders` should have `Paid?` set to **yes** and the `Payment date` field populated
  * Address fields are saved to populate the [order confirmation reusable](/ecommerce-platform-template/assets/reuseables/order-confirmation.md) and to pre-populate the address for future checkouts
  * CC fields are saved to populate the [order confirmation reusable](/ecommerce-platform-template/assets/reuseables/order-confirmation.md)

#### Button Remove Line Item is clicked

* Deletes the `Line item` from the user's `Cart`
* If the user's `Cart` contains no Line items after this one is deleted, the `Cart` will be deleted and the user will be redirected from the checkout page

#### \[Custom] Payment success

* This is triggered following a successful payment for the order
* Updates the `Cart`'s `Paid?` to **yes** as well as populates a few other price fields
  * Updating the `Cart`'s `Paid?` field is important - as this `Cart` will no longer be used for future functionality
* Deletes all **unpaid** Carts (`Paid?` set to **no**) linked to the user
  * The application should only save **paid** `Carts,` as these are used for reference purposes on the user's [settings page](/ecommerce-platform-template/assets/pages/settings-page.md)
* Updates the `Cart`'s `Line items`
* Updates the `Cart`'s `Products` `Total in stock` and `Told sold` fields
* Sends an order confirmation email to both the customer and app admins

#### \[Custom] Payment failure

* Triggered when `Button Place Order has an error running a workflow`
* Notifies the user of the payment error

#### Page is loaded and Current User isn’t logged in

* Sets the `temp cart` state to the user's current cart
* This used to store the relevant `Cart` for logged out users
  * When a user logs in or signs up - on either step 1 or step 2 - we run the `Transfer cart` custom workflow, which utilizes the `temp cart`

#### User is logged in and progressbar Main’s step # is 1 and checkout’s temp cart is not empty

* Triggered when the user logs in during the initial step of the checkout process
* Triggers the `Transfer cart` custom workflow

#### User is logged in and progressbar Main’s step # is 2

* Triggered when the user signs up or logs in using the form on step 2 of the checkout process
* Triggers the `Transfer cart` custom workflow
* Advances to the next step of the checkout process

#### User is logged out and Search for Carts:first item is empty

* Triggered if no `Cart` has been created for the current logged out user
* Redirects the user to the [index page](/ecommerce-platform-template/assets/pages/home.md)

#### Do when Search for Carts:first item is empty and checkout’s temp cart is empty and Group Tab 4’s Order is empty

* Triggered when there is no `Cart` active for the current user
* Redirects the user to the [index page](/ecommerce-platform-template/assets/pages/home.md)

#### \[Custom] Transfer cart

* Used to transfer the `Cart` from the logged out user to the logged in user
* Deletes every `Cart` besides the `temp cart` for the current user (these are no longer necessary)

## Key Elements

#### var - cart subtotal

* Used in the calculations for the payment workflows
* Calculated by taking the sum of each `Line item`'s `Quantity` multiplied by its `Product`'s `Price`

#### var - shipping cost

* Used in the calculations for the payment workflows
* Pulls the `App fee (shipping)` value from the `Website` object

#### RepeatingGroup Line Items (Cart)

* Contains every `Line item` for the current user's `Cart`

#### [Update Line Item Quantity](/ecommerce-platform-template/assets/reuseables/update_lineitem_quantity.md)

#### [Order Confirmation](/ecommerce-platform-template/assets/reuseables/order-confirmation.md)
