Test Failed
Push — develop ( 19b05e...ee5b51 )
by Remco
04:28
created

PaymentMethodsRequest::set_country_code()   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
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * Payment methods 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
/**
14
 * Payment methods request
15
 *
16
 * @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v51/paymentMethods
17
 *
18
 * @author  Remco Tolsma
19
 * @version 1.0.0
20
 * @since   1.0.0
21
 */
22
class PaymentMethodsRequest extends Request {
23
	/**
24
	 * The merchant account identifier, with which you want to process the transaction.
25
	 *
26
	 * @var string
27
	 */
28
	private $merchant_account;
29
30
	/**
31
	 * The shopper's country code.
32
	 *
33
	 * @var string|null
34
	 */
35 7
	private $country_code;
36 7
37 7
	/**
38
	 * The amount information for the transaction.
39
	 *
40
	 * @var Amount|null
41
	 */
42
	private $amount;
43
44 6
	/**
45
	 * Construct a payment request object.
46 6
	 *
47
	 * @param string $merchant_account The merchant account identifier.
48
	 */
49
	public function __construct( $merchant_account ) {
50 6
		$this->merchant_account = $merchant_account;
51
	}
52
53
	/**
54
	 * Set the shopper's country code.
55
	 *
56
	 * @param string|null $country_code The shopper's country code.
57
	 */
58
	public function set_country_code( $country_code ) {
59
		$this->country_code = $country_code;
60
	}
61
62
	/**
63
	 * Set the amount information for the transaction. 
64
	 *
65
	 * @param Amount|null $amount The amount information for the transaction. 
66
	 */
67
	public function set_amount( Amount $amount = null ) {
68
		$this->amount = $amount;
69
	}
70
71
	/**
72
	 * Get JSON.
73
	 *
74
	 * @return object
75
	 */
76
	public function get_json() {
77
		$properties = array(
78
			'merchantAccount' => $this->merchant_account,
79
		);
80
81
		if ( null !== $this->country_code ) {
82
			$properties['countryCode'] = $this->country_code;
83
		}
84
85
		if ( null !== $this->amount ) {
86
			$properties['amount'] = $this->amount->get_json();
87
		}
88
89
		// Return object.
90
		$object = (object) $properties;
91
92
		return $object;
93
	}
94
}
95