@peable.to/shared-types 0.10.0 → 0.11.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.
@@ -1,73 +1,17 @@
1
+ import type { Charge } from './charge';
2
+ import type { Customer } from './customer';
1
3
  import type { Dispute } from './dispute';
2
4
  import type { PaymentIntent } from './paymentIntent';
3
- import type { ConnectedAccount } from './settlement';
4
- export type WebhookEventType = 'payment_intent.confirming' | 'payment_intent.settled' | 'payment_intent.failed' | 'payment_intent.rejected' | 'payment_intent.expired'
5
+ import type { PaymentMethod } from './paymentMethod';
6
+ import type { ConnectedAccount, Refund } from './settlement';
7
+ import type { SetupIntent } from './setupIntent';
8
+ import type { WebhookEndpoint } from './webhookEndpoint';
5
9
  /**
6
- * Money went back to the payer.
7
- *
8
- * Both of these exist for the refund a merchant did NOT initiate — one made
9
- * from the provider's own dashboard, or a dispute the network resolved
10
- * against the merchant. A merchant who only ever learned about their own
11
- * refunds would reconcile to a balance that disagrees with the provider's,
12
- * with nothing to explain the difference.
13
- *
14
- * Additive to a published contract: an existing consumer that switches on
15
- * this union keeps compiling and simply never matches them.
16
- */
17
- | 'payment_intent.refunded' | 'payment_intent.partially_refunded'
18
- /**
19
- * The network is holding this payment's money while a cardholder contests it.
20
- *
21
- * Two events and not one because the two moments demand different things of a
22
- * merchant. `disputed` is a DEADLINE — evidence is due, and a merchant who
23
- * learns about it late has already lost. `dispute_closed` carries the outcome,
24
- * which is when the money is finally theirs or finally gone.
25
- *
26
- * Neither is a payment-intent STATUS. A dispute is the network's process, not
27
- * a stage of the payment's lifecycle — the payment stayed `settled` throughout
28
- * and may end there. That is also how Stripe models it: a charge is
29
- * `disputed`, a PaymentIntent has no such status.
30
- *
31
- * These two carry a {@link Dispute} as their `data.object`, NOT the payment
32
- * intent — see {@link WebhookEventPayload}. The `paymentIntentId` on it is
33
- * how a consumer gets back to the payment.
34
- *
35
- * Additive to a published contract: an existing consumer that switches on
36
- * this union keeps compiling and simply never matches them.
37
- */
38
- | 'payment_intent.disputed' | 'payment_intent.dispute_closed'
39
- /**
40
- * A seller's account changed — their READINESS, in practice.
41
- *
42
- * The first event here that is not about a payment, and it exists because
43
- * readiness is the one fact about a seller a marketplace cannot act without
44
- * and could not learn: the gateway refreshed the account row from the
45
- * provider and told the merchant nothing, so the only ways to find out a
46
- * seller had finished onboarding were to poll `GET /v1/connected_accounts`
47
- * or to attempt a settlement and read the refusal.
48
- *
49
- * Emitted when the fields a merchant ACTS on change — payability, the two
50
- * capabilities, the requirement counts, the disabled reasons — and not on
51
- * every refresh. A periodic sync sweep re-reads every account whether or not
52
- * anything moved, and an event per sweep would be a stream a merchant learns
53
- * to ignore.
54
- *
55
- * It carries a {@link ConnectedAccount} and its delivery names NO payment
56
- * intent, which is why `WebhookDelivery.intentId` is nullable.
57
- *
58
- * Additive to a published contract: an existing consumer that switches on
59
- * this union keeps compiling and simply never matches it.
60
- */
61
- | 'connected_account.updated' | 'billing.observation.updated';
62
- /**
63
- * Which resource each event type carries under `data.object`.
64
- *
65
- * TOTAL over `WebhookEventType`, so a new event type cannot be added without
66
- * saying what it delivers. That matters more here than anywhere else in this
67
- * contract: `data.object` is the whole payload, and an event type added with
68
- * the default would silently ship a PaymentIntent to a consumer expecting
69
- * something else — which typechecks on both sides and fails only in production.
10
+ * The wire date every response names in `Peable-Version`, and the
11
+ * `api_version` an event is stored under (ADR 0014 D2/D4). One constant, so
12
+ * the header and the stored events cannot name two different wires.
70
13
  */
14
+ export declare const PEABLE_API_VERSION = "2026-11-03";
71
15
  /** Wake-up only. Re-read the owner-bound SDK resource; this is never paid or grant authority. */
72
16
  export interface BillingObservation {
73
17
  object: 'billing_observation';
@@ -80,18 +24,81 @@ export interface BillingObservation {
80
24
  revision: number;
81
25
  observed_at: number;
82
26
  }
27
+ /**
28
+ * Which resource each event type carries under `data.object`.
29
+ *
30
+ * TOTAL over {@link WebhookEventType} (which is derived from its keys), so a new
31
+ * event type cannot exist without saying what it delivers: an event added with
32
+ * a default would silently ship a PaymentIntent to a consumer expecting
33
+ * something else — which typechecks on both sides and fails only in production.
34
+ *
35
+ * The `payment_intent.*` events follow the status the intent reached
36
+ * (ADR 0019): `created` when it is minted, then one per transition —
37
+ * `requires_action`, `processing`, `amount_capturable_updated` (authorized,
38
+ * awaiting capture), `succeeded`, `payment_failed` (an attempt failed; a card
39
+ * returns to `requires_payment_method`, a FairCoin underpayment is also
40
+ * `canceled`) and `canceled` (by the merchant, by expiry — `abandoned` — or
41
+ * underpaid).
42
+ *
43
+ * Refunds are not PaymentIntent statuses: `refund.created|updated|failed` carry
44
+ * the Refund, and `charge.refunded` the Charge whose `amount_refunded` moved.
45
+ * A dispute is the network's process beside a payment that stays `succeeded`:
46
+ * `charge.dispute.created` is a DEADLINE (evidence is due), `closed` carries
47
+ * the outcome.
48
+ */
83
49
  export interface WebhookEventPayload {
84
- 'billing.observation.updated': BillingObservation;
85
- 'payment_intent.confirming': PaymentIntent;
86
- 'payment_intent.settled': PaymentIntent;
87
- 'payment_intent.failed': PaymentIntent;
88
- 'payment_intent.rejected': PaymentIntent;
89
- 'payment_intent.expired': PaymentIntent;
90
- 'payment_intent.refunded': PaymentIntent;
91
- 'payment_intent.partially_refunded': PaymentIntent;
92
- 'payment_intent.disputed': Dispute;
93
- 'payment_intent.dispute_closed': Dispute;
50
+ 'payment_intent.created': PaymentIntent;
51
+ 'payment_intent.requires_action': PaymentIntent;
52
+ 'payment_intent.processing': PaymentIntent;
53
+ 'payment_intent.amount_capturable_updated': PaymentIntent;
54
+ 'payment_intent.succeeded': PaymentIntent;
55
+ 'payment_intent.payment_failed': PaymentIntent;
56
+ 'payment_intent.canceled': PaymentIntent;
57
+ 'charge.refunded': Charge;
58
+ 'charge.dispute.created': Dispute;
59
+ 'charge.dispute.updated': Dispute;
60
+ 'charge.dispute.closed': Dispute;
61
+ 'refund.created': Refund;
62
+ 'refund.updated': Refund;
63
+ 'refund.failed': Refund;
64
+ 'customer.created': Customer;
65
+ 'customer.updated': Customer;
66
+ 'customer.deleted': Customer;
67
+ 'payment_method.attached': PaymentMethod;
68
+ 'payment_method.detached': PaymentMethod;
69
+ 'payment_method.updated': PaymentMethod;
70
+ 'setup_intent.created': SetupIntent;
71
+ 'setup_intent.requires_action': SetupIntent;
72
+ 'setup_intent.succeeded': SetupIntent;
73
+ 'setup_intent.setup_failed': SetupIntent;
74
+ 'setup_intent.canceled': SetupIntent;
75
+ /**
76
+ * A seller's account changed — their READINESS, in practice. Emitted when the
77
+ * fields a merchant ACTS on change, not on every refresh. It names no payment
78
+ * intent.
79
+ */
94
80
  'connected_account.updated': ConnectedAccount;
81
+ 'billing.observation.updated': BillingObservation;
82
+ /**
83
+ * A synthetic event sent to ONE endpoint when its owner asks to test it
84
+ * (Orbit's "send test event"). Stored like any other event, but it never fans
85
+ * out and it cannot be subscribed to: `enabled_events` refuses it. The
86
+ * endpoint being tested, as `GET /v1/webhook_endpoints/:id` returns it.
87
+ */
88
+ 'webhook_endpoint.test': WebhookEndpoint;
89
+ }
90
+ /** Every event type, Stripe's names. */
91
+ export type WebhookEventType = keyof WebhookEventPayload;
92
+ /**
93
+ * What caused an event, when an API request did (Stripe's `event.request`).
94
+ * Both `null` for an event caused by something else — the chain watcher, the
95
+ * expiry sweeper, a provider's own notification.
96
+ */
97
+ export interface WebhookEventRequest {
98
+ /** The `Request-Id` of the request whose change produced the event. */
99
+ id: string | null;
100
+ /** The `Idempotency-Key` that request carried, if any. */
101
+ idempotency_key: string | null;
95
102
  }
96
103
  /**
97
104
  * One delivered event.
@@ -100,20 +107,13 @@ export interface WebhookEventPayload {
100
107
  * a switch on `type` with no cast:
101
108
  *
102
109
  * ```ts
103
- * if (event.type === 'payment_intent.disputed') {
110
+ * if (event.type === 'charge.dispute.created') {
104
111
  * event.data.object.evidence_due_at; // Dispute, not PaymentIntent
105
112
  * }
106
113
  * ```
107
114
  *
108
- * That correlation is the whole point of building it this way rather than as
109
- * `{ type: WebhookEventType; data: { object: PaymentIntent | Dispute } }`,
110
- * which typechecks identically at the boundary and then lets a consumer read a
111
- * `Dispute`'s fields off a settlement.
112
- *
113
- * The parameter narrows to a subset of event types — `WebhookEvent<'payment_intent.disputed'>`
114
- * is the dispute event alone. It takes an event TYPE and not a payload type,
115
- * because the payload is derivable from the event and the reverse is not: two
116
- * event types share `Dispute`.
115
+ * The parameter narrows to a subset of event types —
116
+ * `WebhookEvent<'payment_intent.succeeded'>` is that event alone.
117
117
  */
118
118
  export type WebhookEvent<K extends WebhookEventType = WebhookEventType> = {
119
119
  [T in K]: {
@@ -126,13 +126,23 @@ export type WebhookEvent<K extends WebhookEventType = WebhookEventType> = {
126
126
  /**
127
127
  * The connected account (`ca_…`) this event is about — Stripe's
128
128
  * `event.account` (ADR 0012 D7). Present on every event for an on-behalf
129
- * payment and on `connected_account.updated`; absent on events about the
130
- * merchant's own payments. Lets a platform route an event to a seller
131
- * without opening `data.object`.
129
+ * payment and on `connected_account.updated`; absent otherwise.
132
130
  */
133
131
  account?: string;
132
+ /**
133
+ * The wire version the event was rendered with — the `Peable-Version` of
134
+ * the deployment that stored it. An event is a stored snapshot; it is not
135
+ * re-rendered when the wire moves on.
136
+ */
137
+ api_version: string;
134
138
  data: {
135
139
  object: WebhookEventPayload[T];
140
+ /**
141
+ * The fields of `object` that this change moved, with their values
142
+ * BEFORE it. Absent when the event is not a change of an existing object.
143
+ */
144
+ previous_attributes?: Record<string, unknown>;
136
145
  };
146
+ request: WebhookEventRequest;
137
147
  };
138
148
  }[K];
@@ -1,8 +1,13 @@
1
1
  export { UNITS_PER_COIN, isBaseUnitString, type CurrencyCode, CURRENCY_CODES, CURRENCY_DECIMALS, decimalsFor, isCurrencyCode, } from './money';
2
2
  export type { NetworkType } from './network';
3
3
  export type { ExpandParams, List, ListParams, RangeQuery } from './list';
4
- export { type PaymentIntentStatus, type PaymentIntentRail, type PaymentIntent, type CreatePaymentIntentParams, type UpdatePaymentIntentParams, isValidStatusTransition, canStillBePaid, reachesSettlementFromPayer, POST_SETTLEMENT_STATUSES, PAYMENT_INTENT_STATUSES, PAYMENT_INTENT_RAILS, CHAIN_ONLY_STATUSES, CARD_ONLY_STATUSES, EXPIRABLE_STATUSES, canExpire, } from './paymentIntent';
5
- export type { WebhookEventType, WebhookEvent, WebhookEventPayload, BillingObservation, } from './event';
4
+ export { type Address, type AddressParams, type CancelPaymentIntentParams, type CapturePaymentIntentParams, type ConfirmPaymentIntentParams, type CreatePaymentIntentParams, type PaymentIntent, type PaymentIntentCancellationReason, type PaymentIntentCaptureMethod, type PaymentIntentFaircoin, type PaymentIntentLastPaymentError, type PaymentIntentNextAction, type PaymentIntentRail, type PaymentIntentSetupFutureUsage, type PaymentIntentStatus, type PaymentMethodType, type Shipping, type ShippingParams, type UpdatePaymentIntentParams, CARD_ONLY_STATUSES, EXPIRABLE_STATUSES, MERCHANT_CANCELLATION_REASONS, PAYMENT_INTENT_CANCELLATION_REASONS, PAYMENT_INTENT_CAPTURE_METHODS, PAYMENT_INTENT_RAILS, PAYMENT_INTENT_SETUP_FUTURE_USAGES, PAYMENT_INTENT_STATUSES, TERMINAL_STATUSES, canExpire, canStillBePaid, isValidStatusTransition, } from './paymentIntent';
5
+ export type { CardDetails, Charge, ChargeOutcome } from './charge';
6
+ export type { CreateCustomerParams, Customer, DeletedCustomer, UpdateCustomerParams, } from './customer';
7
+ export type { AttachPaymentMethodParams, BillingDetails, PaymentMethod, UpdatePaymentMethodParams, } from './paymentMethod';
8
+ export { type CancelSetupIntentParams, type CreateSetupIntentParams, type SetupIntent, type SetupIntentCancellationReason, type SetupIntentStatus, type SetupIntentUsage, SETUP_INTENT_STATUSES, } from './setupIntent';
9
+ export { PEABLE_API_VERSION, type WebhookEventType, type WebhookEvent, type WebhookEventPayload, type WebhookEventRequest, type BillingObservation, } from './event';
10
+ export { WEBHOOK_ENDPOINT_STATUSES, WEBHOOK_ENDPOINT_DISABLED_REASONS, WEBHOOK_ENDPOINTS_MAX_PER_MERCHANT, WEBHOOK_SECRET_ROLL_MAX_EXPIRES_IN_SECONDS, type WebhookEnabledEvent, type WebhookEndpoint, type WebhookEndpointStatus, type WebhookEndpointDisabledReason, type DeletedWebhookEndpoint, type CreateWebhookEndpointParams, type UpdateWebhookEndpointParams, type RollWebhookEndpointSecretParams, } from './webhookEndpoint';
6
11
  export type { Dispute, DisputeEvidence, DisputeStatus } from './dispute';
7
12
  export type { CapabilityStatus, ConnectedAccount, ConnectedAccountFaircoin, ConnectedAccountFaircoinStatus, ConnectedAccountRail, Refund, RefundOrigin, RefundStatus, Settlement, Transfer, TransferReversal, TransferReversalStatus, TransferStatus, TransferWithReversal, } from './settlement';
8
13
  export type { WebhookDelivery, WebhookDeliveryStatus, } from './webhookDelivery';
@@ -23,7 +23,6 @@ export interface Merchant {
23
23
  network: NetworkType | null;
24
24
  /** `null` on a card-only merchant. Nullable together with `network`. */
25
25
  xpub: string | null;
26
- webhook_url?: string;
27
26
  required_confirmations: number;
28
27
  /**
29
28
  * Payer-facing branding. Absent when unset — `MerchantDisplay` is what a
@@ -1,6 +1,9 @@
1
- import type { ConnectedAccount } from './settlement';
1
+ import type { Charge } from './charge';
2
+ import type { Customer } from './customer';
2
3
  import type { CurrencyCode } from './money';
3
4
  import type { NetworkType } from './network';
5
+ import type { PaymentMethod } from './paymentMethod';
6
+ import type { ConnectedAccount } from './settlement';
4
7
  /**
5
8
  * Which rail moves the money (ADR 0001 D1).
6
9
  *
@@ -11,65 +14,157 @@ import type { NetworkType } from './network';
11
14
  export type PaymentIntentRail = 'faircoin' | 'card';
12
15
  /** {@link PaymentIntentRail} as the tuple the database CHECK reads. */
13
16
  export declare const PAYMENT_INTENT_RAILS: readonly PaymentIntentRail[];
14
- export type PaymentIntentStatus = 'created' | 'awaiting_approval' | 'approved' | 'broadcast' | 'confirming' | 'requires_action' | 'processing' | 'settled' | 'refunded' | 'partially_refunded' | 'expired' | 'failed' | 'rejected';
15
17
  /**
16
- * Which statuses belong to which rail (ADR 0001 D5).
18
+ * Stripe's seven statuses, and no others (ADR 0019).
17
19
  *
18
- * The four chain states describe a transaction on a blockchain and the four
19
- * card states describe an authorization at a card acquirer; neither set is
20
- * expressible on the other rail. Mapping a card authorization onto `broadcast`
21
- * would be cheaper and would be a lie — nothing was broadcast, there is no
22
- * transaction, and `payment_intents_broadcast_requires_txid_check` would then
23
- * be demanding a txid from a payment that can never have one.
20
+ * The FairCoin rail walks four of them: it is created in `requires_action`
21
+ * (the payer must broadcast a transaction — `next_action.faircoin_payment`),
22
+ * moves to `processing` once a transaction is reported and while it confirms,
23
+ * and ends `succeeded` or `canceled`. A card walks all seven.
24
+ */
25
+ export type PaymentIntentStatus = 'requires_payment_method' | 'requires_confirmation' | 'requires_action' | 'processing' | 'requires_capture' | 'canceled' | 'succeeded';
26
+ /**
27
+ * The statuses only a CARD payment can reach (ADR 0019).
24
28
  *
25
- * `db/schema/payments.ts` renders these two sets into CHECK constraints, so the
26
- * restriction holds against a write that skipped the application.
29
+ * A FairCoin payment has no payment method to require (the payer's wallet signs
30
+ * on their own device), nothing to confirm server-side, and no authorization
31
+ * to capture — coins either arrive or they do not. `db/schema/payments.ts`
32
+ * renders this set into a CHECK, so the restriction holds against a write that
33
+ * skipped the application.
27
34
  */
28
- export declare const CHAIN_ONLY_STATUSES: readonly PaymentIntentStatus[];
29
35
  export declare const CARD_ONLY_STATUSES: readonly PaymentIntentStatus[];
30
36
  export declare function isValidStatusTransition(from: PaymentIntentStatus, to: PaymentIntentStatus): boolean;
31
- /** Every legal `PaymentIntentStatus`, derived from `ALLOWED`'s keys — the
32
- * single source of truth consumed by the Gateway's list-route status filter. */
37
+ /** Every `PaymentIntentStatus`, derived from `ALLOWED`'s keys. */
33
38
  export declare const PAYMENT_INTENT_STATUSES: readonly PaymentIntentStatus[];
39
+ /** The statuses that end a payment: nothing leaves them (bar the reorg exception). */
40
+ export declare const TERMINAL_STATUSES: readonly PaymentIntentStatus[];
34
41
  /**
35
42
  * Whether a payer can still complete a payment against an intent in this
36
- * status.
37
- *
38
- * `settled` answers `false`: it is where paying ENDS. `partially_refunded`
39
- * answers `false` too — money can still move, but not from the payer.
43
+ * status — every non-terminal one. Stated, not derived from reachability:
44
+ * `paymentIntent.test.ts` pins it against the table.
40
45
  */
41
46
  export declare function canStillBePaid(status: PaymentIntentStatus): boolean;
42
47
  /**
43
- * The statuses a payment reaches only AFTER the payer has finished.
48
+ * The statuses an intent may still EXPIRE from (ADR 0012 D9).
44
49
  *
45
- * Exported for the gate below rather than for production use: the property that
46
- * makes `PAYABLE_STATUSES` checkable is that a payable status reaches `settled`
47
- * without going through one of these.
50
+ * The gateway is waiting on a PERSON who has not paid: a FairCoin payer who has
51
+ * not broadcast (`requires_action`), or a card payer who has not completed a
52
+ * payment method or a challenge. Once a FairCoin payer has reported a
53
+ * transaction (`processing`) the intent NEVER expires, whatever `expires_at`
54
+ * says — coins are moving and the settlement watcher owns the row. An
55
+ * authorization held for capture (`requires_capture`) is the merchant's to
56
+ * capture or cancel and does not expire either.
57
+ *
58
+ * Expiry is a cancellation with `cancellation_reason: 'abandoned'`: a platform
59
+ * releases a reservation on `payment_intent.canceled`.
48
60
  */
49
- export declare const POST_SETTLEMENT_STATUSES: readonly PaymentIntentStatus[];
61
+ export declare const EXPIRABLE_STATUSES: readonly PaymentIntentStatus[];
62
+ /** Whether an intent in this status can still expire. See {@link EXPIRABLE_STATUSES}. */
63
+ export declare function canExpire(status: PaymentIntentStatus): boolean;
50
64
  /**
51
- * Whether `settled` is reachable from `status` without passing through a
52
- * post-settlement status. The derivation `canStillBePaid` used to BE, kept as
53
- * the thing that checks it rather than as the thing that answers it.
65
+ * Why an intent was cancelled — Stripe's reasons, plus `underpaid`.
66
+ *
67
+ * - `abandoned` — it expired: the payer never paid (the expiry sweeper).
68
+ * - `requested_by_customer` / `duplicate` / `fraudulent` — the merchant said so
69
+ * through `POST /v1/payment_intents/:id/cancel`.
70
+ * - `underpaid` — FairCoin only: a transaction arrived at the address and paid
71
+ * less than the amount. Peable never holds those coins, so it cannot ask for
72
+ * the difference on the same intent; `last_payment_error` says what happened.
73
+ * - `automatic` — the provider cancelled it on its own.
74
+ *
75
+ * `null` on a cancelled intent whose cause was never recorded (one cancelled
76
+ * without a reason, or migrated from the pre-0019 `rejected`).
54
77
  */
55
- export declare function reachesSettlementFromPayer(status: PaymentIntentStatus): boolean;
78
+ export type PaymentIntentCancellationReason = 'abandoned' | 'automatic' | 'duplicate' | 'fraudulent' | 'requested_by_customer' | 'underpaid';
79
+ export declare const PAYMENT_INTENT_CANCELLATION_REASONS: readonly PaymentIntentCancellationReason[];
80
+ /** The reasons a MERCHANT may give `POST /v1/payment_intents/:id/cancel`. */
81
+ export declare const MERCHANT_CANCELLATION_REASONS: readonly ["abandoned", "duplicate", "fraudulent", "requested_by_customer"];
82
+ /** When a card is captured: at confirmation, or by `POST …/capture` (card only). */
83
+ export type PaymentIntentCaptureMethod = 'automatic' | 'manual';
84
+ export declare const PAYMENT_INTENT_CAPTURE_METHODS: readonly PaymentIntentCaptureMethod[];
85
+ /** Card only: keep the payment method on the customer for later (ADR 0016). */
86
+ export type PaymentIntentSetupFutureUsage = 'on_session' | 'off_session';
87
+ export declare const PAYMENT_INTENT_SETUP_FUTURE_USAGES: readonly PaymentIntentSetupFutureUsage[];
88
+ /** The payment method types a rail accepts. One per rail today. */
89
+ export type PaymentMethodType = 'card' | 'faircoin';
90
+ /** Why the last attempt failed. Peable's words, never the provider's raw prose. */
91
+ export interface PaymentIntentLastPaymentError {
92
+ /** `card_error` for a declined card; `payment_error` for a FairCoin underpayment. */
93
+ type: 'card_error' | 'payment_error' | 'api_error';
94
+ code: string | null;
95
+ decline_code: string | null;
96
+ message: string;
97
+ }
98
+ /** A postal address — Stripe's shape. */
99
+ export interface Address {
100
+ line1: string | null;
101
+ line2: string | null;
102
+ city: string | null;
103
+ state: string | null;
104
+ postal_code: string | null;
105
+ /** ISO 3166-1 alpha-2. */
106
+ country: string | null;
107
+ }
108
+ export interface Shipping {
109
+ name: string;
110
+ phone: string | null;
111
+ address: Address;
112
+ carrier: string | null;
113
+ tracking_number: string | null;
114
+ }
115
+ /** An address as a request carries it: every field optional. */
116
+ export interface AddressParams {
117
+ line1?: string;
118
+ line2?: string;
119
+ city?: string;
120
+ state?: string;
121
+ postal_code?: string;
122
+ country?: string;
123
+ }
124
+ /** Shipping as a request carries it: only `name` and `address` are required. */
125
+ export interface ShippingParams {
126
+ name: string;
127
+ phone?: string;
128
+ address: AddressParams;
129
+ carrier?: string;
130
+ tracking_number?: string;
131
+ }
56
132
  /**
57
- * The statuses an intent may still EXPIRE from (ADR 0012 D9).
133
+ * What the payer must do next (`status: 'requires_action'`).
58
134
  *
59
- * Exactly those whose transition list contains `expired`: the gateway is
60
- * waiting on a PERSON who has not paid. Once a FairCoin payer has reported a
61
- * broadcast (`broadcast`), or the chain is confirming it (`confirming`), the
62
- * intent NEVER expires, whatever `expiresAt` says — coins are moving and the
63
- * settlement watcher owns the row. A platform must therefore never cancel an
64
- * order because `expiresAt` passed: it releases a reservation on
65
- * `payment_intent.expired` (or `rejected`), and on nothing else.
135
+ * - `faircoin_payment` — send exactly `amount` (base units) to `address` on
136
+ * `network`; `uri` is the BIP21-style `faircoin:` URI a wallet scans.
137
+ * - `use_peable_sdk` — a card challenge; `@peable.to/sdk/checkout` fetches the
138
+ * provider's confirmation credential through `POST …/client_action` and
139
+ * completes it. The credential is never on the intent itself.
140
+ */
141
+ export type PaymentIntentNextAction = {
142
+ type: 'faircoin_payment';
143
+ faircoin_payment: {
144
+ address: string;
145
+ network: NetworkType;
146
+ amount: string;
147
+ currency: 'FAIR';
148
+ uri: string;
149
+ };
150
+ } | {
151
+ type: 'use_peable_sdk';
152
+ };
153
+ /**
154
+ * The chain side of a FairCoin payment. `null` on a card payment.
66
155
  *
67
- * Stated rather than derived, for `PAYABLE_STATUSES`' reason; the gateway's
68
- * test suite pins it against the transition table.
156
+ * `txid` and `confirmations` describe the transaction the payer reported:
157
+ * `null`/`0` while the intent is `requires_action`, and the watcher's count
158
+ * against `required_confirmations` while it is `processing`.
69
159
  */
70
- export declare const EXPIRABLE_STATUSES: readonly PaymentIntentStatus[];
71
- /** Whether an intent in this status can still expire. See {@link EXPIRABLE_STATUSES}. */
72
- export declare function canExpire(status: PaymentIntentStatus): boolean;
160
+ export interface PaymentIntentFaircoin {
161
+ network: NetworkType;
162
+ /** Watch-only receive address derived per intent from the merchant's (or seller's) xpub. */
163
+ address: string;
164
+ txid: string | null;
165
+ confirmations: number;
166
+ required_confirmations: number;
167
+ }
73
168
  export interface PaymentIntent {
74
169
  id: string;
75
170
  object: 'payment_intent';
@@ -81,83 +176,119 @@ export interface PaymentIntent {
81
176
  status: PaymentIntentStatus;
82
177
  /** Which rail moves this payment. Decides which fields below are populated. */
83
178
  rail: PaymentIntentRail;
179
+ payment_method_types: PaymentMethodType[];
84
180
  /**
85
181
  * Amount in the currency's SMALLEST unit as a canonical integer string.
86
182
  * Never a float, and never interpretable without `currency`: m⊜ (10^-8 FAIR)
87
183
  * on the faircoin rail, cents on a fiat one.
88
184
  */
89
185
  amount: string;
186
+ /** What can still be captured: the authorized amount while `requires_capture`, else `"0"`. */
187
+ amount_capturable: string;
188
+ /** What was received: the captured amount once `succeeded`, else `"0"`. */
189
+ amount_received: string;
190
+ /** The sum of SUCCEEDED refunds on this payment. Refund state lives on the refunds. */
191
+ amount_refunded: string;
90
192
  currency: CurrencyCode;
91
- /** FairCoin rail only. `null` on a card payment, which has no network. */
92
- network: NetworkType | null;
93
- /**
94
- * Watch-only receive address derived per-intent from the merchant xpub.
95
- * FairCoin rail only; `null` on a card payment, which reserves no address.
96
- */
97
- address: string | null;
193
+ capture_method: PaymentIntentCaptureMethod;
194
+ setup_future_usage: PaymentIntentSetupFutureUsage | null;
195
+ /** `cus_…`, or the {@link Customer} with `expand[]=customer`. */
196
+ customer: string | Customer | null;
197
+ /** `pm_…`, or the {@link PaymentMethod} with `expand[]=payment_method`. Card only. */
198
+ payment_method: string | PaymentMethod | null;
199
+ /** `ch_…`, or the {@link Charge} with `expand[]=latest_charge`. Card only. */
200
+ latest_charge: string | Charge | null;
201
+ next_action: PaymentIntentNextAction | null;
202
+ last_payment_error: PaymentIntentLastPaymentError | null;
203
+ cancellation_reason: PaymentIntentCancellationReason | null;
204
+ canceled_at: number | null;
205
+ description: string | null;
206
+ receipt_email: string | null;
207
+ /** Card only. */
208
+ statement_descriptor_suffix: string | null;
209
+ shipping: Shipping | null;
210
+ /** The chain side. FairCoin rail only; `null` on a card payment. */
211
+ faircoin: PaymentIntentFaircoin | null;
212
+ /** The merchant's PUBLIC `merch_…`. */
98
213
  merchant_id: string;
99
214
  /**
100
215
  * The seller this payment is made ON BEHALF OF (`ca_…`), or `null` for a
101
216
  * payment to the merchant itself (ADR 0012 D5). On-behalf payments are
102
- * FairCoin only, and `address` derives from that seller's own key.
103
- *
104
- * The seller's `ca_…`, or the {@link ConnectedAccount} itself when the
105
- * request asked for `expand[]=connected_account`.
217
+ * FairCoin only, and `faircoin.address` derives from that seller's own key.
106
218
  */
107
219
  connected_account: string | ConnectedAccount | null;
108
- txid: string | null;
109
- /** On-chain confirmations. Structurally `0` for the whole life of a card payment. */
110
- confirmations: number;
111
220
  client_secret: string;
112
221
  metadata: Record<string, string>;
113
- /**
114
- * When an UNPAID intent expires. Meaningful only while {@link canExpire}
115
- * is true for `status` — see `canExpire` below.
116
- */
222
+ /** When an UNPAID intent expires. Meaningful only while `can_expire`. */
117
223
  expires_at: number;
118
- /**
119
- * Whether this intent can still expire (ADR 0012 D9). `false` once the payer
120
- * has reported a broadcast: a FairCoin payment that is `broadcast` or
121
- * `confirming` NEVER expires, so a platform must not cancel the order for it.
122
- *
123
- * Optional in the type only for fixtures written against earlier versions;
124
- * a gateway at this version always sends it.
125
- */
126
- can_expire?: boolean;
224
+ /** Whether this intent can still expire (ADR 0012 D9). */
225
+ can_expire: boolean;
127
226
  created: number;
128
227
  updated_at: number;
129
228
  }
229
+ /** `POST /v1/payment_intents`. */
130
230
  export interface CreatePaymentIntentParams {
131
231
  /** Amount in the currency's smallest unit, as a canonical integer string. */
132
232
  amount: string;
133
- /**
134
- * Defaults to `'faircoin'` — the rail this gateway shipped with, so every
135
- * integration written before ADR 0001 keeps working unchanged.
136
- */
233
+ /** Defaults to `'faircoin'`. */
137
234
  rail?: PaymentIntentRail;
138
235
  /** Required on the faircoin rail; refused on the card rail, which has none. */
139
236
  network?: NetworkType;
140
237
  /** Defaults to `'FAIR'` on the faircoin rail; required on the card rail. */
141
238
  currency?: CurrencyCode;
239
+ /** Must name the rail's own type: `['card']` or `['faircoin']`. */
240
+ payment_method_types?: PaymentMethodType[];
241
+ /** `cus_…`. */
242
+ customer?: string;
243
+ /** `pm_…`, card only. A saved payment method of `customer`. */
244
+ payment_method?: string;
245
+ /** Card only: confirm in the same call (needs `payment_method`). */
246
+ confirm?: boolean;
247
+ /** Card only, with `confirm`: the customer is not present (needs `customer`). */
248
+ off_session?: boolean;
249
+ /** Card only. */
250
+ setup_future_usage?: PaymentIntentSetupFutureUsage;
251
+ /** Card only. Defaults to `'automatic'`. */
252
+ capture_method?: PaymentIntentCaptureMethod;
253
+ receipt_email?: string;
254
+ description?: string;
255
+ /** Card only. */
256
+ statement_descriptor_suffix?: string;
257
+ shipping?: ShippingParams;
142
258
  metadata?: Record<string, string>;
143
259
  expires_in_seconds?: number;
144
- /**
145
- * Create the payment ON BEHALF OF this connected account (`ca_…`) — the
146
- * address derives from the seller's own key and the coins go straight to
147
- * their wallet (ADR 0012 D5). FairCoin only: combined with `rail: 'card'` it
148
- * is refused. The account's FairCoin half must be `active` and `network`
149
- * must be the account's network.
150
- */
260
+ /** FairCoin only: pay this seller (`ca_…`, ADR 0012 D5). */
151
261
  connected_account?: string;
262
+ /** Card only, with `confirm`: where a redirect-based challenge returns. */
263
+ return_url?: string;
152
264
  }
153
265
  /**
154
- * `POST /v1/payment_intents/:id`. Only the merchant's own `metadata` is
155
- * mutable on an intent: everything else is either the payment itself or the
156
- * state machine's, which moves only through its own operations.
157
- *
158
- * `metadata` is a PATCH: named keys are set, a key sent as `""` is removed,
159
- * keys not named are kept.
266
+ * `POST /v1/payment_intents/:id`. The merchant's own bookkeeping only —
267
+ * the amount, rail and status are the payment and move through their own
268
+ * operations. `metadata` is a PATCH (`""` unsets a key).
160
269
  */
161
270
  export interface UpdatePaymentIntentParams {
162
271
  metadata?: Record<string, string>;
272
+ description?: string;
273
+ receipt_email?: string;
274
+ shipping?: ShippingParams;
275
+ }
276
+ /** `POST /v1/payment_intents/:id/confirm` (card only). */
277
+ export interface ConfirmPaymentIntentParams {
278
+ /** `pm_…`; defaults to the intent's own. */
279
+ payment_method?: string;
280
+ off_session?: boolean;
281
+ setup_future_usage?: PaymentIntentSetupFutureUsage;
282
+ return_url?: string;
283
+ receipt_email?: string;
284
+ shipping?: ShippingParams;
285
+ }
286
+ /** `POST /v1/payment_intents/:id/capture` (card only, `requires_capture`). */
287
+ export interface CapturePaymentIntentParams {
288
+ /** Base units, at most the authorized amount; defaults to all of it. */
289
+ amount_to_capture?: string;
290
+ }
291
+ /** `POST /v1/payment_intents/:id/cancel`. */
292
+ export interface CancelPaymentIntentParams {
293
+ cancellation_reason?: (typeof MERCHANT_CANCELLATION_REASONS)[number];
163
294
  }