# 현금영수증 취소

원문: https://developers.bootpay.ai/api/cash-receipt/cancel

> 결제 건 발행분과 별건 발행분 현금영수증을 각각 취소하는 방법

발행한 현금영수증을 취소합니다. **결제 건에 발행**한 영수증과 **별건 발행**한 영수증은 취소 엔드포인트가 다릅니다. 발행 시 사용한 방식에 맞춰 호출합니다.

모두 서버에서 [Basic Auth](https://developers.bootpay.ai/api/common/authentication)로 호출합니다.

| 발행 방식 | 취소 엔드포인트 |
| --- | --- |
| 결제 건에 발행 (`/request/receipt/cash/publish`) | `DELETE /v2/request/receipt/cash/cancel/{receipt_id}` |
| 별건 발행 (`/request/cash/receipt`) | `DELETE /v2/request/cash/receipt/{receipt_id}` |

---

## 1. 결제 건 발행분 취소

[결제 건에 발행](https://developers.bootpay.ai/api/cash-receipt/publish#1-결제-건에-발행)한 현금영수증을 취소합니다. 취소 대상은 결제의 `receipt_id`입니다.

::: info 결제를 취소하면 현금영수증도 함께 정리됩니다
결제 건에 발행한 현금영수증이 있는 결제를 [결제 취소 API](https://developers.bootpay.ai/api/pg/server/cancel)로 취소하면, 부트페이가 기존 현금영수증을 취소하고 잔액이 남은 부분취소라면 남은 결제금액으로 다시 발행합니다. 결제 취소 때문에 이 API를 따로 호출할 필요는 없습니다.
재발행이 실패해도 결제 취소 결과는 되돌려지지 않습니다. 부분취소 뒤에는 결제 조회의 `bank_data`·`vbank_data` 안 `cash_receipt_no`로 재발행 여부를 확인합니다.
:::

::: endpoint
method: DELETE
url: https://api.bootpay.co.kr/v2/request/receipt/cash/cancel/{receipt_id}
auth: Basic Auth
:::

::: parameters

| 파라미터 | 위치 | 필수 | 설명 |
| --- | --- | --- | --- |
| `receipt_id` | Path | Y | 현금영수증을 발행했던 결제의 영수증 ID |

:::

::: info 취소자명·취소 사유는 받지 않습니다
결제 건 발행분 취소는 `cancel_username`·`cancel_message`를 본문에 담아 보내도 사용하지 않습니다. 서버가 받아들이기만 하고 PG로 전달하거나 저장하지 않으니, 취소 사유를 남겨야 한다면 가맹점 쪽에 별도로 기록합니다.
:::

::: code-group sync=backend

```bash [cURL]
curl -X DELETE "https://api.bootpay.co.kr/v2/request/receipt/cash/cancel/RECEIPT_ID" \
  -H "Authorization: Basic $(printf '%s' 'CLIENT_KEY:SECRET_KEY' | base64)"
```

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

Bootpay.setConfiguration({
    client_key: process.env.BOOTPAY_CLIENT_KEY,
    secret_key: process.env.BOOTPAY_SECRET_KEY,
})

await Bootpay.cashReceiptCancelOnReceipt({
    receipt_id: '[ receipt_id ]',
})
// 성공 시 HTTP 200, 본문은 JSON 리터럴 null 입니다.
```

```python [Python]
from bootpay_backend import BootpayBackend

bootpay = BootpayBackend(client_key='CLIENT_KEY', secret_key='SECRET_KEY')

response = bootpay.cash_receipt_cancel_on_receipt(receipt_id='[ receipt_id ]')
print(response)
```

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

BootpayApi::setClientKeyConfiguration('CLIENT_KEY', 'SECRET_KEY');
$response = BootpayApi::cashReceiptCancelOnReceipt('[ receipt_id ]');
print_r($response);
```

```java [Java]
import kr.co.bootpay.pg.Bootpay;
import kr.co.bootpay.pg.model.request.Cancel;

Bootpay bootpay = Bootpay.withClientKey("CLIENT_KEY", "SECRET_KEY");
Cancel cancel = new Cancel();
cancel.receiptId = "[ receipt_id ]";

var response = bootpay.requestCashReceiptCancelByBootpay(cancel);
System.out.println(response);
```

```ruby [Ruby]
bootpay = Bootpay::RestClient.new(client_key: 'CLIENT_KEY', secret_key: 'SECRET_KEY')
# Ruby 헬퍼는 cancel_username · cancel_message 를 필수 인자로 받지만 서버는 이 값을 쓰지 않습니다
response = bootpay.cash_receipt_cancel_on_receipt(
  receipt_id: '[ receipt_id ]',
  cancel_username: '홍길동',
  cancel_message: '현금영수증 취소'
)
puts response.data
```

```go [Go]
import "github.com/bootpay/backend-go/v2"

api := bootpay.NewAPIWithClientKey("CLIENT_KEY", "SECRET_KEY", nil, "")
response, err := api.RequestCashReceiptCancelByBootpay(bootpay.CancelData{
    ReceiptId: "[ receipt_id ]",
})
fmt.Println(response, err)
```

```csharp [.NET]
using Bootpay;
using Bootpay.models;

var bootpay = BootpayApi.WithClientKey("CLIENT_KEY", "SECRET_KEY");
var response = await bootpay.RequestCashReceiptCancelByBootpay(new Cancel
{
    receiptId = "[ receipt_id ]"
});
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

:::

::: tip 응답 본문
결제 건 발행분 취소는 성공 시 HTTP 200에 본문 `null`(JSON 리터럴)을 돌려줍니다.
빈 문자열이 아니라 `null`이므로 JSON 파서가 `null`을 반환해도 정상입니다.
에러가 없으면 취소된 것으로 처리하고, 필요하면 결제 조회로 현금영수증 발행 여부를 확인합니다.
:::

---

## 2. 별건 발행분 취소

[별건 발행](https://developers.bootpay.ai/api/cash-receipt/publish#2-별건-발행)한 현금영수증을 취소합니다. 취소 대상은 별건 발행 응답에서 받은 `receipt_id`입니다.

::: endpoint
method: DELETE
url: https://api.bootpay.co.kr/v2/request/cash/receipt/{receipt_id}
auth: Basic Auth
:::

::: parameters

| 파라미터 | 위치 | 필수 | 설명 |
| --- | --- | --- | --- |
| `receipt_id` | Path | Y | 별건 발행 시 받은 현금영수증 영수증 ID |
| `cancel_username` | Body | N | 취소자명 |
| `cancel_message` | Body | N | 취소 사유 |

:::

::: code-group sync=backend

```bash [cURL]
curl -X DELETE "https://api.bootpay.co.kr/v2/request/cash/receipt/RECEIPT_ID" \
  -H "Authorization: Basic $(printf '%s' 'CLIENT_KEY:SECRET_KEY' | base64)" \
  -H "Content-Type: application/json" \
  -d '{ "cancel_username": "홍길동", "cancel_message": "오발행 취소" }'
```

```javascript [Node.js]
const response = await Bootpay.cancelCashReceipt({
    receipt_id: '[ receipt_id ]',
    cancel_username: '홍길동',
    cancel_message: '오발행 취소',
})
console.log(response.status) // status 61: 발행취소
```

```python [Python]
response = bootpay.cancel_cash_receipt(
    receipt_id='[ receipt_id ]',
    cancel_username='홍길동',
    cancel_message='오발행 취소'
)
print(response)  # status 61: 발행취소
```

```php [PHP]
$response = BootpayApi::cancelCashReceipt('[ receipt_id ]', [
    'cancel_username' => '홍길동',
    'cancel_message' => '오발행 취소',
]);
print_r($response);
```

```java [Java]
Cancel cancel = new Cancel();
cancel.receiptId = "[ receipt_id ]";
cancel.cancelUsername = "홍길동";
cancel.cancelMessage = "오발행 취소";

var response = bootpay.requestCashReceiptCancel(cancel);
System.out.println(response.get("status")); // 61: 발행취소
```

```ruby [Ruby]
response = bootpay.cancel_cash_receipt(
  receipt_id: '[ receipt_id ]',
  cancel_username: '홍길동',
  cancel_message: '오발행 취소'
)
puts response.data
```

```go [Go]
response, err := api.RequestCashReceiptCancel(bootpay.CancelData{
    ReceiptId:      "[ receipt_id ]",
    CancelUsername: "홍길동",
    CancelMessage:  "오발행 취소",
})
fmt.Println(response, err)
```

```csharp [.NET]
var response = await bootpay.RequestCashReceiptCancel(new Cancel
{
    receiptId = "[ receipt_id ]",
    cancelUsername = "홍길동",
    cancelMessage = "오발행 취소"
});
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

:::

### 응답 예시

```json
{
  "receipt_id": "62f356871fc192036f9f4ae2",
  "order_id": "cash_1700000000",
  "price": 10000,
  "tax_free": 0,
  "cancelled_price": 10000,
  "cancelled_tax_free": 0,
  "order_name": "현장 수령 현금결제",
  "company_name": "테스트상점",
  "gateway_url": "https://api.bootpay.co.kr",
  "metadata": {},
  "sandbox": false,
  "pg": "나이스페이먼츠",
  "method": "현금영수증",
  "method_symbol": "cash_receipt",
  "method_origin": "현금영수증",
  "method_origin_symbol": "cash_receipt",
  "purchased_at": "2026-04-10T15:56:08+09:00",
  "cancelled_at": "2026-04-10T17:27:20+09:00",
  "requested_at": "2026-04-10T15:56:02+09:00",
  "status_locale": "현금영수증발행취소",
  "currency": "KRW",
  "status": 61,
  "cash_receipt_data": {
    "tid": "Ae75jWNka9lpP2YxJ4K87RXb62PYLrRGZwXLObgyB0vMDm1d",
    "cash_receipt_type": 1,
    "cash_receipt_no": "158190158",
    "receipt_url": "https://.../receipts/cash-receipt/..."
  }
}
```

::: tip cancel_tid 자리
`cash_receipt_data`에는 취소 거래 ID를 담는 `cancel_tid` 키 자리가 있지만, 현금영수증 취소 흐름에서는 이 값이 채워지지 않아 응답에서 빠집니다. 취소 여부는 `status`(`61`)와 `cancelled_at`으로 판단합니다.
:::

---

## 에러 코드

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

::: error-codes

| 코드 | 의미 | 대처 방법 |
| --- | --- | --- |
| `RC_NOT_FOUND` | 영수증 정보를 찾지 못했습니다 | `receipt_id`가 올바른지 확인합니다 |
| `RC_CASH_RECEIPT_CANCEL_NOT_ABLE` (2816) | 별건으로 현금영수증 발행이 된 결제가 아닙니다 — 실제로는 "이 결제 건에 현금영수증이 발행되어 있지 않다"는 뜻입니다 (결제 건 발행분 취소) | 발행 여부를 먼저 조회합니다 |
| `RC_NOT_CASH_RECEIPT` (2805) | 별건 현금영수증이 아닙니다 (별건 발행분 취소) | 결제 건 발행분은 `/request/receipt/cash/cancel/{receipt_id}`로 취소합니다 |
| `RC_CASH_RECEIPT_ALREADY_CANCELLED` (2804) | 이미 취소된 현금영수증입니다 | 상태(`status: 61`)를 먼저 조회합니다 |
| `RC_CASH_RECEIPT_NOT_SUCCESS` (2806) | 발행 완료 상태(`status: 60`)가 아닙니다 | 발행 결과를 먼저 확인합니다 |
| `RC_CASH_RECEIPT_CANCEL_FAILED` (2047) | 현금영수증 취소에 실패했습니다 | PG가 취소 실패로 응답했거나 취소 처리 중 예외가 난 경우입니다. `pg_error_code`와 `message`로 PG 응답을 확인합니다. 발행 방식과 취소 엔드포인트가 어긋난 경우는 2805·2816으로 따로 내려옵니다 |
| `RC_CASH_RECEIPT_CANCEL_ERROR` (2807) | 취소 처리 중 서버 오류가 발생했습니다 | `message`를 확인하고 재시도합니다 |

:::

::: warning 2047·2807은 message가 비어 보일 수 있습니다
이 두 코드는 한국어 메시지가 정의돼 있지 않아서, PG 응답 메시지가 없으면 `message`가 `Translation missing: ko.error.code.2047` 같은 문자열로 내려옵니다.
분기 처리는 `message`가 아니라 `error_code` 기준으로 작성합니다.
:::
