@aghanim-sdk/checkout
v0.4.3
Published
Aghanim Checkout JS SDK — accept payments through the Aghanim checkout without leaving your web game
Readme
@aghanim-sdk/checkout
Accept payments in your web game through the Aghanim checkout — no page leave, no server-side runtime.
📖 Full guide: docs.aghanim.com/checkout/javascript-sdk
Install
npm install @aghanim-sdk/checkoutOr via script tag (exposes window.Aghanim):
<script src="https://cdn.jsdelivr.net/npm/@aghanim-sdk/checkout/dist/aghanim-checkout.global.js"></script>Quick start
import { Aghanim } from "@aghanim-sdk/checkout";
// Key from Dashboard → Integration → API keys.
const aghanim = Aghanim.init({ apiKey: "sdk_..." });
// As soon as your game knows who the player is;
// clearPlayerId() on sign-out.
aghanim.setPlayerId("player_1");
const order = await aghanim.orders.create({ items: [{ sku: "gems-100" }] });
const checkout = await aghanim.openCheckout(order);
checkout
.onPaid(() => showSuccessUI())
.onClosed(() => game.resume());Orders created by this SDK are consumable. paid is a UX signal only: grant items from the
item.add webhook, or drain the unconsumed list on boot, on resume, and after paid.
// Always grant first — consuming the same order twice fails.
for (const order of await aghanim.orders.unconsumedDetails()) {
grantToPlayer(order.items);
await aghanim.orders.consume(order.id);
}Already creating orders server-side? Pass the opaque checkout_url straight through:
const checkout = await aghanim.openCheckout(checkoutUrlFromYourBackend);Develop without a backend
const aghanim = Aghanim.init({
apiKey: "sdk_mock",
mock: { scenario: "instant_success" },
});Scenarios (instant_success, open_external, three_ds, failure, poll_fallback,
unconsumed) play scripted events through the real parsing pipeline. See examples/.
Reference
- Presentation modes (
overlay,embedded,external,auto), events, options, granting: docs.aghanim.com/checkout/javascript-sdk - Wire-level types only:
import type { OrderRead } from "@aghanim-sdk/checkout/protocol" - Evergreen browsers (ES2020), zero runtime dependencies.
