SwipeHQ_Checkout - Version 1.7.2

Version Notes

Download this release

Release Info

Developer Optimizer Ltd.
Extension SwipeHQ_Checkout
Version 1.7.2
Comparing to
See all releases


Code changes from version 1.3.0 to 1.7.2

app/code/community/SwipeHQ/Checkout/Helper/Data.php CHANGED
File without changes
app/code/community/SwipeHQ/Checkout/Model/Permittedorderstates.php CHANGED
File without changes
app/code/community/SwipeHQ/Checkout/Model/Standard.php CHANGED
File without changes
app/code/community/SwipeHQ/Checkout/controllers/PaymentController.php CHANGED
@@ -1,189 +1,249 @@
1
  <?php
2
- /**
 
3
  * Swipe Checkout Controller
4
- *
5
- * @copyright (c) 2012-2013, OptimizerHQ Ltd.
6
- * @link http://www.swipehq.com/checkout/
7
- */
8
 
9
  class SwipeHQ_Checkout_PaymentController extends Mage_Core_Controller_Front_Action {
10
-
11
- // The redirect action is triggered when someone places an order
12
- public function redirectAction() {
13
-
14
- $api_url = trim(Mage::getStoreConfig('payment/swipehq/api_url'), '/');
15
-
16
- //get order data
17
- $_order = new Mage_Sales_Model_Order();
18
- $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
19
- $_order->loadByIncrementId($orderId);
20
-
21
- $orderData = $_order->getData();
22
- $currency = !empty($orderData['order_currency_code']) ? $orderData['order_currency_code'] : false;
23
-
24
- $acceptedCurrencies = $this->_getAcceptedCurrencies();
25
-
26
- if (in_array($currency, $acceptedCurrencies)) {
27
- $orderTotal = $orderData['grand_total'];
28
-
29
- //get list of ordered pruducts
30
- $products = '';
31
- $items = $_order->getAllItems();
32
- foreach ($items as $item) {
33
- $qty = $item->getQtyOrdered();
34
- $name = $item->getProduct()->getName();
35
- $products .= $qty . ' x ' . $name . ($item != end($items) ? '<br />' : '');
36
- }
37
 
38
- //get identifier ID using TransactionIdentifier API
39
- $params = array (
40
- 'merchant_id' => Mage::getStoreConfig('payment/swipehq/merchant_id'),
41
- 'api_key' => Mage::getStoreConfig('payment/swipehq/api_key'),
42
- 'td_item' => 'Order ID ' . $orderId,
43
- 'td_description' => $products,
44
- 'td_amount' => $orderTotal,
45
- 'td_currency' => $currency,
46
- 'td_default_quantity' => 1,
47
- 'td_user_data' => $orderId
48
- );
49
-
50
- $response = $this->_sendRequest($api_url.'/createTransactionIdentifier.php', $params);
51
- $response_data = json_decode($response);
52
-
53
- if ($response_data->response_code == 200 && !empty($response_data->data->identifier)) {
54
- $session = Mage::getSingleton('checkout/session');
55
- $session->swipehq_identifier_id = $response_data->data->identifier;
56
- }
57
- } else {
58
- Mage::getSingleton('checkout/session')->addError('Swipe does not support currency: '.$currency.'. Swipe supports these currencies: '.join(', ', $acceptedCurrencies).'.');
59
- return;
 
 
 
 
 
 
 
 
 
 
 
60
  }
61
-
62
- $this->loadLayout();
63
- $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','swipehq',array('template' => 'swipehq/redirect.phtml'));
64
- $this->getLayout()->getBlock('content')->append($block);
65
- $this->renderLayout();
66
- }
67
-
68
- // The response action is triggered when your gateway sends back a response after processing the customer's payment
69
- public function responseAction() {
70
- $request = $_REQUEST;
71
-
72
- $transaction_id = $request['transaction_id'];
73
- $testMode = Mage::getStoreConfig('payment/swipehq/test_mode');
74
- $order = Mage::getModel('sales/order');
75
-
76
- //Swipe callback
77
- if (isset($request['td_user_data'])) {
78
- $order_id = $request['td_user_data'];
79
-
80
- $is_verified = $this->_verifyTransaction($transaction_id);
81
- if ($is_verified) {
82
- // Payment was successful, so update the order's state, send order email and move to the success page
83
-
84
- $order->loadByIncrementId($order_id);
85
- if (!$order->getId()) {
86
- Mage::throwException('No order for processing found');
87
- }
88
-
89
- $order_status = Mage::getStoreConfig('payment/swipehq/paid_order_status');
90
- if ($testMode) {
91
- $order_status = Mage::getStoreConfig('payment/swipehq/test_order_status');
92
- }
93
-
94
- if($order->isStateProtected($order_status)){
95
- Mage::throwException('Swipe configuration error: "Paid Order Status" must not be: "'.$order_status.'". Failed to change state.');
96
- }else{
97
- $order->setState($order_status, true, 'Swipe has authorized the payment.');
98
- }
99
-
100
- $order->sendNewOrderEmail();
101
- $order->setEmailSent(true);
102
-
103
- $order->save();
104
-
105
- Mage::getSingleton('checkout/session')->unsQuoteId();
106
- } else {
107
- // There is a problem in the response we got
108
- $this->cancelAction();
 
 
 
 
 
 
 
 
 
 
 
109
  }
110
- die('LPN OK, transaction_id: '.$transaction_id.', is_verified: '.($is_verified?'y':'n'));
111
-
112
- //Result page (user redirect)
113
- } elseif (isset($request['result']) && isset($request['user_data'])) {
114
- if ($request['result'] == 'accepted' || $request['result'] == 'test-accepted') {
115
- Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure'=>true));
116
- } elseif ($request['result'] == 'declined' || $request['result'] == 'test-declined') {
117
- Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
118
  } else {
119
- Mage_Core_Controller_Varien_Action::_redirect('');
120
  }
 
 
 
 
 
 
 
 
 
 
121
  }
122
- }
123
-
124
- // The cancel action is triggered when an order is to be cancelled
125
- public function cancelAction() {
126
- if (Mage::getSingleton('checkout/session')->getLastRealOrderId()) {
127
- $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
128
- if($order->getId()) {
129
- // Flag the order as 'cancelled' and save it
130
- $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Gateway has declined the payment.')->save();
131
- }
 
 
 
 
 
 
 
 
 
 
 
132
  }
133
- }
134
-
135
- /**
136
- * Transaction verification
137
- *
138
- * @param string $transaction_id
139
- * @return boolean
140
- */
141
- private function _verifyTransaction($transaction_id) {
142
- $api_url = trim(Mage::getStoreConfig('payment/swipehq/api_url'), '/');
143
-
144
- //parameters for transaction verification
145
- $data = array (
146
- 'merchant_id' => Mage::getStoreConfig('payment/swipehq/merchant_id'),
147
- 'api_key' => Mage::getStoreConfig('payment/swipehq/api_key'),
148
- 'transaction_id' => $transaction_id
149
- );
150
 
151
- $response = $this->_sendRequest($api_url.'/verifyTransaction.php', $data);
152
 
153
- if (!empty($response)) {
154
- $response_data = json_decode($response);
155
 
156
- if ($response_data->response_code == 200 &&
157
- $response_data->data->transaction_id == $transaction_id &&
158
- $response_data->data->transaction_approved == 'yes') {
159
- return true;
 
 
 
 
 
 
 
160
  }
 
 
161
  }
162
- return false;
163
  }
164
-
165
- protected function _getAcceptedCurrencies(){
166
- $api_url = trim(Mage::getStoreConfig('payment/swipehq/api_url'), '/');
167
-
168
- $params = array(
169
- 'merchant_id' => Mage::getStoreConfig('payment/swipehq/merchant_id'),
170
- 'api_key' => Mage::getStoreConfig('payment/swipehq/api_key'),
171
- );
172
-
173
- $resp = $this->_sendRequest($api_url.'/fetchCurrencyCodes.php', $params);
174
- $respArr = json_decode($resp, true);
175
- return $respArr['data'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  }
177
-
178
- private function _sendRequest($url, $data) {
179
- $ch = curl_init ($url);
180
- curl_setopt ($ch, CURLOPT_POST, 1);
181
- curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
182
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
183
- curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
184
- curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
185
- $response = curl_exec ($ch);
186
- curl_close ($ch);
187
- return $response;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  }
189
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+
3
+ /*
4
  * Swipe Checkout Controller
5
+ * @copyright (c) 2012-2014, OptimizerHQ Ltd.
6
+ * @link http://www.swipehq.com/
7
+ */
 
8
 
9
  class SwipeHQ_Checkout_PaymentController extends Mage_Core_Controller_Front_Action {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ // The redirect action is triggered when someone places an order
12
+ public function redirectAction() {
13
+
14
+ $api_url = trim(Mage::getStoreConfig('payment/swipehq/api_url'), '/');
15
+
16
+ //get order data
17
+ $_order = new Mage_Sales_Model_Order();
18
+ $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
19
+ $_order->loadByIncrementId($orderId);
20
+
21
+ $orderData = $_order->getData();
22
+ $currency = !empty($orderData['order_currency_code']) ? $orderData['order_currency_code'] : false;
23
+
24
+ $acceptedCurrencies = $this->_getAcceptedCurrencies();
25
+
26
+ if ($acceptedCurrencies && !in_array($currency, $acceptedCurrencies)) {
27
+ Mage::getSingleton('checkout/session')->addError('Swipe Checkout does not support currency: ' . $currency . '. Swipe supports these currencies: ' . join(', ', $acceptedCurrencies) . '.');
28
+ session_write_close(); //THIS LINE IS VERY IMPORTANT!
29
+ $this->_redirect('checkout/cart');
30
+ }
31
+
32
+
33
+
34
+ if (in_array($currency, $acceptedCurrencies)) {
35
+ $orderTotal = $orderData['grand_total'];
36
+
37
+ //get list of ordered pruducts
38
+ $products = '';
39
+ $items = $_order->getAllItems();
40
+ foreach ($items as $item) {
41
+ $qty = $item->getQtyOrdered();
42
+ $name = $item->getProduct()->getName();
43
+ $products .= $qty . ' x ' . $name . ($item != end($items) ? '<br />' : '');
44
  }
45
+
46
+ $customer_email = $orderData['customer_email'];
47
+
48
+
49
+ $params = array(
50
+ 'merchant_id' => Mage::getStoreConfig('payment/swipehq/merchant_id'),
51
+ 'api_key' => Mage::getStoreConfig('payment/swipehq/api_key'),
52
+ 'td_item' => 'Order ID ' . $orderId,
53
+ 'td_description' => $products,
54
+ 'td_amount' => $orderTotal,
55
+ 'td_currency' => $currency,
56
+ 'td_default_quantity' => 1,
57
+ 'td_user_data' => $orderId,
58
+ 'td_callback_url' => Mage::getUrl('swipehq/payment/response'),
59
+ 'td_lpn_url' => Mage::getUrl('swipehq/payment/responselpn')
60
+ );
61
+
62
+ if (!empty($customer_email)) {
63
+ $params['td_email'] = $customer_email;
64
+ }
65
+
66
+ $response = $this->_sendRequest($api_url . '/createTransactionIdentifier.php', $params);
67
+ $response_data = json_decode($response);
68
+
69
+ if ($response_data->response_code == 200 && !empty($response_data->data->identifier)) {
70
+ $session = Mage::getSingleton('checkout/session');
71
+ $session->swipehq_identifier_id = $response_data->data->identifier;
72
+ }
73
+ } else {
74
+ Mage::getSingleton('checkout/session')->addError('Swipe does not support currency: ' . $currency . '. Swipe supports these currencies: ' . join(', ', $acceptedCurrencies) . '.');
75
+ return;
76
+ }
77
+
78
+ $this->loadLayout();
79
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template', 'swipehq', array('template' => 'swipehq/redirect.phtml'));
80
+ $this->getLayout()->getBlock('content')->append($block);
81
+ $this->renderLayout();
82
+ }
83
+
84
+ // The action is triggered when your gateway sends response
85
+ public function responselpnAction() {
86
+
87
+ $request = $_REQUEST;
88
+
89
+ $transaction_id = $request['transaction_id'];
90
+ $testMode = Mage::getStoreConfig('payment/swipehq/test_mode');
91
+ $order = Mage::getModel('sales/order');
92
+
93
+
94
+ if (isset($request['td_user_data'])) {
95
+ $order_id = $request['td_user_data'];
96
+
97
+ $is_verified = $this->_verifyTransaction($transaction_id);
98
+ if ($is_verified) {
99
+ // Payment was successful, so update the order's state, send order email and move to the success page
100
+
101
+ $order->loadByIncrementId($order_id);
102
+ if (!$order->getId()) {
103
+ Mage::throwException('No order for processing found');
104
  }
105
+
106
+ $order_status = Mage::getStoreConfig('payment/swipehq/paid_order_status');
107
+ if ($testMode) {
108
+ $order_status = Mage::getStoreConfig('payment/swipehq/test_order_status');
109
+ }
110
+
111
+ if ($order->isStateProtected($order_status)) {
112
+ Mage::throwException('Swipe configuration error: "Paid Order Status" must not be: "' . $order_status . '". Failed to change state.');
113
  } else {
114
+ $order->setState($order_status, true, 'Swipe has authorized the payment.')->save();
115
  }
116
+
117
+ $order->sendNewOrderEmail();
118
+ $order->setEmailSent(true);
119
+
120
+ $order->save();
121
+
122
+ //Mage::getSingleton('checkout/session')->unsQuoteId();
123
+ } else {
124
+ // There is a problem in the response we got
125
+ $this->cancelAction($order_id);
126
  }
127
+ die('LPN OK, transaction_id: ' . $transaction_id . ', is_verified: ' . ($is_verified ? 'y' : 'n'));
128
+ }
129
+ }
130
+
131
+ // The response action is triggered when your gateway sends back a response after processing the customer's payment
132
+ public function responseAction() {
133
+ $request = $_REQUEST;
134
+
135
+ $transaction_id = $request['transaction_id'];
136
+ $testMode = Mage::getStoreConfig('payment/swipehq/test_mode');
137
+ $order = Mage::getModel('sales/order');
138
+
139
+ //Swipe callback
140
+ if (isset($request['result']) && isset($request['user_data'])) {
141
+ if ($request['result'] == 'accepted' || $request['result'] == 'test-accepted') {
142
+ Mage::getSingleton('checkout/session')->unsQuoteId();
143
+ Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure' => true));
144
+ } elseif ($request['result'] == 'declined' || $request['result'] == 'test-declined') {
145
+ Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure' => true));
146
+ } else {
147
+ Mage_Core_Controller_Varien_Action::_redirect('');
148
  }
149
+ }
150
+ }
151
+
152
+ // The cancel action is triggered when an order is to be cancelled
153
+ public function cancelAction($order_id) {
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
+ $testMode = Mage::getStoreConfig('payment/swipehq/test_mode');
156
 
 
 
157
 
158
+ $order = Mage::getModel('sales/order');
159
+ $order->loadByIncrementId($order_id);
160
+ if (!$order->getId()) {
161
+ Mage::throwException('No order for processing found');
162
+ } else {
163
+ if ($testMode) {
164
+ $order_status = Mage::getStoreConfig('payment/swipehq/test_order_status');
165
+ if ($order->isStateProtected($order_status)) {
166
+ Mage::throwException('Swipe configuration error: "Paid Order Status" must not be: "' . $order_status . '". Failed to change state.');
167
+ } else {
168
+ $order->setState($order_status, true, 'Swipe has declined the payment.')->save();
169
  }
170
+ } else {
171
+ $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Gateway has declined the payment.')->save();
172
  }
 
173
  }
174
+ }
175
+
176
+ public function testConfigAction() {
177
+ include __DIR__ . '/../etc/test-plugin.php';
178
+ }
179
+
180
+ /**
181
+ * Transaction verification
182
+ *
183
+ * @param string $transaction_id
184
+ * @return boolean
185
+ */
186
+ private function _verifyTransaction($transaction_id) {
187
+ $api_url = trim(Mage::getStoreConfig('payment/swipehq/api_url'), '/');
188
+
189
+ //parameters for transaction verification
190
+ $data = array(
191
+ 'merchant_id' => Mage::getStoreConfig('payment/swipehq/merchant_id'),
192
+ 'api_key' => Mage::getStoreConfig('payment/swipehq/api_key'),
193
+ 'transaction_id' => $transaction_id
194
+ );
195
+
196
+ $response = $this->_sendRequest($api_url . '/verifyTransaction.php', $data);
197
+
198
+ if (!empty($response)) {
199
+ $response_data = json_decode($response);
200
+
201
+ if ($response_data->response_code == 200 &&
202
+ $response_data->data->transaction_id == $transaction_id &&
203
+ $response_data->data->transaction_approved == 'yes') {
204
+ return true;
205
+ }
206
  }
207
+ return false;
208
+ }
209
+
210
+ protected function _getAcceptedCurrencies() {
211
+ $api_url = trim(Mage::getStoreConfig('payment/swipehq/api_url'), '/');
212
+ $merchant_id = trim(Mage::getStoreConfig('payment/swipehq/merchant_id'), '/');
213
+ $api_key = trim(Mage::getStoreConfig('payment/swipehq/api_key'), '/');
214
+
215
+ /* $params = array(
216
+ 'merchant_id' => Mage::getStoreConfig('payment/swipehq/merchant_id'),
217
+ 'api_key' => Mage::getStoreConfig('payment/swipehq/api_key'),
218
+ );
219
+
220
+ $resp = $this->_sendRequest($api_url.'/fetchCurrencyCodes.php', $params);
221
+ $respArr = json_decode($resp, true);
222
+ return $respArr['data']; */
223
+
224
+ if ($api_url && $api_key && $merchant_id) {
225
+ $params = array(
226
+ 'merchant_id' => Mage::getStoreConfig('payment/swipehq/merchant_id'),
227
+ 'api_key' => Mage::getStoreConfig('payment/swipehq/api_key'),
228
+ );
229
+ $resp = $this->_sendRequest($api_url . '/fetchCurrencyCodes.php', $params);
230
+ $respArr = json_decode($resp, true);
231
+ return $respArr['data'];
232
+ } else {
233
+ return null;
234
  }
235
+ }
236
+
237
+ private function _sendRequest($url, $data) {
238
+ $ch = curl_init($url);
239
+ curl_setopt($ch, CURLOPT_POST, 1);
240
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
241
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
242
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
243
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
244
+ $response = curl_exec($ch);
245
+ curl_close($ch);
246
+ return $response;
247
+ }
248
+
249
+ }
app/code/community/SwipeHQ/Checkout/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <SwipeHQ_Checkout>
5
- <version>1.0.0</version><!-- todo: what's the point of this version number? where is it used? -->
6
  </SwipeHQ_Checkout>
7
  </modules>
8
  <global>
2
  <config>
3
  <modules>
4
  <SwipeHQ_Checkout>
5
+ <version>1.7.1</version><!-- todo: what's the point of this version number? where is it used? -->
6
  </SwipeHQ_Checkout>
7
  </modules>
8
  <global>
app/code/community/SwipeHQ/Checkout/etc/system.xml CHANGED
@@ -5,7 +5,82 @@
5
  <groups>
6
  <swipehq translate="label comment" module="paygate">
7
  <label>Swipe Checkout</label>
8
- <comment><![CDATA[<a href="http://www.swipehq.com/support/support_detail.php?cat=General+Questions&title=Becoming+a+Swipe+HQ+Checkout+merchant" target="_blank">Click here to see how to become a SwipeHQ Checkout merchant</a>]]></comment>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  <frontend_type>text</frontend_type>
10
  <sort_order>1</sort_order>
11
  <show_in_default>1</show_in_default>
5
  <groups>
6
  <swipehq translate="label comment" module="paygate">
7
  <label>Swipe Checkout</label>
8
+ <comment><![CDATA[<a href="https://www.swipehq.com/support/support_detail.php?cat=General+Questions&title=Becoming+a+Swipe+Merchant" target="_blank">Click here to see how to become a SwipeHQ Checkout merchant</a>
9
+ <script>
10
+ function check_config(){
11
+ var elementToRemove = document.getElementById("check_config_results");
12
+ if(elementToRemove!=null && typeof(elementToRemove)!="undefined"){
13
+ $(elementToRemove).remove();
14
+ }
15
+
16
+ var mainForm = document.getElementById("payment_swipehq");
17
+ var elementToInsert = document.createElement("div");
18
+ elementToInsert.setAttribute("id", "check_config_results");
19
+ elementToInsert.setAttribute("style", "width:100%;height:100%");
20
+ mainForm.appendChild(elementToInsert);
21
+ elementToInsert.innerHTML = "<p style=\"line-height:1;font-size:50px\">Checking config, please wait...</p>";
22
+
23
+ var merchantId = $("payment_swipehq_merchant_id").value;
24
+ var apiKey = $("payment_swipehq_api_key").value;
25
+ var apiURL = $("payment_swipehq_api_url").value;
26
+ var paymentURL = $("payment_swipehq_payment_page_url").value;
27
+
28
+ var urlToLoad = "../../../../../../../swipehq/payment/testconfig?merchant_id="+merchantId+"&api_key="+apiKey+"&api_url="+apiURL+"&payment_page_url="+paymentURL;
29
+ processAjax(urlToLoad);
30
+
31
+ function processAjax(url) {
32
+ var req = null;
33
+ if (window.XMLHttpRequest) { // Non-IE browsers
34
+ req = new XMLHttpRequest();
35
+ try {
36
+ req.onreadystatechange = targetDiv;
37
+ req.open("GET", url, true);
38
+ req.send(null);
39
+ } catch (e) {
40
+ alert(e);
41
+ }
42
+
43
+ } else if (window.ActiveXObject) { // IE
44
+ var req = new ActiveXObject("Microsoft.XMLHTTP");
45
+ if (req) {
46
+ req.onreadystatechange = targetDiv;
47
+ req.open("GET", url, true);
48
+ req.send();
49
+ }
50
+ }
51
+
52
+
53
+ function targetDiv() {
54
+ if(req!=null){
55
+ if (req.readyState == 4) { // Complete
56
+ if (req.status == 200) { // OK response
57
+ document.getElementById("check_config_results").innerHTML = req.responseText;
58
+ }
59
+ else{
60
+ alert("problem");
61
+ }
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+
68
+ }
69
+
70
+ document.observe("dom:loaded", function(){
71
+ var mainForm = document.getElementById("payment_swipehq");
72
+ var buttonToInsert = document.createElement("input");
73
+ buttonToInsert.setAttribute("type", "button");
74
+ buttonToInsert.setAttribute("value", "Check Config");
75
+ buttonToInsert.setAttribute("name", "checkconfig");
76
+ buttonToInsert.setAttribute("onclick", "check_config()");
77
+ buttonToInsert.setAttribute("style", "margin-top:30px");
78
+ mainForm.appendChild(buttonToInsert);
79
+
80
+ });
81
+ </script>
82
+ ]]>
83
+ </comment>
84
  <frontend_type>text</frontend_type>
85
  <sort_order>1</sort_order>
86
  <show_in_default>1</show_in_default>
app/code/community/SwipeHQ/Checkout/etc/test-plugin.php ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A script to test common issues with plugins
5
+ */
6
+
7
+
8
+ /*
9
+ * Constants
10
+ */
11
+
12
+ $TEST_API = 'connectionTest.php';
13
+ $SELF_ERROR_MSG = 'Sorry, there was a problem running this test. Please contact us at Swipe support to let us know you got this error.';
14
+
15
+ function swipe_curl_call($url){
16
+ $ch = curl_init($url);
17
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
18
+ $html = curl_exec($ch);
19
+ curl_close($ch);
20
+ return $html;
21
+ }
22
+
23
+ function testResultHtml($result){
24
+ if($result === true){
25
+ return '<span style="color:green; font-weight: bold;">OK</span>';
26
+ }else if($result === false){
27
+ return '<span style="color:red; font-weight: bold;">Failed</span>';
28
+ }else{
29
+ return '<span style="color:gray">Did not run</span>';
30
+ }
31
+ }
32
+
33
+ $_order = new Mage_Sales_Model_Order();
34
+ $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
35
+ $_order->loadByIncrementId($orderId);
36
+
37
+ $orderData = $_order->getData();
38
+ $currency = !empty($orderData['order_currency_code']) ? $orderData['order_currency_code'] : false;
39
+
40
+
41
+
42
+
43
+
44
+ /*
45
+ * Configuration
46
+ */
47
+
48
+ $merchantId = isset($_REQUEST['merchant_id']) ? $_REQUEST['merchant_id'] : null;
49
+ $apiKey = isset($_REQUEST['api_key']) ? $_REQUEST['api_key'] : null;
50
+ $apiUrl = isset($_REQUEST['api_url']) ? $_REQUEST['api_url'] : null;
51
+ $paymentPageUrl = isset($_REQUEST['payment_page_url']) ? $_REQUEST['payment_page_url'] : null;
52
+
53
+
54
+
55
+ /*
56
+ * Test start
57
+ */
58
+ try{
59
+
60
+
61
+
62
+ // Tests Init
63
+ $minRequirementsOK = null;
64
+ $basicConnectionTestOK = null;
65
+ $credentialsOK = null;
66
+ $merchantStatusOK = null;
67
+ $pluginConfigOK = null;
68
+
69
+ $basicConnectionTestUrl = $apiUrl . $TEST_API;
70
+ $credentialsUrl = $apiUrl . $TEST_API . '?' . http_build_query(
71
+ array(
72
+ 'mode' => 'credentials',
73
+ 'merchant_id' => $merchantId,
74
+ 'api_key' => $apiKey
75
+ )
76
+ );
77
+
78
+ $merchantStatusUrl = $apiUrl . $TEST_API . '?' . http_build_query(
79
+ array(
80
+ 'mode' => 'merchant_status',
81
+ 'merchant_id' => $merchantId,
82
+ 'api_key' => $apiKey
83
+ )
84
+ );
85
+ $pluginConfigUrl = $apiUrl . $TEST_API . '?' . http_build_query(
86
+ array(
87
+ 'mode' => 'plugin_config',
88
+ 'merchant_id' => $merchantId,
89
+ 'api_key' => $apiKey,
90
+ 'payment_page_url' => $paymentPageUrl,
91
+ 'currency' => $currency
92
+ )
93
+ );
94
+
95
+ // Tests Run
96
+ $minRequirementsOK = function_exists('curl_version');
97
+ if($minRequirementsOK){
98
+ $basicConnectionTestOK = swipe_curl_call($basicConnectionTestUrl) == 'OK';
99
+ }
100
+ if($basicConnectionTestOK){
101
+ $credentialsOK = swipe_curl_call($credentialsUrl) == 'OK';
102
+ }
103
+ if($credentialsOK){
104
+ $merchantStatusOK = swipe_curl_call($merchantStatusUrl) == 'OK';
105
+ }
106
+ if($merchantStatusOK){
107
+ $pluginConfigResponse = swipe_curl_call($pluginConfigUrl);
108
+ $pluginConfigOK = $pluginConfigResponse == 'OK';
109
+ }
110
+
111
+
112
+ ?>
113
+ <style type="text/css">
114
+ #test_config_table { font-family: sans-serif; }
115
+ #test_config_table th { text-align: left; background: lightblue; }
116
+ #test_config_table td { font-size: 12px; }
117
+ #test_config_table table { border-collapse: collapse; }
118
+ #test_config_table tr td { padding: 1em 0.5em; border: 1px solid #aaa; }
119
+ #test_config_table tr th { padding: 1em 0.5em; border: 1px solid #aaa; }
120
+ #test_config_table .test-title { white-space: nowrap; font-weight: bold; }
121
+ #test_config_table .test-result { white-space: nowrap; }
122
+ #test_config_table .technical-details { color: #888; margin: 1em; padding: 0.5em; border: 1px solid #aaa; }
123
+ </style>
124
+
125
+ <div id="test_config_table">
126
+ <table>
127
+ <thead>
128
+ <tr>
129
+ <th colspan="3">
130
+ Swipe Plugin Test
131
+ </th>
132
+ </tr>
133
+ </thead>
134
+ <tbody>
135
+ <tr>
136
+ <td class="test-title">
137
+ 1. Minimum Requirements
138
+ </td>
139
+ <td class="test-result">
140
+ <?php echo testResultHtml($minRequirementsOK); ?>
141
+ </td>
142
+ <td class="test_info">
143
+ <?php if($minRequirementsOK === false){ ?>
144
+ Your shopping cart does not meet the minimum requirements to connect to Swipe. Please contact Swipe support.
145
+ <div class="technical-details">Technical details: curl is required.</div>
146
+ <?php } ?>
147
+ </td>
148
+ </tr>
149
+ <tr>
150
+ <td class="test-title">
151
+ 2. Connection to Swipe
152
+ </td>
153
+ <td class="test-result">
154
+ <?php echo testResultHtml($basicConnectionTestOK); ?>
155
+ </td>
156
+ <td class="test_info">
157
+ <?php if($basicConnectionTestOK === false){ ?>
158
+ Could not connect to Swipe. Check your API Url: "<?php echo $apiUrl; ?>", comparing it with the API Url
159
+ in your Swipe Merchant login under Settings -> API Credentials. If you are sure it is correct, Swipe
160
+ may be temporarily unreachable, please try again later.
161
+ <div class="technical-details">
162
+ Technical details: could not connect to: <?php echo htmlentities($basicConnectionTestUrl); ?>
163
+ </div>
164
+ <?php } ?>
165
+ </td>
166
+ </tr>
167
+ <tr>
168
+ <td class="test-title">
169
+ 3. Swipe Merchant Credentials
170
+ </td>
171
+ <td class="test-result">
172
+ <?php echo testResultHtml($credentialsOK); ?>
173
+ </td>
174
+ <td class="test_info">
175
+ <?php if($credentialsOK === false){ ?>
176
+ Your credentials are incorrect. Check your Merchant ID: "<?php echo $merchantId; ?>" and API Key: "<?php echo $apiKey; ?>",
177
+ comparing them to the details you see in your Swipe Merchant login under Settings -> API Credentials.
178
+ A common mistake is to have these two swapped around.
179
+ <div class="technical-details">
180
+ Technical details: called: <?php echo $credentialsUrl; ?>
181
+ </div>
182
+ <?php } ?>
183
+ </td>
184
+ </tr>
185
+ <tr>
186
+ <td class="test-title">
187
+ 4. Swipe Merchant Status
188
+ </td>
189
+ <td class="test-result">
190
+ <?php echo testResultHtml($merchantStatusOK); ?>
191
+ </td>
192
+ <td class="test_info">
193
+ <?php if($merchantStatusOK === false){ ?>
194
+ Your Swipe Merchant account is inactive, or does not have the Payment Page enabled. Please contact Swipe support.
195
+ <div class="technical-details">
196
+ Technical details: called: <?php echo $merchantStatusUrl; ?>
197
+ </div>
198
+ <?php } ?>
199
+ </td>
200
+ </tr>
201
+ <tr>
202
+ <td class="test-title">
203
+ 5. Plugin Configuration
204
+ </td>
205
+ <td class="test-result">
206
+ <?php echo testResultHtml($pluginConfigOK); ?>
207
+ </td>
208
+ <td class="test_info">
209
+ <?php if($pluginConfigOK === false){ ?>
210
+ Your plugin configuration is incorrect. Merchant ID, API Key, and API Url are OK, but something else is incorrectly configured.
211
+ Please double check your configuration, if the problem persists please contact Swipe support.
212
+ <div class="technical-details">
213
+ Technical details: <?php echo $pluginConfigResponse; ?>
214
+ Request: <?php echo htmlentities($pluginConfigUrl); ?>
215
+ </div>
216
+ <?php } ?>
217
+ </td>
218
+ </tr>
219
+
220
+
221
+
222
+ </tbody>
223
+ </table>
224
+ </div>
225
+ <?php
226
+
227
+ }catch(Exception $e){
228
+ echo self::$selfErrorMsg;
229
+ }
230
+
app/design/frontend/base/default/template/swipehq/redirect.phtml CHANGED
@@ -10,7 +10,7 @@ if (!empty($identifier_id) && $payment_page_url) {
10
  <img src="http://www.swipehq.com/images/checkout-logo.png" width="178" height="76" />
11
  <p>To complete your order, please click Pay Now below, you will be redirected to the secure Swipe Checkout payment page.</p>
12
 
13
- <form name="swipehq_checkout_form" method="post" action="<?=$payment_page_url?>">
14
  <input type="hidden" name="checkout" value="true" />
15
  <input type="hidden" name="identifier_id" value="<?php echo $identifier_id; ?>" />
16
  <button type="submit">Pay Now</button>
10
  <img src="http://www.swipehq.com/images/checkout-logo.png" width="178" height="76" />
11
  <p>To complete your order, please click Pay Now below, you will be redirected to the secure Swipe Checkout payment page.</p>
12
 
13
+ <form name="swipehq_checkout_form" method="post" action="<?php echo $payment_page_url; ?>">
14
  <input type="hidden" name="checkout" value="true" />
15
  <input type="hidden" name="identifier_id" value="<?php echo $identifier_id; ?>" />
16
  <button type="submit">Pay Now</button>
app/etc/modules/SwipeHQ_Checkout.xml CHANGED
File without changes
package.xml CHANGED
@@ -1,74 +1,76 @@
1
- <?xml version="1.0"?>
2
- <package>
3
- <name>SwipeHQ_Checkout</name>
4
- <version>1.3.0</version>
5
- <stability>stable</stability>
6
- <license>GNU General Public License (GPL)</license>
7
- <channel>community</channel>
8
- <extends />
9
- <summary>Swipe Checkout payment method</summary>
10
- <description></description>
11
- <notes></notes>
12
- <authors>
13
- <author>
14
- <name>Optimizer Ltd.</name>
15
- <user>swipehq</user>
16
- <email>support@swipehq.com</email>
17
- </author>
18
- </authors>
19
- <date>2013-09-18</date>
20
- <time>00:00:00</time>
21
- <contents>
22
- <target name="magecommunity">
23
- <dir name="SwipeHQ">
24
- <dir name="Checkout">
25
- <dir name="Helper">
26
- <file name="Data.php" hash="8016d7114990c7cc569821b236dc561e" />
27
- </dir>
28
- <dir name="Model">
29
- <file name="Standard.php" hash="29daa1223e187ce11a86831cd67984b5" />
30
- </dir>
31
- <dir name="controllers">
32
- <file name="PaymentController.php" hash="c235c54ee5f74593c6f94cafcbf385f0" />
33
- </dir>
34
- <dir name="etc">
35
- <file name="config.xml" hash="d469840c842a7ce1fa6125a36f9f5a6a" />
36
- <file name="system.xml" hash="6e106a4b51f5ddf7337b218f003168b9" />
37
- </dir>
38
- </dir>
39
- </dir>
40
- </target>
41
- <target name="magedesign">
42
- <dir name="frontend">
43
- <dir name="base">
44
- <dir name="default">
45
- <dir name="template">
46
- <dir name="swipehq">
47
- <file name="redirect.phtml" hash="3d081595a365f5332d522c876f1f0541" />
48
- </dir>
49
- </dir>
50
- </dir>
51
- </dir>
52
- </dir>
53
- </target>
54
- <target name="mageetc">
55
- <dir name="modules">
56
- <file name="SwipeHQ_Checkout.xml" hash="0889d10dcd74110d9cca21fd27823057" />
57
- </dir>
58
- </target>
59
- </contents>
60
- <compatible />
61
- <dependencies>
62
- <required>
63
- <php>
64
- <min>5.1.0</min>
65
- <max>6.0.0</max>
66
- </php>
67
- <extension>
68
- <name>curl</name>
69
- <min></min>
70
- <max></max>
71
- </extension>
72
- </required>
73
- </dependencies>
74
- </package>
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>SwipeHQ_Checkout</name>
4
+ <version>1.7.2</version>
5
+ <stability>stable</stability>
6
+ <license>GNU General Public License (GPL)</license>
7
+ <channel>community</channel>
8
+ <extends />
9
+ <summary>Swipe Checkout payment method</summary>
10
+ <description></description>
11
+ <notes></notes>
12
+ <authors>
13
+ <author>
14
+ <name>Optimizer Ltd.</name>
15
+ <user>swipehq</user>
16
+ <email>support@swipehq.com</email>
17
+ </author>
18
+ </authors>
19
+ <date>2013-09-20</date>
20
+ <time>00:00:00</time>
21
+ <contents>
22
+ <target name="magecommunity">
23
+ <dir name="SwipeHQ">
24
+ <dir name="Checkout">
25
+ <dir name="Helper">
26
+ <file name="Data.php" hash="8016d7114990c7cc569821b236dc561e" />
27
+ </dir>
28
+ <dir name="Model">
29
+ <file name="Standard.php" hash="29daa1223e187ce11a86831cd67984b5" />
30
+ <file name="Permittedorderstates.php" hash="eccc62e6b03420d9b124bb083e8c8e6b" />
31
+ </dir>
32
+ <dir name="controllers">
33
+ <file name="PaymentController.php" hash="9e549da787ee7d121aed379d33b4e013" />
34
+ </dir>
35
+ <dir name="etc">
36
+ <file name="config.xml" hash="462b6e89f0a043272b45b71e05a7443c" />
37
+ <file name="system.xml" hash="bf965a12b02363a0371b322b1e8366b6" />
38
+ <file name="test-plugin.php" hash="6552a4ecc0af27dcbf92336c9d999f8c" />
39
+ </dir>
40
+ </dir>
41
+ </dir>
42
+ </target>
43
+ <target name="magedesign">
44
+ <dir name="frontend">
45
+ <dir name="base">
46
+ <dir name="default">
47
+ <dir name="template">
48
+ <dir name="swipehq">
49
+ <file name="redirect.phtml" hash="fc7d961fdec90adc657af711ffd2325b" />
50
+ </dir>
51
+ </dir>
52
+ </dir>
53
+ </dir>
54
+ </dir>
55
+ </target>
56
+ <target name="mageetc">
57
+ <dir name="modules">
58
+ <file name="SwipeHQ_Checkout.xml" hash="0889d10dcd74110d9cca21fd27823057" />
59
+ </dir>
60
+ </target>
61
+ </contents>
62
+ <compatible />
63
+ <dependencies>
64
+ <required>
65
+ <php>
66
+ <min>5.1.0</min>
67
+ <max>6.0.0</max>
68
+ </php>
69
+ <extension>
70
+ <name>curl</name>
71
+ <min></min>
72
+ <max></max>
73
+ </extension>
74
+ </required>
75
+ </dependencies>
76
+ </package>
readme.txt CHANGED
@@ -1,55 +1,70 @@
1
- Hikashop Swipe plugin
2
-
3
- Version: 1.3.0 / 18 Sep 2013
4
- Copyright: (c) 2012-2013, Optimizer Ltd.
5
- Link: http://www.swipehq.com/checkout/
6
-
7
-
8
-
9
- REQUIREMENTS
10
- ---
11
-
12
- * Swipe account
13
- * Magento
14
-
15
-
16
- INSTALLATION
17
- ---
18
-
19
- 1. Please install this extension through the normal Magento installation process (System -> Magento Connect -> Magento Connect Manager, then
20
- Install New Extensions, grabbing the key from http://www.magentocommerce.com/magento-connect/catalog/product/view/id/15121/ or Direct
21
- Package File Upload, selecting this zip)
22
- 2. After successful installation it will appear in the list of Packages as "SwipeHQ_Checkout"
23
- 3. Then configure the plugin, go back to the Magento Admin, then go to System -> Configuration -> Sales -> Payment Methods -> Swipe Checkout,
24
- adding the following details from your Swipe Merchant login under Settings -> API Credentials:
25
- Merchant ID
26
- API Key
27
- Payment Page Url
28
- Api Url
29
- 4. And finally configure your Swipe account to send customers back to your shop after they pay.
30
- In your Merchant login under Settings -> Payment Notifiers, set:
31
- Callback Url: %YOUR_WEBSITE%/swipehq/payment/response
32
- Callback pass back user data: on
33
- LPN Url: %YOUR_WEBSITE%/swipehq/payment/response
34
- making sure to replace %YOUR_WEBSITE% with your website url, e.g. www.example.com/my-shop/swipehq/payment/response
35
- 5. All done, test it out, add some products to your cart and you will get the option to pay with Swipe.
36
-
37
-
38
- NOTES
39
- ---
40
- * Magento must be configured to use a currency that your Swipe Merchant Account supports for customers to be able to use Swipe to be a payment option,
41
- see Settings -> API Credentials for a list of currencies your Merchant Account supports. And see System -> Manage Currency -> Symboles
42
- to see which currency your Magento is using.
43
- * Magento allows this plugin to set the order state to only a limited subset of all order states. You must mark orders as complete manually once you ship
44
- them.
45
-
46
-
47
- CHANGE LOG
48
- ---
49
-
50
- 1.3.0:
51
- - first version with this readme
52
- - fixing bug where magento does not allow you to set an order's state to complete
53
- - tested against Magento-1.7.0.2
54
-
55
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Swipe Checkout for Magento
2
+
3
+ Version: 1.7.2 / 14 April 2015
4
+ Copyright: (c) 2012-2015, Optimizer Ltd.
5
+ Link: http://www.swipehq.com/
6
+ http://www.magentocommerce.com/magento-connect/catalog/product/view/id/15121/
7
+
8
+
9
+ REQUIREMENTS
10
+ ---
11
+
12
+ * Swipe account
13
+ * Magento
14
+
15
+
16
+ INSTALLATION
17
+ ---
18
+
19
+ 1. Please install this extension through the normal Magento installation process (System -> Magento Connect -> Magento Connect Manager, then
20
+ Install New Extensions, grabbing the key from the plugin page linked above or Direct Package File Upload, selecting this zip)
21
+ 2. After successful installation it will appear in the list of Packages as "SwipeHQ_Checkout"
22
+ 3. Then configure the plugin, go back to the Magento Admin, then go to System -> Configuration -> Sales -> Payment Methods -> Swipe Checkout,
23
+ adding the following details from your Swipe Merchant login under Settings -> API Credentials:
24
+ Merchant ID
25
+ API Key
26
+ Payment Page Url
27
+ Api Url
28
+ 4. And finally configure your Swipe account to send customers back to your shop after they pay.
29
+ In your Merchant login under Settings -> Payment Notifiers, set:
30
+ Callback Url: %YOUR_WEBSITE%/swipehq/payment/response
31
+ Callback pass back user data: on
32
+ LPN Url: %YOUR_WEBSITE%/swipehq/payment/response
33
+ making sure to replace %YOUR_WEBSITE% with your website url, e.g. www.example.com/my-shop/swipehq/payment/response
34
+ 5. All done, test it out, add some products to your cart and you will get the option to pay with Swipe.
35
+
36
+
37
+ NOTES
38
+ ---
39
+ * Magento must be configured to use a currency that your Swipe Merchant Account supports for customers to be able to use Swipe to be a payment option,
40
+ see Settings -> API Credentials for a list of currencies your Merchant Account supports. And see System -> Manage Currency -> Symbols
41
+ to see which currency your Magento is using.
42
+ * Magento allows this plugin to set the order state to only a limited subset of all order states. You must mark orders as complete manually once you ship
43
+ them.
44
+
45
+
46
+ CHANGE LOG
47
+ ---
48
+
49
+ 1.3.0:
50
+ - first version with this readme
51
+ - fixing bug where magento does not allow you to set an order's state to complete
52
+ - tested against Magento-1.7.0.2
53
+
54
+ 1.4.0:
55
+ - Added test configuration button, fixed bug in package.xml file and added the missing file Permittedorderstates.php in Model directory
56
+
57
+ 1.5.0:
58
+ - Fixing bug, changed php short tag to long tag
59
+
60
+ 1.6.0:
61
+ - Fixing issue with check config for installs with .htaccess enabled which deny direct access to magento files
62
+
63
+ 1.7.0:
64
+ - Bug fixes for updating order status
65
+
66
+ 1.7.1:
67
+ - Pass customer email to SwipeHQ payment page and tested against Magento 1.9.0.1
68
+
69
+ 1.7.2:
70
+ - updated SwipeHQ payment page and tested against Magento 1.9.0.1