# 해지 수수료 계산

원문: https://commerce.bootpay.ai/api/subscription-contract/calculate

> 구독을 해지하기 전에 예상 해지 수수료와 마지막 회차 환불 금액을 계산합니다. 조회만 하며, 받은 금액은 해지 요청에 그대로 넣습니다.

[v1 API 상세 명세](https://commerce.bootpay.ai/api/reference/v1/order-subscriptions)

구독을 해지하기 전에 예상 수수료와 환불 금액을 조회합니다. 해지 전에 고객에게 금액을 안내할 때 씁니다.

## API 엔드포인트

::: endpoint
method: GET
url: https://api.bootapi.com/v1/order_subscriptions/requests/ing/calculate_termination_fee?order_subscription_id=:order_subscription_id
auth: [Basic Auth](https://commerce.bootpay.ai/api/server/authentication)
:::

## 요청 파라미터

::: parameters

| 파라미터 | 타입 | 필수 | 설명 |
|---------|------|------|------|
| order_subscription_id | String | 조건부 | 구독 계약 ID (쿼리). 없으면 `order_number`가 필수입니다 |
| order_number | String | 조건부 | 구독 주문번호. `order_subscription_id`가 없으면 필수입니다 |
| user_id | String | N | 로그인한 회원 ID 또는 이 몰의 외부 회원 ID. 보내면 구독 소유자와 대조합니다. `Bootpay-User-JWT` 헤더로 보내도 됩니다 |

:::

## 코드 예제

::: code-group

```bash [cURL]
curl -X GET "https://api.bootapi.com/v1/order_subscriptions/requests/ing/calculate_termination_fee?order_subscription_id={order_subscription_id}" \
  -H "Authorization: Basic {base64(client_key:secret_key)}" \
  -H "Content-Type: application/json"
```

```javascript [Node.js]
import { BootpayCommerce } from '@bootpay/backend-js';

const commerce = new BootpayCommerce({
    client_key: '{client_key}',
    secret_key: '{secret_key}'
});

const response = await commerce.orderSubscription.requestIng.calculateTerminationFee('sub_abc123');
console.log(response);
```

```python [Python]
from bootpay_backend.commerce import BootpayCommerce

commerce = BootpayCommerce('{client_key}', '{secret_key}')
response = commerce.order_subscription.request_ing.calculate_termination_fee('sub_abc123')
print(response)
```

```php [PHP]
use Bootpay\ServerPhp\BootpayCommerceApi;

$commerce = new BootpayCommerceApi("{client_key}", "{secret_key}");
$response = $commerce->orderSubscription->requestIng->calculateTerminationFee('sub_abc123');
print_r($response);
```

```java [Java]
import kr.co.bootpay.store.BootpayStore;
import kr.co.bootpay.store.model.request.TokenPayload;
import kr.co.bootpay.store.model.response.BootpayStoreResponse;

TokenPayload tokenPayload = new TokenPayload("{client_key}", "{secret_key}");
BootpayStore commerce = new BootpayStore(tokenPayload).withToken();

BootpayStoreResponse response =
    commerce.orderSubscription.requestIng.calculateTerminationFee("sub_abc123");
System.out.println(response);
```

```ruby [Ruby]
require 'bootpay'

commerce = BootpayStore::RestClient.new(client_key: '{client_key}', secret_key: '{secret_key}')
response = commerce.order_subscription_calculate_termination_fee(
  order_subscription_id: 'sub_abc123'
)
puts response.data
```

```go [Go]
commerce := bootpay.NewCommerceAPI("{client_key}", "{secret_key}", nil, "production")
response, err := commerce.OrderSubscription.RequestIng.CalculateTerminationFee("sub_abc123", "")
fmt.Println(response, err)
```

```csharp [.NET]
var commerce = new BootpayCommerceApi("{client_key}", "{secret_key}");
var response = await commerce.OrderSubscriptionCalculateTerminationFee("sub_abc123");
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

:::

## 응답

```json
{
  "termination": {
    "order_subscription_id": "687a1b2c3d4e5f6789012345",
    "use_termination": true,
    "use_termination_approval": true,
    "remaining_duration": 3,
    "remaining_price": 90000,
    "termination_fee": 30000,
    "last_bill_refund_price": 15000,
    "final_fee": 15000,
    "final_tax_free": 0,
    "price": 30000,
    "service_end_at": "2025-08-31T23:59:59+09:00",
    "is_unlimited": false
  },
  "has_pending_request": false
}
```

## 응답 파라미터

| 파라미터 | 타입 | 설명 |
|---------|------|------|
| termination | Object | 해지 계산 결과 |
| &nbsp;&nbsp;└─ order_subscription_id | String | 구독 계약 ID |
| &nbsp;&nbsp;└─ remaining_duration | Integer | 남은 회차 수 (무제한 회차면 `null`) |
| &nbsp;&nbsp;└─ remaining_price | Number | 남은 회차 금액 |
| &nbsp;&nbsp;└─ termination_fee | Number | 예상 해지 수수료 |
| &nbsp;&nbsp;└─ last_bill_refund_price | Number | 마지막 회차 환불 예상 금액 |
| &nbsp;&nbsp;└─ final_fee | Number | 최종 정산 금액 (`termination_fee − last_bill_refund_price`). 양수면 추가 결제, 음수면 환불 |
| &nbsp;&nbsp;└─ final_tax_free | Number | 최종 정산 금액 중 비과세 |
| &nbsp;&nbsp;└─ service_end_at | String | 서비스 종료 예정일 |
| &nbsp;&nbsp;└─ is_unlimited | Boolean | 무제한 회차 계약 여부 |
| has_pending_request | Boolean | 처리 대기 중인 요청이 있는지 |

해지 요청을 보낼 때는 여기서 받은 `termination_fee`·`last_bill_refund_price`·`final_fee` 를 그대로 넣습니다.

## 에러 코드

::: info 공통 에러
인증·권한 관련 에러는 [에러 코드표](https://commerce.bootpay.ai/api/reference/codes#커머스-api-인증-에러)를 참고합니다.
:::

::: error-codes

| 코드 | 메시지 | 대처 방법 |
|------|--------|-----------|
| `ORDER_SUBSCRIPTION_NOT_FOUND` | 구독결제 건을 찾을 수 없습니다. | order_subscription_id를 확인합니다 |
| `ORDER_SUBSCRIPTION_TERMINATE_UNABLE` | 이미 해지되었거나 해지할 수 없는 구독 상태입니다 | 구독 상태를 확인합니다 |

:::

::: tip
이 API는 조회 전용입니다. 실제 해지는 [해지 요청](https://commerce.bootpay.ai/api/subscription-ops/manage/terminate) API를 사용합니다.
:::
