1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PaySys\CardPay\Security; |
4
|
|
|
|
5
|
|
|
use Nette\Http\Url; |
6
|
|
|
use PaySys\CardPay\Configuration; |
7
|
|
|
use PaySys\CardPay\Payment; |
8
|
|
|
|
9
|
|
|
|
10
|
1 |
|
final class Request |
11
|
|
|
{ |
12
|
|
|
const SERVER_TEST = "https://moja.tatrabanka.sk/cgi-bin/e-commerce/start/example"; |
13
|
|
|
const SERVER_PRODUCTION = "https://moja.tatrabanka.sk/cgi-bin/e-commerce/start/cardpay"; |
14
|
|
|
|
15
|
|
|
/** @var Configuration */ |
16
|
|
|
protected $config; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
public function __construct(Configuration $config) |
20
|
|
|
{ |
21
|
1 |
|
$this->config = $config; |
22
|
1 |
|
} |
23
|
|
|
|
24
|
|
|
public function getUrl(Payment $payment) : Url |
25
|
|
|
{ |
26
|
1 |
|
$s = $this->getSign($payment); |
|
|
|
|
27
|
1 |
|
$url = new Url(constant("self::SERVER_" . strtoupper($this->config->getMode()))); |
28
|
1 |
|
$url->appendQuery('MID=' . $this->config->getMid()) |
29
|
1 |
|
->appendQuery('AMT=' . $payment->getAmount()) |
30
|
1 |
|
->appendQuery('CURR=' . $payment->getCurrency()) |
31
|
1 |
|
->appendQuery('VS=' . $payment->getVariableSymbol()) |
32
|
1 |
|
->appendQuery('RURL=' . $this->config->getRurl()) |
33
|
1 |
|
->appendQuery('IPC=' . $this->config->getIpc()) |
34
|
1 |
|
->appendQuery('NAME=' . $payment->getName()); |
35
|
1 |
|
if ($payment->getTpay()) { |
36
|
|
|
$url->appendQuery('TPAY=Y'); |
37
|
|
|
} |
38
|
1 |
|
$url->appendQuery('TIMESTAMP=' . $payment->getTimestamp()) |
39
|
1 |
|
->appendQuery('HMAC=' . $this->getSign($payment)); |
40
|
1 |
|
return $url; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getSign(Payment $payment) : string |
44
|
|
|
{ |
45
|
1 |
|
return hash_hmac("sha256", $this->getSignString($payment), $this->config->getKey()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getSignString(Payment $payment) : string |
49
|
|
|
{ |
50
|
1 |
|
$s = $this->config->getMid() |
51
|
1 |
|
. $payment->getAmount() |
52
|
1 |
|
. $payment->getCurrency() |
53
|
1 |
|
. $payment->getVariableSymbol() |
54
|
1 |
|
. $this->config->getRurl() |
55
|
1 |
|
. $this->config->getIpc() |
56
|
1 |
|
. $payment->getName(); |
57
|
1 |
|
if ($payment->getTpay()) { |
58
|
|
|
$s .= 'Y'; |
59
|
|
|
} |
60
|
1 |
|
$s .= $this->config->getRem() |
61
|
1 |
|
. $payment->getTimestamp(); |
62
|
1 |
|
return $s; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
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.