PHP code example of bobospay / bobospay-php

1. Go to this page and download the library: Download bobospay/bobospay-php 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/ */

    

bobospay / bobospay-php example snippets




// 1. Load Guzzle (adjust the path to match your setup)
-php/autoload.php';

use Bobospay\BobospayClient;
use Bobospay\DTOs\CreateTransactionDTO;
use Bobospay\Exceptions\ApiException;

$bobospay = new BobospayClient('ci_live_your_client_id', 'your_client_secret');

try {
    $response = $bobospay->transactions()->create(new CreateTransactionDTO(
        amount: 1500.00,
        currency: 'NGN',
        callbackUrl: 'https://yoursite.com/payment/callback',
        note: 'Order #1234',
    ));

    $token = $bobospay->transactions()->generateToken($response['data']['id']);
    header('Location: ' . $token['data']['url']);
    exit;
} catch (ApiException $e) {
    echo 'Payment error: ' . $e->getMessage();
}

use Bobospay\BobospayClient;
use Bobospay\DTOs\CreateTransactionDTO;

$bobospay = new BobospayClient(
    'ci_live_your_client_id',
    'your_client_secret',
);

// Create a transaction
$response = $bobospay->transactions()->create(new CreateTransactionDTO(
    amount: 1500.00,
    currency: 'NGN',
    callbackUrl: 'https://yoursite.com/payment/callback',
    note: 'Order #1234',
));

$transactionId = $response['data']['id'];

// Generate a checkout URL
$token = $bobospay->transactions()->generateToken($transactionId);
$checkoutUrl = $token['data']['url'];

// Redirect the customer to $checkoutUrl

// Sandbox -- automatically hits sandbox.bobospay.com
$bobospay = new BobospayClient('ci_test_abc123', 'your_test_secret');

// Production -- automatically hits bobospay.com
$bobospay = new BobospayClient('ci_live_abc123', 'your_live_secret');

$bobospay = new BobospayClient('ci_live_abc123', 'secret', [
    'timeout'    => 60,    // Request timeout in seconds (default: 30)
    'verify_ssl' => false, // Disable SSL verification (default: true)
]);

// Merchant profile
$profile = $bobospay->account()->get();
echo $profile['data']['business_name'];

// Wallet balances
$balances = $bobospay->account()->balances();

// Active currencies for this app
$currencies = $bobospay->account()->currencies();

// Enabled payment methods
$methods = $bobospay->account()->paymentMethods();

use Bobospay\DTOs\CreateTransactionDTO;

// List transactions (paginated)
$list = $bobospay->transactions()->list(page: 1, perPage: 25);

// Create a transaction
$response = $bobospay->transactions()->create(new CreateTransactionDTO(
    amount: 2000.00,
    currency: 'XOF',
    callbackUrl: 'https://yoursite.com/callback',
    note: 'Invoice #5678',
    channels: ['mobile_money', 'card'],
    mobileChannels: ['mtn', 'moov'],
    customer: [
        'firstname' => 'Jane',
        'lastname'  => 'Doe',
        'email'     => '[email protected]',
    ],
    customData: ['invoice_id' => '5678'],
));

// Create with an idempotency key (prevents duplicate transactions on retries)
$response = $bobospay->transactions()->create($dto, idempotencyKey: 'unique-key-123');

// Retrieve a transaction
$tx = $bobospay->transactions()->find(124);
echo $tx['data']['status']; // "Pending", "Successful", etc.

// Generate a checkout token and URL
$token = $bobospay->transactions()->generateToken(124);
$checkoutUrl = $token['data']['url'];

use Bobospay\DTOs\CreateCustomerDTO;

// List customers (paginated)
$list = $bobospay->customers()->list(page: 1, perPage: 15);

// Create or update a customer (upsert by email)
$customer = $bobospay->customers()->create(new CreateCustomerDTO(
    firstname: 'Jane',
    lastname: 'Doe',
    email: '[email protected]',
    phone: '08012345678',
));

// Retrieve a customer
$customer = $bobospay->customers()->find(12);

// List all active currencies
$currencies = $bobospay->currencies()->list();
// $currencies['data'] => ["NGN", "GHS", "USD", ...]

use Bobospay\Webhook\WebhookValidator;

$validator = new WebhookValidator('your_client_secret');

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

// Option 1: boolean check
if ($validator->isValid($payload, $signature)) {
    $data = json_decode($payload, true);
    // process the webhook...
}

// Option 2: validate and decode in one step (throws on invalid signature)
try {
    $data = $validator->validate($payload, $signature);
    // process $data...
} catch (\Bobospay\Exceptions\BobospayException $e) {
    http_response_code(400);
    echo 'Invalid signature';
}

use Bobospay\Exceptions\AuthenticationException;
use Bobospay\Exceptions\ValidationException;
use Bobospay\Exceptions\NotFoundException;
use Bobospay\Exceptions\NotAcceptableException;
use Bobospay\Exceptions\ApiException;

try {
    $tx = $bobospay->transactions()->find(99999);
} catch (AuthenticationException $e) {
    // 401 -- Invalid credentials
} catch (NotFoundException $e) {
    // 404 -- Resource not found
} catch (ValidationException $e) {
    // 422 -- Validation failed
    $fieldErrors = $e->getErrors();
    // ['amount' => ['The amount field is 

use Bobospay\BobospayClient;
use Bobospay\DTOs\CreateTransactionDTO;

class PaymentController extends Controller
{
    public function __construct(private BobospayClient $bobospay) {}

    public function pay(Request $request)
    {
        $response = $this->bobospay->transactions()->create(new CreateTransactionDTO(
            amount: $request->input('amount'),
            currency: 'NGN',
            callbackUrl: route('payment.callback'),
        ));

        $token = $this->bobospay->transactions()->generateToken($response['data']['id']);

        return redirect($token['data']['url']);
    }
}

use Bobospay\Integrations\Laravel\BobospayFacade as Bobospay;

$profile = Bobospay::account()->get();
$tx = Bobospay::transactions()->create($dto);

use Bobospay\BobospayClient;

// Create a client with a custom/mock HTTP implementation
$client = BobospayClient::withHttpClient($mockHttpClient);
bash
composer 

your-project/
    guzzlehttp/          <-- guzzle and its dependencies
    bobospay-php/        <-- this SDK
        autoload.php
        src/
    index.php
bash
php artisan vendor:publish --tag=bobospay-config