xahmedtaha / paybridge
A versatile laravel package providing a consistent and easy-to-use interface for integrating with multiple payment gateways.
Fund package maintenance!
Ahmed Taha
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/pint: ^1.14
- mockery/mockery: ^1.6
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- spatie/invade: ^2.1
README
A versatile laravel package providing a consistent and easy-to-use interface for integrating with multiple payment gateways.
Installation
You can install the package via composer:
composer require xahmedtaha/paybridge
You can publish the config file with:
php artisan vendor:publish --tag="paybridge-config"
Usage
You should typically use the package as follows:
use AhmedTaha\PayBridge\Data\ChargeData; use AhmedTaha\PayBridge\Data\CustomerData; use AhmedTaha\PayBridge\Data\Payment\CreditCardData; use AhmedTaha\PayBridge\Enums\PaymentEnvironment; use AhmedTaha\PayBridge\Enums\PaymentGateway; $charge = new ChargeData('charge ID', 200, 'USD'); $customer = new CustomerData('customer ID', 'Ahmed', 'phone', 'email@test.com'); $paymentData = new CreditCardData('1234 1234 1234 1234', '24', '05', '123'); $result = PayBridge::setEnvironment(PaymentEnvironment::TESTING) ->gateway(PaymentGateway::FawryPay) ->pay($charge, $customer, $paymentData); // $result = [ // 'success' => true, // 'status' => PaymentStatus::PENDING, // 'shouldRedirect' => true, // 'redirectUrl' => 'fawry gateway url...', //];
A callback url should be defined in the config files. Here is how the code for this route should typically be:
use PayBridge; use AhmedTaha\PayBridge\Enums\PaymentGateway; use AhmedTaha\PayBridge\Enums\PaymentEnvironment; use Illuminate\Http\Request; public function callbackRouteHandler(Request $request) { $result = PayBridge::setEnvironment(PaymentEnvironment::TESTING) ->gateway(PaymentGateway::FawryPay) ->callback($request); // Your additional app logic... } // $result = [ // 'success' => true, // 'status' => PaymentStatus::PAID, // 'charge' => ChargeData object, // 'customer' => CustomerData object, // 'referenceNumber' => 'fawry ref no', //];
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.