Raveinfosys_Sagepay - Version 1.0.2

Version Notes

This version is properly tested on the following Magento CE versions: 1.5, 1.6, 1.7,1.8,1.9.* . In this particular version we are supporting it to run on PHP V 5.5.X.

Download this release

Release Info

Developer Rave Infosys
Extension Raveinfosys_Sagepay
Version 1.0.2
Comparing to
See all releases


Code changes from version 1.0.1 to 1.0.2

app/code/community/Raveinfosys/Sagepay/Block/Adminhtml/Sagepay.php CHANGED
@@ -1,13 +1,16 @@
1
  <?php
 
2
  class Raveinfosys_Sagepay_Block_Adminhtml_Sagepay extends Mage_Adminhtml_Block_Widget_Grid_Container
3
  {
4
- public function __construct()
5
- {
6
- $this->_controller = 'adminhtml_sagepay';
7
- $this->_blockGroup = 'sagepay';
8
- $this->_headerText = Mage::helper('sagepay')->__('Sagepay Transaction Details');
9
- $this->_addButtonLabel = Mage::helper('sagepay')->__('Add Item');
10
- parent::__construct();
11
- $this->_removeButton('add');
12
- }
13
- }
 
 
1
  <?php
2
+
3
  class Raveinfosys_Sagepay_Block_Adminhtml_Sagepay extends Mage_Adminhtml_Block_Widget_Grid_Container
4
  {
5
+
6
+ public function __construct()
7
+ {
8
+ $this->_controller = 'adminhtml_sagepay';
9
+ $this->_blockGroup = 'sagepay';
10
+ $this->_headerText = Mage::helper('sagepay')->__('Sagepay Transaction Details');
11
+ $this->_addButtonLabel = Mage::helper('sagepay')->__('Add Item');
12
+ parent::__construct();
13
+ $this->_removeButton('add');
14
+ }
15
+
16
+ }
app/code/community/Raveinfosys/Sagepay/Block/Adminhtml/Sagepay/Grid.php CHANGED
@@ -2,101 +2,102 @@
2
 
3
  class Raveinfosys_Sagepay_Block_Adminhtml_Sagepay_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
  {
5
- public function __construct()
6
- {
7
- parent::__construct();
8
- $this->setId('sagepayGrid');
9
- $this->setDefaultSort('transaction_id');
10
- $this->setDefaultDir('ASC');
11
- $this->setSaveParametersInSession(true);
12
- }
13
-
14
- protected function _prepareCollection()
15
- {
16
- $collection = Mage::getModel('sagepay/transaction')->getCollection();
17
- $this->setCollection($collection);
18
- return parent::_prepareCollection();
19
- }
20
-
21
- protected function _prepareColumns()
22
- {
23
-
24
- $this->addColumn('order_id', array(
25
- 'header' => Mage::helper('sagepay')->__('Order Id'),
26
- 'align' =>'right',
27
- 'width' => '50px',
28
- 'index' => 'order_id',
29
- ));
30
-
31
- $this->addColumn('vendor_tx_code', array(
32
- 'header' => Mage::helper('sagepay')->__('Vendor Tx Code'),
33
- 'align' =>'right',
34
- 'width' => '50px',
35
- 'index' => 'vendor_tx_code',
36
- ));
37
-
38
- /* $this->addColumn('security_key', array(
 
39
  'header' => Mage::helper('sagepay')->__('Security Key'),
40
  'align' =>'right',
41
  'width' => '50px',
42
  'index' => 'security_key',
43
- )); */
44
-
45
- $this->addColumn('order_status', array(
46
- 'header' => Mage::helper('sagepay')->__('Status'),
47
- 'align' =>'right',
48
- 'width' => '50px',
49
- 'index' => 'order_status',
50
- ));
51
-
52
- $this->addColumn('customer_name', array(
53
- 'header' => Mage::helper('sagepay')->__('Customer Name'),
54
- 'align' =>'right',
55
- 'width' => '50px',
56
- 'index' => 'customer_name',
57
- ));
58
-
59
- $this->addColumn('mode', array(
60
- 'header' => Mage::helper('sagepay')->__('Transaction Type'),
61
- 'align' =>'right',
62
- 'width' => '50px',
63
- 'index' => 'mode',
64
- ));
65
-
66
- $this->addColumn('customer_email', array(
67
- 'header' => Mage::helper('sagepay')->__('Email'),
68
- 'align' =>'right',
69
- 'width' => '50px',
70
- 'index' => 'customer_email',
71
- ));
72
-
73
- $this->addColumn('threed_secure', array(
74
- 'header' => Mage::helper('sagepay')->__('3D Auth'),
75
- 'align' =>'right',
76
- 'width' => '50px',
77
- 'index' => 'threed_secure',
78
- ));
79
-
80
- $this->addColumn('card_holder_name', array(
81
- 'header' => Mage::helper('sagepay')->__('Card Holder Name'),
82
- 'align' =>'right',
83
- 'width' => '50px',
84
- 'index' => 'card_holder_name',
85
- ));
86
-
87
- $this->addColumn('card_type', array(
88
- 'header' => Mage::helper('sagepay')->__('Card Type'),
89
- 'align' =>'right',
90
- 'width' => '50px',
91
- 'index' => 'card_type',
92
- ));
93
-
94
-
95
- $this->addExportType('*/*/exportCsv', Mage::helper('sagepay')->__('CSV'));
96
- $this->addExportType('*/*/exportXml', Mage::helper('sagepay')->__('XML'));
97
-
98
- return parent::_prepareColumns();
99
- }
100
 
101
  protected function _prepareMassaction()
102
  {
@@ -104,18 +105,18 @@ class Raveinfosys_Sagepay_Block_Adminhtml_Sagepay_Grid extends Mage_Adminhtml_Bl
104
  $this->getMassactionBlock()->setFormFieldName('sagepay');
105
 
106
  $this->getMassactionBlock()->addItem('delete', array(
107
- 'label' => Mage::helper('sagepay')->__('Delete'),
108
- 'url' => $this->getUrl('*/*/massDelete'),
109
- 'confirm' => Mage::helper('sagepay')->__('Are you sure?')
110
  ));
111
 
112
-
113
  return $this;
114
  }
115
 
116
- public function getRowUrl($row)
117
- {
118
- return '';
119
- }
120
 
121
- }
2
 
3
  class Raveinfosys_Sagepay_Block_Adminhtml_Sagepay_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
  {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('sagepayGrid');
10
+ $this->setDefaultSort('transaction_id');
11
+ $this->setDefaultDir('ASC');
12
+ $this->setSaveParametersInSession(true);
13
+ }
14
+
15
+ protected function _prepareCollection()
16
+ {
17
+ $collection = Mage::getModel('sagepay/transaction')->getCollection();
18
+ $this->setCollection($collection);
19
+ return parent::_prepareCollection();
20
+ }
21
+
22
+ protected function _prepareColumns()
23
+ {
24
+
25
+ $this->addColumn('order_id', array(
26
+ 'header' => Mage::helper('sagepay')->__('Order Id'),
27
+ 'align' => 'right',
28
+ 'width' => '50px',
29
+ 'index' => 'order_id',
30
+ ));
31
+
32
+ $this->addColumn('vendor_tx_code', array(
33
+ 'header' => Mage::helper('sagepay')->__('Vendor Tx Code'),
34
+ 'align' => 'right',
35
+ 'width' => '50px',
36
+ 'index' => 'vendor_tx_code',
37
+ ));
38
+
39
+ /* $this->addColumn('security_key', array(
40
  'header' => Mage::helper('sagepay')->__('Security Key'),
41
  'align' =>'right',
42
  'width' => '50px',
43
  'index' => 'security_key',
44
+ )); */
45
+
46
+ $this->addColumn('order_status', array(
47
+ 'header' => Mage::helper('sagepay')->__('Status'),
48
+ 'align' => 'right',
49
+ 'width' => '50px',
50
+ 'index' => 'order_status',
51
+ ));
52
+
53
+ $this->addColumn('customer_name', array(
54
+ 'header' => Mage::helper('sagepay')->__('Customer Name'),
55
+ 'align' => 'right',
56
+ 'width' => '50px',
57
+ 'index' => 'customer_name',
58
+ ));
59
+
60
+ $this->addColumn('mode', array(
61
+ 'header' => Mage::helper('sagepay')->__('Transaction Type'),
62
+ 'align' => 'right',
63
+ 'width' => '50px',
64
+ 'index' => 'mode',
65
+ ));
66
+
67
+ $this->addColumn('customer_email', array(
68
+ 'header' => Mage::helper('sagepay')->__('Email'),
69
+ 'align' => 'right',
70
+ 'width' => '50px',
71
+ 'index' => 'customer_email',
72
+ ));
73
+
74
+ $this->addColumn('threed_secure', array(
75
+ 'header' => Mage::helper('sagepay')->__('3D Auth'),
76
+ 'align' => 'right',
77
+ 'width' => '50px',
78
+ 'index' => 'threed_secure',
79
+ ));
80
+
81
+ $this->addColumn('card_holder_name', array(
82
+ 'header' => Mage::helper('sagepay')->__('Card Holder Name'),
83
+ 'align' => 'right',
84
+ 'width' => '50px',
85
+ 'index' => 'card_holder_name',
86
+ ));
87
+
88
+ $this->addColumn('card_type', array(
89
+ 'header' => Mage::helper('sagepay')->__('Card Type'),
90
+ 'align' => 'right',
91
+ 'width' => '50px',
92
+ 'index' => 'card_type',
93
+ ));
94
+
95
+
96
+ $this->addExportType('*/*/exportCsv', Mage::helper('sagepay')->__('CSV'));
97
+ $this->addExportType('*/*/exportXml', Mage::helper('sagepay')->__('XML'));
98
+
99
+ return parent::_prepareColumns();
100
+ }
101
 
102
  protected function _prepareMassaction()
103
  {
105
  $this->getMassactionBlock()->setFormFieldName('sagepay');
106
 
107
  $this->getMassactionBlock()->addItem('delete', array(
108
+ 'label' => Mage::helper('sagepay')->__('Delete'),
109
+ 'url' => $this->getUrl('*/*/massDelete'),
110
+ 'confirm' => Mage::helper('sagepay')->__('Are you sure?')
111
  ));
112
 
113
+
114
  return $this;
115
  }
116
 
117
+ public function getRowUrl($row)
118
+ {
119
+ return '';
120
+ }
121
 
122
+ }
app/code/community/Raveinfosys/Sagepay/Controller/Observer.php CHANGED
@@ -2,10 +2,12 @@
2
 
3
  class Raveinfosys_Sagepay_Controller_Observer
4
  {
5
- //Event: adminhtml_controller_action_predispatch_start
6
- public function overrideTheme()
7
- {
8
- Mage::getDesign()->setArea('adminhtml')
9
- ->setTheme('sagepay');
10
- }
 
 
11
  }
2
 
3
  class Raveinfosys_Sagepay_Controller_Observer
4
  {
5
+
6
+ //Event: adminhtml_controller_action_predispatch_start
7
+ public function overrideTheme()
8
+ {
9
+ Mage::getDesign()->setArea('adminhtml')
10
+ ->setTheme('sagepay');
11
+ }
12
+
13
  }
app/code/community/Raveinfosys/Sagepay/Helper/Data.php CHANGED
@@ -3,4 +3,4 @@
3
  class Raveinfosys_Sagepay_Helper_Data extends Mage_Core_Helper_Abstract
4
  {
5
 
6
- }
3
  class Raveinfosys_Sagepay_Helper_Data extends Mage_Core_Helper_Abstract
4
  {
5
 
6
+ }
app/code/community/Raveinfosys/Sagepay/Model/Config.php CHANGED
@@ -1,73 +1,81 @@
1
  <?php
2
 
3
- class Raveinfosys_Sagepay_Model_Config extends Mage_Core_Model_Abstract {
4
- private $config = array();
5
-
6
- public function _construct(){
7
- $sage_pay_urls = array(
8
- 'live' => array(
9
- 'register' => 'https://live.sagepay.com/gateway/service/vspdirect-register.vsp',
10
- 'refund' => 'https://live.sagepay.com/gateway/service/refund.vsp',
11
- 'void' => 'https://live.sagepay.com/gateway/service/void.vsp',
12
- 'cancel' => 'https://live.sagepay.com/gateway/service/cancel.vsp',
13
- 'authorise' => 'https://live.sagepay.com/gateway/service/authorise.vsp',
14
- '3dsecure' => 'https://live.sagepay.com/gateway/service/direct3dcallback.vsp'
15
- ),
16
- 'test' => array(
17
- 'register' => 'https://test.sagepay.com/gateway/service/vspdirect-register.vsp',
18
- 'refund' => 'https://test.sagepay.com/gateway/service/refund.vsp',
19
- 'void' => 'https://test.sagepay.com/gateway/service/void.vsp',
20
- 'cancel' => 'https://test.sagepay.com/gateway/service/cancel.vsp',
21
- 'authorise' => 'https://test.sagepay.com/gateway/service/authorise.vsp',
22
- '3dsecure' => 'https://test.sagepay.com/gateway/service/direct3dcallback.vsp'
23
- ),
24
- 'simulator' => array(
25
- 'register' => 'https://test.sagepay.com/Simulator/VSPDirectGateway.asp',
26
- 'refund' => 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorRefundTx',
27
- 'void' => 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorVoidTx',
28
- 'cancel' => 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorCancelTx',
29
- 'release' => 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorReleaseTx',
30
- 'authorise' => 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorAuthoriseTx',
31
- '3dsecure' => 'https://test.sagepay.com/Simulator/VSPDirectCallback.asp'
32
- )
33
- );
34
- $this->config = $sage_pay_urls;
35
- }
36
-
37
- public function getVendor(){
38
- return Mage::getStoreConfig('payment/sagepay/vendor_name');
39
- }
40
-
41
- public function getGatewayURL(){
42
- $mode = Mage::getStoreConfig('payment/sagepay/mode');
43
- if(in_array($mode, array('live', 'test', 'simulator')))
44
- return $this->config[$mode] ;
45
- else
46
- return $this->config['test'] ;
47
- }
48
-
49
- public function getExpectedError(){
50
- return array('INVALID', 'MALFORMED', 'REJECTED', 'NOTAUTHED', 'ERROR', 'FAIL');
51
- }
52
-
53
- public function getExpectedSuccess(){
54
- return array('OK','AUTHENTICATED','REGISTERED');
55
- }
56
-
57
- public function getCcCode($code){
58
- $data = array(
59
- 'VI'=> 'VISA',
60
- 'AE'=> 'AMEX',
61
- 'MC'=> 'MC',
62
- 'DI'=> 'DC',
63
- 'JCB'=> 'JCB',
64
- 'SM'=> 'MAESTRO',
65
- 'SO'=> 'SOLO',
66
- 'OT'=> 'Other',
67
- );
68
- return $data[$code];
69
- }
70
-
71
-
72
- }
73
- ?>
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ class Raveinfosys_Sagepay_Model_Config extends Mage_Core_Model_Abstract
4
+ {
5
+
6
+ private $config = array();
7
+
8
+ public function _construct()
9
+ {
10
+ $sage_pay_urls = array(
11
+ 'live' => array(
12
+ 'register' => 'https://live.sagepay.com/gateway/service/vspdirect-register.vsp',
13
+ 'refund' => 'https://live.sagepay.com/gateway/service/refund.vsp',
14
+ 'void' => 'https://live.sagepay.com/gateway/service/void.vsp',
15
+ 'cancel' => 'https://live.sagepay.com/gateway/service/cancel.vsp',
16
+ 'authorise' => 'https://live.sagepay.com/gateway/service/authorise.vsp',
17
+ '3dsecure' => 'https://live.sagepay.com/gateway/service/direct3dcallback.vsp'
18
+ ),
19
+ 'test' => array(
20
+ 'register' => 'https://test.sagepay.com/gateway/service/vspdirect-register.vsp',
21
+ 'refund' => 'https://test.sagepay.com/gateway/service/refund.vsp',
22
+ 'void' => 'https://test.sagepay.com/gateway/service/void.vsp',
23
+ 'cancel' => 'https://test.sagepay.com/gateway/service/cancel.vsp',
24
+ 'authorise' => 'https://test.sagepay.com/gateway/service/authorise.vsp',
25
+ '3dsecure' => 'https://test.sagepay.com/gateway/service/direct3dcallback.vsp'
26
+ ),
27
+ 'simulator' => array(
28
+ 'register' => 'https://test.sagepay.com/Simulator/VSPDirectGateway.asp',
29
+ 'refund' => 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorRefundTx',
30
+ 'void' => 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorVoidTx',
31
+ 'cancel' => 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorCancelTx',
32
+ 'release' => 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorReleaseTx',
33
+ 'authorise' => 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorAuthoriseTx',
34
+ '3dsecure' => 'https://test.sagepay.com/Simulator/VSPDirectCallback.asp'
35
+ )
36
+ );
37
+ $this->config = $sage_pay_urls;
38
+ }
39
+
40
+ public function getVendor()
41
+ {
42
+ return Mage::getStoreConfig('payment/sagepay/vendor_name');
43
+ }
44
+
45
+ public function getGatewayURL()
46
+ {
47
+ $mode = Mage::getStoreConfig('payment/sagepay/mode');
48
+ if (in_array($mode, array('live', 'test', 'simulator')))
49
+ return $this->config[$mode];
50
+ else
51
+ return $this->config['test'];
52
+ }
53
+
54
+ public function getExpectedError()
55
+ {
56
+ return array('INVALID', 'MALFORMED', 'REJECTED', 'NOTAUTHED', 'ERROR', 'FAIL');
57
+ }
58
+
59
+ public function getExpectedSuccess()
60
+ {
61
+ return array('OK', 'AUTHENTICATED', 'REGISTERED');
62
+ }
63
+
64
+ public function getCcCode($code)
65
+ {
66
+ $data = array(
67
+ 'VI' => 'VISA',
68
+ 'AE' => 'AMEX',
69
+ 'MC' => 'MC',
70
+ 'DI' => 'DC',
71
+ 'JCB' => 'JCB',
72
+ 'SM' => 'MAESTRO',
73
+ 'SO' => 'SOLO',
74
+ 'OT' => 'Other',
75
+ );
76
+ return $data[$code];
77
+ }
78
+
79
+ }
80
+
81
+ ?>
app/code/community/Raveinfosys/Sagepay/Model/Mysql4/Sagepay.php CHANGED
@@ -2,8 +2,10 @@
2
 
3
  class Raveinfosys_Sagepay_Model_Mysql4_Sagepay extends Mage_Core_Model_Mysql4_Abstract
4
  {
 
5
  public function _construct()
6
- {
7
  $this->_init('sagepay/sagepay', 'sagepay_id');
8
  }
9
- }
 
2
 
3
  class Raveinfosys_Sagepay_Model_Mysql4_Sagepay extends Mage_Core_Model_Mysql4_Abstract
4
  {
5
+
6
  public function _construct()
7
+ {
8
  $this->_init('sagepay/sagepay', 'sagepay_id');
9
  }
10
+
11
+ }
app/code/community/Raveinfosys/Sagepay/Model/Mysql4/Sagepay/Collection.php CHANGED
@@ -2,9 +2,11 @@
2
 
3
  class Raveinfosys_Sagepay_Model_Mysql4_Sagepay_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
  {
 
5
  public function _construct()
6
  {
7
  parent::_construct();
8
  $this->_init('sagepay/sagepay');
9
  }
10
- }
 
2
 
3
  class Raveinfosys_Sagepay_Model_Mysql4_Sagepay_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
  {
5
+
6
  public function _construct()
7
  {
8
  parent::_construct();
9
  $this->_init('sagepay/sagepay');
10
  }
11
+
12
+ }
app/code/community/Raveinfosys/Sagepay/Model/Mysql4/Transaction.php CHANGED
@@ -2,8 +2,10 @@
2
 
3
  class Raveinfosys_Sagepay_Model_Mysql4_Transaction extends Mage_Core_Model_Mysql4_Abstract
4
  {
 
5
  public function _construct()
6
- {
7
- $this->_init('sagepay/transaction', 'transaction_id');
8
  }
9
- }
 
2
 
3
  class Raveinfosys_Sagepay_Model_Mysql4_Transaction extends Mage_Core_Model_Mysql4_Abstract
4
  {
5
+
6
  public function _construct()
7
+ {
8
+ $this->_init('sagepay/transaction', 'transaction_id');
9
  }
10
+
11
+ }
app/code/community/Raveinfosys/Sagepay/Model/Mysql4/Transaction/Collection.php CHANGED
@@ -2,9 +2,11 @@
2
 
3
  class Raveinfosys_Sagepay_Model_Mysql4_Transaction_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
  {
 
5
  public function _construct()
6
  {
7
  parent::_construct();
8
  $this->_init('sagepay/transaction');
9
  }
10
- }
 
2
 
3
  class Raveinfosys_Sagepay_Model_Mysql4_Transaction_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
  {
5
+
6
  public function _construct()
7
  {
8
  parent::_construct();
9
  $this->_init('sagepay/transaction');
10
  }
11
+
12
+ }
app/code/community/Raveinfosys/Sagepay/Model/Observer.php CHANGED
@@ -1,29 +1,33 @@
1
  <?php
2
 
3
- class Raveinfosys_Sagepay_Model_Observer {
4
- public function disableMethod(Varien_Event_Observer $observer){
5
- $moduleName="Raveinfosys_Sagepay";
6
- if('sagepay'==$observer->getMethodInstance()->getCode()){
7
- if(!Mage::getStoreConfigFlag('advanced/modules_disable_output/'.$moduleName)) {
8
- //nothing here, as module is ENABLE
9
- } else {
10
- $observer->getResult()->isAvailable=false;
11
- }
12
-
13
- }
14
- }
15
-
16
- public function layoutUpdate(Varien_Event_Observer $observer)
17
- {
18
- if(!Mage::getStoreConfigFlag('advanced/modules_disable_output/'.$moduleName) && !Mage::getStoreConfigFlag('payment/sagepay/active')){
19
- return $observer;
20
- }
21
- $quote = Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getData();
22
- if($quote['method']=='sagepay'){
23
- $updates = $observer->getEvent()->getUpdates();
24
- $updates->addChild('sagepay_checkout_review')
25
- ->file = 'sagepay_checkout2.xml';
26
- }
27
- }
 
 
 
28
  }
 
29
  ?>
1
  <?php
2
 
3
+ class Raveinfosys_Sagepay_Model_Observer
4
+ {
5
+
6
+ public function disableMethod(Varien_Event_Observer $observer)
7
+ {
8
+ $moduleName = "Raveinfosys_Sagepay";
9
+ if ('sagepay' == $observer->getMethodInstance()->getCode()) {
10
+ if (!Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $moduleName)) {
11
+ //nothing here, as module is ENABLE
12
+ } else {
13
+ $observer->getResult()->isAvailable = false;
14
+ }
15
+ }
16
+ }
17
+
18
+ public function layoutUpdate(Varien_Event_Observer $observer)
19
+ {
20
+ if (!Mage::getStoreConfigFlag('advanced/modules_disable_output/' . $moduleName) && !Mage::getStoreConfigFlag('payment/sagepay/active')) {
21
+ return $observer;
22
+ }
23
+ $quote = Mage::getSingleton('checkout/session')->getQuote()->getPayment()->getData();
24
+ if ($quote['method'] == 'sagepay') {
25
+ $updates = $observer->getEvent()->getUpdates();
26
+ $updates->addChild('sagepay_checkout_review')
27
+ ->file = 'sagepay_checkout2.xml';
28
+ }
29
+ }
30
+
31
  }
32
+
33
  ?>
app/code/community/Raveinfosys/Sagepay/Model/Payment.php CHANGED
@@ -1,89 +1,91 @@
1
  <?php
2
 
3
- class Raveinfosys_Sagepay_Model_Payment extends Mage_Payment_Model_Method_Ccsave {
4
-
5
- protected $_code = 'sagepay';
6
- protected $_isGateway = true; //Is this payment method a gateway (online auth/charge) ?
7
- protected $_canAuthorize = true; //Can authorize online?
8
- protected $_canCapture = true; //Can capture funds online?
9
- protected $_canCapturePartial = true; //Can capture partial amounts online?
10
- protected $_canRefund = true; //Can refund online?
11
- protected $_canRefundInvoicePartial = true; //Can refund invoices partially?
12
- protected $_canVoid = true; //Can void transactions online?
13
- protected $_canUseInternal = true; //Can use this payment method in administration panel?
14
- protected $_canUseCheckout = true; //Can show this payment method as an option on checkout payment page?
15
- protected $_canUseForMultishipping = true; //Is this payment method suitable for multi-shipping checkout?
16
- protected $_canFetchTransactionInfo = false;
17
- protected $_canReviewPayment = true;
 
18
  protected $_infoBlockType = 'payment/info_cc';
19
- protected $_canSaveCc = false;
20
-
21
- const ACTION_PAYMENT = 'PAYMENT';
22
  const ACTION_VOID = 'VOID';
23
- const ACTION_AUTHORISE = 'AUTHORISE';
24
- const ACTION_AUTHENTICATE = 'AUTHENTICATE';
25
- const ACTION_REFUND = 'REFUND';
26
- const ACTION_CANCEL = 'CANCEL';
27
-
28
  private $urls;
29
- private $Vendor;
30
- private $Basket = array();
31
-
32
- public $AccountType = 'E';
33
- public $GiftAidPayment = 0;
34
- public $ApplyAVSCV2 = 0;
35
- public $Apply3DSecure = 0;
36
- public $Description = "Sagepay Direct Transaction.";
37
-
38
- public $VendorTxCode;
39
- public $TxType;
40
- public $Amount;
41
- public $Currency;
42
- public $CardHolder;
43
- public $CardNumber;
44
- public $StartDate;
45
- public $ExpiryDate;
46
- public $IssueNumber;
47
- public $CV2;
48
- public $CardType;
49
- public $BillingSurname;
50
- public $BillingFirstnames;
51
- public $BillingAddress1;
52
- public $BillingAddress2;
53
- public $BillingCity;
54
- public $BillingPostCode;
55
- public $BillingCountry;
56
- public $BillingState;
57
- public $BillingPhone;
58
- public $DeliverySurname;
59
- public $DeliveryFirstnames;
60
- public $DeliveryAddress1;
61
- public $DeliveryAddress2;
62
- public $DeliveryCity;
63
- public $DeliveryPostCode;
64
- public $DeliveryCountry;
65
- public $DeliveryState;
66
- public $DeliveryPhone;
67
- public $CustomerEmail;
68
- public $OrderIncrementId;
69
-
70
- public $result = array('Status' => 'BEGIN');
71
-
72
- public function __construct($vendor , $mode ) {
73
-
74
- $this->urls = $this->getConfigModel()->getGatewayURL();
75
- $this->Vendor = $this->getConfigModel()->getVendor();
76
- }
77
-
78
- public function isMsOnOverview() {
79
  return ($this->_getQuote()->getIsMultiShipping() && $this->getMsActiveStep() == 'multishipping_overview');
80
  }
81
-
82
- public function getMsActiveStep() {
 
83
  return Mage::getSingleton('checkout/type_multishipping_state')->getActiveStep();
84
  }
85
-
86
- protected function _getReservedOid() {
 
87
 
88
  if ($this->isMsOnOverview() && ($this->_getQuote()->getPayment()->getMethod() == 'sagepay')) {
89
  return null;
@@ -97,7 +99,7 @@ class Raveinfosys_Sagepay_Model_Payment extends Mage_Payment_Model_Method_Ccsave
97
  $this->_getQuote()->unsReservedOrderId();
98
  $this->_getQuote()->reserveOrderId()->save();
99
  }
100
- $orderId = $this->_getQuote()->getReservedOrderId();
101
  $this->getSagepayModel()->setReservedId($orderId);
102
  }
103
 
@@ -106,8 +108,9 @@ class Raveinfosys_Sagepay_Model_Payment extends Mage_Payment_Model_Method_Ccsave
106
  }
107
  return $orderId;
108
  }
109
-
110
- protected function _orderIdAlreadyUsed($orderId) {
 
111
  if (!$orderId)
112
  return false;
113
 
@@ -116,10 +119,11 @@ class Raveinfosys_Sagepay_Model_Payment extends Mage_Payment_Model_Method_Ccsave
116
  if (!$existingOrder->getId()) {
117
  return false;
118
  }
119
- return true;
120
  }
121
-
122
- protected function _getQuote() {
 
123
 
124
  $opQuote = Mage::getSingleton('checkout/type_onepage')->getQuote();
125
  $adminQuote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
@@ -128,664 +132,687 @@ class Raveinfosys_Sagepay_Model_Payment extends Mage_Payment_Model_Method_Ccsave
128
  if ($adminQuote->hasItems() === false && (int) $rqQuoteId) {
129
  $opQuote->setQuote(Mage::getModel('sales/quote')->loadActive($rqQuoteId));
130
  }
131
- return ($adminQuote->hasItems() === true) ? $adminQuote : $opQuote;
132
  }
133
 
134
-
135
- protected function _getTrnVendorTxCode() {
136
  return $this->_getReservedOid();
137
  }
138
-
139
-
140
- public function validate() {
141
- $info = $this->getInfoInstance();
142
- $order_amount=0;
143
- if ($info instanceof Mage_Sales_Model_Quote_Payment) {
144
- $order_amount=(double)$info->getQuote()->getBaseGrandTotal();
145
  } elseif ($info instanceof Mage_Sales_Model_Order_Payment) {
146
- $order_amount=(double)$info->getOrder()->getQuoteBaseGrandTotal();
147
- }
148
-
149
- $order_min=$this->getConfigData('min_order_total');
150
- $order_max=$this->getConfigData('max_order_total');
151
- if(!empty($order_max) && (double)$order_max<$order_amount) {
152
- Mage::throwException("Order amount greater than permissible Maximum order amount.");
153
- }
154
- if(!empty($order_min) && (double)$order_min>$order_amount) {
155
- Mage::throwException("Order amount less than required Minimum order amount.");
156
- }
157
-
158
  parent::validate();
159
- }
160
-
161
- public function authorize(Varien_Object $payment, $amount) {
162
- if(Mage::app()->getStore()->isAdmin()){
163
- if ($amount <= 0) {
164
- Mage::throwException(Mage::helper('paygate')->__('Invalid amount for transaction.'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  }
166
-
167
- $this->Amount = number_format($amount, 2, '.', '');
168
- $this->TxType = self::ACTION_AUTHENTICATE;
169
- $this->AccountType = 'M';
170
- $this->Apply3DSecure = 2;
171
- $result = $this->__processPayment($payment);
172
-
173
- if (in_array($this->result['Status'],$this->getConfigModel()->getExpectedSuccess())) {
174
- $payment->setAdditionalInformation('payment_type', $this->getConfigData('payment_action'));
175
- $orderId = $payment->getOrder()->getIncrementId();
176
- $this->result['CustomerEmail'] = $this->CustomerEmail;
177
- $this->result['CustomerName'] = $this->BillingFirstnames.' '.$this->BillingSurname;
178
- $this->result['CardType'] = $this->CardType;
179
- $this->result['CardHolderName'] = $this->CardHolder;
180
- $this->result['CustomerContact'] = $this->BillingPhone;
181
- $this->result['VendorTxCode'] = $this->VendorTxCode;
182
- $sagepay_id = $this->getSagepayModel()->saveAuthDetail($this->result,$orderId);
183
- $this->getSagepayModel()->saveCardDetail($sagepay_id,$this->result);
184
- $this->getTransactionModel()->saveTransactionDetail($orderId ,$this->result, $this->VendorTxCode, self::ACTION_AUTHENTICATE, $sagepay_id);
185
- $this->_addTransaction(
186
- $payment,
187
- $this->VendorTxCode,
188
- Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH,
189
- array('is_transaction_closed' => 0));
190
-
191
- $payment->setSkipTransactionCreation(true);
192
- return $this;
193
- }
194
- else{
195
- $payment->setSkipTransactionCreation(true);
196
- if($result=='ERROR'){
197
- $error = $this->result;
198
- Mage::throwException($error['Errors'][0]);
199
- }
200
- else if(in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
201
- Mage::throwException("Gateway error : {".(string)$this->result['Errors'][0]."}");
202
- }
203
- }
204
- }
205
- else{
206
- $session = Mage::getSingleton('core/session');
207
- if ($data = $session->getGatewayResult()) {
208
- $payment->setAdditionalInformation('payment_type', $this->getConfigData('payment_action'));
209
- $orderId = $payment->getOrder()->getIncrementId();
210
- $sagepay_id = $this->getSagepayModel()->saveAuthDetail($data,$orderId);
211
- $this->getSagepayModel()->saveCardDetail($sagepay_id,$data);
212
- $this->getTransactionModel()->saveTransactionDetail($orderId ,$data, $data['VendorTxCode'], self::ACTION_AUTHENTICATE, $sagepay_id);
213
- $this->_addTransaction(
214
- $payment,
215
- $data['VendorTxCode'],
216
- Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH,
217
- array('is_transaction_closed' => 0));
218
- $session->unsGatewayResult()->unsPaymentdata();
219
- $payment->setSkipTransactionCreation(true);
220
- }
221
- return $this;
222
-
223
- }
224
-
225
- }
226
-
227
- public function capture(Varien_Object $payment, $amount) {
228
- if(Mage::app()->getStore()->isAdmin()){
229
- if ($amount <= 0) {
230
- Mage::throwException(Mage::helper('paygate')->__('Invalid amount for transaction.'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  }
232
-
233
- $data = $this->getSagepayModel()->getCollection()->addFieldToFilter('order_id',$payment->getOrder()->getIncrementId())->getFirstItem();
234
-
235
- if($data->getOrderId() == $payment->getOrder()->getIncrementId()){
236
- $this->authorizePayment($payment, number_format($amount, 2, '.', ''),$data);
237
-
238
- if(in_array($this->result['Status'],$this->getConfigModel()->getExpectedSuccess())){
239
- $orderId = $payment->getOrder()->getIncrementId();
240
- $sagepay_id = $this->getSagepayModel()->saveAuthorisedDetail($this->result,$this->VendorTxCode,$data, $payment->getOrder()->getIncrementId());
241
- $this->getTransactionModel()->saveTransactionDetail($orderId ,$this->result, $this->VendorTxCode, self::ACTION_PAYMENT, $sagepay_id);
242
- $payment->setStatus(self::STATUS_APPROVED);
243
- $payment->setLastTransId((string)$this->VendorTxCode);
244
- if (!$payment->getParentTransactionId() || (string)$this->VendorTxCode != $payment->getParentTransactionId()) {
245
- $payment->setTransactionId((string)$this->VendorTxCode);
246
- }
247
- return $this;
248
- }
249
- else{
250
- $payment->setSkipTransactionCreation(true);
251
- if(in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())){
252
- $error = $this->result;
253
- Mage::throwException($error['Errors'][0]);
254
- }
255
- }
256
-
257
- }
258
- $this->Amount = number_format($amount, 2, '.', '');
259
- $this->TxType = self::ACTION_PAYMENT;
260
- $this->AccountType = 'M';
261
- $this->Apply3DSecure = 2;
262
- $result = $this->__processPayment($payment);
263
-
264
- if (in_array($this->result['Status'],$this->getConfigModel()->getExpectedSuccess())) {
265
- $orderId = $payment->getOrder()->getIncrementId();
266
- $this->result['CustomerEmail'] = $this->CustomerEmail;
267
- $this->result['CustomerName'] = $this->BillingFirstnames.' '.$this->BillingSurname;
268
- $this->result['CardType'] = $this->CardType;
269
- $this->result['CardHolderName'] = $this->CardHolder;
270
- $this->result['CustomerContact'] = $this->BillingPhone;
271
- $this->result['VendorTxCode'] = $this->VendorTxCode;
272
- $sagepay_id = $this->getSagepayModel()->saveOrderDetail($this->result,$orderId);
273
- $this->getSagepayModel()->saveCardDetail($sagepay_id,$this->result);
274
- $this->getTransactionModel()->saveTransactionDetail($orderId ,$this->result, $this->VendorTxCode, self::ACTION_PAYMENT, $sagepay_id);
275
- $payment->setStatus(self::STATUS_APPROVED);
276
- $payment->setLastTransId((string)$this->VendorTxCode);
277
- if (!$payment->getParentTransactionId() || (string)$this->VendorTxCode != $payment->getParentTransactionId()) {
278
- $payment->setTransactionId((string)$this->VendorTxCode);
279
- }
280
- return $this;
281
- }
282
- else{
283
- $payment->setSkipTransactionCreation(true);
284
- if($result=='ERROR'){
285
- $error = $this->result;
286
- Mage::throwException($error['Errors'][0]);
287
- }
288
- else if(in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
289
- Mage::throwException("Gateway error : {".(string)$this->result['Errors'][0]."}");
290
- }
291
- }
292
- }
293
- else{
294
- $session = Mage::getSingleton('core/session');
295
- if ($data = $session->getGatewayResult()) {
296
- $payment->setAdditionalInformation('payment_type', $this->getConfigData('payment_action'));
297
- $orderId = $payment->getOrder()->getIncrementId();
298
- $sagepay_id = $this->getSagepayModel()->saveOrderDetail($data,$orderId);
299
- $this->getSagepayModel()->saveCardDetail($sagepay_id,$data);
300
- $this->getTransactionModel()->saveTransactionDetail($orderId ,$data, $data['VendorTxCode'], $data['TxType'], $sagepay_id);
301
- $payment->setStatus(self::STATUS_APPROVED);
302
- $payment->setLastTransId((string)$data['VendorTxCode']);
303
- if (!$payment->getParentTransactionId() || (string)$data['VendorTxCode'] != $payment->getParentTransactionId()) {
304
- $payment->setTransactionId((string)$data['VendorTxCode']);
305
- }
306
- $session->unsGatewayResult()->unsPaymentdata();
307
- }
308
- return $this;
309
- }
310
- }
311
-
312
- public function authorizePayment(Varien_Object $payment, $amount, $data) {
313
- $params = array();
314
- $params['VPSProtocol'] = urlencode('2.23');
315
- $params['TxType'] = self::ACTION_AUTHORISE;
316
- $params['Vendor'] = urlencode(Mage::getStoreConfig('payment/sagepay/vendor_name'));
317
- $params['VendorTxCode'] = time() . rand(0, 9999).'-'.$payment->getOrder()->getIncrementId();
318
- $this->VendorTxCode = $params['VendorTxCode'];
319
- $params['Amount'] = urlencode($amount);
320
- $params['Description'] = $this->Description;
321
- $params['RelatedVPSTxId'] = $data->getVpsTxId(); //VPSTxId of main transaction
322
- $params['RelatedVendorTxCode'] = urlencode($data->getVendorTxCode()); //VendorTxCode of main transaction
323
- $params['RelatedSecurityKey'] = urlencode($data->getSecurityKey()); //securitykey of main transaction
324
-
325
- $this->result = $this->requestPost($this->urls['authorise'], $params);
326
- if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
327
- $this->result['Errors'] = array();
328
- foreach(split("\n", $this->result['StatusDetail']) as $error) {
329
- $this->result['Errors'] = array_merge($this->result['Errors'], $this->getError($error));
330
- }
331
- }
332
- }
333
-
334
- public function refund(Varien_Object $payment, $amount) {
335
- if ($payment->getRefundTransactionId() && $amount > 0) {
336
- $data = $this->getSagepayModel()->getCollection()->addFieldToFilter('vendor_tx_code',trim($payment->getRefundTransactionId()))->getFirstItem();
337
-
338
- $params = array();
339
- $params['VPSProtocol'] = urlencode('2.23');
340
- $params['TxType'] = self::ACTION_REFUND;
341
- $params['Vendor'] = urlencode(Mage::getStoreConfig('payment/sagepay/vendor_name'));
342
- $params['VendorTxCode'] = time() . rand(0, 9999).'-'.$payment->getOrder()->getIncrementId();
343
- $params['Amount'] = urlencode(number_format($amount, 2, '.', ''));
344
- $params['Currency'] = urlencode(Mage::app()->getStore()->getCurrentCurrencyCode());
345
- $params['Description'] = $this->Description;
346
- $params['RelatedVPSTxId'] = $data->getVpsTxId();
347
- $params['RelatedVendorTxCode'] = urlencode($data->getVendorTxCode());
348
- $params['RelatedSecurityKey'] = urlencode($data->getSecurityKey());
349
- $params['RelatedTxAuthNo'] = urlencode($data->getTxAuthNo());
350
-
351
- $this->result = $this->requestPost($this->urls['refund'], $params);
352
-
353
- if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
354
- $this->result['Errors'] = array();
355
- foreach(split("\n", $this->result['StatusDetail']) as $error) {
356
- $this->result['Errors'] = array_merge($this->result['Errors'], $this->getError($error));
357
- }
358
- }
359
- if (in_array($this->result['Status'],$this->getConfigModel()->getExpectedSuccess())){
360
- $orderId = $payment->getOrder()->getIncrementId();
361
- $this->getSagepayModel()->saveRefundDetail($this->result,$data->getSagepayId());
362
- $this->getTransactionModel()->saveTransactionDetail($orderId ,$this->result, $params['VendorTxCode'], self::ACTION_REFUND, $data->getSagepayId());
363
- $payment->setStatus(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND);
364
- $payment->setLastTransId((string)$params['VendorTxCode']);
365
- if (!$payment->getParentTransactionId() || (string)$params['VendorTxCode'] != $payment->getParentTransactionId()) {
366
- $payment->setTransactionId((string)$params['VendorTxCode']);
367
- }
368
- return $this;
369
- }
370
- else{
371
- if($result=='ERROR'){
372
- $error = $this->result;
373
- Mage::throwException($error['Errors'][0]);
374
- }
375
- else if(in_array($result, $this->getConfigModel()->getExpectedError())) {
376
- Mage::throwException("Gateway error : {".(string)$this->result['Errors'][0]."}");
377
- }
378
- }
379
- }
380
  Mage::throwException(Mage::helper('paygate')->__('Error in refunding the payment.'));
381
-
382
- }
383
-
384
- public function void(Varien_Object $payment) {
385
-
386
- $orderId = $payment->getOrder()->getIncrementId();
387
- $data = $this->getSagepayModel()->getCollection()->addFieldToFilter('order_id',$orderId)->getFirstItem();
388
- $params = array();
389
- $params['VPSProtocol'] = urlencode('2.23');
390
- $params['TxType'] = self::ACTION_VOID;
391
- $params['Vendor'] = urlencode(Mage::getStoreConfig('payment/sagepay/vendor_name'));
392
- $params['VendorTxCode'] = urlencode($data->getVendorTxCode());
393
- $params['VPSTxId'] = $data->getVpsTxId();
394
- $params['SecurityKey'] = urlencode($data->getSecurityKey());
395
- $params['TxAuthNo'] = urlencode($data->getTxAuthNo());
396
-
397
- $this->result = $this->requestPost($this->urls['void'], $params);
398
- if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
399
- $this->result['Errors'] = array();
400
- foreach(split("\n", $this->result['StatusDetail']) as $error) {
401
- $this->result['Errors'] = array_merge($this->result['Errors'], $this->getError($error));
402
- }
403
- }
404
-
405
- if (in_array($this->result['Status'],$this->getConfigModel()->getExpectedSuccess())){
406
- $this->getSagepayModel()->saveVoidDetail($this->result,$data->getSagepayId());
407
- $this->getTransactionModel()->saveTransactionDetail($orderId ,$this->result, $params['VendorTxCode'], self::ACTION_VOID, $data->getSagepayId());
408
- $payment->setStatus(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID);
409
- $payment->setLastTransId((string)$params['VendorTxCode']);
410
- if (!$payment->getParentTransactionId() || (string)$params['VendorTxCode'] != $payment->getParentTransactionId()) {
411
- $payment->setTransactionId((string)$params['VendorTxCode']);
412
- }
413
- return $this;
414
- }
415
- else{
416
- if($result=='ERROR'){
417
- $error = $this->result;
418
- Mage::throwException($error['Errors'][0]);
419
- }
420
- else if(in_array($result, $this->getConfigModel()->getExpectedError())) {
421
- Mage::throwException("Gateway error : {".(string)$this->result['Errors'][0]."}");
422
- }
423
- }
424
  return $this;
425
  }
426
-
427
- public function cancel(Varien_Object $payment) {
 
428
  $orderId = $payment->getOrder()->getIncrementId();
429
- $data = $this->getSagepayModel()->getCollection()->addFieldToFilter('order_id',$orderId)->getFirstItem();
430
- $params = array();
431
- $params['VPSProtocol'] = urlencode('2.23');
432
- $params['TxType'] = self::ACTION_CANCEL;
433
- $params['Vendor'] = urlencode(Mage::getStoreConfig('payment/sagepay/vendor_name'));
434
- $params['VendorTxCode'] = urlencode($data->getVendorTxCode());
435
- $params['VPSTxId'] = $data->getVpsTxId();
436
- $params['SecurityKey'] = urlencode($data->getSecurityKey());
437
- $params['TxAuthNo'] = urlencode($data->getTxAuthNo());
438
-
439
- $this->result = $this->requestPost($this->urls['cancel'], $params);
440
- if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
441
- $this->result['Errors'] = array();
442
- foreach(split("\n", $this->result['StatusDetail']) as $error) {
443
- $this->result['Errors'] = array_merge($this->result['Errors'], $this->getError($error));
444
- }
445
- }
446
-
447
- if (in_array($this->result['Status'],$this->getConfigModel()->getExpectedSuccess())){
448
- $this->getSagepayModel()->saveVoidDetail($this->result,$data->getSagepayId());
449
- $this->getTransactionModel()->saveTransactionDetail($orderId ,$this->result, $params['VendorTxCode'], self::ACTION_CANCEL, $data->getSagepayId());
450
- $payment->setStatus(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID);
451
- $payment->setLastTransId((string)$params['VendorTxCode']);
452
- if (!$payment->getParentTransactionId() || (string)$params['VendorTxCode'] != $payment->getParentTransactionId()) {
453
- $payment->setTransactionId((string)$params['VendorTxCode']);
454
- }
455
- return $this;
456
- }
457
- else{
458
- if($result=='ERROR'){
459
- $error = $this->result;
460
- Mage::throwException($error['Errors'][0]);
461
- }
462
- else if(in_array($result, $this->getConfigModel()->getExpectedError())) {
463
- Mage::throwException("Gateway error : {".(string)$this->result['Errors'][0]."}");
464
- }
465
- }
466
  return $this;
467
- }
468
-
469
- public function __processPayment(Varien_Object $payment){
470
-
471
- $this->Currency = Mage::app()->getStore()->getCurrentCurrencyCode();
472
- $payment->setAmount($amount);
473
- $this->CardHolder = $payment->getCcOwner();
474
- $this->CardNumber = $payment->getCcNumber();
475
- $this->ExpiryDate = date("my",strtotime('01-'.$payment->getCcExpMonth().'-'.$payment->getCcExpYear()));
476
- $this->IssueNumber = $payment->getCcSsIssue();
477
- $this->CV2 = $payment->getCcCid();
478
- $this->CardType = $this->getConfigModel()->getCcCode($payment->getCcType());
479
- $order = $this->_getQuote();
480
- $this->setGatewayOrderData($order);
481
- return $this->register();
482
- }
483
-
484
- public function setGatewayOrderData($order){
485
-
486
- if (!empty($order)) {
487
- $BillingAddress = $order->getBillingAddress();
488
- $this->BillingSurname = $BillingAddress->getLastname();
489
- $this->BillingFirstnames = $BillingAddress->getFirstname();
490
- $this->BillingAddress1 = $BillingAddress->getStreet(1);
491
- $this->BillingAddress2;
492
- $this->BillingCity = $BillingAddress->getCity();
493
- $this->BillingPostCode = $BillingAddress->getPostcode();
494
- $this->BillingCountry = $BillingAddress->getCountry();
495
- $this->BillingState = Mage::getModel('directory/region')->load($BillingAddress->getRegionId())->getCode();
496
- $this->BillingPhone = $BillingAddress->getTelephone();
497
- if(!$order->getIsVirtual())
498
- $ShippingAddress = $order->getShippingAddress();
499
- else
500
- $ShippingAddress = $order->getBillingAddress();
501
- $this->DeliverySurname = $ShippingAddress->getLastname();
502
- $this->DeliveryFirstnames = $ShippingAddress->getFirstname();
503
- $this->DeliveryAddress1 = $ShippingAddress->getStreet(1);
504
- $this->DeliveryAddress2;
505
- $this->DeliveryCity = $ShippingAddress->getCity();
506
- $this->DeliveryPostCode = $ShippingAddress->getPostcode();
507
- $this->DeliveryCountry = $ShippingAddress->getCountry();
508
- $this->DeliveryState = Mage::getModel('directory/region')->load($ShippingAddress->getRegionId())->getCode();
509
- $this->DeliveryPhone = $ShippingAddress->getTelephone();
510
-
511
- $this->CustomerEmail = $order->getCustomerEmail();
512
- $this->VendorTxCode = time() . rand(0, 9999) .'-'. $this->_getTrnVendorTxCode();//$this->_getQuote()->getReservedOrderId();
513
- $product_array = array();
514
- foreach ($order->getAllItems() as $item) {
515
- if(!$item->getParentItemId())
516
- $this->addLine($item->getName(), $item->getQty(), $item->getPrice(), $item->getTaxAmount());
517
- }
518
- foreach ($order->getAllAddresses() as $address) {
519
- //Add shipping amount
520
- if($ship_amount = $address->getData('shipping_amount'))
521
- $this->addLine($address->getData('shipping_description'), 1, $ship_amount, 0);
522
-
523
- //Add discount amount
524
- if($address->getData('discount_amount')<0)
525
- $this->addLine('Discount', 1, $address->getData('discount_amount'), 0);
526
- }
527
-
528
-
529
- }
530
- }
531
-
532
- public function register() {
533
-
534
- $errors = array();
535
- if (!$this->Vendor) $errors[] = 'The Vendor must be provided';
536
- if (!$this->VendorTxCode) $errors[] = 'The VendorTxCode must be provided';
537
- if (!is_numeric($this->Amount)) $errors[] = 'The Amount field must be specified, and must be numeric.';
538
- if (!$this->Currency) $errors[] = 'Currency must be specified, eg GBP.';
539
- if (!$this->CardHolder) $errors[] = 'CardHolder must be specified.';
540
- if (!$this->CardNumber) $errors[] = 'CardNumber must be specified.';
541
- if (!$this->ExpiryDate) $errors[] = 'ExpiryDate must be specified.';
542
- if ($this->IssueNumber and !preg_match("/^\d{1,2}$/", $this->IssueNumber)) $errors[] = 'IssueNumber is invalid.';
543
- if ($this->CardType=='AMEX' and !preg_match("/^\d{4}$/", $this->CV2)) $errors[] = 'CV2 must be 4 numbers long.';
544
- if ($this->CardType!='AMEX' and !preg_match("/^\d{3}$/", $this->CV2)) $errors[] = 'CV2 must be 3 numbers long.';
545
- if (!in_array($this->CardType, array('VISA', 'MC', 'DELTA', 'SOLO', 'MAESTRO', 'UKE', 'AMEX', 'DC', 'JCB', 'LASER'))) $errors[] = 'CardType must be one of VISA, MC, DELTA, SOLO, MAESTRO, UKE, AMEX, DC, JCB, LASER';
546
- if (!$this->BillingSurname) $errors[] = 'BillingSurname must be specified.';
547
- if (!$this->BillingFirstnames) $errors[] = 'BillingFirstnames must be specified.';
548
- if (!$this->BillingAddress1) $errors[] = 'BillingAddress1 must be specified.';
549
- if (!$this->BillingCity) $errors[] = 'BillingCity must be specified.';
550
- if (!$this->BillingPostCode) $errors[] = 'BillingPostCode must be specified.';
551
- if (!$this->BillingCountry) $errors[] = 'BillingCountry must be specified.';
552
- if ($this->BillingCountry == 'US' and !$this->BillingState) $errors['BillingState'] = 'BillingState mut be specified.';
553
- if (!$this->DeliverySurname) $errors[] = 'DeliverySurname must be specified.';
554
- if (!$this->DeliveryFirstnames) $errors[] = 'DeliveryFirstnames must be specified.';
555
- if (!$this->DeliveryAddress1) $errors[] = 'DeliveryAddress1 must be specified.';
556
- if (!$this->DeliveryCity) $errors[] = 'DeliveryCity must be specified.';
557
- if (!$this->DeliveryPostCode) $errors[] = 'DeliveryPostCode must be specified.';
558
- if (!$this->DeliveryCountry) $errors[] = 'DeliveryCountry must be specified.';
559
- if ($this->DeliveryCountry == 'US' and !$this->DeliveryState) $errors[] = 'DeliveryState mut be specified.';
560
- if ($this->CustomerEmail and !preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+\.([a-zA-Z0-9\._-]+)+$/", $this->CustomerEmail)) $errors[] = 'CustomerEmail is invalid.';
561
-
562
- if (count($errors)) {
563
- $this->result = array('Status' => 'ERRORCHECKFAIL', 'Errors' => $errors);
564
- return 'ERROR';
565
- }
566
-
567
- $data = array(
568
- 'VPSProtocol' => 2.23,
569
- 'TxType' => $this->TxType,
570
- 'Vendor' => $this->Vendor,
571
- 'VendorTxCode' => $this->VendorTxCode,
572
- 'Amount' => number_format($this->Amount, 2, '.', ''),
573
- 'Currency' => $this->Currency,
574
- 'Description' => $this->Description,
575
- 'CardHolder' => $this->CardHolder,
576
- 'CardNumber' => $this->CardNumber,
577
- 'ExpiryDate' => $this->ExpiryDate,
578
- 'IssueNumber' => $this->IssueNumber,
579
- 'CV2' => $this->CV2,
580
- 'CardType' => $this->CardType,
581
- 'BillingSurname' => $this->BillingSurname,
582
- 'BillingFirstnames' => $this->BillingFirstnames,
583
- 'BillingAddress1' => $this->BillingAddress1,
584
- 'BillingAddress2' => $this->BillingAddress2,
585
- 'BillingCity' => $this->BillingCity,
586
- 'BillingPostCode' => $this->BillingPostCode,
587
- 'BillingCountry' => $this->BillingCountry,
588
- 'BillingState' => $this->BillingCountry == 'US' ? $this->BillingState : '',
589
- 'BillingPhone' => $this->BillingPhone,
590
- 'DeliverySurname' => $this->DeliverySurname,
591
- 'DeliveryFirstnames' => $this->DeliveryFirstnames,
592
- 'DeliveryAddress1' => $this->DeliveryAddress1,
593
- 'DeliveryAddress2' => $this->DeliveryAddress2,
594
- 'DeliveryCity' => $this->DeliveryCity,
595
- 'DeliveryPostCode' => $this->DeliveryPostCode,
596
- 'DeliveryCountry' => $this->DeliveryCountry,
597
- 'DeliveryState' => $this->DeliveryCountry == 'US' ? $this->DeliveryState : '',
598
- 'DeliveryPhone' => $this->DeliveryPhone,
599
- 'CustomerEmail' => $this->CustomerEmail,
600
- 'GiftAidPayment' => $this->GiftAidPayment,
601
- 'AccountType' => $this->AccountType,
602
- 'ClientIPAddress' => $_SERVER['REMOTE_ADDR'],
603
- 'ApplyAVSCV2' => $this->ApplyAVSCV2,
604
- 'Apply3DSecure' => $this->Apply3DSecure
605
- );
606
-
607
- if (sizeof($this->Basket)) {
608
- $data['Basket'] = count($this->Basket);
609
- foreach($this->Basket as $line) {
610
- $data['Basket'] .= ':' . $line['description'];
611
- $data['Basket'] .= ':' . $line['quantity'];
612
- $data['Basket'] .= ':' . number_format($line['value'], 2, '.', '');
613
- $data['Basket'] .= ':' . number_format($line['tax'], 2, '.', '');
614
- $data['Basket'] .= ':' . number_format(($line['value'] + $line['tax']), 2, '.', '');
615
- $data['Basket'] .= ':' . number_format(($line['quantity'] * ($line['value'] + $line['tax'])), 2, '.', '');
616
- }
617
- }
618
-
619
- $this->result = $this->requestPost($this->urls['register'], $data);
620
-
621
- if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
622
- $this->result['Errors'] = array();
623
- foreach(split("\n", $this->result['StatusDetail']) as $error) {
624
- $this->result['Errors'] = array_merge($this->result['Errors'], $this->getError($error));
625
- }
626
- }
627
- if ($this->result['Status'] == '3DAUTH') {
628
-
629
- $this->result['VendorTxCode'] = $this->VendorTxCode;
630
- return $this->result;
631
- }
632
- return $this->result;
633
- }
634
-
635
- public function addLine($description, $quantity, $value, $tax=0) {
636
- $this->Basket[] = array(
637
- 'description' => $description,
638
- 'quantity' => $quantity,
639
- 'value' => $value,
640
- 'tax' => $tax
641
- );
642
- }
643
-
644
- public static function recover3d() {
645
- $sagepay = unserialize($_SESSION['sagepay_obj']);
646
- unset($_SESSION['sagepay_obj']);
647
- return $sagepay;
648
- }
649
-
650
- public static function is3dResponse() {
651
- if (isset($_REQUEST['PaRes']) and isset($_REQUEST['MD']) and isset($_SESSION['sagepay_obj'])) {
652
- return true;
653
- } else {
654
- return false;
655
- }
656
- }
657
-
658
- public function complete3d($post_data) {
659
- $session = Mage::getSingleton('core/session');
660
- $data = array(
661
- 'PARes' => $post_data['PaRes'],
662
- 'MD' => $post_data['MD']
663
- );
664
-
665
- $result = $this->requestPost($this->urls['3dsecure'], $data);
666
- $vendor = $session->getGatewayResult($gateway_result);
667
- $result['VendorTxCode'] = $vendor['VendorTxCode'];
668
- $result['CustomerEmail'] = $vendor['CustomerEmail'];
669
- $result['CustomerName'] = $vendor['CustomerName'];
670
- $result['CardType'] = $vendor['CardType'];
671
- $result['CardHolderName'] = $vendor['CardHolderName'];
672
- $result['CustomerContact'] = $vendor['CustomerContact'];
673
- $result['TxType'] = $vendor['TxType'];
674
- return $result;
675
-
676
- }
677
-
678
- public function status() {
679
- return $this->result['Status'];
680
- }
681
-
682
- private function getError($message) {
683
- $chunks = split(' : ', $message, 2);
684
- if ($chunks[0] == '3048') { return array('CardNumber' => 'The card number is invalid.'); }
685
- if ($chunks[0] == '4022') { return array('CardNumber' => 'The card number is not valid for the card type selected.'); }
686
- if ($chunks[0] == '4023') { return array('CardNumber' => 'The issue number must be provided.'); }
687
- return array($message);
688
- }
689
-
690
- private function requestPost($url, $data){
691
- $fields_string = http_build_query($data);
692
- $log['request'] = $data;
693
- set_time_limit(60);
694
- $output = array();
695
- $curlSession = curl_init();
696
- curl_setopt ($curlSession, CURLOPT_URL, $url);
697
- curl_setopt ($curlSession, CURLOPT_HEADER, 0);
698
- curl_setopt ($curlSession, CURLOPT_POST, 1);
699
- curl_setopt ($curlSession, CURLOPT_POSTFIELDS, $fields_string);
700
- curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
701
- curl_setopt($curlSession, CURLOPT_TIMEOUT, 30);
702
- curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, FALSE);
703
- curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 2);
704
- $response = explode(chr(10), curl_exec($curlSession));
705
- $log['response'] = $response;
706
- $this->getSagepayModel()->logTransaction($log);
707
- unset($this->CardNumber);
708
- unset($this->ExpiryDate);
709
- unset($this->CV2);
710
-
711
- if (curl_error($curlSession)){
712
- $output['Status'] = "FAIL";
713
- $output['StatusDetail'] = curl_error($curlSession);
714
- }
715
- curl_close ($curlSession);
716
- for ($i=0; $i<count($response); $i++){
717
- $splitAt = strpos($response[$i], "=");
718
- $output[trim(substr($response[$i], 0, $splitAt))] = trim(substr($response[$i], ($splitAt+1)));
719
- }
720
- return $output;
721
- }
722
-
723
- public static function country($code) {
724
- $countries = $this->getSagepayModel()->countries();
725
- return $countries[$code];
726
- }
727
-
728
- public function registerTransaction($data){
729
- if(Mage::getStoreConfig('payment/sagepay/payment_action')=='authorize'){
730
- $this->TxType = self::ACTION_AUTHENTICATE;
731
- }
732
- elseif(Mage::getStoreConfig('payment/sagepay/payment_action')=='authorize_capture'){
733
- $this->TxType = self::ACTION_PAYMENT;
734
- }
735
- return $this->sagePayRegisterPayment($data);
736
- }
737
-
738
- public function sagePayRegisterPayment($data) {
739
-
740
- $quote = Mage::getSingleton('checkout/session')->getQuote();
741
- $amount = $quote->getData('grand_total');
742
-
743
- if ($amount <= 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
744
  Mage::throwException(Mage::helper('paygate')->__('Invalid amount for transaction.'));
745
  }
746
-
747
- $this->Currency = Mage::app()->getStore()->getCurrentCurrencyCode();
748
- $this->Amount = $amount;
749
- $this->CardHolder = $data['cc_owner'];
750
- $this->CardNumber = $data['cc_number'];
751
- $this->ExpiryDate = date("my",strtotime('01-'.$data['cc_exp_month'].'-'.$data['cc_exp_year']));
752
- $this->CV2 = $data['cc_cid'];
753
- $this->CardType = $this->getConfigModel()->getCcCode($data['cc_type']);
754
-
755
- $this->setGatewayOrderData($quote);
756
- $result = $this->register();
757
- if($result=='ERROR'){
758
- $error = $this->result;
759
- Mage::throwException($error['Errors'][0]);
760
- }
761
- elseif(in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
762
- if(!$this->result['Errors'][0])
763
- Mage::throwException("Gateway error : {".(string)$this->result['StatusDetail']."}");
764
- else
765
- Mage::throwException("Gateway error : {".(string)$this->result['Errors'][0]."}");
766
- }
767
- else{
768
- $result['CustomerEmail'] = $this->CustomerEmail;
769
- $result['CustomerName'] = $this->BillingFirstnames.' '.$this->BillingSurname;
770
- $result['CardType'] = $this->CardType;
771
- $result['CardHolderName'] = $this->CardHolder;
772
- $result['CustomerContact'] = $this->BillingPhone;
773
- $result['TxType'] = $this->TxType;
774
- $result['VendorTxCode'] = $this->VendorTxCode;
775
- }
776
- return $result;
777
- }
778
-
779
- protected function _addTransaction(Mage_Sales_Model_Order_Payment $payment, $transactionId, $transactionType,
780
- array $transactionDetails = array(), $message = false ) {
781
-
782
  $payment->setTransactionId($transactionId);
783
  $payment->resetTransactionAdditionalInfo();
784
  foreach ($transactionDetails as $key => $value) {
785
  $payment->setData($key, $value);
786
  }
787
-
788
- $transaction = $payment->addTransaction($transactionType, null, false , $message);
789
  foreach ($transactionDetails as $key => $value) {
790
  $payment->unsetData($key);
791
  }
@@ -795,18 +822,22 @@ class Raveinfosys_Sagepay_Model_Payment extends Mage_Payment_Model_Method_Ccsave
795
 
796
  return $transaction;
797
  }
798
-
799
- public function getConfigModel(){
800
- return Mage::getSingleton('sagepay/config');
801
- }
802
-
803
- public function getSagepayModel(){
804
- return Mage::getSingleton('sagepay/sagepay');
805
- }
806
-
807
- public function getTransactionModel(){
808
- return Mage::getSingleton('sagepay/transaction');
809
- }
 
 
 
810
 
811
  }
 
812
  ?>
1
  <?php
2
 
3
+ class Raveinfosys_Sagepay_Model_Payment extends Mage_Payment_Model_Method_Ccsave
4
+ {
5
+
6
+ protected $_code = 'sagepay';
7
+ protected $_isGateway = true; //Is this payment method a gateway (online auth/charge) ?
8
+ protected $_canAuthorize = true; //Can authorize online?
9
+ protected $_canCapture = true; //Can capture funds online?
10
+ protected $_canCapturePartial = true; //Can capture partial amounts online?
11
+ protected $_canRefund = true; //Can refund online?
12
+ protected $_canRefundInvoicePartial = true; //Can refund invoices partially?
13
+ protected $_canVoid = true; //Can void transactions online?
14
+ protected $_canUseInternal = true; //Can use this payment method in administration panel?
15
+ protected $_canUseCheckout = true; //Can show this payment method as an option on checkout payment page?
16
+ protected $_canUseForMultishipping = true; //Is this payment method suitable for multi-shipping checkout?
17
+ protected $_canFetchTransactionInfo = false;
18
+ protected $_canReviewPayment = true;
19
  protected $_infoBlockType = 'payment/info_cc';
20
+ protected $_canSaveCc = false;
21
+
22
+ const ACTION_PAYMENT = 'PAYMENT';
23
  const ACTION_VOID = 'VOID';
24
+ const ACTION_AUTHORISE = 'AUTHORISE';
25
+ const ACTION_AUTHENTICATE = 'AUTHENTICATE';
26
+ const ACTION_REFUND = 'REFUND';
27
+ const ACTION_CANCEL = 'CANCEL';
28
+
29
  private $urls;
30
+ private $Vendor;
31
+ private $Basket = array();
32
+ public $AccountType = 'E';
33
+ public $GiftAidPayment = 0;
34
+ public $ApplyAVSCV2 = 0;
35
+ public $Apply3DSecure = 0;
36
+ public $Description = "Sagepay Direct Transaction.";
37
+ public $VendorTxCode;
38
+ public $TxType;
39
+ public $Amount;
40
+ public $Currency;
41
+ public $CardHolder;
42
+ public $CardNumber;
43
+ public $StartDate;
44
+ public $ExpiryDate;
45
+ public $IssueNumber;
46
+ public $CV2;
47
+ public $CardType;
48
+ public $BillingSurname;
49
+ public $BillingFirstnames;
50
+ public $BillingAddress1;
51
+ public $BillingAddress2;
52
+ public $BillingCity;
53
+ public $BillingPostCode;
54
+ public $BillingCountry;
55
+ public $BillingState;
56
+ public $BillingPhone;
57
+ public $DeliverySurname;
58
+ public $DeliveryFirstnames;
59
+ public $DeliveryAddress1;
60
+ public $DeliveryAddress2;
61
+ public $DeliveryCity;
62
+ public $DeliveryPostCode;
63
+ public $DeliveryCountry;
64
+ public $DeliveryState;
65
+ public $DeliveryPhone;
66
+ public $CustomerEmail;
67
+ public $OrderIncrementId;
68
+ public $result = array('Status' => 'BEGIN');
69
+
70
+ public function __construct($vendor, $mode = 'simulator')
71
+ {
72
+
73
+ $this->urls = $this->getConfigModel()->getGatewayURL();
74
+ $this->Vendor = $this->getConfigModel()->getVendor();
75
+ }
76
+
77
+ public function isMsOnOverview()
78
+ {
 
79
  return ($this->_getQuote()->getIsMultiShipping() && $this->getMsActiveStep() == 'multishipping_overview');
80
  }
81
+
82
+ public function getMsActiveStep()
83
+ {
84
  return Mage::getSingleton('checkout/type_multishipping_state')->getActiveStep();
85
  }
86
+
87
+ protected function _getReservedOid()
88
+ {
89
 
90
  if ($this->isMsOnOverview() && ($this->_getQuote()->getPayment()->getMethod() == 'sagepay')) {
91
  return null;
99
  $this->_getQuote()->unsReservedOrderId();
100
  $this->_getQuote()->reserveOrderId()->save();
101
  }
102
+ $orderId = $this->_getQuote()->getReservedOrderId();
103
  $this->getSagepayModel()->setReservedId($orderId);
104
  }
105
 
108
  }
109
  return $orderId;
110
  }
111
+
112
+ protected function _orderIdAlreadyUsed($orderId)
113
+ {
114
  if (!$orderId)
115
  return false;
116
 
119
  if (!$existingOrder->getId()) {
120
  return false;
121
  }
122
+ return true;
123
  }
124
+
125
+ protected function _getQuote()
126
+ {
127
 
128
  $opQuote = Mage::getSingleton('checkout/type_onepage')->getQuote();
129
  $adminQuote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
132
  if ($adminQuote->hasItems() === false && (int) $rqQuoteId) {
133
  $opQuote->setQuote(Mage::getModel('sales/quote')->loadActive($rqQuoteId));
134
  }
135
+ return ($adminQuote->hasItems() === true) ? $adminQuote : $opQuote;
136
  }
137
 
138
+ protected function _getTrnVendorTxCode()
139
+ {
140
  return $this->_getReservedOid();
141
  }
142
+
143
+ public function validate()
144
+ {
145
+ $info = $this->getInfoInstance();
146
+ $order_amount = 0;
147
+ if ($info instanceof Mage_Sales_Model_Quote_Payment) {
148
+ $order_amount = (double) $info->getQuote()->getBaseGrandTotal();
149
  } elseif ($info instanceof Mage_Sales_Model_Order_Payment) {
150
+ $order_amount = (double) $info->getOrder()->getQuoteBaseGrandTotal();
151
+ }
152
+
153
+ $order_min = $this->getConfigData('min_order_total');
154
+ $order_max = $this->getConfigData('max_order_total');
155
+ if (!empty($order_max) && (double) $order_max < $order_amount) {
156
+ Mage::throwException("Order amount greater than permissible Maximum order amount.");
157
+ }
158
+ if (!empty($order_min) && (double) $order_min > $order_amount) {
159
+ Mage::throwException("Order amount less than required Minimum order amount.");
160
+ }
161
+
162
  parent::validate();
163
+ }
164
+
165
+ public function authorize(Varien_Object $payment, $amount)
166
+ {
167
+ if (Mage::app()->getStore()->isAdmin()) {
168
+ if ($amount <= 0) {
169
+ Mage::throwException(Mage::helper('paygate')->__('Invalid amount for transaction.'));
170
+ }
171
+
172
+ $this->Amount = number_format($amount, 2, '.', '');
173
+ $this->TxType = self::ACTION_AUTHENTICATE;
174
+ $this->AccountType = 'M';
175
+ $this->Apply3DSecure = 2;
176
+ $result = $this->__processPayment($payment);
177
+
178
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedSuccess())) {
179
+ $payment->setAdditionalInformation('payment_type', $this->getConfigData('payment_action'));
180
+ $orderId = $payment->getOrder()->getIncrementId();
181
+ $this->result['CustomerEmail'] = $this->CustomerEmail;
182
+ $this->result['CustomerName'] = $this->BillingFirstnames . ' ' . $this->BillingSurname;
183
+ $this->result['CardType'] = $this->CardType;
184
+ $this->result['CardHolderName'] = $this->CardHolder;
185
+ $this->result['CustomerContact'] = $this->BillingPhone;
186
+ $this->result['VendorTxCode'] = $this->VendorTxCode;
187
+ $sagepay_id = $this->getSagepayModel()->saveAuthDetail($this->result, $orderId);
188
+ $this->getSagepayModel()->saveCardDetail($sagepay_id, $this->result);
189
+ $this->getTransactionModel()->saveTransactionDetail($orderId, $this->result, $this->VendorTxCode, self::ACTION_AUTHENTICATE, $sagepay_id);
190
+ $this->_addTransaction(
191
+ $payment, $this->VendorTxCode, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, array('is_transaction_closed' => 0));
192
+
193
+ $payment->setSkipTransactionCreation(true);
194
+ return $this;
195
+ } else {
196
+ $payment->setSkipTransactionCreation(true);
197
+ if ($result == 'ERROR') {
198
+ $error = $this->result;
199
+ Mage::throwException($error['Errors'][0]);
200
+ } else if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
201
+ Mage::throwException("Gateway error : {" . (string) $this->result['Errors'][0] . "}");
202
+ }
203
+ }
204
+ } else {
205
+ $session = Mage::getSingleton('core/session');
206
+ if ($data = $session->getGatewayResult()) {
207
+ $payment->setAdditionalInformation('payment_type', $this->getConfigData('payment_action'));
208
+ $orderId = $payment->getOrder()->getIncrementId();
209
+ $sagepay_id = $this->getSagepayModel()->saveAuthDetail($data, $orderId);
210
+ $this->getSagepayModel()->saveCardDetail($sagepay_id, $data);
211
+ $this->getTransactionModel()->saveTransactionDetail($orderId, $data, $data['VendorTxCode'], self::ACTION_AUTHENTICATE, $sagepay_id);
212
+ $this->_addTransaction(
213
+ $payment, $data['VendorTxCode'], Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, array('is_transaction_closed' => 0));
214
+ $session->unsGatewayResult()->unsPaymentdata();
215
+ $payment->setSkipTransactionCreation(true);
216
+ }
217
+ return $this;
218
  }
219
+ }
220
+
221
+ public function capture(Varien_Object $payment, $amount)
222
+ {
223
+ if (Mage::app()->getStore()->isAdmin()) {
224
+ if ($amount <= 0) {
225
+ Mage::throwException(Mage::helper('paygate')->__('Invalid amount for transaction.'));
226
+ }
227
+
228
+ $data = $this->getSagepayModel()->getCollection()->addFieldToFilter('order_id', $payment->getOrder()->getIncrementId())->getFirstItem();
229
+
230
+ if ($data->getOrderId() == $payment->getOrder()->getIncrementId()) {
231
+ $this->authorizePayment($payment, number_format($amount, 2, '.', ''), $data);
232
+
233
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedSuccess())) {
234
+ $orderId = $payment->getOrder()->getIncrementId();
235
+ $sagepay_id = $this->getSagepayModel()->saveAuthorisedDetail($this->result, $this->VendorTxCode, $data, $payment->getOrder()->getIncrementId());
236
+ $this->getTransactionModel()->saveTransactionDetail($orderId, $this->result, $this->VendorTxCode, self::ACTION_PAYMENT, $sagepay_id);
237
+ $payment->setStatus(self::STATUS_APPROVED);
238
+ $payment->setLastTransId((string) $this->VendorTxCode);
239
+ if (!$payment->getParentTransactionId() || (string) $this->VendorTxCode != $payment->getParentTransactionId()) {
240
+ $payment->setTransactionId((string) $this->VendorTxCode);
241
+ }
242
+ return $this;
243
+ } else {
244
+ $payment->setSkipTransactionCreation(true);
245
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
246
+ $error = $this->result;
247
+ Mage::throwException($error['Errors'][0]);
248
+ }
249
+ }
250
+ }
251
+ $this->Amount = number_format($amount, 2, '.', '');
252
+ $this->TxType = self::ACTION_PAYMENT;
253
+ $this->AccountType = 'M';
254
+ $this->Apply3DSecure = 2;
255
+ $result = $this->__processPayment($payment);
256
+
257
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedSuccess())) {
258
+ $orderId = $payment->getOrder()->getIncrementId();
259
+ $this->result['CustomerEmail'] = $this->CustomerEmail;
260
+ $this->result['CustomerName'] = $this->BillingFirstnames . ' ' . $this->BillingSurname;
261
+ $this->result['CardType'] = $this->CardType;
262
+ $this->result['CardHolderName'] = $this->CardHolder;
263
+ $this->result['CustomerContact'] = $this->BillingPhone;
264
+ $this->result['VendorTxCode'] = $this->VendorTxCode;
265
+ $sagepay_id = $this->getSagepayModel()->saveOrderDetail($this->result, $orderId);
266
+ $this->getSagepayModel()->saveCardDetail($sagepay_id, $this->result);
267
+ $this->getTransactionModel()->saveTransactionDetail($orderId, $this->result, $this->VendorTxCode, self::ACTION_PAYMENT, $sagepay_id);
268
+ $payment->setStatus(self::STATUS_APPROVED);
269
+ $payment->setLastTransId((string) $this->VendorTxCode);
270
+ if (!$payment->getParentTransactionId() || (string) $this->VendorTxCode != $payment->getParentTransactionId()) {
271
+ $payment->setTransactionId((string) $this->VendorTxCode);
272
+ }
273
+ return $this;
274
+ } else {
275
+ $payment->setSkipTransactionCreation(true);
276
+ if ($result == 'ERROR') {
277
+ $error = $this->result;
278
+ Mage::throwException($error['Errors'][0]);
279
+ } else if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
280
+ Mage::throwException("Gateway error : {" . (string) $this->result['Errors'][0] . "}");
281
+ }
282
+ }
283
+ } else {
284
+ $session = Mage::getSingleton('core/session');
285
+ if ($data = $session->getGatewayResult()) {
286
+ $payment->setAdditionalInformation('payment_type', $this->getConfigData('payment_action'));
287
+ $orderId = $payment->getOrder()->getIncrementId();
288
+ $sagepay_id = $this->getSagepayModel()->saveOrderDetail($data, $orderId);
289
+ $this->getSagepayModel()->saveCardDetail($sagepay_id, $data);
290
+ $this->getTransactionModel()->saveTransactionDetail($orderId, $data, $data['VendorTxCode'], $data['TxType'], $sagepay_id);
291
+ $payment->setStatus(self::STATUS_APPROVED);
292
+ $payment->setLastTransId((string) $data['VendorTxCode']);
293
+ if (!$payment->getParentTransactionId() || (string) $data['VendorTxCode'] != $payment->getParentTransactionId()) {
294
+ $payment->setTransactionId((string) $data['VendorTxCode']);
295
+ }
296
+ $session->unsGatewayResult()->unsPaymentdata();
297
+ }
298
+ return $this;
299
+ }
300
+ }
301
+
302
+ public function authorizePayment(Varien_Object $payment, $amount, $data)
303
+ {
304
+ $params = array();
305
+ $params['VPSProtocol'] = urlencode('2.23');
306
+ $params['TxType'] = self::ACTION_AUTHORISE;
307
+ $params['Vendor'] = urlencode(Mage::getStoreConfig('payment/sagepay/vendor_name'));
308
+ $params['VendorTxCode'] = time() . rand(0, 9999) . '-' . $payment->getOrder()->getIncrementId();
309
+ $this->VendorTxCode = $params['VendorTxCode'];
310
+ $params['Amount'] = urlencode($amount);
311
+ $params['Description'] = $this->Description;
312
+ $params['RelatedVPSTxId'] = $data->getVpsTxId(); //VPSTxId of main transaction
313
+ $params['RelatedVendorTxCode'] = urlencode($data->getVendorTxCode()); //VendorTxCode of main transaction
314
+ $params['RelatedSecurityKey'] = urlencode($data->getSecurityKey()); //securitykey of main transaction
315
+
316
+ $this->result = $this->requestPost($this->urls['authorise'], $params);
317
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
318
+ $this->result['Errors'] = array();
319
+ foreach (preg_split("\n", $this->result['StatusDetail']) as $error) {
320
+ $this->result['Errors'] = array_merge($this->result['Errors'], $this->getError($error));
321
+ }
322
+ }
323
+ }
324
+
325
+ public function refund(Varien_Object $payment, $amount)
326
+ {
327
+ if ($payment->getRefundTransactionId() && $amount > 0) {
328
+ $data = $this->getSagepayModel()->getCollection()->addFieldToFilter('vendor_tx_code', trim($payment->getRefundTransactionId()))->getFirstItem();
329
+
330
+ $params = array();
331
+ $params['VPSProtocol'] = urlencode('2.23');
332
+ $params['TxType'] = self::ACTION_REFUND;
333
+ $params['Vendor'] = urlencode(Mage::getStoreConfig('payment/sagepay/vendor_name'));
334
+ $params['VendorTxCode'] = time() . rand(0, 9999) . '-' . $payment->getOrder()->getIncrementId();
335
+ $params['Amount'] = urlencode(number_format($amount, 2, '.', ''));
336
+ $params['Currency'] = urlencode(Mage::app()->getStore()->getCurrentCurrencyCode());
337
+ $params['Description'] = $this->Description;
338
+ $params['RelatedVPSTxId'] = $data->getVpsTxId();
339
+ $params['RelatedVendorTxCode'] = urlencode($data->getVendorTxCode());
340
+ $params['RelatedSecurityKey'] = urlencode($data->getSecurityKey());
341
+ $params['RelatedTxAuthNo'] = urlencode($data->getTxAuthNo());
342
+
343
+ $this->result = $this->requestPost($this->urls['refund'], $params);
344
+
345
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
346
+ $this->result['Errors'] = array();
347
+ foreach (preg_split("\n", $this->result['StatusDetail']) as $error) {
348
+ $this->result['Errors'] = array_merge($this->result['Errors'], $this->getError($error));
349
+ }
350
+ }
351
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedSuccess())) {
352
+ $orderId = $payment->getOrder()->getIncrementId();
353
+ $this->getSagepayModel()->saveRefundDetail($this->result, $data->getSagepayId());
354
+ $this->getTransactionModel()->saveTransactionDetail($orderId, $this->result, $params['VendorTxCode'], self::ACTION_REFUND, $data->getSagepayId());
355
+ $payment->setStatus(Mage_Sales_Model_Order_Payment_Transaction::TYPE_REFUND);
356
+ $payment->setLastTransId((string) $params['VendorTxCode']);
357
+ if (!$payment->getParentTransactionId() || (string) $params['VendorTxCode'] != $payment->getParentTransactionId()) {
358
+ $payment->setTransactionId((string) $params['VendorTxCode']);
359
+ }
360
+ return $this;
361
+ } else {
362
+ if ($result == 'ERROR') {
363
+ $error = $this->result;
364
+ Mage::throwException($error['Errors'][0]);
365
+ } else if (in_array($result, $this->getConfigModel()->getExpectedError())) {
366
+ Mage::throwException("Gateway error : {" . (string) $this->result['Errors'][0] . "}");
367
+ }
368
+ }
369
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  Mage::throwException(Mage::helper('paygate')->__('Error in refunding the payment.'));
371
+ }
372
+
373
+ public function void(Varien_Object $payment)
374
+ {
375
+
376
+ $orderId = $payment->getOrder()->getIncrementId();
377
+ $data = $this->getSagepayModel()->getCollection()->addFieldToFilter('order_id', $orderId)->getFirstItem();
378
+ $params = array();
379
+ $params['VPSProtocol'] = urlencode('2.23');
380
+ $params['TxType'] = self::ACTION_VOID;
381
+ $params['Vendor'] = urlencode(Mage::getStoreConfig('payment/sagepay/vendor_name'));
382
+ $params['VendorTxCode'] = urlencode($data->getVendorTxCode());
383
+ $params['VPSTxId'] = $data->getVpsTxId();
384
+ $params['SecurityKey'] = urlencode($data->getSecurityKey());
385
+ $params['TxAuthNo'] = urlencode($data->getTxAuthNo());
386
+
387
+ $this->result = $this->requestPost($this->urls['void'], $params);
388
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
389
+ $this->result['Errors'] = array();
390
+ foreach (preg_split("\n", $this->result['StatusDetail']) as $error) {
391
+ $this->result['Errors'] = array_merge($this->result['Errors'], $this->getError($error));
392
+ }
393
+ }
394
+
395
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedSuccess())) {
396
+ $this->getSagepayModel()->saveVoidDetail($this->result, $data->getSagepayId());
397
+ $this->getTransactionModel()->saveTransactionDetail($orderId, $this->result, $params['VendorTxCode'], self::ACTION_VOID, $data->getSagepayId());
398
+ $payment->setStatus(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID);
399
+ $payment->setLastTransId((string) $params['VendorTxCode']);
400
+ if (!$payment->getParentTransactionId() || (string) $params['VendorTxCode'] != $payment->getParentTransactionId()) {
401
+ $payment->setTransactionId((string) $params['VendorTxCode']);
402
+ }
403
+ return $this;
404
+ } else {
405
+ if ($result == 'ERROR') {
406
+ $error = $this->result;
407
+ Mage::throwException($error['Errors'][0]);
408
+ } else if (in_array($result, $this->getConfigModel()->getExpectedError())) {
409
+ Mage::throwException("Gateway error : {" . (string) $this->result['Errors'][0] . "}");
410
+ }
411
+ }
 
 
412
  return $this;
413
  }
414
+
415
+ public function cancel(Varien_Object $payment)
416
+ {
417
  $orderId = $payment->getOrder()->getIncrementId();
418
+ $data = $this->getSagepayModel()->getCollection()->addFieldToFilter('order_id', $orderId)->getFirstItem();
419
+ $params = array();
420
+ $params['VPSProtocol'] = urlencode('2.23');
421
+ $params['TxType'] = self::ACTION_CANCEL;
422
+ $params['Vendor'] = urlencode(Mage::getStoreConfig('payment/sagepay/vendor_name'));
423
+ $params['VendorTxCode'] = urlencode($data->getVendorTxCode());
424
+ $params['VPSTxId'] = $data->getVpsTxId();
425
+ $params['SecurityKey'] = urlencode($data->getSecurityKey());
426
+ $params['TxAuthNo'] = urlencode($data->getTxAuthNo());
427
+
428
+ $this->result = $this->requestPost($this->urls['cancel'], $params);
429
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
430
+ $this->result['Errors'] = array();
431
+ foreach (preg_split("\n", $this->result['StatusDetail']) as $error) {
432
+ $this->result['Errors'] = array_merge($this->result['Errors'], $this->getError($error));
433
+ }
434
+ }
435
+
436
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedSuccess())) {
437
+ $this->getSagepayModel()->saveVoidDetail($this->result, $data->getSagepayId());
438
+ $this->getTransactionModel()->saveTransactionDetail($orderId, $this->result, $params['VendorTxCode'], self::ACTION_CANCEL, $data->getSagepayId());
439
+ $payment->setStatus(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID);
440
+ $payment->setLastTransId((string) $params['VendorTxCode']);
441
+ if (!$payment->getParentTransactionId() || (string) $params['VendorTxCode'] != $payment->getParentTransactionId()) {
442
+ $payment->setTransactionId((string) $params['VendorTxCode']);
443
+ }
444
+ return $this;
445
+ } else {
446
+ if ($result == 'ERROR') {
447
+ $error = $this->result;
448
+ Mage::throwException($error['Errors'][0]);
449
+ } else if (in_array($result, $this->getConfigModel()->getExpectedError())) {
450
+ Mage::throwException("Gateway error : {" . (string) $this->result['Errors'][0] . "}");
451
+ }
452
+ }
 
 
453
  return $this;
454
+ }
455
+
456
+ public function __processPayment(Varien_Object $payment)
457
+ {
458
+
459
+ $this->Currency = Mage::app()->getStore()->getCurrentCurrencyCode();
460
+ $payment->setAmount($amount);
461
+ $this->CardHolder = $payment->getCcOwner();
462
+ $this->CardNumber = $payment->getCcNumber();
463
+ $this->ExpiryDate = date("my", strtotime('01-' . $payment->getCcExpMonth() . '-' . $payment->getCcExpYear()));
464
+ $this->IssueNumber = $payment->getCcSsIssue();
465
+ $this->CV2 = $payment->getCcCid();
466
+ $this->CardType = $this->getConfigModel()->getCcCode($payment->getCcType());
467
+ $order = $this->_getQuote();
468
+ $this->setGatewayOrderData($order);
469
+ return $this->register();
470
+ }
471
+
472
+ public function setGatewayOrderData($order)
473
+ {
474
+
475
+ if (!empty($order)) {
476
+ $BillingAddress = $order->getBillingAddress();
477
+ $this->BillingSurname = $BillingAddress->getLastname();
478
+ $this->BillingFirstnames = $BillingAddress->getFirstname();
479
+ $this->BillingAddress1 = $BillingAddress->getStreet(1);
480
+ $this->BillingAddress2;
481
+ $this->BillingCity = $BillingAddress->getCity();
482
+ $this->BillingPostCode = $BillingAddress->getPostcode();
483
+ $this->BillingCountry = $BillingAddress->getCountry();
484
+ $this->BillingState = Mage::getModel('directory/region')->load($BillingAddress->getRegionId())->getCode();
485
+ $this->BillingPhone = $BillingAddress->getTelephone();
486
+ if (!$order->getIsVirtual())
487
+ $ShippingAddress = $order->getShippingAddress();
488
+ else
489
+ $ShippingAddress = $order->getBillingAddress();
490
+ $this->DeliverySurname = $ShippingAddress->getLastname();
491
+ $this->DeliveryFirstnames = $ShippingAddress->getFirstname();
492
+ $this->DeliveryAddress1 = $ShippingAddress->getStreet(1);
493
+ $this->DeliveryAddress2;
494
+ $this->DeliveryCity = $ShippingAddress->getCity();
495
+ $this->DeliveryPostCode = $ShippingAddress->getPostcode();
496
+ $this->DeliveryCountry = $ShippingAddress->getCountry();
497
+ $this->DeliveryState = Mage::getModel('directory/region')->load($ShippingAddress->getRegionId())->getCode();
498
+ $this->DeliveryPhone = $ShippingAddress->getTelephone();
499
+
500
+ $this->CustomerEmail = $order->getCustomerEmail();
501
+ $this->VendorTxCode = time() . rand(0, 9999) . '-' . $this->_getTrnVendorTxCode(); //$this->_getQuote()->getReservedOrderId();
502
+ $product_array = array();
503
+ foreach ($order->getAllItems() as $item) {
504
+ if (!$item->getParentItemId())
505
+ $this->addLine($item->getName(), $item->getQty(), $item->getPrice(), $item->getTaxAmount());
506
+ }
507
+ foreach ($order->getAllAddresses() as $address) {
508
+ //Add shipping amount
509
+ if ($ship_amount = $address->getData('shipping_amount'))
510
+ $this->addLine($address->getData('shipping_description'), 1, $ship_amount, 0);
511
+
512
+ //Add discount amount
513
+ if ($address->getData('discount_amount') < 0)
514
+ $this->addLine('Discount', 1, $address->getData('discount_amount'), 0);
515
+ }
516
+ }
517
+ }
518
+
519
+ public function register()
520
+ {
521
+
522
+ $errors = array();
523
+ if (!$this->Vendor)
524
+ $errors[] = 'The Vendor must be provided';
525
+ if (!$this->VendorTxCode)
526
+ $errors[] = 'The VendorTxCode must be provided';
527
+ if (!is_numeric($this->Amount))
528
+ $errors[] = 'The Amount field must be specified, and must be numeric.';
529
+ if (!$this->Currency)
530
+ $errors[] = 'Currency must be specified, eg GBP.';
531
+ if (!$this->CardHolder)
532
+ $errors[] = 'CardHolder must be specified.';
533
+ if (!$this->CardNumber)
534
+ $errors[] = 'CardNumber must be specified.';
535
+ if (!$this->ExpiryDate)
536
+ $errors[] = 'ExpiryDate must be specified.';
537
+ if ($this->IssueNumber and ! preg_match("/^\d{1,2}$/", $this->IssueNumber))
538
+ $errors[] = 'IssueNumber is invalid.';
539
+ if ($this->CardType == 'AMEX' and ! preg_match("/^\d{4}$/", $this->CV2))
540
+ $errors[] = 'CV2 must be 4 numbers long.';
541
+ if ($this->CardType != 'AMEX' and ! preg_match("/^\d{3}$/", $this->CV2))
542
+ $errors[] = 'CV2 must be 3 numbers long.';
543
+ if (!in_array($this->CardType, array('VISA', 'MC', 'DELTA', 'SOLO', 'MAESTRO', 'UKE', 'AMEX', 'DC', 'JCB', 'LASER')))
544
+ $errors[] = 'CardType must be one of VISA, MC, DELTA, SOLO, MAESTRO, UKE, AMEX, DC, JCB, LASER';
545
+ if (!$this->BillingSurname)
546
+ $errors[] = 'BillingSurname must be specified.';
547
+ if (!$this->BillingFirstnames)
548
+ $errors[] = 'BillingFirstnames must be specified.';
549
+ if (!$this->BillingAddress1)
550
+ $errors[] = 'BillingAddress1 must be specified.';
551
+ if (!$this->BillingCity)
552
+ $errors[] = 'BillingCity must be specified.';
553
+ if (!$this->BillingPostCode)
554
+ $errors[] = 'BillingPostCode must be specified.';
555
+ if (!$this->BillingCountry)
556
+ $errors[] = 'BillingCountry must be specified.';
557
+ if ($this->BillingCountry == 'US' and ! $this->BillingState)
558
+ $errors['BillingState'] = 'BillingState mut be specified.';
559
+ if (!$this->DeliverySurname)
560
+ $errors[] = 'DeliverySurname must be specified.';
561
+ if (!$this->DeliveryFirstnames)
562
+ $errors[] = 'DeliveryFirstnames must be specified.';
563
+ if (!$this->DeliveryAddress1)
564
+ $errors[] = 'DeliveryAddress1 must be specified.';
565
+ if (!$this->DeliveryCity)
566
+ $errors[] = 'DeliveryCity must be specified.';
567
+ if (!$this->DeliveryPostCode)
568
+ $errors[] = 'DeliveryPostCode must be specified.';
569
+ if (!$this->DeliveryCountry)
570
+ $errors[] = 'DeliveryCountry must be specified.';
571
+ if ($this->DeliveryCountry == 'US' and ! $this->DeliveryState)
572
+ $errors[] = 'DeliveryState mut be specified.';
573
+ if ($this->CustomerEmail and ! preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+\.([a-zA-Z0-9\._-]+)+$/", $this->CustomerEmail))
574
+ $errors[] = 'CustomerEmail is invalid.';
575
+
576
+ if (count($errors)) {
577
+ $this->result = array('Status' => 'ERRORCHECKFAIL', 'Errors' => $errors);
578
+ return 'ERROR';
579
+ }
580
+
581
+ $data = array(
582
+ 'VPSProtocol' => 2.23,
583
+ 'TxType' => $this->TxType,
584
+ 'Vendor' => $this->Vendor,
585
+ 'VendorTxCode' => $this->VendorTxCode,
586
+ 'Amount' => number_format($this->Amount, 2, '.', ''),
587
+ 'Currency' => $this->Currency,
588
+ 'Description' => $this->Description,
589
+ 'CardHolder' => $this->CardHolder,
590
+ 'CardNumber' => $this->CardNumber,
591
+ 'ExpiryDate' => $this->ExpiryDate,
592
+ 'IssueNumber' => $this->IssueNumber,
593
+ 'CV2' => $this->CV2,
594
+ 'CardType' => $this->CardType,
595
+ 'BillingSurname' => $this->BillingSurname,
596
+ 'BillingFirstnames' => $this->BillingFirstnames,
597
+ 'BillingAddress1' => $this->BillingAddress1,
598
+ 'BillingAddress2' => $this->BillingAddress2,
599
+ 'BillingCity' => $this->BillingCity,
600
+ 'BillingPostCode' => $this->BillingPostCode,
601
+ 'BillingCountry' => $this->BillingCountry,
602
+ 'BillingState' => $this->BillingCountry == 'US' ? $this->BillingState : '',
603
+ 'BillingPhone' => $this->BillingPhone,
604
+ 'DeliverySurname' => $this->DeliverySurname,
605
+ 'DeliveryFirstnames' => $this->DeliveryFirstnames,
606
+ 'DeliveryAddress1' => $this->DeliveryAddress1,
607
+ 'DeliveryAddress2' => $this->DeliveryAddress2,
608
+ 'DeliveryCity' => $this->DeliveryCity,
609
+ 'DeliveryPostCode' => $this->DeliveryPostCode,
610
+ 'DeliveryCountry' => $this->DeliveryCountry,
611
+ 'DeliveryState' => $this->DeliveryCountry == 'US' ? $this->DeliveryState : '',
612
+ 'DeliveryPhone' => $this->DeliveryPhone,
613
+ 'CustomerEmail' => $this->CustomerEmail,
614
+ 'GiftAidPayment' => $this->GiftAidPayment,
615
+ 'AccountType' => $this->AccountType,
616
+ 'ClientIPAddress' => $_SERVER['REMOTE_ADDR'],
617
+ 'ApplyAVSCV2' => $this->ApplyAVSCV2,
618
+ 'Apply3DSecure' => $this->Apply3DSecure
619
+ );
620
+
621
+ if (sizeof($this->Basket)) {
622
+ $data['Basket'] = count($this->Basket);
623
+ foreach ($this->Basket as $line) {
624
+ $data['Basket'] .= ':' . $line['description'];
625
+ $data['Basket'] .= ':' . $line['quantity'];
626
+ $data['Basket'] .= ':' . number_format($line['value'], 2, '.', '');
627
+ $data['Basket'] .= ':' . number_format($line['tax'], 2, '.', '');
628
+ $data['Basket'] .= ':' . number_format(($line['value'] + $line['tax']), 2, '.', '');
629
+ $data['Basket'] .= ':' . number_format(($line['quantity'] * ($line['value'] + $line['tax'])), 2, '.', '');
630
+ }
631
+ }
632
+
633
+ $this->result = $this->requestPost($this->urls['register'], $data);
634
+
635
+ if (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
636
+ $this->result['Errors'] = array();
637
+ foreach (preg_split("\n", $this->result['StatusDetail']) as $error) {
638
+ $this->result['Errors'] = array_merge($this->result['Errors'], $this->getError($error));
639
+ }
640
+ }
641
+ if ($this->result['Status'] == '3DAUTH') {
642
+
643
+ $this->result['VendorTxCode'] = $this->VendorTxCode;
644
+ return $this->result;
645
+ }
646
+ return $this->result;
647
+ }
648
+
649
+ public function addLine($description, $quantity, $value, $tax = 0)
650
+ {
651
+ $this->Basket[] = array(
652
+ 'description' => $description,
653
+ 'quantity' => $quantity,
654
+ 'value' => $value,
655
+ 'tax' => $tax
656
+ );
657
+ }
658
+
659
+ public static function recover3d()
660
+ {
661
+ $sagepay = unserialize($_SESSION['sagepay_obj']);
662
+ unset($_SESSION['sagepay_obj']);
663
+ return $sagepay;
664
+ }
665
+
666
+ public static function is3dResponse()
667
+ {
668
+ if (isset($_REQUEST['PaRes']) and isset($_REQUEST['MD']) and isset($_SESSION['sagepay_obj'])) {
669
+ return true;
670
+ } else {
671
+ return false;
672
+ }
673
+ }
674
+
675
+ public function complete3d($post_data)
676
+ {
677
+ $session = Mage::getSingleton('core/session');
678
+ $data = array(
679
+ 'PARes' => $post_data['PaRes'],
680
+ 'MD' => $post_data['MD']
681
+ );
682
+
683
+ $result = $this->requestPost($this->urls['3dsecure'], $data);
684
+ $vendor = $session->getGatewayResult();
685
+ $result['VendorTxCode'] = $vendor['VendorTxCode'];
686
+ $result['CustomerEmail'] = $vendor['CustomerEmail'];
687
+ $result['CustomerName'] = $vendor['CustomerName'];
688
+ $result['CardType'] = $vendor['CardType'];
689
+ $result['CardHolderName'] = $vendor['CardHolderName'];
690
+ $result['CustomerContact'] = $vendor['CustomerContact'];
691
+ $result['TxType'] = $vendor['TxType'];
692
+ return $result;
693
+ }
694
+
695
+ public function status()
696
+ {
697
+ return $this->result['Status'];
698
+ }
699
+
700
+ private function getError($message)
701
+ {
702
+ $chunks = preg_split(' : ', $message, 2);
703
+ if ($chunks[0] == '3048') {
704
+ return array('CardNumber' => 'The card number is invalid.');
705
+ }
706
+ if ($chunks[0] == '4022') {
707
+ return array('CardNumber' => 'The card number is not valid for the card type selected.');
708
+ }
709
+ if ($chunks[0] == '4023') {
710
+ return array('CardNumber' => 'The issue number must be provided.');
711
+ }
712
+ return array($message);
713
+ }
714
+
715
+ private function requestPost($url, $data)
716
+ {
717
+ $fields_string = http_build_query($data);
718
+ $log['request'] = $data;
719
+ set_time_limit(60);
720
+ $output = array();
721
+ $curlSession = curl_init();
722
+ curl_setopt($curlSession, CURLOPT_URL, $url);
723
+ curl_setopt($curlSession, CURLOPT_HEADER, 0);
724
+ curl_setopt($curlSession, CURLOPT_POST, 1);
725
+ curl_setopt($curlSession, CURLOPT_POSTFIELDS, $fields_string);
726
+ curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
727
+ curl_setopt($curlSession, CURLOPT_TIMEOUT, 30);
728
+ curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, FALSE);
729
+ curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 2);
730
+ $response = explode(chr(10), curl_exec($curlSession));
731
+ $log['response'] = $response;
732
+ $this->getSagepayModel()->logTransaction($log);
733
+ unset($this->CardNumber);
734
+ unset($this->ExpiryDate);
735
+ unset($this->CV2);
736
+
737
+ if (curl_error($curlSession)) {
738
+ $output['Status'] = "FAIL";
739
+ $output['StatusDetail'] = curl_error($curlSession);
740
+ }
741
+ curl_close($curlSession);
742
+ for ($i = 0; $i < count($response); $i++) {
743
+ $splitAt = strpos($response[$i], "=");
744
+ $output[trim(substr($response[$i], 0, $splitAt))] = trim(substr($response[$i], ($splitAt + 1)));
745
+ }
746
+ return $output;
747
+ }
748
+
749
+ public static function country($code)
750
+ {
751
+ $countries = $this->getSagepayModel()->countries();
752
+ return $countries[$code];
753
+ }
754
+
755
+ public function registerTransaction($data)
756
+ {
757
+ if (Mage::getStoreConfig('payment/sagepay/payment_action') == 'authorize') {
758
+ $this->TxType = self::ACTION_AUTHENTICATE;
759
+ } elseif (Mage::getStoreConfig('payment/sagepay/payment_action') == 'authorize_capture') {
760
+ $this->TxType = self::ACTION_PAYMENT;
761
+ }
762
+ return $this->sagePayRegisterPayment($data);
763
+ }
764
+
765
+ public function sagePayRegisterPayment($data)
766
+ {
767
+
768
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
769
+ $amount = $quote->getData('grand_total');
770
+
771
+ if ($amount <= 0) {
772
  Mage::throwException(Mage::helper('paygate')->__('Invalid amount for transaction.'));
773
  }
774
+
775
+ $this->Currency = Mage::app()->getStore()->getCurrentCurrencyCode();
776
+ $this->Amount = $amount;
777
+ $this->CardHolder = $data['cc_owner'];
778
+ $this->CardNumber = $data['cc_number'];
779
+ $this->ExpiryDate = date("my", strtotime('01-' . $data['cc_exp_month'] . '-' . $data['cc_exp_year']));
780
+ $this->CV2 = $data['cc_cid'];
781
+ $this->CardType = $this->getConfigModel()->getCcCode($data['cc_type']);
782
+
783
+ $this->setGatewayOrderData($quote);
784
+ $result = $this->register();
785
+ if ($result == 'ERROR') {
786
+ $error = $this->result;
787
+ Mage::throwException($error['Errors'][0]);
788
+ } elseif (in_array($this->result['Status'], $this->getConfigModel()->getExpectedError())) {
789
+ if (!$this->result['Errors'][0])
790
+ Mage::throwException("Gateway error : {" . (string) $this->result['StatusDetail'] . "}");
791
+ else
792
+ Mage::throwException("Gateway error : {" . (string) $this->result['Errors'][0] . "}");
793
+ }
794
+ else {
795
+ $result['CustomerEmail'] = $this->CustomerEmail;
796
+ $result['CustomerName'] = $this->BillingFirstnames . ' ' . $this->BillingSurname;
797
+ $result['CardType'] = $this->CardType;
798
+ $result['CardHolderName'] = $this->CardHolder;
799
+ $result['CustomerContact'] = $this->BillingPhone;
800
+ $result['TxType'] = $this->TxType;
801
+ $result['VendorTxCode'] = $this->VendorTxCode;
802
+ }
803
+ return $result;
804
+ }
805
+
806
+ protected function _addTransaction(Mage_Sales_Model_Order_Payment $payment, $transactionId, $transactionType, array $transactionDetails = array(), $message = false)
807
+ {
808
+
 
809
  $payment->setTransactionId($transactionId);
810
  $payment->resetTransactionAdditionalInfo();
811
  foreach ($transactionDetails as $key => $value) {
812
  $payment->setData($key, $value);
813
  }
814
+
815
+ $transaction = $payment->addTransaction($transactionType, null, false, $message);
816
  foreach ($transactionDetails as $key => $value) {
817
  $payment->unsetData($key);
818
  }
822
 
823
  return $transaction;
824
  }
825
+
826
+ public function getConfigModel()
827
+ {
828
+ return Mage::getSingleton('sagepay/config');
829
+ }
830
+
831
+ public function getSagepayModel()
832
+ {
833
+ return Mage::getSingleton('sagepay/sagepay');
834
+ }
835
+
836
+ public function getTransactionModel()
837
+ {
838
+ return Mage::getSingleton('sagepay/transaction');
839
+ }
840
 
841
  }
842
+
843
  ?>
app/code/community/Raveinfosys/Sagepay/Model/Sagepay.php CHANGED
@@ -1,126 +1,132 @@
1
  <?php
2
 
3
- class Raveinfosys_Sagepay_Model_Sagepay extends Mage_Core_Model_Abstract {
 
 
 
 
4
 
5
- public function _construct(){
6
-
7
  parent::_construct();
8
  $this->_init('sagepay/sagepay');
9
  }
10
 
11
- public function saveOrderDetail($result,$order_id){
12
- $data['order_id'] = $order_id;
13
- $data['vps_tx_id'] = $result['VPSTxId'];
14
- $data['vendor_tx_code'] = $result['VendorTxCode'];
15
- $data['security_key'] = $result['SecurityKey'];
16
- $data['tx_auth_no'] = $result['TxAuthNo'];
17
- $data['order_status'] = $result['StatusDetail'];
18
- $data['threed_auth'] = $result['3DSecureStatus'];
19
- $data['payment_type'] = 1;
20
- $data['authorised'] = 1;
21
- $data['customer_email'] = $result['CustomerEmail'];
22
- $model = Mage::getModel('sagepay/sagepay');
23
- $model->setData($data)
24
- ->save();
25
- return $model->getId();
26
-
27
- }
28
-
29
- public function saveCardDetail($id,$data){
30
- $model = Mage::getModel('sagepay/sagepay')->load($id);
31
- $model->setCustomerName($data['CustomerName'])
32
- ->setCardType($data['CardType'])
33
- ->setCardHolderName($data['CardHolderName'])
34
- ->setCustomerContact($data['CustomerContact'])
35
- ->save();
36
-
37
- }
38
-
39
- public function saveAuthDetail($result,$order_id){
40
- $data['order_id'] = $order_id;
41
- $data['vps_tx_id'] = $result['VPSTxId'];
42
- $data['vendor_tx_code'] = $result['VendorTxCode'];
43
- $data['security_key'] = $result['SecurityKey'];
44
- if($result['TxAuthNo'])
45
- $data['tx_auth_no'] = $result['TxAuthNo'];
46
- else
47
- $data['tx_auth_no'] = '0';
48
- $data['order_status'] = $result['StatusDetail'];
49
- $data['threed_auth'] = $result['3DSecureStatus'];
50
- $data['payment_type'] = 2;
51
- $data['customer_email'] = $result['CustomerEmail'];
52
- $model = Mage::getModel('sagepay/sagepay');
53
- $model->setData($data)
54
- ->save();
55
- return $model->getId();
56
-
57
- }
58
-
59
- public function saveAuthorisedDetail($result,$vendor_tx_code,$parent_data,$order_id){
60
-
61
- $parent_model = Mage::getModel('sagepay/sagepay')->load($parent_data->getSagepayId());
62
- $parent_model->setAuthorised(1)
63
- ->save()->unsetData();
64
-
65
- $data['order_id'] = $order_id;
66
- $data['parent_id'] = $parent_data->getSagepayId();
67
- $data['vps_tx_id'] = $result['VPSTxId'];
68
- $data['vendor_tx_code'] = $vendor_tx_code;
69
- $data['security_key'] = $result['SecurityKey'];
70
- $data['tx_auth_no'] = $result['TxAuthNo'];
71
- $data['order_status'] = $result['StatusDetail'];
72
- $data['threed_auth'] = $result['3DSecureStatus'];
73
- $data['authorised'] = 1;
74
- $data['customer_email'] = $parent_data->getCustomerEmail();
75
- $data['customer_name'] = $parent_data->getCustomerName();
76
- $data['card_type'] = $parent_data->getCardType();
77
- $data['card_holder_name'] = $parent_data->getCardHolderName();
78
- $data['customer_contact'] = $parent_data->getCustomerContact();
79
-
80
- $model = Mage::getModel('sagepay/sagepay');
81
- $model->setData($data)
82
- ->save();
83
-
84
- return $model->getId();
85
-
86
- }
87
-
88
- public function saveRefundDetail($result,$id){
89
- $model = Mage::getModel('sagepay/sagepay')->load($id);
90
- $model->setIsRefund(1)
91
- ->setRefundStatus($result['StatusDetail'])
92
- ->save();
93
- }
94
-
95
- public function saveVoidDetail($result,$id){
96
- $model = Mage::getModel('sagepay/sagepay')->load($id);
97
- $model->setIsVoid(1)
98
- ->setVoidStatus($result['StatusDetail'])
99
- ->save();
100
- }
101
-
102
- public function canVoid($order){
103
- $data = $this->getCollection()->addFieldToFilter('order_id',$order->getIncrementId())->getFirstItem();
104
- if($data->getPaymentType()==2 && $data->getIsVoid()!=1 && $data->getAuthorised() !=1)
105
- return true;
106
- else
107
- return false;
108
- }
109
-
110
- public function logTransaction($data){
111
- if(Mage::getStoreConfig('payment/sagepay/debug')){
112
- if($data["request"]["CardNumber"]!=''){
113
- $data["request"]["CardNumber"] = '****';
114
- $data["request"]["IssueNumber"] = '****';
115
- $data["request"]["CV2"] = '****';
116
- $data["request"]["CardType"] = '****';
117
- $data["request"]["CardHolder"] = '****';
118
- }
119
- $data["request"]["Vendor"] = '****';
120
- Mage::log($data, null, 'raveinfosys_sagepay.log',1);
121
- }
122
- }
123
-
124
-
125
- }
126
- ?>
 
 
 
 
1
  <?php
2
 
3
+ class Raveinfosys_Sagepay_Model_Sagepay extends Mage_Core_Model_Abstract
4
+ {
5
+
6
+ public function _construct()
7
+ {
8
 
 
 
9
  parent::_construct();
10
  $this->_init('sagepay/sagepay');
11
  }
12
 
13
+ public function saveOrderDetail($result, $order_id)
14
+ {
15
+ $data['order_id'] = $order_id;
16
+ $data['vps_tx_id'] = $result['VPSTxId'];
17
+ $data['vendor_tx_code'] = $result['VendorTxCode'];
18
+ $data['security_key'] = $result['SecurityKey'];
19
+ $data['tx_auth_no'] = $result['TxAuthNo'];
20
+ $data['order_status'] = $result['StatusDetail'];
21
+ $data['threed_auth'] = $result['3DSecureStatus'];
22
+ $data['payment_type'] = 1;
23
+ $data['authorised'] = 1;
24
+ $data['customer_email'] = $result['CustomerEmail'];
25
+ $model = Mage::getModel('sagepay/sagepay');
26
+ $model->setData($data)
27
+ ->save();
28
+ return $model->getId();
29
+ }
30
+
31
+ public function saveCardDetail($id, $data)
32
+ {
33
+ $model = Mage::getModel('sagepay/sagepay')->load($id);
34
+ $model->setCustomerName($data['CustomerName'])
35
+ ->setCardType($data['CardType'])
36
+ ->setCardHolderName($data['CardHolderName'])
37
+ ->setCustomerContact($data['CustomerContact'])
38
+ ->save();
39
+ }
40
+
41
+ public function saveAuthDetail($result, $order_id)
42
+ {
43
+ $data['order_id'] = $order_id;
44
+ $data['vps_tx_id'] = $result['VPSTxId'];
45
+ $data['vendor_tx_code'] = $result['VendorTxCode'];
46
+ $data['security_key'] = $result['SecurityKey'];
47
+ if ($result['TxAuthNo'])
48
+ $data['tx_auth_no'] = $result['TxAuthNo'];
49
+ else
50
+ $data['tx_auth_no'] = '0';
51
+ $data['order_status'] = $result['StatusDetail'];
52
+ $data['threed_auth'] = $result['3DSecureStatus'];
53
+ $data['payment_type'] = 2;
54
+ $data['customer_email'] = $result['CustomerEmail'];
55
+ $model = Mage::getModel('sagepay/sagepay');
56
+ $model->setData($data)
57
+ ->save();
58
+ return $model->getId();
59
+ }
60
+
61
+ public function saveAuthorisedDetail($result, $vendor_tx_code, $parent_data, $order_id)
62
+ {
63
+
64
+ $parent_model = Mage::getModel('sagepay/sagepay')->load($parent_data->getSagepayId());
65
+ $parent_model->setAuthorised(1)
66
+ ->save()->unsetData();
67
+
68
+ $data['order_id'] = $order_id;
69
+ $data['parent_id'] = $parent_data->getSagepayId();
70
+ $data['vps_tx_id'] = $result['VPSTxId'];
71
+ $data['vendor_tx_code'] = $vendor_tx_code;
72
+ $data['security_key'] = $result['SecurityKey'];
73
+ $data['tx_auth_no'] = $result['TxAuthNo'];
74
+ $data['order_status'] = $result['StatusDetail'];
75
+ $data['threed_auth'] = $result['3DSecureStatus'];
76
+ $data['authorised'] = 1;
77
+ $data['customer_email'] = $parent_data->getCustomerEmail();
78
+ $data['customer_name'] = $parent_data->getCustomerName();
79
+ $data['card_type'] = $parent_data->getCardType();
80
+ $data['card_holder_name'] = $parent_data->getCardHolderName();
81
+ $data['customer_contact'] = $parent_data->getCustomerContact();
82
+
83
+ $model = Mage::getModel('sagepay/sagepay');
84
+ $model->setData($data)
85
+ ->save();
86
+
87
+ return $model->getId();
88
+ }
89
+
90
+ public function saveRefundDetail($result, $id)
91
+ {
92
+ $model = Mage::getModel('sagepay/sagepay')->load($id);
93
+ $model->setIsRefund(1)
94
+ ->setRefundStatus($result['StatusDetail'])
95
+ ->save();
96
+ }
97
+
98
+ public function saveVoidDetail($result, $id)
99
+ {
100
+ $model = Mage::getModel('sagepay/sagepay')->load($id);
101
+ $model->setIsVoid(1)
102
+ ->setVoidStatus($result['StatusDetail'])
103
+ ->save();
104
+ }
105
+
106
+ public function canVoid($order)
107
+ {
108
+ $data = $this->getCollection()->addFieldToFilter('order_id', $order->getIncrementId())->getFirstItem();
109
+ if ($data->getPaymentType() == 2 && $data->getIsVoid() != 1 && $data->getAuthorised() != 1)
110
+ return true;
111
+ else
112
+ return false;
113
+ }
114
+
115
+ public function logTransaction($data)
116
+ {
117
+ if (Mage::getStoreConfig('payment/sagepay/debug')) {
118
+ if ($data["request"]["CardNumber"] != '') {
119
+ $data["request"]["CardNumber"] = '****';
120
+ $data["request"]["IssueNumber"] = '****';
121
+ $data["request"]["CV2"] = '****';
122
+ $data["request"]["CardType"] = '****';
123
+ $data["request"]["CardHolder"] = '****';
124
+ }
125
+ $data["request"]["Vendor"] = '****';
126
+ Mage::log($data, null, 'raveinfosys_sagepay.log', 1);
127
+ }
128
+ }
129
+
130
+ }
131
+
132
+ ?>
app/code/community/Raveinfosys/Sagepay/Model/Status.php CHANGED
@@ -2,14 +2,16 @@
2
 
3
  class Raveinfosys_Sagepay_Model_Status extends Varien_Object
4
  {
5
- const STATUS_ENABLED = 1;
6
- const STATUS_DISABLED = 2;
 
7
 
8
  static public function getOptionArray()
9
  {
10
  return array(
11
- self::STATUS_ENABLED => Mage::helper('sagepay')->__('Enabled'),
12
- self::STATUS_DISABLED => Mage::helper('sagepay')->__('Disabled')
13
  );
14
  }
15
- }
 
2
 
3
  class Raveinfosys_Sagepay_Model_Status extends Varien_Object
4
  {
5
+
6
+ const STATUS_ENABLED = 1;
7
+ const STATUS_DISABLED = 2;
8
 
9
  static public function getOptionArray()
10
  {
11
  return array(
12
+ self::STATUS_ENABLED => Mage::helper('sagepay')->__('Enabled'),
13
+ self::STATUS_DISABLED => Mage::helper('sagepay')->__('Disabled')
14
  );
15
  }
16
+
17
+ }
app/code/community/Raveinfosys/Sagepay/Model/System/Config/Source/Dropdown/Values.php CHANGED
@@ -2,7 +2,8 @@
2
 
3
  class Raveinfosys_Sagepay_Model_System_Config_Source_Dropdown_Values
4
  {
5
- public function toOptionArray()
 
6
  {
7
  return array(
8
  array(
@@ -13,10 +14,11 @@ class Raveinfosys_Sagepay_Model_System_Config_Source_Dropdown_Values
13
  'value' => 'test',
14
  'label' => 'Test',
15
  ),
16
- array(
17
  'value' => 'live',
18
  'label' => 'Live',
19
  ),
20
  );
21
  }
 
22
  }
2
 
3
  class Raveinfosys_Sagepay_Model_System_Config_Source_Dropdown_Values
4
  {
5
+
6
+ public function toOptionArray()
7
  {
8
  return array(
9
  array(
14
  'value' => 'test',
15
  'label' => 'Test',
16
  ),
17
+ array(
18
  'value' => 'live',
19
  'label' => 'Live',
20
  ),
21
  );
22
  }
23
+
24
  }
app/code/community/Raveinfosys/Sagepay/Model/Transaction.php CHANGED
@@ -1,34 +1,35 @@
1
  <?php
2
 
3
- class Raveinfosys_Sagepay_Model_Transaction extends Mage_Core_Model_Abstract {
 
 
 
 
4
 
5
- public function _construct(){
6
-
7
  parent::_construct();
8
  $this->_init('sagepay/transaction');
9
  }
10
 
11
- public function saveTransactionDetail($order_id ,$result, $vendor_tx_code, $mode, $sagepay_id)
12
- {
13
- $transaction_detail = array();
14
- $card_detail = Mage::getModel('sagepay/sagepay')->load($sagepay_id);
15
- $transaction_detail['order_id'] = $order_id;
16
- $transaction_detail['vendor_tx_code'] = $vendor_tx_code;
17
- $transaction_detail['vps_tx_id'] = $result['VPSTxId'];
18
- $transaction_detail['security_key'] = $result['SecurityKey'];
19
- $transaction_detail['tx_auth_no'] = $result['TxAuthNo'];
20
- $transaction_detail['order_status'] = $result['Status'];
21
- $transaction_detail['customer_name'] = $card_detail['customer_name'];
22
- $transaction_detail['customer_email'] = $card_detail['customer_email'];
23
- $transaction_detail['customer_contact'] = $card_detail['customer_contact'];
24
- $transaction_detail['card_holder_name'] = $card_detail['card_holder_name'];
25
- $transaction_detail['card_type'] = $card_detail['card_type'];
26
- $transaction_detail['mode'] = $mode;
27
- $transaction_detail['threed_secure'] = $result['3DSecureStatus'];
28
- $this->setData($transaction_detail)->save();
29
- }
30
-
31
-
32
-
33
- }
34
- ?>
1
  <?php
2
 
3
+ class Raveinfosys_Sagepay_Model_Transaction extends Mage_Core_Model_Abstract
4
+ {
5
+
6
+ public function _construct()
7
+ {
8
 
 
 
9
  parent::_construct();
10
  $this->_init('sagepay/transaction');
11
  }
12
 
13
+ public function saveTransactionDetail($order_id, $result, $vendor_tx_code, $mode, $sagepay_id)
14
+ {
15
+ $transaction_detail = array();
16
+ $card_detail = Mage::getModel('sagepay/sagepay')->load($sagepay_id);
17
+ $transaction_detail['order_id'] = $order_id;
18
+ $transaction_detail['vendor_tx_code'] = $vendor_tx_code;
19
+ $transaction_detail['vps_tx_id'] = $result['VPSTxId'];
20
+ $transaction_detail['security_key'] = $result['SecurityKey'];
21
+ $transaction_detail['tx_auth_no'] = $result['TxAuthNo'];
22
+ $transaction_detail['order_status'] = $result['Status'];
23
+ $transaction_detail['customer_name'] = $card_detail['customer_name'];
24
+ $transaction_detail['customer_email'] = $card_detail['customer_email'];
25
+ $transaction_detail['customer_contact'] = $card_detail['customer_contact'];
26
+ $transaction_detail['card_holder_name'] = $card_detail['card_holder_name'];
27
+ $transaction_detail['card_type'] = $card_detail['card_type'];
28
+ $transaction_detail['mode'] = $mode;
29
+ $transaction_detail['threed_secure'] = $result['3DSecureStatus'];
30
+ $this->setData($transaction_detail)->save();
31
+ }
32
+
33
+ }
34
+
35
+ ?>
 
app/code/community/Raveinfosys/Sagepay/controllers/Adminhtml/SagepayController.php CHANGED
@@ -3,42 +3,45 @@
3
  class Raveinfosys_Sagepay_Adminhtml_SagepayController extends Mage_Adminhtml_Controller_Action
4
  {
5
 
6
- protected function _initAction() {
7
- $this->loadLayout()
8
- ->_setActiveMenu('sagepay/items')
9
- ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
10
-
11
- return $this;
12
- }
13
-
14
- public function indexAction() {
15
- $this->_initAction()
16
- ->renderLayout();
17
- }
 
 
 
 
 
 
 
 
18
 
 
 
19
 
20
- public function deleteAction() {
21
- if( $this->getRequest()->getParam('id') > 0 ) {
22
- try {
23
- $model = Mage::getModel('sagepay/sagepay');
24
-
25
- $model->setId($this->getRequest()->getParam('id'))
26
- ->delete();
27
-
28
- Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
29
- $this->_redirect('*/*/');
30
- } catch (Exception $e) {
31
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
32
- $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
33
- }
34
- }
35
- $this->_redirect('*/*/');
36
- }
37
-
38
- public function massDeleteAction() {
39
  $sagepayIds = $this->getRequest()->getParam('sagepay');
40
- if(!is_array($sagepayIds)) {
41
- Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
42
  } else {
43
  try {
44
  foreach ($sagepayIds as $sagepayId) {
@@ -46,9 +49,9 @@ class Raveinfosys_Sagepay_Adminhtml_SagepayController extends Mage_Adminhtml_Con
46
  $sagepay->delete();
47
  }
48
  Mage::getSingleton('adminhtml/session')->addSuccess(
49
- Mage::helper('adminhtml')->__(
50
- 'Total of %d record(s) were successfully deleted', count($sagepayIds)
51
- )
52
  );
53
  } catch (Exception $e) {
54
  Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
@@ -57,32 +60,31 @@ class Raveinfosys_Sagepay_Adminhtml_SagepayController extends Mage_Adminhtml_Con
57
  $this->_redirect('*/*/index');
58
  }
59
 
60
-
61
  public function exportCsvAction()
62
  {
63
- $fileName = 'sagepay.csv';
64
- $content = $this->getLayout()->createBlock('sagepay/adminhtml_sagepay_grid')
65
- ->getCsv();
66
 
67
  $this->_sendUploadResponse($fileName, $content);
68
  }
69
 
70
  public function exportXmlAction()
71
  {
72
- $fileName = 'sagepay.xml';
73
- $content = $this->getLayout()->createBlock('sagepay/adminhtml_sagepay_grid')
74
- ->getXml();
75
 
76
  $this->_sendUploadResponse($fileName, $content);
77
  }
78
 
79
- protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
80
  {
81
  $response = $this->getResponse();
82
- $response->setHeader('HTTP/1.1 200 OK','');
83
  $response->setHeader('Pragma', 'public', true);
84
  $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
85
- $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
86
  $response->setHeader('Last-Modified', date('r'));
87
  $response->setHeader('Accept-Ranges', 'bytes');
88
  $response->setHeader('Content-Length', strlen($content));
@@ -91,4 +93,5 @@ class Raveinfosys_Sagepay_Adminhtml_SagepayController extends Mage_Adminhtml_Con
91
  $response->sendResponse();
92
  die;
93
  }
94
- }
 
3
  class Raveinfosys_Sagepay_Adminhtml_SagepayController extends Mage_Adminhtml_Controller_Action
4
  {
5
 
6
+ protected function _initAction()
7
+ {
8
+ $this->loadLayout()
9
+ ->_setActiveMenu('sagepay/items')
10
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
11
+
12
+ return $this;
13
+ }
14
+
15
+ public function indexAction()
16
+ {
17
+ $this->_initAction()
18
+ ->renderLayout();
19
+ }
20
+
21
+ public function deleteAction()
22
+ {
23
+ if ($this->getRequest()->getParam('id') > 0) {
24
+ try {
25
+ $model = Mage::getModel('sagepay/sagepay');
26
 
27
+ $model->setId($this->getRequest()->getParam('id'))
28
+ ->delete();
29
 
30
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
31
+ $this->_redirect('*/*/');
32
+ } catch (Exception $e) {
33
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
34
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
35
+ }
36
+ }
37
+ $this->_redirect('*/*/');
38
+ }
39
+
40
+ public function massDeleteAction()
41
+ {
 
 
 
 
 
 
 
42
  $sagepayIds = $this->getRequest()->getParam('sagepay');
43
+ if (!is_array($sagepayIds)) {
44
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
45
  } else {
46
  try {
47
  foreach ($sagepayIds as $sagepayId) {
49
  $sagepay->delete();
50
  }
51
  Mage::getSingleton('adminhtml/session')->addSuccess(
52
+ Mage::helper('adminhtml')->__(
53
+ 'Total of %d record(s) were successfully deleted', count($sagepayIds)
54
+ )
55
  );
56
  } catch (Exception $e) {
57
  Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
60
  $this->_redirect('*/*/index');
61
  }
62
 
 
63
  public function exportCsvAction()
64
  {
65
+ $fileName = 'sagepay.csv';
66
+ $content = $this->getLayout()->createBlock('sagepay/adminhtml_sagepay_grid')
67
+ ->getCsv();
68
 
69
  $this->_sendUploadResponse($fileName, $content);
70
  }
71
 
72
  public function exportXmlAction()
73
  {
74
+ $fileName = 'sagepay.xml';
75
+ $content = $this->getLayout()->createBlock('sagepay/adminhtml_sagepay_grid')
76
+ ->getXml();
77
 
78
  $this->_sendUploadResponse($fileName, $content);
79
  }
80
 
81
+ protected function _sendUploadResponse($fileName, $content, $contentType = 'application/octet-stream')
82
  {
83
  $response = $this->getResponse();
84
+ $response->setHeader('HTTP/1.1 200 OK', '');
85
  $response->setHeader('Pragma', 'public', true);
86
  $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
87
+ $response->setHeader('Content-Disposition', 'attachment; filename=' . $fileName);
88
  $response->setHeader('Last-Modified', date('r'));
89
  $response->setHeader('Accept-Ranges', 'bytes');
90
  $response->setHeader('Content-Length', strlen($content));
93
  $response->sendResponse();
94
  die;
95
  }
96
+
97
+ }
app/code/community/Raveinfosys/Sagepay/controllers/Checkout/OnepageController.php CHANGED
@@ -1,10 +1,13 @@
1
  <?php
 
2
  require_once 'Mage/Checkout/controllers/OnepageController.php';
 
3
  class Raveinfosys_Sagepay_Checkout_OnepageController extends Mage_Checkout_OnepageController
4
  {
5
-
6
- public function threedsecureAction(){
7
- if ($this->_expireAjax()) {
 
8
  return;
9
  }
10
 
@@ -20,88 +23,83 @@ class Raveinfosys_Sagepay_Checkout_OnepageController extends Mage_Checkout_Onepa
20
  return;
21
  }
22
  }
23
- if ($data = $this->getRequest()->getPost('payment', false)) {
24
  $this->getOnepage()->getQuote()->getPayment()->importData($data);
25
  }
26
- $gateway_result = Mage::getModel('sagepay/payment')->registerTransaction($data);
27
- $session = Mage::getSingleton('core/session');
28
- $session->setGatewayResult($gateway_result)->setPaymentdata($data);
29
- if($gateway_result['Status'] == '3DAUTH' && $gateway_result["PAReq"]!='' && $gateway_result["MD"]!=''){
30
- $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();
31
- $url = Mage::getUrl('checkout/onepage/sagepay3dCheck');
32
- Mage::register('url',$url);
33
-
34
- if (!isset($result['error'])) {
35
- $result['goto_section'] = 'threedsecure';
36
- $html = Mage::app()->getLayout()->createBlock('checkout/onepage')->setTemplate('sagepay/checkout/3dredirect.phtml')->toHtml();
37
- $result['update_section'] = array(
38
- 'name' => 'threedsecure',
39
- 'html' => $html
40
- #'html' => "<script>alert('hello');window.open('".$url."','mypopup','status=1,width=500,height=500,scrollbars=1');</script>"
41
- );
42
-
43
- }
44
- }
45
- elseif(in_array($gateway_result['Status'],Mage::getSingleton('sagepay/config')->getExpectedSuccess())) {
46
- $this->_forward('saveOrder');
47
- }
48
-
49
  } catch (Exception $e) {
50
  Mage::logException($e);
51
- $result['success'] = false;
52
  $result['error'] = true;
53
  $result['error_messages'] = $e->getMessage();
54
  }
55
  $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
56
  }
57
-
58
- public function sagepay3dcheckAction(){
59
-
60
- $this->loadLayout();
61
- $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','sagepay_3d_form',array('template' => 'sagepay/sagepay.phtml'));
62
- $this->getLayout()->getBlock('content')->append($block);
63
- $this->renderLayout();
64
-
65
- }
66
-
67
- public function threedsuccessAction(){
68
- $this->loadLayout();
69
- try {
70
- $result = Mage::getModel('sagepay/payment')->complete3d($_POST);
71
- if (in_array($result['Status'],Mage::getSingleton('sagepay/config')->getExpectedSuccess())) {
72
- $session = Mage::getSingleton('core/session');
73
- $session->setGatewayResult($result);
74
- Mage::register('status',1);
75
- Mage::register('url',Mage::getUrl('checkout/onepage/savesagepayorder'));
76
- }
77
- } catch (Exception $e) {
 
78
  Mage::logException($e);
79
  Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
80
- $result['success'] = false;
81
- $result['error'] = true;
82
  $result['error_messages'] = $this->__('There was an error processing your order. Please contact us or try again later.');
83
  }
84
-
85
- $this->renderLayout();
86
-
87
- }
88
-
89
- public function saveSagePayOrderAction(){
90
- try {
91
- $session = Mage::getSingleton('core/session');
92
- if ($data = $session->getPaymentdata()) {
93
  $this->getOnepage()->getQuote()->getPayment()->importData($data);
94
  }
95
- $this->getOnepage()->saveOrder();
96
- $this->getOnepage()->getQuote()->save();
97
- } catch (Exception $e) {
98
  Mage::logException($e);
99
  Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
100
-
101
  }
102
- $this->_redirect('checkout/onepage/success');
103
-
104
- }
105
-
106
-
107
  }
1
  <?php
2
+
3
  require_once 'Mage/Checkout/controllers/OnepageController.php';
4
+
5
  class Raveinfosys_Sagepay_Checkout_OnepageController extends Mage_Checkout_OnepageController
6
  {
7
+
8
+ public function threedsecureAction()
9
+ {
10
+ if ($this->_expireAjax()) {
11
  return;
12
  }
13
 
23
  return;
24
  }
25
  }
26
+ if ($data = $this->getRequest()->getPost('payment', false)) {
27
  $this->getOnepage()->getQuote()->getPayment()->importData($data);
28
  }
29
+ $gateway_result = Mage::getModel('sagepay/payment')->registerTransaction($data);
30
+ $session = Mage::getSingleton('core/session');
31
+ $session->setGatewayResult($gateway_result)->setPaymentdata($data);
32
+ if ($gateway_result['Status'] == '3DAUTH' && $gateway_result["PAReq"] != '' && $gateway_result["MD"] != '') {
33
+ $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();
34
+ $url = Mage::getUrl('checkout/onepage/sagepay3dCheck');
35
+ Mage::register('url', $url);
36
+
37
+ if (!isset($result['error'])) {
38
+ $result['goto_section'] = 'threedsecure';
39
+ $html = Mage::app()->getLayout()->createBlock('checkout/onepage')->setTemplate('sagepay/checkout/3dredirect.phtml')->toHtml();
40
+ $result['update_section'] = array(
41
+ 'name' => 'threedsecure',
42
+ 'html' => $html
43
+ #'html' => "<script>alert('hello');window.open('".$url."','mypopup','status=1,width=500,height=500,scrollbars=1');</script>"
44
+ );
45
+ }
46
+ } elseif (in_array($gateway_result['Status'], Mage::getSingleton('sagepay/config')->getExpectedSuccess())) {
47
+ $this->_forward('saveOrder');
48
+ }
 
 
 
49
  } catch (Exception $e) {
50
  Mage::logException($e);
51
+ $result['success'] = false;
52
  $result['error'] = true;
53
  $result['error_messages'] = $e->getMessage();
54
  }
55
  $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
56
  }
57
+
58
+ public function sagepay3dcheckAction()
59
+ {
60
+
61
+ $this->loadLayout();
62
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template', 'sagepay_3d_form', array('template' => 'sagepay/sagepay.phtml'));
63
+ $this->getLayout()->getBlock('content')->append($block);
64
+ $this->renderLayout();
65
+ }
66
+
67
+ public function threedsuccessAction()
68
+ {
69
+ $this->loadLayout();
70
+ try {
71
+ $result = Mage::getModel('sagepay/payment')->complete3d($_POST);
72
+ if (in_array($result['Status'], Mage::getSingleton('sagepay/config')->getExpectedSuccess())) {
73
+ $session = Mage::getSingleton('core/session');
74
+ $session->setGatewayResult($result);
75
+ Mage::register('status', 1);
76
+ Mage::register('url', Mage::getUrl('checkout/onepage/savesagepayorder'));
77
+ }
78
+ } catch (Exception $e) {
79
  Mage::logException($e);
80
  Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
81
+ $result['success'] = false;
82
+ $result['error'] = true;
83
  $result['error_messages'] = $this->__('There was an error processing your order. Please contact us or try again later.');
84
  }
85
+
86
+ $this->renderLayout();
87
+ }
88
+
89
+ public function saveSagePayOrderAction()
90
+ {
91
+ try {
92
+ $session = Mage::getSingleton('core/session');
93
+ if ($data = $session->getPaymentdata()) {
94
  $this->getOnepage()->getQuote()->getPayment()->importData($data);
95
  }
96
+ $this->getOnepage()->saveOrder();
97
+ $this->getOnepage()->getQuote()->save();
98
+ } catch (Exception $e) {
99
  Mage::logException($e);
100
  Mage::helper('checkout')->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
 
101
  }
102
+ $this->_redirect('checkout/onepage/success');
103
+ }
104
+
 
 
105
  }
app/code/community/Raveinfosys/Sagepay/sql/sagepay_setup/mysql4-install-0.1.0.php CHANGED
@@ -6,11 +6,11 @@ $installer->startSetup();
6
 
7
  $installer->run("
8
 
9
- -- DROP TABLE IF EXISTS {$this->getTable('sagepay')};
10
  CREATE TABLE {$this->getTable('sagepay')} (
11
- `sagepay_id` int(11) NOT NULL auto_increment,
12
- `parent_id` int(11),
13
- `order_id` int(11) NOT NULL default 0,
14
  `vps_tx_id` varchar(200) NOT NULL default '',
15
  `vendor_tx_code` varchar(200) NOT NULL default '',
16
  `security_key` varchar(200) NOT NULL default '',
@@ -32,11 +32,11 @@ $installer->run("
32
  PRIMARY KEY (`sagepay_id`)
33
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
34
 
35
- -- DROP TABLE IF EXISTS {$this->getTable('sagepay_transaction_detail')};
36
  CREATE TABLE {$this->getTable('sagepay_transaction_detail')} (
37
- `transaction_id` int(11) NOT NULL auto_increment,
38
- `sagepay_id` int(11) NOT NULL default 0,
39
- `order_id` int(11) NOT NULL default 0,
40
  `vps_tx_id` varchar(200) NOT NULL default '',
41
  `vendor_tx_code` varchar(200) NOT NULL default '',
42
  `security_key` varchar(200) NOT NULL default '',
@@ -51,4 +51,4 @@ CREATE TABLE {$this->getTable('sagepay_transaction_detail')} (
51
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
52
  ");
53
 
54
- $installer->endSetup();
6
 
7
  $installer->run("
8
 
9
+ -- DROP TABLE IF EXISTS {$this->getTable('sagepay')};
10
  CREATE TABLE {$this->getTable('sagepay')} (
11
+ `sagepay_id` int(11) NOT NULL auto_increment,
12
+ `parent_id` int(11),
13
+ `order_id` int(11) NOT NULL default 0,
14
  `vps_tx_id` varchar(200) NOT NULL default '',
15
  `vendor_tx_code` varchar(200) NOT NULL default '',
16
  `security_key` varchar(200) NOT NULL default '',
32
  PRIMARY KEY (`sagepay_id`)
33
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
34
 
35
+ -- DROP TABLE IF EXISTS {$this->getTable('sagepay_transaction_detail')};
36
  CREATE TABLE {$this->getTable('sagepay_transaction_detail')} (
37
+ `transaction_id` int(11) NOT NULL auto_increment,
38
+ `sagepay_id` int(11) NOT NULL default 0,
39
+ `order_id` int(11) NOT NULL default 0,
40
  `vps_tx_id` varchar(200) NOT NULL default '',
41
  `vendor_tx_code` varchar(200) NOT NULL default '',
42
  `security_key` varchar(200) NOT NULL default '',
51
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
52
  ");
53
 
54
+ $installer->endSetup();
app/design/frontend/base/default/layout/sagepay.xml CHANGED
@@ -4,7 +4,7 @@
4
  </default>
5
  <sagepay_index_index>
6
  <reference name="content">
7
- <block type="sagepay/sagepay" name="sagepay" template="sagepay/sagepay.phtml" />
8
  </reference>
9
  </sagepay_index_index>
10
 
@@ -13,7 +13,7 @@
13
  <remove name="top.menu"/>
14
  <remove name="top.search"/>
15
  <reference name="content">
16
- <block type="sagepay/sagepay" name="sagepay_3d_form" template="sagepay/sagepay.phtml" />
17
  </reference>
18
 
19
  </checkout_onepage_sagepay3dcheck>
@@ -23,7 +23,7 @@
23
  <remove name="top.menu"/>
24
  <remove name="top.search"/>
25
  <reference name="content">
26
- <block type="sagepay/sagepay" name="sagepay_success" template="sagepay/threedsuccess.phtml" />
27
  </reference>
28
 
29
  </checkout_onepage_threedsuccess>
4
  </default>
5
  <sagepay_index_index>
6
  <reference name="content">
7
+ <block type="core/template" name="sagepay" template="core/template.phtml" />
8
  </reference>
9
  </sagepay_index_index>
10
 
13
  <remove name="top.menu"/>
14
  <remove name="top.search"/>
15
  <reference name="content">
16
+ <block type="core/template" name="sagepay_3d_form" template="core/template.phtml" />
17
  </reference>
18
 
19
  </checkout_onepage_sagepay3dcheck>
23
  <remove name="top.menu"/>
24
  <remove name="top.search"/>
25
  <reference name="content">
26
+ <block type="core/template" name="sagepay_success" template="sagepay/threedsuccess.phtml" />
27
  </reference>
28
 
29
  </checkout_onepage_threedsuccess>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Raveinfosys_Sagepay</name>
4
- <version>1.0.1</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Sagepay Payment Gateway Extension.</summary>
10
  <description>Sagepay Payment Gateway Extension.</description>
11
- <notes>Sagepay Payment Gateway Extension.</notes>
12
- <authors><author><name>Raveinfosys</name><user>raveinfo</user><email>magento@raveinfosys.com</email></author></authors>
13
- <date>2015-09-21</date>
14
- <time>11:32:32</time>
15
- <contents><target name="magecommunity"><dir name="Raveinfosys"><dir name="Sagepay"><dir name="Block"><dir name="Adminhtml"><dir name="Sagepay"><file name="Grid.php" hash="0db3367183d7a7fe8cae22603d554109"/></dir><file name="Sagepay.php" hash="388092e2215094c2b4290c2ef665451b"/></dir></dir><dir name="Controller"><file name="Observer.php" hash="a8f23ad01b720298539da718bd411579"/></dir><dir name="Helper"><file name="Data.php" hash="82d35f0afe82ce647662b580d280d42b"/></dir><dir name="Model"><file name="Config.php" hash="c3f8ce937d1861c8f516cb6584a07045"/><dir name="Mysql4"><dir name="Sagepay"><file name="Collection.php" hash="a34bc048d96c80c5aefad7611c814889"/></dir><file name="Sagepay.php" hash="4543355ccce2bb8416ae1b54710a5b1b"/><dir name="Transaction"><file name="Collection.php" hash="f254735999990aff4feb7f8f8c7894d5"/></dir><file name="Transaction.php" hash="6c2c64d04a006c8758f7f6a308678cd2"/></dir><file name="Observer.php" hash="87abcae5b96fb4b086c5ce527c8cef7a"/><file name="Payment.php" hash="7335959594e4937f4ce66ef3313683f4"/><file name="Sagepay.php" hash="b4fc9d2512d0f3380791a3bd30a32a7e"/><file name="Status.php" hash="efe219eb960f30999b6cc34714e02e4b"/><dir name="System"><dir name="Config"><dir name="Source"><dir name="Dropdown"><file name="Values.php" hash="c9ee28285f0c4e25edb61d26e350c425"/></dir></dir></dir></dir><file name="Transaction.php" hash="6de8d7dbcd024fa40cdbf945cd179fca"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="SagepayController.php" hash="b929dc68f87b61a8f83831cf4b326aac"/></dir><dir name="Checkout"><file name="OnepageController.php" hash="497f7e4dfc9c7247f21c9918353b71a9"/></dir></dir><dir name="etc"><file name="config.xml" hash="a3c468c7232e42e7c41075ba98a887cb"/><file name="system.xml" hash="4f6cb32581acbf3d8741e2b15a6afe54"/></dir><dir name="sql"><dir name="sagepay_setup"><file name="mysql4-install-0.1.0.php" hash="c8b85994156863722912f98595ce8466"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="sagepay.xml" hash="5d58be735b1705d4341e0728656aa48d"/></dir><dir name="template"><dir name="sagepay"><dir name="checkout"><file name="3dredirect.phtml" hash="bc7dbec38d65fb797d41d09e814338ab"/><dir name="review"><file name="info.phtml" hash="daa7b988f6e41cc2ddf3d7343acd86f6"/></dir></dir><file name="sagepay.phtml" hash="a58ed0d6297e62b457035fb51c7a4955"/><file name="threedsuccess.phtml" hash="83347f1b11211582fe8daa5fcd3dd5df"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="sagepay.xml" hash="befac7554e8892b1e06d5b1d68fae32e"/></dir></dir><dir name="sagepay"><dir name="template"><dir name="sales"><dir name="order"><dir name="view"><dir name="items"><dir name="renderer"><file name="default.phtml" hash="4b6e5e56132537b4eb690ebd189d70ba"/></dir></dir><file name="items.phtml" hash="5e392e35a8c3c123be3a15c49f63c3b8"/><dir name="tab"><file name="info.phtml" hash="2a503acd3054293d7259440435d40eaf"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Raveinfosys_Sagepay.xml" hash="ef02fac665847458f4c4a3980dd1aed0"/></dir></target></contents>
16
  <compatible/>
17
- <dependencies><required><php><min>5.0.0</min><max>5.6.12</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Raveinfosys_Sagepay</name>
4
+ <version>1.0.2</version>
5
  <stability>stable</stability>
6
  <license>OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Sagepay Payment Gateway Extension.</summary>
10
  <description>Sagepay Payment Gateway Extension.</description>
11
+ <notes>This version is properly tested on the following Magento CE versions: 1.5, 1.6, 1.7,1.8,1.9.* . In this particular version we are supporting it to run on PHP V 5.5.X.</notes>
12
+ <authors><author><name>Rave Infosys</name><user>raveinfo</user><email>magento@raveinfosys.com</email></author></authors>
13
+ <date>2016-04-07</date>
14
+ <time>07:15:16</time>
15
+ <contents><target name="magecommunity"><dir name="Raveinfosys"><dir name="Sagepay"><dir name="Block"><dir name="Adminhtml"><dir name="Sagepay"><file name="Grid.php" hash="93cff5cf5c26db14bfc73f70b503d06d"/></dir><file name="Sagepay.php" hash="cd412c35093f881bb5b7cb84d5b697c5"/></dir></dir><dir name="Controller"><file name="Observer.php" hash="fb82d968fae6832d00b669d87d964e0a"/></dir><dir name="Helper"><file name="Data.php" hash="dcd5bdb84912401eef98006697b54a79"/></dir><dir name="Model"><file name="Config.php" hash="4b7b84de4c699a552131b2a8f145d897"/><dir name="Mysql4"><dir name="Sagepay"><file name="Collection.php" hash="861db6e6babf9b900f9c2be422c7e909"/></dir><file name="Sagepay.php" hash="b880c55bd894aeb26a9ad55842eb1e1e"/><dir name="Transaction"><file name="Collection.php" hash="dca1e40bbb6cee2f382f0fac398d32f6"/></dir><file name="Transaction.php" hash="e9b51b73460fca7ac31bfe78dc8defc1"/></dir><file name="Observer.php" hash="b0a26778751bbec6cd7608db6688ed49"/><file name="Payment.php" hash="4baf597cb1e0e751c0c61c73102a932e"/><file name="Sagepay.php" hash="5abb123e24acf07cdea8a8f7c2ee4375"/><file name="Status.php" hash="fd320d12ba0c856b7676df8f651dfb7a"/><dir name="System"><dir name="Config"><dir name="Source"><dir name="Dropdown"><file name="Values.php" hash="8183b136e4a2e5377f2b706ff5ed0d34"/></dir></dir></dir></dir><file name="Transaction.php" hash="f89c934b5d390aee8c30cc8d344e999b"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="SagepayController.php" hash="ba648e6cda846489a6b04364a1f4fec5"/></dir><dir name="Checkout"><file name="OnepageController.php" hash="033fa47705a876fb86315e5aa96a5cb3"/></dir></dir><dir name="etc"><file name="config.xml" hash="a3c468c7232e42e7c41075ba98a887cb"/><file name="system.xml" hash="4f6cb32581acbf3d8741e2b15a6afe54"/></dir><dir name="sql"><dir name="sagepay_setup"><file name="mysql4-install-0.1.0.php" hash="d0453d69d13ea649d2d9946b32de1b6d"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Raveinfosys_Sagepay.xml" hash="ef02fac665847458f4c4a3980dd1aed0"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="sagepay.xml" hash="befac7554e8892b1e06d5b1d68fae32e"/></dir></dir><dir name="sagepay"><dir name="template"><dir name="sales"><dir name="order"><dir name="view"><dir name="items"><dir name="renderer"><file name="default.phtml" hash="4b6e5e56132537b4eb690ebd189d70ba"/></dir></dir><file name="items.phtml" hash="5e392e35a8c3c123be3a15c49f63c3b8"/><dir name="tab"><file name="info.phtml" hash="2a503acd3054293d7259440435d40eaf"/></dir></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="sagepay.xml" hash="4353400c1d20ebc2e89e0318582db039"/></dir><dir name="template"><dir name="sagepay"><dir name="checkout"><file name="3dredirect.phtml" hash="bc7dbec38d65fb797d41d09e814338ab"/><dir name="review"><file name="info.phtml" hash="daa7b988f6e41cc2ddf3d7343acd86f6"/></dir></dir><file name="sagepay.phtml" hash="a58ed0d6297e62b457035fb51c7a4955"/><file name="threedsuccess.phtml" hash="83347f1b11211582fe8daa5fcd3dd5df"/></dir></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>5.6.20</max></php></required></dependencies>
18
  </package>