Failed Conditions
Push — develop ( 008823...2959a9 )
by Remco
09:03 queued 05:30
created

PaymentMethodsResponse::get_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 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 0
b 0
f 0
1
<?php
2
/**
3
 * Payment methods response
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 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
use JsonSchema\Constraints\Constraint;
14
use JsonSchema\Exception\ValidationException;
15
use JsonSchema\Validator;
16
17
/**
18
 * Payment methods response
19
 *
20
 * @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/paymentSession
21
 *
22
 * @author  Remco Tolsma
23
 * @version 1.0.0
24
 * @since   1.0.0
25
 */
26
class PaymentMethodsResponse extends ResponseObject {
27
	/**
28
	 * Groups of payment methods.
29
	 *
30
	 * @var array
31
	 */
32
	private $groups;
33
34
	/**
35
	 * Detailed list of one-click payment methods.
36
	 *
37
	 * @var array
38
	 */
39
	private $one_click_payment_methods;
40
41
	/**
42
	 * Detailed list of payment methods required to generate payment forms.
43
	 *
44
	 * @var array
45
	 */
46
	private $payment_methods;
47
48
	/**
49
	 * Construct payment session response object.
50
	 *
51
	 * @param array $groups          Groups.
52
	 * @param array $payment_methods Payment methods.
53
	 */
54 1
	public function __construct( $groups, $payment_methods ) {
55 1
		$this->groups          = $groups;
56 1
		$this->payment_methods = $payment_methods;
57 1
	}
58
59
	/**
60
	 * Get payment methods.
61
	 *
62
	 * @return array
63
	 */
64 1
	public function get_payment_methods() {
65 1
		return $this->payment_methods;
66
	}
67
68
	/**
69
	 * Set one-click payment methods.
70
	 *
71
	 * @param array|null $one_click_payment_methods One-click payment methods.
72
	 */
73
	public function set_one_click_payment_methods( $one_click_payment_methods ) {
74
		$this->one_click_payment_methods = $one_click_payment_methods;
75
	}
76
77
	/**
78
	 * Create payment methods repsonse from object.
79
	 *
80
	 * @param object $object Object.
81
	 * @return PaymentMethodsResponse
82
	 * @throws ValidationException Throws validation exception when object does not contains the required properties.
83
	 */
84 1
	public static function from_object( $object ) {
85 1
		$validator = new Validator();
86
87 1
		$validator->validate(
88 1
			$object,
89
			(object) array(
90 1
				'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/payment-methods-response.json' ),
91
			),
92 1
			Constraint::CHECK_MODE_EXCEPTIONS
93
		);
94
95 1
		$response = new self( $object->groups, $object->paymentMethods );
96
97 1
		if ( isset( $object->oneClickPaymentMethods ) ) {
98
			$response->set_one_click_payment_methods( $object->oneClickPaymentMethods );
99
		}
100
101 1
		$response->set_original_object( $object );
102
103 1
		return $response;
104
	}
105
}
106