chitanga / pesepay
Seamless Pesepay integration package
Fund package maintenance!
:vendor_name
Requires
- php: ^8.0
- codevirtus/pesepay: ^1.0
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- spatie/laravel-ray: ^1.35
Suggests
- guzzlehttp/guzzle: Required for HTTP requests
- laravel/framework: Required to use with Laravel
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.