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

iamport-server-api

v8.0.0

Published

API for Iamport Server

Downloads

526

Readme

Iamport Server API

GitHub license npm version Downloads Build Status

npm install --save iamport-server-api

iamport-server-apifake-iamport-server 를 기반으로 만들어진 SDK (Software Development Kit) 이다. 그리고 fake-iamport-server 는 아임포트의 API 명세사항을 따라 만든 목업 서버이기에, 본 iamport-server-api 는 진짜 아임포트 서버와의 연동에도 사용할 수 있다.

고로 아임포트와 연동하는 TypeScript 기반 백엔드 서버를 개발함에 있어, 가짜 아임포트 서버 fake-iamport-server 는 직접 이용치 않더라도, 실제 아임포트 서버와의 연동을 위하여, 본 SDK 라이브러리만큼은 반드시 설치하기를 권장하는 바이다.

import { v4 } from "uuid";

import imp from "iamport-server-api";
import { IIamportCardPayment } from "iamport-server-api/lib/structures/IIamportCardPayment";
import { IIamportPayment } from "iamport-server-api/lib/structures/IIamportPayment";
import { IIamportResponse } from "iamport-server-api/lib/structures/IIamportResponse";

export async function test_fake_card_payment(): Promise<IIamportCardPayment>
{
    // 커넥터 정보 구성, 토큰 만료시 자동으로 갱신해 줌
    const connector: imp.IamportConnector = new imp.IamportConnector
    (
        "http://127.0.0.1:10851",
        {
            imp_key: "test_imp_key",
            imp_secret: "test_imp_secret"
        }
    );

    // 카드로 결제하기
    const output: IIamportResponse<IIamportCardPayment> = 
        await imp.functional.subscribe.payments.onetime
        (
            await connector.get(),
            {
                card_number: "1111-2222-3333-4444",
                expiry: "2028-12",
                birth: "880311",

                merchant_uid: v4(),
                amount: 25_000,
                name: "Fake 주문"
            }
        );

    // 결제 내역 조회하기
    const reloaded: IIamportResponse<IIamportPayment> = 
        await imp.functional.payments.at
        (
            await connector.get(),
            output.response.imp_uid,
            {},
        );

    // 결제 방식 및 완료 여부 확인
    const payment: IIamportPayment = reloaded.response;
    if (payment.pay_method !== "card")
        throw new Error("Bug on payments.at(): its pay_method must be card.");
    else if (!payment.paid_at || payment.status !== "paid")
        throw new Error("Bug on payments.at(): its status must be paid.");

    // 첫 번째 if condition 에 의해 자동 다운 캐스팅 된 상태
    payment.card_number;
    return payment;
}