/** * 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); }
/** * Get filename * * @return string */ protected function getFilename() { if (empty($this->generator->getOptions()->categories_filename)) { $config = \XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::getProcessorConfiguration(); $parts = array('Sender_ID' => $config->sender_id, 'Data_Feed_Name' => 'category-tree', 'Operation' => 'update', 'Recipient_ID' => '16061', 'UTC_Date_Time' => \XLite\Core\Converter::formatTime(null, '%Y%m%d_%H%M%S'), 'Random_6_Digits' => str_pad(rand(0, pow(10, 6)), 6, '0', STR_PAD_LEFT)); $this->generator->getOptions()->categories_filename = implode('_', $parts) . '.csv'; } return $this->generator->getOptions()->categories_filename; }
/** * @return void */ protected function confirmOrderApiCall() { $api = new Shipping\PitneyBowesApiFacade(\XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::getProcessorConfiguration()); $confirmOrderResult = $api->confirmOrder($this->getPbOrder()); if ($confirmOrderResult) { $this->confirmOrderHistoryEvent($this->getPbOrder(), $confirmOrderResult); } $this->setShippingStatus(\XLite\Model\Order\Status\Shipping::STATUS_PROCESSING); }
protected function getImportationPart() { $order = $this->getOrderBySurcharge(); $value = Processor\PitneyBowes::getImportationPart($order->getSubtotal(), $order->getProfile()->getShippingAddress()->getCountry()->getCode(), $order->getPbOrder()->getCreateOrderResponse()->order); return static::formatPrice($value, $order->getCurrency(), true); }
/** * Upload to PB SFTP Server, called from completed.tpl * * @return boolean */ public function uploadToPB() { $result = false; $generator = $this->getGenerator(); if ($generator) { $config = \XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::getProcessorConfiguration(); $processor = new PitneyBowes\Logic\FileExchange\Processor($config); $result = $processor->submitCatalog($generator->getCatalogFiles(), $generator->getOptions()->differential); if ($result) { \XLite\Core\TmpVars::getInstance()->{\XLite\Module\XC\PitneyBowes\Core\Task\PitneyBowesCatalog::CELL_DIFF_EXTRACTION} = LC_START_TIME; if (!$generator->getOptions()->differential) { \XLite\Core\TmpVars::getInstance()->{\XLite\Module\XC\PitneyBowes\Core\Task\PitneyBowesCatalog::CELL_FULL_EXTRACTION} = LC_START_TIME; } } } return $result; }
/** * toHubTransportation part of basket * * @return array */ protected function getToHubTransportation() { $handlingFee = Processor\PitneyBowes::getHandlingFeeMarkup(count($this->inputData)); $shippingFee = Processor\PitneyBowes::getShippingFeeMarkup(count($this->inputData)); return array('merchantShippingIdentifier' => 'STANDARD', 'speed' => 'STANDARD', 'shipping' => array('value' => $handlingFee), 'handling' => array('value' => $shippingFee), 'total' => array('value' => $shippingFee + $handlingFee), 'minDays' => intval($this->config->min_delivery_adjustment), 'maxDays' => intval($this->config->max_delivery_adjustment)); }
/** * 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'))); }
/** * * @param mixed $quote Single quote line * * @return float */ protected function getMarkupRate($quote) { $handlingFee = Processor\PitneyBowes::getHandlingFeeMarkup(count($quote->quoteLines)); $shippingFee = Processor\PitneyBowes::getShippingFeeMarkup(count($quote->quoteLines)); return $handlingFee + $shippingFee; }
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; } } } }
/** * Returns configuration * * @return \XLite\Core\ConfigCell */ protected function getConfiguration() { return \XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::getProcessorConfiguration(); }
/** * 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(); }
/** * Check product visibility * * @return boolean */ public function isVisible() { return parent::isVisible() && !(\XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::getProcessorConfiguration()->restricted_products === 'hide' && $this->isRestrictedProduct()); }
/** * Checks if first time configuration window should be displayed * * @return boolean */ public function isCredentialsRequested() { \XLite\Core\Config::updateInstance(); return (bool) \XLite\Module\XC\PitneyBowes\Model\Shipping\Processor\PitneyBowes::getProcessorConfiguration()->credentials_requested; }