/
Payment.php
97 lines (77 loc) · 1.88 KB
/
Payment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Created by PhpStorm.
* User: jam
* Date: 20.8.15
* Time: 11:16
*/
namespace Trejjam\ThePay;
use Nette,
Tp,
Trejjam;
class Payment extends Tp\Payment
{
/**
* @var Nette\Application\LinkGenerator
*/
protected $linkGenerator;
public function __construct(MerchantConfig $config = NULL, Nette\Application\LinkGenerator $linkGenerator)
{
parent::__construct($config);
$this->linkGenerator = $linkGenerator;
}
public function setReturnUrl($returnUrl, $params = [])
{
if (preg_match('~^([\w:]+):(\w*+)(#.*)?()\z~', $returnUrl)) {
$returnUrl = $this->linkGenerator->link($returnUrl, $params);
}
parent::setReturnUrl($returnUrl);
}
/**
* @param string|null $backToEshopUrl
* @param array $params
*
* @throws Nette\Application\UI\InvalidLinkException
*/
public function setBackToEshopUrl($backToEshopUrl = NULL, $params = [])
{
if ($backToEshopUrl !== NULL && preg_match('~^([\w:]+):(\w*+)(#.*)?()\z~', $backToEshopUrl)) {
$backToEshopUrl = $this->linkGenerator->link($backToEshopUrl, $params);
}
parent::setBackToEshopUrl($backToEshopUrl);
}
public function getArgs()
{
$args = parent::getArgs();
foreach ($args as &$arg) {
if (is_float($arg) || is_double($arg)) {
$arg = str_replace(',', '.', (string)$arg);
}
}
return $args;
}
public function getRedirectUrl()
{
$queryArgs = $this->getArgs();
$queryArgs['signature'] = $this->getSignature();
return $this->getMerchantConfig()->gateUrl . '?' . http_build_query($queryArgs);
}
public function redirectOnlinePayment(Nette\Application\UI\Presenter $presenter)
{
$presenter->redirectUrl($this->getRedirectUrl());
}
public function __debugInfo()
{
$out = [];
foreach ($this->__sleep() as $v) {
$out[$v] = $this->$v;
}
return $out;
}
public function __sleep()
{
return array_diff(array_keys(get_object_vars($this)), [
'linkGenerator',
]);
}
}