|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Notification request item |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2019 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Pay\Gateways\Adyen |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Adyen; |
|
12
|
|
|
|
|
13
|
|
|
use DateTime; |
|
14
|
|
|
use JsonSchema\Constraints\Constraint; |
|
15
|
|
|
use JsonSchema\Exception\ValidationException; |
|
16
|
|
|
use JsonSchema\Validator; |
|
17
|
|
|
use Pronamic\WordPress\Pay\Core\Util; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Notification request item |
|
21
|
|
|
* |
|
22
|
|
|
* @link https://docs.adyen.com/developers/api-reference/notifications-api#notificationrequestitem |
|
23
|
|
|
* |
|
24
|
|
|
* @author Remco Tolsma |
|
25
|
|
|
* @version 1.0.0 |
|
26
|
|
|
* @since 1.0.0 |
|
27
|
|
|
*/ |
|
28
|
|
|
class NotificationRequestItem extends ResponseObject { |
|
29
|
|
|
/** |
|
30
|
|
|
* Amount. |
|
31
|
|
|
* |
|
32
|
|
|
* @var Amount |
|
33
|
|
|
*/ |
|
34
|
|
|
private $amount; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Adyen's 16-character unique reference associated with the transaction/the request. This value is globally unique; quote it when communicating with us about this request. |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private $psp_reference; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The type of event the notification item refers to. |
|
45
|
|
|
* |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
private $event_code; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* The time when the event was generated. |
|
52
|
|
|
* |
|
53
|
|
|
* @var DateTime |
|
54
|
|
|
*/ |
|
55
|
|
|
private $event_date; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* The merchant account identifier used in the transaction the notification item refers to. |
|
59
|
|
|
* |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
private $merchant_account_code; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* This field holds a list of the modification operations supported by the transaction the notification item refers to. |
|
66
|
|
|
* |
|
67
|
|
|
* @var array |
|
68
|
|
|
*/ |
|
69
|
|
|
private $operations; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* A reference to uniquely identify the payment. |
|
73
|
|
|
* |
|
74
|
|
|
* @var string |
|
75
|
|
|
*/ |
|
76
|
|
|
private $merchant_reference; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* The payment method used in the transaction the notification item refers to. |
|
80
|
|
|
* |
|
81
|
|
|
* @var string |
|
82
|
|
|
*/ |
|
83
|
|
|
private $payment_method; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Informs about the outcome of the event (`eventCode`) the notification refers to: |
|
87
|
|
|
* |
|
88
|
|
|
* - `true`: the event (`eventCode`) the notification refers to was executed successfully. |
|
89
|
|
|
* - `false`: the event was not executed successfully. |
|
90
|
|
|
* |
|
91
|
|
|
* @var boolean |
|
92
|
|
|
*/ |
|
93
|
|
|
private $success; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Construct notification request item. |
|
97
|
|
|
* |
|
98
|
|
|
* @link https://stackoverflow.com/questions/34468660/how-to-use-builder-pattern-with-all-parameters-as-mandatory |
|
99
|
|
|
* |
|
100
|
|
|
* @param Amount $amount Amount. |
|
101
|
|
|
* @param string $psp_reference PSP reference. |
|
102
|
|
|
* @param string $event_code Event code. |
|
103
|
|
|
* @param DateTime $event_date Event date. |
|
104
|
|
|
* @param string $merchant_account_code Merchant account code. |
|
105
|
|
|
* @param array $operations Operations. |
|
106
|
|
|
* @param string $merchant_reference Merchant reference. |
|
107
|
|
|
* @param string $payment_method Payment method. |
|
108
|
|
|
* @param boolean $success Success. |
|
109
|
|
|
*/ |
|
110
|
4 |
|
public function __construct( |
|
111
|
|
|
Amount $amount, |
|
112
|
|
|
$psp_reference, |
|
113
|
|
|
$event_code, |
|
114
|
|
|
DateTime $event_date, |
|
115
|
|
|
$merchant_account_code, |
|
116
|
|
|
array $operations, |
|
117
|
|
|
$merchant_reference, |
|
118
|
|
|
$payment_method, |
|
119
|
|
|
$success |
|
120
|
|
|
) { |
|
121
|
4 |
|
$this->amount = $amount; |
|
122
|
4 |
|
$this->psp_reference = $psp_reference; |
|
123
|
4 |
|
$this->event_code = $event_code; |
|
124
|
4 |
|
$this->event_date = $event_date; |
|
125
|
4 |
|
$this->merchant_account_code = $merchant_account_code; |
|
126
|
4 |
|
$this->operations = $operations; |
|
127
|
4 |
|
$this->merchant_reference = $merchant_reference; |
|
128
|
4 |
|
$this->payment_method = $payment_method; |
|
129
|
4 |
|
$this->success = $success; |
|
130
|
4 |
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Get amount. |
|
134
|
|
|
* |
|
135
|
|
|
* @return Amount |
|
136
|
|
|
*/ |
|
137
|
|
|
public function get_amount() { |
|
138
|
|
|
return $this->amount; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Get PSP reference. |
|
143
|
|
|
* |
|
144
|
|
|
* @return string |
|
145
|
|
|
*/ |
|
146
|
1 |
|
public function get_psp_reference() { |
|
147
|
1 |
|
return $this->psp_reference; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Get event code. |
|
152
|
|
|
* |
|
153
|
|
|
* @return string |
|
154
|
|
|
*/ |
|
155
|
2 |
|
public function get_event_code() { |
|
156
|
2 |
|
return $this->event_code; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Get event date. |
|
161
|
|
|
* |
|
162
|
|
|
* @return DateTime |
|
163
|
|
|
*/ |
|
164
|
1 |
|
public function get_event_date() { |
|
165
|
1 |
|
return $this->event_date; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Get merchant account code. |
|
170
|
|
|
* |
|
171
|
|
|
* @return string |
|
172
|
|
|
*/ |
|
173
|
1 |
|
public function get_merchant_account_code() { |
|
174
|
1 |
|
return $this->merchant_account_code; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Get operations. |
|
179
|
|
|
* |
|
180
|
|
|
* @return array |
|
181
|
|
|
*/ |
|
182
|
1 |
|
public function get_operations() { |
|
183
|
1 |
|
return $this->operations; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Get operations. |
|
188
|
|
|
* |
|
189
|
|
|
* @return string |
|
190
|
|
|
*/ |
|
191
|
4 |
|
public function get_merchant_reference() { |
|
192
|
4 |
|
return $this->merchant_reference; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Get payment method. |
|
197
|
|
|
* |
|
198
|
|
|
* @return string |
|
199
|
|
|
*/ |
|
200
|
1 |
|
public function get_payment_method() { |
|
201
|
1 |
|
return $this->payment_method; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Is success. |
|
206
|
|
|
* |
|
207
|
|
|
* @return boolean |
|
208
|
|
|
*/ |
|
209
|
2 |
|
public function is_success() { |
|
210
|
2 |
|
return $this->success; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Create notification request item from object. |
|
215
|
|
|
* |
|
216
|
|
|
* @param object $object Object. |
|
217
|
|
|
* @return NotificationRequestItem |
|
218
|
|
|
* @throws ValidationException Throws JSON schema validation exception when JSON is invalid. |
|
219
|
|
|
*/ |
|
220
|
5 |
|
public static function from_object( $object ) { |
|
221
|
5 |
|
$validator = new Validator(); |
|
222
|
|
|
|
|
223
|
5 |
|
$validator->validate( |
|
224
|
5 |
|
$object, |
|
225
|
|
|
(object) array( |
|
226
|
5 |
|
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/notification-request-item.json' ), |
|
227
|
|
|
), |
|
228
|
5 |
|
Constraint::CHECK_MODE_EXCEPTIONS |
|
229
|
|
|
); |
|
230
|
|
|
|
|
231
|
4 |
|
$item = new self( |
|
232
|
4 |
|
Amount::from_object( $object->amount ), |
|
233
|
4 |
|
$object->pspReference, |
|
234
|
4 |
|
$object->eventCode, |
|
235
|
4 |
|
new DateTime( $object->eventDate ), |
|
236
|
4 |
|
$object->merchantAccountCode, |
|
237
|
4 |
|
$object->operations, |
|
238
|
4 |
|
$object->merchantReference, |
|
239
|
4 |
|
$object->paymentMethod, |
|
240
|
4 |
|
filter_var( $object->success, FILTER_VALIDATE_BOOLEAN ) |
|
241
|
|
|
); |
|
242
|
|
|
|
|
243
|
4 |
|
$item->set_original_object( $object ); |
|
244
|
|
|
|
|
245
|
4 |
|
return $item; |
|
246
|
|
|
} |
|
247
|
|
|
} |
|
248
|
|
|
|