Sales, fees and settlements
A customer pays a merchant $100.00 through your gateway. You keep a $2.00 fee and later settle $98.00 to the merchant's bank. That is one sale, but three events reach your backend, and each moves money differently.
These are the merchant's books, kept in the merchant's Paprel company. They are not your gateway's own books. Revenue is $100.00, the fee is an $2.00 expense, and the bank receives $98.00.
How revenue gets double-counted
Revenue is recognised once, when the sale happens. The settlement only moves money the merchant has already earned.
| Mistake | Revenue shown | Should be |
|---|---|---|
| Credit revenue at capture and again at settlement | $198.00 | $100.00 |
| Record only the settlement as revenue | $98.00, with no fee expense | $100.00 revenue and $2.00 expense |
| Post a journal when an invoice has already recognised the sale | $200.00 | $100.00 |
| Categorise the bank feed's $98.00 as income after posting these journals | $198.00 | $100.00 |
A clearing account prevents this. It holds what the gateway owes the merchant, so the sale, the fee and the settlement each touch it, and it returns to zero when the money arrives.
| Account | Debit | Credit |
|---|---|---|
| Payment Gateway Clearing | $100.00 | — |
| Sales Revenue | — | $100.00 |
| Transaction Fee Expense | $2.00 | — |
| Payment Gateway Clearing | — | $2.00 |
| Bank Account (on settlement) | $98.00 | — |
| Payment Gateway Clearing | — | $98.00 |
Payment Gateway Clearing ends at $100.00 − $2.00 − $98.00 = $0.00.
Choose one source of revenue for each sale. If the merchant raises Paprel invoices for these sales, the invoice has already recognised revenue. Do not post the sale journal. Record the payment against the invoice with POST /v1/invoices/{id}/payment and an Idempotency-Key, using bank_charge for the fee. Add bank_charge_account_id to post that fee to a specific expense account instead of the default Bank Charges account.
Before you start
Working in your own language? These samples use plain HTTP. You can generate a typed Partner API client from openapi-partner.json with the same generators; see SDKs and client libraries.
Complete Your first accounting entry first. You need a provisioned company and a session whose permissions allow account and journal writes. Sessions are short-lived, so mint a new one when expires_at passes.
export BASE="https://api.paprel.com"
export AUTH="authorization: Bearer $SESSION_TOKEN"
export PARTNER="x-partner-domain: $PARTNER_DOMAIN"
export CT="content-type: application/json"
1. Set up the merchant's accounts
Read the company's chart with GET /v1/accounting/accounts. Find its existing bank, revenue and fee expense accounts, and reuse them where they fit. Then create the clearing account as an asset, using a kind and account_subtype from the asset accounts in that response:
curl -X POST "$BASE/v1/accounting/accounts" \
-H "$AUTH" -H "$PARTNER" -H "$CT" \
-d '{
"account": "Payment Gateway Clearing",
"kind": "<asset kind from the chart>",
"account_subtype": "<asset subtype from the chart>",
"currency": "USD",
"is_sub_account": false
}'
Store the returned data.id with the merchant record, so you create the account once per company. Account ids differ between companies.
2. Record the sale at gross
Post the full $100.00 when the payment is captured, not the net amount:
| Account | Debit | Credit |
|---|---|---|
| Payment Gateway Clearing | $100.00 | — |
| Sales Revenue | — | $100.00 |
curl -X POST "$BASE/v1/accounting/journals" \
-H "$AUTH" -H "$PARTNER" -H "$CT" \
-d '{
"date": "2026-11-02",
"currency": "USD",
"reference": "TXN-10001",
"description": "Gateway sale TXN-10001",
"posted": true,
"lines": [
{ "account_id": "<Payment Gateway Clearing id>", "description": "Gross amount captured", "debit": "100.00" },
{ "account_id": "<Sales Revenue id>", "description": "Sale TXN-10001", "credit": "100.00" }
],
"meta_data": { "root_entity_type": "gateway_sale", "root_entity_id": "TXN-10001" }
}'
3. Record the fee
| Account | Debit | Credit |
|---|---|---|
| Transaction Fee Expense | $2.00 | — |
| Payment Gateway Clearing | — | $2.00 |
curl -X POST "$BASE/v1/accounting/journals" \
-H "$AUTH" -H "$PARTNER" -H "$CT" \
-d '{
"date": "2026-11-02",
"currency": "USD",
"reference": "TXN-10001-FEE",
"description": "Gateway fee for TXN-10001",
"posted": true,
"lines": [
{ "account_id": "<Transaction Fee Expense id>", "description": "Transaction fee", "debit": "2.00" },
{ "account_id": "<Payment Gateway Clearing id>", "description": "Fee withheld by gateway", "credit": "2.00" }
],
"meta_data": { "root_entity_type": "gateway_fee", "root_entity_id": "TXN-10001" }
}'
If the fee is known at capture, you can post the sale and fee as one journal instead: debit clearing 98.00, debit fees 2.00 and credit revenue 100.00. Revenue is still gross, and you have one less write to track.
4. Record the settlement
When the money reaches the bank, move it out of clearing. Revenue is not on this journal.
| Account | Debit | Credit |
|---|---|---|
| Bank Account | $98.00 | — |
| Payment Gateway Clearing | — | $98.00 |
curl -X POST "$BASE/v1/accounting/journals" \
-H "$AUTH" -H "$PARTNER" -H "$CT" \
-d '{
"date": "2026-11-04",
"currency": "USD",
"reference": "STL-20261104",
"description": "Gateway settlement STL-20261104",
"posted": true,
"lines": [
{ "account_id": "<Bank Account id>", "description": "Settlement received", "debit": "98.00" },
{ "account_id": "<Payment Gateway Clearing id>", "description": "Settlement STL-20261104", "credit": "98.00" }
],
"meta_data": { "root_entity_type": "gateway_settlement", "root_entity_id": "STL-20261104" }
}'
A settlement usually covers many transactions. Post one settlement journal for the batch's net amount, and keep the batch's transaction list on your side against STL-20261104.
If the merchant also imports bank transactions, match the $98.00 deposit to this journal. Categorising it as income is the last row of the table above.
5. Verify the books
Find a journal from your own id. entity_type must match the root_entity_type you posted:
curl --get "$BASE/v1/accounting/journals/for-entity" \
-H "$AUTH" -H "$PARTNER" \
--data-urlencode 'entity_type=gateway_settlement' \
--data-urlencode 'entity_id=STL-20261104' \
| jq '.data[] | {anchor_id, identifier, is_posted}'
Then check the balances:
curl --get "$BASE/v1/reports/trial-balance" \
-H "$AUTH" -H "$PARTNER" \
--data-urlencode 'date=2026-11-04' \
| jq '.data.trial_balance[] | {account_name, debit, credit, balance}'
After this example, expect:
| Account | Debit | Credit |
|---|---|---|
| Payment Gateway Clearing | — | — |
| Sales Revenue | — | $100.00 |
| Transaction Fee Expense | $2.00 | — |
| Bank Account | $98.00 | — |
In live books, clearing equals captured sales less fees and settlements that have not landed yet. Compare it with your gateway's unsettled balance for that merchant. A difference points to a missing or duplicate journal.
Handle retries and other events
Retries. Gateway webhooks are often delivered more than once, and Paprel does not deduplicate journals. Record each gateway event ID in your own database before posting, and keep at most one request in flight per event. After an ambiguous timeout, follow the journal retry rule; do not resend automatically.
Refunds. Post the sale in reverse under its own root_entity_id: debit revenue, or a sales returns account, and credit clearing. Whether your gateway returns its fee depends on your terms. Post a fee reversal only if it does.
Chargebacks. Reverse the sale through clearing the same way. Post any dispute fee as a separate expense.
Foreign currency. Each journal in another currency needs exchange_rate, in base-currency units per unit of the journal currency. A clearing account can keep a small balance when rates differ between capture and settlement, so agree the treatment with the merchant's accountant.
Tax. These examples leave out sales tax and other taxes. Sales tax and tax on fees depend on the merchant and jurisdiction.
Volume. One journal per transaction gives the most detail. For high-volume merchants, a daily summary journal per settlement batch may suit better, provided you keep the transaction detail on your side.
Before launch, work through the production checklist.
Next: retail and F&B point of sale.