/** * 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 }
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()); } }
/** * * @param Mage_Sales_Model_Recurring_Profile $profile * @param Allopass_Hipay_Model_Api_Response_Notification $response * @return Mage_Sales_Model_Order */ protected function createProfileOrder(Mage_Sales_Model_Recurring_Profile $profile, Allopass_Hipay_Model_Api_Response_Notification $response) { $amount = $this->getAmountFromProfile($profile); $productItemInfo = new Varien_Object(); $type = "Regular"; 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); } if ($this->isInitialProfileOrder($profile)) { // because is not additonned in prodile obj $productItemInfo->setPrice($profile->getBillingAmount() + $profile->getInitAmount()); } /* @var $order Mage_Sales_Model_Order */ $order = $profile->createOrder($productItemInfo); //$this->responseToPayment($order->getPayment(),$response); $additionalInfo = $profile->getAdditionalInfo(); $order->getPayment()->setCcType($additionalInfo['ccType']); $order->getPayment()->setCcExpMonth($additionalInfo['ccExpMonth']); $order->getPayment()->setCcExpYear($additionalInfo['ccExpYear']); $order->getPayment()->setAdditionalInformation('token', $additionalInfo['token']); $order->getPayment()->setAdditionalInformation('create_oneclick', $additionalInfo['create_oneclick']); $order->getPayment()->setAdditionalInformation('use_oneclick', $additionalInfo['use_oneclick']); //$order->getPayment()->setAdditionalInformation('selected_oneclick_card', $additionalInfo['selected_oneclick_card']); $order->setState(Mage_Sales_Model_Order::STATE_NEW, 'pending', Mage::helper('hipay')->__("New Order Recurring!")); $order->save(); $profile->addOrderRelation($order->getId()); $profile->save(); return $order; $order->getPayment()->registerCaptureNotification($amount); $order->save(); // notify customer if ($invoice = $order->getPayment()->getCreatedInvoice()) { $message = Mage::helper('hipay')->__('Notified customer about invoice #%s.', $invoice->getIncrementId()); $comment = $order->sendNewOrderEmail()->addStatusHistoryComment($message)->setIsCustomerNotified(true)->save(); /* Add this to send invoice to customer */ $invoice->setEmailSent(true); $invoice->save(); $invoice->sendEmail(); } return $order; }