Failed Conditions
Push — develop ( bc7636...0ebe47 )
by Reüel
09:35
created

set_merchant_order_reference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
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
	 * This reference allows linking multiple transactions to each other for reporting
101
	 * purposes (i.e. order auth-rate). The reference should be unique per billing cycle.
102
	 * The same merchant order reference should never be reused after the first authorised
103
	 * attempt. If used, this field should be supplied for all incoming authorisations.
104
	 *
105
	 * @var string|null
106
	 */
107
	private $merchant_order_reference;
108
109
	/**
110
	 * The reference to uniquely identify a payment. This reference is used in all communication
111
	 * with you about the payment status. We recommend using a unique value per payment;
112
	 * however, it is not a requirement. If you need to provide multiple references for
113
	 * a transaction, separate them with hyphens ("-"). Maximum length: 80 characters.
114
	 *
115
	 * @var string
116
	 */
117
	private $reference;
118
119
	/**
120
	 * The URL to return to.
121
	 *
122
	 * @var string
123
	 */
124
	private $return_url;
125
126
	/**
127
	 * The shopper's IP address.
128
	 *
129
	 * @var string|null
130
	 */
131
	private $shopper_ip;
132
133
	/**
134
	 * The combination of a language code and a country code to specify the language to be used in the payment.
135
	 *
136
	 * @var string|null
137
	 */
138
	private $shopper_locale;
139
140
	/**
141
	 * The shopper's full name and gender (if specified)
142
	 *
143
	 * @var Name|null
144
	 */
145
	private $shopper_name;
146
147
	/**
148
	 * The shopper's email address. We recommend that you provide this data, as it is used in velocity fraud checks.
149
	 *
150
	 * @var string|null
151
	 */
152
	private $shopper_email;
153
154
	/**
155
	 * The shopper's reference to uniquely identify this shopper (e.g. user ID or account ID). This field is
156
	 * required for recurring payments
157
	 *
158
	 * @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v51/payments__reqParam_shopperReference
159
	 * @var string|null
160
	 */
161
	private $shopper_reference;
162
163
	/**
164
	 * The text to appear on the shopper's bank statement.
165
	 *
166
	 * @var string|null
167
	 */
168
	private $shopper_statement;
169
170
	/**
171
	 * The shopper's telephone number
172
	 *
173
	 * @var string|null
174
	 */
175
	private $telephone_number;
176
177
	/**
178
	 * Construct a payment request object.
179
	 *
180
	 * @param Amount $amount           The amount information for the transaction.
181
	 * @param string $merchant_account The merchant account identifier, with which you want to process the transaction.
182
	 * @param string $reference        The reference to uniquely identify a payment.
183
	 * @param string $return_url       The URL to return to.
184
	 */
185 8
	public function __construct( Amount $amount, $merchant_account, $reference, $return_url ) {
186 8
		$this->amount           = $amount;
187 8
		$this->merchant_account = $merchant_account;
188 8
		$this->reference        = $reference;
189 8
		$this->return_url       = $return_url;
190 8
	}
191
192
	/**
193
	 * Get amount.
194
	 *
195
	 * @return Amount
196
	 */
197 6
	public function get_amount() {
198 6
		return $this->amount;
199
	}
200
201
	/**
202
	 * Get application info.
203
	 *
204
	 * @return ApplicationInfo|null
205
	 */
206
	public function get_application_info() {
207
		return $this->application_info;
208
	}
209
210
	/**
211
	 * Set application info.
212
	 *
213
	 * @param ApplicationInfo|null $application_info Application info.
214
	 * @return void
215
	 */
216 1
	public function set_application_info( $application_info ) {
217 1
		$this->application_info = $application_info;
218 1
	}
219
220
	/**
221
	 * Get billing address.
222
	 *
223
	 * @return Address|null
224
	 */
225 1
	public function get_billing_address() {
226 1
		return $this->billing_address;
227
	}
228
229
	/**
230
	 * Set billing address.
231
	 *
232
	 * @param Address|null $billing_address Billing address.
233
	 * @return void
234
	 */
235 1
	public function set_billing_address( Address $billing_address = null ) {
236 1
		$this->billing_address = $billing_address;
237 1
	}
238
239
	/**
240
	 * Get channel.
241
	 *
242
	 * @return string|null
243
	 */
244 2
	public function get_channel() {
245 2
		return $this->channel;
246
	}
247
248
	/**
249
	 * Set channel.
250
	 *
251
	 * @param string|null $channel Channel.
252
	 * @return void
253
	 */
254 2
	public function set_channel( $channel ) {
255 2
		$this->channel = $channel;
256 2
	}
257
258
	/**
259
	 * Get country code.
260
	 *
261
	 * @return string|null
262
	 */
263 2
	public function get_country_code() {
264 2
		return $this->country_code;
265
	}
266
267
	/**
268
	 * Set country code.
269
	 *
270
	 * @param string|null $country_code Country code.
271
	 * @return void
272
	 * @throws InvalidArgumentException Throws invalid argument exception when country code is not 2 characters.
273
	 */
274 5
	public function set_country_code( $country_code ) {
275 5
		if ( null !== $country_code && 2 !== strlen( $country_code ) ) {
276 1
			throw new InvalidArgumentException(
277 1
				sprintf(
278 1
					'Given country code `%s` not ISO 3166-1 alpha-2 value.',
279
					$country_code
280
				)
281
			);
282
		}
283
284 4
		$this->country_code = $country_code;
285 4
	}
286
287
	/**
288
	 * Get date of birth.
289
	 *
290
	 * @return DateTime|null
291
	 */
292 1
	public function get_date_of_birth() {
293 1
		return $this->date_of_birth;
294
	}
295
296
	/**
297
	 * Set date of birth.
298
	 *
299
	 * @param DateTime|null $date_of_birth Date of birth.
300
	 * @return void
301
	 */
302 2
	public function set_date_of_birth( DateTime $date_of_birth = null ) {
303 2
		$this->date_of_birth = $date_of_birth;
304 2
	}
305
306
	/**
307
	 * Get delivery address.
308
	 *
309
	 * @return Address|null
310
	 */
311 1
	public function get_delivery_address() {
312 1
		return $this->delivery_address;
313
	}
314
315
	/**
316
	 * Set delivery address.
317
	 *
318
	 * @param Address|null $delivery_address Delivery address.
319
	 * @return void
320
	 */
321 1
	public function set_delivery_address( Address $delivery_address = null ) {
322 1
		$this->delivery_address = $delivery_address;
323 1
	}
324
325
	/**
326
	 * Get line items.
327
	 *
328
	 * @return LineItems|null
329
	 */
330 1
	public function get_line_items() {
331 1
		return $this->line_items;
332
	}
333
334
	/**
335
	 * Set line items.
336
	 *
337
	 * @param LineItems|null $line_items Line items.
338
	 * @return void
339
	 */
340 1
	public function set_line_items( $line_items ) {
341 1
		$this->line_items = $line_items;
342 1
	}
343
344
	/**
345
	 * Create and set new line items.
346
	 *
347
	 * @return LineItems
348
	 */
349 1
	public function new_line_items() {
350 1
		$this->line_items = new LineItems();
351
352 1
		return $this->line_items;
353
	}
354
355
	/**
356
	 * Get merchant account.
357
	 *
358
	 * @return string
359
	 */
360 6
	public function get_merchant_account() {
361 6
		return $this->merchant_account;
362
	}
363
364
365
	/**
366
	 * Get merchant order reference.
367
	 *
368
	 * @return mixed
369
	 */
370 5
	public function get_merchant_order_reference() {
371 5
		return $this->merchant_order_reference;
372
	}
373
374
	/**
375
	 * Set merchant order reference.
376
	 *
377
	 * @param mixed $merchant_order_reference Merchant order reference.
378
	 * @return void
379
	 */
380
	public function set_merchant_order_reference( $merchant_order_reference ) {
381
		$this->merchant_order_reference = $merchant_order_reference;
382
	}
383
384
	/**
385
	 * Get reference.
386
	 *
387
	 * @return string
388
	 */
389 6
	public function get_reference() {
390 6
		return $this->reference;
391
	}
392
393
	/**
394
	 * Get return URL.
395
	 *
396
	 * @return string
397
	 */
398 6
	public function get_return_url() {
399 6
		return $this->return_url;
400
	}
401
402
	/**
403
	 * Get shopper IP.
404
	 *
405
	 * @return string|null
406
	 */
407 2
	public function get_shopper_ip() {
408 2
		return $this->shopper_ip;
409
	}
410
411
	/**
412
	 * Set shopper IP.
413
	 *
414
	 * @param string|null $shopper_ip Shopper IP.
415
	 * @return void
416
	 */
417 2
	public function set_shopper_ip( $shopper_ip ) {
418 2
		$this->shopper_ip = $shopper_ip;
419 2
	}
420
421
	/**
422
	 * Get shopper locale.
423
	 *
424
	 * @return string|null
425
	 */
426 2
	public function get_shopper_locale() {
427 2
		return $this->shopper_locale;
428
	}
429
430
	/**
431
	 * Set shopper locale.
432
	 *
433
	 * @param string|null $shopper_locale Shopper locale.
434
	 * @return void
435
	 */
436 2
	public function set_shopper_locale( $shopper_locale ) {
437 2
		$this->shopper_locale = $shopper_locale;
438 2
	}
439
440
	/**
441
	 * Get shopper name.
442
	 *
443
	 * @return Name|null
444
	 */
445 1
	public function get_shopper_name() {
446 1
		return $this->shopper_name;
447
	}
448
449
	/**
450
	 * Set shopper name.
451
	 *
452
	 * @param Name|null $shopper_name Shopper name.
453
	 * @return void
454
	 */
455 1
	public function set_shopper_name( Name $shopper_name = null ) {
456 1
		$this->shopper_name = $shopper_name;
457 1
	}
458
459
	/**
460
	 * Get shopper email.
461
	 *
462
	 * @return string|null
463
	 */
464
	public function get_shopper_email() {
465
		return $this->shopper_email;
466
	}
467
468
	/**
469
	 * Set shopper email.
470
	 *
471
	 * @param string|null $shopper_email Shopper email.
472
	 *
473
	 * @return void
474
	 */
475 1
	public function set_shopper_email( $shopper_email = null ) {
476 1
		$this->shopper_email = $shopper_email;
477 1
	}
478
479
	/**
480
	 * Get shopper reference.
481
	 *
482
	 * @return string|null
483
	 */
484 1
	public function get_shopper_reference() {
485 1
		return $this->shopper_reference;
486
	}
487
488
	/**
489
	 * Set shopper reference.
490
	 *
491
	 * @param string|null $shopper_reference Shopper reference.
492
	 * @return void
493
	 */
494 2
	public function set_shopper_reference( $shopper_reference ) {
495 2
		$this->shopper_reference = $shopper_reference;
496 2
	}
497
498
	/**
499
	 * Get shopper statement.
500
	 *
501
	 * @return string|null
502
	 */
503 2
	public function get_shopper_statement() {
504 2
		return $this->shopper_statement;
505
	}
506
507
	/**
508
	 * Set shopper statement.
509
	 *
510
	 * @param string|null $shopper_statement Shopper statement.
511
	 * @return void
512
	 */
513 2
	public function set_shopper_statement( $shopper_statement ) {
514 2
		$this->shopper_statement = $shopper_statement;
515 2
	}
516
517
	/**
518
	 * Get telephone number.
519
	 *
520
	 * @return string|null
521
	 */
522 2
	public function get_telephone_number() {
523 2
		return $this->telephone_number;
524
	}
525
526
	/**
527
	 * Set shopper statement.
528
	 *
529
	 * @param string|null $telephone_number Telephone number.
530
	 * @return void
531
	 */
532 2
	public function set_telephone_number( $telephone_number ) {
533 2
		$this->telephone_number = $telephone_number;
534 2
	}
535
536
	/**
537
	 * Get JSON.
538
	 *
539
	 * @return object
540
	 */
541 5
	public function get_json() {
542 5
		$properties = Util::filter_null(
543
			array(
544 5
				'amount'                 => $this->get_amount()->get_json(),
545 5
				'applicationInfo'        => $this->application_info,
546 5
				'billingAddress'         => is_null( $this->billing_address ) ? null : $this->billing_address->get_json(),
547 5
				'channel'                => $this->channel,
548 5
				'countryCode'            => $this->country_code,
549 5
				'dateOfBirth'            => is_null( $this->date_of_birth ) ? null : $this->date_of_birth->format( 'Y-m-d' ),
550 5
				'deliveryAddress'        => is_null( $this->delivery_address ) ? null : $this->delivery_address->get_json(),
551 5
				'lineItems'              => is_null( $this->line_items ) ? null : $this->line_items->get_json(),
552 5
				'merchantAccount'        => $this->get_merchant_account(),
553 5
				'merchantOrderReference' => $this->get_merchant_order_reference(),
554 5
				'reference'              => $this->get_reference(),
555 5
				'returnUrl'              => $this->get_return_url(),
556 5
				'shopperIP'              => $this->shopper_ip,
557 5
				'shopperLocale'          => $this->shopper_locale,
558 5
				'shopperName'            => is_null( $this->shopper_name ) ? null : $this->shopper_name->get_json(),
559 5
				'shopperEmail'           => $this->shopper_email,
560 5
				'shopperReference'       => $this->shopper_reference,
561 5
				'shopperStatement'       => $this->shopper_statement,
562 5
				'telephoneNumber'        => $this->telephone_number,
563
			)
564
		);
565
566 5
		$object = (object) $properties;
567
568 5
		return $object;
569
	}
570
}
571