PK       ! _û]oh
  h
    Util.phpnu „[µü¤        <?php

/*
 * Created by tpay.com
 */

namespace Omnipay\Tpay\_class_tpay\Utilities;

/**
 * Class Util
 *
 * Utility class which helps with:
 *  - parsing template files
 *  - log library operations
 *  - handle POST array
 *
 * @package tpay
 */
class Util
{
    const REMOTE_ADDR = 'REMOTE_ADDRESS';

    static $lang = 'en';

    static $path = null;

    /**
     * Save text to log file with details
     *
     * @param string $title action name
     * @param string $text text to save
     */
    public static function log($title, $text)
    {
        $text = (string)$text;
        $logFilePath = dirname(__FILE__) . '/../../log';

        $ip = (isset($_SERVER[static::REMOTE_ADDR])) ? $_SERVER[static::REMOTE_ADDR] : '';

        $logText = "\n===========================";
        $logText .= "\n" . $title;
        $logText .= "\n===========================";
        $logText .= "\n" . date('Y-m-d H:i:s');
        $logText .= "\nip: " . $ip;
        $logText .= "\n";
        $logText .= $text;
        $logText .= "\n\n";

        if (file_exists($logFilePath) && is_writable($logFilePath)) {
            file_put_contents($logFilePath, $logText, FILE_APPEND);
        }
    }

    /**
     * Save one line to log file
     *
     * @param string $text text to save
     */
    public static function logLine($text)
    {
        $text = (string)$text;
        $logFilePath = dirname(__FILE__) . '/../../log';
        if (file_exists($logFilePath) && is_writable($logFilePath)) {
            file_put_contents($logFilePath, "\n" . $text, FILE_APPEND);
        }
    }

    /**
     * Get value from $_POST array.
     * If not exists return false
     *
     * @param string $name
     * @param string $type variable type
     *
     * @return mixed
     * @throws TException
     */
    public static function post($name, $type)
    {
        if (!isset($_POST[$name])) {
            return false;
        }
        $val = $_POST[$name];
        if ($type === 'int') {
            $val = (int)$val;
        } elseif ($type === 'float') {
            $val = (float)$val;
        } elseif ($type === 'string') {
            $val = (string)$val;
        } elseif ($type === 'array') {
            $val = (array)$val;
        } else {
            throw new TException('Undefined $_POST variable type');
        }

        return $val;
    }

    public function setLanguage($lang)
    {
        static::$lang = $lang;
        return $this;
    }

    /**
     * Set custom library path
     *
     * @param string $path
     * @return $this
     */
    public function setPath($path)
    {
        static::$path = $path;
        return $this;
    }
}
PK       ! Iü‡  ‡    ObjectsHelper.phpnu „[µü¤        <?php

/*
 * Created by tpay.com.
 * Date: 12.06.2017
 * Time: 17:49
 */

namespace Omnipay\Tpay\_class_tpay\Utilities;

use Omnipay\Tpay\_class_tpay\Validators\FieldsConfigValidator;
use Omnipay\Tpay\Dictionaries\NotificationsIP;

class ObjectsHelper
{
    use FieldsConfigValidator;

    /**
     * Api key
     * @var string
     */
    protected $trApiKey = '[TR_API_KEY]';

    /**
     * Api pass
     * @var string
     */
    protected $trApiPass = '[TR_API_PASS]';

    /**
     * Merchant id
     * @var int
     */
    protected $merchantId = '[MERCHANT_ID]';

    /**
     * Merchant secret
     * @var string
     */
    protected $merchantSecret = '[MERCHANT_SECRET]';

    /**
     * Card API key
     * @var string
     */
    protected $cardApiKey = '[CARD_API_KEY]';

    /**
     * Card API password
     * @var string
     */
    protected $cardApiPass = '[CARD_API_PASSWORD]';

    /**
     * Card API code
     * @var string
     */
    protected $cardVerificationCode = '[CARD_API_CODE]';

    /**
     * Card RSA key
     * @var string
     */
    protected $cardKeyRSA = '[CARD_RSA_KEY]';

    /**
     * Card hash algorithm
     * @var string
     */
    protected $cardHashAlg = '[CARD_HASH_ALG]';
    /**
     * API login
     * @var string
     */
    protected $szkwalApiLogin = '[SZKWAL_LOGIN]';
    /**
     * API password
     * @var string
     */
    protected $szkwalApiPass = '[SZKWAL_API_PASSWORD]';
    /**
     * API hash
     * @var string
     */
    protected $szkwalApiHash = '[SZKWAL_API_HASH]';
    /**
     * API partner unique address
     * @var string
     */
    protected $szkwalPartnerUniqueAddress = '[SZKWAL_PARTNER_ADDRESS]';
    /**
     * API title format
     * @var string
     */
    protected $szkwalTitleFormat = '[SZKWAL_TITLE_FORMAT]';

    protected $secureIP = NotificationsIP::SECURE_IPS;
    protected $validateServerIP = true;
    protected $validateForwardedIP = false;
    protected $transactionApi;
    protected $cardsApi;
    protected $basicClient;
    protected $validator;
    protected $curl;

    public function requests($url, $params)
    {
        return false;
    }

    /**
     * Disabling validation of payment notification server IP
     * Validation of tpay server ip is very important.
     * Use this method only in test mode and be sure to enable validation in production.
     */
    public function disableValidationServerIP()
    {
        $this->validateServerIP = false;
        return $this;
    }

    /**
     * Enabling validation of payment notification server IP
     */
    public function enableValidationServerIP()
    {
        $this->validateServerIP = true;
        return $this;
    }

    /**
     * CloudFlare protected servers will be validated like all others
     * It is default behavior
     */
    public function disableForwardedIPValidation()
    {
        $this->validateForwardedIP = false;
        return $this;
    }

    /**
     * Enabling validation for CloudFlare protected servers
     */
    public function enableForwardedIPValidation()
    {
        $this->validateForwardedIP = true;
        return $this;
    }

    /**
     * Check if request is called from secure tpay server
     *
     * @return bool
     */
    public function isTpayServer()
    {
        return (new ServerValidator(
            $this->validateServerIP,
            $this->validateForwardedIP,
            $this->secureIP)
        )->isValid();
    }

}
PK       ! ˜Ñâä      ServerValidator.phpnu „[µü¤        <?php

/*
 * Created by tpay.com.
 * Date: 12.06.2017
 * Time: 17:49
 */

namespace Omnipay\Tpay\_class_tpay\Utilities;

class ServerValidator
{
    const REMOTE_ADDRESS = 'REMOTE_ADDR';

    const FORWARDER_ADDRESS = 'HTTP_X_FORWARDED_FOR';

    /**
     * @var bool
     */
    private $validateForwardedIP;

    /**
     * @var bool
     */
    private $validateServerIP;

    /**
     * @var bool
     */
    private $secureIP;

    public function __construct($validateServerIP, $validateForwardedIP, array $secureIP)
    {
        $this->validateServerIP = $validateServerIP;
        $this->validateForwardedIP = $validateForwardedIP;
        $this->secureIP = $secureIP;
    }

    /**
     * Check if request is called from secure tpay server
     *
     * @return bool
     */
    public function isValid()
    {
        if (!$this->validateServerIP) {
            return true;
        }

        $remoteIP = $this->getServerValue(static::REMOTE_ADDRESS);
        $forwarderIP = $this->getServerValue(static::FORWARDER_ADDRESS);

        if (is_null($remoteIP) && is_null($forwarderIP)) {
            return false;
        }

        if ($this->checkIP($remoteIP)) {
            return true;
        }

        if ($this->validateForwardedIP && $this->checkIP($forwarderIP)) {
            return true;
        }

        return false;
    }

    /**
     * Get value from $_SERVER array if exists
     *
     * @param string $name
     * @return string|null
     */
    private function getServerValue($name)
    {
        if (isset($_SERVER[$name])) {
            return $_SERVER[$name];
        }
    }

    /**
     * Validate if $ip is secure
     *
     * @param $ip
     * @return bool
     */
    private function checkIP($ip)
    {
        return in_array($ip, $this->secureIP, true);
    }

}
PK       ! }ïUŽ\  \    TException.phpnu „[µü¤        <?php

/*
 * Created by tpay.com
 */

namespace Omnipay\Tpay\_class_tpay\Utilities;

use Exception;

/**
 * Class TException
 *
 * @package tpay
 */
class TException extends Exception
{
    /**
     * @param string $message error message
     * @param int $code error code
     */
    public function __construct($message, $code = 0)
    {
        $message .= ' in file ' . $this->getFile() . ' line: ' . $this->getLine();
        Util::log('TException', $message . "\n\n" . $this->getTraceAsString());

        $this->message = $code . ' : ' . $message;
        return $code . ' : ' . $message;
    }
}
PK         ! _û]oh
  h
                  Util.phpnu „[µü¤        PK         ! Iü‡  ‡               
  ObjectsHelper.phpnu „[µü¤        PK         ! ˜Ñâä                h  ServerValidator.phpnu „[µü¤        PK         ! }ïUŽ\  \              ¾  TException.phpnu „[µü¤        PK      :  X"    