_invoiceInstance) { $this->_invoiceInstance = Mage::registry('order_item'); if (!$this->_invoiceInstance) { Mage::throwException($this->__('Orders instance does not exist in Registry')); } } return $this->_invoiceInstance; } public function getSubmitForm($invoiceInfo) { return $this->createForm($invoiceInfo); } protected function createForm($invoiceInfo) { $isSandBoxOn = false; $payments = Mage::getSingleton('payment/config')->getActiveMethods(); foreach ($payments as $paymentCode => $paymentModel) { $isSandBoxOn = Mage::getStoreConfig('payment/' . $paymentCode . '/sandbox_flag') == 1 ? true : $isSandBoxOn; } $PayPalUrl = $isSandBoxOn == false ? 'https://www.paypal.com/cgi-bin/webscr' : 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay'; $form = new Zend_Form(); $form->setAction($PayPalUrl); $form->setAttrib('id', 'payPal_form'); $form->addElement('hidden', 'cmd', array('value' => '_xclick')); $form->addElement('hidden', 'business', array('value' => Mage::getStoreConfig('paypal/general/business_account'))); $form->addElement('hidden', 'notify_url', array('value' => Mage::getUrl('custom_invoice/index/ipn', array('_secure' => false)))); $form->addElement('hidden', 'return', array('value' => Mage::getUrl(Mage::getStoreConfig('custominvoice_section/main_group/cms_pages')))); $form->addElement('hidden', 'currency_code', array('value' => Mage::app()->getStore()->getCurrentCurrencyCode())); foreach ($invoiceInfo as $field => $value) { $form->addElement('hidden', $field, array('value' => $value)); } $form->addElement('submit', 'submit', array('label' => 'Proceed to Checkout', 'attribs' => array('class' => 'btn')) ); $form->setAttrib('name', 'payPalForm'); $form->removeDecorator('HtmlTag'); foreach ($form->getElements() as $element) { /** @var Zend_Form_Element $element */ $element->removeDecorator('HtmlTag'); $element->removeDecorator('Label'); } return $form; } public function createNewInvoice($alias) { /** @var $orderModel Orange35_CustomInvoicesGenerator_Model_Order */ $orderModel = Mage::getModel('orange35_custominvoicesgenerator/order'); $orderModel->load($alias, 'alias'); /** @var $invoiceModel Orange35_CustomInvoicesGenerator_Model_Invoice */ $invoiceModel = Mage::getModel('orange35_custominvoicesgenerator/invoice'); $invoiceModel->addData(array('order_id' => $orderModel->getId(),)); $invoiceModel->save(); return strtotime($invoiceModel->getDate()); } public function processPayment($form) { /** @var $form Zend_Form */ $view = new Zend_View(); $html = '' . '
' . 'You can not be automatically forwarded. To continue, press the "Proceed to Checkout" button
' . ' ' . $form->render($view) . ' ' . '' . ''; die($html); } public function sendAdminNotifications($invoice, $order) { $this->_sendAdminNotifications($invoice, $order); } protected function _sendAdminNotifications($invoice, $order) { /** @var $invoice Orange35_CustomInvoicesGenerator_Model_Invoice */ /** @var $order Orange35_CustomInvoicesGenerator_Model_Order */ $storeId = Mage::app()->getStore()->getStoreId(); $adminMail = Mage::getStoreConfig('custominvoice_section/main_group/admin_mail'); $adminMail = $adminMail ? $adminMail : Mage::getStoreConfig('trans_email/ident_general/email', $storeId); $params = array( 'store' => Mage::app()->getStore(), 'invoice' => $invoice, 'order' => $order, ); $template = Mage::getModel('core/email_template')->loadDefault(self::MAIL_TEMPLATE); $template->setSenderEmail(Mage::getStoreConfig(self::STORE_SENDER_EMAIL_PATH, $storeId)); $template->setSenderName(Mage::getStoreConfig(self::STORE_SENDER_NAME_PATH, $storeId)); $template->setTemplateSubject('New Custom Invoice Payment Received'); $template->send($adminMail, '', $params); return $this; } }