# Soheil Pay: API reference

Source: https://soheil.fi/pay/docs/

Create an invoice from your server, send the buyer to its payment page, and get a signed message when it is paid. The money goes from the buyer to your own wallet; this API never moves funds.

## Quick start

1.  Sign in to the [dashboard](https://soheil.fi/pay/dashboard/) and add the address you want to be paid at on each network.
2.  Under Developers, create an API key and set your webhook address.
3.  Create an invoice and redirect the buyer to its `url`.
4.  When your webhook receives `invoice.paid` (after checking the signature), deliver the order.

```bash
curl -X POST https://soheil.fi/api/pay/v1/invoices \
  -H "Authorization: Bearer sp_live_…" \
  -H "Content-Type: application/json" \
  -d '{"amountUsd":"25.00","description":"VPN, 1 month","orderId":"1042","redirectUrl":"https://your-shop.example/thanks"}'
```

## Plugins

Two shop systems need no code: install the plugin, paste an API key, and Soheil Pay appears at checkout. Both use this same API.

| Shop system | Download | How to install |
| --- | --- | --- |
| WooCommerce (WordPress) | [soheil-pay-woocommerce.zip](https://soheil.fi/downloads/soheil-pay-woocommerce.zip) | Plugins → Add new → Upload plugin, then WooCommerce → Settings → Payments. |
| WHMCS | [soheil-pay-whmcs.zip](https://soheil.fi/downloads/soheil-pay-whmcs.zip) | Unzip into the WHMCS folder, then Setup → Payments → Payment gateways. |

## Authentication

Send your key as `Authorization: Bearer sp_live_…` over HTTPS, from your server only. A key can create, read and cancel invoices. It cannot change your addresses, webhook or keys: those need a signed-in browser. Errors are JSON, `{"message": "…"}`, with a 4xx status.

## Create an invoice

`POST /api/pay/v1/invoices` (API key)

- `amountUsd` (string, required): The price in US dollars, with at most two decimals. The buyer pays this amount in a one-dollar stablecoin. Leave it out when you price in another currency.
- `currency` (string): A three-letter currency code (`EUR`, `GBP`, `TRY`, …) to price the invoice in, together with `amount`. The currencies available now are in `GET /api/pay/v1/config` under `currencies`.
- `amount` (string): The price in `currency`, with at most two decimals. It is turned into US dollars once, at that moment's rate, and the invoice keeps both: `amountUsd` is what the buyer pays, `price` is what you asked.
- `description` (string): Shown to the buyer on the payment page. Up to 300 characters.
- `orderId` (string): Your own order number, up to 100 characters. Asking again with the same number answers the same invoice while it can still be paid or was paid, so a retry never bills twice. After that invoice ran out or was cancelled, the same number gets a new invoice.
- `redirectUrl` (string): Where the payment page sends the buyer back to. Must start with https://.
- `expiresInMinutes` (number): How long the buyer has. From 5 minutes to 72 hours; one hour when left out.

The answer is the invoice:

```json
{
  "id": "inv_8Qm2…",
  "url": "https://soheil.fi/invoice/?id=inv_8Qm2…",
  "status": "open",          // open, underpaid, paid, overpaid, expired, cancelled
  "late": false,             // paid after it ran out
  "test": false,
  "amountUsd": "25.00",
  "description": "VPN, 1 month",
  "orderId": "1042",
  "redirectUrl": "https://your-shop.example/thanks",
  "createdAt": "2026-11-21T12:00:00Z",
  "expiresAt": "2026-11-21T13:00:00Z",
  "paidAt": null,
  "paidFrom": null,          // paid from another network: what the buyer sent, e.g. "ETH on Base"
  "payments": [],            // one entry per network and token the buyer opened
  "refundedUsd": "0",
  "refunds": []
}
```

An invoice priced in another currency also carries `"price": { "currency": "EUR", "amount": "19.99", "usdPerUnit": "1.08" }`; for a dollar invoice `price` is `null`. Rates are the European Central Bank's daily reference rates. When a currency has no fresh rate the request is refused with a 400 that lists the currencies you can use: a price is never guessed.

> **402 Payment Required**Your prepaid fee balance has been below zero for longer than the grace time. Top it up in the dashboard; invoices already open still complete.

## Read, list and cancel

`GET /api/pay/v1/invoices/{id}` (API key)

`GET /api/pay/v1/invoices?status=paid&before=2026-11-21T00:00:00Z&limit=50` (API key)

`POST /api/pay/v1/invoices/{id}/cancel` (API key)

The list is newest first; pass the `createdAt` of the last one as `before` for the next page (at most 100 a page). Only an open invoice that nothing was paid for can be cancelled.

## Statuses

| Status | Meaning | What to do |
| --- | --- | --- |
| `open` | Waiting for the buyer. | Nothing. |
| `underpaid` | Part of the amount arrived. | The page asks the buyer for the rest. Do not deliver yet. |
| `paid` | The whole amount arrived at your address. | Deliver the order. |
| `overpaid` | More than the amount arrived. | Deliver; the difference is in your wallet, settle it with the buyer. |
| `expired` | Time ran out with nothing paid in full. | A payment arriving within a day still turns it paid, with late: true. |
| `cancelled` | You cancelled it. | Nothing. |

## Webhooks

Set one HTTPS address in the dashboard. We POST a JSON message to it for `invoice.paid`, `invoice.overpaid`, `invoice.underpaid`, `invoice.expired` and `invoice.refunded`. Answer with any 2xx within 10 seconds. Otherwise we try again after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours, and you can resend a message from the dashboard.

```json
{
  "type": "invoice.paid",
  "created": "2026-11-21T12:07:31Z",
  "invoice": { "id": "inv_8Qm2…", "status": "paid", "orderId": "1042", "amountUsd": "25.00", "test": false, "payments": [ … ] }
}
```

Every message carries `Soheil-Signature: t=<unix seconds>,v1=<hex>`, where v1 is the HMAC-SHA256 of `t + "." + body` with your webhook secret. Check it on the raw body before you trust a message, and refuse old timestamps:

Node.js:

```js
import crypto from "node:crypto";

// rawBody: the request body exactly as received (a string), before any JSON parsing
function verify(rawBody, header, secret, toleranceSeconds = 300) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  const expected = crypto.createHmac("sha256", secret).update(parts.t + "." + rawBody).digest("hex");
  const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) <= toleranceSeconds;
  return fresh && expected.length === parts.v1.length && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}
```

PHP:

```text
<?php
// $rawBody = file_get_contents('php://input'); $header = $_SERVER['HTTP_SOHEIL_SIGNATURE'];
function verify(string $rawBody, string $header, string $secret, int $tolerance = 300): bool {
    parse_str(str_replace(',', '&', $header), $parts);
    $expected = hash_hmac('sha256', $parts['t'] . '.' . $rawBody, $secret);
    return abs(time() - (int) $parts['t']) <= $tolerance && hash_equals($expected, $parts['v1'] ?? '');
}
```

Python:

```python
import hashlib, hmac, time

def verify(raw_body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    expected = hmac.new(secret.encode(), parts["t"].encode() + b"." + raw_body, hashlib.sha256).hexdigest()
    return abs(time.time() - int(parts["t"])) <= tolerance and hmac.compare_digest(expected, parts.get("v1", ""))
```

> **Deliver once**A message can arrive more than once. Key your delivery on the invoice id (or your orderId) and its status, and treat a repeat as done.

## Refunds

A buyer's money is in your wallet, so a refund is a transfer you send yourself. Write it down so the invoice, your exports and your server know about it: we send `invoice.refunded` to your webhook, and the invoice shows `refundedUsd` and its `refunds`. Refunds of one invoice cannot add up to more than its amount. Each transaction of a payment carries `from`, the address it came from; ask the buyer before sending there, since an exchange's address may not credit them.

`POST /api/pay/v1/invoices/{id}/refunds` (API key)

- `amountUsd` (string, required): What you refunded, in US dollars.
- `transaction` (string): The hash of your transfer, for your own records. It is not checked.
- `note` (string): Up to 300 characters, for your own records.

## Test mode

A test key (`sp_test_…`, created in the dashboard) makes test invoices. They look like real ones and their payment page says they are tests. Nobody pays them: you mark one paid from the dashboard or with the call below, and your webhook gets the same `invoice.paid` message, with `"test": true`. Test invoices cost no fee and count toward nothing. An order number names one test invoice and one real one, so the same shop database works in both modes.

`POST /api/pay/v1/invoices/{id}/simulate` (API key)

```bash
curl -X POST https://soheil.fi/api/pay/v1/invoices/inv_8Qm2…/simulate -H "Authorization: Bearer sp_test_…"
```

> **Check the flag**In production, ignore messages whose invoice has `"test": true`, or keep a separate webhook secret per environment.

## Selling in Telegram

No code is needed to sell inside Telegram. Every invoice and payment link has a second address that opens it in our bot (`t.me/<bot>?start=pay_<id>`), shown beside it in the dashboard. Under Payment links the dashboard also gives your shop's address: it lists all your active payment links as products, and a buyer picks one and pays in the chat. A payment link can carry a message for the buyer, sent once the payment arrives (in the bot and on the payment page). The message is the same for every buyer of that link; to hand out something different per sale, such as a licence key, deliver it from your webhook.

## What the buyer sees

The payment page lets the buyer choose a network and a stablecoin, then shows your address, the exact amount and a QR code. Where it is available the buyer can instead pay with another token from a browser wallet, or from another network through a one-time deposit address. In every case your address receives the invoice's stablecoin, and the invoice is settled the same way. For some coins that deposit runs through one of our own routes, which cannot promise an amount to the unit: the buyer is then asked for about 1% more, a little more than the invoice reaches you, the invoice is still reported as `paid`, and its fee (the same 1%, covered by that extra) comes off your fee balance.
