|
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
|
1 |
|
} |
|
76
|
1 |
|
|
|
77
|
|
|
/** |
|
78
|
1 |
|
* Create payment methods repsonse from object. |
|
79
|
1 |
|
* |
|
80
|
|
|
* @param object $object Object. |
|
81
|
1 |
|
* @return PaymentMethodsResponse |
|
82
|
|
|
* @throws ValidationException Throws validation exception when object does not contains the required properties. |
|
83
|
1 |
|
*/ |
|
84
|
|
|
public static function from_object( $object ) { |
|
85
|
|
|
$validator = new Validator(); |
|
86
|
1 |
|
|
|
87
|
|
|
$validator->validate( |
|
88
|
|
|
$object, |
|
89
|
|
|
(object) array( |
|
90
|
|
|
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/payment-methods-response.json' ), |
|
91
|
|
|
), |
|
92
|
|
|
Constraint::CHECK_MODE_EXCEPTIONS |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
$response = new self( $object->groups, $object->paymentMethods ); |
|
96
|
|
|
|
|
97
|
|
|
if ( isset( $object->oneClickPaymentMethods ) ) { |
|
98
|
|
|
$response->set_one_click_payment_methods( $object->oneClickPaymentMethods ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
$response->set_original_object( $object ); |
|
102
|
|
|
|
|
103
|
|
|
return $object; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|