-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefundMapper.php
More file actions
46 lines (37 loc) · 1.62 KB
/
RefundMapper.php
File metadata and controls
46 lines (37 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* MIT License
* For full license information, please view the LICENSE file that was distributed with this source code.
*/
namespace Spryker\Client\PaymentTemplate\Api\Refund;
use Generated\Shared\Transfer\PaymentTemplateApiErrorResponseTransfer;
use Generated\Shared\Transfer\PaymentTemplateRefundRequestTransfer;
use Generated\Shared\Transfer\PaymentTemplateRefundResponseTransfer;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
class RefundMapper
{
public function mapRequest(PaymentTemplateRefundRequestTransfer $requestTransfer): string
{
return json_encode($requestTransfer->toArray());
}
public function mapResponse(ResponseInterface $httpResponse): PaymentTemplateRefundResponseTransfer
{
$responseBody = json_decode($httpResponse->getBody()->getContents(), true);
return (new PaymentTemplateRefundResponseTransfer())->fromArray($responseBody);
}
public function mapErrorResponse(RequestException $exception): PaymentTemplateRefundResponseTransfer
{
$errorResponseTransfer = (new PaymentTemplateApiErrorResponseTransfer())
->setMessage($exception->getMessage())
->setStatusCode($exception->getCode());
if ($exception->hasResponse()) {
$errorResponseTransfer
->setStatusCode($exception->getResponse()->getStatusCode())
->setBody($exception->getResponse()->getBody()->getContents());
}
return (new PaymentTemplateRefundResponseTransfer())
->setIsSuccess(false)
->setErrorResponse($errorResponseTransfer);
}
}