Skip to content

Commit 14c4acd

Browse files
committed
wip
1 parent ce47636 commit 14c4acd

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

openapi.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,22 @@
201201
"type": "number",
202202
"default": 0,
203203
"exclusiveMinimum": false,
204-
"minimum": 0
204+
"minimum": 0,
205+
"example": 10.0
205206
},
206207
"shippingCost": {
207208
"type": "number",
208209
"default": 0,
209210
"exclusiveMinimum": false,
210-
"minimum": 0
211+
"minimum": 0,
212+
"example": 10.0
211213
},
212214
"total": {
213215
"type": "number",
214216
"default": 0,
215217
"exclusiveMinimum": true,
216-
"minimum": 0
218+
"minimum": 0,
219+
"example": 25.0
217220
},
218221
"delivery": {
219222
"$ref": "#/components/schemas/Delivery"
@@ -283,10 +286,10 @@
283286
"nullable": true
284287
},
285288
"amount": {
286-
"type": "number",
287-
"exclusiveMinimum": true,
288-
"minimum": 0,
289-
"example": 1
289+
"type": "integer",
290+
"exclusiveMinimum": false,
291+
"minimum": 1,
292+
"description": "The quantity."
290293
},
291294
"price": {
292295
"type": "number",

src/Client.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
use Closure;
66
use Cone\SimplePay\Api\TransactionApi;
7+
use Exception;
78
use GuzzleHttp\Client as Http;
89
use GuzzleHttp\ClientInterface;
910
use GuzzleHttp\HandlerStack;
11+
use GuzzleHttp\Middleware;
1012
use GuzzleHttp\Promise\PromiseInterface;
1113
use GuzzleHttp\Psr7\Utils;
1214
use Psr\Http\Message\RequestInterface;
15+
use Psr\Http\Message\ResponseInterface;
1316

1417
class Client
1518
{
@@ -92,6 +95,27 @@ public function client(): ClientInterface
9295
};
9396
});
9497

98+
$stack->push(Middleware::mapResponse(function (ResponseInterface $response): ResponseInterface {
99+
$body = (string) $response->getBody();
100+
101+
if (! $this->validateSignature($response->getHeader('Signature')[0] ?? '', $body)) {
102+
throw new ApiException('Invalid Signature.', 999, $response->getHeaders(), $response->getBody());
103+
}
104+
105+
$body = json_decode($body, true) ?? [];
106+
107+
if (! empty($body['errorCodes'] ?? [])) {
108+
throw new ApiException(
109+
'SimplePay error.',
110+
(int) $body['errorCodes'][0] ?? 999,
111+
$response->getHeaders(),
112+
$response->getBody()
113+
);
114+
}
115+
116+
return $response;
117+
}));
118+
95119
return new Http([
96120
'handler' => $stack,
97121
]);

0 commit comments

Comments
 (0)