PHP code example of mwanziamutua / omnipay-pesapal

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

    

mwanziamutua / omnipay-pesapal example snippets


$gateway = GatewayFactory::createInstance($consumerKey, $consumerSecret, true);

try {
    $orderNo = uniqid('', true);
    $returnUrl = 'http://localhost:80/gateway-return.php';
    $notifyUrl = 'http://127.0.0.1/online-payments/uuid/notify';
    $ipnId = ' b62dbd97-3b95-43d2-8969-df616360f0ab';
    $description = 'Shopping at myAwesomeStore.com';

    $pesapalOrder = [
        'purchaseData' => [
            'id' => $orderNo,
            'amount'            => 150,
            'currency'          => 'KES',
            'description' => $description,
            'callback_url' => $returnUrl,
            'notification_id' => $ipnId,
            'billing_address'  => [
                "email_address" => "[email protected]",
                "phone_number" => null,
                "country_code" => "",
                "first_name" => "John",
                "middle_name" => "",
                "last_name" => "Doe",
                "line_1" => "",
                "line_2" => "",
                "city" => "",
                "state" => "",
                "postal_code" => null,
                "zip_code" => null
            ]
        ],
    ];


    $response = $gateway->purchase($pesapalOrder);