> Documentation index: https://docs.sellhidden.com/llms.txt

# Full walkthrough

Source: https://docs.sellhidden.com/walkthrough

The whole flow on one page: get a key, make a test payment, send the buyer to the payment page, check the signed webhook, deliver once, then go live.

## Your first test payment

### 1. Get a key.

**Developers** > **API keys** > **Create 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.

### 2. Create a test payment.

**Node** · `create.mjs`

```javascript
const res = await fetch("https://api.sellhidden.com/v1/payments", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.HIDDEN_API_KEY}`,
    "Content-Type": "application/json" },
  body: JSON.stringify({ amountUsd: 49,
    reference: "order-1042", test: true }),
});
const { ok, payment, error } = await res.json();
if (!ok) throw new Error(`${error.code}: ${error.message}`);
console.log(payment.url); // send the buyer there
```

**curl** · `shell`

```bash
curl -X POST \
  "https://api.sellhidden.com/v1/payments" \
  -H "Authorization: Bearer $HIDDEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amountUsd": 49, "reference": "order-1042", "test": true}'
```

**Python** · `create.py`

```python
import os, requests  # pip install requests
r = requests.post(
    "https://api.sellhidden.com/v1/payments",
    headers={"Authorization": f"Bearer {os.environ['HIDDEN_API_KEY']}"},
    json={"amountUsd": 49, "reference": "order-1042", "test": True},
    timeout=15)
body = r.json()
if not body["ok"]:
    raise RuntimeError(f"{body['error']['code']}: "
        f"{body['error']['message']}")
print(body["payment"]["url"])  # send the buyer there
```

**PHP** · `create.php`

```php
<?php
$ch = curl_init("https://api.sellhidden.com/v1/payments");
curl_setopt_array($ch, [
    CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ["Authorization: Bearer "
        . getenv("HIDDEN_API_KEY"), "Content-Type: application/json"],
    CURLOPT_POSTFIELDS => json_encode(["amountUsd" => 49,
        "reference" => "order-1042", "test" => true])]);
$body = json_decode(curl_exec($ch), true);
if (!$body["ok"]) throw new Exception($body["error"]["code"]
    . ": " . $body["error"]["message"]);
header("Location: " . $body["payment"]["url"], true, 303);
```

Response (201):

```json
{ "ok": true, "payment": {
    "id": "7K2Q-9XHD",
    "url": "https://sellhidden.com/order/7K2Q-9XHD",
    "status": "pending", "test": true } }
```

### 3. Open the url. Press Mark as paid.

Send the buyer to `payment.url`: Hidden hosts the payment page, never inside a frame. A test payment's page has no coin choice, only **Mark as paid** and **Mark as expired**: press Mark as paid and Hidden sends your server a real `payment.paid` event with `"test": true`. Deliver only on that signed event, never on `returnUrl`.

Read it back with `GET /payments/7K2Q-9XHD`: `status` is `"pending"` until you press Mark as paid, then `"paid"`. Test mode is one field: no test keys, no sandbox host, no money moves.

**Details**

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. Send the buyer, bring them back.

Your test payment works. Now send a buyer to the payment page, and bring them back after.

**Node** · `add to create.mjs`

```javascript
// 1. add to the create request
body: 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 there
return Response.redirect(payment.url, 303);
```

**curl** · `add to the request`

```bash
# 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
```

**Python** · `add to create.py`

```python
# 1. add to the create request
json={"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)
```

**PHP** · `add to create.php`

```php
// 1. add to the create request
CURLOPT_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 page
header("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. Add your webhook endpoint.

Hidden tells your server when a payment changes. Give it an address to call.

**Developers** > **Webhooks** > **Add 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. Hidden tells your server, signed.

Every event is signed with your secret. Check the signature before you trust the event.

```http
X-Hidden-Timestamp: <Unix seconds>
X-Hidden-Signature: sha256=<hex>
```

**Node** · `webhook.mjs`

```javascript
import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyHidden(raw, timestamp, signature, secret) {
  const age = Math.abs(Date.now() / 1000 - Number(timestamp));
  // missing, or more than 5 minutes off
  if (!timestamp || !(age <= 300)) return false;
  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);
}

export async function POST(req) {
  // the body exactly as sent: never parse it first
  const 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) return new Response("bad signature", { status: 401 });
  const { event, data } = JSON.parse(raw);
  if (event === "payment.paid" && !data.test)
    await fulfilOnce(data.reference, data.id); // your code
  return new Response("ok"); // any 2xx within 15 seconds
}
```

**curl** · `read it back`

```bash
# 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"
```

A shell cannot check a signature. Change the language to Node, Python or PHP.

**Python** · `verify.py`

```python
import hashlib, hmac, time

def verify_hidden(raw: bytes, timestamp: str, signature: str,
                  secret: str) -> bool:
    timestamp, signature = timestamp or "", signature or ""
    if (not timestamp.isascii() or not timestamp.isdigit()
            or abs(time.time() - int(timestamp)) > 300):
        return False  # missing, or more than 5 minutes off
    want = hmac.new(secret.encode(), timestamp.encode() + b"." + raw,
                    hashlib.sha256).hexdigest()
    return hmac.compare_digest(want.encode(),
        signature.removeprefix("sha256=").encode())
```

**PHP** · `verify.php`

```php
<?php
function verify_hidden(string $raw, string $timestamp,
    string $signature, string $secret): bool {
    if (!ctype_digit($timestamp)
        || abs(time() - (int) $timestamp) > 300) return false;
    $want = hash_hmac("sha256", $timestamp . "." . $raw, $secret);
    return hash_equals($want,
        preg_replace('/^sha256=/', '', $signature));
}
// $raw = file_get_contents("php://input");
// the headers are HTTP_X_HIDDEN_TIMESTAMP and
// HTTP_X_HIDDEN_SIGNATURE in $_SERVER
```

HMAC-SHA256 of `<timestamp>.<raw body>`, keyed with the whole `whsec_...` secret in `HIDDEN_WEBHOOK_SECRET`.

A test case for your signature check:
- Secret: `whsec_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef`
- Timestamp: `1794910361`
- Body: `{"id":"evt_0123456789abcdef","event":"payment.paid","createdAt":"2026-11-17T10:12:41.000Z","data":{"id":"7K2Q-9XHD","status":"paid","amountUsd":49}}`
- Signature: `sha256=dc2d0686941478580ce6baf166d24016b291529e1c3cc72819295b2520171a08`

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. Handle `payment.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.

**Node** · `webhook.mjs`

```javascript
import { createHmac, timingSafeEqual } from "node:crypto";

export async function POST(req) {
  const raw = await req.text(); // as sent: never parse it first
  const ok = verifyHidden(raw, req.headers.get("x-hidden-timestamp"),
    req.headers.get("x-hidden-signature"),
    process.env.HIDDEN_WEBHOOK_SECRET);
  if (!ok) return new 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 payment
  return new Response("ok"); // any 2xx within 15 seconds
}

// a retry repeats the event id: deliver once
const delivered = new Set(); // your database in production
async function fulfilOnce(reference, paymentId) {
  if (delivered.has(paymentId)) return;
  // your code: deliver order `reference` here
  delivered.add(paymentId);
}

export function verifyHidden(raw, timestamp, signature, secret) {
  const age = Math.abs(Date.now() / 1000 - Number(timestamp));
  // missing, or more than 5 minutes off
  if (!timestamp || !(age <= 300)) return false;
  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);
}
```

**curl** · `read it back`

```bash
# 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 webhook handler is in Node, Python and PHP; this curl only reads the payment back.

**Python** · `webhook.py`

```python
import hashlib, hmac, json, os, time
from flask import Flask, request  # pip install flask

app = 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"])
    if not ok:
        return "bad signature", 401
    body = json.loads(raw)
    data = body["data"]
    if (body["event"] == "payment.paid" and data["status"] == "paid"
            and not data["test"]):
        fulfil_once(data.get("reference"), data["id"])
    return "ok"  # any 2xx within 15 seconds

delivered = set()  # use your database in production

def fulfil_once(reference, payment_id):
    # a retry repeats the event id: deliver once
    if 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 off
    if (not timestamp.isascii() or not timestamp.isdigit()
            or abs(time.time() - int(timestamp)) > 300):
        return False
    want = hmac.new(secret.encode(), timestamp.encode() + b"." + raw,
                    hashlib.sha256).hexdigest()
    return hmac.compare_digest(want.encode(),
        signature.removeprefix("sha256=").encode())
```

**PHP** · `webhook.php`

```php
<?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 once
function 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) return false;
    $want = hash_hmac("sha256", $timestamp . "." . $raw, $secret);
    return hash_equals($want,
        preg_replace('/^sha256=/', '', $signature));
}
```

- Add your endpoint now, at a public https address: test events need it too ([step 3](https://docs.sellhidden.com/payments#add-endpoint)).
- 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**

| Event | What it means |
| --- | --- |
| `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. Turn on live payments.

Everything works in test. These steps take real payments.

### 1. Add your website.

**Developers** > **Payments** > **Add website**

Under **Your websites**, fill **Website address**. "Payments" is a tab, not in the sidebar.

### 2. Then turn on the switch. Store owner only.

**Accept payments through the API**

### 3. Remove `test` from the create request.

**Before your first live payment**

- [ ] Key on your server only, "Write" on "Payments".
- [ ] Payments created by your server, never a web page.
- [ ] A new `reference` for each order.
- [ ] The four "Payments" events ticked.
- [ ] A bad signature answers `401`.
- [ ] Deliver on `payment.paid`, once per `data.id`.
- [ ] Answer 2xx within 15 seconds.
- [ ] Never deliver on `returnUrl`.
- [ ] Website added, then the switch on.
- [ ] `test` removed from the create request.

## When things go wrong

### 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](https://docs.sellhidden.com/reference#responses)).

| Status | Code | When | Do |
| --- | --- | --- | --- |
| 400 | `validation_error` | A field breaks a rule. `field` names it. | Fix that field. |
| 400 | `site_not_allowed` | `returnUrl` or `cancelUrl` is not on your websites. | Add the website. Match the origin exactly. |
| 401 | `unauthorized` | Key missing or wrong. Also `key_revoked`, `key_expired`. | Use a valid key. |
| 403 | `insufficient_scope` | The key lacks `payments:write` ([scopes](https://docs.sellhidden.com/reference#scopes)). | A new key with "Write" on "Payments". |
| 403 | `server_only` | Created from a web page. | Call from your server. |
| 403 | `payments_off` | A live payment, and the switch is off. | Add the website, then turn on the switch. |
| 409 | `reference_in_use` | This reference is open with another amount, or expired a short while ago. | Cancel it, wait, or use a new reference. |
| 409 | `reference_paid` | This reference is already paid. | Do not charge again. |
| 429 | `rate_limited` | Too many requests. Also `daily_limit`, `open_limit`. | Wait `Retry-After`. Cancel unused payments. |

## Other pages

- [Run your first payment](https://docs.sellhidden.com): One payment, part by part: request, page, webhook.
  - [Check the signature](https://docs.sellhidden.com#check-the-signature)
  - [Deliver once](https://docs.sellhidden.com#deliver-once)
- [API reference](https://docs.sellhidden.com/reference/payments): Payments: five calls, the payment object, statuses, events and errors.
  - [Create a payment](https://docs.sellhidden.com/reference/payments#payments-payments-create)
  - [The payment object](https://docs.sellhidden.com/reference/payments#object)
  - [Statuses and events](https://docs.sellhidden.com/reference/payments#statuses)
  - [Errors](https://docs.sellhidden.com/reference/payments#errors)
