create-order
Method: POST
Path: /orders
Tags: Orders
Summary
Create order
Description
Creates an order from a cart. Returns an Order object along with payment_required and payment_info. When payment_required is true and payment_info is present, use it to initiate the payment flow, then poll /orders/\{order_number\}/payment-status from your return URL. An order that isn't placed on the customer's credit line and that its loyalty points, credit balance or discounts pay in full needs no payment (payment_required is false). Paid by points or a discount alone, it comes back already confirmed (awaiting_approval when the store doesn't approve orders automatically; complete when it is collected in store with nothing to ship) with payment_status success; paid by its credit balance, with or without points, it stays pending until that balance is settled against it. Credit balance applied to the cart must be within what the customer can spend now, which leaves out credit their other unpaid orders have claimed. When credit balance can't be used for a moment, an order using it fails with a 409 and the credit-balance-unavailable error code, and nothing is placed: retry shortly. The payment method must be one the store offers on the token's sales channel (GET /payments/payment-methods lists them); any other is refused with a 400. A POS token can't place an order here: the POS places its orders with POST /pos/orders.
Storefront SDK Usage
SDK Method: sdk.order.createOrder()
Example:
// Juspay Hyper Checkout - Redirects to hosted payment page
const { data, error } = await sdk.order.createOrder({
cart_id: "cart_01H9XYZ12345ABCDE",
payment_method: {
payment_provider_slug: "juspay",
integration_type: "hyper-checkout",
gateway_reference_id: "gateway_ref_123",
return_url: "https://yourapp.com/payment/return",
action: "paymentPage"
}
});
// Juspay Express Checkout - New Card
const { data, error } = await sdk.order.createOrder({
cart_id: "cart_01H9XYZ12345ABCDE",
payment_method: {
payment_provider_slug: "juspay",
integration_type: "express-checkout",
gateway_reference_id: "gateway_ref_123",
return_url: "https://yourapp.com/payment/return",
payment_method_type: "CARD",
payment_method: "VISA",
auth_type: "OTP",
save_to_locker: true,
card_number: "4111111111111111",
card_exp_month: "12",
card_exp_year: "2025",
name_on_card: "John Doe",
card_security_code: "123"
}
});
// Juspay Express Checkout - Saved Card Token
const { data, error } = await sdk.order.createOrder({
cart_id: "cart_01H9XYZ12345ABCDE",
payment_method: {
payment_provider_slug: "juspay",
integration_type: "express-checkout",
gateway_reference_id: "gateway_ref_123",
return_url: "https://yourapp.com/payment/return",
get_client_auth_token: true,
payment_method_type: "CARD",
payment_method: "VISA",
auth_type: "OTP",
save_to_locker: false,
card_token: "token_abc123",
card_security_code: "123"
}
});
// Juspay Express Checkout - UPI Collect
const { data, error } = await sdk.order.createOrder({
cart_id: "cart_01H9XYZ12345ABCDE",
payment_method: {
payment_provider_slug: "juspay",
integration_type: "express-checkout",
gateway_reference_id: "gateway_ref_123",
return_url: "https://yourapp.com/payment/return",
payment_method_type: "UPI",
payment_method: "UPI_COLLECT",
upi_vpa: "user@upi"
}
});
// Juspay Express Checkout - Net Banking
const { data, error, events } = await sdk.order.createOrder({
cart_id: "cart_01H9XYZ12345ABCDE",
payment_method: {
payment_provider_slug: "juspay",
integration_type: "express-checkout",
gateway_reference_id: "gateway_ref_123",
return_url: "https://yourapp.com/payment/return",
payment_method_type: "NB",
payment_method: "NB_HDFC"
}
});
if (error) {
console.error("Failed to create order:", error.message);
} else {
console.log("Order created:", data.order.id);
// `events` holds the `Order Created` event: forward it to
// `@commercengine/analytics` so the browser and server copies dedupe
console.log("Events:", events.map((event) => event.event_id));
console.log("Payment required:", data.payment_required);
console.log("Payment info:", data.payment_info);
// For hyper-checkout, redirect to payment page
if ("payment_links" in data.payment_info) {
window.location.href = data.payment_info.payment_links?.web;
}
// For express-checkout with OTP authentication
if ("payment" in data.payment_info && data.payment_info.payment?.authentication?.params) {
const { id: txn_id, challenge_id } = data.payment_info.payment.authentication.params;
// Use txn_id and challenge_id with sdk.payments.authenticateDirectOtp()
}
}TypeScript Definition
"create-order": {
parameters: {
query?: never;
header?: {
/** @description A ULID you propose as the `event_id` of the first entry this request returns in `events`. Used only when it is a valid ULID minted within a day of now and not already used; otherwise the server mints one. The `event_id` returned in `events` is the one to send. */
"X-CE-Event-ID"?: components["parameters"]["ProposedEventId"];
};
path?: never;
cookie?: never;
};
/** @description Request body */
requestBody: {
content: {
"application/json": {
cart_id: string;
payment_method?: components["schemas"]["PaymentMethodPayload"];
};
};
};
responses: {
/** @description OK */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
message: string;
success: boolean;
content: {
order: components["schemas"]["Order"];
payment_required: boolean;
/** @description Gateway initiation details for the payment. `null` when no gateway payment is started: whenever `payment_required` is `false` (loyalty points, credit balance or discounts leave nothing to pay, or the order is on the customer's credit line), and for a manual payment method (such as cash on delivery) or a bank transfer. */
payment_info: components["schemas"]["JusPayHyperCheckoutResponse"] | components["schemas"]["JusPayExpressCheckoutResponse"] | components["schemas"]["PayuPaymentInfo"] | null;
};
/** @description Analytics events to emit for the change this request made, each with a server-issued `event_id`. Replay them to your analytics destinations so your client-side and server-side copies of the same action dedupe. Empty when the request produced no analytics event. */
events: components["schemas"]["StorefrontResponseEvent"][];
};
};
};
400: components["responses"]["BadRequest"];
401: components["responses"]["Unauthorized"];
/** @description The order uses credit balance, which can't be used at the moment. Nothing is placed; retry shortly. */
409: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
/** @example Paying with credit balance waits for the payment ledger update to finish; try again shortly */
message: string;
/** @default false */
success: boolean;
/** @example credit-balance-unavailable */
code: string;
details?: string;
};
};
};
};
};Component References
| Reference | Resolves To |
|---|---|
components["parameters"]["ProposedEventId"] | ProposedEventId |
components["schemas"]["PaymentMethodPayload"] | PaymentMethodPayload |
components["schemas"]["Order"] | Order |
components["schemas"]["JusPayHyperCheckoutResponse"] | JusPayHyperCheckoutResponse |
components["schemas"]["JusPayExpressCheckoutResponse"] | JusPayExpressCheckoutResponse |
components["schemas"]["PayuPaymentInfo"] | PayuPaymentInfo |
components["schemas"]["StorefrontResponseEvent"] | StorefrontResponseEvent |
components["responses"]["BadRequest"] | BadRequest |
components["responses"]["Unauthorized"] | Unauthorized |
Parameters
- X-CE-Event-ID (header): A ULID you propose as the
event_idof the first entry this request returns inevents. Used only when it is a valid ULID minted within a day of now and not already used; otherwise the server mints one. Theevent_idreturned ineventsis the one to send.
Request Body
Request body
Content Types: application/json
Responses
200
OK
400
Bad request
401
Not authorized for given operation on the Resource
409
The order uses credit balance, which can't be used at the moment. Nothing is placed; retry shortly.
OpenAPI Definition
{
"tags": [
"Orders"
],
"operationId": "create-order",
"summary": "Create order",
"description": "Creates an order from a cart. Returns an `Order` object along with `payment_required` and `payment_info`. When `payment_required` is `true` and `payment_info` is present, use it to initiate the payment flow, then poll `/orders/{order_number}/payment-status` from your return URL. An order that isn't placed on the customer's credit line and that its loyalty points, credit balance or discounts pay in full needs no payment (`payment_required` is `false`). Paid by points or a discount alone, it comes back already `confirmed` (`awaiting_approval` when the store doesn't approve orders automatically; `complete` when it is collected in store with nothing to ship) with `payment_status` `success`; paid by its credit balance, with or without points, it stays `pending` until that balance is settled against it. Credit balance applied to the cart must be within what the customer can spend now, which leaves out credit their other unpaid orders have claimed. When credit balance can't be used for a moment, an order using it fails with a 409 and the `credit-balance-unavailable` error code, and nothing is placed: retry shortly. The payment method must be one the store offers on the token's sales channel (`GET /payments/payment-methods` lists them); any other is refused with a 400. A POS token can't place an order here: the POS places its orders with `POST /pos/orders`.",
"externalDocs": {
"url": "https://llm-docs.commercengine.io/storefront/operations/create-order",
"description": "API reference for the create-order operation"
},
"parameters": [
{
"$ref": "#/components/parameters/ProposedEventId"
}
],
"requestBody": {
"description": "Request body",
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"cart_id"
],
"properties": {
"cart_id": {
"type": "string"
},
"payment_method": {
"$ref": "#/components/schemas/PaymentMethodPayload"
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message",
"success",
"content",
"events"
],
"properties": {
"message": {
"type": "string"
},
"success": {
"type": "boolean"
},
"content": {
"properties": {
"order": {
"$ref": "#/components/schemas/Order"
},
"payment_required": {
"type": "boolean"
},
"payment_info": {
"description": "Gateway initiation details for the payment. `null` when no gateway payment is started: whenever `payment_required` is `false` (loyalty points, credit balance or discounts leave nothing to pay, or the order is on the customer's credit line), and for a manual payment method (such as cash on delivery) or a bank transfer.",
"oneOf": [
{
"$ref": "#/components/schemas/JusPayHyperCheckoutResponse"
},
{
"$ref": "#/components/schemas/JusPayExpressCheckoutResponse"
},
{
"$ref": "#/components/schemas/PayuPaymentInfo"
},
{
"type": "null"
}
]
}
},
"required": [
"order",
"payment_required",
"payment_info"
],
"type": "object"
},
"events": {
"description": "Analytics events to emit for the change this request made, each with a server-issued `event_id`. Replay them to your analytics destinations so your client-side and server-side copies of the same action dedupe. Empty when the request produced no analytics event.",
"type": "array",
"items": {
"$ref": "#/components/schemas/StorefrontResponseEvent"
}
}
}
}
}
},
"links": {
"GetCreatedOrder": {
"operationId": "get-order-detail",
"parameters": {
"order_number": "$response.body#/content/order/order_number"
},
"description": "Retrieve the newly created order."
},
"PollPaymentStatus": {
"operationId": "get-payment-status",
"parameters": {
"order_number": "$response.body#/content/order/order_number"
},
"description": "Poll the payment status of the newly created order."
},
"AuthenticateDirectOtp": {
"operationId": "authenticate-direct-otp",
"requestBody": {
"challenge_id": "$response.body#/content/payment_info/payment/authentication/params/challenge_id",
"txn_id": "$response.body#/content/payment_info/payment/authentication/params/id"
},
"description": "Authenticate with direct OTP when express checkout returns `payment.authentication.params` with `submit_otp_allowed: true`."
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"409": {
"description": "The order uses credit balance, which can't be used at the moment. Nothing is placed; retry shortly.",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"message",
"success",
"code"
],
"properties": {
"message": {
"type": "string",
"examples": [
"Paying with credit balance waits for the payment ledger update to finish; try again shortly"
]
},
"success": {
"type": "boolean",
"default": false
},
"code": {
"type": "string",
"examples": [
"credit-balance-unavailable"
]
},
"details": {
"type": "string"
}
}
}
}
}
}
},
"security": [
{
"Authorization": []
}
],
"x-speakeasy-group": "orders",
"x-speakeasy-ignore": false,
"x-speakeasy-name-override": "createOrder"
}Auto-generated from OpenAPI spec and TypeScript definitions