포트원 API 이용하기
포트원 REST API 를 이용하여 손쉽게 빌링키를 발급할 수 있습니다.
API를 통한 빌링키 발급의 장점
API를 통한 빌링키 발급의 단점
1. 빌링키 발급 API 구현하기 (서버)
// bodyParser 등을 통해 body의 Content-Type에 맞게 데이터를 파싱할 수 있는지 확인해주세요.
// 아래의 카드 정보 입력하기의 방법에 따라 요청으로 오는 Content-Type이 다를 수 있습니다.
// POST 요청을 받는 /billing-keys
app.post("/billing-keys", async (req, res) => {
try {
// 카드를 통한 빌링키 발급을 위한 정보들이 오기를 기대합니다.
// 자세한 필요한 정보는 빌링키 발급 API를 참고해주세요.
const {
customer_id,
card_number,
expiry_month,
expiry_year,
birth_or_business_registration_number,
password_two_digits,
} = req.body;
// 1. 포트원 API를 사용하기 위한 액세스 토큰 발급 받기
const signinResponse = await axios({
url: "https://api.portone.io/v2/signin/api-key",
method: "post",
headers: { "Content-Type": "application/json" },
data: {
api_key: PORTONE_API_KEY, // 포트원 API Key
},
});
const { access_token } = signinResponse.data;
// 2. 포트원 빌링키 발급 API 호출
const issueResponse = await axios({
url: "https://api.portone.io/v2/billing-keys",
method: "post",
// 1번에서 발급받은 액세스 토큰을 Bearer 형식에 맞게 넣어주세요.
headers: { "Authorization": "Bearer " + access_token },
data: {
customer: {
customer_id,
},
payment_method_option: {
card: {
card_credential: {
card_number,
expiry_month,
expiry_year,
birth_or_business_registration_number,
password_two_digits
},
},
},
}
});
const { customer_id, billing_key } = issueResponse.data;
// 빌링키가 발급되었습니다! 빌링키를 저장하거나 결제하는 로직을 구성하세요.
} catch (e) {
// 빌링키 발급에 실패했습니다.
res.status(400).send(e);
}
});2. 카드 정보 입력받기
빌링키 발급을 위한 카드정보
Last updated
Was this helpful?
