Preview Payment
curl --request POST \
--url https://api.khaime.com/api/v1/cart-payment/preview \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"product_id": 123,
"cart_unique_id": "<string>",
"email": "<string>",
"first_name": "<string>",
"last_name": "<string>",
"currency": "<string>"
}
'import requests
url = "https://api.khaime.com/api/v1/cart-payment/preview"
payload = {
"product_id": 123,
"cart_unique_id": "<string>",
"email": "<string>",
"first_name": "<string>",
"last_name": "<string>",
"currency": "<string>"
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
product_id: 123,
cart_unique_id: '<string>',
email: '<string>',
first_name: '<string>',
last_name: '<string>',
currency: '<string>'
})
};
fetch('https://api.khaime.com/api/v1/cart-payment/preview', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.khaime.com/api/v1/cart-payment/preview",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'product_id' => 123,
'cart_unique_id' => '<string>',
'email' => '<string>',
'first_name' => '<string>',
'last_name' => '<string>',
'currency' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.khaime.com/api/v1/cart-payment/preview"
payload := strings.NewReader("{\n \"product_id\": 123,\n \"cart_unique_id\": \"<string>\",\n \"email\": \"<string>\",\n \"first_name\": \"<string>\",\n \"last_name\": \"<string>\",\n \"currency\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.khaime.com/api/v1/cart-payment/preview")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"product_id\": 123,\n \"cart_unique_id\": \"<string>\",\n \"email\": \"<string>\",\n \"first_name\": \"<string>\",\n \"last_name\": \"<string>\",\n \"currency\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.khaime.com/api/v1/cart-payment/preview")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"product_id\": 123,\n \"cart_unique_id\": \"<string>\",\n \"email\": \"<string>\",\n \"first_name\": \"<string>\",\n \"last_name\": \"<string>\",\n \"currency\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": true,
"message": "Payment preview calculated",
"data": {
"subtotal": 5998,
"discount": 600,
"shipping": 599,
"tax": 432,
"transaction_fee": 175,
"total": 6004,
"currency": "USD",
"fee_breakdown": {
"base_fee": 175,
"customer_pays_fee": true
}
}
}
Commerce API
Preview Payment
Preview payment breakdown before creating payment intent
POST
/
cart-payment
/
preview
Preview Payment
curl --request POST \
--url https://api.khaime.com/api/v1/cart-payment/preview \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '
{
"product_id": 123,
"cart_unique_id": "<string>",
"email": "<string>",
"first_name": "<string>",
"last_name": "<string>",
"currency": "<string>"
}
'import requests
url = "https://api.khaime.com/api/v1/cart-payment/preview"
payload = {
"product_id": 123,
"cart_unique_id": "<string>",
"email": "<string>",
"first_name": "<string>",
"last_name": "<string>",
"currency": "<string>"
}
headers = {
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
product_id: 123,
cart_unique_id: '<string>',
email: '<string>',
first_name: '<string>',
last_name: '<string>',
currency: '<string>'
})
};
fetch('https://api.khaime.com/api/v1/cart-payment/preview', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.khaime.com/api/v1/cart-payment/preview",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'product_id' => 123,
'cart_unique_id' => '<string>',
'email' => '<string>',
'first_name' => '<string>',
'last_name' => '<string>',
'currency' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.khaime.com/api/v1/cart-payment/preview"
payload := strings.NewReader("{\n \"product_id\": 123,\n \"cart_unique_id\": \"<string>\",\n \"email\": \"<string>\",\n \"first_name\": \"<string>\",\n \"last_name\": \"<string>\",\n \"currency\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.khaime.com/api/v1/cart-payment/preview")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"product_id\": 123,\n \"cart_unique_id\": \"<string>\",\n \"email\": \"<string>\",\n \"first_name\": \"<string>\",\n \"last_name\": \"<string>\",\n \"currency\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.khaime.com/api/v1/cart-payment/preview")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"product_id\": 123,\n \"cart_unique_id\": \"<string>\",\n \"email\": \"<string>\",\n \"first_name\": \"<string>\",\n \"last_name\": \"<string>\",\n \"currency\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": true,
"message": "Payment preview calculated",
"data": {
"subtotal": 5998,
"discount": 600,
"shipping": 599,
"tax": 432,
"transaction_fee": 175,
"total": 6004,
"currency": "USD",
"fee_breakdown": {
"base_fee": 175,
"customer_pays_fee": true
}
}
}
Preview Payment
Returns a detailed breakdown of payment charges without creating a payment intent. Use this to show customers the final amount including fees before they confirm payment. Requirescart_unique_id from /cart/validate.
Request
string
required
Your API key
Body Parameters
integer
required
Primary product ID in the cart
string
required
Cart ID from
/cart/validate responsestring
required
Customer’s email address
string
required
Customer’s first name
string
required
Customer’s last name
string
required
Currency code (must match cart validation)
Response
{
"status": true,
"message": "Payment preview calculated",
"data": {
"subtotal": 5998,
"discount": 600,
"shipping": 599,
"tax": 432,
"transaction_fee": 175,
"total": 6004,
"currency": "USD",
"fee_breakdown": {
"base_fee": 175,
"customer_pays_fee": true
}
}
}
Use Case
Call this endpoint after/cart/validate to show customers a complete breakdown before they commit to payment:
// 1. Validate cart first
const cartResponse = await fetch('/api/v1/cart/validate', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({
cart: cartItems,
currency: 'USD',
delivery_details: shippingAddress
})
});
const { cart_unique_id, total } = await cartResponse.json();
// 2. Preview payment breakdown
const previewResponse = await fetch('/api/v1/cart-payment/preview', {
method: 'POST',
headers: {
'X-API-Key': apiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({
product_id: primaryProductId,
cart_unique_id,
email: 'john@example.com',
first_name: 'John',
last_name: 'Doe',
currency: 'USD'
})
});
// 3. Show breakdown to customer before final payment
const preview = await previewResponse.json();
displayPaymentSummary(preview.data);
Errors
| Error Code | Description |
|---|---|
CART_EXPIRED | Cart ID is no longer valid |
CART_NOT_FOUND | Invalid cart ID |
PRODUCT_NOT_FOUND | Product no longer available |
Example
curl -X POST "https://api.khaime.com/api/v1/cart-payment/preview" \
-H "X-API-Key: pk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"product_id": 12345,
"cart_unique_id": "bc59bc1f-e1b0-4ee5-a9cb-b966042ce38f",
"email": "john@example.com",
"first_name": "John",
"last_name": "Doe",
"currency": "USD"
}'
⌘I
