1: <?php
2: /*
3: * This file was automatically generated.
4: */
5: namespace Worldline\Acquiring\Sdk\V1;
6:
7: use RuntimeException;
8: use Worldline\Acquiring\Sdk\Domain\DataObject;
9:
10: /**
11: * Class ApiException
12: *
13: * @package Worldline\Acquiring\Sdk\V1
14: */
15: class ApiException extends RuntimeException
16: {
17: /** @var int */
18: private $httpStatusCode;
19:
20: /**
21: * @var DataObject
22: */
23: private $response;
24:
25: /**
26: * @param int $httpStatusCode
27: * @param DataObject $response
28: * @param string $message
29: */
30: public function __construct($httpStatusCode, DataObject $response, $message = null)
31: {
32: if (is_null($message)) {
33: $message = 'The Worldline Acquiring platform returned an error response';
34: }
35: parent::__construct($message);
36: $this->httpStatusCode = $httpStatusCode;
37: $this->response = $response;
38: }
39:
40: public function __toString()
41: {
42: return sprintf(
43: "exception '%s' with message '%s'. in %s:%d\nHTTP status code: %s\nResponse:\n%s\nStack trace:\n%s",
44: __CLASS__,
45: $this->getMessage(),
46: $this->getFile(),
47: $this->getLine(),
48: $this->getHttpStatusCode(),
49: json_encode($this->getResponse(), JSON_PRETTY_PRINT),
50: $this->getTraceAsString()
51: );
52: }
53:
54: /**
55: * @return int
56: */
57: public function getHttpStatusCode()
58: {
59: return $this->httpStatusCode;
60: }
61:
62: /**
63: * @return DataObject
64: */
65: public function getResponse()
66: {
67: return $this->response;
68: }
69:
70: /**
71: * @return string
72: */
73: public function getType()
74: {
75: $responseVariables = get_object_vars($this->getResponse());
76: if (!array_key_exists('type', $responseVariables)) {
77: return '';
78: }
79: return $responseVariables['type'];
80: }
81:
82: /**
83: * @return string
84: */
85: public function getTitle()
86: {
87: $responseVariables = get_object_vars($this->getResponse());
88: if (!array_key_exists('title', $responseVariables)) {
89: return '';
90: }
91: return $responseVariables['title'];
92: }
93:
94: /**
95: * @return int
96: */
97: public function getStatus()
98: {
99: $responseVariables = get_object_vars($this->getResponse());
100: if (!array_key_exists('status', $responseVariables)) {
101: return 0;
102: }
103: return $responseVariables['status'];
104: }
105:
106: /**
107: * @return string
108: */
109: public function getDetail()
110: {
111: $responseVariables = get_object_vars($this->getResponse());
112: if (!array_key_exists('detail', $responseVariables)) {
113: return '';
114: }
115: return $responseVariables['detail'];
116: }
117:
118: /**
119: * @return string
120: */
121: public function getInstance()
122: {
123: $responseVariables = get_object_vars($this->getResponse());
124: if (!array_key_exists('instance', $responseVariables)) {
125: return '';
126: }
127: return $responseVariables['instance'];
128: }
129: }
130: