@yuju/tosspayments-sdk
Version:
Toss Payments SDK for Node.js
61 lines (60 loc) • 2.34 kB
JavaScript
import { filterUndefined } from '../utils/filterUndefined.js';
import { makeTossPaymentsResult } from '../utils/makeTossPaymentsResult.js';
import { validateIssueBillingKeyWithCustomerKey, } from '../types/requestTypes.js';
/**
* 빌링 API
*/
export class BillingApi {
constructor(client) {
Object.defineProperty(this, "client", {
enumerable: true,
configurable: true,
writable: true,
value: client
});
}
/**
* 빌링키 발급 with 고객키
* @param issueBillingKeyWithCustomerKeyRequest 빌링키 발급 요청
* @param idempotencyKey 멱등키
* @return 빌링 정보
*/
async issueWithCustomerKey(issueBillingKeyWithCustomerKeyRequest, idempotencyKey) {
validateIssueBillingKeyWithCustomerKey(issueBillingKeyWithCustomerKeyRequest);
return makeTossPaymentsResult(async () => {
return this.client.post(filterUndefined({
'Content-Type': 'application/json',
'Idempotency-Key': idempotencyKey,
}), '/v1/billing/authorizations/card', issueBillingKeyWithCustomerKeyRequest);
});
}
/**
* 빌링키 발급 with 인증키
* @param issueBillingKeyWithAuthKeyRequest 빌링키 발급 요청
* @param idempotencyKey 멱등키
* @return 빌링 정보
*/
async issueWithAuthKey(issueBillingKeyWithAuthKeyRequest, idempotencyKey) {
return makeTossPaymentsResult(async () => {
return this.client.post(filterUndefined({
'Content-Type': 'application/json',
'Idempotency-Key': idempotencyKey,
}), '/v1/billing/authorizations/issue', issueBillingKeyWithAuthKeyRequest);
});
}
/**
* 빌링키 결제
* @param billingKey 빌링키
* @param billingConfirmRequest 빌링키 결제 요청
* @param idempotencyKey 멱등키
* @return 결제 정보 (카드)
*/
async bill(billingKey, billingConfirmRequest, idempotencyKey) {
return makeTossPaymentsResult(async () => {
return this.client.post(filterUndefined({
'Content-Type': 'application/json',
'Idempotency-Key': idempotencyKey,
}), `/v1/billing/${billingKey}`, billingConfirmRequest);
});
}
}