Paystation_Magento_1_8_ModuleV5 - Version 0.0.13

Version Notes

Minor bug fixes

Download this release

Release Info

Developer Paystation
Extension Paystation_Magento_1_8_ModuleV5
Version 0.0.13
Comparing to
See all releases


Code changes from version 0.0.10 to 0.0.13

app/code/local/Mage/Paystation/Model/Standard.php CHANGED
@@ -275,7 +275,7 @@ class Mage_Paystation_Model_Standard extends Mage_Payment_Model_Method_Abstract
275
  $quote = Mage::getModel('sales/quote')->load($quoteID);
276
  $reservedOrderId = $quote->getReservedOrderId();
277
 
278
- $authenticationKey = Mage::getStoreConfig('payment/paystation_standard/hmac_key', Mage::app()->getStore());
279
  $hmacWebserviceName = 'paystation';
280
  $pstn_HMACTimestamp = time();
281
 
@@ -284,8 +284,8 @@ class Mage_Paystation_Model_Standard extends Mage_Payment_Model_Method_Abstract
284
  $amount = ($checkoutfields['final_amount'] * 100);
285
  $testMode = ($checkoutfields['testmode'] ? true : false);
286
  $postback = Mage::getStoreConfig('payment/paystation_standard/postback', Mage::app()->getStore());
287
- $pstn_pi = $checkoutfields['merchant_id']; //"607113"; //Paystation ID
288
- $pstn_gi = $checkoutfields['gateway_id']; //"CARDPAY"; //Gateway ID
289
  $site = ''; // site can be used to differentiate transactions from different websites in admin.
290
  // $pstn_mr = urlencode('schlocalhost-' . time()); // merchant reference is optional, but is a great way to tie a transaction in with a customer (this is displayed in Paystation Administration when looking at transaction details). Max length is 64 char. Make sure you use it!
291
  if ($testMode) $pstn_mr = urlencode($email.':test-mode:'.$reservedOrderId);
275
  $quote = Mage::getModel('sales/quote')->load($quoteID);
276
  $reservedOrderId = $quote->getReservedOrderId();
277
 
278
+ $authenticationKey = trim(Mage::getStoreConfig('payment/paystation_standard/hmac_key', Mage::app()->getStore()));
279
  $hmacWebserviceName = 'paystation';
280
  $pstn_HMACTimestamp = time();
281
 
284
  $amount = ($checkoutfields['final_amount'] * 100);
285
  $testMode = ($checkoutfields['testmode'] ? true : false);
286
  $postback = Mage::getStoreConfig('payment/paystation_standard/postback', Mage::app()->getStore());
287
+ $pstn_pi = trim($checkoutfields['merchant_id']); //"607113"; //Paystation ID
288
+ $pstn_gi =trim($checkoutfields['gateway_id']); //"CARDPAY"; //Gateway ID
289
  $site = ''; // site can be used to differentiate transactions from different websites in admin.
290
  // $pstn_mr = urlencode('schlocalhost-' . time()); // merchant reference is optional, but is a great way to tie a transaction in with a customer (this is displayed in Paystation Administration when looking at transaction details). Max length is 64 char. Make sure you use it!
291
  if ($testMode) $pstn_mr = urlencode($email.':test-mode:'.$reservedOrderId);
app/code/local/Mage/Paystation/controllers/PostbackController.php CHANGED
@@ -58,11 +58,11 @@ class Mage_Paystation_PostbackController extends Mage_Core_Controller_Front_Acti
58
  $xpl = explode(':', $merchant_ref);
59
  $customer_email = $xpl[0];
60
  $orderid = $xpl[1];
61
- $testmode = Mage::getStoreConfig('payment/paystation_standard/testmode', Mage::app()->getStore());
62
 
63
- if ($orderid == "test-mode" && $testmode =="1") {
64
- $orderid = $xpl[2];
65
- }
66
 
67
 
68
 
@@ -75,65 +75,63 @@ class Mage_Paystation_PostbackController extends Mage_Core_Controller_Front_Acti
75
  if ($errorCode == 0) {
76
 
77
  // transaction approved ...
 
78
 
79
- //var_dump ($order);
80
 
81
- $this->processOrder($order, $transactionId, $errorMessage);
82
-
83
  $s = $order->getStatusLabel();
84
 
85
- //var_dump ($s);
86
-
87
- //echo " -==- =-=-= ";
88
-
89
- //var_dump ($s);
90
- //var_dump ($order);
91
 
92
  $success = true;
93
 
94
  $msg = "Payment successful.\n<br />TnxID: " . $transactionId . ".\n<br />TnxSess: " . $merchantSession;
95
-
96
 
97
  return; // this
98
  } else {
99
  if ($order->getId()) {
100
  $order->addStatusToHistory(
101
- $order->getStatus(),//continue setting current order status
102
  Mage_Sales_Model_Order::STATE_CANCELED, urldecode($errorMessage) . ' at PayStation', Mage::helper('paystation')->__($errorMessage . ' from PayStation')
103
  );
104
- $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
105
  $order->save();
106
 
107
- //\echo "<hr>";
108
  }
109
  }
110
  }
111
  }
112
 
113
- function processOrder($order, $transactionId, $errorMessage) {
114
  //$s = "dsffsdsd";//$order->getStatusLabel();
115
-
116
  // echo " ?? ??";
117
  //var_dump ($s);
118
  //echo "<hr>";
119
  //
120
  // echo "<pre>";
121
  // var_dump($order);
122
- echo "<hr>";
123
 
124
  if ($order->getId()) {
125
-
126
- $amount = $order->getGrandTotal();
127
- $order->addStatusToHistory(
128
- $order->getStatus(), urldecode($errorMessage) . ' at Paystation', Mage::helper('paystation')->__($errorMessage . ' from Paystation')
129
- );
130
- $payment = $order->getPayment();
131
- $payment->setTransactionId( $transactionId)
132
- ->setIsTransactionClosed(0);
133
-
134
- $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);//, Mage::helper('paystation')->__('PayStation payment successful.', true), $notified = true);
135
- $order->save();
136
-
 
 
137
  //var_dump ($order);
138
 
139
  if (method_exists($payment, 'registerCaptureNotification')) {
@@ -141,37 +139,38 @@ class Mage_Paystation_PostbackController extends Mage_Core_Controller_Front_Acti
141
  $order->sendNewOrderEmail();
142
  } else {
143
  $newOrderStatus = $order->getStatus();
144
- if (!$order->canInvoice()) {
145
- // when order cannot create invoice, need to have some logic to take care
146
- $order->addStatusToHistory(
147
- $order->getStatus(), // keep order status/state
148
- Mage::helper('paystation')->__('Error in creating an invoice', true), $notified = true
149
- );
150
- } else {
151
- // need to save transaction id
152
- $order->getPayment()->setTransactionId($_POST['order_num']);
153
-
154
- // need to convert from order into invoice
155
- $invoice = $order->prepareInvoice();
156
- $invoice->register()->pay();
157
- Mage::getModel('core/resource_transaction')
158
- ->addObject($invoice)
159
- ->addObject($invoice->getOrder())
160
- ->save();
161
-
162
- $order->setState(
163
- //Mage_Sales_Model_Order::STATE_COMPLETE, true,
164
- Mage_Sales_Model_Order::STATE_PROCESSING, true, Mage::helper('paystation')->__('Notified customer about invoice #%s.', $invoice->getIncrementId()), $notified = true);
165
- //Mage_Sales_Model_Order::STATE_PROCESSING);//, true, Mage::helper('paystation')->__('Notified customer about invoice #%s.', $invoice->getIncrementId()), $notified = true);
166
-
167
- $order->save();
168
- $order->sendNewOrderEmail();
169
- }
170
  }
171
  $order->save();
172
  }
173
  }
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  }
176
 
177
  ?>
58
  $xpl = explode(':', $merchant_ref);
59
  $customer_email = $xpl[0];
60
  $orderid = $xpl[1];
61
+ $testmode = Mage::getStoreConfig('payment/paystation_standard/testmode', Mage::app()->getStore());
62
 
63
+ if ($orderid == "test-mode" && $testmode == "1") {
64
+ $orderid = $xpl[2];
65
+ }
66
 
67
 
68
 
75
  if ($errorCode == 0) {
76
 
77
  // transaction approved ...
78
+ //var_dump ($order);
79
 
80
+ $this->processOrder($order, $transactionId, $errorMessage);
81
 
 
 
82
  $s = $order->getStatusLabel();
83
 
84
+ //var_dump ($s);
85
+ //echo " -==- =-=-= ";
86
+ //var_dump ($s);
87
+ //var_dump ($order);
 
 
88
 
89
  $success = true;
90
 
91
  $msg = "Payment successful.\n<br />TnxID: " . $transactionId . ".\n<br />TnxSess: " . $merchantSession;
92
+
93
 
94
  return; // this
95
  } else {
96
  if ($order->getId()) {
97
  $order->addStatusToHistory(
98
+ $order->getStatus(), //continue setting current order status
99
  Mage_Sales_Model_Order::STATE_CANCELED, urldecode($errorMessage) . ' at PayStation', Mage::helper('paystation')->__($errorMessage . ' from PayStation')
100
  );
101
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true);
102
  $order->save();
103
 
104
+ //\echo "<hr>";
105
  }
106
  }
107
  }
108
  }
109
 
110
+ function processOrder($order, $transactionId, $errorMessage) {
111
  //$s = "dsffsdsd";//$order->getStatusLabel();
 
112
  // echo " ?? ??";
113
  //var_dump ($s);
114
  //echo "<hr>";
115
  //
116
  // echo "<pre>";
117
  // var_dump($order);
118
+ echo "<hr>";
119
 
120
  if ($order->getId()) {
121
+ if ($order->canInvoice())
122
+ $this->doInvoice($order);
123
+ else {
124
+ $amount = $order->getGrandTotal();
125
+ $order->addStatusToHistory(
126
+ $order->getStatus(), urldecode($errorMessage) . ' at Paystation', Mage::helper('paystation')->__($errorMessage . ' from Paystation')
127
+ );
128
+ $payment = $order->getPayment();
129
+ $payment->setTransactionId($transactionId)
130
+ ->setIsTransactionClosed(0);
131
+
132
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true); //, Mage::helper('paystation')->__('PayStation payment successful.', true), $notified = true);
133
+ $order->save();
134
+ }
135
  //var_dump ($order);
136
 
137
  if (method_exists($payment, 'registerCaptureNotification')) {
139
  $order->sendNewOrderEmail();
140
  } else {
141
  $newOrderStatus = $order->getStatus();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  }
143
  $order->save();
144
  }
145
  }
146
 
147
+ function doInvoice($order) {
148
+ if (!$order->canInvoice()) {
149
+
150
+ // when order cannot create invoice, need to have some logic to take care
151
+ $order->addStatusToHistory(
152
+ $order->getStatus(), // keep order status/state
153
+ Mage::helper('paystation')->__('Error in creating an invoice', true), $notified = true
154
+ );
155
+ } else {
156
+ //exit( 'invoice creation');
157
+ // need to save transaction id
158
+ $order->getPayment()->setTransactionId($_GET['ti']);
159
+
160
+ // need to convert from order into invoice
161
+ $invoice = $order->prepareInvoice();
162
+ $invoice->register()->pay();
163
+ Mage::getModel('core/resource_transaction')
164
+ ->addObject($invoice)
165
+ ->addObject($invoice->getOrder())
166
+ ->save();
167
+
168
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, Mage::helper('paystation')->__('Notified customer about invoice #%s.', $invoice->getIncrementId()), $notified = true);
169
+ $order->save();
170
+ $order->sendNewOrderEmail();
171
+ }
172
+ }
173
+
174
  }
175
 
176
  ?>
app/code/local/Mage/Paystation/controllers/StandardController.php CHANGED
@@ -1,342 +1,339 @@
1
- <?php
2
- /**
3
- * PayStation Payment Module For Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Open Software License (OSL 3.0)
8
- * http://opensource.org/licenses/osl-3.0.php
9
- *
10
- * @package Mage_Paystation
11
- * @author Gayatri S Ajith <gayatri@schogini.com>
12
- * @copyright Copyright (c) 2010 Schogini (http://schogini.biz)
13
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14
- */
15
- class Mage_Paystation_StandardController extends Mage_Core_Controller_Front_Action
16
- {
17
- protected $_order;
18
-
19
- public function getOrder()
20
- {
21
- if ($this->_order == null) {
22
- }
23
- return $this->_order;
24
- }
25
-
26
- protected function _expireAjax()
27
- {
28
- if (!Mage::getSingleton('checkout/session')->getQuote()->hasItems()) {
29
- $this->getResponse()->setHeader('HTTP/1.1','403 Session Expired');
30
- exit;
31
- }
32
- }
33
-
34
- public function getStandard()
35
- {
36
- return Mage::getSingleton('paystation/standard');
37
- }
38
-
39
- /**
40
- * When a customer chooses Paystation on Checkout/Payment page
41
- *
42
- */
43
-
44
-
45
- public function redirectAction()
46
- {
47
-
48
- $paystation = Mage::getSingleton('paystation/standard');
49
- $paystation->payment_success = false;
50
-
51
- $session = Mage::getSingleton('checkout/session');
52
- $session->setPaystationStandardQuoteId($session->getQuoteId());
53
- $_SESSION['quoteId'] = $session->getQuoteId();
54
- $session->unsQuoteId();
55
-
56
- header('location: ' . $_SESSION['redirectURL']);
57
- }
58
-
59
- public function notificationurlAction()
60
- {
61
- $success = false;
62
- $message = '';
63
- $display_message = '';
64
-
65
- $session = Mage::getSingleton('checkout/session');
66
- $quote = $session ->getQuote();
67
- $quote_data = $quote->$_data;
68
- $is_multi_shipping = $quote_data ['is_multi_shipping'];
69
-
70
- $confirm =-1;
71
- $success = false;
72
- $QL_amount = '';
73
- $QL_EC =-1;
74
-
75
- if (isset($_SESSION['paystation_id'])) {
76
- $confirm = $this->transactionVerification($_SESSION['paystation_id'],$_GET['ti'], $QL_amount, $QL_merchant_session, $QL_EC);
77
- //mail ('jack@face.co.nz', 'QL_amount:'.(int)$QL_amount. ' QL_merchant_session: '.$QL_merchant_session. ' ec: '.$confirm, '');
78
- }
79
-
80
- if (!isset($_GET['em'])) {
81
- $_SESSION['paystation_success']=false;
82
- $success = false;
83
- $display_message = "Sorry, we couldn't find the payment information.\nTransaction ID: " . ((isset($_GET['ti']))?$_GET['ti']:'Not defined') . "\nError Code: " . ((isset($_GET['ec']))?$_GET['ec']:'Not defined');
84
- $message = "Payment information was not included with return URL." .
85
- "\n<br />TnxID: " . ((isset($_GET['ti']))?$_GET['ti']:'Not defined') .
86
- "\n<br />ErrCode: " . ((isset($_GET['ec']))?$_GET['ec']:'Not defined') .
87
- "\n<br />TnxSess: " . ((isset($_GET['ms']))?$_GET['ms']:'Not defined') .
88
- "\n<br />Amount: " . ((isset($_GET['am']))?$_GET['am']:'Not defined');
89
- }
90
-
91
- elseif ($_GET['ec']=="0" && (int)$confirm==0 && $QL_amount==$_GET['am'] && $_SESSION['paystation_ms'] == $QL_merchant_session) {
92
- // transaction approved ...
93
-
94
-
95
- $success = true;
96
- $_SESSION['paystation_success']=true;
97
- $msg = "Payment successful.\n<br />TnxID: " . ((isset($_GET['ti']))?$_GET['ti']:'Not defined') . ".\n<br />TnxSess: " . ((isset($_GET['ms']))?$_GET['ms']:'Not defined');
98
-
99
- $session = Mage::getSingleton('checkout/session');
100
-
101
- //get the order number from the merchant reference
102
- $merchant_ref = $_GET['merchant_ref'];
103
- $xpl = explode ('-', $merchant_ref);
104
- $_SESSION['paystation_cust_email'] = $xpl[1];
105
-
106
- $orderid= Mage::getSingleton('checkout/session')->getLastRealOrderId();
107
-
108
- if ($orderid==NULL) {
109
- $xpl = explode(':', $merchant_ref);
110
- $customer_email = $xpl[0];
111
- $orderid = $xpl[1];
112
- $testmode = Mage::getStoreConfig('payment/paystation_standard/testmode', Mage::app()->getStore());
113
-
114
- if ($orderid == "test-mode" && $testmode =="1") {
115
- $orderid = $xpl[2];
116
- }
117
- }
118
-
119
- $order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
120
-
121
- if ($_SESSION['paystation_multishipping']==true) {
122
-
123
- $this->_redirect('checkout/multishipping/success');
124
- }
125
- else {
126
- $postback = Mage::getStoreConfig('payment/paystation_standard/postback', Mage::app()->getStore());
127
-
128
- if ($order && $postback=="0") {
129
- $this->processOrder ($order);
130
- }
131
- $this->_redirect('checkout/onepage/success');
132
- }
133
- return; // this return has not particular use - just to ensure that after redirect it doesn't do anything
134
-
135
- } else {
136
- // transaction failed
137
- $success = false;
138
- $display_message = $_GET['em'] . ".\nTransaction ID: " . ((isset($_GET['ti']))?$_GET['ti']:'Not defined') . "\nError Code: " . ((isset($_GET['ec']))?$_GET['ec']:'Not defined');
139
-
140
- $message = "Paystation payment unsucessful. Message from gateway: " . $_GET['em'] .
141
- "\n<br />TnxID: " . ((isset($_GET['ti']))?$_GET['ti']:'Not defined') .
142
- "\n<br />ErrCode: " . ((isset($_GET['ec']))?$_GET['ec']:'Not defined') .
143
- "\n<br />TnxSess: " . ((isset($_GET['ms']))?$_GET['ms']:'Not defined') .
144
- "\n<br />Amount: " . ((isset($_GET['am']))?$_GET['am']:'Not defined');
145
- }
146
-
147
- if (!$success) {
148
- if ($is_multi_shipping==true) {
149
-
150
- $_SESSION['paystation_success']=false;
151
- $_SESSION['paystation_error_message'] = $display_message;
152
- $this->_redirect('checkout/multishipping/success');
153
- }
154
- elseif ($is_multi_shipping==false) $this->paymentError($message, $display_message);
155
- }
156
-
157
- }
158
-
159
- function paymentError($msg, $display_message = '')
160
- {
161
- // if a display message has not been set then, use the order message
162
- if (empty($display_message)) $display_message = $msg;
163
-
164
- // cancel order
165
- $session = Mage::getSingleton('checkout/session');
166
- $session->setQuoteId($session->getPaystationStandardQuoteId(true));
167
- Mage::getModel('sales/quote')->load($session->getQuoteId())->setIsActive(true)->save();
168
-
169
-
170
- $postback = Mage::getStoreConfig('payment/paystation_standard/postback', Mage::app()->getStore());
171
-
172
- if ($session->getLastRealOrderId() && $postback=="0") {
173
- $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
174
- if ($order->getId()) {
175
- $order->addStatusToHistory(
176
- //$order->getStatus(),//continue setting current order status
177
- Mage_Sales_Model_Order::STATE_CANCELED,
178
- urldecode($msg) . ' at PayStation',
179
- Mage::helper('paystation')->__($msg . ' from PayStation')
180
- );
181
- $order->save();
182
- }
183
- }
184
-
185
- $display_message = 'Paystation payment unsuccessful. Reason: ' . "\n" . $display_message;
186
- $session->addError(nl2br($display_message));
187
-
188
- $this->_redirect('checkout/onepage/failure');
189
-
190
- }
191
-
192
-
193
- public function transactionVerification($paystationID,$transactionID, &$QL_amount, &$QL_merchant_session, &$QL_EC) {
194
-
195
- $transactionVerified='';
196
- $lookupXML=$this->quickLookup($paystationID,'ti',$transactionID);
197
- //$lookupXML=quickLookup($paystationID,'ms',$merchantSession);
198
- $p = xml_parser_create();
199
- xml_parse_into_struct($p, $lookupXML, $vals, $tags);
200
- xml_parser_free($p);
201
- //ob_start();
202
- ///echo "\r\n";
203
- for ($i=0;$i<count($vals);$i++) {
204
-
205
- $key = $vals[$i];
206
- $key = $key['tag'];
207
- $val = $i;
208
- //var_dump ($key);
209
- if ($key == "PAYSTATIONERRORCODE") {
210
- $transactionVerified= (int)$vals[$val]['value'];
211
- $QL_EC = (int)$transactionVerified;
212
- //echo "QL_EC: "; var_dump ($QL_EC);
213
- }
214
- elseif ($key == "PURCHASEAMOUNT") { //19
215
- $QL_amount= $vals[$val];
216
- $QL_amount= $QL_amount ['value'];
217
- }
218
- elseif ($key == "MERCHANTSESSION") { //15
219
- $QL_merchant_session= $vals[$val]['value'];
220
- }
221
- else {
222
- continue;
223
- }
224
- }
225
-
226
- return $transactionVerified;
227
- }
228
-
229
- public function quickLookup($pi,$type,$value){
230
- /*
231
- https://www.paystation.co.nz/lookup/quick/?pi=850047&ms=123
232
- - or
233
- https://www.paystation.co.nz/lookup/quick/?pi=850047&ti=0000585260-01
234
- */
235
-
236
- $url = "https://payments.paystation.co.nz/lookup/";//
237
- $params = "&pi=$pi&$type=$value";
238
-
239
- $authenticationKey = Mage::getStoreConfig('payment/paystation_standard/hmac_key', Mage::app()->getStore());
240
- $hmacWebserviceName = 'paystation';
241
- $pstn_HMACTimestamp = time();
242
-
243
- $hmacBody = pack('a*', $pstn_HMACTimestamp) . pack('a*', $hmacWebserviceName) . pack('a*', $params);
244
- $hmacHash = hash_hmac('sha512', $hmacBody, $authenticationKey);
245
- $hmacGetParams = '?pstn_HMACTimestamp=' . $pstn_HMACTimestamp . '&pstn_HMAC=' . $hmacHash;
246
-
247
- $url.= $hmacGetParams;
248
- $defined_vars = get_defined_vars();
249
- //use curl to get reponse
250
- $ch = curl_init();
251
- curl_setopt($ch, CURLOPT_URL,$url);
252
- curl_setopt($ch, CURLOPT_POST, 1);
253
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
254
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
255
- curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
256
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
257
- $result=curl_exec ($ch);
258
- curl_close ($ch);
259
-
260
-
261
-
262
- $h = htmlspecialchars($result);
263
-
264
- return $result;
265
- }
266
-
267
- function parseCode($mvalues) {
268
- $result='';
269
- for ($i=0; $i < count($mvalues); $i++) {
270
- if (!strcmp($mvalues[$i]["tag"],"QSIRESPONSECODE") && isset($mvalues[$i]["value"])){
271
- $result=$mvalues[$i]["value"];
272
- }
273
- }
274
- return $result;
275
- }
276
- function processOrder ($order) {
277
-
278
- if ($order->getId()) {
279
- $amount = $order->getGrandTotal();
280
- $order->addStatusToHistory(
281
- $order->getStatus(),
282
- urldecode($msg) . ' at Paystation',
283
- Mage::helper('paystation')->__($msg . ' from Paystation')
284
- );
285
- $payment = $order->getPayment();
286
- $payment->setTransactionId($_GET['ti'])
287
- ->setIsTransactionClosed(0);
288
-
289
- $order->setState(
290
- Mage_Sales_Model_Order::STATE_PROCESSING, true, 'PayStation payment successful.');
291
-
292
-
293
- $st = $order->getStatus();
294
-
295
-
296
- if (method_exists($payment, 'registerCaptureNotification')) {
297
- $payment->registerCaptureNotification($amount);
298
- $order->sendNewOrderEmail();
299
-
300
- $order->setState(
301
- Mage_Sales_Model_Order::STATE_PROCESSING, true, 'PayStation payment successful.', true);
302
- $order->save();
303
-
304
- }
305
- else {
306
- $newOrderStatus = $order->getStatus();
307
- if (!$order->canInvoice()) {
308
- // when order cannot create invoice, need to have some logic to take care
309
- $order->addStatusToHistory(
310
- $order->getStatus(), // keep order status/state
311
- Mage::helper('paystation')->__('Error in creating an invoice', true),
312
- $notified = true
313
- );
314
-
315
- } else {
316
- // need to save transaction id
317
- $order->getPayment()->setTransactionId($_GET['ti']);
318
-
319
- // need to convert from order into invoice
320
- $invoice = $order->prepareInvoice();
321
- $invoice->register()->pay();
322
- Mage::getModel('core/resource_transaction')
323
- ->addObject($invoice)
324
- ->addObject($invoice->getOrder())
325
- ->save();
326
-
327
- $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true,
328
- Mage::helper('paystation')->__('Notified customer about invoice #%s.', $invoice->getIncrementId()),
329
- $notified = true
330
- );
331
- $order->save();
332
- $order->sendNewOrderEmail();
333
- }
334
-
335
- }
336
- $order->save();
337
- }
338
- }
339
-
340
- }
341
-
342
- ?>
1
+ <?php
2
+
3
+ /**
4
+ * PayStation Payment Module For Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @package Mage_Paystation
12
+ * @author Gayatri S Ajith <gayatri@schogini.com>
13
+ * @copyright Copyright (c) 2010 Schogini (http://schogini.biz)
14
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
15
+ */
16
+ class Mage_Paystation_StandardController extends Mage_Core_Controller_Front_Action {
17
+
18
+ protected $_order;
19
+
20
+ public function getOrder() {
21
+ if ($this->_order == null) {
22
+
23
+ }
24
+ return $this->_order;
25
+ }
26
+
27
+ protected function _expireAjax() {
28
+ if (!Mage::getSingleton('checkout/session')->getQuote()->hasItems()) {
29
+ $this->getResponse()->setHeader('HTTP/1.1', '403 Session Expired');
30
+ exit;
31
+ }
32
+ }
33
+
34
+ public function getStandard() {
35
+ return Mage::getSingleton('paystation/standard');
36
+ }
37
+
38
+ /**
39
+ * When a customer chooses Paystation on Checkout/Payment page
40
+ *
41
+ */
42
+ public function redirectAction() {
43
+
44
+ $paystation = Mage::getSingleton('paystation/standard');
45
+ $paystation->payment_success = false;
46
+
47
+ $session = Mage::getSingleton('checkout/session');
48
+ $session->setPaystationStandardQuoteId($session->getQuoteId());
49
+ $_SESSION['quoteId'] = $session->getQuoteId();
50
+ $session->unsQuoteId();
51
+
52
+ header('location: ' . $_SESSION['redirectURL']);
53
+ }
54
+
55
+ public function notificationurlAction() {
56
+ $success = false;
57
+ $message = '';
58
+ $display_message = '';
59
+
60
+ $session = Mage::getSingleton('checkout/session');
61
+ $quote = $session->getQuote();
62
+ $quote_data = $quote->$_data;
63
+ $is_multi_shipping = $quote_data ['is_multi_shipping'];
64
+
65
+ $confirm = -1;
66
+ $success = false;
67
+ $QL_amount = '';
68
+ $QL_EC = -1;
69
+
70
+ if (isset($_SESSION['paystation_id'])) {
71
+ $confirm = $this->transactionVerification($_SESSION['paystation_id'], $_GET['ti'], $QL_amount, $QL_merchant_session, $QL_EC);
72
+ //mail ('jack@face.co.nz', 'QL_amount:'.(int)$QL_amount. ' QL_merchant_session: '.$QL_merchant_session. ' ec: '.$confirm, '');
73
+ }
74
+
75
+ if (!isset($_GET['em'])) {
76
+ $_SESSION['paystation_success'] = false;
77
+ $success = false;
78
+ $display_message = "Sorry, we couldn't find the payment information.\nTransaction ID: " . ((isset($_GET['ti'])) ? $_GET['ti'] : 'Not defined') . "\nError Code: " . ((isset($_GET['ec'])) ? $_GET['ec'] : 'Not defined');
79
+ $message = "Payment information was not included with return URL." .
80
+ "\n<br />TnxID: " . ((isset($_GET['ti'])) ? $_GET['ti'] : 'Not defined') .
81
+ "\n<br />ErrCode: " . ((isset($_GET['ec'])) ? $_GET['ec'] : 'Not defined') .
82
+ "\n<br />TnxSess: " . ((isset($_GET['ms'])) ? $_GET['ms'] : 'Not defined') .
83
+ "\n<br />Amount: " . ((isset($_GET['am'])) ? $_GET['am'] : 'Not defined');
84
+ } elseif ($_GET['ec'] == "0" && (int) $confirm == 0 && $QL_amount == $_GET['am'] && $_SESSION['paystation_ms'] == $QL_merchant_session) {
85
+ // transaction approved ...
86
+
87
+
88
+ $success = true;
89
+ $_SESSION['paystation_success'] = true;
90
+ $msg = "Payment successful.\n<br />TnxID: " . ((isset($_GET['ti'])) ? $_GET['ti'] : 'Not defined') . ".\n<br />TnxSess: " . ((isset($_GET['ms'])) ? $_GET['ms'] : 'Not defined');
91
+
92
+ $session = Mage::getSingleton('checkout/session');
93
+
94
+ //get the order number from the merchant reference
95
+ $merchant_ref = $_GET['merchant_ref'];
96
+ $xpl = explode('-', $merchant_ref);
97
+ $_SESSION['paystation_cust_email'] = $xpl[1];
98
+
99
+ $orderid = Mage::getSingleton('checkout/session')->getLastRealOrderId();
100
+
101
+ if ($orderid == NULL) {
102
+ $xpl = explode(':', $merchant_ref);
103
+ $customer_email = $xpl[0];
104
+ $orderid = $xpl[1];
105
+ $testmode = Mage::getStoreConfig('payment/paystation_standard/testmode', Mage::app()->getStore());
106
+
107
+ if ($orderid == "test-mode" && $testmode == "1") {
108
+ $orderid = $xpl[2];
109
+ }
110
+ }
111
+
112
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
113
+
114
+ if ($_SESSION['paystation_multishipping'] == true) {
115
+
116
+ $this->_redirect('checkout/multishipping/success');
117
+ } else {
118
+ $postback = Mage::getStoreConfig('payment/paystation_standard/postback', Mage::app()->getStore());
119
+
120
+ if ($order && $postback == "0") {
121
+ $this->processOrder($order);
122
+ }
123
+ $this->_redirect('checkout/onepage/success');
124
+ }
125
+ return; // this return has not particular use - just to ensure that after redirect it doesn't do anything
126
+ } else {
127
+ // transaction failed
128
+ $success = false;
129
+ $display_message = $_GET['em'] . ".\nTransaction ID: " . ((isset($_GET['ti'])) ? $_GET['ti'] : 'Not defined') . "\nError Code: " . ((isset($_GET['ec'])) ? $_GET['ec'] : 'Not defined');
130
+
131
+ $message = "Paystation payment unsucessful. Message from gateway: " . $_GET['em'] .
132
+ "\n<br />TnxID: " . ((isset($_GET['ti'])) ? $_GET['ti'] : 'Not defined') .
133
+ "\n<br />ErrCode: " . ((isset($_GET['ec'])) ? $_GET['ec'] : 'Not defined') .
134
+ "\n<br />TnxSess: " . ((isset($_GET['ms'])) ? $_GET['ms'] : 'Not defined') .
135
+ "\n<br />Amount: " . ((isset($_GET['am'])) ? $_GET['am'] : 'Not defined');
136
+ }
137
+
138
+ if (!$success) {
139
+ if ($is_multi_shipping == true) {
140
+
141
+ $_SESSION['paystation_success'] = false;
142
+ $_SESSION['paystation_error_message'] = $display_message;
143
+ $this->_redirect('checkout/multishipping/success');
144
+ } elseif ($is_multi_shipping == false)
145
+ $this->paymentError($message, $display_message);
146
+ }
147
+ }
148
+
149
+ function paymentError($msg, $display_message = '') {
150
+ // if a display message has not been set then, use the order message
151
+ if (empty($display_message))
152
+ $display_message = $msg;
153
+
154
+ // cancel order
155
+ $session = Mage::getSingleton('checkout/session');
156
+ $session->setQuoteId($session->getPaystationStandardQuoteId(true));
157
+ Mage::getModel('sales/quote')->load($session->getQuoteId())->setIsActive(true)->save();
158
+
159
+
160
+ $postback = Mage::getStoreConfig('payment/paystation_standard/postback', Mage::app()->getStore());
161
+
162
+ if ($session->getLastRealOrderId() && $postback == "0") {
163
+ $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
164
+ if ($order->getId()) {
165
+ $order->addStatusToHistory(
166
+ //$order->getStatus(),//continue setting current order status
167
+ Mage_Sales_Model_Order::STATE_CANCELED, urldecode($msg) . ' at PayStation', Mage::helper('paystation')->__($msg . ' from PayStation')
168
+ );
169
+ $order->save();
170
+ }
171
+ }
172
+
173
+ $display_message = 'Paystation payment unsuccessful. Reason: ' . "\n" . $display_message;
174
+ $session->addError(nl2br($display_message));
175
+
176
+ $this->_redirect('checkout/onepage/failure');
177
+ }
178
+
179
+ public function transactionVerification($paystationID, $transactionID, &$QL_amount, &$QL_merchant_session, &$QL_EC) {
180
+
181
+ $transactionVerified = '';
182
+ $lookupXML = $this->quickLookup($paystationID, 'ti', $transactionID);
183
+ //$lookupXML=quickLookup($paystationID,'ms',$merchantSession);
184
+ $p = xml_parser_create();
185
+ xml_parse_into_struct($p, $lookupXML, $vals, $tags);
186
+ xml_parser_free($p);
187
+ //ob_start();
188
+ ///echo "\r\n";
189
+ for ($i = 0; $i < count($vals); $i++) {
190
+
191
+ $key = $vals[$i];
192
+ $key = $key['tag'];
193
+ $val = $i;
194
+ //var_dump ($key);
195
+ if ($key == "PAYSTATIONERRORCODE") {
196
+ $transactionVerified = (int) $vals[$val]['value'];
197
+ $QL_EC = (int) $transactionVerified;
198
+ //echo "QL_EC: "; var_dump ($QL_EC);
199
+ } elseif ($key == "PURCHASEAMOUNT") { //19
200
+ $QL_amount = $vals[$val];
201
+ $QL_amount = $QL_amount ['value'];
202
+ } elseif ($key == "MERCHANTSESSION") { //15
203
+ $QL_merchant_session = $vals[$val]['value'];
204
+ } else {
205
+ continue;
206
+ }
207
+ }
208
+
209
+ return $transactionVerified;
210
+ }
211
+
212
+ public function quickLookup($pi, $type, $value) {
213
+ /*
214
+ https://www.paystation.co.nz/lookup/quick/?pi=850047&ms=123
215
+ - or –
216
+ https://www.paystation.co.nz/lookup/quick/?pi=850047&ti=0000585260-01
217
+ */
218
+
219
+ $url = "https://payments.paystation.co.nz/lookup/"; //
220
+ $params = "&pi=$pi&$type=$value";
221
+
222
+ $authenticationKey = Mage::getStoreConfig('payment/paystation_standard/hmac_key', Mage::app()->getStore());
223
+ $hmacWebserviceName = 'paystation';
224
+ $pstn_HMACTimestamp = time();
225
+
226
+ $hmacBody = pack('a*', $pstn_HMACTimestamp) . pack('a*', $hmacWebserviceName) . pack('a*', $params);
227
+ $hmacHash = hash_hmac('sha512', $hmacBody, $authenticationKey);
228
+ $hmacGetParams = '?pstn_HMACTimestamp=' . $pstn_HMACTimestamp . '&pstn_HMAC=' . $hmacHash;
229
+
230
+ $url.= $hmacGetParams;
231
+ $defined_vars = get_defined_vars();
232
+ //use curl to get reponse
233
+ $ch = curl_init();
234
+ curl_setopt($ch, CURLOPT_URL, $url);
235
+ curl_setopt($ch, CURLOPT_POST, 1);
236
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
237
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
238
+ curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
239
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
240
+ $result = curl_exec($ch);
241
+ curl_close($ch);
242
+
243
+
244
+
245
+ $h = htmlspecialchars($result);
246
+
247
+ return $result;
248
+ }
249
+
250
+ function parseCode($mvalues) {
251
+ $result = '';
252
+ for ($i = 0; $i < count($mvalues); $i++) {
253
+ if (!strcmp($mvalues[$i]["tag"], "QSIRESPONSECODE") && isset($mvalues[$i]["value"])) {
254
+ $result = $mvalues[$i]["value"];
255
+ }
256
+ }
257
+ return $result;
258
+ }
259
+
260
+ function processOrder($order) {
261
+ $message = "";
262
+ if ($order->getId()) {
263
+ $message .= "got order id ...";
264
+
265
+ $amount = $order->getGrandTotal();
266
+ $order->addStatusToHistory(
267
+ $order->getStatus(), urldecode($msg) . ' at Paystation', Mage::helper('paystation')->__($msg . ' from Paystation')
268
+ );
269
+ $payment = $order->getPayment();
270
+ $payment->setTransactionId($_GET['ti'])
271
+ ->setIsTransactionClosed(0);
272
+
273
+ $order->setState(
274
+ Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Paystation payment successful.');
275
+
276
+
277
+ $st = $order->getStatus();
278
+
279
+
280
+ if (method_exists($payment, 'registerCaptureNotification')) {
281
+ $message .= "has registerCaptureNotification ...";
282
+ if ($order->canInvoice()) {
283
+ $message .= "canInvoice() ...";
284
+ $this->doInvoice($order);
285
+ $order->sendNewOrderEmail();
286
+ }
287
+
288
+ else {
289
+ $message .= " cannot Invoice ...";
290
+ $payment->registerCaptureNotification($amount);
291
+ $order->sendNewOrderEmail();
292
+
293
+ $order->setState(
294
+ Mage_Sales_Model_Order::STATE_PROCESSING, true, 'PayStation payment successful.', true);
295
+ $order->save();
296
+ }
297
+ } else {
298
+ $message .= " not have registerCaptureNotification ...";
299
+ $newOrderStatus = $order->getStatus();
300
+ $this->doInvoice($order);
301
+ }
302
+ $order->save();
303
+ mail ('jack@face.co.nz', 'order process', $message );
304
+ }
305
+ }
306
+
307
+ function doInvoice($order) {
308
+ if (!$order->canInvoice()) {
309
+
310
+ // when order cannot create invoice, need to have some logic to take care
311
+ $order->addStatusToHistory(
312
+ $order->getStatus(), // keep order status/state
313
+ Mage::helper('paystation')->__('Error in creating an invoice', true), $notified = true
314
+ );
315
+ } else {
316
+ //exit( 'invoice creation');
317
+
318
+ // need to save transaction id
319
+ $order->getPayment()->setTransactionId($_GET['ti']);
320
+
321
+ // need to convert from order into invoice
322
+ $invoice = $order->prepareInvoice();
323
+ $invoice->register()->pay();
324
+ Mage::getModel('core/resource_transaction')
325
+ ->addObject($invoice)
326
+ ->addObject($invoice->getOrder())
327
+ ->save();
328
+
329
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, Mage::helper('paystation')->__('Notified customer about invoice #%s.', $invoice->getIncrementId()), $notified = true);
330
+ $order->save();
331
+ $order->sendNewOrderEmail();
332
+ }
333
+
334
+ }
335
+
336
+
337
+ }
338
+
339
+ ?>
 
 
 
package.xml CHANGED
@@ -1,18 +1,26 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Paystation_Magento_1_8_ModuleV5</name>
4
- <version>0.0.10</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Paystation three-party payment module with Postback</summary>
10
- <description>Paystation three-party payment module with Postback</description>
11
- <notes>Now with postback</notes>
 
 
 
 
 
 
 
 
12
  <authors><author><name>Paystation</name><user>Paystation</user><email>info@paystation.co.nz</email></author></authors>
13
- <date>2014-08-18</date>
14
- <time>05:21:37</time>
15
- <contents><target name="magelocal"><dir><dir name="Mage"><dir name="Paystation"><dir name="Block"><dir name="Standard"><file name="Form.php" hash="29304def98cb1949740c2a6d8edba9e0"/></dir></dir><dir name="Helper"><file name="Data.php" hash="37cfb5767197bb15b7c02f05b303a999"/></dir><dir name="Model"><file name="Abstract.php" hash="274b033bb3bc1bfe8f540114f810960e"/><file name="Session.php" hash="f677d1b5e6e2104536e4189eb563681a"/><dir name="Source"><file name="Cctype.php" hash="8ad4533997e40260a159a0014f5cf713"/><file name="PaymentAction.php" hash="920c20b2fe48b3cdce1cbcccdf3ec516"/><file name="Processing.php" hash="b66b423e58438e041ae5cddea19e2254"/><file name="StandardAction.php" hash="a324886c922616e3e640bf6cb0f20901"/></dir><file name="Standard.php" hash="2f74e9a16ce24904b6eac957650a2fcd"/></dir><dir name="controllers"><file name="PostbackController.php" hash="76bb5fd51651c3fbd75f0e57e8bd9153"/><file name="StandardController.php" hash="f5e3d87f3d3e9358e4b18176604ecb9a"/></dir><dir name="etc"><file name="config.xml" hash="2d9b8ff62b677f80cc388b433c2de0ea"/><file name="system.xml" hash="1be2030b37f504cca10b64e6682e7eb3"/></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Mage_Paystation.xml" hash="dcfb6c0fa8c356597482c51671e8c726"/></dir></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.2.6</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Paystation_Magento_1_8_ModuleV5</name>
4
+ <version>0.0.13</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Paystation One-page Checkout with Post Back</summary>
10
+ <description>The Paystation 3-Party One-Page Checkout Module with Post Back for Magento 1.8 is free to download. For more information on Paystation please visit www.paystation.co.nz.&#xD;
11
+ &#xD;
12
+ This module utilizes the Paystation Quick Look-up tool for transaction validation and Post Back tool for receiving transaction responses even if the customer re-direct is interrupted (optional).&#xD;
13
+ &#xD;
14
+ If you are installing this module it is CRUCIAL that you follow all of the install instructions. The instructions can be found in the Release Notes tab above.&#xD;
15
+ &#xD;
16
+ To request a free development account for integration testing please email info@paystation.co.nz.&#xD;
17
+ &#xD;
18
+ Paystation is your ideal payments solution provider whether you are just starting out in eCommerce or are already well established and looking to leverage your existing technology for smarter payments.</description>
19
+ <notes>Minor bug fixes</notes>
20
  <authors><author><name>Paystation</name><user>Paystation</user><email>info@paystation.co.nz</email></author></authors>
21
+ <date>2015-01-06</date>
22
+ <time>22:31:42</time>
23
+ <contents><target name="magelocal"><dir><dir name="Mage"><dir name="Paystation"><dir name="Block"><dir name="Standard"><file name="Form.php" hash="29304def98cb1949740c2a6d8edba9e0"/></dir></dir><dir name="Helper"><file name="Data.php" hash="37cfb5767197bb15b7c02f05b303a999"/></dir><dir name="Model"><file name="Abstract.php" hash="274b033bb3bc1bfe8f540114f810960e"/><file name="Session.php" hash="f677d1b5e6e2104536e4189eb563681a"/><dir name="Source"><file name="Cctype.php" hash="8ad4533997e40260a159a0014f5cf713"/><file name="PaymentAction.php" hash="920c20b2fe48b3cdce1cbcccdf3ec516"/><file name="Processing.php" hash="b66b423e58438e041ae5cddea19e2254"/><file name="StandardAction.php" hash="a324886c922616e3e640bf6cb0f20901"/></dir><file name="Standard.php" hash="507dad0df484b0b0df9ce90d55520054"/></dir><dir name="controllers"><file name="PostbackController.php" hash="f2e6b84825d2eeb042ba4ceab95c9b87"/><file name="StandardController.php" hash="4cd17a7059725727ca9eafc8f1f6f726"/></dir><dir name="etc"><file name="config.xml" hash="2d9b8ff62b677f80cc388b433c2de0ea"/><file name="system.xml" hash="1be2030b37f504cca10b64e6682e7eb3"/></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Mage_Paystation.xml" hash="dcfb6c0fa8c356597482c51671e8c726"/></dir></dir></target></contents>
24
  <compatible/>
25
  <dependencies><required><php><min>5.2.6</min><max>6.0.0</max></php></required></dependencies>
26
  </package>