StripeException::getHeaders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
crap 2
1
<?php namespace Arcanedev\Stripe\Exceptions;
2
3
use Exception;
4
5
/**
6
 * Class     StripeException
7
 *
8
 * @package  Arcanedev\Stripe\Bases
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
abstract class StripeException extends Exception
12
{
13
    /* -----------------------------------------------------------------
14
     |  Properties
15
     | -----------------------------------------------------------------
16
     */
17
18
    /**
19
     * Stripe Error type.
20
     *
21
     * @var string|null
22
     */
23
    protected $type;
24
25
    /**
26
     * Stripe Error code.
27
     *
28
     * @var string|null
29
     */
30
    protected $stripeCode;
31
32
    /**
33
     * HTTP Response Body (json).
34
     *
35
     * @var string|null
36
     */
37
    protected $httpBody;
38
39
    /**
40
     * HTTP Response Body (array).
41
     *
42
     * @var array|null
43
     */
44
    protected $jsonBody;
45
46
    /**
47
     * Parameters.
48
     *
49
     * @var array
50
     */
51
    protected $params = [];
52
53
    /**
54
     * Headers.
55
     *
56
     * @var array
57
     */
58
    protected $headers;
59
60
    /**
61
     * Request ID.
62
     *
63
     * @var string
64
     */
65
    protected $requestId;
66
67
    /* -----------------------------------------------------------------
68
     |  Constructor
69
     | -----------------------------------------------------------------
70
     */
71
72
    /**
73
     * Create Stripe Exception instance.
74
     *
75
     * @param  string       $message
76
     * @param  int          $code
77
     * @param  string|null  $type
78
     * @param  string|null  $stripeCode
79
     * @param  string|null  $httpBody
80
     * @param  array        $jsonBody
81
     * @param  array        $params
82
     * @param  array        $headers
83
     */
84 148
    public function __construct(
85
        $message,
86
        $code = 0,
87
        $type = null,
88
        $stripeCode = null,
89
        $httpBody = null,
90
        $jsonBody = [],
91
        $params = [],
92
        $headers = []
93
    ) {
94 148
        parent::__construct($message, $code);
95
96
        // Stripe Properties
97
        //--------------------------------------
98 148
        $this->setType($type);
99 148
        $this->setStripeCode($stripeCode);
100 148
        $this->setHttpBody($httpBody);
101 148
        $this->setJsonBody($jsonBody);
102 148
        $this->setParams($params);
103 148
        $this->setHeaders($headers);
104 148
        $this->setRequestId(isset($headers['Request-Id']) ? $headers['Request-Id'] : null);
105 148
    }
106
107
    /* -----------------------------------------------------------------
108
     |  Getters & Setters
109
     | -----------------------------------------------------------------
110
     */
111
112
    /**
113
     * Get Stripe Error type.
114
     *
115
     * @return string
116
     */
117 4
    public function getType()
118
    {
119 4
        return $this->type;
120
    }
121
122
    /**
123
     * Set Type.
124
     *
125
     * @param  string|null  $type
126
     *
127
     * @return self
128
     */
129 148
    private function setType($type)
130
    {
131 148
        $this->type = $type;
132
133 148
        return $this;
134
    }
135
136
    /**
137
     * Get Stripe code.
138
     *
139
     * @return string|null
140
     */
141 8
    public function getStripeCode()
142
    {
143 8
        return $this->stripeCode;
144
    }
145
146
    /**
147
     * Set Stripe code.
148
     *
149
     * @param  string|null  $stripeCode
150
     *
151
     * @return self
152
     */
153 148
    private function setStripeCode($stripeCode)
154
    {
155 148
        $this->stripeCode = $stripeCode;
156
157 148
        return $this;
158
    }
159
160
    /**
161
     * Get HTTP status code.
162
     *
163
     * @return int
164
     */
165 4
    public function getHttpStatus()
166
    {
167 4
        return $this->getCode();
168
    }
169
170
    /**
171
     * Get HTTP Body.
172
     *
173
     * @return string|null
174
     */
175 2
    public function getHttpBody()
176
    {
177 2
        return $this->httpBody;
178
    }
179
180
    /**
181
     * Set HTTP Body.
182
     *
183
     * @param  string|null  $httpBody
184
     *
185
     * @return self
186
     */
187 148
    private function setHttpBody($httpBody)
188
    {
189 148
        $this->httpBody = $httpBody;
190
191 148
        return $this;
192
    }
193
194
    /**
195
     * Get Json Body.
196
     *
197
     * @return array|null
198
     */
199 4
    public function getJsonBody()
200
    {
201 4
        return $this->jsonBody;
202
    }
203
204
    /**
205
     * Set Json Body.
206
     *
207
     * @param  array|null  $jsonBody
208
     *
209
     * @return self
210
     */
211 148
    private function setJsonBody($jsonBody)
212
    {
213 148
        $this->jsonBody = $jsonBody;
214
215 148
        return $this;
216
    }
217
218
    /**
219
     * Get Parameters.
220
     *
221
     * @return array
222
     */
223 4
    public function getParams()
224
    {
225 4
        return $this->params;
226
    }
227
228
    /**
229
     * Set parameters.
230
     *
231
     * @param  array  $params
232
     *
233
     * @return self
234
     */
235 148
    private function setParams($params)
236
    {
237 148
        $this->params = $params;
238
239 148
        return $this;
240
    }
241
242
    /**
243
     * Get the response headers.
244
     *
245
     * @return array
246
     */
247
    public function getHeaders()
248
    {
249
        return $this->headers;
250
    }
251
252
    /**
253
     * Set the response headers.
254
     *
255
     * @param  array  $headers
256
     *
257
     * @return self
258
     */
259 148
    private function setHeaders($headers)
260
    {
261 148
        $this->headers = $headers;
262
263 148
        return $this;
264
    }
265
266
    /**
267
     * Get the Request ID.
268
     *
269
     * @return string|null
270
     */
271 2
    public function getRequestId()
272
    {
273 2
        return $this->requestId;
274
    }
275
276
    /**
277
     * Set the Request ID.
278
     *
279
     * @param  string  $requestId
280
     *
281
     * @return $this
282
     */
283 148
    private function setRequestId($requestId)
284
    {
285 148
        $this->requestId = $requestId;
286
287 148
        return $this;
288
    }
289
}
290