1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PaySys\TatraPay; |
4
|
|
|
|
5
|
|
|
use Nette; |
6
|
|
|
use Nette\Application\LinkGenerator; |
7
|
|
|
use Nette\Utils\Strings; |
8
|
|
|
use PaySys\PaySys\IConfiguration; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @method string getMid() |
13
|
|
|
* @method string getRurl() |
14
|
|
|
* @method string getKey() |
15
|
|
|
* @method string getIpc() |
16
|
|
|
* @method string getLang() |
17
|
|
|
* @method string getMode() |
18
|
|
|
* @method string getRem() |
19
|
|
|
*/ |
20
|
1 |
|
final class Configuration implements IConfiguration |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
private $mid; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
private $rurl; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
private $lang = 'sk'; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
private $key; |
34
|
|
|
|
35
|
|
|
/** @var string */ |
36
|
|
|
private $rem = ''; |
37
|
|
|
|
38
|
|
|
/** @var LinkGenerator */ |
39
|
|
|
private $linkGenerator; |
40
|
|
|
|
41
|
|
|
/** @var string */ |
42
|
|
|
private $buttonTemplate; |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
public function __construct(string $mid, $rurl, string $key, LinkGenerator $linkGenerator = NULL) |
46
|
|
|
{ |
47
|
1 |
|
$this->linkGenerator = $linkGenerator; |
48
|
1 |
|
$this->setMid($mid); |
49
|
1 |
|
$this->setRurl($rurl); |
50
|
1 |
|
$this->setKey($key); |
51
|
1 |
|
$this->setButtonTemplate(__DIR__ . '/template/button.latte'); |
52
|
1 |
|
} |
53
|
|
|
|
54
|
|
|
public function setMid(string $mid) : Configuration |
55
|
|
|
{ |
56
|
1 |
|
if (!Validator::isMid($mid)) |
57
|
1 |
|
throw new \PaySys\PaySys\ConfigurationException(sprintf("Parameter MID must have 3 or 4 characters. '%s' is invalid.", $mid)); |
58
|
|
|
|
59
|
1 |
|
$this->mid = $mid; |
60
|
1 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setRurl($originalRurl) : Configuration |
64
|
|
|
{ |
65
|
1 |
|
$supportedTypes = ['string', 'array']; |
66
|
1 |
|
if (!in_array(gettype($originalRurl), $supportedTypes)) |
67
|
1 |
|
throw new \PaySys\PaySys\ConfigurationException(sprintf("RURL type of '%s' is invalid. Must be %s.", gettype($originalRurl), implode(' or ', $supportedTypes))); |
68
|
|
|
|
69
|
1 |
|
$rurl = $originalRurl; |
70
|
1 |
|
if ($this->linkGenerator instanceof LinkGenerator) { |
|
|
|
|
71
|
|
|
try { |
72
|
1 |
|
if (is_string($originalRurl)) { |
73
|
1 |
|
$rurl = $this->linkGenerator->link($originalRurl); |
74
|
|
|
} elseif (is_array($originalRurl)) { |
75
|
1 |
|
$rurl = $this->linkGenerator->link($originalRurl['dest'], @$originalRurl['params']); |
76
|
|
|
} |
77
|
1 |
|
} catch (Nette\Application\UI\InvalidLinkException $e) {} |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
if (!Validator::isRurl($rurl)) |
81
|
1 |
|
throw new \PaySys\PaySys\ConfigurationException(sprintf("RURL '%s' is invalid. Must be valid URL by RFC 1738.", $originalRurl)); |
82
|
|
|
|
83
|
1 |
|
$this->rurl = $rurl; |
84
|
1 |
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
View Code Duplication |
public function setKey(string $originalKey) : Configuration |
|
|
|
|
88
|
|
|
{ |
89
|
1 |
|
$key = $this->getNormalizedKey($originalKey); |
90
|
1 |
|
if (!Validator::isKey($key)) |
91
|
|
|
throw new \PaySys\PaySys\ConfigurationException(sprintf("Key '%s' is invalid. Must have 64 byte standard string or 128 byte in hexadecimal format.", $originalKey)); |
92
|
|
|
|
93
|
1 |
|
$this->key = $key; |
94
|
1 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
View Code Duplication |
public function setLang(string $originalLang) : Configuration |
|
|
|
|
98
|
|
|
{ |
99
|
1 |
|
$lang = strtolower($originalLang); |
100
|
1 |
|
if (!Validator::isLang($lang)) |
101
|
1 |
|
throw new \PaySys\PaySys\ConfigurationException(sprintf("Lang '%s' is not supported.", $originalLang)); |
102
|
|
|
|
103
|
1 |
|
$this->lang = $lang; |
104
|
1 |
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function setRem(string $rem) : Configuration |
108
|
|
|
{ |
109
|
|
|
if (!Nette\Utils\Validators::isEmail($rem)) |
110
|
|
|
throw new \PaySys\PaySys\ConfigurationException(sprintf("'%s' is not valid e-mail.", $rem)); |
111
|
|
|
|
112
|
|
|
$this->rem = $rem; |
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function setButtonTemplate(string $path) : Configuration |
117
|
|
|
{ |
118
|
1 |
|
if (!file_exists($path)) |
119
|
1 |
|
throw new \PaySys\PaySys\ConfigurationException(sprintf("Template file '%s' not exists.", $path)); |
120
|
|
|
|
121
|
1 |
|
$this->buttonTemplate = $path; |
122
|
1 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getButtonTemplate() : string |
126
|
|
|
{ |
127
|
1 |
|
return $this->buttonTemplate; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function __call($method, $arguments) : string |
131
|
|
|
{ |
132
|
1 |
|
return $this->{strtolower(substr($method, 3))}; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
private function getNormalizedKey(string $originalKey) : string |
136
|
|
|
{ |
137
|
1 |
|
if (strlen($originalKey) === 128 OR strlen($originalKey) === 191) { |
|
|
|
|
138
|
1 |
|
if (strlen($originalKey) === 191) { |
139
|
1 |
|
$key = str_replace(':', '', $originalKey); |
140
|
|
|
} else { |
141
|
1 |
|
$key = $originalKey; |
142
|
|
|
} |
143
|
|
|
|
144
|
1 |
|
if (strlen($key) === 128) |
145
|
1 |
|
return pack("H*", $key); |
146
|
|
|
} |
147
|
1 |
|
return $originalKey; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.