1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Abstract payment request |
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 InvalidArgumentException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Abstract payment request |
18
|
|
|
* |
19
|
|
|
* @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/payments |
20
|
|
|
* @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/paymentSession |
21
|
|
|
* |
22
|
|
|
* @author Remco Tolsma |
23
|
|
|
* @version 1.0.5 |
24
|
|
|
* @since 1.0.0 |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractPaymentRequest extends Request { |
27
|
|
|
/** |
28
|
|
|
* Amount. |
29
|
|
|
* |
30
|
|
|
* @var Amount |
31
|
|
|
*/ |
32
|
|
|
private $amount; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Billing address. |
36
|
|
|
* |
37
|
|
|
* @var Address|null |
38
|
|
|
*/ |
39
|
|
|
private $billing_address; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Channel. |
43
|
|
|
* |
44
|
|
|
* The platform where a payment transaction takes place. This field is optional for filtering out |
45
|
|
|
* payment methods that are only available on specific platforms. If this value is not set, |
46
|
|
|
* then we will try to infer it from the sdkVersion or token. |
47
|
|
|
* |
48
|
|
|
* Possible values: Android, iOS, Web. |
49
|
|
|
* |
50
|
|
|
* @var string|null |
51
|
|
|
*/ |
52
|
|
|
private $channel; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* The shopper country. |
56
|
|
|
* |
57
|
|
|
* Format: ISO 3166-1 alpha-2 Example: NL or DE |
58
|
|
|
* |
59
|
|
|
* @var string|null |
60
|
|
|
*/ |
61
|
|
|
private $country_code; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Date of birth. |
65
|
|
|
* |
66
|
|
|
* @var DateTime|null |
67
|
|
|
*/ |
68
|
|
|
private $date_of_birth; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The address where the purchased goods should be delivered |
72
|
|
|
* |
73
|
|
|
* @var Address|null |
74
|
|
|
*/ |
75
|
|
|
private $delivery_address; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Line items regarding the payment. |
79
|
|
|
* |
80
|
|
|
* @var LineItems|null |
81
|
|
|
*/ |
82
|
|
|
private $line_items; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* The merchant account identifier, with which you want to process the transaction. |
86
|
|
|
* |
87
|
|
|
* @var string |
88
|
|
|
*/ |
89
|
|
|
private $merchant_account; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* The reference to uniquely identify a payment. This reference is used in all communication |
93
|
|
|
* with you about the payment status. We recommend using a unique value per payment; |
94
|
|
|
* however, it is not a requirement. If you need to provide multiple references for |
95
|
|
|
* a transaction, separate them with hyphens ("-"). Maximum length: 80 characters. |
96
|
|
|
* |
97
|
|
|
* @var string |
98
|
|
|
*/ |
99
|
|
|
private $reference; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* The URL to return to. |
103
|
|
|
* |
104
|
|
|
* @var string |
105
|
|
|
*/ |
106
|
|
|
private $return_url; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* The shopper's IP address. |
110
|
|
|
* |
111
|
|
|
* @var string|null |
112
|
|
|
*/ |
113
|
|
|
private $shopper_ip; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* The combination of a language code and a country code to specify the language to be used in the payment. |
117
|
|
|
* |
118
|
|
|
* @var string|null |
119
|
|
|
*/ |
120
|
|
|
private $shopper_locale; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* The shopper's full name and gender (if specified) |
124
|
|
|
* |
125
|
|
|
* @var Name|null |
126
|
|
|
*/ |
127
|
|
|
private $shopper_name; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* The shopper's email address. We recommend that you provide this data, as it is used in velocity fraud checks. |
131
|
|
|
* |
132
|
|
|
* @var string|null |
133
|
|
|
*/ |
134
|
|
|
private $shopper_email; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* The shopper's reference to uniquely identify this shopper (e.g. user ID or account ID). This field is |
138
|
|
|
* required for recurring payments |
139
|
|
|
* |
140
|
|
|
* @var string|null |
141
|
|
|
*/ |
142
|
|
|
private $shopper_reference; |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* The text to appear on the shopper's bank statement. |
146
|
|
|
* |
147
|
|
|
* @var string|null |
148
|
|
|
*/ |
149
|
|
|
private $shopper_statement; |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* The shopper's telephone number |
153
|
|
|
* |
154
|
|
|
* @var string|null |
155
|
|
|
*/ |
156
|
|
|
private $telephone_number; |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Construct a payment request object. |
160
|
|
|
* |
161
|
|
|
* @param Amount $amount The amount information for the transaction. |
162
|
|
|
* @param string $merchant_account The merchant account identifier, with which you want to process the transaction. |
163
|
|
|
* @param string $reference The reference to uniquely identify a payment. |
164
|
|
|
* @param string $return_url The URL to return to. |
165
|
|
|
*/ |
166
|
8 |
|
public function __construct( Amount $amount, $merchant_account, $reference, $return_url ) { |
167
|
8 |
|
$this->amount = $amount; |
168
|
8 |
|
$this->merchant_account = $merchant_account; |
169
|
8 |
|
$this->reference = $reference; |
170
|
8 |
|
$this->return_url = $return_url; |
171
|
8 |
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get amount. |
175
|
|
|
* |
176
|
|
|
* @return Amount |
177
|
|
|
*/ |
178
|
6 |
|
public function get_amount() { |
179
|
6 |
|
return $this->amount; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Get billing address. |
184
|
|
|
* |
185
|
|
|
* @return Address|null |
186
|
|
|
*/ |
187
|
1 |
|
public function get_billing_address() { |
188
|
1 |
|
return $this->billing_address; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Set billing address. |
193
|
|
|
* |
194
|
|
|
* @param Address|null $billing_address Billing address. |
195
|
|
|
* @return void |
196
|
|
|
*/ |
197
|
1 |
|
public function set_billing_address( Address $billing_address = null ) { |
198
|
1 |
|
$this->billing_address = $billing_address; |
199
|
1 |
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Get channel. |
203
|
|
|
* |
204
|
|
|
* @return string|null |
205
|
|
|
*/ |
206
|
2 |
|
public function get_channel() { |
207
|
2 |
|
return $this->channel; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Set channel. |
212
|
|
|
* |
213
|
|
|
* @param string|null $channel Channel. |
214
|
|
|
* @return void |
215
|
|
|
*/ |
216
|
2 |
|
public function set_channel( $channel ) { |
217
|
2 |
|
$this->channel = $channel; |
218
|
2 |
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Get country code. |
222
|
|
|
* |
223
|
|
|
* @return string|null |
224
|
|
|
*/ |
225
|
2 |
|
public function get_country_code() { |
226
|
2 |
|
return $this->country_code; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Set country code. |
231
|
|
|
* |
232
|
|
|
* @param string|null $country_code Country code. |
233
|
|
|
* @return void |
234
|
|
|
* @throws InvalidArgumentException Throws invalid argument exception when country code is not 2 characters. |
235
|
|
|
*/ |
236
|
5 |
|
public function set_country_code( $country_code ) { |
237
|
5 |
|
if ( null !== $country_code && 2 !== strlen( $country_code ) ) { |
238
|
1 |
|
throw new InvalidArgumentException( |
239
|
1 |
|
sprintf( |
240
|
1 |
|
'Given country code `%s` not ISO 3166-1 alpha-2 value.', |
241
|
|
|
$country_code |
242
|
|
|
) |
243
|
|
|
); |
244
|
|
|
} |
245
|
|
|
|
246
|
4 |
|
$this->country_code = $country_code; |
247
|
4 |
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Get date of birth. |
251
|
|
|
* |
252
|
|
|
* @return DateTime|null |
253
|
|
|
*/ |
254
|
1 |
|
public function get_date_of_birth() { |
255
|
1 |
|
return $this->date_of_birth; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Set date of birth. |
260
|
|
|
* |
261
|
|
|
* @param DateTime|null $date_of_birth Date of birth. |
262
|
|
|
* @return void |
263
|
|
|
*/ |
264
|
2 |
|
public function set_date_of_birth( DateTime $date_of_birth = null ) { |
265
|
2 |
|
$this->date_of_birth = $date_of_birth; |
266
|
2 |
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Get delivery address. |
270
|
|
|
* |
271
|
|
|
* @return Address|null |
272
|
|
|
*/ |
273
|
1 |
|
public function get_delivery_address() { |
274
|
1 |
|
return $this->delivery_address; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Set delivery address. |
279
|
|
|
* |
280
|
|
|
* @param Address|null $delivery_address Delivery address. |
281
|
|
|
* @return void |
282
|
|
|
*/ |
283
|
1 |
|
public function set_delivery_address( Address $delivery_address = null ) { |
284
|
1 |
|
$this->delivery_address = $delivery_address; |
285
|
1 |
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Get line items. |
289
|
|
|
* |
290
|
|
|
* @return LineItems|null |
291
|
|
|
*/ |
292
|
1 |
|
public function get_line_items() { |
293
|
1 |
|
return $this->line_items; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Set line items. |
298
|
|
|
* |
299
|
|
|
* @param LineItems|null $line_items Line items. |
300
|
|
|
* @return void |
301
|
|
|
*/ |
302
|
1 |
|
public function set_line_items( $line_items ) { |
303
|
1 |
|
$this->line_items = $line_items; |
304
|
1 |
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Create and set new line items. |
308
|
|
|
* |
309
|
|
|
* @return LineItems |
310
|
|
|
*/ |
311
|
1 |
|
public function new_line_items() { |
312
|
1 |
|
$this->line_items = new LineItems(); |
313
|
|
|
|
314
|
1 |
|
return $this->line_items; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Get merchant account. |
319
|
|
|
* |
320
|
|
|
* @return string |
321
|
|
|
*/ |
322
|
6 |
|
public function get_merchant_account() { |
323
|
6 |
|
return $this->merchant_account; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Get reference. |
328
|
|
|
* |
329
|
|
|
* @return string |
330
|
|
|
*/ |
331
|
6 |
|
public function get_reference() { |
332
|
6 |
|
return $this->reference; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Get return URL. |
337
|
|
|
* |
338
|
|
|
* @return string |
339
|
|
|
*/ |
340
|
6 |
|
public function get_return_url() { |
341
|
6 |
|
return $this->return_url; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Get shopper IP. |
346
|
|
|
* |
347
|
|
|
* @return string|null |
348
|
|
|
*/ |
349
|
2 |
|
public function get_shopper_ip() { |
350
|
2 |
|
return $this->shopper_ip; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* Set shopper IP. |
355
|
|
|
* |
356
|
|
|
* @param string|null $shopper_ip Shopper IP. |
357
|
|
|
* @return void |
358
|
|
|
*/ |
359
|
2 |
|
public function set_shopper_ip( $shopper_ip ) { |
360
|
2 |
|
$this->shopper_ip = $shopper_ip; |
361
|
2 |
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* Get shopper locale. |
365
|
|
|
* |
366
|
|
|
* @return string|null |
367
|
|
|
*/ |
368
|
2 |
|
public function get_shopper_locale() { |
369
|
2 |
|
return $this->shopper_locale; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Set shopper locale. |
374
|
|
|
* |
375
|
|
|
* @param string|null $shopper_locale Shopper locale. |
376
|
|
|
* @return void |
377
|
|
|
*/ |
378
|
2 |
|
public function set_shopper_locale( $shopper_locale ) { |
379
|
2 |
|
$this->shopper_locale = $shopper_locale; |
380
|
2 |
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Get shopper name. |
384
|
|
|
* |
385
|
|
|
* @return Name|null |
386
|
|
|
*/ |
387
|
1 |
|
public function get_shopper_name() { |
388
|
1 |
|
return $this->shopper_name; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* Set shopper name. |
393
|
|
|
* |
394
|
|
|
* @param Name|null $shopper_name Shopper name. |
395
|
|
|
* @return void |
396
|
|
|
*/ |
397
|
1 |
|
public function set_shopper_name( Name $shopper_name = null ) { |
398
|
1 |
|
$this->shopper_name = $shopper_name; |
399
|
1 |
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Get shopper email. |
403
|
|
|
* |
404
|
|
|
* @return string|null |
405
|
|
|
*/ |
406
|
|
|
public function get_shopper_email() { |
407
|
|
|
return $this->shopper_email; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Set shopper email. |
412
|
|
|
* |
413
|
|
|
* @param string|null $shopper_email Shopper email. |
414
|
|
|
* |
415
|
|
|
* @return void |
416
|
|
|
*/ |
417
|
1 |
|
public function set_shopper_email( $shopper_email = null ) { |
418
|
1 |
|
$this->shopper_email = $shopper_email; |
419
|
1 |
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Get shopper reference. |
423
|
|
|
* |
424
|
|
|
* @return string|null |
425
|
|
|
*/ |
426
|
1 |
|
public function get_shopper_reference() { |
427
|
1 |
|
return $this->shopper_reference; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* Set shopper reference. |
432
|
|
|
* |
433
|
|
|
* @param string|null $shopper_reference Shopper reference. |
434
|
|
|
* @return void |
435
|
|
|
*/ |
436
|
1 |
|
public function set_shopper_reference( $shopper_reference ) { |
437
|
1 |
|
$this->shopper_reference = $shopper_reference; |
438
|
1 |
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* Get shopper statement. |
442
|
|
|
* |
443
|
|
|
* @return string|null |
444
|
|
|
*/ |
445
|
2 |
|
public function get_shopper_statement() { |
446
|
2 |
|
return $this->shopper_statement; |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* Set shopper statement. |
451
|
|
|
* |
452
|
|
|
* @param string|null $shopper_statement Shopper statement. |
453
|
|
|
* @return void |
454
|
|
|
*/ |
455
|
2 |
|
public function set_shopper_statement( $shopper_statement ) { |
456
|
2 |
|
$this->shopper_statement = $shopper_statement; |
457
|
2 |
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* Get telephone number. |
461
|
|
|
* |
462
|
|
|
* @return string|null |
463
|
|
|
*/ |
464
|
2 |
|
public function get_telephone_number() { |
465
|
2 |
|
return $this->telephone_number; |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* Set shopper statement. |
470
|
|
|
* |
471
|
|
|
* @param string|null $telephone_number Telephone number. |
472
|
|
|
* @return void |
473
|
|
|
*/ |
474
|
2 |
|
public function set_telephone_number( $telephone_number ) { |
475
|
2 |
|
$this->telephone_number = $telephone_number; |
476
|
2 |
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* Get JSON. |
480
|
|
|
* |
481
|
|
|
* @return object |
482
|
|
|
*/ |
483
|
5 |
|
public function get_json() { |
484
|
5 |
|
$properties = Util::filter_null( |
485
|
|
|
array( |
486
|
5 |
|
'amount' => $this->get_amount()->get_json(), |
487
|
5 |
|
'billingAddress' => is_null( $this->billing_address ) ? null : $this->billing_address->get_json(), |
488
|
5 |
|
'channel' => $this->channel, |
489
|
5 |
|
'countryCode' => $this->country_code, |
490
|
5 |
|
'dateOfBirth' => is_null( $this->date_of_birth ) ? null : $this->date_of_birth->format( 'Y-m-d' ), |
491
|
5 |
|
'deliveryAddress' => is_null( $this->delivery_address ) ? null : $this->delivery_address->get_json(), |
492
|
5 |
|
'lineItems' => is_null( $this->line_items ) ? null : $this->line_items->get_json(), |
493
|
5 |
|
'merchantAccount' => $this->get_merchant_account(), |
494
|
5 |
|
'reference' => $this->get_reference(), |
495
|
5 |
|
'returnUrl' => $this->get_return_url(), |
496
|
5 |
|
'shopperIP' => $this->shopper_ip, |
497
|
5 |
|
'shopperLocale' => $this->shopper_locale, |
498
|
5 |
|
'shopperName' => is_null( $this->shopper_name ) ? null : $this->shopper_name->get_json(), |
499
|
5 |
|
'shopperEmail' => $this->shopper_email, |
500
|
5 |
|
'shopperReference' => $this->shopper_reference, |
501
|
5 |
|
'shopperStatement' => $this->shopper_statement, |
502
|
5 |
|
'telephoneNumber' => $this->telephone_number, |
503
|
|
|
) |
504
|
|
|
); |
505
|
|
|
|
506
|
5 |
|
$object = (object) $properties; |
507
|
|
|
|
508
|
5 |
|
return $object; |
509
|
|
|
} |
510
|
|
|
} |
511
|
|
|
|