メインコンテンツへスキップ

SDKs & ライブラリ

Waffo Pancake は公式 TypeScript SDK と直接 API アクセスを提供しています。

TypeScript SDK

@waffo/pancake-ts

npm 上の公式 TypeScript SDK

インストール

npm install @waffo/pancake-ts

特徴

  • ランタイム依存ゼロ、ESM + CJS、Node >= 20
  • リクエスト署名の自動化と決定的冪等キー
  • 完全な TypeScript 型定義(15 enum、40+ インターフェース)
  • 組み込み公開鍵による Webhook 署名検証(テスト/本番)

クイックスタート

import { WaffoPancake } from "@waffo/pancake-ts";

const client = new WaffoPancake({
  merchantId: process.env.WAFFO_MERCHANT_ID!,
  privateKey: process.env.WAFFO_PRIVATE_KEY!,
});

// ストアを作成
const { store } = await client.stores.create({ name: "My Store" });

// 単発商品を作成
const { product } = await client.onetimeProducts.create({
  storeId: store.id,
  name: "E-Book: TypeScript Handbook",
  prices: {
    USD: { amount: 2900, taxIncluded: false, taxCategory: "digital_goods" },
  },
});

// チェックアウトセッションを作成
const session = await client.checkout.createSession({
  storeId: store.id,
  productId: product.id,
  productType: "onetime",
  currency: "USD",
});
// => バイヤーを session.checkoutUrl にリダイレクト

設定

パラメータ必須説明
merchantIdstringはいマーチャント ID
privateKeystringはいRSA 秘密鍵(PEM、base64、生データ — 自動正規化)
baseUrlstringいいえAPI ベース URL(デフォルト:本番環境)
fetchtypeof fetchいいえカスタム fetch 実装

利用可能なリソース

ネームスペースメソッド説明
client.storescreate() update() delete()ストア管理
client.onetimeProductscreate() update() publish() updateStatus()単発商品 CRUD
client.subscriptionProductscreate() update() publish() updateStatus()サブスクリプション商品 CRUD
client.subscriptionProductGroupscreate() update() delete() publish()商品グループ(共有トライアル)
client.orderscancelSubscription()注文管理
client.checkoutcreateSession()チェックアウトセッション作成
client.graphqlquery<T>()型付き GraphQL クエリ

チェックアウト連携

import { WaffoPancake, CheckoutSessionProductType } from "@waffo/pancake-ts";

const client = new WaffoPancake({
  merchantId: process.env.WAFFO_MERCHANT_ID!,
  privateKey: process.env.WAFFO_PRIVATE_KEY!,
});

// ステップ 1:バイヤーのセッショントークンを発行
const { token } = await client.auth.issueSessionToken({
  storeId: "store_xxx",
  buyerIdentity: "customer@example.com",
});

// ステップ 2:チェックアウトセッションを作成
const session = await client.checkout.createSession({
  storeId: "store_xxx",
  productId: "prod_xxx",
  productType: CheckoutSessionProductType.Onetime,
  currency: "USD",
  buyerEmail: "customer@example.com",
  successUrl: "https://example.com/thank-you",
});

// ステップ 3:新しいタブでチェックアウトを開く(推奨)
// フロントエンド:window.open(session.checkoutUrl, "_blank", "noopener,noreferrer");

Webhook 検証

import { verifyWebhook, WebhookEventType } from "@waffo/pancake-ts";

// Express(生の body を使用 — パース済み JSON は署名検証を壊す)
app.post("/webhooks", express.raw({ type: "application/json" }), (req, res) => {
  try {
    const event = verifyWebhook(
      req.body.toString("utf-8"),
      req.headers["x-waffo-signature"] as string,
    );
    res.status(200).send("OK");

    switch (event.eventType) {
      case WebhookEventType.OrderCompleted:
        // 注文完了を処理
        break;
      case WebhookEventType.SubscriptionActivated:
        // サブスクリプション有効化を処理
        break;
    }
  } catch {
    res.status(401).send("Invalid signature");
  }
});

// Next.js App Router
export async function POST(request: Request) {
  const body = await request.text();
  const sig = request.headers.get("x-waffo-signature");
  try {
    const event = verifyWebhook(body, sig);
    // イベントを処理 ...
    return new Response("OK");
  } catch {
    return new Response("Invalid signature", { status: 401 });
  }
}

エラーハンドリング

import { WaffoPancakeError } from "@waffo/pancake-ts";

try {
  await client.stores.create({ name: "" });
} catch (err) {
  if (err instanceof WaffoPancakeError) {
    console.log(err.status);  // 400
    console.log(err.errors);  // [{ message: "...", layer: "store" }, ...]
  }
}

直接 API アクセス

REST および GraphQL API を直接利用することもできます。API Key 認証は SDK が自動処理するため、手動でヘッダーを設定する必要はありません。
// 商品を作成
const { product } = await client.onetimeProducts.create({
  storeId: "your-store-uuid",
  name: "My Product",
  prices: {
    USD: { amount: 2900, taxIncluded: false, taxCategory: "saas" },
  },
});

// GraphQL でデータをクエリ
const data = await client.graphql.query<{ stores: Array<{ id: string; name: string; status: string }> }>(
  `{ stores { id name status } }`
);

SDK ロードマップ

言語ステータス
Node.js / TypeScript公開済み — @waffo/pancake-ts
Python計画中
Go計画中
PHP計画中

フレームワークガイド

Next.js

Next.js と Server Actions で構築。

チェックアウトセッション

プログラムでチェックアウトフローを作成。

サブスクリプション

定期課金の実装。

Webhooks

リアルタイムのイベント通知を受信。

API リファレンス

エンドポイントの完全なドキュメント:

API リファレンス

REST および GraphQL API の完全なドキュメント。