/**
  * Add a gift card to the container. Will make the gift card balance check
  * and make sure card can be applied to the order.
  * @param EbayEnterprise_GiftCard_Model_IGiftcard $card
  * @return self
  * @throws EbayEnterprise_GiftCard_Exception If gift card could not be added to the order.
  */
 public function addGiftCardToOrder(EbayEnterprise_GiftCard_Model_IGiftcard $card, EbayEnterprise_GiftCard_Model_IContainer $giftCardContainer)
 {
     $card->checkBalance();
     // Treat 0 balance gift cards as invalid.
     if ($card->getBalanceAmount() <= 0) {
         throw Mage::exception('EbayEnterprise_GiftCard', $this->__(self::ZERO_BALANCE_CARD_MESSAGE, $card->getCardNumber()));
     }
     $giftCardContainer->updateGiftCard($card);
     return $this;
 }
 /**
  * Add a gift card to the container. Will make the gift card balance check
  * and make sure card can be applied to the order.
  * @param EbayEnterprise_GiftCard_Model_IGiftcard $card
  * @return self
  */
 public function addGiftCardToOrder(EbayEnterprise_GiftCard_Model_IGiftcard $card)
 {
     try {
         $card->checkBalance();
         // only add cards with an available balance
         if ($card->getBalanceAmount() > 0) {
             $this->_giftCardContainer->updateGiftCard($card);
         } else {
             // throw exception to trigger error handling below, let 0 balance card
             // get handled like any other balance check failure
             throw Mage::exception('EbayEnterprise_GiftCard', $this->__(self::ZERO_BALANCE_CARD_MESSAGE, $card->getCardNumber()));
         }
     } catch (EbayEnterprise_GiftCard_Exception $e) {
         Mage::getSingleton('checkout/session')->addError($this->__($e->getMessage()));
     }
     return $this;
 }
 /**
  * Validate the amount the card was redeemed for. Card should only be considered
  * to have been redeemed successfully if the amount expected to be redeemed
  * matches the amount actually redeemed.
  * @param EbayEnterprise_GiftCard_Model_IGiftcard $card
  * @return self
  */
 protected function _validateCardRedeemed(EbayEnterprise_GiftCard_Model_IGiftcard $card)
 {
     if ($card->getAmountRedeemed() !== $card->getAmountToRedeem()) {
         // Card could not be redeemed for full expected amount but may still
         // be valid.
         if ($card->getBalanceAmount() + $card->getAmountRedeemed() === 0.0) {
             // no balance left on the card so no point in keeping it on the order.
             // remove card and message card could not be redeemed and has been removed
             $this->_failGiftCardRedeem($card, self::REDEEM_FAILED_UNREDEEMABLE_CARD, true);
         }
         $this->_failGiftCardRedeem($card, self::REDEEM_FAILED_UNEXPECTED_AMOUNT);
     }
     return $this;
 }
 /**
  * Get the amount available to redeem on a gift card - balance less any
  * amount already slated to be redeemed
  * @param  EbayEnterprise_GiftCard_Model_IGiftcard $card
  * @return float
  */
 protected function _getGiftCardAvailableAmount(EbayEnterprise_GiftCard_Model_IGiftcard $card)
 {
     return max(0.0, $card->getBalanceAmount() - $card->getAmountToRedeem());
 }
 /**
  * Get the balance of the gift card, formatted as currency for output.
  * @return string
  */
 public function getCardBalance()
 {
     return $this->giftCard ? Mage::helper('core')->formatCurrency($this->giftCard->getBalanceAmount(), true, false) : '';
 }
 /**
  * Validate the amount the card was redeemed for. Card should only be considered
  * to have been redeemed successfully if the amount expected to be redeemed
  * matches the amount actually redeemed.
  * @param EbayEnterprise_GiftCard_Model_IGiftcard $card
  * @return self
  */
 protected function _validateCardRedeemed(EbayEnterprise_GiftCard_Model_IGiftcard $card)
 {
     /**
      * Using bcmath bccomp function in order to resolve PHP float comparison issue due to precision errors.
      * @link http://www.php.net/manual/en/language.types.float.php
      * @var float
      */
     if (bccomp($card->getAmountRedeemed(), $card->getAmountToRedeem(), 2) !== 0) {
         // Card could not be redeemed for full expected amount but may still
         // be valid.
         if ($card->getBalanceAmount() + $card->getAmountRedeemed() === 0.0) {
             // no balance left on the card so no point in keeping it on the order.
             // remove card and message card could not be redeemed and has been removed
             $this->_failGiftCardRedeem($card, self::REDEEM_FAILED_UNREDEEMABLE_CARD, true);
         }
         $this->_failGiftCardRedeem($card, self::REDEEM_FAILED_UNEXPECTED_AMOUNT);
     }
     return $this;
 }