diff --git a/README.md b/README.md index e9601a7..5c19cba 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # Bootpay Server Rest Client [![alt text](https://cdn.bootpay.co.kr/icon/npm.svg)](https://www.npmjs.com/package/@bootpay/server-rest-client) -### 1.0.9 ( Stable ) +### 1.0.10 ( Stable ) +* 빌링키 조회 기능 추가 및 버그 수정 + +### 1.0.9 * 결제 취소시 taxFree 값 추가 diff --git a/package.json b/package.json index 03c8bc0..0f23081 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@bootpay/server-rest-client", - "version": "1.0.9", + "name": "@bootpay/server-rest-client-instance", + "version": "1.0.10", "description": "Bootpay Server Rest Client Javasrcipt Library", "main": "dist/bootpay.js", "types": "dist/bootpay.d.ts", diff --git a/src/bootpay.ts b/src/bootpay.ts index 60e222d..a56ad2f 100644 --- a/src/bootpay.ts +++ b/src/bootpay.ts @@ -1,11 +1,10 @@ -import { BootpaySingleton } from "./lib/bootpay/singleton" import axios, { AxiosInstance, AxiosResponse, AxiosRequestConfig } from "axios" import { isBlank, isPresent, objectKeyToUnderscore } from "./lib/bootpay/support" const API_URL: any = { development: 'https://dev-api.bootpay.co.kr', - stage: 'https://stage-api.bootpay.co.kr', - production: 'https://api.bootpay.co.kr' + stage: 'https://stage-api.bootpay.co.kr', + production: 'https://api.bootpay.co.kr' } export interface BootpayCommonResponse { @@ -123,7 +122,7 @@ export interface BootpayUserInfoData { } -class BootpayRestClient extends BootpaySingleton { +export class BootpayRestClient { $http: AxiosInstance $token?: string @@ -132,10 +131,9 @@ class BootpayRestClient extends BootpaySingleton { mode: string constructor() { - super() - this.mode = 'production' + this.mode = 'production' this.$token = undefined - this.$http = axios.create({ + this.$http = axios.create({ timeout: 60000 }) this.$http.interceptors.response.use((response: AxiosResponse): any => { @@ -143,10 +141,10 @@ class BootpayRestClient extends BootpaySingleton { return response.data as BootpayCommonResponse } else { return { - code: -100, - status: 500, + code: -100, + status: 500, message: `오류가 발생했습니다. ${ response }`, - data: response + data: response } as BootpayCommonResponse } }, function (error) { @@ -154,9 +152,9 @@ class BootpayRestClient extends BootpaySingleton { return Promise.reject(error.response.data) } else { return Promise.reject({ - code: -100, + code: -100, message: `통신오류가 발생하였습니다. ${ error.message }`, - status: 500 + status: 500 }) } }) @@ -165,7 +163,7 @@ class BootpayRestClient extends BootpaySingleton { config.headers.authorization = this.$token } config.headers['Content-Type'] = 'application/json' - config.headers['Accept'] = 'application/json' + config.headers['Accept'] = 'application/json' return config }, (error) => { return Promise.reject(error) @@ -181,8 +179,8 @@ class BootpayRestClient extends BootpaySingleton { */ setConfig(applicationId: string, privateKey: string, mode: string = 'production') { this.applicationId = applicationId - this.privateKey = privateKey - this.mode = isPresent(mode) ? mode : 'production' + this.privateKey = privateKey + this.mode = isPresent(mode) ? mode : 'production' if (isBlank(API_URL[this.mode])) { throw new Error(`환경설정 설정이 잘못되었습니다. 현재 설정된 모드: ${ this.mode }, 가능한 모드: development, stage, production`) } @@ -203,7 +201,7 @@ class BootpayRestClient extends BootpaySingleton { this.getApiUrl('request/token'), { application_id: this.applicationId, - private_key: this.privateKey + private_key: this.privateKey } ) } catch (e) { @@ -266,11 +264,11 @@ class BootpayRestClient extends BootpaySingleton { this.getApiUrl('cancel'), { receipt_id: data.receiptId, - price: data.price, - tax_free: data.taxFree, - name: data.name, - reason: data.reason, - refund: data.refund + price: data.price, + tax_free: data.taxFree, + name: data.name, + reason: data.reason, + refund: data.refund } ) } catch (e) { @@ -292,16 +290,16 @@ class BootpayRestClient extends BootpaySingleton { response = await this.$http.post( this.getApiUrl('request/card_rebill'), { - order_id: data.orderId, - pg: data.pg, - item_name: data.itemName, - card_no: data.cardNo, - card_pw: data.cardPw, - expire_year: data.expireYear, - expire_month: data.expireMonth, + order_id: data.orderId, + pg: data.pg, + item_name: data.itemName, + card_no: data.cardNo, + card_pw: data.cardPw, + expire_year: data.expireYear, + expire_month: data.expireMonth, identify_number: data.identifyNumber, - user_info: data.userInfo, - extra: objectKeyToUnderscore(data.extra) + user_info: data.userInfo, + extra: objectKeyToUnderscore(data.extra) } ) } catch (e) { @@ -310,6 +308,23 @@ class BootpayRestClient extends BootpaySingleton { return Promise.resolve(response) } + /** + * 빌링키 정보를 조회해서 가져온다 + * Comment by GOSOMI + * @date: 2023-09-15 + */ + async lookupBillingKey(billingKey: string) { + let response: BootpayCommonResponse + try { + response = await this.$http.get( + this.getApiUrl(`subscribe/billing_key/${ billingKey }`) + ) + } catch (e) { + return Promise.reject(e) + } + return Promise.resolve(response) + } + /** * destroy billing key * Comment by rumi @@ -342,18 +357,18 @@ class BootpayRestClient extends BootpaySingleton { response = await this.$http.post( this.getApiUrl('subscribe/billing'), { - billing_key: data.billingKey, - order_id: data.orderId, - item_name: data.itemName, - price: data.price, - tax_free: data.taxFree, - interest: data.interest, - quota: data.quota, - items: objectKeyToUnderscore(data.items), - user_info: objectKeyToUnderscore(data.userInfo), - feedback_url: data.feedbackUrl, + billing_key: data.billingKey, + order_id: data.orderId, + item_name: data.itemName, + price: data.price, + tax_free: data.taxFree, + interest: data.interest, + quota: data.quota, + items: objectKeyToUnderscore(data.items), + user_info: objectKeyToUnderscore(data.userInfo), + feedback_url: data.feedbackUrl, feedback_content_type: data.feedbackContentType, - extra: data.extra + extra: data.extra } ) } catch (e) { @@ -375,17 +390,17 @@ class BootpayRestClient extends BootpaySingleton { response = await this.$http.post( this.getApiUrl('subscribe/billing/reserve'), { - billing_key: data.billingKey, - order_id: data.orderId, - price: data.price, - tax_free: data.taxFree, - user_info: objectKeyToUnderscore(data.userInfo), - item_info: objectKeyToUnderscore(data.items), - item_name: data.itemName, - feedback_url: data.feedbackUrl, + billing_key: data.billingKey, + order_id: data.orderId, + price: data.price, + tax_free: data.taxFree, + user_info: objectKeyToUnderscore(data.userInfo), + item_info: objectKeyToUnderscore(data.items), + item_name: data.itemName, + feedback_url: data.feedbackUrl, feedback_content_type: data.feedbackContentType, - scheduler_type: data.schedulerType, - execute_at: data.executeAt + scheduler_type: data.schedulerType, + execute_at: data.executeAt } ) } catch (e) { @@ -445,18 +460,18 @@ class BootpayRestClient extends BootpaySingleton { response = await this.$http.post( this.getApiUrl('request/payment'), { - pg: data.pg, - method: data.method, - methods: data.methods, - order_id: data.orderId, - price: data.price, - params: data.params, - tax_free: data.taxFree, - name: data.itemName, - user_info: objectKeyToUnderscore(data.userInfo), - items: objectKeyToUnderscore(data.items), + pg: data.pg, + method: data.method, + methods: data.methods, + order_id: data.orderId, + price: data.price, + params: data.params, + tax_free: data.taxFree, + name: data.itemName, + user_info: objectKeyToUnderscore(data.userInfo), + items: objectKeyToUnderscore(data.items), return_url: data.returnUrl, - extra: objectKeyToUnderscore(data.extra) + extra: objectKeyToUnderscore(data.extra) } ) } catch (e) { @@ -479,11 +494,11 @@ class BootpayRestClient extends BootpaySingleton { this.getApiUrl('request/user/token'), { user_id: data.userId, - email: data.email, - name: data.name, - gender: data.gender, - birth: data.birth, - phone: data.phone + email: data.email, + name: data.name, + gender: data.gender, + birth: data.birth, + phone: data.phone } ) } catch (e) { @@ -495,6 +510,4 @@ class BootpayRestClient extends BootpaySingleton { private getApiUrl(uri: string) { return [API_URL[this.mode], uri].join('/') } -} - -export const RestClient = BootpayRestClient.currentInstance() \ No newline at end of file +} \ No newline at end of file diff --git a/test/access_token.js b/test/access_token.js index b2ab4b2..ba39d33 100644 --- a/test/access_token.js +++ b/test/access_token.js @@ -1,5 +1,7 @@ (async () => { - const RestClient = require('../dist/bootpay').RestClient + const BootpayRestClient = require('../dist/bootpay').BootpayRestClient + const RestClient = new BootpayRestClient() + console.log(BootpayRestClient) RestClient.setConfig( '59bfc738e13f337dbd6ca48a', 'pDc0NwlkEX3aSaHTp/PPL/i8vn5E/CqRChgyEp/gHD0=', diff --git a/test/axios_test.js b/test/axios_test.js index 52880d4..a78f65a 100644 --- a/test/axios_test.js +++ b/test/axios_test.js @@ -1,6 +1,7 @@ +import { BootpayRestClient } from "../src/bootpay"; (async () => { - const RestClient = require('../dist/bootpay').RestClient + const RestClient = new require('../dist/bootpay').BootpayRestClient() RestClient.setConfig( '59bfc738e13f337dbd6ca48a', 'pDc0NwlkEX3aSaHTp/PPL/i8vn5E/CqRChgyEp/gHD0=', diff --git a/test/subscribe_lookup_biiling_key.js b/test/subscribe_lookup_biiling_key.js new file mode 100644 index 0000000..5634a9d --- /dev/null +++ b/test/subscribe_lookup_biiling_key.js @@ -0,0 +1,23 @@ +(async () => { + const BootpayRestClient = require('../dist/bootpay').BootpayRestClient + // RestClient.setConfig( + // '59bfc738e13f337dbd6ca48a', + // 'pDc0NwlkEX3aSaHTp/PPL/i8vn5E/CqRChgyEp/gHD0=', + // 'development' + // ) + const RestClient = new BootpayRestClient() + RestClient.setConfig( + '59b731f084382614ebf72215', + 'WwDv0UjfwFa04wYG0LJZZv1xwraQnlhnHE375n52X0U=' + ) + let token = await RestClient.getAccessToken() + if (token.status === 200) { + let response + try { + response = await RestClient.lookupBillingKey('64fe783ba575b4002e8d648e') + } catch (e) { + return console.log(e) + } + console.log(response) + } +})() \ No newline at end of file