service = ServiceContainer::getService(CeskaPosta::class);
$this->service->configure('363134001', 'M51535', '40003', '1');
// $this->doSendParcels = true;
}
public function testCeskaPostaGetStats()
{
$dateEnd = date('Y-m-d\T23:59:59.000P');
$dateBegin = date('Y-m-d\T00:00:00.000P', strtotime('-1 week'));
$request = '
1
'.date('Y-m-d\TH:i:s.vP').'
363134001
'.$dateBegin.'
'.$dateEnd.'
';
$this->service->request_url = 'https://b2b.postaonline.cz/services/POLService/v1/getStats';
$this->service->sendToCeskaPosta($request, $this->service->request_url);
$this->assertEquals('', $this->service->error);
$this->assertContains('', $this->service->response);
$this->assertContains('', $this->service->response);
}
public function testCeskaPostaSendParcels()
{
$orderID = 34340; // EU - FI; RR
$order = new \Order();
if ($this->doSendParcels && $order->createFromDB($orderID)) {
$b2bRequest = $this->prepareCeskaPostaRequest($order, $this->service);
$idTransaction = $this->service->sendParcels($b2bRequest);
$this->assertEquals('', $this->service->error);
$this->assertNotFalse($idTransaction);
$parcelCode = $this->service->getResultParcels($idTransaction);
$this->assertEquals('', $this->service->error);
$this->assertNotFalse($parcelCode);
$idForm = $this->getParcelType($parcelCode);
$this->assertEquals('39', $idForm); // 39 - RR
$pdf = $this->service->getParcelsPrinting($parcelCode, $idForm);
$this->assertEquals('', $this->service->error);
$this->assertNotFalse($pdf);
}
}
public function testCeskaPostaGetResultParcels()
{
$idTransaction = '5650B272-0161-4000-E000-33BC0AA06329';
$parcelCode = $this->service->getResultParcels($idTransaction);
$this->assertEquals('', $this->service->error);
$this->assertNotFalse($parcelCode);
$this->assertEquals('CV200180271CZ', $parcelCode);
}
public function testCeskaPostaGetParcelsPrinting()
{
$parcelCode = 'CV200180271CZ';
$idForm = $this->getParcelType($parcelCode);
$this->assertEquals('61', $idForm); // 61 - CV
$pdf = $this->service->getParcelsPrinting($parcelCode, $idForm);
$this->assertEquals('', $this->service->error);
$this->assertNotFalse($pdf);
}
public function prepareCeskaPostaRequest($order, $service_CeskaPosta)
{
$b2bRequest = $service_CeskaPosta->get_b2bRequest($order, 'sendParcels');
$ns2 = $service_CeskaPosta->ns2;
$serviceData = $b2bRequest->serviceData;
$doParcelData = $serviceData->children('ns2', true)->sendParcels->doParcelData;
$doParcelParams = $serviceData->children('ns2', true)->sendParcels->doParcelData->doParcelParams;
$country = !empty($order->delivery_country) ? $order->delivery_country : $order->invoice_country;
$delivery_type = $order->getDeliveryType();
$delivery = $delivery_type->getDelivery();
// 9 - Small package by AIR mail - check
// 10 - Czech Post - regional delivery
if (($delivery->id == 9) || ($delivery->id == 10)) {
$doParcelParams->addChild('ns2:prefixParcelCode', 'RR', $ns2);
if ($country == 'CZ') {
// service 50: Doporučená psaní
$doParcelData->addChild('ns2:doParcelServices', null, $ns2)->addChild('ns2:service', '50', $ns2);
} else {
// service 53: Doporučená zásilka do zahraničí
$doParcelData->addChild('ns2:doParcelServices', null, $ns2)->addChild('ns2:service', '53', $ns2);
}
} else {
$prefixParcelCode = 'CS';
if (findModule(Modules::DELIVERY_PRICELIST)) {
if (isset($delivery->id_pricelist)) {
$priceList = ServiceContainer::getService(\KupShop\DeliveryPriceListBundle\DeliveryPriceCalculator::class);
$priceList->setPricelistId($delivery->id_pricelist);
$priceList->setCountry($country);
if ($priceList->hasCountryInsurance($country)) {
$prefixParcelCode = 'CV';
// insuredValue = udaná cena
$doParcelParams->addChild('ns2:insuredValue', $order->total_price, $ns2);
}
}
}
$doParcelParams->addChild('ns2:prefixParcelCode', $prefixParcelCode, $ns2);
if ($delivery->id == 1) {
// 1 - Czech Post - priority (AIR)
// service 9: Prioritně
$doParcelData->addChild('ns2:doParcelServices', null, $ns2)->addChild('ns2:service', '9', $ns2);
}
// service 4C: Nevracet (Dispozice pro nakládání se zásilkou)
$doParcelData->addChild('ns2:doParcelServices', null, $ns2)->addChild('ns2:service', '4C', $ns2);
}
$cd = (strpos($order->flags, 'CD') !== false);
$mrn = $order->getData('mrn');
if ($mrn) {
$doParcelParams->addChild('ns2:mrn', $mrn, $ns2);
}
if ($cd) {
// service 44: MZ – Zboží s VDD (vývozní doprovodný doklad – pro uplatnění odpočtu DPH)
// služba 44, zboží pro všechny zásilky s VDD (s celními doklady, MRN)
$doParcelData->addChild('ns2:doParcelServices', null, $ns2)->addChild('ns2:service', '44', $ns2);
$doParcelCustomsDeclaration = $doParcelData->addChild('ns2:doParcelCustomsDeclaration', null, $ns2);
// Kategorie zásilky: jiné
$doParcelCustomsDeclaration->addChild('ns2:category', '991', $ns2);
// Měna celní hodnoty: CZK
$doParcelCustomsDeclaration->addChild('ns2:customValCur', 'CZK', $ns2);
$doParcelCustomsGoods = $doParcelCustomsDeclaration->addChild('ns2:doParcelCustomsGoods', null, $ns2);
$doParcelCustomsGoods->addChild('ns2:sequence', '1', $ns2);
// Popis zboží
$doParcelCustomsGoods->addChild('ns2:customCont', 'spare parts / náhradní díly', $ns2);
$doParcelCustomsGoods->addChild('ns2:quantity', '1', $ns2);
$doParcelCustomsGoods->addChild('ns2:weight', $order->getTotalWeight(), $ns2);
// Celní hodnota
$doParcelCustomsGoods->addChild('ns2:customVal', $order->total_price, $ns2);
// HS kód ?
$doParcelCustomsGoods->addChild('ns2:hsCode', '1', $ns2);
// Země původu zboží
$doParcelCustomsGoods->addChild('ns2:iso', 'CZ', $ns2);
} else {
if ($country != 'CZ') {
// service 43: MZ – Zboží/Dárek/Ostatní ( pro mezinárodní zásilky) Odpovědní obálka (pro zásilky DR, DV, DE, NP, NV, NA, BN a BE)
// služba 43, zboží pro všechny zásilky bez VDD (bez celních dokladú, MRN)
$doParcelData->addChild('ns2:doParcelServices', null, $ns2)->addChild('ns2:service', '43', $ns2);
}
}
return $b2bRequest;
}
private function getParcelType($parcelCode)
{
$idForm = '39'; // ? adresní štítek bianco - samostatný (na šířku)
$parcelType = strtoupper(substr($parcelCode, 0, 2));
switch ($parcelType) {
case 'CV':
$idForm = '61';
break;
case 'CS':
$idForm = '58';
break;
case 'RR':
$idForm = '39';
break;
}
return $idForm;
}
public function getDataSet()
{
return $this->getJsonDataSetFromFile();
}
}