# 연동 흐름

카탈로그 또는 확인된 범위를 읽고 견적이나 revision을 확인한 뒤 한 번 제출하고 저장된 작업과 배송 상태를 추적하세요.

## 카탈로그 및 구매

```text
products → catalog → quote → purchase
                         ↓
purchase_status → order_delivery → order_proxies
```

다국가 구매는 국가별 주문과 하나의 다중 항목 청구서를 만듭니다. 할인은 국가별로 계산됩니다. accepted는 대기열 접수이며 배송 완료가 아닙니다.

## 갱신

```text
renewal_options → renewal_quote → renewal → renewal_status
```

## 추가 로그인

```text
extra_login_options → extra_login_create → extra_login_operation_status
```

## Residential 목록 및 트래픽

```text
residential_catalog → residential_quote → residential_purchase
                                              ↓
residential_purchase_status → order_delivery → residential_package_refresh
```

## Idempotency-Key

각 쓰기 작업의 Idempotency-Key를 저장하세요. 시간 초과나 HTTP 5xx는 실패의 증거가 아닙니다. 같은 키로 상태를 조회하고 불확실성을 해결하려고 새 키로 다시 실행하지 마세요.

- [**구매 상태 확인 →****GET** `/orders/create/status`](https://docs.arnproxy.com/ko/api-v1/orders/create/status)
- [**갱신 상태 →****GET** `/renewals/status`](https://docs.arnproxy.com/ko/api-v1/renewals/status)
- [**로그인 작업 확인 →****GET** `/extra-logins/status`](https://docs.arnproxy.com/ko/api-v1/proxies/extra-logins/status)
- [**Residential 배송 상태 →****GET** `/residential/orders/status`](https://docs.arnproxy.com/ko/api-v1/residential/orders/status)

---
[ARNPROXY API](https://docs.arnproxy.com/ko/api-v1/workflows)

## 사용 목적: 하위 목적만 선택

일반 주문에서 두 가지 목적을 따로 선택하게 하지 마세요. catalog.purposes에서 id=201을 찾고 children만 표시합니다. purchase의 purpose_id는 정수 201로 고정하고 subpurpose_id에는 선택한 하위 ID를 넣습니다. 기존 연동과의 호환성을 위해 카탈로그 계층 구조는 유지됩니다.

quote의 주문 항목에는 목적을 보내지 않습니다. location_id, time_id, quantity만 필요하며 목적은 purchase 단계에서 필수입니다.

```javascript
const response = await fetch(
  'https://www.arnproxy.com/account/api/v1/catalog?product_id=' + productId,
  { headers: { Authorization: 'Bearer ' + apiKey } }
);
const catalog = await response.json();
if (!response.ok || !catalog.ok) throw new Error('Catalog request failed');
const purposeGroup = catalog.data.purposes.find(group => group.id === 201);
if (!purposeGroup) throw new Error('Purpose group 201 is not available');
const purposeOptions = purposeGroup.children.map(({ id, name }) => ({ id, name }));
// Show only purposeOptions. The customer selects selectedSubpurposeId.
const purchaseLine = {
  location_id: selectedLocationId,
  time_id: selectedTimeId,
  quantity: selectedQuantity,
  purpose_id: 201,
  subpurpose_id: selectedSubpurposeId
};
// Add other_purpose (1–30 characters) only when selectedSubpurposeId === -1.
// No purchase is sent by this example.
```

```python
import json
import urllib.request

request = urllib.request.Request(
    'https://www.arnproxy.com/account/api/v1/catalog?product_id=' + str(product_id),
    headers={'Authorization': 'Bearer ' + api_key}
)
with urllib.request.urlopen(request, timeout=20) as response:
    catalog = json.load(response)
if not catalog.get('ok'):
    raise RuntimeError('Catalog request failed')
purpose_group = next((g for g in catalog['data']['purposes'] if g['id'] == 201), None)
if purpose_group is None:
    raise RuntimeError('Purpose group 201 is not available')
purpose_options = [{'id': p['id'], 'name': p['name']} for p in purpose_group['children']]
# Display only purpose_options; the customer selects selected_subpurpose_id.
purchase_line = {
    'location_id': selected_location_id,
    'time_id': selected_time_id,
    'quantity': selected_quantity,
    'purpose_id': 201,
    'subpurpose_id': selected_subpurpose_id,
}
# For Other (-1), also set other_purpose to 1–30 characters.
# This example does not submit a purchase.
```

### “기타” 사용 목적

기타를 선택하면 subpurpose_id=-1과 1–30자의 other_purpose를 보냅니다. 다른 선택에는 other_purpose가 필요하지 않습니다. purpose_id는 여전히 201입니다.

```json
{
  "location_id": 10,
  "time_id": 101,
  "quantity": 1,
  "purpose_id": 201,
  "subpurpose_id": -1,
  "other_purpose": "Custom purpose"
}
```

## Residential: 신규 패키지와 GB 추가의 차이

Residential 주문에서는 고객이 용도를 선택하지 않습니다. 새 패키지는 웹사이트 주문과 같은 고정 용도를 서버가 자동 지정하므로 purpose_id, subpurpose_id 또는 other_purpose를 보내지 마세요. 트래픽 충전은 기존 패키지 용도를 유지합니다.

ID와 가격은 예시입니다. 카탈로그와 동일 견적의 실제 값을 사용하고 JSON ID 및 expected_total_minor는 숫자로 보내세요. 예제의 terms=false는 안전을 위한 값입니다. 실제 유료 작업에 대한 고객의 명시적 동의 후에만 terms=true를 보내세요.

## 동일 유형으로 두 국가 주문

하나의 product_id에 서로 다른 location_id를 최대 20개 사용할 수 있습니다. 국가별로 별도 주문이 생성되며 연결된 결제는 하나의 청구서로 처리됩니다. 수량 할인은 국가별 수량으로 계산합니다.

```json
{
  "product_id": 5,
  "lines": [
    {
      "location_id": 10,
      "time_id": 101,
      "quantity": 1,
      "purpose_id": 201,
      "subpurpose_id": 202
    },
    {
      "location_id": 11,
      "time_id": 102,
      "quantity": 1,
      "purpose_id": 201,
      "subpurpose_id": 202
    }
  ],
  "currency": "TRY",
  "expected_total_minor": 2000,
  "promo_code": "",
  "terms": false
}
```

## Residential: 신규 패키지와 GB 추가의 차이 · mode=new

Residential 주문에서는 고객이 용도를 선택하지 않습니다. 새 패키지는 웹사이트 주문과 같은 고정 용도를 서버가 자동 지정하므로 purpose_id, subpurpose_id 또는 other_purpose를 보내지 마세요. 트래픽 충전은 기존 패키지 용도를 유지합니다.

```json
{
  "mode": "new",
  "location_id": 20,
  "time_id": 201,
  "promo_code": "",
  "currency": "TRY",
  "expected_total_minor": 1000,
  "expected_selection_hash": "0000000000000000000000000000000000000000000000000000000000000000",
  "terms": false
}
```

## Residential: 신규 패키지와 GB 추가의 차이 · mode=topup

Residential 주문에서는 고객이 용도를 선택하지 않습니다. 새 패키지는 웹사이트 주문과 같은 고정 용도를 서버가 자동 지정하므로 purpose_id, subpurpose_id 또는 other_purpose를 보내지 마세요. 트래픽 충전은 기존 패키지 용도를 유지합니다.

```json
{
  "mode": "topup",
  "package_id": 10001,
  "time_id": 201,
  "promo_code": "",
  "currency": "TRY",
  "expected_total_minor": 1000,
  "expected_selection_hash": "0000000000000000000000000000000000000000000000000000000000000000",
  "terms": false
}
```

## CSV 내보내기

CSV 열은 id, endpoint, ip, port, login, password 중에서 선택합니다. 사용자 지정 형식은 문서화된 %...% 토큰만 허용하며 코드를 실행하지 않습니다. 접속 정보가 포함되면 credentials 권한이 필요합니다. 내용은 JSON으로 반환되며 파일 저장은 애플리케이션이 수행합니다.

```json
{
  "proxy_ids": [
    10001
  ],
  "format": "csv",
  "columns": [
    "id",
    "endpoint"
  ]
}
```

## 사용자 지정 연결 형식

CSV 열은 id, endpoint, ip, port, login, password 중에서 선택합니다. 사용자 지정 형식은 문서화된 %...% 토큰만 허용하며 코드를 실행하지 않습니다. 접속 정보가 포함되면 credentials 권한이 필요합니다. 내용은 JSON으로 반환되며 파일 저장은 애플리케이션이 수행합니다.

```json
{
  "proxy_ids": [
    10001
  ],
  "format": "custom",
  "template": "%login%:%password%@%endpoint%"
}
```

## 접수는 배송 완료가 아닙니다

HTTP 201/202 또는 state=accepted는 접수만 뜻할 수 있습니다. purchase_status / residential_purchase_status로 같은 작업을, order_delivery로 배송을 추적하세요. poll_after_seconds와 Retry-After가 있으면 따르세요. 시간 초과 후 새 Idempotency-Key로 재구매하지 마세요.
