SDKs

PHP SDK

Install the Strongmb PHP client and handle successful, processing and failed purchases.

Install the package

Shell
composer require strongmb/strongmb-php

Install in your backend project and commit the dependency lockfile where supported. Consult the official repository for runtime requirements and releases.

Configure the API key

Set STRONGMB_API_KEY in your server environment. The example reads it from that variable. Separate development and production configuration. Never expose the key in a browser bundle.

A complete purchase example

PHP
<?php
require 'vendor/autoload.php';

use Strongmb\Strongmb;
use Strongmb\Exceptions\ApiException;
use Strongmb\Exceptions\AuthException;

$strongmb = new Strongmb(getenv('STRONGMB_API_KEY'));

try {
    $response = $strongmb->data->purchase(
        phone:       '0123456789',
        productCode: 'smb_mtn_sme_1gb_30days',
        reference:   'MYAPP' . strtoupper(uniqid()),
    );

    if ($response->successful()) {
        $data = $response->data();
        echo "1GB sent to {$data['recipient']}\n";
        echo "  Balance: ₦{$data['balance_after']}\n";
    } elseif ($response->processing()) {
        echo 'Processing… reference: ' . $response->data()['reference'];
    } elseif ($response->failed()) {
        echo 'Failed. Trace ID: ' . $response->traceId();
    }

} catch (AuthException $e) {
    echo 'Invalid API key.';
} catch (ApiException $e) {
    echo "Error [{$e->getApiCode()}]: {$e->getMessage()}";
}

How the example works

Part Explanation
Imports Load the client and relevant error types.
Constructor Reads the API key from your server environment.
Purchase arguments Set the recipient, product code and unique reference.
successful() Read the payload and show a completed receipt.
processing() Keep the order pending rather than repeating the purchase.
failed() Retain identifiers and reconcile the failed outcome.
Error handler Separate authentication, API and network failures.

Parameter naming

Use productCode in PHP named arguments and Node.js objects. The REST API uses product_code. Follow the client example for the runtime you use.

Reliable transaction handling

Persist the order before calling the client. A network failure leaves the outcome uncertain. Read transaction lifecycle for duplicate-reference handling and the current transaction lookup behavior.

Versions and troubleshooting

These examples follow the existing Strongmb SDK documentation. Check the SDK source and README for version-specific constructor options and available resources. Use the REST API for services not exposed by your installed SDK.

Customer names, phone numbers, meter and smart-card numbers in these examples are fictional placeholders. Replace them with valid customer details for real requests.

Questions? Let’s work through them.

Having an issue or need help with your integration? Join the Strongmb Slack community to ask questions and get assistance from our team and other developers.

Keep API keys and customer details private when sharing examples.

Experiencing a service issue? Check Strongmb’s service status for incident updates.

Join our Slack community

Did this page help you?

Search documentation