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
 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());
     }
 }