Salamek / PplMyApi

Professional Parcel Logistic MyApi PHP client implementation with PDF and ZPL label generator
GNU Lesser General Public License v3.0
27 stars 34 forks source link

Problem se zprovoznenim #65

Closed KarelKopac closed 2 years ago

KarelKopac commented 2 years ago

nedari se mi zprovoznit komunikaci s PPL. Pokud otestuji komunikaci dle prikladu

`use Salamek\PplMyApi\Api;

$pplMyApi = new Api(); if ($pplMyApi->isHealthy()) { echo 'Healthy :)' . PHP_EOL; } else { echo 'Ill :( --- proste neco je f ....' . PHP_EOL; } ` dozvim se, ze je to Healthy :).

Pokud se ale podle prikladu pokusim vytvorit balik

` use Salamek\PplMyApi\Api; use Salamek\PplMyApi\Model\Package; use Salamek\PplMyApi\Model\Recipient; use Salamek\PplMyApi\Enum\Country; use Salamek\PplMyApi\Enum\Product;

$username = 'my_api_username'; $password = 'my_api_password'; $customerId = 'my_api_customer_id';

$pplMyApi = new Api($username, $password, $customerId);

$recipient = new Recipient('Olomouc', 'Adam Schubert', 'My Address', '77900', 'adam@example.com', '+420123456789', 'https://www.salamek.cz', Country::CZ, 'My Compamy a.s.');

$packageNumber = '40950000114'; / Or you can use Tools::generatePackageNumber to get this number only from $packageSeriesNumberId like 114 $packageSeriesNumberId = 114; $packageNumberInfo = new PackageNumberInfo($packageSeriesNumberId, Product::PPL_PARCEL_CZ_PRIVATE, Depo::CODE_09); $packageNumber = Tools::generatePackageNumber($packageNumberInfo); //40950000114 / $package = new Package($packageNumber, Product::PPL_PARCEL_CZ_PRIVATE, 'Testovaci balik', $recipient);

try { $pplMyApi->createPackages([$package]); } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL; } ` (samozrejme ze mam vyplnene realne prihlasovaci udaje) na strance se nevypise nic ale v error logu ctu tuto zpravu:

PHP Catchable fatal error: Argument 5 passed to Salamek\PplMyApi\Model\Package::__construct() must be an instance of Salamek\PplMyApi\Model\ICityRouting, none given, called in /data/www/domeny/xxx.cz/www/adresar/ppl-test-balik.php on line 44 and defined in /data/www/domeny/xxx.cz/vendor/salamek/ppl-my-api/src/Model/Package.php on line 91

Dekuji z radu.

Salamek commented 2 years ago

@KarelKopac ~duplicity of https://github.com/Salamek/PplMyApi/issues/61

Salamek commented 2 years ago

@KarelKopac dle #61 nevime jestli ICityRouting je povinne nebo ne, ale je treba pro tvorbu etiket takze asi je povinne...

Salamek commented 2 years ago

Hmm ale pri zadavani dat potreba neni... wth... upravim to

Salamek commented 2 years ago

@KarelKopac odstranil jsem example bez routed package, pouzite kod s Cities routing co tam zustal...

KarelKopac commented 2 years ago

Nova chyba:

PHP Fatal error: Using $this when not in object context in /data/www/domeny/xxx.cz/www/adresar/ppl-test-balik.php on line 46

line 46: $cityRoutingResponse = $this->pplMyApi->getCitiesRouting($country, null, $zipCode, $street);

Salamek commented 2 years ago

s/$this->pplMyApi/$pplMyApi/

https://github.com/Salamek/PplMyApi/commit/88e3b83935e726ea31ef6be209beebbf805f4717

Salamek commented 2 years ago

@KarelKopac zvladl jste to rozjet?

KarelKopac commented 2 years ago

Bohuzel :-( dostavam dalsi chybu:

PHP Fatal error: Uncaught exception 'Salamek\PplMyApi\Exception\WrongDataException' with message 'Country Code is not supported, use one of CZ, DE, GB, SK, AT, PL, CH, FI, HU, SI, LV, EE, LT, BE, DK, ES, FR, IE, IT, NL, NO, PT, SE, RO, BG, GR, HR, TR, LU' in /data/www/domeny/xxx.cz/vendor/salamek/ppl-my-api/src/Api.php:203\nStack trace:\n#0 /data/www/domeny/xxx.cz/www/adresar/ppl-test-balik.php(47): Salamek\PplMyApi\Api->getCitiesRouting(NULL, NULL, NULL, NULL)\n#1 {main}\n thrown in /data/www/domeny/xxx.cz/vendor/salamek/ppl-my-api/src/Api.php on line 203

radek 47: $cityRoutingResponse = $pplMyApi->getCitiesRouting($country, null, $zipCode, $street);

Cely skript:

$pplMyApi = new Api($username, $password, $customerId);

$recipient = new Recipient('Olomouc', 'Adam Schubert', 'My Address', '77900', 'adam@example.com', '+420123456789', 'https://www.salamek.cz', Country::CZ, 'My Compamy a.s.');

$packageNumber = '40950000114'; / Or you can use Tools::generatePackageNumber to get this number only from $packageSeriesNumberId like 114 $packageSeriesNumberId = 114; $packageNumberInfo = new PackageNumberInfo($packageSeriesNumberId, Product::PPL_PARCEL_CZ_PRIVATE, Depo::CODE_09); $packageNumber = Tools::generatePackageNumber($packageNumberInfo); //40950000114 /

$cityRoutingResponse = $pplMyApi->getCitiesRouting($country, null, $zipCode, $street);

//Get first routing from the response and test (response can contain more records, not 100% sure how this works...) if (is_array($cityRoutingResponse)) { $cityRoutingResponse = $cityRoutingResponse[0]; } if (!isset($cityRoutingResponse->RouteCode) || !isset($cityRoutingResponse->DepoCode) || !isset($cityRoutingResponse->Highlighted)) { throw new Exception('Štítek PPL se nepodařilo vytisknout, chybí Routing, pravděpodobně neplatná adresa!'); }

$cityRouting = new CityRouting( $cityRoutingResponse->RouteCode, $cityRoutingResponse->DepoCode, $cityRoutingResponse->Highlighted );

//Generate SmartLabel with the help of RoutedPackage

$package = new Package($packageNumber, Product::PPL_PARCEL_CZ_PRIVATE, 'Testovaci balik', $recipient, $cityRouting);

try { $pplMyApi->createPackages([$package]); } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL; }

Salamek commented 2 years ago

Um, vy asi nejste moc zbehly v PHP nebo v programovani vseobecne ze? Tak ale uceny nikdo ze stromu nespadl ze...

musite vyplnit parametry ve volani metody:

Z

$pplMyApi->getCitiesRouting($country, null, $zipCode, $street);

NA

use Salamek\PplMyApi\Enum\Country; //Pridat use na zacatek souboru pokud tam jiz neni

.....

$pplMyApi->getCitiesRouting(Country::CZ, null, '77900', 'My address');

No a jeste upravim example v README.md at je trochu vice "polopaticky"

Salamek commented 2 years ago

@KarelKopac mrknete na upraveny

https://github.com/Salamek/PplMyApi/blob/master/README.md#create-packages

je tam ukazano jak nacpat spravne parametry do Recipient a getCitiesRouting

KarelKopac commented 2 years ago

Aktualne dostavam chybu: PHP Fatal error: Class 'Salamek\PplMyApi\Model\CityRouting' not found

Na zacatku skriptu je ale uvedena

use Salamek\PplMyApi\Model\CityRouting;

a v prislusem adresari je skript CityRouting.php

Salamek commented 2 years ago

pokud pouzivate composer pro spravu zavyslosti, tak

composer dump-autoload
KarelKopac commented 2 years ago

bohzel nepouzivam

Salamek commented 2 years ago

Tak jakym zpusobem includujete potrebne soubory? Delate to manualne psanim include "cesta/k/souboru.php" nebo pouzivate nejaky autoloading? Pripadne pouzivate nejaky webovy framework? (Nette, Symphony, ...)

KarelKopac commented 2 years ago

Soubory jsou v adresari /data/www/domeny/xxx.cz/vendor/salamek/ a na zacatku testovaciho skriptu je tento radek require '/data/www/domeny/xxx.cz/vendor/autoload.php';

Salamek commented 2 years ago

No tak to pouzivate composer a jeho autoloading ve slozce xxx.cz musite spustit

composer dump-autoload

coz vygeneruje novy vendor/autoload.php

KarelKopac commented 2 years ago

Ja nema pristup na konzoli, mohu pristupovat jen na web ... takze to je asi prace pro podporu na hostingu. Je to tak?

Salamek commented 2 years ago

Jak jste tam dostal PplMyApi v prve rade? To jste spustil composer na localhostu a pak prekopiroval? nebo vam to tam nekdo nainstaloval na pozadavek?

KarelKopac commented 2 years ago

To mi tam nahral pracovnik podpory kdyz jsem je pozadal o instalaci. Ale rikal mi, ze cokoliv dalsiho si tam mohu nahrat sam, ze na to neni zapotrebi jejich asistence ...

KarelKopac commented 2 years ago

... ze composer jen stahne a nakopiruje soubory na potrebna mista

Salamek commented 2 years ago

Aha no tak si nainstalujte na svou workstation composer, z webu stahnete composer.json (mel by byt na stejne urovni jako slozka vendor) do nove slozky a v te slozce spuste prikaz composer install ktery nainstaluje zavyslosti uvedene v composer.json. (Composer je skvely nastroj pro spravu PHP zavyslosti a jdou nim instalovat snad vsechny PHP knihovny, je to vlastne stejne jako sprava balicku na linuxovych distribucich).

to by v te slozce melo vytvorit novou slozku vendor starou slozku vendor na webu smazte a nahradte ji nove vytvorenou, to vse za predpokladu ze jste nedelal zadne zmeny kodu ve stare slozce.

Salamek commented 2 years ago

Composer je soucasti repozitaru vetsiny linuxovych dister, takze vetsinou staci spustit apt update && apt install composer pro debian based distra.

Pokud pouzivate Windows na vyvoj tak tam vam nepomuzu a musite trochu googlit.

KarelKopac commented 2 years ago

Ted uz tomu rozumim. Pozadam podporu o spusteni composer dump-autoload. Az budu mit trochu casu tak si rozchodim nejaky linux.

KarelKopac commented 2 years ago

Po provedeni composer dump-autoload se mi pravdepodobne podarilo odeslat data. Pockam jeste na overeni od podpory PPL.

KarelKopac commented 2 years ago

Pokousim se zjistit jestli se data prenesla ... tohle by to asi melo dokazat overit:

$result = $pplMyApi->getPackages($customRefs = null, \DateTimeInterface $dateFrom = null, \DateTimeInterface $dateTo = null, array $packageNumbers = []);

Jakym zpusobem se zadava $dateFrom?

Salamek commented 2 years ago

$dateFrom a $dateTo pozaduji tridu implementujci \DateTimeInterface, coz defaultne znamena \DateTime, takze:

$dateFrom = new \DateTime('2022-01-01');

$dateTo = new \DateTime(); // NOW

$result = $pplMyApi->getPackages(null, $dateFrom, $dateTo);

print_r($result);
KarelKopac commented 2 years ago

Dekuji. Balik vidim ve vypisu :-)

KarelKopac commented 2 years ago

PPL mi potvrdilo preneseni dat. Jeste mam dva dotazy:

1) jak predam data od dobirky

2) jak z vypisu

$result = $pplMyApi->getPackages($customRefs, $dateFrom, $dateTo, $packageNumbers );

ktery mi vrati pri

print_r($result)

stdClass Object

  | (   | [AccessPointType] => None   | [BackDate] =>   | [BackPackNumber] =>   | [BackPackNumberActive] =>   | [BackedDoc] =>   | [DelivDate] =>   | [DelivPerson] =>   | [DeliveryToKtm] =>   | [DepInCode] => 04   | [DepInName] => Depo Teplice   | [DepOutCode] => 05   | [DepOutName] => Depo Hradec Králové   | [DepoCode] =>   | [HubDate] =>   | [LoadDate] =>   | [NotDelivDate] =>   | [Note] => Testovaci balik   | [OutDepDate] =>   | [PackNumber] => 40452655740   | [PackProductType] => 13   | [PackageSet] => stdClass Object   | (   | [MasterPackNumber] =>   | [PackageInSetNr] => 1   | [PackagesInSet] => 1   | )   |     | [PackageStatuses] => stdClass Object   | (   | [MyApiPackageOutStatus] => stdClass Object   | (   | [DelivPerson] =>   | [Note] =>   | [Note2] =>   | [StaID] => 900   | [StatusDate] => 2022-02-20T18:06:15   | [StatusName] => Čekáme na přijetí zásilky do přepravy.   | )   |     | )   |     | [PackagesExtNums] => stdClass Object   | (   | )   |     | [PackagesServices] => stdClass Object   | (   | [MyApiPackageOutService] => Array   | (   | [0] => stdClass Object   | (   | [Price] =>   | [PriceCurrency] =>   | [SvcCode] => B2OC   | )   |     | [1] => stdClass Object   | (   | [Price] =>   | [PriceCurrency] =>   | [SvcCode] => TOLL   | )   |     | [2] => stdClass Object   | (   | [Price] =>   | [PriceCurrency] =>   | [SvcCode] => FUEL   | )   |     | )   |     | )   |     | [PalletInfo] => stdClass Object   | (   | [Collies] => stdClass Object   | (   | )   |     | [ManipulationType] =>   | [PEURCount] =>   | [PackDesc] =>   | [PickupCargoTypeCode] =>   | [Volume] =>   | )   |     | [PaymentInfo] => stdClass Object   | (   | [BankAccount] =>   | [BankCode] =>   | [CanPayByCard] =>   | [CodBankStatementDate] =>   | [CodCurrency] =>   | [CodPaidDate] =>   | [CodPaymentAccDate] =>   | [CodPrice] =>   | [CodVarSym] =>   | [IBAN] =>   | [InvDate] =>   | [InvNumber] =>   | [PaidByCard] =>   | [SpecSymbol] =>   | [Swift] =>   | )   |     | [Recipient] => stdClass Object   | (   | [City] => Vysoké Mýto   | [Contact] => https://www.nejakyweb.cz   | [Country] => CZ   | [Email] => kopacek@nejakyweb.cz   | [Name] => Karel Kopáček   | [Name2] => Nějaká firma   | [Phone] => +420603434434   | [Street] => Rokycanova 155/III   | [ZipCode] => 56601   | )   |     | [Sender] => stdClass Object   | (   | [City] => Krupka - Nové Modlany   | [Contact] =>   | [Country] => CZ   | [Email] =>   | [Name] => MyAPI Test Customer   | [Name2] => PPL 04   | [Phone] =>   | [Street] => Kateřinská 95   | [ZipCode] => 41742   | )   |     | [SpecDelivery] => stdClass Object   | (   | [ParcelShopCode] =>   | [SpecDelivDate] =>   | [SpecDelivTimeFrom] => 2022-02-22T00:00:00   | [SpecDelivTimeTo] => 2022-02-22T00:00:00   | [SpecTakeDate] =>   | [SpecTakeTimeFrom] => 2022-02-22T00:00:00   | [SpecTakeTimeTo] => 2022-02-22T00:00:00   | )   |     | [TakeDate] =>   | [Weight] =>   | [WeightVol] =>   | [WeightedDate] =>   | [Flags] => stdClass Object   | (   | [MyApiFlag] => stdClass Object   | (   | [Code] => SD   | [Value] =>   | )   |     | )   |     | )

nactu hodnoty, napriklad [StatusName]?

Klasicke prochazeni polem

foreach ($result as $key => $val) { echo "$key = $val";}

vypise jako posledni prvek [PackProductType] => 13

Omlouvam se za, pro opravdoveho programatora, hloupy dotaz ...

Salamek commented 2 years ago
  1. jak predam data od dobirky

Co tim presne myslite? jak vystavit balik s dobirkou?

  1. nactu hodnoty, napriklad [StatusName]?

V dumpu jde videt ze vracena hodnota neni array ale stdClass

Takze prochazeni polozek se dela standartne volanim promenych tridy viz:


echo $result ->PackageStatuses->MyApiPackageOutStatus->StatusName; //Nejsem si jisty jestli je zanoreni korektni, nejde poznat struktura z dumpu co jste postnul...
KarelKopac commented 2 years ago

Dekuji za napovedu. Mam vraceny aktualni status.

Ano, jak vystavit balik s dobirkou.

Salamek commented 2 years ago

Musite jako 9 parametr v constructoru Package vyplnit tridu implementujci IPaymentInfo defaultne poskytnuta je PaymentInfo

use Salamek\PplMyApi\Model\Package;
use Salamek\PplMyApi\Model\PaymentInfo;
use Salamek\PplMyApi\Enum\Currency;

$cashOnDeliveryPrice = 100;
$cashOnDeliveryCurrency = Currency::CZK;
$cashOnDeliveryVariableSymbol = 1234567;
$paymentInfo = new PaymentInfo($cashOnDeliveryPrice, $cashOnDeliveryCurrency, $cashOnDeliveryVariableSymbol);

$package = new Package(..., $paymentInfo, ...);
// Zbytek znate
KarelKopac commented 2 years ago

Tak jeste jeden zadrhel ...

$package = new Package($packageNumber, Product::PPL_PARCEL_CZ_PRIVATE, 'testovaci dobírka', $recipient, $cityRouting,'','','',$paymentInfo); //9 parametr

vraci chybu

PHP Catchable fatal error: Argument 8 passed to Salamek\PplMyApi\Model\Package::__construct() must be an instance of Salamek\PplMyApi\Model\ISpecialDelivery, string given, called in /data/www/domeny/xxx.cz/www/adresar/ppl-send-2022.php on line 185 and defined in /data/www/domeny/xxx.cz/vendor/salamek/ppl-my-api/src/Model/Package.php on line 94

Salamek commented 2 years ago

V PHP se jako prazny parametr pouziva null ne prazdny string ''