1 <?php
2 /**
3 * Copyright 2016 Klarna AB.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 namespace Klarna\XMLRPC;
18
19 /**
20 * Checkout service response class.
21 *
22 * @example docs/examples/checkoutService.php How to use the checkout service.
23 */
24 class CheckoutServiceResponse
25 {
26 /**
27 * Originating request.
28 *
29 * @var CheckoutServiceRequest
30 */
31 protected $request;
32
33 /**
34 * HTTP status code.
35 *
36 * @var int
37 */
38 protected $status;
39
40 /**
41 * Response data.
42 *
43 * @var array
44 */
45 protected $data;
46
47 /**
48 * Constructor.
49 *
50 * @param CheckoutServiceRequest $request The original request
51 * @param int $status HTTP status code
52 * @param string $data JSON string
53 *
54 * @throws \InvalidArgumentException
55 */
56 public function __construct($request, $status, $data)
57 {
58 $this->request = $request;
59 $this->status = $status;
60 $data = json_decode($data, true);
61
62 if ($data === null) {
63 throw new \InvalidArgumentException('Expected $data to be a valid JSON string');
64 }
65
66 $this->data = $data;
67 }
68
69 /**
70 * Get the original request.
71 *
72 * @return CheckoutServiceRequest The original request
73 */
74 public function getRequest()
75 {
76 return $this->request;
77 }
78
79 /**
80 * Get the response status code.
81 *
82 * @return int Status code
83 */
84 public function getStatus()
85 {
86 return $this->status;
87 }
88
89 /**
90 * Get the response data.
91 *
92 * @return array Response data
93 */
94 public function getData()
95 {
96 return $this->data;
97 }
98 }
99