# Split a payment between merchants

> Add a beneficiary, let it accept, and set the percentages that share each payment.

Source: https://docs.tappay.mn/guides/split/

## Overview {#overview}

[Split](https://docs.tappay.mn/glossary.md#split) shares the net amount of a [payment](https://docs.tappay.mn/glossary.md#payment) among several merchants. You add a [beneficiary](https://docs.tappay.mn/glossary.md#beneficiary), the beneficiary accepts, and then you set the percentages. A beneficiary is a verified merchant, and it receives its share in its own balance.

## Before you begin {#before-you-begin}

Your key needs `split:write` in its [scope](https://docs.tappay.mn/glossary.md#scope), and you use your [secret key](https://docs.tappay.mn/glossary.md#secret-key), shown below as `sk_test_YOUR_SECRET_KEY`. Use a [sandbox](https://docs.tappay.mn/glossary.md#sandbox) key while you build. The beneficiary is a second merchant with its own secret key, and step 2 uses that key. The beneficiary must have completed identity verification and must be `ACTIVE`. TapPay first sets your `split_type`. `STATIC` uses saved rules, `DYNAMIC_ALLOWED` takes the split from each [invoice](https://docs.tappay.mn/glossary.md#invoice), and `HYBRID` uses the saved rules unless an invoice sends its own. `NONE` turns the split off.

> **Note:** **Split in the sandbox**
>
> Every call in this guide works with a sandbox key, as it does in [production](https://docs.tappay.mn/glossary.md#production). The beneficiary needs its own sandbox key. The sandbox has no ledger, no netting and no [payout](https://docs.tappay.mn/glossary.md#payout), so a sandbox payment never moves a share to a beneficiary's balance.

## Steps {#steps}

### Add a beneficiary {#add-a-beneficiary}

Send the merchant code of the beneficiary. The request stays `PENDING` until the beneficiary accepts it. The response has the request `id` and its `version`.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/split/beneficiaries" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"beneficiaryMerchantCode":"YOUR_BENEFICIARY_MERCHANT_CODE"}'
```

```js title="Node.js"
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const splitBeneficiary = await tappay.splitBeneficiaries.create({ body: { beneficiaryMerchantCode: 'YOUR_BENEFICIARY_MERCHANT_CODE' } });
console.log(JSON.stringify(splitBeneficiary));
```

```php title="PHP"
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$splitBeneficiary = $tappay->splitBeneficiaries->create(['body' => ['beneficiaryMerchantCode' => 'YOUR_BENEFICIARY_MERCHANT_CODE']]);
echo json_encode($splitBeneficiary);
```

```python title="Python"
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
split_beneficiary = client.split_beneficiaries.create({"body": {"beneficiaryMerchantCode": "YOUR_BENEFICIARY_MERCHANT_CODE"}})
print(json.dumps(split_beneficiary))
```

### Accept as the beneficiary {#accept-as-the-beneficiary}

The beneficiary merchant accepts with its own secret key, which the example shows as the beneficiary key. Put the request `id` from step 1 in the path, and send the `version` of the request, which is `1` for a new request. Nobody can accept for the beneficiary, and you cannot split to any account that has not accepted.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/split/beneficiaries/BENEFICIARY_ID/accept" \
  -H "Authorization: Bearer sk_test_BENEFICIARY_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"version":1}'
```

```js title="Node.js"
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_BENEFICIARY_SECRET_KEY' });
const splitBeneficiary = await tappay.splitBeneficiaries.accept({ id: 'BENEFICIARY_ID', body: { version: 1 } });
console.log(JSON.stringify(splitBeneficiary));
```

```php title="PHP"
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_BENEFICIARY_SECRET_KEY']);
$splitBeneficiary = $tappay->splitBeneficiaries->accept(['id' => 'BENEFICIARY_ID', 'body' => ['version' => 1]]);
echo json_encode($splitBeneficiary);
```

```python title="Python"
import json
import tappay

client = tappay.TapPay("sk_test_BENEFICIARY_SECRET_KEY")
split_beneficiary = client.split_beneficiaries.accept({"id": "BENEFICIARY_ID", "body": {"version": 1}})
print(json.dumps(split_beneficiary))
```

### Set the rules {#set-the-rules}

Replace the rules of your merchant. For one [terminal](https://docs.tappay.mn/glossary.md#terminal), send `scope` `TERMINAL` and its `scopeId`. Each rule has a `beneficiaryMerchantCode` and a `percent`. The percentages add up to at most 100, and you keep the rest, so more than 100 returns `422` [PYO-205](https://docs.tappay.mn/errors.md#PYO-205). A rule can start later with `validFrom`, but not in the past.

```bash title="curl"
curl -sS -X PUT "https://api.tappay.mn/api/v1/split/rules" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"scope":"MERCHANT","rules":[{"beneficiaryMerchantCode":"YOUR_BENEFICIARY_MERCHANT_CODE","percent":"20"}]}'
```

```js title="Node.js"
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const splitRule = await tappay.splitRules.update({
  body: {
    scope: 'MERCHANT',
    rules: [
      {
        beneficiaryMerchantCode: 'YOUR_BENEFICIARY_MERCHANT_CODE',
        percent: '20',
      },
    ],
  },
});
console.log(JSON.stringify(splitRule));
```

```php title="PHP"
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$splitRule = $tappay->splitRules->update([
    'body' => [
        'scope' => 'MERCHANT',
        'rules' => [
            [
                'beneficiaryMerchantCode' => 'YOUR_BENEFICIARY_MERCHANT_CODE',
                'percent' => '20',
            ],
        ],
    ],
]);
echo json_encode($splitRule);
```

```python title="Python"
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
split_rule = client.split_rules.update({
    "body": {
        "scope": "MERCHANT",
        "rules": [
            {
                "beneficiaryMerchantCode": "YOUR_BENEFICIARY_MERCHANT_CODE",
                "percent": "20",
            },
        ],
    },
})
print(json.dumps(split_rule))
```

### Read the rules {#read-the-rules}

Read the rules that apply now. The response shows your `splitType` and your `primaryPercent`, and `history=true` adds the earlier rule sets.

```bash title="curl"
curl -sS "https://api.tappay.mn/api/v1/split/rules?scope=MERCHANT" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27"
```

```js title="Node.js"
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const splitRule = await tappay.splitRules.retrieve({ query: { scope: 'MERCHANT' } });
console.log(JSON.stringify(splitRule));
```

```php title="PHP"
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$splitRule = $tappay->splitRules->retrieve(['query' => ['scope' => 'MERCHANT']]);
echo json_encode($splitRule);
```

```python title="Python"
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
split_rule = client.split_rules.retrieve({"scope": "MERCHANT"})
print(json.dumps(split_rule))
```

### List your beneficiaries {#list-your-beneficiaries}

List the beneficiaries with a `status` filter. Only an `ACTIVE` beneficiary can be in a rule. A beneficiary can decline a request with [reject](https://docs.tappay.mn/reference/beneficiaries/reject.md).

```bash title="curl"
curl -sS "https://api.tappay.mn/api/v1/split/beneficiaries?status=ACTIVE" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27"
```

```js title="Node.js"
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const page = await tappay.splitBeneficiaries.list({ query: { status: 'ACTIVE' } }).firstPage();
console.log(JSON.stringify(page));
```

```php title="PHP"
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$page = $tappay->splitBeneficiaries->list(['query' => ['status' => 'ACTIVE']])->firstPage();
echo json_encode(['data' => $page->data, 'hasMore' => $page->hasMore, 'nextCursor' => $page->nextCursor]);
```

```python title="Python"
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
page = client.split_beneficiaries.list({"status": "ACTIVE"}).first_page()
print(json.dumps({"data": page.data, "has_more": page.has_more, "next_cursor": page.next_cursor}))
```

### Revoke the beneficiary {#revoke-the-beneficiary}

Revoke the link when the split should end. Put the request `id` from step 1 in the path, send the current `version`, which is `2` after the beneficiary accepted, and a `reason`. The beneficiary becomes `REVOKED`, and later payments are no longer split with it. You can add the same merchant again after that, so in the sandbox you can run this guide from step 1 again.

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/split/beneficiaries/BENEFICIARY_ID/revoke" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"reason":"Contract ended","version":2}'
```

```js title="Node.js"
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const splitBeneficiary = await tappay.splitBeneficiaries.revoke({ id: 'BENEFICIARY_ID', body: { reason: 'Contract ended', version: 2 } });
console.log(JSON.stringify(splitBeneficiary));
```

```php title="PHP"
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$splitBeneficiary = $tappay->splitBeneficiaries->revoke(['id' => 'BENEFICIARY_ID', 'body' => ['reason' => 'Contract ended', 'version' => 2]]);
echo json_encode($splitBeneficiary);
```

```python title="Python"
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
split_beneficiary = client.split_beneficiaries.revoke({"id": "BENEFICIARY_ID", "body": {"reason": "Contract ended", "version": 2}})
print(json.dumps(split_beneficiary))
```

## Verify {#verify}

Read the rules and the beneficiaries as in steps 4 and 5. After step 6 the beneficiary is `REVOKED`. A beneficiary is `PENDING`, `ACTIVE`, `REJECTED` or `REVOKED`.

TapPay splits the net amount, which is the full amount minus the `mdr_rate` fee. You pay the whole fee as the main merchant. What is left after the percentages stays with you, and rounding goes to you too. An [overpaid](https://docs.tappay.mn/glossary.md#overpaid) payment is not split. A [refund](https://docs.tappay.mn/glossary.md#refund) or a chargeback returns money from each beneficiary in the same ratio as the split. If a balance is too small, it goes negative.

Each beneficiary gets its share in its own balance, and it is paid out by its own `payout_policy`. Its balance and bank account can be at another bank.

## Common mistakes {#common-mistakes}

- Adding a merchant that has not completed identity verification. TapPay returns [PYO-203](https://docs.tappay.mn/errors.md#PYO-203).
- Adding yourself or adding the same beneficiary twice. TapPay returns [PYO-202](https://docs.tappay.mn/errors.md#PYO-202) or [PYO-204](https://docs.tappay.mn/errors.md#PYO-204).
- Putting a beneficiary in a rule before it is `ACTIVE`. TapPay returns [PYO-206](https://docs.tappay.mn/errors.md#PYO-206).
- Accepting or deciding on a request that is no longer `PENDING`. TapPay returns [PYO-208](https://docs.tappay.mn/errors.md#PYO-208).
- Setting a rule that starts in the past, or one for a terminal that is not yours. TapPay returns [PYO-210](https://docs.tappay.mn/errors.md#PYO-210) or [PYO-209](https://docs.tappay.mn/errors.md#PYO-209).
- Expecting a split on an overpaid payment, or a split to any bank account. Only an accepted, verified merchant can be a beneficiary.

## Next steps {#next-steps}

See how a refund returns shares in the [refunds guide](https://docs.tappay.mn/guides/refunds.md). See [Add a beneficiary](https://docs.tappay.mn/reference/beneficiaries/create.md), [Accept a beneficiary](https://docs.tappay.mn/reference/beneficiaries/accept.md), [Set split rules](https://docs.tappay.mn/reference/rules/put.md) and [Retrieve split rules](https://docs.tappay.mn/reference/rules/get.md).

To split a single invoice, send `split` when you create the invoice, with the `merchantId` and `percent` of each beneficiary. This works when your `split_type` is `DYNAMIC_ALLOWED` or `HYBRID`.

```json
{
  "split": [
    { "merchantId": "BENEFICIARY_MERCHANT_ID", "percent": "20" }
  ]
}
```
