@arnaudjnn/billing-tools 0.71.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/adapters/workos-org.d.ts +1 -1
- package/dist/adapters/workos-org.js +1 -1
- package/dist/agent-auth/index.js +1 -1
- package/dist/allowance.d.ts +0 -3
- package/dist/allowance.d.ts.map +1 -1
- package/dist/allowance.js +16 -20
- package/dist/allowance.js.map +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +6 -6
- package/dist/auth.js.map +1 -1
- package/dist/billing.d.ts +6 -6
- package/dist/billing.d.ts.map +1 -1
- package/dist/billing.js +27 -27
- package/dist/billing.js.map +1 -1
- package/dist/cli/commands.js +13 -13
- package/dist/cli/commands.js.map +1 -1
- package/dist/create-billing.d.ts +3 -3
- package/dist/create-billing.d.ts.map +1 -1
- package/dist/doctor.js +20 -20
- package/dist/doctor.js.map +1 -1
- package/dist/i18n.js +4 -4
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/metering.d.ts +3 -3
- package/dist/metering.d.ts.map +1 -1
- package/dist/metering.js +3 -3
- package/dist/metering.js.map +1 -1
- package/dist/plan-model.d.ts +52 -23
- package/dist/plan-model.d.ts.map +1 -1
- package/dist/plan-model.js +34 -14
- package/dist/plan-model.js.map +1 -1
- package/dist/plans.d.ts +4 -4
- package/dist/plans.d.ts.map +1 -1
- package/dist/plans.js +8 -8
- package/dist/plans.js.map +1 -1
- package/dist/pricing.d.ts +3 -3
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +9 -9
- package/dist/pricing.js.map +1 -1
- package/dist/routes/webhook.js +4 -4
- package/dist/routes/webhook.js.map +1 -1
- package/dist/seats.js +1 -1
- package/dist/seats.js.map +1 -1
- package/dist/sync.js +11 -11
- package/dist/sync.js.map +1 -1
- package/dist/tools/billing.js +14 -14
- package/dist/tools/billing.js.map +1 -1
- package/dist/tools/management.js +11 -11
- package/dist/tools/management.js.map +1 -1
- package/dist/tools/register.d.ts +3 -3
- package/dist/tools/register.d.ts.map +1 -1
- package/dist/tools/register.js +8 -8
- package/dist/tools/register.js.map +1 -1
- package/dist/tools/subscription.js +1 -1
- package/dist/tools/subscription.js.map +1 -1
- package/dist/topup.d.ts +5 -10
- package/dist/topup.d.ts.map +1 -1
- package/dist/topup.js +5 -18
- package/dist/topup.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -2
- package/dist/types.js.map +1 -1
- package/dist/usage-ledger.d.ts +3 -3
- package/dist/usage-ledger.js +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
---
|
|
23
23
|
|
|
24
|
-
**Billing Tools** packages the "get money in" plumbing you'd otherwise rebuild in every SaaS: API-key auth on top of **WorkOS**,
|
|
24
|
+
**Billing Tools** packages the "get money in" plumbing you'd otherwise rebuild in every SaaS: API-key auth on top of **WorkOS**, credit + subscription billing on top of **Stripe**, and (because the next wave of customers is autonomous) first-class **agent** rails: [`auth.md`](https://workos.com/auth-md) self-registration and [`MPP`](https://mpp.dev/) machine payments. Wire it once; serve humans through a browser and agents through headless HTTP with the same engine. Storage is pluggable behind one small adapter (use the built-in WorkOS store, or mirror into your own Postgres).
|
|
25
25
|
|
|
26
26
|
## Table of contents
|
|
27
27
|
|
|
@@ -46,10 +46,10 @@ But you don't go to war naked. Ship a tool into the wild with no auth and no way
|
|
|
46
46
|
|
|
47
47
|
**Billing Tools is the armor.** Bring a Stripe + WorkOS stack and you inherit, out of the box, the exact monetization model the frontier labs run on. The same shape as **Anthropic, OpenAI, and xAI (Grok)**:
|
|
48
48
|
|
|
49
|
-
- 💰 **A price per
|
|
49
|
+
- 💰 **A price per credit:** every tool call costs credits, metered and deducted automatically.
|
|
50
50
|
- 🏢 **Workspaces:** the billable account, with one Stripe customer + balance each.
|
|
51
51
|
- 👥 **Users per workspace:** seats, invitations, and roles.
|
|
52
|
-
- 🪙 **
|
|
52
|
+
- 🪙 **Credits per user:** per-seat grants, seat limits, and auto-reload.
|
|
53
53
|
|
|
54
54
|
So you do the one thing only you can do (**build great tools**) and monetize them the same afternoon. The get-paid layer is already handled, battle-tested, and agent-ready. 🛡️
|
|
55
55
|
|
|
@@ -63,10 +63,10 @@ So you do the one thing only you can do (**build great tools**) and monetize the
|
|
|
63
63
|
- 🎫 **Optional OAuth-JWT hook:** bring your own MCP OAuth proxy via a single adapter method.
|
|
64
64
|
|
|
65
65
|
### 💳 Billing & payments
|
|
66
|
-
- 🪙 **Usage-metered
|
|
66
|
+
- 🪙 **Usage-metered credit wallet:** held in the native Stripe customer credit balance (1 credit = 1¢), with idempotent credit/debit.
|
|
67
67
|
- 🛒 **Checkout top-ups:** Stripe Checkout that auto-offers cards **+ Apple Pay / Google Pay / Link**.
|
|
68
68
|
- 📦 **Declarative subscription plans:** describe plans in code; products/prices are **auto-provisioned in Stripe** via `lookup_key` (immutable-price safe, orphan-cleaning). Zero dashboard clicks.
|
|
69
|
-
- 🎟️ **Per-seat / per-cycle
|
|
69
|
+
- 🎟️ **Per-seat / per-cycle credit grants + seat limits:** included credits scale with active members.
|
|
70
70
|
- 🔁 **Auto-reload:** off-session saved-card recharge when the balance drops below a threshold.
|
|
71
71
|
- 🧾 **Invoices + 🏛️ Customer Portal:** list invoices, and a one-call Stripe Billing Portal URL for self-serve upgrade/downgrade/cancel + card updates.
|
|
72
72
|
- 🔒 **Idempotency on every money move:** welcome bonus, checkout credit, and per-cycle grants each carry a stable key, so retries/replays never double-charge.
|
|
@@ -74,7 +74,7 @@ So you do the one thing only you can do (**build great tools**) and monetize the
|
|
|
74
74
|
### 🤖 Built for AI agents
|
|
75
75
|
- 📄 **auth.md:** the [agent onboarding standard](https://workos.com/auth-md), served for you (`/auth.md` narrative + discovery metadata).
|
|
76
76
|
- 🏧 **MPP machine payments:** Stripe's [Machine Payments Protocol](https://mpp.dev/): a HTTP **402 + `WWW-Authenticate: Payment`** challenge for pay-per-request (SPT card or crypto/USDC), the payment sibling of auth.md's 401.
|
|
77
|
-
- 🧰 **MCP server tools:** `get_api_key`, `
|
|
77
|
+
- 🧰 **MCP server tools:** `get_api_key`, `get_credit_balance`, `buy_credits`, `list_plans`, `get_billing_portal`, and more, drop straight into Claude, Cursor, or any MCP client.
|
|
78
78
|
- 🧭 **Discovery hints:** every 401/402 advertises `resource_metadata`, so an agent can bootstrap unattended.
|
|
79
79
|
|
|
80
80
|
### 🧩 Three surfaces, one engine
|
|
@@ -160,7 +160,7 @@ Prefer fine-grained control? Every factory is exported individually (`registerBi
|
|
|
160
160
|
curl https://your-app.com/api/v0
|
|
161
161
|
|
|
162
162
|
# Use a key (Bearer sk_…)
|
|
163
|
-
curl -X POST https://your-app.com/api/v0/
|
|
163
|
+
curl -X POST https://your-app.com/api/v0/get_credit_balance \
|
|
164
164
|
-H "Authorization: Bearer sk_…"
|
|
165
165
|
```
|
|
166
166
|
|
|
@@ -265,7 +265,7 @@ registerBillingCommands(program, { configDir: "~/.acme", envPrefix: "ACME", defa
|
|
|
265
265
|
|---|---|---|
|
|
266
266
|
| `baseUrl` | required | Checkout success/cancel + portal return URLs |
|
|
267
267
|
| `currency` | `"usd"` | Stripe currency |
|
|
268
|
-
| `
|
|
268
|
+
| `freeCredits` | `100` | Welcome credit on first customer creation |
|
|
269
269
|
| `internalDomains` | `[]` | Orgs with these **verified** WorkOS domains are unmetered (see `internalDomainsFromEnv`) |
|
|
270
270
|
|
|
271
271
|
## Roadmap
|
|
@@ -66,7 +66,7 @@ export declare class WorkOSOrgAdapter implements BillingAdapter {
|
|
|
66
66
|
id: string;
|
|
67
67
|
name: string;
|
|
68
68
|
} | null>;
|
|
69
|
-
/** Active-member count for the org (per-seat
|
|
69
|
+
/** Active-member count for the org (per-seat credit grants + seat limits).
|
|
70
70
|
* Auto-paginates so orgs with >100 members aren't undercounted. */
|
|
71
71
|
memberCount(orgId: string): Promise<number>;
|
|
72
72
|
getSubscription(orgId: string): Promise<{
|
|
@@ -186,7 +186,7 @@ export class WorkOSOrgAdapter {
|
|
|
186
186
|
return { id: target.id, name: target.name };
|
|
187
187
|
}
|
|
188
188
|
// ── Subscription state + seats (org metadata; used by the billing-sync) ────
|
|
189
|
-
/** Active-member count for the org (per-seat
|
|
189
|
+
/** Active-member count for the org (per-seat credit grants + seat limits).
|
|
190
190
|
* Auto-paginates so orgs with >100 members aren't undercounted. */
|
|
191
191
|
async memberCount(orgId) {
|
|
192
192
|
const paginatable = await this.workos.userManagement.listOrganizationMemberships({
|
package/dist/agent-auth/index.js
CHANGED
|
@@ -357,7 +357,7 @@ Returns \`{ "error": "authorization_pending" }\` until the code is entered, then
|
|
|
357
357
|
: ""}
|
|
358
358
|
## Use the access token
|
|
359
359
|
|
|
360
|
-
All MCP (\`${baseUrl}${p.mcp}\`) and REST (\`${baseUrl}${p.rest}/{tool_name}\`) endpoints accept the same key. Free tools work immediately; paid tools require a
|
|
360
|
+
All MCP (\`${baseUrl}${p.mcp}\`) and REST (\`${baseUrl}${p.rest}/{tool_name}\`) endpoints accept the same key. Free tools work immediately; paid tools require a credit balance.
|
|
361
361
|
|
|
362
362
|
## Revocation
|
|
363
363
|
|
package/dist/allowance.d.ts
CHANGED
|
@@ -87,9 +87,6 @@ export declare function currentCycle(adapter: BillingAdapter, input: {
|
|
|
87
87
|
plan?: string | null;
|
|
88
88
|
now?: number;
|
|
89
89
|
}): Promise<CycleWindow>;
|
|
90
|
-
/** The calendar-month key this library used before the window came from the
|
|
91
|
-
* subscription. Read-only fallback, so grants filed under it still apply. */
|
|
92
|
-
export declare function legacyCycleKey(now?: number): string;
|
|
93
90
|
export declare function resolveAllowance(adapter: BillingAdapter, config: ResolvedConfig, input: AllowanceInput): Promise<AllowanceState>;
|
|
94
91
|
export type DenialReason = "rate_limit_reached" | "pool_exhausted" | "seat_allowance_reached" | "insufficient_balance";
|
|
95
92
|
export interface FundingDecision {
|
package/dist/allowance.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowance.d.ts","sourceRoot":"","sources":["../src/allowance.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"allowance.d.ts","sourceRoot":"","sources":["../src/allowance.ts"],"names":[],"mappings":"AAEA,OAAO,EASL,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,WAAW,EAChB,KAAK,SAAS,EACf,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAA4B,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAWnG,0EAA0E;AAC1E,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC;IACxB,2DAA2D;IAC3D,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,+EAA+E;IAC/E,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,WAAW,CAAC;IACnB;;;;OAIG;IACH,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,2DAA2D;IAC3D,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC/D,kFAAkF;IAClF,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAC;QACjB,IAA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AwB,GACxB,sBAAsB,CAAC;AAE3B,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAC7B,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,oEAAoE;IACpE,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,SAAS,GAAG,IAAI,EACvB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE;IAAE,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD,eAAe,CAoCjB;AAYD,uDAAuD;AACvD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,cAAc,EACrB,KAAK,CAAC,EAAE,UAAU,GACjB,MAAM,CAeR"}
|
package/dist/allowance.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getBillingCustomerId,
|
|
2
|
-
import { cycleWindowFor, exhaustedPolicy, packSizeOf, planModel, poolSizeOf, rateLimitsOf, rateWindowFor, } from "./plan-model.js";
|
|
1
|
+
import { getBillingCustomerId, getCreditBalance } from "./billing.js";
|
|
2
|
+
import { capCovers, cycleWindowFor, exhaustedPolicy, packSizeOf, planModel, poolSizeOf, rateLimitsOf, rateWindowFor, } from "./plan-model.js";
|
|
3
3
|
import { extraAllowance } from "./topup.js";
|
|
4
4
|
import { stripeBalanceUsageLedger } from "./usage-ledger.js";
|
|
5
5
|
/**
|
|
@@ -27,12 +27,6 @@ export async function currentCycle(adapter, input) {
|
|
|
27
27
|
const now = input.now ?? Date.now();
|
|
28
28
|
return cycleWindowFor(model, await subscriptionPeriod(adapter, input.orgId, model), now);
|
|
29
29
|
}
|
|
30
|
-
/** The calendar-month key this library used before the window came from the
|
|
31
|
-
* subscription. Read-only fallback, so grants filed under it still apply. */
|
|
32
|
-
export function legacyCycleKey(now = Date.now()) {
|
|
33
|
-
const d = new Date(now);
|
|
34
|
-
return `${d.getUTCFullYear()}-${String(d.getUTCMonth() + 1).padStart(2, "0")}`;
|
|
35
|
-
}
|
|
36
30
|
export async function resolveAllowance(adapter, config, input) {
|
|
37
31
|
const model = planModel(input.plans, input.plan ?? null);
|
|
38
32
|
const now = input.now ?? Date.now();
|
|
@@ -68,14 +62,14 @@ export async function resolveAllowance(adapter, config, input) {
|
|
|
68
62
|
every: limit.every,
|
|
69
63
|
scope,
|
|
70
64
|
label: limit.label ?? null,
|
|
71
|
-
size: limit.
|
|
65
|
+
size: limit.credits,
|
|
72
66
|
used,
|
|
73
|
-
remaining: Math.max(0, limit.
|
|
67
|
+
remaining: Math.max(0, limit.credits - used),
|
|
74
68
|
window,
|
|
75
69
|
}));
|
|
76
70
|
});
|
|
77
71
|
const [wallet, poolUsed, packUsed, extra, limits] = await Promise.all([
|
|
78
|
-
input.skipWallet ? Promise.resolve(0) :
|
|
72
|
+
input.skipWallet ? Promise.resolve(0) : getCreditBalance(customerId, config.currency),
|
|
79
73
|
poolSize == null
|
|
80
74
|
? Promise.resolve(0)
|
|
81
75
|
: ledger.total({ orgId: input.orgId, customerId, start: cycle.start, end: cycle.end ?? undefined }),
|
|
@@ -94,12 +88,10 @@ export async function resolveAllowance(adapter, config, input) {
|
|
|
94
88
|
}),
|
|
95
89
|
// Top-up grants raise a member's pack for the cycle, keyed by the cycle
|
|
96
90
|
// identity `currentCycle` produces — the same one the approving tool writes,
|
|
97
|
-
// which is
|
|
98
|
-
// calendar key is read as a fallback so grants approved before the two
|
|
99
|
-
// agreed still apply instead of vanishing.
|
|
91
|
+
// which is guaranteed by both going through that function.
|
|
100
92
|
packSize == null || input.caller?.kind !== "user" || !input.caller.id
|
|
101
93
|
? Promise.resolve(0)
|
|
102
|
-
: extraAllowance(adapter, input.orgId, input.caller.id, cycle.key
|
|
94
|
+
: extraAllowance(adapter, input.orgId, input.caller.id, cycle.key),
|
|
103
95
|
Promise.all(limitReads),
|
|
104
96
|
]);
|
|
105
97
|
return {
|
|
@@ -171,14 +163,18 @@ export function fundingFor(state, model, cost, caller) {
|
|
|
171
163
|
return { ok: false, source: null, reason: "rate_limit_reached", limit };
|
|
172
164
|
}
|
|
173
165
|
}
|
|
174
|
-
|
|
166
|
+
// A window the caller is not covered by is not theirs to spend — it is skipped
|
|
167
|
+
// entirely rather than treated as exhausted, so no `onExhausted: "block"` can
|
|
168
|
+
// refuse a machine caller over an allowance that was never included for it.
|
|
169
|
+
const covered = capCovers(model, caller);
|
|
170
|
+
if (covered && state.pool) {
|
|
175
171
|
if (state.pool.remaining >= cost)
|
|
176
172
|
return { ok: true, source: "pool" };
|
|
177
173
|
if (exhaustedPolicy(model, caller) === "block") {
|
|
178
174
|
return { ok: false, source: null, reason: "pool_exhausted" };
|
|
179
175
|
}
|
|
180
176
|
}
|
|
181
|
-
if (state.pack) {
|
|
177
|
+
if (covered && state.pack) {
|
|
182
178
|
if (state.pack.remaining >= cost)
|
|
183
179
|
return { ok: true, source: "pack" };
|
|
184
180
|
if (exhaustedPolicy(model, caller) === "block") {
|
|
@@ -208,11 +204,11 @@ export function describeDenial(reason, state, limit) {
|
|
|
208
204
|
return `Usage limit reached for this ${name} (${l?.size ?? 0}).${resets}`;
|
|
209
205
|
}
|
|
210
206
|
case "pool_exhausted":
|
|
211
|
-
return `Plan allowance used up for this cycle (${state.pool?.size ?? 0}
|
|
207
|
+
return `Plan allowance used up for this cycle (${state.pool?.size ?? 0} credits). Contact us to extend the package.`;
|
|
212
208
|
case "seat_allowance_reached":
|
|
213
|
-
return "Seat
|
|
209
|
+
return "Seat credit allowance reached for this cycle. Ask an owner for a top-up, or buy credits.";
|
|
214
210
|
case "insufficient_balance":
|
|
215
|
-
return `Insufficient
|
|
211
|
+
return `Insufficient credits (balance ${state.wallet}). Buy credits to continue.`;
|
|
216
212
|
}
|
|
217
213
|
}
|
|
218
214
|
//# sourceMappingURL=allowance.js.map
|
package/dist/allowance.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allowance.js","sourceRoot":"","sources":["../src/allowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"allowance.js","sourceRoot":"","sources":["../src/allowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EACL,SAAS,EACT,cAAc,EACd,eAAe,EACf,UAAU,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,aAAa,GAKd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,wBAAwB,EAAwC,MAAM,mBAAmB,CAAC;AAkEnG;;;;;;;;GAQG;AACH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAAuB,EACvB,KAAiF;IAEjF,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,EAAE,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IACpC,OAAO,cAAc,CAAC,KAAK,EAAE,MAAM,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;AAC3F,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAuB,EACvB,MAAsB,EACtB,KAAqB;IAErB,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;IACzD,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,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,EAAE,CAAC;QAC5E,CAAC;QACD,KAAK,gBAAgB;YACnB,OAAO,0CAA0C,KAAK,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,8CAA8C,CAAC;QACvH,KAAK,wBAAwB;YAC3B,OAAO,0FAA0F,CAAC;QACpG,KAAK,sBAAsB;YACzB,OAAO,iCAAiC,KAAK,CAAC,MAAM,6BAA6B,CAAC;IACtF,CAAC;AACH,CAAC"}
|
package/dist/auth.d.ts
CHANGED
|
@@ -60,6 +60,6 @@ export declare function enforceAdmin(adapter: BillingAdapter, action: string): P
|
|
|
60
60
|
principal: Principal | null;
|
|
61
61
|
} | ToolErrorResult>;
|
|
62
62
|
export declare function isInternalOrg(adapter: BillingAdapter, orgId: string, internalDomains: string[]): Promise<boolean>;
|
|
63
|
-
export declare function
|
|
63
|
+
export declare function enforceCredits(adapter: BillingAdapter, config: ResolvedConfig, orgId: string, toolName: string, cost: number): Promise<ToolErrorResult | null>;
|
|
64
64
|
export {};
|
|
65
65
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AASlF;;;;;;;;;GASG;AACH,MAAM,WAAW,SAAS;IACxB,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,SAAS;IACjB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAG1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,WAAW,8BAAqC,CAAC;AAE9D,wBAAgB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E,UAAU,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAA;CAAE,GAAG,eAAe,CAAC,CAsB7F;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,EACb,eAAe,EAAE,MAAM,EAAE,GACxB,OAAO,CAAC,OAAO,CAAC,CAKlB;AAKD,wBAAsB,cAAc,CAClC,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,cAAc,EACtB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CA2BjC"}
|
package/dist/auth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import { getBillingCustomerId,
|
|
2
|
+
import { getBillingCustomerId, getCreditBalance, deductCredits, autoReloadFor, stripeConfigured, } from "./billing.js";
|
|
3
3
|
export const authContext = new AsyncLocalStorage();
|
|
4
4
|
export function runWithAuth(header, fn) {
|
|
5
5
|
return authContext.run({ authHeader: header }, fn);
|
|
@@ -96,9 +96,9 @@ export async function isInternalOrg(adapter, orgId, internalDomains) {
|
|
|
96
96
|
return domains.some((d) => set.has(d.toLowerCase()));
|
|
97
97
|
}
|
|
98
98
|
// Metering gate for paid tools. Free (cost 0), Stripe-unset, and internal orgs
|
|
99
|
-
// are skipped. Otherwise deduct from the org's
|
|
99
|
+
// are skipped. Otherwise deduct from the org's credit balance and fire
|
|
100
100
|
// auto-reload in the background.
|
|
101
|
-
export async function
|
|
101
|
+
export async function enforceCredits(adapter, config, orgId, toolName, cost) {
|
|
102
102
|
if (!cost)
|
|
103
103
|
return null;
|
|
104
104
|
if (!stripeConfigured())
|
|
@@ -112,19 +112,19 @@ export async function enforceTokens(adapter, config, orgId, toolName, cost) {
|
|
|
112
112
|
content: [{ type: "text", text: "No billing account found. Please contact support." }],
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
-
const balance = await
|
|
115
|
+
const balance = await getCreditBalance(customerId, config.currency);
|
|
116
116
|
if (balance < cost) {
|
|
117
117
|
return {
|
|
118
118
|
isError: true,
|
|
119
119
|
content: [
|
|
120
120
|
{
|
|
121
121
|
type: "text",
|
|
122
|
-
text: `Insufficient
|
|
122
|
+
text: `Insufficient credits. This tool costs ${cost} credits but you only have ${balance}. Use buy_credits to purchase more.`,
|
|
123
123
|
},
|
|
124
124
|
],
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
|
-
await
|
|
127
|
+
await deductCredits(customerId, toolName, cost, config.currency);
|
|
128
128
|
autoReloadFor(customerId, config).catch(() => { });
|
|
129
129
|
return null;
|
|
130
130
|
}
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EACL,oBAAoB,EACpB,
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,cAAc,CAAC;AA2BtB,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,iBAAiB,EAAa,CAAC;AAE9D,MAAM,UAAU,WAAW,CAAI,MAAqB,EAAE,EAAW;IAC/D,OAAO,WAAW,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,kBAAkB,CAAI,MAAqB,EAAE,KAAa,EAAE,EAAW;IACrF,OAAO,WAA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AE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACpE,IAAI,OAAO,GAAG,IAAI,EAAE,CAAC;QACnB,OAAO;YACL,OAAO,EAAE,IAAI;YACb,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,yCAAyC,IAAI,8BAA8B,OAAO,qCAAqC;iBAC9H;aACF;SACF,CAAC;IACJ,CAAC;IACD,MAAM,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACjE,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAClD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/billing.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ export declare function getOrgSubscription(adapter: BillingAdapter, orgId: strin
|
|
|
50
50
|
}>;
|
|
51
51
|
export declare function ensureStripeCustomer(adapter: BillingAdapter, orgId: string, email: string | undefined, config: ResolvedConfig): Promise<string>;
|
|
52
52
|
/**
|
|
53
|
-
* The customer's
|
|
53
|
+
* The customer's credit balance, in `currency`.
|
|
54
54
|
*
|
|
55
55
|
* `customer.balance` is a SINGLE scalar, denominated in `customer.currency` —
|
|
56
56
|
* whichever currency first touched the customer, pinned there for good. Stripe
|
|
@@ -67,8 +67,8 @@ export declare function ensureStripeCustomer(adapter: BillingAdapter, orgId: str
|
|
|
67
67
|
* Without `currency`, or when it matches the customer's own, the scalar is
|
|
68
68
|
* correct and is used directly — one API call, as before.
|
|
69
69
|
*/
|
|
70
|
-
export declare function
|
|
71
|
-
export declare function
|
|
70
|
+
export declare function getCreditBalance(stripeCustomerId: string, currency?: string): Promise<number>;
|
|
71
|
+
export declare function deductCredits(stripeCustomerId: string, toolName: string, cost: number, currency: string,
|
|
72
72
|
/** Who ran it — written as balance-transaction metadata so per-seat / per-
|
|
73
73
|
* caller cycle usage can be summed with `usageSince` (no separate ledger). */
|
|
74
74
|
caller?: {
|
|
@@ -79,7 +79,7 @@ export declare function usageSince(stripeCustomerId: string, since: number, filt
|
|
|
79
79
|
callerKind?: string;
|
|
80
80
|
callerId?: string;
|
|
81
81
|
}): Promise<number>;
|
|
82
|
-
export declare function
|
|
82
|
+
export declare function grantCredits(stripeCustomerId: string, amount: number, description: string, currency: string,
|
|
83
83
|
/** Pass a stable key (e.g. the source invoice/session id) so replayed events
|
|
84
84
|
* — a re-delivered webhook, an overlapping poll — credit exactly once. */
|
|
85
85
|
idempotencyKey?: string): Promise<void>;
|
|
@@ -98,12 +98,12 @@ export interface TopUpCheckoutOptions {
|
|
|
98
98
|
taxRates?: string[];
|
|
99
99
|
/** Use Stripe Tax instead. Ignored when `taxRates` is given — Stripe rejects both. */
|
|
100
100
|
automaticTax?: boolean;
|
|
101
|
-
/** Defaults to `${baseUrl}/billing/success?
|
|
101
|
+
/** Defaults to `${baseUrl}/billing/success?credits=…`. */
|
|
102
102
|
successUrl?: string;
|
|
103
103
|
/** Defaults to `${baseUrl}/billing/cancel`. */
|
|
104
104
|
cancelUrl?: string;
|
|
105
105
|
}
|
|
106
|
-
export declare function
|
|
106
|
+
export declare function createCreditCheckoutSession(stripeCustomerId: string, orgId: string, amountMajor: number, config: ResolvedConfig, opts?: TopUpCheckoutOptions): Promise<string>;
|
|
107
107
|
/** A Stripe Billing Portal session URL — the no-code self-serve surface where a
|
|
108
108
|
* customer manages their subscription (upgrade/downgrade/cancel), updates the
|
|
109
109
|
* payment method (fixes a failing card), and views invoices. */
|
package/dist/billing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../src/billing.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAUhF,wBAAgB,SAAS,IAAI,MAAM,CA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AAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGxB;AAOD,iFAAiF;AACjF,wBAAsB,eAAe,CACnC,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,EACb,KAAK,SAAK,GACT,OAAO,CAAC,YAAY,EAAE,CAAC,CAIzB;AAED,+EAA+E;AAC/E,wBAAsB,aAAa,CACjC,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAI9B;AAED,qEAAqE;AACrE,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGxB"}
|
package/dist/billing.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Stripe from "stripe";
|
|
2
2
|
import { defaultPaymentMethodConfig } from "./payment-method-config.js";
|
|
3
|
-
//
|
|
3
|
+
// Credit model: 1 credit = 1 cent. Held in the Stripe customer credit balance,
|
|
4
4
|
// where a negative balance = available credit. All functions keyed on a
|
|
5
5
|
// stripeCustomerId are pure Stripe math (identical across host apps); the
|
|
6
6
|
// customer-id pointer itself is stored by the host via the adapter.
|
|
@@ -117,20 +117,20 @@ export async function ensureStripeCustomer(adapter, orgId, email, config) {
|
|
|
117
117
|
? { preferred_locales: [config.defaultLocale] }
|
|
118
118
|
: {}),
|
|
119
119
|
});
|
|
120
|
-
if (config.
|
|
120
|
+
if (config.freeCredits > 0) {
|
|
121
121
|
// Idempotency key so a race on first-use (two concurrent callers) can't
|
|
122
122
|
// grant the welcome bonus twice for the same org.
|
|
123
123
|
await stripe.customers.createBalanceTransaction(customer.id, {
|
|
124
|
-
amount: -config.
|
|
124
|
+
amount: -config.freeCredits,
|
|
125
125
|
currency: config.currency,
|
|
126
|
-
description: `Welcome bonus: ${config.
|
|
126
|
+
description: `Welcome bonus: ${config.freeCredits} free credits`,
|
|
127
127
|
}, { idempotencyKey: `welcome:${orgId}` });
|
|
128
128
|
}
|
|
129
129
|
await adapter.setBillingCustomerId(orgId, customer.id);
|
|
130
130
|
return customer.id;
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
|
-
* The customer's
|
|
133
|
+
* The customer's credit balance, in `currency`.
|
|
134
134
|
*
|
|
135
135
|
* `customer.balance` is a SINGLE scalar, denominated in `customer.currency` —
|
|
136
136
|
* whichever currency first touched the customer, pinned there for good. Stripe
|
|
@@ -147,7 +147,7 @@ export async function ensureStripeCustomer(adapter, orgId, email, config) {
|
|
|
147
147
|
* Without `currency`, or when it matches the customer's own, the scalar is
|
|
148
148
|
* correct and is used directly — one API call, as before.
|
|
149
149
|
*/
|
|
150
|
-
export async function
|
|
150
|
+
export async function getCreditBalance(stripeCustomerId, currency) {
|
|
151
151
|
const stripe = getStripe();
|
|
152
152
|
const customer = await stripe.customers.retrieve(stripeCustomerId);
|
|
153
153
|
if (customer.deleted)
|
|
@@ -176,14 +176,14 @@ export async function getTokenBalance(stripeCustomerId, currency) {
|
|
|
176
176
|
}
|
|
177
177
|
return 0;
|
|
178
178
|
}
|
|
179
|
-
export async function
|
|
179
|
+
export async function deductCredits(stripeCustomerId, toolName, cost, currency,
|
|
180
180
|
/** Who ran it — written as balance-transaction metadata so per-seat / per-
|
|
181
181
|
* caller cycle usage can be summed with `usageSince` (no separate ledger). */
|
|
182
182
|
caller) {
|
|
183
183
|
await getStripe().customers.createBalanceTransaction(stripeCustomerId, {
|
|
184
184
|
amount: cost, // positive = debit
|
|
185
185
|
currency,
|
|
186
|
-
description: `Tool call: ${toolName} (${cost}
|
|
186
|
+
description: `Tool call: ${toolName} (${cost} credits)`,
|
|
187
187
|
metadata: {
|
|
188
188
|
action: toolName,
|
|
189
189
|
...(caller?.kind ? { caller_kind: caller.kind } : {}),
|
|
@@ -191,7 +191,7 @@ caller) {
|
|
|
191
191
|
},
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
|
-
// Sum debited
|
|
194
|
+
// Sum debited credits on a customer since `since` (unix seconds — the cycle
|
|
195
195
|
// start), optionally filtered to a caller via balance-transaction metadata.
|
|
196
196
|
// This is the Stripe-native usage ledger: debits are positive amounts, credits
|
|
197
197
|
// (grants / top-ups) are negative and excluded. The list is newest-first, so we
|
|
@@ -217,7 +217,7 @@ export async function usageSince(stripeCustomerId, since, filter) {
|
|
|
217
217
|
}
|
|
218
218
|
return total;
|
|
219
219
|
}
|
|
220
|
-
export async function
|
|
220
|
+
export async function grantCredits(stripeCustomerId, amount, description, currency,
|
|
221
221
|
/** Pass a stable key (e.g. the source invoice/session id) so replayed events
|
|
222
222
|
* — a re-delivered webhook, an overlapping poll — credit exactly once. */
|
|
223
223
|
idempotencyKey) {
|
|
@@ -227,9 +227,9 @@ idempotencyKey) {
|
|
|
227
227
|
description,
|
|
228
228
|
}, idempotencyKey ? { idempotencyKey } : undefined);
|
|
229
229
|
}
|
|
230
|
-
export async function
|
|
230
|
+
export async function createCreditCheckoutSession(stripeCustomerId, orgId, amountMajor, config, opts = {}) {
|
|
231
231
|
const amountMinor = Math.round(amountMajor * 100);
|
|
232
|
-
const
|
|
232
|
+
const credits = amountMinor; // 1 credit = 1 minor unit
|
|
233
233
|
const taxRates = opts.taxRates?.length ? opts.taxRates : null;
|
|
234
234
|
// Every method the account has enabled, plus the wallets, minus Link — the same
|
|
235
235
|
// default the subscription checkout and the add-card form get. Undefined when a
|
|
@@ -247,8 +247,8 @@ export async function createTokenCheckoutSession(stripeCustomerId, orgId, amount
|
|
|
247
247
|
price_data: {
|
|
248
248
|
currency: config.currency,
|
|
249
249
|
product_data: {
|
|
250
|
-
name: `${
|
|
251
|
-
description: `${amountMajor} = ${
|
|
250
|
+
name: `${credits} credits`,
|
|
251
|
+
description: `${amountMajor} = ${credits} credits`,
|
|
252
252
|
},
|
|
253
253
|
unit_amount: amountMinor,
|
|
254
254
|
},
|
|
@@ -262,10 +262,10 @@ export async function createTokenCheckoutSession(stripeCustomerId, orgId, amount
|
|
|
262
262
|
invoice_creation: { enabled: true },
|
|
263
263
|
payment_intent_data: {
|
|
264
264
|
setup_future_usage: "off_session",
|
|
265
|
-
metadata: { org_id: orgId,
|
|
265
|
+
metadata: { org_id: orgId, credits: String(credits) },
|
|
266
266
|
},
|
|
267
|
-
metadata: { org_id: orgId,
|
|
268
|
-
success_url: opts.successUrl ?? `${config.baseUrl}/billing/success?
|
|
267
|
+
metadata: { org_id: orgId, credits: String(credits) },
|
|
268
|
+
success_url: opts.successUrl ?? `${config.baseUrl}/billing/success?credits=${credits}`,
|
|
269
269
|
cancel_url: opts.cancelUrl ?? `${config.baseUrl}/billing/cancel`,
|
|
270
270
|
});
|
|
271
271
|
return session.url;
|
|
@@ -334,11 +334,11 @@ export async function tryAutoReload(stripeCustomerId, currency, opts = {}) {
|
|
|
334
334
|
const settings = await getAutoReloadSettings(stripeCustomerId);
|
|
335
335
|
if (!settings || !settings.enabled)
|
|
336
336
|
return;
|
|
337
|
-
const balance = await
|
|
337
|
+
const balance = await getCreditBalance(stripeCustomerId, currency);
|
|
338
338
|
if (balance > settings.threshold)
|
|
339
339
|
return;
|
|
340
|
-
const
|
|
341
|
-
if (
|
|
340
|
+
const creditsNeeded = settings.reload_to - balance;
|
|
341
|
+
if (creditsNeeded <= 0)
|
|
342
342
|
return;
|
|
343
343
|
const stripe = getStripe();
|
|
344
344
|
const pms = await stripe.paymentMethods.list({
|
|
@@ -349,7 +349,7 @@ export async function tryAutoReload(stripeCustomerId, currency, opts = {}) {
|
|
|
349
349
|
if (pms.data.length === 0)
|
|
350
350
|
return;
|
|
351
351
|
// Stable across concurrent triggers: same customer, same target, same hour.
|
|
352
|
-
// Not the exact balance — two racing callers can read balances a
|
|
352
|
+
// Not the exact balance — two racing callers can read balances a credit apart
|
|
353
353
|
// and would then key differently, which is precisely the double charge.
|
|
354
354
|
const slot = new Date().toISOString().slice(0, 13);
|
|
355
355
|
const key = `autoreload:${stripeCustomerId}:${settings.reload_to}:${slot}`;
|
|
@@ -358,8 +358,8 @@ export async function tryAutoReload(stripeCustomerId, currency, opts = {}) {
|
|
|
358
358
|
await stripe.invoiceItems.create({
|
|
359
359
|
customer: stripeCustomerId,
|
|
360
360
|
currency,
|
|
361
|
-
amount:
|
|
362
|
-
description: `Auto-reload: ${
|
|
361
|
+
amount: creditsNeeded,
|
|
362
|
+
description: `Auto-reload: ${creditsNeeded} credits`,
|
|
363
363
|
...(taxRates ? { tax_rates: taxRates } : {}),
|
|
364
364
|
}, { idempotencyKey: `${key}:item` });
|
|
365
365
|
const invoice = await stripe.invoices.create({
|
|
@@ -371,12 +371,12 @@ export async function tryAutoReload(stripeCustomerId, currency, opts = {}) {
|
|
|
371
371
|
// Explicit, and load-bearing: for a customer who HAS a subscription,
|
|
372
372
|
// Stripe otherwise leaves the pending item off this invoice and sweeps
|
|
373
373
|
// it onto the next subscription invoice instead. Measured — the reload
|
|
374
|
-
// invoice came back paid, numbered, and totalling zero, while the
|
|
374
|
+
// invoice came back paid, numbered, and totalling zero, while the credits
|
|
375
375
|
// appeared on the renewal a month later.
|
|
376
376
|
pending_invoice_items_behavior: "include",
|
|
377
|
-
description: `Auto-reload: ${
|
|
377
|
+
description: `Auto-reload: ${creditsNeeded} credits`,
|
|
378
378
|
...(!taxRates && opts.automaticTax ? { automatic_tax: { enabled: true } } : {}),
|
|
379
|
-
metadata: { auto_reload: "true",
|
|
379
|
+
metadata: { auto_reload: "true", credits: String(creditsNeeded) },
|
|
380
380
|
}, { idempotencyKey: `${key}:invoice` });
|
|
381
381
|
if (!invoice.id)
|
|
382
382
|
return;
|
|
@@ -384,7 +384,7 @@ export async function tryAutoReload(stripeCustomerId, currency, opts = {}) {
|
|
|
384
384
|
if (paid.status === "paid") {
|
|
385
385
|
// Same key: a retry that finds the invoice already paid must not credit
|
|
386
386
|
// a second time.
|
|
387
|
-
await
|
|
387
|
+
await grantCredits(stripeCustomerId, creditsNeeded, `Auto-reload: ${creditsNeeded} credits`, currency, `credit:${key}`);
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
catch {
|