1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Order announce response |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2020 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
|
|
|
* Order announce response |
15
|
|
|
* |
16
|
|
|
* @author Remco Tolsma |
17
|
|
|
* @version 2.2.4 |
18
|
|
|
* @since 2.0.2 |
19
|
|
|
*/ |
20
|
|
|
class OrderAnnounceResponse extends ResponseMessage { |
21
|
|
|
/** |
22
|
|
|
* OmniKassa order ID. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $omnikassa_order_id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Redirect URL. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $redirect_url; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Construct notification message. |
37
|
|
|
* |
38
|
|
|
* @param string $omnikassa_order_id OmniKassa order ID. |
39
|
|
|
* @param string $redirect_url Redirect URL. |
40
|
|
|
*/ |
41
|
1 |
|
public function __construct( $omnikassa_order_id, $redirect_url ) { |
42
|
1 |
|
parent::__construct(); |
43
|
|
|
|
44
|
1 |
|
$this->omnikassa_order_id = $omnikassa_order_id; |
45
|
1 |
|
$this->redirect_url = $redirect_url; |
46
|
1 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get OmniKassa order ID. |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
1 |
|
public function get_omnikassa_order_id() { |
54
|
1 |
|
return $this->omnikassa_order_id; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get redirect URL. |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
1 |
|
public function get_redirect_url() { |
63
|
1 |
|
return $this->redirect_url; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get signature fields. |
68
|
|
|
* |
69
|
|
|
* @return array<string> |
70
|
|
|
*/ |
71
|
|
|
public function get_signature_fields() { |
72
|
|
|
return array(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Create notification from object. |
77
|
|
|
* |
78
|
|
|
* @param object $object Object. |
79
|
|
|
* @return OrderAnnounceResponse |
80
|
|
|
* @throws \InvalidArgumentException Throws invalid argument exception when object does not contains the required properties. |
81
|
|
|
*/ |
82
|
1 |
|
public static function from_object( $object ) { |
83
|
1 |
|
if ( ! isset( $object->omnikassaOrderId ) ) { |
84
|
|
|
throw new \InvalidArgumentException( 'Object must contain `omnikassaOrderId` property.' ); |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
if ( ! isset( $object->redirectUrl ) ) { |
88
|
|
|
throw new \InvalidArgumentException( 'Object must contain `redirectUrl` property.' ); |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
return new self( $object->omnikassaOrderId, $object->redirectUrl ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Create order announce response from JSON string. |
96
|
|
|
* |
97
|
|
|
* @param string $json JSON string. |
98
|
|
|
* @return OrderAnnounceResponse |
99
|
|
|
* @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid. |
100
|
|
|
*/ |
101
|
1 |
|
public static function from_json( $json ) { |
102
|
1 |
|
$data = \json_decode( $json ); |
103
|
|
|
|
104
|
1 |
|
$validator = new \JsonSchema\Validator(); |
105
|
|
|
|
106
|
1 |
|
$validator->validate( |
107
|
1 |
|
$data, |
108
|
|
|
(object) array( |
109
|
1 |
|
'$ref' => 'file://' . \realpath( __DIR__ . '/../json-schemas/order-announce-response.json' ), |
110
|
|
|
), |
111
|
1 |
|
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS |
112
|
|
|
); |
113
|
|
|
|
114
|
1 |
|
return self::from_object( $data ); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|