Skip to main content

Order Placement

Overview

Order placement is the final step in the ecommerce journey where a customer's basket is converted into a confirmed order. This process involves comprehensive validation, payment processing, inventory management, and order creation with proper error handling and customer communication.

Order Placement Flow

1. Pre-Placement Validation

  • Basket Validation: Verify basket contents and availability
  • Customer Validation: Validate customer information and authentication
  • Payment Validation: Verify payment method and authorization
  • Delivery Validation: Confirm delivery method and address

2. Order Processing

  • Inventory Reservation: Reserve products and check stock
  • Price Calculation: Final price calculation with all factors
  • Order Creation: Create order record in database
  • Payment Processing: Process payment through payment gateway

3. Post-Placement Actions

  • Inventory Update: Update product stock levels
  • Email Notifications: Send confirmation emails
  • Order Tracking: Generate tracking information
  • Analytics Update: Update order analytics

Order Placement Components

Order Placement Service

The Order Placement Service is responsible for:

  • Processing order placement requests
  • Validating order data
  • Managing the order creation workflow
  • Handling post-placement actions

Key Methods:

  • placeOrder() - Main order placement method
  • validateOrderPlacement() - Validate order data
  • processOrderPlacement() - Process the order

Order Placement Validator

The Order Placement Validator ensures:

  • Basket contents are valid
  • Customer information is complete
  • Delivery information is accurate
  • Payment information is valid
  • Business rules are followed

Validation Areas:

  • Basket validation
  • Customer information validation
  • Delivery information validation
  • Payment information validation
  • Business rules validation

Order Placement API

POST /order/place

Purpose: Place order from basket

Request Headers:

  • store: Web store identifier (required)
  • basket-token: Basket session token (required)
  • Authorization: User authentication token (optional)

Request Body:

{
"shippingName": "John Doe",
"shippingEmail": "john@example.com",
"shippingPhone": "+37251234567",
"shippingAddress": "123 Main St",
"shippingCity": "Tallinn",
"shippingPostcode": "10115",
"shippingCountryNavCode": "EE",
"billingName": "John Doe",
"billingEmail": "john@example.com",
"billingPhone": "+37251234567",
"billingAddress": "123 Main St",
"billingCity": "Tallinn",
"billingPostcode": "10115",
"billingCountryNavCode": "EE",
"deliveryMethodId": 1,
"paymentMethodId": 2,
"notes": "Please deliver after 6 PM",
"termsAccepted": true,
"newsletterSubscription": false,
"marketingConsent": true
}

Response:

{
"success": true,
"order": {
"orderId": 12345,
"referenceNumber": "ORD-2024-001",
"status": "confirmed",
"totalAmount": 82.96,
"deliveryAmount": 2.99,
"discountAmount": 10.00,
"estimatedDelivery": "2024-01-15",
"paymentStatus": "paid",
"trackingNumber": "EE123456789EE"
},
"redirectUrl": "https://payment-gateway.com/checkout/12345",
"message": "Order placed successfully"
}

GET /order/status/{orderId}

Purpose: Check order status

Response:

{
"orderId": 12345,
"referenceNumber": "ORD-2024-001",
"status": "processing",
"statusDescription": "Order is being processed",
"estimatedDelivery": "2024-01-15",
"trackingNumber": "EE123456789EE",
"trackingUrl": "https://tracking.example.com/EE123456789EE",
"lastUpdate": "2024-01-10T14:30:00Z"
}

Order Creation Process

1. Order Record Creation

The Order Creator service handles:

  • Basic order information setup
  • Shipping information setup
  • Billing information setup
  • Delivery and payment setup
  • Order amounts calculation
  • Status initialization
  • Notes and preferences

Process Flow:

  1. Create new order instance
  2. Set basic order information
  3. Set shipping information
  4. Set billing information
  5. Set delivery and payment details
  6. Calculate order amounts
  7. Set initial status
  8. Save order to database

2. Order Products Creation

The Order Product Creator manages:

  • Order product creation
  • Product information setup
  • Pricing information setup
  • Database saving

Process Flow:

  1. Iterate through basket items
  2. Create order product records
  3. Set product information
  4. Set pricing details
  5. Save to database

3. Inventory Reservation

The Inventory Reservation Service ensures:

  • Inventory availability check
  • Stock reservation logic
  • Stock level updates
  • Error handling

Process Flow:

  1. Check available stock
  2. Validate quantity requirements
  3. Reserve inventory
  4. Update stock levels
  5. Handle insufficient stock errors

Payment Processing

The Payment Processor handles:

  • Payment method selection
  • Payment gateway initialization
  • Payment request creation
  • Payment processing
  • Payment record creation

Process Flow:

  1. Get payment method details
  2. Initialize payment gateway
  3. Create payment request
  4. Process payment
  5. Create payment record
  6. Handle payment results

Post-Placement Actions

1. Email Notifications

The Order Notification Service manages:

  • Order confirmation emails
  • Admin notification emails
  • Email composition
  • Email sending

Email Types:

  • Customer order confirmation
  • Admin order notification
  • Shipping updates
  • Delivery confirmations

2. Order Tracking Setup

The Order Tracking Service handles:

  • Tracking number generation
  • Tracking record creation
  • Order updates
  • Database operations

Tracking Features:

  • Unique tracking number generation
  • Tracking record creation
  • Order status updates
  • Customer notifications

3. Analytics Update

The Order Analytics Service manages:

  • Analytics data updates
  • Performance metrics
  • Customer insights
  • Business intelligence

Analytics Areas:

  • Order counts
  • Revenue metrics
  • Product performance
  • Customer metrics

Error Handling

Common Order Placement Errors

  • Basket Validation Errors: Invalid basket contents
  • Customer Information Errors: Missing or invalid customer data
  • Payment Processing Errors: Payment gateway failures
  • Inventory Errors: Insufficient stock
  • System Errors: Database or service failures

Error Response Format

{
"success": false,
"errorCode": "PAYMENT_PROCESSING_ERROR",
"errorMessage": "Payment processing failed",
"details": {
"orderId": 12345,
"paymentMethod": "credit_card",
"gatewayError": "Insufficient funds"
},
"suggestions": [
"Try a different payment method",
"Contact your bank for assistance",
"Verify your payment information"
]
}

Error Recovery

  • Automatic Retry: Retry failed operations
  • Partial Success Handling: Handle partial order creation
  • Rollback Mechanisms: Rollback failed transactions
  • Customer Communication: Inform customers of issues

Order Status Management

Order Status Flow

Pending → Processing → Confirmed → Shipped → Delivered

Status Transitions

  • Pending: Order created, awaiting payment
  • Processing: Payment received, order being processed
  • Confirmed: Order confirmed, inventory allocated
  • Shipped: Order shipped, tracking available
  • Delivered: Order delivered to customer

Status Update Triggers

  • Payment Success: Pending → Processing
  • Inventory Allocation: Processing → Confirmed
  • Shipping: Confirmed → Shipped
  • Delivery Confirmation: Shipped → Delivered

Security and Validation

Input Validation

  • Customer Data: Validate all customer information
  • Payment Data: Secure payment information handling
  • Address Validation: Verify shipping and billing addresses
  • Business Rules: Enforce business logic and restrictions

Fraud Prevention

  • Order Validation: Validate order patterns
  • Payment Verification: Verify payment authenticity
  • Address Verification: Verify address validity
  • Risk Scoring: Calculate order risk scores

Data Protection

  • Customer Privacy: Protect customer information
  • Payment Security: Secure payment processing
  • Order Confidentiality: Maintain order privacy
  • Compliance: GDPR and local compliance

Performance Optimization

Database Optimization

  • Transaction Management: Efficient transaction handling
  • Query Optimization: Optimized database queries
  • Connection Pooling: Database connection management
  • Caching: Cache frequently accessed data

API Performance

  • Response Time: Optimize API response times
  • Concurrent Processing: Handle multiple orders
  • Resource Management: Efficient resource usage
  • Load Balancing: Distribute order processing load

Testing and Monitoring

Test Scenarios

  • Successful Order Placement: Complete order flow
  • Validation Errors: Various validation scenarios
  • Payment Failures: Payment processing failures
  • System Errors: Database and service failures

Performance Monitoring

  • Order Processing Time: Monitor order placement speed
  • Success Rates: Track order placement success
  • Error Rates: Monitor error frequencies
  • System Resources: Monitor system performance

Monitoring Tools

  • Application Logs: Comprehensive order logging
  • Performance Metrics: Real-time performance data
  • Error Tracking: Error monitoring and alerting
  • Business Metrics: Order and revenue tracking