/** * Before collecting item totals, check that all items * in the quote are available to be fulfilled. * * @param Varien_Event_Observer * @return self */ public function handleBeforeCollectTotals(Varien_Event_Observer $observer) { try { $quote = $observer->getEvent()->getQuote(); $this->quantityService->checkQuoteInventory($quote); } catch (EbayEnterprise_Inventory_Exception_Quantity_Collector_Exception $e) { $this->logger->warning($e->getMessage(), $this->logContext->getMetaData(__CLASS__, [], $e)); } return $this; }
/** * @param Mage_Sales_Model_Order * @return self */ public function void(Mage_Sales_Model_Order $order) { if ($this->_canVoid($order)) { try { $this->_getVoidApi()->doVoidOrder($order); } catch (EbayEnterprise_PayPal_Exception $e) { $logMessage = 'Void request failed. See exception log for details.'; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__)); $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e)); } } return $this; }
/** * Get the last timestamp captured from a test message and return a new DateTime * object for the timestamp. If no last test message exists or is not a parseable * date time, will return null. * @return DateTime|null */ protected function _getLastTimestamp() { $lastTimestamp = $this->getValue(); $timestamp = null; try { // If the value isn't set, don't create a new DateTime. new DateTime(null) // gives a DateTime for the current time, which is not desirable here. $timestamp = $lastTimestamp ? $this->_coreHelper->getNewDateTime($lastTimestamp) : null; } catch (Exception $e) { $logData = ['last_timestamp' => $lastTimestamp]; $logMessage = 'Invalid timestamp for last AMQP test message timestamp: {last_timestamp}.'; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData, $e)); } return $timestamp; }
/** * 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; }
/** * Return an instance of `sales/order` when the payload have a valid customer increment id, * the order increment id correspond to a sales order in the Magento store, and the order in the Magento * store is shippable. However, if any of these conditions are not met a null value will be returned. * @return Mage_Sales_Model_Order | null */ protected function _getOrder() { $incrementId = $this->_payload->getCustomerOrderId(); $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId); if (!$order->getId()) { $logMsgOrderNotFound = "The shipment could not be added. The order (id: {$incrementId}) was not found in this Magento store."; $this->_logger->warning($logMsgOrderNotFound, $this->_context->getMetaData(__CLASS__)); return null; } if (!$order->canShip()) { $logMsgOrderNotShippable = "Order ({$incrementId}) can not be shipped."; $this->_logger->warning($logMsgOrderNotShippable, $this->_context->getMetaData(__CLASS__)); return null; } return $order; }
/** * Extract tax data from the ship group. * * Extracts all three sets of tax data as each set of data can be retrieved * from the same item parser. Extracting all three sets at once prevents * nearly identical steps from being repeated for each item for each type of * tax data. * * @return EbayEnterprise_Tax_Model_Record[] */ protected function _extractTaxData() { // Each of these will hold an array of arrays of data extracted from each // ship group - e.g. $taxRecords = [[$recordA, $recordB], [$recordC, $recordD]]. // Prepopulate tax records with data extracted for the address for gifting // so it will get merged together with item taxes. $taxRecords = [$this->_extractGiftingTaxRecords()]; $duties = []; $fees = []; /** @var ITaxedOrderItem $orderItem */ foreach ($this->_shipGroup->getItems() as $orderItem) { /** @var Mage_Sales_Model_Quote_Item $item */ $item = $this->_getItemForItemPayload($orderItem); if ($item) { $itemParser = $this->_taxFactory->createResponseItemParser($orderItem, $item, $this->_addressId, $this->_quoteId); $taxRecords[] = $itemParser->getTaxRecords(); $duties[] = $itemParser->getTaxDuties(); $fees[] = $itemParser->getTaxFees(); } else { $this->_logger->warning('Tax response item does not relate to any known quote item.', $this->_logContext->getMetaData(__CLASS__, ['rom_response_body' => $orderItem->serialize()])); } } // Flatten each nested array of tax data - allows for a single array_merge // instead of iteratively calling array_merge on each pass when extracting // tax data for each item. $this->_taxRecords = $this->_flattenArray($taxRecords); $this->_taxDuties = $this->_flattenArray($duties); $this->_taxFees = $this->_flattenArray($fees); return $this; }
/** * Process all of the products within a given store. * * @param Mage_Catalog_Model_Resource_Product_Collection $products products for a specific store * @param EbayEnterprise_Catalog_Model_Pim_Product_Collection $pimProducts collection of PIM Product instances * @param string $key * @param array $productIds * @return EbayEnterprise_Catalog_Model_Pim_Product_Collection $pimProducts collection of PIM Product instances */ protected function _processProductCollection(Mage_Catalog_Model_Resource_Product_Collection $products, EbayEnterprise_Catalog_Model_Pim_Product_Collection $pimProducts, array &$productIds = null) { $excludedProductIds = array(); $currentStoreId = $products->getStoreId(); $config = Mage::helper('eb2ccore')->getConfigModel($currentStoreId); $clientId = $config->clientId; $catalogId = $config->catalogId; foreach ($products->getItems() as $product) { $product->setStoreId($currentStoreId); $pimProduct = $pimProducts->getItemForProduct($product); if (!$pimProduct) { $pimProduct = Mage::getModel('ebayenterprise_catalog/pim_product', array('client_id' => $clientId, 'catalog_id' => $catalogId, 'sku' => $product->getSku())); $pimProducts->addItem($pimProduct); } try { $pimProduct->loadPimAttributesByProduct($product, $this->_doc, $this->_getFeedConfig(), $this->_getFeedAttributes($currentStoreId)); } catch (EbayEnterprise_Catalog_Model_Pim_Product_Validation_Exception $e) { $logData = ['sku' => $pimProduct->getSku()]; $logMessage = 'Product "{sku}" excluded from export.'; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); $this->_logger->logException($e, $this->_context->getMetaData(__CLASS__, [], $e)); $excludedProductIds[] = $product->getId(); $pimProducts->deleteItem($pimProduct); } } if ($productIds) { $productIds = array_diff($productIds, $excludedProductIds); } return $pimProducts; }
/** * attempt to undo an allocation * * @param EbayEnterprise_Inventory_Model_Allocation_Reservation */ public function rollback(EbayEnterprise_Inventory_Model_Allocation_Reservation $reservation) { $api = $this->prepareApi(); try { $this->prepareRequest($api, $reservation); $api->send(); return; } catch (InvalidPayload $e) { $this->logger->warning('The allocation rollback response payload is invalid.', $this->logContext->getMetaData(__CLASS__, [], $e)); } catch (NetworkError $e) { $this->logger->warning('Failed sending the allocation rollback request.', $this->logContext->getMetaData(__CLASS__, [], $e)); } catch (UnsupportedOperation $e) { $this->logger->critical('Allocation rollback is unsupported in the currently configured SDK.', $this->logContext->getMetaData(__CLASS__, [], $e)); } catch (UnsupportedHttpAction $e) { $this->logger->critical('Allocation rollback configured to use unsupported HTTP action.', $this->logContext->getMetaData(__CLASS__, [], $e)); } }
/** * add the shipping method to the the list if it is a * valid ROM shipping method * * @param string * @param string */ protected function storeShippingMethodInfo($shippingMethod, $displayString) { $sdkId = $this->lookupShipMethod($shippingMethod); if (!$sdkId) { $this->logger->warning('Encountered active shipping method with no ROM mapping.', $this->logContext->getMetaData(__CLASS__, ['shipping_method' => $shippingMethod, 'display_string' => $displayString])); return; } $this->methods[$shippingMethod] = ['sdk_id' => $sdkId, 'display_text' => $displayString]; }
/** * Sets configurable_attributes_data * @param string $productTypeId ('configurable', 'simple' etc). * @param Varien_Object $source the source data field * @param Mage_Catalog_Model_Product $product the product we are setting * @return array of configurable_attributes_data */ public function getConfigurableAttributesData($productTypeId, Varien_Object $source, Mage_Catalog_Model_Product $product) { if ($product->getId() && $product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $productTypeId === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE && $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product)) { $logData = ['sku' => $product->getSku()]; $logMessage = 'Cannot change existing configurable attributes; update discarded for SKU "{sku}"'; $this->logger->warning($logMessage, $this->context->getMetaData(__CLASS__, $logData)); return null; } return $source->getData('configurable_attributes_data'); }
/** * Resubmit an order. * * @param Mage_Sales_Model_Order * @return void */ protected function resubmit(Mage_Sales_Model_Order $order) { if (!$order->hasEb2cOrderCreateRequest()) { $this->logger->warning('Unable to resubmit "{order_id}". Please see documentation for possible solutions.', $this->logContext->getMetaData(['order_id' => $order->getIncrementId()])); return; } $api = $this->coreHelper->getSdkApi($this->orderCfg->apiService, $this->orderCfg->apiCreateOperation); $createArgs = ['api' => $api, 'config' => $this->orderCfg, 'is_payload_prebuilt' => true, 'order' => $order, 'payload' => $api->getRequestBody()]; $this->getOrderCreateModel($createArgs)->send(); }
/** * Processing order rejected event by loading the order using the customer order id * from the payload, if we have a valid order in Magento we proceed to attempt * to cancel the order. * @return self */ public function process() { $incrementId = trim($this->_payload->getCustomerOrderId()); if ($incrementId === '') { $logMessage = 'Received empty customer order id.'; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__)); return $this; } $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId); if (!$order->getId()) { $logData = ['increment_Id' => $incrementId]; $logMessage = 'Customer order id {increment_id} was not found.'; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); return $this; } // canceling the order $this->_orderEventHelper->attemptCancelOrder($order, $this->_payload->getEventType()); return $this; }
/** * Verify that the passed in track number is in the collections of Magento shipment tracks, otherwise logs warning message. * @param Varien_Data_Collection $tracks * @param OrderEvents\ITrackingNumber $trackingNumber * @return self */ protected function _verifyTrack(Varien_Data_Collection $tracks, OrderEvents\ITrackingNumber $trackingNumber) { $number = $trackingNumber->getTrackingNumber(); $track = $tracks->getItemByColumnValue('track_number', $number); if (is_null($track)) { $logMessage = "Magento did not add an expected-to-be-shipped Track number ({$number}) to the shipment."; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__)); } return $this; }
/** * resubmit the order * @param Mage_Sales_Model_Order * @param array */ protected function resubmit(Mage_Sales_Model_Order $order, array $createArgs) { $raw = $order->getEb2cOrderCreateRequest(); if ($raw) { $createArgs['order'] = $order; $this->getOrderCreateModel($createArgs)->send(); } else { $this->logger->warning('Unable to resubmit "{order_id}". Please see documentation for possible solutions.', $this->logContext->getMetaData(['order_id' => $order->getIncrementId()])); } }
/** * If a new email can be sent for the order, queue it to be sent. * * @param Mage_Sales_Model_Order * @return self */ protected function _queueNewOrderEmail(Mage_Sales_Model_Order $order) { if ($order->getCanSendNewEmailFlag()) { try { $order->queueNewOrderEmail(); } catch (Exception $e) { $this->_logger->warning('Unable to queue new order email.', $this->_logContext->getMetaData(__CLASS__, [], $e)); } } return $this; }
/** * Unhandled exceptions cause the entire order not to get saved. * This is by design, so we don't report a false success or try * to keep sending an order that has no hope for success. * * @param Exception|null The exception to log or null for the default. * @return Exception The same (or default) exception after logging */ protected function _logUnhandledException(Exception $e = null) { if (!$e) { $errorMessage = $this->_helper->__(self::ORDER_CREATE_FAIL_MESSAGE); // Mage::exception adds '_Exception' to the end. $exceptionClassName = Mage::getConfig()->getModelClassName('ebayenterprise_order/create'); $e = Mage::exception($exceptionClassName, $errorMessage); } $this->_logger->warning('Encountered a fatal error attempting to send order create. See the exception log.', $this->_logContext->getMetaData(__CLASS__, [], $e)); return $e; }
/** * 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(); }
/** * Log any unexpected behavior that may indicate issues in the request * or the address validation provider. * * @return self */ protected function logResultCode() { $resultCode = $this->getResultCode(); $message = $this->nullCoalesce($this->resultCodeWarningMap, $resultCode, 'Response message did not contain a known result code. Result Code: {result_code}'); if ($message) { $this->logger->warning($message, $this->getMetaData($resultCode)); } $logData = ['result_code' => $resultCode, 'validation' => $this->isAddressValid() ? 'valid' : 'invalid']; $logMessage = 'Response with status code "{result_code}" is {validation}.'; $this->logger->debug($logMessage, $this->context->getMetaData(__CLASS__, $logData)); return $this; }
/** * extract the attribute set name * * @param DOMNodeList $nodes * @param Mage_Catalog_Model_Product $product * @return int */ public function extractAttributeSetValue(DOMNodeList $nodes, Mage_Catalog_Model_Product $product) { $attributeSetName = $this->coreHelper->extractNodeVal($nodes); $attributeSetId = Mage::helper('ebayenterprise_catalog')->getAttributeSetIdByName($attributeSetName); if (is_null($attributeSetId)) { // @todo: move to error confirmation feed $logData = ['attribute_set_name' => $attributeSetName]; $logMessage = 'Attribute Set "{attribute_set_name}" has not yet been setup for this Magento instance.'; $this->logger->warning($logMessage, $this->context->getMetaData(__CLASS__, $logData)); } return $attributeSetId ?: $product->getAttributeSetId(); }
/** * reserve items for the quote * * @param Mage_Sales_Model_Quote */ public function allocateInventoryForQuote(Mage_Sales_Model_Quote $quote) { if (!$this->isAllItemBackorderableAndOutOfStock($quote)) { try { $this->getInventorySession()->setAllocationResult($this->createAllocator()->reserveItemsForQuote($quote)); } catch (EbayEnterprise_Inventory_Exception_Allocation_Failure_Exception $e) { // clear any remnant of a result $this->getInventorySession()->unsAllocationResult(); $this->logger->warning('Unable to allocate inventory for the quote', $this->logContext->getMetaData(__CLASS__, [], $e)); } } }
/** * Before collecting item totals, check that all items * in the quote are available to be fulfilled. * * @param Varien_Event_Observer * @return self */ public function handleBeforeCollectTotals(Varien_Event_Observer $observer) { try { $quote = $observer->getEvent()->getQuote(); $this->quantityService->checkQuoteInventory($quote); } catch (EbayEnterprise_Inventory_Exception_Quantity_Collector_Exception $e) { $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e)); $this->logger->warning('Caught the following exception: {exception_message}.', $this->logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); } catch (EbayEnterprise_Inventory_Exception_Quantity_Unavailable_Exception $e) { $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e)); $this->logger->warning('Caught the following exception: {exception_message}.', $this->logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); if ($this->app->getStore()->isAdmin()) { // Handling admin exception here because it is not // being caught in the admin controller causing it // to display exception traces in the page. return $this->handleAdminOrderException($e, $quote); } // Continue to throw the exception in the frontend and let // the frontend controller handle it. throw $e; } return $this; }
/** * Test connecting to the AMQP server. Will connect to the AMQP server but will * not consume any messages. * @param string $hostname * @param string $username * @param string $password * @return array AJAX response body. Should contain a 'message' => string and 'success' => bool */ public function testConnection($hostname, $username, $password) { try { $this->_validateConfiguration($hostname, $username, $password)->_validateConnection($hostname, $username, $password); } catch (EbayEnterprise_Amqp_Exception $e) { return array('message' => $e->getMessage(), 'success' => false); } catch (Exception $e) { $logData = ['error_message' => $e->getMessage()]; $logMessage = 'Failed to connect to AMQP server with message: {error_message}'; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData, $e)); return array('message' => $this->_helper->__(self::UNABLE_TO_VALIDATE), 'success' => false); } return array('message' => $this->_helper->__(self::CONNECTION_SUCCESS), 'success' => true); }
/** * Determine the type of exception and logged it accordingly. * * @param Exception * @return self */ protected function _processException(Exception $e) { if ($e instanceof NetworkError) { $logMessage = "Caught a network error sending {$this->_getPayloadName()}. Will retry later."; $this->_logger->warning($logMessage, $this->_getLogContext($e)); } elseif ($e instanceof UnsupportedOperation || $e instanceof UnsupportedHttpAction) { $logMessage = "{$this->_getPayloadName()} request could not be sent. Please check your configuration."; $this->_logger->critical($logMessage, $this->_getLogContext($e)); } else { $logMessage = "Encountered a fatal error attempting to send {$this->_getPayloadName()} request."; $this->_logger->warning($logMessage, $this->_getLogContext($e)); } return $this; }
/** * Get a DateTime object for when the file was created. This will * initially attempt to use the value of the CreateDateTimeNode * in the XML contained in the file. If the node cannot be found in * the file, the mtime of the file will be used. Should both methods * fail to produce a usable DateTime, beginning of the Unix epoch will be used. * @param string $filename path to the xml file * @return DateTime */ public function getMessageDate($filename) { $messageDate = $this->_getDateTimeFromFeed($filename); if (!$messageDate) { $logData = ['filename' => $filename]; $logMessage = 'Unable to read the message date from file "{filename}"'; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); // When no CreateDateAndTime node found in the feed, fallback // to the file's mtime. $mtime = filemtime($filename); // Get a formatted date from the unix mtime, when filemtime // failed, the resulting date('c', false) call will result in // the same thing as date('c', 0), which is the expected final fallback value $messageDate = date('c', $mtime); } return $this->_getDateTimeForMessage($messageDate); }
/** * 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; }
/** * attempt to do an inventory allocation operation * * @param EbayEnterprise_Inventory_Model_Allocation_Item_Selector * @return EbayEnterprise_Inventory_Model_Allocation_Result */ protected function doOperation(EbayEnterprise_Inventory_Model_Allocation_Item_Selector $selector) { $api = $this->prepareApi(); $this->prepareRequest($api, $selector); try { $api->send(); return $this->prepareResult($api); } catch (NetworkError $e) { $this->logger->warning('Unable to send allocation the request.', $this->logContext->getMetaData(__CLASS__, [], $e)); } catch (UnsupportedHttpAction $e) { $this->logger->critical('Create inventory allocation failed due to protocol error', $this->logContext->getMetaData(__CLASS__, [], $e)); } 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->warning('The allocation response was invalid.', $this->logContext->getMetaData(__CLASS__, [], $e)); } $this->handleAllocationFailure(); }
/** * Load the file into a new DOM Document and validate the file. If successful, * return the DOM document. Otherwise, return null. * @param array $fileDetail * @return EbayEnterprise_Dom_Document|null */ protected function _loadDom($fileDetail) { $dom = Mage::helper('eb2ccore')->getNewDomDocument(); $basename = basename($fileDetail['local_file']); $logData = ['basename' => $basename]; $context = $this->_context->getMetaData(__CLASS__, $logData); if (!$dom->load($fileDetail['local_file'])) { $logMessage = 'DomDocument could not load file "{basename}"'; $this->_logger->warning($logMessage, $context); return null; } // Validate Eb2c Header Information if (!Mage::helper('ebayenterprise_catalog/feed')->validateHeader($dom, $fileDetail['core_feed']->getEventType())) { $logMessage = 'Invalid header for file "{basename}"'; $this->_logger->warning($logMessage, $context); return null; } return $dom; }
/** * Make a PayPal void request for the order identified by the order id. * * @param string * @param string * @return array * @throws EbayEnterprise_PayPal_Exception when the operation cannot be completed or fails. */ protected function doVoid($orderId, $currencyCode) { $sdk = $this->getSdk($this->config->apiOperationDoVoid); $payload = $sdk->getRequestBody(); $payload->setOrderId($orderId)->setRequestId($this->coreHelper->generateRequestId(self::PAYPAL_DOVOID_REQUEST_ID_PREFIX))->setCurrencyCode($currencyCode); Mage::dispatchEvent('ebayenterprise_paypal_do_void_before_send', ['payload' => $payload]); $sdk->setRequestBody($payload); $reply = $this->sendRequest($sdk); Mage::dispatchEvent('ebayenterprise_paypal_do_void_after_send', ['payload' => $reply]); $isVoided = $reply->isSuccess(); if (!$reply->isSuccess()) { $logMessage = 'PayPal DoVoid failed. See exception log for details.'; $this->logger->warning($logMessage, $this->logContext->getMetaData(__CLASS__)); $e = Mage::exception('EbayEnterprise_PayPal', $this->helper->__(static::EBAYENTERPRISE_PAYPAL_API_FAILED)); $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $e)); throw $e; } return ['method' => EbayEnterprise_PayPal_Model_Method_Express::CODE, 'order_id' => $reply->getOrderId(), 'is_voided' => $isVoided]; }
/** * log the response and return the result of the configured handler method. * * @param Zend_Http_Response $response * @param string $uri * @return string response body or empty */ protected function _processResponse(Zend_Http_Response $response, $uri) { $this->_status = $response->getStatus(); $config = $this->_getHandlerConfig($this->_getHandlerKey($response)); $logMethod = isset($config['logger']) ? $config['logger'] : 'debug'; $logData = array_merge(['rom_request_url' => $uri], $this->_logAppContext); $this->_logger->{$logMethod}('Received response from.', $this->_context->getMetaData(__CLASS__, $logData)); $responseData = $logData; $responseData['rom_response_body'] = $response->asString(); $logMessage = 'Response data.'; $this->_logger->debug($logMessage, $this->_context->getMetaData(__CLASS__, $responseData)); if (!$response->getBody()) { $logMessage = "Received response with no body from {$uri} with status {$this->_status}."; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData)); } $callbackConfig = isset($config['callback']) ? $config['callback'] : array(); $callbackConfig['parameters'] = array($response); return Mage::helper('eb2ccore')->invokeCallBack($callbackConfig); }
/** * 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; }