Skip to main content

Place Order with Payment (Customer)

Creates a new order and initiates payment processing. Returns a client secret for completing payment on the client side (e.g., using Stripe).

Request Body

customerId
string (uuid)
required
Customer identifier (must match authenticated user)
deliveryMethodId
string (uuid)
required
Selected delivery method identifier
deliveryAddress
object
required
Delivery address details
items
array
required
Array of order items (productId, quantity, variantId if applicable)
notes
string
Optional order notes or special instructions

Response

orderId
string (uuid)
Created order identifier
clientSecret
string
Payment client secret for completing payment (e.g., Stripe client secret)
totalAmount
number
Total order amount

Response Codes

  • 200 OK - Order created, payment initiated
  • 400 Bad Request - Invalid order data or insufficient stock
  • 404 Not Found - Customer, delivery method, or product not found
  • 500 Internal Server Error - Payment processing error

Examples

curl -X POST "https://your-server.com/api/orders/with-payment" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "customer-uuid",
    "deliveryMethodId": "delivery-method-uuid",
    "deliveryAddress": {
      "street": "123 Main St",
      "city": "New York",
      "state": "NY",
      "zipCode": "10001",
      "country": "USA"
    },
    "items": [
      {
        "productId": "product-uuid-1",
        "quantity": 2,
        "variantId": null
      },
      {
        "productId": "product-uuid-2",
        "quantity": 1,
        "variantId": "variant-uuid"
      }
    ],
    "notes": "Please ring doorbell upon delivery"
  }'

Success Response Example

{
  "orderId": "order-uuid",
  "clientSecret": "pi_1234567890_secret_abcdefghijklmnop",
  "totalAmount": 459.98
}

Error Response Examples

Insufficient Stock (400 Bad Request):
"Product 'Premium Headphones' has insufficient stock. Available: 1, Requested: 2"
Invalid Delivery Method (404 Not Found):
"Delivery method not found"
Payment Processing Error (500 Internal Server Error):
"Failed to initialize payment: [error details]"

Place Order without Payment (Customer)

Creates an order for cash-on-delivery or other non-prepaid payment methods.

Request Body

customerId
string (uuid)
required
Customer identifier
deliveryMethodId
string (uuid)
required
Selected delivery method identifier
deliveryAddress
object
required
Delivery address details
items
array
required
Array of order items
notes
string
Optional order notes

Response Codes

  • 204 No Content - Order created successfully
  • 400 Bad Request - Invalid order data
  • 404 Not Found - Customer, delivery method, or product not found

Examples

curl -X POST "https://your-server.com/api/orders" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "customer-uuid",
    "deliveryMethodId": "delivery-method-uuid",
    "deliveryAddress": {
      "street": "123 Main St",
      "city": "New York",
      "state": "NY",
      "zipCode": "10001",
      "country": "USA"
    },
    "items": [
      {
        "productId": "product-uuid",
        "quantity": 1
      }
    ]
  }'

Mark Order as Paid (Customer)

Marks an order as paid after successful payment confirmation. Typically called after payment provider confirms payment.

Path Parameters

orderId
string (uuid)
required
Order identifier

Response Codes

  • 204 No Content - Order marked as paid
  • 400 Bad Request - Order already paid or payment failed

Examples

curl -X PATCH "https://your-server.com/api/orders/order-uuid/paid" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Error Response Examples

Already Paid (400 Bad Request):
"Order has already been marked as paid"

Order Creation Flow

1

Add Items to Cart

Customer browses products and adds items to shopping cart
2

Proceed to Checkout

Customer reviews cart and proceeds to checkout
3

Select Delivery

Customer selects delivery method and provides delivery address
4

Choose Payment Method

Customer chooses online payment or cash-on-delivery
5

Create Order

Call /api/orders/with-payment (online) or /api/orders (COD)
6

Complete Payment (if online)

Use client secret to complete payment with payment provider
7

Confirm Payment

Call /api/orders/{orderId}/paid after payment success
8

Order Confirmation

Customer receives order confirmation and tracking information

Order Validation

The system validates all order items before creation:
  • Product availability
  • Stock levels
  • Price accuracy
  • Delivery method compatibility
Orders cannot be modified after creation. Customers must cancel and create a new order for changes.

Payment Integration

The order creation with payment typically integrates with payment providers like Stripe:
  1. Server creates order and payment intent
  2. Server returns client secret
  3. Client uses secret to complete payment
  4. Payment provider confirms payment
  5. Client calls /paid endpoint to finalize order

Stripe Example

// 1. Create order and get client secret
const orderResponse = await fetch('/api/orders/with-payment', {...});
const { orderId, clientSecret } = await orderResponse.json();

// 2. Confirm payment with Stripe
const stripe = Stripe('pk_test_...');
const { error, paymentIntent } = await stripe.confirmCardPayment(clientSecret, {
  payment_method: {
    card: cardElement,
    billing_details: { name: 'Customer Name' }
  }
});

// 3. Mark order as paid
if (paymentIntent.status === 'succeeded') {
  await fetch(`/api/orders/${orderId}/paid`, {
    method: 'PATCH',
    headers: { 'Authorization': `Bearer ${token}` }
  });
}

Build docs developers (and LLMs) love