Skip to main content
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>"
}
'
{
  "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

Authorization
string
required
Bearer token with anon or service_role key
Content-Type
string
default:"application/json"
Request body format

Request Body

storeId
string
required
UUID of the store placing the order
buyerEmail
string
required
Customer’s email address for order confirmation
buyerName
string
required
Customer’s full name
buyerPhone
string
required
Customer’s phone number (with country code)
shippingAddress
object
required
Customer’s shipping address
items
array
required
Array of order items
paymentMethod
string
required
Payment method selected by customerOptions: upi_direct, razorpay
paymentProofUrl
string
URL of payment proof image (required if paymentMethod is upi_direct)

Response

success
boolean
Indicates if the order was created successfully
orderId
string
UUID of the newly created order
orderNumber
string
Human-readable order number (e.g., “ORD-2024-001”)
totalAmount
number
Total order amount in the store’s currency
checkoutFee
number
Platform fee charged for this payment method
finalAmount
number
Total amount + checkout fee
status
string
Initial order statusOptions: pending, payment_pending, paid, processing, shipped, delivered, cancelled

Example 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: '[email protected]',
      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);

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

200
Success
Order created successfully
400
Bad Request
Invalid request body or missing required fields
401
Unauthorized
Invalid or missing authorization token
404
Not Found
Store or product not found
500
Server Error
Internal server error

Business Logic

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%
The fee is added to totalAmount to calculate finalAmount.
Two emails are sent automatically:
  1. Buyer Confirmation Email
    • Order summary with items
    • Shipping address
    • Payment method
    • Order tracking link
  2. Seller Notification Email
    • New order alert
    • Customer details
    • Items to fulfill
    • Payment proof (if UPI Direct)
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.');
  }
}
Need help? Check out the Order Management Guide or reach out on GitHub Discussions