Passed
Push — develop ( b0da7b...3de7dc )
by Remco
03:38
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 payment methods required to generate payment forms.
36
	 *
37
	 * @var array
38
	 */
39
	private $payment_methods;
40
41
	/**
42
	 * Construct payment session response object.
43
	 *
44
	 * @param array $groups          Groups.
45
	 * @param array $payment_methods Payment methods.
46
	 */
47 2
	public function __construct( $groups, $payment_methods ) {
48 2
		$this->groups          = $groups;
49 2
		$this->payment_methods = $payment_methods;
50 2
	}
51
52
	/**
53
	 * Get payment methods.
54
	 *
55
	 * @return array
56
	 */
57 2
	public function get_payment_methods() {
58 2
		return $this->payment_methods;
59
	}
60
61
	/**
62
	 * Create payment methods repsonse from object.
63
	 *
64
	 * @param object $object Object.
65
	 * @return PaymentMethodsResponse
66
	 * @throws ValidationException Throws validation exception when object does not contains the required properties.
67
	 */
68 2
	public static function from_object( $object ) {
69 2
		$validator = new Validator();
70
71 2
		$validator->validate(
72 2
			$object,
73
			(object) array(
74 2
				'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/payment-methods-response.json' ),
75
			),
76 2
			Constraint::CHECK_MODE_EXCEPTIONS
77
		);
78
79 2
		$response = new self( $object->groups, $object->paymentMethods );
80
81 2
		$response->set_original_object( $object );
82
83 2
		return $response;
84
	}
85
}
86