@0to1pay/server-sdk 1.0.1 → 2.1.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 +49 -6
- package/dist/contracts/openapi.yaml +710 -706
- package/dist/packages/domain/contract.d.ts +0 -1
- package/dist/packages/domain/contract.js +0 -3
- package/dist/packages/server-sdk/index.d.ts +33 -19
- package/dist/packages/server-sdk/index.js +36 -3
- package/dist/packages/server-sdk/schema.d.ts +717 -511
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
# 0to1Pay Server SDK
|
|
2
2
|
|
|
3
|
-
Node.js 22.20.0 or newer. Install the verified tarball in your merchant backend.
|
|
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
|
|
6
|
+
npm install @0to1pay/server-sdk@2.1.0
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
Once the package is published to npm, use the scoped name.
|
|
10
|
-
|
|
11
9
|
```sh
|
|
12
|
-
npm install
|
|
10
|
+
npm install ./0to1pay-server-sdk-2.1.0.tgz
|
|
13
11
|
```
|
|
14
12
|
|
|
15
|
-
|
|
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.
|
|
16
14
|
|
|
17
15
|
```ts
|
|
18
16
|
import { ZeroToOnePayClient } from '@0to1pay/server-sdk';
|
|
@@ -26,4 +24,49 @@ const { data } = await client.call('listPayments', { query: { limit: 1 } });
|
|
|
26
24
|
|
|
27
25
|
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.
|
|
28
26
|
|
|
27
|
+
## Create a stablecoin checkout
|
|
28
|
+
|
|
29
|
+
| Live network | `network_id` | Checkout assets |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| Ethereum | `eip155:1` | Native USDC and USDT |
|
|
32
|
+
| TRON | `tron:728126428` | USDT |
|
|
33
|
+
| Base | `eip155:8453` | Native USDC |
|
|
34
|
+
|
|
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
|
+
|
|
37
|
+
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
|
+
|
|
39
|
+
## Buyer approval for on-chain checkout
|
|
40
|
+
|
|
41
|
+
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`.
|
|
42
|
+
|
|
43
|
+
1. Call `client.createChainIntent(quoteId, { checkout_session_ref, payer_address }, createKey)` with the wallet account that will fund the transfer.
|
|
44
|
+
2. Have the wallet sign the exact returned `signing_message` and call `client.authorizeChainIntent(quoteId, intent.intent_id, { checkout_session_ref, signature }, authorizeKey)`. The message binds this authorization to the quote, payer, destination, network, asset, amount, and expiry. Preserve every byte of the message.
|
|
45
|
+
3. After authorization, use the quote's existing transfer instructions. Once the wallet broadcasts, call `chainIntentClaimMessage(intent, transactionId)` on the merchant server and have the same wallet sign the returned message.
|
|
46
|
+
4. Call `client.submitChainIntent(quoteId, intent.intent_id, { checkout_session_ref, transaction_id: transactionId, signature }, submitKey)` from the same checkout. Status `submitted` means the signed transaction claim was queued. Read the payment decision for verification and fulfillment status.
|
|
47
|
+
|
|
48
|
+
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.
|
|
49
|
+
|
|
50
|
+
For test and existing Solana integrations, encode the owner's Ed25519 signature as `0x` followed by 128 hexadecimal characters. The claim helper preserves the case of canonical Base58 Solana transaction signatures that decode to exactly 64 bytes and contain at least one nonzero byte.
|
|
51
|
+
|
|
52
|
+
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. In the [0to1Pay Console](https://github.com/0to1pay/console), open the order and select **Review transfer** on the exact confirmed receipt in **Money movements**. 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.
|
|
53
|
+
|
|
54
|
+
## Subscription and API request allowance
|
|
55
|
+
|
|
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.
|
|
57
|
+
|
|
58
|
+
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
|
+
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.
|
|
60
|
+
3. Sign the invoice intent, call `authorizeBillingInvoice`, then send the quoted USDC. Sign the transaction claim and call `submitBillingInvoice` with the same checkout session. Each mutation uses its own stable idempotency key.
|
|
61
|
+
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.
|
|
62
|
+
5. Call `issueBillingKey` with `body: {}` and a stable idempotency key. Store the returned token on the server.
|
|
63
|
+
|
|
64
|
+
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.
|
|
65
|
+
|
|
66
|
+
## Upgrade from 1.x
|
|
67
|
+
|
|
68
|
+
- Replace `createConnection`, `validateConnection`, and `rotateConnectionCredentials` with a watch-only `createChainConnection` and registered merchant-controlled recipients.
|
|
69
|
+
- Replace `attachExternalAttempt` and `confirmAttempt` with a chain quote and buyer-authorized transaction claim. The `createAttempt` request has `connection_id` and `quote_id`, and returns `201` for the assigned chain attempt.
|
|
70
|
+
- Use `getOperation` to inspect operation history. `recoverOperation` and `ingestProviderWebhook` are retired. Merchant fulfillment still uses the signed outbound events handled by `@0to1pay/fulfillment-sdk`.
|
|
71
|
+
|
|
29
72
|
The SDK is available under the MIT license. See the `LICENSE` file included in the package.
|