## Requirements

# 4. Requirements

## 4.1 Functional Requirements

### 4.1.1 Order Service

- The system shall allow creation of a single order per API request. Bulk or batch order creation is not supported in the current implementation.  
  [KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-4c9591c9-34d5-42b1-a0e2-1de20131159c], [KB-86e313b9-691a-4830-b560-a2097e138f34]

- The system shall support paginated retrieval of order lists, with parameters `skip` (default 0) and `limit` (default 20).  
  [KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-4287fde1-e2d9-4e31-8f2f-5c3f64f00add]

- The system shall allow retrieval of order details by order ID, including itemized order contents.  
  [KB-55d6e023-2c8e-49db-9409-68b9e9ed721f], [KB-4c9591c9-34d5-42b1-a0e2-1de20131159c]

- The system shall support order status transitions: PENDING → PROCESSING → PAID → SHIPPED → DELIVERED.  
  [KB-55d6e023-2c8e-49db-9409-68b9e9ed721f]

- The system shall support order cancellation, updating status to CANCELLED.  
  [KB-55d6e023-2c8e-49db-9409-68b9e9ed721f], [KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9]

- Upon order cancellation, the system shall trigger a refund request to the Payment Service and send a cancellation notification via the Notification Service.  
  [KB-4651de1d-570d-4c49-8a65-ec5b22855797], [KB-981308db-2c30-4894-ba6b-491bf40b1d24], [KB-1a8a8c49-5d2d-4747-b2de-4e95950cdf44]

- When order status is updated to SHIPPED, the system shall send a shipping notification.  
  [KB-4287fde1-e2d9-4e31-8f2f-5c3f64f00add]

- The system shall support webhook integration for payment status updates. Payment Service will call Order Service via POST /api/v1/orders/{order_id}/webhook with payment status and transaction ID.  
  [KB-69d55b34-e506-4b4e-a043-ef842030f397], [KB-981308db-2c30-4894-ba6b-491bf40b1d24], [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6]

### 4.1.2 Payment Service

- The Payment Service shall process payments for a single order per request. Bulk payment processing is not supported.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-8ca26148-03e1-4184-a736-624e14448df9], [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6]

- Payment amount validation: minimum 100 JPY, maximum 1,000,000 JPY per transaction.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6], [KB-186b33d7-f985-455b-8117-0cd019912510]

- The Payment Service shall enforce a 1:1 relationship between orders and payments (one payment per order).  
  [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6], [KB-8072a75f-d61d-49b1-a859-1be86806c449]

- Duplicate payment requests for the same order_id shall be rejected.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6]

- The Payment Service shall support refund processing for completed payments.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-36050440-5a8a-4389-8690-8e458c49f884], [KB-186b33d7-f985-455b-8117-0cd019912510]

- Payment Service shall notify Order Service of payment status changes via webhook.  
  [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6], [KB-4bd8168d-aed4-41eb-8733-2ab9d82daa22]

### 4.1.3 Notification Service

- The Notification Service shall send email and SMS notifications for individual orders using templates.  
  [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-582e7673-bd66-493e-b511-017708ae9326], [KB-1c5832cc-4e41-483e-9898-60c735170444]

- The system shall support three notification templates: ORDER_CONFIRMATION, ORDER_SHIPPED, ORDER_CANCELLED.  
  [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-1c5832cc-4e41-483e-9898-60c735170444]

- Templates shall use Jinja2-style variable substitution and support Japanese language content.  
  [KB-3133bf0e-2d7b-46bc-ae60-dac1a20281ed], [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-79cd66a7-e187-4f66-b53c-ded850690b2e]

- Notification delivery status shall be tracked (PENDING, SENT, FAILED).  
  [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-79cd66a7-e187-4f66-b53c-ded850690b2e]

- The system shall allow retrieval of notification history by notification ID and retrieval of all notifications for a specific order.  
  [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-1c5832cc-4e41-483e-9898-60c735170444], [KB-4d364408-238b-4248-925a-97d5a3446d3c]

- Notification Service API rate limit: 10 requests per second for email notifications.  
  [KB-582e7673-bd66-493e-b511-017708ae9326]

## 4.2 Constraints

- Only single order creation, payment, and notification are supported per API request; bulk operations are not available.  
  [KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-582e7673-bd66-493e-b511-017708ae9326], [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6]

- Payment amount must be between 100 JPY and 1,000,000 JPY per transaction.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6]

- Duplicate payments for the same order are prohibited.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6]

- Refunds are only supported for completed payments.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-36050440-5a8a-4389-8690-8e458c49f884]

- Notification Service rate limiting applies: 10 email notifications per second.  
  [KB-582e7673-bd66-493e-b511-017708ae9326]

## 4.3 Interface Requirements

### 4.3.1 Order Service API

| Endpoint                              | Description                                  | Supported Operations      |
|----------------------------------------|----------------------------------------------|--------------------------|
| POST /api/v1/orders/                   | Create single order                          | Single order only        |
| GET /api/v1/orders/                    | List orders (pagination: skip, limit)        | Paginated list           |
| GET /api/v1/orders/{order_id}          | Retrieve order details                       | By order ID              |
| PUT /api/v1/orders/{order_id}/status   | Update order status                          | Triggers notifications   |
| DELETE /api/v1/orders/{order_id}       | Cancel order                                 | Triggers refund, notify  |
| POST /api/v1/orders/{order_id}/webhook | Payment status update (single order)         | No batch webhook         |

[KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-4287fde1-e2d9-4e31-8f2f-5c3f64f00add], [KB-69d55b34-e506-4b4e-a043-ef842030f397], [KB-981308db-2c30-489e-ac30-457c4c49753b]

### 4.3.2 Payment Service API

| Endpoint                              | Description                                  | Supported Operations      |
|----------------------------------------|----------------------------------------------|--------------------------|
| POST /api/v1/payments/                 | Create payment for single order              | Single order only        |
| GET /api/v1/payments/{payment_id}      | Retrieve payment by payment ID               | Individual payment       |
| GET /api/v1/payments/order/{order_id}  | Retrieve payment for specific order          | 1:1 order-payment        |
| POST /api/v1/payments/refund           | Process refund for completed payment         | Refund only if complete  |

[KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-36050440-5a8a-4389-8690-8e458c49f884], [KB-90c1a181-8f6a-4efe-be94-d7a6c0e37f5a]

### 4.3.3 Notification Service API

| Endpoint                                   | Description                                         | Supported Operations      |
|---------------------------------------------|-----------------------------------------------------|--------------------------|
| POST /api/v1/notifications/email            | Send single email notification                      | Single order only        |
| POST /api/v1/notifications/sms              | Send single SMS notification                        | Single order only        |
| GET /api/v1/notifications/{notification_id} | Retrieve notification by ID                         | Individual notification  |
| GET /api/v1/notifications/order/{order_id}  | Retrieve all notifications for specific order       | Multiple per order       |

[KB-582e7673-bd66-493e-b511-017708ae9326], [KB-1c5832cc-4e41-483e-9898-60c735170444], [KB-4d364408-238b-4248-925a-97d5a3446d3c]

## 4.4 Data Requirements

- Order data must include customer name, email, itemized order details (product name, quantity, unit price), and currency.  
  [KB-4c9591c9-34d5-42b1-a0e2-1de20131159c], [KB-1bfa4181-74da-4372-ba8f-acf6d7aa41c4]

- Payment data must include order_id, amount, currency, payment status, payment method, transaction ID, and timestamps.  
  [KB-90c1a181-8f6a-4efe-be94-d7a6c0e37f5a], [KB-36050440-5a8a-4389-8690-8e458c49f884]

- Notification data must include order_id, channel (email/SMS), template name, recipient, subject, body, status, and timestamps.  
  [KB-258b5996-5aad-4f5f-acd2-8e458c49f884], [KB-582e7673-bd66-493e-b511-017708ae9326]

## 4.5 Error Handling Requirements

- All API error responses must follow RFC 7807 Problem Details for HTTP APIs standard.  
  [KB-6353c73b-fdb1-409c-9679-739f0ab68585], [KB-4c9591c9-34d5-42b1-a0e2-1de20131159c]

- Common error codes:  
  - 400: Bad Request / Validation Error  
  - 404: Resource Not Found  
  - 422: Schema Validation Error  
  - 500: Internal Server Error  
  [KB-4bd8168d-aed4-41eb-8733-2ab9d82daa22]

## 4.6 [GAP: Missing data for Requirements]

- Bulk CSV import functionality for orders is frequently requested and referenced, but is not currently implemented.  
  [KB-155b5f4a-d232-4166-bb96-ba158f86ceb1], [KB-2183809f-cfa9-4b0b-a30d-320f78a4f161], [KB-94407aa3-d1ac-4455-a68c-265236fefec4], [KB-6ef0a78b-63b6-493a-a7b0-76398d5a2889], [KB-1603dccf-0e13-426d-a4c3-527af9e69c16], [KB-2b07b017-3e2f-47a4-9b03-d2be4a0e5644], [KB-5bd83fdc-f7d5-4953-bd1e-e9b287f0bf96], [KB-2c0207d4-673f-470e-a43e-d40dcd638bab], [KB-2b0238e6-fb8b-4c64-bbb0-73de35f73a08], [KB-5a963d29-d4ed-4859-ba71-d355620aa5bc], [KB-2708f598-e5da-4cca-91f0-fd3d267de542], [KB-25b436c5-c5b0-48c1-97de-61d50bd37e57], [KB-063a89e7-bb79-4435-993b-95ec7b9a9e4e], [KB-35c9e00d-f446-4174-be65-d214ecbff895], [KB-110bd1b1-0680-48fd-9bf9-6a5929dbbdec], [KB-0e0f1dd0-0f46-4d13-a092-e3cdc6fdd205], [KB-89dddd9a-2e13-46e7-99a4-34c3fff47435], [KB-6aa21c29-11f1-4b6b-b8e8-2c9990900522], [KB-0e28e3cb-6977-43b1-ba8e-1ed80f2de11e]

---

**End of Requirements Section**