|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Payment 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\Payvision |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Payvision; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Payment Response |
|
15
|
|
|
* |
|
16
|
|
|
* @author Remco Tolsma |
|
17
|
|
|
* @version 1.0.0 |
|
18
|
|
|
* @since 1.0.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class PaymentResponse { |
|
21
|
|
|
/** |
|
22
|
|
|
* Redirect. |
|
23
|
|
|
* |
|
24
|
|
|
* @var RedirectDetails|null |
|
25
|
|
|
*/ |
|
26
|
|
|
public $redirect; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Transaction. |
|
30
|
|
|
* |
|
31
|
|
|
* @var TransactionResponse|null |
|
32
|
|
|
*/ |
|
33
|
|
|
public $transaction; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* The result of the payment. |
|
37
|
|
|
* |
|
38
|
|
|
* @link https://developers.acehubpaymentservices.com/v3.3/reference#result-codes-2 |
|
39
|
|
|
* @var int |
|
40
|
|
|
*/ |
|
41
|
|
|
private $result; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* A short description of the result. |
|
45
|
|
|
* |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
private $description; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Header. |
|
52
|
|
|
* |
|
53
|
|
|
* @var ResponseHeader |
|
54
|
|
|
*/ |
|
55
|
|
|
private $header; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Error. |
|
59
|
|
|
* |
|
60
|
|
|
* @var Error|null |
|
61
|
|
|
*/ |
|
62
|
|
|
private $error; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Construct and initialize payment response |
|
66
|
|
|
* |
|
67
|
|
|
* @param int $result Result. |
|
68
|
|
|
* @param string $description Description. |
|
69
|
|
|
* @param ResponseHeader $header Header. |
|
70
|
|
|
*/ |
|
71
|
4 |
|
public function __construct( $result, $description, $header ) { |
|
72
|
4 |
|
$this->result = $result; |
|
73
|
4 |
|
$this->description = $description; |
|
74
|
4 |
|
$this->header = $header; |
|
75
|
4 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* From JSON. |
|
79
|
|
|
* |
|
80
|
|
|
* @param object $object Object. |
|
81
|
|
|
* @return self |
|
82
|
|
|
* @throws \JsonSchema\Exception\ValidationException Throws exception when JSON is not valid. |
|
83
|
|
|
*/ |
|
84
|
3 |
|
public static function from_json( $object ) { |
|
85
|
3 |
|
$validator = new \JsonSchema\Validator(); |
|
86
|
|
|
|
|
87
|
3 |
|
$validator->validate( |
|
88
|
3 |
|
$object, |
|
89
|
|
|
(object) array( |
|
90
|
3 |
|
'$ref' => 'file://' . \realpath( __DIR__ . '/../json-schemas/payment-response.json' ), |
|
91
|
|
|
), |
|
92
|
3 |
|
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
3 |
|
$response = new self( $object->result, $object->description, ResponseHeader::from_json( $object->header ) ); |
|
96
|
|
|
|
|
97
|
3 |
|
if ( \property_exists( $object->body, 'transaction' ) ) { |
|
98
|
3 |
|
$response->transaction = TransactionResponse::from_json( $object->body->transaction ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
3 |
|
if ( \property_exists( $object->body, 'redirect' ) ) { |
|
102
|
2 |
|
$response->redirect = RedirectDetails::from_json( $object->body->redirect ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
3 |
|
if ( \property_exists( $object->body, 'error' ) ) { |
|
106
|
|
|
$response->set_error( Error::from_json( $object->body->error ) ); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
3 |
|
return $response; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get result. |
|
114
|
|
|
* |
|
115
|
|
|
* @return int |
|
116
|
|
|
*/ |
|
117
|
3 |
|
public function get_result() { |
|
118
|
3 |
|
return $this->result; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Get description. |
|
123
|
|
|
* |
|
124
|
|
|
* @return string |
|
125
|
|
|
*/ |
|
126
|
1 |
|
public function get_description() { |
|
127
|
1 |
|
return $this->description; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Get header. |
|
132
|
|
|
* |
|
133
|
|
|
* @return ResponseHeader |
|
134
|
|
|
*/ |
|
135
|
1 |
|
public function get_header() { |
|
136
|
1 |
|
return $this->header; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Get error. |
|
141
|
|
|
* |
|
142
|
|
|
* @return Error|null |
|
143
|
|
|
*/ |
|
144
|
2 |
|
public function get_error() { |
|
145
|
2 |
|
return $this->error; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Set error. |
|
150
|
|
|
* |
|
151
|
|
|
* @param Error|null $error Error. |
|
152
|
|
|
* @return void |
|
153
|
|
|
*/ |
|
154
|
|
|
public function set_error( Error $error = null ) { |
|
155
|
|
|
$this->error = $error; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|