npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@team-mintc/portone-v2

v0.7.9

Published

api wrapper for portone v2

Downloads

88

Readme

MintC Logo

PortOne V2

설치

npm 사용

npm i @team-mintc/portone-v2

yarn사용

yarn add @team-mintc/portone-v2

Usage

결제 요청

pages/index.tsx

import {PortOne} from '@team-mintc/portone-v2';

// ...

PortOne.requestPayment({
  // 가맹점 storeId로 변경해주세요.
  storeId,
  isTestChannel: true,
  redirectUrl: 'http://192.168.50.27:3000/payment/redirect',
  orderName: productName,
  totalAmount: amount,
  pgProvider: 'PG_PROVIDER_TOSSPAYMENTS',
  payMethod: 'CARD',
  paymentId,
  taxFreeAmount,
  customer: {
    customerId: 'customerId_now',
    fullName: '신현성',
    phoneNumber: '1670-5176',
    email: '[email protected]',
    zipcode: '04783',
  },
  windowType: {
    pc: 'IFRAME',
    mobile: 'REDIRECTION',
  },
  noticeUrls: ['http://192.168.50.27:3000/api/payment/hook'],
  confirmUrl: 'http://192.168.50.27:3000/payment/confirm',
  appScheme: 'portone://',
  isCulturalExpense: false,
  currency: 'CURRENCY_KRW',
  locale: 'KO_KR',
});

결제 검증

api/complete.ts

import {initializePortOneAPI} from '@team-mintc/portone-v2';

// ...

try {
  // 요청의 body로 SDK의 응답 중 txId와 paymentId가 오기를 기대합니다.
  const {txId, paymentId} = req.body;

  // 1. PortOne API Key를 통해 AccessToken을 가져옵니다.
  const portOneAPI = await initializePortOneAPI(
    process.env.PORTONE_API_KEY || '', // 포트원 API Key
  );

  // 2. 포트원 결제내역 단건조회 API 호출
  const paymentResponse = await portOneAPI.getPaymentDetails({
    payment_id: paymentId,
  });
  const {payment} = paymentResponse;
  const {id, transactions} = payment;

  // 대표 트랜잭션(승인된 트랜잭션)을 선택합니다.
  const transaction = transactions.find((tx: any) => tx.is_primary === true);
  if (!transaction) throw 'no transaction';

  // 3. 가맹점 내부 주문 데이터의 가격과 실제 지불된 금액을 비교합니다.
  const order = await FakeORM.OrderService.findById(id);
  if (order && order.amount === transaction.amount.total) {
    switch (transaction.status) {
      case 'VIRTUAL_ACCOUNT_ISSUED': {
        // const {virtual_account} = transaction.payment_method_detail;
        // 가상 계좌가 발급된 상태입니다.
        // 계좌 정보(virtual_account)를 이용해 원하는 로직을 구성하세요.
        console.log('가상 계좌');
        break;
      }
      case 'PAID': {
        // 모든 금액을 지불했습니다! 완료 시 원하는 로직을 구성하세요.
        console.log('paid');
        break;
      }
    }
    res.status(200).send('ok');
  } else {
    // 결제 금액이 불일치하여 위/변조 시도가 의심됩니다.
    res.status(400).send('warning: diff');
  }
} catch (e: any) {
  // 결제 검증에 실패했습니다.
  console.error('fail', e.message, e.response.data);
  res.status(400).send(e);
}

// ...

문서

https://portone.gitbook.io/docs/api-v2/v2-api

getPaymentDetails: 결제내역 단건조회

getPaymentsDetails: 결제내역 다건조회

cancelPayment: 결제 취소

resendWebhook: 웹훅 재발송

noticeVirtualAccountDeposit: 가상계좌 테스트 웹훅 호출

schedulesPayment: 결제 예약

payBillingKey: 빌링키 결제

payInstant: 키인(수기) 결제

escrowLogis: 에스크로 배송정보 등록/변경

escrowComplete: 에스크로 구매완료

getSchedules: 정기결제예약 다건 조회

cancelSchedules: 빌링키 정기결제예약 취소

getSchedule: 정기결제예약 단건 조회

getChannels: 채널 불러오기

getCashReceipt: 현금영수증 조회

issueCashReceipt: 현금영수증 발급

cancelCashReceipt: 현금영수증 발급 취소

getBillingKeys: 빌링키 다건 조회

issueBillingKey: 빌링키 발급

getBillingKey: 빌링키 단건 조회

deleteBillingKey: 빌링키 취소

getStores: 하위상점 다건 조회

createStore: 하위상점 생성

getStore: 하위상점 단건 조회

updateStore: 하위상점 수정

getStoreApplication: 하위상점의 전자결제 신청 정보를 가져오기 (호스팅사 > 포트원)

requestApplications: 온보딩 API 를 통해 전자결제 신청하기 (호스팅사 > 포트원 > 결제대행사)

getTossPaymentsStatusAndUrl: 가입 신청 URL 호출 & 상태값 조회하기

예제 코드

https://github.com/team-mintc/example-payments