Create Order
curl --request POST \
--url https://api.example.com/create-order \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"storeId": "<string>",
"buyerEmail": "<string>",
"buyerName": "<string>",
"buyerPhone": "<string>",
"shippingAddress": {
"line1": "<string>",
"line2": "<string>",
"city": "<string>",
"state": "<string>",
"postalCode": "<string>",
"country": "<string>"
},
"items": [
{
"productId": "<string>",
"variantId": "<string>",
"quantity": 123,
"price": 123
}
],
"paymentMethod": "<string>",
"paymentProofUrl": "<string>"
}
'import requests
url = "https://api.example.com/create-order"
payload = {
"storeId": "<string>",
"buyerEmail": "<string>",
"buyerName": "<string>",
"buyerPhone": "<string>",
"shippingAddress": {
"line1": "<string>",
"line2": "<string>",
"city": "<string>",
"state": "<string>",
"postalCode": "<string>",
"country": "<string>"
},
"items": [
{
"productId": "<string>",
"variantId": "<string>",
"quantity": 123,
"price": 123
}
],
"paymentMethod": "<string>",
"paymentProofUrl": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
storeId: '<string>',
buyerEmail: '<string>',
buyerName: '<string>',
buyerPhone: '<string>',
shippingAddress: {
line1: '<string>',
line2: '<string>',
city: '<string>',
state: '<string>',
postalCode: '<string>',
country: '<string>'
},
items: [{productId: '<string>', variantId: '<string>', quantity: 123, price: 123}],
paymentMethod: '<string>',
paymentProofUrl: '<string>'
})
};
fetch('https://api.example.com/create-order', 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.example.com/create-order",
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([
'storeId' => '<string>',
'buyerEmail' => '<string>',
'buyerName' => '<string>',
'buyerPhone' => '<string>',
'shippingAddress' => [
'line1' => '<string>',
'line2' => '<string>',
'city' => '<string>',
'state' => '<string>',
'postalCode' => '<string>',
'country' => '<string>'
],
'items' => [
[
'productId' => '<string>',
'variantId' => '<string>',
'quantity' => 123,
'price' => 123
]
],
'paymentMethod' => '<string>',
'paymentProofUrl' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$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.example.com/create-order"
payload := strings.NewReader("{\n \"storeId\": \"<string>\",\n \"buyerEmail\": \"<string>\",\n \"buyerName\": \"<string>\",\n \"buyerPhone\": \"<string>\",\n \"shippingAddress\": {\n \"line1\": \"<string>\",\n \"line2\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"postalCode\": \"<string>\",\n \"country\": \"<string>\"\n },\n \"items\": [\n {\n \"productId\": \"<string>\",\n \"variantId\": \"<string>\",\n \"quantity\": 123,\n \"price\": 123\n }\n ],\n \"paymentMethod\": \"<string>\",\n \"paymentProofUrl\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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.example.com/create-order")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"storeId\": \"<string>\",\n \"buyerEmail\": \"<string>\",\n \"buyerName\": \"<string>\",\n \"buyerPhone\": \"<string>\",\n \"shippingAddress\": {\n \"line1\": \"<string>\",\n \"line2\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"postalCode\": \"<string>\",\n \"country\": \"<string>\"\n },\n \"items\": [\n {\n \"productId\": \"<string>\",\n \"variantId\": \"<string>\",\n \"quantity\": 123,\n \"price\": 123\n }\n ],\n \"paymentMethod\": \"<string>\",\n \"paymentProofUrl\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/create-order")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"storeId\": \"<string>\",\n \"buyerEmail\": \"<string>\",\n \"buyerName\": \"<string>\",\n \"buyerPhone\": \"<string>\",\n \"shippingAddress\": {\n \"line1\": \"<string>\",\n \"line2\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"postalCode\": \"<string>\",\n \"country\": \"<string>\"\n },\n \"items\": [\n {\n \"productId\": \"<string>\",\n \"variantId\": \"<string>\",\n \"quantity\": 123,\n \"price\": 123\n }\n ],\n \"paymentMethod\": \"<string>\",\n \"paymentProofUrl\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"200": {},
"400": {},
"401": {},
"404": {},
"500": {},
"success": true,
"orderId": "<string>",
"orderNumber": "<string>",
"totalAmount": 123,
"checkoutFee": 123,
"finalAmount": 123,
"status": "<string>"
}Orders
Create Order
Create a new order for a customer
POST
/
create-order
Create Order
curl --request POST \
--url https://api.example.com/create-order \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"storeId": "<string>",
"buyerEmail": "<string>",
"buyerName": "<string>",
"buyerPhone": "<string>",
"shippingAddress": {
"line1": "<string>",
"line2": "<string>",
"city": "<string>",
"state": "<string>",
"postalCode": "<string>",
"country": "<string>"
},
"items": [
{
"productId": "<string>",
"variantId": "<string>",
"quantity": 123,
"price": 123
}
],
"paymentMethod": "<string>",
"paymentProofUrl": "<string>"
}
'import requests
url = "https://api.example.com/create-order"
payload = {
"storeId": "<string>",
"buyerEmail": "<string>",
"buyerName": "<string>",
"buyerPhone": "<string>",
"shippingAddress": {
"line1": "<string>",
"line2": "<string>",
"city": "<string>",
"state": "<string>",
"postalCode": "<string>",
"country": "<string>"
},
"items": [
{
"productId": "<string>",
"variantId": "<string>",
"quantity": 123,
"price": 123
}
],
"paymentMethod": "<string>",
"paymentProofUrl": "<string>"
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
storeId: '<string>',
buyerEmail: '<string>',
buyerName: '<string>',
buyerPhone: '<string>',
shippingAddress: {
line1: '<string>',
line2: '<string>',
city: '<string>',
state: '<string>',
postalCode: '<string>',
country: '<string>'
},
items: [{productId: '<string>', variantId: '<string>', quantity: 123, price: 123}],
paymentMethod: '<string>',
paymentProofUrl: '<string>'
})
};
fetch('https://api.example.com/create-order', 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.example.com/create-order",
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([
'storeId' => '<string>',
'buyerEmail' => '<string>',
'buyerName' => '<string>',
'buyerPhone' => '<string>',
'shippingAddress' => [
'line1' => '<string>',
'line2' => '<string>',
'city' => '<string>',
'state' => '<string>',
'postalCode' => '<string>',
'country' => '<string>'
],
'items' => [
[
'productId' => '<string>',
'variantId' => '<string>',
'quantity' => 123,
'price' => 123
]
],
'paymentMethod' => '<string>',
'paymentProofUrl' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$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.example.com/create-order"
payload := strings.NewReader("{\n \"storeId\": \"<string>\",\n \"buyerEmail\": \"<string>\",\n \"buyerName\": \"<string>\",\n \"buyerPhone\": \"<string>\",\n \"shippingAddress\": {\n \"line1\": \"<string>\",\n \"line2\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"postalCode\": \"<string>\",\n \"country\": \"<string>\"\n },\n \"items\": [\n {\n \"productId\": \"<string>\",\n \"variantId\": \"<string>\",\n \"quantity\": 123,\n \"price\": 123\n }\n ],\n \"paymentMethod\": \"<string>\",\n \"paymentProofUrl\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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.example.com/create-order")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"storeId\": \"<string>\",\n \"buyerEmail\": \"<string>\",\n \"buyerName\": \"<string>\",\n \"buyerPhone\": \"<string>\",\n \"shippingAddress\": {\n \"line1\": \"<string>\",\n \"line2\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"postalCode\": \"<string>\",\n \"country\": \"<string>\"\n },\n \"items\": [\n {\n \"productId\": \"<string>\",\n \"variantId\": \"<string>\",\n \"quantity\": 123,\n \"price\": 123\n }\n ],\n \"paymentMethod\": \"<string>\",\n \"paymentProofUrl\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/create-order")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"storeId\": \"<string>\",\n \"buyerEmail\": \"<string>\",\n \"buyerName\": \"<string>\",\n \"buyerPhone\": \"<string>\",\n \"shippingAddress\": {\n \"line1\": \"<string>\",\n \"line2\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"postalCode\": \"<string>\",\n \"country\": \"<string>\"\n },\n \"items\": [\n {\n \"productId\": \"<string>\",\n \"variantId\": \"<string>\",\n \"quantity\": 123,\n \"price\": 123\n }\n ],\n \"paymentMethod\": \"<string>\",\n \"paymentProofUrl\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"200": {},
"400": {},
"401": {},
"404": {},
"500": {},
"success": true,
"orderId": "<string>",
"orderNumber": "<string>",
"totalAmount": 123,
"checkoutFee": 123,
"finalAmount": 123,
"status": "<string>"
}Endpoint
POST https://your-project.supabase.co/functions/v1/create-order
Headers
Request Body
Response
Initial order statusOptions:
pending, payment_pending, paid, processing, shipped, delivered, cancelledExample Request
const response = await fetch(
'https://your-project.supabase.co/functions/v1/create-order',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${SUPABASE_ANON_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
storeId: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
buyerEmail: 'customer@example.com',
buyerName: 'John Doe',
buyerPhone: '+919876543210',
shippingAddress: {
line1: '123 Main Street',
line2: 'Apt 4B',
city: 'Mumbai',
state: 'Maharashtra',
postalCode: '400001',
country: 'IN'
},
items: [
{
productId: 'prod-123',
variantId: 'var-456',
quantity: 2,
price: 1299.00
}
],
paymentMethod: 'upi_direct',
paymentProofUrl: 'https://storage.supabase.co/bucket/proof.jpg'
})
}
);
const data = await response.json();
console.log('Order created:', data.orderId);
import Foundation
struct CreateOrderRequest: Codable {
let storeId: String
let buyerEmail: String
let buyerName: String
let buyerPhone: String
let shippingAddress: ShippingAddress
let items: [OrderItem]
let paymentMethod: String
let paymentProofUrl: String?
}
let request = CreateOrderRequest(
storeId: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
buyerEmail: "customer@example.com",
buyerName: "John Doe",
buyerPhone: "+919876543210",
shippingAddress: ShippingAddress(
line1: "123 Main Street",
line2: "Apt 4B",
city: "Mumbai",
state: "Maharashtra",
postalCode: "400001",
country: "IN"
),
items: [
OrderItem(
productId: "prod-123",
variantId: "var-456",
quantity: 2,
price: 1299.00
)
],
paymentMethod: "upi_direct",
paymentProofUrl: "https://storage.supabase.co/bucket/proof.jpg"
)
let response = try await supabase.functions.invoke(
"create-order",
options: FunctionInvokeOptions(body: request)
)
let order = try JSONDecoder().decode(OrderResponse.self, from: response.data)
print("Order created: \(order.orderId)")
curl -X POST https://your-project.supabase.co/functions/v1/create-order \
-H "Authorization: Bearer YOUR_ANON_KEY" \
-H "Content-Type: application/json" \
-d '{
"storeId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"buyerEmail": "customer@example.com",
"buyerName": "John Doe",
"buyerPhone": "+919876543210",
"shippingAddress": {
"line1": "123 Main Street",
"line2": "Apt 4B",
"city": "Mumbai",
"state": "Maharashtra",
"postalCode": "400001",
"country": "IN"
},
"items": [
{
"productId": "prod-123",
"variantId": "var-456",
"quantity": 2,
"price": 1299.00
}
],
"paymentMethod": "upi_direct",
"paymentProofUrl": "https://storage.supabase.co/bucket/proof.jpg"
}'
Example Response
{
"success": true,
"orderId": "ord-789-xyz",
"orderNumber": "ORD-2024-001234",
"totalAmount": 2598.00,
"checkoutFee": 0.00,
"finalAmount": 2598.00,
"status": "payment_pending"
}
Status Codes
Business Logic
Checkout Fee Calculation
Checkout Fee Calculation
UPI Direct: 0% fee (2% discount offered)Razorpay: 2-3% fee depending on payment method
- Credit/Debit Card: 2.5%
- UPI via Razorpay: 2%
- Wallets: 2%
totalAmount to calculate finalAmount.Email Notifications
Email Notifications
Two emails are sent automatically:
-
Buyer Confirmation Email
- Order summary with items
- Shipping address
- Payment method
- Order tracking link
-
Seller Notification Email
- New order alert
- Customer details
- Items to fulfill
- Payment proof (if UPI Direct)
Order Status Lifecycle
Order Status Lifecycle
payment_pending → paid → processing → shipped → delivered
↓
cancelled (any time before shipped)
- payment_pending: Order created, awaiting payment confirmation
- paid: Payment verified (auto for Razorpay, manual for UPI)
- processing: Seller is preparing the order
- shipped: Order dispatched with tracking
- delivered: Order received by customer
- cancelled: Order cancelled by seller or customer
Error Handling
try {
const response = await createOrder(orderData);
if (!response.success) {
throw new Error('Order creation failed');
}
console.log('Order created:', response.orderId);
} catch (error) {
if (error.message.includes('Invalid store')) {
alert('Store not found. Please try again.');
} else if (error.message.includes('Product not available')) {
alert('One or more products are out of stock.');
} else {
alert('Something went wrong. Please contact support.');
}
}
do {
let order = try await OrderService.create(request)
print("Order created: \(order.id)")
} catch let error as APIError {
switch error {
case .invalidStore:
showAlert("Store not found")
case .productUnavailable:
showAlert("Product out of stock")
default:
showAlert("Something went wrong")
}
}
Need help? Check out the Order Management Guide or reach out on GitHub Discussions
