| Conditions | 8 |
| Paths | 208 |
| Total Lines | 156 |
| Code Lines | 124 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 154 | public function process_button() |
||
| 155 | { |
||
| 156 | try { |
||
| 157 | include_once('./ext/modules/payment/pagantis/vendor/autoload.php'); |
||
| 158 | global $order, $customer_id, $sendto, $billto, $cart, $languages_id, $currency, $currencies, $shipping, $payment, $comments, $customer_default_address_id, $cartID; |
||
| 159 | $global_vars = array(); |
||
| 160 | $global_vars['customer_id'] = serialize($customer_id); |
||
| 161 | $global_vars['sendTo'] = serialize($sendto); |
||
| 162 | $global_vars['billTo'] = serialize($billto); |
||
| 163 | $global_vars['cart'] = serialize($cart); |
||
| 164 | $global_vars['languages_id'] = serialize($languages_id); |
||
| 165 | $global_vars['currency'] = serialize($currency); |
||
| 166 | $global_vars['currencies'] = serialize($currencies); |
||
| 167 | $global_vars['shipping'] = serialize($shipping); |
||
| 168 | $global_vars['payment'] = serialize($payment); |
||
| 169 | $global_vars['comments'] = serialize($comments); |
||
| 170 | $global_vars['$customer_default_address_id'] = serialize($customer_default_address_id); |
||
| 171 | $global_vars['cartID'] = serialize($cartID); |
||
| 172 | $global_vars['sessiontoken'] = serialize($_SESSION['sessiontoken']); |
||
| 173 | |||
| 174 | if (!isset($order)) { |
||
| 175 | throw new UnknownException("Order not found"); |
||
| 176 | } |
||
| 177 | |||
| 178 | $id_hash = time().serialize($order->products).''.serialize($order->customer).''.serialize($order->delivery); |
||
| 179 | $this->os_order_reference = md5($id_hash); |
||
| 180 | $_SESSION['order_id'] = $this->os_order_reference; |
||
| 181 | |||
| 182 | $userAddress = new Address(); |
||
| 183 | $userAddress |
||
| 184 | ->setZipCode($order->billing['postcode']) |
||
| 185 | ->setFullName($order->billing['firstname'].' '.$order->billing['lastname']) |
||
| 186 | ->setCountryCode('ES') |
||
| 187 | ->setCity($order->billing['city']) |
||
| 188 | ->setAddress($order->billing['street_address']) |
||
| 189 | ->setFixPhone($order->customer['telephone']) |
||
| 190 | ->setMobilePhone($order->customer['telephone']); |
||
| 191 | |||
| 192 | $orderBillingAddress = $userAddress; |
||
| 193 | |||
| 194 | $orderShippingAddress = new Address(); |
||
| 195 | $orderShippingAddress |
||
| 196 | ->setZipCode($order->delivery['postcode']) |
||
| 197 | ->setFullName($order->billing['firstname'].' '.$order->billing['lastname']) |
||
| 198 | ->setCountryCode('ES') |
||
| 199 | ->setCity($order->delivery['city']) |
||
| 200 | ->setAddress($order->delivery['street_address']) |
||
| 201 | ->setFixPhone($order->customer['telephone']) |
||
| 202 | ->setMobilePhone($order->customer['telephone']); |
||
| 203 | |||
| 204 | $orderUser = new \Pagantis\OrdersApiClient\Model\Order\User(); |
||
| 205 | $orderUser |
||
| 206 | ->setAddress($userAddress) |
||
| 207 | ->setFullName($order->billing['firstname'].' '.$order->billing['lastname']) |
||
| 208 | ->setBillingAddress($orderBillingAddress) |
||
| 209 | ->setEmail($order->customer['email_address']) |
||
| 210 | ->setFixPhone($order->customer['telephone']) |
||
| 211 | ->setMobilePhone($order->customer['telephone']) |
||
| 212 | ->setShippingAddress($orderShippingAddress); |
||
| 213 | |||
| 214 | $previousOrders = $this->getOrders(); |
||
| 215 | foreach ((array)$previousOrders as $k => $previousOrder) { |
||
| 216 | $orderHistory = new \Pagantis\OrdersApiClient\Model\Order\User\OrderHistory(); |
||
| 217 | $orderHistory |
||
| 218 | ->setAmount(intval(100 * $previousOrder['value'])) |
||
| 219 | ->setDate(new \DateTime($previousOrder['date_purchased'])) |
||
| 220 | ; |
||
| 221 | $orderUser->addOrderHistory($orderHistory); |
||
| 222 | } |
||
| 223 | |||
| 224 | $details = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details(); |
||
| 225 | $shippingCost = number_format($order->info['shipping_cost'], 2, '.', ''); |
||
| 226 | $details->setShippingCost(intval(strval(100 * $shippingCost))); |
||
| 227 | foreach ($order->products as $item) { |
||
| 228 | $product = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details\Product(); |
||
| 229 | $product |
||
| 230 | ->setAmount(intval(100 * number_format(($item['final_price'] * $item['qty']), 2))) |
||
| 231 | ->setQuantity(intval($item['qty'])) |
||
| 232 | ->setDescription($item['name']); |
||
| 233 | $details->addProduct($product); |
||
| 234 | } |
||
| 235 | |||
| 236 | $orderShoppingCart = new \Pagantis\OrdersApiClient\Model\Order\ShoppingCart(); |
||
| 237 | $orderShoppingCart |
||
| 238 | ->setDetails($details) |
||
| 239 | ->setOrderReference($this->os_order_reference) |
||
| 240 | ->setPromotedAmount(0) |
||
| 241 | ->setTotalAmount(intval($order->info['total'] * 100)); |
||
| 242 | |||
| 243 | $callback_url = $this->base_url.'/ext/modules/payment/pagantis/notify.php'; |
||
| 244 | $checkoutProcessUrl = htmlspecialchars_decode( |
||
| 245 | tep_href_link(FILENAME_CHECKOUT_PROCESS, "order_id=$this->os_order_reference", 'SSL', true, false) |
||
| 246 | ); |
||
| 247 | $cancelUrl = trim(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL', false)); |
||
| 248 | $orderConfigurationUrls = new \Pagantis\OrdersApiClient\Model\Order\Configuration\Urls(); |
||
| 249 | $orderConfigurationUrls |
||
| 250 | ->setCancel($cancelUrl) |
||
| 251 | ->setKo($checkoutProcessUrl) |
||
| 252 | ->setAuthorizedNotificationCallback($callback_url) |
||
| 253 | ->setRejectedNotificationCallback($callback_url) |
||
| 254 | ->setOk($checkoutProcessUrl); |
||
| 255 | |||
| 256 | |||
| 257 | $orderChannel = new \Pagantis\OrdersApiClient\Model\Order\Configuration\Channel(); |
||
| 258 | $orderChannel |
||
| 259 | ->setAssistedSale(false) |
||
| 260 | ->setType(\Pagantis\OrdersApiClient\Model\Order\Configuration\Channel::ONLINE); |
||
| 261 | $orderConfiguration = new \Pagantis\OrdersApiClient\Model\Order\Configuration(); |
||
| 262 | $orderConfiguration |
||
| 263 | ->setChannel($orderChannel) |
||
| 264 | ->setUrls($orderConfigurationUrls); |
||
| 265 | |||
| 266 | $metadataOrder = new \Pagantis\OrdersApiClient\Model\Order\Metadata(); |
||
| 267 | $metadata = array( |
||
| 268 | 'oscommerce' => PROJECT_VERSION, |
||
| 269 | 'pagantis' => $this->version, |
||
| 270 | 'php' => phpversion() |
||
| 271 | ); |
||
| 272 | foreach ($metadata as $key => $metadatum) { |
||
| 273 | $metadataOrder->addMetadata($key, $metadatum); |
||
| 274 | } |
||
| 275 | $orderApiClient = new \Pagantis\OrdersApiClient\Model\Order(); |
||
| 276 | $orderApiClient |
||
| 277 | ->setConfiguration($orderConfiguration) |
||
| 278 | ->setMetadata($metadataOrder) |
||
| 279 | ->setShoppingCart($orderShoppingCart) |
||
| 280 | ->setUser($orderUser); |
||
| 281 | |||
| 282 | $publicKey = trim(MODULE_PAYMENT_PAGANTIS_PK); |
||
| 283 | $secretKey = trim(MODULE_PAYMENT_PAGANTIS_SK); |
||
| 284 | $orderClient = new \Pagantis\OrdersApiClient\Client($publicKey, $secretKey); |
||
| 285 | $pagantisOrder = $orderClient->createOrder($orderApiClient); |
||
| 286 | if ($pagantisOrder instanceof \Pagantis\OrdersApiClient\Model\Order) { |
||
| 287 | $url = $pagantisOrder->getActionUrls()->getForm(); |
||
| 288 | $this->insertRow($this->order_id, $pagantisOrder->getId(), serialize($global_vars)); |
||
| 289 | } else { |
||
| 290 | throw new OrderNotFoundException(); |
||
| 291 | } |
||
| 292 | |||
| 293 | if ($url == "") { |
||
| 294 | throw new UnknownException(_("No ha sido posible obtener una respuesta de Pagantis")); |
||
| 295 | } else { //if ($this->extraConfig['PAGANTIS_FORM_DISPLAY_TYPE'] == '0') { |
||
| 296 | $output = "\n"; |
||
| 297 | $output.= tep_draw_hidden_field("formUrl", $url) . "\n"; |
||
| 298 | $output.= tep_draw_hidden_field("cancelUrl", $cancelUrl) . "\n"; |
||
| 299 | return $output; |
||
| 300 | } /*else { |
||
| 301 | $template_fields = array( |
||
| 302 | 'url' => $url, |
||
| 303 | 'checkoutUrl' => $cancelUrl |
||
| 304 | ); |
||
| 305 | wc_get_template('iframe.php', $template_fields, '', $this->template_path); //TODO |
||
| 306 | }*/ // |
||
| 307 | } catch (\Exception $exception) { |
||
| 308 | tep_redirect($cancelUrl); |
||
| 309 | return; |
||
| 310 | } |
||
| 513 |