일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 스파르타코딩클럽
- Get
- 5주차
- 4주차
- 개발일지
- nginx
- Transaction
- HTTPS
- cors
- Sequelize
- 트랜잭션
- 비동기
- 위키백과
- NoSQL
- Node.js
- 3주차
- OpenAPI
- node winston
- 노드 윈스턴
- 웹 스크래핑(크롤링)
- MongoDB
- 항해99
- JWT
- 숙제
- post
- db
- 2주차
- 부트스트랩
- SQL
- 1주차
Archives
- Today
- Total
얼음꽃의 일지
[JS] toss 빌링키 연결 및 사용 api 본문
728x90
toss에 요청해서 연결해서 받는 키값은 있다는 전제하에 진행됩니다.
첫번째로 프론트에서 toss 를 연결해서 카드 입력 후 오는 authKey값을 받아서 카드 등록을 진행합니다.
const superagent = require('superagent');
const billingKey = await superagent
.post('https://api.tosspayments.com/v1/billing/authorizations/issue')
.set(
{
Authorization: `Basic ${Buffer.from(
`${토스키}:`,
'utf-8',
).toString('base64')}`,
},
{
'Content-Type': 'application/json; charset=UTF-8',
},
)
.send({
customerKey : "고객값",
authKey : "프론트에서 토스 진행해서 얻은 값",
});
이렇게 진행하게되면 response 값으로 text 값에 고유 빌링키가 생성됩니다.
그 이후 나중에 빌링키로 다음과 같이 api를 작성하게되면 자동결제를 할 수 있습니다.
const superagent = require('superagent');
const data = {
customerKey: "보내고자 하는 고객값",
amount: "금액",
orderId: "unique한 주문 번호",
orderName : "이름",
customerEmail: "이메일",
customerName: "이름",
cardInstallmentPlan: 0, // 부가세
};
try {
const tossPayment = await superagent
.post(
`https://api.tosspayments.com/v1/billing/빌링키`,
)
.set(
{
Authorization: `Basic ${Buffer.from(
`${토스키값}:`,
'utf-8',
).toString('base64')}`,
},
{
'Content-Type': 'application/json; charset=UTF-8',
},
)
.send(data);
필요한 데이터를 넣고 api를 타면 요청한 amount 만큼 결제가 됩니다.
추가적인 내용은 다음을 참조하시면 좋습니다.
https://docs.tosspayments.com/guides/billing/integration
728x90
'잡다한 지식' 카테고리의 다른 글
[JS] 클라이언트 IP 쉽게 가져오기 (1) | 2023.11.11 |
---|---|
[JS] Sequelize Association(관계) 설정 (0) | 2023.11.08 |
[JS] superagent 사용법 (0) | 2023.11.03 |
[JS] api 만들었을때 오래걸리는 현상 확인법 (0) | 2023.11.02 |
[JS] sequelize transaction commit, rollback 잘못 걸었을때 (0) | 2023.11.01 |