first commit

This commit is contained in:
2024-12-17 13:43:22 +01:00
commit 8e6cd8b410
21292 changed files with 3514826 additions and 0 deletions

View File

@@ -0,0 +1,191 @@
<?php
require_once 'EpakaCurl.php';
class EpakaApi {
const API_URL = 'https://epaka.pl/';
const API_URL_FULL = 'https://epaka.pl/';
// const API_URL = 'http://epaka7/';
// const API_URL = 'http://epaka.localhost/';
// const API_URL_FULL = 'http://epaka.localhost/';
const LOOP_LIMIT = 3;
private $connection = null;
private $sessionLogin = null;
private $sessionPassword = null;
private $sessionToken = null;
private $userData = null;
private $carriersEpaka = null;
public function __construct()
{
$this->connection = new EpakaCurl(self::API_URL);
}
public static function getUrl() {
return self::API_URL;
}
public static function getUrlFull() {
return self::API_URL_FULL;
}
public function init($login = null, $password = null, $session = null) {
if (!empty($login)) {
$this->setSessionLogin($login);
}
if (!empty($password)) {
$this->setSessionPassword($password);
}
if (!empty($session)) {
$this->setSessionToken($session);
}
}
private function setSessionLogin($login) {
$this->sessionLogin = $login;
}
private function setSessionPassword($password) {
$this->sessionPassword = $password;
}
private function setSessionToken($session) {
$this->sessionToken = $session;
}
private function setUserData($userData) {
$this->userData = $userData;
}
public function getSessionLogin() {
return (!empty($this->sessionLogin)) ? $this->sessionLogin : false;
}
public function getSessionPassword() {
return (!empty($this->sessionPassword)) ? $this->sessionPassword : false;
}
public function getSessionToken() {
return (!empty($this->sessionToken)) ? $this->sessionToken : false;
}
public function getUserData() {
return (!empty($this->userData)) ? $this->userData : false;
}
public function connected() {
return $this->getSessionToken() && $this->getSessionPassword() && $this->getSessionToken();
}
public function getApiTokenAuth($login = null, $password = null)
{
$data = [
'email' => $login,
'password' => $password,
];
if ($dataTmp = $this->connection->post('api/', 'login.xml', $data, 'xml')) {
if ($dataTmp->status == "OK") {
$this->setSessionLogin($login);
$this->setSessionPassword($password);
$this->setSessionToken($dataTmp->session);
return $this->getSessionToken();
}
};
return false;
}
public function getApiUserData()
{
if (!$this->getSessionToken()) {
return false;
}
$data = [
'session' => $this->getSessionToken(),
];
if ($dataTmp = $this->postData('api/', 'profile.xml', $data, 'xml')) {
$this->setUserData($dataTmp);
return $this->getUserData();
};
return false;
}
public function setApiUserData($data = null)
{
if (!$this->getSessionToken()) {
return false;
}
$data = array_merge([
'session' => $this->getSessionToken(),
], $data);
if ($dataTmp = $this->postData('api/', 'saveProfile.xml', $data)) {
return $dataTmp;
};
return false;
}
public function getMap($path = null, $endpoint = null, $data = null, $responseType = "XML")
{
if (!$this->getSessionToken()) {
return false;
}
$data = array_merge([
'session' => $this->getSessionToken(),
], $data);
if ($dataTmp = $this->postData($path, $endpoint, $data, $responseType)) {
return $dataTmp;
};
return false;
}
public function postData($path = 'api/', $endpoint = null, $data = null, $responseType = "XML", $loopLimit = 0, $session = null)
{
if (!$this->getSessionToken()) {
return false;
}
if ($loopLimit >= self::LOOP_LIMIT) {
return false;
// throw new Exception('Przekroczono limit połączeń do API. Skontaktuj się z administratorem serwisu Epaka.pl');
}
if (!empty($session)) {
$this->setSessionToken($session);
}
$data = array_merge($data, [
'session' => $this->getSessionToken(),
]);
if ($dataTmp = $this->connection->post($path, $endpoint, $data, $responseType)) {
if (($responseType == "html" && strpos($dataTmp, "Errors - Epaka.pl") === false) || ($responseType != "html" && $dataTmp->status == "OK")) {
return $dataTmp;
} elseif (($responseType == "html" && strpos($dataTmp, "Errors - Epaka.pl") !== false) || ($responseType != "html" && $dataTmp->status == "ERROR")) {
if ($newSessionToken = $this->getApiTokenAuth($this->getSessionLogin(), $this->getSessionPassword())) {
Configuration::updateValue('EPAKA_API_SESSION', $newSessionToken);
$loopLimit += 1;
if ($dataTmp = $this->postData($path, $endpoint, $data, $responseType, $loopLimit, $newSessionToken)) {
if (($responseType == "html" && strpos($dataTmp, "Errors - Epaka.pl") === false) || ($responseType != "html" && $dataTmp->status == "OK")) {
return $dataTmp;
}
}
}
}
};
return false;
}
public function getCarriersEpaka() {
if (empty($this->carriersEpaka)) {
$this->carriersEpaka = $this->postData('api/', 'getAvailableCouriers.xml', [], 'xml');
}
return $this->carriersEpaka;
}
}

View File

@@ -0,0 +1,46 @@
<?php
class EpakaCurl {
private $API_URL = null;
public function __construct($api_url)
{
$this->API_URL = $api_url;
}
public function post($path = null, $endPoint, $data = [], $responseType = "xml")
{
if (empty($data)) {
$data = [];
}
$ch = curl_init();
// curl_setopt($ch, CURLOPT_URL, $this->API_URL . $path . $endPoint . '?XDEBUG_SESSION=1');
curl_setopt($ch, CURLOPT_URL, $this->API_URL . $path . $endPoint);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POSTREDIR,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
if (strtolower($responseType) == "xml") {
$result = simplexml_load_string($result, 'SimpleXMLElement', LIBXML_NOCDATA);
$result = json_encode($result);
}
if (strtolower($responseType) != "html") {
$result = json_decode($result);
}
curl_close($ch);
if (isset($result) && !empty($result)) {
return $result;
}
return false;
}
}

View File

@@ -0,0 +1,240 @@
<?php
class EpakaDB
{
public static function addAdminController($className, $module, $position = 1)
{
if(Tab::getIdFromClassName($className) === false){
$sql = "INSERT INTO ". _DB_PREFIX_ ."tab
(id_tab, id_parent, class_name, module, position, active, hide_host_mode)
VALUES (NULL, '-1', '".pSQL($className)."', '".pSQL($module)."' , '".$position."', '1', '0')";
return Db::getInstance()->execute($sql);
}
return true;
}
public static function createTable($tableName, $columnsArr, $primaryKeys = null, $engineDb, $charset = 'utf8', $collate = 'utf8_general_ci')
{
$query = 'CREATE TABLE IF NOT EXISTS '._DB_PREFIX_.$tableName.'(';
$i = 0;
foreach ($columnsArr as $column => $values){
$i++;
$query .= $column.' '.$values;
if ($i < count($columnsArr)) {
$query .= ', ';
}
}
if (!empty($primaryKeys)) {
$query .= ', PRIMARY KEY ('.implode(',',$primaryKeys ).'))';
} else {
$query .= ')';
}
$query .= 'ENGINE = '.pSQL($engineDb);
$query .= ' CHARSET = '.pSQL($charset);
$query .= ' COLLATE = '.pSQL($collate);
return DB::getInstance()->execute($query);
}
public static function dropTable($tableName)
{
$query = 'DROP TABLE IF EXISTS '._DB_PREFIX_.$tableName.';';
return DB::getInstance()->execute($query);
}
public static function deleteFromTable($tableName, $columnName, $value)
{
$query = 'DELETE FROM '._DB_PREFIX_.$tableName.' WHERE '.$columnName.'="'.$value.'";';
return DB::getInstance()->execute($query);
}
public static function existsTable($tableName)
{
$query = 'SELECT 1 FROM '._DB_PREFIX_.$tableName.' LIMIT 1;';
try {
$result = DB::getInstance()->execute($query);
} catch (PrestaShopException $e) {
$result = false;
}
return $result;
}
public static function getCourriers($type = null)
{
$sql = new DbQuery();
$sql->select('*');
$sql->from('epaka_carriers', 'ec');
if (!empty($type)) {
$sql->where('delivery_type = '.$type);
}
$result = Db::getInstance()->executeS($sql);
// $array = array();
// foreach ($result as $row) {
// $array[$row['machine']] = $row['id_machine_type'];
// }
return $result;
}
public static function getCourriersRelations($idPresta = null, $idEpaka = null)
{
$sql = new DbQuery();
$sql->select('*');
$sql->from('epaka_carriers_relations', 'ecr');
if (!empty($idPresta)) {
$sql->where('ecr.prestashop_id = '.$idPresta.'');
}
if (!empty($idEpaka)) {
$sql->where('ecr.epaka_id = '.$idEpaka.'');
}
$result = Db::getInstance()->executeS($sql);
return $result;
}
public static function clearCourriersRelations()
{
return Db::getInstance()->delete('epaka_carriers_relations');
}
public static function addCourriersRelation($idPresta, $idEpaka, $epakaCariers = null)
{
if (empty($epakaCariers)) {
return false;
}
// polaczone z epaka.pl
if (!empty($idEpaka)) {
foreach ($epakaCariers as $eCTmp) {
if ($eCTmp->courierId == $idEpaka) {
if (!empty((array)$eCTmp->courierMapSourceId) && $eCTmp->courierPointDelivery == "1") {
$epakaCarrierDeliveryType = 'p2p';
} else {
$epakaCarrierDeliveryType = 'd2d';
}
break;
}
}
}
// NIE polaczone z epaka.pl
else {
$epakaCarrierDeliveryType = 'onp';
}
return Db::getInstance()->insert('epaka_carriers_relations', array(
'prestashop_id' => (int)$idPresta, 'epaka_id' => (int)$idEpaka, 'epaka_carrier_delivery_type' => $epakaCarrierDeliveryType
));
}
public static function getBasketDelivery($idCart = null)
{
$result = false;
$sql = new DbQuery();
$sql->select('*');
$sql->from('epaka_delivery', 'ed');
if (!empty($idCart)) {
$sql->where('id_cart = '.(int)$idCart);
$result = Db::getInstance()->getRow($sql);
} else {
$result = Db::getInstance()->executeS($sql);
}
return $result;
}
/* public static function getCarrierTypes($id_carrier_prestashop = null)
{
$sql = new DbQuery();
$sql->select('ec.epaka_id, ec.epaka_name, ec.epaka_name_short, c.id_carrier as presta_id, c.name as presta_name');
$sql->from('epaka_carriers_relations', 'ecr');
$sql->innerJoin('epaka_carriers', 'ec', 'ecr.epaka_id = ec.epaka_id');
$sql->innerJoin(
'carrier',
'c',
'c.id_carrier = ecr.prestashop_id AND active = 1 AND deleted = 0');
if (!empty($id_carrier_prestashop)) {
$sql->where('ecr.prestashop_id = '.$id_carrier_prestashop);
}
$result = Db::getInstance()->executeS($sql);
if(empty($result)){
return array();
}
return $result;
} */
public static function getCarrierByShort($short)
{
$sql = new DbQuery();
$sql->select('*');
$sql->from('epaka_carriers', 'ec');
$sql->where('ec.epaka_name_short LIKE "'.$short.'"');
return Db::getInstance()->getRow($sql);
}
public static function checkIfIsOrderReferenceIsOK($id_cart = null, $id_carrier_prestashop = null, $id_carrier_epaka = null)
{
$sql = new DbQuery();
$sql->select('*');
$sql->from('epaka_delivery', 'ed');
if (!empty($id_cart)) {
$sql->where('ed.id_cart = '.$id_cart.'');
}
if (!empty($id_carrier_prestashop)) {
$sql->where('ed.id_carrier_prestashop = '.$id_carrier_prestashop.'');
}
if (!empty($id_carrier_epaka)) {
$sql->where('ed.id_carrier_epaka = '.$id_carrier_epaka.'');
}
return Db::getInstance()->getRow($sql);
}
public static function addEpakaId($id_cart = null, $id_epaka_order = null)
{
$sql = 'UPDATE '._DB_PREFIX_.'epaka_delivery';
$sql .= ' SET id_epaka_order = '.pSQL($id_epaka_order);
$sql .= ' WHERE id_cart = '.pSQL($id_cart);
$sql .= ';';
return DB::getInstance()->execute($sql);
}
public static function delEpakaId($id_cart = null)
{
$sql = 'UPDATE '._DB_PREFIX_.'epaka_delivery';
$sql .= ' SET id_epaka_order = NULL';
$sql .= ' WHERE id_cart = '.pSQL($id_cart);
$sql .= ';';
return DB::getInstance()->execute($sql);
}
public static function insertRelation($id_cart, $id_carrier_prestashop, $id_carrier_epaka, $point_code = null, $point_name = null, $id_epaka_order = null)
{
$insertData = [
'id_cart' => $id_cart,
'id_carrier_prestashop' => $id_carrier_prestashop,
'id_carrier_epaka' => $id_carrier_epaka,
'point_code' => $point_code,
'point_name' => $point_name,
'id_epaka_order' => $id_epaka_order
];
return Db::getInstance()->insert('epaka_delivery',$insertData, false, true, Db::ON_DUPLICATE_KEY);;
}
public static function getUnfinishedPrestaOrders()
{
$sql = 'SELECT * FROM '._DB_PREFIX_.'orders';
$sql .= ' WHERE current_state <> 4'; // 4 -Dostarczane;
$sql .= ';';
return DB::getInstance()->executeS($sql);
}
}

View File

@@ -0,0 +1,398 @@
<?php
require_once __DIR__.'/EpakaApi.php';
class EpakaOrder
{
private $api = null;
private $deliveryAddress = null;
private $orderData = null;
public function __construct()
{
$this->api = new EpakaApi();
}
public function getFormOrderHtml($idOrder)
{
$order = new Order($idOrder);
if (!$order->id) {
return false;
}
try {
if (!empty($epaka_api_email = Configuration::get('EPAKA_API_EMAIL')) &&
!empty($epaka_api_password = Configuration::get('EPAKA_API_PASSWORD')) &&
!empty($epaka_api_session = Configuration::get('EPAKA_API_SESSION'))) {
$this->api->init($epaka_api_email, $epaka_api_password, $epaka_api_session);
}
} catch (Throwable $e) {
throw new Exception('Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.');
}
try{
$orderFormHtml = $this->api->postData('api/', 'getOrderIframe', [], 'html');
}catch(Throwable $e){
throw new Exception('Error get url.<br>'.$e->getMessage());
}
return $orderFormHtml;
}
public function prepareAddress($address)
{
if (!is_string($address)) {
return false;
}
$address = trim($address);
$addressDivided = array();
$pattern = '/([ \p{L}\d]+)(m\.|lokal|lok\.|lok|pokój|pok.|pok)([ \p{L}\d]+)$/iu';
$replacement = '$1/$3';
$address = preg_replace($pattern, $replacement, $address);
$pattern = '/^([\p{L}\d\s.,]+) ([ \p{L}\d]*[\p{L}\d]+)( *(\/|\\\|m\.?) *([\p{L}\d]+[ \p{L}\d]*))?$/iu';
preg_match($pattern, $address, $addressDivided);
$return = [
'street' => '',
'house_number' => '',
'flat_number' => '',
];
if (!empty($addressDivided[2])) {
$return['house_number'] = $addressDivided[2];
} else {
$return['house_number'] = '';
}
if (!empty($addressDivided[5])) {
$return['flat_number'] = substr($addressDivided[5], 0 ,7);
} else {
$return['flat_number'] = '';
}
if (!empty($addressDivided[1])) {
$return['street'] = $addressDivided[1];
} else {
$return['street'] = '';
}
return $return;
}
public function prepareOrderData($data = null)
{
if (empty($data)) {
return false;
}
$orderData = null;
$orderPackages = [];
foreach($data['ZamowieniePaczka'] as $paczka){
array_push($orderPackages,[
"weight" => $paczka['waga'],
"length" =>$paczka['dlugosc'],
"width" => $paczka['szerokosc'],
"height" => $paczka['wysokosc'],
"unsortableShape" => $paczka['ksztalt_niestandardowy'],
]);
}
$contents = "";
if(!empty($data['ZamowienieZawartosc'][0]['zawartosc'])){
$contents = $data['ZamowienieZawartosc'];
}
$pickupTimeFrom = "";
$pickupTimeTo = "";
if(!empty($data['Zamowienie']['odbior_godzina'])){
$pickupTime = explode("-",$data['Zamowienie']['odbior_godzina']);
$pickupTimeFrom = $pickupTime[0];
$pickupTimeTo = $pickupTime[1];
}
$orderData = [
"paymentType" => $data['Zamowienie']['platnosc'],
"courierId" => $data['Zamowienie']['kurier_id'],
"senderName" => $data['Zamowienie']['nadawca_imie'],
"senderLastName" => $data['Zamowienie']['nadawca_nazwisko'],
"senderCompany" => $data['Zamowienie']['nadawca_firma'],
"senderStreet" => $data['Zamowienie']['nadawca_ulica'],
"senderHouseNumber" => $data['Zamowienie']['nadawca_nrdomu'],
"senderFlatNumber" => $data['Zamowienie']['nadawca_nrlokalu'],
"senderPostCode" => $data['Zamowienie']['nadawca_kod'],
"senderCity" => $data['Zamowienie']['nadawca_miasto'],
"senderCountry" => $data['Zamowienie']['nadawca_kraj'],
"senderPhone" => $data['Zamowienie']['nadawca_telefon'],
"senderEmail" => $data['Zamowienie']['nadawca_email'],
"senderMachineName" => $data['Zamowienie']['nadawca_paczkomat'],
"senderMachineDescription" => $data['Zamowienie']['nadawca_paczkomat_opis'],
"receiverName" => $data['Zamowienie']['odbiorca_imie'],
"receiverLastName" => $data['Zamowienie']['odbiorca_nazwisko'],
"receiverCompany" => $data['Zamowienie']['odbiorca_firma'],
"receiverStreet" => $data['Zamowienie']['odbiorca_ulica'],
"receiverHouseNumber" => $data['Zamowienie']['odbiorca_nrdomu'],
"receiverFlatNumber" => $data['Zamowienie']['odbiorca_nrlokalu'],
"receiverPostCode" => $data['Zamowienie']['odbiorca_kod'],
"receiverCity" => $data['Zamowienie']['odbiorca_miasto'],
"receiverCountry" => $data['Zamowienie']['odbiorca_kraj'],
"receiverPhone" => $data['Zamowienie']['odbiorca_telefon'],
"receiverEmail" => $data['Zamowienie']['odbiorca_email'],
"receiverMachineName" => $data['Zamowienie']['odbiorca_paczkomat'],
"receiverMachineDescription" => $data['Zamowienie']['odbiorca_paczkomat_opis'],
"packageType" => $data['Zamowienie']['rodzaj_wysylki'],
"packages" => $orderPackages,
"content" => $data['Zamowienie']['zawartosc'],
"contents" => $contents,
"pickupDate" => $data['Zamowienie']['odbior_dzien'],
"pickupTimeFrom" => $pickupTimeFrom,
"pickupTimeTo" => $pickupTimeTo,
"comments" => $data['Zamowienie']['uwagi'],
"eori" => $data['Zamowienie']['eori'],
"pesel" => $data['Zamowienie']['pesel'],
"purpose" => $data['Zamowienie']['przeznaczenie'],
"insurance" => (!empty($data['Zamowienie']['wartosc'])) ? 1 : 0,
"declaredValue" => $data['Zamowienie']['wartosc'],
];
foreach($data['ZamowienieUsluga'] as $key=>$value){
if($key != "on"){
if($value["on"] == "1"){
$orderData[$key] = 1;
}
}
}
$orderData['cod'] = (isset($data['Zamowienie']['pobranie']) && $data['Zamowienie']['pobranie'] == "on") ? 1 : 0;
$orderData['codType'] = (isset($data['Zamowienie']['pobranie']) && $data['Zamowienie']['pobranie'] == "on") ? $data['Zamowienie']['pobranie_typ'] : null;
$orderData['codAmount'] = $data['Zamowienie']['pobranie_kwota'];
$orderData['codBankAccount'] = $data['Zamowienie']['pobranie_konto'];
return $orderData;
}
public function sendOrder($data = null)
{
if (empty($data)) {
return false;
}
try {
if (!empty($epaka_api_email = Configuration::get('EPAKA_API_EMAIL')) &&
!empty($epaka_api_password = Configuration::get('EPAKA_API_PASSWORD')) &&
!empty($epaka_api_session = Configuration::get('EPAKA_API_SESSION'))) {
$this->api->init($epaka_api_email, $epaka_api_password, $epaka_api_session);
}
} catch (Throwable $e) {
// throw new Exception('Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.');
return (object)[
'status' => 'ERROR',
'message' => 'Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.'
];
}
try {
$return = $this->api->postData('api/', 'makeOrder.xml', $data, 'xml');
} catch(Throwable $e) {
// throw new Exception('Error get url.<br>'.$e->getMessage());
return (object)[
'status' => 'ERROR',
'message' => 'Błąd połączenia API Epaka. '.$e->getMessage()
];
}
return $return;
}
public function getOrderDetails($orderID)
{
if (empty($orderID)) {
return false;
}
try {
if (!empty($epaka_api_email = Configuration::get('EPAKA_API_EMAIL')) &&
!empty($epaka_api_password = Configuration::get('EPAKA_API_PASSWORD')) &&
!empty($epaka_api_session = Configuration::get('EPAKA_API_SESSION'))) {
$this->api->init($epaka_api_email, $epaka_api_password, $epaka_api_session);
}
} catch (Throwable $e) {
// throw new Exception('Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.');
return (object)[
'status' => 'ERROR',
'message' => 'Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.'
];
}
try {
$return = $this->api->postData('api/order/', $orderID.'.xml', [], 'xml');
if ($return->status == "OK") {
$return = $return->orderDetails;
} else {
$return = false;
}
} catch(Throwable $e) {
// throw new Exception('Error get url.<br>'.$e->getMessage());
return (object)[
'status' => 'ERROR',
'message' => 'Błąd połączenia API Epaka. '.$e->getMessage()
];
}
return $return;
}
public function getOrderPayment($orderID, $type = "check")
{
if (empty($orderID)) {
return false;
}
try {
if (!empty($epaka_api_email = Configuration::get('EPAKA_API_EMAIL')) &&
!empty($epaka_api_password = Configuration::get('EPAKA_API_PASSWORD')) &&
!empty($epaka_api_session = Configuration::get('EPAKA_API_SESSION'))) {
$this->api->init($epaka_api_email, $epaka_api_password, $epaka_api_session);
}
} catch (Throwable $e) {
// throw new Exception('Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.');
return (object)[
'status' => 'ERROR',
'message' => 'Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.'
];
}
$return = false;
try {
switch ($type) {
case "check":
$return = $this->api->postData('api/', 'checkPayment.xml', ['order' => $orderID], 'xml');
break;
case "get":
$return = $this->api->postData('api/', 'getPaymentDataForOrder.xml', ['orderId' => $orderID], 'xml');
break;
}
if ($return->status == "OK") {
return $return;
} else {
$return = false;
}
} catch(Throwable $e) {
// throw new Exception('Error get url.<br>'.$e->getMessage());
return (object)[
'status' => 'ERROR',
'message' => 'Błąd połączenia API Epaka. '.$e->getMessage()
];
}
return $return;
}
public function getOrderLabel($orderID = null, $zebra = 0)
{
if (empty($orderID)) {
return false;
}
$zebraTyp = 'label';
if ($zebra) {
$zebraTyp = 'labelZebra';
}
try {
if (!empty($epaka_api_email = Configuration::get('EPAKA_API_EMAIL')) &&
!empty($epaka_api_password = Configuration::get('EPAKA_API_PASSWORD')) &&
!empty($epaka_api_session = Configuration::get('EPAKA_API_SESSION'))) {
$this->api->init($epaka_api_email, $epaka_api_password, $epaka_api_session);
}
} catch (Throwable $e) {
// throw new Exception('Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.');
return (object)[
'status' => 'ERROR',
'message' => 'Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.'
];
}
try {
$return = $this->api->postData('api/'.$zebraTyp.'/', $orderID.'.xml', [], 'xml');
} catch(Throwable $e) {
// throw new Exception('Error get url.<br>'.$e->getMessage());
return (object)[
'status' => 'ERROR',
'message' => 'Błąd połączenia API Epaka. '.$e->getMessage()
];
}
return $return;
}
public function getOrderProtocol($orderID = null)
{
if (empty($orderID)) {
return false;
}
try {
if (!empty($epaka_api_email = Configuration::get('EPAKA_API_EMAIL')) &&
!empty($epaka_api_password = Configuration::get('EPAKA_API_PASSWORD')) &&
!empty($epaka_api_session = Configuration::get('EPAKA_API_SESSION'))) {
$this->api->init($epaka_api_email, $epaka_api_password, $epaka_api_session);
}
} catch (Throwable $e) {
// throw new Exception('Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.');
return (object)[
'status' => 'ERROR',
'message' => 'Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.'
];
}
try {
$return = $this->api->postData('api/protocol/', $orderID.'.xml', [], 'xml');
} catch(Throwable $e) {
// throw new Exception('Error get url.<br>'.$e->getMessage());
return (object)[
'status' => 'ERROR',
'message' => 'Błąd połączenia API Epaka. '.$e->getMessage()
];
}
return $return;
}
public function cancelOrder($orderID = null)
{
if (empty($orderID)) {
return false;
}
try {
if (!empty($epaka_api_email = Configuration::get('EPAKA_API_EMAIL')) &&
!empty($epaka_api_password = Configuration::get('EPAKA_API_PASSWORD')) &&
!empty($epaka_api_session = Configuration::get('EPAKA_API_SESSION'))) {
$this->api->init($epaka_api_email, $epaka_api_password, $epaka_api_session);
}
} catch (Throwable $e) {
// throw new Exception('Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.');
return (object)[
'status' => 'ERROR',
'message' => 'Brak połączonego konta z Epaka.pl. Przejdź do konfiguracji modułu i podaj prawidłowe dane dostępowe.'
];
}
try {
$return = $this->api->postData('api/cancelOrder/', $orderID.'.xml', [], 'xml');
if ((isset($return->status) && $return->status == "ERROR") || $return == false) {
$return = $this->api->postData('api/cancelOrderEmail/', $orderID.'.xml', [], 'xml');
}
} catch(Throwable $e) {
// throw new Exception('Error get url.<br>'.$e->getMessage());
return (object)[
'status' => 'ERROR',
'message' => 'Błąd połączenia API Epaka. '.$e->getMessage()
];
}
return $return;
}
}