|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Service exception |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2019 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Pay\Gateways\OmniKassa2 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Adyen; |
|
12
|
|
|
|
|
13
|
|
|
use InvalidArgumentException; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Service exception |
|
17
|
|
|
* |
|
18
|
|
|
* @link https://docs.adyen.com/developers/api-reference/common-api/serviceexception |
|
19
|
|
|
* |
|
20
|
|
|
* @author Remco Tolsma |
|
21
|
|
|
* @version 1.0.0 |
|
22
|
|
|
* @since 1.0.0 |
|
23
|
|
|
*/ |
|
24
|
|
|
class ServiceException { |
|
25
|
|
|
/** |
|
26
|
|
|
* The HTTP response status code. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
private $status; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The Adyen code that is mapped to the error message. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
private $error_code; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The message, a short explanation of the issue. |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
private $message; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The type of error that was encountered. |
|
48
|
|
|
* |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
private $error_type; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Construct service exception. |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $status Status. |
|
57
|
|
|
* @param string $error_code Error code. |
|
58
|
|
|
* @param string $message Message. |
|
59
|
|
|
* @param string $error_type Error type. |
|
60
|
|
|
*/ |
|
61
|
|
|
public function __construct( $status, $error_code, $message, $error_type ) { |
|
62
|
|
|
$this->status = $status; |
|
63
|
|
|
$this->error_code = $error_code; |
|
64
|
|
|
$this->message = $message; |
|
65
|
|
|
$this->error_type = $error_type; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get status. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
public function get_status() { |
|
74
|
|
|
return $this->status; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Get error code. |
|
79
|
|
|
* |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
public function get_error_code() { |
|
83
|
|
|
return $this->error_code; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get message. |
|
88
|
|
|
* |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
public function get_message() { |
|
92
|
|
|
return $this->message; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Get error type. |
|
97
|
|
|
* |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
|
|
public function get_error_type() { |
|
101
|
|
|
return $this->error_type; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Create service exception from object. |
|
106
|
|
|
* |
|
107
|
|
|
* @param object $object Object. |
|
108
|
|
|
* @return ServiceException |
|
109
|
|
|
* @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties. |
|
110
|
|
|
*/ |
|
111
|
|
|
public static function from_object( $object ) { |
|
112
|
|
|
if ( ! isset( $object->status ) ) { |
|
113
|
|
|
throw new InvalidArgumentException( 'Object must contain `status` property.' ); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
if ( ! isset( $object->errorCode ) ) { |
|
117
|
|
|
throw new InvalidArgumentException( 'Object must contain `errorCode` property.' ); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
if ( ! isset( $object->message ) ) { |
|
121
|
|
|
throw new InvalidArgumentException( 'Object must contain `message` property.' ); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
if ( ! isset( $object->errorType ) ) { |
|
125
|
|
|
throw new InvalidArgumentException( 'Object must contain `errorType` property.' ); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return new self( |
|
129
|
|
|
$object->status, |
|
130
|
|
|
$object->errorCode, |
|
131
|
|
|
$object->message, |
|
132
|
|
|
$object->errorType |
|
133
|
|
|
); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|