Skip to main content

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({
  gameId: "space_shooter",
  userId: "player_42",
  item: { title: "50 Gold Coins", price: 499, currency: "USD" },
  returnUrl: "mygame://payment-complete",
});

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

Resources

Sessions

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

Payments

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

Refunds

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

Accounts

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

Deposits

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