Skip to main content

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โ€‹

StatusMeaningWhen to Use
pendingOrder created, awaiting paymentJust placed, payment not processed
processingPayment received, preparing itemsPayment confirmed, packing items
confirmedOrder confirmed, ready to shipPayment cleared, order verified
shippedOrder dispatched to customerPackage sent via carrier
deliveredOrder received by customerDelivery confirmed
completedOrder finished, no action neededTransaction complete
cancelledOrder cancelledCustomer/admin cancelled
refundedPayment returned to customerRefund processed
failedPayment or processing failedPayment declined

Common Order Operationsโ€‹

OperationDescriptionExample Use Case
Create OrderConvert cart to orderCheckout button clicked
Get OrdersList all orders (paginated)Admin dashboard
Get Order by IDFetch specific orderView order details
Update StatusChange order statusMark as shipped
Process PaymentHandle payment transactionCharge credit card
Calculate TotalsCompute tax, shipping, totalCheckout summary
Cancel OrderCancel pending orderCustomer requests cancellation
Refund OrderReturn payment to customerProduct return

Why Use Orders Module?โ€‹

BenefitDescription
Automated Order ManagementNo manual tracking, everything automated
Payment IntegrationStripe, PayPal, other gateways built-in
Status TrackingReal-time order status updates
Customer NotificationsAuto-send order confirmations, shipping updates
Inventory ManagementAuto-deduct stock on order
Analytics & ReportingSales reports, revenue tracking
SecurityPCI-compliant payment processing

๐Ÿ“‹ What You Need to Knowโ€‹

1. Orders are Created from Cart Dataโ€‹

You need to provide:

  1. Customer information - Name, email, phone
  2. Order items - Products, quantities, prices
  3. Shipping address - Delivery location
  4. 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โ€‹

MethodDescriptionReturnsUse Case
createOrder()Create new orderPromise<Order>Checkout process
getOrders()Get all orders (paginated)Promise<{ items: Order[], total }>Admin dashboard
getOrderById()Get specific orderPromise<Order>View order details
updateOrderStatus()Update order statusPromise<Order>Mark as shipped
processPayment()Process payment transactionPromise<Payment>Charge customer
cancelOrder()Cancel orderPromise<Order>Customer cancellation
refundOrder()Refund order paymentPromise<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:โ€‹

  1. Validate cart before creating order - Check stock availability
  2. Calculate totals on server - Never trust client-side calculations
  3. Send order confirmations - Email customers after order placed
  4. Track order status - Update status as order progresses
  5. Handle payment failures - Retry logic, clear error messages
  6. Implement order search - Let customers find their orders easily
  7. Store order history - Keep records for customer service
  8. Use pagination - Don't load all orders at once

โŒ DON'T:โ€‹

  1. Don't create orders without payment - Verify payment first
  2. Don't expose payment details - Use tokenization
  3. Don't skip validation - Always validate customer data
  4. Don't forget notifications - Send order status updates
  5. Don't ignore inventory - Check stock before order
  6. Don't hardcode tax rates - Use location-based calculation
  7. Don't forget error handling - Handle payment failures gracefully
  8. 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"
}
);