Skip to content

Commit

Permalink
refactor(stdpay): add oid, timestamp to StdPayGetParamsInput
Browse files Browse the repository at this point in the history
  • Loading branch information
greatSumini committed Jun 17, 2021
1 parent e04da17 commit 6933fc0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7,722 deletions.
14 changes: 8 additions & 6 deletions lib/interfaces/stdpay.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export type StdPayGetParamsInput = {
* @default '' */
gopaymethod?: string;

/** ์ฃผ๋ฌธ๋ฒˆํ˜ธ (* ๋ฐ˜๋“œ์‹œ Unique ๊ฐ’์œผ๋กœ ์ƒ์„ฑ (๊ฑฐ๋ž˜์ถ”์  ์‹œ ์‚ฌ์šฉ๋จ))
* @default `${timestamp}${getRandomString(4)}` */
oid?: string;

/** ํƒ€์ž„์Šคํ…œํ”„ [TimeInMillis(Longํ˜•)]
* @default new Date().getTime() */
timestamp?: number;

/** ๊ฒฐ์ œ ๊ธˆ์•ก (* ์ˆซ์ž๋งŒ, 1๋‹ฌ๋Ÿฌ๋Š” 100์œผ๋กœ ์‹œ์ž‘) */
price: number;

Expand Down Expand Up @@ -56,12 +64,6 @@ export type StdPayRequestParams = Pick<InicisOptions, 'mid'> &
/** ์ „๋ฌธ ๋ฒ„์ „ ["1.0" ๊ณ ์ •] */
version: '1.0';

/** ์ฃผ๋ฌธ๋ฒˆํ˜ธ (* ๋ฐ˜๋“œ์‹œ Unique ๊ฐ’์œผ๋กœ ์ƒ์„ฑ (๊ฑฐ๋ž˜์ถ”์  ์‹œ ์‚ฌ์šฉ๋จ)) */
oid: string;

/** ํƒ€์ž„์Šคํ…œํ”„ [TimeInMillis(Longํ˜•)] */
timestamp: number;

/** SHA256 Hash๊ฐ’ [๋Œ€์ƒ: oid, price, timestamp] */
signature: string;

Expand Down
11 changes: 7 additions & 4 deletions lib/resources/stdpay.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ export class InicisStdpay {
constructor(private readonly inicisOptions: InicisOptions) {}

getParams(input: StdPayGetParamsInput): StdPayRequestParams {
const timestamp = new Date().getTime();
const oid = `${timestamp}${getRandomString(4)}`;
const {
timestamp = new Date().getTime(),
oid = `${timestamp}${getRandomString(4)}`,
price,
} = input;

const { mid, signkey } = this.inicisOptions;

const mKey = hash(signkey, 'sha256');
const signature = sign({
oid,
price: input.price,
price,
timestamp,
});

return {
...input,
...STDPAY_BASE_PARAMS,
...input,
mid,
oid,
timestamp,
Expand Down
Loading

0 comments on commit 6933fc0

Please sign in to comment.