/** * 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; }
/** * Make stored value card payloads for any redeemed * gift cards * * @param Mage_Sales_Model_Order $order * @param IPaymentContainer $paymentContainer * @param SplObjectStorage $processedPayments */ public function addPaymentsToPayload(Mage_Sales_Model_Order $order, IPaymentContainer $paymentContainer, SplObjectStorage $processedPayments) { foreach ($this->_giftcardContainer->getRedeemedGiftcards() as $giftcard) { $iterable = $paymentContainer->getPayments(); $payload = $iterable->getEmptyStoredValueCardPayment(); $payload->setOrderId($order->getIncrementId())->setTenderType($giftcard->getTenderType())->setAccountUniqueId($giftcard->getCardNumber())->setPanIsToken((bool) $giftcard->getPanIsToken())->setCreateTimestamp($giftcard->getRedeemedAt())->setAmount($giftcard->getAmountRedeemed())->setPin($giftcard->getPin())->setPaymentRequestId($giftcard->getRedeemRequestId()); // add the new payload $iterable->OffsetSet($payload, $payload); // put the payment in the processed payments set $processedPayments->attach($giftcard); } }
/** * 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; }
/** * Collect gift card totals for the specified address * @param Mage_Sales_Model_Quote_Address $address * @return self */ public function collect(Mage_Sales_Model_Quote_Address $address) { // Cards are not specific to a single address so cards may have already been // partially applied to other address amounts. $cards = $this->_giftCardContainer->getUnredeemedGiftCards(); $grandTotal = $address->getGrandTotal(); $appliedAmount = 0.0; foreach ($cards as $card) { // Amount of this address total to apply to the gift card $amountToApply = min($this->_getGiftCardAvailableAmount($card), $grandTotal - $appliedAmount); // Update the amount expected to be redeemed from the gift card. Must add to any // existing amount exepcted to be redeemed to not clear out amounts // set while collecting other addresses. $card->setAmountToRedeem($card->getAmountToRedeem() + $amountToApply); // Accumulate amounts being redeemed for this address. $appliedAmount += $amountToApply; } // Only support one currency right now. $address->setEbayEnterpriseGiftCardBaseAppliedAmount($appliedAmount)->setEbayEnterpriseGiftCardAppliedAmount($appliedAmount)->setBaseGrandTotal($grandTotal - $appliedAmount)->setGrandTotal($grandTotal - $appliedAmount); return $this; }
/** * remove a giftcard. * * @param string $cardNumber * @return self */ protected function removeGiftCard($cardNumber) { $giftcard = $this->container->getGiftCard($cardNumber); $this->container->removeGiftCard($giftcard); return $this; }