Fees API

Retrieve current service fees and withdrawal charges with transparent pricing structure.

Free Tier
KES 1 - 49
KES 0.00
No service or withdrawal fees

Base Endpoint

GET
/v3/fees/
This endpoint requires API key authentication. Manage keys at /api_keys.php.

Get Fee Structure

Retrieve the complete fee structure including service fees and withdrawal charges for all transaction amounts.

GET
/v3/fees/

Authorization: Bearer YOUR_API_KEY

GET
/v3/fees/?api_key=YOUR_API_KEY

Alternative with query parameter

{ "success": true, "message": "Service fees retrieved successfully", "data": { "fees": [ { "id": 1, "amount_range": { "from": 1.00, "to": 49.00 }, "service_fee": 0.00, "withdrawal_fee": 0.00, "currency": "KES", "is_active": true }, { "id": 2, "amount_range": { "from": 50.00, "to": 499.00 }, "service_fee": 6.00, "withdrawal_fee": 6.00, "currency": "KES", "is_active": true }, { "id": 3, "amount_range": { "from": 500.00, "to": 999.00 }, "service_fee": 10.00, "withdrawal_fee": 10.00, "currency": "KES", "is_active": true } ], "summary": { "total_fee_ranges": 3, "free_service_tiers": 1, "free_withdrawal_tiers": 1, "amount_range": { "minimum": 1.00, "maximum": 999.00, "currency": "KES" } }, "notes": [ "Service fees are charged per successful transaction", "Withdrawal fees apply to B2C money transfers", "Fees are automatically deducted from service wallet", "Failed transactions are not charged", "All amounts are in Kenyan Shillings (KES)" ] }, "timestamp": "2025-01-15T10:30:00Z" }

Response Structure

Fee Object
Field Type Description
id integer Unique identifier for this fee tier
amount_range object Contains from and to amounts for this tier
service_fee float Fee charged for STK Push transactions in this range
withdrawal_fee float Fee charged for B2C withdrawals in this range
currency string Currency code (always "KES" for Kenyan Shillings)
is_active boolean Whether this fee tier is currently active
Summary Object
Field Type Description
total_fee_ranges integer Total number of active fee tiers
free_service_tiers integer Number of tiers with 0 service fee
free_withdrawal_tiers integer Number of tiers with 0 withdrawal fee
amount_range object Overall minimum and maximum amounts supported

Error Responses

401 Unauthorized
Missing API Key
{ "success": false, "error": "Missing API key. Provide via Authorization header or api_key parameter." }
401 Unauthorized
Invalid API Key
{ "success": false, "error": "Invalid or revoked API key" }
405 Method Not Allowed
Wrong HTTP Method
{ "success": false, "error": "Method not allowed. Use GET to retrieve fees." }
500 Internal Server Error
Server Error
{ "success": false, "error": "Internal server error occurred while retrieving fees" }

Understanding Fees

Service Fees
Service Fees
  • Charged per successful STK Push
  • Deducted from service wallet
  • Based on transaction amount
  • Failed transactions not charged
Withdrawal Fees
  • Charged for B2C money transfers
  • Deducted from service wallet
  • Separate from transaction amount
  • Automatically calculated

Fee Calculation Examples

Pro Tip: Use this API to programmatically calculate fees before initiating transactions to inform your users of costs upfront.
Example: Calculate Fee for KES 750 Transaction
// Fetch fees from API
const response = await fetch('/v3/fees/', {
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY'
  }
});

const data = await response.json();

// Find applicable fee for KES 750
const amount = 750;
const applicableFee = data.data.fees.find(fee => 
  amount >= fee.amount_range.from && amount <= fee.amount_range.to
);

if (applicableFee) {
  console.log(`Service Fee: KES ${applicableFee.service_fee}`);
  console.log(`Withdrawal Fee: KES ${applicableFee.withdrawal_fee}`);
  console.log(`Total with Service Fee: KES ${amount + applicableFee.service_fee}`);
}
PHP Example
function calculateFee($amount, $fees) {
    foreach ($fees as $fee) {
        if ($amount >= $fee['amount_range']['from'] && 
            $amount <= $fee['amount_range']['to']) {
            return $fee;
        }
    }
    return null;
}

// Usage
$amount = 750;
$applicableFee = calculateFee($amount, $feesData['fees']);
if ($applicableFee) {
    echo "Service Fee: KES {$applicableFee['service_fee']}\n";
    echo "Withdrawal Fee: KES {$applicableFee['withdrawal_fee']}\n";
}

Example Usage

cURL Example
curl -X GET "http://localhost/pay-app/v3/fees/" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"
JavaScript/Node.js Example
const getFees = async () => {
  try {
    const response = await fetch('http://localhost/pay-app/v3/fees/', {
      method: 'GET',
      headers: {
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
      }
    });

    const result = await response.json();
    
    if (result.success) {
      console.log('Fee Structure:', result.data.fees);
      console.log('Summary:', result.data.summary);
      
      // Display free tiers
      const freeTiers = result.data.fees.filter(fee => fee.service_fee === 0);
      console.log(`Found ${freeTiers.length} free service tiers`);
    } else {
      console.error('Error:', result.error);
    }
  } catch (error) {
    console.error('Network error:', error);
  }
};

getFees();
Python Example
import requests

def get_fees(api_key):
    headers = {
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    }
    
    response = requests.get('http://localhost/pay-app/v3/fees/', headers=headers)
    
    if response.status_code == 200:
        data = response.json()
        if data['success']:
            return data['data']
    return None

# Usage
api_key = 'YOUR_API_KEY'
fees_data = get_fees(api_key)

if fees_data:
    print(f"Total fee ranges: {fees_data['summary']['total_fee_ranges']}")
    for fee in fees_data['fees']:
        print(f"KES {fee['amount_range']['from']}-{fee['amount_range']['to']}: "
              f"Service Fee KES {fee['service_fee']}, "
              f"Withdrawal Fee KES {fee['withdrawal_fee']}")

Best Practices

  • Cache Fee Data: Fee structures don't change frequently. Cache the response for improved performance.
  • Pre-calculate Costs: Show users the total cost including fees before initiating transactions.
  • Handle Edge Cases: Always validate that the transaction amount falls within supported ranges.
  • Monitor Changes: Regularly sync fee structures to stay updated with any pricing changes.
  • Error Handling: Implement proper error handling for API failures.

Related APIs

The Fees API works well with these other endpoints: