@0to1pay/server-sdk 3.0.0 → 3.1.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/README.md
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 0to1pay Server SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Accept USDC or USDT directly in a merchant wallet and verify onchain payment before granting access. The hosted beta serves **Base Sepolia USDC, Ethereum Sepolia USDC and TRON Nile USDT**. Install on your Node.js server (22.20.0+).
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
npm install @0to1pay/server-sdk
|
|
6
|
+
npm install @0to1pay/server-sdk
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
npm install ./0to1pay-server-sdk-3.0.0.tgz
|
|
11
|
-
```
|
|
9
|
+
**Build a working checkout.** The [Next.js Base USDC guide](https://0to1pay.com/guides/nextjs-base-usdc) walks through a 0.01 test USDC order, wallet authorization, transfer proof, signed webhook and PostgreSQL access pass. [Open the hosted demo](https://0to1pay.com/demo/base-usdc) · [Download the complete runnable example](https://0to1pay.com/examples/nextjs-base-usdc.zip).
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
[Sign in to the merchant dashboard](https://pay.0to1pay.com/merchant), create a project, and issue a test server key. Use the public API origin `https://api.0to1pay.com` and keep the key in your backend environment.
|
|
14
12
|
|
|
15
13
|
```ts
|
|
16
14
|
import { ZeroToOnePayClient } from '@0to1pay/server-sdk';
|
|
17
15
|
|
|
18
16
|
const client = new ZeroToOnePayClient({
|
|
19
|
-
origin:
|
|
17
|
+
origin: 'https://api.0to1pay.com',
|
|
20
18
|
apiKey: process.env.ZERO_TO_ONE_PAY_API_KEY!,
|
|
21
19
|
});
|
|
22
|
-
const { data } = await client.call('
|
|
20
|
+
const { data } = await client.call('listChainAssets', {});
|
|
21
|
+
const baseUsdc = data.find(asset => asset.network_id === 'eip155:84532' && asset.symbol === 'USDC');
|
|
23
22
|
```
|
|
24
23
|
|
|
24
|
+
For integration tools and coding assistants, start with the [Markdown quickstart](https://0to1pay.com/guides/nextjs-base-usdc.md), [public OpenAPI JSON](https://api.0to1pay.com/openapi.json), [API reference](https://0to1pay.com/docs), and [SDK reference](https://0to1pay.com/sdk).
|
|
25
|
+
|
|
25
26
|
Use `call` for the full merchant API. Use the same idempotency key when retrying a mutation for the same logical request. The client validates requests and responses against the bundled OpenAPI contract. The hosted API also serves the contract at `/openapi.json`. Keep the scoped key on your server and route browser actions through your merchant backend.
|
|
26
27
|
|
|
27
28
|
## Create a stablecoin checkout
|
|
@@ -34,7 +35,7 @@ Use `call` for the full merchant API. Use the same idempotency key when retrying
|
|
|
34
35
|
|
|
35
36
|
Call `listChainAssets` for the assets enabled in the key's environment. The platform can offer a subset of the live combinations. Register a scoped chain connection and its merchant-owned recipient addresses through `createChainConnection` and `registerChainRecipients`. Create a payment using `policy_ref: 'digital_goods_standard_v1'` and a price in `stable:USDC` or `stable:USDT` with scale `6`. Ten USDC uses `{ asset: 'stable:USDC', amount_atomic: '10000000', scale: 6 }`. The atomic amount must be positive and below `2^64`. Every connection in `allowed_connections` must support the selected price denomination.
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
A Sandbox key can discover the test networks enabled on its Platform deployment. Ethereum Sepolia (`eip155:11155111`) and Base Sepolia (`eip155:84532`) offer test USDC, and TRON Nile (`tron:3448148188`) offers test USDT. An empty test asset list means the deployment has no test assets configured. Use a registered test connection, recipient, and webhook endpoint from the same project for a Sandbox checkout.
|
|
38
39
|
|
|
39
40
|
Call `createQuote` with the matching denomination or its registered asset on the selected chain. Then call `createAttempt` with `connection_id` and `quote_id` to read the reserved destination and transfer instructions. Finish checkout with the buyer authorization and signed transaction steps below.
|
|
40
41
|
|
|
@@ -63,9 +64,9 @@ To integrate with billing directly, use a dedicated billing key on your server.
|
|
|
63
64
|
|
|
64
65
|
Use the paid subscription flow to issue a live server key.
|
|
65
66
|
|
|
66
|
-
1. Call `listBillingPlans` and `getBillingSubscription` to read plan terms, available
|
|
67
|
+
1. Call `listBillingPlans` and `getBillingSubscription` to read plan terms, current request usage, and available collection networks. Each collection option identifies its token and network. Ethereum and Base collect USDC, and TRON collects USDT. Test deployments can enable Ethereum Sepolia, Base Sepolia, and TRON Nile.
|
|
67
68
|
2. Call `createBillingInvoice` with a paid `plan_id`, wallet `payer_address` and an opaque `checkout_session_ref`. Choose an offered `network_id` or omit it for the default configured collector.
|
|
68
|
-
3. Sign the invoice intent, call `authorizeBillingInvoice`, then send the
|
|
69
|
+
3. Sign the invoice intent, call `authorizeBillingInvoice`, then send the exact token and amount in the quote on its specified network. TRON wallets sign the intent and transaction claim using the TRON V2 message format. Sign the transaction claim and call `submitBillingInvoice` with the same checkout session. Each mutation uses its own stable idempotency key.
|
|
69
70
|
4. Use `listBillingInvoices` to resume recent invoices and poll `getBillingInvoice` for a single invoice. During `reconciling`, wait for final reconciliation before paying again. An active invoice reflects verified payment and a current prepaid period. An early renewal can be scheduled for the end of the current period.
|
|
70
71
|
5. Call `issueBillingKey` with `body: {}` and a stable idempotency key. Store the returned token on the server.
|
|
71
72
|
|
|
@@ -30,8 +30,8 @@ paths:
|
|
|
30
30
|
tags: [Billing]
|
|
31
31
|
x-required-scope: billing:read
|
|
32
32
|
description: >
|
|
33
|
-
Plan prices, included API requests, and
|
|
34
|
-
|
|
33
|
+
Plan prices, included API requests, and available subscription collection options for USDC on Ethereum or Base and USDT on TRON.
|
|
34
|
+
Paid periods last 30 days.
|
|
35
35
|
responses:
|
|
36
36
|
'200':
|
|
37
37
|
description: Successful scoped billing response.
|
|
@@ -87,10 +87,10 @@ paths:
|
|
|
87
87
|
$ref: '#/components/responses/Unavailable'
|
|
88
88
|
post:
|
|
89
89
|
operationId: createBillingInvoice
|
|
90
|
-
summary: Create a
|
|
90
|
+
summary: Create a stablecoin subscription invoice and payer challenge
|
|
91
91
|
tags: [Billing]
|
|
92
92
|
x-required-scope: billing:write
|
|
93
|
-
description: Select an offered
|
|
93
|
+
description: Select an offered collection network with network_id, or omit it for the configured default. The selected network determines the six-decimal settlement asset. The invoice records the asset, amount and plan terms.
|
|
94
94
|
parameters:
|
|
95
95
|
- $ref: '#/components/parameters/IdempotencyKey'
|
|
96
96
|
requestBody:
|
|
@@ -293,7 +293,7 @@ paths:
|
|
|
293
293
|
description: >
|
|
294
294
|
Live checkout supports Ethereum native USDC and USDT, TRON USDT, and Base native USDC.
|
|
295
295
|
Only configured networks in the caller's environment are returned.
|
|
296
|
-
|
|
296
|
+
Sandbox keys can discover test USDC on Ethereum Sepolia and Base Sepolia and test USDT on TRON Nile when enabled.
|
|
297
297
|
tags: [Connections]
|
|
298
298
|
x-required-scope: payments:read
|
|
299
299
|
responses:
|
|
@@ -1708,11 +1708,11 @@ components:
|
|
|
1708
1708
|
pattern: '^0x[0-9a-fA-F]{64}$'
|
|
1709
1709
|
ChainSelectorId:
|
|
1710
1710
|
type: integer
|
|
1711
|
-
enum: [1, 8453, 84532, 31337, 31339, 728126428, 900003]
|
|
1711
|
+
enum: [1, 8453, 84532, 11155111, 31337, 31339, 728126428, 3448148188, 900003]
|
|
1712
1712
|
description: Supported EVM or TRON chain selector. Use network_id for the network reference.
|
|
1713
1713
|
ChainNetworkId:
|
|
1714
1714
|
type: string
|
|
1715
|
-
pattern: '^(eip155:(1|8453|84532|31337|31339)|tron:(728126428|900003|0x2b6653dc))$'
|
|
1715
|
+
pattern: '^(eip155:(1|8453|84532|11155111|31337|31339)|tron:(728126428|3448148188|900003|0x2b6653dc))$'
|
|
1716
1716
|
description: Decimal TRON identifiers are emitted. The hexadecimal TRON mainnet alias is accepted on connection creation.
|
|
1717
1717
|
ChainFamily:
|
|
1718
1718
|
type: string
|
|
@@ -2733,7 +2733,7 @@ components:
|
|
|
2733
2733
|
type: object
|
|
2734
2734
|
properties:
|
|
2735
2735
|
asset:
|
|
2736
|
-
|
|
2736
|
+
$ref: '#/components/schemas/StableDenomination'
|
|
2737
2737
|
amount_atomic:
|
|
2738
2738
|
type: string
|
|
2739
2739
|
pattern: '^(0|[1-9][0-9]{0,19})$'
|
|
@@ -2750,6 +2750,12 @@ components:
|
|
|
2750
2750
|
$ref: '#/components/schemas/Environment'
|
|
2751
2751
|
price:
|
|
2752
2752
|
$ref: '#/components/schemas/BillingPrice'
|
|
2753
|
+
description: The plan's reference price in USDC.
|
|
2754
|
+
prices:
|
|
2755
|
+
type: array
|
|
2756
|
+
description: Fixed nominal prices in each supported subscription asset. Availability depends on collection_options.
|
|
2757
|
+
items:
|
|
2758
|
+
$ref: '#/components/schemas/BillingPrice'
|
|
2753
2759
|
request_limit:
|
|
2754
2760
|
type: integer
|
|
2755
2761
|
minimum: 1
|
|
@@ -2757,7 +2763,7 @@ components:
|
|
|
2757
2763
|
type: [integer, 'null']
|
|
2758
2764
|
enum: [30, null]
|
|
2759
2765
|
description: The free test plan uses UTC calendar months.
|
|
2760
|
-
required: [plan_id, environment, price, request_limit, period_days]
|
|
2766
|
+
required: [plan_id, environment, price, prices, request_limit, period_days]
|
|
2761
2767
|
additionalProperties: false
|
|
2762
2768
|
BillingPlans:
|
|
2763
2769
|
type: object
|
|
@@ -2768,7 +2774,7 @@ components:
|
|
|
2768
2774
|
$ref: '#/components/schemas/BillingPlan'
|
|
2769
2775
|
collection_options:
|
|
2770
2776
|
type: array
|
|
2771
|
-
description: Currently offered
|
|
2777
|
+
description: Currently offered collection networks and settlement assets with available recipients.
|
|
2772
2778
|
items:
|
|
2773
2779
|
$ref: '#/components/schemas/BillingCollectionOption'
|
|
2774
2780
|
required: [plans]
|
|
@@ -2781,11 +2787,14 @@ components:
|
|
|
2781
2787
|
network_name:
|
|
2782
2788
|
type: string
|
|
2783
2789
|
family:
|
|
2784
|
-
|
|
2785
|
-
|
|
2790
|
+
$ref: '#/components/schemas/ChainFamily'
|
|
2791
|
+
asset:
|
|
2792
|
+
$ref: '#/components/schemas/StableDenomination'
|
|
2793
|
+
scale:
|
|
2794
|
+
const: 6
|
|
2786
2795
|
is_default:
|
|
2787
2796
|
type: boolean
|
|
2788
|
-
required: [network_id, network_name, family, is_default]
|
|
2797
|
+
required: [network_id, network_name, family, asset, scale, is_default]
|
|
2789
2798
|
additionalProperties: false
|
|
2790
2799
|
BillingSubscription:
|
|
2791
2800
|
type: object
|
|
@@ -2824,7 +2833,7 @@ components:
|
|
|
2824
2833
|
$ref: '#/components/schemas/ChainCheckoutSessionRef'
|
|
2825
2834
|
network_id:
|
|
2826
2835
|
$ref: '#/components/schemas/ChainNetworkId'
|
|
2827
|
-
description:
|
|
2836
|
+
description: Collection network offered in BillingPlans. Ethereum and Base settle in USDC, TRON settles in USDT. The default connection is used when omitted.
|
|
2828
2837
|
required: [plan_id, payer_address, checkout_session_ref]
|
|
2829
2838
|
additionalProperties: false
|
|
2830
2839
|
BillingInvoice:
|
|
@@ -2841,6 +2850,8 @@ components:
|
|
|
2841
2850
|
type: string
|
|
2842
2851
|
enum: [pending, reconciling, active, scheduled, expired, revoked]
|
|
2843
2852
|
description: Reconciling means a wallet-authorized invoice still awaits final reconciliation after transaction submission or quote expiry. Resume that invoice and wait before paying another one.
|
|
2853
|
+
price:
|
|
2854
|
+
$ref: '#/components/schemas/BillingPrice'
|
|
2844
2855
|
quote:
|
|
2845
2856
|
$ref: '#/components/schemas/Quote'
|
|
2846
2857
|
intent:
|
|
@@ -2851,7 +2862,7 @@ components:
|
|
|
2851
2862
|
period_end:
|
|
2852
2863
|
type: [string, 'null']
|
|
2853
2864
|
format: date-time
|
|
2854
|
-
required: [invoice_id, plan_id, environment, status, quote, intent, period_start, period_end]
|
|
2865
|
+
required: [invoice_id, plan_id, environment, status, price, quote, intent, period_start, period_end]
|
|
2855
2866
|
additionalProperties: false
|
|
2856
2867
|
BillingInvoiceList:
|
|
2857
2868
|
type: object
|
|
@@ -12,7 +12,7 @@ export interface paths {
|
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* List request plans and subscription prices
|
|
15
|
-
* @description Plan prices, included API requests, and
|
|
15
|
+
* @description Plan prices, included API requests, and available subscription collection options for USDC on Ethereum or Base and USDT on TRON. Paid periods last 30 days.
|
|
16
16
|
*/
|
|
17
17
|
get: operations["listBillingPlans"];
|
|
18
18
|
put?: never;
|
|
@@ -57,8 +57,8 @@ export interface paths {
|
|
|
57
57
|
get: operations["listBillingInvoices"];
|
|
58
58
|
put?: never;
|
|
59
59
|
/**
|
|
60
|
-
* Create a
|
|
61
|
-
* @description Select an offered
|
|
60
|
+
* Create a stablecoin subscription invoice and payer challenge
|
|
61
|
+
* @description Select an offered collection network with network_id, or omit it for the configured default. The selected network determines the six-decimal settlement asset. The invoice records the asset, amount and plan terms.
|
|
62
62
|
*/
|
|
63
63
|
post: operations["createBillingInvoice"];
|
|
64
64
|
delete?: never;
|
|
@@ -182,7 +182,7 @@ export interface paths {
|
|
|
182
182
|
};
|
|
183
183
|
/**
|
|
184
184
|
* List supported USDC and USDT deployments on configured networks
|
|
185
|
-
* @description Live checkout supports Ethereum native USDC and USDT, TRON USDT, and Base native USDC. Only configured networks in the caller's environment are returned.
|
|
185
|
+
* @description Live checkout supports Ethereum native USDC and USDT, TRON USDT, and Base native USDC. Only configured networks in the caller's environment are returned. Sandbox keys can discover test USDC on Ethereum Sepolia and Base Sepolia and test USDT on TRON Nile when enabled.
|
|
186
186
|
*/
|
|
187
187
|
get: operations["listChainAssets"];
|
|
188
188
|
put?: never;
|
|
@@ -787,7 +787,7 @@ export interface components {
|
|
|
787
787
|
* @description Supported EVM or TRON chain selector. Use network_id for the network reference.
|
|
788
788
|
* @enum {integer}
|
|
789
789
|
*/
|
|
790
|
-
ChainSelectorId: 1 | 8453 | 84532 | 31337 | 31339 | 728126428 | 900003;
|
|
790
|
+
ChainSelectorId: 1 | 8453 | 84532 | 11155111 | 31337 | 31339 | 728126428 | 3448148188 | 900003;
|
|
791
791
|
/** @description Decimal TRON identifiers are emitted. The hexadecimal TRON mainnet alias is accepted on connection creation. */
|
|
792
792
|
ChainNetworkId: string;
|
|
793
793
|
/** @enum {string} */
|
|
@@ -1169,8 +1169,7 @@ export interface components {
|
|
|
1169
1169
|
/** @enum {string} */
|
|
1170
1170
|
PaidBillingPlanId: "starter" | "growth" | "scale";
|
|
1171
1171
|
BillingPrice: {
|
|
1172
|
-
|
|
1173
|
-
asset: "stable:USDC";
|
|
1172
|
+
asset: components["schemas"]["StableDenomination"];
|
|
1174
1173
|
amount_atomic: string;
|
|
1175
1174
|
/** @constant */
|
|
1176
1175
|
scale: 6;
|
|
@@ -1178,7 +1177,10 @@ export interface components {
|
|
|
1178
1177
|
BillingPlan: {
|
|
1179
1178
|
plan_id: components["schemas"]["BillingPlanId"];
|
|
1180
1179
|
environment: components["schemas"]["Environment"];
|
|
1180
|
+
/** @description The plan's reference price in USDC. */
|
|
1181
1181
|
price: components["schemas"]["BillingPrice"];
|
|
1182
|
+
/** @description Fixed nominal prices in each supported subscription asset. Availability depends on collection_options. */
|
|
1183
|
+
prices: components["schemas"]["BillingPrice"][];
|
|
1182
1184
|
request_limit: number;
|
|
1183
1185
|
/**
|
|
1184
1186
|
* @description The free test plan uses UTC calendar months.
|
|
@@ -1188,14 +1190,16 @@ export interface components {
|
|
|
1188
1190
|
};
|
|
1189
1191
|
BillingPlans: {
|
|
1190
1192
|
plans: components["schemas"]["BillingPlan"][];
|
|
1191
|
-
/** @description Currently offered
|
|
1193
|
+
/** @description Currently offered collection networks and settlement assets with available recipients. */
|
|
1192
1194
|
collection_options?: components["schemas"]["BillingCollectionOption"][];
|
|
1193
1195
|
};
|
|
1194
1196
|
BillingCollectionOption: {
|
|
1195
1197
|
network_id: components["schemas"]["ChainNetworkId"];
|
|
1196
1198
|
network_name: string;
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
+
family: components["schemas"]["ChainFamily"];
|
|
1200
|
+
asset: components["schemas"]["StableDenomination"];
|
|
1201
|
+
/** @constant */
|
|
1202
|
+
scale: 6;
|
|
1199
1203
|
is_default: boolean;
|
|
1200
1204
|
};
|
|
1201
1205
|
BillingSubscription: {
|
|
@@ -1214,7 +1218,7 @@ export interface components {
|
|
|
1214
1218
|
plan_id: components["schemas"]["PaidBillingPlanId"];
|
|
1215
1219
|
payer_address: components["schemas"]["ChainAddress"];
|
|
1216
1220
|
checkout_session_ref: components["schemas"]["ChainCheckoutSessionRef"];
|
|
1217
|
-
/** @description
|
|
1221
|
+
/** @description Collection network offered in BillingPlans. Ethereum and Base settle in USDC, TRON settles in USDT. The default connection is used when omitted. */
|
|
1218
1222
|
network_id?: components["schemas"]["ChainNetworkId"];
|
|
1219
1223
|
};
|
|
1220
1224
|
BillingInvoice: {
|
|
@@ -1227,6 +1231,7 @@ export interface components {
|
|
|
1227
1231
|
* @enum {string}
|
|
1228
1232
|
*/
|
|
1229
1233
|
status: "pending" | "reconciling" | "active" | "scheduled" | "expired" | "revoked";
|
|
1234
|
+
price: components["schemas"]["BillingPrice"];
|
|
1230
1235
|
quote: components["schemas"]["Quote"];
|
|
1231
1236
|
intent: components["schemas"]["ChainIntent"];
|
|
1232
1237
|
/** Format: date-time */
|
|
@@ -4,7 +4,7 @@ const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
|
4
4
|
export function tronRecipientProofMessage(input) {
|
|
5
5
|
const origin = new URL(input.origin);
|
|
6
6
|
const validChain = input.environment === 'live' ? input.chain_id === 728126428 :
|
|
7
|
-
input.environment === 'test' && input.chain_id === 900003;
|
|
7
|
+
input.environment === 'test' && (input.chain_id === 900003 || input.chain_id === 3448148188);
|
|
8
8
|
if (!validChain || !['https:', 'http:'].includes(origin.protocol) || origin.origin !== input.origin ||
|
|
9
9
|
![input.merchant_id, input.project_id, input.connection_id].every(value => uuid.test(value)) || !address.test(input.address)) {
|
|
10
10
|
throw new Error('INVALID_TRON_RECIPIENT_PROOF_SCOPE');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0to1pay/server-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Server-only 0to1Pay client for direct on-chain stablecoin checkout and fulfillment",
|
|
@@ -30,5 +30,17 @@
|
|
|
30
30
|
"ajv": "8.20.0",
|
|
31
31
|
"ajv-formats": "3.0.1",
|
|
32
32
|
"yaml": "2.9.1"
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://0to1pay.com/sdk",
|
|
35
|
+
"keywords": [
|
|
36
|
+
"stablecoin-payments",
|
|
37
|
+
"usdc",
|
|
38
|
+
"usdt",
|
|
39
|
+
"base",
|
|
40
|
+
"ethereum",
|
|
41
|
+
"tron",
|
|
42
|
+
"nextjs",
|
|
43
|
+
"webhooks",
|
|
44
|
+
"checkout"
|
|
45
|
+
]
|
|
34
46
|
}
|