1 | <?php |
||
12 | class RestAuthorizeRequest extends AbstractRequest |
||
13 | { |
||
14 | 6 | public function getEndpoint() |
|
18 | |||
19 | 6 | public function getHttpMethod() |
|
23 | |||
24 | 6 | public function getFirstName() |
|
28 | |||
29 | public function setFirstName($value) |
||
33 | |||
34 | 6 | public function getLastName() |
|
38 | |||
39 | public function setLastName($value) |
||
43 | |||
44 | 6 | public function getEmail() |
|
48 | |||
49 | public function setEmail($value) |
||
53 | |||
54 | 6 | public function getReference() |
|
58 | |||
59 | public function setReference($value) |
||
63 | |||
64 | 6 | public function getMeta() |
|
68 | |||
69 | public function setMeta($value) |
||
73 | |||
74 | 6 | public function hasMetaData() |
|
78 | |||
79 | 6 | public function getData() |
|
80 | { |
||
81 | 6 | $this->validate( |
|
82 | 6 | 'amount', |
|
83 | 6 | 'currency', |
|
84 | 4 | 'returnUrl' |
|
85 | 2 | ); |
|
86 | |||
87 | 6 | $data = $this->getBaseData(); |
|
88 | |||
89 | 6 | $data['shopper']['first_name'] = $this->getFirstName(); |
|
90 | 6 | $data['shopper']['last_name'] = $this->getLastName(); |
|
91 | 6 | $data['shopper']['email'] = $this->getEmail(); |
|
92 | 6 | $data['shopper']['billing_address'] = $this->getBillingAddress(); |
|
93 | 6 | $data['order'] = $this->getOrder(); |
|
94 | 6 | $data['config'] = $this->getConfig(); |
|
95 | |||
96 | 6 | if ($this->hasMetaData()) { |
|
97 | $data['metadata'] = $this->getMetaData(); |
||
98 | } |
||
99 | |||
100 | 6 | return $data; |
|
101 | } |
||
102 | |||
103 | 6 | public function getBillingAddress() |
|
104 | { |
||
105 | return [ |
||
106 | 6 | 'line1' => $this->getBillingAddressLine1(), |
|
107 | 6 | 'city' => $this->getBillingAddressCity(), |
|
108 | 6 | 'state' => $this->getBillingAddressState(), |
|
109 | 6 | 'postal_code' => $this->getBillingAddressPostalCode(), |
|
110 | 6 | 'country' => $this->getBillingAddressCountry(), |
|
111 | 6 | 'first_name' => $this->getBillingAddressFirstName(), |
|
112 | 6 | 'last_name' => $this->getBillingAddressLastName(), |
|
113 | 2 | ]; |
|
114 | } |
||
115 | |||
116 | 6 | public function getOrder() |
|
117 | { |
||
118 | return [ |
||
119 | 6 | 'reference' => $this->getReference(), |
|
120 | 6 | 'amount' => $this->getAmount(), |
|
121 | 6 | 'currency' => $this->getCurrency(), |
|
122 | 6 | 'shipping' => $this->getOrderShippingDetails(), |
|
123 | 6 | 'items' => $this->getOrderItems(), |
|
124 | 2 | ]; |
|
125 | } |
||
126 | |||
127 | 6 | public function getOrderItems() |
|
128 | { |
||
129 | 6 | $data = []; |
|
130 | 6 | $items = $this->getItems(); |
|
131 | |||
132 | 6 | if ($items) { |
|
133 | foreach ($items as $item) { |
||
134 | $data[] = $this->convertItemToItemData($item); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | 6 | return $data; |
|
139 | } |
||
140 | |||
141 | protected function convertItemToItemData(ItemInterface $item) |
||
142 | { |
||
143 | return [ |
||
144 | 'name' => $item->getName(), |
||
145 | 'amount' => $item->getQuantity() * $this->formatCurrency($item->getPrice()), |
||
146 | 'quantity' => $item->getQuantity(), |
||
147 | 'type' => 'sku', |
||
148 | 'reference' => $item->getReference(), |
||
149 | 'image_uri' => $item->getImageUri(), |
||
150 | ]; |
||
151 | } |
||
152 | |||
153 | 6 | public function getOrderShippingDetails() |
|
154 | { |
||
155 | return [ |
||
156 | 6 | 'pickup' => true, |
|
157 | 2 | ]; |
|
158 | } |
||
159 | |||
160 | 6 | public function getConfig() |
|
161 | { |
||
162 | return [ |
||
163 | 6 | 'redirect_uri' => $this->getReturnUrl(), |
|
164 | 2 | ]; |
|
165 | } |
||
166 | |||
167 | public function getMetaData() |
||
171 | |||
172 | 6 | public function getBillingAddressLine1() |
|
176 | |||
177 | 6 | public function getBillingAddressCity() |
|
181 | |||
182 | 6 | public function getBillingAddressState() |
|
186 | |||
187 | 6 | public function getBillingAddressPostalCode() |
|
191 | |||
192 | 6 | public function getBillingAddressCountry() |
|
196 | |||
197 | 6 | public function getBillingAddressFirstName() |
|
201 | |||
202 | 6 | public function getBillingAddressLastName() |
|
206 | |||
207 | 6 | protected function createResponse($data, $headers = [], $status = 404) |
|
211 | } |
||
212 |