Пример #1
0
 /**
  * Get filename for PDF documents
  *
  * @return string
  */
 public function getFileName()
 {
     return 'm_' . $this->getManifest()->getManifestId() . '_' . parent::getFileName();
 }
Пример #2
0
 /**
  * Call Get Artifact request
  *
  * Reason to Call:
  * To retrieve a shipping label, a return label, or the paperwork required for shipment pickup or drop-off (manifest).
  *
  * More info at:
  * https://www.canadapost.ca/cpo/mc/business/productsservices/developers/services/shippingmanifest/shipmentartifact.jsf
  *
  * @param \XLite\Module\XC\CanadaPost\Model\Base\Link $link Shipment's link object
  *
  * @return \XLite\Core\CommonCell
  */
 public function callGetArtifactRequest(\XLite\Module\XC\CanadaPost\Model\Base\Link $link)
 {
     $apiHost = $link->getHref();
     $result = new \XLite\Core\CommonCell();
     try {
         $request = new \XLite\Core\HTTP\Request($apiHost);
         $request->requestTimeout = $this->requestTimeout;
         $request->verb = 'GET';
         $request->setHeader('Authorization', 'Basic ' . base64_encode(static::getCanadaPostConfig()->user . ':' . static::getCanadaPostConfig()->password));
         $request->setHeader('Accept', 'application/pdf');
         $request->setHeader('Accept-language', static::ACCEPT_LANGUAGE_EN);
         if (static::isOnBehalfOfAMerchant()) {
             $request->setHeader('Platform-id', $this->getPlatformId());
         }
         $response = $request->sendRequest();
         if (isset($response) && $response->code == 200 && strpos($response->headers->ContentType, 'application/pdf') !== false) {
             // Save valid PDF file to a temporary file
             $filePath = LC_DIR_TMP . $link->getFileName();
             if (\Includes\Utils\FileManager::write($filePath, $response->body)) {
                 $result->filePath = $filePath;
             }
         } else {
             if (!empty($response->body) && strpos($response->headers->ContentType, 'xml') > -1) {
                 // Parse errors
                 $result = $this->parseResponse($response->body);
             } else {
                 if (isset($response) && $response->code == 202) {
                     $result->errors = array('GAR_202' => 'The requested resource is not yet available. Please try again later.');
                 } else {
                     // Other errors
                     $result->errors = array('GAR_01' => sprintf('Error while connecting to the Canada Post host (%s) during Get Artifact request', $apiHost));
                 }
             }
         }
     } catch (\Exception $e) {
         if (!isset($result->errors)) {
             $result->errors = array();
         }
         $result->errors += array($e->getCode(), $e->getMessage());
     }
     return $result;
 }
Пример #3
0
 /**
  * Constructor
  *
  * @param array $data Entity properties (OPTIONAL)
  *
  * @return void
  */
 public function __construct(array $data = array())
 {
     $this->shipments = new \Doctrine\Common\Collections\ArrayCollection();
     $this->links = new \Doctrine\Common\Collections\ArrayCollection();
     parent::__construct($data);
 }
Пример #4
0
 /**
  * Get filename for PDF documents
  *
  * @return string
  */
 public function getFileName()
 {
     return 's_' . $this->getShipment()->getShipmentId() . '_' . parent::getFileName();
 }