Test Failed
Push — develop ( 61c5d3...602393 )
by Reüel
06:05
created

get_allowed_payment_methods()   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 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
rs 10
ccs 0
cts 0
cp 0
crap 2
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|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 7
	private $amount;
50 7
51 7
	/**
52
	 * Construct a payment request object.
53
	 *
54
	 * @param string $merchant_account The merchant account identifier.
55
	 */
56
	public function __construct( $merchant_account ) {
57
		$this->merchant_account = $merchant_account;
58 6
	}
59 6
60
	/**
61
	 * Get allowed payment methods.
62
	 *
63
	 * @return array<int, string>|null
64
	 */
65
	public function get_allowed_payment_methods() {
66
		return $this->allowed_payment_methods;
67
	}
68
69
	/**
70
	 * Set allowed payment methods.
71
	 *
72
	 * @param array $allowed_payment_methods Allowed payment methods.
73
	 */
74
	public function set_allowed_payment_methods( $allowed_payment_methods ) {
75
		$this->allowed_payment_methods = $allowed_payment_methods;
76 6
	}
77 6
78
	/**
79
	 * Get country code.
80
	 *
81
	 * @return string|null
82
	 */
83
	public function get_country_code() {
84
		return $this->country_code;
85
	}
86
87
	/**
88
	 * Set the shopper's country code.
89
	 *
90
	 * @param string|null $country_code The shopper's country code.
91
	 */
92
	public function set_country_code( $country_code ) {
93
		$this->country_code = $country_code;
94 6
	}
95 6
96
	/**
97 6
	 * Get amount.
98 6
	 *
99
	 * @return Amount|null
100
	 */
101
	public function get_amount() {
102 6
		return $this->amount;
103
	}
104
105
	/**
106
	 * Set the amount information for the transaction.
107 6
	 *
108
	 * @param Amount|null $amount The amount information for the transaction.
109 6
	 */
110
	public function set_amount( Amount $amount = null ) {
111
		$this->amount = $amount;
112
	}
113
114
	/**
115
	 * Get JSON.
116
	 *
117
	 * @return object
118
	 */
119
	public function get_json() {
120
		$properties = Util::filter_null(
121
			array(
122
				'merchantAccount'       => $this->merchant_account,
123
				'countryCode'           => $this->get_country_code(),
124
				'allowedPaymentMethods' => $this->get_allowed_payment_methods(),
125
			)
126
		);
127
128
		if ( null !== $this->get_amount() ) {
129
			$properties['amount'] = $this->get_amount()->get_json();
130
		}
131
132
		// Return object.
133
		$object = (object) $properties;
134
135
		return $object;
136
	}
137
}
138