1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Error |
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
|
|
|
* Error |
15
|
|
|
* |
16
|
|
|
* @link https://developers.acehubpaymentservices.com/v3.3/reference#payment-3-1 |
17
|
|
|
* @author Remco Tolsma |
18
|
|
|
* @version 1.0.0 |
19
|
|
|
* @since 1.0.0 |
20
|
|
|
*/ |
21
|
|
|
class Error extends \Exception { |
22
|
|
|
/** |
23
|
|
|
* Detailed message. |
24
|
|
|
* |
25
|
|
|
* A more detailed error message when available. If not available, contains the same as error.message. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $detailed_message; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Construct and initialize payment response |
33
|
|
|
* |
34
|
|
|
* @param int $code Code. |
35
|
|
|
* @param string $message Message. |
36
|
|
|
* @param string $detailed_message Detailed message. |
37
|
|
|
* @return void |
|
|
|
|
38
|
|
|
*/ |
39
|
2 |
|
public function __construct( $code, $message, $detailed_message ) { |
40
|
2 |
|
parent::__construct( $message, $code ); |
41
|
|
|
|
42
|
2 |
|
$this->detailed_message = $detailed_message; |
43
|
2 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* From JSON. |
47
|
|
|
* |
48
|
|
|
* @param object $object Object. |
49
|
|
|
* @return self |
50
|
|
|
* @throws \JsonSchema\Exception\ValidationException Throws exception when JSON is not valid. |
51
|
|
|
*/ |
52
|
1 |
View Code Duplication |
public static function from_json( $object ) { |
|
|
|
|
53
|
1 |
|
$validator = new \JsonSchema\Validator(); |
54
|
|
|
|
55
|
1 |
|
$validator->validate( |
56
|
1 |
|
$object, |
57
|
|
|
(object) array( |
58
|
1 |
|
'$ref' => 'file://' . \realpath( __DIR__ . '/../json-schemas/error.json' ), |
59
|
|
|
), |
60
|
1 |
|
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */ |
64
|
1 |
|
return new self( $object->code, $object->message, $object->detailedMessage ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get code. |
69
|
|
|
* |
70
|
|
|
* @return int|string |
71
|
|
|
*/ |
72
|
1 |
|
public function get_code() { |
73
|
1 |
|
return $this->getCode(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get message. |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
1 |
|
public function get_message() { |
82
|
1 |
|
return $this->getMessage(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get detailed message. |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function get_detailed_message() { |
91
|
|
|
return $this->detailed_message; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.