Your backend drives every step of the payment and your own UI talks to the player's wallet.
How it works
The same payment as the hosted page, with you rendering it. Your backend opens a session and
forwards each step the player takes; the response tells your frontend what to show next and, when
it is time, what to ask the player's wallet to sign. The API secret stays on your server.
Your backend
Opens the session with POST /v1/direct/init and passes the first step to your frontend.
Your frontend
Renders the step: network, wallet, coin, amount. Sends the player's choice to your backend.
Receives payment.completed or payment.failed and credits the player.
Every call is signed as described in Authentication. Start with the
hosted page if you can: the settlement side is identical and you can
move here later without changing your webhook handling or ledger.
Methods, in call order
All three are signed and called from your backend.
Direct · host-to-host
Your backend drives every step of the deposit and your frontend renders it and talks to the player's wallet. The API secret never reaches a browser.
POST/v1/direct/initsigned
Open a deposit session
Starts a session and returns its first step. Everything in the body is optional, but sending external_order_id is what makes a retry safe.
Prefilled values are validated here, because the steps that would normally check them are the ones being skipped. With no prefill the session starts at network_select; with network at connect_wallet, and the coin picker follows once a wallet is connected; with both at connect_wallet and no picker; add amount and the player's only remaining action is connecting a wallet. See prefilling.
Request body
Field
Type
Required
Description
player_id
string
no
Your player reference. Echoed back in the settlement webhook.
external_order_id
string
no
Your order reference, and the idempotency key: repeating a create with the same reference and the same parameters returns the original session instead of opening a second one. Reusing it with different parameters is a conflict.
callback_url
string (uri)
no
Per-session override of the webhook target configured for your merchant. Empty falls back to the merchant default.
amount
string
no
Optional prefill in whole units, e.g. "125.50". Skips the enter_amount step.
network
string
no
Optional prefill of the network, when you already know which one the player is paying on. Skips the network_select step.
token
string
no
Optional prefill of the asset. Requires network; sending both starts the session at connect_wallet.
language
string
no
The language the step views are written in, as an ISO 639-1 code. A region is ignored, so "en-GB" is English. Unsupported or missing falls back to English rather than failing the call. One of: en, ru, es, uk, kk, uz, ky, tg, az, hy, ka, tr, de, fr, it, pt, pl
400unsupportedMalformed JSON, an unknown network or token, a token sent without a network, or an amount that is not a positive number. Codes: validation, unsupported.
401unauthorizedThe signature, key, timestamp or nonce did not check out: a missing header, an unknown key id, a timestamp more than 5 minutes from ours, a signature that does not match, or a nonce already used inside the window. Do not retry without rebuilding the request — a retry needs a new timestamp, a new nonce and a new signature.
403forbiddenThe credential is valid but the caller's IP is not in the allowlist configured for your merchant. Not retryable.
{
"error": {
"code": "forbidden",
"message": "client IP not allowed for this merchant"
}
}
409conflictThis external_order_id already belongs to a session created with different parameters. Repeating a create with identical parameters is safe and returns the original session; changing the amount, player or token under a reference you already used is not, and is refused rather than silently resolved.
{
"error": {
"code": "conflict",
"message": "external_order_id \"deposit-1001\" already belongs to session sess_9f2c1e with different parameters"
}
}
503unavailableA dependency we need to answer safely is degraded, so the request was refused rather than served wrongly. Transient: retry with backoff, using a fresh timestamp, nonce and signature.
Submits the action the current step asked for and returns the next step. The action name and the shape of its value come from the step you are on — see the step machine.
Request body
Field
Type
Required
Description
session
string
yes
Session id returned by init.
action
string
yes
The action the current step expects, e.g. select_network.
value
string
no
The action's value. Empty for actions that carry none, such as poll.
400invalid_actionAn action that does not belong to the current step, a terminal session being advanced, a malformed value such as an address or transaction hash of the wrong shape, or a payer wallet that does not hold enough of the token to cover the deposit. Codes: validation, invalid_action, insufficient_funds, insufficient_allowance, tx_reverted.
{
"error": {
"code": "invalid_action",
"message": "action \"submit_amount\" is not valid at step \"connect_wallet\""
}
}
401unauthorizedThe signature, key, timestamp or nonce did not check out: a missing header, an unknown key id, a timestamp more than 5 minutes from ours, a signature that does not match, or a nonce already used inside the window. Do not retry without rebuilding the request — a retry needs a new timestamp, a new nonce and a new signature.
503unavailableA dependency we need to answer safely is degraded, so the request was refused rather than served wrongly. Transient: retry with backoff, using a fresh timestamp, nonce and signature.
Read-only and safe to poll while the chain listener settles in the background. Each poll is a separate signed request and therefore needs its own nonce.
401unauthorizedThe signature, key, timestamp or nonce did not check out: a missing header, an unknown key id, a timestamp more than 5 minutes from ours, a signature that does not match, or a nonce already used inside the window. Do not retry without rebuilding the request — a retry needs a new timestamp, a new nonce and a new signature.
503unavailableA dependency we need to answer safely is degraded, so the request was refused rather than served wrongly. Transient: retry with backoff, using a fresh timestamp, nonce and signature.
Your backend drives the session and your frontend renders it. Each step comes back as a small UI
schema — headings, buttons, inputs — plus, when the player has to sign something, an opaque
wallet_action you forward to their wallet untouched. The API secret never reaches a
browser because every call goes through your own backend.
Open a session with POST /v1/direct/init and remember its session against the player. Prefill what you already know and the matching steps are skipped.
Render the step from components, and send the action it asks for to POST /v1/direct/step — through your backend, which adds the session id and the signature.
Forward wallet actions to window.ethereum.request exactly as given, then submit the resulting transaction hash with the submit_action the step named.
Poll with the poll action while the step is processing, and credit from the webhook.
The browser never talks to us. It posts {action, value} to your backend, which looks
up the player's session, signs the call and passes the step back. Pass our error code through so
the page can word it.
func paymentStep(client *time2pay.Client, sessionOf func(r *http.Request) (string, error)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session, err := sessionOf(r)
if err != nil {
http.Error(w, "no open deposit", http.StatusNotFound)
return
}
var in struct {
Action string `json:"action"`
Value string `json:"value"`
}
if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
http.Error(w, "bad request", http.StatusBadRequest)
return
}
body, _ := json.Marshal(map[string]string{"session": session, "action": in.Action, "value": in.Value})
step, err := client.Call(r.Context(), "POST", "/v1/direct/step", string(body))
var apiErr *time2pay.Error
if errors.As(err, &apiErr) {
w.WriteHeader(apiErr.Status)
_ = json.NewEncoder(w).Encode(map[string]any{"error": map[string]string{"code": apiErr.Code}})
return
}
if err != nil {
http.Error(w, "try again", http.StatusBadGateway)
return
}
_ = json.NewEncoder(w).Encode(step)
}
}
Plain browser JavaScript; render is yours — it draws components. The
wallet request is forwarded exactly as the step gave it, including the chain switch when
chain_id is set.
The wallet is asked for before the coin. Which coins are worth offering is a question about the
player's wallet: token_select carries the balance the connected wallet holds in each
one, and greys out the coins it cannot open a deposit with. Options on that step may therefore
arrive with note, disabled and reason set — render a
disabled option, do not drop it, or the player is told a coin you accept is unsupported.
A player may also send change_wallet (no value) from token_select,
enter_amount or awaiting_approval to return to
connect_wallet and pay from a different address. It is refused from
awaiting_payment onwards, where the order is already bound to the wallet that
approved it. A coin the player chose is re-chosen with the new wallet; a coin you prefilled is
kept.
Step
Action to send
Value
Moves to
network_select
select_network
the value of the option the player picked
connect_wallet
connect_wallet
wallet_connected
0x + 40 hex chars
token_select, or straight past it when you prefilled token
token_select
select_token
the value of the option the player picked
enter_amount, or awaiting_approval / awaiting_payment when the amount was prefilled
enter_amount
submit_amount
positive decimal
awaiting_approval, or awaiting_payment
awaiting_approval
approval_submitted
0x + 64 hex chars
awaiting_payment
awaiting_payment
signature_submitted
0x + 64 hex chars
processing
processing
poll
empty
processing, completed, failed, reverted
The approval step is skipped when it is not needed. Before asking for one we read
the allowance the wallet has already granted the router; a player who approved enough in an
earlier deposit goes straight to awaiting_payment. Never assume the step order —
render whatever step the response names.
Wait for the approval transaction to be mined before sending the payment transaction. Otherwise
transferFrom reverts, because the allowance is not visible on-chain yet — and
approval_submitted is refused with tx_reverted or unavailable
until the allowance is readable.
Terminal steps
completed, failed and reverted all end the session, and all
three carry an order status of completed or failed —
branch on the status, and use the step only to word the screen. reverted is a
payment that was mined and rejected by the chain: the player's tokens never moved and only their
gas was spent, which is the opposite of what a generic failure message implies.
Prefilling
network, token and amount are optional on both create
calls and mean the same thing in each: when you already know what the player is depositing, the
matching step is skipped and the session starts further along.
Prefilling token does more than skip a screen. The coin picker runs after the wallet
connects and lists what that wallet holds, so a session without a prefilled token gives the player
the coins they can actually pay with — and lets them pick a different one if they change wallets.
Prefill the token only when the order really is denominated in it.
You send
Session starts at
nothing
network_select
network
connect_wallet, then token_select
network + token
connect_wallet, and the coin picker is skipped
network + token + amount
connect_wallet, and the player is never asked for a coin or an amount
Prefilled values are validated when the session is created, because the steps that would normally
check them are exactly the ones being skipped. An unknown network, a token that does not exist on
that network, a token without a network, or an amount that is not a positive number are all
rejected at create time rather than surfacing at settlement.
Deposit statuses
Status
Set by
Meaning
pending
the session
Created; no payment transaction submitted yet.
processing
the session
Payment transaction submitted; waiting for confirmations.
completed
the chain listener
Reached the required confirmation depth. This is when you credit.
failed
the chain listener
Settlement was unsuccessful.
Confirmation depth is amount-based: larger deposits wait for more blocks. The listener matches a
payment by orderRef (which is keccak256(session_id)) and falls back to
the transaction hash, so a deposit reconciles even if the browser never reported the hash.
Webhooks are the way to learn the outcome. If one never arrives — your endpoint was down through
every retry — read the session with /v1/direct/status
and credit from its status, deduplicating on external_order_id exactly
as the webhook handler does.
Webhooks in this flow
Each is a POST to your callback URL, signed with your API key secret. Verify it as described in
Verifying the signature, deduplicate on
X-Idempotency-Key and answer any 2xx.
Any 2xx marks the delivery successful. Anything else is retried with backoff: 30s, 1m, 2m … 1h, up to 8 attempts.
POSTpayment.failedno signature
A deposit failed
Sent to your callback URL when a deposit session ends without a valid payment. failure_code is one of abandoned, not_found, stuck, reverted or rejected; failure_reason is human-readable and may change. Do not credit the player. Signed with your API key secret. Deduplicate on X-Idempotency-Key.
Body
{
"event": "payment.failed",
"session_id": "01J8ZQ9D2F6H0K3M7P1S4V8Y5B",
"merchant_id": "acme-shop",
"player_id": "player-77421",
"amount": "250.000000",
"status": "failed",
"failure_code": "abandoned",
"failure_reason": "session expired before a payment was seen",
"occurred_at": "2026-08-05T13:12:07Z"
}
Response 200
Any 2xx marks the delivery successful. Anything else is retried with backoff: 30s, 1m, 2m … 1h, up to 8 attempts.