@aghanim-sdk/checkout

中文文档
0.5.2发布于 2026/10/22MITTypeScriptESM + CJS零依赖近 30 天下载 4297

Aghanim Checkout JS SDK — accept payments through the Aghanim checkout without leaving your web game

原始使用文档
文档目录4 节
  1. Install
  2. Quick start
  3. Develop without a backend
  4. Reference

@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/checkout

Or 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, load_error, 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.

版本与发布记录

@aghanim-sdk/checkout 共发布 12 个版本,首次发布于 2026/08/13;过去 12 个月发布了 12 个版本。

版本发布日期距今
0.5.2latest2026/10/2217 天前
0.5.12026/10/1722 天前
0.4.32026/08/242 个月前
0.4.22026/08/242 个月前
0.4.12026/08/192 个月前
0.5.02026/08/192 个月前

关于 @aghanim-sdk/checkout 的常见问题

@aghanim-sdk/checkout 是什么?

Aghanim Checkout JS SDK — accept payments through the Aghanim checkout without leaving your web game

如何安装 @aghanim-sdk/checkout?

在项目目录运行 npm install @aghanim-sdk/checkout,或使用 pnpm add / yarn add / bun add。

@aghanim-sdk/checkout 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aghanim-sdk/checkout 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aghanim-sdk/checkout 可以商用吗?

@aghanim-sdk/checkout 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aghanim-sdk/checkout 的下载量有多少?

根据 npm 官方下载统计,@aghanim-sdk/checkout 在 2026/10/05 – 2026/11/03 这 30 天内被下载 4,297 次,日均约 143 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aghanim-sdk/checkout 还在维护吗?

最新版本 0.5.2 发布于 2026/10/22(17 天前);至今共发布 12 个版本,其中过去 12 个月发布了 12 个;首次发布于 2026/08/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。