@0to1pay/server-sdk 3.1.2 → 3.1.4

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.
Files changed (2) hide show
  1. package/README.md +44 -21
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,48 +2,71 @@
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
- **Before installing** you need Node.js 22.20+, PostgreSQL, public HTTPS for the signed webhook, a running merchant worker and a test wallet with Base Sepolia ETH for gas and 0.01 test USDC. [Live Next.js demo](https://0to1pay.com/demo/base-usdc) · [Guide, recovery steps and setup measurements](https://0to1pay.com/guides/nextjs-base-usdc)
5
+ ## Next.js quickstart
6
6
 
7
- A single OrbStack run with Node 22.23.5 and PostgreSQL 17 measured 6.534 s for cold-cache package installation and 10.810 s from setup to a production HTTP response with the database, keys and HTTPS ready. One public Base Sepolia purchase took 2.028 s from recognized confirmation to grant. A signed webhook replay left one active pass. First-merchant self-install time is unmeasured. [Measurement conditions and demo](https://0to1pay.com/guides/nextjs-base-usdc)
7
+ The Next.js example takes a 0.01 test USDC payment on Base Sepolia and grants the buyer one access pass from a signed webhook. Follow the [Next.js quickstart](https://0to1pay.com/docs#nextjs-quickstart) or [한국어 빠른 시작](https://0to1pay.com/docs?lang=ko#nextjs-quickstart). To make a [test purchase](https://0to1pay.com/demo/base-usdc), use a Base Sepolia wallet with test USDC and test ETH for gas. If you have already sent the payment, reopen your original order.
8
8
 
9
- **Project pricing.** Sandbox includes 1,000 requests per UTC calendar month for free. For 30 prepaid days, Starter is 9 test tokens / 1,000 requests, Growth 29 / 5,000, Scale 99 / 25,000. The beta uses test USDC or USDT and costs zero real money. Every paid plan includes Ethereum Sepolia, Base Sepolia, TRON Nile, core APIs, webhooks and recovery. Pricing is independent of volume settled and successful payment count.
9
+ To run the example on your server, prepare Node.js 22.20+, writable PostgreSQL, a public HTTPS webhook and a separate continuously running worker. Create a test project and issue a scoped server key. [Merchant dashboard](https://pay.0to1pay.com/merchant)
10
10
 
11
- Count one request for order creation and one for quote creation. With no other metered calls, 500 fresh checkouts consume Starter’s 1,000 requests. Add any metered list or configuration reads to the estimate. Identical creation retries in the same project with the same idempotency key and content count once. Usage signals are sent at 80% and 95%. At 100% new starts stop. Existing confirmation, fulfillment and webhook redelivery remain available. Manual upgrades cost the price difference and preserve expiry and consumption. Renewals and overages are never charged automatically. [Estimate costs](https://0to1pay.com/pricing)
11
+ ```sh
12
+ curl -fsSLO https://0to1pay.com/examples/nextjs-base-usdc.zip
13
+ unzip nextjs-base-usdc.zip
14
+ cd nextjs-base-usdc
15
+ npm ci
16
+ cp .env.example .env
17
+ ```
18
+
19
+ Set `DATABASE_URL`, `ZERO_TO_ONE_PAY_API_KEY`, `MERCHANT_ID` and `PROJECT_ID`. Use the exact browser origin for `APP_ORIGIN` (local default `http://localhost:3000`) and the public HTTPS URL forwarding the original request bytes to `POST /api/webhooks/0to1pay` for `WEBHOOK_URL`. Run the app in one terminal and the worker in another, from the same directory.
12
20
 
13
21
  ```sh
14
- npm install @0to1pay/server-sdk
22
+ npm run setup
23
+ npm run dev
15
24
  ```
16
25
 
17
- **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).
26
+ ```sh
27
+ npm run worker
28
+ ```
29
+
30
+ Preserve the merchant database and private `.merchant/` directory. The example associates one entitlement with its original order and guest. A signed recovery challenge lets the original paying wallet regain access after cookie loss. [Setup and purchase recovery](https://0to1pay.com/guides/nextjs-base-usdc) · [Machine-readable guide](https://0to1pay.com/guides/nextjs-base-usdc.md)
31
+
32
+ ## Use the server client in an existing app
18
33
 
19
- [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.
34
+ ```sh
35
+ npm install @0to1pay/server-sdk
36
+ ```
37
+
38
+ Read the assets enabled for a test project from your server. Keep the API key in the server environment.
20
39
 
21
- ```ts
40
+ ```js
22
41
  import { ZeroToOnePayClient } from '@0to1pay/server-sdk';
23
42
 
24
43
  const client = new ZeroToOnePayClient({
25
44
  origin: 'https://api.0to1pay.com',
26
- apiKey: process.env.ZERO_TO_ONE_PAY_API_KEY!,
45
+ apiKey: process.env.ZERO_TO_ONE_PAY_API_KEY,
27
46
  });
28
47
  const { data } = await client.call('listChainAssets', {});
29
48
  const baseUsdc = data.find(asset => asset.network_id === 'eip155:84532' && asset.symbol === 'USDC');
30
49
  ```
31
50
 
51
+ ## Plans and usage
52
+
53
+ The project can use Sandbox for free with 1,000 metered requests per UTC calendar month. Prepay for 30 days with Starter (9 test tokens / 1,000 requests), Growth (29 / 5,000), or Scale (99 / 25,000). The beta accepts test USDC or USDT at zero real cost. All paid plans include Ethereum Sepolia, Base Sepolia, TRON Nile, the core APIs, webhooks and recovery. Pricing is independent of settled volume and successful payment count.
54
+
55
+ One order creation plus one quote creation uses two requests. With no other metered calls, 500 fresh checkouts consume Starter’s 1,000 requests. Include metered list/configuration reads in your estimate. Same-project, same-key, same-content creation retries count once. At 80% and 95% the API flags usage. At 100%, new starts stop and existing verification, fulfillment and redelivery continue. A manual upgrade charges the difference and retains usage and expiry. Renewals require a manual payment. The service does not bill overages. [Estimate your 30-day cost](https://0to1pay.com/pricing)
56
+
32
57
  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).
33
58
 
34
59
  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.
35
60
 
36
61
  ## Create a stablecoin checkout
37
62
 
38
- | Live network | `network_id` | Checkout assets |
63
+ | Beta network | `network_id` | Test asset |
39
64
  | --- | --- | --- |
40
- | Ethereum | `eip155:1` | Native USDC and USDT |
41
- | TRON | `tron:728126428` | USDT |
42
- | Base | `eip155:8453` | Native USDC |
43
-
44
- 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.
65
+ | Ethereum Sepolia | `eip155:11155111` | USDC |
66
+ | Base Sepolia | `eip155:84532` | USDC |
67
+ | TRON Nile | `tron:3448148188` | USDT |
45
68
 
46
- 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.
69
+ Call `listChainAssets` to see which assets your project can accept. Register a test connection and its merchant-owned receiving 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`. For example, 0.01 USDC is `{ asset: 'stable:USDC', amount_atomic: '10000', scale: 6 }`. The atomic amount must be positive and below `2^64`. Each connection in `allowed_connections` must support the selected asset. Use a webhook from the same test project.
47
70
 
48
71
  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.
49
72
 
@@ -64,20 +87,20 @@ The merchant backend authenticates the buyer and checks their access to the quot
64
87
 
65
88
  Use the wallet's UTF-8 message signing for the chain. Ethereum and Base use the EVM personal-message signature. TRON uses `signMessageV2`, which returns a `0x`-prefixed signature. EVM and TRON transaction hashes must contain 64 hexadecimal digits. The claim helper accepts `0x` or `0X` and normalizes to lowercase `0x`-prefixed hex. TRON also accepts bare hex.
66
89
 
67
- The platform compares the finalized transaction's actual token source with the approved wallet and checks the exact token, destination, amount, and timing. An observed transfer without a matching signed claim is held for operator review. Sign in with the reviewer role at `/console` on your deployment’s operator Web origin (`CONSOLE_PUBLIC_ORIGIN`). Open the order, find the confirmed receipt in **Money movements**, and select **Review transfer**. A service with `payments:review` can also call `reviewPayment` with `action: 'accept_unattributed_chain_payment'`, that receipt's `movement_id`, the expected payment resource version, and a reason. Set `allow_late_payment: true` only when deliberately approving the specified late transfer. Exchange withdrawals can use this operational review path.
90
+ The platform compares the finalized transaction's actual token source with the approved wallet and checks the exact token, destination, amount, and timing. If a buyer has already sent funds, resume the existing order and use the original transaction hash to finish the wallet proof. The buyer can share their order reference and hash with the merchant for help. Access is granted after the payment is confirmed and the signed fulfillment command is processed.
68
91
 
69
92
  ## Subscription and API request allowance
70
93
 
71
- 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.
94
+ To integrate with billing directly, use a dedicated billing key on your server. 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.
72
95
 
73
- Use the paid subscription flow to issue a live server key.
96
+ To purchase a prepaid subscription for your beta project and issue a server key, use the billing API from your backend.
74
97
 
75
- 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.
98
+ 1. Call `listBillingPlans` and `getBillingSubscription` to read plan terms, current request usage, and available collection networks. Each collection option identifies the network and test token to use.
76
99
  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.
77
100
  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.
78
101
  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.
79
102
  5. Call `issueBillingKey` with `body: {}` and a stable idempotency key. Store the returned token on the server.
80
103
 
81
- The allowance counts admitted requests to metered endpoints, including idempotent replays. `API_REQUEST_LIMIT_REACHED` indicates the period's allowance is exhausted. Payment completion and fulfillment operations remain available to keys with the appropriate scopes.
104
+ `API_REQUEST_LIMIT_REACHED` indicates that the project has used its allowance for the period. Payment completion and fulfillment operations remain available to keys with the appropriate scopes.
82
105
 
83
106
  The SDK is available under the MIT license. See the `LICENSE` file included in the package.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0to1pay/server-sdk",
3
- "version": "3.1.2",
3
+ "version": "3.1.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "Server-only 0to1Pay client for direct on-chain stablecoin checkout and fulfillment",