Example #1
0
 public function _place(Mage_Sales_Model_Order_Payment $payment, $amount)
 {
     $order = $payment->getOrder();
     $items = Mage::helper('iugu')->getItemsFromOrder($payment->getOrder());
     $payer = Mage::helper('iugu')->getPayerInfoFromOrder($payment->getOrder());
     $data = new Varien_Object();
     $data->setMethod(Inovarti_Iugu_Model_Api::PAYMENT_METHOD_BOLETO)->setEmail($order->getCustomerEmail())->setItems($items)->setPayer($payer)->setNotificationUrl(Mage::getUrl('iugu/notification'));
     // Discount
     if ($order->getBaseDiscountAmount()) {
         $data->setDiscountCents(Mage::helper('iugu')->formatAmount(abs($order->getBaseDiscountAmount())));
     }
     // Tax
     if ($order->getBaseTaxAmount()) {
         $data->setTaxCents($this->formatAmount($order->getBaseTaxAmount()));
     }
     $result = Mage::getSingleton('iugu/api')->charge($data);
     if ($result->getErrors()) {
         $messages = array();
         if (is_array($result->getErrors())) {
             foreach ($result->getErrors() as $field => $errors) {
                 foreach ($errors as $error) {
                     $messages[] = $field . ': ' . $error . '.';
                 }
             }
         } else {
             $messages[] = $result->getErrors();
         }
         Mage::throwException(implode("\n", $messages));
     }
     // iugu info
     $payment->setIuguInvoiceId($result->getInvoiceId())->setIuguUrl($result->getUrl())->setIuguPdf($result->getPdf());
     return $this;
 }
 public function collect(Mage_Sales_Model_Quote_Address $address)
 {
     $address->setData('zitec_dpd_cashondelivery_surcharge', 0);
     $address->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
     $address->setData('zitec_dpd_cashondelivery_surcharge_tax', 0);
     $address->setData('base_zitec_dpd_cashondelivery_surcharge_tax', 0);
     $paymentMethod = $address->getQuote()->getPayment()->getMethod();
     if ($paymentMethod == Mage::helper('zitec_dpd')->getDpdPaymentCode() && $address->getAddressType() == 'shipping') {
         $quote = $address->getQuote();
         /* @var $quote Mage_Sales_Model_Quote */
         $shippingAddress = $quote->getShippingAddress();
         $request = new Varien_Object();
         $request->setWebsiteId(Mage::helper('zitec_dpd/payment')->getWebsiteId());
         $request->setDestCountryId($shippingAddress->getCountryId());
         $request->setDestRegionId($shippingAddress->getRegionId());
         $request->setDestPostcode($shippingAddress->getPostcode());
         $request->setPackageWeight($shippingAddress->getWeight());
         if ($this->_getTaxHelper()->shippingPriceIncludesTax($address->getQuote()->getStoreId())) {
             $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotalInclTax());
         } else {
             $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotal());
         }
         $request->setMethod(str_replace(Mage::helper('zitec_dpd')->getDPDCarrierCode() . '_', '', $shippingAddress->getShippingMethod()));
         $tablerateSurcharge = Mage::getResourceModel('zitec_dpd/carrier_tablerate')->getCashOnDeliverySurcharge($request);
         if (is_null($tablerateSurcharge)) {
             return $this;
         } elseif (!empty($tablerateSurcharge)) {
             $baseCashondeliverySurcharge = $this->_getHelper()->calculateQuoteBaseCashOnDeliverySurcharge($quote, $tablerateSurcharge);
         } else {
             $baseCashondeliverySurcharge = $this->_getHelper()->returnDefaultBaseCashOnDeliverySurcharge($quote);
         }
         if (!isset($baseCashondeliverySurcharge)) {
             return $this;
         }
         $baseCurrencyCode = $quote->getStore()->getBaseCurrencyCode();
         $currentCurrencyCode = $quote->getStore()->getCurrentCurrencyCode();
         $cashondeliverySurcharge = Mage::helper('directory')->currencyConvert($baseCashondeliverySurcharge, $baseCurrencyCode, $currentCurrencyCode);
         $address->setData('zitec_dpd_cashondelivery_surcharge', $cashondeliverySurcharge);
         $address->setData('base_zitec_dpd_cashondelivery_surcharge', $baseCashondeliverySurcharge);
         $this->_calculateSurchargeSalesTax($address);
         $quote->save();
     }
     $address->setGrandTotal($address->getGrandTotal() + $address->getData('zitec_dpd_cashondelivery_surcharge'));
     $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getData('base_zitec_dpd_cashondelivery_surcharge'));
     return $this;
 }
 /**
  * Analyze payment data for quote and set free shipping if grand total is covered by balance
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param Varien_Object|Mage_Sales_Model_Quote_Payment $payment
  * @param bool $shouldUseBalance
  */
 protected function _importPaymentData($quote, $payment, $shouldUseBalance)
 {
     $store = Mage::app()->getStore($quote->getStoreId());
     if (!$quote || !$quote->getCustomerId() || $quote->getBaseGrandTotal() + $quote->getBaseCustomerBalanceAmountUsed() <= 0) {
         return;
     }
     $quote->setUseCustomerBalance($shouldUseBalance);
     if ($shouldUseBalance) {
         $balance = Mage::getModel('enterprise_customerbalance/balance')->setCustomerId($quote->getCustomerId())->setWebsiteId($store->getWebsiteId())->loadByCustomer();
         if ($balance) {
             $quote->setCustomerBalanceInstance($balance);
             if (!$payment->getMethod()) {
                 $payment->setMethod('free');
             }
         } else {
             $quote->setUseCustomerBalance(false);
         }
     }
 }
 /**
  * Prepare and set to quote reward balance instance,
  * set zero subtotal checkout payment if need
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param Varien_Object $payment
  * @param boolean $useRewardPoints
  * @return Enterprise_Reward_Model_Observer
  */
 protected function _paymentDataImport($quote, $payment, $useRewardPoints)
 {
     if (!$quote || !$quote->getCustomerId() || $quote->getBaseGrandTotal() + $quote->getBaseRewardCurrencyAmount() <= 0) {
         return $this;
     }
     $quote->setUseRewardPoints((bool) $useRewardPoints);
     if ($quote->getUseRewardPoints()) {
         /* @var $reward Enterprise_Reward_Model_Reward */
         $reward = Mage::getModel('enterprise_reward/reward')->setCustomer($quote->getCustomer())->setWebsiteId($quote->getStore()->getWebsiteId())->loadByCustomer();
         $minPointsBalance = (int) Mage::getStoreConfig(Enterprise_Reward_Model_Reward::XML_PATH_MIN_POINTS_BALANCE, $quote->getStoreId());
         if ($reward->getId() && $reward->getPointsBalance() >= $minPointsBalance) {
             $quote->setRewardInstance($reward);
             if (!$payment->getMethod()) {
                 $payment->setMethod('free');
             }
         } else {
             $quote->setUseRewardPoints(false);
         }
     }
     return $this;
 }
Example #5
0
 /**
  * Prepare and set to quote reward balance instance,
  * set zero subtotal checkout payment if need
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param Varien_Object $payment
  * @param boolean $useRewardPoints
  * @return Enterprise_Reward_Model_Observer
  */
 protected function _paymentDataImport($quote, $payment, $useRewardPoints)
 {
     if (!$quote || !$quote->getCustomerId()) {
         return $this;
     }
     $quote->setUseRewardPoints((bool) $useRewardPoints);
     if ($quote->getUseRewardPoints()) {
         /* @var $reward Enterprise_Reward_Model_Reward */
         $reward = Mage::getModel('enterprise_reward/reward')->setCustomer($quote->getCustomer())->setWebsiteId($quote->getStore()->getWebsiteId())->loadByCustomer();
         if ($reward->getId()) {
             $quote->setRewardInstance($reward);
             if (!$payment->getMethod()) {
                 $payment->setMethod('free');
             }
         } else {
             $quote->setUseRewardPoints(false);
         }
     }
     return $this;
 }
 public function getSurchage()
 {
     if ($this->_surcharge === null) {
         $order = $this->fetchOrder();
         if ($order) {
             $this->_surcharge = $order->getData('base_zitec_dpd_cashondelivery_surcharge');
         } else {
             $quote = Mage::helper('zitec_dpd/payment')->getQuote();
             /* @var $quote Mage_Sales_Model_Quote */
             if ($quote) {
                 $shippingAddress = $quote->getShippingAddress();
                 $request = new Varien_Object();
                 $request->setWebsiteId(Mage::helper('zitec_dpd/payment')->getWebsiteId());
                 $request->setDestCountryId($shippingAddress->getCountryId());
                 $request->setDestRegionId($shippingAddress->getRegionId());
                 $request->setDestPostcode($shippingAddress->getPostcode());
                 $request->setPackageWeight($shippingAddress->getWeight());
                 if ($this->_getTaxHelper()->shippingPriceIncludesTax($quote->getStoreId())) {
                     $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotalInclTax());
                 } else {
                     $request->setData('zitec_table_price', $shippingAddress->getBaseSubtotal());
                 }
                 $request->setMethod(str_replace(Mage::helper('zitec_dpd')->getDPDCarrierCode() . '_', '', $shippingAddress->getShippingMethod()));
                 $tablerateSurcharge = Mage::getResourceModel('zitec_dpd/carrier_tablerate')->getCashOnDeliverySurcharge($request);
                 if (is_null($tablerateSurcharge) || is_array($tablerateSurcharge) && is_null($tablerateSurcharge['cashondelivery_surcharge'])) {
                     return null;
                 } elseif (!empty($tablerateSurcharge)) {
                     $this->_surcharge = $this->_getHelper()->calculateQuoteBaseCashOnDeliverySurcharge($quote, $tablerateSurcharge);
                 } else {
                     $this->_surcharge = $this->_getHelper()->returnDefaultBaseCashOnDeliverySurcharge($quote);
                 }
             }
         }
     }
     return $this->_surcharge;
 }
Example #7
0
 /**
  * tests that the payment method is cleared before importing new data
  * following conditions must be met in order to get the method gets cleared:
  *      1. event must be sales_quote_payment_import_data_before
  *      2. payment must be an instance of Mage_Sales_Quote_Payment
  *
  */
 public function testClearPaymentMethodFromQuote()
 {
     $observer = Mage::getModel('ops/observer');
     $event = new Varien_Event_Observer();
     $payment = Mage::getModel('sales/quote_payment');
     $payment->setMethod('not relevant');
     $eventData = new Varien_Event();
     $event->setEvent($eventData);
     $event->getEvent()->setData('payment', $payment);
     // method is not cleared because of wring event
     $observer->clearPaymentMethodFromQuote($event);
     $this->assertEquals('not relevant', $event->getEvent()->getPayment()->getMethod());
     // method is cleared
     $event->setEventName('sales_quote_payment_import_data_before');
     $observer->clearPaymentMethodFromQuote($event);
     $this->assertEquals(null, $event->getEvent()->getPayment()->getMethod());
     // method is not cleared because the payment is not a Mage_Sales_Quote_Payment
     $payment = new Varien_Object();
     $payment->setMethod('not relevant');
     $event->getEvent()->setData('payment', $payment);
     $observer->clearPaymentMethodFromQuote($event);
     $this->assertEquals('not relevant', $event->getEvent()->getPayment()->getMethod());
 }