1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31:
32:
33: class Mage_Paypal_Model_Observer
34: {
35: 36: 37: 38:
39: public function fetchReports()
40: {
41: try {
42: $reports = Mage::getModel('paypal/report_settlement');
43:
44: $credentials = $reports->getSftpCredentials(true);
45: foreach ($credentials as $config) {
46: try {
47: $reports->fetchAndSave($config);
48: } catch (Exception $e) {
49: Mage::logException($e);
50: }
51: }
52: } catch (Exception $e) {
53: Mage::logException($e);
54: }
55: }
56:
57: 58: 59: 60: 61: 62:
63: public function cleanTransactions()
64: {
65: return $this;
66: }
67:
68: 69: 70: 71: 72: 73:
74: public function saveOrderAfterSubmit(Varien_Event_Observer $observer)
75: {
76:
77: $order = $observer->getEvent()->getData('order');
78: Mage::register('hss_order', $order, true);
79:
80: return $this;
81: }
82:
83: 84: 85: 86: 87: 88:
89: public function setResponseAfterSaveOrder(Varien_Event_Observer $observer)
90: {
91:
92: $order = Mage::registry('hss_order');
93:
94: if ($order && $order->getId()) {
95: $payment = $order->getPayment();
96: if ($payment && in_array($payment->getMethod(), Mage::helper('paypal/hss')->getHssMethods())) {
97:
98: $controller = $observer->getEvent()->getData('controller_action');
99: $result = Mage::helper('core')->jsonDecode(
100: $controller->getResponse()->getBody('default'),
101: Zend_Json::TYPE_ARRAY
102: );
103:
104: if (empty($result['error'])) {
105: $controller->loadLayout('checkout_onepage_review');
106: $html = $controller->getLayout()->getBlock('paypal.iframe')->toHtml();
107: $result['update_section'] = array(
108: 'name' => 'paypaliframe',
109: 'html' => $html
110: );
111: $result['redirect'] = false;
112: $result['success'] = false;
113: $controller->getResponse()->clearHeader('Location');
114: $controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
115: }
116: }
117: }
118:
119: return $this;
120: }
121:
122: 123: 124: 125: 126: 127:
128: public function loadCountryDependentSolutionsConfig(Varien_Event_Observer $observer)
129: {
130: $requestParam = Mage_Paypal_Block_Adminhtml_System_Config_Field_Country::REQUEST_PARAM_COUNTRY;
131: $countryCode = Mage::app()->getRequest()->getParam($requestParam);
132: if (is_null($countryCode) || preg_match('/^[a-zA-Z]{2}$/', $countryCode) == 0) {
133: $countryCode = (string)Mage::getSingleton('adminhtml/config_data')
134: ->getConfigDataValue('paypal/general/merchant_country');
135: }
136: if (empty($countryCode)) {
137: $countryCode = Mage::helper('core')->getDefaultCountry();
138: }
139:
140: $paymentGroups = $observer->getEvent()->getConfig()->getNode('sections/payment/groups');
141: $paymentsConfigs = $paymentGroups->xpath('paypal_payments/*/backend_config/' . $countryCode);
142: if ($paymentsConfigs) {
143: foreach ($paymentsConfigs as $config) {
144: $parent = $config->getParent()->getParent();
145: $parent->extend($config, true);
146: }
147: }
148:
149: $payments = $paymentGroups->xpath('paypal_payments/*');
150: foreach ($payments as $payment) {
151: if ((int)$payment->include) {
152: $fields = $paymentGroups->xpath((string)$payment->group . '/fields');
153: if (isset($fields[0])) {
154: $fields[0]->appendChild($payment, true);
155: }
156: }
157: }
158: }
159: }
160: