@0to1pay/server-sdk 1.0.1 → 2.0.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,16 +3,16 @@
3
3
  Node.js 22.20.0 or newer. Install the verified tarball in your merchant backend.
4
4
 
5
5
  ```sh
6
- npm install ./0to1pay-server-sdk-1.0.0.tgz
6
+ npm install ./0to1pay-server-sdk-2.0.0.tgz
7
7
  ```
8
8
 
9
9
  Once the package is published to npm, use the scoped name.
10
10
 
11
11
  ```sh
12
- npm install @0to1pay/server-sdk@1.0.0
12
+ npm install @0to1pay/server-sdk@2.0.0
13
13
  ```
14
14
 
15
- Open `/developers` on your 0to1Pay API origin to create a test project and issue a server key. Set the HTTPS origin and scoped key in your backend environment.
15
+ 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
16
 
17
17
  ```ts
18
18
  import { ZeroToOnePayClient } from '@0to1pay/server-sdk';
@@ -26,4 +26,29 @@ const { data } = await client.call('listPayments', { query: { limit: 1 } });
26
26
 
27
27
  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
28
 
29
+ ## Create a stablecoin checkout
30
+
31
+ Call `listChainAssets` to discover the enabled networks and assets. 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`.
32
+
33
+ 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.
34
+
35
+ ## Buyer approval for on-chain checkout
36
+
37
+ 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`.
38
+
39
+ 1. Call `client.createChainIntent(quoteId, { checkout_session_ref, payer_address }, createKey)` with the wallet account that will fund the transfer.
40
+ 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.
41
+ 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.
42
+ 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.
43
+
44
+ Use the wallet's UTF-8 message signing for the chain. EVM uses its personal-message signature. Solana uses the owner's Ed25519 signature, encoded as `0x` followed by 128 hexadecimal characters. TRON uses `signMessageV2`, which returns a `0x`-prefixed signature. The claim helper accepts canonical Base58 Solana transaction signatures that decode to exactly 64 bytes and contain at least one nonzero byte. It preserves their case. EVM and TRON transaction hashes must contain 64 hexadecimal digits. The helper accepts `0x` or `0X` and normalizes to lowercase `0x`-prefixed hex. TRON also accepts bare hex.
45
+
46
+ 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.
47
+
48
+ ## Upgrade from 1.x
49
+
50
+ - Replace `createConnection`, `validateConnection`, and `rotateConnectionCredentials` with a watch-only `createChainConnection` and registered merchant-controlled recipients.
51
+ - 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.
52
+ - Use `getOperation` to inspect operation history. `recoverOperation` and `ingestProviderWebhook` are retired. Merchant fulfillment still uses the signed outbound events handled by `@0to1pay/fulfillment-sdk`.
53
+
29
54
  The SDK is available under the MIT license. See the `LICENSE` file included in the package.