{
  "contract": "1.2",
  "documentation_only": true,
  "preconditions": [
    "These are synthetic examples, not production commands or credentials.",
    "Use an isolated installed1.2 server and a configured delivery namespace. Bind customer-001 and product-001 first; stock10 available.",
    "100 KGS per unit must yield total1000 after configured native taxes; example assumes no additional tax on top.",
    "Replace journal IDs100001/100002 and method IDs200001/200002/200003 with verified native manual journal/method IDs from /options; outgoing refund method differs from incoming.",
    "Choose actual dates within the open accounting period. Every timestamp must be UTC Z.",
    "Example branch5 is an alternative fresh scenario; never reuse processed IDs for changed quantities.",
    "No example asserts fiscal issuance; external receipt confirmation is separate."
  ],
  "scenarios": [
    {
      "id": 1,
      "title": "Deliver1000 with no payment",
      "requests": [
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/orders",
          "headers": {
            "Idempotency-Key": "example-order-001"
          },
          "body": {
            "event_id": "event-order-001",
            "external_id": "order-001",
            "version": "1",
            "customer_external_id": "customer-001",
            "currency": "KGS",
            "expected_total": 1000,
            "lines": [
              {
                "item_id": "line-001",
                "product_external_id": "product-001",
                "quantity": 10,
                "price_unit": 100
              }
            ]
          },
          "expected": "Confirmed order only: no invoice or customer stock issue."
        },
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/trips",
          "headers": {
            "Idempotency-Key": "example-trip-001"
          },
          "body": {
            "event_id": "event-trip-001",
            "external_id": "trip-001",
            "driver_external_id": "driver-001"
          },
          "expected": "Internal driver location."
        },
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/trips/trip-001/loads",
          "headers": {
            "Idempotency-Key": "example-load-001"
          },
          "body": {
            "event_id": "event-load-001",
            "external_id": "load-001",
            "occurred_at": "2026-10-20T09:00:00Z",
            "lines": [
              {
                "order_external_id": "order-001",
                "order_version": "1",
                "item_id": "line-001",
                "quantity": 10
              }
            ]
          },
          "expected": "Warehouse → driver: 10 units; no customer debt."
        },
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/delivery-results",
          "headers": {
            "Idempotency-Key": "example-delivery-001"
          },
          "body": {
            "event_id": "event-delivery-001",
            "external_id": "delivery-001",
            "order_external_id": "order-001",
            "order_version": "1",
            "trip_external_id": "trip-001",
            "stop_id": "stop-001",
            "occurred_at": "2026-10-20T09:00:00Z",
            "lines": [
              {
                "item_id": "line-001",
                "accepted_quantity": 10
              }
            ],
            "payments": []
          },
          "expected": "invoiced_total=1000, paid_amount=0, debt=1000, payment_status=unpaid. Driver → customer: 10 units."
        }
      ]
    },
    {
      "id": 2,
      "title": "Collect400 cash",
      "requests": [
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/payments",
          "headers": {
            "Idempotency-Key": "example-payment-cash-001"
          },
          "body": {
            "event_id": "event-payment-cash-001",
            "external_id": "payment-cash-001",
            "order_external_id": "order-001",
            "currency": "KGS",
            "amount": 400,
            "journal_id": 100001,
            "payment_method_line_id": 200001,
            "source": "cash_collected",
            "occurred_at": "2026-10-20T10:00:00Z",
            "payment_date": "2026-10-20",
            "allocations": [
              {
                "delivery_result_external_id": "delivery-001",
                "amount": 400
              }
            ]
          },
          "expected": "No goods or sale recreated; native payment is registered and reconciled, no acquiring call. paid_amount=400, debt=600."
        }
      ]
    },
    {
      "id": 3,
      "title": "Confirm600 bank next day",
      "requests": [
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/payments",
          "headers": {
            "Idempotency-Key": "example-payment-bank-001"
          },
          "body": {
            "event_id": "event-payment-bank-001",
            "external_id": "payment-bank-001",
            "order_external_id": "order-001",
            "currency": "KGS",
            "amount": 600,
            "journal_id": 100002,
            "payment_method_line_id": 200002,
            "source": "elcrm_confirmed_bank",
            "occurred_at": "2026-10-21T10:00:00Z",
            "payment_date": "2026-10-21",
            "allocations": [
              {
                "delivery_result_external_id": "delivery-001",
                "amount": 600
              }
            ],
            "source_reference": "elcrm-confirmed-bank-001",
            "confirmed_at": "2026-10-21T10:00:00Z"
          },
          "expected": "No goods or sale recreated; native payment is registered and reconciled, no acquiring call. paid_amount=1000, debt=0."
        }
      ]
    },
    {
      "id": 4,
      "title": "Exact retries",
      "instruction": "Repeat any successful POST with the identical saved path, body and Idempotency-Key. Expect HTTP200 replayed=true, same record IDs and fresh current, no extra native effects. Changed body with same identity must conflict."
    },
    {
      "id": 5,
      "title": "Partial delivery and unaccepted return",
      "requests": [
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/orders",
          "headers": {
            "Idempotency-Key": "example-order-partial-001"
          },
          "body": {
            "event_id": "event-order-partial-001",
            "external_id": "order-partial-001",
            "version": "1",
            "customer_external_id": "customer-001",
            "currency": "KGS",
            "expected_total": 1000,
            "lines": [
              {
                "item_id": "line-partial-001",
                "product_external_id": "product-001",
                "quantity": 10,
                "price_unit": 100
              }
            ]
          },
          "expected": "Confirmed order only: no invoice or customer stock issue."
        },
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/trips",
          "headers": {
            "Idempotency-Key": "example-trip-partial-001"
          },
          "body": {
            "event_id": "event-trip-partial-001",
            "external_id": "trip-partial-001",
            "driver_external_id": "driver-001"
          },
          "expected": "Internal driver location."
        },
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/trips/trip-partial-001/loads",
          "headers": {
            "Idempotency-Key": "example-load-partial-001"
          },
          "body": {
            "event_id": "event-load-partial-001",
            "external_id": "load-partial-001",
            "occurred_at": "2026-10-20T09:00:00Z",
            "lines": [
              {
                "order_external_id": "order-partial-001",
                "order_version": "1",
                "item_id": "line-partial-001",
                "quantity": 10
              }
            ]
          },
          "expected": "Warehouse → driver: 10 units; no customer debt."
        },
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/delivery-results",
          "headers": {
            "Idempotency-Key": "example-delivery-partial-001"
          },
          "body": {
            "event_id": "event-delivery-partial-001",
            "external_id": "delivery-partial-001",
            "order_external_id": "order-partial-001",
            "order_version": "1",
            "trip_external_id": "trip-partial-001",
            "stop_id": "stop-partial-001",
            "occurred_at": "2026-10-20T09:00:00Z",
            "lines": [
              {
                "item_id": "line-partial-001",
                "accepted_quantity": 8
              }
            ],
            "payments": []
          },
          "expected": "Accepted800, debt800; driver retains2. No payment; only accepted8 invoiced."
        },
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/trips/trip-partial-001/stock-returns",
          "headers": {
            "Idempotency-Key": "example-stock-return-partial-001"
          },
          "body": {
            "event_id": "event-stock-return-partial-001",
            "external_id": "stock-return-partial-001",
            "occurred_at": "2026-10-20T09:00:00Z",
            "lines": [
              {
                "order_external_id": "order-partial-001",
                "order_version": "1",
                "item_id": "line-partial-001",
                "quantity": 2
              }
            ]
          },
          "expected": "Alternative partial-delivery scenario only: driver → warehouse2; no customer credit note."
        },
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/trips/trip-partial-001/close",
          "headers": {
            "Idempotency-Key": "example-trip-close-partial-001"
          },
          "body": {
            "event_id": "event-trip-close-partial-001",
            "external_id": "trip-close-partial-001",
            "occurred_at": "2026-10-20T11:00:00Z"
          },
          "expected": "Closes only when both stock and per-order allocations are zero."
        }
      ],
      "instruction": "Separate alternative order and trip: load10, accept8, return2, close empty trip. No customer credit note for unaccepted stock."
    },
    {
      "id": 6,
      "title": "Return after full payment",
      "requests": [
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/returns",
          "headers": {
            "Idempotency-Key": "example-return-001"
          },
          "body": {
            "event_id": "event-return-001",
            "external_id": "return-001",
            "delivery_result_external_id": "delivery-001",
            "occurred_at": "2026-10-21T11:00:00Z",
            "lines": [
              {
                "item_id": "line-001",
                "quantity": 2
              }
            ]
          },
          "expected": "Customer → configured warehouse: 2 units; credit note=200, customer_credit=200, refund_status=pending. paid_amount stays1000, net_total=800."
        },
        {
          "method": "POST",
          "path": "/api/elpos/v1/delivery/refunds",
          "headers": {
            "Idempotency-Key": "example-refund-001"
          },
          "body": {
            "event_id": "event-refund-001",
            "external_id": "refund-001",
            "return_external_id": "return-001",
            "currency": "KGS",
            "amount": 200,
            "journal_id": 100001,
            "payment_method_line_id": 200003,
            "source": "cash_collected",
            "occurred_at": "2026-10-21T11:05:00Z",
            "payment_date": "2026-10-21"
          },
          "expected": "Record money already returned: refunded_amount=200, customer_credit=0, refund_status=refunded. No card refund request."
        }
      ],
      "instruction": "Requires scenarios1–3. For full return use quantity10 and amount1000 in a separate fresh scenario; do not change existing request IDs."
    },
    {
      "id": 7,
      "title": "Lost response",
      "requests": [
        {
          "method": "GET",
          "path": "/api/elpos/v1/delivery/lookup?kind=payment&external_id=payment-bank-001",
          "expected": "Existing record IDs and current settlement if original payment committed."
        }
      ],
      "instruction": "Persist request before network. After timeout/5xx keep unknown state and look up saved external ID, event ID or idempotency key. Retry only the identical saved request. A missing/forbidden lookup is not permission to use a new ID."
    }
  ]
}
