SDKs & Integrations
PHP

PHP SDK

The official Novasend SDK for PHP provides a robust and typed interface to integrate Mobile Money payments into your PHP projects (Symfony, Laravel, or native PHP).

Prerequisites

  • PHP >= 8.1
  • Extensions: curl, json

Installation

Install the package via Composer:

composer require novasend/novasend-php

Configuration

Use environment variables (putenv or a .env file) to store your keys securely.

.env
NOVASEND_API_KEY=your_public_key
NOVASEND_SECRET_KEY=your_secret_key
NOVASEND_BASE_URL=https://business.novasend.app

Usage

Client Initialization

use Novasend\NovasendClient;
 
$client = new NovasendClient(
    apiKey:    getenv('NOVASEND_API_KEY'),
    secretKey: getenv('NOVASEND_SECRET_KEY'),
    baseUrl:   getenv('NOVASEND_BASE_URL'),
    language:  'en', // 'fr' or 'en'
);

Create a Payment (Wallet)

$response = $client->createWalletPayment([
    'reference'    => 'cmd_98765',
    'amount'       => 5000,
    'msisdn'       => '+2250101010101',
    'customerName' => 'Alice Koffi',
    'country'      => 'CI',
    'action' => [
        'successUrl' => 'https://your-site.com/thanks',
        'failureUrl' => 'https://your-site.com/error',
    ],
]);
 
header('Location: ' . $response['paymentUrl']);
exit;

Check Status

$status = $client->getPaymentStatus('cmd_98765');
echo "Current status: " . $status['status'];

Advanced Features

Webhooks (Automatic Confirmation)

Use the NovasendWebhooks class to validate payment notifications sent by Novasend.

use Novasend\NovasendWebhooks;
 
$webhooks = new NovasendWebhooks(getenv('NOVASEND_WEBHOOK_SECRET'));
 
$payload   = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_SIGNATURE_VALUE'] ?? '';
 
try {
    $event = $webhooks->verifySignature($payload, $signature);
    // Process the event (e.g., update the order in DB)
    http_response_code(200);
    echo 'OK';
} catch (\Exception $e) {
    // Invalid signature or corrupted payload
    http_response_code(401);
    echo 'Unauthorized';
}

Automatic Validation

The SDK throws an exception even before the network call if:

  • The amount is out of limits (Payin: 100 - 2M FCFA, Payout: 200 - 1.5M FCFA).
  • The phone number format is invalid for the chosen country.
  • The OTP is missing for a direct Orange Money payment.

The SDK automatically handles the X-Idempotency-Key header with a unique UUID v4 for each request, ensuring an operation is never executed twice.