/**
  * 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;
 }
 /**
  * process the data from the response into simpler objects
  *
  * @param IBidirectionalApi
  * @return EbayEnterprise_Inventory_Model_Allocation_Result
  */
 protected function prepareResult(IBidirectionalApi $api)
 {
     $result = $this->exportResultData($api->getResponseBody());
     return $result;
 }
 /**
  * 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;
 }
 protected function extractResponseData(IBidirectionalApi $api)
 {
     $response = $api->getResponseBody();
     return $this->extractResult($response)->extractResponseAddresses($response);
 }
 /**
  * Update payment objects with details of the auth request and response. Validate
  * that a successful response was received.
  * @param ApiIBidirectionalApi $api
  * @param Varien_Object        $payment
  * @return self
  */
 protected function _handleApiResponse(Api\IBidirectionalApi $api, Varien_Object $payment)
 {
     $request = $api->getRequestBody();
     $response = $api->getResponseBody();
     return $this->_updatePaymentsWithAuthData($payment, $request, $response)->_validateResponse($response);
 }
 /**
  * Extract quantity results from the API response body.
  *
  * @param IBidirectionalApi
  * @param Mage_Sales_Model_Order_Quote_Item[]
  * @return EbayEnterprise_Inventory_Model_Quantity_Results
  */
 protected function _extractResponseResults(IBidirectionalApi $api, array $items)
 {
     try {
         $responseBody = $api->getResponseBody();
     } catch (UnsupportedOperation $e) {
         // This exception handling is probably not necessary but
         // is technically possible. If the sdk flow of
         // getRequest->setRequest->send->getResponse is followed,
         // which is is by the one public method of this class, this
         // exception should never be thrown in this instance. If it
         // were to be thrown at all by the SDK, it would have already
         // happened during the "send" step.
         $this->_logger->critical('Inventory quantity service response unsupported by SDK.', $this->_logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failQuantityCollection();
     }
     $responseParser = $this->_inventoryQuantityFactory->createResponseParser($responseBody);
     return $this->_inventoryQuantityFactory->createQuantityResults($responseParser->getQuantityResults(), $items);
 }
 /**
  * Check for the gift card redeem to have been voided. If it was, update the
  * gift card with response data. If not, thrown an exception, indicating the
  * request failed.
  * @param  Api\IBidirectionalApi $api
  * @return self
  * @throws EbayEnterprise_GiftCard_Exception If the redeem was not voided
  */
 protected function _handleVoidResponse(Api\IBidirectionalApi $api)
 {
     $response = $api->getResponseBody();
     if (!$response->wasVoided()) {
         throw Mage::exception('EbayEnterprise_GiftCard', self::VOID_REQUEST_FAILED_MESSAGE);
     }
     return $this->_extractPayloadAccountUniqueId($response)->setBalanceAmount($this->getBalanceAmount() + $this->getAmountRedeemed())->setAmountRedeemed(0.0)->setIsRedeemed(false);
 }
 /**
  * Extract tax records from the API response body for the quote.
  *
  * @param IBidirectionalApi
  * @param Mage_Sales_Model_Order_Quote
  * @return EbayEnterprise_Tax_Model_Result
  */
 protected function _extractResponseResults(IBidirectionalApi $api, Mage_Sales_Model_Quote $quote)
 {
     try {
         $responseBody = $api->getResponseBody();
     } catch (UnsupportedOperation $e) {
         // This exception handling is probably not necessary but
         // is technically possible. If the sdk flow of
         // getRequest->setRequest->send->getResponse is followed,
         // which is is by the one public method of this class, this
         // exception should never be thrown in this instance. If it
         // were to be thrown at all by the SDK, it would have already
         // happened during the "send" step.
         $this->logger->critical('Tax quote service response unsupported by SDK.', $this->logContext->getMetaData(__CLASS__, [], $e));
         throw $this->_failTaxCollection();
     }
     $responseParser = $this->taxFactory->createResponseQuoteParser($responseBody, $quote);
     return $this->taxFactory->createTaxResults($responseParser->getTaxRecords(), $responseParser->getTaxDuties(), $responseParser->getTaxFees());
 }