How to Create a Bolt Order Token
Learn how to build a request that initiates checkout using a token.
Bolt has launched a new Merchant Dashboard experience. See this page for help documentation that reflects the Legacy Dashboard.
Create an order token to initiate the checkout process. This token is used to reference the cart generated in your storefront.
1. Configure Authorization & Headers
- Log in to the Merchant Dashboard.
- Navigate to Developers > API.
- Scroll to Keys and reveal your API Key.
- Embed this Publishable Key on your website. The publishable key is a long string of lower and upper case letters and numbers that consists of three sections.
TIP
The Signing Secret found in the Key section must also be used to authenticate payloads sent by Bolt.
Headers
HEADER | VALUE |
---|---|
X-Api-Key | Provide the API_KEY |
X-Nonce | unique 12-16 digit for every request (UUID is a good option) |
Content-Type | application/json |
API URLs
Environment | Bolt API URLs |
---|---|
Sandbox | https://api-sandbox.bolt.com |
Production | https://api.bolt.com |
2. Make a Create Order Request
1. Call Order Endpoint
See the Official API Reference for a request example.
PHP Example
<?php
require(dirname(__FILE__) . '/init_example.php');
$client = new \BoltPay\ApiClient([
'api_key' => \BoltPay\Bolt::$apiKey,
'is_sandbox' => \BoltPay\Bolt::$isSandboxMode
]);
$exampleData = new \BoltPay\Example\Data();
$cartData = $exampleData->generateCart();
/** @var \BoltPay\Http\Response $response */
$response = $client->createOrder($cartData);
$orderToken = $response->isResponseSuccessful() ? @$response->getBody()->token : '';
2. Validate the Response
Request
Check for a HTTP 200
success code and that the response contains an order token.
Cart
Ensure that the order_reference
value corresponds to the unique cart ID value provided in the request and that the cart_url
matches as well.
Items & Totals
Ensure the following for each item and its values:
- Items listed in the response must match the items listed in the request
- The
unit_price
,total_amount
andtax_amount
must be in cents - Every item must have an
image_url
,name
, anddescription
- The
total_amount
must equal(quantity X unit_price) + tax_amount
- Every cent must be precisely accounted for
- You cannot not apply a discount amount that is more than the total order amount. Doing so will result in an error. It is recommended you calculate a max allowable discount amount using the formula line item totals + tax + shipping = max allowable discount