Failed Conditions
Push — develop ( 397f1c...61c5d3 )
by Reüel
05:20
created

PaymentMethodsRequest::get_amount()   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
nc 1
nop 0
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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
	private $country_code;
36
37
	/**
38
	 * The amount information for the transaction.
39
	 *
40
	 * @var Amount|null
41
	 */
42
	private $amount;
43
44
	/**
45
	 * Construct a payment request object.
46
	 *
47
	 * @param string $merchant_account The merchant account identifier.
48
	 */
49 7
	public function __construct( $merchant_account ) {
50 7
		$this->merchant_account = $merchant_account;
51 7
	}
52
53
	/**
54
	 * Get country code.
55
	 *
56
	 * @return string|null
57
	 */
58 6
	public function get_country_code() {
59 6
		return $this->country_code;
60
	}
61
62
	/**
63
	 * Set the shopper's country code.
64
	 *
65
	 * @param string|null $country_code The shopper's country code.
66
	 */
67
	public function set_country_code( $country_code ) {
68
		$this->country_code = $country_code;
69
	}
70
71
	/**
72
	 * Get amount.
73
	 *
74
	 * @return Amount|null
75
	 */
76 6
	public function get_amount() {
77 6
		return $this->amount;
78
	}
79
80
	/**
81
	 * Set the amount information for the transaction.
82
	 *
83
	 * @param Amount|null $amount The amount information for the transaction.
84
	 */
85
	public function set_amount( Amount $amount = null ) {
86
		$this->amount = $amount;
87
	}
88
89
	/**
90
	 * Get JSON.
91
	 *
92
	 * @return object
93
	 */
94 6
	public function get_json() {
95 6
		$properties = Util::filter_null(
96
			array(
97 6
				'merchantAccount' => $this->merchant_account,
98 6
				'countryCode'     => $this->get_country_code(),
99
			)
100
		);
101
102 6
		if ( null !== $this->get_amount() ) {
103
			$properties['amount'] = $this->get_amount()->get_json();
104
		}
105
106
		// Return object.
107 6
		$object = (object) $properties;
108
109 6
		return $object;
110
	}
111
}
112