Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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