eWAY_Payment_Rapid31 - Version 1.1.0

Version Notes

First full release of eWAY's Rapid 3.1 payment module. Process credit card payments with eWAY. Features:

- Supports three connection types: Direct Connection, Transparent Redirect and Responsive Shared Page
- Authorise and Capture or Authorise payments
- Full and parial refunds
- Use MasterPass and PayPal through eWAY, track your transactions in one place
- Securely store customer's card details as tokens with eWAY
- Integrated with eWAY's Beagle anti-fraud
- Use eWAY's Live or Sandbox gateway

Download this release

Release Info

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


Version 1.1.0

Files changed (101) hide show
  1. app/code/community/Eway/Rapid31/Block/Customer/Edit.php +118 -0
  2. app/code/community/Eway/Rapid31/Block/Customer/Mycards.php +23 -0
  3. app/code/community/Eway/Rapid31/Block/Form/Direct/Notsaved.php +9 -0
  4. app/code/community/Eway/Rapid31/Block/Form/Direct/Saved.php +41 -0
  5. app/code/community/Eway/Rapid31/Block/Form/Sharedpage/Notsaved.php +9 -0
  6. app/code/community/Eway/Rapid31/Block/Form/Sharedpage/Saved.php +33 -0
  7. app/code/community/Eway/Rapid31/Block/Form/Transparent/Notsaved.php +37 -0
  8. app/code/community/Eway/Rapid31/Block/Form/Transparent/Saved.php +68 -0
  9. app/code/community/Eway/Rapid31/Block/Info/Direct/Notsaved.php +26 -0
  10. app/code/community/Eway/Rapid31/Block/Info/Direct/Saved.php +45 -0
  11. app/code/community/Eway/Rapid31/Block/Info/Sharedpage/Notsaved.php +26 -0
  12. app/code/community/Eway/Rapid31/Block/Info/Sharedpage/Saved.php +45 -0
  13. app/code/community/Eway/Rapid31/Block/Info/Transparent/Notsaved.php +27 -0
  14. app/code/community/Eway/Rapid31/Block/Info/Transparent/Saved.php +46 -0
  15. app/code/community/Eway/Rapid31/Block/Redirect/PaypalReview.php +76 -0
  16. app/code/community/Eway/Rapid31/Block/Redirect/Transparent.php +84 -0
  17. app/code/community/Eway/Rapid31/Block/Redirect/TransparentCheckout.php +50 -0
  18. app/code/community/Eway/Rapid31/Block/Sales/Order/Grid.php +31 -0
  19. app/code/community/Eway/Rapid31/Helper/Customer.php +235 -0
  20. app/code/community/Eway/Rapid31/Helper/Data.php +147 -0
  21. app/code/community/Eway/Rapid31/Model/Backend/Savedtokens.php +38 -0
  22. app/code/community/Eway/Rapid31/Model/Config.php +128 -0
  23. app/code/community/Eway/Rapid31/Model/Customer/Savedtokens.php +91 -0
  24. app/code/community/Eway/Rapid31/Model/Customer/Token.php +32 -0
  25. app/code/community/Eway/Rapid31/Model/EwayCron.php +135 -0
  26. app/code/community/Eway/Rapid31/Model/Field/CardDetails.php +90 -0
  27. app/code/community/Eway/Rapid31/Model/Field/Customer.php +51 -0
  28. app/code/community/Eway/Rapid31/Model/Field/LineItem.php +21 -0
  29. app/code/community/Eway/Rapid31/Model/Field/Payment.php +24 -0
  30. app/code/community/Eway/Rapid31/Model/Field/ShippingAddress.php +30 -0
  31. app/code/community/Eway/Rapid31/Model/JsonSerializable.php +6 -0
  32. app/code/community/Eway/Rapid31/Model/JsonSerializableAbstract.php +45 -0
  33. app/code/community/Eway/Rapid31/Model/Method/Notsaved.php +471 -0
  34. app/code/community/Eway/Rapid31/Model/Method/Saved.php +286 -0
  35. app/code/community/Eway/Rapid31/Model/Observer.php +285 -0
  36. app/code/community/Eway/Rapid31/Model/RecurringProfile.php +526 -0
  37. app/code/community/Eway/Rapid31/Model/Request/Abstract.php +143 -0
  38. app/code/community/Eway/Rapid31/Model/Request/Direct.php +260 -0
  39. app/code/community/Eway/Rapid31/Model/Request/Sharedpage.php +514 -0
  40. app/code/community/Eway/Rapid31/Model/Request/Token.php +504 -0
  41. app/code/community/Eway/Rapid31/Model/Request/Transparent.php +667 -0
  42. app/code/community/Eway/Rapid31/Model/Response.php +360 -0
  43. app/code/community/Eway/Rapid31/Model/System/Config/Backend/Orderstatus.php +22 -0
  44. app/code/community/Eway/Rapid31/Model/System/Config/Backend/Validation.php +48 -0
  45. app/code/community/Eway/Rapid31/Model/System/Config/Source/Cctype.php +8 -0
  46. app/code/community/Eway/Rapid31/Model/System/Config/Source/ConnectionType.php +23 -0
  47. app/code/community/Eway/Rapid31/Model/System/Config/Source/Mode.php +20 -0
  48. app/code/community/Eway/Rapid31/Model/System/Config/Source/Orderstatus.php +33 -0
  49. app/code/community/Eway/Rapid31/Model/System/Config/Source/PaymentAction.php +17 -0
  50. app/code/community/Eway/Rapid31/Model/System/Config/Source/VerifyStatus.php +22 -0
  51. app/code/community/Eway/Rapid31/Test/Model/Abstract.php +179 -0
  52. app/code/community/Eway/Rapid31/Test/Model/Config.php +71 -0
  53. app/code/community/Eway/Rapid31/Test/Model/CustomerToken.php +203 -0
  54. app/code/community/Eway/Rapid31/Test/Model/JsonSerializable.php +199 -0
  55. app/code/community/Eway/Rapid31/Test/Model/Request.php +191 -0
  56. app/code/community/Eway/Rapid31/Test/Model/Request/fixtures/default.yaml +6 -0
  57. app/code/community/Eway/Rapid31/Test/Model/Response.php +74 -0
  58. app/code/community/Eway/Rapid31/Test/Model/TokenRequest.php +118 -0
  59. app/code/community/Eway/Rapid31/Test/Model/TokenRequest/fixtures/default.yaml +6 -0
  60. app/code/community/Eway/Rapid31/controllers/Adminhtml/IndexController.php +177 -0
  61. app/code/community/Eway/Rapid31/controllers/MycardsController.php +402 -0
  62. app/code/community/Eway/Rapid31/controllers/SharedpageController.php +272 -0
  63. app/code/community/Eway/Rapid31/controllers/TestController.php +131 -0
  64. app/code/community/Eway/Rapid31/controllers/TransparentController.php +407 -0
  65. app/code/community/Eway/Rapid31/etc/config.xml +302 -0
  66. app/code/community/Eway/Rapid31/etc/system.xml +429 -0
  67. app/code/community/Eway/Rapid31/sql/ewayrapid_setup/install-0.1.0.php +25 -0
  68. app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-0.1.0-1.0.0.php +19 -0
  69. app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-1.0.0-1.0.1.php +26 -0
  70. app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-1.0.1-1.0.3.php +33 -0
  71. app/design/adminhtml/default/default/layout/ewayrapid/layout.xml +17 -0
  72. app/design/adminhtml/default/default/template/ewayrapid/form/direct_notsaved.phtml +63 -0
  73. app/design/adminhtml/default/default/template/ewayrapid/form/direct_saved.phtml +110 -0
  74. app/design/adminhtml/default/default/template/ewayrapid/info/direct_notsaved.phtml +64 -0
  75. app/design/adminhtml/default/default/template/ewayrapid/info/direct_saved.phtml +56 -0
  76. app/design/adminhtml/default/default/template/ewayrapid/pdf/direct_notsaved.phtml +33 -0
  77. app/design/frontend/base/default/layout/ewayrapid/layout.xml +184 -0
  78. app/design/frontend/base/default/template/ewayrapid/customer/edit.phtml +615 -0
  79. app/design/frontend/base/default/template/ewayrapid/customer/mycards.phtml +62 -0
  80. app/design/frontend/base/default/template/ewayrapid/form/direct_notsaved.phtml +87 -0
  81. app/design/frontend/base/default/template/ewayrapid/form/direct_saved.phtml +152 -0
  82. app/design/frontend/base/default/template/ewayrapid/form/sharedpage_notsaved.phtml +29 -0
  83. app/design/frontend/base/default/template/ewayrapid/form/sharedpage_saved.phtml +81 -0
  84. app/design/frontend/base/default/template/ewayrapid/form/transparent_notsaved.phtml +132 -0
  85. app/design/frontend/base/default/template/ewayrapid/form/transparent_saved.phtml +322 -0
  86. app/design/frontend/base/default/template/ewayrapid/info/direct_notsaved.phtml +39 -0
  87. app/design/frontend/base/default/template/ewayrapid/info/direct_saved.phtml +39 -0
  88. app/design/frontend/base/default/template/ewayrapid/info/sharedpage_notsaved.phtml +39 -0
  89. app/design/frontend/base/default/template/ewayrapid/info/sharedpage_saved.phtml +39 -0
  90. app/design/frontend/base/default/template/ewayrapid/info/transparent_notsaved.phtml +39 -0
  91. app/design/frontend/base/default/template/ewayrapid/js.phtml +85 -0
  92. app/design/frontend/base/default/template/ewayrapid/redirect/review.phtml +385 -0
  93. app/design/frontend/base/default/template/ewayrapid/redirect/transparent.phtml +77 -0
  94. app/design/frontend/base/default/template/ewayrapid/redirect/transparent_checkout.phtml +32 -0
  95. app/etc/modules/Eway_Rapid31.xml +9 -0
  96. app/locale/en_US/Eway_Rapid31.csv +3 -0
  97. js/ewayrapid/eCrypt.js +1001 -0
  98. js/ewayrapid/ewayrapid.js +682 -0
  99. package.xml +38 -0
  100. skin/adminhtml/default/default/ewayrapid.css +0 -0
  101. skin/frontend/base/default/css/ewayrapid.css +34 -0
app/code/community/Eway/Rapid31/Block/Customer/Edit.php ADDED
@@ -0,0 +1,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
+ }
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
+ }
app/code/community/Eway/Rapid31/Block/Customer/Mycards.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Block_Customer_Mycards extends Mage_Core_Block_Template
3
+ {
4
+ public function getAddCreditCardUrl()
5
+ {
6
+ return $this->getUrl('*/*/new');
7
+ }
8
+
9
+ public function getEditUrl($id)
10
+ {
11
+ return $this->getUrl('*/*/edit', array('token_id' => $id));
12
+ }
13
+
14
+ public function getDeleteUrl($id)
15
+ {
16
+ return $this->getUrl('*/*/delete', array('token_id' => $id));
17
+ }
18
+
19
+ public function getUpdateDefaultUrl($id)
20
+ {
21
+ return $this->getUrl('*/*/setdefault', array('token_id' => $id));
22
+ }
23
+ }
app/code/community/Eway/Rapid31/Block/Form/Direct/Notsaved.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Block_Form_Direct_Notsaved extends Mage_Payment_Block_Form_Cc
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('ewayrapid/form/direct_notsaved.phtml');
8
+ }
9
+ }
app/code/community/Eway/Rapid31/Block/Form/Direct/Saved.php ADDED
@@ -0,0 +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
+ }
app/code/community/Eway/Rapid31/Block/Form/Sharedpage/Notsaved.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
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
+ }
9
+ }
app/code/community/Eway/Rapid31/Block/Form/Sharedpage/Saved.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
9
+
10
+ /**
11
+ * Get list of active tokens of current customer
12
+ *
13
+ * @return array
14
+ */
15
+ public function getTokenList()
16
+ {
17
+ $tokenList = array();
18
+ $tokenList['tokens'] = Mage::helper('ewayrapid/customer')->getActiveTokenList();
19
+ $tokenList['tokens'][Eway_Rapid31_Model_Config::TOKEN_NEW] =
20
+ Mage::getModel('ewayrapid/customer_token')->setCard($this->__('Add new card'))->setOwner('')
21
+ ->setExpMonth('')->setExpYear('');
22
+ $tokenList['default_token'] = Mage::helper('ewayrapid/customer')->getDefaultToken();
23
+
24
+ $tokenListJson = array();
25
+ foreach($tokenList['tokens'] as $id => $token) {
26
+ /* @var Eway_Rapid31_Model_Customer_Token $token */
27
+ $tokenListJson[] = "\"{$id}\":{$token->jsonSerialize()}";
28
+ }
29
+ $tokenList['tokens_json'] = '{' . implode(',', $tokenListJson) . '}';
30
+
31
+ return $tokenList;
32
+ }
33
+ }
app/code/community/Eway/Rapid31/Block/Form/Transparent/Notsaved.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Eway_Rapid31_Block_Form_Transparent_Notsaved extends Mage_Payment_Block_Form_Cc
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+
9
+ //unset all session's transaparent;
10
+ Mage::getModel('ewayrapid/request_transparent')->unsetSessionData();
11
+
12
+ $this->setTemplate('ewayrapid/form/transparent_notsaved.phtml');
13
+ }
14
+
15
+ /**
16
+ * @return mixed
17
+ */
18
+ public function getConfig()
19
+ {
20
+ return (object)Mage::getStoreConfig('payment/ewayrapid_general');
21
+ }
22
+
23
+ public function getEnablePaypalCheckout()
24
+ {
25
+ return Mage::getStoreConfig('payment/ewayrapid_general/enable_paypal_checkout');
26
+ }
27
+
28
+ public function getEnablePaypalStandard()
29
+ {
30
+ return Mage::getStoreConfig('payment/ewayrapid_general/enable_paypal_standard');
31
+ }
32
+
33
+ public function getEnableMasterpass()
34
+ {
35
+ return Mage::getStoreConfig('payment/ewayrapid_general/enable_masterpass');
36
+ }
37
+ }
app/code/community/Eway/Rapid31/Block/Form/Transparent/Saved.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Eway_Rapid31_Block_Form_Transparent_Saved extends Mage_Payment_Block_Form_Cc
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->setIsRecurring(Mage::helper('ewayrapid')->isRecurring());
9
+ $this->setTemplate('ewayrapid/form/transparent_saved.phtml');
10
+
11
+ //unset all session's transaparent
12
+ Mage::getModel('ewayrapid/request_transparent')->unsetSessionData();
13
+ }
14
+
15
+ /**
16
+ * Get list of active tokens of current customer
17
+ *
18
+ * @return array
19
+ */
20
+ public function getTokenList()
21
+ {
22
+ $tokenList = array();
23
+ $tokenList['tokens'] = Mage::helper('ewayrapid/customer')->getActiveTokenList();
24
+ $tokenList['tokens'][Eway_Rapid31_Model_Config::TOKEN_NEW] =
25
+ Mage::getModel('ewayrapid/customer_token')->setCard($this->__('Add new card'))->setOwner('')
26
+ ->setExpMonth('')->setExpYear('');
27
+ $tokenList['default_token'] = Mage::helper('ewayrapid/customer')->getDefaultToken();
28
+
29
+ $tokenListJson = array();
30
+ foreach ($tokenList['tokens'] as $id => $token) {
31
+ /* @var Eway_Rapid31_Model_Customer_Token $token */
32
+ $tokenListJson[] = "\"{$id}\":{$token->jsonSerialize()}";
33
+ }
34
+ $tokenList['tokens_json'] = '{' . implode(',', $tokenListJson) . '}';
35
+
36
+ return $tokenList;
37
+ }
38
+
39
+ /**
40
+ * @return mixed
41
+ */
42
+ public function getConfig()
43
+ {
44
+ return (object)Mage::getStoreConfig('payment/ewayrapid_general');
45
+ }
46
+
47
+ public function getEnablePaypalCheckout()
48
+ {
49
+ return Mage::getStoreConfig('payment/ewayrapid_general/enable_paypal_checkout');
50
+ }
51
+
52
+ public function getEnablePaypalStandard()
53
+ {
54
+ return Mage::getStoreConfig('payment/ewayrapid_general/enable_paypal_standard');
55
+ }
56
+
57
+ public function getEnableMasterpass()
58
+ {
59
+ return Mage::getStoreConfig('payment/ewayrapid_general/enable_masterpass');
60
+ }
61
+
62
+ public function checkCardName($card)
63
+ {
64
+ /* @var Eway_Rapid31_Model_Request_Token $model */
65
+ $model = Mage::getModel('ewayrapid/request_token');
66
+ return $model->checkCardName($card);
67
+ }
68
+ }
app/code/community/Eway/Rapid31/Block/Info/Direct/Notsaved.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Block_Info_Direct_Notsaved extends Mage_Payment_Block_Info
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('ewayrapid/info/direct_notsaved.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
+ public function getCcTypeName($type)
22
+ {
23
+ return Mage::helper('ewayrapid')->getCcTypeName($type);
24
+ }
25
+
26
+ }
app/code/community/Eway/Rapid31/Block/Info/Direct/Saved.php ADDED
@@ -0,0 +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
+ }
app/code/community/Eway/Rapid31/Block/Info/Sharedpage/Notsaved.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Block_Info_Sharedpage_Notsaved extends Mage_Payment_Block_Info
3
+ {
4
+ protected function _construct()
5
+ {
6
+ parent::_construct();
7
+ $this->setTemplate('ewayrapid/info/sharedpage_notsaved.phtml');
8
+ }
9
+
10
+ /**
11
+ * Render as PDF
12
+ *
13
+ * @return string
14
+ */
15
+ public function toPdf()
16
+ {
17
+ $this->setTemplate('ewayrapid/pdf/sharedpage_notsaved.phtml');
18
+ return $this->toHtml();
19
+ }
20
+
21
+ public function getCcTypeName($type)
22
+ {
23
+ return Mage::helper('ewayrapid')->getCcTypeName($type);
24
+ }
25
+
26
+ }
app/code/community/Eway/Rapid31/Block/Info/Sharedpage/Saved.php ADDED
@@ -0,0 +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/sharedpage_saved.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/Transparent/Notsaved.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Eway_Rapid31_Block_Info_Transparent_Notsaved extends Mage_Payment_Block_Info
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->setTemplate('ewayrapid/info/transparent_notsaved.phtml');
9
+ }
10
+
11
+ /**
12
+ * Render as PDF
13
+ *
14
+ * @return string
15
+ */
16
+ public function toPdf()
17
+ {
18
+ $this->setTemplate('ewayrapid/pdf/transparent_notsaved.phtml');
19
+ return $this->toHtml();
20
+ }
21
+
22
+ public function getCcTypeName($type)
23
+ {
24
+ return Mage::helper('ewayrapid')->getCcTypeName($type);
25
+ }
26
+
27
+ }
app/code/community/Eway/Rapid31/Block/Info/Transparent/Saved.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Eway_Rapid31_Block_Info_Transparent_Saved extends Mage_Payment_Block_Info
4
+ {
5
+ protected function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->setTemplate('ewayrapid/info/transparent_saved.phtml');
9
+ }
10
+
11
+ /**
12
+ * Render as PDF
13
+ *
14
+ * @return string
15
+ */
16
+ public function toPdf()
17
+ {
18
+ $this->setTemplate('ewayrapid/pdf/transparent_notsaved.phtml');
19
+ return $this->toHtml();
20
+ }
21
+
22
+
23
+ /**
24
+ * Get eWAY Customer Token Id of this transaction
25
+ *
26
+ * @return string
27
+ */
28
+ public function getTokenId()
29
+ {
30
+ $info = $this->getInfo();
31
+ /* @var Mage_Sales_Model_Order_Payment $info */
32
+ $order = $info->getOrder();
33
+ if ($order->getCustomerIsGuest()) {
34
+ return '';
35
+ }
36
+
37
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
38
+ if (!$info->getSavedToken()) {
39
+ return '';
40
+ }
41
+
42
+ $customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
43
+ $helper = Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
44
+ return $helper->getCustomerTokenId($info->getSavedToken());
45
+ }
46
+ }
app/code/community/Eway/Rapid31/Block/Redirect/PaypalReview.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Eway_Rapid31_Block_Redirect_PaypalReview extends Mage_Core_Block_Template
4
+ {
5
+ /**
6
+ * @var Mage_Sales_Model_Quote
7
+ */
8
+ protected $_quote;
9
+
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+ $this->setTemplate('ewayrapid/redirect/review.phtml');
14
+ }
15
+
16
+ public function setQuote(Mage_Sales_Model_Quote $quote)
17
+ {
18
+ $this->_quote = $quote;
19
+ }
20
+
21
+ protected function _getQuote()
22
+ {
23
+ if (!$this->_quote) {
24
+ $this->_quote = Mage::getSingleton('checkout/session')->getQuote();
25
+ }
26
+ return $this->_quote;
27
+ }
28
+
29
+ public function getBillingAddress()
30
+ {
31
+ return $this->_quote->getBillingAddress();
32
+ }
33
+
34
+ public function getShippingAddress()
35
+ {
36
+ return $this->_quote->getShippingAddress();
37
+ }
38
+
39
+ public function getRates()
40
+ {
41
+ return $this->_getQuote()
42
+ ->getShippingAddress()
43
+ ->collectShippingRates()
44
+ ->getGroupedAllShippingRates();
45
+ }
46
+
47
+ public function getCurrentRateCode()
48
+ {
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');
58
+ return $transModel->getShippingByCode($this->_quote, $postCode);
59
+ }
60
+ return false;
61
+ }
62
+
63
+ /**
64
+ * Return carrier name from config, base on carrier code
65
+ *
66
+ * @param $carrierCode string
67
+ * @return string
68
+ */
69
+ public function getCarrierName($carrierCode)
70
+ {
71
+ if ($name = Mage::getStoreConfig("carriers/{$carrierCode}/title")) {
72
+ return $name;
73
+ }
74
+ return $carrierCode;
75
+ }
76
+ }
app/code/community/Eway/Rapid31/Block/Redirect/Transparent.php ADDED
@@ -0,0 +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') {
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 ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
16
+ $this->setTemplate('ewayrapid/redirect/transparent_checkout.phtml')->toHtml();
17
+ }
18
+
19
+ /**
20
+ * Retrieve credit card expire months
21
+ *
22
+ * @return array
23
+ */
24
+ public function getCcMonths()
25
+ {
26
+ $months = $this->getData('cc_months');
27
+ if (is_null($months)) {
28
+ $months[0] = $this->__('Month');
29
+ $months = array_merge($months, Mage::getSingleton('payment/config')->getMonths());
30
+ $this->setData('cc_months', $months);
31
+ }
32
+ return $months;
33
+ }
34
+
35
+ /**
36
+ * Retrieve credit card expire years
37
+ *
38
+ * @return array
39
+ */
40
+ public function getCcYears()
41
+ {
42
+ $years = $this->getData('cc_years');
43
+ if (is_null($years)) {
44
+ $years = Mage::getSingleton('payment/config')->getYears();
45
+ $years = array(0 => $this->__('Year')) + $years;
46
+ $this->setData('cc_years', $years);
47
+ }
48
+ return $years;
49
+ }
50
+ }
app/code/community/Eway/Rapid31/Block/Sales/Order/Grid.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: Administrator PC
5
+ * Date: 7/21/14
6
+ * Time: 3:47 PM
7
+ */
8
+ class Eway_Rapid31_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid {
9
+
10
+ protected function _prepareMassaction()
11
+ {
12
+ parent::_prepareMassaction();
13
+
14
+ // Append new mass action option
15
+ $this->getMassactionBlock()->addItem(
16
+ 'pending',
17
+ array(
18
+ 'label' => $this->__('Verify eWAY Order'),
19
+ 'url' => Mage::helper("adminhtml")->getUrl("ewayadmin/index/massVerifyEwayOrder"), //this should be the url where there will be mass operation
20
+ 'confirm'=> $this->__('Are you sure?')
21
+ )
22
+ )/*->addItem(
23
+ 'eway_authorised',
24
+ array(
25
+ 'label' => 'eWAY Authorised',
26
+ 'url' => Mage::helper("adminhtml")->getUrl("ewayadmin/index/massEwayAuthorised"), //this should be the url where there will be mass operation
27
+ 'confirm'=> $this->__('Are you sure?')
28
+ )
29
+ )*/;
30
+ }
31
+ }
app/code/community/Eway/Rapid31/Helper/Customer.php ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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() && Mage::getSingleton('adminhtml/session_quote')->getCustomer()) {
41
+ return Mage::getSingleton('adminhtml/session_quote')->getCustomer();
42
+ }
43
+
44
+ if(Mage::getSingleton('customer/session')->isLoggedIn()) {
45
+ return Mage::getSingleton('customer/session')->getCustomer();
46
+ }
47
+
48
+ if(($quote = Mage::getSingleton('checkout/session')->getQuote()) && ($customer = $quote->getCustomer()) && $customer->getId()) {
49
+ return $customer;
50
+ }
51
+
52
+ return false;
53
+ }
54
+
55
+ /**
56
+ * Get eWAY Customer Token Id
57
+ *
58
+ * @param $id
59
+ * @return mixed
60
+ */
61
+ public function getCustomerTokenId($id)
62
+ {
63
+ return $this->getTokenById($id)->getToken() ? $this->getTokenById($id)->getToken() : $this->getTokenById($id)->getTokenCustomerID();
64
+ }
65
+
66
+ /**
67
+ * Get token object by id (id used in Magento, not Customer Token Id)
68
+ *
69
+ * @param $id
70
+ * @return Eway_Rapid31_Model_Customer_Token
71
+ */
72
+ public function getTokenById($id)
73
+ {
74
+ $customer = $this->getCurrentCustomer();
75
+ if($customer && $customer->getSavedTokens()) {
76
+ return $customer->getSavedTokens()->getTokenById($id);
77
+ } else {
78
+ Mage::throwException($this->__('Customer does not have any saved token.'));
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Get last token id of this customer
84
+ *
85
+ * @return bool | int
86
+ */
87
+ public function getLastTokenId()
88
+ {
89
+ $customer = $this->getCurrentCustomer();
90
+ if($customer && $customer->getSavedTokens()) {
91
+ return $customer->getSavedTokens()->getLastId();
92
+ }
93
+
94
+ return false;
95
+ }
96
+
97
+ /**
98
+ * Add new token to customer's token list
99
+ *
100
+ * @param $info array
101
+ */
102
+ public function addToken($info)
103
+ {
104
+ $customer = $this->getCurrentCustomer();
105
+ if($customer) {
106
+ $savedTokens = $customer->getSavedTokens();
107
+ if(!$savedTokens) {
108
+ $savedTokens = Mage::getModel('ewayrapid/customer_savedtokens');
109
+ }
110
+
111
+ $savedTokens->addToken($info);
112
+ $customer->setSavedTokens($savedTokens);
113
+
114
+ // Only save existed customer, new customer will be saved by Magento.
115
+ if($customer->getId()) {
116
+ $customer->save();
117
+ }
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Update token identified by id (id used in Magento, not Customer Token Id)
123
+ *
124
+ * @param int $id
125
+ * @param $info
126
+ */
127
+ public function updateToken($id, $info)
128
+ {
129
+ $this->getTokenById($id)->addData($info);
130
+ $this->getCurrentCustomer()->setDataChanges(true)->save();
131
+ }
132
+
133
+ /**
134
+ * Delete token identified by id (id used in Magento, not Customer Token Id)
135
+ *
136
+ * @param int $id
137
+ */
138
+ public function deleteToken($id)
139
+ {
140
+ $this->updateToken($id, array('Active' => 0));
141
+ }
142
+
143
+ /**
144
+ * Set token identified by id as default token (id used in Magento, not Customer Token Id)
145
+ *
146
+ * @param int $id
147
+ */
148
+ public function setDefaultToken($id)
149
+ {
150
+ // Check if token is existed.
151
+ $this->getTokenById($id);
152
+ $this->getCurrentCustomer()->getSavedTokens()->setDefaultToken($id);
153
+ $this->getCurrentCustomer()->setDataChanges(true)->save();
154
+ }
155
+
156
+ /**
157
+ * Get default token id
158
+ *
159
+ * @return bool | int
160
+ */
161
+ public function getDefaultToken()
162
+ {
163
+ $customer = $this->getCurrentCustomer();
164
+ if($customer && $customer->getSavedTokens()) {
165
+ return $customer->getSavedTokens()->getDefaultToken();
166
+ }
167
+
168
+ return false;
169
+ }
170
+
171
+ /**
172
+ * Get active token list of current customer
173
+ *
174
+ * @return array
175
+ */
176
+ public function getActiveTokenList()
177
+ {
178
+ $customer = $this->getCurrentCustomer();
179
+ if($customer && $customer->getSavedTokens()) {
180
+ $tokens = $customer->getSavedTokens()->getTokens();
181
+ if(is_array($tokens)) {
182
+ foreach($tokens as $key => $token) {
183
+ /* @var Eway_Rapid31_Model_Customer_Token $token */
184
+ if(!$token->getActive()) {
185
+ unset($tokens[$key]);
186
+ } else {
187
+ $token->unsetData('Token');
188
+ }
189
+ }
190
+ return $tokens;
191
+ }
192
+ }
193
+
194
+ return array();
195
+ }
196
+
197
+ /**
198
+ * Get active token list of current customer
199
+ *
200
+ * @return array
201
+ */
202
+ public function checkTokenListByType($type = Eway_Rapid31_Model_Config::CREDITCARD_METHOD)
203
+ {
204
+ $customer = $this->getCurrentCustomer();
205
+ if($customer && $customer->getSavedTokens()) {
206
+ $tokens = $customer->getSavedTokens()->getTokens();
207
+ if(is_array($tokens)) {
208
+ foreach($tokens as $key => $token) {
209
+ /* @var Eway_Rapid31_Model_Customer_Token $token */
210
+ if(!$token->getActive()) {
211
+ unset($tokens[$key]);
212
+ } else {
213
+ $token->unsetData('Token');
214
+ }
215
+
216
+ if($token->getCard() && $type == Eway_Rapid31_Model_Config::CREDITCARD_METHOD) {
217
+ if (preg_match('/^'.Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD.'/', strtolower($token->getCard()))) {
218
+ unset($tokens[$key]);
219
+ }
220
+ if (preg_match('/^mc/', strtolower($token->getCard()))) {
221
+ unset($tokens[$key]);
222
+ }
223
+ } elseif($token->getCard()) {
224
+ if (!preg_match('/^'.$type.'/', strtolower($token->getCard()))) {
225
+ unset($tokens[$key]);
226
+ }
227
+ }
228
+ }
229
+ return $tokens;
230
+ }
231
+ }
232
+
233
+ return array();
234
+ }
235
+ }
app/code/community/Eway/Rapid31/Helper/Data.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: hiephm
5
+ * Date: 4/23/14
6
+ * Time: 5:30 PM
7
+ */
8
+ class Eway_Rapid31_Helper_Data extends Mage_Core_Helper_Abstract
9
+ {
10
+ private $_ccTypeNames = null;
11
+ private $_isSaveMethodEnabled = null;
12
+
13
+ public function isBackendOrder()
14
+ {
15
+ return Mage::app()->getStore()->isAdmin();
16
+ }
17
+
18
+ public function serializeInfoInstance(&$info)
19
+ {
20
+ $fieldsToSerialize = array('is_new_token', 'is_update_token', 'saved_token');
21
+ $data = array();
22
+ foreach($fieldsToSerialize as $field) {
23
+ $data[$field] = $info->getData($field);
24
+ }
25
+
26
+ $info->setAdditionalData(json_encode($data));
27
+ }
28
+
29
+ public function unserializeInfoInstace(&$info)
30
+ {
31
+ $data = json_decode($info->getAdditionalData(), true);
32
+ $info->addData($data);
33
+ }
34
+
35
+ public function getCcTypeName($type)
36
+ {
37
+ if (preg_match('/^paypal/', strtolower($type))) {
38
+ return 'PayPal';
39
+ }
40
+
41
+ if(is_null($this->_ccTypeNames)) {
42
+ $this->_ccTypeNames = Mage::getSingleton('payment/config')->getCcTypes();
43
+ }
44
+ return (isset($this->_ccTypeNames[$type]) ? $this->_ccTypeNames[$type] : 'Unknown');
45
+ }
46
+
47
+ public function isSavedMethodEnabled()
48
+ {
49
+ if(is_null($this->_isSaveMethodEnabled)) {
50
+ $this->_isSaveMethodEnabled = Mage::getSingleton('ewayrapid/method_saved')->getConfigData('active');
51
+ }
52
+ return $this->_isSaveMethodEnabled;
53
+ }
54
+
55
+ public function isRecurring()
56
+ {
57
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
58
+ $items = $quote->getAllItems();
59
+ foreach ($items as $item) {
60
+ if ($item->getIsRecurring()) {
61
+ return true;
62
+ }
63
+ }
64
+ return false;
65
+ }
66
+
67
+ /**
68
+ * @param $data
69
+ * @param $key
70
+ * @return string
71
+ */
72
+ public function encryptSha256($data, $key)
73
+ {
74
+ //To Encrypt:
75
+ return trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB));
76
+ }
77
+
78
+ public function decryptSha256($data, $key)
79
+ {
80
+ //To Decrypt:
81
+ return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB));
82
+ }
83
+
84
+ public function getPaymentAction()
85
+ {
86
+ return Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
87
+ }
88
+
89
+ public function getTransferCartLineItems()
90
+ {
91
+ return Mage::getStoreConfig('payment/ewayrapid_general/transfer_cart_items');
92
+ }
93
+
94
+ public function getLineItems()
95
+ {
96
+ $lineItems = array();
97
+ /** @var Mage_Sales_Model_Quote $quote */
98
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
99
+ if ($quote) {
100
+ // add Shipping item
101
+ if ($quote->getShippingAddress()->getBaseShippingInclTax()) {
102
+ $shippingItem = Mage::getModel('ewayrapid/field_lineItem');
103
+ $shippingItem->setSKU('');
104
+ $shippingItem->setDescription('Shipping');
105
+ $shippingItem->setQuantity(1);
106
+ $shippingItem->setUnitCost(round($quote->getShippingAddress()->getBaseShippingAmount() * 100));
107
+ $shippingItem->setTax(round($quote->getShippingAddress()->getBaseShippingTaxAmount() * 100));
108
+ $shippingItem->setTotal(round($quote->getShippingAddress()->getBaseShippingInclTax() * 100));
109
+ $lineItems[] = $shippingItem;
110
+ }
111
+
112
+ // add Line items
113
+ $items = $quote->getAllVisibleItems();
114
+ foreach ($items as $item) {
115
+ /* @var Mage_Sales_Model_Order_Item $item */
116
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
117
+ $lineItem->setSKU($item->getSku());
118
+ $lineItem->setDescription(substr($item->getName(), 0, 26));
119
+ $lineItem->setQuantity($item->getQty());
120
+ $lineItem->setUnitCost(round($item->getBasePrice() * 100));
121
+ $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
122
+ $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
123
+ $lineItems[] = $lineItem;
124
+ }
125
+
126
+ // add Discount item
127
+ if ((int)$quote->getShippingAddress()->getBaseDiscountAmount() !== 0) {
128
+ $shippingItem = Mage::getModel('ewayrapid/field_lineItem');
129
+ $shippingItem->setSKU('');
130
+ $shippingItem->setDescription('Discount');
131
+ $shippingItem->setQuantity(1);
132
+ $shippingItem->setUnitCost(round($quote->getShippingAddress()->getBaseDiscountAmount() * 100));
133
+ $shippingItem->setTax(0);
134
+ $shippingItem->setTotal(round($quote->getShippingAddress()->getBaseDiscountAmount() * 100));
135
+ $lineItems[] = $shippingItem;
136
+ }
137
+ }
138
+ return $lineItems;
139
+ }
140
+
141
+ public function checkCardName($card)
142
+ {
143
+ /* @var Eway_Rapid31_Model_Request_Token $model */
144
+ $model = Mage::getModel('ewayrapid/request_token');
145
+ return $model->checkCardName($card);
146
+ }
147
+ }
app/code/community/Eway/Rapid31/Model/Backend/Savedtokens.php ADDED
@@ -0,0 +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
+ }
app/code/community/Eway/Rapid31/Model/Config.php ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
9
+ const METHOD_PROCESS_PAYMENT = 'ProcessPayment';
10
+ const METHOD_CREATE_TOKEN = 'CreateTokenCustomer';
11
+ const METHOD_UPDATE_TOKEN = 'UpdateTokenCustomer';
12
+ const METHOD_TOKEN_PAYMENT = 'TokenPayment';
13
+ const METHOD_AUTHORISE = 'Authorise';
14
+
15
+ const TRANSACTION_PURCHASE = 'Purchase';
16
+ const TRANSACTION_MOTO = 'MOTO';
17
+ const TRANSACTION_RECURRING = 'Recurring';
18
+
19
+ const CONNECTION_DIRECT = 'direct';
20
+ const CONNECTION_TRANSPARENT = 'transparent';
21
+ const CONNECTION_SHARED_PAGE = 'sharedpage';
22
+
23
+ const CREDITCARD_METHOD = 'creditcard';
24
+ const PAYPAL_STANDARD_METHOD = 'paypal';
25
+ const PAYPAL_EXPRESS_METHOD = 'paypal_express';
26
+ const MASTERPASS_METHOD = 'masterpass';
27
+
28
+ const MESSAGE_ERROR_ORDER = 'Billing Frequency is wrong. It must be numeric and greater than 0. Status of recurring profile is changed to canceled';
29
+
30
+ const TRANSPARENT_ACCESSCODE = 'AccessCodes';
31
+ const TRANSPARENT_ACCESSCODE_RESULT = 'AccessCode';
32
+
33
+ const ENCRYPTION_PREFIX = 'eCrypted';
34
+ const TOKEN_NEW = 'new';
35
+
36
+ const ORDER_STATUS_AUTHORISED = 'eway_authorised';
37
+ const ORDER_STATUS_CAPTURED = 'eway_captured';
38
+
39
+ private $_isSandbox = true;
40
+ private $_isDebug = false;
41
+ private $_liveUrl = '';
42
+ private $_liveApiKey = '';
43
+ private $_livePassword = '';
44
+ private $_sandboxUrl = '';
45
+ private $_sandboxApiKey = '';
46
+ private $_sandboxPassword = '';
47
+ private $_isEnableSSLVerification = false;
48
+
49
+ public function __construct()
50
+ {
51
+ $this->_isSandbox = (Mage::getStoreConfig('payment/ewayrapid_general/mode') == self::MODE_SANDBOX);
52
+ $this->_isDebug = (bool) Mage::getStoreConfig('payment/ewayrapid_general/debug');
53
+ $this->_sandboxUrl = Mage::getStoreConfig('payment/ewayrapid_general/sandbox_endpoint');
54
+ $this->_liveUrl = Mage::getStoreConfig('payment/ewayrapid_general/live_endpoint');
55
+ $this->_liveApiKey = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/live_api_key'));
56
+ $this->_livePassword = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/live_api_password'));
57
+ $this->_sandboxApiKey = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/sandbox_api_key'));
58
+ $this->_sandboxPassword = Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/ewayrapid_general/sandbox_api_password'));
59
+ $this->_isEnableSSLVerification = Mage::getStoreConfig('payment/ewayrapid_general/ssl_verification');
60
+ }
61
+
62
+ public function isSandbox($sandbox = null)
63
+ {
64
+ if($sandbox !== null) {
65
+ $this->_isSandbox = (bool) $sandbox;
66
+ }
67
+
68
+ return $this->_isSandbox;
69
+ }
70
+
71
+ public function isDebug($debug = null)
72
+ {
73
+ if($debug !== null) {
74
+ $this->_isDebug = (bool) $debug;
75
+ }
76
+
77
+ return $this->_isDebug;
78
+ }
79
+
80
+ public function getRapidAPIUrl($action = false)
81
+ {
82
+ $url = $this->isSandbox() ? $this->_sandboxUrl : $this->_liveUrl;
83
+ $url = rtrim($url, '/') . '/';
84
+ if($action) {
85
+ $url .= $action;
86
+ }
87
+
88
+ return $url;
89
+ }
90
+
91
+ public function getBasicAuthenticationHeader()
92
+ {
93
+ return $this->isSandbox() ? $this->_sandboxApiKey . ':' . $this->_sandboxPassword
94
+ : $this->_liveApiKey . ':' . $this->_livePassword;
95
+ }
96
+
97
+ public function isEnableSSLVerification()
98
+ {
99
+ // Always return true in Live mode regardless Magento config.
100
+ return !$this->isSandbox() || $this->_isEnableSSLVerification;
101
+ }
102
+
103
+ public function getEncryptionKey()
104
+ {
105
+ return $this->isSandbox() ? Mage::getStoreConfig('payment/ewayrapid_general/sandbox_encryption_key')
106
+ : Mage::getStoreConfig('payment/ewayrapid_general/live_encryption_key');
107
+ }
108
+
109
+ public function isDirectConnection()
110
+ {
111
+ return Mage::getStoreConfig('payment/ewayrapid_general/connection_type') == self::CONNECTION_DIRECT;
112
+ }
113
+
114
+ public function isTransparentConnection()
115
+ {
116
+ return Mage::getStoreConfig('payment/ewayrapid_general/connection_type') == self::CONNECTION_TRANSPARENT;
117
+ }
118
+
119
+ public function canEditToken()
120
+ {
121
+ return (bool) Mage::getStoreConfig('payment/ewayrapid_general/can_edit_token');
122
+ }
123
+
124
+ public function getSupportedCardTypes()
125
+ {
126
+ return explode(',', Mage::getStoreConfig('payment/ewayrapid_general/cctypes'));
127
+ }
128
+ }
app/code/community/Eway/Rapid31/Model/Customer/Savedtokens.php ADDED
@@ -0,0 +1,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()) && 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
+ }
app/code/community/Eway/Rapid31/Model/Customer/Token.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Eway_Rapid31_Model_Customer_Token
5
+ *
6
+ * @method int getToken()
7
+ * @method Eway_Rapid31_Model_Customer_Token setToken(int $value)
8
+ * @method string getCard()
9
+ * @method Eway_Rapid31_Model_Customer_Token setCard(string $value)
10
+ * @method string getType()
11
+ * @method Eway_Rapid31_Model_Customer_Token setType(string $value)
12
+ * @method string getOwner()
13
+ * @method Eway_Rapid31_Model_Customer_Token setOwner(string $value)
14
+ * @method string getStartMonth()
15
+ * @method Eway_Rapid31_Model_Customer_Token setStartMonth(string $value)
16
+ * @method string getStartYear()
17
+ * @method Eway_Rapid31_Model_Customer_Token setStartYear(string $value)
18
+ * @method string getIssueNumber()
19
+ * @method Eway_Rapid31_Model_Customer_Token setIssueNumber(string $value)
20
+ * @method int getExpMonth()
21
+ * @method Eway_Rapid31_Model_Customer_Token setExpMonth(int $value)
22
+ * @method int getExpYear()
23
+ * @method Eway_Rapid31_Model_Customer_Token setExpYear(int $value)
24
+ * @method bool getActive()
25
+ * @method Eway_Rapid31_Model_Customer_Token setActive(bool $value)
26
+ * @method Eway_Rapid31_Model_Field_Customer getAddress()
27
+ * @method Eway_Rapid31_Model_Customer_Token setAddress(Eway_Rapid31_Model_Field_Customer $value)
28
+ */
29
+ class Eway_Rapid31_Model_Customer_Token extends Eway_Rapid31_Model_JsonSerializableAbstract
30
+ {
31
+
32
+ }
app/code/community/Eway/Rapid31/Model/EwayCron.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: Administrator PC
5
+ * Date: 7/31/14
6
+ * Time: 4:38 PM
7
+ */
8
+ class Eway_Rapid31_Model_EwayCron {
9
+
10
+ public function querySuspectFraud() {
11
+
12
+ // Load orders with fraud in 7 days before from now
13
+ $orders = Mage::getModel('sales/order')->getCollection()
14
+ ->addFieldToFilter('status', array('eq' => 'fraud')) // State fraud
15
+ ->addFieldToFilter('eway_transaction_id', array('notnull' => ''))
16
+ ->addFieldToFilter('created_at', array('to' => date('Y-m-d 23:59:59'), 'from' => date('Y-m-d 00:00:01', strtotime('-7 days'))));
17
+
18
+ foreach ($orders as $o) {
19
+ $transactionId = $o->getEwayTransactionId();
20
+
21
+ // continue when order does not contain eway transaction
22
+ if (!$transactionId) {
23
+ continue;
24
+ }
25
+ $result = $this->__getTransaction($transactionId);
26
+ $result_decode = json_decode($result);
27
+ // continue when property transaction is not exist
28
+ if (!property_exists($result_decode, 'Transactions') || empty($result_decode->Transactions)) {
29
+ continue;
30
+ }
31
+ $trans = $result_decode->Transactions;
32
+
33
+ // continue when transaction is not exits
34
+ if (!isset($trans[0])) {
35
+ continue;
36
+ }
37
+ $tranId = $trans[0]->TransactionID;
38
+
39
+ // Success - Fraud order has been approved
40
+ if ($trans[0]->ResponseMessage == 'A2000') {
41
+ // Create new transaction
42
+ $this->__createNewTransaction($o, $tranId);
43
+ // Update order status
44
+ $this->__updateStatusOrder($o);
45
+ // Un-mark fraud customer
46
+ $this->__unMarkFraudUser($o);
47
+ }
48
+ }
49
+ // Response data to client
50
+ /*$this->getResponse()->setHeader('Content-type', 'application/json');
51
+ $this->getResponse()->setBody($result);*/
52
+ }
53
+
54
+ private function __getTransaction($transId) {
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
+ private function __createNewTransaction(Mage_Sales_Model_Order $order, $transId) {
75
+
76
+ // Load transaction
77
+ $currentTrans = Mage::getModel('sales/order_payment_transaction')
78
+ ->getCollection()
79
+ ->addFieldToFilter('order_id', array('eq' => $order->getEntityId()));
80
+ foreach($currentTrans as $t) { }
81
+ if($t == null) {
82
+ $t = new Mage_Sales_Model_Order_Payment_Transaction();
83
+ }
84
+
85
+ $trans = new Mage_Sales_Model_Order_Payment_Transaction();
86
+ // Load payment object
87
+ $payment = Mage::getModel('sales/order_payment')->load($t->getPaymentId());
88
+
89
+ $trans->setOrderPaymentObject($payment);
90
+ $trans->setOrder($order);
91
+
92
+ $trans->setParentId($t->getTransactionId());
93
+ $trans->setOrderId($order->getEntityId());
94
+ $trans->setPaymentId($t->getPaymentId());
95
+ // Get new TxnId
96
+ $break = true;
97
+ for($i = 0; $i < 100; $i++) {
98
+ $transId += 1;
99
+ $newTrans = Mage::getModel('sales/order_payment_transaction')
100
+ ->getCollection()
101
+ ->addFieldToFilter('txn_id', array('eq' => $transId));
102
+ if(count($newTrans) == 0) {
103
+ $break = false;
104
+ break;
105
+ }
106
+ }
107
+ if($break) {
108
+ return false;
109
+ }
110
+ $trans->setTxnId($transId);
111
+ $trans->setParentTxnId($t->getTxnId());
112
+ $trans->setTxnType($t->getTxnType());
113
+ $trans->setIsClosed($t->getIsClosed());
114
+ $trans->setCreatedAt(date('Y-m-d H:i:s'));
115
+ $trans->save();
116
+
117
+ }
118
+
119
+ private function __updateStatusOrder(Mage_Sales_Model_Order $order) {
120
+ $state_config = Mage::getStoreConfig('payment/ewayrapid_general/verify_eway_order');
121
+
122
+ $order->setState($state_config);
123
+ $order->setStatus($state_config);
124
+ $order->save();
125
+ }
126
+
127
+ private function __unMarkFraudUser(Mage_Sales_Model_Order $order) {
128
+ $uid = $order->getCustomerId();
129
+ if ($uid) {
130
+ $customer = Mage::getModel('customer/customer')->load($uid);
131
+ $customer->setMarkFraud(0);
132
+ $customer->save();
133
+ }
134
+ }
135
+ }
app/code/community/Eway/Rapid31/Model/Field/CardDetails.php ADDED
@@ -0,0 +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
+ }
app/code/community/Eway/Rapid31/Model/Field/Customer.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Eway_Rapid31_Model_Field_Customer
5
+ *
6
+ * @method long getTokenCustomerID()
7
+ * @method Eway_Rapid31_Model_Field_Customer setTokenCustomerID(long $value)
8
+ * @method string getReference()
9
+ * @method Eway_Rapid31_Model_Field_Customer setReference(string $value)
10
+ * @method string getTitle()
11
+ * @method Eway_Rapid31_Model_Field_Customer setTitle(string $value)
12
+ * @method string getFirstName()
13
+ * @method Eway_Rapid31_Model_Field_Customer setFirstName(string $value)
14
+ * @method string getLastName()
15
+ * @method Eway_Rapid31_Model_Field_Customer setLastName(string $value)
16
+ * @method string getCompanyName()
17
+ * @method Eway_Rapid31_Model_Field_Customer setCompanyName(string $value)
18
+ * @method string getJobDescription()
19
+ * @method Eway_Rapid31_Model_Field_Customer setJobDescription(string $value)
20
+ * @method string getStreet1()
21
+ * @method Eway_Rapid31_Model_Field_Customer setStreet1(string $value)
22
+ * @method string getStreet2()
23
+ * @method Eway_Rapid31_Model_Field_Customer setStreet2(string $value)
24
+ * @method string getCity()
25
+ * @method Eway_Rapid31_Model_Field_Customer setCity(string $value)
26
+ * @method string getState()
27
+ * @method Eway_Rapid31_Model_Field_Customer setState(string $value)
28
+ * @method string getPostalCode()
29
+ * @method Eway_Rapid31_Model_Field_Customer setPostalCode(string $value)
30
+ * @method string getCountry()
31
+ * @method Eway_Rapid31_Model_Field_Customer setCountry(string $value)
32
+ * @method string getEmail()
33
+ * @method Eway_Rapid31_Model_Field_Customer setEmail(string $value)
34
+ * @method string getPhone()
35
+ * @method Eway_Rapid31_Model_Field_Customer setPhone(string $value)
36
+ * @method string getMobile()
37
+ * @method Eway_Rapid31_Model_Field_Customer setMobile(string $value)
38
+ * @method string getComments()
39
+ * @method Eway_Rapid31_Model_Field_Customer setComments(string $value)
40
+ * @method string getFax()
41
+ * @method Eway_Rapid31_Model_Field_Customer setFax(string $value)
42
+ * @method string getUrl()
43
+ * @method Eway_Rapid31_Model_Field_Customer setUrl(string $value)
44
+ * @method Eway_Rapid31_Model_Field_CardDetails getCardDetails()
45
+ * @method Eway_Rapid31_Model_Field_Customer setCardDetails(Eway_Rapid31_Model_Field_CardDetails $value)
46
+ * @method bool getIsActive()
47
+ * @method Eway_Rapid31_Model_Field_Customer setIsActive(bool $value)
48
+ */
49
+ class Eway_Rapid31_Model_Field_Customer extends Eway_Rapid31_Model_JsonSerializableAbstract
50
+ {
51
+ }
app/code/community/Eway/Rapid31/Model/Field/LineItem.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Eway_Rapid31_Model_Field_LineItem
5
+ *
6
+ * @method string getSKU()
7
+ * @method Eway_Rapid31_Model_Field_LineItem setSKU(string $value)
8
+ * @method string getDescription()
9
+ * @method Eway_Rapid31_Model_Field_LineItem setDescription(string $value)
10
+ * @method int getQuantity()
11
+ * @method Eway_Rapid31_Model_Field_LineItem setQuantity(int $value)
12
+ * @method int getUnitCost()
13
+ * @method Eway_Rapid31_Model_Field_LineItem setUnitCost(int $value)
14
+ * @method int getTax()
15
+ * @method Eway_Rapid31_Model_Field_LineItem setTax(int $value)
16
+ * @method int getTotal()
17
+ * @method Eway_Rapid31_Model_Field_LineItem setTotal(int $value)
18
+ */
19
+ class Eway_Rapid31_Model_Field_LineItem extends Eway_Rapid31_Model_JsonSerializableAbstract
20
+ {
21
+ }
app/code/community/Eway/Rapid31/Model/Field/Payment.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Eway_Rapid31_Model_Field_Payment
5
+ *
6
+ * @method int getTotalAmount()
7
+ * @method Eway_Rapid31_Model_Field_Payment setTotalAmount(int $value)
8
+ * @method string getInvoiceNumber()
9
+ * @method Eway_Rapid31_Model_Field_Payment setInvoiceNumber(string $value)
10
+ * @method string getInvoiceDescription()
11
+ * @method Eway_Rapid31_Model_Field_Payment setInvoiceDescription(string $value)
12
+ * @method string getInvoiceReference()
13
+ * @method Eway_Rapid31_Model_Field_Payment setInvoiceReference(string $value)
14
+ * @method string getCurrencyCode()
15
+ * @method Eway_Rapid31_Model_Field_Payment setCurrencyCode(string $value)
16
+ * @method string getTransactionID()
17
+ * @method Eway_Rapid31_Model_Field_Payment setTransactionID(string $value)
18
+ * @method Array getShippingAddress()
19
+ * @method Eway_Rapid31_Model_Field_Payment setShippingAddress(Eway_Rapid31_Model_Field_ShippingAddress $value)
20
+ */
21
+ class Eway_Rapid31_Model_Field_Payment extends Eway_Rapid31_Model_JsonSerializableAbstract
22
+ {
23
+
24
+ }
app/code/community/Eway/Rapid31/Model/Field/ShippingAddress.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class Eway_Rapid31_Model_Field_ShippingAddress
5
+ *
6
+ * @method string getFirstName()
7
+ * @method Eway_Rapid31_Model_Field_ShippingAddress setFirstName(string $value)
8
+ * @method string getLastName()
9
+ * @method Eway_Rapid31_Model_Field_ShippingAddress setLastName(string $value)
10
+ * @method string getStreet1()
11
+ * @method Eway_Rapid31_Model_Field_ShippingAddress setStreet1(string $value)
12
+ * @method string getStreet2()
13
+ * @method Eway_Rapid31_Model_Field_ShippingAddress setStreet2(string $value)
14
+ * @method string getCity()
15
+ * @method Eway_Rapid31_Model_Field_ShippingAddress setCity(string $value)
16
+ * @method string getState()
17
+ * @method Eway_Rapid31_Model_Field_ShippingAddress setState(string $value)
18
+ * @method string getCountry()
19
+ * @method Eway_Rapid31_Model_Field_ShippingAddress setCountry(string $value)
20
+ * @method string getPostalCode()
21
+ * @method Eway_Rapid31_Model_Field_ShippingAddress setPostalCode(string $value)
22
+ * @method string getEmail()
23
+ * @method Eway_Rapid31_Model_Field_ShippingAddress setEmail(string $value)
24
+ * @method string getPhone()
25
+ * @method Eway_Rapid31_Model_Field_ShippingAddress setPhone(string $value)
26
+ */
27
+ class Eway_Rapid31_Model_Field_ShippingAddress extends Eway_Rapid31_Model_JsonSerializableAbstract
28
+ {
29
+
30
+ }
app/code/community/Eway/Rapid31/Model/JsonSerializable.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ interface Eway_Rapid31_Model_JsonSerializable
3
+ {
4
+ public function jsonSerialize();
5
+ public function getJsonData(array $rawData = null);
6
+ }
app/code/community/Eway/Rapid31/Model/JsonSerializableAbstract.php ADDED
@@ -0,0 +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
+ }
app/code/community/Eway/Rapid31/Model/Method/Notsaved.php ADDED
@@ -0,0 +1,471 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = true;
28
+ protected $_canManageRecurringProfiles = true;
29
+ protected $_connectionType;
30
+ protected $_isBackendOrder;
31
+
32
+ public function __construct()
33
+ {
34
+ parent::__construct();
35
+ $this->_isBackendOrder = Mage::helper('ewayrapid')->isBackendOrder();
36
+ $this->_connectionType = Mage::getStoreConfig('payment/ewayrapid_general/connection_type');
37
+ if (!$this->_isBackendOrder) {
38
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
39
+ $this->_infoBlockType = 'ewayrapid/info_transparent_notsaved';
40
+ $this->_formBlockType = 'ewayrapid/form_transparent_notsaved';
41
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
42
+ $this->_infoBlockType = 'ewayrapid/info_sharedpage_notsaved';
43
+ $this->_formBlockType = 'ewayrapid/form_sharedpage_notsaved';
44
+ }
45
+ }
46
+ }
47
+
48
+ public function getConfigData($field, $storeId = null)
49
+ {
50
+ $data = parent::getConfigData($field, $storeId);
51
+ if($data === null) {
52
+ return $this->_getGeneralConfig($field, $storeId);
53
+ } else {
54
+ switch($field) {
55
+ case 'active':
56
+ return $data && $this->_isActive($storeId);
57
+ default:
58
+ return $data;
59
+ }
60
+ }
61
+ }
62
+
63
+ protected function _getGeneralConfig($field, $storeId = null)
64
+ {
65
+ if (null === $storeId) {
66
+ $storeId = $this->getStore();
67
+ }
68
+ $path = 'payment/ewayrapid_general/'.$field;
69
+ return Mage::getStoreConfig($path, $storeId);
70
+ }
71
+
72
+ protected function _isActive($storeId)
73
+ {
74
+ return $this->_getGeneralConfig('active', $storeId);
75
+ }
76
+
77
+ /**
78
+ * Assign data to info model instance
79
+ *
80
+ * @param mixed $data
81
+ * @return Mage_Payment_Model_Info
82
+ */
83
+ public function assignData($data)
84
+ {
85
+ if (!($data instanceof Varien_Object)) {
86
+ $data = new Varien_Object($data);
87
+ }
88
+ $info = $this->getInfoInstance();
89
+
90
+ if (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
91
+ //Mage::getSingleton('core/session')->setData('sharedpagePaypal', $data->getSharedpageNotsaved());
92
+ Mage::getSingleton('core/session')->setData('sharedpagePaypal', 'paypal');
93
+ } elseif (!$this->_isBackendOrder && $this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
94
+ $info->setTransparentNotsaved($data->getTransparentNotsaved());
95
+
96
+ //Option choice
97
+ if ($data->getMethod() == 'ewayrapid_saved' && !$data->getTransparentSaved()) {
98
+ Mage::throwException(Mage::helper('payment')->__('Please select an option payment for eWay saved'));
99
+ } elseif ($data->getMethod() == 'ewayrapid_notsaved' && !$data->getTransparentNotsaved()) {
100
+ Mage::throwException(Mage::helper('payment')->__('Please select an option payment for eWay not saved'));
101
+ }
102
+
103
+ //New Token
104
+ if ($data->getMethod() == 'ewayrapid_saved'
105
+ && $data->getTransparentSaved() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
106
+ && $data->getSavedToken() == Eway_Rapid31_Model_Config::TOKEN_NEW
107
+ && Mage::helper('ewayrapid/customer')->checkTokenListByType(Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD)
108
+ ) {
109
+ Mage::throwException(Mage::helper('payment')->__('You could only save one PayPal account, please select PayPal account existed to payent.'));
110
+ }
111
+
112
+ if ($data->getTransparentNotsaved())
113
+ Mage::getSingleton('core/session')->setTransparentNotsaved($data->getTransparentNotsaved());
114
+
115
+ if ($data->getTransparentSaved())
116
+ Mage::getSingleton('core/session')->setTransparentSaved($data->getTransparentSaved());
117
+
118
+ if ($data->getMethod())
119
+ Mage::getSingleton('core/session')->setMethod($data->getMethod());
120
+
121
+ if ($data->getSavedToken()) {
122
+ Mage::getSingleton('core/session')->setSavedToken($data->getSavedToken());
123
+ if(is_numeric($data->getSavedToken())) {
124
+ $token = Mage::helper('ewayrapid/customer')->getTokenById($data->getSavedToken());
125
+ /* @var Eway_Rapid31_Model_Request_Token $model */
126
+ $model = Mage::getModel('ewayrapid/request_token');
127
+ $type = $model->checkCardName($token);
128
+ Mage::getSingleton('core/session')->setTransparentSaved($type);
129
+ unset($model);
130
+ unset($token);
131
+ }
132
+ }
133
+
134
+ $infoCard = new Varien_Object();
135
+ Mage::getSingleton('core/session')->setInfoCard(
136
+ $infoCard->setCcType($data->getCcType())
137
+ ->setOwner($data->getCcOwner())
138
+ ->setLast4($this->_isClientSideEncrypted($data->getCcNumber()) ? 'encrypted' : substr($data->getCcNumber(), -4))
139
+ ->setCard($data->getCcNumber())
140
+ ->setNumber($data->getCcNumber())
141
+ ->setCid($data->getCcCid())
142
+ ->setExpMonth($data->getCcExpMonth())
143
+ ->setExpYear($data->getCcExpYear()
144
+ ));
145
+
146
+ } else {
147
+ $info->setCcType($data->getCcType())
148
+ ->setCcOwner($data->getCcOwner())
149
+ ->setCcLast4($this->_isClientSideEncrypted($data->getCcNumber()) ? 'encrypted' : substr($data->getCcNumber(), -4))
150
+ ->setCcNumber($data->getCcNumber())
151
+ ->setCcCid($data->getCcCid())
152
+ ->setCcExpMonth($data->getCcExpMonth())
153
+ ->setCcExpYear($data->getCcExpYear());
154
+ }
155
+
156
+ return $this;
157
+ }
158
+
159
+ protected function _isClientSideEncrypted($ccNumber)
160
+ {
161
+ return (strlen($ccNumber) > 19 && strpos($ccNumber, Eway_Rapid31_Model_Config::ENCRYPTION_PREFIX) !== false);
162
+ }
163
+
164
+ /**
165
+ * Validate payment method information object
166
+ *
167
+ * @param Mage_Payment_Model_Info $info
168
+ * @return Mage_Payment_Model_Abstract
169
+ */
170
+ public function validate()
171
+ {
172
+ /*
173
+ * calling parent validate function
174
+ */
175
+ parent::validate();
176
+ if (!$this->_isBackendOrder) {
177
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
178
+ return $this;
179
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
180
+ return $this;
181
+ }
182
+ }
183
+ $info = $this->getInfoInstance();
184
+ $errorMsg = false;
185
+ $availableTypes = explode(',',$this->getConfigData('cctypes'));
186
+
187
+ $ccNumber = $info->getCcNumber();
188
+
189
+ // Cannot do normal validation in case client side encrypted
190
+ if($this->_isClientSideEncrypted($ccNumber)) {
191
+ return true;
192
+ }
193
+
194
+ // remove credit card number delimiters such as "-" and space
195
+ $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
196
+ $info->setCcNumber($ccNumber);
197
+
198
+ $ccType = '';
199
+
200
+ if (in_array($info->getCcType(), $availableTypes)){
201
+ if ($this->validateCcNum($ccNumber)) {
202
+ $ccTypeRegExpList = array(
203
+ // Visa Electron
204
+ 'VE' => '/^(4026|4405|4508|4844|4913|4917)[0-9]{12}|417500[0-9]{10}$/',
205
+ // Maestro
206
+ '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}$))/',
207
+ // Visa
208
+ 'VI' => '/^4[0-9]{12}([0-9]{3})?$/',
209
+ // Master Card
210
+ 'MC' => '/^5[1-5][0-9]{14}$/',
211
+ // American Express
212
+ 'AE' => '/^3[47][0-9]{13}$/',
213
+ // JCB
214
+ 'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/',
215
+ // Diners Club
216
+ 'DC' => '/^3(?:0[0-5]|[68][0-9])[0-9]{11}$/',
217
+ );
218
+
219
+ foreach ($ccTypeRegExpList as $ccTypeMatch=>$ccTypeRegExp) {
220
+ if (preg_match($ccTypeRegExp, $ccNumber)) {
221
+ $ccType = $ccTypeMatch;
222
+ break;
223
+ }
224
+ }
225
+
226
+ if ($ccType!=$info->getCcType()) {
227
+ $errorMsg = Mage::helper('payment')->__('Credit card number mismatch with credit card type.');
228
+ }
229
+ } else {
230
+ $errorMsg = Mage::helper('payment')->__('Invalid Credit Card Number');
231
+ }
232
+
233
+ } else {
234
+ $errorMsg = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
235
+ }
236
+
237
+ //validate credit card verification number
238
+ if ($errorMsg === false && $this->hasVerification()) {
239
+ $verifcationRegEx = $this->getVerificationRegEx();
240
+ $regExp = isset($verifcationRegEx[$info->getCcType()]) ? $verifcationRegEx[$info->getCcType()] : '';
241
+ if (!$info->getCcCid() || !$regExp || !preg_match($regExp ,$info->getCcCid())){
242
+ $errorMsg = Mage::helper('payment')->__('Please enter a valid credit card verification number.');
243
+ }
244
+ }
245
+
246
+ if (!$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth())) {
247
+ $errorMsg = Mage::helper('payment')->__('Incorrect credit card expiration date.');
248
+ }
249
+
250
+ if($errorMsg){
251
+ Mage::throwException($errorMsg);
252
+ }
253
+
254
+ return $this;
255
+ }
256
+
257
+ public function hasVerification()
258
+ {
259
+ if(Mage::helper('ewayrapid')->isBackendOrder()) {
260
+ return false;
261
+ }
262
+
263
+ $configData = $this->getConfigData('useccv');
264
+ if(is_null($configData)){
265
+ return true;
266
+ }
267
+ return (bool) $configData;
268
+ }
269
+
270
+ public function getVerificationRegEx()
271
+ {
272
+ $verificationExpList = array(
273
+ 'VI' => '/^[0-9]{3}$/', // Visa
274
+ 'VE' => '/^[0-9]{3}$/', // Visa Electron
275
+ 'MC' => '/^[0-9]{3}$/', // Master Card
276
+ 'ME' => '/^[0-9]{3,4}$/', // Maestro
277
+ 'AE' => '/^[0-9]{4}$/', // American Express
278
+ 'DC' => '/^[0-9]{3}$/', // Diners Club
279
+ 'JCB' => '/^[0-9]{3,4}$/' //JCB
280
+ );
281
+ return $verificationExpList;
282
+ }
283
+
284
+ protected function _validateExpDate($expYear, $expMonth)
285
+ {
286
+ $date = Mage::app()->getLocale()->date();
287
+ if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
288
+ || ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1))
289
+ ) {
290
+ return false;
291
+ }
292
+ return true;
293
+ }
294
+
295
+ /**
296
+ * Validate credit card number
297
+ *
298
+ * @param string $cc_number
299
+ * @return bool
300
+ */
301
+ public function validateCcNum($ccNumber)
302
+ {
303
+ $cardNumber = strrev($ccNumber);
304
+ $numSum = 0;
305
+
306
+ for ($i=0; $i<strlen($cardNumber); $i++) {
307
+ $currentNum = substr($cardNumber, $i, 1);
308
+
309
+ /**
310
+ * Double every second digit
311
+ */
312
+ if ($i % 2 == 1) {
313
+ $currentNum *= 2;
314
+ }
315
+
316
+ /**
317
+ * Add digits of 2-digit numbers together
318
+ */
319
+ if ($currentNum > 9) {
320
+ $firstNum = $currentNum % 10;
321
+ $secondNum = ($currentNum - $firstNum) / 10;
322
+ $currentNum = $firstNum + $secondNum;
323
+ }
324
+
325
+ $numSum += $currentNum;
326
+ }
327
+
328
+ /**
329
+ * If the total has no remainder it's OK
330
+ */
331
+ return ($numSum % 10 == 0);
332
+ }
333
+
334
+ /**
335
+ * Authorize & Capture a payment
336
+ *
337
+ * @param Varien_Object $payment
338
+ * @param float $amount
339
+ *
340
+ * @return Mage_Payment_Model_Abstract
341
+ */
342
+ public function capture(Varien_Object $payment, $amount)
343
+ {
344
+ if (!$this->_isBackendOrder) {
345
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
346
+ $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
347
+ $payment->setTransactionId($transID);
348
+ $payment->setIsTransactionClosed(0);
349
+ Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
350
+ return $this;
351
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
352
+ $payment = Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
353
+ return $this;
354
+ }
355
+ }
356
+
357
+ /* @var Mage_Sales_Model_Order_Payment $payment */
358
+ if ($amount <= 0) {
359
+ Mage::throwException(Mage::helper('paygate')->__('Invalid amount for capture.'));
360
+ }
361
+
362
+ $amount = round($amount * 100);
363
+ $request = Mage::getModel('ewayrapid/request_direct');
364
+ if($this->_isPreauthCapture($payment)) {
365
+ $request->doCapturePayment($payment, $amount);
366
+ } else {
367
+ $request->doTransaction($payment, $amount);
368
+ }
369
+
370
+ return $this;
371
+ }
372
+
373
+ /**
374
+ * Authorize a payment
375
+ *
376
+ * @param Varien_Object $payment
377
+ * @param float $amount
378
+ *
379
+ * @return Mage_Payment_Model_Abstract
380
+ */
381
+ public function authorize(Varien_Object $payment, $amount)
382
+ {
383
+ if (!$this->_isBackendOrder) {
384
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
385
+ $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
386
+ $payment->setTransactionId($transID);
387
+ $payment->setIsTransactionClosed(0);
388
+ Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
389
+ return $this;
390
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT ) {
391
+ $payment = Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
392
+ return $this;
393
+ }
394
+ }
395
+
396
+ /* @var Mage_Sales_Model_Order_Payment $payment */
397
+ if ($amount <= 0) {
398
+ Mage::throwException(Mage::helper('paygate')->__('Invalid amount for authorize.'));
399
+ }
400
+
401
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT
402
+ ) {
403
+ //Mage::app()->getResponse()->setRedirect(Mage::getUrl('ewayrapid/transparent/'))->sendResponse();
404
+ //exit;
405
+ }
406
+
407
+ $amount = round($amount * 100);
408
+ $request = Mage::getModel('ewayrapid/request_direct');
409
+ $request->doAuthorisation($payment, $amount);
410
+
411
+ return $this;
412
+ }
413
+
414
+ /**
415
+ * Refund a payment
416
+ *
417
+ * @param Varien_Object $payment
418
+ * @param float $amount
419
+ *
420
+ * @return Mage_Payment_Model_Abstract
421
+ */
422
+ public function refund(Varien_Object $payment, $amount)
423
+ {
424
+ /* @var Mage_Sales_Model_Order_Payment $payment */
425
+ if ($amount <= 0) {
426
+ Mage::throwException(Mage::helper('paygate')->__('Invalid amount for refund.'));
427
+ }
428
+
429
+ $amount = round($amount * 100);
430
+ $request = Mage::getModel('ewayrapid/request_direct');
431
+ $request->doRefund($payment, $amount);
432
+
433
+ return $this;
434
+ }
435
+
436
+ /**
437
+ * Cancel a payment
438
+ *
439
+ * @param Varien_Object $payment
440
+ *
441
+ * @return Mage_Payment_Model_Abstract
442
+ */
443
+ public function cancel(Varien_Object $payment)
444
+ {
445
+ /* @var Mage_Sales_Model_Order_Payment $payment */
446
+ $request = Mage::getModel('ewayrapid/request_direct');
447
+ $request->doCancel($payment);
448
+
449
+ return $this;
450
+ }
451
+
452
+ protected function _isPreauthCapture(Mage_Sales_Model_Order_Payment $payment)
453
+ {
454
+ return (bool) $payment->getLastTransId();
455
+ }
456
+
457
+ public function canVoid(Varien_Object $payment)
458
+ {
459
+ return $this->_canVoid && (Mage::app()->getRequest()->getActionName() == 'cancel');
460
+ }
461
+
462
+ public function getCheckoutRedirectUrl()
463
+ {
464
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
465
+ === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
466
+ ) {
467
+ return Mage::getUrl('ewayrapid/sharedpage/start');
468
+ }
469
+ return null;
470
+ }
471
+ }
app/code/community/Eway/Rapid31/Model/Method/Saved.php ADDED
@@ -0,0 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
57
+ && !$this->_isBackendOrder
58
+ ) {
59
+ Mage::getSingleton('core/session')->setData('newToken', 1);
60
+ }
61
+ $info->setIsNewToken(true);
62
+ } else {
63
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
64
+ && !$this->_isBackendOrder
65
+ ) {
66
+ Mage::getSingleton('core/session')->setData('editToken', $data->getSavedToken());
67
+ }
68
+
69
+ $info->setSavedToken($data->getSavedToken());
70
+ // Update token
71
+ if($data->getCcOwner()) {
72
+ $info->setIsUpdateToken(true);
73
+ }
74
+ }
75
+
76
+ parent::assignData($data);
77
+
78
+ Mage::helper('ewayrapid')->serializeInfoInstance($info);
79
+
80
+ return $this;
81
+ }
82
+
83
+ /**
84
+ * Validate payment method information object
85
+ *
86
+ * @param Mage_Payment_Model_Info $info
87
+ * @return Mage_Payment_Model_Abstract
88
+ */
89
+ public function validate()
90
+ {
91
+ $info = $this->getInfoInstance();
92
+ if($info->getIsNewToken()) {
93
+ parent::validate();
94
+ } else {
95
+ // TODO: Check if this token is still Active using GET /Customer endpoint.
96
+ }
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
+ //$payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
120
+ Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
121
+ return $this;
122
+ }
123
+ }
124
+
125
+ /* @var Mage_Sales_Model_Order_Payment $payment */
126
+ if ($amount <= 0) {
127
+ Mage::throwException(Mage::helper('paygate')->__('Invalid amount for capture.'));
128
+ }
129
+ $request = Mage::getModel('ewayrapid/request_token');
130
+
131
+ $amount = round($amount * 100);
132
+ if($this->_isPreauthCapture($payment)) {
133
+ $previousCapture = $payment->lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
134
+ if($previousCapture) {
135
+ $customer = Mage::getModel('customer/customer')->load($payment->getOrder()->getCustomerId());
136
+ Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
137
+
138
+ /* @var Mage_Sales_Model_Order_Payment_Transaction $previousCapture */
139
+ $request->doTransaction($payment, $amount);
140
+ $payment->setParentTransactionId($previousCapture->getParentTxnId());
141
+ } else {
142
+ $request->doCapturePayment($payment, $amount);
143
+ }
144
+ } else {
145
+ if (!$payment->getIsRecurring()) {
146
+ $this->_shouldCreateOrUpdateToken($payment, $request);
147
+ }
148
+ $request->doTransaction($payment, $amount);
149
+ }
150
+
151
+ return $this;
152
+ }
153
+
154
+ /**
155
+ * Authorize a payment
156
+ *
157
+ * @param Varien_Object $payment
158
+ * @param float $amount
159
+ *
160
+ * @return Mage_Payment_Model_Abstract
161
+ */
162
+ public function authorize(Varien_Object $payment, $amount)
163
+ {
164
+ if (!$this->_isBackendOrder) {
165
+ if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
166
+ $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
167
+ $payment->setTransactionId($transID);
168
+ $payment->setIsTransactionClosed(0);
169
+ Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
170
+ return $this;
171
+ } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
172
+ //$payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
173
+ Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
174
+ return $this;
175
+ }
176
+ }
177
+
178
+ /* @var Mage_Sales_Model_Order_Payment $payment */
179
+ if ($amount <= 0) {
180
+ Mage::throwException(Mage::helper('paygate')->__('Invalid amount for authorize.'));
181
+ }
182
+ $request = Mage::getModel('ewayrapid/request_token');
183
+
184
+ /** @todo there's an error in case recurring profile */
185
+ if (!$payment->getIsRecurring()) {
186
+ $this->_shouldCreateOrUpdateToken($payment, $request);
187
+ }
188
+
189
+ $amount = round($amount * 100);
190
+ $request->doAuthorisation($payment, $amount);
191
+
192
+ return $this;
193
+ }
194
+
195
+ /**
196
+ * @param Mage_Sales_Model_Order_Payment $payment
197
+ * @param Eway_Rapid31_Model_Request_Token $request
198
+ */
199
+ public function _shouldCreateOrUpdateToken(Mage_Sales_Model_Order_Payment $payment, Eway_Rapid31_Model_Request_Token $request)
200
+ {
201
+ $order = $payment->getOrder();
202
+ $billing = ($this->_getBilling() == null) ? $order->getBillingAddress() : $this->_getBilling();
203
+ $info = $this->getInfoInstance();
204
+
205
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
206
+ if ($info->getIsNewToken()) {
207
+ $request->createNewToken($billing, $info);
208
+ $info->setSavedToken(Mage::helper('ewayrapid/customer')->getLastTokenId());
209
+ Mage::helper('ewayrapid')->serializeInfoInstance($info);
210
+ } elseif ($info->getIsUpdateToken()) {
211
+ $request->updateToken($billing, $info);
212
+ }
213
+ }
214
+
215
+ public function _setBilling(Mage_Sales_Model_Quote_Address $billing)
216
+ {
217
+ $this->_billing = $billing;
218
+ }
219
+
220
+ public function _getBilling()
221
+ {
222
+ return $this->_billing;
223
+ }
224
+
225
+ /**
226
+ * Validate RP data
227
+ *
228
+ * @param Mage_Payment_Model_Recurring_Profile $profile
229
+ */
230
+ public function validateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
231
+ {
232
+
233
+ }
234
+
235
+ /**
236
+ * Submit RP to the gateway
237
+ *
238
+ * @param Mage_Payment_Model_Recurring_Profile $profile
239
+ * @param Mage_Payment_Model_Info $paymentInfo
240
+ */
241
+ public function submitRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile,
242
+ Mage_Payment_Model_Info $paymentInfo
243
+ ) {
244
+ $profile->setReferenceId(strtoupper(uniqid()));
245
+ $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE);
246
+ }
247
+
248
+ /**
249
+ * Fetch RP details
250
+ *
251
+ * @param string $referenceId
252
+ * @param Varien_Object $result
253
+ */
254
+ public function getRecurringProfileDetails($referenceId, Varien_Object $result)
255
+ {
256
+
257
+ }
258
+
259
+ /**
260
+ * Whether can get recurring profile details
261
+ */
262
+ public function canGetRecurringProfileDetails()
263
+ {
264
+ return true;
265
+ }
266
+
267
+ /**
268
+ * Update RP data
269
+ *
270
+ * @param Mage_Payment_Model_Recurring_Profile $profile
271
+ */
272
+ public function updateRecurringProfile(Mage_Payment_Model_Recurring_Profile $profile)
273
+ {
274
+
275
+ }
276
+
277
+ /**
278
+ * Manage status
279
+ *
280
+ * @param Mage_Payment_Model_Recurring_Profile $profile
281
+ */
282
+ public function updateRecurringProfileStatus(Mage_Payment_Model_Recurring_Profile $profile)
283
+ {
284
+
285
+ }
286
+ }
app/code/community/Eway/Rapid31/Model/Observer.php ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: Administrator PC
5
+ * Date: 7/18/14
6
+ * Time: 2:26 PM
7
+ */
8
+ class Eway_Rapid31_Model_Observer {
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
+ //echo 'You can\'t create new order. Please contact admin site.';
25
+ // do something here
26
+ // .....
27
+
28
+ Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
29
+ Mage::app()->getResponse()->sendResponse();
30
+ 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.'));
31
+ exit;
32
+ }
33
+ }
34
+ }
35
+
36
+ public function sales_order_save_before($observer) {
37
+
38
+ }
39
+
40
+ public function sales_order_save_after($observer) {
41
+
42
+ }
43
+
44
+ public function sales_order_place_before($observer) {
45
+ // Check order fraud here
46
+ // ...
47
+ $fraud = Mage::getSingleton('core/session')->getData('fraud');
48
+ if($fraud === 1) {
49
+
50
+ }
51
+ }
52
+
53
+ public function sales_order_place_after($observer) {
54
+ // Check order fraud here
55
+ // ...
56
+
57
+ $fraud = Mage::getSingleton('core/session')->getData('fraud');
58
+ if($fraud === 1) {
59
+
60
+ }
61
+ }
62
+
63
+ public function checkout_submit_all_after(Varien_Event_Observer $observer) {
64
+ $fraud = Mage::getSingleton('core/session')->getData('fraud');
65
+ $comment = Mage::getSingleton('core/session')->getData('fraudMessage');
66
+ // Read setting config enabled fraud or not
67
+ if($fraud === 1 && $order = $observer->getEvent()->getOrder()) {
68
+ $order->setState('fraud');
69
+ $order->setStatus('fraud');
70
+ if ($comment) {
71
+ $comment = 'An order is marked as Suspected Fraud. Because it contains: ' . $comment;
72
+ $order->addStatusHistoryComment($comment)
73
+ ->setIsVisibleOnFront(false)
74
+ ->setIsCustomerNotified(false);
75
+ }
76
+ $order->save();
77
+
78
+ // Update user to fraud
79
+ $session = Mage::getSingleton('customer/session');
80
+ if ($session->isLoggedIn()) {
81
+ $customer = $session->getCustomer();
82
+ $customer->setData('mark_fraud', 1);
83
+ $customer->save();
84
+ }
85
+
86
+ Mage::getSingleton('core/session')->unsetData('fraud');
87
+ Mage::getSingleton('core/session')->unsetData('fraudMessage');
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Update eway transaction for order
93
+ * @param Varien_Event_Observer $observer
94
+ */
95
+ public function checkout_type_onepage_save_order_after(Varien_Event_Observer $observer) {
96
+ $order = $observer->getData('order');
97
+ $order->setEwayTransactionId($order->getPayment()->getTransactionId());
98
+ $order->save();
99
+
100
+ }
101
+ /*
102
+ * create order of recurring profile
103
+ *
104
+ * @param Varien_Event_Observer $observer
105
+ */
106
+ public function createRecurringOrder(Varien_Event_Observer $observer)
107
+ {
108
+ $profiles = $observer->getEvent()->getRecurringProfiles();
109
+
110
+ if (isset($profiles[0])) {
111
+ /** @var Mage_Sales_Model_Recurring_Profile $profile */
112
+ $profile = $profiles[0];
113
+ } else {
114
+ return;
115
+ }
116
+
117
+ //if Billing Frequency <= 0 or isn't numeric, Status of recurring profile changed to canceled
118
+ if (!$profile->getPeriodFrequency()
119
+ || (string)(int) $profile->getPeriodFrequency() !== ltrim($profile->getPeriodFrequency(), '0')
120
+ || (int) $profile->getPeriodFrequency() <= 0
121
+ ) {
122
+ $profile->cancel();
123
+ 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'));
124
+ $session = Mage::getSingleton('checkout/type_onepage')->getCheckout();
125
+ $session->setLastRecurringProfileIds(null);
126
+ return;
127
+ }
128
+
129
+ $quote = $observer->getEvent()->getQuote();
130
+
131
+ /** @var Eway_Rapid31_Model_RecurringProfile $recurringProfile */
132
+ $recurringProfile = Mage::getModel('ewayrapid/recurringProfile');
133
+ $orderItemInfo = $profile->getOrderItemInfo();
134
+ $buyRequest = unserialize($orderItemInfo['info_buyRequest']);
135
+
136
+ // timezone used as store's timezone
137
+ $startDate = isset($buyRequest['recurring_profile_start_datetime']) && $buyRequest['recurring_profile_start_datetime'] ? $buyRequest['recurring_profile_start_datetime'] : null;
138
+
139
+ $additional = $profile->getAdditionalInfo();
140
+ $token = $recurringProfile->processToken($quote);
141
+ $token = json_decode($token, true);
142
+ $additional['token'] = $token;
143
+ $additional['startDate'] = $startDate;
144
+ $additional['initialFee'] = true;
145
+ $profile->setAdditionalInfo($additional);
146
+ $profile->save();
147
+
148
+ // charge Initial Fee if It is greater than 0 and is numeric
149
+ if ($profile->getInitAmount()
150
+ && (int) $profile->getInitAmount() > 0
151
+ && (string)(int) $profile->getInitAmount() === ltrim($profile->getInitAmount(), '0')
152
+ ) {
153
+ try {
154
+ $recurringProfile->processInitialFee($profile);
155
+ } catch (Exception $e) {
156
+ $additional = $profile->getAdditionalInfo();
157
+ $additional['initialFee'] = false;
158
+ if ($profile->getInitMayFail() == '1') {
159
+ // Allow Initial Fee Failure = yes
160
+ // change status recurring profile = suspended
161
+ $profile->suspend();
162
+ $errorMessage = Mage::getSingleton('core/session')->getData('errorMessage');
163
+ 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));
164
+ return;
165
+
166
+ } else {
167
+ // Allow Initial Fee Failure = no
168
+ // Auto Bill on Next Cycle = no
169
+ // set additionalInfo['outstanding'] = Initial Fee
170
+ if (!$profile->getBillFailedLater()) {
171
+ $additional['outstanding'] = $profile->getInitAmount();
172
+ }
173
+ }
174
+ $profile->setAdditionalInfo($additional);
175
+ $profile->save();
176
+ }
177
+ }
178
+
179
+ // check current time >= started time
180
+ if (!$startDate || $recurringProfile->checkRecurringTimeStart($startDate)) {
181
+ try {
182
+ // create order
183
+ // before day = current date // check if frequency >1day
184
+ // next day with current date
185
+ $recurringProfile->processRequest($profile);
186
+ } catch (Exception $e) {
187
+ $errorMessage = Mage::getSingleton('core/session')->getData('errorMessage');
188
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. (Error message: %s)', $errorMessage));
189
+ // suspend recurring profile when response data contains error and/or TransactionID is null
190
+ $checkPaymentFailures = $recurringProfile->checkMaxPaymentFailures($profile);
191
+ if (!$checkPaymentFailures) {
192
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Out of Payment failures. Status of recurring profile is changed to suspended.'));
193
+ }
194
+ return;
195
+ }
196
+ } else {
197
+ // not created order
198
+ // before day = null
199
+ // next day = date of started time
200
+ $additionalInfo = $profile->getAdditionalInfo();
201
+ $additionalInfo['nextDate'] = $startDate;
202
+ $profile->setAdditionalInfo($additionalInfo);
203
+ $profile->save();
204
+ }
205
+ }
206
+
207
+ /**
208
+ * load recurring profile if methodcode = ewayrapid_saved
209
+ *
210
+ * @param string $methodCode
211
+ * @return array
212
+ */
213
+ protected function _loadProfileByMethod($methodCode = 'ewayrapid_saved')
214
+ {
215
+ $modelRecurringProfile = Mage::getModel('sales/recurring_profile')->getCollection()
216
+ ->addFieldToFilter('method_code', $methodCode)
217
+ ->addFieldToFilter('state', 'active')
218
+ ->addFieldToFilter('additional_info', array('notnull' => true))
219
+ ->addFieldToFilter('period_max_cycles', array(
220
+ array('null' => true),
221
+ array('gt' => 0)
222
+ )
223
+ );
224
+ $profiles = array();
225
+
226
+ foreach ($modelRecurringProfile as $item) {
227
+ /** @var Mage_Sales_Model_Recurring_Profile $item */
228
+ $additionalInfo = unserialize($item->getAdditionalInfo());
229
+ $billingInfo = unserialize($item->getBillingAddressInfo());
230
+ $addressInfo = unserialize($item->getShippingAddressInfo());
231
+ $orderItemInfo = unserialize($item->getOrderItemInfo());
232
+ $orderInfo = unserialize($item->getOrderInfo());
233
+ $item->setBillingAddressInfo($billingInfo);
234
+ $item->setShippingAddressInfo($addressInfo);
235
+ $item->setOrderItemInfo($orderItemInfo);
236
+ $item->setAdditionalInfo($additionalInfo);
237
+ $item->setOrderInfo($orderInfo);
238
+ $profiles[] = $item;
239
+ }
240
+ return $profiles;
241
+ }
242
+
243
+ /**
244
+ * cron recurring profile to create order
245
+ */
246
+ public function cronRecurringOrder()
247
+ {
248
+ $profiles = $this->_loadProfileByMethod();
249
+ foreach ($profiles as $profile) {
250
+ /** @var Mage_Sales_Model_Recurring_Profile $profile */
251
+ /** @var Eway_Rapid31_Model_RecurringProfile $recurringProfile */
252
+ $recurringProfile = Mage::getModel('ewayrapid/recurringProfile');
253
+
254
+ $recurringProfile->updateNextDate($profile);
255
+
256
+ // check run cron job conditions
257
+ if ($recurringProfile->checkRecurringProfileRunCronJob($profile)) {
258
+ // check charge money initial Fee
259
+ $additional = $profile->getAdditionalInfo();
260
+ if ($additional['initialFee'] == false) {
261
+ if (!$profile->getInitMayFail() && $profile->getBillFailedLater()) {
262
+ try {
263
+ $recurringProfile->processInitialFee($profile);
264
+ $additional['initialFee'] = true;
265
+ $profile->setAdditionalInfo($additional);
266
+ $profile->save();
267
+ } catch (Exception $e) {
268
+ Mage::logException($e);
269
+ }
270
+ }
271
+ }
272
+
273
+ $profile->setIsCronJob(true);
274
+
275
+ try {
276
+ $recurringProfile->processRequest($profile);
277
+ } catch (Exception $e) {
278
+ $paymentFailures = $recurringProfile->checkMaxPaymentFailures($profile);
279
+ Mage::logException($e);
280
+ }
281
+ }
282
+ }
283
+ return;
284
+ }
285
+ }
app/code/community/Eway/Rapid31/Model/RecurringProfile.php ADDED
@@ -0,0 +1,526 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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') {
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
+ // timezone used as store's timezone
408
+ return strtotime(date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()))) >= strtotime($startDate);
409
+ }
410
+
411
+ /**
412
+ * process Initial Fee
413
+ *
414
+ * @param Mage_Sales_Model_Recurring_Profile $profile
415
+ */
416
+ public function processInitialFee(Mage_Sales_Model_Recurring_Profile $profile)
417
+ {
418
+ // charge Initial Fee
419
+ /** @var Mage_Sales_Model_Order $order */
420
+ $order = Mage::getModel('sales/order');
421
+ $amount = $profile->getInitAmount();
422
+ $shippingInfo = $profile->getShippingAddressInfo();
423
+ $shippingAddress = Mage::getModel('sales/order_address')
424
+ ->setData($shippingInfo)
425
+ ->setId(null);
426
+
427
+ $orderInfo = new Varien_Object($profile->getOrderInfo());
428
+ $currencyCode = $orderInfo->getBaseCurrencyCode();
429
+
430
+ $order->setShippingAddress($shippingAddress);
431
+ $order->setBaseCurrencyCode($currencyCode);
432
+
433
+ /** @var Mage_Sales_Model_Order_Payment $payment */
434
+ $payment = Mage::getModel('sales/order_payment');
435
+ $payment->setOrder($order);
436
+ $payment->setIsRecurring(true);
437
+ $payment->setIsInitialFee(true);
438
+
439
+ $customerId = $profile->getCustomerId();
440
+ $payment->setCustomerId($customerId);
441
+
442
+ $additionalInfo = $profile->getAdditionalInfo();
443
+ $tokenId = $additionalInfo['token']['saved_token'];
444
+ $payment->setTokenId($tokenId);
445
+
446
+ /** @var Eway_Rapid31_Model_Method_Saved $ewaySave */
447
+ $ewaySave = Mage::getModel('ewayrapid/method_saved');
448
+ $paymentAction = Mage::getStoreConfig('payment/ewayrapid_general/payment_action');
449
+ if ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
450
+ $ewaySave->authorize($payment, $amount);
451
+ } elseif ($paymentAction == Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
452
+ $ewaySave->capture($payment, $amount);
453
+ }
454
+ /** @todo: change status of order = "eWAY Authorised"
455
+ * now status order = "processing"
456
+ */
457
+ }
458
+
459
+ /**
460
+ * @param Mage_Sales_Model_Recurring_Profile $profile
461
+ */
462
+ public function updateNextDate(Mage_Sales_Model_Recurring_Profile $profile)
463
+ {
464
+ $timezone = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
465
+ $additionalInfo = $profile->getAdditionalInfo();
466
+ // timezone used as store's timezone
467
+ $nextDate = new DateTime(date("Y-m-d", strtotime($additionalInfo['nextDate'])), new DateTimeZone($timezone));
468
+ // timezone used as store's timezone
469
+ $currentDate = new DateTime(date("Y-m-d", Mage::getModel('core/date')->timestamp(time())), new DateTimeZone($timezone));
470
+ if ($nextDate < $currentDate) {
471
+ $this->_recurringProfile = $profile;
472
+ $startDate = $nextDate->format('Y-m-d');
473
+ $this->nextDate($startDate);
474
+ }
475
+ }
476
+
477
+ /**
478
+ * @param Mage_Sales_Model_Recurring_Profile $profile
479
+ * @param bool $bool
480
+ * @return bool
481
+ *
482
+ * check Maximum Payment Failures
483
+ * Maximum Payment Failures <= 0 -> run forever
484
+ * Maximum Payment Failures > 0 -> save countFailures into additional Info
485
+ * if isset countFailures -> countFailures - 1
486
+ * if countFailures = 0 -> profile is suspended
487
+ * if Maximum Payment Failures = null -> run forever
488
+ */
489
+ public function checkMaxPaymentFailures(Mage_Sales_Model_Recurring_Profile $profile, $bool = true)
490
+ {
491
+ $additional = $profile->getAdditionalInfo();
492
+ switch (true) {
493
+ // Maximum Payment Failures <= 0 or = null -> run forever
494
+ case (int) $profile->getSuspensionThreshold() <= 0:
495
+ break;
496
+ // Maximum Payment Failures > 0 -> save countFailures into additional Info
497
+ // if countFailures = 0 -> profile is suspended
498
+ case $profile->getSuspensionThreshold() && !isset($additional['paymentFailures']):
499
+ $additional['paymentFailures'] = (int) $profile->getSuspensionThreshold() - 1;
500
+ $profile->setAdditionalInfo($additional);
501
+ $profile->save();
502
+ if ($additional['paymentFailures'] == 0) {
503
+ $profile->suspend();
504
+ $bool = false;
505
+ }
506
+ break;
507
+ // Maximum Payment Failures > 0 -> save countFailures into additional Info
508
+ // if isset countFailures -> countFailures - 1
509
+ // if countFailures = 0 -> profile is suspended
510
+ case $profile->getSuspensionThreshold() && $additional['paymentFailures'] > 0:
511
+ $additional['paymentFailures'] -= 1;
512
+ $profile->setAdditionalInfo($additional);
513
+ $profile->save();
514
+ if ($additional['paymentFailures'] == 0) {
515
+ $profile->suspend();
516
+ $bool = false;
517
+ }
518
+ break;
519
+ default:
520
+ $profile->suspend();
521
+ $bool = false;
522
+ break;
523
+ }
524
+ return $bool;
525
+ }
526
+ }
app/code/community/Eway/Rapid31/Model/Request/Abstract.php ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"));
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: %s", curl_error($ch));
100
+ } else {
101
+ $info = curl_getinfo($ch);
102
+ if ($info['http_code'] == 401 || $info['http_code'] == 404) {
103
+ $response->isSuccess(false);
104
+ $response->setMessage(Mage::helper('ewayrapid')->__("Please check the API Key and Password %s", $mode));
105
+ $this->_log('Access denied. HTTP_CODE = ' . $info['http_code']);
106
+ } else {
107
+ $response->isSuccess(true);
108
+ $response->decodeJSON($result);
109
+ if($this->_config->isDebug()) {
110
+ $this->_log('SUCCESS. Response body:');
111
+ $this->_log(print_r(json_decode($result, true), true));
112
+ }
113
+ }
114
+ curl_close($ch);
115
+ }
116
+
117
+ $this->_log('===== END REQUEST.');
118
+ return $response;
119
+ }
120
+
121
+ protected function _logPostJSON()
122
+ {
123
+ if($this->_config->isDebug()) {
124
+ $cardDetails = null;
125
+ if($this->getCustomer() && $this->getCustomer()->getCardDetails()) {
126
+ $cardDetails = $this->getCustomer()->getCardDetails();
127
+ $cardDetails->shouldBeMasked();
128
+ }
129
+ $this->_log('Request body:');
130
+ $this->_log(print_r($this->getJsonData(), true));
131
+ if(!is_null($cardDetails)) {
132
+ $cardDetails->shouldBeMasked(false);
133
+ }
134
+ }
135
+ }
136
+
137
+ protected function _log($message, $file = self::DEBUG_FILE)
138
+ {
139
+ if($this->_config->isDebug()) {
140
+ Mage::log($message, Zend_Log::DEBUG, $file, true);
141
+ }
142
+ }
143
+ }
app/code/community/Eway/Rapid31/Model/Request/Direct.php ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if($response->isSuccess()) {
18
+ $payment->setTransactionId($response->getTransactionID());
19
+ $payment->setCcLast4($response->getCcLast4());
20
+ return $this;
21
+ } else {
22
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. Please try again. (Error message: %s)',
23
+ $response->getMessage()));
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Call Authorisation API (Authorized only)
29
+ *
30
+ * @param Mage_Sales_Model_Order_Payment $payment
31
+ * @param $amount
32
+ * @return Eway_Rapid31_Model_Request_Direct
33
+ */
34
+ public function doAuthorisation(Mage_Sales_Model_Order_Payment $payment, $amount)
35
+ {
36
+ $this->_buildRequest($payment, $amount);
37
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_AUTHORISE);
38
+ $response = $this->_doRapidAPI('Authorisation');
39
+
40
+ if($response->isSuccess()) {
41
+ $payment->setTransactionId($response->getTransactionID());
42
+ $payment->setIsTransactionClosed(0);
43
+ $payment->setCcLast4($response->getCcLast4());
44
+ return $this;
45
+ } else {
46
+ if ($payment->getIsRecurring()) {
47
+ Mage::getSingleton('core/session')->setData('errorMessage', $response->getMessage());
48
+ }
49
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the authorisation. Please try again. (Error message: %s)',
50
+ $response->getMessage()));
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Call Capture API (do the Capture only, must Authorized previously)
56
+ *
57
+ * @param Mage_Sales_Model_Order_Payment $payment
58
+ * @param $amount
59
+ * @return Eway_Rapid31_Model_Request_Direct
60
+ */
61
+ public function doCapturePayment(Mage_Sales_Model_Order_Payment $payment, $amount)
62
+ {
63
+ // Empty Varien_Object's data
64
+ $this->unsetData();
65
+
66
+ /* @var Mage_Sales_Model_Order_Invoice $invoice */
67
+ $invoice = Mage::registry('current_invoice');
68
+ $order = $payment->getOrder();
69
+
70
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
71
+ $paymentParam->setTotalAmount($amount)
72
+ ->setCurrencyCode($order->getBaseCurrencyCode());
73
+ if($invoice && $invoice->getIncrementId()) {
74
+ $paymentParam->setInvoiceNumber($invoice->getIncrementId())
75
+ ->setInvoiceReference($invoice->getIncrementId())
76
+ ->setInvoiceDescription(Mage::helper('ewayrapid')->__('Invoice created from Magento'));
77
+ }
78
+ $this->setPayment($paymentParam);
79
+ $this->setTransactionId($payment->getLastTransId());
80
+
81
+ $response = $this->_doRapidAPI('CapturePayment');
82
+
83
+ if($response->isSuccess()) {
84
+ $payment->setTransactionId($response->getTransactionID());
85
+ return $this;
86
+ } else {
87
+ if ($payment->getIsRecurring()) {
88
+ Mage::getSingleton('core/session')->setData('errorMessage', $response->getMessage());
89
+ }
90
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the capture. Please try again. (Error message: %s)',
91
+ $response->getMessage()));
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Call Refund API, must complete the transaction (Authorized & Capture) beforehand
97
+ *
98
+ * @param Mage_Sales_Model_Order_Payment $payment
99
+ * @param $amount
100
+ * @return Eway_Rapid31_Model_Request_Direct
101
+ */
102
+ public function doRefund(Mage_Sales_Model_Order_Payment $payment, $amount)
103
+ {
104
+ // Empty Varien_Object's data
105
+ $this->unsetData();
106
+
107
+ $order = $payment->getOrder();
108
+ /* @var Mage_Sales_Model_Order_Creditmemo $creditMemo */
109
+ $creditMemo = Mage::registry('current_creditmemo');
110
+
111
+ $invoice = ($creditMemo ? $creditMemo->getInvoice() : null);
112
+ /* @var Mage_Sales_Model_Order_Invoice $invoice */
113
+ if(!$invoice || !$invoice->getTransactionId()) {
114
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the online refund: Invoice or transaction does not exist.'));
115
+ }
116
+
117
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
118
+ $paymentParam->setTotalAmount($amount)
119
+ ->setCurrencyCode($order->getBaseCurrencyCode())
120
+ ->setTransactionID($invoice->getTransactionId());
121
+ if($creditMemo && $creditMemo->getIncrementId()) {
122
+ $paymentParam->setInvoiceDescription("Creditmemo ID " . $creditMemo->getIncrementId());
123
+ }
124
+
125
+ if($invoice && $invoice->getIncrementId()) {
126
+ $paymentParam->setInvoiceNumber($invoice->getIncrementId())
127
+ ->setInvoiceReference($invoice->getIncrementId());
128
+ }
129
+ $this->setRefund($paymentParam);
130
+
131
+ $response = $this->_doRapidAPI('Transaction/' . $invoice->getTransactionId() . '/Refund');
132
+
133
+ if($response->isSuccess()) {
134
+ $payment->setTransactionId($response->getTransactionID());
135
+ return $this;
136
+ } else {
137
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the refund. Please try again. (Error message: %s)',
138
+ $response->getMessage()));
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Call Cancel API, the transaction must be Authorized beforehand
144
+ *
145
+ * @param Mage_Sales_Model_Order_Payment $payment
146
+ * @return Eway_Rapid31_Model_Request_Direct
147
+ */
148
+ public function doCancel(Mage_Sales_Model_Order_Payment $payment)
149
+ {
150
+ // Empty Varien_Object's data
151
+ $this->unsetData();
152
+
153
+ $transactionId = $payment->getLastTransId();
154
+ $this->setTransactionId($transactionId);
155
+ $response = $this->_doRapidAPI('CancelAuthorisation');
156
+
157
+ if($response->isSuccess()) {
158
+ $payment->setTransactionId($response->getTransactionID());
159
+ $payment->setIsTransactionClosed(1);
160
+ return $this;
161
+ } else {
162
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the cancel. Please try again. (Error message: %s)',
163
+ $response->getMessage()));
164
+ }
165
+
166
+ }
167
+
168
+ /**
169
+ * Build the request with necessary parameters for doAuthorisation() and doTransaction()
170
+ *
171
+ * @param Mage_Sales_Model_Order_Payment $payment
172
+ * @param $amount
173
+ * @return Eway_Rapid31_Model_Request_Direct
174
+ */
175
+ protected function _buildRequest(Mage_Sales_Model_Order_Payment $payment, $amount)
176
+ {
177
+ // Empty Varien_Object's data
178
+ $this->unsetData();
179
+ $methodInstance = $payment->getMethodInstance();
180
+ $infoInstance = $methodInstance->getInfoInstance();
181
+ $order = $payment->getOrder();
182
+ $billing = $order->getBillingAddress();
183
+ $shipping = $order->getShippingAddress();
184
+
185
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
186
+ if(Mage::helper('ewayrapid')->isBackendOrder()) {
187
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
188
+ } else {
189
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
190
+ }
191
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion());
192
+ $this->setShippingMethod('Other');
193
+
194
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
195
+ $paymentParam->setTotalAmount($amount)
196
+ ->setCurrencyCode($order->getBaseCurrencyCode());
197
+ $this->setPayment($paymentParam);
198
+
199
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
200
+ $customerParam->setTitle($billing->getPrefix())
201
+ ->setFirstName($billing->getFirstname())
202
+ ->setLastName($billing->getLastname())
203
+ ->setCompanyName($billing->getCompany())
204
+ ->setJobDescription('')
205
+ ->setStreet1($billing->getStreet1())
206
+ ->setStreet2($billing->getStreet2())
207
+ ->setCity($billing->getCity())
208
+ ->setState($billing->getRegion())
209
+ ->setPostalCode($billing->getPostcode())
210
+ ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
211
+ ->setEmail($billing->getEmail())
212
+ ->setPhone($billing->getTelephone())
213
+ ->setMobile('')
214
+ ->setComments('')
215
+ ->setFax($billing->getFax())
216
+ ->setUrl('');
217
+ $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
218
+ $cardDetails->setName($infoInstance->getCcOwner())
219
+ ->setNumber($infoInstance->getCcNumber())
220
+ ->setExpiryMonth($infoInstance->getCcExpMonth())
221
+ ->setExpiryYear($infoInstance->getCcExpYear())
222
+ ->setCVN($infoInstance->getCcCid());
223
+
224
+ $customerParam->setCardDetails($cardDetails);
225
+ $this->setCustomer($customerParam);
226
+
227
+ $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
228
+ $shippingParam->setFirstName($shipping->getFirstname())
229
+ ->setLastName($shipping->getLastname())
230
+ ->setStreet1($shipping->getStreet1())
231
+ ->setStreet2($shipping->getStreet2())
232
+ ->setCity($shipping->getCity())
233
+ ->setState($shipping->getRegion())
234
+ ->setPostalCode($shipping->getPostcode())
235
+ ->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))
236
+ ->setEmail($shipping->getEmail())
237
+ ->setPhone($shipping->getTelephone())
238
+ ->setFax($shipping->getFax());
239
+ $this->setShippingAddress($shippingParam);
240
+
241
+ if($methodInstance->getConfigData('transfer_cart_items')) {
242
+ $orderItems = $order->getAllVisibleItems();
243
+ $lineItems = array();
244
+ foreach($orderItems as $orderItem) {
245
+ /* @var Mage_Sales_Model_Order_Item $orderItem */
246
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
247
+ $lineItem->setSKU($orderItem->getSku());
248
+ $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
249
+ $lineItem->setQuantity($orderItem->getQtyOrdered());
250
+ $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
251
+ $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
252
+ $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
253
+ $lineItems[] = $lineItem;
254
+ }
255
+ $this->setItems($lineItems);
256
+ }
257
+
258
+ return $this;
259
+ }
260
+ }
app/code/community/Eway/Rapid31/Model/Request/Sharedpage.php ADDED
@@ -0,0 +1,514 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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->_isNewToken()) {
43
+ $returnUrl .= '?newToken=1';
44
+ $method = Eway_Rapid31_Model_Config::METHOD_CREATE_TOKEN;
45
+ } elseif ($token = $this->_editToken()) {
46
+ $returnUrl .= '?editToken=' . $token;
47
+ $token = Mage::helper('ewayrapid/customer')->getCustomerTokenId($token);
48
+ $method = Eway_Rapid31_Model_Config::METHOD_UPDATE_TOKEN;
49
+ } else {
50
+ if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
51
+ $method = Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT;
52
+ } else {
53
+ $method = Eway_Rapid31_Model_Config::METHOD_AUTHORISE;
54
+ }
55
+ $totalAmount = round($this->_quote->getBaseGrandTotal() * 100);
56
+ $paypal = $this->_getPaypalCheckout();
57
+ if ($paypal === Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD) {
58
+ $this->setCheckoutPayment(true);
59
+ $this->setCheckoutURL(Mage::getUrl('ewayrapid/sharedpage/review'));
60
+ }
61
+ }
62
+
63
+ $this->_buildRequest();
64
+
65
+ $customer = $this->getCustomer();
66
+ $customer->setTokenCustomerID($token ? $token : '');
67
+ $this->setCustomer($customer);
68
+
69
+ // prepare API
70
+ $this->setRedirectUrl($returnUrl);
71
+ $this->setCancelUrl($cancelUrl);
72
+ $this->setMethod($method);
73
+
74
+ if (Mage::helper('ewayrapid')->getTransferCartLineItems()) {
75
+ // add Shipping item and Line items
76
+ $lineItems = Mage::helper('ewayrapid')->getLineItems();
77
+ $this->setItems($lineItems);
78
+ }
79
+
80
+ // add Payment
81
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
82
+ $paymentParam->setTotalAmount($totalAmount);
83
+ $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
84
+ $this->setPayment($paymentParam);
85
+
86
+ $response = $this->_doRapidAPI('AccessCodesShared');
87
+ return $response;
88
+ }
89
+
90
+ /**
91
+ * Call Authorisation API (Authorized only)
92
+ *
93
+ * @param Eway_Rapid31_Model_Response $response
94
+ * @return Eway_Rapid31_Model_Response
95
+ */
96
+ public function doAuthorisation(Eway_Rapid31_Model_Response $response)
97
+ {
98
+ $this->unsetData();
99
+
100
+ $this->_buildRequest();
101
+
102
+ $cardData = $response->getCustomer();
103
+ if ($cardData['CardNumber'] && $cardData['CardName']) {
104
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_AUTHORISE);
105
+ } else {
106
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
107
+ }
108
+
109
+ $items = $this->_quote->getAllVisibleItems();
110
+ $lineItems = array();
111
+ foreach ($items as $item) {
112
+ /* @var Mage_Sales_Model_Order_Item $item */
113
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
114
+ $lineItem->setSKU($item->getSku());
115
+ $lineItem->setDescription(substr($item->getName(), 0, 26));
116
+ $lineItem->setQuantity($item->getQty());
117
+ $lineItem->setUnitCost(round($item->getBasePrice() * 100));
118
+ $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
119
+ $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
120
+ $lineItems[] = $lineItem;
121
+ }
122
+ $this->setItems($lineItems);
123
+
124
+ $this->setItems(false);
125
+
126
+ // add Payment
127
+ $amount = round($this->_quote->getBaseGrandTotal() * 100);
128
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
129
+ $paymentParam->setTotalAmount($amount);
130
+ $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
131
+ $this->setPayment($paymentParam);
132
+
133
+ $customerParam = $this->getCustomer();
134
+ $customerParam->setTokenCustomerID($response->getTokenCustomerID());
135
+ $this->setCustomer($customerParam);
136
+
137
+ $response = $this->_doRapidAPI('Authorisation');
138
+ return $response;
139
+ }
140
+
141
+ /**
142
+ * Call Transaction API (Authorized & Capture at the same time)
143
+ *
144
+ * @param Eway_Rapid31_Model_Response $response
145
+ * @return Eway_Rapid31_Model_Response
146
+ */
147
+ public function doTransaction(Eway_Rapid31_Model_Response $response)
148
+ {
149
+ $this->unsetData();
150
+
151
+ $this->_buildRequest();
152
+
153
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
154
+
155
+ $items = $this->_quote->getAllVisibleItems();
156
+ $lineItems = array();
157
+ foreach ($items as $item) {
158
+ /* @var Mage_Sales_Model_Order_Item $item */
159
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
160
+ $lineItem->setSKU($item->getSku());
161
+ $lineItem->setDescription(substr($item->getName(), 0, 26));
162
+ $lineItem->setQuantity($item->getQty());
163
+ $lineItem->setUnitCost(round($item->getBasePrice() * 100));
164
+ $lineItem->setTax(round($item->getBaseTaxAmount() * 100));
165
+ $lineItem->setTotal(round($item->getBaseRowTotalInclTax() * 100));
166
+ $lineItems[] = $lineItem;
167
+ }
168
+ $this->setItems($lineItems);
169
+
170
+ $this->setItems(false);
171
+
172
+ // add Payment
173
+ $amount = round($this->_quote->getBaseGrandTotal() * 100);
174
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
175
+ $paymentParam->setTotalAmount($amount);
176
+ $paymentParam->setCurrencyCode($this->_quote->getBaseCurrencyCode());
177
+ $this->setPayment($paymentParam);
178
+
179
+ $customerParam = $this->getCustomer();
180
+ $customerParam->setTokenCustomerID($response->getTokenCustomerID());
181
+
182
+ $this->setCustomer($customerParam);
183
+
184
+ $response = $this->_doRapidAPI('Transaction');
185
+ return $response;
186
+ }
187
+
188
+ /**
189
+ * Call Capture API (do the Capture only, must Authorized previously)
190
+ *
191
+ * @param Eway_Rapid31_Model_Response $response
192
+ * @return Eway_Rapid31_Model_Response
193
+ */
194
+ public function doCapturePayment(Eway_Rapid31_Model_Response $response)
195
+ {
196
+ $this->setTransactionId($response->getTransactionID());
197
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT);
198
+
199
+ $response = $this->_doRapidAPI('CapturePayment');
200
+ return $response;
201
+ }
202
+
203
+ /**
204
+ * Build the request with necessary parameters for doAuthorisation(), doTransaction() and CreateAccessCode()
205
+ *
206
+ * @return $this
207
+ */
208
+ protected function _buildRequest()
209
+ {
210
+ // prepare API
211
+ $this->setShippingMethod('Other');
212
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
213
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion());
214
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
215
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
216
+ } else {
217
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
218
+ }
219
+ $this->setCustomerReadOnly(true);
220
+
221
+ // add Billing Address
222
+ $billingAddress = $this->_quote->getBillingAddress();
223
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
224
+ $customerParam->setTitle($billingAddress->getPrefix() ? $billingAddress->getPrefix() : 'Mr')
225
+ ->setFirstName($billingAddress->getFirstname())
226
+ ->setLastName($billingAddress->getLastname())
227
+ ->setCompanyName($billingAddress->getCompany())
228
+ ->setJobDescription($billingAddress->getJobDescription())
229
+ ->setStreet1($billingAddress->getStreet1())
230
+ ->setStreet2($billingAddress->getStreet2())
231
+ ->setCity($billingAddress->getCity())
232
+ ->setState($billingAddress->getRegion())
233
+ ->setPostalCode($billingAddress->getPostcode())
234
+ ->setCountry(strtolower($billingAddress->getCountryModel()->getIso2Code()))
235
+ ->setEmail($billingAddress->getEmail())
236
+ ->setPhone($billingAddress->getTelephone())
237
+ ->setMobile($billingAddress->getMobile())
238
+ ->setComments('')
239
+ ->setFax($billingAddress->getFax())
240
+ ->setUrl('');
241
+ $this->setCustomer($customerParam);
242
+
243
+ // add Shipping Address
244
+ $shippingAddress = $this->_quote->getShippingAddress();
245
+ $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
246
+ $shippingParam->setFirstName($shippingAddress->getFirstname())
247
+ ->setLastName($shippingAddress->getLastname())
248
+ ->setStreet1($shippingAddress->getStreet1())
249
+ ->setStreet2($shippingAddress->getStreet2())
250
+ ->setCity($shippingAddress->getCity())
251
+ ->setState($shippingAddress->getRegion())
252
+ ->setPostalCode($shippingAddress->getPostcode())
253
+ ->setCountry(strtolower($shippingAddress->getCountryModel()->getIso2Code()))
254
+ ->setEmail($shippingAddress->getEmail())
255
+ ->setPhone($shippingAddress->getTelephone())
256
+ ->setFax($shippingAddress->getFax());
257
+ $this->setShippingAddress($shippingParam);
258
+
259
+ return $this;
260
+ }
261
+
262
+ /**
263
+ * Get customer information by access code
264
+ */
265
+ public function getInfoByAccessCode($accessCode)
266
+ {
267
+ $response = $this->_doRapidAPI('AccessCode/' . $accessCode, false);
268
+ return $response;
269
+ }
270
+
271
+ /**
272
+ * Get customer session object
273
+ *
274
+ * @return Mage_Customer_Model_Session
275
+ */
276
+ public function getCustomerSession()
277
+ {
278
+ return $this->_customerSession;
279
+ }
280
+
281
+ /**
282
+ * check is new token when checkout
283
+ *
284
+ * @return bool
285
+ */
286
+ protected function _isNewToken()
287
+ {
288
+ $info = $this->_quote->getPayment();
289
+ Mage::helper('ewayrapid')->unserializeInfoInstace($info);
290
+ if ($token = Mage::getSingleton('core/session')->getData('newToken')) {
291
+ Mage::getSingleton('core/session')->unsetData('newToken');
292
+ return true;
293
+ }
294
+ return false;
295
+ }
296
+
297
+ /**
298
+ * get TokenCustomerID is selected of customer
299
+ *
300
+ * @return mixed
301
+ */
302
+ protected function _editToken()
303
+ {
304
+ if ($token = Mage::getSingleton('core/session')->getData('editToken')) {
305
+ Mage::getSingleton('core/session')->unsetData('editToken');
306
+ return $token;
307
+ }
308
+ return $token;
309
+ }
310
+
311
+ /**
312
+ * check paypal option in eway not saved
313
+ *
314
+ * @return mixed|null
315
+ */
316
+ protected function _getPaypalCheckout()
317
+ {
318
+ if ($paypal = Mage::getSingleton('core/session')->getData('sharedpagePaypal')) {
319
+ Mage::getModel('core/session')->unsetData('sharedpagePaypal');
320
+ return $paypal;
321
+ }
322
+ return null;
323
+ }
324
+
325
+ /**
326
+ * update customer when edit shipping address to paypal
327
+ *
328
+ * @param $accessCode
329
+ */
330
+ public function updateCustomer($accessCode)
331
+ {
332
+ $response = $this->_doRapidAPI('Transaction/' . $accessCode, 'GET');
333
+ if ($response->isSuccess()) {
334
+ $customer = $this->_quote->getCustomer();
335
+ $billingAddress = $this->_quote->getBillingAddress();
336
+ $shippingAddress = $this->_quote->getShippingAddress();
337
+ $trans = $response->getTransactions();
338
+
339
+ if (isset($trans[0]['Customer'])) {
340
+ $billing = $trans[0]['Customer'];
341
+ $billingAddress->setFirstname($billing['FirstName'])
342
+ ->setLastName($billing['LastName'])
343
+ ->setCompany($billing['CompanyName'])
344
+ ->setJobDescription($billing['JobDescription'])
345
+ ->setStreet($billing['Street1'])
346
+ ->setStreet2($billing['Street2'])
347
+ ->setCity($billing['City'])
348
+ ->setState($billing['State'])
349
+ ->setPostcode($billing['PostalCode'])
350
+ ->setCountryId(strtoupper($billing['Country']))
351
+ ->setEmail($billing['Email'])
352
+ ->setTelephone($billing['Phone'])
353
+ ->setMobile($billing['Mobile'])
354
+ ->setComments($billing['Comments'])
355
+ ->setFax($billing['Fax'])
356
+ ->setUrl($billing['Url']);
357
+ }
358
+ if (isset($trans[0]['ShippingAddress'])) {
359
+ $shipping = $trans[0]['ShippingAddress'];
360
+ $shippingAddress->setFirstname($shipping['FirstName'])
361
+ ->setLastname($shipping['LastName'])
362
+ ->setStreet($shipping['Street1'])
363
+ ->setStreet2($shipping['Street2'])
364
+ ->setCity($shipping['City'])
365
+ ->setPostcode($shipping['PostalCode'])
366
+ ->setCountryId(strtoupper($shipping['Country']))
367
+ ->setEmail($shipping['Email'])
368
+ ->setFax($shipping['Fax']);
369
+
370
+ if ($shipping['State']
371
+ && $shipping['Country']
372
+ && $region = Mage::getModel('directory/region')->loadByCode($shipping['State'], $shipping['Country'])
373
+ ) {
374
+ $shippingAddress->setRegion($region->getName())
375
+ ->setRegionId($region->getId());
376
+ }
377
+ if ($shipping['Phone']) {
378
+ $shippingAddress->setTelephone($shipping['Phone']);
379
+ }
380
+ }
381
+ $this->_quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress)->save();
382
+ }
383
+ }
384
+
385
+ /**
386
+ * save token when checkout with eway saved
387
+ *
388
+ * @param Eway_Rapid31_Model_Response $response
389
+ * @param null $ccNumber
390
+ */
391
+ public function saveTokenById(Eway_Rapid31_Model_Response $response, $ccNumber = null)
392
+ {
393
+ $this->unsetData();
394
+
395
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
396
+ $customerParam->setTokenCustomerID($response->getTokenCustomerID());
397
+ $this->setCustomer($customerParam);
398
+ $payment = Mage::getModel('ewayrapid/field_payment');
399
+ $payment->setTotalAmount(1);
400
+ $this->setPayment($payment);
401
+ $this->setRedirectUrl(Mage::getBaseUrl() . '/ewayrapid/sharedpage/saveToken');
402
+ $this->setMethod('');
403
+
404
+ $response = $this->_doRapidAPI('AccessCodesShared');
405
+ $token = true;
406
+ if ($response->isSuccess()) {
407
+ if (!$ccNumber) {
408
+ $token = $this->_createNewToken($response);
409
+ } else {
410
+ $token = $this->_updateToken($response, $ccNumber);
411
+ }
412
+
413
+ } else {
414
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while creating new token. Please try again. (Error message: %s)',
415
+ $response->getMessage()));
416
+ }
417
+ if (!$token) {
418
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while process token. Please try again.'));
419
+ }
420
+ return $response;
421
+ }
422
+
423
+ /**
424
+ * Create new token when checkout
425
+ *
426
+ * @param Eway_Rapid31_Model_Response $response
427
+ * @return $this
428
+ */
429
+ protected function _createNewToken(Eway_Rapid31_Model_Response $response)
430
+ {
431
+ try {
432
+ $customer = $response->getCustomer();
433
+
434
+ $tokenInfo = array(
435
+ 'Token' => $response->getTokenCustomerID(),
436
+ 'Card' => $customer['CardNumber'] ? substr_replace($customer['CardNumber'], '******', 6, 6) : 'Paypal',
437
+ 'Owner' => $customer['CardName'],
438
+ 'StartMonth' => $customer['CardStartMonth'],
439
+ 'StartYear' => $customer['CardStartYear'],
440
+ 'IssueNumber' => $customer['CardIssueNumber'],
441
+ 'ExpMonth' => $customer['CardExpiryMonth'],
442
+ 'ExpYear' => (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear']),
443
+ 'Type' => $this->checkCardType($customer['CardNumber']),
444
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customer),
445
+ );
446
+
447
+ Mage::helper('ewayrapid/customer')->addToken($tokenInfo);
448
+ return true;
449
+ } catch (Exception $e) {
450
+ return false;
451
+ }
452
+ }
453
+
454
+ /**
455
+ * Update token when checkout with existing token
456
+ *
457
+ * @param Eway_Rapid31_Model_Response $response
458
+ * @param null $ccNumber
459
+ * @return $this
460
+ */
461
+ protected function _updateToken(Eway_Rapid31_Model_Response $response, $ccNumber = null)
462
+ {
463
+ try {
464
+ $customer = $response->getCustomer();
465
+
466
+ $tokenInfo = array(
467
+ 'Token' => $response->getTokenCustomerID(),
468
+ 'Card' => $customer['CardNumber'] ? substr_replace($customer['CardNumber'], '******', 6, 6) : 'Paypal',
469
+ 'Owner' => $customer['CardName'],
470
+ 'StartMonth' => $customer['CardStartMonth'],
471
+ 'StartYear' => $customer['CardStartYear'],
472
+ 'IssueNumber' => $customer['CardIssueNumber'],
473
+ 'ExpMonth' => $customer['CardExpiryMonth'],
474
+ 'ExpYear' => (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear']),
475
+ 'Type' => $this->checkCardType($customer['CardNumber']),
476
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customer),
477
+ );
478
+
479
+ Mage::helper('ewayrapid/customer')->updateToken($ccNumber, $tokenInfo);
480
+ return true;
481
+ } catch (Exception $e) {
482
+ return false;
483
+ }
484
+ }
485
+
486
+ /**
487
+ * Get card type name by card number
488
+ * @param $num Card number
489
+ * @return string Card type name
490
+ */
491
+ public function checkCardType($num)
492
+ {
493
+ if ($num == null) {
494
+ return Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD;
495
+ }
496
+ return Mage::getModel('ewayrapid/request_token')->checkCardType($num);
497
+ }
498
+
499
+ public function getShippingByCode($postalCode)
500
+ {
501
+ $groups = $this->_quote->getShippingAddress()
502
+ ->collectShippingRates()
503
+ ->getGroupedAllShippingRates();
504
+ // determine current selected code & name
505
+ foreach ($groups as $code => $rates) {
506
+ foreach ($rates as $rate) {
507
+ if (strtoupper($postalCode) == strtoupper($rate->getCode())) {
508
+ return $rate;
509
+ }
510
+ }
511
+ }
512
+ return false;
513
+ }
514
+ }
app/code/community/Eway/Rapid31/Model/Request/Token.php ADDED
@@ -0,0 +1,504 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $customerParam->setTitle($billing->getPrefix())
18
+ ->setFirstName($billing->getFirstname())
19
+ ->setLastName($billing->getLastname())
20
+ ->setCompanyName($billing->getCompany())
21
+ ->setJobDescription($billing->getJobDescription())
22
+ ->setStreet1($billing->getStreet1())
23
+ ->setStreet2($billing->getStreet2())
24
+ ->setCity($billing->getCity())
25
+ ->setState($billing->getRegion())
26
+ ->setPostalCode($billing->getPostcode())
27
+ ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
28
+ ->setEmail($billing->getEmail())
29
+ ->setPhone($billing->getTelephone())
30
+ ->setMobile($billing->getMobile())
31
+ ->setComments('')
32
+ ->setFax($billing->getFax())
33
+ ->setUrl('');
34
+
35
+ $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
36
+ $cardDetails->setName($infoInstance->getCcOwner())
37
+ ->setNumber($infoInstance->getCcNumber())
38
+ ->setExpiryMonth($infoInstance->getCcExpMonth())
39
+ ->setExpiryYear($infoInstance->getCcExpYear())
40
+ ->setCVN($infoInstance->getCcCid())
41
+ ->setStartMonth($infoInstance->getStartMonth())
42
+ ->setStartYear($infoInstance->getStartYear())
43
+ ->setIssueNumber($infoInstance->getIssueNumber());
44
+ $customerParam->setCardDetails($cardDetails);
45
+ $this->setCustomer($customerParam);
46
+
47
+ $response = $this->_doRapidAPI('Customer');
48
+ if ($response->isSuccess()) {
49
+ $customerReturn = $response->getCustomer();
50
+ $cardDetails = $customerReturn['CardDetails'];
51
+ unset($customerReturn['CardDetails']);
52
+ $customerReturn['RegionId'] = ((!$billing->getRegion() && $billing->getRegionId()) ? $billing->getRegionId() : '');
53
+ $tokenInfo = array(
54
+ 'Token' => $response->getTokenCustomerID(),
55
+ 'Card' => substr_replace($cardDetails['Number'], '******', 6, 6),
56
+ 'Owner' => $infoInstance->getCcOwner(),
57
+ 'ExpMonth' => $infoInstance->getCcExpMonth(),
58
+ 'ExpYear' => $infoInstance->getCcExpYear(),
59
+ 'Type' => $infoInstance->getCcType(),
60
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customerReturn),
61
+ );
62
+ Mage::helper('ewayrapid/customer')->addToken($tokenInfo);
63
+ return $this;
64
+ } else {
65
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while creating new token. Please try again. (Error message: %s)',
66
+ $response->getMessage()));
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Update current token
72
+ *
73
+ * @param Varien_Object $billing
74
+ * @param Varien_Object $infoInstance
75
+ * @return Eway_Rapid31_Model_Request_Token
76
+ */
77
+ public function updateToken(Varien_Object $billing, Varien_Object $infoInstance)
78
+ {
79
+ if (!Mage::helper('ewayrapid')->isBackendOrder() && !Mage::getSingleton('ewayrapid/config')->canEditToken()) {
80
+ Mage::throwException(Mage::helper('ewayrapid')->__('Customers are not allowed to edit token.'));
81
+ }
82
+
83
+ // Empty Varien_Object's data
84
+ $this->unsetData();
85
+
86
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
87
+ $customerParam->setTitle($billing->getPrefix())
88
+ ->setFirstName($billing->getFirstname())
89
+ ->setLastName($billing->getLastname())
90
+ ->setCompanyName($billing->getCompany())
91
+ ->setJobDescription($billing->getJobDescription())
92
+ ->setStreet1($billing->getStreet1())
93
+ ->setStreet2($billing->getStreet2())
94
+ ->setCity($billing->getCity())
95
+ ->setState($billing->getRegion())
96
+ ->setPostalCode($billing->getPostcode())
97
+ ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
98
+ ->setEmail($billing->getEmail())
99
+ ->setPhone($billing->getTelephone())
100
+ ->setMobile($billing->getMobile())
101
+ ->setFax($billing->getFax());
102
+
103
+ $customerHelper = Mage::helper('ewayrapid/customer');
104
+ $customerTokenId = $customerHelper->getCustomerTokenId($infoInstance->getSavedToken());
105
+ if ($customerTokenId) {
106
+ $customerParam->setTokenCustomerID($customerTokenId);
107
+ } else {
108
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
109
+ }
110
+
111
+ $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
112
+ $cardDetails->setName($infoInstance->getCcOwner())
113
+ ->setExpiryMonth($infoInstance->getCcExpMonth())
114
+ ->setNumber('444433XXXXXX1111') // Required dummy card number for update to work
115
+ ->setExpiryYear($infoInstance->getCcExpYear())
116
+ ->setCVN($infoInstance->getCcCid());
117
+ $customerParam->setCardDetails($cardDetails);
118
+
119
+ $this->setCustomer($customerParam);
120
+
121
+ $response = $this->_doRapidAPI('Customer', 'PUT');
122
+ if ($response->isSuccess()) {
123
+ $customerReturn = $response->getCustomer();
124
+ $customerReturn['RegionId'] = ((!$billing->getRegion() && $billing->getRegionId()) ? $billing->getRegionId() : '');
125
+ unset($customerReturn['CardDetails']);
126
+ $tokenInfo = array(
127
+ 'Token' => $response->getTokenCustomerID(),
128
+ 'Owner' => $infoInstance->getCcOwner(),
129
+ 'ExpMonth' => $infoInstance->getCcExpMonth(),
130
+ 'ExpYear' => $infoInstance->getCcExpYear(),
131
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($customerReturn),
132
+ );
133
+ Mage::helper('ewayrapid/customer')->updateToken($infoInstance->getSavedToken(), $tokenInfo);
134
+ return $this;
135
+ } else {
136
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token. Please try again. (Error message: %s)',
137
+ $response->getMessage()));
138
+ }
139
+ }
140
+
141
+ protected function _buildRequest(Mage_Sales_Model_Order_Payment $payment, $amount)
142
+ {
143
+ // Empty Varien_Object's data
144
+ $this->unsetData();
145
+ // in case recurring profile, $methodInstance is not exist, and $payment->getIsRecurring() is used
146
+ if (!$payment->getIsRecurring()) {
147
+ $methodInstance = $payment->getMethodInstance();
148
+ $infoInstance = $methodInstance->getInfoInstance();
149
+ Mage::helper('ewayrapid')->unserializeInfoInstace($infoInstance);
150
+ }
151
+ $order = $payment->getOrder();
152
+ $shipping = $order->getShippingAddress();
153
+
154
+
155
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
156
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
157
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
158
+ } elseif ($payment->getIsRecurring()) {
159
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_RECURRING);
160
+ } else {
161
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
162
+ }
163
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion());
164
+ $this->setShippingMethod('Other');
165
+
166
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
167
+ $paymentParam->setTotalAmount($amount)
168
+ ->setCurrencyCode($order->getBaseCurrencyCode());
169
+ $this->setPayment($paymentParam);
170
+
171
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
172
+ $customerTokenId = null;
173
+
174
+ /** get $customerTokenId if product is recurring profile */
175
+ if ($payment->getIsRecurring()) {
176
+ /** @todo save customer id and tokent id into payment when place order */
177
+ $customer = Mage::getModel('customer/customer')->load($payment->getCustomerId());
178
+ $customerHelper = Mage::helper('ewayrapid/customer');
179
+ $customerHelper->setCurrentCustomer($customer);
180
+ $customerTokenId = $customerHelper->getCustomerTokenId($payment->getTokenId());
181
+ } else {
182
+ /** get $customerTokenId if product is normal item */
183
+ if ($infoInstance->getSavedToken()) {
184
+ $customerHelper = Mage::helper('ewayrapid/customer');
185
+ $customerTokenId = $customerHelper->getCustomerTokenId($infoInstance->getSavedToken());
186
+ }
187
+ else {
188
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction: Token info does not exist.'));
189
+ }
190
+ }
191
+ if ($customerTokenId) {
192
+ $customerParam->setTokenCustomerID($customerTokenId);
193
+ if ($this->getTransactionType() == Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE) {
194
+ $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
195
+ $cardDetails->setCVN($infoInstance->getCcCid());
196
+ $customerParam->setCardDetails($cardDetails);
197
+ }
198
+ $this->setCustomer($customerParam);
199
+ } else {
200
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction: Token info does not exist.'));
201
+ }
202
+
203
+ $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
204
+ $shippingParam->setFirstName($shipping->getFirstname())
205
+ ->setLastName($shipping->getLastname())
206
+ ->setStreet1($shipping->getStreet1())
207
+ ->setStreet2($shipping->getStreet2())
208
+ ->setCity($shipping->getCity())
209
+ ->setState($shipping->getRegion())
210
+ ->setPostalCode($shipping->getPostcode())
211
+ ->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))
212
+ ->setEmail($shipping->getEmail())
213
+ ->setPhone($shipping->getTelephone())
214
+ ->setFax($shipping->getFax());
215
+ $this->setShippingAddress($shippingParam);
216
+
217
+ if ((isset($methodInstance) && $methodInstance->getConfigData('transfer_cart_items')) || $payment->getIsRecurring() || !$payment->getIsInitialFee()) {
218
+ $orderItems = $order->getAllVisibleItems();
219
+ $lineItems = array();
220
+ foreach ($orderItems as $orderItem) {
221
+ /* @var Mage_Sales_Model_Order_Item $orderItem */
222
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
223
+ $lineItem->setSKU($orderItem->getSku());
224
+ $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
225
+ $lineItem->setQuantity($orderItem->getQtyOrdered());
226
+ $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
227
+ $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
228
+ $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
229
+ $lineItems[] = $lineItem;
230
+ }
231
+ $this->setItems($lineItems);
232
+ }
233
+
234
+
235
+ return $this;
236
+ }
237
+
238
+ /**
239
+ * Create new AccessCode
240
+ * @param Varien_Object $billing
241
+ * @param Varien_Object $infoInstance
242
+ * @param string $method
243
+ * @param null $request
244
+ * @return Eway_Rapid31_Model_Response
245
+ */
246
+ public function createAccessCode(Varien_Object $billing, Varien_Object $infoInstance,
247
+ $method = 'AccessCodes', $request = null)
248
+ {
249
+ // Empty Varien_Object's data
250
+ $tokenCustomerID = $request->get('TokenCustomerID');
251
+ $this->unsetData();
252
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
253
+ $customerParam->setTokenCustomerID($tokenCustomerID)
254
+ ->setTitle($billing->getPrefix())
255
+ ->setFirstName($billing->getFirstname())
256
+ ->setLastName($billing->getLastname())
257
+ ->setCompanyName($billing->getCompany())
258
+ ->setJobDescription($billing->getJobDescription())
259
+ ->setStreet1($billing->getStreet1())
260
+ ->setStreet2($billing->getStreet2())
261
+ ->setCity($billing->getCity())
262
+ ->setState($billing->getRegion())
263
+ ->setPostalCode($billing->getPostcode())
264
+ ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
265
+ ->setEmail($billing->getEmail())
266
+ ->setPhone($billing->getTelephone())
267
+ ->setMobile($billing->getMobile())
268
+ ->setComments('')
269
+ ->setFax($billing->getFax())
270
+ ->setUrl('');
271
+
272
+ $returnUrl = Mage::getBaseUrl() . '/ewayrapid/mycards/saveToken?ccType='
273
+ . $infoInstance->getCcType() . '&expYear=' . $infoInstance->getCcExpYear();
274
+ if ($request->get('is_default') == 'on') {
275
+ $returnUrl .= '&is_default=on';
276
+ }
277
+ if($infoInstance->getCcStartMonth()) {
278
+ $returnUrl .= '&startMonth=' . $infoInstance->getCcStartMonth();
279
+ }
280
+ if($infoInstance->getCcStartYear()) {
281
+ $returnUrl .= '&startYear=' . $infoInstance->getCcStartYear();
282
+ }
283
+ if($infoInstance->getCcIssueNumber()) {
284
+ $returnUrl .= '&issueNumber=' . $infoInstance->getCcIssueNumber();
285
+ }
286
+ // Binding address on url param
287
+ $returnUrl .= '&street1=' . base64_encode($billing->getStreet1())
288
+ . '&street2=' . base64_encode($billing->getStreet2());
289
+ $tokenId = $request->get('token_id');
290
+ if (!empty($tokenId)) { // ID token customer will be defined to update
291
+ $returnUrl = $returnUrl . '&token_id=' . $tokenId;
292
+ }
293
+
294
+ $this->setCustomer($customerParam);
295
+ $this->setRedirectUrl($returnUrl);
296
+ $this->setCancelUrl($returnUrl);
297
+ $this->setMethod(!empty($tokenCustomerID) ? 'UpdateTokenCustomer' : 'CreateTokenCustomer');
298
+ $this->setCustomerIP($_SERVER["REMOTE_ADDR"]);
299
+ $this->setDeviceID('');
300
+ $this->setTransactionType("Purchase");
301
+ $this->setCustomerReadOnly(true);
302
+
303
+ // Create new access code
304
+ //$formMethod = !empty($tokenCustomerID) ? 'PUT' : 'POST';
305
+ $response = $this->_doRapidAPI($method);
306
+ return $response;
307
+ }
308
+
309
+ /*
310
+ * Get customer information by access code
311
+ */
312
+ public function getInfoByAccessCode($accessCode)
313
+ {
314
+ $response = $this->_doRapidAPI('AccessCode/' . $accessCode, false);
315
+ return $response;
316
+ }
317
+
318
+ public function saveInfoByTokenId($cardData)
319
+ {
320
+ // Empty Varien_Object's data
321
+ $this->unsetData();
322
+
323
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
324
+ $customerParam->setTokenCustomerID($cardData['token']);
325
+ $payment = Mage::getModel('ewayrapid/field_payment');
326
+ $payment->setTotalAmount(1);
327
+ $returnUrl = Mage::getBaseUrl() . '/ewayrapid/mycards';
328
+
329
+ $this->setCustomer($customerParam);
330
+ $this->setPayment($payment);
331
+ $this->setRedirectUrl($returnUrl);
332
+ $this->setMethod('');
333
+ $this->setTransactionType('');
334
+ $this->setDeviceID('');
335
+ $this->setCustomerIP($_SERVER["REMOTE_ADDR"]);
336
+
337
+ $response = $this->_doRapidAPI('AccessCodes');
338
+
339
+ if ($cardData['token_id']) {
340
+ // Update card
341
+ $this->__updateTokenTransparentOrSharedPage($response, $cardData);
342
+ } else
343
+ // Create new token
344
+ $this->__createNewTokenTransparentOrSharedPage($response, $cardData);
345
+ return $this;
346
+
347
+ }
348
+
349
+ private function __createNewTokenTransparentOrSharedPage($response, $cardData)
350
+ {
351
+ if ($response->isSuccess()) {
352
+ $data = $response->getData();
353
+ $customer = $data['Customer'];
354
+ $address = array(
355
+ //'TokenCustomerID' => $customer['TokenCustomerID'],
356
+ 'Reference' => $customer['Reference'],
357
+ 'Title' => $customer['Title'],
358
+ 'FirstName' => $customer['FirstName'],
359
+ 'LastName' => $customer['LastName'],
360
+ 'CompanyName' => $customer['CompanyName'],
361
+ 'JobDescription' => $customer['JobDescription'],
362
+ 'Street1' => isset($cardData['street1'])? $cardData['street1'] : $customer['Street1'],
363
+ 'Street2' => isset($cardData['street2']) ? $cardData['street2'] : $customer['Street2'],
364
+ 'City' => $customer['City'],
365
+ 'State' => $customer['State'],
366
+ 'PostalCode' => $customer['PostalCode'],
367
+ 'Country' => $customer['Country'],
368
+ 'Email' => $customer['Email'],
369
+ 'Phone' => $customer['Phone'],
370
+ 'Mobile' => $customer['Mobile'],
371
+ 'Comments' => $customer['Comments'],
372
+ 'Fax' => $customer['Fax'],
373
+ 'Url' => $customer['Url']
374
+ );
375
+ $tokenInfo = array(
376
+ 'Token' => $response->getTokenCustomerID(),
377
+ 'Card' => substr_replace($customer['CardNumber'], '******', 6, 6),
378
+ 'Owner' => $customer['CardName'],
379
+ 'StartMonth' => $cardData['startMonth'],
380
+ 'StartYear' => $cardData['startYear'],
381
+ 'IssueNumber' => $cardData['issueNumber'],
382
+ 'ExpMonth' => $customer['CardExpiryMonth'],
383
+ 'ExpYear' => (!empty($cardData['expYear']) ? $cardData['expYear'] :
384
+ (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear'])),
385
+ 'Type' => $cardData['ccType'] ? $cardData['ccType'] : $this->checkCardType($customer['CardNumber']),
386
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($address),
387
+ );
388
+
389
+ Mage::helper('ewayrapid/customer')->addToken($tokenInfo);
390
+ return $this;
391
+ } else {
392
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while creating new token. Please try again. (Error message: %s)',
393
+ $response->getMessage()));
394
+ }
395
+ }
396
+
397
+ private function __updateTokenTransparentOrSharedPage($res, $cardData)
398
+ {
399
+ if ($res->isSuccess()) {
400
+ $data = $res->getData();
401
+ $customer = $data['Customer'];
402
+ $address = array(
403
+ //'TokenCustomerID' => $customer['TokenCustomerID'],
404
+ 'Reference' => $customer['Reference'],
405
+ 'Title' => $customer['Title'],
406
+ 'FirstName' => $customer['FirstName'],
407
+ 'LastName' => $customer['LastName'],
408
+ 'CompanyName' => $customer['CompanyName'],
409
+ 'JobDescription' => $customer['JobDescription'],
410
+ 'Street1' => isset($cardData['street1'])? $cardData['street1'] : $customer['Street1'],
411
+ 'Street2' => isset($cardData['street2']) ? $cardData['street2'] : $customer['Street2'],
412
+ 'City' => $customer['City'],
413
+ 'State' => $customer['State'],
414
+ 'PostalCode' => $customer['PostalCode'],
415
+ 'Country' => $customer['Country'],
416
+ 'Email' => $customer['Email'],
417
+ 'Phone' => $customer['Phone'],
418
+ 'Mobile' => $customer['Mobile'],
419
+ 'Comments' => $customer['Comments'],
420
+ 'Fax' => $customer['Fax'],
421
+ 'Url' => $customer['Url']
422
+ );
423
+
424
+ $tokenInfo = array(
425
+ 'Token' => $res->getTokenCustomerID(),
426
+ 'Owner' => $customer['CardName'],
427
+ 'StartMonth' => $cardData['startMonth'],
428
+ 'StartYear' => $cardData['startYear'],
429
+ 'IssueNumber' => $cardData['issueNumber'],
430
+ 'ExpMonth' => $customer['CardExpiryMonth'],
431
+ 'ExpYear' => (!empty($cardData['expYear']) ? $cardData['expYear'] :
432
+ (strlen($customer['CardExpiryYear']) == 2 ? '20' . $customer['CardExpiryYear'] : $customer['CardExpiryYear'])),
433
+ 'Type' => $cardData['ccType'] ? $cardData['ccType'] : $this->checkCardType($customer['CardNumber']),
434
+ 'Address' => Mage::getModel('ewayrapid/field_customer')->addData($address),
435
+ );
436
+ //edit card number if connection type = shared page
437
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
438
+ $tokenInfo['Card'] = str_replace('X', '*', $customer['CardNumber']);
439
+ $tokenInfo['Card'] = str_replace('x', '*', $tokenInfo['Card']);
440
+ }
441
+
442
+ Mage::helper('ewayrapid/customer')->updateToken($cardData['token_id'], $tokenInfo);
443
+ return $this;
444
+ } else {
445
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while creating new token. Please try again. (Error message: %s)',
446
+ $res->getMessage()));
447
+ }
448
+ }
449
+
450
+ /**
451
+ * Get card type name by card number
452
+ * @param $num Card number
453
+ * @return string Card type name
454
+ */
455
+ public function checkCardType($num)
456
+ {
457
+ if (preg_match('/^(4026|417500|4508|4844|4913|4917)/', $num)) {
458
+ return 'VE';
459
+ }
460
+ if (preg_match('/^4/', $num)) {
461
+ return 'VI';
462
+ }
463
+ if (preg_match('/^(34|37)/', $num)) {
464
+ return 'AE';
465
+ }
466
+ if (preg_match('/^(5[1-5])/', $num)) {
467
+ return 'MC';
468
+ }
469
+ if (preg_match('/^(2131|1800)/', $num)) {
470
+ return 'JCB';
471
+ }
472
+ if (preg_match('/^36/', $num)) {
473
+ return 'DC';
474
+ }
475
+ if (preg_match('/^(5018|5020|5038|5893|6304|6759|6761|6762|6763)/', $num)) {
476
+ return 'ME';
477
+ }
478
+
479
+ return 'Unknown';
480
+ }
481
+
482
+ public function getTransaction($transaction_number) {
483
+
484
+ }
485
+
486
+
487
+ /**
488
+ * Check Card Name
489
+ * @param $card Card Info
490
+ * @return string Card name: paypal | masterpass | mastercard
491
+ */
492
+ public function checkCardName($card)
493
+ {
494
+ $cardType = strtolower($card->getType());
495
+ if (preg_match('/^paypal/', $cardType)) {
496
+ return Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD;
497
+ }
498
+ $ccTypes = Mage::getSingleton('ewayrapid/system_config_source_cctype')->getAllowedTypes();
499
+ if (in_array(strtoupper($cardType), $ccTypes)) {
500
+ return Eway_Rapid31_Model_Config::CREDITCARD_METHOD;
501
+ }
502
+ return Eway_Rapid31_Model_Config::MASTERPASS_METHOD;
503
+ }
504
+ }
app/code/community/Eway/Rapid31/Model/Request/Transparent.php ADDED
@@ -0,0 +1,667 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
18
+ $customerParam->setTitle($billingAddress->getPrefix() ? $billingAddress->getPrefix() : 'Mr')
19
+ ->setFirstName($billingAddress->getFirstname())
20
+ ->setLastName($billingAddress->getLastname())
21
+ ->setCompanyName($billingAddress->getCompany())
22
+ ->setJobDescription($billingAddress->getJobDescription())
23
+ ->setStreet1($billingAddress->getStreet1())
24
+ ->setStreet2($billingAddress->getStreet2())
25
+ ->setCity($billingAddress->getCity())
26
+ ->setState($billingAddress->getRegion())
27
+ ->setPostalCode($billingAddress->getPostcode())
28
+ ->setCountry(strtolower($billingAddress->getCountryModel()->getIso2Code()))
29
+ ->setEmail($billingAddress->getEmail())
30
+ ->setPhone($billingAddress->getTelephone())
31
+ ->setMobile($billingAddress->getMobile())
32
+ ->setComments('')
33
+ ->setFax($billingAddress->getFax())
34
+ ->setUrl('');
35
+
36
+ if ($this->getMethod() == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD) {
37
+ $customerTokenId = Mage::getSingleton('core/session')->getSavedToken();
38
+ if (!$customerTokenId) {
39
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
40
+ } elseif (is_numeric($customerTokenId)) {
41
+ $customerHelper = Mage::helper('ewayrapid/customer');
42
+ $customerTokenId = $customerHelper->getCustomerTokenId($customerTokenId);
43
+ if ($customerTokenId) {
44
+ $customerParam->setTokenCustomerID($customerTokenId);
45
+ } else {
46
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
47
+ }
48
+ }
49
+ }
50
+
51
+ $this->setCustomer($customerParam);
52
+
53
+ $shippingAddress = $quote->getShippingAddress();
54
+ $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
55
+ $shippingParam->setFirstName($shippingAddress->getFirstname())
56
+ ->setLastName($shippingAddress->getLastname())
57
+ ->setStreet1($shippingAddress->getStreet1())
58
+ ->setStreet2($shippingAddress->getStreet2())
59
+ ->setCity($shippingAddress->getCity())
60
+ ->setState($shippingAddress->getRegion())
61
+ ->setPostalCode($shippingAddress->getPostcode())
62
+ ->setCountry(strtolower($shippingAddress->getCountryModel()->getIso2Code()))
63
+ ->setEmail($shippingAddress->getEmail())
64
+ ->setPhone($shippingAddress->getTelephone())
65
+ ->setFax($shippingAddress->getFax());
66
+ $this->setShippingAddress($shippingParam);
67
+
68
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
69
+ $paymentParam->setTotalAmount(round($quote->getBaseGrandTotal() * 100));
70
+ if ($method == 'CreateTokenCustomer' || $method == 'UpdateTokenCustomer') {
71
+ $paymentParam->setTotalAmount(0);
72
+ }
73
+ $paymentParam->setCurrencyCode($quote->getBaseCurrencyCode());
74
+ $this->setPayment($paymentParam);
75
+
76
+ $returnUrl = Mage::getBaseUrl() . '/ewayrapid/transparent/callBack';
77
+ $cancelUrl = Mage::getBaseUrl() . '/ewayrapid/transparent/cancel';
78
+
79
+ $this->setRedirectUrl($returnUrl);
80
+
81
+ //CheckOutUrl if using PayPal
82
+ $checkOutUrl = Mage::getBaseUrl() . '/ewayrapid/transparent/review';
83
+
84
+ if (Mage::helper('ewayrapid/data')->getTransferCartLineItems()) {
85
+ // add Shipping item and Line items
86
+ $lineItems = Mage::helper('ewayrapid')->getLineItems();
87
+ $this->setItems($lineItems);
88
+ }
89
+
90
+ /*if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
91
+ $this->setItems(false);
92
+ }*/
93
+
94
+ if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD) {
95
+ $this->setCheckoutPayment(true);
96
+ $this->setCheckoutURL($checkOutUrl);
97
+ $this->setItems(false);
98
+ }
99
+
100
+ $this->setCancelUrl($cancelUrl);
101
+ $this->setMethod($method);
102
+ $this->setShippingMethod('Other');
103
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
104
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion());
105
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
106
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
107
+ } else {
108
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
109
+ }
110
+ $this->setCustomerReadOnly(true);
111
+
112
+ $response = $this->_doRapidAPI($action);
113
+ if ($response->isSuccess()) {
114
+ return $response;
115
+ } else {
116
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
117
+ $response->getMessage()));
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Get customer information by access code
123
+ * @param $accessCode
124
+ * @throws Mage_Core_Exception
125
+ */
126
+ public function getInfoByAccessCode($accessCode)
127
+ {
128
+ $response = $this->_doRapidAPI('AccessCode/' . $accessCode, false);
129
+ if ($response->isSuccess()) {
130
+ return $response;
131
+ } else {
132
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. Please try again. (Error message: %s)',
133
+ $response->getMessage()));
134
+ return false;
135
+ }
136
+ }
137
+
138
+ public function getTransaction($accessCode)
139
+ {
140
+ try {
141
+ $results = $this->_doRapidAPI("Transaction/$accessCode", 'GET');
142
+ if ($results->isSuccess()) {
143
+ return $results->getTransactions();
144
+ }
145
+ } catch (Exception $e) {
146
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
147
+ $results->getMessage()));
148
+ return false;
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Update customer info
154
+ * @param $transId
155
+ * @return mixed
156
+ */
157
+ public function updateCustomer($accessCode, Mage_Sales_Model_Quote $quote)
158
+ {
159
+ try {
160
+ $results = $this->_doRapidAPI("Transaction/$accessCode", 'GET');
161
+ if (!$results->isSuccess()) {
162
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: %s)',
163
+ $results->getMessage()));
164
+ }
165
+
166
+ $customer = $quote->getCustomer();
167
+ $billingAddress = $quote->getBillingAddress();
168
+ $shippingAddress = $quote->getShippingAddress();
169
+
170
+ if ($results->isSuccess()) {
171
+ $trans = $results->getTransactions();
172
+
173
+ if (isset($trans[0]['Customer'])) {
174
+ $billing = $trans[0]['Customer'];
175
+ $billingAddress->setFirstname($billing['FirstName'])
176
+ ->setLastName($billing['LastName'])
177
+ ->setCompany($billing['CompanyName'])
178
+ ->setJobDescription($billing['JobDescription'])
179
+ ->setStreet($billing['Street1'])
180
+ ->setStreet2($billing['Street2'])
181
+ ->setCity($billing['City'])
182
+ ->setState($billing['State'])
183
+ ->setPostcode($billing['PostalCode'])
184
+ ->setCountryId(strtoupper($billing['Country']))
185
+ ->setEmail($billing['Email'])
186
+ ->setTelephone($billing['Phone'])
187
+ ->setMobile($billing['Mobile'])
188
+ ->setComments($billing['Comments'])
189
+ ->setFax($billing['Fax'])
190
+ ->setUrl($billing['Url']);
191
+ }
192
+ if (isset($trans[0]['ShippingAddress'])) {
193
+ $shipping = $trans[0]['ShippingAddress'];
194
+ $shippingAddress->setFirstname($shipping['FirstName'])
195
+ ->setLastname($shipping['LastName'])
196
+ ->setStreet($shipping['Street1'])
197
+ ->setStreet2($shipping['Street2'])
198
+ ->setCity($shipping['City'])
199
+ ->setPostcode($shipping['PostalCode'])
200
+ ->setCountryId(strtoupper($shipping['Country']))
201
+ ->setEmail($shipping['Email'])
202
+ ->setFax($shipping['Fax']);
203
+
204
+ if ($shipping['State']
205
+ && $shipping['Country']
206
+ && $region = Mage::getModel('directory/region')->loadByCode($shipping['State'], $shipping['Country'])
207
+ ) {
208
+ $shippingAddress->setRegion($region->getName())
209
+ ->setRegionId($region->getId());
210
+ }
211
+ if ($shipping['Phone']) {
212
+ $shippingAddress->setTelephone($shipping['Phone']);
213
+ }
214
+ }
215
+ return $quote->assignCustomerWithAddressChange($customer, $billingAddress, $shippingAddress)->save();
216
+ }
217
+ return false;
218
+ } catch (Exception $e) {
219
+ Mage::throwException($e->getMessage());
220
+ return false;
221
+ }
222
+ }
223
+
224
+ /**
225
+ * @param Mage_Sales_Model_Quote $quote
226
+ * @param $tokenInfo
227
+ * @param $tokenCustomerID
228
+ * @return bool
229
+ */
230
+ public function addToken(Mage_Sales_Model_Quote $quote, $tokenInfo, $tokenCustomerID = 0)
231
+ {
232
+ try {
233
+ if (!$tokenCustomerID)
234
+ return false;
235
+
236
+ //Get Customer Card Info
237
+ $customerCard = $this->getCustomerCard($tokenCustomerID);
238
+ $cardetail = null;
239
+ if ($customerCard) {
240
+ $customer = $customerCard->getCustomer();
241
+ $cardetail = $customer && isset($customer['CardDetails']) ? $customer['CardDetails'] : null;
242
+ unset($customer);
243
+ }
244
+
245
+ $billingAddress = $quote->getBillingAddress();
246
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
247
+ $customerParam->setTitle($billingAddress->getPrefix() ? $billingAddress->getPrefix() : 'Mr')
248
+ ->setFirstName($billingAddress->getFirstname())
249
+ ->setLastName($billingAddress->getLastname())
250
+ ->setCompanyName($billingAddress->getCompany())
251
+ ->setJobDescription($billingAddress->getJobDescription())
252
+ ->setStreet1($billingAddress->getStreet1())
253
+ ->setStreet2($billingAddress->getStreet2())
254
+ ->setCity($billingAddress->getCity())
255
+ ->setState($billingAddress->getRegion())
256
+ ->setPostalCode($billingAddress->getPostcode())
257
+ ->setCountry(strtolower($billingAddress->getCountryModel()->getIso2Code()))
258
+ ->setEmail($billingAddress->getEmail())
259
+ ->setPhone($billingAddress->getTelephone())
260
+ ->setMobile($billingAddress->getMobile())
261
+ ->setComments('')
262
+ ->setFax($billingAddress->getFax())
263
+ ->setUrl('');
264
+ $config = Mage::getSingleton('ewayrapid/config');
265
+ $cardNumber = null;
266
+
267
+ if ($tokenInfo['SavedType'] == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
268
+ $tokenInfo['ccType'] = "PayPal";
269
+ $cardNumber = "PayPal";
270
+ $tokenInfo['EWAY_CARDNAME'] = "PayPal";
271
+ $tokenInfo['EWAY_CARDEXPIRYMONTH'] = $tokenInfo['EWAY_CARDEXPIRYYEAR'] = '';
272
+ } elseif ($tokenInfo['SavedType'] == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
273
+ //$tokenInfo['ccType'] = "MC";
274
+ $cardNumber = $cardetail && isset($cardetail['Number']) ? substr_replace($cardetail['Number'], '******', 6, 6) : "MasterPass";
275
+ $cardNumber = substr_replace($cardNumber, '******', 6, 6);
276
+ $tokenInfo['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "MasterPass";
277
+ $tokenInfo['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : "";
278
+ $tokenInfo['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : "";
279
+ } else {
280
+ $cardNumber = $cardetail && isset($cardetail['Number']) ? $cardetail['Number'] : @Mage::helper('ewayrapid/data')->decryptSha256($tokenInfo['EWAY_CARDNUMBER'], $config->getBasicAuthenticationHeader());
281
+ $cardNumber = substr_replace($cardNumber, '******', 6, 6);
282
+ $tokenInfo['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "creditcard";
283
+ $tokenInfo['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : "";
284
+ $tokenInfo['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : "";
285
+ }
286
+ $type = isset($tokenInfo['ccType']) ? $tokenInfo['ccType'] : $this->checkCardType($cardNumber);
287
+ if($type == 'Unknown') {
288
+ $type = $tokenInfo['SavedType'] == Eway_Rapid31_Model_Config::MASTERPASS_METHOD ? 'MasterPass' : 'CreditCard';
289
+ }
290
+
291
+ $tokenInfo['EWAY_CARDEXPIRYYEAR'] = $tokenInfo['EWAY_CARDEXPIRYYEAR'] && strlen($tokenInfo['EWAY_CARDEXPIRYYEAR']) == 2 ? '20' . $tokenInfo['EWAY_CARDEXPIRYYEAR'] : $cardetail['EWAY_CARDEXPIRYYEAR'];
292
+ $cardInfo = array(
293
+ 'Token' => $tokenCustomerID,
294
+ 'TokenCustomerID' => $tokenCustomerID,
295
+ 'Card' => $cardNumber,
296
+ 'Owner' => $tokenInfo['EWAY_CARDNAME'],
297
+ 'StartMonth' => '',
298
+ 'StartYear' => '',
299
+ 'IssueNumber' => '',
300
+ 'ExpMonth' => (int)$tokenInfo['EWAY_CARDEXPIRYMONTH'],
301
+ 'ExpYear' => (int)$tokenInfo['EWAY_CARDEXPIRYYEAR'],
302
+ 'Type' => $type,
303
+ 'Address' => $customerParam,
304
+ );
305
+
306
+ Mage::helper('ewayrapid/customer')->addToken($cardInfo);
307
+ return true;
308
+ } catch (Exception $e) {
309
+ return false;
310
+ }
311
+ }
312
+
313
+ /**
314
+ * @param $id
315
+ * @param $info
316
+ * @return bool
317
+ */
318
+ public function updateToken($id, $info = null)
319
+ {
320
+ try {
321
+ //Get Customer Card Info
322
+ $customerCard = $this->getCustomerCard($id);
323
+ $cardetail = null;
324
+ if ($customerCard) {
325
+ $customer = $customerCard->getCustomer();
326
+ $cardetail = $customer && isset($customer['CardDetails']) ? $customer['CardDetails'] : null;
327
+ unset($customer);
328
+ }
329
+ $cardetail['ExpiryYear'] = $cardetail['ExpiryYear'] && strlen($cardetail['ExpiryYear']) == 2 ? '20' . $cardetail['ExpiryYear'] : $cardetail['ExpiryYear'];
330
+
331
+ if ($info['SavedType'] == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
332
+ $tokenInfo['EWAY_CARDNAME'] = "PayPal";
333
+ } elseif ($info['SavedType'] == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
334
+ $info['ccType'] = "MC";
335
+ $info['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "MasterPass";
336
+ $info['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : "";
337
+ $info['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : "";
338
+ } else {
339
+ $info['EWAY_CARDNAME'] = $cardetail && isset($cardetail['Name']) ? $cardetail['Name'] : "PayPal";
340
+ $info['EWAY_CARDEXPIRYMONTH'] = $cardetail && isset($cardetail['ExpiryMonth']) ? $cardetail['ExpiryMonth'] : $info['EWAY_CARDEXPIRYMONTH'];
341
+ $info['EWAY_CARDEXPIRYYEAR'] = $cardetail && isset($cardetail['ExpiryYear']) ? $cardetail['ExpiryYear'] : $info['EWAY_CARDEXPIRYYEAR'];
342
+ }
343
+
344
+ $cardInfo = array(
345
+ 'Owner' => $info['EWAY_CARDNAME'],
346
+ 'StartMonth' => '',
347
+ 'StartYear' => '',
348
+ 'IssueNumber' => '',
349
+ 'ExpMonth' => $info ? (int)$info['EWAY_CARDEXPIRYMONTH'] : '',
350
+ 'ExpYear' => $info ? (int)$info['EWAY_CARDEXPIRYYEAR'] : '',
351
+ );
352
+
353
+ if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
354
+ $uid = Mage::getSingleton('core/session')->getPaypalSavedToken();
355
+ } elseif ($this->getTransMethod() == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
356
+ $uid = Mage::getSingleton('core/session')->getMasterpassSavedToken();
357
+ } else {
358
+ $uid = Mage::getSingleton('core/session')->getSavedToken();
359
+ }
360
+
361
+ Mage::helper('ewayrapid/customer')->updateToken($uid, $cardInfo);
362
+ return true;
363
+ } catch (Exception $e) {
364
+ return false;
365
+ }
366
+ }
367
+
368
+ /**
369
+ * Get card type name by card number
370
+ * @param $num Card number
371
+ * @return string Card type name
372
+ */
373
+ public function checkCardType($num)
374
+ {
375
+ return Mage::getModel('ewayrapid/request_token')->checkCardType($num);
376
+ }
377
+
378
+ /**
379
+ * @param Mage_Sales_Model_Order_Payment $payment
380
+ * @return bool
381
+ */
382
+ public function setTransaction(Mage_Sales_Model_Order_Payment $payment)
383
+ {
384
+ $payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
385
+ $payment->setIsTransactionClosed(0);
386
+ return $payment;
387
+ }
388
+
389
+ /**
390
+ * Get shipping by code
391
+ *
392
+ * @param Mage_Sales_Model_Quote $quote
393
+ * @param $postalCode
394
+ * @return bool
395
+ */
396
+ public function getShippingByCode(Mage_Sales_Model_Quote $quote, $postalCode)
397
+ {
398
+ $groups = $quote->getShippingAddress()->collectShippingRates()->getGroupedAllShippingRates();
399
+ // determine current selected code & name
400
+ foreach ($groups as $code => $rates) {
401
+ foreach ($rates as $rate) {
402
+ if (strtoupper($postalCode) == strtoupper($rate->getCode())) {
403
+ return $rate;
404
+ }
405
+ }
406
+ }
407
+ return false;
408
+ }
409
+
410
+ /**
411
+ * Call Transaction API (Authorized & Capture at the same time)
412
+ *
413
+ * @param Mage_Sales_Model_Order_Payment $payment
414
+ * @param float $amount
415
+ * @return Eway_Rapid31_Model_Request_Direct $this
416
+ */
417
+ public function doTransaction(Mage_Sales_Model_Quote $quote, $amount)
418
+ {
419
+ $this->_buildRequest($quote, $amount);
420
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
421
+ $response = $this->_doRapidAPI('Transaction');
422
+
423
+ if ($response->isSuccess()) {
424
+ $quote->setTransactionId($response->getTransactionID());
425
+ $quote->setCcLast4($response->getCcLast4());
426
+ $quote->save();
427
+ return $quote;
428
+ } else {
429
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while making the transaction. Please try again. (Error message: %s)',
430
+ $response->getMessage()));
431
+ }
432
+ }
433
+
434
+ /**
435
+ * Call Authorisation API (Authorized only)
436
+ *
437
+ * @param Mage_Sales_Model_Order_Payment $payment
438
+ * @param $amount
439
+ * @return Eway_Rapid31_Model_Request_Direct
440
+ */
441
+ public function doAuthorisation(Mage_Sales_Model_Quote $quote, $amount)
442
+ {
443
+ $this->_buildRequest($quote, $amount);
444
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_AUTHORISE);
445
+ $response = $this->_doRapidAPI('Authorisation');
446
+ if ($response->isSuccess()) {
447
+ $quote->setTransactionId($response->getTransactionID());
448
+ $quote->setIsTransactionClosed(0);
449
+ $quote->setCcLast4($response->getCcLast4());
450
+ $quote->save();
451
+ return $quote;
452
+ } else {
453
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the authorisation. Please try again. (Error message: %s)',
454
+ $response->getMessage()));
455
+ }
456
+ }
457
+
458
+ /**
459
+ * Call Capture API (do the Capture only, must Authorized previously)
460
+ *
461
+ * @param Mage_Sales_Model_Order_Payment $payment
462
+ * @param $amount
463
+ * @return Eway_Rapid31_Model_Request_Direct
464
+ */
465
+ public function doCapturePayment(Mage_Sales_Model_Quote $quote, $amount)
466
+ {
467
+ // Empty Varien_Object's data
468
+ $this->unsetData();
469
+
470
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
471
+ $paymentParam->setTotalAmount($amount)
472
+ ->setCurrencyCode($quote->getBaseCurrencyCode());
473
+
474
+ $this->setPayment($paymentParam);
475
+ $this->setTransactionId($quote->getTransactionId());
476
+ $this->setMethod(Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT);
477
+ $response = $this->_doRapidAPI('CapturePayment');
478
+
479
+ if ($response->isSuccess()) {
480
+ $quote->setTransactionId($response->getTransactionID());
481
+ $quote->save();
482
+ return $quote;
483
+ } else {
484
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while doing the capture. Please try again. (Error message: %s)',
485
+ $response->getMessage()));
486
+ }
487
+ }
488
+
489
+ /**
490
+ * Build the request with necessary parameters for doAuthorisation() and doTransaction()
491
+ *
492
+ * @param Mage_Sales_Model_Order_Payment $payment
493
+ * @param $amount
494
+ * @return Eway_Rapid31_Model_Request_Direct
495
+ */
496
+ protected function _buildRequest(Mage_Sales_Model_Quote $quote, $amount)
497
+ {
498
+ // Empty Varien_Object's data
499
+ $this->unsetData();
500
+
501
+ $billing = $quote->getBillingAddress();
502
+ $shipping = $quote->getShippingAddress();
503
+
504
+ $this->setCustomerIP(Mage::helper('core/http')->getRemoteAddr());
505
+ if (Mage::helper('ewayrapid')->isBackendOrder()) {
506
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
507
+ } else {
508
+ $this->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
509
+ }
510
+ $this->setDeviceID('Magento ' . Mage::getEdition() . ' ' . Mage::getVersion());
511
+ $this->setShippingMethod('Other');
512
+
513
+ $paymentParam = Mage::getModel('ewayrapid/field_payment');
514
+ $paymentParam->setTotalAmount($amount);
515
+ $paymentParam->setCurrencyCode($quote->getBaseCurrencyCode());
516
+ $this->setPayment($paymentParam);
517
+
518
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
519
+ $customerParam->setTitle($billing->getPrefix())
520
+ ->setFirstName($billing->getFirstname())
521
+ ->setLastName($billing->getLastname())
522
+ ->setCompanyName($billing->getCompany())
523
+ ->setJobDescription('')
524
+ ->setStreet1($billing->getStreet1())
525
+ ->setStreet2($billing->getStreet2())
526
+ ->setCity($billing->getCity())
527
+ ->setState($billing->getRegion())
528
+ ->setPostalCode($billing->getPostcode())
529
+ ->setCountry(strtolower($billing->getCountryModel()->getIso2Code()))
530
+ ->setEmail($billing->getEmail())
531
+ ->setPhone($billing->getTelephone())
532
+ ->setMobile('')
533
+ ->setComments('')
534
+ ->setFax($billing->getFax())
535
+ ->setUrl('');
536
+
537
+ $infoCard = Mage::getSingleton('core/session')->getInfoCard();
538
+ if ($infoCard && $infoCard->getCard() && $infoCard->getOwner() && !$this->getTokenInfo()) {
539
+ $cardDetails = Mage::getModel('ewayrapid/field_cardDetails');
540
+ $cardDetails->setName($infoCard->getOwner())
541
+ ->setNumber($infoCard->getCard())
542
+ ->setExpiryMonth($infoCard->getExpMonth())
543
+ ->setExpiryYear($infoCard->getExpYear())
544
+ ->setCVN($infoCard->getCid());
545
+ $customerParam->setCardDetails($cardDetails);
546
+ }
547
+
548
+ if ($quote->getTokenCustomerID()) {
549
+ $customerParam->setTokenCustomerID($quote->getTokenCustomerID());
550
+ } elseif ($token = $this->getTokenInfo()) {
551
+ $customerParam->setTokenCustomerID($token->getToken() ? $token->getToken() : $token->getTokenCustomerID());
552
+ }
553
+
554
+ $this->setCustomer($customerParam);
555
+
556
+ $shippingParam = Mage::getModel('ewayrapid/field_shippingAddress');
557
+ $shippingParam->setFirstName($shipping->getFirstname())
558
+ ->setLastName($shipping->getLastname())
559
+ ->setStreet1($shipping->getStreet1())
560
+ ->setStreet2($shipping->getStreet2())
561
+ ->setCity($shipping->getCity())
562
+ ->setState($shipping->getRegion())
563
+ ->setPostalCode($shipping->getPostcode())
564
+ ->setCountry(strtolower($shipping->getCountryModel()->getIso2Code()))
565
+ ->setEmail($shipping->getEmail())
566
+ ->setPhone($shipping->getTelephone())
567
+ ->setFax($shipping->getFax());
568
+ $this->setShippingAddress($shippingParam);
569
+
570
+ $orderItems = $quote->getAllVisibleItems();
571
+ $lineItems = array();
572
+ foreach ($orderItems as $orderItem) {
573
+ /* @var Mage_Sales_Model_Order_Item $orderItem */
574
+ $lineItem = Mage::getModel('ewayrapid/field_lineItem');
575
+ $lineItem->setSKU($orderItem->getSku());
576
+ $lineItem->setDescription(substr($orderItem->getName(), 0, 26));
577
+ $lineItem->setQuantity($orderItem->getQtyOrdered());
578
+ $lineItem->setUnitCost(round($orderItem->getBasePrice() * 100));
579
+ $lineItem->setTax(round($orderItem->getBaseTaxAmount() * 100));
580
+ $lineItem->setTotal(round($orderItem->getBaseRowTotalInclTax() * 100));
581
+ $lineItems[] = $lineItem;
582
+ }
583
+ $this->setItems($lineItems);
584
+ if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
585
+ $this->setItems(false);
586
+ }
587
+
588
+ return $this;
589
+ }
590
+
591
+ /**
592
+ * @param $tokenCustomerID
593
+ * @throws Mage_Core_Exception
594
+ */
595
+ public function getCustomerCard($tokenCustomerID)
596
+ {
597
+ // Empty Varien_Object's data
598
+ $this->unsetData();
599
+
600
+ $customerParam = Mage::getModel('ewayrapid/field_customer');
601
+
602
+ if ($tokenCustomerID) {
603
+ $customerParam->setTokenCustomerID($tokenCustomerID);
604
+ } else {
605
+ Mage::throwException(Mage::helper('ewayrapid')->__('An error occurred while updating token: Token info does not exist.'));
606
+ }
607
+ $this->setCustomer($customerParam);
608
+
609
+ $response = $this->_doRapidAPI('Customer', 'PUT');
610
+ if ($response->isSuccess()) {
611
+ return $response;
612
+ } else {
613
+ return false;
614
+ }
615
+ }
616
+
617
+ public function getMethod()
618
+ {
619
+ return Mage::getSingleton('core/session')->getMethod();
620
+ }
621
+
622
+ /**
623
+ * @return mixed
624
+ */
625
+ public function getTransMethod()
626
+ {
627
+ $transMethod = Mage::getSingleton('core/session')->getTransparentNotsaved();
628
+ if (!$transMethod) {
629
+ $transMethod = Mage::getSingleton('core/session')->getTransparentSaved();
630
+ }
631
+ return $transMethod;
632
+ }
633
+
634
+ /**
635
+ * @return mixed
636
+ */
637
+ public function getTokenInfo()
638
+ {
639
+ if ($this->getTransMethod() == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
640
+ $uid = Mage::getSingleton('core/session')->getPaypalSavedToken();
641
+ } elseif ($this->getTransMethod() == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
642
+ $uid = Mage::getSingleton('core/session')->getMasterpassSavedToken();
643
+ } else {
644
+ $uid = Mage::getSingleton('core/session')->getSavedToken();
645
+ }
646
+ if ($uid && $uid != Eway_Rapid31_Model_Config::TOKEN_NEW)
647
+ return Mage::helper('ewayrapid/customer')->getTokenById($uid);
648
+ return false;
649
+ }
650
+
651
+ /**
652
+ *
653
+ */
654
+ public function unsetSessionData()
655
+ {
656
+ Mage::getSingleton('core/session')->unsTransparentNotsaved();
657
+ Mage::getSingleton('core/session')->unsTransparentSaved();
658
+ Mage::getSingleton('core/session')->unsSavedToken();
659
+ Mage::getSingleton('core/session')->unsTransactionId();
660
+ Mage::getSingleton('core/session')->unsFormActionUrl();
661
+ Mage::getSingleton('core/session')->unsPaypalSavedToken();
662
+ Mage::getSingleton('core/session')->unsMethod();
663
+ Mage::getSingleton('core/session')->unsCompleteCheckoutURL();
664
+ Mage::getSingleton('core/session')->unsMasterPassSavedToken();
665
+ Mage::getSingleton('core/session')->unsInfoCard();
666
+ }
667
+ }
app/code/community/Eway/Rapid31/Model/Response.php ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
143
+ 'D4401' => 'Refer to Issuer',
144
+ 'D4402' => 'Refer to Issuer, special',
145
+ 'D4403' => 'No Merchant',
146
+ 'D4404' => 'Pick Up Card',
147
+ 'D4405' => 'Do Not Honour',
148
+ 'D4406' => 'Error',
149
+ 'D4407' => 'Pick Up Card, Special',
150
+ 'D4409' => 'Request In Progress',
151
+ 'D4412' => 'Invalid Transaction',
152
+ 'D4413' => 'Invalid Amount',
153
+ 'D4414' => 'Invalid Card Number',
154
+ 'D4415' => 'No Issuer',
155
+ 'D4419' => 'Re-enter Last Transaction',
156
+ 'D4421' => 'No Method Taken',
157
+ 'D4422' => 'Suspected Malfunction',
158
+ 'D4423' => 'Unacceptable Transaction Fee',
159
+ 'D4425' => 'Unable to Locate Record On File',
160
+ 'D4430' => 'Format Error',
161
+ 'D4431' => 'Bank Not Supported By Switch',
162
+ 'D4433' => 'Expired Card, Capture',
163
+ 'D4434' => 'Suspected Fraud, Retain Card',
164
+ 'D4435' => 'Card Acceptor, Contact Acquirer, Retain Card',
165
+ 'D4436' => 'Restricted Card, Retain Card',
166
+ 'D4437' => 'Contact Acquirer Security Department, Retain Card',
167
+ 'D4438' => 'PIN Tries Exceeded, Capture',
168
+ 'D4439' => 'No Credit Account',
169
+ 'D4440' => 'Function Not Supported',
170
+ 'D4441' => 'Lost Card',
171
+ 'D4442' => 'No Universal Account',
172
+ 'D4443' => 'Stolen Card',
173
+ 'D4444' => 'No Investment Account',
174
+ 'D4451' => 'Insufficient Funds',
175
+ 'D4452' => 'No Cheque Account',
176
+ 'D4453' => 'No Savings Account',
177
+ 'D4454' => 'Expired Card',
178
+ 'D4455' => 'Incorrect PIN',
179
+ 'D4456' => 'No Card Record',
180
+ 'D4457' => 'Function Not Permitted to Cardholder',
181
+ 'D4458' => 'Function Not Permitted to Terminal',
182
+ 'D4460' => 'Acceptor Contact Acquirer',
183
+ 'D4461' => 'Exceeds Withdrawal Limit',
184
+ 'D4462' => 'Restricted Card',
185
+ 'D4463' => 'Security Violation',
186
+ 'D4464' => 'Original Amount Incorrect',
187
+ 'D4466' => 'Acceptor Contact Acquirer, Security',
188
+ 'D4467' => 'Capture Card',
189
+ 'D4475' => 'PIN Tries Exceeded',
190
+ 'D4482' => 'CVV Validation Error',
191
+ 'D4490' => 'Cutoff In Progress',
192
+ 'D4491' => 'Card Issuer Unavailable',
193
+ 'D4492' => 'Unable To Route Transaction',
194
+ 'D4493' => 'Cannot Complete, Violation Of The Law',
195
+ 'D4494' => 'Duplicate Transaction',
196
+ 'D4496' => 'System Error',
197
+ 'D4497' => 'MasterPass Error',
198
+ 'D4498' => 'PayPal Create Transaction Error',
199
+ 'D4499' => 'Invalid Transaction for Auth/Void',
200
+
201
+ 'S5000' => 'System Error',
202
+ 'S5085' => 'Started 3dSecure',
203
+ 'S5086' => 'Routed 3dSecure',
204
+ 'S5087' => 'Completed 3dSecure',
205
+ 'S5088' => 'PayPal Transaction Created',
206
+ 'S5099' => 'Incomplete (Access Code in progress/incomplete)',
207
+ 'S5010' => 'Unknown error returned by gateway',
208
+ );
209
+ private $_isSuccess = false;
210
+
211
+ private $_messageCode = array(
212
+ 'F7000' => 'Undefined Fraud Error',
213
+ 'F7001' => 'Challenged Fraud',
214
+ 'F7002' => 'Country Match Fraud',
215
+ 'F7003' => 'High Risk Country Fraud',
216
+ 'F7004' => 'Anonymous Proxy Fraud',
217
+ 'F7005' => 'Transparent Proxy Fraud',
218
+ 'F7006' => 'Free Email Fraud',
219
+ 'F7007' => 'International Transaction Fraud',
220
+ 'F7008' => 'Risk Score Fraud',
221
+ 'F7009' => 'Denied Fraud',
222
+ 'F9010' => 'High Risk Billing Country',
223
+ 'F9011' => 'High Risk Credit Card Country',
224
+ 'F9012' => 'High Risk Customer IP Address',
225
+ 'F9013' => 'High Risk Email Address',
226
+ 'F9014' => 'High Risk Shipping Country',
227
+ 'F9015' => 'Multiple card numbers for single email address',
228
+ 'F9016' => 'Multiple card numbers for single location',
229
+ 'F9017' => 'Multiple email addresses for single card number',
230
+ 'F9018' => 'Multiple email addresses for single location',
231
+ 'F9019' => 'Multiple locations for single card number',
232
+ 'F9020' => 'Multiple locations for single email address',
233
+ 'F9021' => 'Suspicious Customer First Name',
234
+ 'F9022' => 'Suspicious Customer Last Name',
235
+ 'F9023' => 'Transaction Declined',
236
+ 'F9024' => 'Multiple transactions for same address with known credit card',
237
+ 'F9025' => 'Multiple transactions for same address with new credit card',
238
+ 'F9026' => 'Multiple transactions for same email with new credit card',
239
+ 'F9027' => 'Multiple transactions for same email with known credit card',
240
+ 'F9028' => 'Multiple transactions for new credit card',
241
+ 'F9029' => 'Multiple transactions for known credit card',
242
+ 'F9030' => 'Multiple transactions for same email address',
243
+ 'F9031' => 'Multiple transactions for same credit card',
244
+ 'F9032' => 'Invalid Customer Last Name',
245
+ 'F9033' => 'Invalid Billing Street',
246
+ 'F9034' => 'Invalid Shipping Street',
247
+ 'F9037' => 'Suspicious Customer Email Address',
248
+ );
249
+
250
+ public function getMessage() {
251
+ if($this->getData('Message')) {
252
+ return $this->getData('Message');
253
+ }
254
+
255
+ $messageCode = $this->getResponseMessage();
256
+ if(empty($messageCode) && ($errors = $this->getErrors())) {
257
+ $messageCode = $errors[0];
258
+ }
259
+
260
+ if(empty($messageCode)) {
261
+ return Mage::helper('ewayrapid')->__("Unknown");
262
+ }
263
+
264
+ if (isset($this->_codes[$messageCode])) {
265
+ return $this->_codes[$messageCode];
266
+ } else {
267
+ return Mage::helper('ewayrapid')->__("%s", $this->replaceMessage($messageCode));
268
+ }
269
+ }
270
+
271
+ public function isSuccess($flag = null)
272
+ {
273
+ if($flag !== null) {
274
+ $this->_isSuccess = $flag;
275
+ }
276
+
277
+ return $this->_isSuccess;
278
+ }
279
+
280
+ /**
281
+ * Decode response returned by eWAY API call
282
+ *
283
+ * @param $response
284
+ * @return Eway_Rapid31_Model_Response
285
+ */
286
+ public function decodeJSON($response)
287
+ {
288
+ $json = json_decode($response, true);
289
+ $this->addData($json);
290
+ if(!empty($json['Customer']) && is_array($json['Customer'])) {
291
+ $this->_setIfNotEmpty($json['Customer'], 'TokenCustomerID');
292
+ if(!empty($json['Customer']['CardDetails']) && !empty($json['Customer']['CardDetails']['Number'])) {
293
+ $this->setData('CcLast4', substr($json['Customer']['CardDetails']['Number'], -4));
294
+ }
295
+ }
296
+
297
+ if(!empty($json['Errors'])) {
298
+ $this->setErrors(explode(',', $json['Errors']));
299
+ }
300
+
301
+ if(isset($json['TransactionStatus'])) {
302
+ // Use TransactionStatus if it's presented in response
303
+ $this->isSuccess((bool)$this->getTransactionStatus());
304
+
305
+ // Check response message has fraud code
306
+ if (isset($json['ResponseMessage']) && $this->isSuccess()) {
307
+ $codeMessage = str_replace(' ', '', $json['ResponseMessage']);
308
+ $codeMessage = explode(',', $codeMessage);
309
+ $codeMessage = array_flip($codeMessage);
310
+
311
+ $result = array_intersect_key($this->_messageCode, $codeMessage);
312
+ if (!empty($result)) {
313
+ Mage::getSingleton('core/session')->setData('fraud', 1);
314
+ $fraudMessage = implode(', ', $result);
315
+ Mage::getSingleton('core/session')->setData('fraudMessage', $fraudMessage);
316
+ }
317
+ }
318
+ } else {
319
+ // Otherwise base on the Errors (Token transactions)
320
+ $this->isSuccess(!$this->getErrors());
321
+ }
322
+
323
+ return $this;
324
+ }
325
+
326
+ private function _setIfNotEmpty($json, $key)
327
+ {
328
+ if(!empty($json[$key])) {
329
+ $this->setData($key, $json[$key]);
330
+ }
331
+ }
332
+
333
+ /**
334
+ * Override Varien_Object::_underscore() to prevent transform of field name.
335
+ *
336
+ * @param string $name
337
+ * @return string
338
+ */
339
+ protected function _underscore($name)
340
+ {
341
+ return $name;
342
+ }
343
+
344
+ /**
345
+ * replace error code to message
346
+ * @param $message
347
+ */
348
+ public function replaceMessage($message)
349
+ {
350
+ $results = $message;
351
+ if($this->_codes) {
352
+ foreach ($this->_codes as $code => $mess) {
353
+ if(strpos($message, $code) !== false) {
354
+ $results = str_replace( $results, $code, $mess );
355
+ }
356
+ }
357
+ }
358
+ return $results;
359
+ }
360
+ }
app/code/community/Eway/Rapid31/Model/System/Config/Backend/Orderstatus.php ADDED
@@ -0,0 +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
+ }
app/code/community/Eway/Rapid31/Model/System/Config/Backend/Validation.php ADDED
@@ -0,0 +1,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')->__("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
+ }
app/code/community/Eway/Rapid31/Model/System/Config/Source/Cctype.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Model_System_Config_Source_Cctype extends Mage_Payment_Model_Source_Cctype
3
+ {
4
+ public function getAllowedTypes()
5
+ {
6
+ return array('VI', 'MC', 'AE', 'DC', 'JCB', 'VE', 'ME');
7
+ }
8
+ }
app/code/community/Eway/Rapid31/Model/System/Config/Source/ConnectionType.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Model_System_Config_Source_ConnectionType
3
+ {
4
+ /**
5
+ * Options getter
6
+ *
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ return array(
12
+ array(
13
+ 'value' => Eway_Rapid31_Model_Config::CONNECTION_DIRECT,
14
+ 'label'=>Mage::helper('ewayrapid')->__('Direct connection')),
15
+ array(
16
+ 'value' => Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT,
17
+ 'label'=>Mage::helper('ewayrapid')->__('Transparent redirect')),
18
+ array(
19
+ 'value' => Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE,
20
+ 'label'=>Mage::helper('ewayrapid')->__('Responsive shared page')),
21
+ );
22
+ }
23
+ }
app/code/community/Eway/Rapid31/Model/System/Config/Source/Mode.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Model_System_Config_Source_Mode
3
+ {
4
+ /**
5
+ * Options getter
6
+ *
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ return array(
12
+ array(
13
+ 'value' => Eway_Rapid31_Model_Config::MODE_SANDBOX,
14
+ 'label'=>Mage::helper('ewayrapid')->__('Sandbox')),
15
+ array(
16
+ 'value' => Eway_Rapid31_Model_Config::MODE_LIVE,
17
+ 'label'=>Mage::helper('ewayrapid')->__('Live')),
18
+ );
19
+ }
20
+ }
app/code/community/Eway/Rapid31/Model/System/Config/Source/Orderstatus.php ADDED
@@ -0,0 +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
+ }
app/code/community/Eway/Rapid31/Model/System/Config/Source/PaymentAction.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Model_System_Config_Source_PaymentAction
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return array(
7
+ array(
8
+ 'value' => Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE,
9
+ 'label' => Mage::helper('ewayrapid')->__('Authorise and Capture')
10
+ ),
11
+ array(
12
+ 'value' => Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE,
13
+ 'label' => Mage::helper('ewayrapid')->__('Authorise Only')
14
+ )
15
+ );
16
+ }
17
+ }
app/code/community/Eway/Rapid31/Model/System/Config/Source/VerifyStatus.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Model_System_Config_Source_VerifyStatus
3
+ {
4
+ /**
5
+ * Filter out order status based on eWAY requirement
6
+ *
7
+ * @return array
8
+ */
9
+ public function toOptionArray()
10
+ {
11
+ return array(
12
+ array(
13
+ 'value' => 'pending',
14
+ 'label' => ('Pending')
15
+ ),
16
+ array(
17
+ 'value' => 'processing',
18
+ 'label' => ('Processing')
19
+ ),
20
+ );
21
+ }
22
+ }
app/code/community/Eway/Rapid31/Test/Model/Abstract.php ADDED
@@ -0,0 +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
+ }
app/code/community/Eway/Rapid31/Test/Model/Config.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Test_Model_Config extends Eway_Rapid31_Test_Model_Abstract
3
+ {
4
+ public function testDefaultConfig()
5
+ {
6
+ $this->assertEquals(0, Mage::getStoreConfig('payment/ewayrapid_general/active'));
7
+ $this->assertEquals(0, Mage::getStoreConfig('payment/ewayrapid_notsaved/active'));
8
+ $this->assertEquals(0, Mage::getStoreConfig('payment/ewayrapid_saved/active'));
9
+ $this->assertEquals('sandbox', Mage::getStoreConfig('payment/ewayrapid_general/mode'));
10
+ $this->assertEquals('https://api.sandbox.ewaypayments.com/', Mage::getStoreConfig('payment/ewayrapid_general/sandbox_endpoint'));
11
+ $this->assertEquals('https://api.ewaypayments.com/', Mage::getStoreConfig('payment/ewayrapid_general/live_endpoint'));
12
+ $this->assertNull(Mage::getStoreConfig('payment/ewayrapid_general/live_api_key'));
13
+ $this->assertNull(Mage::getStoreConfig('payment/ewayrapid_general/live_api_password'));
14
+ $this->assertNull(Mage::getStoreConfig('payment/ewayrapid_general/sandbox_api_key'));
15
+ $this->assertNull(Mage::getStoreConfig('payment/ewayrapid_general/sandbox_api_password'));
16
+ $this->assertEquals('authorize', Mage::getStoreConfig('payment/ewayrapid_general/payment_action'));
17
+ $this->assertEquals('direct', Mage::getStoreConfig('payment/ewayrapid_general/connection_type'));
18
+ $this->assertEquals(1, Mage::getStoreConfig('payment/ewayrapid_general/can_edit_token'));
19
+ $this->assertEquals(0, Mage::getStoreConfig('payment/ewayrapid_general/can_cancel_subscriptions'));
20
+ $this->assertEquals(1, Mage::getStoreConfig('payment/ewayrapid_general/useccv'));
21
+ $this->assertEquals('AE,VI,MC,DC,JCB', Mage::getStoreConfig('payment/ewayrapid_general/cctypes'));
22
+ $this->assertEquals(0, Mage::getStoreConfig('payment/ewayrapid_general/allowspecific'));
23
+ $this->assertEquals('eway_authorised', Mage::getStoreConfig('payment/ewayrapid_general/order_status'));
24
+ $this->assertEquals(0, Mage::getStoreConfig('payment/ewayrapid_general/ssl_verification'));
25
+ $this->assertEquals(1, Mage::getStoreConfig('payment/ewayrapid_general/transfer_cart_items'));
26
+ $this->assertEquals(0, Mage::getStoreConfig('payment/ewayrapid_general/debug'));
27
+ $this->assertEquals('ewayrapid/method_notsaved', Mage::getStoreConfig('payment/ewayrapid_notsaved/model'));
28
+ $this->assertEquals('ewayrapid/method_saved', Mage::getStoreConfig('payment/ewayrapid_saved/model'));
29
+ }
30
+
31
+ public function testPaymentActive()
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
+
42
+ $methodNotSaved = Mage::getModel('ewayrapid/method_notsaved');
43
+ $methodSaved = Mage::getModel('ewayrapid/method_saved');
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
+ }
53
+
54
+ public function testSSLVerification()
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
+ }
64
+
65
+ public function testConfigModel()
66
+ {
67
+ $config = Mage::getModel('ewayrapid/config');
68
+ $this->assertFalse($config->isDebug());
69
+ $this->assertTrue($config->isSandbox());
70
+ }
71
+ }
app/code/community/Eway/Rapid31/Test/Model/CustomerToken.php ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Test_Model_CustomerToken extends Eway_Rapid31_Test_Model_Abstract
3
+ {
4
+ protected $_dummyJson =
5
+ '{
6
+ "LastId": 3,
7
+ "DefaultToken": 2,
8
+ "Tokens": {
9
+ "1": {
10
+ "Token": "1234567891",
11
+ "Card": "444433******1111",
12
+ "Type": "VI",
13
+ "Owner": "Hiep Ho 1",
14
+ "ExpMonth": "1",
15
+ "ExpYear": "2015",
16
+ "Active": 1,
17
+ "Address": { "FirstName": "John",
18
+ "LastName": "Smith",
19
+ "Street1": "Level 5",
20
+ "Street2": "369 Queen Street",
21
+ "City": "Auckland",
22
+ "State": "",
23
+ "Country": "nz",
24
+ "PostalCode": "1010",
25
+ "Phone": "09 889 0986"
26
+ }
27
+ },
28
+ "2": {
29
+ "Token": "1234567892",
30
+ "Card": "378282******005",
31
+ "Type": "AE",
32
+ "Owner": "Hiep Ho 2",
33
+ "ExpMonth": "2",
34
+ "ExpYear": "2015",
35
+ "Active": 0,
36
+ "Address": { "FirstName": "John",
37
+ "LastName": "Smith",
38
+ "Street1": "Level 5",
39
+ "Street2": "369 Queen Street",
40
+ "City": "Auckland",
41
+ "State": "",
42
+ "Country": "nz",
43
+ "PostalCode": "1010",
44
+ "Phone": "09 889 0986"
45
+ }
46
+ },
47
+ "3": {
48
+ "Token": "1234567893",
49
+ "Card": "353011******0000",
50
+ "Type": "JCB",
51
+ "Owner": "Hiep Ho 3",
52
+ "ExpMonth": "3",
53
+ "ExpYear": "2015",
54
+ "Active": 1,
55
+ "Address": { "FirstName": "John",
56
+ "LastName": "Smith",
57
+ "Street1": "Level 5",
58
+ "Street2": "369 Queen Street",
59
+ "City": "Auckland",
60
+ "State": "",
61
+ "Country": "nz",
62
+ "PostalCode": "1010",
63
+ "Phone": "09 889 0986"
64
+ }
65
+ }
66
+ }
67
+ }';
68
+
69
+ public function testEncode()
70
+ {
71
+ $savedTokens = Mage::getModel('ewayrapid/customer_savedtokens')
72
+ ->setDefaultToken(2)
73
+ ->setLastId(3);
74
+
75
+ $tokens = array();
76
+ $address = $this->getDummyShippingAddress();
77
+ $token = Mage::getModel('ewayrapid/customer_token')
78
+ ->setAddress($address)
79
+ ->setActive(1)
80
+ ->setCard('444433******1111')
81
+ ->setType('VI')
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')
90
+ ->setAddress($address)
91
+ ->setActive(0)
92
+ ->setCard('378282******005')
93
+ ->setType('AE')
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')
102
+ ->setAddress($address)
103
+ ->setActive(1)
104
+ ->setCard('353011******0000')
105
+ ->setType('JCB')
106
+ ->setToken('1234567893')
107
+ ->setExpMonth(3)
108
+ ->setExpYear(2015)
109
+ ->setOwner('Hiep Ho 3')
110
+ ;
111
+ $tokens[3] = $token;
112
+
113
+ $savedTokens->setTokens($tokens);
114
+ $this->assertJsonMatch($savedTokens->jsonSerialize(), $this->_dummyJson);
115
+ }
116
+
117
+ public function testDecode()
118
+ {
119
+ $savedTokens = Mage::getModel('ewayrapid/customer_savedtokens')->decodeJSON($this->_dummyJson);
120
+ $this->assertJsonMatch($savedTokens->jsonSerialize(), $this->_dummyJson);
121
+ }
122
+
123
+
124
+ public function testSavedTokens()
125
+ {
126
+ $customer = Mage::getModel('customer/customer');
127
+ $customer->setSavedTokens(Mage::getModel('ewayrapid/customer_savedtokens')->decodeJSON($this->_dummyJson));
128
+
129
+ $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
130
+ $customer->setStore(Mage::app()->getStore());
131
+ $customer->setFirstname("Dummy");
132
+ $customer->setLastname("User");
133
+ $customer->setEmail(time() . "1@dummy.com");
134
+ $customer->setPasswordHash(md5("dummy"));
135
+ $customer->save();
136
+
137
+ $customer = Mage::getModel('customer/customer')->load($customer->getId());
138
+ $savedTokens = $customer->getSavedTokens();
139
+ $this->assertInstanceOf('Eway_Rapid31_Model_Customer_Savedtokens', $savedTokens);
140
+ $this->assertJsonMatch($savedTokens->jsonSerialize(), $this->_dummyJson);
141
+ }
142
+
143
+ public function testCustomerHelper()
144
+ {
145
+ $customer = Mage::getModel('customer/customer');
146
+ $customer->setSavedTokens(Mage::getModel('ewayrapid/customer_savedtokens')->decodeJSON($this->_dummyJson));
147
+
148
+ $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
149
+ $customer->setStore(Mage::app()->getStore());
150
+ $customer->setFirstname("Dummy");
151
+ $customer->setLastname("User");
152
+ $customer->setEmail(time() . "2@dummy.com");
153
+ $customer->setPasswordHash(md5("dummy"));
154
+ $customer->save();
155
+
156
+ $customer = Mage::getModel('customer/customer')->load($customer->getId());
157
+ $helper = Mage::helper('ewayrapid/customer')->setCurrentCustomer($customer);
158
+ /* @var Eway_Rapid31_Helper_Customer $helper */
159
+ $address = $this->getDummyShippingAddress();
160
+ $address->setFirstName('Hiep Ho');
161
+ $helper->updateToken(2, array('Active' => 1, 'Address' => $address));
162
+
163
+ $customer = Mage::getModel('customer/customer')->load($customer->getId());
164
+ $helper->setCurrentCustomer($customer);
165
+ $savedTokens = $customer->getSavedTokens();
166
+ $token = $savedTokens->getTokenById(2);
167
+ $this->assertEquals(1, $token->getActive());
168
+ $this->assertEquals('Hiep Ho', $token->getAddress()->getFirstName());
169
+
170
+ $activeTokens = $helper->getActiveTokenList();
171
+ $this->assertEquals(3, count($activeTokens));
172
+
173
+ $tokenInfo = array(
174
+ 'Token' => '1234567894',
175
+ 'Card' => '353011******0000',
176
+ 'Owner' => 'Hiep Ho 4',
177
+ 'ExpMonth' => 4,
178
+ 'ExpYear' => 2015,
179
+ 'Type' => 'JCB',
180
+ 'Address' => $address,
181
+ );
182
+
183
+ $helper->addToken($tokenInfo);
184
+ $customer = Mage::getModel('customer/customer')->load($customer->getId());
185
+ $tokens = $customer->getSavedTokens()->getTokens();
186
+ $this->assertEquals(4, count($tokens));
187
+ $this->assertEquals(1, $tokens[4]->getActive());
188
+
189
+ $helper->setCurrentCustomer($customer);
190
+ $helper->deleteToken(4);
191
+ $customer = Mage::getModel('customer/customer')->load($customer->getId());
192
+ $helper->setCurrentCustomer($customer);
193
+ $this->assertEquals(3, count($helper->getActiveTokenList()));
194
+
195
+ $this->assertEquals(4, $helper->getLastTokenId());
196
+
197
+ $this->assertEquals(2, $helper->getDefaultToken());
198
+ $helper->setDefaultToken(3);
199
+ $customer = Mage::getModel('customer/customer')->load($customer->getId());
200
+ $helper->setCurrentCustomer($customer);
201
+ $this->assertEquals(3, $helper->getDefaultToken());
202
+ }
203
+ }
app/code/community/Eway/Rapid31/Test/Model/JsonSerializable.php ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Eway_Rapid31_Test_Model_JsonSerializable extends Eway_Rapid31_Test_Model_Abstract
3
+ {
4
+ public function testDummyData()
5
+ {
6
+ $this->assertJsonMatch($this->getDummyShippingAddress()->jsonSerialize(),
7
+ '{ "FirstName": "John",
8
+ "LastName": "Smith",
9
+ "Street1": "Level 5",
10
+ "Street2": "369 Queen Street",
11
+ "City": "Auckland",
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",
21
+ "ExpiryYear": "16",
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.",
47
+ "FirstName": "John",
48
+ "LastName": "Smith",
49
+ "CompanyName": "Demo Shop 123",
50
+ "JobDescription": "Developer",
51
+ "Street1": "Level 5",
52
+ "Street2": "369 Queen Street",
53
+ "City": "Auckland",
54
+ "State": "",
55
+ "PostalCode": "1010",
56
+ "Country": "nz",
57
+ "Email": "",
58
+ "Phone": "09 889 0986",
59
+ "Mobile": "09 889 0986",
60
+ "Comments": "",
61
+ "Fax": "",
62
+ "Url": "",
63
+ "CardDetails": {
64
+ "Name": "Card Holder Name",
65
+ "Number": "4444333322221111",
66
+ "ExpiryMonth": "12",
67
+ "ExpiryYear": "16",
68
+ "StartMonth" : "",
69
+ "StartYear" : "",
70
+ "IssueNumber": "",
71
+ "CVN": "123"
72
+ }
73
+ }');
74
+ }
75
+
76
+ public function testRequestDirect()
77
+ {
78
+ $request = Mage::getModel('ewayrapid/request_direct')
79
+ ->setCustomer($this->getDummyCustomer())
80
+ ->setShippingAddress($this->getDummyShippingAddress())
81
+ ->setShippingMethod('NextDay')
82
+ ->setItems($this->getDummyLineItemArray(3))
83
+ ->setPayment($this->getDummyPayment())
84
+ ->setDeviceID('D1234')
85
+ ->setCustomerIP('127.0.0.1')
86
+ ->setPartnerID('04A0FD665F7348A295C5B9EE95400301')
87
+ ->setTransactionType('Purchase')
88
+ ->setMethod('ProcessPayment');
89
+
90
+ $this->assertJsonMatch($request->jsonSerialize(),
91
+ '{ "Customer": {
92
+ "Reference": "A12345",
93
+ "Title": "Mr.",
94
+ "FirstName": "John",
95
+ "LastName": "Smith",
96
+ "CompanyName": "Demo Shop 123",
97
+ "JobDescription": "Developer",
98
+ "Street1": "Level 5",
99
+ "Street2": "369 Queen Street",
100
+ "City": "Auckland",
101
+ "State": "",
102
+ "PostalCode": "1010",
103
+ "Country": "nz",
104
+ "Email": "",
105
+ "Phone": "09 889 0986",
106
+ "Mobile": "09 889 0986",
107
+ "Comments": "",
108
+ "Fax": "",
109
+ "Url": "",
110
+ "CardDetails": {
111
+ "Name": "Card Holder Name",
112
+ "Number": "4444333322221111",
113
+ "ExpiryMonth": "12",
114
+ "ExpiryYear": "16",
115
+ "StartMonth" : "",
116
+ "StartYear" : "",
117
+ "IssueNumber": "",
118
+ "CVN": "123"
119
+ }
120
+ },
121
+ "ShippingAddress": {
122
+ "FirstName": "John",
123
+ "LastName": "Smith",
124
+ "Street1": "Level 5",
125
+ "Street2": "369 Queen Street",
126
+ "City": "Auckland",
127
+ "State": "",
128
+ "Country": "nz",
129
+ "PostalCode": "1010",
130
+ "Phone": "09 889 0986"
131
+ },
132
+ "ShippingMethod": "NextDay",
133
+ "Items": [
134
+ {
135
+ "SKU": "SKU1",
136
+ "Description": "Description1",
137
+ "Quantity": "1",
138
+ "UnitCost": "100",
139
+ "Tax": "0",
140
+ "Total": "100"
141
+ },
142
+ {
143
+ "SKU": "SKU2",
144
+ "Description": "Description2",
145
+ "Quantity": "1",
146
+ "UnitCost": "100",
147
+ "Tax": "0",
148
+ "Total": "100"
149
+ },
150
+ {
151
+ "SKU": "SKU3",
152
+ "Description": "Description3",
153
+ "Quantity": "1",
154
+ "UnitCost": "100",
155
+ "Tax": "0",
156
+ "Total": "100"
157
+ }
158
+ ],
159
+ "Payment": {
160
+ "TotalAmount": 100,
161
+ "InvoiceNumber": "Inv 21540",
162
+ "InvoiceDescription": "Individual Invoice Description",
163
+ "InvoiceReference": "513456",
164
+ "CurrencyCode": "AUD"
165
+ },
166
+ "DeviceID": "D1234",
167
+ "CustomerIP": "127.0.0.1",
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": "**",
182
+ "ExpiryYear": "**",
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",
193
+ "ExpiryYear": "16",
194
+ "StartMonth" : "",
195
+ "StartYear" : "",
196
+ "IssueNumber": "",
197
+ "CVN": "123" }');
198
+ }
199
+ }
app/code/community/Eway/Rapid31/Test/Model/Request.php ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @loadSharedFixture
4
+ */
5
+ class Eway_Rapid31_Test_Model_Request extends Eway_Rapid31_Test_Model_Abstract
6
+ {
7
+ /**
8
+ * Error case (blank request)
9
+ */
10
+ public function testBlankBody()
11
+ {
12
+ $this->assertEquals(1, Mage::getStoreConfig('payment/ewayrapid_general/debug'));
13
+ /* @var Eway_Rapid31_Model_Request_Abstract $request */
14
+ $request = $this->getMockForAbstractClass('Eway_Rapid31_Model_Request_Abstract');
15
+
16
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Transaction'));
17
+ /* @var Eway_Rapid31_Model_Response $response */
18
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
19
+ $this->assertFalse($response->isSuccess());
20
+ $this->assertContains('V6021', $response->getErrors());
21
+ }
22
+
23
+ /**
24
+ * Success case
25
+ */
26
+ public function testSuccess()
27
+ {
28
+ /* @var Eway_Rapid31_Model_Request_Abstract $request */
29
+ $request = $this->getMockForAbstractClass('Eway_Rapid31_Model_Request_Abstract');
30
+
31
+ $request->setCustomer($this->getDummyCustomer())
32
+ ->setShippingAddress($this->getDummyShippingAddress())
33
+ ->setShippingMethod('NextDay')
34
+ ->setItems($this->getDummyLineItemArray(3))
35
+ ->setPayment($this->getDummyPayment())
36
+ ->setDeviceID('D1234')
37
+ ->setCustomerIP('127.0.0.1')
38
+ ->setPartnerID('04A0FD665F7348A295C5B9EE95400301')
39
+ ->setTransactionType('Purchase')
40
+ ->setMethod('ProcessPayment');
41
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Transaction'));
42
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
43
+ $this->assertTrue($response->isSuccess());
44
+ $this->assertEquals('00', $response->getResponseCode());
45
+ $this->assertEquals('A2000', $response->getResponseMessage());
46
+ $this->assertNull($response->getErrors());
47
+
48
+ }
49
+
50
+ /**
51
+ * Error case (REMEMBER TO ENABLE 'Use Cents Value' in MYeWAY sandbox)
52
+ */
53
+ public function testError()
54
+ {
55
+ /* @var Eway_Rapid31_Model_Request_Abstract $request */
56
+ $request = $this->getMockForAbstractClass('Eway_Rapid31_Model_Request_Abstract');
57
+ $request->setCustomer($this->getDummyCustomer())
58
+ ->setShippingAddress($this->getDummyShippingAddress())
59
+ ->setShippingMethod('NextDay')
60
+ ->setItems($this->getDummyLineItemArray(3))
61
+ ->setDeviceID('D1234')
62
+ ->setCustomerIP('127.0.0.1')
63
+ ->setPartnerID('04A0FD665F7348A295C5B9EE95400301')
64
+ ->setTransactionType('Purchase')
65
+ ->setMethod('ProcessPayment');
66
+ $payment = $this->getDummyPayment();
67
+ $payment->setTotalAmount(101); // 'D4401' => "Refer to Issuer"
68
+ $request->setPayment($payment);
69
+
70
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Transaction'));
71
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
72
+ $this->assertFalse($response->isSuccess());
73
+ $this->assertEquals('01', $response->getResponseCode());
74
+ $this->assertNull($response->getErrors());
75
+ $this->assertEquals('D4401', $response->getResponseMessage());
76
+ $this->assertEquals('Refer to Issuer', $response->getMessage());
77
+ }
78
+
79
+ public function testAuthorisationAndCapture()
80
+ {
81
+ /* @var Eway_Rapid31_Model_Request_Abstract $request */
82
+ $request = $this->getMockForAbstractClass('Eway_Rapid31_Model_Request_Abstract');
83
+
84
+ $request->setCustomer($this->getDummyCustomer())
85
+ ->setShippingAddress($this->getDummyShippingAddress())
86
+ ->setItems($this->getDummyLineItemArray(3))
87
+ ->setPayment($this->getDummyPayment())
88
+ ->setTransactionType('Purchase')
89
+ ->setMethod('Authorise');
90
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Authorisation'));
91
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
92
+ $this->assertTrue($response->isSuccess());
93
+ $this->assertEquals('00', $response->getResponseCode());
94
+ $this->assertEquals('A2000', $response->getResponseMessage());
95
+ $this->assertNull($response->getErrors());
96
+
97
+ $transactionId = $response->getTransactionID();
98
+ $this->assertGreaterThan(1, $transactionId);
99
+
100
+ $request->unsetData();
101
+ $request->setPayment($this->getDummyPayment());
102
+ $request->setTransactionId($transactionId);
103
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('CapturePayment'));
104
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
105
+ $this->assertTrue($response->isSuccess());
106
+ $this->assertGreaterThan($transactionId, $response->getTransactionID());
107
+ $this->assertNull($response->getErrors());
108
+
109
+ return $response->getTransactionID();
110
+ }
111
+
112
+ public function testAuthorisationAndCancel()
113
+ {
114
+ /* @var Eway_Rapid31_Model_Request_Abstract $request */
115
+ $request = $this->getMockForAbstractClass('Eway_Rapid31_Model_Request_Abstract');
116
+
117
+ $request->setCustomer($this->getDummyCustomer())
118
+ ->setShippingAddress($this->getDummyShippingAddress())
119
+ ->setItems($this->getDummyLineItemArray(3))
120
+ ->setPayment($this->getDummyPayment())
121
+ ->setTransactionType('Purchase')
122
+ ->setMethod('Authorise');
123
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Authorisation'));
124
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
125
+ $this->assertTrue($response->isSuccess());
126
+ $this->assertEquals('00', $response->getResponseCode());
127
+ $this->assertEquals('A2000', $response->getResponseMessage());
128
+ $this->assertNull($response->getErrors());
129
+
130
+ $transactionId = $response->getTransactionID();
131
+ $this->assertGreaterThan(1, $transactionId);
132
+
133
+ $request->unsetData();
134
+ $request->setTransactionId($transactionId);
135
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('CancelAuthorisation'));
136
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
137
+ $this->assertTrue($response->isSuccess());
138
+ $this->assertGreaterThan($transactionId, $response->getTransactionID());
139
+ $this->assertNull($response->getErrors());
140
+ }
141
+
142
+ public function testTransactionAndRefund()
143
+ {
144
+ /* @var Eway_Rapid31_Model_Request_Abstract $request */
145
+ $request = $this->getMockForAbstractClass('Eway_Rapid31_Model_Request_Abstract');
146
+
147
+ $request->setCustomer($this->getDummyCustomer())
148
+ ->setShippingAddress($this->getDummyShippingAddress())
149
+ ->setPayment($this->getDummyPayment())
150
+ ->setTransactionType('Purchase')
151
+ ->setMethod('ProcessPayment');
152
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Transaction'));
153
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
154
+ $this->assertTrue($response->isSuccess());
155
+ $this->assertEquals('00', $response->getResponseCode());
156
+ $this->assertEquals('A2000', $response->getResponseMessage());
157
+ $this->assertNull($response->getErrors());
158
+
159
+ $transactionId = $response->getTransactionID();
160
+ $this->assertGreaterThan(1, $transactionId);
161
+
162
+ $request->unsetData();
163
+
164
+ $payment = $this->getDummyPayment();
165
+ $payment->setTransactionID($transactionId);
166
+ $request->setRefund($payment);
167
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Transaction/' . $transactionId . '/Refund'));
168
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
169
+ $this->assertTrue($response->isSuccess());
170
+ $this->assertEquals('A2000', $response->getResponseMessage());
171
+ $this->assertNull($response->getErrors());
172
+ $this->assertGreaterThan($transactionId, $response->getTransactionID());
173
+ }
174
+
175
+ public function testAuthorisationCaptureAndRefund()
176
+ {
177
+ $transactionId = $this->testAuthorisationAndCapture();
178
+ /* @var Eway_Rapid31_Model_Request_Abstract $request */
179
+ $request = $this->getMockForAbstractClass('Eway_Rapid31_Model_Request_Abstract');
180
+ $payment = $this->getDummyPayment();
181
+ $payment->setTransactionID($transactionId);
182
+ $request->setRefund($payment);
183
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Transaction/' . $transactionId . '/Refund'));
184
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
185
+ $this->assertTrue($response->isSuccess());
186
+ $this->assertEquals('A2000', $response->getResponseMessage());
187
+ $this->assertNull($response->getErrors());
188
+ $this->assertGreaterThan($transactionId, $response->getTransactionID());
189
+ }
190
+
191
+ }
app/code/community/Eway/Rapid31/Test/Model/Request/fixtures/default.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ config:
2
+ stores/admin/payment/ewayrapid_general/sandbox_api_key: 'cZpDMzAhynZo3f4RIwTmRWEXU0ZixvZbvM/GVbgIpzieoaip0XZ/dYji6A/MIgBPYnvldWHP+E+VGPLzAYQxfczBMfT6QhIX'
3
+ stores/admin/payment/ewayrapid_general/sandbox_api_password: 'NxVgbCAnIJw='
4
+ stores/admin/payment/ewayrapid_general/debug: 1
5
+ stores/admin/payment/ewayrapid_general/mode: 'sandbox'
6
+ stores/admin/payment/ewayrapid_general/ssl_verification: 0
app/code/community/Eway/Rapid31/Test/Model/Response.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ 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",
10
+ "ResponseMessage": "D4458",
11
+ "TransactionID": 1006615,
12
+ "TransactionStatus": false,
13
+ "TransactionType": "MOTO",
14
+ "BeagleScore": 12.58,
15
+ "Verification": {
16
+ "CVN": 0,
17
+ "Address": 0,
18
+ "Email": 0,
19
+ "Mobile": 0,
20
+ "Phone": 0
21
+ },
22
+ "Customer": {
23
+ "IsActive": false,
24
+ "TokenCustomerID": 12345,
25
+ "Reference": "A12345",
26
+ "Title": "Mr.",
27
+ "FirstName": "John",
28
+ "LastName": "Smith",
29
+ "CompanyName": "Demo Shop 123",
30
+ "JobDescription": "Developer",
31
+ "Street1": "Level 5",
32
+ "Street2": "369 Queen Street",
33
+ "City": "Auckland",
34
+ "State": "",
35
+ "PostalCode": "1010",
36
+ "Country": "au",
37
+ "Email": "",
38
+ "Phone": "09 889 0986",
39
+ "Mobile": "09 889 0986",
40
+ "Comments": "",
41
+ "Fax": "",
42
+ "Url": "",
43
+ "CardDetails": {
44
+ "Number": "444433XXXXXX1111",
45
+ "Name": "Card Holder Name",
46
+ "ExpiryMonth": "12",
47
+ "ExpiryYear": "16",
48
+ "StartMonth": null,
49
+ "StartYear": null,
50
+ "IssueNumber": null,
51
+ "CVN": null
52
+ }
53
+ },
54
+ "Payment": {
55
+ "TotalAmount": 100,
56
+ "InvoiceNumber": "Inv 21540",
57
+ "InvoiceDescription": "Individual Invoice Description",
58
+ "InvoiceReference": "513456",
59
+ "CurrencyCode": "AUD"
60
+ },
61
+ "Errors": null
62
+ }
63
+ ');
64
+
65
+ $this->assertEquals('000000', $response->getAuthorisationCode());
66
+ $this->assertEquals('58', $response->getResponseCode());
67
+ $this->assertEquals('D4458', $response->getResponseMessage());
68
+ $this->assertEquals(false, $response->getTransactionStatus());
69
+ $this->assertEquals(false, $response->isSuccess());
70
+ $this->assertEquals(1006615, $response->getTransactionID());
71
+ $this->assertEquals(12345, $response->getTokenCustomerID());
72
+ $this->assertEquals('Function Not Permitted to Terminal', $response->getMessage());
73
+ }
74
+ }
app/code/community/Eway/Rapid31/Test/Model/TokenRequest.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @loadSharedFixture
4
+ */
5
+ class Eway_Rapid31_Test_Model_TokenRequest extends Eway_Rapid31_Test_Model_Abstract
6
+ {
7
+ public function testCreateToken()
8
+ {
9
+ /* @var Eway_Rapid31_Model_Response $response */
10
+ $request = $this->getMockForAbstractClass('Eway_Rapid31_Model_Request_Abstract');
11
+ $customer = $this->getDummyCustomer();
12
+ // Create new: Error
13
+ $customer->getCardDetails()->setNumber('4444333322221112');
14
+ $request->setCustomer($customer);
15
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Customer'));
16
+ $this->assertFalse($response->isSuccess());
17
+ $this->assertEquals(1, count($response->getErrors()));
18
+ $this->assertEquals('Invalid ProcessRequest Number', $response->getMessage());
19
+
20
+ // Create new: Success
21
+ $customer->getCardDetails()->setNumber('4444333322221111');
22
+ $request->setCustomer($customer);
23
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Customer'));
24
+ $this->assertTrue($response->isSuccess());
25
+ $this->assertNotNull($response->getTokenCustomerID());
26
+
27
+ // Update
28
+ $customer->setTokenCustomerID($response->getTokenCustomerID());
29
+ $customer->setFirstName('Hiep');
30
+ $cardDetail = $customer->getCardDetails();
31
+ $cardDetail->setName('Ho Minh Hiep');
32
+ $cardDetail->setExpiryMonth('10');
33
+ $cardDetail->setNumber('5555555555554444');
34
+ $request->setCustomer($customer);
35
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Customer', 'PUT'));
36
+ $this->assertTrue($response->isSuccess());
37
+ $this->assertNotNull($response->getTokenCustomerID());
38
+ $this->assertEquals($customer->getTokenCustomerID(), $response->getTokenCustomerID());
39
+ $updatedCustomer = $response->getCustomer();
40
+ $this->assertEquals('555555XXXXXX4444', $updatedCustomer['CardDetails']['Number']);
41
+ $this->assertEquals('Ho Minh Hiep', $updatedCustomer['CardDetails']['Name']);
42
+ $this->assertEquals('10', $updatedCustomer['CardDetails']['ExpiryMonth']);
43
+ $this->assertEquals('Hiep', $updatedCustomer['FirstName']);
44
+
45
+ // $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Customer/919601631568', 'GET'));
46
+ // $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Transaction/10728154', 'GET'));
47
+
48
+ }
49
+
50
+ public function testTokenPayment()
51
+ {
52
+ /* @var Eway_Rapid31_Model_Response $response */
53
+ /* @var Eway_Rapid31_Model_Request_Abstract $request */
54
+ $request = $this->getMockForAbstractClass('Eway_Rapid31_Model_Request_Abstract');
55
+ $customer = $this->getDummyCustomer();
56
+ $request->setCustomer($customer);
57
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Customer'));
58
+ $this->assertTrue($response->isSuccess());
59
+ $this->assertNotNull($response->getTokenCustomerID());
60
+
61
+ $customer = Mage::getModel('ewayrapid/field_customer');
62
+ $customer->setTokenCustomerID($response->getTokenCustomerID());
63
+ $request->setCustomer($customer);
64
+ $payment = $this->getDummyPayment();
65
+ $payment->setTotalAmount(1000);
66
+ $request->setPayment($payment);
67
+ $request->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_MOTO);
68
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Transaction'));
69
+ $this->assertTrue($response->isSuccess());
70
+ $this->assertEquals('00', $response->getResponseCode());
71
+ $this->assertEquals('A2000', $response->getResponseMessage());
72
+ $this->assertNull($response->getErrors());
73
+
74
+ $request->unsetData();
75
+ $customer->setCardDetails(Mage::getModel('ewayrapid/field_cardDetails')->setCVN('123'));
76
+ $request->setCustomer($customer);
77
+ $request->setPayment($payment);
78
+ $request->setTransactionType(Eway_Rapid31_Model_Config::TRANSACTION_PURCHASE);
79
+ $request->setMethod(Eway_Rapid31_Model_Config::METHOD_AUTHORISE);
80
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Authorisation'));
81
+ $this->assertTrue($response->isSuccess());
82
+ $this->assertEquals('00', $response->getResponseCode());
83
+ $this->assertEquals('A2000', $response->getResponseMessage());
84
+ $this->assertNull($response->getErrors());
85
+ $transactionId = $response->getTransactionID();
86
+ $this->assertGreaterThan(1, $transactionId);
87
+
88
+ $request->unsetData();
89
+ $request->setTransactionId($transactionId);
90
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('CancelAuthorisation'));
91
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
92
+ $this->assertTrue($response->isSuccess());
93
+ $this->assertGreaterThan($transactionId, $response->getTransactionID());
94
+ $this->assertNull($response->getErrors());
95
+ }
96
+
97
+ public function _testQuick()
98
+ {
99
+ /* @var Eway_Rapid31_Model_Request_Abstract $request */
100
+ $request = $this->getMockForAbstractClass('Eway_Rapid31_Model_Request_Abstract');
101
+
102
+ $transactionId = 10735468;
103
+ $payment = $this->getDummyPayment();
104
+ $payment->setTransactionID($transactionId);
105
+ $payment->setTotalAmount(23996);
106
+ $request->setRefund($payment);
107
+ $customer = Mage::getModel('ewayrapid/field_customer');
108
+ $customer->setTokenCustomerID(912903316601);
109
+ $request->setCustomer($customer);
110
+ $response = EcomDev_Utils_Reflection::invokeRestrictedMethod($request, '_doRapidAPI', array('Transaction/' . $transactionId . '/Refund'));
111
+ $this->assertInstanceOf('Eway_Rapid31_Model_Response', $response);
112
+ $this->assertTrue($response->isSuccess());
113
+ $this->assertEquals('A2000', $response->getResponseMessage());
114
+ $this->assertNull($response->getErrors());
115
+ $this->assertGreaterThan($transactionId, $response->getTransactionID());
116
+
117
+ }
118
+ }
app/code/community/Eway/Rapid31/Test/Model/TokenRequest/fixtures/default.yaml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ config:
2
+ stores/admin/payment/ewayrapid_general/sandbox_api_key: 'cZpDMzAhynZo3f4RIwTmRWEXU0ZixvZbvM/GVbgIpzieoaip0XZ/dYji6A/MIgBPYnvldWHP+E+VGPLzAYQxfczBMfT6QhIX'
3
+ stores/admin/payment/ewayrapid_general/sandbox_api_password: 'NxVgbCAnIJw='
4
+ stores/admin/payment/ewayrapid_general/debug: 1
5
+ stores/admin/payment/ewayrapid_general/mode: 'sandbox'
6
+ stores/admin/payment/ewayrapid_general/ssl_verification: 0
app/code/community/Eway/Rapid31/controllers/Adminhtml/IndexController.php ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: Administrator PC
5
+ * Date: 7/22/14
6
+ * Time: 9:07 AM
7
+ */
8
+ class Eway_Rapid31_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action {
9
+ public function indexAction() {
10
+
11
+ }
12
+
13
+ public function massEwayAuthorisedAction() {
14
+ $data = Mage::app()->getRequest()->getPost();
15
+ if(is_array($data) & isset($data['order_ids'])) {
16
+ foreach($data['order_ids'] as $id) {
17
+ $order = Mage::getModel('sales/order')->load($id);
18
+ $order->setData('state', 'processing');
19
+ $order->setData('status', Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED);
20
+ $order->save();
21
+
22
+ // Update user fraud status
23
+ $customer_data = Mage::getModel('customer/customer')->load($order->getCustomerId());
24
+ $customer_data->setData('mark_fraud', 0);
25
+ $customer_data->save();
26
+
27
+ // Re-order current order
28
+ // ...
29
+ }
30
+ }
31
+ // Redirect form
32
+ $this->_redirectUrl(Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/index"));
33
+ }
34
+
35
+ public function massProcessingAction() {
36
+ $data = Mage::app()->getRequest()->getPost();
37
+ if(is_array($data) & isset($data['order_ids'])) {
38
+ foreach($data['order_ids'] as $id) {
39
+ $order = Mage::getModel('sales/order')->load($id);
40
+ $order->setData('state', 'processing');
41
+ $order->setData('status', 'processing');
42
+ $order->save();
43
+
44
+ // Update user fraud status
45
+ $customer_data = Mage::getModel('customer/customer')->load($order->getCustomerId());
46
+ $customer_data->setData('mark_fraud', 0);
47
+ $customer_data->save();
48
+
49
+ // Re-order current order
50
+ // ...
51
+ }
52
+ }
53
+ // Redirect form
54
+ $this->_redirectUrl(Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/index"));
55
+ }
56
+
57
+ public function massVerifyEwayOrderAction() {
58
+ $data = Mage::app()->getRequest()->getPost();
59
+ if(is_array($data) & isset($data['order_ids'])) {
60
+
61
+ foreach($data['order_ids'] as $id) {
62
+
63
+ $order = Mage::getModel('sales/order')->load($id);
64
+
65
+ $result = $this->__getTransaction($order->getEwayTransactionId());
66
+
67
+ // Check return data
68
+ $result_decode = json_decode($result);
69
+
70
+ $trans = $result_decode->Transactions;
71
+ if(!isset($trans[0])) {
72
+ continue; // go to next cycle when no element is exist
73
+ }
74
+ $tranId = $trans[0]->TransactionID;
75
+
76
+ if($trans[0]->ResponseMessage == 'A2000') { // Success - Fraud order has been approved
77
+ // Create new transaction
78
+ $this->__createNewTransaction($order, $tranId);
79
+ // Update order status
80
+ $this->__updateStatusOrder($order);
81
+ // Un-mark fraud customer
82
+ $this->__unMarkFraudUser($order);
83
+ }
84
+ }
85
+ }
86
+ // Redirect form
87
+ $this->_redirectUrl(Mage::helper("adminhtml")->getUrl("adminhtml/sales_order/index"));
88
+ }
89
+ private function __getTransaction($transId) {
90
+ $ewayConfig = Mage::getSingleton('ewayrapid/config');
91
+ $url = $ewayConfig->getRapidAPIUrl('Transaction') . '/' . $transId;
92
+ $ch = curl_init($url);
93
+ curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
94
+ curl_setopt($ch, CURLOPT_USERPWD, $ewayConfig->getBasicAuthenticationHeader());
95
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
96
+
97
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
98
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
99
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ewayConfig->isEnableSSLVerification());
100
+
101
+ $result = curl_exec($ch);
102
+ return $result;
103
+ }
104
+
105
+ /**
106
+ * Create new transaction with base order
107
+ * @param $data
108
+ */
109
+ private function __createNewTransaction(Mage_Sales_Model_Order $order, $transId) {
110
+
111
+ // Load transaction
112
+ $currentTrans = Mage::getModel('sales/order_payment_transaction')
113
+ ->getCollection()
114
+ ->addFieldToFilter('order_id', array('eq' => $order->getEntityId()));
115
+ foreach($currentTrans as $t) { }
116
+ if($t == null) {
117
+ $t = new Mage_Sales_Model_Order_Payment_Transaction();
118
+ }
119
+
120
+ $trans = new Mage_Sales_Model_Order_Payment_Transaction();
121
+ // Load payment object
122
+ $payment = Mage::getModel('sales/order_payment')->load($t->getPaymentId());
123
+
124
+ $trans->setOrderPaymentObject($payment);
125
+ $trans->setOrder($order);
126
+
127
+ $trans->setParentId($t->getTransactionId());
128
+ $trans->setOrderId($order->getEntityId());
129
+ $trans->setPaymentId($t->getPaymentId());
130
+ // Get new TxnId
131
+ $break = true;
132
+ for($i = 0; $i < 100; $i++) {
133
+ $transId += 1;
134
+ $newTrans = Mage::getModel('sales/order_payment_transaction')
135
+ ->getCollection()
136
+ ->addFieldToFilter('txn_id', array('eq' => $transId));
137
+ if(count($newTrans) == 0) {
138
+ $break = false;
139
+ break;
140
+ }
141
+ }
142
+ if($break) {
143
+ return false;
144
+ }
145
+ $trans->setTxnId($transId);
146
+
147
+ $trans->setParentTxnId($t->getTxnId());
148
+ $trans->setTxnType($t->getTxnType());
149
+ $trans->setIsClosed($t->getIsClosed());
150
+ $trans->setCreatedAt(date('Y-m-d H:i:s'));
151
+
152
+ try {
153
+ $trans->save();
154
+ } catch(Exception $e) {
155
+ // Do something
156
+ }
157
+ return true;
158
+
159
+ }
160
+
161
+ private function __updateStatusOrder(Mage_Sales_Model_Order $order) {
162
+ $state_config = Mage::getStoreConfig('payment/ewayrapid_general/verify_eway_order');
163
+
164
+ $order->setState($state_config);
165
+ $order->setStatus($state_config);
166
+ $order->save();
167
+ }
168
+
169
+ private function __unMarkFraudUser(Mage_Sales_Model_Order $order) {
170
+ if ($uid = $order->getCustomerId()) {
171
+ $customer = Mage::getModel('customer/customer')->load($uid);
172
+ $customer->setMarkFraud(0);
173
+ $customer->save();
174
+ }
175
+ }
176
+
177
+ }
app/code/community/Eway/Rapid31/controllers/MycardsController.php ADDED
@@ -0,0 +1,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(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
+ ) {
258
+ $method = 'AccessCodesShared';
259
+ }
260
+
261
+ $request = $this->getRequest();
262
+
263
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
264
+ list($billingAddress, $infoInstance) = $this->_generateApiParams($request);
265
+ $data = $apiRequest->createAccessCode($billingAddress, $infoInstance, $method, $request);
266
+
267
+ /*
268
+ * {"AccessCode":"C3AB9RIc_reC_FRm8nXsy36QddJm_-YlaZCc2ZHuhbOeR5RzX682kfgl_12-vipFpJiuPPcOyh-ToeWP--Px06J04mW1zhqKpyqRTsvz0ub9-URgih4V_rHDYoNxQHXq9Ho2l",
269
+ * "Customer":{
270
+ * "CardNumber":"",
271
+ * "CardStartMonth":"",
272
+ * "CardStartYear":"",
273
+ * "CardIssueNumber":"",
274
+ * "CardName":"",
275
+ * "CardExpiryMonth":"",
276
+ * "CardExpiryYear":"",
277
+ * "IsActive":false,
278
+ * "TokenCustomerID":null,
279
+ * "Reference":"",
280
+ * "Title":"Mr.",
281
+ * "FirstName":"binh",
282
+ * "LastName":"nguyen",
283
+ * "CompanyName":"aaaaaa",
284
+ * "JobDescription":"job",
285
+ * "Street1":"Product Attributes",
286
+ * "Street2":"def",
287
+ * "City":"city here",
288
+ * "State":"123",
289
+ * "PostalCode":"1234",
290
+ * "Country":"as",
291
+ * "Email":"4444ddd@gmail.com",
292
+ * "Phone":"0987654321",
293
+ * "Mobile":"4444444444",
294
+ * "Comments":"",
295
+ * "Fax":"4535343",
296
+ * "Url":""
297
+ * },
298
+ * "Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},
299
+ * "FormActionURL":"https:\/\/secure-au.sandbox.ewaypayments.com\/AccessCode\/C3AB9RIc_reC_FRm8nXsy36QddJm_-YlaZCc2ZHuhbOeR5RzX682kfgl_12-vipFpJiuPPcOyh-ToeWP--Px06J04mW1zhqKpyqRTsvz0ub9-URgih4V_rHDYoNxQHXq9Ho2l",
300
+ * "CompleteCheckoutURL":null,
301
+ * "Errors":null}
302
+ */
303
+ if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type')
304
+ === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE
305
+ ) {
306
+ $data = $data->getData();
307
+ return $this->_redirectUrl($data['SharedPaymentUrl']);
308
+ }
309
+
310
+ $data = json_encode($data->getData());
311
+ $this->getResponse()->setBody($data);
312
+ }
313
+
314
+ /**
315
+ * Save or update token with Transparent or Shared page
316
+ */
317
+ public function saveTokenAction()
318
+ {
319
+
320
+ // Check session timeout
321
+ $session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
322
+ if (!$session->isLoggedIn()) {
323
+ $this->_redirect('*/*/');
324
+ return;
325
+ }
326
+
327
+ $req = $this->getRequest();
328
+ // Check load access code
329
+ $accessCode = $req->get('AccessCode');
330
+ $ccType = $req->get('ccType');
331
+ $expYear = $req->get('expYear');
332
+ $token_id = $req->get('token_id');
333
+
334
+ if (isset($accessCode)) {
335
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
336
+ // Retrieve data card by token key to save information
337
+ $result = $apiRequest->getInfoByAccessCode($accessCode);
338
+ $data = $result->getData();
339
+
340
+ $token_customer_id = $data['TokenCustomerID'];
341
+
342
+ /**
343
+ * TEST TOKEN ID NULL
344
+ */
345
+ //$token_customer_id = null;
346
+ /**
347
+ * END TEST
348
+ */
349
+
350
+ if (isset($token_customer_id) && !empty($token_customer_id)) {
351
+ $apiRequest = Mage::getModel('ewayrapid/request_token');
352
+ $street1 = $req->get('street1');
353
+ $street2 = $req->get('street2');
354
+ $cardData = array(
355
+ 'token' => $token_customer_id,
356
+ 'ccType' => $ccType,
357
+ 'expYear' => $expYear,
358
+ 'token_id' => $token_id,
359
+ 'startMonth' => $req->get('startMonth'),
360
+ 'startYear' => $req->get('startYear'),
361
+ 'issueNumber' => $req->get('issueNumber'),
362
+ 'street1' => base64_decode($street1),
363
+ 'street2' => base64_decode($street2)
364
+ );
365
+ // Retrieve data card by token key and save information
366
+ $apiRequest->saveInfoByTokenId($cardData);
367
+ if ($req->getParam('is_default')) {
368
+ //Mage::helper('ewayrapid/customer')->getLastTokenId()
369
+ Mage::helper('ewayrapid/customer')->setDefaultToken($token_id ? $token_id : Mage::helper('ewayrapid/customer')->getLastTokenId());
370
+ }
371
+ // Add flash message
372
+ $this->_getSession()->addSuccess($this->__('Your Credit Card has been saved successfully.'));
373
+ } else {
374
+ // If error, it will be showed message ERR-002
375
+ $this->_getSession()->addError($this->__('Failed to update Credit Card. Please try again later.'));
376
+ }
377
+ $this->_redirect('*/*/');
378
+ }
379
+
380
+ }
381
+
382
+ /*public function getTransactionAction() {
383
+ $url = 'https://api.sandbox.ewaypayments.com/Transaction/10889350';
384
+ //echo $url; die();
385
+ $ch = curl_init($url);
386
+ curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
387
+ curl_setopt($ch, CURLOPT_USERPWD, 'A1001CO7f5Se/wnuCkN96LX02vLgZlLfDVdbxDZzFgm+YsxckCiIG8d5mZzHXCProMwr7C:abc12345');
388
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
389
+
390
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
391
+ curl_setopt($ch, CURLOPT_TIMEOUT, 60);
392
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
393
+
394
+ $result = curl_exec($ch);
395
+ var_dump (json_decode($result)); die();
396
+ }
397
+
398
+ public function queryFraudAction() {
399
+ $cron = new Eway_Rapid31_Model_EwayCron();
400
+ $cron->querySuspectFraud();
401
+ }*/
402
+ }
app/code/community/Eway/Rapid31/controllers/SharedpageController.php ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ) {
29
+ Mage::getSingleton('core/session')->addError($this->__('Payment method ' . $method . ' not available'));
30
+ $this->_redirect('checkout/cart');
31
+ return;
32
+ }
33
+ if ($method === Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD
34
+ && !Mage::helper('ewayrapid')->isSavedMethodEnabled()
35
+ ) {
36
+ Mage::getSingleton('core/session')->addError($this->__('This feature has been disabled. Please contact site owner.'));
37
+ $this->_redirect('checkout/cart');
38
+ return;
39
+ }
40
+
41
+ try {
42
+ $this->_initCheckout();
43
+ $data = $this->_checkout->createAccessCode(Mage::getUrl('*/*/return'), Mage::getUrl('*/*/cancel'));
44
+ if ($data->isSuccess()) {
45
+ Mage::getSingleton('core/session')->setData('FormActionURL', $data->getFormActionURL());
46
+ if ($data->getSharedPaymentUrl()) {
47
+ $this->_redirectUrl($data->getSharedPaymentUrl());
48
+ return;
49
+ }
50
+ } else {
51
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later. (Error message: ' . $data->getMessage() . ')'));
52
+ $this->_redirect('checkout/cart');
53
+ return;
54
+ }
55
+
56
+ } catch (Exception $e) {
57
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__($e->getMessage()));
58
+ $this->_redirect('checkout/cart');
59
+ }
60
+ }
61
+
62
+ public function cancelAction()
63
+ {
64
+ $this->_redirect('checkout/cart');
65
+ }
66
+
67
+ /**
68
+ * process payment when eway callback
69
+ */
70
+ public function returnAction()
71
+ {
72
+ try {
73
+ $this->_initCheckout();
74
+
75
+ $newToken = $this->getRequest()->getParam('newToken');
76
+ $editToken = $this->getRequest()->getParam('editToken');
77
+ $accessCode = $this->getRequest()->getParam('AccessCode');
78
+
79
+ $response = $this->_checkout->getInfoByAccessCode($accessCode);
80
+ if ($newToken || $editToken) {
81
+ if ($response->getTokenCustomerID()) {
82
+ $response = $this->_checkout->saveTokenById($response, $editToken);
83
+ $response = $this->_processPayment($response);
84
+ } else {
85
+ 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.',
86
+ $response->getMessage()));
87
+ }
88
+ }
89
+
90
+ $orderId = null;
91
+ if ($response->isSuccess()) {
92
+ $orderId = $this->storeOrder($response);
93
+ } else {
94
+ 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.',
95
+ $response->getMessage()));
96
+ }
97
+ if ($orderId) {
98
+ $this->_redirect('checkout/onepage/success');
99
+ return;
100
+ }
101
+ } catch (Exception $e) {
102
+ Mage::getSingleton('checkout/session')->addError($e->getMessage());
103
+ Mage::logException($e);
104
+ $this->_redirect('checkout/cart');
105
+ return;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * save order
111
+ *
112
+ * @param Eway_Rapid31_Model_Response $response
113
+ * @param string $successType
114
+ * @return string
115
+ */
116
+ private function storeOrder($response, $successType = 'success')
117
+ {
118
+ try {
119
+ // Clear the basket and save the order (including some info about how the payment went)
120
+ $this->getOnepage()->getQuote()->collectTotals();
121
+ $payment = $this->getOnepage()->getQuote()->getPayment();
122
+ $payment->setAdditionalInformation('successType', $successType);
123
+ Mage::getSingleton('core/session')->setData('ewayTransactionID', $response->getTransactionID());
124
+ $orderId = $this->getOnepage()->saveOrder()->getLastOrderId();
125
+ $this->getOnepage()->getQuote()->save();
126
+ return $orderId;
127
+ } catch (Exception $e) {
128
+ Mage::throwException(Mage::helper('ewayrapid')->__($e->getMessage()));
129
+ }
130
+
131
+ }
132
+
133
+ /**
134
+ * Get one page checkout model
135
+ *
136
+ * @return Mage_Checkout_Model_Type_Onepage
137
+ */
138
+ public function getOnepage()
139
+ {
140
+ return Mage::getSingleton('checkout/type_onepage');
141
+ }
142
+
143
+ /**
144
+ * Return checkout session object
145
+ *
146
+ * @return Mage_Checkout_Model_Session
147
+ */
148
+ private function _getCheckoutSession()
149
+ {
150
+ return Mage::getSingleton('checkout/session');
151
+ }
152
+
153
+ /**
154
+ * Return checkout quote object
155
+ *
156
+ * @return Mage_Sales_Model_Quote
157
+ */
158
+ private function _getQuote()
159
+ {
160
+ if (!$this->_quote) {
161
+ $this->_quote = $this->_getCheckoutSession()->getQuote();
162
+ }
163
+ return $this->_quote;
164
+ }
165
+
166
+ private function _initCheckout()
167
+ {
168
+ $quote = $this->_getQuote();
169
+ if (!$quote->hasItems() || $quote->getHasError()) {
170
+ $this->getResponse()->setHeader('HTTP/1.1', '403 Forbidden');
171
+ Mage::throwException(Mage::helper('ewayrapid')->__('Unable to initialize Shared page Checkout.'));
172
+ }
173
+ $this->_checkout = Mage::getSingleton($this->_checkoutType, array(
174
+ 'quote' => $quote
175
+ ));
176
+ }
177
+
178
+ /**
179
+ * review order when checkout with paypal express
180
+ */
181
+ public function reviewAction()
182
+ {
183
+ try {
184
+ $this->_initCheckout();
185
+ $accessCode = $this->getRequest()->getParam('AccessCode');
186
+ $this->_checkout->updateCustomer($accessCode);
187
+ $this->loadLayout();
188
+ $blockReview = $this->getLayout()->getBlock('eway.block.review');
189
+ $blockReview->setQuote($this->_getQuote());
190
+ $blockReview->setAccessCode($accessCode);
191
+ $blockReview->setActionUrl(Mage::getUrl('*/*/saveInfoShipping'));
192
+ $this->renderLayout();
193
+ return;
194
+ } catch (Exception $e) {
195
+ Mage::getSingleton('checkout/session')->addError(
196
+ $this->__('Unable to initialize Express Checkout review. Error message: ' . $e->getMessage())
197
+ );
198
+ Mage::logException($e);
199
+ }
200
+ $this->_redirect('checkout/cart');
201
+ }
202
+
203
+ /**
204
+ * save shipping total amount to quote
205
+ * send new shipping total amount to eway
206
+ *
207
+ * @throws Exception
208
+ * @throws Mage_Core_Exception
209
+ */
210
+ public function saveInfoShippingAction()
211
+ {
212
+ $this->_initCheckout();
213
+ $formActionURL = Mage::getSingleton('core/session')->getData('FormActionURL');
214
+ if ($formActionURL) {
215
+ Mage::getSingleton('core/session')->unsetData('FormActionURL');
216
+ }
217
+ $shippingMethod = $this->getRequest()->getParam('shipping_method');
218
+ if ($shippingMethod) {
219
+ //Save to quote
220
+ $this->_quote->getShippingAddress()->setShippingMethod($shippingMethod)->save();
221
+
222
+ //Get price
223
+ $quote = $this->_getQuote();
224
+ $cRate = $this->_checkout->getShippingByCode($shippingMethod);
225
+ if ($cRate) {
226
+ echo json_encode(array(
227
+ 'form_action' => $formActionURL,
228
+ 'input_post' => '<input type="hidden" name="EWAY_NEWSHIPPINGTOTAL" value="' . round($cRate->getPrice() * 100) . '" />'
229
+ ));
230
+ } else {
231
+ Mage::throwException($this->__('Method not found.'));
232
+ }
233
+ } else {
234
+ Mage::throwException($this->__('Method not support.'));
235
+ }
236
+ die;
237
+ }
238
+
239
+ /**
240
+ * process Payment: authorize only or authorize & capture
241
+ *
242
+ * @param Eway_Rapid31_Model_Response $response
243
+ * @return Eway_Rapid31_Model_Response
244
+ * @throws Mage_Core_Exception
245
+ */
246
+ protected function _processPayment(Eway_Rapid31_Model_Response $response)
247
+ {
248
+ $this->_initCheckout();
249
+
250
+ $cardData = $response->getCustomer();
251
+
252
+ if ($cardData['CardNumber'] && $cardData['CardName']) {
253
+ $response = $this->_checkout->doAuthorisation($response);
254
+ if ($response->isSuccess()
255
+ && Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE
256
+ ) {
257
+ $response = $this->_checkout->doCapturePayment($response);
258
+ }
259
+ } else {
260
+ if (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE) {
261
+ $response = $this->_checkout->doAuthorisation($response);
262
+ } elseif (Mage::helper('ewayrapid')->getPaymentAction() === Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE) {
263
+ $response = $this->_checkout->doTransaction($response);
264
+ }
265
+ }
266
+ if (!$response->isSuccess()) {
267
+ 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.',
268
+ $response->getMessage()));
269
+ }
270
+ return $response;
271
+ }
272
+ }
app/code/community/Eway/Rapid31/controllers/TestController.php ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: Administrator PC
5
+ * Date: 8/7/14
6
+ * Time: 10:05 AM
7
+ */
8
+ class Eway_Rapid31_TestController extends Mage_Core_Controller_Front_Action
9
+ {
10
+ public function querySuspectFraudAction()
11
+ {
12
+
13
+ $base_path = Mage::getBaseDir('base');
14
+ $file = $base_path . DS .'var' . DS . 'report' . DS .'people.txt';
15
+ // The new person to add to the file
16
+ $person = "John Smith " . rand(1, 9999) . "\n";
17
+ // Write the contents to the file,
18
+ // using the FILE_APPEND flag to append the content to the end of the file
19
+ // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
20
+ file_put_contents($file, $person, FILE_APPEND | LOCK_EX);
21
+
22
+ // Load orders with fraud in 7 days before from now
23
+ $orders = Mage::getModel('sales/order')->getCollection()
24
+ ->addFieldToFilter('status', array('eq' => 'fraud')) // State fraud
25
+ ->addFieldToFilter('eway_transaction_id', array('notnull' => ''))
26
+ ->addFieldToFilter('created_at', array('to' => date('Y-m-d 23:59:59'), 'from' => date('Y-m-d 00:00:01', strtotime('-7 days'))));
27
+
28
+ foreach ($orders as $o) {
29
+ $transactionId = $o->getEwayTransactionId();
30
+ if ($transactionId) {
31
+ $result = $this->__getTransaction($transactionId);
32
+ // Check return data
33
+ $result_decode = json_decode($result);
34
+
35
+ $trans = $result_decode->Transactions;
36
+ $tranId = $trans[0]->TransactionID;
37
+
38
+ if ($trans[0]->ResponseMessage == 'A2000') { // Success - Fraud order has been approved
39
+ // Create new transaction
40
+ $this->__createNewTransaction($o, $tranId);
41
+ // Update order status
42
+ $this->__updateStatusOrder($o);
43
+ // Un-mark fraud customer
44
+ $this->__unMarkFraudUser($o);
45
+ }
46
+ }
47
+ }
48
+ // Response data to client
49
+ $this->getResponse()->setHeader('Content-type', 'application/json');
50
+ $this->getResponse()->setBody(count($orders));
51
+ }
52
+
53
+ private function __getTransaction($transId)
54
+ {
55
+ $ewayConfig = new Eway_Rapid31_Model_Config();
56
+ $url = 'https://api.sandbox.ewaypayments.com/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
+ private 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
+ $trans->setTxnId($transId);
98
+ $trans->setParentTxnId($t->getTxnId());
99
+ $trans->setTxnType($t->getTxnType());
100
+ $trans->setIsClosed($t->getIsClosed());
101
+ $trans->setCreatedAt(date('Y-m-d H:i:s'));
102
+ $trans->save();
103
+
104
+ }
105
+
106
+ private function __updateStatusOrder(Mage_Sales_Model_Order $order)
107
+ {
108
+ $order->setState('Processing');
109
+ $order->setStatus(Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED);
110
+ $order->save();
111
+ }
112
+
113
+ private function __unMarkFraudUser(Mage_Sales_Model_Order $order)
114
+ {
115
+ $uid = $order->getCustomerId();
116
+ $customer = Mage::getModel('customer/customer')->load($uid);
117
+ $customer->setMarkFraud(0);
118
+ $customer->save();
119
+ }
120
+
121
+ public function recurringAction()
122
+ {
123
+ try {
124
+ $modelObserver = Mage::getModel('ewayrapid/Observer');
125
+ $modelObserver->cronRecurringOrder();
126
+ echo "done";
127
+ } catch (Exception $e) {
128
+ throw $e;
129
+ }
130
+ }
131
+ }
app/code/community/Eway/Rapid31/controllers/TransparentController.php ADDED
@@ -0,0 +1,407 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
21
+ function _getSession()
22
+ {
23
+ $this->methodPayment = Mage::getSingleton('core/session')->getMethod();
24
+ $this->transMethod = Mage::getSingleton('core/session')->getTransparentNotsaved();
25
+ if (!$this->transMethod) {
26
+ $this->transMethod = Mage::getSingleton('core/session')->getTransparentSaved();
27
+ }
28
+
29
+ if ($this->methodPayment == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD) {
30
+ $this->savedToken = Mage::getSingleton('core/session')->getSavedToken();
31
+ }
32
+ $this->cardInfo = Mage::getSingleton('core/session')->getCardInfo();
33
+ }
34
+
35
+ /**
36
+ * @return false|Eway_Rapid31_Model_Request_Transparent
37
+ */
38
+ protected function transparentModel()
39
+ {
40
+ if (!self::$_transparentmodel) {
41
+ self::$_transparentmodel = Mage::getModel('ewayrapid/request_transparent');
42
+ }
43
+ return self::$_transparentmodel;
44
+ }
45
+
46
+ /**
47
+ * @return Eway_Rapid31_Helper_Data
48
+ */
49
+ protected function helperData()
50
+ {
51
+ return Mage::helper('ewayrapid/data');
52
+ }
53
+
54
+ public function indexAction()
55
+ {
56
+ try {
57
+
58
+ } catch (Exception $e) {
59
+ Mage::throwException($e->getMessage());
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Action build link redirect checkout after Click Place Order
65
+ */
66
+ public function buildAction()
67
+ {
68
+ try {
69
+ $this->_getSession();
70
+ $quote = $this->_getQuote();
71
+ /** @var Eway_Rapid31_Model_Request_Sharedpage $sharedpageModel */
72
+
73
+ $action = 'AccessCodes';
74
+ if ($this->methodPayment == Eway_Rapid31_Model_Config::PAYMENT_SAVED_METHOD) {
75
+ $methodData = Eway_Rapid31_Model_Config::METHOD_TOKEN_PAYMENT;
76
+
77
+ //Authorize Only
78
+ if ($this->helperData()->getPaymentAction() != Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE
79
+ || $this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
80
+ if ($this->savedToken == Eway_Rapid31_Model_Config::TOKEN_NEW)
81
+ $methodData = Eway_Rapid31_Model_Config::METHOD_CREATE_TOKEN;
82
+ else
83
+ $methodData = Eway_Rapid31_Model_Config::METHOD_UPDATE_TOKEN;
84
+ }
85
+ } else {
86
+ $methodData = Eway_Rapid31_Model_Config::METHOD_PROCESS_PAYMENT;
87
+ if ($this->helperData()->getPaymentAction() != Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE
88
+ && $this->transMethod != Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD
89
+ && $this->transMethod != Eway_Rapid31_Model_Config::MASTERPASS_METHOD
90
+ )
91
+ {
92
+ $methodData = Eway_Rapid31_Model_Config::METHOD_AUTHORISE;
93
+ }
94
+ }
95
+
96
+ $data = $this->transparentModel()->createAccessCode($quote, $methodData, $action);
97
+ if ($data['AccessCode']) {
98
+ //save FormActionURL, AccessCode
99
+ Mage::getSingleton('core/session')->setFormActionUrl($data['FormActionURL']);
100
+ if (isset($data['CompleteCheckoutURL']))
101
+ Mage::getSingleton('core/session')->setCompleteCheckoutURL($data['CompleteCheckoutURL']);
102
+ if ($this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD || $this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD || $this->transMethod == Eway_Rapid31_Model_Config::MASTERPASS_METHOD ) {
103
+ $urlRedirect = Mage::getUrl('ewayrapid/transparent/redirect') . '?AccessCode=' . $data['AccessCode'];
104
+ } else {
105
+ $urlRedirect = Mage::getUrl('ewayrapid/transparent/paynow') . '?AccessCode=' . $data['AccessCode'];
106
+ }
107
+ echo($urlRedirect);
108
+ } else {
109
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later.'));
110
+ $this->transparentModel()->unsetSessionData();
111
+ echo Mage::getUrl('checkout/cart/');
112
+ return;
113
+ }
114
+ } catch (Exception $e) {
115
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('An error occurred while connecting to payment gateway. Please try again later.'));
116
+ $this->transparentModel()->unsetSessionData();
117
+ echo Mage::getUrl('checkout/cart/');
118
+ return;
119
+ }
120
+ die;
121
+ }
122
+
123
+ /**
124
+ * Action display form customer's detail card: Add new info
125
+ */
126
+ public function paynowAction()
127
+ {
128
+ $this->loadLayout();
129
+
130
+ $accessCode = $this->getRequest()->getParam('AccessCode');
131
+ $this->getLayout()->getBlock('transparent.block.paynow')->setAccessCode($accessCode);
132
+
133
+ $this->renderLayout();
134
+ }
135
+
136
+ /**
137
+ * Action display form customer's detail card: Add new info
138
+ */
139
+ public function redirectAction()
140
+ {
141
+ $this->loadLayout();
142
+
143
+ $accessCode = $this->getRequest()->getParam('AccessCode');
144
+ $this->getLayout()->getBlock('transparent.block.checkout')->setAccessCode($accessCode);
145
+
146
+ $this->renderLayout();
147
+ }
148
+
149
+ /**
150
+ * Action process at returnUrl
151
+ */
152
+ public function callBackAction()
153
+ {
154
+ try {
155
+ $this->_getSession();
156
+ $quote = $this->_getQuote();
157
+
158
+ $accessCode = $this->getRequest()->getParam('AccessCode');
159
+ $order_id = $transactionID = $tokenCustomerID = 0;
160
+
161
+ if ($this->methodPayment == 'ewayrapid_notsaved') {
162
+ $dataResult = $this->resultProcess($accessCode);
163
+ $transactionID = $dataResult['TransactionID'];
164
+ } else {
165
+ $transaction = $this->transparentModel()->getTransaction($accessCode);
166
+ if($transaction) {
167
+ $tokenCustomerID = $transaction && isset($transaction[0]['TokenCustomerID']) ? $transaction[0]['TokenCustomerID'] : null;
168
+ unset($transaction);
169
+ }
170
+ $quote->setTokenCustomerID($tokenCustomerID);
171
+
172
+ if($this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
173
+ /*
174
+ $dataResult = $this->resultProcess($accessCode);
175
+ $transactionID = $dataResult['TransactionID'];
176
+ */
177
+ $quote = $this->transparentModel()->doTransaction($quote, round($this->_getQuote()->getBaseGrandTotal() * 100));
178
+ $transactionID = $quote->getTransactionId();
179
+ } else {
180
+ if ($this->helperData()->getPaymentAction() === Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE) {
181
+ $dataResult = $this->resultProcess($accessCode);
182
+ $transactionID = $dataResult['TransactionID'];
183
+ } else {
184
+ $quote = $this->transparentModel()->doAuthorisation($quote, round($this->_getQuote()->getBaseGrandTotal() * 100));
185
+ $transactionID = $quote->getTransactionId();
186
+ //$quote = $this->transparentModel()->doCapturePayment($quote, round($this->_getQuote()->getBaseGrandTotal() * 100));
187
+ }
188
+ }
189
+ $quote->setTransactionId($transactionID);
190
+
191
+ //Save Token
192
+ $this->saveToken($quote, $tokenCustomerID);
193
+ }
194
+
195
+ if ($transactionID) {
196
+ Mage::getSingleton('core/session')->setTransactionId($transactionID);
197
+ //Save order
198
+ $order_id = $this->storeOrder('success', $transactionID);
199
+ }
200
+
201
+ //unset all session's transaparent
202
+ $this->transparentModel()->unsetSessionData();
203
+
204
+ // Redirect to success page
205
+ if ($order_id) {
206
+ $this->_redirect('checkout/onepage/success');
207
+ return;
208
+ } else {
209
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Create order error. Please again.'));
210
+ $this->_redirect('checkout/cart/');
211
+ return;
212
+ }
213
+ } catch (Exception $e) {
214
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Call back error: ' . $e->getMessage()));
215
+ $this->transparentModel()->unsetSessionData();
216
+ $this->_redirect('checkout/cart/');
217
+ return;
218
+ }
219
+ }
220
+
221
+ /**
222
+ * @param $accessCode
223
+ */
224
+ protected function resultProcess($accessCode) {
225
+ return $this->transparentModel()->getInfoByAccessCode($accessCode);
226
+ }
227
+
228
+ /**
229
+ * @param $quote
230
+ * @param $tokenCustomerID
231
+ */
232
+ protected function saveToken($quote, $tokenCustomerID) {
233
+ 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) {
234
+ $this->cardInfo['SavedType'] = Eway_Rapid31_Model_Config::CREDITCARD_METHOD;
235
+
236
+ if ($this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) {
237
+ $this->cardInfo['SavedType'] = Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD;
238
+ } elseif ($this->transMethod == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) {
239
+ $this->cardInfo['SavedType'] = Eway_Rapid31_Model_Config::MASTERPASS_METHOD;
240
+ }
241
+ $this->transparentModel()->addToken($quote, $this->cardInfo, $tokenCustomerID);
242
+ } else {
243
+ $this->transparentModel()->updateToken($tokenCustomerID, $this->cardInfo);
244
+ }
245
+ return true;
246
+ }
247
+
248
+ protected function authorizeOnly() {
249
+
250
+ }
251
+ /**
252
+ * Action Cancel
253
+ */
254
+ public function cancelAction()
255
+ {
256
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Request eway api error. Please try again.'));
257
+ $this->transparentModel()->unsetSessionData();
258
+ $this->_redirect('checkout/cart');
259
+ return;
260
+ }
261
+
262
+ /**
263
+ * @param string $successType
264
+ * @param $transactionID
265
+ * @return string
266
+ */
267
+ private function storeOrder($successType = 'success', $transactionID)
268
+ {
269
+ try {
270
+ //Clear the basket and save the order (including some info about how the payment went)
271
+ $this->getOnepage()->getQuote()->collectTotals();
272
+ $this->getOnepage()->getQuote()->getPayment()->setTransactionId($transactionID);
273
+ $this->getOnepage()->getQuote()->getPayment()->setAdditionalInformation('transactionId', $transactionID);
274
+ $this->getOnepage()->getQuote()->getPayment()->setAdditionalInformation('successType', $successType);
275
+ $orderId = $this->getOnepage()->saveOrder()->getLastOrderId();
276
+ $this->getOnepage()->getQuote()->save();
277
+
278
+ return $orderId;
279
+ } catch (Exception $e) {
280
+ Mage::throwException($e->getMessage());
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Review shipping
286
+ */
287
+ public function reviewAction()
288
+ {
289
+ try {
290
+ $accessCode = $this->getRequest()->getParam('AccessCode');
291
+ $quote = $this->transparentModel()->updateCustomer($accessCode, $this->_getQuote());
292
+
293
+ if (!$quote) {
294
+ $quote = $this->_getQuote();
295
+ }
296
+
297
+ $this->loadLayout();
298
+ $blockReview = $this->getLayout()->getBlock('eway.block.review');
299
+ $blockReview->setQuote($quote);
300
+ $blockReview->setAccessCode($accessCode);
301
+ $blockReview->setActionUrl(Mage::getUrl('*/*/saveInfoShipping'));
302
+ $this->renderLayout();
303
+ } catch (Exception $e) {
304
+ Mage::getSingleton('core/session')->addError(Mage::helper('ewayrapid')->__('Update customer info error: ' . $e->getMessage()));
305
+ $this->transparentModel()->unsetSessionData();
306
+ $this->_redirect('checkout/cart/');
307
+ return;
308
+ }
309
+ }
310
+
311
+ /**
312
+ *
313
+ */
314
+ public function saveCardInfoAction()
315
+ {
316
+ try {
317
+ $data = $this->getRequest()->getPost();
318
+ if (isset($data['EWAY_CARDNUMBER'])) {
319
+ $config = Mage::getSingleton('ewayrapid/config');
320
+ $data['EWAY_CARDNUMBER'] = $this->helperData()->encryptSha256($data['EWAY_CARDNUMBER'], $config->getBasicAuthenticationHeader());
321
+ }
322
+ Mage::getSingleton('core/session')->setCardInfo($data);
323
+ echo 1;
324
+ } catch (Exception $e) {
325
+ $this->transparentModel()->unsetSessionData();
326
+ Mage::throwException($e->getMessage());
327
+ }
328
+ die;
329
+ }
330
+
331
+ /**
332
+ *
333
+ */
334
+ public function saveInfoShippingAction()
335
+ {
336
+ $shippingMethod = $this->getRequest()->getParam('shipping_method');
337
+ if ($shippingMethod) {
338
+ //Get price
339
+ $quote = $this->_getQuote();
340
+ $cRate = $this->transparentModel()->getShippingByCode($quote, $shippingMethod);
341
+
342
+ //Save to quote
343
+ $quote->getShippingAddress()->setShippingMethod($shippingMethod)->save();
344
+
345
+ if ($cRate) {
346
+ echo json_encode(array(
347
+ 'form_action' => Mage::getSingleton('core/session')->getFormActionUrl(),
348
+ 'input_post' => '<input type="hidden" name="EWAY_NEWSHIPPINGTOTAL" value="' . round($cRate->getPrice() * 100) . '" />',
349
+ ));
350
+ } else {
351
+ $this->transparentModel()->unsetSessionData();
352
+ Mage::throwException($this->__('Method not found.'));
353
+ }
354
+ } else {
355
+ $this->transparentModel()->unsetSessionData();
356
+ Mage::throwException($this->__('Method not support.'));
357
+ }
358
+ die;
359
+ }
360
+
361
+ /**
362
+ * @param $orderId
363
+ * @return null
364
+ */
365
+ private function _loadOrder($orderId)
366
+ {
367
+ try {
368
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
369
+ if ($order->getIncrementId() == $orderId) {
370
+ return $order;
371
+ }
372
+ return null;
373
+ } catch (Exception $e) {
374
+ Mage::throwException($e->getMessage());
375
+ }
376
+ }
377
+
378
+ /**
379
+ * Return checkout quote object
380
+ *
381
+ * @return Mage_Sale_Model_Quote
382
+ */
383
+ private function _getQuote()
384
+ {
385
+ /** @var Mage_Sales_Model_Quote $this->_quote */
386
+ $this->_quote = $this->_getCheckoutSession()->getQuote();
387
+ return $this->_quote;
388
+ }
389
+
390
+ /**
391
+ * @return Mage_Core_Model_Abstract
392
+ */
393
+ private function _getCheckoutSession()
394
+ {
395
+ return Mage::getSingleton('checkout/session');
396
+ }
397
+
398
+ /**
399
+ * Get one page checkout model
400
+ *
401
+ * @return Mage_Checkout_Model_Type_Onepage
402
+ */
403
+ public function getOnepage()
404
+ {
405
+ return Mage::getSingleton('checkout/type_onepage');
406
+ }
407
+ }
app/code/community/Eway/Rapid31/etc/config.xml ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Eway_Rapid31>
5
+ <version>1.0.3</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
+ </rewrite>
27
+ </adminhtml>
28
+ </blocks>
29
+
30
+ <helpers>
31
+ <ewayrapid>
32
+ <class>Eway_Rapid31_Helper</class>
33
+ </ewayrapid>
34
+ </helpers>
35
+ <resources>
36
+ <ewayrapid_setup>
37
+ <setup>
38
+ <module>Eway_Rapid31</module>
39
+ </setup>
40
+ </ewayrapid_setup>
41
+ </resources>
42
+ <payment>
43
+ <cc>
44
+ <types>
45
+ <DC>
46
+ <code>DC</code>
47
+ <name>Diners Club International</name>
48
+ <order>100</order>
49
+ </DC>
50
+ <VE>
51
+ <code>VE</code>
52
+ <name>Visa Electron</name>
53
+ <order>11</order>
54
+ </VE>
55
+ <ME>
56
+ <code>ME</code>
57
+ <name>Maestro</name>
58
+ <order>21</order>
59
+ </ME>
60
+ </types>
61
+ </cc>
62
+ </payment>
63
+ </global>
64
+ <frontend>
65
+ <translate>
66
+ <modules>
67
+ <Eway_Rapid31>
68
+ <files>
69
+ <default>Eway_Rapid31.csv</default>
70
+ </files>
71
+ </Eway_Rapid31>
72
+ </modules>
73
+ </translate>
74
+ <layout>
75
+ <updates>
76
+ <ewayrapid>
77
+ <file>ewayrapid/layout.xml</file>
78
+ </ewayrapid>
79
+ </updates>
80
+ </layout>
81
+ <routers>
82
+ <ewayrapid>
83
+ <use>standard</use>
84
+ <args>
85
+ <module>Eway_Rapid31</module>
86
+ <frontName>ewayrapid</frontName>
87
+ </args>
88
+ </ewayrapid>
89
+ </routers>
90
+
91
+ <events>
92
+
93
+ <controller_action_predispatch_ewayrapid_mycards_index>
94
+ <observers>
95
+ <eway_rapid31_my_cards>
96
+ <type>singleton</type>
97
+ <class>ewayrapid/observer</class>
98
+ <method>myCards</method>
99
+ </eway_rapid31_my_cards>
100
+ </observers>
101
+ </controller_action_predispatch_ewayrapid_mycards_index>
102
+
103
+ <!-- Event default -->
104
+ <controller_action_predispatch_checkout_onepage_index>
105
+ <observers>
106
+ <eway_rapid31_check_customer_mark>
107
+ <type>singleton</type>
108
+ <class>ewayrapid/observer</class>
109
+ <method>checkCustomerMark</method>
110
+ </eway_rapid31_check_customer_mark>
111
+ </observers>
112
+ </controller_action_predispatch_checkout_onepage_index>
113
+
114
+ <!--<sales_order_save_before>
115
+ <observers>
116
+ <sales_order_save_before>
117
+ <class>ewayrapid/observer</class>
118
+ <method>hookToSaveOrderBefore</method>
119
+ </sales_order_save_before>
120
+ </observers>
121
+ </sales_order_save_before>
122
+
123
+ <sales_order_save_after>
124
+ <observers>
125
+ <sales_order_save_after>
126
+ <class>ewayrapid/observer</class>
127
+ <method>hookToSaveOrderAfter</method>
128
+ </sales_order_save_after>
129
+ </observers>
130
+ </sales_order_save_after>-->
131
+
132
+ <sales_order_place_before>
133
+ <observers>
134
+ <sales_order_place_before>
135
+ <class>ewayrapid/observer</class>
136
+ <method>sales_order_place_before</method>
137
+ </sales_order_place_before>
138
+ </observers>
139
+ </sales_order_place_before>
140
+
141
+ <sales_order_place_after>
142
+ <observers>
143
+ <sales_order_place_after>
144
+ <class>ewayrapid/observer</class>
145
+ <method>sales_order_place_after</method>
146
+ </sales_order_place_after>
147
+ </observers>
148
+ </sales_order_place_after>
149
+
150
+ <checkout_type_onepage_save_order_after>
151
+ <observers>
152
+ <checkout_type_onepage_save_order_after>
153
+ <class>ewayrapid/observer</class>
154
+ <method>checkout_type_onepage_save_order_after</method>
155
+ </checkout_type_onepage_save_order_after>
156
+ </observers>
157
+ </checkout_type_onepage_save_order_after>
158
+
159
+ <!--<sales_order_save_commit_before>
160
+ <observers>
161
+ <sales_order_save_commit_before>
162
+ <class>ewayrapid/observer</class>
163
+ <method>sales_order_save_commit_before</method>
164
+ </sales_order_save_commit_before>
165
+ </observers>
166
+ </sales_order_save_commit_before>
167
+
168
+ <sales_order_save_commit_after>
169
+ <observers>
170
+ <sales_order_save_commit_after>
171
+ <class>ewayrapid/observer</class>
172
+ <method>sales_order_save_commit_after</method>
173
+ </sales_order_save_commit_after>
174
+ </observers>
175
+ </sales_order_save_commit_after>-->
176
+
177
+ <checkout_submit_all_after>
178
+ <observers>
179
+ <checkout_submit_all_after>
180
+ <class>ewayrapid/observer</class>
181
+ <method>checkout_submit_all_after</method>
182
+ </checkout_submit_all_after>
183
+ </observers>
184
+ <observers>
185
+ <eway_recurring_profile>
186
+ <class>ewayrapid/observer</class>
187
+ <method>createRecurringOrder</method>
188
+ </eway_recurring_profile>
189
+ </observers>
190
+ </checkout_submit_all_after>
191
+ </events>
192
+
193
+ </frontend>
194
+ <admin>
195
+ <routers>
196
+ <ewayrapid_admin>
197
+ <use>admin</use>
198
+ <args>
199
+ <module>Eway_Rapid31_Adminhtml</module>
200
+ <frontName>ewayadmin</frontName>
201
+ </args>
202
+ </ewayrapid_admin>
203
+ </routers>
204
+ </admin>
205
+ <adminhtml>
206
+ <translate>
207
+ <modules>
208
+ <Eway_Rapid31>
209
+ <files>
210
+ <default>Eway_Rapid31.csv</default>
211
+ </files>
212
+ </Eway_Rapid31>
213
+ </modules>
214
+ </translate>
215
+ <layout>
216
+ <updates>
217
+ <ewayrapid>
218
+ <file>ewayrapid/layout.xml</file>
219
+ </ewayrapid>
220
+ </updates>
221
+ </layout>
222
+ <!--<menu>
223
+ <system>
224
+ <children>
225
+ <eway_admin_index>
226
+ <title>Eway Mass</title>
227
+ <action>ewayadmin/index/index</action>
228
+ </eway_admin_index>
229
+ <eway_admin_mass_authorised>
230
+ <title>Eway Mass</title>
231
+ <action>ewayadmin/index/massEwayAuthorised</action>
232
+ </eway_admin_mass_authorised>
233
+ <eway_admin_mass_pending>
234
+ <title>Eway Mass</title>
235
+ <action>ewayadmin/index/massPending</action>
236
+ </eway_admin_mass_pending>
237
+ </children>
238
+ </system>
239
+ </menu>-->
240
+ </adminhtml>
241
+ <default>
242
+ <payment>
243
+ <ewayrapid_general>
244
+ <active>0</active>
245
+ <mode>sandbox</mode>
246
+ <sandbox_endpoint>https://api.sandbox.ewaypayments.com/</sandbox_endpoint>
247
+ <live_endpoint>https://api.ewaypayments.com/</live_endpoint>
248
+ <payment_action>authorize_capture</payment_action>
249
+ <connection_type>direct</connection_type>
250
+ <can_edit_token>1</can_edit_token>
251
+ <can_cancel_subscriptions>0</can_cancel_subscriptions>
252
+ <block_fraud_customers>1</block_fraud_customers>
253
+ <useccv>1</useccv>
254
+ <cctypes>VI,MC</cctypes>
255
+ <order_status>eway_captured</order_status>
256
+ <allowspecific>0</allowspecific>
257
+ <ssl_verification>1</ssl_verification>
258
+ <transfer_cart_items>1</transfer_cart_items>
259
+ <debug>0</debug>
260
+ <billing_agreement_title>eWAY Billing Agreement</billing_agreement_title>
261
+ </ewayrapid_general>
262
+ <ewayrapid_notsaved>
263
+ <model>ewayrapid/method_notsaved</model>
264
+ <active>0</active>
265
+ <title>Credit Card - eWAY (not saved)</title>
266
+ </ewayrapid_notsaved>
267
+ <ewayrapid_saved>
268
+ <model>ewayrapid/method_saved</model>
269
+ <active>0</active>
270
+ <title>Credit Card - eWAY (saved)</title>
271
+ </ewayrapid_saved>
272
+
273
+ </payment>
274
+ </default>
275
+ <phpunit>
276
+ <suite>
277
+ <modules>
278
+ <Eway_Rapid31/>
279
+ </modules>
280
+ </suite>
281
+ </phpunit>
282
+ <crontab>
283
+ <jobs>
284
+ <eway_recurring_order>
285
+ <schedule>
286
+ <cron_expr>0 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * *</cron_expr>
287
+ </schedule>
288
+ <run>
289
+ <model>ewayrapid/observer::cronRecurringOrder</model>
290
+ </run>
291
+ </eway_recurring_order>
292
+ <eway_rapid31>
293
+ <schedule>
294
+ <cron_expr>0 0,3,6,9,12,15,18,21 * * *</cron_expr>
295
+ </schedule>
296
+ <run>
297
+ <model>ewayrapid/ewayCron::querySuspectFraud</model>
298
+ </run>
299
+ </eway_rapid31>
300
+ </jobs>
301
+ </crontab>
302
+ </config>
app/code/community/Eway/Rapid31/etc/system.xml ADDED
@@ -0,0 +1,429 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <sections>
3
+ <payment>
4
+ <groups>
5
+ <ewayrapid_general translate="label" module="ewayrapid">
6
+ <label>eWAY Rapid 3.1 (General settings)</label>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>200</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <fields>
13
+ <active translate="label">
14
+ <label>Enable this solution</label>
15
+ <frontend_type>select</frontend_type>
16
+ <source_model>adminhtml/system_config_source_yesno</source_model>
17
+ <backend_model>ewayrapid/system_config_backend_validation</backend_model>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <sort_order>10</sort_order>
21
+ </active>
22
+
23
+ <heading_mode translate="label">
24
+ <label>eWAY Rapid 3.1 Mode</label>
25
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ <sort_order>20</sort_order>
30
+ </heading_mode>
31
+ <mode translate="label">
32
+ <label>Mode</label>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>ewayrapid/system_config_source_mode</source_model>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ <sort_order>30</sort_order>
39
+ </mode>
40
+ <live_api_key translate="label">
41
+ <label>Live API Key</label>
42
+ <frontend_type>obscure</frontend_type>
43
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>1</show_in_store>
47
+ <sort_order>40</sort_order>
48
+ </live_api_key>
49
+ <live_api_password translate="label">
50
+ <label>Live API Password</label>
51
+ <frontend_type>obscure</frontend_type>
52
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ <sort_order>50</sort_order>
57
+ <comment>
58
+ <![CDATA[
59
+ <a href="https://eway.zendesk.com/entries/22370567-How-to-generate-your-Live-Rapid-3-0-API-Key-and-Password" target="_blank">How to generate Live Rapid 3.1 API Key and Password</a>
60
+ ]]>
61
+ </comment>
62
+ </live_api_password>
63
+ <live_encryption_key translate="label">
64
+ <label>Live Client-side Encryption Key</label>
65
+ <frontend_type>textarea</frontend_type>
66
+ <show_in_default>1</show_in_default>
67
+ <show_in_website>1</show_in_website>
68
+ <show_in_store>1</show_in_store>
69
+ <sort_order>55</sort_order>
70
+ </live_encryption_key>
71
+ <sandbox_api_key translate="label">
72
+ <label>Sandbox API Key</label>
73
+ <frontend_type>obscure</frontend_type>
74
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_website>1</show_in_website>
77
+ <show_in_store>1</show_in_store>
78
+ <sort_order>60</sort_order>
79
+ </sandbox_api_key>
80
+ <sandbox_api_password translate="label">
81
+ <label>Sandbox API Password</label>
82
+ <frontend_type>obscure</frontend_type>
83
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
84
+ <show_in_default>1</show_in_default>
85
+ <show_in_website>1</show_in_website>
86
+ <show_in_store>1</show_in_store>
87
+ <sort_order>70</sort_order>
88
+ <comment>
89
+ <![CDATA[
90
+ <a href="https://eway.zendesk.com/entries/22370486-How-to-generate-your-Sandbox-Rapid-3-0-API-Key-and-Password" target="_blank">How to generate Sandbox Rapid 3.1 API Key and Password</a>
91
+ ]]>
92
+ </comment>
93
+ </sandbox_api_password>
94
+ <sandbox_encryption_key translate="label">
95
+ <label>Sandbox Client-side Encryption Key</label>
96
+ <frontend_type>textarea</frontend_type>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>1</show_in_store>
100
+ <sort_order>75</sort_order>
101
+ </sandbox_encryption_key>
102
+
103
+ <heading_basic_settings translate="label">
104
+ <label>Basic Settings</label>
105
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
106
+ <show_in_default>1</show_in_default>
107
+ <show_in_website>1</show_in_website>
108
+ <sort_order>80</sort_order>
109
+ </heading_basic_settings>
110
+ <payment_action translate="label">
111
+ <label>Payment Action</label>
112
+ <frontend_type>select</frontend_type>
113
+ <source_model>ewayrapid/system_config_source_paymentAction</source_model>
114
+ <show_in_default>1</show_in_default>
115
+ <show_in_website>1</show_in_website>
116
+ <sort_order>90</sort_order>
117
+ </payment_action>
118
+ <connection_type translate="label">
119
+ <label>Connection Type</label>
120
+ <frontend_type>select</frontend_type>
121
+ <source_model>ewayrapid/system_config_source_connectionType</source_model>
122
+ <show_in_default>1</show_in_default>
123
+ <show_in_website>1</show_in_website>
124
+ <sort_order>100</sort_order>
125
+ </connection_type>
126
+
127
+ <enable_masterpass translate="label">
128
+ <label>Enable MasterPass</label>
129
+ <frontend_type>select</frontend_type>
130
+ <source_model>adminhtml/system_config_source_yesno</source_model>
131
+ <show_in_default>1</show_in_default>
132
+ <show_in_website>1</show_in_website>
133
+ <sort_order>102</sort_order>
134
+ <depends>
135
+ <connection_type>transparent</connection_type>
136
+ </depends>
137
+ </enable_masterpass>
138
+ <enable_paypal_standard translate="label">
139
+ <label>Enable PayPal</label>
140
+ <frontend_type>select</frontend_type>
141
+ <source_model>adminhtml/system_config_source_yesno</source_model>
142
+ <show_in_default>1</show_in_default>
143
+ <show_in_website>1</show_in_website>
144
+ <sort_order>103</sort_order>
145
+ <depends>
146
+ <connection_type>transparent</connection_type>
147
+ </depends>
148
+ </enable_paypal_standard>
149
+ <!--<enable_paypal_checkout translate="label">-->
150
+ <!--<label>Enable PayPal Express Checkout</label>-->
151
+ <!--<frontend_type>select</frontend_type>-->
152
+ <!--<source_model>adminhtml/system_config_source_yesno</source_model>-->
153
+ <!--<show_in_default>1</show_in_default>-->
154
+ <!--<show_in_website>1</show_in_website>-->
155
+ <!--<sort_order>104</sort_order>-->
156
+ <!--<depends>-->
157
+ <!--<connection_type>transparent</connection_type>-->
158
+ <!--</depends>-->
159
+ <!--<comment>-->
160
+ <!--<![CDATA[-->
161
+ <!--<span style="color:red;font-weight:bold">Caution</span>: If you enable PayPal or MasterPass, you must also setup the connection in MYeWAY-->
162
+ <!--]]>-->
163
+ <!--</comment>-->
164
+ <!--</enable_paypal_checkout>-->
165
+ <store_in_paypal translate="label">
166
+ <label>Store Transaction in PayPal</label>
167
+ <frontend_type>select</frontend_type>
168
+ <source_model>adminhtml/system_config_source_yesno</source_model>
169
+ <show_in_default>1</show_in_default>
170
+ <show_in_website>1</show_in_website>
171
+ <sort_order>105</sort_order>
172
+ <depends>
173
+ <connection_type>transparent</connection_type>
174
+ </depends>
175
+ </store_in_paypal>
176
+
177
+ <heading_customer_settings translate="label">
178
+ <label>Customer Settings</label>
179
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
180
+ <show_in_default>1</show_in_default>
181
+ <show_in_website>1</show_in_website>
182
+ <sort_order>110</sort_order>
183
+ </heading_customer_settings>
184
+ <can_edit_token translate="label">
185
+ <label>Customer can edit token</label>
186
+ <frontend_type>select</frontend_type>
187
+ <source_model>adminhtml/system_config_source_yesno</source_model>
188
+ <show_in_default>1</show_in_default>
189
+ <show_in_website>1</show_in_website>
190
+ <sort_order>120</sort_order>
191
+ </can_edit_token>
192
+ <can_cancel_subscriptions translate="label">
193
+ <label>Customer can cancel subscriptions</label>
194
+ <frontend_type>select</frontend_type>
195
+ <source_model>adminhtml/system_config_source_yesno</source_model>
196
+ <show_in_default>1</show_in_default>
197
+ <show_in_website>1</show_in_website>
198
+ <sort_order>130</sort_order>
199
+ </can_cancel_subscriptions>
200
+ <block_fraud_customers translate="label">
201
+ <label>Block Fraud customers</label>
202
+ <frontend_type>select</frontend_type>
203
+ <source_model>adminhtml/system_config_source_yesno</source_model>
204
+ <show_in_default>1</show_in_default>
205
+ <show_in_website>1</show_in_website>
206
+ <comment>
207
+ <![CDATA[
208
+ If yes, customers who place a Suspected Fraud order will be blocked from
209
+ placing a new order until the earlier order is accepted.
210
+ ]]>
211
+ </comment>
212
+ <sort_order>140</sort_order>
213
+ </block_fraud_customers>
214
+
215
+ <verify_eway_order translate="label">
216
+ <label>Verify Order</label>
217
+ <frontend_type>select</frontend_type>
218
+ <source_model>ewayrapid/system_config_source_verifyStatus</source_model>
219
+ <show_in_default>1</show_in_default>
220
+ <show_in_website>1</show_in_website>
221
+ <comment>
222
+ <![CDATA[
223
+ The status of an approved "Suspect Fraud" order
224
+ ]]>
225
+ </comment>
226
+ <sort_order>140</sort_order>
227
+ </verify_eway_order>
228
+
229
+ <heading_advanced_settings translate="label">
230
+ <label>Advanced Settings</label>
231
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
232
+ <show_in_default>1</show_in_default>
233
+ <show_in_website>1</show_in_website>
234
+ <sort_order>150</sort_order>
235
+ </heading_advanced_settings>
236
+ <useccv translate="label">
237
+ <label>Require CVN</label>
238
+ <frontend_type>select</frontend_type>
239
+ <source_model>adminhtml/system_config_source_yesno</source_model>
240
+ <show_in_default>1</show_in_default>
241
+ <show_in_website>1</show_in_website>
242
+ <sort_order>160</sort_order>
243
+ <comment>
244
+ <![CDATA[
245
+ eWAY strongly recommends enabling CVN to help prevent fraud. Many banks require it.
246
+ ]]>
247
+ </comment>
248
+ </useccv>
249
+ <cctypes translate="label">
250
+ <label>Accepted Credit Cards</label>
251
+ <frontend_type>multiselect</frontend_type>
252
+ <source_model>ewayrapid/system_config_source_cctype</source_model>
253
+ <show_in_default>1</show_in_default>
254
+ <show_in_website>1</show_in_website>
255
+ <sort_order>170</sort_order>
256
+ <comment>
257
+ <![CDATA[
258
+ Visa Electron and Maestro are accepted in the UK only.
259
+ ]]>
260
+ </comment>
261
+ </cctypes>
262
+ <allowspecific translate="label">
263
+ <label>Payment from Applicable Countries</label>
264
+ <frontend_type>allowspecific</frontend_type>
265
+ <sort_order>175</sort_order>
266
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
267
+ <show_in_default>1</show_in_default>
268
+ <show_in_website>1</show_in_website>
269
+ </allowspecific>
270
+ <specificcountry translate="label">
271
+ <label>Payment from Specific Countries</label>
272
+ <frontend_type>multiselect</frontend_type>
273
+ <sort_order>176</sort_order>
274
+ <source_model>adminhtml/system_config_source_country</source_model>
275
+ <show_in_default>1</show_in_default>
276
+ <show_in_website>1</show_in_website>
277
+ </specificcountry>
278
+ <order_status translate="label">
279
+ <label>New Order Status</label>
280
+ <frontend_type>select</frontend_type>
281
+ <source_model>ewayrapid/system_config_source_orderstatus</source_model>
282
+ <backend_model>ewayrapid/system_config_backend_orderstatus</backend_model>
283
+ <show_in_default>1</show_in_default>
284
+ <show_in_website>1</show_in_website>
285
+ <sort_order>180</sort_order>
286
+ <comment>
287
+ <![CDATA[
288
+ If you have changed Payment Action, please save the config before updating this field.
289
+ ]]>
290
+ </comment>
291
+ </order_status>
292
+ <ssl_verification translate="label">
293
+ <label>Enable SSL Verification</label>
294
+ <frontend_type>select</frontend_type>
295
+ <source_model>adminhtml/system_config_source_yesno</source_model>
296
+ <show_in_default>1</show_in_default>
297
+ <show_in_website>1</show_in_website>
298
+ <sort_order>190</sort_order>
299
+ <comment>
300
+ <![CDATA[
301
+ SSL Verification is always on in Live mode, regardless of this setting.
302
+ ]]>
303
+ </comment>
304
+ </ssl_verification>
305
+ <transfer_cart_items translate="label">
306
+ <label>Transfer Cart Line Items</label>
307
+ <frontend_type>select</frontend_type>
308
+ <source_model>adminhtml/system_config_source_yesno</source_model>
309
+ <show_in_default>1</show_in_default>
310
+ <show_in_website>1</show_in_website>
311
+ <sort_order>200</sort_order>
312
+ </transfer_cart_items>
313
+ <debug translate="label">
314
+ <label>Debug</label>
315
+ <frontend_type>select</frontend_type>
316
+ <source_model>adminhtml/system_config_source_yesno</source_model>
317
+ <show_in_default>1</show_in_default>
318
+ <show_in_website>1</show_in_website>
319
+ <sort_order>230</sort_order>
320
+ </debug>
321
+
322
+ <heading_billing_agreement translate="label">
323
+ <label>Billing Agreement Settings</label>
324
+ <frontend_model>adminhtml/system_config_form_field_heading</frontend_model>
325
+ <show_in_default>1</show_in_default>
326
+ <show_in_website>1</show_in_website>
327
+ <show_in_store>1</show_in_store>
328
+ <sort_order>240</sort_order>
329
+ </heading_billing_agreement>
330
+ <billing_agreement_active translate="label">
331
+ <label>Enabled</label>
332
+ <frontend_type>select</frontend_type>
333
+ <source_model>adminhtml/system_config_source_yesno</source_model>
334
+ <show_in_default>1</show_in_default>
335
+ <show_in_website>1</show_in_website>
336
+ <sort_order>250</sort_order>
337
+ </billing_agreement_active>
338
+ <billing_agreement_title translate="label">
339
+ <label>Title</label>
340
+ <frontend_type>text</frontend_type>
341
+ <show_in_default>1</show_in_default>
342
+ <show_in_website>1</show_in_website>
343
+ <show_in_store>1</show_in_store>
344
+ <sort_order>260</sort_order>
345
+ </billing_agreement_title>
346
+ <billing_agreement_sort_order translate="label">
347
+ <label>Sort Order</label>
348
+ <frontend_type>text</frontend_type>
349
+ <show_in_default>1</show_in_default>
350
+ <show_in_website>1</show_in_website>
351
+ <sort_order>270</sort_order>
352
+ </billing_agreement_sort_order>
353
+ </fields>
354
+ </ewayrapid_general>
355
+ <ewayrapid_notsaved>
356
+ <label>eWAY Rapid 3.1 (Not Saved)</label>
357
+ <frontend_type>text</frontend_type>
358
+ <sort_order>201</sort_order>
359
+ <show_in_default>1</show_in_default>
360
+ <show_in_website>1</show_in_website>
361
+ <show_in_store>1</show_in_store>
362
+ <fields>
363
+ <active>
364
+ <label>Enabled</label>
365
+ <frontend_type>select</frontend_type>
366
+ <source_model>adminhtml/system_config_source_yesno</source_model>
367
+ <show_in_default>1</show_in_default>
368
+ <show_in_website>1</show_in_website>
369
+ <sort_order>10</sort_order>
370
+ </active>
371
+ <title>
372
+ <label>Title</label>
373
+ <frontend_type>text</frontend_type>
374
+ <show_in_default>1</show_in_default>
375
+ <show_in_website>1</show_in_website>
376
+ <show_in_store>1</show_in_store>
377
+ <sort_order>20</sort_order>
378
+ </title>
379
+ <sort_order>
380
+ <label>Sort Order</label>
381
+ <frontend_type>text</frontend_type>
382
+ <show_in_default>1</show_in_default>
383
+ <show_in_website>1</show_in_website>
384
+ <sort_order>30</sort_order>
385
+ </sort_order>
386
+ </fields>
387
+ </ewayrapid_notsaved>
388
+ <ewayrapid_saved>
389
+ <label>eWAY Rapid 3.1 (Saved)</label>
390
+ <frontend_type>text</frontend_type>
391
+ <sort_order>202</sort_order>
392
+ <show_in_default>1</show_in_default>
393
+ <show_in_website>1</show_in_website>
394
+ <show_in_store>1</show_in_store>
395
+ <fields>
396
+ <active>
397
+ <label>Enabled</label>
398
+ <frontend_type>select</frontend_type>
399
+ <source_model>adminhtml/system_config_source_yesno</source_model>
400
+ <show_in_default>1</show_in_default>
401
+ <show_in_website>1</show_in_website>
402
+ <sort_order>10</sort_order>
403
+ <comment>
404
+ <![CDATA[
405
+ eWAY Rapid 3.1 (Saved) will only display to logged in customers
406
+ ]]>
407
+ </comment>
408
+ </active>
409
+ <title>
410
+ <label>Title</label>
411
+ <frontend_type>text</frontend_type>
412
+ <show_in_default>1</show_in_default>
413
+ <show_in_website>1</show_in_website>
414
+ <show_in_store>1</show_in_store>
415
+ <sort_order>20</sort_order>
416
+ </title>
417
+ <sort_order>
418
+ <label>Sort Order</label>
419
+ <frontend_type>text</frontend_type>
420
+ <show_in_default>1</show_in_default>
421
+ <show_in_website>1</show_in_website>
422
+ <sort_order>30</sort_order>
423
+ </sort_order>
424
+ </fields>
425
+ </ewayrapid_saved>
426
+ </groups>
427
+ </payment>
428
+ </sections>
429
+ </config>
app/code/community/Eway/Rapid31/sql/ewayrapid_setup/install-0.1.0.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Created by PhpStorm.
4
+ * User: hiephm
5
+ * Date: 4/23/14
6
+ * Time: 5:30 PM
7
+ */
8
+ /* @var $installer Mage_Core_Model_Resource_Setup */
9
+ $installer = $this;
10
+
11
+ $installer->startSetup();
12
+
13
+ $setup = Mage::getResourceModel('customer/setup', 'core_setup');
14
+
15
+ $setup->addAttribute('customer', 'saved_tokens_json', array(
16
+ 'input' => '',
17
+ 'type' => 'text',
18
+ 'label' => '',
19
+ 'visible' => '0',
20
+ 'required' => '0',
21
+ 'user_defined' => '0',
22
+ 'backend' => 'ewayrapid/backend_savedtokens',
23
+ ));
24
+
25
+ $installer->endSetup();
app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-0.1.0-1.0.0.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ Mage::getModel('sales/order_status')
8
+ ->setStatus(Eway_Rapid31_Model_Config::ORDER_STATUS_AUTHORISED)
9
+ ->setLabel('eWAY Authorised')
10
+ ->assignState('processing')
11
+ ->save();
12
+
13
+ Mage::getModel('sales/order_status')
14
+ ->setStatus(Eway_Rapid31_Model_Config::ORDER_STATUS_CAPTURED)
15
+ ->setLabel('eWAY Captured')
16
+ ->assignState('processing')
17
+ ->save();
18
+
19
+ $installer->endSetup();
app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-1.0.0-1.0.1.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* @var $installer Mage_Core_Model_Resource_Setup */
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+ try {
7
+ $installer->run("
8
+ ALTER IGNORE TABLE sales_flat_order ADD COLUMN eway_transaction_id char(50) NULL;
9
+ ALTER TABLE sales_flat_quote ADD IGNORE COLUMN transaction_id char(50) NULL;
10
+ ");
11
+ } catch (Exception $e) {
12
+ }
13
+
14
+ $setup = Mage::getResourceModel('customer/setup', 'core_setup');
15
+
16
+ $setup->addAttribute('customer', 'mark_fraud', array(
17
+ 'input' => '',
18
+ 'type' => 'int',
19
+ 'label' => '',
20
+ 'visible' => '0',
21
+ 'required' => '0',
22
+ 'user_defined' => '0',
23
+ 'backend' => '',
24
+ ));
25
+
26
+ $installer->endSetup();
app/code/community/Eway/Rapid31/sql/ewayrapid_setup/upgrade-1.0.1-1.0.3.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* @var $installer Mage_Core_Model_Resource_Setup */
4
+ $installer = $this;
5
+ $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',
13
+ 'visible' => '0',
14
+ 'required' => '0',
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');
22
+ Mage::getModel('customer/attribute')->load($attributeId)
23
+ ->setSortOrder(999)
24
+ ->save();
25
+
26
+ $oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'block_fraud_customer');
27
+ $oAttribute->setData('used_in_forms', array('adminhtml_customer'));
28
+ $oAttribute->save();
29
+
30
+ $installer->endSetup();
31
+ } catch (Exception $e) {
32
+
33
+ }
app/design/adminhtml/default/default/layout/ewayrapid/layout.xml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <adminhtml_sales_order_create_index>
4
+ <reference name="head">
5
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/eCrypt.js</script></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
+ </layout>
app/design/adminhtml/default/default/template/ewayrapid/form/direct_notsaved.phtml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ </ul>
app/design/adminhtml/default/default/template/ewayrapid/form/direct_saved.phtml ADDED
@@ -0,0 +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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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/info/direct_notsaved.phtml ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ <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
+ <tr>
43
+ <td><?php echo $_helper->__('Card Holder\'s Name') ?>:</td>
44
+ <td><?php echo $_info->getCcOwner(); ?></td>
45
+ </tr>
46
+ <tr>
47
+ <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
48
+ <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
49
+ </tr>
50
+ <tr>
51
+ <td><?php echo $_helper->__('Credit Card Expiry') ?>:</td>
52
+ <td><?php echo str_pad($_info->getCcExpMonth(), 2, '0', STR_PAD_LEFT); ?> / <?php echo $_info->getCcExpYear() ?></td>
53
+ </tr>
54
+ <tr>
55
+ <td><?php echo $_helper->__('Credit Card Type') ?>:</td>
56
+ <td><?php echo $this->getCcTypeName($_info->getCcType()); ?></td>
57
+ </tr>
58
+ <tr>
59
+ <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
60
+ <td><?php echo $_info->getLastTransId(); ?></td>
61
+ </tr>
62
+ </tbody>
63
+ </table>
64
+ </div>
app/design/adminhtml/default/default/template/ewayrapid/info/direct_saved.phtml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ <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
+ <tr>
43
+ <td><?php echo $_helper->__('Payer ID') ?>:</td>
44
+ <td><?php echo $this->getTokenId() ?></td>
45
+ </tr>
46
+ <tr>
47
+ <td><?php echo $_helper->__('Credit Card Number') ?>:</td>
48
+ <td><?php echo str_pad($_info->getCcLast4(), 16, '*', STR_PAD_LEFT); ?></td>
49
+ </tr>
50
+ <tr>
51
+ <td><?php echo $_helper->__('Last Transaction ID') ?>:</td>
52
+ <td><?php echo $_info->getLastTransId(); ?></td>
53
+ </tr>
54
+ </tbody>
55
+ </table>
56
+ </div>
app/design/adminhtml/default/default/template/ewayrapid/pdf/direct_notsaved.phtml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+
28
+ <?php
29
+ $cards = $this->getCards();
30
+ $showCount = count($cards) > 1;
31
+ ?>
32
+
33
+ <?php echo $this->getMethod()->getTitle() ?>{{pdf_row_separator}}
app/design/frontend/base/default/layout/ewayrapid/layout.xml ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <checkout_onepage_index>
4
+ <reference name="head">
5
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/eCrypt.js</script></action>
6
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
7
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
8
+ </reference>
9
+ <reference name="content">
10
+ <block type="core/template" name="ewayrapid.js" after="-">
11
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
12
+ <template>ewayrapid/js.phtml</template>
13
+ </action>
14
+ </block>
15
+ </reference>
16
+ </checkout_onepage_index>
17
+
18
+ <checkout_multishipping_billing>
19
+ <reference name="head">
20
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/eCrypt.js</script></action>
21
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
22
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
23
+ </reference>
24
+ <reference name="content">
25
+ <block type="core/template" name="ewayrapid.js" after="-">
26
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
27
+ <template>ewayrapid/js.phtml</template>
28
+ </action>
29
+ <action method="setCheckoutExtension">
30
+ <name>MultiShippingAddress</name>
31
+ </action>
32
+ </block>
33
+ </reference>
34
+ </checkout_multishipping_billing>
35
+
36
+ <customer_account>
37
+ <reference name="customer_account_navigation">
38
+ <action ifconfig="payment/ewayrapid_saved/active" method="addLink" translate="label" module="ewayrapid">
39
+ <name>my-creditcards</name>
40
+ <path>ewayrapid/mycards/</path>
41
+ <label>My Credit Cards</label>
42
+ </action>
43
+
44
+ <action ifconfig="payment/ewayrapid_transparentRedirect/active" method="addLink" translate="label" module="ewayrapid">
45
+ <name>my-transparent-redirect-card</name>
46
+ <path>ewayrapid/transparentredirectcard/</path>
47
+ <label>My Transparent Redirect Card</label>
48
+ </action>
49
+
50
+ </reference>
51
+ </customer_account>
52
+ <ewayrapid_mycards_index>
53
+ <update handle="customer_account"/>
54
+ <reference name="my.account.wrapper">
55
+ <block type="ewayrapid/customer_mycards" template="ewayrapid/customer/mycards.phtml" name="ewayrapid.token.list"></block>
56
+ <block type="customer/account_dashboard" name="customer.account.link.back" template="customer/account/link/back.phtml"/>
57
+ </reference>
58
+ </ewayrapid_mycards_index>
59
+
60
+ <ewayrapid_mycards_edit>
61
+ <reference name="head">
62
+ <!--<action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/eCrypt.js</script></action>-->
63
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
64
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
65
+ </reference>
66
+ <update handle="customer_account"/>
67
+ <reference name="my.account.wrapper">
68
+ <block type="ewayrapid/customer_edit" template="ewayrapid/customer/edit.phtml" name="ewayrapid.token.edit"></block>
69
+ </reference>
70
+ </ewayrapid_mycards_edit>
71
+
72
+ <onestepcheckout_index_index>
73
+ <reference name="head">
74
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/eCrypt.js</script></action>
75
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
76
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
77
+ </reference>
78
+ <reference name="before_body_end">
79
+ <block type="core/template" name="ewayrapid.js" after="-">
80
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
81
+ <template>ewayrapid/js.phtml</template>
82
+ </action>
83
+ <action method="setCheckoutExtension">
84
+ <name>OneStepCheckout</name>
85
+ </action>
86
+ </block>
87
+ </reference>
88
+ </onestepcheckout_index_index>
89
+
90
+ <firecheckout_index_index>
91
+ <reference name="head">
92
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/eCrypt.js</script></action>
93
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
94
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
95
+ </reference>
96
+ <reference name="before_body_end">
97
+ <block type="core/template" name="ewayrapid.js" after="-">
98
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
99
+ <template>ewayrapid/js.phtml</template>
100
+ </action>
101
+ <action method="setCheckoutExtension">
102
+ <name>FireCheckout</name>
103
+ </action>
104
+ </block>
105
+ </reference>
106
+ </firecheckout_index_index>
107
+
108
+ <opc_index_index>
109
+ <reference name="head">
110
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/eCrypt.js</script></action>
111
+ <action ifconfig="payment/ewayrapid_general/active" method="addJs"><script>ewayrapid/ewayrapid.js</script></action>
112
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
113
+ </reference>
114
+ <reference name="before_body_end">
115
+ <block type="core/template" name="ewayrapid.js" after="-">
116
+ <action ifconfig="payment/ewayrapid_general/active" method="setTemplate">
117
+ <template>ewayrapid/js.phtml</template>
118
+ </action>
119
+ <action method="setCheckoutExtension">
120
+ <name>IWDOnePageCheckout</name>
121
+ </action>
122
+ </block>
123
+ </reference>
124
+ </opc_index_index>
125
+
126
+ <hanlder_transparent_layout_empty>
127
+ <update handle="default"/>
128
+ <reference name="root">
129
+ <action method="setTemplate">
130
+ <template>page/empty.phtml</template>
131
+ </action>
132
+ </reference>
133
+ </hanlder_transparent_layout_empty>
134
+
135
+ <hanlder_transparent_layout>
136
+ <update handle="default"/>
137
+ <reference name="head">
138
+ <action ifconfig="payment/ewayrapid_general/active" method="addCss"><script>css/ewayrapid.css</script></action>
139
+ </reference>
140
+ <reference name="root">
141
+ <action method="setTemplate">
142
+ <template>page/1column.phtml</template>
143
+ </action>
144
+ </reference>
145
+ </hanlder_transparent_layout>
146
+
147
+ <ewayrapid_transparent_paynow>
148
+ <update handle="hanlder_transparent_layout_empty"/>
149
+ <reference name="content">
150
+ <block type="ewayrapid/redirect_transparent" name="transparent.block.paynow"/>
151
+ </reference>
152
+ </ewayrapid_transparent_paynow>
153
+
154
+ <ewayrapid_transparent_redirect>
155
+ <update handle="hanlder_transparent_layout_empty"/>
156
+ <reference name="content">
157
+ <block type="ewayrapid/redirect_transparentCheckout" name="transparent.block.checkout"/>
158
+ </reference>
159
+ </ewayrapid_transparent_redirect>
160
+
161
+ <ewayrapid_handle_review>
162
+ <label>Eway Paypal Order Review Form</label>
163
+ <remove name="right"/>
164
+ <remove name="left"/>
165
+
166
+ <reference name="root">
167
+ <action method="setTemplate">
168
+ <template>page/1column.phtml</template>
169
+ </action>
170
+ </reference>
171
+ <reference name="content">
172
+ <block type="ewayrapid/redirect_paypalReview" name="eway.block.review">
173
+ </block>
174
+ </reference>
175
+ </ewayrapid_handle_review>
176
+
177
+ <ewayrapid_transparent_review>
178
+ <update handle="ewayrapid_handle_review"/>
179
+ </ewayrapid_transparent_review>
180
+
181
+ <ewayrapid_sharedpage_review>
182
+ <update handle="ewayrapid_handle_review"/>
183
+ </ewayrapid_sharedpage_review>
184
+ </layout>
app/design/frontend/base/default/template/ewayrapid/customer/edit.phtml ADDED
@@ -0,0 +1,615 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ switch ($connectionType) {
10
+ case Eway_Rapid31_Model_Config::CONNECTION_DIRECT:
11
+ echo '<script type="text/javascript" src="' . Mage::getBaseUrl() . '/js/ewayrapid/eCrypt.js"></script>';
12
+ break;
13
+ case Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT:
14
+ $transparent = true;
15
+ break;
16
+ case Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE:
17
+ $formUrl = Mage::getBaseUrl() . '/ewayrapid/mycards/getAccessCode';
18
+ break;
19
+ default:
20
+ break;
21
+ }
22
+ ?>
23
+ <?php if ($this->getTitle()): ?>
24
+ <div class="page-title">
25
+ <h1><?php echo $this->getTitle() ?></h1>
26
+ </div>
27
+ <?php endif; ?>
28
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
29
+ <div class="tool-tip" id="payment-tool-tip" style="display:none;">
30
+ <div class="btn-close"><a href="#" id="payment-tool-tip-close"
31
+ title="<?php echo $this->__('Close') ?>"><?php echo $this->__('Close') ?></a></div>
32
+ <div class="tool-tip-content"><img src="<?php echo $this->getSkinUrl('images/cvv.gif') ?>"
33
+ alt="<?php echo $this->__('Card Verification Number Visual Reference') ?>"
34
+ title="<?php echo $this->__('Card Verification Number Visual Reference') ?>"/>
35
+ </div>
36
+ </div>
37
+ <form action="<?php echo $formUrl ?>" method="post" id="form-validate">
38
+ <input type="hidden" name="EWAY_ACCESSCODE" id="eway_accesscode"/>
39
+ <?php
40
+ if ($_token->getTokenId()) {
41
+ ?>
42
+ <input type="hidden" name="token_id" value="<?php echo $_token->getTokenId() ?>"/>
43
+ <input type="hidden" name="TokenCustomerID" value="<?php echo $_token->getToken() ?>"/>
44
+ <?php } ?>
45
+
46
+ <!-- Card info -->
47
+ <?php
48
+ if ($connectionType !== Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
49
+ ?>
50
+ <div class="fieldset">
51
+ <?php echo $this->getBlockHtml('formkey') ?>
52
+ <h2 class="legend"><?php echo $this->__('Credit Card Information') ?></h2>
53
+
54
+ <div class="sp-methods">
55
+ <ul class="form-list">
56
+ <li>
57
+ <div class="input-box">
58
+ <label for="ewayrapid_saved_cc_owner"
59
+ class="required"><em>*</em><?php echo $this->__('Name on Card') ?></label>
60
+ <input type="text" title="<?php echo $this->__('Name on Card') ?>"
61
+ class="input-text required-entry validate-length maximum-length-50"
62
+ id="ewayrapid_saved_cc_owner"
63
+ name="payment[cc_owner]" value="<?php echo $this->escapeHtml($_token->getOwner()) ?>"
64
+ __maxlength="50" autocomplete="off"/>
65
+ </div>
66
+ </li>
67
+ <li>
68
+ <label for="ewayrapid_saved_cc_number"
69
+ class="required"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
70
+
71
+ <div class="input-box help-disabled-cc">
72
+ <input type="text" id="ewayrapid_saved_cc_number" data-eway-encrypt-name="payment[cc_number]"
73
+ title="<?php echo $this->__('Credit Card Number') ?>"
74
+ class="input-text <?php if (!$this->isEdit()): ?>validate-cc-number validate-cc-type-auto<?php endif; ?>"
75
+ autocomplete="off" <?php if ($this->isEdit()): ?>value="<?php echo $_token->getCard() ?>"
76
+ disabled="disabled" <?php endif; ?> pattern="\d*"/>
77
+ <input type="hidden" id="ewayrapid_saved_cc_type" name="payment[cc_type]"
78
+ value="<?php echo $_token->getType() ?>"/>
79
+ <?php if ($this->isEdit()): ?>
80
+ <input type="hidden" name="EWAY_CARDNUMBER" value="444433XXXXXX1111"/>
81
+ <a href="#"><?php echo $this->__('Help') ?></a>
82
+ <div class="tool-tip" id="cc-help-tool-tip" style="display:none;">
83
+ <div class="btn-close">
84
+ <a href="#" id="cc-help-tool-tip-close"
85
+ title="<?php echo $this->__('Close') ?>"><?php echo $this->__('Close') ?></a>
86
+ </div>
87
+ <div class="tool-tip-content">To use a new credit card number, please add another card
88
+ </div>
89
+ </div>
90
+ <?php endif; ?>
91
+ </div>
92
+ </li>
93
+
94
+ <li id="ewayrapid_saved_cc_type_exp_div">
95
+ <label for="ewayrapid_saved_expiration"
96
+ class="required"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
97
+
98
+ <div class="input-box">
99
+ <div class="v-fix">
100
+ <select id="ewayrapid_saved_expiration" name="payment[cc_exp_month]"
101
+ class="month validate-cc-exp required-entry" autocomplete="off">
102
+ <?php $_ccExpMonth = $_token->getExpMonth() ?>
103
+ <?php foreach ($this->getCcMonths() as $k => $v): ?>
104
+ <option
105
+ value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
106
+ <?php endforeach ?>
107
+ </select>
108
+ </div>
109
+ <div class="v-fix">
110
+ <?php $_ccExpYear = $_token->getExpYear() ?>
111
+ <select id="ewayrapid_saved_expiration_yr" name="payment[cc_exp_year]"
112
+ class="year required-entry" autocomplete="off">
113
+ <?php foreach ($this->getCcYears() as $k => $v): ?>
114
+ <option
115
+ value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
116
+ <?php endforeach ?>
117
+ </select>
118
+ </div>
119
+ </div>
120
+ </li>
121
+
122
+ <?php
123
+ if ($transparent) {
124
+ ?>
125
+ <li class="value_from_date">
126
+ <label for="ewayrapid_saved_start_month"
127
+ class="required"><?php echo $this->__('Valid From Date') ?></label>
128
+
129
+ <div class="input-box">
130
+ <div class="v-fix">
131
+ <select id="ewayrapid_saved_start_month" name="payment[cc_start_month]"
132
+ class="month" autocomplete="off">
133
+ <?php $_ccStartMonth = $_token->getStartMonth() ?>
134
+ <?php foreach ($this->getCcMonths() as $k => $v): ?>
135
+ <option value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccStartMonth): ?>
136
+ selected="selected"<?php endif ?>><?php echo $v ?></option>
137
+ <?php endforeach ?>
138
+ </select>
139
+ </div>
140
+ <div class="v-fix">
141
+ <?php $_ccStartYear = $_token->getStartYear() ?>
142
+ <select id="ewayrapid_saved_start_year" name="payment[cc_start_year]"
143
+ class="year" autocomplete="off">
144
+ <?php
145
+ $start_year = 0;
146
+ $inc = 0;
147
+ foreach ($this->getCcYears() as $k => $v) {
148
+ if ($inc == 1) {
149
+ $start_year = (int)$k;
150
+ break;
151
+ }
152
+ echo "<option value=''>Year</option>";
153
+ $inc++;
154
+ }
155
+
156
+ for ($i = 10; $i > 0; $i--) {
157
+ ?>
158
+ <option value="<?php echo $start_year - $i ?>"
159
+ <?php if (($start_year - $i) == $_ccStartYear) { ?>
160
+ selected="selected"<?php } ?>>
161
+ <?php echo $start_year - $i ?>
162
+ </option>
163
+ <?php
164
+ }
165
+
166
+ $inc = 0;
167
+ foreach ($this->getCcYears() as $k => $v):
168
+ $inc++;
169
+ if ($inc == 1) {
170
+ continue;
171
+ }
172
+ ?>
173
+ <option value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccStartYear): ?>
174
+ selected="selected"<?php endif ?>><?php echo $v ?></option>
175
+ <?php
176
+ endforeach;
177
+ ?>
178
+ </select>
179
+ </div>
180
+ </div>
181
+ </li>
182
+ <li>
183
+ <div class="input-box">
184
+ <label for="ewayrapid_saved_issue_number">
185
+ <?php echo $this->__('Issue Number') ?>
186
+ </label>
187
+ <input type="text" title="<?php echo $this->__('Issue Number') ?>"
188
+ class="input-text validate-length maximum-length-4"
189
+ id="ewayrapid_saved_issue_number"
190
+ name="payment[cc_issue_number]"
191
+ value="<?php echo $this->escapeHtml($_token->getIssueNumber()) ?>"
192
+ __maxlength="50" autocomplete="off"/>
193
+ </div>
194
+ </li>
195
+ <?php
196
+ }
197
+ ?>
198
+
199
+ <?php if ($this->hasVerification()): ?>
200
+ <li id="ewayrapid_saved_cc_type_cvv_div">
201
+ <label for="ewayrapid_saved_cc_cid"
202
+ class="required"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
203
+
204
+ <div class="input-box">
205
+ <div class="v-fix">
206
+ <input type="text" title="<?php echo $this->__('Card Verification Number') ?>"
207
+ class="input-text cvv required-entry validate-cc-cvn" id="ewayrapid_saved_cc_cid"
208
+ data-eway-encrypt-name="payment[cc_cid]" value="" autocomplete="off"
209
+ pattern="\d*"/>
210
+ </div>
211
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
212
+ </div>
213
+ </li>
214
+ <?php endif; ?>
215
+ <?php
216
+ $_defaultToken = Mage::helper('ewayrapid/customer')->getDefaultToken();
217
+ if (!$_token->getToken() || ($_defaultToken && $_defaultToken != $_token->getTokenId())): ?>
218
+ <li>
219
+ <div class="v-fix" style="padding-right: 5px;">
220
+ <input type="checkbox" id="ewayrapid_saved_default" name="is_default"/>
221
+ </div>
222
+ <label for="ewayrapid_saved_default"><?php echo $this->__('Default Credit Card') ?></label>
223
+ </li>
224
+ <?php endif; ?>
225
+ </ul>
226
+ </div>
227
+ </div>
228
+ <?php
229
+ } else {
230
+ // Responsive shared page card data
231
+ // ....
232
+ $_defaultToken = Mage::helper('ewayrapid/customer')->getDefaultToken();
233
+ if (!$_token->getToken() || ($_defaultToken && $_defaultToken != $_token->getTokenId())): ?>
234
+ <ul>
235
+ <li>
236
+ <div class="v-fix" style="padding-right: 5px;">
237
+ <input type="checkbox" id="ewayrapid_saved_default" name="is_default"/>
238
+ </div>
239
+ <label for="ewayrapid_saved_default"><?php echo $this->__('Default Credit Card') ?></label>
240
+ </li>
241
+ </ul>
242
+ <?php endif;
243
+ } ?>
244
+ <div class="fieldset bill-address">
245
+ <h2 class="legend"><?php echo $this->__('Billing Address') ?></h2>
246
+ <ul class="form-list">
247
+ <li class="fields">
248
+ <div class="customer-name-prefix">
249
+ <div class="field name-prefix">
250
+ <label for="address_prefix"><?php echo $this->__('Title') ?></label>
251
+
252
+ <div class="input-box">
253
+ <select id="address_prefix" name="address[prefix]" title="<?php echo $this->__('Title') ?>">
254
+ <?php foreach ($this->getPrefixOptions() as $_option): ?>
255
+ <option
256
+ value="<?php echo $_option ?>"<?php if ($_address->getTitle() == $_option): ?>
257
+ selected="selected"<?php endif; ?>><?php echo $this->__($_option) ?></option>
258
+ <?php endforeach; ?>
259
+ </select>
260
+ </div>
261
+ </div>
262
+ <div class="field name-firstname">
263
+ <label for="address_firstname" class="required"><em>*</em><?php echo $this->__('First Name') ?>
264
+ </label>
265
+
266
+ <div class="input-box">
267
+ <input type="text" id="address_firstname" name="address[firstname]"
268
+ value="<?php echo $this->escapeHtml($_address->getFirstName()) ?>"
269
+ title="<?php echo $this->__('First Name') ?>"
270
+ __maxlength="50" class="input-text required-entry validate-length maximum-length-50"/>
271
+ </div>
272
+ </div>
273
+ <div class="field name-lastname">
274
+ <label for="address_lastname" class="required"><em>*</em><?php echo $this->__('Last Name') ?>
275
+ </label>
276
+
277
+ <div class="input-box">
278
+ <input type="text" id="address_lastname" name="address[lastname]"
279
+ value="<?php echo $this->escapeHtml($_address->getLastName()) ?>"
280
+ title="<?php echo $this->__('Last Name') ?>" __maxlength="50"
281
+ class="input-text required-entry validate-length maximum-length-50"/>
282
+ </div>
283
+ </div>
284
+ </div>
285
+ </li>
286
+ <li class="fields">
287
+ <div class="field">
288
+ <label for="address_company"><?php echo $this->__('Company') ?></label>
289
+
290
+ <div class="input-box">
291
+ <input type="text" name="address[company]" id="address_company"
292
+ title="<?php echo $this->__('Company') ?>" __maxlength="50"
293
+ value="<?php echo $this->escapeHtml($_address->getCompanyName()) ?>"
294
+ class="input-text validate-length maximum-length-50"/>
295
+ </div>
296
+ </div>
297
+ <div class="field">
298
+ <label for="address_job_description"><?php echo $this->__('Job Description') ?></label>
299
+
300
+ <div class="input-box">
301
+ <input type="text" name="address[job_description]" id="address_job_description"
302
+ title="<?php echo $this->__('Job Description') ?>" __maxlength="50"
303
+ value="<?php echo $this->escapeHtml($_address->getJobDescription()) ?>"
304
+ class="input-text validate-length maximum-length-50"/>
305
+ </div>
306
+ </div>
307
+
308
+ </li>
309
+ <li class="fields">
310
+ <div class="field">
311
+ <label for="address_telephone" class="required"><em>*</em><?php echo $this->__('Phone') ?></label>
312
+
313
+ <div class="input-box">
314
+ <input type="text" name="address[telephone]"
315
+ value="<?php echo $this->escapeHtml($_address->getPhone()) ?>"
316
+ title="<?php echo $this->__('Phone') ?>"
317
+ class="input-text required-entry eway-validate-phone validate-length maximum-length-32"
318
+ id="address_telephone" __maxlength="32"/>
319
+ </div>
320
+ </div>
321
+ <div class="field">
322
+ <label for="address_mobile"><?php echo $this->__('Mobile') ?></label>
323
+
324
+ <div class="input-box">
325
+ <input type="text" name="address[mobile]"
326
+ value="<?php echo $this->escapeHtml($_address->getMobile()) ?>"
327
+ title="<?php echo $this->__('Mobile') ?>"
328
+ class="input-text eway-validate-phone validate-length maximum-length-32"
329
+ id="address_mobile" __maxlength="32"/>
330
+ </div>
331
+ </div>
332
+ </li>
333
+ <li class="fields">
334
+ <div class="field">
335
+ <label for="address_email"><?php echo $this->__('Email') ?></label>
336
+
337
+ <div class="input-box">
338
+ <input type="text" name="address[email]" id="address_email" __maxlength="50"
339
+ title="<?php echo $this->__('Email') ?>"
340
+ value="<?php echo $this->escapeHtml($_address->getEmail()) ?>"
341
+ class="input-text validate-email validate-length maximum-length-50"/>
342
+ </div>
343
+ </div>
344
+ <div class="field">
345
+ <label for="address_fax"><?php echo $this->__('Fax') ?></label>
346
+
347
+ <div class="input-box">
348
+ <input type="text" name="address[fax]" id="address_fax" title="<?php echo $this->__('Fax') ?>"
349
+ value="<?php echo $this->escapeHtml($_address->getFax()) ?>"
350
+ class="input-text eway-validate-phone validate-length maximum-length-32" __maxlength="32"/>
351
+ </div>
352
+ </div>
353
+ </li>
354
+ <li class="wide">
355
+ <label for="address_street_1" class="required"><em>*</em><?php echo $this->__('Street Address') ?></label>
356
+
357
+ <div class="input-box">
358
+ <input type="text" name="address[street][]" __maxlength="50"
359
+ value="<?php echo $this->escapeHtml($_address->getStreet1()) ?>"
360
+ title="<?php echo $this->__('Street Address') ?>" id="address_street_1"
361
+ class="input-text required-entry validate-length maximum-length-50"/>
362
+ </div>
363
+ </li>
364
+ <li class="wide">
365
+ <div class="input-box">
366
+ <input type="text" name="address[street][]" __maxlength="50"
367
+ value="<?php echo $this->escapeHtml($_address->getStreet2()) ?>"
368
+ title="<?php echo $this->__('Street Address') ?>" id="address_street_2"
369
+ class="input-text validate-length maximum-length-50"/>
370
+ </div>
371
+ </li>
372
+ <li class="fields">
373
+ <div class="field">
374
+ <label for="address_city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
375
+
376
+ <div class="input-box">
377
+ <input type="text" name="address[city]" __maxlength="50"
378
+ value="<?php echo $_address->getCity() ?>" title="<?php echo $this->__('City') ?>"
379
+ class="input-text required-entry validate-length maximum-length-50" id="address_city"/>
380
+ </div>
381
+ </div>
382
+ <div class="field">
383
+ <label for="address_region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?>
384
+ </label>
385
+
386
+ <div class="input-box">
387
+ <select id="address_region_id" name="address[region_id]"
388
+ title="<?php echo $this->__('State/Province') ?>" class="validate-select"
389
+ style="display:none;">
390
+ <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
391
+ </select>
392
+ <script type="text/javascript">
393
+ //<![CDATA[
394
+ $('address_region_id').setAttribute('defaultValue', "<?php echo $_address->getRegionId() ?>");
395
+ //]]>
396
+ </script>
397
+ <input type="text" id="address_region" name="address[region]" __maxlength="50"
398
+ value="<?php echo $this->escapeHtml($_address->getState()) ?>"
399
+ title="<?php echo $this->__('State/Province') ?>"
400
+ class="input-text validate-length maximum-length-50"/>
401
+ </div>
402
+ </div>
403
+ </li>
404
+ <li class="fields">
405
+ <div class="field">
406
+ <label for="address_zip" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
407
+
408
+ <div class="input-box">
409
+ <input type="text" name="address[postcode]"
410
+ value="<?php echo $this->escapeHtml($_address->getPostalCode()) ?>"
411
+ title="<?php echo $this->__('Zip/Postal Code') ?>" id="address_zip"
412
+ class="input-text validate-zip-international required-entry validate-length maximum-length-30"
413
+ __maxlength="30"/>
414
+ </div>
415
+ </div>
416
+ <div class="field">
417
+ <label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
418
+
419
+ <div class="input-box">
420
+ <?php echo $this->getCountryHtmlSelect(strtoupper($_address->getCountry()), 'address[country_id]', 'address_country') ?>
421
+ </div>
422
+ </div>
423
+ </li>
424
+ </ul>
425
+ </div>
426
+ <div class="buttons-set">
427
+ <p class="required"><?php echo $this->__('* Required Fields') ?></p>
428
+
429
+ <p class="back-link"><a href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>">
430
+ <small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
431
+ <?php
432
+ echo $transparent ? '<button type="button" onclick="beforeSubmit(this)" title="'
433
+ . $this->__('Save Credit Card') . '" class="button"><span><span>'
434
+ . $this->__('Save Credit Card') . '</span></span></button>'
435
+ . '<span id="save-please-wait" class="please-wait" style="display:none;">
436
+ <img class="v-middle" title="Loading..." alt="Loading..." src="'
437
+ . Mage::getBaseUrl() . '/skin/frontend/default/default/images/opc-ajax-loader.gif">
438
+ Please waiting ...
439
+ </span>'
440
+ : '<button type="submit" title="' . $this->__('Save Credit Card') . '" class="button"><span><span>' . $this->__('Save Credit Card') . '</span></span></button>';
441
+ ?>
442
+
443
+ </div>
444
+ </form>
445
+
446
+ <script type="text/javascript">
447
+ //<![CDATA[
448
+ var dataForm = new VarienForm('form-validate', true);
449
+ new RegionUpdater('address_country', 'address_region', 'address_region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'address_zip');
450
+ EwayPayment.supportCardTypes = <?php echo json_encode(Mage::getSingleton('ewayrapid/config')->getSupportedCardTypes()) ?>;
451
+
452
+ $$('.cvv-what-is-this').each(function (element) {
453
+ Event.observe(element, 'click', toggleToolTip);
454
+ });
455
+
456
+ function toggleToolTip(event) {
457
+ if ($('payment-tool-tip')) {
458
+ $('payment-tool-tip').setStyle({
459
+ top: (Event.pointerY(event) - 200) + 'px'//,
460
+ })
461
+ $('payment-tool-tip').toggle();
462
+ }
463
+ Event.stop(event);
464
+ }
465
+ if ($('payment-tool-tip-close')) {
466
+ Event.observe($('payment-tool-tip-close'), 'click', toggleToolTip);
467
+ }
468
+
469
+ $('form-validate').onsubmit = function () {
470
+ return (dataForm.validator && dataForm.validator.validate());
471
+ }
472
+ var ewayPayment = new EwayPayment($('form-validate'), '<?php echo Mage::getSingleton('ewayrapid/config')->getEncryptionKey() ?>');
473
+
474
+ $$('.help-disabled-cc a').each(function (element) {
475
+ Event.observe(element, 'click', toggleToolTipCc);
476
+ });
477
+
478
+ function toggleToolTipCc(event) {
479
+ if ($('cc-help-tool-tip')) {
480
+ $('cc-help-tool-tip').toggle();
481
+ }
482
+ Event.stop(event);
483
+ }
484
+ if ($('cc-help-tool-tip-close')) {
485
+ Event.observe($('cc-help-tool-tip-close'), 'click', toggleToolTipCc);
486
+ }
487
+
488
+ // TRANSPARENT REDIRECT
489
+ function beforeSubmit(obj) {
490
+ $('validate_from_date_message') != null ? $('validate_from_date_message').remove() : '';
491
+ $('ewayrapid_saved_start_month').removeClassName('validation-failed');
492
+ $('ewayrapid_saved_start_year').removeClassName('validation-failed');
493
+ $$('li.value_from_date')[0].removeClassName('validation-error');
494
+
495
+ if (typeof isTest !== 'undefined') {
496
+ // Alert error code ERR-012
497
+ alert('An error occurred while connecting to payment gateway. Please try again later.!');
498
+ return false;
499
+ }
500
+
501
+ //*********************************Valid From Date If Select********************************************************************
502
+ if($('ewayrapid_saved_start_year').value > 0 && $('ewayrapid_saved_start_month').value <= 0) {
503
+ $('validation-advice-year') && $('validation-advice-year').remove();
504
+ $('ewayrapid_saved_start_month').addClassName('validation-failed');
505
+ $('ewayrapid_saved_start_month').up('div').insert('<div class="validation-advice" id="validation-advice-month">Incorrect credit card from date.</div>');
506
+ return;
507
+ } else if($('ewayrapid_saved_start_year').value <= 0 && $('ewayrapid_saved_start_month').value > 0) {
508
+ $('validation-advice-month') && $('validation-advice-month').remove();
509
+ $('ewayrapid_saved_start_year').addClassName('validation-failed');
510
+ $('ewayrapid_saved_start_year').up('div').insert('<div class="validation-advice" id="validation-advice-year">Incorrect credit card from year.</div>');
511
+ return;
512
+ } else {
513
+ $('validation-advice-year') && $('validation-advice-year').remove();
514
+ $('validation-advice-month') && $('validation-advice-month').remove();
515
+ }
516
+
517
+ var from_date = new Date($('ewayrapid_saved_start_year').value + '-' + $('ewayrapid_saved_start_month').value).getTime();
518
+ var expiration_date = new Date($('ewayrapid_saved_expiration_yr').value + '-' + $('ewayrapid_saved_expiration').value).getTime();
519
+ if(Prototype.Browser.IE) {
520
+ from_date = new Date($('ewayrapid_saved_start_year').value, $('ewayrapid_saved_start_month').value, 1).getTime();
521
+ expiration_date = new Date($('ewayrapid_saved_expiration_yr').value, $('ewayrapid_saved_expiration').value, 1).getTime();
522
+ }
523
+ //console.log(from_date - expiration_date);
524
+
525
+ if(from_date - expiration_date > 0) {
526
+ $$('li.value_from_date')[0].insert({after: '<div style="" id="validate_from_date_message" ' +
527
+ 'class="validation-advice">From Date is invalid. It must be earlier than Expiration Date.</div>'});
528
+ $('ewayrapid_saved_start_month').addClassName('validation-failed');
529
+ $('ewayrapid_saved_start_year').addClassName('validation-failed');
530
+ $$('li.value_from_date')[0].addClassName('validation-error');
531
+ return;
532
+ }
533
+ //******************************************************************************************************************************
534
+
535
+ var validate = dataForm.validator.validate();
536
+ if (!validate) {
537
+ return;
538
+ }
539
+
540
+ /*if ($('ewayrapid_saved_start_year').value != '' || $('ewayrapid_saved_start_month').value != '') {
541
+ if ((new Date($('ewayrapid_saved_expiration_yr').value + '-'
542
+ + ($('ewayrapid_saved_expiration').value <= 9 ? '0' : '') + $('ewayrapid_saved_expiration').value).getTime() )
543
+ - ( new Date($('ewayrapid_saved_start_year').value + '-'
544
+ + ($('ewayrapid_saved_start_month').value <= 9 ? '0' : '') + $('ewayrapid_saved_start_month').value).getTime() )
545
+ <= 0 ) {
546
+ $$('li.value_from_date')[0].insert({after: '<div style="" id="validate_from_date_message" ' +
547
+ 'class="validation-advice">From Date is invalid. It must be earlier than Expiration Date.</div>'});
548
+ $('ewayrapid_saved_start_month').addClassName('validation-failed');
549
+ $('ewayrapid_saved_start_year').addClassName('validation-failed');
550
+ $$('li.value_from_date')[0].addClassName('validation-error');
551
+ return;
552
+ }
553
+ }*/
554
+
555
+ // Waiting
556
+ $(obj).setStyle({'display': 'none'});
557
+ $('save-please-wait').setStyle({'display': 'block'});
558
+
559
+ // Get access code
560
+ new Ajax.Request('<?php echo Mage::getBaseUrl() ?>/ewayrapid/mycards/getAccessCode',
561
+ {
562
+ method: 'post',
563
+ parameters: $('form-validate').serialize(true),
564
+ onSuccess: function (transport) {
565
+ if (transport.responseText) {
566
+ var data = JSON.parse(transport.responseText);
567
+ if (typeof data == 'object') {
568
+
569
+ // Check login require
570
+ if (data.login != undefined) {
571
+ alert('Session has expired');
572
+ window.location = window.location.href;
573
+ }
574
+
575
+ if (typeof data.AccessCode != 'undefined' & data.AccessCode != null) {
576
+
577
+ var actionUrl = data.FormActionURL;
578
+ $('form-validate').setAttribute('action', actionUrl);
579
+ // Change card info
580
+ $('ewayrapid_saved_cc_owner').setAttribute('name', 'EWAY_CARDNAME');
581
+ <?php
582
+ // Change card name if not edited
583
+ if (!$this->isEdit()) {
584
+ echo "$('ewayrapid_saved_cc_number').setAttribute('name', 'EWAY_CARDNUMBER');";
585
+ }
586
+ ?>
587
+ $('ewayrapid_saved_expiration').setAttribute('name', 'EWAY_CARDEXPIRYMONTH');
588
+ $('ewayrapid_saved_expiration_yr').setAttribute('name', 'EWAY_CARDEXPIRYYEAR');
589
+
590
+ $('eway_accesscode').setValue(data.AccessCode);
591
+ $('form-validate').submit();
592
+ return;
593
+ }
594
+ else {
595
+ // Alert error code ERR-012
596
+ alert('An error occurred while connecting to payment gateway. Please try again later.!');
597
+ }
598
+ } else {
599
+ alert(transport.responseText)
600
+ }
601
+
602
+ // Remove style waiting
603
+ $(obj).setStyle({'display': 'block'});
604
+ $('save-please-wait').setStyle({'display': 'none'});
605
+ }
606
+ },
607
+ onFailure: function () {
608
+ alert('Something went wrong...')
609
+ }
610
+ });
611
+ return false;
612
+ }
613
+
614
+ //]]>
615
+ </script>
app/design/frontend/base/default/template/ewayrapid/customer/mycards.phtml ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
2
+ <?php
3
+ $_tokens = Mage::helper('ewayrapid/customer')->getActiveTokenList();
4
+ $_defaultToken = Mage::helper('ewayrapid/customer')->getDefaultToken();
5
+ $_helper = Mage::helper('ewayrapid');
6
+ ?>
7
+ <?php if($_helper->isSavedMethodEnabled()): ?>
8
+ <div class="page-title title-buttons">
9
+ <h1><?php echo $this->__('My Credit Cards') ?></h1>
10
+ <button type="button" title="<?php echo $this->__('Add New Credit Card') ?>" class="button"
11
+ onclick="window.location='<?php echo $this->getAddCreditCardUrl() ?>';">
12
+ <span><span><?php echo $this->__('Add New Credit Card') ?></span></span>
13
+ </button>
14
+ </div>
15
+ <?php if($_tokens): ?>
16
+ <table class="data-table" id="my-creditcards-table">
17
+ <col width="1" />
18
+ <col />
19
+ <col width="1" />
20
+ <col width="1" />
21
+ <thead>
22
+ <tr>
23
+ <th><?php echo $this->__('Credit Card Type') ?></th>
24
+ <th><?php echo $this->__('Credit Card Number') ?></th>
25
+ <th><?php echo $this->__('Expiration Date') ?></th>
26
+ <th>&nbsp;</th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+ <?php foreach ($_tokens as $_id => $_token): ?>
31
+ <?php /* @var Eway_Rapid31_Model_Customer_Token $_token */ ?>
32
+ <tr>
33
+ <td><span class="nobr"><?php echo $_token->getType() ? $_helper->getCcTypeName($_token->getType()) : $this->__('Unknown'); ?></span></td>
34
+ <td><?php echo $_token->getCard() ?> <?php if($_defaultToken == $_id):?><?php echo $this->__('(Default)') ?><?php endif; ?></td>
35
+ <td class="a-center"><?php echo $_token->getExpMonth() . ' / ' . $_token->getExpYear() ?></td>
36
+ <td>
37
+ <span class="nobr">
38
+ <?php if(Mage::getSingleton('ewayrapid/config')->canEditToken()): ?>
39
+ <?php if (Mage::helper('ewayrapid')->checkCardName($_token) != Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD) : ?>
40
+ <a href="<?php echo $this->getEditUrl($_id) ?>"><?php echo $this->__('Edit') ?></a>
41
+ <?php else: ?>
42
+ &nbsp; &nbsp; &nbsp; &nbsp;
43
+ <?php endif; ?>
44
+ <span class="separator">|</span>
45
+ <?php endif; ?>
46
+ <a href="<?php echo $this->getDeleteUrl($_id) ?>"
47
+ onclick="return confirm('<?php echo $this->__('Are you sure to delete this Credit Card?') ?>');"><?php echo $this->__('Delete') ?></a>
48
+ <?php if($_defaultToken != $_id): ?>
49
+ <span class="separator">|</span>
50
+ <a href="<?php echo $this->getUpdateDefaultUrl($_id) ?>"><?php echo $this->__('Set as Default') ?></a>
51
+ <?php endif; ?>
52
+ </span>
53
+ </td>
54
+ </tr>
55
+ <?php endforeach; ?>
56
+ </tbody>
57
+ </table>
58
+ <script type="text/javascript">decorateTable('my-creditcards-table');</script>
59
+ <?php else: ?>
60
+ <p><?php echo $this->__('You have no credit cards. <a href="%s">Click here</a> to create new one.', $this->getAddCreditCardUrl()); ?></p>
61
+ <?php endif ?>
62
+ <?php endif; ?>
app/design/frontend/base/default/template/ewayrapid/form/direct_notsaved.phtml ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ <li>
33
+ <label for="<?php echo $_code ?>_cc_owner" class="required"><em>*</em><?php echo $this->__('Name on Card') ?></label>
34
+ <div class="input-box">
35
+ <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')) ?>" />
36
+ </div>
37
+ </li>
38
+ <li>
39
+ <label for="<?php echo $_code ?>_cc_number" class="required"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
40
+ <div class="input-box">
41
+ <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*"/>
42
+ <input type="hidden" id="<?php echo $_code ?>_cc_type" name="payment[cc_type]" />
43
+ </div>
44
+ </li>
45
+ <li id="<?php echo $_code ?>_cc_type_exp_div">
46
+ <label for="<?php echo $_code ?>_expiration" class="required"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
47
+ <div class="input-box">
48
+ <div class="v-fix">
49
+ <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]" class="month validate-cc-exp required-entry">
50
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
51
+ <?php foreach ($this->getCcMonths() as $k=>$v): ?>
52
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
53
+ <?php endforeach ?>
54
+ </select>
55
+ </div>
56
+ <div class="v-fix">
57
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
58
+ <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]" class="year required-entry">
59
+ <?php foreach ($this->getCcYears() as $k=>$v): ?>
60
+ <option value="<?php echo $k?$k:'' ?>"<?php if($k==$_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
61
+ <?php endforeach ?>
62
+ </select>
63
+ </div>
64
+ </div>
65
+ </li>
66
+ <?php echo $this->getChildHtml() ?>
67
+ <?php if($this->hasVerification()): ?>
68
+ <li id="<?php echo $_code ?>_cc_type_cvv_div">
69
+ <label for="<?php echo $_code ?>_cc_cid" class="required"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
70
+ <div class="input-box">
71
+ <div class="v-fix">
72
+ <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*"/>
73
+ </div>
74
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
75
+ </div>
76
+ </li>
77
+ <?php endif; ?>
78
+ </ul>
79
+
80
+ <!--[if lt IE 10]>
81
+ <script>
82
+ $('p_method_ewayrapid_notsaved').observe('click', function () {
83
+ $('p_method_ewayrapid_notsaved').setAttribute('checked', 'true');
84
+ $('p_method_ewayrapid_saved').removeAttribute('checked');
85
+ });
86
+ </script>
87
+ <![endif]-->
app/design/frontend/base/default/template/ewayrapid/form/direct_saved.phtml ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ <li>
33
+ <div class="input-box">
34
+ <div class="v-fix">
35
+ <select id="ewayrapid_saved_token" name="payment[saved_token]" class="ewayrapid_saved_token">
36
+ <?php
37
+ $_tokens = $this->getTokenList();
38
+ $_defaultToken = isset($_tokens['default_token']) ? $_tokens['default_token'] : false;
39
+ ?>
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_saved_edit" class="ewayrapid_saved_edit" href="javascript:void(0);"><?php echo $this->__('Edit') ?></a>
53
+ </div>
54
+ <?php endif; ?>
55
+ </div>
56
+ </li>
57
+
58
+ <li class="saved_token_fields" style="display: none">
59
+ <label for="<?php echo $_code ?>_cc_owner" class="required"><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" style="display: none">
65
+ <label for="<?php echo $_code ?>_cc_number" class="required"><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 id="<?php echo $_code ?>_cc_type_exp_div" class="saved_token_fields" style="display: none">
77
+ <label for="<?php echo $_code ?>_expiration" class="required"><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" class="required"><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
+ </ul>
119
+
120
+ <script type="text/javascript">
121
+ var ewayPaymentToken = new EwayPaymentToken(
122
+ <?php echo $_tokens['tokens_json'] ?>,
123
+ <?php echo count($_tokens['tokens']) ?>,
124
+ false,
125
+ '<?php echo $this->__('Edit') ?>',
126
+ '<?php echo $this->__('Cancel edit') ?>'
127
+ )
128
+
129
+ $$('.help-disabled-cc a').each(function(element){
130
+ Event.observe(element, 'click', toggleToolTipCc);
131
+ });
132
+
133
+ function toggleToolTipCc(event){
134
+ if($('cc-help-tool-tip')){
135
+ $('cc-help-tool-tip').toggle();
136
+ }
137
+ Event.stop(event);
138
+ }
139
+ if($('cc-help-tool-tip-close')){
140
+ Event.observe($('cc-help-tool-tip-close'), 'click', toggleToolTipCc);
141
+ }
142
+
143
+ </script>
144
+
145
+ <!--[if lt IE 10]>
146
+ <script type="text/javascript">
147
+ $('p_method_ewayrapid_saved').observe('click', function () {
148
+ $('p_method_ewayrapid_saved').setAttribute('checked', 'true');
149
+ $('p_method_ewayrapid_notsaved').removeAttribute('checked');
150
+ });
151
+ </script>
152
+ <![endif]-->
app/design/frontend/base/default/template/ewayrapid/form/sharedpage_notsaved.phtml ADDED
@@ -0,0 +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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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/frontend/base/default/template/ewayrapid/form/sharedpage_saved.phtml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ <ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display: none">
31
+ <li>
32
+ <div class="input-box">
33
+ <div class="v-fix">
34
+ <select id="ewayrapid_saved_token" name="payment[saved_token]" class="ewayrapid_saved_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; ?>>
42
+ <?php echo $_token->getCard() ?>
43
+ </option>
44
+ <?php endforeach; ?>
45
+ </select>
46
+ </div>
47
+ <?php if(Mage::getSingleton('ewayrapid/config')->canEditToken() && 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
+ </li>
54
+
55
+
56
+ </ul>
57
+
58
+ <script type="text/javascript">
59
+ var ewayPaymentToken = new EwayPaymentToken(
60
+ <?php echo $_tokens['tokens_json'] ?>,
61
+ <?php echo count($_tokens['tokens']) ?>,
62
+ false,
63
+ '<?php echo $this->__('Edit') ?>',
64
+ '<?php echo $this->__('Cancel edit') ?>'
65
+ )
66
+
67
+ $$('.help-disabled-cc a').each(function(element){
68
+ Event.observe(element, 'click', toggleToolTipCc);
69
+ });
70
+
71
+ function toggleToolTipCc(event){
72
+ if($('cc-help-tool-tip')){
73
+ $('cc-help-tool-tip').toggle();
74
+ }
75
+ Event.stop(event);
76
+ }
77
+ if($('cc-help-tool-tip-close')){
78
+ Event.observe($('cc-help-tool-tip-close'), 'click', toggleToolTipCc);
79
+ }
80
+
81
+ </script>
app/design/frontend/base/default/template/ewayrapid/form/transparent_notsaved.phtml ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $_code = $this->getMethodCode();
3
+ ?>
4
+ <dl class="sp-methods" id="payment_form_<?php echo $_code ?>"
5
+ style="display:none; padding-left: 16px; padding-bottom: 8px; border: 1px solid rgb(193, 193, 193);">
6
+
7
+ <dt>
8
+ <input id="p_method_ewayrapid_transparent_mastercard"
9
+ value="<?php echo Eway_Rapid31_Model_Config::CREDITCARD_METHOD ?>" type="radio"
10
+ name="payment[transparent_notsaved]" title="Check / Money order" class="radio" autocomplete="off"
11
+ checked="checked">
12
+ <label for="p_method_ewayrapid_transparent_paypalexpress">Credit Card </label>
13
+
14
+ <ul class="form-list" id="ul_payment_form_<?php echo $_code ?>" style="display: block;">
15
+ <li>
16
+ <label for="<?php echo $_code ?>_cc_owner"
17
+ class="required"><em>*</em><?php echo $this->__('Name on Card') ?></label>
18
+ <div class="input-box">
19
+ <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry"
20
+ id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]"
21
+ value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>"/>
22
+ </div>
23
+ </li>
24
+ <li>
25
+ <label for="<?php echo $_code ?>_cc_number"
26
+ class="required"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
27
+
28
+ <div class="input-box">
29
+ <input type="text" id="<?php echo $_code ?>_cc_number"
30
+ name="payment[cc_number]"
31
+ title="<?php echo $this->__('Credit Card Number') ?>"
32
+ data-eway-encrypt-name="payment[cc_number]"
33
+ class="input-text validate-cc-number validate-cc-type-auto" value="" pattern="\d*"/>
34
+ <input type="hidden" id="<?php echo $_code ?>_cc_type" name="payment[cc_type]"/>
35
+ </div>
36
+ </li>
37
+ <li id="<?php echo $_code ?>_cc_type_exp_div">
38
+ <label for="<?php echo $_code ?>_expiration"
39
+ class="required"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
40
+
41
+ <div class="input-box">
42
+ <div class="v-fix">
43
+ <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]"
44
+ class="month validate-cc-exp required-entry">
45
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
46
+ <?php foreach ($this->getCcMonths() as $k => $v): ?>
47
+ <option
48
+ value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
49
+ <?php endforeach ?>
50
+ </select>
51
+ </div>
52
+ <div class="v-fix">
53
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
54
+ <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]"
55
+ class="year required-entry">
56
+ <?php foreach ($this->getCcYears() as $k => $v): ?>
57
+ <option
58
+ value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
59
+ <?php endforeach ?>
60
+ </select>
61
+ </div>
62
+ </div>
63
+ </li>
64
+ <?php echo $this->getChildHtml() ?>
65
+ <?php if ($this->hasVerification()): ?>
66
+ <li id="<?php echo $_code ?>_cc_type_cvv_div">
67
+ <label for="<?php echo $_code ?>_cc_cid"
68
+ class="required"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
69
+
70
+ <div class="input-box">
71
+ <div class="v-fix">
72
+ <input type="text" title="<?php echo $this->__('Card Verification Number') ?>"
73
+ name="payment[cc_cid]"
74
+ class="input-text cvv required-entry validate-cc-cvn" id="<?php echo $_code ?>_cc_cid"
75
+ data-eway-encrypt-name="payment[cc_cid]"
76
+ value="" pattern="\d*"/>
77
+ </div>
78
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
79
+ </div>
80
+ </li>
81
+ <?php endif; ?>
82
+ </ul>
83
+ </dt>
84
+
85
+ <?php if ($this->getEnablePaypalStandard()) { ?>
86
+ <dt>
87
+ <input id="p_method_ewayrapid_transparent_paypal"
88
+ value="<?php echo Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD ?>" type="radio"
89
+ name="payment[transparent_notsaved]" title="Paypal - eWAY (not saved)" class="radio"
90
+ autocomplete="off">
91
+ <label for="p_method_ewayrapid_transparent_paypal">Paypal Standard </label>
92
+ </dt>
93
+ <?php } ?>
94
+
95
+ <?php if ($this->getEnableMasterPass() && Mage::helper('ewayrapid/data')->getPaymentAction() == Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE) { ?>
96
+ <dt>
97
+ <input id="p_method_ewayrapid_transparent_masterpass"
98
+ value="<?php echo Eway_Rapid31_Model_Config::MASTERPASS_METHOD ?>" type="radio"
99
+ name="payment[transparent_notsaved]" title="MasterPass - eWAY (not saved)"
100
+ class="radio validate-one-required-by-name"
101
+ autocomplete="off">
102
+ <label for="p_method_ewayrapid_transparent_masterpass">MasterPass </label>
103
+ </dt>
104
+ <?php } ?>
105
+ </dl>
106
+
107
+ <script>
108
+
109
+ $('p_method_<?php echo $_code ?>').observe('click', function(){
110
+ $('ul_payment_form_<?php echo $_code ?>').show();
111
+ });
112
+
113
+ $$('.radio').each(function(rd) {
114
+ rd.observe('click', function(el) {
115
+ if(rd.getValue() == '<?php echo Eway_Rapid31_Model_Config::CREDITCARD_METHOD ?>') {
116
+ $('ul_payment_form_<?php echo $_code ?>').show();
117
+ } else if(rd.getValue() == '<?php echo Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD ?>'
118
+ || rd.getValue() == '<?php echo Eway_Rapid31_Model_Config::MASTERPASS_METHOD ?>') {
119
+ $('ul_payment_form_<?php echo $_code ?>').hide();
120
+ } else {
121
+ $('ul_payment_form_<?php echo $_code ?>').show();
122
+ }
123
+ });
124
+ });
125
+ </script>
126
+
127
+ <script>
128
+ $('p_method_ewayrapid_notsaved').observe('click', function () {
129
+ $('p_method_ewayrapid_notsaved').setAttribute('checked', 'true');
130
+ $('p_method_ewayrapid_saved').removeAttribute('checked');
131
+ });
132
+ </script>
app/design/frontend/base/default/template/ewayrapid/form/transparent_saved.phtml ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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 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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ $_tokens = $this->getTokenList();
30
+ ?>
31
+
32
+ <dl class="sp-methods" id="payment_form_<?php echo $_code ?>"
33
+ style="display:none; padding-left: 16px; padding-bottom: 8px; border: 1px solid rgb(193, 193, 193);">
34
+
35
+ <dt>
36
+ <ul class="form-list" style="display: block;">
37
+ <li>
38
+ <div class="eway-saved-div-box">
39
+ <label class="eway-saved-label-box"><?php echo $this->__('Saved Details') ?></label>
40
+ <select id="ewayrapid_saved_token" name="payment[saved_token]"
41
+ class="ewayrapid_saved_token eway-saved-select-box">
42
+ <?php
43
+ $_tokens = $this->getTokenList();
44
+ $_defaultToken = isset($_tokens['default_token']) ? $_tokens['default_token'] : false;
45
+ $_defaultLabel = $_firstLabel = '';
46
+ ?>
47
+ <?php foreach ($_tokens['tokens'] as $_key => $_token):
48
+ if(!$_firstLabel) $_firstLabel = $_token->getCard();
49
+ if($_key == $_defaultToken) :
50
+ $_defaultLabel = $_token->getCard();
51
+ endif;
52
+ ?>
53
+ <option value="<?php echo $_key ?>"
54
+ rel="<?php echo $this->checkCardName($_token); ?>"
55
+ <?php if ($_key == $_defaultToken): ?>selected="selected"<?php endif; ?>>
56
+ <?php echo $_token->getCard() ?>
57
+ </option>
58
+ <?php endforeach; ?>
59
+ </select>
60
+
61
+ <?php if(!$_defaultLabel) $_defaultLabel = strtolower($_firstLabel) == 'paypal' ? $_firstLabel : ''; ?>
62
+
63
+ <?php if (Mage::getSingleton('ewayrapid/config')->canEditToken() && count($_tokens['tokens']) > 1): ?>
64
+ <div class="v-fix eway-saved-edit-box">
65
+ <a style="<?php echo strtolower($_defaultLabel) === 'paypal' ? 'display:none;' : ''; ?>" id="ewayrapid_saved_edit" class="ewayrapid_saved_edit" href="javascript:void(0);"><?php echo $this->__('Edit') ?></a>
66
+ </div>
67
+ <?php endif; ?>
68
+ </div>
69
+ </li>
70
+ </ul>
71
+ </dt>
72
+
73
+
74
+ <dt id="eway_save_creditcard">
75
+ <input id="p_method_ewayrapid_saved_mastercard" rel="ul_payment_form_<?php echo $_code ?>"
76
+ value="<?php echo Eway_Rapid31_Model_Config::CREDITCARD_METHOD ?>" type="radio"
77
+ name="payment[transparent_saved]" title="Check / Money order" class="radio element_save_creditcard" autocomplete="off"
78
+ checked="checked"
79
+ />
80
+ <label for="p_method_ewayrapid_saved_mastercard" class="element_save_creditcard">Credit Card </label>
81
+
82
+ <ul class="form-list ul-form-list" id="ul_payment_form_<?php echo $_code ?>"
83
+ style="display: block;margin-left: 20px;">
84
+ <li class="element_save_creditcard">
85
+ <label for="<?php echo $_code ?>_cc_owner"
86
+ class="required"><em>*</em><?php echo $this->__('Name on Card') ?></label>
87
+ <div class="input-box">
88
+ <input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry"
89
+ id="<?php echo $_code ?>_cc_owner" name="payment[cc_owner]"
90
+ value="<?php echo $this->htmlEscape($this->getInfoData('cc_owner')) ?>"/>
91
+ </div>
92
+ </li>
93
+ <li class="element_save_creditcard">
94
+ <label for="<?php echo $_code ?>_cc_number"
95
+ class="required"><em>*</em><?php echo $this->__('Credit Card Number') ?></label>
96
+
97
+ <div class="input-box">
98
+ <input type="text" id="<?php echo $_code ?>_cc_number"
99
+ name="payment[cc_number]"
100
+ title="<?php echo $this->__('Credit Card Number') ?>"
101
+ data-eway-encrypt-name="payment[cc_number]"
102
+ class="input-text validate-cc-number validate-cc-type-auto" value="" pattern="\d*"/>
103
+ <input type="hidden" id="<?php echo $_code ?>_cc_type" name="payment[cc_type]"/>
104
+ </div>
105
+ </li>
106
+ <li id="<?php echo $_code ?>_cc_type_exp_div" class="element_save_creditcard">
107
+ <label for="<?php echo $_code ?>_expiration"
108
+ class="required"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
109
+
110
+ <div class="input-box">
111
+ <div class="v-fix">
112
+ <select id="<?php echo $_code ?>_expiration" name="payment[cc_exp_month]"
113
+ class="month validate-cc-exp required-entry">
114
+ <?php $_ccExpMonth = $this->getInfoData('cc_exp_month') ?>
115
+ <?php foreach ($this->getCcMonths() as $k => $v): ?>
116
+ <option
117
+ value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccExpMonth): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
118
+ <?php endforeach ?>
119
+ </select>
120
+ </div>
121
+ <div class="v-fix">
122
+ <?php $_ccExpYear = $this->getInfoData('cc_exp_year') ?>
123
+ <select id="<?php echo $_code ?>_expiration_yr" name="payment[cc_exp_year]"
124
+ class="year required-entry">
125
+ <?php foreach ($this->getCcYears() as $k => $v): ?>
126
+ <option
127
+ value="<?php echo $k ? $k : '' ?>"<?php if ($k == $_ccExpYear): ?> selected="selected"<?php endif ?>><?php echo $v ?></option>
128
+ <?php endforeach ?>
129
+ </select>
130
+ </div>
131
+ </div>
132
+ </li>
133
+ <?php echo $this->getChildHtml() ?>
134
+ <?php if ($this->hasVerification()): ?>
135
+ <li id="<?php echo $_code ?>_cc_type_cvv_div" style="<?php echo strtolower($_defaultLabel) == 'paypal' ? 'display:none;' : '' ?>">
136
+ <label for="<?php echo $_code ?>_cc_cid"
137
+ class="required"><em>*</em><?php echo $this->__('Card Verification Number') ?></label>
138
+
139
+ <div class="input-box">
140
+ <div class="v-fix" id="v-fix-change">
141
+ <input type="text" title="<?php echo $this->__('Card Verification Number') ?>"
142
+ name="payment[cc_cid]"
143
+ disabled="disabled"
144
+ class="input-text cvv required-entry validate-cc-cvn" id="<?php echo $_code ?>_cc_cid"
145
+ data-eway-encrypt-name="payment[cc_cid]"
146
+ value="" pattern="\d*"/>
147
+ </div>
148
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
149
+ </div>
150
+ </li>
151
+ <?php if ($this->getIsRecurring()) { ?>
152
+ <li>
153
+ <p>I authorize <?php echo Mage::app()->getStore()->getName(); ?> to charge the available balance
154
+ in my credit card for the future payments of this order. To make a change, I can go to
155
+ <a href="<?php echo Mage::getUrl('checkout/cart'); ?>">Cart</a>
156
+ </p>
157
+ <input type="checkbox" name="recurring-agree" class="recurring-agree required-entry"/><label class="lable-for-recurring" for="">Agree</label>
158
+ </li>
159
+ <?php } ?>
160
+ <?php endif; ?>
161
+ </ul>
162
+ </dt>
163
+
164
+ <?php if ($this->getEnablePaypalStandard()) { ?>
165
+ <dt id="eway_save_paypal" style="display: none">
166
+ <input id="p_method_ewayrapid_saved_transparent_paypal" rel="payment_form_paypal_saved"
167
+ value="<?php echo Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD ?>" type="radio"
168
+ name="payment[transparent_saved]" title="Paypal - eWAY (saved)" class="radio" autocomplete="off">
169
+ <label for="p_method_ewayrapid_saved_transparent_paypal">Paypal Standard </label>
170
+ </dt>
171
+ <?php } ?>
172
+
173
+ <?php if ($this->getEnableMasterPass() && Mage::helper('ewayrapid/data')->getPaymentAction() == Eway_Rapid31_Model_Method_Notsaved::ACTION_AUTHORIZE_CAPTURE) { ?>
174
+ <dt id="eway_save_masterpass" style="display: none">
175
+ <input id="p_method_ewayrapid_transparent_masterpass" rel="payment_form_masterpass_saved"
176
+ value="<?php echo Eway_Rapid31_Model_Config::MASTERPASS_METHOD ?>" type="radio"
177
+ name="payment[transparent_saved]" title="MasterPass - eWAY (saved)" class="radio" autocomplete="off">
178
+ <label for="p_method_ewayrapid_transparent_masterpass">MasterPass </label>
179
+ </dt>
180
+ <?php } ?>
181
+ </dl>
182
+
183
+ <script type="text/javascript">
184
+
185
+ var ewayPaymentToken = new EwayPaymentToken(
186
+ <?php echo $_tokens['tokens_json'] ?>,
187
+ <?php echo count($_tokens['tokens']) ?>,
188
+ false,
189
+ '<?php echo $this->__('Edit') ?>',
190
+ '<?php echo $this->__('Cancel edit') ?>'
191
+ );
192
+
193
+ $$('.help-disabled-cc a').each(function (element) {
194
+ Event.observe(element, 'click', toggleToolTipCc);
195
+ });
196
+
197
+ function toggleToolTipCc(event) {
198
+ if ($('cc-help-tool-tip')) {
199
+ $('cc-help-tool-tip').toggle();
200
+ }
201
+ Event.stop(event);
202
+ }
203
+ if ($('cc-help-tool-tip-close')) {
204
+ Event.observe($('cc-help-tool-tip-close'), 'click', toggleToolTipCc);
205
+ }
206
+
207
+ var _tokenCount = <?php echo count($_tokens['tokens']); ?>;
208
+ //console.log(_tokenCount);
209
+ var _defaultLabel = "<?php echo strtolower($_defaultLabel); ?>";
210
+ //console.log('default Label: ' + _defaultLabel);
211
+ if(_defaultLabel == 'paypal') {
212
+ $('ewayrapid_saved_cc_type_cvv_div') && $('ewayrapid_saved_cc_type_cvv_div').hide();
213
+ $('ewayrapid_saved_edit') && $('ewayrapid_saved_edit').hide();
214
+ $$('.element_save_creditcard').each(function(el) {
215
+ el.hide();
216
+ });
217
+ } else if((_defaultLabel == "" || _defaultLabel == null) && _tokenCount < 2) {
218
+ addNew();
219
+ } else {
220
+ $$('.element_save_creditcard').each(function(el) {
221
+ el.hide();
222
+ });
223
+ }
224
+
225
+ $$('.radio').each(function (el) {
226
+ var _rel = $(el).readAttribute('rel');
227
+ //console.log(_rel);
228
+ if (_rel != '' && _rel != null) {
229
+ $(el).observe('click', function () {
230
+ $$('.ul-form-list').each(function (rd) {
231
+ rd.hide();
232
+ });
233
+ $(_rel) && $(_rel).show();
234
+ $(_rel) && $(_rel).firstElementChild.show();
235
+ });
236
+ }
237
+ });
238
+
239
+ $('ewayrapid_saved_edit') && $('ewayrapid_saved_edit').observe('click', function (elment) {
240
+ //console.log('Edit click: ' + this.innerHTML);
241
+ $('p_method_ewayrapid_saved_mastercard') && ($('p_method_ewayrapid_saved_mastercard').checked = true);
242
+ $('p_method_ewayrapid_saved_transparent_paypal') && ($('p_method_ewayrapid_saved_transparent_paypal').checked = false);
243
+ $('p_method_ewayrapid_transparent_masterpass') && ($('p_method_ewayrapid_transparent_masterpass').checked = false);
244
+
245
+ $('ul_payment_form_ewayrapid_saved') && $('ul_payment_form_ewayrapid_saved').show();
246
+ $('ewayrapid_saved_cc_type_cvv_div') && $('ewayrapid_saved_cc_type_cvv_div').show();
247
+ if (this.innerHTML == "Edit") {
248
+ $('eway_save_masterpass') && $('eway_save_masterpass').hide();
249
+ $('eway_save_paypal') && $('eway_save_paypal').hide();
250
+
251
+ $$('.element_save_creditcard').each(function(el) {
252
+ el.hide();
253
+ });
254
+ } else {
255
+ $('eway_save_masterpass') && $('eway_save_masterpass').hide(150);
256
+ $('eway_save_paypal') && $('eway_save_paypal').hide(150);
257
+
258
+ $('ul_payment_form_<?php echo $_code ?>') && $('ul_payment_form_<?php echo $_code ?>').show(150);
259
+
260
+ $$('.element_save_creditcard').each(function(el) {
261
+ el.show();
262
+ });
263
+ }
264
+ });
265
+
266
+ $('ewayrapid_saved_token').observe('change', function () {
267
+ //console.log('Value: ' + this.getValue());
268
+ var _ctype = $('ewayrapid_saved_token')[this.selectedIndex].readAttribute('rel');
269
+ //console.log(_ctype);
270
+ if (this.getValue() == 'new') {
271
+ addNew();
272
+ } else {
273
+ edit(_ctype);
274
+ }
275
+ });
276
+
277
+ function addNew() {
278
+ $('<?php echo $_code ?>_cc_number') && $('<?php echo $_code ?>_cc_number').writeAttribute('disabled', false);
279
+ $('eway_save_masterpass') && $('eway_save_masterpass').show(150);
280
+ $('eway_save_paypal') && $('eway_save_paypal').show(150);
281
+ $('ul_payment_form_<?php echo $_code ?>') && $('ul_payment_form_<?php echo $_code ?>').show(150);
282
+
283
+ $('ewayrapid_saved_edit') && $('ewayrapid_saved_edit').hide();
284
+
285
+ $$('.element_save_creditcard').each(function(el) {
286
+ el.show();
287
+ });
288
+ $('ul_payment_form_ewayrapid_saved') && $('ul_payment_form_ewayrapid_saved').show();
289
+ $('ewayrapid_saved_cc_type_cvv_div') && $('ewayrapid_saved_cc_type_cvv_div').show();
290
+ }
291
+
292
+ function edit(_ctype) {
293
+ $$('.element_save_creditcard').each(function(el) {
294
+ el.hide();
295
+ });
296
+
297
+ $('eway_save_masterpass') && $('eway_save_masterpass').hide();
298
+ $('eway_save_paypal') && $('eway_save_paypal').hide();
299
+ $('<?php echo $_code ?>_cc_number') && $('<?php echo $_code ?>_cc_number').writeAttribute('disabled', 'disabled');
300
+
301
+
302
+ if('<?php echo Eway_Rapid31_Model_Config::CREDITCARD_METHOD ?>' != _ctype) {
303
+ $('ewayrapid_saved_cc_type_cvv_div') && $('ewayrapid_saved_cc_type_cvv_div').hide();
304
+ $('ewayrapid_saved_edit') && $('ewayrapid_saved_edit').hide();
305
+ } else {
306
+ $('p_method_ewayrapid_saved_mastercard') && ($('p_method_ewayrapid_saved_mastercard').checked = true);
307
+ $('p_method_ewayrapid_saved_transparent_paypal') && ($('p_method_ewayrapid_saved_transparent_paypal').checked = false);
308
+ $('p_method_ewayrapid_transparent_masterpass') && ($('p_method_ewayrapid_transparent_masterpass').checked = false);
309
+
310
+ $('ul_payment_form_ewayrapid_saved') && $('ul_payment_form_ewayrapid_saved').show();
311
+ $('ewayrapid_saved_cc_type_cvv_div') && $('ewayrapid_saved_cc_type_cvv_div').show();
312
+ $('ewayrapid_saved_edit') && $('ewayrapid_saved_edit').show();
313
+ }
314
+ }
315
+ </script>
316
+
317
+ <script type="text/javascript">
318
+ $('p_method_ewayrapid_saved').observe('click', function () {
319
+ $('p_method_ewayrapid_saved').setAttribute('checked', 'true');
320
+ $('p_method_ewayrapid_notsaved').removeAttribute('checked');
321
+ });
322
+ </script>
app/design/frontend/base/default/template/ewayrapid/info/direct_notsaved.phtml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ <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
+ </div>
app/design/frontend/base/default/template/ewayrapid/info/direct_saved.phtml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ <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
+ </div>
app/design/frontend/base/default/template/ewayrapid/info/sharedpage_notsaved.phtml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ <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
+ </div>
app/design/frontend/base/default/template/ewayrapid/info/sharedpage_saved.phtml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ <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
+ </div>
app/design/frontend/base/default/template/ewayrapid/info/transparent_notsaved.phtml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
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
+ <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
+ </div>
app/design/frontend/base/default/template/ewayrapid/js.phtml ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php $_config = Mage::getSingleton('ewayrapid/config'); ?>
2
+ <?php $_backend = Mage::helper('ewayrapid')->isBackendOrder(); ?>
3
+ <?php $_checkoutExtension = $this->getCheckoutExtension(); ?>
4
+ <?php if($_config->isDirectConnection() || $_backend): ?>
5
+ <script type="text/javascript">
6
+ EwayPayment.supportCardTypes = <?php echo json_encode($_config->getSupportedCardTypes()) ?>;
7
+ <?php if(Mage::helper('ewayrapid')->isBackendOrder()): ?>
8
+ var ewayPayment = new EwayPayment($('edit_form'), '<?php echo $_config->getEncryptionKey() ?>');
9
+ AdminOrder.prototype.submit = ewayPayment.submitAdminOrder;
10
+ <?php else: ?>
11
+ <?php switch($_checkoutExtension):
12
+ case 'OneStepCheckout': // OneStepCheckout extension ?>
13
+ document.observe("dom:loaded", function() {
14
+ var ewayPayment = new EwayPayment($('onestepcheckout-form'), '<?php echo $_config->getEncryptionKey() ?>');
15
+ Payment.prototype.switchMethod = ewayPayment.OneStepCheckout.switchMethod;
16
+ if(payment.currentMethod) {
17
+ payment.switchMethod(payment.currentMethod);
18
+ }
19
+ $('onestepcheckout-form').submit = function() {
20
+ form = eCrypt.doEncrypt();
21
+ form.submit();
22
+ };
23
+ });
24
+ <?php break; ?>
25
+ <?php case 'FireCheckout': // FireCheckout extension ?>
26
+ document.observe("dom:loaded", function() {
27
+ var ewayPayment = new EwayPayment($('firecheckout-form'), '<?php echo $_config->getEncryptionKey() ?>');
28
+ if(typeof FireCheckout.prototype.ewayOldSave == "undefined") {
29
+ FireCheckout.prototype.ewayOldSave = FireCheckout.prototype.save;
30
+ FireCheckout.prototype.save = ewayPayment.FireCheckout.save;
31
+ }
32
+ });
33
+ <?php break; ?>
34
+ <?php case 'IWDOnePageCheckout': // FireCheckout extension ?>
35
+ document.observe("dom:loaded", function() {
36
+ var ewayPayment = new EwayPayment($('co-payment-form'), '<?php echo $_config->getEncryptionKey() ?>');
37
+ if(typeof IWD.OPC.ewayOldSavePayment == "undefined") {
38
+ IWD.OPC.ewayOldSavePayment = IWD.OPC.savePayment;
39
+ IWD.OPC.ewayOldSaveOrder = IWD.OPC.saveOrder;
40
+ IWD.OPC.savePayment = ewayPayment.IWDOnePageCheckout.savePayment;
41
+ IWD.OPC.saveOrder = ewayPayment.IWDOnePageCheckout.saveOrder;
42
+ }
43
+ });
44
+ <?php break; ?>
45
+ <?php case 'MultiShippingAddress': // Magento default multi shipping address ?>
46
+ var ewayPayment = new EwayPayment($('multishipping-billing-form'), '<?php echo $_config->getEncryptionKey() ?>');
47
+ <?php break; ?>
48
+ <?php default: // Magento default one page checkout ?>
49
+ var ewayPayment = new EwayPayment($('co-payment-form'), '<?php echo $_config->getEncryptionKey() ?>');
50
+ Payment.prototype.save = ewayPayment.savePaymentWithEncryption;
51
+ Review.prototype.save = ewayPayment.saveReviewWithEncryption;
52
+ <?php endswitch; ?>
53
+ <?php endif; ?>
54
+ </script>
55
+ <?php endif; ?>
56
+
57
+ <?php if($_config->isTransparentConnection() && !$_backend): ?>
58
+ <script type="text/javascript">
59
+ var creditcard = '<?php echo Eway_Rapid31_Model_Config::CREDITCARD_METHOD ?>';
60
+ var ewayPayment = new EwayPayment($('co-payment-form'), '<?php echo $_config->getEncryptionKey() ?>');
61
+ Payment.prototype.save = ewayPayment.savePaymentWithTransEncryption;
62
+ Review.prototype.save = function() {
63
+ $('review-please-wait').show();
64
+ $('review-buttons-container').down('button').hide();
65
+ var request = new Ajax.Request(
66
+ '<?php echo Mage::getUrl('ewayrapid/transparent/build'); ?>',
67
+ {
68
+ method:'post',
69
+ onComplete: {
70
+
71
+ },
72
+ onSuccess: function(response) {
73
+ if(response.responseText != '0') {
74
+ window.location = response.responseText;
75
+ }
76
+ return false;
77
+ },
78
+ onFailure: {
79
+
80
+ }
81
+ }
82
+ );
83
+ }
84
+ </script>
85
+ <?php endif; ?>
app/design/frontend/base/default/template/ewayrapid/redirect/review.phtml ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $billingAddress = $this->getBillingAddress();
4
+ $shippingAddress = $this->getShippingAddress();
5
+ ?>
6
+
7
+
8
+ <div class="main">
9
+ <div class="col-main">
10
+ <div class="page-title">
11
+ <h1>Review Order</h1>
12
+ </div>
13
+ <h2 class="sub-title">
14
+ Please choice your shipping method
15
+ </h2>
16
+
17
+ <div class="paypal-review-order">
18
+
19
+ <div class="info-set col2-set">
20
+ <div class="col-1" id="billing-address">
21
+ <h2 class="legend">Billing Address</h2>
22
+ <fieldset>
23
+ <ul class="form-list form-list-narrow">
24
+ <li id="billing-address-form" class="address-form">
25
+ <fieldset>
26
+ <ul>
27
+ <li class="fields">
28
+ <div class="customer-name">
29
+ <div class="field name-firstname">
30
+ <label for="billing:firstname"
31
+ class="required"><?php echo $this->__('First Name') ?></label>
32
+
33
+ <div class="input-box">
34
+ <input readonly type="text" id="" name=""
35
+ value="<?php echo $billingAddress ? $billingAddress->getFirstname() : ''; ?>"
36
+ title="First Name" maxlength="255" class="input-text">
37
+ </div>
38
+ </div>
39
+ <div class="field name-lastname">
40
+ <label for="billing:lastname"
41
+ class="required"><?php echo $this->__('Last Name') ?></label>
42
+
43
+ <div class="input-box">
44
+ <input readonly type="text" id="billing:lastname" name=""
45
+ value="<?php echo $billingAddress ? $billingAddress->getLastname() : ''; ?>"
46
+ title="<?php echo $this->__('Last Name') ?>" maxlength="255"
47
+ class="input-text">
48
+ </div>
49
+ </div>
50
+ </div>
51
+ </li>
52
+ <li class="fields">
53
+ <div class="field">
54
+ <label for="billing:company"><?php echo $this->__('Company') ?></label>
55
+
56
+ <div class="input-box">
57
+ <input readonly type="text" id="billing:company" name="billing[company]"
58
+ value="<?php echo $billingAddress ? $billingAddress->getCompany() : ''; ?>"
59
+ title="<?php echo $this->__('Company') ?>" class="input-text">
60
+ </div>
61
+ </div>
62
+ </li>
63
+ <li class="wide">
64
+ <label for="billing:street1" class="required"><?php echo $this->__('Address') ?></label>
65
+
66
+ <div class="input-box">
67
+ <input readonly type="text" title="Street Address" name="billing[street][]"
68
+ id="billing:street1"
69
+ value="<?php echo $billingAddress ? $billingAddress->getStreet1() : ''; ?>"
70
+ class="input-text">
71
+ </div>
72
+ </li>
73
+ <li class="add-field">
74
+ <div class="input-box">
75
+ <input readonly type="text" title="Street Address 2" name="billing[street][]"
76
+ id="billing:street2"
77
+ value="<?php echo $billingAddress ? $billingAddress->getStreet2() : ''; ?>"
78
+ class="input-text">
79
+ </div>
80
+ </li>
81
+ <li class="fields">
82
+ <div class="field">
83
+ <label for="billing:city" class="required"><?php echo $this->__('City') ?></label>
84
+
85
+ <div class="input-box">
86
+ <input readonly type="text" title="City" name="billing[city]"
87
+ value="<?php echo $billingAddress ? $billingAddress->getCity() : ''; ?>"
88
+ class="input-text required-entry" id="billing:city">
89
+ </div>
90
+ </div>
91
+ <div class="field">
92
+ <label for="billing:region_id"
93
+ class=""><?php echo $this->__('State/Province') ?></label>
94
+
95
+ <div class="input-box">
96
+ <input readonly type="text" id="shipping:region" name="shipping[region]"
97
+ value="<?php echo $billingAddress ? $billingAddress->getState() : ''; ?>"
98
+ title="State/Province" class="input-text regions" style="">
99
+ </div>
100
+ </div>
101
+ </li>
102
+ <li class="fields">
103
+ <div class="field">
104
+ <label for="billing:postcode"
105
+ class="required"><?php echo $this->__('Zip/Postal Code') ?></label>
106
+
107
+ <div class="input-box">
108
+ <input readonly type="text" title="Zip/Postal Code" name="billing[postcode]"
109
+ id="billing:postcode"
110
+ value="<?php echo $billingAddress ? $billingAddress->getPostalCode() : ''; ?>"
111
+ class="input-text validate-zip-international required-entry">
112
+ </div>
113
+ </div>
114
+ <div class="field">
115
+ <label for="billing:country_id"
116
+ class="required"><?php echo $this->__('Country') ?></label>
117
+
118
+ <div class="input-box">
119
+ <select name="billing[country_id]" id="billing:country_id" class="validate-select"
120
+ title="<?php echo $this->__('Country') ?>">
121
+ <option value=""
122
+ selected="selected"><?php echo $billingAddress ? Mage::app()->getLocale()->getCountryTranslation($billingAddress->getCountryId()) : ''; ?></option>
123
+ </select>
124
+ </div>
125
+ </div>
126
+ </li>
127
+ <li class="fields">
128
+ <div class="field">
129
+ <label for="billing:telephone"
130
+ class="required"><?php echo $this->__('Telephone') ?></label>
131
+
132
+ <div class="input-box">
133
+ <input readonly type="text" name=""
134
+ value="<?php echo $billingAddress ? $billingAddress->getTelephone() : ''; ?>"
135
+ title="Telephone"
136
+ class="input-text" id="billing:telephone">
137
+ </div>
138
+ </div>
139
+ <div class="field">
140
+ <label for="billing:fax"><?php echo $this->__('Fax') ?></label>
141
+
142
+ <div class="input-box">
143
+ <input readonly type="text" name=""
144
+ value="<?php echo $billingAddress ? $billingAddress->getFax() : ''; ?>"
145
+ title="Fax" class="input-text"
146
+ id="billing:fax">
147
+ </div>
148
+ </div>
149
+ </li>
150
+
151
+ </ul>
152
+ </fieldset>
153
+ </li>
154
+ </ul>
155
+ </fieldset>
156
+ </div>
157
+ <div class="col-2" id="shipping-address">
158
+ <h2 class="legend">Shipping Address</h2>
159
+ <fieldset>
160
+ <ul class="form-list form-list-narrow">
161
+ <li id="billing-address-form" class="address-form">
162
+ <fieldset>
163
+ <ul>
164
+ <li class="fields">
165
+ <div class="customer-name">
166
+ <div class="field name-firstname">
167
+ <label for="billing:firstname"
168
+ class="required"><?php echo $this->__('First Name') ?></label>
169
+
170
+ <div class="input-box">
171
+ <input readonly type="text" id="" name=""
172
+ value="<?php echo $shippingAddress ? $shippingAddress->getFirstname() : ''; ?>"
173
+ title="First Name" maxlength="255" class="input-text">
174
+ </div>
175
+ </div>
176
+ <div class="field name-lastname">
177
+ <label for="billing:lastname"
178
+ class="required"><?php echo $this->__('Last Name') ?></label>
179
+
180
+ <div class="input-box">
181
+ <input readonly type="text" id="billing:lastname" name=""
182
+ value="<?php echo $shippingAddress ? $shippingAddress->getLastname() : ''; ?>"
183
+ title="<?php echo $this->__('Last Name') ?>" maxlength="255"
184
+ class="input-text">
185
+ </div>
186
+ </div>
187
+ </div>
188
+ </li>
189
+ <li class="fields">
190
+ <div class="field">
191
+ <label for="billing:company"><?php echo $this->__('Company') ?></label>
192
+
193
+ <div class="input-box">
194
+ <input readonly type="text" id="billing:company" name="billing[company]"
195
+ value="<?php echo $shippingAddress ? $shippingAddress->getCompany() : ''; ?>"
196
+ title="<?php echo $this->__('Company') ?>" class="input-text">
197
+ </div>
198
+ </div>
199
+ </li>
200
+ <li class="wide">
201
+ <label for="billing:street1" class="required"><?php echo $this->__('Address') ?></label>
202
+
203
+ <div class="input-box">
204
+ <input readonly type="text" title="Street Address" name="billing[street][]"
205
+ id="billing:street1"
206
+ value="<?php echo $shippingAddress ? $shippingAddress->getStreet1() : ''; ?>"
207
+ class="input-text">
208
+ </div>
209
+ </li>
210
+ <li class="add-field">
211
+ <div class="input-box">
212
+ <input readonly type="text" title="Street Address 2" name="billing[street][]"
213
+ id="billing:street2"
214
+ value="<?php echo $shippingAddress ? $shippingAddress->getStreet2() : ''; ?>"
215
+ class="input-text">
216
+ </div>
217
+ </li>
218
+ <li class="fields">
219
+ <div class="field">
220
+ <label for="billing:city" class="required"><?php echo $this->__('City') ?></label>
221
+
222
+ <div class="input-box">
223
+ <input readonly type="text" title="City" name="billing[city]"
224
+ value="<?php echo $shippingAddress ? $shippingAddress->getCity() : ''; ?>"
225
+ class="input-text required-entry" id="billing:city">
226
+ </div>
227
+ </div>
228
+ <div class="field">
229
+ <label for="billing:region_id"
230
+ class=""><?php echo $this->__('State/Province') ?></label>
231
+
232
+ <div class="input-box">
233
+ <input readonly type="text" id="shipping:region" name="shipping[region]"
234
+ value="<?php echo $shippingAddress ? $shippingAddress->getState() : ''; ?>"
235
+ title="State/Province" class="input-text regions" style="">
236
+ </div>
237
+ </div>
238
+ </li>
239
+ <li class="fields">
240
+ <div class="field">
241
+ <label for="billing:postcode"
242
+ class="required"><?php echo $this->__('Zip/Postal Code') ?></label>
243
+
244
+ <div class="input-box">
245
+ <input readonly type="text" title="Zip/Postal Code" name="billing[postcode]"
246
+ id="billing:postcode"
247
+ value="<?php echo $shippingAddress ? $shippingAddress->getPostalCode() : ''; ?>"
248
+ class="input-text validate-zip-international required-entry">
249
+ </div>
250
+ </div>
251
+ <div class="field">
252
+ <label for="billing:country_id"
253
+ class="required"><?php echo $this->__('Country') ?></label>
254
+
255
+ <div class="input-box">
256
+ <select name="billing[country_id]" id="billing:country_id" class="validate-select"
257
+ title="<?php echo $this->__('Country') ?>">
258
+ <option value=""
259
+ selected="selected"><?php echo $shippingAddress ? Mage::app()->getLocale()->getCountryTranslation($shippingAddress->getCountryId()) : ''; ?></option>
260
+ </select>
261
+ </div>
262
+ </div>
263
+ </li>
264
+ <li class="fields">
265
+ <div class="field">
266
+ <label for="billing:telephone"
267
+ class="required"><?php echo $this->__('Telephone') ?></label>
268
+
269
+ <div class="input-box">
270
+ <input readonly type="text" name="billing[telephone]"
271
+ value="<?php echo $shippingAddress ? $shippingAddress->getTelephone() : ''; ?>"
272
+ title="Telephone"
273
+ class="input-text required-entry" id="billing:telephone">
274
+ </div>
275
+ </div>
276
+ <div class="field">
277
+ <label for="billing:fax"><?php echo $this->__('Fax') ?></label>
278
+
279
+ <div class="input-box">
280
+ <input readonly type="text" name="billing[fax]"
281
+ value="<?php echo $shippingAddress ? $shippingAddress->getFax() : ''; ?>"
282
+ title="Fax" class="input-text"
283
+ id="billing:fax">
284
+ </div>
285
+ </div>
286
+ </li>
287
+
288
+ </ul>
289
+ </fieldset>
290
+ </li>
291
+ </ul>
292
+ </fieldset>
293
+ </div>
294
+ </div>
295
+
296
+ <div class="info-set col2-set">
297
+ <div class="col-2">
298
+ <div class="box paypal-shipping-method">
299
+ <div class="box-title">
300
+ <h3>Shipping Method</h3>
301
+ </div>
302
+ <form method="post" id="order_review_form" action="">
303
+ <input type="hidden" name="EWAY_ACCESSCODE" value="<?php echo $this->getAccessCode() ?>"/>
304
+ <input type="hidden" name="EWAY_PAYMENTTYPE" value="paypal"/>
305
+ <input type="hidden" name="EWAY_ISREFERENCETRANSACTION" value="false"/>
306
+
307
+ <div class="box-content">
308
+ <fieldset id="shipping-method-container">
309
+ <select name="shipping_method" id="shipping_method" style="width:250px;"
310
+ class="required-entry" <?php echo $this->getCurrentRateCode() ? 'disabled' : '' ?>>
311
+ <?php if (!$this->getCurrentRateCode()): ?>
312
+ <option value=""><?php echo $this->__('Please select a shipping method...') ?></option>
313
+ <?php endif; ?>
314
+
315
+ <?php foreach ($this->getRates() as $code => $rates) { ?>
316
+ <optgroup label="<?php echo $this->escapeHtml($this->getCarrierName($code)) ?>"
317
+ style="font-style:normal;">
318
+ <?php foreach ($rates as $rate): ?>
319
+ <option
320
+ value="<?php echo $rate->getCode(); ?>" <?php echo ($this->getCurrentRateCode() === $rate) ? ' selected="selected"' : ''; ?>>
321
+ <?php echo $rate->getMethodTitle() . ' - ' . $rate->getPrice(); ?>
322
+ </option>
323
+ <?php endforeach; ?>
324
+ </optgroup>
325
+ <?php } ?>
326
+ </select>
327
+
328
+ <?php if ($this->getCurrentRateCode()) { ?>
329
+ <input type="hidden" name="shipping_method"
330
+ value="<?php echo $this->getCurrentRateCode()->getCode() ?>"/>
331
+ <?php } ?>
332
+ </fieldset>
333
+ <div style="display: none;" id="shipping_method_update">
334
+ <p><?php echo $this->__('Please update order data to get shipping methods and rates') ?></p>
335
+ </div>
336
+ </div>
337
+
338
+ </form>
339
+ </div>
340
+ </div>
341
+ </div>
342
+
343
+ <div class="buttons-set buttons-set-order" id="review-buttons-container">
344
+ <button type="button" id="review_button" value="<?php echo $this->__('Continue') ?>" class="button btn-checkout">
345
+ <span><span><?php echo $this->__('Continue') ?></span></span>
346
+ </button>
347
+
348
+ <span class="please-wait" id="review-please-wait" style="display: none;">
349
+ <img src="http://eway.local/skin/frontend/default/default/images/opc-ajax-loader.gif"
350
+ alt="Submitting order information..." title="Submitting order information..." class="v-middle"> Submitting order information...
351
+ </span>
352
+ </div>
353
+
354
+ </div>
355
+ <script type="text/javascript">
356
+
357
+ $("review_button").observe('click', function () {
358
+ var validator = new Validation('order_review_form');
359
+ if (validator.validate()) {
360
+ $(this).hide();
361
+ $("review-please-wait").show();
362
+ var request = new Ajax.Request(
363
+ '<?php echo $this->getActionUrl(); ?>',
364
+ {
365
+ method: 'post',
366
+ onComplete: {},
367
+ parameters: $("order_review_form").serialize(),
368
+ onSuccess: function (response) {
369
+ if (response) {
370
+ var json = response.responseText.evalJSON();
371
+ $("order_review_form").insert(json.input_post);
372
+ $("order_review_form").writeAttribute("action", json.form_action);
373
+ $("order_review_form").submit();
374
+ }
375
+ return true;
376
+ },
377
+ onFailure: {}
378
+ }
379
+ );
380
+ }
381
+ return false;
382
+ });
383
+ </script>
384
+ </div>
385
+ </div>
app/design/frontend/base/default/template/ewayrapid/redirect/transparent.phtml ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ $_code = $this->methodPayment;
29
+ if (!$_code) $_code = 'ewayrapid_notsaved';
30
+
31
+ $infoCard = Mage::getSingleton('core/session')->getInfoCard();;
32
+ if (is_numeric($this->savedToken)) {
33
+ $infoCardData = Mage::helper('ewayrapid/customer')->getTokenById($this->savedToken);
34
+ if($infoCard->getOwner()) {
35
+ $infoCardData->setOwner($infoCard->getOwner());
36
+ }
37
+
38
+ if($infoCard->getExpMonth()) {
39
+ $infoCardData->setExpMonth($infoCard->getExpMonth());
40
+ }
41
+
42
+ if($infoCard->getExpYear()) {
43
+ $infoCardData->setExpYear($infoCard->getExpYear());
44
+ }
45
+
46
+ if($infoCard->getCid()) {
47
+ $infoCardData->setCid($infoCard->getCid());
48
+ }
49
+ $infoCard = $infoCardData;
50
+ }
51
+
52
+ ?>
53
+
54
+ <form method="POST" action="<?php echo Mage::getSingleton('core/session')->getFormActionUrl(); ?>" name="transparent_card" id="transparent_card">
55
+ <h4><span class="please-wait" id="payment-please-wait" style="display: block;float: left;"><img
56
+ src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif'); ?>" alt="Connecting..."
57
+ title="Connecting..." class="v-middle"> Connecting...</span></h4>
58
+
59
+ <input type="hidden" name="EWAY_ACCESSCODE" value="<?php echo $this->getAccessCode(); ?>"/>
60
+ <input type="hidden" name="EWAY_PAYMENTTYPE" value="<?php echo $this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD ? 'paypal' : $this->transMethod; ?>"/>
61
+ <input type="hidden" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry"
62
+ id="EWAY_CARDNAME" name="EWAY_CARDNAME"
63
+ value="<?php echo ($infoCard && $infoCard->getOwner()) ? $infoCard->getOwner() : '' ?>"/>
64
+ <input type="hidden" name="EWAY_CARDNUMBER" value="<?php echo $infoCard && $infoCard->getCardFull() ? str_replace('*', 'X', $infoCard->getCardFull()) : str_replace('*','X',$infoCard->getCard()) ?>"/>
65
+
66
+ <input type="hidden" name="EWAY_CARDEXPIRYMONTH" value="<?php echo $infoCard && $infoCard->getExpMonth() ? $infoCard->getExpMonth() : '' ?>" />
67
+ <input type="hidden" name="EWAY_CARDEXPIRYYEAR" value="<?php echo $infoCard && $infoCard->getExpYear() ? $infoCard->getExpYear() : '' ?>" />
68
+ <?php if($this->hasVerification()): ?>
69
+ <input type="hidden" title="<?php echo $this->__('Card Verification Number') ?>"
70
+ class="" id="EWAY_CARDCVN" name="EWAY_CARDCVN" value="<?php echo $infoCard && $infoCard->getCid() ? $infoCard->getCid() : '' ?>"
71
+ />
72
+ <?php endif; ?>
73
+ </form>
74
+
75
+ <script type="text/javascript">
76
+ document.getElementById("transparent_card").submit();
77
+ </script>
app/design/frontend/base/default/template/ewayrapid/redirect/transparent_checkout.phtml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $_code = $this->getMethodCode();
3
+ $accessCode = $this->getAccessCode();
4
+ ?>
5
+
6
+ <form method="post" action="<?php echo Mage::getSingleton('core/session')->getFormActionUrl(); ?>"
7
+ name="transparent_card" id="transparent_card">
8
+ <h4><span class="please-wait" id="payment-please-wait" style="display: block;float: left;"><img
9
+ src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif'); ?>" alt="Connecting..."
10
+ title="Connecting..." class="v-middle"> Connecting...</span></h4>
11
+ <input type="hidden" name="EWAY_ACCESSCODE" value="<?php echo $accessCode; ?>"/>
12
+
13
+ <?php if ($this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_STANDARD_METHOD || $this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD) { ?>
14
+ <input type="hidden" name="EWAY_PAYMENTTYPE" value="paypal"/>
15
+ <?php } elseif ($this->transMethod == Eway_Rapid31_Model_Config::MASTERPASS_METHOD) { ?>
16
+ <input type="hidden" name="EWAY_PAYMENTTYPE" value="masterpass"/>
17
+ <?php if($this->hasVerification() && Mage::getSingleton('core/session')->getInfoCard()->getCid()): ?>
18
+ <input type="hidden" title="<?php echo $this->__('Card Verification Number') ?>"
19
+ class="" id="EWAY_CARDCVN" name="EWAY_CARDCVN" value="<?php echo Mage::getSingleton('core/session')->getInfoCard()->getCid(); ?>"
20
+ />
21
+ <?php endif; ?>
22
+ <?php } ?>
23
+
24
+ <?php if ($this->transMethod == Eway_Rapid31_Model_Config::PAYPAL_EXPRESS_METHOD) { ?>
25
+ <input type="hidden" name="EWAY_NEWSHIPPINGTOTAL" value="<?php echo @$this->getNewShipping(); ?>"/>
26
+ <input type="hidden" name="EWAY_ISREFERENCETRANSACTION" value="false"/>
27
+ <?php } ?>
28
+ </form>
29
+
30
+ <script type="text/javascript">
31
+ document.getElementById("transparent_card").submit();
32
+ </script>
app/etc/modules/Eway_Rapid31.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Eway_Rapid31>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Eway_Rapid31>
8
+ </modules>
9
+ </config>
app/locale/en_US/Eway_Rapid31.csv ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ "There is an error in making API request: %s","There is an error in making API request: %s"
2
+ "Please check the API Key and Password ","Please check the API Key and Password "
3
+ "Unknown message code (%s)","Unknown message code (%s)"
js/ewayrapid/eCrypt.js ADDED
@@ -0,0 +1,1001 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // eWAY RSA Client Cryptography
2
+ // Version 0.6 Alpha
3
+
4
+ function eCrypt() {
5
+ this.init = null;
6
+ this.doEncrypt = null;
7
+ }
8
+
9
+ (function (eCrypt) {
10
+ function eCryptInit() {
11
+
12
+ var ewayPublicKeyAttribute = "data-eway-encrypt-key";
13
+ var ewayEncryptAttribute = "data-eway-encrypt-name";
14
+
15
+ var PUBLIC_KEY_N = null;
16
+ var PUBLIC_KEY_E = b64tohex("AQAB");
17
+
18
+ var isAjaxCall = false;
19
+
20
+ // TODO: How should we handle form not found...
21
+ var form = findFormToEncrypt();
22
+ extractPublicKey(form);
23
+ addSubmitEvent(form);
24
+
25
+ function encryptForm(event) {
26
+ try {
27
+ var target;
28
+ // the form is not the event target in ajax call, so we use form variable found before
29
+ if(form != null) {
30
+ target = form;
31
+ } else {
32
+ event = event || window.event; // event is undefined in IE
33
+ target = event.target || event.srcElement; // IE uses srcElement, everything else uses target
34
+ }
35
+ var rsa = new RSAKey();
36
+ rsa.setPublic(PUBLIC_KEY_N, PUBLIC_KEY_E);
37
+ var newForm = cloneForm(target);
38
+ if (newForm.id) {
39
+ newForm.id = "EWAY_CLONED_" + newForm.id;
40
+ }
41
+
42
+ for (formNode = 0, formLength = newForm.length; formNode < formLength; formNode++) {
43
+ var dataAttribute = newForm[formNode].getAttribute(ewayEncryptAttribute);
44
+ if (dataAttribute != null) {
45
+ encryptElement(newForm[formNode], rsa);
46
+ }
47
+ else if (newForm[formNode].id) {
48
+ newForm[formNode].id = "EWAY_ENCRYPTED_" + newForm[formNode].id;
49
+ }
50
+ }
51
+
52
+ newForm.style.display = "none";
53
+ form.parentNode.appendChild(newForm); //IE and FF will not submit form without it being inserted into the DOM
54
+ if(isAjaxCall) {
55
+ return newForm;
56
+ } else {
57
+ var formProxy = document.createElement('form');
58
+ formProxy.submit.apply(newForm); // To guard against a form with a button named 'submit'
59
+ }
60
+ }
61
+ catch (err) {
62
+ // Debugging - In case console not open in IE
63
+ if (!window.console) window.console = {};
64
+ if (!window.console.log) window.console.log = function () { };
65
+ console.log('Uh oh, something went wrong');
66
+ console.log(err);
67
+ console.log(err.message);
68
+ }
69
+ finally {
70
+ if(!isAjaxCall) {
71
+ return false;
72
+ }
73
+ }
74
+ }
75
+
76
+ function findFormToEncrypt() {
77
+ var forms = document.getElementsByTagName('form');
78
+ for (var i = 0; i < forms.length; i++) {
79
+ var key = forms[i].getAttribute(ewayPublicKeyAttribute);
80
+ if (key) {
81
+ return forms[i];
82
+ }
83
+ }
84
+ return null;
85
+ }
86
+
87
+ function extractPublicKey(f) {
88
+ PUBLIC_KEY_N = b64tohex(f.getAttribute(ewayPublicKeyAttribute));
89
+ }
90
+
91
+ function cloneForm(oldForm) {
92
+ var newForm = oldForm.cloneNode(true);
93
+ copySelectLists(oldForm, newForm);
94
+ return newForm;
95
+ }
96
+
97
+ function copySelectLists(oldForm, newForm) {
98
+ var selectElementsOld = oldForm.getElementsByTagName('Select');
99
+ var selectElementsNew = newForm.getElementsByTagName('Select');
100
+
101
+ for (var i = 0; i < selectElementsOld.length; i++) {
102
+ selectElementsNew[i].selectedIndex = selectElementsOld[i].selectedIndex;
103
+ }
104
+ }
105
+
106
+ function encryptElement(element, rsa) {
107
+ if (element.id) {
108
+ element.id = "EWAY_ENCRYPTED_" + element.id;
109
+ }
110
+ element.name = element.getAttribute(ewayEncryptAttribute);
111
+ element.value = "eCrypted:" + rsa.encrypt(element.value);
112
+ }
113
+
114
+ function addSubmitEvent(frm) {
115
+ var oldonsubmit = frm.onsubmit;
116
+ if (typeof frm.onsubmit != 'function') {
117
+ frm.onsubmit = encryptForm;
118
+ } else {
119
+ frm.onsubmit = function (e) {
120
+ if (!oldonsubmit(e)) {
121
+ return false;
122
+ };
123
+ return encryptForm(e);
124
+ }
125
+ }
126
+
127
+ eCrypt.doEncrypt = function() {
128
+ isAjaxCall = true;
129
+ return encryptForm();
130
+ }
131
+ }
132
+ };
133
+
134
+
135
+
136
+ // Start jsbn.js
137
+ var dbits;
138
+
139
+ // JavaScript engine analysis
140
+ var canary = 0xdeadbeefcafe;
141
+ var j_lm = ((canary & 0xffffff) == 0xefcafe);
142
+
143
+ // (public) Constructor
144
+ function BigInteger(a, b, c) {
145
+ if (a != null)
146
+ if ("number" == typeof a) this.fromNumber(a, b, c);
147
+ else if (b == null && "string" != typeof a) this.fromString(a, 256);
148
+ else this.fromString(a, b);
149
+ }
150
+
151
+ // return new, unset BigInteger
152
+ function nbi() { return new BigInteger(null); }
153
+
154
+ // am: Compute w_j += (x*this_i), propagate carries,
155
+ // c is initial carry, returns final carry.
156
+ // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
157
+ // We need to select the fastest one that works in this environment.
158
+
159
+ // am1: use a single mult and divide to get the high bits,
160
+ // max digit bits should be 26 because
161
+ // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
162
+ function am1(i, x, w, j, c, n) {
163
+ while (--n >= 0) {
164
+ var v = x * this[i++] + w[j] + c;
165
+ c = Math.floor(v / 0x4000000);
166
+ w[j++] = v & 0x3ffffff;
167
+ }
168
+ return c;
169
+ }
170
+ // am2 avoids a big mult-and-extract completely.
171
+ // Max digit bits should be <= 30 because we do bitwise ops
172
+ // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
173
+ function am2(i, x, w, j, c, n) {
174
+ var xl = x & 0x7fff, xh = x >> 15;
175
+ while (--n >= 0) {
176
+ var l = this[i] & 0x7fff;
177
+ var h = this[i++] >> 15;
178
+ var m = xh * l + h * xl;
179
+ l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff);
180
+ c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30);
181
+ w[j++] = l & 0x3fffffff;
182
+ }
183
+ return c;
184
+ }
185
+ // Alternately, set max digit bits to 28 since some
186
+ // browsers slow down when dealing with 32-bit numbers.
187
+ function am3(i, x, w, j, c, n) {
188
+ var xl = x & 0x3fff, xh = x >> 14;
189
+ while (--n >= 0) {
190
+ var l = this[i] & 0x3fff;
191
+ var h = this[i++] >> 14;
192
+ var m = xh * l + h * xl;
193
+ l = xl * l + ((m & 0x3fff) << 14) + w[j] + c;
194
+ c = (l >> 28) + (m >> 14) + xh * h;
195
+ w[j++] = l & 0xfffffff;
196
+ }
197
+ return c;
198
+ }
199
+ if (j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
200
+ BigInteger.prototype.am = am2;
201
+ dbits = 30;
202
+ }
203
+ else if (j_lm && (navigator.appName != "Netscape")) {
204
+ BigInteger.prototype.am = am1;
205
+ dbits = 26;
206
+ }
207
+ else { // Mozilla/Netscape seems to prefer am3
208
+ BigInteger.prototype.am = am3;
209
+ dbits = 28;
210
+ }
211
+
212
+ BigInteger.prototype.DB = dbits;
213
+ BigInteger.prototype.DM = ((1 << dbits) - 1);
214
+ BigInteger.prototype.DV = (1 << dbits);
215
+
216
+ var BI_FP = 52;
217
+ BigInteger.prototype.FV = Math.pow(2, BI_FP);
218
+ BigInteger.prototype.F1 = BI_FP - dbits;
219
+ BigInteger.prototype.F2 = 2 * dbits - BI_FP;
220
+
221
+ // Digit conversions
222
+ var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
223
+ var BI_RC = new Array();
224
+ var rr, vv;
225
+ rr = "0".charCodeAt(0);
226
+ for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
227
+ rr = "a".charCodeAt(0);
228
+ for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
229
+ rr = "A".charCodeAt(0);
230
+ for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
231
+
232
+ function int2char(n) { return BI_RM.charAt(n); }
233
+ function intAt(s, i) {
234
+ var c = BI_RC[s.charCodeAt(i)];
235
+ return (c == null) ? -1 : c;
236
+ }
237
+
238
+ // (protected) copy this to r
239
+ function bnpCopyTo(r) {
240
+ for (var i = this.t - 1; i >= 0; --i) r[i] = this[i];
241
+ r.t = this.t;
242
+ r.s = this.s;
243
+ }
244
+
245
+ // (protected) set from integer value x, -DV <= x < DV
246
+ function bnpFromInt(x) {
247
+ this.t = 1;
248
+ this.s = (x < 0) ? -1 : 0;
249
+ if (x > 0) this[0] = x;
250
+ else if (x < -1) this[0] = x + this.DV;
251
+ else this.t = 0;
252
+ }
253
+
254
+ // return bigint initialized to value
255
+ function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
256
+
257
+ // (protected) set from string and radix
258
+ function bnpFromString(s, b) {
259
+ var k;
260
+ if (b == 16) k = 4;
261
+ else if (b == 8) k = 3;
262
+ else if (b == 256) k = 8; // byte array
263
+ else if (b == 2) k = 1;
264
+ else if (b == 32) k = 5;
265
+ else if (b == 4) k = 2;
266
+ else { this.fromRadix(s, b); return; }
267
+ this.t = 0;
268
+ this.s = 0;
269
+ var i = s.length, mi = false, sh = 0;
270
+ while (--i >= 0) {
271
+ var x = (k == 8) ? s[i] & 0xff : intAt(s, i);
272
+ if (x < 0) {
273
+ if (s.charAt(i) == "-") mi = true;
274
+ continue;
275
+ }
276
+ mi = false;
277
+ if (sh == 0)
278
+ this[this.t++] = x;
279
+ else if (sh + k > this.DB) {
280
+ this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh;
281
+ this[this.t++] = (x >> (this.DB - sh));
282
+ }
283
+ else
284
+ this[this.t - 1] |= x << sh;
285
+ sh += k;
286
+ if (sh >= this.DB) sh -= this.DB;
287
+ }
288
+ if (k == 8 && (s[0] & 0x80) != 0) {
289
+ this.s = -1;
290
+ if (sh > 0) this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh;
291
+ }
292
+ this.clamp();
293
+ if (mi) BigInteger.ZERO.subTo(this, this);
294
+ }
295
+
296
+ // (protected) clamp off excess high words
297
+ function bnpClamp() {
298
+ var c = this.s & this.DM;
299
+ while (this.t > 0 && this[this.t - 1] == c)--this.t;
300
+ }
301
+
302
+ // (public) return string representation in given radix
303
+ function bnToString(b) {
304
+ if (this.s < 0) return "-" + this.negate().toString(b);
305
+ var k;
306
+ if (b == 16) k = 4;
307
+ else if (b == 8) k = 3;
308
+ else if (b == 2) k = 1;
309
+ else if (b == 32) k = 5;
310
+ else if (b == 4) k = 2;
311
+ else return this.toRadix(b);
312
+ var km = (1 << k) - 1, d, m = false, r = "", i = this.t;
313
+ var p = this.DB - (i * this.DB) % k;
314
+ if (i-- > 0) {
315
+ if (p < this.DB && (d = this[i] >> p) > 0) { m = true; r = int2char(d); }
316
+ while (i >= 0) {
317
+ if (p < k) {
318
+ d = (this[i] & ((1 << p) - 1)) << (k - p);
319
+ d |= this[--i] >> (p += this.DB - k);
320
+ }
321
+ else {
322
+ d = (this[i] >> (p -= k)) & km;
323
+ if (p <= 0) { p += this.DB; --i; }
324
+ }
325
+ if (d > 0) m = true;
326
+ if (m) r += int2char(d);
327
+ }
328
+ }
329
+ return m ? r : "0";
330
+ }
331
+
332
+ // (public) -this
333
+ function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this, r); return r; }
334
+
335
+ // (public) |this|
336
+ function bnAbs() { return (this.s < 0) ? this.negate() : this; }
337
+
338
+ // (public) return + if this > a, - if this < a, 0 if equal
339
+ function bnCompareTo(a) {
340
+ var r = this.s - a.s;
341
+ if (r != 0) return r;
342
+ var i = this.t;
343
+ r = i - a.t;
344
+ if (r != 0) return (this.s < 0) ? -r : r;
345
+ while (--i >= 0) if ((r = this[i] - a[i]) != 0) return r;
346
+ return 0;
347
+ }
348
+
349
+ // returns bit length of the integer x
350
+ function nbits(x) {
351
+ var r = 1, t;
352
+ if ((t = x >>> 16) != 0) { x = t; r += 16; }
353
+ if ((t = x >> 8) != 0) { x = t; r += 8; }
354
+ if ((t = x >> 4) != 0) { x = t; r += 4; }
355
+ if ((t = x >> 2) != 0) { x = t; r += 2; }
356
+ if ((t = x >> 1) != 0) { x = t; r += 1; }
357
+ return r;
358
+ }
359
+
360
+ // (public) return the number of bits in "this"
361
+ function bnBitLength() {
362
+ if (this.t <= 0) return 0;
363
+ return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM));
364
+ }
365
+
366
+ // (protected) r = this << n*DB
367
+ function bnpDLShiftTo(n, r) {
368
+ var i;
369
+ for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i];
370
+ for (i = n - 1; i >= 0; --i) r[i] = 0;
371
+ r.t = this.t + n;
372
+ r.s = this.s;
373
+ }
374
+
375
+ // (protected) r = this >> n*DB
376
+ function bnpDRShiftTo(n, r) {
377
+ for (var i = n; i < this.t; ++i) r[i - n] = this[i];
378
+ r.t = Math.max(this.t - n, 0);
379
+ r.s = this.s;
380
+ }
381
+
382
+ // (protected) r = this << n
383
+ function bnpLShiftTo(n, r) {
384
+ var bs = n % this.DB;
385
+ var cbs = this.DB - bs;
386
+ var bm = (1 << cbs) - 1;
387
+ var ds = Math.floor(n / this.DB), c = (this.s << bs) & this.DM, i;
388
+ for (i = this.t - 1; i >= 0; --i) {
389
+ r[i + ds + 1] = (this[i] >> cbs) | c;
390
+ c = (this[i] & bm) << bs;
391
+ }
392
+ for (i = ds - 1; i >= 0; --i) r[i] = 0;
393
+ r[ds] = c;
394
+ r.t = this.t + ds + 1;
395
+ r.s = this.s;
396
+ r.clamp();
397
+ }
398
+
399
+ // (protected) r = this >> n
400
+ function bnpRShiftTo(n, r) {
401
+ r.s = this.s;
402
+ var ds = Math.floor(n / this.DB);
403
+ if (ds >= this.t) { r.t = 0; return; }
404
+ var bs = n % this.DB;
405
+ var cbs = this.DB - bs;
406
+ var bm = (1 << bs) - 1;
407
+ r[0] = this[ds] >> bs;
408
+ for (var i = ds + 1; i < this.t; ++i) {
409
+ r[i - ds - 1] |= (this[i] & bm) << cbs;
410
+ r[i - ds] = this[i] >> bs;
411
+ }
412
+ if (bs > 0) r[this.t - ds - 1] |= (this.s & bm) << cbs;
413
+ r.t = this.t - ds;
414
+ r.clamp();
415
+ }
416
+
417
+ // (protected) r = this - a
418
+ function bnpSubTo(a, r) {
419
+ var i = 0, c = 0, m = Math.min(a.t, this.t);
420
+ while (i < m) {
421
+ c += this[i] - a[i];
422
+ r[i++] = c & this.DM;
423
+ c >>= this.DB;
424
+ }
425
+ if (a.t < this.t) {
426
+ c -= a.s;
427
+ while (i < this.t) {
428
+ c += this[i];
429
+ r[i++] = c & this.DM;
430
+ c >>= this.DB;
431
+ }
432
+ c += this.s;
433
+ }
434
+ else {
435
+ c += this.s;
436
+ while (i < a.t) {
437
+ c -= a[i];
438
+ r[i++] = c & this.DM;
439
+ c >>= this.DB;
440
+ }
441
+ c -= a.s;
442
+ }
443
+ r.s = (c < 0) ? -1 : 0;
444
+ if (c < -1) r[i++] = this.DV + c;
445
+ else if (c > 0) r[i++] = c;
446
+ r.t = i;
447
+ r.clamp();
448
+ }
449
+
450
+ // (protected) r = this * a, r != this,a (HAC 14.12)
451
+ // "this" should be the larger one if appropriate.
452
+ function bnpMultiplyTo(a, r) {
453
+ var x = this.abs(), y = a.abs();
454
+ var i = x.t;
455
+ r.t = i + y.t;
456
+ while (--i >= 0) r[i] = 0;
457
+ for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
458
+ r.s = 0;
459
+ r.clamp();
460
+ if (this.s != a.s) BigInteger.ZERO.subTo(r, r);
461
+ }
462
+
463
+ // (protected) r = this^2, r != this (HAC 14.16)
464
+ function bnpSquareTo(r) {
465
+ var x = this.abs();
466
+ var i = r.t = 2 * x.t;
467
+ while (--i >= 0) r[i] = 0;
468
+ for (i = 0; i < x.t - 1; ++i) {
469
+ var c = x.am(i, x[i], r, 2 * i, 0, 1);
470
+ if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
471
+ r[i + x.t] -= x.DV;
472
+ r[i + x.t + 1] = 1;
473
+ }
474
+ }
475
+ if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
476
+ r.s = 0;
477
+ r.clamp();
478
+ }
479
+
480
+ // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
481
+ // r != q, this != m. q or r may be null.
482
+ function bnpDivRemTo(m, q, r) {
483
+ var pm = m.abs();
484
+ if (pm.t <= 0) return;
485
+ var pt = this.abs();
486
+ if (pt.t < pm.t) {
487
+ if (q != null) q.fromInt(0);
488
+ if (r != null) this.copyTo(r);
489
+ return;
490
+ }
491
+ if (r == null) r = nbi();
492
+ var y = nbi(), ts = this.s, ms = m.s;
493
+ var nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus
494
+ if (nsh > 0) { pm.lShiftTo(nsh, y); pt.lShiftTo(nsh, r); }
495
+ else { pm.copyTo(y); pt.copyTo(r); }
496
+ var ys = y.t;
497
+ var y0 = y[ys - 1];
498
+ if (y0 == 0) return;
499
+ var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
500
+ var d1 = this.FV / yt, d2 = (1 << this.F1) / yt, e = 1 << this.F2;
501
+ var i = r.t, j = i - ys, t = (q == null) ? nbi() : q;
502
+ y.dlShiftTo(j, t);
503
+ if (r.compareTo(t) >= 0) {
504
+ r[r.t++] = 1;
505
+ r.subTo(t, r);
506
+ }
507
+ BigInteger.ONE.dlShiftTo(ys, t);
508
+ t.subTo(y, y); // "negative" y so we can replace sub with am later
509
+ while (y.t < ys) y[y.t++] = 0;
510
+ while (--j >= 0) {
511
+ // Estimate quotient digit
512
+ var qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
513
+ if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
514
+ y.dlShiftTo(j, t);
515
+ r.subTo(t, r);
516
+ while (r[i] < --qd) r.subTo(t, r);
517
+ }
518
+ }
519
+ if (q != null) {
520
+ r.drShiftTo(ys, q);
521
+ if (ts != ms) BigInteger.ZERO.subTo(q, q);
522
+ }
523
+ r.t = ys;
524
+ r.clamp();
525
+ if (nsh > 0) r.rShiftTo(nsh, r); // Denormalize remainder
526
+ if (ts < 0) BigInteger.ZERO.subTo(r, r);
527
+ }
528
+
529
+ // (public) this mod a
530
+ function bnMod(a) {
531
+ var r = nbi();
532
+ this.abs().divRemTo(a, null, r);
533
+ if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r, r);
534
+ return r;
535
+ }
536
+
537
+ // Modular reduction using "classic" algorithm
538
+ function Classic(m) { this.m = m; }
539
+ function cConvert(x) {
540
+ if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
541
+ else return x;
542
+ }
543
+ function cRevert(x) { return x; }
544
+ function cReduce(x) { x.divRemTo(this.m, null, x); }
545
+ function cMulTo(x, y, r) { x.multiplyTo(y, r); this.reduce(r); }
546
+ function cSqrTo(x, r) { x.squareTo(r); this.reduce(r); }
547
+
548
+ Classic.prototype.convert = cConvert;
549
+ Classic.prototype.revert = cRevert;
550
+ Classic.prototype.reduce = cReduce;
551
+ Classic.prototype.mulTo = cMulTo;
552
+ Classic.prototype.sqrTo = cSqrTo;
553
+
554
+ // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
555
+ // justification:
556
+ // xy == 1 (mod m)
557
+ // xy = 1+km
558
+ // xy(2-xy) = (1+km)(1-km)
559
+ // x[y(2-xy)] = 1-k^2m^2
560
+ // x[y(2-xy)] == 1 (mod m^2)
561
+ // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
562
+ // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
563
+ // JS multiply "overflows" differently from C/C++, so care is needed here.
564
+ function bnpInvDigit() {
565
+ if (this.t < 1) return 0;
566
+ var x = this[0];
567
+ if ((x & 1) == 0) return 0;
568
+ var y = x & 3; // y == 1/x mod 2^2
569
+ y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
570
+ y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
571
+ y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
572
+ // last step - calculate inverse mod DV directly;
573
+ // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
574
+ y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
575
+ // we really want the negative inverse, and -DV < y < DV
576
+ return (y > 0) ? this.DV - y : -y;
577
+ }
578
+
579
+ // Montgomery reduction
580
+ function Montgomery(m) {
581
+ this.m = m;
582
+ this.mp = m.invDigit();
583
+ this.mpl = this.mp & 0x7fff;
584
+ this.mph = this.mp >> 15;
585
+ this.um = (1 << (m.DB - 15)) - 1;
586
+ this.mt2 = 2 * m.t;
587
+ }
588
+
589
+ // xR mod m
590
+ function montConvert(x) {
591
+ var r = nbi();
592
+ x.abs().dlShiftTo(this.m.t, r);
593
+ r.divRemTo(this.m, null, r);
594
+ if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r);
595
+ return r;
596
+ }
597
+
598
+ // x/R mod m
599
+ function montRevert(x) {
600
+ var r = nbi();
601
+ x.copyTo(r);
602
+ this.reduce(r);
603
+ return r;
604
+ }
605
+
606
+ // x = x/R mod m (HAC 14.32)
607
+ function montReduce(x) {
608
+ while (x.t <= this.mt2) // pad x so am has enough room later
609
+ x[x.t++] = 0;
610
+ for (var i = 0; i < this.m.t; ++i) {
611
+ // faster way of calculating u0 = x[i]*mp mod DV
612
+ var j = x[i] & 0x7fff;
613
+ var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM;
614
+ // use am to combine the multiply-shift-add into one call
615
+ j = i + this.m.t;
616
+ x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
617
+ // propagate carry
618
+ while (x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
619
+ }
620
+ x.clamp();
621
+ x.drShiftTo(this.m.t, x);
622
+ if (x.compareTo(this.m) >= 0) x.subTo(this.m, x);
623
+ }
624
+
625
+ // r = "x^2/R mod m"; x != r
626
+ function montSqrTo(x, r) { x.squareTo(r); this.reduce(r); }
627
+
628
+ // r = "xy/R mod m"; x,y != r
629
+ function montMulTo(x, y, r) { x.multiplyTo(y, r); this.reduce(r); }
630
+
631
+ Montgomery.prototype.convert = montConvert;
632
+ Montgomery.prototype.revert = montRevert;
633
+ Montgomery.prototype.reduce = montReduce;
634
+ Montgomery.prototype.mulTo = montMulTo;
635
+ Montgomery.prototype.sqrTo = montSqrTo;
636
+
637
+ // (protected) true iff this is even
638
+ function bnpIsEven() { return ((this.t > 0) ? (this[0] & 1) : this.s) == 0; }
639
+
640
+ // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
641
+ function bnpExp(e, z) {
642
+ if (e > 0xffffffff || e < 1) return BigInteger.ONE;
643
+ var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e) - 1;
644
+ g.copyTo(r);
645
+ while (--i >= 0) {
646
+ z.sqrTo(r, r2);
647
+ if ((e & (1 << i)) > 0) z.mulTo(r2, g, r);
648
+ else { var t = r; r = r2; r2 = t; }
649
+ }
650
+ return z.revert(r);
651
+ }
652
+
653
+ // (public) this^e % m, 0 <= e < 2^32
654
+ function bnModPowInt(e, m) {
655
+ var z;
656
+ if (e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
657
+ return this.exp(e, z);
658
+ }
659
+
660
+ // protected
661
+ BigInteger.prototype.copyTo = bnpCopyTo;
662
+ BigInteger.prototype.fromInt = bnpFromInt;
663
+ BigInteger.prototype.fromString = bnpFromString;
664
+ BigInteger.prototype.clamp = bnpClamp;
665
+ BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
666
+ BigInteger.prototype.drShiftTo = bnpDRShiftTo;
667
+ BigInteger.prototype.lShiftTo = bnpLShiftTo;
668
+ BigInteger.prototype.rShiftTo = bnpRShiftTo;
669
+ BigInteger.prototype.subTo = bnpSubTo;
670
+ BigInteger.prototype.multiplyTo = bnpMultiplyTo;
671
+ BigInteger.prototype.squareTo = bnpSquareTo;
672
+ BigInteger.prototype.divRemTo = bnpDivRemTo;
673
+ BigInteger.prototype.invDigit = bnpInvDigit;
674
+ BigInteger.prototype.isEven = bnpIsEven;
675
+ BigInteger.prototype.exp = bnpExp;
676
+
677
+ // public
678
+ BigInteger.prototype.toString = bnToString;
679
+ BigInteger.prototype.negate = bnNegate;
680
+ BigInteger.prototype.abs = bnAbs;
681
+ BigInteger.prototype.compareTo = bnCompareTo;
682
+ BigInteger.prototype.bitLength = bnBitLength;
683
+ BigInteger.prototype.mod = bnMod;
684
+ BigInteger.prototype.modPowInt = bnModPowInt;
685
+
686
+ // "constants"
687
+ BigInteger.ZERO = nbv(0);
688
+ BigInteger.ONE = nbv(1);
689
+
690
+
691
+ // prng4.js - uses Arcfour as a PRNG
692
+
693
+ function Arcfour() {
694
+ this.i = 0;
695
+ this.j = 0;
696
+ this.S = new Array();
697
+ }
698
+
699
+ // Initialize arcfour context from key, an array of ints, each from [0..255]
700
+ function ARC4init(key) {
701
+ var i, j, t;
702
+ for (i = 0; i < 256; ++i)
703
+ this.S[i] = i;
704
+ j = 0;
705
+ for (i = 0; i < 256; ++i) {
706
+ j = (j + this.S[i] + key[i % key.length]) & 255;
707
+ t = this.S[i];
708
+ this.S[i] = this.S[j];
709
+ this.S[j] = t;
710
+ }
711
+ this.i = 0;
712
+ this.j = 0;
713
+ }
714
+
715
+ function ARC4next() {
716
+ var t;
717
+ this.i = (this.i + 1) & 255;
718
+ this.j = (this.j + this.S[this.i]) & 255;
719
+ t = this.S[this.i];
720
+ this.S[this.i] = this.S[this.j];
721
+ this.S[this.j] = t;
722
+ return this.S[(t + this.S[this.i]) & 255];
723
+ }
724
+
725
+ Arcfour.prototype.init = ARC4init;
726
+ Arcfour.prototype.next = ARC4next;
727
+
728
+ // Plug in your RNG constructor here
729
+ function prng_newstate() {
730
+ return new Arcfour();
731
+ }
732
+
733
+ // Pool size must be a multiple of 4 and greater than 32.
734
+ // An array of bytes the size of the pool will be passed to init()
735
+ var rng_psize = 256;
736
+
737
+ // Random number generator - requires a PRNG backend, e.g. prng4.js
738
+
739
+ // For best results, put code like
740
+ // <body onClick='rng_seed_time();' onKeyPress='rng_seed_time();'>
741
+ // in your main HTML document.
742
+
743
+ var rng_state;
744
+ var rng_pool;
745
+ var rng_pptr;
746
+
747
+ // Mix in a 32-bit integer into the pool
748
+ function rng_seed_int(x) {
749
+ rng_pool[rng_pptr++] ^= x & 255;
750
+ rng_pool[rng_pptr++] ^= (x >> 8) & 255;
751
+ rng_pool[rng_pptr++] ^= (x >> 16) & 255;
752
+ rng_pool[rng_pptr++] ^= (x >> 24) & 255;
753
+ if (rng_pptr >= rng_psize) rng_pptr -= rng_psize;
754
+ }
755
+
756
+ // Mix in the current time (w/milliseconds) into the pool
757
+ function rng_seed_time() {
758
+ rng_seed_int(new Date().getTime());
759
+ }
760
+
761
+ // Initialize the pool with junk if needed.
762
+ if (rng_pool == null) {
763
+ rng_pool = new Array();
764
+ rng_pptr = 0;
765
+ var t;
766
+ if (window.crypto && window.crypto.getRandomValues) {
767
+ // Use webcrypto if available
768
+ var ua = new Uint8Array(32);
769
+ window.crypto.getRandomValues(ua);
770
+ for (t = 0; t < 32; ++t)
771
+ rng_pool[rng_pptr++] = ua[t];
772
+ }
773
+ if (navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) {
774
+ // Extract entropy (256 bits) from NS4 RNG if available
775
+ var z = window.crypto.random(32);
776
+ for (t = 0; t < z.length; ++t)
777
+ rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
778
+ }
779
+ while (rng_pptr < rng_psize) { // extract some randomness from Math.random()
780
+ t = Math.floor(65536 * Math.random());
781
+ rng_pool[rng_pptr++] = t >>> 8;
782
+ rng_pool[rng_pptr++] = t & 255;
783
+ }
784
+ rng_pptr = 0;
785
+ rng_seed_time();
786
+ //rng_seed_int(window.screenX);
787
+ //rng_seed_int(window.screenY);
788
+ }
789
+
790
+ function rng_get_byte() {
791
+ if (rng_state == null) {
792
+ rng_seed_time();
793
+ rng_state = prng_newstate();
794
+ rng_state.init(rng_pool);
795
+ for (rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
796
+ rng_pool[rng_pptr] = 0;
797
+ rng_pptr = 0;
798
+ //rng_pool = null;
799
+ }
800
+ // TODO: allow reseeding after first request
801
+ return rng_state.next();
802
+ }
803
+
804
+ function rng_get_bytes(ba) {
805
+ var i;
806
+ for (i = 0; i < ba.length; ++i) ba[i] = rng_get_byte();
807
+ }
808
+
809
+ function SecureRandom() { }
810
+
811
+ SecureRandom.prototype.nextBytes = rng_get_bytes;
812
+
813
+
814
+ // Depends on jsbn.js and rng.js
815
+
816
+ // Version 1.1: support utf-8 encoding in pkcs1pad2
817
+
818
+ // convert a (hex) string to a bignum object
819
+ function parseBigInt(str, r) {
820
+ return new BigInteger(str, r);
821
+ }
822
+
823
+ function linebrk(s, n) {
824
+ var ret = "";
825
+ var i = 0;
826
+ while (i + n < s.length) {
827
+ ret += s.substring(i, i + n) + "\n";
828
+ i += n;
829
+ }
830
+ return ret + s.substring(i, s.length);
831
+ }
832
+
833
+ function byte2Hex(b) {
834
+ if (b < 0x10)
835
+ return "0" + b.toString(16);
836
+ else
837
+ return b.toString(16);
838
+ }
839
+
840
+ // PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
841
+ function pkcs1pad2(s, n) {
842
+ if (n < s.length + 11) { // TODO: fix for utf-8
843
+ alert("Message too long for RSA");
844
+ return null;
845
+ }
846
+ var ba = new Array();
847
+ var i = s.length - 1;
848
+ while (i >= 0 && n > 0) {
849
+ var c = s.charCodeAt(i--);
850
+ if (c < 128) { // encode using utf-8
851
+ ba[--n] = c;
852
+ }
853
+ else if ((c > 127) && (c < 2048)) {
854
+ ba[--n] = (c & 63) | 128;
855
+ ba[--n] = (c >> 6) | 192;
856
+ }
857
+ else {
858
+ ba[--n] = (c & 63) | 128;
859
+ ba[--n] = ((c >> 6) & 63) | 128;
860
+ ba[--n] = (c >> 12) | 224;
861
+ }
862
+ }
863
+ ba[--n] = 0;
864
+ var rng = new SecureRandom();
865
+ var x = new Array();
866
+ while (n > 2) { // random non-zero pad
867
+ x[0] = 0;
868
+ while (x[0] == 0) rng.nextBytes(x);
869
+ ba[--n] = x[0];
870
+ }
871
+ ba[--n] = 2;
872
+ ba[--n] = 0;
873
+ return new BigInteger(ba);
874
+ }
875
+
876
+ // "empty" RSA key constructor
877
+ function RSAKey() {
878
+ this.n = null;
879
+ this.e = 0;
880
+ this.d = null;
881
+ this.p = null;
882
+ this.q = null;
883
+ this.dmp1 = null;
884
+ this.dmq1 = null;
885
+ this.coeff = null;
886
+ }
887
+
888
+ // Set the public key fields N and e from hex strings
889
+ function RSASetPublic(N, E) {
890
+ if (N != null && E != null && N.length > 0 && E.length > 0) {
891
+ this.n = parseBigInt(N, 16);
892
+ this.e = parseInt(E, 16);
893
+ }
894
+ else
895
+ alert("Invalid RSA public key");
896
+ }
897
+
898
+ // Perform raw public operation on "x": return x^e (mod n)
899
+ function RSADoPublic(x) {
900
+ return x.modPowInt(this.e, this.n);
901
+ }
902
+
903
+ // Return the PKCS#1 RSA encryption of "text" as an even-length hex string
904
+ function RSAEncrypt(text) {
905
+ var m = pkcs1pad2(text, (this.n.bitLength() + 7) >> 3);
906
+ if (m == null) return null;
907
+ var c = this.doPublic(m);
908
+ if (c == null) return null;
909
+ var h = c.toString(16);
910
+ if ((h.length & 1) == 0) return hex2b64(h); else return hex2b64("0" + h);
911
+ }
912
+
913
+ // Return the PKCS#1 RSA encryption of "text" as a Base64-encoded string
914
+ //function RSAEncryptB64(text) {
915
+ // var h = this.encrypt(text);
916
+ // if (h) return hex2b64(h); else return null;
917
+ //}
918
+
919
+ // protected
920
+ RSAKey.prototype.doPublic = RSADoPublic;
921
+
922
+ // public
923
+ RSAKey.prototype.setPublic = RSASetPublic;
924
+ RSAKey.prototype.encrypt = RSAEncrypt;
925
+
926
+ // base64.js
927
+
928
+ var b64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
929
+ var b64padchar = "=";
930
+
931
+ function hex2b64(h) {
932
+ var i;
933
+ var c;
934
+ var ret = "";
935
+ for (i = 0; i + 3 <= h.length; i += 3) {
936
+ c = parseInt(h.substring(i, i + 3), 16);
937
+ ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63);
938
+ }
939
+ if (i + 1 == h.length) {
940
+ c = parseInt(h.substring(i, i + 1), 16);
941
+ ret += b64map.charAt(c << 2);
942
+ }
943
+ else if (i + 2 == h.length) {
944
+ c = parseInt(h.substring(i, i + 2), 16);
945
+ ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4);
946
+ }
947
+ while ((ret.length & 3) > 0) ret += b64padchar;
948
+ return ret;
949
+ }
950
+
951
+ // convert a base64 string to hex
952
+ function b64tohex(s) {
953
+ var ret = ""
954
+ var i;
955
+ var k = 0; // b64 state, 0-3
956
+ var slop;
957
+ for (i = 0; i < s.length; ++i) {
958
+ if (s.charAt(i) == b64padchar) break;
959
+ v = b64map.indexOf(s.charAt(i));
960
+ if (v < 0) continue;
961
+ if (k == 0) {
962
+ ret += int2char(v >> 2);
963
+ slop = v & 3;
964
+ k = 1;
965
+ }
966
+ else if (k == 1) {
967
+ ret += int2char((slop << 2) | (v >> 4));
968
+ slop = v & 0xf;
969
+ k = 2;
970
+ }
971
+ else if (k == 2) {
972
+ ret += int2char(slop);
973
+ ret += int2char(v >> 2);
974
+ slop = v & 3;
975
+ k = 3;
976
+ }
977
+ else {
978
+ ret += int2char((slop << 2) | (v >> 4));
979
+ ret += int2char(v & 0xf);
980
+ k = 0;
981
+ }
982
+ }
983
+ if (k == 1)
984
+ ret += int2char(slop << 2);
985
+ return ret;
986
+ }
987
+
988
+ // convert a base64 string to a byte/number array
989
+ function b64toBA(s) {
990
+ //piggyback on b64tohex for now, optimize later
991
+ var h = b64tohex(s);
992
+ var i;
993
+ var a = new Array();
994
+ for (i = 0; 2 * i < h.length; ++i) {
995
+ a[i] = parseInt(h.substring(2 * i, 2 * i + 2), 16);
996
+ }
997
+ return a;
998
+ }
999
+
1000
+ eCrypt.init = eCryptInit;
1001
+ })(eCrypt);
js/ewayrapid/ewayrapid.js ADDED
@@ -0,0 +1,682 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var EwayPayment = Class.create();
2
+ EwayPayment.isEwayRapidMethod = function(method) {
3
+ return ("ewayrapid_saved" === method || "ewayrapid_notsaved" === method);
4
+ }
5
+ EwayPayment.supportCardTypes = ['AE', 'VI', 'MC', 'JCB', 'DC', 'VE', 'ME'];
6
+ EwayPayment.prototype = {
7
+ ewayPayment: this,
8
+ initialize: function(form, encryptionKey) {
9
+ if(form) {
10
+ // Init client-side encryption
11
+ if(typeof eCrypt == 'function') {
12
+ form.writeAttribute('data-eway-encrypt-key', encryptionKey);
13
+ eCrypt && eCrypt.init();
14
+ }
15
+ }
16
+ },
17
+
18
+ savePaymentWithEncryption: function() {
19
+ if (checkout.loadWaiting!=false) return;
20
+ var validator = new Validation(this.form);
21
+ if (this.validate() && validator.validate()) {
22
+ checkout.setLoadWaiting('payment');
23
+ var form = $(this.form);
24
+ if($$("input[id*='ewayrapid_'][name='payment[method]']:checked").length > 0) {
25
+ form = eCrypt.doEncrypt();
26
+ }
27
+ this.ewayForm = form;
28
+ var request = new Ajax.Request(
29
+ this.saveUrl,
30
+ {
31
+ method:'post',
32
+ onComplete: this.onComplete,
33
+ onSuccess: this.onSave,
34
+ onFailure: checkout.ajaxFailure.bind(checkout),
35
+ parameters: $(form.id).serialize()
36
+ }
37
+ );
38
+ }
39
+ },
40
+
41
+ savePaymentWithTransEncryption: function() {
42
+ if (checkout.loadWaiting!=false) return;
43
+ var validator = new Validation(this.form);
44
+ if (this.validate() && validator.validate()) {
45
+ checkout.setLoadWaiting('payment');
46
+ var form = $(this.form);
47
+ var _method = $$("input[name='payment[method]']:checked")[0].getValue();
48
+ var _transparent_method = '';
49
+
50
+ if(_method == 'ewayrapid_notsaved' && $$("input[name='payment[transparent_notsaved]']:checked").length > 0) {
51
+ _transparent_method = $$("input[name='payment[transparent_notsaved]']:checked")[0];
52
+ } else if(_method == 'ewayrapid_saved' && $$("input[name='payment[transparent_saved]']:checked").length > 0) {
53
+ _transparent_method = $$("input[name='payment[transparent_saved]']:checked")[0];
54
+ }
55
+
56
+ if(_transparent_method != '' && $(_transparent_method.id).getValue() == creditcard) {
57
+ if($$("input[id*='ewayrapid_'][name='payment[method]']:checked").length > 0) {
58
+ form = eCrypt.doEncrypt();
59
+ }
60
+ }
61
+
62
+ this.ewayForm = form;
63
+ var request = new Ajax.Request(
64
+ this.saveUrl,
65
+ {
66
+ method:'post',
67
+ onComplete: this.onComplete,
68
+ onSuccess: this.onSave,
69
+ onFailure: checkout.ajaxFailure.bind(checkout),
70
+ parameters: $(form.id).serialize()
71
+ }
72
+ );
73
+ }
74
+ },
75
+
76
+ saveReviewWithEncryption: function() {
77
+ if (checkout.loadWaiting!=false) return;
78
+ checkout.setLoadWaiting('review');
79
+ //var params = Form.serialize(payment.form);
80
+ var params = payment.ewayForm.serialize();
81
+ if (this.agreementsForm) {
82
+ params += '&'+Form.serialize(this.agreementsForm);
83
+ }
84
+ params.save = true;
85
+ var request = new Ajax.Request(
86
+ this.saveUrl,
87
+ {
88
+ method:'post',
89
+ parameters:params,
90
+ onComplete: this.onComplete,
91
+ onSuccess: this.onSave,
92
+ onFailure: checkout.ajaxFailure.bind(checkout)
93
+ }
94
+ );
95
+ },
96
+
97
+ submitAdminOrder: function() {
98
+ if(editForm.validator && editForm.validator.validate()) {
99
+ if($$("input[id*='ewayrapid_'][name='payment[method]']:checked").length > 0) {
100
+ editForm = eCrypt.doEncrypt();
101
+ }
102
+ if (this.orderItemChanged) {
103
+ if (confirm('You have item changes')) {
104
+ if (editForm.submit()) {
105
+ disableElements('save');
106
+ }
107
+ } else {
108
+ this.itemsUpdate();
109
+ }
110
+ } else {
111
+ if (editForm.submit()) {
112
+ disableElements('save');
113
+ }
114
+ }
115
+ }
116
+ },
117
+
118
+ OneStepCheckout: {
119
+ switchMethod: function(method) {
120
+ $$('.payment-method .form-list').each(function(form) {
121
+ form.style.display = 'none';
122
+ var elements = form.select('input').concat(form.select('select')).concat(form.select('textarea'));
123
+ for (var i=0; i<elements.length; i++) elements[i].disabled = true;
124
+ });
125
+
126
+ if ($('payment_form_'+method)){
127
+ var form = $('payment_form_'+method);
128
+ form.style.display = '';
129
+ var elements = form.select('input').concat(form.select('select')).concat(form.select('textarea'));
130
+ for (var i=0; i<elements.length; i++) elements[i].disabled = false;
131
+ this.currentMethod = method;
132
+ }
133
+ }
134
+ },
135
+
136
+ FireCheckout: {
137
+ save: function(urlSuffix, forceSave) {
138
+ var currentMethod = payment.currentMethod ? payment.currentMethod : '';
139
+ if(EwayPayment.isEwayRapidMethod(currentMethod)) {
140
+ if (this.loadWaiting != false) {
141
+ return;
142
+ }
143
+
144
+ if (!this.validate()) {
145
+ return;
146
+ }
147
+
148
+ // infostrates tnt
149
+ if (!forceSave && (typeof shippingMethod === 'object')
150
+ && shippingMethod.getCurrentMethod().indexOf("tnt_") === 0) {
151
+
152
+ shippingMethodTnt(shippingMethodTntUrl);
153
+ return;
154
+ }
155
+ // infostrates tnt
156
+
157
+ checkout.setLoadWaiting(true);
158
+
159
+ var params = Form.serialize(this.form, true);
160
+ $('review-please-wait').show();
161
+
162
+ encryptedForm = eCrypt.doEncrypt();
163
+ params = Form.serialize(encryptedForm, true);
164
+
165
+ urlSuffix = urlSuffix || '';
166
+ var request = new Ajax.Request(this.urls.save + urlSuffix, {
167
+ method:'post',
168
+ parameters:params,
169
+ onSuccess: this.setResponse.bind(this),
170
+ onFailure: this.ajaxFailure.bind(this)
171
+ });
172
+ } else if(typeof this.ewayOldSave == 'function') {
173
+ this.ewayOldSave(urlSuffix, forceSave);
174
+ }
175
+ }
176
+ },
177
+
178
+ IWDOnePageCheckout: {
179
+ savePayment: function() {
180
+ if(EwayPayment.isEwayRapidMethod(payment.currentMethod)) {
181
+ if (IWD.OPC.Checkout.xhr!=null){
182
+ IWD.OPC.Checkout.xhr.abort();
183
+ }
184
+ IWD.OPC.Checkout.showLoader();
185
+ var ewayForm = eCrypt.doEncrypt();
186
+ form = $j(ewayForm).serializeArray();
187
+ IWD.OPC.Checkout.xhr = $j.post(IWD.OPC.Checkout.config.baseUrl + 'onepage/json/savePayment',form, IWD.OPC.preparePaymentResponse,'json');
188
+ } else if(typeof IWD.OPC.ewayOldSavePayment == 'function') {
189
+ IWD.OPC.ewayOldSavePayment();
190
+ }
191
+ },
192
+ saveOrder: function() {
193
+ if(EwayPayment.isEwayRapidMethod(payment.currentMethod)) {
194
+ var ewayForm = eCrypt.doEncrypt();
195
+ form = $j(ewayForm).serializeArray();
196
+ form = IWD.OPC.checkAgreement(form);
197
+ IWD.OPC.Checkout.showLoader();
198
+ if (IWD.OPC.Checkout.config.comment!=="0"){
199
+ IWD.OPC.saveCustomerComment();
200
+ }
201
+
202
+ IWD.OPC.Plugin.dispatch('saveOrder');
203
+ IWD.OPC.Checkout.xhr = $j.post(IWD.OPC.Checkout.saveOrderUrl ,form, IWD.OPC.prepareOrderResponse,'json');
204
+ } else if(typeof IWD.OPC.ewayOldSaveOrder == 'function') {
205
+ IWD.OPC.ewayOldSaveOrder();
206
+ }
207
+ }
208
+ }
209
+ }
210
+
211
+ var EwayPaymentToken = Class.create();
212
+ EwayPaymentToken.prototype = {
213
+ savedTokens: null,
214
+ tokenCount: 0,
215
+ isAdmin: false,
216
+ labelEdit: 'Edit',
217
+ labelCancel: 'Cancel edit',
218
+ isEdit: true,
219
+ initialize: function(savedTokens, tokenCount, isAdmin, labelEdit, labelCancel) {
220
+ savedTokens['new']['Card'] = '';
221
+ this.savedTokens = savedTokens;
222
+ this.tokenCount = tokenCount;
223
+ this.isAdmin = isAdmin;
224
+ this.labelEdit = labelEdit;
225
+ this.labelCancel = labelCancel;
226
+
227
+ $('ewayrapid_saved_token') && $('ewayrapid_saved_token').observe('change', this.onSavedTokenChanged.bind(this));
228
+
229
+ $('ewayrapid_saved_edit') && $('ewayrapid_saved_edit').observe('click', this.onEditClick.bind(this));
230
+
231
+ if(this.tokenCount == 1) {
232
+ // Show credit card form in case customer does not have saved credit card (only 'Add new card' option)
233
+ this.ewayrapidToggleCcForm(true);
234
+ } else {
235
+ this.onSavedTokenChanged();
236
+ }
237
+ },
238
+
239
+ onSavedTokenChanged: function() {
240
+ if($('ewayrapid_saved_token') && $('ewayrapid_saved_token').value == 'new') {
241
+ this.ewayrapidToggleCcForm(true);
242
+ this.ewayrapidSelectToken('new');
243
+ $('ewayrapid_saved_cc_type') && $('ewayrapid_saved_cc_type').setValue('');
244
+ $('ewayrapid_saved_edit') && $('ewayrapid_saved_edit').hide();
245
+ $$('.help-disabled-cc a').each(function(element){
246
+ element.hide();
247
+ });
248
+ } else {
249
+ this.ewayrapidToggleCcForm(false);
250
+ $('ewayrapid_saved_cc_type') && $('ewayrapid_saved_cc_type').setValue(this.savedTokens[$('ewayrapid_saved_token').getValue()]['Type']);
251
+ if($('ewayrapid_saved_edit')) {
252
+ this.isEdit = true;
253
+ $('ewayrapid_saved_edit').update(this.labelEdit);
254
+ $('ewayrapid_saved_edit').show();
255
+ }
256
+ }
257
+ $('ewayrapid_saved_cc_cid') && $('ewayrapid_saved_cc_cid').setValue('');
258
+ },
259
+
260
+ onEditClick: function() {
261
+ if(this.isEdit) {
262
+ this.ewayrapidToggleCcForm(true);
263
+ this.ewayrapidSelectToken($('ewayrapid_saved_token').getValue());
264
+ $('ewayrapid_saved_edit').update(this.labelCancel);
265
+ $('ewayrapid_saved_cc_number').disable();
266
+ $('ewayrapid_saved_cc_number').removeClassName('validate-cc-number').removeClassName('validate-cc-type-auto');
267
+ $$('.help-disabled-cc a').each(function(element){
268
+ element.show();
269
+ });
270
+
271
+ this.isEdit = false;
272
+ } else {
273
+ this.ewayrapidToggleCcForm(false);
274
+ $('ewayrapid_saved_edit').update(this.labelEdit);
275
+ this.isEdit = true;
276
+ }
277
+ var validator = new Validation('co-payment-form');
278
+ validator.validate();
279
+ $('advice-validate-cc-type-auto-ewayrapid_saved_cc_number') && $('advice-validate-cc-type-auto-ewayrapid_saved_cc_number').hide();
280
+ },
281
+
282
+ ewayrapidToggleCcForm: function(isShow) {
283
+ $$('.saved_token_fields input,.saved_token_fields select').each(function(ele) {
284
+ isShow ? ele.enable() : ele.disable();
285
+ });
286
+ $$('.saved_token_fields').each(function(ele) {
287
+ isShow ? ele.show() : ele.hide();
288
+ });
289
+
290
+ isShow && $('ewayrapid_saved_cc_number') ? $('ewayrapid_saved_cc_number').addClassName('validate-cc-number').addClassName('validate-cc-type-auto') : ($('ewayrapid_saved_cc_number') ? $('ewayrapid_saved_cc_number').removeClassName('validate-cc-number').removeClassName('validate-cc-type-auto') : '' );
291
+ },
292
+
293
+ ewayrapidSelectToken: function(tokenId) {
294
+ $('ewayrapid_saved_cc_owner').setValue(this.savedTokens[tokenId]['Owner']);
295
+ $('ewayrapid_saved_cc_number').setValue(this.savedTokens[tokenId]['Card']);
296
+ $('ewayrapid_saved_expiration').setValue(this.savedTokens[tokenId]['ExpMonth']);
297
+ $('ewayrapid_saved_expiration_yr').setValue(this.savedTokens[tokenId]['ExpYear']);
298
+ $('ewayrapid_saved_cc_owner').focus();
299
+ }
300
+ }
301
+
302
+ Validation.creditCartTypes = $H({
303
+ // Add Diners Club, Maestro and Visa Electron card type
304
+ 'DC': [new RegExp('^3(?:0[0-5]|[68][0-9])[0-9]{11}$'), new RegExp('^[0-9]{3}$'), true],
305
+ 'VE': [new RegExp('^(4026|4405|4508|4844|4913|4917)[0-9]{12}|417500[0-9]{10}$'), new RegExp('^[0-9]{3}$'), true],
306
+ 'ME': [new RegExp('^(5018|5020|5038|5612|5893|6304|6759|6761|6762|6763|6390)[0-9]{8,15}$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],
307
+
308
+ 'SO': [new RegExp('^(6334[5-9]([0-9]{11}|[0-9]{13,14}))|(6767([0-9]{12}|[0-9]{14,15}))$'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],
309
+ 'VI': [new RegExp('^4[0-9]{12}([0-9]{3})?$'), new RegExp('^[0-9]{3}$'), true],
310
+ 'MC': [new RegExp('^5[1-5][0-9]{14}$'), new RegExp('^[0-9]{3}$'), true],
311
+ 'AE': [new RegExp('^3[47][0-9]{13}$'), new RegExp('^[0-9]{4}$'), true],
312
+ 'DI': [new RegExp('^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})|36[0-9]{12}|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}|5[0-9]{14}))$'), new RegExp('^[0-9]{3}$'), true],
313
+ 'JCB': [new RegExp('^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})|36[0-9]{12}|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}|5[0-9]{14}))$'), new RegExp('^[0-9]{3,4}$'), true],
314
+ // 'DICL': [new RegExp('^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})|36[0-9]{12}|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}|5[0-9]{14}))$'), new RegExp('^[0-9]{3}$'), true],
315
+ 'SM': [new RegExp('(^(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}$))'), new RegExp('^([0-9]{3}|[0-9]{4})?$'), true],
316
+ 'OT': [false, new RegExp('^([0-9]{3}|[0-9]{4})?$'), false]
317
+ });
318
+
319
+ Validation.add('validate-cc-type-auto', 'Invalid credit card number or credit card type is not supported.',
320
+ function(v, elm) {
321
+ // remove credit card number delimiters such as "-" and space
322
+ elm.value = removeDelimiters(elm.value);
323
+ v = removeDelimiters(v);
324
+ var acceptedTypes = EwayPayment.supportCardTypes;
325
+
326
+ var ccType = '';
327
+ Validation.creditCartTypes.each(function(cardType) {
328
+ $cardNumberPattern = cardType.value[0];
329
+ if($cardNumberPattern && v.match($cardNumberPattern)) {
330
+ ccType = cardType.key;
331
+
332
+ // Correct JCB/DI type since they has identical pattern:
333
+ if(ccType === 'DI' && v.indexOf('35') == 0) {
334
+ ccType = 'JCB';
335
+ }
336
+
337
+ throw $break;
338
+ }
339
+ });
340
+
341
+ if(acceptedTypes.indexOf(ccType) == -1) {
342
+ return false;
343
+ }
344
+
345
+ var ccTypeContainer = $(elm.id.substr(0,elm.id.indexOf('_cc_number')) + '_cc_type');
346
+ if (ccTypeContainer) {
347
+ ccTypeContainer.value = ccType;
348
+ }
349
+
350
+ return true;
351
+ }
352
+ );
353
+
354
+ Validation.add('eway-validate-phone', 'Please enter a valid phone number.', function(v, elm) {
355
+ return Validation.get('IsEmpty').test(v) || /^[0-9\+\*\(\)]{1,32}$/.test(v);
356
+ });
357
+
358
+ document.observe('dom:loaded', function(){
359
+ /*
360
+ var name = 'ewayrapid_saved_cc_owner';
361
+ // Validate card name
362
+ $('' + name).observe('keyup',function() {
363
+ if($('ewayrapid_saved_cc_owner').up()
364
+ .select('#advice-required-entry-ewayrapid_saved_cc_owner').length > 0) {
365
+ $('ewayrapid_saved_cc_owner').up()
366
+ .select('#advice-required-entry-ewayrapid_saved_cc_owner')[0].remove();
367
+ }
368
+ if($('ewayrapid_saved_cc_owner').value.length > 50) {
369
+ $('ewayrapid_saved_cc_owner').addClassName('validation-failed');
370
+ $('ewayrapid_saved_cc_owner').up().insert(
371
+ '<div id="advice-required-entry-ewayrapid_saved_cc_owner" ' +
372
+ 'class="validation-advice" style="">Maxlength of this field is 50.</div>');
373
+ } else {
374
+ // Remove notify
375
+ if($('ewayrapid_saved_cc_owner').up()
376
+ .select('#advice-required-entry-ewayrapid_saved_cc_owner').length > 0) {
377
+ $('ewayrapid_saved_cc_owner').up()
378
+ .select('#advice-required-entry-ewayrapid_saved_cc_owner')[0].remove();
379
+ }
380
+ // Remove class require on text field
381
+ $('ewayrapid_saved_cc_owner').removeClassName('validation-failed');
382
+ }
383
+ });
384
+
385
+ // First name
386
+ $('address_firstname').observe('keyup',function() {
387
+ if($('address_firstname').up()
388
+ .select('#advice-required-entry-address_firstname').length > 0) {
389
+ $('address_firstname').up()
390
+ .select('#advice-required-entry-address_firstname')[0].remove();
391
+ }
392
+ if($('address_firstname').value.length > 50) {
393
+ $('address_firstname').addClassName('validation-failed');
394
+ $('address_firstname').up().insert(
395
+ '<div id="advice-required-entry-address_firstname" ' +
396
+ 'class="validation-advice" style="">Maxlength of this field is 50.</div>');
397
+ } else {
398
+ // Remove notify
399
+ if($('ewayrapid_saved_cc_owner').up()
400
+ .select('#advice-required-entry-address_firstname').length > 0) {
401
+ $('address_firstname').up()
402
+ .select('#advice-required-entry-address_firstname')[0].remove();
403
+ }
404
+ // Remove class require on text field
405
+ $('address_firstname').removeClassName('validation-failed');
406
+ }
407
+ });
408
+
409
+ // Last name
410
+ $('address_lastname').observe('keyup',function() {
411
+ if($('address_lastname').up()
412
+ .select('#advice-required-entry-address_lastname').length > 0) {
413
+ $('address_lastname').up()
414
+ .select('#advice-required-entry-address_lastname')[0].remove();
415
+ }
416
+ if($('address_lastname').value.length > 50) {
417
+ $('address_lastname').addClassName('validation-failed');
418
+ $('address_lastname').up().insert(
419
+ '<div id="advice-required-entry-address_lastname" ' +
420
+ 'class="validation-advice" style="">Maxlength of this field is 50.</div>');
421
+ } else {
422
+ // Remove notify
423
+ if($('address_lastname').up()
424
+ .select('#advice-required-entry-address_lastname').length > 0) {
425
+ $('address_lastname').up()
426
+ .select('#advice-required-entry-address_lastname')[0].remove();
427
+ }
428
+ // Remove class require on text field
429
+ $('address_lastname').removeClassName('validation-failed');
430
+ }
431
+ });
432
+
433
+ // Company
434
+ $('address_company').observe('keyup',function() {
435
+ if($('address_company').up()
436
+ .select('#advice-required-entry-address_company').length > 0) {
437
+ $('address_company').up()
438
+ .select('#advice-required-entry-address_company')[0].remove();
439
+ }
440
+ if($('address_company').value.length > 50) {
441
+ $('address_company').addClassName('validation-failed');
442
+ $('address_company').up().insert(
443
+ '<div id="advice-required-entry-address_company" ' +
444
+ 'class="validation-advice" style="">Maxlength of this field is 50.</div>');
445
+ } else {
446
+ // Remove notify
447
+ if($('address_company').up()
448
+ .select('#advice-required-entry-address_company').length > 0) {
449
+ $('address_company').up()
450
+ .select('#advice-required-entry-address_company')[0].remove();
451
+ }
452
+ // Remove class require on text field
453
+ $('address_company').removeClassName('validation-failed');
454
+ }
455
+ });
456
+
457
+ // job description
458
+ $('address_job_description').observe('keyup',function() {
459
+ if($('address_job_description').up()
460
+ .select('#advice-required-entry-address_job_description').length > 0) {
461
+ $('address_job_description').up()
462
+ .select('#advice-required-entry-address_job_description')[0].remove();
463
+ }
464
+ if($('address_job_description').value.length > 50) {
465
+ $('address_job_description').addClassName('validation-failed');
466
+ $('address_job_description').up().insert(
467
+ '<div id="advice-required-entry-address_job_description" ' +
468
+ 'class="validation-advice" style="">Maxlength of this field is 50.</div>');
469
+ } else {
470
+ // Remove notify
471
+ if($('address_job_description').up()
472
+ .select('#advice-required-entry-address_job_description').length > 0) {
473
+ $('address_job_description').up()
474
+ .select('#advice-required-entry-address_job_description')[0].remove();
475
+ }
476
+ // Remove class require on text field
477
+ $('address_job_description').removeClassName('validation-failed');
478
+ }
479
+ });
480
+
481
+ // Phone
482
+ $('address_telephone').observe('keyup',function() {
483
+ if($('address_telephone').up()
484
+ .select('#advice-required-entry-address_telephone').length > 0) {
485
+ $('address_telephone').up()
486
+ .select('#advice-required-entry-address_telephone')[0].remove();
487
+ }
488
+ if($('address_telephone').value.length > 32) {
489
+ $('address_telephone').addClassName('validation-failed');
490
+ $('address_telephone').up().insert(
491
+ '<div id="advice-required-entry-address_telephone" ' +
492
+ 'class="validation-advice" style="">Maxlength of this field is 32.</div>');
493
+ } else {
494
+ // Remove notify
495
+ if($('address_telephone').up()
496
+ .select('#advice-required-entry-address_telephone').length > 0) {
497
+ $('address_telephone').up()
498
+ .select('#advice-required-entry-address_telephone')[0].remove();
499
+ }
500
+ // Remove class require on text field
501
+ $('address_telephone').removeClassName('validation-failed');
502
+ }
503
+ });
504
+ $('address_mobile').observe('keyup',function() {
505
+ if($('address_mobile').up()
506
+ .select('#advice-required-entry-address_mobile').length > 0) {
507
+ $('address_mobile').up()
508
+ .select('#advice-required-entry-address_mobile')[0].remove();
509
+ }
510
+ if($('address_mobile').value.length > 32) {
511
+ $('address_mobile').addClassName('validation-failed');
512
+ $('address_mobile').up().insert(
513
+ '<div id="advice-required-entry-address_mobile" ' +
514
+ 'class="validation-advice" style="">Maxlength of this field is 32.</div>');
515
+ } else {
516
+ // Remove notify
517
+ if($('address_mobile').up()
518
+ .select('#advice-required-entry-address_mobile').length > 0) {
519
+ $('address_mobile').up()
520
+ .select('#advice-required-entry-address_mobile')[0].remove();
521
+ }
522
+ // Remove class require on text field
523
+ $('address_mobile').removeClassName('validation-failed');
524
+ }
525
+ });
526
+ $('address_email').observe('keyup',function() {
527
+ if($('address_email').up()
528
+ .select('#advice-required-entry-address_email').length > 0) {
529
+ $('address_email').up()
530
+ .select('#advice-required-entry-address_email')[0].remove();
531
+ }
532
+ if($('address_email').value.length > 50) {
533
+ $('address_email').addClassName('validation-failed');
534
+ $('address_email').up().insert(
535
+ '<div id="advice-required-entry-address_email" ' +
536
+ 'class="validation-advice" style="">Maxlength of this field is 50.</div>');
537
+ } else {
538
+ // Remove notify
539
+ if($('address_email').up()
540
+ .select('#advice-required-entry-address_email').length > 0) {
541
+ $('address_email').up()
542
+ .select('#advice-required-entry-address_email')[0].remove();
543
+ }
544
+ // Remove class require on text field
545
+ $('address_email').removeClassName('validation-failed');
546
+ }
547
+ });
548
+ $('address_fax').observe('keyup',function() {
549
+ if($('address_fax').up()
550
+ .select('#advice-required-entry-address_fax').length > 0) {
551
+ $('address_fax').up()
552
+ .select('#advice-required-entry-address_fax')[0].remove();
553
+ }
554
+ if($('address_fax').value.length > 32) {
555
+ $('address_fax').addClassName('validation-failed');
556
+ $('address_fax').up().insert(
557
+ '<div id="advice-required-entry-address_fax" ' +
558
+ 'class="validation-advice" style="">Maxlength of this field is 32.</div>');
559
+ } else {
560
+ // Remove notify
561
+ if($('address_fax').up()
562
+ .select('#advice-required-entry-address_fax').length > 0) {
563
+ $('address_fax').up()
564
+ .select('#advice-required-entry-address_fax')[0].remove();
565
+ }
566
+ // Remove class require on text field
567
+ $('address_fax').removeClassName('validation-failed');
568
+ }
569
+ });
570
+ $('address_street_1').observe('keyup',function() {
571
+ if($('address_street_1').up()
572
+ .select('#advice-required-entry-address_street_1').length > 0) {
573
+ $('address_street_1').up()
574
+ .select('#advice-required-entry-address_street_1')[0].remove();
575
+ }
576
+ if($('address_street_1').value.length > 50) {
577
+ $('address_street_1').addClassName('validation-failed');
578
+ $('address_street_1').up().insert(
579
+ '<div id="advice-required-entry-address_street_1" ' +
580
+ 'class="validation-advice" style="">Maxlength of this field is 50.</div>');
581
+ } else {
582
+ // Remove notify
583
+ if($('address_street_1').up()
584
+ .select('#advice-required-entry-address_street_1').length > 0) {
585
+ $('address_street_1').up()
586
+ .select('#advice-required-entry-address_street_1')[0].remove();
587
+ }
588
+ // Remove class require on text field
589
+ $('address_street_1').removeClassName('validation-failed');
590
+ }
591
+ });
592
+ $('address_street_2').observe('keyup',function() {
593
+ if($('address_street_2').up()
594
+ .select('#advice-required-entry-address_street_2').length > 0) {
595
+ $('address_street_2').up()
596
+ .select('#advice-required-entry-address_street_2')[0].remove();
597
+ }
598
+ if($('address_street_2').value.length > 50) {
599
+ $('address_street_2').addClassName('validation-failed');
600
+ $('address_street_2').up().insert(
601
+ '<div id="advice-required-entry-address_street_2" ' +
602
+ 'class="validation-advice" style="">Maxlength of this field is 50.</div>');
603
+ } else {
604
+ // Remove notify
605
+ if($('address_street_2').up()
606
+ .select('#advice-required-entry-address_street_2').length > 0) {
607
+ $('address_street_2').up()
608
+ .select('#advice-required-entry-address_street_2')[0].remove();
609
+ }
610
+ // Remove class require on text field
611
+ $('address_street_2').removeClassName('validation-failed');
612
+ }
613
+ });
614
+ $('address_city').observe('keyup',function() {
615
+ if($('address_city').up()
616
+ .select('#advice-required-entry-address_city').length > 0) {
617
+ $('address_city').up()
618
+ .select('#advice-required-entry-address_city')[0].remove();
619
+ }
620
+ if($('address_city').value.length > 50) {
621
+ $('address_city').addClassName('validation-failed');
622
+ $('address_city').up().insert(
623
+ '<div id="advice-required-entry-address_city" ' +
624
+ 'class="validation-advice" style="">Maxlength of this field is 30.</div>');
625
+ } else {
626
+ // Remove notify
627
+ if($('address_city').up()
628
+ .select('#advice-required-entry-address_city').length > 0) {
629
+ $('address_city').up()
630
+ .select('#advice-required-entry-address_city')[0].remove();
631
+ }
632
+ // Remove class require on text field
633
+ $('address_city').removeClassName('validation-failed');
634
+ }
635
+ });
636
+ $('address_region').observe('keyup',function() {
637
+ if($('address_region').up()
638
+ .select('#advice-required-entry-address_region').length > 0) {
639
+ $('address_region').up()
640
+ .select('#advice-required-entry-address_region')[0].remove();
641
+ }
642
+ if($('address_region').value.length > 50) {
643
+ $('address_region').addClassName('validation-failed');
644
+ $('address_region').up().insert(
645
+ '<div id="advice-required-entry-address_region" ' +
646
+ 'class="validation-advice" style="">Maxlength of this field is 50.</div>');
647
+ } else {
648
+ // Remove notify
649
+ if($('address_region').up()
650
+ .select('#advice-required-entry-address_region').length > 0) {
651
+ $('address_region').up()
652
+ .select('#advice-required-entry-address_region')[0].remove();
653
+ }
654
+ // Remove class require on text field
655
+ $('address_region').removeClassName('validation-failed');
656
+ }
657
+ });
658
+ $('address_zip').observe('keyup',function() {
659
+ if($('address_zip').up()
660
+ .select('#advice-required-entry-address_zip').length > 0) {
661
+ $('address_zip').up()
662
+ .select('#advice-required-entry-address_zip')[0].remove();
663
+ }
664
+ if($('address_zip').value.length > 50) {
665
+ $('address_zip').addClassName('validation-failed');
666
+ $('address_zip').up().insert(
667
+ '<div id="advice-required-entry-address_zip" ' +
668
+ 'class="validation-advice" style="">Maxlength of this field is 30.</div>');
669
+ } else {
670
+ // Remove notify
671
+ if($('address_zip').up()
672
+ .select('#advice-required-entry-address_zip').length > 0) {
673
+ $('address_zip').up()
674
+ .select('#advice-required-entry-address_zip')[0].remove();
675
+ }
676
+ // Remove class require on text field
677
+ $('address_zip').removeClassName('validation-failed');
678
+ }
679
+ });
680
+ */
681
+
682
+ });
package.xml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>eWAY_Payment_Rapid31</name>
4
+ <version>1.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>The eWAY payment module - accept credit card payments, save cards, process refunds with eWAY's Rapid 3.1 Payment Gateway.</summary>
10
+ <description>The eWAY Rapid 3.1 payments module - made by eWAY for eWAY merchants:&#xD;
11
+ &#xD;
12
+ - It's free!&#xD;
13
+ - Fast and easy to set up and integrate&#xD;
14
+ - Smash chargebacks with global fraud protection&#xD;
15
+ - More options for your customers - more payment methods&#xD;
16
+ - Improve basket conversion with faster checkout features&#xD;
17
+ - Full Magento back-office integration, including manual orders and refunds&#xD;
18
+ - Supports eWAY's Sandbox for testing&#xD;
19
+ - Your customers can save their card details using eWAY's secure servers for faster checkout&#xD;
20
+ - Get help when and where you need it with 24/7 support&#xD;
21
+ &#xD;
22
+ Discover more at http://www.eway.com.au - payments made smarter!</description>
23
+ <notes>First full release of eWAY's Rapid 3.1 payment module. Process credit card payments with eWAY. Features:&#xD;
24
+ &#xD;
25
+ - Supports three connection types: Direct Connection, Transparent Redirect and Responsive Shared Page&#xD;
26
+ - Authorise and Capture or Authorise payments&#xD;
27
+ - Full and parial refunds&#xD;
28
+ - Use MasterPass and PayPal through eWAY, track your transactions in one place&#xD;
29
+ - Securely store customer's card details as tokens with eWAY&#xD;
30
+ - Integrated with eWAY's Beagle anti-fraud&#xD;
31
+ - Use eWAY's Live or Sandbox gateway</notes>
32
+ <authors><author><name>eWAY Payments</name><user>eWAYPayments</user><email>partner@eway.com.au</email></author></authors>
33
+ <date>2014-11-10</date>
34
+ <time>05:40:10</time>
35
+ <contents><target name="magecommunity"><dir name="Eway"><dir name="Rapid31"><dir name="Block"><dir name="Customer"><file name="Edit.php" hash="d7b1373e21796578ff7b6be9d0bf051d"/><file name="Mycards.php" hash="34df399b9c3e8a2752cf2989b188ae80"/></dir><dir name="Form"><dir name="Direct"><file name="Notsaved.php" hash="82a649f61fb2c4cc1d02a492aed401a2"/><file name="Saved.php" hash="1ce47a1e6edb31dda3388a9d0966f80d"/></dir><dir name="Sharedpage"><file name="Notsaved.php" hash="adde0646618931ee2f61eb107fa5bdd6"/><file name="Saved.php" hash="8de32b94291d6ce778adff5e5cb8bd0c"/></dir><dir name="Transparent"><file name="Notsaved.php" hash="c53c26ce01caaa88f7b66f5e4193cb46"/><file name="Saved.php" hash="46e0fc182e8f51fc84733c75e147038c"/></dir></dir><dir name="Info"><dir name="Direct"><file name="Notsaved.php" hash="76857a644cafc5b880a8a6930e9c8246"/><file name="Saved.php" hash="a9b1a08db461a9875cb67c24ec0d341d"/></dir><dir name="Sharedpage"><file name="Notsaved.php" hash="a6ef9de991184f5f009fe979d7d6e2fa"/><file name="Saved.php" hash="c4504bd457395b60545a797431008f51"/></dir><dir name="Transparent"><file name="Notsaved.php" hash="9ff716868b289d9eed866b130369df84"/><file name="Saved.php" hash="b83b7032ab677a04a3cb45421095a96f"/></dir></dir><dir name="Redirect"><file name="PaypalReview.php" hash="bdfff05cf75ce9739a5022ce9fd553ed"/><file name="Transparent.php" hash="d0f589b3e1d19ec02fbea141ff0aaa2e"/><file name="TransparentCheckout.php" hash="458b1b10da66953fe38a82af8832f136"/></dir><dir name="Sales"><dir name="Order"><file name="Grid.php" hash="aa7b83ca6d666a9fe34a1d762bd10eae"/></dir></dir></dir><dir name="Helper"><file name="Customer.php" hash="e480272d3c88f22b31102b2588110f32"/><file name="Data.php" hash="9e77b610fe6bbdc39d1ee86e977fb988"/></dir><dir name="Model"><dir name="Backend"><file name="Savedtokens.php" hash="55c209484a4ee56caadcde3633cb68dc"/></dir><file name="Config.php" hash="070d408e0e6f7b2c654c70d73b63714a"/><dir name="Customer"><file name="Savedtokens.php" hash="fec7133470f1c26cb284c12fd56e7991"/><file name="Token.php" hash="698166a7b2f9906a08842d15f01dc86c"/></dir><file name="EwayCron.php" hash="a426a8f6a7fde721eebfb4863b880b47"/><dir name="Field"><file name="CardDetails.php" hash="15d10ff8dec0590335b5c576df00554b"/><file name="Customer.php" hash="a5c32b1f06070ec3fe419ff9bc1a298a"/><file name="LineItem.php" hash="0ba66e9b1ecd1acb95c91d6192f9a8df"/><file name="Payment.php" hash="5226334c0d5fe39f27466b6113e8c091"/><file name="ShippingAddress.php" hash="3e46233fa343875dd061a158b3363c32"/></dir><file name="JsonSerializable.php" hash="630af4fb2b90d9e7808615bcca2b968a"/><file name="JsonSerializableAbstract.php" hash="15f72821079c02efe2f31ce52be22193"/><dir name="Method"><file name="Notsaved.php" hash="1f1e8475bfc71731cb8a69dc5cf0e19d"/><file name="Saved.php" hash="43662ca59e0f47edf1e3992330aed64a"/></dir><file name="Observer.php" hash="bef99e2b34a78c70daf4b1641b1b93dd"/><file name="RecurringProfile.php" hash="1d9b4b3d92664a885d222304b613d378"/><dir name="Request"><file name="Abstract.php" hash="b339384263b3139d7711fcf1288f9ca7"/><file name="Direct.php" hash="e2eec1c953aeebb85cc4cf5e8387f763"/><file name="Sharedpage.php" hash="106f32db2db1c6a09abbe049302c8a3d"/><file name="Token.php" hash="39bab32f5f8b428ec39e7e4f93ac1312"/><file name="Transparent.php" hash="e010ae30ba07a521c512db33c7b632fb"/></dir><file name="Response.php" hash="94346cfea6521bb45d8424dd1d54f750"/><dir name="System"><dir name="Config"><dir name="Backend"><file name="Orderstatus.php" hash="26a90ac9556ba210a73685a2b6edc5cd"/><file name="Validation.php" hash="39a895e6083f47872425e1616e75bee5"/></dir><dir name="Source"><file name="Cctype.php" hash="1b31bfaae980669c5ac0ba7e644ea515"/><file name="ConnectionType.php" hash="9060bb5013246eaf08c8ebf215b70a7d"/><file name="Mode.php" hash="a3f1dffc58540b31c5ab43a32452cce5"/><file name="Orderstatus.php" hash="75524debbd930498e278abd74c635fb9"/><file name="PaymentAction.php" hash="eaca860975abf97aa3ca49ba5f57d21b"/><file name="VerifyStatus.php" hash="28ff5c7c66c6b70c3923379ce3b82671"/></dir></dir></dir></dir><dir name="Test"><dir name="Model"><file name="Abstract.php" hash="5683575f264336a8c5f4c71768883b73"/><file name="Config.php" hash="98cc66555893a2a29a2ac093795dde17"/><file name="CustomerToken.php" hash="ed2f390b4579a33da70835356a718a79"/><file name="JsonSerializable.php" hash="d0735fda26a7461885c3cf8a5afcca2a"/><dir name="Request"><dir name="fixtures"><file name="default.yaml" hash="51c7dc1c509fcd1e4cf8dc0c49c9126a"/></dir></dir><file name="Request.php" hash="e19218a48cfd0fe5c8abaa0a99d5da08"/><file name="Response.php" hash="fd7b02d0e0f7a4a50862b6649d9faf41"/><dir name="TokenRequest"><dir name="fixtures"><file name="default.yaml" hash="51c7dc1c509fcd1e4cf8dc0c49c9126a"/></dir></dir><file name="TokenRequest.php" hash="965cc4efc952fd9d612d0a6dc924e43e"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="1677f97c007f6da3e67c5bd2c2779aa7"/></dir><file name="MycardsController.php" hash="6f91776f56decab5beedda246c54437f"/><file name="SharedpageController.php" hash="eae60af9c9c83656342ac300b6cc5895"/><file name="TestController.php" hash="68c0eed4d6142f00e6d67c719cd08abc"/><file name="TransparentController.php" hash="55a0efd1d7a6982ce9c260a1c57fbf6e"/></dir><dir name="etc"><file name="config.xml" hash="bada7cdf321bd5050c2167d7182e3f1d"/><file name="system.xml" hash="eceea5c968c5171561d65eb06c7beba0"/></dir><dir name="sql"><dir name="ewayrapid_setup"><file name="install-0.1.0.php" hash="54e7220359ce69267caafaffda73709e"/><file name="upgrade-0.1.0-1.0.0.php" hash="5183123b924cd233ee739c710da05bc2"/><file name="upgrade-1.0.0-1.0.1.php" hash="78aa6c5bf4704f65b0ced6d007539d0c"/><file name="upgrade-1.0.1-1.0.3.php" hash="9b7d1892e813b70bf82a79cd9a16ed29"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="ewayrapid"><file name="layout.xml" hash="b5ce2f60041814eb192c75deec216647"/></dir></dir><dir name="template"><dir name="ewayrapid"><dir name="form"><file name="direct_notsaved.phtml" hash="5a3aac5acc635e03083773b706330b4f"/><file name="direct_saved.phtml" hash="69070e4a3c9c7931154457029d996976"/></dir><dir name="info"><file name="direct_notsaved.phtml" hash="e222c4fb5900cd0bef303fc042b5ffb1"/><file name="direct_saved.phtml" hash="464ec1cda4fc6b297873f6dea0a0ea68"/></dir><dir name="pdf"><file name="direct_notsaved.phtml" hash="2e6a90083a15298e463b29c6120018c3"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><dir name="ewayrapid"><file name="layout.xml" hash="7e3b28ed8b30cbedab1a54b76ff394b0"/></dir></dir><dir name="template"><dir name="ewayrapid"><dir name="customer"><file name="edit.phtml" hash="4083e59fdbe25b9cb4b4571c7fb70a72"/><file name="mycards.phtml" hash="edef4b70420c7225e9ee0e8098a686e0"/></dir><dir name="form"><file name="direct_notsaved.phtml" hash="713fbcf4022c87f20f5756c0a3553a82"/><file name="direct_saved.phtml" hash="0335e638099347a967eb8f99c2c40c75"/><file name="sharedpage_notsaved.phtml" hash="84bcdff59da4888fde3d68b0e0044854"/><file name="sharedpage_saved.phtml" hash="3ec62b5d5847a5353b538de9b26900c1"/><file name="transparent_notsaved.phtml" hash="020a5b1b5348ad9bd99f807f68bd89c0"/><file name="transparent_saved.phtml" hash="1539252ba72afa2d58b5bc2916da0a8b"/></dir><dir name="info"><file name="direct_notsaved.phtml" hash="e3e6de0f60921687690a5c6225ddf8b6"/><file name="direct_saved.phtml" hash="e3e6de0f60921687690a5c6225ddf8b6"/><file name="sharedpage_notsaved.phtml" hash="e3e6de0f60921687690a5c6225ddf8b6"/><file name="sharedpage_saved.phtml" hash="b14f24a69d19129b34e5369dc075298d"/><file name="transparent_notsaved.phtml" hash="3b7c42bfbf960a89ebb5988c8c3f0e2d"/></dir><file name="js.phtml" hash="2412777214fbee8722678094ed08e0e2"/><dir name="redirect"><file name="review.phtml" hash="8f64dfebe347f45cc9cfa6be3554d7e7"/><file name="transparent.phtml" hash="cbebd7e80098232886a8b854b8c6bde5"/><file name="transparent_checkout.phtml" hash="20ae7dc582a9c430c84b381c9be8148d"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Eway_Rapid31.xml" hash="00ca307f8ad6f1bf88e9ad79ed9eac1f"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Eway_Rapid31.csv" hash="4cecdb8c8152a113467fb2ca48b5062f"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><file name="ewayrapid.css" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="ewayrapid.css" hash="751f4dc335e904908cea2368de394dc6"/></dir></dir></dir></dir></target><target name="mageweb"><dir name="js"><dir name="ewayrapid"><file name="eCrypt.js" hash="0a4a054505eb9789092afcfab5c50220"/><file name="ewayrapid.js" hash="fc871be5939c19acf0e455a8930fa93f"/></dir></dir></target></contents>
36
+ <compatible/>
37
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><extension><name>curl</name><min/><max/></extension></required></dependencies>
38
+ </package>
skin/adminhtml/default/default/ewayrapid.css ADDED
File without changes
skin/frontend/base/default/css/ewayrapid.css ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .sp-methods select.ewayrapid_saved_token {width: 180px; margin-right: 10px;}
2
+ #onestepcheckout-form #payment_form_ewayrapid_saved input.input-text:disabled,
3
+ .sp-methods input.input-text:disabled {background: rgb(235, 235, 228);} /* Default disabled color */
4
+
5
+ .sp-methods .form-list .control .input-box {margin-left: 170px;}
6
+
7
+ .form-list .help-disabled-cc {width: 290px; position: relative;}
8
+ .form-list .help-disabled-cc .tool-tip {width: 330px; top: -70px; left: 80px;}
9
+ .sp-methods .form-list { padding-left: 0px; }
10
+
11
+
12
+ .recurring-agree {float: left; margin: 0 4px 0 0; padding: 0; }
13
+ .lable-for-recurring {float: left;line-height: 14px; }
14
+
15
+ #transparent_card h3 { width: 40% !important; margin-left: 30% !important; }
16
+ #transparent_card ul.form-list { width: 40% !important; margin-left: 30%; border: 1px solid #bbafa0; padding: 20px 20px 20px 20px; }
17
+ #transparent_card ul.form-list select { width: 99% !important; }
18
+ #transparent_card label { text-align: left !important; }
19
+ #transparent_card input { width: 97% !important; }
20
+ #transparent_card .input-box { width: 98% !important; }
21
+ #transparent_card .cvv-what-is-this { margin-left: 15px;}
22
+ #payment_form_mastercard_saved .saved_token_mastercard_field { clear: both; display: block;}
23
+ .saved_token_mastercard_field #ewayrapid_saved_token { float: left; margin-right: 10px;}
24
+ #ul_payment_form_ewayrapid_notsaved { margin-left: 20px;}
25
+ #ewayrapid_saved_cc_type_exp_div .input-box .v-fix #advice-validate-cc-exp-ewayrapid_saved_expiration, #ewayrapid_notsaved_cc_type_exp_div .input-box .v-fix #advice-validate-cc-exp-ewayrapid_notsaved_expiration { width: 146px; word-wrap: break-word; margin-right: 0 !important; }
26
+
27
+ #ewayrapid_saved_cc_type_exp_div .input-box .v-fix #advice-required-entry-ewayrapid_saved_expiration_yr,
28
+ #ewayrapid_notsaved_cc_type_exp_div .input-box .v-fix #advice-required-entry-ewayrapid_notsaved_expiration_yr{ width: 79px; word-wrap: break-word; margin-right: 0 !important; }
29
+ .help-disabled-cc.validation-passed .card-number-help { margin-left: 5px;}
30
+
31
+ .eway-saved-div-box {float: left;}
32
+ .eway-saved-label-box {float: left;}
33
+ .eway-saved-edit-box { float: left;}
34
+ .eway-saved-select-box {float: left;margin-left: 10px;}