PHPackages                             omidgfx/payir-gateway - 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. omidgfx/payir-gateway

ActiveLibrary[Payment Processing](/categories/payments)

omidgfx/payir-gateway
=====================

Makes your (pay.ir) payments easy and implements reliable interfaces for payment gateway.

v1.0.8(5y ago)66311LGPL-2.1-onlyPHPPHP &gt;=5.6

Since Sep 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/omidgfx/payir-gateway)[ Packagist](https://packagist.org/packages/omidgfx/payir-gateway)[ Docs](https://github.com/omidgfx/payir-gateway)[ RSS](/packages/omidgfx-payir-gateway/feed)WikiDiscussions master Synced today

READMEChangelog (9)DependenciesVersions (10)Used By (0)

Pay.ir gateway for composer
===========================

[](#payir-gateway-for-composer)

##### Makes your (pay.ir) payments easy and implements reliable interfaces for payment gateway.

[](#makes-your-payir-payments-easy-and-implements-reliable-interfaces-for-payment-gateway)

---

Payir Gateway is a composer library to help working with pay.ir payment gateway.

- Secure
- Reliable
- Easy-to-use

Tutorial
--------

[](#tutorial)

#### [▷ Watch tutorial video in aparat](https://www.aparat.com/v/vBHIQ)

[](#-watch-tutorial-video-in-aparat)

Basic scenario
--------------

[](#basic-scenario)

For a healthy payment, first of all you need to send the order information to pay.ir and get a token and store it in your database (uniquely), then pass your client to an address that's involved with the token you just got. The client pays and passes back to your website again.

Now the client is in your website, you should verify his payment and sell your stuff.

---

### How to use?

[](#how-to-use)

- #### Step 1

    [](#step-1)

    Add [Payir Gateway](https://packagist.org/packages/omidgfx/payir-gateway) to your project.

    ```
    $ composer require omidgfx/payir-gateway
    ```
- #### Step 2

    [](#step-2)

    Create an instance of `Omidgfx\Payir` class using by your `API-KEY`.

    ```
     $payir = new Omidgfx\Payir(
         # api key
            'API-KEY-STRING',
         # language
            Payir::LANGUAGE_FARSI // or Payir::LANGUAGE_ENGLISH
     );
    ```
- #### Step 3

    [](#step-3)

    Get a new `token` from pay.ir by `send` method and use it for opening payment gateway.

    ```
    $response = $payir->send(
        # total amount of the order
            1000,
        # callback url to your website
            'https://myshop.com/verify?order=123',
        # mobile number [optional]
            '09121111111',
        # factor number
            '123',
        # description of the order
            'Some description',
        # valid card number
            '6219861012345678'
    );
    ```

    ```
    > Use `try-catch` to catch the exceptions.

    ```
- #### Step 4

    [](#step-4)

    Check for `$response` to be an instance of `Omidgfx\Payir\SendResponse` class.

    - if `$response` was an instance of `Omidgfx\Payir\SendResponse` class then save the token in your database and then redirect your client to **Pay Link** by `$response->redirectToPayLink()` or get **Pay Link** by`$response->getPayLink()` as a string.
    - if `$response` was an instance of `Omidgfx\Payir\ErrorResponse` class then show the error message to your client by `$response->error()` or track it down to fix it.

    ```
    if ($response instanceof Omidgfx\Payir\SendResponse) {
       $response->redirectToPayLink(); # redirection
    } elseif ($response instanceof Omidgfx\Payir\ErrorResponse) {
       echo 'ERR ' . $response->errorCode . ': ' . $response->error();
    }
    ```
- #### Step 5

    [](#step-5)

    After payment action performed, the client will be passed to your website, now you need to verify the transaction. Payir Gateway will do this for you with a cool callback listener like following:

    > Imagine `https://site.com/verify.php?invoice=123` is your callback (redirect), following code must written in your callback listener controller for example `verify.php`.

    Do [Step 2](#step-2) in `verify.php` again.

    ```
    $payir = new Omidgfx\Payir(
        # api key
           'API-KEY-STRING',
        # language
           Payir::LANGUAGE_FARSI // or Payir::LANGUAGE_ENGLISH
    );
    ```

    Create your callback listener:

    ```
    $cb = $payir->makeCallbackListener();
    ```

    Setup events on your callback listener:

    - setOnError
    - setOnSuccess
    - setOnException

    ```
    $cb->setOnError(function (Payir\ErrorResponse $errorResponse) {
     echo 'ERR ' . $errorResponse->errorCode . ': ' . $errorResponse->error();
    })->setOnSuccess(function (Payir\VerifyResponse $verifyResponse) {
     // $verifyResponse->status is always 1 here
     /*
     // Save these data or use them to check if transId is in your database already.
     $status       = $verifyResponse->status;
     $amount       = $verifyResponse->amount;
     $transId      = $verifyResponse->transId;
     $factorNumber = $verifyResponse->factorNumber;
     $mobile       = $verifyResponse->mobile;
     $factorNumber = $verifyResponse->factorNumber;
     $description  = $verifyResponse->description;
     $message      = $verifyResponse->message;
     */
      if(DB::getInstance()->exists('orders', ['trans_id' => $verifyResponse->transId]) == false){
          // SELL YOUR STUFF HERE
      }else{
          echo 'ERR: Security reason';
      }
    })->setOnException(function (Exception $exception) {
     //throw $exception;
     echo 'ERR: ' . $exception->getMessage();
    });
    ```

    Now turn on your callback listener like following:

    ```
    $cb->listen();
    ```

---

Created with ❤ by [Pejman Chatrrouz (Omidgfx)](https://github.com/omidgfx)

### 🎁 [Donate me](https://me.pay.ir/omidgfx)

[](#-donate-me)

[Email](mailto:info@omidgfx.com) | [Facebook](https://fb.com/omidgfx)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~23 days

Total

9

Last Release

1923d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eeeb3e8d7ebbb9676cff4cdc78d58852f5be28a913f6ffe0607666c461be9726?d=identicon)[omidgfx](/maintainers/omidgfx)

---

Top Contributors

[![omidgfx](https://avatars.githubusercontent.com/u/3041998?v=4)](https://github.com/omidgfx "omidgfx (17 commits)")

---

Tags

plugingatewaypayment gatewaypayirpejman chatrrouzomidgfx

### Embed Badge

![Health badge](/badges/omidgfx-payir-gateway/health.svg)

```
[![Health](https://phpackages.com/badges/omidgfx-payir-gateway/health.svg)](https://phpackages.com/packages/omidgfx-payir-gateway)
```

###  Alternatives

[shetabit/payment

Laravel Payment Gateway Integration Package

944330.1k5](/packages/shetabit-payment)[omalizadeh/laravel-multi-payment

A driver-based laravel package for online payments via multiple gateways

491.1k](/packages/omalizadeh-laravel-multi-payment)[dena-a/iran-payment

a Laravel package to handle Internet Payment Gateways for Iran Banking System

312.4k1](/packages/dena-a-iran-payment)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
