PHP code example of amirasaran / zarinpal

1. Go to this page and download the library: Download amirasaran/zarinpal 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/ */

    

amirasaran / zarinpal example snippets


php composer.phar 

..... 

public function actionRequest()
{
    /** @var Zarinpal $zarinpal */
    $zarinpal = Yii::$app->zarinpal ;
    /*
    * if you whant, you can pass $callbackParams as array to request method for additional params send to your callback url
    */
    if($zarinpal->request(100,'Test Payment description',null,null,['parameter'=>'value','parameter2'=>'value2'])->getStatus() == '100'){
        /*
        * You can save your payment request data to the database in here before rediract user
        * to get authority code you can use $zarinpal->getAuthority()
        */
        return $this->redirect($zarinpal->getRedirectUrl());
    }
    echo "Error !";
}

/*
* $parameter and $parameter2 are optional parameter that set in request method $callbackParams
*/
public function actionVerify($Authority, $Status , $parameter , $parameter2){

    if($Status != "OK")
        return ; //Payment canceled by user 

    /** @var Zarinpal $zarinpal */
    $zarinpal = Yii::$app->zarinpal ;
    
    if($zarinpal->verify($Authority, 100)->getStatus() == '100'){
        //User payment successfully verified!
        echo "payment successfully";
    }
    elseif($zarinpal->getStatus() == '101') {
        //User payment successfuly verified but user try to verified more than one 
        echo  "duplicated verify payment";
    } 
    else
        echo "payment error !";
}

.....