Skip to main content
This guide walks you through:
  1. Setting up
  2. Creating a payment session
  3. Opening the payment page
  4. Handling payment webhook
  5. Returning to game
  6. Confirming payment
For a visual overview of the complete payment flow, see the Payments page.

Setup

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

const toffee = new Toffee({
  accessToken: "your-access-token",
  environment: "sandbox", // omit for production
});

Create 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
See the Create Session API reference for the full request/response schema.

Open the Payment Page

Open the returned payment url in the browser. The user will:
  • View the list of items and total price
  • Pay using Apple Pay or another supported method

Handle Payment Webhook

Once payment is successful, ToffeePay sends a payment.succeeded webhook to your backend. This is the most reliable way to confirm payments. See the Webhooks page for signature verification and all available events.

Return to Game

After a successful payment, the player is redirected to your specified return_url. This is typically a custom deep link that your game handles to:
  • Show a success screen
  • Confirm the session was paid
Example:
"return_url": "mygame://payment-complete"
Make sure your mobile client is set up to handle and parse this URI scheme.

Confirming Payment

To confirm the payment status after returning to the game:
const status = await toffee.sessions.status("sess_123");

if (status.status === "paid") {
  // Grant items
}
See the Payments page for status handling details.