Esempio n. 1
0
 /**
  * @param array $response
  * @return TpDataApiResponse
  * @throws TpInvalidSignatureException
  */
 public static function createFromResponse(array $response)
 {
     $keys = array('merchantId');
     $data = TpUtils::filterKeys($response, $keys);
     $instance = new static($data);
     return $instance;
 }
 /**
  * @param string $operation
  * @param array $data
  * @return TpDataApiRequest
  */
 public static function getRequest($operation, TpMerchantConfig $config, array $data)
 {
     /** @var TpDataApiRequest $className Only class name. */
     $className = preg_replace('/^get(.+)$/', 'TpDataApiGet$1Request', $operation);
     $fileName = $className . '.php';
     TpUtils::requirePaths(array(array('dataApi', 'requests', $fileName)));
     $request = $className::createWithConfig($config, $data);
     return $request;
 }
Esempio n. 3
0
 /**
  * TpAbstractModel constructor.
  *
  * @param array $data
  */
 public function __construct(array $data = array())
 {
     $keys = static::keys();
     $filtered = TpUtils::filterKeys($data, $keys);
     foreach ($filtered as $key => $value) {
         $this[$key] = $value;
     }
     unset($value);
 }
 /**
  * @param string $operation
  * @param TpMerchantConfig $config
  * @param stdClass $data
  * @return TpDataApiResponse
  * @throws TpInvalidSignatureException
  */
 public static function getResponse($operation, TpMerchantConfig $config, stdClass $data)
 {
     /** @var string|TpDataApiResponse $className Only class name. */
     $className = preg_replace('/^get(.+)$/', 'TpDataApiGet$1Response', $operation);
     $fileName = $className . '.php';
     TpUtils::requirePaths(array(array('dataApi', 'responses', $fileName)));
     $array = TpUtils::toArrayRecursive($data);
     $listPaths = $className::listPaths();
     $flattened = TpDataApiSoapFlattener::processWithPaths($array, $listPaths);
     TpDataApiSignature::validate($flattened, $config->dataApiPassword);
     $dateTimePaths = $className::dateTimePaths();
     $inflated = TpDataApiDateTimeInflater::processWithPaths($flattened, $dateTimePaths);
     $response = $className::createFromResponse($inflated);
     return $response;
 }
Esempio n. 5
0
 /**
  * @param mixed $value
  * @param string[] $currentPath
  * @return mixed
  */
 protected function processItem($value, array $currentPath)
 {
     $isArray = is_array($value);
     if ($isArray) {
         $isList = TpUtils::isList($value);
         if ($isList) {
             $processed = $this->processList($value, $currentPath);
         } else {
             $processed = $this->processHash($value, $currentPath);
         }
     } else {
         // Only arrays are treated specially.
         $processed = $value;
     }
     return $processed;
 }
Esempio n. 6
0
<?php

TpUtils::requirePaths(array(array('TpMerchantConfig.php')));
class TpPermanentPayment
{
    /**
     * @var TpMerchantConfig
     */
    protected $config;
    protected $merchantData;
    protected $description;
    protected $returnUrl;
    protected $signature;
    function __construct(TpMerchantConfig $config, $merchantData, $description, $returnUrl)
    {
        $this->config = $config;
        $this->merchantData = $merchantData;
        $this->description = $description;
        $this->returnUrl = $returnUrl;
    }
    public function getConfig()
    {
        return $this->config;
    }
    public function getMerchantData()
    {
        return $this->merchantData;
    }
    public function getDescription()
    {
        return $this->description;
Esempio n. 7
0
<?php

TpUtils::requirePaths(array(array('dataApi', 'TpDataApiObject.php'), array('dataApi', 'parameters', 'TpDataApiSignature.php'), array('dataApi', 'processors', 'TpDataApiDateTimeDeflater.php'), array('exceptions', 'TpBadMethodCallException.php')));
abstract class TpDataApiRequest extends TpDataApiObject
{
    /**
     * @var TpMerchantConfig|null
     */
    protected $_config;
    protected static $dateTimePaths = array();
    /**
     * Request must contain merchant config data alongside its own: merchant ID,
     * account ID, password. Thus, requests must be instantiating by this call
     * instead of their constructor.
     *
     * @param TpMerchantConfig $config
     * @param array $data
     * @return TpDataApiRequest
     */
    public static function createWithConfig(TpMerchantConfig $config, $data = array())
    {
        $instance = new static($data);
        $instance->_config = $config;
        return $instance;
    }
    /**
     * Merchant ID and in some request also account ID is prepeneded. Moreover,
     * SOAP request must not contain DateTime timestamps: They must be cast as
     * strings.
     *
     * @return array
<?php

TpUtils::requirePaths(array(array('dataApi', 'responses', 'TpDataApiResponse.php')));
class TpDataApiGetPaymentStateResponse extends TpDataApiResponse
{
    /**
     * @var int|null
     */
    protected $state;
    /**
     * @param array $response
     * @return TpDataApiGetPaymentStateResponse
     */
    public static function createFromResponse(array $response)
    {
        /** @var TpDataApiGetPaymentStateResponse $instance */
        $instance = parent::createFromResponse($response);
        $instance->setState($response['state']);
        return $instance;
    }
    /**
     * @return int|null
     */
    public function getState()
    {
        return $this->state;
    }
    /**
     * @param int|null $state
     */
    public function setState($state = null)
Esempio n. 9
0
<?php

require_once implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'TpUtils.php'));
// …everything else can be loaded using TpUtils::requirePaths.
TpUtils::requirePaths(array(array('TpMerchantConfig.php'), array('exceptions', 'TpSoapException.php'), array('dataApi', 'requests', 'TpDataApiRequestFactory.php'), array('dataApi', 'responses', 'TpDataApiResponseFactory.php'), array('dataApi', 'parameters', 'TpDataApiGetPaymentsSearchParams.php'), array('dataApi', 'parameters', 'TpDataApiPaginationRequest.php'), array('dataApi', 'parameters', 'TpDataApiOrdering.php')));
class TpDataApiHelper
{
    /**
     * @param TpMerchantConfig $config
     * @param bool|null $onlyActive
     * @return TpDataApiGetPaymentMethodsResponse
     * @throws TpSoapException
     */
    public static function getPaymentMethods(TpMerchantConfig $config, $onlyActive = null)
    {
        $data = array('onlyActive' => $onlyActive);
        $request = TpDataApiRequestFactory::getRequest(__FUNCTION__, $config, $data);
        $response = self::call(__FUNCTION__, $config, $request);
        return $response;
    }
    /**
     * @param TpMerchantConfig $config
     * @param int $paymentId
     * @return TpDataApiGetPaymentResponse
     * @throws TpSoapException
     */
    public static function getPayment(TpMerchantConfig $config, $paymentId)
    {
        $data = array('paymentId' => $paymentId);
        $request = TpDataApiRequestFactory::getRequest(__FUNCTION__, $config, $data);
        $response = self::call(__FUNCTION__, $config, $request);
Esempio n. 10
0
<?php

TpUtils::requirePaths(array(array('exceptions', 'TpInvalidArgumentException.php'), array('ferbuy', 'TpFerBuyCartItem.php')));
/**
 * Class TpFerBuyCart represents user cart.
 */
class TpFerBuyCart
{
    /**
     * @var TpFerBuyCartItem[]
     */
    private $items = array();
    /**
     * @var int
     */
    private $subTotal = 0;
    /**
     * @var int
     */
    private $discount = 0;
    /**
     * @var int
     */
    private $tax = 0;
    /**
     * @var int
     */
    private $shipping = 0;
    /**
     * @var string
     */
Esempio n. 11
0
<?php

require_once implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'TpUtils.php'));
// …everything else can be loaded using TpUtils::requirePaths.
TpUtils::requirePaths(array(array('TpCardPaymentResponse.php'), array('exceptions', 'TpException.php')));
/**
 * @author Michal Kandr
 */
class TpCardHelper
{
    protected static function getSignature($data)
    {
        return md5(http_build_query(array_filter($data)));
    }
    public static function depositPayment(TpMerchantConfig $config, $merchantData)
    {
        $client = new SoapClient($config->webServicesWsdl);
        $signature = static::getSignature(array('merchantId' => $config->merchantId, 'accountId' => $config->accountId, 'merchantData' => $merchantData, 'password' => $config->password));
        $result = $client->cardDepositPaymentRequest(array('merchantId' => $config->merchantId, 'accountId' => $config->accountId, 'merchantData' => $merchantData, 'signature' => $signature));
        if (!$result) {
            throw new TpException();
        }
        return new TpCardPaymentResponse($result);
    }
    public static function stornoPayment(TpMerchantConfig $config, $merchantData)
    {
        $client = new SoapClient($config->webServicesWsdl);
        $signature = static::getSignature(array('merchantId' => $config->merchantId, 'accountId' => $config->accountId, 'merchantData' => $merchantData, 'password' => $config->password));
        $result = $client->cardStornoPaymentRequest(array('merchantId' => $config->merchantId, 'accountId' => $config->accountId, 'merchantData' => $merchantData, 'signature' => $signature));
        if (!$result) {
            throw new TpException();
Esempio n. 12
0
<?php

TpUtils::requirePaths(array(array('TpPayment.php')));
/**
 * Base class for various ThePay Merchant components.
 */
abstract class TpMerchantHelper
{
    /**
     * Payment that should be rendered using the helper. Specify the
     * payment as parameter to the helper constructor.
     * @var TpPayment
     */
    protected $payment;
    /**
     * Constructor. Specify the payment object here.
     * @param payment Instace of the TpPayment method, that contains
     *   inforamtion about the payment to be made.
     */
    function __construct(TpPayment $payment)
    {
        $this->payment = $payment;
    }
    /**
     * Call this function to render the code for the component. This
     * is abstract function prototype, that should be implemented in
     * derived classes to provide custom HTML (or other) code.
     */
    abstract function render();
    /**
     * Build the query part of the URL from payment data and optional
Esempio n. 13
0
<?php

TpUtils::requirePaths(array(array('exceptions', 'TpInvalidParameterException.php'), array('ferbuy', 'TpFerBuyOrder.php'), array('TpMerchantConfig.php'), array('TpEscaper.php')));
/**
 * Class representing one payment instance.
 */
class TpPayment
{
    /**
     * Config containing merchant-specific configuration options.
     * Instance of TpMerchantConfig, passed to the TpPayment constructor.
     * @var TpMerchantConfig
     */
    protected $config;
    /**
     * @var float value indicating the amount of money that should be paid.
     */
    protected $value = NULL;
    /**
     * @var string Currency identifier.
     */
    protected $currency = NULL;
    /**
     * @var string Payment description that should be visible to the customer.
     */
    protected $description = NULL;
    /**
     * Any merchant-specific data, that will be returned to the site after
     * the payment has been completed.
     * @var string
     */
<?php

TpUtils::requirePaths(array(array('exceptions', 'TpException.php')));
/**
 * Exception thrown when invalid parameter value has been received.
 */
class TpInvalidParameterException extends TpException
{
    protected $parameter;
    public function __construct($parameter)
    {
        $this->parameter = $parameter;
        parent::__construct("Invalid parameter value.");
    }
    public function getParameter()
    {
        return $this->parameter;
    }
}
<?php

TpUtils::requirePaths(array(array('dataApi', 'requests', 'TpDataApiRequest.php'), array('dataApi', 'parameters', 'TpDataApiPaginationRequest.php'), array('dataApi', 'parameters', 'TpDataApiOrdering.php'), array('dataApi', 'TpValueFormatter.php')));
class TpDataApiGetPaymentsRequest extends TpDataApiRequest
{
    protected static $dateTimePaths = array(array('searchParams', 'createdOnFrom'), array('searchParams', 'createdOnTo'), array('searchParams', 'finishedOnFrom'), array('searchParams', 'finishedOnTo'));
    /**
     * @var TpDataApiGetPaymentsSearchParams|null
     */
    protected $searchParams;
    /**
     * @var TpDataApiPaginationRequest|null
     */
    protected $pagination;
    /**
     * @var TpDataApiOrdering|null
     */
    protected $ordering;
    /**
     * @return TpDataApiGetPaymentsSearchParams|null
     */
    public function getSearchParams()
    {
        return $this->searchParams;
    }
    /**
     * @param TpDataApiGetPaymentsSearchParams|null $searchParams
     */
    public function setSearchParams(TpDataApiGetPaymentsSearchParams $searchParams = null)
    {
        $this->searchParams = TpValueFormatter::format('TpDataApiGetPaymentsSearchParams', $searchParams);
Esempio n. 16
0
<?php

require_once implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'TpUtils.php'));
// …everything else can be loaded using TpUtils::requirePaths.
TpUtils::requirePaths(array(array('ferbuy', 'TpFerBuyCart.php'), array('ferbuy', 'TpFerBuyCustomer.php'), array('TpEscaper.php')));
/**
 * Class TpFerBuyOrder represents order.
 */
class TpFerBuyOrder
{
    /**
     * @var TpFerBuyCart
     */
    private $cart;
    /**
     * @var TpFerBuyCustomer
     */
    private $customer;
    /**
     * @param TpFerBuyCustomer $customer Customer object.
     * @param TpFerBuyCart $cart User cart
     */
    public function __construct(TpFerBuyCustomer $customer, TpFerBuyCart $cart)
    {
        $this->cart = $cart;
        $this->customer = $customer;
    }
    /**
     * Get previously set cart.
     * @return TpFerBuyCart
     */
Esempio n. 17
0
<?php

TpUtils::requirePaths(array(array('exceptions', 'TpMissingParameterException.php'), array('exceptions', 'TpInvalidSignatureException.php'), array('dataApi', 'processors', 'TpDataApiDigester.php')));
class TpDataApiSignature
{
    /**
     * TpDataApiSignature constructor.
     */
    protected function __construct()
    {
        // Hidden.
    }
    /**
     * Signature is always computed from a hash. If there is a 'signature' key
     * already present, it is removed. Password can be provided either as a hash
     * key 'password', or as a method argument $password.
     *
     * @param array $data
     * @param string $password
     * @return string
     * @throws TpMissingParameterException
     */
    public static function compute(array $data, $password = null)
    {
        unset($data['signature']);
        $passwordIsNull = is_null($password);
        if (!$passwordIsNull) {
            $data['password'] = $password;
        }
        $dataPasswordKeyExists = array_key_exists('password', $data);
        if (!$dataPasswordKeyExists) {
<?php

TpUtils::requirePaths(array(array('dataApi', 'requests', 'TpDataApiRequest.php'), array('dataApi', 'TpValueFormatter.php')));
class TpDataApiGetPaymentStateRequest extends TpDataApiRequest
{
    /**
     * @var int|null
     */
    protected $paymentId;
    /**
     * @return int|null
     */
    public function getPaymentId()
    {
        return $this->paymentId;
    }
    /**
     * @param int|null $paymentId
     */
    public function setPaymentId($paymentId = null)
    {
        $this->paymentId = TpValueFormatter::format('int', $paymentId);
    }
}
<?php

TpUtils::requirePaths(array(array('dataApi', 'processors', 'TpDataApiProcessorWithPaths.php')));
class TpDataApiDateTimeDeflater extends TpDataApiProcessorWithPaths
{
    /**
     * @param mixed $value
     * @param array $currentPath
     * @return mixed
     */
    protected function processItem($value, array $currentPath)
    {
        $isNull = is_null($value);
        if ($isNull) {
            $processed = null;
        } else {
            $onPath = $this->onPath($currentPath);
            if ($onPath) {
                /** @var DateTime $value */
                $processed = $value->format('c');
            } else {
                $processed = parent::processItem($value, $currentPath);
            }
        }
        return $processed;
    }
}
<?php

TpUtils::requirePaths(array(array('dataApi', 'parameters', 'TpDataApiPagination.php')));
class TpDataApiPaginationRequest extends TpDataApiPagination
{
}
<?php

TpUtils::requirePaths(array(array('dataApi', 'processors', 'TpDataApiProcessorWithPaths.php'), array('exceptions', 'TpInvalidParameterException.php')));
class TpDataApiDateTimeInflater extends TpDataApiProcessorWithPaths
{
    /**
     * @param mixed $value
     * @param string[] $currentPath
     * @return mixed
     * @throws TpInvalidParameterException
     */
    protected function processItem($value, array $currentPath)
    {
        $isNull = is_null($value);
        if ($isNull) {
            $processed = parent::processItem($value, $currentPath);
        } else {
            $onPath = $this->onPath($currentPath);
            if ($onPath) {
                // Pozor, neprojde, pokud časové razítko obsahuje desetinnou část
                // vteřin. Viz https://bugs.php.net/bug.php?id=51950.
                $processed = DateTime::createFromFormat(DateTime::ISO8601, $value);
                if ($processed === false) {
                    $errorPathArray = $currentPath;
                    array_unshift($errorPathArray, '');
                    $errorPathString = implode('/', $errorPathArray);
                    throw new TpInvalidParameterException($errorPathString);
                }
            } else {
                $processed = parent::processItem($value, $currentPath);
            }
Esempio n. 22
0
<?php

TpUtils::requirePaths(array(array('dataApi', 'TpDataApiObject.php'), array('dataApi', 'TpValueFormatter.php')));
class TpDataApiPaymentInfo extends TpDataApiObject
{
    /**
     * @var bool|null
     */
    protected $isOffline;
    /**
     * @var string|null
     */
    protected $paymentPageUrl;
    /**
     * Only applicable for unpaid payments.
     * @var string|null
     */
    protected $paymentInfoUrl;
    /**
     * Only applicable for unpaid payments.
     *
     * @var string|null
     */
    protected $methodChangeUrl;
    /**
     * @var float|null
     */
    protected $value;
    /**
     * Only applicable for offline payments. 
     *
<?php

TpUtils::requirePaths(array(array('exceptions', 'TpInvalidParameterException.php')));
class TpMissingParameterException extends TpInvalidParameterException
{
    function __construct($parameter)
    {
        parent::__construct($parameter);
        $this->message = "Missing parameter " . $parameter;
    }
}
<?php

TpUtils::requirePaths(array(array('dataApi', 'responses', 'TpDataApiResponse.php'), array('dataApi', 'parameters', 'TpDataApiMerchantAccountMethod.php')));
class TpDataApiGetPaymentMethodsResponse extends TpDataApiResponse
{
    protected static $listPaths = array(array('methods', 'method'));
    /**
     * @var int|null
     */
    protected $accountId;
    /**
     * @var TpDataApiMerchantAccountMethod[]
     */
    protected $methods = array();
    /**
     * @param array $response
     * @return TpDataApiGetPaymentMethodsResponse
     */
    public static function createFromResponse(array $response)
    {
        /** @var TpDataApiGetPaymentMethodsResponse $instance */
        $instance = parent::createFromResponse($response);
        $instance->setAccountId($response['accountId']);
        $methods = array();
        foreach ($response['methods'] as $method) {
            $methods[] = new TpDataApiMerchantAccountMethod($method);
        }
        unset($method);
        $instance->setMethods($methods);
        return $instance;
    }
Esempio n. 25
0
<?php

require_once implode(DIRECTORY_SEPARATOR, array(__DIR__, 'TpUtils.php'));
// …everything else can be loaded using TpUtils::requirePaths.
TpUtils::requirePaths(array(array('TpPayment.php'), array('exceptions', 'TpMissingParameterException.php'), array('exceptions', 'TpInvalidSignatureException.php')));
/**
 * Class to handle returned payment callback from ThePay gate.
 */
class TpReturnedPayment extends TpPayment
{
    /**
     * @var integer merchantId from request
     */
    protected $requestMerchantId = null;
    /**
     * @var integer accountId from request
     */
    protected $requestAccountId = null;
    /**
     * @var integer Payment status. One of enum values specified in the ThePay API documentation.
     */
    protected $status;
    /**
     * @var integer Unique payment ID in the ThePay system.
     */
    protected $paymentId;
    /**
     * Threat rating of the IP address that sent the payment.
     */
    protected $ipRating;
    /**
<?php

require_once implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'TpUtils.php'));
// …everything else can be loaded using TpUtils::requirePaths.
TpUtils::requirePaths(array(array('helpers', 'TpMerchantHelper.php'), array('TpEscaper.php')));
/**
 * Button helper, that generates simple text button that points to the
 * ThePay page, where rest of the functionality occurs.
 */
class TpButtonMerchantHelper extends TpMerchantHelper
{
    /**
     * Button visual style. If left blank, only simple text link will be
     * created. Otherwise, one of button styles specified in ThePay API
     * documentation can be used.
     */
    protected $buttonStyle = "fullsize";
    /**
     * Button text. This text is displayed if button image cannot be loaded
     * or when simple text style (empty buttonStyle property) is used.
     */
    protected $buttonText = "Donate!";
    /**
     * Sets the buttonStyle property.
     * @param buttonStyle String specifying the button style. Can be empty
     *   for default text button, or one of button styles specified in the
     *   ThePay API documentation.
     * @param buttonText Optional argument specifying the text that should
     *   be displayed on the button.
     */
    function setButtonStyle($buttonStyle, $buttonText = NULL)
<?php

TpUtils::requirePaths(array(array('TpPermanentPaymentResponseMethod.php')));
/**
 *
 * @author Michal Kandr
 */
class TpPermanentPaymentResponse
{
    protected $status;
    protected $errorDescription;
    /** @var TpPermanentPaymentResponseMethod[] */
    protected $paymentMethods = array();
    function __construct(stdClass $data)
    {
        $this->status = $data->status;
        if (property_exists($data, 'errorDescription')) {
            $this->errorDescription = $data->errorDescription;
        }
        if (property_exists($data, 'paymentMethods') && $data->paymentMethods instanceof stdClass && property_exists($data->paymentMethods, 'paymentMethod') && is_array($data->paymentMethods->paymentMethod)) {
            foreach ($data->paymentMethods->paymentMethod as $value) {
                $this->paymentMethods[] = new TpPermanentPaymentResponseMethod($value->methodId, $value->methodName, $value->url, $value->accountNumber, $value->vs);
            }
            unset($value);
        }
    }
    public function getStatus()
    {
        return $this->status;
    }
    public function getErrorDescription()
<?php

TpUtils::requirePaths(array(array('dataApi', 'responses', 'TpDataApiResponse.php'), array('dataApi', 'parameters', 'TpDataApiPaymentInfo.php')));
class TpDataApiGetPaymentInstructionsResponse extends TpDataApiResponse
{
    /**
     * @var TpDataApiPaymentInfo|null
     */
    protected $paymentInfo;
    /**
     * @param array $response
     * @return TpDataApiGetPaymentInstructionsResponse
     */
    public static function createFromResponse(array $response)
    {
        /** @var TpDataApiGetPaymentInstructionsResponse $instance */
        $instance = parent::createFromResponse($response);
        $paymentInfo = new TpDataApiPaymentInfo($response['paymentInfo']);
        $instance->setPaymentInfo($paymentInfo);
        return $instance;
    }
    /**
     * @return TpDataApiPaymentInfo|null
     */
    public function getPaymentInfo()
    {
        return $this->paymentInfo;
    }
    /**
     * @param TpDataApiPaymentInfo|null $paymentInfo
     */
Esempio n. 29
0
<?php

TpUtils::requirePaths(array(array('exceptions', 'TpInvalidArgumentException.php')));
class TpValueFormatter
{
    /**
     * @param string $type
     * @param mixed $value
     * @return mixed
     * @throws TpInvalidArgumentException
     */
    public static function format($type, $value)
    {
        if (substr($type, -2) == '[]') {
            return static::formatList(substr($type, 0, -2), $value);
        }
        $isNull = is_null($value);
        if ($isNull) {
            return null;
        } else {
            $method = "format{$type}";
            // Method names are case-insensitive.
            if (method_exists(__CLASS__, $method)) {
                return static::$method($value);
            }
            if (class_exists($type) && $value instanceof $type) {
                return $value;
            }
            $message = 'Unknown type ' . $type . '.';
            throw new TpInvalidArgumentException($message);
        }