https://github.com/rtler/zarinpal-composer-library
transaction request library for zarinpal
https://github.com/rtler/zarinpal-composer-library
composer laravel php zarinpal
Last synced: 15 days ago
JSON representation
transaction request library for zarinpal
- Host: GitHub
- URL: https://github.com/rtler/zarinpal-composer-library
- Owner: RTLer
- License: gpl-2.0
- Created: 2015-06-23T18:30:26.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2021-11-28T14:17:31.000Z (over 3 years ago)
- Last Synced: 2025-04-09T20:12:20.444Z (15 days ago)
- Topics: composer, laravel, php, zarinpal
- Language: PHP
- Size: 240 KB
- Stars: 54
- Watchers: 2
- Forks: 44
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# zarinpal-composer-library
[](https://travis-ci.org/RTLer/zarinpal-composer-library)
[](https://styleci.io/repos/37937280)
[](https://coveralls.io/github/RTLer/zarinpal-composer-library?branch=master)transaction request library for zarinpal
## usage
### installation
``composer require zarinpal/zarinpal``### request
```php
use Zarinpal\Zarinpal;$zarinpal = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
$zarinpal->enableSandbox(); // active sandbox mod for test env
// $zarinpal->isZarinGate(); // active zarinGate mode
$results = $zarinpal->request(
"example.com/testVerify.php", //required
1000, //required
'testing', //required
'[email protected]', //optional
'09000000000', //optional
[ //optional
"Wages" => [
"zp.1.1"'=> [
"Amount"'=> 120,
"Description"'=> "part 1"
],
"zp.2.5"'=> [
"Amount"'=> 60,
"Description"'=> "part 2"
]
]
]
);
echo json_encode($results);
if (isset($results['Authority'])) {
file_put_contents('Authority', $results['Authority']);
$zarinpal->redirect();
}
//it will redirect to zarinpal to do the transaction or fail and just echo the errors.
//$results['Authority'] must save somewhere to do the verification
```### verify
```php
use Zarinpal\Zarinpal;$zarinpal = new Zarinpal('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');
$authority = file_get_contents('Authority');
echo json_encode($zarinpal->verify('OK', 1000, $authority));
//'Status'(index) going to be 'success', 'error' or 'canceled'
```## laravel ready
this package is going to work with all kinds of projects, but for laravel i add provider to make it as easy as possible.
just add **(if you are using laravel 5.5 or higher skip this one)**:
```php
'providers' => [
...
Zarinpal\Laravel\ZarinpalServiceProvider::class
...
]
```
to providers list in "config/app.php". then add this to `config/services.php`
```php
'zarinpal' => [
'merchantID' => 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
'zarinGate' => false,
'sandbox' => false,
],
```
and you are good to go (legacy config still works)
now you can access the zarinpal lib like this:
```php
use Zarinpal\Laravel\Facade\Zarinpal;$results = Zarinpal::request(
"example.com/testVerify.php", //required
1000, //required
'testing', //required
'[email protected]', //optional
'09000000000', //optional
[ //optional
"Wages" => [
"zp.1.1" => [
"Amount" => 120,
"Description" => "part 1"
],
"zp.2.5" => [
"Amount" => 60,
"Description" => "part 2"
]
]
]
);
// save $results['Authority'] for verifying step
Zarinpal::redirect(); // redirect user to zarinpal// after that verify transaction by that $results['Authority']
Zarinpal::verify('OK',1000,$results['Authority']);
```