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 for handling the placement, payment, and delivery aspects of a regular order, with all responsibilities managed within the scope of a single account. This process is divided into the following steps:
- Assess cart requirements: The process begins with the simulation of a cart to assess available delivery and payment options. Additionally, since indicating an email address is necessary to place an order, this step also includes verifying if the provided email is already associated with an existing customer.
- Assemble the cart: After assessing the cart requirements, the next step is to assemble the cart, ensuring that all essential order information is organized according to the orderForm data structure.
- Handle the order: This step involves placing the order on the VTEX platform and sending the necessary payment data to resolve the order payment.
- Process and validate the order: The process ends by processing order details and conducting a verification procedure to confirm the successful placement of the order.
Before you begin
Before proceeding any further, ensure that you have a valid appKey
and appToken
granted with the necessary permissions to access the Checkout and Payments Gateway APIs. For more information, please refer to the Roles article.
Click the steps below to navigate through this article and explore specific topics. Relevant code will be highlighted and focused for your convenience on the right side of the screen.
Step 1 - Assessing cart requirements
In this step, we will verify if your store can fulfill the cart requirements and gather essential order information to ensure a smooth order placement process in the subsequent steps.
Simulating a cart
This step provides essential information regarding the available delivery and payment options for the specific combination of items in the cart.
- Send a request to the Cart simulation API endpoint. Specify the SKU ID (
items.id
), the number of items in the cart (items.quantity
), the Seller's ID (items.seller
), and the shipping address country (country
) in the request body. Also, provide the shipping address's postal code (postalCode
) or the geo-coordinates (geoCoordinates
). - Take note of the
items
,shippingData.logisticsInfo
, andpaymentData
objects, as we will use this data in the following steps.
Checking for existing customer
Now, we will verify whether the email that will be used to place the order is already related to a customer in your database. This verification serves to not only enhance operational efficiency but also proactively prevent potential permission-related issues.
- Send a request to the Get client by email endpoint to check for existing profiles associated with a specific email address. If the response to this request returns any content, it means the shopper’s information is in your database. In such cases, you can proceed using this data in subsequent steps, sparing the shopper from the need to provide their email again.
- If applicable, take note of the
availableAddresses
anduserProfile
objects, as we will use this data in the following steps.
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:
items
clientProfileData
shippingData.address
shippingData.logisticsInfo
paymentData
Note that while an orderForm
can have multiple elements, a standard order typically consists of the ones mentioned 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
logisticsInfo
array with the same number of objects as in theitems
array. For each object within thelogisticsInfo
array, define the following elements:itemIndex
- index of the corresponding item in theitems
array. For example, the object referring to the first item in theitems
array has anitemIndex
of0
.selectedSla
- desired delivery option. You can find theid
value of the available options in theslas
array 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, thevalue
andreferenceValue
should 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
In this step, we will use the orderForm
we built in the previous steps to place an order on the VTEX platform.
Reviewing the orderForm
of a new customer
After building the orderForm
for your order, ensure it adheres to a valid JSON format. For new customers, your orderForm
should resemble this structure.
Reviewing the orderForm
of an existing customer
For returning customers, the orderForm
for your order should resemble this structure.
Placing the order
Send a request to the Place order endpoint using the orderForm
you built as the request body.
Upon receiving a 201 Created
response, take note of these four pieces of information:
orderId
- ID of the order within VTEX’s Order Management System (OMS). You can find theorderId
within each object in theorders
array.transactionId
- ID of the transaction, which can be found within the objects contained in thetransactionData.merchantTransactions
array.addressId
- ID of the customer address. If you plan to use the same address for both shipping and billing, get theaddressId
from theorders[].shippingData.address
object.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
In this step, we will communicate the necessary payment data to VTEX for the finalization of the order's payment.
Starting from the moment the order is placed, you have a window of five minutes to complete the payment process. Failure to do so will result in automatic cancellation, and the order will be labeled as "incomplete."
-
Send a request to the Send payments information public endpoint, considering the following:
- Use the
orderId
value obtained in the previous step as theorderId
query-string parameter. - Use the
transactionId
value obtained in the previous step as a path parameter. - Ensure that the request body is based on the
paymentData
section of yourorderForm
. - In the
fields
object, use theaddressId
field to reference an existing address or introduce a newaddress
object for an entirely new address.
- Use the
If you intend to send saved credit card data, you can use the Send payments with saved credit card endpoint instead.
Step 4 - Processing and validating the order
In this final step, we will process the order.
- Send a request to the Process order endpoint. If the payment is processed without any issues, the order should be successfully placed. Otherwise, a
status 500
error 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 if your store can fulfill the cart requirements and gather essential order information to ensure a smooth order placement process in the subsequent steps.
Simulating a cart
This step provides essential information regarding the available delivery and payment options for the specific combination of items in the cart.
- Send a request to the Cart simulation API endpoint. Specify the SKU ID (
items.id
), the number of items in the cart (items.quantity
), the Seller's ID (items.seller
), and the shipping address country (country
) in the request body. Also, provide the shipping address's postal code (postalCode
) or the geo-coordinates (geoCoordinates
). - Take note of the
items
,shippingData.logisticsInfo
, andpaymentData
objects, as we will use this data in the following steps.
Checking for existing customer
Now, we will verify whether the email that will be used to place the order is already related to a customer in your database. This verification serves to not only enhance operational efficiency but also proactively prevent potential permission-related issues.
- Send a request to the Get client by email endpoint to check for existing profiles associated with a specific email address. If the response to this request returns any content, it means the shopper’s information is in your database. In such cases, you can proceed using this data in subsequent steps, sparing the shopper from the need to provide their email again.
- If applicable, take note of the
availableAddresses
anduserProfile
objects, as we will use this data in the following steps.
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:
items
clientProfileData
shippingData.address
shippingData.logisticsInfo
paymentData
Note that while an orderForm
can have multiple elements, a standard order typically consists of the ones mentioned 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
logisticsInfo
array with the same number of objects as in theitems
array. For each object within thelogisticsInfo
array, define the following elements:itemIndex
- index of the corresponding item in theitems
array. For example, the object referring to the first item in theitems
array has anitemIndex
of0
.selectedSla
- desired delivery option. You can find theid
value of the available options in theslas
array 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, thevalue
andreferenceValue
should 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
In this step, we will use the orderForm
we built in the previous steps to place an order on the VTEX platform.
Reviewing the orderForm
of a new customer
After building the orderForm
for your order, ensure it adheres to a valid JSON format. For new customers, your orderForm
should resemble this structure.
Reviewing the orderForm
of an existing customer
For returning customers, the orderForm
for your order should resemble this structure.
Placing the order
Send a request to the Place order endpoint using the orderForm
you built as the request body.
Upon receiving a 201 Created
response, take note of these four pieces of information:
orderId
- ID of the order within VTEX’s Order Management System (OMS). You can find theorderId
within each object in theorders
array.transactionId
- ID of the transaction, which can be found within the objects contained in thetransactionData.merchantTransactions
array.addressId
- ID of the customer address. If you plan to use the same address for both shipping and billing, get theaddressId
from theorders[].shippingData.address
object.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
In this step, we will communicate the necessary payment data to VTEX for the finalization of the order's payment.
Starting from the moment the order is placed, you have a window of five minutes to complete the payment process. Failure to do so will result in automatic cancellation, and the order will be labeled as "incomplete."
-
Send a request to the Send payments information public endpoint, considering the following:
- Use the
orderId
value obtained in the previous step as theorderId
query-string parameter. - Use the
transactionId
value obtained in the previous step as a path parameter. - Ensure that the request body is based on the
paymentData
section of yourorderForm
. - In the
fields
object, use theaddressId
field to reference an existing address or introduce a newaddress
object for an entirely new address.
- Use the
If you intend to send saved credit card data, you can use the Send payments with saved credit card endpoint instead.
Step 4 - Processing and validating the order
In this final step, we will process the order.
- Send a request to the Process order endpoint. If the payment is processed without any issues, the order should be successfully placed. Otherwise, a
status 500
error 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.