Node.js
Jamm Node.js SDKのインストールと利用 — 決済・返金・カスタマー・Webhook。
インストール
npm install @jamm-pay/node-sdk ソース: github.com/jamm-pay/node-sdk
初期化
import jamm from "@jamm-pay/node-sdk";
jamm.config.init({
clientId: process.env.JAMM_CLIENT_ID,
clientSecret: process.env.JAMM_CLIENT_SECRET,
environment: "staging", // "staging" | "prod"(その他: "local" | "develop" | "testing")
}); ⚙️ 注: SDKはアクセストークンの交換と更新を自動的に行います。
On-session決済
const result = await jamm.payment.onSessionPayment({
buyer: { email: "customer@example.com" },
charge: { price: 4000, description: "Order 1234" },
redirect: {
successUrl: "https://yoursite.com/success",
failureUrl: "https://yoursite.com/failure"
},
oneTime: true,
});
const paymentUrl = result.data?.paymentLink?.url; // buyerをここにリダイレクト カスタマーの状態を確認
off-sessionで請求する前に、カスタマーを取得してactivatedがtrueであることを確認してください。activatedは契約状況と、該当する場合はKYC状況を反映するため、カスタマーが請求可能かどうかを判断する単一の指標です。
const customer = await jamm.customer.get("cus-...");
if (!customer?.activated) {
// まだ請求できません — スキップするなど適切に処理してください
} Off-session決済(非同期)
請求前にカスタマーのactivatedを確認してください — 上記のカスタマーの状態を確認を参照。
const result = await jamm.payment.offSessionPaymentAsync({
customer: "cus-...",
charge: { price: 1000, description: "Monthly plan" },
idempotencyKey: "order-2026-001", // 任意。省略時は自動生成
}); 返金・キャンセル
await jamm.payment.refund({ chargeId: "trx-..." }); // 全額。当日はキャンセル、それ以降は返金
await jamm.payment.refund({ chargeId: "trx-...", amount: 500 }); // 部分返金
await jamm.payment.refund({ chargeId: "trx-...", cancelOnly: true }); // キャンセルのみ(返金フォールバックなし) Webhook
jamm.webhook.verify({ data: body, signature });
const event = jamm.webhook.parse({ data: body });
if (jamm.types.eventTypeEquals(jamm.types.EventType.CHARGE_SUCCESS, event.eventType)) {
// 注文を確定
} Was this page helpful?
Need help? Coming Soon
Support Center Slack community Contact usSign up for our developer newsletter: Coming Soon
You can unsubscribe at any time. Read our
privacy policy and terms and conditions.
privacy policy and terms and conditions.