# 링크 생성

원문: https://commerce.bootpay.ai/api/link-payment/create

> 결제 링크를 만드는 API — 요청 파라미터와 응답

결제 링크(Invoice)를 만듭니다. `use_notification: true` 면 고객에게 결제 안내도 보냅니다.

::: info 상품 없는 링크페이
링크페이는 상품 없이 결제할 수 있습니다. 주문명(`name`)·금액(`price`)·고객(`user.user_id`)·식별자(`request_id`)로 링크를 만듭니다.

`products` 를 넣으면 상품 기준으로 금액을 다시 계산하고 재고·구독 설정을 적용합니다. 넣지 않으면 전달한 `price` 를 그대로 청구합니다.
:::

::: tip 코드 없이 생성하려면
관리자 콘솔 화면에서 링크페이를 만들어도 됩니다(매뉴얼 [결제 링크 만들기](https://blog.bootpay.ai/articles/link-pay-create)). API 와 다른 점은 아래 [API 와 관리자 콘솔 차이](#api-와-관리자-콘솔-차이)에 있습니다.
:::

## API 엔드포인트

::: endpoint
method: POST
url: https://api.bootapi.com/v1/invoices
auth: [Basic Auth](https://commerce.bootpay.ai/api/server/authentication)
:::

## 처리 흐름

:::canvas-flow
{
  "nodes": [
    { "id": "create", "label": "링크 생성\n이 API", "col": 0, "row": 0, "type": "process" },
    { "id": "send", "label": "결제 안내 발송\n이메일 · SMS · 알림톡", "col": 1, "row": 0 },
    { "id": "pay", "label": "고객이 링크에서 결제", "col": 2, "row": 0 },
    { "id": "hook", "label": "웹훅으로 결과 전달\n고객에게 완료 알림", "col": 3, "row": 0, "type": "success" }
  ],
  "edges": [
    { "from": "create", "to": "send" },
    { "from": "send", "to": "pay" },
    { "from": "pay", "to": "hook" }
  ],
  "direction": "LR"
}
:::

상품 없이 만들기 · 상품으로 만들기와 링크 상태는 [링크페이](https://commerce.bootpay.ai/docs/link-payment)에 있습니다.

::: tip
링크를 만들기 전에 결제할 고객 정보(이메일, 휴대폰 번호, 이름)를 먼저 등록해 두면, 그 고객의 `user_id` 를 `user` 파라미터로 넣어 바로 연결합니다.
:::

## 요청 파라미터

::: parameters

| 파라미터 | 타입 | 필수 | 설명 |
|---------|------|------|------|
| name | String | Y | 주문명 |
| price | Integer | Y | 결제 금액 |
| tax_free_price | Integer | N | 면세 금액 |
| delivery_price | Integer | N | 배송비 |
| memo | String | N | 내부 메모 |
| request_id | String | Y | 가맹점 고유 식별자 (웹훅 매칭용) — 비우면 `INVOICE_REQUEST_ID_BLANK` 로 거절됩니다 |
| redirect_url | String | N | 결제 완료 후 이동할 URL |
| webhook_url | String | N | 결제 결과를 받을 웹훅 URL |
| header_content_type | String | N | 웹훅 전송 시 Content-Type |
| usage_api_url | String | N | 사용량 기반 구독의 사용량 조회 URL |
| use_notification | Boolean | N | 알림 자동 발송 여부 |
| use_auto_login | Boolean | N | 링크 진입 시 자동 로그인 여부 |
| expired_at | String | N | 링크 만료 시간 (ISO 8601). **생략하면 생성일로부터 3일 뒤 자정**입니다. 과거 시각은 `INVOICE_EXPIRED_DATE_INVALID` 로 거절됩니다 |
| metadata | Object | N | 추가 데이터 |
| extra | Object | N | 결제창 부가 설정 |
| user | Object | Y | 고객 정보 — 없으면 `INVOICE_TARGET_NOT_FOUND` 로 거절됩니다 |
| &nbsp;&nbsp;└─ membership_type | String | N | 고객 유형 (`member` 기본 / `guest`) |
| &nbsp;&nbsp;└─ user_id | String | Y | 고객 ID — **이 값이 없으면 `user` 객체 전체가 무시돼 요청이 거절됩니다**. `member` 면 부트페이에 [등록된 고객](https://commerce.bootpay.ai/api/customer/register)의 `user_id`(몰 설정에 따라 로그인 ID·이메일도 가능)여야 하고, 없는 회원이면 `INVOICE_TARGET_NOT_FOUND` 입니다. `guest` 면 가맹점 쪽 식별자이고, 처음 보는 값이면 비회원 고객을 새로 만듭니다 |
| &nbsp;&nbsp;└─ name | String | N | 고객 이름 (`guest` 로 새로 만들 때 사용됩니다. 비우면 `비회원`) |
| &nbsp;&nbsp;└─ corporate_type | String | N | `member` 일 때 개인·기업 구분 (`individual` 기본 / `corporate`) |
| &nbsp;&nbsp;└─ email | String | N | 고객 이메일 |
| &nbsp;&nbsp;└─ phone | String | N | 고객 전화번호 |
| products | Array | N | 상품 목록 |
| &nbsp;&nbsp;└─ product_id | String | N | 상품 ID |
| &nbsp;&nbsp;└─ product_option_id | String | N | 옵션 ID. 옵션이 있는 상품이면 필수(`INVOICE_PRODUCT_OPTION_ID_REQUIRED`) |
| &nbsp;&nbsp;└─ quantity | Integer | N | 수량 |
| &nbsp;&nbsp;└─ duration | Integer | N | 구독 회차 수. 구독 기간이 설정된 구독 상품이면 필수 — 상품에 등록된 회차 중 하나여야 합니다(`INVOICE_PRODUCT_SUBSCRIPTION_DURATION_NOT_FOUND`). 수시결제·사용량 구독은 생략합니다. `subscription_duration` 으로 보내면 이 API 는 읽지 않습니다 |

:::

## 코드 예제

::: code-group

```bash [cURL]
curl -X POST "https://api.bootapi.com/v1/invoices" \
  -H "Authorization: Basic {base64(client_key:secret_key)}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Professional 플랜 구독",
    "price": 29900,
    "request_id": "invoice_20250801_0001",
    "use_notification": true,
    "expired_at": "2025-08-01T23:59:59Z",
    "redirect_url": "https://myshop.com/payment/complete",
    "user": {
      "membership_type": "guest",
      "user_id": "user_20250801",
      "email": "user@example.com",
      "phone": "01012345678"
    },
    "products": [
      {
        "product_id": "67c95e64d01640bb9859c629",
        "quantity": 1,
        "duration": 12
      }
    ]
  }'
```

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

const commerce = new BootpayCommerce({
    client_key: 'your-commerce-client-key',
    secret_key: 'your-commerce-secret-key',
    mode: 'production'
})

const response = await commerce.invoice.create({
    name: 'Professional 플랜 구독',
    price: 29900,
    request_id: 'invoice_20250801_0001',
    use_notification: true,
    expired_at: '2025-08-01T23:59:59Z',
    redirect_url: 'https://myshop.com/payment/complete',
    user: {
        membership_type: 'guest',   // 부트페이에 등록된 고객이면 생략하고 그 고객의 user_id 를 넣습니다
        user_id: 'user_20250801',
        email: 'user@example.com',
        phone: '01012345678'
    },
    products: [
        {
            product_id: '67c95e64d01640bb9859c629',
            quantity: 1,
            duration: 12
        }
    ]
})
console.log('invoice_url:', response.invoice_url)
```

```python [Python]
from bootpay_backend import BootpayCommerce

commerce = BootpayCommerce(
    client_key='your-commerce-client-key',
    secret_key='your-commerce-secret-key',
    mode='production'
)

response = commerce.invoice.create({
    'name': 'Professional 플랜 구독',
    'price': 29900,
    'request_id': 'invoice_20250801_0001',
    'use_notification': True,
    'expired_at': '2025-08-01T23:59:59Z',
    'redirect_url': 'https://myshop.com/payment/complete',
    'user': {
        'membership_type': 'guest',
        'user_id': 'user_20250801',
        'email': 'user@example.com',
        'phone': '01012345678'
    },
    'products': [
        {
            'product_id': '67c95e64d01640bb9859c629',
            'quantity': 1,
            'duration': 12
        }
    ]
})
print('invoice_url:', response['invoice_url'])
```

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

$commerce = new BootpayCommerceApi('your-commerce-client-key', 'your-commerce-secret-key');
$response = $commerce->invoice->create([
    'name' => 'Professional 플랜 구독',
    'price' => 29900,
    'request_id' => 'invoice_20250801_0001',
    'use_notification' => true,
    'expired_at' => '2025-08-01T23:59:59Z',
    'redirect_url' => 'https://myshop.com/payment/complete',
    'user' => [
        'membership_type' => 'guest',
        'user_id' => 'user_20250801',
        'email' => 'user@example.com',
        'phone' => '01012345678'
    ],
    'products' => [
        [
            'product_id' => '67c95e64d01640bb9859c629',
            'quantity' => 1,
            'duration' => 12
        ]
    ]
]);
echo 'invoice_url: ' . $response->invoice_url;
```

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

import java.util.Arrays;

TokenPayload tp = new TokenPayload("your-commerce-client-key", "your-commerce-secret-key");
BootpayStore commerce = new BootpayStore(tp).withToken();

SInvoiceUser user = new SInvoiceUser();
user.membershipType = SInvoiceUser.MEMBERSHIP_TYPE_GUEST;   // 등록된 고객이면 생략하고 그 고객의 user_id 를 넣습니다
user.userId = "user_20250801";   // 필수 — 이 값이 없으면 user 객체 전체가 무시됩니다
user.email = "user@example.com";
user.phone = "01012345678";

SInvoiceProduct product = new SInvoiceProduct();
product.productId = "67c95e64d01640bb9859c629";
product.quantity = 1;
product.duration = 12;

SInvoice invoice = new SInvoice();
invoice.name = "Professional 플랜 구독";
invoice.price = 29900.0;
invoice.requestId = "invoice_20250801_0001";   // 필수 — 가맹점 고유 식별자
invoice.useNotification = true;
invoice.expiredAt = "2025-08-01T23:59:59Z";
invoice.redirectUrl = "https://myshop.com/payment/complete";
invoice.user = user;
invoice.products = Arrays.asList(product);

BootpayStoreResponse response = commerce.invoice.create(invoice);
System.out.println("invoice_url: " + response.getData().get("invoice_url"));
```

```ruby [Ruby]
require 'bootpay'

commerce = BootpayStore::RestClient.new(client_key: 'your-commerce-client-key', secret_key: 'your-commerce-secret-key')
response = commerce.request_checkout(
  name: 'Professional 플랜 구독',
  price: 29900,
  request_id: 'invoice_20250801_0001',
  use_notification: true,
  expired_at: '2025-08-01T23:59:59Z',
  redirect_url: 'https://myshop.com/payment/complete',
  user: {
    membership_type: 'guest',
    user_id: 'user_20250801',
    email: 'user@example.com',
    phone: '01012345678'
  },
  products: [
    {
      product_id: '67c95e64d01640bb9859c629',
      quantity: 1,
      duration: 12
    }
  ]
)
puts "invoice_url: #{response.data[:invoice_url]}" # BootpayStore::Response — 본문은 data, 키는 심볼
```

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

commerce := bootpay.NewCommerceAPI("your-commerce-client-key", "your-commerce-secret-key", nil, "production")
// Go SDK 의 CommerceInvoice 구조체에는 user · products 칸이 없어 범용 Post 로 보냅니다
response, err := commerce.Post("invoices", map[string]interface{}{
    "name":             "Professional 플랜 구독",
    "price":            29900,
    "request_id":       "invoice_20250801_0001",
    "use_notification": true,
    "expired_at":       "2025-08-01T23:59:59Z",
    "redirect_url":     "https://myshop.com/payment/complete",
    "user": map[string]interface{}{
        "membership_type": "guest",
        "user_id":         "user_20250801",
        "email":           "user@example.com",
        "phone":           "01012345678",
    },
    "products": []map[string]interface{}{
        {"product_id": "67c95e64d01640bb9859c629", "quantity": 1, "duration": 12},
    },
})
if err != nil {
    log.Fatal(err)
}
fmt.Println("invoice_url:", response["invoice_url"])
```

```csharp [.NET]
using Bootpay.Commerce;
using System.Net.Http;

var commerce = new BootpayCommerceApi("your-commerce-client-key", "your-commerce-secret-key");
// .NET SDK 의 CommerceInvoice 에는 user · products 속성이 없어 SendAsync 로 보냅니다
var response = await commerce.SendAsync("invoices", HttpMethod.Post, new {
    name = "Professional 플랜 구독",
    price = 29900,
    request_id = "invoice_20250801_0001",
    use_notification = true,
    expired_at = "2025-08-01T23:59:59Z",
    redirect_url = "https://myshop.com/payment/complete",
    user = new {
        membership_type = "guest",
        user_id = "user_20250801",
        email = "user@example.com",
        phone = "01012345678"
    },
    products = new[] {
        new {
            product_id = "67c95e64d01640bb9859c629",
            quantity = 1,
            duration = 12
        }
    }
});
Console.WriteLine(await response.Content.ReadAsStringAsync());  // invoice_url 이 들어 있습니다
```

:::

## 응답

#### 성공 응답

주요 필드만 추린 예시입니다.

```json
{
  "invoice_id": "687a1b2c3d4e5f6789012345",
  "name": "Professional 플랜 구독",
  "price": 29900,
  "status": 1,
  "invoice_url": "https://i.bootpay.co.kr/i/{client_key}/687a1b2c3d4e5f6789012345",
  "user_id": "68707c59b0eacea5cd974efd",
  "expired_at": "2025-08-01 23:59:59",
  "c_at": "2025-07-29T10:00:00+09:00"
}
```

## 응답 필드 설명

| 필드 | 타입 | 설명 |
|------|------|------|
| `invoice_id` | String | 생성된 링크페이 ID (24자리) |
| `invoice_url` | String | 고객에게 전달할 결제 페이지 URL |
| `status` | Integer | 링크페이 상태 (`1` 결제 가능 — [링크페이 상태](https://commerce.bootpay.ai/api/reference/enum#링크페이-상태-status)) |
| `user_id` | String | 연결된 부트페이 고객 ID |
| `expired_at` | String | 링크 만료 시간 (`YYYY-MM-DD HH:MM:SS`) |
| `c_at` | String | 생성 시각 (ISO 8601) |

::: info `extra.create_order_immediately: true` 면 응답이 다릅니다
링크페이와 함께 주문 초안까지 바로 만들고, 위 링크페이 정보 대신 주문 정보([주문 상세](https://commerce.bootpay.ai/api/orders/detail)와 같은 필드, 결제 URL 은 `order_url`)를 돌려줍니다.
:::

## 에러 코드

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

::: error-codes

| 코드 | 메시지 | 대처 방법 |
|------|--------|-----------|
| `INVOICE_TARGET_NOT_FOUND` | 링크페이에 등록된 사용자 정보가 없습니다 | `user.user_id` 를 넣었는지, `member` 라면 부트페이에 등록된 고객인지 확인합니다 |
| `INVOICE_REQUEST_ID_BLANK` | 요청 ID가 필요합니다 | `request_id` 를 넣습니다 |
| `INVOICE_EXPIRED_DATE_INVALID` | 만료일이 현재 시간보다 과거입니다 | `expired_at` 을 미래 시각으로 넣습니다 |
| `PRODUCT_NOT_FOUND` | 존재하지 않는 상품입니다 | `product_id` 가 이 프로젝트의 상품인지 확인합니다 |
| `INVOICE_PRODUCT_NOT_FOUND` | 존재하지 않는 상품이 포함되어 있습니다 | 판매 중(노출) 상품인지 확인합니다 |
| `INVOICE_ITEM_QTY_LT_ZERO` | 상품 수량은 0보다 커야 합니다 | `quantity` 를 1 이상으로 넣습니다 |
| `INVOICE_PRODUCT_OPTION_ID_REQUIRED` | 옵션이 필요한 상품이 포함되어 있습니다 | `product_option_id` 를 넣습니다 |
| `INVOICE_PRODUCT_OPTION_NOT_FOUND` | 존재하지 않는 옵션이 포함되어 있습니다 | `product_option_id` 를 확인합니다 |
| `INVOICE_SUBSCRIPTION_REQUEST_ONLY_ONE` | 구독 상품은 하나만 청구서에 포함될 수 있습니다 | 구독 상품은 한 줄만 넣습니다 |
| `INVOICE_PRODUCT_SUBSCRIPTION_DURATION_NOT_FOUND` | 존재하지 않는 구독 기간이 포함되어 있습니다 | `duration` 을 상품에 등록된 회차로 넣습니다 |
| `INVOICE_NEED_USAGE_API_URL` | 사용량 기반 구독 상품은 사용량 API URL이 필요합니다 | 상품에 사용량 조회 URL 을 등록합니다 |

:::

::: tip
`use_notification: true` 면 고객에게 SMS, 카카오톡, 이메일로 결제 링크를 자동으로 보냅니다.
:::

## API 와 관리자 콘솔 차이

| 항목 | API | [관리자 콘솔](https://admin.bootpay.co.kr/order/invoice) |
|------|-----|------------|
| 생성 | 서버 코드로 생성 | 건별 수동 생성 |
| 대량 발송 | 반복 호출 | 다수 수신자 동시 지정 |
| 미리보기 | 없음 | 데스크톱·모바일 실시간 미리보기 |
| 발송 | [재발송 API](https://commerce.bootpay.ai/api/link-payment/notify) 별도 호출 | 생성 시 함께 설정 |
| 상품 선택 | `product_id` 직접 지정 | UI 에서 검색·선택 |
| 오픈 링크 | 미지원 (생성 API 가 `is_open_link` 를 받지 않습니다) | UI 토글 |

관리자에서는 만료 기본값이 생성일로부터 3일이고, 결제완료 · 결제취소 상태의 링크는 편집할 수 없어 같은 내용으로 다시 보내려면 복제합니다. 관리자에서 발송 수단(알림톡 · 이메일)이 비활성이면 [개발자 설정 > 메시지 설정](https://admin.bootpay.co.kr/setting/developer?tab=message)에서 먼저 켭니다.
