/** * Show how unredeemed gift cards will apply to the cart * for display purposes. * * @param Mage_Sales_Model_Quote_Address $address * @return self */ public function fetch(Mage_Sales_Model_Quote_Address $address) { /** * Pass a copy of the unredeemed cards SPLObjectStorage to the total * with applied amounts supplied as values to each object. */ $address->addTotal(array('code' => $this->getCode(), 'title' => $this->_giftCardHelper->__(static::GIFT_CARD_SYSTEM_MESSAGE), 'value' => $address->getEbayEnterpriseGiftCardBaseAppliedAmount(), 'cards' => $this->_giftCardContainer->getUnredeemedGiftCards())); return $this; }
/** * 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)); } }
/** * 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; }
/** * Check the balance of a gift card. */ public function balanceAction() { $checkoutSession = $this->_getCheckoutSession(); list($cardNumber, $pin) = $this->_getCardInfoFromRequest(); // try a balance request. $giftcard = $this->_getContainer()->getGiftCard($cardNumber)->setPin($pin); try { $giftcard->checkBalance(); $checkoutSession->setEbayEnterpriseCurrentGiftCard($giftcard); } catch (EbayEnterprise_GiftCard_Exception $e) { $checkoutSession->addError($this->_helper->__($e->getMessage())); } if ($this->getRequest()->isAjax()) { $this->loadLayout(); $this->renderLayout(); } else { $this->_redirect(static::REDIRECT_PATH); } }
/** * add a giftcard. * * @param string $cardNumber * @param string $pin * @return self */ protected function addGiftCard($cardNumber, $pin) { $giftcard = $this->container->getGiftCard($cardNumber)->setPin($pin); try { $this->helper->addGiftCardToOrder($giftcard, $this->container); $this->getSession()->addSuccess($this->helper->__(EbayEnterprise_GiftCard_Helper_Data::GIFT_CARD_ADD_SUCCESS, $cardNumber)); } catch (EbayEnterprise_GiftCard_Exception $e) { $this->getSession()->addError($this->helper->__($e->getMessage())); $this->logger->debug('Failed to add gift card to admin order. See exception log for more details.', $this->logContext->getMetaData(__CLASS__, ['exception_message' => $e->getMessage()])); $this->logger->logException($e, $this->logContext->getMetaData(__CLASS__, [], $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; }
/** * Register gift card totals with the order totals block. * * @return self */ public function initTotals() { $total = new Varien_Object(['code' => self::TOTAL_CODE, 'block_name' => $this->getNameInLayout(), 'label' => $this->helper->__(self::TOTAL_LABEL)]); $this->getParentBlock()->addTotalBefore($total, ['customerbalance', 'grand_total']); return $this; }