Paystation_Magento_1_8_ModuleV5 - Version 0.0.10

Version Notes

Now with postback

Download this release

Release Info

Developer Paystation
Extension Paystation_Magento_1_8_ModuleV5
Version 0.0.10
Comparing to
See all releases


Version 0.0.10

app/code/local/Mage/Paystation/Block/Standard/Form.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Block_Standard_Form extends Mage_Payment_Block_Form
16
+ {
17
+ protected function _construct()
18
+ {
19
+ //$this->setTemplate('paystation/standard/form.phtml');
20
+
21
+ // We need to ask only the CC type from the customer - rest of the information will be collected
22
+ // by PayStation when we redirect to their servers. Also, the value for each card type is different
23
+ // from the normal values in Magento. Hence, we need to specifically pass them to our custom template
24
+ //$this->setData('cctypes', Mage::getModel('Mage_Paystation_Model_Standard')->getConfigData('cctypes'));
25
+ parent::_construct();
26
+ }
27
+ }
app/code/local/Mage/Paystation/Helper/Data.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_PayStation
23
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * PayStation data helper
29
+ */
30
+ class Mage_Paystation_Helper_Data extends Mage_Core_Helper_Abstract
31
+ {
32
+
33
+ }
app/code/local/Mage/Paystation/Model/Abstract.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
16
+ /**
17
+ * PayStation Abstract Payment Module
18
+ */
19
+ abstract class Mage_Paystation_Model_Abstract extends Mage_Payment_Model_Method_Abstract
20
+ {
21
+ /**
22
+ * Get Paystation API Model
23
+ *
24
+ * @return Mage_Paystation_Model_Api_Nvp
25
+ */
26
+ public function getApi()
27
+ {
28
+ return Mage::getSingleton('paystation/api_nvp');
29
+ }
30
+
31
+ /**
32
+ * Get paystation session namespace
33
+ *
34
+ * @return Mage_Paystation_Model_Session
35
+ */
36
+ public function getSession()
37
+ {
38
+ return Mage::getSingleton('paystation/session');
39
+ }
40
+
41
+ /**
42
+ * Get checkout session namespace
43
+ *
44
+ * @return Mage_Checkout_Model_Session
45
+ */
46
+ public function getCheckout()
47
+ {
48
+ return Mage::getSingleton('checkout/session');
49
+ }
50
+
51
+ /**
52
+ * Get current quote
53
+ *
54
+ * @return Mage_Sales_Model_Quote
55
+ */
56
+ public function getQuote()
57
+ {
58
+ return $this->getCheckout()->getQuote();
59
+ }
60
+
61
+ public function getRedirectUrl()
62
+ {
63
+ return $this->getApi()->getRedirectUrl();
64
+ }
65
+
66
+ public function getCountryRegionId()
67
+ {
68
+ $a = $this->getApi()->getShippingAddress();
69
+ return $this;
70
+ }
71
+ }
app/code/local/Mage/Paystation/Model/Session.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
16
+ /**
17
+ * Paystation transaction session namespace
18
+ */
19
+ class Mage_Paystation_Model_Session extends Mage_Core_Model_Session_Abstract
20
+ {
21
+ public function __construct()
22
+ {
23
+ $this->init('paystation');
24
+ }
25
+ }
app/code/local/Mage/Paystation/Model/Source/Cctype.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Model_Source_Cctype
16
+ {
17
+ public function toOptionArray()
18
+ {
19
+ return array(
20
+ array('value' => 'visa', 'label' => 'Visa'),
21
+ array('value' => 'mastercard', 'label' => 'MasterCard'),
22
+ array('value' => 'amex', 'label' => 'American Express'),
23
+ array('value' => 'dinersclub', 'label' => 'Diners Club'),
24
+ array('value' => 'qcard', 'label' => 'Union Pay'),
25
+ );
26
+ }
27
+ }
app/code/local/Mage/Paystation/Model/Source/PaymentAction.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Model_Source_PaymentAction
16
+ {
17
+ public function toOptionArray()
18
+ {
19
+ return array(
20
+ #array('value' => Mage_Paystation_Model_Api_Abstract::PAYMENT_TYPE_AUTH, 'label' => Mage::helper('paystation')->__('Authorization')),
21
+ #array('value' => Mage_Paystation_Model_Api_Abstract::PAYMENT_TYPE_ORDER, 'label' => Mage::helper('paystation')->__('Order')),
22
+ array('value' => Mage_Paystation_Model_Api_Abstract::PAYMENT_TYPE_SALE, 'label' => Mage::helper('paystation')->__('Sale')),
23
+ );
24
+ }
25
+ }
app/code/local/Mage/Paystation/Model/Source/Processing.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Model_Source_Processing extends Mage_Adminhtml_Model_System_Config_Source_Order_Status
16
+ {
17
+ protected $_stateStatuses = array (
18
+ //Mage_Sales_Model_Order::STATE_NEW,
19
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
20
+ //Mage_Sales_Model_Order::STATE_PROCESSING,
21
+ //Mage_Sales_Model_Order::STATE_COMPLETE,
22
+ //Mage_Sales_Model_Order::STATE_CLOSED,
23
+ //Mage_Sales_Model_Order::STATE_CANCELED,
24
+ //Mage_Sales_Model_Order::STATE_HOLDED,
25
+ );
26
+ }
app/code/local/Mage/Paystation/Model/Source/StandardAction.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Model_Source_StandardAction
16
+ {
17
+ public function toOptionArray()
18
+ {
19
+ return array(
20
+ #array('value' => Mage_Paystation_Model_Standard::PAYMENT_TYPE_AUTH, 'label' => Mage::helper('paystation')->__('Authorization')),
21
+ array('value' => Mage_Paystation_Model_Standard::PAYMENT_TYPE_SALE, 'label' => Mage::helper('paystation')->__('Sale')),
22
+ );
23
+ }
24
+ }
app/code/local/Mage/Paystation/Model/Standard.php ADDED
@@ -0,0 +1,338 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * Updated Jack Stinchcombe 18/11/2013
17
+ * Updated Jack Stinchcombe 05/08/2014
18
+ */
19
+ class Mage_Paystation_Model_Standard extends Mage_Payment_Model_Method_Abstract {
20
+
21
+ protected $_code = 'paystation_standard';
22
+ protected $_formBlockType = 'paystation/standard_form';
23
+ protected $_allowCurrencyCode = array('AUD', 'CAD', 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'HKD', 'HUF', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'SGD', 'USD');
24
+ // This payment method doesn't support capture, void or refund
25
+ protected $_authorize = '';
26
+ protected $_isGateway = true;
27
+ protected $_canAuthorize = true;
28
+ protected $_canCapture = false;
29
+ protected $_canCapturePartial = false;
30
+ protected $_canRefund = false;
31
+ protected $_canVoid = false;
32
+ protected $_canUseInternal = false;
33
+ protected $_canUseCheckout = true;
34
+ protected $_canUseForMultishipping = true;
35
+ protected $_canSaveCc = false;
36
+
37
+ public function getSession() {
38
+ return Mage::getSingleton('paystation/session');
39
+ }
40
+
41
+ public function getCheckout() {
42
+ return Mage::getSingleton('checkout/session');
43
+ }
44
+
45
+ public function getQuote() {
46
+ return $this->getCheckout()->getQuote();
47
+ }
48
+
49
+ public function canUseInternal() {
50
+ return false;
51
+ }
52
+
53
+ public function canUseForMultishipping() {
54
+ return true;
55
+ }
56
+
57
+ public function createFormBlock($name) {
58
+ $block = $this->getLayout()->createBlock('paystation/standard_form', $name)
59
+ ->setMethod('paystation_standard')
60
+ ->setPayment($this->getPayment())
61
+ ->setTemplate('paystation/standard/form.phtml');
62
+
63
+ return $block;
64
+ }
65
+
66
+ /* validate the currency code is avaialable to use for paystation or not */
67
+
68
+ public function validate() {
69
+ parent::validate();
70
+ $currency_code = $this->getQuote()->getBaseCurrencyCode();
71
+ if (!in_array($currency_code, $this->_allowCurrencyCode)) {
72
+ Mage::throwException(Mage::helper('paystation')->__('Selected currency code (' . $currency_code . ') is not compatabile with PayStation'));
73
+ }
74
+
75
+ //if (!isset($_SESSION['redirectURL'])) $this->initiate_paystation();
76
+ return $this;
77
+ }
78
+
79
+ public function onOrderValidate(Mage_Sales_Model_Order_Payment $payment) {
80
+ return $this;
81
+ }
82
+
83
+ public function onInvoiceCreate(Mage_Sales_Model_Invoice_Payment $payment) {
84
+
85
+ }
86
+
87
+ public function canCapture() {
88
+ return true;
89
+ }
90
+
91
+ public function getOrderPlaceRedirectUrl() {
92
+
93
+ //mail('jack@face.co.nz', 'getOrderPlaceRedirectUrl()', '');
94
+
95
+ //return Mage::getUrl('paystation/standard/redirect', array('_secure' => true));
96
+ // set the quote id so that we can load the quote later if, we need to show the shopping cart page again.
97
+ $session = Mage::getSingleton('checkout/session');
98
+ $session->setPaystationStandardQuoteId($session->getQuoteId());
99
+ $session->unsQuoteId();
100
+
101
+ return $this->initiate_paystation();
102
+ /* if (isset($_SESSION['redirectURL']) && !empty($_SESSION['redirectURL'])) {
103
+ return $_SESSION['redirectURL'];
104
+ }
105
+ return null; */
106
+ }
107
+
108
+ // The fields that you set here are acces in Redirect.php
109
+ // and can be sent to the external payment gateway if needed.
110
+ // All the fields that are entered by the user on the checkout page can be accessed here.
111
+ public function getStandardCheckoutFormFields() {
112
+
113
+ $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
114
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
115
+
116
+ $quote = $this->getQuote();
117
+ $currency_code = $quote->getBaseCurrencyCode();
118
+ $isQuoteVirtual = $quote->getIsVirtual();
119
+ $address = $isQuoteVirtual ? $quote->getBillingAddress() : $quote->getShippingAddress();
120
+ $shipping = $isQuoteVirtual ? $quote->getShippingAddress() : $quote->getBillingAddress();
121
+ $customer_email = $address->getEmail();
122
+
123
+ //$orderIncrementId = $this->getCheckout()->getLastRealOrderId();
124
+
125
+ if ($address->getFirstname() == '') {
126
+ $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
127
+ $quote = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
128
+ $currency_code = $quote->getBaseCurrencyCode();
129
+ $isQuoteVirtual = $quote->getIsVirtual();
130
+ $address = $isQuoteVirtual ? $quote->getBillingAddress() : $quote->getShippingAddress();
131
+ $shipping = $isQuoteVirtual ? $quote->getShippingAddress() : $quote->getBillingAddress();
132
+ $customer_email = $quote->getCustomerEmail();
133
+ }
134
+
135
+ if (!isset($shipping) || empty($shipping)) {
136
+ $shipping = $address;
137
+ }
138
+
139
+ $sArr = array(
140
+ 'merchant_id' => $this->getConfigData('paystation_id'),
141
+ 'gateway_id' => $this->getConfigData('gateway_id'),
142
+ 'testmode' => $this->getConfigData('testmode'),
143
+ 'invoice' => $this->getCheckout()->getLastRealOrderId(),
144
+ 'currency_code' => $currency_code,
145
+ 'address_override' => 1,
146
+ // billing address
147
+ 'first_name' => $address->getFirstname(),
148
+ 'last_name' => $address->getLastname(),
149
+ 'address1' => $address->getStreet(1),
150
+ 'address2' => $address->getStreet(2),
151
+ 'city' => $address->getCity(),
152
+ 'state' => $address->getRegionCode(),
153
+ 'country' => $address->getCountry(),
154
+ 'zip' => $address->getPostcode(),
155
+ 'telephone' => $address->getTelephone(),
156
+ // shipping address
157
+ 's_first_name' => $shipping->getFirstname(),
158
+ 's_last_name' => $shipping->getLastname(),
159
+ 's_address1' => $shipping->getStreet(1),
160
+ 's_address2' => $shipping->getStreet(2),
161
+ 's_city' => $shipping->getCity(),
162
+ 's_state' => $shipping->getRegionCode(),
163
+ 's_country' => $shipping->getCountry(),
164
+ 's_zip' => $shipping->getPostcode(),
165
+ 's_telephone' => $shipping->getTelephone(),
166
+ 'email' => $customer_email,
167
+ 'cctype' => $quote->getPayment()->getCcType(),
168
+ 'order' => $order
169
+ );
170
+
171
+ //http://docs.magentocommerce.com/Mage_Sales/Mage_Sales_Model_Quote.htm
172
+
173
+ $quote2 = $quote->collectTotals();
174
+ $totals = $quote2->getTotals();
175
+
176
+ $final_amount = $totals['grand_total']['value'];
177
+
178
+ $sArr['final_amount'] = sprintf('%.2f', $final_amount);
179
+ $_SESSION['paystation_amount'] = number_format($final_amount, 4);
180
+ $_SESSION['paystation_id'] = $this->getConfigData('paystation_id');
181
+ //var_dump ($_SESSION['paystation_amount']);
182
+
183
+ return $sArr;
184
+ }
185
+
186
+ public function getPaystationUrl() {
187
+ $url = 'https://secure.paystation.com/cgi-bin/order2/processorder1.pl';
188
+ return $url;
189
+ }
190
+
191
+ public function getDebug() {
192
+ return Mage::getStoreConfig('paystation/wps/debug_flag');
193
+ }
194
+
195
+ public function isInitializeNeeded() {
196
+ return true;
197
+ }
198
+
199
+ public function initialize($paymentAction, $stateObject) {
200
+ $state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
201
+ $stateObject->setState($state);
202
+ $stateObject->setStatus('pending_payment');
203
+ $stateObject->setIsNotified(false);
204
+ }
205
+
206
+ function makePaystationSessionID($min = 8, $max = 8) {
207
+ // seed the random number generator - straight from PHP manual
208
+ $seed = (double) microtime() * getrandmax();
209
+ srand($seed);
210
+
211
+ // make a string of $max characters with ASCII values of 40-122
212
+ $p = 0;
213
+ $pass ="";
214
+ while ($p < $max):
215
+ $r = chr(123 - (rand() % 75));
216
+
217
+ // get rid of all non-alphanumeric characters
218
+ if (!($r >= 'a' && $r <= 'z') && !($r >= 'A' && $r <= 'Z') && !($r >= '1' && $r <= '9'))
219
+ continue;
220
+ $pass.=$r;
221
+
222
+ $p++;
223
+ endwhile;
224
+ // if string is too short, remake it
225
+ if (strlen($pass) < $min):
226
+ $pass = $this->makePaystationSessionID($min, $max);
227
+ endif;
228
+
229
+ return $pass;
230
+ }
231
+
232
+ function directTransaction($url, $params) {
233
+
234
+ $defined_vars = get_defined_vars();
235
+
236
+ //use curl to get reponse
237
+ $ch = curl_init();
238
+ curl_setopt($ch, CURLOPT_POST, 1);
239
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
240
+ curl_setopt($ch, CURLOPT_URL, $url);
241
+ //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
242
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
243
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
244
+ //curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
245
+ curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
246
+
247
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
248
+ $result = curl_exec($ch);
249
+ if (curl_error($ch)) {
250
+ echo curl_error($ch);
251
+ }
252
+ curl_close($ch);
253
+
254
+ return $result;
255
+ }
256
+
257
+ function initiate_paystation() {
258
+
259
+ $returnURL = urlencode( Mage::getUrl('paystation/standard/notificationurl'));
260
+ $postbackURL = urlencode( Mage::getUrl('paystation/postback'));
261
+
262
+
263
+ $_SESSION['paystation_success'] = false;
264
+ $_SESSION['paystation_redirected'] = false;
265
+
266
+ // Try to initiate a transaction with PayStation and get the redirect URL
267
+ $checkoutfields = $this->getStandardCheckoutFormFields();
268
+ $email = $checkoutfields['email'];
269
+
270
+ $postback = Mage::getStoreConfig('payment/paystation_standard/postback', Mage::app()->getStore());
271
+
272
+ $quoteID= Mage::getSingleton('checkout/session')->getQuoteId();
273
+ if ($quoteID==NULL) $quoteID = "NULL";
274
+
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
+
282
+
283
+ $paystationURL = "https://www.paystation.co.nz/direct/paystation.dll";
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);
292
+ else $pstn_mr = urlencode($email.':'.$reservedOrderId);//:'.$orderID);
293
+
294
+ $merchantSession = urlencode(time() . '-' . $this->makePaystationSessionID(18, 18)); // max length of ms is 64 char
295
+ $_SESSION['paystation_ms'] = $merchantSession;
296
+ $paystationParams = "paystation&pstn_pi=" . $pstn_pi . "&pstn_gi=" . $pstn_gi . "&pstn_ms=" . $merchantSession . "&pstn_am=" . $amount . "&pstn_mr=" . $pstn_mr . "&pstn_nr=t";
297
+ $paystationParams .= "&pstn_du=".$returnURL;
298
+
299
+ if ($postback=='1') $paystationParams .= "&pstn_dp=".$postbackURL;
300
+ //echo "postback: ";
301
+ //var_dump ($postback);
302
+ //var_dump ($paystationParams); exit();
303
+
304
+ //$this->setTransactionAdditionalInfo ('pstn_ms', $merchantSession);
305
+
306
+ if ($testMode == true) {
307
+ $paystationParams = $paystationParams . "&pstn_tm=t";
308
+ }
309
+ // if, possible pass the cc type so that the first step of selecting card type can be skipped on the external page
310
+
311
+
312
+ $hmacBody = pack('a*', $pstn_HMACTimestamp).pack('a*', $hmacWebserviceName) . pack('a*', $paystationParams);
313
+ $hmacHash = hash_hmac('sha512', $hmacBody, $authenticationKey);
314
+ $hmacGetParams = '?pstn_HMACTimestamp=' . $pstn_HMACTimestamp . '&pstn_HMAC=' . $hmacHash;
315
+ $paystationURL.= $hmacGetParams;
316
+
317
+ $initiationResult = $this->directTransaction($paystationURL, $paystationParams);
318
+ preg_match_all("/<(.*?)>(.*?)\</", $initiationResult, $outarr, PREG_SET_ORDER);
319
+ $n = 0;
320
+ while (isset($outarr[$n])) {
321
+ $retarr[$outarr[$n][1]] = strip_tags($outarr[$n][0]);
322
+ $n++;
323
+ }
324
+
325
+
326
+ $_SESSION['redirectURL'] = '';
327
+ if (isset($retarr['DigitalOrder']) && isset($retarr['PaystationTransactionID'])) {
328
+ $_SESSION['redirectURL'] = $retarr['DigitalOrder'];
329
+
330
+
331
+ return $_SESSION['redirectURL'];
332
+ } else {
333
+ Mage::throwException(Mage::helper('paystation')->__('Error: ' . $retarr['em']));
334
+ return null;
335
+ }
336
+ }
337
+
338
+ }
app/code/local/Mage/Paystation/controllers/PostbackController.php ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Jack Stinchcombe info@paystation.co.nz
13
+ * @copyright Copyright (c) 2014 Paystation Ltd
14
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
15
+ *
16
+ *
17
+ */
18
+ require_once('Mage/Paystation/controllers/StandardController.php');
19
+
20
+ class Mage_Paystation_PostbackController extends Mage_Core_Controller_Front_Action {
21
+
22
+ public function indexAction() {
23
+ if (!$this->getRequest()->isPost()) {
24
+ return;
25
+ }
26
+
27
+ $xml = file_get_contents('php://input');
28
+ $xml = simplexml_load_string($xml);
29
+ //var_dump ($xml);
30
+
31
+ if (!empty($xml)) {
32
+ //echo ('<hr>!empty(xml) <br><br>');
33
+ $errorCode = (int) $xml->ec;
34
+ $errorMessage = $xml->em;
35
+ $transactionId = $xml->ti;
36
+ $cardType = $xml->ct;
37
+ $merchantReference = $xml->merchant_ref;
38
+ $testMode = $xml->tm;
39
+ $merchantSession = $xml->MerchantSession;
40
+ $usedAcquirerMerchantId = $xml->UsedAcquirerMerchantID;
41
+ $amount = $xml->PurchaseAmount; // Note this is in cents
42
+ $transactionTime = $xml->TransactionTime;
43
+ $requestIp = $xml->RequestIP;
44
+
45
+ $message = "Error Code: " . $errorCode . "<br/>";
46
+ $message .= "Error Message: " . $errorMessage . "<br/>";
47
+ $message .= "Transaction ID: " . $transactionId . "<br/>";
48
+ $message .= "Card Type: " . $cardType . "<br/>";
49
+ $message .= "Merchant Reference: " . $merchantReference . "<br/>";
50
+ $message .= "Test Mode: " . $testMode . "<br/>";
51
+ $message .= "Merchant Session: " . $merchantSession . "<br/>";
52
+ $message .= "Merchant ID: " . $usedAcquirerMerchantId . "<br/>";
53
+ $message .= "Amount: " . $amount . " (cents)<br/>";
54
+ $message .= "Transaction Time: " . $transactionTime . "<br/>";
55
+ $message .= "IP: " . $requestIp . "<br/>";
56
+
57
+ $merchant_ref = $merchantReference;
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
+
69
+ //var_dump ($customer_email);
70
+
71
+
72
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
73
+
74
+
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')) {
140
+ $payment->registerCaptureNotification($amount);
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
+ ?>
app/code/local/Mage/Paystation/controllers/StandardController.php ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ?>
app/code/local/Mage/Paystation/etc/config.xml ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Mage_Paystation>
5
+ <version>0.1</version>
6
+ </Mage_Paystation>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <paystation>
11
+ <class>Mage_Paystation_Model</class>
12
+ <resourceModel>paystation_mysql4</resourceModel>
13
+ </paystation>
14
+ <paystation_mysql4>
15
+ <class>Mage_Paystation_Model_Mysql4</class>
16
+ <entities>
17
+ <paystation_debug><table>paystation_debug</table></paystation_debug>
18
+ </entities>
19
+ </paystation_mysql4>
20
+ </models>
21
+ <resources>
22
+ <paystation_setup>
23
+ <connection>
24
+ <use>core_setup</use>
25
+ </connection>
26
+ </paystation_setup>
27
+ <paystation_write>
28
+ <connection>
29
+ <use>core_write</use>
30
+ </connection>
31
+ </paystation_write>
32
+ <paystation_read>
33
+ <connection>
34
+ <use>core_read</use>
35
+ </connection>
36
+ </paystation_read>
37
+ </resources>
38
+ <blocks>
39
+ <paystation><class>Mage_Paystation_Block</class></paystation>
40
+ </blocks>
41
+ <rewrite>
42
+
43
+ <Mage_Paystation_checkout_multishipping_overview>
44
+ <from><![CDATA[#^/checkout/multishipping/overview/#]]></from>
45
+
46
+ <to>/paystation/checkout_multishipping/overview/</to>
47
+ </Mage_Paystation_checkout_multishipping_overview>
48
+ <Mage_Paystation_checkout_multishipping_overviewPost>
49
+ <from><![CDATA[#^/checkout/multishipping/overviewPost/#]]></from>
50
+
51
+ <to>/paystation/checkout_multishipping/overviewPost/</to>
52
+ </Mage_Paystation_checkout_multishipping_overviewPost>
53
+ <Mage_Paystation_checkout_multishipping_success>
54
+ <from><![CDATA[#^/checkout/multishipping/success/#]]></from>
55
+ <to>/paystation/checkout_multishipping/success/</to>
56
+ </Mage_Paystation_checkout_multishipping_success>
57
+ </rewrite>
58
+ </global>
59
+ <frontend>
60
+ <secure_url>
61
+ <paystation_standard>/paystation/standard</paystation_standard>
62
+ </secure_url>
63
+ <routers>
64
+ <paystation>
65
+ <use>standard</use>
66
+ <args>
67
+ <module>Mage_Paystation</module>
68
+ <frontName>paystation</frontName>
69
+ </args>
70
+ </paystation>
71
+ </routers>
72
+ </frontend>
73
+ <default>
74
+ <payment>
75
+ <paystation_standard>
76
+ <model>paystation/standard</model>
77
+ <title>Paystation Payment Gateway</title>
78
+ <testmode>1</testmode>
79
+ <postback>1</postback>
80
+ <allowspecific>0</allowspecific>
81
+ <order_status>pending_paystation</order_status>
82
+ <cctypes>visa,mastercard</cctypes>
83
+ </paystation_standard>
84
+ </payment>
85
+ </default>
86
+ </config>
app/code/local/Mage/Paystation/etc/system.xml ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <paystation_standard translate="label" module="paystation">
7
+ <label>Paystation Payment Gateway</label>
8
+
9
+ <frontend_type>text</frontend_type>
10
+ <sort_order>102</sort_order>
11
+ <show_in_default>1</show_in_default>
12
+ <show_in_website>1</show_in_website>
13
+ <show_in_store>1</show_in_store>
14
+ <fields>
15
+ <active translate="label">
16
+ <label>Enabled</label>
17
+ <frontend_type>select</frontend_type>
18
+ <source_model>adminhtml/system_config_source_yesno</source_model>
19
+ <sort_order>1</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>1</show_in_website>
22
+ <show_in_store>1</show_in_store>
23
+ </active>
24
+ <title translate="label">
25
+ <label>Title</label>
26
+ <comment>This is the text that appears beside the payment method during checkout.</comment>
27
+ <frontend_type>text</frontend_type>
28
+ <sort_order>2</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ </title>
33
+ <paystation_id translate="label">
34
+ <comment>Provided by Paystation</comment>
35
+ <label>Paystation ID</label>
36
+ <frontend_type>text</frontend_type>
37
+ <sort_order>3</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>1</show_in_website>
40
+ <show_in_store>1</show_in_store>
41
+ </paystation_id>
42
+ <gateway_id translate="label">
43
+ <comment>Provided by Paystation</comment>
44
+ <label>Gateway ID</label>
45
+ <frontend_type>text</frontend_type>
46
+ <sort_order>4</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>1</show_in_store>
50
+ </gateway_id>
51
+ <hmac_key translate="label">
52
+ <comment>Provided by Paystation</comment>
53
+ <label>HMAC key</label>
54
+ <frontend_type>text</frontend_type>
55
+ <sort_order>5</sort_order>
56
+ <show_in_default>1</show_in_default>
57
+ <show_in_website>1</show_in_website>
58
+ <show_in_store>1</show_in_store>
59
+ </hmac_key>
60
+
61
+
62
+ <postback translate="label">
63
+ <comment>
64
+ <![CDATA[
65
+ We strongly suggest setting 'Enable Postback' to 'Yes' as it will allow the cart to capture payment results even
66
+ if your customers re-direct is interrupted. However, if your development/test environment is local or on a network
67
+ that cannot receive connections from the internet, you must set 'Enable Postback' to 'No'.<br/><br/>
68
+
69
+ Your Paystation account needs to reflect your Magento settings accurately, otherwise order status will not update correctly.
70
+ Email <b>info@paystation.co.nz</b> with your Paystation ID and advise whether 'Enable Postback' is set to 'Yes' or 'No' in your Magento settings.
71
+ ]]>
72
+ </comment>
73
+ <label>Enable PostBack</label>
74
+ <frontend_type>select</frontend_type>
75
+ <source_model>adminhtml/system_config_source_yesno</source_model>
76
+ <sort_order>6</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>1</show_in_website>
79
+ <show_in_store>1</show_in_store>
80
+ </postback>
81
+ <testmode translate="label">
82
+ <label>Test Mode</label>
83
+ <frontend_type>select</frontend_type>
84
+ <source_model>adminhtml/system_config_source_yesno</source_model>
85
+ <sort_order>7</sort_order>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>1</show_in_website>
88
+ <show_in_store>1</show_in_store>
89
+ </testmode>
90
+ <sort_order translate="label">
91
+ <comment>Optional parameter - controlls the order payment methods are
92
+ displayed in the checkout.</comment>
93
+ <label>Sort order</label>
94
+ <frontend_type>text</frontend_type>
95
+ <sort_order>100</sort_order>
96
+ <show_in_default>1</show_in_default>
97
+ <show_in_website>1</show_in_website>
98
+ <show_in_store>1</show_in_store>
99
+ </sort_order>
100
+ </fields>
101
+ </paystation_standard>
102
+ </groups>
103
+ </payment>
104
+ </sections>
105
+ </config>
app/etc/modules/Mage_Paystation.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <modules>
3
+
4
+ <Mage_Paystation>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <depends>
8
+ <Mage_Paygate />
9
+ </depends>
10
+ <version>0.1.0</version>
11
+ </Mage_Paystation>
12
+
13
+ </modules>
14
+ </config>
15
+
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>