PHP SDK (watenga-php)

The official PHP library for the Watenga API. Works with Laravel, Symfony, WordPress, and plain PHP.

Installation

bash
composer require watenga/watenga-php

Requires PHP 7.4 or higher with ext-json and ext-curl (standard in all hosting environments).

Initialisation

php
use Watenga\Watenga;

$watenga = new Watenga('sk_test_YOUR_KEY');

// Optional config:
$watenga = new Watenga('sk_test_YOUR_KEY', [
    'baseUrl' => 'https://api.watenga.africa',
    'timeout' => 30,
]);

Available resources

Each resource mirrors the Node SDK: checkout, transactions, paymentLinks, payouts, and account.

php
// Create a checkout session
$checkout = $watenga->checkout->create([
    'amount' => 25.00,
    'currency' => 'USD',
    'merchantTransactionId' => 'ORD-1001',
    'returnUrl' => 'https://yoursite.com/thank-you',
    'notificationUrl' => 'https://yoursite.com/webhooks/watenga',
]);

// List and retrieve transactions
$transactions = $watenga->transactions->list(['limit' => 20]);
$txn = $watenga->transactions->retrieve('txn_...');

// Refund (full or partial)
$watenga->transactions->refund('txn_...', ['amount' => 10.00, 'reason' => 'customer request']);

// Payment links
$link = $watenga->paymentLinks->create(['title' => 'Donation', 'amount' => 5.00, 'currency' => 'USD']);

// Request a payout
$watenga->payouts->request(['amount' => 100.00, 'currency' => 'USD', 'method' => 'bank_transfer']);

// Account balance
$balance = $watenga->account->balance();

Error handling

php
use Watenga\WatengaException;

try {
    $checkout = $watenga->checkout->create([/* ... */]);
} catch (WatengaException $e) {
    echo $e->getMessage();   // human-readable
    echo $e->code;           // machine-readable: 'KYC_REQUIRED' etc
    echo $e->statusCode;     // HTTP status
}

Every failure throws a WatengaException exposing getMessage(), a machine-readable code, and the HTTP statusCode (see the Errors reference).

Laravel

Using Laravel?

See the Laravel Integration Guide for service provider setup, config binding, and controller examples.

Webhook verification

Read the raw request body and verify the signature before processing. Respond 200 only after successful verification.

php
$rawBody = file_get_contents('php://input');
$signature = $_SERVER['HTTP_WATENGA_SIGNATURE'] ?? '';

try {
    $event = Watenga::constructEvent(
        $rawBody,
        $signature,
        getenv('WATENGA_WEBHOOK_SECRET')
    );
    // $event['type'] === 'payment.capture.completed'
    // $event['data'] holds the transaction object
} catch (\Exception $e) {
    http_response_code(400);
    exit;
}

http_response_code(200);
echo json_encode(['received' => true]);

Package

Published on Packagist. The SDK version is independent of the API version.