841 lines
31 KiB
PHP
841 lines
31 KiB
PHP
<?php
|
|
|
|
/*
|
|
|
|
Main API include file.
|
|
Revision 1.8
|
|
|
|
Copyright (c) 2011 InPost Sp. z o.o.
|
|
|
|
*/
|
|
//require_once 'config.php';
|
|
//error_reporting(E_ALL^E_NOTICE);
|
|
//require_once 'functions.php';
|
|
|
|
function inpost_check_environment($verbose=0) {
|
|
|
|
global $inpost_data_dir;
|
|
|
|
$status = 1;
|
|
if (!file_exists($inpost_data_dir)) {
|
|
if ($verbose)
|
|
echo "Paczkomaty API: path to proper data directory must be set (config.php)!<br/>";
|
|
$status = 0;
|
|
}
|
|
|
|
if (!is_writable("$inpost_data_dir/time1.dat")) {
|
|
if ($verbose)
|
|
echo "Paczkomaty API: file " . $inpost_data_dir . "/time1.dat must be writable!<br/>";
|
|
$status = 0;
|
|
}
|
|
|
|
if (!is_writable("$inpost_data_dir/time2.dat")) {
|
|
if ($verbose)
|
|
echo "Paczkomaty API: file " . $inpost_data_dir . "/time2.dat must be writable!<br/>";
|
|
$status = 0;
|
|
}
|
|
|
|
if (!is_writable("$inpost_data_dir/cache1.dat")) {
|
|
if ($verbose)
|
|
echo "Paczkomaty API: file " . $inpost_data_dir . "/cache1.dat must be writable!<br/>";
|
|
$status = 0;
|
|
}
|
|
|
|
if (!is_writable("$inpost_data_dir/cache2.dat")) {
|
|
if ($verbose)
|
|
echo "Paczkomaty API: file " . $inpost_data_dir . "/cache2.dat must be writable!<br/>";
|
|
$status = 0;
|
|
}
|
|
|
|
if (!function_exists('xml_parser_create')) {
|
|
if ($verbose)
|
|
echo "Paczkomaty API: PHP xml_parser_create() function is required!<br/>";
|
|
$status = 0;
|
|
}
|
|
|
|
return $status;
|
|
}
|
|
|
|
function inpost_get_params() {
|
|
global $inpost_data_dir, $inpost_api_url;
|
|
if ($Contents = file_get_contents("$inpost_api_url/?do=getparams")) {
|
|
$parsedXML = inpost_xml2array($Contents);
|
|
$wynik = array();
|
|
foreach ($parsedXML['paczkomaty'] as $name => $array)
|
|
$wynik[$name] = $array['value'];
|
|
$wynik['current_api_version'] = '2.1.1';
|
|
return $wynik;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_get_machine_list($town='', $paymentavailable='') {
|
|
|
|
global $inpost_data_dir;
|
|
|
|
if (inpost_cache_is_valid(1) == 0) {
|
|
inpost_download_machines();
|
|
}
|
|
if ($cache = @file_get_contents("$inpost_data_dir/cache1.dat")) {
|
|
$machineList = unserialize($cache);
|
|
|
|
if (count($machineList)) {
|
|
|
|
if ($town) {
|
|
foreach ($machineList as $machine) {
|
|
if ($machine[4] == $town)
|
|
$resultList[] = $machine;
|
|
}
|
|
$machineList = $resultList;
|
|
}
|
|
|
|
if (count($machineList)) {
|
|
$resultList = array();
|
|
$i = 0;
|
|
foreach ($machineList as $machine) {
|
|
if (!$paymentavailable || ($paymentavailable == 't' && $machine[7] == 't') || ($paymentavailable == 'f' && $machine[7] == 'f')) {
|
|
$resultList[$i]['name'] = $machine[0];
|
|
$resultList[$i]['street'] = $machine[1];
|
|
$resultList[$i]['buildingnumber'] = $machine[2];
|
|
$resultList[$i]['postcode'] = $machine[3];
|
|
$resultList[$i]['town'] = $machine[4];
|
|
$resultList[$i]['latitude'] = $machine[5];
|
|
$resultList[$i]['longitude'] = $machine[6];
|
|
if ($machine[7] == 't')
|
|
$resultList[$i]['paymentavailable'] = 1;
|
|
else
|
|
$resultList[$i]['paymentavailable'] = 0;
|
|
$resultList[$i]['operatinghours'] = $machine[8];
|
|
$resultList[$i]['locationdescription'] = $machine[9];
|
|
$resultList[$i]['paymentpointdescr'] = $machine[10];
|
|
$resultList[$i]['partnerid'] = $machine[11];
|
|
$resultList[$i]['paymenttype'] = $machine[12];
|
|
$i++;
|
|
}
|
|
}
|
|
usort($resultList, 'inpost_machine_sort');
|
|
return $resultList;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_get_pricelist() {
|
|
|
|
global $inpost_data_dir;
|
|
|
|
if (inpost_cache_is_valid(2) == 0) {
|
|
inpost_download_pricelist();
|
|
}
|
|
if ($cache = @file_get_contents("$inpost_data_dir/cache2.dat")) {
|
|
return unserialize($cache);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_get_pack_status($packcode) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
if ($statusContents = @file_get_contents("$inpost_api_url/?do=getpackstatus&packcode=$packcode")) {
|
|
$parsedXML = inpost_xml2array($statusContents);
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'],
|
|
'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
$parsedXML = $parsedXML['paczkomaty'];
|
|
$packStatus = $parsedXML['status']['value'];
|
|
return $packStatus;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_find_customer($email) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
if ($customerContents = @file_get_contents("$inpost_api_url/?do=findcustomer&email=$email")) {
|
|
$parsedXML = inpost_xml2array($customerContents);
|
|
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'], 'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
$parsedXML = $parsedXML['paczkomaty']['customer'];
|
|
if (isset($parsedXML['email']['value']) AND $parsedXML['email']['value'] == $email) {
|
|
$preferedBoxMachineName = $parsedXML['preferedBoxMachineName']['value'];
|
|
if (isset($parsedXML['alternativeBoxMachineName']['value']))
|
|
$alternativeBoxMachineName = $parsedXML['alternativeBoxMachineName']['value'];
|
|
else
|
|
$alternativeBoxMachineName = '';
|
|
return array('preferedBoxMachineName' => $preferedBoxMachineName, 'alternativeBoxMachineName' => $alternativeBoxMachineName);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_create_customer_partner($email, $password, $customerData) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
|
|
$digest = inpost_digest($password);
|
|
|
|
if (count($customerData)) {
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
$customerXML = "<paczkomaty>\n";
|
|
$customerXML .= "<customer>\n";
|
|
$customerXML .= "<email>" . $customerData['email'] . "</email>\n";
|
|
$customerXML .= "<mobileNumber>" . $customerData['mobileNumber'] . "</mobileNumber>\n";
|
|
$customerXML .= "<preferedBoxMachineName>" . $customerData['preferedBoxMachineName'] . "</preferedBoxMachineName>\n";
|
|
$customerXML .= "<alternativeBoxMachineName>" . $customerData['alternativeBoxMachineName'] . "</alternativeBoxMachineName>\n";
|
|
$customerXML .= "<phoneNum>" . $customerData['phoneNum'] . "</phoneNum>\n";
|
|
$customerXML .= "<street>" . $customerData['street'] . "</street>\n";
|
|
$customerXML .= "<town>" . $customerData['town'] . "</town>\n";
|
|
$customerXML .= "<postCode>" . $customerData['postCode'] . "</postCode>\n";
|
|
$customerXML .= "<building>" . $customerData['building'] . "</building>\n";
|
|
$customerXML .= "<flat>" . $customerData['flat'] . "</flat>\n";
|
|
$customerXML .= "<firstName><![CDATA[" . $customerData['firstName'] . "]]></firstName>\n";
|
|
$customerXML .= "<lastName><![CDATA[" . $customerData['lastName'] . "]]></lastName>\n";
|
|
$customerXML .= "<companyName><![CDATA[" . $customerData['companyName'] . "]]></companyName>\n";
|
|
$customerXML .= "<regon>" . $customerData['regon'] . "</regon>\n";
|
|
$customerXML .= "<nip>" . $customerData['nip'] . "</nip>\n";
|
|
$customerXML .= "</customer>\n";
|
|
$customerXML .= "</paczkomaty>\n";
|
|
|
|
$customerEmail = $customerData['email'];
|
|
$customerData = array('email' => $email, 'digest' => $digest, 'content' => $customerXML);
|
|
$postData = http_build_query($customerData);
|
|
if ($customerResponse = inpost_post_request("$inpost_api_url/?do=createcustomerpartner", $postData)) {
|
|
$parsedXML = inpost_xml2array($customerResponse);
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'], 'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
$parsedXML = $parsedXML['paczkomaty']['customer'];
|
|
if (isset($parsedXML['email']['value']) AND $parsedXML['email']['value'] == $customerEmail) {
|
|
return array('email' => $parsedXML['email']['value']);
|
|
}
|
|
}
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_send_packs($email, $password, $packsData, $autoLabels=1, $selfSend=0) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
|
|
$digest = inpost_digest($password);
|
|
|
|
if (count($packsData)) {
|
|
|
|
$packsXML = "<paczkomaty>\n";
|
|
$packsXML .= "<autoLabels>$autoLabels</autoLabels>\n";
|
|
$packsXML .= "<selfSend>$selfSend</selfSend>\n";
|
|
foreach ($packsData as $packId => $packData) {
|
|
$packsXML .= "<pack>\n";
|
|
$packsXML .= "<id>" . $packId . "</id>\n";
|
|
$packsXML .= "<adreseeEmail>" . $packData['adreseeEmail'] . "</adreseeEmail>\n";
|
|
$packsXML .= "<senderEmail>" . $packData['senderEmail'] . "</senderEmail>\n";
|
|
$packsXML .= "<phoneNum>" . $packData['phoneNum'] . "</phoneNum>\n";
|
|
if (array_key_exists('dispatchPointName', $packData))
|
|
$packsXML .= "<dispatchPointName>" . $packData['dispatchPointName'] . "</dispatchPointName>\n";
|
|
if (array_key_exists('boxMachineName', $packData))
|
|
$packsXML .= "<boxMachineName>" . $packData['boxMachineName'] . "</boxMachineName>\n";
|
|
if (array_key_exists('alternativeBoxMachineName', $packData))
|
|
$packsXML .= "<alternativeBoxMachineName>" . $packData['alternativeBoxMachineName'] . "</alternativeBoxMachineName>\n";
|
|
if (array_key_exists('packType', $packData))
|
|
$packsXML .= "<packType>" . $packData['packType'] . "</packType>\n";
|
|
if (array_key_exists('customerDelivering', $packData))
|
|
$packsXML .= "<customerDelivering>" . $packData['customerDelivering'] . "</customerDelivering>\n";
|
|
else
|
|
$packsXML .= "<customerDelivering>false</customerDelivering>\n";
|
|
if ( isset( $packData['insuranceAmount'] ) ) {
|
|
$packsXML .= "<insuranceAmount>" . $packData['insuranceAmount'] . "</insuranceAmount>\n";
|
|
}
|
|
if ( isset( $packData['onDeliveryAmount'] ) ) {
|
|
$packsXML .= "<onDeliveryAmount>" . $packData['onDeliveryAmount'] . "</onDeliveryAmount>\n";
|
|
}
|
|
if (array_key_exists('customerRef', $packData))
|
|
$packsXML .= "<customerRef>" . $packData['customerRef'] . "</customerRef>\n";
|
|
if (array_key_exists('senderBoxMachineName', $packData))
|
|
$packsXML .= "<senderBoxMachineName>" . $packData['senderBoxMachineName'] . "</senderBoxMachineName>\n";
|
|
if (array_key_exists('senderAddress', $packData) and !empty($packData['senderAddress'])) {
|
|
$packsXML .= "<senderAddress>\n";
|
|
$tmpFieldsArray = array('name', 'surName', 'email', 'phoneNum', 'street', 'buildingNo', 'flatNo', 'town', 'zipCode', 'province');
|
|
foreach ($tmpFieldsArray as $tmpField) {
|
|
if (array_key_exists($tmpField, $packData['senderAddress']) && !empty($packData['senderAddress'][$tmpField])) {
|
|
$packsXML .= "<$tmpField>" . $packData['senderAddress'][$tmpField] . "</$tmpField>\n";
|
|
}
|
|
}
|
|
$packsXML .= "</senderAddress>\n";
|
|
}
|
|
if (array_key_exists('receiverAddress', $packData) and !empty($packData['receiverAddress'])) {
|
|
$packsXML .= "<receiverAddress>\n";
|
|
$tmpFieldsArray = array('name', 'surName', 'companyName', 'email', 'phoneNum', 'street', 'buildingNo', 'flatNo', 'town', 'zipCode', 'province');
|
|
foreach ($tmpFieldsArray as $tmpField) {
|
|
if (array_key_exists($tmpField, $packData['receiverAddress']) && !empty($packData['receiverAddress'][$tmpField])) {
|
|
$packsXML .= "<$tmpField><![CDATA[" . $packData['receiverAddress'][$tmpField] . "]]></$tmpField>\n";
|
|
}
|
|
}
|
|
$packsXML .= "</receiverAddress>\n";
|
|
}
|
|
if (array_key_exists('allegro', $packData)) {
|
|
$allegro = "<userId>" . $packData['allegro']['userId'] . "</userId>\n";
|
|
$allegro .= "<transactionId>" . $packData['allegro']['transactionId'] . "</transactionId>\n";
|
|
$packsXML .= "<allegro>" . $allegro . "</allegro>\n";
|
|
}
|
|
$packsXML .= "</pack>\n";
|
|
}
|
|
$packsXML .= "</paczkomaty>\n";
|
|
$packsData = array('email' => $email, 'digest' => $digest, 'content' => $packsXML);
|
|
|
|
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
$postData = http_build_query($packsData);
|
|
if ( $packsResponse = inpost_post_request("$inpost_api_url/?do=createdeliverypacks", $postData ) ) {
|
|
$parsedXML = inpost_xml2array($packsResponse);
|
|
if ( isset( $parsedXML['error'] ) ) {
|
|
return array('error' => array('key' => $parsedXML['error']['key'], 'message' => $parsedXML['error']['message']));
|
|
}
|
|
if ( isset( $parsedXML['paczkomaty']['error'] ) ) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'], 'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
|
|
if (isset($parsedXML['paczkomaty']['pack']))
|
|
$packsData = $parsedXML['paczkomaty']['pack'];
|
|
if (!isset($packsData[0])) {
|
|
$temp = $packsData;
|
|
$packsData = array();
|
|
$packsData[0] = $temp;
|
|
}
|
|
if (count($packsData)) {
|
|
foreach ($packsData as $packData) {
|
|
if (isset($packData['packcode']['value']))
|
|
$resultData[$packData['id']['value']]['packcode'] = $packData['packcode']['value'];
|
|
if (isset($packData['customerdeliveringcode']['value']))
|
|
$resultData[$packData['id']['value']]['customerdeliveringcode'] = $packData['customerdeliveringcode']['value'];
|
|
if (isset($packData['error']['attr']['key']))
|
|
$resultData[$packData['id']['value']]['error_key'] = $packData['error']['attr']['key'];
|
|
if (isset($packData['error']['value']))
|
|
$resultData[$packData['id']['value']]['error_message'] = $packData['error']['value'];
|
|
if (isset($packData['pack']['error']['value']))
|
|
$resultData[$packData['id']['value']]['error_message'] = $packData['pack']['error']['value'];
|
|
}
|
|
if (isset($resultData))
|
|
return $resultData;
|
|
else
|
|
return array( 'error' => array( 'key' => 'error', 'message' => $json['message'] = __( 'Wystąpił błąd podczas przetwarzania żądania: ', 'woocommerce-paczkomaty-inpost' ) . print_r( $parsedXML, true ) ) );
|
|
}
|
|
}
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_send_letters($email, $password, $packsData, $autoLabels=0 ) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
|
|
$digest = inpost_digest($password);
|
|
|
|
if (count($packsData)) {
|
|
|
|
$packsXML = "<letters>\n";
|
|
$packsXML .= "<autoLabels>$autoLabels</autoLabels>\n";
|
|
foreach ($packsData as $packId => $packData) {
|
|
$packsXML .= "<letter>\n";
|
|
$packsXML .= "<addresseeEmail>" . $packData['adreseeEmail'] . "</addresseeEmail>\n";
|
|
$packsXML .= "<id>" . $packId . "</id>\n";
|
|
$packsXML .= "<senderEmail>" . $packData['senderEmail'] . "</senderEmail>\n";
|
|
$packsXML .= "<phoneNum>" . $packData['phoneNum'] . "</phoneNum>\n";
|
|
//$packsXML .= "<dispatchPointName>" . $packData['senderBoxMachineName'] . "</dispatchPointName>\n";
|
|
$packsXML .= "<senderBoxMachineName>" . $packData['senderBoxMachineName'] . "</senderBoxMachineName>\n";
|
|
//$packsXML .= "<insuranceAmount>" . $packData['insuranceAmount'] . "</insuranceAmount>\n";
|
|
//$packsXML .= "<onDeliveryAmount>" . $packData['onDeliveryAmount'] . "</onDeliveryAmount>\n";
|
|
if (array_key_exists('customerRef', $packData))
|
|
$packsXML .= "<customerRef>" . $packData['customerRef'] . "</customerRef>\n";
|
|
if (array_key_exists('senderAddress', $packData) and !empty($packData['senderAddress'])) {
|
|
$packsXML .= "<senderAddress>\n";
|
|
$tmpFieldsArray = array('name', 'surName', 'companyName', 'email', 'phoneNum', 'street', 'buildingNo', 'flatNo', 'town', 'zipCode', 'province');
|
|
foreach ($tmpFieldsArray as $tmpField) {
|
|
if (array_key_exists($tmpField, $packData['senderAddress']) && !empty($packData['senderAddress'][$tmpField])) {
|
|
$packsXML .= "<$tmpField><![CDATA[" . str_replace( '&', '&', $packData['senderAddress'][$tmpField] ) . "]]></$tmpField>\n";
|
|
}
|
|
}
|
|
$packsXML .= "</senderAddress>\n";
|
|
}
|
|
if (array_key_exists('receiverAddress', $packData) and !empty($packData['receiverAddress'])) {
|
|
$packsXML .= "<receiverAddress>\n";
|
|
$tmpFieldsArray = array('name', 'surName', 'companyName', 'email', 'phoneNum', 'street', 'buildingNo', 'flatNo', 'town', 'zipCode', 'province');
|
|
foreach ($tmpFieldsArray as $tmpField) {
|
|
if (array_key_exists($tmpField, $packData['receiverAddress']) && !empty($packData['receiverAddress'][$tmpField])) {
|
|
$packsXML .= "<$tmpField><![CDATA[" . $packData['receiverAddress'][$tmpField] . "]]></$tmpField>\n";
|
|
}
|
|
}
|
|
$packsXML .= "</receiverAddress>\n";
|
|
}
|
|
if (array_key_exists('allegro', $packData)) {
|
|
$allegro = "<userId>" . $packData['allegro']['userId'] . "</userId>\n";
|
|
$allegro .= "<transactionId>" . $packData['allegro']['transactionId'] . "</transactionId>\n";
|
|
$packsXML .= "<allegro>" . $allegro . "</allegro>\n";
|
|
}
|
|
$packsXML .= "</letter>\n";
|
|
}
|
|
$packsXML .= "</letters>\n";
|
|
$packsData = array('email' => $email, 'digest' => $digest, 'content' => $packsXML);
|
|
|
|
|
|
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
$postData = http_build_query($packsData);
|
|
if ($packsResponse = inpost_post_request("$inpost_api_url/?do=createdeliveryletters", $postData)) {
|
|
$parsedXML = inpost_xml2array($packsResponse);
|
|
if ( isset( $parsedXML['error'] ) ) {
|
|
return array('error' => array('key' => $parsedXML['error']['key'], 'message' => $parsedXML['error']['message']));
|
|
}
|
|
if (isset($parsedXML['letters']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['letters']['error']['attr']['key'], 'message' => $parsedXML['letters']['error']['value']));
|
|
}
|
|
if ( isset( $parsedXML['paczkomaty'] ) && isset( $parsedXML['paczkomaty']['error'] ) ) {
|
|
return array( 'error' => array( 'key' => $parsedXML['paczkomaty']['error']['attr']['key'], 'message' => $parsedXML['paczkomaty']['error']['value'] ) );
|
|
}
|
|
|
|
if (isset($parsedXML['letters']['letter'])) {
|
|
$packsData = $parsedXML['letters']['letter'];
|
|
}
|
|
if (!isset($packsData[0])) {
|
|
$temp = $packsData;
|
|
$packsData = array();
|
|
$packsData[0] = $temp;
|
|
}
|
|
if (count($packsData)) {
|
|
foreach ($packsData as $packData) {
|
|
if (isset($packData['parcelCode']['value'])) {
|
|
$resultData[$packData['tmpId']['value']]['packcode'] = $packData['parcelCode']['value'];
|
|
}
|
|
if (isset($packData['customerDeliveringCode']['value']))
|
|
$resultData[$packData['tmpId']['value']]['customerdeliveringcode'] = $packData['customerDeliveringCode']['value'];
|
|
if (isset($packData['error']['attr']['key']))
|
|
$resultData[$packData['tmpId']['value']]['error_key'] = $packData['error']['attr']['key'];
|
|
if (isset($packData['error']['value']))
|
|
$resultData[$packData['tmpId']['value']]['error_message'] = $packData['error']['value'];
|
|
}
|
|
if (isset($resultData))
|
|
return $resultData;
|
|
else
|
|
return array( 'error' => array( 'key' => 'error', 'message' => $json['message'] = __( 'Wystąpił błąd podczas przetwarzania żądania: ', 'woocommerce-paczkomaty-inpost' ) . print_r( $parsedXML, true ) ) );
|
|
}
|
|
}
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_get_sticker($email, $password, $packCode, $labelType='', $labelFormat = '') {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
|
|
$digest = inpost_digest($password);
|
|
if (isset($packCode)) {
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
|
|
$customerData = array('email' => $email, 'digest' => $digest, 'packcode' => $packCode, 'labelType' => $labelType, 'labelFormat' => $labelFormat);
|
|
$postData = http_build_query($customerData);
|
|
if ($customerResponse = inpost_post_request("$inpost_api_url/?do=getsticker", $postData)) {
|
|
if (strpos($customerResponse, '<?xml') === false )
|
|
return $customerResponse;
|
|
$parsedXML = inpost_xml2array($customerResponse);
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'],
|
|
'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
}
|
|
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_cancel_pack($email, $password, $packCode) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
|
|
$digest = inpost_digest($password);
|
|
|
|
if (isset($packCode)) {
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
|
|
$customerData = array('email' => $email, 'digest' => $digest, 'packcode' => $packCode);
|
|
$postData = http_build_query($customerData);
|
|
|
|
|
|
if ($customerResponse = inpost_post_request("$inpost_api_url/?do=cancelpack", $postData)) {
|
|
|
|
$parsedXML = inpost_xml2array($customerResponse);
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'],
|
|
'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
else
|
|
return $customerResponse;
|
|
}
|
|
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_change_packsize($email, $password, $packCode, $packSize) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
|
|
$digest = inpost_digest($password);
|
|
|
|
if (isset($packCode) && isset($packSize)) {
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
|
|
$customerData = array('email' => $email, 'digest' => $digest, 'packcode' => $packCode, 'packsize' => $packSize);
|
|
$postData = http_build_query($customerData);
|
|
|
|
|
|
if ($customerResponse = inpost_post_request("$inpost_api_url/?do=change_packsize", $postData)) {
|
|
|
|
$parsedXML = inpost_xml2array($customerResponse);
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'],
|
|
'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
else
|
|
return $customerResponse;
|
|
}
|
|
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_get_stickers($email, $password, $packCodes, $labelType='') {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
|
|
$digest = inpost_digest($password);
|
|
|
|
|
|
|
|
if (is_array($packCodes)) {
|
|
//$customerEmail = $customerData['email'];
|
|
$customerData = array('email' => $email, 'digest' => $digest, 'packcodes' => $packCodes, 'labeltype' => $labelType);
|
|
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
$postData = http_build_query($customerData);
|
|
|
|
if ($customerResponse = inpost_post_request("$inpost_api_url/?do=getstickers", $postData)) {
|
|
if (strpos($customerResponse, 'PDF'))
|
|
return $customerResponse;
|
|
$parsedXML = inpost_xml2array($customerResponse);
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'],
|
|
'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
}
|
|
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_set_customer_ref($email, $password, $packCode, $customerRef) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
|
|
$digest = inpost_digest($password);
|
|
|
|
if (isset($packCode)) {
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
|
|
//$customerEmail = $customerData['email'];
|
|
$customerData = array('email' => $email, 'digest' => $digest, 'packcode' => $packCode,
|
|
'customerref' => $customerRef);
|
|
$postData = http_build_query($customerData);
|
|
if ($customerResponse = inpost_post_request("$inpost_api_url/?do=setcustomerref", $postData)) {
|
|
if (strpos($customerResponse, 'Set'))
|
|
return 1;
|
|
$parsedXML = inpost_xml2array($customerResponse);
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'],
|
|
'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
}
|
|
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_get_confirm_printout($email, $password, $packCodes, $testPrintout=0) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
|
|
$digest = inpost_digest($password);
|
|
|
|
if (is_array($packCodes)) {
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
|
|
$packsXML = "<paczkomaty>\n";
|
|
$packsXML .= "<testprintout>$testPrintout</testprintout>\n";
|
|
foreach ($packCodes as $packCode) {
|
|
$packsXML .= "<pack>\n";
|
|
$packsXML .= "<packcode>" . $packCode . "</packcode>\n";
|
|
$packsXML .= "</pack>\n";
|
|
}
|
|
$packsXML .= "</paczkomaty>\n";
|
|
|
|
$packsData = array('email' => $email, 'digest' => $digest, 'content' => $packsXML);
|
|
$postData = http_build_query($packsData);
|
|
|
|
if ($customerResponse = inpost_post_request("$inpost_api_url/?do=getconfirmprintout", $postData)) {
|
|
if (strpos($customerResponse, 'PDF'))
|
|
return $customerResponse;
|
|
$parsedXML = inpost_xml2array($customerResponse);
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'],
|
|
'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
}
|
|
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
function inpost_get_packs_by_sender($email, $password, $parameters=array()) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
$digest = inpost_digest($password);
|
|
$paramData = array('email' => $email, 'digest' => $digest);
|
|
|
|
if (isset($parameters['status']))
|
|
$paramData['status'] = $parameters['status'];
|
|
if (isset($parameters['startdate']))
|
|
$paramData['startdate'] = $parameters['startdate'];
|
|
if (isset($parameters['enddate']))
|
|
$paramData['enddate'] = $parameters['enddate'];
|
|
if (isset($parameters['is_conf_printed']))
|
|
$paramData['is_conf_printed'] = $parameters['is_conf_printed'];
|
|
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
|
|
$postData = http_build_query($paramData);
|
|
if ($packsResponse = inpost_post_request("$inpost_api_url/?do=getpacksbysender", $postData)) {
|
|
$parsedXML = inpost_xml2array($packsResponse);
|
|
|
|
$packsData = $parsedXML['paczkomaty']['pack'];
|
|
if (!isset($packsData[0])) {
|
|
$temp = $packsData;
|
|
$packsData = array();
|
|
$packsData[0] = $temp;
|
|
}
|
|
if (count($packsData)) {
|
|
$i = 0;
|
|
foreach ($packsData as $packData) {
|
|
foreach ($packData as $param => $value) {
|
|
if (isset($value['value']))
|
|
$resultData[$i][$param] = $value['value']; else
|
|
$resultData[$i][$param] = '';
|
|
}
|
|
$i++;
|
|
}
|
|
return $resultData;
|
|
}
|
|
}
|
|
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
|
|
return 0;
|
|
}
|
|
|
|
function inpost_get_cod_report($email, $password, $parameters=array()) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
$digest = inpost_digest($password);
|
|
$paramData = array('email' => $email, 'digest' => $digest);
|
|
|
|
if (isset($parameters['startdate']))
|
|
$paramData['startdate'] = $parameters['startdate'];
|
|
if (isset($parameters['enddate']))
|
|
$paramData['enddate'] = $parameters['enddate'];
|
|
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
|
|
$postData = http_build_query($paramData);
|
|
if ($packsResponse = inpost_post_request("$inpost_api_url/?do=getcodreport", $postData)) {
|
|
$parsedXML = inpost_xml2array($packsResponse);
|
|
|
|
$packsData = $parsedXML['paczkomaty']['payment'];
|
|
if (!isset($packsData[0])) {
|
|
$temp = $packsData;
|
|
$packsData = array();
|
|
$packsData[0] = $temp;
|
|
}
|
|
if (count($packsData)) {
|
|
$i = 0;
|
|
foreach ($packsData as $packData) {
|
|
foreach ($packData as $param => $value) {
|
|
if (isset($value['value']))
|
|
$resultData[$i][$param] = $value['value']; else
|
|
$resultData[$i][$param] = '';
|
|
}
|
|
$i++;
|
|
}
|
|
return $resultData;
|
|
}
|
|
}
|
|
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
|
|
return 0;
|
|
}
|
|
|
|
function inpost_pay_for_pack($email, $password, $packcode) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
$digest = inpost_digest($password);
|
|
$paramData = array('email' => $email, 'digest' => $digest, 'packcode' => $packcode);
|
|
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
|
|
$postData = http_build_query($paramData);
|
|
if ($packsResponse = inpost_post_request("$inpost_api_url/?do=payforpack", $postData)) {
|
|
|
|
$parsedXML = inpost_xml2array($packsResponse);
|
|
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'],
|
|
'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
else
|
|
return 1;
|
|
}
|
|
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
function inpost_get_dispatch_points($email, $password) {
|
|
|
|
global $inpost_api_url;
|
|
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
$digest = inpost_digest($password);
|
|
|
|
$_lastArgSeparatorOutput = ini_get('arg_separator.output');
|
|
ini_set('arg_separator.output', '&');
|
|
|
|
$packsXML = "<paczkomaty>\n";
|
|
$packsXML .= "<name></name>";
|
|
$packsXML .= "<agencyName></agencyName>";
|
|
$packsXML .= "<dispatchPointStatus>ACTIVE</dispatchPointStatus>";
|
|
|
|
$packsXML .= "</paczkomaty>\n";
|
|
|
|
$packsData = array('email' => $email, 'digest' => $digest, 'content' => $packsXML);
|
|
$postData = http_build_query($packsData);
|
|
|
|
if ($packsResponse = inpost_post_request("$inpost_api_url/?do=getdispatchpoints", $postData)) {
|
|
|
|
$parsedXML = inpost_xml2array($packsResponse);
|
|
if (isset($parsedXML['paczkomaty']['error'])) {
|
|
return array('error' => array('key' => $parsedXML['paczkomaty']['error']['attr']['key'],
|
|
'message' => $parsedXML['paczkomaty']['error']['value']));
|
|
}
|
|
else
|
|
return $parsedXML;
|
|
}
|
|
|
|
ini_set('arg_separator.output', $_lastArgSeparatorOutput);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
function inpost_listmachines( $pickuppoint = '', $paymentavailable = '' ) {
|
|
$transient_name = 'paczkomaty_paczkomaty_p'.$pickuppoint.'_p.'.$paymentavailable;
|
|
$paczkomaty = get_transient( $transient_name );
|
|
if ( !$paczkomaty )
|
|
{
|
|
global $inpost_api_url;
|
|
$inpost_api_url = str_replace('http://', 'https://', $inpost_api_url);
|
|
$url = "$inpost_api_url/?do=listmachines_xml&pickuppoint=$pickuppoint&paymentavailable=$paymentavailable";
|
|
$args = array( 'timeout' => 50, 'sslverify' => false );
|
|
$response = wp_remote_get( $url, $args );
|
|
|
|
if ( is_wp_error( $response ) )
|
|
{
|
|
return array( '0' => 'Błąd przy pobieraniu listy paczkomatów: ' . $response->get_error_message() );
|
|
}
|
|
else {
|
|
$paczkomaty = array();
|
|
$response = inpost_xml2array( $response['body'] );
|
|
if ( isset( $response['paczkomaty']['machine'] ) ) {
|
|
foreach ( $response['paczkomaty']['machine'] as $paczkomat ) {
|
|
$paczkomaty[ $paczkomat['name']['value'] ] =
|
|
'[' . $paczkomat['name']['value'] . '] ' .
|
|
$paczkomat['town']['value'] . ', ';
|
|
if ( isset( $paczkomat['street'] ) && isset( $paczkomat['street']['value'] ) ) {
|
|
$paczkomaty[ $paczkomat['name']['value'] ] .= $paczkomat['street']['value'] . ' ';
|
|
}
|
|
if ( isset( $paczkomat['buildingnumber'] ) && isset( $paczkomat['buildingnumber']['value'] ) ) {
|
|
$paczkomaty[ $paczkomat['name']['value'] ] .= $paczkomat['buildingnumber']['value'];
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
return $paczkomaty;
|
|
}
|
|
}
|
|
set_transient( $transient_name, $paczkomaty, DAY_IN_SECONDS );
|
|
}
|
|
return $paczkomaty;
|
|
}
|
|
|