Introduction
๐ฏ What does this module do?โ
The Orders module lets you create, manage, and track customer orders - from shopping cart checkout to payment processing and order fulfillment - handling the complete e-commerce order lifecycle.
Think of it as your order management system - customers add items to cart, place orders, make payments, and you track everything from order creation to delivery, all within OneEntry.
๐ Simple Explanationโ
Every e-commerce application needs order management:
- ๐ Shopping Cart - Users add products, proceed to checkout
- ๐ Order Creation - Convert cart to order with customer details
- ๐ณ Payment Processing - Accept payments (credit card, PayPal, etc.)
- ๐ฆ Order Tracking - Track status (pending, processing, shipped, delivered)
- ๐ Order Management - View all orders, filter by status, search
- ๐งพ Order Details - View line items, totals, customer info
The problem with manual order management:
// โ Bad - Manual tracking
const orders = {
order1: { items: [...], total: 99.99, status: 'pending' },
order2: { items: [...], total: 149.99, status: 'shipped' }
};
// No payment processing, no proper tracking, no status updates
Issues:
- ๐ No payment integration - Manual payment tracking
- ๐ Poor tracking - Hard to find orders, filter by status
- ๐ No automation - Manual status updates, no notifications
- ๐ธ No tax/shipping calculation - Calculate manually
The Orders solution:
// โ
Good - Automated order management
const order = await Orders.createOrder({
items: cart.items,
customer: userInfo,
shippingAddress: address,
paymentMethod: 'card'
});
// Order automatically:
// - Calculates totals, tax, shipping
// - Creates order record
// - Processes payment
// - Sends confirmation email
// - Tracks status
Benefits:
- ๐ Integrated payments - Stripe, PayPal, other gateways
- ๐ Advanced tracking - Filter, search, export orders
- ๐ Automated workflows - Status updates, notifications
- ๐ธ Auto-calculations - Tax, shipping, discounts
โจ Key Conceptsโ
What is an Order?โ
An Order is a customer purchase transaction containing:
- Order Items - Products/services being purchased (quantity, price)
- Customer Information - Name, email, phone
- Shipping Address - Delivery location
- Billing Address - Payment billing info
- Payment Details - Payment method, transaction ID
- Order Totals - Subtotal, tax, shipping, total
- Order Status - Current state (pending, processing, completed)
- Timestamps - Created, updated, completed dates
Order Structureโ
Each order has this structure:
{
id: "ORD-2024-001", // Unique order ID
orderNumber: "1001", // Human-readable number
status: "processing", // Order status
customer: {
name: "John Doe",
email: "john@example.com",
phone: "+1-555-0123"
},
items: [ // Order line items
{
productId: 123,
name: "Laptop",
quantity: 1,
price: 999.99,
subtotal: 999.99
},
{
productId: 456,
name: "Mouse",
quantity: 2,
price: 29.99,
subtotal: 59.98
}
],
shippingAddress: {
street: "123 Main St",
city: "New York",
state: "NY",
zip: "10001",
country: "USA"
},
totals: {
subtotal: 1059.97,
tax: 84.80,
shipping: 15.00,
discount: 0,
total: 1159.77
},
payment: {
method: "credit_card",
status: "paid",
transactionId: "ch_abc123",
paidAt: "2024-01-15T10:30:00Z"
},
createdAt: "2024-01-15T10:25:00Z",
updatedAt: "2024-01-15T10:30:00Z"
}
Order Lifecycleโ
1. Customer adds items to cart
โ
2. Proceeds to checkout
โ
3. Enters shipping/billing info
โ
4. Selects payment method
โ
5. Order created (status: pending)
โ
6. Payment processed (status: processing)
โ
7. Order confirmed (status: confirmed)
โ
8. Items prepared (status: processing)
โ
9. Order shipped (status: shipped)
โ
10. Order delivered (status: completed)
Order Statusesโ
| Status | Meaning | When to Use |
|---|---|---|
| pending | Order created, awaiting payment | Just placed, payment not processed |
| processing | Payment received, preparing items | Payment confirmed, packing items |
| confirmed | Order confirmed, ready to ship | Payment cleared, order verified |
| shipped | Order dispatched to customer | Package sent via carrier |
| delivered | Order received by customer | Delivery confirmed |
| completed | Order finished, no action needed | Transaction complete |
| cancelled | Order cancelled | Customer/admin cancelled |
| refunded | Payment returned to customer | Refund processed |
| failed | Payment or processing failed | Payment declined |
Common Order Operationsโ
| Operation | Description | Example Use Case |
|---|---|---|
| Create Order | Convert cart to order | Checkout button clicked |
| Get Orders | List all orders (paginated) | Admin dashboard |
| Get Order by ID | Fetch specific order | View order details |
| Update Status | Change order status | Mark as shipped |
| Process Payment | Handle payment transaction | Charge credit card |
| Calculate Totals | Compute tax, shipping, total | Checkout summary |
| Cancel Order | Cancel pending order | Customer requests cancellation |
| Refund Order | Return payment to customer | Product return |
Why Use Orders Module?โ
| Benefit | Description |
|---|---|
| Automated Order Management | No manual tracking, everything automated |
| Payment Integration | Stripe, PayPal, other gateways built-in |
| Status Tracking | Real-time order status updates |
| Customer Notifications | Auto-send order confirmations, shipping updates |
| Inventory Management | Auto-deduct stock on order |
| Analytics & Reporting | Sales reports, revenue tracking |
| Security | PCI-compliant payment processing |
๐ What You Need to Knowโ
1. Orders are Created from Cart Dataโ
You need to provide:
- Customer information - Name, email, phone
- Order items - Products, quantities, prices
- Shipping address - Delivery location
- Payment method - How customer will pay
const orderData = {
customer: { name, email, phone },
items: cartItems,
shippingAddress: address,
paymentMethod: 'credit_card'
};
const order = await Orders.createOrder(orderData);
2. Order Status Managementโ
Track order progress through statuses:
// Update order status
await Orders.updateOrderStatus(orderId, 'shipped');
// Get orders by status
const processingOrders = await Orders.getOrders({
status: 'processing'
});
Common status flows:
- Digital products: pending โ processing โ completed
- Physical products: pending โ processing โ shipped โ delivered โ completed
- Cancelled: any status โ cancelled
- Refunded: completed โ refunded
3. Payment Processingโ
Orders integrate with payment gateways:
// Process payment
const payment = await Orders.processPayment(orderId, {
method: 'credit_card',
cardToken: 'tok_from_stripe',
amount: orderTotal
});
// Check payment status
if (payment.status === 'succeeded') {
await Orders.updateOrderStatus(orderId, 'processing');
}
Supported payment methods:
- Credit/Debit cards (via Stripe, PayPal)
- PayPal
- Bank transfer
- Cash on delivery
- Custom payment gateways
4. Order Totals Calculationโ
OneEntry automatically calculates:
{
subtotal: 1059.97, // Sum of all items
tax: 84.80, // Tax based on location
shipping: 15.00, // Shipping cost
discount: 0, // Applied discounts/coupons
total: 1159.77 // Final amount to charge
}
Formula: total = subtotal + tax + shipping - discount
๐ Quick Reference Tableโ
| Method | Description | Returns | Use Case |
|---|---|---|---|
createOrder() | Create new order | Promise<Order> | Checkout process |
getOrders() | Get all orders (paginated) | Promise<{ items: Order[], total }> | Admin dashboard |
getOrderById() | Get specific order | Promise<Order> | View order details |
updateOrderStatus() | Update order status | Promise<Order> | Mark as shipped |
processPayment() | Process payment transaction | Promise<Payment> | Charge customer |
cancelOrder() | Cancel order | Promise<Order> | Customer cancellation |
refundOrder() | Refund order payment | Promise<Refund> | Product return |
Order Structure:
interface Order {
id: string;
orderNumber: string;
status: OrderStatus;
customer: {
name: string;
email: string;
phone: string;
};
items: OrderItem[];
shippingAddress: Address;
billingAddress: Address;
totals: {
subtotal: number;
tax: number;
shipping: number;
discount: number;
total: number;
};
payment: {
method: string;
status: string;
transactionId: string;
paidAt: string;
};
createdAt: string;
updatedAt: string;
}
๐ก Important Notesโ
โ ๏ธ Orders are Created in OneEntryโ
The Orders module handles the complete order lifecycle:
- โ Create orders from cart data
- โ Process payments
- โ Update order status
- โ Track shipping
- โ Does NOT handle shopping cart UI (you build that)
Your responsibility:
- Build shopping cart interface
- Collect customer information
- Display order confirmation
๐ณ Payment Processingโ
Orders integrate with payment gateways:
- Stripe (recommended)
- PayPal
- Custom gateways via IntegrationCollections
Important:
- Never store credit card details directly
- Use tokenization (Stripe.js, PayPal SDK)
- OneEntry handles secure payment processing
๐ฆ Inventory Managementโ
Orders automatically:
- โ Deduct inventory on order creation
- โ Restore inventory on cancellation
- โ Track stock levels
Best practice: Check stock before creating order
๐ Securityโ
Orders contain sensitive data:
- ๐ Customer personal information
- ๐ Payment details
- ๐ Shipping addresses
Always:
- Use HTTPS for checkout pages
- Validate data before creating orders
- Implement proper authentication
- Follow PCI DSS compliance for payments
๐ Best Practicesโ
โ DO:โ
- Validate cart before creating order - Check stock availability
- Calculate totals on server - Never trust client-side calculations
- Send order confirmations - Email customers after order placed
- Track order status - Update status as order progresses
- Handle payment failures - Retry logic, clear error messages
- Implement order search - Let customers find their orders easily
- Store order history - Keep records for customer service
- Use pagination - Don't load all orders at once
โ DON'T:โ
- Don't create orders without payment - Verify payment first
- Don't expose payment details - Use tokenization
- Don't skip validation - Always validate customer data
- Don't forget notifications - Send order status updates
- Don't ignore inventory - Check stock before order
- Don't hardcode tax rates - Use location-based calculation
- Don't forget error handling - Handle payment failures gracefully
- Don't skip order confirmation - Always show order summary
Definition of the Orders moduleโ
The Orders module manages the creation and payment of goods or services.
The ability to make and pay for goods or services is an integral part of the E-commerce application. In this section, you can familiarize yourself with the principles of working with orders.
More information about the module's user interface https://doc.oneentry.cloud/docs/category/orders
const { Orders } = defineOneEntry( "your-project-url", { "token": "your-app-token" });
๐ Related Documentationโ
- Products Module - Manage products available for purchase
- Users Module - Manage customers who place orders
- IntegrationCollections Module - Payment gateway integrations
- Events Module - Order status notifications