1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PaySys\TatraPay\Security; |
4
|
|
|
|
5
|
|
|
use Nette\Http\Url; |
6
|
|
|
use PaySys\TatraPay\Configuration; |
7
|
|
|
use PaySys\TatraPay\Payment; |
8
|
|
|
|
9
|
|
|
|
10
|
1 |
|
final class Request |
11
|
|
|
{ |
12
|
|
|
const SERVER = "https://moja.tatrabanka.sk/cgi-bin/e-commerce/start/tatrapay"; |
13
|
|
|
|
14
|
|
|
/** @var Configuration */ |
15
|
|
|
protected $config; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
public function __construct(Configuration $config) |
19
|
|
|
{ |
20
|
1 |
|
$this->config = $config; |
21
|
1 |
|
} |
22
|
|
|
|
23
|
|
|
public function getUrl(Payment $payment) : Url |
24
|
|
|
{ |
25
|
1 |
|
$s = $this->getSign($payment); |
|
|
|
|
26
|
1 |
|
$url = new Url(self::SERVER); |
27
|
1 |
|
$url->appendQuery('MID=' . $this->config->getMid()) |
28
|
1 |
|
->appendQuery('AMT=' . $payment->getAmount()) |
29
|
1 |
|
->appendQuery('CURR=' . $payment->getCurrency()) |
30
|
1 |
|
->appendQuery('VS=' . $payment->getVariableSymbol()) |
31
|
1 |
|
->appendQuery('RURL=' . $this->config->getRurl()); |
32
|
1 |
|
if (!empty($this->config->getRem())) |
33
|
|
|
$url->appendQuery('REM=' . $this->config->getRem()); |
34
|
1 |
|
$url->appendQuery('TIMESTAMP=' . $payment->getTimestamp()) |
35
|
1 |
|
->appendQuery('HMAC=' . $this->getSign($payment)); |
36
|
1 |
|
return $url; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getSign(Payment $payment) : string |
40
|
|
|
{ |
41
|
1 |
|
return hash_hmac("sha256", $this->getSignString($payment), $this->config->getKey()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getSignString(Payment $payment) : string |
45
|
|
|
{ |
46
|
1 |
|
return $this->config->getMid() |
47
|
1 |
|
. $payment->getAmount() |
48
|
1 |
|
. $payment->getCurrency() |
49
|
1 |
|
. $payment->getVariableSymbol() |
50
|
1 |
|
. $this->config->getRurl() |
51
|
1 |
|
. $this->config->getRem() |
52
|
1 |
|
. $payment->getTimestamp(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.