get('test_mode');
}
$url = $test_mode ? self::PACZKOMATY_SANDBOX_URL : self::PACZKOMATY_URL;
$url = $url.(!empty($parameters) ? '?'.http_build_query($parameters, '', '&') : '');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if ($postData) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
public static function callAuth($parameters, $postData = array())
{
$config = stConfig::getInstance('stPaczkomatyBackend');
$postData = array_merge(array('email' => $config->get('username'), 'password' => $config->get('password')), $postData);
return self::call($parameters, $postData);
}
public static function getStatus($code) {
$response = self::call(array('do' => 'getpackstatus', 'packcode' => $code));
$xml = simplexml_load_string($response);
if(isset($xml->status))
return array('status' => (string)$xml->status, 'date' => (string)$xml->statusDate);
}
public static function checkAuth($login, $password, $test_mode)
{
$response = self::call(array('do' => 'pricelist'), array('email' => $login, 'password' => $password), $test_mode);
$logger = sfConfig::get('sf_debug') ? sfLogger::getInstance() : null;
if($response == false)
{
if ($logger)
{
$logger->log('{stPaczkomaty} Connection problem', SF_LOG_ERR);
}
return false;
}
$xml = simplexml_load_string($response);
if ($logger && isset($xml->error))
{
$logger->log('{stPaczkomaty} '.$xml->error, SF_LOG_ERR);
}
return !isset($xml->error);
}
public static function createPack(PaczkomatyPack $pack) {
$config = stConfig::getInstance('stPaczkomatyBackend');
$allegro = '';
try
{
if ($pack->hasAllegroTransactionId())
{
$userId = stConfig::getInstance('stAllegroBackend')->get('seller_id');
$transactionId = $pack->getAllegroTransactionId();
$allegro = ''.$userId.''.$transactionId.'';
}
}
catch (stAllegroException $e)
{
foreach (stAllegroApi::getLastErrors() as $error)
{
$messages[] = $error->userMessage;
}
$message = implode('
', $messages);
return array('status' => false, 'error' => $message);
}
$xml = '
0
'.($pack->getUseSenderPaczkomat() ? 1 : 0).'
'.$pack->getId().'
'.$pack->getCustomerEmail().'
'.$config->get('username').'
'.$pack->getCustomerPhone().'
'.$pack->getCustomerPaczkomat().''.
($pack->getUseSenderPaczkomat() ? ''.$pack->getSenderPaczkomat().'' : '')
.''.$pack->getPackType().'
'.$pack->getInsurance().'
'.$pack->getCashOnDelivery().'
'.$pack->getDescription().'
'.$config->get('sender_company').'
'.$config->get('sender_name').'
'.$config->get('sender_surname').'
'.$config->get('sender_email').'
'.$config->get('sender_phone').'
'.$config->get('sender_street').'
'.$config->get('sender_building_no').'
'.$config->get('sender_flat_no').'
'.$config->get('sender_town').'
'.$config->get('sender_zip_code').'
'.$config->get('sender_province').'
'.$allegro.'
';
$post = array('content' => $xml);
$response = self::callAuth(array('do' => 'createdeliverypacks'), $post);
if($response == false)
return array('status' => false, 'error' => 'Błąd połączenia z serwerem API Paczkomaty.');
$xml = simplexml_load_string($response);
if(isset($xml->pack->error))
return array('status' => false, 'error' => (string)$xml->pack->error);
if(isset($xml->error))
return array('status' => false, 'error' => (string)$xml->error);
if(isset($xml->pack->packcode)) {
$pack->setCode((string)$xml->pack->packcode);
$pack->setCustomerDeliveringCode((string)$xml->pack->customerdeliveringcode);
$pack->save();
}
return array('status' => true);
}
public static function getSticker($code) {
$config = stConfig::getInstance('stPaczkomatyBackend');
$post = array('packcode' => $code, 'labelType' => $config->get('label_type'));
$response = self::callAuth(array('do' => 'getsticker'), $post);
if (strpos($response, 'PDF'))
return array('status' => true, 'pdf' => $response);
$xml = simplexml_load_string($response);
if(isset($xml->error))
return array('status' => false, 'error' => (string)$xml->error);
}
public static function payForPack($code) {
$config = stConfig::getInstance('stPaczkomatyBackend');
$post = array('packcode' => $code);
$response = self::callAuth(array('do' => 'payforpack'), $post);
if ($response == '1')
return array('status' => true);
$xml = simplexml_load_string($response);
if(isset($xml->error))
return array('status' => false, 'error' => (string)$xml->error);
}
}