Constconst outcome = await economy.submit(subscribe({
idempotencyKey: idempotencyKey('sub', 'usr_buyer', 'club_pass'),
actor: userActor('usr_buyer'),
userId: 'usr_buyer',
sellerId: 'usr_seller',
sku: 'club_pass',
price: toAmount('CREDIT', 50_000n), // 500 credits per period
periodMs: 2_592_000_000, // 30 days
}));
Builds a
subscribeoperation: charges the first period of a recurring plan, grants the buyer the SKU through the period just billed, and saves the subscription record, all in one transaction; the worker's renewal sweep bills every later period fromspendableonly. The first charge drawspromofirst, thenspendable, with the platform fee on the spendable part only — the same split as a spend. Rejects withALREADY_SUBSCRIBED(an active subscription already exists for the same buyer, SKU, and seller),INSUFFICIENT_FUNDS,FUNDS_IMMATURE,RISK_DENIED, orECONOMY_PAUSED. Auseractor may subscribe only their own wallet, and the buyer must differ from the seller. Thepricemust sit inside the configured per-period band. A retry under the sameidempotencyKeyreturns the first-period transaction asduplicate.