Skip to content

PHP SDK

The sangho/sangho-php SDK supports PHP 8.0+ with an object-oriented interface. Compatible with Laravel, Symfony, and any standard PHP project.

Installation

bash
composer require sangho/sangho-php

Configure your API key via the static method Sangho::setApiKey(). In production, use environment variables rather than hardcoded values.

Laravel — Sangho facade

With Laravel, publish the config file via php artisan vendor:publish –provider=“Sangho\SanghoServiceProvider”, then set SANGHO_SECRET_KEY in your .env. The Sangho:: facade is automatically available in all your controllers.

Initialization

php
<?php
use Sangho\Sangho;
// Global configuration (once, at bootstrap)
Sangho::setApiKey(getenv('SANGHO_SECRET_KEY'));
// Create a PaymentIntent
$intent = Sangho::paymentIntents()->create([
    'amount'               => 5000,
    'currency'             => 'XAF',
    'payment_method_types' => ['mobile_money', 'card'],
    'metadata'             => ['order_id' => 'CMD-001'],
]);
echo $intent->client_secret;

Error handling

All exceptions inherit from Sangho\Exception\SanghoException. Use subclasses to differentiate business cases.

Pagination

List endpoints return a ListObject with properties count, data, and has_more. Use page and page_size to navigate.

Automatic retry

The SDK automatically retries 429 and 5xx errors with exponential backoff. Configure via Sangho::setMaxNetworkRetries(3).

Error handling

php
<?php
use Sangho\Exception\AuthenticationException;
use Sangho\Exception\InvalidRequestException;
use Sangho\Exception\RateLimitException;
use Sangho\Exception\SanghoException;


try {
    $intent = Sangho::paymentIntents()->create([
        'amount'   => 5000,
        'currency' => 'XAF',
    ]);
} catch (AuthenticationException $e) {
    // Invalid or expired API key
} catch (InvalidRequestException $e) {
    echo $e->getParam();   // Invalid field
    echo $e->getMessage();
} catch (RateLimitException $e) {
    // Too many requests — retry later
} catch (SanghoException $e) {
    echo $e->getCode();    // Sangho business code
    echo $e->getMessage(); // Human-readable message
    echo $e->getStatus();  // HTTP status code
}

Pagination

php
<?php
$page = Sangho::transactions()->list([
    'status'    => 'completed',
    'page'      => 1,
    'page_size' => 20,
]);
echo $page->count;          // Total results
foreach ($page->data as $tx) {
    echo $tx->id . "\n";
}
// Next page
if ($page->has_more) {
    $page2 = Sangho::transactions()->list([
        'status'    => 'completed',
        'page'      => 2,
        'page_size' => 20,
    ]);
}