## Requirements

# 4. Requirements

## 4.1 Functional Requirements

### 4.1.1 Order Service

| ID     | Requirement                                                                                                    | Priority   |
|--------|---------------------------------------------------------------------------------------------------------------|------------|
| FR-001 | The system shall allow creation of a single order by specifying customer information (name, email) and order details (product name, quantity, unit price). | P1         |
| FR-002 | The system shall automatically calculate the total order amount as the sum of (quantity × unit price) for each item. | P1         |
| FR-003 | The system shall support paginated retrieval of order lists using skip and limit parameters. Default limit is 20. | P1         |
| FR-004 | The system shall retrieve order details (including items) by order ID.                                          | P1         |
| FR-005 | The system shall support order status transitions: PENDING → PROCESSING_PAYMENT → PAID → SHIPPED → DELIVERED.  | P1         |
| FR-006 | The system shall support order cancellation and transition status to CANCELLED.                                 | P1         |

**References:**  
[KB-0e0f1dd0-0f46-4d13-a092-e3cdc6fdd205], [KB-55d6e023-2c8e-49db-9409-68b9e9ed721f], [KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-4287fde1-e2d9-4e31-8f2f-5c3f64f00add]

---

### 4.1.2 Payment Service

| ID     | Requirement                                                                                           | Priority   |
|--------|-------------------------------------------------------------------------------------------------------|------------|
| FR-013 | The system shall enforce a maximum amount of 1,000,000 JPY per single transaction.                    | P1         |
| FR-014 | The system shall maintain a 1:1 relationship between orders and payments (one payment per order).      | P1         |
| FR-015 | The system shall reject duplicate payment requests for the same order.                                 | P1         |
| FR-016 | The system shall support refund processing for completed payments.                                     | P1         |

**References:**  
[KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6], [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-90c1a181-8f6a-4efe-be94-d7a6c0e37f5a]

---

### 4.1.3 Notification Service

| ID     | Requirement                                                                                                 | Priority   |
|--------|-------------------------------------------------------------------------------------------------------------|------------|
| FR-019 | The system shall send email notifications for individual orders using templates.                            | P1         |
| FR-020 | The system shall send SMS notifications for individual orders using templates.                              | P2         |
| FR-021 | The system shall support three notification templates: ORDER_CONFIRMATION, ORDER_SHIPPED, ORDER_CANCELLED.  | P1         |
| FR-022 | Templates shall support Jinja2-style variable substitution with Japanese language content.                  | P1         |
| FR-023 | The system shall track notification delivery status (PENDING, SENT, FAILED).                                | P1         |
| FR-024 | The system shall retrieve notification history by notification ID.                                          | P2         |
| FR-025 | The system shall retrieve all notifications for a specific order.                                           | P2         |

**References:**  
[KB-6155f440-0799-44eb-851f-9a5b81fbbcf8], [KB-3133bf0e-2d9b-46e7-b894-1fd70c185060], [KB-582e7673-bd66-493e-b511-017708ae9326], [KB-2414677b-6e22-47f5-917c-2ed718d86fd4], [KB-258b5996-5aad-4f5f-acd2-8e458c49f884]

---

### 4.1.4 Bulk/CSV Import (Business Requirement)

| ID            | Requirement                                                                                      | Priority   |
|---------------|--------------------------------------------------------------------------------------------------|------------|
| FR-BULK-001   | The system shall allow users to upload CSV files for bulk order import. Maximum file size: 50MB. Supported encodings: UTF-8, Shift_JIS. | P1         |
| FR-BULK-002   | The system shall validate CSV structure, data types, and required fields. Errors must be reported per row. | P1         |
| FR-BULK-003   | The system shall create orders in bulk from validated CSV data (100–10,000 orders supported).     | P1         |
| FR-BULK-004   | The system shall process payments for all created orders in bulk, enforcing per-order amount limits. | P1         |
| FR-BULK-005   | The system shall send confirmation emails in bulk for imported orders.                            | P2         |
| FR-BULK-006   | The system shall display real-time progress tracking for import processing (processed/total count). | P1         |
| FR-BULK-007   | The system shall handle partial failures: successful orders are retained, failed orders are downloadable as error list. | P1         |
| FR-BULK-009   | The system shall allow download of a CSV template in correct format for import.                   | P3         |
| FR-BULK-010   | The system shall allow cancellation of ongoing import; unprocessed orders will not be created.    | P3         |

**References:**  
[KB-063a89e7-bb79-4435-993b-95ec7b9a9e4e], [KB-35c9e00d-f446-4174-be65-d214ecbff895], [KB-89dddd9a-2e13-46e7-8281-0f528a467093], [KB-6aa21c29-11f1-4b6b-b8e8-2c9990900522], [KB-1b4a5120-e114-4bb2-b423-43e981424088], [KB-0e28e3cb-6977-43b1-ba8e-1ed80f2de11e]

---

## 4.2 Interface Requirements

### 4.2.1 Order Service API

| Endpoint                                 | Description                                                                                       |
|-------------------------------------------|---------------------------------------------------------------------------------------------------|
| POST /api/v1/orders/                      | Create a single order. Batch creation is not supported.                                           |
| GET /api/v1/orders/                       | Retrieve paginated list of orders (skip, limit). Default limit: 20.                               |
| GET /api/v1/orders/{order_id}             | Retrieve details for a specific order.                                                            |
| PUT /api/v1/orders/{order_id}/status      | Update order status. Changing to SHIPPED triggers shipping notification.                          |
| DELETE /api/v1/orders/{order_id}          | Cancel order. Triggers refund via Payment Service and cancellation email via Notification Service. |
| POST /api/v1/orders/{order_id}/webhook    | Receive payment status update from Payment Service. Updates order status accordingly.              |

**References:**  
[KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-4287fde1-e2d9-4e31-8f2f-5c3f64f00add], [KB-69d55b34-e506-4b4e-a043-ef842030f397], [KB-981308db-2c30-4894-ba6b-491bf40b1d24]

---

### 4.2.2 Payment Service API

| Endpoint                                 | Description                                                                                       |
|-------------------------------------------|---------------------------------------------------------------------------------------------------|
| POST /api/v1/payments/                    | Process payment for a single order. Amount must be between 100 and 1,000,000 JPY.                 |
| GET /api/v1/payments/{payment_id}         | Retrieve payment details by payment ID.                                                           |
| GET /api/v1/payments/order/{order_id}     | Retrieve payment details for a specific order (1:1 relationship).                                 |
| POST /api/v1/payments/refund              | Process refund for a completed payment.                                                           |

**References:**  
[KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-36050440-5a8a-4389-8690-8fd0a46f5cd3], [KB-90c1a181-8f6a-4efe-be94-d7a6c0e37f5a], [KB-8e5c6600-75fa-4e87-a6f5-0d06b21d8625]

---

### 4.2.3 Notification Service API

| Endpoint                                         | Description                                                                                   |
|--------------------------------------------------|-----------------------------------------------------------------------------------------------|
| POST /api/v1/notifications/email                 | Send single email notification for an order.                                                  |
| POST /api/v1/notifications/sms                   | Send single SMS notification for an order.                                                    |
| GET /api/v1/notifications/{notification_id}      | Retrieve notification history by notification ID.                                             |
| GET /api/v1/notifications/order/{order_id}       | Retrieve all notifications for a specific order.                                              |

**References:**  
[KB-582e7673-bd66-493e-b511-017708ae9326], [KB-2414677b-6e22-47f5-917c-2ed718d86fd4], [KB-4d364408-238b-4248-925a-97d5a3446d3c]

---

## 4.3 Constraint Requirements

### 4.3.1 Payment Constraints

- Maximum payment amount per single transaction: 1,000,000 JPY.
- Minimum payment amount: 100 JPY.
- No batch payment endpoint; each order requires individual payment API call.
- Duplicate payments for the same order are rejected.

**References:**  
[KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6], [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6]

---

### 4.3.2 Bulk Import Constraints

- CSV file upload: Maximum size 50MB; supported encodings: UTF-8, Shift_JIS.
- Bulk order creation: 100–10,000 orders per import.
- Progress tracking and partial failure handling required.
- No batch payment or batch notification endpoint; each order processed individually.

**References:**  
[KB-063a89e7-bb79-4435-993b-95ec7b9a9e4e], [KB-35c9e00d-f446-4174-be65-d214ecbff895], [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6]

---

## 4.4 Business Requirements

- Bulk CSV import is requested by corporate customers to improve operational efficiency, supporting business processes for high-volume order creation (100–10,000 orders per batch).
- The system must provide CSV template download and import history tracking.

**References:**  
[KB-155b5f4a-d232-4166-bb96-ba158f86ceb1], [KB-6aa21c29-11f1-4b6b-b8e8-2c9990900522], [KB-89dddd9a-2e13-46e7-8281-0f528a467093]

---

## 4.5 [GAP: Missing data for Requirements]

If additional requirements are needed for other modules or cross-cutting concerns, please provide further context.

---

**End of Requirements Section**