*/ class Mage_Paypal_Model_Observer { /** * Goes to reports.paypal.com and fetches Settlement reports. * @return Mage_Paypal_Model_Observer */ public function fetchReports() { try { $reports = Mage::getModel('paypal/report_settlement'); /* @var $reports Mage_Paypal_Model_Report_Settlement */ $credentials = $reports->getSftpCredentials(true); foreach ($credentials as $config) { try { $reports->fetchAndSave($config); } catch (Exception $e) { Mage::logException($e); } } } catch (Exception $e) { Mage::logException($e); } } /** * Clean unfinished transaction * * @deprecated since 1.6.2.0 * @return Mage_Paypal_Model_Observer */ public function cleanTransactions() { return $this; } /** * Save order into registry to use it in the overloaded controller. * * @param Varien_Event_Observer $observer * @return Mage_Paypal_Model_Observer */ public function saveOrderAfterSubmit(Varien_Event_Observer $observer) { /* @var $order Mage_Sales_Model_Order */ $order = $observer->getEvent()->getData('order'); Mage::register('hss_order', $order, true); return $this; } /** * Set data for response of frontend saveOrder action * * @param Varien_Event_Observer $observer * @return Mage_Paypal_Model_Observer */ public function setResponseAfterSaveOrder(Varien_Event_Observer $observer) { /* @var $order Mage_Sales_Model_Order */ $order = Mage::registry('hss_order'); if ($order && $order->getId()) { $payment = $order->getPayment(); if ($payment && in_array($payment->getMethod(), Mage::helper('paypal/hss')->getHssMethods())) { /* @var $controller Mage_Core_Controller_Varien_Action */ $controller = $observer->getEvent()->getData('controller_action'); $result = Mage::helper('core')->jsonDecode( $controller->getResponse()->getBody('default'), Zend_Json::TYPE_ARRAY ); if (empty($result['error'])) { $controller->loadLayout('checkout_onepage_review'); $html = $controller->getLayout()->getBlock('paypal.iframe')->toHtml(); $result['update_section'] = array( 'name' => 'paypaliframe', 'html' => $html ); $result['redirect'] = false; $result['success'] = false; $controller->getResponse()->clearHeader('Location'); $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } } } return $this; } /** * Load country dependent PayPal solutions system configuration * * @param Varien_Event_Observer $observer * @return void */ public function loadCountryDependentSolutionsConfig(Varien_Event_Observer $observer) { $countryCode = Mage::helper('paypal')->getConfigurationCountryCode(); $paymentGroups = $observer->getEvent()->getConfig()->getNode('sections/payment/groups'); $paymentsConfigs = $paymentGroups->xpath('paypal_payments/*/backend_config/' . $countryCode); if ($paymentsConfigs) { foreach ($paymentsConfigs as $config) { $parent = $config->getParent()->getParent(); $parent->extend($config, true); } } $payments = $paymentGroups->xpath('paypal_payments/*'); foreach ($payments as $payment) { if ((int)$payment->include) { $fields = $paymentGroups->xpath((string)$payment->group . '/fields'); if (isset($fields[0])) { $fields[0]->appendChild($payment, true); } } } } /** * Update transaction with HTML representation of txn_id * * @param Varien_Event_Observer $observer */ public function observeHtmlTransactionId(Varien_Event_Observer $observer) { /** @var Varien_Object $transaction */ $transaction = $observer->getEvent()->getTransaction(); $transaction->setHtmlTxnId(Mage::helper('paypal')->getHtmlTransactionId( $observer->getEvent()->getPayment()->getMethodInstance()->getCode(), $transaction->getTxnId() )); } }