Example #1
0
 /**
  * Overwrite this method to copy custom fields values to orders created by recurring profile
  */
 protected function _registerRecurringProfilePaymentCapture()
 {
     $price = $this->getRequestData('mc_gross') - $this->getRequestData('tax') - $this->getRequestData('shipping');
     $productItemInfo = new Varien_Object();
     $type = trim($this->getRequestData('period_type'));
     if ($type == 'Trial') {
         $productItemInfo->setPaymentType(Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL);
     } elseif ($type == 'Regular') {
         $productItemInfo->setPaymentType(Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_REGULAR);
     }
     $productItemInfo->setTaxAmount($this->getRequestData('tax'));
     $productItemInfo->setShippingAmount($this->getRequestData('shipping'));
     $productItemInfo->setPrice($price);
     $order = $this->_recurringProfile->createOrder($productItemInfo);
     $payment = $order->getPayment();
     $payment->setTransactionId($this->getRequestData('txn_id'))->setPreparedMessage($this->_createIpnComment(''))->setIsTransactionClosed(0);
     $order->save();
     $this->_recurringProfile->addOrderRelation($order->getId());
     $payment->registerCaptureNotification($this->getRequestData('mc_gross'));
     $order->save();
     // notify customer
     if ($invoice = $payment->getCreatedInvoice()) {
         $message = Mage::helper('paypal')->__('Notified customer about invoice #%s.', $invoice->getIncrementId());
         $comment = $order->sendNewOrderEmail()->addStatusHistoryComment($message)->setIsCustomerNotified(true)->save();
     }
     //start aitoc modification
     Mage::getModel('aitcheckoutfields/aitcheckoutfields')->copyRecProfileFieldsToOrderFields($this->_recurringProfile->getId(), $order->getId());
     //end aitoc modification
 }
Example #2
0
 /**
  * Import totals information from google request to quote address
  *
  * @param Varien_Object $qAddress
  */
 protected function _importGoogleTotals($qAddress)
 {
     $quote = $qAddress->getQuote();
     $qAddress->setTaxAmount($this->_reCalculateToStoreCurrency($this->getData('root/order-adjustment/total-tax/VALUE'), $quote));
     $qAddress->setBaseTaxAmount($this->getData('root/order-adjustment/total-tax/VALUE'));
     $prefix = 'root/order-adjustment/shipping/';
     if ($shipping = $this->getData($prefix . 'carrier-calculated-shipping-adjustment')) {
         $method = 'googlecheckout_carrier';
     } elseif ($shipping = $this->getData($prefix . 'merchant-calculated-shipping-adjustment')) {
         $method = 'googlecheckout_merchant';
     } elseif ($shipping = $this->getData($prefix . 'flat-rate-shipping-adjustment')) {
         $method = 'googlecheckout_flatrate';
     } elseif ($shipping = $this->getData($prefix . 'pickup-shipping-adjustment')) {
         $method = 'googlecheckout_pickup';
     }
     if (!empty($method)) {
         Mage::getSingleton('tax/config')->setShippingPriceIncludeTax(false);
         $rate = Mage::getModel('sales/quote_address_rate')->setCode($method)->setPrice($shipping['shipping-cost']['VALUE']);
         $qAddress->addShippingRate($rate)->setShippingMethod($method)->setShippingDescription($shipping['shipping-name']['VALUE']);
         /*if (!Mage::helper('tax')->shippingPriceIncludesTax($quote->getStore())) {
               $includingTax = Mage::helper('tax')->getShippingPrice($excludingTax, true, $qAddress, $quote->getCustomerTaxClassId());
               $shippingTax = $includingTax - $excludingTax;
               $qAddress->setShippingTaxAmount($this->_reCalculateToStoreCurrency($shippingTax, $quote))
                   ->setBaseShippingTaxAmount($shippingTax)
                   ->setShippingInclTax($includingTax)
                   ->setBaseShippingInclTax($this->_reCalculateToStoreCurrency($includingTax, $quote));
           } else {
               if ($method == 'googlecheckout_carrier') {
                   $qAddress->setShippingTaxAmount(0)
                       ->setBaseShippingTaxAmount(0);
               }
           }*/
     } else {
         $qAddress->setShippingMethod(null);
     }
     $qAddress->setGrandTotal($this->_reCalculateToStoreCurrency($this->getData('root/order-total/VALUE'), $quote));
     $qAddress->setBaseGrandTotal($this->getData('root/order-total/VALUE'));
 }
Example #3
0
 /**
  * Import totals information from google request to quote address
  *
  * @param Varien_Object $qAddress
  */
 protected function _importGoogleTotals($qAddress)
 {
     $quote = $qAddress->getQuote();
     $qAddress->setTaxAmount($this->_reCalculateToStoreCurrency($this->getData('root/order-adjustment/total-tax/VALUE'), $quote));
     $qAddress->setBaseTaxAmount($this->getData('root/order-adjustment/total-tax/VALUE'));
     $method = null;
     $prefix = 'root/order-adjustment/shipping/';
     if (null !== ($shipping = $this->getData($prefix . 'carrier-calculated-shipping-adjustment'))) {
         $method = 'googlecheckout_carrier';
     } else {
         if (null !== ($shipping = $this->getData($prefix . 'merchant-calculated-shipping-adjustment'))) {
             $method = $this->_getShippingMethodByName($shipping['shipping-name']['VALUE']);
             if ($method === false) {
                 $method = 'googlecheckout_merchant';
             }
         } else {
             if (null !== ($shipping = $this->getData($prefix . 'flat-rate-shipping-adjustment'))) {
                 $method = 'googlecheckout_flatrate';
             } else {
                 if (null !== ($shipping = $this->getData($prefix . 'pickup-shipping-adjustment'))) {
                     $method = 'googlecheckout_pickup';
                 }
             }
         }
     }
     if ($method) {
         Mage::getSingleton('Mage_Tax_Model_Config')->setShippingPriceIncludeTax(false);
         $rate = $this->_createShippingRate($method)->setMethodTitle($shipping['shipping-name']['VALUE'])->setPrice($shipping['shipping-cost']['VALUE']);
         $qAddress->addShippingRate($rate)->setShippingMethod($method)->setShippingDescription($shipping['shipping-name']['VALUE']);
         // We get from Google price with discounts applied via merchant calculations
         $qAddress->setShippingAmountForDiscount(0);
         /*if (!Mage::helper('Mage_Tax_Helper_Data')->shippingPriceIncludesTax($quote->getStore())) {
               $includingTax = Mage::helper('Mage_Tax_Helper_Data')->getShippingPrice(
                   $excludingTax, true, $qAddress, $quote->getCustomerTaxClassId()
               );
               $shippingTax = $includingTax - $excludingTax;
               $qAddress->setShippingTaxAmount($this->_reCalculateToStoreCurrency($shippingTax, $quote))
                   ->setBaseShippingTaxAmount($shippingTax)
                   ->setShippingInclTax($includingTax)
                   ->setBaseShippingInclTax($this->_reCalculateToStoreCurrency($includingTax, $quote));
           } else {
               if ($method == 'googlecheckout_carrier') {
                   $qAddress->setShippingTaxAmount(0)
                       ->setBaseShippingTaxAmount(0);
               }
           }*/
     } else {
         $qAddress->setShippingMethod(null);
     }
     $qAddress->setGrandTotal($this->_reCalculateToStoreCurrency($this->getData('root/order-total/VALUE'), $quote));
     $qAddress->setBaseGrandTotal($this->getData('root/order-total/VALUE'));
 }
Example #4
0
 protected function _registerRecurringProfilePaymentCapture()
 {
     $price = $this->getRequestData('mc_gross') - $this->getRequestData('tax') - $this->getRequestData('shipping');
     $productItemInfo = new Varien_Object();
     $type = trim($this->getRequestData('period_type'));
     if ($type == 'Trial') {
         $productItemInfo->setPaymentType(Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL);
     } elseif ($type == 'Regular') {
         $productItemInfo->setPaymentType(Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_REGULAR);
     }
     $productItemInfo->setTaxAmount($this->getRequestData('tax'));
     $productItemInfo->setShippingAmount($this->getRequestData('shipping'));
     $productItemInfo->setPrice($price);
     $order = $this->_recurringProfile->createOrder($productItemInfo);
     $payment = $order->getPayment();
     $payment->setTransactionId($this->getRequestData('txn_id'))->setPreparedMessage($this->_createIpnComment(''))->setIsTransactionClosed(0);
     $order->save();
     $this->_recurringProfile->addOrderRelation($order->getId());
     $payment->registerCaptureNotification($this->getRequestData('mc_gross'));
     $order->save();
     /*----------- add by KK --------*/
     $profile = $this->_recurringProfile;
     $plugin = Mage::helper('usermanagement/plugin')->load($profile->getId(), 'profile_id');
     $oldExpiredTime = $plugin->getExpiredTime();
     if ($type == 'Trial') {
         $trialPeriodUnit = $profile->getTrialPeriodUnit();
         $trialPeriodFrequency = $profile->getTrialPeriodFrequency();
         switch ($trialPeriodUnit) {
             case 'day':
                 $expiredTime = strtotime("+{$trialPeriodFrequency} day", strtotime($oldExpiredTime));
                 break;
             case 'week':
                 $expiredTime = strtotime("+{$trialPeriodFrequency} week", strtotime($oldExpiredTime));
                 break;
             case 'semi_month':
                 $df = $trialPeriodFrequency * 2;
                 $expiredTime = strtotime("+{$df} week", strtotime($oldExpiredTime));
                 break;
             case 'month':
                 $expiredTime = strtotime("+{$trialPeriodFrequency} month", strtotime($oldExpiredTime));
                 break;
             case 'year':
                 $expiredTime = strtotime("+{$trialPeriodFrequency} year", strtotime($oldExpiredTime));
                 break;
         }
     } elseif ($type == 'Regular') {
         $periodUnit = $recurringProfile->getPeriodUnit();
         $periodFrequency = $recurringProfile->getPeriodFrequency();
         switch ($periodUnit) {
             case 'day':
                 $expiredTime = strtotime("+{$periodFrequency} day", strtotime($oldExpiredTime));
                 break;
             case 'week':
                 $expiredTime = strtotime("+{$periodFrequency} week", strtotime($oldExpiredTime));
                 break;
             case 'semi_month':
                 $df = $periodFrequency * 2;
                 $expiredTime = strtotime("+{$df} week", strtotime($oldExpiredTime));
                 break;
             case 'month':
                 $expiredTime = strtotime("+{$periodFrequency} month", strtotime($oldExpiredTime));
                 break;
             case 'year':
                 $expiredTime = strtotime("+{$periodFrequency} year", strtotime($oldExpiredTime));
                 break;
         }
         $plugin->setStatus(Simicart_UserManagement_Model_Plugin::STATUS_ENABLED);
     }
     $plugin->setExpiredTime($expiredTime);
     try {
         $plugin->save();
     } catch (Exception $e) {
     }
     /*--------------end-------------*/
     $invoice = $payment->getCreatedInvoice();
     if ($invoice) {
         // notify customer
         $message = Mage::helper('paypal')->__('Notified customer about invoice #%s.', $invoice->getIncrementId());
         $order->sendNewOrderEmail()->addStatusHistoryComment($message)->setIsCustomerNotified(true)->save();
     }
 }
 /**
  * Register recurring payment notification, create and process order
  */
 protected function _registerRecurringProfilePaymentCapture()
 {
     $price = $this->_price;
     $tax = $this->_taxAmount;
     $shipping = $this->_shippingAmount;
     $grandTotal = $this->_amount;
     $periodType = $this->_periodType;
     $transactionId = $this->_txdId;
     $ewayMessage = '';
     $productItemInfo = new Varien_Object();
     /** @todo: response doesn't contain period type / payment type */
     $productItemInfo->setPaymentType($periodType);
     $productItemInfo->setTaxAmount($tax);
     $productItemInfo->setShippingAmount($shipping);
     $productItemInfo->setPrice($price);
     /** @var Mage_Sales_Model_Recurring_Profile $recurringProfile */
     $recurringProfile = $this->_recurringProfile;
     $order = $recurringProfile->createOrder($productItemInfo);
     $payment = $order->getPayment();
     $payment->setTransactionId($transactionId)->setPreparedMessage($ewayMessage)->setIsTransactionClosed(0);
     $order->save();
     $this->_recurringProfile->addOrderRelation($order->getId());
     $payment->registerCaptureNotification($grandTotal);
     $order->save();
     // notify customer
     if ($invoice = $payment->getCreatedInvoice()) {
         $message = Mage::helper('paypal')->__('Notified customer about invoice #%s.', $invoice->getIncrementId());
         $comment = $order->sendNewOrderEmail()->addStatusHistoryComment($message)->setIsCustomerNotified(true)->save();
     }
     if (!$recurringProfile->getIsCronJob()) {
         $session = Mage::getSingleton('checkout/type_onepage')->getCheckout();
         $session->setLastOrderId($order->getId());
     }
 }
 public function extractRefundLine($order, $amount)
 {
     $_extract = new Varien_Object();
     $_extract->setName('Refund / Correction');
     $_extract->setPrice($amount);
     $_extract->setTaxAmount(0);
     $_extract->setQtyOrdered(1);
     return $_extract;
 }