Skip to content

Commit

Permalink
Add PermanentPayment
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Aug 20, 2015
1 parent d8f3950 commit dc8a63a
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/DI/ThePayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
19 changes: 19 additions & 0 deletions src/Helper/IRadioMerchant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: jam
* Date: 20.8.15
* Time: 17:24
*/

namespace Trejjam\ThePay\Helper;

use Tp;

interface IRadioMerchant
{
/**
* @return Tp\Helper\RadioMerchant
*/
function create();
}
18 changes: 18 additions & 0 deletions src/IPermanentPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: jam
* Date: 20.8.15
* Time: 11:48
*/

namespace Trejjam\ThePay;


interface IPermanentPayment
{
/**
* @return PermanentPayment
*/
function create();
}
80 changes: 80 additions & 0 deletions src/PermanentPayment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Created by PhpStorm.
* User: jam
* Date: 20.8.15
* Time: 11:16
*/

namespace Trejjam\ThePay;


use Nette,
Tp,
Trejjam;

class PermanentPayment extends Tp\PermanentPayment
{
/**
* @var Nette\Application\LinkGenerator
*/
protected $linkGenerator;

public function __construct(Tp\MerchantConfig $config, Nette\Application\LinkGenerator $linkGenerator)
{
parent::__construct($config, NULL, NULL, NULL);

$this->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();
}
}
6 changes: 6 additions & 0 deletions src/exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
namespace Trejjam\ThePay;

use Trejjam;

class PermanentPaymentException extends \RuntimeException
{
const
UNDEFINED_PROPERTY = 1;
}

0 comments on commit dc8a63a

Please sign in to comment.