## Requirements

# 4. Requirements

This section documents the functional and interface requirements for the Order, Payment, and Notification Services, as well as constraints and business rules, as derived from the provided context. All requirements are structured in accordance with ISO-29148.

---

## 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 all items. | P1       |
| FR-003  | The system shall support retrieval of order lists with pagination (parameters: skip, limit). Default: limit=20. | P1       |
| FR-004  | The system shall support retrieval of order details (including line 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 the status to CANCELLED.         | P1       |
| FR-009  | Upon order cancellation, the system shall send a refund request to the Payment Service.     | P1       |
| FR-010  | Upon order cancellation, the system shall send a cancellation notification to the Notification Service. | P1       |

**References:**  
[KB-0e0f1dd0-0f46-4d13-a092-e3cdc6fdd205], [KB-55d6e023-2c8e-49db-9409-68b9e9ed721f], [KB-4651de1d-570d-4c49-8a65-ec5b22855797], [KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-4c9591c9-34d5-42b1-a0e2-1de20131159c]

---

### 4.1.2 Payment Service

| ID      | Requirement                                                                                                  | Priority |
|---------|-------------------------------------------------------------------------------------------------------------|----------|
| FR-013  | The system shall enforce a maximum payment amount of 1,000,000 JPY per transaction.                         | P1       |
| FR-014  | The system shall maintain a 1:1 relationship between an order and a payment (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], [KB-9b61fb5a-8a89-4024-a535-ca56b147a8c8]

---

### 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-1c5832cc-4e41-483e-9898-60c735170444], [KB-79cd66a7-e187-4f66-b53c-ded850690b2e]

---

### 4.1.4 CSV Import (Bulk Order Creation)

| ID            | Requirement                                                                                      | Priority | Affected Service   | Acceptance Criteria                                    |
|---------------|-------------------------------------------------------------------------------------------------|----------|--------------------|--------------------------------------------------------|
| FR-BULK-001   | The system shall allow users to upload CSV files. Maximum file size: 50MB. Supported encodings: UTF-8, Shift_JIS. | P1       | Order Service      | Upload succeeds for valid files.                       |
| FR-BULK-002   | The system shall validate CSV column structure, data types, and required fields. Error rows are identified and reported. | P1       | Order Service      | Validation results are displayed after upload.          |
| FR-BULK-003   | The system shall create orders in bulk from validated CSV data. Supports 100–10,000 orders per batch. | P1       | Order Service      | 10,000 orders are created within 5 minutes.            |
| FR-BULK-004   | The system shall process payments in bulk for created orders. Each payment is processed individually. | P1       | Payment Service    | All payments are processed; individual errors handled. |
| FR-BULK-005   | The system shall send confirmation emails in bulk for imported orders.                            | P2       | Notification Service | All customers receive confirmation emails.             |
| FR-BULK-006   | The system shall display real-time progress tracking for import processing (processed/total count). | P1       | Order Service      | Progress bar updates in real time.                     |
| FR-BULK-007   | The system shall handle partial failures: successful orders are retained, failed orders can be downloaded as a list. | P1       | Order Service      | List of failed orders is downloadable.                 |
| FR-BULK-009   | The system shall allow download of a correctly formatted CSV template.                            | P3       | Order Service      | Template is downloadable and usable as-is.             |
| FR-BULK-010   | The system shall support cancellation of in-progress imports; unprocessed orders are not created. | P3       | Order Service      | Cancellation prevents creation of unprocessed orders.   |

**References:**  
[KB-063a89e7-bb79-4435-993b-95ec7b9a9e4e], [KB-2d968f58-3ed8-4207-9d71-0c429c197cb4], [KB-35c9e00d-f446-4174-be65-d214ecbff895], [KB-6aa21c29-11f1-4b6b-b8e8-2c9990900522], [KB-89dddd9a-2e13-46e7-99a4-34c3f7e21e]

---

### 4.1.5 API Endpoints

#### Order Service

| Endpoint                                   | Description                                 |
|--------------------------------------------|---------------------------------------------|
| POST /api/v1/orders/                       | Create a 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 and notification) |
| POST /api/v1/orders/{order_id}/webhook     | Receive payment status update (single order) |

**References:**  
[KB-459cbd85-fb6b-4a7e-8a36-e5f711cac6b9], [KB-4287fde1-e2d9-4e31-8f2f-5c3f64f00add], [KB-69d55b34-e506-4b4e-a043-ef842030f397]

#### Payment Service

| Endpoint                                   | Description                                 |
|--------------------------------------------|---------------------------------------------|
| POST /api/v1/payments/                     | Create payment for a single order           |
| GET /api/v1/payments/{payment_id}          | Retrieve payment by payment ID              |
| GET /api/v1/payments/order/{order_id}      | Retrieve payment for a specific order       |
| 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]

#### Notification Service

| 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 by ID                 |
| GET /api/v1/notifications/order/{order_id} | Retrieve all notifications for an order     |

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

---

## 4.2 Interface Requirements

### 4.2.1 Service Integration

| Caller Service   | Callee Service      | Endpoint                                         | Trigger                        | Payload/Contract                                      |
|------------------|--------------------|--------------------------------------------------|--------------------------------|-------------------------------------------------------|
| Order Service    | Payment Service    | POST /api/v1/payments/                           | Order creation                 | {"order_id": N, "amount": N.N, "currency": "JPY"}     |
| Payment Service  | Order Service      | POST /api/v1/orders/{order_id}/webhook           | Payment status change          | {"payment_status": "completed", "transaction_id": "..."} |
| Order Service    | Notification Service | POST /api/v1/notifications/email                | Order creation, status change, cancellation | {"order_id": N, "to_email": "...", "template_name": "...", "template_data": {...}} |

**References:**  
[KB-5a54adc1-e1bc-4649-9fe6-237c50ce768c], [KB-4bd8168d-aed4-41eb-8733-2ab9d82daa22], [KB-69d55b34-e506-4b4e-a043-ef842030f397]

---

## 4.3 Constraints

- **Single Order Processing:** All order, payment, and notification endpoints process one order per request. There is no batch or bulk endpoint for payments or notifications. Bulk order creation (via CSV import) results in individual order and payment requests per order.  
  **References:** [KB-8072a75f-d61d-49b1-a859-1be86806c449], [KB-564ae239-84b1-4ef2-bb04-b7e829eb53b6]
- **Payment Amount Limit:** Maximum payment amount per transaction is 1,000,000 JPY.  
  **References:** [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6], [KB-8072a75f-d61d-49b1-a859-1be86806c449]
- **Order-Payment Relationship:** Each order must have at most one payment; duplicate payments for the same order are rejected.  
  **References:** [KB-299da2e5-721b-4ab1-9bb0-cd2d0f03c8c6]
- **CSV Import Limits:** Bulk import supports 100–10,000 orders per file. Maximum file size is 50MB.  
  **References:** [KB-063a89e7-bb79-4435-993b-95ec7b9a9e4e], [KB-35c9e00d-f446-4174-be65-d214ecbff895]
- **Notification Rate Limiting:** Email notifications are rate-limited to 10 per second.  
  **References:** [KB-582e7673-bd66-493e-b511-017708ae9326]

---

## 4.4 Business Requirements

- The system shall support bulk order creation via CSV import to improve operational efficiency for corporate customers, addressing requests for importing 100–10,000 orders at once.  
  **References:** [KB-2b0238e6-fb8b-4b64-bbb0-73de35f73a08], [KB-6ef0a78b-63b6-493a-a7b0-76398d5a2889], [KB-9722c127-de97-4494-bb8d-1d840efa8899], [KB-94407aa3-d1ac-4455-a68c-265236fefec4]

---

## 4.5 Gaps

- [GAP: Missing data for Requirements] (No requirements for user authentication, authorization, or audit logging are specified in the provided context for the order/payment/notification modules. If required, reference to security requirements should be added from relevant context blocks.)

---

**End of Requirements Section**