PHP code example of dizatech / zarinpal_ipg

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

    

dizatech / zarinpal_ipg example snippets


$args = [
    'merchantId'    => '4e1598fc-09b8-29e6-2edc-bf5494616b4d'
]; //Replace arguments with your gateway actual values
$ipg = new ZarinpalIpg($args);

$args = [
    'merchantId'    => '4e1598fc-09b8-29e6-2edc-bf5494616b4d'
]; //Replace arguments with your gateway actual values
$ipg = new ZarinpalIpg($args);
$amount = 1000; //Replace with actual order amount in Rials
$description = 'خرید آزمایشی'; //Replace it with order description
$redirect_address = 'http://my.com/verify'; //Replace with your desired callback page URL
$result = $ipg->getToken($amount, $order_id, $redirect_address);
if( $result->status == 'success' ){
    header('Location: https://www.zarinpal.com/pg/StartPay/' . $result->token);
    die();
}
else{
    echo "Error: {$result->message}";
}

$args = [
    'merchantId'    => '4e1598fc-09b8-29e6-2edc-bf5494616b4d'
]; //Replace arguments with your gateway actual values
$ipg = new ZarinpalIpg($args);
$amount = 1000; //Replace with actual order amount in Rials
$result = $ipg->verifyRequest($amount, $_GET['Authority']);