TRADOM PaymentDocs

TypeScript SDK

@tradom/paymentのインストール、client設定、利用できるresource

@tradom/payment は、TRADOM Payment APIをNode.jsから利用するためのサーバ側SDKです。このドキュメントは 0.5.0 を対象にしています。

0.5.0 は checkoutStatus の入金レシート(underpaid / txHash / paidAmount など)と、Hosted Checkoutの補助endpoint(referenceQuote / verifyStatus / extendSession / resetVerification)を追加したreleaseです。GatewayのUSD注文・TRON / USDT・slippageCheck はproductionで利用できます。

インストール

npm install @tradom/payment

Clientを作成

import { PaymentClient } from "@tradom/payment";

const TRADOM_PAYMENT_GATEWAY_KEY =
  process.env.TRADOM_PAYMENT_GATEWAY_KEY;

if (!TRADOM_PAYMENT_GATEWAY_KEY) {
  throw new Error("TRADOM_PAYMENT_GATEWAY_KEY is required");
}

export const tradomPayment = new PaymentClient({
  apiKey: TRADOM_PAYMENT_GATEWAY_KEY,
});

SDKはサーバ専用です。API keyをbrowser bundle、mobile app、公開repositoryへ含めないでください。

認証情報

利用するAPIごとに、別のclientを作成します。

KeyResource用途
gw_live_…client.gatewayHosted Checkout
sk_test_… / sk_live_…client.paymentIntentsCustom Payment Flow
sk_test_… / sk_live_…client.webhookEndpoints / client.eventsWebhook登録・event参照
whsec_…constructEventWebhook署名検証

Gateway用とPaymentIntent用のkeyは別の認証情報です。1つの PaymentClient で使い回さないでください。

Resource

ResourceMethod
gatewaycreateOrder、checkoutStatus、selectAsset、refreshQuote、acceptTos、simulateDeposit、slippageCheck、referenceQuote、verifyStatus、extendSession、resetVerification
paymentIntentscreate、createCheckoutSession、retrieve、cryptoQuote、confirm、cancel、refund、simulateDeposit
webhookEndpointscreate、list
eventslist、retrieve

Webhook署名検証は constructEvent または verifyWebhookSignature を直接importします。

Client options

const client = new PaymentClient({
  apiKey: TRADOM_PAYMENT_GATEWAY_KEY,
  baseUrl: "https://payment.tradom.jp",
  authScheme: "x-api-key",
  timeoutMs: 15_000,
});
OptionDefault説明
apiKeyなし認証付き操作では必須。token/client-secret scoped操作だけなら省略可
baseUrlhttps://payment.tradom.jpAPIの接続先
authSchemex-api-keyGatewayのkey送信方式。bearerも選択可
timeoutMs15000request timeout
fetchglobalThis.fetchtestやcustom agent用のfetch実装

PaymentIntentのマーチャント操作は、authScheme に関係なくBearer認証を使います。retrieve、cryptoQuote、confirm はoptionsへ clientSecret を渡すと、代わりに X-Client-Secret を送信します。

API keyなしのclient

公開checkout tokenまたはPaymentIntentのclient secretだけを使う場合は、API keyを省略できます。

const checkoutClient = new PaymentClient({});
const session = await checkoutClient.paymentIntents.createCheckoutSession({
  paymentLinkToken: "<share_token>",
});

const latest = await checkoutClient.paymentIntents.retrieve(session.id, {
  clientSecret: session.clientSecret!,
});

API keyを省略したclientで認証必須methodを呼ぶと、通信前に PaymentError("authentication_required") をthrowします。SDK自体はサーバ専用なので、この処理はbackend/BFFに置いてください。

Responseとerror

REST APIの snake_case はSDKで camelCase に変換されます。API errorと通信errorは PaymentError になります。

import { PaymentError } from "@tradom/payment";

try {
  await tradomPayment.gateway.checkoutStatus(checkoutToken);
} catch (error) {
  if (error instanceof PaymentError) {
    console.error(error.code, error.httpStatus);
  }
}

詳しくは error handling を参照してください。

Versionと互換性

本番REST APIとSDKの既知差分は 互換性・既知の制約 にまとめています。

このページの内容