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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@portone/server-sdk

v0.18.0

Published

PortOne JavaScript SDK for server-side usage

Readme

PortOne Server SDK for JavaScript

JavaScript 서버 환경에서 포트원 V2 결제 시스템에 연동하기 위한 SDK입니다.

API 색인

의존성

Web Crypto API와 Fetch API를 사용합니다.

  • Node.js의 경우 v20 이상이 필요합니다.
  • 기타 위 표준 API를 지원하는 모든 자바스크립트 런타임에서 사용할 수 있습니다.

설치

NPM Version JSR Version

npm 혹은 jsr을 통해 설치합니다.

npm install --save @portone/server-sdk

사용법

포트원 REST API

먼저 포트원 개발자콘솔에서 API Secret을 발급받습니다.

발급받은 API Secret을 사용해 필요한 API에 맞는 Client를 생성합니다.

import { PaymentClient, PortOneClient } from "@portone/server-sdk";

// 결제 관련 API를 사용하는 경우
const paymentClient = PaymentClient({ secret: PORTONE_API_SECRET });
paymentClient.getPayment(/* ... */);

// 전체 API를 사용하는 경우
const portoneClient = PortOneClient({ secret: PORTONE_API_SECRET });
// 상위 Client를 생성한 경우 하위 Client에 접근 가능합니다.
portoneClient.payment.getPayment(/* ... */);

Client의 각 함수는 함수마다 고유한 타입의 Error을 발생시킬 수 있습니다. Error의 data 필드는 서버로부터 받은 오류 응답값을 나타내며, data.type 필드를 통해 오류의 상세 원인을 파악하실 수 있습니다.

import { GetPaymentError } from "@portone/server-sdk/payment";

try {
    const payment = await paymentClient.getPayment({ paymentId: "test" });
} catch (e) {
    if (e instanceof GetPaymentError) {
        switch (e.data.type) {
            case "FORBIDDEN":
                // 요청이 거절된 경우
            case "INVALID_REQUEST":
                // 입력 정보가 유효하지 않은 경우
        }
    }
}

포트원 REST API로부터 현재 SDK 버전에서 지원하지 않는 응답을 받을 수 있습니다. 이 경우 isUnrecognized 편의 함수를 통해 해당 응답을 검출할 수 있습니다.

import { isUnrecognizedPayment } from "@portone/server-sdk/payment";

const payment = await paymentClient.getPayment({ paymentId: "test" });
console.log(payment.amount.total); // Error: Property 'amount' does not exist on type 'Payment'.
if (!isUnrecognizedPayment(payment)) {
    console.log(payment.amount.total); // Ok
}

웹훅 검증

먼저 포트원 개발자콘솔에서 웹훅 시크릿을 발급받습니다.

Webhook.verify 함수로 웹훅 내용을 검증할 수 있습니다.

주의: 웹훅 내용은 서버에서 전달한 body를 JSON 형태로 파싱하지 않고, 문자열 형태로 그대로 입력합니다.

import { Webhook } from "@portone/server-sdk";

const payload =
    `{"type":"BillingKey.Issued","timestamp":"2024-04-25T10:00:00.000Z","data":{"storeId":"store-61e0db3d-b967-47db-8b50-96002da90d55","billingKey":"billing-key-75ae3cab-6afe-422d-bf34-3a7b1762451d"}}`;
const headers = {
    "webhook-id": "test-id",
    "webhook-signature": `v1,aW52YWxpZCBzaWduYXR1cmU=`,
    "webhook-timestamp": "100",
};
await Webhook.verify(PORTONE_WEBHOOK_SECRET, payload, headers);

Webhook.verify 함수는 body를 object 형태로 변환하여 반환합니다. 웹훅 또한 현재 SDK 버전에서 지원하지 않은 응답을 받을 수 있으며, 이 경우 isUnrecognizedWebhook 편의 함수를 통해 해당 응답을 검출할 수 있습니다.

const webhook = await Webhook.verify(/* ... */);

console.log(webhook.data); // Error: Property 'data' does not exist on type 'Webhook'.
if (!Webhook.isUnrecognizedWebhook(webhook)) {
    console.log(payment.data); // Ok
}

웹훅의 type 값에 따라 data의 형식이 변하기 때문에, 각 필드에 접근하기 위해서는 type을 확인해야 합니다.

if (
    webhook.type === "Transaction.Paid" ||
    webhook.type === "Transaction.VirtualAccountIssued"
) {
    console.log(webhook.data.paymentId);
}
if (webhook.type === "Transaction.Cancelled") {
    console.log(webhook.data.cancellationId);
}

버전

유의적 버전 2.0.0을 사용합니다.

현재 주(主) 버전은 0입니다. 이는 라이브러리 공개 API가 아직 고정되지 않았음을 의미합니다. 주 버전이 1이 되기 전에도 릴리스 버전(프리릴리스가 아닌 버전)의 SDK를 프로덕션에서 사용할 수 있으며, 포트원은 관련 기술 지원을 제공합니다.

API 안정성

포트원 V2는 REST API의 하위 호환을 보장합니다. 본 SDK는 REST API에 의존하므로, 한 버전의 SDK로 연동한 뒤에는 해당 버전에 특별한 버그가 없는 한 연동이 깨지지 않습니다.

SDK의 버전을 업데이트한 경우 코드 호환성이 깨질 수 있습니다. 이 경우 코드 작업이 필요합니다.

기술 지원


Packages under portone-io/server-sdk-js are primarily distributed under the terms of both the Apache License (Version 2.0) and the MIT license. See COPYRIGHT for details.