# Split a payment across multiple subaccounts

> Divide a payment between your main account and several subaccounts with a saved split or a dynamic split.

There are two ways to divide a payment between your main account and several subaccounts:

- **Saved split**: create the split once, then pass its `split_code` on every payment you want to divide the same way.
- **Dynamic split**: send the split with each payment, for when the division changes from one payment to the next.

Before you start, [create a subaccount](/payments/split-payments/subaccounts) for each partner. The examples use Oasis Foods (`ACCT_6uujpqtzmnufzkw`) and Lekki Bakes (`ACCT_hdl8abxl8drhrl3`). Paystack generates different codes for your subaccounts.

## Create a split

Send the split's name, type, currency, and subaccount shares to [Create Split](/api/split#create). In this example, Oasis Foods gets 50% of each payment, Lekki Bakes gets 30%, and your main account keeps the remaining 20%:

<localized-request-response src="payments/split-payments/create-split">



</localized-request-response>

Set `type` to `percentage` or `flat`. Every share in the split uses that type. The `share` values must follow these limits, or Paystack rejects the request:

<table>
<thead>
  <tr>
    <th>
      <code>
        type
      </code>
    </th>
    
    <th>
      Each <code>
        share
      </code>
      
       is
    </th>
    
    <th>
      Shares must total
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        percentage
      </code>
    </td>
    
    <td>
      A whole-number percentage
    </td>
    
    <td>
      100 or less. Your main account gets the rest.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        flat
      </code>
    </td>
    
    <td>
      An amount in the currency's subunit. See <a href="/api/supported-currencies">
        supported currencies
      </a>
      
      .
    </td>
    
    <td>
      No more than the amount of the payment you use the split on.
    </td>
  </tr>
</tbody>
</table>

Save the `split_code` (`SPL_RcScyW5jp2`) and `id` (`2703655`). Pass the `split_code` on each payment and the `id` when you change the split.

You can also create and manage splits on the [Transaction splits](https://dashboard.paystack.com/v2/transaction-splits) page of your Dashboard.

## Choose who pays the Paystack fee

Set `bearer_type` when you create a split or pass a `split` object.

<table>
<thead>
  <tr>
    <th>
      <code>
        bearer_type
      </code>
    </th>
    
    <th>
      Who pays the fee
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        all
      </code>
    </td>
    
    <td>
      Your main account and every subaccount pay an equal part of the fee.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        all-proportional
      </code>
    </td>
    
    <td>
      Each party pays a part of the fee in proportion to its share of the payment.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        account
      </code>
    </td>
    
    <td>
      Your main account pays the whole fee.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        subaccount
      </code>
    </td>
    
    <td>
      The subaccount in <code>
        bearer_subaccount
      </code>
      
       pays the whole fee. Pass <code>
        bearer_subaccount
      </code>
      
       with this value, and use a subaccount that's in the split.
    </td>
  </tr>
</tbody>
</table>

<callout title="Default fee bearer" type="warning">

If you leave out `bearer_type`, your main account and every subaccount pay an equal part of the fee.

</callout>

## Collect a payment with the split

Pass the `split_code` to [Initialize Transaction](/api/transaction#initialize):

<request-response>
<template v-slot:curl="">

```bash
curl https://api.paystack.co/transaction/initialize \
  -H "Authorization: Bearer $PAYSTACK_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "ada.obi@example.com",
    "amount": 2000000,
    "split_code": "SPL_RcScyW5jp2"
  }' \
  -X POST
```

</template>

<template v-slot:js="">

```javascript
const https = require("https");

const params = JSON.stringify({
  "email": "ada.obi@example.com",
  "amount": 2000000,
  "split_code": "SPL_RcScyW5jp2"
});

const options = {
  hostname: "api.paystack.co",
  port: 443,
  path: "/transaction/initialize",
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.PAYSTACK_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
};

const req = https.request(options, (res) => {
  let data = "";
  res.on("data", (chunk) => {
    data += chunk;
  });
  res.on("end", () => {
    console.log(res.statusCode, JSON.parse(data));
  });
});

req.on("error", (error) => {
  console.error(error);
});

req.write(params);
req.end();
```

</template>

<template v-slot:php="">

```php
<?php
$fields = [
  "email" => "ada.obi@example.com",
  "amount" => 2000000,
  "split_code" => "SPL_RcScyW5jp2",
];

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.paystack.co/transaction/initialize",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode($fields),
  CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer " . getenv("PAYSTACK_SECRET_KEY"),
    "Content-Type: application/json",
    "Cache-Control: no-cache",
  ),
));
$response = curl_exec($curl);
echo curl_getinfo($curl, CURLINFO_HTTP_CODE) . " " . $response;
?>
```

</template>

<template v-slot:response="">

```json
{
  "status": true,
  "message": "Authorization URL created",
  "data": {
    "authorization_url": "https://checkout.paystack.com/nkdks46nymizns7",
    "access_code": "nkdks46nymizns7",
    "reference": "nms6uvr1pl"
  }
}
```

</template>
</request-response>

To split a repeat payment from a saved card, pass the same `split_code` to [Charge Authorization](/api/transaction#chargeAuthorization):

<localized-request-response src="payments/split-payments/charge-authorization">



</localized-request-response>

## Use a dynamic split

A saved split divides every payment the same way. Use a dynamic split when the division depends on the payment itself.

For example, a customer's 2000000 order includes 1200000 of food from Oasis Foods and 500000 of pastries from Lekki Bakes. The next order has different amounts, so a saved split can't describe it. Instead, you send the shares for this order with the payment.

To do this, pass a `split` object instead of a `split_code`. You don't need to create the split first. [Initialize Transaction](/api/transaction#initialize), [Charge Authorization](/api/transaction#chargeAuthorization), and [Paystack Popup](/developer-tools/inline-js#multi-split-transaction) all accept a `split` object.

<table>
<thead>
  <tr>
    <th>
      Field
    </th>
    
    <th>
      Required
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        name
      </code>
    </td>
    
    <td>
      Yes
    </td>
    
    <td>
      Name of the split, for example the order number.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        type
      </code>
    </td>
    
    <td>
      Yes
    </td>
    
    <td>
      <code>
        percentage
      </code>
      
       or <code>
        flat
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        currency
      </code>
    </td>
    
    <td>
      Yes
    </td>
    
    <td>
      Currency of the split. Use the payment's currency.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        subaccounts
      </code>
    </td>
    
    <td>
      Yes
    </td>
    
    <td>
      Array of objects, each with a <code>
        subaccount
      </code>
      
       code and its <code>
        share
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bearer_type
      </code>
    </td>
    
    <td>
      No
    </td>
    
    <td>
      Who pays the Paystack fee. See <a href="#choose-who-pays-the-paystack-fee">
        Choose who pays the Paystack fee
      </a>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bearer_subaccount
      </code>
    </td>
    
    <td>
      When <code>
        bearer_type
      </code>
      
       is <code>
        subaccount
      </code>
    </td>
    
    <td>
      Code of the subaccount that pays the fee.
    </td>
  </tr>
</tbody>
</table>

The shares follow the same [limits](#create-a-split) as a saved split.

This request splits that order. It uses a `flat` split, so each `share` is an amount in the currency's subunit (<localized-value page-key="markets" path="subunit">



</localized-value>

), and 2000000 is <localized-value page-key="markets" path="example_amount">



</localized-value>

:

<localized-request-response src="payments/split-payments/initialize-dynamic-split">



</localized-request-response>

Oasis Foods gets 1200000 and Lekki Bakes gets 500000. Your main account gets the remaining 300000 and pays the Paystack fee from it, because `bearer_type` is `account`.

## Change a split

Pass the split's `id` to these endpoints:

- To add a subaccount, or change the share of a subaccount already in the split, call [Add Subaccount to Split](/api/split#addSubaccount) with the `subaccount` code and its `share`.
- To remove a subaccount, call [Remove Subaccount from Split](/api/split#removeSubaccount) with its `subaccount` code.
- If the subaccount you're removing is the `bearer_subaccount`, call [Update Split](/api/split#update) first to change it.
- To rename the split, change `bearer_type` or `bearer_subaccount`, or deactivate the split, call Update Split. Set `active` to `false` to deactivate it.

<callout title="You can't change a split's type" type="warning">

To change the type, deactivate the split and create one with the new type.

</callout>

## Confirm the split

When a payment with a split succeeds, the `charge.success` event includes a `split` object:

- `formula`: the split configuration Paystack applied.
- `shares`: the amount each party received, in the currency's subunit.
- `integration`: your main account, in both objects.

This event is for payment `nms6uvr1pl`, initialized with `SPL_RcScyW5jp2`:

<localized-snippet src="payments/split-payments/charge-success-split">



</localized-snippet>

Because the split uses `bearer_type: "account"`, your main account pays the Paystack fee (`shares.paystack`) from its 20% share. Each subaccount receives its full share.

The fee in this example uses standard pricing for <localized-value page-key="markets" path="currency_code">



</localized-value>

 local card payments. Your fee depends on your pricing and the payment channel.

Use the `charge.success` webhook as your primary signal to fulfill orders, grant access, or update your database. The customer can close the page before your callback runs, but the webhook still arrives.

Add your webhook URL on the [Paystack Dashboard](https://dashboard.paystack.com/v2/developers/api-configuration), and [verify the signature](/developer-tools/integration/webhooks#verify-webhook-signatures) on every event with your webhook signing secret.
