SecurePay_SecureXML - Version 1.0.0

Version Notes

In the config options, select Authorize for preauth/complete mode, or Authorize and Capture for standard payment mode.

If there is a problem with the initial transaction, the bank response code and text will be displayed to the user.

Download this release

Release Info

Developer Magento Core Team
Extension SecurePay_SecureXML
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/SecurePay/Sxml/Block/Form/Cc.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class SecurePay_Sxml_Block_Form_Cc extends Mage_Payment_Block_Form_Cc
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->setTemplate('sxml/form/cc.phtml');
9
+ }
10
+ }
11
+
12
+ ?>
app/code/local/SecurePay/Sxml/Helper/Data.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Data helper
4
+ */
5
+ class SecurePay_Sxml_Helper_Data extends Mage_Core_Helper_Abstract
6
+ {
7
+
8
+ }
9
+ ?>
app/code/local/SecurePay/Sxml/Model/Source/Cctype.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class SecurePay_Sxml_Model_Source_Cctype extends Mage_Payment_Model_Source_Cctype
4
+ {
5
+ public function getAllowedTypes()
6
+ {
7
+ return array('VI', 'DN', 'AE','OT','MC');
8
+ }
9
+ }
10
+ ?>
app/code/local/SecurePay/Sxml/Model/Sxml.php ADDED
@@ -0,0 +1,427 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SecurePay Sxml Extension
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
+ * @category SecurePay
16
+ * @package Sxml
17
+ * @author Andrew Dubbeld (support@securepay.com.au)
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ *
20
+ * @notes Partially derived from the Fontis SecurePay module, Copyright (c) 2008 Fontis Pty. Ltd. (http://www.fontis.com.au)
21
+ */
22
+
23
+ require_once('SecurePay/securepay_xml_api.php');
24
+
25
+ /**
26
+ * SecurePay_Sxml_Model_Sxml
27
+ *
28
+ * The bulk of the SecurePay XML API payment module. It handles Preauth/Advice, Standard, Reverse and Refund transactions in the Magento application.
29
+ */
30
+ class SecurePay_Sxml_Model_Sxml extends Mage_Payment_Model_Method_Cc
31
+ {
32
+ protected $_code = 'Sxml';
33
+
34
+ protected $_isGateway = true;
35
+ protected $_canAuthorize = true;
36
+ protected $_canCapture = true;
37
+ protected $_canCapturePartial = true;
38
+ protected $_canRefund = true;
39
+ protected $_canVoid = true;
40
+ protected $_canUseInternal = true;
41
+ protected $_canUseCheckout = true;
42
+ protected $_canUseForMultishipping = true;
43
+ protected $_canSaveCc = false;
44
+
45
+ protected $_formBlockType = 'SecurePay_Sxml_block_form_cc';
46
+
47
+ const STATUS_APPROVED = 'Approved';
48
+
49
+ const PAYMENT_ACTION_AUTH_CAPTURE = 'authorize_capture';
50
+ const PAYMENT_ACTION_AUTH = 'authorize';
51
+
52
+ public function getDebug()
53
+ {
54
+ return Mage::getStoreConfig('payment/Sxml/debug');
55
+ }
56
+
57
+ public function getMode()
58
+ {
59
+ if(Mage::getStoreConfig('payment/Sxml/test'))
60
+ {
61
+ return SECUREPAY_GATEWAY_MODE_TEST;
62
+ }
63
+
64
+ return SECUREPAY_GATEWAY_MODE_LIVE;
65
+ }
66
+
67
+ public function getLogPath()
68
+ {
69
+ return Mage::getBaseDir() . '/var/log/Sxml.log';
70
+ }
71
+
72
+ public function getUsername()
73
+ {
74
+ return Mage::getStoreConfig('payment/Sxml/username');
75
+ }
76
+
77
+ public function getPassword()
78
+ {
79
+ return Mage::getStoreConfig('payment/Sxml/password');
80
+ }
81
+
82
+ public function getCCVStatus()
83
+ {
84
+ return Mage::getStoreConfig('payment/Sxml/usecvv');
85
+ }
86
+
87
+ public function getCurrency()
88
+ {
89
+ return $this->getInfoInstance()->getQuote()->getBaseCurrencyCode();
90
+ }
91
+
92
+
93
+ /**
94
+ * validate
95
+ *
96
+ * Checks form data before it is submitted to processing functions.
97
+ *
98
+ * @param Varien_Object $payment
99
+ * @param int/float $amount
100
+ *
101
+ * @return Mage_Payment_Model_Method_Cc $this.
102
+ */
103
+ public function validate()
104
+ {
105
+ if($this->getDebug())
106
+ {
107
+ $writer = new Zend_Log_Writer_Stream($this->getLogPath());
108
+ $logger = new Zend_Log($writer);
109
+ }
110
+
111
+ //parent::validate();
112
+ $paymentInfo = $this->getInfoInstance();
113
+
114
+ if ($paymentInfo instanceof Mage_Sales_Model_Order_Payment)
115
+ {
116
+ $currency_code = $paymentInfo->getOrder()->getBaseCurrencyCode();
117
+ }
118
+ else
119
+ {
120
+ $currency_code = $paymentInfo->getQuote()->getBaseCurrencyCode();
121
+ }
122
+
123
+ return $this;
124
+ }
125
+
126
+ /**
127
+ * authorize
128
+ *
129
+ * Sends a preauth transaction to the SecurePay Gateway. Only called in "Authorize" mode (See module settings).
130
+ *
131
+ * @param Varien_Object $payment
132
+ * @param int/float $amount
133
+ *
134
+ * @return Mage_Payment_Model_Method_Cc $this. Failure will throw Mage::throwException(), and the except value will be displayed to the customer. (!)
135
+ */
136
+ public function authorize(Varien_Object $payment, $amount)
137
+ {
138
+ if($this->getDebug())
139
+ {
140
+ $writer = new Zend_Log_Writer_Stream($this->getLogPath());
141
+ $logger = new Zend_Log($writer);
142
+ }
143
+
144
+ //Create the transaction object
145
+ $sxml = new securepay_xml_transaction ($this->getMode(),trim($this->getUsername()),trim($this->getPassword()));
146
+
147
+ $transaction_id = $payment->getOrder()->getIncrementId();
148
+
149
+ //Issue the preauth
150
+ $preauthID = $sxml->processCreditPreauth($amount,$transaction_id,$payment->getCcNumber(),
151
+ $payment->getCcExpMonth(),$payment->getCcExpYear(),$payment->getCcCid());
152
+
153
+ $txnResultCodeText = $sxml->getErrorString();
154
+ $approved = strtoupper($sxml->getResultByKeyName('approved'))=='YES'?true:false;
155
+ $status = $sxml->getResultByKeyName('responseCode');
156
+
157
+ $payment->setCcTransId(''.$preauthID);
158
+
159
+ if($this->getDebug())
160
+ {
161
+ if($approved)
162
+ {
163
+ $logger->info( "Preauth Approved. Preauth: ".$payment->getCcTransId() );
164
+ }
165
+ else
166
+ {
167
+ $logger->info( "Preauth Declined. ".$txnResultCodeText );
168
+ }
169
+ }
170
+
171
+ if($status == '000' || $status == '008')
172
+ {
173
+ if ($approved==false)
174
+ {
175
+ $this->setError(array('message' => $txnResultCodeText,));
176
+ Mage::throwException("" . $txnResultCodeText);
177
+ }
178
+ }
179
+ else
180
+ {
181
+ $this->setError(array('message' => $txnResultCodeText,));
182
+ Mage::throwException("" . $txnResultCodeText);
183
+ }
184
+
185
+ return $this;
186
+ }
187
+
188
+ /**
189
+ * capture
190
+ *
191
+ * Completes a preauthorised transaction in preauth (Authorize) mode OR processes a standard transaction in standard (Authorize+Capture) mode.
192
+ * This function can be called in two possible situations:
193
+ * 1. When the payment module is set to "Authorize", the module is in Preauth/Advice mode, and payments are preauthorized ($this->authorize()) when a user
194
+ * submits an order. Later on, the store owner needs to manually capture the payment, and this function is called.
195
+ * 2. When the payment module is set to "Authorize & Capture", or Standard mode, credit-card/order details are passed directly to this function after
196
+ * customer form submission.
197
+ * This function will store a gateway response id in $payment->CcTransId to facilitate void/refunds.
198
+ *
199
+ * @param Varien_Object $payment
200
+ * @param int/float $amount
201
+ *
202
+ * @return Mage_Payment_Model_Method_Cc $this. Failure will throw Mage::throwException(); in Standard mode the except value is displayed to the customer (!)
203
+ */
204
+
205
+ public function capture(Varien_Object $payment, $amount)
206
+ {
207
+ if($this->getDebug())
208
+ {
209
+ $writer = new Zend_Log_Writer_Stream($this->getLogPath());
210
+ $logger = new Zend_Log($writer);
211
+ }
212
+ $preauth = $payment->getCcTransId();
213
+
214
+ $txnType = "Advice";
215
+
216
+ if(!$preauth)
217
+ {
218
+ if($payment->getCcExpYear())
219
+ {
220
+ $txnType = "Standard";
221
+ }
222
+ else
223
+ {
224
+ if($this->getDebug())
225
+ {
226
+ $logger->info( "SecurePay_Sxml_Model_Sxml->capture(): CC details are missing in 'Preauth + Capture'. This should not happen.");
227
+ }
228
+ Mage::throwException("CC details missing.");
229
+ }
230
+ }
231
+
232
+ //Create the transaction object
233
+ $sxml = new securepay_xml_transaction ($this->getMode(),$this->getUsername(),$this->getPassword());
234
+
235
+ $transaction_id = $payment->getOrder()->getIncrementId();
236
+
237
+ if($txnType == "Advice")
238
+ {
239
+ //Issue an advice transaction
240
+ $bankTxnID = $sxml->processCreditAdvice($amount,$transaction_id,$preauth);
241
+ }
242
+ else if ($txnType == "Standard")
243
+ {
244
+ //Issue a standard transaction
245
+ $bankTxnID = $sxml->processCreditStandard($amount,$transaction_id,$payment->getCcNumber(),
246
+ $payment->getCcExpMonth(),$payment->getCcExpYear(),$payment->getCcCid());
247
+ }
248
+ else
249
+ {
250
+ Mage::throwException("Unknown transaction type.");
251
+ }
252
+
253
+ $txnResultCodeText = $sxml->getErrorString();
254
+ $approved = strtoupper($sxml->getResultByKeyName('approved'))=='YES'?true:false;
255
+ $status = $sxml->getResultByKeyName('responseCode');
256
+
257
+ if($bankTxnID)
258
+ {
259
+ $payment->setCcTransId(''.$bankTxnID);
260
+ }
261
+
262
+ if($this->getDebug())
263
+ {
264
+ if($approved)
265
+ {
266
+ $logger->info( "Advice/Standard Approved. Response ID: ".$payment->getCcTransId() );
267
+ }
268
+ else
269
+ {
270
+ $logger->info( "Advice/Standard Declined. ".$txnResultCodeText );
271
+ }
272
+ }
273
+
274
+ if($status == '000' || $status == '008')
275
+ {
276
+ if ($approved==false)
277
+ {
278
+ Mage::throwException("" . $txnResultCodeText);
279
+ }
280
+ }
281
+ else
282
+ {
283
+ Mage::throwException("" . $txnResultCodeText);
284
+ }
285
+
286
+ return $this;
287
+ }
288
+
289
+ /**
290
+ * void
291
+ *
292
+ * Handles reverse transactions.
293
+ *
294
+ * @param Varien_Object $payment
295
+ * @param int/float $amount
296
+ *
297
+ * @return Mage_Payment_Model_Method_Cc $this. Failure will throw Mage::throwException('description')
298
+ */
299
+ public function void(Varien_Object $payment)
300
+ {
301
+ if($this->getDebug())
302
+ {
303
+ $writer = new Zend_Log_Writer_Stream($this->getLogPath());
304
+ $logger = new Zend_Log($writer);
305
+ }
306
+ $amount = $payment->getOrder()->getData('grand_total');
307
+
308
+ $bankRespID = $payment->getCcTransId();
309
+
310
+ if(!$bankRespID)
311
+ {
312
+ Mage::throwException("Cannot issue a void on this transaction: bank response id is missing.");
313
+ }
314
+ if(!$amount)
315
+ {
316
+ Mage::throwException("Cannot issue a void on this transaction: transaction amount is missing.");
317
+ }
318
+
319
+ //Create the transaction object
320
+ $sxml = new securepay_xml_transaction ($this->getMode(),$this->getUsername(),$this->getPassword());
321
+
322
+ $transaction_id = $payment->getOrder()->getIncrementId();
323
+
324
+ //Issue a reverse transaction
325
+ $bankTxnID = $sxml->processCreditReverse($amount,$transaction_id,$bankRespID);
326
+
327
+ $txnResultCodeText = $sxml->getErrorString();
328
+ $approved = strtoupper($sxml->getResultByKeyName('approved'))=='YES'?true:false;
329
+ $status = $sxml->getResultByKeyName('responseCode');
330
+
331
+ if($bankTxnID)
332
+ {
333
+ $payment->setCcTransId(''.$bankTxnID);
334
+ }
335
+
336
+ if($this->getDebug())
337
+ {
338
+ if($approved)
339
+ {
340
+ $logger->info( "Void Approved. Response ID: ".$payment->getCcTransId() );
341
+ }
342
+ else
343
+ {
344
+ $logger->info( "Void Declined. ".$txnResultCodeText."; TransID: ".$payment->getCcTransId() );
345
+ }
346
+ }
347
+
348
+ if($status == '000' || $status == '008')
349
+ {
350
+ if ($approved==false)
351
+ {
352
+ Mage::throwException("" . $txnResultCodeText);
353
+ }
354
+ }
355
+ else
356
+ {
357
+ Mage::throwException("" . $txnResultCodeText);
358
+ }
359
+
360
+ return $this;
361
+ }
362
+
363
+ /**
364
+ * refund
365
+ *
366
+ * Processes a partial or whole refund on an existing transaction.
367
+ *
368
+ * @param Varien_Object $payment
369
+ * @param int/float $amount
370
+ *
371
+ * @return Mage_Payment_Model_Method_Cc $this. Failure will throw Mage::throwException('description')
372
+ */
373
+ public function refund(Varien_Object $payment, $amount)
374
+ {
375
+ if($this->getDebug())
376
+ {
377
+ $writer = new Zend_Log_Writer_Stream($this->getLogPath());
378
+ $logger = new Zend_Log($writer);
379
+ }
380
+
381
+ $bankRespID = $payment->getCcTransId();
382
+
383
+ if(!$bankRespID)
384
+ {
385
+ Mage::throwException("Cannot issue a refund on this transaction: bank response id is missing.");
386
+ }
387
+
388
+ //Create the transaction object
389
+ $sxml = new securepay_xml_transaction ($this->getMode(),$this->getUsername(),$this->getPassword());
390
+
391
+ $transaction_id = $payment->getOrder()->getIncrementId();
392
+
393
+ //Issue a refund transaction
394
+ $bankTxnID = $sxml->processCreditRefund($amount,$transaction_id,$bankRespID);
395
+
396
+ $txnResultCodeText = $sxml->getErrorString();
397
+ $approved = strtoupper($sxml->getResultByKeyName('approved'))=='YES'?true:false;
398
+ $status = $sxml->getResultByKeyName('responseCode');
399
+
400
+ /* Don't reset $payment->CcTransId for refunds, so that more than one is possible. This means that the gateway response id ($bankTxnID) is not stored here. If necessary, it can be recovered from the SecurePay Merchant Management Facility. http://securepay.com.au */
401
+
402
+ if($this->getDebug())
403
+ {
404
+ if($approved)
405
+ {
406
+ $logger->info( "Refund Approved. Response ID: ".$bankTxnID );
407
+ }
408
+ else
409
+ {
410
+ $logger->info( "Refund Declined. ".$txnResultCodeText );
411
+ }
412
+ }
413
+
414
+ if($status == '000' || $status == '008')
415
+ {
416
+ if ($approved==false)
417
+ {
418
+ Mage::throwException("" . $txnResultCodeText);
419
+ }
420
+ }
421
+ else
422
+ {
423
+ Mage::throwException("" . $txnResultCodeText);
424
+ }
425
+ return $this;
426
+ }
427
+ }
app/code/local/SecurePay/Sxml/Model/Sxml/PaymentAction.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * SecurePay SecurePayXML Extension
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
+ * @category SecurePay
16
+ * @package SecurePay_SecurePayXML
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+
20
+ class SecurePay_Sxml_Model_Sxml_PaymentAction
21
+ {
22
+ public function toOptionArray()
23
+ {
24
+ return array(
25
+ array(
26
+ 'value' => SecurePay_Sxml_Model_Sxml::PAYMENT_ACTION_AUTH_CAPTURE,
27
+ 'label' => Mage::helper('Sxml')->__('Authorize and Capture')
28
+ ),
29
+ array(
30
+ 'value' => SecurePay_Sxml_Model_Sxml::PAYMENT_ACTION_AUTH,
31
+ 'label' => Mage::helper('Sxml')->__('Authorize')
32
+ )
33
+ );
34
+ }
35
+ }
36
+
37
+ ?>
app/code/local/SecurePay/Sxml/Model/Sxml/Request.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class SecurePay_Sxml_Model_Sxml_Request extends Varien_Object
4
+ {
5
+
6
+ }
7
+
8
+ ?>
app/code/local/SecurePay/Sxml/Model/Sxml/Result.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class SecurePay_Sxml_Model_Sxml_Result extends Varien_Object
4
+ {
5
+
6
+ }
7
+
8
+ ?>
app/code/local/SecurePay/Sxml/etc/config.xml ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <modules>
5
+ <SecurePay_Sxml>
6
+ <version>0.1.0</version>
7
+ <depends>
8
+ <Mage_payment />
9
+ </depends>
10
+ </SecurePay_Sxml>
11
+ </modules>
12
+ <global>
13
+ <models>
14
+ <Sxml>
15
+ <class>SecurePay_Sxml_Model</class>
16
+ </Sxml>
17
+ </models>
18
+ <blocks>
19
+ <Sxml>
20
+ <class>SecurePay_Sxml_Block</class>
21
+ </Sxml>
22
+ </blocks>
23
+ <helpers>
24
+ <Sxml>
25
+ <class>SecurePay_sxml_Helper</class>
26
+ </Sxml>
27
+ </helpers>
28
+ <resources>
29
+ <sxml_setup>
30
+ <setup>
31
+ <module>SecurePay_sxml</module>
32
+ </setup>
33
+ <connection>
34
+ <use>local_setup</use>
35
+ </connection>
36
+ </sxml_setup>
37
+ <sxml_write>
38
+ <connection>
39
+ <use>local_write</use>
40
+ </connection>
41
+ </sxml_write>
42
+ <sxml_read>
43
+ <connection>
44
+ <use>local_read</use>
45
+ </connection>
46
+ </sxml_read>
47
+ </resources>
48
+ <payment>
49
+ <cc>
50
+ <types>
51
+ <DN>
52
+ <code>DN</code>
53
+ <name>Diners</name>
54
+ <order>100</order>
55
+ </DN>
56
+ </types>
57
+ </cc>
58
+ </payment>
59
+ </global>
60
+ <default>
61
+ <payment>
62
+ <Sxml>
63
+ <active>1</active>
64
+ <model>Sxml/Sxml</model>
65
+ <username>Change me</username>
66
+ <password>Change me</password>
67
+ <title>Credit Card (Securepay)</title>
68
+ <allowspecific>0</allowspecific>
69
+ <debug>1</debug>
70
+ <test>1</test>
71
+ <usecvv>0</usecvv>
72
+ <!--<cctypes>AE,VI,MC,DN</cctypes>-->
73
+ <payment_action>authorize</payment_action>
74
+ </Sxml>
75
+ </payment>
76
+ </default>
77
+ </config>
app/code/local/SecurePay/Sxml/etc/system.xml ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <config>
4
+ <sections>
5
+ <payment translate="label">
6
+ <groups>
7
+ <Sxml translate="label">
8
+ <label>Credit Card (SecurePay)</label>
9
+ <frontend_type>text</frontend_type>
10
+ <sort_order>1</sort_order>
11
+ <show_in_default>1</show_in_default>
12
+ <show_in_website>1</show_in_website>
13
+ <show_in_store>0</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>0</show_in_store>
23
+ </active>
24
+ <test translate="label">
25
+ <label>Test mode</label>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_yesno</source_model>
28
+ <sort_order>5</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>1</show_in_website>
31
+ <show_in_store>0</show_in_store>
32
+ </test>
33
+ <order_status translate="label">
34
+ <label>New order status</label>
35
+ <frontend_type>select</frontend_type>
36
+ <source_model>adminhtml/system_config_source_order_status</source_model>
37
+ <sort_order>9</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>1</show_in_website>
40
+ <show_in_store>0</show_in_store>
41
+ </order_status>
42
+ <sort_order translate="label">
43
+ <label>Sort order</label>
44
+ <frontend_type>text</frontend_type>
45
+ <sort_order>100</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>0</show_in_store>
49
+ </sort_order>
50
+ <useccv translate="label">
51
+ <label>Credit Card Verification</label>
52
+ <frontend_type>select</frontend_type>
53
+ <source_model>adminhtml/system_config_source_yesno</source_model>
54
+ <sort_order>12</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>1</show_in_website>
57
+ <show_in_store>0</show_in_store>
58
+ </useccv>
59
+ <title translate="label">
60
+ <label>Title</label>
61
+ <frontend_type>text</frontend_type>
62
+ <sort_order>1</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>1</show_in_website>
65
+ <show_in_store>0</show_in_store>
66
+ </title>
67
+ <username translate="label">
68
+ <label>Merchant ID</label>
69
+ <frontend_type>text</frontend_type>
70
+ <sort_order>20</sort_order>
71
+ <show_in_default>1</show_in_default>
72
+ <show_in_website>1</show_in_website>
73
+ <show_in_store>0</show_in_store>
74
+ </username>
75
+ <password translate="label">
76
+ <label>Merchant Password</label>
77
+ <frontend_type>text</frontend_type>
78
+ <sort_order>21</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>0</show_in_store>
82
+ </password>
83
+ <payment_action translate="label">
84
+ <label>Action</label>
85
+ <frontend_type>select</frontend_type>
86
+ <source_model>Sxml/sxml_paymentAction</source_model>
87
+ <sort_order>22</sort_order>
88
+ <show_in_default>1</show_in_default>
89
+ <show_in_website>1</show_in_website>
90
+ <show_in_store>0</show_in_store>
91
+ </payment_action>
92
+ <debug translate="label">
93
+ <label>Debug</label>
94
+ <frontend_type>select</frontend_type>
95
+ <source_model>adminhtml/system_config_source_yesno</source_model>
96
+ <sort_order>40</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>0</show_in_store>
100
+ </debug>
101
+ <allowspecific translate="label">
102
+ <label>Payment from applicable countries</label>
103
+ <frontend_type>allowspecific</frontend_type>
104
+ <sort_order>50</sort_order>
105
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
106
+ <show_in_default>1</show_in_default>
107
+ <show_in_website>1</show_in_website>
108
+ <show_in_store>1</show_in_store>
109
+ </allowspecific>
110
+ <specificcountry translate="label">
111
+ <label>Payment from Specific countries</label>
112
+ <frontend_type>multiselect</frontend_type>
113
+ <sort_order>51</sort_order>
114
+ <source_model>adminhtml/system_config_source_country</source_model>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>1</show_in_website>
117
+ <show_in_store>1</show_in_store>
118
+ </specificcountry>
119
+ </fields>
120
+ </Sxml>
121
+ </groups>
122
+ </payment>
123
+ </sections>
124
+ </config>
app/code/local/SecurePay/securepay_xml_api.php ADDED
@@ -0,0 +1,1157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * securepay_xml_api.php:
5
+ *
6
+ * Contains a class for sending transaction requests to SecurePay,
7
+ * and receiving responses from the SecurePay via the XML API
8
+ *
9
+ * This class requires cURL to be available to PHP
10
+ *
11
+ */
12
+
13
+ define( 'SECUREPAY_GATEWAY_MODE_TEST', 1);
14
+ define( 'SECUREPAY_GATEWAY_MODE_LIVE', 2);
15
+ define( 'SECUREPAY_GATEWAY_MODE_PERIODIC_TEST', 3);
16
+ define( 'SECUREPAY_GATEWAY_MODE_PERIODIC_LIVE', 4);
17
+
18
+ /* The valid transaction types for this interface. */
19
+
20
+ define( 'SECUREPAY_TXN_STANDARD', 0);
21
+ define( 'SECUREPAY_TXN_REFUND', 4);
22
+ define( 'SECUREPAY_TXN_REVERSE', 6);
23
+ define( 'SECUREPAY_TXN_PREAUTH', 10); //To be included in a future revision
24
+ define( 'SECUREPAY_TXN_ADVICE', 11);
25
+
26
+ define( 'SECUREPAY_TXN_DIRECTDEBIT', 15); //To be included in a future revision
27
+ define( 'SECUREPAY_TXN_DIRECTCREDIT', 17);
28
+
29
+ define( 'SECUREPAY_TXN_IVR', 20);
30
+
31
+ define( 'SECUREPAY_REQ_ECHO', 'Echo'); //To be included in a future revision
32
+ define( 'SECUREPAY_REQ_PAYMENT', 'Payment');
33
+ define( 'SECUREPAY_REQ_PERIODIC', 'Periodic'); //To be included in a future revision
34
+
35
+ define( 'CURRENCY_DEFAULT', 'AUD');
36
+
37
+ /**
38
+ * securepay_xml_transaction
39
+ *
40
+ * This class handles XML SecurePay transactions
41
+ *
42
+ * It supports the following tranactions:
43
+ * Credit Payment (standard)
44
+ * Credit Refund
45
+ * Credit Reversal
46
+ * Credit Preauthorisation
47
+ * Credit Preauthorised completion (Advice)
48
+ *
49
+ * It partially supports the following transactions (which are not yet required):
50
+ * Direct Entry Credit
51
+ * Direct Entry Debit
52
+ *
53
+ * It can support the following transactions in future:
54
+ * Add Trigger/Peridic Payment
55
+ * Delete Trigger/Periodic Payment
56
+ * Trigger Triggered payment
57
+ *
58
+ * @param int mode - The kind of transaction object you would like to open. i.e. SECUREPAY_GATEWAY_MODE_TEST See top of this file for definitions.
59
+ * @param string merchantID - The merchant's login ID, received from SecurePay
60
+ * @param string merchantPW - The merchant's login password
61
+ */
62
+
63
+ class securepay_xml_transaction
64
+ {
65
+ const SECUREPAY_TEST_HOST = "https://www.securepay.com.au/test/payment";
66
+ const SECUREPAY_LIVE_HOST = "https://www.securepay.com.au/xmlapi/payment";
67
+
68
+ const TIMEOUT="60";
69
+
70
+ const GATEWAY_ERROR_OBJECT_INVALID = "The Gateway Object is invalid (constructor failure?)";
71
+ const GATEWAY_ERROR_CURL_ERROR = "CURL failed and reported the following error";
72
+ const GATEWAY_ERROR_INVALID_CCNUMBER = "Parameter Check failure: Invalid credit card number";
73
+ const GATEWAY_ERROR_INVALID_CCEXPIRY = "Parameter Check failure: Invalid credit card expiry date";
74
+ const GATEWAY_ERROR_INVALID_CC_CVC = "Parameter Check failure: Invalid credit card verification code";
75
+ const GATEWAY_ERROR_INVALID_TXN_AMT = "Parameter Check failure: Invalid transaction amount";
76
+ const GATEWAY_ERROR_INVALID_REF_ID = "Parameter Check failure: Invalid transaction reference number";
77
+ const GATEWAY_ERROR_INVALID_ACCOUNTNUMBER = "Parameter Check failure: Invalid account number";
78
+ const GATEWAY_ERROR_INVALID_ACCOUNTNAME = "Parameter Check failure: Invalid account name";
79
+ const GATEWAY_ERROR_INVALID_ACCOUNTBSB = "Parameter Check failure: Invalid BSB";
80
+ const GATEWAY_ERROR_RESPONSE_ERROR = "A general response error was detected";
81
+ const GATEWAY_ERROR_RESPONSE_INVALID = "A unspecified error was detected in the response content";
82
+ const GATEWAY_ERROR_XML_PARSE_FAILED = "The response message could not be parsed (invalid XML?)";
83
+ const GATEWAY_ERROR_RESPONSE_XML_MESSAGE_ERROR = "An unspecified error was found in the response message (missing field?)";
84
+ const GATEWAY_ERROR_SECUREPAY_STATUS = "The remote Gateway reported the following status error";
85
+ const GATEWAY_ERROR_TXN_DECLINED = "Transaction Declined";
86
+
87
+ private $errorString;
88
+ private $gatewayObjectValid = true;
89
+ private $gatewayURL;
90
+ private $merchantID;
91
+ private $merchantPW;
92
+ private $responseArray = array();
93
+ private $txnType;
94
+
95
+ private $ccNumber;
96
+ private $ccVerify;
97
+ private $ccExpiryMonth;
98
+ private $ccExpiryYear;
99
+
100
+ private $accNumber;
101
+ private $accBSB;
102
+ private $accName;
103
+
104
+ private $txnReference;
105
+ private $amount;
106
+
107
+ private $currency=CURRENCY_DEFAULT;
108
+
109
+ private $requestType;
110
+ private $periodicType;
111
+ private $periodicInterval;
112
+
113
+ private $bankTxnID = 0;
114
+
115
+ /**
116
+ * __construct
117
+ *
118
+ * @param integer $gatewaymode
119
+ * @param string $setup_merchantID
120
+ * @param string $setup_merchantPW
121
+ *
122
+ */
123
+ public function __construct( $gatewaymode, $setup_merchantID, $setup_merchantPW)
124
+ {
125
+
126
+ switch ( $gatewaymode )
127
+ {
128
+ case SECUREPAY_GATEWAY_MODE_TEST:
129
+ $this->gatewayURL = self::SECUREPAY_TEST_HOST;
130
+ break;
131
+
132
+ case SECUREPAY_GATEWAY_MODE_LIVE:
133
+ $this->gatewayURL = self::SECUREPAY_LIVE_HOST;
134
+ break;
135
+
136
+ default:
137
+ $this->gatewayObjectValid = false;
138
+ return;
139
+ }
140
+
141
+ if ( strlen( $setup_merchantID ) == 0
142
+ || strlen( $setup_merchantPW ) == 0 )
143
+ {
144
+ $this->gatewayObjectValid = false;
145
+ return;
146
+ }
147
+
148
+ $this->setAuth($setup_merchantID,$setup_merchantPW);
149
+
150
+ }
151
+
152
+ /**
153
+ * reset
154
+ *
155
+ * To clear response variables: prevents mismatched results in certain failure cases.
156
+ * This is called before each transaction, so be sure to check these values between transactions.
157
+ */
158
+ public function reset()
159
+ {
160
+ $this->errorString = NULL;
161
+ $this->responseArray = array();
162
+ $this->bankTxnID = 0;
163
+ }
164
+
165
+ public function isGatewayObjectValid()
166
+ {
167
+ return $this->gatewayObjectValid;
168
+ }
169
+
170
+ public function getAmount()
171
+ {
172
+ return $this->amount;
173
+ }
174
+
175
+ /**
176
+ * setAmount
177
+ *
178
+ * Takes amount as a float; requires currency to be set
179
+ *
180
+ * @param float amount
181
+ */
182
+ public function setAmount($amount)
183
+ {
184
+ if($this->getCurrency() == 'JPY')
185
+ $this->amount = $amount;
186
+ else
187
+ $this->amount = round($amount*100,0);
188
+ return;
189
+ }
190
+
191
+ public function getCurrency()
192
+ {
193
+ return $this->currency;
194
+ }
195
+
196
+ public function setCurrency($cur)
197
+ {
198
+ $this->currency = $cur;
199
+ return;
200
+ }
201
+
202
+ public function getTxnReference()
203
+ {
204
+ return $this->txnReference;
205
+ }
206
+
207
+ public function setTxnReference($ref)
208
+ {
209
+ $this->txnReference = $ref;
210
+ return;
211
+ }
212
+
213
+ public function getTxnType()
214
+ {
215
+ return $this->txnType;
216
+ }
217
+
218
+ public function setTxnType($type)
219
+ {
220
+ $this->txnType = $type;
221
+ return;
222
+ }
223
+
224
+ public function getPreauthID()
225
+ {
226
+ return $this->preauthID;
227
+ }
228
+
229
+ public function setPreauthID($id)
230
+ {
231
+ $this->preauthID = $id;
232
+ return;
233
+ }
234
+
235
+ public function getAccBSB()
236
+ {
237
+ return $this->accBSB;
238
+ }
239
+
240
+ public function setAccBSB($bsb)
241
+ {
242
+ $this->accBSB = $bsb;
243
+ return;
244
+ }
245
+
246
+ public function getAccNumber()
247
+ {
248
+ return $this->accNumber;
249
+ }
250
+
251
+ public function setAccNumber($Number)
252
+ {
253
+ $this->accNumber = $Number;
254
+ return;
255
+ }
256
+
257
+ public function getAccName()
258
+ {
259
+ return $this->accName;
260
+ }
261
+
262
+ public function setAccName($name)
263
+ {
264
+ $this->accName = $name;
265
+ return;
266
+ }
267
+
268
+ public function getCCNumber()
269
+ {
270
+ return $this->ccNumber;
271
+ }
272
+
273
+ public function setCCNumber($ccNumber)
274
+ {
275
+ $this->ccNumber = $ccNumber;
276
+ return;
277
+ }
278
+
279
+ public function getClearCCNumber()
280
+ {
281
+ $t = $this->getCCNumber();
282
+ $this->setCCNumber("0");
283
+ return $t;
284
+ }
285
+
286
+ public function getCCVerify()
287
+ {
288
+ return $this->ccVerify;
289
+ }
290
+
291
+ public function setCCVerify($ver)
292
+ {
293
+ $this->ccVerify = $ver;
294
+ return;
295
+ }
296
+
297
+ public function getClearCCVerify()
298
+ {
299
+ $t = $this->getCCVerify();
300
+ $this->setCCVerify(0);
301
+ return $t;
302
+ }
303
+
304
+ /* @return string month MM*/
305
+ public function getCCExpiryMonth()
306
+ {
307
+ return $this->ccExpiryMonth;
308
+ }
309
+
310
+ /* @param string/int month MM or month M - If there are leading zeros, type needs to be a string*/
311
+ public function setCCExpiryMonth($month)
312
+ {
313
+ $l = strlen(trim($month));
314
+ if($l == 1)
315
+ $this->ccExpiryMonth = sprintf("%02d",ltrim($month,'0'));
316
+ else
317
+ $this->ccExpiryMonth = $month;
318
+ return;
319
+ }
320
+
321
+ /* @return string year YY*/
322
+ public function getCCExpiryYear()
323
+ {
324
+ return $this->ccExpiryYear;
325
+ }
326
+
327
+ /* @param string year YY or year YYYY - If there are leading zeros, type needs to be a string*/
328
+ public function setCCExpiryYear($year)
329
+ {
330
+ $y = ltrim(trim((string)$year),"0");
331
+ $l = strlen($y);
332
+ if($l==4)
333
+ $this->ccExpiryYear = substr($y,2);
334
+ else if($l>=5)
335
+ $this->ccExpiryYear = 0;
336
+ else if($l==1)
337
+ $this->ccExpiryYear = sprintf("%02d",$y);
338
+ else
339
+ $this->ccExpiryYear = $year;
340
+
341
+ return;
342
+ }
343
+
344
+ public function getMerchantID()
345
+ {
346
+ return $this->merchantID;
347
+ }
348
+
349
+ public function setMerchantID($id)
350
+ {
351
+ $this->merchantID = $id;
352
+ return;
353
+ }
354
+
355
+ public function getMerchantPW ()
356
+ {
357
+ return $this->merchantPW;
358
+ }
359
+
360
+ public function setMerchantPW ($pw)
361
+ {
362
+ $this->merchantPW = $pw;
363
+ return;
364
+ }
365
+
366
+ public function getBankTxnID ()
367
+ {
368
+ return $this->bankTxnID;
369
+ }
370
+
371
+ public function setBankTxnID ($id)
372
+ {
373
+ $this->bankTxnID = $id;
374
+ return;
375
+ }
376
+
377
+ public function getRequestType ()
378
+ {
379
+ return $this->requestType;
380
+ }
381
+
382
+ public function setRequestType ($t)
383
+ {
384
+ $this->requestType = $t;
385
+ return;
386
+ }
387
+
388
+ public function getPeriodicType ()
389
+ {
390
+ return $this->periodicType;
391
+ }
392
+
393
+ public function setPeriodicType ($t)
394
+ {
395
+ $this->periodicType = $t;
396
+ return;
397
+ }
398
+
399
+ public function getPeriodicInterval ()
400
+ {
401
+ return $this->periodicInterval;
402
+ }
403
+
404
+ public function setPeriodicInterval ($t)
405
+ {
406
+ $this->periodicInterval = $t;
407
+ return;
408
+ }
409
+
410
+ public function getErrorString ()
411
+ {
412
+ return $this->errorString;
413
+ }
414
+
415
+ public function getResultArray ()
416
+ {
417
+ return $this->responseArray;
418
+ }
419
+
420
+ public function getResultByKeyName ( $keyName)
421
+ {
422
+ if ( array_key_exists( $keyName, $this->responseArray) === true )
423
+ {
424
+ return $this->responseArray[$keyName];
425
+ }
426
+ else
427
+ return false;
428
+ }
429
+
430
+ public function getTxnWasSuccesful()
431
+ {
432
+ if ( array_key_exists( "txnResult", $this->responseArray) === true
433
+ && $this->responseArray["txnResult"] === true )
434
+ return true;
435
+ else
436
+ return false;
437
+ }
438
+
439
+ public function setAuth($id, $pw)
440
+ {
441
+ $this->setMerchantID($id);
442
+ $this->setMerchantPW($pw);
443
+ return;
444
+ }
445
+
446
+ /**
447
+ * processCreditStandard:
448
+ *
449
+ * Process a standard credit card payment
450
+ *
451
+ * @param float amount - Numeric and decimal only: no thousand separators
452
+ * @param string txnReference - Merchant's unique transaction ID
453
+ * @param int cardNumber - 12-18 digit credit-card number
454
+ * @param int cardMonth - 2 digit month
455
+ * @param int cardYear - 2 or 4 digit year
456
+ * @param int cardVerify - 3 or 4 digit CVV (optional)
457
+ * @param string currency - Exactly three characters. See SecurePay documentation for list of valid currencies. (optional)
458
+ *
459
+ * @return string txnID - Bank's unique transaction ID (use for reversal or refund), or FALSE in case of failure (check $this->getErrorText() afterwards).
460
+ */
461
+ public function processCreditStandard($amount, $txnReference, $cardNumber, $cardMonth, $cardYear, $cardVerify=0, $currency=CURRENCY_DEFAULT)
462
+ {
463
+ $this->reset();
464
+
465
+ $this->setTxnType(SECUREPAY_TXN_STANDARD);
466
+
467
+ $this->setAmount($amount);
468
+ $this->setTxnReference($txnReference);
469
+ $this->setCCNumber($cardNumber);
470
+ if(strlen($cardVerify)!=0)
471
+ $this->setCCVerify($cardVerify);
472
+ $this->setCCExpiryYear($cardYear);
473
+ $this->setCCExpiryMonth($cardMonth);
474
+ if($currency)
475
+ $this->setCurrency($currency);
476
+
477
+ if($this->processTransaction());
478
+ if(array_key_exists('banktxnID',$this->responseArray))
479
+ return $this->responseArray['banktxnID'];
480
+ return false;
481
+ }
482
+
483
+ /**
484
+ * processCreditRefund:
485
+ *
486
+ * Refund a standard credit card payment. $amount can be less than the original transaction.
487
+ *
488
+ * @param float amount - Numeric and decimal only: no thousand separators
489
+ * @param string txnReference - Merchant's unique transaction ID: must be same as in initial transaction
490
+ * @param int txnID - Result of original transaction
491
+ *
492
+ * @return string txnID - Bank's unique transaction ID, or FALSE in case of failure (check $this->getErrorText() afterwards).
493
+ */
494
+ public function processCreditRefund($amount, $txnReference, $txnID)
495
+ {
496
+ $this->reset();
497
+
498
+ $this->setTxnType(SECUREPAY_TXN_REFUND);
499
+
500
+ $this->setAmount($amount);
501
+ $this->setTxnReference($txnReference);
502
+
503
+ $this->setBankTxnID($txnID);
504
+
505
+ if($this->processTransaction());
506
+ if(array_key_exists('banktxnID',$this->responseArray))
507
+ return $this->responseArray['banktxnID'];
508
+ return false;
509
+ }
510
+
511
+ /**
512
+ * processCreditReverse:
513
+ *
514
+ * Reverse a standard credit card payment. $amount should be same as in original transaction.
515
+ *
516
+ * @param float amount - Numeric and decimal only: no thousand separators
517
+ * @param string txnReference - Merchant's unique transaction ID: must be same as in initial transaction
518
+ * @param int txnID - Result of original transaction
519
+ *
520
+ * @return string txnID - Bank's unique transaction ID, or FALSE in case of failure (check $this->getErrorText() afterwards).
521
+ */
522
+ public function processCreditReverse($amount, $txnReference, $txnID)
523
+ {
524
+ $this->reset();
525
+
526
+ $this->setTxnType(SECUREPAY_TXN_REVERSE);
527
+
528
+ $this->setAmount($amount);
529
+ $this->setTxnReference($txnReference);
530
+
531
+ $this->setBankTxnID($txnID);
532
+
533
+ if($this->processTransaction());
534
+ if(array_key_exists('banktxnID',$this->responseArray))
535
+ return $this->responseArray['banktxnID'];
536
+ return false;
537
+ }
538
+
539
+ /**
540
+ * processCreditPreauth:
541
+ *
542
+ * Preauthorise a credit card payment
543
+ *
544
+ * @param float amount - Numeric and decimal only: no thousand separators
545
+ * @param string txnReference - Merchant's unique transaction ID
546
+ * @param int cardNumber - 12-18 digit credit-card number
547
+ * @param int cardMonth - 2 digit month
548
+ * @param int cardYear - 2 or 4 digit year
549
+ * @param int cardVerify - 3 or 4 digit CVV (optional)
550
+ * @param string currency - Exactly three characters. See SecurePay documentation for list of valid currencies. (optional)
551
+ *
552
+ * @return string preauthID - preauthorisation ID (use to execute transaction later (processCreditAdvice)), or FALSE (check $this->getErrorText() afterwards).
553
+ */
554
+ public function processCreditPreauth($amount, $txnReference, $cardNumber, $cardMonth, $cardYear, $cardVerify=0, $currency=CURRENCY_DEFAULT)
555
+ {
556
+ $this->reset();
557
+
558
+ $this->setTxnType(SECUREPAY_TXN_PREAUTH);
559
+
560
+ $this->setAmount($amount);
561
+ $this->setTxnReference($txnReference);
562
+ $this->setCCNumber($cardNumber);
563
+ if(strlen($cardVerify)!=0)
564
+ $this->setCCVerify($cardVerify);
565
+ $this->setCCExpiryYear($cardYear);
566
+ $this->setCCExpiryMonth($cardMonth);
567
+
568
+ if($currency)
569
+ $this->setCurrency($currency);
570
+
571
+ if($this->processTransaction())
572
+ {
573
+ if(array_key_exists('preauthID',$this->responseArray))
574
+ return $this->responseArray['preauthID'];
575
+ }
576
+
577
+ return false;
578
+ }
579
+
580
+ /**
581
+ * processCreditAdvice:
582
+ *
583
+ * Execute a preauthorised transaction
584
+ *
585
+ * @param float amount - Numeric and decimal only: no thousand separators. Should be same as preauthorised amount.
586
+ * @param string txnReference - Merchant's unique transaction ID: must be same as in initial transaction
587
+ * @param string preauthID - Preauthorisation code which was returned from processCreditPreauth
588
+ *
589
+ * @return string txnID - Bank's unique transaction ID, or FALSE in case of failure (check $this->getErrorText() afterwards).
590
+ */
591
+ public function processCreditAdvice($amount, $txnReference, $preauthID)
592
+ {
593
+ $this->reset();
594
+
595
+ $this->setTxnType(SECUREPAY_TXN_ADVICE);
596
+
597
+ $this->setAmount($amount);
598
+ $this->setTxnReference($txnReference);
599
+ $this->setPreauthID($preauthID);
600
+
601
+ if($this->processTransaction());
602
+ if(array_key_exists('banktxnID',$this->responseArray))
603
+ return $this->responseArray['banktxnID'];
604
+ return false;
605
+ }
606
+
607
+ /*
608
+ //Disabled for the time being: not required yet
609
+ public function processDirectCredit($amount, $txnReference, $accName, $accBSB, $accNumber)
610
+ {
611
+ $this->reset();
612
+
613
+ $this->setTxnType(SECUREPAY_TXN_DIRECTCREDIT);
614
+
615
+ $this->setAmount($amount);
616
+ $this->setTxnReference($txnReference);
617
+ $this->setAccName($accName);
618
+ $this->setAccNumber($accNumber);
619
+ $this->setAccBSB($accBSB);
620
+
621
+ return $this->processTransaction();
622
+ }
623
+
624
+ public function processDirectDebit($amount, $txnReference, $accName, $accBSB, $accNumber)
625
+ {
626
+ $this->reset();
627
+
628
+ $this->setTxnType(SECUREPAY_TXN_DIRECTDEBIT);
629
+
630
+ $this->setAmount($amount);
631
+ $this->setTxnReference($txnReference);
632
+ $this->setAccName($accName);
633
+ $this->setAccNumber($accNumber);
634
+ $this->setAccBSB($accBSB);
635
+
636
+ return $this->processTransaction();
637
+ }
638
+ */
639
+
640
+ /**
641
+ * processTransaction:
642
+ *
643
+ * this function attempts to process a payment transaction using the
644
+ * supplied details on the SecurePay SecureXML Gateway
645
+ *
646
+ * @return boolean Returns true for succesful (approved) transaction / false for failure (declined) or error
647
+ *
648
+ */
649
+ private function processTransaction ()
650
+ {
651
+ // check that self is a valid gateway object
652
+ if ( !$this->gatewayObjectValid )
653
+ {
654
+ $this->errorString = self::GATEWAY_ERROR_OBJECT_INVALID;
655
+ return false;
656
+ }
657
+
658
+ // check parameters
659
+ if( $this->getTxnType()==SECUREPAY_TXN_STANDARD ||
660
+ $this->getTxnType()==SECUREPAY_TXN_PREAUTH )
661
+ {
662
+ if ($this->checkCCparameters() == false)
663
+ return false;
664
+ }
665
+ else if ( $this->getTxnType()==SECUREPAY_TXN_DIRECTDEBIT ||
666
+ $this->getTxnType()==SECUREPAY_TXN_DIRECTCREDIT )
667
+ {
668
+ if ($this->checkDirectparameters() == false)
669
+ return false;
670
+ }
671
+ if ($this->checkTxnParameters() == false)
672
+ {
673
+ return false;
674
+ }
675
+
676
+ // create request message. This function will retrieve and destroy CC details, if we're in credit-card mode (!)
677
+ $requestMessage = $this->createXMLTransactionRequestString();
678
+
679
+ $this->responseArray["raw-XML-request"] = htmlentities($requestMessage);
680
+
681
+ // send request
682
+ $response = $this->sendRequest( $this->gatewayURL, $requestMessage );
683
+
684
+ $this->responseArray["raw-response"] = htmlentities($response);
685
+
686
+ // was a response received?
687
+ if ( $response === false )
688
+ {
689
+ if ( strlen( $this->errorString ) == 0 )
690
+ {
691
+ $this->errorString = self::GATEWAY_ERROR_RESPONSE_ERROR;
692
+ }
693
+ return false;
694
+ }
695
+
696
+ // process response for validity
697
+ if ( $this->processTransactionResponseMessageIntoResponseArray( $response ) === false )
698
+ {
699
+ if ( strlen( $this->errorString ) == 0 )
700
+ {
701
+ $this->errorString = self::GATEWAY_ERROR_RESPONSE_INVALID;
702
+ }
703
+ return false;
704
+ }
705
+
706
+ // if we get this far, the transaction is succesful and "approved"
707
+ $this->responseArray["txnResult"] = true;
708
+
709
+ return true;
710
+ }
711
+
712
+
713
+ /**
714
+ * checkCCparameters
715
+ *
716
+ * Check the input parameters are valid for a credit card transaction
717
+ *
718
+ * @return boolean Return TRUE for all checks passed OK, or FALSE if an error is detected
719
+ */
720
+ private function checkCCparameters()
721
+ {
722
+ // the string ccNumber must be all numeric, and between 12 and 19 digits long
723
+ if (strlen( $this->getCCNumber() ) < 12 ||
724
+ strlen( $this->getCCNumber() ) > 19 ||
725
+ preg_match("/\D/",$this->getCCNumber()) )// REGEXP: true if "any match for non-numeral"
726
+ {
727
+ $this->errorString = self::GATEWAY_ERROR_INVALID_CCNUMBER;
728
+ return false;
729
+ }
730
+
731
+ // the string $ccExpiryMonth must be all numeric with value between 1 and 12
732
+ if (preg_match("/\D/", $this->getCCExpiryMonth()) || // REGEXP: true if "any match for non-numeral"
733
+ (int) $this->getCCExpiryMonth() < 1 ||
734
+ (int) $this->getCCExpiryMonth() > 12 )
735
+ {
736
+ $this->errorString = self::GATEWAY_ERROR_INVALID_CCEXPIRY;
737
+ return false;
738
+ }
739
+
740
+ // the string $ccExpiryYear must be all numeric with value between this year and this year + 12 years
741
+ if (preg_match( "/\D/", $this->getCCExpiryYear()) || // REGEXP: true if "any match for non-numeral"
742
+ (strlen($this->getCCExpiryYear()) != 2) || //YY form
743
+ (int) $this->getCCExpiryYear() < (int) substr(date("Y"),2) || // Between now and now + 12
744
+ (int) $this->getCCExpiryYear() > ( (int) substr(date("Y"),2) + 12 ) )
745
+ {
746
+ $this->errorString = self::GATEWAY_ERROR_INVALID_CCEXPIRY;
747
+ return false;
748
+ }
749
+
750
+ // The CVC is an optional data item so only perform the checks if the parameter was present
751
+ if ( strlen( $this->getCCVerify() ) != 0 )
752
+ {
753
+ // the string $ccVericationNumber must be all numeric with value between 000 and 9999
754
+ if (preg_match( "/\D/", $this->getCCVerify() ) || // REGEXP: true if "any match for non-numeral"
755
+ strlen( $this->getCCVerify() ) < 3 ||
756
+ strlen( $this->getCCVerify() ) > 4 ||
757
+ (int) $this->getCCVerify() < 0 ||
758
+ (int) $this->getCCVerify() > 9999 )
759
+ {
760
+ $this->errorString = self::GATEWAY_ERROR_INVALID_CC_CVC;
761
+ return false;
762
+ }
763
+ }
764
+ return true;
765
+ }
766
+
767
+ /**
768
+ * checkCCparameters
769
+ *
770
+ * Check the input parameters are valid for a credit card transaction
771
+ *
772
+ * @return boolean Return TRUE for all checks passed OK, or FALSE if an error is detected
773
+ */
774
+ private function checkDirectparameters()
775
+ {
776
+ // the string accNumber must be all numeric, and between 12 and 19 digits long
777
+ if (preg_match( "/\D/", $this->getAccNumber() ) )// REGEXP: true if "any match for non-numeral"
778
+ {
779
+ $this->errorString = self::GATEWAY_ERROR_INVALID_ACCOUNTNUMBER;
780
+ return false;
781
+ }
782
+
783
+ // the string $accName must be all numeric with value between 1 and 12
784
+ if ( preg_match( "/\D/", $this->getAccName() )) // REGEXP: true if "any match for non-numeral"
785
+ {
786
+ print "Month\n";
787
+ $this->errorString = self::GATEWAY_ERROR_INVALID_ACCOUNTNAME;
788
+ return false;
789
+ }
790
+ // the string $accBSB must be all numeric with value between 000 and 9999
791
+ if (preg_match( "/\D/", $this->getAccBSB())) // REGEXP: true if "any match for non-numeral"
792
+ {
793
+ $this->errorString = self::GATEWAY_ERROR_INVALID_BSB;
794
+ return false;
795
+ }
796
+
797
+ return true;
798
+ }
799
+
800
+ /**
801
+ * checkTxnParameters
802
+ *
803
+ * Check that the transaction input parameters are within requirements
804
+ *
805
+ * @param string $txnAmount
806
+ * @param string $txnReference
807
+ *
808
+ * @return TRUE for pass, FALSE for fail
809
+ */
810
+ private function checkTxnParameters ()
811
+ {
812
+ $amount = $this->getAmount();
813
+ if (preg_match( "/^[0-9]/", $amount)==false || (int) $amount < 0 )
814
+ {
815
+ $this->errorString = self::GATEWAY_ERROR_INVALID_TXN_AMT;
816
+ return false;
817
+ }
818
+
819
+ $ref = $this->getTxnReference();
820
+ if ( $this->getTxnType()==SECUREPAY_TXN_DIRECTDEBIT ||
821
+ $this->getTxnType()==SECUREPAY_TXN_DIRECTCREDIT )
822
+ {
823
+ // Direct Entry Payment References need to conform to EBCDIC, and should be <= 18 characters
824
+ if (strlen($ref) == 0 || strlen($ref)>18 ||
825
+ preg_match('/[^0-9a-zA-Z*\.&\/-_\']/', $ref)) // REGEXP: match any non-EBCDIC character
826
+ {
827
+ $this->errorString = self::GATEWAY_ERROR_INVALID_REF_ID;
828
+ return false;
829
+ }
830
+ }
831
+ else
832
+ {
833
+ // Standard/Credit References can have any character except space and single quote
834
+ if (strlen($ref) == 0 || strlen($ref)>59 ||
835
+ preg_match('/[^ \']/', $ref)==false) // REGEXP: match invalid characters
836
+ {
837
+ $this->errorString = self::GATEWAY_ERROR_INVALID_REF_ID;
838
+ return false;
839
+ }
840
+ }
841
+ return true;
842
+ }
843
+
844
+ /**
845
+ * createXMLTransactionRequestString:
846
+ * Creates the XML request string for a transaction request message
847
+ *
848
+ * Note: calls to getClearCCNumber & getClearCCVerify: details are removed from their respective private variables here
849
+ *
850
+ * @return string xml_transaction
851
+ */
852
+ private function createXMLTransactionRequestString()
853
+ {
854
+ $x =
855
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".
856
+ "<SecurePayMessage>" .
857
+ "<MessageInfo>" .
858
+ "<messageID>".htmlentities($this->getTxnReference().date("his").current(split(' ',microtime( ))))."</messageID>".
859
+ "<messageTimestamp>".htmlentities($this->getGMTTimeStamp())."</messageTimestamp>".
860
+ "<timeoutValue>".self::TIMEOUT."</timeoutValue>".
861
+ "<apiVersion>xml-4.2</apiVersion>" .
862
+ "</MessageInfo>".
863
+ "<MerchantInfo>".
864
+ "<merchantID>".htmlentities($this->getMerchantID())."</merchantID>" .
865
+ "<password>".htmlentities($this->getMerchantPW())."</password>" .
866
+ "</MerchantInfo>".
867
+ "<RequestType>Payment</RequestType>".
868
+ "<Payment>".
869
+ "<TxnList count=\"1\">".
870
+ "<Txn ID=\"1\">".
871
+ "<txnType>".htmlentities($this->getTxnType())."</txnType>".
872
+ "<txnSource>23</txnSource>".
873
+ "<amount>".htmlentities($this->getAmount())."</amount>";
874
+ if( ($this->getTxnType()==SECUREPAY_TXN_STANDARD ||
875
+ $this->getTxnType()==SECUREPAY_TXN_PREAUTH ) &&
876
+ $this->getCurrency()!=CURRENCY_DEFAULT)
877
+ {
878
+ $x .= "<currency>".htmlentities($this->getCurrency())."</currency>";
879
+ }
880
+ $x .= "<purchaseOrderNo>".htmlentities($this->getTxnReference())."</purchaseOrderNo>";
881
+ if( $this->getTxnType()==SECUREPAY_TXN_ADVICE)
882
+ {
883
+ $x .= "<preauthID>".htmlentities($this->getPreauthID())."</preauthID>";
884
+ }
885
+ if( $this->getTxnType()==SECUREPAY_TXN_REFUND ||
886
+ $this->getTxnType()==SECUREPAY_TXN_REVERSE &&
887
+ $this->getBankTxnID() != 0)
888
+ {
889
+ $x .= "<txnID>".htmlentities($this->getBankTxnID())."</txnID>";
890
+ }
891
+
892
+ if( $this->getTxnType()==SECUREPAY_TXN_STANDARD ||
893
+ $this->getTxnType()==SECUREPAY_TXN_PREAUTH )
894
+ {
895
+ $x .= "<CreditCardInfo>".
896
+ "<cardNumber>".htmlentities($this->getClearCCNumber())."</cardNumber>";
897
+ if (trim($this->getCCVerify()) <> "")
898
+ {
899
+ $x .= "<cvv>".htmlentities($this->getClearCCVerify())."</cvv>";
900
+ }
901
+ $x .= "<expiryDate>".htmlentities(sprintf("%02d",$this->getCCExpiryMonth())."/".sprintf("%02d",$this->getCCExpiryYear()))."</expiryDate>".
902
+ "</CreditCardInfo>";
903
+ }
904
+ else if ( $this->getTxnType()==SECUREPAY_TXN_DIRECTDEBIT ||
905
+ $this->getTxnType()==SECUREPAY_TXN_DIRECTCREDIT )
906
+ {
907
+ $x .= "<DirectEntryInfo>".
908
+ "<bsbNumber>".htmlentities($this->getAccBSB())."</bsbNumber>".
909
+ "<accountNumber>".htmlentities($this->getAccNumber())."</accountNumber>".
910
+ "<accountName>".htmlentities($this->getAccName())."</accountName>".
911
+ "</DirectEntryInfo>";
912
+ }
913
+ $x .= "</Txn>".
914
+ "</TxnList>".
915
+ "</Payment>".
916
+ "</SecurePayMessage>";
917
+
918
+ return $x;
919
+ }
920
+
921
+
922
+ /**
923
+ * getGMTTimeStamp:
924
+ *
925
+ * this function creates a timestamp formatted as per requirement in the
926
+ * SecureXML documentation
927
+ *
928
+ * @return string The formatted timestamp
929
+ */
930
+ private function getGMTTimeStamp()
931
+ {
932
+ /* Format: YYYYDDMMHHNNSSKKK000sOOO
933
+ YYYY is a 4-digit year
934
+ DD is a 2-digit zero-padded day of month
935
+ MM is a 2-digit zero-padded month of year (January = 01)
936
+ HH is a 2-digit zero-padded hour of day in 24-hour clock format (midnight =0)
937
+ NN is a 2-digit zero-padded minute of hour
938
+ SS is a 2-digit zero-padded second of minute
939
+ KKK is a 3-digit zero-padded millisecond of second
940
+ 000 is a Static 0 characters, as SecurePay does not store nanoseconds
941
+ sOOO is a Time zone offset, where s is �+� or �-�, and OOO = minutes, from GMT.
942
+ */
943
+
944
+
945
+ $val = date("Z") / 60;
946
+ if ($val >= 0)
947
+ {
948
+ $val = "+" . strval($val);
949
+ }
950
+
951
+ $stamp = date("YdmGis000000") . $val;
952
+
953
+ return $stamp;
954
+ }
955
+
956
+ /**
957
+ * sendRequest:
958
+ * uses cURL to open a Secure Socket connection to the gateway,
959
+ * sends the transaction request and then returns the response
960
+ * data
961
+ *
962
+ * @param $postURL The URL of the remote gateway to which the request is sent
963
+ * @param $requestMessage
964
+ */
965
+ private function sendRequest( $postURL, $requestMessage )
966
+ {
967
+ $ch = curl_init();
968
+
969
+ // Set up curl parameters
970
+ curl_setopt( $ch, CURLOPT_URL, $postURL ); // set remote address
971
+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // Make CURL pass the response as a curl_exec return value instead of outputting to STDOUT
972
+ curl_setopt( $ch, CURLOPT_POST, 1 ); // Activate the POST method
973
+ curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
974
+ curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
975
+
976
+ curl_setopt( $ch, CURLOPT_POSTFIELDS, $requestMessage ); // add the request message itself
977
+
978
+ // execute the connexion
979
+ $result = curl_exec( $ch );
980
+
981
+ $debugoutput = curl_getinfo($ch);
982
+ $curl_error_message = curl_error( $ch ); // must retrieve an error message (if any) before closing the curl object
983
+
984
+ curl_close($ch);
985
+
986
+
987
+ if ( $result === false )
988
+ {
989
+ $this->errorString = self::GATEWAY_ERROR_CURL_ERROR.': '.$curl_error_message;
990
+ return false;
991
+ }
992
+
993
+ // we do not need the header part of the response, trim it off the result
994
+ $pos = strstr( $result, "\n" );
995
+ $result = substr( $result, $pos );
996
+
997
+ return $result;
998
+ }
999
+
1000
+ /**
1001
+ * processTransactionResponseMessageIntoResponseArray:
1002
+ * converts the response XML message into a nested array structure and then
1003
+ * pulls out the relevant data into a simplified result array
1004
+ *
1005
+ * @param string $responseMessage - An XML response from the gateway
1006
+ * @return boolean True to indicate succesful decoding of response message AND succesful txn result, false to indicate an error or declined result
1007
+ */
1008
+ private function processTransactionResponseMessageIntoResponseArray ( $responseMessage )
1009
+ {
1010
+ $xmlres = array();
1011
+ $xmlres = $this->convertXMLToNestedArray( $responseMessage );
1012
+
1013
+ if ( $xmlres === false )
1014
+ {
1015
+ if ( strlen( $this->errorString ) == 0 )
1016
+ {
1017
+ $this->errorString = self::GATEWAY_ERROR_RESPONSE_XML_MESSAGE_ERROR;
1018
+ }
1019
+ return false;
1020
+ }
1021
+
1022
+ $responseArray["raw-XML-response"] = htmlentities($responseMessage);
1023
+
1024
+ $statusCode = trim( $xmlres['SecurePayMessage']['Status']['statusCode'] );
1025
+ $statusDescription = trim($xmlres['SecurePayMessage']['Status']['statusDescription']);
1026
+
1027
+ $responseArray["statusCode"] = $statusCode;
1028
+ $responseArray["statusDescription"] = $statusDescription;
1029
+
1030
+ // Three digit codes indicate a repsonse from the Securepay gateway (error detected by gateway)
1031
+ if ( strcmp( $statusCode, '000' ) != 0 )
1032
+ {
1033
+ $this->errorString = self::GATEWAY_ERROR_SECUREPAY_STATUS.": ".$statusCode." ".$statusDescription;
1034
+ return false;
1035
+ }
1036
+
1037
+ $responseArray["messageID"] = trim($xmlres['SecurePayMessage']['MessageInfo']['messageID']);
1038
+ $responseArray["messageTimestamp"] = trim($xmlres['SecurePayMessage']['MessageInfo']['messageTimestamp']);
1039
+ $responseArray["apiVersion"] = trim($xmlres['SecurePayMessage']['MessageInfo']['apiVersion']);
1040
+ $responseArray["RequestType"] = trim($xmlres['SecurePayMessage']['RequestType']);
1041
+ $responseArray["merchantID"] = trim($xmlres['SecurePayMessage']['MerchantInfo']['merchantID']);
1042
+ $responseArray["txnType"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['txnType']);
1043
+ $responseArray["txnSource"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['txnSource']);
1044
+ $responseArray["amount"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['amount']);
1045
+ $responseArray["approved"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['approved']);
1046
+ $responseArray["responseCode"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['responseCode']);
1047
+ $responseArray["responseText"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['responseText']);
1048
+ $responseArray["banktxnID"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['txnID']);
1049
+ $responseArray["settlementDate"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['settlementDate']);
1050
+
1051
+ if( $this->getTxnType()==SECUREPAY_TXN_PREAUTH && array_key_exists('preauthID',$xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']))
1052
+ {
1053
+ $responseArray["preauthID"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['preauthID']);
1054
+ }
1055
+ if($this->getRequestType() == SECUREPAY_REQ_PERIODIC)
1056
+ {
1057
+ if( $this->getTxnType()==SECUREPAY_TXN_STANDARD ||
1058
+ $this->getTxnType()==SECUREPAY_TXN_PREAUTH )
1059
+ {
1060
+ $responseArray["creditCardPAN"] = trim($xmlres['SecurePayMessage']['Periodic']['PeriodicList']['PeriodicItem']['CreditCardInfo']['pan']);
1061
+ $responseArray["expiryDate"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['CreditCardInfo']['expiryDate']);
1062
+ }
1063
+ }
1064
+ else if (strtoupper($responseArray['approved']) == 'YES' &&
1065
+ ($this->getTxnType()==SECUREPAY_TXN_DIRECTDEBIT ||
1066
+ $this->getTxnType()==SECUREPAY_TXN_DIRECTCREDIT) )
1067
+ {
1068
+ $responseArray["bsbNumber"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['DirectEntryInfo']['bsbNumber']);
1069
+ $responseArray["accountNumber"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['DirectEntryInfo']['accountNumber']);
1070
+ $responseArray["accountName"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['DirectEntryInfo']['accountName']);
1071
+ }
1072
+ else if ($this->getRequestType() == SECUREPAY_REQ_PAYMENT)
1073
+ {
1074
+ $responseArray["creditCardPAN"] = trim($xmlres['SecurePayMessage']['Periodic']['PeriodicList']['PeriodicItem']['CreditCardInfo']['pan']);
1075
+ $responseArray["expiryDate"] = trim($xmlres['SecurePayMessage']['Payment']['TxnList']['Txn']['CreditCardInfo']['expiryDate']);
1076
+ }
1077
+ $this->responseArray = $responseArray;
1078
+
1079
+ /* field "successful" = "Yes" means "triggered transaction successfully registered", anything else is failure */
1080
+ /* responseCodes:
1081
+ "00" indicates approved,
1082
+ "08" is Honor with ID (approved) and
1083
+ "77" is Approved (ANZ only).
1084
+ Any other 2 digit code is a decline or error from the bank. */
1085
+
1086
+ if ((strcasecmp( $responseArray["approved"], "Yes" ) == 0) &&
1087
+ (strcmp( $responseArray["responseCode"], "00" ) === 0 ||
1088
+ strcmp( $responseArray["responseCode"], "08" ) === 0 ||
1089
+ strcmp( $responseArray["responseCode"], "77" ) === 0 ) )
1090
+ {
1091
+ return true;
1092
+ }
1093
+ else
1094
+ {
1095
+ $this->errorString = self::GATEWAY_ERROR_TXN_DECLINED." (".$responseArray["responseCode"]."): ".$responseArray["responseText"];
1096
+ return false;
1097
+ }
1098
+ }
1099
+
1100
+
1101
+ /**
1102
+ * convertXMLToNestedArray:
1103
+ * converts an XML document into a nested array structure
1104
+ *
1105
+ * @param string $XMLDocument An XML document
1106
+ * @return boolean True to indicate succesful conversion of document, false to indicate an error
1107
+ */
1108
+ private function convertXMLToNestedArray ( $XMLDocument )
1109
+ {
1110
+
1111
+ $output = array();
1112
+
1113
+ $parser = xml_parser_create();
1114
+
1115
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
1116
+ xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
1117
+ $parse_result = xml_parse_into_struct($parser, $XMLDocument, $values);
1118
+
1119
+ if ( $parse_result === 0)
1120
+ {
1121
+ $this->errorString = self::GATEWAY_ERROR_XML_PARSE_FAILED.": ".xml_get_error_code ( $parser )." ".xml_error_string (xml_get_error_code ( $parser ) );
1122
+ xml_parser_free($parser);
1123
+
1124
+ return false;
1125
+ }
1126
+
1127
+ xml_parser_free($parser);
1128
+
1129
+ $hash_stack = array();
1130
+
1131
+ foreach ($values as $val)
1132
+ {
1133
+ switch ($val['type'])
1134
+ {
1135
+ case 'open':
1136
+ array_push($hash_stack, $val['tag']);
1137
+ break;
1138
+
1139
+ case 'close':
1140
+ array_pop($hash_stack);
1141
+ break;
1142
+
1143
+ case 'complete':
1144
+ array_push($hash_stack, $val['tag']);
1145
+ if ( array_key_exists('value', $val) )
1146
+ eval("\$output['" . implode($hash_stack, "']['") . "'] = \"{$val['value']}\";");
1147
+ else // to handle empty self closing tags i.e. <paymentInterval/>
1148
+ eval("\$output['" . implode($hash_stack, "']['") . "'] = null;");
1149
+ array_pop($hash_stack);
1150
+ break;
1151
+ }
1152
+ }
1153
+ return $output;
1154
+ }
1155
+ }
1156
+
1157
+ ?>
app/design/frontend/default/default/template/securepay/form/cc.phtml ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-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 design_default
22
+ * @package Mage
23
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <fieldset class="form-list">
28
+ <?php $_code=$this->getMethodCode() ?>
29
+ <ul id="payment_form_<?php echo $_code ?>" style="display:none">
30
+ <!--li>
31
+ <div class="input-box">
32
+ <label for="<?php echo $_code ?>_cc_owner"><?php echo $this->__('Name on Card') ?> <span class="required">*</span></label><br/>
33
+ <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="required-entry input-text" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>"/>
34
+ </div>
35
+ </li-->
36
+ <!--<li>
37
+ <div class="input-box">
38
+ <label for="<?php echo $_code ?>_cc_type"><?php echo $this->__('Credit Card Type') ?> <span class="required">*</span></label><br />
39
+ <select id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" class="required-entry validate-sxml-cc-type-select">
40
+ <option value="OT">Other</option>
41
+ </select>
42
+ </div>
43
+ </li>-->
44
+ <li>
45
+ <div class="input-box">
46
+ <label for="<?php echo $_code ?>_cc_number"><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label><br/>
47
+ <input type="text" id="<?php echo $_code ?>_cc_number" name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type" value="" />
48
+ </div>
49
+ </li>
50
+ <li>
51
+ <div class="input-box">
52
+ <label for="<?php echo $_code ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label><br />
53
+ <div class="v-fix">
54
+ <select id="<?php echo $_code ?>_expiration" style="width:140px;" name="payment[cc_exp_month]" class="required-entry">
55
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
56
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
57
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
58
+ <?php endforeach ?>
59
+ </select>
60
+ </div>
61
+ <div class="v-fix" style="padding-left:5px;">
62
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
63
+ <select id="<?php echo $_code ?>_expiration_yr" style="width:103px;" name="payment[cc_exp_year]" class="required-entry">
64
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
65
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
66
+ <?php endforeach ?>
67
+ </select>
68
+ </div>
69
+ </div>
70
+ </li>
71
+ <?php if($this->hasVerification()): ?>
72
+ <li>
73
+ <div class="input-box">
74
+ <label for="<?php echo $_code ?>_cc_cid"><?php echo $this->__('Card Verification Number') ?> <span class="required">*</span></label><br />
75
+ <div class="v-fix"><input type="text" title="<?php echo $this->__('Card Verification Number') ?>" class="required-entry input-text validate-cc-cvn" id="<?php echo $_code ?>_cc_cid" name="payment[cc_cid]" style="width:3em;" value="" /></div>
76
+ &nbsp;
77
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
78
+ </div>
79
+ </li>
80
+ <?php endif; ?>
81
+ </ul>
82
+ </fieldset>
app/etc/modules/SecurePay_Sxml.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <SecurePay_Sxml>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <depends>
8
+ <Mage_Payment />
9
+ </depends>
10
+ </SecurePay_Sxml>
11
+ </modules>
12
+ </config>
package.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>SecurePay_SecureXML</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Provides credit-card transactions via the SecurePay XML API</summary>
10
+ <description>Provides support for the following kinds of credit-card transaction:
11
+ Standard (Payment)
12
+ Preauthorise
13
+ Advice (Complete/Capture)
14
+ Reverse (Void)
15
+ Refund
16
+
17
+ Fraudguard, Direct Entry (Credit/Debit) and Periodic/Triggered payments are not supported.</description>
18
+ <notes>In the config options, select Authorize for preauth/complete mode, or Authorize and Capture for standard payment mode.
19
+
20
+ If there is a problem with the initial transaction, the bank response code and text will be displayed to the user.</notes>
21
+ <authors><author><name>Andrew Dubbeld</name><user>auto-converted</user><email>support@securepay.com.au</email></author></authors>
22
+ <date>2009-10-16</date>
23
+ <time>04:10:10</time>
24
+ <contents><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="securepay"><dir name="form"><file name="cc.phtml" hash="6c04dbd1934b9dbf8b0dec3d33c8c735"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="SecurePay_Sxml.xml" hash="e466d9b1db62c1844ccf17cca44bee5e"/></dir></target><target name="magelocal"><dir name="SecurePay"><dir name="Sxml"><dir name="Block"><dir name="Form"><file name="Cc.php" hash="412525e5c8c79ebd26cbf6033618b615"/></dir></dir><dir name="etc"><file name="config.xml" hash="1dc198c9787f377be148d60ec7ca48fa"/><file name="system.xml" hash="5ee5515d045fae42d3da2032ffe73bf8"/></dir><dir name="Helper"><file name="Data.php" hash="393c88c60eca919c13f255156355c536"/></dir><dir name="Model"><dir name="Source"><file name="Cctype.php" hash="bfe90747333890f72c94bd57b8b288c0"/></dir><dir name="Sxml"><file name="PaymentAction.php" hash="a5b8594da33b6113f3e9cc759c364d03"/><file name="Request.php" hash="95c4749da03d4e68b83706c8ce70ef0f"/><file name="Result.php" hash="f3f463587b5293a897f5c7e2bd4fc139"/></dir><file name="Sxml.php" hash="39b43e1680c3cb25844bd35e28ca0d38"/></dir></dir><file name="securepay_xml_api.php" hash="eb7530a7170fb7756ca80bad9698468b"/></dir></target></contents>
25
+ <compatible/>
26
+ <dependencies/>
27
+ </package>