Failed Conditions
Push — master ( 84f509...0a235e )
by Remco
14:29 queued 05:04
created

get_blocked_payment_methods()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
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
	 * Allowed payment methods.
25
	 *
26
	 * @var array<int, string>|null
27
	 */
28
	private $allowed_payment_methods;
29
30
	/**
31
	 * Blocked payment methods.
32
	 *
33
	 * @var array<int, string>|null
34
	 */
35
	private $blocked_payment_methods;
36
37
	/**
38
	 * The merchant account identifier, with which you want to process the transaction.
39
	 *
40
	 * @var string
41
	 */
42
	private $merchant_account;
43
44
	/**
45
	 * The shopper's country code.
46
	 *
47
	 * @var string|null
48
	 */
49
	private $country_code;
50
51
	/**
52
	 * The amount information for the transaction.
53
	 *
54
	 * @var Amount|null
55
	 */
56
	private $amount;
57
58
	/**
59
	 * Construct a payment request object.
60
	 *
61
	 * @param string $merchant_account The merchant account identifier.
62
	 */
63 7
	public function __construct( $merchant_account ) {
64 7
		$this->merchant_account = $merchant_account;
65 7
	}
66
67
	/**
68
	 * Get allowed payment methods.
69
	 *
70
	 * @return array<int, string>|null
71
	 */
72 6
	public function get_allowed_payment_methods() {
73 6
		return $this->allowed_payment_methods;
74
	}
75
76
	/**
77
	 * Set allowed payment methods.
78
	 *
79
	 * @param array<int, string> $allowed_payment_methods Allowed payment methods.
80
	 * @return void
81
	 */
82
	public function set_allowed_payment_methods( $allowed_payment_methods ) {
83
		$this->allowed_payment_methods = $allowed_payment_methods;
84
	}
85
86
	/**
87
	 * Get blocked payment methods.
88
	 *
89
	 * @return array<int, string>|null
90
	 */
91 6
	public function get_blocked_payment_methods() {
92 6
		return $this->blocked_payment_methods;
93
	}
94
95
	/**
96
	 * Set blocked payment methods.
97
	 *
98
	 * @param array<int, string> $blocked_payment_methods Blocked payment methods.
99
	 * @return void
100
	 */
101
	public function set_blocked_payment_methods( $blocked_payment_methods ) {
102
		$this->blocked_payment_methods = $blocked_payment_methods;
103
	}
104
105
	/**
106
	 * Get country code.
107
	 *
108
	 * @return string|null
109
	 */
110 6
	public function get_country_code() {
111 6
		return $this->country_code;
112
	}
113
114
	/**
115
	 * Set the shopper's country code.
116
	 *
117
	 * @param string|null $country_code The shopper's country code.
118
	 * @return void
119
	 */
120
	public function set_country_code( $country_code ) {
121
		$this->country_code = $country_code;
122
	}
123
124
	/**
125
	 * Get amount.
126
	 *
127
	 * @return Amount|null
128
	 */
129 6
	public function get_amount() {
130 6
		return $this->amount;
131
	}
132
133
	/**
134
	 * Set the amount information for the transaction.
135
	 *
136
	 * @param Amount|null $amount The amount information for the transaction.
137
	 * @return void
138
	 */
139
	public function set_amount( Amount $amount = null ) {
140
		$this->amount = $amount;
141
	}
142
143
	/**
144
	 * Get JSON.
145
	 *
146
	 * @return object
147
	 */
148 6
	public function get_json() {
149 6
		$properties = Util::filter_null(
150
			array(
151 6
				'merchantAccount'       => $this->merchant_account,
152 6
				'countryCode'           => $this->get_country_code(),
153 6
				'allowedPaymentMethods' => $this->get_allowed_payment_methods(),
154 6
				'blockedPaymentMethods' => $this->get_blocked_payment_methods(),
155
			)
156
		);
157
158
		// Amount.
159 6
		$amount = $this->get_amount();
160
161 6
		if ( null !== $amount ) {
162
			$properties['amount'] = $amount->get_json();
163
		}
164
165
		// Return object.
166 6
		$object = (object) $properties;
167
168 6
		return $object;
169
	}
170
}
171