## 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]

- The system shall calculate the total order amount automatically as the sum of (quantity × unit price) for all items.  
  [KB-0e0f1dd0-0f46-4d13-a092-e3cdc6fdd205], [KB-86e313b9-691a-4830-b560-a2097e138f34]

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

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

- The system shall provide paginated order listing with parameters: skip (default 0), limit (default 20).  
  [KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-0972bd0e-7d3f-4b2c-a364-813e023a3495]

- The system shall allow retrieval of order details by order ID, including item details.  
  [KB-55d6e023-2c8e-49db-9409-68b9e9ed721f]

- The system shall allow updating order status via API. Setting status to SHIPPED triggers a shipping notification.  
  [KB-4287fde1-e2d9-4e31-8f2f-5c3f64f00add]

- The system shall allow order cancellation via API, which triggers refund processing and cancellation notification.  
  [KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-186b33d7-f985-455b-8117-0cd019912510], [KB-981308db-2c30-4894-ba6b-491bf40b1d24]

- The system shall support payment status updates via webhook from Payment Service (single order callback only).  
  [KB-69d55b34-e506-4b4e-a043-ef842030f397], [KB-981308db-2c30-4894-ba6b-491bf40b1d24]

### 4.1.2 Payment Service

- The system shall process payment for a single order per API request. Batch payment processing is not supported.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-8ca26148-03e1-4184-a736-624e14448df9]

- The system shall enforce a minimum payment amount of 100 JPY and a maximum of 1,000,000 JPY per transaction.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6], [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6]

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

- The system shall reject duplicate payment requests for the same order ID.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6]

- The system shall support refund processing for completed payments.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6]

- The system shall notify Order Service of payment status changes via webhook (single order callback only).  
  [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6], [KB-4bd8168d-aed4-41eb-8733-2ab9d82daa22]

### 4.1.3 Notification Service

- The system shall send email notifications for individual orders using templates.  
  [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-582e7673-bd66-493e-b511-017708ae9326]

- The system shall send SMS notifications for individual orders using templates.  
  [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-582e7673-bd66-493e-b511-017708ae9326]

- The system shall support three notification templates: ORDER_CONFIRMATION, ORDER_SHIPPED, ORDER_CANCELLED.  
  [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8]

- Templates shall support Jinja2-style variable substitution with Japanese language content.  
  [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-3133bf0e-2d7c-4477-9e36-c8548c037b2c]

- The system shall track notification delivery status (PENDING, SENT, FAILED).  
  [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8]

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

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

### 4.1.4 CSV Import (Bulk Order Creation) — Business Requirement

- There is a documented business requirement to support bulk order creation via CSV import for corporate customers (100–10,000 orders per batch).  
  [KB-155b5f4a-d232-4166-bb96-ba158f86ceb1], [KB-1603dccf-0e13-426d-a4c3-527af9e69c16], [KB-2b0238e6-fb8b-4c64-bbb0-73de35f73a08], [KB-6ef0a78b-63b6-493a-a7b0-76398d5a2889], [KB-94407aa3-d1ac-4455-a68c-265236fefec4], [KB-5bd83fdc-f7d5-4953-bd1e-e9b287f0bf96], [KB-5a963d29-d4ed-4859-ba71-d355620aa5bc], [KB-9722c127-de97-4494-bb8d-1d840efa8899], [KB-2183809f-cfa9-4b0b-a30d-320f78a4f161], [KB-2708f598-e5da-4cca-91f0-fd3d267de542], [KB-25b436c5-c5b0-48c1-97de-61d50bd37e57], [KB-1ac0c309-d977-46d8-9523-c7d212164f65], [KB-2cb01db2-27b0-46bc-ae60-dac1a20281ed]

- As of current system implementation, CSV bulk import is not available. The UI displays a warning banner and disables the CSV import button.  
  [KB-16181d30-2dd3-421e-bab0-939cd85255d2]

- If implemented, each order in the CSV would require individual processing and payment API calls due to per-order transaction limits.  
  [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6]

## 4.2 Constraints

- Only one order can be created per API request; batch/bulk endpoints are not available.  
  [KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-4c9591c9-34d5-42b1-a0e2-1de20131159c]

- Payment Service enforces a maximum amount of 1,000,000 JPY per transaction and a minimum of 100 JPY.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6], [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6]

- There is a strict 1:1 relationship between orders and payments; duplicate payments for the same order are rejected.  
  [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6]

- Webhook callbacks for payment status updates are performed per order; batch webhook or batch status update is not supported.  
  [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6], [KB-69d55b34-e506-4b4e-a043-ef842030f397]

- Notification Service supports only single notification per API request; batch notification sending is not available.  
  [KB-582e7673-bd66-493e-b511-017708ae9326]

## 4.3 Interface Requirements

### 4.3.1 Order Service API

| Endpoint                              | Description                                 |
|----------------------------------------|---------------------------------------------|
| POST /api/v1/orders/                   | Create single order                         |
| GET /api/v1/orders/                    | List orders (pagination: skip, limit)       |
| GET /api/v1/orders/{order_id}          | Retrieve order details                      |
| PUT /api/v1/orders/{order_id}/status   | Update order status                         |
| DELETE /api/v1/orders/{order_id}       | Cancel order, triggers refund & notification |
| POST /api/v1/orders/{order_id}/webhook | Receive payment status update (single order) |

[KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-4287fde1-e2d9-4e31-8f2f-5c3f64f00add], [KB-69d55b34-e506-4b4e-a043-ef842030f397], [KB-981308db-2c30-4b61-8281-0f528a467093]

### 4.3.2 Payment Service API

| Endpoint                              | Description                                 |
|----------------------------------------|---------------------------------------------|
| POST /api/v1/payments/                 | Process payment for single order            |
| GET /api/v1/payments/{payment_id}      | Retrieve payment details                    |
| GET /api/v1/payments/order/{order_id}  | Retrieve payment by order ID                |
| POST /api/v1/payments/refund           | Process refund for completed payment        |

[KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-90c1a181-8f6a-4efe-be94-d7a6c0e37f5a], [KB-8e5c6600-75fa-4e87-a6f5-0d06b21d8625]

### 4.3.3 Notification Service API

| Endpoint                                      | Description                                   |
|------------------------------------------------|-----------------------------------------------|
| POST /api/v1/notifications/email               | Send single email notification (rate limit: 10/sec) |
| POST /api/v1/notifications/sms                 | Send single SMS notification                  |
| GET /api/v1/notifications/{notification_id}    | Retrieve notification history by ID           |
| GET /api/v1/notifications/order/{order_id}     | Retrieve all notifications for an order       |

[KB-582e7673-bd66-493e-b511-017708ae9326], [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-4d364408-238b-4248-925a-97d5a3446d3c]

## 4.4 Data Requirements

- Order data must include customer name, customer email, item details (product name, quantity, unit price), currency, and calculated total amount.  
  [KB-0e0f1dd0-0f46-4d13-a092-e3cdc6fdd205], [KB-1bfa4181-74da-4372-ba8f-acf6d7aa41c4]

- Payment data must include order ID, amount, currency, payment status, payment method, transaction ID, timestamps.  
  [KB-90c1a181-8f6a-4efe-be94-d7a6c0e37f5a]

- Notification data must include order ID, channel (email/SMS), template name, recipient, subject, body, status, timestamps.  
  [KB-258b5996-5aad-4f5f-acd2-8e458c49f884]

## 4.5 [GAP: Missing data for Requirements]

- Bulk CSV import functionality is not implemented; requirements for CSV file structure, validation, and processing are not fully specified.
- No requirements for error handling, retry logic, or import history for bulk operations are available in the current context.

---

**References:**  
[KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-4c9591c9-34d5-42b1-a0e2-1de20131159c], [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6], [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6], [KB-582e7673-bd66-493e-b511-017708ae9326], [KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-155b5f4a-d232-4166-bb96-ba158f86ceb1], [KB-16181d30-2dd3-421e-bab0-939cd85255d2], [KB-69d55b34-e506-4b4e-a043-ef842030f397], [KB-90c1a181-8f6a-4efe-be94-d7a6c0e37f5a], [KB-1bfa4181-74da-4372-ba8f-acf6d7aa41c4], [KB-258b5996-5aad-4f5f-acd2-8e458c49f884], [KB-4d364408-238b-4248-925a-97d5a3446d3c], [KB-981308db-2c30-4b61-8281-0f528a467093]