load_credentials(); } /** * Load API credentials from settings */ private function load_credentials() { $options = get_option(CARRYBEE_WP_SETTINGS_OPTION, array()); $environment = isset($options[CARRYBEE_WP_SETTING_ENVIRONMENT]) ? $options[CARRYBEE_WP_SETTING_ENVIRONMENT] : CARRYBEE_WP_DEFAULT_ENVIRONMENT; $this->base_url = CARRYBEE_WP_get_api_base_url($environment); $this->client_id = isset($options[CARRYBEE_WP_SETTING_CLIENT_ID]) ? $options[CARRYBEE_WP_SETTING_CLIENT_ID] : ''; $this->client_secret = isset($options[CARRYBEE_WP_SETTING_CLIENT_SECRET]) ? $options[CARRYBEE_WP_SETTING_CLIENT_SECRET] : ''; $this->client_context = isset($options[CARRYBEE_WP_SETTING_CLIENT_CONTEXT]) ? $options[CARRYBEE_WP_SETTING_CLIENT_CONTEXT] : ''; } /** * Reload API credentials from settings (public method) * Useful when credentials are updated and need to be refreshed */ public function reload_credentials() { $this->load_credentials(); } /** * Check if API is configured * * @return bool */ public function is_configured() { return !empty($this->base_url) && !empty($this->client_id) && !empty($this->client_secret) && !empty($this->client_context); } /** * Get authorization headers * * @return array */ private function get_auth_headers() { return array( 'Content-Type' => 'application/json', 'Client-ID' => $this->client_id, 'Client-Secret' => $this->client_secret, 'Client-Context' => $this->client_context, ); } /** * Set credentials manually * * @param string $client_id * @param string $client_secret * @param string $client_context */ public function set_credentials($client_id, $client_secret, $client_context = '') { $this->client_id = $client_id; $this->client_secret = $client_secret; $this->client_context = $client_context; } /** * Get access token * * @return string */ public function get_access_token() { return ''; } /** * Legacy login method retained for backward compatibility. * * @param bool $save_token Whether to save the token to database immediately * @return true|WP_Error */ public function login($save_token = true) { if (!$this->is_configured()) { return new WP_Error('not_configured', __('API headers are not configured. Please enter Client-ID, Client-Secret, and Client-Context.', 'carrybee')); } return true; } /** * Test API connection * * @return array|WP_Error */ public function test_connection() { if (!$this->is_configured()) { return new WP_Error('not_configured', __('API credentials are not configured.', 'carrybee')); } $endpoint = $this->base_url . CARRYBEE_WP_API_Endpoints::STORES; $response = wp_remote_get($endpoint, array( 'headers' => $this->get_auth_headers(), 'timeout' => 10, )); if (is_wp_error($response)) { return $response; } $response_code = wp_remote_retrieve_response_code($response); if ($response_code !== 200) { $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $error_message = isset($data['message']) ? $data['message'] : __('API connection test failed.', 'carrybee'); return new WP_Error('connection_failed', $error_message); } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $stores = null; if (isset($data['error']) && $data['error'] === false && isset($data['data']['stores']) && is_array($data['data']['stores'])) { $stores = $data['data']['stores']; } elseif (isset($data['success']) && $data['success'] === true && isset($data['data']) && is_array($data['data'])) { $stores = $data['data']; } if (!is_array($stores)) { $error_message = isset($data['message']) ? $data['message'] : __('Invalid stores response while testing API connection.', 'carrybee'); return new WP_Error('connection_failed', $error_message); } set_transient( CARRYBEE_WP_cache_key(CARRYBEE_WP_CACHE_KEY_STORES), $stores, CARRYBEE_WP_CACHE_STORES_TTL ); return array( 'status' => 'success', 'stores_count' => count($stores), ); } /** * Generic GET request to API * * @param string $endpoint The API endpoint (without base URL) * @param array $args Additional wp_remote_get arguments * @return array|WP_Error */ public function get($endpoint, $args = array()) { if (!$this->is_configured()) { return new WP_Error('not_configured', __('API credentials are not configured.', 'carrybee')); } $url = $this->base_url . $endpoint; $default_args = array( 'headers' => $this->get_auth_headers(), 'timeout' => 15, ); $args = wp_parse_args($args, $default_args); if (CARRYBEE_WP_debug_enabled()) { CARRYBEE_WP_debug_log('CBWP API GET Request: ' . $url); } $response = wp_remote_get($url, $args); if (is_wp_error($response)) { if (CARRYBEE_WP_debug_enabled()) { CARRYBEE_WP_debug_log('CBWP API GET Error: ' . $response->get_error_message()); } return $response; } if (CARRYBEE_WP_debug_enabled()) { CARRYBEE_WP_debug_log('CBWP API GET Response Code: ' . wp_remote_retrieve_response_code($response)); } return $response; } /** * Create parcel * * @param array $order_data * @return array|WP_Error */ /** * Create order/parcel via API * * @param array $order_data * @return array|WP_Error */ public function create_parcel($order_data) { if (!$this->is_configured()) { return new WP_Error('not_configured', __('API credentials are not configured.', 'carrybee')); } // Use new orders endpoint $endpoint = $this->base_url . CARRYBEE_WP_API_Endpoints::ORDERS; $store_id = isset($order_data['store_id']) ? sanitize_text_field($order_data['store_id']) : ''; $merchant_order_id = isset($order_data['merchant_order_id']) ? sanitize_text_field($order_data['merchant_order_id']) : ''; $recipient_secondary_phone = ''; if (isset($order_data['recipient_secendary_phone'])) { $recipient_secondary_phone = sanitize_text_field($order_data['recipient_secendary_phone']); } elseif (isset($order_data['recipient_phone_secondary'])) { $recipient_secondary_phone = sanitize_text_field($order_data['recipient_phone_secondary']); } $special_instruction = isset($order_data['special_instruction']) ? sanitize_textarea_field($order_data['special_instruction']) : ''; $product_description = ''; if (isset($order_data['product_description'])) { $product_description = sanitize_text_field($order_data['product_description']); } elseif (isset($order_data['item_desc'])) { $product_description = sanitize_text_field($order_data['item_desc']); } $item_weight = 0; if (isset($order_data['item_weight'])) { $item_weight = absint($order_data['item_weight']); } elseif (isset($order_data['weight'])) { // Backward compatibility: existing UI sends weight in KG, API expects grams. $item_weight = (int) round(floatval($order_data['weight']) * 1000); } if ($item_weight < 1) { $item_weight = 500; } $item_quantity = isset($order_data['item_quantity']) ? absint($order_data['item_quantity']) : 0; if ($item_quantity < 1 && isset($order_data['quantity'])) { $item_quantity = absint($order_data['quantity']); } if ($item_quantity < 1) { $item_quantity = 1; } $collectable_amount = 0; if (isset($order_data['collectable_amount'])) { $collectable_amount = max(0, (int) round(floatval($order_data['collectable_amount']))); } elseif (isset($order_data['amount_collect'])) { $collectable_amount = max(0, (int) round(floatval($order_data['amount_collect']))); } // Prepare order data with API v2 structure. $api_data = array( 'store_id' => $store_id, 'delivery_type' => isset($order_data['delivery_type']) ? absint($order_data['delivery_type']) : 1, 'product_type' => isset($order_data['product_type']) ? absint($order_data['product_type']) : 2, 'recipient_phone' => isset($order_data['recipient_phone']) ? sanitize_text_field($order_data['recipient_phone']) : '', 'recipient_name' => isset($order_data['recipient_name']) ? sanitize_text_field($order_data['recipient_name']) : '', 'recipient_address' => isset($order_data['recipient_address']) ? sanitize_text_field($order_data['recipient_address']) : '', 'item_weight' => $item_weight, 'item_quantity' => $item_quantity, 'collectable_amount' => $collectable_amount, ); if (!empty($merchant_order_id)) { $api_data['merchant_order_id'] = $merchant_order_id; } if (!empty($recipient_secondary_phone)) { $api_data['recipient_secendary_phone'] = $recipient_secondary_phone; } if (!empty($special_instruction)) { $api_data['special_instruction'] = $special_instruction; } if (!empty($product_description)) { $api_data['product_description'] = $product_description; } // Only include location fields when they have valid values. Direct send omits // city/zone/area entirely and lets the courier resolve them from the address. if (!empty($order_data['city_id']) && absint($order_data['city_id']) > 0) { $api_data['city_id'] = absint($order_data['city_id']); } if (!empty($order_data['zone_id']) && absint($order_data['zone_id']) > 0) { $api_data['zone_id'] = absint($order_data['zone_id']); } if (!empty($order_data['area_id']) && absint($order_data['area_id']) > 0) { $api_data['area_id'] = absint($order_data['area_id']); } // Log request for debugging $this->log('Creating order', array( 'endpoint' => $endpoint, 'data' => $api_data, )); $response = wp_remote_post($endpoint, array( 'headers' => $this->get_auth_headers(), 'body' => wp_json_encode($api_data), 'timeout' => 20, )); if (is_wp_error($response)) { $this->log('Order creation failed', array('error' => $response->get_error_message())); return $response; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $response_code = wp_remote_retrieve_response_code($response); // Log response $this->log('Order creation response', array( 'status_code' => $response_code, 'response' => $data, )); // Check for success (200 or 201) if ($response_code !== 200 && $response_code !== 201) { // Return detailed validation response so callers can map field errors. if (!empty($data) && (isset($data['causes']) || isset($data['errors']) || isset($data['error']))) { return $data; } $error_message = isset($data['message']) ? $data['message'] : __('Failed to create order.', 'carrybee'); return new WP_Error('order_creation_failed', $error_message); } if (isset($data['error']) && $data['error'] === true) { return $data; } return $data; } /** * Get print POD (proof of delivery) data for one or more consignments. * * @param string|array $consignment_ids Single ID, comma-separated list or array of IDs. * @return array|WP_Error Decoded JSON body, or array{raw: string, content_type: string} for non-JSON responses. */ public function get_order_print_pod($consignment_ids) { if (!$this->is_configured()) { return new WP_Error('not_configured', __('API credentials are not configured.', 'carrybee')); } if (is_array($consignment_ids)) { $consignment_ids = implode(',', array_map('sanitize_text_field', $consignment_ids)); } else { $consignment_ids = sanitize_text_field($consignment_ids); } if ($consignment_ids === '') { return new WP_Error('invalid_data', __('Consignment ID is required.', 'carrybee')); } $endpoint = add_query_arg( 'consignment_ids', $consignment_ids, $this->base_url . CARRYBEE_WP_API_Endpoints::ORDER_PRINT_POD ); $this->log('Fetching print POD', array('endpoint' => $endpoint)); $response = wp_remote_get($endpoint, array( 'headers' => $this->get_auth_headers(), 'timeout' => 30, )); if (is_wp_error($response)) { $this->log('Print POD request failed', array('error' => $response->get_error_message())); return $response; } $response_code = wp_remote_retrieve_response_code($response); $content_type = wp_remote_retrieve_header($response, 'content-type'); $body = wp_remote_retrieve_body($response); $this->log('Print POD response', array( 'status_code' => $response_code, 'content_type' => $content_type, 'body_length' => strlen($body), )); $data = json_decode($body, true); if ($response_code !== 200 && $response_code !== 201) { $error_message = is_array($data) && isset($data['message']) ? $data['message'] : __('Failed to fetch print data.', 'carrybee'); return new WP_Error('print_pod_failed', $error_message); } if (is_array($data)) { return $data; } // Non-JSON response (e.g. ready-made HTML or PDF) - hand back raw payload. return array( 'raw' => $body, 'content_type' => (string) $content_type, ); } /** * Create bulk orders/parcels via API * * @param array $orders_data Array of order data arrays * @return array|WP_Error */ public function create_bulk_parcels($orders_data) { if (!$this->is_configured()) { return new WP_Error('not_configured', __('API credentials are not configured.', 'carrybee')); } if (empty($orders_data) || !is_array($orders_data)) { return new WP_Error('invalid_data', __('Invalid bulk orders data.', 'carrybee')); } // Use bulk orders endpoint $endpoint = $this->base_url . CARRYBEE_WP_API_Endpoints::ORDERS_BULK; // Prepare all orders data with API v2 structure. $api_orders = array(); foreach ($orders_data as $order_data) { $store_id = isset($order_data['store_id']) ? sanitize_text_field($order_data['store_id']) : ''; $merchant_order_id = isset($order_data['merchant_order_id']) ? sanitize_text_field($order_data['merchant_order_id']) : ''; $recipient_secondary_phone = ''; if (isset($order_data['recipient_secendary_phone'])) { $recipient_secondary_phone = sanitize_text_field($order_data['recipient_secendary_phone']); } elseif (isset($order_data['recipient_phone_secondary'])) { $recipient_secondary_phone = sanitize_text_field($order_data['recipient_phone_secondary']); } $product_description = ''; if (isset($order_data['product_description'])) { $product_description = sanitize_text_field($order_data['product_description']); } elseif (isset($order_data['item_desc'])) { $product_description = sanitize_text_field($order_data['item_desc']); } $item_weight = 0; if (isset($order_data['item_weight'])) { $item_weight = absint($order_data['item_weight']); } elseif (isset($order_data['weight'])) { // Backward compatibility: UI sends weight in KG, API expects grams. $item_weight = (int) round(floatval($order_data['weight']) * 1000); } if ($item_weight < 1) { $item_weight = 500; } $item_quantity = isset($order_data['item_quantity']) ? absint($order_data['item_quantity']) : 0; if ($item_quantity < 1 && isset($order_data['quantity'])) { $item_quantity = absint($order_data['quantity']); } if ($item_quantity < 1) { $item_quantity = 1; } $collectable_amount = 0; if (isset($order_data['collectable_amount'])) { $collectable_amount = max(0, (int) round(floatval($order_data['collectable_amount']))); } elseif (isset($order_data['amount_collect'])) { $collectable_amount = max(0, (int) round(floatval($order_data['amount_collect']))); } $api_data = array( 'store_id' => $store_id, 'delivery_type' => isset($order_data['delivery_type']) ? absint($order_data['delivery_type']) : 1, 'product_type' => isset($order_data['product_type']) ? absint($order_data['product_type']) : 2, 'recipient_name' => isset($order_data['recipient_name']) ? sanitize_text_field($order_data['recipient_name']) : '', 'recipient_phone' => isset($order_data['recipient_phone']) ? sanitize_text_field($order_data['recipient_phone']) : '', 'recipient_secendary_phone' => $recipient_secondary_phone, 'recipient_address' => isset($order_data['recipient_address']) ? sanitize_text_field($order_data['recipient_address']) : '', 'special_instruction' => isset($order_data['special_instruction']) ? sanitize_textarea_field($order_data['special_instruction']) : '', 'product_description' => $product_description, 'item_weight' => $item_weight, 'item_quantity' => $item_quantity, 'collectable_amount' => $collectable_amount, ); if (!empty($merchant_order_id)) { $api_data['merchant_order_id'] = $merchant_order_id; } if (empty($api_data['recipient_secendary_phone'])) { unset($api_data['recipient_secendary_phone']); } if (empty($api_data['special_instruction'])) { unset($api_data['special_instruction']); } if (empty($api_data['product_description'])) { unset($api_data['product_description']); } // Only include location fields when they have valid values. Direct bulk send // omits city/zone/area entirely and lets the courier resolve them from the address. if (!empty($order_data['city_id']) && absint($order_data['city_id']) > 0) { $api_data['city_id'] = absint($order_data['city_id']); } if (!empty($order_data['zone_id']) && absint($order_data['zone_id']) > 0) { $api_data['zone_id'] = absint($order_data['zone_id']); } if (!empty($order_data['area_id']) && absint($order_data['area_id']) > 0) { $api_data['area_id'] = absint($order_data['area_id']); } $api_orders[] = $api_data; } // Log request for debugging $this->log('Creating bulk orders', array( 'endpoint' => $endpoint, 'count' => count($api_orders), )); // Wrap orders in 'orders' key for bulk API endpoint $request_body = array( 'orders' => $api_orders ); $response = wp_remote_post($endpoint, array( 'headers' => $this->get_auth_headers(), 'body' => wp_json_encode($request_body), 'timeout' => 60, // Longer timeout for bulk operations )); if (is_wp_error($response)) { $this->log('Bulk order creation failed', array('error' => $response->get_error_message())); return $response; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $response_code = wp_remote_retrieve_response_code($response); // Log response $this->log('Bulk order creation response', array( 'status_code' => $response_code, 'response' => $data, )); // Check for success (200 or 201) if ($response_code !== 200 && $response_code !== 201) { // If we have structured validation errors, return them to caller for row-level handling. if (!empty($data) && (isset($data['causes']) || isset($data['errors']) || isset($data['error']) || (isset($data['success']) && $data['success'] === false))) { return $data; } $error_message = isset($data['message']) ? $data['message'] : __('Failed to create bulk orders.', 'carrybee'); return new WP_Error('bulk_order_creation_failed', $error_message); } if (isset($data['error']) && $data['error'] === true) { return $data; } return $data; } /** * Prepare parcel data for API * * @param array $order_data * @return array */ private function prepare_parcel_data($order_data) { $parcel_data = array( 'merchant_order_id' => $order_data['order_id'], 'recipient_name' => $order_data['customer']['name'], 'recipient_phone' => $order_data['customer']['phone'], 'recipient_address' => $this->format_address($order_data['customer']['address']), 'recipient_city' => $order_data['customer']['address']['city'], 'recipient_zone' => $order_data['customer']['address']['state'], 'amount' => $order_data['total_amount'], 'item_type' => 'Parcel', 'item_quantity' => count($order_data['items']), 'item_weight' => $this->calculate_total_weight($order_data['items']), 'item_description' => $this->format_item_description($order_data['items']), ); return apply_filters('CARRYBEE_WP_parcel_data', $parcel_data, $order_data); } /** * Format address * * @param array $address * @return string */ private function format_address($address) { $parts = array_filter(array( $address['address_1'] ?? '', $address['address_2'] ?? '', )); return implode(', ', $parts); } /** * Calculate total weight from items * * @param array $items * @return float */ private function calculate_total_weight($items) { $total_weight = 0; foreach ($items as $item) { if (isset($item['weight']) && is_numeric($item['weight'])) { $total_weight += (float) $item['weight'] * $item['quantity']; } } // Default weight if none specified (in kg) return $total_weight > 0 ? $total_weight : 0.5; } /** * Format item description * * @param array $items * @return string */ private function format_item_description($items) { $descriptions = array(); foreach ($items as $item) { $descriptions[] = $item['name'] . ' x ' . $item['quantity']; } return implode(', ', $descriptions); } /** * Get order info by consignment ID * * @param string $consignment_id * @return array|WP_Error */ public function get_order_info($consignment_id) { if (!$this->is_configured()) { return new WP_Error('not_configured', __('API credentials are not configured.', 'carrybee')); } $endpoint = $this->base_url . CARRYBEE_WP_API_Endpoints::get_order_details($consignment_id); $this->log('Getting order info', array( 'endpoint' => $endpoint, 'consignment_id' => $consignment_id, )); $response = wp_remote_get($endpoint, array( 'headers' => $this->get_auth_headers(), 'timeout' => 15, )); if (is_wp_error($response)) { $this->log('Get order info failed', array('error' => $response->get_error_message())); return $response; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $response_code = wp_remote_retrieve_response_code($response); // Fall back to legacy endpoint if details route is unavailable in current environment. if ($response_code === 404) { $legacy_endpoint = $this->base_url . CARRYBEE_WP_API_Endpoints::get_order_info($consignment_id); $this->log('Order details endpoint not found, trying legacy endpoint', array( 'legacy_endpoint' => $legacy_endpoint, 'consignment_id' => $consignment_id, )); $response = wp_remote_get($legacy_endpoint, array( 'headers' => $this->get_auth_headers(), 'timeout' => 15, )); if (is_wp_error($response)) { $this->log('Get order info fallback failed', array('error' => $response->get_error_message())); return $response; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $response_code = wp_remote_retrieve_response_code($response); } $this->log('Get order info response', array( 'status_code' => $response_code, 'response' => $data, )); if ($response_code !== 200) { $error_message = isset($data['message']) ? $data['message'] : __('Failed to get order info.', 'carrybee'); return new WP_Error('get_order_info_failed', $error_message); } if (isset($data['error']) && $data['error'] === true) { $error_message = isset($data['message']) ? $data['message'] : __('Failed to get order info.', 'carrybee'); return new WP_Error('get_order_info_failed', $error_message); } // Normalize status key so caller can consistently read current courier status. if (isset($data['data']) && is_array($data['data'])) { if (!isset($data['data']['order_status']) && isset($data['data']['transfer_status'])) { $data['data']['order_status'] = $data['data']['transfer_status']; } } return $data; } /** * Parse address to get city and zone * * @param string $address The address to parse * @return array|WP_Error */ public function parse_address($address) { if (!$this->is_configured()) { return new WP_Error('not_configured', __('API credentials are not configured.', 'carrybee')); } if (empty($address)) { return new WP_Error('empty_address', __('Address is required.', 'carrybee')); } $endpoint = $this->base_url . CARRYBEE_WP_API_Endpoints::ADDRESS_PARSER; $this->log('Parsing address', array( 'endpoint' => $endpoint, 'address' => $address, )); $response = wp_remote_post($endpoint, array( 'headers' => $this->get_auth_headers(), 'body' => wp_json_encode(array( 'query' => $address, )), 'timeout' => 15, )); if (is_wp_error($response)) { $this->log('Address parsing failed', array('error' => $response->get_error_message())); return $response; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $response_code = wp_remote_retrieve_response_code($response); $this->log('Address parsing response', array( 'status_code' => $response_code, 'response' => $data, )); if (!is_array($data)) { return new WP_Error('address_parsing_failed', __('Invalid response while parsing address.', 'carrybee')); } // New parser API always returns structured payload with `error` + `message`. if (array_key_exists('error', $data)) { return $data; } if ($response_code !== 200) { $error_message = isset($data['message']) ? $data['message'] : __('Failed to parse address.', 'carrybee'); return new WP_Error('address_parsing_failed', $error_message); } return $data; } /** * Parse multiple addresses to get city and zone for each * * @param array $addresses Array of addresses to parse * @return array|WP_Error */ public function parse_addresses_bulk($addresses) { if (!$this->is_configured()) { return new WP_Error('not_configured', __('API credentials are not configured.', 'carrybee')); } if (empty($addresses) || !is_array($addresses)) { return new WP_Error('empty_addresses', __('Addresses array is required.', 'carrybee')); } $endpoint = $this->base_url . CARRYBEE_WP_API_Endpoints::ADDRESS_PARSER_BULK; $this->log('Parsing addresses in bulk', array( 'endpoint' => $endpoint, 'count' => count($addresses), )); $response = wp_remote_post($endpoint, array( 'headers' => $this->get_auth_headers(), 'body' => wp_json_encode(array( 'queries' => $addresses, )), 'timeout' => 30, // Longer timeout for bulk operations )); if (is_wp_error($response)) { $this->log('Bulk address parsing failed', array('error' => $response->get_error_message())); return $response; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $response_code = wp_remote_retrieve_response_code($response); // Backward compatibility fallback for environments still on the legacy route/payload. if ($response_code === 404) { $legacy_endpoint = $this->base_url . CARRYBEE_WP_API_Endpoints::ADDRESS_PARSER_BULK_LEGACY; $this->log('Bulk parser endpoint not found, trying legacy endpoint', array( 'legacy_endpoint' => $legacy_endpoint, )); $response = wp_remote_post($legacy_endpoint, array( 'headers' => $this->get_auth_headers(), 'body' => wp_json_encode(array( 'addresses' => $addresses, )), 'timeout' => 30, )); if (is_wp_error($response)) { $this->log('Bulk address parsing fallback failed', array('error' => $response->get_error_message())); return $response; } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); $response_code = wp_remote_retrieve_response_code($response); } $this->log('Bulk address parsing response', array( 'status_code' => $response_code, 'response' => $data, )); if (!is_array($data)) { return new WP_Error('bulk_address_parsing_failed', __('Invalid response while parsing addresses in bulk.', 'carrybee')); } if ($response_code !== 200) { $error_message = isset($data['message']) ? $data['message'] : __('Failed to parse addresses in bulk.', 'carrybee'); return new WP_Error('bulk_address_parsing_failed', $error_message); } return $data; } /** * Log messages * * @param string $message * @param array $context */ private function log($message, $context = array()) { if (!CARRYBEE_WP_debug_enabled() || !function_exists('wc_get_logger')) { return; } // Never write customer details (names, phones, addresses) to the log. wc_get_logger()->debug($message, array('source' => 'carrybee-courier', 'context' => CARRYBEE_WP_redact($context))); } }