/** * charge money for recurring item */ protected function _checkoutRecurring() { /** @var Mage_Sales_Model_Order $order */ $order = Mage::getModel('sales/order'); $item = new Varien_Object($this->_recurringProfile->getOrderItemInfo()); $this->_price = $item->getBasePrice() * $item->getQty(); $additionalInfo = $this->_recurringProfile->getAdditionalInfo(); // check isset TrialBilling // Trial Billing Frequency <= 0 or isn't numeric => failure if ($this->_recurringProfile->getTrialBillingAmount() && $this->_recurringProfile->getTrialPeriodFrequency() && $this->_recurringProfile->getTrialPeriodMaxCycles() && $this->_recurringProfile->getTrialPeriodUnit() && (string) (int) $this->_recurringProfile->getTrialPeriodFrequency() === ltrim($this->_recurringProfile->getTrialPeriodFrequency(), '0') && (int) $this->_recurringProfile->getTrialPeriodFrequency() > 0) { $trialPeriodMaxCycles = (int) $this->_recurringProfile->getTrialPeriodMaxCycles(); if (!isset($additionalInfo['trialPeriodMaxCycles'])) { $additionalInfo['trialPeriodMaxCycles'] = $trialPeriodMaxCycles; $this->_recurringProfile->setAdditionalInfo($additionalInfo); $this->_price = $this->_recurringProfile->getTrialBillingAmount(); $this->_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL; } elseif (isset($additionalInfo['trialPeriodMaxCycles']) && $additionalInfo['trialPeriodMaxCycles'] > 0) { $this->_price = $this->_recurringProfile->getTrialBillingAmount(); $this->_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL; } } // calculate total amount $this->_shippingAmount = $item->getBaseShippingAmount(); $this->_taxAmount = $item->getBaseTaxAmount(); $this->_amount = $this->_price + $this->_shippingAmount + $this->_taxAmount; // init order /** @var Mage_Sales_Model_Order_Item $orderItem */ $orderItem = Mage::getModel('sales/order_item')->setName($item->getName())->setSku($item->getSku())->setDescription($item->getDescription())->setQtyOrdered($item->getQty())->setBasePrice($item->getBasePrice())->setBaseTaxAmount($item->getBaseTaxAmount())->setBaseRowTotalInclTax($item->getBaseRowTotalInclTax()); $order->addItem($orderItem); $shippingInfo = $this->_recurringProfile->getShippingAddressInfo(); $shippingAddress = Mage::getModel('sales/order_address')->setData($shippingInfo)->setId(null); // get base currency code $orderInfo = new Varien_Object($this->_recurringProfile->getOrderInfo()); $currencyCode = $orderInfo->getBaseCurrencyCode(); $order->setShippingAddress($shippingAddress); $order->setBaseCurrencyCode($currencyCode); /** @var Mage_Sales_Model_Order_Payment $payment */ $payment = Mage::getModel('sales/order_payment'); $payment->setOrder($order); $payment->setIsRecurring(true); $payment->setIsInitialFee(true); $customerId = $this->_recurringProfile->getCustomerId(); $payment->setCustomerId($customerId); $tokenId = $additionalInfo['token']['saved_token']; $payment->setTokenId($tokenId); /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */ $ewaySave = Mage::getModel('ewayrapid/method_saved'); $paymentAction = Mage::getStoreConfig('payment/ewayrapid_general/payment_action'); if ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) { $ewaySave->authorize($payment, $this->_amount); } elseif ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) { $ewaySave->capture($payment, $this->_amount); } if (!$payment->getTransactionId()) { throw new Exception('Transaction is not available'); } else { $this->_txdId = $payment->getTransactionId(); } /** @todo: change status of order = "eWAY Authorised" * now status order = "processing" */ }