PHP code example of blessdarah / php-campay

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

    

blessdarah / php-campay example snippets


use BlessDarah\PhpCampay\Campay;

$campay = new Campay();

$data = array(
    "amount" => 3,
    "currency" => "XAF",
    "from" => "237******",
    "description" => "test payment"
);
$res = $campay->collect($data);
// handle your response data from here
echo $res;

use BlessDarah\PhpCampay\Campay;

$campay = new Campay();

$data = array(
    "amount" => 3,
    "currency" => "XAF",
    "to" => "237******",
    "description" => "test payment"
);
$res = $campay->withdraw($data);
echo $res;


use BlessDarah\PhpCampay\Campay;

$campay = new Campay();

/*
* Suppose you have carried out a collection request from user then you can
* collection logic here
* /
$ref = $res->reference; // e.g: b1d44bc7-648d-451b-a3ef-c5807738ec82

$transaction_feedback = $campay->getTransactionStatus($ref) /* your reference code */

if($transaction_feedback->status == 'SUCCESSFUL')
{
    /* success logic here */
}

if($transaction_feedback->status == 'PENDING')
{
    /* Pending logic here */
}

if($transaction_feedback->status == 'FAILED')
{
    /* Erro logic here */
}

use BlessDarah\PhpCampay\Campay;

$campay = new Campay();
$res = $campay->getAppBalance();

// handle your response data from here
echo $res;

use BlessDarah\PhpCampay\Campay;

$campay = new Campay();
$res = $campay->transactionHistory();

// handle your response data from here
echo $res;

$start_date = new Date("2022-06-13");
$end_date = new Date("2022-08-13");

$res = $campay->transactionHistory($start_date, $end_date);

use BlessDarah\PhpCampay\Campay;

$campay = new Campay();

$params = [
    "amount" => 4,
    "currency" => "XAF",
    "description" => "Sample description",
    "first_name" =>  "John",
    "last_name" =>  "Doe",
    "email" => "[email protected]",
    "external_reference" =>  "",
    "redirect_url" =>  "https://example.com",
    "failure_redirect_url" => "https://example.com",
    "payment_options" => "MOMO" // or CARD for credit card payments
];
$res = $campay->generatePaymentUrl($params);

// handle your response data from here
echo $res;
bash
composer