PHP code example of dpsoft / zibal

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

    

dpsoft / zibal example snippets


try {
    $zibal = new \Dpsoft\Zibal\Zibal($merchant);
    $result = $zibal->request($callbackUrl,$amount);
    //save amount and invoice id to forther use
    $_SESSION['amount']=$amount;
    $_SESSION['token']=$result['token'];

    $zibal->redirectToBank();
    exit();
}catch (Throwable $exception){
    echo $exception->getMessage();
}

try {
    $zibal = new \Dpsoft\Zibal\Zibal($merchant);
    $result = $zibal->verify($_SESSION['amount'],$_SESSION['token']);
    //save result. The keys are: card_number,transaction_id and token for example $result['token']
    echo "Successfull transaction.";
}catch (Throwable $exception){
    echo "Error in transaction: ";
}