From a key to live payments, in Language for the whole page: curlNodePythonPHP.
Jump to a step
1Get a key.
DevelopersAPI keysCreate a key
In Permissions: Read only, then Write on Payments. Create key, copy it from Copy your new API key (shown once) into HIDDEN_API_KEY. Needs a verified email.
2Create a test payment.
Language for the whole page: curlNodePythonPHPcreate.mjsshellcreate.pycreate.phptest: true"test": true"test": True"test" => true
Test mode is one field: no test keys, no sandbox host, no money moves.Paid. No money moved. Now let your server hear itExpired. Nothing was paid, and the reference is free again.
What the buyer sees, what the API never returns, and what the samples run on.
The API never returns a deposit address, a coin amount or a QR code: the buyer picks a coin and pays on the Hidden page.
The page shows your store name, the amount and "Powered by Hidden" on every plan except Enterprise. It speaks 12 languages and works on phones.
The samples run on Node 18, Python 3.9 and PHP 8, or later.
4.Sendthebuyer,bringthemback.
Your test payment works. Now send a buyer to the payment page, and bring them back after.
Language for the whole page: curlNodePythonPHPadd to create.mjsadd to the requestadd to create.pyadd to create.php
// 1. add to the create requestbody: JSON.stringify({ amountUsd: 49, reference: "order-1042", returnUrl:"https://shop.example.com/thanks?order=1042", cancelUrl: "https://shop.example.com/cart", test: true }),// 2. in your route, send the buyer therereturn Response.redirect(payment.url, 303);
# 1. add to the create request-d '{"amountUsd": 49, "reference": "order-1042","returnUrl":"https://shop.example.com/thanks?order=1042","cancelUrl": "https://shop.example.com/cart", "test": true}'# 2. then open payment.url in a browser
# 1. add to the create requestjson={"amountUsd": 49, "reference": "order-1042","returnUrl":"https://shop.example.com/thanks?order=1042","cancelUrl": "https://shop.example.com/cart", "test": True},# 2. in your Flask route (from flask import redirect):return redirect(body["payment"]["url"], code=303)
// 1. add to the create requestCURLOPT_POSTFIELDS => json_encode(["amountUsd" => 49,"reference" => "order-1042","returnUrl" =>"https://shop.example.com/thanks?order=1042","cancelUrl" => "https://shop.example.com/cart", "test" => true]),// 2. then send the buyer to the payment pageheader("Location: " . $body["payment"]["url"], true, 303);
A 303 to payment.url, or a link: the payment page cannot be shown inside a frame. Both URLs: https, on one of your websites, same origin exactly. A test payment may also return to localhost.
Your return page
Thanks the buyer and shows the order as your webhook left it, or reads GET /payments/7K2Q-9XHD.
Never delivers: anyone can open that URL. Hidden adds nothing to it.
Paid while the page is open, or opened within 15 minutes: back to returnUrl after 5 seconds.
cancelUrl is the "Back to Nova Studio" link when a payment expires, is cancelled or is short.
5.Addyourwebhookendpoint.
Hidden tells your server when a payment changes. Give it an address to call.
DevelopersWebhooksAdd endpoint
Endpoint URL: your public https address. In Events, untick order.paid, tick the four under Payments:
payment.paid
payment.underpaid
payment.expired
payment.cancelled
Add endpoint shows the signing secret once: copy it into HIDDEN_WEBHOOK_SECRET.
6.Hiddentellsyourserver,signed.
Every event is signed with your secret. Check the signature before you trust the event.
Language for the whole page: curlNodePythonPHPwebhook.mjsread it backverify.pyverify.php
import { createHmac, timingSafeEqual } from"node:crypto";exportfunction verifyHidden(raw, timestamp, signature, secret) {const age = Math.abs(Date.now() / 1000 - Number(timestamp));// missing, or more than 5 minutes offif (!timestamp || !(age <= 300)) returnfalse;const want = Buffer.from(createHmac("sha256", secret) .update(`${timestamp}.${raw}`).digest("hex"));const got = Buffer.from( String(signature ?? "").replace(/^sha256=/, ""));return got.length === want.length && timingSafeEqual(got, want);}exportasyncfunction POST(req) {// the body exactly as sent: never parse it firstconst raw = await req.text();const ok = verifyHidden(raw, req.headers.get("x-hidden-timestamp"), req.headers.get("x-hidden-signature"), process.env.HIDDEN_WEBHOOK_SECRET);if (!ok) returnnew Response("bad signature", { status: 401 });const { event, data } = JSON.parse(raw);if (event === "payment.paid" && !data.test)await fulfilOnce(data.reference, data.id); // your codereturnnew Response("ok"); // any 2xx within 15 seconds}
# A shell cannot take a webhook.# Read the payment back instead:curl https://api.sellhidden.com/v1/payments/7K2Q-9XHD \ -H "Authorization: Bearer $HIDDEN_API_KEY"
The timestamp is old, so the 5-minute check refuses it: for this test, check the HMAC alone or set the clock to 1794910361.
7.Handlepayment.paid,once.
When the payment is paid, deliver the order one time. Here is the whole webhook file.
Deliver only when all three are true:
data.status is paid
data.test is false
Once per data.id
Never on returnUrl: anyone can open that URL.
Language for the whole page: curlNodePythonPHPwebhook.mjsread it backwebhook.pywebhook.php
import { createHmac, timingSafeEqual } from"node:crypto";exportasyncfunction POST(req) {const raw = await req.text(); // as sent: never parse it firstconst ok = verifyHidden(raw, req.headers.get("x-hidden-timestamp"), req.headers.get("x-hidden-signature"), process.env.HIDDEN_WEBHOOK_SECRET);if (!ok) returnnew Response("bad signature", { status: 401 });const { event, data } = JSON.parse(raw);if (event === "payment.paid" && data.status === "paid" && !data.test)await fulfilOnce(data.reference, data.id); // once per paymentreturnnew Response("ok"); // any 2xx within 15 seconds}// a retry repeats the event id: deliver onceconst delivered = new Set(); // your database in productionasyncfunction fulfilOnce(reference, paymentId) {if (delivered.has(paymentId)) return;// your code: deliver order `reference` here delivered.add(paymentId);}exportfunction verifyHidden(raw, timestamp, signature, secret) {const age = Math.abs(Date.now() / 1000 - Number(timestamp));// missing, or more than 5 minutes offif (!timestamp || !(age <= 300)) returnfalse;const want = Buffer.from(createHmac("sha256", secret) .update(`${timestamp}.${raw}`).digest("hex"));const got = Buffer.from( String(signature ?? "").replace(/^sha256=/, ""));return got.length === want.length && timingSafeEqual(got, want);}
# A shell cannot take a webhook.# Read the payment back instead:curl https://api.sellhidden.com/v1/payments/7K2Q-9XHD \ -H "Authorization: Bearer $HIDDEN_API_KEY"
import hashlib, hmac, json, os, timefrom flask import Flask, request # pip install flaskapp = Flask(__name__)@app.post("/hidden/webhook")def hidden_webhook(): raw = request.get_data() # as sent: never parse it first ok = verify_hidden( raw, request.headers.get("X-Hidden-Timestamp"), request.headers.get("X-Hidden-Signature"), os.environ["HIDDEN_WEBHOOK_SECRET"])ifnot ok:return"bad signature", 401 body = json.loads(raw) data = body["data"]if (body["event"] == "payment.paid"and data["status"] == "paid"andnot data["test"]): fulfil_once(data.get("reference"), data["id"])return"ok"# any 2xx within 15 secondsdelivered = set() # use your database in productiondef fulfil_once(reference, payment_id):# a retry repeats the event id: deliver onceif payment_id in delivered:return# your code: deliver order `reference` here delivered.add(payment_id)def verify_hidden(raw: bytes, timestamp: str, signature: str, secret: str) -> bool:# a missing header arrives as None timestamp, signature = timestamp or"", signature or""# refuse it when missing, malformed,# or more than 5 minutes offif (not timestamp.isascii() ornot timestamp.isdigit()or abs(time.time() - int(timestamp)) > 300):returnFalse want = hmac.new(secret.encode(), timestamp.encode() + b"." + raw, hashlib.sha256).hexdigest()return hmac.compare_digest(want.encode(), signature.removeprefix("sha256=").encode())
<?php$raw = file_get_contents("php://input"); // the raw body$ok = verify_hidden($raw, $_SERVER["HTTP_X_HIDDEN_TIMESTAMP"] ?? "", $_SERVER["HTTP_X_HIDDEN_SIGNATURE"] ?? "", (string) getenv("HIDDEN_WEBHOOK_SECRET"));if (!$ok) { http_response_code(401); exit("bad signature"); }$body = json_decode($raw, true);$data = $body["data"];if ($body["event"] === "payment.paid" && $data["status"] === "paid" && !$data["test"]) { fulfil_once($data["reference"] ?? "", $data["id"]);}echo"ok"; // any 2xx within 15 seconds// a retry repeats the event id: deliver oncefunction fulfil_once(string $reference, string $paymentId): void {// use your database in production; a file marks it here $mark = sys_get_temp_dir() . "/hidden-" . bin2hex($paymentId);if (file_exists($mark)) return;// your code: deliver order $reference here touch($mark);}function verify_hidden(string $raw, string $timestamp,string $signature, string $secret): bool {if (!ctype_digit($timestamp) || abs(time() - (int) $timestamp) > 300) returnfalse; $want = hash_hmac("sha256", $timestamp . "." . $raw, $secret);return hash_equals($want, preg_replace('/^sha256=/', '', $signature));}
The webhook handler is in Node, Python and PHP; this curl only reads the payment back.
Add your endpoint now, at a public https address: test events need it too (step 3).
Checks X-Hidden-Signature on the raw body with HIDDEN_WEBHOOK_SECRET. Bad: 401.
Delivers when data.status is paid and data.test is false, once per data.id.
Payment events
payment.paid
Deliver, once.
payment.underpaid
Short: the rest has 48 hours.
payment.expired
Not final: can still be paid.
payment.cancelled
Final.
Answer 2xx within 15 seconds, or Hidden tries 7 times over about 45 hours, same event id. Mark as paid sends a real event with "test": true: nothing is delivered.
8.Turnonlivepayments.
Everything works in test. These steps take real payments.
1Add your website.
DevelopersPaymentsAdd website
Under Your websites, fill Website address. "Payments" is a tab, not in the sidebar.
2Then turn on the switch. Store owner only.
Accept payments through the API
3Remove test from the create request.
Before your first live payment0 of 10
A payment arrives short.
Short by more than the store's tolerance: status underpaid, event payment.underpaid. Do not deliver yet.
The buyer has 48 hours to send the rest ("Send the rest" on the page). Then payment.paid comes.
Short within the tolerance counts as paid: shortUsd shows the gap.
To complete it on what arrived: POST /payments/{id}/accept. It cannot be undone.
A test payment cannot be short.
Expired, then paid.
expired is not final. A late transfer can still make it paid, or underpaid if it is short.
Keep the order open on payment.expired. Deliver on payment.paid, as always.
The API shows expired once expiresAt passes. The event follows within about 30 minutes.
expiresInMinutes: 15 to 1,440. Default 60.
A reference used twice.
Same reference, amount and test while open: 200, "existing": true, the same payment.
Another amount while open, or expired less than 2 hours ago after the buyer got an address: 409 reference_in_use.
Already paid: 409 reference_paid. Do not charge again.
Testing: a new reference each time, or press "Mark as expired" to free it.
The signature does not match.
Check the body exactly as it arrived. Express: express.raw({ type: "application/json" }) on this route, never express.json() first. Flask: request.get_data(). PHP: php://input.
Nothing in front of your server may rewrite the JSON.
Use this endpoint's whole whsec_ secret (the new one after a rotate), never the API key.
Your server clock must be within 5 minutes of the real time.
Refunds.
Crypto payments are final: Hidden does not send refunds for API payments.
To refund a buyer, send them the money yourself.
Errors.
Errors come as { "ok": false, "error": { "code", "message", "field" } } (responses).
CodeWhenDo
400validation_error
A field breaks a rule. field names it.
Fix that field.
400site_not_allowed
returnUrl or cancelUrl is not on your websites.
Add the website. Match the origin exactly.
401unauthorized
Key missing or wrong. Also key_revoked, key_expired.