Skip to content

posquit0/node-iamporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Iamporter.js
Iamporter

A REST API client for I'mport


Iamporter๋Š” ์•„์ž„ํฌํŠธ์—์„œ ์ œ๊ณตํ•˜๋Š” REST API๋ฅผ ์‰ฝ๊ฒŒ ํ™œ์šฉํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ์ž‘์„ฑ๋œ Node.js ํด๋ผ์ด์–ธํŠธ ์ž…๋‹ˆ๋‹ค.

  • ์•„์ž„ํฌํŠธ๋Š” ๊ตญ๋‚ด PG์‚ฌ์™€์˜๊ฐ„ํŽธํ•œ ์—ฐ๋™์„ ์ œ๊ณตํ•˜๋Š” ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค.
  • ์ด์šฉ ์ค‘ ๋ฐœ์ƒํ•œ ๋ฌธ์ œ์— ๋Œ€ํ•˜์—ฌ ์ฑ…์ž„์ง€์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • ์ตœ์ดˆ ์ž‘์„ฑ์€ ์ž๋™์ฐจ ๋ ŒํŠธ ํ”Œ๋žซํผ CARPLAT์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•˜์—ฌ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

Features

  • Written in ES6 Syntax
  • Promise Support
  • Exception Handling with a custom error class IamporterError

Installation

$ npm install iamporter

Specification

  • ๋ชจ๋“  API ์š”์ฒญ์€ Promise๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Fulfilled

  • API ์š”์ฒญ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ˆ˜ํ–‰๋œ ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ˜•์‹์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
{
  "status": 200, // HTTP STATUS CODE
  "message": "", // ์•„์ž„ํฌํŠธ API ์‘๋‹ต ๋ฉ”์‹œ์ง€ ํ˜น์€ Iamporter ์ •์˜ ๋ฉ”์‹œ์ง€
  "data": {}, // ์•„์ž„ํฌํŠธ API ์‘๋‹ต ๋ฐ์ดํ„ฐ
 ย "raw": {} // ์•„์ž„ํฌํŠธ API RAW DATA
}

Rejected

  • API ์š”์ฒญ์„ ์„ฑ๊ณต์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•˜์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ ํ•ญ์ƒ IamporterError ์—๋Ÿฌ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
iamporter.paySubscription(...)
  .catch((err) => {
    console.log(err.status); // HTTP STATUS CODE
    console.log(err.message); // ์•„์ž„ํฌํŠธ API ์‘๋‹ต ๋ฉ”์‹œ์ง€ ํ˜น์€ Iamporter ์ •์˜ ๋ฉ”์‹œ์ง€
    console.log(err.data); // ์•„์ž„ํฌํŠธ API ์‘๋‹ต ๋ฐ์ดํ„ฐ
    console.log(err.raw); // ์•„์ž„ํฌํŠธ API RAW DATA
  });

Usage

Import & Create an Instance

  • iamporter ํŒจํ‚ค์ง€๋Š” Iamporter์™€ IamporterError ๋‘ ํด๋ž˜์Šค๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
const { Iamporter, IamporterError } = require('iamporter');

// For Testing (ํ…Œ์ŠคํŠธ์šฉ API KEY์™€ SECRET ๊ธฐ๋ณธ ์„ค์ •)
const iamporter = new Iamporter();

// For Production
const iamporter = new Iamporter({
  apiKey: 'YOUR_API_KEY',
  secret: 'YOUR_SECRET'
});

API Token

  • iamporter๋Š” API ์š”์ฒญ ์ „์— API ํ† ํฐ์˜ ์œ ํšจ์„ฑ์„ ํ™•์ธ ํ›„ ์ž๋™ ๋ฐœ๊ธ‰/๊ฐฑ์‹ ํ•˜๋ฏ€๋กœ ์ง์ ‘ ํ† ํฐ API๋ฅผ ํ˜ธ์ถœํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.
// ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ์‹œ ์„ค์ •ํ•œ API KEY์™€ SECRET
iamporter.getToken()
  .then(...)

// ํ† ํฐ ์ƒ์„ฑ ์‹œ ์‚ฌ์šฉ๋  API KEY์™€ SECRET ์ง์ ‘ ์ง€์ •
iamporter.getToken('API_KEY', 'SECRET')
  .then(...)

Subscription

  • ์ •๊ธฐ ๊ตฌ๋…(Subscription)ํ˜• ์„œ๋น„์Šค ๋“ฑ์— ์ด์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋นŒ๋งํ‚ค๋ฅผ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
// ๋นŒ๋งํ‚ค ์ƒ์„ฑ
iamporter.createSubscription({
  'customer_uid': 'test_uid',
  'card_number': '1234-1234-1234-1234',
  'expiry': '2021-11',
  'birth': '620201',
  'pwd_2digit': '99'
}).then(result => {
  console.log(result);
}).catch(err => {
  if (err instanceof IamporterError)
    // Handle the exception
});

// ๋นŒ๋งํ‚ค ์กฐํšŒ
iamporter.getSubscription('test_uid')
  .then(...)

// ๋นŒ๋งํ‚ค ์‚ญ์ œ
iamporter.deleteSubscription('test_uid')
  .then(...)

// ๋น„์ธ์ฆ ๊ฒฐ์ œ (๋นŒ๋งํ‚ค ์ด์šฉ)
iamporter.paySubscription({
  'customer_uid': 'test_uid',
  'merchant_uid': 'test_billing_key',
  'amount': 50000
}).then(result => {
    console.log(result);
}).catch(err => {
  if (err instanceof IamporterError)
    // Handle the exception
});

Onetime Payment

  • ๋นŒ๋งํ‚ค๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š์•„๋„ ์‹ ์šฉ์นด๋“œ ์ •๋ณด๋งŒ์œผ๋กœ ๊ฐ„ํŽธ ๊ฒฐ์ œ๋ฅผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
// Onetime ๋น„์ธ์ฆ ๊ฒฐ์ œ
iamporter.payOnetime({
  'merchant_uid': 'merchant_1448280088556',
  'amount': 5000,
  'card_number': '1234-1234-1234-1234',
  'expiry': '2021-12',
  'birth': '590912',
  'pwd_2digit': '11'
}).then(result => {
    console.log(result);
}).catch(err => {
  if (err instanceof IamporterError)
    // Handle the exception
});

// ํ•ด์™ธ์นด๋“œ ๋น„์ธ์ฆ ๊ฒฐ์ œ
iamporter.payForeign({
  'merchant_uid': 'merchant_1448280088556',
  'amount': 5000,
  'card_number': '1234-1234-1234-1234',
  'expiry': '2021-12',
}).then(result => {
    console.log(result);
}).catch(err => {
  if (err instanceof IamporterError)
    // Handle the exception
});

Cancel the Payment

  • ์•„์ž„ํฌํŠธ ๊ณ ์œ  ์•„์ด๋”” ํ˜น์€ ์ƒ์  ๊ณ ์œ  ์•„์ด๋””๋กœ ๊ฒฐ์ œ ์ทจ์†Œ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  • ๋ถ€๋ถ„ ๊ฒฐ์ œ ์ทจ์†Œ ๋˜ํ•œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
// ์•„์ž„ํฌํŠธ ๊ณ ์œ  ์•„์ด๋””๋กœ ๊ฒฐ์ œ ์ทจ์†Œ
iamporter.cancelByImpUid('imp_448280090638')
  .then(...)

// ์ƒ์  ๊ณ ์œ  ์•„์ด๋””๋กœ ๊ฒฐ์ œ ์ทจ์†Œ
iamporter.cancelByMerchantUid('merchant_1448280088556')
  .then(...)

// ์ƒ์  ๊ณ ์œ  ์•„์ด๋””๋กœ ๋ถ€๋ถ„ ๊ฒฐ์ œ ์ทจ์†Œ
iamporter.cancelByMerchantUid('merchant_1448280088556', {
  'amount': 2500,
  'reason': '์˜ˆ์•ฝ ๋ณ€๊ฒฝ'
}).then(...)

// ๊ฒฐ์ œ ์ทจ์†Œ ํ›„ ๊ณ„์ขŒ ํ™˜๋ถˆ
iamporter.cancel({
  'imp_uid': 'imp_448280090638',
  'reason': '์ œํ’ˆ ์ƒํƒœ ๋ถˆ๋Ÿ‰',
  'refund_holder': 'ํ™๊ธธ๋™',
  'refund_bank': '03',
  'refund_account': '056-076923-01-017'
).then(...)

Find the Payments

  • ์•„์ž„ํฌํŠธ์—์„œ๋Š” ์•„์ž„ํฌํŠธ ๊ณ ์œ  ์•„์ด๋””(ImpUid)์™€ ์ƒ์  ๊ณ ์œ  ์•„์ด๋””(MerchantUid)๋กœ ๊ฒฐ์ œ์ •๋ณด ์กฐํšŒ๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
// ์•„์ž„ํฌํŠธ ๊ณ ์œ  ์•„์ด๋””๋กœ ๊ฒฐ์ œ์ •๋ณด ์กฐํšŒ
iamporter.findByImpUid('imp_448280090638')
  .then(...)

// ์ƒ์  ๊ณ ์œ  ์•„์ด๋””๋กœ ๊ฒฐ์ œ์ •๋ณด ์กฐํšŒ
iamporter.findByMerchantUid('merchant_1448280088556')
  .then(...)

// ์ƒ์  ๊ณ ์œ  ์•„์ด๋””๋กœ ๊ฒฐ์ œ์ •๋ณด ๋ชฉ๋ก ์กฐํšŒ
iamporter.findAllByMerchantUid('merchant_1448280088556')
  .then(...)

// ๊ฒฐ์ œ ์ƒํƒœ๋กœ ๊ฒฐ์ œ์ •๋ณด ๋ชฉ๋ก ์กฐํšŒ(status: ['all', 'ready', 'paid', 'cancelled', 'failed'])
iamporter.findAllByStatus('paid')
  .then(...)

Prepared Payment

  • ์•„์ž„ํฌํŠธ์—์„œ๋Š” ๊ฒฐ์ œ ๊ฑด์— ๋Œ€ํ•œ ์‚ฌ์ „ ์ •๋ณด ๋“ฑ๋ก ๋ฐ ๊ฒ€์ฆ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
// ๊ฒฐ์ œ ์˜ˆ์ •๊ธˆ์•ก ์‚ฌ์ „ ๋“ฑ๋ก
iamporter.createPreparedPayment({
  'merchant_uid': 'merchant_1448280088556',
  'amount', '128900'
}).then(...)

// ๊ฒฐ์ œ ์˜ˆ์ •๊ธˆ์•ก ์กฐํšŒ
iamporter.getPreparedPayment('merchant_1448280088556')
  .then(...)

Certifications

  • ์•„์ž„ํฌํŠธ์—์„œ๋Š” SMS ๋ณธ์ธ์ธ์ฆ ๊ฒฐ๊ณผ๋ฅผ ์กฐํšŒ/์‚ญ์ œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
// ์•„์ž„ํฌํŠธ ๊ณ ์œ  ์•„์ด๋””๋กœ SMS ๋ณธ์ธ์ธ์ฆ ๊ฒฐ๊ณผ ์กฐํšŒ
iamporter.getCertification('imp_448280090638')
  .then(...)

// ์•„์ž„ํฌํŠธ ๊ณ ์œ  ์•„์ด๋””๋กœ SMS ๋ณธ์ธ์ธ์ฆ ๊ฒฐ๊ณผ ์‚ญ์ œ
iamporter.deleteCertification('imp_448280090638')
  .then(...)

VBanks

  • ์•„์ž„ํฌํŠธ์—์„œ๋Š” PG ๊ฒฐ์ œํ™”๋ฉด ์—†์ด API ๋งŒ์œผ๋กœ ๊ฐ€์ƒ๊ณ„์ขŒ ๋ฐœ๊ธ‰์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
// ๊ฐ€์ƒ๊ณ„์ขŒ ๋ฐœ๊ธ‰
iamporter.createVbank({
  'merchant_uid': 'merchant_1448280088556',
  'amount': '128900',
  'vbank_code': '03',
  'vbank_due': 1485697047,
  'vbank_holder': 'PLAT Corp'
}).then(...)

Links

Contact

If you have any questions, feel free to join me at #posquit0 on Freenode and ask away. Click here to connect.

License