Skip to content

E-Commerce Purchase Flow

Complete customer journey from product discovery to delivery and post-purchase support.

Overview

The purchase flow includes:

  1. Product discovery (browsing, search, filtering)
  2. Product details and reviews
  3. Cart management
  4. Checkout process (shipping, payment)
  5. Order confirmation and tracking
  6. Delivery and post-purchase activities

Main Flow Diagram


Step Details

1. Product Discovery

Browsing Endpoint: GET /products

Query Parameters:

ParameterTypeDescription
categorystringCategory slug
minPricenumberMinimum price filter
maxPricenumberMaximum price filter
sortstringpopular, newest, price_asc, price_desc
pagenumberPage number (default: 1)
limitnumberItems per page (default: 20, max: 100)
inStockbooleanOnly show in-stock items

Search Endpoint: GET /products/search

Query Parameters:

ParameterTypeDescription
qstringSearch query (min 2 chars)
categorystringOptional category filter
sortstringrelevance, popular, price_asc, price_desc

Search Implementation:

  • PostgreSQL full-text search with tsvector
  • Weighted search: name (A), description (B), SKU (C)
  • Fuzzy matching for typo tolerance

2. Product Details

Endpoint: GET /products/{slug}

Response:

json
{
  "id": "uuid",
  "sku": "WH-BT-001",
  "name": "Wireless Headphones Pro",
  "slug": "wireless-headphones-pro",
  "shortDescription": "Premium wireless headphones with noise cancellation",
  "description": "Full HTML description...",
  "basePrice": 9990.00,
  "salePrice": 7990.00,
  "currency": "RUB",
  "status": "ACTIVE",
  "stockQuantity": 45,
  "inStock": true,
  "images": [
    { "url": "https://cdn.../main.jpg", "isPrimary": true },
    { "url": "https://cdn.../side.jpg", "isPrimary": false }
  ],
  "category": {
    "id": "uuid",
    "name": "Electronics",
    "slug": "electronics"
  },
  "reviewsSummary": {
    "averageRating": 4.5,
    "totalReviews": 128
  },
  "careerPointsValue": 100.00
}

Stock Status Display:

Stock LevelDisplay
> 10"In Stock"
1-10"Only X left"
0"Out of Stock"

3. Add to Cart

Endpoint: POST /cart/items

Request:

json
{
  "productId": "product-uuid",
  "quantity": 2
}

Validation Rules:

RuleConstraint
QuantityMin: 1, Max: 99
Stockquantity <= available stock
Product statusMust be ACTIVE
Cart itemsMax 50 unique items

Cart Identification:

  • Authenticated: By user_id
  • Guest: By session_id (cookie)

Referral Attribution:

  • Cart inherits referring_partner_id from session attribution
  • Preserved even if user logs in during checkout

4. Cart Management

Get Cart Endpoint: GET /cart

Response:

json
{
  "id": "cart-uuid",
  "items": [
    {
      "id": "item-uuid",
      "product": {
        "id": "product-uuid",
        "name": "Wireless Headphones Pro",
        "sku": "WH-BT-001",
        "imageUrl": "https://cdn.../thumb.jpg",
        "slug": "wireless-headphones-pro"
      },
      "quantity": 2,
      "unitPrice": 7990.00,
      "totalPrice": 15980.00,
      "stockStatus": "IN_STOCK",
      "availableQuantity": 45
    }
  ],
  "subtotal": 15980.00,
  "discountTotal": 0.00,
  "total": 15980.00,
  "currency": "RUB",
  "itemCount": 2,
  "referringPartnerCode": "ABC123"
}

Update Quantity Endpoint: PATCH /cart/items/{itemId}

Request:

json
{
  "quantity": 3
}

Remove Item Endpoint: DELETE /cart/items/{itemId}

Save for Later: POST /cart/items/{itemId}/save-for-later


5. Guest vs Authenticated Checkout

Guest Checkout Flow:

  1. Email collection (required)
  2. Shipping address entry
  3. Payment processing
  4. Account creation offer (optional, post-purchase)

Guest Checkout Limitations:

  • Order history only via email lookup
  • No saved addresses/payment methods
  • Cannot use loyalty points
  • Still receives referral attribution

Cart Merge (when guest logs in):

  • Guest cart items merged into user cart
  • Duplicate products: quantities summed
  • Attribution preserved from original cart

6. Checkout Step 1: Shipping Address

Saved Addresses Endpoint: GET /users/me/addresses?type=SHIPPING

New Address Request:

json
{
  "firstName": "Ivan",
  "lastName": "Petrov",
  "phone": "+79001234567",
  "addressLine1": "ul. Lenina, d. 10, kv. 5",
  "addressLine2": "",
  "city": "Moscow",
  "state": "Moscow Oblast",
  "postalCode": "101000",
  "country": "RUS",
  "saveAddress": true,
  "setAsDefault": true
}

Address Validation:

FieldRules
firstName, lastNameRequired, 2-100 chars
addressLine1Required, max 255 chars
cityRequired, max 100 chars
postalCodeRequired, format varies by country
countryRequired, ISO 3166-1 alpha-3
phoneRequired, E.164 format

7. Checkout Step 2: Shipping Method

Endpoint: GET /checkout/shipping-methods

Response:

json
{
  "methods": [
    {
      "id": "method-uuid",
      "name": "CDEK Express",
      "carrier": "CDEK",
      "price": 350.00,
      "currency": "RUB",
      "estimatedDays": { "min": 2, "max": 4 },
      "description": "Fast delivery to your door"
    },
    {
      "id": "method-uuid-2",
      "name": "Standard Delivery",
      "carrier": "CDEK",
      "price": 200.00,
      "currency": "RUB",
      "estimatedDays": { "min": 5, "max": 7 },
      "description": "Economic delivery option"
    }
  ]
}

Rate Calculation:

  • Based on: destination, weight, dimensions
  • Cached for 15 minutes
  • Real-time API call to carrier if cache miss

8. Checkout Step 3: Payment

Supported Payment Methods:

MethodProviderFeatures
Credit/Debit CardStripe3D Secure, saved cards
Bank Card (RU)YooKassaRussian cards, SberPay
E-walletYooKassaYooMoney, QIWI
Bank TransferYooKassaInvoice payment

Payment Flow (Stripe):

  1. Frontend creates PaymentIntent
  2. User enters card details in Stripe Elements
  3. Frontend confirms payment
  4. Backend verifies via webhook

Complete Checkout Endpoint: POST /checkout/complete

Request:

json
{
  "paymentMethodId": "pm_xxx",
  "paymentIntentId": "pi_xxx",
  "billingAddressId": "address-uuid",
  "notes": "Leave at door"
}

9. Order Confirmation

Order Created:

json
{
  "id": "order-uuid",
  "orderNumber": "ORD-2024-001234",
  "status": "CONFIRMED",
  "items": [...],
  "subtotal": 15980.00,
  "shippingCost": 350.00,
  "discountTotal": 0.00,
  "taxAmount": 0.00,
  "total": 16330.00,
  "currency": "RUB",
  "shippingAddress": {...},
  "shippingMethod": {...},
  "createdAt": "2024-01-15T10:30:00Z",
  "estimatedDelivery": "2024-01-19"
}

Confirmation Email Contains:

  • Order number and summary
  • Itemized list with prices
  • Shipping address and method
  • Estimated delivery date
  • Support contact

10. Order Tracking

Endpoint: GET /orders/{orderNumber}

Order Status Timeline:

StatusDescriptionUser Action
PENDINGOrder created, awaiting paymentComplete payment
CONFIRMEDPayment successfulWait for processing
PROCESSINGBeing preparedWait for shipping
SHIPPEDHanded to carrierTrack shipment
DELIVEREDReceived by customerLeave review, request return
CANCELLEDOrder cancelledContact support
REFUNDEDMoney returnedN/A

Tracking Integration:

  • Real-time tracking via carrier API
  • Webhook updates for status changes
  • SMS/Email notifications at each stage

11-12. Fulfillment and Delivery

Order State Transitions:

PENDING -> CONFIRMED -> PROCESSING -> SHIPPED -> DELIVERED
    |          |            |
    v          v            v
CANCELLED  CANCELLED   CANCELLED (rare)
                           |
                           v
                       REFUNDED

Carrier Webhook Events:

EventAction
picked_upUpdate shipment status
in_transitUpdate tracking events
out_for_deliverySend notification
deliveredUpdate order to DELIVERED
returnedInitiate return process

13. Post-Purchase

Reviews

Endpoint: POST /products/{productId}/reviews

Request:

json
{
  "rating": 5,
  "title": "Great headphones!",
  "content": "Sound quality is amazing, battery lasts all day.",
  "orderId": "order-uuid"
}

Review Rules:

  • Must have purchased product (order DELIVERED)
  • One review per product per user
  • Moderation required before publishing

Returns

Endpoint: POST /orders/{orderNumber}/returns

Request:

json
{
  "items": [
    {
      "orderItemId": "item-uuid",
      "quantity": 1,
      "reason": "DEFECTIVE",
      "description": "Left speaker not working"
    }
  ]
}

Return Reasons:

CodeDescriptionRefund Timeline
DEFECTIVEProduct defectFull refund, 3-5 days
WRONG_ITEMReceived wrong itemFull refund, 3-5 days
NOT_AS_DESCRIBEDDoesn't match listingFull refund, 3-5 days
CHANGED_MINDCustomer changed mindRefund minus shipping, 5-7 days

Return Window: 14 days from delivery


Error Scenarios

Cart Errors

ScenarioHTTP CodeError CodeMessage
Product not found404PRODUCT_NOT_FOUND"Product no longer available"
Out of stock422INSUFFICIENT_STOCK"Only X items available"
Product discontinued422PRODUCT_UNAVAILABLE"This product is no longer sold"
Cart empty400EMPTY_CART"Your cart is empty"

Checkout Errors

ScenarioHTTP CodeError CodeMessage
Stock changed during checkout409STOCK_CHANGED"Some items are no longer available"
Price changed409PRICE_CHANGED"Prices have been updated"
Invalid address400INVALID_ADDRESS"Please check your address"
Shipping unavailable422SHIPPING_UNAVAILABLE"Delivery not available to this address"

Payment Errors

ScenarioHTTP CodeError CodeMessage
Card declined422CARD_DECLINED"Your card was declined"
Insufficient funds422INSUFFICIENT_FUNDS"Insufficient funds"
3DS failed4223DS_FAILED"3D Secure verification failed"
Payment timeout408PAYMENT_TIMEOUT"Payment timed out, please try again"