multon_everypay - Version 1.1.0

Version Notes

1.1.0
Converted to stand-alone community extension

1.0.6
Description and contact info

1.0.5
API protocol update: separated fail/cancelled transaction status

1.0.4
API protocol update

1.0.3
add account id

1.0.2
FIX: return url
FIX: return verification
new gateway url

1.0.1
FIX: redirect template

1.0.0
Stable release

Download this release

Release Info

Developer Multon
Extension multon_everypay
Version 1.1.0
Comparing to
See all releases


Version 1.1.0

app/code/community/Multon/Everypay/Block/Adminhtml/Fieldset.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @author Tanel Raja <tanel.raja@multon.ee>
4
+ * @copyright Copyright (c) 2014, Multon (http://multon.ee/)
5
+ */
6
+ class Multon_Everypay_Block_Adminhtml_Fieldset extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
7
+ {
8
+
9
+ protected function _getHeaderTitleHtml($element)
10
+ {
11
+ $element->setLegend('<img style="position: relative; top: 2px; margin-right: 5px;" src="' .
12
+ Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) .
13
+ 'adminhtml/default/default/images/everypay-logo.jpg" />' .
14
+ $element->getLegend()
15
+ );
16
+ return parent::_getHeaderTitleHtml($element);
17
+ }
18
+
19
+ }
app/code/community/Multon/Everypay/Block/Adminhtml/System/Config/Intro.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Multon_Everypay_Block_Adminhtml_System_Config_Intro extends Mage_Adminhtml_Block_Abstract
4
+ implements Varien_Data_Form_Element_Renderer_Interface
5
+ {
6
+
7
+ /**
8
+ * Render element html
9
+ *
10
+ * @param Varien_Data_Form_Element_Abstract $element
11
+ * @return string
12
+ */
13
+ public function render(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ return '<tr><td colspan="5"><p>EveryPay is a card payment gateway service provider, '
16
+ . 'enabling e-commerce merchants to collect credit and debit card online payments '
17
+ . 'from their customers.</p>'
18
+ . '<p>EveryPay, Hõbeda 6, 10125 Tallinn, Estonia</p>'
19
+ . '<a href="https://every-pay.com/contact">https://every-pay.com/contact</a></td></tr>';
20
+ }
21
+
22
+ }
app/code/community/Multon/Everypay/Block/Adminhtml/System/Config/Outro.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Multon_Everypay_Block_Adminhtml_System_Config_Outro extends Mage_Adminhtml_Block_Abstract
4
+ implements Varien_Data_Form_Element_Renderer_Interface
5
+ {
6
+
7
+ /**
8
+ * Render element html
9
+ *
10
+ * @param Varien_Data_Form_Element_Abstract $element
11
+ * @return string
12
+ */
13
+ public function render(Varien_Data_Form_Element_Abstract $element)
14
+ {
15
+ return '<tr><td colspan="5"><p>For further information please refer to the documentation or get in touch with us:</p>'
16
+ . '<a href="https://every-pay.com/documentation">https://every-pay.com/documentation</a><br>'
17
+ . '<a href="https://every-pay.com/contact">https://every-pay.com/contact</a></td></tr>';
18
+ }
19
+
20
+ }
app/code/community/Multon/Everypay/Block/Adminhtml/System/Config/Version.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Multon_Everypay_Block_Adminhtml_System_Config_Version
4
+ extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
5
+ {
6
+ /**
7
+ * Render element html
8
+ *
9
+ * @param Varien_Data_Form_Element_Abstract $element
10
+ * @return string
11
+ */
12
+ public function render(Varien_Data_Form_Element_Abstract $element)
13
+ {
14
+ $html = sprintf('<tr class="system-fieldset-sub-head" id="row_%s"><td colspan="5"><h4 id="%s">%s</h4></td></tr>',
15
+ $element->getHtmlId(), $element->getHtmlId(), $element->getLabel()
16
+ );
17
+ $html .= '<tr><td colspan="5">Everypay module version: '.Mage::getConfig()->getModuleConfig('Multon_Everypay')->version.'</td></tr>';
18
+
19
+ return $html;
20
+ }
21
+ }
app/code/community/Multon/Everypay/Block/Everypay.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Multon_Everypay_Block_Everypay extends Mage_Payment_Block_Form
4
+ {
5
+ protected $_code = 'multon_everypay';
6
+ protected $_gateway = 'everypay';
7
+
8
+ protected function getReturnUrl()
9
+ {
10
+ return Mage::getUrl('everypay/everypay/return');
11
+ }
12
+
13
+ /**
14
+ * Returns payment gateway URL
15
+ *
16
+ * @return string Gateway URL
17
+ */
18
+ public function getGatewayUrl()
19
+ {
20
+ return Mage::getStoreConfig('payment/' . $this->_code . '/gateway_url');
21
+ }
22
+
23
+ /**
24
+ * Returns payment method logo URL
25
+ *
26
+ * @return string
27
+ */
28
+ public function getMethodLogoUrl()
29
+ {
30
+ return $this->getSkinUrl('images/multon/everypay/mastercard_visa_acceptance.jpg');
31
+ }
32
+
33
+ /**
34
+ * Adds payment mehtod logotypes after method name
35
+ *
36
+ * @return string
37
+ */
38
+ public function getMethodLabelAfterHtml()
39
+ {
40
+ if (Mage::getStoreConfig('payment/' . $this->_code . '/hide_logo'))
41
+ return '';
42
+
43
+ $blockHtml = sprintf(
44
+ '<img src="%1$s"
45
+ title="%2$s"
46
+ alt="%2$s"
47
+ class="payment-method-logo"/>',
48
+ $this->getMethodLogoUrl(), ucfirst($this->_gateway)
49
+ );
50
+ return $blockHtml;
51
+ }
52
+
53
+ /**
54
+ * Checks if quick redirect is enabled and
55
+ * returns javascript block that redirects user
56
+ * to bank without intermediate page
57
+ *
58
+ * @return outstr Javascript block
59
+ */
60
+ public function getQuickRedirectScript()
61
+ {
62
+ $outstr = '';
63
+ if (Mage::getStoreConfig('payment/' . $this->_code . '/quick_redirect'))
64
+ {
65
+ $outstr = '<script type="text/javascript"><!--
66
+ if($("GatewayForm")){$("GatewayForm").submit();}
67
+ //--></script>';
68
+ }
69
+ return $outstr;
70
+ }
71
+
72
+ /**
73
+ * Populates and returns array of fields to be submitted
74
+ * to a bank for payment
75
+ *
76
+ * @return Array
77
+ */
78
+ public function getFields()
79
+ {
80
+ $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
81
+ $order = Mage::getModel('sales/order')->load($orderId);
82
+ /* @var $order Mage_Sales_Model_Order */
83
+ switch (Mage::app()->getLocale()->getLocaleCode())
84
+ {
85
+ case 'et_EE':
86
+ $language = 'et';
87
+ break;
88
+ case 'ru_RU':
89
+ $language = 'ru';
90
+ break;
91
+ default:
92
+ $language = 'en';
93
+ break;
94
+ }
95
+
96
+ $billing = $order->getBillingAddress();
97
+ $shipping = $order->getShippingAddress();
98
+
99
+ $fields = array(
100
+ 'account_id' => Mage::getStoreConfig('payment/' . $this->_code . '/account_id'),
101
+ 'amount' => number_format($order->getTotalDue(), 2, '.', ''),
102
+ 'api_username' => Mage::getStoreConfig('payment/' . $this->_code . '/api_username'),
103
+ 'billing_address' => $billing->getStreetFull(),
104
+ 'billing_city' => $billing->getCity(),
105
+ 'billing_country' => $billing->getCountry(),
106
+ 'billing_postcode' => $billing->getPostcode(),
107
+ 'callback_url' => $this->getReturnUrl(),
108
+ 'customer_url' => $this->getReturnUrl(),
109
+ 'delivery_address' => $shipping->getStreetFull(),
110
+ 'delivery_city' => $shipping->getCity(),
111
+ 'delivery_country' => $shipping->getCountry(),
112
+ 'delivery_postcode' => $shipping->getPostcode(),
113
+ 'email' => $billing->getEmail(),
114
+ 'nonce' => $this->getNonce(),
115
+ 'order_reference' => $order->getIncrementId(),
116
+ 'timestamp' => time(),
117
+ 'transaction_type' => Mage::getStoreConfig('payment/' . $this->_code . '/transaction_type'),
118
+ 'user_ip' => $_SERVER['REMOTE_ADDR'],
119
+ );
120
+
121
+ $fields['hmac'] = $this->signData($this->prepareData($fields));
122
+ $fields['locale'] = $language;
123
+
124
+ // Mage::log(print_r($fields, 1), null, $this->logFile);
125
+
126
+ return $fields;
127
+ }
128
+
129
+ protected function getNonce()
130
+ {
131
+ while (1)
132
+ {
133
+ $nonce = uniqid(true);
134
+ $r = Mage::getSingleton('core/resource')
135
+ ->getConnection('read_connection')
136
+ ->query('select nonce from everypay_nonce where nonce=\'' . $nonce . '\'')
137
+ ->fetchAll();
138
+ if (!count($r))
139
+ {
140
+ $r = Mage::getSingleton('core/resource')
141
+ ->getConnection('write_connection')
142
+ ->insert('everypay_nonce', array('nonce' => $nonce))
143
+ ;
144
+ break;
145
+ }
146
+ }
147
+ return $nonce;
148
+ }
149
+
150
+ /**
151
+ * Prepare data package for signing
152
+ *
153
+ * @param array $fields
154
+ * @return string
155
+ */
156
+ protected function prepareData(array $fields)
157
+ {
158
+ $arr = array();
159
+ foreach ($fields as $k => $v)
160
+ {
161
+ $arr[] = $k . '=' . $v;
162
+ }
163
+ return implode('&', $arr);
164
+ }
165
+
166
+ protected function signData($data)
167
+ {
168
+ return hash_hmac('sha1', $data, Mage::getStoreConfig('payment/' . $this->_code . '/api_secret'));
169
+ }
170
+
171
+ }
app/code/community/Multon/Everypay/Block/Info.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Multon_Everypay_Block_Info extends Mage_Core_Block_Template
4
+ {
5
+
6
+ public function getEnabledGateways()
7
+ {
8
+ $methods = array();
9
+ if (Mage::getStoreConfig('payment/multon_everypay/active'))
10
+ {
11
+ $paymentModel = Mage::getModel('everypay/everypay');
12
+ $paymentTitle = Mage::getStoreConfig('payment/multon_everypay/title');
13
+ $formBlockType = $paymentModel->getFormBlockType();
14
+ $formBlockInstance = Mage::getBlockSingleton($formBlockType);
15
+ $methods[] = array(
16
+ 'title' => $paymentTitle,
17
+ 'code' => $paymentModel->getCode(),
18
+ 'logo' => $formBlockInstance->getMethodLogoUrl()
19
+ );
20
+ }
21
+ return $methods;
22
+ }
23
+
24
+ }
app/code/community/Multon/Everypay/Model/Everypay.php ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Multon_Everypay_Model_Everypay extends Mage_Payment_Model_Method_Abstract
4
+ {
5
+ const _VERIFY_SUCCESS = 1; // payment successful
6
+ const _VERIFY_CANCEL = 2; // payment unsuccessful
7
+ const _VERIFY_CORRUPT = 3; // wrong or corrupt response
8
+
9
+ protected $_canAuthorize = true;
10
+ protected $_isGateway = true;
11
+ protected $_canUseCheckout = true;
12
+ protected $logFile = 'everypay.log';
13
+
14
+ /**
15
+ * Order Id to create invoice for
16
+ * @var string
17
+ */
18
+ protected $_orderId;
19
+
20
+ protected $_code = 'multon_everypay';
21
+ protected $_formBlockType = 'everypay/everypay';
22
+ private $statuses = array(
23
+ 'completed' => self::_VERIFY_SUCCESS,
24
+ 'failed' => self::_VERIFY_CANCEL,
25
+ 'cancelled' => self::_VERIFY_CANCEL,
26
+ );
27
+
28
+ public function getOrderPlaceRedirectUrl()
29
+ {
30
+ return Mage::getUrl('everypay/everypay/redirect');
31
+ }
32
+
33
+ /**
34
+ * Verifies response from Everypay
35
+ *
36
+ * @param array $params Response sent by bank and to be verified
37
+ *
38
+ * @return int
39
+ */
40
+ public function verify(array $params = array())
41
+ {
42
+ // only in automatic callback message
43
+ if (isset($params['processing_errors']))
44
+ {
45
+ $errors = json_decode($params['processing_errors']);
46
+ if (!empty($errors))
47
+ $this->log('(Everypay) Errors: ' . print_r($errors, 1), __METHOD__, __LINE__);
48
+ }
49
+ if (isset($params['processing_warnings']))
50
+ {
51
+ $warnings = json_decode($params['processing_warnings']);
52
+ if (!empty($warnings))
53
+ $this->log('(Everypay) Warnings: ' . print_r($warnings, 1), __METHOD__, __LINE__);
54
+ }
55
+
56
+ if (!isset($params['api_username']) || ($params['api_username'] !== Mage::getStoreConfig('payment/' . $this->_code . '/api_username')))
57
+ {
58
+ $this->log('(Everypay) Invalid username', __METHOD__, __LINE__);
59
+ Mage::getSingleton('checkout/session')->addError('Invalid username.');
60
+ return self::_VERIFY_CORRUPT;
61
+ }
62
+
63
+ $now = time();
64
+ if (($params['timestamp'] > $now) || ($params['timestamp'] < ($now - 300)))
65
+ {
66
+ $this->log('(Everypay) Response outdated (now: ' . $now . ', age: ' . ($now - $params['timestamp']) . ')', __METHOD__, __LINE__);
67
+ Mage::getSingleton('checkout/session')->addError('Response outdated.');
68
+ return self::_VERIFY_CORRUPT;
69
+ }
70
+
71
+ $session = Mage::getSingleton('checkout/session');
72
+ // Reference number doesn't match.
73
+ if ($session->getLastRealOrderId() != $params['order_reference'])
74
+ {
75
+ $this->log('(Everypay): Order number doesn\'t match (potential tampering attempt).', __METHOD__, __LINE__);
76
+ Mage::getSingleton('checkout/session')->addError('Order number error.');
77
+ return self::_VERIFY_CORRUPT;
78
+ }
79
+
80
+ if (!$this->verifyNonce($params['nonce']))
81
+ {
82
+ $this->log('(Everypay): Nonce already used.', __METHOD__, __LINE__);
83
+ Mage::getSingleton('checkout/session')->addError('Nonce already used.');
84
+ return self::_VERIFY_CORRUPT;
85
+ }
86
+
87
+ $status = $this->statuses[$params['transaction_result']];
88
+ switch ($params['transaction_result'])
89
+ {
90
+ case 'completed':
91
+ case 'failed':
92
+ if ($params['account_id'] !== Mage::getStoreConfig('payment/' . $this->_code . '/account_id'))
93
+ {
94
+ $this->log('(Everypay) Invalid account ID', __METHOD__, __LINE__);
95
+ Mage::getSingleton('checkout/session')->addError('Invalid account.');
96
+ return self::_VERIFY_CORRUPT;
97
+ }
98
+
99
+ $data = 'account_id=' . $params['account_id'] . '&' .
100
+ 'amount=' . $params['amount'] . '&' .
101
+ 'api_username=' . $params['api_username'] . '&' .
102
+ 'nonce=' . $params['nonce'] . '&' .
103
+ 'order_reference=' . $params['order_reference'] . '&' .
104
+ 'payment_reference=' . $params['payment_reference'] . '&' .
105
+ 'payment_state=' . $params['payment_state'] . '&';
106
+ if (isset($params['processing_errors']))
107
+ {
108
+ $data .= 'processing_errors=' . $params['processing_errors'] . '&' .
109
+ 'processing_warnings=' . $params['processing_warnings'] . '&';
110
+ }
111
+ $data .= 'timestamp=' . $params['timestamp'] . '&' .
112
+ 'transaction_result=' . $params['transaction_result'];
113
+ break;
114
+ case 'cancelled':
115
+ $data = 'api_username=' . $params['api_username'] . '&' .
116
+ 'nonce=' . $params['nonce'] . '&' .
117
+ 'order_reference=' . $params['order_reference'] . '&' .
118
+ 'payment_state=' . $params['payment_state'] . '&' .
119
+ 'timestamp=' . $params['timestamp'] . '&' .
120
+ 'transaction_result=' . $params['transaction_result'];
121
+ break;
122
+ }
123
+ $hmac = hash_hmac('sha1', $data, Mage::getStoreConfig('payment/' . $this->_code . '/api_secret'));
124
+ if ($params['hmac'] != $hmac)
125
+ {
126
+ $this->log('(Everypay) Invalid HMAC', __METHOD__, __LINE__);
127
+ Mage::getSingleton('checkout/session')->addError('Invalid HMAC.');
128
+ return self::_VERIFY_CORRUPT;
129
+ }
130
+
131
+ return $status;
132
+ }
133
+
134
+ protected function verifyNonce($nonce)
135
+ {
136
+ $r = Mage::getSingleton('core/resource')
137
+ ->getConnection('read_connection')
138
+ ->query('select nonce from everypay_nonce where nonce=\'' . $nonce . '\'')
139
+ ->fetchAll();
140
+ return (count($r) === 0);
141
+ }
142
+
143
+ /**
144
+ * This method creates invoice for current order
145
+ */
146
+ public function createInvoice()
147
+ {
148
+ $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
149
+
150
+ if (!$this->isLocked($this->getOrderId()))
151
+ {
152
+ if ($order->canInvoice())
153
+ {
154
+
155
+ if ($this->createLock($this->getOrderId()))
156
+ {
157
+
158
+ $invoice = $order->prepareInvoice();
159
+ $invoice->pay()->register();
160
+ $invoice->save();
161
+
162
+ $order->setStatus(Mage_Sales_Model_Order::STATE_PROCESSING);
163
+ $order->save();
164
+
165
+ /* Release lock file right after creating invoice */
166
+ $this->releaseLock($this->getOrderId());
167
+
168
+ /* Send invoice */
169
+ if (Mage::getStoreConfig('payment/' . $this->_code . '/invoice_confirmation') == '1')
170
+ {
171
+ $invoice->sendEmail(true, '');
172
+ }
173
+
174
+ Mage::register('current_invoice', $invoice);
175
+ }
176
+ } else
177
+ {
178
+ $this->log('Failed to create invoice for order ' . $this->getOrderId() . '. Reason: invoice already created', __METHOD__, __LINE__);
179
+ }
180
+ } else
181
+ {
182
+ $this->log('Failed to create invoice for order ' . $this->getOrderId() . '. Reason: order locked', __METHOD__, __LINE__);
183
+ }
184
+ }
185
+
186
+ /**
187
+ *
188
+ * @param string $orderId
189
+ * @return string
190
+ */
191
+ private function getLockfilePath($orderId)
192
+ {
193
+ return Mage::getBaseDir('var') . DS . 'locks' . DS . 'order_' . $orderId . '.lock';
194
+ }
195
+
196
+ /**
197
+ * Checks if given invoice is locked, i.e if it has
198
+ * a file in var/locks folder
199
+ *
200
+ * @param string $orderId
201
+ */
202
+ public function isLocked($orderId)
203
+ {
204
+ return file_exists($this->getLockfilePath($orderId));
205
+ }
206
+
207
+ /**
208
+ * Locks order, i.e creates a lock file
209
+ * in var/locks folder
210
+ * @param string $orderId
211
+ */
212
+ public function createLock($orderId)
213
+ {
214
+ $path = $this->getLockfilePath($orderId);
215
+ if (!touch($this->getLockfilePath($orderId)))
216
+ {
217
+ $this->log('Failed to create lockfile ' . $path, __METHOD__, __LINE__);
218
+ return false;
219
+ }
220
+ $this->log('Created lockfile ' . $path, __METHOD__, __LINE__);
221
+ return true;
222
+ }
223
+
224
+ /**
225
+ * Releases lock for order, i.e deletes
226
+ * lock file from var/locks folder
227
+ *
228
+ * @param string $orderId
229
+ */
230
+ public function releaseLock($orderId)
231
+ {
232
+ $path = $this->getLockfilePath($orderId);
233
+ if (!unlink($path))
234
+ {
235
+ $this->log('Failed to delete lockfile ' . $path, __METHOD__, __LINE__);
236
+ return false;
237
+ }
238
+ $this->log('Deleted lockfile ' . $path, __METHOD__, __LINE__);
239
+ return true;
240
+ }
241
+
242
+ protected function log($t, $m, $l)
243
+ {
244
+ Mage::log(sprintf('%s(%s)@%s: %s', $m, $l, $_SERVER['REMOTE_ADDR'], $t), null, $this->logFile);
245
+ }
246
+
247
+ }
app/code/community/Multon/Everypay/Model/Source/PaymentAction.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Multon_Everypay_Model_Source_PaymentAction
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array(
8
+ 'value' => 'authorisation',
9
+ 'label' => 'Authorisation'
10
+ ),
11
+ array(
12
+ 'value' => 'charge',
13
+ 'label' => 'Charge'
14
+ ),
15
+ );
16
+ }
17
+ }
app/code/community/Multon/Everypay/controllers/EverypayController.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Multon_Everypay_EverypayController extends Mage_Core_Controller_Front_Action
3
+ {
4
+
5
+ /**
6
+ *
7
+ * @var Specifies model to be used to verify response from bank
8
+ */
9
+ protected $_model = 'everypay/everypay';
10
+
11
+ /**
12
+ *
13
+ * @var Specifies payment method code in magento
14
+ */
15
+ protected $_code = 'multon_everypay';
16
+
17
+ /**
18
+ *
19
+ * @var Fieldname of order number in return data (used on automatic response from bank)
20
+ */
21
+ protected $orderNoField = 'order_reference';
22
+
23
+ /**
24
+ *
25
+ * @var specifies log file name for Payment
26
+ */
27
+ protected $logFile = 'everypay.log';
28
+
29
+ /**
30
+ * This action redirects user to bank for payment
31
+ *
32
+ * @return void
33
+ */
34
+ public function redirectAction()
35
+ {
36
+ /* Send order confirmation */
37
+ if (Mage::getStoreConfig('payment/' . $this->_code . '/order_confirmation') == '1') {
38
+ try {
39
+ $order = Mage::getModel('sales/order');
40
+ $order->load(
41
+ Mage::getSingleton('checkout/session')->getLastOrderId()
42
+ );
43
+ $order->sendNewOrderEmail();
44
+ $order->save();
45
+ } catch (Exception $e) {
46
+ Mage::log(sprintf('%s(%s): %s', __METHOD__, __LINE__, print_r($e->getMessage(), true)), null, $this->logFile);
47
+ }
48
+ }
49
+
50
+ $this->loadLayout();
51
+ $this->renderLayout();
52
+ }
53
+
54
+ /**
55
+ * This is return action handler for Multon Payment method
56
+ * It verifies signature and creates invoice.
57
+ * In case of verification failure it cancels the order
58
+ *
59
+ * @return void
60
+ */
61
+ public function returnAction()
62
+ {
63
+ Mage::log(sprintf('%s(%s)@%s: %s', __METHOD__, __LINE__, $_SERVER['REMOTE_ADDR'], print_r($this->getRequest()->getParams(), true)), null, $this->logFile);
64
+
65
+ $session = Mage::getSingleton('checkout/session');
66
+ $orderId = $session->getLastRealOrderId();
67
+ if (!$orderId) {
68
+ $orderId = $this->getRequest()->getParam($this->orderNoField);
69
+ }
70
+ if (!$orderId) {
71
+ Mage::log(sprintf('%s(%s)@%s: Order number not found in session or \'%s\'', __METHOD__, __LINE__, $_SERVER['REMOTE_ADDR'], $this->orderNoField),null, $this->logFile);
72
+ $this->_redirect('checkout/onepage/failure');
73
+ return;
74
+ }
75
+ $model = Mage::getModel($this->_model);
76
+ $model->setOrderId($orderId);
77
+ $verify = $model->verify($this->getRequest()->getParams());
78
+ switch ($verify) {
79
+ case Multon_Everypay_Model_Everypay::_VERIFY_SUCCESS:
80
+ $model->createInvoice();
81
+ $this->_redirect('checkout/onepage/success');
82
+ break;
83
+ case Multon_Everypay_Model_Everypay::_VERIFY_CANCEL:
84
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
85
+ $order->cancel()->save();
86
+ $this->_redirect('checkout/onepage/failure');
87
+ break;
88
+ case Multon_Everypay_Model_Everypay::_VERIFY_CORRUPT:
89
+ default:
90
+ $this->_redirect('checkout/onepage/failure');
91
+ break;
92
+ }
93
+ }
94
+
95
+
96
+ }
app/code/community/Multon/Everypay/etc/config.xml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Multon_Everypay>
5
+ <version>1.1.0</version>
6
+ </Multon_Everypay>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <everypay>
11
+ <class>Multon_Everypay_Model</class>
12
+ <resourceModel>everypay_resource</resourceModel>
13
+ </everypay>
14
+ <everypay_resource>
15
+ <class>Multon_Everypay_Model_Resource</class>
16
+ <entities>
17
+ <nonce>
18
+ <table>everypay_nonce</table>
19
+ </nonce>
20
+ </entities>
21
+ </everypay_resource>
22
+ </models>
23
+ <blocks>
24
+ <everypay>
25
+ <class>Multon_Everypay_Block</class>
26
+ </everypay>
27
+ </blocks>
28
+ <resources>
29
+ <everypay_setup>
30
+ <setup>
31
+ <module>Multon_Everypay</module>
32
+ </setup>
33
+ </everypay_setup>
34
+ </resources>
35
+ </global>
36
+ <adminhtml>
37
+ <layout>
38
+ <updates>
39
+ <Multon_Everypay>
40
+ <file>multon/everypay.xml</file>
41
+ </Multon_Everypay>
42
+ </updates>
43
+ </layout>
44
+ </adminhtml>
45
+ <frontend>
46
+ <layout>
47
+ <updates>
48
+ <Multon_Everypay>
49
+ <file>multon/everypay.xml</file>
50
+ </Multon_Everypay>
51
+ </updates>
52
+ </layout>
53
+ <routers>
54
+ <everypay>
55
+ <use>standard</use>
56
+ <args>
57
+ <module>Multon_Everypay</module>
58
+ <frontName>everypay</frontName>
59
+ </args>
60
+ </everypay>
61
+ </routers>
62
+ </frontend>
63
+ <default>
64
+ <payment>
65
+ <multon_everypay>
66
+ <active>0</active>
67
+ <title>EveryPay</title>
68
+ <order_status>pending</order_status>
69
+ <gateway_url>https://pay.every-pay.eu/transactions/</gateway_url>
70
+ <api_username></api_username>
71
+ <api_secret></api_secret>
72
+ <account_id></account_id>
73
+ <transaction_type>authorisation</transaction_type>
74
+ <order_confirmation>0</order_confirmation>
75
+ <invoice_confirmation>1</invoice_confirmation>
76
+ <model>everypay/everypay</model>
77
+ <payment_action>authorize</payment_action>
78
+ </multon_everypay>
79
+ </payment>
80
+ </default>
81
+ </config>
app/code/community/Multon/Everypay/etc/system.xml ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <multon_everypay translate="label" module="multonpay">
7
+ <frontend_model>Multon_Everypay_Block_Adminhtml_Fieldset</frontend_model>
8
+ <label>EveryPay</label>
9
+ <sort_order>170</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <intro>
15
+ <frontend_model>everypay/adminhtml_system_config_intro</frontend_model>
16
+ <sort_order>1</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ </intro>
21
+ <active translate="label">
22
+ <label>Enabled</label>
23
+ <frontend_type>select</frontend_type>
24
+ <source_model>adminhtml/system_config_source_yesno</source_model>
25
+ <sort_order>11</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>0</show_in_store>
29
+ </active>
30
+ <title translate="label">
31
+ <label>Title</label>
32
+ <frontend_type>text</frontend_type>
33
+ <sort_order>12</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>1</show_in_website>
36
+ <show_in_store>1</show_in_store>
37
+ </title>
38
+ <order_status translate="label">
39
+ <label>New Order Status</label>
40
+ <frontend_type>select</frontend_type>
41
+ <source_model>adminhtml/system_config_source_order_status</source_model>
42
+ <sort_order>13</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>0</show_in_store>
46
+ </order_status>
47
+ <gateway_url translate="label">
48
+ <label>Gateway URL</label>
49
+ <frontend_type>text</frontend_type>
50
+ <sort_order>14</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>0</show_in_website>
53
+ <show_in_store>0</show_in_store>
54
+ </gateway_url>
55
+ <api_username translate="label">
56
+ <label>API username</label>
57
+ <frontend_type>text</frontend_type>
58
+ <sort_order>15</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>0</show_in_store>
62
+ </api_username>
63
+ <api_secret translate="label">
64
+ <label>API secret</label>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>16</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>0</show_in_store>
70
+ </api_secret>
71
+ <account_id translate="label">
72
+ <label>Processing Account</label>
73
+ <frontend_type>text</frontend_type>
74
+ <sort_order>17</sort_order>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_website>1</show_in_website>
77
+ <show_in_store>0</show_in_store>
78
+ </account_id>
79
+ <transaction_type translate="label">
80
+ <label>Transaction Type</label>
81
+ <frontend_type>select</frontend_type>
82
+ <source_model>everypay/source_paymentAction</source_model>
83
+ <sort_order>18</sort_order>
84
+ <show_in_default>1</show_in_default>
85
+ <show_in_website>1</show_in_website>
86
+ <show_in_store>0</show_in_store>
87
+ </transaction_type>
88
+ <order_confirmation translate="label">
89
+ <label>Send Order Confirmation</label>
90
+ <frontend_type>select</frontend_type>
91
+ <source_model>adminhtml/system_config_source_yesno</source_model>
92
+ <sort_order>19</sort_order>
93
+ <show_in_default>1</show_in_default>
94
+ <show_in_website>1</show_in_website>
95
+ <show_in_store>1</show_in_store>
96
+ </order_confirmation>
97
+ <invoice_confirmation translate="label">
98
+ <label>Send Invoice</label>
99
+ <frontend_type>select</frontend_type>
100
+ <source_model>adminhtml/system_config_source_yesno</source_model>
101
+ <sort_order>20</sort_order>
102
+ <show_in_default>1</show_in_default>
103
+ <show_in_website>1</show_in_website>
104
+ <show_in_store>1</show_in_store>
105
+ </invoice_confirmation>
106
+ <quick_redirect translate="label">
107
+ <label>Quick Redirect</label>
108
+ <description><![CDATA[Redirect to bank right after order confirmation (no intermediate page)]]>
109
+ </description>
110
+ <frontend_type>select</frontend_type>
111
+ <source_model>adminhtml/system_config_source_yesno</source_model>
112
+ <sort_order>25</sort_order>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>1</show_in_website>
115
+ <show_in_store>1</show_in_store>
116
+ </quick_redirect>
117
+ <hide_logo translate="label">
118
+ <label>Hide Logo</label>
119
+ <frontend_type>select</frontend_type>
120
+ <sort_order>30</sort_order>
121
+ <source_model>adminhtml/system_config_source_yesno</source_model>
122
+ <show_in_default>1</show_in_default>
123
+ <show_in_website>1</show_in_website>
124
+ <show_in_store>1</show_in_store>
125
+ <comment>Hide logo in checkout</comment>
126
+ </hide_logo>
127
+ <sort_order translate="label">
128
+ <label>Sort order</label>
129
+ <frontend_type>text</frontend_type>
130
+ <sort_order>80</sort_order>
131
+ <show_in_default>1</show_in_default>
132
+ <show_in_website>1</show_in_website>
133
+ <show_in_store>1</show_in_store>
134
+ </sort_order>
135
+ <outro>
136
+ <frontend_model>everypay/adminhtml_system_config_outro</frontend_model>
137
+ <sort_order>89</sort_order>
138
+ <show_in_default>1</show_in_default>
139
+ <show_in_website>1</show_in_website>
140
+ <show_in_store>1</show_in_store>
141
+ </outro>
142
+ <version>
143
+ <label>Version info</label>
144
+ <frontend_model>everypay/adminhtml_system_config_version</frontend_model>
145
+ <sort_order>90</sort_order>
146
+ <show_in_default>1</show_in_default>
147
+ <show_in_website>1</show_in_website>
148
+ <show_in_store>1</show_in_store>
149
+ </version>
150
+ </fields>
151
+ </multon_everypay>
152
+ </groups>
153
+ </payment>
154
+ </sections>
155
+ </config>
app/code/community/Multon/Everypay/sql/everypay_setup/install-1.0.0.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $tableName = $installer->getTable('everypay/nonce');
8
+
9
+ $table = $installer->getConnection()
10
+ ->newTable($tableName)
11
+ ->addColumn('nonce', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
12
+ 'nullable' => false,
13
+ ), 'Nonce')
14
+ ->addIndex($installer->getIdxName($tableName, array('nonce'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE),
15
+ 'nonce',
16
+ array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE))
17
+ ;
18
+ $installer->getConnection()->createTable($table);
19
+
20
+ $installer->endSetup();
app/design/frontend/base/default/layout/multon/everypay.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout version="0.1.0">
3
+ <everypay_everypay_redirect>
4
+ <reference name="content">
5
+ <block type="everypay/everypay" name="everypay" template="multon/everypay/everypay.phtml">
6
+ <block type="cms/block" name="everypay_description">
7
+ <action method="setBlockId">
8
+ <block_id>everypay_description</block_id>
9
+ </action>
10
+ </block>
11
+ </block>
12
+ </reference>
13
+ </everypay_everypay_redirect>
14
+ <default>
15
+ <reference name="footer">
16
+ <block type="everypay/info" name="everypay_info" template="multon/everypay/info.phtml" />
17
+ </reference>
18
+ </default>
19
+ </layout>
app/design/frontend/base/default/template/multon/everypay/everypay.phtml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <div class="payment_everyay_container payment_method_everypay">
2
+ <?php echo $this->getChildHtml('everypay_everypay_description') ?>
3
+ <form id="GatewayForm" name="everypay" action="<?php echo $this->getGatewayUrl() ?>" method="POST" target="_top">
4
+ <input type="image" src="<?php echo $this->getMethodLogoUrl(); ?>" onclick="this.form.submit()" class="payment-gateway-logo everypay_logo"/>
5
+ <?php foreach ($this->getFields() as $key => $value) { ?>
6
+ <input type="hidden" name="<?php echo $key ?>" value="<?php echo $value ?>"/>
7
+ <?php } ?>
8
+ </form>
9
+ <?php echo $this->getQuickRedirectScript(); ?>
10
+ </div>
app/design/frontend/base/default/template/multon/everypay/info.phtml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $gateways = $this->getEnabledGateways();
3
+ if (is_array($gateways) && sizeof($gateways) > 0)
4
+ {
5
+ ?>
6
+ <ul class="everypay-logo">
7
+ <?php
8
+ foreach ($gateways as $gateway)
9
+ {
10
+ ?>
11
+ <li class="item">
12
+ <img src="<?php echo $gateway['logo'] ?>" alt="<?php echo $gateway['title'] ?>" title="<?php echo $gateway['title'] ?>"/>
13
+ </li>
14
+ <?php } ?>
15
+ </ul>
16
+ <?php } ?>
app/etc/modules/Multon_Everypay.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Multon_Everypay>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Multon_Everypay>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>multon_everypay</name>
4
+ <version>1.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Multon Everypay</summary>
10
+ <description>Multon Everypay</description>
11
+ <notes>1.1.0&#xD;
12
+ Converted to stand-alone community extension&#xD;
13
+ &#xD;
14
+ 1.0.6&#xD;
15
+ Description and contact info&#xD;
16
+ &#xD;
17
+ 1.0.5&#xD;
18
+ API protocol update: separated fail/cancelled transaction status&#xD;
19
+ &#xD;
20
+ 1.0.4&#xD;
21
+ API protocol update&#xD;
22
+ &#xD;
23
+ 1.0.3&#xD;
24
+ add account id&#xD;
25
+ &#xD;
26
+ 1.0.2&#xD;
27
+ FIX: return url&#xD;
28
+ FIX: return verification&#xD;
29
+ new gateway url&#xD;
30
+ &#xD;
31
+ 1.0.1&#xD;
32
+ FIX: redirect template&#xD;
33
+ &#xD;
34
+ 1.0.0&#xD;
35
+ Stable release</notes>
36
+ <authors><author><name>Multon</name><user>eepohs</user><email>magento@multon.ee</email></author><author><name>Jaanus Vapper</name><user>hullkuri</user><email>hullkuri@gmail.com</email></author><author><name>Tanel Raja</name><user>Pronto</user><email>tanel.raja@gmail.com</email></author></authors>
37
+ <date>2015-05-19</date>
38
+ <time>11:27:25</time>
39
+ <contents><target name="magecommunity"><dir name="Multon"><dir name="Everypay"><dir name="Block"><dir name="Adminhtml"><file name="Fieldset.php" hash="324c82a14594133019deef5c98e8ec78"/><dir name="System"><dir name="Config"><file name="Intro.php" hash="25a5c87ee274de259ede0decc040f643"/><file name="Outro.php" hash="21e9865c5f85cc0c8a601cc171d3f5d0"/><file name="Version.php" hash="63d888085e44f1b99e77aec70f12f62a"/></dir></dir></dir><file name="Everypay.php" hash="f3283cf8916de80d740e2ad722ae69f5"/><file name="Info.php" hash="4755af2b544c9f5de39098046e6da0fb"/></dir><dir name="Model"><file name="Everypay.php" hash="dcbcb043e7874c21f2ef93e79f4add90"/><dir name="Source"><file name="PaymentAction.php" hash="27787205d1886997aeccecb4028d488f"/></dir></dir><dir name="controllers"><file name="EverypayController.php" hash="4d70fc06e227af4e6fcf920be2e89ec1"/></dir><dir name="etc"><file name="config.xml" hash="95b8d791da82f544b8c1d661a760bbb3"/><file name="system.xml" hash="c337dd813b2f7bc4a162ac624e0499c2"/></dir><dir name="sql"><dir name="everypay_setup"><file name="install-1.0.0.php" hash="201924647c609f33835712ab2c81e4d4"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Multon_Everypay.xml" hash="99a2dd0a396a3a1b937d767e48ce237f"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="multon"><file name="everypay.xml" hash="d85234989ed7853a5f29e10e82945056"/></dir></dir><dir name="template"><dir name="multon"><dir name="everypay"><file name="everypay.phtml" hash="1e168f001770918f4d4fa934767854d8"/><file name="info.phtml" hash="91eb9c88527bc6b0076f382df0f6809c"/></dir></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="multon"><dir name="everypay"><file name="everypay_logo_220x44.png" hash="be48db5df549b24058f4e5c889791f6b"/><file name="mastercard_visa_acceptance.jpg" hash="2e7bf5940eeab9863caf8d641ac6f1e9"/></dir></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><file name="everypay-logo.jpg" hash="909c46f5e89be9de1d0d2ad7fdfb8bc6"/></dir></dir></dir></dir></target></contents>
40
+ <compatible/>
41
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
42
+ </package>
skin/adminhtml/default/default/images/everypay-logo.jpg ADDED
Binary file
skin/frontend/base/default/images/multon/everypay/everypay_logo_220x44.png ADDED
Binary file
skin/frontend/base/default/images/multon/everypay/mastercard_visa_acceptance.jpg ADDED
Binary file