charge_party($payload) === self::CHARGE_RECIPIENT) ? self::CHARGE_CODE_RECIPIENT : self::CHARGE_CODE_SENDER; } public function create_mode() { return 'api'; } protected function base_url() { return 'https://ecapi.elta-courier.gr/api'; } protected function test_base_url() { return 'https://wsstage.elta-courier.gr/api'; } public function tracking_url($voucher_no) { $tpl = trim((string) $this->get_setting('tracking_url_template', '')); if ($tpl !== '') { return str_replace('{voucher_no}', rawurlencode((string) $voucher_no), $tpl); } return AIEO_Runtime_Fulfillment_URLs::tracking_url('elta', (string) $voucher_no); } public function settings_schema() { return array( 'customer_code' => array('type' => 'text', 'label' => __('Customer code', 'ai-eshop-optimizer'), 'required' => true, 'help' => __('customerCode / pelCode — supplied by ELTA. Max 12 characters.', 'ai-eshop-optimizer')), 'customer_user' => array('type' => 'text', 'label' => __('User code', 'ai-eshop-optimizer'), 'required' => true, 'help' => __('customerUser / userCode — supplied by ELTA. Max 12 characters.', 'ai-eshop-optimizer')), 'customer_pass' => array('type' => 'password', 'label' => __('User password', 'ai-eshop-optimizer'), 'required' => true, 'help' => __('customerPassword / userPassword — supplied by ELTA. Max 7 characters.', 'ai-eshop-optimizer')), 'pel_sub_code' => array('type' => 'text', 'label' => __('Customer sub-code', 'ai-eshop-optimizer'), 'help' => __('pelSubCode — only if ELTA gave you one. Leave empty otherwise.', 'ai-eshop-optimizer')), 'ar_sub_code' => array('type' => 'text', 'label' => __('Return sub-code (AR)', 'ai-eshop-optimizer'), 'help' => __('ARSubCode — used only when additional service 002 is on. Empty means a return goes back to the sender.', 'ai-eshop-optimizer')), 'service_code' => array('type' => 'select', 'label' => __('Default service', 'ai-eshop-optimizer'), 'options' => array( self::SERVICE_DOOR_TO_DOOR => __('Door to door', 'ai-eshop-optimizer'), self::SERVICE_OFFICE_TO_DOOR => __('Office to door', 'ai-eshop-optimizer'), self::SERVICE_OFFICE_TO_OFFICE => __('Office to office', 'ai-eshop-optimizer'), self::SERVICE_DOOR_TO_OFFICE => __('Door to office', 'ai-eshop-optimizer'), self::SERVICE_PUDO => __('Pickup point (PUDO)', 'ai-eshop-optimizer'), ), 'help' => __('voucher_service. ELTA default is door to door.', 'ai-eshop-optimizer')), 'sender_title' => array('type' => 'text', 'label' => __('Sender name', 'ai-eshop-optimizer'), 'help' => __('Printed as the sender on the voucher. Leave empty to use the shop name.', 'ai-eshop-optimizer')), 'sender_address' => array('type' => 'text', 'label' => __('Sender address', 'ai-eshop-optimizer')), 'sender_area' => array('type' => 'text', 'label' => __('Sender area', 'ai-eshop-optimizer')), 'sender_zip' => array('type' => 'text', 'label' => __('Sender postcode', 'ai-eshop-optimizer')), 'sender_phone' => array('type' => 'text', 'label' => __('Sender phone', 'ai-eshop-optimizer')), 'sender_email' => array('type' => 'text', 'label' => __('Sender email', 'ai-eshop-optimizer')), 'request_pickup' => array('type' => 'checkbox', 'label' => __('Ask for a pickup with each voucher', 'ai-eshop-optimizer'), 'help' => __('Sets order_flag = 1. Leave off if a courier already calls on a standing arrangement — ELTA rejects a pickup order with no date.', 'ai-eshop-optimizer')), 'additional_services' => array('type' => 'text', 'label' => __('Additional service codes', 'ai-eshop-optimizer'), 'help' => __('Comma-separated codes supplied by ELTA, e.g. 002. Leave empty for none.', 'ai-eshop-optimizer')), 'tracking_url_template' => array('type' => 'text', 'label' => __('Tracking URL template', 'ai-eshop-optimizer'), 'help' => __('Public tracking page with {voucher_no} placeholder. Leave empty for the ELTA default.', 'ai-eshop-optimizer')), ); } public function authenticate(array $creds = array()) { $env = $this->is_sandbox() ? 'stage' : 'prod'; $cache = get_option(self::TOKEN_OPTION, array()); if (is_array($cache) && isset($cache['env']) && $cache['env'] === $env && !empty($cache['token']) && (int) (isset($cache['expires_at']) ? $cache['expires_at'] : 0) > (time() + self::TOKEN_SAFETY_MARGIN)) { return array('ok' => true, 'auth_token' => (string) $cache['token'], 'expires_at' => (int) $cache['expires_at']); } $code = trim((string) $this->get_setting('customer_code', '')); $user = trim((string) $this->get_setting('customer_user', '')); $pass = (string) $this->get_setting('customer_pass', ''); if ($code === '' || $user === '' || $pass === '') { return array('ok' => false, 'auth_token' => null, 'expires_at' => null, 'error' => __('ELTA: customer code, user code and password are all required.', 'ai-eshop-optimizer')); } $resp = $this->request('POST', '/authorization', array( 'customerCode' => $code, 'customerUser' => $user, 'customerPassword' => $pass, )); if (is_wp_error($resp)) { return array('ok' => false, 'auth_token' => null, 'expires_at' => null, 'error' => $resp->get_error_message()); } $err = $this->unwrap($resp); if ($err !== '') { return array('ok' => false, 'auth_token' => null, 'expires_at' => null, 'error' => $err); } $token = ''; foreach (array('api_Key', 'api_key', 'apiKey', 'apikey') as $k) { if (!empty($resp[$k])) { $token = (string) $resp[$k]; break; } } if ($token === '') { return array('ok' => false, 'auth_token' => null, 'expires_at' => null, 'error' => __('ELTA authorised but returned no api_Key.', 'ai-eshop-optimizer')); } $exp = strtotime((string) (isset($resp['expiration_date']) ? $resp['expiration_date'] : '')); if (!$exp || $exp < time()) { $exp = time() + HOUR_IN_SECONDS; } update_option(self::TOKEN_OPTION, array('env' => $env, 'token' => $token, 'expires_at' => $exp), false); return array('ok' => true, 'auth_token' => $token, 'expires_at' => $exp); } private static function auth_headers($token) { return array('apiKey' => (string) $token, 'api_secret' => (string) $token); } private function call($path, array $body, $retry = true) { $auth = $this->authenticate(); if (empty($auth['ok'])) { return new WP_Error('aieo_elta_auth', (string) (isset($auth['error']) ? $auth['error'] : 'auth failed')); } $resp = $this->request('POST', $path, $body, self::auth_headers((string) $auth['auth_token'])); if (is_wp_error($resp) && $retry) { $c = $resp->get_error_code(); if ($c === 'aieo_courier_http_401' || $c === 'aieo_courier_http_403') { delete_option(self::TOKEN_OPTION); return $this->call($path, $body, false); } } return $resp; } private function error_code($resp) { if (!is_array($resp) || !isset($resp['baseResponse']['error_code'])) { return ''; } return trim((string) $resp['baseResponse']['error_code']); } private function unwrap($resp) { if (!is_array($resp)) { return __('ELTA returned an unreadable response.', 'ai-eshop-optimizer'); } $base = (isset($resp['baseResponse']) && is_array($resp['baseResponse'])) ? $resp['baseResponse'] : array(); $code = trim((string) (isset($base['error_code']) ? $base['error_code'] : '')); if ($code === '' || $code === '0' || $code === '00') { return ''; } $msg = trim((string) (isset($base['error_remarks']) ? $base['error_remarks'] : '')); if ($msg !== '') { return sprintf(__('ELTA %1$s: %2$s', 'ai-eshop-optimizer'), $code, $msg); } return sprintf(__('ELTA returned error code %s.', 'ai-eshop-optimizer'), $code); } private function creds() { return array( 'userCode' => $this->cut($this->get_setting('customer_user', ''), 12), 'userPassword' => $this->cut($this->get_setting('customer_pass', ''), 7), 'pelCode' => $this->cut($this->get_setting('customer_code', ''), 12), ); } private function cut($v, $max) { $v = trim((string) $v); return function_exists('mb_substr') ? mb_substr($v, 0, (int) $max) : substr($v, 0, (int) $max); } private function party(array $p, $remarks = '') { $phone = preg_replace('/\D+/', '', (string) (isset($p['phone']) ? $p['phone'] : '')); if (strpos($phone, '0030') === 0) { $phone = substr($phone, 4); } if (strlen($phone) === 12 && strpos($phone, '30') === 0) { $phone = substr($phone, 2); } $is_greek = (strlen($phone) === 10); return array( 'cust_title' => $this->cut((string) (isset($p['name']) ? $p['name'] : ''), 30), 'cust_address' => $this->cut((string) (isset($p['address']) ? $p['address'] : ''), 50), 'cust_area' => $this->cut((string) (isset($p['city']) ? $p['city'] : ''), 40), 'cust_postal_code' => $this->cut(preg_replace('/\s+/', '', (string) (isset($p['zip']) ? $p['zip'] : '')), 10), 'cust_telefon' => $this->cut(($is_greek && $phone[0] !== '6') ? $phone : '', 15), 'cust_mobile' => $this->cut(($is_greek && $phone[0] === '6') ? $phone : '', 15), 'cust_mobileExoterikou' => $this->cut($is_greek ? '' : $phone, 15), 'cust_email' => $this->cut((string) (isset($p['email']) ? $p['email'] : ''), 40), 'cust_remarks' => $this->cut((string) $remarks, 150), ); } private function shop_party($remarks = '') { $title = trim((string) $this->get_setting('sender_title', '')); return $this->party(array( 'name' => $title !== '' ? $title : get_bloginfo('name'), 'address' => $this->get_setting('sender_address', ''), 'city' => $this->get_setting('sender_area', ''), 'zip' => $this->get_setting('sender_zip', ''), 'phone' => $this->get_setting('sender_phone', ''), 'email' => $this->get_setting('sender_email', ''), ), $remarks); } public function create_voucher(array $payload) { $r = (isset($payload['recipient']) && is_array($payload['recipient'])) ? $payload['recipient'] : array(); if (trim((string) (isset($r['name']) ? $r['name'] : '')) === '' || trim((string) (isset($r['address']) ? $r['address'] : '')) === '') { return array('ok' => false, 'error' => __('ELTA needs a recipient name and address.', 'ai-eshop-optimizer')); } $cod_amount = round((float) (isset($payload['cod_amount']) ? $payload['cod_amount'] : 0), 2); $pieces = max(1, (int) (isset($payload['pieces']) ? $payload['pieces'] : 1)); $weight = round((float) (isset($payload['weight']) ? $payload['weight'] : 0), 2); $service = (int) $this->get_setting('service_code', self::SERVICE_DOOR_TO_DOOR); $pudo = trim((string) (isset($payload['pickup_point_id']) ? $payload['pickup_point_id'] : (isset($r['shop_id']) ? $r['shop_id'] : ''))); if ($pudo !== '') { $service = self::SERVICE_PUDO; } $extra = array_values(array_filter(array_map('trim', explode(',', (string) $this->get_setting('additional_services', ''))), 'strlen')); $body = array_merge($this->creds(), array( 'pelType' => self::GENERATOR_SENDER, 'pelSubCode' => $this->cut($this->get_setting('pel_sub_code', ''), 10), 'ARSubCode' => $this->cut($this->get_setting('ar_sub_code', ''), 10), 'recCode' => '', 'voucher_numbers' => array( 'voucher_number' => '', 'voucher_child' => array(), 'epitagi_number' => '', 'ar_number' => '', ), 'sender_details' => $this->shop_party(), 'receiver_details' => $this->party($r, (string) (isset($payload['content_description']) ? $payload['content_description'] : '')), 'voucher_details' => array( 'voucher_service' => $service, 'voucher_charge' => $this->charge_code($payload), 'voucher_packages' => $pieces, 'voucher_actual_weight' => $weight, 'voucher_insurance_amount' => round((float) (isset($payload['insurance_amount']) ? $payload['insurance_amount'] : 0), 2), 'dim_x' => (int) (isset($payload['length']) ? $payload['length'] : 0), 'dim_y' => (int) (isset($payload['width']) ? $payload['width'] : 0), 'dim_z' => (int) (isset($payload['height']) ? $payload['height'] : 0), 'additional_services' => $extra, 'pudo_code' => $this->cut($pudo, 20), 'reference1' => $this->cut($this->reference($payload, 50), 50), 'reference2' => '', 'reference3' => '', ), 'cod_details' => array( 'cod_type' => $cod_amount > 0 ? self::COD_CASH : self::COD_NONE, 'cod_amount' => $cod_amount, 'cod_date' => '', ), 'order_details' => $this->order_block($payload), )); $resp = $this->call('/CreateVoucher', $body); if (is_wp_error($resp)) { return array('ok' => false, 'error' => $resp->get_error_message()); } $err = $this->unwrap($resp); if ($err !== '') { return array('ok' => false, 'error' => $err, 'raw' => $resp); } $vn = (isset($resp['voucher_numbers']) && is_array($resp['voucher_numbers'])) ? $resp['voucher_numbers'] : array(); $awb = trim((string) (isset($vn['voucher_number']) ? $vn['voucher_number'] : '')); if ($awb === '') { return array('ok' => false, 'raw' => $resp, 'error' => __('ELTA accepted the shipment but returned no voucher number.', 'ai-eshop-optimizer')); } $children = array(); if (!empty($vn['voucher_child']) && is_array($vn['voucher_child'])) { foreach ($vn['voucher_child'] as $c) { $cn = is_array($c) ? trim((string) (isset($c['child_number']) ? $c['child_number'] : '')) : trim((string) $c); if ($cn !== '' && $cn !== $awb) { $children[] = $cn; } } } return array( 'ok' => true, 'voucher_no' => $awb, 'subvouchers' => $children, 'job_id' => null, 'raw' => $resp, ); } private function order_block(array $payload) { if (!$this->get_setting('request_pickup', 0)) { return array('order_flag' => self::ORDER_NO_PICKUP, 'pickup_date' => '', 'pickup_start_time' => '', 'pickup_end_time' => ''); } return array( 'order_flag' => self::ORDER_WITH_PICKUP, 'pickup_date' => $this->pickup_date($payload, 'Ymd'), 'pickup_start_time' => '', 'pickup_end_time' => '', ); } public function create_return_voucher(array $payload) { $from = (isset($payload['sender']) && is_array($payload['sender'])) ? $payload['sender'] : array(); $to = (isset($payload['recipient']) && is_array($payload['recipient'])) ? $payload['recipient'] : array(); if (trim((string) (isset($from['name']) ? $from['name'] : '')) === '' || trim((string) (isset($from['address']) ? $from['address'] : '')) === '') { return array('ok' => false, 'error' => __('ELTA needs the customer\'s name and pickup address for a return.', 'ai-eshop-optimizer')); } $shop = (trim((string) (isset($to['address']) ? $to['address'] : '')) !== '') ? $this->party($to) : $this->shop_party(); if (trim((string) $shop['cust_address']) === '') { return array('ok' => false, 'error' => __('A return needs your own shop address — fill the sender fields on the ELTA card.', 'ai-eshop-optimizer')); } $extra = array_values(array_filter(array_map('trim', explode(',', (string) $this->get_setting('additional_services', ''))), 'strlen')); $body = array_merge($this->creds(), array( 'pelType' => self::GENERATOR_RECIPIENT, 'pelSubCode' => $this->cut($this->get_setting('pel_sub_code', ''), 10), 'ARSubCode' => $this->cut($this->get_setting('ar_sub_code', ''), 10), 'recCode' => '', 'voucher_numbers' => array( 'voucher_number' => '', 'voucher_child' => array(), 'epitagi_number' => '', 'ar_number' => '', ), 'sender_details' => $this->party($from, (string) (isset($payload['comments']) ? $payload['comments'] : '')), 'receiver_details' => $shop, 'voucher_details' => array( 'voucher_service' => (int) $this->get_setting('service_code', self::SERVICE_DOOR_TO_DOOR), 'voucher_charge' => $this->charge_code($payload), 'voucher_packages' => max(1, (int) (isset($payload['pieces']) ? $payload['pieces'] : 1)), 'voucher_actual_weight' => round((float) (isset($payload['weight']) ? $payload['weight'] : 0), 2), 'voucher_insurance_amount' => 0, 'dim_x' => 0, 'dim_y' => 0, 'dim_z' => 0, 'additional_services' => $extra, 'pudo_code' => '', 'reference1' => $this->cut($this->reference($payload, 50), 50), 'reference2' => '', 'reference3' => '', ), 'cod_details' => array('cod_type' => self::COD_NONE, 'cod_amount' => 0, 'cod_date' => ''), )); $day = $this->pickup_datetime($payload, true); $resp = null; $attempt = 0; while (true) { $body['order_details'] = array( 'order_flag' => self::ORDER_WITH_PICKUP, 'pickup_date' => $day->format('Ymd'), 'pickup_start_time' => '', 'pickup_end_time' => '', ); $resp = $this->call('/CreateVoucher', $body); if (is_wp_error($resp)) { return array('ok' => false, 'error' => $resp->get_error_message()); } if ($this->error_code($resp) !== self::ERROR_BAD_PICKUP_DATE || $attempt >= self::PICKUP_DATE_RETRIES) { break; } $day = self::next_working_day($day->modify('+1 day')); $attempt++; } $err = $this->unwrap($resp); if ($err !== '') { return array('ok' => false, 'error' => $err, 'raw' => $resp); } $vn = (isset($resp['voucher_numbers']) && is_array($resp['voucher_numbers'])) ? $resp['voucher_numbers'] : array(); $awb = trim((string) (isset($vn['voucher_number']) ? $vn['voucher_number'] : '')); if ($awb === '') { return array('ok' => false, 'raw' => $resp, 'error' => __('ELTA accepted the return but returned no voucher number.', 'ai-eshop-optimizer')); } return array( 'ok' => true, 'voucher_no' => $awb, 'subvouchers' => array(), 'job_id' => null, 'raw' => $resp, ); } public function get_label_pdf($voucher_no, $format = 'A4') { $vn = trim((string) $voucher_no); if ($vn === '') { return array('ok' => false, 'error' => __('Missing voucher number.', 'ai-eshop-optimizer')); } $resp = $this->call('/PrintVoucher', array_merge($this->creds(), array('voucherNum' => $vn))); if (is_wp_error($resp)) { return array('ok' => false, 'error' => $resp->get_error_message()); } $err = $this->unwrap($resp); if ($err !== '') { return array('ok' => false, 'error' => $err, 'raw' => $resp); } $list = (isset($resp['b64vouchersList']) && is_array($resp['b64vouchersList'])) ? $resp['b64vouchersList'] : array(); $first = ''; foreach ($list as $b64) { if (is_string($b64) && trim($b64) !== '') { $first = trim($b64); break; } } if ($first === '') { return array('ok' => false, 'raw' => $resp, 'error' => __('ELTA returned no label for that voucher.', 'ai-eshop-optimizer')); } $decoded = $this->decode_label($first); if (empty($decoded['ok'])) { return $decoded; } $decoded['pdf_url'] = null; $decoded['labels_b64'] = $list; return $decoded; } public function cancel($voucher_no) { $vn = trim((string) $voucher_no); if ($vn === '') { return array('ok' => false, 'error' => __('Missing voucher number.', 'ai-eshop-optimizer')); } $resp = $this->call('/CancelVoucher', array( 'pelCode' => $this->cut($this->get_setting('customer_code', ''), 12), 'pelUserCode' => $this->cut($this->get_setting('customer_user', ''), 12), 'flag1' => '0', 'flag2' => '0', 'type' => '2', 'voucher' => $vn, 'id' => 0, 'cancelComments' => __('Cancelled from the shop', 'ai-eshop-optimizer'), )); if (is_wp_error($resp)) { return array('ok' => false, 'error' => $resp->get_error_message()); } $err = $this->unwrap($resp); if ($err !== '') { return array('ok' => false, 'error' => $err, 'raw' => $resp); } return array('ok' => true); } public function track($voucher_no) { $vn = trim((string) $voucher_no); if ($vn === '') { return array('ok' => false, 'error' => 'voucher_no required'); } $resp = $this->call('/TraceVoucher', array_merge($this->creds(), array( 'voucher' => $vn, 'dateFrom' => '', 'dateTo' => '', 'paralCode' => '', 'statusFlag' => '', ))); if (is_wp_error($resp)) { return array('ok' => false, 'error' => $resp->get_error_message()); } $err = $this->unwrap($resp); if ($err !== '') { return array('ok' => false, 'error' => $err, 'raw' => $resp); } $rows = (isset($resp['trace_details']) && is_array($resp['trace_details'])) ? $resp['trace_details'] : array(); $checkpoints = array(); $latest_code = ''; $delivered_at = null; foreach ($rows as $t) { if (!is_array($t)) { continue; } $code = trim((string) (isset($t['trace_Status_code']) ? $t['trace_Status_code'] : '')); $desc = trim((string) (isset($t['trace_Status_gr']) ? $t['trace_Status_gr'] : (isset($t['trace_Status_en']) ? $t['trace_Status_en'] : ''))); $loc = trim((string) (isset($t['trace_Station_gr']) ? $t['trace_Station_gr'] : (isset($t['trace_Station_en']) ? $t['trace_Station_en'] : ''))); $ts = $this->stamp((string) (isset($t['trace_date']) ? $t['trace_date'] : ''), (string) (isset($t['trace_time']) ? $t['trace_time'] : '')); $checkpoints[] = array( 'code' => $code !== '' ? $code : $desc, 'description' => $desc, 'location' => $loc, 'checkpoint_at' => $ts, ); if ($code !== '' || $desc !== '') { $latest_code = ($code !== '' ? $code : $desc); } if ($this->map_status($desc !== '' ? $desc : $code) === 'delivered' && is_int($ts)) { $delivered_at = $ts; } } if ($delivered_at === null) { $d = $this->stamp((string) (isset($resp['delivery_date']) ? $resp['delivery_date'] : ''), (string) (isset($resp['delivery_time']) ? $resp['delivery_time'] : '')); if (is_int($d)) { $delivered_at = $d; } } $consignee = trim((string) (isset($resp['rec_title']) ? $resp['rec_title'] : '')); return array( 'ok' => true, 'status_code' => $latest_code, 'checkpoints' => $checkpoints, 'consignee' => $consignee !== '' ? $consignee : null, 'delivered_at' => $delivered_at, 'raw' => $resp, ); } private function stamp($date, $time) { $date = trim((string) $date); $time = trim((string) $time); if ($date === '') { return null; } if ($time === '') { $time = '00:00'; } if (preg_match('/^\d{4}$/', $time)) { $time = substr($time, 0, 2) . ':' . substr($time, 2, 2); } foreach (array('dmY H:i', 'd-m-Y H:i', 'd/m/Y H:i', 'Y-m-d H:i', 'Ymd H:i') as $fmt) { $dt = DateTime::createFromFormat($fmt, $date . ' ' . $time); if ($dt instanceof DateTime) { $y = (int) $dt->format('Y'); if ($y >= 2000 && $y <= 2100) { return $dt->getTimestamp(); } } } return null; } public function map_status($raw_code) { $raw = mb_strtoupper((string) $raw_code); if ($raw === '') { return 'unknown'; } if (mb_strpos($raw, 'ΠΡΟΣ ΠΑΡΑΔΟΣΗ') !== false) { return 'out_for_delivery'; } if (mb_strpos($raw, 'ΠΡΟΣ ΔΙΑΝΟΜΗ') !== false) { return 'out_for_delivery'; } if (mb_strpos($raw, 'ΕΞΟΔΟΣ') !== false) { return 'out_for_delivery'; } if (mb_strpos($raw, 'ΠΑΡΑΔΟΘ') !== false) { return 'delivered'; } if (mb_strpos($raw, 'ΕΓΙΝΕ ΠΑΡΑΔΟΣΗ') !== false) { return 'delivered'; } if (mb_strpos($raw, 'ΕΠΙΣΤΡΟΦ') !== false) { return 'returned'; } if (mb_strpos($raw, 'ΑΚΥΡΩΣ') !== false) { return 'canceled'; } if (mb_strpos($raw, 'ΑΠΟΠΕΙΡ') !== false) { return 'attempted'; } if (mb_strpos($raw, 'ΛΑΘΟΣ ΔΙΕΥΘΥΝΣΗ') !== false) { return 'attempted'; } if (mb_strpos($raw, 'ΠΑΡΑΛΑΒ') !== false) { return 'in_transit'; } if (mb_strpos($raw, 'ΑΠΟΣΤΟΛ') !== false) { return 'in_transit'; } if (mb_strpos($raw, 'ΔΡΟΜΟΛΟΓ') !== false) { return 'in_transit'; } if (mb_strpos($raw, 'ΦΟΡΤΩΣ') !== false) { return 'in_transit'; } if (mb_strpos($raw, 'ΕΚΦΟΡΤΩΣ') !== false) { return 'in_transit'; } return 'unknown'; } public function shop_list() { $resp = $this->call('/PundoInfo', $this->creds()); if (is_wp_error($resp)) { return array('ok' => false, 'shops' => array(), 'error' => $resp->get_error_message()); } $err = $this->unwrap($resp); if ($err !== '') { return array('ok' => false, 'shops' => array(), 'error' => $err); } $rows = (isset($resp['pundo_Info_details']) && is_array($resp['pundo_Info_details'])) ? $resp['pundo_Info_details'] : array(); $shops = array(); foreach ($rows as $p) { if (!is_array($p) || empty($p['codes'])) { continue; } $shops[] = array( 'id' => (string) $p['codes'], 'name' => (string) (isset($p['titles_gr']) ? $p['titles_gr'] : (isset($p['titles_en']) ? $p['titles_en'] : '')), 'address' => (string) (isset($p['addres_gr']) ? $p['addres_gr'] : (isset($p['addres_en']) ? $p['addres_en'] : '')), 'zip' => (string) (isset($p['postal_code']) ? $p['postal_code'] : ''), 'city' => (string) (isset($p['city_gr']) ? $p['city_gr'] : (isset($p['city_en']) ? $p['city_en'] : '')), 'lat' => (string) (isset($p['latitude']) ? $p['latitude'] : ''), 'lng' => (string) (isset($p['longitude']) ? $p['longitude'] : ''), 'phone' => (string) (isset($p['telefon']) ? $p['telefon'] : ''), ); } return array('ok' => true, 'shops' => $shops, 'error' => null); } public function status_dictionary() { $resp = $this->call('/StatusInfo', $this->creds()); if (is_wp_error($resp)) { return array('ok' => false, 'statuses' => array(), 'error' => $resp->get_error_message()); } $err = $this->unwrap($resp); if ($err !== '') { return array('ok' => false, 'statuses' => array(), 'error' => $err); } $out = array(); $rows = (isset($resp['statusInfoDetails']) && is_array($resp['statusInfoDetails'])) ? $resp['statusInfoDetails'] : array(); foreach ($rows as $s) { if (!is_array($s) || !isset($s['codes'])) { continue; } $out[(string) $s['codes']] = array( 'gr' => (string) (isset($s['title_gr']) ? $s['title_gr'] : ''), 'en' => (string) (isset($s['title_en']) ? $s['title_en'] : ''), 'remarks' => (string) (isset($s['remarks']) ? $s['remarks'] : ''), ); } return array('ok' => true, 'statuses' => $out, 'error' => null); } } add_filter('aieo_fulfillment_couriers', static function (array $drivers) { if (!isset($drivers['elta']) && class_exists('AIEO_Courier_Driver_Elta')) { $drivers['elta'] = new AIEO_Courier_Driver_Elta(); } return $drivers; });