@0to1pay/server-sdk 2.1.0 → 2.3.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 CHANGED
@@ -3,14 +3,14 @@
3
3
  Node.js 22.20.0 or newer. Install the SDK from npm after publication or use the verified tarball in your merchant backend.
4
4
 
5
5
  ```sh
6
- npm install @0to1pay/server-sdk@2.1.0
6
+ npm install @0to1pay/server-sdk@2.3.0
7
7
  ```
8
8
 
9
9
  ```sh
10
- npm install ./0to1pay-server-sdk-2.1.0.tgz
10
+ npm install ./0to1pay-server-sdk-2.3.0.tgz
11
11
  ```
12
12
 
13
- Provision a test project and scoped server key through the platform operator. Set the HTTPS API origin and scoped key in your merchant backend environment.
13
+ On a deployment with public signup enabled, sign in to **My workspace** and issue a scoped Sandbox key from **API keys**. On a restricted deployment, get a test project and server key from the platform operator. Set the HTTPS API origin and scoped key in your app's backend environment.
14
14
 
15
15
  ```ts
16
16
  import { ZeroToOnePayClient } from '@0to1pay/server-sdk';
@@ -34,8 +34,16 @@ Use `call` for the full merchant API. Use the same idempotency key when retrying
34
34
 
35
35
  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
36
 
37
+ When Platform enables Base Sepolia, a Sandbox key can discover test USDC at `eip155:84532`. 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
+
37
39
  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. Queries also support historical payment and operation records retained by the platform.
38
40
 
41
+ ## Payment receipts
42
+
43
+ The server SDK provides this method in version 2.3.0 and later. The Platform must support `GET /v1/payments/{payment_id}/receipt`. Earlier SDK versions can access that route through authenticated HTTP.
44
+
45
+ Call `getPaymentReceipt(payment_id)` with a server key that has `payments:read`. Display each confirmed amount with its own asset, scale, and network. The receipt reports the funds received at the order’s destinations. Use the payment decision to determine whether to grant the purchased product. An empty available receipt has no confirmed funds. Historical records can return `availability: "unavailable"`.
46
+
39
47
  ## Buyer approval for on-chain checkout
40
48
 
41
49
  The merchant backend authenticates the buyer and checks their access to the quote on every checkout request. Give that checkout a stable, opaque `checkout_session_ref` of 16 to 128 base64url characters. Generate or derive it on the server and keep the raw session cookie or bearer token private. The three calls require a server key with `payments:write`.
@@ -53,7 +61,9 @@ The platform compares the finalized transaction's actual token source with the a
53
61
 
54
62
  ## Subscription and API request allowance
55
63
 
56
- SDK `2.1.0` includes billing operations in the generated contract. To integrate directly with the API, use a dedicated billing key on your server with a platform deployment that supports the operations below.
64
+ To integrate with billing directly, use a dedicated billing key on your server. On a compatible Platform release, a test billing key with `billing:write` can issue a Sandbox server key via `client.call('issueTestBillingKey', { body: {}, idempotencyKey })`. The returned key belongs to the test environment. Save its token in your server's secret store. If the response is lost, retry with the same billing credential and idempotency key. A project can issue five Sandbox keys per rolling 24 hours and hold five active Sandbox keys. `SANDBOX_KEY_LIMIT_REACHED` indicates that limit was reached.
65
+
66
+ Use the paid subscription flow to issue a live server key.
57
67
 
58
68
  1. Call `listBillingPlans` and `getBillingSubscription` to read plan terms, available USDC networks and current request usage. Live USDC billing can use configured Ethereum or Base connections.
59
69
  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.
@@ -244,6 +244,48 @@ paths:
244
244
  $ref: '#/components/responses/Conflict'
245
245
  '503':
246
246
  $ref: '#/components/responses/Unavailable'
247
+ /billing/test-keys:
248
+ post:
249
+ operationId: issueTestBillingKey
250
+ summary: Issue a scoped Sandbox server key
251
+ tags: [Billing]
252
+ x-required-scope: billing:write
253
+ description: >-
254
+ Issue a test-only integration key without a paid subscription. A project may issue up to five
255
+ Sandbox keys per rolling 24 hours and hold up to five active Sandbox keys.
256
+ Keep the returned secret server-side. If the response is lost, retry with the same billing
257
+ credential and Idempotency-Key. Regular reads never expose the secret.
258
+ parameters:
259
+ - $ref: '#/components/parameters/IdempotencyKey'
260
+ requestBody:
261
+ required: true
262
+ content:
263
+ application/json:
264
+ schema:
265
+ $ref: '#/components/schemas/BillingKeyRequest'
266
+ responses:
267
+ '201':
268
+ description: Test-only server key.
269
+ content:
270
+ application/json:
271
+ schema:
272
+ $ref: '#/components/schemas/TestBillingKey'
273
+ '400':
274
+ $ref: '#/components/responses/BadRequest'
275
+ '401':
276
+ $ref: '#/components/responses/Unauthorized'
277
+ '403':
278
+ $ref: '#/components/responses/BillingForbidden'
279
+ '409':
280
+ $ref: '#/components/responses/Conflict'
281
+ '429':
282
+ description: Sandbox key limit reached.
283
+ content:
284
+ application/json:
285
+ schema:
286
+ $ref: '#/components/schemas/Error'
287
+ '503':
288
+ $ref: '#/components/responses/Unavailable'
247
289
  /chain/assets:
248
290
  get:
249
291
  operationId: listChainAssets
@@ -251,6 +293,7 @@ paths:
251
293
  description: >
252
294
  Live checkout supports Ethereum native USDC and USDT, TRON USDT, and Base native USDC.
253
295
  Only configured networks in the caller's environment are returned.
296
+ Base Sepolia's test USDC can appear for Sandbox keys when the deployment enables it.
254
297
  tags: [Connections]
255
298
  x-required-scope: payments:read
256
299
  responses:
@@ -448,6 +491,32 @@ paths:
448
491
  $ref: '#/components/responses/RateLimited'
449
492
  '503':
450
493
  $ref: '#/components/responses/Unavailable'
494
+ /payments/{payment_id}/receipt:
495
+ parameters:
496
+ - $ref: '#/components/parameters/payment_id'
497
+ get:
498
+ operationId: getPaymentReceipt
499
+ summary: Read the confirmed funds received for a payment
500
+ tags: [Payments]
501
+ x-required-scope: payments:read
502
+ description: Returns current finalized on-chain funds linked to this payment's bound quote recipients, grouped by exact token and network. Confirmed reversals, refunds, and dispute adjustments are deducted. These are deposits to the order's recipients and do not establish payer identity or eligibility for fulfillment. Historical payments without canonical receipt data are reported as unavailable.
503
+ responses:
504
+ '200':
505
+ description: Successful scoped receipt response.
506
+ content:
507
+ application/json:
508
+ schema:
509
+ $ref: '#/components/schemas/PaymentReceipt'
510
+ '400':
511
+ $ref: '#/components/responses/BadRequest'
512
+ '401':
513
+ $ref: '#/components/responses/Unauthorized'
514
+ '403':
515
+ $ref: '#/components/responses/Forbidden'
516
+ '404':
517
+ $ref: '#/components/responses/NotFound'
518
+ '503':
519
+ $ref: '#/components/responses/Unavailable'
451
520
  /payments/{payment_id}/quotes:
452
521
  parameters:
453
522
  - $ref: '#/components/parameters/payment_id'
@@ -1639,7 +1708,7 @@ components:
1639
1708
  pattern: '^0x[0-9a-fA-F]{64}$'
1640
1709
  ChainSelectorId:
1641
1710
  type: integer
1642
- enum: [1, 999, 8453, 42161, 31337, 31338, 31339, 31340, 900001, 900002, 728126428, 900003]
1711
+ enum: [1, 999, 8453, 84532, 42161, 31337, 31338, 31339, 31340, 900001, 900002, 728126428, 900003]
1643
1712
  description: EVM or TRON chain ID, or a local or Solana selector. Use network_id for the network reference.
1644
1713
  ChainNetworkId:
1645
1714
  type: string
@@ -1818,6 +1887,46 @@ components:
1818
1887
  - scale
1819
1888
  additionalProperties: false
1820
1889
  description: The asset registry confirms scale. USDC 10.00 is amount_atomic="10000000", scale=6.
1890
+ PaymentReceipt:
1891
+ type: object
1892
+ required: [payment_id, availability, confirmed_received]
1893
+ additionalProperties: false
1894
+ properties:
1895
+ payment_id: { type: string, format: uuid }
1896
+ availability:
1897
+ type: string
1898
+ enum: [available, unavailable]
1899
+ description: Available allows an empty array when no current finalized deposit remains.
1900
+ confirmed_received:
1901
+ type: array
1902
+ items:
1903
+ $ref: '#/components/schemas/ConfirmedReceiptTotal'
1904
+ ConfirmedReceiptTotal:
1905
+ type: object
1906
+ required: [asset, amount_atomic, scale, symbol, network_id, network_name, last_confirmed_at]
1907
+ additionalProperties: false
1908
+ properties:
1909
+ asset:
1910
+ type: string
1911
+ minLength: 1
1912
+ maxLength: 160
1913
+ amount_atomic:
1914
+ type: string
1915
+ description: Positive sum of finalized deposits, in the asset minor unit.
1916
+ pattern: ^[1-9][0-9]*$
1917
+ scale: { type: integer, minimum: 0, maximum: 36 }
1918
+ symbol:
1919
+ type: [string, 'null']
1920
+ network_id:
1921
+ anyOf:
1922
+ - $ref: '#/components/schemas/ChainNetworkId'
1923
+ - type: 'null'
1924
+ network_name:
1925
+ type: [string, 'null']
1926
+ last_confirmed_at:
1927
+ type: [string, 'null']
1928
+ format: date-time
1929
+ description: Canonical chain timestamp of the latest included deposit.
1821
1930
  NonNegativeMoney:
1822
1931
  type: object
1823
1932
  properties:
@@ -2780,6 +2889,16 @@ components:
2780
2889
  $ref: '#/components/schemas/Environment'
2781
2890
  required: [key_id, token, environment]
2782
2891
  additionalProperties: false
2892
+ TestBillingKey:
2893
+ allOf:
2894
+ - $ref: '#/components/schemas/BillingKey'
2895
+ - type: object
2896
+ properties:
2897
+ environment:
2898
+ const: test
2899
+ token:
2900
+ type: string
2901
+ pattern: '^sp_test_[0-9a-f]{16}\.[A-Za-z0-9_-]{43}$'
2783
2902
  ChainCheckoutSessionRef:
2784
2903
  type: string
2785
2904
  pattern: '^[A-Za-z0-9_-]{16,128}$'
@@ -108,6 +108,11 @@ export declare class ZeroToOnePayClient {
108
108
  updated_at: string;
109
109
  resource_version: number;
110
110
  }>;
111
+ getPaymentReceipt(payment_id: string): Promise<{
112
+ payment_id: string;
113
+ availability: "available" | "unavailable";
114
+ confirmed_received: components["schemas"]["ConfirmedReceiptTotal"][];
115
+ }>;
111
116
  createQuote(payment_id: string, body: Schema<'CreateQuote'>, idempotencyKey: string): Promise<{
112
117
  merchant_id: string;
113
118
  project_id: string;
@@ -164,6 +164,9 @@ export class ZeroToOnePayClient {
164
164
  getPayment(payment_id) {
165
165
  return this.call('getPayment', { path: { payment_id } });
166
166
  }
167
+ getPaymentReceipt(payment_id) {
168
+ return this.call('getPaymentReceipt', { path: { payment_id } });
169
+ }
167
170
  createQuote(payment_id, body, idempotencyKey) {
168
171
  return this.call('createQuote', { path: { payment_id }, body, idempotencyKey });
169
172
  }
@@ -153,6 +153,26 @@ export interface paths {
153
153
  patch?: never;
154
154
  trace?: never;
155
155
  };
156
+ "/billing/test-keys": {
157
+ parameters: {
158
+ query?: never;
159
+ header?: never;
160
+ path?: never;
161
+ cookie?: never;
162
+ };
163
+ get?: never;
164
+ put?: never;
165
+ /**
166
+ * Issue a scoped Sandbox server key
167
+ * @description Issue a test-only integration key without a paid subscription. A project may issue up to five Sandbox keys per rolling 24 hours and hold up to five active Sandbox keys. Keep the returned secret server-side. If the response is lost, retry with the same billing credential and Idempotency-Key. Regular reads never expose the secret.
168
+ */
169
+ post: operations["issueTestBillingKey"];
170
+ delete?: never;
171
+ options?: never;
172
+ head?: never;
173
+ patch?: never;
174
+ trace?: never;
175
+ };
156
176
  "/chain/assets": {
157
177
  parameters: {
158
178
  query?: never;
@@ -162,7 +182,7 @@ export interface paths {
162
182
  };
163
183
  /**
164
184
  * List supported USDC and USDT deployments on configured networks
165
- * @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. Base Sepolia's test USDC can appear for Sandbox keys when the deployment enables it.
166
186
  */
167
187
  get: operations["listChainAssets"];
168
188
  put?: never;
@@ -252,6 +272,28 @@ export interface paths {
252
272
  patch?: never;
253
273
  trace?: never;
254
274
  };
275
+ "/payments/{payment_id}/receipt": {
276
+ parameters: {
277
+ query?: never;
278
+ header?: never;
279
+ path: {
280
+ payment_id: components["parameters"]["payment_id"];
281
+ };
282
+ cookie?: never;
283
+ };
284
+ /**
285
+ * Read the confirmed funds received for a payment
286
+ * @description Returns current finalized on-chain funds linked to this payment's bound quote recipients, grouped by exact token and network. Confirmed reversals, refunds, and dispute adjustments are deducted. These are deposits to the order's recipients and do not establish payer identity or eligibility for fulfillment. Historical payments without canonical receipt data are reported as unavailable.
287
+ */
288
+ get: operations["getPaymentReceipt"];
289
+ put?: never;
290
+ post?: never;
291
+ delete?: never;
292
+ options?: never;
293
+ head?: never;
294
+ patch?: never;
295
+ trace?: never;
296
+ };
255
297
  "/payments/{payment_id}/quotes": {
256
298
  parameters: {
257
299
  query?: never;
@@ -745,7 +787,7 @@ export interface components {
745
787
  * @description EVM or TRON chain ID, or a local or Solana selector. Use network_id for the network reference.
746
788
  * @enum {integer}
747
789
  */
748
- ChainSelectorId: 1 | 999 | 8453 | 42161 | 31337 | 31338 | 31339 | 31340 | 900001 | 900002 | 728126428 | 900003;
790
+ ChainSelectorId: 1 | 999 | 8453 | 84532 | 42161 | 31337 | 31338 | 31339 | 31340 | 900001 | 900002 | 728126428 | 900003;
749
791
  /** @description Decimal TRON identifiers are emitted. The hexadecimal TRON mainnet alias is accepted on connection creation. */
750
792
  ChainNetworkId: string;
751
793
  /** @enum {string} */
@@ -832,6 +874,30 @@ export interface components {
832
874
  amount_atomic: string;
833
875
  scale: number;
834
876
  };
877
+ PaymentReceipt: {
878
+ /** Format: uuid */
879
+ payment_id: string;
880
+ /**
881
+ * @description Available allows an empty array when no current finalized deposit remains.
882
+ * @enum {string}
883
+ */
884
+ availability: "available" | "unavailable";
885
+ confirmed_received: components["schemas"]["ConfirmedReceiptTotal"][];
886
+ };
887
+ ConfirmedReceiptTotal: {
888
+ asset: string;
889
+ /** @description Positive sum of finalized deposits, in the asset minor unit. */
890
+ amount_atomic: string;
891
+ scale: number;
892
+ symbol: string | null;
893
+ network_id: components["schemas"]["ChainNetworkId"] | null;
894
+ network_name: string | null;
895
+ /**
896
+ * Format: date-time
897
+ * @description Canonical chain timestamp of the latest included deposit.
898
+ */
899
+ last_confirmed_at: string | null;
900
+ };
835
901
  NonNegativeMoney: {
836
902
  asset: string;
837
903
  amount_atomic: string;
@@ -1184,6 +1250,11 @@ export interface components {
1184
1250
  token: string;
1185
1251
  environment: components["schemas"]["Environment"];
1186
1252
  };
1253
+ TestBillingKey: components["schemas"]["BillingKey"] & {
1254
+ /** @constant */
1255
+ environment?: "test";
1256
+ token?: string;
1257
+ };
1187
1258
  /** @description Stable opaque reference assigned by the merchant server to the authenticated buyer checkout. */
1188
1259
  ChainCheckoutSessionRef: string;
1189
1260
  /** @description Use a 0x-prefixed wallet signature. Encode raw Solana Ed25519 signature bytes as hex. */
@@ -1867,6 +1938,47 @@ export interface operations {
1867
1938
  503: components["responses"]["Unavailable"];
1868
1939
  };
1869
1940
  };
1941
+ issueTestBillingKey: {
1942
+ parameters: {
1943
+ query?: never;
1944
+ header: {
1945
+ /** @description Stable per logical caller mutation, scoped to bound merchant/project/environment + operation. Same key with different canonical request -> 409. Claim responses dynamically revalidate validity. */
1946
+ "Idempotency-Key": components["parameters"]["IdempotencyKey"];
1947
+ };
1948
+ path?: never;
1949
+ cookie?: never;
1950
+ };
1951
+ requestBody: {
1952
+ content: {
1953
+ "application/json": components["schemas"]["BillingKeyRequest"];
1954
+ };
1955
+ };
1956
+ responses: {
1957
+ /** @description Test-only server key. */
1958
+ 201: {
1959
+ headers: {
1960
+ [name: string]: unknown;
1961
+ };
1962
+ content: {
1963
+ "application/json": components["schemas"]["TestBillingKey"];
1964
+ };
1965
+ };
1966
+ 400: components["responses"]["BadRequest"];
1967
+ 401: components["responses"]["Unauthorized"];
1968
+ 403: components["responses"]["BillingForbidden"];
1969
+ 409: components["responses"]["Conflict"];
1970
+ /** @description Sandbox key limit reached. */
1971
+ 429: {
1972
+ headers: {
1973
+ [name: string]: unknown;
1974
+ };
1975
+ content: {
1976
+ "application/json": components["schemas"]["Error"];
1977
+ };
1978
+ };
1979
+ 503: components["responses"]["Unavailable"];
1980
+ };
1981
+ };
1870
1982
  listChainAssets: {
1871
1983
  parameters: {
1872
1984
  query?: never;
@@ -2052,6 +2164,33 @@ export interface operations {
2052
2164
  503: components["responses"]["Unavailable"];
2053
2165
  };
2054
2166
  };
2167
+ getPaymentReceipt: {
2168
+ parameters: {
2169
+ query?: never;
2170
+ header?: never;
2171
+ path: {
2172
+ payment_id: components["parameters"]["payment_id"];
2173
+ };
2174
+ cookie?: never;
2175
+ };
2176
+ requestBody?: never;
2177
+ responses: {
2178
+ /** @description Successful scoped receipt response. */
2179
+ 200: {
2180
+ headers: {
2181
+ [name: string]: unknown;
2182
+ };
2183
+ content: {
2184
+ "application/json": components["schemas"]["PaymentReceipt"];
2185
+ };
2186
+ };
2187
+ 400: components["responses"]["BadRequest"];
2188
+ 401: components["responses"]["Unauthorized"];
2189
+ 403: components["responses"]["Forbidden"];
2190
+ 404: components["responses"]["NotFound"];
2191
+ 503: components["responses"]["Unavailable"];
2192
+ };
2193
+ };
2055
2194
  createQuote: {
2056
2195
  parameters: {
2057
2196
  query?: never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0to1pay/server-sdk",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "Server-only 0to1Pay client for direct on-chain stablecoin checkout and fulfillment",