Failed Conditions
Push — master ( cc3467...84f509 )
by Reüel
09:31 queued 01:25
created

PaymentMethodsRequest::get_json()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

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