|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Payment result 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
|
|
|
use JsonSchema\Constraints\Constraint; |
|
15
|
|
|
use JsonSchema\Exception\ValidationException; |
|
16
|
|
|
use JsonSchema\Validator; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Payment result response |
|
20
|
|
|
* |
|
21
|
|
|
* @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/payments/result |
|
22
|
|
|
* |
|
23
|
|
|
* @author Remco Tolsma |
|
24
|
|
|
* @version 1.0.0 |
|
25
|
|
|
* @since 1.0.0 |
|
26
|
|
|
*/ |
|
27
|
|
|
class PaymentResultResponse extends ResponseObject { |
|
28
|
|
|
/** |
|
29
|
|
|
* A unique value that you provided in the initial `/paymentSession` request as a `reference` field. |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $merchant_reference; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The payment method used in the transaction. |
|
37
|
|
|
* |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
private $payment_method; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The shopperLocale value provided in the payment request |
|
44
|
|
|
* |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
private $shopper_locale; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* The result of the payment. |
|
51
|
|
|
* |
|
52
|
|
|
* @var string|null |
|
53
|
|
|
*/ |
|
54
|
|
|
private $result_code; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Adyen's 16-character string reference associated with the transaction/request. This value is globally unique; quote it when communicating with us about this request. |
|
58
|
|
|
* |
|
59
|
|
|
* @var string|null |
|
60
|
|
|
*/ |
|
61
|
|
|
private $psp_reference; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Construct payment result response object. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $merchant_reference Merchant reference. |
|
67
|
|
|
* @param string $payment_method Payment method. |
|
68
|
|
|
* @param string $shopper_locale Shopper locale. |
|
69
|
|
|
*/ |
|
70
|
2 |
|
public function __construct( $merchant_reference, $payment_method, $shopper_locale ) { |
|
71
|
2 |
|
$this->merchant_reference = $merchant_reference; |
|
72
|
2 |
|
$this->payment_method = $payment_method; |
|
73
|
2 |
|
$this->shopper_locale = $shopper_locale; |
|
74
|
2 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get merchant reference. |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
2 |
|
public function get_merchant_reference() { |
|
82
|
2 |
|
return $this->merchant_reference; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get payment method. |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
2 |
|
public function get_payment_method() { |
|
91
|
2 |
|
return $this->payment_method; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get shopper locale. |
|
96
|
|
|
* |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
2 |
|
public function get_shopper_locale() { |
|
100
|
2 |
|
return $this->shopper_locale; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get result code. |
|
105
|
|
|
* |
|
106
|
|
|
* @return string|null |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function get_result_code() { |
|
109
|
1 |
|
return $this->result_code; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Set result code. |
|
114
|
|
|
* |
|
115
|
|
|
* @param string|null $result_code Result code. |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function set_result_code( $result_code ) { |
|
119
|
1 |
|
$this->result_code = $result_code; |
|
120
|
1 |
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Get PSP reference. |
|
124
|
|
|
* |
|
125
|
|
|
* @return string|null |
|
126
|
|
|
*/ |
|
127
|
1 |
|
public function get_psp_reference() { |
|
128
|
1 |
|
return $this->psp_reference; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Set PSP reference. |
|
133
|
|
|
* |
|
134
|
|
|
* @param string|null $psp_reference PSP reference. |
|
135
|
|
|
* @return void |
|
136
|
|
|
*/ |
|
137
|
1 |
|
public function set_psp_reference( $psp_reference ) { |
|
138
|
1 |
|
$this->psp_reference = $psp_reference; |
|
139
|
1 |
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Create payment result repsonse from object. |
|
143
|
|
|
* |
|
144
|
|
|
* @param object $object Object. |
|
145
|
|
|
* @return PaymentResultResponse |
|
146
|
|
|
* @throws ValidationException Throws validation exception when object does not contains the required properties. |
|
147
|
|
|
*/ |
|
148
|
1 |
|
public static function from_object( $object ) { |
|
149
|
1 |
|
$validator = new Validator(); |
|
150
|
|
|
|
|
151
|
1 |
|
$validator->validate( |
|
152
|
1 |
|
$object, |
|
153
|
|
|
(object) array( |
|
154
|
1 |
|
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/payment-result.json' ), |
|
155
|
|
|
), |
|
156
|
1 |
|
Constraint::CHECK_MODE_EXCEPTIONS |
|
157
|
|
|
); |
|
158
|
|
|
|
|
159
|
1 |
|
$response = new self( |
|
160
|
1 |
|
$object->merchantReference, |
|
161
|
1 |
|
$object->paymentMethod, |
|
162
|
1 |
|
$object->shopperLocale |
|
163
|
|
|
); |
|
164
|
|
|
|
|
165
|
1 |
|
if ( isset( $object->pspReference ) ) { |
|
166
|
1 |
|
$response->set_psp_reference( $object->pspReference ); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
1 |
|
if ( isset( $object->resultCode ) ) { |
|
170
|
1 |
|
$response->set_result_code( $object->resultCode ); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
1 |
|
$response->set_original_object( $object ); |
|
174
|
|
|
|
|
175
|
1 |
|
return $response; |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|