Learn how to use VTEX APIs to place a regular order from an existing cart.
This step-by-step guide will walk you through the process of using the Checkout API to create an order from an existing shopping cart. This process is divided into the following steps:
- Get cart information: The process begins with retrieving the
orderFormId
of the current shopping cart via the Get current or create a new cart endpoint. - Place the order: The process continues by placing the order on the VTEX platform via the Place order from an existing cart endpoint.
- Handling the order payment and processing: The process ends by sending the necessary payment data to resolve the order payment and processing order details.
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 for each phase or parameter will be highlighted on the right side of the screen.
Step 1 - Getting cart information
Send a GET
request to the Get current or create a new cart endpoint to retrieve the orderFormId
of the shopping cart you intend to use to create an order.
For more information, access the Get cart information by ID guide.
Step 2 - Placing the order
Place a new order via the Place order from an existing cart endpoint, providing the following information in the request body:
referenceId
:orderFormId
obtained in the previous step, serving as the unique identifier (ID) of theorderForm
associated with the shopping cart from which the order will be created.savePersonalData
: set astrue
if the shopper’s data provided during checkout should be saved for future reference (default isfalse
).optinNewsLetter
: set astrue
if the shopper opted to receive the newsletter (default isfalse
).value
: total value of the order without separating cents (e.g., $24.99 is represented by2499
).referenceValue
: reference value of the order, without separating cents (e.g., $24.99 is represented by2499
). This is used for calculating interest, if applicable.interestValue
: interest rate to be applied, if applicable.
Upon receiving a 201 Created
response, the request will provide a response body containing the orderForm with comprehensive details of the newly created regular order. Take note of these pieces of information and proceed to Resolving the order payment.
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 theshippingData.address
object.
If you face errors during the request submission, refer to Handling HTTP response errors when placing the order for common error scenarios when placing an order.
Step 3 - Resolving the order payment
Now, we will communicate the necessary payment data to VTEX for the finalization of the order's payment. Note that from now on, you have 5 (five) minutes to complete the payment process.
-
Send a request to the Send payments information public endpoint, considering the following:
- Use the
orderFormId
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.
Step 1 - Getting cart information
Send a GET
request to the Get current or create a new cart endpoint to retrieve the orderFormId
of the shopping cart you intend to use to create an order.
For more information, access the Get cart information by ID guide.
Step 2 - Placing the order
Place a new order via the Place order from an existing cart endpoint, providing the following information in the request body:
referenceId
:orderFormId
obtained in the previous step, serving as the unique identifier (ID) of theorderForm
associated with the shopping cart from which the order will be created.savePersonalData
: set astrue
if the shopper’s data provided during checkout should be saved for future reference (default isfalse
).optinNewsLetter
: set astrue
if the shopper opted to receive the newsletter (default isfalse
).value
: total value of the order without separating cents (e.g., $24.99 is represented by2499
).referenceValue
: reference value of the order, without separating cents (e.g., $24.99 is represented by2499
). This is used for calculating interest, if applicable.interestValue
: interest rate to be applied, if applicable.
Upon receiving a 201 Created
response, the request will provide a response body containing the orderForm with comprehensive details of the newly created regular order. Take note of these pieces of information and proceed to Resolving the order payment.
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 theshippingData.address
object.
If you face errors during the request submission, refer to Handling HTTP response errors when placing the order for common error scenarios when placing an order.
Step 3 - Resolving the order payment
Now, we will communicate the necessary payment data to VTEX for the finalization of the order's payment. Note that from now on, you have 5 (five) minutes to complete the payment process.
-
Send a request to the Send payments information public endpoint, considering the following:
- Use the
orderFormId
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.
Handling HTTP response errors when placing the order
400 - Bad Request (ORD002
)
Message error example (code ORD002): "Invalid order form"
- Issue: The
orderFormId
information is not valid. - Troubleshooting:
- Verify that the
orderFormId
is correct. - Ensure that the
orderFormId
corresponds to an existing shopping cart.
- Verify that the
400 - Bad Request (CHK0016
)
Message error example (code CHK0016): "Payment value does not match with reference value"
- Issue: The
value
andreferenceValue
fields have different values even without the use of interest in the payment. - Troubleshooting:
- Confirm that the provided
value
andreferenceValue
align correctly. - Check if the interest rate is correctly configured.
- Confirm that the provided
404 - Not Found
Message error example: "The requested URL was not found on the server"
- Issue: The requested URL was not found on the server.
- Troubleshooting: Check if the endpoint used is correct.
500 - Internal Server Error
Message error example (code ORD005): "The purchase cannot be done without items"
- Issue: The shopping cart (
orderFormId
) informed in the request does not have any item, making it impossible to create an order. - Troubleshooting:
- Verify that the specified shopping cart has items.
- Confirm that the
orderFormId
corresponds to a valid and non-empty shopping cart.
400 - Bad Request (ORD002
)
Message error example (code ORD002): "Invalid order form"
- Issue: The
orderFormId
information is not valid. - Troubleshooting:
- Verify that the
orderFormId
is correct. - Ensure that the
orderFormId
corresponds to an existing shopping cart.
- Verify that the
400 - Bad Request (CHK0016
)
Message error example (code CHK0016): "Payment value does not match with reference value"
- Issue: The
value
andreferenceValue
fields have different values even without the use of interest in the payment. - Troubleshooting:
- Confirm that the provided
value
andreferenceValue
align correctly. - Check if the interest rate is correctly configured.
- Confirm that the provided
404 - Not Found
Message error example: "The requested URL was not found on the server"
- Issue: The requested URL was not found on the server.
- Troubleshooting: Check if the endpoint used is correct.
500 - Internal Server Error
Message error example (code ORD005): "The purchase cannot be done without items"
- Issue: The shopping cart (
orderFormId
) informed in the request does not have any item, making it impossible to create an order. - Troubleshooting:
- Verify that the specified shopping cart has items.
- Confirm that the
orderFormId
corresponds to a valid and non-empty shopping cart.