PaymentSessionResponse   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_payment_session() 0 2 1
A __construct() 0 2 1
A from_object() 0 13 1
1
<?php
2
/**
3
 * Payment session response
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
use JsonSchema\Constraints\Constraint;
14
use JsonSchema\Exception\ValidationException;
15
use JsonSchema\Validator;
16
17
/**
18
 * Payment session 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 PaymentSessionResponse extends ResponseObject {
27
	/**
28
	 * The encoded payment session that you need to pass to the SDK.
29
	 *
30
	 * @var string
31
	 */
32
	private $payment_session;
33
34
	/**
35
	 * Construct payment session response object.
36
	 *
37
	 * @param string $payment_session The encoded payment session.
38
	 */
39 2
	public function __construct( $payment_session ) {
40 2
		$this->payment_session = $payment_session;
41 2
	}
42
43
	/**
44
	 * Get payment session.
45
	 *
46
	 * @return string
47
	 */
48 2
	public function get_payment_session() {
49 2
		return $this->payment_session;
50
	}
51
52
	/**
53
	 * Create payment session repsonse from object.
54
	 *
55
	 * @param object $object Object.
56
	 * @return PaymentSessionResponse
57
	 * @throws ValidationException Throws validation exception when object does not contains the required properties.
58
	 */
59 1
	public static function from_object( $object ) {
60 1
		$validator = new Validator();
61
62 1
		$validator->validate(
63 1
			$object,
64
			(object) array(
65 1
				'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/payment-session-response.json' ),
66
			),
67 1
			Constraint::CHECK_MODE_EXCEPTIONS
68
		);
69
70
		// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Adyen JSON object.
71 1
		return new self( $object->paymentSession );
72
	}
73
}
74