Collections API
Accept payments from customers via mobile money networks.
Overview​
The Collections API allows you to request payments from customers using their mobile money accounts. Currently supporting Airtel Money in Tanzania.
Endpoint​
POST /payment-service/airtel/c2b
Authentication​
Requires Bearer token authentication:
Authorization: Bearer YOUR_API_TOKEN
Request Parameters​
Parameter | Type | Required | Description |
---|---|---|---|
phone_number | string | Yes | Customer's phone number (E.164 format) |
amount | string | Yes | Amount to collect (minimum 500 TZS) |
external_id | string | No | Your unique transaction reference |
Request Example​
{
"phone_number": "+255683542710",
"amount": "1000"
}
Response Example​
Success Response​
{
"status": "success",
"message": "Payment request sent successfully",
"transaction_id": "TXN_123456789",
"reference": "GCA_REF_987654321",
"amount": "1000",
"currency": "TZS",
"phone_number": "+255683542710",
"status_code": "PENDING"
}
Error Response​
{
"status": "error",
"message": "Invalid phone number format",
"error_code": "INVALID_PHONE_NUMBER"
}
Status Codes​
Code | Description |
---|---|
PENDING | Payment request sent to customer |
SUCCESS | Payment completed successfully |
FAILED | Payment failed or was rejected |
TIMEOUT | Payment request timed out |
Implementation Example​
JavaScript/Node.js​
const axios = require('axios');
async function requestPayment(phoneNumber, amount) {
try {
const response = await axios.post(
'https://gcapay.site/api/v1/payment-service/airtel/c2b',
{
phone_number: phoneNumber,
amount: amount.toString()
},
{
headers: {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json'
}
}
);
console.log('Payment initiated:', response.data);
return response.data;
} catch (error) {
console.error('Payment failed:', error.response?.data);
throw error;
}
}
// Usage
requestPayment('+255683542710', 1000);
Python​
import requests
def request_payment(phone_number, amount):
url = "https://gcapay.site/api/v1/payment-service/airtel/c2b"
headers = {
"Authorization": "Bearer YOUR_API_TOKEN",
"Content-Type": "application/json"
}
payload = {
"phone_number": phone_number,
"amount": str(amount)
}
try:
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Payment request failed: {e}")
raise
# Usage
result = request_payment("+255683542710", 1000)
print(result)
PHP​
<?php
function requestPayment($phoneNumber, $amount) {
$url = 'https://gcapay.site/api/v1/payment-service/airtel/c2b';
$data = array(
'phone_number' => $phoneNumber,
'amount' => (string)$amount
);
$headers = array(
'Authorization: Bearer YOUR_API_TOKEN',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
return json_decode($response, true);
} else {
throw new Exception("Payment request failed: " . $response);
}
}
// Usage
try {
$result = requestPayment('+255683542710', 1000);
echo json_encode($result, JSON_PRETTY_PRINT);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>
Best Practices​
Phone Number Format​
- Always use E.164 format:
+255683542710
- Validate format before sending requests
- Handle international prefixes correctly
Amount Handling​
- Send amounts as strings to avoid floating-point issues
- Minimum amount: 500 TZS
- Validate amounts are positive integers
Error Handling​
- Implement retry logic for network failures
- Log all transactions for reconciliation
- Handle timeout scenarios gracefully
Security​
- Never expose API tokens in client-side code
- Implement rate limiting on your endpoints
- Validate all input parameters
Testing​
Use the following test credentials in sandbox environment:
- Test Phone:
+255683542710
- Test Amount:
1000
- Expected Result: Success response
Transaction Flow​
- Initiate: Send payment request to GCA Pay
- Customer Prompt: Customer receives payment prompt on their phone
- Authorization: Customer enters PIN to authorize payment
- Completion: Transaction completes and webhook is sent
- Confirmation: You receive final status via webhook
Next Steps​
- Disbursements API → - Send money to recipients
- Webhooks → - Handle transaction status updates
- Transaction Inquiry → - Query transaction status