Failed Conditions
Push — master ( cc3467...84f509 )
by Reüel
09:31 queued 01:25
created

AbstractPaymentRequest::get_country_code()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
	 * @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v51/payments__reqParam_shopperReference
149
	 * @var string|null
150
	 */
151
	private $shopper_reference;
152
153
	/**
154
	 * The text to appear on the shopper's bank statement.
155
	 *
156
	 * @var string|null
157
	 */
158
	private $shopper_statement;
159
160
	/**
161
	 * The shopper's telephone number
162
	 *
163
	 * @var string|null
164
	 */
165
	private $telephone_number;
166
167
	/**
168
	 * Construct a payment request object.
169
	 *
170
	 * @param Amount $amount           The amount information for the transaction.
171
	 * @param string $merchant_account The merchant account identifier, with which you want to process the transaction.
172
	 * @param string $reference        The reference to uniquely identify a payment.
173
	 * @param string $return_url       The URL to return to.
174
	 */
175 8
	public function __construct( Amount $amount, $merchant_account, $reference, $return_url ) {
176 8
		$this->amount           = $amount;
177 8
		$this->merchant_account = $merchant_account;
178 8
		$this->reference        = $reference;
179 8
		$this->return_url       = $return_url;
180 8
	}
181
182
	/**
183
	 * Get amount.
184
	 *
185
	 * @return Amount
186
	 */
187 6
	public function get_amount() {
188 6
		return $this->amount;
189
	}
190
191
	/**
192
	 * Get application info.
193
	 *
194
	 * @return ApplicationInfo|null
195
	 */
196
	public function get_application_info() {
197
		return $this->application_info;
198
	}
199
200
	/**
201
	 * Set application info.
202
	 *
203
	 * @param ApplicationInfo|null $application_info Application info.
204
	 * @return void
205
	 */
206 1
	public function set_application_info( $application_info ) {
207 1
		$this->application_info = $application_info;
208 1
	}
209
210
	/**
211
	 * Get billing address.
212
	 *
213
	 * @return Address|null
214
	 */
215 1
	public function get_billing_address() {
216 1
		return $this->billing_address;
217
	}
218
219
	/**
220
	 * Set billing address.
221
	 *
222
	 * @param Address|null $billing_address Billing address.
223
	 * @return void
224
	 */
225 1
	public function set_billing_address( Address $billing_address = null ) {
226 1
		$this->billing_address = $billing_address;
227 1
	}
228
229
	/**
230
	 * Get channel.
231
	 *
232
	 * @return string|null
233
	 */
234 2
	public function get_channel() {
235 2
		return $this->channel;
236
	}
237
238
	/**
239
	 * Set channel.
240
	 *
241
	 * @param string|null $channel Channel.
242
	 * @return void
243
	 */
244 2
	public function set_channel( $channel ) {
245 2
		$this->channel = $channel;
246 2
	}
247
248
	/**
249
	 * Get country code.
250
	 *
251
	 * @return string|null
252
	 */
253 2
	public function get_country_code() {
254 2
		return $this->country_code;
255
	}
256
257
	/**
258
	 * Set country code.
259
	 *
260
	 * @param string|null $country_code Country code.
261
	 * @return void
262
	 * @throws InvalidArgumentException Throws invalid argument exception when country code is not 2 characters.
263
	 */
264 5
	public function set_country_code( $country_code ) {
265 5
		if ( null !== $country_code && 2 !== strlen( $country_code ) ) {
266 1
			throw new InvalidArgumentException(
267 1
				sprintf(
268 1
					'Given country code `%s` not ISO 3166-1 alpha-2 value.',
269
					$country_code
270
				)
271
			);
272
		}
273
274 4
		$this->country_code = $country_code;
275 4
	}
276
277
	/**
278
	 * Get date of birth.
279
	 *
280
	 * @return DateTime|null
281
	 */
282 1
	public function get_date_of_birth() {
283 1
		return $this->date_of_birth;
284
	}
285
286
	/**
287
	 * Set date of birth.
288
	 *
289
	 * @param DateTime|null $date_of_birth Date of birth.
290
	 * @return void
291
	 */
292 2
	public function set_date_of_birth( DateTime $date_of_birth = null ) {
293 2
		$this->date_of_birth = $date_of_birth;
294 2
	}
295
296
	/**
297
	 * Get delivery address.
298
	 *
299
	 * @return Address|null
300
	 */
301 1
	public function get_delivery_address() {
302 1
		return $this->delivery_address;
303
	}
304
305
	/**
306
	 * Set delivery address.
307
	 *
308
	 * @param Address|null $delivery_address Delivery address.
309
	 * @return void
310
	 */
311 1
	public function set_delivery_address( Address $delivery_address = null ) {
312 1
		$this->delivery_address = $delivery_address;
313 1
	}
314
315
	/**
316
	 * Get line items.
317
	 *
318
	 * @return LineItems|null
319
	 */
320 1
	public function get_line_items() {
321 1
		return $this->line_items;
322
	}
323
324
	/**
325
	 * Set line items.
326
	 *
327
	 * @param LineItems|null $line_items Line items.
328
	 * @return void
329
	 */
330 1
	public function set_line_items( $line_items ) {
331 1
		$this->line_items = $line_items;
332 1
	}
333
334
	/**
335
	 * Create and set new line items.
336
	 *
337
	 * @return LineItems
338
	 */
339 1
	public function new_line_items() {
340 1
		$this->line_items = new LineItems();
341
342 1
		return $this->line_items;
343
	}
344
345
	/**
346
	 * Get merchant account.
347
	 *
348
	 * @return string
349
	 */
350 6
	public function get_merchant_account() {
351 6
		return $this->merchant_account;
352
	}
353
354
	/**
355
	 * Get reference.
356
	 *
357
	 * @return string
358
	 */
359 6
	public function get_reference() {
360 6
		return $this->reference;
361
	}
362
363
	/**
364
	 * Get return URL.
365
	 *
366
	 * @return string
367
	 */
368 6
	public function get_return_url() {
369 6
		return $this->return_url;
370
	}
371
372
	/**
373
	 * Get shopper IP.
374
	 *
375
	 * @return string|null
376
	 */
377 2
	public function get_shopper_ip() {
378 2
		return $this->shopper_ip;
379
	}
380
381
	/**
382
	 * Set shopper IP.
383
	 *
384
	 * @param string|null $shopper_ip Shopper IP.
385
	 * @return void
386
	 */
387 2
	public function set_shopper_ip( $shopper_ip ) {
388 2
		$this->shopper_ip = $shopper_ip;
389 2
	}
390
391
	/**
392
	 * Get shopper locale.
393
	 *
394
	 * @return string|null
395
	 */
396 2
	public function get_shopper_locale() {
397 2
		return $this->shopper_locale;
398
	}
399
400
	/**
401
	 * Set shopper locale.
402
	 *
403
	 * @param string|null $shopper_locale Shopper locale.
404
	 * @return void
405
	 */
406 2
	public function set_shopper_locale( $shopper_locale ) {
407 2
		$this->shopper_locale = $shopper_locale;
408 2
	}
409
410
	/**
411
	 * Get shopper name.
412
	 *
413
	 * @return Name|null
414
	 */
415 1
	public function get_shopper_name() {
416 1
		return $this->shopper_name;
417
	}
418
419
	/**
420
	 * Set shopper name.
421
	 *
422
	 * @param Name|null $shopper_name Shopper name.
423
	 * @return void
424
	 */
425 1
	public function set_shopper_name( Name $shopper_name = null ) {
426 1
		$this->shopper_name = $shopper_name;
427 1
	}
428
429
	/**
430
	 * Get shopper email.
431
	 *
432
	 * @return string|null
433
	 */
434
	public function get_shopper_email() {
435
		return $this->shopper_email;
436
	}
437
438
	/**
439
	 * Set shopper email.
440
	 *
441
	 * @param string|null $shopper_email Shopper email.
442
	 *
443
	 * @return void
444
	 */
445 1
	public function set_shopper_email( $shopper_email = null ) {
446 1
		$this->shopper_email = $shopper_email;
447 1
	}
448
449
	/**
450
	 * Get shopper reference.
451
	 *
452
	 * @return string|null
453
	 */
454 1
	public function get_shopper_reference() {
455 1
		return $this->shopper_reference;
456
	}
457
458
	/**
459
	 * Set shopper reference.
460
	 *
461
	 * @param string|null $shopper_reference Shopper reference.
462
	 * @return void
463
	 */
464 2
	public function set_shopper_reference( $shopper_reference ) {
465 2
		$this->shopper_reference = $shopper_reference;
466 2
	}
467
468
	/**
469
	 * Get shopper statement.
470
	 *
471
	 * @return string|null
472
	 */
473 2
	public function get_shopper_statement() {
474 2
		return $this->shopper_statement;
475
	}
476
477
	/**
478
	 * Set shopper statement.
479
	 *
480
	 * @param string|null $shopper_statement Shopper statement.
481
	 * @return void
482
	 */
483 2
	public function set_shopper_statement( $shopper_statement ) {
484 2
		$this->shopper_statement = $shopper_statement;
485 2
	}
486
487
	/**
488
	 * Get telephone number.
489
	 *
490
	 * @return string|null
491
	 */
492 2
	public function get_telephone_number() {
493 2
		return $this->telephone_number;
494
	}
495
496
	/**
497
	 * Set shopper statement.
498
	 *
499
	 * @param string|null $telephone_number Telephone number.
500
	 * @return void
501
	 */
502 2
	public function set_telephone_number( $telephone_number ) {
503 2
		$this->telephone_number = $telephone_number;
504 2
	}
505
506
	/**
507
	 * Get JSON.
508
	 *
509
	 * @return object
510
	 */
511 5
	public function get_json() {
512 5
		$properties = Util::filter_null(
513
			array(
514 5
				'amount'           => $this->get_amount()->get_json(),
515 5
				'applicationInfo'  => $this->application_info,
516 5
				'billingAddress'   => is_null( $this->billing_address ) ? null : $this->billing_address->get_json(),
517 5
				'channel'          => $this->channel,
518 5
				'countryCode'      => $this->country_code,
519 5
				'dateOfBirth'      => is_null( $this->date_of_birth ) ? null : $this->date_of_birth->format( 'Y-m-d' ),
520 5
				'deliveryAddress'  => is_null( $this->delivery_address ) ? null : $this->delivery_address->get_json(),
521 5
				'lineItems'        => is_null( $this->line_items ) ? null : $this->line_items->get_json(),
522 5
				'merchantAccount'  => $this->get_merchant_account(),
523 5
				'reference'        => $this->get_reference(),
524 5
				'returnUrl'        => $this->get_return_url(),
525 5
				'shopperIP'        => $this->shopper_ip,
526 5
				'shopperLocale'    => $this->shopper_locale,
527 5
				'shopperName'      => is_null( $this->shopper_name ) ? null : $this->shopper_name->get_json(),
528 5
				'shopperEmail'     => $this->shopper_email,
529 5
				'shopperReference' => $this->shopper_reference,
530 5
				'shopperStatement' => $this->shopper_statement,
531 5
				'telephoneNumber'  => $this->telephone_number,
532
			)
533
		);
534
535 5
		$object = (object) $properties;
536
537 5
		return $object;
538
	}
539
}
540