PHP code example of dpsoft / saderat

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


 use Dpsoft\Saderat\Saderat;

try{
    /**
    * @param int $terminalId The Saderat cart terminal id assign to you 
    */
    $request = new Saderat($terminalId);
	
    /**
     * @param string $callbackUrl The url that customer redirect to after payment
     * @param int $amount The amount that customer must pay
     * @param string $payload Optional addition data
	 *
	 * @method payRequest Return invoice id and you can save in your DB
	 *
     */
    $invoiceId = $request->request($callbackUrl, $amount, $payload);
	
    echo $request->getRedirectScript();
   
}catch (\Throwable $exception){
    echo $exception->getMessage();
}


use Dpsoft\Saderat\Saderat;

try{
    /**
      * @var int $terminalId
      */
    $response = new Saderat($terminalId);
	
        /**
          * @method $verify return class of all response value and you can convert to array by toArray() method
          */
        $verifyData = $response->verify();
        /**
          * Check your amount with response amount
          */
        echo "Successful payment ...";
       
}catch (\Throwable $exception){
    echo $exception->getMessage();
}


use Dpsoft\Saderat\Saderat;

try{
    /**
      * @var int $terminalId
      */
    $response = new Saderat($terminalId);
	
    $response->rollbackPayment($digitalReceipt);
    	
    echo "Successful rollback transaction ...";
       
}catch (\Throwable $exception){
    echo $exception->getMessage();
}

 $digitalReceipt = $verifyData->getDigitalReceipt();
 

$verifyDataArray = $verifyData->toArray();
$digitalReceipt = $verifyDataArray['digitalreceipt'];