PHP code example of omidgfx / payir-gateway

1. Go to this page and download the library: Download omidgfx/payir-gateway library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

omidgfx / payir-gateway example snippets


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

    $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'
    );
    

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

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

  $cb = $payir->makeCallbackListener();
    

  $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();
   });
    

  $cb->listen();