salamzadeh / pb-payment
a Laravel package to handle Internet Payment Gateways for Iran Banking System
Requires
- php: ^7.4|^8.0|^9.0
- ext-curl: *
- ext-json: *
- ext-soap: *
- doctrine/dbal: ^2.10
- illuminate/database: ~5.7|~6.0|~7.0|~8.0
- illuminate/http: ~5.7|~6.0|~7.0|~8.0
- illuminate/support: ~5.7|~6.0|~7.0|~8.0
- nesbot/carbon: *
Requires (Dev)
- fzaninotto/faker: ^1.4
- orchestra/testbench: ^5.0
- phpstan/phpstan: ^0.12.0@dev
- phpunit/phpunit: ^9.1
This package is auto-updated.
Last update: 2024-11-30 01:47:15 UTC
README
Payment Gateways for Laravel
a Laravel package to handle Internet Payment Gateways (IPGs) for Iran Banking System
Accepting Sadad (Melli), Pay.ir, Zarinpal and more iranian payment gateways. Just use the PBPayment to receive payments directly on your website.
Gateways
Requirements
Installation
-
Add the package to your composer file via the
composer require
command:$ composer require salamzadeh/pb-payment:^1.2.0
Or add it to
composer.json
manually:"require": { "salamzadeh/pb-payment": "^1.2.0" }
-
PBPayment's service providers will be automatically registered using Laravel's auto-discovery feature.
Note: For Lumen you have to add the PBPayment service provider manually to:
bootstrap/app.php
:$app->register( Salamzadeh\PBPayment\PBPaymentServiceProvider::class);
-
Publish the config-file and migration with:
php artisan vendor:publish --provider="Salamzadeh\PBPayment\PBPaymentServiceProvider"
-
After the migration has been published you can create the transactions-tables by running the migrations:
php artisan migrate
Usage
New Payment:
use Salamzadeh\PBPayment\PBPayment; // Default gateway $payment = PBPayment::create(); // Select one of available gateways $payment = PBPayment::create('sadad'); // Test gateway (Would not work on production environment) $payment = PBPayment::create('test'); // Or use your own gateway $payment = PBPayment::create(NewGateway::class); $payment->setUserId($user->id) ->setAmount($data['amount']) ->setCallbackUrl(route('bank.callback')) ->ready(); return $payment->redirect();
Verify Payment:
use Salamzadeh\PBPayment\PBPayment; use Salamzadeh\PBPayment\Exceptions\PBPaymentException; try { $payment = PBPayment::detect()->confirm(); $trackingCode = $payment->getTrackingCode(); $statusText = $payment->getTransactionStatusText(); } catch (Salamzadeh\PBPayment\Exceptions\PBPaymentException $ex) { throw $ex; }
Create your own payment gateway class
use Salamzadeh\PBPayment\Gateways\AbstractGateway; use Salamzadeh\PBPayment\Gateways\GatewayInterface; class NewGateway extends AbstractGateway implements GatewayInterface { public function getName(): string { return 'new-gateway'; } public function initialize(array $parameters = []): self { parent::initialize($parameters); return $this; } public function purchase(): void { // Send Purchase Request $reference_number = 'xxxx'; $this->transactionUpdate([ 'reference_number' => $reference_number, ]); } public function purchaseUri(): string { return 'http://new-gateway.com/token/xxxx'; } public function verify(): void { $this->transactionVerifyPending(); // Send Payment Verify Request $tracking_code = 'yyyy'; $this->transactionSucceed([ 'tracking_code' => $tracking_code ]); } }
Upgrading from v1.x
TODO:
Contribute
Contributions are always welcome!
Support
If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.
License
The MIT License (MIT). Please see License File for more information.