Skip to content

Commit

Permalink
new documents added
Browse files Browse the repository at this point in the history
  • Loading branch information
aahmetgaliev committed Sep 6, 2019
1 parent b143e46 commit 2650da3
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 41 deletions.
84 changes: 80 additions & 4 deletions src/CorreosConnector/CorreosConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace CorreosSdk\CorreosConnector;

use CorreosSdk\ServiceType\Documentacion;
use CorreosSdk\StructType\SolicitudDocumentacionAduanera;
use CorreosSdk\StructType\SolicitudDocumentacionAduaneraCN23CP71;
use CorreosSdk\StructType\SolicitudEtiquetaExp;
use InvalidArgumentException;
use CorreosSdk\ServiceType\Anular;
use CorreosSdk\ServiceType\Modificar;
Expand Down Expand Up @@ -114,13 +118,85 @@ public function printLabel(string $trackNumber, \DateTime $shipDateRequest = nul

$response = $documentationService->SolicitudEtiquetaOp($labelData);

if($response->getResultado() == 1) {
if ($response->getResultado() == 1) {
throw new CorreosException("Shipment with track number " . $trackNumber . " not found");
}

return !empty($response->Bulto) ? $response->Bulto->Etiqueta->Etiqueta_pdf->Fichero : "";
}

/**
* @param string $trackNumber
* @param \DateTime $shipDateRequest
* @return string
* @throws CorreosException
*/
public function printExpeditionLabel(string $trackNumber, \DateTime $shipDateRequest = null): string
{
$documentationService = new Solicitud($this->correosConfig->getOptions());

$labelData = new SolicitudEtiquetaExp(
!empty($shipDateRequest) ? $shipDateRequest->format('d-m-y H:i:s') : null,
$this->correosConfig->getClientCode(),
$this->correosConfig->getClientContractNumber(),
$this->correosConfig->getClientNumber(),
$trackNumber,
$this->correosConfig->getCare(),
self::PDF_TYPE_REQUEST
);
$response = $documentationService->SolicitudEtiquetaExpOp($labelData);

return !empty($response->Bulto) ? $response->Bulto->Etiqueta->Etiqueta_pdf->Fichero : "";
}


/**
*
* @param string $type
* @param string $countryIso
* @param string $numberOfShippings
* @param string $companyName
* @param string $province
* @return string|null
*/
public function printCustomsDocument(string $type, string $countryIso, string $numberOfShippings, string $companyName, string $province = ''): ?string
{
$documentationService = new Documentacion($this->correosConfig->getOptions());

$documentData = new SolicitudDocumentacionAduanera(
$type,
$this->correosConfig->getClientContractNumber(),
$this->correosConfig->getClientNumber(),
$this->correosConfig->getClientCode(),
$province,
$countryIso,
$companyName,
$numberOfShippings
);

$response = $documentationService->DocumentacionAduaneraOp($documentData);

return !empty($response->Fichero) ? $response->Fichero : "";

}

/**
* @param $trackNumber
* @return string
*/
public function printCustomDocumentCN23CP71(string $trackNumber)
{
$documentationService = new Documentacion($this->correosConfig->getOptions());

$documentData = new SolicitudDocumentacionAduaneraCN23CP71(
$trackNumber
);

$response = $documentationService->DocumentacionAduaneraCN23CP71Op($documentData);

return !empty($response->Fichero) ? $response->Fichero : "";
}

/**
* @param string $trackNumber
* @return bool
Expand All @@ -144,15 +220,16 @@ public function cancelShipment(string $trackNumber): bool

/**
* @param Shipment $invoice
* @param string $trackNumber
* @return Shipment
* @throws CorreosException
*/
public function updateShipment(Shipment $invoice): Shipment
public function updateShipment(Shipment $invoice, string $trackNumber): Shipment
{
try {
$updateService = new Modificar($this->correosConfig->getOptions());
$updateData = new PeticionModificar(
$invoice->getClippedTrackNumber(),
$trackNumber,
$invoice->getDateRequest()->format('d-m-y H:i:s'),
$this->correosConfig->getClientCode(),
$this->correosConfig->getClientContractNumber(),
Expand All @@ -164,7 +241,6 @@ public function updateShipment(Shipment $invoice): Shipment
$invoice->getReceiverUnitedIdentity()->buildUpdateReceiverIdentity(),
$invoice->getSendingContent()->buildUpdateSendingContent()
);

$response = $updateService->ModificarOp($updateData);

$invoice->setResponse($response);
Expand Down
4 changes: 2 additions & 2 deletions src/Factories/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function setDateRequest(\DateTime $dateRequest): void
{
$preparedDateTime = $this->setZerosToSeconds($dateRequest);

$this->dateRequest = $preparedDateTime;
$this->dateRequest = $dateRequest;
}

/**
Expand All @@ -127,7 +127,7 @@ private function setZerosToSeconds(\DateTime $dateTime) : \DateTime
* For printing labels need cut last character
* @return string
*/
public function getClippedTrackNumber(): string
public function getClippedTrackNumber(): ?string
{
return substr($this->trackNumber, 0, -1);
}
Expand Down
24 changes: 23 additions & 1 deletion tests/CancelShipmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
namespace CorreosSdk\Tests;


use CorreosSdk\CorreosConnector\CorreosConfig;
use CorreosSdk\CorreosConnector\CorreosConnector;
use CorreosSdk\Exceptions\CorreosException;
use CorreosSdk\Factories\Address;
use CorreosSdk\Factories\Identification;
use CorreosSdk\Factories\SenderUnitedIdentity;
use CorreosSdk\StructType\PeticionAnular;
use Matomo\Ini\IniReader;

class CancelShipmentTest extends InitTest
{
Expand All @@ -17,7 +23,7 @@ public function testCancelShipment()
$shipment = $this->createShipment();

$trackNumber = $shipment->getClippedTrackNumber();

echo "track number =" . $trackNumber;
$isCancelShipment = $this->client->cancelShipment($trackNumber);

$this->assertTrue($isCancelShipment);
Expand All @@ -35,4 +41,20 @@ public function testFailedCancel()
$this->expectException(CorreosException::class);

}

public function testProdCancel()
{

// $shipment = $this->createShipment();

// print_r($shipment->getResponse());

// echo $trackNumber = $shipment->getClippedTrackNumber();

// $isCancelShipment = $this->client->cancelShipment("LX504912338ES");

// $this->assertTrue($isCancelShipment);

}

}
21 changes: 8 additions & 13 deletions tests/InitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,20 @@ public function __construct($name = null, array $data = array(), $dataName = '')
$config['sender_city_name'],
$config['sender_street_name'],
$config['sender_province_name'],
$config['sender_street_number']
$config['sender_street_number'],
null,
"C",
null,
null,
$config['sender_street_floor']
);
$senderIdentification = new Identification(
$config['sender_name'],
$config['sender_first_name'],
$config['sender_second_name'],
$config['sender_company_name'],
$config['sender_name']
);
$senderUnitedIdentity = new SenderUnitedIdentity(
$senderAddress,
$senderIdentification,
$config['sender_postcode'],
$config['sender_phone'],
$config['sender_email']
$config['sender_post_code']
);

$this->client = new CorreosConnector($correosConfig, $senderUnitedIdentity);
Expand All @@ -68,11 +67,7 @@ protected function createShipment() : Shipment
"20"
);
$receiverIdentity = new Identification(
"TEST TEST",
null,
null,
null,
null
"TEST TEST"
);
$receiverUnitedIdentity = new ReceiverUnitedIdentity(
$receiverAddress,
Expand Down
43 changes: 33 additions & 10 deletions tests/PrintLabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@

namespace CorreosSdk\Tests;


use CorreosSdk\CorreosConnector\CorreosConfig;
use CorreosSdk\CorreosConnector\CorreosConnector;
use CorreosSdk\Exceptions\CorreosException;
use CorreosSdk\Factories\Address;
use CorreosSdk\Factories\Identification;
use CorreosSdk\Factories\SenderUnitedIdentity;
use Matomo\Ini\IniReader;

class PrintLabelTest extends InitTest
{
Expand All @@ -28,7 +21,6 @@ public function testPrinting()

$labelPdfByteCode = $this->client->printLabel($trackNumber, null);


$this->assertTrue(strlen($labelPdfByteCode) > 3);

}
Expand All @@ -42,8 +34,6 @@ public function testfailedPrinting()

$trackNumber = $shipment->getTrackNumber();

$dateTime = $shipment->getDateRequest();

$dateTime = new \DateTime('tomorrow');

$labelPdfByteCode = $this->client->printLabel($trackNumber, $dateTime);
Expand All @@ -54,4 +44,37 @@ public function testfailedPrinting()

}

public function testPrintCustomDocument()
{

$typeDocument = "DDP"; // DCAF
$countryIso = "RU";
$numberOfShipments = "2";
$companyName = "test";

$documentCode = $this->client->printCustomsDocument($typeDocument, $countryIso, $numberOfShipments, $companyName);

$this->assertTrue(strlen($documentCode) > 3);
}

public function testCustomDocumentCN23CP71()
{
$invoice = $this->createShipment();

$trackNumber = $invoice->getClippedTrackNumber();

$documentCode = $this->client->printCustomDocumentCN23CP71($trackNumber);

$this->assertTrue(strlen($documentCode) > 3);

}

public function testExpeditionPrint()
{
$invoice = $this->createShipment();

$trackNumber = $invoice->getTrackNumber();

// $labelPdfByteCode = $this->client->printExpeditionLabel($trackNumber, $invoice->getDateRequest());
}
}
Loading

0 comments on commit 2650da3

Please sign in to comment.