/**
  * Lookup the tender type for given gift card.
  * @param string
  * @param string
  * @param bool
  * @return string
  * @throws EbayEnterprise_GiftCard_Exception_InvalidCardNumber_Exception If card number cannot be retrieved.
  */
 public function lookupTenderType($cardNumber, $currencyCode, $panIsToken = false)
 {
     try {
         $api = $this->getTenderTypeLookupApi();
         return $this->createTenderTypeLookup($cardNumber, $currencyCode, $api, $panIsToken)->getTenderType();
     } catch (EbayEnterprise_GiftCard_Exception_TenderTypeLookupFailed_Exception $e) {
         $this->logger->error('Unable to lookup tender type', $this->logContext->getMetaData(__CLASS__, [], $e));
         throw Mage::exception('EbayEnterprise_GiftCard_Exception_InvalidCardNumber', $this->helper->__(self::INVLIAD_CARD_NUMBER_MESSAGE, $cardNumber));
     }
 }
 /**
  * get the ROM identifier for the given magento shipping method code
  * return null if $shippingMethod evaluates to false
  *
  * @param string
  * @return string|null
  */
 public function getMethodSdkId($shippingMethod)
 {
     $this->fetchAvailableShippingMethods();
     if (!$shippingMethod) {
         return '';
     }
     if (!isset($this->methods[$shippingMethod]['sdk_id'])) {
         $this->logger->error('Unable to get the SDK identifier for shipping method {shipping_method}', $this->logContext->getMetaData(__CLASS__, ['shipping_method' => $shippingMethod]));
         throw Mage::exception('EbayEnterprise_Eb2cCore', 'Unable to find a valid shipping method');
     }
     return $this->methods[$shippingMethod]['sdk_id'];
 }
 /**
  * Fetches feeds from the remote, and then loops through all files found in the Inbound Dir.
  *
  * @return int Number of files we looked at.
  */
 public function processFeeds()
 {
     $filesProcessed = 0;
     foreach ($this->_getFilesToProcess() as $feedFile) {
         try {
             $this->processFile($feedFile);
             $filesProcessed++;
         } catch (Mage_Core_Exception $e) {
             $logData = ['local_file' => basename($feedFile['local_file']), 'error_message' => $e->getMessage()];
             $logMessage = 'Failed to process file, {local_file}. {error_message}';
             $this->_logger->error($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
         }
     }
     return $filesProcessed;
 }
 /**
  * fetch the tender type for the given card account
  *
  * @param string
  * @return string
  * @throws EbayEnterprise_GiftCard_Exception_TenderTypeLookupFailed_Exception
  *         if the tender type cannot be retrieved for the account
  */
 public function getTenderType()
 {
     try {
         $this->prepareApiForSend();
         $this->api->send();
         return $this->processResponse($this->api->getResponseBody());
     } catch (EbayEnterprise_GiftCard_Exception_TenderTypeLookupFailed_Exception $e) {
         $this->logger->error('The service reported the tender type lookup as unsuccessful.', $this->logContext->getMetaData(__CLASS__, [], $e));
     } catch (InvalidPayload $e) {
         $this->logger->warning('Either the request or the response for the tender type lookup contains invalid data.', $this->logContext->getMetaData(__CLASS__, [], $e));
     } catch (NetworkError $e) {
         $this->logger->warning('There was a network error when attempting to fetch the tender type', $this->logContext->getMetaData(__CLASS__, [], $e));
     } catch (UnsupportedOperation $e) {
         $this->logger->critical('The tender type lookup operation is unsupported in the current configuration.', $this->logContext->getMetaData(__CLASS__, [], $e));
     } catch (UnsupportedHttpAction $e) {
         $this->logger->critical('The tender type lookup is configured with an unsupported HTTP action', $this->logContext->getMetaData(__CLASS__, [], $e));
     }
     // we only care if we were able to get the tender type or not, so
     // boil all errors down to a single exception
     throw $this->createUnsuccessfulOperationException();
 }
 /**
  * Saving shipment and order in one transaction.
  * @param  Mage_Sales_Model_Order_Shipment $shipment
  * @param  string $incrementId
  * @return self
  */
 protected function _saveShipment(Mage_Sales_Model_Order_Shipment $shipment, $incrementId)
 {
     $order = $shipment->getOrder();
     $order->setIsInProcess(true);
     $transactionSave = Mage::getModel('core/resource_transaction')->addObject($shipment)->addObject($order);
     try {
         $transactionSave->save();
     } catch (Exception $e) {
         $logData = ['increment_id' => $incrementId];
         $logMessage = 'An error occurred saving shipment confirmation to order id ({increment_id}). See exception log for details.';
         $this->_logger->error($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
         $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
     }
     return $this;
 }
 /**
  * given a sourceFile and a self::_configMap give move the file
  * to any destination the key is map to after successful file move
  * try removing the source file
  * @param string
  * @param string
  * @return self
  */
 protected function _mvTo($sourceFile, $cfgKey)
 {
     $destination = $this->_buildPath($cfgKey) . DS . basename($sourceFile);
     $isDeletable = true;
     try {
         $this->_coreHelper->moveFile($sourceFile, $destination);
     } catch (EbayEnterprise_Catalog_Exception_Feed_File $e) {
         $isDeletable = false;
         $this->_logger->error($e->getMessage(), $this->_context->getMetaData(__CLASS__, [], $e));
     }
     if ($isDeletable) {
         try {
             $this->_coreHelper->removeFile($sourceFile);
         } catch (EbayEnterprise_Catalog_Exception_Feed_File $e) {
             $this->_logger->error($e->getMessage(), $this->_context->getMetaData(__CLASS__, [], $e));
         }
     }
     return $this;
 }
 /**
  * fill out the request payload to send
  *
  * @param IBidirectionalApi
  * @param EbayEnterprise_Inventory_Model_Allocation_Item_Selector
  * @return self
  */
 protected function prepareRequest(IBidirectionalApi $api, EbayEnterprise_Inventory_Model_Allocation_Item_Selector $selector)
 {
     $this->logger->debug('Building inventory allocation request reservation id {reservation_id}', $this->logContext->getMetaData(__CLASS__, ['reservation_id' => $this->reservation->getId()]));
     try {
         $request = $api->getRequestBody();
         $builder = $this->createRequestBuilder($request, $selector, $this->reservation);
         $builder->buildOutRequest();
         // rule out the possibility of exceptions from the request
         // being thrown during the send.
         $request->serialize();
         $api->setRequestBody($request);
         return $request;
     } catch (UnsupportedOperation $e) {
         $this->logger->critical('The allocation operation is unsupported by the currently configured SDK', $this->logContext->getMetaData(__CLASS__, [], $e));
     } catch (InvalidPayload $e) {
         $this->logger->error('The allocation request is invalid', $this->logContext->getMetaData(__CLASS__, [], $e));
     }
     $this->handleAllocationFailure();
 }