Orders Reference

Orders are created exclusively via payment provider webhooks. You cannot create orders directly via API. This reference documents the Order entity structure and read-only operations.

Order Status Flow

Status Meanings:

  • paid - Payment received, awaiting fulfillment
  • fulfilled - Order shipped and completed
  • cancelled - Order cancelled before fulfillment
  • refunded - Payment refunded to customer

Note: Unlike traditional e-commerce systems, there is no pending status. Orders go directly to paid when payment succeeds.

Order Entity Fields

Identification Fields

FieldTypeDescription
iduuidUnique order ID
orderNumberstringHuman-readable order number (e.g., "ORD-000042")
storeIduuidParent store
customerIduuidCustomer who placed order

Financial Fields

FieldTypeDescription
subtotaldecimalTotal before tax/shipping
taxdecimalTax amount
taxRatedecimalApplied tax rate (e.g., 0.08 for 8%)
shippingdecimalShipping cost
discountdecimalTotal discount applied
discountCodestringPromo code used (if any)
totaldecimalFinal total
currencystringISO 4217 currency code (e.g., "USD")

Status Fields

FieldTypeValuesDescription
statusenumpending, paid, fulfilled, cancelledOrder status
paymentStatusenumpending, processing, succeeded, failed, refunded, partially_refunded, cancelledPayment status

Payment Provider Fields

FieldTypeDescription
paymentProviderstring"stripe", "paypal", or "square"
paymentIdstringProvider's transaction ID (e.g., Stripe PaymentIntent ID)
paymentMethodstringCard type, PayPal wallet, etc.
paymentDetailsjsonProvider-specific metadata (see below)

paymentDetails examples:

// Stripe
{
  "last4": "4242",
  "brand": "visa",
  "expMonth": 12,
  "expYear": 2025
}
 
// PayPal
{
  "email": "buyer@example.com",
  "payerStatus": "verified"
}
 
// Square
{
  "last4": "1111",
  "cardBrand": "VISA"
}

Address Snapshots (JSON)

Addresses are stored as JSON snapshots because customer addresses may change later.

FieldTypeDescription
shippingAddressjsonAddress where order ships to
billingAddressjsonAddress on payment method

Address structure:

{
  "firstName": "John",
  "lastName": "Doe",
  "address1": "123 Main St",
  "address2": null,
  "city": "San Francisco",
  "region": "CA",
  "postalCode": "94103",
  "country": "US",
  "company": null,
  "phone": "+1-555-0123"
}

Timeline Fields

FieldTypeDescription
placedAtdatetimeWhen order was finalized
paidAtdatetimeWhen payment succeeded
fulfilledAtdatetimeWhen shipped/completed
cancelledAtdatetimeWhen cancelled
createdAtdatetimeWhen order was created (immutable)
updatedAtdatetimeLast update time

Notes

FieldTypeDescription
customerNotestringNote customer entered at checkout
merchantNotestringInternal merchant notes (editable)

Order Items

FieldTypeDescription
itemsarrayArray of OrderItem objects (see below)

Order Item Fields

Each order contains line items:

{
  "id": "item_123",
  "orderId": "order_456",
  "productId": "prod_789",
  "titleSnapshot": "Blue Shirt",
  "skuSnapshot": "BLUE-SHIRT-001",
  "quantity": 2,
  "unitPrice": "39.99",
  "variantTitle": "Blue / Medium",
  "attributesSnapshot": {
    "color": "blue",
    "size": "m"
  },
  "lineDiscount": "0.00",
  "primaryImageId": "media_abc"
}
FieldTypeDescription
iduuidItem ID
orderIduuidParent order
productIduuidLink to product
titleSnapshotstringProduct title at purchase time
skuSnapshotstringSKU at purchase time
quantityintegerQuantity ordered
unitPricedecimalPrice per unit (at purchase)
variantTitlestringVariant description (e.g., "Blue / Medium")
attributesSnapshotjsonProduct attributes (color, size, etc.)
lineDiscountdecimalPer-line discount
primaryImageIdstringProduct image ID at purchase

Example Response

{
  "item": {
    "id": "order_abc123def456",
    "orderNumber": "ORD-000042",
    "customerId": "cust_xyz789",
    "storeId": "store_123",
    "subtotal": "79.98",
    "tax": "6.40",
    "taxRate": "0.08",
    "shipping": "10.00",
    "discount": "6.39",
    "discountCode": "SAVE10",
    "total": "89.99",
    "currency": "USD",
    "status": "paid",
    "paymentStatus": "succeeded",
    "paymentProvider": "stripe",
    "paymentId": "pi_1ABC123XYZ",
    "paymentMethod": "card",
    "paymentDetails": {
      "last4": "4242",
      "brand": "visa",
      "expMonth": 12,
      "expYear": 2025
    },
    "shippingAddress": {
      "firstName": "John",
      "lastName": "Doe",
      "address1": "123 Main St",
      "address2": null,
      "city": "San Francisco",
      "region": "CA",
      "postalCode": "94103",
      "country": "US",
      "company": null,
      "phone": "+1-555-0123"
    },
    "billingAddress": {
      "firstName": "John",
      "lastName": "Doe",
      "address1": "123 Main St",
      "address2": null,
      "city": "San Francisco",
      "region": "CA",
      "postalCode": "94103",
      "country": "US"
    },
    "customerNote": "Please leave at door",
    "merchantNote": "VIP customer - priority shipping",
    "placedAt": "2024-01-15T10:30:00Z",
    "paidAt": "2024-01-15T10:30:05Z",
    "fulfilledAt": null,
    "cancelledAt": null,
    "items": [
      {
        "id": "item_1",
        "productId": "prod_abc",
        "titleSnapshot": "Blue Shirt",
        "skuSnapshot": "BLUE-SHIRT-001",
        "quantity": 2,
        "unitPrice": "39.99",
        "variantTitle": "Blue / Medium",
        "attributesSnapshot": {
          "color": "blue",
          "size": "m"
        },
        "lineDiscount": "0.00",
        "primaryImageId": "media_xyz"
      },
      {
        "id": "item_2",
        "productId": "prod_def",
        "titleSnapshot": "T-Shirt",
        "skuSnapshot": "TSHIRT-001",
        "quantity": 1,
        "unitPrice": "24.99",
        "variantTitle": null,
        "attributesSnapshot": {},
        "lineDiscount": "6.39",
        "primaryImageId": "media_123"
      }
    ],
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-01-15T10:30:05Z"
  }
}

API Operations

List Orders

Endpoint: GET /api/stores/{storeId}/orders

Query Parameters:

ParameterTypeDescription
statusstringFilter by status: pending, paid, fulfilled, cancelled
paymentStatusstringFilter by payment status
customerIdstringFilter by customer ID
orderNumberstringFilter by order number
limitintegerPage size (1-200, default 50)
offsetintegerSkip count (default 0)

Examples:

# List all paid orders
curl https://api.barecommercecore.com/api/stores/{storeId}/orders?status=paid \
  -H "X-API-Key: sk_live_your_key"
 
# List orders by customer
curl https://api.barecommercecore.com/api/stores/{storeId}/orders?customerId={customerId} \
  -H "X-API-Key: sk_live_your_key"
 
# Search by order number
curl https://api.barecommercecore.com/api/stores/{storeId}/orders?orderNumber=ORD-000042 \
  -H "X-API-Key: sk_live_your_key"
 
# Paginated request
curl "https://api.barecommercecore.com/api/stores/{storeId}/orders?limit=20&offset=40" \
  -H "X-API-Key: sk_live_your_key"

Response: 200 OK

{
  "items": [...array of orders...],
  "total": 150
}

Get Single Order

Endpoint: GET /api/stores/{storeId}/orders/{orderId}

curl https://api.barecommercecore.com/api/stores/{storeId}/orders/{orderId} \
  -H "X-API-Key: sk_live_your_key"

Response: 200 OK - Full order object (see example above)

Record a Refund

Endpoint: POST /api/stores/{storeId}/orders/{orderId}/refund

This endpoint records a refund for merchant tracking. For actual refund processing, use your payment provider's API.

Request:

{
  "amount": "39.99",
  "reason": "Customer requested",
  "refundId": "re_1ABC123"
}

Fields:

  • amount (required) - Refund amount
  • reason (optional) - Reason for refund
  • refundId (optional) - Provider's refund ID (from Stripe, PayPal, etc.)

Example:

curl -X POST https://api.barecommercecore.com/api/stores/{storeId}/orders/{orderId}/refund \
  -H "X-API-Key: sk_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": "39.99",
    "reason": "Customer request",
    "refundId": "re_1ABC123"
  }'

Response: 200 OK

{
  "item": {
    "refundId": "ref_123",
    "amount": "39.99",
    "recordedAt": "2024-01-15T10:35:00Z"
  }
}

Common Tasks

Get Total Revenue for Period

// List all paid orders (adjust filters as needed)
const response = await fetch(
  'https://api.barecommercecore.com/api/stores/{storeId}/orders?status=paid&limit=200',
  { headers: { 'X-API-Key': apiKey } }
);
 
const { items } = await response.json();
 
// Sum totals
const revenue = items.reduce((sum, order) => 
  sum + parseFloat(order.total), 0
);
 
console.log(`Total revenue: $${revenue.toFixed(2)}`);

Get Orders by Date Range

// List recent orders
const orders = await fetchOrders({ status: 'paid', limit: 100 });
 
// Filter by date (BareCommerce doesn't support date filters in API)
const startDate = new Date('2024-01-01');
const endDate = new Date('2024-01-31');
 
const january = orders.filter(order => {
  const date = new Date(order.placedAt);
  return date >= startDate && date <= endDate;
});
 
console.log(`Orders in January: ${january.length}`);

Get Customer Order History

const customerId = 'cust_123';
 
const response = await fetch(
  `https://api.barecommercecore.com/api/stores/{storeId}/orders?customerId=${customerId}`,
  { headers: { 'X-API-Key': apiKey } }
);
 
const { items: customerOrders } = await response.json();
 
console.log(`Customer has ${customerOrders.length} orders`);
console.log(`Total spent: $${
  customerOrders.reduce((sum, o) => sum + parseFloat(o.total), 0).toFixed(2)
}`);

Process Fulfilled Orders

const fulfilled = await fetch(
  'https://api.barecommercecore.com/api/stores/{storeId}/orders?status=fulfilled',
  { headers: { 'X-API-Key': apiKey } }
);
 
const { items } = await fulfilled.json();
 
for (const order of items) {
  // Send shipment tracking to customer
  await sendTrackingEmail(order.customerId, order.orderNumber);
}

Important Notes

  • Orders are read-only - You cannot create or update orders via API (except merchantNote)
  • Orders are immutable - Once created, order data doesn't change (except status and merchantNote)
  • Payment is authoritative - Trust paymentStatus and paymentProvider as the source of truth
  • Addresses are snapshots - Stored as JSON because customer data may change
  • Items are snapshots - Product prices/details at purchase time, not current
  • No pending status - Orders go straight to paid when payment succeeds

Next Steps