TheDocumentation Index
Fetch the complete documentation index at: https://docs.tybritelabs.com/llms.txt
Use this file to discover all available pages before exploring further.
OrdersService class (accessed via client.orders) manages the entire commerce lifecycle. All order write operations require mandatory HMAC Security to ensure complete data integrity.
π Security & Signing (HMAC)
To prevent tampering, replay attacks, and duplicate processing of updates,createOrder and updateOrder require both an HMAC-SHA256 signature and a mandatory Idempotency Key.
Signing Process
- Generate Timestamp: Get the current Unix timestamp in seconds.
- Prepare Payload: Concatenate the timestamp and the JSON request body with a dot:
timestamp + "." + JSON_body. - Generate Signature: Compute an HMAC-SHA256 signature of the payload using your HMAC Secret (found in Settings β Integration Settings).
- Base64 Encode: The resulting signature must be Base64 encoded.
Code Implementation (TypeScript/Node.js)
Core Operations
createOrder
Place a new order. Returns 201 Created (semantic create) with the new order resource. Requires verified signatures and idempotency protection.
- Required body fields:
total_amount,payment_method, and a non-emptyitemsarray. Each item requiresproduct_id. - Optional:
customer_id(guest checkout is supported),billing_address,shipping_address(both nullable),variant_idper item (defaults to the productβs primary variant), andgift_card_redemption. - Replay Protection: The
X-Timestampmust be within 5 minutes of the server time. - Post-processing: When
payment_status: "paid"is set, the worker runs gift card redemption, stock reduction, and customer metrics updates. See Post-Processing Warnings below β the response may include apost_processing_warningsarray that clients must check.
Post-Processing Warnings
When an order is created withpayment_status: "paid", the worker runs post-processing in this order:
- Gift card redemption (if
gift_card_redemptionprovided) - Stock reduction per item via atomic RPC
- Customer metrics update via atomic RPC (no lost-update races)
post_processing_warnings array AND the orderβs notes field is stamped with a tag ([GIFT_CARD_REDEMPTION_FAILED] or [STOCK_REDUCTION_PARTIAL]). Clients MUST check this array and route failures to a support or retry flow.
Response shape
Handling pattern
Customer metrics (
total_purchases, lifetime value) are incremented via the atomic increment_customer_purchase_stats RPC. This eliminates lost-update races under concurrent order load, so purchase counts remain correct at high throughput. This is transparent to clients.getOrder
Retrieve complete details for a specific order.
updateOrder
Update fulfillment or payment status. Requires HMAC signature and Idempotency Key.
- Idempotency: Use a unique key for each distinct update (e.g.,
update-payment-{order_id}-{timestamp}). - Protection: This prevents double-triggering side effects like accounting entries or inventory reduction on network retries.
Security & Error Handling
| Error Code | Meaning | Resolution |
|---|---|---|
401 Unauthorized | Invalid HMAC signature | Verify your secret key and payload concatenation. |
401 Unauthorized | Missing X-Timestamp | Ensure the X-Timestamp header is sent. |
401 Unauthorized | Expired Timestamp | Ensure your server clock is synced (5-min window). |
403 Forbidden | Publishable Key Used | Create orders using a Secret Key only. |
Side Effects of payment_status: 'paid'
Transitioning an order to the paid state automatically triggers:
- Inventory Sync: Live stock reduction across variants.
- Accounting Engine: Double-entry bookkeeping entry creation.
- LTV Update: Increments customer lifetime value and purchase counts (via atomic RPC β safe under concurrent load).
- Promoter Logic: Marks loyalty points and promotion usage as finalized.
Response Codes
| Code | Endpoint | Meaning |
|---|---|---|
201 | POST /v1/orders | Order created. Response includes post_processing_warnings? if any post-paid step failed. |
200 | GET /v1/orders/{id}, PATCH /v1/orders/{id} | Success. PATCH returns the updated order. |
400 | All | Invalid request body β missing total_amount / payment_method / items, per-item missing product_id, or invalid tax/subtotal for a tax-exclusive store. |
401 | All | Invalid API key, or invalid / expired HMAC signature. |
403 | Read & write | Publishable key used on an order endpoint. Orders are secret-key only. |
404 | All | Order not found, or a product_id referenced in items not found. |
409 | POST /v1/orders | Idempotency key reused with a different payload. |
429 | POST / PATCH | Rate limit exceeded (100/hr per key). |
500 | All | Server error. |

