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

# Platform patterns

> Common Connect shapes and splitting one sale across payees.

Each pattern starts from a test key and no existing payee. The sheet is `https://js.easner.com/v1/connect.js`. Live money stays off until a person saves the fee on the program.

Every path:

1. `POST /v1/payees` with your reference.
2. `POST /v1/link_sessions` and open `EasnerConnect.connect` with the `client_secret`.
3. In test mode, approve as a test payee.
4. `POST /v1/payees/:id/credits` for what they earned.
5. Either wait for the daily automatic payout, or `POST /v1/payout_sessions` and open `EasnerConnect.withdraw`.

For a first run in test, follow [Quickstart](https://docs.easner.com/connect.md#quickstart) on the Connect overview.

## Distributor

A label pays an artist. Create a payee with `income_type: royalties`, open a link session, and let the person connect. Credits land on the payee balance. The person withdraws from the sheet.

## Marketplace

A marketplace pays a seller. The payee reference is the seller id. A payout session with `source: platform_balance` withdraws a fixed amount the marketplace set.

## Gig

A gig platform pays after a job. Credit the payee when the job is done. The first payout can be held by the program's first-payout rule. When the client pays you first and you release after approval, follow [Holding funds until the work is done](https://docs.easner.com/connect-escrow.md).

## Affiliate

An affiliate program pays a referrer. The payee reference is the affiliate id. Income type is `other_income`.

## Creator

A course or membership site pays a teacher. Income type is `royalties` or `services`. The teacher connects once and later withdrawals use the same payee.

## Splitting one sale between several payees

A song with three writers, a bundle from two sellers, a course taught by two people. Easner has no separate split object: you decide the shares, then add them together in one call with `POST /v1/credits/batch`. The batch is all or nothing, so either every payee is credited or nobody is, and the same `Idempotency-Key` never credits twice.

Work in whole cents and make the shares add up exactly. Give each payee `floor(total × share)`, then hand the leftover cents one at a time to the payees with the largest remainders (earlier payees first on a tie). The batch's `total` control total refuses a split that does not add up.

```js theme={null}
function splitCents(total, sharesInBasisPoints) {
  // sharesInBasisPoints add up to 10000, for example [5000, 3000, 2000]
  const exact = sharesInBasisPoints.map((bps) => (total * bps) / 10000)
  const parts = exact.map(Math.floor)
  let left = total - parts.reduce((a, b) => a + b, 0)
  exact.map((x, i) => [x - parts[i], i]).sort((a, b) => b[0] - a[0] || a[1] - b[1])
    .forEach(([, i]) => { if (left-- > 0) parts[i] += 1 })
  return parts
}

const [a, b, c] = splitCents(100001, [5000, 3000, 2000]) // 50001, 30000, 20000 (a gets the odd cent)
await post("/v1/credits/batch", {
  count: 3, total: 100001,
  credits: [
    { payee: "pye_writer1", amount: a, reference: "sale-9120-w1" },
    { payee: "pye_writer2", amount: b, reference: "sale-9120-w2" },
    { payee: "pye_writer3", amount: c, reference: "sale-9120-w3" },
  ],
}, { "Idempotency-Key": "sale-9120" })
```

Use one reference per payee per sale (`sale-9120-w1`). If the sale is refunded, reverse each credit with `POST /v1/credits/:id/reversals`; what was already paid out becomes an offset against that payee's future credits.


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