Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.toffeepay.com/llms.txt

Use this file to discover all available pages before exploring further.

Install

npm install @toffeepay/sdk

Configuration

import { Toffee } from "@toffeepay/sdk";

const toffee = new Toffee({
  accessToken: "your-access-token",
});

Sandbox

const toffee = new Toffee({
  accessToken: "your-sandbox-token",
  environment: "sandbox",
});

Checkout

Shorthand for creating a payment session:
const session = await toffee.checkout({
  item: { title: "Gem Pack 50", price: 100, currency: "USD" },
  gameId: "your-game-id",
  userId: "user-id",
  returnUrl: "https://example.com/return",
});

console.log(session.url); // redirect the user here

Refund

Shorthand for creating a refund:
const refund = await toffee.refund({ paymentId: "pay_123" });

Idempotency

Pass an idempotency key to protect against duplicate operations:
const session = await toffee.checkout(
  {
    item: { title: "Gem Pack 50", price: 100, currency: "USD" },
    gameId: "game_1",
    userId: "user_1",
    returnUrl: "https://example.com/return",
  },
  { idempotencyKey: "unique-key-123" },
);

const refund = await toffee.refund(
  { paymentId: "pay_123" },
  { idempotencyKey: "refund-key-456" },
);

Resources

Sessions

const { session } = await toffee.sessions.create({ ... });
const { session } = await toffee.sessions.get({ id: "sess_123" });
const { status }  = await toffee.sessions.status({ id: "sess_123" });
const { sessions } = await toffee.sessions.list({ gameId: "game_1" });
await toffee.sessions.cancel({ id: "sess_123" });

Payments

const { payment } = await toffee.payments.get({ id: "pay_123" });
const { payments } = await toffee.payments.list({ gameId: "game_1" });
await toffee.payments.complete({ id: "pay_123" });
await toffee.payments.cancel({ id: "pay_123" });

Refunds

const { refund } = await toffee.refunds.create({ paymentId: "pay_123" });
const { refund } = await toffee.refunds.get({ id: "ref_123" });
const { refunds } = await toffee.refunds.list({ paymentId: "pay_123" });

Accounts

const { account } = await toffee.accounts.get({ id: "acc_123" });
const { accounts } = await toffee.accounts.list({ gameId: "game_1" });

Deposits

const { deposit } = await toffee.deposits.get({ id: "dep_123" });
const { deposits } = await toffee.deposits.list({ gameId: "game_1" });