Skip to main content

SDKs & Libraries

Waffo Pancake provides an official TypeScript SDK and direct API access.

TypeScript SDK

@waffo/pancake-ts

Official TypeScript SDK on npm

Installation

npm install @waffo/pancake-ts

Features

  • Zero runtime dependencies, ESM + CJS, Node >= 20
  • Automatic request signing with deterministic idempotency keys
  • Full TypeScript type definitions (15 enums, 40+ interfaces)
  • Webhook verification with embedded public keys (test/prod)

Quick Start

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

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

// Create a store
const { store } = await client.stores.create({ name: "My Store" });

// Create a one-time product
const { product } = await client.onetimeProducts.create({
  storeId: store.id,
  name: "E-Book: TypeScript Handbook",
  prices: {
    USD: { amount: 2900, taxIncluded: false, taxCategory: "digital_goods" },
  },
});

// Create a checkout session
const session = await client.checkout.createSession({
  storeId: store.id,
  productId: product.id,
  productType: "onetime",
  currency: "USD",
});
// => redirect buyer to session.checkoutUrl

Configuration

ParameterTypeRequiredDescription
merchantIdstringYesYour Merchant ID
privateKeystringYesRSA private key (PEM, base64, or raw — auto-normalized)
baseUrlstringNoAPI base URL (default: production)
fetchtypeof fetchNoCustom fetch implementation

Available Resources

NamespaceMethodsDescription
client.storescreate() update() delete()Store management
client.onetimeProductscreate() update() publish() updateStatus()One-time product CRUD
client.subscriptionProductscreate() update() publish() updateStatus()Subscription product CRUD
client.subscriptionProductGroupscreate() update() delete() publish()Product groups for shared trial
client.orderscancelSubscription()Order management
client.checkoutcreateSession()Create checkout sessions
client.graphqlquery<T>()Typed GraphQL queries

Checkout Integration

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

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

// Create checkout session
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",
});

// Step 3: Open checkout in new tab (recommended)
// Frontend: window.open(session.checkoutUrl, "_blank", "noopener,noreferrer");

Webhook Verification

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

// Express (use raw body — parsed JSON breaks signature verification)
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:
        // handle order completion
        break;
      case WebhookEventType.SubscriptionActivated:
        // handle subscription activation
        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);
    // handle event ...
    return new Response("OK");
  } catch {
    return new Response("Invalid signature", { status: 401 });
  }
}

Error Handling

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" }, ...]
  }
}

Direct API Access

You can also use the REST and GraphQL API directly. API Key authentication is handled automatically by the SDK — no manual header setup is needed.
// Create a product
const { product } = await client.onetimeProducts.create({
  storeId: "your-store-uuid",
  name: "My Product",
  prices: {
    USD: { amount: 2900, taxIncluded: false, taxCategory: "saas" },
  },
});

// Query data via GraphQL
const data = await client.graphql.query<{ stores: Array<{ id: string; name: string; status: string }> }>(
  `{ stores { id name status } }`
);

SDK Roadmap

LanguageStatus
Node.js / TypeScriptAvailable — @waffo/pancake-ts
PythonPlanned
GoPlanned
PHPPlanned

Framework Guides

Next.js

Build with Next.js and Server Actions.

Checkout Sessions

Create checkout flows programmatically.

Subscriptions

Implement recurring billing.

Webhooks

Receive real-time event notifications.

API Reference

For complete endpoint documentation:

API Reference

Full REST and GraphQL API documentation.