chitanga/pesepay

Seamless Pesepay integration package

v1.0.0 2025-04-10 22:08 UTC

This package is auto-updated.

Last update: 2025-04-10 22:54:59 UTC


README

Pesepay Payment Gateway for Laravel Latest Version on Packagist GitHub Tests Action Status Total Downloads

A comprehensive Laravel package for integrating Pesepay payment gateway into your application. This package provides seamless Ecocash and card payment processing with robust error handling and status checking.

Features

Ecocash payments integration

Card payments processing

Payment status verification

Comprehensive exception handling

Configurable through environment variables

Installation

You can install the package via composer:

composer require chitanga/pesepay

You can publish with:

php artisan vendor:publish --tag="pesepay-config"

You can publish the config file with:

php artisan vendor:publish --tag=":package_slug-config"

This is the contents of the published config file:

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')),

];

Configuration Add these environment variables to your .env file:

PESEPAY_INTEGRATION_KEY=your_integration_key
PESEPAY_ENCRYPTION_KEY=your_encryption_key
PESEPAY_RETURN_URL=https://your-app.com/return
PESEPAY_RESULT_URL=https://your-app.com/webhook
PESEPAY_BRAND_NAME="Your Business Name"

Usage

use Chitanga\Pesepay\PesepayService;

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

Ecocash Payment

try {
    $payment = $pesepay->ecocash([
        'amount'        => 10.50,
        'phone'         => '263771234567',
        'email'         => 'customer@example.com',
        '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
}

Card Payment

try {
    $payment = $pesepay->card([
        'amount'        => 25.00,
        'email'         => 'customer@example.com',
        '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
}

Check Payment Status

// 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
}

Error Handling

The package throws PesepayException for all payment-related errors. You can catch and handle these exceptions:

try {
    // Payment operations
} catch (\Chitanga\Pesepay\Exceptions\PesepayException $e) {
    // Get error details
    $errorMessage = $e->getMessage();
    $errorCode = $e->getCode();
    $errorData = $e->getData();
    
    // Handle error appropriately
}

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.