/** * Create asn request * * @return void */ public function doActionCreateAsn() { $api = new \XLite\Module\XC\PitneyBowes\Model\Shipping\PitneyBowesApiFacade(\XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::getProcessorConfiguration()); if ($this->getParcel()) { $inputData = array('pbParcel' => $this->getParcel(), 'request' => \XLite\Core\Request::getInstance()); $inboundParcelResult = $api->createInboundParcelsRequest($inputData); if ($inboundParcelResult) { \XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::logDebug($inboundParcelResult); foreach ($inboundParcelResult as $inboundParcel) { $existedTrackingNumber = \XLite\Core\Database::getRepo('XLite\\Model\\OrderTrackingNumber')->findOneBy(array('value' => $inboundParcel->parcelIdentifier, 'order' => $this->getOrder())); if (!$existedTrackingNumber) { $trackingNumber = new \XLite\Model\OrderTrackingNumber(); $trackingNumber->setOrder($this->getOrder()); $trackingNumber->setValue($inboundParcel->parcelIdentifier); $this->getOrder()->addTrackingNumbers($trackingNumber); \XLite\Core\Database::getEM()->persist($this->getOrder()); \XLite\Core\Database::getEM()->flush($this->getOrder()); } } $this->getParcel()->setCreateAsnCalled(true); \XLite\Core\Database::getEM()->persist($this->getParcel()); \XLite\Core\Database::getEM()->flush($this->getParcel()); } else { \XLite\Core\TopMessage::addWarning('Create ASN action failed, try again later'); } } $this->setSilenceClose(true); }
/** * Perform actual mapping * * @return mixed */ protected function performMap() { $dstAddress = \XLite\Model\Shipping::getInstance()->getDestinationAddress($this->inputData); if (!Processor\PitneyBowes::isCountryApplicable($dstAddress['country'])) { \XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::logDebug($dstAddress['country'] . ' is not an applicable country'); return null; } $basket = new API\DataTypes\Basket(); $basket->merchantId = $this->config->merchant_code; $basket->basketCurrency = $this->inputData->getOrder()->getCurrency()->getCode(); $basket->quoteCurrency = $this->inputData->getOrder()->getCurrency()->getCode(); $consignee = $this->getConsignee(); if (null !== $consignee) { $basket->consignee = $consignee; } else { unset($basket->consignee); } $basket->shippingAddress = $this->getShippingAdress(); foreach ($this->inputData->getItems() as $orderItem) { $basket->basketLines[] = $this->getBasketLine($orderItem); } $basket->toHubTransportations[] = $this->getToHubTransportation(); $basket->parcels = $this->getParcels(); return $basket; }
/** * Get return details address * * N.B. Currently returns current logged admin contact information * * @return array */ protected function getReturnContactInformation() { $profile = \XLite\Core\Auth::getInstance()->getProfile(); $address = $profile->getBillingAddress() ?: $profile->getShippingAddress(); if (!$address || !$address->getLastname()) { \XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::logDebug('Cannot call createASN without vendor\'s address specified'); return null; } return array('familyName' => $address->getLastname(), 'givenName' => $address->getFirstname(), 'email' => $profile->getLogin(), 'phoneNumbers' => array(array('number' => $address->getPhone(), 'type' => 'other'))); }
protected function processExportResponses($files, $sftp) { // get export responses $exports = \XLite\Core\Database::getRepo('XLite\\Module\\XC\\PitneyBowes\\Model\\PBExport')->findBy(array('status' => PitneyBowes\Model\PBExport::STATUS_PENDING)); foreach ($files as $filename => $info) { \XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::logDebug('Notification file ' . $filename); foreach ($exports as $export) { if (pathinfo($export->getFilename(), \PATHINFO_FILENAME) == pathinfo($filename, \PATHINFO_FILENAME)) { switch (pathinfo($filename, \PATHINFO_EXTENSION)) { case 'ok': $export->setStatus(PitneyBowes\Model\PBExport::STATUS_APPROVED); \XLite\Logger::logCustom("PitneyBowes", 'Approved catalog export (file: ' . $filename . ')', false); break; case 'err': $export->setStatus(PitneyBowes\Model\PBExport::STATUS_FAILED); $export->setErrors($sftp->get($filename)); \XLite\Logger::logCustom("PitneyBowes", 'Failed to approve catalog export (file: ' . $filename . ')', false); break; default: break; } $sftp->delete($filename); break; } } } }
/** * https://wiki.ecommerce.pb.com/display/TECH4/Create+Inbound+Parcels * * @param array $inputData * * @return mixed */ public function createInboundParcelsRequest(array $inputData) { if (!isset($inputData['pbParcel'])) { return null; } $url = static::getApiURL($this->config, 'asn_endpoint') . '/orders/' . $inputData['pbParcel']->getOrder()->getOrmus() . '/inbound-parcels'; $request = new API\Request\CreateInboundParcelsRequest($url, $inputData); $inputMapper = new Mapper\CreateInboundParcels\InputMapper($this->config); $request->setInputMapper($inputMapper); $request->setOutputMapper(new Mapper\CreateInboundParcels\OutputMapper($this->config)); $auth = $this->getAuth(); $request->setAuth($auth['type'], $auth['value']); $request->sendRequest(); \XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::logDebug('createInboundParcels API called with: ' . PHP_EOL . 'URL: ' . $url . PHP_EOL . 'Request: ' . $request->getRawRequest() . PHP_EOL . 'Response: ' . $request->getRawResponse() . PHP_EOL); return $request->getResponse(); }