import type { Money } from './money.js'; import type { Iso8601 } from './time.js'; import type { PaymentStatus, Receipt } from './domain.js'; /** * A declaration of what entitlements a payment should grant on success. The * host produces this; Stipend executes it. */ export type GrantSpecEntry = { readonly type: 'one_time'; readonly scope: { readonly service: string; readonly tool?: string; }; } | { readonly type: 'balance'; readonly scope: { readonly service: string; readonly tool?: string; }; readonly amount: Money; } | { readonly type: 'subscription'; readonly scope: { readonly service: string; readonly tool?: string; }; readonly validFor: string; } | { readonly type: 'quota'; readonly scope: { readonly service: string; readonly tool?: string; }; readonly limit: number; readonly period: 'daily' | 'weekly' | 'monthly' | 'never'; }; export type GrantsSpec = readonly GrantSpecEntry[]; /** * Where the money comes from. The shape selects which funding flow a * {@link PaymentProvider} should run. * * - `customer_payment_method` (v1.0): closed-loop. The host holds the * principal's saved payment method via a Stripe Customer; the adapter * charges it server-side. * - `shared_payment_token` (v1.5): cross-ecosystem. An external agent * host issued a Shared Payment Token scoped to this seller; the * adapter redeems it. v1.0 ships the variant so callers and policy * can be written against the final shape, but the Stripe adapter * throws `NotImplementedError` until v1.5. */ export type PaymentSource = { readonly type: 'customer_payment_method'; /** Provider-side customer identifier (e.g. Stripe `cus_…`). */ readonly customerId: string; /** Provider-side payment method identifier (e.g. Stripe `pm_…`). */ readonly paymentMethodId: string; } | { readonly type: 'shared_payment_token'; /** Provider-side granted-token identifier (e.g. Stripe `spt_…`). */ readonly token: string; }; export interface PaymentIntent { readonly accountId: string; readonly amount: Money; readonly description: string; readonly grantsSpec: GrantsSpec; /** How the money is funded. See {@link PaymentSource}. */ readonly source: PaymentSource; readonly metadata?: Readonly>; } export interface IntentHandle { readonly providerIntentId: string; readonly approvalUrl: string; } export interface PrincipalToken { readonly value: string; } export interface Approval { readonly providerIntentId: string; readonly approvedAt: Iso8601; readonly providerRef?: string; } /** * A payment provider adapter (Stripe SPT in v1; x402, MPP, AP2 to follow). * * The adapter is purely about moving money and producing receipts. Whether a * receipt grants entitlements is decided by Stipend core based on the * payment's `grants_spec`. */ export interface PaymentProvider { readonly name: string; intent(req: PaymentIntent): Promise; approve(handle: IntentHandle, token: PrincipalToken): Promise; execute(approval: Approval): Promise<{ readonly status: PaymentStatus; readonly providerRef: string; }>; refund(receipt: Receipt, amount?: Money): Promise<{ readonly providerRef: string; }>; } //# sourceMappingURL=provider.d.ts.map