1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Request |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2018 Pronamic |
7
|
|
|
* @license GPL-3.0-or-later |
8
|
|
|
* @package Pronamic\WordPress\Pay\Payments |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Sisow; |
12
|
|
|
|
13
|
|
|
use Pronamic\WordPress\Pay\Core\Util as Pay_Util; |
14
|
|
|
use Pronamic\WordPress\Pay\Payments\Items; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Title: iDEAL Sisow transaction request |
18
|
|
|
* Description: |
19
|
|
|
* Copyright: Copyright (c) 2015 |
20
|
|
|
* Company: Pronamic |
21
|
|
|
* |
22
|
|
|
* @author Remco Tolsma |
23
|
|
|
* @version 2.0.0 |
24
|
|
|
* @since 1.0.0 |
25
|
|
|
*/ |
26
|
|
|
class Request { |
27
|
|
|
/** |
28
|
|
|
* Parameters. |
29
|
|
|
* |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private $parameters = array(); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Construct request. |
36
|
|
|
* |
37
|
|
|
* @param string $merchant_id Merchant ID. |
38
|
|
|
* @param string|null $shop_id Shop ID. |
39
|
|
|
*/ |
40
|
2 |
|
public function __construct( $merchant_id, $shop_id = null ) { |
41
|
2 |
|
$this->set_parameter( 'merchantid', $merchant_id ); |
42
|
2 |
|
$this->set_parameter( 'shopid', $shop_id ); |
43
|
2 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get parameter. |
47
|
|
|
* |
48
|
|
|
* @param string $parameter Parameter. |
49
|
|
|
* @return string|null |
50
|
|
|
*/ |
51
|
2 |
|
public function get_parameter( $parameter ) { |
52
|
2 |
|
if ( isset( $this->parameters[ $parameter ] ) ) { |
53
|
2 |
|
return $this->parameters[ $parameter ]; |
54
|
|
|
} |
55
|
|
|
|
56
|
2 |
|
return null; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Set parameter. |
61
|
|
|
* |
62
|
|
|
* @param string $parameter Parameter. |
63
|
|
|
* @param string|null $value Value. |
64
|
|
|
*/ |
65
|
2 |
|
public function set_parameter( $parameter, $value ) { |
66
|
2 |
|
$this->parameters[ $parameter ] = $value; |
67
|
2 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get parameters. |
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function get_parameters() { |
75
|
|
|
return $this->parameters; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Merge parameters. |
80
|
|
|
* |
81
|
|
|
* @param array $parameters Parameters. |
82
|
|
|
*/ |
83
|
|
|
public function merge_parameters( $parameters ) { |
84
|
|
|
$this->parameters = array_merge( $this->parameters, $parameters ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get signature data. |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public function get_signature_data() { |
93
|
|
|
return array(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get signature. |
98
|
|
|
* |
99
|
|
|
* @param string $merchant_key Merchant key. |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
2 |
|
public function get_signature( $merchant_key ) { |
103
|
2 |
|
$data = $this->get_signature_data(); |
104
|
|
|
|
105
|
2 |
|
$data[] = $merchant_key; |
106
|
|
|
|
107
|
2 |
|
$string = implode( '', $data ); |
108
|
|
|
|
109
|
2 |
|
$signature = sha1( $string ); |
110
|
|
|
|
111
|
2 |
|
return $signature; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Sign this request with the specified merchant key. |
116
|
|
|
* |
117
|
|
|
* @param string $merchant_key Merchant key. |
118
|
|
|
*/ |
119
|
|
|
public function sign( $merchant_key ) { |
120
|
|
|
$signature = $this->get_signature( $merchant_key ); |
121
|
|
|
|
122
|
|
|
$this->set_parameter( 'sha1', $signature ); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|