/**
  * @return WP_Bring_Response
  */
 static function request_customer_numbers()
 {
     $args = ['headers' => ['Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-MyBring-API-Uid' => Bring_Booking::get_api_uid(), 'X-MyBring-API-Key' => Bring_Booking::get_api_key(), 'X-Bring-Client-URL' => Bring_Booking::get_client_url()]];
     $request = new WP_Bring_Request();
     $response = $request->get(self::CUSTOMERS_URL, array(), $args);
     return $response;
 }
 /**
  * @param Bring_WC_Order_Adapter $order
  */
 static function download_to_local($order)
 {
     if (!$order->has_booking_consignments()) {
         return;
     }
     self::init_local_dir();
     $consignments = $order->get_booking_consignments();
     foreach ($consignments as $consignment) {
         $consignment_number = $consignment->confirmation->consignmentNumber;
         $source = $consignment->confirmation->links->labels;
         $destination = self::get_file_path($order->order->id, $consignment_number);
         $request = new WP_Bring_Request();
         $request->get($source, array(), array('stream' => true, 'filename' => $destination));
     }
 }
 public function get_shipping_data()
 {
     $data = [];
     foreach ($this->get_fraktguiden_shipping_items() as $item_id => $method) {
         $pickup_point_id = wc_get_order_item_meta($item_id, '_fraktguiden_pickup_point_id', true);
         $pickup_point = null;
         $pickup_point_cached = null;
         $pickup_point_postcode = null;
         if ($pickup_point_id) {
             $shipping_address = $this->order->get_address('shipping');
             $request = new WP_Bring_Request();
             $response = $request->get('https://api.bring.com/pickuppoint/api/pickuppoint/' . $shipping_address['country'] . '/id/' . $pickup_point_id . '.json');
             $pickup_point = $response->has_errors() ? null : json_decode($response->get_body())->pickupPoint[0];
             $pickup_point_cached = wc_get_order_item_meta($item_id, '_fraktguiden_pickup_point_cached', true);
             $pickup_point_postcode = wc_get_order_item_meta($item_id, '_fraktguiden_pickup_point_postcode', true);
         }
         $data[] = ['item_id' => $item_id, 'pickup_point' => $pickup_point, 'pickup_point_info_cached' => $pickup_point_cached, 'postcode' => $pickup_point_postcode, 'packages' => json_encode($this->get_packages_for_order_item($item_id))];
     }
     return $data;
 }
 static function get_pickup_points($country, $postcode)
 {
     $request = new WP_Bring_Request();
     return $request->get(self::BASE_URL . '/' . $country . '/postalCode/' . $postcode . '.json');
 }
 /**
  * @return WP_Bring_Response
  */
 public function send()
 {
     $args = ['headers' => ['Content-Type' => $this->get_content_type(), 'Accept' => $this->get_accept(), 'X-MyBring-API-Uid' => $this->get_api_uid(), 'X-MyBring-API-Key' => $this->get_api_key(), 'X-Bring-Client-URL' => $this->get_client_url()], 'body' => json_encode($this->create_data())];
     return $this->request->post(self::BOOKING_URL, array(), $args);
 }
 /**
  * Calculate shipping costs.
  *
  * @todo: in 2.6, the package param was added. Investigate this!
  */
 public function calculate_shipping($package = array())
 {
     global $woocommerce;
     //include_once( 'common/class-fraktguiden-packer.php' );
     // Offer flat rate if the cart contents exceeds max product.
     if ($woocommerce->cart->get_cart_contents_count() > $this->max_products) {
         if ($this->alt_flat_rate == '') {
             return;
         }
         $rate = array('id' => $this->id . ':' . 'alt_flat_rate', 'cost' => $this->alt_flat_rate, 'label' => $this->method_title . ' flat rate');
         $this->add_rate($rate);
     } else {
         $cart = $woocommerce->cart->get_cart();
         $this->packages_params = $this->pack_order($cart);
         if (!$this->packages_params) {
             return;
         }
         if (is_checkout()) {
             $_COOKIE['_fraktguiden_packages'] = json_encode($this->packages_params);
         }
         // Request parameters.
         $params = array_merge($this->create_standard_url_params(), $this->packages_params);
         // Remove any empty elements.
         $params = array_filter($params);
         $url = add_query_arg($params, self::SERVICE_URL);
         // Add all the selected services to the URL
         $service_count = 0;
         if ($this->services && count($this->services) > 0) {
             foreach ($this->services as $service) {
                 $url .= '&product=' . $service;
             }
         }
         // Make the request.
         $request = new WP_Bring_Request();
         $response = $request->get($url);
         if ($response->status_code != 200) {
             return;
         }
         // Decode the JSON data from bring.
         $json = json_decode($response->get_body(), true);
         // Filter the response json to get only the selected services from the settings.
         $rates = $this->get_services_from_response($json);
         $rates = apply_filters('bring_shipping_rates', $rates);
         if ($this->debug != 'no') {
             $this->log->add($this->id, 'params: ' . print_r($params, true));
             if ($rates) {
                 $this->log->add($this->id, 'Rates found: ' . print_r($rates, true));
             } else {
                 $this->log->add($this->id, 'No rates found for params: ' . print_r($params, true));
             }
             $this->log->add($this->id, 'Request url: ' . print_r($url, true));
         }
         // Calculate rate.
         if ($rates) {
             foreach ($rates as $rate) {
                 $this->add_rate($rate);
             }
         }
     }
 }