Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/pay-webhook-livemode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@agentaos/pay": minor
---

Add `livemode` to webhook payloads and type the subscription webhook events.

- Every `WebhookEvent` `data` now carries `livemode: boolean` (`true` = live mode, `false` = test mode) — the account-mode signal. This replaces the previous chain-specific `testnet` field, which was meaningless for card/bank rails; use `network` for the chain/rail.
- New `SubscriptionData` type and five `subscription.*` events on the `WebhookEvent` union: `subscription.created`, `subscription.renewed`, `subscription.payment_failed`, `subscription.updated`, `subscription.canceled`.
1 change: 1 addition & 0 deletions packages/pay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type {
CheckoutCompletedData,
SendCompletedData,
SendFailedData,
SubscriptionData,
PaginatedList,
ListParams,
} from './types.js';
Expand Down
30 changes: 29 additions & 1 deletion packages/pay/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ export interface CheckoutCompletedData {
payer: string;
payerType: 'human' | 'agent';
network: string;
/** `true` = live mode, `false` = test mode. Account mode, not the chain — see `network` for the chain/rail. */
livemode: boolean;
metadata: Record<string, unknown>;
}

Expand All @@ -377,6 +379,8 @@ export interface SendCompletedData {
token: string;
chainId: number;
network: string;
/** `true` = live mode, `false` = test mode. */
livemode: boolean;
description: string | null;
}

Expand All @@ -389,10 +393,34 @@ export interface SendFailedData {
token: string;
chainId: number;
network: string;
/** `true` = live mode, `false` = test mode. */
livemode: boolean;
description: string | null;
}

export interface SubscriptionData {
id: string;
/** Stripe subscription status, mirrored verbatim (e.g. `incomplete`, `active`, `trialing`, `past_due`, `unpaid`, `canceled`). */
status: string;
planName: string | null;
currency: string;
/** Price snapshot in integer minor units (e.g. cents). */
amountMinor: number;
/** ISO 8601 timestamp, or `null` before the first billing cycle is set. */
currentPeriodEnd: string | null;
cancelAtPeriodEnd: boolean;
customerEmail: string | null;
customerName: string | null;
/** `true` = live mode, `false` = test mode. */
livemode: boolean;
}

export type WebhookEvent =
| { type: 'checkout.session.completed'; data: CheckoutCompletedData }
| { type: 'send.completed'; data: SendCompletedData }
| { type: 'send.failed'; data: SendFailedData };
| { type: 'send.failed'; data: SendFailedData }
| { type: 'subscription.created'; data: SubscriptionData }
| { type: 'subscription.renewed'; data: SubscriptionData }
| { type: 'subscription.payment_failed'; data: SubscriptionData }
| { type: 'subscription.updated'; data: SubscriptionData }
| { type: 'subscription.canceled'; data: SubscriptionData };
Loading