Failed Conditions
Push — develop ( 05bf6b...a342cf )
by Reüel
03:02
created

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