Skip to content

Farmer Payout

Triggers a USDC → UGX → MTN Mobile Money payout to a farmer via Kotani Pay. Called automatically by the Alchemy webhook on EXPORTED event. Can also be called manually by a COOPERATIVE token for exceptional cases (e.g. net-only payment without a loan).

POST /payments/farmer-payout

Auth: COOPERATIVE or ADMIN token.

Terminal window
curl -X POST https://api.asilichain.xyz/payments/farmer-payout \
-H "Authorization: Bearer {cooperative_token}" \
-H "Content-Type: application/json" \
-d '{
"farmer_id": "UG-KAS-2024-001234",
"batch_id": "BATCH-2026-004821",
"amount_usdc": 518.50,
"reason": "NET_COFFEE_PAYMENT",
"cooperative_id": "COOP-MBALE-001"
}'
FieldTypeRequiredDescription
farmer_idstringYesMAAIF farmer ID
batch_idstringYesAssociated batch reference for audit
amount_usdcnumberYesUSDC amount to disburse
reasonstringYesNET_COFFEE_PAYMENT, LOAN_DISBURSEMENT, TOP_UP, MANUAL
cooperative_idstringYesMust match token’s cooperative
{
"payout_id": "PAY-2026-004821-001",
"status": "PROCESSING",
"farmer_id": "UG-KAS-2024-001234",
"amount_usdc": 518.50,
"estimated_ugx": 1910882,
"phone": "+256XXXXXXXX",
"kotanipay_reference": "KP-2026-XYZ",
"estimated_completion_seconds": 60,
"created_at": "2026-04-20T12:00:00Z"
}
Terminal window
GET /payments/farmer-payout/{payout_id}
{
"payout_id": "PAY-2026-004821-001",
"status": "COMPLETED",
"amount_usdc": 518.50,
"amount_ugx": 1910882,
"kotanipay_reference": "KP-2026-XYZ",
"mtn_transaction_id": "MTN20260420123456",
"completed_at": "2026-04-20T12:00:47Z",
"elapsed_seconds": 47
}
StatusMeaning
PROCESSINGKotani Pay accepted, MTN MoMo pending
COMPLETEDFarmer received MTN MoMo notification
FAILEDKotani Pay returned error — retry queued
RETRY_1 / RETRY_2 / RETRY_3Automatic retry in progress
MANUAL_REVIEWThree retries exhausted — requires human intervention

On FAILED, the system automatically retries at 30s / 60s / 120s intervals. On MANUAL_REVIEW, cooperative manager is notified and farmer can collect at cooperative office against batch receipt. The batch is still marked SETTLED on-chain — the USDC is held in a Supabase-recorded holding balance.

CodeTrigger
FARMER_NOT_REGISTEREDfarmer_id not in FarmerRegistry
PHONE_NOT_FOUNDNo phone number on record for farmer
DUPLICATE_PAYOUTPayout already processed for this batch + reason
KOTANIPAY_UNAVAILABLEKotani Pay API unreachable after 3 attempts