Vendix Ecommerce Checkout Flow
Complete Checkout Flow - From cart to order creation, including shipping and payment.
π― Overview
The ecommerce checkout handles online sales through STORE_ECOMMERCE app. It processes cart items, validates shipping, calculates totals, and creates orders.
π Data Flow
sequenceDiagram
participant FE as Frontend
participant API as POST /ecommerce/checkout
participant Cart as CartService
participant Ship as ShippingRates
participant Pay as PaymentMethods
participant DB as Database
FE->>API: CheckoutRequest
API->>Cart: getCart()
API->>Ship: validate rate (if provided)
API->>Pay: validate payment method
API->>DB: create order + items + payment
API->>Cart: clearCart()
API-->>FE: { order_id, order_number, total }
π§ Backend Components
CheckoutDto
// apps/backend/src/domains/ecommerce/checkout/dto/checkout.dto.ts
export class CheckoutDto {
@IsOptional() @IsInt() shipping_method_id?: number;
@IsOptional() @IsInt() shipping_rate_id?: number;
@IsOptional() @IsInt() shipping_address_id?: number;
@IsOptional() @IsObject() shipping_address?: ShippingAddressDto;
@IsInt() payment_method_id: number;
@IsOptional() @IsString() notes?: string;
}
CheckoutService Key Steps
- Get Cart - Retrieve cart with items
- Validate Payment Method - Check enabled and belongs to store
- Validate Stock - Ensure all items have sufficient stock
- Process Address - Create new or use existing
- Validate Shipping - Check rate/method if provided
- Calculate Totals - subtotal + shipping_cost = grand_total
- Create Order - With items, addresses, shipping info
- Create Payment - Pending payment record
- Update Stock - Decrement quantities
- Clear Cart - Remove cart items
π Frontend Components
Key Files
| File | Purpose |
|---|---|
checkout.component.ts | Main checkout page component |
checkout.service.ts | API calls for checkout |
cart.service.ts | Cart management + shipping estimates |
CheckoutRequest Interface
export interface CheckoutRequest {
shipping_address_id?: number;
shipping_address?: AddressDto;
shipping_method_id?: number;
shipping_rate_id?: number;
payment_method_id: number;
notes?: string;
}
Checkout Steps UI
- Address Selection - Pick existing or enter new
- Shipping Method - Load options via
getShippingEstimates() - Payment Method - Select from store's enabled methods
- Confirmation - Review and place order
π¦ Database Models
orders
model orders {
id Int
store_id Int
customer_id Int?
order_number String
channel order_channel_enum // 'pos' | 'ecommerce' | 'agent' | 'whatsapp' | 'marketplace'
shipping_address_id Int?
shipping_method_id Int?
shipping_cost Decimal
subtotal_amount Decimal
grand_total Decimal
state order_state_enum
// ... relationships
}
Note: The
channelfield is auto-assigned:
'ecommerce'- Orders from CheckoutService (online storefront)'pos'- Orders from PaymentsService.processPosPayment (point of sale)
Related Models
cart_items- Items being purchasedshipping_methods- Delivery optionsshipping_rates- Zone-specific pricingstore_payment_methods- Enabled payments
β οΈ Error Handling
| Error | Cause | Message |
|---|---|---|
| 400 | Empty cart | "Cart is empty" |
| 400 | Invalid payment | "Invalid payment method" |
| 400 | Stock issue | "Insufficient stock for {product}" |
| 400 | Bad shipping | "Invalid shipping method" |
| 400 | Wrong store | "Shipping method not available for this store" |
π Related Skills
vendix-backend-api- API patternsvendix-error-handling- Error handlingvendix-frontend-state- State managementvendix-multi-tenant-context- Store context
