Create Payment Intent
curl --request POST \
--url https://api.khaime.com/api/v1/payment/intent \
--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>",
"delivery_details": {}
}
'import requests
url = "https://api.khaime.com/api/v1/payment/intent"
payload = {
"product_id": 123,
"cart_unique_id": "<string>",
"email": "<string>",
"first_name": "<string>",
"last_name": "<string>",
"currency": "<string>",
"delivery_details": {}
}
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>',
delivery_details: {}
})
};
fetch('https://api.khaime.com/api/v1/payment/intent', 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/payment/intent",
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>',
'delivery_details' => [
]
]),
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/payment/intent"
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 \"delivery_details\": {}\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/payment/intent")
.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 \"delivery_details\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.khaime.com/api/v1/payment/intent")
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 \"delivery_details\": {}\n}"
response = http.request(request)
puts response.read_body{
"status": true,
"message": "Payment intent created",
"data": {
"secret": "pi_3abc123_secret_xyz789",
"publishable_key": "pk_live_abc123...",
"payment_method_types": ["card"],
"currency": "usd",
"amount_to_pay": 5829,
"data": {
"transaction_id": "txn_abc123",
"product_title": "Premium T-Shirt",
"customer_email": "john@example.com"
}
}
}
Commerce API
Create Payment Intent
Create a payment intent for checkout
POST
/
payment
/
intent
Create Payment Intent
curl --request POST \
--url https://api.khaime.com/api/v1/payment/intent \
--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>",
"delivery_details": {}
}
'import requests
url = "https://api.khaime.com/api/v1/payment/intent"
payload = {
"product_id": 123,
"cart_unique_id": "<string>",
"email": "<string>",
"first_name": "<string>",
"last_name": "<string>",
"currency": "<string>",
"delivery_details": {}
}
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>',
delivery_details: {}
})
};
fetch('https://api.khaime.com/api/v1/payment/intent', 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/payment/intent",
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>',
'delivery_details' => [
]
]),
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/payment/intent"
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 \"delivery_details\": {}\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/payment/intent")
.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 \"delivery_details\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.khaime.com/api/v1/payment/intent")
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 \"delivery_details\": {}\n}"
response = http.request(request)
puts response.read_body{
"status": true,
"message": "Payment intent created",
"data": {
"secret": "pi_3abc123_secret_xyz789",
"publishable_key": "pk_live_abc123...",
"payment_method_types": ["card"],
"currency": "usd",
"amount_to_pay": 5829,
"data": {
"transaction_id": "txn_abc123",
"product_title": "Premium T-Shirt",
"customer_email": "john@example.com"
}
}
}
Create Payment Intent
Creates a PaymentIntent (or equivalent for other gateways) for processing the 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)
object
Shipping details (for physical products)
Response
{
"status": true,
"message": "Payment intent created",
"data": {
"secret": "pi_3abc123_secret_xyz789",
"publishable_key": "pk_live_abc123...",
"payment_method_types": ["card"],
"currency": "usd",
"amount_to_pay": 5829,
"data": {
"transaction_id": "txn_abc123",
"product_title": "Premium T-Shirt",
"customer_email": "john@example.com"
}
}
}
Frontend Integration
Use thesecret (client_secret) with Khaime Payment SDK to complete the payment:
const khaime = Khaime(response.publishable_key);
const { error, paymentIntent } = await khaime.confirmPayment(
response.secret,
{
payment_method: {
card: cardElement,
billing_details: {
name: 'John Doe',
email: 'john@example.com'
}
}
}
);
if (error) {
console.error(error.message);
} else if (paymentIntent.status === 'succeeded') {
// Redirect to order confirmation
window.location.href = `/order/${response.data.transaction_id}`;
}
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 |
PAYMENT_GATEWAY_ERROR | Error creating payment intent |
Example
curl -X POST "https://api.khaime.com/api/v1/payment/intent" \
-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
