/** * 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; }
/** * 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; }