← Rudi Mipangilio

HarakaPay API

Unganisha mfumo wako wa malipo na HarakaPay. Pokea malipo ya USSD push moja kwa moja kwenye app au website yako.

Authentication

Kila ombi lazima liwe na API key yako kwenye header:

X-API-Key: hpk_your_api_key_here

Unaweza kupata API key yako kwenye Mipangilio.

Endpoints

1. Kukusanya Malipo

POSThttps://harakapay.net/api/v1/collect

Tuma ombi la malipo kwa simu ya mteja kupitia USSD push.

ParameterTypeRequiredDescription
phonestringYesNamba ya simu (mfano: 0712345678)
amountnumberYesKiasi cha TZS (min: 100)
descriptionstringNoMaelezo ya malipo
webhook_urlstringNoURL ya kupokea taarifa (POST) pale status itakapotofautiana kwa "completed" au "failed".

Response (Success):

{
  "success": true,
  "message": "USSD push sent to phone",
  "order_id": "HP1706123456789",
  "amount": 10000,
  "net_amount": 9400,
  "fee": 600
}

2. Angalia Hali ya Malipo

GEThttps://harakapay.net/api/v1/status/{order_id}

Angalia hali ya malipo kwa kutumia order_id. Endpoint hii pia inatoa fursa ya kusababisha HarakaPay kutuma
takwimu kwenye webhook_url kama ulivyopatia wakati wa /api/v1/collect.

{
  "success": true,
  "payment": {
    "order_id": "HP1706123456789",
    "status": "completed",
    "amount": 10000,
    "net_amount": 9400,
    "fee_amount": 600,
    "created_at": "2026-01-24T12:00:00Z",
    "completed_at": "2026-01-24T12:01:30Z"
  }
}

3. Angalia Salio

GEThttps://harakapay.net/api/v1/balance
{
  "success": true,
  "wallet_balance": 94000,
  "float_balance": 50000
}

Webhook Notifications

Ikiwa ulikuwa umeongeza webhook_url kwenye ombi la /api/v1/collect, HarakaPay itatuma POST mara moja (kila inapotokea) unapopokea matokeo ya completed au failed kutoka Selcom. Mwisho wa maombi haya ni 200; tukio la nje halijatambuliwa hatutarekodi taarifa ya kutuma.

{
  "order_id": "HP1706123456789",
  "status": "completed",
  "amount": 10000,
  "net_amount": 9400,
  "fee_amount": 600,
  "created_at": "2026-01-24T12:00:00Z",
  "completed_at": "2026-01-24T12:01:30Z"
}

Mfano wa PHP

<?php
// HarakaPay PHP Integration Example

class HarakaPay {
    private $apiKey;
    private $baseUrl = 'https://harakapay.net';
    
    public function __construct($apiKey) {
        $this->apiKey = $apiKey;
    }
    
    public function collectPayment($phone, $amount, $description = '') {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->baseUrl . '/api/v1/collect');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Content-Type: application/json',
            'X-API-Key: ' . $this->apiKey
        ]);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
            'phone' => $phone,
            'amount' => $amount,
            'description' => $description,
            'webhook_url' => 'https://your-domain.com/harakap-webhook' // optional callback URL
        ]));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
        $response = curl_exec($ch);
        curl_close($ch);
        
        return json_decode($response, true);
    }
    
    public function checkStatus($orderId) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->baseUrl . '/api/v1/status/' . $orderId);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'X-API-Key: ' . $this->apiKey
        ]);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
        $response = curl_exec($ch);
        curl_close($ch);
        
        return json_decode($response, true);
    }
    
    public function getBalance() {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->baseUrl . '/api/v1/balance');
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'X-API-Key: ' . $this->apiKey
        ]);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
        $response = curl_exec($ch);
        curl_close($ch);
        
        return json_decode($response, true);
    }
}

// Jinsi ya Kutumia:
$harakaPay = new HarakaPay('hpk_your_api_key_here');

// Kusanya malipo
$result = $harakaPay->collectPayment('0712345678', 10000, 'Bidhaa yangu');

if ($result['success']) {
    echo 'Order ID: ' . $result['order_id'];
    // Hifadhi order_id kwenye database yako
} else {
    echo 'Error: ' . $result['error'];
}

// Baadaye, angalia hali ya malipo
$status = $harakaPay->checkStatus('HP1706123456789');
if ($status['payment']['status'] === 'completed') {
    echo 'Malipo yamekamilika!';
}
?>

Mfano wa JavaScript (Node.js)

const axios = require('axios');

const API_KEY = 'hpk_your_api_key_here';
const BASE_URL = 'https://harakapay.net';

async function collectPayment(phone, amount, description) {
    const response = await axios.post(`${BASE_URL}/api/v1/collect`, {
        phone, amount, description,
        webhook_url: 'https://your-domain.com/harakap-webhook' // optional callback URL
    }, {
        headers: { 'X-API-Key': API_KEY }
    });
    return response.data;
}

async function checkStatus(orderId) {
    const response = await axios.get(`${BASE_URL}/api/v1/status/${orderId}`, {
        headers: { 'X-API-Key': API_KEY }
    });
    return response.data;
}

// Mfano wa matumizi
collectPayment('0712345678', 10000, 'Bidhaa').then(result => {
    console.log('Order ID:', result.order_id);
});

Mfano wa Python

import requests

API_KEY = 'hpk_your_api_key_here'
BASE_URL = 'https://harakapay.net'

class HarakaPay:
    def __init__(self, api_key):
        self.api_key = api_key
        self.headers = {
            'Content-Type': 'application/json',
            'X-API-Key': api_key
        }
    
    def collect_payment(self, phone, amount, description=''):
        """Tuma ombi la malipo kwa simu ya mteja"""
        response = requests.post(
            f'{BASE_URL}/api/v1/collect',
            json={
                'phone': phone,
                'amount': amount,
                'description': description,
                'webhook_url': 'https://your-domain.com/harakap-webhook'  # optional callback URL
            },
            headers=self.headers
        )
        return response.json()
    
    def check_status(self, order_id):
        """Angalia hali ya malipo"""
        response = requests.get(
            f'{BASE_URL}/api/v1/status/{order_id}',
            headers=self.headers
        )
        return response.json()
    
    def get_balance(self):
        """Angalia salio lako"""
        response = requests.get(
            f'{BASE_URL}/api/v1/balance',
            headers=self.headers
        )
        return response.json()

# Jinsi ya Kutumia:
harakapay = HarakaPay('hpk_your_api_key_here')

# Kusanya malipo
result = harakapay.collect_payment('0712345678', 10000, 'Bidhaa yangu')

if result.get('success'):
    print(f"Order ID: {result['order_id']}")
    # Hifadhi order_id kwenye database yako
else:
    print(f"Error: {result.get('error')}")

# Baadaye, angalia hali ya malipo
status = harakapay.check_status('HP1706123456789')
if status.get('payment', {}).get('status') == 'completed':
    print('Malipo yamekamilika!')

# Angalia salio
balance = harakapay.get_balance()
print(f"Wallet: TZS {balance['wallet_balance']}")
print(f"Float: TZS {balance['float_balance']}")

Ada za Malipo

HarakaPay inakata ada kulingana na aina ya akaunti yako:

KiasiAda Personal (5.9%)UnapataAda Biashara (2.9%)Unapata
TZS 10,000TZS 590TZS 9,410TZS 290TZS 9,710
TZS 50,000TZS 2,950TZS 47,050TZS 1,450TZS 48,550
TZS 100,000TZS 5,900TZS 94,100TZS 2,900TZS 97,100

Msaada

Kama una maswali au unahitaji msaada, wasiliana nasi kupitia barua pepe: support@harakapay.net