Skip to content

toffeepay/sdk-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@toffeepay/sdk

ToffeePay TypeScript SDK.

Install

npm install @toffeepay/sdk

Usage

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

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

// Checkout
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
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" },
);

Sandbox

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

Resources

Sessions

const res    = await toffee.sessions.create({ gameId: "game_1", userId: "user_1", item: { ... }, returnUrl: "https://example.com/return" });
const res    = await toffee.sessions.get({ id: "sess_123" });
const res    = await toffee.sessions.status({ id: "sess_123" });
const res    = await toffee.sessions.list({ gameId: "game_1" });
const res    = await toffee.sessions.cancel({ id: "sess_123" });

Payments

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

Refunds

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

Accounts

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

Deposits

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

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors