Docs
Dashboard Create account

PHP examples

Initiate a payment

<?php
$ch = curl_init('https://nixpay.supreonix.com/api/v1/payments/stk-push');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST           => true,
    CURLOPT_HTTPHEADER     => [
        'Authorization: Bearer ' . getenv('NIXPAY_SECRET_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'amount'            => 500,
        'phone'             => '254712345678',
        'account_reference' => 'INV-1042',
    ]),
]);

$response = json_decode(curl_exec($ch), true);
if (!$response['ok']) {
    error_log($response['error']['message']);
}

Verify a webhook signature

$raw  = file_get_contents('php://input');
$sent = $_SERVER['HTTP_X_NIXPAY_SIGNATURE'] ?? '';
$expected = 'sha256=' . hash_hmac('sha256', $raw, getenv('NIXPAY_WEBHOOK_SECRET'));

if (!hash_equals($expected, $sent)) {
    http_response_code(400);
    exit('Invalid signature');
}

$event = json_decode($raw, true);
if ($event['event'] === 'payment.success') {
    // mark the order paid using $event['data']['reference']
}

NixPay documentation · A Supreonix product Back to introduction