PHP code example of maatify / pay-tabs

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

    

maatify / pay-tabs example snippets



use App\Assist\AppFunctions;
use Maatify\PayTabs\PayTabsRedirectUrl;

class PayTabsCartPayUrl extends PayTabsRedirectUrl
{
    public function __construct()
    {
        $this->url = 'https://secure-egypt.paytabs.com/payment/request';
        $this->profile_id = 142849;
        $this->server_secret_key = __YOUR_SERVER_KEY__;
        $this->client_secret_key = __YOUR_CLIENT_KEY__;
        $this->currency = 'EGP';
        $this->url_callback = __CALLBACK_URL__;
        $this->url_return = __RETURN_URL__;
    }
}

try {

        return PayTabsCartPayUrl::obj()->getRedirectUrl($name, $email, $amount, $cart_id, $description, $language);
        
    }
catch (PayTabsException $exception){

    Logger::RecordLog($exception, 'paytabs_getRedirectUrl_exception');

        // Handle specific error codes programmatically
        
        switch ($exception->getErrorCode()) {
        
            case 1004:
            
                // Connection Error
                
                break;
                
            case 1003:
            
                // Curl response Error
                
                break;
        }
    }

use App\Assist\AppFunctions;
use Maatify\PayTabs\PayTabsValidations;

class PayTabsAppValidation extends PayTabsValidations
{
    public function __construct()
    {
        $this->url = 'https://secure-egypt.paytabs.com/payment/request';
        $this->profile_id = 142849;
        $this->server_secret_key = __YOUR_SERVER_KEY__;
        $this->client_secret_key = __YOUR_CLIENT_KEY__;
        $this->currency = 'EGP';
        $this->url_callback = __CALLBACK_URL__;
        $this->url_return = __RETURN_URL__;
    }
}


try {

    $signature_fields = (new PayTabsAppValidation())->returnValidation();
    
    // Start logic for success|Declined|Canceled return

}catch (PayTabsException $exception){

    Logger::RecordLog($exception, 'paytabs_return_exception');
    
    // Handle specific error codes programmatically
    
    switch ($exception->getErrorCode()) {
        case 1002:
        
            // Missing Post
            
            break;
            
        case 1005:
        
            // Hash Nit Equals
            
            break;
    }
}


try {

    $signature_fields = (new PayTabsAppValidation())->callbackValidation();
    
    // Start logic for success|Declined|Canceled return
    
}catch (PayTabsException $exception){

    Logger::RecordLog($exception, 'paytabs_callback_exception');
    
    // Handle specific error codes programmatically
    
    switch ($exception->getErrorCode()) {
        
        case 1002:
        
//            echo "Handle MissingPost logic here.\n";

            break;
            
        case 1005:
        
//            echo "Handle InvalidSignature logic here.\n";

        break;
    }

}