/** * get the giftcard config registry * * @return EbayEnterprise_Eb2cCore_Model_Config_Registry */ protected function getConfig() { if (!$this->config) { $this->config = $this->helper->getConfigModel(); } return $this->config; }
/** * 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; }
/** * Test that when a balance check fails, gift cards are not added to the cart/container. */ public function testAddGiftCardToOrderBalanceCheckFails() { // replace session used by the gift card container - prevents headers already sent error from session $session = $this->_replaceSession('checkout/session'); $cardNumber = '1111222233334444'; $card = $this->getModelMock('ebayenterprise_giftcard/giftcard', array('checkBalance')); $card->setBalanceAmount(50.0)->setCardNumber($cardNumber); $card->expects($this->once())->method('checkBalance')->will($this->throwException(new EbayEnterprise_GiftCard_Exception())); // attempt to add the gift card to the order $this->giftCardHelper->addGiftCardToOrder($card); // gift card balance check failures should result in new error message $this->assertCount(1, $session->getMessages()->getErrors()); // card should not have been added to the container - get gift card with same number will return new gift card instance $this->assertNotSame($card, Mage::getModel('ebayenterprise_giftcard/container')->getGiftCard($cardNumber)); }
/** * Test that when a balance check fails, gift cards are not added to the cart/container. */ public function testAddGiftCardToOrderBalanceCheckFails() { // replace session used by the gift card container - prevents headers already sent error from session $this->_replaceSession('ebayenterprise_giftcard/session'); $cardNumber = '1111222233334444'; $pin = '1234'; $card = $this->getModelMock('ebayenterprise_giftcard/giftcard', array('checkBalance')); $card->setBalanceAmount(50.0)->setCardNumber($cardNumber)->setPin($pin); $card->expects($this->once())->method('checkBalance')->will($this->throwException(new EbayEnterprise_GiftCard_Exception())); // Need custom exception testing: want to make sure that an expected // exception is thrown but also need to test some post conditions, // specifically that the gift cards wasn't added to the container. Catch // the exception thrown and validate that the expected exception was // thrown and caught in the test. $thrownException = null; try { // attempt to add the gift card to the order $this->giftCardHelper->addGiftCardToOrder($card, $this->giftCardContainer); } catch (EbayEnterprise_GiftCard_Exception $e) { $thrownException = $e; } $this->assertInstanceOf('EbayEnterprise_GiftCard_Exception', $thrownException); // card should not have been added to the container - get gift card with same number will return new gift card instance $this->assertNotSame($card->getPin(), $this->giftCardContainer->getGiftCard($cardNumber)->getPin()); }
/** * 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; }