주문서 요청
Commerce SDK를 사용하여 구독/요금제 결제를 쉽게 구현하세요.
Commerce SDK는 서비스의 상품, 구독 결제 등을 손쉽게 구현할 수 있습니다. 상품 등록부터 주문서 발행, 구독 관리까지 모든 과정을 지원합니다.
Commerce SDK를 사용하기 전에, 먼저 부트페이 관리자에서 판매할 상품을 등록해야 합니다.
상품명사용자에게 표시될 상품 이름가격상품 가격 (단건/구독 가격)구독 설정구독 상품인 경우 구독 정책 설정 (구독주기/환불 등)
product_id가 발급됩니다. 이 ID를 사용하여 결제를 요청합니다.할인/프로모션 적용이 필요한 경우, 서버에서 먼저 commerce.invoice.create()를 호출하여 invoice_id를 발급받습니다.
invoice.create(), 클라이언트 SDK는 requestCheckout()을 사용합니다. 메서드명이 다릅니다.| 구분 | 서버 (Backend SDK) | 클라이언트 (Frontend SDK) |
|---|---|---|
| 메서드 | commerce.invoice.create() | BootpayCommerce.requestCheckout() |
| 목적 | 청구서 생성, invoice_id 발급 | 결제창 표시 |
| 필수 여부 | 선택 (할인 적용 시) | 필수 |
서버에서 commerce.invoice.create()를 호출하면 invoice_id가 반환됩니다.
price할인이 적용된 최종 결제 금액products상품 목록 (product_id, quantity 등)user구매자 정보
invoice_id를 클라이언트에 전달하세요.클라이언트에서 BootpayCommerce.requestCheckout() 호출 시 invoice_id를 함께 전달하면, 서버에서 설정한 할인 가격이 적용됩니다.
invoice_id를 전달하지 않으면 상품 원가로 결제됩니다.서버에서 받은 주문 정보로 BootpayCommerce.requestCheckout()를 호출하여 결제 페이지를 표시합니다.
client_keyCommerce 클라이언트 키name주문명 (예: "Professional 플랜")price서버에서 계산한 결제 금액redirect_url결제 완료 후 이동할 URL
할인/프로모션을 적용하려면 주문서 API로 미리 생성한 request_id를 함께 전달해야 합니다.
request_id주문서 API 호출 시 발급받은 주문 요청 ID (할인 정보 포함)
request_id를 전달하면 주문서 API에서 설정한 할인 가격이 자동으로 적용됩니다.구독할 상품 정보를 배열로 전달합니다.
product_idCommerce에 등록된 상품 IDduration구독 기간 (-1은 무기한)quantity수량
membership_type회원 유형 (guest또는member)user_id가맹점의 사용자 고유 IDname, phone, email사용자 정보
requestCheckout()가 완료되면 redirect_url로 이동하며, order_number가 URL 파라미터로 전달됩니다.
order_numberCommerce 주문 고유 번호 (서버 검증에 사용)event결제 결과 이벤트 (done,cancel,error)
서버에서 order_number로 Commerce API를 호출하여 실제 주문 정보를 조회하고, 결제 상태와 금액을 검증합니다.
1. 액세스 토큰 발급Commerce API 토큰 발급 (Basic Auth)2. 주문 정보 조회GET /v1/orders/{order_number}3. 결제 상태 확인status, receipt_status 검증
status주문 상태 (order_completed,subscription_request_completed등)price결제 금액order_subscriptions구독 정보 (구독 상품인 경우)
고급 기능
부트페이 Commerce API의 invoice.create()를 호출하여 할인된 가격으로 청구서를 미리 생성할 수 있습니다.
const { BootpayCommerce } = require('@bootpay/backend-js')
const commerce = new BootpayCommerce({
client_key: 'xxx',
secret_key: 'yyy',
mode: 'production'
})
app.post('/api/invoices/create', async (req, res) => {
const { products, user, promotion_code } = req.body
// 할인 가격 계산
let finalPrice = calculateDiscountPrice(products, promotion_code)
// 부트페이 청구서 생성 API 호출
await commerce.getAccessToken()
const invoice = await commerce.invoice.create({
products: products,
price: finalPrice, // 할인 적용된 가격
user: user
})
res.json({
success: true,
invoice_id: invoice.data.invoice_id // 클라이언트에서 사용
})
})requestCheckout() 호출 시 invoice_id를 전달하면 미리 생성한 청구서 정보(할인 가격 포함)가 적용됩니다.주문서 요청 시 extra 객체로 전달하는 옵션입니다.
| separately_confirmed | 분리 승인 모드 (true 시 별도 승인 필요) |
| create_order_immediately | 즉시 주문 생성 여부 |
결제에 추가 정보를 저장할 수 있습니다.
metadata: {
order_id: 'ORDER_123',
plan_key: 'pro',
billing_type: '연간',
promotion_code: 'SUMMER2024'
}