SwipeHQ_Checkout - Version 1.3.0

Version Notes

Download this release

Release Info

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


Code changes from version 1.2.0 to 1.3.0

app/code/community/SwipeHQ/Checkout/Model/Permittedorderstates.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class SwipeHQ_Checkout_Model_Permittedorderstates {
3
+
4
+ public function toOptionArray(){
5
+ $orig = new Mage_Adminhtml_Model_System_Config_Source_Order_Status();
6
+ $origOptions = $orig->toOptionArray();
7
+
8
+ $order = new Mage_Sales_Model_Order();
9
+
10
+ $r = array();
11
+ foreach($origOptions as $opt){
12
+ $orderState = $opt['value'];
13
+ if(!$orderState) continue; // omit blank option, we require one to be selected
14
+ if($order->isStateProtected($orderState)) continue; // omit options that will cause errors when we try to set the order state
15
+ $r[] = $opt;
16
+ }
17
+ return $r;
18
+ }
19
+
20
+ }
app/code/community/SwipeHQ/Checkout/controllers/PaymentController.php CHANGED
@@ -56,8 +56,6 @@ class SwipeHQ_Checkout_PaymentController extends Mage_Core_Controller_Front_Acti
56
  }
57
  } else {
58
  Mage::getSingleton('checkout/session')->addError('Swipe does not support currency: '.$currency.'. Swipe supports these currencies: '.join(', ', $acceptedCurrencies).'.');
59
- session_write_close(); // required to have message show up after redirect
60
- Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
61
  return;
62
  }
63
 
@@ -70,27 +68,34 @@ class SwipeHQ_Checkout_PaymentController extends Mage_Core_Controller_Front_Acti
70
  // The response action is triggered when your gateway sends back a response after processing the customer's payment
71
  public function responseAction() {
72
  $request = $_REQUEST;
73
-
 
 
 
 
74
  //Swipe callback
75
  if (isset($request['td_user_data'])) {
76
  $order_id = $request['td_user_data'];
77
 
78
- $is_verified = $this->_verifyTransaction($request['transaction_id']);
79
- if ($request['transaction_approved'] == 'yes' && $is_verified) {
80
  // Payment was successful, so update the order's state, send order email and move to the success page
81
 
82
- $order = Mage::getModel('sales/order');
83
  $order->loadByIncrementId($order_id);
84
  if (!$order->getId()) {
85
  Mage::throwException('No order for processing found');
86
  }
87
 
88
  $order_status = Mage::getStoreConfig('payment/swipehq/paid_order_status');
89
- if (Mage::getStoreConfig('payment/swipehq/test_mode')) {
90
  $order_status = Mage::getStoreConfig('payment/swipehq/test_order_status');
91
  }
92
 
93
- $order->setState($order_status, true, 'Gateway has authorized the payment.');
 
 
 
 
94
 
95
  $order->sendNewOrderEmail();
96
  $order->setEmailSent(true);
@@ -98,11 +103,11 @@ class SwipeHQ_Checkout_PaymentController extends Mage_Core_Controller_Front_Acti
98
  $order->save();
99
 
100
  Mage::getSingleton('checkout/session')->unsQuoteId();
101
- } elseif ($request['transaction_approved'] == 'no' && $is_verified) {
102
  // There is a problem in the response we got
103
  $this->cancelAction();
104
- Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
105
  }
 
106
 
107
  //Result page (user redirect)
108
  } elseif (isset($request['result']) && isset($request['user_data'])) {
@@ -148,8 +153,10 @@ class SwipeHQ_Checkout_PaymentController extends Mage_Core_Controller_Front_Acti
148
  if (!empty($response)) {
149
  $response_data = json_decode($response);
150
 
151
- if ($response_data->response_code == 200 && $response_data->data->transaction_id == $transaction_id) {
152
- return true;
 
 
153
  }
154
  }
155
  return false;
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
 
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);
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'])) {
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;
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>
6
  </SwipeHQ_Checkout>
7
  </modules>
8
  <global>
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>
app/code/community/SwipeHQ/Checkout/etc/system.xml CHANGED
@@ -78,7 +78,7 @@
78
  <order_status translate="label">
79
  <label>New Order Status</label>
80
  <frontend_type>select</frontend_type>
81
- <source_model>adminhtml/system_config_source_order_status</source_model>
82
  <sort_order>60</sort_order>
83
  <show_in_default>1</show_in_default>
84
  <show_in_website>1</show_in_website>
@@ -87,7 +87,7 @@
87
  <paid_order_status translate="label">
88
  <label>Paid Order Status</label>
89
  <frontend_type>select</frontend_type>
90
- <source_model>adminhtml/system_config_source_order_status</source_model>
91
  <sort_order>70</sort_order>
92
  <show_in_default>1</show_in_default>
93
  <show_in_website>1</show_in_website>
@@ -97,7 +97,7 @@
97
  <label>Test Order Status</label>
98
  <comment>Paid order status in the test mode</comment>
99
  <frontend_type>select</frontend_type>
100
- <source_model>adminhtml/system_config_source_order_status</source_model>
101
  <sort_order>80</sort_order>
102
  <show_in_default>1</show_in_default>
103
  <show_in_website>1</show_in_website>
78
  <order_status translate="label">
79
  <label>New Order Status</label>
80
  <frontend_type>select</frontend_type>
81
+ <source_model>swipehq/permittedorderstates</source_model>
82
  <sort_order>60</sort_order>
83
  <show_in_default>1</show_in_default>
84
  <show_in_website>1</show_in_website>
87
  <paid_order_status translate="label">
88
  <label>Paid Order Status</label>
89
  <frontend_type>select</frontend_type>
90
+ <source_model>swipehq/permittedorderstates</source_model>
91
  <sort_order>70</sort_order>
92
  <show_in_default>1</show_in_default>
93
  <show_in_website>1</show_in_website>
97
  <label>Test Order Status</label>
98
  <comment>Paid order status in the test mode</comment>
99
  <frontend_type>select</frontend_type>
100
+ <source_model>swipehq/permittedorderstates</source_model>
101
  <sort_order>80</sort_order>
102
  <show_in_default>1</show_in_default>
103
  <show_in_website>1</show_in_website>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>SwipeHQ_Checkout</name>
4
- <version>1.2.0</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
@@ -16,7 +16,7 @@
16
  <email>support@swipehq.com</email>
17
  </author>
18
  </authors>
19
- <date>2013-09-05</date>
20
  <time>00:00:00</time>
21
  <contents>
22
  <target name="magecommunity">
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>
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">
readme.txt ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+