PHP code example of openpesa / pesa

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

    

openpesa / pesa example snippets




use Openpesa\SDK\Pesa;

// Intiate with credentials
$pesa = new Pesa([
            'api_key' => 'YOUR_API_KEY',
            'public_key' => 'PUBLIC_KEY',
            'client_options' => [],
        ],'sandbox');

// Setup the transaction
$data = [
    'input_Amount' => '10000',
    'input_Country' => 'TZN',
    'input_Currency' => 'TZS',
    'input_CustomerMSISDN' => '255766303775',
    'input_ServiceProviderCode' => '000000',
    'input_ThirdPartyConversationID' => 'rerekf',
    'input_TransactionReference' => rand(),
    'input_PurchasedItemsDesc' => 'Test Two Item'
];

// Execute
$result = $pesa->c2b($data);

// Print results
var_dump($result);