빌링키 발급
고객의 결제수단을 등록하고 빌링키를 발급합니다. 가맹점 서버는 카드 정보를 저장하지 않고, 발급 결과를 조회해 billing_key와 표시용 카드 정보만 저장합니다. 발급된 빌링키는 빌링키 결제 요청 또는 예약결제에 사용합니다.
발급 흐름 한눈에
프론트엔드에서 발급하기
PG 결제창에서 발급합니다. 카드 정보는 PG사에서 직접 처리됩니다.
발급 요청
Bootpay.requestSubscription 으로 빌링키 발급 결제창을 띄웁니다.
요청 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
| pg | String | Y | PG사 코드 (미입력 시 SUBSCRIBE_NEED_PG_METHOD 2300) |
| method | String | Y | Web 은 카드자동, 모바일 SDK 는 card_rebill |
| subscription_id | String | Y | 가맹점에서 관리하는 고유 주문번호 |
| order_name | String | Y | 주문명 (미입력 시 RC_NAME_BLANK 2003) |
| price | Integer | N | 0 또는 100원 이상. 0보다 큰 값이면 빌링키 발급 즉시 결제, 0이면 빌링키만 발급 |
| extra.subscribe_test_payment | Boolean | N | true 지정 시 PG 최소금액(기본 100원)으로 인증결제를 하고, 약 10초 뒤 자동으로 취소합니다 |
| extra.theme_color | String | N | 카드 등록 화면의 강조색(버튼 배경·입력 포커스·로딩). CSS 색상값. 미입력 시 #3182F6 |
| extra.theme_text_color | String | N | theme_color 배경 위 버튼 글자색. CSS 색상값. 미입력 시 #FFFFFF. 테마 색상 상세 |
Flutter Web은 Flutter Web 사전 설정에 따라 bootpay_api.js 복사와 두 스크립트 로드를 먼저 완료합니다.
import { Bootpay } from '@bootpay/client-js'
const response = await Bootpay.requestSubscription({
client_key: '[ Client Key ]',
pg: 'nicepay',
method: '카드자동',
order_name: '정기결제 등록',
subscription_id: 'sub_' + Date.now(),
price: 0,
user: {
username: '홍길동',
phone: '01012345678'
},
extra: {
subscribe_test_payment: true
}
})
console.log(response)import android.util.Log
import kr.co.bootpay.android.Bootpay
import kr.co.bootpay.android.events.BootpayEventListener
import kr.co.bootpay.android.models.Payload
import kr.co.bootpay.android.models.BootUser
import kr.co.bootpay.android.models.BootExtra
val payload = Payload().apply {
clientKey = "[ Client Key ]"
pg = "nicepay"
method = "card_rebill"
orderName = "정기결제 등록"
subscriptionId = "SUB-" + System.currentTimeMillis()
price = 0.0
user = BootUser().apply {
id = "user_123"
username = "홍길동"
phone = "01012345678"
}
extra = BootExtra().apply {
isSubscribeTestPayment = true
}
}
Bootpay.init(supportFragmentManager)
.setPayload(payload)
.setEventListener(object : BootpayEventListener {
override fun onDone(data: String) {
// 발급 완료 — 서버에서 빌링키 조회
Log.d("Bootpay", "빌링키 발급 완료: " + data)
}
override fun onConfirm(data: String): Boolean = true
override fun onCancel(data: String) {
Log.d("Bootpay", "사용자 취소: " + data)
}
override fun onError(data: String) {
Log.e("Bootpay", "발급 오류: " + data)
}
override fun onIssued(data: String) {
Log.d("Bootpay", "가상계좌 발급: " + data)
}
override fun onClose() {
Bootpay.dismiss()
}
})
.requestSubscription()import Foundation
import Bootpay
let payload = Payload()
payload.clientKey = "[ Client Key ]"
payload.pg = "nicepay"
payload.method = "card_rebill"
payload.orderName = "정기결제 등록"
payload.subscriptionId = "SUB-\(Int(Date().timeIntervalSince1970 * 1000))"
payload.price = 0
let user = BootUser()
user.username = "홍길동"
user.phone = "01012345678"
payload.user = user
let extra = BootExtra()
extra.subscribeTestPayment = true
payload.extra = extra
Bootpay.requestSubscription(
viewController: self,
payload: payload,
isModal: true,
animated: true,
modalPresentationStyle: .automatic
)
.onDone { data in
// 발급 완료 — 서버에서 빌링키 조회
print("빌링키 발급 완료: \(data)")
}
.onConfirm { data in
return true
}
.onCancel { data in
print("사용자 취소: \(data)")
}
.onError { data in
print("발급 오류: \(data)")
}
.onClose {
print("발급창 닫힘")
}Payload payload = Payload();
payload.clientKey = '[ Client Key ]';
payload.pg = 'nicepay';
payload.method = 'card_rebill';
payload.orderName = '정기결제 등록';
payload.subscriptionId = 'SUB-${DateTime.now().millisecondsSinceEpoch}';
payload.price = 0;
User user = User();
user.username = '홍길동';
user.phone = '01012345678';
payload.user = user;
Extra extra = Extra();
extra.subscribeTestPayment = true;
payload.extra = extra;
Bootpay().requestSubscription(
context: context,
payload: payload,
showCloseButton: false,
onDone: (String data) {
// 발급 완료 — 서버에서 빌링키 조회
print('빌링키 발급 완료: $data');
},
onConfirm: (String data) {
return true;
},
onCancel: (String data) {
print('사용자 취소: $data');
},
onError: (String data) {
print('발급 오류: $data');
},
onClose: () {
print('발급창 닫힘');
Bootpay().dismiss(context);
},
);// Flutter Web 사전 설정에 따라 bootpay_api.js를 복사하고 두 스크립트를 로드합니다.
Payload payload = Payload();
payload.clientKey = '[ Client Key ]';
payload.pg = 'nicepay';
payload.method = 'card_rebill';
payload.orderName = '정기결제 등록';
payload.subscriptionId = 'SUB-${DateTime.now().millisecondsSinceEpoch}';
payload.price = 0;
User user = User();
user.username = '홍길동';
user.phone = '01012345678';
payload.user = user;
Extra extra = Extra();
extra.subscribeTestPayment = true;
extra.openType = 'redirect';
extra.redirectUrl = 'https://yoursite.com/billing/result';
payload.extra = extra;
Bootpay().requestSubscription(
context: context,
payload: payload,
showCloseButton: false,
onDone: (String data) {
// redirect 방식에서는 호출되지 않음
print('빌링키 발급 완료: $data');
},
onCancel: (String data) {
print('사용자 취소: $data');
},
onError: (String data) {
print('발급 오류: $data');
},
onClose: () {
Bootpay().dismiss(context);
},
);import React, { useRef } from 'react';
import { Bootpay } from 'react-native-bootpay-api';
const bootpay = useRef<Bootpay>(null);
const payload = {
client_key: '[ Client Key ]',
pg: 'nicepay',
method: 'card_rebill',
order_name: '정기결제 등록',
subscription_id: 'SUB-' + Date.now(),
price: 0,
};
const user = {
id: 'user_123',
username: '홍길동',
phone: '01012345678',
};
const extra = {
subscribe_test_payment: true,
app_scheme: 'yourAppScheme', // iOS Info.plist에 등록한 앱 스킴
};
if (bootpay != null && bootpay.current != null)
bootpay.current.requestSubscription(payload, [], user, extra);
<Bootpay ref={bootpay}
client_key={'[ Client Key ]'}
onDone={(data) => {
// 발급 완료 — 서버에서 빌링키 조회
console.log('빌링키 발급 완료', data);
}}
onConfirm={(data) => true}
onCancel={(data) => { console.log('사용자 취소', data); }}
onError={(data) => { console.log('발급 오류', data); }}
onClose={() => { console.log('발급창 닫힘'); }}
/>발급 결과 처리
빌링키 발급이 완료되면 done 이벤트가 옵니다. 보안상 빌링키는 프론트엔드로 바로 전달되지 않으므로, 백엔드에서 빌링키 조회 API를 호출하여 빌링키를 확인하고 데이터베이스에 저장해야 합니다.
백엔드에서 발급하기
가맹점이 직접 카드 정보를 받아 백엔드에서 빌링키를 발급합니다.
API 정보
필수 파라미터
가맹점 화면에서 받은 카드 정보와 함께 아래 값을 보내야 합니다.
요청 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
| pg | String | Y | PG사 코드 (미입력 시 SUBSCRIBE_NEED_PG_METHOD 2300) |
| method | String | Y | 반드시 카드자동(REST) 값을 지정 |
| subscription_id | String | Y | 가맹점에서 관리하는 고유 구독 번호 (미입력 시 RC_O_ID_BLANK 2005) |
| order_name | String | Y | 주문명 (미입력 시 RC_NAME_BLANK 2003) |
| card_no | String | Y | 카드번호 (하이픈 없이) |
| card_pw | String | Y | 카드 비밀번호 앞 2자리 |
| card_identity_no | String | Y | 생년월일 6자리 또는 사업자등록번호 10자리 |
| card_expire_year | String | Y | 카드 유효기간 년 2자리 |
| card_expire_month | String | Y | 카드 유효기간 월 2자리 (01~12 범위를 벗어나면 RC_INVALID_EXP_MONTH 2084) |
REST 발급 응답
백엔드 REST 발급은 발급이 끝나면 응답에 billing_key가 바로 들어옵니다. 프론트엔드 결제창 발급과 달리 빌링키 조회 API를 다시 호출할 필요가 없습니다.
| 파라미터 | 타입 | 설명 |
|---|---|---|
| receipt_id | String | 발급 요청의 영수증 ID |
| subscription_id | String | 요청 시 넣은 가맹점 고유 구독 번호 |
| pg | String | PG사명 |
| method | String | 결제수단 한글명 |
| method_symbol | String | 결제수단 영문 심볼 |
| method_origin | String | 원 결제수단 한글명 |
| method_origin_symbol | String | 원 결제수단 영문 심볼 |
| published_at | Date | 빌링키 발급 시각 (ISO 8601) |
| requested_at | Date | 발급 요청 시각 (ISO 8601) |
| status_locale | String | 발급 상태 한글 ("빌링키발급완료") |
| status | Number | 발급 상태. 11이면 발급 완료 |
| billing_key | String | 발급된 빌링키. 반드시 데이터베이스에 저장합니다 |
| billing_data | Object | 카드 표시 정보 (card_company, card_no, card_company_code, card_type, card_hash) |
| billing_expire_at | Date | 빌링키 만료일. REST 카드 발급은 입력한 카드 유효기간 + 1개월로 계산됩니다 |
| receipt_data | Object | price를 0보다 크게 보내 발급과 동시에 결제까지 한 경우에만 들어오는 결제 정보 |
POST
/v2/request/subscribeBase URLhttps://api.bootpay.co.kr
인증Basic Auth
import { Bootpay } from '@bootpay/backend-js'
Bootpay.setConfiguration({
client_key: '[ Client Key ]',
secret_key: '[ Secret Key ]'
})
try {
const response = await Bootpay.requestSubscribeBillingKey({
pg: 'nicepay',
method: '카드자동(REST)',
subscription_id: 'sub_' + Date.now(),
card_no: '5570********1074',
card_pw: '00',
card_identity_no: '900101',
card_expire_year: '25',
card_expire_month: '12',
order_name: '정기결제 등록'
})
// billing_key를 데이터베이스에 저장
console.log(response)
} catch (e) {
console.log(e)
}from bootpay_backend import BootpayBackend
import time
bootpay = BootpayBackend(client_key='CLIENT_KEY', secret_key='SECRET_KEY')
response = bootpay.request_subscribe_billing_key(
pg='nicepay',
method='카드자동(REST)',
subscription_id=f'sub_{int(time.time())}',
card_no='5570********1074',
card_pw='00',
card_identity_no='900101',
card_expire_year='25',
card_expire_month='12',
order_name='정기결제 등록'
)
print(response)<?php
require_once 'vendor/autoload.php';
use Bootpay\ServerPhp\BootpayApi;
BootpayApi::setClientKeyConfiguration('CLIENT_KEY', 'SECRET_KEY');
$response = BootpayApi::requestSubscribeBillingKey([
'pg' => 'nicepay',
'method' => '카드자동(REST)',
'subscription_id' => 'sub_' . time(),
'card_no' => '5570********1074',
'card_pw' => '00',
'card_identity_no' => '900101',
'card_expire_year' => '25',
'card_expire_month' => '12',
'order_name' => '정기결제 등록'
]);
// billing_key를 데이터베이스에 저장
echo $response->billing_key; // 응답 본문이 그대로 json_decode 객체로 옵니다 (data 감싸개 없음)import java.util.HashMap;
import kr.co.bootpay.pg.Bootpay;
Bootpay bootpay = Bootpay.withClientKey("CLIENT_KEY", "SECRET_KEY");
try {
// Java SDK(3.9.0) 의 Subscribe 에는 method 필드가 없어 '카드자동(REST)' 을 보낼 수 없으므로
// getBillingKey 가 쓰는 경로(request/subscribe)에 doPost 로 직접 보냅니다. 키는 snake_case 그대로 씁니다
HashMap<String, Object> subscribe = new HashMap<>();
subscribe.put("pg", "nicepay");
subscribe.put("method", "카드자동(REST)");
subscribe.put("subscription_id", "sub_" + System.currentTimeMillis());
subscribe.put("card_no", "5570********1074");
subscribe.put("card_pw", "00");
subscribe.put("card_identity_no", "900101");
subscribe.put("card_expire_year", "25");
subscribe.put("card_expire_month", "12");
subscribe.put("order_name", "정기결제 등록");
HashMap<String, Object> response = bootpay.doPost("request/subscribe", subscribe);
// 발급 실패는 예외가 아니라 error_code 가 담긴 응답으로 옵니다
if (response.get("error_code") != null) {
System.out.println(response.get("error_code") + " " + response.get("message"));
return;
}
// billing_key를 데이터베이스에 저장
System.out.println(response.get("billing_key"));
} catch (Exception e) {
e.printStackTrace();
}require 'bootpay'
bootpay = Bootpay::RestClient.new(client_key: 'CLIENT_KEY', secret_key: 'SECRET_KEY')
# request_subscribe_billing_key 헬퍼는 method 인자를 받지 않아 '카드자동(REST)' 을 보낼 수 없으므로
# gem 내부의 request 로 직접 보낸다. request 는 private 이라 send 로 부른다 (bootpay.request(...) 는 NoMethodError)
response = bootpay.send(:request,
uri: 'request/subscribe',
payload: {
pg: 'nicepay',
method: '카드자동(REST)',
subscription_id: "sub_#{Time.now.to_i}",
card_no: '5570********1074',
card_pw: '00',
card_identity_no: '900101',
card_expire_year: '25',
card_expire_month: '12',
order_name: '정기결제 등록'
}
)
# billing_key를 데이터베이스에 저장
puts response.data[:billing_key]package main
import (
"fmt"
"time"
"github.com/bootpay/backend-go/v2"
)
func main() {
api := bootpay.NewAPIWithClientKey("CLIENT_KEY", "SECRET_KEY", nil, "")
payload := bootpay.BillingKeyPayload{
Pg: "nicepay",
Method: "카드자동(REST)",
SubscriptionId: fmt.Sprintf("sub_%d", time.Now().UnixMilli()),
CardNo: "5570********1074",
CardPw: "00",
CardIdentityNo: "900101",
CardExpireYear: "25",
CardExpireMonth: "12",
OrderName: "정기결제 등록",
}
response, err := api.GetBillingKey(payload)
if err != nil {
fmt.Println(err)
return
}
// billing_key를 데이터베이스에 저장
fmt.Println(response)
}using System.Net.Http;
using Bootpay;
using Newtonsoft.Json;
var api = BootpayApi.WithClientKey("CLIENT_KEY", "SECRET_KEY");
// .NET SDK(2.12.0) 의 Subscribe 에는 method 속성이 없어 '카드자동(REST)' 을 보낼 수 없으므로
// GetBillingKey 가 쓰는 경로(request/subscribe)에 SendAsync 로 직접 보냅니다
var json = JsonConvert.SerializeObject(new
{
pg = "nicepay",
method = "카드자동(REST)",
subscription_id = $"sub_{DateTimeOffset.Now.ToUnixTimeMilliseconds()}",
card_no = "5570********1074",
card_pw = "00",
card_identity_no = "900101",
card_expire_year = "25",
card_expire_month = "12",
order_name = "정기결제 등록"
});
var response = await api.SendAsync("request/subscribe", HttpMethod.Post, json);
// 발급 실패는 예외가 아니라 4xx 응답 + error_code 본문으로 옵니다 (response.IsSuccessStatusCode 로 가릅니다)
// billing_key를 데이터베이스에 저장
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);JSON
{
"receipt_id": "6261104e1fc19202e6f9420e",
"subscription_id": "sub_1705289520000",
"pg": "나이스페이먼츠",
"method": "카드자동(REST)",
"method_symbol": "card_rebill_rest",
"method_origin": "카드자동(REST)",
"method_origin_symbol": "card_rebill_rest",
"published_at": "2025-01-15T14:32:00+09:00",
"requested_at": "2025-01-15T14:31:52+09:00",
"status_locale": "빌링키발급완료",
"status": 11,
"billing_key": "615d00f0197c300036b4fef5",
"billing_data": {
"card_company": "하나카드",
"card_no": "5570-****-****-1074",
"card_company_code": "046",
"card_type": 0,
"card_hash": "f5b2a..."
},
"billing_expire_at": "2026-01-01T00:00:00+09:00"
}발급 결과 저장
발급한 billing_key 는 서비스 회원과 묶어 서버 DB 에 저장합니다. 카드번호·유효기간 같은 카드 정보는 저장하지 않고, 화면 표시용 카드사·마스킹 번호만 저장합니다. billing_key 는 결제 요청에 쓰이므로 외부로 노출되지 않게 관리합니다.
SQL
CREATE TABLE billing_keys (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
user_id BIGINT NOT NULL,
billing_key VARCHAR(100) NOT NULL,
card_name VARCHAR(50),
card_last4 VARCHAR(4),
status VARCHAR(20) DEFAULT 'active', -- active / revoked
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
INDEX idx_user (user_id)
);| 컬럼 | 의미 |
|---|---|
billing_key | 결제 요청 시 사용. 노출 최소화 |
card_last4 | UI 표시용 마스킹 카드번호 |
status | revoked 면 청구 대상에서 제외 |
- 카드를 새로 등록하면 행을 추가하고 기존 행을
revoked로 바꿉니다. 한 회원의 활성 빌링키는 1개로 유지합니다. - 더 쓰지 않는 빌링키는 빌링키 삭제 API 로 삭제합니다.
- 반복 청구용 회차 테이블 예시는 자동결제 전체 구현 예제에 있습니다.
에러 코드
요청값
오류 코드
| 코드 | 메시지 | 대처 방법 |
|---|---|---|
SUBSCRIBE_NEED_PG_METHOD (2300) | pg와 method 정보가 필수입니다 | pg와 method 파라미터를 입력합니다 |
RC_ONLY_REST_API (2058) | 현재 요청한 결제 수단은 REST API로 요청이 가능한 결제 수단이 아니다 | 백엔드 REST 발급은 method를 카드자동(REST)로 보내야 합니다 |
RC_INVALID_EXP_MONTH (2084) | 카드 만료월 정보를 다시 확인한다 (01월~12월) | card_expire_month를 01~12 범위로 입력합니다 |
RC_NAME_BLANK (2003) | 상품명을 입력합니다 | order_name 값을 입력합니다 |
RC_O_ID_BLANK (2005) | order_id 값을 입력합니다 | subscription_id 또는 order_id를 입력합니다 |
RC_PRICE_LEAST_LT (2004) | 100원보다 큰 금액을 결제할 수 있습니다 | price를 100원 이상으로 설정합니다 |
SUBSCRIBE_CARD_NO_BLANK (2311) | 카드 번호를 입력합니다 | card_no 값을 입력합니다 |
SUBSCRIBE_CARD_PW_BLANK (2312) | 카드 비밀번호 앞 2자리를 입력합니다 | card_pw 값을 입력합니다 |
SUBSCRIBE_CARD_IDENTITY_BLANK (2313) | 생년월일/사업자등록번호를 입력합니다 | card_identity_no 값을 입력합니다 |
SUBSCRIBE_CARD_EX_YEAR_BLANK (2314) | 카드 만료 년도를 입력합니다 | card_expire_year 값을 입력합니다 |
SUBSCRIBE_CARD_EX_MONTH_BLANK (2315) | 카드 만료 월을 입력합니다 | card_expire_month 값을 입력합니다 |
가맹점·PG 설정
오류 코드
| 코드 | 메시지 | 대처 방법 |
|---|---|---|
RC_NOT_SUBSCRIBE (2057) | 정기결제 요청 정보가 아니다 | 정기결제 요청 파라미터를 확인합니다 |
RC_PROVIDER_NOT_ALLOW (2104) | 가맹점이 탈퇴/차단 상태 | 부트페이 관리자에서 가맹점 상태를 확인합니다 |
RC_PROVIDER_PAYMENT_NOT_ALLOW (2102) | 서비스 이용료 미납으로 결제 불가 | 부트페이 서비스 이용료를 납부합니다 |
RC_RESOURCE_NOT_CONFIG (2017) | 결제수단이 허가/설정되지 않았습니다 | 부트페이 관리자에서 정기결제 설정을 확인합니다 |
SUBSCRIBE_PUBLISH_M_NOT_FOUND (2305) | 빌링키 발급 기능이 없는 PG | 빌링키 발급을 지원하는 PG를 사용합니다 |
발급 처리
오류 코드
| 코드 | 메시지 | 대처 방법 |
|---|---|---|
SUBSCRIBE_REQUEST_FAILED (2301) | 빌링키 발급 요청 실패 | 카드 정보를 확인 후 재시도합니다 |
SUBSCRIBE_PUBLISH_NOT_READY (2303) | 빌링키 발급 대기 상태가 아니다 | 발급 요청을 처음부터 다시 진행합니다 |
SUBSCRIBE_PUBLISH_FAILED (2304) | 빌링키 발급 처리 중 서버 오류가 발생했습니다 | 잠시 후 재시도하고, 계속 발생하면 부트페이 관리자에 문의합니다 |
SUBSCRIBE_ALREADY_PUBLISHED (2319) | 이미 빌링키를 발급받은 진행건입니다 | 같은 receipt_id로 중복 발급을 요청한 경우입니다. 발급된 빌링키를 그대로 사용합니다 |