Skip to content

Commit dc8a63a

Browse files
committed
Add PermanentPayment
1 parent d8f3950 commit dc8a63a

5 files changed

+132
-5
lines changed

src/DI/ThePayExtension.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ public function loadConfiguration()
4444
$config = $this->createConfig();
4545

4646
$classesDefinition = [
47-
'merchantConfig' => 'Tp\MerchantConfig',
48-
'payment' => 'Trejjam\ThePay\Payment',
49-
'returnedPayment' => 'Trejjam\ThePay\ReturnedPayment',
47+
'merchantConfig' => 'Tp\MerchantConfig',
48+
'payment' => 'Trejjam\ThePay\Payment',
49+
'permanentPayment' => 'Trejjam\ThePay\PermanentPayment',
50+
'returnedPayment' => 'Trejjam\ThePay\ReturnedPayment',
51+
'helper.radioMerchant' => 'Tp\Helper\RadioMerchant',
5052
];
5153
$factoriesDefinition = [
52-
'paymentFactory' => 'Trejjam\ThePay\IPayment',
53-
'returnedPaymentFactory' => 'Trejjam\ThePay\IReturnedPayment',
54+
'paymentFactory' => 'Trejjam\ThePay\IPayment',
55+
'permanentPaymentFactory' => 'Trejjam\ThePay\IPermanentPayment',
56+
'returnedPaymentFactory' => 'Trejjam\ThePay\IReturnedPayment',
57+
'helper.radioMerchantFactory' => 'Trejjam\ThePay\Helper\IRadioMerchant',
5458
];
5559

5660
/** @var Nette\DI\ServiceDefinition[] $classes */

src/Helper/IRadioMerchant.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: jam
5+
* Date: 20.8.15
6+
* Time: 17:24
7+
*/
8+
9+
namespace Trejjam\ThePay\Helper;
10+
11+
use Tp;
12+
13+
interface IRadioMerchant
14+
{
15+
/**
16+
* @return Tp\Helper\RadioMerchant
17+
*/
18+
function create();
19+
}

src/IPermanentPayment.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: jam
5+
* Date: 20.8.15
6+
* Time: 11:48
7+
*/
8+
9+
namespace Trejjam\ThePay;
10+
11+
12+
interface IPermanentPayment
13+
{
14+
/**
15+
* @return PermanentPayment
16+
*/
17+
function create();
18+
}

src/PermanentPayment.php

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: jam
5+
* Date: 20.8.15
6+
* Time: 11:16
7+
*/
8+
9+
namespace Trejjam\ThePay;
10+
11+
12+
use Nette,
13+
Tp,
14+
Trejjam;
15+
16+
class PermanentPayment extends Tp\PermanentPayment
17+
{
18+
/**
19+
* @var Nette\Application\LinkGenerator
20+
*/
21+
protected $linkGenerator;
22+
23+
public function __construct(Tp\MerchantConfig $config, Nette\Application\LinkGenerator $linkGenerator)
24+
{
25+
parent::__construct($config, NULL, NULL, NULL);
26+
27+
$this->linkGenerator = $linkGenerator;
28+
}
29+
30+
public function getMerchantData()
31+
{
32+
if (is_null($this->merchantData)) {
33+
throw new PermanentPaymentException('Property merchantData was not set', PermanentPaymentException::UNDEFINED_PROPERTY);
34+
}
35+
36+
return parent::getMerchantData();
37+
}
38+
39+
public function getDescription()
40+
{
41+
if (is_null($this->description)) {
42+
throw new PermanentPaymentException('Property description was not set', PermanentPaymentException::UNDEFINED_PROPERTY);
43+
}
44+
45+
return parent::getDescription();
46+
}
47+
48+
public function getReturnUrl()
49+
{
50+
if (is_null($this->returnUrl)) {
51+
throw new PermanentPaymentException('Property returnUrl was not set', PermanentPaymentException::UNDEFINED_PROPERTY);
52+
}
53+
54+
return parent::getReturnUrl();
55+
}
56+
57+
public function setReturnUrl($returnUrl, $params = [])
58+
{
59+
if (preg_match('~^([\w:]+):(\w*+)(#.*)?()\z~', $returnUrl)) {
60+
$returnUrl = $this->linkGenerator->link($returnUrl, $params);
61+
}
62+
63+
parent::setReturnUrl($returnUrl);
64+
}
65+
66+
public function getSignature()
67+
{
68+
$this->getMerchantData();
69+
$this->getDescription();
70+
$this->getReturnUrl();
71+
72+
return parent::getSignature();
73+
}
74+
public function getSignatureLite()
75+
{
76+
$this->getMerchantData();
77+
78+
return parent::getSignatureLite();
79+
}
80+
}

src/exceptions.php

+6
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
namespace Trejjam\ThePay;
1010

1111
use Trejjam;
12+
13+
class PermanentPaymentException extends \RuntimeException
14+
{
15+
const
16+
UNDEFINED_PROPERTY = 1;
17+
}

0 commit comments

Comments
 (0)