-
Notifications
You must be signed in to change notification settings - Fork 4
/
Signer.php
57 lines (54 loc) · 1.35 KB
/
Signer.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
<?php
namespace Dfe\IPay88;
/**
* 2017-04-10
* @see \Dfe\IPay88\Signer\Request
* @see \Dfe\IPay88\Signer\Response
* @method Settings s()
*/
abstract class Signer extends \Df\PaypalClone\Signer {
/**
* 2017-04-10
* @used-by sign()
* @see \Dfe\IPay88\Signer\Request::values()
* @see \Dfe\IPay88\Signer\Response::values()
* @return string[]
*/
abstract protected function values();
/**
* 2017-04-10
* @override
* @see \Df\PaypalClone\Signer::adjust()
* @used-by \Df\PaypalClone\Signer::_sign()
* @see \Dfe\IPay88\Signer::adjust()
* @param array(string => mixed) $v
* @return array(string => mixed)
*/
final protected function adjust(array $v) {return
['Amount' => df_string_clean($v['Amount'], '.', ',')] + $v
;}
/**
* 2017-04-10
* @override
* @see \Df\PaypalClone\Signer::sign()
* @used-by \Df\PaypalClone\Signer::_sign()
* @return string
*/
final protected function sign() {return base64_encode(self::hex2bin(sha1(df_cc('',
$this->s()->privateKey(), $this->v('MerchantCode'), $this->values()
))));}
/**
* 2017-04-10
* @used-by sign()
* @param string $s
* @return string
*/
private static function hex2bin($s) {
/** @var string $result */
$result = '';
for ($i = 0; $i < strlen($s); $i += 2) {
$result .= chr(hexdec(substr($s, $i, 2)));
}
return $result;
}
}