Comprehensive documentation for integrating with our payment system
Introduction
OptimaPay Payment Gateway API allows you to integrate M-Pesa STK Push payments into your applications. This documentation provides details on how to configure your system, initiate payments, and track transactions in real-time.
To track transactions in real-time, implement a polling mechanism that checks the status of a payment at regular intervals until it's completed or failed.
PHP Implementation Example
<?php
// Function to check payment status
function checkPaymentStatus($apiKey, $apiSecret, $checkoutRequestId) {
$url = "https://www.infinity.gazelleusacompany.com/api/v2/status.php";
$data = ['checkout_request_id' => $checkoutRequestId];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-Key: ' . $apiKey,
'X-API-Secret: . $apiSecret,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return json_decode($response, true);
}
// Example usage after initiating payment
$checkoutRequestId = $result['checkout_request_id']; // From STK Push response
// Check status with polling (every 5 seconds for up to 2 minutes)
$maxAttempts = 24;
$attempt = 0;
while ($attempt < $maxAttempts) {
$status = checkPaymentStatus($apiKey, $apiSecret, $checkoutRequestId);
if ($status['success']) {
if ($status['status'] === 'completed') {
echo "Payment completed. Transaction Code: " . $status['transaction_code'];
break;
} elseif ($status['status'] === 'failed') {
echo "Payment failed.";
break;
}
// If still pending, continue polling
}
$attempt++;
sleep(5); // Wait 5 seconds before next check
}
if ($attempt >= $maxAttempts) {
echo "Payment status check timeout.";
}
?>
Error Handling
The API uses standard HTTP status codes to indicate success or failure:
Code
Description
200
Success
400
Bad Request - Invalid parameters
401
Unauthorized - Invalid API credentials
404
Not Found - Resource not found
405
Method Not Allowed
500
Internal Server Error
Common Error Messages
Insufficient service balance - Top up your account to cover transaction fees
Invalid payment account ID - Check your payment account ID
Transaction not found - The checkout_request_id doesn't exist
Missing required parameter - Check that all required parameters are provided
Complete Test Code
Here's a complete PHP implementation that includes a user interface for testing the API:
OptimaPayBridge provides a high-performance unified payment middleware. We seamlessly bridge global clearing networks, Visa/Mastercard processing, and localized payment protocols into a single, cohesive API ecosystem, executing real-time account settlements automatically.
Commercial Fee Transparency
Our bridge leverages an optimized 8.0% aggregate commercial fee model. This breakdown accounts for underlying processing overheads combined with your dedicated service markup. Merchants securely clear and retain exactly 92.0% of gross processing volumes directly inside their operational ledger.
Payment Channel
Total Aggregate Fee
Settlement Target
Secure Card Checkout (Visa/Mastercard)
8.0%
xdigitex_balance (KES)
Mobile Money Processing
8.0%
xdigitex_balance (KES)
Crypto Assets (USDT/BTC)
8.0%
xdigitex_balance (KES)
Secure Authentication
All inbound commercial API requests must pass signature security tokens within the HTTP headers. Live credentials can be rotated inside your merchant dashboard manager.
To explicitly check, process status variations, or safely force-reflect credit executions directly into your xdigitex_balance repository via backend mechanisms, transmit signed validations to our core commercial callback controller.
POST https://optimapaybridge.co.ke/api/v2/xdigitex_callback.php
Payload Requirements: Pass the transaction reference key inside a standard JSON string payload while serving operational authorization tokens across corresponding headers.
Callback Query Structure
{
"reference": "REF_TX_XYZ7890"
}
Interactive API Playground
Verify network configurations and test connection instances against real-time data states instantly below.
Topup (STK Push) API for Wallet
The Topup API enables automated customer-initiated deposits (STK Push) straight to your OptimaPay Service Wallet. Note that a 6% processing fee is deducted from your Service Balance upfront for every transaction.
The customer mobile number to receive the STK Push prompt (e.g., 0712345678 or 254712345678).
amount
Float
Yes
The principal amount to deposit in KES. Must be greater than 0.
Sample Request Body
{
"phone": "0712345678",
"amount": 100.00
}
API Responses
This endpoint utilizes a hybrid synchronous loop. If the customer enters their PIN within 5 seconds, a completed response is delivered instantly. Otherwise, it falls back to a pending status awaiting callback execution.
1. Synchronous Success Response (PIN entered within 5s)
<?php
// Listener URL on your server
$input = file_get_contents('php://input');
$data = json_decode($input, true);
if (isset($data['status']) && $data['status'] === 'success') {
$receipt = $data['mpesa_receipt'];
$ref = $data['reference'];
// Update your order status to 'Paid' in your database
// notify_user($ref);
http_response_code(200);
echo json_encode(["message" => "Acknowledged"]);
}
?>
Merchant Gateway: Crypto Deposit API ⚡
Enable your users to pay via USDT (TRC20) with automatic conversion to KES.
8% Platform FeeDeducted from gross USD
128.00 KES RateFixed settlement value
Auto-SettlementDirect to service_wallet
1. The Request Endpoint
Trigger a new deposit by sending a POST request with your API credentials in the headers.
⚠️ Network Restriction:
This service exclusively supports **USDT via TRON (TRC20)**. Sending funds via other networks like Ethereum (ERC20) or BSC (BEP20) will result in a permanent loss of funds.
Support
If you need help integrating with our API, please contact our support team.