eWAY_Payment_Rapid31 - Version 1.4.1

Version Notes

Fixes and updates:

- Require eWAY customer account pages to use HTTPS if available
- Fix for PHP 5.3 compatibility issues
- Fix for issues with using alternate payment methods
- Fix the card selection dropdown appearing even if saved cards was disabled

Download this release

Release Info

Developer eWAY Payments
Extension eWAY_Payment_Rapid31
Version 1.4.1
Comparing to
See all releases


Code changes from version 1.4.0 to 1.4.1

Files changed (78) hide show
  1. app/code/community/Eway/Rapid31/Block/Adminhtml/Customer/Edit/Tab/Cards.php +57 -54
  2. app/code/community/Eway/Rapid31/Block/Adminhtml/Customer/Edit/Tab/Form.php +106 -105
  3. app/code/community/Eway/Rapid31/Block/Adminhtml/Customer/Method.php +33 -33
  4. app/code/community/Eway/Rapid31/Block/Adminhtml/Sales/Order/Grid.php +205 -187
  5. app/code/community/Eway/Rapid31/Block/Adminhtml/Sales/Order/Renderer/Items.php +18 -18
  6. app/code/community/Eway/Rapid31/Block/Customer/Edit.php +116 -117
  7. app/code/community/Eway/Rapid31/Block/Form/Direct/Ewayone.php +61 -57
  8. app/code/community/Eway/Rapid31/Block/Form/Direct/Saved.php +40 -40
  9. app/code/community/Eway/Rapid31/Block/Form/Sharedpage/Ewayone.php +57 -53
  10. app/code/community/Eway/Rapid31/Block/Form/Sharedpage/Notsaved.php +12 -12
  11. app/code/community/Eway/Rapid31/Block/Form/Sharedpage/Saved.php +34 -34
  12. app/code/community/Eway/Rapid31/Block/Form/Transparent/Ewayone.php +8 -4
  13. app/code/community/Eway/Rapid31/Block/Html/Head.php +2 -1
  14. app/code/community/Eway/Rapid31/Block/Info/Direct/Ewayone.php +44 -44
  15. app/code/community/Eway/Rapid31/Block/Info/Direct/Saved.php +44 -44
  16. app/code/community/Eway/Rapid31/Block/Info/Sharedpage/Ewayone.php +44 -44
  17. app/code/community/Eway/Rapid31/Block/Info/Sharedpage/Saved.php +44 -44
  18. app/code/community/Eway/Rapid31/Block/Redirect/PaypalReview.php +4 -2
  19. app/code/community/Eway/Rapid31/Block/Redirect/Transparent.php +83 -83
  20. app/code/community/Eway/Rapid31/Block/Redirect/TransparentCheckout.php +54 -54
  21. app/code/community/Eway/Rapid31/Block/Sales/Order/Grid.php +2 -1
  22. app/code/community/Eway/Rapid31/Helper/Customer.php +242 -242
  23. app/code/community/Eway/Rapid31/Helper/Data.php +232 -231
  24. app/code/community/Eway/Rapid31/Model/Backend/Savedtokens.php +37 -37
  25. app/code/community/Eway/Rapid31/Model/Config.php +187 -184
  26. app/code/community/Eway/Rapid31/Model/Customer/Savedtokens.php +92 -90
  27. app/code/community/Eway/Rapid31/Model/EwayCron.php +138 -131
  28. app/code/community/Eway/Rapid31/Model/Field/CardDetails.php +89 -89
  29. app/code/community/Eway/Rapid31/Model/JsonSerializableAbstract.php +44 -44
  30. app/code/community/Eway/Rapid31/Model/Method/Ewayone.php +431 -432
  31. app/code/community/Eway/Rapid31/Model/Method/Notsaved.php +524 -542
  32. app/code/community/Eway/Rapid31/Model/Method/Saved.php +284 -286
  33. app/code/community/Eway/Rapid31/Model/Observer.php +297 -292
  34. app/code/community/Eway/Rapid31/Model/RecurringProfile.php +531 -530
  35. app/code/community/Eway/Rapid31/Model/Request/Abstract.php +181 -179
  36. app/code/community/Eway/Rapid31/Model/Request/Direct.php +364 -339
  37. app/code/community/Eway/Rapid31/Model/Request/Sharedpage.php +647 -638
  38. app/code/community/Eway/Rapid31/Model/Request/Token.php +556 -543
  39. app/code/community/Eway/Rapid31/Model/Request/Transparent.php +779 -751
  40. app/code/community/Eway/Rapid31/Model/Resource/Setup.php +5 -4
  41. app/code/community/Eway/Rapid31/Model/Response.php +425 -426
  42. app/code/community/Eway/Rapid31/Model/System/Config/Backend/Orderstatus.php +21 -21
  43. app/code/community/Eway/Rapid31/Model/System/Config/Backend/Validation.php +51 -47
  44. app/code/community/Eway/Rapid31/Model/System/Config/Source/Orderstatus.php +32 -32
  45. app/code/community/Eway/Rapid31/Test/Model/Abstract.php +178 -178
  46. app/code/community/Eway/Rapid31/Test/Model/Config.php +12 -6
  47. app/code/community/Eway/Rapid31/Test/Model/CustomerToken.php +3 -6
  48. app/code/community/Eway/Rapid31/Test/Model/JsonSerializable.php +33 -17
  49. app/code/community/Eway/Rapid31/Test/Model/Response.php +4 -2
  50. app/code/community/Eway/Rapid31/controllers/Adminhtml/EwayadminController.php +237 -189
  51. app/code/community/Eway/Rapid31/controllers/Adminhtml/Ewayrapid/SavedcardController.php +306 -300
  52. app/code/community/Eway/Rapid31/controllers/Adminhtml/Sales/Order/CreateController.php +321 -302
  53. app/code/community/Eway/Rapid31/controllers/MycardsController.php +407 -401
  54. app/code/community/Eway/Rapid31/controllers/SharedpageController.php +475 -459
  55. app/code/community/Eway/Rapid31/controllers/TestController.php +127 -127
  56. app/code/community/Eway/Rapid31/controllers/TransparentController.php +556 -556
  57. app/code/community/Eway/Rapid31/etc/config.xml +369 -381
  58. app/code/community/Eway/Rapid31/sql/ewayrapid_setup/install-0.1.0.php +4 -2
  59. app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-1.0.0-1.0.1.php +14 -10
  60. app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-1.0.1-1.0.3.php +4 -2
  61. app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-1.3.2-1.4.0.php +20 -10
  62. app/design/adminhtml/default/default/layout/ewayrapid/layout.xml +78 -78
  63. app/design/adminhtml/default/default/template/ewayrapid/customer/edit/tab/cards.phtml +36 -36
  64. app/design/adminhtml/default/default/template/ewayrapid/customer/edit/tab/form.phtml +218 -218
  65. app/design/adminhtml/default/default/template/ewayrapid/customer/method.phtml +175 -175
  66. app/design/adminhtml/default/default/template/ewayrapid/form/direct_ewayone.phtml +181 -180
  67. app/design/adminhtml/default/default/template/ewayrapid/form/direct_notsaved.phtml +73 -72
  68. app/design/adminhtml/default/default/template/ewayrapid/form/direct_saved.phtml +110 -109
  69. app/design/adminhtml/default/default/template/ewayrapid/form/sharedpage_ewayone.phtml +7 -6
  70. app/design/adminhtml/default/default/template/ewayrapid/form/sharedpage_notsaved.phtml +28 -27
  71. app/design/adminhtml/default/default/template/ewayrapid/info/direct_ewayone.phtml +90 -90
  72. app/design/adminhtml/default/default/template/ewayrapid/info/direct_notsaved.phtml +104 -104
  73. app/design/adminhtml/default/default/template/ewayrapid/info/direct_saved.phtml +89 -89
  74. app/design/adminhtml/default/default/template/ewayrapid/info/sharedpage_notsaved.phtml +103 -103
  75. app/design/adminhtml/default/default/template/ewayrapid/info/sharedpage_saved.phtml +103 -103
  76. app/design/adminhtml/default/default/template/ewayrapid/pdf/direct_notsaved.phtml +54 -53
  77. app/design/frontend/base/default/layout/ewayrapid/layout.xml +215 -215
  78. app/design/frontend/base/default/template/ewayrapid/customer/edit.phtml +93 -706
app/code/community/Eway/Rapid31/Block/Adminhtml/Customer/Edit/Tab/Cards.php CHANGED
@@ -1,54 +1,57 @@
1
- <?php
2
- class Eway_Rapid31_Block_Adminhtml_Customer_Edit_Tab_Cards extends Mage_Adminhtml_Block_Template
3
- {
4
- protected $_code = 'ewayrapid';
5
- protected $_addressModel = null;
6
-
7
- /**
8
- * Get stored cards for the currently-active method.
9
- */
10
- public function getCards()
11
- {
12
- $customer = Mage::registry('current_customer');
13
- if($customer && $customer->getSavedTokens()){
14
- return $customer->getSavedTokens()->getTokens();
15
- }else{
16
- return array();
17
- }
18
- }
19
-
20
- protected function _getAddressModel(){
21
- if(!$this->_addressModel){
22
- $this->_addressModel = Mage::getModel('customer/address');
23
- }
24
-
25
- return $this->_addressModel;
26
- }
27
-
28
- /**
29
- * Get the current method code.
30
- */
31
- public function getCode()
32
- {
33
- if( parent::hasCode() ) {
34
- return parent::getCode();
35
- }
36
-
37
- return $this->_code;
38
- }
39
-
40
- public function formatAddress($address){
41
- $this->_getAddressModel()->unsetData();
42
- $this->_getAddressModel()->addData($address->getData());
43
- return $this->_getAddressModel()->format('html');
44
- }
45
-
46
- public function checkCards(){
47
- foreach($this->getCards() as $card){
48
- if($card->getActive()){
49
- return true;
50
- }
51
- }
52
- return false;
53
- }
54
- }
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Block_Adminhtml_Customer_Edit_Tab_Cards extends Mage_Adminhtml_Block_Template
3
+ {
4
+ protected $_code = 'ewayrapid';
5
+ protected $_addressModel = null;
6
+
7
+ /**
8
+ * Get stored cards for the currently-active method.
9
+ */
10
+ public function getCards()
11
+ {
12
+ $customer = Mage::registry('current_customer');
13
+ if ($customer && $customer->getSavedTokens()) {
14
+ return $customer->getSavedTokens()->getTokens();
15
+ } else {
16
+ return array();
17
+ }
18
+ }
19
+
20
+ protected function _getAddressModel()
21
+ {
22
+ if (!$this->_addressModel) {
23
+ $this->_addressModel = Mage::getModel('customer/address');
24
+ }
25
+
26
+ return $this->_addressModel;
27
+ }
28
+
29
+ /**
30
+ * Get the current method code.
31
+ */
32
+ public function getCode()
33
+ {
34
+ if ( parent::hasCode() ) {
35
+ return parent::getCode();
36
+ }
37
+
38
+ return $this->_code;
39
+ }
40
+
41
+ public function formatAddress($address)
42
+ {
43
+ $this->_getAddressModel()->unsetData();
44
+ $this->_getAddressModel()->addData($address->getData());
45
+ return $this->_getAddressModel()->format('html');
46
+ }
47
+
48
+ public function checkCards()
49
+ {
50
+ foreach ($this->getCards() as $card) {
51
+ if ($card->getActive()) {
52
+ return true;
53
+ }
54
+ }
55
+ return false;
56
+ }
57
+ }
app/code/community/Eway/Rapid31/Block/Adminhtml/Customer/Edit/Tab/Form.php CHANGED
@@ -1,105 +1,106 @@
1
- <?php
2
-
3
- class Eway_Rapid31_Block_Adminhtml_Customer_Edit_Tab_Form extends Mage_Adminhtml_Block_Template
4
- {
5
- protected $_code = 'ewayrapid';
6
- protected $_card = null;
7
-
8
- /**
9
- * Get the address block for dynamic state/country selection on forms.
10
- */
11
- public function getAddressBlock()
12
- {
13
- return Mage::helper('ewayrapid')->getAddressBlock();
14
- }
15
-
16
- /**
17
- * Return active card (if any).
18
- */
19
- public function getCard()
20
- {
21
- if(!$this->_card){
22
- $tokenId = $this->getTokenId();
23
- if($tokenId && $tokenId > 0){
24
- $tokens = Mage::registry('current_customer')->getSavedTokens();
25
- $this->_card = $tokens->getTokenById($tokenId);
26
- }else{
27
- $token = new Varien_Object();
28
- $address = new Varien_Object();
29
- $addressInfo = array(
30
- 'token_customer_id' => '',
31
- 'reference' => '',
32
- 'title' => '',
33
- 'first_name' => '',
34
- 'last_name' => '',
35
- 'company_name' => '',
36
- 'job_description' => '',
37
- 'street_1' => '',
38
- 'street_2' => '',
39
- 'city' => '',
40
- 'state' => '',
41
- 'postal_code' => '',
42
- 'country' => 'us',
43
- 'email' => '',
44
- 'phone' => '',
45
- 'mobile' => '',
46
- 'comments' => '',
47
- 'fax' => '',
48
- 'url' => '',
49
- 'region_id' => ''
50
- );
51
- $address->addData($addressInfo);
52
-
53
- $tokenInfo = array(
54
- 'token' => '',
55
- 'card' => '',
56
- 'owner' => '',
57
- 'exp_month' => '',
58
- 'exp_year' => '',
59
- // 'Type' => 'a',
60
- 'address' => $address,
61
- 'active' => 0
62
- );
63
- $token->addData($tokenInfo);
64
- $this->_card = $token;
65
- }
66
- }
67
-
68
- return $this->_card;
69
- }
70
-
71
- public function getRegionId(){
72
- $region = Mage::getModel('directory/region')->loadByName($this->getCard()->getAddress()->getState(), $this->getCard()->getAddress()->getData('Country'));
73
- return $region->getId();
74
- }
75
-
76
- /**
77
- * Get the current method code.
78
- */
79
- public function getCode()
80
- {
81
- if( parent::hasCode() ) {
82
- return parent::getCode();
83
- }
84
-
85
- return $this->_code;
86
- }
87
-
88
- /**
89
- * Return whether or not this is a card edit.
90
- */
91
- public function isEdit()
92
- {
93
- return ($this->getCard() && $this->getCard()->getToken());
94
- }
95
-
96
- /**
97
- * Retrieve array of prefix that accepted by eWAY
98
- *
99
- * @return array
100
- */
101
- public function getPrefixOptions()
102
- {
103
- return array('', 'Mr.', 'Ms.', 'Mrs.', 'Miss', 'Dr.', 'Sir.', 'Prof.');
104
- }
105
- }
 
1
+ <?php
2
+
3
+ class Eway_Rapid31_Block_Adminhtml_Customer_Edit_Tab_Form extends Mage_Adminhtml_Block_Template
4
+ {
5
+ protected $_code = 'ewayrapid';
6
+ protected $_card = null;
7
+
8
+ /**
9
+ * Get the address block for dynamic state/country selection on forms.
10
+ */
11
+ public function getAddressBlock()
12
+ {
13
+ return Mage::helper('ewayrapid')->getAddressBlock();
14
+ }
15
+
16
+ /**
17
+ * Return active card (if any).
18
+ */
19
+ public function getCard()
20
+ {
21
+ if (!$this->_card) {
22
+ $tokenId = $this->getTokenId();
23
+ if ($tokenId && $tokenId > 0) {
24
+ $tokens = Mage::registry('current_customer')->getSavedTokens();
25
+ $this->_card = $tokens->getTokenById($tokenId);
26
+ } else {
27
+ $token = new Varien_Object();
28
+ $address = new Varien_Object();
29
+ $addressInfo = array(
30
+ 'token_customer_id' => '',
31
+ 'reference' => '',
32
+ 'title' => '',
33
+ 'first_name' => '',
34
+ 'last_name' => '',
35
+ 'company_name' => '',
36
+ 'job_description' => '',
37
+ 'street_1' => '',
38
+ 'street_2' => '',
39
+ 'city' => '',
40
+ 'state' => '',
41
+ 'postal_code' => '',
42
+ 'country' => 'us',
43
+ 'email' => '',
44
+ 'phone' => '',
45
+ 'mobile' => '',
46
+ 'comments' => '',
47
+ 'fax' => '',
48
+ 'url' => '',
49
+ 'region_id' => ''
50
+ );
51
+ $address->addData($addressInfo);
52
+
53
+ $tokenInfo = array(
54
+ 'token' => '',
55
+ 'card' => '',
56
+ 'owner' => '',
57
+ 'exp_month' => '',
58
+ 'exp_year' => '',
59
+ // 'Type' => 'a',
60
+ 'address' => $address,
61
+ 'active' => 0
62
+ );
63
+ $token->addData($tokenInfo);
64
+ $this->_card = $token;
65
+ }
66
+ }
67
+
68
+ return $this->_card;
69
+ }
70
+
71
+ public function getRegionId()
72
+ {
73
+ $region = Mage::getModel('directory/region')->loadByName($this->getCard()->getAddress()->getState(), $this->getCard()->getAddress()->getData('Country'));
74
+ return $region->getId();
75
+ }
76
+
77
+ /**
78
+ * Get the current method code.
79
+ */
80
+ public function getCode()
81
+ {
82
+ if ( parent::hasCode() ) {
83
+ return parent::getCode();
84
+ }
85
+
86
+ return $this->_code;
87
+ }
88
+
89
+ /**
90
+ * Return whether or not this is a card edit.
91
+ */
92
+ public function isEdit()
93
+ {
94
+ return ($this->getCard() && $this->getCard()->getToken());
95
+ }
96
+
97
+ /**
98
+ * Retrieve array of prefix that accepted by eWAY
99
+ *
100
+ * @return array
101
+ */
102
+ public function getPrefixOptions()
103
+ {
104
+ return array('', 'Mr.', 'Ms.', 'Mrs.', 'Miss', 'Dr.', 'Sir.', 'Prof.');
105
+ }
106
+ }
app/code/community/Eway/Rapid31/Block/Adminhtml/Customer/Method.php CHANGED
@@ -1,33 +1,33 @@
1
- <?php
2
- class Eway_Rapid31_Block_Adminhtml_Customer_Method extends Mage_Adminhtml_Block_Template
3
- {
4
- protected $_code = 'ewayrapid';
5
-
6
- /**
7
- * Get the current method code.
8
- */
9
- public function getCode()
10
- {
11
- if( parent::hasCode() ) {
12
- return parent::getCode();
13
- }
14
-
15
- return $this->_code;
16
- }
17
-
18
- /**
19
- * Return whether or not this is an AJAX request.
20
- */
21
- public function isAjax()
22
- {
23
- return ( $this->getRequest()->getParam('isAjax') == 1 ) ? true : false;
24
- }
25
-
26
- /**
27
- * Return the current customer record.
28
- */
29
- public function getCustomer()
30
- {
31
- return Mage::registry('current_customer');
32
- }
33
- }
1
+ <?php
2
+ class Eway_Rapid31_Block_Adminhtml_Customer_Method extends Mage_Adminhtml_Block_Template
3
+ {
4
+ protected $_code = 'ewayrapid';
5
+
6
+ /**
7
+ * Get the current method code.
8
+ */
9
+ public function getCode()
10
+ {
11
+ if ( parent::hasCode() ) {
12
+ return parent::getCode();
13
+ }
14
+
15
+ return $this->_code;
16
+ }
17
+
18
+ /**
19
+ * Return whether or not this is an AJAX request.
20
+ */
21
+ public function isAjax()
22
+ {
23
+ return ( $this->getRequest()->getParam('isAjax') == 1 ) ? true : false;
24
+ }
25
+
26
+ /**
27
+ * Return the current customer record.
28
+ */
29
+ public function getCustomer()
30
+ {
31
+ return Mage::registry('current_customer');
32
+ }
33
+ }
app/code/community/Eway/Rapid31/Block/Adminhtml/Sales/Order/Grid.php CHANGED
@@ -1,188 +1,206 @@
1
- <?php
2
- class Eway_Rapid31_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
- {
4
- const CAPTURED = 1;
5
- const NOT_CAPTURED = 0;
6
-
7
- public function __construct()
8
- {
9
- parent::__construct();
10
- $this->setId('eway_order_grid');
11
- $this->setUseAjax(true);
12
- $this->setDefaultSort('created_at');
13
- $this->setDefaultDir('DESC');
14
- $this->setSaveParametersInSession(true);
15
- }
16
-
17
- protected function _getCollectionClass()
18
- {
19
- return 'sales/order_grid_collection';
20
- }
21
-
22
- /**
23
- * Set the orders to display
24
- *
25
- * @return $this
26
- */
27
- protected function _prepareCollection()
28
- {
29
- // Test that the eWAY columns are present
30
- $resource = Mage::getSingleton('core/resource');
31
- $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
32
- $table = $resource->getTableName('sales/order_payment');
33
- $rows = $connection->fetchAll("SHOW COLUMNS FROM `{$table}` LIKE 'fraud_action'");
34
-
35
- if (empty($rows)) {
36
- echo '<div id="messages"><ul class="messages"><li class="error-msg"><ul><li><span>Error fetching eWAY orders, please check the eWAY extension is properly installed.</span></li></ul></li></ul></div>';
37
- return parent::_prepareCollection();
38
- }
39
-
40
- $collection = Mage::getResourceModel($this->_getCollectionClass());
41
-
42
- $ewayMethodCodes = array(
43
- Mage::getModel('ewayrapid/method_notsaved')->getCode(),
44
- Mage::getModel('ewayrapid/method_saved')->getCode(),
45
- Mage::getModel('ewayrapid/method_ewayone')->getCode()
46
- );
47
-
48
- // Add payment method to filter
49
- $collection->getSelect()->join(
50
- array('payment' => $resource->getTableName('sales/order_payment')),
51
- 'main_table.entity_id=payment.parent_id',
52
- array(
53
- 'payment_method' => 'payment.method',
54
- 'fraud_action' => 'payment.fraud_action',
55
- 'fraud_codes' => 'payment.fraud_codes',
56
- 'transaction_captured' => 'payment.transaction_captured',
57
- 'beagle_score' => 'payment.beagle_score'
58
- )
59
- );
60
-
61
- $collection->addFieldToFilter('payment.method',array('in' => $ewayMethodCodes));
62
-
63
- $this->setCollection($collection);
64
- return parent::_prepareCollection();
65
- }
66
-
67
- protected function _prepareColumns()
68
- {
69
-
70
- $this->addColumn('real_order_id', array(
71
- 'header'=> Mage::helper('ewayrapid')->__('Magento Order ID'),
72
- 'width' => '80px',
73
- 'type' => 'text',
74
- 'index' => 'increment_id',
75
- ));
76
-
77
- $this->addColumn('items_ordered', array(
78
- 'header' => Mage::helper('ewayrapid')->__('Item(s) Ordered'),
79
- 'index' => 'entity_id',
80
- 'renderer' => 'Eway_Rapid31_Block_Adminhtml_Sales_Order_Renderer_Items',
81
- 'filter_condition_callback' => array($this, '_itemsFilter'),
82
- ));
83
-
84
- $this->addColumn('created_at', array(
85
- 'header' => Mage::helper('ewayrapid')->__('Purchased On'),
86
- 'index' => 'created_at',
87
- 'type' => 'datetime',
88
- 'width' => '100px',
89
- ));
90
-
91
- $this->addColumn('billing_name', array(
92
- 'header' => Mage::helper('ewayrapid')->__('Bill to Name'),
93
- 'index' => 'billing_name',
94
- ));
95
-
96
- $this->addColumn('beagle_score', array(
97
- 'header' => Mage::helper('ewayrapid')->__('Beagle Score'),
98
- 'index' => 'beagle_score',
99
- ));
100
-
101
- $this->addColumn('fraud_action', array(
102
- 'header' => Mage::helper('ewayrapid')->__('Fraud Action'),
103
- 'index' => 'fraud_action',
104
- ));
105
-
106
- $this->addColumn('transaction_captured', array(
107
- 'header' => Mage::helper('ewayrapid')->__('Captured'),
108
- 'index' => 'transaction_captured',
109
- 'type' => 'options',
110
- 'options' => array(
111
- self::CAPTURED => Mage::helper('ewayrapid')->__('Yes'),
112
- self::NOT_CAPTURED => Mage::helper('ewayrapid')->__('No')
113
- ),
114
- ));
115
-
116
- $this->addColumn('fraud_codes', array(
117
- 'header' => Mage::helper('ewayrapid')->__('Fraud Codes'),
118
- 'index' => 'fraud_codes',
119
- ));
120
-
121
- $this->addColumn('status', array(
122
- 'header' => Mage::helper('ewayrapid')->__('Order Status'),
123
- 'index' => 'status',
124
- 'type' => 'options',
125
- 'width' => '70px',
126
- 'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
127
- ));
128
-
129
- return parent::_prepareColumns();
130
- }
131
-
132
- protected function _prepareMassaction()
133
- {
134
- $this->setMassactionIdField('entity_id');
135
- $this->getMassactionBlock()->setFormFieldName('order_ids');
136
- $this->getMassactionBlock()->setUseSelectAll(false);
137
-
138
- // Append new mass action option
139
- $this->getMassactionBlock()->addItem(
140
- 'pending',
141
- array(
142
- 'label' => $this->__('Verify eWAY Order'),
143
- 'url' => Mage::helper("adminhtml")->getUrl("adminhtml/ewayadmin/massVerifyEwayOrder"), //this should be the url where there will be mass operation
144
- 'confirm'=> $this->__('Are you sure?')
145
- )
146
- );
147
- }
148
-
149
- public function getGridUrl()
150
- {
151
- return $this->getUrl('*/*/grid', array('_current'=>true));
152
- }
153
-
154
- protected function _itemsFilter($collection, $column)
155
- {
156
- if (!$value = $column->getFilter()->getValue()) {
157
- return $this;
158
- }
159
- $filteredCollection = Mage::getResourceModel($this->_getCollectionClass());
160
-
161
- $resource = Mage::getSingleton('core/resource');
162
-
163
- $filteredCollection->getSelect()->join(
164
- array('items' => $resource->getTableName('sales/order_item')),
165
- 'main_table.entity_id=items.order_id and items.parent_item_id is null',
166
- array('items_ordered' => 'GROUP_CONCAT(items.name)')
167
- )->group('main_table.entity_id')->having('items_ordered like "%'. $value .'%"');
168
-
169
- $filteredOrderIds = array();
170
-
171
- foreach($filteredCollection as $filteredOrder){
172
- $filteredOrderIds[] = $filteredOrder->getId();
173
- }
174
-
175
- $collection->addFieldToFilter('entity_id',array('in' => $filteredOrderIds));
176
-
177
- return $this;
178
- }
179
-
180
- public function getRowUrl($row)
181
- {
182
- if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
183
- return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
184
- }
185
- return false;
186
- }
187
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
3
+ {
4
+ const CAPTURED = 1;
5
+ const NOT_CAPTURED = 0;
6
+
7
+ public function __construct()
8
+ {
9
+ parent::__construct();
10
+ $this->setId('eway_order_grid');
11
+ $this->setUseAjax(true);
12
+ $this->setDefaultSort('created_at');
13
+ $this->setDefaultDir('DESC');
14
+ $this->setSaveParametersInSession(true);
15
+ }
16
+
17
+ protected function _getCollectionClass()
18
+ {
19
+ return 'sales/order_grid_collection';
20
+ }
21
+
22
+ /**
23
+ * Set the orders to display
24
+ *
25
+ * @return $this
26
+ */
27
+ protected function _prepareCollection()
28
+ {
29
+ // Test that the eWAY columns are present
30
+ $resource = Mage::getSingleton('core/resource');
31
+ $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
32
+ $table = $resource->getTableName('sales/order_payment');
33
+ $rows = $connection->fetchAll("SHOW COLUMNS FROM `{$table}` LIKE 'fraud_action'");
34
+
35
+ if (empty($rows)) {
36
+ echo '<div id="messages"><ul class="messages"><li class="error-msg"><ul><li><span>Error fetching eWAY orders, please check the eWAY extension is properly installed.</span></li></ul></li></ul></div>';
37
+ return parent::_prepareCollection();
38
+ }
39
+
40
+ $collection = Mage::getResourceModel($this->_getCollectionClass());
41
+
42
+ $ewayMethodCodes = array(
43
+ Mage::getModel('ewayrapid/method_notsaved')->getCode(),
44
+ Mage::getModel('ewayrapid/method_saved')->getCode(),
45
+ Mage::getModel('ewayrapid/method_ewayone')->getCode()
46
+ );
47
+
48
+ // Add payment method to filter
49
+ $collection->getSelect()->join(
50
+ array('payment' => $resource->getTableName('sales/order_payment')),
51
+ 'main_table.entity_id=payment.parent_id',
52
+ array(
53
+ 'payment_method' => 'payment.method',
54
+ 'fraud_action' => 'payment.fraud_action',
55
+ 'fraud_codes' => 'payment.fraud_codes',
56
+ 'transaction_captured' => 'payment.transaction_captured',
57
+ 'beagle_score' => 'payment.beagle_score'
58
+ )
59
+ );
60
+
61
+ $collection->addFieldToFilter('payment.method', array('in' => $ewayMethodCodes));
62
+
63
+ $this->setCollection($collection);
64
+ return parent::_prepareCollection();
65
+ }
66
+
67
+ protected function _prepareColumns()
68
+ {
69
+
70
+ $this->addColumn(
71
+ 'real_order_id', array(
72
+ 'header'=> Mage::helper('ewayrapid')->__('Magento Order ID'),
73
+ 'width' => '80px',
74
+ 'type' => 'text',
75
+ 'index' => 'increment_id',
76
+ )
77
+ );
78
+
79
+ $this->addColumn(
80
+ 'items_ordered', array(
81
+ 'header' => Mage::helper('ewayrapid')->__('Item(s) Ordered'),
82
+ 'index' => 'entity_id',
83
+ 'renderer' => 'Eway_Rapid31_Block_Adminhtml_Sales_Order_Renderer_Items',
84
+ 'filter_condition_callback' => array($this, '_itemsFilter'),
85
+ )
86
+ );
87
+
88
+ $this->addColumn(
89
+ 'created_at', array(
90
+ 'header' => Mage::helper('ewayrapid')->__('Purchased On'),
91
+ 'index' => 'created_at',
92
+ 'type' => 'datetime',
93
+ 'width' => '100px',
94
+ )
95
+ );
96
+
97
+ $this->addColumn(
98
+ 'billing_name', array(
99
+ 'header' => Mage::helper('ewayrapid')->__('Bill to Name'),
100
+ 'index' => 'billing_name',
101
+ )
102
+ );
103
+
104
+ $this->addColumn(
105
+ 'beagle_score', array(
106
+ 'header' => Mage::helper('ewayrapid')->__('Beagle Score'),
107
+ 'index' => 'beagle_score',
108
+ )
109
+ );
110
+
111
+ $this->addColumn(
112
+ 'fraud_action', array(
113
+ 'header' => Mage::helper('ewayrapid')->__('Fraud Action'),
114
+ 'index' => 'fraud_action',
115
+ )
116
+ );
117
+
118
+ $this->addColumn(
119
+ 'transaction_captured', array(
120
+ 'header' => Mage::helper('ewayrapid')->__('Captured'),
121
+ 'index' => 'transaction_captured',
122
+ 'type' => 'options',
123
+ 'options' => array(
124
+ self::CAPTURED => Mage::helper('ewayrapid')->__('Yes'),
125
+ self::NOT_CAPTURED => Mage::helper('ewayrapid')->__('No')
126
+ ),
127
+ )
128
+ );
129
+
130
+ $this->addColumn(
131
+ 'fraud_codes', array(
132
+ 'header' => Mage::helper('ewayrapid')->__('Fraud Codes'),
133
+ 'index' => 'fraud_codes',
134
+ )
135
+ );
136
+
137
+ $this->addColumn(
138
+ 'status', array(
139
+ 'header' => Mage::helper('ewayrapid')->__('Order Status'),
140
+ 'index' => 'status',
141
+ 'type' => 'options',
142
+ 'width' => '70px',
143
+ 'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
144
+ )
145
+ );
146
+
147
+ return parent::_prepareColumns();
148
+ }
149
+
150
+ protected function _prepareMassaction()
151
+ {
152
+ $this->setMassactionIdField('entity_id');
153
+ $this->getMassactionBlock()->setFormFieldName('order_ids');
154
+ $this->getMassactionBlock()->setUseSelectAll(false);
155
+
156
+ // Append new mass action option
157
+ $this->getMassactionBlock()->addItem(
158
+ 'pending',
159
+ array(
160
+ 'label' => $this->__('Verify eWAY Order'),
161
+ 'url' => Mage::helper("adminhtml")->getUrl("adminhtml/ewayadmin/massVerifyEwayOrder"), //this should be the url where there will be mass operation
162
+ 'confirm'=> $this->__('Are you sure?')
163
+ )
164
+ );
165
+ }
166
+
167
+ public function getGridUrl()
168
+ {
169
+ return $this->getUrl('*/*/grid', array('_current'=>true));
170
+ }
171
+
172
+ protected function _itemsFilter($collection, $column)
173
+ {
174
+ if (!$value = $column->getFilter()->getValue()) {
175
+ return $this;
176
+ }
177
+ $filteredCollection = Mage::getResourceModel($this->_getCollectionClass());
178
+
179
+ $resource = Mage::getSingleton('core/resource');
180
+
181
+ $filteredCollection->getSelect()->join(
182
+ array('items' => $resource->getTableName('sales/order_item')),
183
+ 'main_table.entity_id=items.order_id and items.parent_item_id is null',
184
+ array('items_ordered' => 'GROUP_CONCAT(items.name)')
185
+ )->group('main_table.entity_id')->having('items_ordered like "%'. $value .'%"');
186
+
187
+ $filteredOrderIds = array();
188
+
189
+ foreach ($filteredCollection as $filteredOrder) {
190
+ $filteredOrderIds[] = $filteredOrder->getId();
191
+ }
192
+
193
+ $collection->addFieldToFilter('entity_id', array('in' => $filteredOrderIds));
194
+
195
+ return $this;
196
+ }
197
+
198
+ public function getRowUrl($row)
199
+ {
200
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
201
+ return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
202
+ }
203
+ return false;
204
+ }
205
+
206
  }
app/code/community/Eway/Rapid31/Block/Adminhtml/Sales/Order/Renderer/Items.php CHANGED
@@ -1,19 +1,19 @@
1
- <?php
2
- class Eway_Rapid31_Block_Adminhtml_Sales_Order_Renderer_Items extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
3
- {
4
- public function render(Varien_Object $row)
5
- {
6
- $value = $row->getData('entity_id');
7
-
8
- $order = Mage::getModel('sales/order')->load($value);
9
-
10
- $html = '';
11
- if($order->getId()){
12
- foreach($order->getAllVisibleItems() as $item){
13
- $html .= $item->getName() . ', ';
14
- }
15
- }
16
-
17
- return trim($html, ', ');
18
- }
19
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Adminhtml_Sales_Order_Renderer_Items extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
3
+ {
4
+ public function render(Varien_Object $row)
5
+ {
6
+ $value = $row->getData('entity_id');
7
+
8
+ $order = Mage::getModel('sales/order')->load($value);
9
+
10
+ $html = '';
11
+ if ($order->getId()) {
12
+ foreach ($order->getAllVisibleItems() as $item) {
13
+ $html .= $item->getName() . ', ';
14
+ }
15
+ }
16
+
17
+ return trim($html, ', ');
18
+ }
19
  }
app/code/community/Eway/Rapid31/Block/Customer/Edit.php CHANGED
@@ -1,118 +1,117 @@
1
- <?php
2
- class Eway_Rapid31_Block_Customer_Edit extends Mage_Directory_Block_Data
3
- {
4
-
5
- private $_currentToken = null;
6
-
7
- public function getTitle()
8
- {
9
- if ($title = $this->getData('title')) {
10
- return $title;
11
- }
12
- if ($this->isEdit()) {
13
- $title = Mage::helper('customer')->__('Edit Credit Card');
14
- }
15
- else {
16
- $title = Mage::helper('customer')->__('Add New Credit Card');
17
- }
18
- return $title;
19
- }
20
-
21
- /**
22
- * @return Eway_Rapid31_Model_Customer_Token|mixed
23
- */
24
- public function getCurrentToken()
25
- {
26
- if(Mage::getSingleton('customer/session')->getTokenInfo()) {
27
- $this->_currentToken = Mage::getSingleton('customer/session')->getTokenInfo();
28
- Mage::getSingleton('customer/session')->setTokenInfo(null);
29
- }
30
-
31
- if(is_null($this->_currentToken)) {
32
- $this->_currentToken = Mage::registry('current_token') ? Mage::registry('current_token') : Mage::getModel('ewayrapid/customer_token');
33
- }
34
-
35
- return $this->_currentToken;
36
- }
37
-
38
- /**
39
- * @return Eway_Rapid31_Model_Field_Customer
40
- */
41
- public function getCustomerAddress()
42
- {
43
- return $this->getCurrentToken()->getAddress() ? $this->getCurrentToken()->getAddress() : Mage::getModel('ewayrapid/field_customer');
44
- }
45
-
46
- public function getSaveUrl()
47
- {
48
- return $this::getUrl('*/*/save');
49
- }
50
-
51
- public function getBackUrl()
52
- {
53
- return $this::getUrl('*/*/');
54
- }
55
-
56
- /**
57
- * Check if CVN is required or not
58
- *
59
- * @return bool
60
- */
61
- public function hasVerification()
62
- {
63
- // No need for CVN in creating/updating token
64
- return false;
65
- }
66
-
67
- /**
68
- * Check if current action is Edit or New
69
- *
70
- * @return int
71
- */
72
- public function isEdit()
73
- {
74
- return $this->getCurrentToken()->getToken();
75
- }
76
-
77
- /**
78
- * Retrieve credit card expire months
79
- *
80
- * @return array
81
- */
82
- public function getCcMonths()
83
- {
84
- $months = $this->getData('cc_months');
85
- if (is_null($months)) {
86
- $months[0] = $this->__('Month');
87
- $months = array_merge($months, Mage::getSingleton('payment/config')->getMonths());
88
- $this->setData('cc_months', $months);
89
- }
90
- return $months;
91
- }
92
-
93
- /**
94
- * Retrieve credit card expire years
95
- *
96
- * @return array
97
- */
98
- public function getCcYears()
99
- {
100
- $years = $this->getData('cc_years');
101
- if (is_null($years)) {
102
- $years = Mage::getSingleton('payment/config')->getYears();
103
- $years = array(0=>$this->__('Year'))+$years;
104
- $this->setData('cc_years', $years);
105
- }
106
- return $years;
107
- }
108
-
109
- /**
110
- * Retrieve array of prefix that accepted by eWAY
111
- *
112
- * @return array
113
- */
114
- public function getPrefixOptions()
115
- {
116
- return array('', 'Mr.', 'Ms.', 'Mrs.', 'Miss', 'Dr.', 'Sir.', 'Prof.');
117
- }
118
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Customer_Edit extends Mage_Directory_Block_Data
3
+ {
4
+
5
+ private $_currentToken = null;
6
+
7
+ public function getTitle()
8
+ {
9
+ if ($title = $this->getData('title')) {
10
+ return $title;
11
+ }
12
+ if ($this->isEdit()) {
13
+ $title = Mage::helper('customer')->__('Edit Credit Card');
14
+ } else {
15
+ $title = Mage::helper('customer')->__('Add New Credit Card');
16
+ }
17
+ return $title;
18
+ }
19
+
20
+ /**
21
+ * @return Eway_Rapid31_Model_Customer_Token|mixed
22
+ */
23
+ public function getCurrentToken()
24
+ {
25
+ if (Mage::getSingleton('customer/session')->getTokenInfo()) {
26
+ $this->_currentToken = Mage::getSingleton('customer/session')->getTokenInfo();
27
+ Mage::getSingleton('customer/session')->setTokenInfo(null);
28
+ }
29
+
30
+ if (is_null($this->_currentToken)) {
31
+ $this->_currentToken = Mage::registry('current_token') ? Mage::registry('current_token') : Mage::getModel('ewayrapid/customer_token');
32
+ }
33
+
34
+ return $this->_currentToken;
35
+ }
36
+
37
+ /**
38
+ * @return Eway_Rapid31_Model_Field_Customer
39
+ */
40
+ public function getCustomerAddress()
41
+ {
42
+ return $this->getCurrentToken()->getAddress() ? $this->getCurrentToken()->getAddress() : Mage::getModel('ewayrapid/field_customer');
43
+ }
44
+
45
+ public function getSaveUrl()
46
+ {
47
+ return $this::getUrl('*/*/save');
48
+ }
49
+
50
+ public function getBackUrl()
51
+ {
52
+ return $this::getUrl('*/*/');
53
+ }
54
+
55
+ /**
56
+ * Check if CVN is required or not
57
+ *
58
+ * @return bool
59
+ */
60
+ public function hasVerification()
61
+ {
62
+ // No need for CVN in creating/updating token
63
+ return false;
64
+ }
65
+
66
+ /**
67
+ * Check if current action is Edit or New
68
+ *
69
+ * @return int
70
+ */
71
+ public function isEdit()
72
+ {
73
+ return $this->getCurrentToken()->getToken();
74
+ }
75
+
76
+ /**
77
+ * Retrieve credit card expire months
78
+ *
79
+ * @return array
80
+ */
81
+ public function getCcMonths()
82
+ {
83
+ $months = $this->getData('cc_months');
84
+ if (is_null($months)) {
85
+ $months[0] = $this->__('Month');
86
+ $months = array_merge($months, Mage::getSingleton('payment/config')->getMonths());
87
+ $this->setData('cc_months', $months);
88
+ }
89
+ return $months;
90
+ }
91
+
92
+ /**
93
+ * Retrieve credit card expire years
94
+ *
95
+ * @return array
96
+ */
97
+ public function getCcYears()
98
+ {
99
+ $years = $this->getData('cc_years');
100
+ if (is_null($years)) {
101
+ $years = Mage::getSingleton('payment/config')->getYears();
102
+ $years = array(0=>$this->__('Year'))+$years;
103
+ $this->setData('cc_years', $years);
104
+ }
105
+ return $years;
106
+ }
107
+
108
+ /**
109
+ * Retrieve array of prefix that accepted by eWAY
110
+ *
111
+ * @return array
112
+ */
113
+ public function getPrefixOptions()
114
+ {
115
+ return array('', 'Mr.', 'Ms.', 'Mrs.', 'Miss', 'Dr.', 'Sir.', 'Prof.');
116
+ }
 
117
  }
app/code/community/Eway/Rapid31/Block/Form/Direct/Ewayone.php CHANGED
@@ -1,58 +1,62 @@
1
- <?php
2
- class Eway_Rapid31_Block_Form_Direct_Ewayone extends Mage_Payment_Block_Form_Cc
3
- {
4
- protected function _construct()
5
- {
6
- parent::_construct();
7
- $this->setIsRecurring(Mage::helper('ewayrapid')->isRecurring());
8
- $this->setTemplate('ewayrapid/form/direct_ewayone.phtml');
9
- }
10
-
11
- /**
12
- * Get list of active tokens of current customer
13
- *
14
- * @return array
15
- */
16
- public function getTokenList()
17
- {
18
- $tokenList = array();
19
- $tokenList['tokens'] = Mage::helper('ewayrapid/customer')->getActiveTokenList();
20
- $tokenList['tokens'][Eway_Rapid31_Model_Config::TOKEN_NEW] =
21
- Mage::getModel('ewayrapid/customer_token')->setCard($this->__('Use a new card'))->setOwner('')
22
- ->setExpMonth('')->setExpYear('');
23
- $tokenList['default_token'] = Mage::helper('ewayrapid/customer')->getDefaultToken();
24
-
25
- $tokenListJson = array();
26
- foreach($tokenList['tokens'] as $id => $token) {
27
- /* @var Eway_Rapid31_Model_Customer_Token $token */
28
- $tokenListJson[] = "\"{$id}\":{$token->jsonSerialize()}";
29
- }
30
- $tokenList['tokens_json'] = '{' . implode(',', $tokenListJson) . '}';
31
-
32
- return $tokenList;
33
- }
34
-
35
- public function checkCardName($card)
36
- {
37
- /* @var Eway_Rapid31_Model_Request_Token $model */
38
- $model = Mage::getModel('ewayrapid/request_token');
39
- return $model->checkCardName($card);
40
- }
41
-
42
- public function getSaveCard(){
43
- return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card');
44
- }
45
-
46
- public function getSaveText(){
47
- return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_text');
48
- }
49
-
50
- public function getSaveDefaultCheck(){
51
- return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card_checked');
52
- }
53
-
54
- public function checkSaveCardAvailable(){
55
- return Mage::helper('ewayrapid/customer')->getCurrentCustomer()
56
- || Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER;
57
- }
 
 
 
 
58
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Form_Direct_Ewayone extends Mage_Payment_Block_Form_Cc
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setIsRecurring(Mage::helper('ewayrapid')->isRecurring());
8
+ $this->setTemplate('ewayrapid/form/direct_ewayone.phtml');
9
+ }
10
+
11
+ /**
12
+ * Get list of active tokens of current customer
13
+ *
14
+ * @return array
15
+ */
16
+ public function getTokenList()
17
+ {
18
+ $tokenList = array();
19
+ $tokenList['tokens'] = Mage::helper('ewayrapid/customer')->getActiveTokenList();
20
+ $tokenList['tokens'][Eway_Rapid31_Model_Config::TOKEN_NEW] =
21
+ Mage::getModel('ewayrapid/customer_token')->setCard($this->__('Use a new card'))->setOwner('')
22
+ ->setExpMonth('')->setExpYear('');
23
+ $tokenList['default_token'] = Mage::helper('ewayrapid/customer')->getDefaultToken();
24
+
25
+ $tokenListJson = array();
26
+ foreach ($tokenList['tokens'] as $id => $token) {
27
+ /* @var Eway_Rapid31_Model_Customer_Token $token */
28
+ $tokenListJson[] = "\"{$id}\":{$token->jsonSerialize()}";
29
+ }
30
+ $tokenList['tokens_json'] = '{' . implode(',', $tokenListJson) . '}';
31
+
32
+ return $tokenList;
33
+ }
34
+
35
+ public function checkCardName($card)
36
+ {
37
+ /* @var Eway_Rapid31_Model_Request_Token $model */
38
+ $model = Mage::getModel('ewayrapid/request_token');
39
+ return $model->checkCardName($card);
40
+ }
41
+
42
+ public function getSaveCard()
43
+ {
44
+ return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card');
45
+ }
46
+
47
+ public function getSaveText()
48
+ {
49
+ return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_text');
50
+ }
51
+
52
+ public function getSaveDefaultCheck()
53
+ {
54
+ return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card_checked');
55
+ }
56
+
57
+ public function checkSaveCardAvailable()
58
+ {
59
+ return Mage::helper('ewayrapid/customer')->getCurrentCustomer()
60
+ || Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER;
61
+ }
62
  }
app/code/community/Eway/Rapid31/Block/Form/Direct/Saved.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- class Eway_Rapid31_Block_Form_Direct_Saved extends Mage_Payment_Block_Form_Cc
3
- {
4
- protected function _construct()
5
- {
6
- parent::_construct();
7
- $this->setIsRecurring(Mage::helper('ewayrapid')->isRecurring());
8
- $this->setTemplate('ewayrapid/form/direct_saved.phtml');
9
- }
10
-
11
- /**
12
- * Get list of active tokens of current customer
13
- *
14
- * @return array
15
- */
16
- public function getTokenList()
17
- {
18
- $tokenList = array();
19
- $tokenList['tokens'] = Mage::helper('ewayrapid/customer')->getActiveTokenList();
20
- $tokenList['tokens'][Eway_Rapid31_Model_Config::TOKEN_NEW] =
21
- Mage::getModel('ewayrapid/customer_token')->setCard($this->__('Add new card'))->setOwner('')
22
- ->setExpMonth('')->setExpYear('');
23
- $tokenList['default_token'] = Mage::helper('ewayrapid/customer')->getDefaultToken();
24
-
25
- $tokenListJson = array();
26
- foreach($tokenList['tokens'] as $id => $token) {
27
- /* @var Eway_Rapid31_Model_Customer_Token $token */
28
- $tokenListJson[] = "\"{$id}\":{$token->jsonSerialize()}";
29
- }
30
- $tokenList['tokens_json'] = '{' . implode(',', $tokenListJson) . '}';
31
-
32
- return $tokenList;
33
- }
34
-
35
- public function checkCardName($card)
36
- {
37
- /* @var Eway_Rapid31_Model_Request_Token $model */
38
- $model = Mage::getModel('ewayrapid/request_token');
39
- return $model->checkCardName($card);
40
- }
41
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Form_Direct_Saved extends Mage_Payment_Block_Form_Cc
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setIsRecurring(Mage::helper('ewayrapid')->isRecurring());
8
+ $this->setTemplate('ewayrapid/form/direct_saved.phtml');
9
+ }
10
+
11
+ /**
12
+ * Get list of active tokens of current customer
13
+ *
14
+ * @return array
15
+ */
16
+ public function getTokenList()
17
+ {
18
+ $tokenList = array();
19
+ $tokenList['tokens'] = Mage::helper('ewayrapid/customer')->getActiveTokenList();
20
+ $tokenList['tokens'][Eway_Rapid31_Model_Config::TOKEN_NEW] =
21
+ Mage::getModel('ewayrapid/customer_token')->setCard($this->__('Add new card'))->setOwner('')
22
+ ->setExpMonth('')->setExpYear('');
23
+ $tokenList['default_token'] = Mage::helper('ewayrapid/customer')->getDefaultToken();
24
+
25
+ $tokenListJson = array();
26
+ foreach ($tokenList['tokens'] as $id => $token) {
27
+ /* @var Eway_Rapid31_Model_Customer_Token $token */
28
+ $tokenListJson[] = "\"{$id}\":{$token->jsonSerialize()}";
29
+ }
30
+ $tokenList['tokens_json'] = '{' . implode(',', $tokenListJson) . '}';
31
+
32
+ return $tokenList;
33
+ }
34
+
35
+ public function checkCardName($card)
36
+ {
37
+ /* @var Eway_Rapid31_Model_Request_Token $model */
38
+ $model = Mage::getModel('ewayrapid/request_token');
39
+ return $model->checkCardName($card);
40
+ }
41
  }
app/code/community/Eway/Rapid31/Block/Form/Sharedpage/Ewayone.php CHANGED
@@ -1,54 +1,58 @@
1
- <?php
2
- class Eway_Rapid31_Block_Form_Sharedpage_Ewayone extends Mage_Payment_Block_Form_Cc
3
- {
4
- protected function _construct()
5
- {
6
- parent::_construct();
7
- $this->setTemplate('ewayrapid/form/sharedpage_ewayone.phtml');
8
- // unset all session's sharedpage
9
- if(!Mage::app()->getRequest()->isPost()){
10
- Mage::helper('ewayrapid')->clearSessionSharedpage();
11
- }
12
- }
13
-
14
- /**
15
- * Get list of active tokens of current customer
16
- *
17
- * @return array
18
- */
19
- public function getTokenList()
20
- {
21
- $tokenList = array();
22
- $tokenList['tokens'] = Mage::helper('ewayrapid/customer')->getActiveTokenList();
23
- $tokenList['tokens'][Eway_Rapid31_Model_Config::TOKEN_NEW] =
24
- Mage::getModel('ewayrapid/customer_token')->setCard($this->__('Use a new card'))->setOwner('')
25
- ->setExpMonth('')->setExpYear('');
26
- $tokenList['default_token'] = Mage::helper('ewayrapid/customer')->getDefaultToken();
27
-
28
- $tokenListJson = array();
29
- foreach($tokenList['tokens'] as $id => $token) {
30
- /* @var Eway_Rapid31_Model_Customer_Token $token */
31
- $tokenListJson[] = "\"{$id}\":{$token->jsonSerialize()}";
32
- }
33
- $tokenList['tokens_json'] = '{' . implode(',', $tokenListJson) . '}';
34
-
35
- return $tokenList;
36
- }
37
-
38
- public function getSaveCard(){
39
- return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card');
40
- }
41
-
42
- public function getSaveText(){
43
- return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_text');
44
- }
45
-
46
- public function getSaveDefaultCheck(){
47
- return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card_checked');
48
- }
49
-
50
- public function checkSaveCardAvailable(){
51
- return Mage::helper('ewayrapid/customer')->getCurrentCustomer()
52
- || Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER;
53
- }
 
 
 
 
54
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Form_Sharedpage_Ewayone extends Mage_Payment_Block_Form_Cc
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('ewayrapid/form/sharedpage_ewayone.phtml');
8
+ // unset all session's sharedpage
9
+ if (!Mage::app()->getRequest()->isPost()) {
10
+ Mage::helper('ewayrapid')->clearSessionSharedpage();
11
+ }
12
+ }
13
+
14
+ /**
15
+ * Get list of active tokens of current customer
16
+ *
17
+ * @return array
18
+ */
19
+ public function getTokenList()
20
+ {
21
+ $tokenList = array();
22
+ $tokenList['tokens'] = Mage::helper('ewayrapid/customer')->getActiveTokenList();
23
+ $tokenList['tokens'][Eway_Rapid31_Model_Config::TOKEN_NEW] =
24
+ Mage::getModel('ewayrapid/customer_token')->setCard($this->__('Use a new card'))->setOwner('')
25
+ ->setExpMonth('')->setExpYear('');
26
+ $tokenList['default_token'] = Mage::helper('ewayrapid/customer')->getDefaultToken();
27
+
28
+ $tokenListJson = array();
29
+ foreach ($tokenList['tokens'] as $id => $token) {
30
+ /* @var Eway_Rapid31_Model_Customer_Token $token */
31
+ $tokenListJson[] = "\"{$id}\":{$token->jsonSerialize()}";
32
+ }
33
+ $tokenList['tokens_json'] = '{' . implode(',', $tokenListJson) . '}';
34
+
35
+ return $tokenList;
36
+ }
37
+
38
+ public function getSaveCard()
39
+ {
40
+ return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card');
41
+ }
42
+
43
+ public function getSaveText()
44
+ {
45
+ return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_text');
46
+ }
47
+
48
+ public function getSaveDefaultCheck()
49
+ {
50
+ return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card_checked');
51
+ }
52
+
53
+ public function checkSaveCardAvailable()
54
+ {
55
+ return Mage::helper('ewayrapid/customer')->getCurrentCustomer()
56
+ || Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER;
57
+ }
58
  }
app/code/community/Eway/Rapid31/Block/Form/Sharedpage/Notsaved.php CHANGED
@@ -1,13 +1,13 @@
1
- <?php
2
- class Eway_Rapid31_Block_Form_Sharedpage_Notsaved extends Mage_Payment_Block_Form_Cc
3
- {
4
- protected function _construct()
5
- {
6
- parent::_construct();
7
- $this->setTemplate('ewayrapid/form/sharedpage_notsaved.phtml');
8
- // unset all session's sharedpage
9
- if(!Mage::app()->getRequest()->isPost()){
10
- Mage::helper('ewayrapid')->clearSessionSharedpage();
11
- }
12
- }
13
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Form_Sharedpage_Notsaved extends Mage_Payment_Block_Form_Cc
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('ewayrapid/form/sharedpage_notsaved.phtml');
8
+ // unset all session's sharedpage
9
+ if (!Mage::app()->getRequest()->isPost()) {
10
+ Mage::helper('ewayrapid')->clearSessionSharedpage();
11
+ }
12
+ }
13
  }
app/code/community/Eway/Rapid31/Block/Form/Sharedpage/Saved.php CHANGED
@@ -1,35 +1,35 @@
1
- <?php
2
- class Eway_Rapid31_Block_Form_Sharedpage_Saved extends Mage_Payment_Block_Form_Cc
3
- {
4
- protected function _construct()
5
- {
6
- parent::_construct();
7
- $this->setTemplate('ewayrapid/form/sharedpage_saved.phtml');
8
- // unset all session's sharedpage
9
- Mage::helper('ewayrapid')->clearSessionSharedpage();
10
- }
11
-
12
- /**
13
- * Get list of active tokens of current customer
14
- *
15
- * @return array
16
- */
17
- public function getTokenList()
18
- {
19
- $tokenList = array();
20
- $tokenList['tokens'] = Mage::helper('ewayrapid/customer')->getActiveTokenList();
21
- $tokenList['tokens'][Eway_Rapid31_Model_Config::TOKEN_NEW] =
22
- Mage::getModel('ewayrapid/customer_token')->setCard($this->__('Add new card'))->setOwner('')
23
- ->setExpMonth('')->setExpYear('');
24
- $tokenList['default_token'] = Mage::helper('ewayrapid/customer')->getDefaultToken();
25
-
26
- $tokenListJson = array();
27
- foreach($tokenList['tokens'] as $id => $token) {
28
- /* @var Eway_Rapid31_Model_Customer_Token $token */
29
- $tokenListJson[] = "\"{$id}\":{$token->jsonSerialize()}";
30
- }
31
- $tokenList['tokens_json'] = '{' . implode(',', $tokenListJson) . '}';
32
-
33
- return $tokenList;
34
- }
35
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Form_Sharedpage_Saved extends Mage_Payment_Block_Form_Cc
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('ewayrapid/form/sharedpage_saved.phtml');
8
+ // unset all session's sharedpage
9
+ Mage::helper('ewayrapid')->clearSessionSharedpage();
10
+ }
11
+
12
+ /**
13
+ * Get list of active tokens of current customer
14
+ *
15
+ * @return array
16
+ */
17
+ public function getTokenList()
18
+ {
19
+ $tokenList = array();
20
+ $tokenList['tokens'] = Mage::helper('ewayrapid/customer')->getActiveTokenList();
21
+ $tokenList['tokens'][Eway_Rapid31_Model_Config::TOKEN_NEW] =
22
+ Mage::getModel('ewayrapid/customer_token')->setCard($this->__('Add new card'))->setOwner('')
23
+ ->setExpMonth('')->setExpYear('');
24
+ $tokenList['default_token'] = Mage::helper('ewayrapid/customer')->getDefaultToken();
25
+
26
+ $tokenListJson = array();
27
+ foreach ($tokenList['tokens'] as $id => $token) {
28
+ /* @var Eway_Rapid31_Model_Customer_Token $token */
29
+ $tokenListJson[] = "\"{$id}\":{$token->jsonSerialize()}";
30
+ }
31
+ $tokenList['tokens_json'] = '{' . implode(',', $tokenListJson) . '}';
32
+
33
+ return $tokenList;
34
+ }
35
  }
app/code/community/Eway/Rapid31/Block/Form/Transparent/Ewayone.php CHANGED
@@ -72,19 +72,23 @@ class Eway_Rapid31_Block_Form_Transparent_Ewayone extends Mage_Payment_Block_For
72
  return $model->checkCardName($card);
73
  }
74
 
75
- public function getSaveCard(){
 
76
  return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card');
77
  }
78
 
79
- public function getSaveText(){
 
80
  return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_text');
81
  }
82
 
83
- public function getSaveDefaultCheck(){
 
84
  return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card_checked');
85
  }
86
 
87
- public function checkSaveCardAvailable(){
 
88
  return Mage::helper('ewayrapid/customer')->getCurrentCustomer()
89
  || Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER;
90
  }
72
  return $model->checkCardName($card);
73
  }
74
 
75
+ public function getSaveCard()
76
+ {
77
  return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card');
78
  }
79
 
80
+ public function getSaveText()
81
+ {
82
  return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_text');
83
  }
84
 
85
+ public function getSaveDefaultCheck()
86
+ {
87
  return Mage::getStoreConfig('payment/ewayrapid_ewayone/save_card_checked');
88
  }
89
 
90
+ public function checkSaveCardAvailable()
91
+ {
92
  return Mage::helper('ewayrapid/customer')->getCurrentCustomer()
93
  || Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER;
94
  }
app/code/community/Eway/Rapid31/Block/Html/Head.php CHANGED
@@ -62,7 +62,8 @@ class Eway_Rapid31_Block_Html_Head extends Mage_Adminhtml_Block_Page_Head
62
  $href = $itemName;
63
  switch ($itemType) {
64
  case 'rss':
65
- $lines[$itemIf]['other'][] = sprintf('<link href="%s"%s rel="alternate" type="application/rss+xml" />',
 
66
  $href, $params
67
  );
68
  break;
62
  $href = $itemName;
63
  switch ($itemType) {
64
  case 'rss':
65
+ $lines[$itemIf]['other'][] = sprintf(
66
+ '<link href="%s"%s rel="alternate" type="application/rss+xml" />',
67
  $href, $params
68
  );
69
  break;
app/code/community/Eway/Rapid31/Block/Info/Direct/Ewayone.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- class Eway_Rapid31_Block_Info_Direct_Ewayone extends Mage_Payment_Block_Info
3
- {
4
- protected function _construct()
5
- {
6
- parent::_construct();
7
- $this->setTemplate('ewayrapid/info/direct_ewayone.phtml');
8
- }
9
-
10
- /**
11
- * Render as PDF
12
- *
13
- * @return string
14
- */
15
- public function toPdf()
16
- {
17
- $this->setTemplate('ewayrapid/pdf/direct_notsaved.phtml');
18
- return $this->toHtml();
19
- }
20
-
21
-
22
- /**
23
- * Get eWAY Customer Token Id of this transaction
24
- *
25
- * @return string
26
- */
27
- public function getTokenId()
28
- {
29
- $info = $this->getInfo();
30
- /* @var Mage_Sales_Model_Order_Payment $info */
31
- $order = $info->getOrder();
32
- if($order->getCustomerIsGuest()) {
33
- return '';
34
- }
35
-
36
- Mage::helper('ewayrapid')->unserializeInfoInstace($info);
37
- if(!$info->getSavedToken()) {
38
- return '';
39
- }
40
-
41
- $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
42
- $helper = Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
43
- return $helper->getCustomerTokenId($info->getSavedToken());
44
- }
45
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Info_Direct_Ewayone extends Mage_Payment_Block_Info
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('ewayrapid/info/direct_ewayone.phtml');
8
+ }
9
+
10
+ /**
11
+ * Render as PDF
12
+ *
13
+ * @return string
14
+ */
15
+ public function toPdf()
16
+ {
17
+ $this->setTemplate('ewayrapid/pdf/direct_notsaved.phtml');
18
+ return $this->toHtml();
19
+ }
20
+
21
+
22
+ /**
23
+ * Get eWAY Customer Token Id of this transaction
24
+ *
25
+ * @return string
26
+ */
27
+ public function getTokenId()
28
+ {
29
+ $info = $this->getInfo();
30
+ /* @var Mage_Sales_Model_Order_Payment $info */
31
+ $order = $info->getOrder();
32
+ if ($order->getCustomerIsGuest()) {
33
+ return '';
34
+ }
35
+
36
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
37
+ if (!$info->getSavedToken()) {
38
+ return '';
39
+ }
40
+
41
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
42
+ $helper = Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
43
+ return $helper->getCustomerTokenId($info->getSavedToken());
44
+ }
45
  }
app/code/community/Eway/Rapid31/Block/Info/Direct/Saved.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- class Eway_Rapid31_Block_Info_Direct_Saved extends Mage_Payment_Block_Info
3
- {
4
- protected function _construct()
5
- {
6
- parent::_construct();
7
- $this->setTemplate('ewayrapid/info/direct_saved.phtml');
8
- }
9
-
10
- /**
11
- * Render as PDF
12
- *
13
- * @return string
14
- */
15
- public function toPdf()
16
- {
17
- $this->setTemplate('ewayrapid/pdf/direct_notsaved.phtml');
18
- return $this->toHtml();
19
- }
20
-
21
-
22
- /**
23
- * Get eWAY Customer Token Id of this transaction
24
- *
25
- * @return string
26
- */
27
- public function getTokenId()
28
- {
29
- $info = $this->getInfo();
30
- /* @var Mage_Sales_Model_Order_Payment $info */
31
- $order = $info->getOrder();
32
- if($order->getCustomerIsGuest()) {
33
- return '';
34
- }
35
-
36
- Mage::helper('ewayrapid')->unserializeInfoInstace($info);
37
- if(!$info->getSavedToken()) {
38
- return '';
39
- }
40
-
41
- $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
42
- $helper = Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
43
- return $helper->getCustomerTokenId($info->getSavedToken());
44
- }
45
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Info_Direct_Saved extends Mage_Payment_Block_Info
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('ewayrapid/info/direct_saved.phtml');
8
+ }
9
+
10
+ /**
11
+ * Render as PDF
12
+ *
13
+ * @return string
14
+ */
15
+ public function toPdf()
16
+ {
17
+ $this->setTemplate('ewayrapid/pdf/direct_notsaved.phtml');
18
+ return $this->toHtml();
19
+ }
20
+
21
+
22
+ /**
23
+ * Get eWAY Customer Token Id of this transaction
24
+ *
25
+ * @return string
26
+ */
27
+ public function getTokenId()
28
+ {
29
+ $info = $this->getInfo();
30
+ /* @var Mage_Sales_Model_Order_Payment $info */
31
+ $order = $info->getOrder();
32
+ if ($order->getCustomerIsGuest()) {
33
+ return '';
34
+ }
35
+
36
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
37
+ if (!$info->getSavedToken()) {
38
+ return '';
39
+ }
40
+
41
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
42
+ $helper = Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
43
+ return $helper->getCustomerTokenId($info->getSavedToken());
44
+ }
45
  }
app/code/community/Eway/Rapid31/Block/Info/Sharedpage/Ewayone.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- class Eway_Rapid31_Block_Info_Sharedpage_Ewayone extends Mage_Payment_Block_Info
3
- {
4
- protected function _construct()
5
- {
6
- parent::_construct();
7
- $this->setTemplate('ewayrapid/info/sharedpage_saved.phtml');
8
- }
9
-
10
- /**
11
- * Render as PDF
12
- *
13
- * @return string
14
- */
15
- public function toPdf()
16
- {
17
- $this->setTemplate('ewayrapid/pdf/direct_notsaved.phtml');
18
- return $this->toHtml();
19
- }
20
-
21
-
22
- /**
23
- * Get eWAY Customer Token Id of this transaction
24
- *
25
- * @return string
26
- */
27
- public function getTokenId()
28
- {
29
- $info = $this->getInfo();
30
- /* @var Mage_Sales_Model_Order_Payment $info */
31
- $order = $info->getOrder();
32
- if($order->getCustomerIsGuest()) {
33
- return '';
34
- }
35
-
36
- Mage::helper('ewayrapid')->unserializeInfoInstace($info);
37
- if(!$info->getSavedToken()) {
38
- return '';
39
- }
40
-
41
- $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
42
- $helper = Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
43
- return $helper->getCustomerTokenId($info->getSavedToken());
44
- }
45
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Info_Sharedpage_Ewayone extends Mage_Payment_Block_Info
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('ewayrapid/info/sharedpage_saved.phtml');
8
+ }
9
+
10
+ /**
11
+ * Render as PDF
12
+ *
13
+ * @return string
14
+ */
15
+ public function toPdf()
16
+ {
17
+ $this->setTemplate('ewayrapid/pdf/direct_notsaved.phtml');
18
+ return $this->toHtml();
19
+ }
20
+
21
+
22
+ /**
23
+ * Get eWAY Customer Token Id of this transaction
24
+ *
25
+ * @return string
26
+ */
27
+ public function getTokenId()
28
+ {
29
+ $info = $this->getInfo();
30
+ /* @var Mage_Sales_Model_Order_Payment $info */
31
+ $order = $info->getOrder();
32
+ if ($order->getCustomerIsGuest()) {
33
+ return '';
34
+ }
35
+
36
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
37
+ if (!$info->getSavedToken()) {
38
+ return '';
39
+ }
40
+
41
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
42
+ $helper = Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
43
+ return $helper->getCustomerTokenId($info->getSavedToken());
44
+ }
45
  }
app/code/community/Eway/Rapid31/Block/Info/Sharedpage/Saved.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- class Eway_Rapid31_Block_Info_Sharedpage_Saved extends Mage_Payment_Block_Info
3
- {
4
- protected function _construct()
5
- {
6
- parent::_construct();
7
- $this->setTemplate('ewayrapid/info/sharedpage_saved.phtml');
8
- }
9
-
10
- /**
11
- * Render as PDF
12
- *
13
- * @return string
14
- */
15
- public function toPdf()
16
- {
17
- $this->setTemplate('ewayrapid/pdf/direct_notsaved.phtml');
18
- return $this->toHtml();
19
- }
20
-
21
-
22
- /**
23
- * Get eWAY Customer Token Id of this transaction
24
- *
25
- * @return string
26
- */
27
- public function getTokenId()
28
- {
29
- $info = $this->getInfo();
30
- /* @var Mage_Sales_Model_Order_Payment $info */
31
- $order = $info->getOrder();
32
- if($order->getCustomerIsGuest()) {
33
- return '';
34
- }
35
-
36
- Mage::helper('ewayrapid')->unserializeInfoInstace($info);
37
- if(!$info->getSavedToken()) {
38
- return '';
39
- }
40
-
41
- $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
42
- $helper = Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
43
- return $helper->getCustomerTokenId($info->getSavedToken());
44
- }
45
  }
1
+ <?php
2
+ class Eway_Rapid31_Block_Info_Sharedpage_Saved extends Mage_Payment_Block_Info
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('ewayrapid/info/sharedpage_saved.phtml');
8
+ }
9
+
10
+ /**
11
+ * Render as PDF
12
+ *
13
+ * @return string
14
+ */
15
+ public function toPdf()
16
+ {
17
+ $this->setTemplate('ewayrapid/pdf/direct_notsaved.phtml');
18
+ return $this->toHtml();
19
+ }
20
+
21
+
22
+ /**
23
+ * Get eWAY Customer Token Id of this transaction
24
+ *
25
+ * @return string
26
+ */
27
+ public function getTokenId()
28
+ {
29
+ $info = $this->getInfo();
30
+ /* @var Mage_Sales_Model_Order_Payment $info */
31
+ $order = $info->getOrder();
32
+ if ($order->getCustomerIsGuest()) {
33
+ return '';
34
+ }
35
+
36
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
37
+ if (!$info->getSavedToken()) {
38
+ return '';
39
+ }
40
+
41
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
42
+ $helper = Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
43
+ return $helper->getCustomerTokenId($info->getSavedToken());
44
+ }
45
  }
app/code/community/Eway/Rapid31/Block/Redirect/PaypalReview.php CHANGED
@@ -49,9 +49,11 @@ class Eway_Rapid31_Block_Redirect_PaypalReview extends Mage_Core_Block_Template
49
  $postCode = $this->_quote->getShippingAddress()
50
  ->getPostcode();
51
  if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
52
- $sharedpageModel = Mage::getModel('ewayrapid/request_sharedpage', array(
 
53
  'quote' => $this->_quote
54
- ));
 
55
  return $sharedpageModel->getShippingByCode($postCode);
56
  } elseif (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
57
  $transModel = Mage::getModel('ewayrapid/request_transparent');
49
  $postCode = $this->_quote->getShippingAddress()
50
  ->getPostcode();
51
  if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
52
+ $sharedpageModel = Mage::getModel(
53
+ 'ewayrapid/request_sharedpage', array(
54
  'quote' => $this->_quote
55
+ )
56
+ );
57
  return $sharedpageModel->getShippingByCode($postCode);
58
  } elseif (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
59
  $transModel = Mage::getModel('ewayrapid/request_transparent');
app/code/community/Eway/Rapid31/Block/Redirect/Transparent.php CHANGED
@@ -1,84 +1,84 @@
1
- <?php
2
-
3
- class Eway_Rapid31_Block_Redirect_Transparent extends Mage_Core_Block_Template
4
- {
5
- protected $methodPayment;
6
- protected $transMethod;
7
- protected $paypalSavedToken;
8
- protected $savedToken;
9
-
10
- public function _construct()
11
- {
12
- $this->methodPayment = Mage::getSingleton('core/session')->getMethod();
13
- $this->transMethod = Mage::getSingleton('core/session')->getTransparentNotsaved();
14
- if (!$this->transMethod) {
15
- $this->transMethod = Mage::getSingleton('core/session')->getTransparentSaved();
16
- }
17
-
18
- if ($this->methodPayment == 'ewayrapid_saved' || $this->methodPayment == 'ewayrapid_ewayone') {
19
- if ($this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
20
- $this->paypalSavedToken = Mage::getSingleton('core/session')->getPaypalSavedToken();
21
- } else {
22
- $this->savedToken = Mage::getSingleton('core/session')->getSavedToken();
23
- }
24
- }
25
-
26
- $this->setTemplate('ewayrapid/redirect/transparent.phtml')->toHtml();
27
- }
28
-
29
- /**
30
- * Retrieve credit card expire months
31
- *
32
- * @return array
33
- */
34
- public function getCcMonths()
35
- {
36
- $months = $this->getData('cc_months');
37
- if (is_null($months)) {
38
- $months[0] = $this->__('Month');
39
- $months = array_merge($months, Mage::getSingleton('payment/config')->getMonths());
40
- $this->setData('cc_months', $months);
41
- }
42
- return $months;
43
- }
44
-
45
- /**
46
- * Retrieve credit card expire years
47
- *
48
- * @return array
49
- */
50
- public function getCcYears()
51
- {
52
- $years = $this->getData('cc_years');
53
- if (is_null($years)) {
54
- $years = Mage::getSingleton('payment/config')->getYears();
55
- $years = array(0 => $this->__('Year')) + $years;
56
- $this->setData('cc_years', $years);
57
- }
58
- return $years;
59
- }
60
-
61
- /**
62
- * Get New Shipping from items
63
- * @return int
64
- */
65
- public function getNewShippingTotal()
66
- {
67
- $totalItem = 0;
68
- foreach ($this->_getQuote()->getAllVisibleItems() as $item) {
69
- $totalItem += $item->getQty();
70
- }
71
- return $totalItem;
72
- }
73
-
74
- /**
75
- * Check if CVN is required or not
76
- *
77
- * @return bool
78
- */
79
- public function hasVerification()
80
- {
81
- // No need for CVN in creating/updating token
82
- return Mage::getModel('ewayrapid/method_notsaved')->hasVerification();
83
- }
84
  }
1
+ <?php
2
+
3
+ class Eway_Rapid31_Block_Redirect_Transparent extends Mage_Core_Block_Template
4
+ {
5
+ protected $_methodPayment;
6
+ protected $_transMethod;
7
+ protected $_paypalSavedToken;
8
+ protected $_savedToken;
9
+
10
+ public function _construct()
11
+ {
12
+ $this->_methodPayment = Mage::getSingleton('core/session')->getMethod();
13
+ $this->_transMethod = Mage::getSingleton('core/session')->getTransparentNotsaved();
14
+ if (!$this->_transMethod) {
15
+ $this->_transMethod = Mage::getSingleton('core/session')->getTransparentSaved();
16
+ }
17
+
18
+ if ($this->_methodPayment == 'ewayrapid_saved' || $this->_methodPayment == 'ewayrapid_ewayone') {
19
+ if ($this->_transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
20
+ $this->_paypalSavedToken = Mage::getSingleton('core/session')->getPaypalSavedToken();
21
+ } else {
22
+ $this->_savedToken = Mage::getSingleton('core/session')->getSavedToken();
23
+ }
24
+ }
25
+
26
+ $this->setTemplate('ewayrapid/redirect/transparent.phtml')->toHtml();
27
+ }
28
+
29
+ /**
30
+ * Retrieve credit card expire months
31
+ *
32
+ * @return array
33
+ */
34
+ public function getCcMonths()
35
+ {
36
+ $months = $this->getData('cc_months');
37
+ if (is_null($months)) {
38
+ $months[0] = $this->__('Month');
39
+ $months = array_merge($months, Mage::getSingleton('payment/config')->getMonths());
40
+ $this->setData('cc_months', $months);
41
+ }
42
+ return $months;
43
+ }
44
+
45
+ /**
46
+ * Retrieve credit card expire years
47
+ *
48
+ * @return array
49
+ */
50
+ public function getCcYears()
51
+ {
52
+ $years = $this->getData('cc_years');
53
+ if (is_null($years)) {
54
+ $years = Mage::getSingleton('payment/config')->getYears();
55
+ $years = array(0 => $this->__('Year')) + $years;
56
+ $this->setData('cc_years', $years);
57
+ }
58
+ return $years;
59
+ }
60
+
61
+ /**
62
+ * Get New Shipping from items
63
+ * @return int
64
+ */
65
+ public function getNewShippingTotal()
66
+ {
67
+ $totalItem = 0;
68
+ foreach ($this->_getQuote()->getAllVisibleItems() as $item) {
69
+ $totalItem += $item->getQty();
70
+ }
71
+ return $totalItem;
72
+ }
73
+
74
+ /**
75
+ * Check if CVN is required or not
76
+ *
77
+ * @return bool
78
+ */
79
+ public function hasVerification()
80
+ {
81
+ // No need for CVN in creating/updating token
82
+ return Mage::getModel('ewayrapid/method_notsaved')->hasVerification();
83
+ }
84
  }
app/code/community/Eway/Rapid31/Block/Redirect/TransparentCheckout.php CHANGED
@@ -1,55 +1,55 @@
1
- <?php
2
-
3
- class Eway_Rapid31_Block_Redirect_TransparentCheckout extends Mage_Core_Block_Template
4
- {
5
- protected $methodPayment;
6
- protected $transMethod;
7
-
8
- public function _construct()
9
- {
10
- $this->methodPayment = Mage::getSingleton('core/session')->getMethod();
11
- $this->transMethod = Mage::getSingleton('core/session')->getTransparentNotsaved();
12
- if(!$this->transMethod) {
13
- $this->transMethod = Mage::getSingleton('core/session')->getTransparentSaved();
14
- }
15
- $this->setTemplate('ewayrapid/redirect/transparent_checkout.phtml')->toHtml();
16
- }
17
-
18
- /**
19
- * Retrieve credit card expire months
20
- *
21
- * @return array
22
- */
23
- public function getCcMonths()
24
- {
25
- $months = $this->getData('cc_months');
26
- if (is_null($months)) {
27
- $months[0] = $this->__('Month');
28
- $months = array_merge($months, Mage::getSingleton('payment/config')->getMonths());
29
- $this->setData('cc_months', $months);
30
- }
31
- return $months;
32
- }
33
-
34
- /**
35
- * Retrieve credit card expire years
36
- *
37
- * @return array
38
- */
39
- public function getCcYears()
40
- {
41
- $years = $this->getData('cc_years');
42
- if (is_null($years)) {
43
- $years = Mage::getSingleton('payment/config')->getYears();
44
- $years = array(0 => $this->__('Year')) + $years;
45
- $this->setData('cc_years', $years);
46
- }
47
- return $years;
48
- }
49
-
50
- public function getEnableVisaCheckout()
51
- {
52
- $_config = Mage::getSingleton('ewayrapid/config');
53
- return $_config->getVisaCheckoutEnable();
54
- }
55
  }
1
+ <?php
2
+
3
+ class Eway_Rapid31_Block_Redirect_TransparentCheckout extends Mage_Core_Block_Template
4
+ {
5
+ protected $_methodPayment;
6
+ protected $_transMethod;
7
+
8
+ public function _construct()
9
+ {
10
+ $this->_methodPayment = Mage::getSingleton('core/session')->getMethod();
11
+ $this->_transMethod = Mage::getSingleton('core/session')->getTransparentNotsaved();
12
+ if (!$this->_transMethod) {
13
+ $this->_transMethod = Mage::getSingleton('core/session')->getTransparentSaved();
14
+ }
15
+ $this->setTemplate('ewayrapid/redirect/transparent_checkout.phtml')->toHtml();
16
+ }
17
+
18
+ /**
19
+ * Retrieve credit card expire months
20
+ *
21
+ * @return array
22
+ */
23
+ public function getCcMonths()
24
+ {
25
+ $months = $this->getData('cc_months');
26
+ if (is_null($months)) {
27
+ $months[0] = $this->__('Month');
28
+ $months = array_merge($months, Mage::getSingleton('payment/config')->getMonths());
29
+ $this->setData('cc_months', $months);
30
+ }
31
+ return $months;
32
+ }
33
+
34
+ /**
35
+ * Retrieve credit card expire years
36
+ *
37
+ * @return array
38
+ */
39
+ public function getCcYears()
40
+ {
41
+ $years = $this->getData('cc_years');
42
+ if (is_null($years)) {
43
+ $years = Mage::getSingleton('payment/config')->getYears();
44
+ $years = array(0 => $this->__('Year')) + $years;
45
+ $this->setData('cc_years', $years);
46
+ }
47
+ return $years;
48
+ }
49
+
50
+ public function getEnableVisaCheckout()
51
+ {
52
+ $_config = Mage::getSingleton('ewayrapid/config');
53
+ return $_config->getVisaCheckoutEnable();
54
+ }
55
  }
app/code/community/Eway/Rapid31/Block/Sales/Order/Grid.php CHANGED
@@ -2,7 +2,8 @@
2
  /**
3
  *
4
  */
5
- class Eway_Rapid31_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid {
 
6
 
7
  protected function _prepareMassaction()
8
  {
2
  /**
3
  *
4
  */
5
+ class Eway_Rapid31_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
6
+ {
7
 
8
  protected function _prepareMassaction()
9
  {
app/code/community/Eway/Rapid31/Helper/Customer.php CHANGED
@@ -1,243 +1,243 @@
1
- <?php
2
- class Eway_Rapid31_Helper_Customer extends Mage_Core_Helper_Abstract
3
- {
4
- private $_currentCustomer = false;
5
-
6
- public function __construct()
7
- {
8
- $this->setCurrentCustomer($this->_getCurrentCustomer());
9
- }
10
-
11
- /**
12
- * @return Mage_Customer_Model_Customer
13
- */
14
- public function getCurrentCustomer()
15
- {
16
- if(!$this->_currentCustomer) {
17
- $this->_currentCustomer = $this->_getCurrentCustomer();
18
- }
19
-
20
- return $this->_currentCustomer;
21
- }
22
-
23
- /**
24
- * @param Mage_Customer_Model_Customer $value
25
- * @return $this
26
- */
27
- public function setCurrentCustomer($value)
28
- {
29
- $this->_currentCustomer = $value;
30
- return $this;
31
- }
32
-
33
- /**
34
- * Get current logged in customer (frontend) or chosen customer to create order (backend)
35
- *
36
- * @return bool|Mage_Customer_Model_Customer
37
- */
38
- protected function _getCurrentCustomer()
39
- {
40
- if(Mage::helper('ewayrapid')->isBackendOrder()){
41
- if(Mage::registry('current_customer')){
42
- return Mage::registry('current_customer');
43
- }elseif($this->_getRequest()->getParam('customer_id')){
44
- return Mage::getModel('customer/customer')->load($this->_getRequest()->getParam('customer_id'));
45
- }
46
- }
47
-
48
- if(Mage::helper('ewayrapid')->isBackendOrder() && Mage::getSingleton('adminhtml/session_quote')->getCustomer()) {
49
- return Mage::getSingleton('adminhtml/session_quote')->getCustomer();
50
- }
51
-
52
- if(Mage::getSingleton('customer/session')->isLoggedIn()) {
53
- return Mage::getSingleton('customer/session')->getCustomer();
54
- }
55
-
56
- if(($quote = Mage::getSingleton('checkout/session')->getQuote()) && ($customer = $quote->getCustomer()) && $customer->getId()) {
57
- return $customer;
58
- }
59
-
60
- return false;
61
- }
62
-
63
- /**
64
- * Get eWAY Customer Token Id
65
- *
66
- * @param $id
67
- * @return mixed
68
- */
69
- public function getCustomerTokenId($id)
70
- {
71
- return $this->getTokenById($id)->getToken() ? $this->getTokenById($id)->getToken() : $this->getTokenById($id)->getTokenCustomerID();
72
- }
73
-
74
- /**
75
- * Get token object by id (id used in Magento, not Customer Token Id)
76
- *
77
- * @param $id
78
- * @return Eway_Rapid31_Model_Customer_Token
79
- */
80
- public function getTokenById($id)
81
- {
82
- $customer = $this->getCurrentCustomer();
83
- if($customer && $customer->getSavedTokens()) {
84
- return $customer->getSavedTokens()->getTokenById($id);
85
- } else {
86
- Mage::throwException($this->__('Customer does not have any saved token.'));
87
- }
88
- }
89
-
90
- /**
91
- * Get last token id of this customer
92
- *
93
- * @return bool | int
94
- */
95
- public function getLastTokenId()
96
- {
97
- $customer = $this->getCurrentCustomer();
98
- if($customer && $customer->getSavedTokens()) {
99
- return $customer->getSavedTokens()->getLastId();
100
- }
101
-
102
- return false;
103
- }
104
-
105
- /**
106
- * Add new token to customer's token list
107
- *
108
- * @param $info array
109
- */
110
- public function addToken($info)
111
- {
112
- $customer = $this->getCurrentCustomer();
113
- if($customer) {
114
- $savedTokens = $customer->getSavedTokens();
115
- if(!$savedTokens) {
116
- $savedTokens = Mage::getModel('ewayrapid/customer_savedtokens');
117
- }
118
-
119
- $savedTokens->addToken($info);
120
- $customer->setSavedTokens($savedTokens);
121
-
122
- // Only save existed customer, new customer will be saved by Magento.
123
- if($customer->getId()) {
124
- $customer->save();
125
- }
126
- }
127
- }
128
-
129
- /**
130
- * Update token identified by id (id used in Magento, not Customer Token Id)
131
- *
132
- * @param int $id
133
- * @param $info
134
- */
135
- public function updateToken($id, $info)
136
- {
137
- $this->getTokenById($id)->addData($info);
138
- $this->getCurrentCustomer()->setDataChanges(true)->save();
139
- }
140
-
141
- /**
142
- * Delete token identified by id (id used in Magento, not Customer Token Id)
143
- *
144
- * @param int $id
145
- */
146
- public function deleteToken($id)
147
- {
148
- $this->updateToken($id, array('Active' => 0));
149
- }
150
-
151
- /**
152
- * Set token identified by id as default token (id used in Magento, not Customer Token Id)
153
- *
154
- * @param int $id
155
- */
156
- public function setDefaultToken($id)
157
- {
158
- // Check if token is existed.
159
- $this->getTokenById($id);
160
- $this->getCurrentCustomer()->getSavedTokens()->setDefaultToken($id);
161
- $this->getCurrentCustomer()->setDataChanges(true)->save();
162
- }
163
-
164
- /**
165
- * Get default token id
166
- *
167
- * @return bool | int
168
- */
169
- public function getDefaultToken()
170
- {
171
- $customer = $this->getCurrentCustomer();
172
- if($customer && $customer->getSavedTokens()) {
173
- return $customer->getSavedTokens()->getDefaultToken();
174
- }
175
-
176
- return false;
177
- }
178
-
179
- /**
180
- * Get active token list of current customer
181
- *
182
- * @return array
183
- */
184
- public function getActiveTokenList()
185
- {
186
- $customer = $this->getCurrentCustomer();
187
- if($customer && $customer->getSavedTokens()) {
188
- $tokens = $customer->getSavedTokens()->getTokens();
189
- if(is_array($tokens)) {
190
- foreach($tokens as $key => $token) {
191
- /* @var Eway_Rapid31_Model_Customer_Token $token */
192
- if(!$token->getActive()) {
193
- unset($tokens[$key]);
194
- } else {
195
- $token->unsetData('Token');
196
- }
197
- }
198
- return $tokens;
199
- }
200
- }
201
-
202
- return array();
203
- }
204
-
205
- /**
206
- * Get active token list of current customer
207
- *
208
- * @return array
209
- */
210
- public function checkTokenListByType($type = Eway_Rapid31_Model_Config::CREDITCARD_METHOD)
211
- {
212
- $customer = $this->getCurrentCustomer();
213
- if($customer && $customer->getSavedTokens()) {
214
- $tokens = $customer->getSavedTokens()->getTokens();
215
- if(is_array($tokens)) {
216
- foreach($tokens as $key => $token) {
217
- /* @var Eway_Rapid31_Model_Customer_Token $token */
218
- if(!$token->getActive()) {
219
- unset($tokens[$key]);
220
- } else {
221
- $token->unsetData('Token');
222
- }
223
-
224
- if($token->getCard() && $type == Eway_Rapid31_Model_Config::CREDITCARD_METHOD) {
225
- if (preg_match('/^'.Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD.'/', strtolower($token->getCard()))) {
226
- unset($tokens[$key]);
227
- }
228
- if (preg_match('/^mc/', strtolower($token->getCard()))) {
229
- unset($tokens[$key]);
230
- }
231
- } elseif($token->getCard()) {
232
- if (!preg_match('/^'.$type.'/', strtolower($token->getCard()))) {
233
- unset($tokens[$key]);
234
- }
235
- }
236
- }
237
- return $tokens;
238
- }
239
- }
240
-
241
- return array();
242
- }
243
  }
1
+ <?php
2
+ class Eway_Rapid31_Helper_Customer extends Mage_Core_Helper_Abstract
3
+ {
4
+ private $_currentCustomer = false;
5
+
6
+ public function __construct()
7
+ {
8
+ $this->setCurrentCustomer($this->_getCurrentCustomer());
9
+ }
10
+
11
+ /**
12
+ * @return Mage_Customer_Model_Customer
13
+ */
14
+ public function getCurrentCustomer()
15
+ {
16
+ if (!$this->_currentCustomer) {
17
+ $this->_currentCustomer = $this->_getCurrentCustomer();
18
+ }
19
+
20
+ return $this->_currentCustomer;
21
+ }
22
+
23
+ /**
24
+ * @param Mage_Customer_Model_Customer $value
25
+ * @return $this
26
+ */
27
+ public function setCurrentCustomer($value)
28
+ {
29
+ $this->_currentCustomer = $value;
30
+ return $this;
31
+ }
32
+
33
+ /**
34
+ * Get current logged in customer (frontend) or chosen customer to create order (backend)
35
+ *
36
+ * @return bool|Mage_Customer_Model_Customer
37
+ */
38
+ protected function _getCurrentCustomer()
39
+ {
40
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
41
+ if (Mage::registry('current_customer')) {
42
+ return Mage::registry('current_customer');
43
+ } elseif ($this->_getRequest()->getParam('customer_id')) {
44
+ return Mage::getModel('customer/customer')->load($this->_getRequest()->getParam('customer_id'));
45
+ }
46
+ }
47
+
48
+ if (Mage::helper('ewayrapid')->isBackendOrder() && Mage::getSingleton('adminhtml/session_quote')->getCustomer()) {
49
+ return Mage::getSingleton('adminhtml/session_quote')->getCustomer();
50
+ }
51
+
52
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
53
+ return Mage::getSingleton('customer/session')->getCustomer();
54
+ }
55
+
56
+ if (($quote = Mage::getSingleton('checkout/session')->getQuote()) && ($customer = $quote->getCustomer()) && $customer->getId()) {
57
+ return $customer;
58
+ }
59
+
60
+ return false;
61
+ }
62
+
63
+ /**
64
+ * Get eWAY Customer Token Id
65
+ *
66
+ * @param $id
67
+ * @return mixed
68
+ */
69
+ public function getCustomerTokenId($id)
70
+ {
71
+ return $this->getTokenById($id)->getToken() ? $this->getTokenById($id)->getToken() : $this->getTokenById($id)->getTokenCustomerID();
72
+ }
73
+
74
+ /**
75
+ * Get token object by id (id used in Magento, not Customer Token Id)
76
+ *
77
+ * @param $id
78
+ * @return Eway_Rapid31_Model_Customer_Token
79
+ */
80
+ public function getTokenById($id)
81
+ {
82
+ $customer = $this->getCurrentCustomer();
83
+ if ($customer && $customer->getSavedTokens()) {
84
+ return $customer->getSavedTokens()->getTokenById($id);
85
+ } else {
86
+ Mage::throwException($this->__('Customer does not have any saved token.'));
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Get last token id of this customer
92
+ *
93
+ * @return bool | int
94
+ */
95
+ public function getLastTokenId()
96
+ {
97
+ $customer = $this->getCurrentCustomer();
98
+ if ($customer && $customer->getSavedTokens()) {
99
+ return $customer->getSavedTokens()->getLastId();
100
+ }
101
+
102
+ return false;
103
+ }
104
+
105
+ /**
106
+ * Add new token to customer's token list
107
+ *
108
+ * @param $info array
109
+ */
110
+ public function addToken($info)
111
+ {
112
+ $customer = $this->getCurrentCustomer();
113
+ if ($customer) {
114
+ $savedTokens = $customer->getSavedTokens();
115
+ if (!$savedTokens) {
116
+ $savedTokens = Mage::getModel('ewayrapid/customer_savedtokens');
117
+ }
118
+
119
+ $savedTokens->addToken($info);
120
+ $customer->setSavedTokens($savedTokens);
121
+
122
+ // Only save existed customer, new customer will be saved by Magento.
123
+ if ($customer->getId()) {
124
+ $customer->save();
125
+ }
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Update token identified by id (id used in Magento, not Customer Token Id)
131
+ *
132
+ * @param int $id
133
+ * @param $info
134
+ */
135
+ public function updateToken($id, $info)
136
+ {
137
+ $this->getTokenById($id)->addData($info);
138
+ $this->getCurrentCustomer()->setDataChanges(true)->save();
139
+ }
140
+
141
+ /**
142
+ * Delete token identified by id (id used in Magento, not Customer Token Id)
143
+ *
144
+ * @param int $id
145
+ */
146
+ public function deleteToken($id)
147
+ {
148
+ $this->updateToken($id, array('Active' => 0));
149
+ }
150
+
151
+ /**
152
+ * Set token identified by id as default token (id used in Magento, not Customer Token Id)
153
+ *
154
+ * @param int $id
155
+ */
156
+ public function setDefaultToken($id)
157
+ {
158
+ // Check if token is existed.
159
+ $this->getTokenById($id);
160
+ $this->getCurrentCustomer()->getSavedTokens()->setDefaultToken($id);
161
+ $this->getCurrentCustomer()->setDataChanges(true)->save();
162
+ }
163
+
164
+ /**
165
+ * Get default token id
166
+ *
167
+ * @return bool | int
168
+ */
169
+ public function getDefaultToken()
170
+ {
171
+ $customer = $this->getCurrentCustomer();
172
+ if ($customer && $customer->getSavedTokens()) {
173
+ return $customer->getSavedTokens()->getDefaultToken();
174
+ }
175
+
176
+ return false;
177
+ }
178
+
179
+ /**
180
+ * Get active token list of current customer
181
+ *
182
+ * @return array
183
+ */
184
+ public function getActiveTokenList()
185
+ {
186
+ $customer = $this->getCurrentCustomer();
187
+ if ($customer && $customer->getSavedTokens()) {
188
+ $tokens = $customer->getSavedTokens()->getTokens();
189
+ if (is_array($tokens)) {
190
+ foreach ($tokens as $key => $token) {
191
+ /* @var Eway_Rapid31_Model_Customer_Token $token */
192
+ if (!$token->getActive()) {
193
+ unset($tokens[$key]);
194
+ } else {
195
+ $token->unsetData('Token');
196
+ }
197
+ }
198
+ return $tokens;
199
+ }
200
+ }
201
+
202
+ return array();
203
+ }
204
+
205
+ /**
206
+ * Get active token list of current customer
207
+ *
208
+ * @return array
209
+ */
210
+ public function checkTokenListByType($type = Eway_Rapid31_Model_Config::CREDITCARD_METHOD)
211
+ {
212
+ $customer = $this->getCurrentCustomer();
213
+ if ($customer && $customer->getSavedTokens()) {
214
+ $tokens = $customer->getSavedTokens()->getTokens();
215
+ if (is_array($tokens)) {
216
+ foreach ($tokens as $key => $token) {
217
+ /* @var Eway_Rapid31_Model_Customer_Token $token */
218
+ if (!$token->getActive()) {
219
+ unset($tokens[$key]);
220
+ } else {
221
+ $token->unsetData('Token');
222
+ }
223
+
224
+ if ($token->getCard() && $type == Eway_Rapid31_Model_Config::CREDITCARD_METHOD) {
225
+ if (preg_match('/^'.Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD.'/', strtolower($token->getCard()))) {
226
+ unset($tokens[$key]);
227
+ }
228
+ if (preg_match('/^mc/', strtolower($token->getCard()))) {
229
+ unset($tokens[$key]);
230
+ }
231
+ } elseif ($token->getCard()) {
232
+ if (!preg_match('/^'.$type.'/', strtolower($token->getCard()))) {
233
+ unset($tokens[$key]);
234
+ }
235
+ }
236
+ }
237
+ return $tokens;
238
+ }
239
+ }
240
+
241
+ return array();
242
+ }
243
  }
app/code/community/Eway/Rapid31/Helper/Data.php CHANGED
@@ -1,232 +1,233 @@
1
- <?php
2
- /**
3
- *
4
- */
5
- class Eway_Rapid31_Helper_Data extends Mage_Core_Helper_Abstract
6
- {
7
- protected $_address = null;
8
- private $_ccTypeNames = null;
9
- private $_isSaveMethodEnabled = null;
10
- private $_beagleVerificationCodes = array(
11
- 0 => 'Not Verified',
12
- 1 => 'Attempted',
13
- 2 => 'Verified',
14
- 3 => 'Failed'
15
- );
16
-
17
- public function isBackendOrder()
18
- {
19
- return Mage::app()->getStore()->isAdmin();
20
- }
21
-
22
- public function getExtensionVersion()
23
- {
24
- return (string) Mage::getConfig()->getModuleConfig("Eway_Rapid31")->version;
25
- }
26
-
27
- public function serializeInfoInstance(&$info)
28
- {
29
- $fieldsToSerialize = array('is_new_token', 'is_update_token', 'saved_token');
30
- $data = array();
31
- foreach($fieldsToSerialize as $field) {
32
- $data[$field] = $info->getData($field);
33
- }
34
-
35
- $info->setAdditionalData(json_encode($data));
36
- }
37
-
38
- public function unserializeInfoInstace(&$info)
39
- {
40
- $data = json_decode($info->getAdditionalData(), true);
41
- $info->addData($data);
42
- }
43
-
44
- public function getCcTypeName($type)
45
- {
46
- if (preg_match('/^paypal/', strtolower($type))) {
47
- return 'PayPal';
48
- }
49
-
50
- if(is_null($this->_ccTypeNames)) {
51
- $this->_ccTypeNames = Mage::getSingleton('payment/config')->getCcTypes();
52
- }
53
- return (isset($this->_ccTypeNames[$type]) ? $this->_ccTypeNames[$type] : 'Unknown');
54
- }
55
-
56
- public function isSavedMethodEnabled()
57
- {
58
- if(is_null($this->_isSaveMethodEnabled)) {
59
- $savedEnable = Mage::getSingleton('ewayrapid/method_saved')->getConfigData('active');
60
- $ewayOneEnable = Mage::getSingleton('ewayrapid/method_ewayone')->getConfigData('active');
61
- $this->_isSaveMethodEnabled = $ewayOneEnable ? $ewayOneEnable : $savedEnable;
62
- }
63
- return $this->_isSaveMethodEnabled;
64
- }
65
-
66
- public function isRecurring()
67
- {
68
- $quote = Mage::getSingleton('checkout/session')->getQuote();
69
- $items = $quote->getAllItems();
70
- foreach ($items as $item) {
71
- if ($item->getIsRecurring()) {
72
- return true;
73
- }
74
- }
75
- return false;
76
- }
77
-
78
- /**
79
- * @param $data
80
- * @param $key
81
- * @return string
82
- */
83
- public function encryptSha256($data, $key)
84
- {
85
- //To Encrypt:
86
- return trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB));
87
- }
88
-
89
- public function decryptSha256($data, $key)
90
- {
91
- //To Decrypt:
92
- return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB));
93
- }
94
-
95
- public function getPaymentAction()
96
- {
97
- return Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
98
- }
99
-
100
- public function getTransferCartLineItems()
101
- {
102
- return Mage::getStoreConfig('payment/ewayrapid_general/transfer_cart_items');
103
- }
104
-
105
- public function getLineItems()
106
- {
107
- $lineItems = array();
108
- /** @var Mage_Sales_Model_Quote $quote */
109
- if(!$this->isBackendOrder()){
110
- $quote = Mage::getSingleton('checkout/session')->getQuote();
111
- }else{
112
- $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
113
- }
114
- if ($quote) {
115
- // add Shipping item
116
- if ($quote->getShippingAddress()->getBaseShippingInclTax()) {
117
- $shippingItem = Mage::getModel('ewayrapid/field_lineItem');
118
- $shippingItem->setSKU('');
119
- $shippingItem->setDescription('Shipping');
120
- $shippingItem->setQuantity(1);
121
- $shippingItem->setUnitCost(round($quote->getShippingAddress()->getBaseShippingAmount() * 100));
122
- $shippingItem->setTax(round($quote->getShippingAddress()->getBaseShippingTaxAmount() * 100));
123
- $shippingItem->setTotal(round($quote->getShippingAddress()->getBaseShippingInclTax() * 100));
124
- $lineItems[] = $shippingItem;
125
- }
126
-
127
- // add Line items
128
- $items = $quote->getAllVisibleItems();
129
- foreach ($items as $item) {
130
- /* @var Mage_Sales_Model_Order_Item $item */
131
- $lineItem = Mage::getModel('ewayrapid/field_lineItem');
132
- $lineItem->setSKU($item->getSku());
133
- $lineItem->setDescription(substr($item->getName(), 0, 26));
134
- $lineItem->setQuantity($item->getQty());
135
- $lineItem->setUnitCost(round($item->getBasePrice() * 100));
136
- $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
137
- $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
138
- $lineItems[] = $lineItem;
139
- }
140
-
141
- // add Discount item
142
- if ((int)$quote->getShippingAddress()->getBaseDiscountAmount() !== 0) {
143
- $shippingItem = Mage::getModel('ewayrapid/field_lineItem');
144
- $shippingItem->setSKU('');
145
- $shippingItem->setDescription('Discount');
146
- $shippingItem->setQuantity(1);
147
- $shippingItem->setUnitCost(round($quote->getShippingAddress()->getBaseDiscountAmount() * 100));
148
- $shippingItem->setTax(0);
149
- $shippingItem->setTotal(round($quote->getShippingAddress()->getBaseDiscountAmount() * 100));
150
- $lineItems[] = $shippingItem;
151
- }
152
- }
153
- return $lineItems;
154
- }
155
-
156
- public function checkCardName($card)
157
- {
158
- /* @var Eway_Rapid31_Model_Request_Token $model */
159
- $model = Mage::getModel('ewayrapid/request_token');
160
- return $model->checkCardName($card);
161
- }
162
-
163
- public function clearSessionSharedpage()
164
- {
165
- Mage::getSingleton('core/session')->unsetData('editToken');
166
- Mage::getSingleton('core/session')->unsetData('newToken');
167
- Mage::getSingleton('core/session')->unsetData('sharedpagePaypal');
168
- }
169
-
170
- public function limitInvoiceDescriptionLength($description)
171
- {
172
- if(strlen($description) > 64){
173
- $description = substr($description,0,61);
174
- $description .= '...';
175
- }
176
-
177
- return $description;
178
- }
179
-
180
- public function getBeagleVerificationTitle($code)
181
- {
182
- return $this->_beagleVerificationCodes[$code];
183
- }
184
-
185
- /**
186
- * Get Fraud Codes from ResponseMessage
187
- *
188
- * @return string
189
- */
190
- public function getFraudCodes($codes)
191
- {
192
- $codes = explode(',', $codes);
193
-
194
- $fraudCodes = array();
195
-
196
- foreach($codes as $code){
197
- $code = trim($code);
198
- if(substr($code,0,1) == "F"){
199
- $fraudCodes[] = $code;
200
- }
201
- }
202
-
203
- return implode(',', $fraudCodes);
204
- }
205
-
206
- /**
207
- * Get the address block for dynamic state/country selection on forms.
208
- */
209
- public function getAddressBlock()
210
- {
211
- if( is_null( $this->_address ) ) {
212
- $this->_address = Mage::app()->getLayout()->createBlock('directory/data');
213
- }
214
-
215
- return $this->_address;
216
- }
217
-
218
- /**
219
- * Get customer country dropdown
220
- */
221
- public function getCountryHtmlSelect( $name, $default='US', $id=null )
222
- {
223
- return $this->getAddressBlock()->getCountryHtmlSelect( $default, $name, $id );
224
- }
225
-
226
- public function useIframeInBackend(){
227
- $_config = Mage::getSingleton('ewayrapid/config');
228
- $isBackend = $this->isBackendOrder();
229
-
230
- return $isBackend && ($_config->isSharedPageConnection() || $_config->isRapidIframeConnection());
231
- }
 
232
  }
1
+ <?php
2
+ /**
3
+ *
4
+ */
5
+ class Eway_Rapid31_Helper_Data extends Mage_Core_Helper_Abstract
6
+ {
7
+ protected $_address = null;
8
+ private $_ccTypeNames = null;
9
+ private $_isSaveMethodEnabled = null;
10
+ private $_beagleVerificationCodes = array(
11
+ 0 => 'Not Verified',
12
+ 1 => 'Attempted',
13
+ 2 => 'Verified',
14
+ 3 => 'Failed'
15
+ );
16
+
17
+ public function isBackendOrder()
18
+ {
19
+ return Mage::app()->getStore()->isAdmin();
20
+ }
21
+
22
+ public function getExtensionVersion()
23
+ {
24
+ return (string) Mage::getConfig()->getModuleConfig("Eway_Rapid31")->version;
25
+ }
26
+
27
+ public function serializeInfoInstance(&$info)
28
+ {
29
+ $fieldsToSerialize = array('is_new_token', 'is_update_token', 'saved_token');
30
+ $data = array();
31
+ foreach ($fieldsToSerialize as $field) {
32
+ $data[$field] = $info->getData($field);
33
+ }
34
+
35
+ $info->setAdditionalData(json_encode($data));
36
+ }
37
+
38
+ public function unserializeInfoInstace(&$info)
39
+ {
40
+ $data = json_decode($info->getAdditionalData(), true);
41
+ $info->addData($data);
42
+ }
43
+
44
+ public function getCcTypeName($type)
45
+ {
46
+ if (preg_match('/^paypal/', strtolower($type))) {
47
+ return 'PayPal';
48
+ }
49
+
50
+ if (is_null($this->_ccTypeNames)) {
51
+ $this->_ccTypeNames = Mage::getSingleton('payment/config')->getCcTypes();
52
+ }
53
+ return (isset($this->_ccTypeNames[$type]) ? $this->_ccTypeNames[$type] : 'Unknown');
54
+ }
55
+
56
+ public function isSavedMethodEnabled()
57
+ {
58
+ if (is_null($this->_isSaveMethodEnabled)) {
59
+ $savedEnable = Mage::getSingleton('ewayrapid/method_saved')->getConfigData('active');
60
+ $ewayOneEnable = Mage::getSingleton('ewayrapid/method_ewayone')->getConfigData('active');
61
+ $this->_isSaveMethodEnabled = $ewayOneEnable ? $ewayOneEnable : $savedEnable;
62
+ }
63
+ return $this->_isSaveMethodEnabled;
64
+ }
65
+
66
+ public function isRecurring()
67
+ {
68
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
69
+ $items = $quote->getAllItems();
70
+ foreach ($items as $item) {
71
+ if ($item->getIsRecurring()) {
72
+ return true;
73
+ }
74
+ }
75
+ return false;
76
+ }
77
+
78
+ /**
79
+ * @param $data
80
+ * @param $key
81
+ * @return string
82
+ */
83
+ public function encryptSha256($data, $key)
84
+ {
85
+ //To Encrypt:
86
+ return trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB));
87
+ }
88
+
89
+ public function decryptSha256($data, $key)
90
+ {
91
+ //To Decrypt:
92
+ return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB));
93
+ }
94
+
95
+ public function getPaymentAction()
96
+ {
97
+ return Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
98
+ }
99
+
100
+ public function getTransferCartLineItems()
101
+ {
102
+ return Mage::getStoreConfig('payment/ewayrapid_general/transfer_cart_items');
103
+ }
104
+
105
+ public function getLineItems()
106
+ {
107
+ $lineItems = array();
108
+ /** @var Mage_Sales_Model_Quote $quote */
109
+ if (!$this->isBackendOrder()) {
110
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
111
+ } else {
112
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
113
+ }
114
+ if ($quote) {
115
+ // add Shipping item
116
+ if ($quote->getShippingAddress()->getBaseShippingInclTax()) {
117
+ $shippingItem = Mage::getModel('ewayrapid/field_lineItem');
118
+ $shippingItem->setSKU('');
119
+ $shippingItem->setDescription('Shipping');
120
+ $shippingItem->setQuantity(1);
121
+ $shippingItem->setUnitCost(round($quote->getShippingAddress()->getBaseShippingAmount() * 100));
122
+ $shippingItem->setTax(round($quote->getShippingAddress()->getBaseShippingTaxAmount() * 100));
123
+ $shippingItem->setTotal(round($quote->getShippingAddress()->getBaseShippingInclTax() * 100));
124
+ $lineItems[] = $shippingItem;
125
+ }
126
+
127
+ // add Line items
128
+ $items = $quote->getAllVisibleItems();
129
+ foreach ($items as $item) {
130
+ /* @var Mage_Sales_Model_Order_Item $item */
131
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
132
+ $lineItem->setSKU($item->getSku());
133
+ $lineItem->setDescription(substr($item->getName(), 0, 26));
134
+ $lineItem->setQuantity($item->getQty());
135
+ $lineItem->setUnitCost(round($item->getBasePrice() * 100));
136
+ $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
137
+ $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
138
+ $lineItems[] = $lineItem;
139
+ }
140
+
141
+ // add Discount item
142
+ if ((int)$quote->getShippingAddress()->getBaseDiscountAmount() !== 0) {
143
+ $shippingItem = Mage::getModel('ewayrapid/field_lineItem');
144
+ $shippingItem->setSKU('');
145
+ $shippingItem->setDescription('Discount');
146
+ $shippingItem->setQuantity(1);
147
+ $shippingItem->setUnitCost(round($quote->getShippingAddress()->getBaseDiscountAmount() * 100));
148
+ $shippingItem->setTax(0);
149
+ $shippingItem->setTotal(round($quote->getShippingAddress()->getBaseDiscountAmount() * 100));
150
+ $lineItems[] = $shippingItem;
151
+ }
152
+ }
153
+ return $lineItems;
154
+ }
155
+
156
+ public function checkCardName($card)
157
+ {
158
+ /* @var Eway_Rapid31_Model_Request_Token $model */
159
+ $model = Mage::getModel('ewayrapid/request_token');
160
+ return $model->checkCardName($card);
161
+ }
162
+
163
+ public function clearSessionSharedpage()
164
+ {
165
+ Mage::getSingleton('core/session')->unsetData('editToken');
166
+ Mage::getSingleton('core/session')->unsetData('newToken');
167
+ Mage::getSingleton('core/session')->unsetData('sharedpagePaypal');
168
+ }
169
+
170
+ public function limitInvoiceDescriptionLength($description)
171
+ {
172
+ if (strlen($description) > 64) {
173
+ $description = substr($description, 0, 61);
174
+ $description .= '...';
175
+ }
176
+
177
+ return $description;
178
+ }
179
+
180
+ public function getBeagleVerificationTitle($code)
181
+ {
182
+ return $this->_beagleVerificationCodes[$code];
183
+ }
184
+
185
+ /**
186
+ * Get Fraud Codes from ResponseMessage
187
+ *
188
+ * @return string
189
+ */
190
+ public function getFraudCodes($codes)
191
+ {
192
+ $codes = explode(',', $codes);
193
+
194
+ $fraudCodes = array();
195
+
196
+ foreach ($codes as $code) {
197
+ $code = trim($code);
198
+ if (substr($code, 0, 1) == "F") {
199
+ $fraudCodes[] = $code;
200
+ }
201
+ }
202
+
203
+ return implode(',', $fraudCodes);
204
+ }
205
+
206
+ /**
207
+ * Get the address block for dynamic state/country selection on forms.
208
+ */
209
+ public function getAddressBlock()
210
+ {
211
+ if ( is_null($this->_address) ) {
212
+ $this->_address = Mage::app()->getLayout()->createBlock('directory/data');
213
+ }
214
+
215
+ return $this->_address;
216
+ }
217
+
218
+ /**
219
+ * Get customer country dropdown
220
+ */
221
+ public function getCountryHtmlSelect( $name, $default='US', $id=null )
222
+ {
223
+ return $this->getAddressBlock()->getCountryHtmlSelect($default, $name, $id);
224
+ }
225
+
226
+ public function useIframeInBackend()
227
+ {
228
+ $_config = Mage::getSingleton('ewayrapid/config');
229
+ $isBackend = $this->isBackendOrder();
230
+
231
+ return $isBackend && ($_config->isSharedPageConnection() || $_config->isRapidIframeConnection());
232
+ }
233
  }
app/code/community/Eway/Rapid31/Model/Backend/Savedtokens.php CHANGED
@@ -1,38 +1,38 @@
1
- <?php
2
- class Eway_Rapid31_Model_Backend_Savedtokens extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
3
- {
4
- /**
5
- * Serialize array in saved_tokens field, then encrypt it and save it into saved_tokens_json attribute
6
- *
7
- * @param Varien_Object $object
8
- * @return $this|Mage_Eav_Model_Entity_Attribute_Backend_Abstract
9
- */
10
- public function beforeSave($object)
11
- {
12
- $attrCode = $this->getAttribute()->getAttributeCode();
13
- if($object->hasData('saved_tokens') && ($savedTokens = $object->getData('saved_tokens'))) {
14
- /* @var Eway_Rapid31_Model_Customer_Savedtokens $savedTokens */
15
- if($savedTokens && $savedTokens instanceof Eway_Rapid31_Model_Customer_Savedtokens) {
16
- $object->setData($attrCode, Mage::helper('core')->encrypt($savedTokens->jsonSerialize()));
17
- }
18
- }
19
-
20
- return $this;
21
- }
22
-
23
- /**
24
- * Decrypt data in saved_tokens_json, decode it into array and set into saved_tokens field.
25
- *
26
- * @param Varien_Object $object
27
- * @return $this|Mage_Eav_Model_Entity_Attribute_Backend_Abstract
28
- */
29
- public function afterLoad($object)
30
- {
31
- $attrCode = $this->getAttribute()->getAttributeCode();
32
- if($encryptedJson = $object->getData($attrCode)) {
33
- $object->setData('saved_tokens', Mage::getModel('ewayrapid/customer_savedtokens')->decodeJSON(Mage::helper('core')->decrypt($encryptedJson)));
34
- }
35
-
36
- return $this;
37
- }
38
  }
1
+ <?php
2
+ class Eway_Rapid31_Model_Backend_Savedtokens extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
3
+ {
4
+ /**
5
+ * Serialize array in saved_tokens field, then encrypt it and save it into saved_tokens_json attribute
6
+ *
7
+ * @param Varien_Object $object
8
+ * @return $this|Mage_Eav_Model_Entity_Attribute_Backend_Abstract
9
+ */
10
+ public function beforeSave($object)
11
+ {
12
+ $attrCode = $this->getAttribute()->getAttributeCode();
13
+ if ($object->hasData('saved_tokens') && ($savedTokens = $object->getData('saved_tokens'))) {
14
+ /* @var Eway_Rapid31_Model_Customer_Savedtokens $savedTokens */
15
+ if ($savedTokens && $savedTokens instanceof Eway_Rapid31_Model_Customer_Savedtokens) {
16
+ $object->setData($attrCode, Mage::helper('core')->encrypt($savedTokens->jsonSerialize()));
17
+ }
18
+ }
19
+
20
+ return $this;
21
+ }
22
+
23
+ /**
24
+ * Decrypt data in saved_tokens_json, decode it into array and set into saved_tokens field.
25
+ *
26
+ * @param Varien_Object $object
27
+ * @return $this|Mage_Eav_Model_Entity_Attribute_Backend_Abstract
28
+ */
29
+ public function afterLoad($object)
30
+ {
31
+ $attrCode = $this->getAttribute()->getAttributeCode();
32
+ if ($encryptedJson = $object->getData($attrCode)) {
33
+ $object->setData('saved_tokens', Mage::getModel('ewayrapid/customer_savedtokens')->decodeJSON(Mage::helper('core')->decrypt($encryptedJson)));
34
+ }
35
+
36
+ return $this;
37
+ }
38
  }
app/code/community/Eway/Rapid31/Model/Config.php CHANGED
@@ -1,185 +1,188 @@
1
- <?php
2
- class Eway_Rapid31_Model_Config
3
- {
4
- const MODE_SANDBOX = 'sandbox';
5
- const MODE_LIVE = 'live';
6
- const PAYMENT_NOT_SAVED_METHOD = 'ewayrapid_notsaved';
7
- const PAYMENT_SAVED_METHOD = 'ewayrapid_saved';
8
- const PAYMENT_EWAYONE_METHOD = 'ewayrapid_ewayone';
9
-
10
- const METHOD_PROCESS_PAYMENT = 'ProcessPayment';
11
- const METHOD_CREATE_TOKEN = 'CreateTokenCustomer';
12
- const METHOD_UPDATE_TOKEN = 'UpdateTokenCustomer';
13
- const METHOD_TOKEN_PAYMENT = 'TokenPayment';
14
- const METHOD_AUTHORISE = 'Authorise';
15
-
16
- const TRANSACTION_PURCHASE = 'Purchase';
17
- const TRANSACTION_MOTO = 'MOTO';
18
- const TRANSACTION_RECURRING = 'Recurring';
19
-
20
- const CONNECTION_DIRECT = 'direct';
21
- const CONNECTION_TRANSPARENT = 'transparent';
22
- const CONNECTION_SHARED_PAGE = 'sharedpage';
23
- const CONNECTION_RAPID_IFRAME = 'rapidiframe';
24
-
25
- const CREDITCARD_METHOD = 'creditcard';
26
- const PAYPAL_STANDARD_METHOD = 'paypal';
27
- const PAYPAL_EXPRESS_METHOD = 'paypal_express';
28
- const MASTERPASS_METHOD = 'masterpass';
29
- const VISA_CHECKOUT_METHOD = 'visa';
30
-
31
- const MESSAGE_ERROR_ORDER = 'Billing Frequency is wrong. It must be numeric and greater than 0. Status of recurring profile is changed to cancelled';
32
-
33
- const TRANSPARENT_ACCESSCODE = 'AccessCodes';
34
- const TRANSPARENT_ACCESSCODE_RESULT = 'AccessCode';
35
-
36
- const ENCRYPTION_PREFIX = 'eCrypted';
37
- const TOKEN_NEW = 'new';
38
-
39
- const ORDER_STATUS_AUTHORISED = 'eway_authorised';
40
- const ORDER_STATUS_CAPTURED = 'eway_captured';
41
-
42
- private $_isSandbox = true;
43
- private $_isDebug = false;
44
- private $_liveUrl = '';
45
- private $_liveApiKey = '';
46
- private $_livePassword = '';
47
- private $_sandboxUrl = '';
48
- private $_sandboxApiKey = '';
49
- private $_sandboxPassword = '';
50
- private $_isEnableSSLVerification = false;
51
-
52
- public function __construct()
53
- {
54
- $this->_isSandbox = (Mage::getStoreConfig('payment/ewayrapid_general/mode') == self::MODE_SANDBOX);
55
- $this->_isDebug = (bool) Mage::getStoreConfig('payment/ewayrapid_general/debug');
56
- $this->_sandboxUrl = Mage::getStoreConfig('payment/ewayrapid_general/sandbox_endpoint');
57
- $this->_liveUrl = Mage::getStoreConfig('payment/ewayrapid_general/live_endpoint');
58
- $this->_liveApiKey = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/live_api_key'));
59
- $this->_livePassword = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/live_api_password'));
60
- $this->_sandboxApiKey = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/sandbox_api_key'));
61
- $this->_sandboxPassword = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/sandbox_api_password'));
62
- $this->_isEnableSSLVerification = Mage::getStoreConfig('payment/ewayrapid_general/ssl_verification');
63
- }
64
-
65
- public function isSandbox($sandbox = null)
66
- {
67
- if($sandbox !== null) {
68
- $this->_isSandbox = (bool) $sandbox;
69
- }
70
-
71
- return $this->_isSandbox;
72
- }
73
-
74
- public function isDebug($debug = null)
75
- {
76
- if($debug !== null) {
77
- $this->_isDebug = (bool) $debug;
78
- }
79
-
80
- return $this->_isDebug;
81
- }
82
-
83
- public function getRapidAPIUrl($action = false)
84
- {
85
- $url = $this->isSandbox() ? $this->_sandboxUrl : $this->_liveUrl;
86
- $url = rtrim($url, '/') . '/';
87
- if($action) {
88
- $url .= $action;
89
- }
90
-
91
- return $url;
92
- }
93
-
94
- public function getBasicAuthenticationHeader()
95
- {
96
- return $this->isSandbox() ? $this->_sandboxApiKey . ':' . $this->_sandboxPassword
97
- : $this->_liveApiKey . ':' . $this->_livePassword;
98
- }
99
-
100
- public function isEnableSSLVerification()
101
- {
102
- // Always return true in Live mode regardless Magento config.
103
- return !$this->isSandbox() || $this->_isEnableSSLVerification;
104
- }
105
-
106
- public function getEncryptionKey()
107
- {
108
- return $this->isSandbox() ? Mage::getStoreConfig('payment/ewayrapid_general/sandbox_encryption_key')
109
- : Mage::getStoreConfig('payment/ewayrapid_general/live_encryption_key');
110
- }
111
-
112
- public function isDirectConnection()
113
- {
114
- return Mage::getStoreConfig('payment/ewayrapid_general/connection_type') == self::CONNECTION_DIRECT;
115
- }
116
-
117
- public function isTransparentConnection()
118
- {
119
- return Mage::getStoreConfig('payment/ewayrapid_general/connection_type') == self::CONNECTION_TRANSPARENT;
120
- }
121
-
122
- public function isSharedPageConnection()
123
- {
124
- return Mage::getStoreConfig('payment/ewayrapid_general/connection_type') == self::CONNECTION_SHARED_PAGE;
125
- }
126
-
127
- public function isRapidIframeConnection()
128
- {
129
- return Mage::getStoreConfig('payment/ewayrapid_general/connection_type') == self::CONNECTION_RAPID_IFRAME;
130
- }
131
-
132
- public function canEditToken()
133
- {
134
- return (bool) Mage::getStoreConfig('payment/ewayrapid_general/can_edit_token');
135
- }
136
-
137
- public function getSupportedCardTypes()
138
- {
139
- return explode(',', Mage::getStoreConfig('payment/ewayrapid_general/cctypes'));
140
- }
141
-
142
- public function getVerifyEmail()
143
- {
144
- return (bool) Mage::getStoreConfig('payment/ewayrapid_general/beagle_verify_email');
145
- }
146
-
147
- public function getVerifyPhone()
148
- {
149
- return (bool) Mage::getStoreConfig('payment/ewayrapid_general/beagle_verify_phone');
150
- }
151
-
152
- public function getCustomView()
153
- {
154
- return Mage::getStoreConfig('payment/ewayrapid_general/custom_view');
155
- }
156
-
157
- public function shouldPassingInvoiceDescription()
158
- {
159
- return Mage::getStoreConfig('payment/ewayrapid_general/invoice_description');
160
- }
161
-
162
- public function shouldPassingGuessOrder()
163
- {
164
- return Mage::getStoreConfig('payment/ewayrapid_general/guess_order');
165
- }
166
-
167
- public function getVisaCheckoutApiKey(){
168
- return Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/visa_checkout_api_key'));
169
- }
170
-
171
- public function getVisaCheckoutEnable(){
172
- return Mage::getStoreConfig('payment/ewayrapid_general/enable_visa_checkout')
173
- && Mage::getStoreConfig('payment/ewayrapid_general/visa_checkout_api_key') != '';
174
- }
175
-
176
- public function getVisaCheckoutSDK(){
177
- if(!$this->getVisaCheckoutEnable()){
178
- return false;
179
- }else{
180
- return $this->_isSandbox
181
- ? 'https://sandbox-assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js'
182
- : 'https://assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js';
183
- }
184
- }
 
 
 
185
  }
1
+ <?php
2
+ class Eway_Rapid31_Model_Config
3
+ {
4
+ const MODE_SANDBOX = 'sandbox';
5
+ const MODE_LIVE = 'live';
6
+ const PAYMENT_NOT_SAVED_METHOD = 'ewayrapid_notsaved';
7
+ const PAYMENT_SAVED_METHOD = 'ewayrapid_saved';
8
+ const PAYMENT_EWAYONE_METHOD = 'ewayrapid_ewayone';
9
+
10
+ const METHOD_PROCESS_PAYMENT = 'ProcessPayment';
11
+ const METHOD_CREATE_TOKEN = 'CreateTokenCustomer';
12
+ const METHOD_UPDATE_TOKEN = 'UpdateTokenCustomer';
13
+ const METHOD_TOKEN_PAYMENT = 'TokenPayment';
14
+ const METHOD_AUTHORISE = 'Authorise';
15
+
16
+ const TRANSACTION_PURCHASE = 'Purchase';
17
+ const TRANSACTION_MOTO = 'MOTO';
18
+ const TRANSACTION_RECURRING = 'Recurring';
19
+
20
+ const CONNECTION_DIRECT = 'direct';
21
+ const CONNECTION_TRANSPARENT = 'transparent';
22
+ const CONNECTION_SHARED_PAGE = 'sharedpage';
23
+ const CONNECTION_RAPID_IFRAME = 'rapidiframe';
24
+
25
+ const CREDITCARD_METHOD = 'creditcard';
26
+ const PAYPAL_STANDARD_METHOD = 'paypal';
27
+ const PAYPAL_EXPRESS_METHOD = 'paypal_express';
28
+ const MASTERPASS_METHOD = 'masterpass';
29
+ const VISA_CHECKOUT_METHOD = 'visa';
30
+
31
+ const MESSAGE_ERROR_ORDER = 'Billing Frequency is wrong. It must be numeric and greater than 0. Status of recurring profile is changed to cancelled';
32
+
33
+ const TRANSPARENT_ACCESSCODE = 'AccessCodes';
34
+ const TRANSPARENT_ACCESSCODE_RESULT = 'AccessCode';
35
+
36
+ const ENCRYPTION_PREFIX = 'eCrypted';
37
+ const TOKEN_NEW = 'new';
38
+
39
+ const ORDER_STATUS_AUTHORISED = 'eway_authorised';
40
+ const ORDER_STATUS_CAPTURED = 'eway_captured';
41
+
42
+ protected $_isSandbox = true;
43
+ protected $_isDebug = false;
44
+ protected $_liveUrl = '';
45
+ protected $_liveApiKey = '';
46
+ protected $_livePassword = '';
47
+ protected $_sandboxUrl = '';
48
+ protected $_sandboxApiKey = '';
49
+ protected $_sandboxPassword = '';
50
+ protected $_isEnableSSLVerification = false;
51
+
52
+ public function __construct()
53
+ {
54
+ $this->_isSandbox = (Mage::getStoreConfig('payment/ewayrapid_general/mode') == self::MODE_SANDBOX);
55
+ $this->_isDebug = (bool) Mage::getStoreConfig('payment/ewayrapid_general/debug');
56
+ $this->_sandboxUrl = Mage::getStoreConfig('payment/ewayrapid_general/sandbox_endpoint');
57
+ $this->_liveUrl = Mage::getStoreConfig('payment/ewayrapid_general/live_endpoint');
58
+ $this->_liveApiKey = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/live_api_key'));
59
+ $this->_livePassword = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/live_api_password'));
60
+ $this->_sandboxApiKey = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/sandbox_api_key'));
61
+ $this->_sandboxPassword = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/sandbox_api_password'));
62
+ $this->_isEnableSSLVerification = Mage::getStoreConfig('payment/ewayrapid_general/ssl_verification');
63
+ }
64
+
65
+ public function isSandbox($sandbox = null)
66
+ {
67
+ if ($sandbox !== null) {
68
+ $this->_isSandbox = (bool) $sandbox;
69
+ }
70
+
71
+ return $this->_isSandbox;
72
+ }
73
+
74
+ public function isDebug($debug = null)
75
+ {
76
+ if ($debug !== null) {
77
+ $this->_isDebug = (bool) $debug;
78
+ }
79
+
80
+ return $this->_isDebug;
81
+ }
82
+
83
+ public function getRapidAPIUrl($action = false)
84
+ {
85
+ $url = $this->isSandbox() ? $this->_sandboxUrl : $this->_liveUrl;
86
+ $url = rtrim($url, '/') . '/';
87
+ if ($action) {
88
+ $url .= $action;
89
+ }
90
+
91
+ return $url;
92
+ }
93
+
94
+ public function getBasicAuthenticationHeader()
95
+ {
96
+ return $this->isSandbox() ? $this->_sandboxApiKey . ':' . $this->_sandboxPassword
97
+ : $this->_liveApiKey . ':' . $this->_livePassword;
98
+ }
99
+
100
+ public function isEnableSSLVerification()
101
+ {
102
+ // Always return true in Live mode regardless Magento config.
103
+ return !$this->isSandbox() || $this->_isEnableSSLVerification;
104
+ }
105
+
106
+ public function getEncryptionKey()
107
+ {
108
+ return $this->isSandbox() ? Mage::getStoreConfig('payment/ewayrapid_general/sandbox_encryption_key')
109
+ : Mage::getStoreConfig('payment/ewayrapid_general/live_encryption_key');
110
+ }
111
+
112
+ public function isDirectConnection()
113
+ {
114
+ return Mage::getStoreConfig('payment/ewayrapid_general/connection_type') == self::CONNECTION_DIRECT;
115
+ }
116
+
117
+ public function isTransparentConnection()
118
+ {
119
+ return Mage::getStoreConfig('payment/ewayrapid_general/connection_type') == self::CONNECTION_TRANSPARENT;
120
+ }
121
+
122
+ public function isSharedPageConnection()
123
+ {
124
+ return Mage::getStoreConfig('payment/ewayrapid_general/connection_type') == self::CONNECTION_SHARED_PAGE;
125
+ }
126
+
127
+ public function isRapidIframeConnection()
128
+ {
129
+ return Mage::getStoreConfig('payment/ewayrapid_general/connection_type') == self::CONNECTION_RAPID_IFRAME;
130
+ }
131
+
132
+ public function canEditToken()
133
+ {
134
+ return (bool) Mage::getStoreConfig('payment/ewayrapid_general/can_edit_token');
135
+ }
136
+
137
+ public function getSupportedCardTypes()
138
+ {
139
+ return explode(',', Mage::getStoreConfig('payment/ewayrapid_general/cctypes'));
140
+ }
141
+
142
+ public function getVerifyEmail()
143
+ {
144
+ return (bool) Mage::getStoreConfig('payment/ewayrapid_general/beagle_verify_email');
145
+ }
146
+
147
+ public function getVerifyPhone()
148
+ {
149
+ return (bool) Mage::getStoreConfig('payment/ewayrapid_general/beagle_verify_phone');
150
+ }
151
+
152
+ public function getCustomView()
153
+ {
154
+ return Mage::getStoreConfig('payment/ewayrapid_general/custom_view');
155
+ }
156
+
157
+ public function shouldPassingInvoiceDescription()
158
+ {
159
+ return Mage::getStoreConfig('payment/ewayrapid_general/invoice_description');
160
+ }
161
+
162
+ public function shouldPassingGuessOrder()
163
+ {
164
+ return Mage::getStoreConfig('payment/ewayrapid_general/guess_order');
165
+ }
166
+
167
+ public function getVisaCheckoutApiKey()
168
+ {
169
+ return Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/visa_checkout_api_key'));
170
+ }
171
+
172
+ public function getVisaCheckoutEnable()
173
+ {
174
+ return Mage::getStoreConfig('payment/ewayrapid_general/enable_visa_checkout')
175
+ && Mage::getStoreConfig('payment/ewayrapid_general/visa_checkout_api_key') != '';
176
+ }
177
+
178
+ public function getVisaCheckoutSDK()
179
+ {
180
+ if (!$this->getVisaCheckoutEnable()) {
181
+ return false;
182
+ } else {
183
+ return $this->_isSandbox
184
+ ? 'https://sandbox-assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js'
185
+ : 'https://assets.secure.checkout.visa.com/checkout-widget/resources/js/integration/v1/sdk.js';
186
+ }
187
+ }
188
  }
app/code/community/Eway/Rapid31/Model/Customer/Savedtokens.php CHANGED
@@ -1,91 +1,93 @@
1
- <?php
2
-
3
- /**
4
- * Class Eway_Rapid31_Model_Customer_Savedtokens
5
- *
6
- *
7
- * @method int getLastId()
8
- * @method Eway_Rapid31_Model_Customer_Savedtokens setLastId(int $value)
9
- * @method int getDefaultToken()
10
- * @method Eway_Rapid31_Model_Customer_Savedtokens setDefaultToken(int $value)
11
- * @method array getTokens()
12
- * @method Eway_Rapid31_Model_Customer_Savedtokens setTokens(array $value)
13
- */
14
- class Eway_Rapid31_Model_Customer_Savedtokens extends Eway_Rapid31_Model_JsonSerializableAbstract
15
- {
16
- protected function _construct()
17
- {
18
- $this->setLastId(0);
19
- $this->setTokens(array());
20
- }
21
-
22
- /**
23
- * @param $json string|array
24
- * @return $this
25
- */
26
- public function decodeJSON($json)
27
- {
28
- if(is_string($json)) {
29
- $json = json_decode($json, true);
30
- }
31
- /*
32
- $json = array(
33
- 'LastId' => <last token id>
34
- 'DefaultToken' => <default token id>
35
- 'Tokens' => array(
36
- <token id> => array(
37
- 'Token' => <eWAY customer token>,
38
- 'Card' => <masked card number>,
39
- 'Type' => <credit card type, e.g: VI, MA>
40
- 'Owner' => <owner>,
41
- 'ExpMonth' => <expired month>,
42
- 'ExpYear' => <expired year>,
43
- 'Active' => 0 | 1,
44
- 'Address' => array(
45
- 'FirstName' => <first name>
46
- ...
47
- )
48
- ),
49
- )
50
- )
51
- */
52
-
53
- $this->addData($json);
54
- $tokens = $this->getTokens();
55
- if(is_array($tokens)) {
56
- foreach($tokens as $id => $token) {
57
- $tokenModel = Mage::getModel('ewayrapid/customer_token')->addData($token);
58
- /* @var Eway_Rapid31_Model_Customer_Token $tokenModel */
59
- if($address = $tokenModel->getAddress()) {
60
- $tokenModel->setAddress(Mage::getModel('ewayrapid/field_customer')->addData($address));
61
- }
62
- $tokens[$id] = $tokenModel;
63
- }
64
-
65
- $this->setTokens($tokens);
66
- }
67
-
68
- return $this;
69
- }
70
-
71
- /**
72
- * @param $id
73
- * @return Eway_Rapid31_Model_Customer_Token
74
- */
75
- public function getTokenById($id)
76
- {
77
- if(($tokens = $this->getTokens()) && isset($tokens[$id]) && $tokens[$id] instanceof Eway_Rapid31_Model_Customer_Token) {
78
- return $tokens[$id];
79
- } else {
80
- Mage::throwException(Mage::helper('ewayrapid')->__('Customer token does not exist.'));
81
- }
82
- }
83
-
84
- public function addToken($info)
85
- {
86
- $this->setLastId($this->getLastId() + 1);
87
- $tokens = $this->getTokens();
88
- $tokens[$this->getLastId()] = Mage::getModel('ewayrapid/customer_token')->addData($info)->setActive(1);
89
- $this->setTokens($tokens);
90
- }
 
 
91
  }
1
+ <?php
2
+
3
+ /**
4
+ * Class Eway_Rapid31_Model_Customer_Savedtokens
5
+ *
6
+ *
7
+ * @method int getLastId()
8
+ * @method Eway_Rapid31_Model_Customer_Savedtokens setLastId(int $value)
9
+ * @method int getDefaultToken()
10
+ * @method Eway_Rapid31_Model_Customer_Savedtokens setDefaultToken(int $value)
11
+ * @method array getTokens()
12
+ * @method Eway_Rapid31_Model_Customer_Savedtokens setTokens(array $value)
13
+ */
14
+ class Eway_Rapid31_Model_Customer_Savedtokens extends Eway_Rapid31_Model_JsonSerializableAbstract
15
+ {
16
+ protected function _construct()
17
+ {
18
+ $this->setLastId(0);
19
+ $this->setTokens(array());
20
+ }
21
+
22
+ /**
23
+ * @param $json string|array
24
+ * @return $this
25
+ */
26
+ public function decodeJSON($json)
27
+ {
28
+ if (is_string($json)) {
29
+ $json = json_decode($json, true);
30
+ }
31
+ /*
32
+ $json = array(
33
+ 'LastId' => <last token id>
34
+ 'DefaultToken' => <default token id>
35
+ 'Tokens' => array(
36
+ <token id> => array(
37
+ 'Token' => <eWAY customer token>,
38
+ 'Card' => <masked card number>,
39
+ 'Type' => <credit card type, e.g: VI, MA>
40
+ 'Owner' => <owner>,
41
+ 'ExpMonth' => <expired month>,
42
+ 'ExpYear' => <expired year>,
43
+ 'Active' => 0 | 1,
44
+ 'Address' => array(
45
+ 'FirstName' => <first name>
46
+ ...
47
+ )
48
+ ),
49
+ )
50
+ )
51
+ */
52
+
53
+ $this->addData($json);
54
+ $tokens = $this->getTokens();
55
+ if (is_array($tokens)) {
56
+ foreach ($tokens as $id => $token) {
57
+ $tokenModel = Mage::getModel('ewayrapid/customer_token')->addData($token);
58
+ /* @var Eway_Rapid31_Model_Customer_Token $tokenModel */
59
+ if ($address = $tokenModel->getAddress()) {
60
+ $tokenModel->setAddress(Mage::getModel('ewayrapid/field_customer')->addData($address));
61
+ }
62
+ $tokens[$id] = $tokenModel;
63
+ }
64
+
65
+ $this->setTokens($tokens);
66
+ }
67
+
68
+ return $this;
69
+ }
70
+
71
+ /**
72
+ * @param $id
73
+ * @return Eway_Rapid31_Model_Customer_Token
74
+ */
75
+ public function getTokenById($id)
76
+ {
77
+ if (($tokens = $this->getTokens())
78
+ && isset($tokens[$id])
79
+ && $tokens[$id] instanceof Eway_Rapid31_Model_Customer_Token) {
80
+ return $tokens[$id];
81
+ } else {
82
+ Mage::throwException(Mage::helper('ewayrapid')->__('Customer token does not exist.'));
83
+ }
84
+ }
85
+
86
+ public function addToken($info)
87
+ {
88
+ $this->setLastId($this->getLastId() + 1);
89
+ $tokens = $this->getTokens();
90
+ $tokens[$this->getLastId()] = Mage::getModel('ewayrapid/customer_token')->addData($info)->setActive(1);
91
+ $this->setTokens($tokens);
92
+ }
93
  }
app/code/community/Eway/Rapid31/Model/EwayCron.php CHANGED
@@ -1,132 +1,139 @@
1
- <?php
2
- /**
3
- *
4
- */
5
- class Eway_Rapid31_Model_EwayCron {
6
-
7
- public function querySuspectFraud() {
8
-
9
- // Load orders with fraud in 7 days before from now
10
- $orders = Mage::getModel('sales/order')->getCollection()
11
- ->addFieldToFilter('status', array('eq' => 'fraud')) // State fraud
12
- ->addFieldToFilter('eway_transaction_id', array('notnull' => ''))
13
- ->addFieldToFilter('created_at', array('to' => date('Y-m-d 23:59:59'), 'from' => date('Y-m-d 00:00:01', strtotime('-7 days'))));
14
-
15
- foreach ($orders as $o) {
16
- $transactionId = $o->getEwayTransactionId();
17
-
18
- // continue when order does not contain eway transaction
19
- if (!$transactionId) {
20
- continue;
21
- }
22
- $result = $this->__getTransaction($transactionId);
23
- $result_decode = json_decode($result);
24
- // continue when property transaction is not exist
25
- if (!property_exists($result_decode, 'Transactions') || empty($result_decode->Transactions)) {
26
- continue;
27
- }
28
- $trans = $result_decode->Transactions;
29
-
30
- // continue when transaction is not exits
31
- if (!isset($trans[0])) {
32
- continue;
33
- }
34
- $tranId = $trans[0]->TransactionID;
35
-
36
- // Success - Fraud order has been approved
37
- if ($trans[0]->ResponseMessage == 'A2000') {
38
- // Create new transaction
39
- $this->__createNewTransaction($o, $tranId);
40
- // Update order status
41
- $this->__updateStatusOrder($o);
42
- // Un-mark fraud customer
43
- $this->__unMarkFraudUser($o);
44
- }
45
- }
46
- // Response data to client
47
- /*$this->getResponse()->setHeader('Content-type', 'application/json');
48
- $this->getResponse()->setBody($result);*/
49
- }
50
-
51
- private function __getTransaction($transId) {
52
- $ewayConfig = Mage::getSingleton('ewayrapid/config');
53
- $url = $ewayConfig->getRapidAPIUrl('Transaction') . '/' . $transId;
54
- $ch = curl_init($url);
55
- curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
56
- curl_setopt($ch, CURLOPT_USERPWD, $ewayConfig->getBasicAuthenticationHeader());
57
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
58
-
59
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
60
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
61
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ewayConfig->isEnableSSLVerification());
62
-
63
- $result = curl_exec($ch);
64
- return $result;
65
- }
66
-
67
- /**
68
- * Re-create order with new transaction returned by Eway
69
- * @param $data
70
- */
71
- private function __createNewTransaction(Mage_Sales_Model_Order $order, $transId) {
72
-
73
- // Load transaction
74
- $currentTrans = Mage::getModel('sales/order_payment_transaction')
75
- ->getCollection()
76
- ->addFieldToFilter('order_id', array('eq' => $order->getEntityId()));
77
- foreach($currentTrans as $t) { }
78
- if($t == null) {
79
- $t = new Mage_Sales_Model_Order_Payment_Transaction();
80
- }
81
-
82
- $trans = new Mage_Sales_Model_Order_Payment_Transaction();
83
- // Load payment object
84
- $payment = Mage::getModel('sales/order_payment')->load($t->getPaymentId());
85
-
86
- $trans->setOrderPaymentObject($payment);
87
- $trans->setOrder($order);
88
-
89
- $trans->setParentId($t->getTransactionId());
90
- $trans->setOrderId($order->getEntityId());
91
- $trans->setPaymentId($t->getPaymentId());
92
- // Get new TxnId
93
- $break = true;
94
- for($i = 0; $i < 100; $i++) {
95
- $transId ++;
96
- $newTrans = Mage::getModel('sales/order_payment_transaction')
97
- ->getCollection()
98
- ->addFieldToFilter('txn_id', array('eq' => $transId));
99
- if(count($newTrans) == 0) {
100
- $break = false;
101
- break;
102
- }
103
- }
104
- if($break) {
105
- return false;
106
- }
107
- $trans->setTxnId($transId);
108
- $trans->setParentTxnId($t->getTxnId());
109
- $trans->setTxnType($t->getTxnType());
110
- $trans->setIsClosed($t->getIsClosed());
111
- $trans->setCreatedAt(date('Y-m-d H:i:s'));
112
- $trans->save();
113
-
114
- }
115
-
116
- private function __updateStatusOrder(Mage_Sales_Model_Order $order) {
117
- $state_config = Mage::getStoreConfig('payment/ewayrapid_general/verify_eway_order');
118
-
119
- $order->setState($state_config);
120
- $order->setStatus($state_config);
121
- $order->save();
122
- }
123
-
124
- private function __unMarkFraudUser(Mage_Sales_Model_Order $order) {
125
- $uid = $order->getCustomerId();
126
- if ($uid) {
127
- $customer = Mage::getModel('customer/customer')->load($uid);
128
- $customer->setMarkFraud(0);
129
- $customer->save();
130
- }
131
- }
 
 
 
 
 
 
 
132
  }
1
+ <?php
2
+ /**
3
+ *
4
+ */
5
+ class Eway_Rapid31_Model_EwayCron
6
+ {
7
+
8
+ public function querySuspectFraud()
9
+ {
10
+
11
+ // Load orders with fraud in 7 days before from now
12
+ $orders = Mage::getModel('sales/order')->getCollection()
13
+ ->addFieldToFilter('status', array('eq' => 'fraud')) // State fraud
14
+ ->addFieldToFilter('eway_transaction_id', array('notnull' => ''))
15
+ ->addFieldToFilter('created_at', array('to' => date('Y-m-d 23:59:59'), 'from' => date('Y-m-d 00:00:01', strtotime('-7 days'))));
16
+
17
+ foreach ($orders as $o) {
18
+ $transactionId = $o->getEwayTransactionId();
19
+
20
+ // continue when order does not contain eway transaction
21
+ if (!$transactionId) {
22
+ continue;
23
+ }
24
+ $result = $this->__getTransaction($transactionId);
25
+ $resultDecode = json_decode($result);
26
+ // continue when property transaction is not exist
27
+ if (!property_exists($resultDecode, 'Transactions') || empty($resultDecode->Transactions)) {
28
+ continue;
29
+ }
30
+ $trans = $resultDecode->Transactions;
31
+
32
+ // continue when transaction is not exits
33
+ if (!isset($trans[0])) {
34
+ continue;
35
+ }
36
+ $tranId = $trans[0]->TransactionID;
37
+
38
+ // Success - Fraud order has been approved
39
+ if ($trans[0]->ResponseMessage == 'A2000') {
40
+ // Create new transaction
41
+ $this->__createNewTransaction($o, $tranId);
42
+ // Update order status
43
+ $this->__updateStatusOrder($o);
44
+ // Un-mark fraud customer
45
+ $this->__unMarkFraudUser($o);
46
+ }
47
+ }
48
+ // Response data to client
49
+ /*$this->getResponse()->setHeader('Content-type', 'application/json');
50
+ $this->getResponse()->setBody($result);*/
51
+ }
52
+
53
+ protected function __getTransaction($transId)
54
+ {
55
+ $ewayConfig = Mage::getSingleton('ewayrapid/config');
56
+ $url = $ewayConfig->getRapidAPIUrl('Transaction') . '/' . $transId;
57
+ $ch = curl_init($url);
58
+ curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
59
+ curl_setopt($ch, CURLOPT_USERPWD, $ewayConfig->getBasicAuthenticationHeader());
60
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
61
+
62
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
63
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
64
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ewayConfig->isEnableSSLVerification());
65
+
66
+ $result = curl_exec($ch);
67
+ return $result;
68
+ }
69
+
70
+ /**
71
+ * Re-create order with new transaction returned by Eway
72
+ * @param $data
73
+ */
74
+ protected function __createNewTransaction(Mage_Sales_Model_Order $order, $transId)
75
+ {
76
+
77
+ // Load transaction
78
+ $currentTrans = Mage::getModel('sales/order_payment_transaction')
79
+ ->getCollection()
80
+ ->addFieldToFilter('order_id', array('eq' => $order->getEntityId()));
81
+ foreach ($currentTrans as $t) {
82
+ }
83
+ if ($t == null) {
84
+ $t = new Mage_Sales_Model_Order_Payment_Transaction();
85
+ }
86
+
87
+ $trans = new Mage_Sales_Model_Order_Payment_Transaction();
88
+ // Load payment object
89
+ $payment = Mage::getModel('sales/order_payment')->load($t->getPaymentId());
90
+
91
+ $trans->setOrderPaymentObject($payment);
92
+ $trans->setOrder($order);
93
+
94
+ $trans->setParentId($t->getTransactionId());
95
+ $trans->setOrderId($order->getEntityId());
96
+ $trans->setPaymentId($t->getPaymentId());
97
+ // Get new TxnId
98
+ $break = true;
99
+ for ($i = 0; $i < 100; $i++) {
100
+ $transId ++;
101
+ $newTrans = Mage::getModel('sales/order_payment_transaction')
102
+ ->getCollection()
103
+ ->addFieldToFilter('txn_id', array('eq' => $transId));
104
+ if (count($newTrans) == 0) {
105
+ $break = false;
106
+ break;
107
+ }
108
+ }
109
+ if ($break) {
110
+ return false;
111
+ }
112
+ $trans->setTxnId($transId);
113
+ $trans->setParentTxnId($t->getTxnId());
114
+ $trans->setTxnType($t->getTxnType());
115
+ $trans->setIsClosed($t->getIsClosed());
116
+ $trans->setCreatedAt(date('Y-m-d H:i:s'));
117
+ $trans->save();
118
+
119
+ }
120
+
121
+ protected function __updateStatusOrder(Mage_Sales_Model_Order $order)
122
+ {
123
+ $stateConfig = Mage::getStoreConfig('payment/ewayrapid_general/verify_eway_order');
124
+
125
+ $order->setState($stateConfig);
126
+ $order->setStatus($stateConfig);
127
+ $order->save();
128
+ }
129
+
130
+ protected function __unMarkFraudUser(Mage_Sales_Model_Order $order)
131
+ {
132
+ $uid = $order->getCustomerId();
133
+ if ($uid) {
134
+ $customer = Mage::getModel('customer/customer')->load($uid);
135
+ $customer->setMarkFraud(0);
136
+ $customer->save();
137
+ }
138
+ }
139
  }
app/code/community/Eway/Rapid31/Model/Field/CardDetails.php CHANGED
@@ -1,90 +1,90 @@
1
- <?php
2
-
3
- /**
4
- * Class Eway_Rapid31_Model_Field_CardDetails
5
- *
6
- * @method string getName()
7
- * @method Eway_Rapid31_Model_Field_CardDetails setName(string $value)
8
- * @method Eway_Rapid31_Model_Field_CardDetails setNumber(string $value)
9
- * @method string getStartMonth()
10
- * @method Eway_Rapid31_Model_Field_CardDetails setStartMonth(string $value)
11
- * @method string getStartYear()
12
- * @method string getExpiryMonth()
13
- * @method string getExpiryYear()
14
- * @method Eway_Rapid31_Model_Field_CardDetails setStartYear(string $value)
15
- * @method string getIssueNumber()
16
- * @method Eway_Rapid31_Model_Field_CardDetails setIssueNumber(string $value)
17
- * @method Eway_Rapid31_Model_Field_CardDetails setCVN(string $value)
18
- */
19
- class Eway_Rapid31_Model_Field_CardDetails extends Eway_Rapid31_Model_JsonSerializableAbstract
20
- {
21
- protected $_shouldMasked = false;
22
-
23
- public function shouldBeMasked($value = true)
24
- {
25
- $this->_shouldMasked = $value;
26
- }
27
-
28
- public function getJsonData(array $rawData = null)
29
- {
30
- $jsonData = parent::getJsonData($rawData);
31
- // Mask sensitive data in necessary
32
- if($this->_shouldMasked) {
33
- if(!empty($jsonData['Number'])) {
34
- if(strlen($jsonData['Number']) > 19) {
35
- $jsonData['Number'] = '*** Encrypted ***';
36
- } else {
37
- $jsonData['Number'] = substr_replace($this->_data['Number'], '******', 6, 6);
38
- }
39
- }
40
-
41
- if(!empty($this->_data['CVN'])) {
42
- $jsonData['CVN'] = '***';
43
- }
44
- if(!empty($this->_data['ExpiryMonth'])) {
45
- $jsonData['ExpiryMonth'] = '**';
46
- }
47
- if(!empty($this->_data['ExpiryYear'])) {
48
- $jsonData['ExpiryYear'] = '**';
49
- }
50
-
51
- if(!empty($this->_data['StartMonth'])) {
52
- $jsonData['StartMonth'] = '**';
53
- }
54
- if(!empty($this->_data['StartYear'])) {
55
- $jsonData['StartYear'] = '**';
56
- }
57
- if(!empty($this->_data['IssueNumber'])) {
58
- $jsonData['IssueNumber'] = '***';
59
- }
60
- }
61
-
62
- return $jsonData;
63
- }
64
-
65
- /**
66
- * Normalize data to compatible with eWAY API
67
- *
68
- * @param $value
69
- * @return $this
70
- */
71
- public function setExpiryMonth($value)
72
- {
73
- $value = (string) ($value < 10 ? '0' . $value : $value);
74
- $this->setData('ExpiryMonth', $value);
75
- return $this;
76
- }
77
-
78
- /**
79
- * Normalize data to compatible with eWAY API
80
- *
81
- * @param $value
82
- * @return $this
83
- */
84
- public function setExpiryYear($value)
85
- {
86
- $value = substr((string)$value, -2);
87
- $this->setData('ExpiryYear', $value);
88
- return $this;
89
- }
90
  }
1
+ <?php
2
+
3
+ /**
4
+ * Class Eway_Rapid31_Model_Field_CardDetails
5
+ *
6
+ * @method string getName()
7
+ * @method Eway_Rapid31_Model_Field_CardDetails setName(string $value)
8
+ * @method Eway_Rapid31_Model_Field_CardDetails setNumber(string $value)
9
+ * @method string getStartMonth()
10
+ * @method Eway_Rapid31_Model_Field_CardDetails setStartMonth(string $value)
11
+ * @method string getStartYear()
12
+ * @method string getExpiryMonth()
13
+ * @method string getExpiryYear()
14
+ * @method Eway_Rapid31_Model_Field_CardDetails setStartYear(string $value)
15
+ * @method string getIssueNumber()
16
+ * @method Eway_Rapid31_Model_Field_CardDetails setIssueNumber(string $value)
17
+ * @method Eway_Rapid31_Model_Field_CardDetails setCVN(string $value)
18
+ */
19
+ class Eway_Rapid31_Model_Field_CardDetails extends Eway_Rapid31_Model_JsonSerializableAbstract
20
+ {
21
+ protected $_shouldMasked = false;
22
+
23
+ public function shouldBeMasked($value = true)
24
+ {
25
+ $this->_shouldMasked = $value;
26
+ }
27
+
28
+ public function getJsonData(array $rawData = null)
29
+ {
30
+ $jsonData = parent::getJsonData($rawData);
31
+ // Mask sensitive data in necessary
32
+ if ($this->_shouldMasked) {
33
+ if (!empty($jsonData['Number'])) {
34
+ if (strlen($jsonData['Number']) > 19) {
35
+ $jsonData['Number'] = '*** Encrypted ***';
36
+ } else {
37
+ $jsonData['Number'] = substr_replace($this->_data['Number'], '******', 6, 6);
38
+ }
39
+ }
40
+
41
+ if (!empty($this->_data['CVN'])) {
42
+ $jsonData['CVN'] = '***';
43
+ }
44
+ if (!empty($this->_data['ExpiryMonth'])) {
45
+ $jsonData['ExpiryMonth'] = '**';
46
+ }
47
+ if (!empty($this->_data['ExpiryYear'])) {
48
+ $jsonData['ExpiryYear'] = '**';
49
+ }
50
+
51
+ if (!empty($this->_data['StartMonth'])) {
52
+ $jsonData['StartMonth'] = '**';
53
+ }
54
+ if (!empty($this->_data['StartYear'])) {
55
+ $jsonData['StartYear'] = '**';
56
+ }
57
+ if (!empty($this->_data['IssueNumber'])) {
58
+ $jsonData['IssueNumber'] = '***';
59
+ }
60
+ }
61
+
62
+ return $jsonData;
63
+ }
64
+
65
+ /**
66
+ * Normalize data to compatible with eWAY API
67
+ *
68
+ * @param $value
69
+ * @return $this
70
+ */
71
+ public function setExpiryMonth($value)
72
+ {
73
+ $value = (string) ($value < 10 ? '0' . $value : $value);
74
+ $this->setData('ExpiryMonth', $value);
75
+ return $this;
76
+ }
77
+
78
+ /**
79
+ * Normalize data to compatible with eWAY API
80
+ *
81
+ * @param $value
82
+ * @return $this
83
+ */
84
+ public function setExpiryYear($value)
85
+ {
86
+ $value = substr((string)$value, -2);
87
+ $this->setData('ExpiryYear', $value);
88
+ return $this;
89
+ }
90
  }
app/code/community/Eway/Rapid31/Model/JsonSerializableAbstract.php CHANGED
@@ -1,45 +1,45 @@
1
- <?php
2
- abstract class Eway_Rapid31_Model_JsonSerializableAbstract extends Varien_Object implements Eway_Rapid31_Model_JsonSerializable
3
- {
4
- /**
5
- * Recursively serialize json for all value in _data array in Varien_Object
6
- *
7
- * @param array $rawData
8
- * @return array
9
- */
10
- public function getJsonData(array $rawData = null)
11
- {
12
- if($rawData === null) {
13
- $rawData = $this->_data;
14
- }
15
-
16
- $jsonData = array();
17
- foreach ($rawData as $key => $value) {
18
- if (is_scalar($value)) {
19
- $jsonData[$key] = $value;
20
- } elseif (is_array($value)) {
21
- $jsonData[$key] = $this->getJsonData($value);
22
- } elseif (is_object($value) && $value instanceof Eway_Rapid31_Model_JsonSerializable) {
23
- $jsonData[$key] = $value->getJsonData();
24
- }
25
- }
26
-
27
- return $jsonData;
28
- }
29
-
30
- public function jsonSerialize()
31
- {
32
- return json_encode($this->getJsonData());
33
- }
34
-
35
- /**
36
- * Override Varien_Object::_underscore() to prevent transform of field name.
37
- *
38
- * @param string $name
39
- * @return string
40
- */
41
- protected function _underscore($name)
42
- {
43
- return $name;
44
- }
45
  }
1
+ <?php
2
+ abstract class Eway_Rapid31_Model_JsonSerializableAbstract extends Varien_Object implements Eway_Rapid31_Model_JsonSerializable
3
+ {
4
+ /**
5
+ * Recursively serialize json for all value in _data array in Varien_Object
6
+ *
7
+ * @param array $rawData
8
+ * @return array
9
+ */
10
+ public function getJsonData(array $rawData = null)
11
+ {
12
+ if ($rawData === null) {
13
+ $rawData = $this->_data;
14
+ }
15
+
16
+ $jsonData = array();
17
+ foreach ($rawData as $key => $value) {
18
+ if (is_scalar($value)) {
19
+ $jsonData[$key] = $value;
20
+ } elseif (is_array($value)) {
21
+ $jsonData[$key] = $this->getJsonData($value);
22
+ } elseif (is_object($value) && $value instanceof Eway_Rapid31_Model_JsonSerializable) {
23
+ $jsonData[$key] = $value->getJsonData();
24
+ }
25
+ }
26
+
27
+ return $jsonData;
28
+ }
29
+
30
+ public function jsonSerialize()
31
+ {
32
+ return json_encode($this->getJsonData());
33
+ }
34
+
35
+ /**
36
+ * Override Varien_Object::_underscore() to prevent transform of field name.
37
+ *
38
+ * @param string $name
39
+ * @return string
40
+ */
41
+ protected function _underscore($name)
42
+ {
43
+ return $name;
44
+ }
45
  }
app/code/community/Eway/Rapid31/Model/Method/Ewayone.php CHANGED
@@ -1,433 +1,432 @@
1
- <?php
2
- class Eway_Rapid31_Model_Method_Ewayone extends Eway_Rapid31_Model_Method_Notsaved implements Mage_Payment_Model_Recurring_Profile_MethodInterface
3
- {
4
- protected $_code = 'ewayrapid_ewayone';
5
-
6
- protected $_formBlockType = 'ewayrapid/form_direct_ewayone';
7
- protected $_infoBlockType = 'ewayrapid/info_direct_ewayone';
8
- protected $_canCapturePartial = true;
9
- protected $_billing = null;
10
-
11
- public function __construct()
12
- {
13
- parent::__construct();
14
- if (!$this->_isBackendOrder) {
15
- if (!Mage::helper('ewayrapid')->isBackendOrder()) {
16
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
17
- $this->_infoBlockType = 'ewayrapid/info_transparent_ewayone';
18
- $this->_formBlockType = 'ewayrapid/form_transparent_ewayone';
19
- } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
20
- $this->_infoBlockType = 'ewayrapid/info_sharedpage_ewayone';
21
- $this->_formBlockType = 'ewayrapid/form_sharedpage_ewayone';
22
- } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME) {
23
- $this->_infoBlockType = 'ewayrapid/info_sharedpage_ewayone';
24
- $this->_formBlockType = 'ewayrapid/form_sharedpage_ewayone';
25
- }
26
- }
27
- }
28
-
29
- if ($this->_isBackendOrder) {
30
- if (Mage::helper('ewayrapid')->isBackendOrder()) {
31
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
32
- // $this->_infoBlockType = 'ewayrapid/info_sharedpage_ewayone';
33
- $this->_formBlockType = 'ewayrapid/form_sharedpage_ewayone';
34
- } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME) {
35
- // $this->_infoBlockType = 'ewayrapid/info_sharedpage_ewayone';
36
- $this->_formBlockType = 'ewayrapid/form_sharedpage_ewayone';
37
- }
38
- }
39
- }
40
- }
41
-
42
- /**
43
- * Use the grandparent isAvailable
44
- *
45
- * @param Mage_Sales_Model_Quote|null $quote
46
- * @return boolean
47
- */
48
- public function isAvailable($quote = null) {
49
- return Mage_Payment_Model_Method_Abstract::isAvailable($quote);
50
- }
51
-
52
- /**
53
- * Assign data to info model instance
54
- *
55
- * @param mixed $data
56
- * @return Mage_Payment_Model_Info
57
- */
58
- public function assignData($data)
59
- {
60
- if (!($data instanceof Varien_Object)) {
61
- $data = new Varien_Object($data);
62
- }
63
- $info = $this->getInfoInstance();
64
- if($data->getSavedToken() == Eway_Rapid31_Model_Config::TOKEN_NEW) {
65
- Mage::helper('ewayrapid')->clearSessionSharedpage();
66
- Mage::getSingleton('core/session')->unsetData('visa_checkout_call_id');
67
- if (($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
68
- || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
69
- && !$this->_isBackendOrder && $data->getSaveCard()
70
- ) {
71
- Mage::getSingleton('core/session')->setData('newToken', 1);
72
- }
73
- if($data->getSaveCard()){
74
- $info->setIsNewToken(true);
75
- }
76
-
77
- if($this->_isBackendOrder
78
- && ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
79
- || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
80
- && $data->getSaveCard()
81
- ){
82
- Mage::getSingleton('core/session')->setData('newToken', 1);
83
- }
84
-
85
-
86
- } else {
87
- if ( ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
88
- && !$this->_isBackendOrder
89
- ) {
90
- Mage::getSingleton('core/session')->setData('editToken', $data->getSavedToken());
91
- }
92
-
93
- if($this->_isBackendOrder
94
- && ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
95
- || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
96
- ){
97
- Mage::getSingleton('core/session')->setData('editToken', $data->getSavedToken());
98
- }
99
-
100
- $info->setSavedToken($data->getSavedToken());
101
- // Update token
102
- if($data->getCcOwner() && $data->getSaveCard()) {
103
- $info->setIsUpdateToken(true);
104
- }
105
- }
106
-
107
- if ($this->_isBackendOrder &&
108
- ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
109
- || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
110
- ) {
111
- if ($data->getMethod()) {
112
- Mage::getSingleton('core/session')->setData('ewayMethod', $data->getMethod());
113
- }
114
- }
115
-
116
- if (!$this->_isBackendOrder &&
117
- ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
118
- || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
119
- ) {
120
- if ($data->getMethod()) {
121
- Mage::getSingleton('core/session')->setData('ewayMethod', $data->getMethod());
122
- }
123
- } elseif (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
124
- if($data->getVisaCheckoutCallId()){
125
- Mage::getSingleton('core/session')->setData('visa_checkout_call_id', $data->getVisaCheckoutCallId());
126
- }
127
- $info->setTransparentNotsaved($data->getTransparentNotsaved());
128
- $info->setTransparentSaved($data->getTransparentSaved());
129
-
130
- //Option choice
131
- if ($data->getMethod() == 'ewayrapid_ewayone' && !$data->getTransparentSaved()) {
132
- Mage::throwException(Mage::helper('payment')->__('Please select an option payment for eWay saved'));
133
- } elseif ($data->getMethod() == 'ewayrapid_notsaved' && !$data->getTransparentNotsaved()) {
134
- Mage::throwException(Mage::helper('payment')->__('Please select an option payment for eWay not saved'));
135
- }
136
-
137
- //New Token
138
- if ($data->getMethod() == 'ewayrapid_ewayone'
139
- && $data->getTransparentSaved() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
140
- && $data->getSavedToken() == Eway_Rapid31_Model_Config::TOKEN_NEW
141
- && Mage::helper('ewayrapid/customer')->checkTokenListByType(Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD)
142
- && $data->getSaveCard()
143
- ) {
144
- Mage::throwException(Mage::helper('payment')->__('You could only save one PayPal account, please select PayPal account existed to payent.'));
145
- }
146
-
147
- if ($data->getTransparentNotsaved())
148
- Mage::getSingleton('core/session')->setTransparentNotsaved($data->getTransparentNotsaved());
149
-
150
- if ($data->getTransparentSaved())
151
- Mage::getSingleton('core/session')->setTransparentSaved($data->getTransparentSaved());
152
-
153
- if ($data->getMethod())
154
- Mage::getSingleton('core/session')->setMethod($data->getMethod());
155
-
156
- // Add Save Card to session
157
- Mage::getSingleton('core/session')->setSaveCard($data->getSaveCard());
158
-
159
- if ($data->getSavedToken()) {
160
- Mage::getSingleton('core/session')->setSavedToken($data->getSavedToken());
161
- if(is_numeric($data->getSavedToken())) {
162
- $token = Mage::helper('ewayrapid/customer')->getTokenById($data->getSavedToken());
163
- /* @var Eway_Rapid31_Model_Request_Token $model */
164
- $model = Mage::getModel('ewayrapid/request_token');
165
- $type = $model->checkCardName($token);
166
- Mage::getSingleton('core/session')->setTransparentSaved($type);
167
- unset($model);
168
- unset($token);
169
- }
170
- }
171
-
172
- $infoCard = new Varien_Object();
173
- Mage::getSingleton('core/session')->setInfoCard(
174
- $infoCard->setCcType($data->getCcType())
175
- ->setOwner($data->getCcOwner())
176
- ->setLast4($this->_isClientSideEncrypted($data->getCcNumber()) ? 'encrypted' : substr($data->getCcNumber(), -4))
177
- ->setCard($data->getCcNumber())
178
- ->setNumber($data->getCcNumber())
179
- ->setCid($data->getCcCid())
180
- ->setExpMonth($data->getCcExpMonth())
181
- ->setExpYear($data->getCcExpYear()
182
- ));
183
-
184
- } else {
185
- $info->setCcType($data->getCcType())
186
- ->setCcOwner($data->getCcOwner())
187
- ->setCcLast4($this->_isClientSideEncrypted($data->getCcNumber()) ? 'encrypted' : substr($data->getCcNumber(), -4))
188
- ->setCcNumber($data->getCcNumber())
189
- ->setCcCid($data->getCcCid())
190
- ->setCcExpMonth($data->getCcExpMonth())
191
- ->setCcExpYear($data->getCcExpYear());
192
- }
193
-
194
- Mage::helper('ewayrapid')->serializeInfoInstance($info);
195
-
196
- return $this;
197
- }
198
-
199
- /**
200
- * Validate payment method information object
201
- *
202
- * @param Mage_Payment_Model_Info $info
203
- * @return Mage_Payment_Model_Abstract
204
- */
205
- public function validate()
206
- {
207
- $info = $this->getInfoInstance();
208
- if($info->getIsNewToken()) {
209
- parent::validate();
210
- } else {
211
- // TODO: Check if this token is still Active using GET /Customer endpoint.
212
- }
213
-
214
- return $this;
215
- }
216
-
217
- /**
218
- * Authorize & Capture a payment
219
- *
220
- * @param Varien_Object $payment
221
- * @param float $amount
222
- *
223
- * @return Mage_Payment_Model_Abstract
224
- */
225
- public function capture(Varien_Object $payment, $amount)
226
- {
227
- if (!$this->_isPreauthCapture($payment) && (
228
- $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
229
- || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)) {
230
- $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
231
- $payment->setTransactionId($transID);
232
- $payment->setIsTransactionClosed(0);
233
- Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
234
- return $this;
235
- } elseif (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
236
- //$payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
237
- Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
238
- return $this;
239
- }
240
-
241
- /* @var Mage_Sales_Model_Order_Payment $payment */
242
- if ($amount <= 0) {
243
- Mage::throwException(Mage::helper('payment')->__('Invalid amount for capture.'));
244
- }
245
- $info = $this->getInfoInstance();
246
- Mage::helper('ewayrapid')->unserializeInfoInstace($info);
247
-
248
- if(!$info->getIsNewToken() && !$info->getIsUpdateToken()){
249
- // Not new/update token
250
- if($info->getSavedToken() && is_numeric($info->getSavedToken())){
251
- // Saved token is numeric
252
- $request = Mage::getModel('ewayrapid/request_token');
253
- }else{
254
- $request = Mage::getModel('ewayrapid/request_direct');
255
- }
256
- }else{
257
- // New/update token
258
- $request = Mage::getModel('ewayrapid/request_token');
259
- }
260
-
261
- $amount = round($amount * 100);
262
- if($this->_isPreauthCapture($payment)) {
263
- $previousCapture = $payment->lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
264
- if($previousCapture) {
265
- $customer = Mage::getModel('customer/customer')->load($payment->getOrder()->getCustomerId());
266
- Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
267
-
268
- /* @var Mage_Sales_Model_Order_Payment_Transaction $previousCapture */
269
- $request->doTransaction($payment, $amount);
270
- $payment->setParentTransactionId($previousCapture->getParentTxnId());
271
- } else {
272
- $request->doCapturePayment($payment, $amount);
273
- }
274
- } else {
275
- if (!$payment->getIsRecurring()) {
276
- if($request instanceof Eway_Rapid31_Model_Request_Token){
277
- $this->_shouldCreateOrUpdateToken($payment, $request);
278
- }
279
-
280
- }
281
- $request->doTransaction($payment, $amount);
282
- }
283
-
284
- return $this;
285
- }
286
-
287
- /**
288
- * Authorize a payment
289
- *
290
- * @param Varien_Object $payment
291
- * @param float $amount
292
- *
293
- * @return Mage_Payment_Model_Abstract
294
- */
295
- public function authorize(Varien_Object $payment, $amount)
296
- {
297
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME) {
298
- $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
299
- $payment->setTransactionId($transID);
300
- $payment->setIsTransactionClosed(0);
301
- Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
302
- return $this;
303
- } elseif (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
304
- //$payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
305
- Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
306
- return $this;
307
- }
308
-
309
- /* @var Mage_Sales_Model_Order_Payment $payment */
310
- if ($amount <= 0) {
311
- Mage::throwException(Mage::helper('payment')->__('Invalid amount for authorize.'));
312
- }
313
- $info = $this->getInfoInstance();
314
- Mage::helper('ewayrapid')->unserializeInfoInstace($info);
315
-
316
- if(!$info->getIsNewToken() && !$info->getIsUpdateToken()){
317
- // Not new/update token
318
- if($info->getSavedToken() && is_numeric($info->getSavedToken())){
319
- // Saved token is numeric
320
- $request = Mage::getModel('ewayrapid/request_token');
321
- }else{
322
- $request = Mage::getModel('ewayrapid/request_direct');
323
- }
324
- }else{
325
- // New/update token
326
- $request = Mage::getModel('ewayrapid/request_token');
327
- }
328
-
329
- /** @todo there's an error in case recurring profile */
330
- if (!$payment->getIsRecurring()) {
331
- if($request instanceof Eway_Rapid31_Model_Request_Token){
332
- $this->_shouldCreateOrUpdateToken($payment, $request);
333
- }
334
- }
335
-
336
- $amount = round($amount * 100);
337
- $request->doAuthorisation($payment, $amount);
338
-
339
- return $this;
340
- }
341
-
342
- /**
343
- * @param Mage_Sales_Model_Order_Payment $payment
344
- * @param Eway_Rapid31_Model_Request_Token $request
345
- */
346
- public function _shouldCreateOrUpdateToken(Mage_Sales_Model_Order_Payment $payment, Eway_Rapid31_Model_Request_Token $request)
347
- {
348
- $order = $payment->getOrder();
349
- $billing = ($this->_getBilling() == null) ? $order->getBillingAddress() : $this->_getBilling();
350
- $info = $this->getInfoInstance();
351
-
352
- Mage::helper('ewayrapid')->unserializeInfoInstace($info);
353
- if ($info->getIsNewToken()) {
354
- $request->createNewToken($billing, $info);
355
- $info->setSavedToken(Mage::helper('ewayrapid/customer')->getLastTokenId());
356
- Mage::helper('ewayrapid')->serializeInfoInstance($info);
357
- } elseif ($info->getIsUpdateToken()) {
358
- $request->updateToken($billing, $info);
359
- }
360
- }
361
-
362
- public function _setBilling(Mage_Sales_Model_Quote_Address $billing)
363
- {
364
- $this->_billing = $billing;
365
- }
366
-
367
- public function _getBilling()
368
- {
369
- return $this->_billing;
370
- }
371
-
372
- /**
373
- * Validate RP data
374
- *
375
- * @param Mage_Payment_Model_Recurring_Profile $profile
376
- */
377
- public function validateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
378
- {
379
-
380
- }
381
-
382
- /**
383
- * Submit RP to the gateway
384
- *
385
- * @param Mage_Payment_Model_Recurring_Profile $profile
386
- * @param Mage_Payment_Model_Info $paymentInfo
387
- */
388
- public function submitRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile,
389
- Mage_Payment_Model_Info $paymentInfo
390
- ) {
391
- $profile->setReferenceId(strtoupper(uniqid()));
392
- $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE);
393
- }
394
-
395
- /**
396
- * Fetch RP details
397
- *
398
- * @param string $referenceId
399
- * @param Varien_Object $result
400
- */
401
- public function getRecurringProfileDetails($referenceId, Varien_Object $result)
402
- {
403
-
404
- }
405
-
406
- /**
407
- * Whether can get recurring profile details
408
- */
409
- public function canGetRecurringProfileDetails()
410
- {
411
- return true;
412
- }
413
-
414
- /**
415
- * Update RP data
416
- *
417
- * @param Mage_Payment_Model_Recurring_Profile $profile
418
- */
419
- public function updateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
420
- {
421
-
422
- }
423
-
424
- /**
425
- * Manage status
426
- *
427
- * @param Mage_Payment_Model_Recurring_Profile $profile
428
- */
429
- public function updateRecurringProfileStatus(Mage_Payment_Model_Recurring_Profile $profile)
430
- {
431
-
432
- }
433
  }
1
+ <?php
2
+ class Eway_Rapid31_Model_Method_Ewayone extends Eway_Rapid31_Model_Method_Notsaved implements Mage_Payment_Model_Recurring_Profile_MethodInterface
3
+ {
4
+ protected $_code = 'ewayrapid_ewayone';
5
+
6
+ protected $_formBlockType = 'ewayrapid/form_direct_ewayone';
7
+ protected $_infoBlockType = 'ewayrapid/info_direct_ewayone';
8
+ protected $_canCapturePartial = true;
9
+ protected $_billing = null;
10
+
11
+ public function __construct()
12
+ {
13
+ parent::__construct();
14
+ if (!$this->_isBackendOrder) {
15
+ if (!Mage::helper('ewayrapid')->isBackendOrder()) {
16
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
17
+ $this->_infoBlockType = 'ewayrapid/info_transparent_ewayone';
18
+ $this->_formBlockType = 'ewayrapid/form_transparent_ewayone';
19
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
20
+ $this->_infoBlockType = 'ewayrapid/info_sharedpage_ewayone';
21
+ $this->_formBlockType = 'ewayrapid/form_sharedpage_ewayone';
22
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME) {
23
+ $this->_infoBlockType = 'ewayrapid/info_sharedpage_ewayone';
24
+ $this->_formBlockType = 'ewayrapid/form_sharedpage_ewayone';
25
+ }
26
+ }
27
+ }
28
+
29
+ if ($this->_isBackendOrder) {
30
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
31
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
32
+ $this->_formBlockType = 'ewayrapid/form_sharedpage_ewayone';
33
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME) {
34
+ $this->_formBlockType = 'ewayrapid/form_sharedpage_ewayone';
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Use the grandparent isAvailable
42
+ *
43
+ * @param Mage_Sales_Model_Quote|null $quote
44
+ * @return boolean
45
+ */
46
+ public function isAvailable($quote = null)
47
+ {
48
+ return Mage_Payment_Model_Method_Abstract::isAvailable($quote);
49
+ }
50
+
51
+ /**
52
+ * Assign data to info model instance
53
+ *
54
+ * @param mixed $data
55
+ * @return Mage_Payment_Model_Info
56
+ */
57
+ public function assignData($data)
58
+ {
59
+ if (!($data instanceof Varien_Object)) {
60
+ $data = new Varien_Object($data);
61
+ }
62
+ $info = $this->getInfoInstance();
63
+ if ($data->getSavedToken() == Eway_Rapid31_Model_Config::TOKEN_NEW) {
64
+ Mage::helper('ewayrapid')->clearSessionSharedpage();
65
+ Mage::getSingleton('core/session')->unsetData('visa_checkout_call_id');
66
+ if (($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
67
+ || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
68
+ && !$this->_isBackendOrder && $data->getSaveCard()
69
+ ) {
70
+ Mage::getSingleton('core/session')->setData('newToken', 1);
71
+ }
72
+ if ($data->getSaveCard()) {
73
+ $info->setIsNewToken(true);
74
+ }
75
+
76
+ if ($this->_isBackendOrder
77
+ && ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
78
+ || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
79
+ && $data->getSaveCard()
80
+ ) {
81
+ Mage::getSingleton('core/session')->setData('newToken', 1);
82
+ }
83
+
84
+
85
+ } else {
86
+ if ( ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
87
+ && !$this->_isBackendOrder
88
+ ) {
89
+ Mage::getSingleton('core/session')->setData('editToken', $data->getSavedToken());
90
+ }
91
+
92
+ if ($this->_isBackendOrder
93
+ && ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
94
+ || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
95
+ ) {
96
+ Mage::getSingleton('core/session')->setData('editToken', $data->getSavedToken());
97
+ }
98
+
99
+ $info->setSavedToken($data->getSavedToken());
100
+ // Update token
101
+ if ($data->getCcOwner() && $data->getSaveCard()) {
102
+ $info->setIsUpdateToken(true);
103
+ }
104
+ }
105
+
106
+ if ($this->_isBackendOrder &&
107
+ ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
108
+ || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
109
+ ) {
110
+ if ($data->getMethod()) {
111
+ Mage::getSingleton('core/session')->setData('ewayMethod', $data->getMethod());
112
+ }
113
+ }
114
+
115
+ if (!$this->_isBackendOrder &&
116
+ ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
117
+ || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)
118
+ ) {
119
+ if ($data->getMethod()) {
120
+ Mage::getSingleton('core/session')->setData('ewayMethod', $data->getMethod());
121
+ }
122
+ } elseif (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
123
+ if ($data->getVisaCheckoutCallId()) {
124
+ Mage::getSingleton('core/session')->setData('visa_checkout_call_id', $data->getVisaCheckoutCallId());
125
+ }
126
+ $info->setTransparentNotsaved($data->getTransparentNotsaved());
127
+ $info->setTransparentSaved($data->getTransparentSaved());
128
+
129
+ //Option choice
130
+ if ($data->getMethod() == 'ewayrapid_ewayone' && !$data->getTransparentSaved()) {
131
+ Mage::throwException(Mage::helper('payment')->__('Please select an option payment for eWay saved'));
132
+ } elseif ($data->getMethod() == 'ewayrapid_notsaved' && !$data->getTransparentNotsaved()) {
133
+ Mage::throwException(Mage::helper('payment')->__('Please select an option payment for eWay not saved'));
134
+ }
135
+
136
+ //New Token
137
+ if ($data->getMethod() == 'ewayrapid_ewayone'
138
+ && $data->getTransparentSaved() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
139
+ && $data->getSavedToken() == Eway_Rapid31_Model_Config::TOKEN_NEW
140
+ && Mage::helper('ewayrapid/customer')->checkTokenListByType(Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD)
141
+ && $data->getSaveCard()
142
+ ) {
143
+ Mage::throwException(Mage::helper('payment')->__('You could only save one PayPal account, please select PayPal account existed to payent.'));
144
+ }
145
+
146
+ if ($data->getTransparentNotsaved())
147
+ Mage::getSingleton('core/session')->setTransparentNotsaved($data->getTransparentNotsaved());
148
+
149
+ if ($data->getTransparentSaved())
150
+ Mage::getSingleton('core/session')->setTransparentSaved($data->getTransparentSaved());
151
+
152
+ if ($data->getMethod())
153
+ Mage::getSingleton('core/session')->setMethod($data->getMethod());
154
+
155
+ // Add Save Card to session
156
+ Mage::getSingleton('core/session')->setSaveCard($data->getSaveCard());
157
+
158
+ if ($data->getSavedToken()) {
159
+ Mage::getSingleton('core/session')->setSavedToken($data->getSavedToken());
160
+ if (is_numeric($data->getSavedToken())) {
161
+ $token = Mage::helper('ewayrapid/customer')->getTokenById($data->getSavedToken());
162
+ /* @var Eway_Rapid31_Model_Request_Token $model */
163
+ $model = Mage::getModel('ewayrapid/request_token');
164
+ $type = $model->checkCardName($token);
165
+ Mage::getSingleton('core/session')->setTransparentSaved($type);
166
+ unset($model);
167
+ unset($token);
168
+ }
169
+ }
170
+
171
+ $infoCard = new Varien_Object();
172
+ Mage::getSingleton('core/session')->setInfoCard(
173
+ $infoCard->setCcType($data->getCcType())
174
+ ->setOwner($data->getCcOwner())
175
+ ->setLast4($this->_isClientSideEncrypted($data->getCcNumber()) ? 'encrypted' : substr($data->getCcNumber(), -4))
176
+ ->setCard($data->getCcNumber())
177
+ ->setNumber($data->getCcNumber())
178
+ ->setCid($data->getCcCid())
179
+ ->setExpMonth($data->getCcExpMonth())
180
+ ->setExpYear(
181
+ $data->getCcExpYear()
182
+ )
183
+ );
184
+
185
+ } else {
186
+ $info->setCcType($data->getCcType())
187
+ ->setCcOwner($data->getCcOwner())
188
+ ->setCcLast4($this->_isClientSideEncrypted($data->getCcNumber()) ? 'encrypted' : substr($data->getCcNumber(), -4))
189
+ ->setCcNumber($data->getCcNumber())
190
+ ->setCcCid($data->getCcCid())
191
+ ->setCcExpMonth($data->getCcExpMonth())
192
+ ->setCcExpYear($data->getCcExpYear());
193
+ }
194
+
195
+ Mage::helper('ewayrapid')->serializeInfoInstance($info);
196
+
197
+ return $this;
198
+ }
199
+
200
+ /**
201
+ * Validate payment method information object
202
+ *
203
+ * @param Mage_Payment_Model_Info $info
204
+ * @return Mage_Payment_Model_Abstract
205
+ */
206
+ public function validate()
207
+ {
208
+ $info = $this->getInfoInstance();
209
+ if ($info->getIsNewToken()) {
210
+ parent::validate();
211
+ }
212
+ // TODO: Check if this token is still Active using GET /Customer endpoint.
213
+
214
+ return $this;
215
+ }
216
+
217
+ /**
218
+ * Authorize & Capture a payment
219
+ *
220
+ * @param Varien_Object $payment
221
+ * @param float $amount
222
+ *
223
+ * @return Mage_Payment_Model_Abstract
224
+ */
225
+ public function capture(Varien_Object $payment, $amount)
226
+ {
227
+ if (!$this->_isPreauthCapture($payment) && (
228
+ $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
229
+ || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME)) {
230
+ $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
231
+ $payment->setTransactionId($transID);
232
+ $payment->setIsTransactionClosed(0);
233
+ Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
234
+ return $this;
235
+ } elseif (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
236
+ Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
237
+ return $this;
238
+ }
239
+
240
+ /* @var Mage_Sales_Model_Order_Payment $payment */
241
+ if ($amount <= 0) {
242
+ Mage::throwException(Mage::helper('payment')->__('Invalid amount for capture.'));
243
+ }
244
+ $info = $this->getInfoInstance();
245
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
246
+
247
+ if (!$info->getIsNewToken() && !$info->getIsUpdateToken()) {
248
+ // Not new/update token
249
+ if ($info->getSavedToken() && is_numeric($info->getSavedToken())) {
250
+ // Saved token is numeric
251
+ $request = Mage::getModel('ewayrapid/request_token');
252
+ } else {
253
+ $request = Mage::getModel('ewayrapid/request_direct');
254
+ }
255
+ } else {
256
+ // New/update token
257
+ $request = Mage::getModel('ewayrapid/request_token');
258
+ }
259
+
260
+ $amount = round($amount * 100);
261
+ if ($this->_isPreauthCapture($payment)) {
262
+ $previousCapture = $payment->lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
263
+ if ($previousCapture) {
264
+ $customer = Mage::getModel('customer/customer')->load($payment->getOrder()->getCustomerId());
265
+ Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
266
+
267
+ /* @var Mage_Sales_Model_Order_Payment_Transaction $previousCapture */
268
+ $request->doTransaction($payment, $amount);
269
+ $payment->setParentTransactionId($previousCapture->getParentTxnId());
270
+ } else {
271
+ $request->doCapturePayment($payment, $amount);
272
+ }
273
+ } else {
274
+ if (!$payment->getIsRecurring()) {
275
+ if ($request instanceof Eway_Rapid31_Model_Request_Token) {
276
+ $this->_shouldCreateOrUpdateToken($payment, $request);
277
+ }
278
+
279
+ }
280
+ $request->doTransaction($payment, $amount);
281
+ }
282
+
283
+ return $this;
284
+ }
285
+
286
+ /**
287
+ * Authorize a payment
288
+ *
289
+ * @param Varien_Object $payment
290
+ * @param float $amount
291
+ *
292
+ * @return Mage_Payment_Model_Abstract
293
+ */
294
+ public function authorize(Varien_Object $payment, $amount)
295
+ {
296
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME) {
297
+ $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
298
+ $payment->setTransactionId($transID);
299
+ $payment->setIsTransactionClosed(0);
300
+ Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
301
+ return $this;
302
+ } elseif (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
303
+ Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
304
+ return $this;
305
+ }
306
+
307
+ /* @var Mage_Sales_Model_Order_Payment $payment */
308
+ if ($amount <= 0) {
309
+ Mage::throwException(Mage::helper('payment')->__('Invalid amount for authorize.'));
310
+ }
311
+ $info = $this->getInfoInstance();
312
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
313
+
314
+ if (!$info->getIsNewToken() && !$info->getIsUpdateToken()) {
315
+ // Not new/update token
316
+ if ($info->getSavedToken() && is_numeric($info->getSavedToken())) {
317
+ // Saved token is numeric
318
+ $request = Mage::getModel('ewayrapid/request_token');
319
+ } else {
320
+ $request = Mage::getModel('ewayrapid/request_direct');
321
+ }
322
+ } else {
323
+ // New/update token
324
+ $request = Mage::getModel('ewayrapid/request_token');
325
+ }
326
+
327
+ /** @todo there's an error in case recurring profile */
328
+ if (!$payment->getIsRecurring()) {
329
+ if ($request instanceof Eway_Rapid31_Model_Request_Token) {
330
+ $this->_shouldCreateOrUpdateToken($payment, $request);
331
+ }
332
+ }
333
+
334
+ $amount = round($amount * 100);
335
+ $request->doAuthorisation($payment, $amount);
336
+
337
+ return $this;
338
+ }
339
+
340
+ /**
341
+ * @param Mage_Sales_Model_Order_Payment $payment
342
+ * @param Eway_Rapid31_Model_Request_Token $request
343
+ */
344
+ public function _shouldCreateOrUpdateToken(Mage_Sales_Model_Order_Payment $payment, Eway_Rapid31_Model_Request_Token $request)
345
+ {
346
+ $order = $payment->getOrder();
347
+ $billing = ($this->_getBilling() == null) ? $order->getBillingAddress() : $this->_getBilling();
348
+ $info = $this->getInfoInstance();
349
+
350
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
351
+ if ($info->getIsNewToken()) {
352
+ $request->createNewToken($billing, $info);
353
+ $info->setSavedToken(Mage::helper('ewayrapid/customer')->getLastTokenId());
354
+ Mage::helper('ewayrapid')->serializeInfoInstance($info);
355
+ } elseif ($info->getIsUpdateToken()) {
356
+ $request->updateToken($billing, $info);
357
+ }
358
+ }
359
+
360
+ public function _setBilling(Mage_Sales_Model_Quote_Address $billing)
361
+ {
362
+ $this->_billing = $billing;
363
+ }
364
+
365
+ public function _getBilling()
366
+ {
367
+ return $this->_billing;
368
+ }
369
+
370
+ /**
371
+ * Validate RP data
372
+ *
373
+ * @param Mage_Payment_Model_Recurring_Profile $profile
374
+ */
375
+ public function validateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
376
+ {
377
+
378
+ }
379
+
380
+ /**
381
+ * Submit RP to the gateway
382
+ *
383
+ * @param Mage_Payment_Model_Recurring_Profile $profile
384
+ * @param Mage_Payment_Model_Info $paymentInfo
385
+ */
386
+ public function submitRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile,
387
+ Mage_Payment_Model_Info $paymentInfo
388
+ )
389
+ {
390
+ $profile->setReferenceId(strtoupper(uniqid()));
391
+ $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE);
392
+ }
393
+
394
+ /**
395
+ * Fetch RP details
396
+ *
397
+ * @param string $referenceId
398
+ * @param Varien_Object $result
399
+ */
400
+ public function getRecurringProfileDetails($referenceId, Varien_Object $result)
401
+ {
402
+
403
+ }
404
+
405
+ /**
406
+ * Whether can get recurring profile details
407
+ */
408
+ public function canGetRecurringProfileDetails()
409
+ {
410
+ return true;
411
+ }
412
+
413
+ /**
414
+ * Update RP data
415
+ *
416
+ * @param Mage_Payment_Model_Recurring_Profile $profile
417
+ */
418
+ public function updateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
419
+ {
420
+
421
+ }
422
+
423
+ /**
424
+ * Manage status
425
+ *
426
+ * @param Mage_Payment_Model_Recurring_Profile $profile
427
+ */
428
+ public function updateRecurringProfileStatus(Mage_Payment_Model_Recurring_Profile $profile)
429
+ {
430
+
431
+ }
 
432
  }
app/code/community/Eway/Rapid31/Model/Method/Notsaved.php CHANGED
@@ -1,543 +1,525 @@
1
- <?php
2
- class Eway_Rapid31_Model_Method_Notsaved extends Mage_Payment_Model_Method_Abstract
3
- {
4
- protected $_code = 'ewayrapid_notsaved';
5
-
6
- protected $_formBlockType = 'ewayrapid/form_direct_notsaved';
7
- protected $_infoBlockType = 'ewayrapid/info_direct_notsaved';
8
- protected $_canSaveCc = false;
9
-
10
- /**
11
- * Payment Method features
12
- * @var bool
13
- */
14
- protected $_isGateway = true;
15
- protected $_canAuthorize = true;
16
- protected $_canCapture = true;
17
- protected $_canCapturePartial = false;
18
- protected $_canRefund = true;
19
- protected $_canRefundInvoicePartial = true;
20
- protected $_canVoid = true;
21
- protected $_canUseInternal = true;
22
- protected $_canUseCheckout = true;
23
- protected $_canUseForMultishipping = true;
24
- protected $_isInitializeNeeded = false;
25
- protected $_canFetchTransactionInfo = true;
26
- protected $_canReviewPayment = false;
27
- protected $_canCreateBillingAgreement = false;
28
- protected $_canManageRecurringProfiles = true;
29
- protected $_connectionType;
30
- protected $_isBackendOrder;
31
-
32
- public static $_extension = false;
33
- public function __construct()
34
- {
35
- parent::__construct();
36
- $this->_isBackendOrder = Mage::helper('ewayrapid')->isBackendOrder();
37
- $this->_connectionType = Mage::getStoreConfig('payment/ewayrapid_general/connection_type');
38
- if (!$this->_isBackendOrder) {
39
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
40
- $this->_infoBlockType = 'ewayrapid/info_transparent_notsaved';
41
- $this->_formBlockType = 'ewayrapid/form_transparent_notsaved';
42
- } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
43
- $this->_infoBlockType = 'ewayrapid/info_sharedpage_notsaved';
44
- $this->_formBlockType = 'ewayrapid/form_sharedpage_notsaved';
45
- }
46
- }
47
-
48
- if($this->_isBackendOrder){
49
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
50
- || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
51
- ) {
52
- $this->_infoBlockType = 'ewayrapid/info_sharedpage_notsaved';
53
- $this->_formBlockType = 'ewayrapid/form_sharedpage_notsaved';
54
- }
55
- }
56
- }
57
-
58
- /**
59
- * As of version 1.4.0 this payment method isn't used.
60
- *
61
- * @param Mage_Sales_Model_Quote|null $quote
62
- * @return boolean
63
- */
64
- public function isAvailable($quote = null) {
65
- return false;
66
- }
67
-
68
- public function getConfigData($field, $storeId = null)
69
- {
70
- $data = parent::getConfigData($field, $storeId);
71
- if($data === null) {
72
- return $this->_getGeneralConfig($field, $storeId);
73
- } else {
74
- switch($field) {
75
- case 'active':
76
- return $data && $this->_isActive($storeId);
77
- default:
78
- return $data;
79
- }
80
- }
81
- }
82
-
83
- protected function _getGeneralConfig($field, $storeId = null)
84
- {
85
- if (null === $storeId) {
86
- $storeId = $this->getStore();
87
- }
88
- $path = 'payment/ewayrapid_general/'.$field;
89
- return Mage::getStoreConfig($path, $storeId);
90
- }
91
-
92
- protected function _isActive($storeId)
93
- {
94
- return $this->_getGeneralConfig('active', $storeId);
95
- }
96
-
97
- /**
98
- * Assign data to info model instance
99
- *
100
- * @param mixed $data
101
- * @return Mage_Payment_Model_Info
102
- */
103
- public function assignData($data)
104
- {
105
- if (!($data instanceof Varien_Object)) {
106
- $data = new Varien_Object($data);
107
- }
108
- $info = $this->getInfoInstance();
109
-
110
- if (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
111
- // Mage::helper('ewayrapid')->clearSessionSharedpage();
112
- //Mage::getSingleton('core/session')->setData('sharedpagePaypal', $data->getSharedpageNotsaved());
113
- // Mage::getSingleton('core/session')->setData('sharedpagePaypal', 'paypal');
114
- if ($data->getMethod()) {
115
- Mage::getSingleton('core/session')->setData('ewayMethod', $data->getMethod());
116
- }
117
- } elseif (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
118
- $info->setTransparentNotsaved($data->getTransparentNotsaved());
119
-
120
- //Option choice
121
- if ($data->getMethod() == 'ewayrapid_saved' && !$data->getTransparentSaved()) {
122
- Mage::throwException(Mage::helper('payment')->__('Please select an option payment for saved'));
123
- } elseif ($data->getMethod() == 'ewayrapid_notsaved' && !$data->getTransparentNotsaved()) {
124
- Mage::throwException(Mage::helper('payment')->__('Please select an option payment for not saved'));
125
- }
126
-
127
- //New Token
128
- if ($data->getMethod() == 'ewayrapid_saved'
129
- && $data->getTransparentSaved() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
130
- && $data->getSavedToken() == Eway_Rapid31_Model_Config::TOKEN_NEW
131
- && Mage::helper('ewayrapid/customer')->checkTokenListByType(Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD)
132
- ) {
133
- Mage::throwException(Mage::helper('payment')->__('You can only save one PayPal account, please select existing PayPal account.'));
134
- }
135
-
136
- if ($data->getTransparentNotsaved())
137
- Mage::getSingleton('core/session')->setTransparentNotsaved($data->getTransparentNotsaved());
138
-
139
- if ($data->getTransparentSaved())
140
- Mage::getSingleton('core/session')->setTransparentSaved($data->getTransparentSaved());
141
-
142
- if ($data->getMethod())
143
- Mage::getSingleton('core/session')->setMethod($data->getMethod());
144
-
145
- if ($data->getSavedToken()) {
146
- Mage::getSingleton('core/session')->setSavedToken($data->getSavedToken());
147
- if(is_numeric($data->getSavedToken())) {
148
- $token = Mage::helper('ewayrapid/customer')->getTokenById($data->getSavedToken());
149
- /* @var Eway_Rapid31_Model_Request_Token $model */
150
- $model = Mage::getModel('ewayrapid/request_token');
151
- $type = $model->checkCardName($token);
152
- Mage::getSingleton('core/session')->setTransparentSaved($type);
153
- unset($model);
154
- unset($token);
155
- }
156
- }
157
-
158
- $infoCard = new Varien_Object();
159
- Mage::getSingleton('core/session')->setInfoCard(
160
- $infoCard->setCcType($data->getCcType())
161
- ->setOwner($data->getCcOwner())
162
- ->setLast4($this->_isClientSideEncrypted($data->getCcNumber()) ? 'encrypted' : substr($data->getCcNumber(), -4))
163
- ->setCard($data->getCcNumber())
164
- ->setNumber($data->getCcNumber())
165
- ->setCid($data->getCcCid())
166
- ->setExpMonth($data->getCcExpMonth())
167
- ->setExpYear($data->getCcExpYear()
168
- ));
169
-
170
- } else {
171
- $info->setCcType($data->getCcType())
172
- ->setCcOwner($data->getCcOwner())
173
- ->setCcLast4($this->_isClientSideEncrypted($data->getCcNumber()) ? 'encrypted' : substr($data->getCcNumber(), -4))
174
- ->setCcNumber($data->getCcNumber())
175
- ->setCcCid($data->getCcCid())
176
- ->setCcExpMonth($data->getCcExpMonth())
177
- ->setCcExpYear($data->getCcExpYear());
178
- }
179
-
180
- return $this;
181
- }
182
-
183
- protected function _isClientSideEncrypted($ccNumber)
184
- {
185
- return (strlen($ccNumber) > 19 && strpos($ccNumber, Eway_Rapid31_Model_Config::ENCRYPTION_PREFIX) !== false);
186
- }
187
-
188
- /**
189
- * Validate payment method information object
190
- *
191
- * @param Mage_Payment_Model_Info $info
192
- * @return Mage_Payment_Model_Abstract
193
- */
194
- public function validate()
195
- {
196
- /*
197
- * calling parent validate function
198
- */
199
- parent::validate();
200
- if (!$this->_isBackendOrder) {
201
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME) {
202
- return $this;
203
- } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
204
- return $this;
205
- }
206
- }
207
-
208
- if($this->_isBackendOrder
209
- && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
210
- || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
211
- ){
212
- return $this;
213
- }
214
-
215
- $info = $this->getInfoInstance();
216
- $errorMsg = false;
217
- $availableTypes = explode(',',$this->getConfigData('cctypes'));
218
-
219
- $ccNumber = $info->getCcNumber();
220
-
221
- // Cannot do normal validation in case client side encrypted
222
- if($this->_isClientSideEncrypted($ccNumber)) {
223
- return true;
224
- }
225
-
226
- // remove credit card number delimiters such as "-" and space
227
- $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
228
- $info->setCcNumber($ccNumber);
229
-
230
- $ccType = '';
231
-
232
- if (in_array($info->getCcType(), $availableTypes)){
233
- if ($this->validateCcNum($ccNumber)) {
234
- $ccTypeRegExpList = array(
235
- // Visa Electron
236
- 'VE' => '/^(4026|4405|4508|4844|4913|4917)[0-9]{12}|417500[0-9]{10}$/',
237
- // Maestro
238
- 'ME' => '/(^(5[0678])[0-9]{11,18}$)|(^(6[^05])[0-9]{11,18}$)|(^(601)[^1][0-9]{9,16}$)|(^(6011)[0-9]{9,11}$)|(^(6011)[0-9]{13,16}$)|(^(65)[0-9]{11,13}$)|(^(65)[0-9]{15,18}$)|(^(49030)[2-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49033)[5-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49110)[1-2]([0-9]{10}$|[0-9]{12,13}$))|(^(49117)[4-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49118)[0-2]([0-9]{10}$|[0-9]{12,13}$))|(^(4936)([0-9]{12}$|[0-9]{14,15}$))/',
239
- // Visa
240
- 'VI' => '/^4[0-9]{12}([0-9]{3})?$/',
241
- // Master Card
242
- 'MC' => '/^5[1-5][0-9]{14}$/',
243
- // Master Card 2017 - new MasterCard Range 2221-2720
244
- //'MC' => '/(^5[1-5][0-9]{14}$)|(^2221[0-9]{12}$)|(^222[2-9][0-9]{12}$)|(^22[3-9][0-9]{13}$)|(^2[3-6][0-9]{14}$)|(^2720[0-9]{12}$)|(^27[0-1][0-9]{13}$)/',
245
- // American Express
246
- 'AE' => '/^3[47][0-9]{13}$/',
247
- // JCB
248
- 'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/',
249
- // Diners Club
250
- 'DC' => '/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/',
251
- );
252
-
253
- foreach ($ccTypeRegExpList as $ccTypeMatch=>$ccTypeRegExp) {
254
- if (preg_match($ccTypeRegExp, $ccNumber)) {
255
- $ccType = $ccTypeMatch;
256
- break;
257
- }
258
- }
259
-
260
- if ($ccType!=$info->getCcType()) {
261
- $errorMsg = Mage::helper('payment')->__('Please enter a valid credit card number.');
262
- }
263
- } else {
264
- $errorMsg = Mage::helper('payment')->__('Invalid Credit Card Number');
265
- }
266
-
267
- } else {
268
- $errorMsg = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
269
- }
270
-
271
- //validate credit card verification number
272
- if ($errorMsg === false && $this->hasVerification()) {
273
- $verifcationRegEx = $this->getVerificationRegEx();
274
- $regExp = isset($verifcationRegEx[$info->getCcType()]) ? $verifcationRegEx[$info->getCcType()] : '';
275
- if (!$info->getCcCid() || !$regExp || !preg_match($regExp ,$info->getCcCid())){
276
- $errorMsg = Mage::helper('payment')->__('Please enter a valid credit card verification number.');
277
- }
278
- }
279
-
280
- if (!$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth())) {
281
- $errorMsg = Mage::helper('payment')->__('Incorrect credit card expiration date.');
282
- }
283
-
284
- if($errorMsg){
285
- Mage::throwException($errorMsg);
286
- }
287
-
288
- return $this;
289
- }
290
-
291
- public function hasVerification()
292
- {
293
- if(Mage::helper('ewayrapid')->isBackendOrder()) {
294
- return false;
295
- }
296
-
297
- $configData = $this->getConfigData('useccv');
298
- if(is_null($configData)){
299
- return true;
300
- }
301
- return (bool) $configData;
302
- }
303
-
304
- public function getVerificationRegEx()
305
- {
306
- $verificationExpList = array(
307
- 'VI' => '/^[0-9]{3}$/', // Visa
308
- 'VE' => '/^[0-9]{3}$/', // Visa Electron
309
- 'MC' => '/^[0-9]{3}$/', // Master Card
310
- 'ME' => '/^[0-9]{3,4}$/', // Maestro
311
- 'AE' => '/^[0-9]{4}$/', // American Express
312
- 'DC' => '/^[0-9]{3}$/', // Diners Club
313
- 'JCB' => '/^[0-9]{3,4}$/' //JCB
314
- );
315
- return $verificationExpList;
316
- }
317
-
318
- protected function _validateExpDate($expYear, $expMonth)
319
- {
320
- $date = Mage::app()->getLocale()->date();
321
- if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
322
- || ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1))
323
- ) {
324
- return false;
325
- }
326
- return true;
327
- }
328
-
329
- /**
330
- * Validate credit card number
331
- *
332
- * @param string $cc_number
333
- * @return bool
334
- */
335
- public function validateCcNum($ccNumber)
336
- {
337
- $cardNumber = strrev($ccNumber);
338
- $numSum = 0;
339
-
340
- for ($i=0; $i<strlen($cardNumber); $i++) {
341
- $currentNum = substr($cardNumber, $i, 1);
342
-
343
- /**
344
- * Double every second digit
345
- */
346
- if ($i % 2 == 1) {
347
- $currentNum *= 2;
348
- }
349
-
350
- /**
351
- * Add digits of 2-digit numbers together
352
- */
353
- if ($currentNum > 9) {
354
- $firstNum = $currentNum % 10;
355
- $secondNum = ($currentNum - $firstNum) / 10;
356
- $currentNum = $firstNum + $secondNum;
357
- }
358
-
359
- $numSum += $currentNum;
360
- }
361
-
362
- /**
363
- * If the total has no remainder it's OK
364
- */
365
- return ($numSum % 10 == 0);
366
- }
367
-
368
- /**
369
- * Authorize & Capture a payment
370
- *
371
- * @param Varien_Object $payment
372
- * @param float $amount
373
- *
374
- * @return Mage_Payment_Model_Abstract
375
- */
376
- public function capture(Varien_Object $payment, $amount)
377
- {
378
- if (!$this->_isBackendOrder) {
379
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
380
- $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
381
- $payment->setTransactionId($transID);
382
- $payment->setIsTransactionClosed(0);
383
- Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
384
- return $this;
385
- } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
386
- $payment = Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
387
- return $this;
388
- }
389
- }
390
-
391
- if ($this->_isBackendOrder) {
392
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
393
- || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
394
- ) {
395
- return $this;
396
- }
397
- }
398
-
399
- /* @var Mage_Sales_Model_Order_Payment $payment */
400
- if ($amount <= 0) {
401
- Mage::throwException(Mage::helper('payment')->__('Invalid amount for capture.'));
402
- }
403
-
404
- $amount = round($amount * 100);
405
- $request = Mage::getModel('ewayrapid/request_direct');
406
- if($this->_isPreauthCapture($payment)) {
407
- $request->doCapturePayment($payment, $amount);
408
- } else {
409
- $request->doTransaction($payment, $amount);
410
- }
411
-
412
- return $this;
413
- }
414
-
415
- /**
416
- * Authorize a payment
417
- *
418
- * @param Varien_Object $payment
419
- * @param float $amount
420
- *
421
- * @return Mage_Payment_Model_Abstract
422
- */
423
- public function authorize(Varien_Object $payment, $amount)
424
- {
425
- if (!$this->_isBackendOrder) {
426
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
427
- $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
428
- $payment->setTransactionId($transID);
429
- $payment->setIsTransactionClosed(0);
430
- Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
431
- return $this;
432
- } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
433
- $payment = Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
434
- return $this;
435
- }
436
- }
437
-
438
- if ($this->_isBackendOrder) {
439
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
440
- || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
441
- ) {
442
- return $this;
443
- }
444
- }
445
-
446
- /* @var Mage_Sales_Model_Order_Payment $payment */
447
- if ($amount <= 0) {
448
- Mage::throwException(Mage::helper('payment')->__('Invalid amount for authorize.'));
449
- }
450
-
451
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
452
- ) {
453
- //Mage::app()->getResponse()->setRedirect(Mage::getUrl('ewayrapid/transparent/'))->sendResponse();
454
- //exit;
455
- }
456
-
457
- $amount = round($amount * 100);
458
- $request = Mage::getModel('ewayrapid/request_direct');
459
- $request->doAuthorisation($payment, $amount);
460
-
461
- return $this;
462
- }
463
-
464
- /**
465
- * Refund a payment
466
- *
467
- * @param Varien_Object $payment
468
- * @param float $amount
469
- *
470
- * @return Mage_Payment_Model_Abstract
471
- */
472
- public function refund(Varien_Object $payment, $amount)
473
- {
474
- /* @var Mage_Sales_Model_Order_Payment $payment */
475
- if ($amount <= 0) {
476
- Mage::throwException(Mage::helper('payment')->__('Invalid amount for refund.'));
477
- }
478
-
479
- $amount = round($amount * 100);
480
- $request = Mage::getModel('ewayrapid/request_direct');
481
- $request->doRefund($payment, $amount);
482
-
483
- return $this;
484
- }
485
-
486
- /**
487
- * Cancel a payment
488
- *
489
- * @param Varien_Object $payment
490
- *
491
- * @return Mage_Payment_Model_Abstract
492
- */
493
- public function cancel(Varien_Object $payment)
494
- {
495
- /* @var Mage_Sales_Model_Order_Payment $payment */
496
- $request = Mage::getModel('ewayrapid/request_direct');
497
- $request->doCancel($payment);
498
-
499
- return $this;
500
- }
501
-
502
- protected function _isPreauthCapture(Mage_Sales_Model_Order_Payment $payment)
503
- {
504
- return (bool) $payment->getLastTransId();
505
- }
506
-
507
- public function canVoid(Varien_Object $payment)
508
- {
509
- return $this->_canVoid && (Mage::app()->getRequest()->getActionName() == 'cancel');
510
- }
511
-
512
- public function getCheckoutRedirectUrl()
513
- {
514
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
515
- === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
516
- ) {
517
- return Mage::getUrl('ewayrapid/sharedpage/start', array('_secure'=>true));
518
- }
519
- elseif (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
520
- === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
521
- && Mage::getSingleton('core/session')->getCheckoutExtension()
522
- ){
523
- return Mage::getUrl('ewayrapid/sharedpage/iframe', array('_secure'=>true));
524
- }
525
- elseif (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
526
- === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
527
- && Mage::getSingleton('core/session')->getCheckoutExtension()
528
- ) {
529
- return Mage::getUrl('ewayrapid/transparent/build', array('_secure'=>true));
530
- }
531
- /*elseif (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
532
- === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
533
- && (Mage::getStoreConfig('onestepcheckout/general/active')
534
- || Mage::getStoreConfig('opc/global/status')
535
- || Mage::getStoreConfig('firecheckout/general/enabled')
536
- || Mage::getStoreConfig('gomage_checkout/general/enabled')
537
- || Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links'))
538
- ) {
539
- return Mage::getUrl('ewayrapid/transparent/build', array('_secure'=>true));
540
- }*/
541
- return null;
542
- }
543
  }
1
+ <?php
2
+ class Eway_Rapid31_Model_Method_Notsaved extends Mage_Payment_Model_Method_Abstract
3
+ {
4
+ protected $_code = 'ewayrapid_notsaved';
5
+
6
+ protected $_formBlockType = 'ewayrapid/form_direct_notsaved';
7
+ protected $_infoBlockType = 'ewayrapid/info_direct_notsaved';
8
+ protected $_canSaveCc = false;
9
+
10
+ /**
11
+ * Payment Method features
12
+ * @var bool
13
+ */
14
+ protected $_isGateway = true;
15
+ protected $_canAuthorize = true;
16
+ protected $_canCapture = true;
17
+ protected $_canCapturePartial = false;
18
+ protected $_canRefund = true;
19
+ protected $_canRefundInvoicePartial = true;
20
+ protected $_canVoid = true;
21
+ protected $_canUseInternal = true;
22
+ protected $_canUseCheckout = true;
23
+ protected $_canUseForMultishipping = true;
24
+ protected $_isInitializeNeeded = false;
25
+ protected $_canFetchTransactionInfo = true;
26
+ protected $_canReviewPayment = false;
27
+ protected $_canCreateBillingAgreement = false;
28
+ protected $_canManageRecurringProfiles = true;
29
+ protected $_connectionType;
30
+ protected $_isBackendOrder;
31
+
32
+ public static $extension = false;
33
+ public function __construct()
34
+ {
35
+ parent::__construct();
36
+ $this->_isBackendOrder = Mage::helper('ewayrapid')->isBackendOrder();
37
+ $this->_connectionType = Mage::getStoreConfig('payment/ewayrapid_general/connection_type');
38
+ if (!$this->_isBackendOrder) {
39
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
40
+ $this->_infoBlockType = 'ewayrapid/info_transparent_notsaved';
41
+ $this->_formBlockType = 'ewayrapid/form_transparent_notsaved';
42
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
43
+ $this->_infoBlockType = 'ewayrapid/info_sharedpage_notsaved';
44
+ $this->_formBlockType = 'ewayrapid/form_sharedpage_notsaved';
45
+ }
46
+ }
47
+
48
+ if ($this->_isBackendOrder) {
49
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
50
+ || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
51
+ ) {
52
+ $this->_infoBlockType = 'ewayrapid/info_sharedpage_notsaved';
53
+ $this->_formBlockType = 'ewayrapid/form_sharedpage_notsaved';
54
+ }
55
+ }
56
+ }
57
+
58
+ /**
59
+ * As of version 1.4.0 this payment method isn't used.
60
+ *
61
+ * @param Mage_Sales_Model_Quote|null $quote
62
+ * @return boolean
63
+ */
64
+ public function isAvailable($quote = null)
65
+ {
66
+ return false;
67
+ }
68
+
69
+ public function getConfigData($field, $storeId = null)
70
+ {
71
+ $data = parent::getConfigData($field, $storeId);
72
+ if ($data === null) {
73
+ return $this->_getGeneralConfig($field, $storeId);
74
+ } else {
75
+ switch($field) {
76
+ case 'active':
77
+ return $data && $this->_isActive($storeId);
78
+ default:
79
+ return $data;
80
+ }
81
+ }
82
+ }
83
+
84
+ protected function _getGeneralConfig($field, $storeId = null)
85
+ {
86
+ if (null === $storeId) {
87
+ $storeId = $this->getStore();
88
+ }
89
+ $path = 'payment/ewayrapid_general/'.$field;
90
+ return Mage::getStoreConfig($path, $storeId);
91
+ }
92
+
93
+ protected function _isActive($storeId)
94
+ {
95
+ return $this->_getGeneralConfig('active', $storeId);
96
+ }
97
+
98
+ /**
99
+ * Assign data to info model instance
100
+ *
101
+ * @param mixed $data
102
+ * @return Mage_Payment_Model_Info
103
+ */
104
+ public function assignData($data)
105
+ {
106
+ if (!($data instanceof Varien_Object)) {
107
+ $data = new Varien_Object($data);
108
+ }
109
+ $info = $this->getInfoInstance();
110
+
111
+ if (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
112
+ if ($data->getMethod()) {
113
+ Mage::getSingleton('core/session')->setData('ewayMethod', $data->getMethod());
114
+ }
115
+ } elseif (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
116
+ $info->setTransparentNotsaved($data->getTransparentNotsaved());
117
+
118
+ //Option choice
119
+ if ($data->getMethod() == 'ewayrapid_saved' && !$data->getTransparentSaved()) {
120
+ Mage::throwException(Mage::helper('payment')->__('Please select an option payment for saved'));
121
+ } elseif ($data->getMethod() == 'ewayrapid_notsaved' && !$data->getTransparentNotsaved()) {
122
+ Mage::throwException(Mage::helper('payment')->__('Please select an option payment for not saved'));
123
+ }
124
+
125
+ //New Token
126
+ if ($data->getMethod() == 'ewayrapid_saved'
127
+ && $data->getTransparentSaved() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
128
+ && $data->getSavedToken() == Eway_Rapid31_Model_Config::TOKEN_NEW
129
+ && Mage::helper('ewayrapid/customer')->checkTokenListByType(Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD)
130
+ ) {
131
+ Mage::throwException(Mage::helper('payment')->__('You can only save one PayPal account, please select existing PayPal account.'));
132
+ }
133
+
134
+ if ($data->getTransparentNotsaved())
135
+ Mage::getSingleton('core/session')->setTransparentNotsaved($data->getTransparentNotsaved());
136
+
137
+ if ($data->getTransparentSaved())
138
+ Mage::getSingleton('core/session')->setTransparentSaved($data->getTransparentSaved());
139
+
140
+ if ($data->getMethod())
141
+ Mage::getSingleton('core/session')->setMethod($data->getMethod());
142
+
143
+ if ($data->getSavedToken()) {
144
+ Mage::getSingleton('core/session')->setSavedToken($data->getSavedToken());
145
+ if (is_numeric($data->getSavedToken())) {
146
+ $token = Mage::helper('ewayrapid/customer')->getTokenById($data->getSavedToken());
147
+ /* @var Eway_Rapid31_Model_Request_Token $model */
148
+ $model = Mage::getModel('ewayrapid/request_token');
149
+ $type = $model->checkCardName($token);
150
+ Mage::getSingleton('core/session')->setTransparentSaved($type);
151
+ unset($model);
152
+ unset($token);
153
+ }
154
+ }
155
+
156
+ $infoCard = new Varien_Object();
157
+ Mage::getSingleton('core/session')->setInfoCard(
158
+ $infoCard->setCcType($data->getCcType())
159
+ ->setOwner($data->getCcOwner())
160
+ ->setLast4($this->_isClientSideEncrypted($data->getCcNumber()) ? 'encrypted' : substr($data->getCcNumber(), -4))
161
+ ->setCard($data->getCcNumber())
162
+ ->setNumber($data->getCcNumber())
163
+ ->setCid($data->getCcCid())
164
+ ->setExpMonth($data->getCcExpMonth())
165
+ ->setExpYear(
166
+ $data->getCcExpYear()
167
+ )
168
+ );
169
+
170
+ } else {
171
+ $info->setCcType($data->getCcType())
172
+ ->setCcOwner($data->getCcOwner())
173
+ ->setCcLast4($this->_isClientSideEncrypted($data->getCcNumber()) ? 'encrypted' : substr($data->getCcNumber(), -4))
174
+ ->setCcNumber($data->getCcNumber())
175
+ ->setCcCid($data->getCcCid())
176
+ ->setCcExpMonth($data->getCcExpMonth())
177
+ ->setCcExpYear($data->getCcExpYear());
178
+ }
179
+
180
+ return $this;
181
+ }
182
+
183
+ protected function _isClientSideEncrypted($ccNumber)
184
+ {
185
+ return (strlen($ccNumber) > 19 && strpos($ccNumber, Eway_Rapid31_Model_Config::ENCRYPTION_PREFIX) !== false);
186
+ }
187
+
188
+ /**
189
+ * Validate payment method information object
190
+ *
191
+ * @param Mage_Payment_Model_Info $info
192
+ * @return Mage_Payment_Model_Abstract
193
+ */
194
+ public function validate()
195
+ {
196
+ /*
197
+ * calling parent validate function
198
+ */
199
+ parent::validate();
200
+ if (!$this->_isBackendOrder) {
201
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME) {
202
+ return $this;
203
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
204
+ return $this;
205
+ }
206
+ }
207
+
208
+ if ($this->_isBackendOrder
209
+ && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
210
+ || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
211
+ ) {
212
+ return $this;
213
+ }
214
+
215
+ $info = $this->getInfoInstance();
216
+ $errorMsg = false;
217
+ $availableTypes = explode(',', $this->getConfigData('cctypes'));
218
+
219
+ $ccNumber = $info->getCcNumber();
220
+
221
+ // Cannot do normal validation in case client side encrypted
222
+ if ($this->_isClientSideEncrypted($ccNumber)) {
223
+ return true;
224
+ }
225
+
226
+ // remove credit card number delimiters such as "-" and space
227
+ $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
228
+ $info->setCcNumber($ccNumber);
229
+
230
+ $ccType = '';
231
+
232
+ if (in_array($info->getCcType(), $availableTypes)) {
233
+ if ($this->validateCcNum($ccNumber)) {
234
+ $ccTypeRegExpList = array(
235
+ // Visa Electron
236
+ 'VE' => '/^(4026|4405|4508|4844|4913|4917)[0-9]{12}|417500[0-9]{10}$/',
237
+ // Maestro
238
+ 'ME' => '/(^(5[0678])[0-9]{11,18}$)|(^(6[^05])[0-9]{11,18}$)|(^(601)[^1][0-9]{9,16}$)|(^(6011)[0-9]{9,11}$)|(^(6011)[0-9]{13,16}$)|(^(65)[0-9]{11,13}$)|(^(65)[0-9]{15,18}$)|(^(49030)[2-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49033)[5-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49110)[1-2]([0-9]{10}$|[0-9]{12,13}$))|(^(49117)[4-9]([0-9]{10}$|[0-9]{12,13}$))|(^(49118)[0-2]([0-9]{10}$|[0-9]{12,13}$))|(^(4936)([0-9]{12}$|[0-9]{14,15}$))/',
239
+ // Visa
240
+ 'VI' => '/^4[0-9]{12}([0-9]{3})?$/',
241
+ // Master Card
242
+ 'MC' => '/^5[1-5][0-9]{14}$/',
243
+ // Master Card 2017 - new MasterCard Range 2221-2720
244
+ //'MC' => '/(^5[1-5][0-9]{14}$)|(^2221[0-9]{12}$)|(^222[2-9][0-9]{12}$)|(^22[3-9][0-9]{13}$)|(^2[3-6][0-9]{14}$)|(^2720[0-9]{12}$)|(^27[0-1][0-9]{13}$)/',
245
+ // American Express
246
+ 'AE' => '/^3[47][0-9]{13}$/',
247
+ // JCB
248
+ 'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/',
249
+ // Diners Club
250
+ 'DC' => '/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/',
251
+ );
252
+
253
+ foreach ($ccTypeRegExpList as $ccTypeMatch=>$ccTypeRegExp) {
254
+ if (preg_match($ccTypeRegExp, $ccNumber)) {
255
+ $ccType = $ccTypeMatch;
256
+ break;
257
+ }
258
+ }
259
+
260
+ if ($ccType!=$info->getCcType()) {
261
+ $errorMsg = Mage::helper('payment')->__('Please enter a valid credit card number.');
262
+ }
263
+ } else {
264
+ $errorMsg = Mage::helper('payment')->__('Invalid Credit Card Number');
265
+ }
266
+
267
+ } else {
268
+ $errorMsg = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
269
+ }
270
+
271
+ //validate credit card verification number
272
+ if ($errorMsg === false && $this->hasVerification()) {
273
+ $verifcationRegEx = $this->getVerificationRegEx();
274
+ $regExp = isset($verifcationRegEx[$info->getCcType()]) ? $verifcationRegEx[$info->getCcType()] : '';
275
+ if (!$info->getCcCid() || !$regExp || !preg_match($regExp, $info->getCcCid())) {
276
+ $errorMsg = Mage::helper('payment')->__('Please enter a valid credit card verification number.');
277
+ }
278
+ }
279
+
280
+ if (!$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth())) {
281
+ $errorMsg = Mage::helper('payment')->__('Incorrect credit card expiration date.');
282
+ }
283
+
284
+ if ($errorMsg) {
285
+ Mage::throwException($errorMsg);
286
+ }
287
+
288
+ return $this;
289
+ }
290
+
291
+ public function hasVerification()
292
+ {
293
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
294
+ return false;
295
+ }
296
+
297
+ $configData = $this->getConfigData('useccv');
298
+ if ($configData === null) {
299
+ return true;
300
+ }
301
+ return (bool) $configData;
302
+ }
303
+
304
+ public function getVerificationRegEx()
305
+ {
306
+ $verificationExpList = array(
307
+ 'VI' => '/^[0-9]{3}$/', // Visa
308
+ 'VE' => '/^[0-9]{3}$/', // Visa Electron
309
+ 'MC' => '/^[0-9]{3}$/', // Master Card
310
+ 'ME' => '/^[0-9]{3,4}$/', // Maestro
311
+ 'AE' => '/^[0-9]{4}$/', // American Express
312
+ 'DC' => '/^[0-9]{3}$/', // Diners Club
313
+ 'JCB' => '/^[0-9]{3,4}$/' //JCB
314
+ );
315
+ return $verificationExpList;
316
+ }
317
+
318
+ protected function _validateExpDate($expYear, $expMonth)
319
+ {
320
+ $date = Mage::app()->getLocale()->date();
321
+ if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
322
+ || ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1))
323
+ ) {
324
+ return false;
325
+ }
326
+ return true;
327
+ }
328
+
329
+ /**
330
+ * Validate credit card number
331
+ *
332
+ * @param string $cc_number
333
+ * @return bool
334
+ */
335
+ public function validateCcNum($ccNumber)
336
+ {
337
+ $cardNumber = strrev($ccNumber);
338
+ $numSum = 0;
339
+
340
+ for ($i=0; $i<strlen($cardNumber); $i++) {
341
+ $currentNum = substr($cardNumber, $i, 1);
342
+
343
+ /**
344
+ * Double every second digit
345
+ */
346
+ if ($i % 2 == 1) {
347
+ $currentNum *= 2;
348
+ }
349
+
350
+ /**
351
+ * Add digits of 2-digit numbers together
352
+ */
353
+ if ($currentNum > 9) {
354
+ $firstNum = $currentNum % 10;
355
+ $secondNum = ($currentNum - $firstNum) / 10;
356
+ $currentNum = $firstNum + $secondNum;
357
+ }
358
+
359
+ $numSum += $currentNum;
360
+ }
361
+
362
+ /**
363
+ * If the total has no remainder it's OK
364
+ */
365
+ return ($numSum % 10 == 0);
366
+ }
367
+
368
+ /**
369
+ * Authorize & Capture a payment
370
+ *
371
+ * @param Varien_Object $payment
372
+ * @param float $amount
373
+ *
374
+ * @return Mage_Payment_Model_Abstract
375
+ */
376
+ public function capture(Varien_Object $payment, $amount)
377
+ {
378
+ if (!$this->_isBackendOrder) {
379
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
380
+ $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
381
+ $payment->setTransactionId($transID);
382
+ $payment->setIsTransactionClosed(0);
383
+ Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
384
+ return $this;
385
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
386
+ $payment = Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
387
+ return $this;
388
+ }
389
+ }
390
+
391
+ if ($this->_isBackendOrder) {
392
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
393
+ || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
394
+ ) {
395
+ return $this;
396
+ }
397
+ }
398
+
399
+ /* @var Mage_Sales_Model_Order_Payment $payment */
400
+ if ($amount <= 0) {
401
+ Mage::throwException(Mage::helper('payment')->__('Invalid amount for capture.'));
402
+ }
403
+
404
+ $amount = round($amount * 100);
405
+ $request = Mage::getModel('ewayrapid/request_direct');
406
+ if ($this->_isPreauthCapture($payment)) {
407
+ $request->doCapturePayment($payment, $amount);
408
+ } else {
409
+ $request->doTransaction($payment, $amount);
410
+ }
411
+
412
+ return $this;
413
+ }
414
+
415
+ /**
416
+ * Authorize a payment
417
+ *
418
+ * @param Varien_Object $payment
419
+ * @param float $amount
420
+ *
421
+ * @return Mage_Payment_Model_Abstract
422
+ */
423
+ public function authorize(Varien_Object $payment, $amount)
424
+ {
425
+ if (!$this->_isBackendOrder) {
426
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
427
+ $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
428
+ $payment->setTransactionId($transID);
429
+ $payment->setIsTransactionClosed(0);
430
+ Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
431
+ return $this;
432
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
433
+ $payment = Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
434
+ return $this;
435
+ }
436
+ }
437
+
438
+ if ($this->_isBackendOrder) {
439
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
440
+ || $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
441
+ ) {
442
+ return $this;
443
+ }
444
+ }
445
+
446
+ /* @var Mage_Sales_Model_Order_Payment $payment */
447
+ if ($amount <= 0) {
448
+ Mage::throwException(Mage::helper('payment')->__('Invalid amount for authorize.'));
449
+ }
450
+
451
+ $amount = round($amount * 100);
452
+ $request = Mage::getModel('ewayrapid/request_direct');
453
+ $request->doAuthorisation($payment, $amount);
454
+
455
+ return $this;
456
+ }
457
+
458
+ /**
459
+ * Refund a payment
460
+ *
461
+ * @param Varien_Object $payment
462
+ * @param float $amount
463
+ *
464
+ * @return Mage_Payment_Model_Abstract
465
+ */
466
+ public function refund(Varien_Object $payment, $amount)
467
+ {
468
+ /* @var Mage_Sales_Model_Order_Payment $payment */
469
+ if ($amount <= 0) {
470
+ Mage::throwException(Mage::helper('payment')->__('Invalid amount for refund.'));
471
+ }
472
+
473
+ $amount = round($amount * 100);
474
+ $request = Mage::getModel('ewayrapid/request_direct');
475
+ $request->doRefund($payment, $amount);
476
+
477
+ return $this;
478
+ }
479
+
480
+ /**
481
+ * Cancel a payment
482
+ *
483
+ * @param Varien_Object $payment
484
+ *
485
+ * @return Mage_Payment_Model_Abstract
486
+ */
487
+ public function cancel(Varien_Object $payment)
488
+ {
489
+ /* @var Mage_Sales_Model_Order_Payment $payment */
490
+ $request = Mage::getModel('ewayrapid/request_direct');
491
+ $request->doCancel($payment);
492
+
493
+ return $this;
494
+ }
495
+
496
+ protected function _isPreauthCapture(Mage_Sales_Model_Order_Payment $payment)
497
+ {
498
+ return (bool) $payment->getLastTransId();
499
+ }
500
+
501
+ public function canVoid(Varien_Object $payment)
502
+ {
503
+ return $this->_canVoid && (Mage::app()->getRequest()->getActionName() == 'cancel');
504
+ }
505
+
506
+ public function getCheckoutRedirectUrl()
507
+ {
508
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
509
+ === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
510
+ ) {
511
+ return Mage::getUrl('ewayrapid/sharedpage/start', array('_secure'=>true));
512
+ } elseif (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
513
+ === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
514
+ && Mage::getSingleton('core/session')->getCheckoutExtension()
515
+ ) {
516
+ return Mage::getUrl('ewayrapid/sharedpage/iframe', array('_secure'=>true));
517
+ } elseif (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
518
+ === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
519
+ && Mage::getSingleton('core/session')->getCheckoutExtension()
520
+ ) {
521
+ return Mage::getUrl('ewayrapid/transparent/build', array('_secure'=>true));
522
+ }
523
+ return null;
524
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
  }
app/code/community/Eway/Rapid31/Model/Method/Saved.php CHANGED
@@ -1,287 +1,285 @@
1
- <?php
2
- class Eway_Rapid31_Model_Method_Saved extends Eway_Rapid31_Model_Method_Notsaved implements Mage_Payment_Model_Recurring_Profile_MethodInterface
3
- {
4
- protected $_code = 'ewayrapid_saved';
5
-
6
- protected $_formBlockType = 'ewayrapid/form_direct_saved';
7
- protected $_infoBlockType = 'ewayrapid/info_direct_saved';
8
-
9
- protected $_canCapturePartial = true;
10
-
11
- protected $_billing = null;
12
-
13
- public function __construct()
14
- {
15
- parent::__construct();
16
- if (!$this->_isBackendOrder) {
17
- if (!Mage::helper('ewayrapid')->isBackendOrder()) {
18
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
19
- $this->_infoBlockType = 'ewayrapid/info_transparent_saved';
20
- $this->_formBlockType = 'ewayrapid/form_transparent_saved';
21
- } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
22
- $this->_infoBlockType = 'ewayrapid/info_sharedpage_saved';
23
- $this->_formBlockType = 'ewayrapid/form_sharedpage_saved';
24
- }
25
- }
26
- }
27
- }
28
-
29
- protected function _isActive($storeId)
30
- {
31
- return parent::_isActive($storeId) &&
32
- (Mage::helper('ewayrapid/customer')->getCurrentCustomer()
33
- || Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER);
34
- }
35
-
36
- /**
37
- * Assign data to info model instance
38
- *
39
- * @param mixed $data
40
- * @return Mage_Payment_Model_Info
41
- */
42
- public function assignData($data)
43
- {
44
- if (!($data instanceof Varien_Object)) {
45
- $data = new Varien_Object($data);
46
- }
47
- $info = $this->getInfoInstance();
48
-
49
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
50
- && !$this->_isBackendOrder
51
- ) {
52
- $info->setTransparentSaved($data->getTransparentSaved());
53
- }
54
-
55
- if($data->getSavedToken() == Eway_Rapid31_Model_Config::TOKEN_NEW) {
56
- Mage::helper('ewayrapid')->clearSessionSharedpage();
57
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
58
- && !$this->_isBackendOrder
59
- ) {
60
- Mage::getSingleton('core/session')->setData('newToken', 1);
61
- }
62
- $info->setIsNewToken(true);
63
- } else {
64
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
65
- && !$this->_isBackendOrder
66
- ) {
67
- Mage::getSingleton('core/session')->setData('editToken', $data->getSavedToken());
68
- }
69
-
70
- $info->setSavedToken($data->getSavedToken());
71
- // Update token
72
- if($data->getCcOwner()) {
73
- $info->setIsUpdateToken(true);
74
- }
75
- }
76
-
77
- parent::assignData($data);
78
-
79
- Mage::helper('ewayrapid')->serializeInfoInstance($info);
80
-
81
- return $this;
82
- }
83
-
84
- /**
85
- * Validate payment method information object
86
- *
87
- * @param Mage_Payment_Model_Info $info
88
- * @return Mage_Payment_Model_Abstract
89
- */
90
- public function validate()
91
- {
92
- $info = $this->getInfoInstance();
93
- if($info->getIsNewToken()) {
94
- parent::validate();
95
- } else {
96
- // TODO: Check if this token is still Active using GET /Customer endpoint.
97
- }
98
-
99
- return $this;
100
- }
101
-
102
- /**
103
- * Authorize & Capture a payment
104
- *
105
- * @param Varien_Object $payment
106
- * @param float $amount
107
- *
108
- * @return Mage_Payment_Model_Abstract
109
- */
110
- public function capture(Varien_Object $payment, $amount)
111
- {
112
- if (!$this->_isBackendOrder) {
113
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
114
- $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
115
- $payment->setTransactionId($transID);
116
- $payment->setIsTransactionClosed(0);
117
- Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
118
- return $this;
119
- } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
120
- //$payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
121
- Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
122
- return $this;
123
- }
124
- }
125
-
126
- /* @var Mage_Sales_Model_Order_Payment $payment */
127
- if ($amount <= 0) {
128
- Mage::throwException(Mage::helper('payment')->__('Invalid amount for capture.'));
129
- }
130
- $request = Mage::getModel('ewayrapid/request_token');
131
-
132
- $amount = round($amount * 100);
133
- if($this->_isPreauthCapture($payment)) {
134
- $previousCapture = $payment->lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
135
- if($previousCapture) {
136
- $customer = Mage::getModel('customer/customer')->load($payment->getOrder()->getCustomerId());
137
- Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
138
-
139
- /* @var Mage_Sales_Model_Order_Payment_Transaction $previousCapture */
140
- $request->doTransaction($payment, $amount);
141
- $payment->setParentTransactionId($previousCapture->getParentTxnId());
142
- } else {
143
- $request->doCapturePayment($payment, $amount);
144
- }
145
- } else {
146
- if (!$payment->getIsRecurring()) {
147
- $this->_shouldCreateOrUpdateToken($payment, $request);
148
- }
149
- $request->doTransaction($payment, $amount);
150
- }
151
-
152
- return $this;
153
- }
154
-
155
- /**
156
- * Authorize a payment
157
- *
158
- * @param Varien_Object $payment
159
- * @param float $amount
160
- *
161
- * @return Mage_Payment_Model_Abstract
162
- */
163
- public function authorize(Varien_Object $payment, $amount)
164
- {
165
- if (!$this->_isBackendOrder) {
166
- if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
167
- $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
168
- $payment->setTransactionId($transID);
169
- $payment->setIsTransactionClosed(0);
170
- Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
171
- return $this;
172
- } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
173
- //$payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
174
- Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
175
- return $this;
176
- }
177
- }
178
-
179
- /* @var Mage_Sales_Model_Order_Payment $payment */
180
- if ($amount <= 0) {
181
- Mage::throwException(Mage::helper('payment')->__('Invalid amount for authorize.'));
182
- }
183
- $request = Mage::getModel('ewayrapid/request_token');
184
-
185
- /** @todo there's an error in case recurring profile */
186
- if (!$payment->getIsRecurring()) {
187
- $this->_shouldCreateOrUpdateToken($payment, $request);
188
- }
189
-
190
- $amount = round($amount * 100);
191
- $request->doAuthorisation($payment, $amount);
192
-
193
- return $this;
194
- }
195
-
196
- /**
197
- * @param Mage_Sales_Model_Order_Payment $payment
198
- * @param Eway_Rapid31_Model_Request_Token $request
199
- */
200
- public function _shouldCreateOrUpdateToken(Mage_Sales_Model_Order_Payment $payment, Eway_Rapid31_Model_Request_Token $request)
201
- {
202
- $order = $payment->getOrder();
203
- $billing = ($this->_getBilling() == null) ? $order->getBillingAddress() : $this->_getBilling();
204
- $info = $this->getInfoInstance();
205
-
206
- Mage::helper('ewayrapid')->unserializeInfoInstace($info);
207
- if ($info->getIsNewToken()) {
208
- $request->createNewToken($billing, $info);
209
- $info->setSavedToken(Mage::helper('ewayrapid/customer')->getLastTokenId());
210
- Mage::helper('ewayrapid')->serializeInfoInstance($info);
211
- } elseif ($info->getIsUpdateToken()) {
212
- $request->updateToken($billing, $info);
213
- }
214
- }
215
-
216
- public function _setBilling(Mage_Sales_Model_Quote_Address $billing)
217
- {
218
- $this->_billing = $billing;
219
- }
220
-
221
- public function _getBilling()
222
- {
223
- return $this->_billing;
224
- }
225
-
226
- /**
227
- * Validate RP data
228
- *
229
- * @param Mage_Payment_Model_Recurring_Profile $profile
230
- */
231
- public function validateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
232
- {
233
-
234
- }
235
-
236
- /**
237
- * Submit RP to the gateway
238
- *
239
- * @param Mage_Payment_Model_Recurring_Profile $profile
240
- * @param Mage_Payment_Model_Info $paymentInfo
241
- */
242
- public function submitRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile,
243
- Mage_Payment_Model_Info $paymentInfo
244
- ) {
245
- $profile->setReferenceId(strtoupper(uniqid()));
246
- $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE);
247
- }
248
-
249
- /**
250
- * Fetch RP details
251
- *
252
- * @param string $referenceId
253
- * @param Varien_Object $result
254
- */
255
- public function getRecurringProfileDetails($referenceId, Varien_Object $result)
256
- {
257
-
258
- }
259
-
260
- /**
261
- * Whether can get recurring profile details
262
- */
263
- public function canGetRecurringProfileDetails()
264
- {
265
- return true;
266
- }
267
-
268
- /**
269
- * Update RP data
270
- *
271
- * @param Mage_Payment_Model_Recurring_Profile $profile
272
- */
273
- public function updateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
274
- {
275
-
276
- }
277
-
278
- /**
279
- * Manage status
280
- *
281
- * @param Mage_Payment_Model_Recurring_Profile $profile
282
- */
283
- public function updateRecurringProfileStatus(Mage_Payment_Model_Recurring_Profile $profile)
284
- {
285
-
286
- }
287
  }
1
+ <?php
2
+ class Eway_Rapid31_Model_Method_Saved extends Eway_Rapid31_Model_Method_Notsaved implements Mage_Payment_Model_Recurring_Profile_MethodInterface
3
+ {
4
+ protected $_code = 'ewayrapid_saved';
5
+
6
+ protected $_formBlockType = 'ewayrapid/form_direct_saved';
7
+ protected $_infoBlockType = 'ewayrapid/info_direct_saved';
8
+
9
+ protected $_canCapturePartial = true;
10
+
11
+ protected $_billing = null;
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+ if (!$this->_isBackendOrder) {
17
+ if (!Mage::helper('ewayrapid')->isBackendOrder()) {
18
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
19
+ $this->_infoBlockType = 'ewayrapid/info_transparent_saved';
20
+ $this->_formBlockType = 'ewayrapid/form_transparent_saved';
21
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
22
+ $this->_infoBlockType = 'ewayrapid/info_sharedpage_saved';
23
+ $this->_formBlockType = 'ewayrapid/form_sharedpage_saved';
24
+ }
25
+ }
26
+ }
27
+ }
28
+
29
+ protected function _isActive($storeId)
30
+ {
31
+ return parent::_isActive($storeId) &&
32
+ (Mage::helper('ewayrapid/customer')->getCurrentCustomer()
33
+ || Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod() == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER);
34
+ }
35
+
36
+ /**
37
+ * Assign data to info model instance
38
+ *
39
+ * @param mixed $data
40
+ * @return Mage_Payment_Model_Info
41
+ */
42
+ public function assignData($data)
43
+ {
44
+ if (!($data instanceof Varien_Object)) {
45
+ $data = new Varien_Object($data);
46
+ }
47
+ $info = $this->getInfoInstance();
48
+
49
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
50
+ && !$this->_isBackendOrder
51
+ ) {
52
+ $info->setTransparentSaved($data->getTransparentSaved());
53
+ }
54
+
55
+ if ($data->getSavedToken() == Eway_Rapid31_Model_Config::TOKEN_NEW) {
56
+ Mage::helper('ewayrapid')->clearSessionSharedpage();
57
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
58
+ && !$this->_isBackendOrder
59
+ ) {
60
+ Mage::getSingleton('core/session')->setData('newToken', 1);
61
+ }
62
+ $info->setIsNewToken(true);
63
+ } else {
64
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
65
+ && !$this->_isBackendOrder
66
+ ) {
67
+ Mage::getSingleton('core/session')->setData('editToken', $data->getSavedToken());
68
+ }
69
+
70
+ $info->setSavedToken($data->getSavedToken());
71
+ // Update token
72
+ if ($data->getCcOwner()) {
73
+ $info->setIsUpdateToken(true);
74
+ }
75
+ }
76
+
77
+ parent::assignData($data);
78
+
79
+ Mage::helper('ewayrapid')->serializeInfoInstance($info);
80
+
81
+ return $this;
82
+ }
83
+
84
+ /**
85
+ * Validate payment method information object
86
+ *
87
+ * @param Mage_Payment_Model_Info $info
88
+ * @return Mage_Payment_Model_Abstract
89
+ */
90
+ public function validate()
91
+ {
92
+ $info = $this->getInfoInstance();
93
+ if ($info->getIsNewToken()) {
94
+ parent::validate();
95
+ }
96
+ // TODO: Check if this token is still Active using GET /Customer endpoint.
97
+
98
+ return $this;
99
+ }
100
+
101
+ /**
102
+ * Authorize & Capture a payment
103
+ *
104
+ * @param Varien_Object $payment
105
+ * @param float $amount
106
+ *
107
+ * @return Mage_Payment_Model_Abstract
108
+ */
109
+ public function capture(Varien_Object $payment, $amount)
110
+ {
111
+ if (!$this->_isBackendOrder) {
112
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
113
+ $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
114
+ $payment->setTransactionId($transID);
115
+ $payment->setIsTransactionClosed(0);
116
+ Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
117
+ return $this;
118
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
119
+ Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
120
+ return $this;
121
+ }
122
+ }
123
+
124
+ /* @var Mage_Sales_Model_Order_Payment $payment */
125
+ if ($amount <= 0) {
126
+ Mage::throwException(Mage::helper('payment')->__('Invalid amount for capture.'));
127
+ }
128
+ $request = Mage::getModel('ewayrapid/request_token');
129
+
130
+ $amount = round($amount * 100);
131
+ if ($this->_isPreauthCapture($payment)) {
132
+ $previousCapture = $payment->lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
133
+ if ($previousCapture) {
134
+ $customer = Mage::getModel('customer/customer')->load($payment->getOrder()->getCustomerId());
135
+ Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
136
+
137
+ /* @var Mage_Sales_Model_Order_Payment_Transaction $previousCapture */
138
+ $request->doTransaction($payment, $amount);
139
+ $payment->setParentTransactionId($previousCapture->getParentTxnId());
140
+ } else {
141
+ $request->doCapturePayment($payment, $amount);
142
+ }
143
+ } else {
144
+ if (!$payment->getIsRecurring()) {
145
+ $this->_shouldCreateOrUpdateToken($payment, $request);
146
+ }
147
+ $request->doTransaction($payment, $amount);
148
+ }
149
+
150
+ return $this;
151
+ }
152
+
153
+ /**
154
+ * Authorize a payment
155
+ *
156
+ * @param Varien_Object $payment
157
+ * @param float $amount
158
+ *
159
+ * @return Mage_Payment_Model_Abstract
160
+ */
161
+ public function authorize(Varien_Object $payment, $amount)
162
+ {
163
+ if (!$this->_isBackendOrder) {
164
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
165
+ $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
166
+ $payment->setTransactionId($transID);
167
+ $payment->setIsTransactionClosed(0);
168
+ Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
169
+ return $this;
170
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
171
+ Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
172
+ return $this;
173
+ }
174
+ }
175
+
176
+ /* @var Mage_Sales_Model_Order_Payment $payment */
177
+ if ($amount <= 0) {
178
+ Mage::throwException(Mage::helper('payment')->__('Invalid amount for authorize.'));
179
+ }
180
+ $request = Mage::getModel('ewayrapid/request_token');
181
+
182
+ /** @todo there's an error in case recurring profile */
183
+ if (!$payment->getIsRecurring()) {
184
+ $this->_shouldCreateOrUpdateToken($payment, $request);
185
+ }
186
+
187
+ $amount = round($amount * 100);
188
+ $request->doAuthorisation($payment, $amount);
189
+
190
+ return $this;
191
+ }
192
+
193
+ /**
194
+ * @param Mage_Sales_Model_Order_Payment $payment
195
+ * @param Eway_Rapid31_Model_Request_Token $request
196
+ */
197
+ public function _shouldCreateOrUpdateToken(Mage_Sales_Model_Order_Payment $payment, Eway_Rapid31_Model_Request_Token $request)
198
+ {
199
+ $order = $payment->getOrder();
200
+ $billing = ($this->_getBilling() == null) ? $order->getBillingAddress() : $this->_getBilling();
201
+ $info = $this->getInfoInstance();
202
+
203
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
204
+ if ($info->getIsNewToken()) {
205
+ $request->createNewToken($billing, $info);
206
+ $info->setSavedToken(Mage::helper('ewayrapid/customer')->getLastTokenId());
207
+ Mage::helper('ewayrapid')->serializeInfoInstance($info);
208
+ } elseif ($info->getIsUpdateToken()) {
209
+ $request->updateToken($billing, $info);
210
+ }
211
+ }
212
+
213
+ public function _setBilling(Mage_Sales_Model_Quote_Address $billing)
214
+ {
215
+ $this->_billing = $billing;
216
+ }
217
+
218
+ public function _getBilling()
219
+ {
220
+ return $this->_billing;
221
+ }
222
+
223
+ /**
224
+ * Validate RP data
225
+ *
226
+ * @param Mage_Payment_Model_Recurring_Profile $profile
227
+ */
228
+ public function validateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
229
+ {
230
+
231
+ }
232
+
233
+ /**
234
+ * Submit RP to the gateway
235
+ *
236
+ * @param Mage_Payment_Model_Recurring_Profile $profile
237
+ * @param Mage_Payment_Model_Info $paymentInfo
238
+ */
239
+ public function submitRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile,
240
+ Mage_Payment_Model_Info $paymentInfo
241
+ )
242
+ {
243
+ $profile->setReferenceId(strtoupper(uniqid()));
244
+ $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE);
245
+ }
246
+
247
+ /**
248
+ * Fetch RP details
249
+ *
250
+ * @param string $referenceId
251
+ * @param Varien_Object $result
252
+ */
253
+ public function getRecurringProfileDetails($referenceId, Varien_Object $result)
254
+ {
255
+
256
+ }
257
+
258
+ /**
259
+ * Whether can get recurring profile details
260
+ */
261
+ public function canGetRecurringProfileDetails()
262
+ {
263
+ return true;
264
+ }
265
+
266
+ /**
267
+ * Update RP data
268
+ *
269
+ * @param Mage_Payment_Model_Recurring_Profile $profile
270
+ */
271
+ public function updateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
272
+ {
273
+
274
+ }
275
+
276
+ /**
277
+ * Manage status
278
+ *
279
+ * @param Mage_Payment_Model_Recurring_Profile $profile
280
+ */
281
+ public function updateRecurringProfileStatus(Mage_Payment_Model_Recurring_Profile $profile)
282
+ {
283
+
284
+ }
 
 
285
  }
app/code/community/Eway/Rapid31/Model/Observer.php CHANGED
@@ -1,293 +1,298 @@
1
- <?php
2
- /**
3
- *
4
- */
5
- class Eway_Rapid31_Model_Observer {
6
-
7
- /* @var Magento_Sales_Model_Order_Invoice*/
8
- var $_invoice;
9
-
10
- public function myCards() {
11
-
12
- }
13
-
14
- public function checkCustomerMark() {
15
- if(Mage::getSingleton('customer/session')->isLoggedIn()) {
16
- $fraud_enabled = Mage::getStoreConfig('payment/ewayrapid_general/block_fraud_customers');
17
- $customer = Mage::getSingleton('customer/session')->getCustomer();
18
- $markFraud = $customer->getMarkFraud();
19
- $unblock = $customer->getBlockFraudCustomer();
20
- if((int)$markFraud === 1
21
- && $fraud_enabled
22
- && (int)$unblock === 0
23
- ) {
24
- Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
25
- Mage::app()->getResponse()->sendResponse();
26
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Your latest payment is being reviewed and you cannot place a new order temporarily. Please try again later.'));
27
- exit;
28
- }
29
- }
30
- }
31
-
32
- public function sales_order_save_before($observer) {
33
-
34
- }
35
-
36
- public function sales_order_save_after($observer) {
37
-
38
- }
39
-
40
- public function sales_order_place_before($observer) {
41
- // Check order fraud here
42
- // ...
43
- $fraud = Mage::getSingleton('core/session')->getData('fraud');
44
- if($fraud === 1) {
45
-
46
- }
47
- }
48
-
49
- public function sales_order_place_after($observer) {
50
- // Check order fraud here
51
- // ...
52
-
53
- $fraud = Mage::getSingleton('core/session')->getData('fraud');
54
- if($fraud === 1) {
55
-
56
- }
57
- }
58
-
59
- public function sales_order_invoice_save_after($observer)
60
- {
61
- try {
62
- /* @var $order Magento_Sales_Model_Order_Invoice */
63
- $this->_invoice = $observer->getEvent()->getInvoice();
64
- $this->_invoice->sendEmail();
65
- } catch (Mage_Core_Exception $e) {
66
- Mage::log("Error sending invoice email: " . $e->getMessage());
67
- }
68
- return $this;
69
- }
70
-
71
- public function checkout_submit_all_after(Varien_Event_Observer $observer) {
72
- $fraud = Mage::getSingleton('core/session')->getData('fraud');
73
- $comment = Mage::getSingleton('core/session')->getData('fraudMessage');
74
- // Read setting config enabled fraud or not
75
- if($fraud === 1 && $order = $observer->getEvent()->getOrder()) {
76
- $order->setState('fraud');
77
- $order->setStatus('fraud');
78
- if ($comment) {
79
- $comment = 'An order is marked as Suspected Fraud. Because it contains: ' . $comment;
80
- $order->addStatusHistoryComment($comment)
81
- ->setIsVisibleOnFront(false)
82
- ->setIsCustomerNotified(false);
83
- }
84
- $order->save();
85
-
86
- // Update user to fraud
87
- $session = Mage::getSingleton('customer/session');
88
- if ($session->isLoggedIn()) {
89
- $customer = $session->getCustomer();
90
- $customer->setData('mark_fraud', 1);
91
- $customer->save();
92
- }
93
-
94
- Mage::getSingleton('core/session')->unsetData('fraud');
95
- Mage::getSingleton('core/session')->unsetData('fraudMessage');
96
- }
97
- }
98
-
99
- /**
100
- * Update eway transaction for order
101
- * @param Varien_Event_Observer $observer
102
- */
103
- public function checkout_type_onepage_save_order_after(Varien_Event_Observer $observer) {
104
- $order = $observer->getData('order');
105
- $order->setEwayTransactionId($order->getPayment()->getTransactionId());
106
- $order->save();
107
-
108
- }
109
- /*
110
- * create order of recurring profile
111
- *
112
- * @param Varien_Event_Observer $observer
113
- */
114
- public function createRecurringOrder(Varien_Event_Observer $observer)
115
- {
116
- $profiles = $observer->getEvent()->getRecurringProfiles();
117
-
118
- if (isset($profiles[0])) {
119
- /** @var Mage_Sales_Model_Recurring_Profile $profile */
120
- $profile = $profiles[0];
121
- } else {
122
- return;
123
- }
124
-
125
- //if Billing Frequency <= 0 or isn't numeric, Status of recurring profile changed to canceled
126
- if (!$profile->getPeriodFrequency()
127
- || (string)(int) $profile->getPeriodFrequency() !== ltrim($profile->getPeriodFrequency(), '0')
128
- || (int) $profile->getPeriodFrequency() <= 0
129
- ) {
130
- $profile->cancel();
131
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Billing Frequency is wrong. It must be numeric and greater than 0. Status of recurring profile is changed to canceled'));
132
- $session = Mage::getSingleton('checkout/type_onepage')->getCheckout();
133
- $session->setLastRecurringProfileIds(null);
134
- return;
135
- }
136
-
137
- $quote = $observer->getEvent()->getQuote();
138
-
139
- /** @var Eway_Rapid31_Model_RecurringProfile $recurringProfile */
140
- $recurringProfile = Mage::getModel('ewayrapid/recurringProfile');
141
- $orderItemInfo = $profile->getOrderItemInfo();
142
- $buyRequest = unserialize($orderItemInfo['info_buyRequest']);
143
-
144
- // timezone used as store's timezone
145
- $startDate = isset($buyRequest['recurring_profile_start_datetime']) && $buyRequest['recurring_profile_start_datetime'] ? $buyRequest['recurring_profile_start_datetime'] : null;
146
-
147
- $additional = $profile->getAdditionalInfo();
148
- $token = $recurringProfile->processToken($quote);
149
- $token = json_decode($token, true);
150
- $additional['token'] = $token;
151
- $additional['startDate'] = $startDate;
152
- $additional['initialFee'] = true;
153
- $profile->setAdditionalInfo($additional);
154
- $profile->save();
155
-
156
- // charge Initial Fee if It is greater than 0 and is numeric
157
- if ($profile->getInitAmount()
158
- && (float) $profile->getInitAmount() > 0
159
- //&& (string)(int) $profile->getInitAmount() === ltrim($profile->getInitAmount(), '0')
160
- ) {
161
- try {
162
- $recurringProfile->processInitialFee($profile);
163
- } catch (Exception $e) {
164
- $additional = $profile->getAdditionalInfo();
165
- $additional['initialFee'] = false;
166
- if ($profile->getInitMayFail() == '1') {
167
- // Allow Initial Fee Failure = yes
168
- // change status recurring profile = suspended
169
- $profile->suspend();
170
- $errorMessage = Mage::getSingleton('core/session')->getData('errorMessage');
171
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while making the transaction by Initial Fee (Error message: %s). Status of recurring profile is changed to suspended.', $errorMessage));
172
- return;
173
-
174
- } else {
175
- // Allow Initial Fee Failure = no
176
- // Auto Bill on Next Cycle = no
177
- // set additionalInfo['outstanding'] = Initial Fee
178
- if (!$profile->getBillFailedLater()) {
179
- $additional['outstanding'] = $profile->getInitAmount();
180
- }
181
- }
182
- $profile->setAdditionalInfo($additional);
183
- $profile->save();
184
- }
185
- }
186
-
187
- // check current time >= started time
188
- if (!$startDate || $recurringProfile->checkRecurringTimeStart($startDate)) {
189
- try {
190
- // create order
191
- // before day = current date // check if frequency >1day
192
- // next day with current date
193
- $recurringProfile->processRequest($profile);
194
- } catch (Exception $e) {
195
- $errorMessage = Mage::getSingleton('core/session')->getData('errorMessage');
196
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. (Error message: %s)', $errorMessage));
197
- // suspend recurring profile when response data contains error and/or TransactionID is null
198
- $checkPaymentFailures = $recurringProfile->checkMaxPaymentFailures($profile);
199
- if (!$checkPaymentFailures) {
200
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Out of Payment failures. Status of recurring profile is changed to suspended.'));
201
- }
202
- return;
203
- }
204
- } else {
205
- // not created order
206
- // before day = null
207
- // next day = date of started time
208
- $additionalInfo = $profile->getAdditionalInfo();
209
- $additionalInfo['nextDate'] = $startDate;
210
- $profile->setAdditionalInfo($additionalInfo);
211
- $profile->save();
212
- }
213
- }
214
-
215
- /**
216
- * load recurring profiles if methodcode = ewayrapid_saved or ewayrapid_ewayone
217
- *
218
- * @param array $methodCode
219
- * @return array
220
- */
221
- protected function _loadProfileByMethod($methodCode = ['ewayrapid_saved', 'ewayrapid_ewayone'])
222
- {
223
- $modelRecurringProfile = Mage::getModel('sales/recurring_profile')->getCollection()
224
- ->addFieldToFilter('method_code', array('in' => $methodCode))
225
- ->addFieldToFilter('state', 'active')
226
- ->addFieldToFilter('additional_info', array('notnull' => true))
227
- ->addFieldToFilter('period_max_cycles', array(
228
- array('null' => true),
229
- array('gt' => 0)
230
- )
231
- );
232
- $profiles = array();
233
-
234
- foreach ($modelRecurringProfile as $item) {
235
- /** @var Mage_Sales_Model_Recurring_Profile $item */
236
- $additionalInfo = unserialize($item->getAdditionalInfo());
237
- $billingInfo = unserialize($item->getBillingAddressInfo());
238
- $addressInfo = unserialize($item->getShippingAddressInfo());
239
- $orderItemInfo = unserialize($item->getOrderItemInfo());
240
- $orderInfo = unserialize($item->getOrderInfo());
241
- $item->setBillingAddressInfo($billingInfo);
242
- $item->setShippingAddressInfo($addressInfo);
243
- $item->setOrderItemInfo($orderItemInfo);
244
- $item->setAdditionalInfo($additionalInfo);
245
- $item->setOrderInfo($orderInfo);
246
- $profiles[] = $item;
247
- }
248
- return $profiles;
249
- }
250
-
251
- /**
252
- * cron recurring profile to create order
253
- */
254
- public function cronRecurringOrder()
255
- {
256
- $profiles = $this->_loadProfileByMethod();
257
- foreach ($profiles as $profile) {
258
- /** @var Mage_Sales_Model_Recurring_Profile $profile */
259
- /** @var Eway_Rapid31_Model_RecurringProfile $recurringProfile */
260
- $recurringProfile = Mage::getModel('ewayrapid/recurringProfile');
261
-
262
- $recurringProfile->updateNextDate($profile);
263
-
264
- // check run cron job conditions
265
- if ($recurringProfile->checkRecurringProfileRunCronJob($profile)) {
266
- // check charge money initial Fee
267
- $additional = $profile->getAdditionalInfo();
268
- if ($additional['initialFee'] == false) {
269
- if (!$profile->getInitMayFail() && $profile->getBillFailedLater()) {
270
- try {
271
- $recurringProfile->processInitialFee($profile);
272
- $additional['initialFee'] = true;
273
- $profile->setAdditionalInfo($additional);
274
- $profile->save();
275
- } catch (Exception $e) {
276
- Mage::logException($e);
277
- }
278
- }
279
- }
280
-
281
- $profile->setIsCronJob(true);
282
-
283
- try {
284
- $recurringProfile->processRequest($profile);
285
- } catch (Exception $e) {
286
- $paymentFailures = $recurringProfile->checkMaxPaymentFailures($profile);
287
- Mage::logException($e);
288
- }
289
- }
290
- }
291
- return;
292
- }
 
 
 
 
 
293
  }
1
+ <?php
2
+ /**
3
+ *
4
+ */
5
+ class Eway_Rapid31_Model_Observer
6
+ {
7
+
8
+ /* @var Magento_Sales_Model_Order_Invoice*/
9
+ public $invoice;
10
+
11
+ public function myCards()
12
+ {
13
+
14
+ }
15
+
16
+ public function checkCustomerMark()
17
+ {
18
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
19
+ $fraudEnabled = Mage::getStoreConfig('payment/ewayrapid_general/block_fraud_customers');
20
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
21
+ $markFraud = $customer->getMarkFraud();
22
+ $unblock = $customer->getBlockFraudCustomer();
23
+ if ((int)$markFraud === 1
24
+ && $fraudEnabled
25
+ && (int)$unblock === 0
26
+ ) {
27
+ Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
28
+ Mage::app()->getResponse()->sendResponse();
29
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Your latest payment is being reviewed and you cannot place a new order temporarily. Please try again later.'));
30
+ exit;
31
+ }
32
+ }
33
+ }
34
+
35
+ public function sales_order_save_before($observer) {
36
+
37
+ }
38
+
39
+ public function sales_order_save_after($observer) {
40
+
41
+ }
42
+
43
+ public function sales_order_place_before($observer) {
44
+ // Check order fraud here
45
+ // ...
46
+ $fraud = Mage::getSingleton('core/session')->getData('fraud');
47
+ if($fraud === 1) {
48
+
49
+ }
50
+ }
51
+
52
+ public function sales_order_place_after($observer) {
53
+ // Check order fraud here
54
+ // ...
55
+
56
+ $fraud = Mage::getSingleton('core/session')->getData('fraud');
57
+ if($fraud === 1) {
58
+
59
+ }
60
+ }
61
+
62
+ public function sales_order_invoice_save_after($observer)
63
+ {
64
+ try {
65
+ /* @var $order Magento_Sales_Model_Order_Invoice */
66
+ $this->invoice = $observer->getEvent()->getInvoice();
67
+ $this->invoice->sendEmail();
68
+ } catch (Mage_Core_Exception $e) {
69
+ Mage::log("Error sending invoice email: " . $e->getMessage());
70
+ }
71
+ return $this;
72
+ }
73
+
74
+ public function checkout_submit_all_after(Varien_Event_Observer $observer)
75
+ {
76
+ $fraud = Mage::getSingleton('core/session')->getData('fraud');
77
+ $comment = Mage::getSingleton('core/session')->getData('fraudMessage');
78
+ // Read setting config enabled fraud or not
79
+ if ($fraud === 1 && $order = $observer->getEvent()->getOrder()) {
80
+ $order->setState('fraud');
81
+ $order->setStatus('fraud');
82
+ if ($comment) {
83
+ $comment = 'An order is marked as Suspected Fraud. Because it contains: ' . $comment;
84
+ $order->addStatusHistoryComment($comment)
85
+ ->setIsVisibleOnFront(false)
86
+ ->setIsCustomerNotified(false);
87
+ }
88
+ $order->save();
89
+
90
+ // Update user to fraud
91
+ $session = Mage::getSingleton('customer/session');
92
+ if ($session->isLoggedIn()) {
93
+ $customer = $session->getCustomer();
94
+ $customer->setData('mark_fraud', 1);
95
+ $customer->save();
96
+ }
97
+
98
+ Mage::getSingleton('core/session')->unsetData('fraud');
99
+ Mage::getSingleton('core/session')->unsetData('fraudMessage');
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Update eway transaction for order
105
+ * @param Varien_Event_Observer $observer
106
+ */
107
+ public function checkout_type_onepage_save_order_after(Varien_Event_Observer $observer)
108
+ {
109
+ $order = $observer->getData('order');
110
+ $order->setEwayTransactionId($order->getPayment()->getTransactionId());
111
+ $order->save();
112
+
113
+ }
114
+ /*
115
+ * create order of recurring profile
116
+ *
117
+ * @param Varien_Event_Observer $observer
118
+ */
119
+ public function createRecurringOrder(Varien_Event_Observer $observer)
120
+ {
121
+ $profiles = $observer->getEvent()->getRecurringProfiles();
122
+
123
+ if (isset($profiles[0])) {
124
+ /** @var Mage_Sales_Model_Recurring_Profile $profile */
125
+ $profile = $profiles[0];
126
+ } else {
127
+ return;
128
+ }
129
+
130
+ //if Billing Frequency <= 0 or isn't numeric, Status of recurring profile changed to canceled
131
+ if (!$profile->getPeriodFrequency()
132
+ || (string)(int) $profile->getPeriodFrequency() !== ltrim($profile->getPeriodFrequency(), '0')
133
+ || (int) $profile->getPeriodFrequency() <= 0
134
+ ) {
135
+ $profile->cancel();
136
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Billing Frequency is wrong. It must be numeric and greater than 0. Status of recurring profile is changed to canceled'));
137
+ $session = Mage::getSingleton('checkout/type_onepage')->getCheckout();
138
+ $session->setLastRecurringProfileIds(null);
139
+ return;
140
+ }
141
+
142
+ $quote = $observer->getEvent()->getQuote();
143
+
144
+ /** @var Eway_Rapid31_Model_RecurringProfile $recurringProfile */
145
+ $recurringProfile = Mage::getModel('ewayrapid/recurringProfile');
146
+ $orderItemInfo = $profile->getOrderItemInfo();
147
+ $buyRequest = unserialize($orderItemInfo['info_buyRequest']);
148
+
149
+ // timezone used as store's timezone
150
+ $startDate = isset($buyRequest['recurring_profile_start_datetime']) && $buyRequest['recurring_profile_start_datetime'] ? $buyRequest['recurring_profile_start_datetime'] : null;
151
+
152
+ $additional = $profile->getAdditionalInfo();
153
+ $token = $recurringProfile->processToken($quote);
154
+ $token = json_decode($token, true);
155
+ $additional['token'] = $token;
156
+ $additional['startDate'] = $startDate;
157
+ $additional['initialFee'] = true;
158
+ $profile->setAdditionalInfo($additional);
159
+ $profile->save();
160
+
161
+ // charge Initial Fee if It is greater than 0 and is numeric
162
+ if ($profile->getInitAmount()
163
+ && (float) $profile->getInitAmount() > 0
164
+ //&& (string)(int) $profile->getInitAmount() === ltrim($profile->getInitAmount(), '0')
165
+ ) {
166
+ try {
167
+ $recurringProfile->processInitialFee($profile);
168
+ } catch (Exception $e) {
169
+ $additional = $profile->getAdditionalInfo();
170
+ $additional['initialFee'] = false;
171
+ if ($profile->getInitMayFail() == '1') {
172
+ // Allow Initial Fee Failure = yes
173
+ // change status recurring profile = suspended
174
+ $profile->suspend();
175
+ $errorMessage = Mage::getSingleton('core/session')->getData('errorMessage');
176
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while making the transaction by Initial Fee (Error message: %s). Status of recurring profile is changed to suspended.', $errorMessage));
177
+ return;
178
+
179
+ } else {
180
+ // Allow Initial Fee Failure = no
181
+ // Auto Bill on Next Cycle = no
182
+ // set additionalInfo['outstanding'] = Initial Fee
183
+ if (!$profile->getBillFailedLater()) {
184
+ $additional['outstanding'] = $profile->getInitAmount();
185
+ }
186
+ }
187
+ $profile->setAdditionalInfo($additional);
188
+ $profile->save();
189
+ }
190
+ }
191
+
192
+ // check current time >= started time
193
+ if (!$startDate || $recurringProfile->checkRecurringTimeStart($startDate)) {
194
+ try {
195
+ // create order
196
+ // before day = current date // check if frequency >1day
197
+ // next day with current date
198
+ $recurringProfile->processRequest($profile);
199
+ } catch (Exception $e) {
200
+ $errorMessage = Mage::getSingleton('core/session')->getData('errorMessage');
201
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. (Error message: %s)', $errorMessage));
202
+ // suspend recurring profile when response data contains error and/or TransactionID is null
203
+ $checkPaymentFailures = $recurringProfile->checkMaxPaymentFailures($profile);
204
+ if (!$checkPaymentFailures) {
205
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Out of Payment failures. Status of recurring profile is changed to suspended.'));
206
+ }
207
+ return;
208
+ }
209
+ } else {
210
+ // not created order
211
+ // before day = null
212
+ // next day = date of started time
213
+ $additionalInfo = $profile->getAdditionalInfo();
214
+ $additionalInfo['nextDate'] = $startDate;
215
+ $profile->setAdditionalInfo($additionalInfo);
216
+ $profile->save();
217
+ }
218
+ }
219
+
220
+ /**
221
+ * load recurring profiles if methodcode = ewayrapid_saved or ewayrapid_ewayone
222
+ *
223
+ * @param array $methodCode
224
+ * @return array
225
+ */
226
+ protected function _loadProfileByMethod($methodCode = array('ewayrapid_saved', 'ewayrapid_ewayone'))
227
+ {
228
+ $modelRecurringProfile = Mage::getModel('sales/recurring_profile')->getCollection()
229
+ ->addFieldToFilter('method_code', array('in' => $methodCode))
230
+ ->addFieldToFilter('state', 'active')
231
+ ->addFieldToFilter('additional_info', array('notnull' => true))
232
+ ->addFieldToFilter(
233
+ 'period_max_cycles', array(
234
+ array('null' => true),
235
+ array('gt' => 0)
236
+ )
237
+ );
238
+ $profiles = array();
239
+
240
+ foreach ($modelRecurringProfile as $item) {
241
+ /** @var Mage_Sales_Model_Recurring_Profile $item */
242
+ $additionalInfo = unserialize($item->getAdditionalInfo());
243
+ $billingInfo = unserialize($item->getBillingAddressInfo());
244
+ $addressInfo = unserialize($item->getShippingAddressInfo());
245
+ $orderItemInfo = unserialize($item->getOrderItemInfo());
246
+ $orderInfo = unserialize($item->getOrderInfo());
247
+ $item->setBillingAddressInfo($billingInfo);
248
+ $item->setShippingAddressInfo($addressInfo);
249
+ $item->setOrderItemInfo($orderItemInfo);
250
+ $item->setAdditionalInfo($additionalInfo);
251
+ $item->setOrderInfo($orderInfo);
252
+ $profiles[] = $item;
253
+ }
254
+ return $profiles;
255
+ }
256
+
257
+ /**
258
+ * cron recurring profile to create order
259
+ */
260
+ public function cronRecurringOrder()
261
+ {
262
+ $profiles = $this->_loadProfileByMethod();
263
+ foreach ($profiles as $profile) {
264
+ /** @var Mage_Sales_Model_Recurring_Profile $profile */
265
+ /** @var Eway_Rapid31_Model_RecurringProfile $recurringProfile */
266
+ $recurringProfile = Mage::getModel('ewayrapid/recurringProfile');
267
+
268
+ $recurringProfile->updateNextDate($profile);
269
+
270
+ // check run cron job conditions
271
+ if ($recurringProfile->checkRecurringProfileRunCronJob($profile)) {
272
+ // check charge money initial Fee
273
+ $additional = $profile->getAdditionalInfo();
274
+ if ($additional['initialFee'] == false) {
275
+ if (!$profile->getInitMayFail() && $profile->getBillFailedLater()) {
276
+ try {
277
+ $recurringProfile->processInitialFee($profile);
278
+ $additional['initialFee'] = true;
279
+ $profile->setAdditionalInfo($additional);
280
+ $profile->save();
281
+ } catch (Exception $e) {
282
+ Mage::logException($e);
283
+ }
284
+ }
285
+ }
286
+
287
+ $profile->setIsCronJob(true);
288
+
289
+ try {
290
+ $recurringProfile->processRequest($profile);
291
+ } catch (Exception $e) {
292
+ $paymentFailures = $recurringProfile->checkMaxPaymentFailures($profile);
293
+ Mage::logException($e);
294
+ }
295
+ }
296
+ }
297
+ }
298
  }
app/code/community/Eway/Rapid31/Model/RecurringProfile.php CHANGED
@@ -1,531 +1,532 @@
1
- <?php
2
-
3
- class Eway_Rapid31_Model_RecurringProfile
4
- {
5
-
6
- /**
7
- * @var Mage_Sales_Model_Recurring_Profile
8
- */
9
- protected $_recurringProfile;
10
- /**
11
- * eway transaction id
12
- * @var string
13
- */
14
- protected $_txdId;
15
- /**
16
- * total price of all nominal items. i.e $10*5 = $50
17
- * @var float
18
- */
19
- protected $_price;
20
- /**
21
- * shipping fee
22
- * @var float
23
- */
24
- protected $_shippingAmount;
25
- /**
26
- * tax amount
27
- * @var float
28
- */
29
- protected $_taxAmount;
30
- /**
31
- * grand total
32
- * @var float
33
- */
34
- protected $_amount;
35
-
36
- /**
37
- * period type
38
- *
39
- * @var string
40
- */
41
- protected $_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_REGULAR;
42
-
43
- /**
44
- * @param Mage_Sales_Model_Recurring_Profile $profile
45
- * @throws Exception
46
- */
47
- public function processRequest(Mage_Sales_Model_Recurring_Profile $profile)
48
- {
49
- $this->_recurringProfile = $profile;
50
- try {
51
- $this->_checkRecurringProfile();
52
- $this->_checkoutRecurring();
53
- $this->_processRecurringProfile();
54
- } catch (Exception $e) {
55
- throw $e;
56
- }
57
- $this->updateBeforeDate();
58
- $this->nextDate();
59
- $this->updatePeriodMaxCycles();
60
- }
61
-
62
- /**
63
- * check eway active, check whether method code is eway
64
- */
65
- protected function _checkRecurringProfile()
66
- {
67
- $methodCode = $this->_recurringProfile->getMethodCode();
68
- if ($methodCode != 'ewayrapid_saved' && $methodCode != 'ewayrapid_ewayone') {
69
- throw new Exception(sprintf('Method "%s" is not eWAY Rapid (Saved).', $methodCode));
70
- }
71
- if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
72
- throw new Exception(sprintf('Method "%s" is not available.', $methodCode));
73
- }
74
- }
75
-
76
- /**
77
- * charge money for recurring item
78
- */
79
- protected function _checkoutRecurring()
80
- {
81
- /** @var Mage_Sales_Model_Order $order */
82
- $order = Mage::getModel('sales/order');
83
-
84
- $item = new Varien_Object($this->_recurringProfile->getOrderItemInfo());
85
-
86
- $this->_price = $item->getBasePrice() * $item->getQty();
87
-
88
- $additionalInfo = $this->_recurringProfile->getAdditionalInfo();
89
-
90
- // check isset TrialBilling
91
- // Trial Billing Frequency <= 0 or isn't numeric => failure
92
- if ($this->_recurringProfile->getTrialBillingAmount()
93
- && $this->_recurringProfile->getTrialPeriodFrequency()
94
- && $this->_recurringProfile->getTrialPeriodMaxCycles()
95
- && $this->_recurringProfile->getTrialPeriodUnit()
96
- && (string)(int) $this->_recurringProfile->getTrialPeriodFrequency() === ltrim($this->_recurringProfile->getTrialPeriodFrequency(), '0')
97
- && (int) $this->_recurringProfile->getTrialPeriodFrequency() > 0
98
- ) {
99
- $trialPeriodMaxCycles = (int)$this->_recurringProfile->getTrialPeriodMaxCycles();
100
- if (!isset($additionalInfo['trialPeriodMaxCycles'])) {
101
- $additionalInfo['trialPeriodMaxCycles'] = $trialPeriodMaxCycles;
102
- $this->_recurringProfile->setAdditionalInfo($additionalInfo);
103
- $this->_price = $this->_recurringProfile->getTrialBillingAmount();
104
- $this->_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL;
105
- }
106
- elseif (isset($additionalInfo['trialPeriodMaxCycles']) && $additionalInfo['trialPeriodMaxCycles'] > 0) {
107
- $this->_price = $this->_recurringProfile->getTrialBillingAmount();
108
- $this->_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL;
109
- }
110
- }
111
-
112
- // calculate total amount
113
- $this->_shippingAmount = $item->getBaseShippingAmount();
114
- $this->_taxAmount = $item->getBaseTaxAmount();
115
- $this->_amount = $this->_price + $this->_shippingAmount + $this->_taxAmount;
116
-
117
- // init order
118
- /** @var Mage_Sales_Model_Order_Item $orderItem */
119
- $orderItem = Mage::getModel('sales/order_item')
120
- ->setName($item->getName())
121
- ->setSku($item->getSku())
122
- ->setDescription($item->getDescription())
123
- ->setQtyOrdered($item->getQty())
124
- ->setBasePrice($item->getBasePrice())
125
- ->setBaseTaxAmount($item->getBaseTaxAmount())
126
- ->setBaseRowTotalInclTax($item->getBaseRowTotalInclTax());
127
-
128
- $order->addItem($orderItem);
129
-
130
- $shippingInfo = $this->_recurringProfile->getShippingAddressInfo();
131
- $shippingAddress = Mage::getModel('sales/order_address')
132
- ->setData($shippingInfo)
133
- ->setId(null);
134
-
135
- // get base currency code
136
- $orderInfo = new Varien_Object($this->_recurringProfile->getOrderInfo());
137
- $currencyCode = $orderInfo->getBaseCurrencyCode();
138
-
139
- $order->setShippingAddress($shippingAddress);
140
- $order->setBaseCurrencyCode($currencyCode);
141
-
142
- /** @var Mage_Sales_Model_Order_Payment $payment */
143
- $payment = Mage::getModel('sales/order_payment');
144
- $payment->setOrder($order);
145
- $payment->setIsRecurring(true);
146
- $payment->setIsInitialFee(true);
147
-
148
- $customerId = $this->_recurringProfile->getCustomerId();
149
- $payment->setCustomerId($customerId);
150
-
151
- $tokenId = $additionalInfo['token']['saved_token'];
152
- $payment->setTokenId($tokenId);
153
-
154
- /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */
155
- $ewaySave = Mage::getModel('ewayrapid/method_saved');
156
-
157
- $paymentAction = Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
158
- if ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
159
- $ewaySave->authorize($payment, $this->_amount);
160
- } elseif ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
161
- $ewaySave->capture($payment, $this->_amount);
162
- }
163
- if (!$payment->getTransactionId()) {
164
- throw new Exception('Transaction is not available');
165
- } else {
166
- $this->_txdId = $payment->getTransactionId();
167
- }
168
- /** @todo: change status of order = "eWAY Authorised"
169
- * now status order = "processing"
170
- */
171
- }
172
-
173
- /**
174
- * Process notification from recurring profile payments
175
- *
176
- * @throws Exception
177
- * @throws Mage_Core_Exception
178
- */
179
- protected function _processRecurringProfile()
180
- {
181
- try {
182
- $this->_registerRecurringProfilePaymentCapture();
183
- if ($this->_periodType == Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL) {
184
- $additionalInfo = $this->_recurringProfile->getAdditionalInfo();
185
- $additionalInfo['trialPeriodMaxCycles'] -= 1;
186
- $this->_recurringProfile->setAdditionalInfo($additionalInfo);
187
- $this->_recurringProfile->save();
188
- }
189
- } catch (Mage_Core_Exception $e) {
190
- throw $e;
191
- }
192
- }
193
-
194
- /**
195
- * Register recurring payment notification, create and process order
196
- */
197
- protected function _registerRecurringProfilePaymentCapture()
198
- {
199
- $price = $this->_price;
200
- $tax = $this->_taxAmount;
201
- $shipping = $this->_shippingAmount;
202
- $grandTotal = $this->_amount;
203
- $periodType = $this->_periodType;
204
- $transactionId = $this->_txdId;
205
- $ewayMessage = '';
206
-
207
- $productItemInfo = new Varien_Object;
208
- /** @todo: response doesn't contain period type / payment type */
209
- $productItemInfo->setPaymentType($periodType);
210
- $productItemInfo->setTaxAmount($tax);
211
- $productItemInfo->setShippingAmount($shipping);
212
- $productItemInfo->setPrice($price);
213
-
214
-
215
- /** @var Mage_Sales_Model_Recurring_Profile $recurringProfile */
216
- $recurringProfile = $this->_recurringProfile;
217
- $order = $recurringProfile->createOrder($productItemInfo);
218
- $payment = $order->getPayment();
219
- $payment->setTransactionId($transactionId)
220
- ->setPreparedMessage($ewayMessage)
221
- ->setIsTransactionClosed(0);
222
- $order->save();
223
- $this->_recurringProfile->addOrderRelation($order->getId());
224
- $payment->registerCaptureNotification($grandTotal);
225
- $order->save();
226
-
227
- // notify customer
228
- if ($invoice = $payment->getCreatedInvoice()) {
229
- $message = Mage::helper('paypal')->__('Notified customer about invoice #%s.', $invoice->getIncrementId());
230
- $comment = $order->sendNewOrderEmail()->addStatusHistoryComment($message)
231
- ->setIsCustomerNotified(true)
232
- ->save();
233
- }
234
-
235
- if (!$recurringProfile->getIsCronJob()) {
236
- $session = Mage::getSingleton('checkout/type_onepage')->getCheckout();
237
- $session->setLastOrderId($order->getId());
238
- }
239
- }
240
-
241
- /**
242
- * process token if customer create and edit token when checkout with recurring profile
243
- *
244
- * @param Mage_Sales_Model_Quote $quote
245
- * @return string
246
- * @throws Exception
247
- */
248
- public function processToken(Mage_Sales_Model_Quote $quote)
249
- {
250
- try {
251
- $billing = $quote->getBillingAddress();
252
- $payment = $quote->getPayment();
253
-
254
- /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */
255
- $ewaySave = Mage::getModel('ewayrapid/method_saved');
256
- $ewaySave->setData('info_instance', $payment);
257
-
258
- /** @var Mage_Sales_Model_Order $order */
259
- $order = Mage::getModel('sales/order');
260
- /*$order->setBillingAddress($billing);*/
261
-
262
- /** @var Mage_Sales_Model_Order_Payment $paymentObj */
263
- $paymentObj = Mage::getModel('sales/order_payment');
264
- $paymentObj->setOrder($order);
265
-
266
- $request = Mage::getModel('ewayrapid/request_token');
267
-
268
- $ewaySave->_setBilling($billing);
269
- $ewaySave->_shouldCreateOrUpdateToken($paymentObj, $request);
270
- return $payment->getAdditionalData();
271
- } catch (Exception $e) {
272
- throw $e;
273
- }
274
- }
275
-
276
- /**
277
- * update day was run of recurring profile when cron job create order
278
- */
279
- public function updateBeforeDate()
280
- {
281
- // timezone used as store's timezone
282
- $currentDate = date("Y-m-d", Mage::getModel('core/date')->timestamp(time()));
283
- $additionalInfo = $this->_recurringProfile->getAdditionalInfo();
284
- $additionalInfo['beforeDate'] = $currentDate;
285
- $this->_recurringProfile->setAdditionalInfo($additionalInfo);
286
- $this->_recurringProfile->save();
287
- }
288
-
289
-
290
- /**
291
- * @param null $startDate
292
- *
293
- * calculate the next date create order of recurring profile
294
- * Timezone of startDate is store's timezone
295
- * Timezone of startDatetime load into recurring profile is store's timezone
296
- */
297
- public function nextDate($startDate = null)
298
- {
299
- // when recurring profile loaded, startDate updated by currentDate
300
- // timezone used as store's timezone
301
- if ($startDate == null) {
302
- $startDate = $this->_recurringProfile->getStartDatetime();
303
- $date = new DateTime($startDate, new DateTimeZone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE));
304
- $timezone = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
305
- $date->setTimezone(new DateTimeZone($timezone));
306
- $startDate = $date->format('Y-m-d');
307
- }
308
-
309
- $frequency = (int)$this->_recurringProfile->getPeriodFrequency();
310
- $unit = $this->_recurringProfile->getPeriodUnit();
311
-
312
- if ($unit === 'week') {
313
- $unit = 'day';
314
- $frequency = $frequency * 7;
315
- }
316
- if ($unit === 'two weeks') {
317
- $unit = 'day';
318
- $frequency = $frequency * 14;
319
- }
320
-
321
- $newDate = date('Y-m-d', strtotime('+' . $frequency . $unit, strtotime($startDate)));
322
-
323
- if (!$this->_checkDate($unit, $frequency, $startDate, $newDate)) {
324
- $newDate = date('Y-m-d', strtotime('-1day', strtotime(date('Y-m-1', strtotime('+1month', strtotime($newDate))))));
325
- }
326
-
327
- $additionalInfo = $this->_recurringProfile->getAdditionalInfo();
328
- $additionalInfo['nextDate'] = $newDate;
329
- $this->_recurringProfile->setAdditionalInfo($additionalInfo);
330
- $this->_recurringProfile->save();
331
- }
332
-
333
- /**
334
- * update period max cycles of recurring profile when cron job create order
335
- */
336
- public function updatePeriodMaxCycles()
337
- {
338
- // edit period max cycles if It is greater than or equal 0 and is numeric
339
- // If period max cycles <= 0 or null, recurring profile will run forever
340
- if ($periodMaxCycles = $this->_recurringProfile->getPeriodMaxCycles()) {
341
- if ((string)(int) $periodMaxCycles === ltrim($periodMaxCycles, '0') && $periodMaxCycles > 0) {
342
- $periodMaxCycles = (int) $periodMaxCycles - 1;
343
- $this->_recurringProfile->setPeriodMaxCycles($periodMaxCycles);
344
- $this->_recurringProfile->save();
345
- }
346
- }
347
- }
348
-
349
- /**
350
- * check date valid
351
- *
352
- * @param $unit
353
- * @param $frequency
354
- * @param $startDate
355
- * @param $newDate
356
- * @return bool
357
- */
358
- protected function _checkDate($unit, $frequency, $startDate, $newDate)
359
- {
360
- if('day' === $unit) {
361
- return true;
362
- }
363
-
364
- list($oldYear, $oldMonth, $oldDay) = explode('-', date('Y-m-d', strtotime($startDate)));
365
- list($newYear, $newMonth, $newDay) = explode('-', date('Y-m-d', strtotime($newDate)));
366
-
367
- if(($oldDay + (int)('day' == $unit ? $frequency : 0)) == $newDay && ($oldMonth + (int)('month' == $unit ? $frequency : 0)) == $newMonth && ($oldYear + (int)('year' == $unit ? $frequency : 0)) == $newYear) {
368
- return true;
369
- }
370
- return false;
371
- }
372
-
373
- /**
374
- * check run cron job conditions
375
- *
376
- * @param Mage_Sales_Model_Recurring_Profile $profile
377
- * @return bool
378
- */
379
- public function checkRecurringProfileRunCronJob(Mage_Sales_Model_Recurring_Profile $profile)
380
- {
381
- $additionalInfo = $profile->getAdditionalInfo();
382
- $timezone = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
383
- // timezone used as store's timezone
384
- $nextDate = new DateTime(date("Y-m-d", strtotime($additionalInfo['nextDate'])), new DateTimeZone($timezone));
385
- $currentDate = new DateTime(date("Y-m-d", Mage::getModel('core/date')->timestamp(time())), new DateTimeZone($timezone));
386
- if (!isset($additionalInfo['beforeDate']) || $additionalInfo['beforeDate'] == null) {
387
- if($nextDate == $currentDate) {
388
- return true;
389
- }
390
- } else {
391
- $beforeDate = new DateTime(date("Y-m-d", strtotime($additionalInfo['beforeDate'])), new DateTimeZone($timezone));
392
- if ($beforeDate < $currentDate && $nextDate == $currentDate) {
393
- return true;
394
- }
395
- }
396
- return false;
397
- }
398
-
399
- /**
400
- * check current time >= started time
401
- *
402
- * @param null $startDate
403
- * @return bool
404
- */
405
- public function checkRecurringTimeStart($startDate = null)
406
- {
407
- // fix for ambigious timestamp (dashes force to dd/mm not mm/dd)
408
- //$startDate = str_replace('/', '-', $startDate);
409
- // timezone used as store's timezone
410
- return strtotime(date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()))) >= strtotime($startDate);
411
- }
412
-
413
- /**
414
- * process Initial Fee
415
- *
416
- * @param Mage_Sales_Model_Recurring_Profile $profile
417
- */
418
- public function processInitialFee(Mage_Sales_Model_Recurring_Profile $profile)
419
- {
420
- // charge Initial Fee
421
- /** @var Mage_Sales_Model_Order $order */
422
- $order = Mage::getModel('sales/order');
423
- $amount = $profile->getInitAmount();
424
- $shippingInfo = $profile->getShippingAddressInfo();
425
- $shippingAddress = Mage::getModel('sales/order_address')
426
- ->setData($shippingInfo)
427
- ->setId(null);
428
-
429
- $orderInfo = new Varien_Object($profile->getOrderInfo());
430
- $currencyCode = $orderInfo->getBaseCurrencyCode();
431
-
432
- $order->setShippingAddress($shippingAddress);
433
- $order->setBaseCurrencyCode($currencyCode);
434
-
435
- /** @var Mage_Sales_Model_Order_Payment $payment */
436
- $payment = Mage::getModel('sales/order_payment');
437
- $payment->setOrder($order);
438
- $payment->setIsRecurring(true);
439
- $payment->setIsInitialFee(true);
440
-
441
- $customerId = $profile->getCustomerId();
442
- $payment->setCustomerId($customerId);
443
-
444
- $additionalInfo = $profile->getAdditionalInfo();
445
- $tokenId = $additionalInfo['token']['saved_token'];
446
- $payment->setTokenId($tokenId);
447
-
448
- /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */
449
- $ewaySave = Mage::getModel('ewayrapid/method_saved');
450
- $paymentAction = Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
451
- if ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
452
- $ewaySave->authorize($payment, $amount);
453
- } elseif ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
454
- $ewaySave->capture($payment, $amount);
455
- }
456
- /** @todo: change status of order = "eWAY Authorised"
457
- * now status order = "processing"
458
- */
459
- }
460
-
461
- /**
462
- * If next date on profile is less than today, set next date to today
463
- * (fixes missed days)
464
- *
465
- * @param Mage_Sales_Model_Recurring_Profile $profile
466
- */
467
- public function updateNextDate(Mage_Sales_Model_Recurring_Profile $profile)
468
- {
469
- $timezone = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
470
- $additionalInfo = $profile->getAdditionalInfo();
471
- // timezone used as store's timezone
472
- $nextDate = new DateTime(date("Y-m-d", strtotime($additionalInfo['nextDate'])), new DateTimeZone($timezone));
473
- // timezone used as store's timezone
474
- $currentDate = new DateTime(date("Y-m-d", Mage::getModel('core/date')->timestamp(time())), new DateTimeZone($timezone));
475
- if ($nextDate < $currentDate) {
476
- $this->_recurringProfile = $profile;
477
- $startDate = $currentDate->format('Y-m-d');
478
- $this->nextDate($startDate);
479
- }
480
- }
481
-
482
- /**
483
- * @param Mage_Sales_Model_Recurring_Profile $profile
484
- * @param bool $bool
485
- * @return bool
486
- *
487
- * check Maximum Payment Failures
488
- * Maximum Payment Failures <= 0 -> run forever
489
- * Maximum Payment Failures > 0 -> save countFailures into additional Info
490
- * if isset countFailures -> countFailures - 1
491
- * if countFailures = 0 -> profile is suspended
492
- * if Maximum Payment Failures = null -> run forever
493
- */
494
- public function checkMaxPaymentFailures(Mage_Sales_Model_Recurring_Profile $profile, $bool = true)
495
- {
496
- $additional = $profile->getAdditionalInfo();
497
- switch (true) {
498
- // Maximum Payment Failures <= 0 or = null -> run forever
499
- case (int) $profile->getSuspensionThreshold() <= 0:
500
- break;
501
- // Maximum Payment Failures > 0 -> save countFailures into additional Info
502
- // if countFailures = 0 -> profile is suspended
503
- case $profile->getSuspensionThreshold() && !isset($additional['paymentFailures']):
504
- $additional['paymentFailures'] = (int) $profile->getSuspensionThreshold() - 1;
505
- $profile->setAdditionalInfo($additional);
506
- $profile->save();
507
- if ($additional['paymentFailures'] == 0) {
508
- $profile->suspend();
509
- $bool = false;
510
- }
511
- break;
512
- // Maximum Payment Failures > 0 -> save countFailures into additional Info
513
- // if isset countFailures -> countFailures - 1
514
- // if countFailures = 0 -> profile is suspended
515
- case $profile->getSuspensionThreshold() && $additional['paymentFailures'] > 0:
516
- $additional['paymentFailures'] -= 1;
517
- $profile->setAdditionalInfo($additional);
518
- $profile->save();
519
- if ($additional['paymentFailures'] == 0) {
520
- $profile->suspend();
521
- $bool = false;
522
- }
523
- break;
524
- default:
525
- $profile->suspend();
526
- $bool = false;
527
- break;
528
- }
529
- return $bool;
530
- }
 
531
  }
1
+ <?php
2
+
3
+ class Eway_Rapid31_Model_RecurringProfile
4
+ {
5
+
6
+ /**
7
+ * @var Mage_Sales_Model_Recurring_Profile
8
+ */
9
+ protected $_recurringProfile;
10
+ /**
11
+ * eway transaction id
12
+ * @var string
13
+ */
14
+ protected $_txdId;
15
+ /**
16
+ * total price of all nominal items. i.e $10*5 = $50
17
+ * @var float
18
+ */
19
+ protected $_price;
20
+ /**
21
+ * shipping fee
22
+ * @var float
23
+ */
24
+ protected $_shippingAmount;
25
+ /**
26
+ * tax amount
27
+ * @var float
28
+ */
29
+ protected $_taxAmount;
30
+ /**
31
+ * grand total
32
+ * @var float
33
+ */
34
+ protected $_amount;
35
+
36
+ /**
37
+ * period type
38
+ *
39
+ * @var string
40
+ */
41
+ protected $_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_REGULAR;
42
+
43
+ /**
44
+ * @param Mage_Sales_Model_Recurring_Profile $profile
45
+ * @throws Exception
46
+ */
47
+ public function processRequest(Mage_Sales_Model_Recurring_Profile $profile)
48
+ {
49
+ $this->_recurringProfile = $profile;
50
+ try {
51
+ $this->_checkRecurringProfile();
52
+ $this->_checkoutRecurring();
53
+ $this->_processRecurringProfile();
54
+ } catch (Exception $e) {
55
+ throw $e;
56
+ }
57
+ $this->updateBeforeDate();
58
+ $this->nextDate();
59
+ $this->updatePeriodMaxCycles();
60
+ }
61
+
62
+ /**
63
+ * check eway active, check whether method code is eway
64
+ */
65
+ protected function _checkRecurringProfile()
66
+ {
67
+ $methodCode = $this->_recurringProfile->getMethodCode();
68
+ if ($methodCode != 'ewayrapid_saved' && $methodCode != 'ewayrapid_ewayone') {
69
+ Mage::throwException(sprintf('Method "%s" is not eWAY Rapid (Saved).', $methodCode));
70
+ }
71
+ if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
72
+ Mage::throwException(sprintf('Method "%s" is not available.', $methodCode));
73
+ }
74
+ }
75
+
76
+ /**
77
+ * charge money for recurring item
78
+ */
79
+ protected function _checkoutRecurring()
80
+ {
81
+ /** @var Mage_Sales_Model_Order $order */
82
+ $order = Mage::getModel('sales/order');
83
+
84
+ $item = new Varien_Object($this->_recurringProfile->getOrderItemInfo());
85
+
86
+ $this->_price = $item->getBasePrice() * $item->getQty();
87
+
88
+ $additionalInfo = $this->_recurringProfile->getAdditionalInfo();
89
+
90
+ // check isset TrialBilling
91
+ // Trial Billing Frequency <= 0 or isn't numeric => failure
92
+ if ($this->_recurringProfile->getTrialBillingAmount()
93
+ && $this->_recurringProfile->getTrialPeriodFrequency()
94
+ && $this->_recurringProfile->getTrialPeriodMaxCycles()
95
+ && $this->_recurringProfile->getTrialPeriodUnit()
96
+ && (string)(int) $this->_recurringProfile->getTrialPeriodFrequency() === ltrim($this->_recurringProfile->getTrialPeriodFrequency(), '0')
97
+ && (int) $this->_recurringProfile->getTrialPeriodFrequency() > 0
98
+ ) {
99
+ $trialPeriodMaxCycles = (int)$this->_recurringProfile->getTrialPeriodMaxCycles();
100
+ if (!isset($additionalInfo['trialPeriodMaxCycles'])) {
101
+ $additionalInfo['trialPeriodMaxCycles'] = $trialPeriodMaxCycles;
102
+ $this->_recurringProfile->setAdditionalInfo($additionalInfo);
103
+ $this->_price = $this->_recurringProfile->getTrialBillingAmount();
104
+ $this->_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL;
105
+ } elseif (isset($additionalInfo['trialPeriodMaxCycles']) && $additionalInfo['trialPeriodMaxCycles'] > 0) {
106
+ $this->_price = $this->_recurringProfile->getTrialBillingAmount();
107
+ $this->_periodType = Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL;
108
+ }
109
+ }
110
+
111
+ // calculate total amount
112
+ $this->_shippingAmount = $item->getBaseShippingAmount();
113
+ $this->_taxAmount = $item->getBaseTaxAmount();
114
+ $this->_amount = $this->_price + $this->_shippingAmount + $this->_taxAmount;
115
+
116
+ // init order
117
+ /** @var Mage_Sales_Model_Order_Item $orderItem */
118
+ $orderItem = Mage::getModel('sales/order_item')
119
+ ->setName($item->getName())
120
+ ->setSku($item->getSku())
121
+ ->setDescription($item->getDescription())
122
+ ->setQtyOrdered($item->getQty())
123
+ ->setBasePrice($item->getBasePrice())
124
+ ->setBaseTaxAmount($item->getBaseTaxAmount())
125
+ ->setBaseRowTotalInclTax($item->getBaseRowTotalInclTax());
126
+
127
+ $order->addItem($orderItem);
128
+
129
+ $shippingInfo = $this->_recurringProfile->getShippingAddressInfo();
130
+ $shippingAddress = Mage::getModel('sales/order_address')
131
+ ->setData($shippingInfo)
132
+ ->setId(null);
133
+
134
+ // get base currency code
135
+ $orderInfo = new Varien_Object($this->_recurringProfile->getOrderInfo());
136
+ $currencyCode = $orderInfo->getBaseCurrencyCode();
137
+
138
+ $order->setShippingAddress($shippingAddress);
139
+ $order->setBaseCurrencyCode($currencyCode);
140
+
141
+ /** @var Mage_Sales_Model_Order_Payment $payment */
142
+ $payment = Mage::getModel('sales/order_payment');
143
+ $payment->setOrder($order);
144
+ $payment->setIsRecurring(true);
145
+ $payment->setIsInitialFee(true);
146
+
147
+ $customerId = $this->_recurringProfile->getCustomerId();
148
+ $payment->setCustomerId($customerId);
149
+
150
+ $tokenId = $additionalInfo['token']['saved_token'];
151
+ $payment->setTokenId($tokenId);
152
+
153
+ /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */
154
+ $ewaySave = Mage::getModel('ewayrapid/method_saved');
155
+
156
+ $paymentAction = Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
157
+ if ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
158
+ $ewaySave->authorize($payment, $this->_amount);
159
+ } elseif ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
160
+ $ewaySave->capture($payment, $this->_amount);
161
+ }
162
+ if (!$payment->getTransactionId()) {
163
+ throw new Exception('Transaction is not available');
164
+ } else {
165
+ $this->_txdId = $payment->getTransactionId();
166
+ }
167
+ /** @todo: change status of order = "eWAY Authorised"
168
+ * now status order = "processing"
169
+ */
170
+ }
171
+
172
+ /**
173
+ * Process notification from recurring profile payments
174
+ *
175
+ * @throws Exception
176
+ * @throws Mage_Core_Exception
177
+ */
178
+ protected function _processRecurringProfile()
179
+ {
180
+ try {
181
+ $this->_registerRecurringProfilePaymentCapture();
182
+ if ($this->_periodType == Mage_Sales_Model_Recurring_Profile::PAYMENT_TYPE_TRIAL) {
183
+ $additionalInfo = $this->_recurringProfile->getAdditionalInfo();
184
+ $additionalInfo['trialPeriodMaxCycles'] -= 1;
185
+ $this->_recurringProfile->setAdditionalInfo($additionalInfo);
186
+ $this->_recurringProfile->save();
187
+ }
188
+ } catch (Mage_Core_Exception $e) {
189
+ throw $e;
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Register recurring payment notification, create and process order
195
+ */
196
+ protected function _registerRecurringProfilePaymentCapture()
197
+ {
198
+ $price = $this->_price;
199
+ $tax = $this->_taxAmount;
200
+ $shipping = $this->_shippingAmount;
201
+ $grandTotal = $this->_amount;
202
+ $periodType = $this->_periodType;
203
+ $transactionId = $this->_txdId;
204
+ $ewayMessage = '';
205
+
206
+ $productItemInfo = new Varien_Object;
207
+ /** @todo: response doesn't contain period type / payment type */
208
+ $productItemInfo->setPaymentType($periodType);
209
+ $productItemInfo->setTaxAmount($tax);
210
+ $productItemInfo->setShippingAmount($shipping);
211
+ $productItemInfo->setPrice($price);
212
+
213
+
214
+ /** @var Mage_Sales_Model_Recurring_Profile $recurringProfile */
215
+ $recurringProfile = $this->_recurringProfile;
216
+ $order = $recurringProfile->createOrder($productItemInfo);
217
+ $payment = $order->getPayment();
218
+ $payment->setTransactionId($transactionId)
219
+ ->setPreparedMessage($ewayMessage)
220
+ ->setIsTransactionClosed(0);
221
+ $order->save();
222
+ $this->_recurringProfile->addOrderRelation($order->getId());
223
+ $payment->registerCaptureNotification($grandTotal);
224
+ $order->save();
225
+
226
+ // notify customer
227
+ if ($invoice = $payment->getCreatedInvoice()) {
228
+ $message = Mage::helper('paypal')->__('Notified customer about invoice #%s.', $invoice->getIncrementId());
229
+ $comment = $order->sendNewOrderEmail()->addStatusHistoryComment($message)
230
+ ->setIsCustomerNotified(true)
231
+ ->save();
232
+ }
233
+
234
+ if (!$recurringProfile->getIsCronJob()) {
235
+ $session = Mage::getSingleton('checkout/type_onepage')->getCheckout();
236
+ $session->setLastOrderId($order->getId());
237
+ }
238
+ }
239
+
240
+ /**
241
+ * process token if customer create and edit token when checkout with recurring profile
242
+ *
243
+ * @param Mage_Sales_Model_Quote $quote
244
+ * @return string
245
+ * @throws Exception
246
+ */
247
+ public function processToken(Mage_Sales_Model_Quote $quote)
248
+ {
249
+ try {
250
+ $billing = $quote->getBillingAddress();
251
+ $payment = $quote->getPayment();
252
+
253
+ /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */
254
+ $ewaySave = Mage::getModel('ewayrapid/method_saved');
255
+ $ewaySave->setData('info_instance', $payment);
256
+
257
+ /** @var Mage_Sales_Model_Order $order */
258
+ $order = Mage::getModel('sales/order');
259
+ /*$order->setBillingAddress($billing);*/
260
+
261
+ /** @var Mage_Sales_Model_Order_Payment $paymentObj */
262
+ $paymentObj = Mage::getModel('sales/order_payment');
263
+ $paymentObj->setOrder($order);
264
+
265
+ $request = Mage::getModel('ewayrapid/request_token');
266
+
267
+ $ewaySave->_setBilling($billing);
268
+ $ewaySave->_shouldCreateOrUpdateToken($paymentObj, $request);
269
+ return $payment->getAdditionalData();
270
+ } catch (Exception $e) {
271
+ throw $e;
272
+ }
273
+ }
274
+
275
+ /**
276
+ * update day was run of recurring profile when cron job create order
277
+ */
278
+ public function updateBeforeDate()
279
+ {
280
+ // timezone used as store's timezone
281
+ $currentDate = date("Y-m-d", Mage::getModel('core/date')->timestamp(time()));
282
+ $additionalInfo = $this->_recurringProfile->getAdditionalInfo();
283
+ $additionalInfo['beforeDate'] = $currentDate;
284
+ $this->_recurringProfile->setAdditionalInfo($additionalInfo);
285
+ $this->_recurringProfile->save();
286
+ }
287
+
288
+
289
+ /**
290
+ * @param null $startDate
291
+ *
292
+ * calculate the next date create order of recurring profile
293
+ * Timezone of startDate is store's timezone
294
+ * Timezone of startDatetime load into recurring profile is store's timezone
295
+ */
296
+ public function nextDate($startDate = null)
297
+ {
298
+ // when recurring profile loaded, startDate updated by currentDate
299
+ // timezone used as store's timezone
300
+ if ($startDate == null) {
301
+ $startDate = $this->_recurringProfile->getStartDatetime();
302
+ $date = new DateTime($startDate, new DateTimeZone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE));
303
+ $timezone = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
304
+ $date->setTimezone(new DateTimeZone($timezone));
305
+ $startDate = $date->format('Y-m-d');
306
+ }
307
+
308
+ $frequency = (int)$this->_recurringProfile->getPeriodFrequency();
309
+ $unit = $this->_recurringProfile->getPeriodUnit();
310
+
311
+ if ($unit === 'week') {
312
+ $unit = 'day';
313
+ $frequency = $frequency * 7;
314
+ }
315
+ if ($unit === 'two weeks') {
316
+ $unit = 'day';
317
+ $frequency = $frequency * 14;
318
+ }
319
+
320
+ $newDate = date('Y-m-d', strtotime('+' . $frequency . $unit, strtotime($startDate)));
321
+
322
+ if (!$this->_checkDate($unit, $frequency, $startDate, $newDate)) {
323
+ $newDate = date('Y-m-d', strtotime('-1day', strtotime(date('Y-m-1', strtotime('+1month', strtotime($newDate))))));
324
+ }
325
+
326
+ $additionalInfo = $this->_recurringProfile->getAdditionalInfo();
327
+ $additionalInfo['nextDate'] = $newDate;
328
+ $this->_recurringProfile->setAdditionalInfo($additionalInfo);
329
+ $this->_recurringProfile->save();
330
+ }
331
+
332
+ /**
333
+ * update period max cycles of recurring profile when cron job create order
334
+ */
335
+ public function updatePeriodMaxCycles()
336
+ {
337
+ // edit period max cycles if It is greater than or equal 0 and is numeric
338
+ // If period max cycles <= 0 or null, recurring profile will run forever
339
+ if ($periodMaxCycles = $this->_recurringProfile->getPeriodMaxCycles()) {
340
+ if ((string)(int) $periodMaxCycles === ltrim($periodMaxCycles, '0') && $periodMaxCycles > 0) {
341
+ $periodMaxCycles = (int) $periodMaxCycles - 1;
342
+ $this->_recurringProfile->setPeriodMaxCycles($periodMaxCycles);
343
+ $this->_recurringProfile->save();
344
+ }
345
+ }
346
+ }
347
+
348
+ /**
349
+ * check date valid
350
+ *
351
+ * @param $unit
352
+ * @param $frequency
353
+ * @param $startDate
354
+ * @param $newDate
355
+ * @return bool
356
+ */
357
+ protected function _checkDate($unit, $frequency, $startDate, $newDate)
358
+ {
359
+ if ('day' === $unit) {
360
+ return true;
361
+ }
362
+
363
+ list($oldYear, $oldMonth, $oldDay) = explode('-', date('Y-m-d', strtotime($startDate)));
364
+ list($newYear, $newMonth, $newDay) = explode('-', date('Y-m-d', strtotime($newDate)));
365
+
366
+ if (
367
+ ($oldDay + (int)('day' == $unit ? $frequency : 0)) == $newDay
368
+ && ($oldMonth + (int)('month' == $unit ? $frequency : 0)) == $newMonth
369
+ && ($oldYear + (int)('year' == $unit ? $frequency : 0)) == $newYear
370
+ ) {
371
+ return true;
372
+ }
373
+ return false;
374
+ }
375
+
376
+ /**
377
+ * check run cron job conditions
378
+ *
379
+ * @param Mage_Sales_Model_Recurring_Profile $profile
380
+ * @return bool
381
+ */
382
+ public function checkRecurringProfileRunCronJob(Mage_Sales_Model_Recurring_Profile $profile)
383
+ {
384
+ $additionalInfo = $profile->getAdditionalInfo();
385
+ $timezone = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
386
+ // timezone used as store's timezone
387
+ $nextDate = new DateTime(date("Y-m-d", strtotime($additionalInfo['nextDate'])), new DateTimeZone($timezone));
388
+ $currentDate = new DateTime(date("Y-m-d", Mage::getModel('core/date')->timestamp(time())), new DateTimeZone($timezone));
389
+ if (!isset($additionalInfo['beforeDate']) || $additionalInfo['beforeDate'] == null) {
390
+ if ($nextDate == $currentDate) {
391
+ return true;
392
+ }
393
+ } else {
394
+ $beforeDate = new DateTime(date("Y-m-d", strtotime($additionalInfo['beforeDate'])), new DateTimeZone($timezone));
395
+ if ($beforeDate < $currentDate && $nextDate == $currentDate) {
396
+ return true;
397
+ }
398
+ }
399
+ return false;
400
+ }
401
+
402
+ /**
403
+ * check current time >= started time
404
+ *
405
+ * @param null $startDate
406
+ * @return bool
407
+ */
408
+ public function checkRecurringTimeStart($startDate = null)
409
+ {
410
+ // timezone used as store's timezone
411
+ return strtotime(date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()))) >= strtotime($startDate);
412
+ }
413
+
414
+ /**
415
+ * process Initial Fee
416
+ *
417
+ * @param Mage_Sales_Model_Recurring_Profile $profile
418
+ */
419
+ public function processInitialFee(Mage_Sales_Model_Recurring_Profile $profile)
420
+ {
421
+ // charge Initial Fee
422
+ /** @var Mage_Sales_Model_Order $order */
423
+ $order = Mage::getModel('sales/order');
424
+ $amount = $profile->getInitAmount();
425
+ $shippingInfo = $profile->getShippingAddressInfo();
426
+ $shippingAddress = Mage::getModel('sales/order_address')
427
+ ->setData($shippingInfo)
428
+ ->setId(null);
429
+
430
+ $orderInfo = new Varien_Object($profile->getOrderInfo());
431
+ $currencyCode = $orderInfo->getBaseCurrencyCode();
432
+
433
+ $order->setShippingAddress($shippingAddress);
434
+ $order->setBaseCurrencyCode($currencyCode);
435
+
436
+ /** @var Mage_Sales_Model_Order_Payment $payment */
437
+ $payment = Mage::getModel('sales/order_payment');
438
+ $payment->setOrder($order);
439
+ $payment->setIsRecurring(true);
440
+ $payment->setIsInitialFee(true);
441
+
442
+ $customerId = $profile->getCustomerId();
443
+ $payment->setCustomerId($customerId);
444
+
445
+ $additionalInfo = $profile->getAdditionalInfo();
446
+ $tokenId = $additionalInfo['token']['saved_token'];
447
+ $payment->setTokenId($tokenId);
448
+
449
+ /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */
450
+ $ewaySave = Mage::getModel('ewayrapid/method_saved');
451
+ $paymentAction = Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
452
+ if ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
453
+ $ewaySave->authorize($payment, $amount);
454
+ } elseif ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
455
+ $ewaySave->capture($payment, $amount);
456
+ }
457
+ /** @todo: change status of order = "eWAY Authorised"
458
+ * now status order = "processing"
459
+ */
460
+ }
461
+
462
+ /**
463
+ * If next date on profile is less than today, set next date to today
464
+ * (fixes missed days)
465
+ *
466
+ * @param Mage_Sales_Model_Recurring_Profile $profile
467
+ */
468
+ public function updateNextDate(Mage_Sales_Model_Recurring_Profile $profile)
469
+ {
470
+ $timezone = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
471
+ $additionalInfo = $profile->getAdditionalInfo();
472
+ // timezone used as store's timezone
473
+ $nextDate = new DateTime(date("Y-m-d", strtotime($additionalInfo['nextDate'])), new DateTimeZone($timezone));
474
+ // timezone used as store's timezone
475
+ $currentDate = new DateTime(date("Y-m-d", Mage::getModel('core/date')->timestamp(time())), new DateTimeZone($timezone));
476
+ if ($nextDate < $currentDate) {
477
+ $this->_recurringProfile = $profile;
478
+ $startDate = $currentDate->format('Y-m-d');
479
+ $this->nextDate($startDate);
480
+ }
481
+ }
482
+
483
+ /**
484
+ * @param Mage_Sales_Model_Recurring_Profile $profile
485
+ * @param bool $bool
486
+ * @return bool
487
+ *
488
+ * check Maximum Payment Failures
489
+ * Maximum Payment Failures <= 0 -> run forever
490
+ * Maximum Payment Failures > 0 -> save countFailures into additional Info
491
+ * if isset countFailures -> countFailures - 1
492
+ * if countFailures = 0 -> profile is suspended
493
+ * if Maximum Payment Failures = null -> run forever
494
+ */
495
+ public function checkMaxPaymentFailures(Mage_Sales_Model_Recurring_Profile $profile, $bool = true)
496
+ {
497
+ $additional = $profile->getAdditionalInfo();
498
+ switch (true) {
499
+ // Maximum Payment Failures <= 0 or = null -> run forever
500
+ case (int) $profile->getSuspensionThreshold() <= 0:
501
+ break;
502
+ // Maximum Payment Failures > 0 -> save countFailures into additional Info
503
+ // if countFailures = 0 -> profile is suspended
504
+ case $profile->getSuspensionThreshold() && !isset($additional['paymentFailures']):
505
+ $additional['paymentFailures'] = (int) $profile->getSuspensionThreshold() - 1;
506
+ $profile->setAdditionalInfo($additional);
507
+ $profile->save();
508
+ if ($additional['paymentFailures'] == 0) {
509
+ $profile->suspend();
510
+ $bool = false;
511
+ }
512
+ break;
513
+ // Maximum Payment Failures > 0 -> save countFailures into additional Info
514
+ // if isset countFailures -> countFailures - 1
515
+ // if countFailures = 0 -> profile is suspended
516
+ case $profile->getSuspensionThreshold() && $additional['paymentFailures'] > 0:
517
+ $additional['paymentFailures'] -= 1;
518
+ $profile->setAdditionalInfo($additional);
519
+ $profile->save();
520
+ if ($additional['paymentFailures'] == 0) {
521
+ $profile->suspend();
522
+ $bool = false;
523
+ }
524
+ break;
525
+ default:
526
+ $profile->suspend();
527
+ $bool = false;
528
+ break;
529
+ }
530
+ return $bool;
531
+ }
532
  }
app/code/community/Eway/Rapid31/Model/Request/Abstract.php CHANGED
@@ -1,180 +1,182 @@
1
- <?php
2
-
3
- /**
4
- * Class Eway_Rapid31_Model_Request_Abstract
5
- *
6
- * @method Eway_Rapid31_Model_Field_Customer getCustomer()
7
- * @method Eway_Rapid31_Model_Request_Abstract setCustomer(Eway_Rapid31_Model_Field_Customer $value)
8
- * @method Eway_Rapid31_Model_Field_ShippingAddress getShippingAddress()
9
- * @method Eway_Rapid31_Model_Request_Abstract setShippingAddress(Eway_Rapid31_Model_Field_ShippingAddress $value)
10
- * @method string getShippingMethod()
11
- * @method Eway_Rapid31_Model_Request_Abstract setShippingMethod(string $value)
12
- * @method array getItems()
13
- * @method Eway_Rapid31_Model_Request_Abstract setItems(array $value)
14
- * @method Eway_Rapid31_Model_Field_Payment getPayment()
15
- * @method Eway_Rapid31_Model_Request_Abstract setPayment(Eway_Rapid31_Model_Field_Payment $value)
16
- * @method string getDeviceID()
17
- * @method Eway_Rapid31_Model_Request_Abstract setDeviceID(string $value)
18
- * @method string getCustomerIP()
19
- * @method Eway_Rapid31_Model_Request_Abstract setCustomerIP(string $value)
20
- * @method string getPartnerID()
21
- * @method Eway_Rapid31_Model_Request_Abstract setPartnerID(string $value)
22
- * @method string getTransactionType()
23
- * @method Eway_Rapid31_Model_Request_Abstract setTransactionType(string $value)
24
- * @method string getMethod()
25
- * @method Eway_Rapid31_Model_Request_Abstract setMethod(string $value)
26
- * @method int getTransactionId()
27
- * @method Eway_Rapid31_Model_Request_Abstract setTransactionId(int $value)
28
- * @method Eway_Rapid31_Model_Field_Payment getRefund()
29
- * @method Eway_Rapid31_Model_Request_Abstract setRefund(Eway_Rapid31_Model_Field_Payment $value)
30
- * @method string getRedirectUrl()
31
- * @method Eway_Rapid31_Model_Request_Abstract setRedirectUrl(string $value)
32
- * @method string getCheckoutPayment()
33
- * @method Eway_Rapid31_Model_Request_Abstract setCheckoutPayment(bool $value)
34
- * @method string getCheckoutURL()
35
- * @method Eway_Rapid31_Model_Request_Abstract setCheckoutURL(string $value)
36
- * @method string getCancelUrl()
37
- * @method Eway_Rapid31_Model_Request_Abstract setCancelUrl(string $value)
38
- * @method Eway_Rapid31_Model_Request_Abstract setCustomerReadOnly(bool $value)
39
- */
40
- abstract class Eway_Rapid31_Model_Request_Abstract extends Eway_Rapid31_Model_JsonSerializableAbstract
41
- {
42
- const DEBUG_FILE = 'ewayrapid31_api_request.log';
43
-
44
- /**
45
- * @var Eway_Rapid31_Model_Config
46
- */
47
- protected $_config = null;
48
-
49
- protected function _construct()
50
- {
51
- $this->_config = Mage::getSingleton('ewayrapid/config');
52
- }
53
-
54
- /**
55
- * Do the main API request.
56
- * All API request to eWAY should call this function with appropriate parameters, after set all necessary data.
57
- *
58
- * @param string $action can be one of POST, GET, DELETE or PUT
59
- * @param string $method
60
- * @return Eway_Rapid31_Model_Response
61
- */
62
- protected function _doRapidAPI($action, $method = 'POST') {
63
-
64
- $url = $this->_config->getRapidAPIUrl($action);
65
- $mode = $this->_config->isSandbox() ? '(Sandbox)' : '(Live)';
66
- $this->_log('>>>>> START REQUEST ' . $mode . ' (' . $method . ') ' . ' : ' . $url);
67
-
68
- $ch = curl_init($url);
69
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "X-EWAY-APIVERSION: 40"));
70
- curl_setopt($ch, CURLOPT_USERPWD, $this->_config->getBasicAuthenticationHeader());
71
- switch($method) {
72
- case 'POST':
73
- curl_setopt($ch, CURLOPT_POST, true);
74
- curl_setopt($ch, CURLOPT_POSTFIELDS, $this->jsonSerialize());
75
- $this->_logPostJSON();
76
- break;
77
- case 'GET':
78
- case 'DELETE':
79
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
80
- break;
81
- case 'PUT':
82
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
83
- curl_setopt($ch, CURLOPT_POSTFIELDS, $this->jsonSerialize());
84
- $this->_logPostJSON();
85
- break;
86
- }
87
-
88
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
89
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
90
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->_config->isEnableSSLVerification());
91
-
92
- $result = curl_exec($ch);
93
-
94
- $this->_log('<<<<< RESPONSE:');
95
- $response = Mage::getModel('ewayrapid/response');
96
- if (curl_errno($ch) != CURLE_OK) {
97
- $response->isSuccess(false);
98
- $response->setMessage(Mage::helper('ewayrapid')->__("There is an error in making API request: %s", curl_error($ch)));
99
- $this->_log("There is an error in making API request: " . curl_error($ch));
100
- } else {
101
- $info = curl_getinfo($ch);
102
- $http_code = intval(trim($info['http_code']));
103
- if ($http_code == 401 || $http_code == 404 || $http_code == 403) {
104
- $response->isSuccess(false);
105
- $response->setMessage(Mage::helper('ewayrapid')->__("Please check the API Key and Password %s", $mode));
106
- $this->_log('Access denied. HTTP_CODE = ' . $info['http_code']);
107
- } elseif ($http_code != 200) {
108
- $response->isSuccess(false);
109
- $response->setMessage(Mage::helper('ewayrapid')->__("Error connecting to payment gateway, please try again"));
110
- $this->_log('Error connecting to payment gateway. HTTP_CODE = ' . $info['http_code']);
111
- } else {
112
- $response->isSuccess(true);
113
- $response->decodeJSON($result);
114
- if($this->_config->isDebug()) {
115
- $this->_log('SUCCESS. Response body: ');
116
- $this->_log(print_r(json_decode($result, true), true));
117
- }
118
- $this->_log('SUCCESS. HTTP_CODE = ' . $info['http_code']);
119
- }
120
- curl_close($ch);
121
- }
122
-
123
- $this->_log('===== END REQUEST.');
124
- return $response;
125
- }
126
-
127
- protected function _logPostJSON()
128
- {
129
- if($this->_config->isDebug()) {
130
- $cardDetails = null;
131
- if($this->getCustomer() && $this->getCustomer()->getCardDetails()) {
132
- $cardDetails = $this->getCustomer()->getCardDetails();
133
- $cardDetails->shouldBeMasked();
134
- }
135
- $this->_log('Request body:');
136
- $this->_log(print_r($this->getJsonData(), true));
137
- if(!is_null($cardDetails)) {
138
- $cardDetails->shouldBeMasked(false);
139
- }
140
- }
141
- }
142
-
143
- protected function _log($message, $file = self::DEBUG_FILE)
144
- {
145
- if($this->_config->isDebug()) {
146
- Mage::log($message, Zend_Log::DEBUG, $file, true);
147
- }
148
- }
149
-
150
- protected function _fixTitle($title) {
151
- if ($title == 'n/a' || empty($title)) {
152
- return 'Mr.';
153
- }
154
- return $title;
155
- }
156
-
157
- /**
158
- * Get predicted increment order id
159
- * @return string
160
- */
161
- protected function _getIncrementOrderId($quote)
162
- {
163
- $orderConfig = Mage::getSingleton('eav/config')->getEntityType('order');
164
-
165
- $entityStoreConfig = Mage::getModel('eav/entity_store')
166
- ->loadByEntityStore($orderConfig->getId(), $quote->getStoreId());
167
-
168
- $incrementInstance = Mage::getModel($orderConfig->getIncrementModel())
169
- ->setPrefix($entityStoreConfig->getIncrementPrefix())
170
- ->setPadLength($orderConfig->getIncrementPadLength())
171
- ->setPadChar($orderConfig->getIncrementPadChar())
172
- ->setLastId($entityStoreConfig->getIncrementLastId())
173
- ->setEntityTypeId($entityStoreConfig->getEntityTypeId())
174
- ->setStoreId($entityStoreConfig->getStoreId());
175
-
176
- $incrementId = $incrementInstance->getNextId();
177
-
178
- return $incrementId;
179
- }
 
 
180
  }
1
+ <?php
2
+
3
+ /**
4
+ * Class Eway_Rapid31_Model_Request_Abstract
5
+ *
6
+ * @method Eway_Rapid31_Model_Field_Customer getCustomer()
7
+ * @method Eway_Rapid31_Model_Request_Abstract setCustomer(Eway_Rapid31_Model_Field_Customer $value)
8
+ * @method Eway_Rapid31_Model_Field_ShippingAddress getShippingAddress()
9
+ * @method Eway_Rapid31_Model_Request_Abstract setShippingAddress(Eway_Rapid31_Model_Field_ShippingAddress $value)
10
+ * @method string getShippingMethod()
11
+ * @method Eway_Rapid31_Model_Request_Abstract setShippingMethod(string $value)
12
+ * @method array getItems()
13
+ * @method Eway_Rapid31_Model_Request_Abstract setItems(array $value)
14
+ * @method Eway_Rapid31_Model_Field_Payment getPayment()
15
+ * @method Eway_Rapid31_Model_Request_Abstract setPayment(Eway_Rapid31_Model_Field_Payment $value)
16
+ * @method string getDeviceID()
17
+ * @method Eway_Rapid31_Model_Request_Abstract setDeviceID(string $value)
18
+ * @method string getCustomerIP()
19
+ * @method Eway_Rapid31_Model_Request_Abstract setCustomerIP(string $value)
20
+ * @method string getPartnerID()
21
+ * @method Eway_Rapid31_Model_Request_Abstract setPartnerID(string $value)
22
+ * @method string getTransactionType()
23
+ * @method Eway_Rapid31_Model_Request_Abstract setTransactionType(string $value)
24
+ * @method string getMethod()
25
+ * @method Eway_Rapid31_Model_Request_Abstract setMethod(string $value)
26
+ * @method int getTransactionId()
27
+ * @method Eway_Rapid31_Model_Request_Abstract setTransactionId(int $value)
28
+ * @method Eway_Rapid31_Model_Field_Payment getRefund()
29
+ * @method Eway_Rapid31_Model_Request_Abstract setRefund(Eway_Rapid31_Model_Field_Payment $value)
30
+ * @method string getRedirectUrl()
31
+ * @method Eway_Rapid31_Model_Request_Abstract setRedirectUrl(string $value)
32
+ * @method string getCheckoutPayment()
33
+ * @method Eway_Rapid31_Model_Request_Abstract setCheckoutPayment(bool $value)
34
+ * @method string getCheckoutURL()
35
+ * @method Eway_Rapid31_Model_Request_Abstract setCheckoutURL(string $value)
36
+ * @method string getCancelUrl()
37
+ * @method Eway_Rapid31_Model_Request_Abstract setCancelUrl(string $value)
38
+ * @method Eway_Rapid31_Model_Request_Abstract setCustomerReadOnly(bool $value)
39
+ */
40
+ abstract class Eway_Rapid31_Model_Request_Abstract extends Eway_Rapid31_Model_JsonSerializableAbstract
41
+ {
42
+ const DEBUG_FILE = 'ewayrapid31_api_request.log';
43
+
44
+ /**
45
+ * @var Eway_Rapid31_Model_Config
46
+ */
47
+ protected $_config = null;
48
+
49
+ protected function _construct()
50
+ {
51
+ $this->_config = Mage::getSingleton('ewayrapid/config');
52
+ }
53
+
54
+ /**
55
+ * Do the main API request.
56
+ * All API request to eWAY should call this function with appropriate parameters, after set all necessary data.
57
+ *
58
+ * @param string $action can be one of POST, GET, DELETE or PUT
59
+ * @param string $method
60
+ * @return Eway_Rapid31_Model_Response
61
+ */
62
+ protected function _doRapidAPI($action, $method = 'POST')
63
+ {
64
+
65
+ $url = $this->_config->getRapidAPIUrl($action);
66
+ $mode = $this->_config->isSandbox() ? '(Sandbox)' : '(Live)';
67
+ $this->_log('>>>>> START REQUEST ' . $mode . ' (' . $method . ') ' . ' : ' . $url);
68
+
69
+ $ch = curl_init($url);
70
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "X-EWAY-APIVERSION: 40"));
71
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_config->getBasicAuthenticationHeader());
72
+ switch($method) {
73
+ case 'POST':
74
+ curl_setopt($ch, CURLOPT_POST, true);
75
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->jsonSerialize());
76
+ $this->_logPostJSON();
77
+ break;
78
+ case 'GET':
79
+ case 'DELETE':
80
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
81
+ break;
82
+ case 'PUT':
83
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
84
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $this->jsonSerialize());
85
+ $this->_logPostJSON();
86
+ break;
87
+ }
88
+
89
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
90
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
91
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->_config->isEnableSSLVerification());
92
+
93
+ $result = curl_exec($ch);
94
+
95
+ $this->_log('<<<<< RESPONSE:');
96
+ $response = Mage::getModel('ewayrapid/response');
97
+ if (curl_errno($ch) != CURLE_OK) {
98
+ $response->isSuccess(false);
99
+ $response->setMessage(Mage::helper('ewayrapid')->__("There is an error in making API request: %s", curl_error($ch)));
100
+ $this->_log("There is an error in making API request: " . curl_error($ch));
101
+ } else {
102
+ $info = curl_getinfo($ch);
103
+ $httpCode = intval(trim($info['http_code']));
104
+ if ($httpCode == 401 || $httpCode == 404 || $httpCode == 403) {
105
+ $response->isSuccess(false);
106
+ $response->setMessage(Mage::helper('ewayrapid')->__("Please check the API Key and Password %s", $mode));
107
+ $this->_log('Access denied. HTTP_CODE = ' . $info['http_code']);
108
+ } elseif ($httpCode != 200) {
109
+ $response->isSuccess(false);
110
+ $response->setMessage(Mage::helper('ewayrapid')->__("Error connecting to payment gateway, please try again"));
111
+ $this->_log('Error connecting to payment gateway. HTTP_CODE = ' . $info['http_code']);
112
+ } else {
113
+ $response->isSuccess(true);
114
+ $response->decodeJSON($result);
115
+ if ($this->_config->isDebug()) {
116
+ $this->_log('SUCCESS. Response body: ');
117
+ $this->_log(print_r(json_decode($result, true), true));
118
+ }
119
+ $this->_log('SUCCESS. HTTP_CODE = ' . $info['http_code']);
120
+ }
121
+ curl_close($ch);
122
+ }
123
+
124
+ $this->_log('===== END REQUEST.');
125
+ return $response;
126
+ }
127
+
128
+ protected function _logPostJSON()
129
+ {
130
+ if ($this->_config->isDebug()) {
131
+ $cardDetails = null;
132
+ if ($this->getCustomer() && $this->getCustomer()->getCardDetails()) {
133
+ $cardDetails = $this->getCustomer()->getCardDetails();
134
+ $cardDetails->shouldBeMasked();
135
+ }
136
+ $this->_log('Request body:');
137
+ $this->_log(print_r($this->getJsonData(), true));
138
+ if ($cardDetails !== null) {
139
+ $cardDetails->shouldBeMasked(false);
140
+ }
141
+ }
142
+ }
143
+
144
+ protected function _log($message, $file = self::DEBUG_FILE)
145
+ {
146
+ if ($this->_config->isDebug()) {
147
+ Mage::log($message, Zend_Log::DEBUG, $file, true);
148
+ }
149
+ }
150
+
151
+ protected function _fixTitle($title)
152
+ {
153
+ if ($title == 'n/a' || empty($title)) {
154
+ return 'Mr.';
155
+ }
156
+ return $title;
157
+ }
158
+
159
+ /**
160
+ * Get predicted increment order id
161
+ * @return string
162
+ */
163
+ protected function _getIncrementOrderId($quote)
164
+ {
165
+ $orderConfig = Mage::getSingleton('eav/config')->getEntityType('order');
166
+
167
+ $entityStoreConfig = Mage::getModel('eav/entity_store')
168
+ ->loadByEntityStore($orderConfig->getId(), $quote->getStoreId());
169
+
170
+ $incrementInstance = Mage::getModel($orderConfig->getIncrementModel())
171
+ ->setPrefix($entityStoreConfig->getIncrementPrefix())
172
+ ->setPadLength($orderConfig->getIncrementPadLength())
173
+ ->setPadChar($orderConfig->getIncrementPadChar())
174
+ ->setLastId($entityStoreConfig->getIncrementLastId())
175
+ ->setEntityTypeId($entityStoreConfig->getEntityTypeId())
176
+ ->setStoreId($entityStoreConfig->getStoreId());
177
+
178
+ $incrementId = $incrementInstance->getNextId();
179
+
180
+ return $incrementId;
181
+ }
182
  }
app/code/community/Eway/Rapid31/Model/Request/Direct.php CHANGED
@@ -1,340 +1,365 @@
1
- <?php
2
- class Eway_Rapid31_Model_Request_Direct extends Eway_Rapid31_Model_Request_Abstract
3
- {
4
- /**
5
- * Call Transaction API (Authorized & Capture at the same time)
6
- *
7
- * @param Mage_Sales_Model_Order_Payment $payment
8
- * @param float $amount
9
- * @return Eway_Rapid31_Model_Request_Direct $this
10
- */
11
- public function doTransaction(Mage_Sales_Model_Order_Payment $payment, $amount)
12
- {
13
- $this->_buildRequest($payment, $amount);
14
- $this->setMethod(Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT);
15
- $response = $this->_doRapidAPI('Transaction');
16
-
17
- // Save fraud information
18
-
19
- $transaction = $this->getTransaction($response['TransactionID']);
20
- if($transaction) {
21
- $fraudAction = $transaction[0]['FraudAction'];
22
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
23
- $captured = $transaction[0]['TransactionCaptured'];
24
- unset($transaction);
25
- }
26
-
27
- if($response->isSuccess()) {
28
- $payment->setTransactionId($response->getTransactionID());
29
- $payment->setCcLast4($response->getCcLast4());
30
- $beagleScore = $response->getBeagleScore() && $response->getData('BeagleScore') > 0 ? $response->getBeagleScore() : '';
31
- $payment->setBeagleScore($beagleScore);
32
- $payment->setBeagleVerification(serialize($response->getBeagleVerification()));
33
- $payment->setFraudAction($fraudAction);
34
- $payment->setFraudCodes($fraudCodes);
35
- $payment->setTransactionCaptured($captured);
36
- return $this;
37
- } else {
38
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. Please try again. (Error message: %s)',
39
- $response->getMessage()));
40
- }
41
- }
42
-
43
- /**
44
- * Call Authorisation API (Authorized only)
45
- *
46
- * @param Mage_Sales_Model_Order_Payment $payment
47
- * @param $amount
48
- * @return Eway_Rapid31_Model_Request_Direct
49
- */
50
- public function doAuthorisation(Mage_Sales_Model_Order_Payment $payment, $amount)
51
- {
52
- $this->_buildRequest($payment, $amount);
53
- $this->setMethod(Eway_Rapid31_Model_Config::METHOD_AUTHORISE);
54
- $response = $this->_doRapidAPI('Authorisation');
55
-
56
- // Save fraud information
57
-
58
- $transaction = $this->getTransaction($response['TransactionID']);
59
- if($transaction) {
60
- $fraudAction = $transaction[0]['FraudAction'];
61
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
62
- $captured = $transaction[0]['TransactionCaptured'];
63
- unset($transaction);
64
- }
65
-
66
- if($response->isSuccess()) {
67
- $payment->setTransactionId($response->getTransactionID());
68
- $payment->setIsTransactionClosed(0);
69
- $beagleScore = $response->getBeagleScore() && $response->getData('BeagleScore') > 0 ? $response->getBeagleScore() : '';
70
- $payment->setBeagleScore($beagleScore);
71
- $payment->setBeagleVerification(serialize($response->getBeagleVerification()));
72
- $payment->setCcLast4($response->getCcLast4());
73
- $payment->setFraudAction($fraudAction);
74
- $payment->setFraudCodes($fraudCodes);
75
- $payment->setTransactionCaptured($captured);
76
- return $this;
77
- } else {
78
- if ($payment->getIsRecurring()) {
79
- Mage::getSingleton('core/session')->setData('errorMessage', $response->getMessage());
80
- }
81
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the authorisation. Please try again. (Error message: %s)',
82
- $response->getMessage()));
83
- }
84
- }
85
-
86
- /**
87
- * Call Capture API (do the Capture only, must Authorized previously)
88
- *
89
- * @param Mage_Sales_Model_Order_Payment $payment
90
- * @param $amount
91
- * @return Eway_Rapid31_Model_Request_Direct
92
- */
93
- public function doCapturePayment(Mage_Sales_Model_Order_Payment $payment, $amount)
94
- {
95
- // Empty Varien_Object's data
96
- $this->unsetData();
97
-
98
- /* @var Mage_Sales_Model_Order_Invoice $invoice */
99
- $invoice = Mage::registry('current_invoice');
100
- $order = $payment->getOrder();
101
-
102
- $paymentParam = Mage::getModel('ewayrapid/field_payment');
103
- $paymentParam->setTotalAmount($amount)
104
- ->setCurrencyCode($order->getBaseCurrencyCode());
105
- if($invoice && $invoice->getIncrementId()) {
106
- $paymentParam->setInvoiceNumber($invoice->getIncrementId())
107
- ->setInvoiceReference($invoice->getIncrementId())
108
- ->setInvoiceDescription(Mage::helper('ewayrapid')->__('Invoice created from Magento'));
109
- }
110
- $this->setPayment($paymentParam);
111
- $this->setTransactionId($payment->getLastTransId());
112
-
113
- $response = $this->_doRapidAPI('CapturePayment');
114
-
115
- if($response->isSuccess()) {
116
- $payment->setTransactionId($response->getTransactionID());
117
- return $this;
118
- } else {
119
- if ($payment->getIsRecurring()) {
120
- Mage::getSingleton('core/session')->setData('errorMessage', $response->getMessage());
121
- }
122
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the capture. Please try again. (Error message: %s)',
123
- $response->getMessage()));
124
- }
125
- }
126
-
127
- /**
128
- * Call Refund API, must complete the transaction (Authorized & Capture) beforehand
129
- *
130
- * @param Mage_Sales_Model_Order_Payment $payment
131
- * @param $amount
132
- * @return Eway_Rapid31_Model_Request_Direct
133
- */
134
- public function doRefund(Mage_Sales_Model_Order_Payment $payment, $amount)
135
- {
136
- // Empty Varien_Object's data
137
- $this->unsetData();
138
-
139
- $order = $payment->getOrder();
140
- /* @var Mage_Sales_Model_Order_Creditmemo $creditMemo */
141
- $creditMemo = Mage::registry('current_creditmemo');
142
-
143
- $invoice = ($creditMemo ? $creditMemo->getInvoice() : null);
144
- /* @var Mage_Sales_Model_Order_Invoice $invoice */
145
- if(!$invoice || !$invoice->getTransactionId()) {
146
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the online refund: Invoice or transaction does not exist.'));
147
- }
148
-
149
- $paymentParam = Mage::getModel('ewayrapid/field_payment');
150
- $paymentParam->setTotalAmount($amount)
151
- ->setCurrencyCode($order->getBaseCurrencyCode())
152
- ->setTransactionID($invoice->getTransactionId());
153
- if($creditMemo && $creditMemo->getIncrementId()) {
154
- $paymentParam->setInvoiceDescription("Creditmemo ID " . $creditMemo->getIncrementId());
155
- }
156
-
157
- if($invoice && $invoice->getIncrementId()) {
158
- $paymentParam->setInvoiceNumber($invoice->getIncrementId())
159
- ->setInvoiceReference($invoice->getIncrementId());
160
- }
161
- $this->setRefund($paymentParam);
162
-
163
- $response = $this->_doRapidAPI('Transaction/' . $invoice->getTransactionId() . '/Refund');
164
-
165
- if($response->isSuccess()) {
166
- $payment->setTransactionId($response->getTransactionID());
167
- return $this;
168
- } else {
169
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the refund. Please try again. (Error message: %s)',
170
- $response->getMessage()));
171
- }
172
- }
173
-
174
- /**
175
- * Call Cancel API, the transaction must be Authorized beforehand
176
- *
177
- * @param Mage_Sales_Model_Order_Payment $payment
178
- * @return Eway_Rapid31_Model_Request_Direct
179
- */
180
- public function doCancel(Mage_Sales_Model_Order_Payment $payment)
181
- {
182
- // Empty Varien_Object's data
183
- $this->unsetData();
184
-
185
- $transactionId = $payment->getLastTransId();
186
- $this->setTransactionId($transactionId);
187
- $response = $this->_doRapidAPI('CancelAuthorisation');
188
-
189
- if($response->isSuccess()) {
190
- $payment->setTransactionId($response->getTransactionID());
191
- $payment->setIsTransactionClosed(1);
192
- return $this;
193
- } else {
194
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the cancel. Please try again. (Error message: %s)',
195
- $response->getMessage()));
196
- }
197
-
198
- }
199
-
200
- /**
201
- * Build the request with necessary parameters for doAuthorisation() and doTransaction()
202
- *
203
- * @param Mage_Sales_Model_Order_Payment $payment
204
- * @param $amount
205
- * @return Eway_Rapid31_Model_Request_Direct
206
- */
207
- protected function _buildRequest(Mage_Sales_Model_Order_Payment $payment, $amount)
208
- {
209
- // Empty Varien_Object's data
210
- $this->unsetData();
211
- $methodInstance = $payment->getMethodInstance();
212
- $infoInstance = $methodInstance->getInfoInstance();
213
- $order = $payment->getOrder();
214
- $billing = $order->getBillingAddress();
215
- $shipping = $order->getShippingAddress();
216
-
217
- // if item is virtual product
218
- if (!$shipping) {
219
- $quote = Mage::getModel('checkout/cart')->getQuote();
220
- if ($quote->isVirtual()) {
221
- $shipping = $quote->getBillingAddress();
222
- }
223
- }
224
-
225
- $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
226
- if(Mage::helper('ewayrapid')->isBackendOrder()) {
227
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
228
- } else {
229
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
230
- }
231
- $version = Mage::helper('ewayrapid')->getExtensionVersion();
232
- $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
233
- $this->setShippingMethod('Other');
234
-
235
- $paymentParam = Mage::getModel('ewayrapid/field_payment');
236
- $paymentParam->setTotalAmount($amount)
237
- ->setCurrencyCode($order->getBaseCurrencyCode());
238
-
239
- // add InvoiceDescription and InvoiceReference
240
- $config = Mage::getModel('ewayrapid/config');
241
-
242
- if($config->shouldPassingInvoiceDescription()){
243
- $invoiceDescription = '';
244
- foreach($order->getAllVisibleItems() as $item){
245
- // Check in case multi-shipping
246
- if (!$item->getQuoteParentItemId()) {
247
- $invoiceDescription .= (int) $item->getQtyOrdered() . ' x ' .$item->getName() . ', ';
248
- }
249
- }
250
- $invoiceDescription = trim($invoiceDescription,', ');
251
- $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
252
-
253
- $paymentParam->setInvoiceDescription($invoiceDescription);
254
- }
255
-
256
- if($config->shouldPassingGuessOrder()){
257
- $paymentParam->setInvoiceReference($order->getIncrementId());
258
- }
259
-
260
- $this->setPayment($paymentParam);
261
-
262
- $title = $this->_fixTitle($billing->getPrefix());
263
-
264
- $customerParam = Mage::getModel('ewayrapid/field_customer');
265
- $customerParam->setTitle($title)
266
- ->setFirstName($billing->getFirstname())
267
- ->setLastName($billing->getLastname())
268
- ->setCompanyName($billing->getCompany())
269
- ->setJobDescription('')
270
- ->setStreet1($billing->getStreet1())
271
- ->setStreet2($billing->getStreet2())
272
- ->setCity($billing->getCity())
273
- ->setState($billing->getRegion())
274
- ->setPostalCode($billing->getPostcode())
275
- ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
276
- ->setEmail($billing->getEmail())
277
- ->setPhone($billing->getTelephone())
278
- ->setMobile('')
279
- ->setComments('')
280
- ->setFax($billing->getFax())
281
- ->setUrl('');
282
- $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
283
- $cardDetails->setName($infoInstance->getCcOwner())
284
- ->setNumber($infoInstance->getCcNumber())
285
- ->setExpiryMonth($infoInstance->getCcExpMonth())
286
- ->setExpiryYear($infoInstance->getCcExpYear())
287
- ->setCVN($infoInstance->getCcCid());
288
-
289
- $customerParam->setCardDetails($cardDetails);
290
- $this->setCustomer($customerParam);
291
-
292
- if (!empty($shipping)) {
293
- $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
294
- $shippingParam->setFirstName($shipping->getFirstname())
295
- ->setLastName($shipping->getLastname())
296
- ->setStreet1($shipping->getStreet1())
297
- ->setStreet2($shipping->getStreet2())
298
- ->setCity($shipping->getCity())
299
- ->setState($shipping->getRegion())
300
- ->setPostalCode($shipping->getPostcode())
301
- ->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))
302
- ->setEmail($shipping->getEmail())
303
- ->setPhone($shipping->getTelephone())
304
- ->setFax($shipping->getFax());
305
- $this->setShippingAddress($shippingParam);
306
- }
307
-
308
- if($methodInstance->getConfigData('transfer_cart_items')) {
309
- $orderItems = $order->getAllVisibleItems();
310
- $lineItems = array();
311
- foreach($orderItems as $orderItem) {
312
- /* @var Mage_Sales_Model_Order_Item $orderItem */
313
- $lineItem = Mage::getModel('ewayrapid/field_lineItem');
314
- $lineItem->setSKU($orderItem->getSku());
315
- $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
316
- $lineItem->setQuantity($orderItem->getQtyOrdered());
317
- $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
318
- $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
319
- $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
320
- $lineItems[] = $lineItem;
321
- }
322
- $this->setItems($lineItems);
323
- }
324
-
325
- return $this;
326
- }
327
-
328
- public function getTransaction($transaction_number) {
329
- try {
330
- $results = $this->_doRapidAPI("Transaction/$transaction_number", 'GET');
331
- if ($results->isSuccess()) {
332
- return $results->getTransactions();
333
- }
334
- } catch (Exception $e) {
335
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
336
- $results->getMessage()));
337
- return false;
338
- }
339
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
  }
1
+ <?php
2
+ class Eway_Rapid31_Model_Request_Direct extends Eway_Rapid31_Model_Request_Abstract
3
+ {
4
+ /**
5
+ * Call Transaction API (Authorized & Capture at the same time)
6
+ *
7
+ * @param Mage_Sales_Model_Order_Payment $payment
8
+ * @param float $amount
9
+ * @return Eway_Rapid31_Model_Request_Direct $this
10
+ */
11
+ public function doTransaction(Mage_Sales_Model_Order_Payment $payment, $amount)
12
+ {
13
+ $this->_buildRequest($payment, $amount);
14
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT);
15
+ $response = $this->_doRapidAPI('Transaction');
16
+
17
+ // Save fraud information
18
+
19
+ $transaction = $this->getTransaction($response['TransactionID']);
20
+ if ($transaction) {
21
+ $fraudAction = $transaction[0]['FraudAction'];
22
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
23
+ $captured = $transaction[0]['TransactionCaptured'];
24
+ unset($transaction);
25
+ }
26
+
27
+ if ($response->isSuccess()) {
28
+ $payment->setTransactionId($response->getTransactionID());
29
+ $payment->setCcLast4($response->getCcLast4());
30
+ $beagleScore = $response->getBeagleScore() && $response->getData('BeagleScore') > 0 ? $response->getBeagleScore() : '';
31
+ $payment->setBeagleScore($beagleScore);
32
+ $payment->setBeagleVerification(serialize($response->getBeagleVerification()));
33
+ $payment->setFraudAction($fraudAction);
34
+ $payment->setFraudCodes($fraudCodes);
35
+ $payment->setTransactionCaptured($captured);
36
+ return $this;
37
+ } else {
38
+ Mage::throwException(
39
+ Mage::helper('ewayrapid')->__(
40
+ 'An error occurred while making the transaction. Please try again. (Error message: %s)',
41
+ $response->getMessage()
42
+ )
43
+ );
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Call Authorisation API (Authorized only)
49
+ *
50
+ * @param Mage_Sales_Model_Order_Payment $payment
51
+ * @param $amount
52
+ * @return Eway_Rapid31_Model_Request_Direct
53
+ */
54
+ public function doAuthorisation(Mage_Sales_Model_Order_Payment $payment, $amount)
55
+ {
56
+ $this->_buildRequest($payment, $amount);
57
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_AUTHORISE);
58
+ $response = $this->_doRapidAPI('Authorisation');
59
+
60
+ // Save fraud information
61
+
62
+ $transaction = $this->getTransaction($response['TransactionID']);
63
+ if ($transaction) {
64
+ $fraudAction = $transaction[0]['FraudAction'];
65
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
66
+ $captured = $transaction[0]['TransactionCaptured'];
67
+ unset($transaction);
68
+ }
69
+
70
+ if ($response->isSuccess()) {
71
+ $payment->setTransactionId($response->getTransactionID());
72
+ $payment->setIsTransactionClosed(0);
73
+ $beagleScore = $response->getBeagleScore() && $response->getData('BeagleScore') > 0 ? $response->getBeagleScore() : '';
74
+ $payment->setBeagleScore($beagleScore);
75
+ $payment->setBeagleVerification(serialize($response->getBeagleVerification()));
76
+ $payment->setCcLast4($response->getCcLast4());
77
+ $payment->setFraudAction($fraudAction);
78
+ $payment->setFraudCodes($fraudCodes);
79
+ $payment->setTransactionCaptured($captured);
80
+ return $this;
81
+ } else {
82
+ if ($payment->getIsRecurring()) {
83
+ Mage::getSingleton('core/session')->setData('errorMessage', $response->getMessage());
84
+ }
85
+ Mage::throwException(
86
+ Mage::helper('ewayrapid')->__(
87
+ 'An error occurred while doing the authorisation. Please try again. (Error message: %s)',
88
+ $response->getMessage()
89
+ )
90
+ );
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Call Capture API (do the Capture only, must Authorized previously)
96
+ *
97
+ * @param Mage_Sales_Model_Order_Payment $payment
98
+ * @param $amount
99
+ * @return Eway_Rapid31_Model_Request_Direct
100
+ */
101
+ public function doCapturePayment(Mage_Sales_Model_Order_Payment $payment, $amount)
102
+ {
103
+ // Empty Varien_Object's data
104
+ $this->unsetData();
105
+
106
+ /* @var Mage_Sales_Model_Order_Invoice $invoice */
107
+ $invoice = Mage::registry('current_invoice');
108
+ $order = $payment->getOrder();
109
+
110
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
111
+ $paymentParam->setTotalAmount($amount)
112
+ ->setCurrencyCode($order->getBaseCurrencyCode());
113
+ if ($invoice && $invoice->getIncrementId()) {
114
+ $paymentParam->setInvoiceNumber($invoice->getIncrementId())
115
+ ->setInvoiceReference($invoice->getIncrementId())
116
+ ->setInvoiceDescription(Mage::helper('ewayrapid')->__('Invoice created from Magento'));
117
+ }
118
+ $this->setPayment($paymentParam);
119
+ $this->setTransactionId($payment->getLastTransId());
120
+
121
+ $response = $this->_doRapidAPI('CapturePayment');
122
+
123
+ if ($response->isSuccess()) {
124
+ $payment->setTransactionId($response->getTransactionID());
125
+ return $this;
126
+ } else {
127
+ if ($payment->getIsRecurring()) {
128
+ Mage::getSingleton('core/session')->setData('errorMessage', $response->getMessage());
129
+ }
130
+ Mage::throwException(
131
+ Mage::helper('ewayrapid')->__(
132
+ 'An error occurred while doing the capture. Please try again. (Error message: %s)',
133
+ $response->getMessage()
134
+ )
135
+ );
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Call Refund API, must complete the transaction (Authorized & Capture) beforehand
141
+ *
142
+ * @param Mage_Sales_Model_Order_Payment $payment
143
+ * @param $amount
144
+ * @return Eway_Rapid31_Model_Request_Direct
145
+ */
146
+ public function doRefund(Mage_Sales_Model_Order_Payment $payment, $amount)
147
+ {
148
+ // Empty Varien_Object's data
149
+ $this->unsetData();
150
+
151
+ $order = $payment->getOrder();
152
+ /* @var Mage_Sales_Model_Order_Creditmemo $creditMemo */
153
+ $creditMemo = Mage::registry('current_creditmemo');
154
+
155
+ $invoice = ($creditMemo ? $creditMemo->getInvoice() : null);
156
+ /* @var Mage_Sales_Model_Order_Invoice $invoice */
157
+ if (!$invoice || !$invoice->getTransactionId()) {
158
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the online refund: Invoice or transaction does not exist.'));
159
+ }
160
+
161
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
162
+ $paymentParam->setTotalAmount($amount)
163
+ ->setCurrencyCode($order->getBaseCurrencyCode())
164
+ ->setTransactionID($invoice->getTransactionId());
165
+ if ($creditMemo && $creditMemo->getIncrementId()) {
166
+ $paymentParam->setInvoiceDescription("Creditmemo ID " . $creditMemo->getIncrementId());
167
+ }
168
+
169
+ if ($invoice && $invoice->getIncrementId()) {
170
+ $paymentParam->setInvoiceNumber($invoice->getIncrementId())
171
+ ->setInvoiceReference($invoice->getIncrementId());
172
+ }
173
+ $this->setRefund($paymentParam);
174
+
175
+ $response = $this->_doRapidAPI('Transaction/' . $invoice->getTransactionId() . '/Refund');
176
+
177
+ if ($response->isSuccess()) {
178
+ $payment->setTransactionId($response->getTransactionID());
179
+ return $this;
180
+ } else {
181
+ Mage::throwException(
182
+ Mage::helper('ewayrapid')->__(
183
+ 'An error occurred while doing the refund. Please try again. (Error message: %s)',
184
+ $response->getMessage()
185
+ )
186
+ );
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Call Cancel API, the transaction must be Authorized beforehand
192
+ *
193
+ * @param Mage_Sales_Model_Order_Payment $payment
194
+ * @return Eway_Rapid31_Model_Request_Direct
195
+ */
196
+ public function doCancel(Mage_Sales_Model_Order_Payment $payment)
197
+ {
198
+ // Empty Varien_Object's data
199
+ $this->unsetData();
200
+
201
+ $transactionId = $payment->getLastTransId();
202
+ $this->setTransactionId($transactionId);
203
+ $response = $this->_doRapidAPI('CancelAuthorisation');
204
+
205
+ if ($response->isSuccess()) {
206
+ $payment->setTransactionId($response->getTransactionID());
207
+ $payment->setIsTransactionClosed(1);
208
+ return $this;
209
+ } else {
210
+ Mage::throwException(
211
+ Mage::helper('ewayrapid')->__(
212
+ 'An error occurred while doing the cancel. Please try again. (Error message: %s)',
213
+ $response->getMessage()
214
+ )
215
+ );
216
+ }
217
+
218
+ }
219
+
220
+ /**
221
+ * Build the request with necessary parameters for doAuthorisation() and doTransaction()
222
+ *
223
+ * @param Mage_Sales_Model_Order_Payment $payment
224
+ * @param $amount
225
+ * @return Eway_Rapid31_Model_Request_Direct
226
+ */
227
+ protected function _buildRequest(Mage_Sales_Model_Order_Payment $payment, $amount)
228
+ {
229
+ // Empty Varien_Object's data
230
+ $this->unsetData();
231
+ $methodInstance = $payment->getMethodInstance();
232
+ $infoInstance = $methodInstance->getInfoInstance();
233
+ $order = $payment->getOrder();
234
+ $billing = $order->getBillingAddress();
235
+ $shipping = $order->getShippingAddress();
236
+
237
+ // if item is virtual product
238
+ if (!$shipping) {
239
+ $quote = Mage::getModel('checkout/cart')->getQuote();
240
+ if ($quote->isVirtual()) {
241
+ $shipping = $quote->getBillingAddress();
242
+ }
243
+ }
244
+
245
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
246
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
247
+ } else {
248
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
249
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
250
+ }
251
+ $version = Mage::helper('ewayrapid')->getExtensionVersion();
252
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
253
+ $this->setShippingMethod('Other');
254
+
255
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
256
+ $paymentParam->setTotalAmount($amount)
257
+ ->setCurrencyCode($order->getBaseCurrencyCode());
258
+
259
+ // add InvoiceDescription and InvoiceReference
260
+ $config = Mage::getModel('ewayrapid/config');
261
+
262
+ if ($config->shouldPassingInvoiceDescription()) {
263
+ $invoiceDescription = '';
264
+ foreach ($order->getAllVisibleItems() as $item) {
265
+ // Check in case multi-shipping
266
+ if (!$item->getQuoteParentItemId()) {
267
+ $invoiceDescription .= (int) $item->getQtyOrdered() . ' x ' .$item->getName() . ', ';
268
+ }
269
+ }
270
+ $invoiceDescription = trim($invoiceDescription, ', ');
271
+ $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
272
+
273
+ $paymentParam->setInvoiceDescription($invoiceDescription);
274
+ }
275
+
276
+ if ($config->shouldPassingGuessOrder()) {
277
+ $paymentParam->setInvoiceReference($order->getIncrementId());
278
+ }
279
+
280
+ $this->setPayment($paymentParam);
281
+
282
+ $title = $this->_fixTitle($billing->getPrefix());
283
+
284
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
285
+ $customerParam->setTitle($title)
286
+ ->setFirstName($billing->getFirstname())
287
+ ->setLastName($billing->getLastname())
288
+ ->setCompanyName($billing->getCompany())
289
+ ->setJobDescription('')
290
+ ->setStreet1($billing->getStreet1())
291
+ ->setStreet2($billing->getStreet2())
292
+ ->setCity($billing->getCity())
293
+ ->setState($billing->getRegion())
294
+ ->setPostalCode($billing->getPostcode())
295
+ ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
296
+ ->setEmail($billing->getEmail())
297
+ ->setPhone($billing->getTelephone())
298
+ ->setMobile('')
299
+ ->setComments('')
300
+ ->setFax($billing->getFax())
301
+ ->setUrl('');
302
+ $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
303
+ $cardDetails->setName($infoInstance->getCcOwner())
304
+ ->setNumber($infoInstance->getCcNumber())
305
+ ->setExpiryMonth($infoInstance->getCcExpMonth())
306
+ ->setExpiryYear($infoInstance->getCcExpYear())
307
+ ->setCVN($infoInstance->getCcCid());
308
+
309
+ $customerParam->setCardDetails($cardDetails);
310
+ $this->setCustomer($customerParam);
311
+
312
+ if (!empty($shipping)) {
313
+ $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
314
+ $shippingParam->setFirstName($shipping->getFirstname())
315
+ ->setLastName($shipping->getLastname())
316
+ ->setStreet1($shipping->getStreet1())
317
+ ->setStreet2($shipping->getStreet2())
318
+ ->setCity($shipping->getCity())
319
+ ->setState($shipping->getRegion())
320
+ ->setPostalCode($shipping->getPostcode())
321
+ ->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))
322
+ ->setEmail($shipping->getEmail())
323
+ ->setPhone($shipping->getTelephone())
324
+ ->setFax($shipping->getFax());
325
+ $this->setShippingAddress($shippingParam);
326
+ }
327
+
328
+ if ($methodInstance->getConfigData('transfer_cart_items')) {
329
+ $orderItems = $order->getAllVisibleItems();
330
+ $lineItems = array();
331
+ foreach ($orderItems as $orderItem) {
332
+ /* @var Mage_Sales_Model_Order_Item $orderItem */
333
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
334
+ $lineItem->setSKU($orderItem->getSku());
335
+ $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
336
+ $lineItem->setQuantity($orderItem->getQtyOrdered());
337
+ $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
338
+ $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
339
+ $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
340
+ $lineItems[] = $lineItem;
341
+ }
342
+ $this->setItems($lineItems);
343
+ }
344
+
345
+ return $this;
346
+ }
347
+
348
+ public function getTransaction($transactionNumber)
349
+ {
350
+ try {
351
+ $results = $this->_doRapidAPI("Transaction/$transactionNumber", 'GET');
352
+ if ($results->isSuccess()) {
353
+ return $results->getTransactions();
354
+ }
355
+ } catch (Exception $e) {
356
+ Mage::throwException(
357
+ Mage::helper('ewayrapid')->__(
358
+ 'An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
359
+ $results->getMessage()
360
+ )
361
+ );
362
+ return false;
363
+ }
364
+ }
365
  }
app/code/community/Eway/Rapid31/Model/Request/Sharedpage.php CHANGED
@@ -1,639 +1,648 @@
1
- <?php
2
-
3
- class Eway_Rapid31_Model_Request_Sharedpage extends Eway_Rapid31_Model_Request_Abstract
4
- {
5
- /**
6
- * @var Mage_Sales_Model_Quote
7
- */
8
- protected $_quote = null;
9
-
10
- /**
11
- * @var Mage_Customer_Model_Session
12
- */
13
- protected $_customerSession;
14
-
15
- public function __construct($params = array())
16
- {
17
- if (isset($params['quote']) && $params['quote'] instanceof Mage_Sales_Model_Quote) {
18
- $this->_quote = $params['quote'];
19
- } else {
20
- throw new Exception('Quote instance is required.');
21
- }
22
-
23
- $this->_config = Mage::getSingleton('ewayrapid/config');
24
- $this->_customerSession = Mage::getSingleton('customer/session');
25
- }
26
-
27
- /**
28
- * create AccessCode for process checkout
29
- *
30
- * @param null $returnUrl
31
- * @param null $cancelUrl
32
- * @return Eway_Rapid31_Model_Response
33
- */
34
- public function createAccessCode($returnUrl = null, $cancelUrl = null)
35
- {
36
- // Empty Varien_Object's data
37
- $this->unsetData();
38
- $token = null;
39
- $paypal = null;
40
- $totalAmount = 0;
41
-
42
- if ($this->getMethod() == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD) {
43
- if ($this->_isNewToken()) {
44
- $returnUrl .= '?newToken=1';
45
- $method = Eway_Rapid31_Model_Config::METHOD_CREATE_TOKEN;
46
- } elseif ($token = $this->_editToken()) {
47
- $returnUrl .= '?editToken=' . $token;
48
- $token = Mage::helper('ewayrapid/customer')->getCustomerTokenId($token);
49
- $method = Eway_Rapid31_Model_Config::METHOD_UPDATE_TOKEN;
50
- }
51
- } elseif ($this->getMethod() == Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD) {
52
- if ($this->_isNewToken()) {
53
- $returnUrl .= '?newToken=1';
54
- if(Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE){
55
- $method = Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT;
56
- $totalAmount = round($this->_quote->getBaseGrandTotal() * 100);
57
- }else{
58
- $method = Eway_Rapid31_Model_Config::METHOD_CREATE_TOKEN ;
59
- }
60
- } elseif ($token = $this->_editToken()) {
61
- $returnUrl .= '?editToken=' . $token;
62
- $token = Mage::helper('ewayrapid/customer')->getCustomerTokenId($token);
63
- if(Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE){
64
- $method = Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT;
65
- $totalAmount = round($this->_quote->getBaseGrandTotal() * 100);
66
- }else{
67
- $method = Eway_Rapid31_Model_Config::METHOD_UPDATE_TOKEN ;
68
- }
69
- }else{
70
- if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
71
- $method = Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT;
72
- } else {
73
- $method = Eway_Rapid31_Model_Config::METHOD_AUTHORISE;
74
- }
75
- $totalAmount = round($this->_quote->getBaseGrandTotal() * 100);
76
- $paypal = $this->_getPaypalCheckout();
77
- if ($paypal === Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD) {
78
- $this->setCheckoutPayment(true);
79
- $this->setCheckoutURL(Mage::getUrl('ewayrapid/sharedpage/review'));
80
- }
81
- }
82
- } else {
83
- if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
84
- $method = Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT;
85
- } else {
86
- $method = Eway_Rapid31_Model_Config::METHOD_AUTHORISE;
87
- }
88
- $totalAmount = round($this->_quote->getBaseGrandTotal() * 100);
89
- $paypal = $this->_getPaypalCheckout();
90
- if ($paypal === Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD) {
91
- $this->setCheckoutPayment(true);
92
- $this->setCheckoutURL(Mage::getUrl('ewayrapid/sharedpage/review'));
93
- }
94
- }
95
-
96
- $this->_buildRequest();
97
-
98
- $customer = $this->getCustomer();
99
- $customer->setTokenCustomerID($token ? $token : '');
100
- $this->setCustomer($customer);
101
-
102
- // prepare API
103
- $this->setRedirectUrl($returnUrl);
104
- $this->setCancelUrl($cancelUrl);
105
- $this->setMethod($method);
106
-
107
- if (Mage::helper('ewayrapid')->getTransferCartLineItems()) {
108
- // add Shipping item and Line items
109
- $lineItems = Mage::helper('ewayrapid')->getLineItems();
110
- $this->setItems($lineItems);
111
- }
112
-
113
- // add Payment
114
- $paymentParam = Mage::getModel('ewayrapid/field_payment');
115
- $paymentParam->setTotalAmount($totalAmount);
116
- $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
117
-
118
- // add InvoiceDescription and InvoiceReference
119
- $config = Mage::getModel('ewayrapid/config');
120
-
121
- if($config->shouldPassingInvoiceDescription()){
122
- $invoiceDescription = '';
123
- foreach($this->_quote->getAllVisibleItems() as $item){
124
- // Check in case multi-shipping
125
- if (!$item->getQuoteParentItem()) {
126
- $invoiceDescription .= (int) $item->getQty() . ' x ' .$item->getName() . ', ';
127
- }
128
- }
129
- $invoiceDescription = trim($invoiceDescription,', ');
130
- $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
131
-
132
- $paymentParam->setInvoiceDescription($invoiceDescription);
133
- }
134
-
135
- if($config->shouldPassingGuessOrder()){
136
- $incrementId = $this->_getIncrementOrderId($this->_quote);
137
- $paymentParam->setInvoiceReference($incrementId);
138
- $paymentParam->setInvoiceNumber($incrementId);
139
- }
140
-
141
- $this->setPayment($paymentParam);
142
-
143
- if($this->_config->isSharedPageConnection()){
144
- // add Verify options
145
- $this->setVerifyCustomerEmail($this->_config->getVerifyEmail());
146
- $this->setVerifyCustomerPhone($this->_config->getVerifyPhone());
147
-
148
- // add Custom View
149
- $this->setCustomView($this->_config->getCustomView());
150
-
151
- }
152
-
153
- $response = $this->_doRapidAPI('AccessCodesShared');
154
- return $response;
155
- }
156
-
157
- /**
158
- * Call Authorisation API (Authorized only)
159
- *
160
- * @param Eway_Rapid31_Model_Response $response
161
- * @return Eway_Rapid31_Model_Response
162
- */
163
- public function doAuthorisation(Eway_Rapid31_Model_Response $response)
164
- {
165
- $this->unsetData();
166
-
167
- $this->_buildRequest();
168
-
169
- $cardData = $response->getCustomer();
170
- if ($cardData['CardNumber'] && $cardData['CardName']) {
171
- $this->setMethod(Eway_Rapid31_Model_Config::METHOD_AUTHORISE);
172
- } else {
173
- $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
174
- }
175
-
176
- $items = $this->_quote->getAllVisibleItems();
177
- $lineItems = array();
178
- foreach ($items as $item) {
179
- /* @var Mage_Sales_Model_Order_Item $item */
180
- $lineItem = Mage::getModel('ewayrapid/field_lineItem');
181
- $lineItem->setSKU($item->getSku());
182
- $lineItem->setDescription(substr($item->getName(), 0, 26));
183
- $lineItem->setQuantity($item->getQty());
184
- $lineItem->setUnitCost(round($item->getBasePrice() * 100));
185
- $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
186
- $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
187
- $lineItems[] = $lineItem;
188
- }
189
- $this->setItems($lineItems);
190
-
191
- $this->setItems(false);
192
-
193
- // add Payment
194
- $amount = round($this->_quote->getBaseGrandTotal() * 100);
195
- $paymentParam = Mage::getModel('ewayrapid/field_payment');
196
- $paymentParam->setTotalAmount($amount);
197
- $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
198
-
199
- // add InvoiceDescription and InvoiceReference
200
- $config = Mage::getModel('ewayrapid/config');
201
-
202
- if($config->shouldPassingInvoiceDescription()){
203
- $invoiceDescription = '';
204
- foreach($this->_quote->getAllVisibleItems() as $item){
205
- // Check in case multi-shipping
206
- if (!$item->getQuoteParentItemId()) {
207
- $invoiceDescription .= (int) $item->getQty() . ' x ' .$item->getName() . ', ';
208
- }
209
- }
210
- $invoiceDescription = trim($invoiceDescription,', ');
211
- $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
212
-
213
- $paymentParam->setInvoiceDescription($invoiceDescription);
214
- }
215
-
216
- if($config->shouldPassingGuessOrder()){
217
- $incrementId = $this->_getIncrementOrderId($this->_quote);
218
- $paymentParam->setInvoiceReference($incrementId);
219
- }
220
-
221
- $this->setPayment($paymentParam);
222
-
223
- $customerParam = $this->getCustomer();
224
- $customerParam->setTokenCustomerID($response->getTokenCustomerID());
225
- $this->setCustomer($customerParam);
226
-
227
- $response = $this->_doRapidAPI('Authorisation');
228
- return $response;
229
- }
230
-
231
- /**
232
- * Call Transaction API (Authorized & Capture at the same time)
233
- *
234
- * @param Eway_Rapid31_Model_Response $response
235
- * @return Eway_Rapid31_Model_Response
236
- */
237
- public function doTransaction(Eway_Rapid31_Model_Response $response)
238
- {
239
- $this->unsetData();
240
-
241
- $this->_buildRequest();
242
-
243
- $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
244
-
245
- $items = $this->_quote->getAllVisibleItems();
246
- $lineItems = array();
247
- foreach ($items as $item) {
248
- /* @var Mage_Sales_Model_Order_Item $item */
249
- $lineItem = Mage::getModel('ewayrapid/field_lineItem');
250
- $lineItem->setSKU($item->getSku());
251
- $lineItem->setDescription(substr($item->getName(), 0, 26));
252
- $lineItem->setQuantity($item->getQty());
253
- $lineItem->setUnitCost(round($item->getBasePrice() * 100));
254
- $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
255
- $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
256
- $lineItems[] = $lineItem;
257
- }
258
- $this->setItems($lineItems);
259
-
260
- $this->setItems(false);
261
-
262
- // add Payment
263
- $amount = round($this->_quote->getBaseGrandTotal() * 100);
264
- $paymentParam = Mage::getModel('ewayrapid/field_payment');
265
- $paymentParam->setTotalAmount($amount);
266
- $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
267
- $this->setPayment($paymentParam);
268
-
269
- $customerParam = $this->getCustomer();
270
- $customerParam->setTokenCustomerID($response->getTokenCustomerID());
271
-
272
- $this->setCustomer($customerParam);
273
-
274
- $response = $this->_doRapidAPI('Transaction');
275
- return $response;
276
- }
277
-
278
- /**
279
- * Call Capture API (do the Capture only, must Authorized previously)
280
- *
281
- * @param Eway_Rapid31_Model_Response $response
282
- * @return Eway_Rapid31_Model_Response
283
- */
284
- public function doCapturePayment(Eway_Rapid31_Model_Response $response)
285
- {
286
- $this->setTransactionId($response->getTransactionID());
287
- $this->setMethod(Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT);
288
-
289
- $response = $this->_doRapidAPI('CapturePayment');
290
- return $response;
291
- }
292
-
293
- /**
294
- * Build the request with necessary parameters for doAuthorisation(), doTransaction() and CreateAccessCode()
295
- *
296
- * @return $this
297
- */
298
- protected function _buildRequest()
299
- {
300
- // prepare API
301
- $this->setShippingMethod('Other');
302
- $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
303
- $version = Mage::helper('ewayrapid')->getExtensionVersion();
304
- $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
305
- if (Mage::helper('ewayrapid')->isBackendOrder()) {
306
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
307
- } else {
308
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
309
- }
310
- $this->setCustomerReadOnly(true);
311
-
312
- // add Billing Address
313
- $billingAddress = $this->_quote->getBillingAddress();
314
- $customerParam = Mage::getModel('ewayrapid/field_customer');
315
-
316
- $title = $this->_fixTitle($billingAddress->getPrefix());
317
-
318
- $customerParam->setTitle($title)
319
- ->setFirstName($billingAddress->getFirstname())
320
- ->setLastName($billingAddress->getLastname())
321
- ->setCompanyName($billingAddress->getCompany())
322
- ->setJobDescription($billingAddress->getJobDescription())
323
- ->setStreet1($billingAddress->getStreet1())
324
- ->setStreet2($billingAddress->getStreet2())
325
- ->setCity($billingAddress->getCity())
326
- ->setState($billingAddress->getRegion())
327
- ->setPostalCode($billingAddress->getPostcode())
328
- ->setCountry(strtolower($billingAddress->getCountryModel()->getIso2Code()))
329
- ->setEmail($billingAddress->getEmail())
330
- ->setPhone($billingAddress->getTelephone())
331
- ->setMobile($billingAddress->getMobile())
332
- ->setComments('')
333
- ->setFax($billingAddress->getFax())
334
- ->setUrl('');
335
- $this->setCustomer($customerParam);
336
-
337
- // add Shipping Address
338
- $shippingAddress = $this->_quote->getShippingAddress();
339
-
340
- // copy BillingAddress to ShippingAddress if checkout with guest or register
341
- /**
342
- $checkoutMethod = $this->_quote->getCheckoutMethod();
343
- if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST
344
- || $checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER
345
- ) {
346
- $shippingAddress = $billingAddress;
347
- }
348
- */
349
-
350
- if (!empty($shippingAddress)) {
351
- $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
352
- $shippingParam->setFirstName($shippingAddress->getFirstname())
353
- ->setLastName($shippingAddress->getLastname())
354
- ->setStreet1($shippingAddress->getStreet1())
355
- ->setStreet2($shippingAddress->getStreet2())
356
- ->setCity($shippingAddress->getCity())
357
- ->setState($shippingAddress->getRegion())
358
- ->setPostalCode($shippingAddress->getPostcode())
359
- ->setCountry(strtolower($shippingAddress->getCountryModel()->getIso2Code()))
360
- ->setEmail($shippingAddress->getEmail())
361
- ->setPhone($shippingAddress->getTelephone())
362
- ->setFax($shippingAddress->getFax());
363
- $this->setShippingAddress($shippingParam);
364
- }
365
-
366
- return $this;
367
- }
368
-
369
- /**
370
- * Get customer information by access code
371
- */
372
- public function getInfoByAccessCode($accessCode)
373
- {
374
- $response = $this->_doRapidAPI('AccessCode/' . $accessCode, false);
375
- return $response;
376
- }
377
-
378
- /**
379
- * Get customer session object
380
- *
381
- * @return Mage_Customer_Model_Session
382
- */
383
- public function getCustomerSession()
384
- {
385
- return $this->_customerSession;
386
- }
387
-
388
- /**
389
- * check is new token when checkout
390
- *
391
- * @return bool
392
- */
393
- protected function _isNewToken()
394
- {
395
- $info = $this->_quote->getPayment();
396
- Mage::helper('ewayrapid')->unserializeInfoInstace($info);
397
- if ($token = Mage::getSingleton('core/session')->getData('newToken')) {
398
- Mage::getSingleton('core/session')->unsetData('newToken');
399
- return true;
400
- }
401
- return false;
402
- }
403
-
404
- /**
405
- * get TokenCustomerID is selected of customer
406
- *
407
- * @return mixed
408
- */
409
- protected function _editToken()
410
- {
411
- if ($token = Mage::getSingleton('core/session')->getData('editToken')) {
412
- Mage::getSingleton('core/session')->unsetData('editToken');
413
- return $token;
414
- }
415
- return $token;
416
- }
417
-
418
- /**
419
- * check paypal option in eway not saved
420
- *
421
- * @return mixed|null
422
- */
423
- protected function _getPaypalCheckout()
424
- {
425
- if ($paypal = Mage::getSingleton('core/session')->getData('sharedpagePaypal')) {
426
- Mage::getModel('core/session')->unsetData('sharedpagePaypal');
427
- return $paypal;
428
- }
429
- return null;
430
- }
431
-
432
- /**
433
- * update customer when edit shipping address to paypal
434
- *
435
- * @param $accessCode
436
- */
437
- public function updateCustomer($accessCode)
438
- {
439
- $response = $this->_doRapidAPI('Transaction/' . $accessCode, 'GET');
440
- if ($response->isSuccess()) {
441
- $customer = $this->_quote->getCustomer();
442
- $billingAddress = $this->_quote->getBillingAddress();
443
- $shippingAddress = $this->_quote->getShippingAddress();
444
- $trans = $response->getTransactions();
445
-
446
- if (isset($trans[0]['Customer'])) {
447
- $billing = $trans[0]['Customer'];
448
- $billingAddress->setFirstname($billing['FirstName'])
449
- ->setLastName($billing['LastName'])
450
- ->setCompany($billing['CompanyName'])
451
- ->setJobDescription($billing['JobDescription'])
452
- ->setStreet($billing['Street1'])
453
- ->setStreet2($billing['Street2'])
454
- ->setCity($billing['City'])
455
- ->setState($billing['State'])
456
- ->setPostcode($billing['PostalCode'])
457
- ->setCountryId(strtoupper($billing['Country']))
458
- ->setEmail($billing['Email'])
459
- ->setTelephone($billing['Phone'])
460
- ->setMobile($billing['Mobile'])
461
- ->setComments($billing['Comments'])
462
- ->setFax($billing['Fax'])
463
- ->setUrl($billing['Url']);
464
- }
465
- if (isset($trans[0]['ShippingAddress'])) {
466
- $shipping = $trans[0]['ShippingAddress'];
467
- $shippingAddress->setFirstname($shipping['FirstName'])
468
- ->setLastname($shipping['LastName'])
469
- ->setStreet($shipping['Street1'])
470
- ->setStreet2($shipping['Street2'])
471
- ->setCity($shipping['City'])
472
- ->setPostcode($shipping['PostalCode'])
473
- ->setCountryId(strtoupper($shipping['Country']))
474
- ->setEmail($shipping['Email'])
475
- ->setFax($shipping['Fax']);
476
-
477
- if ($shipping['State']
478
- && $shipping['Country']
479
- && $region = Mage::getModel('directory/region')->loadByCode($shipping['State'], $shipping['Country'])
480
- ) {
481
- $shippingAddress->setRegion($region->getName())
482
- ->setRegionId($region->getId());
483
- }
484
- if ($shipping['Phone']) {
485
- $shippingAddress->setTelephone($shipping['Phone']);
486
- }
487
- }
488
- $this->_quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress)->save();
489
- }
490
- }
491
-
492
- /**
493
- * save token when checkout with eway saved
494
- *
495
- * @param Eway_Rapid31_Model_Response $response
496
- * @param null $ccNumber
497
- */
498
- public function saveTokenById(Eway_Rapid31_Model_Response $response, $ccNumber = null)
499
- {
500
- $this->unsetData();
501
-
502
- $customerParam = Mage::getModel('ewayrapid/field_customer');
503
- $customerParam->setTokenCustomerID($response->getTokenCustomerID());
504
- $this->setCustomer($customerParam);
505
- $payment = Mage::getModel('ewayrapid/field_payment');
506
- $payment->setTotalAmount(1);
507
- $this->setPayment($payment);
508
- $this->setRedirectUrl(Mage::getBaseUrl() . '/ewayrapid/sharedpage/saveToken');
509
- $this->setMethod('');
510
-
511
- $response = $this->_doRapidAPI('AccessCodesShared');
512
- $token = true;
513
- if ($response->isSuccess()) {
514
- if (!$ccNumber) {
515
- $token = $this->_createNewToken($response);
516
- } else {
517
- $token = $this->_updateToken($response, $ccNumber);
518
- }
519
-
520
- } else {
521
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while creating new token. Please try again. (Error message: %s)',
522
- $response->getMessage()));
523
- }
524
- if (!$token) {
525
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while process token. Please try again.'));
526
- }
527
- return $response;
528
- }
529
-
530
- /**
531
- * Create new token when checkout
532
- *
533
- * @param Eway_Rapid31_Model_Response $response
534
- * @return $this
535
- */
536
- protected function _createNewToken(Eway_Rapid31_Model_Response $response)
537
- {
538
- try {
539
- $customer = $response->getCustomer();
540
-
541
- $tokenInfo = array(
542
- 'Token' => $response->getTokenCustomerID(),
543
- 'Card' => $customer['CardNumber'] ? substr_replace($customer['CardNumber'], '******', 6, 6) : 'Paypal',
544
- 'Owner' => $customer['CardName'],
545
- 'StartMonth' => $customer['CardStartMonth'],
546
- 'StartYear' => $customer['CardStartYear'],
547
- 'IssueNumber' => $customer['CardIssueNumber'],
548
- 'ExpMonth' => $customer['CardExpiryMonth'],
549
- 'ExpYear' => (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear']),
550
- 'Type' => $this->checkCardType($customer['CardNumber']),
551
- 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customer),
552
- );
553
-
554
- Mage::helper('ewayrapid/customer')->addToken($tokenInfo);
555
- return true;
556
- } catch (Exception $e) {
557
- return false;
558
- }
559
- }
560
-
561
- /**
562
- * Update token when checkout with existing token
563
- *
564
- * @param Eway_Rapid31_Model_Response $response
565
- * @param null $ccNumber
566
- * @return $this
567
- */
568
- protected function _updateToken(Eway_Rapid31_Model_Response $response, $ccNumber = null)
569
- {
570
- try {
571
- $customer = $response->getCustomer();
572
-
573
- $tokenInfo = array(
574
- 'Token' => $response->getTokenCustomerID(),
575
- 'Card' => $customer['CardNumber'] ? substr_replace($customer['CardNumber'], '******', 6, 6) : 'Paypal',
576
- 'Owner' => $customer['CardName'],
577
- 'StartMonth' => $customer['CardStartMonth'],
578
- 'StartYear' => $customer['CardStartYear'],
579
- 'IssueNumber' => $customer['CardIssueNumber'],
580
- 'ExpMonth' => $customer['CardExpiryMonth'],
581
- 'ExpYear' => (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear']),
582
- 'Type' => $this->checkCardType($customer['CardNumber']),
583
- 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customer),
584
- );
585
-
586
- Mage::helper('ewayrapid/customer')->updateToken($ccNumber, $tokenInfo);
587
- return true;
588
- } catch (Exception $e) {
589
- return false;
590
- }
591
- }
592
-
593
- /**
594
- * Get card type name by card number
595
- * @param $num Card number
596
- * @return string Card type name
597
- */
598
- public function checkCardType($num)
599
- {
600
- if ($num == null) {
601
- return Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD;
602
- }
603
- return Mage::getModel('ewayrapid/request_token')->checkCardType($num);
604
- }
605
-
606
- public function getShippingByCode($postalCode)
607
- {
608
- $groups = $this->_quote->getShippingAddress()
609
- ->collectShippingRates()
610
- ->getGroupedAllShippingRates();
611
- // determine current selected code & name
612
- foreach ($groups as $code => $rates) {
613
- foreach ($rates as $rate) {
614
- if (strtoupper($postalCode) == strtoupper($rate->getCode())) {
615
- return $rate;
616
- }
617
- }
618
- }
619
- return false;
620
- }
621
-
622
- public function getMethod()
623
- {
624
- return Mage::getSingleton('core/session')->getData('ewayMethod');
625
- }
626
-
627
- public function getTransaction($transaction_number) {
628
- try {
629
- $results = $this->_doRapidAPI("Transaction/$transaction_number", 'GET');
630
- if ($results->isSuccess()) {
631
- return $results->getTransactions();
632
- }
633
- } catch (Exception $e) {
634
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
635
- $results->getMessage()));
636
- return false;
637
- }
638
- }
 
 
 
 
 
 
 
 
 
639
  }
1
+ <?php
2
+
3
+ class Eway_Rapid31_Model_Request_Sharedpage extends Eway_Rapid31_Model_Request_Abstract
4
+ {
5
+ /**
6
+ * @var Mage_Sales_Model_Quote
7
+ */
8
+ protected $_quote = null;
9
+
10
+ /**
11
+ * @var Mage_Customer_Model_Session
12
+ */
13
+ protected $_customerSession;
14
+
15
+ public function __construct($params = array())
16
+ {
17
+ if (isset($params['quote']) && $params['quote'] instanceof Mage_Sales_Model_Quote) {
18
+ $this->_quote = $params['quote'];
19
+ } else {
20
+ Mage::throwException('Quote instance is required.');
21
+ }
22
+
23
+ $this->_config = Mage::getSingleton('ewayrapid/config');
24
+ $this->_customerSession = Mage::getSingleton('customer/session');
25
+ }
26
+
27
+ /**
28
+ * create AccessCode for process checkout
29
+ *
30
+ * @param null $returnUrl
31
+ * @param null $cancelUrl
32
+ * @return Eway_Rapid31_Model_Response
33
+ */
34
+ public function createAccessCode($returnUrl = null, $cancelUrl = null)
35
+ {
36
+ // Empty Varien_Object's data
37
+ $this->unsetData();
38
+ $token = null;
39
+ $paypal = null;
40
+ $totalAmount = 0;
41
+
42
+ if ($this->getMethod() == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD) {
43
+ if ($this->_isNewToken()) {
44
+ $returnUrl .= '?newToken=1';
45
+ $method = Eway_Rapid31_Model_Config::METHOD_CREATE_TOKEN;
46
+ } elseif ($token = $this->_editToken()) {
47
+ $returnUrl .= '?editToken=' . $token;
48
+ $token = Mage::helper('ewayrapid/customer')->getCustomerTokenId($token);
49
+ $method = Eway_Rapid31_Model_Config::METHOD_UPDATE_TOKEN;
50
+ }
51
+ } elseif ($this->getMethod() == Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD) {
52
+ if ($this->_isNewToken()) {
53
+ $returnUrl .= '?newToken=1';
54
+ if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
55
+ $method = Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT;
56
+ $totalAmount = round($this->_quote->getBaseGrandTotal() * 100);
57
+ } else {
58
+ $method = Eway_Rapid31_Model_Config::METHOD_CREATE_TOKEN ;
59
+ }
60
+ } elseif ($token = $this->_editToken()) {
61
+ $returnUrl .= '?editToken=' . $token;
62
+ $token = Mage::helper('ewayrapid/customer')->getCustomerTokenId($token);
63
+ if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
64
+ $method = Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT;
65
+ $totalAmount = round($this->_quote->getBaseGrandTotal() * 100);
66
+ } else {
67
+ $method = Eway_Rapid31_Model_Config::METHOD_UPDATE_TOKEN ;
68
+ }
69
+ } else {
70
+ if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
71
+ $method = Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT;
72
+ } else {
73
+ $method = Eway_Rapid31_Model_Config::METHOD_AUTHORISE;
74
+ }
75
+ $totalAmount = round($this->_quote->getBaseGrandTotal() * 100);
76
+ $paypal = $this->_getPaypalCheckout();
77
+ if ($paypal === Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD) {
78
+ $this->setCheckoutPayment(true);
79
+ $this->setCheckoutURL(Mage::getUrl('ewayrapid/sharedpage/review'));
80
+ }
81
+ }
82
+ } else {
83
+ if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
84
+ $method = Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT;
85
+ } else {
86
+ $method = Eway_Rapid31_Model_Config::METHOD_AUTHORISE;
87
+ }
88
+ $totalAmount = round($this->_quote->getBaseGrandTotal() * 100);
89
+ $paypal = $this->_getPaypalCheckout();
90
+ if ($paypal === Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD) {
91
+ $this->setCheckoutPayment(true);
92
+ $this->setCheckoutURL(Mage::getUrl('ewayrapid/sharedpage/review'));
93
+ }
94
+ }
95
+
96
+ $this->_buildRequest();
97
+
98
+ $customer = $this->getCustomer();
99
+ $customer->setTokenCustomerID($token ? $token : '');
100
+ $this->setCustomer($customer);
101
+
102
+ // prepare API
103
+ $this->setRedirectUrl($returnUrl);
104
+ $this->setCancelUrl($cancelUrl);
105
+ $this->setMethod($method);
106
+
107
+ if (Mage::helper('ewayrapid')->getTransferCartLineItems()) {
108
+ // add Shipping item and Line items
109
+ $lineItems = Mage::helper('ewayrapid')->getLineItems();
110
+ $this->setItems($lineItems);
111
+ }
112
+
113
+ // add Payment
114
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
115
+ $paymentParam->setTotalAmount($totalAmount);
116
+ $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
117
+
118
+ // add InvoiceDescription and InvoiceReference
119
+ $config = Mage::getModel('ewayrapid/config');
120
+
121
+ if ($config->shouldPassingInvoiceDescription()) {
122
+ $invoiceDescription = '';
123
+ foreach ($this->_quote->getAllVisibleItems() as $item) {
124
+ // Check in case multi-shipping
125
+ if (!$item->getQuoteParentItem()) {
126
+ $invoiceDescription .= (int) $item->getQty() . ' x ' .$item->getName() . ', ';
127
+ }
128
+ }
129
+ $invoiceDescription = trim($invoiceDescription, ', ');
130
+ $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
131
+
132
+ $paymentParam->setInvoiceDescription($invoiceDescription);
133
+ }
134
+
135
+ if ($config->shouldPassingGuessOrder()) {
136
+ $incrementId = $this->_getIncrementOrderId($this->_quote);
137
+ $paymentParam->setInvoiceReference($incrementId);
138
+ $paymentParam->setInvoiceNumber($incrementId);
139
+ }
140
+
141
+ $this->setPayment($paymentParam);
142
+
143
+ if ($this->_config->isSharedPageConnection()) {
144
+ // add Verify options
145
+ $this->setVerifyCustomerEmail($this->_config->getVerifyEmail());
146
+ $this->setVerifyCustomerPhone($this->_config->getVerifyPhone());
147
+
148
+ // add Custom View
149
+ $this->setCustomView($this->_config->getCustomView());
150
+
151
+ }
152
+
153
+ $response = $this->_doRapidAPI('AccessCodesShared');
154
+ return $response;
155
+ }
156
+
157
+ /**
158
+ * Call Authorisation API (Authorized only)
159
+ *
160
+ * @param Eway_Rapid31_Model_Response $response
161
+ * @return Eway_Rapid31_Model_Response
162
+ */
163
+ public function doAuthorisation(Eway_Rapid31_Model_Response $response)
164
+ {
165
+ $this->unsetData();
166
+
167
+ $this->_buildRequest();
168
+
169
+ $cardData = $response->getCustomer();
170
+ if ($cardData['CardNumber'] && $cardData['CardName']) {
171
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_AUTHORISE);
172
+ } else {
173
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
174
+ }
175
+
176
+ $items = $this->_quote->getAllVisibleItems();
177
+ $lineItems = array();
178
+ foreach ($items as $item) {
179
+ /* @var Mage_Sales_Model_Order_Item $item */
180
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
181
+ $lineItem->setSKU($item->getSku());
182
+ $lineItem->setDescription(substr($item->getName(), 0, 26));
183
+ $lineItem->setQuantity($item->getQty());
184
+ $lineItem->setUnitCost(round($item->getBasePrice() * 100));
185
+ $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
186
+ $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
187
+ $lineItems[] = $lineItem;
188
+ }
189
+ $this->setItems($lineItems);
190
+
191
+ $this->setItems(false);
192
+
193
+ // add Payment
194
+ $amount = round($this->_quote->getBaseGrandTotal() * 100);
195
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
196
+ $paymentParam->setTotalAmount($amount);
197
+ $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
198
+
199
+ // add InvoiceDescription and InvoiceReference
200
+ $config = Mage::getModel('ewayrapid/config');
201
+
202
+ if ($config->shouldPassingInvoiceDescription()) {
203
+ $invoiceDescription = '';
204
+ foreach ($this->_quote->getAllVisibleItems() as $item) {
205
+ // Check in case multi-shipping
206
+ if (!$item->getQuoteParentItemId()) {
207
+ $invoiceDescription .= (int) $item->getQty() . ' x ' .$item->getName() . ', ';
208
+ }
209
+ }
210
+ $invoiceDescription = trim($invoiceDescription, ', ');
211
+ $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
212
+
213
+ $paymentParam->setInvoiceDescription($invoiceDescription);
214
+ }
215
+
216
+ if ($config->shouldPassingGuessOrder()) {
217
+ $incrementId = $this->_getIncrementOrderId($this->_quote);
218
+ $paymentParam->setInvoiceReference($incrementId);
219
+ }
220
+
221
+ $this->setPayment($paymentParam);
222
+
223
+ $customerParam = $this->getCustomer();
224
+ $customerParam->setTokenCustomerID($response->getTokenCustomerID());
225
+ $this->setCustomer($customerParam);
226
+
227
+ $response = $this->_doRapidAPI('Authorisation');
228
+ return $response;
229
+ }
230
+
231
+ /**
232
+ * Call Transaction API (Authorized & Capture at the same time)
233
+ *
234
+ * @param Eway_Rapid31_Model_Response $response
235
+ * @return Eway_Rapid31_Model_Response
236
+ */
237
+ public function doTransaction(Eway_Rapid31_Model_Response $response)
238
+ {
239
+ $this->unsetData();
240
+
241
+ $this->_buildRequest();
242
+
243
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
244
+
245
+ $items = $this->_quote->getAllVisibleItems();
246
+ $lineItems = array();
247
+ foreach ($items as $item) {
248
+ /* @var Mage_Sales_Model_Order_Item $item */
249
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
250
+ $lineItem->setSKU($item->getSku());
251
+ $lineItem->setDescription(substr($item->getName(), 0, 26));
252
+ $lineItem->setQuantity($item->getQty());
253
+ $lineItem->setUnitCost(round($item->getBasePrice() * 100));
254
+ $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
255
+ $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
256
+ $lineItems[] = $lineItem;
257
+ }
258
+ $this->setItems($lineItems);
259
+
260
+ $this->setItems(false);
261
+
262
+ // add Payment
263
+ $amount = round($this->_quote->getBaseGrandTotal() * 100);
264
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
265
+ $paymentParam->setTotalAmount($amount);
266
+ $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
267
+ $this->setPayment($paymentParam);
268
+
269
+ $customerParam = $this->getCustomer();
270
+ $customerParam->setTokenCustomerID($response->getTokenCustomerID());
271
+
272
+ $this->setCustomer($customerParam);
273
+
274
+ $response = $this->_doRapidAPI('Transaction');
275
+ return $response;
276
+ }
277
+
278
+ /**
279
+ * Call Capture API (do the Capture only, must Authorized previously)
280
+ *
281
+ * @param Eway_Rapid31_Model_Response $response
282
+ * @return Eway_Rapid31_Model_Response
283
+ */
284
+ public function doCapturePayment(Eway_Rapid31_Model_Response $response)
285
+ {
286
+ $this->setTransactionId($response->getTransactionID());
287
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT);
288
+
289
+ $response = $this->_doRapidAPI('CapturePayment');
290
+ return $response;
291
+ }
292
+
293
+ /**
294
+ * Build the request with necessary parameters for doAuthorisation(), doTransaction() and CreateAccessCode()
295
+ *
296
+ * @return $this
297
+ */
298
+ protected function _buildRequest()
299
+ {
300
+ // prepare API
301
+ $this->setShippingMethod('Other');
302
+ $version = Mage::helper('ewayrapid')->getExtensionVersion();
303
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
304
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
305
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
306
+ } else {
307
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
308
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
309
+ }
310
+ $this->setCustomerReadOnly(true);
311
+
312
+ // add Billing Address
313
+ $billingAddress = $this->_quote->getBillingAddress();
314
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
315
+
316
+ $title = $this->_fixTitle($billingAddress->getPrefix());
317
+
318
+ $customerParam->setTitle($title)
319
+ ->setFirstName($billingAddress->getFirstname())
320
+ ->setLastName($billingAddress->getLastname())
321
+ ->setCompanyName($billingAddress->getCompany())
322
+ ->setJobDescription($billingAddress->getJobDescription())
323
+ ->setStreet1($billingAddress->getStreet1())
324
+ ->setStreet2($billingAddress->getStreet2())
325
+ ->setCity($billingAddress->getCity())
326
+ ->setState($billingAddress->getRegion())
327
+ ->setPostalCode($billingAddress->getPostcode())
328
+ ->setCountry(strtolower($billingAddress->getCountryModel()->getIso2Code()))
329
+ ->setEmail($billingAddress->getEmail())
330
+ ->setPhone($billingAddress->getTelephone())
331
+ ->setMobile($billingAddress->getMobile())
332
+ ->setComments('')
333
+ ->setFax($billingAddress->getFax())
334
+ ->setUrl('');
335
+ $this->setCustomer($customerParam);
336
+
337
+ // add Shipping Address
338
+ $shippingAddress = $this->_quote->getShippingAddress();
339
+
340
+ // copy BillingAddress to ShippingAddress if checkout with guest or register
341
+ /**
342
+ $checkoutMethod = $this->_quote->getCheckoutMethod();
343
+ if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST
344
+ || $checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER
345
+ ) {
346
+ $shippingAddress = $billingAddress;
347
+ }
348
+ */
349
+
350
+ if (!empty($shippingAddress)) {
351
+ $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
352
+ $shippingParam->setFirstName($shippingAddress->getFirstname())
353
+ ->setLastName($shippingAddress->getLastname())
354
+ ->setStreet1($shippingAddress->getStreet1())
355
+ ->setStreet2($shippingAddress->getStreet2())
356
+ ->setCity($shippingAddress->getCity())
357
+ ->setState($shippingAddress->getRegion())
358
+ ->setPostalCode($shippingAddress->getPostcode())
359
+ ->setCountry(strtolower($shippingAddress->getCountryModel()->getIso2Code()))
360
+ ->setEmail($shippingAddress->getEmail())
361
+ ->setPhone($shippingAddress->getTelephone())
362
+ ->setFax($shippingAddress->getFax());
363
+ $this->setShippingAddress($shippingParam);
364
+ }
365
+
366
+ return $this;
367
+ }
368
+
369
+ /**
370
+ * Get customer information by access code
371
+ */
372
+ public function getInfoByAccessCode($accessCode)
373
+ {
374
+ $response = $this->_doRapidAPI('AccessCode/' . $accessCode, false);
375
+ return $response;
376
+ }
377
+
378
+ /**
379
+ * Get customer session object
380
+ *
381
+ * @return Mage_Customer_Model_Session
382
+ */
383
+ public function getCustomerSession()
384
+ {
385
+ return $this->_customerSession;
386
+ }
387
+
388
+ /**
389
+ * check is new token when checkout
390
+ *
391
+ * @return bool
392
+ */
393
+ protected function _isNewToken()
394
+ {
395
+ $info = $this->_quote->getPayment();
396
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
397
+ if ($token = Mage::getSingleton('core/session')->getData('newToken')) {
398
+ Mage::getSingleton('core/session')->unsetData('newToken');
399
+ return true;
400
+ }
401
+ return false;
402
+ }
403
+
404
+ /**
405
+ * get TokenCustomerID is selected of customer
406
+ *
407
+ * @return mixed
408
+ */
409
+ protected function _editToken()
410
+ {
411
+ if ($token = Mage::getSingleton('core/session')->getData('editToken')) {
412
+ Mage::getSingleton('core/session')->unsetData('editToken');
413
+ return $token;
414
+ }
415
+ return $token;
416
+ }
417
+
418
+ /**
419
+ * check paypal option in eway not saved
420
+ *
421
+ * @return mixed|null
422
+ */
423
+ protected function _getPaypalCheckout()
424
+ {
425
+ if ($paypal = Mage::getSingleton('core/session')->getData('sharedpagePaypal')) {
426
+ Mage::getModel('core/session')->unsetData('sharedpagePaypal');
427
+ return $paypal;
428
+ }
429
+ return null;
430
+ }
431
+
432
+ /**
433
+ * update customer when edit shipping address to paypal
434
+ *
435
+ * @param $accessCode
436
+ */
437
+ public function updateCustomer($accessCode)
438
+ {
439
+ $response = $this->_doRapidAPI('Transaction/' . $accessCode, 'GET');
440
+ if ($response->isSuccess()) {
441
+ $customer = $this->_quote->getCustomer();
442
+ $billingAddress = $this->_quote->getBillingAddress();
443
+ $shippingAddress = $this->_quote->getShippingAddress();
444
+ $trans = $response->getTransactions();
445
+
446
+ if (isset($trans[0]['Customer'])) {
447
+ $billing = $trans[0]['Customer'];
448
+ $billingAddress->setFirstname($billing['FirstName'])
449
+ ->setLastName($billing['LastName'])
450
+ ->setCompany($billing['CompanyName'])
451
+ ->setJobDescription($billing['JobDescription'])
452
+ ->setStreet($billing['Street1'])
453
+ ->setStreet2($billing['Street2'])
454
+ ->setCity($billing['City'])
455
+ ->setState($billing['State'])
456
+ ->setPostcode($billing['PostalCode'])
457
+ ->setCountryId(strtoupper($billing['Country']))
458
+ ->setEmail($billing['Email'])
459
+ ->setTelephone($billing['Phone'])
460
+ ->setMobile($billing['Mobile'])
461
+ ->setComments($billing['Comments'])
462
+ ->setFax($billing['Fax'])
463
+ ->setUrl($billing['Url']);
464
+ }
465
+ if (isset($trans[0]['ShippingAddress'])) {
466
+ $shipping = $trans[0]['ShippingAddress'];
467
+ $shippingAddress->setFirstname($shipping['FirstName'])
468
+ ->setLastname($shipping['LastName'])
469
+ ->setStreet($shipping['Street1'])
470
+ ->setStreet2($shipping['Street2'])
471
+ ->setCity($shipping['City'])
472
+ ->setPostcode($shipping['PostalCode'])
473
+ ->setCountryId(strtoupper($shipping['Country']))
474
+ ->setEmail($shipping['Email'])
475
+ ->setFax($shipping['Fax']);
476
+
477
+ if ($shipping['State']
478
+ && $shipping['Country']
479
+ && $region = Mage::getModel('directory/region')->loadByCode($shipping['State'], $shipping['Country'])
480
+ ) {
481
+ $shippingAddress->setRegion($region->getName())
482
+ ->setRegionId($region->getId());
483
+ }
484
+ if ($shipping['Phone']) {
485
+ $shippingAddress->setTelephone($shipping['Phone']);
486
+ }
487
+ }
488
+ $this->_quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress)->save();
489
+ }
490
+ }
491
+
492
+ /**
493
+ * save token when checkout with eway saved
494
+ *
495
+ * @param Eway_Rapid31_Model_Response $response
496
+ * @param null $ccNumber
497
+ */
498
+ public function saveTokenById(Eway_Rapid31_Model_Response $response, $ccNumber = null)
499
+ {
500
+ $this->unsetData();
501
+
502
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
503
+ $customerParam->setTokenCustomerID($response->getTokenCustomerID());
504
+ $this->setCustomer($customerParam);
505
+ $payment = Mage::getModel('ewayrapid/field_payment');
506
+ $payment->setTotalAmount(1);
507
+ $this->setPayment($payment);
508
+ $this->setRedirectUrl(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . '/ewayrapid/sharedpage/saveToken');
509
+ $this->setMethod('');
510
+
511
+ $response = $this->_doRapidAPI('AccessCodesShared');
512
+ $token = true;
513
+ if ($response->isSuccess()) {
514
+ if (!$ccNumber) {
515
+ $token = $this->_createNewToken($response);
516
+ } else {
517
+ $token = $this->_updateToken($response, $ccNumber);
518
+ }
519
+
520
+ } else {
521
+ Mage::throwException(
522
+ Mage::helper('ewayrapid')->__(
523
+ 'An error occurred while creating new token. Please try again. (Error message: %s)',
524
+ $response->getMessage()
525
+ )
526
+ );
527
+ }
528
+ if (!$token) {
529
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while process token. Please try again.'));
530
+ }
531
+ return $response;
532
+ }
533
+
534
+ /**
535
+ * Create new token when checkout
536
+ *
537
+ * @param Eway_Rapid31_Model_Response $response
538
+ * @return $this
539
+ */
540
+ protected function _createNewToken(Eway_Rapid31_Model_Response $response)
541
+ {
542
+ try {
543
+ $customer = $response->getCustomer();
544
+
545
+ $tokenInfo = array(
546
+ 'Token' => $response->getTokenCustomerID(),
547
+ 'Card' => $customer['CardNumber'] ? substr_replace($customer['CardNumber'], '******', 6, 6) : 'Paypal',
548
+ 'Owner' => $customer['CardName'],
549
+ 'StartMonth' => $customer['CardStartMonth'],
550
+ 'StartYear' => $customer['CardStartYear'],
551
+ 'IssueNumber' => $customer['CardIssueNumber'],
552
+ 'ExpMonth' => $customer['CardExpiryMonth'],
553
+ 'ExpYear' => (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear']),
554
+ 'Type' => $this->checkCardType($customer['CardNumber']),
555
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customer),
556
+ );
557
+
558
+ Mage::helper('ewayrapid/customer')->addToken($tokenInfo);
559
+ return true;
560
+ } catch (Exception $e) {
561
+ return false;
562
+ }
563
+ }
564
+
565
+ /**
566
+ * Update token when checkout with existing token
567
+ *
568
+ * @param Eway_Rapid31_Model_Response $response
569
+ * @param null $ccNumber
570
+ * @return $this
571
+ */
572
+ protected function _updateToken(Eway_Rapid31_Model_Response $response, $ccNumber = null)
573
+ {
574
+ try {
575
+ $customer = $response->getCustomer();
576
+
577
+ $tokenInfo = array(
578
+ 'Token' => $response->getTokenCustomerID(),
579
+ 'Card' => $customer['CardNumber'] ? substr_replace($customer['CardNumber'], '******', 6, 6) : 'Paypal',
580
+ 'Owner' => $customer['CardName'],
581
+ 'StartMonth' => $customer['CardStartMonth'],
582
+ 'StartYear' => $customer['CardStartYear'],
583
+ 'IssueNumber' => $customer['CardIssueNumber'],
584
+ 'ExpMonth' => $customer['CardExpiryMonth'],
585
+ 'ExpYear' => (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear']),
586
+ 'Type' => $this->checkCardType($customer['CardNumber']),
587
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customer),
588
+ );
589
+
590
+ Mage::helper('ewayrapid/customer')->updateToken($ccNumber, $tokenInfo);
591
+ return true;
592
+ } catch (Exception $e) {
593
+ return false;
594
+ }
595
+ }
596
+
597
+ /**
598
+ * Get card type name by card number
599
+ * @param $num Card number
600
+ * @return string Card type name
601
+ */
602
+ public function checkCardType($num)
603
+ {
604
+ if ($num == null) {
605
+ return Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD;
606
+ }
607
+ return Mage::getModel('ewayrapid/request_token')->checkCardType($num);
608
+ }
609
+
610
+ public function getShippingByCode($postalCode)
611
+ {
612
+ $groups = $this->_quote->getShippingAddress()
613
+ ->collectShippingRates()
614
+ ->getGroupedAllShippingRates();
615
+ // determine current selected code & name
616
+ foreach ($groups as $code => $rates) {
617
+ foreach ($rates as $rate) {
618
+ if (strtoupper($postalCode) == strtoupper($rate->getCode())) {
619
+ return $rate;
620
+ }
621
+ }
622
+ }
623
+ return false;
624
+ }
625
+
626
+ public function getMethod()
627
+ {
628
+ return Mage::getSingleton('core/session')->getData('ewayMethod');
629
+ }
630
+
631
+ public function getTransaction($transactionNumber)
632
+ {
633
+ try {
634
+ $results = $this->_doRapidAPI("Transaction/$transactionNumber", 'GET');
635
+ if ($results->isSuccess()) {
636
+ return $results->getTransactions();
637
+ }
638
+ } catch (Exception $e) {
639
+ Mage::throwException(
640
+ Mage::helper('ewayrapid')->__(
641
+ 'An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
642
+ $results->getMessage()
643
+ )
644
+ );
645
+ return false;
646
+ }
647
+ }
648
  }
app/code/community/Eway/Rapid31/Model/Request/Token.php CHANGED
@@ -1,544 +1,557 @@
1
- <?php
2
- class Eway_Rapid31_Model_Request_Token extends Eway_Rapid31_Model_Request_Direct
3
- {
4
- /**
5
- * Call create new customer token API
6
- *
7
- * @param Varien_Object $billing
8
- * @param Varien_Object $infoInstance
9
- * @return Eway_Rapid31_Model_Request_Token
10
- */
11
- public function createNewToken(Varien_Object $billing, Varien_Object $infoInstance)
12
- {
13
- // Empty Varien_Object's data
14
- $this->unsetData();
15
-
16
- $customerParam = Mage::getModel('ewayrapid/field_customer');
17
-
18
- $title = $this->_fixTitle($billing->getPrefix());
19
-
20
- $customerParam->setTitle($title)
21
- ->setFirstName($billing->getFirstname())
22
- ->setLastName($billing->getLastname())
23
- ->setCompanyName($billing->getCompany())
24
- ->setJobDescription($billing->getJobDescription())
25
- ->setStreet1($billing->getStreet1())
26
- ->setStreet2($billing->getStreet2())
27
- ->setCity($billing->getCity())
28
- ->setState($billing->getRegion())
29
- ->setPostalCode($billing->getPostcode())
30
- ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
31
- ->setEmail($billing->getEmail())
32
- ->setPhone($billing->getTelephone())
33
- ->setMobile($billing->getMobile())
34
- ->setComments('')
35
- ->setFax($billing->getFax())
36
- ->setUrl('');
37
-
38
- $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
39
- $cardDetails->setName($infoInstance->getCcOwner())
40
- ->setNumber($infoInstance->getCcNumber())
41
- ->setExpiryMonth($infoInstance->getCcExpMonth())
42
- ->setExpiryYear($infoInstance->getCcExpYear())
43
- ->setCVN($infoInstance->getCcCid())
44
- ->setStartMonth($infoInstance->getStartMonth())
45
- ->setStartYear($infoInstance->getStartYear())
46
- ->setIssueNumber($infoInstance->getIssueNumber());
47
- $customerParam->setCardDetails($cardDetails);
48
- $this->setCustomer($customerParam);
49
-
50
- $response = $this->_doRapidAPI('Customer');
51
- if ($response->isSuccess()) {
52
- $customerReturn = $response->getCustomer();
53
- $cardDetails = $customerReturn['CardDetails'];
54
- unset($customerReturn['CardDetails']);
55
- $customerReturn['RegionId'] = ((!$billing->getRegion() && $billing->getRegionId()) ? $billing->getRegionId() : '');
56
- $tokenInfo = array(
57
- 'Token' => $response->getTokenCustomerID(),
58
- 'Card' => substr_replace($cardDetails['Number'], '******', 6, 6),
59
- 'Owner' => $infoInstance->getCcOwner(),
60
- 'ExpMonth' => $infoInstance->getCcExpMonth(),
61
- 'ExpYear' => $infoInstance->getCcExpYear(),
62
- 'Type' => $infoInstance->getCcType(),
63
- 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customerReturn),
64
- );
65
- Mage::helper('ewayrapid/customer')->addToken($tokenInfo);
66
- return $this;
67
- } else {
68
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while creating new token. Please try again. (Error message: %s)',
69
- $response->getMessage()));
70
- }
71
- }
72
-
73
- /**
74
- * Update current token
75
- *
76
- * @param Varien_Object $billing
77
- * @param Varien_Object $infoInstance
78
- * @return Eway_Rapid31_Model_Request_Token
79
- */
80
- public function updateToken(Varien_Object $billing, Varien_Object $infoInstance)
81
- {
82
- if (!Mage::helper('ewayrapid')->isBackendOrder() && !Mage::getSingleton('ewayrapid/config')->canEditToken()) {
83
- Mage::throwException(Mage::helper('ewayrapid')->__('Customers are not allowed to edit token.'));
84
- }
85
-
86
- // Empty Varien_Object's data
87
- $this->unsetData();
88
-
89
- $customerParam = Mage::getModel('ewayrapid/field_customer');
90
-
91
- $title = $this->_fixTitle($billing->getPrefix());
92
-
93
- $customerParam->setTitle($title)
94
- ->setFirstName($billing->getFirstname())
95
- ->setLastName($billing->getLastname())
96
- ->setCompanyName($billing->getCompany())
97
- ->setJobDescription($billing->getJobDescription())
98
- ->setStreet1($billing->getStreet1())
99
- ->setStreet2($billing->getStreet2())
100
- ->setCity($billing->getCity())
101
- ->setState($billing->getRegion())
102
- ->setPostalCode($billing->getPostcode())
103
- ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
104
- ->setEmail($billing->getEmail())
105
- ->setPhone($billing->getTelephone())
106
- ->setMobile($billing->getMobile())
107
- ->setFax($billing->getFax());
108
-
109
- $customerHelper = Mage::helper('ewayrapid/customer');
110
- $customerTokenId = $customerHelper->getCustomerTokenId($infoInstance->getSavedToken());
111
- if ($customerTokenId) {
112
- $customerParam->setTokenCustomerID($customerTokenId);
113
- } else {
114
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
115
- }
116
-
117
- $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
118
- $cardDetails->setName($infoInstance->getCcOwner())
119
- ->setExpiryMonth($infoInstance->getCcExpMonth())
120
- ->setNumber('444433XXXXXX1111') // Required dummy card number for update to work
121
- ->setExpiryYear($infoInstance->getCcExpYear())
122
- ->setCVN($infoInstance->getCcCid());
123
- $customerParam->setCardDetails($cardDetails);
124
-
125
- $this->setCustomer($customerParam);
126
-
127
- $response = $this->_doRapidAPI('Customer', 'PUT');
128
- if ($response->isSuccess()) {
129
- $customerReturn = $response->getCustomer();
130
- $customerReturn['RegionId'] = ((!$billing->getRegion() && $billing->getRegionId()) ? $billing->getRegionId() : '');
131
- unset($customerReturn['CardDetails']);
132
- $tokenInfo = array(
133
- 'Token' => $response->getTokenCustomerID(),
134
- 'Owner' => $infoInstance->getCcOwner(),
135
- 'ExpMonth' => $infoInstance->getCcExpMonth(),
136
- 'ExpYear' => $infoInstance->getCcExpYear(),
137
- 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customerReturn),
138
- );
139
- Mage::helper('ewayrapid/customer')->updateToken($infoInstance->getSavedToken(), $tokenInfo);
140
- return $this;
141
- } else {
142
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token. Please try again. (Error message: %s)',
143
- $response->getMessage()));
144
- }
145
- }
146
-
147
- protected function _buildRequest(Mage_Sales_Model_Order_Payment $payment, $amount)
148
- {
149
- // Empty Varien_Object's data
150
- $this->unsetData();
151
- // in case recurring profile, $methodInstance is not exist, and $payment->getIsRecurring() is used
152
- if (!$payment->getIsRecurring()) {
153
- $methodInstance = $payment->getMethodInstance();
154
- $infoInstance = $methodInstance->getInfoInstance();
155
- Mage::helper('ewayrapid')->unserializeInfoInstace($infoInstance);
156
- }
157
- $order = $payment->getOrder();
158
- $shipping = $order->getShippingAddress();
159
-
160
- // if item is virtual product
161
- if (!$shipping) {
162
- $quote = Mage::getModel('checkout/cart')->getQuote();
163
- if ($quote->isVirtual()) {
164
- $shipping = $quote->getBillingAddress();
165
- }
166
- }
167
-
168
- if (!$payment->getIsRecurring()) {
169
- $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
170
- }
171
- if (Mage::helper('ewayrapid')->isBackendOrder()) {
172
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
173
- } elseif ($payment->getIsRecurring()) {
174
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_RECURRING);
175
- } else {
176
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
177
- }
178
- $version = Mage::helper('ewayrapid')->getExtensionVersion();
179
- $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
180
- $this->setShippingMethod('Other');
181
-
182
- $paymentParam = Mage::getModel('ewayrapid/field_payment');
183
- $paymentParam->setTotalAmount($amount)
184
- ->setCurrencyCode($order->getBaseCurrencyCode());
185
-
186
- // add InvoiceDescription and InvoiceReference
187
- $config = Mage::getModel('ewayrapid/config');
188
-
189
- if($config->shouldPassingInvoiceDescription()){
190
- $invoiceDescription = '';
191
- foreach($order->getAllVisibleItems() as $item){
192
- // Check in case multi-shipping
193
- if (!$item->getQuoteParentItemId()) {
194
- $invoiceDescription .= (int) $item->getQtyOrdered() . ' x ' .$item->getName() . ', ';
195
- }
196
- }
197
- $invoiceDescription = trim($invoiceDescription,', ');
198
- $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
199
-
200
- $paymentParam->setInvoiceDescription($invoiceDescription);
201
- }
202
-
203
- if($config->shouldPassingGuessOrder()){
204
- $paymentParam->setInvoiceReference($order->getIncrementId());
205
- }
206
-
207
- $this->setPayment($paymentParam);
208
-
209
- $customerParam = Mage::getModel('ewayrapid/field_customer');
210
- $customerTokenId = null;
211
-
212
- /** get $customerTokenId if product is recurring profile */
213
- if ($payment->getIsRecurring()) {
214
- $customer = Mage::getModel('customer/customer')->load($payment->getCustomerId());
215
- $customerHelper = Mage::helper('ewayrapid/customer');
216
- $customerHelper->setCurrentCustomer($customer);
217
- $customerTokenId = $customerHelper->getCustomerTokenId($payment->getTokenId());
218
- } else {
219
- /** get $customerTokenId if product is normal item */
220
- if ($infoInstance->getSavedToken()) {
221
- $customerHelper = Mage::helper('ewayrapid/customer');
222
- $customerTokenId = $customerHelper->getCustomerTokenId($infoInstance->getSavedToken());
223
- }
224
- else {
225
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction: Token info does not exist.'));
226
- }
227
- }
228
- if ($customerTokenId) {
229
- $customerParam->setTokenCustomerID($customerTokenId);
230
- if ($this->getTransactionType() == Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE) {
231
- $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
232
- $cardDetails->setCVN($infoInstance->getCcCid());
233
- $customerParam->setCardDetails($cardDetails);
234
- }
235
- $this->setCustomer($customerParam);
236
- } else {
237
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction: Token info does not exist.'));
238
- }
239
-
240
- if (!empty($shipping)) {
241
- $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
242
- $shippingParam->setFirstName($shipping->getFirstname())
243
- ->setLastName($shipping->getLastname())
244
- ->setStreet1($shipping->getStreet1())
245
- ->setStreet2($shipping->getStreet2())
246
- ->setCity($shipping->getCity())
247
- ->setState($shipping->getRegion())
248
- ->setPostalCode($shipping->getPostcode())
249
- ->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))
250
- ->setEmail($shipping->getEmail())
251
- ->setPhone($shipping->getTelephone())
252
- ->setFax($shipping->getFax());
253
- $this->setShippingAddress($shippingParam);
254
- }
255
-
256
- if ((isset($methodInstance) && $methodInstance->getConfigData('transfer_cart_items')) || $payment->getIsRecurring() || !$payment->getIsInitialFee()) {
257
- $orderItems = $order->getAllVisibleItems();
258
- $lineItems = array();
259
- foreach ($orderItems as $orderItem) {
260
- /* @var Mage_Sales_Model_Order_Item $orderItem */
261
- $lineItem = Mage::getModel('ewayrapid/field_lineItem');
262
- $lineItem->setSKU($orderItem->getSku());
263
- $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
264
- $lineItem->setQuantity($orderItem->getQtyOrdered());
265
- $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
266
- $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
267
- $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
268
- $lineItems[] = $lineItem;
269
- }
270
- $this->setItems($lineItems);
271
- }
272
-
273
-
274
- return $this;
275
- }
276
-
277
- /**
278
- * Create new AccessCode
279
- * @param Varien_Object $billing
280
- * @param Varien_Object $infoInstance
281
- * @param string $method
282
- * @param null $request
283
- * @return Eway_Rapid31_Model_Response
284
- */
285
- public function createAccessCode(Varien_Object $billing, Varien_Object $infoInstance,
286
- $method = 'AccessCodes', $request = null)
287
- {
288
- // Empty Varien_Object's data
289
- $tokenCustomerID = $request->get('TokenCustomerID');
290
- $this->unsetData();
291
- $customerParam = Mage::getModel('ewayrapid/field_customer');
292
-
293
- $title = $this->_fixTitle($billing->getPrefix());
294
-
295
- $customerParam->setTokenCustomerID($tokenCustomerID)
296
- ->setTitle($title)
297
- ->setFirstName($billing->getFirstname())
298
- ->setLastName($billing->getLastname())
299
- ->setCompanyName($billing->getCompany())
300
- ->setJobDescription($billing->getJobDescription())
301
- ->setStreet1($billing->getStreet1())
302
- ->setStreet2($billing->getStreet2())
303
- ->setCity($billing->getCity())
304
- ->setState($billing->getRegion())
305
- ->setPostalCode($billing->getPostcode())
306
- ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
307
- ->setEmail($billing->getEmail())
308
- ->setPhone($billing->getTelephone())
309
- ->setMobile($billing->getMobile())
310
- ->setComments('')
311
- ->setFax($billing->getFax())
312
- ->setUrl('');
313
-
314
- $returnUrl = Mage::getBaseUrl() . '/ewayrapid/mycards/saveToken?ccType='
315
- . $infoInstance->getCcType() . '&expYear=' . $infoInstance->getCcExpYear();
316
- if ($request->get('is_default') == 'on') {
317
- $returnUrl .= '&is_default=on';
318
- }
319
- if($infoInstance->getCcStartMonth()) {
320
- $returnUrl .= '&startMonth=' . $infoInstance->getCcStartMonth();
321
- }
322
- if($infoInstance->getCcStartYear()) {
323
- $returnUrl .= '&startYear=' . $infoInstance->getCcStartYear();
324
- }
325
- if($infoInstance->getCcIssueNumber()) {
326
- $returnUrl .= '&issueNumber=' . $infoInstance->getCcIssueNumber();
327
- }
328
- // Binding address on url param
329
- $returnUrl .= '&street1=' . base64_encode($billing->getStreet1())
330
- . '&street2=' . base64_encode($billing->getStreet2());
331
- $tokenId = $request->get('token_id');
332
- if (!empty($tokenId)) { // ID token customer will be defined to update
333
- $returnUrl = $returnUrl . '&token_id=' . $tokenId;
334
- }
335
-
336
- $this->setCustomer($customerParam);
337
- $this->setRedirectUrl($returnUrl);
338
- $this->setCancelUrl($returnUrl);
339
- $this->setMethod(!empty($tokenCustomerID) ? 'UpdateTokenCustomer' : 'CreateTokenCustomer');
340
- $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
341
- $version = Mage::helper('ewayrapid')->getExtensionVersion();
342
- $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
343
- $this->setTransactionType("Purchase");
344
- $this->setCustomerReadOnly(true);
345
-
346
- // Create new access code
347
- //$formMethod = !empty($tokenCustomerID) ? 'PUT' : 'POST';
348
- $response = $this->_doRapidAPI($method);
349
- return $response;
350
- }
351
-
352
- /*
353
- * Get customer information by access code
354
- */
355
- public function getInfoByAccessCode($accessCode)
356
- {
357
- $response = $this->_doRapidAPI('AccessCode/' . $accessCode, false);
358
- return $response;
359
- }
360
-
361
- public function saveInfoByTokenId($cardData)
362
- {
363
- // Empty Varien_Object's data
364
- $this->unsetData();
365
-
366
- $customerParam = Mage::getModel('ewayrapid/field_customer');
367
- $customerParam->setTokenCustomerID($cardData['token']);
368
- $payment = Mage::getModel('ewayrapid/field_payment');
369
- $payment->setTotalAmount(1);
370
- $returnUrl = Mage::getBaseUrl() . '/ewayrapid/mycards';
371
-
372
- $this->setCustomer($customerParam);
373
- $this->setPayment($payment);
374
- $this->setRedirectUrl($returnUrl);
375
- $this->setMethod('');
376
- $this->setTransactionType('');
377
- $version = Mage::helper('ewayrapid')->getExtensionVersion();
378
- $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
379
- $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
380
-
381
- $response = $this->_doRapidAPI('AccessCodes');
382
-
383
- if ($cardData['token_id']) {
384
- // Update card
385
- $this->__updateTokenTransparentOrSharedPage($response, $cardData);
386
- } else
387
- // Create new token
388
- $this->__createNewTokenTransparentOrSharedPage($response, $cardData);
389
- return $this;
390
-
391
- }
392
-
393
- private function __createNewTokenTransparentOrSharedPage($response, $cardData)
394
- {
395
- if ($response->isSuccess()) {
396
- $data = $response->getData();
397
- $customer = $data['Customer'];
398
- $address = array(
399
- //'TokenCustomerID' => $customer['TokenCustomerID'],
400
- 'Reference' => $customer['Reference'],
401
- 'Title' => $customer['Title'],
402
- 'FirstName' => $customer['FirstName'],
403
- 'LastName' => $customer['LastName'],
404
- 'CompanyName' => $customer['CompanyName'],
405
- 'JobDescription' => $customer['JobDescription'],
406
- 'Street1' => isset($cardData['street1'])? $cardData['street1'] : $customer['Street1'],
407
- 'Street2' => isset($cardData['street2']) ? $cardData['street2'] : $customer['Street2'],
408
- 'City' => $customer['City'],
409
- 'State' => $customer['State'],
410
- 'PostalCode' => $customer['PostalCode'],
411
- 'Country' => $customer['Country'],
412
- 'Email' => $customer['Email'],
413
- 'Phone' => $customer['Phone'],
414
- 'Mobile' => $customer['Mobile'],
415
- 'Comments' => $customer['Comments'],
416
- 'Fax' => $customer['Fax'],
417
- 'Url' => $customer['Url']
418
- );
419
- $tokenInfo = array(
420
- 'Token' => $response->getTokenCustomerID(),
421
- 'Card' => substr_replace($customer['CardNumber'], '******', 6, 6),
422
- 'Owner' => $customer['CardName'],
423
- 'StartMonth' => $cardData['startMonth'],
424
- 'StartYear' => $cardData['startYear'],
425
- 'IssueNumber' => $cardData['issueNumber'],
426
- 'ExpMonth' => $customer['CardExpiryMonth'],
427
- 'ExpYear' => (!empty($cardData['expYear']) ? $cardData['expYear'] :
428
- (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear'])),
429
- 'Type' => $cardData['ccType'] ? $cardData['ccType'] : $this->checkCardType($customer['CardNumber']),
430
- 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($address),
431
- );
432
-
433
- Mage::helper('ewayrapid/customer')->addToken($tokenInfo);
434
- return $this;
435
- } else {
436
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while creating new token. Please try again. (Error message: %s)',
437
- $response->getMessage()));
438
- }
439
- }
440
-
441
- private function __updateTokenTransparentOrSharedPage($res, $cardData)
442
- {
443
- if ($res->isSuccess()) {
444
- $data = $res->getData();
445
- $customer = $data['Customer'];
446
- $address = array(
447
- //'TokenCustomerID' => $customer['TokenCustomerID'],
448
- 'Reference' => $customer['Reference'],
449
- 'Title' => $customer['Title'],
450
- 'FirstName' => $customer['FirstName'],
451
- 'LastName' => $customer['LastName'],
452
- 'CompanyName' => $customer['CompanyName'],
453
- 'JobDescription' => $customer['JobDescription'],
454
- 'Street1' => isset($cardData['street1'])? $cardData['street1'] : $customer['Street1'],
455
- 'Street2' => isset($cardData['street2']) ? $cardData['street2'] : $customer['Street2'],
456
- 'City' => $customer['City'],
457
- 'State' => $customer['State'],
458
- 'PostalCode' => $customer['PostalCode'],
459
- 'Country' => $customer['Country'],
460
- 'Email' => $customer['Email'],
461
- 'Phone' => $customer['Phone'],
462
- 'Mobile' => $customer['Mobile'],
463
- 'Comments' => $customer['Comments'],
464
- 'Fax' => $customer['Fax'],
465
- 'Url' => $customer['Url']
466
- );
467
-
468
- $tokenInfo = array(
469
- 'Token' => $res->getTokenCustomerID(),
470
- 'Owner' => $customer['CardName'],
471
- 'StartMonth' => $cardData['startMonth'],
472
- 'StartYear' => $cardData['startYear'],
473
- 'IssueNumber' => $cardData['issueNumber'],
474
- 'ExpMonth' => $customer['CardExpiryMonth'],
475
- 'ExpYear' => (!empty($cardData['expYear']) ? $cardData['expYear'] :
476
- (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear'])),
477
- 'Type' => $cardData['ccType'] ? $cardData['ccType'] : $this->checkCardType($customer['CardNumber']),
478
- 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($address),
479
- );
480
- //edit card number if connection type = shared page
481
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
482
- || Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
483
- ) {
484
- $tokenInfo['Card'] = str_replace('X', '*', $customer['CardNumber']);
485
- $tokenInfo['Card'] = str_replace('x', '*', $tokenInfo['Card']);
486
- }
487
-
488
- Mage::helper('ewayrapid/customer')->updateToken($cardData['token_id'], $tokenInfo);
489
- return $this;
490
- } else {
491
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while creating new token. Please try again. (Error message: %s)',
492
- $res->getMessage()));
493
- }
494
- }
495
-
496
- /**
497
- * Get card type name by card number
498
- * @param $num Card number
499
- * @return string Card type name
500
- */
501
- public function checkCardType($num)
502
- {
503
- if (preg_match('/^(4026|417500|4508|4844|4913|4917)/', $num)) {
504
- return 'VE';
505
- }
506
- if (preg_match('/^4/', $num)) {
507
- return 'VI';
508
- }
509
- if (preg_match('/^(34|37)/', $num)) {
510
- return 'AE';
511
- }
512
- if (preg_match('/^(5[1-5])/', $num)) {
513
- return 'MC';
514
- }
515
- if (preg_match('/^(2131|1800)/', $num)) {
516
- return 'JCB';
517
- }
518
- if (preg_match('/^36/', $num)) {
519
- return 'DC';
520
- }
521
- if (preg_match('/^(5018|5020|5038|5893|6304|6759|6761|6762|6763)/', $num)) {
522
- return 'ME';
523
- }
524
-
525
- return 'Unknown';
526
- }
527
- /**
528
- * Check Card Name
529
- * @param $card Card Info
530
- * @return string Card name: paypal | masterpass | mastercard
531
- */
532
- public function checkCardName($card)
533
- {
534
- $cardType = strtolower($card->getType());
535
- if (preg_match('/^paypal/', $cardType)) {
536
- return Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD;
537
- }
538
- $ccTypes = Mage::getSingleton('ewayrapid/system_config_source_cctype')->getAllowedTypes();
539
- if (in_array(strtoupper($cardType), $ccTypes)) {
540
- return Eway_Rapid31_Model_Config::CREDITCARD_METHOD;
541
- }
542
- return Eway_Rapid31_Model_Config::MASTERPASS_METHOD;
543
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
544
  }
1
+ <?php
2
+ class Eway_Rapid31_Model_Request_Token extends Eway_Rapid31_Model_Request_Direct
3
+ {
4
+ /**
5
+ * Call create new customer token API
6
+ *
7
+ * @param Varien_Object $billing
8
+ * @param Varien_Object $infoInstance
9
+ * @return Eway_Rapid31_Model_Request_Token
10
+ */
11
+ public function createNewToken(Varien_Object $billing, Varien_Object $infoInstance)
12
+ {
13
+ // Empty Varien_Object's data
14
+ $this->unsetData();
15
+
16
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
17
+
18
+ $title = $this->_fixTitle($billing->getPrefix());
19
+
20
+ $customerParam->setTitle($title)
21
+ ->setFirstName($billing->getFirstname())
22
+ ->setLastName($billing->getLastname())
23
+ ->setCompanyName($billing->getCompany())
24
+ ->setJobDescription($billing->getJobDescription())
25
+ ->setStreet1($billing->getStreet1())
26
+ ->setStreet2($billing->getStreet2())
27
+ ->setCity($billing->getCity())
28
+ ->setState($billing->getRegion())
29
+ ->setPostalCode($billing->getPostcode())
30
+ ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
31
+ ->setEmail($billing->getEmail())
32
+ ->setPhone($billing->getTelephone())
33
+ ->setMobile($billing->getMobile())
34
+ ->setComments('')
35
+ ->setFax($billing->getFax())
36
+ ->setUrl('');
37
+
38
+ $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
39
+ $cardDetails->setName($infoInstance->getCcOwner())
40
+ ->setNumber($infoInstance->getCcNumber())
41
+ ->setExpiryMonth($infoInstance->getCcExpMonth())
42
+ ->setExpiryYear($infoInstance->getCcExpYear())
43
+ ->setCVN($infoInstance->getCcCid())
44
+ ->setStartMonth($infoInstance->getStartMonth())
45
+ ->setStartYear($infoInstance->getStartYear())
46
+ ->setIssueNumber($infoInstance->getIssueNumber());
47
+ $customerParam->setCardDetails($cardDetails);
48
+ $this->setCustomer($customerParam);
49
+
50
+ $response = $this->_doRapidAPI('Customer');
51
+ if ($response->isSuccess()) {
52
+ $customerReturn = $response->getCustomer();
53
+ $cardDetails = $customerReturn['CardDetails'];
54
+ unset($customerReturn['CardDetails']);
55
+ $customerReturn['RegionId'] = ((!$billing->getRegion() && $billing->getRegionId()) ? $billing->getRegionId() : '');
56
+ $tokenInfo = array(
57
+ 'Token' => $response->getTokenCustomerID(),
58
+ 'Card' => substr_replace($cardDetails['Number'], '******', 6, 6),
59
+ 'Owner' => $infoInstance->getCcOwner(),
60
+ 'ExpMonth' => $infoInstance->getCcExpMonth(),
61
+ 'ExpYear' => $infoInstance->getCcExpYear(),
62
+ 'Type' => $infoInstance->getCcType(),
63
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customerReturn),
64
+ );
65
+ Mage::helper('ewayrapid/customer')->addToken($tokenInfo);
66
+ return $this;
67
+ } else {
68
+ Mage::throwException(
69
+ Mage::helper('ewayrapid')->__(
70
+ 'An error occurred while creating new token. Please try again. (Error message: %s)',
71
+ $response->getMessage()
72
+ )
73
+ );
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Update current token
79
+ *
80
+ * @param Varien_Object $billing
81
+ * @param Varien_Object $infoInstance
82
+ * @return Eway_Rapid31_Model_Request_Token
83
+ */
84
+ public function updateToken(Varien_Object $billing, Varien_Object $infoInstance)
85
+ {
86
+ if (!Mage::helper('ewayrapid')->isBackendOrder() && !Mage::getSingleton('ewayrapid/config')->canEditToken()) {
87
+ Mage::throwException(Mage::helper('ewayrapid')->__('Customers are not allowed to edit token.'));
88
+ }
89
+
90
+ // Empty Varien_Object's data
91
+ $this->unsetData();
92
+
93
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
94
+
95
+ $title = $this->_fixTitle($billing->getPrefix());
96
+
97
+ $customerParam->setTitle($title)
98
+ ->setFirstName($billing->getFirstname())
99
+ ->setLastName($billing->getLastname())
100
+ ->setCompanyName($billing->getCompany())
101
+ ->setJobDescription($billing->getJobDescription())
102
+ ->setStreet1($billing->getStreet1())
103
+ ->setStreet2($billing->getStreet2())
104
+ ->setCity($billing->getCity())
105
+ ->setState($billing->getRegion())
106
+ ->setPostalCode($billing->getPostcode())
107
+ ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
108
+ ->setEmail($billing->getEmail())
109
+ ->setPhone($billing->getTelephone())
110
+ ->setMobile($billing->getMobile())
111
+ ->setFax($billing->getFax());
112
+
113
+ $customerHelper = Mage::helper('ewayrapid/customer');
114
+ $customerTokenId = $customerHelper->getCustomerTokenId($infoInstance->getSavedToken());
115
+ if ($customerTokenId) {
116
+ $customerParam->setTokenCustomerID($customerTokenId);
117
+ } else {
118
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
119
+ }
120
+
121
+ $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
122
+ $cardDetails->setName($infoInstance->getCcOwner())
123
+ ->setExpiryMonth($infoInstance->getCcExpMonth())
124
+ ->setNumber('444433XXXXXX1111') // Required dummy card number for update to work
125
+ ->setExpiryYear($infoInstance->getCcExpYear())
126
+ ->setCVN($infoInstance->getCcCid());
127
+ $customerParam->setCardDetails($cardDetails);
128
+
129
+ $this->setCustomer($customerParam);
130
+
131
+ $response = $this->_doRapidAPI('Customer', 'PUT');
132
+ if ($response->isSuccess()) {
133
+ $customerReturn = $response->getCustomer();
134
+ $customerReturn['RegionId'] = ((!$billing->getRegion() && $billing->getRegionId()) ? $billing->getRegionId() : '');
135
+ unset($customerReturn['CardDetails']);
136
+ $tokenInfo = array(
137
+ 'Token' => $response->getTokenCustomerID(),
138
+ 'Owner' => $infoInstance->getCcOwner(),
139
+ 'ExpMonth' => $infoInstance->getCcExpMonth(),
140
+ 'ExpYear' => $infoInstance->getCcExpYear(),
141
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customerReturn),
142
+ );
143
+ Mage::helper('ewayrapid/customer')->updateToken($infoInstance->getSavedToken(), $tokenInfo);
144
+ return $this;
145
+ } else {
146
+ Mage::throwException(
147
+ Mage::helper('ewayrapid')->__(
148
+ 'An error occurred while updating token. Please try again. (Error message: %s)',
149
+ $response->getMessage()
150
+ )
151
+ );
152
+ }
153
+ }
154
+
155
+ protected function _buildRequest(Mage_Sales_Model_Order_Payment $payment, $amount)
156
+ {
157
+ // Empty Varien_Object's data
158
+ $this->unsetData();
159
+ // in case recurring profile, $methodInstance is not exist, and $payment->getIsRecurring() is used
160
+ if (!$payment->getIsRecurring()) {
161
+ $methodInstance = $payment->getMethodInstance();
162
+ $infoInstance = $methodInstance->getInfoInstance();
163
+ Mage::helper('ewayrapid')->unserializeInfoInstace($infoInstance);
164
+ }
165
+ $order = $payment->getOrder();
166
+ $shipping = $order->getShippingAddress();
167
+
168
+ // if item is virtual product
169
+ if (!$shipping) {
170
+ $quote = Mage::getModel('checkout/cart')->getQuote();
171
+ if ($quote->isVirtual()) {
172
+ $shipping = $quote->getBillingAddress();
173
+ }
174
+ }
175
+
176
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
177
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
178
+ } elseif ($payment->getIsRecurring()) {
179
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_RECURRING);
180
+ } else {
181
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
182
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
183
+ }
184
+ $version = Mage::helper('ewayrapid')->getExtensionVersion();
185
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
186
+ $this->setShippingMethod('Other');
187
+
188
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
189
+ $paymentParam->setTotalAmount($amount)
190
+ ->setCurrencyCode($order->getBaseCurrencyCode());
191
+
192
+ // add InvoiceDescription and InvoiceReference
193
+ $config = Mage::getModel('ewayrapid/config');
194
+
195
+ if ($config->shouldPassingInvoiceDescription()) {
196
+ $invoiceDescription = '';
197
+ foreach ($order->getAllVisibleItems() as $item) {
198
+ // Check in case multi-shipping
199
+ if (!$item->getQuoteParentItemId()) {
200
+ $invoiceDescription .= (int) $item->getQtyOrdered() . ' x ' .$item->getName() . ', ';
201
+ }
202
+ }
203
+ $invoiceDescription = trim($invoiceDescription, ', ');
204
+ $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
205
+
206
+ $paymentParam->setInvoiceDescription($invoiceDescription);
207
+ }
208
+
209
+ if ($config->shouldPassingGuessOrder()) {
210
+ $paymentParam->setInvoiceReference($order->getIncrementId());
211
+ }
212
+
213
+ $this->setPayment($paymentParam);
214
+
215
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
216
+ $customerTokenId = null;
217
+
218
+ /** get $customerTokenId if product is recurring profile */
219
+ if ($payment->getIsRecurring()) {
220
+ $customer = Mage::getModel('customer/customer')->load($payment->getCustomerId());
221
+ $customerHelper = Mage::helper('ewayrapid/customer');
222
+ $customerHelper->setCurrentCustomer($customer);
223
+ $customerTokenId = $customerHelper->getCustomerTokenId($payment->getTokenId());
224
+ } else {
225
+ /** get $customerTokenId if product is normal item */
226
+ if ($infoInstance->getSavedToken()) {
227
+ $customerHelper = Mage::helper('ewayrapid/customer');
228
+ $customerTokenId = $customerHelper->getCustomerTokenId($infoInstance->getSavedToken());
229
+ } else {
230
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction: Token info does not exist.'));
231
+ }
232
+ }
233
+ if ($customerTokenId) {
234
+ $customerParam->setTokenCustomerID($customerTokenId);
235
+ if ($this->getTransactionType() == Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE) {
236
+ $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
237
+ $cardDetails->setCVN($infoInstance->getCcCid());
238
+ $customerParam->setCardDetails($cardDetails);
239
+ }
240
+ $this->setCustomer($customerParam);
241
+ } else {
242
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction: Token info does not exist.'));
243
+ }
244
+
245
+ if (!empty($shipping)) {
246
+ $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
247
+ $shippingParam->setFirstName($shipping->getFirstname())
248
+ ->setLastName($shipping->getLastname())
249
+ ->setStreet1($shipping->getStreet1())
250
+ ->setStreet2($shipping->getStreet2())
251
+ ->setCity($shipping->getCity())
252
+ ->setState($shipping->getRegion())
253
+ ->setPostalCode($shipping->getPostcode())
254
+ ->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))
255
+ ->setEmail($shipping->getEmail())
256
+ ->setPhone($shipping->getTelephone())
257
+ ->setFax($shipping->getFax());
258
+ $this->setShippingAddress($shippingParam);
259
+ }
260
+
261
+ if ((isset($methodInstance) && $methodInstance->getConfigData('transfer_cart_items')) || $payment->getIsRecurring() || !$payment->getIsInitialFee()) {
262
+ $orderItems = $order->getAllVisibleItems();
263
+ $lineItems = array();
264
+ foreach ($orderItems as $orderItem) {
265
+ /* @var Mage_Sales_Model_Order_Item $orderItem */
266
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
267
+ $lineItem->setSKU($orderItem->getSku());
268
+ $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
269
+ $lineItem->setQuantity($orderItem->getQtyOrdered());
270
+ $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
271
+ $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
272
+ $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
273
+ $lineItems[] = $lineItem;
274
+ }
275
+ $this->setItems($lineItems);
276
+ }
277
+
278
+
279
+ return $this;
280
+ }
281
+
282
+ /**
283
+ * Create new AccessCode
284
+ * @param Varien_Object $billing
285
+ * @param Varien_Object $infoInstance
286
+ * @param string $method
287
+ * @param null $request
288
+ * @return Eway_Rapid31_Model_Response
289
+ */
290
+ public function createAccessCode(Varien_Object $billing, Varien_Object $infoInstance,
291
+ $method = 'AccessCodes', $request = null)
292
+ {
293
+ // Empty Varien_Object's data
294
+ $tokenCustomerID = $request->get('TokenCustomerID');
295
+ $this->unsetData();
296
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
297
+
298
+ $title = $this->_fixTitle($billing->getPrefix());
299
+
300
+ $customerParam->setTokenCustomerID($tokenCustomerID)
301
+ ->setTitle($title)
302
+ ->setFirstName($billing->getFirstname())
303
+ ->setLastName($billing->getLastname())
304
+ ->setCompanyName($billing->getCompany())
305
+ ->setJobDescription($billing->getJobDescription())
306
+ ->setStreet1($billing->getStreet1())
307
+ ->setStreet2($billing->getStreet2())
308
+ ->setCity($billing->getCity())
309
+ ->setState($billing->getRegion())
310
+ ->setPostalCode($billing->getPostcode())
311
+ ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
312
+ ->setEmail($billing->getEmail())
313
+ ->setPhone($billing->getTelephone())
314
+ ->setMobile($billing->getMobile())
315
+ ->setComments('')
316
+ ->setFax($billing->getFax())
317
+ ->setUrl('');
318
+
319
+ $returnUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)
320
+ . '/ewayrapid/mycards/saveToken?ccType='
321
+ . $infoInstance->getCcType() . '&expYear=' . $infoInstance->getCcExpYear();
322
+ if ($request->get('is_default') == 'on') {
323
+ $returnUrl .= '&is_default=on';
324
+ }
325
+ if ($infoInstance->getCcStartMonth()) {
326
+ $returnUrl .= '&startMonth=' . $infoInstance->getCcStartMonth();
327
+ }
328
+ if ($infoInstance->getCcStartYear()) {
329
+ $returnUrl .= '&startYear=' . $infoInstance->getCcStartYear();
330
+ }
331
+ if ($infoInstance->getCcIssueNumber()) {
332
+ $returnUrl .= '&issueNumber=' . $infoInstance->getCcIssueNumber();
333
+ }
334
+ // Binding address on url param
335
+ $returnUrl .= '&street1=' . base64_encode($billing->getStreet1())
336
+ . '&street2=' . base64_encode($billing->getStreet2());
337
+ $tokenId = $request->get('token_id');
338
+ if (!empty($tokenId)) { // ID token customer will be defined to update
339
+ $returnUrl = $returnUrl . '&token_id=' . $tokenId;
340
+ }
341
+
342
+ $this->setCustomer($customerParam);
343
+ $this->setRedirectUrl($returnUrl);
344
+ $this->setCancelUrl($returnUrl);
345
+ $this->setMethod(!empty($tokenCustomerID) ? 'UpdateTokenCustomer' : 'CreateTokenCustomer');
346
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
347
+ $version = Mage::helper('ewayrapid')->getExtensionVersion();
348
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
349
+ $this->setTransactionType("Purchase");
350
+ $this->setCustomerReadOnly(true);
351
+
352
+ // Create new access code
353
+ $response = $this->_doRapidAPI($method);
354
+ return $response;
355
+ }
356
+
357
+ /*
358
+ * Get customer information by access code
359
+ */
360
+ public function getInfoByAccessCode($accessCode)
361
+ {
362
+ $response = $this->_doRapidAPI('AccessCode/' . $accessCode, false);
363
+ return $response;
364
+ }
365
+
366
+ public function saveInfoByTokenId($cardData)
367
+ {
368
+ // Empty Varien_Object's data
369
+ $this->unsetData();
370
+
371
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
372
+ $customerParam->setTokenCustomerID($cardData['token']);
373
+ $payment = Mage::getModel('ewayrapid/field_payment');
374
+ $payment->setTotalAmount(1);
375
+ $returnUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . '/ewayrapid/mycards';
376
+
377
+ $this->setCustomer($customerParam);
378
+ $this->setPayment($payment);
379
+ $this->setRedirectUrl($returnUrl);
380
+ $this->setMethod('');
381
+ $this->setTransactionType('');
382
+ $version = Mage::helper('ewayrapid')->getExtensionVersion();
383
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
384
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
385
+
386
+ $response = $this->_doRapidAPI('AccessCodes');
387
+
388
+ if ($cardData['token_id']) {
389
+ // Update card
390
+ $this->__updateTokenTransparentOrSharedPage($response, $cardData);
391
+ } else
392
+ // Create new token
393
+ $this->__createNewTokenTransparentOrSharedPage($response, $cardData);
394
+ return $this;
395
+
396
+ }
397
+
398
+ protected function __createNewTokenTransparentOrSharedPage($response, $cardData)
399
+ {
400
+ if ($response->isSuccess()) {
401
+ $data = $response->getData();
402
+ $customer = $data['Customer'];
403
+ $address = array(
404
+ //'TokenCustomerID' => $customer['TokenCustomerID'],
405
+ 'Reference' => $customer['Reference'],
406
+ 'Title' => $customer['Title'],
407
+ 'FirstName' => $customer['FirstName'],
408
+ 'LastName' => $customer['LastName'],
409
+ 'CompanyName' => $customer['CompanyName'],
410
+ 'JobDescription' => $customer['JobDescription'],
411
+ 'Street1' => isset($cardData['street1'])? $cardData['street1'] : $customer['Street1'],
412
+ 'Street2' => isset($cardData['street2']) ? $cardData['street2'] : $customer['Street2'],
413
+ 'City' => $customer['City'],
414
+ 'State' => $customer['State'],
415
+ 'PostalCode' => $customer['PostalCode'],
416
+ 'Country' => $customer['Country'],
417
+ 'Email' => $customer['Email'],
418
+ 'Phone' => $customer['Phone'],
419
+ 'Mobile' => $customer['Mobile'],
420
+ 'Comments' => $customer['Comments'],
421
+ 'Fax' => $customer['Fax'],
422
+ 'Url' => $customer['Url']
423
+ );
424
+ $tokenInfo = array(
425
+ 'Token' => $response->getTokenCustomerID(),
426
+ 'Card' => substr_replace($customer['CardNumber'], '******', 6, 6),
427
+ 'Owner' => $customer['CardName'],
428
+ 'StartMonth' => $cardData['startMonth'],
429
+ 'StartYear' => $cardData['startYear'],
430
+ 'IssueNumber' => $cardData['issueNumber'],
431
+ 'ExpMonth' => $customer['CardExpiryMonth'],
432
+ 'ExpYear' => (!empty($cardData['expYear']) ? $cardData['expYear'] :
433
+ (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear'])),
434
+ 'Type' => $cardData['ccType'] ? $cardData['ccType'] : $this->checkCardType($customer['CardNumber']),
435
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($address),
436
+ );
437
+
438
+ Mage::helper('ewayrapid/customer')->addToken($tokenInfo);
439
+ return $this;
440
+ } else {
441
+ Mage::throwException(
442
+ Mage::helper('ewayrapid')->__(
443
+ 'An error occurred while creating new token. Please try again. (Error message: %s)',
444
+ $response->getMessage()
445
+ )
446
+ );
447
+ }
448
+ }
449
+
450
+ protected function __updateTokenTransparentOrSharedPage($res, $cardData)
451
+ {
452
+ if ($res->isSuccess()) {
453
+ $data = $res->getData();
454
+ $customer = $data['Customer'];
455
+ $address = array(
456
+ //'TokenCustomerID' => $customer['TokenCustomerID'],
457
+ 'Reference' => $customer['Reference'],
458
+ 'Title' => $customer['Title'],
459
+ 'FirstName' => $customer['FirstName'],
460
+ 'LastName' => $customer['LastName'],
461
+ 'CompanyName' => $customer['CompanyName'],
462
+ 'JobDescription' => $customer['JobDescription'],
463
+ 'Street1' => isset($cardData['street1'])? $cardData['street1'] : $customer['Street1'],
464
+ 'Street2' => isset($cardData['street2']) ? $cardData['street2'] : $customer['Street2'],
465
+ 'City' => $customer['City'],
466
+ 'State' => $customer['State'],
467
+ 'PostalCode' => $customer['PostalCode'],
468
+ 'Country' => $customer['Country'],
469
+ 'Email' => $customer['Email'],
470
+ 'Phone' => $customer['Phone'],
471
+ 'Mobile' => $customer['Mobile'],
472
+ 'Comments' => $customer['Comments'],
473
+ 'Fax' => $customer['Fax'],
474
+ 'Url' => $customer['Url']
475
+ );
476
+
477
+ $tokenInfo = array(
478
+ 'Token' => $res->getTokenCustomerID(),
479
+ 'Owner' => $customer['CardName'],
480
+ 'StartMonth' => $cardData['startMonth'],
481
+ 'StartYear' => $cardData['startYear'],
482
+ 'IssueNumber' => $cardData['issueNumber'],
483
+ 'ExpMonth' => $customer['CardExpiryMonth'],
484
+ 'ExpYear' => (!empty($cardData['expYear']) ? $cardData['expYear'] :
485
+ (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear'])),
486
+ 'Type' => $cardData['ccType'] ? $cardData['ccType'] : $this->checkCardType($customer['CardNumber']),
487
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($address),
488
+ );
489
+ //edit card number if connection type = shared page
490
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
491
+ || Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
492
+ ) {
493
+ $tokenInfo['Card'] = str_replace('X', '*', $customer['CardNumber']);
494
+ $tokenInfo['Card'] = str_replace('x', '*', $tokenInfo['Card']);
495
+ }
496
+
497
+ Mage::helper('ewayrapid/customer')->updateToken($cardData['token_id'], $tokenInfo);
498
+ return $this;
499
+ } else {
500
+ Mage::throwException(
501
+ Mage::helper('ewayrapid')->__(
502
+ 'An error occurred while creating new token. Please try again. (Error message: %s)',
503
+ $res->getMessage()
504
+ )
505
+ );
506
+ }
507
+ }
508
+
509
+ /**
510
+ * Get card type name by card number
511
+ * @param $num Card number
512
+ * @return string Card type name
513
+ */
514
+ public function checkCardType($num)
515
+ {
516
+ if (preg_match('/^(4026|417500|4508|4844|4913|4917)/', $num)) {
517
+ return 'VE';
518
+ }
519
+ if (preg_match('/^4/', $num)) {
520
+ return 'VI';
521
+ }
522
+ if (preg_match('/^(34|37)/', $num)) {
523
+ return 'AE';
524
+ }
525
+ if (preg_match('/^(5[1-5])/', $num)) {
526
+ return 'MC';
527
+ }
528
+ if (preg_match('/^(2131|1800)/', $num)) {
529
+ return 'JCB';
530
+ }
531
+ if (preg_match('/^36/', $num)) {
532
+ return 'DC';
533
+ }
534
+ if (preg_match('/^(5018|5020|5038|5893|6304|6759|6761|6762|6763)/', $num)) {
535
+ return 'ME';
536
+ }
537
+
538
+ return 'Unknown';
539
+ }
540
+ /**
541
+ * Check Card Name
542
+ * @param $card Card Info
543
+ * @return string Card name: paypal | masterpass | mastercard
544
+ */
545
+ public function checkCardName($card)
546
+ {
547
+ $cardType = strtolower($card->getType());
548
+ if (preg_match('/^paypal/', $cardType)) {
549
+ return Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD;
550
+ }
551
+ $ccTypes = Mage::getSingleton('ewayrapid/system_config_source_cctype')->getAllowedTypes();
552
+ if (in_array(strtoupper($cardType), $ccTypes)) {
553
+ return Eway_Rapid31_Model_Config::CREDITCARD_METHOD;
554
+ }
555
+ return Eway_Rapid31_Model_Config::MASTERPASS_METHOD;
556
+ }
557
  }
app/code/community/Eway/Rapid31/Model/Request/Transparent.php CHANGED
@@ -1,752 +1,780 @@
1
- <?php
2
-
3
- class Eway_Rapid31_Model_Request_Transparent extends Eway_Rapid31_Model_Request_Abstract
4
- {
5
- /**
6
- * Get AccessCode
7
- *
8
- * @param Mage_Sales_Model_Quote $quote
9
- * @return Eway_Rapid31_Model_Response
10
- */
11
- public function createAccessCode(Mage_Sales_Model_Quote $quote, $method = 'ProcessPayment', $action = 'AccessCodes')
12
- {
13
- // Empty Varien_Object's data
14
- $this->unsetData();
15
-
16
- $billingAddress = $quote->getBillingAddress();
17
-
18
- $title = $this->_fixTitle($billingAddress->getPrefix());
19
-
20
- $customerParam = Mage::getModel('ewayrapid/field_customer');
21
- $customerParam->setTitle($title)
22
- ->setFirstName($billingAddress->getFirstname())
23
- ->setLastName($billingAddress->getLastname())
24
- ->setCompanyName($billingAddress->getCompany())
25
- ->setJobDescription($billingAddress->getJobDescription())
26
- ->setStreet1($billingAddress->getStreet1())
27
- ->setStreet2($billingAddress->getStreet2())
28
- ->setCity($billingAddress->getCity())
29
- ->setState($billingAddress->getRegion())
30
- ->setPostalCode($billingAddress->getPostcode())
31
- ->setCountry(strtolower($billingAddress->getCountryModel()->getIso2Code()))
32
- ->setEmail($billingAddress->getEmail())
33
- ->setPhone($billingAddress->getTelephone())
34
- ->setMobile($billingAddress->getMobile())
35
- ->setComments('')
36
- ->setFax($billingAddress->getFax())
37
- ->setUrl('');
38
-
39
- if ($this->getMethod() == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
40
- || ($this->getMethod() == Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD
41
- && Mage::getSingleton('core/session')->getSavedToken())
42
- ) {
43
- $customerTokenId = Mage::getSingleton('core/session')->getSavedToken();
44
- if (!$customerTokenId) {
45
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
46
- } elseif (is_numeric($customerTokenId)) {
47
- $customerHelper = Mage::helper('ewayrapid/customer');
48
- $customerTokenId = $customerHelper->getCustomerTokenId($customerTokenId);
49
- if ($customerTokenId) {
50
- $customerParam->setTokenCustomerID($customerTokenId);
51
- } else {
52
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
53
- }
54
- }
55
- }
56
-
57
- $this->setCustomer($customerParam);
58
-
59
- $shippingAddress = $quote->getShippingAddress();
60
-
61
- // copy BillingAddress to ShippingAddress if checkout with guest or register
62
- /**
63
- $checkoutMethod = $quote->getCheckoutMethod();
64
- if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST
65
- || $checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER
66
- ) {
67
- $shippingAddress = $billingAddress;
68
- }
69
- */
70
-
71
- if (!empty($shippingAddress)) {
72
- $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
73
- $shippingParam->setFirstName($shippingAddress->getFirstname())
74
- ->setLastName($shippingAddress->getLastname())
75
- ->setStreet1($shippingAddress->getStreet1())
76
- ->setStreet2($shippingAddress->getStreet2())
77
- ->setCity($shippingAddress->getCity())
78
- ->setState($shippingAddress->getRegion())
79
- ->setPostalCode($shippingAddress->getPostcode())
80
- ->setCountry(strtolower($shippingAddress->getCountryModel()->getIso2Code()))
81
- ->setEmail($shippingAddress->getEmail())
82
- ->setPhone($shippingAddress->getTelephone())
83
- ->setFax($shippingAddress->getFax());
84
- $this->setShippingAddress($shippingParam);
85
- }
86
-
87
- $paymentParam = Mage::getModel('ewayrapid/field_payment');
88
- $paymentParam->setTotalAmount(round($quote->getBaseGrandTotal() * 100));
89
- if ($method == 'CreateTokenCustomer' || $method == 'UpdateTokenCustomer') {
90
- $paymentParam->setTotalAmount(0);
91
- }
92
-
93
- // add InvoiceDescription and InvoiceReference
94
- $config = Mage::getModel('ewayrapid/config');
95
-
96
- if($config->shouldPassingInvoiceDescription()){
97
- $invoiceDescription = '';
98
- foreach($quote->getAllVisibleItems() as $item){
99
- // Check in case multi-shipping
100
- if (!$item->getQuoteParentItemId()) {
101
- $invoiceDescription .= (int) $item->getQty() . ' x ' .$item->getName() . ', ';
102
- }
103
- }
104
- $invoiceDescription = trim($invoiceDescription,', ');
105
- $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
106
-
107
- $paymentParam->setInvoiceDescription($invoiceDescription);
108
- }
109
-
110
- if($config->shouldPassingGuessOrder()){
111
- $incrementId = $this->_getIncrementOrderId($quote);
112
- $paymentParam->setInvoiceReference($incrementId);
113
- }
114
-
115
- $paymentParam->setCurrencyCode($quote->getBaseCurrencyCode());
116
- $this->setPayment($paymentParam);
117
-
118
- $returnUrl = Mage::getBaseUrl() . '/ewayrapid/transparent/callBack';
119
- $cancelUrl = Mage::getBaseUrl() . '/ewayrapid/transparent/cancel';
120
-
121
- $this->setRedirectUrl($returnUrl);
122
-
123
- //CheckOutUrl if using PayPal
124
- $checkOutUrl = Mage::getBaseUrl() . '/ewayrapid/transparent/review';
125
-
126
- if (Mage::helper('ewayrapid/data')->getTransferCartLineItems()) {
127
- // add Shipping item and Line items
128
- $lineItems = Mage::helper('ewayrapid')->getLineItems();
129
- $this->setItems($lineItems);
130
- }
131
-
132
- /*if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
133
- $this->setItems(false);
134
- }*/
135
-
136
- if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD) {
137
- $this->setCheckoutPayment(true);
138
- $this->setCheckoutURL($checkOutUrl);
139
- $this->setItems(false);
140
- }
141
-
142
- $this->setCancelUrl($cancelUrl);
143
- $this->setMethod($method);
144
- $this->setShippingMethod('Other');
145
- $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
146
- $version = Mage::helper('ewayrapid')->getExtensionVersion();
147
- $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
148
- if (Mage::helper('ewayrapid')->isBackendOrder()) {
149
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
150
- } else {
151
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
152
- }
153
- $this->setCustomerReadOnly(true);
154
-
155
- $response = $this->_doRapidAPI($action);
156
- if ($response->isSuccess()) {
157
- return $response;
158
- } else {
159
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
160
- $response->getMessage()));
161
- }
162
- }
163
-
164
- /**
165
- * Get customer information by access code
166
- * @param $accessCode
167
- * @throws Mage_Core_Exception
168
- */
169
- public function getInfoByAccessCode($accessCode)
170
- {
171
- $response = $this->_doRapidAPI('AccessCode/' . $accessCode, false);
172
- if ($response->isSuccess()) {
173
- return $response;
174
- } else {
175
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. Please try again. (Error message: %s)',
176
- $response->getMessage()));
177
- return false;
178
- }
179
- }
180
-
181
- public function getTransaction($accessCode)
182
- {
183
- try {
184
- $results = $this->_doRapidAPI("Transaction/$accessCode", 'GET');
185
- if ($results->isSuccess()) {
186
- return $results->getTransactions();
187
- }
188
- } catch (Exception $e) {
189
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
190
- $results->getMessage()));
191
- return false;
192
- }
193
- }
194
-
195
- /**
196
- * Update customer info
197
- * @param $transId
198
- * @return mixed
199
- */
200
- public function updateCustomer($accessCode, Mage_Sales_Model_Quote $quote)
201
- {
202
- try {
203
- $results = $this->_doRapidAPI("Transaction/$accessCode", 'GET');
204
- if (!$results->isSuccess()) {
205
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
206
- $results->getMessage()));
207
- }
208
-
209
- $customer = $quote->getCustomer();
210
- $billingAddress = $quote->getBillingAddress();
211
- $shippingAddress = $quote->getShippingAddress();
212
-
213
- if ($results->isSuccess()) {
214
- $trans = $results->getTransactions();
215
-
216
- if (isset($trans[0]['Customer'])) {
217
- $billing = $trans[0]['Customer'];
218
- $billingAddress->setFirstname($billing['FirstName'])
219
- ->setLastName($billing['LastName'])
220
- ->setCompany($billing['CompanyName'])
221
- ->setJobDescription($billing['JobDescription'])
222
- ->setStreet($billing['Street1'])
223
- ->setStreet2($billing['Street2'])
224
- ->setCity($billing['City'])
225
- ->setState($billing['State'])
226
- ->setPostcode($billing['PostalCode'])
227
- ->setCountryId(strtoupper($billing['Country']))
228
- ->setEmail($billing['Email'])
229
- ->setTelephone($billing['Phone'])
230
- ->setMobile($billing['Mobile'])
231
- ->setComments($billing['Comments'])
232
- ->setFax($billing['Fax'])
233
- ->setUrl($billing['Url']);
234
- }
235
- if (isset($trans[0]['ShippingAddress'])) {
236
- $shipping = $trans[0]['ShippingAddress'];
237
- $shippingAddress->setFirstname($shipping['FirstName'])
238
- ->setLastname($shipping['LastName'])
239
- ->setStreet($shipping['Street1'])
240
- ->setStreet2($shipping['Street2'])
241
- ->setCity($shipping['City'])
242
- ->setPostcode($shipping['PostalCode'])
243
- ->setCountryId(strtoupper($shipping['Country']))
244
- ->setEmail($shipping['Email'])
245
- ->setFax($shipping['Fax']);
246
-
247
- if ($shipping['State']
248
- && $shipping['Country']
249
- && $region = Mage::getModel('directory/region')->loadByCode($shipping['State'], $shipping['Country'])
250
- ) {
251
- $shippingAddress->setRegion($region->getName())
252
- ->setRegionId($region->getId());
253
- }
254
- if ($shipping['Phone']) {
255
- $shippingAddress->setTelephone($shipping['Phone']);
256
- }
257
- }
258
- return $quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress)->save();
259
- }
260
- return false;
261
- } catch (Exception $e) {
262
- Mage::throwException($e->getMessage());
263
- return false;
264
- }
265
- }
266
-
267
- /**
268
- * @param Mage_Sales_Model_Quote $quote
269
- * @param $tokenInfo
270
- * @param $tokenCustomerID
271
- * @return bool
272
- */
273
- public function addToken(Mage_Sales_Model_Quote $quote, $tokenInfo, $tokenCustomerID = 0)
274
- {
275
- try {
276
- if (!$tokenCustomerID)
277
- return false;
278
-
279
- //Get Customer Card Info
280
- $customerCard = $this->getCustomerCard($tokenCustomerID);
281
- $cardetail = null;
282
- if ($customerCard) {
283
- $customer = $customerCard->getCustomer();
284
- $cardetail = $customer && isset($customer['CardDetails']) ? $customer['CardDetails'] : null;
285
- unset($customer);
286
- }
287
-
288
- $billingAddress = $quote->getBillingAddress();
289
-
290
- $title = $this->_fixTitle($billingAddress->getPrefix());
291
-
292
- $customerParam = Mage::getModel('ewayrapid/field_customer');
293
- $customerParam->setTitle($title)
294
- ->setFirstName($billingAddress->getFirstname())
295
- ->setLastName($billingAddress->getLastname())
296
- ->setCompanyName($billingAddress->getCompany())
297
- ->setJobDescription($billingAddress->getJobDescription())
298
- ->setStreet1($billingAddress->getStreet1())
299
- ->setStreet2($billingAddress->getStreet2())
300
- ->setCity($billingAddress->getCity())
301
- ->setState($billingAddress->getRegion())
302
- ->setPostalCode($billingAddress->getPostcode())
303
- ->setCountry(strtolower($billingAddress->getCountryModel()->getIso2Code()))
304
- ->setEmail($billingAddress->getEmail())
305
- ->setPhone($billingAddress->getTelephone())
306
- ->setMobile($billingAddress->getMobile())
307
- ->setComments('')
308
- ->setFax($billingAddress->getFax())
309
- ->setUrl('');
310
- $config = Mage::getSingleton('ewayrapid/config');
311
- $cardNumber = null;
312
-
313
- if ($tokenInfo['SavedType'] == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
314
- $tokenInfo['ccType'] = "PayPal";
315
- $cardNumber = "PayPal";
316
- $tokenInfo['EWAY_CARDNAME'] = "PayPal";
317
- $tokenInfo['EWAY_CARDEXPIRYMONTH'] = $tokenInfo['EWAY_CARDEXPIRYYEAR'] = '';
318
- } elseif ($tokenInfo['SavedType'] == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
319
- //$tokenInfo['ccType'] = "MC";
320
- $cardNumber = $cardetail && isset($cardetail['Number']) ? substr_replace($cardetail['Number'], '******', 6, 6) : "MasterPass";
321
- $cardNumber = substr_replace($cardNumber, '******', 6, 6);
322
- $tokenInfo['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "MasterPass";
323
- $tokenInfo['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : "";
324
- $tokenInfo['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : "";
325
- } else {
326
- $cardNumber = $cardetail && isset($cardetail['Number']) ? $cardetail['Number'] : @Mage::helper('ewayrapid/data')->decryptSha256($tokenInfo['EWAY_CARDNUMBER'], $config->getBasicAuthenticationHeader());
327
- $cardNumber = substr_replace($cardNumber, '******', 6, 6);
328
- $tokenInfo['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "creditcard";
329
- $tokenInfo['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : "";
330
- $tokenInfo['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : "";
331
- }
332
- $type = isset($tokenInfo['ccType']) ? $tokenInfo['ccType'] : $this->checkCardType($cardNumber);
333
- if($type == 'Unknown') {
334
- $type = $tokenInfo['SavedType'] == Eway_Rapid31_Model_Config::MASTERPASS_METHOD ? 'MasterPass' : 'CreditCard';
335
- }
336
-
337
- $tokenInfo['EWAY_CARDEXPIRYYEAR'] = $tokenInfo['EWAY_CARDEXPIRYYEAR'] && strlen($tokenInfo['EWAY_CARDEXPIRYYEAR']) == 2 ? '20' . $tokenInfo['EWAY_CARDEXPIRYYEAR'] : $cardetail['EWAY_CARDEXPIRYYEAR'];
338
- $cardInfo = array(
339
- 'Token' => $tokenCustomerID,
340
- 'TokenCustomerID' => $tokenCustomerID,
341
- 'Card' => $cardNumber,
342
- 'Owner' => $tokenInfo['EWAY_CARDNAME'],
343
- 'StartMonth' => '',
344
- 'StartYear' => '',
345
- 'IssueNumber' => '',
346
- 'ExpMonth' => (int)$tokenInfo['EWAY_CARDEXPIRYMONTH'],
347
- 'ExpYear' => (int)$tokenInfo['EWAY_CARDEXPIRYYEAR'],
348
- 'Type' => $type,
349
- 'Address' => $customerParam,
350
- );
351
-
352
- Mage::helper('ewayrapid/customer')->addToken($cardInfo);
353
- return true;
354
- } catch (Exception $e) {
355
- return false;
356
- }
357
- }
358
-
359
- /**
360
- * @param $id
361
- * @param $info
362
- * @return bool
363
- */
364
- public function updateToken($id, $info = null)
365
- {
366
- try {
367
- //Get Customer Card Info
368
- $customerCard = $this->getCustomerCard($id);
369
- $cardetail = null;
370
- if ($customerCard) {
371
- $customer = $customerCard->getCustomer();
372
- $cardetail = $customer && isset($customer['CardDetails']) ? $customer['CardDetails'] : null;
373
- unset($customer);
374
- }
375
- $cardetail['ExpiryYear'] = $cardetail['ExpiryYear'] && strlen($cardetail['ExpiryYear']) == 2 ? '20' . $cardetail['ExpiryYear'] : $cardetail['ExpiryYear'];
376
-
377
- if ($info['SavedType'] == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
378
- $tokenInfo['EWAY_CARDNAME'] = "PayPal";
379
- } elseif ($info['SavedType'] == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
380
- $info['ccType'] = "MC";
381
- $info['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "MasterPass";
382
- $info['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : "";
383
- $info['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : "";
384
- } else {
385
- $info['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "PayPal";
386
- $info['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : $info['EWAY_CARDEXPIRYMONTH'];
387
- $info['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : $info['EWAY_CARDEXPIRYYEAR'];
388
- }
389
-
390
- $cardInfo = array(
391
- 'Owner' => $info['EWAY_CARDNAME'],
392
- 'StartMonth' => '',
393
- 'StartYear' => '',
394
- 'IssueNumber' => '',
395
- 'ExpMonth' => $info ? (int)$info['EWAY_CARDEXPIRYMONTH'] : '',
396
- 'ExpYear' => $info ? (int)$info['EWAY_CARDEXPIRYYEAR'] : '',
397
- );
398
-
399
- if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
400
- $uid = Mage::getSingleton('core/session')->getPaypalSavedToken();
401
- } elseif ($this->getTransMethod() == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
402
- $uid = Mage::getSingleton('core/session')->getMasterpassSavedToken();
403
- } else {
404
- $uid = Mage::getSingleton('core/session')->getSavedToken();
405
- }
406
-
407
- Mage::helper('ewayrapid/customer')->updateToken($uid, $cardInfo);
408
- return true;
409
- } catch (Exception $e) {
410
- return false;
411
- }
412
- }
413
-
414
- /**
415
- * Get card type name by card number
416
- * @param $num Card number
417
- * @return string Card type name
418
- */
419
- public function checkCardType($num)
420
- {
421
- return Mage::getModel('ewayrapid/request_token')->checkCardType($num);
422
- }
423
-
424
- /**
425
- * @param Mage_Sales_Model_Order_Payment $payment
426
- * @return bool
427
- */
428
- public function setTransaction(Mage_Sales_Model_Order_Payment $payment)
429
- {
430
- $payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
431
- $payment->setIsTransactionClosed(0);
432
- return $payment;
433
- }
434
-
435
- /**
436
- * Get shipping by code
437
- *
438
- * @param Mage_Sales_Model_Quote $quote
439
- * @param $postalCode
440
- * @return bool
441
- */
442
- public function getShippingByCode(Mage_Sales_Model_Quote $quote, $postalCode)
443
- {
444
- $groups = $quote->getShippingAddress()->collectShippingRates()->getGroupedAllShippingRates();
445
- // determine current selected code & name
446
- foreach ($groups as $code => $rates) {
447
- foreach ($rates as $rate) {
448
- if (strtoupper($postalCode) == strtoupper($rate->getCode())) {
449
- return $rate;
450
- }
451
- }
452
- }
453
- return false;
454
- }
455
-
456
- /**
457
- * Call Transaction API (Authorized & Capture at the same time)
458
- *
459
- * @param Mage_Sales_Model_Order_Payment $payment
460
- * @param float $amount
461
- * @return Eway_Rapid31_Model_Request_Direct $this
462
- */
463
- public function doTransaction(Mage_Sales_Model_Quote $quote, $amount)
464
- {
465
- $this->_buildRequest($quote, $amount);
466
- $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
467
- $response = $this->_doRapidAPI('Transaction');
468
-
469
- if ($response->isSuccess()) {
470
- $quote->setTransactionId($response->getTransactionID());
471
- $quote->setCcLast4($response->getCcLast4());
472
- $quote->save();
473
- return $quote;
474
- } else {
475
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. Please try again. (Error message: %s)',
476
- $response->getMessage()));
477
- }
478
- }
479
-
480
- /**
481
- * Call Authorisation API (Authorized only)
482
- *
483
- * @param Mage_Sales_Model_Order_Payment $payment
484
- * @param $amount
485
- * @return Eway_Rapid31_Model_Request_Direct
486
- */
487
- public function doAuthorisation(Mage_Sales_Model_Quote $quote, $amount)
488
- {
489
- $this->_buildRequest($quote, $amount);
490
- $this->setMethod(Eway_Rapid31_Model_Config::METHOD_AUTHORISE);
491
- $response = $this->_doRapidAPI('Authorisation');
492
- if ($response->isSuccess()) {
493
- $quote->setTransactionId($response->getTransactionID());
494
- $quote->setIsTransactionClosed(0);
495
- $quote->setCcLast4($response->getCcLast4());
496
- $beagleScore = $response->getBeagleScore() ? $response->getBeagleScore() : '';
497
- $quote->setBeagleScore($beagleScore);
498
- $quote->setBeagleVerification($response->getBeagleVerification());
499
- $quote->save();
500
- return $quote;
501
- } else {
502
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the authorisation. Please try again. (Error message: %s)',
503
- $response->getMessage()));
504
- }
505
- }
506
-
507
- /**
508
- * Call Capture API (do the Capture only, must Authorized previously)
509
- *
510
- * @param Mage_Sales_Model_Order_Payment $payment
511
- * @param $amount
512
- * @return Eway_Rapid31_Model_Request_Direct
513
- */
514
- public function doCapturePayment(Mage_Sales_Model_Quote $quote, $amount)
515
- {
516
- // Empty Varien_Object's data
517
- $this->unsetData();
518
-
519
- $paymentParam = Mage::getModel('ewayrapid/field_payment');
520
- $paymentParam->setTotalAmount($amount)
521
- ->setCurrencyCode($quote->getBaseCurrencyCode());
522
-
523
- $this->setPayment($paymentParam);
524
- $this->setTransactionId($quote->getTransactionId());
525
- $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
526
- $response = $this->_doRapidAPI('CapturePayment');
527
-
528
- if ($response->isSuccess()) {
529
- $quote->setTransactionId($response->getTransactionID());
530
- $quote->save();
531
- return $quote;
532
- } else {
533
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the capture. Please try again. (Error message: %s)',
534
- $response->getMessage()));
535
- }
536
- }
537
-
538
- /**
539
- * Build the request with necessary parameters for doAuthorisation() and doTransaction()
540
- *
541
- * @param Mage_Sales_Model_Order_Payment $payment
542
- * @param $amount
543
- * @return Eway_Rapid31_Model_Request_Direct
544
- */
545
- protected function _buildRequest(Mage_Sales_Model_Quote $quote, $amount)
546
- {
547
- // Empty Varien_Object's data
548
- $this->unsetData();
549
-
550
- $billing = $quote->getBillingAddress();
551
- $shipping = $quote->getShippingAddress();
552
-
553
- // copy BillingAddress to ShippingAddress if checkout with guest or register
554
- $checkoutMethod = $quote->getCheckoutMethod();
555
- if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST
556
- || $checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER
557
- ) {
558
- $shipping = $billing;
559
- }
560
-
561
- $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
562
- if (Mage::helper('ewayrapid')->isBackendOrder()) {
563
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
564
- } else {
565
- $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
566
- }
567
- $version = Mage::helper('ewayrapid')->getExtensionVersion();
568
- $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
569
- $this->setShippingMethod('Other');
570
-
571
- $paymentParam = Mage::getModel('ewayrapid/field_payment');
572
- $paymentParam->setTotalAmount($amount);
573
- $paymentParam->setCurrencyCode($quote->getBaseCurrencyCode());
574
-
575
- // add InvoiceDescription and InvoiceReference
576
- $config = Mage::getModel('ewayrapid/config');
577
-
578
- if($config->shouldPassingInvoiceDescription()){
579
- $invoiceDescription = '';
580
- foreach($quote->getAllVisibleItems() as $item){
581
- // Check in case multi-shipping
582
- if (!$item->getQuoteParentItemId()) {
583
- $invoiceDescription .= (int) $item->getQty() . ' x ' .$item->getName() . ', ';
584
- }
585
- }
586
- $invoiceDescription = trim($invoiceDescription,', ');
587
- $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
588
-
589
- $paymentParam->setInvoiceDescription($invoiceDescription);
590
- }
591
-
592
- if($config->shouldPassingGuessOrder()){
593
- $incrementId = $this->_getIncrementOrderId($quote);
594
- $paymentParam->setInvoiceReference($incrementId);
595
- }
596
-
597
- $this->setPayment($paymentParam);
598
-
599
- $title = $this->_fixTitle($billing->getPrefix());
600
-
601
- $customerParam = Mage::getModel('ewayrapid/field_customer');
602
- $customerParam->setTitle($title)
603
- ->setFirstName($billing->getFirstname())
604
- ->setLastName($billing->getLastname())
605
- ->setCompanyName($billing->getCompany())
606
- ->setJobDescription('')
607
- ->setStreet1($billing->getStreet1())
608
- ->setStreet2($billing->getStreet2())
609
- ->setCity($billing->getCity())
610
- ->setState($billing->getRegion())
611
- ->setPostalCode($billing->getPostcode())
612
- ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
613
- ->setEmail($billing->getEmail())
614
- ->setPhone($billing->getTelephone())
615
- ->setMobile('')
616
- ->setComments('')
617
- ->setFax($billing->getFax())
618
- ->setUrl('');
619
-
620
- $infoCard = Mage::getSingleton('core/session')->getInfoCard();
621
- if ($infoCard && $infoCard->getCard() && $infoCard->getOwner() && !$this->getTokenInfo()) {
622
- $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
623
- $cardDetails->setName($infoCard->getOwner())
624
- ->setNumber($infoCard->getCard())
625
- ->setExpiryMonth($infoCard->getExpMonth())
626
- ->setExpiryYear($infoCard->getExpYear())
627
- ->setCVN($infoCard->getCid());
628
- $customerParam->setCardDetails($cardDetails);
629
- }
630
-
631
- if ($quote->getTokenCustomerID()) {
632
- $customerParam->setTokenCustomerID($quote->getTokenCustomerID());
633
- } elseif ($token = $this->getTokenInfo()) {
634
- $customerParam->setTokenCustomerID($token->getToken() ? $token->getToken() : $token->getTokenCustomerID());
635
- }
636
-
637
- $this->setCustomer($customerParam);
638
-
639
- if (!empty($shipping)) {
640
- $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
641
- $shippingParam->setFirstName($shipping->getFirstname())
642
- ->setLastName($shipping->getLastname())
643
- ->setStreet1($shipping->getStreet1())
644
- ->setStreet2($shipping->getStreet2())
645
- ->setCity($shipping->getCity())
646
- ->setState($shipping->getRegion())
647
- ->setPostalCode($shipping->getPostcode())
648
- ->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))
649
- ->setEmail($shipping->getEmail())
650
- ->setPhone($shipping->getTelephone())
651
- ->setFax($shipping->getFax());
652
- $this->setShippingAddress($shippingParam);
653
- }
654
-
655
- $orderItems = $quote->getAllVisibleItems();
656
- $lineItems = array();
657
- foreach ($orderItems as $orderItem) {
658
- /* @var Mage_Sales_Model_Order_Item $orderItem */
659
- $lineItem = Mage::getModel('ewayrapid/field_lineItem');
660
- $lineItem->setSKU($orderItem->getSku());
661
- $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
662
- $lineItem->setQuantity($orderItem->getQtyOrdered());
663
- $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
664
- $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
665
- $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
666
- $lineItems[] = $lineItem;
667
- }
668
- $this->setItems($lineItems);
669
- if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
670
- $this->setItems(false);
671
- }
672
-
673
- return $this;
674
- }
675
-
676
- /**
677
- * @param $tokenCustomerID
678
- * @throws Mage_Core_Exception
679
- */
680
- public function getCustomerCard($tokenCustomerID)
681
- {
682
- // Empty Varien_Object's data
683
- $this->unsetData();
684
-
685
- $customerParam = Mage::getModel('ewayrapid/field_customer');
686
-
687
- if ($tokenCustomerID) {
688
- $customerParam->setTokenCustomerID($tokenCustomerID);
689
- } else {
690
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
691
- }
692
- $this->setCustomer($customerParam);
693
-
694
- $response = $this->_doRapidAPI('Customer', 'PUT');
695
- if ($response->isSuccess()) {
696
- return $response;
697
- } else {
698
- return false;
699
- }
700
- }
701
-
702
- public function getMethod()
703
- {
704
- return Mage::getSingleton('core/session')->getMethod();
705
- }
706
-
707
- /**
708
- * @return mixed
709
- */
710
- public function getTransMethod()
711
- {
712
- $transMethod = Mage::getSingleton('core/session')->getTransparentNotsaved();
713
- if (!$transMethod) {
714
- $transMethod = Mage::getSingleton('core/session')->getTransparentSaved();
715
- }
716
- return $transMethod;
717
- }
718
-
719
- /**
720
- * @return mixed
721
- */
722
- public function getTokenInfo()
723
- {
724
- if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
725
- $uid = Mage::getSingleton('core/session')->getPaypalSavedToken();
726
- } elseif ($this->getTransMethod() == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
727
- $uid = Mage::getSingleton('core/session')->getMasterpassSavedToken();
728
- } else {
729
- $uid = Mage::getSingleton('core/session')->getSavedToken();
730
- }
731
- if ($uid && $uid != Eway_Rapid31_Model_Config::TOKEN_NEW)
732
- return Mage::helper('ewayrapid/customer')->getTokenById($uid);
733
- return false;
734
- }
735
-
736
- /**
737
- *
738
- */
739
- public function unsetSessionData()
740
- {
741
- Mage::getSingleton('core/session')->unsTransparentNotsaved();
742
- Mage::getSingleton('core/session')->unsTransparentSaved();
743
- Mage::getSingleton('core/session')->unsSavedToken();
744
- Mage::getSingleton('core/session')->unsTransactionId();
745
- Mage::getSingleton('core/session')->unsFormActionUrl();
746
- Mage::getSingleton('core/session')->unsPaypalSavedToken();
747
- Mage::getSingleton('core/session')->unsMethod();
748
- Mage::getSingleton('core/session')->unsCompleteCheckoutURL();
749
- Mage::getSingleton('core/session')->unsMasterPassSavedToken();
750
- Mage::getSingleton('core/session')->unsInfoCard();
751
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
752
  }
1
+ <?php
2
+
3
+ class Eway_Rapid31_Model_Request_Transparent extends Eway_Rapid31_Model_Request_Abstract
4
+ {
5
+ /**
6
+ * Get AccessCode
7
+ *
8
+ * @param Mage_Sales_Model_Quote $quote
9
+ * @return Eway_Rapid31_Model_Response
10
+ */
11
+ public function createAccessCode(Mage_Sales_Model_Quote $quote, $method = 'ProcessPayment', $action = 'AccessCodes')
12
+ {
13
+ // Empty Varien_Object's data
14
+ $this->unsetData();
15
+
16
+ $billingAddress = $quote->getBillingAddress();
17
+
18
+ $title = $this->_fixTitle($billingAddress->getPrefix());
19
+
20
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
21
+ $customerParam->setTitle($title)
22
+ ->setFirstName($billingAddress->getFirstname())
23
+ ->setLastName($billingAddress->getLastname())
24
+ ->setCompanyName($billingAddress->getCompany())
25
+ ->setJobDescription($billingAddress->getJobDescription())
26
+ ->setStreet1($billingAddress->getStreet1())
27
+ ->setStreet2($billingAddress->getStreet2())
28
+ ->setCity($billingAddress->getCity())
29
+ ->setState($billingAddress->getRegion())
30
+ ->setPostalCode($billingAddress->getPostcode())
31
+ ->setCountry(strtolower($billingAddress->getCountryModel()->getIso2Code()))
32
+ ->setEmail($billingAddress->getEmail())
33
+ ->setPhone($billingAddress->getTelephone())
34
+ ->setMobile($billingAddress->getMobile())
35
+ ->setComments('')
36
+ ->setFax($billingAddress->getFax())
37
+ ->setUrl('');
38
+
39
+ if ($this->getMethod() == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
40
+ || ($this->getMethod() == Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD
41
+ && Mage::getSingleton('core/session')->getSavedToken())
42
+ ) {
43
+ $customerTokenId = Mage::getSingleton('core/session')->getSavedToken();
44
+ if (!$customerTokenId) {
45
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
46
+ } elseif (is_numeric($customerTokenId)) {
47
+ $customerHelper = Mage::helper('ewayrapid/customer');
48
+ $customerTokenId = $customerHelper->getCustomerTokenId($customerTokenId);
49
+ if ($customerTokenId) {
50
+ $customerParam->setTokenCustomerID($customerTokenId);
51
+ } else {
52
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
53
+ }
54
+ }
55
+ }
56
+
57
+ $this->setCustomer($customerParam);
58
+
59
+ $shippingAddress = $quote->getShippingAddress();
60
+
61
+ // copy BillingAddress to ShippingAddress if checkout with guest or register
62
+ /**
63
+ $checkoutMethod = $quote->getCheckoutMethod();
64
+ if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST
65
+ || $checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER
66
+ ) {
67
+ $shippingAddress = $billingAddress;
68
+ }
69
+ */
70
+
71
+ if (!empty($shippingAddress)) {
72
+ $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
73
+ $shippingParam->setFirstName($shippingAddress->getFirstname())
74
+ ->setLastName($shippingAddress->getLastname())
75
+ ->setStreet1($shippingAddress->getStreet1())
76
+ ->setStreet2($shippingAddress->getStreet2())
77
+ ->setCity($shippingAddress->getCity())
78
+ ->setState($shippingAddress->getRegion())
79
+ ->setPostalCode($shippingAddress->getPostcode())
80
+ ->setCountry(strtolower($shippingAddress->getCountryModel()->getIso2Code()))
81
+ ->setEmail($shippingAddress->getEmail())
82
+ ->setPhone($shippingAddress->getTelephone())
83
+ ->setFax($shippingAddress->getFax());
84
+ $this->setShippingAddress($shippingParam);
85
+ }
86
+
87
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
88
+ $paymentParam->setTotalAmount(round($quote->getBaseGrandTotal() * 100));
89
+ if ($method == 'CreateTokenCustomer' || $method == 'UpdateTokenCustomer') {
90
+ $paymentParam->setTotalAmount(0);
91
+ }
92
+
93
+ // add InvoiceDescription and InvoiceReference
94
+ $config = Mage::getModel('ewayrapid/config');
95
+
96
+ if ($config->shouldPassingInvoiceDescription()) {
97
+ $invoiceDescription = '';
98
+ foreach ($quote->getAllVisibleItems() as $item) {
99
+ // Check in case multi-shipping
100
+ if (!$item->getQuoteParentItemId()) {
101
+ $invoiceDescription .= (int) $item->getQty() . ' x ' .$item->getName() . ', ';
102
+ }
103
+ }
104
+ $invoiceDescription = trim($invoiceDescription, ', ');
105
+ $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
106
+
107
+ $paymentParam->setInvoiceDescription($invoiceDescription);
108
+ }
109
+
110
+ if ($config->shouldPassingGuessOrder()) {
111
+ $incrementId = $this->_getIncrementOrderId($quote);
112
+ $paymentParam->setInvoiceReference($incrementId);
113
+ }
114
+
115
+ $paymentParam->setCurrencyCode($quote->getBaseCurrencyCode());
116
+ $this->setPayment($paymentParam);
117
+
118
+ $returnUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . '/ewayrapid/transparent/callBack';
119
+ $cancelUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . '/ewayrapid/transparent/cancel';
120
+
121
+ $this->setRedirectUrl($returnUrl);
122
+
123
+ //CheckOutUrl if using PayPal
124
+ $checkOutUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . '/ewayrapid/transparent/review';
125
+
126
+ if (Mage::helper('ewayrapid/data')->getTransferCartLineItems()) {
127
+ // add Shipping item and Line items
128
+ $lineItems = Mage::helper('ewayrapid')->getLineItems();
129
+ $this->setItems($lineItems);
130
+ }
131
+
132
+ /*if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
133
+ $this->setItems(false);
134
+ }*/
135
+
136
+ if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD) {
137
+ $this->setCheckoutPayment(true);
138
+ $this->setCheckoutURL($checkOutUrl);
139
+ $this->setItems(false);
140
+ }
141
+
142
+ $this->setCancelUrl($cancelUrl);
143
+ $this->setMethod($method);
144
+ $this->setShippingMethod('Other');
145
+ $version = Mage::helper('ewayrapid')->getExtensionVersion();
146
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
147
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
148
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
149
+ } else {
150
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
151
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
152
+ }
153
+ $this->setCustomerReadOnly(true);
154
+
155
+ $response = $this->_doRapidAPI($action);
156
+ if ($response->isSuccess()) {
157
+ return $response;
158
+ } else {
159
+ Mage::throwException(
160
+ Mage::helper('ewayrapid')->__(
161
+ 'An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
162
+ $response->getMessage()
163
+ )
164
+ );
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Get customer information by access code
170
+ * @param $accessCode
171
+ * @throws Mage_Core_Exception
172
+ */
173
+ public function getInfoByAccessCode($accessCode)
174
+ {
175
+ $response = $this->_doRapidAPI('AccessCode/' . $accessCode, false);
176
+ if ($response->isSuccess()) {
177
+ return $response;
178
+ } else {
179
+ Mage::throwException(
180
+ Mage::helper('ewayrapid')->__(
181
+ 'An error occurred while making the transaction. Please try again. (Error message: %s)',
182
+ $response->getMessage()
183
+ )
184
+ );
185
+ return false;
186
+ }
187
+ }
188
+
189
+ public function getTransaction($accessCode)
190
+ {
191
+ try {
192
+ $results = $this->_doRapidAPI("Transaction/$accessCode", 'GET');
193
+ if ($results->isSuccess()) {
194
+ return $results->getTransactions();
195
+ }
196
+ } catch (Exception $e) {
197
+ Mage::throwException(
198
+ Mage::helper('ewayrapid')->__(
199
+ 'An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
200
+ $results->getMessage()
201
+ )
202
+ );
203
+ return false;
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Update customer info
209
+ * @param $transId
210
+ * @return mixed
211
+ */
212
+ public function updateCustomer($accessCode, Mage_Sales_Model_Quote $quote)
213
+ {
214
+ try {
215
+ $results = $this->_doRapidAPI("Transaction/$accessCode", 'GET');
216
+ if (!$results->isSuccess()) {
217
+ Mage::throwException(
218
+ Mage::helper('ewayrapid')->__(
219
+ 'An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
220
+ $results->getMessage()
221
+ )
222
+ );
223
+ }
224
+
225
+ $customer = $quote->getCustomer();
226
+ $billingAddress = $quote->getBillingAddress();
227
+ $shippingAddress = $quote->getShippingAddress();
228
+
229
+ if ($results->isSuccess()) {
230
+ $trans = $results->getTransactions();
231
+
232
+ if (isset($trans[0]['Customer'])) {
233
+ $billing = $trans[0]['Customer'];
234
+ $billingAddress->setFirstname($billing['FirstName'])
235
+ ->setLastName($billing['LastName'])
236
+ ->setCompany($billing['CompanyName'])
237
+ ->setJobDescription($billing['JobDescription'])
238
+ ->setStreet($billing['Street1'])
239
+ ->setStreet2($billing['Street2'])
240
+ ->setCity($billing['City'])
241
+ ->setState($billing['State'])
242
+ ->setPostcode($billing['PostalCode'])
243
+ ->setCountryId(strtoupper($billing['Country']))
244
+ ->setEmail($billing['Email'])
245
+ ->setTelephone($billing['Phone'])
246
+ ->setMobile($billing['Mobile'])
247
+ ->setComments($billing['Comments'])
248
+ ->setFax($billing['Fax'])
249
+ ->setUrl($billing['Url']);
250
+ }
251
+ if (isset($trans[0]['ShippingAddress'])) {
252
+ $shipping = $trans[0]['ShippingAddress'];
253
+ $shippingAddress->setFirstname($shipping['FirstName'])
254
+ ->setLastname($shipping['LastName'])
255
+ ->setStreet($shipping['Street1'])
256
+ ->setStreet2($shipping['Street2'])
257
+ ->setCity($shipping['City'])
258
+ ->setPostcode($shipping['PostalCode'])
259
+ ->setCountryId(strtoupper($shipping['Country']))
260
+ ->setEmail($shipping['Email'])
261
+ ->setFax($shipping['Fax']);
262
+
263
+ if ($shipping['State']
264
+ && $shipping['Country']
265
+ && $region = Mage::getModel('directory/region')->loadByCode($shipping['State'], $shipping['Country'])
266
+ ) {
267
+ $shippingAddress->setRegion($region->getName())
268
+ ->setRegionId($region->getId());
269
+ }
270
+ if ($shipping['Phone']) {
271
+ $shippingAddress->setTelephone($shipping['Phone']);
272
+ }
273
+ }
274
+ return $quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress)->save();
275
+ }
276
+ return false;
277
+ } catch (Exception $e) {
278
+ Mage::throwException($e->getMessage());
279
+ return false;
280
+ }
281
+ }
282
+
283
+ /**
284
+ * @param Mage_Sales_Model_Quote $quote
285
+ * @param $tokenInfo
286
+ * @param $tokenCustomerID
287
+ * @return bool
288
+ */
289
+ public function addToken(Mage_Sales_Model_Quote $quote, $tokenInfo, $tokenCustomerID = 0)
290
+ {
291
+ try {
292
+ if (!$tokenCustomerID)
293
+ return false;
294
+
295
+ //Get Customer Card Info
296
+ $customerCard = $this->getCustomerCard($tokenCustomerID);
297
+ $cardetail = null;
298
+ if ($customerCard) {
299
+ $customer = $customerCard->getCustomer();
300
+ $cardetail = $customer && isset($customer['CardDetails']) ? $customer['CardDetails'] : null;
301
+ unset($customer);
302
+ }
303
+
304
+ $billingAddress = $quote->getBillingAddress();
305
+
306
+ $title = $this->_fixTitle($billingAddress->getPrefix());
307
+
308
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
309
+ $customerParam->setTitle($title)
310
+ ->setFirstName($billingAddress->getFirstname())
311
+ ->setLastName($billingAddress->getLastname())
312
+ ->setCompanyName($billingAddress->getCompany())
313
+ ->setJobDescription($billingAddress->getJobDescription())
314
+ ->setStreet1($billingAddress->getStreet1())
315
+ ->setStreet2($billingAddress->getStreet2())
316
+ ->setCity($billingAddress->getCity())
317
+ ->setState($billingAddress->getRegion())
318
+ ->setPostalCode($billingAddress->getPostcode())
319
+ ->setCountry(strtolower($billingAddress->getCountryModel()->getIso2Code()))
320
+ ->setEmail($billingAddress->getEmail())
321
+ ->setPhone($billingAddress->getTelephone())
322
+ ->setMobile($billingAddress->getMobile())
323
+ ->setComments('')
324
+ ->setFax($billingAddress->getFax())
325
+ ->setUrl('');
326
+ $config = Mage::getSingleton('ewayrapid/config');
327
+ $cardNumber = null;
328
+
329
+ if ($tokenInfo['SavedType'] == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
330
+ $tokenInfo['ccType'] = "PayPal";
331
+ $cardNumber = "PayPal";
332
+ $tokenInfo['EWAY_CARDNAME'] = "PayPal";
333
+ $tokenInfo['EWAY_CARDEXPIRYMONTH'] = $tokenInfo['EWAY_CARDEXPIRYYEAR'] = '';
334
+ } elseif ($tokenInfo['SavedType'] == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
335
+ //$tokenInfo['ccType'] = "MC";
336
+ $cardNumber = $cardetail && isset($cardetail['Number']) ? substr_replace($cardetail['Number'], '******', 6, 6) : "MasterPass";
337
+ $cardNumber = substr_replace($cardNumber, '******', 6, 6);
338
+ $tokenInfo['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "MasterPass";
339
+ $tokenInfo['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : "";
340
+ $tokenInfo['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : "";
341
+ } else {
342
+ $cardNumber = $cardetail && isset($cardetail['Number']) ? $cardetail['Number'] : @Mage::helper('ewayrapid/data')->decryptSha256($tokenInfo['EWAY_CARDNUMBER'], $config->getBasicAuthenticationHeader());
343
+ $cardNumber = substr_replace($cardNumber, '******', 6, 6);
344
+ $tokenInfo['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "creditcard";
345
+ $tokenInfo['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : "";
346
+ $tokenInfo['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : "";
347
+ }
348
+ $type = isset($tokenInfo['ccType']) ? $tokenInfo['ccType'] : $this->checkCardType($cardNumber);
349
+ if ($type == 'Unknown') {
350
+ $type = $tokenInfo['SavedType'] == Eway_Rapid31_Model_Config::MASTERPASS_METHOD ? 'MasterPass' : 'CreditCard';
351
+ }
352
+
353
+ $tokenInfo['EWAY_CARDEXPIRYYEAR'] = $tokenInfo['EWAY_CARDEXPIRYYEAR'] && strlen($tokenInfo['EWAY_CARDEXPIRYYEAR']) == 2 ? '20' . $tokenInfo['EWAY_CARDEXPIRYYEAR'] : $cardetail['EWAY_CARDEXPIRYYEAR'];
354
+ $cardInfo = array(
355
+ 'Token' => $tokenCustomerID,
356
+ 'TokenCustomerID' => $tokenCustomerID,
357
+ 'Card' => $cardNumber,
358
+ 'Owner' => $tokenInfo['EWAY_CARDNAME'],
359
+ 'StartMonth' => '',
360
+ 'StartYear' => '',
361
+ 'IssueNumber' => '',
362
+ 'ExpMonth' => (int)$tokenInfo['EWAY_CARDEXPIRYMONTH'],
363
+ 'ExpYear' => (int)$tokenInfo['EWAY_CARDEXPIRYYEAR'],
364
+ 'Type' => $type,
365
+ 'Address' => $customerParam,
366
+ );
367
+
368
+ Mage::helper('ewayrapid/customer')->addToken($cardInfo);
369
+ return true;
370
+ } catch (Exception $e) {
371
+ return false;
372
+ }
373
+ }
374
+
375
+ /**
376
+ * @param $id
377
+ * @param $info
378
+ * @return bool
379
+ */
380
+ public function updateToken($id, $info = null)
381
+ {
382
+ try {
383
+ //Get Customer Card Info
384
+ $customerCard = $this->getCustomerCard($id);
385
+ $cardetail = null;
386
+ if ($customerCard) {
387
+ $customer = $customerCard->getCustomer();
388
+ $cardetail = $customer && isset($customer['CardDetails']) ? $customer['CardDetails'] : null;
389
+ unset($customer);
390
+ }
391
+ $cardetail['ExpiryYear'] = $cardetail['ExpiryYear'] && strlen($cardetail['ExpiryYear']) == 2 ? '20' . $cardetail['ExpiryYear'] : $cardetail['ExpiryYear'];
392
+
393
+ if ($info['SavedType'] == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
394
+ $tokenInfo['EWAY_CARDNAME'] = "PayPal";
395
+ } elseif ($info['SavedType'] == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
396
+ $info['ccType'] = "MC";
397
+ $info['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "MasterPass";
398
+ $info['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : "";
399
+ $info['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : "";
400
+ } else {
401
+ $info['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "PayPal";
402
+ $info['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : $info['EWAY_CARDEXPIRYMONTH'];
403
+ $info['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : $info['EWAY_CARDEXPIRYYEAR'];
404
+ }
405
+
406
+ $cardInfo = array(
407
+ 'Owner' => $info['EWAY_CARDNAME'],
408
+ 'StartMonth' => '',
409
+ 'StartYear' => '',
410
+ 'IssueNumber' => '',
411
+ 'ExpMonth' => $info ? (int)$info['EWAY_CARDEXPIRYMONTH'] : '',
412
+ 'ExpYear' => $info ? (int)$info['EWAY_CARDEXPIRYYEAR'] : '',
413
+ );
414
+
415
+ if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
416
+ $uid = Mage::getSingleton('core/session')->getPaypalSavedToken();
417
+ } elseif ($this->getTransMethod() == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
418
+ $uid = Mage::getSingleton('core/session')->getMasterpassSavedToken();
419
+ } else {
420
+ $uid = Mage::getSingleton('core/session')->getSavedToken();
421
+ }
422
+
423
+ Mage::helper('ewayrapid/customer')->updateToken($uid, $cardInfo);
424
+ return true;
425
+ } catch (Exception $e) {
426
+ return false;
427
+ }
428
+ }
429
+
430
+ /**
431
+ * Get card type name by card number
432
+ * @param $num Card number
433
+ * @return string Card type name
434
+ */
435
+ public function checkCardType($num)
436
+ {
437
+ return Mage::getModel('ewayrapid/request_token')->checkCardType($num);
438
+ }
439
+
440
+ /**
441
+ * @param Mage_Sales_Model_Order_Payment $payment
442
+ * @return bool
443
+ */
444
+ public function setTransaction(Mage_Sales_Model_Order_Payment $payment)
445
+ {
446
+ $payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
447
+ $payment->setIsTransactionClosed(0);
448
+ return $payment;
449
+ }
450
+
451
+ /**
452
+ * Get shipping by code
453
+ *
454
+ * @param Mage_Sales_Model_Quote $quote
455
+ * @param $postalCode
456
+ * @return bool
457
+ */
458
+ public function getShippingByCode(Mage_Sales_Model_Quote $quote, $postalCode)
459
+ {
460
+ $groups = $quote->getShippingAddress()->collectShippingRates()->getGroupedAllShippingRates();
461
+ // determine current selected code & name
462
+ foreach ($groups as $code => $rates) {
463
+ foreach ($rates as $rate) {
464
+ if (strtoupper($postalCode) == strtoupper($rate->getCode())) {
465
+ return $rate;
466
+ }
467
+ }
468
+ }
469
+ return false;
470
+ }
471
+
472
+ /**
473
+ * Call Transaction API (Authorized & Capture at the same time)
474
+ *
475
+ * @param Mage_Sales_Model_Order_Payment $payment
476
+ * @param float $amount
477
+ * @return Eway_Rapid31_Model_Request_Direct $this
478
+ */
479
+ public function doTransaction(Mage_Sales_Model_Quote $quote, $amount)
480
+ {
481
+ $this->_buildRequest($quote, $amount);
482
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
483
+ $response = $this->_doRapidAPI('Transaction');
484
+
485
+ if ($response->isSuccess()) {
486
+ $quote->setTransactionId($response->getTransactionID());
487
+ $quote->setCcLast4($response->getCcLast4());
488
+ $quote->save();
489
+ return $quote;
490
+ } else {
491
+ Mage::throwException(
492
+ Mage::helper('ewayrapid')->__(
493
+ 'An error occurred while making the transaction. Please try again. (Error message: %s)',
494
+ $response->getMessage()
495
+ )
496
+ );
497
+ }
498
+ }
499
+
500
+ /**
501
+ * Call Authorisation API (Authorized only)
502
+ *
503
+ * @param Mage_Sales_Model_Order_Payment $payment
504
+ * @param $amount
505
+ * @return Eway_Rapid31_Model_Request_Direct
506
+ */
507
+ public function doAuthorisation(Mage_Sales_Model_Quote $quote, $amount)
508
+ {
509
+ $this->_buildRequest($quote, $amount);
510
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_AUTHORISE);
511
+ $response = $this->_doRapidAPI('Authorisation');
512
+ if ($response->isSuccess()) {
513
+ $quote->setTransactionId($response->getTransactionID());
514
+ $quote->setIsTransactionClosed(0);
515
+ $quote->setCcLast4($response->getCcLast4());
516
+ $beagleScore = $response->getBeagleScore() ? $response->getBeagleScore() : '';
517
+ $quote->setBeagleScore($beagleScore);
518
+ $quote->setBeagleVerification($response->getBeagleVerification());
519
+ $quote->save();
520
+ return $quote;
521
+ } else {
522
+ Mage::throwException(
523
+ Mage::helper('ewayrapid')->__(
524
+ 'An error occurred while doing the authorisation. Please try again. (Error message: %s)',
525
+ $response->getMessage()
526
+ )
527
+ );
528
+ }
529
+ }
530
+
531
+ /**
532
+ * Call Capture API (do the Capture only, must Authorized previously)
533
+ *
534
+ * @param Mage_Sales_Model_Order_Payment $payment
535
+ * @param $amount
536
+ * @return Eway_Rapid31_Model_Request_Direct
537
+ */
538
+ public function doCapturePayment(Mage_Sales_Model_Quote $quote, $amount)
539
+ {
540
+ // Empty Varien_Object's data
541
+ $this->unsetData();
542
+
543
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
544
+ $paymentParam->setTotalAmount($amount)
545
+ ->setCurrencyCode($quote->getBaseCurrencyCode());
546
+
547
+ $this->setPayment($paymentParam);
548
+ $this->setTransactionId($quote->getTransactionId());
549
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
550
+ $response = $this->_doRapidAPI('CapturePayment');
551
+
552
+ if ($response->isSuccess()) {
553
+ $quote->setTransactionId($response->getTransactionID());
554
+ $quote->save();
555
+ return $quote;
556
+ } else {
557
+ Mage::throwException(
558
+ Mage::helper('ewayrapid')->__(
559
+ 'An error occurred while doing the capture. Please try again. (Error message: %s)',
560
+ $response->getMessage()
561
+ )
562
+ );
563
+ }
564
+ }
565
+
566
+ /**
567
+ * Build the request with necessary parameters for doAuthorisation() and doTransaction()
568
+ *
569
+ * @param Mage_Sales_Model_Order_Payment $payment
570
+ * @param $amount
571
+ * @return Eway_Rapid31_Model_Request_Direct
572
+ */
573
+ protected function _buildRequest(Mage_Sales_Model_Quote $quote, $amount)
574
+ {
575
+ // Empty Varien_Object's data
576
+ $this->unsetData();
577
+
578
+ $billing = $quote->getBillingAddress();
579
+ $shipping = $quote->getShippingAddress();
580
+
581
+ // copy BillingAddress to ShippingAddress if checkout with guest or register
582
+ $checkoutMethod = $quote->getCheckoutMethod();
583
+ if ($checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_GUEST
584
+ || $checkoutMethod == Mage_Checkout_Model_Type_Onepage::METHOD_REGISTER
585
+ ) {
586
+ $shipping = $billing;
587
+ }
588
+
589
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
590
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
591
+ } else {
592
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
593
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
594
+ }
595
+ $version = Mage::helper('ewayrapid')->getExtensionVersion();
596
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion().' - eWAY '.$version);
597
+ $this->setShippingMethod('Other');
598
+
599
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
600
+ $paymentParam->setTotalAmount($amount);
601
+ $paymentParam->setCurrencyCode($quote->getBaseCurrencyCode());
602
+
603
+ // add InvoiceDescription and InvoiceReference
604
+ $config = Mage::getModel('ewayrapid/config');
605
+
606
+ if ($config->shouldPassingInvoiceDescription()) {
607
+ $invoiceDescription = '';
608
+ foreach ($quote->getAllVisibleItems() as $item) {
609
+ // Check in case multi-shipping
610
+ if (!$item->getQuoteParentItemId()) {
611
+ $invoiceDescription .= (int) $item->getQty() . ' x ' .$item->getName() . ', ';
612
+ }
613
+ }
614
+ $invoiceDescription = trim($invoiceDescription, ', ');
615
+ $invoiceDescription = Mage::helper('ewayrapid')->limitInvoiceDescriptionLength($invoiceDescription);
616
+
617
+ $paymentParam->setInvoiceDescription($invoiceDescription);
618
+ }
619
+
620
+ if ($config->shouldPassingGuessOrder()) {
621
+ $incrementId = $this->_getIncrementOrderId($quote);
622
+ $paymentParam->setInvoiceReference($incrementId);
623
+ }
624
+
625
+ $this->setPayment($paymentParam);
626
+
627
+ $title = $this->_fixTitle($billing->getPrefix());
628
+
629
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
630
+ $customerParam->setTitle($title)
631
+ ->setFirstName($billing->getFirstname())
632
+ ->setLastName($billing->getLastname())
633
+ ->setCompanyName($billing->getCompany())
634
+ ->setJobDescription('')
635
+ ->setStreet1($billing->getStreet1())
636
+ ->setStreet2($billing->getStreet2())
637
+ ->setCity($billing->getCity())
638
+ ->setState($billing->getRegion())
639
+ ->setPostalCode($billing->getPostcode())
640
+ ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
641
+ ->setEmail($billing->getEmail())
642
+ ->setPhone($billing->getTelephone())
643
+ ->setMobile('')
644
+ ->setComments('')
645
+ ->setFax($billing->getFax())
646
+ ->setUrl('');
647
+
648
+ $infoCard = Mage::getSingleton('core/session')->getInfoCard();
649
+ if ($infoCard && $infoCard->getCard() && $infoCard->getOwner() && !$this->getTokenInfo()) {
650
+ $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
651
+ $cardDetails->setName($infoCard->getOwner())
652
+ ->setNumber($infoCard->getCard())
653
+ ->setExpiryMonth($infoCard->getExpMonth())
654
+ ->setExpiryYear($infoCard->getExpYear())
655
+ ->setCVN($infoCard->getCid());
656
+ $customerParam->setCardDetails($cardDetails);
657
+ }
658
+
659
+ if ($quote->getTokenCustomerID()) {
660
+ $customerParam->setTokenCustomerID($quote->getTokenCustomerID());
661
+ } elseif ($token = $this->getTokenInfo()) {
662
+ $customerParam->setTokenCustomerID($token->getToken() ? $token->getToken() : $token->getTokenCustomerID());
663
+ }
664
+
665
+ $this->setCustomer($customerParam);
666
+
667
+ if (!empty($shipping)) {
668
+ $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
669
+ $shippingParam->setFirstName($shipping->getFirstname())
670
+ ->setLastName($shipping->getLastname())
671
+ ->setStreet1($shipping->getStreet1())
672
+ ->setStreet2($shipping->getStreet2())
673
+ ->setCity($shipping->getCity())
674
+ ->setState($shipping->getRegion())
675
+ ->setPostalCode($shipping->getPostcode())
676
+ ->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))
677
+ ->setEmail($shipping->getEmail())
678
+ ->setPhone($shipping->getTelephone())
679
+ ->setFax($shipping->getFax());
680
+ $this->setShippingAddress($shippingParam);
681
+ }
682
+
683
+ $orderItems = $quote->getAllVisibleItems();
684
+ $lineItems = array();
685
+ foreach ($orderItems as $orderItem) {
686
+ /* @var Mage_Sales_Model_Order_Item $orderItem */
687
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
688
+ $lineItem->setSKU($orderItem->getSku());
689
+ $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
690
+ $lineItem->setQuantity($orderItem->getQtyOrdered());
691
+ $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
692
+ $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
693
+ $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
694
+ $lineItems[] = $lineItem;
695
+ }
696
+ $this->setItems($lineItems);
697
+ if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
698
+ $this->setItems(false);
699
+ }
700
+
701
+ return $this;
702
+ }
703
+
704
+ /**
705
+ * @param $tokenCustomerID
706
+ * @throws Mage_Core_Exception
707
+ */
708
+ public function getCustomerCard($tokenCustomerID)
709
+ {
710
+ // Empty Varien_Object's data
711
+ $this->unsetData();
712
+
713
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
714
+
715
+ if ($tokenCustomerID) {
716
+ $customerParam->setTokenCustomerID($tokenCustomerID);
717
+ } else {
718
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
719
+ }
720
+ $this->setCustomer($customerParam);
721
+
722
+ $response = $this->_doRapidAPI('Customer', 'PUT');
723
+ if ($response->isSuccess()) {
724
+ return $response;
725
+ } else {
726
+ return false;
727
+ }
728
+ }
729
+
730
+ public function getMethod()
731
+ {
732
+ return Mage::getSingleton('core/session')->getMethod();
733
+ }
734
+
735
+ /**
736
+ * @return mixed
737
+ */
738
+ public function getTransMethod()
739
+ {
740
+ $transMethod = Mage::getSingleton('core/session')->getTransparentNotsaved();
741
+ if (!$transMethod) {
742
+ $transMethod = Mage::getSingleton('core/session')->getTransparentSaved();
743
+ }
744
+ return $transMethod;
745
+ }
746
+
747
+ /**
748
+ * @return mixed
749
+ */
750
+ public function getTokenInfo()
751
+ {
752
+ if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
753
+ $uid = Mage::getSingleton('core/session')->getPaypalSavedToken();
754
+ } elseif ($this->getTransMethod() == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
755
+ $uid = Mage::getSingleton('core/session')->getMasterpassSavedToken();
756
+ } else {
757
+ $uid = Mage::getSingleton('core/session')->getSavedToken();
758
+ }
759
+ if ($uid && $uid != Eway_Rapid31_Model_Config::TOKEN_NEW)
760
+ return Mage::helper('ewayrapid/customer')->getTokenById($uid);
761
+ return false;
762
+ }
763
+
764
+ /**
765
+ *
766
+ */
767
+ public function unsetSessionData()
768
+ {
769
+ Mage::getSingleton('core/session')->unsTransparentNotsaved();
770
+ Mage::getSingleton('core/session')->unsTransparentSaved();
771
+ Mage::getSingleton('core/session')->unsSavedToken();
772
+ Mage::getSingleton('core/session')->unsTransactionId();
773
+ Mage::getSingleton('core/session')->unsFormActionUrl();
774
+ Mage::getSingleton('core/session')->unsPaypalSavedToken();
775
+ Mage::getSingleton('core/session')->unsMethod();
776
+ Mage::getSingleton('core/session')->unsCompleteCheckoutURL();
777
+ Mage::getSingleton('core/session')->unsMasterPassSavedToken();
778
+ Mage::getSingleton('core/session')->unsInfoCard();
779
+ }
780
  }
app/code/community/Eway/Rapid31/Model/Resource/Setup.php CHANGED
@@ -1,4 +1,5 @@
1
- <?php
2
-
3
- class Eway_Rapid31_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup {
4
- }
 
1
+ <?php
2
+
3
+ class Eway_Rapid31_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
4
+ {
5
+ }
app/code/community/Eway/Rapid31/Model/Response.php CHANGED
@@ -1,427 +1,426 @@
1
- <?php
2
-
3
- /**
4
- * Class Eway_Rapid31_Model_Response
5
- *
6
- * @method Eway_Rapid31_Model_Response setMessage(string $value)
7
- * @method string getAuthorisationCode()
8
- * @method Eway_Rapid31_Model_Response setAuthorisationCode(string $value)
9
- * @method string getResponseCode()
10
- * @method Eway_Rapid31_Model_Response setResponseCode(string $value)
11
- * @method string getResponseMessage()
12
- * @method Eway_Rapid31_Model_Response setResponseMessage(string $value)
13
- * @method int getTransactionID()
14
- * @method Eway_Rapid31_Model_Response setTransactionID(int $value)
15
- * @method bool getTransactionStatus()
16
- * @method Eway_Rapid31_Model_Response setTransactionStatus(bool $value)
17
- * @method long getTokenCustomerID()
18
- * @method Eway_Rapid31_Model_Response setTokenCustomerID(long $value)
19
- * @method array getVerification()
20
- * @method Eway_Rapid31_Model_Response setVerification(array $value)
21
- * @method array getErrors()
22
- * @method Eway_Rapid31_Model_Response setErrors(array $value)
23
- * @method string getCcLast4()
24
- */
25
- class Eway_Rapid31_Model_Response extends Varien_Object
26
- {
27
- private $_codes = array(
28
- 'F7000' => 'Undefined Fraud',
29
- 'V5000' => 'Undefined System',
30
- 'A0000' => 'Undefined Approved',
31
- 'A2000' => 'Transaction Approved',
32
- 'A2008' => 'Honour With Identification',
33
- 'A2010' => 'Approved For Partial Amount',
34
- 'A2011' => 'Approved VIP',
35
- 'A2016' => 'Approved Update Track 3',
36
-
37
- 'V6000' => 'Undefined Validation',
38
- 'V6001' => 'Invalid Request CustomerIP',
39
- 'V6002' => 'Invalid Request DeviceID',
40
- 'V6011' => 'Invalid Payment Amount',
41
- 'V6012' => 'Invalid Payment InvoiceDescription',
42
- 'V6013' => 'Invalid Payment InvoiceNumber',
43
- 'V6014' => 'Invalid Payment InvoiceReference',
44
- 'V6015' => 'Invalid Payment CurrencyCode',
45
- 'V6016' => 'Payment Required',
46
- 'V6017' => 'Payment CurrencyCode Required',
47
- 'V6018' => 'Unknown Payment CurrencyCode',
48
- 'V6021' => 'Cardholder Name Required',
49
- 'V6022' => 'Card Number Required',
50
- 'V6023' => 'CVN Required',
51
- 'V6031' => 'Invalid Card Number',
52
- 'V6032' => 'Invalid CVN',
53
- 'V6033' => 'Invalid Expiry Date',
54
- 'V6034' => 'Invalid Issue Number',
55
- 'V6035' => 'Invalid Start Date',
56
- 'V6036' => 'Invalid Month',
57
- 'V6037' => 'Invalid Year',
58
- 'V6040' => 'Invalid Token Customer Id',
59
- 'V6041' => 'Customer Required',
60
- 'V6042' => 'Customer First Name Required',
61
- 'V6043' => 'Customer Last Name Required',
62
- 'V6044' => 'Customer Country Code Required',
63
- 'V6045' => 'Customer Title Required',
64
- 'V6046' => 'Token Customer ID Required',
65
- 'V6047' => 'RedirectURL Required',
66
- 'V6051' => 'Invalid Customer First Name',
67
- 'V6052' => 'Invalid Customer Last Name',
68
- 'V6053' => 'Invalid Customer Country Code',
69
- 'V6054' => 'Invalid Customer Email',
70
- 'V6055' => 'Invalid Customer Phone',
71
- 'V6056' => 'Invalid Customer Mobile',
72
- 'V6057' => 'Invalid Customer Fax',
73
- 'V6058' => 'Invalid Customer Title',
74
- 'V6059' => 'Redirect URL Invalid',
75
- 'V6060' => 'Redirect URL Invalid',
76
- 'V6061' => 'Invalid Customer Reference',
77
- 'V6062' => 'Invalid Customer CompanyName',
78
- 'V6063' => 'Invalid Customer JobDescription',
79
- 'V6064' => 'Invalid Customer Street1',
80
- 'V6065' => 'Invalid Customer Street2',
81
- 'V6066' => 'Invalid Customer City',
82
- 'V6067' => 'Invalid Customer State',
83
- 'V6068' => 'Invalid Customer Postalcode',
84
- 'V6069' => 'Invalid Customer Email',
85
- 'V6070' => 'Invalid Customer Phone',
86
- 'V6071' => 'Invalid Customer Mobile',
87
- 'V6072' => 'Invalid Customer Comments',
88
- 'V6073' => 'Invalid Customer Fax',
89
- 'V6074' => 'Invalid Customer Url',
90
- 'V6075' => 'Invalid ShippingAddress FirstName',
91
- 'V6076' => 'Invalid ShippingAddress LastName',
92
- 'V6077' => 'Invalid ShippingAddress Street1',
93
- 'V6078' => 'Invalid ShippingAddress Street2',
94
- 'V6079' => 'Invalid ShippingAddress City',
95
- 'V6080' => 'Invalid ShippingAddress State',
96
- 'V6081' => 'Invalid ShippingAddress PostalCode',
97
- 'V6082' => 'Invalid ShippingAddress Email',
98
- 'V6083' => 'Invalid ShippingAddress Phone',
99
- 'V6084' => 'Invalid ShippingAddress Country',
100
- 'V6091' => 'Unknown Country Code',
101
- 'V6100' => 'Invalid name',
102
- 'V6101' => 'Invalid ExpiryMonth',
103
- 'V6102' => 'Invalid ExpiryYear',
104
- 'V6103' => 'Invalid StartMonth',
105
- 'V6104' => 'Invalid StartYear',
106
- 'V6105' => 'Invalid IssueNumber',
107
- 'V6106' => 'Invalid CVN',
108
- 'V6107' => 'Invalid AccessCode',
109
- 'V6108' => 'Invalid CustomerHostAddress',
110
- 'V6109' => 'Invalid UserAgent',
111
- 'V6110' => 'Invalid Number',
112
- 'V6111' => 'Unauthorised API Access, Account Not PCI Certified',
113
- 'V6112' => 'Redundant card details other than expiry year and month',
114
- 'V6113' => 'Invalid transaction for refund',
115
- 'V6114' => 'Gateway validation error',
116
- 'V6115' => 'Invalid DirectRefundRequest, Transaction ID ',
117
- 'V6116' => 'Invalid card data on original TransactionID ',
118
- 'V6117' => 'Invalid CreateAccessCodeSharedRequest, FooterText',
119
- 'V6118' => 'Invalid CreateAccessCodeSharedRequest, HeaderText',
120
- 'V6119' => 'Invalid CreateAccessCodeSharedRequest, Language',
121
- 'V6120' => 'Invalid CreateAccessCodeSharedRequest, LogoUrl ',
122
- 'V6121' => 'Invalid TransactionSearch, Filter Match Type',
123
- 'V6122' => 'Invalid TransactionSearch, Non numeric Transaction ID',
124
- 'V6123' => 'Invalid TransactionSearch,no TransactionID or AccessCode specified ',
125
- 'V6124' => 'Invalid Line Items. The line items have been provided however the totals do not match the TotalAmount field',
126
- 'V6125' => 'Selected Payment Type not enabled',
127
- 'V6126' => 'Invalid encrypted card number, decryption failed',
128
- 'V6127' => 'Invalid encrypted cvn, decryption failed',
129
- 'V6128' => 'Invalid Method for Payment Type',
130
- 'V6129' => 'Transaction has not been authorised for Capture/Cancellation',
131
- 'V6130' => 'Generic customer information error',
132
- 'V6131' => 'Generic shipping information error',
133
- 'V6132' => 'Transaction has already been completed or voided, operation not permitted',
134
- 'V6133' => 'Checkout not available for Payment Type',
135
- 'V6134' => 'Invalid Auth Transaction ID for Capture/Void',
136
- 'V6135' => 'PayPal Error Processing Refund',
137
- 'V6140' => 'Merchant account is suspended',
138
- 'V6141' => 'Invalid PayPal account details or API signature',
139
- 'V6142' => 'Authorise not available for Bank/Branch',
140
- 'V6150' => 'Invalid Refund Amount',
141
- 'V6151' => 'Refund amount greater than original transaction',
142
- 'V6152' => 'Original transaction already refunded for total amount',
143
- 'V6153' => 'Card type not support by merchant',
144
- 'V6160' => 'Encryption Method Not Supported',
145
- 'V6165' => 'Invalid Visa Checkout data or decryption failed',
146
-
147
- 'D4401' => 'Refer to Issuer',
148
- 'D4402' => 'Refer to Issuer, special',
149
- 'D4403' => 'No Merchant',
150
- 'D4404' => 'Pick Up Card',
151
- 'D4405' => 'Do Not Honour',
152
- 'D4406' => 'Error',
153
- 'D4407' => 'Pick Up Card, Special',
154
- 'D4409' => 'Request In Progress',
155
- 'D4412' => 'Invalid Transaction',
156
- 'D4413' => 'Invalid Amount',
157
- 'D4414' => 'Invalid Card Number',
158
- 'D4415' => 'No Issuer',
159
- 'D4419' => 'Re-enter Last Transaction',
160
- 'D4421' => 'No Method Taken',
161
- 'D4422' => 'Suspected Malfunction',
162
- 'D4423' => 'Unacceptable Transaction Fee',
163
- 'D4425' => 'Unable to Locate Record On File',
164
- 'D4430' => 'Format Error',
165
- 'D4431' => 'Bank Not Supported By Switch',
166
- 'D4433' => 'Expired Card, Capture',
167
- 'D4434' => 'Suspected Fraud, Retain Card',
168
- 'D4435' => 'Card Acceptor, Contact Acquirer, Retain Card',
169
- 'D4436' => 'Restricted Card, Retain Card',
170
- 'D4437' => 'Contact Acquirer Security Department, Retain Card',
171
- 'D4438' => 'PIN Tries Exceeded, Capture',
172
- 'D4439' => 'No Credit Account',
173
- 'D4440' => 'Function Not Supported',
174
- 'D4441' => 'Lost Card',
175
- 'D4442' => 'No Universal Account',
176
- 'D4443' => 'Stolen Card',
177
- 'D4444' => 'No Investment Account',
178
- 'D4451' => 'Insufficient Funds',
179
- 'D4452' => 'No Cheque Account',
180
- 'D4453' => 'No Savings Account',
181
- 'D4454' => 'Expired Card',
182
- 'D4455' => 'Incorrect PIN',
183
- 'D4456' => 'No Card Record',
184
- 'D4457' => 'Function Not Permitted to Cardholder',
185
- 'D4458' => 'Function Not Permitted to Terminal',
186
- 'D4460' => 'Acceptor Contact Acquirer',
187
- 'D4461' => 'Exceeds Withdrawal Limit',
188
- 'D4462' => 'Restricted Card',
189
- 'D4463' => 'Security Violation',
190
- 'D4464' => 'Original Amount Incorrect',
191
- 'D4466' => 'Acceptor Contact Acquirer, Security',
192
- 'D4467' => 'Capture Card',
193
- 'D4475' => 'PIN Tries Exceeded',
194
- 'D4482' => 'CVV Validation Error',
195
- 'D4490' => 'Cutoff In Progress',
196
- 'D4491' => 'Card Issuer Unavailable',
197
- 'D4492' => 'Unable To Route Transaction',
198
- 'D4493' => 'Cannot Complete, Violation Of The Law',
199
- 'D4494' => 'Duplicate Transaction',
200
- 'D4496' => 'System Error',
201
- 'D4497' => 'MasterPass Error',
202
- 'D4498' => 'PayPal Create Transaction Error',
203
- 'D4499' => 'Invalid Transaction for Auth/Void',
204
-
205
- 'S5000' => 'System Error',
206
- 'S5085' => 'Started 3dSecure',
207
- 'S5086' => 'Routed 3dSecure',
208
- 'S5087' => 'Completed 3dSecure',
209
- 'S5088' => 'PayPal Transaction Created',
210
- 'S5099' => 'Incomplete (Access Code in progress/incomplete)',
211
- 'S5010' => 'Unknown error returned by gateway',
212
- );
213
- private $_isSuccess = false;
214
-
215
- private $_messageCode = array(
216
- 'F7000' => 'Undefined Fraud Error',
217
- 'F7001' => 'Challenged Fraud',
218
- 'F7002' => 'Country Match Fraud',
219
- 'F7003' => 'High Risk Country Fraud',
220
- 'F7004' => 'Anonymous Proxy Fraud',
221
- 'F7005' => 'Transparent Proxy Fraud',
222
- 'F7006' => 'Free Email Fraud',
223
- 'F7007' => 'International Transaction Fraud',
224
- 'F7008' => 'Risk Score Fraud',
225
- 'F7009' => 'Denied Fraud',
226
- 'F9010' => 'High Risk Billing Country',
227
- 'F9011' => 'High Risk Credit Card Country',
228
- 'F9012' => 'High Risk Customer IP Address',
229
- 'F9013' => 'High Risk Email Address',
230
- 'F9014' => 'High Risk Shipping Country',
231
- 'F9015' => 'Multiple card numbers for single email address',
232
- 'F9016' => 'Multiple card numbers for single location',
233
- 'F9017' => 'Multiple email addresses for single card number',
234
- 'F9018' => 'Multiple email addresses for single location',
235
- 'F9019' => 'Multiple locations for single card number',
236
- 'F9020' => 'Multiple locations for single email address',
237
- 'F9021' => 'Suspicious Customer First Name',
238
- 'F9022' => 'Suspicious Customer Last Name',
239
- 'F9023' => 'Transaction Declined',
240
- 'F9024' => 'Multiple transactions for same address with known credit card',
241
- 'F9025' => 'Multiple transactions for same address with new credit card',
242
- 'F9026' => 'Multiple transactions for same email with new credit card',
243
- 'F9027' => 'Multiple transactions for same email with known credit card',
244
- 'F9028' => 'Multiple transactions for new credit card',
245
- 'F9029' => 'Multiple transactions for known credit card',
246
- 'F9030' => 'Multiple transactions for same email address',
247
- 'F9031' => 'Multiple transactions for same credit card',
248
- 'F9032' => 'Invalid Customer Last Name',
249
- 'F9033' => 'Invalid Billing Street',
250
- 'F9034' => 'Invalid Shipping Street',
251
- 'F9037' => 'Suspicious Customer Email Address',
252
- 'F9049' => 'Genuine Customer',
253
- 'F9050' => 'High Risk Email Address and amount',
254
- 'F9113' => 'Card issuing country differs from IP address country'
255
- );
256
-
257
- public function getMessage() {
258
- if($this->getData('Message')) {
259
- return $this->getData('Message');
260
- }
261
-
262
- $messageCode = $this->getResponseMessage();
263
- if(empty($messageCode) && ($errors = $this->getErrors())) {
264
- $messageCode = $errors[0];
265
- }
266
-
267
- if(empty($messageCode)) {
268
- return Mage::helper('ewayrapid')->__("Unknown");
269
- }
270
-
271
- if (isset($this->_codes[$messageCode])) {
272
- return $this->_codes[$messageCode];
273
- } else {
274
- return Mage::helper('ewayrapid')->__("%s", $this->replaceMessage($messageCode));
275
- }
276
- }
277
-
278
- public function isSuccess($flag = null)
279
- {
280
- if($flag !== null) {
281
- $this->_isSuccess = $flag;
282
- }
283
-
284
- return $this->_isSuccess;
285
- }
286
-
287
- /**
288
- * Decode response returned by eWAY API call
289
- *
290
- * @param $response
291
- * @return Eway_Rapid31_Model_Response
292
- */
293
- public function decodeJSON($response)
294
- {
295
- $json = json_decode($response, true);
296
- $this->addData($json);
297
- if(!empty($json['Customer']) && is_array($json['Customer'])) {
298
- $this->_setIfNotEmpty($json['Customer'], 'TokenCustomerID');
299
- if(!empty($json['Customer']['CardDetails']) && !empty($json['Customer']['CardDetails']['Number'])) {
300
- $this->setData('CcLast4', substr($json['Customer']['CardDetails']['Number'], -4));
301
- }
302
- }
303
-
304
- if(!empty($json['Errors'])) {
305
- $this->setErrors(explode(',', $json['Errors']));
306
- }
307
-
308
- if(isset($json['TransactionStatus'])) {
309
- // Use TransactionStatus if it's presented in response
310
- $this->isSuccess((bool)$this->getTransactionStatus());
311
-
312
- // Check response message has fraud code
313
- if (isset($json['ResponseMessage']) && $this->isSuccess()) {
314
- $codeMessage = str_replace(' ', '', $json['ResponseMessage']);
315
- $codeMessage = explode(',', $codeMessage);
316
- //$codeMessage = array_flip($codeMessage);
317
-
318
- //$result = array_intersect_key($this->_messageCode, $codeMessage);
319
- $result = preg_grep("/^F.*/", $codeMessage);
320
- if (!empty($result)) {
321
- $codes = array_flip($result);
322
- $resultMatched = array_intersect_key($this->_messageCode, $codes);
323
- $resultDefault = array_fill_keys(array_keys($codes), "Unknown fraud rule");
324
- $resultMessages = array_merge($resultDefault,$resultMatched);
325
- Mage::getSingleton('core/session')->setData('fraud', 1);
326
- $fraudMessage = implode(', ', $resultMessages);
327
- Mage::getSingleton('core/session')->setData('fraudMessage', $fraudMessage);
328
- }
329
- }
330
- } else {
331
- // Otherwise base on the Errors (Token transactions)
332
- $this->isSuccess(!$this->getErrors());
333
-
334
- // Catch empty response
335
- if(!isset($json['TransactionStatus'])
336
- && !isset($json['TransactionID'])
337
- && !isset($json['Customer']['TokenCustomerID'])
338
- && !isset($json['AccessCode'])
339
- && !isset($json['Transactions'])) {
340
- $this->isSuccess(false);
341
- }
342
- }
343
-
344
- return $this;
345
- }
346
-
347
- /**
348
- * Sets a value in the object if present
349
- *
350
- * @param array $json
351
- * @param string $key
352
- */
353
- private function _setIfNotEmpty($json, $key)
354
- {
355
- if(!empty($json[$key])) {
356
- $this->setData($key, $json[$key]);
357
- }
358
- }
359
-
360
- /**
361
- * Override Varien_Object::_underscore() to prevent transform of field name.
362
- *
363
- * @param string $name
364
- * @return string
365
- */
366
- protected function _underscore($name)
367
- {
368
- return $name;
369
- }
370
-
371
- /**
372
- * replace error code to message
373
- *
374
- * @param $message
375
- */
376
- public function replaceMessage($message)
377
- {
378
- $results = $message;
379
- $found = false;
380
- if($this->_codes) {
381
- foreach ($this->_codes as $code => $mess) {
382
- if(strpos($message, $code) !== false) {
383
- $found = true;
384
- $results = str_replace( $results, $code, $mess );
385
- }
386
- }
387
- }
388
- if ($found) {
389
- return $results;
390
- } else {
391
- return Mage::helper('ewayrapid')->__('Transaction failed.');
392
- }
393
- }
394
-
395
- /**
396
- * Checks if the transaction was marked as challenged by Beagle anti-fraud
397
- *
398
- * @param array $result transaction result from eWAY
399
- */
400
- private function _checkfraud($result)
401
- {
402
- if (isset($result['FraudAction']) && !empty($result['FraudAction'])) {
403
-
404
- // Challenged orders are Review or PreAuth/Allow that processed
405
- if (($result['FraudAction'] == "Review") ||
406
- ($result['FraudAction'] == "PreAuth" && $this->isSuccess()) ||
407
- ($result['FraudAction'] == "Allow" && $this->isSuccess())) {
408
-
409
- // Find fraud codes
410
- $codeMessage = str_replace(' ', '', $result['ResponseMessage']);
411
- $codeMessages = explode(',', $codeMessage);
412
- $result = preg_grep("/^F.*/", $codeMessages);
413
- $codes = array_flip($result);
414
-
415
- // Convert to text and signal fraud
416
- $resultMatched = array_intersect_key($this->_messageCode, $codes);
417
- $resultDefault = array_fill_keys(array_keys($codes), "Unknown fraud rule");
418
- $resultMessages = array_merge($resultDefault,$resultMatched);
419
- Mage::getSingleton('core/session')->setData('fraud', 1);
420
- $fraudMessage = implode(', ', $resultMessages);
421
- Mage::getSingleton('core/session')->setData('fraudMessage', $fraudMessage);
422
-
423
- }
424
-
425
- }
426
- }
427
  }
1
+ <?php
2
+
3
+ /**
4
+ * Class Eway_Rapid31_Model_Response
5
+ *
6
+ * @method Eway_Rapid31_Model_Response setMessage(string $value)
7
+ * @method string getAuthorisationCode()
8
+ * @method Eway_Rapid31_Model_Response setAuthorisationCode(string $value)
9
+ * @method string getResponseCode()
10
+ * @method Eway_Rapid31_Model_Response setResponseCode(string $value)
11
+ * @method string getResponseMessage()
12
+ * @method Eway_Rapid31_Model_Response setResponseMessage(string $value)
13
+ * @method int getTransactionID()
14
+ * @method Eway_Rapid31_Model_Response setTransactionID(int $value)
15
+ * @method bool getTransactionStatus()
16
+ * @method Eway_Rapid31_Model_Response setTransactionStatus(bool $value)
17
+ * @method long getTokenCustomerID()
18
+ * @method Eway_Rapid31_Model_Response setTokenCustomerID(long $value)
19
+ * @method array getVerification()
20
+ * @method Eway_Rapid31_Model_Response setVerification(array $value)
21
+ * @method array getErrors()
22
+ * @method Eway_Rapid31_Model_Response setErrors(array $value)
23
+ * @method string getCcLast4()
24
+ */
25
+ class Eway_Rapid31_Model_Response extends Varien_Object
26
+ {
27
+ protected $_codes = array(
28
+ 'F7000' => 'Undefined Fraud',
29
+ 'V5000' => 'Undefined System',
30
+ 'A0000' => 'Undefined Approved',
31
+ 'A2000' => 'Transaction Approved',
32
+ 'A2008' => 'Honour With Identification',
33
+ 'A2010' => 'Approved For Partial Amount',
34
+ 'A2011' => 'Approved VIP',
35
+ 'A2016' => 'Approved Update Track 3',
36
+
37
+ 'V6000' => 'Undefined Validation',
38
+ 'V6001' => 'Invalid Request CustomerIP',
39
+ 'V6002' => 'Invalid Request DeviceID',
40
+ 'V6011' => 'Invalid Payment Amount',
41
+ 'V6012' => 'Invalid Payment InvoiceDescription',
42
+ 'V6013' => 'Invalid Payment InvoiceNumber',
43
+ 'V6014' => 'Invalid Payment InvoiceReference',
44
+ 'V6015' => 'Invalid Payment CurrencyCode',
45
+ 'V6016' => 'Payment Required',
46
+ 'V6017' => 'Payment CurrencyCode Required',
47
+ 'V6018' => 'Unknown Payment CurrencyCode',
48
+ 'V6021' => 'Cardholder Name Required',
49
+ 'V6022' => 'Card Number Required',
50
+ 'V6023' => 'CVN Required',
51
+ 'V6031' => 'Invalid Card Number',
52
+ 'V6032' => 'Invalid CVN',
53
+ 'V6033' => 'Invalid Expiry Date',
54
+ 'V6034' => 'Invalid Issue Number',
55
+ 'V6035' => 'Invalid Start Date',
56
+ 'V6036' => 'Invalid Month',
57
+ 'V6037' => 'Invalid Year',
58
+ 'V6040' => 'Invalid Token Customer Id',
59
+ 'V6041' => 'Customer Required',
60
+ 'V6042' => 'Customer First Name Required',
61
+ 'V6043' => 'Customer Last Name Required',
62
+ 'V6044' => 'Customer Country Code Required',
63
+ 'V6045' => 'Customer Title Required',
64
+ 'V6046' => 'Token Customer ID Required',
65
+ 'V6047' => 'RedirectURL Required',
66
+ 'V6051' => 'Invalid Customer First Name',
67
+ 'V6052' => 'Invalid Customer Last Name',
68
+ 'V6053' => 'Invalid Customer Country Code',
69
+ 'V6054' => 'Invalid Customer Email',
70
+ 'V6055' => 'Invalid Customer Phone',
71
+ 'V6056' => 'Invalid Customer Mobile',
72
+ 'V6057' => 'Invalid Customer Fax',
73
+ 'V6058' => 'Invalid Customer Title',
74
+ 'V6059' => 'Redirect URL Invalid',
75
+ 'V6060' => 'Redirect URL Invalid',
76
+ 'V6061' => 'Invalid Customer Reference',
77
+ 'V6062' => 'Invalid Customer CompanyName',
78
+ 'V6063' => 'Invalid Customer JobDescription',
79
+ 'V6064' => 'Invalid Customer Street1',
80
+ 'V6065' => 'Invalid Customer Street2',
81
+ 'V6066' => 'Invalid Customer City',
82
+ 'V6067' => 'Invalid Customer State',
83
+ 'V6068' => 'Invalid Customer Postalcode',
84
+ 'V6069' => 'Invalid Customer Email',
85
+ 'V6070' => 'Invalid Customer Phone',
86
+ 'V6071' => 'Invalid Customer Mobile',
87
+ 'V6072' => 'Invalid Customer Comments',
88
+ 'V6073' => 'Invalid Customer Fax',
89
+ 'V6074' => 'Invalid Customer Url',
90
+ 'V6075' => 'Invalid ShippingAddress FirstName',
91
+ 'V6076' => 'Invalid ShippingAddress LastName',
92
+ 'V6077' => 'Invalid ShippingAddress Street1',
93
+ 'V6078' => 'Invalid ShippingAddress Street2',
94
+ 'V6079' => 'Invalid ShippingAddress City',
95
+ 'V6080' => 'Invalid ShippingAddress State',
96
+ 'V6081' => 'Invalid ShippingAddress PostalCode',
97
+ 'V6082' => 'Invalid ShippingAddress Email',
98
+ 'V6083' => 'Invalid ShippingAddress Phone',
99
+ 'V6084' => 'Invalid ShippingAddress Country',
100
+ 'V6091' => 'Unknown Country Code',
101
+ 'V6100' => 'Invalid name',
102
+ 'V6101' => 'Invalid ExpiryMonth',
103
+ 'V6102' => 'Invalid ExpiryYear',
104
+ 'V6103' => 'Invalid StartMonth',
105
+ 'V6104' => 'Invalid StartYear',
106
+ 'V6105' => 'Invalid IssueNumber',
107
+ 'V6106' => 'Invalid CVN',
108
+ 'V6107' => 'Invalid AccessCode',
109
+ 'V6108' => 'Invalid CustomerHostAddress',
110
+ 'V6109' => 'Invalid UserAgent',
111
+ 'V6110' => 'Invalid Number',
112
+ 'V6111' => 'Unauthorised API Access, Account Not PCI Certified',
113
+ 'V6112' => 'Redundant card details other than expiry year and month',
114
+ 'V6113' => 'Invalid transaction for refund',
115
+ 'V6114' => 'Gateway validation error',
116
+ 'V6115' => 'Invalid DirectRefundRequest, Transaction ID ',
117
+ 'V6116' => 'Invalid card data on original TransactionID ',
118
+ 'V6117' => 'Invalid CreateAccessCodeSharedRequest, FooterText',
119
+ 'V6118' => 'Invalid CreateAccessCodeSharedRequest, HeaderText',
120
+ 'V6119' => 'Invalid CreateAccessCodeSharedRequest, Language',
121
+ 'V6120' => 'Invalid CreateAccessCodeSharedRequest, LogoUrl ',
122
+ 'V6121' => 'Invalid TransactionSearch, Filter Match Type',
123
+ 'V6122' => 'Invalid TransactionSearch, Non numeric Transaction ID',
124
+ 'V6123' => 'Invalid TransactionSearch,no TransactionID or AccessCode specified ',
125
+ 'V6124' => 'Invalid Line Items. The line items have been provided however the totals do not match the TotalAmount field',
126
+ 'V6125' => 'Selected Payment Type not enabled',
127
+ 'V6126' => 'Invalid encrypted card number, decryption failed',
128
+ 'V6127' => 'Invalid encrypted cvn, decryption failed',
129
+ 'V6128' => 'Invalid Method for Payment Type',
130
+ 'V6129' => 'Transaction has not been authorised for Capture/Cancellation',
131
+ 'V6130' => 'Generic customer information error',
132
+ 'V6131' => 'Generic shipping information error',
133
+ 'V6132' => 'Transaction has already been completed or voided, operation not permitted',
134
+ 'V6133' => 'Checkout not available for Payment Type',
135
+ 'V6134' => 'Invalid Auth Transaction ID for Capture/Void',
136
+ 'V6135' => 'PayPal Error Processing Refund',
137
+ 'V6140' => 'Merchant account is suspended',
138
+ 'V6141' => 'Invalid PayPal account details or API signature',
139
+ 'V6142' => 'Authorise not available for Bank/Branch',
140
+ 'V6150' => 'Invalid Refund Amount',
141
+ 'V6151' => 'Refund amount greater than original transaction',
142
+ 'V6152' => 'Original transaction already refunded for total amount',
143
+ 'V6153' => 'Card type not support by merchant',
144
+ 'V6160' => 'Encryption Method Not Supported',
145
+ 'V6165' => 'Invalid Visa Checkout data or decryption failed',
146
+
147
+ 'D4401' => 'Refer to Issuer',
148
+ 'D4402' => 'Refer to Issuer, special',
149
+ 'D4403' => 'No Merchant',
150
+ 'D4404' => 'Pick Up Card',
151
+ 'D4405' => 'Do Not Honour',
152
+ 'D4406' => 'Error',
153
+ 'D4407' => 'Pick Up Card, Special',
154
+ 'D4409' => 'Request In Progress',
155
+ 'D4412' => 'Invalid Transaction',
156
+ 'D4413' => 'Invalid Amount',
157
+ 'D4414' => 'Invalid Card Number',
158
+ 'D4415' => 'No Issuer',
159
+ 'D4419' => 'Re-enter Last Transaction',
160
+ 'D4421' => 'No Method Taken',
161
+ 'D4422' => 'Suspected Malfunction',
162
+ 'D4423' => 'Unacceptable Transaction Fee',
163
+ 'D4425' => 'Unable to Locate Record On File',
164
+ 'D4430' => 'Format Error',
165
+ 'D4431' => 'Bank Not Supported By Switch',
166
+ 'D4433' => 'Expired Card, Capture',
167
+ 'D4434' => 'Suspected Fraud, Retain Card',
168
+ 'D4435' => 'Card Acceptor, Contact Acquirer, Retain Card',
169
+ 'D4436' => 'Restricted Card, Retain Card',
170
+ 'D4437' => 'Contact Acquirer Security Department, Retain Card',
171
+ 'D4438' => 'PIN Tries Exceeded, Capture',
172
+ 'D4439' => 'No Credit Account',
173
+ 'D4440' => 'Function Not Supported',
174
+ 'D4441' => 'Lost Card',
175
+ 'D4442' => 'No Universal Account',
176
+ 'D4443' => 'Stolen Card',
177
+ 'D4444' => 'No Investment Account',
178
+ 'D4451' => 'Insufficient Funds',
179
+ 'D4452' => 'No Cheque Account',
180
+ 'D4453' => 'No Savings Account',
181
+ 'D4454' => 'Expired Card',
182
+ 'D4455' => 'Incorrect PIN',
183
+ 'D4456' => 'No Card Record',
184
+ 'D4457' => 'Function Not Permitted to Cardholder',
185
+ 'D4458' => 'Function Not Permitted to Terminal',
186
+ 'D4460' => 'Acceptor Contact Acquirer',
187
+ 'D4461' => 'Exceeds Withdrawal Limit',
188
+ 'D4462' => 'Restricted Card',
189
+ 'D4463' => 'Security Violation',
190
+ 'D4464' => 'Original Amount Incorrect',
191
+ 'D4466' => 'Acceptor Contact Acquirer, Security',
192
+ 'D4467' => 'Capture Card',
193
+ 'D4475' => 'PIN Tries Exceeded',
194
+ 'D4482' => 'CVV Validation Error',
195
+ 'D4490' => 'Cutoff In Progress',
196
+ 'D4491' => 'Card Issuer Unavailable',
197
+ 'D4492' => 'Unable To Route Transaction',
198
+ 'D4493' => 'Cannot Complete, Violation Of The Law',
199
+ 'D4494' => 'Duplicate Transaction',
200
+ 'D4496' => 'System Error',
201
+ 'D4497' => 'MasterPass Error',
202
+ 'D4498' => 'PayPal Create Transaction Error',
203
+ 'D4499' => 'Invalid Transaction for Auth/Void',
204
+
205
+ 'S5000' => 'System Error',
206
+ 'S5085' => 'Started 3dSecure',
207
+ 'S5086' => 'Routed 3dSecure',
208
+ 'S5087' => 'Completed 3dSecure',
209
+ 'S5088' => 'PayPal Transaction Created',
210
+ 'S5099' => 'Incomplete (Access Code in progress/incomplete)',
211
+ 'S5010' => 'Unknown error returned by gateway',
212
+ );
213
+ protected $_isSuccess = false;
214
+
215
+ protected $_messageCode = array(
216
+ 'F7000' => 'Undefined Fraud Error',
217
+ 'F7001' => 'Challenged Fraud',
218
+ 'F7002' => 'Country Match Fraud',
219
+ 'F7003' => 'High Risk Country Fraud',
220
+ 'F7004' => 'Anonymous Proxy Fraud',
221
+ 'F7005' => 'Transparent Proxy Fraud',
222
+ 'F7006' => 'Free Email Fraud',
223
+ 'F7007' => 'International Transaction Fraud',
224
+ 'F7008' => 'Risk Score Fraud',
225
+ 'F7009' => 'Denied Fraud',
226
+ 'F9010' => 'High Risk Billing Country',
227
+ 'F9011' => 'High Risk Credit Card Country',
228
+ 'F9012' => 'High Risk Customer IP Address',
229
+ 'F9013' => 'High Risk Email Address',
230
+ 'F9014' => 'High Risk Shipping Country',
231
+ 'F9015' => 'Multiple card numbers for single email address',
232
+ 'F9016' => 'Multiple card numbers for single location',
233
+ 'F9017' => 'Multiple email addresses for single card number',
234
+ 'F9018' => 'Multiple email addresses for single location',
235
+ 'F9019' => 'Multiple locations for single card number',
236
+ 'F9020' => 'Multiple locations for single email address',
237
+ 'F9021' => 'Suspicious Customer First Name',
238
+ 'F9022' => 'Suspicious Customer Last Name',
239
+ 'F9023' => 'Transaction Declined',
240
+ 'F9024' => 'Multiple transactions for same address with known credit card',
241
+ 'F9025' => 'Multiple transactions for same address with new credit card',
242
+ 'F9026' => 'Multiple transactions for same email with new credit card',
243
+ 'F9027' => 'Multiple transactions for same email with known credit card',
244
+ 'F9028' => 'Multiple transactions for new credit card',
245
+ 'F9029' => 'Multiple transactions for known credit card',
246
+ 'F9030' => 'Multiple transactions for same email address',
247
+ 'F9031' => 'Multiple transactions for same credit card',
248
+ 'F9032' => 'Invalid Customer Last Name',
249
+ 'F9033' => 'Invalid Billing Street',
250
+ 'F9034' => 'Invalid Shipping Street',
251
+ 'F9037' => 'Suspicious Customer Email Address',
252
+ 'F9049' => 'Genuine Customer',
253
+ 'F9050' => 'High Risk Email Address and amount',
254
+ 'F9113' => 'Card issuing country differs from IP address country'
255
+ );
256
+
257
+ public function getMessage()
258
+ {
259
+ if ($this->getData('Message')) {
260
+ return $this->getData('Message');
261
+ }
262
+
263
+ $messageCode = $this->getResponseMessage();
264
+ if (empty($messageCode) && ($errors = $this->getErrors())) {
265
+ $messageCode = $errors[0];
266
+ }
267
+
268
+ if (empty($messageCode)) {
269
+ return Mage::helper('ewayrapid')->__("Unknown");
270
+ }
271
+
272
+ if (isset($this->_codes[$messageCode])) {
273
+ return $this->_codes[$messageCode];
274
+ } else {
275
+ return Mage::helper('ewayrapid')->__("%s", $this->replaceMessage($messageCode));
276
+ }
277
+ }
278
+
279
+ public function isSuccess($flag = null)
280
+ {
281
+ if ($flag !== null) {
282
+ $this->_isSuccess = $flag;
283
+ }
284
+
285
+ return $this->_isSuccess;
286
+ }
287
+
288
+ /**
289
+ * Decode response returned by eWAY API call
290
+ *
291
+ * @param $response
292
+ * @return Eway_Rapid31_Model_Response
293
+ */
294
+ public function decodeJSON($response)
295
+ {
296
+ $json = json_decode($response, true);
297
+ $this->addData($json);
298
+ if (!empty($json['Customer']) && is_array($json['Customer'])) {
299
+ $this->_setIfNotEmpty($json['Customer'], 'TokenCustomerID');
300
+ if (!empty($json['Customer']['CardDetails']) && !empty($json['Customer']['CardDetails']['Number'])) {
301
+ $this->setData('CcLast4', substr($json['Customer']['CardDetails']['Number'], -4));
302
+ }
303
+ }
304
+
305
+ if (!empty($json['Errors'])) {
306
+ $this->setErrors(explode(',', $json['Errors']));
307
+ }
308
+
309
+ if (isset($json['TransactionStatus'])) {
310
+ // Use TransactionStatus if it's presented in response
311
+ $this->isSuccess((bool)$this->getTransactionStatus());
312
+
313
+ // Check response message has fraud code
314
+ if (isset($json['ResponseMessage']) && $this->isSuccess()) {
315
+ $codeMessage = str_replace(' ', '', $json['ResponseMessage']);
316
+ $codeMessage = explode(',', $codeMessage);
317
+
318
+ $result = preg_grep("/^F.*/", $codeMessage);
319
+ if (!empty($result)) {
320
+ $codes = array_flip($result);
321
+ $resultMatched = array_intersect_key($this->_messageCode, $codes);
322
+ $resultDefault = array_fill_keys(array_keys($codes), "Unknown fraud rule");
323
+ $resultMessages = array_merge($resultDefault, $resultMatched);
324
+ Mage::getSingleton('core/session')->setData('fraud', 1);
325
+ $fraudMessage = implode(', ', $resultMessages);
326
+ Mage::getSingleton('core/session')->setData('fraudMessage', $fraudMessage);
327
+ }
328
+ }
329
+ } else {
330
+ // Otherwise base on the Errors (Token transactions)
331
+ $this->isSuccess(!$this->getErrors());
332
+
333
+ // Catch empty response
334
+ if (!isset($json['TransactionStatus'])
335
+ && !isset($json['TransactionID'])
336
+ && !isset($json['Customer']['TokenCustomerID'])
337
+ && !isset($json['AccessCode'])
338
+ && !isset($json['Transactions'])) {
339
+ $this->isSuccess(false);
340
+ }
341
+ }
342
+
343
+ return $this;
344
+ }
345
+
346
+ /**
347
+ * Sets a value in the object if present
348
+ *
349
+ * @param array $json
350
+ * @param string $key
351
+ */
352
+ protected function _setIfNotEmpty($json, $key)
353
+ {
354
+ if (!empty($json[$key])) {
355
+ $this->setData($key, $json[$key]);
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Override Varien_Object::_underscore() to prevent transform of field name.
361
+ *
362
+ * @param string $name
363
+ * @return string
364
+ */
365
+ protected function _underscore($name)
366
+ {
367
+ return $name;
368
+ }
369
+
370
+ /**
371
+ * replace error code to message
372
+ *
373
+ * @param $message
374
+ */
375
+ public function replaceMessage($message)
376
+ {
377
+ $results = $message;
378
+ $found = false;
379
+ if ($this->_codes) {
380
+ foreach ($this->_codes as $code => $mess) {
381
+ if (strpos($message, $code) !== false) {
382
+ $found = true;
383
+ $results = str_replace($results, $code, $mess);
384
+ }
385
+ }
386
+ }
387
+ if ($found) {
388
+ return $results;
389
+ } else {
390
+ return Mage::helper('ewayrapid')->__('Transaction failed.');
391
+ }
392
+ }
393
+
394
+ /**
395
+ * Checks if the transaction was marked as challenged by Beagle anti-fraud
396
+ *
397
+ * @param array $result transaction result from eWAY
398
+ */
399
+ protected function _checkfraud($result)
400
+ {
401
+ if (isset($result['FraudAction']) && !empty($result['FraudAction'])) {
402
+
403
+ // Challenged orders are Review or PreAuth/Allow that processed
404
+ if (($result['FraudAction'] == "Review") ||
405
+ ($result['FraudAction'] == "PreAuth" && $this->isSuccess()) ||
406
+ ($result['FraudAction'] == "Allow" && $this->isSuccess())) {
407
+
408
+ // Find fraud codes
409
+ $codeMessage = str_replace(' ', '', $result['ResponseMessage']);
410
+ $codeMessages = explode(',', $codeMessage);
411
+ $result = preg_grep("/^F.*/", $codeMessages);
412
+ $codes = array_flip($result);
413
+
414
+ // Convert to text and signal fraud
415
+ $resultMatched = array_intersect_key($this->_messageCode, $codes);
416
+ $resultDefault = array_fill_keys(array_keys($codes), "Unknown fraud rule");
417
+ $resultMessages = array_merge($resultDefault, $resultMatched);
418
+ Mage::getSingleton('core/session')->setData('fraud', 1);
419
+ $fraudMessage = implode(', ', $resultMessages);
420
+ Mage::getSingleton('core/session')->setData('fraudMessage', $fraudMessage);
421
+
422
+ }
423
+
424
+ }
425
+ }
 
426
  }
app/code/community/Eway/Rapid31/Model/System/Config/Backend/Orderstatus.php CHANGED
@@ -1,22 +1,22 @@
1
- <?php
2
- class Eway_Rapid31_Model_System_Config_Backend_Orderstatus extends Mage_Core_Model_Config_Data
3
- {
4
- /**
5
- * Set default new order status when changing payment action field
6
- *
7
- * @return Mage_Core_Model_Abstract|void
8
- */
9
- protected function _beforeSave()
10
- {
11
- $paymentAction = $this->getFieldsetDataValue('payment_action');
12
- // Check if payment action is changed
13
- if($paymentAction != Mage::getStoreConfig('payment/ewayrapid_general/payment_action')) {
14
- $defaultStatus = ( $paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE ?
15
- Eway_Rapid31_Model_Config::ORDER_STATUS_CAPTURED :
16
- Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED
17
- );
18
-
19
- $this->setValue($defaultStatus);
20
- };
21
- }
22
  }
1
+ <?php
2
+ class Eway_Rapid31_Model_System_Config_Backend_Orderstatus extends Mage_Core_Model_Config_Data
3
+ {
4
+ /**
5
+ * Set default new order status when changing payment action field
6
+ *
7
+ * @return Mage_Core_Model_Abstract|void
8
+ */
9
+ protected function _beforeSave()
10
+ {
11
+ $paymentAction = $this->getFieldsetDataValue('payment_action');
12
+ // Check if payment action is changed
13
+ if ($paymentAction != Mage::getStoreConfig('payment/ewayrapid_general/payment_action')) {
14
+ $defaultStatus = ( $paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE ?
15
+ Eway_Rapid31_Model_Config::ORDER_STATUS_CAPTURED :
16
+ Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED
17
+ );
18
+
19
+ $this->setValue($defaultStatus);
20
+ };
21
+ }
22
  }
app/code/community/Eway/Rapid31/Model/System/Config/Backend/Validation.php CHANGED
@@ -1,48 +1,52 @@
1
- <?php
2
- class Eway_Rapid31_Model_System_Config_Backend_Validation extends Mage_Core_Model_Config_Data
3
- {
4
- protected function _beforeSave()
5
- {
6
- // Only do the validation in case eWAY Rapid solution is enabled
7
- if($this->getValue() == 1) {
8
- $errors = array();
9
- $this->_validateAPIKey($errors);
10
- $this->_validateEncryptionKey($errors);
11
- $this->_validateCCTypes($errors);
12
-
13
- if($count = count($errors)) {
14
- for($i = 0; $i < $count - 1; $i++) {
15
- Mage::getSingleton('adminhtml/session')->addError($errors[$i]);
16
- }
17
- Mage::throwException($errors[$count - 1]);
18
- }
19
- }
20
-
21
- parent::_beforeSave();
22
- }
23
-
24
- protected function _validateAPIKey(&$errors)
25
- {
26
- $mode = $this->getFieldsetDataValue('mode');
27
- if(!$this->getFieldsetDataValue($mode . '_api_key') || !$this->getFieldsetDataValue($mode . '_api_password')) {
28
- $errors[] = Mage::helper('ewayrapid')->__("Please input eWAY API Key and API Password for %s mode.",
29
- $mode == Eway_Rapid31_Model_Config::MODE_SANDBOX ? "Sandbox" : "Live");
30
- }
31
- }
32
-
33
- protected function _validateEncryptionKey(&$errors)
34
- {
35
- $mode = $this->getFieldsetDataValue('mode');
36
- if(!$this->getFieldsetDataValue($mode . '_encryption_key')) {
37
- $errors[] = Mage::helper('ewayrapid')->__("Client-side Encryption Key is required (%s).",
38
- $mode == Eway_Rapid31_Model_Config::MODE_SANDBOX ? "Sandbox" : "Live");
39
- }
40
- }
41
-
42
- protected function _validateCCTypes(&$errors)
43
- {
44
- if(!$this->getFieldsetDataValue('cctypes')) {
45
- $errors[] = Mage::helper('ewayrapid')->__("Please choose at least one Accepted Credit Card Type for eWAY payment method.");
46
- }
47
- }
 
 
 
 
48
  }
1
+ <?php
2
+ class Eway_Rapid31_Model_System_Config_Backend_Validation extends Mage_Core_Model_Config_Data
3
+ {
4
+ protected function _beforeSave()
5
+ {
6
+ // Only do the validation in case eWAY Rapid solution is enabled
7
+ if ($this->getValue() == 1) {
8
+ $errors = array();
9
+ $this->_validateAPIKey($errors);
10
+ $this->_validateEncryptionKey($errors);
11
+ $this->_validateCCTypes($errors);
12
+
13
+ if ($count = count($errors)) {
14
+ for ($i = 0; $i < $count - 1; $i++) {
15
+ Mage::getSingleton('adminhtml/session')->addError($errors[$i]);
16
+ }
17
+ Mage::throwException($errors[$count - 1]);
18
+ }
19
+ }
20
+
21
+ parent::_beforeSave();
22
+ }
23
+
24
+ protected function _validateAPIKey(&$errors)
25
+ {
26
+ $mode = $this->getFieldsetDataValue('mode');
27
+ if (!$this->getFieldsetDataValue($mode . '_api_key') || !$this->getFieldsetDataValue($mode . '_api_password')) {
28
+ $errors[] = Mage::helper('ewayrapid')->__(
29
+ "Please input eWAY API Key and API Password for %s mode.",
30
+ $mode == Eway_Rapid31_Model_Config::MODE_SANDBOX ? "Sandbox" : "Live"
31
+ );
32
+ }
33
+ }
34
+
35
+ protected function _validateEncryptionKey(&$errors)
36
+ {
37
+ $mode = $this->getFieldsetDataValue('mode');
38
+ if (!$this->getFieldsetDataValue($mode . '_encryption_key')) {
39
+ $errors[] = Mage::helper('ewayrapid')->__(
40
+ "Client-side Encryption Key is required (%s).",
41
+ $mode == Eway_Rapid31_Model_Config::MODE_SANDBOX ? "Sandbox" : "Live"
42
+ );
43
+ }
44
+ }
45
+
46
+ protected function _validateCCTypes(&$errors)
47
+ {
48
+ if (!$this->getFieldsetDataValue('cctypes')) {
49
+ $errors[] = Mage::helper('ewayrapid')->__("Please choose at least one Accepted Credit Card Type for eWAY payment method.");
50
+ }
51
+ }
52
  }
app/code/community/Eway/Rapid31/Model/System/Config/Source/Orderstatus.php CHANGED
@@ -1,33 +1,33 @@
1
- <?php
2
- class Eway_Rapid31_Model_System_Config_Source_Orderstatus extends Mage_Adminhtml_Model_System_Config_Source_Order_Status_Processing
3
- {
4
- /**
5
- * Filter out order status based on eWAY requirement
6
- *
7
- * @return array
8
- */
9
- public function toOptionArray()
10
- {
11
- $options = parent::toOptionArray();
12
-
13
- $paymentAction = Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
14
-
15
- foreach($options as $key => $option) {
16
- if(strpos($option['value'], '_ogone') !== false) {
17
- unset($options[$key]);
18
- }
19
-
20
- if($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
21
- if($option['value'] == Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED) {
22
- unset($options[$key]);
23
- }
24
- } else {
25
- if($option['value'] == Eway_Rapid31_Model_Config::ORDER_STATUS_CAPTURED) {
26
- unset($options[$key]);
27
- }
28
- }
29
- }
30
-
31
- return $options;
32
- }
33
  }
1
+ <?php
2
+ class Eway_Rapid31_Model_System_Config_Source_Orderstatus extends Mage_Adminhtml_Model_System_Config_Source_Order_Status_Processing
3
+ {
4
+ /**
5
+ * Filter out order status based on eWAY requirement
6
+ *
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ $options = parent::toOptionArray();
12
+
13
+ $paymentAction = Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
14
+
15
+ foreach ($options as $key => $option) {
16
+ if (strpos($option['value'], '_ogone') !== false) {
17
+ unset($options[$key]);
18
+ }
19
+
20
+ if ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
21
+ if ($option['value'] == Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED) {
22
+ unset($options[$key]);
23
+ }
24
+ } else {
25
+ if ($option['value'] == Eway_Rapid31_Model_Config::ORDER_STATUS_CAPTURED) {
26
+ unset($options[$key]);
27
+ }
28
+ }
29
+ }
30
+
31
+ return $options;
32
+ }
33
  }
app/code/community/Eway/Rapid31/Test/Model/Abstract.php CHANGED
@@ -1,179 +1,179 @@
1
- <?php
2
-
3
- /**
4
- * Class Eway_Rapid31_Test_Model_Abstract
5
- */
6
- abstract class Eway_Rapid31_Test_Model_Abstract extends EcomDev_PHPUnit_Test_Case
7
- {
8
- public function setUp()
9
- {
10
- Mage::getConfig()->saveScopeSnapshot();
11
- // Reset the config object
12
- Mage::unregister('_singleton/ewayrapid/config');
13
- }
14
-
15
- public function tearDown()
16
- {
17
- Mage::getConfig()->loadScopeSnapshot();
18
- $this->flushConfigCache();
19
- }
20
-
21
- public static function assertJsonMatch($json, $expectedValue, $exact = true)
22
- {
23
- if(is_string($json)) {
24
- $json = json_decode($json, true);
25
- }
26
-
27
- if(is_string($expectedValue)) {
28
- $expectedValue = json_decode($expectedValue, true);
29
- }
30
-
31
- // if the indexes don't match, return immediately
32
- $diff = array_diff_assoc($json, $expectedValue);
33
- if(count($diff)) {
34
- self::fail("There are different items in input json: \n" . print_r($diff, true));
35
- }
36
-
37
- if($exact) {
38
- $diff = array_diff_assoc($expectedValue, $json);
39
- if(count($diff)) {
40
- self::fail("There are different items in expected json: \n" . print_r($diff, true));
41
- }
42
- }
43
-
44
- foreach($json as $k => $v) {
45
- if(is_array($v)) {
46
- self::assertJsonMatch($v, $expectedValue[$k], $exact);
47
- }
48
- }
49
- }
50
-
51
- public static function assertJsonContain($jsonNeedle, $jsonHaystack)
52
- {
53
- self::assertJsonMatch($jsonNeedle, $jsonHaystack, false);
54
- }
55
-
56
- public function getDummyCardDetails()
57
- {
58
- return Mage::getModel('ewayrapid/field_cardDetails')
59
- ->setName('Card Holder Name')
60
- ->setNumber('4444333322221111')
61
- ->setExpiryMonth('12')
62
- ->setExpiryYear('16')
63
- ->setStartMonth('')
64
- ->setStartYear('')
65
- ->setIssueNumber('')
66
- ->setCVN('123');
67
- }
68
-
69
- public function getDummyShippingAddress()
70
- {
71
- return Mage::getModel('ewayrapid/field_shippingAddress')
72
- ->setCity('Auckland')
73
- ->setFirstName('John')
74
- ->setLastName('Smith')
75
- ->setStreet1('Level 5')
76
- ->setStreet2('369 Queen Street')
77
- ->setCountry('nz')
78
- ->setPostalCode('1010')
79
- ->setPhone('09 889 0986')
80
- ->setState('');
81
- }
82
-
83
- public function getDummyLineItem($count = 1)
84
- {
85
- return Mage::getModel('ewayrapid/field_lineItem')
86
- ->setSKU('SKU' . $count)
87
- ->setDescription('Description' . $count)
88
- ->setQuantity(1)
89
- ->setUnitCost(100)
90
- ->setTax(0)
91
- ->setTotal(100);
92
- }
93
-
94
- public function getDummyLineItemArray($count = 3)
95
- {
96
- $lineItems = array();
97
- for($i = 1; $i <= 3; $i++) {
98
- $lineItems[] = $this->getDummyLineItem($i);
99
- }
100
-
101
- return $lineItems;
102
- }
103
-
104
- public function getDummyPayment()
105
- {
106
- return Mage::getModel('ewayrapid/field_payment')
107
- ->setTotalAmount(100)
108
- ->setInvoiceNumber('Inv 21540')
109
- ->setInvoiceDescription('Individual Invoice Description')
110
- ->setInvoiceReference('513456')
111
- ->setCurrencyCode('AUD');
112
- }
113
-
114
- public function getDummyCustomer()
115
- {
116
- return Mage::getModel('ewayrapid/field_customer')
117
- ->setCardDetails($this->getDummyCardDetails())
118
- ->setReference('A12345')
119
- ->setTitle('Mr.')
120
- ->setFirstName('John')
121
- ->setLastName('Smith')
122
- ->setCompanyName('Demo Shop 123')
123
- ->setJobDescription('Developer')
124
- ->setStreet1('Level 5')
125
- ->setStreet2('369 Queen Street')
126
- ->setCity('Auckland')
127
- ->setState('')
128
- ->setPostalCode('1010')
129
- ->setCountry('nz')
130
- ->setEmail('')
131
- ->setPhone('09 889 0986')
132
- ->setMobile('09 889 0986')
133
- ->setComments('')
134
- ->setFax('')
135
- ->setUrl('');
136
- }
137
-
138
- public function setConfig(array $data, $store = 'admin')
139
- {
140
- $config = Mage::getConfig();
141
- foreach ($data as $path => $value) {
142
- $fullPath = 'stores/' . $store . '/' . $path;
143
- $config->setNode($fullPath, $value);
144
- }
145
-
146
- $this->flushConfigCache();
147
- }
148
-
149
- public function flushConfigCache()
150
- {
151
- // Flush website and store configuration caches
152
- foreach (Mage::app()->getWebsites(true) as $website) {
153
- EcomDev_Utils_Reflection::setRestrictedPropertyValue(
154
- $website, '_configCache', array()
155
- );
156
- }
157
- foreach (Mage::app()->getStores(true) as $store) {
158
- EcomDev_Utils_Reflection::setRestrictedPropertyValue(
159
- $store, '_configCache', array()
160
- );
161
- }
162
- }
163
-
164
- protected function _mockSessionObject()
165
- {
166
- $sessionMock = $this->getModelMockBuilder('adminhtml/session_quote')
167
- ->disableOriginalConstructor() // This one removes session_start and other methods usage
168
- ->setMethods(null) // Enables original methods usage, because by default it overrides all methods
169
- ->getMock();
170
- $this->replaceByMock('singleton', 'adminhtml/session_quote', $sessionMock);
171
-
172
- $sessionMock = $this->getModelMockBuilder('customer/session')
173
- ->disableOriginalConstructor() // This one removes session_start and other methods usage
174
- ->setMethods(null) // Enables original methods usage, because by default it overrides all methods
175
- ->getMock();
176
- $this->replaceByMock('singleton', 'customer/session', $sessionMock);
177
-
178
- }
179
  }
1
+ <?php
2
+
3
+ /**
4
+ * Class Eway_Rapid31_Test_Model_Abstract
5
+ */
6
+ abstract class Eway_Rapid31_Test_Model_Abstract extends EcomDev_PHPUnit_Test_Case
7
+ {
8
+ public function setUp()
9
+ {
10
+ Mage::getConfig()->saveScopeSnapshot();
11
+ // Reset the config object
12
+ Mage::unregister('_singleton/ewayrapid/config');
13
+ }
14
+
15
+ public function tearDown()
16
+ {
17
+ Mage::getConfig()->loadScopeSnapshot();
18
+ $this->flushConfigCache();
19
+ }
20
+
21
+ public static function assertJsonMatch($json, $expectedValue, $exact = true)
22
+ {
23
+ if (is_string($json)) {
24
+ $json = json_decode($json, true);
25
+ }
26
+
27
+ if (is_string($expectedValue)) {
28
+ $expectedValue = json_decode($expectedValue, true);
29
+ }
30
+
31
+ // if the indexes don't match, return immediately
32
+ $diff = array_diff_assoc($json, $expectedValue);
33
+ if (count($diff)) {
34
+ self::fail("There are different items in input json: \n" . print_r($diff, true));
35
+ }
36
+
37
+ if ($exact) {
38
+ $diff = array_diff_assoc($expectedValue, $json);
39
+ if (count($diff)) {
40
+ self::fail("There are different items in expected json: \n" . print_r($diff, true));
41
+ }
42
+ }
43
+
44
+ foreach ($json as $k => $v) {
45
+ if (is_array($v)) {
46
+ self::assertJsonMatch($v, $expectedValue[$k], $exact);
47
+ }
48
+ }
49
+ }
50
+
51
+ public static function assertJsonContain($jsonNeedle, $jsonHaystack)
52
+ {
53
+ self::assertJsonMatch($jsonNeedle, $jsonHaystack, false);
54
+ }
55
+
56
+ public function getDummyCardDetails()
57
+ {
58
+ return Mage::getModel('ewayrapid/field_cardDetails')
59
+ ->setName('Card Holder Name')
60
+ ->setNumber('4444333322221111')
61
+ ->setExpiryMonth('12')
62
+ ->setExpiryYear('16')
63
+ ->setStartMonth('')
64
+ ->setStartYear('')
65
+ ->setIssueNumber('')
66
+ ->setCVN('123');
67
+ }
68
+
69
+ public function getDummyShippingAddress()
70
+ {
71
+ return Mage::getModel('ewayrapid/field_shippingAddress')
72
+ ->setCity('Auckland')
73
+ ->setFirstName('John')
74
+ ->setLastName('Smith')
75
+ ->setStreet1('Level 5')
76
+ ->setStreet2('369 Queen Street')
77
+ ->setCountry('nz')
78
+ ->setPostalCode('1010')
79
+ ->setPhone('09 889 0986')
80
+ ->setState('');
81
+ }
82
+
83
+ public function getDummyLineItem($count = 1)
84
+ {
85
+ return Mage::getModel('ewayrapid/field_lineItem')
86
+ ->setSKU('SKU' . $count)
87
+ ->setDescription('Description' . $count)
88
+ ->setQuantity(1)
89
+ ->setUnitCost(100)
90
+ ->setTax(0)
91
+ ->setTotal(100);
92
+ }
93
+
94
+ public function getDummyLineItemArray($count = 3)
95
+ {
96
+ $lineItems = array();
97
+ for ($i = 1; $i <= 3; $i++) {
98
+ $lineItems[] = $this->getDummyLineItem($i);
99
+ }
100
+
101
+ return $lineItems;
102
+ }
103
+
104
+ public function getDummyPayment()
105
+ {
106
+ return Mage::getModel('ewayrapid/field_payment')
107
+ ->setTotalAmount(100)
108
+ ->setInvoiceNumber('Inv 21540')
109
+ ->setInvoiceDescription('Individual Invoice Description')
110
+ ->setInvoiceReference('513456')
111
+ ->setCurrencyCode('AUD');
112
+ }
113
+
114
+ public function getDummyCustomer()
115
+ {
116
+ return Mage::getModel('ewayrapid/field_customer')
117
+ ->setCardDetails($this->getDummyCardDetails())
118
+ ->setReference('A12345')
119
+ ->setTitle('Mr.')
120
+ ->setFirstName('John')
121
+ ->setLastName('Smith')
122
+ ->setCompanyName('Demo Shop 123')
123
+ ->setJobDescription('Developer')
124
+ ->setStreet1('Level 5')
125
+ ->setStreet2('369 Queen Street')
126
+ ->setCity('Auckland')
127
+ ->setState('')
128
+ ->setPostalCode('1010')
129
+ ->setCountry('nz')
130
+ ->setEmail('')
131
+ ->setPhone('09 889 0986')
132
+ ->setMobile('09 889 0986')
133
+ ->setComments('')
134
+ ->setFax('')
135
+ ->setUrl('');
136
+ }
137
+
138
+ public function setConfig(array $data, $store = 'admin')
139
+ {
140
+ $config = Mage::getConfig();
141
+ foreach ($data as $path => $value) {
142
+ $fullPath = 'stores/' . $store . '/' . $path;
143
+ $config->setNode($fullPath, $value);
144
+ }
145
+
146
+ $this->flushConfigCache();
147
+ }
148
+
149
+ public function flushConfigCache()
150
+ {
151
+ // Flush website and store configuration caches
152
+ foreach (Mage::app()->getWebsites(true) as $website) {
153
+ EcomDev_Utils_Reflection::setRestrictedPropertyValue(
154
+ $website, '_configCache', array()
155
+ );
156
+ }
157
+ foreach (Mage::app()->getStores(true) as $store) {
158
+ EcomDev_Utils_Reflection::setRestrictedPropertyValue(
159
+ $store, '_configCache', array()
160
+ );
161
+ }
162
+ }
163
+
164
+ protected function _mockSessionObject()
165
+ {
166
+ $sessionMock = $this->getModelMockBuilder('adminhtml/session_quote')
167
+ ->disableOriginalConstructor() // This one removes session_start and other methods usage
168
+ ->setMethods(null) // Enables original methods usage, because by default it overrides all methods
169
+ ->getMock();
170
+ $this->replaceByMock('singleton', 'adminhtml/session_quote', $sessionMock);
171
+
172
+ $sessionMock = $this->getModelMockBuilder('customer/session')
173
+ ->disableOriginalConstructor() // This one removes session_start and other methods usage
174
+ ->setMethods(null) // Enables original methods usage, because by default it overrides all methods
175
+ ->getMock();
176
+ $this->replaceByMock('singleton', 'customer/session', $sessionMock);
177
+
178
+ }
179
  }
app/code/community/Eway/Rapid31/Test/Model/Config.php CHANGED
@@ -32,10 +32,12 @@ class Eway_Rapid31_Test_Model_Config extends Eway_Rapid31_Test_Model_Abstract
32
  {
33
  $this->_mockSessionObject();
34
 
35
- $this->setConfig(array(
 
36
  'payment/ewayrapid_notsaved/active' => 1,
37
  'payment/ewayrapid_saved/active' => 1,
38
- ));
 
39
  $this->assertEquals(1, Mage::getStoreConfig('payment/ewayrapid_notsaved/active'));
40
  $this->assertEquals(1, Mage::getStoreConfig('payment/ewayrapid_saved/active'));
41
 
@@ -44,9 +46,11 @@ class Eway_Rapid31_Test_Model_Config extends Eway_Rapid31_Test_Model_Abstract
44
 
45
  $this->assertFalse($methodNotSaved->getConfigData('active'));
46
  $this->assertFalse($methodSaved->getConfigData('active'));
47
- $this->setConfig(array(
 
48
  'payment/ewayrapid_general/active' => 1,
49
- ));
 
50
  $this->assertTrue($methodNotSaved->getConfigData('active'));
51
  $this->assertTrue($methodSaved->getConfigData('active'));
52
  }
@@ -55,9 +59,11 @@ class Eway_Rapid31_Test_Model_Config extends Eway_Rapid31_Test_Model_Abstract
55
  {
56
  $this->assertFalse(Mage::getModel('ewayrapid/config')->isEnableSSLVerification());
57
 
58
- $this->setConfig(array(
 
59
  'payment/ewayrapid_general/mode' => 'live',
60
- ));
 
61
 
62
  $this->assertTrue(Mage::getModel('ewayrapid/config')->isEnableSSLVerification());
63
  }
32
  {
33
  $this->_mockSessionObject();
34
 
35
+ $this->setConfig(
36
+ array(
37
  'payment/ewayrapid_notsaved/active' => 1,
38
  'payment/ewayrapid_saved/active' => 1,
39
+ )
40
+ );
41
  $this->assertEquals(1, Mage::getStoreConfig('payment/ewayrapid_notsaved/active'));
42
  $this->assertEquals(1, Mage::getStoreConfig('payment/ewayrapid_saved/active'));
43
 
46
 
47
  $this->assertFalse($methodNotSaved->getConfigData('active'));
48
  $this->assertFalse($methodSaved->getConfigData('active'));
49
+ $this->setConfig(
50
+ array(
51
  'payment/ewayrapid_general/active' => 1,
52
+ )
53
+ );
54
  $this->assertTrue($methodNotSaved->getConfigData('active'));
55
  $this->assertTrue($methodSaved->getConfigData('active'));
56
  }
59
  {
60
  $this->assertFalse(Mage::getModel('ewayrapid/config')->isEnableSSLVerification());
61
 
62
+ $this->setConfig(
63
+ array(
64
  'payment/ewayrapid_general/mode' => 'live',
65
+ )
66
+ );
67
 
68
  $this->assertTrue(Mage::getModel('ewayrapid/config')->isEnableSSLVerification());
69
  }
app/code/community/Eway/Rapid31/Test/Model/CustomerToken.php CHANGED
@@ -82,8 +82,7 @@ class Eway_Rapid31_Test_Model_CustomerToken extends Eway_Rapid31_Test_Model_Abst
82
  ->setToken('1234567891')
83
  ->setExpMonth(1)
84
  ->setExpYear(2015)
85
- ->setOwner('Hiep Ho 1')
86
- ;
87
  $tokens[1] = $token;
88
 
89
  $token = Mage::getModel('ewayrapid/customer_token')
@@ -94,8 +93,7 @@ class Eway_Rapid31_Test_Model_CustomerToken extends Eway_Rapid31_Test_Model_Abst
94
  ->setToken('1234567892')
95
  ->setExpMonth(2)
96
  ->setExpYear(2015)
97
- ->setOwner('Hiep Ho 2')
98
- ;
99
  $tokens[2] = $token;
100
 
101
  $token = Mage::getModel('ewayrapid/customer_token')
@@ -106,8 +104,7 @@ class Eway_Rapid31_Test_Model_CustomerToken extends Eway_Rapid31_Test_Model_Abst
106
  ->setToken('1234567893')
107
  ->setExpMonth(3)
108
  ->setExpYear(2015)
109
- ->setOwner('Hiep Ho 3')
110
- ;
111
  $tokens[3] = $token;
112
 
113
  $savedTokens->setTokens($tokens);
82
  ->setToken('1234567891')
83
  ->setExpMonth(1)
84
  ->setExpYear(2015)
85
+ ->setOwner('Hiep Ho 1');
 
86
  $tokens[1] = $token;
87
 
88
  $token = Mage::getModel('ewayrapid/customer_token')
93
  ->setToken('1234567892')
94
  ->setExpMonth(2)
95
  ->setExpYear(2015)
96
+ ->setOwner('Hiep Ho 2');
 
97
  $tokens[2] = $token;
98
 
99
  $token = Mage::getModel('ewayrapid/customer_token')
104
  ->setToken('1234567893')
105
  ->setExpMonth(3)
106
  ->setExpYear(2015)
107
+ ->setOwner('Hiep Ho 3');
 
108
  $tokens[3] = $token;
109
 
110
  $savedTokens->setTokens($tokens);
app/code/community/Eway/Rapid31/Test/Model/JsonSerializable.php CHANGED
@@ -3,7 +3,8 @@ class Eway_Rapid31_Test_Model_JsonSerializable extends Eway_Rapid31_Test_Model_A
3
  {
4
  public function testDummyData()
5
  {
6
- $this->assertJsonMatch($this->getDummyShippingAddress()->jsonSerialize(),
 
7
  '{ "FirstName": "John",
8
  "LastName": "Smith",
9
  "Street1": "Level 5",
@@ -12,9 +13,11 @@ class Eway_Rapid31_Test_Model_JsonSerializable extends Eway_Rapid31_Test_Model_A
12
  "State": "",
13
  "Country": "nz",
14
  "PostalCode": "1010",
15
- "Phone": "09 889 0986" }');
 
16
 
17
- $this->assertJsonMatch($this->getDummyCardDetails()->jsonSerialize(),
 
18
  '{ "Name": "Card Holder Name",
19
  "Number": "4444333322221111",
20
  "ExpiryMonth": "12",
@@ -22,25 +25,31 @@ class Eway_Rapid31_Test_Model_JsonSerializable extends Eway_Rapid31_Test_Model_A
22
  "StartMonth" : "",
23
  "StartYear" : "",
24
  "IssueNumber": "",
25
- "CVN": "123" }');
 
26
 
27
- $this->assertJsonMatch($this->getDummyLineItem(1)->jsonSerialize(),
 
28
  '{ "SKU": "SKU1",
29
  "Description": "Description1",
30
  "Quantity": 1,
31
  "UnitCost": 100,
32
  "Tax": 0,
33
- "Total": 100 }');
 
34
 
35
- $this->assertJsonMatch($this->getDummyPayment()->jsonSerialize(),
 
36
  '{ "TotalAmount": 100,
37
  "InvoiceNumber": "Inv 21540",
38
  "InvoiceDescription": "Individual Invoice Description",
39
  "InvoiceReference": "513456",
40
  "CurrencyCode": "AUD"
41
- }');
 
42
 
43
- $this->assertJsonMatch($this->getDummyCustomer()->jsonSerialize(),
 
44
  '{
45
  "Reference": "A12345",
46
  "Title": "Mr.",
@@ -70,7 +79,8 @@ class Eway_Rapid31_Test_Model_JsonSerializable extends Eway_Rapid31_Test_Model_A
70
  "IssueNumber": "",
71
  "CVN": "123"
72
  }
73
- }');
 
74
  }
75
 
76
  public function testRequestDirect()
@@ -87,8 +97,9 @@ class Eway_Rapid31_Test_Model_JsonSerializable extends Eway_Rapid31_Test_Model_A
87
  ->setTransactionType('Purchase')
88
  ->setMethod('ProcessPayment');
89
 
90
- $this->assertJsonMatch($request->jsonSerialize(),
91
- '{ "Customer": {
 
92
  "Reference": "A12345",
93
  "Title": "Mr.",
94
  "FirstName": "John",
@@ -168,14 +179,16 @@ class Eway_Rapid31_Test_Model_JsonSerializable extends Eway_Rapid31_Test_Model_A
168
  "PartnerID": "04A0FD665F7348A295C5B9EE95400301",
169
  "TransactionType": "Purchase",
170
  "Method": "ProcessPayment"
171
- }');
 
172
  }
173
 
174
  public function testMaskedCardDetails()
175
  {
176
  $cardDetails = $this->getDummyCardDetails();
177
  $cardDetails->shouldBeMasked();
178
- $this->assertJsonMatch($cardDetails->jsonSerialize(),
 
179
  '{ "Name": "Card Holder Name",
180
  "Number": "444433******1111",
181
  "ExpiryMonth": "**",
@@ -183,10 +196,12 @@ class Eway_Rapid31_Test_Model_JsonSerializable extends Eway_Rapid31_Test_Model_A
183
  "StartMonth" : "",
184
  "StartYear" : "",
185
  "IssueNumber": "",
186
- "CVN": "***" }');
 
187
 
188
  $cardDetails->shouldBeMasked(false);
189
- $this->assertJsonMatch($cardDetails->jsonSerialize(),
 
190
  '{ "Name": "Card Holder Name",
191
  "Number": "4444333322221111",
192
  "ExpiryMonth": "12",
@@ -194,6 +209,7 @@ class Eway_Rapid31_Test_Model_JsonSerializable extends Eway_Rapid31_Test_Model_A
194
  "StartMonth" : "",
195
  "StartYear" : "",
196
  "IssueNumber": "",
197
- "CVN": "123" }');
 
198
  }
199
  }
3
  {
4
  public function testDummyData()
5
  {
6
+ $this->assertJsonMatch(
7
+ $this->getDummyShippingAddress()->jsonSerialize(),
8
  '{ "FirstName": "John",
9
  "LastName": "Smith",
10
  "Street1": "Level 5",
13
  "State": "",
14
  "Country": "nz",
15
  "PostalCode": "1010",
16
+ "Phone": "09 889 0986" }'
17
+ );
18
 
19
+ $this->assertJsonMatch(
20
+ $this->getDummyCardDetails()->jsonSerialize(),
21
  '{ "Name": "Card Holder Name",
22
  "Number": "4444333322221111",
23
  "ExpiryMonth": "12",
25
  "StartMonth" : "",
26
  "StartYear" : "",
27
  "IssueNumber": "",
28
+ "CVN": "123" }'
29
+ );
30
 
31
+ $this->assertJsonMatch(
32
+ $this->getDummyLineItem(1)->jsonSerialize(),
33
  '{ "SKU": "SKU1",
34
  "Description": "Description1",
35
  "Quantity": 1,
36
  "UnitCost": 100,
37
  "Tax": 0,
38
+ "Total": 100 }'
39
+ );
40
 
41
+ $this->assertJsonMatch(
42
+ $this->getDummyPayment()->jsonSerialize(),
43
  '{ "TotalAmount": 100,
44
  "InvoiceNumber": "Inv 21540",
45
  "InvoiceDescription": "Individual Invoice Description",
46
  "InvoiceReference": "513456",
47
  "CurrencyCode": "AUD"
48
+ }'
49
+ );
50
 
51
+ $this->assertJsonMatch(
52
+ $this->getDummyCustomer()->jsonSerialize(),
53
  '{
54
  "Reference": "A12345",
55
  "Title": "Mr.",
79
  "IssueNumber": "",
80
  "CVN": "123"
81
  }
82
+ }'
83
+ );
84
  }
85
 
86
  public function testRequestDirect()
97
  ->setTransactionType('Purchase')
98
  ->setMethod('ProcessPayment');
99
 
100
+ $this->assertJsonMatch(
101
+ $request->jsonSerialize(),
102
+ '{ "Customer": {
103
  "Reference": "A12345",
104
  "Title": "Mr.",
105
  "FirstName": "John",
179
  "PartnerID": "04A0FD665F7348A295C5B9EE95400301",
180
  "TransactionType": "Purchase",
181
  "Method": "ProcessPayment"
182
+ }'
183
+ );
184
  }
185
 
186
  public function testMaskedCardDetails()
187
  {
188
  $cardDetails = $this->getDummyCardDetails();
189
  $cardDetails->shouldBeMasked();
190
+ $this->assertJsonMatch(
191
+ $cardDetails->jsonSerialize(),
192
  '{ "Name": "Card Holder Name",
193
  "Number": "444433******1111",
194
  "ExpiryMonth": "**",
196
  "StartMonth" : "",
197
  "StartYear" : "",
198
  "IssueNumber": "",
199
+ "CVN": "***" }'
200
+ );
201
 
202
  $cardDetails->shouldBeMasked(false);
203
+ $this->assertJsonMatch(
204
+ $cardDetails->jsonSerialize(),
205
  '{ "Name": "Card Holder Name",
206
  "Number": "4444333322221111",
207
  "ExpiryMonth": "12",
209
  "StartMonth" : "",
210
  "StartYear" : "",
211
  "IssueNumber": "",
212
+ "CVN": "123" }'
213
+ );
214
  }
215
  }
app/code/community/Eway/Rapid31/Test/Model/Response.php CHANGED
@@ -3,7 +3,8 @@ class Eway_Rapid31_Test_Model_Response extends EcomDev_PHPUnit_Test_Case
3
  {
4
  public function testResponse()
5
  {
6
- $response = Mage::getModel('ewayrapid/response')->decodeJSON('
 
7
  {
8
  "AuthorisationCode": "000000",
9
  "ResponseCode": "58",
@@ -60,7 +61,8 @@ class Eway_Rapid31_Test_Model_Response extends EcomDev_PHPUnit_Test_Case
60
  },
61
  "Errors": null
62
  }
63
- ');
 
64
 
65
  $this->assertEquals('000000', $response->getAuthorisationCode());
66
  $this->assertEquals('58', $response->getResponseCode());
3
  {
4
  public function testResponse()
5
  {
6
+ $response = Mage::getModel('ewayrapid/response')->decodeJSON(
7
+ '
8
  {
9
  "AuthorisationCode": "000000",
10
  "ResponseCode": "58",
61
  },
62
  "Errors": null
63
  }
64
+ '
65
+ );
66
 
67
  $this->assertEquals('000000', $response->getAuthorisationCode());
68
  $this->assertEquals('58', $response->getResponseCode());
app/code/community/Eway/Rapid31/controllers/Adminhtml/EwayadminController.php CHANGED
@@ -1,190 +1,238 @@
1
- <?php
2
- /**
3
- *
4
- */
5
- class Eway_Rapid31_Adminhtml_EwayadminController extends Mage_Adminhtml_Controller_Action {
6
-
7
- protected function _isAllowed() {
8
- return true;
9
- }
10
-
11
- public function indexAction() {
12
- }
13
-
14
- public function massEwayAuthorisedAction() {
15
- $data = Mage::app()->getRequest()->getPost();
16
- if(is_array($data) & isset($data['order_ids'])) {
17
- foreach($data['order_ids'] as $id) {
18
- $order = Mage::getModel('sales/order')->load($id);
19
- $order->setData('state', 'processing');
20
- $order->setData('status', Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED);
21
- $order->save();
22
-
23
- // Update user fraud status
24
- $customer_data = Mage::getModel('customer/customer')->load($order->getCustomerId());
25
- $customer_data->setData('mark_fraud', 0);
26
- $customer_data->save();
27
-
28
- // Re-order current order
29
- // ...
30
- }
31
- }
32
- // Redirect form
33
- $this->_redirectUrl(Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/index"));
34
- }
35
-
36
- public function massProcessingAction() {
37
- $data = Mage::app()->getRequest()->getPost();
38
- if(is_array($data) & isset($data['order_ids'])) {
39
- foreach($data['order_ids'] as $id) {
40
- $order = Mage::getModel('sales/order')->load($id);
41
- $order->setData('state', 'processing');
42
- $order->setData('status', 'processing');
43
- $order->save();
44
-
45
- // Update user fraud status
46
- $customer_data = Mage::getModel('customer/customer')->load($order->getCustomerId());
47
- $customer_data->setData('mark_fraud', 0);
48
- $customer_data->save();
49
-
50
- // Re-order current order
51
- // ...
52
- }
53
- }
54
- // Redirect form
55
- $this->_redirectUrl(Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/index"));
56
- }
57
-
58
- public function massVerifyEwayOrderAction() {
59
- $data = Mage::app()->getRequest()->getPost();
60
- if(is_array($data) & isset($data['order_ids'])) {
61
-
62
- foreach($data['order_ids'] as $id) {
63
-
64
- $order = Mage::getModel('sales/order')->load($id);
65
-
66
- $result = $this->__getTransaction($order->getEwayTransactionId());
67
-
68
- // Check return data
69
- $result_decode = json_decode($result);
70
-
71
- $trans = (isset($result_decode->Transactions) ? $result_decode->Transactions : array());
72
- if(!isset($trans[0])) {
73
- continue; // go to next cycle when no element is exist
74
- }
75
- $tranId = $trans[0]->TransactionID;
76
-
77
- if($trans[0]->ResponseMessage == 'A2000') { // Success - Fraud order has been approved
78
- // Create new transaction
79
- $this->__createNewTransaction($order, $tranId);
80
- // Update order status
81
- $this->__updateStatusOrder($order);
82
- // Un-mark fraud customer
83
- $this->__unMarkFraudUser($order);
84
- }
85
- }
86
- }
87
- // Redirect form
88
- $this->_redirectReferer();
89
- }
90
- private function __getTransaction($transId) {
91
- $ewayConfig = Mage::getSingleton('ewayrapid/config');
92
- $url = $ewayConfig->getRapidAPIUrl('Transaction') . '/' . $transId;
93
- $ch = curl_init($url);
94
- curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
95
- curl_setopt($ch, CURLOPT_USERPWD, $ewayConfig->getBasicAuthenticationHeader());
96
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
97
-
98
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
99
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
100
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ewayConfig->isEnableSSLVerification());
101
-
102
- $result = curl_exec($ch);
103
- return $result;
104
- }
105
-
106
- /**
107
- * Create new transaction with base order
108
- * @param $data
109
- */
110
- private function __createNewTransaction(Mage_Sales_Model_Order $order, $transId) {
111
-
112
- // Load transaction
113
- $currentTrans = Mage::getModel('sales/order_payment_transaction')
114
- ->getCollection()
115
- ->addFieldToFilter('order_id', array('eq' => $order->getEntityId()));
116
- foreach($currentTrans as $t) { }
117
- if($t == null) {
118
- $t = new Mage_Sales_Model_Order_Payment_Transaction();
119
- }
120
-
121
- $trans = new Mage_Sales_Model_Order_Payment_Transaction();
122
- // Load payment object
123
- $payment = Mage::getModel('sales/order_payment')->load($t->getPaymentId());
124
-
125
- $trans->setOrderPaymentObject($payment);
126
- $trans->setOrder($order);
127
-
128
- $trans->setParentId($t->getTransactionId());
129
- $trans->setOrderId($order->getEntityId());
130
- $trans->setPaymentId($t->getPaymentId());
131
- // Get new TxnId
132
- $break = true;
133
- for($i = 0; $i < 100; $i++) {
134
- $transId += 1;
135
- $newTrans = Mage::getModel('sales/order_payment_transaction')
136
- ->getCollection()
137
- ->addFieldToFilter('txn_id', array('eq' => $transId));
138
- if(count($newTrans) == 0) {
139
- $break = false;
140
- break;
141
- }
142
- }
143
- if($break) {
144
- return false;
145
- }
146
- $trans->setTxnId($transId);
147
-
148
- $trans->setParentTxnId($t->getTxnId());
149
- $trans->setTxnType($t->getTxnType());
150
- $trans->setIsClosed($t->getIsClosed());
151
- $trans->setCreatedAt(date('Y-m-d H:i:s'));
152
-
153
- try {
154
- $trans->save();
155
- } catch(Exception $e) {
156
- // Do something
157
- }
158
- return true;
159
-
160
- }
161
-
162
- private function __updateStatusOrder(Mage_Sales_Model_Order $order) {
163
- $state_config = Mage::getStoreConfig('payment/ewayrapid_general/verify_eway_order');
164
-
165
- $order->setState($state_config);
166
- $order->setStatus($state_config);
167
- $order->save();
168
- }
169
-
170
- private function __unMarkFraudUser(Mage_Sales_Model_Order $order) {
171
- if ($uid = $order->getCustomerId()) {
172
- $customer = Mage::getModel('customer/customer')->load($uid);
173
- $customer->setMarkFraud(0);
174
- $customer->save();
175
- }
176
- }
177
-
178
- public function ewayordersAction()
179
- {
180
- $this->loadLayout();
181
- $this->renderLayout();
182
- }
183
-
184
- public function gridAction()
185
- {
186
- $this->loadLayout(false);
187
- $this->renderLayout();
188
- }
189
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  }
1
+ <?php
2
+ /**
3
+ *
4
+ */
5
+ class Eway_Rapid31_Adminhtml_EwayadminController extends Mage_Adminhtml_Controller_Action
6
+ {
7
+ const DEBUG_FILE = 'ewayrapid31_api_request.log';
8
+
9
+ /**
10
+ * @var Eway_Rapid31_Model_Config
11
+ */
12
+ protected $_config = null;
13
+
14
+ protected function _construct()
15
+ {
16
+ $this->_config = Mage::getSingleton('ewayrapid/config');
17
+ }
18
+
19
+ protected function _isAllowed()
20
+ {
21
+ return true;
22
+ }
23
+
24
+ public function indexAction()
25
+ {
26
+ }
27
+
28
+ public function massEwayAuthorisedAction()
29
+ {
30
+ $data = Mage::app()->getRequest()->getPost();
31
+ if (is_array($data) & isset($data['order_ids'])) {
32
+ foreach ($data['order_ids'] as $id) {
33
+ $order = Mage::getModel('sales/order')->load($id);
34
+ $order->setData('state', 'processing');
35
+ $order->setData('status', Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED);
36
+ $order->save();
37
+
38
+ // Update user fraud status
39
+ $customerData = Mage::getModel('customer/customer')->load($order->getCustomerId());
40
+ $customerData->setData('mark_fraud', 0);
41
+ $customerData->save();
42
+
43
+ // Re-order current order
44
+ // ...
45
+ }
46
+ }
47
+ // Redirect form
48
+ $this->_redirectUrl(Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/index"));
49
+ }
50
+
51
+ public function massProcessingAction()
52
+ {
53
+ $data = Mage::app()->getRequest()->getPost();
54
+ if (is_array($data) & isset($data['order_ids'])) {
55
+ foreach ($data['order_ids'] as $id) {
56
+ $order = Mage::getModel('sales/order')->load($id);
57
+ $order->setData('state', 'processing');
58
+ $order->setData('status', 'processing');
59
+ $order->save();
60
+
61
+ // Update user fraud status
62
+ $customerData = Mage::getModel('customer/customer')->load($order->getCustomerId());
63
+ $customerData->setData('mark_fraud', 0);
64
+ $customerData->save();
65
+
66
+ // Re-order current order
67
+ // ...
68
+ }
69
+ }
70
+ // Redirect form
71
+ $this->_redirectUrl(Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/index"));
72
+ }
73
+
74
+ public function massVerifyEwayOrderAction()
75
+ {
76
+ $data = Mage::app()->getRequest()->getPost();
77
+ if (is_array($data) & isset($data['order_ids'])) {
78
+
79
+ foreach ($data['order_ids'] as $id) {
80
+
81
+ $order = Mage::getModel('sales/order')->load($id);
82
+
83
+ $result = $this->__getTransaction($order->getEwayTransactionId());
84
+
85
+ // Check return data
86
+ $resultDecode = json_decode($result);
87
+
88
+ $trans = (isset($resultDecode->Transactions) ? $resultDecode->Transactions : array());
89
+ if (!isset($trans[0])) {
90
+ continue; // go to next cycle when no element is exist
91
+ }
92
+ $tranId = $trans[0]->TransactionID;
93
+
94
+ if ($trans[0]->ResponseMessage == 'A2000' || $trans[0]->ResponseMessage == 'A2008') { // Success - Fraud order has been approved
95
+ // Create new transaction
96
+ $this->__createNewTransaction($order, $tranId);
97
+ // Update order status
98
+ $this->__updateStatusOrder($order);
99
+ // Un-mark fraud customer
100
+ $this->__unMarkFraudUser($order);
101
+ }
102
+ }
103
+ }
104
+ // Redirect form
105
+ $this->_redirectReferer();
106
+ }
107
+
108
+ /**
109
+ * Queries an eWAY Transacion
110
+ *
111
+ * @param int $transId
112
+ * @return string Raw JSON result
113
+ */
114
+ private function __getTransaction($transId)
115
+ {
116
+
117
+ $url = $this->_config->getRapidAPIUrl('Transaction') . '/' . $transId;
118
+ $mode = $this->_config->isSandbox() ? '(Sandbox)' : '(Live)';
119
+ $this->_log('>>>>> START REQUEST ' . $mode . ' (GET) ' . ' : ' . $url);
120
+
121
+ $ch = curl_init($url);
122
+ curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json", "X-EWAY-APIVERSION: 40"));
123
+ curl_setopt($ch, CURLOPT_USERPWD, $this->_config->getBasicAuthenticationHeader());
124
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
125
+
126
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
127
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
128
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->_config->isEnableSSLVerification());
129
+
130
+ $result = curl_exec($ch);
131
+
132
+ $this->_log('<<<<< RESPONSE:');
133
+ if ($this->_config->isDebug()) {
134
+ $this->_log('SUCCESS. Response body: ');
135
+ $this->_log(print_r(json_decode($result, true), true));
136
+ }
137
+
138
+ return $result;
139
+ }
140
+
141
+ /**
142
+ * Create new transaction with base order
143
+ *
144
+ * @param Mage_Sales_Model_Order $order
145
+ * @param int eWAY tranasction ID
146
+ */
147
+ private function __createNewTransaction(Mage_Sales_Model_Order $order, $transId)
148
+ {
149
+
150
+ // Load transaction
151
+ $currentTrans = Mage::getModel('sales/order_payment_transaction')
152
+ ->getCollection()
153
+ ->addFieldToFilter('order_id', array('eq' => $order->getEntityId()));
154
+ foreach ($currentTrans as $t) {
155
+ }
156
+ if ($t == null) {
157
+ $t = new Mage_Sales_Model_Order_Payment_Transaction();
158
+ }
159
+
160
+ $trans = new Mage_Sales_Model_Order_Payment_Transaction();
161
+ // Load payment object
162
+ $payment = Mage::getModel('sales/order_payment')->load($t->getPaymentId());
163
+
164
+ $trans->setOrderPaymentObject($payment);
165
+ $trans->setOrder($order);
166
+
167
+ $trans->setParentId($t->getTransactionId());
168
+ $trans->setOrderId($order->getEntityId());
169
+ $trans->setPaymentId($t->getPaymentId());
170
+ // Get new TxnId
171
+ $break = true;
172
+ for ($i = 0; $i < 100; $i++) {
173
+ $transId++;
174
+ $newTrans = Mage::getModel('sales/order_payment_transaction')
175
+ ->getCollection()
176
+ ->addFieldToFilter('txn_id', array('eq' => $transId));
177
+ if (count($newTrans) == 0) {
178
+ $break = false;
179
+ break;
180
+ }
181
+ }
182
+ if ($break) {
183
+ return false;
184
+ }
185
+ $trans->setTxnId($transId);
186
+
187
+ $trans->setParentTxnId($t->getTxnId());
188
+ $trans->setTxnType($t->getTxnType());
189
+ $trans->setIsClosed($t->getIsClosed());
190
+ $trans->setCreatedAt(date('Y-m-d H:i:s'));
191
+
192
+ try {
193
+ $trans->save();
194
+ } catch(Exception $e) {
195
+ // Do something
196
+ }
197
+ return true;
198
+
199
+ }
200
+
201
+ private function __updateStatusOrder(Mage_Sales_Model_Order $order)
202
+ {
203
+ $stateConfig = Mage::getStoreConfig('payment/ewayrapid_general/verify_eway_order');
204
+
205
+ $order->setState($stateConfig);
206
+ $order->setStatus($stateConfig);
207
+ $order->save();
208
+ }
209
+
210
+ private function __unMarkFraudUser(Mage_Sales_Model_Order $order)
211
+ {
212
+ if ($uid = $order->getCustomerId()) {
213
+ $customer = Mage::getModel('customer/customer')->load($uid);
214
+ $customer->setMarkFraud(0);
215
+ $customer->save();
216
+ }
217
+ }
218
+
219
+ public function ewayordersAction()
220
+ {
221
+ $this->loadLayout();
222
+ $this->renderLayout();
223
+ }
224
+
225
+ public function gridAction()
226
+ {
227
+ $this->loadLayout(false);
228
+ $this->renderLayout();
229
+ }
230
+
231
+ protected function _log($message, $file = self::DEBUG_FILE)
232
+ {
233
+ if ($this->_config->isDebug()) {
234
+ Mage::log($message, Zend_Log::DEBUG, $file, true);
235
+ }
236
+ }
237
+
238
  }
app/code/community/Eway/Rapid31/controllers/Adminhtml/Ewayrapid/SavedcardController.php CHANGED
@@ -1,301 +1,307 @@
1
- <?php
2
-
3
- class Eway_Rapid31_Adminhtml_Ewayrapid_SavedcardController extends Mage_Adminhtml_Controller_Action {
4
-
5
- protected function _isAllowed() {
6
- return true;
7
- }
8
-
9
- public function loadAction()
10
- {
11
- $request = $this->getRequest();
12
- $tokenId = $request->getParam('token_id');
13
- $message = array(
14
- 'message' => $this->__('Invalid request'),
15
- 'success' => false
16
- );
17
-
18
- if($tokenId && is_numeric($tokenId) && $tokenId > 0){
19
- $customerId = $request->getParam('customer_id');
20
- $customer = Mage::getModel('customer/customer')->load($customerId);
21
- Mage::register('current_customer', $customer);
22
- $this->loadLayout();
23
- $this->getLayout()->getBlock('root')->setData('token_id', $tokenId);
24
- $this->renderLayout();
25
- }else{
26
- $this->loadLayout();
27
- $this->getLayout()->getBlock('root')->setData('token_id', 0);
28
- $this->renderLayout();
29
- }
30
-
31
-
32
- }
33
-
34
- public function newAction()
35
- {
36
- $this->_forward('edit');
37
- }
38
-
39
- public function saveAction(){
40
-
41
- $request = $this->getRequest();
42
- $params = $request->getParam('ewayrapid');
43
- $customerId = $request->getParam('customer_id');
44
- $customer = Mage::getModel('customer/customer')->load($customerId);
45
-
46
- $message = array(
47
- 'success' => false,
48
- 'message' => Mage::helper('ewayrapid')->__('Invalid request')
49
- );
50
-
51
- Mage::register('current_customer', $customer);
52
- if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
53
- $this->getResponse()->setBody(json_encode($message));
54
- return;
55
- }
56
-
57
- $apiRequest = Mage::getModel('ewayrapid/request_token');
58
- try {
59
- if (!$request->isPost() || !$params['address'] || !$params['payment']) {
60
- $this->getResponse()->setBody(json_encode($message));
61
- return;
62
- }
63
-
64
- $tokenId = $params['token_id'];
65
- if (is_numeric($tokenId) && $tokenId > 0) {
66
- list($billingAddress, $infoInstance) = $this->_generateApiParams($params);
67
-
68
- $infoInstance->setSavedToken($tokenId);
69
- $apiRequest->updateToken($billingAddress, $infoInstance);
70
-
71
- } else if (!$tokenId) {
72
- list($billingAddress, $infoInstance) = $this->_generateApiParams($params);
73
- $apiRequest->createNewToken($billingAddress, $infoInstance);
74
-
75
- $message['message'] = $this->__('Your Credit Card has been saved successfully.');
76
- $message['success'] = true;
77
- } else {
78
- $message['message'] = $this->__('Invalid token id');
79
- $message['success'] = false;
80
- $this->getResponse()->setBody(json_encode($message));
81
- return;
82
- }
83
- } catch (Mage_Core_Exception $e) {
84
- $message['message'] = $e->getMessage();
85
- $this->getResponse()->setBody(json_encode($message));
86
- return;
87
- } catch (Exception $e){
88
- $message['message'] = $e->getMessage();
89
- $this->getResponse()->setBody(json_encode($message));
90
- return;
91
- }
92
-
93
- $this->loadLayout();
94
- $this->renderLayout();
95
- }
96
-
97
- public function deleteAction(){
98
- $request = $this->getRequest();
99
- $tokenId = $request->getParam('token_id');
100
- $message = array(
101
- 'message' => $this->__('Invalid request'),
102
- 'success' => false
103
- );
104
-
105
- if($tokenId && is_numeric($tokenId) && $tokenId > 0){
106
- $customerId = $request->getParam('customer_id');
107
- $customer = Mage::getModel('customer/customer')->load($customerId);
108
- Mage::register('current_customer', $customer);
109
- Mage::helper('ewayrapid/customer')->deleteToken($tokenId);
110
- $message['success'] = true;
111
- $message['message'] = $this->__('Card deleted');
112
- $this->getResponse()->setBody(json_encode($message));
113
- return;
114
- }else{
115
- $this->getResponse()->setBody(json_encode($message));
116
- return;
117
- }
118
- }
119
-
120
- public function getAccessCodeAction(){
121
- try{
122
- $request = $this->getRequest();
123
- $params = $request->getParam('ewayrapid');
124
- $customerId = $request->getParam('customer_id');
125
- $customer = Mage::getModel('customer/customer')->load($customerId);
126
-
127
- $message = array(
128
- 'message' => $this->__('Invalid request'),
129
- 'success' => false
130
- );
131
- // Response data to client
132
- $this->getResponse()->setHeader('Content-type', 'application/json');
133
-
134
- // Enabled method save
135
- if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
136
- $this->getResponse()->setBody(json_encode($message));
137
- return;
138
- }
139
-
140
- Mage::register('current_customer', $customer);
141
- $method = 'AccessCodes';
142
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
143
- === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE ||
144
- Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
145
- === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
146
- ) {
147
- $method = 'AccessCodesShared';
148
- }
149
-
150
- $request = $this->getRequest();
151
-
152
- $apiRequest = Mage::getModel('ewayrapid/request_token');
153
- list($billingAddress, $infoInstance) = $this->_generateApiParams($params);
154
- $data = $apiRequest->createAccessCode($billingAddress, $infoInstance, $method, $request);
155
- /*
156
- * {"AccessCode":"C3AB9RIc_reC_FRm8nXsy36QddJm_-YlaZCc2ZHuhbOeR5RzX682kfgl_12-vipFpJiuPPcOyh-ToeWP--Px06J04mW1zhqKpyqRTsvz0ub9-URgih4V_rHDYoNxQHXq9Ho2l",
157
- * "Customer":{
158
- * "CardNumber":"",
159
- * "CardStartMonth":"",
160
- * "CardStartYear":"",
161
- * "CardIssueNumber":"",
162
- * "CardName":"",
163
- * "CardExpiryMonth":"",
164
- * "CardExpiryYear":"",
165
- * "IsActive":false,
166
- * "TokenCustomerID":null,
167
- * "Reference":"",
168
- * "Title":"Mr.",
169
- * "FirstName":"binh",
170
- * "LastName":"nguyen",
171
- * "CompanyName":"aaaaaa",
172
- * "JobDescription":"job",
173
- * "Street1":"Product Attributes",
174
- * "Street2":"def",
175
- * "City":"city here",
176
- * "State":"123",
177
- * "PostalCode":"1234",
178
- * "Country":"as",
179
- * "Email":"4444ddd@gmail.com",
180
- * "Phone":"0987654321",
181
- * "Mobile":"4444444444",
182
- * "Comments":"",
183
- * "Fax":"4535343",
184
- * "Url":""
185
- * },
186
- * "Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},
187
- * "FormActionURL":"https:\/\/secure-au.sandbox.ewaypayments.com\/AccessCode\/C3AB9RIc_reC_FRm8nXsy36QddJm_-YlaZCc2ZHuhbOeR5RzX682kfgl_12-vipFpJiuPPcOyh-ToeWP--Px06J04mW1zhqKpyqRTsvz0ub9-URgih4V_rHDYoNxQHXq9Ho2l",
188
- * "CompleteCheckoutURL":null,
189
- * "Errors":null}
190
- */
191
- // if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
192
- // === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE||
193
- // Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
194
- // === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
195
- // ) {
196
- // $data = $data->getData();
197
- // }
198
- $customerData = $data->getCustomer();
199
- $data->setData('street1', $customerData['Street1']);
200
- $data->setData('street2', $customerData['Street2']);
201
- $data = json_encode($data->getData());
202
- $this->getResponse()->setBody($data);
203
- }catch (Mage_Core_Exception $e) {
204
- $message['message'] = $e->getMessage();
205
- $this->getResponse()->setBody(json_encode($message));
206
- return;
207
- } catch (Exception $e){
208
- $message['message'] = $e->getMessage();
209
- $this->getResponse()->setBody(json_encode($message));
210
- return;
211
- }
212
- }
213
-
214
- public function savetokenAction(){
215
- $req = $this->getRequest();
216
-
217
- $customerId = $req->getParam('customer_id');
218
- $customer = Mage::getModel('customer/customer')->load($customerId);
219
- Mage::register('current_customer', $customer);
220
- $message = array(
221
- 'message' => $this->__('Invalid request'),
222
- 'success' => false
223
- );
224
- // Check load access code
225
- $accessCode = $req->getParam('AccessCode');
226
- $ccType = $req->getParam('ccType');
227
- $expYear = $req->getParam('expYear');
228
- $token_id = $req->getParam('token_id');
229
-
230
- if (isset($accessCode)) {
231
- $apiRequest = Mage::getModel('ewayrapid/request_token');
232
- // Retrieve data card by token key to save information
233
- $result = $apiRequest->getInfoByAccessCode($accessCode);
234
- $data = $result->getData();
235
-
236
- $token_customer_id = $data['TokenCustomerID'];
237
-
238
- /**
239
- * TEST TOKEN ID NULL
240
- */
241
- //$token_customer_id = null;
242
- /**
243
- * END TEST
244
- */
245
-
246
- if (isset($token_customer_id) && !empty($token_customer_id)) {
247
- $apiRequest = Mage::getModel('ewayrapid/request_token');
248
- $street1 = $req->getParam('street1');
249
- $street2 = $req->getParam('street2');
250
- $cardData = array(
251
- 'token' => $token_customer_id,
252
- 'ccType' => $ccType,
253
- 'expYear' => $expYear,
254
- 'token_id' => $token_id,
255
- 'startMonth' => $req->getParam('startMonth'),
256
- 'startYear' => $req->getParam('startYear'),
257
- 'issueNumber' => $req->getParam('issueNumber'),
258
- 'street1' => $street1,
259
- 'street2' => $street2
260
- );
261
- // Retrieve data card by token key and save information
262
- $apiRequest->saveInfoByTokenId($cardData);
263
- if ($req->getParam('is_default')) {
264
- Mage::helper('ewayrapid/customer')->setDefaultToken($token_id ? $token_id : Mage::helper('ewayrapid/customer')->getLastTokenId());
265
- }
266
- $this->loadLayout();
267
- $this->renderLayout();
268
- return;
269
-
270
- } else {
271
- // If error, it will be showed message ERR-002
272
- $message['message'] = $this->__('Failed to update Credit Card. Please try again later.');
273
- $this->getResponse()->setBody(json_encode($message));
274
- }
275
- }
276
- $this->getResponse()->setBody(json_encode($message));
277
- return;
278
- }
279
- /**
280
- * Generate params to post to eWAY gateway to create new token.
281
- *
282
- * @param Array $params
283
- * @return array
284
- */
285
- protected function _generateApiParams($params)
286
- {
287
- $billingAddress = Mage::getModel('customer/address');
288
- $billingAddress->addData($params['address']);
289
- $errors = $billingAddress->validate();
290
- if ($errors !== true && is_array($errors)) {
291
- Mage::throwException(implode("\n", $errors));
292
- }
293
- if($params && isset($params['payment'])){
294
- $infoInstance = new Varien_Object($params['payment']);
295
- }else{
296
- $infoInstance = new Varien_Object();
297
- }
298
-
299
- return array($billingAddress, $infoInstance);
300
- }
 
 
 
 
 
 
301
  }
1
+ <?php
2
+
3
+ class Eway_Rapid31_Adminhtml_Ewayrapid_SavedcardController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ protected function _isAllowed()
7
+ {
8
+ return true;
9
+ }
10
+
11
+ public function loadAction()
12
+ {
13
+ $request = $this->getRequest();
14
+ $tokenId = $request->getParam('token_id');
15
+ $message = array(
16
+ 'message' => $this->__('Invalid request'),
17
+ 'success' => false
18
+ );
19
+
20
+ if ($tokenId && is_numeric($tokenId) && $tokenId > 0) {
21
+ $customerId = $request->getParam('customer_id');
22
+ $customer = Mage::getModel('customer/customer')->load($customerId);
23
+ Mage::register('current_customer', $customer);
24
+ $this->loadLayout();
25
+ $this->getLayout()->getBlock('root')->setData('token_id', $tokenId);
26
+ $this->renderLayout();
27
+ } else {
28
+ $this->loadLayout();
29
+ $this->getLayout()->getBlock('root')->setData('token_id', 0);
30
+ $this->renderLayout();
31
+ }
32
+
33
+
34
+ }
35
+
36
+ public function newAction()
37
+ {
38
+ $this->_forward('edit');
39
+ }
40
+
41
+ public function saveAction()
42
+ {
43
+
44
+ $request = $this->getRequest();
45
+ $params = $request->getParam('ewayrapid');
46
+ $customerId = $request->getParam('customer_id');
47
+ $customer = Mage::getModel('customer/customer')->load($customerId);
48
+
49
+ $message = array(
50
+ 'success' => false,
51
+ 'message' => Mage::helper('ewayrapid')->__('Invalid request')
52
+ );
53
+
54
+ Mage::register('current_customer', $customer);
55
+ if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
56
+ $this->getResponse()->setBody(json_encode($message));
57
+ return;
58
+ }
59
+
60
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
61
+ try {
62
+ if (!$request->isPost() || !$params['address'] || !$params['payment']) {
63
+ $this->getResponse()->setBody(json_encode($message));
64
+ return;
65
+ }
66
+
67
+ $tokenId = $params['token_id'];
68
+ if (is_numeric($tokenId) && $tokenId > 0) {
69
+ list($billingAddress, $infoInstance) = $this->_generateApiParams($params);
70
+
71
+ $infoInstance->setSavedToken($tokenId);
72
+ $apiRequest->updateToken($billingAddress, $infoInstance);
73
+
74
+ } else if (!$tokenId) {
75
+ list($billingAddress, $infoInstance) = $this->_generateApiParams($params);
76
+ $apiRequest->createNewToken($billingAddress, $infoInstance);
77
+
78
+ $message['message'] = $this->__('Your Credit Card has been saved successfully.');
79
+ $message['success'] = true;
80
+ } else {
81
+ $message['message'] = $this->__('Invalid token id');
82
+ $message['success'] = false;
83
+ $this->getResponse()->setBody(json_encode($message));
84
+ return;
85
+ }
86
+ } catch (Mage_Core_Exception $e) {
87
+ $message['message'] = $e->getMessage();
88
+ $this->getResponse()->setBody(json_encode($message));
89
+ return;
90
+ } catch (Exception $e){
91
+ $message['message'] = $e->getMessage();
92
+ $this->getResponse()->setBody(json_encode($message));
93
+ return;
94
+ }
95
+
96
+ $this->loadLayout();
97
+ $this->renderLayout();
98
+ }
99
+
100
+ public function deleteAction()
101
+ {
102
+ $request = $this->getRequest();
103
+ $tokenId = $request->getParam('token_id');
104
+ $message = array(
105
+ 'message' => $this->__('Invalid request'),
106
+ 'success' => false
107
+ );
108
+
109
+ if ($tokenId && is_numeric($tokenId) && $tokenId > 0) {
110
+ $customerId = $request->getParam('customer_id');
111
+ $customer = Mage::getModel('customer/customer')->load($customerId);
112
+ Mage::register('current_customer', $customer);
113
+ Mage::helper('ewayrapid/customer')->deleteToken($tokenId);
114
+ $message['success'] = true;
115
+ $message['message'] = $this->__('Card deleted');
116
+ $this->getResponse()->setBody(json_encode($message));
117
+ return;
118
+ } else {
119
+ $this->getResponse()->setBody(json_encode($message));
120
+ return;
121
+ }
122
+ }
123
+
124
+ public function getAccessCodeAction()
125
+ {
126
+ try{
127
+ $request = $this->getRequest();
128
+ $params = $request->getParam('ewayrapid');
129
+ $customerId = $request->getParam('customer_id');
130
+ $customer = Mage::getModel('customer/customer')->load($customerId);
131
+
132
+ $message = array(
133
+ 'message' => $this->__('Invalid request'),
134
+ 'success' => false
135
+ );
136
+ // Response data to client
137
+ $this->getResponse()->setHeader('Content-type', 'application/json');
138
+
139
+ // Enabled method save
140
+ if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
141
+ $this->getResponse()->setBody(json_encode($message));
142
+ return;
143
+ }
144
+
145
+ Mage::register('current_customer', $customer);
146
+ $method = 'AccessCodes';
147
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
148
+ === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE ||
149
+ Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
150
+ === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
151
+ ) {
152
+ $method = 'AccessCodesShared';
153
+ }
154
+
155
+ $request = $this->getRequest();
156
+
157
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
158
+ list($billingAddress, $infoInstance) = $this->_generateApiParams($params);
159
+ $data = $apiRequest->createAccessCode($billingAddress, $infoInstance, $method, $request);
160
+ /*
161
+ * {"AccessCode":"C3AB9RIc_reC_FRm8nXsy36QddJm_-YlaZCc2ZHuhbOeR5RzX682kfgl_12-vipFpJiuPPcOyh-ToeWP--Px06J04mW1zhqKpyqRTsvz0ub9-URgih4V_rHDYoNxQHXq9Ho2l",
162
+ * "Customer":{
163
+ * "CardNumber":"",
164
+ * "CardStartMonth":"",
165
+ * "CardStartYear":"",
166
+ * "CardIssueNumber":"",
167
+ * "CardName":"",
168
+ * "CardExpiryMonth":"",
169
+ * "CardExpiryYear":"",
170
+ * "IsActive":false,
171
+ * "TokenCustomerID":null,
172
+ * "Reference":"",
173
+ * "Title":"Mr.",
174
+ * "FirstName":"binh",
175
+ * "LastName":"nguyen",
176
+ * "CompanyName":"aaaaaa",
177
+ * "JobDescription":"job",
178
+ * "Street1":"Product Attributes",
179
+ * "Street2":"def",
180
+ * "City":"city here",
181
+ * "State":"123",
182
+ * "PostalCode":"1234",
183
+ * "Country":"as",
184
+ * "Email":"4444ddd@gmail.com",
185
+ * "Phone":"0987654321",
186
+ * "Mobile":"4444444444",
187
+ * "Comments":"",
188
+ * "Fax":"4535343",
189
+ * "Url":""
190
+ * },
191
+ * "Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},
192
+ * "FormActionURL":"https:\/\/secure-au.sandbox.ewaypayments.com\/AccessCode\/C3AB9RIc_reC_FRm8nXsy36QddJm_-YlaZCc2ZHuhbOeR5RzX682kfgl_12-vipFpJiuPPcOyh-ToeWP--Px06J04mW1zhqKpyqRTsvz0ub9-URgih4V_rHDYoNxQHXq9Ho2l",
193
+ * "CompleteCheckoutURL":null,
194
+ * "Errors":null}
195
+ */
196
+ // if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
197
+ // === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE||
198
+ // Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
199
+ // === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
200
+ // ) {
201
+ // $data = $data->getData();
202
+ // }
203
+ $customerData = $data->getCustomer();
204
+ $data->setData('street1', $customerData['Street1']);
205
+ $data->setData('street2', $customerData['Street2']);
206
+ $data = json_encode($data->getData());
207
+ $this->getResponse()->setBody($data);
208
+ }catch (Mage_Core_Exception $e) {
209
+ $message['message'] = $e->getMessage();
210
+ $this->getResponse()->setBody(json_encode($message));
211
+ return;
212
+ } catch (Exception $e){
213
+ $message['message'] = $e->getMessage();
214
+ $this->getResponse()->setBody(json_encode($message));
215
+ return;
216
+ }
217
+ }
218
+
219
+ public function savetokenAction()
220
+ {
221
+ $req = $this->getRequest();
222
+
223
+ $customerId = $req->getParam('customer_id');
224
+ $customer = Mage::getModel('customer/customer')->load($customerId);
225
+ Mage::register('current_customer', $customer);
226
+ $message = array(
227
+ 'message' => $this->__('Invalid request'),
228
+ 'success' => false
229
+ );
230
+ // Check load access code
231
+ $accessCode = $req->getParam('AccessCode');
232
+ $ccType = $req->getParam('ccType');
233
+ $expYear = $req->getParam('expYear');
234
+ $tokenId = $req->getParam('token_id');
235
+
236
+ if (isset($accessCode)) {
237
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
238
+ // Retrieve data card by token key to save information
239
+ $result = $apiRequest->getInfoByAccessCode($accessCode);
240
+ $data = $result->getData();
241
+
242
+ $tokenCustomerId = $data['TokenCustomerID'];
243
+
244
+ /**
245
+ * TEST TOKEN ID NULL
246
+ */
247
+ //$token_customer_id = null;
248
+ /**
249
+ * END TEST
250
+ */
251
+
252
+ if (isset($tokenCustomerId) && !empty($tokenCustomerId)) {
253
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
254
+ $street1 = $req->getParam('street1');
255
+ $street2 = $req->getParam('street2');
256
+ $cardData = array(
257
+ 'token' => $tokenCustomerId,
258
+ 'ccType' => $ccType,
259
+ 'expYear' => $expYear,
260
+ 'token_id' => $tokenId,
261
+ 'startMonth' => $req->getParam('startMonth'),
262
+ 'startYear' => $req->getParam('startYear'),
263
+ 'issueNumber' => $req->getParam('issueNumber'),
264
+ 'street1' => $street1,
265
+ 'street2' => $street2
266
+ );
267
+ // Retrieve data card by token key and save information
268
+ $apiRequest->saveInfoByTokenId($cardData);
269
+ if ($req->getParam('is_default')) {
270
+ Mage::helper('ewayrapid/customer')->setDefaultToken($tokenId ? $tokenId : Mage::helper('ewayrapid/customer')->getLastTokenId());
271
+ }
272
+ $this->loadLayout();
273
+ $this->renderLayout();
274
+ return;
275
+
276
+ } else {
277
+ // If error, it will be showed message ERR-002
278
+ $message['message'] = $this->__('Failed to update Credit Card. Please try again later.');
279
+ $this->getResponse()->setBody(json_encode($message));
280
+ }
281
+ }
282
+ $this->getResponse()->setBody(json_encode($message));
283
+ return;
284
+ }
285
+ /**
286
+ * Generate params to post to eWAY gateway to create new token.
287
+ *
288
+ * @param Array $params
289
+ * @return array
290
+ */
291
+ protected function _generateApiParams($params)
292
+ {
293
+ $billingAddress = Mage::getModel('customer/address');
294
+ $billingAddress->addData($params['address']);
295
+ $errors = $billingAddress->validate();
296
+ if ($errors !== true && is_array($errors)) {
297
+ Mage::throwException(implode("\n", $errors));
298
+ }
299
+ if ($params && isset($params['payment'])) {
300
+ $infoInstance = new Varien_Object($params['payment']);
301
+ } else {
302
+ $infoInstance = new Varien_Object();
303
+ }
304
+
305
+ return array($billingAddress, $infoInstance);
306
+ }
307
  }
app/code/community/Eway/Rapid31/controllers/Adminhtml/Sales/Order/CreateController.php CHANGED
@@ -1,303 +1,322 @@
1
- <?php
2
- /**
3
- */
4
- require_once 'Mage/Adminhtml/controllers/Sales/Order/CreateController.php';
5
-
6
-
7
- class Eway_Rapid31_Adminhtml_Sales_Order_CreateController extends Mage_Adminhtml_Sales_Order_CreateController
8
- {
9
- /**
10
- * @var Eway_Rapid31_Model_Request_Sharedpage
11
- */
12
- protected $_checkout = null;
13
-
14
- protected $_checkoutType = 'ewayrapid/request_sharedpage';
15
-
16
- protected function _isAllowed() {
17
- return true;
18
- }
19
-
20
- public function ewayIframeAction()
21
- {
22
- $this->_processActionData('save');
23
- $postData = $this->getRequest()->getPost('order');
24
-
25
- $this->_getSession()->unsetData('iframePostQuote');
26
- $this->_getSession()->setData('iframePostQuote', $postData);
27
-
28
- $paymentData = $this->getRequest()->getPost('payment');
29
- if ($paymentData) {
30
- $paymentData['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_INTERNAL
31
- | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY
32
- | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY
33
- | Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX
34
- | Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;
35
- $this->_getOrderCreateModel()->setPaymentData($paymentData);
36
- $this->_getOrderCreateModel()->getQuote()->getPayment()->addData($paymentData);
37
- }
38
- $quote = $this->_getOrderCreateModel()->getQuote();
39
-
40
- try {
41
- $checkout = Mage::getSingleton($this->_checkoutType, array(
42
- 'quote' => $quote
43
- ));
44
-
45
- $redirectUrl = $this->getUrl('*/*/ewaysaveiframeorder');
46
- //Init AccessCode
47
- $data = $checkout->createAccessCode($redirectUrl, Mage::getUrl('*/*/cancel', array('_secure' => true)));
48
-
49
- $redirectParams = array(
50
- 'AccessCode' => $data->getAccessCode()
51
- );
52
-
53
- //New/Edit or not saved token
54
- $savedToken = $paymentData['saved_token'];
55
- $saveCard = (isset($paymentData['save_card']) ? $paymentData['save_card'] : '');
56
-
57
- if($savedToken && is_numeric($savedToken)) {
58
- $redirectParams['saved_token'] = $savedToken;
59
- } elseif($saveCard) {
60
- $redirectParams['newToken'] = 1;
61
- }
62
-
63
- $redirectUrl = $this->getUrl('*/*/ewaysaveiframeorder', $redirectParams);
64
- $result = array(
65
- 'success' => false,
66
- 'message' => '',
67
- 'url' => '',
68
- 'returnUrl' => $redirectUrl
69
- );
70
-
71
- if ($data->isSuccess()) {
72
- //Mage::getSingleton('core/session')->setData('FormActionURL', $data->getFormActionURL());
73
- if ($data->getSharedPaymentUrl()) {
74
- $result['url'] = $data->getSharedPaymentUrl();
75
- $result['success'] = true;
76
- $this->getResponse()->setBody(json_encode($result));
77
- return;
78
- }
79
- } else {
80
- $result['message'] = Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: ' . $data->getMessage() . ')');
81
- $this->getResponse()->setBody(json_encode($result));
82
- return;
83
- }
84
- } catch (Exception $e) {
85
- $result['message'] = Mage::helper('ewayrapid')->__($e->getMessage());
86
- $this->getResponse()->setBody(json_encode($result));
87
- return;
88
- }
89
-
90
- }
91
-
92
- public function ewaySaveIframeOrderAction()
93
- {
94
- try {
95
- $newToken = $this->getRequest()->getParam('newToken');
96
- $editToken = $this->getRequest()->getParam('saved_token');
97
- $accessCode = $this->getRequest()->getParam('AccessCode');
98
-
99
- $orderModel = $this->_getOrderCreateModel()
100
- ->setIsValidate(true)
101
- ->importPostData($this->_getSession()->getData('iframePostQuote'));
102
-
103
- $beagleScore = 0;
104
- $beagleVerification = array();
105
-
106
- $quote = $orderModel->getQuote();
107
- $this->_checkout = $this->_checkout = Mage::getSingleton($this->_checkoutType, array(
108
- 'quote' => $quote
109
- ));
110
-
111
- $response = $this->_checkout->getInfoByAccessCode($accessCode);
112
- // Get Fraud Information
113
- if($response->isSuccess()){
114
- $transaction = $this->_checkout->getTransaction($response['TransactionID']);
115
- if($transaction) {
116
- $fraudAction = $transaction[0]['FraudAction'];
117
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
118
- $captured = $transaction[0]['TransactionCaptured'];
119
- unset($transaction);
120
- }
121
- }
122
-
123
- if($response->getData('BeagleVerification')){
124
- $beagleVerification = $response->getData('BeagleVerification');
125
- }
126
- if($response->getData('BeagleScore') && $response->getData('BeagleScore') > 0){
127
- $beagleScore = $response->getData('BeagleScore');
128
- }
129
-
130
- if ($newToken || $editToken) {
131
- if ($response->getTokenCustomerID()) {
132
- $response = $this->_checkout->saveTokenById($response, $editToken);
133
- $response = $this->_processPayment($response);
134
- if($response->getData('BeagleVerification')){
135
- $beagleVerification = $response->getData('BeagleVerification');
136
- }
137
- if($response->getData('BeagleScore') && $response->getData('BeagleScore') > 0){
138
- $beagleScore = $response->getData('BeagleScore');
139
- }
140
- } else {
141
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. Please try again. (Error message: %s)',
142
- $response->getMessage()));
143
- }
144
- }
145
- if ($response->isSuccess()) {
146
-
147
- // Save fraud information
148
- if(is_null($fraudAction)){
149
- $fraudAction = $response->getFraudAction();
150
- }
151
- if(is_null($fraudCodes)){
152
- $fraudCodes = $response->getFraudCodes();
153
- }
154
- if(is_null($captured)){
155
- $captured = $response->getTransactionCaptured();
156
- }
157
-
158
- $beagleScore = $beagleScore ? $beagleScore : '';
159
- $orderModel->getQuote()->getPayment()
160
- ->setAdditionalInformation('successType', 'success')
161
- ->setBeagleScore($beagleScore)
162
- ->setBeagleVerification(serialize($beagleVerification))
163
- ->setFraudAction($fraudAction)
164
- ->setFraudCodes($fraudCodes)
165
- ->setTransactionCaptured($captured);
166
-
167
- Mage::getSingleton('core/session')->setData('ewayTransactionID', $response->getTransactionID());
168
- } else {
169
- Mage::throwException(Mage::helper('ewayrapid')->__('Sorry, your payment could not be processed (Message: %s). Please check your details and try again, or try an alternative payment method.',
170
- $response->getMessage()));
171
- }
172
-
173
- $order = $orderModel->createOrder();
174
- $order->setEwayTransactionId($response->getTransactionID());
175
- $order->save();
176
- $this->_getSession()->clear();
177
- Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The order has been created.'));
178
- if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
179
- $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
180
- } else {
181
- $this->_redirect('*/sales_order/index');
182
- }
183
- } catch (Mage_Payment_Model_Info_Exception $e) {
184
- $this->_getOrderCreateModel()->saveQuote();
185
- $message = $e->getMessage();
186
- if (!empty($message)) {
187
- $this->_getSession()->addError($message);
188
- }
189
- $this->_redirect('*/*/');
190
- } catch (Mage_Core_Exception $e) {
191
- $message = $e->getMessage();
192
- if (!empty($message)) {
193
- $this->_getSession()->addError($message);
194
- }
195
- $this->_redirect('*/*/');
196
- } catch (Exception $e) {
197
- $this->_getSession()->addException($e, $this->__('Order saving error: %s', $e->getMessage()));
198
- $this->_redirect('*/*/');
199
- }
200
- }
201
-
202
- /**
203
- * process Payment: authorize only or authorize & capture
204
- *
205
- * @param Eway_Rapid31_Model_Response $response
206
- * @return Eway_Rapid31_Model_Response
207
- * @throws Mage_Core_Exception
208
- */
209
- protected function _processPayment(Eway_Rapid31_Model_Response $response)
210
- {
211
- $this->_initCheckout();
212
-
213
- $cardData = $response->getCustomer();
214
-
215
- if ($cardData['CardNumber'] && $cardData['CardName']) {
216
- $response = $this->_checkout->doAuthorisation($response);
217
- $beagleScore = $response->getBeagleScore();
218
-
219
- // Get Fraud Information
220
- if($response->isSuccess()){
221
- $transaction = $this->_checkout->getTransaction($response['TransactionID']);
222
- if($transaction) {
223
- $fraudAction = $transaction[0]['FraudAction'];
224
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
225
- $captured = $transaction[0]['TransactionCaptured'];
226
- unset($transaction);
227
- }
228
- }
229
-
230
- if ($response->isSuccess()
231
- && Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE
232
- ) {
233
- $response = $this->_checkout->doCapturePayment($response);
234
-
235
- // Reload Fraud Information
236
- if($response->isSuccess()){
237
- $transaction = $this->_checkout->getTransaction($response['TransactionID']);
238
- if($transaction) {
239
- if($transaction[0]['FraudAction']){
240
- $fraudAction = $transaction[0]['FraudAction'];
241
- }
242
- if(Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage'])){
243
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
244
- }
245
- if($transaction[0]['TransactionCaptured']){
246
- $captured = $transaction[0]['TransactionCaptured'];
247
- }
248
- unset($transaction);
249
- }
250
- }
251
-
252
- }
253
- } else {
254
- if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
255
- $response = $this->_checkout->doAuthorisation($response);
256
-
257
- // Get Fraud Information
258
- if($response->isSuccess()){
259
- $transaction = $this->_checkout->getTransaction($response['TransactionID']);
260
- if($transaction) {
261
- $fraudAction = $transaction[0]['FraudAction'];
262
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
263
- $captured = $transaction[0]['TransactionCaptured'];
264
- unset($transaction);
265
- }
266
- }
267
- } elseif (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
268
- $response = $this->_checkout->doTransaction($response);
269
-
270
- // Get Fraud Information
271
- if($response->isSuccess()){
272
- $transaction = $this->_checkout->getTransaction($response['TransactionID']);
273
- if($transaction) {
274
- $fraudAction = $transaction[0]['FraudAction'];
275
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
276
- $captured = $transaction[0]['TransactionCaptured'];
277
- unset($transaction);
278
- }
279
- }
280
- }
281
- }
282
- if (!$response->isSuccess()) {
283
- Mage::throwException(Mage::helper('ewayrapid')->__('Sorry, your payment could not be processed (Message: %s). Please check your details and try again, or try an alternative payment method.',
284
- $response->getMessage()));
285
- }
286
-
287
- if($response->getBeagleScore() === null){
288
- $response->setBeagleScore($beagleScore);
289
- }
290
- $response->setFraudAction($fraudAction);
291
- $response->setFraudCodes($fraudCodes);
292
- $response->setTransactionCaptured($captured);
293
- return $response;
294
- }
295
-
296
- private function _initCheckout()
297
- {
298
- $quote = $this->_getOrderCreateModel()->getQuote();
299
- $this->_checkout = Mage::getSingleton($this->_checkoutType, array(
300
- 'quote' => $quote
301
- ));
302
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  }
1
+ <?php
2
+ /**
3
+ */
4
+ require_once 'Mage/Adminhtml/controllers/Sales/Order/CreateController.php';
5
+
6
+
7
+ class Eway_Rapid31_Adminhtml_Sales_Order_CreateController extends Mage_Adminhtml_Sales_Order_CreateController
8
+ {
9
+ /**
10
+ * @var Eway_Rapid31_Model_Request_Sharedpage
11
+ */
12
+ protected $_checkout = null;
13
+
14
+ protected $_checkoutType = 'ewayrapid/request_sharedpage';
15
+
16
+ protected function _isAllowed()
17
+ {
18
+ return true;
19
+ }
20
+
21
+ public function ewayIframeAction()
22
+ {
23
+ $this->_processActionData('save');
24
+ $postData = $this->getRequest()->getPost('order');
25
+
26
+ $this->_getSession()->unsetData('iframePostQuote');
27
+ $this->_getSession()->setData('iframePostQuote', $postData);
28
+
29
+ $paymentData = $this->getRequest()->getPost('payment');
30
+ if ($paymentData) {
31
+ $paymentData['checks'] = Mage_Payment_Model_Method_Abstract::CHECK_USE_INTERNAL
32
+ | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_COUNTRY
33
+ | Mage_Payment_Model_Method_Abstract::CHECK_USE_FOR_CURRENCY
34
+ | Mage_Payment_Model_Method_Abstract::CHECK_ORDER_TOTAL_MIN_MAX
35
+ | Mage_Payment_Model_Method_Abstract::CHECK_ZERO_TOTAL;
36
+ $this->_getOrderCreateModel()->setPaymentData($paymentData);
37
+ $this->_getOrderCreateModel()->getQuote()->getPayment()->addData($paymentData);
38
+ }
39
+ $quote = $this->_getOrderCreateModel()->getQuote();
40
+
41
+ try {
42
+ $checkout = Mage::getSingleton(
43
+ $this->_checkoutType, array(
44
+ 'quote' => $quote
45
+ )
46
+ );
47
+
48
+ $redirectUrl = $this->getUrl('*/*/ewaysaveiframeorder');
49
+ //Init AccessCode
50
+ $data = $checkout->createAccessCode($redirectUrl, Mage::getUrl('*/*/cancel', array('_secure' => true)));
51
+
52
+ $redirectParams = array(
53
+ 'AccessCode' => $data->getAccessCode()
54
+ );
55
+
56
+ //New/Edit or not saved token
57
+ $savedToken = $paymentData['saved_token'];
58
+ $saveCard = (isset($paymentData['save_card']) ? $paymentData['save_card'] : '');
59
+
60
+ if ($savedToken && is_numeric($savedToken)) {
61
+ $redirectParams['saved_token'] = $savedToken;
62
+ } elseif ($saveCard) {
63
+ $redirectParams['newToken'] = 1;
64
+ }
65
+
66
+ $redirectUrl = $this->getUrl('*/*/ewaysaveiframeorder', $redirectParams);
67
+ $result = array(
68
+ 'success' => false,
69
+ 'message' => '',
70
+ 'url' => '',
71
+ 'returnUrl' => $redirectUrl
72
+ );
73
+
74
+ if ($data->isSuccess()) {
75
+ //Mage::getSingleton('core/session')->setData('FormActionURL', $data->getFormActionURL());
76
+ if ($data->getSharedPaymentUrl()) {
77
+ $result['url'] = $data->getSharedPaymentUrl();
78
+ $result['success'] = true;
79
+ $this->getResponse()->setBody(json_encode($result));
80
+ return;
81
+ }
82
+ } else {
83
+ $result['message'] = Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: ' . $data->getMessage() . ')');
84
+ $this->getResponse()->setBody(json_encode($result));
85
+ return;
86
+ }
87
+ } catch (Exception $e) {
88
+ $result['message'] = Mage::helper('ewayrapid')->__($e->getMessage());
89
+ $this->getResponse()->setBody(json_encode($result));
90
+ return;
91
+ }
92
+
93
+ }
94
+
95
+ public function ewaySaveIframeOrderAction()
96
+ {
97
+ try {
98
+ $newToken = $this->getRequest()->getParam('newToken');
99
+ $editToken = $this->getRequest()->getParam('saved_token');
100
+ $accessCode = $this->getRequest()->getParam('AccessCode');
101
+
102
+ $orderModel = $this->_getOrderCreateModel()
103
+ ->setIsValidate(true)
104
+ ->importPostData($this->_getSession()->getData('iframePostQuote'));
105
+
106
+ $beagleScore = 0;
107
+ $beagleVerification = array();
108
+
109
+ $quote = $orderModel->getQuote();
110
+ $this->_checkout = $this->_checkout = Mage::getSingleton(
111
+ $this->_checkoutType, array(
112
+ 'quote' => $quote
113
+ )
114
+ );
115
+
116
+ $response = $this->_checkout->getInfoByAccessCode($accessCode);
117
+ // Get Fraud Information
118
+ if ($response->isSuccess()) {
119
+ $transaction = $this->_checkout->getTransaction($response['TransactionID']);
120
+ if ($transaction) {
121
+ $fraudAction = $transaction[0]['FraudAction'];
122
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
123
+ $captured = $transaction[0]['TransactionCaptured'];
124
+ unset($transaction);
125
+ }
126
+ }
127
+
128
+ if ($response->getData('BeagleVerification')) {
129
+ $beagleVerification = $response->getData('BeagleVerification');
130
+ }
131
+ if ($response->getData('BeagleScore') && $response->getData('BeagleScore') > 0) {
132
+ $beagleScore = $response->getData('BeagleScore');
133
+ }
134
+
135
+ if ($newToken || $editToken) {
136
+ if ($response->getTokenCustomerID()) {
137
+ $response = $this->_checkout->saveTokenById($response, $editToken);
138
+ $response = $this->_processPayment($response);
139
+ if ($response->getData('BeagleVerification')) {
140
+ $beagleVerification = $response->getData('BeagleVerification');
141
+ }
142
+ if ($response->getData('BeagleScore') && $response->getData('BeagleScore') > 0) {
143
+ $beagleScore = $response->getData('BeagleScore');
144
+ }
145
+ } else {
146
+ Mage::throwException(
147
+ Mage::helper('ewayrapid')->__(
148
+ 'An error occurred while making the transaction. Please try again. (Error message: %s)',
149
+ $response->getMessage()
150
+ )
151
+ );
152
+ }
153
+ }
154
+ if ($response->isSuccess()) {
155
+
156
+ // Save fraud information
157
+ if (is_null($fraudAction)) {
158
+ $fraudAction = $response->getFraudAction();
159
+ }
160
+ if (is_null($fraudCodes)) {
161
+ $fraudCodes = $response->getFraudCodes();
162
+ }
163
+ if (is_null($captured)) {
164
+ $captured = $response->getTransactionCaptured();
165
+ }
166
+
167
+ $beagleScore = $beagleScore ? $beagleScore : '';
168
+ $orderModel->getQuote()->getPayment()
169
+ ->setAdditionalInformation('successType', 'success')
170
+ ->setBeagleScore($beagleScore)
171
+ ->setBeagleVerification(serialize($beagleVerification))
172
+ ->setFraudAction($fraudAction)
173
+ ->setFraudCodes($fraudCodes)
174
+ ->setTransactionCaptured($captured);
175
+
176
+ Mage::getSingleton('core/session')->setData('ewayTransactionID', $response->getTransactionID());
177
+ } else {
178
+ Mage::throwException(
179
+ Mage::helper('ewayrapid')->__(
180
+ 'Sorry, your payment could not be processed (Message: %s). Please check your details and try again, or try an alternative payment method.',
181
+ $response->getMessage()
182
+ )
183
+ );
184
+ }
185
+
186
+ $order = $orderModel->createOrder();
187
+ $order->setEwayTransactionId($response->getTransactionID());
188
+ $order->save();
189
+ $this->_getSession()->clear();
190
+ Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The order has been created.'));
191
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
192
+ $this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));
193
+ } else {
194
+ $this->_redirect('*/sales_order/index');
195
+ }
196
+ } catch (Mage_Payment_Model_Info_Exception $e) {
197
+ $this->_getOrderCreateModel()->saveQuote();
198
+ $message = $e->getMessage();
199
+ if (!empty($message)) {
200
+ $this->_getSession()->addError($message);
201
+ }
202
+ $this->_redirect('*/*/');
203
+ } catch (Mage_Core_Exception $e) {
204
+ $message = $e->getMessage();
205
+ if (!empty($message)) {
206
+ $this->_getSession()->addError($message);
207
+ }
208
+ $this->_redirect('*/*/');
209
+ } catch (Exception $e) {
210
+ $this->_getSession()->addException($e, $this->__('Order saving error: %s', $e->getMessage()));
211
+ $this->_redirect('*/*/');
212
+ }
213
+ }
214
+
215
+ /**
216
+ * process Payment: authorize only or authorize & capture
217
+ *
218
+ * @param Eway_Rapid31_Model_Response $response
219
+ * @return Eway_Rapid31_Model_Response
220
+ * @throws Mage_Core_Exception
221
+ */
222
+ protected function _processPayment(Eway_Rapid31_Model_Response $response)
223
+ {
224
+ $this->_initCheckout();
225
+
226
+ $cardData = $response->getCustomer();
227
+
228
+ if ($cardData['CardNumber'] && $cardData['CardName']) {
229
+ $response = $this->_checkout->doAuthorisation($response);
230
+ $beagleScore = $response->getBeagleScore();
231
+
232
+ // Get Fraud Information
233
+ if ($response->isSuccess()) {
234
+ $transaction = $this->_checkout->getTransaction($response['TransactionID']);
235
+ if ($transaction) {
236
+ $fraudAction = $transaction[0]['FraudAction'];
237
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
238
+ $captured = $transaction[0]['TransactionCaptured'];
239
+ unset($transaction);
240
+ }
241
+ }
242
+
243
+ if ($response->isSuccess()
244
+ && Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE
245
+ ) {
246
+ $response = $this->_checkout->doCapturePayment($response);
247
+
248
+ // Reload Fraud Information
249
+ if ($response->isSuccess()) {
250
+ $transaction = $this->_checkout->getTransaction($response['TransactionID']);
251
+ if ($transaction) {
252
+ if ($transaction[0]['FraudAction']) {
253
+ $fraudAction = $transaction[0]['FraudAction'];
254
+ }
255
+ if (Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage'])) {
256
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
257
+ }
258
+ if ($transaction[0]['TransactionCaptured']) {
259
+ $captured = $transaction[0]['TransactionCaptured'];
260
+ }
261
+ unset($transaction);
262
+ }
263
+ }
264
+
265
+ }
266
+ } else {
267
+ if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
268
+ $response = $this->_checkout->doAuthorisation($response);
269
+
270
+ // Get Fraud Information
271
+ if ($response->isSuccess()) {
272
+ $transaction = $this->_checkout->getTransaction($response['TransactionID']);
273
+ if ($transaction) {
274
+ $fraudAction = $transaction[0]['FraudAction'];
275
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
276
+ $captured = $transaction[0]['TransactionCaptured'];
277
+ unset($transaction);
278
+ }
279
+ }
280
+ } elseif (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
281
+ $response = $this->_checkout->doTransaction($response);
282
+
283
+ // Get Fraud Information
284
+ if ($response->isSuccess()) {
285
+ $transaction = $this->_checkout->getTransaction($response['TransactionID']);
286
+ if ($transaction) {
287
+ $fraudAction = $transaction[0]['FraudAction'];
288
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
289
+ $captured = $transaction[0]['TransactionCaptured'];
290
+ unset($transaction);
291
+ }
292
+ }
293
+ }
294
+ }
295
+ if (!$response->isSuccess()) {
296
+ Mage::throwException(
297
+ Mage::helper('ewayrapid')->__(
298
+ 'Sorry, your payment could not be processed (Message: %s). Please check your details and try again, or try an alternative payment method.',
299
+ $response->getMessage()
300
+ )
301
+ );
302
+ }
303
+
304
+ if ($response->getBeagleScore() === null) {
305
+ $response->setBeagleScore($beagleScore);
306
+ }
307
+ $response->setFraudAction($fraudAction);
308
+ $response->setFraudCodes($fraudCodes);
309
+ $response->setTransactionCaptured($captured);
310
+ return $response;
311
+ }
312
+
313
+ private function _initCheckout()
314
+ {
315
+ $quote = $this->_getOrderCreateModel()->getQuote();
316
+ $this->_checkout = Mage::getSingleton(
317
+ $this->_checkoutType, array(
318
+ 'quote' => $quote
319
+ )
320
+ );
321
+ }
322
  }
app/code/community/Eway/Rapid31/controllers/MycardsController.php CHANGED
@@ -1,402 +1,408 @@
1
- <?php
2
- class Eway_Rapid31_MycardsController extends Mage_Core_Controller_Front_Action
3
- {
4
- /**
5
- * Action predispatch
6
- *
7
- * Check customer authentication
8
- */
9
- public function preDispatch()
10
- {
11
- parent::preDispatch();
12
- $loginUrl = Mage::helper('customer')->getLoginUrl();
13
-
14
- if (!Mage::getSingleton('customer/session')->authenticate($this, $loginUrl)) {
15
- $this->setFlag('', self::FLAG_NO_DISPATCH, true);
16
- }
17
- }
18
-
19
- protected function _getSession()
20
- {
21
- return Mage::getSingleton('customer/session');
22
- }
23
-
24
- /**
25
- * List all active tokens of current logged in customer
26
- */
27
- public function indexAction()
28
- {
29
- if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
30
- $this->_getSession()->addError($this->__('This feature has been disabled. Please contact site owner.'));
31
- }
32
-
33
- $this->loadLayout();
34
- $this->_initLayoutMessages('customer/session');
35
-
36
- $this->getLayout()->getBlock('head')->setTitle($this->__('My Credit Cards'));
37
-
38
- if ($block = $this->getLayout()->getBlock('customer.account.link.back')) {
39
- if (Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
40
- $block->setRefererUrl($this->_getRefererUrl());
41
- } else {
42
- $block->setRefererUrl(Mage::getUrl('customer/account/'));
43
- }
44
- }
45
- /*$session = Mage::getSingleton("customer/session", array('name'=>'frontend'));
46
- $customer = $session->getCustomer();
47
- // $customer->setMarkFraud(1);
48
- // $customer->save();
49
- echo '<pre>';
50
- print_r($customer->getData());
51
- die();*/
52
-
53
- $this->renderLayout();
54
- }
55
-
56
- /**
57
- * Display create new token screen. Do nothing, just forward to editAction
58
- */
59
- public function newAction()
60
- {
61
- $this->_forward('edit');
62
- }
63
-
64
- /**
65
- * Display edit form for both create new/edit token
66
- */
67
- public function editAction()
68
- {
69
- if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
70
- $this->_redirect('*/*/');
71
- return;
72
- }
73
-
74
- $this->loadLayout();
75
- $this->_initLayoutMessages('customer/session');
76
-
77
- $tokenId = $this->getRequest()->getParam('token_id');
78
- if (is_numeric($tokenId)) {
79
- Mage::register('current_token', Mage::helper('ewayrapid/customer')->getTokenById($tokenId)->setTokenId($tokenId));
80
- $this->getLayout()->getBlock('head')->setTitle($this->__('Edit Credit Card'));
81
- } else {
82
- $this->getLayout()->getBlock('head')->setTitle($this->__('Add New Credit Card'));
83
- }
84
- $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation');
85
- if ($navigationBlock) {
86
- $navigationBlock->setActive('ewayrapid/mycards');
87
- }
88
-
89
- if ($block = $this->getLayout()->getBlock('customer.account.link.back')) {
90
- $block->setRefererUrl($this->_getRefererUrl());
91
- }
92
- $this->renderLayout();
93
- }
94
-
95
- /**
96
- * Handle edit form saving
97
- */
98
- public function saveAction()
99
- {
100
- if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
101
- $this->_redirect('*/*/');
102
- return;
103
- }
104
-
105
- $request = $this->getRequest();
106
-
107
- $apiRequest = Mage::getModel('ewayrapid/request_token');
108
- try {
109
- if (!$request->isPost() || !$request->getParam('address') || !$request->getParam('payment')) {
110
- Mage::throwException($this->__('Invalid request'));
111
- }
112
-
113
- $tokenId = $request->getParam('token_id');
114
- if (is_numeric($tokenId)) {
115
- list($billingAddress, $infoInstance) = $this->_generateApiParams($request);
116
-
117
- $infoInstance->setSavedToken($tokenId);
118
-
119
- $apiRequest->updateToken($billingAddress, $infoInstance);
120
- if ($request->getParam('is_default')) {
121
- Mage::helper('ewayrapid/customer')->setDefaultToken($tokenId);
122
- }
123
- $this->_getSession()->addSuccess($this->__('Your Credit Card has been saved successfully.'));
124
- $this->_redirect('*/*/');
125
- } else if (!$tokenId) {
126
- list($billingAddress, $infoInstance) = $this->_generateApiParams($request);
127
- $apiRequest->createNewToken($billingAddress, $infoInstance);
128
- if ($request->getParam('is_default')) {
129
- Mage::helper('ewayrapid/customer')->setDefaultToken(Mage::helper('ewayrapid/customer')->getLastTokenId());
130
- }
131
- $this->_getSession()->addSuccess($this->__('Your Credit Card has been saved successfully.'));
132
- $this->_redirect('*/*/');
133
- } else {
134
- Mage::throwException($this->__('Invalid token id'));
135
- }
136
- } catch (Mage_Core_Exception $e) {
137
- Mage::logException($e);
138
- $token = Mage::getModel('ewayrapid/customer_token');
139
- $customerInfo = ($apiRequest->getCustomer() ? $apiRequest->getCustomer() : Mage::getModel('ewayrapid/field_customer'));
140
- $token->setOwner($infoInstance->getCcOwner())
141
- ->setExpMonth($infoInstance->getCcExpMonth())
142
- ->setExpYear($infoInstance->getCcExpYear())
143
- ->setAddress($customerInfo);
144
- if (is_numeric($tokenId)) {
145
- $oldToken = Mage::helper('ewayrapid/customer')->getTokenById($tokenId);
146
- $token->setToken($oldToken->getToken())
147
- ->setCard($oldToken->getCard())
148
- ->setTokenId($tokenId);
149
- }
150
-
151
- $this->_getSession()->setTokenInfo($token);
152
- $this->_getSession()->addError($e->getMessage());
153
- $params = is_numeric($tokenId) ? array('token_id' => $tokenId) : array();
154
- $this->_redirect('*/*/edit', $params);
155
- }
156
- }
157
-
158
- /**
159
- * Generate params to post to eWAY gateway to create new token.
160
- *
161
- * @param Mage_Core_Controller_Request_Http $request
162
- * @return array
163
- */
164
- protected function _generateApiParams($request)
165
- {
166
- $billingAddress = Mage::getModel('customer/address');
167
- $billingAddress->addData($request->getParam('address'));
168
- $errors = $billingAddress->validate();
169
- if ($errors !== true && is_array($errors)) {
170
- Mage::throwException(implode('<br/>', $errors));
171
- }
172
- $infoInstance = new Varien_Object($request->getParam('payment'));
173
- return array($billingAddress, $infoInstance);
174
- }
175
-
176
- /**
177
- * Make current token inactive
178
- */
179
- public function deleteAction()
180
- {
181
- if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
182
- $this->_redirect('*/*/');
183
- return;
184
- }
185
-
186
- try {
187
- $tokenId = $this->getRequest()->getParam('token_id');
188
- if (is_numeric($tokenId)) {
189
- Mage::helper('ewayrapid/customer')->deleteToken($tokenId);
190
- $this->_getSession()->addSuccess($this->__('Your Credit Card has been deleted successfully.'));
191
- $this->_redirect('*/*/');
192
- } else {
193
- Mage::throwException($this->__('Invalid token id'));
194
- }
195
- } catch (Mage_Core_Exception $e) {
196
- Mage::logException($e);
197
- $this->_getSession()->addError($e->getMessage());
198
- $this->_redirect('*/*/');
199
- }
200
- }
201
-
202
- /**
203
- * Set this token as default.
204
- */
205
- public function setdefaultAction()
206
- {
207
- if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
208
- $this->_redirect('*/*/');
209
- return;
210
- }
211
-
212
- try {
213
- $tokenId = $this->getRequest()->getParam('token_id');
214
- if (is_numeric($tokenId)) {
215
- Mage::helper('ewayrapid/customer')->setDefaultToken($tokenId);
216
- $this->_getSession()->addSuccess($this->__('Your Credit Card has been saved successfully.'));
217
- $this->_redirect('*/*/');
218
- } else {
219
- Mage::throwException($this->__('Invalid token id'));
220
- }
221
- } catch (Mage_Core_Exception $e) {
222
- Mage::logException($e);
223
- $this->_getSession()->addError($e->getMessage());
224
- $this->_redirect('*/*/');
225
- }
226
- }
227
-
228
- /**
229
- * Get access code with transparent redirect or responsive shared page type
230
- */
231
- public function getAccessCodeAction()
232
- {
233
- // Response data to client
234
- $this->getResponse()->setHeader('Content-type', 'application/json');
235
-
236
- // Enabled method save
237
- if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
238
- //$this->_redirect('*/*/');
239
- $this->getResponse()->setBody(json_encode(array(
240
- 'msg' => 'Access denied!'
241
- )));
242
- return;
243
- }
244
-
245
- // Check session timeout
246
- $session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
247
- if (!$session->isLoggedIn()) {
248
- $this->getResponse()->setBody(json_encode(
249
- array('login' => false)
250
- ));
251
- return;
252
- }
253
-
254
- $method = 'AccessCodes';
255
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
256
- === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE ||
257
- Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
258
- === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
259
- ) {
260
- $method = 'AccessCodesShared';
261
- }
262
-
263
- $request = $this->getRequest();
264
-
265
- $apiRequest = Mage::getModel('ewayrapid/request_token');
266
- list($billingAddress, $infoInstance) = $this->_generateApiParams($request);
267
- $data = $apiRequest->createAccessCode($billingAddress, $infoInstance, $method, $request);
268
-
269
- /*
270
- * {"AccessCode":"C3AB9RIc_reC_FRm8nXsy36QddJm_-YlaZCc2ZHuhbOeR5RzX682kfgl_12-vipFpJiuPPcOyh-ToeWP--Px06J04mW1zhqKpyqRTsvz0ub9-URgih4V_rHDYoNxQHXq9Ho2l",
271
- * "Customer":{
272
- * "CardNumber":"",
273
- * "CardStartMonth":"",
274
- * "CardStartYear":"",
275
- * "CardIssueNumber":"",
276
- * "CardName":"",
277
- * "CardExpiryMonth":"",
278
- * "CardExpiryYear":"",
279
- * "IsActive":false,
280
- * "TokenCustomerID":null,
281
- * "Reference":"",
282
- * "Title":"Mr.",
283
- * "FirstName":"binh",
284
- * "LastName":"nguyen",
285
- * "CompanyName":"aaaaaa",
286
- * "JobDescription":"job",
287
- * "Street1":"Product Attributes",
288
- * "Street2":"def",
289
- * "City":"city here",
290
- * "State":"123",
291
- * "PostalCode":"1234",
292
- * "Country":"as",
293
- * "Email":"4444ddd@gmail.com",
294
- * "Phone":"0987654321",
295
- * "Mobile":"4444444444",
296
- * "Comments":"",
297
- * "Fax":"4535343",
298
- * "Url":""
299
- * },
300
- * "Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},
301
- * "FormActionURL":"https:\/\/secure-au.sandbox.ewaypayments.com\/AccessCode\/C3AB9RIc_reC_FRm8nXsy36QddJm_-YlaZCc2ZHuhbOeR5RzX682kfgl_12-vipFpJiuPPcOyh-ToeWP--Px06J04mW1zhqKpyqRTsvz0ub9-URgih4V_rHDYoNxQHXq9Ho2l",
302
- * "CompleteCheckoutURL":null,
303
- * "Errors":null}
304
- */
305
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
306
- === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
307
- ) {
308
- $data = $data->getData();
309
- return $this->_redirectUrl($data['SharedPaymentUrl']);
310
- }
311
-
312
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
313
- === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
314
- ) {
315
- $redirectUrl = $apiRequest->getRedirectUrl();
316
-
317
- $redirectUrl = Mage::getModel('core/url')->parseUrl($redirectUrl)
318
- ->setQueryParam('AccessCode',$data->getAccessCode());
319
-
320
- $redirectUrl = Mage::getUrl('*/*/saveToken', $redirectUrl->getQueryParams());
321
-
322
- $data->setReturnUrl($redirectUrl);
323
- }
324
-
325
- $data = json_encode($data->getData());
326
- $this->getResponse()->setBody($data);
327
- }
328
-
329
- /**
330
- * Save or update token with Transparent or Shared page
331
- */
332
- public function saveTokenAction()
333
- {
334
-
335
- // Check session timeout
336
- $session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
337
- if (!$session->isLoggedIn()) {
338
- $this->_redirect('*/*/');
339
- return;
340
- }
341
-
342
- $req = $this->getRequest();
343
- // Check load access code
344
- $accessCode = $req->get('AccessCode');
345
- $ccType = $req->get('ccType');
346
- $expYear = $req->get('expYear');
347
- $token_id = $req->get('token_id');
348
-
349
- if (isset($accessCode)) {
350
- $apiRequest = Mage::getModel('ewayrapid/request_token');
351
- // Retrieve data card by token key to save information
352
- $result = $apiRequest->getInfoByAccessCode($accessCode);
353
- $data = $result->getData();
354
-
355
- $token_customer_id = $data['TokenCustomerID'];
356
-
357
- /**
358
- * TEST TOKEN ID NULL
359
- */
360
- //$token_customer_id = null;
361
- /**
362
- * END TEST
363
- */
364
-
365
- if (isset($token_customer_id) && !empty($token_customer_id)) {
366
- $apiRequest = Mage::getModel('ewayrapid/request_token');
367
- $street1 = $req->get('street1');
368
- $street2 = $req->get('street2');
369
- $cardData = array(
370
- 'token' => $token_customer_id,
371
- 'ccType' => $ccType,
372
- 'expYear' => $expYear,
373
- 'token_id' => $token_id,
374
- 'startMonth' => $req->get('startMonth'),
375
- 'startYear' => $req->get('startYear'),
376
- 'issueNumber' => $req->get('issueNumber'),
377
- 'street1' => base64_decode($street1),
378
- 'street2' => base64_decode($street2)
379
- );
380
- // Retrieve data card by token key and save information
381
- $apiRequest->saveInfoByTokenId($cardData);
382
- if ($req->getParam('is_default')) {
383
- //Mage::helper('ewayrapid/customer')->getLastTokenId()
384
- Mage::helper('ewayrapid/customer')->setDefaultToken($token_id ? $token_id : Mage::helper('ewayrapid/customer')->getLastTokenId());
385
- }
386
- // Add flash message
387
- $this->_getSession()->addSuccess($this->__('Your Credit Card has been saved successfully.'));
388
- } else {
389
- // If error, it will be showed message ERR-002
390
- $this->_getSession()->addError($this->__('Failed to update Credit Card. Please try again later.'));
391
- }
392
- $this->_redirect('*/*/');
393
- }
394
-
395
- }
396
-
397
- /*
398
- public function queryFraudAction() {
399
- $cron = new Eway_Rapid31_Model_EwayCron();
400
- $cron->querySuspectFraud();
401
- }*/
 
 
 
 
 
 
402
  }
1
+ <?php
2
+ class Eway_Rapid31_MycardsController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ /**
5
+ * Action predispatch
6
+ *
7
+ * Check customer authentication
8
+ */
9
+ public function preDispatch()
10
+ {
11
+ parent::preDispatch();
12
+ $loginUrl = Mage::helper('customer')->getLoginUrl();
13
+
14
+ if (!Mage::getSingleton('customer/session')->authenticate($this, $loginUrl)) {
15
+ $this->setFlag('', self::FLAG_NO_DISPATCH, true);
16
+ }
17
+ }
18
+
19
+ protected function _getSession()
20
+ {
21
+ return Mage::getSingleton('customer/session');
22
+ }
23
+
24
+ /**
25
+ * List all active tokens of current logged in customer
26
+ */
27
+ public function indexAction()
28
+ {
29
+ if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
30
+ $this->_getSession()->addError($this->__('This feature has been disabled. Please contact site owner.'));
31
+ }
32
+
33
+ $this->loadLayout();
34
+ $this->_initLayoutMessages('customer/session');
35
+
36
+ $this->getLayout()->getBlock('head')->setTitle($this->__('My Credit Cards'));
37
+
38
+ if ($block = $this->getLayout()->getBlock('customer.account.link.back')) {
39
+ if (Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
40
+ $block->setRefererUrl($this->_getRefererUrl());
41
+ } else {
42
+ $block->setRefererUrl(Mage::getUrl('customer/account/'));
43
+ }
44
+ }
45
+ /*$session = Mage::getSingleton("customer/session", array('name'=>'frontend'));
46
+ $customer = $session->getCustomer();
47
+ // $customer->setMarkFraud(1);
48
+ // $customer->save();
49
+ echo '<pre>';
50
+ print_r($customer->getData());
51
+ die();*/
52
+
53
+ $this->renderLayout();
54
+ }
55
+
56
+ /**
57
+ * Display create new token screen. Do nothing, just forward to editAction
58
+ */
59
+ public function newAction()
60
+ {
61
+ $this->_forward('edit');
62
+ }
63
+
64
+ /**
65
+ * Display edit form for both create new/edit token
66
+ */
67
+ public function editAction()
68
+ {
69
+ if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
70
+ $this->_redirect('*/*/');
71
+ return;
72
+ }
73
+
74
+ $this->loadLayout();
75
+ $this->_initLayoutMessages('customer/session');
76
+
77
+ $tokenId = $this->getRequest()->getParam('token_id');
78
+ if (is_numeric($tokenId)) {
79
+ Mage::register('current_token', Mage::helper('ewayrapid/customer')->getTokenById($tokenId)->setTokenId($tokenId));
80
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Edit Credit Card'));
81
+ } else {
82
+ $this->getLayout()->getBlock('head')->setTitle($this->__('Add New Credit Card'));
83
+ }
84
+ $navigationBlock = $this->getLayout()->getBlock('customer_account_navigation');
85
+ if ($navigationBlock) {
86
+ $navigationBlock->setActive('ewayrapid/mycards');
87
+ }
88
+
89
+ if ($block = $this->getLayout()->getBlock('customer.account.link.back')) {
90
+ $block->setRefererUrl($this->_getRefererUrl());
91
+ }
92
+ $this->renderLayout();
93
+ }
94
+
95
+ /**
96
+ * Handle edit form saving
97
+ */
98
+ public function saveAction()
99
+ {
100
+ if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
101
+ $this->_redirect('*/*/');
102
+ return;
103
+ }
104
+
105
+ $request = $this->getRequest();
106
+
107
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
108
+ try {
109
+ if (!$request->isPost() || !$request->getParam('address') || !$request->getParam('payment')) {
110
+ Mage::throwException($this->__('Invalid request'));
111
+ }
112
+
113
+ $tokenId = $request->getParam('token_id');
114
+ if (is_numeric($tokenId)) {
115
+ list($billingAddress, $infoInstance) = $this->_generateApiParams($request);
116
+
117
+ $infoInstance->setSavedToken($tokenId);
118
+
119
+ $apiRequest->updateToken($billingAddress, $infoInstance);
120
+ if ($request->getParam('is_default')) {
121
+ Mage::helper('ewayrapid/customer')->setDefaultToken($tokenId);
122
+ }
123
+ $this->_getSession()->addSuccess($this->__('Your Credit Card has been saved successfully.'));
124
+ $this->_redirect('*/*/');
125
+ } else if (!$tokenId) {
126
+ list($billingAddress, $infoInstance) = $this->_generateApiParams($request);
127
+ $apiRequest->createNewToken($billingAddress, $infoInstance);
128
+ if ($request->getParam('is_default')) {
129
+ Mage::helper('ewayrapid/customer')->setDefaultToken(Mage::helper('ewayrapid/customer')->getLastTokenId());
130
+ }
131
+ $this->_getSession()->addSuccess($this->__('Your Credit Card has been saved successfully.'));
132
+ $this->_redirect('*/*/');
133
+ } else {
134
+ Mage::throwException($this->__('Invalid token id'));
135
+ }
136
+ } catch (Mage_Core_Exception $e) {
137
+ Mage::logException($e);
138
+ $token = Mage::getModel('ewayrapid/customer_token');
139
+ $customerInfo = ($apiRequest->getCustomer() ? $apiRequest->getCustomer() : Mage::getModel('ewayrapid/field_customer'));
140
+ $token->setOwner($infoInstance->getCcOwner())
141
+ ->setExpMonth($infoInstance->getCcExpMonth())
142
+ ->setExpYear($infoInstance->getCcExpYear())
143
+ ->setAddress($customerInfo);
144
+ if (is_numeric($tokenId)) {
145
+ $oldToken = Mage::helper('ewayrapid/customer')->getTokenById($tokenId);
146
+ $token->setToken($oldToken->getToken())
147
+ ->setCard($oldToken->getCard())
148
+ ->setTokenId($tokenId);
149
+ }
150
+
151
+ $this->_getSession()->setTokenInfo($token);
152
+ $this->_getSession()->addError($e->getMessage());
153
+ $params = is_numeric($tokenId) ? array('token_id' => $tokenId) : array();
154
+ $this->_redirect('*/*/edit', $params);
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Generate params to post to eWAY gateway to create new token.
160
+ *
161
+ * @param Mage_Core_Controller_Request_Http $request
162
+ * @return array
163
+ */
164
+ protected function _generateApiParams($request)
165
+ {
166
+ $billingAddress = Mage::getModel('customer/address');
167
+ $billingAddress->addData($request->getParam('address'));
168
+ $errors = $billingAddress->validate();
169
+ if ($errors !== true && is_array($errors)) {
170
+ Mage::throwException(implode('<br/>', $errors));
171
+ }
172
+ $infoInstance = new Varien_Object($request->getParam('payment'));
173
+ return array($billingAddress, $infoInstance);
174
+ }
175
+
176
+ /**
177
+ * Make current token inactive
178
+ */
179
+ public function deleteAction()
180
+ {
181
+ if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
182
+ $this->_redirect('*/*/');
183
+ return;
184
+ }
185
+
186
+ try {
187
+ $tokenId = $this->getRequest()->getParam('token_id');
188
+ if (is_numeric($tokenId)) {
189
+ Mage::helper('ewayrapid/customer')->deleteToken($tokenId);
190
+ $this->_getSession()->addSuccess($this->__('Your Credit Card has been deleted successfully.'));
191
+ $this->_redirect('*/*/');
192
+ } else {
193
+ Mage::throwException($this->__('Invalid token id'));
194
+ }
195
+ } catch (Mage_Core_Exception $e) {
196
+ Mage::logException($e);
197
+ $this->_getSession()->addError($e->getMessage());
198
+ $this->_redirect('*/*/');
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Set this token as default.
204
+ */
205
+ public function setdefaultAction()
206
+ {
207
+ if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
208
+ $this->_redirect('*/*/');
209
+ return;
210
+ }
211
+
212
+ try {
213
+ $tokenId = $this->getRequest()->getParam('token_id');
214
+ if (is_numeric($tokenId)) {
215
+ Mage::helper('ewayrapid/customer')->setDefaultToken($tokenId);
216
+ $this->_getSession()->addSuccess($this->__('Your Credit Card has been saved successfully.'));
217
+ $this->_redirect('*/*/');
218
+ } else {
219
+ Mage::throwException($this->__('Invalid token id'));
220
+ }
221
+ } catch (Mage_Core_Exception $e) {
222
+ Mage::logException($e);
223
+ $this->_getSession()->addError($e->getMessage());
224
+ $this->_redirect('*/*/');
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Get access code with transparent redirect or responsive shared page type
230
+ */
231
+ public function getAccessCodeAction()
232
+ {
233
+ // Response data to client
234
+ $this->getResponse()->setHeader('Content-type', 'application/json');
235
+
236
+ // Enabled method save
237
+ if (!Mage::helper('ewayrapid')->isSavedMethodEnabled()) {
238
+ //$this->_redirect('*/*/');
239
+ $this->getResponse()->setBody(
240
+ json_encode(
241
+ array(
242
+ 'msg' => 'Access denied!'
243
+ )
244
+ )
245
+ );
246
+ return;
247
+ }
248
+
249
+ // Check session timeout
250
+ $session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
251
+ if (!$session->isLoggedIn()) {
252
+ $this->getResponse()->setBody(
253
+ json_encode(
254
+ array('login' => false)
255
+ )
256
+ );
257
+ return;
258
+ }
259
+
260
+ $method = 'AccessCodes';
261
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
262
+ === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE ||
263
+ Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
264
+ === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
265
+ ) {
266
+ $method = 'AccessCodesShared';
267
+ }
268
+
269
+ $request = $this->getRequest();
270
+
271
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
272
+ list($billingAddress, $infoInstance) = $this->_generateApiParams($request);
273
+ $data = $apiRequest->createAccessCode($billingAddress, $infoInstance, $method, $request);
274
+
275
+ /*
276
+ * {"AccessCode":"C3AB9RIc_reC_FRm8nXsy36QddJm_-YlaZCc2ZHuhbOeR5RzX682kfgl_12-vipFpJiuPPcOyh-ToeWP--Px06J04mW1zhqKpyqRTsvz0ub9-URgih4V_rHDYoNxQHXq9Ho2l",
277
+ * "Customer":{
278
+ * "CardNumber":"",
279
+ * "CardStartMonth":"",
280
+ * "CardStartYear":"",
281
+ * "CardIssueNumber":"",
282
+ * "CardName":"",
283
+ * "CardExpiryMonth":"",
284
+ * "CardExpiryYear":"",
285
+ * "IsActive":false,
286
+ * "TokenCustomerID":null,
287
+ * "Reference":"",
288
+ * "Title":"Mr.",
289
+ * "FirstName":"binh",
290
+ * "LastName":"nguyen",
291
+ * "CompanyName":"aaaaaa",
292
+ * "JobDescription":"job",
293
+ * "Street1":"Product Attributes",
294
+ * "Street2":"def",
295
+ * "City":"city here",
296
+ * "State":"123",
297
+ * "PostalCode":"1234",
298
+ * "Country":"as",
299
+ * "Email":"4444ddd@gmail.com",
300
+ * "Phone":"0987654321",
301
+ * "Mobile":"4444444444",
302
+ * "Comments":"",
303
+ * "Fax":"4535343",
304
+ * "Url":""
305
+ * },
306
+ * "Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},
307
+ * "FormActionURL":"https:\/\/secure-au.sandbox.ewaypayments.com\/AccessCode\/C3AB9RIc_reC_FRm8nXsy36QddJm_-YlaZCc2ZHuhbOeR5RzX682kfgl_12-vipFpJiuPPcOyh-ToeWP--Px06J04mW1zhqKpyqRTsvz0ub9-URgih4V_rHDYoNxQHXq9Ho2l",
308
+ * "CompleteCheckoutURL":null,
309
+ * "Errors":null}
310
+ */
311
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
312
+ === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
313
+ ) {
314
+ $data = $data->getData();
315
+ return $this->_redirectUrl($data['SharedPaymentUrl']);
316
+ }
317
+
318
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
319
+ === Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME
320
+ ) {
321
+ $redirectUrl = $apiRequest->getRedirectUrl();
322
+
323
+ $redirectUrl = Mage::getModel('core/url')->parseUrl($redirectUrl)
324
+ ->setQueryParam('AccessCode', $data->getAccessCode());
325
+
326
+ $redirectUrl = Mage::getUrl('*/*/saveToken', $redirectUrl->getQueryParams());
327
+
328
+ $data->setReturnUrl($redirectUrl);
329
+ }
330
+
331
+ $data = json_encode($data->getData());
332
+ $this->getResponse()->setBody($data);
333
+ }
334
+
335
+ /**
336
+ * Save or update token with Transparent or Shared page
337
+ */
338
+ public function saveTokenAction()
339
+ {
340
+
341
+ // Check session timeout
342
+ $session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
343
+ if (!$session->isLoggedIn()) {
344
+ $this->_redirect('*/*/');
345
+ return;
346
+ }
347
+
348
+ $req = $this->getRequest();
349
+ // Check load access code
350
+ $accessCode = $req->get('AccessCode');
351
+ $ccType = $req->get('ccType');
352
+ $expYear = $req->get('expYear');
353
+ $tokenId = $req->get('token_id');
354
+
355
+ if (isset($accessCode)) {
356
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
357
+ // Retrieve data card by token key to save information
358
+ $result = $apiRequest->getInfoByAccessCode($accessCode);
359
+ $data = $result->getData();
360
+
361
+ $tokenCustomerId = $data['TokenCustomerID'];
362
+
363
+ /**
364
+ * TEST TOKEN ID NULL
365
+ */
366
+ //$token_customer_id = null;
367
+ /**
368
+ * END TEST
369
+ */
370
+
371
+ if (isset($tokenCustomerId) && !empty($tokenCustomerId)) {
372
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
373
+ $street1 = $req->get('street1');
374
+ $street2 = $req->get('street2');
375
+ $cardData = array(
376
+ 'token' => $tokenCustomerId,
377
+ 'ccType' => $ccType,
378
+ 'expYear' => $expYear,
379
+ 'token_id' => $tokenId,
380
+ 'startMonth' => $req->get('startMonth'),
381
+ 'startYear' => $req->get('startYear'),
382
+ 'issueNumber' => $req->get('issueNumber'),
383
+ 'street1' => base64_decode($street1),
384
+ 'street2' => base64_decode($street2)
385
+ );
386
+ // Retrieve data card by token key and save information
387
+ $apiRequest->saveInfoByTokenId($cardData);
388
+ if ($req->getParam('is_default')) {
389
+ //Mage::helper('ewayrapid/customer')->getLastTokenId()
390
+ Mage::helper('ewayrapid/customer')->setDefaultToken($tokenId ? $tokenId : Mage::helper('ewayrapid/customer')->getLastTokenId());
391
+ }
392
+ // Add flash message
393
+ $this->_getSession()->addSuccess($this->__('Your Credit Card has been saved successfully.'));
394
+ } else {
395
+ // If error, it will be showed message ERR-002
396
+ $this->_getSession()->addError($this->__('Failed to update Credit Card. Please try again later.'));
397
+ }
398
+ $this->_redirect('*/*/');
399
+ }
400
+
401
+ }
402
+
403
+ /*
404
+ public function queryFraudAction() {
405
+ $cron = new Eway_Rapid31_Model_EwayCron();
406
+ $cron->querySuspectFraud();
407
+ }*/
408
  }
app/code/community/Eway/Rapid31/controllers/SharedpageController.php CHANGED
@@ -1,460 +1,476 @@
1
- <?php
2
-
3
- require_once "Mage" . DS . "Checkout" . DS . "controllers" . DS . "OnepageController.php";
4
-
5
- class Eway_Rapid31_SharedpageController extends Mage_Checkout_OnepageController
6
- {
7
- /**
8
- * @var Mage_Sales_Model_Quote
9
- */
10
- protected $_quote = null;
11
-
12
- /**
13
- * @var Eway_Rapid31_Model_Request_Sharedpage
14
- */
15
- protected $_checkout = null;
16
-
17
- protected $_checkoutType = 'ewayrapid/request_sharedpage';
18
-
19
- /**
20
- * process checkout with eway Responsive Shared Page
21
- */
22
- public function startAction()
23
- {
24
- // check method available
25
- $method = $this->_getQuote()->getPayment()->getMethod();
26
- if ($method !== Eway_Rapid31_Model_Config::PAYMENT_NOT_SAVED_METHOD
27
- && $method !== Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
28
- && $method !== Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD
29
- ) {
30
- Mage::getSingleton('core/session')->addError($this->__('Payment method ' . $method . ' not available'));
31
- $this->_redirect('checkout/cart');
32
- return;
33
- }
34
- if (($method === Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
35
- || $method === Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD)
36
- && !Mage::helper('ewayrapid')->isSavedMethodEnabled()
37
- ) {
38
- Mage::getSingleton('core/session')->addError($this->__('This feature has been disabled. Please contact site owner.'));
39
- $this->_redirect('checkout/cart');
40
- return;
41
- }
42
-
43
- try {
44
- $this->_initCheckout();
45
- $data = $this->_checkout->createAccessCode(Mage::getUrl('*/*/return', array('_secure'=>true)), Mage::getUrl('*/*/cancel', array('_secure'=>true)));
46
- if ($data->isSuccess()) {
47
- Mage::getSingleton('core/session')->setData('FormActionURL', $data->getFormActionURL());
48
- if ($data->getSharedPaymentUrl()) {
49
- $this->_redirectUrl($data->getSharedPaymentUrl());
50
- return;
51
- }
52
- } else {
53
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: ' . $data->getMessage() . ')'));
54
- $this->_redirect('checkout/cart');
55
- return;
56
- }
57
-
58
- } catch (Exception $e) {
59
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__($e->getMessage()));
60
- $this->_redirect('checkout/cart');
61
- }
62
- }
63
-
64
- /**
65
- * generate a Shared Payment URL for Rapid Iframe
66
- */
67
- public function iframeAction()
68
- {
69
- // check method available
70
- $method = $this->_getQuote()->getPayment()->getMethod();
71
- if ($method !== Eway_Rapid31_Model_Config::PAYMENT_NOT_SAVED_METHOD
72
- && $method !== Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
73
- && $method !== Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD
74
- ) {
75
- Mage::getSingleton('core/session')->addError($this->__('Payment method ' . $method . ' not available'));
76
- $this->_redirect('checkout/cart');
77
- return;
78
- }
79
- if (($method === Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
80
- || $method === Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD)
81
- && !Mage::helper('ewayrapid')->isSavedMethodEnabled()
82
- ) {
83
- Mage::getSingleton('core/session')->addError($this->__('This feature has been disabled. Please contact site owner.'));
84
- $this->_redirect('checkout/cart');
85
- return;
86
- }
87
-
88
- try {
89
- $this->_initCheckout();
90
- $data = $this->_checkout->createAccessCode(Mage::getUrl('*/*/return', array('_secure'=>true)), Mage::getUrl('*/*/cancel', array('_secure'=>true)));
91
-
92
- // Save redirect url for iframe callback
93
- $redirectUrl = Mage::getModel('core/url')->parseUrl($this->_checkout->getRedirectUrl())
94
- ->setQueryParam('AccessCode',$data['AccessCode']);
95
-
96
- $redirectUrl = Mage::getUrl('*/*/return', $redirectUrl->getQueryParams());
97
-
98
- $result = array(
99
- 'success' => false,
100
- 'message' => '',
101
- 'url' => '',
102
- 'returnUrl' => $redirectUrl
103
- );
104
-
105
- if ($data->isSuccess()) {
106
- Mage::getSingleton('core/session')->setData('FormActionURL', $data->getFormActionURL());
107
- if ($data->getSharedPaymentUrl()) {
108
- $result['url'] = $data->getSharedPaymentUrl();
109
- $result['success'] = true;
110
- $this->getResponse()->setBody(json_encode($result));
111
- return;
112
- }
113
- } else {
114
- $result['message'] = Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: ' . $data->getMessage() . ')');
115
- $this->getResponse()->setBody(json_encode($result));
116
- return;
117
- }
118
-
119
- } catch (Exception $e) {
120
- $result['message'] = Mage::helper('ewayrapid')->__($e->getMessage());
121
- $this->getResponse()->setBody(json_encode($result));
122
- return;
123
- }
124
- }
125
-
126
- public function cancelAction()
127
- {
128
- $this->_redirect('checkout/cart');
129
- }
130
-
131
- /**
132
- * process payment when eway callback
133
- */
134
- public function returnAction()
135
- {
136
- try {
137
- $this->_initCheckout();
138
-
139
- $newToken = $this->getRequest()->getParam('newToken');
140
- $editToken = $this->getRequest()->getParam('editToken');
141
- $accessCode = $this->getRequest()->getParam('AccessCode');
142
-
143
- $beagleScore = 0;
144
- $beagleVerification = array();
145
-
146
- $response = $this->_checkout->getInfoByAccessCode($accessCode);
147
- // Get Fraud Information
148
- if($response->isSuccess()){
149
- $transaction = $this->_checkout->getTransaction($response['TransactionID']);
150
- if($transaction) {
151
- $fraudAction = $transaction[0]['FraudAction'];
152
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
153
- $captured = $transaction[0]['TransactionCaptured'];
154
- unset($transaction);
155
- }
156
- }
157
-
158
- if($response->getData('BeagleVerification')){
159
- $beagleVerification = $response->getData('BeagleVerification');
160
- }
161
- if($response->getData('BeagleScore') && $response->getData('BeagleScore') > 0){
162
- $beagleScore = $response->getData('BeagleScore');
163
- }
164
- if ($editToken || $newToken) {
165
- if ($response->getTokenCustomerID()) {
166
- $method = $this->_getQuote()->getPayment()->getMethod();
167
- if($method == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE){
168
- // Authorize only require to call 2 requests, create token first, then use response to authorize payment
169
- $response = $this->_checkout->saveTokenById($response, $editToken);
170
- $response = $this->_processPayment($response);
171
- }else{
172
- // Authorize & Capture using TokenPayment will create request & charge payment in one call request.
173
- // Don't need to call processPayment with token id
174
- $this->_checkout->saveTokenById($response, $editToken);
175
- }
176
- if($response->getData('BeagleVerification')){
177
- $beagleVerification = $response->getData('BeagleVerification');
178
- }
179
- if($response->getData('BeagleScore') && $response->getData('BeagleScore') > 0){
180
- $beagleScore = $response->getData('BeagleScore');
181
- }
182
- } else {
183
- Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. Please try again. (Error message: %s)',
184
- $response->getMessage()));
185
- }
186
- }
187
-
188
- $orderId = null;
189
- if ($response->isSuccess()) {
190
-
191
- // Save fraud information
192
- if(is_null($fraudAction)){
193
- $fraudAction = $response->getFraudAction();
194
- }
195
- if(is_null($fraudCodes)){
196
- $fraudCodes = $response->getFraudCodes();
197
- }
198
- if(is_null($captured)){
199
- $captured = $response->getTransactionCaptured();
200
- }
201
-
202
- $orderId = $this->storeOrder($response, 'success', $beagleScore, $beagleVerification, $fraudAction, $fraudCodes, $captured);
203
- } else {
204
- Mage::throwException(Mage::helper('ewayrapid')->__('Sorry, your payment could not be processed (Message: %s). Please check your details and try again, or try an alternative payment method.',
205
- $response->getMessage()));
206
- }
207
- if ($orderId) {
208
- $this->_redirect('checkout/onepage/success');
209
- return;
210
- }
211
- } catch (Exception $e) {
212
- Mage::getSingleton('checkout/session')->addError($e->getMessage());
213
- Mage::logException($e);
214
- $this->_redirect('checkout/cart');
215
- return;
216
- }
217
- }
218
-
219
- /**
220
- * save order
221
- *
222
- * @param Eway_Rapid31_Model_Response $response
223
- * @param string $successType
224
- * @return string
225
- */
226
- private function storeOrder($response, $successType = 'success', $beagleScore, $beagleVerification, $fraudAction, $fraudCodes, $captured)
227
- {
228
- try {
229
- // Clear the basket and save the order (including some info about how the payment went)
230
- $this->getOnepage()->getQuote()->collectTotals();
231
- $payment = $this->getOnepage()->getQuote()->getPayment();
232
- $payment->setAdditionalInformation('successType', $successType);
233
- $beagleScore = $beagleScore ? $beagleScore : '';
234
- $payment->setBeagleScore($beagleScore);
235
- $payment->setBeagleVerification(serialize($beagleVerification));
236
- $payment->setFraudAction($fraudAction);
237
- $payment->setFraudCodes($fraudCodes);
238
- $payment->setTransactionCaptured($captured);
239
- Mage::getSingleton('core/session')->setData('ewayTransactionID', $response->getTransactionID());
240
- $orderId = $this->getOnepage()->saveOrder()->getLastOrderId();
241
- $this->getOnepage()->getQuote()->setIsActive(1);
242
- try {
243
- $cartHelper = Mage::helper('checkout/cart');
244
- //Get all items from cart
245
- $items = $cartHelper->getCart()->getItems();
246
- //Loop through all of cart items
247
- foreach ($items as $item) {
248
- $itemId = $item->getItemId();
249
- //Remove items, one by one
250
- $cartHelper->getCart()->removeItem($itemId)->save();
251
- }
252
- } catch (Exception $e) {
253
- }
254
- $this->getOnepage()->getQuote()->save();
255
- return $orderId;
256
- } catch (Exception $e) {
257
- Mage::throwException(Mage::helper('ewayrapid')->__($e->getMessage()));
258
- }
259
-
260
- }
261
-
262
- /**
263
- * Get one page checkout model
264
- *
265
- * @return Mage_Checkout_Model_Type_Onepage
266
- */
267
- public function getOnepage()
268
- {
269
- return Mage::getSingleton('checkout/type_onepage');
270
- }
271
-
272
- /**
273
- * Return checkout session object
274
- *
275
- * @return Mage_Checkout_Model_Session
276
- */
277
- private function _getCheckoutSession()
278
- {
279
- return Mage::getSingleton('checkout/session');
280
- }
281
-
282
- /**
283
- * Return checkout quote object
284
- *
285
- * @return Mage_Sales_Model_Quote
286
- */
287
- private function _getQuote()
288
- {
289
- if (!$this->_quote) {
290
- $this->_quote = $this->_getCheckoutSession()->getQuote();
291
- }
292
- return $this->_quote;
293
- }
294
-
295
- private function _initCheckout()
296
- {
297
- $quote = $this->_getQuote();
298
- if (!$quote->hasItems() || $quote->getHasError()) {
299
- $this->getResponse()->setHeader('HTTP/1.1', '403 Forbidden');
300
- Mage::throwException(Mage::helper('ewayrapid')->__('Unable to initialize Shared page Checkout.'));
301
- }
302
- $this->_checkout = Mage::getSingleton($this->_checkoutType, array(
303
- 'quote' => $quote
304
- ));
305
- }
306
-
307
- /**
308
- * review order when checkout with paypal express
309
- */
310
- public function reviewAction()
311
- {
312
- try {
313
- $this->_initCheckout();
314
- $accessCode = $this->getRequest()->getParam('AccessCode');
315
- $this->_checkout->updateCustomer($accessCode);
316
- $this->loadLayout();
317
- $blockReview = $this->getLayout()->getBlock('eway.block.review');
318
- $blockReview->setQuote($this->_getQuote());
319
- $blockReview->setAccessCode($accessCode);
320
- $blockReview->setActionUrl(Mage::getUrl('*/*/saveInfoShipping'));
321
- $this->renderLayout();
322
- return;
323
- } catch (Exception $e) {
324
- Mage::getSingleton('checkout/session')->addError(
325
- $this->__('Unable to initialize Express Checkout review. Error message: ' . $e->getMessage())
326
- );
327
- Mage::logException($e);
328
- }
329
- $this->_redirect('checkout/cart');
330
- }
331
-
332
- /**
333
- * save shipping total amount to quote
334
- * send new shipping total amount to eway
335
- *
336
- * @throws Exception
337
- * @throws Mage_Core_Exception
338
- */
339
- public function saveInfoShippingAction()
340
- {
341
- $this->_initCheckout();
342
- $formActionURL = Mage::getSingleton('core/session')->getData('FormActionURL');
343
- if ($formActionURL) {
344
- Mage::getSingleton('core/session')->unsetData('FormActionURL');
345
- }
346
- $shippingMethod = $this->getRequest()->getParam('shipping_method');
347
- if ($shippingMethod) {
348
- //Save to quote
349
- $this->_quote->getShippingAddress()->setShippingMethod($shippingMethod)->save();
350
-
351
- //Get price
352
- $quote = $this->_getQuote();
353
- $cRate = $this->_checkout->getShippingByCode($shippingMethod);
354
- if ($cRate) {
355
- echo json_encode(array(
356
- 'form_action' => $formActionURL,
357
- 'input_post' => '<input type="hidden" name="EWAY_NEWSHIPPINGTOTAL" value="' . round($cRate->getPrice() * 100) . '" />'
358
- ));
359
- } else {
360
- Mage::throwException($this->__('Method not found.'));
361
- }
362
- } else {
363
- Mage::throwException($this->__('Method not support.'));
364
- }
365
- die;
366
- }
367
-
368
- /**
369
- * process Payment: authorize only or authorize & capture
370
- *
371
- * @param Eway_Rapid31_Model_Response $response
372
- * @return Eway_Rapid31_Model_Response
373
- * @throws Mage_Core_Exception
374
- */
375
- protected function _processPayment(Eway_Rapid31_Model_Response $response)
376
- {
377
- $this->_initCheckout();
378
-
379
- $cardData = $response->getCustomer();
380
-
381
- if ($cardData['CardNumber'] && $cardData['CardName']) {
382
- $beagleScore = $response->getBeagleScore();
383
-
384
- // Get Fraud Information
385
- if($response->isSuccess()){
386
- $transaction = $this->_checkout->getTransaction($response['TransactionID']);
387
- if($transaction) {
388
- $fraudAction = $transaction[0]['FraudAction'];
389
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
390
- $captured = $transaction[0]['TransactionCaptured'];
391
- unset($transaction);
392
- }
393
- }
394
-
395
- if ($response->isSuccess()
396
- && Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE
397
- ) {
398
- $response = $this->_checkout->doAuthorisation($response);
399
-
400
- // Reload Fraud Information
401
- if($response->isSuccess()){
402
- $transaction = $this->_checkout->getTransaction($response['TransactionID']);
403
- if($transaction) {
404
- if($transaction[0]['FraudAction']){
405
- $fraudAction = $transaction[0]['FraudAction'];
406
- }
407
- if(Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage'])){
408
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
409
- }
410
- if($transaction[0]['TransactionCaptured']){
411
- $captured = $transaction[0]['TransactionCaptured'];
412
- }
413
- unset($transaction);
414
- }
415
- }
416
-
417
- }
418
- } else {
419
- if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
420
- $response = $this->_checkout->doAuthorisation($response);
421
-
422
- // Get Fraud Information
423
- if($response->isSuccess()){
424
- $transaction = $this->_checkout->getTransaction($response['TransactionID']);
425
- if($transaction) {
426
- $fraudAction = $transaction[0]['FraudAction'];
427
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
428
- $captured = $transaction[0]['TransactionCaptured'];
429
- unset($transaction);
430
- }
431
- }
432
- } elseif (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
433
- $response = $this->_checkout->doTransaction($response);
434
-
435
- // Get Fraud Information
436
- if($response->isSuccess()){
437
- $transaction = $this->_checkout->getTransaction($response['TransactionID']);
438
- if($transaction) {
439
- $fraudAction = $transaction[0]['FraudAction'];
440
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
441
- $captured = $transaction[0]['TransactionCaptured'];
442
- unset($transaction);
443
- }
444
- }
445
- }
446
- }
447
- if (!$response->isSuccess()) {
448
- Mage::throwException(Mage::helper('ewayrapid')->__('Sorry, your payment could not be processed (Message: %s). Please check your details and try again, or try an alternative payment method.',
449
- $response->getMessage()));
450
- }
451
-
452
- if($response->getBeagleScore() === null){
453
- $response->setBeagleScore($beagleScore);
454
- }
455
- $response->setFraudAction($fraudAction);
456
- $response->setFraudCodes($fraudCodes);
457
- $response->setTransactionCaptured($captured);
458
- return $response;
459
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
  }
1
+ <?php
2
+
3
+ require_once "Mage" . DS . "Checkout" . DS . "controllers" . DS . "OnepageController.php";
4
+
5
+ class Eway_Rapid31_SharedpageController extends Mage_Checkout_OnepageController
6
+ {
7
+ /**
8
+ * @var Mage_Sales_Model_Quote
9
+ */
10
+ protected $_quote = null;
11
+
12
+ /**
13
+ * @var Eway_Rapid31_Model_Request_Sharedpage
14
+ */
15
+ protected $_checkout = null;
16
+
17
+ protected $_checkoutType = 'ewayrapid/request_sharedpage';
18
+
19
+ /**
20
+ * process checkout with eway Responsive Shared Page
21
+ */
22
+ public function startAction()
23
+ {
24
+ // check method available
25
+ $method = $this->_getQuote()->getPayment()->getMethod();
26
+ if ($method !== Eway_Rapid31_Model_Config::PAYMENT_NOT_SAVED_METHOD
27
+ && $method !== Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
28
+ && $method !== Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD
29
+ ) {
30
+ Mage::getSingleton('core/session')->addError($this->__('Payment method ' . $method . ' not available'));
31
+ $this->_redirect('checkout/cart');
32
+ return;
33
+ }
34
+ if (($method === Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
35
+ || $method === Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD)
36
+ && !Mage::helper('ewayrapid')->isSavedMethodEnabled()
37
+ ) {
38
+ Mage::getSingleton('core/session')->addError($this->__('This feature has been disabled. Please contact site owner.'));
39
+ $this->_redirect('checkout/cart');
40
+ return;
41
+ }
42
+
43
+ try {
44
+ $this->_initCheckout();
45
+ $data = $this->_checkout->createAccessCode(Mage::getUrl('*/*/return', array('_secure'=>true)), Mage::getUrl('*/*/cancel', array('_secure'=>true)));
46
+ if ($data->isSuccess()) {
47
+ Mage::getSingleton('core/session')->setData('FormActionURL', $data->getFormActionURL());
48
+ if ($data->getSharedPaymentUrl()) {
49
+ $this->_redirectUrl($data->getSharedPaymentUrl());
50
+ return;
51
+ }
52
+ } else {
53
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: ' . $data->getMessage() . ')'));
54
+ $this->_redirect('checkout/cart');
55
+ return;
56
+ }
57
+
58
+ } catch (Exception $e) {
59
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__($e->getMessage()));
60
+ $this->_redirect('checkout/cart');
61
+ }
62
+ }
63
+
64
+ /**
65
+ * generate a Shared Payment URL for Rapid Iframe
66
+ */
67
+ public function iframeAction()
68
+ {
69
+ // check method available
70
+ $method = $this->_getQuote()->getPayment()->getMethod();
71
+ if ($method !== Eway_Rapid31_Model_Config::PAYMENT_NOT_SAVED_METHOD
72
+ && $method !== Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
73
+ && $method !== Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD
74
+ ) {
75
+ Mage::getSingleton('core/session')->addError($this->__('Payment method ' . $method . ' not available'));
76
+ $this->_redirect('checkout/cart');
77
+ return;
78
+ }
79
+ if (($method === Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
80
+ || $method === Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD)
81
+ && !Mage::helper('ewayrapid')->isSavedMethodEnabled()
82
+ ) {
83
+ Mage::getSingleton('core/session')->addError($this->__('This feature has been disabled. Please contact site owner.'));
84
+ $this->_redirect('checkout/cart');
85
+ return;
86
+ }
87
+
88
+ try {
89
+ $this->_initCheckout();
90
+ $data = $this->_checkout->createAccessCode(Mage::getUrl('*/*/return', array('_secure'=>true)), Mage::getUrl('*/*/cancel', array('_secure'=>true)));
91
+
92
+ // Save redirect url for iframe callback
93
+ $redirectUrl = Mage::getModel('core/url')->parseUrl($this->_checkout->getRedirectUrl())
94
+ ->setQueryParam('AccessCode', $data['AccessCode']);
95
+
96
+ $redirectUrl = Mage::getUrl('*/*/return', $redirectUrl->getQueryParams());
97
+
98
+ $result = array(
99
+ 'success' => false,
100
+ 'message' => '',
101
+ 'url' => '',
102
+ 'returnUrl' => $redirectUrl
103
+ );
104
+
105
+ if ($data->isSuccess()) {
106
+ Mage::getSingleton('core/session')->setData('FormActionURL', $data->getFormActionURL());
107
+ if ($data->getSharedPaymentUrl()) {
108
+ $result['url'] = $data->getSharedPaymentUrl();
109
+ $result['success'] = true;
110
+ $this->getResponse()->setBody(json_encode($result));
111
+ return;
112
+ }
113
+ } else {
114
+ $result['message'] = Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: ' . $data->getMessage() . ')');
115
+ $this->getResponse()->setBody(json_encode($result));
116
+ return;
117
+ }
118
+
119
+ } catch (Exception $e) {
120
+ $result['message'] = Mage::helper('ewayrapid')->__($e->getMessage());
121
+ $this->getResponse()->setBody(json_encode($result));
122
+ return;
123
+ }
124
+ }
125
+
126
+ public function cancelAction()
127
+ {
128
+ $this->_redirect('checkout/cart');
129
+ }
130
+
131
+ /**
132
+ * process payment when eway callback
133
+ */
134
+ public function returnAction()
135
+ {
136
+ try {
137
+ $this->_initCheckout();
138
+
139
+ $newToken = $this->getRequest()->getParam('newToken');
140
+ $editToken = $this->getRequest()->getParam('editToken');
141
+ $accessCode = $this->getRequest()->getParam('AccessCode');
142
+
143
+ $beagleScore = 0;
144
+ $beagleVerification = array();
145
+
146
+ $response = $this->_checkout->getInfoByAccessCode($accessCode);
147
+ // Get Fraud Information
148
+ if ($response->isSuccess()) {
149
+ $transaction = $this->_checkout->getTransaction($response['TransactionID']);
150
+ if ($transaction) {
151
+ $fraudAction = $transaction[0]['FraudAction'];
152
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
153
+ $captured = $transaction[0]['TransactionCaptured'];
154
+ unset($transaction);
155
+ }
156
+ }
157
+
158
+ if ($response->getData('BeagleVerification')) {
159
+ $beagleVerification = $response->getData('BeagleVerification');
160
+ }
161
+ if ($response->getData('BeagleScore') && $response->getData('BeagleScore') > 0) {
162
+ $beagleScore = $response->getData('BeagleScore');
163
+ }
164
+ if ($editToken || $newToken) {
165
+ if ($response->getTokenCustomerID()) {
166
+ $method = $this->_getQuote()->getPayment()->getMethod();
167
+ if ($method == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
168
+ // Authorize only require to call 2 requests, create token first, then use response to authorize payment
169
+ $response = $this->_checkout->saveTokenById($response, $editToken);
170
+ $response = $this->_processPayment($response);
171
+ } else {
172
+ // Authorize & Capture using TokenPayment will create request & charge payment in one call request.
173
+ // Don't need to call processPayment with token id
174
+ $this->_checkout->saveTokenById($response, $editToken);
175
+ }
176
+ if ($response->getData('BeagleVerification')) {
177
+ $beagleVerification = $response->getData('BeagleVerification');
178
+ }
179
+ if ($response->getData('BeagleScore') && $response->getData('BeagleScore') > 0) {
180
+ $beagleScore = $response->getData('BeagleScore');
181
+ }
182
+ } else {
183
+ Mage::throwException(
184
+ Mage::helper('ewayrapid')->__(
185
+ 'An error occurred while making the transaction. Please try again. (Error message: %s)',
186
+ $response->getMessage()
187
+ )
188
+ );
189
+ }
190
+ }
191
+
192
+ $orderId = null;
193
+ if ($response->isSuccess()) {
194
+
195
+ // Save fraud information
196
+ if (is_null($fraudAction)) {
197
+ $fraudAction = $response->getFraudAction();
198
+ }
199
+ if (is_null($fraudCodes)) {
200
+ $fraudCodes = $response->getFraudCodes();
201
+ }
202
+ if (is_null($captured)) {
203
+ $captured = $response->getTransactionCaptured();
204
+ }
205
+
206
+ $orderId = $this->storeOrder($response, $beagleScore, $beagleVerification, $fraudAction, $fraudCodes, $captured, 'success');
207
+ } else {
208
+ Mage::throwException(
209
+ Mage::helper('ewayrapid')->__(
210
+ 'Sorry, your payment could not be processed (Message: %s). Please check your details and try again, or try an alternative payment method.',
211
+ $response->getMessage()
212
+ )
213
+ );
214
+ }
215
+ if ($orderId) {
216
+ $this->_redirect('checkout/onepage/success');
217
+ return;
218
+ }
219
+ } catch (Exception $e) {
220
+ Mage::getSingleton('checkout/session')->addError($e->getMessage());
221
+ Mage::logException($e);
222
+ $this->_redirect('checkout/cart');
223
+ return;
224
+ }
225
+ }
226
+
227
+ /**
228
+ * save order
229
+ *
230
+ * @param Eway_Rapid31_Model_Response $response
231
+ * @param string $successType
232
+ * @return string
233
+ */
234
+ private function storeOrder($response, $beagleScore, $beagleVerification, $fraudAction, $fraudCodes, $captured, $successType = 'success')
235
+ {
236
+ try {
237
+ // Clear the basket and save the order (including some info about how the payment went)
238
+ $this->getOnepage()->getQuote()->collectTotals();
239
+ $payment = $this->getOnepage()->getQuote()->getPayment();
240
+ $payment->setAdditionalInformation('successType', $successType);
241
+ $beagleScore = $beagleScore ? $beagleScore : '';
242
+ $payment->setBeagleScore($beagleScore);
243
+ $payment->setBeagleVerification(serialize($beagleVerification));
244
+ $payment->setFraudAction($fraudAction);
245
+ $payment->setFraudCodes($fraudCodes);
246
+ $payment->setTransactionCaptured($captured);
247
+ Mage::getSingleton('core/session')->setData('ewayTransactionID', $response->getTransactionID());
248
+ $orderId = $this->getOnepage()->saveOrder()->getLastOrderId();
249
+ $this->getOnepage()->getQuote()->setIsActive(1);
250
+ try {
251
+ $cartHelper = Mage::helper('checkout/cart');
252
+ //Get all items from cart
253
+ $items = $cartHelper->getCart()->getItems();
254
+ //Loop through all of cart items
255
+ foreach ($items as $item) {
256
+ $itemId = $item->getItemId();
257
+ //Remove items, one by one
258
+ $cartHelper->getCart()->removeItem($itemId)->save();
259
+ }
260
+ } catch (Exception $e) {
261
+ }
262
+ $this->getOnepage()->getQuote()->save();
263
+ return $orderId;
264
+ } catch (Exception $e) {
265
+ Mage::throwException(Mage::helper('ewayrapid')->__($e->getMessage()));
266
+ }
267
+
268
+ }
269
+
270
+ /**
271
+ * Get one page checkout model
272
+ *
273
+ * @return Mage_Checkout_Model_Type_Onepage
274
+ */
275
+ public function getOnepage()
276
+ {
277
+ return Mage::getSingleton('checkout/type_onepage');
278
+ }
279
+
280
+ /**
281
+ * Return checkout session object
282
+ *
283
+ * @return Mage_Checkout_Model_Session
284
+ */
285
+ private function _getCheckoutSession()
286
+ {
287
+ return Mage::getSingleton('checkout/session');
288
+ }
289
+
290
+ /**
291
+ * Return checkout quote object
292
+ *
293
+ * @return Mage_Sales_Model_Quote
294
+ */
295
+ private function _getQuote()
296
+ {
297
+ if (!$this->_quote) {
298
+ $this->_quote = $this->_getCheckoutSession()->getQuote();
299
+ }
300
+ return $this->_quote;
301
+ }
302
+
303
+ private function _initCheckout()
304
+ {
305
+ $quote = $this->_getQuote();
306
+ if (!$quote->hasItems() || $quote->getHasError()) {
307
+ $this->getResponse()->setHeader('HTTP/1.1', '403 Forbidden');
308
+ Mage::throwException(Mage::helper('ewayrapid')->__('Unable to initialize Shared page Checkout.'));
309
+ }
310
+ $this->_checkout = Mage::getSingleton(
311
+ $this->_checkoutType, array(
312
+ 'quote' => $quote
313
+ )
314
+ );
315
+ }
316
+
317
+ /**
318
+ * review order when checkout with paypal express
319
+ */
320
+ public function reviewAction()
321
+ {
322
+ try {
323
+ $this->_initCheckout();
324
+ $accessCode = $this->getRequest()->getParam('AccessCode');
325
+ $this->_checkout->updateCustomer($accessCode);
326
+ $this->loadLayout();
327
+ $blockReview = $this->getLayout()->getBlock('eway.block.review');
328
+ $blockReview->setQuote($this->_getQuote());
329
+ $blockReview->setAccessCode($accessCode);
330
+ $blockReview->setActionUrl(Mage::getUrl('*/*/saveInfoShipping'));
331
+ $this->renderLayout();
332
+ return;
333
+ } catch (Exception $e) {
334
+ Mage::getSingleton('checkout/session')->addError(
335
+ $this->__('Unable to initialize Express Checkout review. Error message: ' . $e->getMessage())
336
+ );
337
+ Mage::logException($e);
338
+ }
339
+ $this->_redirect('checkout/cart');
340
+ }
341
+
342
+ /**
343
+ * save shipping total amount to quote
344
+ * send new shipping total amount to eway
345
+ *
346
+ * @throws Exception
347
+ * @throws Mage_Core_Exception
348
+ */
349
+ public function saveInfoShippingAction()
350
+ {
351
+ $this->_initCheckout();
352
+ $formActionURL = Mage::getSingleton('core/session')->getData('FormActionURL');
353
+ if ($formActionURL) {
354
+ Mage::getSingleton('core/session')->unsetData('FormActionURL');
355
+ }
356
+ $shippingMethod = $this->getRequest()->getParam('shipping_method');
357
+ if ($shippingMethod) {
358
+ //Save to quote
359
+ $this->_quote->getShippingAddress()->setShippingMethod($shippingMethod)->save();
360
+
361
+ //Get price
362
+ $quote = $this->_getQuote();
363
+ $cRate = $this->_checkout->getShippingByCode($shippingMethod);
364
+ if ($cRate) {
365
+ echo json_encode(
366
+ array(
367
+ 'form_action' => $formActionURL,
368
+ 'input_post' => '<input type="hidden" name="EWAY_NEWSHIPPINGTOTAL" value="' . round($cRate->getPrice() * 100) . '" />'
369
+ )
370
+ );
371
+ } else {
372
+ Mage::throwException($this->__('Method not found.'));
373
+ }
374
+ } else {
375
+ Mage::throwException($this->__('Method not support.'));
376
+ }
377
+ die;
378
+ }
379
+
380
+ /**
381
+ * process Payment: authorize only or authorize & capture
382
+ *
383
+ * @param Eway_Rapid31_Model_Response $response
384
+ * @return Eway_Rapid31_Model_Response
385
+ * @throws Mage_Core_Exception
386
+ */
387
+ protected function _processPayment(Eway_Rapid31_Model_Response $response)
388
+ {
389
+ $this->_initCheckout();
390
+
391
+ $cardData = $response->getCustomer();
392
+
393
+ if ($cardData['CardNumber'] && $cardData['CardName']) {
394
+ $beagleScore = $response->getBeagleScore();
395
+
396
+ // Get Fraud Information
397
+ if ($response->isSuccess()) {
398
+ $transaction = $this->_checkout->getTransaction($response['TransactionID']);
399
+ if ($transaction) {
400
+ $fraudAction = $transaction[0]['FraudAction'];
401
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
402
+ $captured = $transaction[0]['TransactionCaptured'];
403
+ unset($transaction);
404
+ }
405
+ }
406
+
407
+ if ($response->isSuccess()
408
+ && Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE
409
+ ) {
410
+ $response = $this->_checkout->doAuthorisation($response);
411
+
412
+ // Reload Fraud Information
413
+ if ($response->isSuccess()) {
414
+ $transaction = $this->_checkout->getTransaction($response['TransactionID']);
415
+ if ($transaction) {
416
+ if ($transaction[0]['FraudAction']) {
417
+ $fraudAction = $transaction[0]['FraudAction'];
418
+ }
419
+ if (Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage'])) {
420
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
421
+ }
422
+ if ($transaction[0]['TransactionCaptured']) {
423
+ $captured = $transaction[0]['TransactionCaptured'];
424
+ }
425
+ unset($transaction);
426
+ }
427
+ }
428
+
429
+ }
430
+ } else {
431
+ if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
432
+ $response = $this->_checkout->doAuthorisation($response);
433
+
434
+ // Get Fraud Information
435
+ if ($response->isSuccess()) {
436
+ $transaction = $this->_checkout->getTransaction($response['TransactionID']);
437
+ if ($transaction) {
438
+ $fraudAction = $transaction[0]['FraudAction'];
439
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
440
+ $captured = $transaction[0]['TransactionCaptured'];
441
+ unset($transaction);
442
+ }
443
+ }
444
+ } elseif (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
445
+ $response = $this->_checkout->doTransaction($response);
446
+
447
+ // Get Fraud Information
448
+ if ($response->isSuccess()) {
449
+ $transaction = $this->_checkout->getTransaction($response['TransactionID']);
450
+ if ($transaction) {
451
+ $fraudAction = $transaction[0]['FraudAction'];
452
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
453
+ $captured = $transaction[0]['TransactionCaptured'];
454
+ unset($transaction);
455
+ }
456
+ }
457
+ }
458
+ }
459
+ if (!$response->isSuccess()) {
460
+ Mage::throwException(
461
+ Mage::helper('ewayrapid')->__(
462
+ 'Sorry, your payment could not be processed (Message: %s). Please check your details and try again, or try an alternative payment method.',
463
+ $response->getMessage()
464
+ )
465
+ );
466
+ }
467
+
468
+ if ($response->getBeagleScore() === null) {
469
+ $response->setBeagleScore($beagleScore);
470
+ }
471
+ $response->setFraudAction($fraudAction);
472
+ $response->setFraudCodes($fraudCodes);
473
+ $response->setTransactionCaptured($captured);
474
+ return $response;
475
+ }
476
  }
app/code/community/Eway/Rapid31/controllers/TestController.php CHANGED
@@ -1,128 +1,128 @@
1
- <?php
2
- /**
3
- *
4
- */
5
- class Eway_Rapid31_TestController extends Mage_Core_Controller_Front_Action
6
- {
7
- public function querySuspectFraudAction()
8
- {
9
-
10
- $base_path = Mage::getBaseDir('base');
11
- $file = $base_path . DS .'var' . DS . 'report' . DS .'people.txt';
12
- // The new person to add to the file
13
- $person = "John Smith " . rand(1, 9999) . "\n";
14
- // Write the contents to the file,
15
- // using the FILE_APPEND flag to append the content to the end of the file
16
- // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
17
- file_put_contents($file, $person, FILE_APPEND | LOCK_EX);
18
-
19
- // Load orders with fraud in 7 days before from now
20
- $orders = Mage::getModel('sales/order')->getCollection()
21
- ->addFieldToFilter('status', array('eq' => 'fraud')) // State fraud
22
- ->addFieldToFilter('eway_transaction_id', array('notnull' => ''))
23
- ->addFieldToFilter('created_at', array('to' => date('Y-m-d 23:59:59'), 'from' => date('Y-m-d 00:00:01', strtotime('-7 days'))));
24
-
25
- foreach ($orders as $o) {
26
- $transactionId = $o->getEwayTransactionId();
27
- if ($transactionId) {
28
- $result = $this->__getTransaction($transactionId);
29
- // Check return data
30
- $result_decode = json_decode($result);
31
-
32
- $trans = $result_decode->Transactions;
33
- $tranId = $trans[0]->TransactionID;
34
-
35
- if ($trans[0]->ResponseMessage == 'A2000') { // Success - Fraud order has been approved
36
- // Create new transaction
37
- $this->__createNewTransaction($o, $tranId);
38
- // Update order status
39
- $this->__updateStatusOrder($o);
40
- // Un-mark fraud customer
41
- $this->__unMarkFraudUser($o);
42
- }
43
- }
44
- }
45
- // Response data to client
46
- $this->getResponse()->setHeader('Content-type', 'application/json');
47
- $this->getResponse()->setBody(count($orders));
48
- }
49
-
50
- private function __getTransaction($transId)
51
- {
52
- $ewayConfig = new Eway_Rapid31_Model_Config();
53
- $url = 'https://api.sandbox.ewaypayments.com/Transaction/' . $transId;
54
- $ch = curl_init($url);
55
- curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
56
- curl_setopt($ch, CURLOPT_USERPWD, $ewayConfig->getBasicAuthenticationHeader());
57
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
58
-
59
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
60
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
61
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ewayConfig->isEnableSSLVerification());
62
-
63
- $result = curl_exec($ch);
64
- return $result;
65
- }
66
-
67
- /**
68
- * Re-create order with new transaction returned by Eway
69
- * @param $data
70
- */
71
- private function __createNewTransaction(Mage_Sales_Model_Order $order, $transId)
72
- {
73
-
74
- // Load transaction
75
- $currentTrans = Mage::getModel('sales/order_payment_transaction')
76
- ->getCollection()
77
- ->addFieldToFilter('order_id', array('eq' => $order->getEntityId()));
78
- foreach ($currentTrans as $t) {
79
- }
80
- if ($t == null) {
81
- $t = new Mage_Sales_Model_Order_Payment_Transaction();
82
- }
83
-
84
- $trans = new Mage_Sales_Model_Order_Payment_Transaction();
85
- // Load payment object
86
- $payment = Mage::getModel('sales/order_payment')->load($t->getPaymentId());
87
-
88
- $trans->setOrderPaymentObject($payment);
89
- $trans->setOrder($order);
90
-
91
- $trans->setParentId($t->getTransactionId());
92
- $trans->setOrderId($order->getEntityId());
93
- $trans->setPaymentId($t->getPaymentId());
94
- $trans->setTxnId($transId);
95
- $trans->setParentTxnId($t->getTxnId());
96
- $trans->setTxnType($t->getTxnType());
97
- $trans->setIsClosed($t->getIsClosed());
98
- $trans->setCreatedAt(date('Y-m-d H:i:s'));
99
- $trans->save();
100
-
101
- }
102
-
103
- private function __updateStatusOrder(Mage_Sales_Model_Order $order)
104
- {
105
- $order->setState('Processing');
106
- $order->setStatus(Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED);
107
- $order->save();
108
- }
109
-
110
- private function __unMarkFraudUser(Mage_Sales_Model_Order $order)
111
- {
112
- $uid = $order->getCustomerId();
113
- $customer = Mage::getModel('customer/customer')->load($uid);
114
- $customer->setMarkFraud(0);
115
- $customer->save();
116
- }
117
-
118
- public function recurringAction()
119
- {
120
- try {
121
- $modelObserver = Mage::getModel('ewayrapid/Observer');
122
- $modelObserver->cronRecurringOrder();
123
- echo "done";
124
- } catch (Exception $e) {
125
- throw $e;
126
- }
127
- }
128
  }
1
+ <?php
2
+ /**
3
+ *
4
+ */
5
+ class Eway_Rapid31_TestController extends Mage_Core_Controller_Front_Action
6
+ {
7
+ public function querySuspectFraudAction()
8
+ {
9
+
10
+ $basePath = Mage::getBaseDir('base');
11
+ $file = $basePath . DS .'var' . DS . 'report' . DS .'people.txt';
12
+ // The new person to add to the file
13
+ $person = "John Smith " . rand(1, 9999) . "\n";
14
+ // Write the contents to the file,
15
+ // using the FILE_APPEND flag to append the content to the end of the file
16
+ // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
17
+ file_put_contents($file, $person, FILE_APPEND | LOCK_EX);
18
+
19
+ // Load orders with fraud in 7 days before from now
20
+ $orders = Mage::getModel('sales/order')->getCollection()
21
+ ->addFieldToFilter('status', array('eq' => 'fraud')) // State fraud
22
+ ->addFieldToFilter('eway_transaction_id', array('notnull' => ''))
23
+ ->addFieldToFilter('created_at', array('to' => date('Y-m-d 23:59:59'), 'from' => date('Y-m-d 00:00:01', strtotime('-7 days'))));
24
+
25
+ foreach ($orders as $o) {
26
+ $transactionId = $o->getEwayTransactionId();
27
+ if ($transactionId) {
28
+ $result = $this->__getTransaction($transactionId);
29
+ // Check return data
30
+ $resultDecode = json_decode($result);
31
+
32
+ $trans = $resultDecode->Transactions;
33
+ $tranId = $trans[0]->TransactionID;
34
+
35
+ if ($trans[0]->ResponseMessage == 'A2000') { // Success - Fraud order has been approved
36
+ // Create new transaction
37
+ $this->__createNewTransaction($o, $tranId);
38
+ // Update order status
39
+ $this->__updateStatusOrder($o);
40
+ // Un-mark fraud customer
41
+ $this->__unMarkFraudUser($o);
42
+ }
43
+ }
44
+ }
45
+ // Response data to client
46
+ $this->getResponse()->setHeader('Content-type', 'application/json');
47
+ $this->getResponse()->setBody(count($orders));
48
+ }
49
+
50
+ private function __getTransaction($transId)
51
+ {
52
+ $ewayConfig = new Eway_Rapid31_Model_Config();
53
+ $url = 'https://api.sandbox.ewaypayments.com/Transaction/' . $transId;
54
+ $ch = curl_init($url);
55
+ curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
56
+ curl_setopt($ch, CURLOPT_USERPWD, $ewayConfig->getBasicAuthenticationHeader());
57
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
58
+
59
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
60
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
61
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ewayConfig->isEnableSSLVerification());
62
+
63
+ $result = curl_exec($ch);
64
+ return $result;
65
+ }
66
+
67
+ /**
68
+ * Re-create order with new transaction returned by Eway
69
+ * @param $data
70
+ */
71
+ private function __createNewTransaction(Mage_Sales_Model_Order $order, $transId)
72
+ {
73
+
74
+ // Load transaction
75
+ $currentTrans = Mage::getModel('sales/order_payment_transaction')
76
+ ->getCollection()
77
+ ->addFieldToFilter('order_id', array('eq' => $order->getEntityId()));
78
+ foreach ($currentTrans as $t) {
79
+ }
80
+ if ($t == null) {
81
+ $t = new Mage_Sales_Model_Order_Payment_Transaction();
82
+ }
83
+
84
+ $trans = new Mage_Sales_Model_Order_Payment_Transaction();
85
+ // Load payment object
86
+ $payment = Mage::getModel('sales/order_payment')->load($t->getPaymentId());
87
+
88
+ $trans->setOrderPaymentObject($payment);
89
+ $trans->setOrder($order);
90
+
91
+ $trans->setParentId($t->getTransactionId());
92
+ $trans->setOrderId($order->getEntityId());
93
+ $trans->setPaymentId($t->getPaymentId());
94
+ $trans->setTxnId($transId);
95
+ $trans->setParentTxnId($t->getTxnId());
96
+ $trans->setTxnType($t->getTxnType());
97
+ $trans->setIsClosed($t->getIsClosed());
98
+ $trans->setCreatedAt(date('Y-m-d H:i:s'));
99
+ $trans->save();
100
+
101
+ }
102
+
103
+ private function __updateStatusOrder(Mage_Sales_Model_Order $order)
104
+ {
105
+ $order->setState('Processing');
106
+ $order->setStatus(Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED);
107
+ $order->save();
108
+ }
109
+
110
+ private function __unMarkFraudUser(Mage_Sales_Model_Order $order)
111
+ {
112
+ $uid = $order->getCustomerId();
113
+ $customer = Mage::getModel('customer/customer')->load($uid);
114
+ $customer->setMarkFraud(0);
115
+ $customer->save();
116
+ }
117
+
118
+ public function recurringAction()
119
+ {
120
+ try {
121
+ $modelObserver = Mage::getModel('ewayrapid/Observer');
122
+ $modelObserver->cronRecurringOrder();
123
+ echo "done";
124
+ } catch (Exception $e) {
125
+ throw $e;
126
+ }
127
+ }
128
  }
app/code/community/Eway/Rapid31/controllers/TransparentController.php CHANGED
@@ -1,557 +1,557 @@
1
- <?php
2
-
3
- require_once "Mage" . DS . "Checkout" . DS . "controllers" . DS . "OnepageController.php";
4
-
5
- class Eway_Rapid31_TransparentController extends Mage_Checkout_OnepageController
6
- {
7
- /**
8
- * @var Mage_Sales_Model_Quote
9
- */
10
- protected $_quote;
11
-
12
- public static $_transparentmodel;
13
-
14
- protected $methodPayment;
15
- protected $transMethod;
16
- protected $paypalSavedToken;
17
- protected $savedToken;
18
- protected $cardInfo;
19
- protected $masterPassSavedToken;
20
- protected $saveCard;
21
-
22
- function _getSession()
23
- {
24
- $this->methodPayment = Mage::getSingleton('core/session')->getMethod();
25
- $this->transMethod = Mage::getSingleton('core/session')->getTransparentNotsaved();
26
- if (!$this->transMethod) {
27
- $this->transMethod = Mage::getSingleton('core/session')->getTransparentSaved();
28
- }
29
-
30
- $this->saveCard = Mage::getSingleton('core/session')->getSaveCard();
31
-
32
- if ($this->methodPayment == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
33
- || $this->methodPayment == Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD) {
34
- $this->savedToken = Mage::getSingleton('core/session')->getSavedToken();
35
- }
36
- $this->cardInfo = Mage::getSingleton('core/session')->getCardInfo();
37
- }
38
-
39
- /**
40
- * @return false|Eway_Rapid31_Model_Request_Transparent
41
- */
42
- protected function transparentModel()
43
- {
44
- if (!self::$_transparentmodel) {
45
- self::$_transparentmodel = Mage::getModel('ewayrapid/request_transparent');
46
- }
47
- return self::$_transparentmodel;
48
- }
49
-
50
- /**
51
- * @return Eway_Rapid31_Helper_Data
52
- */
53
- protected function helperData()
54
- {
55
- return Mage::helper('ewayrapid/data');
56
- }
57
-
58
- public function indexAction()
59
- {
60
- try {
61
-
62
- } catch (Exception $e) {
63
- Mage::throwException($e->getMessage());
64
- }
65
- }
66
-
67
- /**
68
- * Action build link redirect checkout after Click Place Order
69
- */
70
- public function buildAction()
71
- {
72
- try {
73
- $this->_getSession();
74
- $quote = $this->_getQuote();
75
- /** @var Eway_Rapid31_Model_Request_Sharedpage $sharedpageModel */
76
-
77
- $action = 'AccessCodes';
78
- if ($this->methodPayment == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD) {
79
- $methodData = Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT;
80
-
81
- //Authorize Only
82
- if ($this->helperData()->getPaymentAction() != Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE
83
- || $this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
84
- if ($this->savedToken == Eway_Rapid31_Model_Config::TOKEN_NEW)
85
- $methodData = Eway_Rapid31_Model_Config::METHOD_CREATE_TOKEN;
86
- else
87
- $methodData = Eway_Rapid31_Model_Config::METHOD_UPDATE_TOKEN;
88
- }
89
- } else if($this->methodPayment == Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD) {
90
- if($visaCheckout = $this->getRequest()->getParam('visa_checkout_call_id')){
91
- if($visaCheckout && $visaCheckout != ""){
92
- Mage::getSingleton('core/session')->setData('visa_checkout_call_id', $visaCheckout);
93
- }
94
- }
95
- $methodData = Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT;
96
-
97
- if ($this->helperData()->getPaymentAction() != Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE
98
- // && $this->transMethod != Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
99
- // && $this->transMethod != Eway_Rapid31_Model_Config::MASTERPASS_METHOD
100
- // && $this->transMethod != Eway_Rapid31_Model_Config::VISA_CHECKOUT_METHOD
101
- )
102
- {
103
- $methodData = Eway_Rapid31_Model_Config::METHOD_AUTHORISE;
104
- }
105
-
106
- if ($this->saveCard || ($this->savedToken && is_numeric($this->savedToken))) {
107
- $methodData = Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT;
108
- }
109
-
110
- //Authorize Only
111
- if ($this->helperData()->getPaymentAction() != Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE
112
- || $this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
113
- ) {
114
- if ($this->savedToken && $this->savedToken == Eway_Rapid31_Model_Config::TOKEN_NEW && $this->saveCard)
115
- $methodData = Eway_Rapid31_Model_Config::METHOD_CREATE_TOKEN;
116
- else if ($this->savedToken && is_numeric($this->savedToken))
117
- $methodData = Eway_Rapid31_Model_Config::METHOD_UPDATE_TOKEN;
118
- }
119
- } else{
120
- $methodData = Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT;
121
- if ($this->helperData()->getPaymentAction() != Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE
122
- && $this->transMethod != Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
123
- && $this->transMethod != Eway_Rapid31_Model_Config::MASTERPASS_METHOD
124
- && $this->transMethod != Eway_Rapid31_Model_Config::VISA_CHECKOUT_METHOD
125
- )
126
- {
127
- $methodData = Eway_Rapid31_Model_Config::METHOD_AUTHORISE;
128
- }
129
- }
130
-
131
- $data = $this->transparentModel()->createAccessCode($quote, $methodData, $action);
132
- if ($data['AccessCode']) {
133
- //save FormActionURL, AccessCode
134
- Mage::getSingleton('core/session')->setFormActionUrl($data['FormActionURL']);
135
- if (isset($data['CompleteCheckoutURL']))
136
- Mage::getSingleton('core/session')->setCompleteCheckoutURL($data['CompleteCheckoutURL']);
137
- if ($this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
138
- || $this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD
139
- || $this->transMethod == Eway_Rapid31_Model_Config::MASTERPASS_METHOD
140
- || $this->transMethod == Eway_Rapid31_Model_Config::VISA_CHECKOUT_METHOD) {
141
- $urlRedirect = Mage::getUrl('ewayrapid/transparent/redirect', array('_secure'=>true)) . '?AccessCode=' . $data['AccessCode'];
142
- } else {
143
- $urlRedirect = Mage::getUrl('ewayrapid/transparent/paynow', array('_secure'=>true)) . '?AccessCode=' . $data['AccessCode'];
144
- }
145
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
146
- === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
147
- && Mage::getSingleton('core/session')->getCheckoutExtension()
148
- /*(Mage::getStoreConfig('onestepcheckout/general/active')
149
- || Mage::getStoreConfig('opc/global/status')
150
- || Mage::getStoreConfig('firecheckout/general/enabled')
151
- || Mage::getStoreConfig('gomage_checkout/general/enabled')
152
- || Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links'))*/
153
- ) {
154
- $this->_redirectUrl($urlRedirect);
155
- return;
156
- }
157
- else {
158
- echo($urlRedirect);
159
- }
160
- } else {
161
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later.'));
162
- $this->transparentModel()->unsetSessionData();
163
- echo Mage::getUrl('checkout/cart/');
164
- return;
165
- }
166
- //
167
- } catch (Exception $e) {
168
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later.'));
169
- $this->transparentModel()->unsetSessionData();
170
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
171
- === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
172
- && Mage::getSingleton('core/session')->getCheckoutExtension()
173
- /*(Mage::getStoreConfig('onestepcheckout/general/active')
174
- || Mage::getStoreConfig('opc/global/status')
175
- || Mage::getStoreConfig('firecheckout/general/enabled')
176
- || Mage::getStoreConfig('gomage_checkout/general/enabled')
177
- || Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links'))*/
178
- ) {
179
- $this->_redirectUrl(Mage::getUrl('checkout/cart/'));
180
- return;
181
- }
182
- else {
183
- echo Mage::getUrl('checkout/cart/');
184
- }
185
- return;
186
- }
187
- die;
188
- }
189
-
190
- /**
191
- * Action display form customer's detail card: Add new info
192
- */
193
- public function paynowAction()
194
- {
195
- $this->loadLayout();
196
-
197
- $accessCode = $this->getRequest()->getParam('AccessCode');
198
- $this->getLayout()->getBlock('transparent.block.paynow')->setAccessCode($accessCode);
199
-
200
- $this->renderLayout();
201
- }
202
-
203
- /**
204
- * Action display form customer's detail card: Add new info
205
- */
206
- public function redirectAction()
207
- {
208
- $this->loadLayout();
209
-
210
- $accessCode = $this->getRequest()->getParam('AccessCode');
211
- $this->getLayout()->getBlock('transparent.block.checkout')->setAccessCode($accessCode);
212
-
213
- $this->renderLayout();
214
- }
215
-
216
- /**
217
- * Action process at returnUrl
218
- */
219
- public function callBackAction()
220
- {
221
- try {
222
- $this->_getSession();
223
- $quote = $this->_getQuote();
224
-
225
- $accessCode = $this->getRequest()->getParam('AccessCode');
226
- $order_id = $transactionID = $tokenCustomerID = 0;
227
-
228
- $fraudAction = '';
229
- $fraudCodes = '';
230
-
231
- if ($this->methodPayment == 'ewayrapid_notsaved'
232
- || ($this->methodPayment == 'ewayrapid_ewayone' && !$this->saveCard
233
- && (!$this->savedToken || !is_numeric($this->savedToken)))
234
- ) {
235
- $dataResult = $this->resultProcess($accessCode);
236
- $transactionID = $dataResult['TransactionID'];
237
-
238
- $transaction = $this->transparentModel()->getTransaction($transactionID);
239
- if($transaction) {
240
- $fraudAction = $transaction[0]['FraudAction'];
241
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
242
- $captured = $transaction[0]['TransactionCaptured'];
243
- unset($transaction);
244
- }
245
- } else {
246
- $transaction = $this->transparentModel()->getTransaction($accessCode);
247
- if($transaction) {
248
- $tokenCustomerID = $transaction && isset($transaction[0]['TokenCustomerID']) ? $transaction[0]['TokenCustomerID'] : null;
249
- $fraudAction = $transaction[0]['FraudAction'];
250
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
251
- $captured = $transaction[0]['TransactionCaptured'];
252
- unset($transaction);
253
- }
254
- $quote->setTokenCustomerID($tokenCustomerID);
255
-
256
- if($this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
257
- /*
258
- $dataResult = $this->resultProcess($accessCode);
259
- $transactionID = $dataResult['TransactionID'];
260
- */
261
- $quote = $this->transparentModel()->doTransaction($quote, round($this->_getQuote()->getBaseGrandTotal() * 100));
262
- $transactionID = $quote->getTransactionId();
263
- } else {
264
- if ($this->helperData()->getPaymentAction() === Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE) {
265
- $dataResult = $this->resultProcess($accessCode);
266
- $transactionID = $dataResult['TransactionID'];
267
- } else {
268
- $quote = $this->transparentModel()->doAuthorisation($quote, round($this->_getQuote()->getBaseGrandTotal() * 100));
269
- $transactionID = $quote->getTransactionId();
270
- //$quote = $this->transparentModel()->doCapturePayment($quote, round($this->_getQuote()->getBaseGrandTotal() * 100));
271
-
272
- // Reload fraud information after do authorisation
273
- $transaction = $this->transparentModel()->getTransaction($transactionID);
274
- if($transaction) {
275
- $fraudAction = $transaction[0]['FraudAction'];
276
- $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
277
- $captured = $transaction[0]['TransactionCaptured'];
278
- unset($transaction);
279
- }
280
- }
281
- }
282
- $quote->setTransactionId($transactionID);
283
-
284
- //Save Token
285
- if($this->methodPayment == 'ewayrapid_saved'){
286
- $this->saveToken($quote, $tokenCustomerID);
287
- } elseif($this->methodPayment == 'ewayrapid_ewayone' && $this->saveCard) {
288
- $this->saveToken($quote, $tokenCustomerID);
289
- }
290
-
291
- }
292
-
293
- if ($transactionID) {
294
- //Add Beagle Information
295
- if (isset($dataResult)) {
296
- $beagleScore = $dataResult->getBeagleScore();
297
- $beagleVerification = $dataResult->getBeagleVerification();
298
- }else{
299
- $beagleScore = $quote->getBeagleScore();
300
- $beagleVerification = $quote->getBeagleVerification();
301
- }
302
- Mage::getSingleton('core/session')->setTransactionId($transactionID);
303
- //Save order
304
- $order_id = $this->storeOrder('success', $transactionID, $beagleScore, $beagleVerification, $fraudAction, $fraudCodes, $captured);
305
- }
306
-
307
- //unset all session's transaparent
308
- $this->transparentModel()->unsetSessionData();
309
-
310
- // Redirect to success page
311
- if ($order_id) {
312
- $this->_redirect('checkout/onepage/success');
313
- return;
314
- } else {
315
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Create order error. Please again.'));
316
- $this->_redirect('checkout/cart/');
317
- return;
318
- }
319
- } catch (Exception $e) {
320
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Call back error: ' . $e->getMessage()));
321
- $this->transparentModel()->unsetSessionData();
322
- if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
323
- === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
324
- && Mage::getSingleton('core/session')->getCheckoutExtension()
325
- /*(Mage::getStoreConfig('onestepcheckout/general/active')
326
- || Mage::getStoreConfig('opc/global/status')
327
- || Mage::getStoreConfig('firecheckout/general/enabled')
328
- || Mage::getStoreConfig('gomage_checkout/general/enabled')
329
- || Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links'))*/
330
- ) {
331
- $this->_redirectUrl(Mage::getUrl('checkout/cart/'));
332
- return;
333
- }
334
- else {
335
- //echo Mage::getUrl('checkout/cart/');
336
- $this->_redirectUrl(Mage::getUrl('checkout/cart/'));
337
- }
338
- return;
339
- }
340
- }
341
-
342
- /**
343
- * @param $accessCode
344
- */
345
- protected function resultProcess($accessCode) {
346
- return $this->transparentModel()->getInfoByAccessCode($accessCode);
347
- }
348
-
349
- /**
350
- * @param $quote
351
- * @param $tokenCustomerID
352
- */
353
- protected function saveToken($quote, $tokenCustomerID) {
354
- if ($this->savedToken == Eway_Rapid31_Model_Config::TOKEN_NEW || $this->paypalSavedToken == Eway_Rapid31_Model_Config::TOKEN_NEW || $this->masterPassSavedToken == Eway_Rapid31_Model_Config::TOKEN_NEW) {
355
- $this->cardInfo['SavedType'] = Eway_Rapid31_Model_Config::CREDITCARD_METHOD;
356
-
357
- if ($this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
358
- $this->cardInfo['SavedType'] = Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD;
359
- } elseif ($this->transMethod == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
360
- $this->cardInfo['SavedType'] = Eway_Rapid31_Model_Config::MASTERPASS_METHOD;
361
- } elseif ($this->transMethod == Eway_Rapid31_Model_Config::VISA_CHECKOUT_METHOD) {
362
- $this->cardInfo['SavedType'] = Eway_Rapid31_Model_Config::VISA_CHECKOUT_METHOD;
363
- }
364
- $this->transparentModel()->addToken($quote, $this->cardInfo, $tokenCustomerID);
365
- } else {
366
- $this->transparentModel()->updateToken($tokenCustomerID, $this->cardInfo);
367
- }
368
- return true;
369
- }
370
-
371
- protected function authorizeOnly() {
372
-
373
- }
374
- /**
375
- * Action Cancel
376
- */
377
- public function cancelAction()
378
- {
379
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Request eway api error. Please try again.'));
380
- $this->transparentModel()->unsetSessionData();
381
- $this->_redirect('checkout/cart');
382
- return;
383
- }
384
-
385
- /**
386
- * @param string $successType
387
- * @param $transactionID
388
- * @return string
389
- */
390
- private function storeOrder($successType = 'success', $transactionID, $beagleScore, $beagleVerification, $fraudAction, $fraudCodes, $captured)
391
- {
392
- try {
393
- //Clear the basket and save the order (including some info about how the payment went)
394
- $this->getOnepage()->getQuote()->collectTotals();
395
- $this->getOnepage()->getQuote()->getPayment()->setTransactionId($transactionID);
396
- $this->getOnepage()->getQuote()->getPayment()->setAdditionalInformation('transactionId', $transactionID);
397
- $this->getOnepage()->getQuote()->getPayment()->setAdditionalInformation('successType', $successType);
398
- $beagleScore = $beagleScore && ($beagleScore > 0) ? $beagleScore : '';
399
- $this->getOnepage()->getQuote()->getPayment()->setBeagleScore($beagleScore);
400
- $this->getOnepage()->getQuote()->getPayment()->setBeagleVerification(serialize($beagleVerification));
401
- $this->getOnepage()->getQuote()->getPayment()->setFraudAction($fraudAction);
402
- $this->getOnepage()->getQuote()->getPayment()->setFraudCodes($fraudCodes);
403
- $this->getOnepage()->getQuote()->getPayment()->setTransactionCaptured($captured);
404
- Mage::getSingleton('core/session')->setData('transparentCheckout', true);
405
- $orderId = $this->getOnepage()->saveOrder()->getLastOrderId();
406
-
407
- $this->getOnepage()->getQuote()->setIsActive(1);
408
- try {
409
- $cartHelper = Mage::helper('checkout/cart');
410
-
411
- //Get all items from cart
412
- $items = $cartHelper->getCart()->getItems();
413
-
414
- //Loop through all of cart items
415
- foreach ($items as $item) {
416
- $itemId = $item->getItemId();
417
- //Remove items, one by one
418
- $cartHelper->getCart()->removeItem($itemId)->save();
419
- }
420
- } catch (Exception $e) {
421
-
422
- }
423
-
424
- $this->getOnepage()->getQuote()->save();
425
- Mage::getSingleton('core/session')->unsetData('transparentCheckout');
426
- Mage::getSingleton('core/session')->unsCheckoutExtension();
427
- return $orderId;
428
- } catch (Exception $e) {
429
- Mage::throwException($e->getMessage());
430
- }
431
- }
432
-
433
- /**
434
- * Review shipping
435
- */
436
- public function reviewAction()
437
- {
438
- try {
439
- $accessCode = $this->getRequest()->getParam('AccessCode');
440
- $quote = $this->transparentModel()->updateCustomer($accessCode, $this->_getQuote());
441
-
442
- if (!$quote) {
443
- $quote = $this->_getQuote();
444
- }
445
-
446
- $this->loadLayout();
447
- $blockReview = $this->getLayout()->getBlock('eway.block.review');
448
- $blockReview->setQuote($quote);
449
- $blockReview->setAccessCode($accessCode);
450
- $blockReview->setActionUrl(Mage::getUrl('*/*/saveInfoShipping'));
451
- $this->renderLayout();
452
- } catch (Exception $e) {
453
- Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Update customer info error: ' . $e->getMessage()));
454
- $this->transparentModel()->unsetSessionData();
455
- $this->_redirect('checkout/cart/');
456
- return;
457
- }
458
- }
459
-
460
- /**
461
- *
462
- */
463
- public function saveCardInfoAction()
464
- {
465
- try {
466
- $data = $this->getRequest()->getPost();
467
- if (isset($data['EWAY_CARDNUMBER'])) {
468
- $config = Mage::getSingleton('ewayrapid/config');
469
- $data['EWAY_CARDNUMBER'] = $this->helperData()->encryptSha256($data['EWAY_CARDNUMBER'], $config->getBasicAuthenticationHeader());
470
- }
471
- Mage::getSingleton('core/session')->setCardInfo($data);
472
- echo 1;
473
- } catch (Exception $e) {
474
- $this->transparentModel()->unsetSessionData();
475
- Mage::throwException($e->getMessage());
476
- }
477
- die;
478
- }
479
-
480
- /**
481
- *
482
- */
483
- public function saveInfoShippingAction()
484
- {
485
- $shippingMethod = $this->getRequest()->getParam('shipping_method');
486
- if ($shippingMethod) {
487
- //Get price
488
- $quote = $this->_getQuote();
489
- $cRate = $this->transparentModel()->getShippingByCode($quote, $shippingMethod);
490
-
491
- //Save to quote
492
- $quote->getShippingAddress()->setShippingMethod($shippingMethod)->save();
493
-
494
- if ($cRate) {
495
- echo json_encode(array(
496
- 'form_action' => Mage::getSingleton('core/session')->getFormActionUrl(),
497
- 'input_post' => '<input type="hidden" name="EWAY_NEWSHIPPINGTOTAL" value="' . round($cRate->getPrice() * 100) . '" />',
498
- ));
499
- } else {
500
- $this->transparentModel()->unsetSessionData();
501
- Mage::throwException($this->__('Method not found.'));
502
- }
503
- } else {
504
- $this->transparentModel()->unsetSessionData();
505
- Mage::throwException($this->__('Method not support.'));
506
- }
507
- die;
508
- }
509
-
510
- /**
511
- * @param $orderId
512
- * @return null
513
- */
514
- private function _loadOrder($orderId)
515
- {
516
- try {
517
- $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
518
- if ($order->getIncrementId() == $orderId) {
519
- return $order;
520
- }
521
- return null;
522
- } catch (Exception $e) {
523
- Mage::throwException($e->getMessage());
524
- }
525
- }
526
-
527
- /**
528
- * Return checkout quote object
529
- *
530
- * @return Mage_Sale_Model_Quote
531
- */
532
- private function _getQuote()
533
- {
534
- /** @var Mage_Sales_Model_Quote $this->_quote */
535
- $this->_quote = $this->_getCheckoutSession()->getQuote();
536
- return $this->_quote;
537
- }
538
-
539
- /**
540
- * @return Mage_Core_Model_Abstract
541
- */
542
- private function _getCheckoutSession()
543
- {
544
- return Mage::getSingleton('checkout/session');
545
- }
546
-
547
- /**
548
- * Get one page checkout model
549
- *
550
- * @return Mage_Checkout_Model_Type_Onepage
551
- */
552
- public function getOnepage()
553
- {
554
- return Mage::getSingleton('checkout/type_onepage');
555
- }
556
-
557
  }
1
+ <?php
2
+
3
+ require_once "Mage" . DS . "Checkout" . DS . "controllers" . DS . "OnepageController.php";
4
+
5
+ class Eway_Rapid31_TransparentController extends Mage_Checkout_OnepageController
6
+ {
7
+ /**
8
+ * @var Mage_Sales_Model_Quote
9
+ */
10
+ protected $_quote;
11
+
12
+ public static $transparentmodel;
13
+
14
+ protected $_methodPayment;
15
+ protected $_transMethod;
16
+ protected $_paypalSavedToken;
17
+ protected $_savedToken;
18
+ protected $_cardInfo;
19
+ protected $_masterPassSavedToken;
20
+ protected $_saveCard;
21
+
22
+ public function _getSession()
23
+ {
24
+ $this->_methodPayment = Mage::getSingleton('core/session')->getMethod();
25
+ $this->_transMethod = Mage::getSingleton('core/session')->getTransparentNotsaved();
26
+ if (!$this->_transMethod) {
27
+ $this->_transMethod = Mage::getSingleton('core/session')->getTransparentSaved();
28
+ }
29
+
30
+ $this->_saveCard = Mage::getSingleton('core/session')->getSaveCard();
31
+
32
+ if ($this->_methodPayment == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
33
+ || $this->_methodPayment == Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD) {
34
+ $this->_savedToken = Mage::getSingleton('core/session')->getSavedToken();
35
+ }
36
+ $this->_cardInfo = Mage::getSingleton('core/session')->getCardInfo();
37
+ }
38
+
39
+ /**
40
+ * @return false|Eway_Rapid31_Model_Request_Transparent
41
+ */
42
+ protected function transparentModel()
43
+ {
44
+ if (!self::$transparentmodel) {
45
+ self::$transparentmodel = Mage::getModel('ewayrapid/request_transparent');
46
+ }
47
+ return self::$transparentmodel;
48
+ }
49
+
50
+ /**
51
+ * @return Eway_Rapid31_Helper_Data
52
+ */
53
+ protected function helperData()
54
+ {
55
+ return Mage::helper('ewayrapid/data');
56
+ }
57
+
58
+ public function indexAction()
59
+ {
60
+ try {
61
+
62
+ } catch (Exception $e) {
63
+ Mage::throwException($e->getMessage());
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Action build link redirect checkout after Click Place Order
69
+ */
70
+ public function buildAction()
71
+ {
72
+ try {
73
+ $this->_getSession();
74
+ $quote = $this->_getQuote();
75
+ /** @var Eway_Rapid31_Model_Request_Sharedpage $sharedpageModel */
76
+
77
+ $action = 'AccessCodes';
78
+ if ($this->_methodPayment == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD) {
79
+ $methodData = Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT;
80
+
81
+ //Authorize Only
82
+ if ($this->helperData()->getPaymentAction() != Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE
83
+ || $this->_transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
84
+ if ($this->_savedToken == Eway_Rapid31_Model_Config::TOKEN_NEW)
85
+ $methodData = Eway_Rapid31_Model_Config::METHOD_CREATE_TOKEN;
86
+ else
87
+ $methodData = Eway_Rapid31_Model_Config::METHOD_UPDATE_TOKEN;
88
+ }
89
+ } else if ($this->_methodPayment == Eway_Rapid31_Model_Config::PAYMENT_EWAYONE_METHOD) {
90
+ if ($visaCheckout = $this->getRequest()->getParam('visa_checkout_call_id')) {
91
+ if ($visaCheckout && $visaCheckout != "") {
92
+ Mage::getSingleton('core/session')->setData('visa_checkout_call_id', $visaCheckout);
93
+ }
94
+ }
95
+ $methodData = Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT;
96
+
97
+ if ($this->helperData()->getPaymentAction() != Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE
98
+ // && $this->transMethod != Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
99
+ // && $this->transMethod != Eway_Rapid31_Model_Config::MASTERPASS_METHOD
100
+ // && $this->transMethod != Eway_Rapid31_Model_Config::VISA_CHECKOUT_METHOD
101
+ ) {
102
+ $methodData = Eway_Rapid31_Model_Config::METHOD_AUTHORISE;
103
+ }
104
+
105
+ if ($this->_saveCard || ($this->_savedToken && is_numeric($this->_savedToken))) {
106
+ $methodData = Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT;
107
+ }
108
+
109
+ //Authorize Only
110
+ if ($this->helperData()->getPaymentAction() != Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE
111
+ || $this->_transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
112
+ ) {
113
+ if ($this->_savedToken && $this->_savedToken == Eway_Rapid31_Model_Config::TOKEN_NEW && $this->_saveCard)
114
+ $methodData = Eway_Rapid31_Model_Config::METHOD_CREATE_TOKEN;
115
+ else if ($this->_savedToken && is_numeric($this->_savedToken))
116
+ $methodData = Eway_Rapid31_Model_Config::METHOD_UPDATE_TOKEN;
117
+ }
118
+ } else {
119
+ $methodData = Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT;
120
+ if ($this->helperData()->getPaymentAction() != Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE
121
+ && $this->_transMethod != Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
122
+ && $this->_transMethod != Eway_Rapid31_Model_Config::MASTERPASS_METHOD
123
+ && $this->_transMethod != Eway_Rapid31_Model_Config::VISA_CHECKOUT_METHOD
124
+ ) {
125
+ $methodData = Eway_Rapid31_Model_Config::METHOD_AUTHORISE;
126
+ }
127
+ }
128
+
129
+ $data = $this->transparentModel()->createAccessCode($quote, $methodData, $action);
130
+ if ($data['AccessCode']) {
131
+ //save FormActionURL, AccessCode
132
+ Mage::getSingleton('core/session')->setFormActionUrl($data['FormActionURL']);
133
+ if (isset($data['CompleteCheckoutURL']))
134
+ Mage::getSingleton('core/session')->setCompleteCheckoutURL($data['CompleteCheckoutURL']);
135
+ if ($this->_transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
136
+ || $this->_transMethod == Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD
137
+ || $this->_transMethod == Eway_Rapid31_Model_Config::MASTERPASS_METHOD
138
+ || $this->_transMethod == Eway_Rapid31_Model_Config::VISA_CHECKOUT_METHOD) {
139
+ $urlRedirect = Mage::getUrl('ewayrapid/transparent/redirect', array('_secure'=>true)) . '?AccessCode=' . $data['AccessCode'];
140
+ } else {
141
+ $urlRedirect = Mage::getUrl('ewayrapid/transparent/paynow', array('_secure'=>true)) . '?AccessCode=' . $data['AccessCode'];
142
+ }
143
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
144
+ === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
145
+ && Mage::getSingleton('core/session')->getCheckoutExtension()
146
+ /*(Mage::getStoreConfig('onestepcheckout/general/active')
147
+ || Mage::getStoreConfig('opc/global/status')
148
+ || Mage::getStoreConfig('firecheckout/general/enabled')
149
+ || Mage::getStoreConfig('gomage_checkout/general/enabled')
150
+ || Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links'))*/
151
+ ) {
152
+ $this->_redirectUrl($urlRedirect);
153
+ return;
154
+ } else {
155
+ echo($urlRedirect);
156
+ }
157
+ } else {
158
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later.'));
159
+ $this->transparentModel()->unsetSessionData();
160
+ echo Mage::getUrl('checkout/cart/');
161
+ return;
162
+ }
163
+ //
164
+ } catch (Exception $e) {
165
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later.'));
166
+ $this->transparentModel()->unsetSessionData();
167
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
168
+ === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
169
+ && Mage::getSingleton('core/session')->getCheckoutExtension()
170
+ /*(Mage::getStoreConfig('onestepcheckout/general/active')
171
+ || Mage::getStoreConfig('opc/global/status')
172
+ || Mage::getStoreConfig('firecheckout/general/enabled')
173
+ || Mage::getStoreConfig('gomage_checkout/general/enabled')
174
+ || Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links'))*/
175
+ ) {
176
+ $this->_redirectUrl(Mage::getUrl('checkout/cart/'));
177
+ return;
178
+ } else {
179
+ echo Mage::getUrl('checkout/cart/');
180
+ }
181
+ return;
182
+ }
183
+ die;
184
+ }
185
+
186
+ /**
187
+ * Action display form customer's detail card: Add new info
188
+ */
189
+ public function paynowAction()
190
+ {
191
+ $this->loadLayout();
192
+
193
+ $accessCode = $this->getRequest()->getParam('AccessCode');
194
+ $this->getLayout()->getBlock('transparent.block.paynow')->setAccessCode($accessCode);
195
+
196
+ $this->renderLayout();
197
+ }
198
+
199
+ /**
200
+ * Action display form customer's detail card: Add new info
201
+ */
202
+ public function redirectAction()
203
+ {
204
+ $this->loadLayout();
205
+
206
+ $accessCode = $this->getRequest()->getParam('AccessCode');
207
+ $this->getLayout()->getBlock('transparent.block.checkout')->setAccessCode($accessCode);
208
+
209
+ $this->renderLayout();
210
+ }
211
+
212
+ /**
213
+ * Action process at returnUrl
214
+ */
215
+ public function callBackAction()
216
+ {
217
+ try {
218
+ $this->_getSession();
219
+ $quote = $this->_getQuote();
220
+
221
+ $accessCode = $this->getRequest()->getParam('AccessCode');
222
+ $orderId = $transactionID = $tokenCustomerID = 0;
223
+
224
+ $fraudAction = '';
225
+ $fraudCodes = '';
226
+
227
+ if ($this->_methodPayment == 'ewayrapid_notsaved'
228
+ || ($this->_methodPayment == 'ewayrapid_ewayone' && !$this->_saveCard
229
+ && (!$this->_savedToken || !is_numeric($this->_savedToken)))
230
+ ) {
231
+ $dataResult = $this->resultProcess($accessCode);
232
+ $transactionID = $dataResult['TransactionID'];
233
+
234
+ $transaction = $this->transparentModel()->getTransaction($transactionID);
235
+ if ($transaction) {
236
+ $fraudAction = $transaction[0]['FraudAction'];
237
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
238
+ $captured = $transaction[0]['TransactionCaptured'];
239
+ unset($transaction);
240
+ }
241
+ } else {
242
+ $transaction = $this->transparentModel()->getTransaction($accessCode);
243
+ if ($transaction) {
244
+ $tokenCustomerID = $transaction && isset($transaction[0]['TokenCustomerID']) ? $transaction[0]['TokenCustomerID'] : null;
245
+ $fraudAction = $transaction[0]['FraudAction'];
246
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
247
+ $captured = $transaction[0]['TransactionCaptured'];
248
+ unset($transaction);
249
+ }
250
+ $quote->setTokenCustomerID($tokenCustomerID);
251
+
252
+ if ($this->_transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
253
+ /*
254
+ $dataResult = $this->resultProcess($accessCode);
255
+ $transactionID = $dataResult['TransactionID'];
256
+ */
257
+ $quote = $this->transparentModel()->doTransaction($quote, round($this->_getQuote()->getBaseGrandTotal() * 100));
258
+ $transactionID = $quote->getTransactionId();
259
+ } else {
260
+ if ($this->helperData()->getPaymentAction() === Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE) {
261
+ $dataResult = $this->resultProcess($accessCode);
262
+ $transactionID = $dataResult['TransactionID'];
263
+ } else {
264
+ $quote = $this->transparentModel()->doAuthorisation($quote, round($this->_getQuote()->getBaseGrandTotal() * 100));
265
+ $transactionID = $quote->getTransactionId();
266
+ //$quote = $this->transparentModel()->doCapturePayment($quote, round($this->_getQuote()->getBaseGrandTotal() * 100));
267
+
268
+ // Reload fraud information after do authorisation
269
+ $transaction = $this->transparentModel()->getTransaction($transactionID);
270
+ if ($transaction) {
271
+ $fraudAction = $transaction[0]['FraudAction'];
272
+ $fraudCodes = Mage::helper('ewayrapid')->getFraudCodes($transaction[0]['ResponseMessage']);
273
+ $captured = $transaction[0]['TransactionCaptured'];
274
+ unset($transaction);
275
+ }
276
+ }
277
+ }
278
+ $quote->setTransactionId($transactionID);
279
+
280
+ //Save Token
281
+ if ($this->_methodPayment == 'ewayrapid_saved') {
282
+ $this->saveToken($quote, $tokenCustomerID);
283
+ } elseif ($this->_methodPayment == 'ewayrapid_ewayone' && $this->_saveCard) {
284
+ $this->saveToken($quote, $tokenCustomerID);
285
+ }
286
+
287
+ }
288
+
289
+ if ($transactionID) {
290
+ //Add Beagle Information
291
+ if (isset($dataResult)) {
292
+ $beagleScore = $dataResult->getBeagleScore();
293
+ $beagleVerification = $dataResult->getBeagleVerification();
294
+ } else {
295
+ $beagleScore = $quote->getBeagleScore();
296
+ $beagleVerification = $quote->getBeagleVerification();
297
+ }
298
+ Mage::getSingleton('core/session')->setTransactionId($transactionID);
299
+ //Save order
300
+ $orderId = $this->storeOrder($transactionID, $beagleScore, $beagleVerification, $fraudAction, $fraudCodes, $captured, 'success');
301
+ }
302
+
303
+ //unset all session's transaparent
304
+ $this->transparentModel()->unsetSessionData();
305
+
306
+ // Redirect to success page
307
+ if ($orderId) {
308
+ $this->_redirect('checkout/onepage/success');
309
+ return;
310
+ } else {
311
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Create order error. Please again.'));
312
+ $this->_redirect('checkout/cart/');
313
+ return;
314
+ }
315
+ } catch (Exception $e) {
316
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Call back error: ' . $e->getMessage()));
317
+ $this->transparentModel()->unsetSessionData();
318
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
319
+ === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
320
+ && Mage::getSingleton('core/session')->getCheckoutExtension()
321
+ /*(Mage::getStoreConfig('onestepcheckout/general/active')
322
+ || Mage::getStoreConfig('opc/global/status')
323
+ || Mage::getStoreConfig('firecheckout/general/enabled')
324
+ || Mage::getStoreConfig('gomage_checkout/general/enabled')
325
+ || Mage::getStoreConfig('onestepcheckout/general/rewrite_checkout_links'))*/
326
+ ) {
327
+ $this->_redirectUrl(Mage::getUrl('checkout/cart/'));
328
+ return;
329
+ } else {
330
+ //echo Mage::getUrl('checkout/cart/');
331
+ $this->_redirectUrl(Mage::getUrl('checkout/cart/'));
332
+ }
333
+ return;
334
+ }
335
+ }
336
+
337
+ /**
338
+ * @param $accessCode
339
+ */
340
+ protected function resultProcess($accessCode)
341
+ {
342
+ return $this->transparentModel()->getInfoByAccessCode($accessCode);
343
+ }
344
+
345
+ /**
346
+ * @param $quote
347
+ * @param $tokenCustomerID
348
+ */
349
+ protected function saveToken($quote, $tokenCustomerID)
350
+ {
351
+ if ($this->_savedToken == Eway_Rapid31_Model_Config::TOKEN_NEW || $this->_paypalSavedToken == Eway_Rapid31_Model_Config::TOKEN_NEW || $this->_masterPassSavedToken == Eway_Rapid31_Model_Config::TOKEN_NEW) {
352
+ $this->_cardInfo['SavedType'] = Eway_Rapid31_Model_Config::CREDITCARD_METHOD;
353
+
354
+ if ($this->_transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
355
+ $this->_cardInfo['SavedType'] = Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD;
356
+ } elseif ($this->_transMethod == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
357
+ $this->_cardInfo['SavedType'] = Eway_Rapid31_Model_Config::MASTERPASS_METHOD;
358
+ } elseif ($this->_transMethod == Eway_Rapid31_Model_Config::VISA_CHECKOUT_METHOD) {
359
+ $this->_cardInfo['SavedType'] = Eway_Rapid31_Model_Config::VISA_CHECKOUT_METHOD;
360
+ }
361
+ $this->transparentModel()->addToken($quote, $this->_cardInfo, $tokenCustomerID);
362
+ } else {
363
+ $this->transparentModel()->updateToken($tokenCustomerID, $this->_cardInfo);
364
+ }
365
+ return true;
366
+ }
367
+
368
+ protected function authorizeOnly()
369
+ {
370
+
371
+ }
372
+ /**
373
+ * Action Cancel
374
+ */
375
+ public function cancelAction()
376
+ {
377
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Request eway api error. Please try again.'));
378
+ $this->transparentModel()->unsetSessionData();
379
+ $this->_redirect('checkout/cart');
380
+ return;
381
+ }
382
+
383
+ /**
384
+ * @param string $successType
385
+ * @param $transactionID
386
+ * @return string
387
+ */
388
+ private function storeOrder($transactionID, $beagleScore, $beagleVerification, $fraudAction, $fraudCodes, $captured, $successType = 'success')
389
+ {
390
+ try {
391
+ //Clear the basket and save the order (including some info about how the payment went)
392
+ $this->getOnepage()->getQuote()->collectTotals();
393
+ $this->getOnepage()->getQuote()->getPayment()->setTransactionId($transactionID);
394
+ $this->getOnepage()->getQuote()->getPayment()->setAdditionalInformation('transactionId', $transactionID);
395
+ $this->getOnepage()->getQuote()->getPayment()->setAdditionalInformation('successType', $successType);
396
+ $beagleScore = $beagleScore && ($beagleScore > 0) ? $beagleScore : '';
397
+ $this->getOnepage()->getQuote()->getPayment()->setBeagleScore($beagleScore);
398
+ $this->getOnepage()->getQuote()->getPayment()->setBeagleVerification(serialize($beagleVerification));
399
+ $this->getOnepage()->getQuote()->getPayment()->setFraudAction($fraudAction);
400
+ $this->getOnepage()->getQuote()->getPayment()->setFraudCodes($fraudCodes);
401
+ $this->getOnepage()->getQuote()->getPayment()->setTransactionCaptured($captured);
402
+ Mage::getSingleton('core/session')->setData('transparentCheckout', true);
403
+ $orderId = $this->getOnepage()->saveOrder()->getLastOrderId();
404
+
405
+ $this->getOnepage()->getQuote()->setIsActive(1);
406
+ try {
407
+ $cartHelper = Mage::helper('checkout/cart');
408
+
409
+ //Get all items from cart
410
+ $items = $cartHelper->getCart()->getItems();
411
+
412
+ //Loop through all of cart items
413
+ foreach ($items as $item) {
414
+ $itemId = $item->getItemId();
415
+ //Remove items, one by one
416
+ $cartHelper->getCart()->removeItem($itemId)->save();
417
+ }
418
+ } catch (Exception $e) {
419
+
420
+ }
421
+
422
+ $this->getOnepage()->getQuote()->save();
423
+ Mage::getSingleton('core/session')->unsetData('transparentCheckout');
424
+ Mage::getSingleton('core/session')->unsCheckoutExtension();
425
+ return $orderId;
426
+ } catch (Exception $e) {
427
+ Mage::throwException($e->getMessage());
428
+ }
429
+ }
430
+
431
+ /**
432
+ * Review shipping
433
+ */
434
+ public function reviewAction()
435
+ {
436
+ try {
437
+ $accessCode = $this->getRequest()->getParam('AccessCode');
438
+ $quote = $this->transparentModel()->updateCustomer($accessCode, $this->_getQuote());
439
+
440
+ if (!$quote) {
441
+ $quote = $this->_getQuote();
442
+ }
443
+
444
+ $this->loadLayout();
445
+ $blockReview = $this->getLayout()->getBlock('eway.block.review');
446
+ $blockReview->setQuote($quote);
447
+ $blockReview->setAccessCode($accessCode);
448
+ $blockReview->setActionUrl(Mage::getUrl('*/*/saveInfoShipping'));
449
+ $this->renderLayout();
450
+ } catch (Exception $e) {
451
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Update customer info error: ' . $e->getMessage()));
452
+ $this->transparentModel()->unsetSessionData();
453
+ $this->_redirect('checkout/cart/');
454
+ return;
455
+ }
456
+ }
457
+
458
+ /**
459
+ *
460
+ */
461
+ public function saveCardInfoAction()
462
+ {
463
+ try {
464
+ $data = $this->getRequest()->getPost();
465
+ if (isset($data['EWAY_CARDNUMBER'])) {
466
+ $config = Mage::getSingleton('ewayrapid/config');
467
+ $data['EWAY_CARDNUMBER'] = $this->helperData()->encryptSha256($data['EWAY_CARDNUMBER'], $config->getBasicAuthenticationHeader());
468
+ }
469
+ Mage::getSingleton('core/session')->setCardInfo($data);
470
+ echo 1;
471
+ } catch (Exception $e) {
472
+ $this->transparentModel()->unsetSessionData();
473
+ Mage::throwException($e->getMessage());
474
+ }
475
+ die;
476
+ }
477
+
478
+ /**
479
+ *
480
+ */
481
+ public function saveInfoShippingAction()
482
+ {
483
+ $shippingMethod = $this->getRequest()->getParam('shipping_method');
484
+ if ($shippingMethod) {
485
+ //Get price
486
+ $quote = $this->_getQuote();
487
+ $cRate = $this->transparentModel()->getShippingByCode($quote, $shippingMethod);
488
+
489
+ //Save to quote
490
+ $quote->getShippingAddress()->setShippingMethod($shippingMethod)->save();
491
+
492
+ if ($cRate) {
493
+ echo json_encode(
494
+ array(
495
+ 'form_action' => Mage::getSingleton('core/session')->getFormActionUrl(),
496
+ 'input_post' => '<input type="hidden" name="EWAY_NEWSHIPPINGTOTAL" value="' . round($cRate->getPrice() * 100) . '" />',
497
+ )
498
+ );
499
+ } else {
500
+ $this->transparentModel()->unsetSessionData();
501
+ Mage::throwException($this->__('Method not found.'));
502
+ }
503
+ } else {
504
+ $this->transparentModel()->unsetSessionData();
505
+ Mage::throwException($this->__('Method not support.'));
506
+ }
507
+ die;
508
+ }
509
+
510
+ /**
511
+ * @param $orderId
512
+ * @return null
513
+ */
514
+ private function _loadOrder($orderId)
515
+ {
516
+ try {
517
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
518
+ if ($order->getIncrementId() == $orderId) {
519
+ return $order;
520
+ }
521
+ return null;
522
+ } catch (Exception $e) {
523
+ Mage::throwException($e->getMessage());
524
+ }
525
+ }
526
+
527
+ /**
528
+ * Return checkout quote object
529
+ *
530
+ * @return Mage_Sale_Model_Quote
531
+ */
532
+ private function _getQuote()
533
+ {
534
+ /** @var Mage_Sales_Model_Quote $this->_quote */
535
+ $this->_quote = $this->_getCheckoutSession()->getQuote();
536
+ return $this->_quote;
537
+ }
538
+
539
+ /**
540
+ * @return Mage_Core_Model_Abstract
541
+ */
542
+ private function _getCheckoutSession()
543
+ {
544
+ return Mage::getSingleton('checkout/session');
545
+ }
546
+
547
+ /**
548
+ * Get one page checkout model
549
+ *
550
+ * @return Mage_Checkout_Model_Type_Onepage
551
+ */
552
+ public function getOnepage()
553
+ {
554
+ return Mage::getSingleton('checkout/type_onepage');
555
+ }
556
+
557
  }
app/code/community/Eway/Rapid31/etc/config.xml CHANGED
@@ -1,382 +1,370 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Eway_Rapid31>
5
- <version>1.4.0</version>
6
- </Eway_Rapid31>
7
- </modules>
8
- <global>
9
- <models>
10
- <ewayrapid>
11
- <class>Eway_Rapid31_Model</class>
12
- <resourceModel>ewayrapid_resource</resourceModel>
13
- </ewayrapid>
14
- <ewayrapid_resource>
15
- <class>Eway_Rapid31_Model_Resource</class>
16
- </ewayrapid_resource>
17
- </models>
18
-
19
- <blocks>
20
- <ewayrapid>
21
- <class>Eway_Rapid31_Block</class>
22
- </ewayrapid>
23
- <adminhtml>
24
- <rewrite>
25
- <sales_order_grid>Eway_Rapid31_Block_Sales_Order_Grid</sales_order_grid>
26
- <page_head>Eway_Rapid31_Block_Html_Head</page_head>
27
- </rewrite>
28
- </adminhtml>
29
- </blocks>
30
-
31
- <helpers>
32
- <ewayrapid>
33
- <class>Eway_Rapid31_Helper</class>
34
- </ewayrapid>
35
- </helpers>
36
- <resources>
37
- <ewayrapid_setup>
38
- <setup>
39
- <module>Eway_Rapid31</module>
40
- <class>Eway_Rapid31_Model_Resource_Setup</class>
41
- </setup>
42
- </ewayrapid_setup>
43
- </resources>
44
- <payment>
45
- <cc>
46
- <types>
47
- <DC>
48
- <code>DC</code>
49
- <name>Diners Club International</name>
50
- <order>100</order>
51
- </DC>
52
- <VE>
53
- <code>VE</code>
54
- <name>Visa Electron</name>
55
- <order>11</order>
56
- </VE>
57
- <ME>
58
- <code>ME</code>
59
- <name>Maestro</name>
60
- <order>21</order>
61
- </ME>
62
- </types>
63
- </cc>
64
- </payment>
65
- <fieldsets>
66
- <sales_convert_quote_payment>
67
- <fraud_action>
68
- <to_order_payment>*</to_order_payment>
69
- </fraud_action>
70
- <fraud_codes>
71
- <to_order_payment>*</to_order_payment>
72
- </fraud_codes>
73
- <transaction_captured>
74
- <to_order_payment>*</to_order_payment>
75
- </transaction_captured>
76
- <beagle_score>
77
- <to_order_payment>*</to_order_payment>
78
- </beagle_score>
79
- <beagle_verification>
80
- <to_order_payment>*</to_order_payment>
81
- </beagle_verification>
82
- </sales_convert_quote_payment>
83
- <sales_convert_order_payment>
84
- <fraud_action>
85
- <to_quote_payment>*</to_quote_payment>
86
- </fraud_action>
87
- <fraud_codes>
88
- <to_order_payment>*</to_order_payment>
89
- </fraud_codes>
90
- <transaction_captured>
91
- <to_order_payment>*</to_order_payment>
92
- </transaction_captured>
93
- <beagle_score>
94
- <to_order_payment>*</to_order_payment>
95
- </beagle_score>
96
- <beagle_verification>
97
- <to_order_payment>*</to_order_payment>
98
- </beagle_verification>
99
- </sales_convert_order_payment>
100
- </fieldsets>
101
- </global>
102
- <frontend>
103
- <translate>
104
- <modules>
105
- <Eway_Rapid31>
106
- <files>
107
- <default>Eway_Rapid31.csv</default>
108
- </files>
109
- </Eway_Rapid31>
110
- </modules>
111
- </translate>
112
- <layout>
113
- <updates>
114
- <ewayrapid>
115
- <file>ewayrapid/layout.xml</file>
116
- </ewayrapid>
117
- </updates>
118
- </layout>
119
- <routers>
120
- <ewayrapid>
121
- <use>standard</use>
122
- <args>
123
- <module>Eway_Rapid31</module>
124
- <frontName>ewayrapid</frontName>
125
- </args>
126
- </ewayrapid>
127
- </routers>
128
-
129
- <events>
130
-
131
- <controller_action_predispatch_ewayrapid_mycards_index>
132
- <observers>
133
- <eway_rapid31_my_cards>
134
- <type>singleton</type>
135
- <class>ewayrapid/observer</class>
136
- <method>myCards</method>
137
- </eway_rapid31_my_cards>
138
- </observers>
139
- </controller_action_predispatch_ewayrapid_mycards_index>
140
-
141
- <!-- Event default -->
142
- <controller_action_predispatch_checkout_onepage_index>
143
- <observers>
144
- <eway_rapid31_check_customer_mark>
145
- <type>singleton</type>
146
- <class>ewayrapid/observer</class>
147
- <method>checkCustomerMark</method>
148
- </eway_rapid31_check_customer_mark>
149
- </observers>
150
- </controller_action_predispatch_checkout_onepage_index>
151
-
152
- <!--<sales_order_save_before>
153
- <observers>
154
- <sales_order_save_before>
155
- <class>ewayrapid/observer</class>
156
- <method>hookToSaveOrderBefore</method>
157
- </sales_order_save_before>
158
- </observers>
159
- </sales_order_save_before>
160
-
161
- <sales_order_save_after>
162
- <observers>
163
- <sales_order_save_after>
164
- <class>ewayrapid/observer</class>
165
- <method>hookToSaveOrderAfter</method>
166
- </sales_order_save_after>
167
- </observers>
168
- </sales_order_save_after>-->
169
-
170
- <sales_order_place_before>
171
- <observers>
172
- <sales_order_place_before>
173
- <class>ewayrapid/observer</class>
174
- <method>sales_order_place_before</method>
175
- </sales_order_place_before>
176
- </observers>
177
- </sales_order_place_before>
178
-
179
- <sales_order_place_after>
180
- <observers>
181
- <sales_order_place_after>
182
- <class>ewayrapid/observer</class>
183
- <method>sales_order_place_after</method>
184
- </sales_order_place_after>
185
- </observers>
186
- </sales_order_place_after>
187
-
188
- <sales_order_invoice_save_after>
189
- <observers>
190
- <sales_order_invoice_save_after>
191
- <class>ewayrapid/observer</class>
192
- <method>sales_order_invoice_save_after</method>
193
- </sales_order_invoice_save_after>
194
- </observers>
195
- </sales_order_invoice_save_after>
196
- <checkout_type_onepage_save_order_after>
197
- <observers>
198
- <checkout_type_onepage_save_order_after>
199
- <class>ewayrapid/observer</class>
200
- <method>checkout_type_onepage_save_order_after</method>
201
- </checkout_type_onepage_save_order_after>
202
- </observers>
203
- </checkout_type_onepage_save_order_after>
204
-
205
- <!--<sales_order_save_commit_before>
206
- <observers>
207
- <sales_order_save_commit_before>
208
- <class>ewayrapid/observer</class>
209
- <method>sales_order_save_commit_before</method>
210
- </sales_order_save_commit_before>
211
- </observers>
212
- </sales_order_save_commit_before>
213
-
214
- <sales_order_save_commit_after>
215
- <observers>
216
- <sales_order_save_commit_after>
217
- <class>ewayrapid/observer</class>
218
- <method>sales_order_save_commit_after</method>
219
- </sales_order_save_commit_after>
220
- </observers>
221
- </sales_order_save_commit_after>-->
222
-
223
- <checkout_submit_all_after>
224
- <observers>
225
- <checkout_submit_all_after>
226
- <class>ewayrapid/observer</class>
227
- <method>checkout_submit_all_after</method>
228
- </checkout_submit_all_after>
229
- </observers>
230
- <observers>
231
- <eway_recurring_profile>
232
- <class>ewayrapid/observer</class>
233
- <method>createRecurringOrder</method>
234
- </eway_recurring_profile>
235
- </observers>
236
- </checkout_submit_all_after>
237
- </events>
238
-
239
- </frontend>
240
-
241
- <!--
242
- <admin>
243
- <routers>
244
- <ewayrapid_admin>
245
- <use>admin</use>
246
- <args>
247
- <module>Eway_Rapid31_Adminhtml</module>
248
- <frontName>ewayadmin</frontName>
249
- </args>
250
- </ewayrapid_admin>
251
- </routers>
252
- </admin>
253
- -->
254
-
255
- <admin>
256
- <routers>
257
- <adminhtml>
258
- <args>
259
- <modules>
260
- <eway_rapid31_adminhtml after="Mage_Adminhtml">Eway_Rapid31_Adminhtml</eway_rapid31_adminhtml>
261
- <eway_rapid31 before="-">Eway_Rapid31_Adminhtml</eway_rapid31>
262
- </modules>
263
- </args>
264
- </adminhtml>
265
- </routers>
266
- </admin>
267
-
268
- <adminhtml>
269
- <translate>
270
- <modules>
271
- <Eway_Rapid31>
272
- <files>
273
- <default>Eway_Rapid31.csv</default>
274
- </files>
275
- </Eway_Rapid31>
276
- </modules>
277
- </translate>
278
- <layout>
279
- <updates>
280
- <ewayrapid>
281
- <file>ewayrapid/layout.xml</file>
282
- </ewayrapid>
283
- </updates>
284
- </layout>
285
- <!--<menu>
286
- <system>
287
- <children>
288
- <eway_admin_index>
289
- <title>Eway Mass</title>
290
- <action>ewayadmin/index/index</action>
291
- </eway_admin_index>
292
- <eway_admin_mass_authorised>
293
- <title>Eway Mass</title>
294
- <action>ewayadmin/index/massEwayAuthorised</action>
295
- </eway_admin_mass_authorised>
296
- <eway_admin_mass_pending>
297
- <title>Eway Mass</title>
298
- <action>ewayadmin/index/massPending</action>
299
- </eway_admin_mass_pending>
300
- </children>
301
- </system>
302
- </menu>-->
303
- <menu>
304
- <sales>
305
- <children>
306
- <eway_orders>
307
- <title>eWAY</title>
308
- <action>adminhtml/ewayadmin/ewayorders</action>
309
- <sort_order>100</sort_order>
310
- </eway_orders>
311
- </children>
312
- </sales>
313
- </menu>
314
- </adminhtml>
315
- <default>
316
- <payment>
317
- <ewayrapid_general>
318
- <active>0</active>
319
- <mode>sandbox</mode>
320
- <sandbox_endpoint>https://api.sandbox.ewaypayments.com/</sandbox_endpoint>
321
- <live_endpoint>https://api.ewaypayments.com/</live_endpoint>
322
- <payment_action>authorize_capture</payment_action>
323
- <connection_type>direct</connection_type>
324
- <can_edit_token>1</can_edit_token>
325
- <can_cancel_subscriptions>0</can_cancel_subscriptions>
326
- <block_fraud_customers>1</block_fraud_customers>
327
- <useccv>1</useccv>
328
- <cctypes>VI,MC</cctypes>
329
- <order_status>eway_captured</order_status>
330
- <allowspecific>0</allowspecific>
331
- <ssl_verification>0</ssl_verification>
332
- <transfer_cart_items>1</transfer_cart_items>
333
- <debug>0</debug>
334
- <billing_agreement_title>eWAY Billing Agreement</billing_agreement_title>
335
- </ewayrapid_general>
336
- <ewayrapid_notsaved>
337
- <model>ewayrapid/method_notsaved</model>
338
- <active>0</active>
339
- <title>Credit Card - eWAY (not saved)</title>
340
- </ewayrapid_notsaved>
341
- <ewayrapid_saved>
342
- <model>ewayrapid/method_saved</model>
343
- <active>0</active>
344
- <title>Credit Card - eWAY (saved)</title>
345
- </ewayrapid_saved>
346
- <ewayrapid_ewayone>
347
- <model>ewayrapid/method_ewayone</model>
348
- <active>0</active>
349
- <title>Credit Card - eWAY</title>
350
- <save_card>1</save_card>
351
- <save_text>Save my details</save_text>
352
- </ewayrapid_ewayone>
353
- </payment>
354
- </default>
355
- <phpunit>
356
- <suite>
357
- <modules>
358
- <Eway_Rapid31/>
359
- </modules>
360
- </suite>
361
- </phpunit>
362
- <crontab>
363
- <jobs>
364
- <eway_recurring_order>
365
- <schedule>
366
- <cron_expr>0 * * * *</cron_expr>
367
- </schedule>
368
- <run>
369
- <model>ewayrapid/observer::cronRecurringOrder</model>
370
- </run>
371
- </eway_recurring_order>
372
- <eway_rapid31>
373
- <schedule>
374
- <cron_expr>0 */3 * * *</cron_expr>
375
- </schedule>
376
- <run>
377
- <model>ewayrapid/ewayCron::querySuspectFraud</model>
378
- </run>
379
- </eway_rapid31>
380
- </jobs>
381
- </crontab>
382
  </config>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Eway_Rapid31>
5
+ <version>1.4.1</version>
6
+ </Eway_Rapid31>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <ewayrapid>
11
+ <class>Eway_Rapid31_Model</class>
12
+ <resourceModel>ewayrapid_resource</resourceModel>
13
+ </ewayrapid>
14
+ <ewayrapid_resource>
15
+ <class>Eway_Rapid31_Model_Resource</class>
16
+ </ewayrapid_resource>
17
+ </models>
18
+
19
+ <blocks>
20
+ <ewayrapid>
21
+ <class>Eway_Rapid31_Block</class>
22
+ </ewayrapid>
23
+ <adminhtml>
24
+ <rewrite>
25
+ <sales_order_grid>Eway_Rapid31_Block_Sales_Order_Grid</sales_order_grid>
26
+ <page_head>Eway_Rapid31_Block_Html_Head</page_head>
27
+ </rewrite>
28
+ </adminhtml>
29
+ </blocks>
30
+
31
+ <helpers>
32
+ <ewayrapid>
33
+ <class>Eway_Rapid31_Helper</class>
34
+ </ewayrapid>
35
+ </helpers>
36
+ <resources>
37
+ <ewayrapid_setup>
38
+ <setup>
39
+ <module>Eway_Rapid31</module>
40
+ <class>Eway_Rapid31_Model_Resource_Setup</class>
41
+ </setup>
42
+ </ewayrapid_setup>
43
+ </resources>
44
+ <payment>
45
+ <cc>
46
+ <types>
47
+ <DC>
48
+ <code>DC</code>
49
+ <name>Diners Club International</name>
50
+ <order>100</order>
51
+ </DC>
52
+ <VE>
53
+ <code>VE</code>
54
+ <name>Visa Electron</name>
55
+ <order>11</order>
56
+ </VE>
57
+ <ME>
58
+ <code>ME</code>
59
+ <name>Maestro</name>
60
+ <order>21</order>
61
+ </ME>
62
+ </types>
63
+ </cc>
64
+ </payment>
65
+ <fieldsets>
66
+ <sales_convert_quote_payment>
67
+ <fraud_action>
68
+ <to_order_payment>*</to_order_payment>
69
+ </fraud_action>
70
+ <fraud_codes>
71
+ <to_order_payment>*</to_order_payment>
72
+ </fraud_codes>
73
+ <transaction_captured>
74
+ <to_order_payment>*</to_order_payment>
75
+ </transaction_captured>
76
+ <beagle_score>
77
+ <to_order_payment>*</to_order_payment>
78
+ </beagle_score>
79
+ <beagle_verification>
80
+ <to_order_payment>*</to_order_payment>
81
+ </beagle_verification>
82
+ </sales_convert_quote_payment>
83
+ <sales_convert_order_payment>
84
+ <fraud_action>
85
+ <to_quote_payment>*</to_quote_payment>
86
+ </fraud_action>
87
+ <fraud_codes>
88
+ <to_order_payment>*</to_order_payment>
89
+ </fraud_codes>
90
+ <transaction_captured>
91
+ <to_order_payment>*</to_order_payment>
92
+ </transaction_captured>
93
+ <beagle_score>
94
+ <to_order_payment>*</to_order_payment>
95
+ </beagle_score>
96
+ <beagle_verification>
97
+ <to_order_payment>*</to_order_payment>
98
+ </beagle_verification>
99
+ </sales_convert_order_payment>
100
+ </fieldsets>
101
+ </global>
102
+ <frontend>
103
+ <secure_url>
104
+ <eway_account_cards>/ewayrapid/mycards</eway_account_cards>
105
+ <eway_checkout_redirect>/ewayrapid/transparent</eway_checkout_redirect>
106
+ <eway_checkout_shared>/ewayrapid/sharedpage</eway_checkout_shared>
107
+ </secure_url>
108
+ <translate>
109
+ <modules>
110
+ <Eway_Rapid31>
111
+ <files>
112
+ <default>Eway_Rapid31.csv</default>
113
+ </files>
114
+ </Eway_Rapid31>
115
+ </modules>
116
+ </translate>
117
+ <layout>
118
+ <updates>
119
+ <ewayrapid>
120
+ <file>ewayrapid/layout.xml</file>
121
+ </ewayrapid>
122
+ </updates>
123
+ </layout>
124
+ <routers>
125
+ <ewayrapid>
126
+ <use>standard</use>
127
+ <args>
128
+ <module>Eway_Rapid31</module>
129
+ <frontName>ewayrapid</frontName>
130
+ </args>
131
+ </ewayrapid>
132
+ </routers>
133
+
134
+ <events>
135
+
136
+ <controller_action_predispatch_ewayrapid_mycards_index>
137
+ <observers>
138
+ <eway_rapid31_my_cards>
139
+ <type>singleton</type>
140
+ <class>ewayrapid/observer</class>
141
+ <method>myCards</method>
142
+ </eway_rapid31_my_cards>
143
+ </observers>
144
+ </controller_action_predispatch_ewayrapid_mycards_index>
145
+
146
+ <!-- Event default -->
147
+ <controller_action_predispatch_checkout_onepage_index>
148
+ <observers>
149
+ <eway_rapid31_check_customer_mark>
150
+ <type>singleton</type>
151
+ <class>ewayrapid/observer</class>
152
+ <method>checkCustomerMark</method>
153
+ </eway_rapid31_check_customer_mark>
154
+ </observers>
155
+ </controller_action_predispatch_checkout_onepage_index>
156
+
157
+ <sales_order_place_before>
158
+ <observers>
159
+ <sales_order_place_before>
160
+ <class>ewayrapid/observer</class>
161
+ <method>sales_order_place_before</method>
162
+ </sales_order_place_before>
163
+ </observers>
164
+ </sales_order_place_before>
165
+
166
+ <sales_order_place_after>
167
+ <observers>
168
+ <sales_order_place_after>
169
+ <class>ewayrapid/observer</class>
170
+ <method>sales_order_place_after</method>
171
+ </sales_order_place_after>
172
+ </observers>
173
+ </sales_order_place_after>
174
+
175
+ <sales_order_invoice_save_after>
176
+ <observers>
177
+ <sales_order_invoice_save_after>
178
+ <class>ewayrapid/observer</class>
179
+ <method>sales_order_invoice_save_after</method>
180
+ </sales_order_invoice_save_after>
181
+ </observers>
182
+ </sales_order_invoice_save_after>
183
+ <checkout_type_onepage_save_order_after>
184
+ <observers>
185
+ <checkout_type_onepage_save_order_after>
186
+ <class>ewayrapid/observer</class>
187
+ <method>checkout_type_onepage_save_order_after</method>
188
+ </checkout_type_onepage_save_order_after>
189
+ </observers>
190
+ </checkout_type_onepage_save_order_after>
191
+
192
+ <!--<sales_order_save_commit_before>
193
+ <observers>
194
+ <sales_order_save_commit_before>
195
+ <class>ewayrapid/observer</class>
196
+ <method>sales_order_save_commit_before</method>
197
+ </sales_order_save_commit_before>
198
+ </observers>
199
+ </sales_order_save_commit_before>
200
+
201
+ <sales_order_save_commit_after>
202
+ <observers>
203
+ <sales_order_save_commit_after>
204
+ <class>ewayrapid/observer</class>
205
+ <method>sales_order_save_commit_after</method>
206
+ </sales_order_save_commit_after>
207
+ </observers>
208
+ </sales_order_save_commit_after>-->
209
+
210
+ <checkout_submit_all_after>
211
+ <observers>
212
+ <checkout_submit_all_after>
213
+ <class>ewayrapid/observer</class>
214
+ <method>checkout_submit_all_after</method>
215
+ </checkout_submit_all_after>
216
+ </observers>
217
+ <observers>
218
+ <eway_recurring_profile>
219
+ <class>ewayrapid/observer</class>
220
+ <method>createRecurringOrder</method>
221
+ </eway_recurring_profile>
222
+ </observers>
223
+ </checkout_submit_all_after>
224
+ </events>
225
+
226
+ </frontend>
227
+
228
+ <!--
229
+ <admin>
230
+ <routers>
231
+ <ewayrapid_admin>
232
+ <use>admin</use>
233
+ <args>
234
+ <module>Eway_Rapid31_Adminhtml</module>
235
+ <frontName>ewayadmin</frontName>
236
+ </args>
237
+ </ewayrapid_admin>
238
+ </routers>
239
+ </admin>
240
+ -->
241
+
242
+ <admin>
243
+ <routers>
244
+ <adminhtml>
245
+ <args>
246
+ <modules>
247
+ <eway_rapid31_adminhtml after="Mage_Adminhtml">Eway_Rapid31_Adminhtml</eway_rapid31_adminhtml>
248
+ <eway_rapid31 before="-">Eway_Rapid31_Adminhtml</eway_rapid31>
249
+ </modules>
250
+ </args>
251
+ </adminhtml>
252
+ </routers>
253
+ </admin>
254
+
255
+ <adminhtml>
256
+ <translate>
257
+ <modules>
258
+ <Eway_Rapid31>
259
+ <files>
260
+ <default>Eway_Rapid31.csv</default>
261
+ </files>
262
+ </Eway_Rapid31>
263
+ </modules>
264
+ </translate>
265
+ <layout>
266
+ <updates>
267
+ <ewayrapid>
268
+ <file>ewayrapid/layout.xml</file>
269
+ </ewayrapid>
270
+ </updates>
271
+ </layout>
272
+ <!--<menu>
273
+ <system>
274
+ <children>
275
+ <eway_admin_index>
276
+ <title>Eway Mass</title>
277
+ <action>ewayadmin/index/index</action>
278
+ </eway_admin_index>
279
+ <eway_admin_mass_authorised>
280
+ <title>Eway Mass</title>
281
+ <action>ewayadmin/index/massEwayAuthorised</action>
282
+ </eway_admin_mass_authorised>
283
+ <eway_admin_mass_pending>
284
+ <title>Eway Mass</title>
285
+ <action>ewayadmin/index/massPending</action>
286
+ </eway_admin_mass_pending>
287
+ </children>
288
+ </system>
289
+ </menu>-->
290
+ <menu>
291
+ <sales>
292
+ <children>
293
+ <eway_orders>
294
+ <title>eWAY</title>
295
+ <action>adminhtml/ewayadmin/ewayorders</action>
296
+ <sort_order>100</sort_order>
297
+ </eway_orders>
298
+ </children>
299
+ </sales>
300
+ </menu>
301
+ </adminhtml>
302
+ <default>
303
+ <payment>
304
+ <ewayrapid_general>
305
+ <active>0</active>
306
+ <mode>sandbox</mode>
307
+ <sandbox_endpoint>https://api.sandbox.ewaypayments.com/</sandbox_endpoint>
308
+ <live_endpoint>https://api.ewaypayments.com/</live_endpoint>
309
+ <payment_action>authorize_capture</payment_action>
310
+ <connection_type>direct</connection_type>
311
+ <can_edit_token>1</can_edit_token>
312
+ <can_cancel_subscriptions>0</can_cancel_subscriptions>
313
+ <block_fraud_customers>1</block_fraud_customers>
314
+ <useccv>1</useccv>
315
+ <cctypes>VI,MC</cctypes>
316
+ <order_status>eway_captured</order_status>
317
+ <allowspecific>0</allowspecific>
318
+ <ssl_verification>0</ssl_verification>
319
+ <transfer_cart_items>1</transfer_cart_items>
320
+ <debug>0</debug>
321
+ <billing_agreement_title>eWAY Billing Agreement</billing_agreement_title>
322
+ </ewayrapid_general>
323
+ <ewayrapid_notsaved>
324
+ <model>ewayrapid/method_notsaved</model>
325
+ <active>0</active>
326
+ <title>Credit Card - eWAY (not saved)</title>
327
+ </ewayrapid_notsaved>
328
+ <ewayrapid_saved>
329
+ <model>ewayrapid/method_saved</model>
330
+ <active>0</active>
331
+ <title>Credit Card - eWAY (saved)</title>
332
+ </ewayrapid_saved>
333
+ <ewayrapid_ewayone>
334
+ <model>ewayrapid/method_ewayone</model>
335
+ <active>0</active>
336
+ <title>Credit Card - eWAY</title>
337
+ <save_card>1</save_card>
338
+ <save_text>Save my details</save_text>
339
+ <save_card_checked>1</save_card_checked>
340
+ </ewayrapid_ewayone>
341
+ </payment>
342
+ </default>
343
+ <phpunit>
344
+ <suite>
345
+ <modules>
346
+ <Eway_Rapid31/>
347
+ </modules>
348
+ </suite>
349
+ </phpunit>
350
+ <crontab>
351
+ <jobs>
352
+ <eway_recurring_order>
353
+ <schedule>
354
+ <cron_expr>0 * * * *</cron_expr>
355
+ </schedule>
356
+ <run>
357
+ <model>ewayrapid/observer::cronRecurringOrder</model>
358
+ </run>
359
+ </eway_recurring_order>
360
+ <eway_rapid31>
361
+ <schedule>
362
+ <cron_expr>0 */3 * * *</cron_expr>
363
+ </schedule>
364
+ <run>
365
+ <model>ewayrapid/ewayCron::querySuspectFraud</model>
366
+ </run>
367
+ </eway_rapid31>
368
+ </jobs>
369
+ </crontab>
 
 
 
 
 
 
 
 
 
 
 
 
370
  </config>
app/code/community/Eway/Rapid31/sql/ewayrapid_setup/install-0.1.0.php CHANGED
@@ -6,7 +6,8 @@ $installer->startSetup();
6
 
7
  $setup = Mage::getResourceModel('customer/setup', 'core_setup');
8
 
9
- $setup->addAttribute('customer', 'saved_tokens_json', array(
 
10
  'input' => '',
11
  'type' => 'text',
12
  'label' => '',
@@ -14,6 +15,7 @@ $setup->addAttribute('customer', 'saved_tokens_json', array(
14
  'required' => '0',
15
  'user_defined' => '0',
16
  'backend' => 'ewayrapid/backend_savedtokens',
17
- ));
 
18
 
19
  $installer->endSetup();
6
 
7
  $setup = Mage::getResourceModel('customer/setup', 'core_setup');
8
 
9
+ $setup->addAttribute(
10
+ 'customer', 'saved_tokens_json', array(
11
  'input' => '',
12
  'type' => 'text',
13
  'label' => '',
15
  'required' => '0',
16
  'user_defined' => '0',
17
  'backend' => 'ewayrapid/backend_savedtokens',
18
+ )
19
+ );
20
 
21
  $installer->endSetup();
app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-1.0.0-1.0.1.php CHANGED
@@ -5,30 +5,33 @@ $installer = $this;
5
  $installer->startSetup();
6
 
7
  $installer->getConnection()
8
- ->addColumn($installer->getTable('sales/order'),
9
- 'eway_transaction_id',
10
- array(
 
11
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
12
  'length' => 50,
13
  'nullable' => true,
14
  'comment' => 'eWAY Transaction ID'
15
- )
16
  );
17
 
18
  $installer->getConnection()
19
- ->addColumn($installer->getTable('sales/quote'),
20
- 'transaction_id',
21
- array(
 
22
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
23
  'length' => 50,
24
  'nullable' => true,
25
  'comment' => 'eWAY Transaction ID'
26
- )
27
  );
28
 
29
  $setup = Mage::getResourceModel('customer/setup', 'core_setup');
30
 
31
- $setup->addAttribute('customer', 'mark_fraud', array(
 
32
  'input' => '',
33
  'type' => 'int',
34
  'label' => '',
@@ -36,6 +39,7 @@ $setup->addAttribute('customer', 'mark_fraud', array(
36
  'required' => '0',
37
  'user_defined' => '0',
38
  'backend' => '',
39
- ));
 
40
 
41
  $installer->endSetup();
5
  $installer->startSetup();
6
 
7
  $installer->getConnection()
8
+ ->addColumn(
9
+ $installer->getTable('sales/order'),
10
+ 'eway_transaction_id',
11
+ array(
12
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
13
  'length' => 50,
14
  'nullable' => true,
15
  'comment' => 'eWAY Transaction ID'
16
+ )
17
  );
18
 
19
  $installer->getConnection()
20
+ ->addColumn(
21
+ $installer->getTable('sales/quote'),
22
+ 'transaction_id',
23
+ array(
24
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
25
  'length' => 50,
26
  'nullable' => true,
27
  'comment' => 'eWAY Transaction ID'
28
+ )
29
  );
30
 
31
  $setup = Mage::getResourceModel('customer/setup', 'core_setup');
32
 
33
+ $setup->addAttribute(
34
+ 'customer', 'mark_fraud', array(
35
  'input' => '',
36
  'type' => 'int',
37
  'label' => '',
39
  'required' => '0',
40
  'user_defined' => '0',
41
  'backend' => '',
42
+ )
43
+ );
44
 
45
  $installer->endSetup();
app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-1.0.1-1.0.3.php CHANGED
@@ -6,7 +6,8 @@ $installer->startSetup();
6
 
7
  $setup = Mage::getResourceModel('customer/setup', 'core_setup');
8
 
9
- $setup->addAttribute('customer', 'block_fraud_customer', array(
 
10
  'input' => 'select',
11
  'type' => 'int',
12
  'label' => 'Unblock Fraud Customer',
@@ -15,7 +16,8 @@ $setup->addAttribute('customer', 'block_fraud_customer', array(
15
  'user_defined' => '0',
16
  'default' => '0',
17
  'source' => 'eav/entity_attribute_source_boolean'
18
- ));
 
19
 
20
  try {
21
  $attributeId = $setup->getAttributeId('customer', 'block_fraud_customer');
6
 
7
  $setup = Mage::getResourceModel('customer/setup', 'core_setup');
8
 
9
+ $setup->addAttribute(
10
+ 'customer', 'block_fraud_customer', array(
11
  'input' => 'select',
12
  'type' => 'int',
13
  'label' => 'Unblock Fraud Customer',
16
  'user_defined' => '0',
17
  'default' => '0',
18
  'source' => 'eav/entity_attribute_source_boolean'
19
+ )
20
+ );
21
 
22
  try {
23
  $attributeId = $setup->getAttributeId('customer', 'block_fraud_customer');
app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-1.3.2-1.4.0.php CHANGED
@@ -5,7 +5,8 @@ $installer = $this;
5
  $installer->startSetup();
6
 
7
  $installer->getConnection()
8
- ->addColumn($installer->getTable('sales/order_payment'),
 
9
  'fraud_action',
10
  array(
11
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
@@ -16,7 +17,8 @@ $installer->getConnection()
16
  );
17
 
18
  $installer->getConnection()
19
- ->addColumn($installer->getTable('sales/quote_payment'),
 
20
  'fraud_action',
21
  array(
22
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
@@ -27,7 +29,8 @@ $installer->getConnection()
27
  );
28
 
29
  $installer->getConnection()
30
- ->addColumn($installer->getTable('sales/order_payment'),
 
31
  'fraud_codes',
32
  array(
33
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
@@ -38,7 +41,8 @@ $installer->getConnection()
38
  );
39
 
40
  $installer->getConnection()
41
- ->addColumn($installer->getTable('sales/quote_payment'),
 
42
  'fraud_codes',
43
  array(
44
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
@@ -49,7 +53,8 @@ $installer->getConnection()
49
  );
50
 
51
  $installer->getConnection()
52
- ->addColumn($installer->getTable('sales/order_payment'),
 
53
  'transaction_captured',
54
  array(
55
  'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
@@ -60,7 +65,8 @@ $installer->getConnection()
60
  );
61
 
62
  $installer->getConnection()
63
- ->addColumn($installer->getTable('sales/quote_payment'),
 
64
  'transaction_captured',
65
  array(
66
  'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
@@ -71,7 +77,8 @@ $installer->getConnection()
71
  );
72
 
73
  $installer->getConnection()
74
- ->addColumn($installer->getTable('sales/order_payment'),
 
75
  'beagle_score',
76
  array(
77
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
@@ -82,7 +89,8 @@ $installer->getConnection()
82
  );
83
 
84
  $installer->getConnection()
85
- ->addColumn($installer->getTable('sales/quote_payment'),
 
86
  'beagle_score',
87
  array(
88
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
@@ -93,7 +101,8 @@ $installer->getConnection()
93
  );
94
 
95
  $installer->getConnection()
96
- ->addColumn($installer->getTable('sales/order_payment'),
 
97
  'beagle_verification',
98
  array(
99
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
@@ -104,7 +113,8 @@ $installer->getConnection()
104
  );
105
 
106
  $installer->getConnection()
107
- ->addColumn($installer->getTable('sales/quote_payment'),
 
108
  'beagle_verification',
109
  array(
110
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
5
  $installer->startSetup();
6
 
7
  $installer->getConnection()
8
+ ->addColumn(
9
+ $installer->getTable('sales/order_payment'),
10
  'fraud_action',
11
  array(
12
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
17
  );
18
 
19
  $installer->getConnection()
20
+ ->addColumn(
21
+ $installer->getTable('sales/quote_payment'),
22
  'fraud_action',
23
  array(
24
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
29
  );
30
 
31
  $installer->getConnection()
32
+ ->addColumn(
33
+ $installer->getTable('sales/order_payment'),
34
  'fraud_codes',
35
  array(
36
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
41
  );
42
 
43
  $installer->getConnection()
44
+ ->addColumn(
45
+ $installer->getTable('sales/quote_payment'),
46
  'fraud_codes',
47
  array(
48
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
53
  );
54
 
55
  $installer->getConnection()
56
+ ->addColumn(
57
+ $installer->getTable('sales/order_payment'),
58
  'transaction_captured',
59
  array(
60
  'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
65
  );
66
 
67
  $installer->getConnection()
68
+ ->addColumn(
69
+ $installer->getTable('sales/quote_payment'),
70
  'transaction_captured',
71
  array(
72
  'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
77
  );
78
 
79
  $installer->getConnection()
80
+ ->addColumn(
81
+ $installer->getTable('sales/order_payment'),
82
  'beagle_score',
83
  array(
84
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
89
  );
90
 
91
  $installer->getConnection()
92
+ ->addColumn(
93
+ $installer->getTable('sales/quote_payment'),
94
  'beagle_score',
95
  array(
96
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
101
  );
102
 
103
  $installer->getConnection()
104
+ ->addColumn(
105
+ $installer->getTable('sales/order_payment'),
106
  'beagle_verification',
107
  array(
108
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
113
  );
114
 
115
  $installer->getConnection()
116
+ ->addColumn(
117
+ $installer->getTable('sales/quote_payment'),
118
  'beagle_verification',
119
  array(
120
  'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
app/design/adminhtml/default/default/layout/ewayrapid/layout.xml CHANGED
@@ -1,79 +1,79 @@
1
- <?xml version="1.0"?>
2
- <layout version="0.1.0">
3
- <adminhtml_sales_order_create_index>
4
- <reference name="head">
5
- <action method="addExternalItem"><type>external_js</type><name>https://secure.ewaypayments.com/scripts/eCrypt.js</name><params/></action>
6
- <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
7
- </reference>
8
- <reference name="js">
9
- <block type="core/template" name="ewayrapid.js" after="-">
10
- <action method="setArea"><area>frontend</area></action>
11
- <action ifconfig="payment/ewayrapid_general/active" method="setTemplate" >
12
- <template>ewayrapid/js.phtml</template>
13
- </action>
14
- </block>
15
- </reference>
16
- </adminhtml_sales_order_create_index>
17
- <adminhtml_ewayadmin_ewayorders>
18
- <reference name="menu">
19
- <action method="setActive">
20
- <menupath>sales/eway_orders</menupath>
21
- </action>
22
- </reference>
23
- <reference name="content">
24
- <block type="ewayrapid/adminhtml_sales_order" name="eway_orders" />
25
- </reference>
26
- </adminhtml_ewayadmin_ewayorders>
27
- <adminhtml_ewayadmin_grid>
28
- <update handle="formkey"/>
29
- <block type="ewayrapid/adminhtml_sales_order_grid" name="eway_order.grid" output="toHtml"></block>
30
- </adminhtml_ewayadmin_grid>
31
-
32
-
33
- <adminhtml_customer_edit>
34
- <reference name="head">
35
- <action method="addExternalItem"><type>external_js</type><name>https://secure.ewaypayments.com/scripts/eCrypt.js</name><params/></action>
36
- <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
37
- </reference>
38
- <reference name="js">
39
- <block type="core/template" name="ewayrapid.js" after="-">
40
- <action method="setArea"><area>frontend</area></action>
41
- <action ifconfig="payment/ewayrapid_general/active" method="setTemplate" >
42
- <template>ewayrapid/js.phtml</template>
43
- </action>
44
- </block>
45
- </reference>
46
- <reference name="customer_edit_tabs">
47
- <block type="ewayrapid/adminhtml_customer_savedcard" name="admin.customer.savedcard" template="ewayrapid/customer/cardcontainer.phtml">
48
- <block type="ewayrapid/adminhtml_customer_method" name="admin.customer.ewayrapid.method" template="ewayrapid/customer/method.phtml" before="-">
49
- <action method="setCode"><code>ewayrapid</code></action>
50
- <block type="ewayrapid/adminhtml_customer_edit_tab_cards" name="admin.customer.ewayrapid.cards" template="ewayrapid/customer/edit/tab/cards.phtml">
51
- <action method="setCode"><code>ewayrapid</code></action>
52
- </block>
53
- <block type="ewayrapid/adminhtml_customer_edit_tab_form" name="admin.customer.ewayrapid.form" template="ewayrapid/customer/edit/tab/form.phtml">
54
- <action method="setCode"><code>ewayrapid</code></action>
55
- </block>
56
- </block>
57
- </block>
58
- <action method="addTab"><name>admin.customer.savedcard</name><block>admin.customer.savedcard</block></action>
59
- </reference>
60
- </adminhtml_customer_edit>
61
-
62
- <adminhtml_ewayrapid_savedcard_load>
63
- <block type="ewayrapid/adminhtml_customer_edit_tab_form" name="root" template="ewayrapid/customer/edit/tab/form.phtml">
64
- <action method="setCode"><code>ewayrapid</code></action>
65
- </block>
66
- </adminhtml_ewayrapid_savedcard_load>
67
-
68
- <adminhtml_ewayrapid_savedcard_save>
69
- <block type="ewayrapid/adminhtml_customer_edit_tab_cards" name="root" template="ewayrapid/customer/edit/tab/cards.phtml">
70
- <action method="setCode"><code>ewayrapid</code></action>
71
- </block>
72
- </adminhtml_ewayrapid_savedcard_save>
73
-
74
- <adminhtml_ewayrapid_savedcard_savetoken>
75
- <block type="ewayrapid/adminhtml_customer_edit_tab_cards" name="root" template="ewayrapid/customer/edit/tab/cards.phtml">
76
- <action method="setCode"><code>ewayrapid</code></action>
77
- </block>
78
- </adminhtml_ewayrapid_savedcard_savetoken>
79
  </layout>
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <adminhtml_sales_order_create_index>
4
+ <reference name="head">
5
+ <action method="addExternalItem"><type>external_js</type><name>https://secure.ewaypayments.com/scripts/eCrypt.js</name><params/></action>
6
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
7
+ </reference>
8
+ <reference name="js">
9
+ <block type="core/template" name="ewayrapid.js" after="-">
10
+ <action method="setArea"><area>frontend</area></action>
11
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate" >
12
+ <template>ewayrapid/js.phtml</template>
13
+ </action>
14
+ </block>
15
+ </reference>
16
+ </adminhtml_sales_order_create_index>
17
+ <adminhtml_ewayadmin_ewayorders>
18
+ <reference name="menu">
19
+ <action method="setActive">
20
+ <menupath>sales/eway_orders</menupath>
21
+ </action>
22
+ </reference>
23
+ <reference name="content">
24
+ <block type="ewayrapid/adminhtml_sales_order" name="eway_orders" />
25
+ </reference>
26
+ </adminhtml_ewayadmin_ewayorders>
27
+ <adminhtml_ewayadmin_grid>
28
+ <update handle="formkey"/>
29
+ <block type="ewayrapid/adminhtml_sales_order_grid" name="eway_order.grid" output="toHtml"></block>
30
+ </adminhtml_ewayadmin_grid>
31
+
32
+
33
+ <adminhtml_customer_edit>
34
+ <reference name="head">
35
+ <action method="addExternalItem"><type>external_js</type><name>https://secure.ewaypayments.com/scripts/eCrypt.js</name><params/></action>
36
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
37
+ </reference>
38
+ <reference name="js">
39
+ <block type="core/template" name="ewayrapid.js" after="-">
40
+ <action method="setArea"><area>frontend</area></action>
41
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate" >
42
+ <template>ewayrapid/js.phtml</template>
43
+ </action>
44
+ </block>
45
+ </reference>
46
+ <reference name="customer_edit_tabs">
47
+ <block type="ewayrapid/adminhtml_customer_savedcard" name="admin.customer.savedcard" template="ewayrapid/customer/cardcontainer.phtml">
48
+ <block type="ewayrapid/adminhtml_customer_method" name="admin.customer.ewayrapid.method" template="ewayrapid/customer/method.phtml" before="-">
49
+ <action method="setCode"><code>ewayrapid</code></action>
50
+ <block type="ewayrapid/adminhtml_customer_edit_tab_cards" name="admin.customer.ewayrapid.cards" template="ewayrapid/customer/edit/tab/cards.phtml">
51
+ <action method="setCode"><code>ewayrapid</code></action>
52
+ </block>
53
+ <block type="ewayrapid/adminhtml_customer_edit_tab_form" name="admin.customer.ewayrapid.form" template="ewayrapid/customer/edit/tab/form.phtml">
54
+ <action method="setCode"><code>ewayrapid</code></action>
55
+ </block>
56
+ </block>
57
+ </block>
58
+ <action method="addTab"><name>admin.customer.savedcard</name><block>admin.customer.savedcard</block></action>
59
+ </reference>
60
+ </adminhtml_customer_edit>
61
+
62
+ <adminhtml_ewayrapid_savedcard_load>
63
+ <block type="ewayrapid/adminhtml_customer_edit_tab_form" name="root" template="ewayrapid/customer/edit/tab/form.phtml">
64
+ <action method="setCode"><code>ewayrapid</code></action>
65
+ </block>
66
+ </adminhtml_ewayrapid_savedcard_load>
67
+
68
+ <adminhtml_ewayrapid_savedcard_save>
69
+ <block type="ewayrapid/adminhtml_customer_edit_tab_cards" name="root" template="ewayrapid/customer/edit/tab/cards.phtml">
70
+ <action method="setCode"><code>ewayrapid</code></action>
71
+ </block>
72
+ </adminhtml_ewayrapid_savedcard_save>
73
+
74
+ <adminhtml_ewayrapid_savedcard_savetoken>
75
+ <block type="ewayrapid/adminhtml_customer_edit_tab_cards" name="root" template="ewayrapid/customer/edit/tab/cards.phtml">
76
+ <action method="setCode"><code>ewayrapid</code></action>
77
+ </block>
78
+ </adminhtml_ewayrapid_savedcard_savetoken>
79
  </layout>
app/design/adminhtml/default/default/template/ewayrapid/customer/edit/tab/cards.phtml CHANGED
@@ -1,36 +1,36 @@
1
- <div class="entry-edit-head">
2
- <h4 class="icon-head head-customer-address-list"><?php echo $this->__('Saved Card') ?></h4>
3
- </div>
4
- <div class="fieldset" style="padding:0">
5
- <ol>
6
- <?php if ($this->checkCards()): ?>
7
- <?php foreach ($this->getCards() as $id => $card): ?>
8
- <?php if(!$card->getActive()) continue; ?>
9
- <li class="item info-box" id="token-<?php echo $id ?>" style="cursor:default">
10
- <h3 class="box-title">
11
- <?php if ($card->getExpYear()): ?>
12
- <small class="right"><?php echo $card->getExpMonth() . '/' . $card->getExpYear() ?></small>
13
- <?php endif; ?>
14
- <?php echo $this->__('Card: %s', $card->getCard()) ?>
15
- </h3>
16
- <address class="box-content" style="overflow:auto">
17
-
18
- <?php echo $this->formatAddress($card->getAddress()) ?>
19
- <div class="right">
20
- <?php if(Mage::helper('ewayrapid')->checkCardName($card) != Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD): ?>
21
- <button class="button" type="button" onclick="ewayrapid.editCard( <?php echo $id; ?> );">
22
- <span><?php echo $this->__('Edit'); ?></span>
23
- </button>
24
- <?php endif; ?>
25
- <button class="button" type="button" onclick="ewayrapid.deleteCard( <?php echo $id; ?> );">
26
- <span><?php echo $this->__('Delete'); ?></span>
27
- </button>
28
- </div>
29
- </address>
30
- </li>
31
- <?php endforeach; ?>
32
- <?php else: ?>
33
- <li class="item"><?php echo $this->__('No payment data saved yet.') ?></li>
34
- <?php endif; ?>
35
- </ol>
36
- </div>
1
+ <div class="entry-edit-head">
2
+ <h4 class="icon-head head-customer-address-list"><?php echo $this->__('Saved Card') ?></h4>
3
+ </div>
4
+ <div class="fieldset" style="padding:0">
5
+ <ol>
6
+ <?php if ($this->checkCards()): ?>
7
+ <?php foreach ($this->getCards() as $id => $card): ?>
8
+ <?php if(!$card->getActive()) continue; ?>
9
+ <li class="item info-box" id="token-<?php echo $id ?>" style="cursor:default">
10
+ <h3 class="box-title">
11
+ <?php if ($card->getExpYear()): ?>
12
+ <small class="right"><?php echo $card->getExpMonth() . '/' . $card->getExpYear() ?></small>
13
+ <?php endif; ?>
14
+ <?php echo $this->__('Card: %s', $card->getCard()) ?>
15
+ </h3>
16
+ <address class="box-content" style="overflow:auto">
17
+
18
+ <?php echo $this->formatAddress($card->getAddress()) ?>
19
+ <div class="right">
20
+ <?php if(Mage::helper('ewayrapid')->checkCardName($card) != Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD): ?>
21
+ <button class="button" type="button" onclick="ewayrapid.editCard( <?php echo $id; ?> );">
22
+ <span><?php echo $this->__('Edit'); ?></span>
23
+ </button>
24
+ <?php endif; ?>
25
+ <button class="button" type="button" onclick="ewayrapid.deleteCard( <?php echo $id; ?> );">
26
+ <span><?php echo $this->__('Delete'); ?></span>
27
+ </button>
28
+ </div>
29
+ </address>
30
+ </li>
31
+ <?php endforeach; ?>
32
+ <?php else: ?>
33
+ <li class="item"><?php echo $this->__('No payment data saved yet.') ?></li>
34
+ <?php endif; ?>
35
+ </ol>
36
+ </div>
app/design/adminhtml/default/default/template/ewayrapid/customer/edit/tab/form.phtml CHANGED
@@ -1,218 +1,218 @@
1
- <div class="entry-edit-head">
2
- <h4 class="icon-head head-customer-address-list">
3
- <?php if( $this->isEdit() ): ?>
4
- <?php echo $this->__('Editing Card %s', $this->getCard()->getCard()); ?>
5
- <?php else: ?>
6
- <?php echo $this->__('Add A Credit Card') ?>
7
- <?php endif; ?>
8
- </h4>
9
- </div>
10
- <div class="fieldset">
11
- <input type="hidden" id="token_id" name="<?php echo $this->getCode(); ?>[token_id]" value="<?php echo $this->getTokenId() ? $this->getTokenId() : 0; ?>" />
12
- <input type="hidden" name="<?php echo $this->getCode(); ?>[TokenCustomerID]" value="<?php echo $this->getCard()->getToken() ? $this->getCard()->getToken() : ''; ?>" />
13
- <h4><?php echo $this->__('Cardholder Information') ?></h4>
14
- <table class="form-list" cellspacing="0">
15
- <tr>
16
- <td class="label"><label for="<?php echo $this->getCode(); ?>_title"><?php echo $this->__('Title') ?></label></td>
17
- <td class="value">
18
- <select id="<?php echo $this->getCode(); ?>_title" name="<?php echo $this->getCode(); ?>[address][title]">
19
- <?php foreach ($this->getPrefixOptions() as $_option): ?>
20
- <option
21
- value="<?php echo $_option ?>"<?php if ($this->getCard()->getAddress()->getTitle() == $_option): ?>
22
- selected="selected"<?php endif; ?>><?php echo $this->__($_option) ?></option>
23
- <?php endforeach; ?>
24
- </select>
25
- </td>
26
- </tr>
27
- <tr>
28
- <td class="label"><label for="<?php echo $this->getCode(); ?>_fn"><?php echo $this->__('First Name') ?> <span class="required">*</span></label></td>
29
- <td class="value">
30
- <input type="text" id="<?php echo $this->getCode(); ?>_fn" name="<?php echo $this->getCode(); ?>[address][firstname]"
31
- class="input-text save-card-validate" data-validate="required-entry validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('FirstName')); ?>" />
32
- </td>
33
- </tr>
34
- <tr>
35
- <td class="label"><label for="<?php echo $this->getCode(); ?>_ln"><?php echo $this->__('Last Name') ?> <span class="required">*</span></label></td>
36
- <td class="value">
37
- <input type="text" id="<?php echo $this->getCode(); ?>_ln" name="<?php echo $this->getCode(); ?>[address][lastname]"
38
- class="input-text save-card-validate" data-validate="required-entry validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('LastName')); ?>" />
39
- </td>
40
- </tr>
41
- <tr>
42
- <td class="label"><label for="<?php echo $this->getCode(); ?>_company"><?php echo $this->__('Company') ?></label></td>
43
- <td class="value">
44
- <input type="text" id="<?php echo $this->getCode(); ?>_company" name="<?php echo $this->getCode(); ?>[address][company]" class="input-text" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getCompanyName()); ?>" />
45
- </td>
46
- </tr>
47
- <tr>
48
- <td class="label"><label for="<?php echo $this->getCode(); ?>_job_desc"><?php echo $this->__('Job Description') ?></label></td>
49
- <td class="value">
50
- <input type="text" id="<?php echo $this->getCode(); ?>_job_desc" name="<?php echo $this->getCode(); ?>[address][job_description]" class="input-text" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getJobDescription()); ?>" />
51
- </td>
52
- </tr>
53
- <tr>
54
- <td class="label"><label for="<?php echo $this->getCode(); ?>_street1"><?php echo $this->__('Street Address') ?> <span class="required">*</span></label></td>
55
- <td class="value">
56
- <input type="text" id="<?php echo $this->getCode(); ?>_street1" name="<?php echo $this->getCode(); ?>[address][street][]"
57
- class="input-text save-card-validate" data-validate="required-entry validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getStreet1()); ?>" />
58
- </td>
59
- </tr>
60
- <tr>
61
- <td></td>
62
- <td class="value">
63
- <input type="text" id="<?php echo $this->getCode(); ?>_street2" name="<?php echo $this->getCode(); ?>[address][street][]"
64
- class="input-text save-card-validate" data-validate="validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getStreet2()); ?>" />
65
- </td>
66
- </tr>
67
- <tr>
68
- <td class="label"><label for="<?php echo $this->getCode(); ?>_city"><?php echo $this->__('City') ?> <span class="required">*</span></label></td>
69
- <td class="value">
70
- <input type="text" id="<?php echo $this->getCode(); ?>_city" name="<?php echo $this->getCode(); ?>[address][city]"
71
- class="input-text save-card-validate" data-validate="required-entry validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('City')); ?>" />
72
- </td>
73
- </tr>
74
- <tr>
75
- <td class="label"><label for="<?php echo $this->getCode(); ?>_region_id"><?php echo $this->__('State/Province') ?> <span class="required">*</span></label></td>
76
- <td class="value">
77
- <select class="validate-select" title="State/Province" name="<?php echo $this->getCode(); ?>[address][region_id]" id="<?php echo $this->getCode(); ?>_region_id">
78
- <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
79
- </select>
80
- <script type="text/javascript">
81
- $('<?php echo $this->getCode(); ?>_region_id').setAttribute('defaultValue', '<?php echo $this->getRegionId()?>');
82
- </script>
83
- <input type="text" class="input-text" title="State/Province" value="<?php echo $this->escapeHtml( $this->getCard()->getAddress()->getData('State') ); ?>" name="<?php echo $this->getCode(); ?>[address][region]" id="<?php echo $this->getCode(); ?>_region" />
84
- </td>
85
- </tr>
86
- <tr>
87
- <td class="label"><label for="<?php echo $this->getCode(); ?>_postcode"><?php echo $this->__('Zip/Postal Code') ?> <span class="required">*</span></label></td>
88
- <td class="value">
89
- <input type="text" id="<?php echo $this->getCode(); ?>_postcode" name="<?php echo $this->getCode(); ?>[address][postcode]"
90
- class="input-text save-card-validate" data-validate="required-entry validate-zip-international validate-length maximum-length-30" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('PostalCode')); ?>" />
91
- </td>
92
- </tr>
93
- <tr>
94
- <td class="label"><label for="<?php echo $this->getCode(); ?>_country"><?php echo $this->__('Country') ?> <span class="required">*</span></label></td>
95
- <td class="value">
96
- <?php echo Mage::helper('ewayrapid')->getCountryHtmlSelect( $this->getCode() . '[address][country_id]',strtoupper($this->getCard()->getAddress()->getCountry()), $this->getCode().'_country' ); ?>
97
- </td>
98
- </tr>
99
- <tr>
100
- <td class="label"><label for="<?php echo $this->getCode(); ?>_telephone"><?php echo $this->__('Telephone') ?> <span class="required">*</span></label></td>
101
- <td class="value">
102
- <input type="text" id="<?php echo $this->getCode(); ?>_telephone" name="<?php echo $this->getCode(); ?>[address][telephone]"
103
- class="input-text save-card-validate" data-validate="required-entry eway-validate-phone validate-length maximum-length-32" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('Phone')); ?>" />
104
- </td>
105
- </tr>
106
- <tr>
107
- <td class="label"><label for="<?php echo $this->getCode(); ?>_mobile"><?php echo $this->__('Mobile') ?></label></td>
108
- <td class="value">
109
- <input type="text" id="<?php echo $this->getCode(); ?>_mobile" name="<?php echo $this->getCode(); ?>[address][mobile]"
110
- class="input-text save-card-validate" data-validate="eway-validate-phone validate-length maximum-length-32" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getMobile()); ?>" />
111
- </td>
112
- </tr>
113
- <tr>
114
- <td class="label"><label for="<?php echo $this->getCode(); ?>_email"><?php echo $this->__('Email') ?></label></td>
115
- <td class="value">
116
- <input type="text" id="<?php echo $this->getCode(); ?>_email" name="<?php echo $this->getCode(); ?>[address][email]"
117
- class="input-text save-card-validate" data-validate="validate-email validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getEmail()); ?>" />
118
- </td>
119
- </tr>
120
- <tr>
121
- <td class="label"><label for="<?php echo $this->getCode(); ?>_fax"><?php echo $this->__('Fax') ?></label></td>
122
- <td class="value">
123
- <input type="text" id="<?php echo $this->getCode(); ?>_fax" name="<?php echo $this->getCode(); ?>[address][fax]"
124
- class="input-text save-card-validate" data-validate="eway-validate-phone validate-length maximum-length-32" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('Fax')); ?>" />
125
- </td>
126
- </tr>
127
- </table>
128
-
129
- <?php if(!Mage::helper('ewayrapid')->useIframeInBackend()): ?>
130
- <h4><?php echo $this->__('Credit Card Information') ?></h4>
131
- <table class="form-list" cellspacing="0" id="<?php echo $this->getCode(); ?>_ccInfo">
132
- <tr>
133
- <td class="label"><label for="<?php echo $this->getCode(); ?>_cc_owner"><?php echo $this->__('Name on Card') ?> <span class="required">*</span></label></td>
134
- <td class="value">
135
- <input type="text" id="<?php echo $this->getCode(); ?>_cc_owner" name="<?php echo $this->getCode(); ?>[payment][cc_owner]" title="<?php echo $this->__('Card Holder Name') ?>"
136
- class="input-text save-card-validate" data-validate="required-entry validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getOwner()); ?>" autocomplete="off" />
137
- </td>
138
- </tr>
139
- <tr>
140
- <td class="label"><label for="<?php echo $this->getCode(); ?>_cc_number"><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label></td>
141
- <td class="value">
142
- <input type="text" id="<?php echo $this->getCode(); ?>_saved_cc_number" name="<?php echo $this->getCode(); ?>[payment][cc_number]"
143
- title="<?php echo $this->__('Credit Card Number') ?>" class="input-text save-card-validate"
144
- data-validate="validate-cc-number validate-cc-type-auto validate-cc-type"
145
- <?php if($this->isEdit()): ?>value="<?php echo $this->escapeHtml($this->getCard()->getCard()); ?>" disabled="disabled" <?php endif;?> autocomplete="off" />
146
- <input type="hidden" id="<?php echo $this->getCode(); ?>_saved_cc_type" name="<?php echo $this->getCode(); ?>[payment][cc_type]"
147
- value="<?php echo $this->getCard()->getType() ?>"/>
148
- </td>
149
- </tr>
150
- <tr>
151
- <td class="label"><label for="<?php echo $this->getCode(); ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label></td>
152
- <td class="value">
153
- <select id="<?php echo $this->getCode(); ?>_expiration" name="<?php echo $this->getCode(); ?>[payment][cc_exp_month]" class="month save-card-validate"
154
- data-validate="validate-cc-exp required-entry" style="width:150px">
155
- <option value=""><?php echo $this->__('Month') ?></option>
156
- <?php $_ccExpMonth = $this->getCard()->getExpMonth() ?>
157
- <?php foreach(Mage::getSingleton('payment/config')->getMonths() as $k=>$v ): ?>
158
- <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
159
- <?php endforeach ?>
160
- </select>
161
-
162
- <select id="<?php echo $this->getCode(); ?>_expiration_yr" name="<?php echo $this->getCode(); ?>[payment][cc_exp_year]" class="year" style="width:80px">
163
- <option value=""><?php echo $this->__('Year') ?></option>
164
- <?php $_ccExpYear = $this->getCard()->getExpYear() ?>
165
- <?php foreach(Mage::getSingleton('payment/config')->getYears() as $k=>$v ): ?>
166
- <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
167
- <?php endforeach ?>
168
- </select>
169
- </td>
170
- </tr>
171
- <!-- --><?php //if( Mage::helper('payment')->getMethodInstance( $this->getCode() )->getConfigData('useccv') ): ?>
172
- <!-- <tr>-->
173
- <!-- <td class="label"><label for="--><?php //echo $this->getCode(); ?><!--_cc_cid">--><?php //echo $this->__('Card Verification Number') ?><!-- <span class="required">*</span></label></td>-->
174
- <!-- <td class="value">-->
175
- <!-- <input type="text" title="--><?php //echo $this->__('Card Verification Number') ?><!--" class="input-text cvv" id="--><?php //echo $this->getCode(); ?><!--_cc_cid" name="--><?php //echo $this->getCode(); ?><!--[payment][cc_cid]" value="" style="width:50px" autocomplete="off" />-->
176
- <!-- </td>-->
177
- <!-- </tr>-->
178
- <!-- --><?php //endif; ?>
179
- </table>
180
- <!-- --><?php //$requireCvv = Mage::helper('payment')->getMethodInstance( $this->getCode() )->getAdvancedConfigData('require_ccv'); ?>
181
- <!-- --><?php //if( $this->isEdit() && Mage::helper('payment')->getMethodInstance( $this->getCode() )->getConfigData('useccv') && $requireCvv ): ?>
182
- <!-- <table class="form-list" cellspacing="0" id="--><?php //echo $this->getCode(); ?><!--_ccInfoCcv">-->
183
- <!-- <tr>-->
184
- <!-- <td class="label"><label for="--><?php //echo $this->getCode(); ?><!--_saved_cc_cid">--><?php //echo $this->__('Card Verification Number') ?><!-- <span class="required">*</span></label></td>-->
185
- <!-- <td class="value">-->
186
- <!-- <input type="text" title="--><?php //echo $this->__('Card Verification Number') ?><!--" class="input-text cvv" id="--><?php //echo $this->getCode(); ?><!--_saved_cc_cid" name="--><?php //echo $this->getCode(); ?><!--[payment][saved_cc_cid]" value="" style="width:50px" autocomplete="off" />-->
187
- <!-- </td>-->
188
- <!-- </tr>-->
189
- <!-- </table>-->
190
- <!-- --><?php //endif; ?>
191
- <?php endif; ?>
192
- <table class="form-list" cellspacing="0">
193
- <tr>
194
- <td class="label"></td>
195
- <td class="value">
196
- <button class="button" type="button" onclick="<?php echo $this->getCode(); ?>.saveCard(<?php echo $this->getCard()->getToken() ? $this->getCard()->getToken() : ''?>);"><span><?php echo $this->__('Save') ?></span></button>
197
- <a href="#" onclick="<?php echo $this->getCode(); ?>.editCard(0); return false;"><?php echo $this->__('Cancel'); ?></a>
198
- </td>
199
- </tr>
200
- </table>
201
- </div>
202
- <script type="text/javascript">
203
- //<![CDATA[
204
- new RegionUpdater('<?php echo $this->getCode(); ?>_country', '<?php echo $this->getCode(); ?>_region', '<?php echo $this->getCode(); ?>_region_id', <?php echo Mage::helper('directory')->getRegionJson() ?>, undefined, '<?php echo $this->getCode(); ?>_postcode');
205
-
206
- function <?php echo $this->getCode(); ?>_clearAddrValidation() {
207
- $('<?php echo $this->getCode(); ?>_region_id').removeClassName('required-entry').removeClassName('validate-select');
208
- $('<?php echo $this->getCode(); ?>_country').removeClassName('required-entry').removeClassName('validate-select');
209
- $('<?php echo $this->getCode(); ?>_region').removeClassName('required-entry');
210
- $('<?php echo $this->getCode(); ?>_postcode').removeClassName('required-entry');
211
- }
212
-
213
- /* Prevent the region from holding up submit... */
214
- document.observe("dom:loaded", function() {
215
- <?php echo $this->getCode(); ?>_clearAddrValidation();
216
- });
217
- //]]>
218
- </script>
1
+ <div class="entry-edit-head">
2
+ <h4 class="icon-head head-customer-address-list">
3
+ <?php if( $this->isEdit() ): ?>
4
+ <?php echo $this->__('Editing Card %s', $this->getCard()->getCard()); ?>
5
+ <?php else: ?>
6
+ <?php echo $this->__('Add A Credit Card') ?>
7
+ <?php endif; ?>
8
+ </h4>
9
+ </div>
10
+ <div class="fieldset">
11
+ <input type="hidden" id="token_id" name="<?php echo $this->getCode(); ?>[token_id]" value="<?php echo $this->getTokenId() ? $this->getTokenId() : 0; ?>" />
12
+ <input type="hidden" name="<?php echo $this->getCode(); ?>[TokenCustomerID]" value="<?php echo $this->getCard()->getToken() ? $this->getCard()->getToken() : ''; ?>" />
13
+ <h4><?php echo $this->__('Cardholder Information') ?></h4>
14
+ <table class="form-list" cellspacing="0">
15
+ <tr>
16
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_title"><?php echo $this->__('Title') ?></label></td>
17
+ <td class="value">
18
+ <select id="<?php echo $this->getCode(); ?>_title" name="<?php echo $this->getCode(); ?>[address][title]">
19
+ <?php foreach ($this->getPrefixOptions() as $_option): ?>
20
+ <option
21
+ value="<?php echo $_option ?>"<?php if ($this->getCard()->getAddress()->getTitle() == $_option): ?>
22
+ selected="selected"<?php endif; ?>><?php echo $this->__($_option) ?></option>
23
+ <?php endforeach; ?>
24
+ </select>
25
+ </td>
26
+ </tr>
27
+ <tr>
28
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_fn"><?php echo $this->__('First Name') ?> <span class="required">*</span></label></td>
29
+ <td class="value">
30
+ <input type="text" id="<?php echo $this->getCode(); ?>_fn" name="<?php echo $this->getCode(); ?>[address][firstname]"
31
+ class="input-text save-card-validate" data-validate="required-entry validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('FirstName')); ?>" />
32
+ </td>
33
+ </tr>
34
+ <tr>
35
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_ln"><?php echo $this->__('Last Name') ?> <span class="required">*</span></label></td>
36
+ <td class="value">
37
+ <input type="text" id="<?php echo $this->getCode(); ?>_ln" name="<?php echo $this->getCode(); ?>[address][lastname]"
38
+ class="input-text save-card-validate" data-validate="required-entry validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('LastName')); ?>" />
39
+ </td>
40
+ </tr>
41
+ <tr>
42
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_company"><?php echo $this->__('Company') ?></label></td>
43
+ <td class="value">
44
+ <input type="text" id="<?php echo $this->getCode(); ?>_company" name="<?php echo $this->getCode(); ?>[address][company]" class="input-text" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getCompanyName()); ?>" />
45
+ </td>
46
+ </tr>
47
+ <tr>
48
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_job_desc"><?php echo $this->__('Job Description') ?></label></td>
49
+ <td class="value">
50
+ <input type="text" id="<?php echo $this->getCode(); ?>_job_desc" name="<?php echo $this->getCode(); ?>[address][job_description]" class="input-text" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getJobDescription()); ?>" />
51
+ </td>
52
+ </tr>
53
+ <tr>
54
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_street1"><?php echo $this->__('Street Address') ?> <span class="required">*</span></label></td>
55
+ <td class="value">
56
+ <input type="text" id="<?php echo $this->getCode(); ?>_street1" name="<?php echo $this->getCode(); ?>[address][street][]"
57
+ class="input-text save-card-validate" data-validate="required-entry validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getStreet1()); ?>" />
58
+ </td>
59
+ </tr>
60
+ <tr>
61
+ <td></td>
62
+ <td class="value">
63
+ <input type="text" id="<?php echo $this->getCode(); ?>_street2" name="<?php echo $this->getCode(); ?>[address][street][]"
64
+ class="input-text save-card-validate" data-validate="validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getStreet2()); ?>" />
65
+ </td>
66
+ </tr>
67
+ <tr>
68
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_city"><?php echo $this->__('City') ?> <span class="required">*</span></label></td>
69
+ <td class="value">
70
+ <input type="text" id="<?php echo $this->getCode(); ?>_city" name="<?php echo $this->getCode(); ?>[address][city]"
71
+ class="input-text save-card-validate" data-validate="required-entry validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('City')); ?>" />
72
+ </td>
73
+ </tr>
74
+ <tr>
75
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_region_id"><?php echo $this->__('State/Province') ?> <span class="required">*</span></label></td>
76
+ <td class="value">
77
+ <select class="validate-select" title="State/Province" name="<?php echo $this->getCode(); ?>[address][region_id]" id="<?php echo $this->getCode(); ?>_region_id">
78
+ <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
79
+ </select>
80
+ <script type="text/javascript">
81
+ $('<?php echo $this->getCode(); ?>_region_id').setAttribute('defaultValue', '<?php echo $this->getRegionId()?>');
82
+ </script>
83
+ <input type="text" class="input-text" title="State/Province" value="<?php echo $this->escapeHtml( $this->getCard()->getAddress()->getData('State') ); ?>" name="<?php echo $this->getCode(); ?>[address][region]" id="<?php echo $this->getCode(); ?>_region" />
84
+ </td>
85
+ </tr>
86
+ <tr>
87
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_postcode"><?php echo $this->__('Zip/Postal Code') ?> <span class="required">*</span></label></td>
88
+ <td class="value">
89
+ <input type="text" id="<?php echo $this->getCode(); ?>_postcode" name="<?php echo $this->getCode(); ?>[address][postcode]"
90
+ class="input-text save-card-validate" data-validate="required-entry validate-zip-international validate-length maximum-length-30" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('PostalCode')); ?>" />
91
+ </td>
92
+ </tr>
93
+ <tr>
94
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_country"><?php echo $this->__('Country') ?> <span class="required">*</span></label></td>
95
+ <td class="value">
96
+ <?php echo Mage::helper('ewayrapid')->getCountryHtmlSelect( $this->getCode() . '[address][country_id]',strtoupper($this->getCard()->getAddress()->getCountry()), $this->getCode().'_country' ); ?>
97
+ </td>
98
+ </tr>
99
+ <tr>
100
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_telephone"><?php echo $this->__('Telephone') ?> <span class="required">*</span></label></td>
101
+ <td class="value">
102
+ <input type="text" id="<?php echo $this->getCode(); ?>_telephone" name="<?php echo $this->getCode(); ?>[address][telephone]"
103
+ class="input-text save-card-validate" data-validate="required-entry eway-validate-phone validate-length maximum-length-32" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('Phone')); ?>" />
104
+ </td>
105
+ </tr>
106
+ <tr>
107
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_mobile"><?php echo $this->__('Mobile') ?></label></td>
108
+ <td class="value">
109
+ <input type="text" id="<?php echo $this->getCode(); ?>_mobile" name="<?php echo $this->getCode(); ?>[address][mobile]"
110
+ class="input-text save-card-validate" data-validate="eway-validate-phone validate-length maximum-length-32" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getMobile()); ?>" />
111
+ </td>
112
+ </tr>
113
+ <tr>
114
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_email"><?php echo $this->__('Email') ?></label></td>
115
+ <td class="value">
116
+ <input type="text" id="<?php echo $this->getCode(); ?>_email" name="<?php echo $this->getCode(); ?>[address][email]"
117
+ class="input-text save-card-validate" data-validate="validate-email validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getEmail()); ?>" />
118
+ </td>
119
+ </tr>
120
+ <tr>
121
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_fax"><?php echo $this->__('Fax') ?></label></td>
122
+ <td class="value">
123
+ <input type="text" id="<?php echo $this->getCode(); ?>_fax" name="<?php echo $this->getCode(); ?>[address][fax]"
124
+ class="input-text save-card-validate" data-validate="eway-validate-phone validate-length maximum-length-32" value="<?php echo $this->escapeHtml($this->getCard()->getAddress()->getData('Fax')); ?>" />
125
+ </td>
126
+ </tr>
127
+ </table>
128
+
129
+ <?php if(!Mage::helper('ewayrapid')->useIframeInBackend()): ?>
130
+ <h4><?php echo $this->__('Credit Card Information') ?></h4>
131
+ <table class="form-list" cellspacing="0" id="<?php echo $this->getCode(); ?>_ccInfo">
132
+ <tr>
133
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_cc_owner"><?php echo $this->__('Name on Card') ?> <span class="required">*</span></label></td>
134
+ <td class="value">
135
+ <input type="text" id="<?php echo $this->getCode(); ?>_cc_owner" name="<?php echo $this->getCode(); ?>[payment][cc_owner]" title="<?php echo $this->__('Card Holder Name') ?>"
136
+ class="input-text save-card-validate" data-validate="required-entry validate-length maximum-length-50" value="<?php echo $this->escapeHtml($this->getCard()->getOwner()); ?>" autocomplete="off" />
137
+ </td>
138
+ </tr>
139
+ <tr>
140
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_cc_number"><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label></td>
141
+ <td class="value">
142
+ <input type="text" id="<?php echo $this->getCode(); ?>_saved_cc_number" name="<?php echo $this->getCode(); ?>[payment][cc_number]"
143
+ title="<?php echo $this->__('Credit Card Number') ?>" class="input-text save-card-validate"
144
+ data-validate="validate-cc-number validate-cc-type-auto validate-cc-type"
145
+ <?php if($this->isEdit()): ?>value="<?php echo $this->escapeHtml($this->getCard()->getCard()); ?>" disabled="disabled" <?php endif;?> autocomplete="off" />
146
+ <input type="hidden" id="<?php echo $this->getCode(); ?>_saved_cc_type" name="<?php echo $this->getCode(); ?>[payment][cc_type]"
147
+ value="<?php echo $this->getCard()->getType() ?>"/>
148
+ </td>
149
+ </tr>
150
+ <tr>
151
+ <td class="label"><label for="<?php echo $this->getCode(); ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label></td>
152
+ <td class="value">
153
+ <select id="<?php echo $this->getCode(); ?>_expiration" name="<?php echo $this->getCode(); ?>[payment][cc_exp_month]" class="month save-card-validate"
154
+ data-validate="validate-cc-exp required-entry" style="width:150px">
155
+ <option value=""><?php echo $this->__('Month') ?></option>
156
+ <?php $_ccExpMonth = $this->getCard()->getExpMonth() ?>
157
+ <?php foreach(Mage::getSingleton('payment/config')->getMonths() as $k=>$v ): ?>
158
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
159
+ <?php endforeach ?>
160
+ </select>
161
+
162
+ <select id="<?php echo $this->getCode(); ?>_expiration_yr" name="<?php echo $this->getCode(); ?>[payment][cc_exp_year]" class="year" style="width:80px">
163
+ <option value=""><?php echo $this->__('Year') ?></option>
164
+ <?php $_ccExpYear = $this->getCard()->getExpYear() ?>
165
+ <?php foreach(Mage::getSingleton('payment/config')->getYears() as $k=>$v ): ?>
166
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
167
+ <?php endforeach ?>
168
+ </select>
169
+ </td>
170
+ </tr>
171
+ <!-- --><?php //if( Mage::helper('payment')->getMethodInstance( $this->getCode() )->getConfigData('useccv') ): ?>
172
+ <!-- <tr>-->
173
+ <!-- <td class="label"><label for="--><?php //echo $this->getCode(); ?><!--_cc_cid">--><?php //echo $this->__('Card Verification Number') ?><!-- <span class="required">*</span></label></td>-->
174
+ <!-- <td class="value">-->
175
+ <!-- <input type="text" title="--><?php //echo $this->__('Card Verification Number') ?><!--" class="input-text cvv" id="--><?php //echo $this->getCode(); ?><!--_cc_cid" name="--><?php //echo $this->getCode(); ?><!--[payment][cc_cid]" value="" style="width:50px" autocomplete="off" />-->
176
+ <!-- </td>-->
177
+ <!-- </tr>-->
178
+ <!-- --><?php //endif; ?>
179
+ </table>
180
+ <!-- --><?php //$requireCvv = Mage::helper('payment')->getMethodInstance( $this->getCode() )->getAdvancedConfigData('require_ccv'); ?>
181
+ <!-- --><?php //if( $this->isEdit() && Mage::helper('payment')->getMethodInstance( $this->getCode() )->getConfigData('useccv') && $requireCvv ): ?>
182
+ <!-- <table class="form-list" cellspacing="0" id="--><?php //echo $this->getCode(); ?><!--_ccInfoCcv">-->
183
+ <!-- <tr>-->
184
+ <!-- <td class="label"><label for="--><?php //echo $this->getCode(); ?><!--_saved_cc_cid">--><?php //echo $this->__('Card Verification Number') ?><!-- <span class="required">*</span></label></td>-->
185
+ <!-- <td class="value">-->
186
+ <!-- <input type="text" title="--><?php //echo $this->__('Card Verification Number') ?><!--" class="input-text cvv" id="--><?php //echo $this->getCode(); ?><!--_saved_cc_cid" name="--><?php //echo $this->getCode(); ?><!--[payment][saved_cc_cid]" value="" style="width:50px" autocomplete="off" />-->
187
+ <!-- </td>-->
188
+ <!-- </tr>-->
189
+ <!-- </table>-->
190
+ <!-- --><?php //endif; ?>
191
+ <?php endif; ?>
192
+ <table class="form-list" cellspacing="0">
193
+ <tr>
194
+ <td class="label"></td>
195
+ <td class="value">
196
+ <button class="button" type="button" onclick="<?php echo $this->getCode(); ?>.saveCard(<?php echo $this->getCard()->getToken() ? $this->getCard()->getToken() : ''?>);"><span><?php echo $this->__('Save') ?></span></button>
197
+ <a href="#" onclick="<?php echo $this->getCode(); ?>.editCard(0); return false;"><?php echo $this->__('Cancel'); ?></a>
198
+ </td>
199
+ </tr>
200
+ </table>
201
+ </div>
202
+ <script type="text/javascript">
203
+ //<![CDATA[
204
+ new RegionUpdater('<?php echo $this->getCode(); ?>_country', '<?php echo $this->getCode(); ?>_region', '<?php echo $this->getCode(); ?>_region_id', <?php echo Mage::helper('directory')->getRegionJson() ?>, undefined, '<?php echo $this->getCode(); ?>_postcode');
205
+
206
+ function <?php echo $this->getCode(); ?>_clearAddrValidation() {
207
+ $('<?php echo $this->getCode(); ?>_region_id').removeClassName('required-entry').removeClassName('validate-select');
208
+ $('<?php echo $this->getCode(); ?>_country').removeClassName('required-entry').removeClassName('validate-select');
209
+ $('<?php echo $this->getCode(); ?>_region').removeClassName('required-entry');
210
+ $('<?php echo $this->getCode(); ?>_postcode').removeClassName('required-entry');
211
+ }
212
+
213
+ /* Prevent the region from holding up submit... */
214
+ document.observe("dom:loaded", function() {
215
+ <?php echo $this->getCode(); ?>_clearAddrValidation();
216
+ });
217
+ //]]>
218
+ </script>
app/design/adminhtml/default/default/template/ewayrapid/customer/method.phtml CHANGED
@@ -1,175 +1,175 @@
1
- <?php if( !$this->isAjax() ): ?>
2
- <table id="tokenbase-edit-<?php echo $this->getCode(); ?>" class="form-edit" cellspacing="0">
3
- <?php endif; ?>
4
- <tr>
5
- <td id="<?php echo $this->getCode(); ?>-cards" class="address-list">
6
- <?php echo $this->getChildHtml('admin.customer.ewayrapid.cards'); ?>
7
- </td>
8
- <td id="<?php echo $this->getCode(); ?>-form">
9
- <?php echo $this->getChildHtml('admin.customer.ewayrapid.form'); ?>
10
- </td>
11
- </tr>
12
- <?php if( !$this->isAjax() ): ?>
13
- </table>
14
- <?php endif; ?>
15
-
16
- <?php if( !$this->isAjax() ): ?>
17
- <script type="text/javascript">
18
- var encryptKey = '<?php echo Mage::getSingleton('ewayrapid/config')->getEncryptionKey() ?>';
19
- var accessCode = '';
20
- var saveTokenResult = '';
21
- //<![CDATA[
22
- var <?php echo $this->getCode(); ?> = {
23
- deleteCard: function( id ) {
24
- if( confirm("<?php echo $this->__('Are you sure you want to delete this?'); ?>") ) {
25
- Element.show('loading-mask');
26
- new Ajax.Request("<?php echo $this->getUrl('*/ewayrapid_savedcard/delete', array('customer_id' => $this->getCustomer()->getId())); ?>", {
27
- method: 'post',
28
- parameters: "token_id="+id,
29
- evalScripts: true,
30
- onComplete: function(data) {
31
- Element.hide('loading-mask');
32
-
33
- try {
34
- var json = data.responseText.evalJSON();
35
- } catch(e) {}
36
-
37
- if( typeof json != 'undefined' && json.success == false ) {
38
- alert( json.message );
39
- }
40
- else {
41
- $('token-'+id).hide();
42
- <?php echo $this->getCode(); ?>.editCard(0);
43
- }
44
- }
45
- });
46
- }
47
- },
48
-
49
- editCard: function( id ) {
50
- Element.show('loading-mask');
51
- new Ajax.Request("<?php echo $this->getUrl('*/ewayrapid_savedcard/load', array('customer_id' => $this->getCustomer()->getId())); ?>", {
52
- method: 'post',
53
- parameters: "token_id="+id,
54
- evalScripts: true,
55
- onComplete: function(data) {
56
- Element.hide('loading-mask');
57
-
58
- try {
59
- var json = data.responseText.evalJSON();
60
- } catch(e) {}
61
-
62
- if( typeof json != 'undefined' && json.success == false ) {
63
- alert( json.message );
64
- }
65
- else {
66
- $('<?php echo $this->getCode(); ?>-form').update( data.responseText );
67
- }
68
- }
69
- });
70
- },
71
-
72
- saveCard: function(customertokenid) {
73
- var form = $('edit_form');
74
- form.writeAttribute('data-eway-encrypt-key', encryptKey);
75
- if(!validateForm()){
76
- return;
77
- }
78
- var ewayForm = new EwayForm();
79
- var submitForm = ewayForm.encryptForm(form, true);
80
-
81
- Element.show('loading-mask');
82
- var url = '';
83
- <?php if(Mage::helper('ewayrapid')->useIframeInBackend()): ?>
84
- url = '<?php echo $this->getUrl('*/ewayrapid_savedcard/getAccessCode', array('customer_id' => $this->getCustomer()->getId())); ?>';
85
- <?php else: ?>
86
- url = '<?php echo $this->getUrl('*/ewayrapid_savedcard/save', array('customer_id' => $this->getCustomer()->getId())); ?>'
87
- <?php endif; ?>
88
-
89
- if(customertokenid){
90
- url += 'TokenCustomerID/' + customertokenid;
91
- }
92
- new Ajax.Request(url, {
93
- method: 'post',
94
- parameters: Form.serialize(submitForm, true),
95
- evalScripts: true,
96
- onComplete: function(data) {
97
- Element.hide('loading-mask');
98
- try {
99
- var json = data.responseText.evalJSON();
100
- } catch(e) {}
101
-
102
- if( typeof json != 'undefined' && json.success == false ) {
103
- alert( json.message );
104
- }
105
- else {
106
- <?php if(Mage::helper('ewayrapid')->useIframeInBackend()): ?>
107
- var eWAYConfig = {
108
- sharedPaymentUrl: json.SharedPaymentUrl
109
- };
110
- ewayReturnUrl = '<?php echo $this->getUrl('*/ewayrapid_savedcard/savetoken', array('customer_id' => $this->getCustomer()->getId())); ?>';
111
- saveTokenResult = json;
112
- Element.show('loading-mask');
113
- eCrypt.showModalPayment(eWAYConfig, saveTokenCallBack);
114
- <?php else: ?>
115
- $('<?php echo $this->getCode(); ?>-cards').update(data.responseText);
116
- <?php echo $this->getCode(); ?>.editCard(0);
117
- <?php endif; ?>
118
- }
119
- }
120
- });
121
- }
122
- }
123
-
124
- function saveTokenCallBack (result, transactionID, errors) {
125
- if (result == "Complete") {
126
- var reqParams = {
127
- // 'ccType': '',
128
- // 'expYear': saveTokenResult.Customer.CardExpiryYear,
129
- 'token_id': $('token_id').value,
130
- // 'startMonth': saveTokenResult.Customer.CardStartMonth,
131
- // 'startYear': saveTokenResult.Customer.CardStartYear,
132
- // 'issueNumber': saveTokenResult.Customer.CardIssueNumber,
133
- 'AccessCode': saveTokenResult.AccessCode,
134
- 'street1': saveTokenResult.street1,
135
- 'street2': saveTokenResult.street2
136
- };
137
- new Ajax.Request(ewayReturnUrl, {
138
- method: 'post',
139
- parameters: reqParams,
140
- evalScripts: true,
141
- onComplete: function(data) {
142
- Element.hide('loading-mask');
143
- try {
144
- var json = data.responseText.evalJSON();
145
- } catch(e) {}
146
-
147
- if( typeof json != 'undefined' && json.success == false ) {
148
- alert( json.message );
149
- }
150
- else {
151
- $('<?php echo $this->getCode(); ?>-cards').update( data.responseText );
152
- <?php echo $this->getCode(); ?>.editCard(0);
153
- }
154
- }
155
- });
156
- } else if (result == "Error") {
157
- alert("There was a problem completing the payment: " + errors);
158
- Element.hide('loading-mask');
159
- } else{
160
- Element.hide('loading-mask');
161
- }
162
- }
163
-
164
- function validateForm(){
165
- $$('.save-card-validate').each(function(ele){
166
- var eleValidate = ele.getAttribute('data-validate');
167
- ele.addClassName(eleValidate);
168
- });
169
- $('ewayrapid_region_id') && $('ewayrapid_region_id').addClassName('required-entry').addClassName('validate-select');
170
- var validator = new Validation('edit_form');
171
- return validator.validate();
172
- }
173
- //]]!>
174
- </script>
175
- <?php endif; ?>
1
+ <?php if( !$this->isAjax() ): ?>
2
+ <table id="tokenbase-edit-<?php echo $this->getCode(); ?>" class="form-edit" cellspacing="0">
3
+ <?php endif; ?>
4
+ <tr>
5
+ <td id="<?php echo $this->getCode(); ?>-cards" class="address-list">
6
+ <?php echo $this->getChildHtml('admin.customer.ewayrapid.cards'); ?>
7
+ </td>
8
+ <td id="<?php echo $this->getCode(); ?>-form">
9
+ <?php echo $this->getChildHtml('admin.customer.ewayrapid.form'); ?>
10
+ </td>
11
+ </tr>
12
+ <?php if( !$this->isAjax() ): ?>
13
+ </table>
14
+ <?php endif; ?>
15
+
16
+ <?php if( !$this->isAjax() ): ?>
17
+ <script type="text/javascript">
18
+ var encryptKey = '<?php echo Mage::getSingleton('ewayrapid/config')->getEncryptionKey() ?>';
19
+ var accessCode = '';
20
+ var saveTokenResult = '';
21
+ //<![CDATA[
22
+ var <?php echo $this->getCode(); ?> = {
23
+ deleteCard: function( id ) {
24
+ if( confirm("<?php echo $this->__('Are you sure you want to delete this?'); ?>") ) {
25
+ Element.show('loading-mask');
26
+ new Ajax.Request("<?php echo $this->getUrl('*/ewayrapid_savedcard/delete', array('customer_id' => $this->getCustomer()->getId())); ?>", {
27
+ method: 'post',
28
+ parameters: "token_id="+id,
29
+ evalScripts: true,
30
+ onComplete: function(data) {
31
+ Element.hide('loading-mask');
32
+
33
+ try {
34
+ var json = data.responseText.evalJSON();
35
+ } catch(e) {}
36
+
37
+ if( typeof json != 'undefined' && json.success == false ) {
38
+ alert( json.message );
39
+ }
40
+ else {
41
+ $('token-'+id).hide();
42
+ <?php echo $this->getCode(); ?>.editCard(0);
43
+ }
44
+ }
45
+ });
46
+ }
47
+ },
48
+
49
+ editCard: function( id ) {
50
+ Element.show('loading-mask');
51
+ new Ajax.Request("<?php echo $this->getUrl('*/ewayrapid_savedcard/load', array('customer_id' => $this->getCustomer()->getId())); ?>", {
52
+ method: 'post',
53
+ parameters: "token_id="+id,
54
+ evalScripts: true,
55
+ onComplete: function(data) {
56
+ Element.hide('loading-mask');
57
+
58
+ try {
59
+ var json = data.responseText.evalJSON();
60
+ } catch(e) {}
61
+
62
+ if( typeof json != 'undefined' && json.success == false ) {
63
+ alert( json.message );
64
+ }
65
+ else {
66
+ $('<?php echo $this->getCode(); ?>-form').update( data.responseText );
67
+ }
68
+ }
69
+ });
70
+ },
71
+
72
+ saveCard: function(customertokenid) {
73
+ var form = $('edit_form');
74
+ form.writeAttribute('data-eway-encrypt-key', encryptKey);
75
+ if(!validateForm()){
76
+ return;
77
+ }
78
+ var ewayForm = new EwayForm();
79
+ var submitForm = ewayForm.encryptForm(form, true);
80
+
81
+ Element.show('loading-mask');
82
+ var url = '';
83
+ <?php if(Mage::helper('ewayrapid')->useIframeInBackend()): ?>
84
+ url = '<?php echo $this->getUrl('*/ewayrapid_savedcard/getAccessCode', array('customer_id' => $this->getCustomer()->getId())); ?>';
85
+ <?php else: ?>
86
+ url = '<?php echo $this->getUrl('*/ewayrapid_savedcard/save', array('customer_id' => $this->getCustomer()->getId())); ?>'
87
+ <?php endif; ?>
88
+
89
+ if(customertokenid){
90
+ url += 'TokenCustomerID/' + customertokenid;
91
+ }
92
+ new Ajax.Request(url, {
93
+ method: 'post',
94
+ parameters: Form.serialize(submitForm, true),
95
+ evalScripts: true,
96
+ onComplete: function(data) {
97
+ Element.hide('loading-mask');
98
+ try {
99
+ var json = data.responseText.evalJSON();
100
+ } catch(e) {}
101
+
102
+ if( typeof json != 'undefined' && json.success == false ) {
103
+ alert( json.message );
104
+ }
105
+ else {
106
+ <?php if(Mage::helper('ewayrapid')->useIframeInBackend()): ?>
107
+ var eWAYConfig = {
108
+ sharedPaymentUrl: json.SharedPaymentUrl
109
+ };
110
+ ewayReturnUrl = '<?php echo $this->getUrl('*/ewayrapid_savedcard/savetoken', array('customer_id' => $this->getCustomer()->getId())); ?>';
111
+ saveTokenResult = json;
112
+ Element.show('loading-mask');
113
+ eCrypt.showModalPayment(eWAYConfig, saveTokenCallBack);
114
+ <?php else: ?>
115
+ $('<?php echo $this->getCode(); ?>-cards').update(data.responseText);
116
+ <?php echo $this->getCode(); ?>.editCard(0);
117
+ <?php endif; ?>
118
+ }
119
+ }
120
+ });
121
+ }
122
+ }
123
+
124
+ function saveTokenCallBack (result, transactionID, errors) {
125
+ if (result == "Complete") {
126
+ var reqParams = {
127
+ // 'ccType': '',
128
+ // 'expYear': saveTokenResult.Customer.CardExpiryYear,
129
+ 'token_id': $('token_id').value,
130
+ // 'startMonth': saveTokenResult.Customer.CardStartMonth,
131
+ // 'startYear': saveTokenResult.Customer.CardStartYear,
132
+ // 'issueNumber': saveTokenResult.Customer.CardIssueNumber,
133
+ 'AccessCode': saveTokenResult.AccessCode,
134
+ 'street1': saveTokenResult.street1,
135
+ 'street2': saveTokenResult.street2
136
+ };
137
+ new Ajax.Request(ewayReturnUrl, {
138
+ method: 'post',
139
+ parameters: reqParams,
140
+ evalScripts: true,
141
+ onComplete: function(data) {
142
+ Element.hide('loading-mask');
143
+ try {
144
+ var json = data.responseText.evalJSON();
145
+ } catch(e) {}
146
+
147
+ if( typeof json != 'undefined' && json.success == false ) {
148
+ alert( json.message );
149
+ }
150
+ else {
151
+ $('<?php echo $this->getCode(); ?>-cards').update( data.responseText );
152
+ <?php echo $this->getCode(); ?>.editCard(0);
153
+ }
154
+ }
155
+ });
156
+ } else if (result == "Error") {
157
+ alert("There was a problem completing the payment: " + errors);
158
+ Element.hide('loading-mask');
159
+ } else{
160
+ Element.hide('loading-mask');
161
+ }
162
+ }
163
+
164
+ function validateForm(){
165
+ $$('.save-card-validate').each(function(ele){
166
+ var eleValidate = ele.getAttribute('data-validate');
167
+ ele.addClassName(eleValidate);
168
+ });
169
+ $('ewayrapid_region_id') && $('ewayrapid_region_id').addClassName('required-entry').addClassName('validate-select');
170
+ var validator = new Validation('edit_form');
171
+ return validator.validate();
172
+ }
173
+ //]]!>
174
+ </script>
175
+ <?php endif; ?>
app/design/adminhtml/default/default/template/ewayrapid/form/direct_ewayone.phtml CHANGED
@@ -1,181 +1,182 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package base_default
23
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
- */
25
- ?>
26
- <?php
27
- $_code = $this->getMethodCode();
28
- ?>
29
-
30
- <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display: none">
31
- <?php if($this->checkSaveCardAvailable()): ?>
32
- <?php
33
- $_tokens = $this->getTokenList();
34
- $_defaultToken = isset($_tokens['default_token']) ? $_tokens['default_token'] : false;
35
- ?>
36
- <li <?php echo count($_tokens['tokens']) <= 1 ? 'style="display:none;"' : '' ?>>
37
- <div class="input-box">
38
- <div class="v-fix">
39
- <select id="ewayrapid_ewayone_token" name="payment[saved_token]" class="ewayrapid_ewayone_token">
40
- <?php foreach($_tokens['tokens'] as $_key => $_token):
41
- if ($_key == Eway_Rapid31_Model_Config::TOKEN_NEW || $this->checkCardName($_token) == Eway_Rapid31_Model_Config::CREDITCARD_METHOD): ?>
42
- <?php /* @var Eway_Rapid31_Model_Customer_Token $_token */ ?>
43
- <option value="<?php echo $_key ?>" <?php if($_key == $_defaultToken): ?>selected="selected"<?php endif; ?>>
44
- <?php echo $_token->getCard() ?>
45
- </option>
46
- <?php endif; ?>
47
- <?php endforeach; ?>
48
- </select>
49
- </div>
50
- <?php if(Mage::getSingleton('ewayrapid/config')->canEditToken() && count($_tokens['tokens']) > 1): ?>
51
- <div class="v-fix">
52
- <a id="ewayrapid_ewayone_edit" class="ewayrapid_ewayone_edit" href="javascript:void(0);"><?php echo $this->__('Edit') ?></a>
53
- </div>
54
- <?php endif; ?>
55
- </div>
56
- </li>
57
- <?php endif; ?>
58
- <li class="saved_token_fields">
59
- <label for="<?php echo $_code ?>_cc_owner"><em>*</em><?php echo $this->__('Name on Card') ?></label>
60
- <div class="input-box">
61
- <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>" />
62
- </div>
63
- </li>
64
- <li class="saved_token_fields">
65
- <label for="<?php echo $_code ?>_cc_number"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
66
- <div class="input-box help-disabled-cc">
67
- <input type="text" id="<?php echo $_code ?>_cc_number" data-eway-encrypt-name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type-auto" value="" pattern="\d*"/>
68
- <input type="hidden" id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" />
69
- <a class="card-number-help" href="#"><?php echo $this->__('Help') ?></a>
70
- <div class="tool-tip" id="cc-help-tool-tip" style="display:none;">
71
- <div class="btn-close"><a href="#" id="cc-help-tool-tip-close" title="<?php echo $this->__('Close') ?>"><?php echo $this->__('Close') ?></a></div>
72
- <div class="tool-tip-content">To use a new credit card number, please add another card</div>
73
- </div>
74
- </div>
75
- </li>
76
- <li class="saved_token_fields">
77
- <label for="<?php echo $_code ?>_expiration"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
78
- <div class="input-box">
79
- <div class="v-fix">
80
- <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]" class="month validate-cc-exp required-entry">
81
- <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
82
- <?php foreach ($this->getCcMonths() as $k=>$v): ?>
83
- <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
84
- <?php endforeach ?>
85
- </select>
86
- </div>
87
- <div class="v-fix">
88
- <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
89
- <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]" class="year required-entry">
90
- <?php foreach ($this->getCcYears() as $k=>$v): ?>
91
- <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
92
- <?php endforeach ?>
93
- </select>
94
- </div>
95
- </div>
96
- </li>
97
- <?php echo $this->getChildHtml() ?>
98
- <?php if($this->hasVerification()): ?>
99
- <li id="<?php echo $_code ?>_cc_type_cvv_div">
100
- <label for="<?php echo $_code ?>_cc_cid"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
101
- <div class="input-box">
102
- <div class="v-fix">
103
- <input type="text" title="<?php echo $this->__('Card Verification Number') ?>" class="input-text cvv required-entry validate-cc-cvn" id="<?php echo $_code ?>_cc_cid" data-eway-encrypt-name="payment[cc_cid]" value="" pattern="\d*"/>
104
- </div>
105
- <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
106
- </div>
107
- </li>
108
- <?php if ($this->getIsRecurring()) { ?>
109
- <li>
110
- <p>I authorize <?php echo Mage::app()->getStore()->getName(); ?> to charge the available balance
111
- in my credit card for the future payments of this order. To make a change, I can go to
112
- <a href="<?php echo Mage::getUrl('checkout/cart'); ?>">Cart</a>
113
- </p>
114
- <input type="checkbox" name="recurring-agree" class="recurring-agree required-entry"/><label class="lable-for-recurring" for="">Agree</label>
115
- </li>
116
- <?php } ?>
117
- <?php endif; ?>
118
- <?php if($this->checkSaveCardAvailable() && $this->getSaveCard()): ?>
119
- <li id="eway_save_card" class="saved_token_fields">
120
- <div class="v-fix">
121
- <input type="checkbox" title="<?php echo $this->getSaveText() ?>" id="<?php echo $_code ?>_cc_save_card"
122
- <?php echo $this->getSaveDefaultCheck() ? 'checked' : '' ?> name="payment[save_card]" value="1" pattern="\d*"/>
123
- <label for="<?php echo $_code ?>_cc_save_card" ><?php echo $this->getSaveText() ?></label>
124
- </div>
125
- </li>
126
- <?php endif; ?>
127
- </ul>
128
- <?php if(count($_tokens['tokens']) > 1): ?>
129
- <script type="text/javascript">
130
- var ewayPaymentToken = new EwayPaymentToken(
131
- <?php echo $_tokens['tokens_json'] ?>,
132
- <?php echo count($_tokens['tokens']) ?>,
133
- false,
134
- '<?php echo $this->__('Edit') ?>',
135
- '<?php echo $this->__('Cancel edit') ?>'
136
- );
137
-
138
- $$('.help-disabled-cc a').each(function(element){
139
- Event.observe(element, 'click', toggleToolTipCc);
140
- });
141
-
142
- function toggleToolTipCc(event){
143
- if($('cc-help-tool-tip')){
144
- $('cc-help-tool-tip').toggle();
145
- }
146
- Event.stop(event);
147
- }
148
- if($('cc-help-tool-tip-close')){
149
- Event.observe($('cc-help-tool-tip-close'), 'click', toggleToolTipCc);
150
- }
151
-
152
- if(typeof AdminOrder.prototype.setPaymentMethodBackup == "undefined") {
153
- AdminOrder.prototype.setPaymentMethodBackup = AdminOrder.prototype.setPaymentMethod;
154
- AdminOrder.prototype.setPaymentMethod = function(method) {
155
- AdminOrder.prototype.setPaymentMethodBackup(method);
156
- if(EwayPayment.isEwayRapidMethod(method)) {
157
- ewayPaymentToken.onSavedTokenChanged();
158
- }
159
- }
160
- }
161
-
162
- </script>
163
- <?php endif; ?>
164
- <script type="text/javascript">
165
- $('p_method_ewayrapid_ewayone').observe('click', function () {
166
- $('p_method_ewayrapid_ewayone').setAttribute('checked', 'true');
167
- $('p_method_ewayrapid_notsaved') && $('p_method_ewayrapid_notsaved').removeAttribute('checked');
168
-
169
- $$('#payment_form_ewayrapid_ewayone input[name*=payment]').each(function(inp) {
170
- inp.removeAttribute('disabled');
171
- });
172
-
173
- $$('#payment_form_ewayrapid_ewayone select[name*=payment]').each(function(inp) {
174
- inp.removeAttribute('disabled');
175
- });
176
-
177
- $$('#payment_form_ewayrapid_ewayone input[data-eway-encrypt-name*=payment]').each(function(inp) {
178
- inp.removeAttribute('disabled');
179
- });
180
- });
 
181
  </script>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ $_code = $this->getMethodCode();
29
+ ?>
30
+
31
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display: none">
32
+ <?php if($this->checkSaveCardAvailable()): ?>
33
+ <?php
34
+ $_tokens = $this->getTokenList();
35
+ $_defaultToken = isset($_tokens['default_token']) ? $_tokens['default_token'] : false;
36
+ ?>
37
+ <li <?php echo count($_tokens['tokens']) <= 1 ? 'style="display:none;"' : '' ?>>
38
+ <div class="input-box">
39
+ <div class="v-fix">
40
+ <select id="ewayrapid_ewayone_token" name="payment[saved_token]" class="ewayrapid_ewayone_token">
41
+ <?php foreach($_tokens['tokens'] as $_key => $_token):
42
+ if ($_key == Eway_Rapid31_Model_Config::TOKEN_NEW || $this->checkCardName($_token) == Eway_Rapid31_Model_Config::CREDITCARD_METHOD): ?>
43
+ <?php /* @var Eway_Rapid31_Model_Customer_Token $_token */ ?>
44
+ <option value="<?php echo $_key ?>" <?php if($_key == $_defaultToken): ?>selected="selected"<?php endif; ?>>
45
+ <?php echo $_token->getCard() ?>
46
+ </option>
47
+ <?php endif; ?>
48
+ <?php endforeach; ?>
49
+ </select>
50
+ </div>
51
+ <?php if(Mage::getSingleton('ewayrapid/config')->canEditToken() && count($_tokens['tokens']) > 1): ?>
52
+ <div class="v-fix">
53
+ <a id="ewayrapid_ewayone_edit" class="ewayrapid_ewayone_edit" href="javascript:void(0);"><?php echo $this->__('Edit') ?></a>
54
+ </div>
55
+ <?php endif; ?>
56
+ </div>
57
+ </li>
58
+ <?php endif; ?>
59
+ <li class="saved_token_fields">
60
+ <label for="<?php echo $_code ?>_cc_owner"><em>*</em><?php echo $this->__('Name on Card') ?></label>
61
+ <div class="input-box">
62
+ <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>" />
63
+ </div>
64
+ </li>
65
+ <li class="saved_token_fields">
66
+ <label for="<?php echo $_code ?>_cc_number"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
67
+ <div class="input-box help-disabled-cc">
68
+ <input type="text" id="<?php echo $_code ?>_cc_number" data-eway-encrypt-name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type-auto" value="" pattern="\d*"/>
69
+ <input type="hidden" id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" />
70
+ <a class="card-number-help" href="#"><?php echo $this->__('Help') ?></a>
71
+ <div class="tool-tip" id="cc-help-tool-tip" style="display:none;">
72
+ <div class="btn-close"><a href="#" id="cc-help-tool-tip-close" title="<?php echo $this->__('Close') ?>"><?php echo $this->__('Close') ?></a></div>
73
+ <div class="tool-tip-content">To use a new credit card number, please add another card</div>
74
+ </div>
75
+ </div>
76
+ </li>
77
+ <li class="saved_token_fields">
78
+ <label for="<?php echo $_code ?>_expiration"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
79
+ <div class="input-box">
80
+ <div class="v-fix">
81
+ <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]" class="month validate-cc-exp required-entry">
82
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
83
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
84
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
85
+ <?php endforeach ?>
86
+ </select>
87
+ </div>
88
+ <div class="v-fix">
89
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
90
+ <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]" class="year required-entry">
91
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
92
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
93
+ <?php endforeach ?>
94
+ </select>
95
+ </div>
96
+ </div>
97
+ </li>
98
+ <?php echo $this->getChildHtml() ?>
99
+ <?php if($this->hasVerification()): ?>
100
+ <li id="<?php echo $_code ?>_cc_type_cvv_div">
101
+ <label for="<?php echo $_code ?>_cc_cid"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
102
+ <div class="input-box">
103
+ <div class="v-fix">
104
+ <input type="text" title="<?php echo $this->__('Card Verification Number') ?>" class="input-text cvv required-entry validate-cc-cvn" id="<?php echo $_code ?>_cc_cid" data-eway-encrypt-name="payment[cc_cid]" value="" pattern="\d*"/>
105
+ </div>
106
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
107
+ </div>
108
+ </li>
109
+ <?php if ($this->getIsRecurring()) { ?>
110
+ <li>
111
+ <p>I authorize <?php echo Mage::app()->getStore()->getName(); ?> to charge the available balance
112
+ in my credit card for the future payments of this order. To make a change, I can go to
113
+ <a href="<?php echo Mage::getUrl('checkout/cart'); ?>">Cart</a>
114
+ </p>
115
+ <input type="checkbox" name="recurring-agree" class="recurring-agree required-entry"/><label class="lable-for-recurring" for="">Agree</label>
116
+ </li>
117
+ <?php } ?>
118
+ <?php endif; ?>
119
+ <?php if($this->checkSaveCardAvailable() && $this->getSaveCard()): ?>
120
+ <li id="eway_save_card" class="saved_token_fields">
121
+ <div class="v-fix">
122
+ <input type="checkbox" title="<?php echo $this->getSaveText() ?>" id="<?php echo $_code ?>_cc_save_card"
123
+ <?php echo $this->getSaveDefaultCheck() ? 'checked' : '' ?> name="payment[save_card]" value="1" pattern="\d*"/>
124
+ <label for="<?php echo $_code ?>_cc_save_card" ><?php echo $this->getSaveText() ?></label>
125
+ </div>
126
+ </li>
127
+ <?php endif; ?>
128
+ </ul>
129
+ <?php if(count($_tokens['tokens']) > 1): ?>
130
+ <script type="text/javascript">
131
+ var ewayPaymentToken = new EwayPaymentToken(
132
+ <?php echo $_tokens['tokens_json'] ?>,
133
+ <?php echo count($_tokens['tokens']) ?>,
134
+ false,
135
+ '<?php echo $this->__('Edit') ?>',
136
+ '<?php echo $this->__('Cancel edit') ?>'
137
+ );
138
+
139
+ $$('.help-disabled-cc a').each(function(element){
140
+ Event.observe(element, 'click', toggleToolTipCc);
141
+ });
142
+
143
+ function toggleToolTipCc(event){
144
+ if($('cc-help-tool-tip')){
145
+ $('cc-help-tool-tip').toggle();
146
+ }
147
+ Event.stop(event);
148
+ }
149
+ if($('cc-help-tool-tip-close')){
150
+ Event.observe($('cc-help-tool-tip-close'), 'click', toggleToolTipCc);
151
+ }
152
+
153
+ if(typeof AdminOrder.prototype.setPaymentMethodBackup == "undefined") {
154
+ AdminOrder.prototype.setPaymentMethodBackup = AdminOrder.prototype.setPaymentMethod;
155
+ AdminOrder.prototype.setPaymentMethod = function(method) {
156
+ AdminOrder.prototype.setPaymentMethodBackup(method);
157
+ if(EwayPayment.isEwayRapidMethod(method)) {
158
+ ewayPaymentToken.onSavedTokenChanged();
159
+ }
160
+ }
161
+ }
162
+
163
+ </script>
164
+ <?php endif; ?>
165
+ <script type="text/javascript">
166
+ $('p_method_ewayrapid_ewayone').observe('click', function () {
167
+ $('p_method_ewayrapid_ewayone').setAttribute('checked', 'true');
168
+ $('p_method_ewayrapid_notsaved') && $('p_method_ewayrapid_notsaved').removeAttribute('checked');
169
+
170
+ $$('#payment_form_ewayrapid_ewayone input[name*=payment]').each(function(inp) {
171
+ inp.removeAttribute('disabled');
172
+ });
173
+
174
+ $$('#payment_form_ewayrapid_ewayone select[name*=payment]').each(function(inp) {
175
+ inp.removeAttribute('disabled');
176
+ });
177
+
178
+ $$('#payment_form_ewayrapid_ewayone input[data-eway-encrypt-name*=payment]').each(function(inp) {
179
+ inp.removeAttribute('disabled');
180
+ });
181
+ });
182
  </script>
app/design/adminhtml/default/default/template/ewayrapid/form/direct_notsaved.phtml CHANGED
@@ -1,73 +1,74 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package base_default
23
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
- */
25
- ?>
26
- <?php $_code=$this->getMethodCode() ?>
27
- <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
28
- <li>
29
- <div class="input-box">
30
- <label for="<?php echo $_code ?>_cc_owner"><?php echo $this->__('Name on Card') ?> <span class="required">*</span></label>
31
- <br/>
32
- <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>" />
33
- </div>
34
- </li>
35
- <li>
36
- <label for="<?php echo $_code ?>_cc_number"><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label>
37
- <br/>
38
- <div class="input-box">
39
- <input type="text" id="<?php echo $_code ?>_cc_number" data-eway-encrypt-name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type-auto" value="" />
40
- <input type="hidden" id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" />
41
- </div>
42
- </li>
43
- <li id="<?php echo $_code ?>_cc_type_exp_div">
44
- <div class="input-box">
45
- <label for="<?php echo $_code ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label>
46
- <br/>
47
- <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]" class="month validate-cc-exp required-entry">
48
- <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
49
- <?php foreach ($this->getCcMonths() as $k=>$v): ?>
50
- <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
51
- <?php endforeach ?>
52
- </select>
53
- <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
54
- <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]" class="year required-entry">
55
- <?php foreach ($this->getCcYears() as $k=>$v): ?>
56
- <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
57
- <?php endforeach ?>
58
- </select>
59
- </div>
60
- </li>
61
- <?php echo $this->getChildHtml() ?>
62
- <?php if($this->hasVerification()): ?>
63
- <li id="<?php echo $_code ?>_cc_type_cvv_div">
64
- <label for="<?php echo $_code ?>_cc_cid" class="required"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
65
- <div class="input-box">
66
- <div class="v-fix">
67
- <input type="text" title="<?php echo $this->__('Card Verification Number') ?>" class="input-text cvv required-entry validate-cc-cvn" id="<?php echo $_code ?>_cc_cid" data-eway-encrypt-name="payment[cc_cid]" value="" pattern="\d*"/>
68
- </div>
69
- <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
70
- </div>
71
- </li>
72
- <?php endif; ?>
 
73
  </ul>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php $_code=$this->getMethodCode() ?>
28
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
29
+ <li>
30
+ <div class="input-box">
31
+ <label for="<?php echo $_code ?>_cc_owner"><?php echo $this->__('Name on Card') ?> <span class="required">*</span></label>
32
+ <br/>
33
+ <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>" />
34
+ </div>
35
+ </li>
36
+ <li>
37
+ <label for="<?php echo $_code ?>_cc_number"><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label>
38
+ <br/>
39
+ <div class="input-box">
40
+ <input type="text" id="<?php echo $_code ?>_cc_number" data-eway-encrypt-name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type-auto" value="" />
41
+ <input type="hidden" id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" />
42
+ </div>
43
+ </li>
44
+ <li id="<?php echo $_code ?>_cc_type_exp_div">
45
+ <div class="input-box">
46
+ <label for="<?php echo $_code ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label>
47
+ <br/>
48
+ <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]" class="month validate-cc-exp required-entry">
49
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
50
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
51
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
52
+ <?php endforeach ?>
53
+ </select>
54
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
55
+ <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]" class="year required-entry">
56
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
57
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
58
+ <?php endforeach ?>
59
+ </select>
60
+ </div>
61
+ </li>
62
+ <?php echo $this->getChildHtml() ?>
63
+ <?php if($this->hasVerification()): ?>
64
+ <li id="<?php echo $_code ?>_cc_type_cvv_div">
65
+ <label for="<?php echo $_code ?>_cc_cid" class="required"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
66
+ <div class="input-box">
67
+ <div class="v-fix">
68
+ <input type="text" title="<?php echo $this->__('Card Verification Number') ?>" class="input-text cvv required-entry validate-cc-cvn" id="<?php echo $_code ?>_cc_cid" data-eway-encrypt-name="payment[cc_cid]" value="" pattern="\d*"/>
69
+ </div>
70
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
71
+ </div>
72
+ </li>
73
+ <?php endif; ?>
74
  </ul>
app/design/adminhtml/default/default/template/ewayrapid/form/direct_saved.phtml CHANGED
@@ -1,109 +1,110 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package base_default
23
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
- */
25
- ?>
26
- <?php $_code=$this->getMethodCode() ?>
27
- <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display: none">
28
- <li>
29
- <div class="input-box">
30
- <div class="v-fix" style="float: left; padding-right: 10px;">
31
- <select id="ewayrapid_saved_token" name="payment[saved_token]" class="ewayrapid_saved_token">
32
- <?php
33
- $_tokens = $this->getTokenList();
34
- $_defaultToken = isset($_tokens['default_token']) ? $_tokens['default_token'] : false;
35
- ?>
36
- <?php foreach($_tokens['tokens'] as $_key => $_token):
37
- if ($_key == Eway_Rapid31_Model_Config::TOKEN_NEW || $this->checkCardName($_token) == Eway_Rapid31_Model_Config::CREDITCARD_METHOD): ?>
38
- <?php /* @var Eway_Rapid31_Model_Customer_Token $_token */ ?>
39
- <option value="<?php echo $_key ?>" <?php if($_key == $_defaultToken): ?>selected="selected"<?php endif; ?>>
40
- <?php echo $_token->getCard() ?>
41
- </option>
42
- <?php endif; ?>
43
- <?php endforeach; ?>
44
- </select>
45
- </div>
46
- <?php if(count($_tokens['tokens']) > 1): ?>
47
- <div class="v-fix">
48
- <a id="ewayrapid_saved_edit" class="ewayrapid_saved_edit" href="javascript:void(0);"><?php echo $this->__('Edit') ?></a>
49
- </div>
50
- <?php endif; ?>
51
- </div>
52
- <div style="clear: both;"></div>
53
- </li>
54
-
55
- <li class="saved_token_fields" style="display: none">
56
- <div class="input-box">
57
- <label for="<?php echo $_code ?>_cc_owner"><?php echo $this->__('Name on Card') ?> <span class="required">*</span></label>
58
- <br/>
59
- <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>" />
60
- </div>
61
- </li>
62
- <li class="saved_token_fields" style="display: none">
63
- <label for="<?php echo $_code ?>_cc_number"><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label>
64
- <br/>
65
- <div class="input-box">
66
- <input type="text" id="<?php echo $_code ?>_cc_number" data-eway-encrypt-name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type-auto" value="" />
67
- <input type="hidden" id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" />
68
- </div>
69
- </li>
70
- <li id="<?php echo $_code ?>_cc_type_exp_div" class="saved_token_fields" style="display: none">
71
- <div class="input-box">
72
- <label for="<?php echo $_code ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label>
73
- <br/>
74
- <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]" class="month validate-cc-exp required-entry">
75
- <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
76
- <?php foreach ($this->getCcMonths() as $k=>$v): ?>
77
- <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
78
- <?php endforeach ?>
79
- </select>
80
- <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
81
- <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]" class="year required-entry">
82
- <?php foreach ($this->getCcYears() as $k=>$v): ?>
83
- <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
84
- <?php endforeach ?>
85
- </select>
86
- </div>
87
- </li>
88
- <?php echo $this->getChildHtml() ?>
89
- <script type="text/javascript">
90
- var ewayPaymentToken = new EwayPaymentToken(
91
- <?php echo $_tokens['tokens_json'] ?>,
92
- <?php echo count($_tokens['tokens']) ?>,
93
- true,
94
- '<?php echo $this->__('Edit') ?>',
95
- '<?php echo $this->__('Cancel edit') ?>'
96
- )
97
-
98
- if(typeof AdminOrder.prototype.setPaymentMethodBackup == "undefined") {
99
- AdminOrder.prototype.setPaymentMethodBackup = AdminOrder.prototype.setPaymentMethod;
100
- AdminOrder.prototype.setPaymentMethod = function(method) {
101
- AdminOrder.prototype.setPaymentMethodBackup(method);
102
- if(EwayPayment.isEwayRapidMethod(method)) {
103
- ewayPaymentToken.onSavedTokenChanged();
104
- }
105
- }
106
- }
107
- </script>
108
- </ul>
109
-
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php $_code=$this->getMethodCode() ?>
28
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display: none">
29
+ <li>
30
+ <div class="input-box">
31
+ <div class="v-fix" style="float: left; padding-right: 10px;">
32
+ <select id="ewayrapid_saved_token" name="payment[saved_token]" class="ewayrapid_saved_token">
33
+ <?php
34
+ $_tokens = $this->getTokenList();
35
+ $_defaultToken = isset($_tokens['default_token']) ? $_tokens['default_token'] : false;
36
+ ?>
37
+ <?php foreach($_tokens['tokens'] as $_key => $_token):
38
+ if ($_key == Eway_Rapid31_Model_Config::TOKEN_NEW || $this->checkCardName($_token) == Eway_Rapid31_Model_Config::CREDITCARD_METHOD): ?>
39
+ <?php /* @var Eway_Rapid31_Model_Customer_Token $_token */ ?>
40
+ <option value="<?php echo $_key ?>" <?php if($_key == $_defaultToken): ?>selected="selected"<?php endif; ?>>
41
+ <?php echo $_token->getCard() ?>
42
+ </option>
43
+ <?php endif; ?>
44
+ <?php endforeach; ?>
45
+ </select>
46
+ </div>
47
+ <?php if(count($_tokens['tokens']) > 1): ?>
48
+ <div class="v-fix">
49
+ <a id="ewayrapid_saved_edit" class="ewayrapid_saved_edit" href="javascript:void(0);"><?php echo $this->__('Edit') ?></a>
50
+ </div>
51
+ <?php endif; ?>
52
+ </div>
53
+ <div style="clear: both;"></div>
54
+ </li>
55
+
56
+ <li class="saved_token_fields" style="display: none">
57
+ <div class="input-box">
58
+ <label for="<?php echo $_code ?>_cc_owner"><?php echo $this->__('Name on Card') ?> <span class="required">*</span></label>
59
+ <br/>
60
+ <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]" value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>" />
61
+ </div>
62
+ </li>
63
+ <li class="saved_token_fields" style="display: none">
64
+ <label for="<?php echo $_code ?>_cc_number"><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label>
65
+ <br/>
66
+ <div class="input-box">
67
+ <input type="text" id="<?php echo $_code ?>_cc_number" data-eway-encrypt-name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text validate-cc-number validate-cc-type-auto" value="" />
68
+ <input type="hidden" id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" />
69
+ </div>
70
+ </li>
71
+ <li id="<?php echo $_code ?>_cc_type_exp_div" class="saved_token_fields" style="display: none">
72
+ <div class="input-box">
73
+ <label for="<?php echo $_code ?>_expiration"><?php echo $this->__('Expiration Date') ?> <span class="required">*</span></label>
74
+ <br/>
75
+ <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]" class="month validate-cc-exp required-entry">
76
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
77
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
78
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
79
+ <?php endforeach ?>
80
+ </select>
81
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
82
+ <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]" class="year required-entry">
83
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
84
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
85
+ <?php endforeach ?>
86
+ </select>
87
+ </div>
88
+ </li>
89
+ <?php echo $this->getChildHtml() ?>
90
+ <script type="text/javascript">
91
+ var ewayPaymentToken = new EwayPaymentToken(
92
+ <?php echo $_tokens['tokens_json'] ?>,
93
+ <?php echo count($_tokens['tokens']) ?>,
94
+ true,
95
+ '<?php echo $this->__('Edit') ?>',
96
+ '<?php echo $this->__('Cancel edit') ?>'
97
+ )
98
+
99
+ if(typeof AdminOrder.prototype.setPaymentMethodBackup == "undefined") {
100
+ AdminOrder.prototype.setPaymentMethodBackup = AdminOrder.prototype.setPaymentMethod;
101
+ AdminOrder.prototype.setPaymentMethod = function(method) {
102
+ AdminOrder.prototype.setPaymentMethodBackup(method);
103
+ if(EwayPayment.isEwayRapidMethod(method)) {
104
+ ewayPaymentToken.onSavedTokenChanged();
105
+ }
106
+ }
107
+ }
108
+ </script>
109
+ </ul>
110
+
app/design/adminhtml/default/default/template/ewayrapid/form/sharedpage_ewayone.phtml CHANGED
@@ -19,7 +19,8 @@
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category design
22
- * @package base_default
 
23
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
  */
25
  ?>
@@ -28,14 +29,14 @@ $_code = $this->getMethodCode()
28
  ?>
29
  <?php if($this->checkSaveCardAvailable()): ?>
30
  <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display: none;width: 80%;padding-top: 8px;">
31
- <li>
 
 
 
 
32
  <div class="input-box">
33
  <div class="v-fix">
34
  <select id="ewayrapid_ewayone_token" name="payment[saved_token]" class="ewayrapid_ewayone_token">
35
- <?php
36
- $_tokens = $this->getTokenList();
37
- $_defaultToken = isset($_tokens['default_token']) ? $_tokens['default_token'] : false;
38
- ?>
39
  <?php foreach($_tokens['tokens'] as $_key => $_token): ?>
40
  <?php /* @var Eway_Rapid31_Model_Customer_Token $_token */ ?>
41
  <option value="<?php echo $_key ?>" <?php if($_key == $_defaultToken): ?>selected="selected"<?php endif; ?>>
19
  * needs please refer to http://www.magentocommerce.com for more information.
20
  *
21
  * @category design
22
+ * @package base_default
23
+
24
  * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
  */
26
  ?>
29
  ?>
30
  <?php if($this->checkSaveCardAvailable()): ?>
31
  <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display: none;width: 80%;padding-top: 8px;">
32
+ <?php
33
+ $_tokens = $this->getTokenList();
34
+ $_defaultToken = isset($_tokens['default_token']) ? $_tokens['default_token'] : false;
35
+ ?>
36
+ <li <?php echo count($_tokens['tokens']) <= 1 ? 'style="display:none;"' : '' ?>>
37
  <div class="input-box">
38
  <div class="v-fix">
39
  <select id="ewayrapid_ewayone_token" name="payment[saved_token]" class="ewayrapid_ewayone_token">
 
 
 
 
40
  <?php foreach($_tokens['tokens'] as $_key => $_token): ?>
41
  <?php /* @var Eway_Rapid31_Model_Customer_Token $_token */ ?>
42
  <option value="<?php echo $_key ?>" <?php if($_key == $_defaultToken): ?>selected="selected"<?php endif; ?>>
app/design/adminhtml/default/default/template/ewayrapid/form/sharedpage_notsaved.phtml CHANGED
@@ -1,28 +1,29 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package base_default
23
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
- */
25
- ?>
26
- <?php
27
- $_code = $this->getMethodCode();
 
28
  ?>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package base_default
23
+
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ $_code = $this->getMethodCode();
29
  ?>
app/design/adminhtml/default/default/template/ewayrapid/info/direct_ewayone.phtml CHANGED
@@ -1,90 +1,90 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package default_default
23
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
- */
25
- ?>
26
- <?php
27
- $_helper = Mage::helper('ewayrapid');
28
- /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
29
- $_info = $this->getInfo();
30
- /* @var Mage_Sales_Model_Order_Payment $_info */
31
- ?>
32
- <div class="cards-list">
33
-
34
- <?php if (!$this->getHideTitle()): ?>
35
- <div class="bold"><?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?></div>
36
- <?php endif;?>
37
-
38
- <table class="info-table">
39
- <tbody>
40
- <?php if($_info->getTokenId()): ?>
41
- <tr>
42
- <td><?php echo $_helper->__('Payer ID') ?>:</td>
43
- <td><?php echo $this->getTokenId() ?></td>
44
- </tr>
45
- <?php endif; ?>
46
-
47
- <?php if($_info->getCcLast4()): ?>
48
- <tr>
49
- <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
50
- <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
51
- </tr>
52
- <?php endif; ?>
53
-
54
- <?php if($_info->getLastTransId()): ?>
55
- <tr>
56
- <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
57
- <td><?php echo $_info->getLastTransId(); ?></td>
58
- </tr>
59
- <?php endif; ?>
60
-
61
- <?php if($_info['beagle_score'] > 0): ?>
62
- <tr>
63
- <td><?php echo $_helper->__('Beagle Score') ?>:</td>
64
- <td><?php echo $_info['beagle_score']; ?></td>
65
- </tr>
66
- <?php endif; ?>
67
-
68
- <?php if(is_array($_info['beagle_verification'])): ?>
69
- <?php $_verifications = array_filter(unserialize($_info['beagle_verification']) ) ?>
70
- <?php endif; ?>
71
-
72
- <?php if(!empty($_verifications)): ?>
73
- <tr>
74
- <td><?php echo $_helper->__('Beagle Verification') ?>:</td>
75
- <td>
76
- <?php $count = 0; ?>
77
- <?php foreach($_verifications as $key => $_verificationCode): ?>
78
- <?php
79
- $_verificationTitle = Mage::helper('ewayrapid')->getBeagleVerificationTitle($_verificationCode);
80
- ?>
81
- <span><?php echo $count ? ', ' : '' ?><?php echo $key . ': ' . $_verificationTitle ?></span>
82
- <?php $count++ ?>
83
- <?php endforeach; ?>
84
- </td>
85
- </tr>
86
- <?php endif; ?>
87
-
88
- </tbody>
89
- </table>
90
- </div>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
+ */
25
+ ?>
26
+ <?php
27
+ $_helper = Mage::helper('ewayrapid');
28
+ /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
29
+ $_info = $this->getInfo();
30
+ /* @var Mage_Sales_Model_Order_Payment $_info */
31
+ ?>
32
+ <div class="cards-list">
33
+
34
+ <?php if (!$this->getHideTitle()): ?>
35
+ <div class="bold"><?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?></div>
36
+ <?php endif;?>
37
+
38
+ <table class="info-table">
39
+ <tbody>
40
+ <?php if($_info->getTokenId()): ?>
41
+ <tr>
42
+ <td><?php echo $_helper->__('Payer ID') ?>:</td>
43
+ <td><?php echo $this->getTokenId() ?></td>
44
+ </tr>
45
+ <?php endif; ?>
46
+
47
+ <?php if($_info->getCcLast4()): ?>
48
+ <tr>
49
+ <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
50
+ <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
51
+ </tr>
52
+ <?php endif; ?>
53
+
54
+ <?php if($_info->getLastTransId()): ?>
55
+ <tr>
56
+ <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
57
+ <td><?php echo $_info->getLastTransId(); ?></td>
58
+ </tr>
59
+ <?php endif; ?>
60
+
61
+ <?php if($_info['beagle_score'] > 0): ?>
62
+ <tr>
63
+ <td><?php echo $_helper->__('Beagle Score') ?>:</td>
64
+ <td><?php echo $_info['beagle_score']; ?></td>
65
+ </tr>
66
+ <?php endif; ?>
67
+
68
+ <?php if(is_array($_info['beagle_verification'])): ?>
69
+ <?php $_verifications = array_filter(unserialize($_info['beagle_verification']) ) ?>
70
+ <?php endif; ?>
71
+
72
+ <?php if(!empty($_verifications)): ?>
73
+ <tr>
74
+ <td><?php echo $_helper->__('Beagle Verification') ?>:</td>
75
+ <td>
76
+ <?php $count = 0; ?>
77
+ <?php foreach($_verifications as $key => $_verificationCode): ?>
78
+ <?php
79
+ $_verificationTitle = Mage::helper('ewayrapid')->getBeagleVerificationTitle($_verificationCode);
80
+ ?>
81
+ <span><?php echo $count ? ', ' : '' ?><?php echo $key . ': ' . $_verificationTitle ?></span>
82
+ <?php $count++ ?>
83
+ <?php endforeach; ?>
84
+ </td>
85
+ </tr>
86
+ <?php endif; ?>
87
+
88
+ </tbody>
89
+ </table>
90
+ </div>
app/design/adminhtml/default/default/template/ewayrapid/info/direct_notsaved.phtml CHANGED
@@ -1,104 +1,104 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package default_default
23
-
24
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
- */
26
- ?>
27
- <?php
28
- $_helper = Mage::helper('ewayrapid');
29
- /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
30
- $_info = $this->getInfo();
31
- /* @var Mage_Sales_Model_Order_Payment $_info */
32
- $_additionalInfo = $_info->getAdditionalInformation();
33
- ?>
34
- <div class="cards-list">
35
-
36
- <?php if (!$this->getHideTitle()): ?>
37
- <div class="bold"><?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?></div>
38
- <?php endif;?>
39
-
40
- <table class="info-table">
41
- <tbody>
42
- <?php if($_info->getCcOwner()) : ?>
43
- <tr>
44
- <td><?php echo $_helper->__('Card Holder\'s Name') ?>:</td>
45
- <td><?php echo $_info->getCcOwner(); ?></td>
46
- </tr>
47
- <?php endif;?>
48
-
49
- <?php if($_info->getCcLast4()) : ?>
50
- <tr>
51
- <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
52
- <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
53
- </tr>
54
- <?php endif;?>
55
-
56
- <?php if($_info->getCcExpMonth()) : ?>
57
- <tr>
58
- <td><?php echo $_helper->__('Credit Card Expiry') ?>:</td>
59
- <td><?php echo str_pad($_info->getCcExpMonth(), 2, '0', STR_PAD_LEFT); ?> / <?php echo $_info->getCcExpYear() ?></td>
60
- </tr>
61
- <?php endif;?>
62
-
63
- <?php if($_info->getCcType()) : ?>
64
- <tr>
65
- <td><?php echo $_helper->__('Credit Card Type') ?>:</td>
66
- <td><?php echo $this->getCcTypeName($_info->getCcType()); ?></td>
67
- </tr>
68
- <?php endif;?>
69
-
70
- <?php if($_info->getLastTransId()) : ?>
71
- <tr>
72
- <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
73
- <td><?php echo $_info->getLastTransId(); ?></td>
74
- </tr>
75
- <?php endif;?>
76
-
77
- <?php if($_info['beagle_score'] > 0): ?>
78
- <tr>
79
- <td><?php echo $_helper->__('Beagle Score') ?>:</td>
80
- <td><?php echo $_info['beagle_score']; ?></td>
81
- </tr>
82
- <?php endif; ?>
83
-
84
- <?php if (isset($_info['beagle_verification'])):
85
- $_verifications = array_filter(unserialize($_info['beagle_verification']) );
86
- endif; ?>
87
- <?php if(isset($_verifications) && !empty($_verifications)): ?>
88
- <tr>
89
- <td><?php echo $_helper->__('Beagle Verification') ?>:</td>
90
- <td>
91
- <?php $count = 0; ?>
92
- <?php foreach($_verifications as $key => $_verificationCode): ?>
93
- <?php
94
- $_verificationTitle = Mage::helper('ewayrapid')->getBeagleVerificationTitle($_verificationCode);
95
- ?>
96
- <span><?php echo $count ? ',' : '' ?><?php echo $key . ' : ' . $_verificationTitle ?></span>
97
- <?php $count++ ?>
98
- <?php endforeach; ?>
99
- </td>
100
- </tr>
101
- <?php endif; ?>
102
- </tbody>
103
- </table>
104
- </div>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ $_helper = Mage::helper('ewayrapid');
29
+ /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
30
+ $_info = $this->getInfo();
31
+ /* @var Mage_Sales_Model_Order_Payment $_info */
32
+ $_additionalInfo = $_info->getAdditionalInformation();
33
+ ?>
34
+ <div class="cards-list">
35
+
36
+ <?php if (!$this->getHideTitle()): ?>
37
+ <div class="bold"><?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?></div>
38
+ <?php endif;?>
39
+
40
+ <table class="info-table">
41
+ <tbody>
42
+ <?php if($_info->getCcOwner()) : ?>
43
+ <tr>
44
+ <td><?php echo $_helper->__('Card Holder\'s Name') ?>:</td>
45
+ <td><?php echo $_info->getCcOwner(); ?></td>
46
+ </tr>
47
+ <?php endif;?>
48
+
49
+ <?php if($_info->getCcLast4()) : ?>
50
+ <tr>
51
+ <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
52
+ <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
53
+ </tr>
54
+ <?php endif;?>
55
+
56
+ <?php if($_info->getCcExpMonth()) : ?>
57
+ <tr>
58
+ <td><?php echo $_helper->__('Credit Card Expiry') ?>:</td>
59
+ <td><?php echo str_pad($_info->getCcExpMonth(), 2, '0', STR_PAD_LEFT); ?> / <?php echo $_info->getCcExpYear() ?></td>
60
+ </tr>
61
+ <?php endif;?>
62
+
63
+ <?php if($_info->getCcType()) : ?>
64
+ <tr>
65
+ <td><?php echo $_helper->__('Credit Card Type') ?>:</td>
66
+ <td><?php echo $this->getCcTypeName($_info->getCcType()); ?></td>
67
+ </tr>
68
+ <?php endif;?>
69
+
70
+ <?php if($_info->getLastTransId()) : ?>
71
+ <tr>
72
+ <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
73
+ <td><?php echo $_info->getLastTransId(); ?></td>
74
+ </tr>
75
+ <?php endif;?>
76
+
77
+ <?php if($_info['beagle_score'] > 0): ?>
78
+ <tr>
79
+ <td><?php echo $_helper->__('Beagle Score') ?>:</td>
80
+ <td><?php echo $_info['beagle_score']; ?></td>
81
+ </tr>
82
+ <?php endif; ?>
83
+
84
+ <?php if (isset($_info['beagle_verification'])):
85
+ $_verifications = array_filter(unserialize($_info['beagle_verification']) );
86
+ endif; ?>
87
+ <?php if(isset($_verifications) && !empty($_verifications)): ?>
88
+ <tr>
89
+ <td><?php echo $_helper->__('Beagle Verification') ?>:</td>
90
+ <td>
91
+ <?php $count = 0; ?>
92
+ <?php foreach($_verifications as $key => $_verificationCode): ?>
93
+ <?php
94
+ $_verificationTitle = Mage::helper('ewayrapid')->getBeagleVerificationTitle($_verificationCode);
95
+ ?>
96
+ <span><?php echo $count ? ',' : '' ?><?php echo $key . ' : ' . $_verificationTitle ?></span>
97
+ <?php $count++ ?>
98
+ <?php endforeach; ?>
99
+ </td>
100
+ </tr>
101
+ <?php endif; ?>
102
+ </tbody>
103
+ </table>
104
+ </div>
app/design/adminhtml/default/default/template/ewayrapid/info/direct_saved.phtml CHANGED
@@ -1,89 +1,89 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package default_default
23
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
- */
25
- ?>
26
- <?php
27
- $_helper = Mage::helper('ewayrapid');
28
- /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
29
- $_info = $this->getInfo();
30
- /* @var Mage_Sales_Model_Order_Payment $_info */
31
- ?>
32
- <div class="cards-list">
33
-
34
- <?php if (!$this->getHideTitle()): ?>
35
- <div class="bold"><?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?></div>
36
- <?php endif;?>
37
-
38
- <table class="info-table">
39
- <tbody>
40
- <?php if($_info->getTokenId()): ?>
41
- <tr>
42
- <td><?php echo $_helper->__('Payer ID') ?>:</td>
43
- <td><?php echo $this->getTokenId() ?></td>
44
- </tr>
45
- <?php endif; ?>
46
-
47
- <?php if($_info->getCcLast4()): ?>
48
- <tr>
49
- <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
50
- <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
51
- </tr>
52
- <?php endif; ?>
53
-
54
- <?php if($_info->getLastTransId()): ?>
55
- <tr>
56
- <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
57
- <td><?php echo $_info->getLastTransId(); ?></td>
58
- </tr>
59
- <?php endif; ?>
60
-
61
- <?php if($_info['beagle_score'] > 0): ?>
62
- <tr>
63
- <td><?php echo $_helper->__('Beagle Score') ?>:</td>
64
- <td><?php echo $_info['beagle_score']; ?></td>
65
- </tr>
66
- <?php endif; ?>
67
-
68
- <?php if (isset($_info['beagle_verification'])):
69
- $_verifications = array_filter(unserialize($_info['beagle_verification']) );
70
- endif; ?>
71
- <?php if(isset($_verifications) && !empty($_verifications)): ?>
72
- <tr>
73
- <td><?php echo $_helper->__('Beagle Verification') ?>:</td>
74
- <td>
75
- <?php $count = 0; ?>
76
- <?php foreach($_verifications as $key => $_verificationCode): ?>
77
- <?php
78
- $_verificationTitle = Mage::helper('ewayrapid')->getBeagleVerificationTitle($_verificationCode);
79
- ?>
80
- <span><?php echo $count ? ',' : '' ?><?php echo $key . ' : ' . $_verificationTitle ?></span>
81
- <?php $count++ ?>
82
- <?php endforeach; ?>
83
- </td>
84
- </tr>
85
- <?php endif; ?>
86
-
87
- </tbody>
88
- </table>
89
- </div>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
+ */
25
+ ?>
26
+ <?php
27
+ $_helper = Mage::helper('ewayrapid');
28
+ /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
29
+ $_info = $this->getInfo();
30
+ /* @var Mage_Sales_Model_Order_Payment $_info */
31
+ ?>
32
+ <div class="cards-list">
33
+
34
+ <?php if (!$this->getHideTitle()): ?>
35
+ <div class="bold"><?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?></div>
36
+ <?php endif;?>
37
+
38
+ <table class="info-table">
39
+ <tbody>
40
+ <?php if($_info->getTokenId()): ?>
41
+ <tr>
42
+ <td><?php echo $_helper->__('Payer ID') ?>:</td>
43
+ <td><?php echo $this->getTokenId() ?></td>
44
+ </tr>
45
+ <?php endif; ?>
46
+
47
+ <?php if($_info->getCcLast4()): ?>
48
+ <tr>
49
+ <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
50
+ <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
51
+ </tr>
52
+ <?php endif; ?>
53
+
54
+ <?php if($_info->getLastTransId()): ?>
55
+ <tr>
56
+ <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
57
+ <td><?php echo $_info->getLastTransId(); ?></td>
58
+ </tr>
59
+ <?php endif; ?>
60
+
61
+ <?php if($_info['beagle_score'] > 0): ?>
62
+ <tr>
63
+ <td><?php echo $_helper->__('Beagle Score') ?>:</td>
64
+ <td><?php echo $_info['beagle_score']; ?></td>
65
+ </tr>
66
+ <?php endif; ?>
67
+
68
+ <?php if (isset($_info['beagle_verification'])):
69
+ $_verifications = array_filter(unserialize($_info['beagle_verification']) );
70
+ endif; ?>
71
+ <?php if(isset($_verifications) && !empty($_verifications)): ?>
72
+ <tr>
73
+ <td><?php echo $_helper->__('Beagle Verification') ?>:</td>
74
+ <td>
75
+ <?php $count = 0; ?>
76
+ <?php foreach($_verifications as $key => $_verificationCode): ?>
77
+ <?php
78
+ $_verificationTitle = Mage::helper('ewayrapid')->getBeagleVerificationTitle($_verificationCode);
79
+ ?>
80
+ <span><?php echo $count ? ',' : '' ?><?php echo $key . ' : ' . $_verificationTitle ?></span>
81
+ <?php $count++ ?>
82
+ <?php endforeach; ?>
83
+ </td>
84
+ </tr>
85
+ <?php endif; ?>
86
+
87
+ </tbody>
88
+ </table>
89
+ </div>
app/design/adminhtml/default/default/template/ewayrapid/info/sharedpage_notsaved.phtml CHANGED
@@ -1,103 +1,103 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package default_default
23
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
- */
25
- ?>
26
- <?php
27
- $_helper = Mage::helper('ewayrapid');
28
- /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
29
- $_info = $this->getInfo();
30
- /* @var Mage_Sales_Model_Order_Payment $_info */
31
- $_additionalInfo = $_info->getAdditionalInformation();
32
- ?>
33
- <div class="cards-list">
34
-
35
- <?php if (!$this->getHideTitle()): ?>
36
- <div class="bold"><?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?></div>
37
- <?php endif;?>
38
-
39
- <table class="info-table">
40
- <tbody>
41
- <?php if($_info->getCcOwner()) : ?>
42
- <tr>
43
- <td><?php echo $_helper->__('Card Holder\'s Name') ?>:</td>
44
- <td><?php echo $_info->getCcOwner(); ?></td>
45
- </tr>
46
- <?php endif;?>
47
-
48
- <?php if($_info->getCcLast4()) : ?>
49
- <tr>
50
- <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
51
- <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
52
- </tr>
53
- <?php endif;?>
54
-
55
- <?php if($_info->getCcExpMonth()) : ?>
56
- <tr>
57
- <td><?php echo $_helper->__('Credit Card Expiry') ?>:</td>
58
- <td><?php echo str_pad($_info->getCcExpMonth(), 2, '0', STR_PAD_LEFT); ?> / <?php echo $_info->getCcExpYear() ?></td>
59
- </tr>
60
- <?php endif;?>
61
-
62
- <?php if($_info->getCcType()) : ?>
63
- <tr>
64
- <td><?php echo $_helper->__('Credit Card Type') ?>:</td>
65
- <td><?php echo $this->getCcTypeName($_info->getCcType()); ?></td>
66
- </tr>
67
- <?php endif;?>
68
-
69
- <?php if($_info->getLastTransId()) : ?>
70
- <tr>
71
- <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
72
- <td><?php echo $_info->getLastTransId(); ?></td>
73
- </tr>
74
- <?php endif;?>
75
-
76
- <?php if($_info['beagle_score'] > 0): ?>
77
- <tr>
78
- <td><?php echo $_helper->__('Beagle Score') ?>:</td>
79
- <td><?php echo $_info['beagle_score']; ?></td>
80
- </tr>
81
- <?php endif; ?>
82
-
83
- <?php if (isset($_info['beagle_verification'])):
84
- $_verifications = array_filter(unserialize($_info['beagle_verification']) );
85
- endif; ?>
86
- <?php if(isset($_verifications) && !empty($_verifications)): ?>
87
- <tr>
88
- <td><?php echo $_helper->__('Beagle Verification') ?>:</td>
89
- <td>
90
- <?php $count = 0; ?>
91
- <?php foreach($_verifications as $key => $_verificationCode): ?>
92
- <?php
93
- $_verificationTitle = Mage::helper('ewayrapid')->getBeagleVerificationTitle($_verificationCode);
94
- ?>
95
- <span><?php echo $count ? ',' : '' ?><?php echo $key . ' : ' . $_verificationTitle ?></span>
96
- <?php $count++ ?>
97
- <?php endforeach; ?>
98
- </td>
99
- </tr>
100
- <?php endif; ?>
101
- </tbody>
102
- </table>
103
- </div>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
+ */
25
+ ?>
26
+ <?php
27
+ $_helper = Mage::helper('ewayrapid');
28
+ /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
29
+ $_info = $this->getInfo();
30
+ /* @var Mage_Sales_Model_Order_Payment $_info */
31
+ $_additionalInfo = $_info->getAdditionalInformation();
32
+ ?>
33
+ <div class="cards-list">
34
+
35
+ <?php if (!$this->getHideTitle()): ?>
36
+ <div class="bold"><?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?></div>
37
+ <?php endif;?>
38
+
39
+ <table class="info-table">
40
+ <tbody>
41
+ <?php if($_info->getCcOwner()) : ?>
42
+ <tr>
43
+ <td><?php echo $_helper->__('Card Holder\'s Name') ?>:</td>
44
+ <td><?php echo $_info->getCcOwner(); ?></td>
45
+ </tr>
46
+ <?php endif;?>
47
+
48
+ <?php if($_info->getCcLast4()) : ?>
49
+ <tr>
50
+ <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
51
+ <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
52
+ </tr>
53
+ <?php endif;?>
54
+
55
+ <?php if($_info->getCcExpMonth()) : ?>
56
+ <tr>
57
+ <td><?php echo $_helper->__('Credit Card Expiry') ?>:</td>
58
+ <td><?php echo str_pad($_info->getCcExpMonth(), 2, '0', STR_PAD_LEFT); ?> / <?php echo $_info->getCcExpYear() ?></td>
59
+ </tr>
60
+ <?php endif;?>
61
+
62
+ <?php if($_info->getCcType()) : ?>
63
+ <tr>
64
+ <td><?php echo $_helper->__('Credit Card Type') ?>:</td>
65
+ <td><?php echo $this->getCcTypeName($_info->getCcType()); ?></td>
66
+ </tr>
67
+ <?php endif;?>
68
+
69
+ <?php if($_info->getLastTransId()) : ?>
70
+ <tr>
71
+ <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
72
+ <td><?php echo $_info->getLastTransId(); ?></td>
73
+ </tr>
74
+ <?php endif;?>
75
+
76
+ <?php if($_info['beagle_score'] > 0): ?>
77
+ <tr>
78
+ <td><?php echo $_helper->__('Beagle Score') ?>:</td>
79
+ <td><?php echo $_info['beagle_score']; ?></td>
80
+ </tr>
81
+ <?php endif; ?>
82
+
83
+ <?php if (isset($_info['beagle_verification'])):
84
+ $_verifications = array_filter(unserialize($_info['beagle_verification']) );
85
+ endif; ?>
86
+ <?php if(isset($_verifications) && !empty($_verifications)): ?>
87
+ <tr>
88
+ <td><?php echo $_helper->__('Beagle Verification') ?>:</td>
89
+ <td>
90
+ <?php $count = 0; ?>
91
+ <?php foreach($_verifications as $key => $_verificationCode): ?>
92
+ <?php
93
+ $_verificationTitle = Mage::helper('ewayrapid')->getBeagleVerificationTitle($_verificationCode);
94
+ ?>
95
+ <span><?php echo $count ? ',' : '' ?><?php echo $key . ' : ' . $_verificationTitle ?></span>
96
+ <?php $count++ ?>
97
+ <?php endforeach; ?>
98
+ </td>
99
+ </tr>
100
+ <?php endif; ?>
101
+ </tbody>
102
+ </table>
103
+ </div>
app/design/adminhtml/default/default/template/ewayrapid/info/sharedpage_saved.phtml CHANGED
@@ -1,103 +1,103 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package default_default
23
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
- */
25
- ?>
26
- <?php
27
- $_helper = Mage::helper('ewayrapid');
28
- /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
29
- $_info = $this->getInfo();
30
- /* @var Mage_Sales_Model_Order_Payment $_info */
31
- $_additionalInfo = $_info->getAdditionalInformation();
32
- ?>
33
- <div class="cards-list">
34
-
35
- <?php if (!$this->getHideTitle()): ?>
36
- <div class="bold"><?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?></div>
37
- <?php endif;?>
38
-
39
- <table class="info-table">
40
- <tbody>
41
- <?php if($_info->getCcOwner()) : ?>
42
- <tr>
43
- <td><?php echo $_helper->__('Card Holder\'s Name') ?>:</td>
44
- <td><?php echo $_info->getCcOwner(); ?></td>
45
- </tr>
46
- <?php endif;?>
47
-
48
- <?php if($_info->getCcLast4()) : ?>
49
- <tr>
50
- <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
51
- <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
52
- </tr>
53
- <?php endif;?>
54
-
55
- <?php if($_info->getCcExpMonth()) : ?>
56
- <tr>
57
- <td><?php echo $_helper->__('Credit Card Expiry') ?>:</td>
58
- <td><?php echo str_pad($_info->getCcExpMonth(), 2, '0', STR_PAD_LEFT); ?> / <?php echo $_info->getCcExpYear() ?></td>
59
- </tr>
60
- <?php endif;?>
61
-
62
- <?php if($_info->getCcType()) : ?>
63
- <tr>
64
- <td><?php echo $_helper->__('Credit Card Type') ?>:</td>
65
- <td><?php echo $this->getCcTypeName($_info->getCcType()); ?></td>
66
- </tr>
67
- <?php endif;?>
68
-
69
- <?php if($_info->getLastTransId()) : ?>
70
- <tr>
71
- <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
72
- <td><?php echo $_info->getLastTransId(); ?></td>
73
- </tr>
74
- <?php endif;?>
75
-
76
- <?php if($_info['beagle_score'] > 0): ?>
77
- <tr>
78
- <td><?php echo $_helper->__('Beagle Score') ?>:</td>
79
- <td><?php echo $_info['beagle_score']; ?></td>
80
- </tr>
81
- <?php endif; ?>
82
-
83
- <?php if (isset($_info['beagle_verification'])):
84
- $_verifications = array_filter(unserialize($_info['beagle_verification']) );
85
- endif; ?>
86
- <?php if(isset($_verifications) && !empty($_verifications)): ?>
87
- <tr>
88
- <td><?php echo $_helper->__('Beagle Verification') ?>:</td>
89
- <td>
90
- <?php $count = 0; ?>
91
- <?php foreach($_verifications as $key => $_verificationCode): ?>
92
- <?php
93
- $_verificationTitle = Mage::helper('ewayrapid')->getBeagleVerificationTitle($_verificationCode);
94
- ?>
95
- <span><?php echo $count ? ',' : '' ?><?php echo $key . ' : ' . $_verificationTitle ?></span>
96
- <?php $count++ ?>
97
- <?php endforeach; ?>
98
- </td>
99
- </tr>
100
- <?php endif; ?>
101
- </tbody>
102
- </table>
103
- </div>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
+ */
25
+ ?>
26
+ <?php
27
+ $_helper = Mage::helper('ewayrapid');
28
+ /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
29
+ $_info = $this->getInfo();
30
+ /* @var Mage_Sales_Model_Order_Payment $_info */
31
+ $_additionalInfo = $_info->getAdditionalInformation();
32
+ ?>
33
+ <div class="cards-list">
34
+
35
+ <?php if (!$this->getHideTitle()): ?>
36
+ <div class="bold"><?php echo $this->htmlEscape($this->getMethod()->getTitle()) ?></div>
37
+ <?php endif;?>
38
+
39
+ <table class="info-table">
40
+ <tbody>
41
+ <?php if($_info->getCcOwner()) : ?>
42
+ <tr>
43
+ <td><?php echo $_helper->__('Card Holder\'s Name') ?>:</td>
44
+ <td><?php echo $_info->getCcOwner(); ?></td>
45
+ </tr>
46
+ <?php endif;?>
47
+
48
+ <?php if($_info->getCcLast4()) : ?>
49
+ <tr>
50
+ <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
51
+ <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
52
+ </tr>
53
+ <?php endif;?>
54
+
55
+ <?php if($_info->getCcExpMonth()) : ?>
56
+ <tr>
57
+ <td><?php echo $_helper->__('Credit Card Expiry') ?>:</td>
58
+ <td><?php echo str_pad($_info->getCcExpMonth(), 2, '0', STR_PAD_LEFT); ?> / <?php echo $_info->getCcExpYear() ?></td>
59
+ </tr>
60
+ <?php endif;?>
61
+
62
+ <?php if($_info->getCcType()) : ?>
63
+ <tr>
64
+ <td><?php echo $_helper->__('Credit Card Type') ?>:</td>
65
+ <td><?php echo $this->getCcTypeName($_info->getCcType()); ?></td>
66
+ </tr>
67
+ <?php endif;?>
68
+
69
+ <?php if($_info->getLastTransId()) : ?>
70
+ <tr>
71
+ <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
72
+ <td><?php echo $_info->getLastTransId(); ?></td>
73
+ </tr>
74
+ <?php endif;?>
75
+
76
+ <?php if($_info['beagle_score'] > 0): ?>
77
+ <tr>
78
+ <td><?php echo $_helper->__('Beagle Score') ?>:</td>
79
+ <td><?php echo $_info['beagle_score']; ?></td>
80
+ </tr>
81
+ <?php endif; ?>
82
+
83
+ <?php if (isset($_info['beagle_verification'])):
84
+ $_verifications = array_filter(unserialize($_info['beagle_verification']) );
85
+ endif; ?>
86
+ <?php if(isset($_verifications) && !empty($_verifications)): ?>
87
+ <tr>
88
+ <td><?php echo $_helper->__('Beagle Verification') ?>:</td>
89
+ <td>
90
+ <?php $count = 0; ?>
91
+ <?php foreach($_verifications as $key => $_verificationCode): ?>
92
+ <?php
93
+ $_verificationTitle = Mage::helper('ewayrapid')->getBeagleVerificationTitle($_verificationCode);
94
+ ?>
95
+ <span><?php echo $count ? ',' : '' ?><?php echo $key . ' : ' . $_verificationTitle ?></span>
96
+ <?php $count++ ?>
97
+ <?php endforeach; ?>
98
+ </td>
99
+ </tr>
100
+ <?php endif; ?>
101
+ </tbody>
102
+ </table>
103
+ </div>
app/design/adminhtml/default/default/template/ewayrapid/pdf/direct_notsaved.phtml CHANGED
@@ -1,54 +1,55 @@
1
- <?php
2
- /**
3
- * Magento
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Academic Free License (AFL 3.0)
8
- * that is bundled with this package in the file LICENSE_AFL.txt.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://opensource.org/licenses/afl-3.0.php
11
- * If you did not receive a copy of the license and are unable to
12
- * obtain it through the world-wide-web, please send an email
13
- * to license@magentocommerce.com so we can send you a copy immediately.
14
- *
15
- * DISCLAIMER
16
- *
17
- * Do not edit or add to this file if you wish to upgrade Magento to newer
18
- * versions in the future. If you wish to customize Magento for your
19
- * needs please refer to http://www.magentocommerce.com for more information.
20
- *
21
- * @category design
22
- * @package default_default
23
- * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24
- */
25
- ?>
26
- <?php
27
- $_helper = Mage::helper('ewayrapid');
28
- /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
29
- $_info = $this->getInfo();
30
- /* @var Mage_Sales_Model_Order_Payment $_info */
31
-
32
- ?>
33
-
34
-
35
- <?php echo $this->getMethod()->getTitle() ?>{{pdf_row_separator}}
36
- <?php if($_info->getCcOwner()): ?>
37
- <?php echo $_helper->__('Card Holder\'s Name') ?>: <?php echo $_info->getCcOwner(); ?>{{pdf_row_separator}}
38
- <?php endif; ?>
39
-
40
- <?php if($_info->getCcLast4()): ?>
41
- <?php echo $_helper->__('Credit Card Number') ?>: <?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?>{{pdf_row_separator}}
42
- <?php endif; ?>
43
-
44
- <?php if($_info->getCcExpMonth()): ?>
45
- <?php echo $_helper->__('Credit Card Expiry') ?>: <?php echo str_pad($_info->getCcExpMonth(), 2, '0', STR_PAD_LEFT); ?> / <?php echo $_info->getCcExpYear() ?>{{pdf_row_separator}}
46
- <?php endif; ?>
47
-
48
- <?php if($_info->getCcType()): ?>
49
- <?php echo $_helper->__('Credit Card Type') ?>: <?php echo $this->getCcTypeName($_info->getCcType()); ?>{{pdf_row_separator}}
50
- <?php endif; ?>
51
-
52
- <?php if($_info->getLastTransId()): ?>
53
- <?php echo $_helper->__('Last Transaction ID') ?>: <?php echo $_info->getLastTransId(); ?>{{pdf_row_separator}}
 
54
  <?php endif; ?>
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ $_helper = Mage::helper('ewayrapid');
29
+ /* @var Eway_Rapid31_Block_Info_Direct_Notsaved $this */
30
+ $_info = $this->getInfo();
31
+ /* @var Mage_Sales_Model_Order_Payment $_info */
32
+
33
+ ?>
34
+
35
+
36
+ <?php echo $this->getMethod()->getTitle() ?>{{pdf_row_separator}}
37
+ <?php if($_info->getCcOwner()): ?>
38
+ <?php echo $_helper->__('Card Holder\'s Name') ?>: <?php echo $_info->getCcOwner(); ?>{{pdf_row_separator}}
39
+ <?php endif; ?>
40
+
41
+ <?php if($_info->getCcLast4()): ?>
42
+ <?php echo $_helper->__('Credit Card Number') ?>: <?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?>{{pdf_row_separator}}
43
+ <?php endif; ?>
44
+
45
+ <?php if($_info->getCcExpMonth()): ?>
46
+ <?php echo $_helper->__('Credit Card Expiry') ?>: <?php echo str_pad($_info->getCcExpMonth(), 2, '0', STR_PAD_LEFT); ?> / <?php echo $_info->getCcExpYear() ?>{{pdf_row_separator}}
47
+ <?php endif; ?>
48
+
49
+ <?php if($_info->getCcType()): ?>
50
+ <?php echo $_helper->__('Credit Card Type') ?>: <?php echo $this->getCcTypeName($_info->getCcType()); ?>{{pdf_row_separator}}
51
+ <?php endif; ?>
52
+
53
+ <?php if($_info->getLastTransId()): ?>
54
+ <?php echo $_helper->__('Last Transaction ID') ?>: <?php echo $_info->getLastTransId(); ?>{{pdf_row_separator}}
55
  <?php endif; ?>
app/design/frontend/base/default/layout/ewayrapid/layout.xml CHANGED
@@ -1,216 +1,216 @@
1
- <?xml version="1.0"?>
2
- <layout version="0.1.0">
3
- <checkout_onepage_index>
4
- <reference name="head">
5
- <block type="core/text" name="external_js">
6
- <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
7
- </block>
8
- <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
9
- <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
10
- </reference>
11
- <reference name="content">
12
- <block type="core/template" name="ewayrapid.js" after="-">
13
- <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
14
- <template>ewayrapid/js.phtml</template>
15
- </action>
16
- </block>
17
- </reference>
18
- </checkout_onepage_index>
19
-
20
- <checkout_multishipping_billing>
21
- <reference name="head">
22
- <block type="core/text" name="external_js">
23
- <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
24
- </block>
25
- <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
26
- <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
27
- </reference>
28
- <reference name="content">
29
- <block type="core/template" name="ewayrapid.js" after="-">
30
- <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
31
- <template>ewayrapid/js.phtml</template>
32
- </action>
33
- <action method="setCheckoutExtension">
34
- <name>MultiShippingAddress</name>
35
- </action>
36
- </block>
37
- </reference>
38
- </checkout_multishipping_billing>
39
-
40
- <customer_account>
41
- <reference name="customer_account_navigation">
42
- <action ifconfig="payment/ewayrapid_ewayone/active" method="addLink" translate="label" module="ewayrapid">
43
- <name>my-creditcards</name>
44
- <path>ewayrapid/mycards/</path>
45
- <label>My Credit Cards</label>
46
- </action>
47
-
48
- <action ifconfig="payment/ewayrapid_transparentRedirect/active" method="addLink" translate="label" module="ewayrapid">
49
- <name>my-transparent-redirect-card</name>
50
- <path>ewayrapid/transparentredirectcard/</path>
51
- <label>My Transparent Redirect Card</label>
52
- </action>
53
-
54
- </reference>
55
- </customer_account>
56
- <ewayrapid_mycards_index>
57
- <update handle="customer_account"/>
58
- <reference name="my.account.wrapper">
59
- <block type="ewayrapid/customer_mycards" template="ewayrapid/customer/mycards.phtml" name="ewayrapid.token.list"></block>
60
- <block type="customer/account_dashboard" name="customer.account.link.back" template="customer/account/link/back.phtml"/>
61
- </reference>
62
- </ewayrapid_mycards_index>
63
-
64
- <ewayrapid_mycards_edit>
65
- <reference name="head">
66
- <block type="core/text" name="external_js">
67
- <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
68
- </block>
69
- <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
70
- <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
71
- </reference>
72
- <update handle="customer_account"/>
73
- <reference name="my.account.wrapper">
74
- <block type="ewayrapid/customer_edit" template="ewayrapid/customer/edit.phtml" name="ewayrapid.token.edit"></block>
75
- </reference>
76
- </ewayrapid_mycards_edit>
77
-
78
- <onestepcheckout_index_index>
79
- <reference name="head">
80
- <block type="core/text" name="external_js">
81
- <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
82
- </block>
83
- <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
84
- <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
85
- </reference>
86
- <reference name="before_body_end">
87
- <block type="core/template" name="ewayrapid.js" after="-">
88
- <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
89
- <template>ewayrapid/js.phtml</template>
90
- </action>
91
- <action method="setCheckoutExtension">
92
- <name>OneStepCheckout</name>
93
- </action>
94
- </block>
95
- </reference>
96
- </onestepcheckout_index_index>
97
-
98
- <firecheckout_index_index>
99
- <reference name="head">
100
- <block type="core/text" name="external_js">
101
- <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
102
- </block>
103
- <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
104
- <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
105
- </reference>
106
- <reference name="before_body_end">
107
- <block type="core/template" name="ewayrapid.js" after="-">
108
- <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
109
- <template>ewayrapid/js.phtml</template>
110
- </action>
111
- <action method="setCheckoutExtension">
112
- <name>FireCheckout</name>
113
- </action>
114
- </block>
115
- </reference>
116
- </firecheckout_index_index>
117
-
118
- <opc_index_index>
119
- <reference name="head">
120
- <block type="core/text" name="external_js">
121
- <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
122
- </block>
123
- <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
124
- <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
125
- </reference>
126
- <reference name="before_body_end">
127
- <block type="core/template" name="ewayrapid.js" after="-">
128
- <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
129
- <template>ewayrapid/js.phtml</template>
130
- </action>
131
- <action method="setCheckoutExtension">
132
- <name>IWDOnePageCheckout</name>
133
- </action>
134
- </block>
135
- </reference>
136
- </opc_index_index>
137
-
138
- <gomage_checkout_onepage_index>
139
- <reference name="head">
140
- <block type="core/text" name="external_js">
141
- <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
142
- </block>
143
- <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
144
- <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
145
- </reference>
146
- <reference name="before_body_end">
147
- <block type="core/template" name="ewayrapid.js" after="-">
148
- <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
149
- <template>ewayrapid/js.phtml</template>
150
- </action>
151
- <action method="setCheckoutExtension">
152
- <name>LightCheckout</name>
153
- </action>
154
- </block>
155
- </reference>
156
- </gomage_checkout_onepage_index>
157
-
158
- <hanlder_transparent_layout_empty>
159
- <update handle="default"/>
160
- <reference name="root">
161
- <action method="setTemplate">
162
- <template>page/empty.phtml</template>
163
- </action>
164
- </reference>
165
- </hanlder_transparent_layout_empty>
166
-
167
- <hanlder_transparent_layout>
168
- <update handle="default"/>
169
- <reference name="head">
170
- <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
171
- </reference>
172
- <reference name="root">
173
- <action method="setTemplate">
174
- <template>page/1column.phtml</template>
175
- </action>
176
- </reference>
177
- </hanlder_transparent_layout>
178
-
179
- <ewayrapid_transparent_paynow>
180
- <update handle="hanlder_transparent_layout_empty"/>
181
- <reference name="content">
182
- <block type="ewayrapid/redirect_transparent" name="transparent.block.paynow"/>
183
- </reference>
184
- </ewayrapid_transparent_paynow>
185
-
186
- <ewayrapid_transparent_redirect>
187
- <update handle="hanlder_transparent_layout_empty"/>
188
- <reference name="content">
189
- <block type="ewayrapid/redirect_transparentCheckout" name="transparent.block.checkout"/>
190
- </reference>
191
- </ewayrapid_transparent_redirect>
192
-
193
- <ewayrapid_handle_review>
194
- <label>Eway Paypal Order Review Form</label>
195
- <remove name="right"/>
196
- <remove name="left"/>
197
-
198
- <reference name="root">
199
- <action method="setTemplate">
200
- <template>page/1column.phtml</template>
201
- </action>
202
- </reference>
203
- <reference name="content">
204
- <block type="ewayrapid/redirect_paypalReview" name="eway.block.review">
205
- </block>
206
- </reference>
207
- </ewayrapid_handle_review>
208
-
209
- <ewayrapid_transparent_review>
210
- <update handle="ewayrapid_handle_review"/>
211
- </ewayrapid_transparent_review>
212
-
213
- <ewayrapid_sharedpage_review>
214
- <update handle="ewayrapid_handle_review"/>
215
- </ewayrapid_sharedpage_review>
216
  </layout>
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout_onepage_index>
4
+ <reference name="head">
5
+ <block type="core/text" name="external_js">
6
+ <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
7
+ </block>
8
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
9
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
10
+ </reference>
11
+ <reference name="content">
12
+ <block type="core/template" name="ewayrapid.js" after="-">
13
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
14
+ <template>ewayrapid/js.phtml</template>
15
+ </action>
16
+ </block>
17
+ </reference>
18
+ </checkout_onepage_index>
19
+
20
+ <checkout_multishipping_billing>
21
+ <reference name="head">
22
+ <block type="core/text" name="external_js">
23
+ <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
24
+ </block>
25
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
26
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
27
+ </reference>
28
+ <reference name="content">
29
+ <block type="core/template" name="ewayrapid.js" after="-">
30
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
31
+ <template>ewayrapid/js.phtml</template>
32
+ </action>
33
+ <action method="setCheckoutExtension">
34
+ <name>MultiShippingAddress</name>
35
+ </action>
36
+ </block>
37
+ </reference>
38
+ </checkout_multishipping_billing>
39
+
40
+ <customer_account>
41
+ <reference name="customer_account_navigation">
42
+ <action ifconfig="payment/ewayrapid_ewayone/active" method="addLink" translate="label" module="ewayrapid">
43
+ <name>my-creditcards</name>
44
+ <path>ewayrapid/mycards/</path>
45
+ <label>My Credit Cards</label>
46
+ </action>
47
+
48
+ <action ifconfig="payment/ewayrapid_transparentRedirect/active" method="addLink" translate="label" module="ewayrapid">
49
+ <name>my-transparent-redirect-card</name>
50
+ <path>ewayrapid/transparentredirectcard/</path>
51
+ <label>My Transparent Redirect Card</label>
52
+ </action>
53
+
54
+ </reference>
55
+ </customer_account>
56
+ <ewayrapid_mycards_index>
57
+ <update handle="customer_account"/>
58
+ <reference name="my.account.wrapper">
59
+ <block type="ewayrapid/customer_mycards" template="ewayrapid/customer/mycards.phtml" name="ewayrapid.token.list"></block>
60
+ <block type="customer/account_dashboard" name="customer.account.link.back" template="customer/account/link/back.phtml"/>
61
+ </reference>
62
+ </ewayrapid_mycards_index>
63
+
64
+ <ewayrapid_mycards_edit>
65
+ <reference name="head">
66
+ <block type="core/text" name="external_js">
67
+ <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
68
+ </block>
69
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
70
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
71
+ </reference>
72
+ <update handle="customer_account"/>
73
+ <reference name="my.account.wrapper">
74
+ <block type="ewayrapid/customer_edit" template="ewayrapid/customer/edit.phtml" name="ewayrapid.token.edit"></block>
75
+ </reference>
76
+ </ewayrapid_mycards_edit>
77
+
78
+ <onestepcheckout_index_index>
79
+ <reference name="head">
80
+ <block type="core/text" name="external_js">
81
+ <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
82
+ </block>
83
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
84
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
85
+ </reference>
86
+ <reference name="before_body_end">
87
+ <block type="core/template" name="ewayrapid.js" after="-">
88
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
89
+ <template>ewayrapid/js.phtml</template>
90
+ </action>
91
+ <action method="setCheckoutExtension">
92
+ <name>OneStepCheckout</name>
93
+ </action>
94
+ </block>
95
+ </reference>
96
+ </onestepcheckout_index_index>
97
+
98
+ <firecheckout_index_index>
99
+ <reference name="head">
100
+ <block type="core/text" name="external_js">
101
+ <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
102
+ </block>
103
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
104
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
105
+ </reference>
106
+ <reference name="before_body_end">
107
+ <block type="core/template" name="ewayrapid.js" after="-">
108
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
109
+ <template>ewayrapid/js.phtml</template>
110
+ </action>
111
+ <action method="setCheckoutExtension">
112
+ <name>FireCheckout</name>
113
+ </action>
114
+ </block>
115
+ </reference>
116
+ </firecheckout_index_index>
117
+
118
+ <opc_index_index>
119
+ <reference name="head">
120
+ <block type="core/text" name="external_js">
121
+ <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
122
+ </block>
123
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
124
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
125
+ </reference>
126
+ <reference name="before_body_end">
127
+ <block type="core/template" name="ewayrapid.js" after="-">
128
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
129
+ <template>ewayrapid/js.phtml</template>
130
+ </action>
131
+ <action method="setCheckoutExtension">
132
+ <name>IWDOnePageCheckout</name>
133
+ </action>
134
+ </block>
135
+ </reference>
136
+ </opc_index_index>
137
+
138
+ <gomage_checkout_onepage_index>
139
+ <reference name="head">
140
+ <block type="core/text" name="external_js">
141
+ <action method="setText"><text><![CDATA[<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>]]> </text> </action>
142
+ </block>
143
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
144
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
145
+ </reference>
146
+ <reference name="before_body_end">
147
+ <block type="core/template" name="ewayrapid.js" after="-">
148
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
149
+ <template>ewayrapid/js.phtml</template>
150
+ </action>
151
+ <action method="setCheckoutExtension">
152
+ <name>LightCheckout</name>
153
+ </action>
154
+ </block>
155
+ </reference>
156
+ </gomage_checkout_onepage_index>
157
+
158
+ <hanlder_transparent_layout_empty>
159
+ <update handle="default"/>
160
+ <reference name="root">
161
+ <action method="setTemplate">
162
+ <template>page/empty.phtml</template>
163
+ </action>
164
+ </reference>
165
+ </hanlder_transparent_layout_empty>
166
+
167
+ <hanlder_transparent_layout>
168
+ <update handle="default"/>
169
+ <reference name="head">
170
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
171
+ </reference>
172
+ <reference name="root">
173
+ <action method="setTemplate">
174
+ <template>page/1column.phtml</template>
175
+ </action>
176
+ </reference>
177
+ </hanlder_transparent_layout>
178
+
179
+ <ewayrapid_transparent_paynow>
180
+ <update handle="hanlder_transparent_layout_empty"/>
181
+ <reference name="content">
182
+ <block type="ewayrapid/redirect_transparent" name="transparent.block.paynow"/>
183
+ </reference>
184
+ </ewayrapid_transparent_paynow>
185
+
186
+ <ewayrapid_transparent_redirect>
187
+ <update handle="hanlder_transparent_layout_empty"/>
188
+ <reference name="content">
189
+ <block type="ewayrapid/redirect_transparentCheckout" name="transparent.block.checkout"/>
190
+ </reference>
191
+ </ewayrapid_transparent_redirect>
192
+
193
+ <ewayrapid_handle_review>
194
+ <label>Eway Paypal Order Review Form</label>
195
+ <remove name="right"/>
196
+ <remove name="left"/>
197
+
198
+ <reference name="root">
199
+ <action method="setTemplate">
200
+ <template>page/1column.phtml</template>
201
+ </action>
202
+ </reference>
203
+ <reference name="content">
204
+ <block type="ewayrapid/redirect_paypalReview" name="eway.block.review">
205
+ </block>
206
+ </reference>
207
+ </ewayrapid_handle_review>
208
+
209
+ <ewayrapid_transparent_review>
210
+ <update handle="ewayrapid_handle_review"/>
211
+ </ewayrapid_transparent_review>
212
+
213
+ <ewayrapid_sharedpage_review>
214
+ <update handle="ewayrapid_handle_review"/>
215
+ </ewayrapid_sharedpage_review>
216
  </layout>
app/design/frontend/base/default/template/ewayrapid/customer/edit.phtml CHANGED
@@ -1,706 +1,706 @@
1
- <?php
2
- $_token = $this->getCurrentToken();
3
- $_address = $this->getCustomerAddress();
4
-
5
- // Form Url
6
- $connectionType = Mage::getStoreConfig('payment/ewayrapid_general/connection_type');
7
- $formUrl = $this->getSaveUrl();
8
- $transparent = false;
9
- $iframe = false;
10
- $submitFunction = '';
11
- switch ($connectionType) {
12
- case Eway_Rapid31_Model_Config::CONNECTION_DIRECT:
13
- echo '<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>';
14
- break;
15
- case Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT:
16
- $transparent = true;
17
- $submitFunction = 'beforeSubmit';
18
- break;
19
- case Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE:
20
- $formUrl = Mage::getBaseUrl() . '/ewayrapid/mycards/getAccessCode';
21
- break;
22
- case Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME:
23
- $formUrl = Mage::getBaseUrl() . '/ewayrapid/mycards/getAccessCode';
24
- $iframe = true;
25
- $submitFunction = 'beforeSubmitIframe';
26
- break;
27
- default:
28
- break;
29
- }
30
- ?>
31
- <?php if ($this->getTitle()): ?>
32
- <div class="page-title">
33
- <h1><?php echo $this->getTitle() ?></h1>
34
- </div>
35
- <?php endif; ?>
36
- <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
37
- <div class="tool-tip" id="payment-tool-tip" style="display:none;">
38
- <div class="btn-close"><a href="#" id="payment-tool-tip-close"
39
- title="<?php echo $this->__('Close') ?>"><?php echo $this->__('Close') ?></a></div>
40
- <div class="tool-tip-content"><img src="<?php echo $this->getSkinUrl('images/cvv.gif') ?>"
41
- alt="<?php echo $this->__('Card Verification Number Visual Reference') ?>"
42
- title="<?php echo $this->__('Card Verification Number Visual Reference') ?>"/>
43
- </div>
44
- </div>
45
- <form action="<?php echo $formUrl ?>" method="post" id="form-validate">
46
- <input type="hidden" name="EWAY_ACCESSCODE" id="eway_accesscode"/>
47
- <?php
48
- if ($_token->getTokenId()) {
49
- ?>
50
- <input type="hidden" name="token_id" value="<?php echo $_token->getTokenId() ?>"/>
51
- <input type="hidden" name="TokenCustomerID" value="<?php echo $_token->getToken() ?>"/>
52
- <?php } ?>
53
-
54
- <!-- Card info -->
55
- <?php
56
- if ($connectionType !== Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE && $connectionType !== Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME) {
57
- ?>
58
- <div class="fieldset">
59
- <?php echo $this->getBlockHtml('formkey') ?>
60
- <h2 class="legend"><?php echo $this->__('Credit Card Information') ?></h2>
61
-
62
- <div class="sp-methods">
63
- <ul class="form-list">
64
- <li>
65
- <div class="input-box">
66
- <label for="ewayrapid_saved_cc_owner"
67
- class="required"><em>*</em><?php echo $this->__('Name on Card') ?></label>
68
- <input type="text" title="<?php echo $this->__('Name on Card') ?>"
69
- class="input-text required-entry validate-length maximum-length-50"
70
- id="ewayrapid_saved_cc_owner"
71
- name="payment[cc_owner]" value="<?php echo $this->escapeHtml($_token->getOwner()) ?>"
72
- __maxlength="50" autocomplete="off"/>
73
- </div>
74
- </li>
75
- <li>
76
- <label for="ewayrapid_saved_cc_number"
77
- class="required"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
78
-
79
- <div class="input-box help-disabled-cc">
80
- <input type="text" id="ewayrapid_saved_cc_number" data-eway-encrypt-name="payment[cc_number]"
81
- title="<?php echo $this->__('Credit Card Number') ?>"
82
- class="input-text <?php if (!$this->isEdit()): ?>validate-cc-number validate-cc-type-auto<?php endif; ?>"
83
- autocomplete="off" <?php if ($this->isEdit()): ?>value="<?php echo $_token->getCard() ?>"
84
- disabled="disabled" <?php endif; ?> pattern="\d*"/>
85
- <input type="hidden" id="ewayrapid_saved_cc_type" name="payment[cc_type]"
86
- value="<?php echo $_token->getType() ?>"/>
87
- <?php if ($this->isEdit()): ?>
88
- <input type="hidden" name="EWAY_CARDNUMBER" value="444433XXXXXX1111"/>
89
- <a href="#"><?php echo $this->__('Help') ?></a>
90
- <div class="tool-tip" id="cc-help-tool-tip" style="display:none;">
91
- <div class="btn-close">
92
- <a href="#" id="cc-help-tool-tip-close"
93
- title="<?php echo $this->__('Close') ?>"><?php echo $this->__('Close') ?></a>
94
- </div>
95
- <div class="tool-tip-content">To use a new credit card number, please add another card
96
- </div>
97
- </div>
98
- <?php endif; ?>
99
- </div>
100
- </li>
101
-
102
- <li id="ewayrapid_saved_cc_type_exp_div">
103
- <label for="ewayrapid_saved_expiration"
104
- class="required"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
105
-
106
- <div class="input-box">
107
- <div class="v-fix">
108
- <select id="ewayrapid_saved_expiration" name="payment[cc_exp_month]"
109
- class="month validate-cc-exp required-entry" autocomplete="off">
110
- <?php $_ccExpMonth = $_token->getExpMonth() ?>
111
- <?php foreach ($this->getCcMonths() as $k => $v): ?>
112
- <option
113
- value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
114
- <?php endforeach ?>
115
- </select>
116
- </div>
117
- <div class="v-fix">
118
- <?php $_ccExpYear = $_token->getExpYear() ?>
119
- <select id="ewayrapid_saved_expiration_yr" name="payment[cc_exp_year]"
120
- class="year required-entry" autocomplete="off">
121
- <?php foreach ($this->getCcYears() as $k => $v): ?>
122
- <option
123
- value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
124
- <?php endforeach ?>
125
- </select>
126
- </div>
127
- </div>
128
- </li>
129
-
130
- <?php
131
- if ($transparent) {
132
- ?>
133
- <li class="value_from_date">
134
- <label for="ewayrapid_saved_start_month"
135
- class="required"><?php echo $this->__('Valid From Date') ?></label>
136
-
137
- <div class="input-box">
138
- <div class="v-fix">
139
- <select id="ewayrapid_saved_start_month" name="payment[cc_start_month]"
140
- class="month" autocomplete="off">
141
- <?php $_ccStartMonth = $_token->getStartMonth() ?>
142
- <?php foreach ($this->getCcMonths() as $k => $v): ?>
143
- <option value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccStartMonth): ?>
144
- selected="selected"<?php endif ?>><?php echo $v ?></option>
145
- <?php endforeach ?>
146
- </select>
147
- </div>
148
- <div class="v-fix">
149
- <?php $_ccStartYear = $_token->getStartYear() ?>
150
- <select id="ewayrapid_saved_start_year" name="payment[cc_start_year]"
151
- class="year" autocomplete="off">
152
- <?php
153
- $start_year = 0;
154
- $inc = 0;
155
- foreach ($this->getCcYears() as $k => $v) {
156
- if ($inc == 1) {
157
- $start_year = (int)$k;
158
- break;
159
- }
160
- echo "<option value=''>Year</option>";
161
- $inc++;
162
- }
163
-
164
- for ($i = 10; $i > 0; $i--) {
165
- ?>
166
- <option value="<?php echo $start_year - $i ?>"
167
- <?php if (($start_year - $i) == $_ccStartYear) { ?>
168
- selected="selected"<?php } ?>>
169
- <?php echo $start_year - $i ?>
170
- </option>
171
- <?php
172
- }
173
-
174
- $inc = 0;
175
- foreach ($this->getCcYears() as $k => $v):
176
- $inc++;
177
- if ($inc == 1) {
178
- continue;
179
- }
180
- ?>
181
- <option value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccStartYear): ?>
182
- selected="selected"<?php endif ?>><?php echo $v ?></option>
183
- <?php
184
- endforeach;
185
- ?>
186
- </select>
187
- </div>
188
- </div>
189
- </li>
190
- <li>
191
- <div class="input-box">
192
- <label for="ewayrapid_saved_issue_number">
193
- <?php echo $this->__('Issue Number') ?>
194
- </label>
195
- <input type="text" title="<?php echo $this->__('Issue Number') ?>"
196
- class="input-text validate-length maximum-length-4"
197
- id="ewayrapid_saved_issue_number"
198
- name="payment[cc_issue_number]"
199
- value="<?php echo $this->escapeHtml($_token->getIssueNumber()) ?>"
200
- __maxlength="50" autocomplete="off"/>
201
- </div>
202
- </li>
203
- <?php
204
- }
205
- ?>
206
-
207
- <?php if ($this->hasVerification()): ?>
208
- <li id="ewayrapid_saved_cc_type_cvv_div">
209
- <label for="ewayrapid_saved_cc_cid"
210
- class="required"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
211
-
212
- <div class="input-box">
213
- <div class="v-fix">
214
- <input type="text" title="<?php echo $this->__('Card Verification Number') ?>"
215
- class="input-text cvv required-entry validate-cc-cvn" id="ewayrapid_saved_cc_cid"
216
- data-eway-encrypt-name="payment[cc_cid]" value="" autocomplete="off"
217
- pattern="\d*"/>
218
- </div>
219
- <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
220
- </div>
221
- </li>
222
- <?php endif; ?>
223
- <?php
224
- $_defaultToken = Mage::helper('ewayrapid/customer')->getDefaultToken();
225
- if (!$_token->getToken() || ($_defaultToken && $_defaultToken != $_token->getTokenId())): ?>
226
- <li>
227
- <div class="v-fix" style="padding-right: 5px;">
228
- <input type="checkbox" id="ewayrapid_saved_default" name="is_default"/>
229
- </div>
230
- <label for="ewayrapid_saved_default"><?php echo $this->__('Default Credit Card') ?></label>
231
- </li>
232
- <?php endif; ?>
233
- </ul>
234
- </div>
235
- </div>
236
- <?php
237
- } else {
238
- // Responsive shared page card data
239
- // ....
240
- $_defaultToken = Mage::helper('ewayrapid/customer')->getDefaultToken();
241
- if (!$_token->getToken() || ($_defaultToken && $_defaultToken != $_token->getTokenId())): ?>
242
- <ul>
243
- <li>
244
- <div class="v-fix" style="padding-right: 5px;">
245
- <input type="checkbox" id="ewayrapid_saved_default" name="is_default"/>
246
- </div>
247
- <label for="ewayrapid_saved_default"><?php echo $this->__('Default Credit Card') ?></label>
248
- </li>
249
- </ul>
250
- <?php endif;
251
- } ?>
252
- <div class="fieldset bill-address">
253
- <h2 class="legend"><?php echo $this->__('Billing Address') ?></h2>
254
- <ul class="form-list">
255
- <li class="fields">
256
- <div class="customer-name-prefix">
257
- <div class="field name-prefix">
258
- <label for="address_prefix"><?php echo $this->__('Title') ?></label>
259
-
260
- <div class="input-box">
261
- <select id="address_prefix" name="address[prefix]" title="<?php echo $this->__('Title') ?>">
262
- <?php foreach ($this->getPrefixOptions() as $_option): ?>
263
- <option
264
- value="<?php echo $_option ?>"<?php if ($_address->getTitle() == $_option): ?>
265
- selected="selected"<?php endif; ?>><?php echo $this->__($_option) ?></option>
266
- <?php endforeach; ?>
267
- </select>
268
- </div>
269
- </div>
270
- <div class="field name-firstname">
271
- <label for="address_firstname" class="required"><em>*</em><?php echo $this->__('First Name') ?>
272
- </label>
273
-
274
- <div class="input-box">
275
- <input type="text" id="address_firstname" name="address[firstname]"
276
- value="<?php echo $this->escapeHtml($_address->getFirstName()) ?>"
277
- title="<?php echo $this->__('First Name') ?>"
278
- __maxlength="50" class="input-text required-entry validate-length maximum-length-50"/>
279
- </div>
280
- </div>
281
- <div class="field name-lastname">
282
- <label for="address_lastname" class="required"><em>*</em><?php echo $this->__('Last Name') ?>
283
- </label>
284
-
285
- <div class="input-box">
286
- <input type="text" id="address_lastname" name="address[lastname]"
287
- value="<?php echo $this->escapeHtml($_address->getLastName()) ?>"
288
- title="<?php echo $this->__('Last Name') ?>" __maxlength="50"
289
- class="input-text required-entry validate-length maximum-length-50"/>
290
- </div>
291
- </div>
292
- </div>
293
- </li>
294
- <li class="fields">
295
- <div class="field">
296
- <label for="address_company"><?php echo $this->__('Company') ?></label>
297
-
298
- <div class="input-box">
299
- <input type="text" name="address[company]" id="address_company"
300
- title="<?php echo $this->__('Company') ?>" __maxlength="50"
301
- value="<?php echo $this->escapeHtml($_address->getCompanyName()) ?>"
302
- class="input-text validate-length maximum-length-50"/>
303
- </div>
304
- </div>
305
- <div class="field">
306
- <label for="address_job_description"><?php echo $this->__('Job Description') ?></label>
307
-
308
- <div class="input-box">
309
- <input type="text" name="address[job_description]" id="address_job_description"
310
- title="<?php echo $this->__('Job Description') ?>" __maxlength="50"
311
- value="<?php echo $this->escapeHtml($_address->getJobDescription()) ?>"
312
- class="input-text validate-length maximum-length-50"/>
313
- </div>
314
- </div>
315
-
316
- </li>
317
- <li class="fields">
318
- <div class="field">
319
- <label for="address_telephone" class="required"><em>*</em><?php echo $this->__('Phone') ?></label>
320
-
321
- <div class="input-box">
322
- <input type="text" name="address[telephone]"
323
- value="<?php echo $this->escapeHtml($_address->getPhone()) ?>"
324
- title="<?php echo $this->__('Phone') ?>"
325
- class="input-text required-entry eway-validate-phone validate-length maximum-length-32"
326
- id="address_telephone" __maxlength="32"/>
327
- </div>
328
- </div>
329
- <div class="field">
330
- <label for="address_mobile"><?php echo $this->__('Mobile') ?></label>
331
-
332
- <div class="input-box">
333
- <input type="text" name="address[mobile]"
334
- value="<?php echo $this->escapeHtml($_address->getMobile()) ?>"
335
- title="<?php echo $this->__('Mobile') ?>"
336
- class="input-text eway-validate-phone validate-length maximum-length-32"
337
- id="address_mobile" __maxlength="32"/>
338
- </div>
339
- </div>
340
- </li>
341
- <li class="fields">
342
- <div class="field">
343
- <label for="address_email"><?php echo $this->__('Email') ?></label>
344
-
345
- <div class="input-box">
346
- <input type="text" name="address[email]" id="address_email" __maxlength="50"
347
- title="<?php echo $this->__('Email') ?>"
348
- value="<?php echo $this->escapeHtml($_address->getEmail()) ?>"
349
- class="input-text validate-email validate-length maximum-length-50"/>
350
- </div>
351
- </div>
352
- <div class="field">
353
- <label for="address_fax"><?php echo $this->__('Fax') ?></label>
354
-
355
- <div class="input-box">
356
- <input type="text" name="address[fax]" id="address_fax" title="<?php echo $this->__('Fax') ?>"
357
- value="<?php echo $this->escapeHtml($_address->getFax()) ?>"
358
- class="input-text eway-validate-phone validate-length maximum-length-32" __maxlength="32"/>
359
- </div>
360
- </div>
361
- </li>
362
- <li class="wide">
363
- <label for="address_street_1" class="required"><em>*</em><?php echo $this->__('Street Address') ?></label>
364
-
365
- <div class="input-box">
366
- <input type="text" name="address[street][]" __maxlength="50"
367
- value="<?php echo $this->escapeHtml($_address->getStreet1()) ?>"
368
- title="<?php echo $this->__('Street Address') ?>" id="address_street_1"
369
- class="input-text required-entry validate-length maximum-length-50"/>
370
- </div>
371
- </li>
372
- <li class="wide">
373
- <div class="input-box">
374
- <input type="text" name="address[street][]" __maxlength="50"
375
- value="<?php echo $this->escapeHtml($_address->getStreet2()) ?>"
376
- title="<?php echo $this->__('Street Address') ?>" id="address_street_2"
377
- class="input-text validate-length maximum-length-50"/>
378
- </div>
379
- </li>
380
- <li class="fields">
381
- <div class="field">
382
- <label for="address_city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
383
-
384
- <div class="input-box">
385
- <input type="text" name="address[city]" __maxlength="50"
386
- value="<?php echo $_address->getCity() ?>" title="<?php echo $this->__('City') ?>"
387
- class="input-text required-entry validate-length maximum-length-50" id="address_city"/>
388
- </div>
389
- </div>
390
- <div class="field">
391
- <label for="address_region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?>
392
- </label>
393
-
394
- <div class="input-box">
395
- <select id="address_region_id" name="address[region_id]"
396
- title="<?php echo $this->__('State/Province') ?>" class="validate-select"
397
- style="display:none;">
398
- <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
399
- </select>
400
- <script type="text/javascript">
401
- //<![CDATA[
402
- $('address_region_id').setAttribute('defaultValue', "<?php echo $_address->getRegionId() ?>");
403
- //]]>
404
- </script>
405
- <input type="text" id="address_region" name="address[region]" __maxlength="50"
406
- value="<?php echo $this->escapeHtml($_address->getState()) ?>"
407
- title="<?php echo $this->__('State/Province') ?>"
408
- class="input-text validate-length maximum-length-50"/>
409
- </div>
410
- </div>
411
- </li>
412
- <li class="fields">
413
- <div class="field">
414
- <label for="address_zip" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
415
-
416
- <div class="input-box">
417
- <input type="text" name="address[postcode]"
418
- value="<?php echo $this->escapeHtml($_address->getPostalCode()) ?>"
419
- title="<?php echo $this->__('Zip/Postal Code') ?>" id="address_zip"
420
- class="input-text validate-zip-international required-entry validate-length maximum-length-30"
421
- __maxlength="30"/>
422
- </div>
423
- </div>
424
- <div class="field">
425
- <label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
426
-
427
- <div class="input-box">
428
- <?php echo $this->getCountryHtmlSelect(strtoupper($_address->getCountry()), 'address[country_id]', 'address_country') ?>
429
- </div>
430
- </div>
431
- </li>
432
- </ul>
433
- </div>
434
- <div class="buttons-set">
435
- <p class="required"><?php echo $this->__('* Required Fields') ?></p>
436
-
437
- <p class="back-link"><a href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>">
438
- <small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
439
- <?php
440
- echo $transparent || $iframe ? '<button type="button" onclick="'.$submitFunction.'(this)" title="'
441
- . $this->__('Save Credit Card') . '" class="button"><span><span>'
442
- . $this->__('Save Credit Card') . '</span></span></button>'
443
- . '<span id="save-please-wait" class="please-wait" style="display:none;">
444
- <img class="v-middle" title="Loading..." alt="Loading..." src="'
445
- . Mage::getBaseUrl() . '/skin/frontend/rwd/default/images/opc-ajax-loader.gif">
446
- Please waiting ...
447
- </span>'
448
- : '<button type="submit" title="' . $this->__('Save Credit Card') . '" class="button"><span><span>' . $this->__('Save Credit Card') . '</span></span></button>';
449
- ?>
450
-
451
- </div>
452
- </form>
453
-
454
- <script type="text/javascript">
455
- //<![CDATA[
456
- var dataForm = new VarienForm('form-validate', true);
457
- new RegionUpdater('address_country', 'address_region', 'address_region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'address_zip');
458
- EwayPayment.supportCardTypes = <?php echo json_encode(Mage::getSingleton('ewayrapid/config')->getSupportedCardTypes()) ?>;
459
-
460
- $$('.cvv-what-is-this').each(function (element) {
461
- Event.observe(element, 'click', toggleToolTip);
462
- });
463
-
464
- function toggleToolTip(event) {
465
- if ($('payment-tool-tip')) {
466
- $('payment-tool-tip').setStyle({
467
- top: (Event.pointerY(event) - 200) + 'px'//,
468
- })
469
- $('payment-tool-tip').toggle();
470
- }
471
- Event.stop(event);
472
- }
473
- if ($('payment-tool-tip-close')) {
474
- Event.observe($('payment-tool-tip-close'), 'click', toggleToolTip);
475
- }
476
-
477
- $('form-validate').onsubmit = function () {
478
- return (dataForm.validator && dataForm.validator.validate());
479
- }
480
- var ewayPayment = new EwayPayment($('form-validate'), '<?php echo Mage::getSingleton('ewayrapid/config')->getEncryptionKey() ?>');
481
-
482
- $$('.help-disabled-cc a').each(function (element) {
483
- Event.observe(element, 'click', toggleToolTipCc);
484
- });
485
-
486
- function toggleToolTipCc(event) {
487
- if ($('cc-help-tool-tip')) {
488
- $('cc-help-tool-tip').toggle();
489
- }
490
- Event.stop(event);
491
- }
492
- if ($('cc-help-tool-tip-close')) {
493
- Event.observe($('cc-help-tool-tip-close'), 'click', toggleToolTipCc);
494
- }
495
-
496
- // TRANSPARENT REDIRECT
497
- function beforeSubmit(obj) {
498
- $('validate_from_date_message') != null ? $('validate_from_date_message').remove() : '';
499
- $('ewayrapid_saved_start_month').removeClassName('validation-failed');
500
- $('ewayrapid_saved_start_year').removeClassName('validation-failed');
501
- $$('li.value_from_date')[0].removeClassName('validation-error');
502
-
503
- if (typeof isTest !== 'undefined') {
504
- // Alert error code ERR-012
505
- alert('An error occurred while connecting to payment gateway. Please try again later.!');
506
- return false;
507
- }
508
-
509
- //*********************************Valid From Date If Select********************************************************************
510
- if($('ewayrapid_saved_start_year').value > 0 && $('ewayrapid_saved_start_month').value <= 0) {
511
- $('validation-advice-year') && $('validation-advice-year').remove();
512
- $('ewayrapid_saved_start_month').addClassName('validation-failed');
513
- $('ewayrapid_saved_start_month').up('div').insert('<div class="validation-advice" id="validation-advice-month">Incorrect credit card from date.</div>');
514
- return;
515
- } else if($('ewayrapid_saved_start_year').value <= 0 && $('ewayrapid_saved_start_month').value > 0) {
516
- $('validation-advice-month') && $('validation-advice-month').remove();
517
- $('ewayrapid_saved_start_year').addClassName('validation-failed');
518
- $('ewayrapid_saved_start_year').up('div').insert('<div class="validation-advice" id="validation-advice-year">Incorrect credit card from year.</div>');
519
- return;
520
- } else {
521
- $('validation-advice-year') && $('validation-advice-year').remove();
522
- $('validation-advice-month') && $('validation-advice-month').remove();
523
- }
524
-
525
- var from_date = new Date($('ewayrapid_saved_start_year').value + '-' + $('ewayrapid_saved_start_month').value).getTime();
526
- var expiration_date = new Date($('ewayrapid_saved_expiration_yr').value + '-' + $('ewayrapid_saved_expiration').value).getTime();
527
- if(Prototype.Browser.IE) {
528
- from_date = new Date($('ewayrapid_saved_start_year').value, $('ewayrapid_saved_start_month').value, 1).getTime();
529
- expiration_date = new Date($('ewayrapid_saved_expiration_yr').value, $('ewayrapid_saved_expiration').value, 1).getTime();
530
- }
531
- //console.log(from_date - expiration_date);
532
-
533
- if(from_date - expiration_date > 0) {
534
- $$('li.value_from_date')[0].insert({after: '<div style="" id="validate_from_date_message" ' +
535
- 'class="validation-advice">From Date is invalid. It must be earlier than Expiration Date.</div>'});
536
- $('ewayrapid_saved_start_month').addClassName('validation-failed');
537
- $('ewayrapid_saved_start_year').addClassName('validation-failed');
538
- $$('li.value_from_date')[0].addClassName('validation-error');
539
- return;
540
- }
541
- //******************************************************************************************************************************
542
-
543
- var validate = dataForm.validator.validate();
544
- if (!validate) {
545
- return;
546
- }
547
-
548
- /*if ($('ewayrapid_saved_start_year').value != '' || $('ewayrapid_saved_start_month').value != '') {
549
- if ((new Date($('ewayrapid_saved_expiration_yr').value + '-'
550
- + ($('ewayrapid_saved_expiration').value <= 9 ? '0' : '') + $('ewayrapid_saved_expiration').value).getTime() )
551
- - ( new Date($('ewayrapid_saved_start_year').value + '-'
552
- + ($('ewayrapid_saved_start_month').value <= 9 ? '0' : '') + $('ewayrapid_saved_start_month').value).getTime() )
553
- <= 0 ) {
554
- $$('li.value_from_date')[0].insert({after: '<div style="" id="validate_from_date_message" ' +
555
- 'class="validation-advice">From Date is invalid. It must be earlier than Expiration Date.</div>'});
556
- $('ewayrapid_saved_start_month').addClassName('validation-failed');
557
- $('ewayrapid_saved_start_year').addClassName('validation-failed');
558
- $$('li.value_from_date')[0].addClassName('validation-error');
559
- return;
560
- }
561
- }*/
562
-
563
- // Waiting
564
- $(obj).setStyle({'display': 'none'});
565
- $('save-please-wait').setStyle({'display': 'block'});
566
-
567
- // Get access code
568
- new Ajax.Request('<?php echo Mage::getBaseUrl() ?>/ewayrapid/mycards/getAccessCode',
569
- {
570
- method: 'post',
571
- parameters: $('form-validate').serialize(true),
572
- onSuccess: function (transport) {
573
- if (transport.responseText) {
574
- var data = JSON.parse(transport.responseText);
575
- if (typeof data == 'object') {
576
-
577
- // Check login require
578
- if (data.login != undefined) {
579
- alert('Session has expired');
580
- window.location = window.location.href;
581
- }
582
-
583
- if (typeof data.AccessCode != 'undefined' & data.AccessCode != null) {
584
-
585
- var actionUrl = data.FormActionURL;
586
- $('form-validate').setAttribute('action', actionUrl);
587
- // Change card info
588
- $('ewayrapid_saved_cc_owner').setAttribute('name', 'EWAY_CARDNAME');
589
- <?php
590
- // Change card name if not edited
591
- if (!$this->isEdit()) {
592
- echo "$('ewayrapid_saved_cc_number').setAttribute('name', 'EWAY_CARDNUMBER');";
593
- }
594
- ?>
595
- $('ewayrapid_saved_expiration').setAttribute('name', 'EWAY_CARDEXPIRYMONTH');
596
- $('ewayrapid_saved_expiration_yr').setAttribute('name', 'EWAY_CARDEXPIRYYEAR');
597
-
598
- $('eway_accesscode').setValue(data.AccessCode);
599
- $('form-validate').submit();
600
- return;
601
- }
602
- else {
603
- // Alert error code ERR-012
604
- alert('An error occurred while connecting to payment gateway. Please try again later.!');
605
- }
606
- } else {
607
- alert(transport.responseText)
608
- }
609
-
610
- // Remove style waiting
611
- $(obj).setStyle({'display': 'block'});
612
- $('save-please-wait').setStyle({'display': 'none'});
613
- }
614
- },
615
- onFailure: function () {
616
- alert('Something went wrong...')
617
- }
618
- });
619
- return false;
620
- }
621
-
622
- // Iframe
623
-
624
- ewayReturnUrl = '';
625
-
626
- function eWayRapidCallback (result, transactionID, errors) {
627
- if (result == "Complete") {
628
- setLocation(ewayReturnUrl);
629
- } else if (result == "Error") {
630
- alert("There was a problem while connecting to payment gateway: " + errors);
631
- dataForm.form.down('button').setStyle({'display': 'block'});
632
- $('save-please-wait').setStyle({'display': 'none'});
633
- } else{
634
- dataForm.form.down('button').setStyle({'display': 'block'});
635
- $('save-please-wait').setStyle({'display': 'none'});
636
- }
637
- }
638
-
639
- function beforeSubmitIframe(obj) {
640
- $('validate_from_date_message') != null ? $('validate_from_date_message').remove() : '';
641
-
642
- if (typeof isTest !== 'undefined') {
643
- // Alert error code ERR-012
644
- alert('An error occurred while connecting to payment gateway. Please try again later.!');
645
- return false;
646
- }
647
-
648
- var validate = dataForm.validator.validate();
649
- if (!validate) {
650
- return;
651
- }
652
-
653
- // Waiting
654
- $(obj).setStyle({'display': 'none'});
655
- $('save-please-wait').setStyle({'display': 'block'});
656
-
657
- // Get access code
658
- new Ajax.Request('<?php echo Mage::getBaseUrl() ?>/ewayrapid/mycards/getAccessCode',
659
- {
660
- method: 'post',
661
- parameters: $('form-validate').serialize(true),
662
- onSuccess: function (transport) {
663
- if (transport.responseText) {
664
- var data = JSON.parse(transport.responseText);
665
- if (typeof data == 'object') {
666
-
667
- // Check login require
668
- if (data.login != undefined) {
669
- alert('Session has expired');
670
- window.location = window.location.href;
671
- }
672
-
673
- if (typeof data.SharedPaymentUrl != 'undefined' & data.SharedPaymentUrl != null) {
674
-
675
- var eWAYConfig = {
676
- sharedPaymentUrl: data.SharedPaymentUrl
677
- };
678
-
679
- ewayReturnUrl = data.ReturnUrl;
680
-
681
- eCrypt.showModalPayment(eWAYConfig, eWayRapidCallback);
682
-
683
- return;
684
- }
685
- else {
686
- // Alert error code ERR-012
687
- alert('An error occurred while connecting to payment gateway. Please try again later.!');
688
- }
689
- } else {
690
- alert(transport.responseText)
691
- }
692
-
693
- // Remove style waiting
694
- $(obj).setStyle({'display': 'block'});
695
- $('save-please-wait').setStyle({'display': 'none'});
696
- }
697
- },
698
- onFailure: function () {
699
- alert('Something went wrong...')
700
- }
701
- });
702
- return false;
703
- }
704
-
705
- //]]>
706
- </script>
1
+ <?php
2
+ $_token = $this->getCurrentToken();
3
+ $_address = $this->getCustomerAddress();
4
+
5
+ // Form Url
6
+ $connectionType = Mage::getStoreConfig('payment/ewayrapid_general/connection_type');
7
+ $formUrl = $this->getSaveUrl();
8
+ $transparent = false;
9
+ $iframe = false;
10
+ $submitFunction = '';
11
+ switch ($connectionType) {
12
+ case Eway_Rapid31_Model_Config::CONNECTION_DIRECT:
13
+ echo '<script type="text/javascript" src="https://secure.ewaypayments.com/scripts/eCrypt.js"></script>';
14
+ break;
15
+ case Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT:
16
+ $transparent = true;
17
+ $submitFunction = 'beforeSubmit';
18
+ break;
19
+ case Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE:
20
+ $formUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . '/ewayrapid/mycards/getAccessCode';
21
+ break;
22
+ case Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME:
23
+ $formUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true) . '/ewayrapid/mycards/getAccessCode';
24
+ $iframe = true;
25
+ $submitFunction = 'beforeSubmitIframe';
26
+ break;
27
+ default:
28
+ break;
29
+ }
30
+ ?>
31
+ <?php if ($this->getTitle()): ?>
32
+ <div class="page-title">
33
+ <h1><?php echo $this->getTitle() ?></h1>
34
+ </div>
35
+ <?php endif; ?>
36
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
37
+ <div class="tool-tip" id="payment-tool-tip" style="display:none;">
38
+ <div class="btn-close"><a href="#" id="payment-tool-tip-close"
39
+ title="<?php echo $this->__('Close') ?>"><?php echo $this->__('Close') ?></a></div>
40
+ <div class="tool-tip-content"><img src="<?php echo $this->getSkinUrl('images/cvv.gif') ?>"
41
+ alt="<?php echo $this->__('Card Verification Number Visual Reference') ?>"
42
+ title="<?php echo $this->__('Card Verification Number Visual Reference') ?>"/>
43
+ </div>
44
+ </div>
45
+ <form action="<?php echo $formUrl ?>" method="post" id="form-validate">
46
+ <input type="hidden" name="EWAY_ACCESSCODE" id="eway_accesscode"/>
47
+ <?php
48
+ if ($_token->getTokenId()) {
49
+ ?>
50
+ <input type="hidden" name="token_id" value="<?php echo $_token->getTokenId() ?>"/>
51
+ <input type="hidden" name="TokenCustomerID" value="<?php echo $_token->getToken() ?>"/>
52
+ <?php } ?>
53
+
54
+ <!-- Card info -->
55
+ <?php
56
+ if ($connectionType !== Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE && $connectionType !== Eway_Rapid31_Model_Config::CONNECTION_RAPID_IFRAME) {
57
+ ?>
58
+ <div class="fieldset">
59
+ <?php echo $this->getBlockHtml('formkey') ?>
60
+ <h2 class="legend"><?php echo $this->__('Credit Card Information') ?></h2>
61
+
62
+ <div class="sp-methods">
63
+ <ul class="form-list">
64
+ <li>
65
+ <div class="input-box">
66
+ <label for="ewayrapid_saved_cc_owner"
67
+ class="required"><em>*</em><?php echo $this->__('Name on Card') ?></label>
68
+ <input type="text" title="<?php echo $this->__('Name on Card') ?>"
69
+ class="input-text required-entry validate-length maximum-length-50"
70
+ id="ewayrapid_saved_cc_owner"
71
+ name="payment[cc_owner]" value="<?php echo $this->escapeHtml($_token->getOwner()) ?>"
72
+ __maxlength="50" autocomplete="off"/>
73
+ </div>
74
+ </li>
75
+ <li>
76
+ <label for="ewayrapid_saved_cc_number"
77
+ class="required"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
78
+
79
+ <div class="input-box help-disabled-cc">
80
+ <input type="text" id="ewayrapid_saved_cc_number" data-eway-encrypt-name="payment[cc_number]"
81
+ title="<?php echo $this->__('Credit Card Number') ?>"
82
+ class="input-text <?php if (!$this->isEdit()): ?>validate-cc-number validate-cc-type-auto<?php endif; ?>"
83
+ autocomplete="off" <?php if ($this->isEdit()): ?>value="<?php echo $_token->getCard() ?>"
84
+ disabled="disabled" <?php endif; ?> pattern="\d*"/>
85
+ <input type="hidden" id="ewayrapid_saved_cc_type" name="payment[cc_type]"
86
+ value="<?php echo $_token->getType() ?>"/>
87
+ <?php if ($this->isEdit()): ?>
88
+ <input type="hidden" name="EWAY_CARDNUMBER" value="444433XXXXXX1111"/>
89
+ <a href="#"><?php echo $this->__('Help') ?></a>
90
+ <div class="tool-tip" id="cc-help-tool-tip" style="display:none;">
91
+ <div class="btn-close">
92
+ <a href="#" id="cc-help-tool-tip-close"
93
+