UNPKG

@yuju/tosspayments-sdk

Version:

Toss Payments SDK for Node.js

117 lines (116 loc) 3.9 kB
import { HttpClient } from './httpClient.js'; import { LazyLoader } from './utils/lazyLoader.js'; import { PaymentApi } from './core/paymentApi.js'; import { VirtualAccountApi } from './core/virtualAccountApi.js'; import { BillingApi } from './core/billingApi.js'; import { SettlementApi } from './core/settlementApi.js'; import { TransactionApi } from './core/transactionApi.js'; import { CashReceiptApi } from './core/cashReceiptApi.js'; /** * TossPayments API */ export class TossPaymentsApi { /** * TossPayments API 생성 * @param secretKey API Secret Key * @param options version, endpoint */ constructor(secretKey, options = { version: '2022-06-08', endpoint: 'https://api.tosspayments.com', }) { Object.defineProperty(this, "secretKey", { enumerable: true, configurable: true, writable: true, value: secretKey }); Object.defineProperty(this, "options", { enumerable: true, configurable: true, writable: true, value: options }); Object.defineProperty(this, "paymentApiLoader", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "virtualAccountApiLoader", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "billingApiLoader", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "settlementApiLoader", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "transactionApiLoader", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "cashReceiptApiLoader", { enumerable: true, configurable: true, writable: true, value: void 0 }); if (options.version != '2022-06-08') { throw new Error(`TossPaymentsApi version is 2022-06-08, but you set ${options.version} in options.`); } this.paymentApiLoader = new LazyLoader(() => new PaymentApi(new HttpClient(this.options.endpoint, this.secretKey))); this.virtualAccountApiLoader = new LazyLoader(() => new VirtualAccountApi(new HttpClient(this.options.endpoint, this.secretKey))); this.billingApiLoader = new LazyLoader(() => new BillingApi(new HttpClient(this.options.endpoint, this.secretKey))); this.settlementApiLoader = new LazyLoader(() => new SettlementApi(new HttpClient(this.options.endpoint, this.secretKey))); this.transactionApiLoader = new LazyLoader(() => new TransactionApi(new HttpClient(this.options.endpoint, this.secretKey))); this.cashReceiptApiLoader = new LazyLoader(() => new CashReceiptApi(new HttpClient(this.options.endpoint, this.secretKey))); } /** * 결제 API */ get payment() { return this.paymentApiLoader.get(); } /** * 가상계좌 API */ get virtualAccount() { return this.virtualAccountApiLoader.get(); } /** * 정기결제 API */ get billing() { return this.billingApiLoader.get(); } /** * 정산 API */ get settlement() { return this.settlementApiLoader.get(); } /** * 거래내역 API */ get transaction() { return this.transactionApiLoader.get(); } /** * 현금영수증 API */ get cashReceipt() { return this.cashReceiptApiLoader.get(); } }