Failed Conditions
Push — develop ( def963...184746 )
by Remco
02:41
created

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