PHP code example of chitanga / pesepay

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

    

chitanga / pesepay example snippets


return [
    /*
    |--------------------------------------------------------------------------
    | API Credentials
    |--------------------------------------------------------------------------
    */
    'integration_key' => env('PESEPAY_INTEGRATION_KEY'),
    'encryption_key' => env('PESEPAY_ENCRYPTION_KEY'),

    /*
    |--------------------------------------------------------------------------
    | Payment URLs
    |--------------------------------------------------------------------------
    */
    'return_url' => env('PESEPAY_RETURN_URL'),
    'result_url' => env('PESEPAY_RESULT_URL'),

    /*
    |--------------------------------------------------------------------------
    | Default Settings
    |--------------------------------------------------------------------------
    */
    'default_currency' => 'USD',
    'brand_name' => env('PESEPAY_BRAND_NAME', env('APP_NAME', 'Laravel')),

];

use Chitanga\Pesepay\PesepayService;

$pesepay = new PesepayService(
    config('pesepay.integration_key'),
    config('pesepay.encryption_key'),
    config('pesepay.return_url'),
    config('pesepay.result_url')
);

try {
    $payment = $pesepay->ecocash([
        'amount'        => 10.50,
        'phone'         => '263771234567',
        'email'         => '[email protected]',
        'reference'     => 'PZW211',                // Dont change the reference code 
        'description'   => 'Product purchase'
    ]);
    
    // Store $payment['reference_number'] and $payment['poll_url'] in your database
} catch (\Chitanga\Pesepay\Exceptions\PesepayException $e) {
    // Handle payment error
}

try {
    $payment = $pesepay->card([
        'amount'        => 25.00,
        'email'         => '[email protected]',
        'card_number'   => '4111111111111111',
        'card_expiry'   => '12/25',
        'card_cvv'      => '123',
        'reference'     => 'PWZ204'                 // Dont change the reference code 
    ]);
    
    // Process payment response
} catch (\Chitanga\Pesepay\Exceptions\PesepayException $e) {
    // Handle payment error
}

// Using the poll_url from the payment response
$status = $pesepay->checkPaymentStatus($pollUrl);

if ($status['success']) {
    // Payment was successful
} else {
    // Payment failed or is pending
}

// Quick check
if ($pesepay->isPaymentSuccessful($pollUrl)) {
    // Payment successful
}
bash
php artisan vendor:publish --tag="pesepay-config"