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