diff --git a/src/DI/ThePayExtension.php b/src/DI/ThePayExtension.php index cacc244..b6a373d 100644 --- a/src/DI/ThePayExtension.php +++ b/src/DI/ThePayExtension.php @@ -44,13 +44,17 @@ public function loadConfiguration() $config = $this->createConfig(); $classesDefinition = [ - 'merchantConfig' => 'Tp\MerchantConfig', - 'payment' => 'Trejjam\ThePay\Payment', - 'returnedPayment' => 'Trejjam\ThePay\ReturnedPayment', + 'merchantConfig' => 'Tp\MerchantConfig', + 'payment' => 'Trejjam\ThePay\Payment', + 'permanentPayment' => 'Trejjam\ThePay\PermanentPayment', + 'returnedPayment' => 'Trejjam\ThePay\ReturnedPayment', + 'helper.radioMerchant' => 'Tp\Helper\RadioMerchant', ]; $factoriesDefinition = [ - 'paymentFactory' => 'Trejjam\ThePay\IPayment', - 'returnedPaymentFactory' => 'Trejjam\ThePay\IReturnedPayment', + 'paymentFactory' => 'Trejjam\ThePay\IPayment', + 'permanentPaymentFactory' => 'Trejjam\ThePay\IPermanentPayment', + 'returnedPaymentFactory' => 'Trejjam\ThePay\IReturnedPayment', + 'helper.radioMerchantFactory' => 'Trejjam\ThePay\Helper\IRadioMerchant', ]; /** @var Nette\DI\ServiceDefinition[] $classes */ diff --git a/src/Helper/IRadioMerchant.php b/src/Helper/IRadioMerchant.php new file mode 100644 index 0000000..cb47783 --- /dev/null +++ b/src/Helper/IRadioMerchant.php @@ -0,0 +1,19 @@ +linkGenerator = $linkGenerator; + } + + public function getMerchantData() + { + if (is_null($this->merchantData)) { + throw new PermanentPaymentException('Property merchantData was not set', PermanentPaymentException::UNDEFINED_PROPERTY); + } + + return parent::getMerchantData(); + } + + public function getDescription() + { + if (is_null($this->description)) { + throw new PermanentPaymentException('Property description was not set', PermanentPaymentException::UNDEFINED_PROPERTY); + } + + return parent::getDescription(); + } + + public function getReturnUrl() + { + if (is_null($this->returnUrl)) { + throw new PermanentPaymentException('Property returnUrl was not set', PermanentPaymentException::UNDEFINED_PROPERTY); + } + + return parent::getReturnUrl(); + } + + public function setReturnUrl($returnUrl, $params = []) + { + if (preg_match('~^([\w:]+):(\w*+)(#.*)?()\z~', $returnUrl)) { + $returnUrl = $this->linkGenerator->link($returnUrl, $params); + } + + parent::setReturnUrl($returnUrl); + } + + public function getSignature() + { + $this->getMerchantData(); + $this->getDescription(); + $this->getReturnUrl(); + + return parent::getSignature(); + } + public function getSignatureLite() + { + $this->getMerchantData(); + + return parent::getSignatureLite(); + } +} diff --git a/src/exceptions.php b/src/exceptions.php index e503b18..2be6327 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -9,3 +9,9 @@ namespace Trejjam\ThePay; use Trejjam; + +class PermanentPaymentException extends \RuntimeException +{ + const + UNDEFINED_PROPERTY = 1; +}