Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
SoleeChoi committed Jan 14, 2022
2 parents 187a11b + e9c7f00 commit 047a10e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
NodeJS용 아임포트 REST API Client 입니다.

## 버전정보
최신 버전은 [v0.9.6](https://github.com/iamport/rest-client-nodejs/tree/v0.9.6)입니다.
최신 버전은 [v0.9.7](https://github.com/iamport/rest-client-nodejs/tree/v0.9.7)입니다.

## 설치하기
아래 명령어를 통해 `iamport-rest-client-nodejs`를 귀하의 nodeJS 프로젝트에 추가합니다.
Expand Down
9 changes: 9 additions & 0 deletions example/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ module.exports = async (iamport) => {
.then(response => console.log('response: ', response.data.code))
.catch(error => console.log('error: ', error.response.data));

/* 결제정보 조회 > 아임포트 번호 & 티어 코드 */
const paymentByImpUidWithTierCode = Payments.getByImpUid({
imp_uid: 'imp_734819086221',
}, {
Tier: 'lt0'
});
await paymentByImpUidWithTierCode.request(iamport)
.then(response => console.log('response: ', response.data.code))
.catch(error => console.log('error: ', error.response.data));

/* 결제정보 조회 > 주문번호 */
const paymentByMerchantUid = Payments.getByMerchantUid({
Expand Down
5 changes: 3 additions & 2 deletions lib/Interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export type Method = 'GET' | 'POST' | 'PUT' | 'DELETE'

export interface Headers {
Authorization: string,
'User-Agent': string,
Authorization?: string,
'User-Agent'?: string,
Tier?: string,
}

export interface Config {
Expand Down
2 changes: 1 addition & 1 deletion lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const BASE_URL: string = 'https://api.iamport.kr';
export const EXPIRE_BUFFER: number = 30000;
export const USER_AGENT: string = 'iamport-rest-client-nodejs/v0.9.6';
export const USER_AGENT: string = 'iamport-rest-client-nodejs/v0.9.7';
11 changes: 9 additions & 2 deletions lib/request/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import _ from 'lodash';
import { List, Item, Collection } from '../response';

import { Iamport } from '../Iamport';
import { Method, Config, AxiosResponse } from '../Interfaces';
import { Method, Config, AxiosResponse, Headers } from '../Interfaces';

class RequestBase {
public url: string;
public method: Method = 'GET';
public headers: Headers = {};
public params: any;
public data: any;
public responseType: string = 'item';
Expand All @@ -22,8 +23,14 @@ class RequestBase {
params: this.params,
data: this.data,
};
if (Object.keys(this.headers).length > 0) {
config.headers = { ...this.headers };
}
if (this.isTokenNeeded) {
config.headers = await iamport.getHeaders();
config.headers = {
...config.headers,
...await iamport.getHeaders(),
};
}

return iamport.getApiInstance().request(config)
Expand Down
8 changes: 6 additions & 2 deletions lib/request/Payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import RequestBase from './Base';
import { PaymentResponse, PaymentAmountResponse } from '../response';
import { StatusEnum, SortingEnum } from '../enum';

import { ImpUidParams } from '../Interfaces';
import { ImpUidParams, Headers } from '../Interfaces';

interface ImpUidsParams {
imp_uid: string[],
Expand Down Expand Up @@ -80,9 +80,13 @@ class Payments extends RequestBase {
}

/* 결제정보 조회 > 아임포트 번호 */
public static getByImpUid({ imp_uid }: ImpUidParams): Payments {
public static getByImpUid({ imp_uid }: ImpUidParams, headers?: Headers): Payments {
const payments = new Payments();
payments.url = `/payments/${imp_uid}`;
if (headers && typeof headers === 'object' && !Array.isArray(headers) && Object.keys(headers).length !== 0) {
// 티어 결제 건 조회 용도
payments.headers = { ...headers };
}
return payments;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iamport-rest-client-nodejs",
"version": "0.9.6",
"version": "0.9.7",
"description": "NodeJS용 아임포트 REST API Client 입니다.",
"main": "dist/Iamport.js",
"types": "dist/Iamport.d.ts",
Expand Down

0 comments on commit 047a10e

Please sign in to comment.