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

univapay-node

v4.0.82

Published

[node]: https://nodejs.org/ [npm]: https://www.npmjs.com/ [yarn]: https://yarnpkg.com/ [webpack]: https://webpack.js.org/ [rollup]: https://rollupjs.org/ [univapay-url]: https://univapay.com/ [npm-url]: https://www.npmjs.com/package/univapay-node [build-u

Downloads

13,588

Readme

univapay-node

Node.jsUnivaPayAPI を使用するための SDK ライブラリです。

English readme

Github Actions NPM version Node.js version support Code coverage GitHub Issues GitHub Pull Requests CLA assistant MIT licensed

インストール

# npm (推奨)
npm install --save univapay-node

# yarn
yarn add univapay-node

利用方法

準備

ストアアプリケーショントークンがない場合は、まず以下の手順で作成してください。

  • 店舗 > 店舗を選択 > 開発 > アプリトークン ページに移動
  • 追加 をクリック
  • ドメインとモードを追加する
  • 作成されたトークンから JWT をコピーする
  • シークレットを保存することを忘れないでください

SDK のセットアップ

import SDK from "univapay-node";
// Node.JSなど、fetchが提供されない環境では
// import "cross-fetch/polyfill"
// import "isomorphic-form-data"
// を使ってください

const apiEndpoint = "https://api.univapay.com";
const storeJwt = jwt; // `準備`を参照
const storeJwtSecret = secret; // `準備`を参照

const sdk = new SDK({
    endpoint: apiEndpoint,
    jwt: storeJwt,
    secret: storeJwtSecret,
});

課金を作成する

import SDK, { PaymentType, TransactionTokenType, ResponseError } from "univapay-node";

const sdk = new SDK({ endpoint, jwt, secret });

// 課金用のトークンを作成
let transactionToken;
try {
  const transactionToken = await sdk.transactionTokens.create({
    type: TransactionTokenType.ONE_TIME, // 1回のみ利用可
    paymentType: PaymentType.CARD,

    // データの型は決済方法によって異なります
    data: { cardholder, cardNumber, expMonth, expYear, cvv }
  });
} catch (tokenCreateError: ResponseError) {
  handleError(tokenCreateError);
}

// 課金を作成
try {
  const charge = await sdk.charges.create({
    amount: 1000;
    currency: "JPY",
    transactionTokenId: transactionToken.id,
  });
} catch (chargeCreateError: ResponseError) {
  // 未使用のトークンをクリーンアップして、次の課金のために別のトークンを再作成します
  await sdk.transactionTokens.delete(transactionToken.id);

  handleError(chargeCreateError);
}

ポーリング

課金を作成した後、ステータスはpendingに初期化されます。 API が完全に処理し終わると、successfulまたはfailedになります。課金がfailedまたはsuccessfulになったタイミングを知る必要がある場合は、課金をポーリングすることができます。

import SDK, {
    PaymentType,
    TransactionTokenType,
    ResponseError,
} from "univapay-node";

const sdk = new SDK({ endpoint, jwt, secret });

const transactionToken = await sdk.transactionTokens.create(/* */);
const createdCharge = await sdk.charges.create(/* */); // Pending ステータス

const charge = await sdk.charges.poll(
    createdCharge.storeId,
    createdCharge.id,
    null,
    null,
    null,

    // ポーリングが停止してnullを返す条件
    // 任意: (charge:ResponseCharge) => boolean
    cancelCondition,

    // ポーリングが成功する条件。デフォルトは、statusがpendingではないこと
    // 任意: (charge: ResponseCharge) => boolean
    successCondition,
);

認証が必要な課金の作成

デフォルトでは、課金を作成するとそのままキャプチャされます。そうではなく、認証する必要がある場合は、captureプロパティを falseに設定し、任意のcaptureAtプロパティを指定して特定の日付で自動的にキャプチャするようにすることができます。

const charge = await sdk.charges.create({
  amount: 1000;
  currency: "JPY",
  transactionTokenId: transactionToken.id,
  capture: false, // 課金を直接はキャプチャしない
  captureAt: "2020-08-12", // 任意
});

API リファレンス

イベント

ChargesStoresなどの、PaymentsSDKおよびResourceベースのクラスはEventEmitterです。次のイベントをサブスクライブできます。

const sdk = new SDK();
sdk.on('request', (req: Request) => void)
sdk.on('response', (res: Response) => void)

RequestResponsefetchAPIの型です。

ブラウザでの利用方法

このモジュールは主にNode.js用に設計されていますが、WebpackRollupなどのバンドラによってトランスパイルされたときに、ブラウザで使用することができます。

コントリビュート

univapay-nodeの開発に寄与するには、このリポジトリをローカルで clone し、コードを別のブランチとして commit します。その際、コードの単体テストを記述し、プルリクエストを作成する前に Lint を実行してください。

npm run lint -- --fix
npm run format

npm test

ライセンス

univapay-nodeは、MITライセンスの下で配布されています。

Copyright © 2019, UnivaPay Team