Install
Copy
npm install @toffeepay/sdk
Configuration
Copy
import { Toffee } from "@toffeepay/sdk";
const toffee = new Toffee({
accessToken: "your-access-token",
});
Sandbox
Copy
const toffee = new Toffee({
accessToken: "your-sandbox-token",
environment: "sandbox",
});
Checkout
Shorthand for creating a payment session:Copy
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
Copy
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
Copy
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
Copy
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
Copy
const account = await toffee.accounts.get("acc_123");
const list = await toffee.accounts.list({ gameId: "game_1" });
Deposits
Copy
const deposit = await toffee.deposits.get("dep_123");
const list = await toffee.deposits.list({ gameId: "game_1" });