PHP code example of bazzly / payoffice

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

    

bazzly / payoffice example snippets


use Bazzly\Payoffice\PingServer;

// PingServer(string $name, string $url, ?int $preferredPingMs = null)
$check = new PingServer('paystack', 'api.paystack.co', 100);

$result = $check->getUrlServerDetails();

// $result = [
//     'name'        => 'paystack',
//     'apiurl'      => 'api.paystack.co',
//     'serverStatus'=> 'up',     // PingServer::UPSTATUS / PingServer::DOWNSTATUS
//     'serverPing'  => 42,       // measured latency in ms
//     'userPing'    => 100,      // your preferred/acceptable threshold (defaults to 10)
// ];

if ($result['serverStatus'] === PingServer::UPSTATUS && $result['serverPing'] <= $result['userPing']) {
    // safe to redirect the customer to this provider
} else {
    // provider is down or too slow — fall back to another provider
}

use Bazzly\Payoffice\PingServer;

$providers = config('payoffice');

$statuses = collect($providers)->map(function ($provider) {
    $ping = new PingServer($provider['name'], $provider['APIURL']);
    return $ping->getUrlServerDetails();
});

use Bazzly\Payoffice\Models\PingsMonitoring;
use Bazzly\Payoffice\PingServer;

$result = (new PingServer('paystack', 'api.paystack.co', 100))->getUrlServerDetails();

PingsMonitoring::create([
    'name'         => $result['name'],
    'apiurl'       => $result['apiurl'],
    'serverStatus' => $result['serverStatus'],
    'serverPing'   => $result['serverPing'],
    'userPing'     => $result['userPing'],
]);

use Bazzly\Payoffice\Paystack\GetPaid;

$paystack = new GetPaid();

// Initialize a transaction and redirect the customer to Paystack
public function pay(GetPaid $paystack)
{
    return $paystack->getAuthorizationUrl()->redirectNow();
}

// Or supply the payload explicitly instead of relying on request() input
$paystack->getAuthorizationUrl([
    'amount'    => 500000, // kobo
    'email'     => '[email protected]',
    'reference' => $paystack->genTranxRef(),
]);

// Verify a transaction after the customer returns from Paystack
public function callback(GetPaid $paystack)
{
    if ($paystack->isTransactionVerificationValid()) {
        $payment = $paystack->getPaymentData();
        // mark the order as paid
    }
}

use Bazzly\Payoffice\Paystack\Transfer;

$transfer = new Transfer();

// List supported banks
$banks = $transfer->getBanks('nigeria');

// Confirm an account number belongs to the expected owner
$account = $transfer->confirmAccount('0123456789', '058');

// Send money to a bank account
$transfer->sendMonyToAccDetails(
    accName: 'Jane Doe',
    accNumber: '0123456789',
    bankName: 'Guaranty Trust Bank',
    metadata: [
        'bankCode' => '058',
        'source'   => 'balance',
        'amount'   => 500000, // kobo
        'reference'=> $transfer->getBanks() ? uniqid('trf_') : null,
        'reason'   => 'Vendor payout',
    ]
);

// Check your Paystack balance
$balance = $transfer->getBalance();

// Verify a transfer by its reference
$status = $transfer->getVerifyTransfer('trf_abc123');

use Bazzly\Payoffice\TransRef;

$reference = TransRef::getHashedToken(); // 25-char alphanumeric token by default
$reference = TransRef::getHashedToken(12); // custom length

use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;

$mock = new MockHandler([
    new Response(200, [], json_encode(['status' => true, 'data' => [/* ... */]])),
]);

$paystack = new GetPaid(HandlerStack::create($mock));
bash
php artisan vendor:publish --provider="Bazzly\Payoffice\PaymentServiceProvider" --tag="config"
php artisan vendor:publish --provider="Bazzly\Payoffice\PaymentServiceProvider" --tag="pings_monitoring"
php artisan migrate
bash
composer install
php examples/demo.php