218 lines
6.8 KiB
PHP
218 lines
6.8 KiB
PHP
<?php
|
|
/**
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to a commercial license from Common-Services Co., Ltd.
|
|
* Use, copy, modification or distribution of this source file without written
|
|
* license agreement from the SARL SMC is strictly forbidden.
|
|
* In order to obtain a license, please contact us: contact@common-services.com
|
|
* ...........................................................................
|
|
* INFORMATION SUR LA LICENCE D'UTILISATION
|
|
*
|
|
* L'utilisation de ce fichier source est soumise a une licence commerciale
|
|
* concedee par la societe Common-Services Co., Ltd.
|
|
* Toute utilisation, reproduction, modification ou distribution du present
|
|
* fichier source sans contrat de licence ecrit de la part de la Common-Services Co. Ltd. est
|
|
* expressement interdite.
|
|
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
|
|
* ...........................................................................
|
|
*
|
|
* @package soflexibilite
|
|
* @author Alexandre D.
|
|
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
|
|
* @license Commercial license
|
|
* Support by mail : support.spartoo@common-services.com
|
|
*/
|
|
|
|
class SoFlexibiliteWebService
|
|
{
|
|
|
|
protected $debug;
|
|
private $ws;
|
|
private $login;
|
|
private $password;
|
|
public $options;
|
|
|
|
/**
|
|
* SoFlexibiliteWebService constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->debug = false;
|
|
$this->params = null;
|
|
$this->ws = Configuration::get('SOFLEXIBILITE_WS');
|
|
$this->login = Configuration::get('SOFLEXIBILITE_LOGIN');
|
|
$this->password = Configuration::get('SOFLEXIBILITE_PASSWORD');
|
|
$this->options = array(
|
|
'trace' => true,
|
|
'exceptions' => true,
|
|
'soap_version' => 'SOAP_1_1',
|
|
'encoding' => 'utf-8'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Call web service.
|
|
*
|
|
* @param $method
|
|
* @param $params
|
|
* @return bool|mixed|null
|
|
*/
|
|
private function call($method, $params)
|
|
{
|
|
ini_set('soap.wsdl_cache_enabled', 0);
|
|
ini_set('soap.wsdl_cache_ttl', 0);
|
|
libxml_disable_entity_loader(false);
|
|
|
|
$options = $this->options;
|
|
$debug = $this->debug;
|
|
|
|
try {
|
|
$client = new SoapClient($this->ws, $options);
|
|
} catch (Exception $e) {
|
|
if ($debug) {
|
|
echo '<pre>'.print_r(libxml_get_errors(), true)."\n".
|
|
var_dump(libxml_get_last_error())."\n".
|
|
$e->getMessage().
|
|
'</pre>';
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
$result = $client->__call($method, array($params));
|
|
} catch (SoapFault $fault) {
|
|
if ($debug) {
|
|
echo 'Request : <br/><xmp>'.$client->__getLastRequest().'</xmp><br/>Response : <br/>
|
|
<xmp>'.$client->__getLastResponse().'</xmp><br/>Error Message : <br/>'.$fault->getMessage().'<br/>\n';
|
|
echo $fault->getMessage().'\n';
|
|
}
|
|
|
|
$result = null;
|
|
}
|
|
|
|
return ($result);
|
|
}
|
|
|
|
|
|
/**
|
|
* Get the delivery mode available.
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function getSelectedDeliveryMode()
|
|
{
|
|
$delivery_mode = array();
|
|
|
|
$relay_carrier = new Carrier((int)Configuration::get('SOFLEXIBILITE_A2P_ID'));
|
|
$bpr_carrier = new Carrier((int)Configuration::get('SOFLEXIBILITE_BPR_ID'));
|
|
if (Validate::isLoadedObject($relay_carrier) && $relay_carrier->active) {
|
|
$delivery_mode = array_merge($delivery_mode, array('A2P', 'CMT'));
|
|
}
|
|
if (Validate::isLoadedObject($bpr_carrier) && $bpr_carrier->active) {
|
|
$delivery_mode = array_merge($delivery_mode, array('BPR', 'BDP', 'CDI'));
|
|
}
|
|
|
|
return ($delivery_mode);
|
|
}
|
|
|
|
|
|
/**
|
|
* Get a list of relay pickup based on the address.
|
|
*
|
|
* @param $address
|
|
* @param int $filter_relay Filter relay pickup, set 0 not to get PickUp relays
|
|
* @return bool|mixed|null
|
|
*/
|
|
public function getRelays($address, $filter_relay = 1)
|
|
{
|
|
$method = 'findRDVPointRetraitAcheminement';
|
|
$request_id = md5(date('Ymdhis'));
|
|
|
|
if (isset($address['country']) && Tools::strlen($address['country']) > 2) {
|
|
$address['country'] = Country::getIsoById((int)Country::getIdByName(null, $address['country']));
|
|
}
|
|
|
|
$params = array(
|
|
'accountNumber' => $this->login,
|
|
'password' => $this->password,
|
|
'address' => $this->cleanup($address['address']),
|
|
'zipCode' => sprintf('%s', ($address['postcode'])),
|
|
'city' => $this->cleanup($address['city']),
|
|
'countryCode' => (isset($address['country']) && $address['country']) ? $address['country'] : 'FR',
|
|
'optionInter' => (isset($address['country']) && !in_array($address['country'], array('FR'))) ? 1 : 0,
|
|
'weight' => $address['weight'],
|
|
'shippingDate' => $address['date'],
|
|
'filterRelay' => (int)$filter_relay,
|
|
'requestId' => $request_id.$request_id
|
|
);
|
|
|
|
return ($this->call($method, $params));
|
|
}
|
|
|
|
/**
|
|
* Get Information about a relay based on its ID.
|
|
*
|
|
* @param $id
|
|
* @param string|null $date
|
|
* @return stdClass|null
|
|
*/
|
|
public function getRelay($id, $date = null)
|
|
{
|
|
$method = 'findPointRetraitAcheminementByID';
|
|
|
|
if (!$date) {
|
|
$date = date('d/m/Y', time() + 86400 * 2);
|
|
}
|
|
|
|
$params = array(
|
|
'accountNumber' => $this->login,
|
|
'password' => $this->password,
|
|
'id' => $id,
|
|
'date' => $date
|
|
);
|
|
|
|
$result = $this->call($method, $params);
|
|
if (!$result->return->errorCode) {
|
|
return ($result->return->pointRetraitAcheminement);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get Information about a relay based on its ID.
|
|
* Static function.
|
|
*
|
|
* @param $id
|
|
* @param string|null $date
|
|
* @return stdClass|null
|
|
*/
|
|
public static function getRelayStatic($id, $date = null)
|
|
{
|
|
$web_service = new SoFlexibiliteWebService();
|
|
return $web_service->getRelay($id, $date);
|
|
}
|
|
|
|
/**
|
|
* Santize string for web service call
|
|
*
|
|
* @param $text
|
|
* @return string
|
|
*/
|
|
private function cleanup($text)
|
|
{
|
|
$text = mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8');
|
|
$text = preg_replace(
|
|
array('/ß/', '/&(..)lig;/', '/&([aouAOU])uml;/', '/&(.)[^;]*;/'),
|
|
array('ss', '$1', '$1e', '$1'),
|
|
$text
|
|
);
|
|
$text = str_replace('_', '/', $text);
|
|
$text = preg_replace('/[\x00-\x1F\x21-\x2E\x3A-\x3F\x5B-\x60\x7B-\x7F]/', ' ', $text);
|
|
|
|
return (Tools::strtoupper($text));
|
|
}
|
|
}
|