PHP code example of webumer / bcb-php-sdk

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

    

webumer / bcb-php-sdk example snippets


use Webumer\Bcb\BcbClient;
use Webumer\Bcb\BcbEnvironment;

// For UAT/Sandbox environment
$client = BcbClient::forEnvironment(
    environment: BcbEnvironment::UAT,
    clientId: 'your_client_id',
    clientSecret: 'your_client_secret'
);

// For Production environment
$client = BcbClient::forEnvironment(
    environment: BcbEnvironment::PRODUCTION,
    clientId: 'your_client_id',
    clientSecret: 'your_client_secret'
);

use Webumer\Bcb\BcbClient;

$client = new BcbClient(
    baseUrl: 'https://api.bcb.group',
    authUrl: 'https://auth.bcb.group', 
    clientBaseUrl: 'https://client-api.bcb.group',
    clientId: 'your_client_id',
    clientSecret: 'your_client_secret'
);

// List beneficiaries
$beneficiaries = $client->beneficiaries()->list();

// Create virtual IBAN
$viban = $client->viban()->create($accountId, [
    'correlationId' => 'unique-id',
    'name' => 'John Doe',
    'isIndividual' => true,
    // ... other fields
]);

// Initiate payment
$payment = $client->payments()->authorise([
    'counterparty_id' => 'counterparty-id',
    'beneficiary_account_id' => 'beneficiary-id', 
    'ccy' => 'GBP',
    'amount' => '100.00',
    'reference' => 'Invoice 123',
    'preferred_scheme' => 'AUTO'
]);

// Parse webhook events
$webhook = $client->webhooks()->parseVirtualAccountEvent($payload);

// Get virtual account details
$account = $client->viban()->get($accountId, $iban);

// Get virtual account balance
$balance = $client->viban()->getBalance($accountId, $iban);

// Get transaction history
$transactions = $client->viban()->getTransactions($accountId, $iban, [
    'from' => '2024-01-01',
    'to' => '2024-12-31'
]);

// Create beneficiary
$beneficiary = $client->beneficiaries()->create([
    'name' => 'John Doe',
    'account_number' => '12345678',
    'sort_code' => '123456',
    'currency' => 'GBP'
]);

// List payments
$payments = $client->payments()->list(['status' => 'completed']);

// Cancel payment
$result = $client->payments()->cancel($paymentId);

// UAT Environment
$uatClient = BcbClient::forEnvironment(
    environment: BcbEnvironment::UAT,
    clientId: 'your_uat_client_id',
    clientSecret: 'your_uat_client_secret'
);

// Production Environment
$prodClient = BcbClient::forEnvironment(
    environment: BcbEnvironment::PRODUCTION,
    clientId: 'your_prod_client_id',
    clientSecret: 'your_prod_client_secret'
);
bash
composer