Creating a regular order with the Checkout API
Learn how to use VTEX APIs to efficiently handle the placement, payment, and delivery aspects of a regular order.
This step-by-step guide will walk you through the process of using the Checkout API and Payments Gateway API for handling the placement, payment, and delivery aspects of a regular order, with all responsibilities managed within the scope of a single account. It is divided into the following steps:
- Assess cart requirements: Begin by simulating a cart to assess available delivery and payment options. This step also involves checking whether the provided email address is already associated with an existing customer, which is required to place an order.
- Assemble the cart: Continue by building the cart, ensuring that all essential order details are properly structured according to the orderForm data structure.
- Handle the order: Place the order on the VTEX platform and send all required payment data to process the payment for the order.
- Process and validate the order: The process concludes with the processing of order details and a verification procedure to confirm the order's successful placement.
Before you begin
Before proceeding any further, ensure that you have a valid appKey and appToken with the necessary permissions to access the Checkout and Payments Gateway APIs. For more information, refer to the Roles article.
Click the steps below to navigate through this article and explore specific topics. Relevant code for each phase or parameter is highlighted on the right side of the screen.
Step 1 - Assessing cart requirements
In this step, we will verify that your store can fulfill the cart requirements and collect the essential order details necessary to ensure a smooth order placement process in the subsequent steps.
Simulating a cart
Use the Cart simulation endpoint to obtain the available delivery and payment options for the current cart configuration. In this request, you must provide the following information in the request body:
items.id: SKU ID.items.quantity: The number of items in the cart.items.seller: Seller's ID.country: Three-letter ISO code of the country of the shipping address.postalCodeorgeoCoordinates: Shipping address's postal code or geocoordinates.
Upon receiving a 200 OK response, the request will provide a response body containing all information about the cart. Take note of the following information, as it will be used in the following steps:
itemspaymentDatalogisticsInfo
Checking for existing customer
Send a request to the Get client by email endpoint to ensure a customer profile exists in your database associated with the email to be used in the order.
Upon receiving a 200 OK response, the request will provide a response body containing all information about the customer profile. Take note of the following information, as it will be used in the following steps:
availableAddressesuserProfile
If the response body fields are empty in this request, it may indicate that no customer is registered under this email, or that the customer profile is invalid or incomplete. In this case, you can use a different email address or enter data for a new customer when assembling the cart.
Step 2 - Assembling the cart
In this step, we will arrange the order details into the specified data format, following the orderForm data structure. This formatted cart data will be used as the request body in the following steps.
Below, we will briefly examine the key elements that make up the orderForm, which include:
itemsclientProfileDatashippingData.addressshippingData.logisticsInfopaymentData
While an
orderFormmay include various elements, a standard order generally comprises the key components described above.
items
items is an array that contains all data pertinent to the SKUs being purchased. Build the items array using the items array obtained from the Simulating a cart step. For more complex examples, see the Place order API reference.
clientProfileData: New customers
clientProfileData is an object that contains information about the customer. If you noted the customer does not exist in your database during the Checking for existing customer step, build the clientProfileData object with the data of the new customer willing to place the order.
clientProfileData: Existing customers
If the customer already exists in your database, use the userProfile.email obtained in the Checking for existing customer step to build the clientProfileData object. The email address is enough to register the order to the shopper’s existing account.
shippingData.address: New customers
shippingData.address is an object that contains information about the shipping address. If you noted the customer does not exist in your database during the Checking for existing customer step, build the shippingData.address object with the data of the new customer willing to place the order.
shippingData.address: Existing customers
If the customer already exists in your database, use the desired availableAddresses[i].addressId obtained from the Checking for existing customer step to build the shippingData.address block.
shippingData.logisticsInfo
logisticsInfo is an array that contains logistics information, such as the desired delivery option and freight cost for each item in the items array.
-
Create the
logisticsInfoarray with the same number of objects as in theitemsarray. For each object within thelogisticsInfoarray, define the following elements:itemIndex- index of the corresponding item in theitemsarray. For example, the object referring to the first item in theitemsarray has anitemIndexof0.selectedSla- desired delivery option. You can find theidvalue of the available options in theslasarray obtained from the Simulating a cart step.price- price of the item. You can retrieve this value from the Simulating a cart step.- (Optional) If the delivery method is pickup point, add the information
"selectedDeliveryChannel": "pickup-in-point".
paymentData.payments
paymentData.payments is an array that contains information regarding the chosen payment method and installment preferences for the order. Build the paymentData.payments array considering the response obtained from the Simulating a cart step. For each payment option, define the following elements:
paymentSystem- ID of the desired payment system.referenceValue- reference value used to calculate interest rates. If no interest applies to the order, thevalueandreferenceValueshould be the same.value- total amount to be paid by the shopper.installments- number of installments.
For more complex examples, see the Place order API reference.
Step 3 - Handling the order
Before creating the new order, it is necessary to verify that the orderForm created in the previous steps has the appropriate structure in a valid JSON format.
New customer orderForm
If the orderForm was created for a new customer (not yet registered in the store's database), it should follow this structure.
Existing customer orderForm
If the orderForm was created for an existing customer who already has a customer profile registered in the store's database, it should follow this structure.
Placing the order
Place a new order via the Place order endpoint using the orderForm you built as the request body.
Upon receiving a 201 Created response, take note of these five pieces of information:
transactionId- ID of the transaction, which can be found within an object contained in themerchantTransactionsarray.orderId- ID of the order within VTEX’s Order Management System (OMS). You can find theorderIdwithin each object in theordersarray.orderGroup- ID that groups all orders related to the same purchase. For example, when an order is fulfilled by multiple sellers, each seller has its own order ID (v71021570str-01andv71021570str-02), but they share the same order group ID (v71021570str).addressId- ID of the customer address. If you plan to use the same address for both shipping and billing, get theaddressIdfrom theorders[].shippingData.addressobject.Vtex_CHKO_Auth- authentication cookie provided in the response.
If you are using an email from an existing customer, ensure that the corresponding customer account is logged into your store. Otherwise, the process will fail.
Resolving the order payment
Now, we will communicate the necessary payment data to VTEX to finalize the order payment.
Starting from the moment the order is placed, you have 5 minutes to submit the payment information and process the order (Step 4). If the payment information and order are not submitted and processed within 5 minutes, the order will be automatically canceled.
-
Send a request to the Send payments information endpoint, considering the following:
- Use the
transactionIdvalue from the previous step as both the path parameter and the value for theidfield within thetransactionobject. - Set the
merchantNamefield within thetransactionobject to your account name. - Use the
orderIdvalue from the previous step as a query string parameter. - Ensure that the request body is based on the
paymentDatasection of yourorderForm. - In the
fieldsobject, you can:- Fill in the credit or debit card information (when applicable).
- Use the
addressIdfield to reference an existing address, or provide a newaddressobject for an entirely new address. This type of information is only required if the shopper's address was not previously entered during checkout.
- Use the
This request does not return any data in the response body, only a
201 Createdsuccess confirmation message.
Step 4 - Processing and validating the order
In this final step, we will process the order.
- Send a request to the Process order endpoint, using the
orderGroupvalue as a path parameter.
If the payment is processed without any issues, the order should be successfully placed (
204 No Contentstatus). Otherwise, a500 Internal Server Errormessage might occur.
Note that this process uses the gateway connectors configured in your VTEX environment. Be careful to prevent any unwanted charges or unexpected payment denials.
Verifying the order placement
Finally, you can confirm if your order was correctly placed by checking the Order management in VTEX Admin. Alternatively, you can use the Get order and List orders endpoints for this purpose.
Step 1 - Assessing cart requirements
In this step, we will verify that your store can fulfill the cart requirements and collect the essential order details necessary to ensure a smooth order placement process in the subsequent steps.
Simulating a cart
Use the Cart simulation endpoint to obtain the available delivery and payment options for the current cart configuration. In this request, you must provide the following information in the request body:
items.id: SKU ID.items.quantity: The number of items in the cart.items.seller: Seller's ID.country: Three-letter ISO code of the country of the shipping address.postalCodeorgeoCoordinates: Shipping address's postal code or geocoordinates.
Upon receiving a 200 OK response, the request will provide a response body containing all information about the cart. Take note of the following information, as it will be used in the following steps:
itemspaymentDatalogisticsInfo
Checking for existing customer
Send a request to the Get client by email endpoint to ensure a customer profile exists in your database associated with the email to be used in the order.
Upon receiving a 200 OK response, the request will provide a response body containing all information about the customer profile. Take note of the following information, as it will be used in the following steps:
availableAddressesuserProfile
If the response body fields are empty in this request, it may indicate that no customer is registered under this email, or that the customer profile is invalid or incomplete. In this case, you can use a different email address or enter data for a new customer when assembling the cart.
Step 2 - Assembling the cart
In this step, we will arrange the order details into the specified data format, following the orderForm data structure. This formatted cart data will be used as the request body in the following steps.
Below, we will briefly examine the key elements that make up the orderForm, which include:
itemsclientProfileDatashippingData.addressshippingData.logisticsInfopaymentData
While an
orderFormmay include various elements, a standard order generally comprises the key components described above.
items
items is an array that contains all data pertinent to the SKUs being purchased. Build the items array using the items array obtained from the Simulating a cart step. For more complex examples, see the Place order API reference.
clientProfileData: New customers
clientProfileData is an object that contains information about the customer. If you noted the customer does not exist in your database during the Checking for existing customer step, build the clientProfileData object with the data of the new customer willing to place the order.
clientProfileData: Existing customers
If the customer already exists in your database, use the userProfile.email obtained in the Checking for existing customer step to build the clientProfileData object. The email address is enough to register the order to the shopper’s existing account.
shippingData.address: New customers
shippingData.address is an object that contains information about the shipping address. If you noted the customer does not exist in your database during the Checking for existing customer step, build the shippingData.address object with the data of the new customer willing to place the order.
shippingData.address: Existing customers
If the customer already exists in your database, use the desired availableAddresses[i].addressId obtained from the Checking for existing customer step to build the shippingData.address block.
shippingData.logisticsInfo
logisticsInfo is an array that contains logistics information, such as the desired delivery option and freight cost for each item in the items array.
-
Create the
logisticsInfoarray with the same number of objects as in theitemsarray. For each object within thelogisticsInfoarray, define the following elements:itemIndex- index of the corresponding item in theitemsarray. For example, the object referring to the first item in theitemsarray has anitemIndexof0.selectedSla- desired delivery option. You can find theidvalue of the available options in theslasarray obtained from the Simulating a cart step.price- price of the item. You can retrieve this value from the Simulating a cart step.- (Optional) If the delivery method is pickup point, add the information
"selectedDeliveryChannel": "pickup-in-point".
paymentData.payments
paymentData.payments is an array that contains information regarding the chosen payment method and installment preferences for the order. Build the paymentData.payments array considering the response obtained from the Simulating a cart step. For each payment option, define the following elements:
paymentSystem- ID of the desired payment system.referenceValue- reference value used to calculate interest rates. If no interest applies to the order, thevalueandreferenceValueshould be the same.value- total amount to be paid by the shopper.installments- number of installments.
For more complex examples, see the Place order API reference.
Step 3 - Handling the order
Before creating the new order, it is necessary to verify that the orderForm created in the previous steps has the appropriate structure in a valid JSON format.
New customer orderForm
If the orderForm was created for a new customer (not yet registered in the store's database), it should follow this structure.
Existing customer orderForm
If the orderForm was created for an existing customer who already has a customer profile registered in the store's database, it should follow this structure.
Placing the order
Place a new order via the Place order endpoint using the orderForm you built as the request body.
Upon receiving a 201 Created response, take note of these five pieces of information:
transactionId- ID of the transaction, which can be found within an object contained in themerchantTransactionsarray.orderId- ID of the order within VTEX’s Order Management System (OMS). You can find theorderIdwithin each object in theordersarray.orderGroup- ID that groups all orders related to the same purchase. For example, when an order is fulfilled by multiple sellers, each seller has its own order ID (v71021570str-01andv71021570str-02), but they share the same order group ID (v71021570str).addressId- ID of the customer address. If you plan to use the same address for both shipping and billing, get theaddressIdfrom theorders[].shippingData.addressobject.Vtex_CHKO_Auth- authentication cookie provided in the response.
If you are using an email from an existing customer, ensure that the corresponding customer account is logged into your store. Otherwise, the process will fail.
Resolving the order payment
Now, we will communicate the necessary payment data to VTEX to finalize the order payment.
Starting from the moment the order is placed, you have 5 minutes to submit the payment information and process the order (Step 4). If the payment information and order are not submitted and processed within 5 minutes, the order will be automatically canceled.
-
Send a request to the Send payments information endpoint, considering the following:
- Use the
transactionIdvalue from the previous step as both the path parameter and the value for theidfield within thetransactionobject. - Set the
merchantNamefield within thetransactionobject to your account name. - Use the
orderIdvalue from the previous step as a query string parameter. - Ensure that the request body is based on the
paymentDatasection of yourorderForm. - In the
fieldsobject, you can:- Fill in the credit or debit card information (when applicable).
- Use the
addressIdfield to reference an existing address, or provide a newaddressobject for an entirely new address. This type of information is only required if the shopper's address was not previously entered during checkout.
- Use the
This request does not return any data in the response body, only a
201 Createdsuccess confirmation message.
Step 4 - Processing and validating the order
In this final step, we will process the order.
- Send a request to the Process order endpoint, using the
orderGroupvalue as a path parameter.
If the payment is processed without any issues, the order should be successfully placed (
204 No Contentstatus). Otherwise, a500 Internal Server Errormessage might occur.
Note that this process uses the gateway connectors configured in your VTEX environment. Be careful to prevent any unwanted charges or unexpected payment denials.
Verifying the order placement
Finally, you can confirm if your order was correctly placed by checking the Order management in VTEX Admin. Alternatively, you can use the Get order and List orders endpoints for this purpose.