1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: class Phoenix_Moneybookers_Helper_Data extends Mage_Payment_Helper_Data
21: {
22: const XML_PATH_EMAIL = 'moneybookers/settings/moneybookers_email';
23: const XML_PATH_CUSTOMER_ID = 'moneybookers/settings/customer_id';
24: const XML_PATH_SECRET_KEY = 'moneybookers/settings/secret_key';
25:
26: 27: 28:
29: protected = 'https://www.moneybookers.com';
30: protected $_checkEmailUrl = '/app/email_check.pl';
31: protected $_checkEmailCustId = '6999315';
32: protected $_checkEmailPassword = 'a4ce5a98a8950c04a3d34a2e2cb8c89f';
33: protected $_checkSecretUrl = '/app/secret_word_check.pl';
34: protected $_activationEmailTo = 'ecommerce@moneybookers.com';
35: protected $_activationEmailSubject = 'Magento Moneybookers Activation';
36: protected $_moneybookersMasterCustId = '7283403';
37: protected $_moneybookersMasterSecretHash = 'c18524b6b1082653039078a4700367f0';
38:
39: 40: 41:
42: public function activateEmail()
43: {
44: $storeId = Mage::app()->getStore()->getId();
45:
46: $translate = Mage::getSingleton('core/translate');
47:
48: $translate->setTranslateInline(false);
49:
50: Mage::getModel('core/email_template')
51: ->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))
52: ->sendTransactional(
53: 'moneybookers_activateemail',
54: Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_IDENTITY, $storeId),
55: $this->_activationEmailTo,
56: null,
57: array(
58: 'subject' => $this->_activationEmailSubject,
59: 'email_addr' => Mage::getStoreConfig(self::XML_PATH_EMAIL),
60: 'url' => Mage::getBaseUrl(),
61: 'customer_id' => Mage::getStoreConfig(self::XML_PATH_CUSTOMER_ID),
62: 'language' => Mage::getModel('core/locale')->getDefaultLocale()
63: )
64: );
65:
66: $translate->setTranslateInline(true);
67: }
68:
69: 70: 71: 72: 73: 74:
75: public function checkEmailRequest(Array $params) {
76: $response = null;
77: try {
78: $response = $this->_getHttpsPage($this->_moneybookersServer . $this->_checkEmailUrl, array(
79: 'email' => $params['email'],
80: 'cust_id' => $this->_checkEmailCustId,
81: 'password' => $this->_checkEmailPassword)
82: );
83: } catch (Exception $e) {
84: Mage::log($e->getMessage());
85: return null;
86: }
87: return $response;
88: }
89:
90: 91: 92: 93: 94:
95: public function checkSecretRequest(Array $params)
96: {
97: $response = null;
98: try {
99: $response = $this->_getHttpsPage($this->_moneybookersServer . $this->_checkSecretUrl, array(
100: 'email' => $params['email'],
101: 'secret' => md5(md5($params['secret']) . $this->_moneybookersMasterSecretHash),
102: 'cust_id' => $this->_moneybookersMasterCustId)
103: );
104: } catch (Exception $e) {
105: Mage::log($e->getMessage());
106: return null;
107: }
108: return $response;
109: }
110:
111: 112: 113:
114: protected function _getHttpsPage($host, $parameter)
115: {
116: $client = new Varien_Http_Client();
117: $client->setUri($host)
118: ->setConfig(array('timeout' => 30))
119: ->setHeaders('accept-encoding', '')
120: ->setParameterGet($parameter)
121: ->setMethod(Zend_Http_Client::GET);
122: $request = $client->request();
123:
124:
125: if (!preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", $request->getRawBody(), $m))
126: return $request->getRawBody();
127:
128: return $request->getBody();
129: }
130: }
131: