PHP code example of sykez / betterpay

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

    

sykez / betterpay example snippets


use Sykez\Betterpay\Betterpay;

$bp = new Betterpay($api_key, $merchant_id, $api_url, $callback_url, $success_url, $fail_url);
$response = $bp->createTokenizationUrl($reference_id); // unique $reference_id
header('Location: '.$response['credit_card_verification_url']); // redirect to payment gateway

$token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // token returned from verification
$bp->charge($token, $invoice, $amount);

use Sykez\Betterpay\Betterpay;

public function charge(Betterpay $bp, Request $request)
{
    $invoice = bin2hex(random_bytes(5));
    $token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $amount = 10.5;
    return $bp->charge($token, $invoice, $amount);
}