Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saeeddev94/zarinpal-laravel
Zarinpal payment for Laravel Framework
https://github.com/saeeddev94/zarinpal-laravel
framework laravel payment zarinpal
Last synced: about 2 months ago
JSON representation
Zarinpal payment for Laravel Framework
- Host: GitHub
- URL: https://github.com/saeeddev94/zarinpal-laravel
- Owner: SaeedDev94
- License: mit
- Created: 2017-08-10T05:47:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-23T16:14:52.000Z (over 1 year ago)
- Last Synced: 2024-11-18T09:56:53.411Z (about 2 months ago)
- Topics: framework, laravel, payment, zarinpal
- Language: PHP
- Homepage:
- Size: 104 KB
- Stars: 46
- Watchers: 3
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# **Zarinpal payment for Laravel Framework**
- [Use this lib with other frameworks](#use-this-lib-with-other-frameworks)
- [Available configs](#available-configs)install it:
```shell
composer require saeedpooyanfar/zarinpal
```laravel service provider should register automatically, if not, register `Zarinpal\ZarinpalServiceProvider::class` manually or run:
```shell
composer dump-autoload
```set 36 chars "ZARINPAL_MERCHANTID" in `.env` file:
```
...
ZARINPAL_MERCHANTID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
...
```# **Use it**
**request new payment:**
```php
route('payment.verify'), // Required
'amount' => 5000, // Required
'description' => 'a short description', // Required
'metadata' => [
'mobile' => '0933xxx7694', // Optional
'email' => '[email protected]' // Optional
]
];
try {
$response = $zarinpal->request($payment);
$code = $response['data']['code'];
$message = $zarinpal->getCodeMessage($code);
if($code === 100) {
$authority = $response['data']['authority'];
return $zarinpal->redirect($authority);
}
return "Error, Code: ${code}, Message: ${message}";
} catch (RequestException $exception) {
// handle exception
}
}
...
```If you have other redirection methods you can use:
```php
...
$url = $zarinpal->getRedirectUrl($authority);
...
```to get the redirect url as a string.
**verify the payment:**
```php
$request->input('Authority'), // $_GET['Authority']
'amount' => 5000
];
if ($request->input('Status') !== 'OK') abort(406);
try {
$response = $zarinpal->verify($payment);
$code = $response['data']['code'];
$message = $zarinpal->getCodeMessage($code);
if($code === 100) {
$refId = $response['data']['ref_id'];
return "Payment was successful, RefID: ${refId}, Message: ${message}";
}
return "Error, Code: ${code}, Message: ${message}";
} catch (RequestException $exception) {
// handle exception
}
}
...
```# **Use this lib with other frameworks**
```php