PHPackages                             llabbasmkhll/laravel-zibal - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. llabbasmkhll/laravel-zibal

ActiveLibrary[Payment Processing](/categories/payments)

llabbasmkhll/laravel-zibal
==========================

transaction request library for zibal

v1.0.0(4y ago)461MITPHPPHP ^7.1.3|8.0.\*

Since Sep 2Pushed 4y ago1 watchersCompare

[ Source](https://github.com/abbasudo/laravel-zibal)[ Packagist](https://packagist.org/packages/llabbasmkhll/laravel-zibal)[ RSS](/packages/llabbasmkhll-laravel-zibal/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (2)Versions (5)Used By (0)

 [ ![Logo](https://camo.githubusercontent.com/add54281c9fb74f167b2c1f1e13468346d6ef8885dc90eb7036e09b579462947/68747470733a2f2f6c61726176656c2e636f6d2f696d672f6c6f676f6d61726b2e6d696e2e737667) ](https://laravel.com) [![](https://camo.githubusercontent.com/b1f4748958534554893c67db37e89b58f7e7ae2fe2667081055a177aec451d85/68747470733a2f2f696d672e69636f6e73382e636f6d2f6d6174657269616c2d6f75746c696e65642f39362f3030303030302f706c75732d6d6174682d2d76312e706e67)](https://camo.githubusercontent.com/b1f4748958534554893c67db37e89b58f7e7ae2fe2667081055a177aec451d85/68747470733a2f2f696d672e69636f6e73382e636f6d2f6d6174657269616c2d6f75746c696e65642f39362f3030303030302f706c75732d6d6174682d2d76312e706e67) [ ![Logo](https://camo.githubusercontent.com/edf76b9f6f2a2bdb90409932806e14a5fc56518cb6347bd450f128d60532caa3/68747470733a2f2f7a6962616c2e69722f7374617469632f6d656469612f6c6f676f2d7072696d6172792e36386236616163652e737667) ](https://zibal.ir/)

laravel zibal
-------------

[](#laravel-zibal)

 transaction request package for [zibal](https://zibal.ir/)

Getting Started
---------------

[](#getting-started)

To get a local copy up and running follow these simple steps.

### Installation

[](#installation)

1. You can install the package via composer: ```
    composer require llabbasmkhll/laravel-zibal
    ```

note that you only need to do following steps if you want to change merchant id . if you only want to test the webservice , no need to do these steps

2. publish config file to your project ```
    php artisan vendor:publish
    ```
3. change merchant value to your merchant id in config/zibal.php ( use `zibal` for testing ) ```
    return [
          'merchant' => 'zibal',
    ];
    ```

Usage
-----

[](#usage)

first include package facade into your file by :

```
use Llabbasmkhll\LaravelZibal\Facades\Zibal;
```

according to zibals [official documentation](https://docs.zibal.ir/IPG/API)there is 3 steps to issue a transaction in zibal

### 1 . Request :

[](#1--request-)

in this step zibal gets basic information about the transaction and returns `trackId` that is needed for next step

use this to init the transaction request :

```
Zibal::init(
    1000000,            //required amount          - in rial
    'redirect',         //required callback        - can be either route name or a valid url starting with http or https
    ['key' => 'value'], //optional callback_params - will be passed to callback as query params , works only when route name passed to callback
    'description',      //optional description     - additional data , good for various reports
    123,                //optional orderId         - id of clients order (eg $invoice->id) , will be passed back to callback
    '09366217515',      //optional mobile          - clients mobile number
    ['000000000000']    //optional allowedCards    - array of allowed card numbers
)->getResponse();
```

this will return an array consist of `result` , `message` and `trackId`

`result` represents the request status as below.

statusmeaning100successful operation102merchant not found103merchant not active104merchant not valid201processed before105amount must be grater than 1000106callbackUrl is not valid113amount greater than maximumyou can add `validate()` function after init like below :

```
Zibal::init( $amount, 'redirect')->validate(404)->getResponse();
```

this will redirect the user to 404 page if the result code was anything except 100.

### 2 . Start :

[](#2--start-)

redirect the user to zibals gateway for payment use :

```
Zibal::redirect($trackId);
```

you may **combine** first and second step into one line of code like this :

```
Zibal::init( $amount, 'redirect')->validate()->redirect();
```

that will init the transaction , then redirect the user zibals payment page if init was successful , otherwise it will redirect the user to 422 page

### 3 . Verify :

[](#3--verify-)

you can use this line of code to verify the transaction status:

```
Zibal::verify($trackId)->validate()->getResponse();
```

this will return an array consist of below parameters

parameterdiscriptionpaidAtdatetime of the paymentcardNumbermasked card number that used to paystatusstatus of the payment (discribed below)amountamount of the paymentrefNumberpayment reference number (in case of successful operation)descriptiondescription of the paymentorderIdthe same id that you passed in initresultresult of the requestmessageshort description of the request
`result` represents the request status as below.

codemeaning100successful operation102merchant not found103merchant not active104merchant not valid201processed before202payment failed (reason in status)203invalid trackId
`status` represents the request status as below.

statusmeaning-2internal failure-1wating for payment1paid - verified2paid - unverified3canceled by user4invalid card number5not enough balance6invalid code7maximum request length reached8maximum daily online payment number reached9maximum daily online payment amount reached10invalid card issuer11switch error12card unreachable

Example Controller
------------------

[](#example-controller)

```
