@atumlabs/payment-gateway-client 3.0.0 → 4.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/CHANGELOG.md +56 -0
- package/LICENSE +202 -83
- package/NOTICE +2 -0
- package/README.md +55 -17
- package/THIRD-PARTY-NOTICES.txt +4 -5
- package/dist/cli/approve-permit2.js +6406 -1077
- package/dist/cli/payment-status.js +6038 -1084
- package/dist/cli/quote-status.js +6090 -1149
- package/dist/cli/request-quote.js +6090 -1149
- package/dist/cli/send-payment.js +6566 -1209
- package/dist/index.d.ts +390 -2373
- package/dist/index.js +7095 -1414
- package/dist/sender-auth-verify-CEf7FN6s.d.ts +2316 -0
- package/dist/signing.d.ts +223 -0
- package/dist/signing.js +20687 -0
- package/docs/idempotency.md +8 -5
- package/docs/signing.md +221 -0
- package/package.json +32 -11
- package/signing.d.ts +2 -0
- package/signing.js +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [4.0.0] - 2026-10-16
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `preparePaymentRequest` signs depositRequestHash v2, the hash of the payment terms, when the source chain's `GET /v1/defaults` entry says so. The new `deposit_request_hash_version` on that response is read into `ChainDefaults.depositRequestHashVersion`; absent is 1, and v1, `keccak256(request_id)`, stays the default. A caller passing `resolvedDefaults.source` sets it there.
|
|
14
|
+
- `verifyPaymentRequestJSON` and `verifyRequestCommitment` read depositRequestHash v2 when asked: `depositRequestHashV2Mode: 'audit' | 'enforce'` on the expectations, or as the new `options` argument of `verifyRequestCommitment`. Either mode accepts a deposit committing v1 or v2; `audit` admits a request the strict reader refuses and reports why in `strictDetail`, `enforce` refuses it as `request_malformed`. Without it, both behave exactly as before. Opted in, `CommitmentResult` carries `depositRequestHashVersion` (`v1` or `v2`) and `expectedDepositRequestHashV2`, and `VerifyResult` carries the check's result as `commitment`.
|
|
15
|
+
- `capFromQuote(sourceAmount, slippageBps)` derives a `max_source_amount` from a settler's quoted `source_amount` plus a slippage tolerance in basis points (0 to 10000). Both amounts are in the source token's smallest units, so no decimals or price are involved, and the result rounds up so it never falls below quote plus tolerance. A non-canonical amount or an out-of-range slippage throws.
|
|
16
|
+
- `preparePaymentRequest` leaves `executor` off unless the caller passes it. Omitted on the wire means settler. Pass `{ deposit, reserve, fulfill }` to split the legs. The request `version` is the declaration bindings constant, `1.3`, because `executor` is a new field.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- `PaymentStatus` gains `refunding`, `refund_available` and `refunded`, so a caller branching exhaustively on it needs the new values. `GetPaymentStatusResponse.refund_signature` is present only on `refund_available` and lets the originator submit the refund itself, `refund_reason` on the three payment responses says why the settler gave up when it said so, and `PaymentTransactions.refund` is the refund transaction. `isTerminalStatus` treats `refunded` as terminal, so `waitForTerminalStatus` stops on it. `refund_available` is not terminal: the funds are still in escrow until the refund lands or a late delivery is paid. `send-payment` exits 4 on `refund_available` and 3 on `refunded`, and `--wait` does not wait on a payment that is already `refund_available`.
|
|
20
|
+
- **The default quote deadline is now 3 seconds** for both `preparePaymentRequest` (was 10) and `prepareQuoteRequest` (was 5), and so for `send-payment` and `request-quote` as well. Bidding closes at the quote deadline and the gateway always waits until then, so a payment or quote request that relies on the default now spends about 3 seconds at the quote step instead of 5 to 10. `DEFAULT_PAYMENT_QUOTE_DEADLINE_SECONDS` and `DEFAULT_QUOTE_DEADLINE_SECONDS` are both `3`, and the API description's default for `quote_deadline_seconds` on `PreparePaymentRequest` is `3`. The window has to cover signing and submitting the request as well as settlers quoting, and a signed request is submittable only before its quote deadline. Pass a larger `quoteDeadlineSeconds` (`--quote-deadline-seconds` on the command line) when signing takes longer, for example a signer that waits for an approval, when you submit the request later, or when your clock lags the gateway's. Passing the old value restores the old window.
|
|
21
|
+
- **Breaking: the three Atum credential contexts moved to `schemas.atum.xyz`.** A holder credential passed to `buildEnvelope` must name `https://schemas.atum.xyz/credentials/known-to-atum/v1`, `.../kyc/v1` or `.../sender-compliance/v1`. Their terms moved with them, for example to `https://schemas.atum.xyz/credentials/known-to-atum/v1#role`, and those term IRIs are what a credential's signature covers. A credential that still names a `https://schemas.atum.network/credentials/...` URL is refused as an unknown JSON-LD context. One issued under the old vocabulary does not verify even with its URL rewritten, so it has to be re-issued.
|
|
22
|
+
- `FulfillmentAuthorization.authorization` now documents the EIP-3009 shape the settler signs: the transfer is in `message_prehash` as typed-data JSON, `message` is its EIP-712 digest, there is no `payload`, and `validBefore` is the payment's `fulfillment_deadline` in whole seconds. The type is unchanged.
|
|
23
|
+
- **Breaking: `preparePaymentRequest` and `prepareQuoteRequest` refuse a `requestId` outside `^[A-Za-z0-9._-]{1,128}$`**, before anything is built: 1 to 128 ASCII letters, digits, `.`, `_` or `-`. The payment request is now read with the strict reader that computes depositRequestHash v2, whichever version is signed, and that reader, like the gateway once it enforces v2, takes no other `request_id`. Ids the CLI generates already conform; a `--request-id` or `--request-id-prefix` outside the pattern is refused. More generally, any body the strict reader refuses now fails at build, whichever version is signed, not only one with such a `request_id`: for example `settlerRequirements` carrying a member other than `whitelist` and `blacklist`, which the schema allows.
|
|
24
|
+
- `preparePaymentRequest` builds the whole request body before the deposit authorization and signs over exactly that body, then adds `sender_auth` to it. The output for v1 is unchanged.
|
|
25
|
+
- `CommitmentOutcome` gains `quote_request_mismatch`, from the shared SDK's new quote binding. A `Record` or exhaustive `switch` over the outcomes needs a branch for it.
|
|
26
|
+
- `verifyPaymentRequest` is deprecated: it checks a parsed copy of the request and accepts only depositRequestHash v1, and refuses a `depositRequestHashV2Mode`. Use `verifyPaymentRequestJSON` with the request as received.
|
|
27
|
+
- **Breaking for TypeScript callers: `fulfillment_verifier` and `escrow_contract_address` are required on `PaymentRequest` and `CreateQuoteRequest`.** The gateway already refuses a request that omits either. The types said optional with a default the gateway never filled in. Take both from `GET /v1/defaults` for the source chain. `preparePaymentRequest` and `prepareQuoteRequest` already set them, so a caller using the builders is unaffected. The gateway also requires `message_prehash` on every `sender_auth.signed_messages` entry; `SignedMessage` keeps it optional because the award and fulfillment authorization shapes share that type.
|
|
28
|
+
- **Breaking: `preparePaymentRequest` requires `maxSourceAmount`.** It used to default an omitted cap to `fulfillment_amount` plus 2 bps in raw units and sign that into the Permit2, without either token's decimals or price. Across assets with different decimals or value, the signed ceiling could be orders of magnitude above what the payment was worth. The cap is now required in the type and at runtime, must be a positive base-10 integer in the source token's smallest units, and is checked before any network call. Derive it from a settler quote with `capFromQuote`, or state it explicitly. `send-payment` gains `--max-source-amount`, required when building a payment.
|
|
29
|
+
- **`prepareQuoteRequest` no longer invents `max_source_amount`.** An omitted cap used to be derived from `fulfillment_amount` plus 2 bps in raw units, which ignored both tokens' decimals and price: across assets it either filtered nothing or filtered every honest quote. An omitted cap is now left off the request, which the gateway reads as no cap. A supplied cap must be a positive base-10 integer in the source token's smallest units; anything else throws. A caller that relied on the implicit filter should pass `maxSourceAmount` explicitly.
|
|
30
|
+
- **Breaking: the builders for retired escrow shapes are removed.** No deployed escrow accepts what they produce. Removed: `createPermitWitnessTransferFromPrehash`, `PermitWitnessTransferFromParams`, `hashRequestId`, `createTvmPermitWitnessTransferFromPrehash`, `TvmPermitWitnessTransferFromParams`, `createSolanaDepositPrehash`, `hashSolanaDeposit`, `generateSolanaPaymentId`, `SolanaDepositParams`, `SolanaDepositPrehash` and `DEPOSIT_MESSAGE_SIZE`. Build payments with `PaymentGatewayClient.preparePaymentRequest` and sign them with `signPaymentRequest`; `hashPermitWitnessTransferFrom`, `hashTvmPermitWitnessTransferFrom` and the address and nonce helpers remain.
|
|
31
|
+
- **Breaking for TypeScript callers: `destination` and `requestId` are removed from `VerifyPaymentRequestExpectations`.** The payee check they switched on is now always on, and it takes both values from the request itself.
|
|
32
|
+
- **Breaking for TypeScript callers: `depositWitnessVersion` is removed from `ChainDefaults`.** Every deployed escrow uses the four-member deposit witness, which is now the only one built, so the gateway's `deposit_witness_version` is no longer read. Building a Solana payment fails for an `svm_signature_domain_version` below 4.
|
|
33
|
+
- `deposit_witness_version` is removed from the `GET /v1/defaults` response in the API description and the generated wire types. The SDK builds only the four-member witness.
|
|
34
|
+
- A payee-check refusal throws an error whose message names its outcome, for example `sender_auth: destination_mismatch: ...`. `ParsedPermit.destination` and `depositRequestHash` are now set on every chain.
|
|
35
|
+
- New `verifyPaymentRequestJSON` checks a request from its JSON text and also refuses a repeated member name, including names that differ only in letter case, where it is read: any top-level name, or inside `source`, `destination`, `request_id` or `sender_auth`. New `commitmentResultOf` reads the outcome and both copies of the payee from a refusal, and each verified entry carries the same result as `commitment`.
|
|
36
|
+
- Each value a verifier reads has one accepted spelling: `message` is `0x`-prefixed hex on every chain, Tron included; a signature is `0x` followed by 65 bytes of hex (recovery id 0, 1, 27 or 28) on EVM and Tron and `0x` followed by 64 bytes on Solana; and `max_source_amount` is a decimal integer with no sign, prefix, padding or leading zero.
|
|
37
|
+
- New `verifyRequestCommitment` checks the payee and request id a deposit commits to without recovering the signer, so it serves contract-account payers (ERC-1271, such as a Safe). `verifyPaymentRequest` and `verifyPaymentRequestJSON` recover every signer and so accept key-account payers only.
|
|
38
|
+
- A Solana deposit may omit `delegate_signer`; the signature is then checked against `source.account`. When present, it must equal `source.account`.
|
|
39
|
+
- **Breaking for TypeScript callers: `fulfillment_timestamp` is optional on `FulfillmentConfirmation`.** The gateway stopped sending it on 28 August, when settlement moved onto the settler's own report and the path that read the fulfilled event's block time was removed. The settler's report carries no time, so the field is simply absent from every confirmation. The type said `string`, so a caller reading it got a value the compiler promised and the runtime never delivered, and a client generated in a language that enforces required fields failed to deserialize a **completed** payment, after the money had moved. It is now `string | undefined`, which is what arrives. A caller that reads it gets a compile error and has to handle the absence; a caller that ignores it is unaffected. It will become required again when the settler reports the destination block time, and widening it back is not a break.
|
|
40
|
+
- **`request_id_reusable` is new on every error shape**, on `ErrorResponse` and on the asynchronous `PaymentFailure`. `retry_classification` was answering two questions at once: what the caller must change, and whether their own `request_id` survived. A malformed body and an unserved corridor are both `NOT_RETRYABLE_FIX_REQUEST`, and only the first leaves the id free, so the enum could not say both. `true` means no payment was created and the id can be re-sent; `false` means a payment exists and re-sending only replays that outcome. Absent means undetermined, which a caller should read as `false`, since assuming an id is free when it is not is the direction that costs an attempt.
|
|
41
|
+
- **Several public error codes changed value**, so a caller branching on the string needs the new ones. `CONFLICT` split into `ALREADY_SETTLED`, `DUPLICATE_INTENT`, `PAYMENT_IN_PROGRESS` and `REQUEST_ID_TAKEN`, because one code meant four different required actions: read the result, reconcile, poll, or start over with a new id. `INTERNAL_ERROR` split off `SETTLEMENT_OUTCOME_UNKNOWN`, which means settlement had started and money may already have moved, as distinct from a fault where nothing happened. `RATE_LIMITED` and `REQUEST_TIMEOUT` are gone: nothing emitted them. Every one of these keeps its HTTP status and its `retry_classification`, so the code string is the only signal that anything moved. **A caller matching `CONFLICT` keeps compiling and keeps receiving 409, then falls through to its default branch** — and for an already-settled payment that can mean re-submitting one that has been paid.
|
|
42
|
+
- `METHOD_NOT_ALLOWED` is a new public code. A wrong HTTP verb was reported as a missing route, which sends an integrator looking at their URL instead of their method. A 405 now also carries the `Allow` header naming the methods the target does support.
|
|
43
|
+
- **Breaking: `PaymentStatus` is one type across all three payment responses**, with the values `pending`, `finalizing`, `completed` and `failed`. Submitting a payment, polling its status and reading its timeline previously returned three unrelated status types, so a caller could not write one function that handled "a payment status". `settling` is gone — it described how far our own bookkeeping had got, not the payment. `cancelled` is gone too: nothing could produce it, and a payment that ends without being delivered is reported as `failed`. `isTerminalStatus('cancelled')` therefore returns `false` now. A caller with an exhaustive `switch` on status gets a compile error and has to add a `finalizing` branch; a caller testing only for `completed` or `failed` is unaffected.
|
|
44
|
+
- **`finalizing` is new, and is NOT terminal.** It means the transaction paying the recipient is on chain and accruing the confirmations its chain requires — made, but not yet irreversible, much as a card authorization is not a settlement. It normally becomes `completed` and can still become `failed`. Nothing emits it yet; it is declared here so clients are ready before the gateway starts sending it.
|
|
45
|
+
- **Breaking: one failure shape.** `PaymentError` and `TimelineError` are replaced by a single `PaymentFailure` used by all three responses, so a failure reads identically however you ask about the payment. On the timeline that is a real change of shape: `chain_id`, `tx_hash` and `revert_reason` were flat on the error and are now nested under `blockchain_context`, which also carries the four fields that endpoint previously discarded — the block number among them.
|
|
46
|
+
- **Breaking: `tx_hash` is now `transaction_hash`**, on `error.blockchain_context` (all three responses) and on `steps[]` (timeline). This is the name the shared error shape and the rest of our published specs already used; the payment API was the outlier. **A caller reading `error.blockchain_context.tx_hash` gets `undefined` after upgrading** — there is no deprecation period because the field moved to the shared definition rather than being duplicated under both names.
|
|
47
|
+
- `PaymentFailure` now carries `docs_url` and `retry_classification`. Both were already computed for every error code but only ever reached failed *requests*, never failed *payments*.
|
|
48
|
+
- The `payment-outcome` CLI no longer maps `cancelled` to exit code 3 (terminal failure), because the gateway no longer reports it. A status this build does not recognise exits 2 (still pending), which is the safe direction: a script that waits one more round costs a poll, a script that gives up on a live payment can cost a second charge.
|
|
49
|
+
- **New `transactions` object** (`deposit`, `fulfillment`) on all three responses, for looking a payment's on-chain transactions up yourself. Declared but not yet populated.
|
|
50
|
+
- The package moved within the protocol repository, from `payment-gateway-client/` to `schemas/apis/payment-gateway/v1/bindings/payment-gateway-client/`, beside the other payment-gateway bindings. Only the manifest `homepage` and `repository.directory` change; the published name, entry points and behavior do not.
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
- `preparePaymentRequest` and `prepareQuoteRequest` stamp the quote and fulfillment deadlines after their own network reads, the chain-defaults fetch and, for a Solana source, the cluster-clock read, so that time no longer comes out of the quote window. Invalid deadline values are still refused before any network call.
|
|
54
|
+
|
|
55
|
+
### Security
|
|
56
|
+
- `verifyPaymentRequest` refuses a request whose payee or `request_id` differs from the one the payer signed, on EVM, Tron and Solana. A request's `destination` and `request_id` fields are not covered by the payer's signature; the copies inside the signed deposit are, and the two must now agree. A deposit that commits no destination is refused.
|
|
57
|
+
- The HTTP client is now axios 1.20.0. 1.13.2 had a run of advisories (prototype-pollution gadgets that could tamper with requests or responses, proxy-authorization leaks, NO_PROXY SSRF, ReDoS). A caller that pins axios independently should take 1.18.0 or newer. A timeout that fires after headers have arrived still surfaces as `GatewayTimeoutError`: axios 1.20 attaches the partial response, and the client drops it so a stalled error body is not reported as a completed HTTP status.
|
|
58
|
+
|
|
59
|
+
## [3.0.1] - 2026-09-18
|
|
60
|
+
|
|
61
|
+
### Changed
|
|
62
|
+
- Published under Apache-2.0 with `publishConfig.access: public`. npm will not overwrite 3.0.0, so this version exists to ship the LICENSE, NOTICE, and public visibility that 3.0.0 cannot take.
|
|
63
|
+
|
|
10
64
|
## [3.0.0] - 2026-09-16
|
|
11
65
|
|
|
12
66
|
> **Read this before upgrading if the gateway has been accepting your asset identifiers.**
|
|
@@ -44,6 +98,8 @@ corridor is refused rather than silently served.
|
|
|
44
98
|
### Added
|
|
45
99
|
- **`ensureSourceApproval` and `needsSourceApproval`**, so the Permit2 prerequisite this package has always stated can now be satisfied from it. Paying from EVM or Tron needs a one-off approval of the source token for Permit2; without it a payment is built correctly, signed correctly, accepted by the gateway, and then reverts on-chain at settlement — the most expensive way to learn about a missing allowance. Until now the README and `send-payment --help` named the requirement and offered no way to meet it. `ensureSourceApproval` reads the current allowance and sends an approval only if it falls short; `needsSourceApproval` answers the same question read-only, spending no gas, so a payer can be warned before being asked to sign. Solana reports that no approval is needed rather than doing nothing, since its deposit authorizes the transfer itself. **This is the first part of this package that broadcasts a transaction and spends gas.** Everything else builds and signs offline, and that has not changed: you pass a connected ethers signer (or a TronWeb instance for Tron), so the package still never chooses an RPC endpoint or holds a key. An approval is unlimited by default, so later payments need no further transaction; `approvalAmount` bounds it instead, at the cost of having to renew it as Permit2 consumes it — pair a bound with `requiredAllowance` across repeated payments, or the bound stops covering itself as soon as the first charge is decremented from it. Waiting for the approval to confirm is bounded by `confirmation.timeoutMs` (one minute by default) rather than indefinite, and `onSubmitted` hands you the transaction hash the moment it is broadcast. Tokens that refuse to overwrite a non-zero allowance — mainnet USDT most notably — are reset to zero first, but only where the token actually demands it. An approval is refused outright when the signer you pass does not hold the `owner` account whose allowance was read: an approval only ever applies to the account that sends it, so a mismatched signer would approve that account, hand back a transaction hash that reads as success, and leave the owner exactly as unable to pay as before. The read-only `needsSourceApproval` is unaffected, since asking whether a payer is ready without holding their keys is a legitimate preflight. `isUnconfirmed` ships alongside them for telling a broadcast-but-unseen approval apart from one that failed: the wait for a confirmation is bounded, and reaching that bound is not a failure, so the two need opposite responses. `approve-permit2` reports an unconfirmed run as `{"unconfirmed": true, "txHash": ...}` on stdout rather than as a bare non-zero exit indistinguishable from a revert. These helpers raise an allowance and never lower one, so `--amount` below an allowance the wallet already holds leaves it alone and says so.
|
|
46
100
|
- **`approve-permit2`**, a command that performs that approval. `approve-permit2 <sender> <sourceAsset> --rpc-url <url>` takes the same CAIP-19 asset string as `send-payment`, and `--check` reports whether an approval is needed without sending anything or needing a key. It is a separate command rather than a flag on `send-payment` because it is a different kind of act: it spends gas, once per wallet and token, and is worth doing deliberately and ahead of time rather than as a side effect of paying. The private key comes from `PRIVATE_KEY` or an interactive prompt and is never accepted as a flag, which would put it in shell history and in the process list. EVM and Tron; Tron additionally needs `tronweb`, an optional peer dependency, so that EVM-only installs do not carry it. The result JSON goes to stdout, like the other commands. The allowance is read before a key is ever requested, so an already-approved wallet — which is every wallet after the first run — never has to produce a secret to learn there was nothing to do, and the key is checked against `<sender>` before anything is sent, so a mismatched key cannot approve the wrong account and report success.
|
|
101
|
+
- **Signing helpers for all three PaymentRequest signatures**, available from the `@atum-labs/payment-gateway-client/signing` subpath. A PaymentRequest carries three unrelated signatures and choosing the wrong one is the mistake this surface exists to prevent, so they are named for what they authorize rather than for how they are built. `signPaymentRequest` fills `sender_auth.signed_messages[]` and authorizes the **on-chain transfer**. `signDeclaration` attests that the **document** came from its signer, as a W3C Data Integrity proof over the URDNA2015-canonicalized request — it is exported under that name, rather than the upstream library's `signPaymentRequest`, precisely so the two cannot be confused. `buildEnvelope` and `buildEnvelopeForAccount` carry the **originator's identity** as a holder-signed PaymentRequestEnvelope. Signing one does not stand in for another: a request with a valid `sender_auth` and no envelope authorizes a transfer by an unidentified originator, and the reverse identifies an originator who has authorized nothing. Every one of them takes a **signer, never a private key** — a hex key would force raw key material into a JavaScript string that cannot be zeroized, is copied on assignment, and lands in heap snapshots and any log line that stringifies the surrounding object, and it would exclude every custodian whose key sits in a KMS or an HSM. `signerFromEthersWallet` covers a local key; a custodial signer implements `signDigest` over its own call. The signature contract is 65 bytes of `r || s || v` with **v ∈ {0, 1}**: a signature whose v is already 27 or 28 is refused, because applying the alignment twice recovers a *different* address, which is a well-formed signature that verifies as somebody else. Also exported: `computeRequestHash`, `verifyDeclaration` (which **throws** rather than returning a flag, and refuses a document whose signature recovers a signer other than the one it claims), `verifyPaymentRequest` for checking what a `sender_auth` signature actually commits to before submitting, `didForAccount`, `verificationMethodForAccount`, and their types. See `docs/signing.md`.
|
|
102
|
+
- **`jsonld` is a new dependency**, and it is pinned exactly rather than floating. It runs URDNA2015, the canonicalization that determines exactly what a signature covers, so a minor release that changed its output would change what customers sign, on their machines, with nothing in our CI to notice.
|
|
47
103
|
- **`send-payment --prepare-only` and `send-payment --submit <file>`** split the single-shot command in two. `--prepare-only` builds and signs a payment request, prints it to stdout, and stops without submitting; `--submit` sends one that was prepared earlier (`-` reads stdin, so the two pipe together). Together they turn the single-shot command into an inspect-then-approve flow: the printed document is byte-for-byte what that run would have POSTed, so it can be read and reviewed before any money moves. Treat it like a signed cheque: it is a signed authorization rather than a draft and `--submit` needs no key, so delete the file once the payment is sent or abandoned. Re-preparing under the same `request_id` targets the same payment and cannot pay twice, but does not reproduce the same bytes: the deadlines are stamped from the clock on each run and the signature covers them. Two things to know. `--prepare-only` still calls the gateway, which is where the corridor addresses come from, so it is not an offline signing mode. And the exit-code table describes a *submitted* payment, so it does not apply under `--prepare-only`, where `0` means the request was built and signed and no payment exists — do not chain a payment-conditional step off such a run. If you intend to submit later, widen the quote window with `--quote-deadline-seconds` — but by tens of seconds, not minutes. A prepared document is submittable only while its window is open (the default is 10 seconds), and that same window is the settler auction: the gateway waits it out before selecting, and settler quotes expire on their own, so an over-long window ends in a terminal `QUOTES_EXPIRED`. `--submit` signs nothing and needs no private key, takes no corridor arguments, refuses the options that only shape a request being built rather than ignoring them, and reports with the same exit codes and streams as an ordinary run; it supports `--wait` the same way. The two flags are mutually exclusive, and a short invocation now names both forms rather than reporting a missing argument.
|
|
48
104
|
- The Permit2 approval prerequisite now appears at the top of `send-payment --help`, above the arguments and options, instead of in the last paragraph. It is the most common cause of a payment that is built and signed correctly and still fails to settle, and it was previously about a hundred lines below the usage line. The contract addresses stay at the end of the help, where the prerequisite points.
|
|
49
105
|
- **`waitForTerminalStatus` and `isTerminalStatus` are exported**, so following a submitted payment to its end is one call rather than a hand-written loop. A submission usually comes back `pending`, so waiting is the ordinary path, and the previous answer — write your own poll — put the burden of getting it right on every caller. A failed status check does not end the wait: a blip while a payment is settling is the worst moment to stop looking, so failures are counted in `errorCount`, reported through `onError`, and polling continues to the budget. The outcome reports `timedOut` so a caller can tell "still in flight" from "finished", which a bare loop cannot. This is the same helper behind the `send-payment --wait` flag, so the command-line tools and the SDK now agree by construction. `isTerminalStatus` is the single definition of which states are final, so a caller no longer keeps its own copy of that list in step with the contract. `budgetMs` is optional and in milliseconds, defaulting to `DEFAULT_WAIT_BUDGET_MS` (one minute); the seconds-based constant behind the command line's `--wait-seconds` stays internal, so there is one unit on the public surface and no way to pass 60 where 60000 was meant. An optional `signal` ends the wait early for a caller that must stop on shutdown or when its request is cancelled, and the outcome reports `aborted` — which always implies `timedOut`, so an interrupted wait can never be read as a settled payment. Also exported: `DEFAULT_WAIT_BUDGET_MS`, `DEFAULT_POLL_INTERVAL_MS`, `StatusSnapshot`, `WaitOutcome`, `WaitParams`.
|
package/LICENSE
CHANGED
|
@@ -1,83 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
TypeScript client for Atum Payment Gateway API with CLI support.
|
|
4
4
|
Full documentation: [docs.atum.xyz](https://docs.atum.xyz).
|
|
5
5
|
|
|
6
|
-
>
|
|
6
|
+
> Copyright 2026 Atum Labs, Inc.
|
|
7
7
|
>
|
|
8
|
-
>
|
|
8
|
+
> Licensed under the Apache License, Version 2.0. See the `LICENSE` file
|
|
9
|
+
> distributed with this package.
|
|
9
10
|
|
|
10
11
|
> NOTE: Before your first payment from an EVM or Tron chain, the source token must be approved
|
|
11
12
|
> for the Permit2 contract. Without it a payment is built, signed and accepted by the gateway,
|
|
@@ -15,8 +16,7 @@ Full documentation: [docs.atum.xyz](https://docs.atum.xyz).
|
|
|
15
16
|
|
|
16
17
|
## Installation
|
|
17
18
|
|
|
18
|
-
`@atumlabs/payment-gateway-client` is
|
|
19
|
-
has been granted access, install it with npm.
|
|
19
|
+
`@atumlabs/payment-gateway-client` is on the public npm registry.
|
|
20
20
|
|
|
21
21
|
To use the SDK in a project:
|
|
22
22
|
|
|
@@ -83,6 +83,7 @@ send-payment --submit <file> [options]
|
|
|
83
83
|
- `--gateway <url>` - Payment gateway URL (default: testnet)
|
|
84
84
|
- `--request-id <id>` - Idempotency key; seeds the on-chain deposit nonce. Re-run with the same id to re-attempt one payment. Omitted, an id is generated and printed, which makes every bare re-run a separate payment (see [Idempotency and retries](#idempotency-and-retries))
|
|
85
85
|
- `--request-id-prefix <prefix>` - Prefix for the auto-generated request id (default: `pmt-gw-cli`)
|
|
86
|
+
- `--max-source-amount <amount>` - Required to build a payment: the most the payer authorizes from source, in the source token's smallest units, signed into the Permit2. Never derived for you; the quoted `source_amount` from `request-quote` plus a slippage margin is the usual basis (the SDK's `capFromQuote` computes it). Not accepted with `--submit`
|
|
86
87
|
- `--prepare-only` - Build and sign the request, print it to stdout, and stop without submitting. For inspecting an authorization, or for review before paying; send it later with `--submit` (see [Preparing a payment for review](#preparing-a-payment-for-review)). Cannot be combined with `--wait`
|
|
87
88
|
- `--submit <file>` - Send a request built earlier by `--prepare-only`, instead of building one. Signs nothing and needs no private key; `-` reads stdin. Takes no corridor arguments
|
|
88
89
|
- `--wait` - After submitting, keep checking until the payment settles or fails instead of reporting it as still pending
|
|
@@ -97,8 +98,9 @@ runs the next step only for a settled payment:
|
|
|
97
98
|
| Code | Meaning |
|
|
98
99
|
| ---- | --------------------------------------------------------------------------- |
|
|
99
100
|
| `0` | `completed` — settled |
|
|
100
|
-
| `2` | `pending` — accepted, no result yet
|
|
101
|
-
| `3` | `failed`
|
|
101
|
+
| `2` | `pending`, `finalizing` or `refunding` — accepted, no result yet |
|
|
102
|
+
| `3` | `failed` or `refunded` — terminal; a fresh attempt needs a new `--request-id` |
|
|
103
|
+
| `4` | `refund_available` — not delivered, funds still in escrow; submit `refund_signature`, do not pay again |
|
|
102
104
|
| `1` | no outcome obtained (rejected, gateway unreachable, bad arguments) |
|
|
103
105
|
|
|
104
106
|
On `2`, follow the payment with **`payment-status <payment_id>`** — the id is in the
|
|
@@ -202,7 +204,8 @@ PRIVATE_KEY=0xabc... send-payment \
|
|
|
202
204
|
100000 \
|
|
203
205
|
eip155:42161/erc20:0xaf88d065e77c8cC2239327C5EDb3A432268e5831 \
|
|
204
206
|
TRX123... \
|
|
205
|
-
tron:shasta/trc20:TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs
|
|
207
|
+
tron:shasta/trc20:TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs \
|
|
208
|
+
--max-source-amount 101000
|
|
206
209
|
```
|
|
207
210
|
|
|
208
211
|
### Preparing a payment for review
|
|
@@ -215,7 +218,7 @@ one that was prepared earlier.
|
|
|
215
218
|
|
|
216
219
|
```bash
|
|
217
220
|
# 1. build and sign, submit nothing
|
|
218
|
-
send-payment --prepare-only --quote-deadline-seconds 30 \
|
|
221
|
+
send-payment --prepare-only --quote-deadline-seconds 30 --max-source-amount 101000 \
|
|
219
222
|
0xF0D0... 100000 \
|
|
220
223
|
eip155:42161/erc20:0xaf88d065e77c8cC2239327C5EDb3A432268e5831 \
|
|
221
224
|
0xMerchant... \
|
|
@@ -240,7 +243,7 @@ Four things to know:
|
|
|
240
243
|
it, so this is not an offline signing mode.
|
|
241
244
|
- **Widen the quote window if you intend to submit later — but only by tens of seconds.**
|
|
242
245
|
A prepared document is submittable only while its quote window is open, and the default
|
|
243
|
-
is
|
|
246
|
+
is 3 seconds. That window is also the auction: the gateway waits it out before choosing
|
|
244
247
|
a settler, and settler quotes expire on their own, so an over-long window ends in
|
|
245
248
|
`QUOTES_EXPIRED`. That failure is terminal, and a fresh attempt needs a new request id.
|
|
246
249
|
Give the reviewer enough time and no more.
|
|
@@ -378,6 +381,9 @@ async function sendPayment() {
|
|
|
378
381
|
sourceAsset: 'tron:shasta/trc20:TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs', // USDT on Tron Shasta
|
|
379
382
|
destinationAccount: '0xYourEthereumAddressHere',
|
|
380
383
|
destinationAsset: 'eip155:11142220/erc20:0x456a3D042C0DbD3db53D5489e98dFb038553B0d0', // USDC on Celo Sepolia
|
|
384
|
+
// Required. The most the payer authorizes from source, in USDT's smallest units, signed into
|
|
385
|
+
// the Permit2. The SDK never derives it; capFromQuote builds one from a settler quote.
|
|
386
|
+
maxSourceAmount: '101000',
|
|
381
387
|
// Required. Your stable idempotency key — reuse the SAME value on retry so a
|
|
382
388
|
// retry never becomes a second payment (see "Idempotency and retries" below).
|
|
383
389
|
requestId: 'order-4711',
|
|
@@ -417,10 +423,18 @@ async function sendPayment() {
|
|
|
417
423
|
console.log('Destination TX:', response.fulfillment_confirmation?.destination_tx_hash);
|
|
418
424
|
break;
|
|
419
425
|
case 'failed':
|
|
420
|
-
case 'cancelled':
|
|
421
426
|
// Terminal, and this request_id stays bound to it. A fresh attempt needs a NEW id.
|
|
422
427
|
console.error('Failed:', response.error?.code, response.error?.message);
|
|
423
428
|
break;
|
|
429
|
+
case 'refunded':
|
|
430
|
+
// Terminal and not delivered, so a fresh attempt needs a NEW id.
|
|
431
|
+
console.error('Refunded:', response.payment_id);
|
|
432
|
+
break;
|
|
433
|
+
case 'refund_available':
|
|
434
|
+
// Not delivered and the funds are still in escrow. getPaymentStatus(payment_id) returns
|
|
435
|
+
// refund_signature, which returns them. Do not pay again: a late delivery can still land.
|
|
436
|
+
console.error('Refund available:', response.payment_id);
|
|
437
|
+
break;
|
|
424
438
|
default:
|
|
425
439
|
// Still settling. Do not release goods, and do not pay again under a new id.
|
|
426
440
|
// Follow it with getPaymentStatus(payment_id); re-submitting this same request
|
|
@@ -453,11 +467,17 @@ it is what you need to find the payment again.
|
|
|
453
467
|
| Status | Meaning |
|
|
454
468
|
| --- | --- |
|
|
455
469
|
| `pending` | Accepted, not yet settled |
|
|
470
|
+
| `finalizing` | Paid on chain, collecting confirmations. Not final |
|
|
456
471
|
| `completed` | Delivered |
|
|
457
472
|
| `failed` | Did not settle |
|
|
458
|
-
| `
|
|
473
|
+
| `refunding` | Not delivered, the escrowed funds are being returned. Not final |
|
|
474
|
+
| `refund_available` | Not delivered, funds still in escrow. `getPaymentStatus` returns `refund_signature`, which you submit to the source escrow to return them. Not final: it becomes `refunded`, or `completed` if a late delivery is paid first |
|
|
475
|
+
| `refunded` | Not delivered, your funds were returned |
|
|
459
476
|
|
|
460
|
-
|
|
477
|
+
On the three refund statuses `refund_reason` says why the settler gave up, when it said. Act on
|
|
478
|
+
`status`, not on `refund_reason.retry_classification`.
|
|
479
|
+
|
|
480
|
+
`completed`, `failed` and `refunded` are final. A payment that reaches one of them keeps
|
|
461
481
|
its `request_id` for good, so re-submitting that id returns the same finished payment
|
|
462
482
|
rather than trying again — a genuine new attempt needs a **new** `request_id`. Any status
|
|
463
483
|
this client does not recognise is treated as still in flight. `isTerminalStatus` is exported
|
|
@@ -481,7 +501,7 @@ if (snapshot.error) {
|
|
|
481
501
|
console.error(
|
|
482
502
|
snapshot.error.code,
|
|
483
503
|
snapshot.error.message,
|
|
484
|
-
snapshot.error.blockchain_context?.
|
|
504
|
+
snapshot.error.blockchain_context?.transaction_hash ?? '',
|
|
485
505
|
);
|
|
486
506
|
}
|
|
487
507
|
```
|
|
@@ -578,18 +598,24 @@ investigate a payment that did not settle:
|
|
|
578
598
|
const timeline = await client.payments.getPaymentTimeline({ paymentId });
|
|
579
599
|
|
|
580
600
|
for (const step of timeline.steps) {
|
|
581
|
-
console.log(step.status, step.label, step.
|
|
601
|
+
console.log(step.status, step.label, step.transaction_hash ?? '');
|
|
582
602
|
}
|
|
583
603
|
|
|
584
604
|
if (timeline.error) {
|
|
585
605
|
// Why it failed, and where: for an on-chain failure this carries the chain id, the
|
|
586
606
|
// transaction hash and the revert reason.
|
|
587
|
-
console.error(
|
|
607
|
+
console.error(
|
|
608
|
+
timeline.error.code,
|
|
609
|
+
timeline.error.message,
|
|
610
|
+
timeline.error.blockchain_context?.revert_reason ?? '',
|
|
611
|
+
);
|
|
588
612
|
}
|
|
589
613
|
```
|
|
590
614
|
|
|
591
|
-
|
|
592
|
-
`
|
|
615
|
+
A payment reads the same on every endpoint: `getPayment`, `getPaymentStatus` and
|
|
616
|
+
`getPaymentTimeline` all report the one `PaymentStatus`. `finalizing` means the
|
|
617
|
+
transaction paying your recipient is on chain and accruing confirmations — it is not
|
|
618
|
+
final, and it is not a reason to treat the payment as delivered.
|
|
593
619
|
|
|
594
620
|
### Solana signing
|
|
595
621
|
|
|
@@ -847,9 +873,21 @@ See [docs/idempotency.md](docs/idempotency.md) for the full model: the two
|
|
|
847
873
|
guarantees and which endpoints each covers, when the `409` applies, how to read
|
|
848
874
|
the outcome, and the per-chain differences (EVM/Tron vs Solana).
|
|
849
875
|
|
|
876
|
+
## Signing
|
|
877
|
+
|
|
878
|
+
A PaymentRequest carries three unrelated signatures: `signPaymentRequest` authorizes the
|
|
879
|
+
on-chain transfer, `signDeclaration` attests the document, and an identity envelope carries the
|
|
880
|
+
originator. None substitutes for another.
|
|
881
|
+
|
|
882
|
+
Both signing surfaces take a **signer**, never a private key, so a key held in a KMS, an HSM or
|
|
883
|
+
a custodial provider works without leaving its boundary; `signerFromEthersWallet` covers a local
|
|
884
|
+
key. See [docs/signing.md](docs/signing.md) for which signature to use when, what the proof does
|
|
885
|
+
and does not cover, and the two details a custodial signer must get right.
|
|
886
|
+
|
|
850
887
|
## What is in the package
|
|
851
888
|
|
|
852
889
|
- `dist/` — compiled JavaScript and TypeScript declarations, ready to use
|
|
853
890
|
- `dist/cli/` — the five command-line tools
|
|
854
891
|
- `docs/` — reference documentation, including [idempotency and retries](docs/idempotency.md)
|
|
892
|
+
and [signing](docs/signing.md)
|
|
855
893
|
- `LICENSE`, `THIRD-PARTY-NOTICES.txt` — license terms and third-party attribution
|
package/THIRD-PARTY-NOTICES.txt
CHANGED
|
@@ -2,12 +2,11 @@ THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
|
|
|
2
2
|
==============================================================================
|
|
3
3
|
@atumlabs/payment-gateway-client
|
|
4
4
|
|
|
5
|
-
@atumlabs/payment-gateway-client is
|
|
6
|
-
|
|
5
|
+
@atumlabs/payment-gateway-client is licensed under the Apache License, Version 2.0, as stated
|
|
6
|
+
in the package-root LICENSE file. THIS file is not that license. This
|
|
7
7
|
package includes the third-party software identified below; the licenses and
|
|
8
8
|
notices reproduced here apply only to those third-party components. They do not
|
|
9
|
-
modify the
|
|
10
|
-
and they do not make it open source.
|
|
9
|
+
modify the Apache-2.0 license governing this package or any Atum-authored code.
|
|
11
10
|
|
|
12
11
|
The published artifact of this package (the compiled code under dist/) statically
|
|
13
12
|
bundles the third-party open-source components listed below; their source is
|
|
@@ -15,7 +14,7 @@ redistributed within this package, so their license and copyright notices are
|
|
|
15
14
|
reproduced here. Components and versions were taken from the exact modules the
|
|
16
15
|
build inlined. This file does NOT cover packages the consumer installs separately
|
|
17
16
|
as dependencies of this package (for example @solana/web3.js, axios, ethers, bs58,
|
|
18
|
-
commander, dotenv, tweetnacl, and zod) — those ship under their own licenses and are not
|
|
17
|
+
commander, dotenv, jsonld, tweetnacl, and zod) — those ship under their own licenses and are not
|
|
19
18
|
redistributed here.
|
|
20
19
|
|
|
21
20
|
LICENSE SUMMARY (1 component)
|