|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Return parameters |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2022 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Pay\Gateways\OmniKassa2 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Return parameters |
|
15
|
|
|
* |
|
16
|
|
|
* @author Remco Tolsma |
|
17
|
|
|
* @version 2.1.8 |
|
18
|
|
|
* @since 2.0.2 |
|
19
|
|
|
*/ |
|
20
|
|
|
class ReturnParameters extends ResponseMessage { |
|
21
|
|
|
/** |
|
22
|
|
|
* The "merchantOrderId" as used in the Order announce. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
private $order_id; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The status of the order, see below for more details. |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $status; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Construct return parameters object. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $order_id Order ID. |
|
39
|
|
|
* @param string $status Status. |
|
40
|
|
|
* @param string $signature Signature. |
|
41
|
|
|
*/ |
|
42
|
2 |
|
public function __construct( $order_id, $status, $signature ) { |
|
43
|
2 |
|
parent::__construct( $signature ); |
|
44
|
|
|
|
|
45
|
2 |
|
$this->order_id = $order_id; |
|
46
|
2 |
|
$this->status = $status; |
|
47
|
2 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get order ID. |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
2 |
|
public function get_order_id() { |
|
55
|
2 |
|
return $this->order_id; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Get status. |
|
60
|
|
|
* |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
2 |
|
public function get_status() { |
|
64
|
2 |
|
return $this->status; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get signature data. |
|
69
|
|
|
* |
|
70
|
|
|
* The signature is calculated in the same way as other signatures. In this case, the two fields (in order: order_id, status) are used as input. |
|
71
|
|
|
* |
|
72
|
|
|
* @return array<string> |
|
73
|
|
|
*/ |
|
74
|
2 |
|
public function get_signature_fields() { |
|
75
|
|
|
return array( |
|
76
|
2 |
|
$this->get_order_id(), |
|
77
|
2 |
|
$this->get_status(), |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Check if data array contains return parameters. |
|
83
|
|
|
* |
|
84
|
|
|
* @param array<string> $data Data array. |
|
85
|
|
|
* @return bool True if array contains return parameters, false otherwise. |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public static function contains( array $data ) { |
|
88
|
|
|
$result = ( |
|
89
|
1 |
|
\array_key_exists( 'order_id', $data ) |
|
90
|
|
|
&& |
|
91
|
1 |
|
\array_key_exists( 'status', $data ) |
|
92
|
|
|
&& |
|
93
|
1 |
|
\array_key_exists( 'signature', $data ) |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
1 |
|
return $result; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Get return parameters from the specified data array. |
|
101
|
|
|
* |
|
102
|
|
|
* @param array<string> $data Data array. |
|
103
|
|
|
* @return ReturnParameters |
|
104
|
|
|
* @throws \InvalidArgumentException Throws invalid argument exception when array does not contains the required keys. |
|
105
|
|
|
*/ |
|
106
|
2 |
|
public static function from_array( array $data ) { |
|
107
|
2 |
|
if ( ! \array_key_exists( 'order_id', $data ) ) { |
|
108
|
|
|
throw new \InvalidArgumentException( 'Data array must contain `order_id` field.' ); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
2 |
|
if ( ! \array_key_exists( 'status', $data ) ) { |
|
112
|
|
|
throw new \InvalidArgumentException( 'Data array must contain `status` field.' ); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
2 |
|
if ( ! \array_key_exists( 'signature', $data ) ) { |
|
116
|
|
|
throw new \InvalidArgumentException( 'Data array must contain `signature` field.' ); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
2 |
|
return new self( $data['order_id'], $data['status'], $data['signature'] ); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|