PHP code example of nyanumba-codes / pesapal

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

    

nyanumba-codes / pesapal example snippets


use NyanumbaCodes\Pesapal\Pesapal;

$pesapal = new Pesapal();
$ipnId = $pesapal->registerIpnUrl();

use NyanumbaCodes\Pesapal\Pesapal;

$pesapal = new Pesapal();
$ipnId = $pesapal->getIpnList();

$amount = 100;
$description = 'Order No. 1234';
$notification_id = '123xxx-xxxxxxxx-xxx....'
$billing_address = [
    "email_address" => auth()->user()->email,
    "phone_number" => "",
    "country_code" => "KE",
    "first_name" => "",
    "middle_name" => "",
    "last_name" => "",
    "line_1" => "",
    "line_2" => "",
    "city" => "",
    "state" => "",
    "postal_code" => "",
    "zip_code" => ""
];

$response = $pesapal->submitOrderRequest($amount, $description, $billing_address, $notification_id);
return redirect()->away($response['redirect_url']);

Route::post('pesapal/callback', [PaymentController::class, 'handleCallback'])->name('pesapal.callback');

public function handleCallback(Request $request)
{
    // Process callback data
    /**
     * Maybe you have saved the data into the Database
     */
}

use NyanumbaCodes\Pesapal\Pesapal;


$pesapal = new Pesapal();
$response = $pesapal->getTransactionStatus($orderTrackingId);



$subscription_details = [
    'start_date'=>'dd-mm-yyyy',
    'end_date'=>'dd-mm-yyyy',
    'frequency'=>'DAILY', 
];

use NyanumbaCodes\Pesapal\Pesapal;


$pesapal = new Pesapal();

$response = $pesapal->refundRequest($confirmation_code, $amount, $username, $remarks);


use NyanumbaCodes\Pesapal\Pesapal;


$pesapal = new Pesapal();

$response = $pesapal->orderCancellation($trackingId);

bash
php artisan vendor:publish --tag="pesapal-config"

bash
php artisan make:controller PaymentController