> ## Documentation Index
> Fetch the complete documentation index at: https://docs.salesive.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Payment provider apps

> Register a payment method your app captures itself: redirect checkout, a signed webhook to confirm or fail the payment, and refunds. Salesive never sees card data and never holds the funds.

A payment provider app adds its own payment method to a store's checkout. The
shopper is redirected to you, you capture the money in whatever way you already
do (card, bank transfer, crypto, wallet), and you tell Salesive over a signed
webhook whether the payment succeeded. Salesive records the order, and invoices
its platform fee to the merchant separately.

This is different from [checkout functions](https://docs.salesive.com/apps/checkout-functions.md), which can
only hide or rename payment methods that already exist. A payment provider app
**adds** one.

> [!WARNING]
>
> Building a payment provider requires an admin to set `paymentCapable` on your
> app at review, and every provider you register is reviewed again before a
> merchant can see it. Contact us before you start.

## How the money works

You are the merchant of record for the payment. Salesive never sees card data,
never holds the funds and never moves money for you. Because the order was
captured outside the platform's own gateways, the platform fee is **invoiced**
rather than withheld: the ledger reads the `externalProvider` marker on the order
and accrues the fee from it. See [platform billing](https://docs.salesive.com/apps-api/platform-billing.md).

## The flow

**1. Register your provider**

`PUT /api/v1/app/payment-provider` with your `app_` token. One provider per
installation. The row starts `pending`.

**2. Wait for review**

An admin reviews the configuration, your licence and your sandbox. They set
the provider `active` and the app `paymentCapable`. Only then does it appear
in a merchant's payment settings.

**3. The merchant switches it on**

They enable it in their payment settings. That writes the store's own switch,
and checkout starts offering you.

**4. Authorize a payment**

When the shopper picks you, Salesive `POST`s to your `authorizeUrl` and sends
the shopper to the `redirectUrl` you return.

**5. Confirm with a webhook**

When the money is captured, send `payments/authorized` to the webhook URL
Salesive shows you. **This is the only thing that marks the order paid.**

## 1. Register the provider

```http theme={null}
PUT /api/v1/app/payment-provider
Authorization: Bearer <app_ token>
Content-Type: application/json
```

```json theme={null}
{
  "name": "Pay with Chain",
  "logo": "https://yourapp.com/logo.png",
  "countries": ["NG", "GH"],
  "currencies": ["NGN", "USDC"],
  "authorizeUrl": "https://yourapp.com/pay/authorize",
  "refundUrl": "https://yourapp.com/pay/refund",
  "webhookUrl": "https://yourapp.com/pay/webhook",
  "testMode": true
}
```

| Field | Rules |
| - | - |
| `name` | What the shopper sees at checkout. 60 characters. |
| `logo` | Public https image URL. Same URL guard as every other app URL: https only, no credentials, no private or loopback address. |
| `countries` | At least one ISO 3166-1 alpha-2 code. |
| `currencies` | At least one ISO 4217 code. |
| `authorizeUrl` | Where Salesive asks you to start a payment. |
| `refundUrl` | Where Salesive asks you to refund one. |
| `webhookUrl` | Where Salesive sends `payments/authorized`, `payments/failed` and `payments/refunded`. |
| `testMode` | Your own sandbox flag. Required to work before review passes. |

Every URL is checked against the same guard as app webhooks, at registration and
again before each call.

> [!NOTE]
>
> No OAuth scope is required for this route. It is your app's own payment
> configuration, not a write to store data. The gates that matter are
> `paymentCapable` on the app and the provider's `status`.

**Changing anything sends the row back to `pending`.** What the merchant agreed
to is the reviewed configuration, so a changed URL or name is reviewed again. You
cannot re-register your way past an admin kill switch.

`GET` returns your row. `DELETE` removes it and removes every store's switch for
it at once. The fee ledger is untouched, because an accrual is written from the
order, not from this row.

## 2. Authorize a payment

When a shopper chooses your method, Salesive calls your `authorizeUrl` with a
signed `POST`:

```json theme={null}
{
  "sessionId": "6782f1c0a1b2c3d4e5f60718",
  "orderId": "6782f1c0a1b2c3d4e5f60718",
  "amount": 250000,
  "currency": "NGN",
  "shopId": "6680aabbccddeeff00112200",
  "returnUrl": "https://shop.example.com/orders/6782f1c0a1b2c3d4e5f60718",
  "customer": { "id": "6699aabbccddeeff00112211" }
}
```

`amount` is in **minor units** of `currency`. `returnUrl` is a hint for where to
send the shopper afterwards; it is never proof of payment.

Answer with a redirect:

```json theme={null}
{ "redirectUrl": "https://checkout.yourapp.com/s/abc123", "providerReference": "yourapp_charge_abc123" }
```

The redirect must be `https`. `providerReference` is your own identifier for this
charge, and it is what you can quote back to yourself later.

> [!WARNING]
>
> Answering this call does not mark anything paid. It only moves the shopper to
> your page. Only the webhook does that.

## 3. Confirm or fail with a webhook

Salesive gives you a webhook URL when the provider is registered:

```http theme={null}
POST https://api.salesive.com/api/v1/webhooks/app-payment/<providerId>
X-Salesive-Signature: <hmac>
Content-Type: application/json
```

`X-Salesive-Signature` is an HMAC of the raw request body signed with the app
secret for that installation's environment. Verify it over the raw bytes before
parsing.

```json theme={null}
{
  "event": "payments/authorized",
  "sessionId": "6782f1c0a1b2c3d4e5f60718",
  "providerReference": "yourapp_charge_abc123"
}
```

| `event` | When you send it | What Salesive does |
| - | - | - |
| `payments/authorized` | The money is captured. | Marks the session `authorized`, marks the order paid, writes the `externalProvider` marker, and fires `orders/paid` to every installed app exactly once. |
| `payments/failed` | The payment will not complete. | Marks the session failed with your short reason. The order is not paid. |
| `payments/refunded` | A refund you were asked for has completed. | Moves the session to `refunded`. |

Your handler must be **idempotent**. A retried `payments/authorized` must not
double-apply, and it will be retried if Salesive cannot reach you.

## 4. Refunds

The merchant asks from their dashboard. Salesive `POST`s to your `refundUrl`:

```json theme={null}
{
  "sessionId": "6782f1c0a1b2c3d4e5f60718",
  "providerReference": "yourapp_charge_abc123",
  "amount": 250000,
  "currency": "NGN",
  "reason": "Damaged on arrival"
}
```

Answer `200` to accept the request, then confirm with `payments/refunded` on the
webhook when the money is actually back with the shopper. The session stays
`authorized` until you confirm, so a refund you accept and never complete is
visible as an open session rather than a silent success.

Phase 1 supports **full refunds only**. Partial refunds are reserved in the
contract and always refused today.

## Idempotency, retries and reconciliation

* Every session is unique per provider and idempotency key, so a double-click at
  checkout cannot create two charges for one order.
* Treat `payments/authorized` as at-least-once. Key your own writes on
  `sessionId`, not on arrival time.
* A session that is never confirmed stays open. Reconcile open sessions with your
  own charge list rather than assuming the webhook always arrives.

## Test mode

Set `testMode: true` and point the three URLs at a sandbox that fails on demand.
Review requires a working test mode, including a failed payment and a refund. A
`testMode` provider is still gated by `status` and by the app being active.

## Checklist before review

* [ ] All four URLs are public https and pass the URL guard.
* [ ] `authorizeUrl` answers with an https `redirectUrl`.
* [ ] `webhookUrl` verifies `X-Salesive-Signature` over the raw body.
* [ ] `payments/authorized` is idempotent.
* [ ] `payments/failed` is sent, with a short reason, when a payment will not complete.
* [ ] `refundUrl` accepts a full refund and `payments/refunded` confirms it.
* [ ] Your sandbox can produce a success, a failure and a refund on demand.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.