PHP code example of camoo / payment-api

1. Go to this page and download the library: Download camoo/payment-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

camoo / payment-api example snippets




amoo\Payment\Http\Client as PaymentClient;

// Your credentials
$apiKey = 'YOUR_API_KEY';
$apiSecret = 'YOUR_API_SECRET';

$client = new PaymentClient(
    apiKey: $apiKey,
    apiSecret: $apiSecret,
    httpClient: null,  // optionally pass a custom ClientInterface
    debug: false,      // set to true for verbose logging
    apiVersion: 'v1'
);

use Camoo\Payment\Api\AccountApi;

$accountApi = new AccountApi($client);

try {
    $accountInfo = $accountApi->get();
    // $accountInfo is an instance of \Camoo\Payment\Models\Account

    echo "Balance: " . $accountInfo->balance->amount . " " . $accountInfo->balance->currency->value . PHP_EOL;
    echo "Viewed At: " . $accountInfo->viewedAt->format('Y-m-d H:i:s') . PHP_EOL;
} catch (\Camoo\Payment\Exception\ApiException $e) {
    // Handle error
    echo "Error fetching account: " . $e->getMessage();
}

use Camoo\Payment\Api\PaymentApi;

$paymentApi = new PaymentApi($client);

// 1) Cash Out (example usage)
try {
    $response = $paymentApi->cashout([
        'phone_number' => '+237612345678',
        'amount'      => 5000,
        'notification_url'    => 'https://example.com/notify-me',
    ]);

    // $response is an instance of \Camoo\Payment\Models\Payment
    echo "Cashout ID: " . $response->id . PHP_EOL;
    echo "Status: " . $response->status . PHP_EOL;
} catch (\Camoo\Payment\Exception\ApiException $e) {
    // Handle error
    echo "Cashout error: " . $e->getMessage();
}

// 2) Verify a payment (example usage)
try {
    $paymentId = '12345';
    $verifiedPayment = $paymentApi->verify($paymentId);

    echo "Payment " . $verifiedPayment->id . " status: " . $verifiedPayment->status . PHP_EOL;
} catch (\Camoo\Payment\Exception\ApiException $e) {
    // Handle error
    echo "Verification error: " . $e->getMessage();
}

try {
    // Some Payment API call
} catch (\Camoo\Payment\Exception\ApiException $e) {
    echo 'API Error (code ' . $e->getCode() . '): ' . $e->getMessage();
}