Customer wallets
Hold a balance for each of your customers: collect into it, pay out from it, move between them. We keep the ledger.
Customer wallets let you hold a balance for each of your own customers (riders, farmers, sellers on your marketplace, members of a chama) inside your workspace balance. We keep the ledger, so you don't have to build one. Endpoint details are in the Customers reference.
Whose money it is. A customer wallet is your own record of how your workspace balance is split. All the money in it belongs to your business. AutoPayKe doesn't hold funds for your customers, open accounts for them, or let them withdraw directly: only your API key can move a wallet.
If you let your customers keep balances with you, that can count as holding e-money or deposits. In Kenya that needs authorisation from the Central Bank under the National Payment System Act. Check what applies to your business before you offer it.
How it works
# 1. A wallet for one of your customers
curl https://api.autopayke.com/api/v1/customers \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY" \
-H "Idempotency-Key: rider-118" \
-H "Content-Type: application/json" \
-d '{ "name": "Jane Wanjiku", "reference": "rider-118", "phone": "+254712345678" }'
# 2. Collect into it: when the customer pays, their wallet is credited
curl https://api.autopayke.com/api/v1/collections \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY" \
-H "Idempotency-Key: deposit-118-001" \
-H "Content-Type: application/json" \
-d '{ "amount": 500000, "currency": "KES", "payer": { "phone": "+254712345678" },
"customer": "cus_6Tn3Qw8Lx2Zp7Vk4Rm9Yd5Hc" }'
# 3. Pay out from it: refused if the customer's balance doesn't cover it
curl https://api.autopayke.com/api/v1/payouts \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY" \
-H "Idempotency-Key: withdraw-118-001" \
-H "Content-Type: application/json" \
-d '{ "amount": 200000, "currency": "KES", "customer": "cus_6Tn3Qw8Lx2Zp7Vk4Rm9Yd5Hc",
"destination": { "type": "mobile_money", "phone": "+254712345678" } }'| You send | What happens to the customer's wallet |
|---|---|
A collection with customer | Credited with what reached your balance (after the collection fee) once it succeeds. |
A payout with customer | Debited by the payout's total with fees. Refused with CUSTOMER_INSUFFICIENT_BALANCE if it doesn't cover it. |
| A payout that fails or comes back | The full amount goes back to the wallet, once. |
| A refund of a customer's collection | Paid from that customer's wallet. |
POST /api/v1/customer-transfers | Moves balance between two customers. No money leaves the workspace. |
POST /api/v1/customers/{id}/adjustments | Credits or debits by hand, with a reason: a bank deposit you received, a correction. |
Guarantees
- A wallet never goes below zero. Each change locks the customer, so payouts and transfers sent at the same moment can't spend the same money twice.
- Every change is a balance transaction with the balance after it:
GET /api/v1/customers/{id}/balance-transactions. - The same collection, payout or Idempotency-Key is never applied to a wallet twice.
GET /api/v1/balanceshowsallocated_to_customers_usdc: what your customers hold in total. Keep your workspace balance above it.
Testing
With an apk_test_ key, create a customer, collect from +254700000001 with their id, then pay out from their wallet. Pay out to +254700000002 to see a failed payout return to the wallet.