PHP code example of hamid-a / saderat-pg

1. Go to this page and download the library: Download hamid-a/saderat-pg 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/ */

    

hamid-a / saderat-pg example snippets


use SaderatPaymentGateway\SaderatPG;

$tid = 'terminal-id';
$mid = 'merchant-id';
$public_key = __DIR__.'/saderat-public-key.pub'; // path to public key file
$private_key = __DIR__.'/saderat-private-key.key'; // path to private key file
$callback_url = 'callback-url'; // we can set calback url in initializing or getToken section


$gateway = new SaderatPG($tid, $mid, $public_key, $private_key, $callback_url);

$amount = 1000; // in int format
$crn = 'customer receipt number'; // must be unique in each transaction
$callback_url = 'callback-url'; // we can set calback url in initializing or getToken section
token = '';
try {

    $token = $gateway->getToken($amount, $crn, $callback_url);

} catch (\Exception $e){
    echo 'Error code:'.$e->getCode().' Error message:'.$e->getMessage();
}
if($token != '') {
// redirect user to: https://mabna.shaparak.ir/?ID=$token
} 

$verified = fasle;

try {

    $verified = $gateway->verifyTransaction($token, $_POST['CRN'], $_POST['TRN'], $_POST['SIGNATURE']);

} catch(\Exception $e){
    echo 'Error code:'.$e->getCode().' Error message:'.$e->getMessage();
}

if($verified) {
//transaction verified
} else {
// verification failed
}

    'saderat-pg' => [
        'mid' => 'your merchant id',
        'tid' => 'your terminal id',
        'public-key' => __DIR__.'/saderat-public-key.pub', // path to public key file
        'private-key' => __DIR__.'/saderat-private-key.key', // path to private key file
        'callback-url' => '' // callback url (not 

use SaderatPG;

// get token
$token = SaderatPG::getToken($amount, $crn, $callback_url);

// verify transaction
$verified = SaderatPG::verifyTransaction($token, $request->get('CRN'), $request->get('TRN'), $request->get('SIGNATURE'));