Failed Conditions
Push — develop ( 0b29b3...e9481e )
by Remco
03:53 queued 10s
created

PaymentSessionResponse::__construct()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Payment session 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 InvalidArgumentException;
14
15
/**
16
 * Payment session response
17
 *
18
 * @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/paymentSession
19
 *
20
 * @author  Remco Tolsma
21
 * @version 1.0.0
22
 * @since   1.0.0
23
 */
24
class PaymentSessionResponse {
25
	/**
26
	 * The encoded payment session that you need to pass to the SDK.
27
	 *
28
	 * @var string
29
	 */
30
	private $payment_session;
31
32
	/**
33
	 * Construct payment session response object.
34
	 *
35
	 * @param string $payment_session The encoded payment session.
36
	 */
37
	public function __construct( $payment_session ) {
38
		$this->payment_session = $payment_session;
39
	}
40
41
	/**
42
	 * Get payment session.
43
	 *
44
	 * @return string
45
	 */
46
	public function get_payment_session() {
47
		return $this->payment_session;
48
	}
49
50
	/**
51
	 * Create payment session repsonse from object.
52
	 *
53
	 * @param object $object Object.
54
	 * @return PaymentSessionResponse
55
	 * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties.
56
	 */
57
	public static function from_object( $object ) {
58
		if ( ! isset( $object->paymentSession ) ) {
59
			throw new InvalidArgumentException( 'Object must contain `paymentSession` property.' );
60
		}
61
62
		return new self( $object->paymentSession );
63
	}
64
}
65