# RESIV API documentation

Accept bank-transfer payments and get paid out automatically.

## How it works

RESIV lets your customers pay you by bank transfer, and pays the money out to your bank account automatically. You never withdraw anything.

1. Your server creates a payment with `POST /payments`. You get back a `checkout_url`.
2. You send the customer to the `checkout_url`. They see a bank account to transfer to.
3. The customer pays from their banking app. RESIV confirms it within seconds.
4. RESIV sends your server a signed `payment.success` webhook, then pays your business bank account.

> **Note:** All amounts are whole numbers in kobo. ₦15,000.00 is `1500000`. Never send decimals.

## Quickstart

1. Sign in to your dashboard, open **Developers**, and create a **test** secret key (`resiv_sk_test_…`). It is shown once. Store it in an environment variable called `RESIV_SECRET_KEY`.
2. Add your site's address under **Developers → Return URLs** so customers can be sent back to it.
3. Create a payment (next section) and open its `checkout_url`.
4. In test mode the checkout shows a **Simulate payment** button. Press it to see the full flow without moving money.

> **Important:** Keep secret keys on your server. Never put them in a mobile app, a web page or a public repository.

## Create a payment

`POST /payments` with `Authorization: Bearer <secret key>`. Add an `Idempotency-Key` header so a retried request never creates a second payment.

| Field | Type | Notes |
| --- | --- | --- |
| `amount` | integer, required | Kobo. Minimum and maximum depend on your business limits. |
| `reference` | string, required | Your own unique id for this payment (letters, numbers, `. _ : -`, up to 100). You look the payment up by it. |
| `customer.name` | string, required | The payer's name. |
| `customer.email` | string, required | The payer's email. |
| `customer.phone` | string | Optional. |
| `return_url` | https URL | Where to send the customer afterwards. Its address must be on your Return URLs list. |
| `description` | string | Up to 200 characters. Optional. |
| `metadata` | object | Up to 20 flat keys (text, number or true/false). Echoed back to you. |

**Create a payment: cURL**

```bash
curl https://api.resiv.cc/payments \
  -H "Authorization: Bearer resiv_sk_test_xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1001" \
  -d '{
    "amount": 1500000,
    "reference": "order-1001",
    "customer": { "name": "Ada Obi", "email": "ada@example.com" },
    "return_url": "https://yourshop.com/thanks"
  }'
```

**Create a payment: Node.js**

```js
// amount is in KOBO: 1500000 = ₦15,000.00
const res = await fetch("https://api.resiv.cc/payments", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.RESIV_SECRET_KEY,
    "Content-Type": "application/json",
    "Idempotency-Key": "order-1001", // a retry never creates a second payment
  },
  body: JSON.stringify({
    amount: 1500000,
    reference: "order-1001",
    customer: { name: "Ada Obi", email: "ada@example.com" },
    return_url: "https://yourshop.com/thanks",
  }),
});
const { data } = await res.json();
// Send the customer to data.checkout_url
```

**Create a payment: PHP**

```php
<?php
$ch = curl_init("https://api.resiv.cc/payments");
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("RESIV_SECRET_KEY"),
    "Content-Type: application/json",
    "Idempotency-Key: order-1001",
  ],
  CURLOPT_POSTFIELDS => json_encode([
    "amount" => 1500000, // kobo: ₦15,000.00
    "reference" => "order-1001",
    "customer" => ["name" => "Ada Obi", "email" => "ada@example.com"],
    "return_url" => "https://yourshop.com/thanks",
  ]),
]);
$data = json_decode(curl_exec($ch), true)["data"];
// Send the customer to $data["checkout_url"]
```

**Create a payment: Python**

```python
import os, requests

res = requests.post(
    "https://api.resiv.cc/payments",
    headers={
        "Authorization": "Bearer " + os.environ["RESIV_SECRET_KEY"],
        "Idempotency-Key": "order-1001",
    },
    json={
        "amount": 1500000,  # kobo: ₦15,000.00
        "reference": "order-1001",
        "customer": {"name": "Ada Obi", "email": "ada@example.com"},
        "return_url": "https://yourshop.com/thanks",
    },
)
data = res.json()["data"]
# Send the customer to data["checkout_url"]
```

**Response (201)**

```json
{
  "success": true,
  "data": {
    "id": "665f1c2e9b1f4a0012ab34cd",
    "reference": "order-1001",
    "status": "pending",
    "amount": 1500000,
    "amount_paid": null,
    "currency": "NGN",
    "customer": { "email": "ada@example.com", "name": "Ada Obi", "phone": null },
    "checkout_url": "https://pay.resiv.cc/pay/…",
    "return_url": "https://yourshop.com/thanks",
    "livemode": false,
    "expires_at": "2026-01-01T10:30:00.000Z",
    "paid_at": null,
    "created_at": "2026-01-01T10:00:00.000Z"
  }
}
```

A checkout stays open for a limited time (shown in `expires_at`). Use the same call with a new `reference` for a new attempt. To cancel an unpaid payment: `POST /payments/{reference}/cancel`. To list payments: `GET /payments?page=1&limit=20&status=succeeded&q=…`.

## Check a payment

`GET /payments/{reference}` returns the payment (you can also use the `id`). **Always check on your server before you give the customer what they paid for.** Do not rely on the browser redirect alone.

**Verify before fulfilling: cURL**

```bash
curl https://api.resiv.cc/payments/order-1001 \
  -H "Authorization: Bearer resiv_sk_test_xxxxxxxxxxxxxxxx"
# Only give the customer what they paid for if "status" is "succeeded"
# and "amount_paid" is what you expected.
```

**Verify before fulfilling: Node.js**

```js
const res = await fetch("https://api.resiv.cc/payments/" + encodeURIComponent(reference), {
  headers: { Authorization: "Bearer " + process.env.RESIV_SECRET_KEY },
});
const { data } = await res.json();
if (data.status === "succeeded" && data.amount_paid === expectedKobo) {
  // safe to fulfil the order
}
```

**Verify before fulfilling: PHP**

```php
<?php
$ch = curl_init("https://api.resiv.cc/payments/" . rawurlencode($reference));
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("RESIV_SECRET_KEY")],
]);
$data = json_decode(curl_exec($ch), true)["data"];
if ($data["status"] === "succeeded" && $data["amount_paid"] === $expectedKobo) {
  // safe to fulfil the order
}
```

**Verify before fulfilling: Python**

```python
res = requests.get(
    f"https://api.resiv.cc/payments/{reference}",
    headers={"Authorization": "Bearer " + os.environ["RESIV_SECRET_KEY"]},
)
data = res.json()["data"]
if data["status"] == "succeeded" and data["amount_paid"] == expected_kobo:
    pass  # safe to fulfil the order
```

## Webhooks

Add an endpoint in **Developers → Webhooks** (https only). RESIV sends a `POST` with a JSON body for each event, and a signing secret you keep on your server.

| Event | When |
| --- | --- |
| `payment.success` | The customer paid in full. Fulfil the order. |
| `payment.expired` | The checkout timed out unpaid. |
| `payout.sent` | Your money was sent to your bank account. |
| `payout.failed` | A payout could not be sent. We are already looking at it. |

**Body**

```json
{
  "id": "evt_9f2c…",
  "type": "payment.success",
  "created": 1767261600,
  "livemode": false,
  "data": { "object": { /* the payment, as returned by the API */ } }
}
```

Each request has the header `X-Resiv-Signature: t=<unix time>,v1=<hex>`, where `v1` is the HMAC-SHA256 of `"<t>.<raw body>"` using your signing secret. Compute it from the **raw** body, compare in constant time, and reject anything older than 5 minutes.

**Verify the signature: cURL**

```bash
# Header:  X-Resiv-Signature: t=<unix time>,v1=<hex>
# v1 = HMAC-SHA256(signing secret, "<t>.<raw request body>")
# See the Node.js, PHP or Python tab for a full check.
```

**Verify the signature: Node.js**

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

// IMPORTANT: use the RAW body string, exactly as received (not re-serialised JSON).
export function isValidResivWebhook(rawBody, header, secret, toleranceSeconds = 300) {
  const parts = Object.fromEntries(String(header).split(",").map((p) => p.split("=")));
  const t = Number(parts.t);
  if (!Number.isInteger(t) || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false; // too old: replay
  const expected = crypto.createHmac("sha256", secret).update(t + "." + rawBody).digest("hex");
  const given = String(parts.v1 ?? "");
  return expected.length === given.length && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(given));
}
```

**Verify the signature: PHP**

```php
<?php
function is_valid_resiv_webhook(string $rawBody, string $header, string $secret, int $tolerance = 300): bool {
  parse_str(str_replace(",", "&", $header), $parts);
  $t = (int)($parts["t"] ?? 0);
  if ($t === 0 || abs(time() - $t) > $tolerance) return false; // too old: replay
  $expected = hash_hmac("sha256", $t . "." . $rawBody, $secret);
  return hash_equals($expected, $parts["v1"] ?? "");
}
// $rawBody = file_get_contents("php://input");
```

**Verify the signature: Python**

```python
import hmac, hashlib, time

def is_valid_resiv_webhook(raw_body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    t = int(parts.get("t", 0))
    if t == 0 or abs(time.time() - t) > tolerance:
        return False  # too old: replay
    expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))
```

- Answer with any `2xx` within 10 seconds. Do slow work after replying.
- Failed deliveries retry after 1 min, 5 min, 15 min, 1 h, 3 h, 6 h and 12 h, then stop. You can resend any delivery from the dashboard.
- The same event can arrive more than once. Use the event `id` (or the payment `reference`) so fulfilling twice does nothing.

## Return redirect

When the customer finishes, we send their browser to your `return_url` with `?reference=…&status=…&sig=…`. `status` is `success`, `expired`, `cancelled`, `failed` or `review`. `sig` is the HMAC-SHA256 of `"<reference>.<status>"` with your **return secret** (Developers → Return URLs).

> **Important:** The redirect is for showing the customer a page. It is not proof of payment. Confirm with `GET /payments/{reference}` or the webhook before fulfilling.

**Check the signature: cURL**

```bash
# sig = HMAC-SHA256(return secret, "<reference>.<status>")  (hex)
```

**Check the signature: Node.js**

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

// On the page customers return to: /thanks?reference=order-1001&status=success&sig=...
const { reference, status, sig } = req.query;
const expected = crypto.createHmac("sha256", process.env.RESIV_RETURN_SECRET)
  .update(reference + "." + status).digest("hex");
const looksGenuine = sig.length === expected.length && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
// Even if it looks genuine, confirm with GET /payments/:reference before fulfilling.
```

**Check the signature: PHP**

```php
<?php
$expected = hash_hmac("sha256", $_GET["reference"] . "." . $_GET["status"], getenv("RESIV_RETURN_SECRET"));
$looks_genuine = hash_equals($expected, $_GET["sig"] ?? "");
// Even if it looks genuine, confirm with GET /payments/:reference before fulfilling.
```

**Check the signature: Python**

```python
expected = hmac.new(os.environ["RESIV_RETURN_SECRET"].encode(),
                    f"{reference}.{status}".encode(), hashlib.sha256).hexdigest()
looks_genuine = hmac.compare_digest(expected, sig)
# Even if it looks genuine, confirm with GET /payments/:reference before fulfilling.
```

## Payment statuses

| Status | Meaning | What you do |
| --- | --- | --- |
| `pending` | Waiting for the transfer. | Wait. |
| `succeeded` | Paid in full. A payout is scheduled. | Fulfil the order. |
| `expired` | Nothing arrived before the checkout closed. | Offer a new payment. |
| `cancelled` | You cancelled it. | Nothing. |
| `failed` | The payment could not complete. | Offer a new payment. |
| `underpaid`, `overpaid`, `late`, `needs_review` | Money arrived but not as expected (wrong amount, after expiry, or a second transfer). It is held and RESIV staff review it. | Do not fulfil and tell the customer not to pay again. It resolves to `succeeded` or `refunded`. |
| `refunded` | A held payment was returned to the customer. | Nothing. |

## Fees and payouts

You pay one fee to RESIV: a percentage of each collection plus a flat fee per payout. Your rates are on your dashboard. The rest is paid to your business bank account automatically, a few minutes after each successful payment.

Example at a 2% collection rate and a ₦50 payout fee: customer pays ₦10,000.00, the collection fee is ₦200.00, and your account receives ₦9,750.00. Each paid payment carries a `fees` object (`resiv_fee`, `merchant_payout`) in kobo.

Payout account changes need RESIV approval. Payouts go only to approved accounts in your own name.

## Test and live

|  | Test | Live |
| --- | --- | --- |
| Key prefix | `resiv_sk_test_…` | `resiv_sk_live_…` |
| Money moves | No | Yes |
| Checkout | Has a Simulate payment button | Real bank account to pay |
| Data | Separate from live | Separate from test |

The mode comes from the key, never from the request. Live keys work once your business is approved and has a verified payout account.

## Errors and limits

**Error format**

```json
{
  "success": false,
  "error": {
    "code": "validation_error",
    "message": "Some fields are invalid",
    "details": [{ "path": "amount", "message": "…" }],
    "requestId": "req_…"
  }
}
```

| HTTP | Meaning |
| --- | --- |
| 400 | Something in your request is wrong. See `details`. |
| 401 | Missing, wrong or revoked secret key. |
| 403 | The key or your business can't do this (for example live mode before approval). |
| 404 | No such payment. |
| 409 | Conflict, such as reusing an `Idempotency-Key` with a different body. |
| 429 | Too many requests (240 per minute per key). Wait and retry. |
| 5xx | Our side. Retry with the same `Idempotency-Key`. |

Quote the `requestId` when you contact support.

## Go-live checklist

- Your business is approved and your payout account shows as approved.
- You swapped the test key for a live key, stored in an environment variable on your server.
- Your return URL and your webhook endpoint use your live site over https.
- Webhook signatures are verified on the raw body, with a time limit.
- Fulfilment happens once per payment, from `payment.success` or a server-side `GET /payments/{reference}`.
- You tested a real small payment end to end.
