@fragmentpay/server 0.3.1 → 0.4.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 +40 -8
- package/dist/index.d.mts +120 -7
- package/dist/index.d.ts +120 -7
- package/dist/index.js +169 -32
- package/dist/index.mjs +168 -32
- package/dist/openapi-client.d.mts +1201 -0
- package/dist/openapi-client.d.ts +1201 -0
- package/dist/openapi-client.js +54 -0
- package/dist/openapi-client.mjs +19 -0
- package/dist/openapi.d.ts +1161 -0
- package/package.json +40 -7
package/README.md
CHANGED
|
@@ -17,11 +17,11 @@ npm install @fragmentpay/server
|
|
|
17
17
|
|
|
18
18
|
## Required environment variables
|
|
19
19
|
|
|
20
|
-
| Name | Where
|
|
21
|
-
| ------------------------ |
|
|
22
|
-
| `FRAG_SECRET_KEY` | server only
|
|
23
|
-
| `FRAG_WEBHOOK_SECRET` | server only
|
|
24
|
-
| `FRAG_BASE_URL`
|
|
20
|
+
| Name | Where | Example |
|
|
21
|
+
| ------------------------ | ----------- | ------------------------------------------ |
|
|
22
|
+
| `FRAG_SECRET_KEY` | server only | `sk_live_…` or `sk_test_…` |
|
|
23
|
+
| `FRAG_WEBHOOK_SECRET` | server only | value shown when you create the webhook |
|
|
24
|
+
| `FRAG_BASE_URL` _(opt.)_ | server only | override host, default `https://frag.cash` |
|
|
25
25
|
|
|
26
26
|
Never expose `sk_…` in a browser bundle.
|
|
27
27
|
|
|
@@ -46,7 +46,7 @@ export async function startCheckout(orderId: string, cents: number, email: strin
|
|
|
46
46
|
address: process.env.MERCHANT_USDC_ADDRESS!,
|
|
47
47
|
},
|
|
48
48
|
successUrl: "https://shop.example.com/thanks",
|
|
49
|
-
cancelUrl:
|
|
49
|
+
cancelUrl: "https://shop.example.com/cart",
|
|
50
50
|
metadata: { order_id: orderId },
|
|
51
51
|
idempotencyKey: `order_${orderId}`,
|
|
52
52
|
});
|
|
@@ -64,7 +64,7 @@ export async function POST(req: Request) {
|
|
|
64
64
|
const payload = await req.text();
|
|
65
65
|
const event = await verifyWebhook({
|
|
66
66
|
payload,
|
|
67
|
-
signature: req.headers.get("
|
|
67
|
+
signature: req.headers.get("frag-signature"),
|
|
68
68
|
secret: process.env.FRAG_WEBHOOK_SECRET!,
|
|
69
69
|
});
|
|
70
70
|
|
|
@@ -77,6 +77,22 @@ export async function POST(req: Request) {
|
|
|
77
77
|
|
|
78
78
|
**3. React drop-in on the frontend** — see `@fragmentpay/react`.
|
|
79
79
|
|
|
80
|
+
## Advanced options
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const frag = new Frag({
|
|
84
|
+
secretKey: process.env.FRAG_SECRET_KEY!,
|
|
85
|
+
baseUrl: "https://frag.cash", // default
|
|
86
|
+
timeoutMs: 15_000, // per-request timeout
|
|
87
|
+
maxRetries: 3, // retries on 5xx / network errors with Retry-After honored
|
|
88
|
+
fetch: myCustomFetch, // inject a custom fetch (Workers, tracing, etc.)
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Every method throws `FragError` on non-2xx responses. It carries `status`,
|
|
93
|
+
`code`, `message`, and `requestId` for observability, plus the raw provider
|
|
94
|
+
body when available.
|
|
95
|
+
|
|
80
96
|
## Validation errors
|
|
81
97
|
|
|
82
98
|
Every method validates its arguments and throws a `FragValidationError`
|
|
@@ -89,7 +105,8 @@ frag.paymentIntents.create({ amount: -5 });
|
|
|
89
105
|
|
|
90
106
|
## Public API surface
|
|
91
107
|
|
|
92
|
-
- `frag.paymentIntents.{create, retrieve, list, cancel, transactions,
|
|
108
|
+
- `frag.paymentIntents.{create, retrieve, list, cancel, transactions, routing}`
|
|
109
|
+
- `routing(id)` returns router candidates evaluated for the intent (chosen + rejected with reasons). `route(id)` is kept as a deprecated alias.
|
|
93
110
|
- `frag.refunds.{create, retrieve, list}`
|
|
94
111
|
- `frag.payouts.{retrieve, list, replay}`
|
|
95
112
|
- `frag.webhookEndpoints.{create, list, retrieve, update, delete, rotateSecret}`
|
|
@@ -97,6 +114,21 @@ frag.paymentIntents.create({ amount: -5 });
|
|
|
97
114
|
- `verifyWebhook({ payload, signature, secret })`
|
|
98
115
|
- `FragError` (HTTP + upstream) and `FragValidationError` (input)
|
|
99
116
|
|
|
117
|
+
## Idempotency
|
|
118
|
+
|
|
119
|
+
Every `POST` accepts an optional `Idempotency-Key` header (SDK auto-sends it
|
|
120
|
+
when you set `idempotencyKey`). Replays within 24h with the **same body**
|
|
121
|
+
return the original response; a **different body** returns HTTP `409` with
|
|
122
|
+
`code: "idempotency_conflict"`.
|
|
123
|
+
|
|
124
|
+
## Webhook events
|
|
125
|
+
|
|
126
|
+
The SDK's `WebhookEventType` union stays in sync with the API. Notable events:
|
|
127
|
+
`payment_intent.created`, `payment_intent.quoted`, `payment_intent.executing`,
|
|
128
|
+
`payment_intent.settled`, `payment_intent.failed`, `payment_intent.expired`,
|
|
129
|
+
`payment_intent.cancelled`, `payment_intent.refunded`, `payout.created`,
|
|
130
|
+
`payout.paid`, `payout.failed`, `ping`.
|
|
131
|
+
|
|
100
132
|
## License
|
|
101
133
|
|
|
102
134
|
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -23,7 +23,23 @@ declare class FragValidationError extends Error {
|
|
|
23
23
|
type Chain = "solana" | "ethereum" | "base" | "arbitrum" | "optimism" | "polygon" | "bnb";
|
|
24
24
|
type IntentStatus = "created" | "requires_payment" | "quoted" | "awaiting_signature" | "executing" | "partially_filled" | "settled" | "failed" | "expired" | "cancelled" | "refunded";
|
|
25
25
|
type PayoutStatus = "queued" | "pending" | "paid" | "failed" | "paused";
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Raw refund status as stored on the backend. See {@link refundPhase} for a
|
|
28
|
+
* simplified 4-state bucket (`queued | sent | completed | failed`) suitable
|
|
29
|
+
* for rendering merchant/customer-facing status pills.
|
|
30
|
+
*/
|
|
31
|
+
type RefundStatus = "pending" | "processing" | "retry_scheduled" | "succeeded" | "failed";
|
|
32
|
+
/** UI-friendly refund bucket. */
|
|
33
|
+
type RefundPhase = "queued" | "sent" | "completed" | "failed";
|
|
34
|
+
/**
|
|
35
|
+
* Map a raw {@link RefundStatus} onto a stable 4-bucket UI phase.
|
|
36
|
+
*
|
|
37
|
+
* - `queued` → `pending` | `retry_scheduled` (waiting to dispatch / retry)
|
|
38
|
+
* - `sent` → `processing` (broadcast on-chain / to payout provider, awaiting confirmation)
|
|
39
|
+
* - `completed` → `succeeded` (funds delivered, `paid_at` set, `tx_hash` present on-chain rails)
|
|
40
|
+
* - `failed` → `failed` (permanent — retry budget exhausted)
|
|
41
|
+
*/
|
|
42
|
+
declare function refundPhase(status: RefundStatus | string | null | undefined): RefundPhase;
|
|
27
43
|
interface Settlement {
|
|
28
44
|
chain: Chain | string;
|
|
29
45
|
token: string;
|
|
@@ -87,16 +103,59 @@ interface Refund {
|
|
|
87
103
|
id: string;
|
|
88
104
|
payment_intent_id: string;
|
|
89
105
|
amount_usd: number;
|
|
90
|
-
chain: string;
|
|
91
|
-
token: string;
|
|
106
|
+
chain: string | null;
|
|
107
|
+
token: string | null;
|
|
108
|
+
/**
|
|
109
|
+
* Payout address. May be `""` when a refund was auto-enqueued (e.g. by the
|
|
110
|
+
* expiry sweeper) and Frag has not yet resolved the payer's originating
|
|
111
|
+
* address. In that case `failure_reason` is `"missing_destination"` and the
|
|
112
|
+
* refund waits until the merchant supplies one, or Frag derives it from a
|
|
113
|
+
* confirmed payer leg.
|
|
114
|
+
*/
|
|
92
115
|
destination: string;
|
|
93
116
|
reason: string;
|
|
117
|
+
/** Raw backend status. Use {@link refundPhase} to bucket for UI. */
|
|
94
118
|
status: RefundStatus;
|
|
119
|
+
/** On-chain hash once the refund broadcasts. `null` until then. */
|
|
95
120
|
tx_hash: string | null;
|
|
96
|
-
|
|
121
|
+
/** Number of dispatch attempts already made against this refund. */
|
|
122
|
+
attempts: number;
|
|
123
|
+
/** ISO timestamp of the next scheduled retry (only set in `retry_scheduled`). */
|
|
124
|
+
next_attempt_at: string | null;
|
|
125
|
+
/** ISO timestamp when the refund settled. `null` until `status="succeeded"`. */
|
|
97
126
|
paid_at: string | null;
|
|
127
|
+
/** Optional payer email captured at intent time. */
|
|
128
|
+
customer_email?: string | null;
|
|
129
|
+
created_at: string;
|
|
130
|
+
updated_at: string;
|
|
98
131
|
failure_reason?: string | null;
|
|
99
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Public payer-facing refund status returned by {@link RefundResource.status}.
|
|
135
|
+
* UNAUTHENTICATED — safe to render on a receipt page or email. `destination`
|
|
136
|
+
* is redacted to the last 6 chars via `destination_tail`. `phase` is a
|
|
137
|
+
* stable 4-bucket categorization computed with {@link refundPhase}.
|
|
138
|
+
*/
|
|
139
|
+
interface PublicRefundStatus {
|
|
140
|
+
id: string;
|
|
141
|
+
payment_intent_id: string;
|
|
142
|
+
amount_usd: number;
|
|
143
|
+
chain: string | null;
|
|
144
|
+
token: string | null;
|
|
145
|
+
destination_tail: string;
|
|
146
|
+
reason: string;
|
|
147
|
+
status: RefundStatus;
|
|
148
|
+
/** UI bucket: `queued | sent | completed | failed`. */
|
|
149
|
+
phase: RefundPhase;
|
|
150
|
+
tx_hash: string | null;
|
|
151
|
+
failure_reason: string | null;
|
|
152
|
+
attempts: number;
|
|
153
|
+
created_at: string;
|
|
154
|
+
updated_at: string;
|
|
155
|
+
paid_at: string | null;
|
|
156
|
+
/** `true` once no further state change is possible (`completed` or `failed`). */
|
|
157
|
+
terminal: boolean;
|
|
158
|
+
}
|
|
100
159
|
interface Payout {
|
|
101
160
|
id: string;
|
|
102
161
|
payment_intent_id: string | null;
|
|
@@ -132,7 +191,7 @@ interface FragToken {
|
|
|
132
191
|
verified: boolean;
|
|
133
192
|
min_liquidity_usd?: number;
|
|
134
193
|
}
|
|
135
|
-
type WebhookEventType = "payment_intent.created" | "payment_intent.quoted" | "payment_intent.executing" | "payment_intent.executed" | "payment_intent.settled" | "payment_intent.failed" | "payment_intent.expired" | "payment_intent.cancelled" | "payment_intent.refunded" | "quote.created" | "settlement.confirmed" | "payout.
|
|
194
|
+
type WebhookEventType = "payment_intent.created" | "payment_intent.quoted" | "payment_intent.executing" | "payment_intent.executed" | "payment_intent.settled" | "payment_intent.failed" | "payment_intent.expired" | "payment_intent.cancelled" | "payment_intent.refunded" | "quote.created" | "settlement.confirmed" | "payout.created" | "payout.paid" | "payout.failed" | "refund.created" | "refund.processing" | "refund.paid" | "refund.failed";
|
|
136
195
|
interface WebhookEvent<T = unknown> {
|
|
137
196
|
id: string;
|
|
138
197
|
type: WebhookEventType;
|
|
@@ -160,6 +219,7 @@ declare class FragError extends Error {
|
|
|
160
219
|
type Requester = <T>(path: string, init?: RequestInit & {
|
|
161
220
|
idempotencyKey?: string;
|
|
162
221
|
query?: Record<string, string | number | boolean | undefined>;
|
|
222
|
+
skipAuth?: boolean;
|
|
163
223
|
}) => Promise<T>;
|
|
164
224
|
declare class FragmentPay {
|
|
165
225
|
#private;
|
|
@@ -169,7 +229,23 @@ declare class FragmentPay {
|
|
|
169
229
|
readonly webhookEndpoints: WebhookEndpointResource;
|
|
170
230
|
readonly webhooks: WebhookHelpers;
|
|
171
231
|
readonly tokens: TokenResource;
|
|
232
|
+
readonly checkout: PublicCheckoutResource;
|
|
172
233
|
constructor(opts: FragOptions);
|
|
234
|
+
/**
|
|
235
|
+
* Unauthenticated health probe against the API host. Safe to call from
|
|
236
|
+
* uptime monitors and CI. Returns `{ status: "ok" | "degraded" | "down", ... }`.
|
|
237
|
+
*/
|
|
238
|
+
health(): Promise<{
|
|
239
|
+
status: "ok" | "degraded" | "down";
|
|
240
|
+
service: string;
|
|
241
|
+
version: string;
|
|
242
|
+
time: string;
|
|
243
|
+
latency_ms: number;
|
|
244
|
+
checks: {
|
|
245
|
+
env: Record<string, boolean>;
|
|
246
|
+
database: "ok" | "degraded" | "down";
|
|
247
|
+
};
|
|
248
|
+
}>;
|
|
173
249
|
setDebug(on: boolean): void;
|
|
174
250
|
}
|
|
175
251
|
declare class PaymentIntentResource {
|
|
@@ -201,17 +277,54 @@ declare class RefundResource {
|
|
|
201
277
|
create(input: {
|
|
202
278
|
paymentIntentId: string;
|
|
203
279
|
amountUsd: number;
|
|
204
|
-
|
|
280
|
+
/**
|
|
281
|
+
* Payer address to refund to. Optional — omit to let Frag auto-fill from
|
|
282
|
+
* the intent's confirmed payer leg(s). If no payer address can be derived
|
|
283
|
+
* the refund is created in `pending` with `failure_reason: "missing_destination"`
|
|
284
|
+
* until the merchant provides one from the dashboard.
|
|
285
|
+
*/
|
|
286
|
+
destination?: string;
|
|
205
287
|
reason?: string;
|
|
206
288
|
idempotencyKey?: string;
|
|
207
289
|
}): Promise<Refund>;
|
|
208
290
|
retrieve(id: string): Promise<Refund>;
|
|
209
291
|
list(params?: {
|
|
210
292
|
paymentIntentId?: string;
|
|
293
|
+
status?: RefundStatus;
|
|
211
294
|
limit?: number;
|
|
212
295
|
}): Promise<{
|
|
213
296
|
data: Refund[];
|
|
214
297
|
}>;
|
|
298
|
+
/**
|
|
299
|
+
* Fetch the payer-facing safe status view for a refund. UNAUTHENTICATED —
|
|
300
|
+
* safe to expose in a customer-facing page or email. Redacts the destination
|
|
301
|
+
* address (only the last 6 chars) and omits merchant PII. The returned
|
|
302
|
+
* `phase` field is a stable 4-bucket categorization
|
|
303
|
+
* (`queued | sent | completed | failed`) computed on the client for
|
|
304
|
+
* convenient status pills.
|
|
305
|
+
*/
|
|
306
|
+
status(id: string): Promise<PublicRefundStatus>;
|
|
307
|
+
/** Client-side helper: bucket a raw {@link RefundStatus} to a UI phase. */
|
|
308
|
+
phase(status: RefundStatus | string | null | undefined): RefundPhase;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Unauthenticated public checkout view used by hosted checkout pages and the
|
|
312
|
+
* @fragmentpay/react polling hook. Exposes only non-PII fields — no merchant
|
|
313
|
+
* data, no keys, no idempotency records. Rate-limited to 120 req/min per IP.
|
|
314
|
+
*/
|
|
315
|
+
declare class PublicCheckoutResource {
|
|
316
|
+
private req;
|
|
317
|
+
constructor(req: Requester);
|
|
318
|
+
retrieve(id: string): Promise<{
|
|
319
|
+
id: string;
|
|
320
|
+
amount: string;
|
|
321
|
+
currency: string;
|
|
322
|
+
status: IntentStatus;
|
|
323
|
+
settlement_chain: string | null;
|
|
324
|
+
settlement_token: string | null;
|
|
325
|
+
expires_at: string;
|
|
326
|
+
metadata?: Record<string, unknown>;
|
|
327
|
+
}>;
|
|
215
328
|
}
|
|
216
329
|
declare class PayoutResource {
|
|
217
330
|
private req;
|
|
@@ -283,4 +396,4 @@ declare class Frag extends FragmentPay {
|
|
|
283
396
|
});
|
|
284
397
|
}
|
|
285
398
|
|
|
286
|
-
export { type Chain, type CreateIntentInput, Frag, FragError, type FragOptions, type FragToken, FragValidationError, FragmentPay, type IntentStatus, type IntentTransaction, type PaymentIntent, type Payout, type PayoutStatus, type Refund, type RefundStatus, type RouteCandidate, type Settlement, type VerifyWebhookInput, type WebhookEndpoint, type WebhookEvent, type WebhookEventType, verifyWebhook };
|
|
399
|
+
export { type Chain, type CreateIntentInput, Frag, FragError, type FragOptions, type FragToken, FragValidationError, FragmentPay, type IntentStatus, type IntentTransaction, type PaymentIntent, type Payout, type PayoutStatus, type PublicRefundStatus, type Refund, type RefundPhase, type RefundStatus, type RouteCandidate, type Settlement, type VerifyWebhookInput, type WebhookEndpoint, type WebhookEvent, type WebhookEventType, refundPhase, verifyWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,23 @@ declare class FragValidationError extends Error {
|
|
|
23
23
|
type Chain = "solana" | "ethereum" | "base" | "arbitrum" | "optimism" | "polygon" | "bnb";
|
|
24
24
|
type IntentStatus = "created" | "requires_payment" | "quoted" | "awaiting_signature" | "executing" | "partially_filled" | "settled" | "failed" | "expired" | "cancelled" | "refunded";
|
|
25
25
|
type PayoutStatus = "queued" | "pending" | "paid" | "failed" | "paused";
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Raw refund status as stored on the backend. See {@link refundPhase} for a
|
|
28
|
+
* simplified 4-state bucket (`queued | sent | completed | failed`) suitable
|
|
29
|
+
* for rendering merchant/customer-facing status pills.
|
|
30
|
+
*/
|
|
31
|
+
type RefundStatus = "pending" | "processing" | "retry_scheduled" | "succeeded" | "failed";
|
|
32
|
+
/** UI-friendly refund bucket. */
|
|
33
|
+
type RefundPhase = "queued" | "sent" | "completed" | "failed";
|
|
34
|
+
/**
|
|
35
|
+
* Map a raw {@link RefundStatus} onto a stable 4-bucket UI phase.
|
|
36
|
+
*
|
|
37
|
+
* - `queued` → `pending` | `retry_scheduled` (waiting to dispatch / retry)
|
|
38
|
+
* - `sent` → `processing` (broadcast on-chain / to payout provider, awaiting confirmation)
|
|
39
|
+
* - `completed` → `succeeded` (funds delivered, `paid_at` set, `tx_hash` present on-chain rails)
|
|
40
|
+
* - `failed` → `failed` (permanent — retry budget exhausted)
|
|
41
|
+
*/
|
|
42
|
+
declare function refundPhase(status: RefundStatus | string | null | undefined): RefundPhase;
|
|
27
43
|
interface Settlement {
|
|
28
44
|
chain: Chain | string;
|
|
29
45
|
token: string;
|
|
@@ -87,16 +103,59 @@ interface Refund {
|
|
|
87
103
|
id: string;
|
|
88
104
|
payment_intent_id: string;
|
|
89
105
|
amount_usd: number;
|
|
90
|
-
chain: string;
|
|
91
|
-
token: string;
|
|
106
|
+
chain: string | null;
|
|
107
|
+
token: string | null;
|
|
108
|
+
/**
|
|
109
|
+
* Payout address. May be `""` when a refund was auto-enqueued (e.g. by the
|
|
110
|
+
* expiry sweeper) and Frag has not yet resolved the payer's originating
|
|
111
|
+
* address. In that case `failure_reason` is `"missing_destination"` and the
|
|
112
|
+
* refund waits until the merchant supplies one, or Frag derives it from a
|
|
113
|
+
* confirmed payer leg.
|
|
114
|
+
*/
|
|
92
115
|
destination: string;
|
|
93
116
|
reason: string;
|
|
117
|
+
/** Raw backend status. Use {@link refundPhase} to bucket for UI. */
|
|
94
118
|
status: RefundStatus;
|
|
119
|
+
/** On-chain hash once the refund broadcasts. `null` until then. */
|
|
95
120
|
tx_hash: string | null;
|
|
96
|
-
|
|
121
|
+
/** Number of dispatch attempts already made against this refund. */
|
|
122
|
+
attempts: number;
|
|
123
|
+
/** ISO timestamp of the next scheduled retry (only set in `retry_scheduled`). */
|
|
124
|
+
next_attempt_at: string | null;
|
|
125
|
+
/** ISO timestamp when the refund settled. `null` until `status="succeeded"`. */
|
|
97
126
|
paid_at: string | null;
|
|
127
|
+
/** Optional payer email captured at intent time. */
|
|
128
|
+
customer_email?: string | null;
|
|
129
|
+
created_at: string;
|
|
130
|
+
updated_at: string;
|
|
98
131
|
failure_reason?: string | null;
|
|
99
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Public payer-facing refund status returned by {@link RefundResource.status}.
|
|
135
|
+
* UNAUTHENTICATED — safe to render on a receipt page or email. `destination`
|
|
136
|
+
* is redacted to the last 6 chars via `destination_tail`. `phase` is a
|
|
137
|
+
* stable 4-bucket categorization computed with {@link refundPhase}.
|
|
138
|
+
*/
|
|
139
|
+
interface PublicRefundStatus {
|
|
140
|
+
id: string;
|
|
141
|
+
payment_intent_id: string;
|
|
142
|
+
amount_usd: number;
|
|
143
|
+
chain: string | null;
|
|
144
|
+
token: string | null;
|
|
145
|
+
destination_tail: string;
|
|
146
|
+
reason: string;
|
|
147
|
+
status: RefundStatus;
|
|
148
|
+
/** UI bucket: `queued | sent | completed | failed`. */
|
|
149
|
+
phase: RefundPhase;
|
|
150
|
+
tx_hash: string | null;
|
|
151
|
+
failure_reason: string | null;
|
|
152
|
+
attempts: number;
|
|
153
|
+
created_at: string;
|
|
154
|
+
updated_at: string;
|
|
155
|
+
paid_at: string | null;
|
|
156
|
+
/** `true` once no further state change is possible (`completed` or `failed`). */
|
|
157
|
+
terminal: boolean;
|
|
158
|
+
}
|
|
100
159
|
interface Payout {
|
|
101
160
|
id: string;
|
|
102
161
|
payment_intent_id: string | null;
|
|
@@ -132,7 +191,7 @@ interface FragToken {
|
|
|
132
191
|
verified: boolean;
|
|
133
192
|
min_liquidity_usd?: number;
|
|
134
193
|
}
|
|
135
|
-
type WebhookEventType = "payment_intent.created" | "payment_intent.quoted" | "payment_intent.executing" | "payment_intent.executed" | "payment_intent.settled" | "payment_intent.failed" | "payment_intent.expired" | "payment_intent.cancelled" | "payment_intent.refunded" | "quote.created" | "settlement.confirmed" | "payout.
|
|
194
|
+
type WebhookEventType = "payment_intent.created" | "payment_intent.quoted" | "payment_intent.executing" | "payment_intent.executed" | "payment_intent.settled" | "payment_intent.failed" | "payment_intent.expired" | "payment_intent.cancelled" | "payment_intent.refunded" | "quote.created" | "settlement.confirmed" | "payout.created" | "payout.paid" | "payout.failed" | "refund.created" | "refund.processing" | "refund.paid" | "refund.failed";
|
|
136
195
|
interface WebhookEvent<T = unknown> {
|
|
137
196
|
id: string;
|
|
138
197
|
type: WebhookEventType;
|
|
@@ -160,6 +219,7 @@ declare class FragError extends Error {
|
|
|
160
219
|
type Requester = <T>(path: string, init?: RequestInit & {
|
|
161
220
|
idempotencyKey?: string;
|
|
162
221
|
query?: Record<string, string | number | boolean | undefined>;
|
|
222
|
+
skipAuth?: boolean;
|
|
163
223
|
}) => Promise<T>;
|
|
164
224
|
declare class FragmentPay {
|
|
165
225
|
#private;
|
|
@@ -169,7 +229,23 @@ declare class FragmentPay {
|
|
|
169
229
|
readonly webhookEndpoints: WebhookEndpointResource;
|
|
170
230
|
readonly webhooks: WebhookHelpers;
|
|
171
231
|
readonly tokens: TokenResource;
|
|
232
|
+
readonly checkout: PublicCheckoutResource;
|
|
172
233
|
constructor(opts: FragOptions);
|
|
234
|
+
/**
|
|
235
|
+
* Unauthenticated health probe against the API host. Safe to call from
|
|
236
|
+
* uptime monitors and CI. Returns `{ status: "ok" | "degraded" | "down", ... }`.
|
|
237
|
+
*/
|
|
238
|
+
health(): Promise<{
|
|
239
|
+
status: "ok" | "degraded" | "down";
|
|
240
|
+
service: string;
|
|
241
|
+
version: string;
|
|
242
|
+
time: string;
|
|
243
|
+
latency_ms: number;
|
|
244
|
+
checks: {
|
|
245
|
+
env: Record<string, boolean>;
|
|
246
|
+
database: "ok" | "degraded" | "down";
|
|
247
|
+
};
|
|
248
|
+
}>;
|
|
173
249
|
setDebug(on: boolean): void;
|
|
174
250
|
}
|
|
175
251
|
declare class PaymentIntentResource {
|
|
@@ -201,17 +277,54 @@ declare class RefundResource {
|
|
|
201
277
|
create(input: {
|
|
202
278
|
paymentIntentId: string;
|
|
203
279
|
amountUsd: number;
|
|
204
|
-
|
|
280
|
+
/**
|
|
281
|
+
* Payer address to refund to. Optional — omit to let Frag auto-fill from
|
|
282
|
+
* the intent's confirmed payer leg(s). If no payer address can be derived
|
|
283
|
+
* the refund is created in `pending` with `failure_reason: "missing_destination"`
|
|
284
|
+
* until the merchant provides one from the dashboard.
|
|
285
|
+
*/
|
|
286
|
+
destination?: string;
|
|
205
287
|
reason?: string;
|
|
206
288
|
idempotencyKey?: string;
|
|
207
289
|
}): Promise<Refund>;
|
|
208
290
|
retrieve(id: string): Promise<Refund>;
|
|
209
291
|
list(params?: {
|
|
210
292
|
paymentIntentId?: string;
|
|
293
|
+
status?: RefundStatus;
|
|
211
294
|
limit?: number;
|
|
212
295
|
}): Promise<{
|
|
213
296
|
data: Refund[];
|
|
214
297
|
}>;
|
|
298
|
+
/**
|
|
299
|
+
* Fetch the payer-facing safe status view for a refund. UNAUTHENTICATED —
|
|
300
|
+
* safe to expose in a customer-facing page or email. Redacts the destination
|
|
301
|
+
* address (only the last 6 chars) and omits merchant PII. The returned
|
|
302
|
+
* `phase` field is a stable 4-bucket categorization
|
|
303
|
+
* (`queued | sent | completed | failed`) computed on the client for
|
|
304
|
+
* convenient status pills.
|
|
305
|
+
*/
|
|
306
|
+
status(id: string): Promise<PublicRefundStatus>;
|
|
307
|
+
/** Client-side helper: bucket a raw {@link RefundStatus} to a UI phase. */
|
|
308
|
+
phase(status: RefundStatus | string | null | undefined): RefundPhase;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Unauthenticated public checkout view used by hosted checkout pages and the
|
|
312
|
+
* @fragmentpay/react polling hook. Exposes only non-PII fields — no merchant
|
|
313
|
+
* data, no keys, no idempotency records. Rate-limited to 120 req/min per IP.
|
|
314
|
+
*/
|
|
315
|
+
declare class PublicCheckoutResource {
|
|
316
|
+
private req;
|
|
317
|
+
constructor(req: Requester);
|
|
318
|
+
retrieve(id: string): Promise<{
|
|
319
|
+
id: string;
|
|
320
|
+
amount: string;
|
|
321
|
+
currency: string;
|
|
322
|
+
status: IntentStatus;
|
|
323
|
+
settlement_chain: string | null;
|
|
324
|
+
settlement_token: string | null;
|
|
325
|
+
expires_at: string;
|
|
326
|
+
metadata?: Record<string, unknown>;
|
|
327
|
+
}>;
|
|
215
328
|
}
|
|
216
329
|
declare class PayoutResource {
|
|
217
330
|
private req;
|
|
@@ -283,4 +396,4 @@ declare class Frag extends FragmentPay {
|
|
|
283
396
|
});
|
|
284
397
|
}
|
|
285
398
|
|
|
286
|
-
export { type Chain, type CreateIntentInput, Frag, FragError, type FragOptions, type FragToken, FragValidationError, FragmentPay, type IntentStatus, type IntentTransaction, type PaymentIntent, type Payout, type PayoutStatus, type Refund, type RefundStatus, type RouteCandidate, type Settlement, type VerifyWebhookInput, type WebhookEndpoint, type WebhookEvent, type WebhookEventType, verifyWebhook };
|
|
399
|
+
export { type Chain, type CreateIntentInput, Frag, FragError, type FragOptions, type FragToken, FragValidationError, FragmentPay, type IntentStatus, type IntentTransaction, type PaymentIntent, type Payout, type PayoutStatus, type PublicRefundStatus, type Refund, type RefundPhase, type RefundStatus, type RouteCandidate, type Settlement, type VerifyWebhookInput, type WebhookEndpoint, type WebhookEvent, type WebhookEventType, refundPhase, verifyWebhook };
|