/**
  * 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()
 {
     $logger = $this->logger;
     $logContext = $this->logContext;
     try {
         $this->prepareApiForSend();
         $this->api->send();
         return $this->processResponse($this->api->getResponseBody());
     } catch (EbayEnterprise_GiftCard_Exception_TenderTypeLookupFailed_Exception $e) {
         $logger->error('The service reported the tender type lookup as unsuccessful. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     } catch (InvalidPayload $e) {
         $logger->warning('Invalid payload for tender type lookup. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     } catch (NetworkError $e) {
         $logger->warning('Caught a network error sending the tender type lookup. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     } catch (UnsupportedOperation $e) {
         $logger->critical('The tender type lookup operation is unsupported in the current configuration. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     } catch (UnsupportedHttpAction $e) {
         $logger->critical('The tender type lookup is configured with an unsupported HTTP action. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $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();
 }
 /**
  * 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();
 }
 /**
  * Send the request via the sdk
  *
  * @param  IBidirectionalApi
  * @return Payload
  *
  * @throws EbayEnterprise_PayPal_Exception
  * @throws UnsupportedOperation
  * @throws UnsupportedHttpAction
  * @throws Exception
  */
 protected function sendRequest(IBidirectionalApi $sdk)
 {
     $logger = $this->logger;
     $logContext = $this->logContext;
     try {
         $sdk->send();
         $reply = $sdk->getResponseBody();
         return $reply;
     } catch (InvalidPayload $e) {
         $logMessage = 'Invalid payload for PayPal request. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     } catch (NetworkError $e) {
         $logMessage = 'Caught network error sending the PayPal request. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     } catch (UnsupportedOperation $e) {
         $logMessage = 'The PayPal operation is unsupported in the current configuration. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     } catch (UnsupportedHttpAction $e) {
         $logMessage = 'The PayPal operation is configured with an unsupported HTTP action. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     } catch (Exception $e) {
         $logMessage = 'Encountered unexpected exception from PayPal operation. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     }
     $e = Mage::exception('EbayEnterprise_PayPal', $this->helper->__(static::EBAYENTERPRISE_PAYPAL_API_FAILED));
     $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     throw $e;
 }
 /**
  * Make the API request, handling exceptions if they arise.
  *
  * @param IBidirectionalApi
  * @return self
  * @throws EbayEnterprise_Inventory_Exception_Allocation_Failure_Exception If request fails.
  */
 protected function makeRequest(IBidirectionalApi $api)
 {
     $logger = $this->logger;
     $logContext = $this->logContext;
     try {
         $api->send();
         return $this;
     } catch (InvalidPayload $e) {
         $logger->warning('Invalid payload for inventory allocation. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     } catch (NetworkError $e) {
         $logger->warning('Caught a network error sending the inventory allocation request. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     } catch (UnsupportedOperation $e) {
         $logger->critical('The inventory allocation operation is unsupported in the current configuration. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     } catch (UnsupportedHttpAction $e) {
         $logger->critical('The inventory allocation operation is configured with an unsupported HTTP action. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
     }
     $this->handleAllocationFailure();
 }
 /**
  * Send the request via the sdk
  *
  * @param  IBidirectionalApi
  * @return Payload
  *
  * @throws EbayEnterprise_PayPal_Exception
  * @throws EbayEnterprise_PayPal_Exception_Network
  */
 protected function sendRequest(IBidirectionalApi $sdk)
 {
     try {
         $sdk->send();
         $reply = $sdk->getResponseBody();
         return $reply;
     } catch (InvalidPayload $e) {
         $logMessage = 'PayPal payload invalid. See exception log for details.';
         $this->logger->warning($logMessage, $this->logContext->getMetaData(__CLASS__));
         $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e));
     } catch (NetworkError $e) {
         $logMessage = 'PayPal request encountered a network error. See exception log for details.';
         $this->logger->warning($logMessage, $this->logContext->getMetaData(__CLASS__));
         $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e));
     }
     $e = Mage::exception('EbayEnterprise_PayPal', $this->helper->__(static::EBAYENTERPRISE_PAYPAL_API_FAILED));
     $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e));
     throw $e;
 }
 /**
  * Make the API request and handle any exceptions.
  * @param ApiIBidirectionalApi $api
  * @return self
  */
 protected function _sendAuthRequest(Api\IBidirectionalApi $api)
 {
     try {
         $api->send();
     } catch (Payload\Exception\InvalidPayload $e) {
         // Invalid payloads cannot be valid - log the error and fail the auth
         $logData = ['error_message' => $e->getMessage()];
         $logMessage = 'Credit card auth payload invalid: {error_message}';
         $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
         $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         $this->_failPaymentAuth(self::CREDITCARD_AUTH_FAILED_MESSAGE);
     } catch (Api\Exception\NetworkError $e) {
         // Can't accept an auth request that could not be made successfully - log
         // the error and fail the auth.
         $logData = ['error_message' => $e->getMessage()];
         $logMessage = 'Credit card auth request failed: {error_message}';
         $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData));
         $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         $this->_failPaymentAuth(self::CREDITCARD_AUTH_FAILED_MESSAGE);
     }
     return $this;
 }
 /**
  * Send the request for the TDF service and handle any responses or exceptions.
  *
  * @param IBidirectionalApi
  * @return self
  */
 protected function _sendApiRequest(IBidirectionalApi $api)
 {
     try {
         $api->send();
         // Generally, these catch statements will all add a log message for the
         // exception and throw a more generic exception that can be handled
         // (by Magento or the Inventory module) in such a way as to not block checkout.
     } catch (NetworkError $e) {
         $this->_logger->warning('Caught network error getting inventory quantity. Will retry on next opportunity.', $this->_logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     } catch (InvalidPayload $e) {
         $this->_logger->warning('Inventory quantity request payload is invalid.', $this->_logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     } catch (UnsupportedOperation $e) {
         $this->_logger->critical('Inventory quantity service response unsupported by SDK.', $this->_logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     } catch (UnsupportedHttpAction $e) {
         $this->_logger->critical('Inventory quantity operation failed due to unsupported HTTP action in the SDK.', $this->_logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     } catch (Exception $e) {
         $this->_logger->warning('Encountered unexepcted error attempting to request inventory quantities. See the exception log.', $this->_logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     }
     return $this;
 }
 /**
  * Make the API request and handle any exceptions.
  * @param ApiIBidirectionalApi $api
  * @return self
  */
 protected function _sendAuthRequest(Api\IBidirectionalApi $api)
 {
     $logger = $this->_logger;
     $logContext = $this->_context;
     try {
         $api->send();
     } catch (InvalidPayload $e) {
         // Invalid payloads cannot be valid - log the error and fail the auth
         $logMessage = 'Invalid payload for credit card auth. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         $this->_failPaymentAuth(self::CREDITCARD_AUTH_FAILED_MESSAGE);
     } catch (NetworkError $e) {
         // Can't accept an auth request that could not be made successfully - log
         // the error and fail the auth.
         $logMessage = 'Caught a network error sending credit card auth. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         $this->_failPaymentAuth(self::CREDITCARD_AUTH_FAILED_MESSAGE);
     } catch (UnsupportedOperation $e) {
         $logMessage = 'The credit card auth operation is unsupported in the current configuration. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     } catch (UnsupportedHttpAction $e) {
         $logMessage = 'The credit card auth operation is configured with an unsupported HTTP action. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     } catch (Exception $e) {
         $logMessage = 'Encountered unexpected exception from the credit card auth operation. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     }
     return $this;
 }
 /**
  * Send the request via the SDK
  * @param  Api\IBidirectionalApi $api
  * @return self
  * @throws EbayEnterprise_GiftCard_Exception If request cannot be made successfully
  */
 protected function _sendRequest(Api\IBidirectionalApi $api)
 {
     try {
         $api->send();
     } catch (Api\Exception\NetworkError $e) {
         $logMessage = 'Stored value request failed. See exception log for details.';
         $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__));
         $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         throw Mage::exception('EbayEnterprise_GiftCard_Exception_Network', $this->_helper->__(self::REQUEST_FAILED_MESSAGE));
     } catch (Payload\Exception\InvalidPayload $e) {
         $logMessage = 'Invalid payload for stored value response. See exception log for details.';
         $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__));
         $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e));
         throw Mage::exception('EbayEnterprise_GiftCard', $this->_helper->__(self::REQUEST_FAILED_MESSAGE));
     }
     return $this;
 }
 /**
  * Send the request for the TDF service and handle any responses or exceptions.
  *
  * @param IBidirectionalApi
  * @return self
  */
 protected function _sendApiRequest(IBidirectionalApi $api)
 {
     $logger = $this->_logger;
     $logContext = $this->_logContext;
     try {
         $api->send();
         // Generally, these catch statements will all add a log message for the
         // exception and throw a more generic exception that can be handled
         // (by Magento or the Inventory module) in such a way as to not block checkout.
     } catch (InvalidPayload $e) {
         $logger->warning('Invalid payload for inventory quantity. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     } catch (NetworkError $e) {
         $logger->warning('Caught network error getting inventory quantity. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     } catch (UnsupportedOperation $e) {
         $logger->critical('The inventory quantity operation is unsupported in the current configuration. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     } catch (UnsupportedHttpAction $e) {
         $logger->critical('Inventory quantity operation is configured with an unsupported HTTP action. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     } catch (Exception $e) {
         $logger->warning('Inventory quantity operation failed with unexpected exception. See exception log for more details.', $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     }
     return $this;
 }
 /**
  * Send the request via the SDK
  * @param  IBidirectionalApi $api
  * @return self
  * @throws EbayEnterprise_GiftCard_Exception If request cannot be made successfully
  */
 protected function sendRequest(IBidirectionalApi $api)
 {
     $logger = $this->logger;
     $logContext = $this->context;
     try {
         $api->send();
     } catch (InvalidPayload $e) {
         $logMessage = 'Invalid payload for stored value request. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw Mage::exception('EbayEnterprise_GiftCard', $this->helper->__(self::REQUEST_FAILED_MESSAGE));
     } catch (NetworkError $e) {
         $logMessage = 'Caught a network error sending stored value request. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw Mage::exception('EbayEnterprise_GiftCard_Exception_Network', $this->helper->__(self::REQUEST_FAILED_MESSAGE));
     } catch (UnsupportedOperation $e) {
         $logMessage = 'The stored value card operation is unsupported in the current configuration. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     } catch (UnsupportedHttpAction $e) {
         $logMessage = 'The stored value card operation is configured with an unsupported HTTP action. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     } catch (Exception $e) {
         $logMessage = 'Encountered unexpected exception from stored value card operation. See exception log for more details.';
         $logger->warning($logMessage, $logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()]));
         $logger->logException($e, $logContext->getMetaData(__CLASS__, [], $e));
         throw $e;
     }
     return $this;
 }