@genesis-tech/genesispay-seller 0.12.0 → 0.13.1
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/CHANGELOG.md +45 -0
- package/README.md +89 -10
- package/package.json +1 -1
- package/dist/client.d.ts +0 -283
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -575
- package/dist/client.js.map +0 -1
- package/dist/customers.d.ts +0 -41
- package/dist/customers.d.ts.map +0 -1
- package/dist/customers.js +0 -76
- package/dist/customers.js.map +0 -1
- package/dist/entitlements.d.ts +0 -19
- package/dist/entitlements.d.ts.map +0 -1
- package/dist/entitlements.js +0 -30
- package/dist/entitlements.js.map +0 -1
- package/dist/errors.d.ts +0 -63
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -162
- package/dist/errors.js.map +0 -1
- package/dist/genesispay-settlement.d.ts +0 -30
- package/dist/genesispay-settlement.d.ts.map +0 -1
- package/dist/genesispay-settlement.js +0 -103
- package/dist/genesispay-settlement.js.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -13
- package/dist/index.js.map +0 -1
- package/dist/invoices.d.ts +0 -80
- package/dist/invoices.d.ts.map +0 -1
- package/dist/invoices.js +0 -133
- package/dist/invoices.js.map +0 -1
- package/dist/mandate-gate.d.ts +0 -49
- package/dist/mandate-gate.d.ts.map +0 -1
- package/dist/mandate-gate.js +0 -109
- package/dist/mandate-gate.js.map +0 -1
- package/dist/mandates.d.ts +0 -172
- package/dist/mandates.d.ts.map +0 -1
- package/dist/mandates.js +0 -213
- package/dist/mandates.js.map +0 -1
- package/dist/networks.d.ts +0 -10
- package/dist/networks.d.ts.map +0 -1
- package/dist/networks.js +0 -22
- package/dist/networks.js.map +0 -1
- package/dist/payment-gate.d.ts +0 -67
- package/dist/payment-gate.d.ts.map +0 -1
- package/dist/payment-gate.js +0 -106
- package/dist/payment-gate.js.map +0 -1
- package/dist/plans.d.ts +0 -68
- package/dist/plans.d.ts.map +0 -1
- package/dist/plans.js +0 -127
- package/dist/plans.js.map +0 -1
- package/dist/products.d.ts +0 -146
- package/dist/products.d.ts.map +0 -1
- package/dist/products.js +0 -295
- package/dist/products.js.map +0 -1
- package/dist/resource.d.ts +0 -47
- package/dist/resource.d.ts.map +0 -1
- package/dist/resource.js +0 -71
- package/dist/resource.js.map +0 -1
- package/dist/usdc-amount.d.ts +0 -7
- package/dist/usdc-amount.d.ts.map +0 -1
- package/dist/usdc-amount.js +0 -21
- package/dist/usdc-amount.js.map +0 -1
- package/dist/webhooks.d.ts +0 -277
- package/dist/webhooks.d.ts.map +0 -1
- package/dist/webhooks.js +0 -224
- package/dist/webhooks.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.13.0 — checkout return parameters and fulfilment DX
|
|
4
|
+
|
|
5
|
+
Additive. Exports the return-parameter constants and a hint parser, and adds
|
|
6
|
+
local redirect-URL validation to `checkout.create`. No removed or changed
|
|
7
|
+
behaviour; the server stays the authoritative backstop for raw HTTP clients.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **`CHECKOUT_RETURN_LINK_ID_PARAM` / `CHECKOUT_RETURN_STATUS_PARAM`** — the exact
|
|
12
|
+
query-parameter names (`genesispay_link_id` / `genesispay_status`) the hosted
|
|
13
|
+
checkout appends to a merchant's `returnUrl`. Exported so a merchant can build
|
|
14
|
+
or match the return URL without hardcoding the names.
|
|
15
|
+
- **`parseCheckoutReturnHint(url: string | URL): CheckoutReturnHint | null`** and the
|
|
16
|
+
**`CheckoutReturnHint`** type (`{ linkId, status: "paid" }`). Returns a hint only
|
|
17
|
+
when the URL carries a non-empty `genesispay_link_id` and an exact
|
|
18
|
+
`genesispay_status=paid`; a missing id, an unknown status, or an unparseable URL
|
|
19
|
+
returns `null`. It performs **no verification** — the parameters are unsigned,
|
|
20
|
+
so gate fulfilment on `checkout.retrieve(hint.linkId)` or a webhook, never on
|
|
21
|
+
the hint itself.
|
|
22
|
+
|
|
23
|
+
### Behaviour changes
|
|
24
|
+
|
|
25
|
+
- `checkout.create` now validates `returnUrl` and `cancelUrl` **locally** before
|
|
26
|
+
the request is sent: each field is trimmed (a blank field is dropped), capped at
|
|
27
|
+
2,048 characters, and must be `https` (`http` is accepted only for the exact
|
|
28
|
+
loopback hosts `localhost` and `127.0.0.1`). A `javascript:`/`data:` value, a
|
|
29
|
+
remote `http` host, or a deceptive `localhost.example` name throws
|
|
30
|
+
`GenesisPayValidationError` with one `issues` entry per offending field, and no
|
|
31
|
+
network request is made. The fields stay typed `string`; the server's own
|
|
32
|
+
validation is unchanged and remains authoritative for non-SDK callers.
|
|
33
|
+
|
|
34
|
+
### Documentation
|
|
35
|
+
|
|
36
|
+
- The unsigned-return-parameter warning moved beside the SDK quick start, with a
|
|
37
|
+
parse-hint → authenticated `checkout.retrieve()` → idempotent-action example.
|
|
38
|
+
- New fulfilment guide (per product: what to fulfil on and how to dedupe), a note
|
|
39
|
+
that the `cs` query parameter is internal payer session identity rather than
|
|
40
|
+
merchant correlation, and the exact correlation echo contract for `metadata`
|
|
41
|
+
and `clientReferenceId`.
|
|
42
|
+
|
|
43
|
+
### Requirements
|
|
44
|
+
|
|
45
|
+
- None. Works against any backend; a server predating this release simply sees
|
|
46
|
+
the same validated values it would have received anyway.
|
|
47
|
+
|
|
3
48
|
## 0.12.0 — permanent product checkout permalinks
|
|
4
49
|
|
|
5
50
|
### Added
|
package/README.md
CHANGED
|
@@ -56,6 +56,52 @@ export const GET = genesispay.gate({ amountUsdc: "0.02" }).wrap(
|
|
|
56
56
|
);
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
### Return URL — parse the hint, then verify
|
|
60
|
+
|
|
61
|
+
When you pass `returnUrl` to `checkout.create`, the hosted checkout shows a
|
|
62
|
+
"Return to …" button and appends
|
|
63
|
+
`?genesispay_link_id=<publicId>&genesispay_status=paid` only when the payer
|
|
64
|
+
selects it — there is no timed auto-redirect. Those parameters are a **UI hint
|
|
65
|
+
only**: they are unsigned, and a payer can navigate to that URL directly without
|
|
66
|
+
paying. **Never fulfil on the query string**; use webhooks as the reliable
|
|
67
|
+
delivery path.
|
|
68
|
+
|
|
69
|
+
Use `parseCheckoutReturnHint` to read the hint, then confirm with an
|
|
70
|
+
**authenticated** `checkout.retrieve()` before fulfilling:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { parseCheckoutReturnHint } from "@genesis-tech/genesispay-seller";
|
|
74
|
+
|
|
75
|
+
export async function GET(request: Request) {
|
|
76
|
+
const hint = parseCheckoutReturnHint(new URL(request.url));
|
|
77
|
+
if (!hint) return Response.json({ ok: true }); // no return params — nothing to do
|
|
78
|
+
|
|
79
|
+
// hint.linkId is the link's publicId. Verify with your seller key, not the URL.
|
|
80
|
+
const session = await genesispay.checkout.retrieve(hint.linkId);
|
|
81
|
+
|
|
82
|
+
// Only single-use links are fulfilled here. A reusable link's "paid" means
|
|
83
|
+
// "ever paid"; fulfil those on a payment.confirmed webhook keyed by attempt.id.
|
|
84
|
+
if (session.linkType !== "single") return Response.json({ ok: true });
|
|
85
|
+
|
|
86
|
+
// Single-use link: fulfil once, keyed by the link itself.
|
|
87
|
+
if (session.paid) await fulfilOnce(hint.linkId);
|
|
88
|
+
|
|
89
|
+
return Response.json({ ok: true });
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`parseCheckoutReturnHint(url)` returns `{ linkId, status: "paid" }` only when the
|
|
94
|
+
URL carries a non-empty `genesispay_link_id` and an exact `genesispay_status=paid`.
|
|
95
|
+
Anything else — a missing id, an unknown status like `refunded`, a hand-built URL
|
|
96
|
+
— returns `null`. It performs **no verification**: treat it as a prompt to look
|
|
97
|
+
the link up with your key, never as a receipt.
|
|
98
|
+
|
|
99
|
+
This pattern fulfils a **single-use** link, keyed by `hint.linkId` (the link's
|
|
100
|
+
`publicId`) and refuses any other `linkType`. For a **reusable** link, `paid`
|
|
101
|
+
means "ever paid" and the return URL cannot say which payment triggered it —
|
|
102
|
+
fulfil those on verified `payment.confirmed` webhooks keyed by `attempt.id` (see
|
|
103
|
+
the fulfilment guide below).
|
|
104
|
+
|
|
59
105
|
### Amounts and settlement
|
|
60
106
|
|
|
61
107
|
During the beta, every new hosted checkout link settles in **USDC on Base**. An
|
|
@@ -292,8 +338,9 @@ migration) the new link gets a new `inv_…`, and every hardcoded copy of the ol
|
|
|
292
338
|
`link.payUrl` — a button in your shop, a page in your docs, an email template —
|
|
293
339
|
silently breaks.
|
|
294
340
|
|
|
295
|
-
Store the **product's** `publicId` (`prod_…`) instead; it never changes.
|
|
296
|
-
|
|
341
|
+
Store the **product's** `publicId` (`prod_…`) instead; it never changes. Because
|
|
342
|
+
the permanent URL is deterministic (`{baseUrl}/pay/p/{publicId}`), derive it at
|
|
343
|
+
render time — don't store the URL itself in a config file or env var. Then either:
|
|
297
344
|
|
|
298
345
|
- build the permanent URL — `genesispay.products.permalink(product.publicId)`
|
|
299
346
|
returns `{baseUrl}/pay/p/{publicId}`: pure string builder, no network call,
|
|
@@ -395,13 +442,42 @@ endpoint does not exist at all. The resulting attempt has `txHash: null` (no
|
|
|
395
442
|
transaction happened) and `simulated: true`; branch on that flag rather than on
|
|
396
443
|
the missing hash, because a *pending real* attempt has no hash either.
|
|
397
444
|
|
|
398
|
-
###
|
|
445
|
+
### Fulfilment guide
|
|
446
|
+
|
|
447
|
+
GenesisPay reports payment truth as **confirmed attempts**; it cannot know whether
|
|
448
|
+
*your* action — shipping, unlocking, granting access — actually succeeded, so
|
|
449
|
+
there is deliberately no `fulfilled` field on the SDK or the API. Fulfilment is
|
|
450
|
+
merchant-owned. Key each fulfilment idempotently so a webhook retry or a repeated
|
|
451
|
+
handler run never double-delivers.
|
|
452
|
+
|
|
453
|
+
| Product | Fulfil on | Deduplicate by |
|
|
454
|
+
|---|---|---|
|
|
455
|
+
| Standalone single-use checkout | a verified `payment.confirmed` webhook, or an authenticated `checkout.retrieve()` | the link `publicId` (fulfil once per link) |
|
|
456
|
+
| Standalone reusable checkout | each verified `payment.confirmed` attempt | `attempt.id` — never the link-level `paid`, which means "ever paid" |
|
|
457
|
+
| Redirect product | a verified, non-simulated entitlement (see Products) | the entitlement `publicId` |
|
|
458
|
+
| Product-backed gate | the confirmed purchase inside `protect` | `purchase.payment.attemptId` |
|
|
459
|
+
|
|
460
|
+
Webhook deliveries are retried (up to three attempts, stable `event.id`), and a
|
|
461
|
+
single-use link emits both `payment.confirmed` and `link.paid` for one settlement —
|
|
462
|
+
dedupe on `event.id`, and branch on `event.type` so you fulfil once (see
|
|
463
|
+
Webhooks above).
|
|
464
|
+
|
|
465
|
+
### Correlation, and the `cs` query parameter
|
|
466
|
+
|
|
467
|
+
The hosted checkout may carry a `cs` query parameter. That is GenesisPay's
|
|
468
|
+
**internal payer checkout-session identity**, not a merchant correlation field —
|
|
469
|
+
do not read it or rely on it. To correlate a payment back to your own records,
|
|
470
|
+
send `clientReferenceId` and `metadata` on `checkout.create`; both are echoed back
|
|
471
|
+
to you.
|
|
472
|
+
|
|
473
|
+
The echo contract is exact:
|
|
399
474
|
|
|
400
|
-
|
|
401
|
-
`
|
|
402
|
-
|
|
403
|
-
`
|
|
404
|
-
|
|
475
|
+
- Non-empty `metadata` keys and values round-trip **unchanged** on `create`,
|
|
476
|
+
`retrieve`, and the payment-link webhook payloads.
|
|
477
|
+
- An empty `metadata` object is normalised to `null`.
|
|
478
|
+
- `clientReferenceId` is **trimmed**; a blank value is normalised to `null`.
|
|
479
|
+
- Both appear on `create`/`retrieve` responses and on the `payment.confirmed` /
|
|
480
|
+
`link.paid` webhook payloads.
|
|
405
481
|
|
|
406
482
|
### Limits
|
|
407
483
|
|
|
@@ -409,9 +485,12 @@ query string.
|
|
|
409
485
|
|---|---|
|
|
410
486
|
| `metadata` | 20 keys; keys ≤ 40 chars; values must be strings, ≤ 500 chars; ≤ 4096 bytes serialized |
|
|
411
487
|
| `clientReferenceId` | ≤ 200 chars |
|
|
412
|
-
| `returnUrl` / `cancelUrl` | ≤ 2048 chars, `https` only (`http` allowed for localhost) |
|
|
488
|
+
| `returnUrl` / `cancelUrl` | ≤ 2048 chars, `https` only (`http` allowed for `localhost` / `127.0.0.1`) |
|
|
413
489
|
|
|
414
|
-
|
|
490
|
+
The `returnUrl`/`cancelUrl` limits and the amount-conflict check are validated
|
|
491
|
+
**locally** and throw `GenesisPayValidationError` before any request is sent. The
|
|
492
|
+
remaining limits (`metadata`, `clientReferenceId`) are enforced server-side and
|
|
493
|
+
fail the `checkout.create` call with a 422.
|
|
415
494
|
|
|
416
495
|
### Note on `paid` for reusable links
|
|
417
496
|
|
package/package.json
CHANGED
package/dist/client.d.ts
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import type { MandatesResource } from "./mandates.js";
|
|
2
|
-
import type { CustomersResource } from "./customers.js";
|
|
3
|
-
import type { InvoicesResource } from "./invoices.js";
|
|
4
|
-
import type { VerifySettlement } from "./payment-gate.js";
|
|
5
|
-
import type { PlansResource } from "./plans.js";
|
|
6
|
-
import type { ProductsResource } from "./products.js";
|
|
7
|
-
import type { EntitlementsResource } from "./entitlements.js";
|
|
8
|
-
import type { PaymentGateNetwork } from "./networks.js";
|
|
9
|
-
import type { ConstructEventOptions, GenesisPayEvent } from "./webhooks.js";
|
|
10
|
-
/**
|
|
11
|
-
* The legacy `GenesisPay` client — a Stripe-like entry point that owns the seller key and
|
|
12
|
-
* resolves everything else (payout wallet, network, base URL) from it. The key
|
|
13
|
-
* prefix decides the mode: `gp_sk_test_…` / legacy `gp_sk_…` → test,
|
|
14
|
-
* `gp_sk_live_…` → live. See docs/archive/SELLER_SDK_DX_SPEC.md.
|
|
15
|
-
*/
|
|
16
|
-
export type GenesisPayKeyMode = "test" | "live";
|
|
17
|
-
export type GenesisPayClientOptions = {
|
|
18
|
-
/** gp_sk_test_… | gp_sk_live_… | legacy gp_sk_… — the only required field. */
|
|
19
|
-
apiKey: string;
|
|
20
|
-
/** Overrides the mode→URL default (self-host / staging). Must be https (http only for localhost). */
|
|
21
|
-
baseUrl?: string;
|
|
22
|
-
/** Injectable fetch for tests. Defaults to the global fetch. */
|
|
23
|
-
fetchFn?: typeof fetch;
|
|
24
|
-
/** Seller-config cache TTL. Default 5 min. */
|
|
25
|
-
configTtlMs?: number;
|
|
26
|
-
/** Optional local pin on the resolved payout wallet; recommended for live keys. */
|
|
27
|
-
expectedPayTo?: string;
|
|
28
|
-
};
|
|
29
|
-
export type SellerConfig = {
|
|
30
|
-
id: string;
|
|
31
|
-
mode: GenesisPayKeyMode;
|
|
32
|
-
payTo: string | null;
|
|
33
|
-
hasPayTo: boolean;
|
|
34
|
-
network: {
|
|
35
|
-
networkName: PaymentGateNetwork;
|
|
36
|
-
chainId: number;
|
|
37
|
-
usdcAddress: string;
|
|
38
|
-
asset: "USDC";
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* The amount half of {@link CheckoutCreateInput}, as a union so that **one of
|
|
43
|
-
* the two names is always required at compile time** — `amountUsdc` was a
|
|
44
|
-
* required property before 0.6.0, and losing that to two optional fields would
|
|
45
|
-
* have turned a type error into a runtime one.
|
|
46
|
-
*/
|
|
47
|
-
export type CheckoutAmountInput = {
|
|
48
|
-
/**
|
|
49
|
-
* Decimal amount **in `asset`** — `"5.00"`, at most 6 decimals, always a
|
|
50
|
-
* string (a float would lose minor units). Hosted checkout links settle
|
|
51
|
-
* in USDC during the beta, so the amount is in dollars.
|
|
52
|
-
*
|
|
53
|
-
* Passing the deprecated `amountUsdc` alongside it is allowed only when
|
|
54
|
-
* both are the same amount; two different values throw
|
|
55
|
-
* `GenesisPayValidationError` before the request.
|
|
56
|
-
*/
|
|
57
|
-
amount: string;
|
|
58
|
-
/** @deprecated Use `amount` alone. */
|
|
59
|
-
amountUsdc?: string;
|
|
60
|
-
} | {
|
|
61
|
-
amount?: string;
|
|
62
|
-
/**
|
|
63
|
-
* @deprecated Renamed to `amount` in 0.6.0. The name claimed a currency
|
|
64
|
-
* the value did not always have. Still accepted, and still sent on the wire for backends older than
|
|
65
|
-
* 0.6.0 — but new code should set `amount`.
|
|
66
|
-
*/
|
|
67
|
-
amountUsdc: string;
|
|
68
|
-
};
|
|
69
|
-
export type CheckoutCreateInput = CheckoutAmountInput & {
|
|
70
|
-
title: string;
|
|
71
|
-
description?: string;
|
|
72
|
-
linkType?: "single" | "reusable";
|
|
73
|
-
destinationWallet?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Hosted checkout links settle in USDC during the beta. Omit this field in
|
|
76
|
-
* new integrations; it is kept only to make the invariant explicit in the
|
|
77
|
-
* request type.
|
|
78
|
-
*/
|
|
79
|
-
asset?: "USDC";
|
|
80
|
-
/** Free-form correlation data; echoed back in webhooks and `checkout.retrieve()`. */
|
|
81
|
-
metadata?: Record<string, string>;
|
|
82
|
-
/** The merchant's own reference (Stripe: client_reference_id). */
|
|
83
|
-
clientReferenceId?: string;
|
|
84
|
-
/** Where the payer returns after a successful payment (https). */
|
|
85
|
-
returnUrl?: string;
|
|
86
|
-
/** Where the payer returns when they cancel (https). */
|
|
87
|
-
cancelUrl?: string;
|
|
88
|
-
};
|
|
89
|
-
export type CheckoutLink = {
|
|
90
|
-
publicId: string;
|
|
91
|
-
payUrl: string;
|
|
92
|
-
/** Decimal amount in `asset`, as the server normalized it (e.g. `"5.00"`). */
|
|
93
|
-
amount: string;
|
|
94
|
-
/** @deprecated Same value as {@link CheckoutLink.amount}; see the input field. */
|
|
95
|
-
amountUsdc: string;
|
|
96
|
-
/**
|
|
97
|
-
* The currency `amount` is denominated in. Echoed back on create so a EURC
|
|
98
|
-
* link can be confirmed as one without a second round-trip.
|
|
99
|
-
*/
|
|
100
|
-
asset: "USDC" | "EURC";
|
|
101
|
-
title: string;
|
|
102
|
-
metadata: Record<string, string> | null;
|
|
103
|
-
clientReferenceId: string | null;
|
|
104
|
-
returnUrl: string | null;
|
|
105
|
-
cancelUrl: string | null;
|
|
106
|
-
};
|
|
107
|
-
/** Lifecycle of a single payment attempt on a link, as the server reports it. */
|
|
108
|
-
export type CheckoutAttemptStatus = "pending" | "submitted" | "confirmed" | "failed" | "expired";
|
|
109
|
-
/**
|
|
110
|
-
* One payment attempt against a checkout link — the receipt data (`txHash`,
|
|
111
|
-
* `payerWallet`) that `paid === true` alone cannot give you.
|
|
112
|
-
*
|
|
113
|
-
* A `reusable` link accumulates attempts; the newest comes first. `txHash` is
|
|
114
|
-
* null while an attempt is still pending, and stays null for attempts created
|
|
115
|
-
* by the test-mode `simulate-payment` endpoint (no transaction exists).
|
|
116
|
-
*/
|
|
117
|
-
export type CheckoutAttempt = {
|
|
118
|
-
id: string;
|
|
119
|
-
status: CheckoutAttemptStatus;
|
|
120
|
-
txHash: string | null;
|
|
121
|
-
payerWallet: string | null;
|
|
122
|
-
createdAt: string;
|
|
123
|
-
confirmedAt: string | null;
|
|
124
|
-
failureReason: string | null;
|
|
125
|
-
/**
|
|
126
|
-
* True when no funds moved — an attempt created by
|
|
127
|
-
* `checkout.simulatePayment`. Note that such an attempt also has
|
|
128
|
-
* `txHash: null` — but so does a pending real one, which is why this flag
|
|
129
|
-
* exists rather than inferring it.
|
|
130
|
-
*
|
|
131
|
-
* `false` for a real settlement, including on testnet and in provider
|
|
132
|
-
* sandboxes: this is the fabricated-payment axis, not the environment axis.
|
|
133
|
-
*
|
|
134
|
-
* Defaults to `false` against a backend that does not report it.
|
|
135
|
-
*/
|
|
136
|
-
simulated: boolean;
|
|
137
|
-
};
|
|
138
|
-
export type CheckoutSession = CheckoutLink & {
|
|
139
|
-
description: string | null;
|
|
140
|
-
linkType: "single" | "reusable";
|
|
141
|
-
status: "active" | "paid" | "archived";
|
|
142
|
-
destinationWallet: string;
|
|
143
|
-
chainId: number;
|
|
144
|
-
/**
|
|
145
|
-
* true as soon as at least one payment is confirmed — the value to poll on.
|
|
146
|
-
*
|
|
147
|
-
* For a `reusable` link this answers "has this link ever been paid", not "has
|
|
148
|
-
* this buyer paid": `confirmedPaymentCount` only grows, so `paid` stays true
|
|
149
|
-
* from the first payment onward. Per-buyer fulfilment on a reusable link needs
|
|
150
|
-
* a webhook, or `confirmedPaymentCount` tracked as a delta.
|
|
151
|
-
*/
|
|
152
|
-
paid: boolean;
|
|
153
|
-
confirmedPaymentCount: number;
|
|
154
|
-
createdAt: string;
|
|
155
|
-
/**
|
|
156
|
-
* Payment attempts for this link, newest first — empty when the server does
|
|
157
|
-
* not report them (older backend) or when nobody has tried to pay yet.
|
|
158
|
-
*/
|
|
159
|
-
attempts: CheckoutAttempt[];
|
|
160
|
-
};
|
|
161
|
-
export type SimulatePaymentOptions = {
|
|
162
|
-
/**
|
|
163
|
-
* Payer address recorded on the simulated attempt. Defaults to a deliberately
|
|
164
|
-
* synthetic server-side placeholder, so nobody mistakes a simulated payment
|
|
165
|
-
* for a real payer in a dashboard or an export.
|
|
166
|
-
*/
|
|
167
|
-
payerWallet?: string;
|
|
168
|
-
};
|
|
169
|
-
export type GateConfig = {
|
|
170
|
-
amountUsdc: string;
|
|
171
|
-
description?: string;
|
|
172
|
-
resource?: string;
|
|
173
|
-
mimeType?: string;
|
|
174
|
-
maxTimeoutSeconds?: number;
|
|
175
|
-
};
|
|
176
|
-
type GateHandler<Args extends unknown[]> = (request: Request, ...args: Args) => Response | Promise<Response>;
|
|
177
|
-
export interface ResolvingGate {
|
|
178
|
-
wrap<Args extends unknown[]>(handler: GateHandler<Args>, opts?: {
|
|
179
|
-
verifySettlement?: VerifySettlement;
|
|
180
|
-
}): (request: Request, ...args: Args) => Promise<Response>;
|
|
181
|
-
/** Warm the seller-config cache (and surface auth/wallet errors) before traffic. */
|
|
182
|
-
prime(): Promise<void>;
|
|
183
|
-
}
|
|
184
|
-
export { GenesisPayConfigError, GenesisPayNetworkSafetyError, GenesisPayNotFoundError, GenesisPayRateLimitError, GenesisPayValidationError, type GenesisPayValidationIssue, } from "./errors.js";
|
|
185
|
-
export declare class GenesisPay {
|
|
186
|
-
readonly mode: GenesisPayKeyMode;
|
|
187
|
-
readonly baseUrl: string;
|
|
188
|
-
readonly checkout: {
|
|
189
|
-
create(input: CheckoutCreateInput): Promise<CheckoutLink>;
|
|
190
|
-
retrieve(publicId: string): Promise<CheckoutSession>;
|
|
191
|
-
/**
|
|
192
|
-
* Test mode only: records a confirmed payment on one of your links without
|
|
193
|
-
* any money moving, and fires the real `payment.confirmed` (plus
|
|
194
|
-
* `link.paid` for a single-use link) webhooks — the point being that you can
|
|
195
|
-
* exercise your webhook handler end to end.
|
|
196
|
-
*
|
|
197
|
-
* The resulting attempt carries `simulated: true` and `txHash: null`; there
|
|
198
|
-
* is no transaction, and a made-up hash would be a lie in a field other
|
|
199
|
-
* systems point a block explorer at.
|
|
200
|
-
*/
|
|
201
|
-
simulatePayment(publicId: string, opts?: SimulatePaymentOptions): Promise<CheckoutSession>;
|
|
202
|
-
};
|
|
203
|
-
/** Subscription plans and their hosted `checkoutUrl` — see ./plans.ts. */
|
|
204
|
-
readonly plans: PlansResource;
|
|
205
|
-
/** The merchant's catalogue and its canonical payment links — see ./products.ts. */
|
|
206
|
-
readonly products: ProductsResource;
|
|
207
|
-
/** Seller-scoped redirect-entitlement verification. */
|
|
208
|
-
readonly entitlements: EntitlementsResource;
|
|
209
|
-
/** Reusable billing contacts for one-off invoices. */
|
|
210
|
-
readonly customers: CustomersResource;
|
|
211
|
-
/** Draft, finalize, deliver, and collect one-off invoices. */
|
|
212
|
-
readonly invoices: InvoicesResource;
|
|
213
|
-
/**
|
|
214
|
-
* Payment mandates: bounded, revocable spending approvals a payer signs once.
|
|
215
|
-
*
|
|
216
|
-
* There is no `mandates.activate` on purpose — activation carries the
|
|
217
|
-
* *payer's* signature, is authorized by their wallet rather than by this API
|
|
218
|
-
* key, and therefore belongs in the payer-facing frontend. See the module
|
|
219
|
-
* comment in ./mandates.ts.
|
|
220
|
-
*/
|
|
221
|
-
readonly mandates: MandatesResource;
|
|
222
|
-
/**
|
|
223
|
-
* Webhook signature verification. Also exported as the free function
|
|
224
|
-
* `constructEvent` — a webhook route rarely has a client instance in scope,
|
|
225
|
-
* and verification needs the endpoint secret rather than the API key.
|
|
226
|
-
*/
|
|
227
|
-
readonly webhooks: {
|
|
228
|
-
constructEvent(rawBody: string | Uint8Array, signatureHeader: string, secret: string, opts?: ConstructEventOptions): Promise<GenesisPayEvent>;
|
|
229
|
-
};
|
|
230
|
-
private readonly apiKey;
|
|
231
|
-
private readonly fetchFn;
|
|
232
|
-
private readonly configTtlMs;
|
|
233
|
-
private readonly expectedPayTo?;
|
|
234
|
-
private cache?;
|
|
235
|
-
private inflight?;
|
|
236
|
-
/**
|
|
237
|
-
* The single authenticated-JSON seam every resource goes through. Bound as a
|
|
238
|
-
* field so it can be handed to `./plans.ts` / `./mandates.ts` without leaking
|
|
239
|
-
* the key, the base URL or `fetch` into them.
|
|
240
|
-
*/
|
|
241
|
-
private readonly request;
|
|
242
|
-
constructor(options: GenesisPayClientOptions);
|
|
243
|
-
/** Raw on purpose: product-gate negotiation must preserve 402 protocol headers. */
|
|
244
|
-
private performProductGateRequest;
|
|
245
|
-
/**
|
|
246
|
-
* Resolve (and cache) the seller config from the key. Single-flight so a
|
|
247
|
-
* cold-start burst shares one request; failures are never cached (the memo is
|
|
248
|
-
* cleared on rejection so the next call retries).
|
|
249
|
-
*/
|
|
250
|
-
retrieveSeller(opts?: {
|
|
251
|
-
forceRefresh?: boolean;
|
|
252
|
-
}): Promise<SellerConfig>;
|
|
253
|
-
gate(config: GateConfig): ResolvingGate;
|
|
254
|
-
private fetchSeller;
|
|
255
|
-
private assertSafe;
|
|
256
|
-
/**
|
|
257
|
-
* Applies the `expectedPayTo` pin to a destination the server just froze onto
|
|
258
|
-
* a newly created object.
|
|
259
|
-
*
|
|
260
|
-
* Checking it in `assertSafe` alone was not enough: that only covers the
|
|
261
|
-
* `/api/v1/seller` config lookup, while a checkout link and a subscription
|
|
262
|
-
* plan each record their own `destinationWallet` at creation. Those are the
|
|
263
|
-
* addresses money actually moves to — a pin that does not cover them is not
|
|
264
|
-
* the guarantee the option advertises.
|
|
265
|
-
*/
|
|
266
|
-
private assertPinnedDestination;
|
|
267
|
-
/**
|
|
268
|
-
* One authenticated JSON round-trip, with the error mapping every method
|
|
269
|
-
* shares. A transport failure (no response at all) is the only case handled
|
|
270
|
-
* here rather than in `throwForErrorResponse`, because there is no status to
|
|
271
|
-
* map — it is always a config/connectivity problem.
|
|
272
|
-
*/
|
|
273
|
-
private performRequest;
|
|
274
|
-
private createCheckout;
|
|
275
|
-
/**
|
|
276
|
-
* Fetch the current state of a checkout link. `paid` is the field to poll on;
|
|
277
|
-
* an unknown publicId raises `GenesisPayNotFoundError`, never a config error.
|
|
278
|
-
*/
|
|
279
|
-
private retrieveCheckout;
|
|
280
|
-
/** Test-mode only — see the doc on `checkout.simulatePayment`. */
|
|
281
|
-
private simulateCheckoutPayment;
|
|
282
|
-
}
|
|
283
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAaxD,OAAO,KAAK,EA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