HC_PayByFinance - Version 1.0.2

Version Notes

First stable release

Download this release

Release Info

Developer Sandor Czettner
Extension HC_PayByFinance
Version 1.0.2
Comparing to
See all releases


Version 1.0.2

Files changed (82) hide show
  1. app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service.php +46 -0
  2. app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service/Edit.php +67 -0
  3. app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service/Edit/Form.php +54 -0
  4. app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service/Edit/Tab/Form.php +157 -0
  5. app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service/Edit/Tabs.php +66 -0
  6. app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service/Grid.php +198 -0
  7. app/code/local/HC/PayByFinance/Block/Checkout/Redirect.php +30 -0
  8. app/code/local/HC/PayByFinance/Block/Sales/Order/Totals.php +81 -0
  9. app/code/local/HC/PayByFinance/Block/Selector.php +150 -0
  10. app/code/local/HC/PayByFinance/Block/Status.php +130 -0
  11. app/code/local/HC/PayByFinance/Helper/Cart.php +94 -0
  12. app/code/local/HC/PayByFinance/Helper/Checkout.php +117 -0
  13. app/code/local/HC/PayByFinance/Helper/Data.php +306 -0
  14. app/code/local/HC/PayByFinance/Helper/Notification.php +92 -0
  15. app/code/local/HC/PayByFinance/Model/Calculator.php +144 -0
  16. app/code/local/HC/PayByFinance/Model/Config/Source/Catalog/Product/Finance.php +62 -0
  17. app/code/local/HC/PayByFinance/Model/Config/Source/Catalog/Product/Type.php +46 -0
  18. app/code/local/HC/PayByFinance/Model/Config/Source/Cms/Block.php +57 -0
  19. app/code/local/HC/PayByFinance/Model/Config/Source/Connectionmode.php +45 -0
  20. app/code/local/HC/PayByFinance/Model/Config/Source/Type.php +64 -0
  21. app/code/local/HC/PayByFinance/Model/Log.php +39 -0
  22. app/code/local/HC/PayByFinance/Model/Mysql4/Log.php +39 -0
  23. app/code/local/HC/PayByFinance/Model/Mysql4/Log/Collection.php +39 -0
  24. app/code/local/HC/PayByFinance/Model/Mysql4/Service.php +39 -0
  25. app/code/local/HC/PayByFinance/Model/Mysql4/Service/Collection.php +53 -0
  26. app/code/local/HC/PayByFinance/Model/Observer.php +202 -0
  27. app/code/local/HC/PayByFinance/Model/Paypal/Api/Nvp.php +54 -0
  28. app/code/local/HC/PayByFinance/Model/Paypal/Hostedpro/Request.php +68 -0
  29. app/code/local/HC/PayByFinance/Model/PaypalUk/Api/Nvp.php +54 -0
  30. app/code/local/HC/PayByFinance/Model/Post.php +123 -0
  31. app/code/local/HC/PayByFinance/Model/Post/Abstract.php +95 -0
  32. app/code/local/HC/PayByFinance/Model/Post/Live.php +32 -0
  33. app/code/local/HC/PayByFinance/Model/Post/Simulation.php +32 -0
  34. app/code/local/HC/PayByFinance/Model/Post/Test.php +32 -0
  35. app/code/local/HC/PayByFinance/Model/Resource/Setup.php +33 -0
  36. app/code/local/HC/PayByFinance/Model/Sales/Order/Creditmemo/Financeamount.php +64 -0
  37. app/code/local/HC/PayByFinance/Model/Sales/Order/Invoice/Financeamount.php +64 -0
  38. app/code/local/HC/PayByFinance/Model/Sales/Quote/Financeamount.php +121 -0
  39. app/code/local/HC/PayByFinance/Model/Sales/Quote/Totalcost.php +78 -0
  40. app/code/local/HC/PayByFinance/Model/Service.php +39 -0
  41. app/code/local/HC/PayByFinance/Model/Session.php +39 -0
  42. app/code/local/HC/PayByFinance/controllers/Adminhtml/Paybyfinance/ServiceController.php +223 -0
  43. app/code/local/HC/PayByFinance/controllers/CheckoutController.php +191 -0
  44. app/code/local/HC/PayByFinance/controllers/NotificationController.php +78 -0
  45. app/code/local/HC/PayByFinance/controllers/SelectorController.php +84 -0
  46. app/code/local/HC/PayByFinance/controllers/SessionController.php +72 -0
  47. app/code/local/HC/PayByFinance/controllers/StatusController.php +91 -0
  48. app/code/local/HC/PayByFinance/etc/adminhtml.xml +51 -0
  49. app/code/local/HC/PayByFinance/etc/config.xml +239 -0
  50. app/code/local/HC/PayByFinance/etc/system.xml +253 -0
  51. app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/abandoned.html +9 -0
  52. app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/accepted.html +11 -0
  53. app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/declined.html +20 -0
  54. app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/error.html +8 -0
  55. app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/information.html +24 -0
  56. app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/page-finance-options.html +98 -0
  57. app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/referred.html +8 -0
  58. app/code/local/HC/PayByFinance/sql/paybyfinance_setup/mysql4-install-1.0.2.php +214 -0
  59. app/code/local/HC/PayByFinance/sql/paybyfinance_setup/mysql4-upgrade-1.0.0-1.0.1.php +37 -0
  60. app/code/local/HC/PayByFinance/sql/paybyfinance_setup/mysql4-upgrade-1.0.1-1.0.2.php +31 -0
  61. app/design/adminhtml/default/default/layout/paybyfinance.xml +124 -0
  62. app/design/frontend/base/default/layout/paybyfinance.xml +194 -0
  63. app/design/frontend/base/default/template/checkout/cart.phtml +165 -0
  64. app/design/frontend/base/default/template/checkout/cart/totals.phtml +49 -0
  65. app/design/frontend/base/default/template/checkout/onepage/review/info.phtml +85 -0
  66. app/design/frontend/base/default/template/checkout/onepage/review/totals.phtml +47 -0
  67. app/design/frontend/base/default/template/paybyfinance/form.phtml +41 -0
  68. app/design/frontend/base/default/template/paybyfinance/sales/order/totals.phtml +0 -0
  69. app/design/frontend/base/default/template/paybyfinance/selector-no.phtml +5 -0
  70. app/design/frontend/base/default/template/paybyfinance/selector.phtml +489 -0
  71. app/design/frontend/base/default/template/paybyfinance/status.phtml +1 -0
  72. app/etc/modules/HC_PayByFinance.xml +9 -0
  73. package.xml +18 -0
  74. skin/frontend/base/default/css/paybyfinance-ie8.css +32 -0
  75. skin/frontend/base/default/css/paybyfinance.css +238 -0
  76. skin/frontend/base/default/images/paybyfinance/bullet.png +0 -0
  77. skin/frontend/base/default/images/paybyfinance/pointer-toggle.png +0 -0
  78. skin/frontend/base/default/images/paybyfinance/pointer.png +0 -0
  79. skin/frontend/base/default/images/paybyfinance/progress.png +0 -0
  80. skin/frontend/base/default/js/paybyfinance/checkout.js +67 -0
  81. skin/frontend/base/default/js/paybyfinance/functions.js +12 -0
  82. skin/frontend/base/default/js/paybyfinance/slider.js +165 -0
app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Healthy Websites
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Services grid widget container
20
+ *
21
+ * @uses Mage_Adminhtml_Block_Widget_Grid_Container
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Block_Adminhtml_Paybyfinance_Service
30
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
31
+ {
32
+ /**
33
+ * Constructor
34
+ *
35
+ * @return mixed Value.
36
+ */
37
+ public function __construct()
38
+ {
39
+ $this->_controller = 'adminhtml_paybyfinance_service';
40
+ $this->_blockGroup = 'paybyfinance';
41
+ $helper = Mage::helper('paybyfinance');
42
+ $this->_headerText = $helper->__('Services');
43
+ $this->_addButtonLabel = $helper->__('Add Service');
44
+ parent::__construct();
45
+ }
46
+ }
app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service/Edit.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Healthy Websites
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Edit form container for service
20
+ *
21
+ * @uses Mage_Adminhtml_Block_Widget_Form_Container
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Block_Adminhtml_Paybyfinance_Service_Edit
30
+ extends Mage_Adminhtml_Block_Widget_Form_Container
31
+ {
32
+ /**
33
+ * Constructor
34
+ *
35
+ * @return mixed Value.
36
+ */
37
+ public function __construct()
38
+ {
39
+ parent::__construct();
40
+
41
+ $this->_objectId = 'id';
42
+ $this->_controller = 'adminhtml_paybyfinance_service';
43
+ $this->_blockGroup = 'paybyfinance';
44
+ $helper = Mage::helper('paybyfinance');
45
+
46
+ $this->_updateButton('save', 'label', $helper->__('Save Service'));
47
+ $this->_updateButton('delete', 'label', $helper->__('Delete Service'));
48
+ }
49
+
50
+ /**
51
+ * Get Header Text
52
+ *
53
+ * @return string Header text.
54
+ */
55
+ public function getHeaderText()
56
+ {
57
+ $service = Mage::registry('service_data');
58
+ if ($service && $service->getId() ) {
59
+ return Mage::helper('paybyfinance')->__(
60
+ "Edit Service '%s'",
61
+ $this->htmlEscape(Mage::registry('service_data')->getName())
62
+ );
63
+ } else {
64
+ return Mage::helper('paybyfinance')->__('Add Service');
65
+ }
66
+ }
67
+ }
app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service/Edit/Form.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Healthy Websites
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Form widget block for service
20
+ *
21
+ * @uses Mage_Adminhtml_Block_Widget_Form
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Block_Adminhtml_Paybyfinance_Service_Edit_Form
30
+ extends Mage_Adminhtml_Block_Widget_Form
31
+ {
32
+ /**
33
+ * _prepareForm
34
+ *
35
+ * @return mixed Value.
36
+ */
37
+ protected function _prepareForm()
38
+ {
39
+ $form = new Varien_Data_Form(
40
+ array(
41
+ 'id' => 'edit_form',
42
+ 'action' => $this->getUrl(
43
+ '*/*/save',
44
+ array('id' => $this->getRequest()->getParam('id'))
45
+ ),
46
+ 'method' => 'post',
47
+ )
48
+ );
49
+
50
+ $form->setUseContainer(true);
51
+ $this->setForm($form);
52
+ return parent::_prepareForm();
53
+ }
54
+ }
app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service/Edit/Tab/Form.php ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Healthy Websites
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Data form for service
20
+ *
21
+ * @uses Mage_Adminhtml_Block_Widget_Form
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Block_Adminhtml_Paybyfinance_Service_Edit_Tab_Form
30
+ extends Mage_Adminhtml_Block_Widget_Form
31
+ {
32
+ /**
33
+ * _prepareForm
34
+ *
35
+ * @return mixed Value.
36
+ */
37
+ protected function _prepareForm()
38
+ {
39
+ $form = new Varien_Data_Form();
40
+ $helper = Mage::helper('paybyfinance');
41
+ $this->setForm($form);
42
+ $fieldset = $form->addFieldset(
43
+ 'service_form',
44
+ array('legend' => $helper->__('Service information'))
45
+ );
46
+
47
+ $fieldset->addField(
48
+ 'name', 'text', array(
49
+ 'label' => $helper->__('Name'),
50
+ 'class' => 'required-entry',
51
+ 'required' => true,
52
+ 'name' => 'name',
53
+ )
54
+ );
55
+
56
+ $fieldset->addField(
57
+ 'type', 'select', array(
58
+ 'label' => $helper->__('Service Type'),
59
+ 'class' => 'required-entry',
60
+ 'required' => true,
61
+ 'name' => 'type',
62
+ 'values' => Mage::getSingleton('paybyfinance/config_source_type')->toOptionArray(),
63
+ )
64
+ );
65
+
66
+ $fieldset->addField(
67
+ 'apr', 'text', array(
68
+ 'label' => $helper->__('APR'),
69
+ 'class' => 'required-entry',
70
+ 'required' => true,
71
+ 'name' => 'apr',
72
+ )
73
+ );
74
+
75
+ $fieldset->addField(
76
+ 'term', 'text', array(
77
+ 'label' => $helper->__('Term'),
78
+ 'class' => 'required-entry',
79
+ 'required' => true,
80
+ 'name' => 'term',
81
+ )
82
+ );
83
+
84
+ $fieldset->addField(
85
+ 'defer_term', 'text', array(
86
+ 'label' => $helper->__('Defer Term'),
87
+ 'class' => 'required-entry',
88
+ 'required' => true,
89
+ 'name' => 'defer_term',
90
+ )
91
+ );
92
+
93
+ $fieldset->addField(
94
+ 'option_term', 'text', array(
95
+ 'label' => $helper->__('Option Term'),
96
+ 'class' => 'required-entry',
97
+ 'required' => true,
98
+ 'name' => 'option_term',
99
+ )
100
+ );
101
+
102
+ $fieldset->addField(
103
+ 'deposit', 'text', array(
104
+ 'label' => $helper->__('Deposit (%)'),
105
+ 'class' => 'required-entry',
106
+ 'required' => true,
107
+ 'name' => 'deposit',
108
+ )
109
+ );
110
+
111
+ $fieldset->addField(
112
+ 'fee', 'text', array(
113
+ 'label' => $helper->__('Fee'),
114
+ 'class' => 'required-entry',
115
+ 'required' => true,
116
+ 'name' => 'fee',
117
+ )
118
+ );
119
+
120
+ $fieldset->addField(
121
+ 'min_amount', 'text', array(
122
+ 'label' => $helper->__('Minimum Amount'),
123
+ 'class' => 'required-entry',
124
+ 'required' => true,
125
+ 'name' => 'min_amount',
126
+ )
127
+ );
128
+
129
+ $fieldset->addField(
130
+ 'multiplier', 'text', array(
131
+ 'label' => $helper->__('Multiplier'),
132
+ 'class' => 'required-entry',
133
+ 'required' => true,
134
+ 'name' => 'multiplier',
135
+ )
136
+ );
137
+
138
+ $fieldset->addField(
139
+ 'rpm', 'text', array(
140
+ 'label' => $helper->__('Rpm'),
141
+ 'class' => 'required-entry',
142
+ 'required' => true,
143
+ 'name' => 'rpm',
144
+ )
145
+ );
146
+
147
+ if ( Mage::getSingleton('adminhtml/session')->getServiceData() ) {
148
+ $form->setValues(
149
+ Mage::getSingleton('adminhtml/session')->getServiceData()
150
+ );
151
+ Mage::getSingleton('adminhtml/session')->setServiceData(null);
152
+ } elseif ( Mage::registry('service_data') ) {
153
+ $form->setValues(Mage::registry('service_data')->getData());
154
+ }
155
+ return parent::_prepareForm();
156
+ }
157
+ }
app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service/Edit/Tabs.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Healthy Websites
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Tabs widget for service edit form
20
+ *
21
+ * @uses Mage_Adminhtml_Block_Widget_Tabs
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFInance_Block_Adminhtml_Paybyfinance_Service_Edit_Tabs
30
+ extends Mage_Adminhtml_Block_Widget_Tabs
31
+ {
32
+ /**
33
+ * Constructor.
34
+ *
35
+ * @return mixed Value.
36
+ */
37
+ public function __construct()
38
+ {
39
+ parent::__construct();
40
+ $this->setId('service_tabs');
41
+ $this->setDestElementId('edit_form');
42
+ $this->setTitle(
43
+ Mage::helper('paybyfinance')->__('Service Information')
44
+ );
45
+ }
46
+
47
+ /**
48
+ * _beforeToHtml
49
+ *
50
+ * @return mixed Value.
51
+ */
52
+ protected function _beforeToHtml()
53
+ {
54
+ $helper = Mage::helper('paybyfinance');
55
+ $blockId = 'paybyfinance/adminhtml_paybyfinance_service_edit_tab_form';
56
+ $this->addTab(
57
+ 'form_section', array(
58
+ 'label' => $helper->__('Service Information'),
59
+ 'title' => $helper->__('Service Information'),
60
+ 'content' => $this->getLayout()
61
+ ->createBlock($blockId)->toHtml(),
62
+ )
63
+ );
64
+ return parent::_beforeToHtml();
65
+ }
66
+ }
app/code/local/HC/PayByFinance/Block/Adminhtml/Paybyfinance/Service/Grid.php ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Healthy Websites
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Grid widget for services
20
+ *
21
+ * @uses Mage_Adminhtml_Block_Widget_Grid
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFInance_Block_Adminhtml_Paybyfinance_Service_Grid
30
+ extends Mage_Adminhtml_Block_Widget_Grid
31
+ {
32
+ /**
33
+ * Constructor
34
+ *
35
+ * @return void.
36
+ */
37
+ public function __construct()
38
+ {
39
+ parent::__construct();
40
+ $this->setId('ServiceGrid');
41
+ // This is the primary key of the database
42
+ $this->setDefaultSort('service_id');
43
+ $this->setDefaultDir('ASC');
44
+ $this->setSaveParametersInSession(true);
45
+ $this->setUseAjax(true);
46
+ }
47
+
48
+ /**
49
+ * _prepareCollection
50
+ *
51
+ * @return mixed Value.
52
+ */
53
+ protected function _prepareCollection()
54
+ {
55
+ $collection = Mage::getModel('paybyfinance/service')->getCollection();
56
+ $this->setCollection($collection);
57
+ return parent::_prepareCollection();
58
+ }
59
+
60
+ /**
61
+ * _prepareColumns
62
+ *
63
+ * @return mixed Value.
64
+ */
65
+ protected function _prepareColumns()
66
+ {
67
+ $helper = Mage::helper('paybyfinance');
68
+ $this->addColumn(
69
+ 'service_id', array(
70
+ 'header' => $helper->__('ID'),
71
+ 'align' => 'right',
72
+ 'width' => '50px',
73
+ 'index' => 'service_id',
74
+ )
75
+ );
76
+
77
+ $this->addColumn(
78
+ 'type', array(
79
+ 'header' => $helper->__('Type'),
80
+ 'align' => 'right',
81
+ 'type' => 'number',
82
+ 'index' => 'type',
83
+ )
84
+ );
85
+
86
+ $this->addColumn(
87
+ 'name', array(
88
+ 'header' => $helper->__('Name'),
89
+ 'align' => 'left',
90
+ 'index' => 'name',
91
+ )
92
+ );
93
+
94
+ $this->addColumn(
95
+ 'apr', array(
96
+ 'header' => $helper->__('APR'),
97
+ 'align' => 'right',
98
+ 'type' => 'number',
99
+ 'index' => 'apr',
100
+ )
101
+ );
102
+
103
+ $this->addColumn(
104
+ 'term', array(
105
+ 'header' => $helper->__('Term'),
106
+ 'align' => 'right',
107
+ 'type' => 'number',
108
+ 'index' => 'term',
109
+ )
110
+ );
111
+
112
+ $this->addColumn(
113
+ 'defer_term', array(
114
+ 'header' => $helper->__('Defer Term'),
115
+ 'align' => 'right',
116
+ 'type' => 'number',
117
+ 'index' => 'defer_term',
118
+ )
119
+ );
120
+
121
+ $this->addColumn(
122
+ 'option_term', array(
123
+ 'header' => $helper->__('Option Term'),
124
+ 'align' => 'right',
125
+ 'type' => 'number',
126
+ 'index' => 'option_term',
127
+ )
128
+ );
129
+
130
+ $this->addColumn(
131
+ 'deposit', array(
132
+ 'header' => $helper->__('Deposit (%)'),
133
+ 'align' => 'right',
134
+ 'type' => 'number',
135
+ 'index' => 'deposit',
136
+ )
137
+ );
138
+
139
+ $this->addColumn(
140
+ 'fee', array(
141
+ 'header' => $helper->__('Fee'),
142
+ 'align' => 'right',
143
+ 'type' => 'number',
144
+ 'index' => 'fee',
145
+ )
146
+ );
147
+
148
+ $this->addColumn(
149
+ 'minimum_amount', array(
150
+ 'header' => $helper->__('Minimum Amount'),
151
+ 'align' => 'right',
152
+ 'type' => 'number',
153
+ 'index' => 'min_amount',
154
+ )
155
+ );
156
+
157
+ $this->addColumn(
158
+ 'multiplier', array(
159
+ 'header' => $helper->__('Multiplier'),
160
+ 'align' => 'right',
161
+ 'index' => 'multiplier',
162
+ )
163
+ );
164
+
165
+ $this->addColumn(
166
+ 'rpm', array(
167
+ 'header' => $helper->__('RPM'),
168
+ 'align' => 'right',
169
+ 'type' => 'number',
170
+ 'index' => 'rpm',
171
+ )
172
+ );
173
+
174
+ return parent::_prepareColumns();
175
+ }
176
+
177
+ /**
178
+ * Get Row Url
179
+ *
180
+ * @param object $row Row Object.
181
+ *
182
+ * @return string Value.
183
+ */
184
+ public function getRowUrl($row)
185
+ {
186
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
187
+ }
188
+
189
+ /**
190
+ * Get Grid Url
191
+ *
192
+ * @return string Value.
193
+ */
194
+ public function getGridUrl()
195
+ {
196
+ return $this->getUrl('*/*/grid', array('_current'=>true));
197
+ }
198
+ }
app/code/local/HC/PayByFinance/Block/Checkout/Redirect.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * To render the redirect form
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Block_Checkout_Redirect extends Mage_Core_Block_Template
28
+ {
29
+
30
+ }
app/code/local/HC/PayByFinance/Block/Sales/Order/Totals.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Totals on cart and checkout
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFInance_Block_Sales_Order_Totals extends Mage_Core_Block_Template
28
+ {
29
+ /**
30
+ * Init totals
31
+ *
32
+ * @return $this
33
+ */
34
+ public function initTotals()
35
+ {
36
+ $parent = $this->getParentBlock();
37
+
38
+ $totals = array();
39
+ $totals['finance_amount'] = array(
40
+ 'label' => Mage::helper('paybyfinance')->__('Financed Amount'),
41
+ 'before' => 'grand_total'
42
+ );
43
+ foreach ($totals as $code => $total) {
44
+ if (($value = (float) $parent->getSource()->getData($code)) != 0) {
45
+ $this->_addTotal($code, $value, $total);
46
+ }
47
+ }
48
+
49
+ return $this;
50
+ }
51
+
52
+ /**
53
+ * Add totals to the right place
54
+ *
55
+ * @param string $code Code
56
+ * @param string $value Value
57
+ * @param string $params Parameters (before, after)
58
+ *
59
+ * @return $this
60
+ */
61
+ protected function _addTotal($code, $value, $params = null)
62
+ {
63
+ $after = (isset($params['after']) ? $params['after'] : null);
64
+ $before = (isset($params['before']) ? $params['before'] : null);
65
+ $total = new Varien_Object(
66
+ array(
67
+ 'code' => $code,
68
+ 'label' => $params['label'],
69
+ 'strong' => (isset($params['strong']) ? $params['strong'] : false),
70
+ 'value' => $value
71
+ )
72
+ );
73
+ if (is_null($before)) {
74
+ $this->getParentBlock()->addTotal($total, $after);
75
+ } else {
76
+ $this->getParentBlock()->addTotalBefore($total, $before);
77
+ }
78
+
79
+ return $this;
80
+ }
81
+ }
app/code/local/HC/PayByFinance/Block/Selector.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Selector block class
20
+ *
21
+ * @uses Mage_Core_Block_Template
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Block_Selector extends Mage_Core_Block_Template
30
+ {
31
+
32
+ protected $_services;
33
+ protected $_amount;
34
+
35
+ /**
36
+ * Get available services
37
+ *
38
+ * @return HC_PayByFinance_Model_Mysql4_Service_Collection Services.
39
+ */
40
+ public function getServices()
41
+ {
42
+ if (!isset($this->_services)) {
43
+ $amount = $this->getAmount();
44
+ $this->_services = Mage::getModel('paybyfinance/service')
45
+ ->getCollection()
46
+ ->addPriceFilter($amount)
47
+ ->load();
48
+ }
49
+
50
+ return $this->_services;
51
+ }
52
+
53
+ /**
54
+ * getAmount
55
+ *
56
+ * @return float Amount.
57
+ */
58
+ protected function getAmount()
59
+ {
60
+ if (!isset($this->_amount)) {
61
+ if ($product = Mage::registry('current_product')) {
62
+ // We are on the product page
63
+ $this->_amount = $product->getFinalPrice();
64
+ } else {
65
+ $cartHelper = Mage::helper('paybyfinance/cart');
66
+ $this->_amount = $cartHelper->getEligibleAmount()
67
+ + $cartHelper->getQuoteAdditionalAmount();
68
+ }
69
+ }
70
+
71
+ return $this->_amount;
72
+ }
73
+
74
+ /**
75
+ * getJSON
76
+ *
77
+ * @return string Value.
78
+ */
79
+ public function getJSON()
80
+ {
81
+ $helper = Mage::helper('paybyfinance');
82
+
83
+ return $helper->getSelectorJSON(
84
+ $this->getServices(), $this->getAmount()
85
+ );
86
+ }
87
+
88
+ /**
89
+ * get current product or false if not on product page
90
+ *
91
+ * @return mixed Value.
92
+ */
93
+ public function getProduct()
94
+ {
95
+ $product = Mage::registry('current_product');
96
+
97
+ return $product;
98
+ }
99
+
100
+ /**
101
+ * Fixed deposit only
102
+ *
103
+ * @return integer 0 if No, 1 if Yes
104
+ */
105
+ public function getIsFixedDepositOnly()
106
+ {
107
+ $helper = Mage::helper('paybyfinance');
108
+ $fixed = Mage::getStoreConfig($helper::XML_PATH_FIXED_DEPOSIT);
109
+ return $fixed;
110
+ }
111
+
112
+ /**
113
+ * Render block HTML
114
+ *
115
+ * @return string
116
+ */
117
+ protected function _toHtml()
118
+ {
119
+ if (!$this->getProduct() && $this->getServices()->getSize() == 0) {
120
+ $this->setTemplate('paybyfinance/selector-no.phtml');
121
+ }
122
+
123
+ return parent::_toHtml();
124
+ }
125
+
126
+ /**
127
+ * Get Retailer Name as appears on FCA register
128
+ *
129
+ * @return string Retailer Name
130
+ */
131
+ public function getRetailerName()
132
+ {
133
+ $helper = Mage::helper('paybyfinance');
134
+ $name = Mage::getStoreConfig($helper::XML_PATH_ACCOUNT_RETAILERNAME);
135
+ return $name;
136
+ }
137
+
138
+ /**
139
+ * Get Trading Name
140
+ *
141
+ * @return string Trading Name
142
+ */
143
+ public function getTradingName()
144
+ {
145
+ $helper = Mage::helper('paybyfinance');
146
+ $name = Mage::getStoreConfig($helper::XML_PATH_ACCOUNT_TRADINGNAME);
147
+ return $name;
148
+ }
149
+
150
+ }
app/code/local/HC/PayByFinance/Block/Status.php ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Block class for status pages
20
+ *
21
+ * @uses Mage_Core_Block_Template
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Block_Status extends Mage_Core_Block_Template
30
+ {
31
+ private $_type;
32
+ private $_order;
33
+
34
+ /**
35
+ * Set block type
36
+ *
37
+ * @param string $type Block type
38
+ *
39
+ * @return void
40
+ */
41
+ public function setType($type)
42
+ {
43
+ $this->_type = $type;
44
+ }
45
+
46
+ /**
47
+ * Get CMS block based on layout xml
48
+ *
49
+ * @return string HTML output.
50
+ *
51
+ * @throws Exception Misconfiguration
52
+ */
53
+ public function getCmsBlock()
54
+ {
55
+ $helper = Mage::helper('paybyfinance');
56
+ switch ($this->_type) {
57
+ case 'accepted':
58
+ $id = Mage::getStoreConfig($helper::XML_PATH_BLOCK_ACCEPTED);
59
+ break;
60
+ case 'referred':
61
+ $id = Mage::getStoreConfig($helper::XML_PATH_BLOCK_REFERRED);
62
+ break;
63
+ case 'declined':
64
+ $id = Mage::getStoreConfig($helper::XML_PATH_BLOCK_DECLINED);
65
+ break;
66
+ case 'abandoned':
67
+ $id = Mage::getStoreConfig($helper::XML_PATH_BLOCK_ABANDONED);
68
+ break;
69
+ case 'error':
70
+ $id = Mage::getStoreConfig($helper::XML_PATH_BLOCK_ERROR);
71
+ break;
72
+ default:
73
+ throw new Exception("Undefined status block type.", 1);
74
+ }
75
+
76
+ $block = Mage::getModel('cms/block')->load($id);
77
+ $this->_order = Mage::getModel('sales/order')->load(
78
+ Mage::getSingleton('paybyfinance/session')->getData('order_id')
79
+ );
80
+ $helper = Mage::helper('cms');
81
+ $processor = $helper->getBlockTemplateProcessor();
82
+ $processor->setVariables(array('order_id' => $this->getOrderIdText()));
83
+ $html = $processor->filter($block->getContent());
84
+
85
+ return $html;
86
+ }
87
+
88
+ /**
89
+ * Get order ID text based on the circumstances
90
+ *
91
+ * @return string Link or the order increment id
92
+ */
93
+ private function getOrderIdText()
94
+ {
95
+ if ($this->canPrint()) {
96
+ $url = $this->getUrl(
97
+ 'sales/order/view/',
98
+ array(
99
+ 'order_id' => $this->_order->getId(),
100
+ '_secure' => true
101
+ )
102
+ );
103
+
104
+ return $this->__('<a href="%s">%s</a>', $url, $this->_order->getIncrementId());
105
+ }
106
+
107
+ return $this->_order->getIncrementId();
108
+ }
109
+
110
+ /**
111
+ * Whatever we can print the order link or not
112
+ *
113
+ * @return bool Decision
114
+ */
115
+ private function canPrint()
116
+ {
117
+ if (!$this->_order) {
118
+ return false;
119
+ }
120
+ if (in_array(
121
+ $this->_order->getState(),
122
+ Mage::getSingleton('sales/order_config')->getInvisibleOnFrontStates()
123
+ )) {
124
+ return false;
125
+ }
126
+
127
+ return Mage::getSingleton('customer/session')->isLoggedIn();
128
+ }
129
+
130
+ }
app/code/local/HC/PayByFinance/Helper/Cart.php ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Data helper for cart functions
20
+ *
21
+ * @uses Mage_Core_Helper_Data
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Helper_Cart extends Mage_Core_Helper_Data
30
+ {
31
+
32
+ /**
33
+ * getEligibleProducts
34
+ *
35
+ * @param Collection $items Product collection or null
36
+ *
37
+ * @return array Eligible products.
38
+ */
39
+ public function getEligibleProducts($items = null)
40
+ {
41
+ $cart = Mage::getModel('checkout/cart')->getQuote();
42
+ if ($items === null) {
43
+ $items = $cart->getAllItems();
44
+ }
45
+ $helper = Mage::helper('paybyfinance');
46
+ $eligible = array();
47
+
48
+ foreach ($items as $item) {
49
+ if ($helper->isProductEligible($item)) {
50
+ $eligible[] = $item;
51
+ }
52
+ }
53
+
54
+ return $eligible;
55
+ }
56
+
57
+ /**
58
+ * Get any additional price into the eligible amount
59
+ *
60
+ * @return double Additional price
61
+ */
62
+ public function getQuoteAdditionalAmount()
63
+ {
64
+ $additional = 0;
65
+ $helper = Mage::helper('paybyfinance');
66
+
67
+ $shippingAddress = Mage::getModel('checkout/cart')->getQuote()->getShippingAddress();
68
+ if (Mage::getStoreConfig($helper::XML_PATH_INCLUDE_SHIPPING)) {
69
+ $additional += $shippingAddress->getShippingAmount();
70
+ }
71
+ $additional += $shippingAddress->getDiscountAmount();
72
+ $additional -= $shippingAddress->getGiftCardsAmount();
73
+
74
+ return $additional;
75
+ }
76
+
77
+ /**
78
+ * getEligibleAmount
79
+ *
80
+ * @param Collection $items Product collection or null
81
+ *
82
+ * @return float Sum of subtotal of eligible products.
83
+ */
84
+ public function getEligibleAmount($items = null)
85
+ {
86
+ $amount = 0;
87
+ $items = $this->getEligibleProducts($items);
88
+ foreach ($items as $item) {
89
+ $amount += $item->getRowTotalInclTax();
90
+ }
91
+ return $amount;
92
+ }
93
+
94
+ }
app/code/local/HC/PayByFinance/Helper/Checkout.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Data helper for checkout functions
20
+ *
21
+ * @uses Mage_Core_Helper_Data
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Helper_Checkout extends Mage_Core_Helper_Data
30
+ {
31
+
32
+ /**
33
+ * Processes return status from the CheckoutController
34
+ *
35
+ * @param Mage_Sales_Model_Order $order order object
36
+ * @param array $parameters get/post parameters
37
+ *
38
+ * @throws Exception Invalid decision code
39
+ *
40
+ * @return string Redirect URL.
41
+ */
42
+ public function processReturnStatus($order, $parameters)
43
+ {
44
+ $helper = Mage::helper('paybyfinance');
45
+ switch ($parameters['decision']) {
46
+ case 'ACCEPTED':
47
+ $status = Mage::getStoreConfig($helper::XML_PATH_STATUS_ACCEPTED);
48
+ $redirectUrl = 'paybyfinance/status/accepted';
49
+ break;
50
+ case 'DECLINED':
51
+ $status = Mage::getStoreConfig($helper::XML_PATH_STATUS_DECLINED);
52
+ $redirectUrl = 'paybyfinance/status/declined';
53
+ break;
54
+ case 'REFERRED':
55
+ $status = Mage::getStoreConfig($helper::XML_PATH_STATUS_REFERRED);
56
+ $redirectUrl = 'paybyfinance/status/referred';
57
+ break;
58
+ case 'VALIDATION_ERROR':
59
+ $status = Mage::getStoreConfig($helper::XML_PATH_STATUS_ERROR);
60
+ $redirectUrl = 'paybyfinance/status/error';
61
+ break;
62
+ case 'ABANDON':
63
+ $status = Mage::getStoreConfig($helper::XML_PATH_STATUS_ABANDONED);
64
+ $redirectUrl = 'paybyfinance/status/abandoned';
65
+ break;
66
+ default:
67
+ throw new Exception("Invalid decision code", 1);
68
+ }
69
+
70
+
71
+ $message .= 'id: ' . $parameters['id'];
72
+ $message .= ' id2: ' . $parameters['id2'];
73
+ $message .= "\n" . $parameters['decision'];
74
+ $message .= "\nApplication: " . $parameters['applicationNo'];
75
+ $message .= "\nAuthorization: " . $parameters['authorisationcode'];
76
+ $message .= "\nSURL: " . $parameters['sourceurl'];
77
+ $message .= "\nReason: " . $parameters['Errreason'];
78
+ $message .= "\nMessage: " . $parameters['Errtext'];
79
+
80
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
81
+ $order->setState($state, $status);
82
+ $order->addStatusToHistory($status, nl2br(trim($message)), false);
83
+ $order->save();
84
+
85
+ return $redirectUrl;
86
+ }
87
+
88
+ /**
89
+ * Processes unexpected return from the CheckoutController
90
+ *
91
+ * @param Mage_Sales_Model_Order $order order object
92
+ * @param array $parameters get/post parameters
93
+ *
94
+ * @throws Exception Invalid decision code
95
+ *
96
+ * @return nil
97
+ */
98
+ public function setUnexpectedError($order, $parameters)
99
+ {
100
+ $helper = Mage::helper('paybyfinance');
101
+ $status = Mage::getStoreConfig($helper::XML_PATH_STATUS_ABANDONED);
102
+ $message .= 'id: ' . $parameters['id'];
103
+ $message .= ' id2: ' . $parameters['id2'];
104
+ $message .= "\n" . $parameters['decision'];
105
+ $message .= "\nApplication: " . $parameters['applicationNo'];
106
+ $message .= "\nAuthorization: " . $parameters['authorisationcode'];
107
+ $message .= "\nSURL: " . $parameters['sourceurl'];
108
+ $message .= "\nReason: " . $parameters['Errreason'];
109
+ $message .= "\nMessage: " . $parameters['Errtext'];
110
+
111
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
112
+ $order->setState($state, $status);
113
+ $order->addStatusToHistory($status, nl2br(trim($message)), false);
114
+ $order->save();
115
+ }
116
+
117
+ }
app/code/local/HC/PayByFinance/Helper/Data.php ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Data helper for storing and getting configuration
20
+ *
21
+ * @uses Mage_Core_Helper_Data
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Helper_Data extends Mage_Core_Helper_Data
30
+ {
31
+ const XML_PATH_PRODUCTTYPES = 'hc_paybyfinance/general/enable_producttypes';
32
+ const XML_PATH_MINIMUM_PRICE_PRODUCT = 'hc_paybyfinance/general/minimum_price_product';
33
+ const XML_PATH_MINIMUM_PRICE_BASKET = 'hc_paybyfinance/general/minimum_price_basket';
34
+ const XML_PATH_FIXED_DEPOSIT = 'hc_paybyfinance/general/fixed_deposit';
35
+ const XML_PATH_INCLUDE_SHIPPING = 'hc_paybyfinance/general/include_shipping';
36
+ const XML_PATH_STATUS_ACCEPTED = 'hc_paybyfinance/order_status/accepted';
37
+ const XML_PATH_STATUS_REFERRED = 'hc_paybyfinance/order_status/referred';
38
+ const XML_PATH_STATUS_DECLINED = 'hc_paybyfinance/order_status/declined';
39
+ const XML_PATH_STATUS_ABANDONED = 'hc_paybyfinance/order_status/abandoned';
40
+ const XML_PATH_STATUS_ERROR = 'hc_paybyfinance/order_status/error';
41
+ const XML_PATH_BLOCK_INFO = 'hc_paybyfinance/blocks_info/information';
42
+ const XML_PATH_BLOCK_ACCEPTED = 'hc_paybyfinance/blocks_info/accepted';
43
+ const XML_PATH_BLOCK_REFERRED = 'hc_paybyfinance/blocks_info/referred';
44
+ const XML_PATH_BLOCK_DECLINED = 'hc_paybyfinance/blocks_info/declined';
45
+ const XML_PATH_BLOCK_ABANDONED = 'hc_paybyfinance/blocks_info/abandoned';
46
+ const XML_PATH_BLOCK_ERROR = 'hc_paybyfinance/blocks_info/error';
47
+ const XML_PATH_PBF_ACCOUNT_ID1 = 'hc_paybyfinance/account/id1';
48
+ const XML_PATH_PBF_ACCOUNT_ID2 = 'hc_paybyfinance/account/id2';
49
+ const XML_PATH_CONNECTION_MODE = 'hc_paybyfinance/account/connectionmode';
50
+ const XML_PATH_ERROR_NOTIFY_EMAIL = 'hc_paybyfinance/account/erroremail';
51
+ const XML_PATH_ACCOUNT_RETAILERNAME = 'hc_paybyfinance/account/retailername';
52
+ const XML_PATH_ACCOUNT_TRADINGNAME = 'hc_paybyfinance/account/tradingname';
53
+ const ERROR_LOG_PATH_LOG = 'paybyfinance/paybyfinance-log.log';
54
+ const ERROR_LOG_PATH_POST = 'paybyfinance/paybyfinance-post.log';
55
+ const ERROR_LOG_PATH_NOTIFICATION = 'paybyfinance/paybyfinance-notification.log';
56
+
57
+ private $_types;
58
+
59
+ /**
60
+ * Get JSON for the selector JS data
61
+ *
62
+ * @param _Collection $services Services
63
+ * @param float $amount Financeable Amount.
64
+ *
65
+ * @return string JSON.
66
+ */
67
+ public function getSelectorJSON($services, $amount)
68
+ {
69
+ $session = Mage::getSingleton('paybyfinance/session');
70
+ $json = array(
71
+ 'services' => array(),
72
+ 'amount' => $amount,
73
+ 'enabled' => $session->getData('enabled'),
74
+ 'service' => $session->getData('service'),
75
+ 'deposit' => $session->getData('deposit'),
76
+ );
77
+ foreach ($services as $service) {
78
+ $types[$service->getType()] = $this->getTypeName((int) $service->getType());
79
+ $json['terms'][] = array(
80
+ 'term' => $service->getTerm(),
81
+ 'service_id' => $service->getId(),
82
+ 'type' => $service->getType(),
83
+ );
84
+ $json['services'][$service->getId()] = array(
85
+ 'name' => $service->getName(),
86
+ 'type' => $service->getType(),
87
+ 'apr' => $service->getApr(),
88
+ 'term' => $service->getTerm(),
89
+ 'defer_term' => $service->getDeferTerm(),
90
+ 'option_term' => $service->getOptionTerm(),
91
+ 'deposit' => $service->getDeposit(),
92
+ 'fee' => $service->getFee(),
93
+ 'min_amount' => $service->getMinAmount(),
94
+ 'multiplier' => $service->getMultiplier(),
95
+ 'rpm' => $service->getRpm(),
96
+ );
97
+ }
98
+
99
+ usort(
100
+ $json['terms'],
101
+ function ($a, $b) {
102
+ if ($a['term'] == $b['term']) {
103
+ return 0;
104
+ }
105
+ return ($a['term'] < $b['term']) ? -1 : 1;
106
+ }
107
+ );
108
+
109
+ foreach ($types as $key => $value) {
110
+ $json['types'][] = array(
111
+ 'type' => $key,
112
+ 'name' => $value,
113
+ );
114
+ $terms = null;
115
+ foreach ($json['terms'] as $termkey => $termvalue) {
116
+ if ($termvalue['type'] == $key) {
117
+ $terms[] = $termvalue;
118
+ }
119
+ }
120
+ $json['subterms'][] = $terms;
121
+ }
122
+
123
+ return json_encode($json);
124
+ }
125
+
126
+ /**
127
+ * Get type name by type id
128
+ *
129
+ * @param integer $type type id, for example 31
130
+ *
131
+ * @return string Type name
132
+ */
133
+ public function getTypeName($type)
134
+ {
135
+ if (!isset($this->_types)) {
136
+ $this->_types = Mage::getModel('paybyfinance/config_source_type')->toFrontendArray();
137
+ }
138
+
139
+ return $this->_types[(integer) $type];
140
+ }
141
+
142
+ /**
143
+ * Is product eligible for finance?
144
+ *
145
+ * @param Mage_Sales_Model_Quote_Item|Mage_Catalog_Model_Product $item Quote item.
146
+ *
147
+ * @return boolean Eligible or not.
148
+ */
149
+ public function isProductEligible($item)
150
+ {
151
+ $options = Mage::getSingleton('paybyfinance/config_source_catalog_product_finance');
152
+
153
+ if ( $item instanceof Mage_Sales_Model_Quote_Item
154
+ || $item instanceof Mage_Sales_Model_Order_Item
155
+ ) {
156
+ $product = $item->getProduct();
157
+ } elseif ($item instanceof Mage_Catalog_Model_Product) {
158
+ $product = $item;
159
+ }
160
+
161
+ if ($product->getPaybyfinanceEnable() == $options::VALUES_DISABLE) {
162
+ return;
163
+ }
164
+
165
+ switch ($product->getPaybyfinanceEnable()) {
166
+ case $options::VALUES_DISABLE:
167
+ return false;
168
+ case $options::VALUES_ENABLE:
169
+ return true;
170
+ case $options::VALUES_CONFIG:
171
+ default:
172
+ // Calculate based on the configuration in the backend
173
+ break;
174
+ }
175
+
176
+ $helper = Mage::helper('paybyfinance');
177
+ $types = explode(',', Mage::getStoreConfig($helper::XML_PATH_PRODUCTTYPES));
178
+ if (!in_array($product->getTypeID(), $types)) {
179
+ return false;
180
+ }
181
+ $minPriceProduct = Mage::getStoreConfig($helper::XML_PATH_MINIMUM_PRICE_PRODUCT);
182
+ if ($product->getFinalPrice() < $minPriceProduct) {
183
+ return false;
184
+ }
185
+
186
+ return true;
187
+ }
188
+
189
+ /**
190
+ * Logging data to the specified log file
191
+ *
192
+ * @param string|array $data As returned by print_r or any text to log
193
+ * @param string $type log type
194
+ *
195
+ * @throws Exception
196
+ *
197
+ * @return void
198
+ */
199
+ public function log($data, $type = 'log')
200
+ {
201
+ if (!is_array($data) && !is_object($data)) {
202
+ $data = $this->_processUserInput($data);
203
+ } else {
204
+ throw new Exception("Usage of array or object is discouraged for security reasons.", 1);
205
+ }
206
+
207
+ $this->logDB($data, $type);
208
+
209
+ if (!file_exists(Mage::getBaseDir('var').'/log')) {
210
+ mkdir(Mage::getBaseDir('var').'/log');
211
+ }
212
+ if (!file_exists(Mage::getBaseDir('var').'/log/paybyfinance')) {
213
+ mkdir(Mage::getBaseDir('var').'/log/paybyfinance');
214
+ }
215
+ if ($type == 'log') {
216
+ Mage::log($data, null, self::ERROR_LOG_PATH_LOG);
217
+ }
218
+
219
+ if ($type == 'post') {
220
+ Mage::log($data, null, self::ERROR_LOG_PATH_POST);
221
+ }
222
+
223
+ if ($type == 'notification') {
224
+ Mage::log($data, null, self::ERROR_LOG_PATH_NOTIFICATION);
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Logging data to the database log file
230
+ *
231
+ * @param string $data data as returned by print_r or any text to log
232
+ * @param string $type log type
233
+ *
234
+ * @return void
235
+ */
236
+ public function logDB($data, $type ='log')
237
+ {
238
+
239
+ if (!is_null($data)) {
240
+ $currentTime = Mage::getModel('core/date')->date('Y-m-d H:i:s');
241
+ $log = Mage::getModel('paybyfinance/log');
242
+ } else {
243
+ return;
244
+ }
245
+
246
+ if ($type == 'log') {
247
+ $log->setType('General')
248
+ ->setFlow('outgoing')
249
+ ->setTime($currentTime)
250
+ ->setContent($data)
251
+ ->save();
252
+ }
253
+
254
+ if ($type == 'post') {
255
+ $log->setType('Post')
256
+ ->setFlow('Outgoing')
257
+ ->setTime($currentTime)
258
+ ->setContent($data)
259
+ ->save();
260
+ }
261
+
262
+ if ($type == 'notification') {
263
+ $log->setType('Notification')
264
+ ->setFlow('Outgoing')
265
+ ->setTime($currentTime)
266
+ ->setContent($data)
267
+ ->save();
268
+ }
269
+
270
+ if ($type == 'notification-productupdate') {
271
+ $log->setType('Notification')
272
+ ->setFlow('Incomming')
273
+ ->setTime($currentTime)
274
+ ->setContent($data)
275
+ ->save();
276
+ }
277
+ }
278
+
279
+ /**
280
+ * A basic array dump
281
+ *
282
+ * @param array $arr Array to dump
283
+ *
284
+ * @return string Formatted text for logs
285
+ */
286
+ public function arrayDump($arr)
287
+ {
288
+ $text = '';
289
+ foreach ($arr as $key => $val) {
290
+ $text .= $key . ': ' . $val . PHP_EOL;
291
+ }
292
+ return $text;
293
+ }
294
+
295
+ /**
296
+ * Processing user input for extra security, removing php open tags
297
+ *
298
+ * @param string $data User input as string
299
+ *
300
+ * @return string Processed string
301
+ */
302
+ protected function _processUserInput($data)
303
+ {
304
+ return htmlspecialchars($data);
305
+ }
306
+ }
app/code/local/HC/PayByFinance/Helper/Notification.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Data helper for notification process
20
+ *
21
+ * @uses Mage_Core_Helper_Data
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Helper_Notification extends Mage_Core_Helper_Data
30
+ {
31
+
32
+ /**
33
+ * Process notification requests
34
+ *
35
+ * @param Mage_Sales_Model_Order $order Order object
36
+ *
37
+ * @param array $parameters Array of parameters
38
+ *
39
+ * @return boolean true if success, false on error
40
+ */
41
+ public function processOrder($order, $parameters)
42
+ {
43
+ $orderStatus = $order->getStatus();
44
+ $orderState = $order->getState();
45
+
46
+ switch ($parameters['status']) {
47
+ case 'S':
48
+ $message = 'Status: Awaiting dispatch of goods. authorisationcode: '
49
+ . $parameters['authorisationcode'];
50
+ $orderStatus = Mage_Sales_Model_Order::STATE_PROCESSING;
51
+ $order->setTotalPaid(
52
+ $order->getTotalPaid() + abs($order->getFinanceAmount())
53
+ );
54
+ $order->setBaseTotalPaid(
55
+ $order->getBaseTotalPaid() + abs($order->getFinanceAmount())
56
+ );
57
+ break;
58
+ case 'A':
59
+ $message = 'Status: Accepted';
60
+ break;
61
+ case 'R':
62
+ $message = 'Status: Referred for manual underwriting';
63
+ break;
64
+ case 'D':
65
+ $message = 'Status: Declined';
66
+ break;
67
+ case 'G':
68
+ $message = 'Status: Goods dispatched';
69
+ break;
70
+ case 'C':
71
+ $message = 'Status: Cancelled';
72
+ $orderState = $orderStatus = Mage_Sales_Model_Order::STATE_CANCELED;
73
+ break;
74
+ case 'F':
75
+ $message = 'Status: Fraud';
76
+ $orderState = $orderStatus = Mage_Sales_Model_Order::STATE_CANCELED;
77
+ break;
78
+ default:
79
+ $message = 'Status: Unknown: ' . $parameters['status'];
80
+ break;
81
+ }
82
+
83
+ $message = "<strong>Hitachi Capital Pay By Finance"
84
+ . "</strong> notification received: " . $message;
85
+ $order->setFinanceStatus($status)
86
+ ->setFinanceApplicationNo($applicationNo)
87
+ ->setState($orderState, $orderStatus)
88
+ ->addStatusToHistory($orderStatus, $message, false);
89
+ return $order->save();
90
+ }
91
+
92
+ }
app/code/local/HC/PayByFinance/Model/Calculator.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Data model for finance calculations
20
+ *
21
+ * @uses Varien_Object
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Model_Calculator extends Varien_Object
30
+ {
31
+ private $_service;
32
+
33
+ /**
34
+ * Set service by id
35
+ *
36
+ * @param integer $id ID
37
+ *
38
+ * @throws Exception in case the service does not exists
39
+ *
40
+ * @return self $this
41
+ */
42
+ public function setService($id)
43
+ {
44
+ $service = Mage::getModel('paybyfinance/service')->load($id);
45
+ if (!$service) {
46
+ throw new Exception("Requested service with id: $id does not exist", 1);
47
+ }
48
+ $this->_service = $service;
49
+
50
+ return $this;
51
+ }
52
+
53
+ /**
54
+ * Set service for unit tests (fake service object)
55
+ *
56
+ * @param Object $service Service object
57
+ *
58
+ * @return self $this
59
+ */
60
+ public function setTestService($service)
61
+ {
62
+ $this->_service = $service;
63
+ return $this;
64
+ }
65
+
66
+ /**
67
+ * Get Service
68
+ *
69
+ * @throws Exception In case it was not initialised by setService()
70
+ *
71
+ * @return HC_PayByFinance_Model_Service Service object
72
+ */
73
+ public function getService()
74
+ {
75
+ if (!$this->_service) {
76
+ throw new Exception("You must set the service first", 1);
77
+ }
78
+
79
+ return $this->_service;
80
+ }
81
+
82
+ /**
83
+ * Calculating monthly payments
84
+ *
85
+ * @param float $amount Credit amount
86
+ *
87
+ * @return float Monthly installment
88
+ */
89
+ public function calcMonthlyPayment($amount)
90
+ {
91
+ $service = $this->getService();
92
+ // No rounding issues, rounding always down.
93
+ $monthlyPayment = floor(($amount * $service->getMultiplier()) * 100) / 100;
94
+
95
+ return $monthlyPayment;
96
+ }
97
+
98
+ /**
99
+ * Calculating monthly payments (Interst Free, type=32)
100
+ *
101
+ * @param float $amount Credit amount
102
+ *
103
+ * @return float Monthly installment
104
+ */
105
+ public function calcMonthlyPaymentInterestFree($amount)
106
+ {
107
+ $service = $this->getService();
108
+ $monthlyPayment = floor(($amount / $service->getTerm()) * 100) / 100;
109
+
110
+ return $monthlyPayment;
111
+ }
112
+
113
+ /**
114
+ * Calculate and get results
115
+ *
116
+ * @return Varien_Object Results
117
+ */
118
+ public function getResults()
119
+ {
120
+ $amount = $this->getAmount();
121
+ $deposit = $this->getDeposit();
122
+ $service = $this->getService();
123
+ $discount = abs($this->getDiscount()); // Discount is a negative value
124
+ $giftcard = abs($this->getGiftcard()); // Giftcard (EE) is a positive value
125
+
126
+ $depositAmount = ($amount - $discount - $giftcard) * ($deposit / 100);
127
+ $financeAmount = $amount - $depositAmount - $discount - $giftcard;
128
+
129
+ if ($service->getType() == 32) {
130
+ $monthlyPayment = $this->calcMonthlyPaymentInterestFree($financeAmount);
131
+ } else {
132
+ $monthlyPayment = $this->calcMonthlyPayment($financeAmount);
133
+ }
134
+
135
+ $results = new Varien_Object();
136
+ $results
137
+ ->setDeposit($depositAmount)
138
+ ->setAmount($amount)
139
+ ->setFinanceAmount($financeAmount)
140
+ ->setMonthlyPayment($monthlyPayment);
141
+
142
+ return $results;
143
+ }
144
+ }
app/code/local/HC/PayByFinance/Model/Config/Source/Catalog/Product/Finance.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Provides the list of config values to enable finance
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Config_Source_Catalog_Product_Finance
28
+ extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
29
+ {
30
+
31
+ const VALUES_CONFIG = 0;
32
+ const VALUES_ENABLE = 1;
33
+ const VALUES_DISABLE = 2;
34
+
35
+ /**
36
+ * Retrieve all options array
37
+ *
38
+ * @return array
39
+ */
40
+ public function getAllOptions()
41
+ {
42
+ if (is_null($this->_options)) {
43
+ $helper = Mage::helper('paybyfinance');
44
+ $this->_options = array(
45
+ array(
46
+ 'label' => $helper->__('Based on configuration'),
47
+ 'value' => self::VALUES_CONFIG
48
+ ),
49
+ array(
50
+ 'label' => $helper->__('Enable'),
51
+ 'value' => self::VALUES_ENABLE
52
+ ),
53
+ array(
54
+ 'label' => $helper->__('Disable'),
55
+ 'value' => self::VALUES_DISABLE
56
+ ),
57
+ );
58
+ }
59
+ return $this->_options;
60
+ }
61
+
62
+ }
app/code/local/HC/PayByFinance/Model/Config/Source/Catalog/Product/Type.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Provides the list of product types to be used in admin config fields
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Config_Source_Catalog_Product_Type
28
+ {
29
+ protected $_options;
30
+
31
+ /**
32
+ * toOptionArray
33
+ *
34
+ * @return array Indexed array of options.
35
+ */
36
+ public function toOptionArray()
37
+ {
38
+ if (!$this->_options) {
39
+ $this->_options = Mage_Catalog_Model_Product_Type::getAllOptions();
40
+ unset($this->_options[0]);
41
+ }
42
+ $options = $this->_options;
43
+
44
+ return $options;
45
+ }
46
+ }
app/code/local/HC/PayByFinance/Model/Config/Source/Cms/Block.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Provides the list of blocks to be used in admin config fields
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Config_Source_Cms_Block
28
+ {
29
+ protected $_options;
30
+
31
+ /**
32
+ * toOptionArray
33
+ *
34
+ * @return array Indexed array of options.
35
+ */
36
+ public function toOptionArray()
37
+ {
38
+ if (!$this->_options) {
39
+ $this->_options = Mage::getResourceModel('cms/block_collection')
40
+ ->load()
41
+ ->toOptionArray();
42
+ }
43
+ $options = $this->_options;
44
+
45
+ array_unshift(
46
+ $options,
47
+ array(
48
+ 'value' => '',
49
+ 'label' => Mage::helper('adminhtml')->__(
50
+ '--Please Select--'
51
+ )
52
+ )
53
+ );
54
+
55
+ return $options;
56
+ }
57
+ }
app/code/local/HC/PayByFinance/Model/Config/Source/Connectionmode.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Provides the list of product types to be used in admin config fields
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Config_Source_Connectionmode
28
+ {
29
+ /**
30
+ * toOptionArray
31
+ *
32
+ * @return array Indexed array of options.
33
+ */
34
+ public function toOptionArray()
35
+ {
36
+ $options = array(
37
+ 'test' => 'Test',
38
+ 'simulation' => 'Simulation',
39
+ 'live' => 'Live',
40
+ );
41
+
42
+ return $options;
43
+ }
44
+
45
+ }
app/code/local/HC/PayByFinance/Model/Config/Source/Type.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Provides the list of product types to be used in admin config fields
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Config_Source_Type
28
+ {
29
+ /**
30
+ * toOptionArray
31
+ *
32
+ * @return array Indexed array of options.
33
+ */
34
+ public function toOptionArray()
35
+ {
36
+ $options = array(
37
+ 31 => '31: Interest bearing credit',
38
+ 32 => '32: Interest free credit',
39
+ 33 => '33: Interest option',
40
+ 34 => '34: Buy now pay later interest free credit',
41
+ 35 => '35: Buy now pay later interest bearing',
42
+ );
43
+
44
+ return $options;
45
+ }
46
+
47
+ /**
48
+ * For names useful to diplay in the frontend
49
+ *
50
+ * @return array Indexed array of options.
51
+ */
52
+ public function toFrontendArray()
53
+ {
54
+ $options = array(
55
+ 31 => 'Interest bearing',
56
+ 32 => 'Interest free',
57
+ 33 => 'Interest option',
58
+ 34 => 'Buy now pay later interest free',
59
+ 35 => 'Buy now pay later interest bearing',
60
+ );
61
+
62
+ return $options;
63
+ }
64
+ }
app/code/local/HC/PayByFinance/Model/Log.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension f6f5b81
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Log Model
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Log extends Mage_Core_Model_Abstract
28
+ {
29
+ /**
30
+ * Mage Constructor
31
+ *
32
+ * @return mixed Value.
33
+ */
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->_init('paybyfinance/log');
38
+ }
39
+ }
app/code/local/HC/PayByFinance/Model/Mysql4/Log.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Log Resource model
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Mysql4_Log
28
+ extends Mage_Core_Model_Mysql4_Abstract
29
+ {
30
+ /**
31
+ * Magento constructor
32
+ *
33
+ * @return mixed Value.
34
+ */
35
+ public function _construct()
36
+ {
37
+ $this->_init('paybyfinance/log', 'api_id');
38
+ }
39
+ }
app/code/local/HC/PayByFinance/Model/Mysql4/Log/Collection.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Log Collection
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Mysql4_Log_Collection
28
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
29
+ {
30
+ /**
31
+ * Mage constructor.
32
+ *
33
+ * @return mixed Value.
34
+ */
35
+ public function _construct()
36
+ {
37
+ $this->_init('paybyfinance/log');
38
+ }
39
+ }
app/code/local/HC/PayByFinance/Model/Mysql4/Service.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Service Resource model
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Mysql4_Service
28
+ extends Mage_Core_Model_Mysql4_Abstract
29
+ {
30
+ /**
31
+ * Magento constructor
32
+ *
33
+ * @return mixed Value.
34
+ */
35
+ public function _construct()
36
+ {
37
+ $this->_init('paybyfinance/service', 'service_id');
38
+ }
39
+ }
app/code/local/HC/PayByFinance/Model/Mysql4/Service/Collection.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Services Collection
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Mysql4_Service_Collection
28
+ extends Mage_Core_Model_Mysql4_Collection_Abstract
29
+ {
30
+ /**
31
+ * Mage constructor.
32
+ *
33
+ * @return mixed Value.
34
+ */
35
+ public function _construct()
36
+ {
37
+ $this->_init('paybyfinance/service');
38
+ }
39
+
40
+ /**
41
+ * Add collection filter by price
42
+ *
43
+ * @param float $price Price.
44
+ *
45
+ * @return HC_PayByFinance_Model_Mysql4_Service_Collection
46
+ */
47
+ public function addPriceFilter($price)
48
+ {
49
+ $condition = array('lteq' => $price);
50
+ $this->addFieldToFilter('min_amount', $condition);
51
+ return $this;
52
+ }
53
+ }
app/code/local/HC/PayByFinance/Model/Observer.php ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Observer Model
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Observer
28
+ {
29
+ /**
30
+ * Clearing enterprise full page cache after saving a service
31
+ *
32
+ * @param Object $observer Onserver object
33
+ *
34
+ * @return void
35
+ */
36
+ public function enterpriseCacheClear($observer)
37
+ {
38
+ $cache = Mage::getModel('enterprise_pagecache/cache');
39
+ if ($cache) {
40
+ $cache::getCacheInstance()->clean();
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Converting address data into a quote
46
+ *
47
+ * @param Object $observer Onserver object
48
+ *
49
+ * @return void
50
+ */
51
+ public function convertQuoteAddressToOrder(Varien_Event_Observer $observer)
52
+ {
53
+ if (!Mage::getSingleton('paybyfinance/session')->getData('enabled')) {
54
+ return;
55
+ }
56
+
57
+ $address = $observer->getEvent()->getAddress();
58
+ $order = $observer->getEvent()->getOrder();
59
+ $financeAmount = $address->getFinanceAmount();
60
+ $serviceId = Mage::getSingleton('paybyfinance/session')->getData('service');
61
+ $deposit = Mage::getSingleton('paybyfinance/session')->getData('deposit');
62
+ $items = $address->getAllItems();
63
+ $eligibleAmount = Mage::helper('paybyfinance/cart')->getEligibleAmount($items);
64
+
65
+ $helper = Mage::helper('paybyfinance');
66
+ $includeShipping = Mage::getStoreConfig(
67
+ $helper::XML_PATH_INCLUDE_SHIPPING
68
+ );
69
+ if ($includeShipping) {
70
+ $shippingCost = $address->getShippingAmount();
71
+ $eligibleAmount += $shippingCost;
72
+ }
73
+
74
+ $calculator = Mage::getModel('paybyfinance/calculator');
75
+ $calculator->setService($serviceId)
76
+ ->setDeposit($deposit)
77
+ ->setAmount($eligibleAmount)
78
+ ->setDiscount($address->getDiscountAmount())
79
+ ->setGiftcard($address->getGiftCardsAmount());
80
+ $finance = $calculator->getResults();
81
+
82
+ $amt = $finance->getFinanceAmount() * -1;
83
+ if ($amt) {
84
+ $order->setFinanceAmount($amt)
85
+ ->setBaseFinanceAmount($amt)
86
+ ->setFinanceService($serviceId)
87
+ ->setFinanceDeposit($deposit)
88
+ ->setBaseTotalDue($order->getBaseGrandTotal())
89
+ ->setTotalDue($order->getGrandTotal())
90
+ ->setFromQuote(true);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Order save event. Responds only if it's the first save after converted from quote
96
+ * See $order->setFromQuote() in function convertQuoteAddressToOrder()
97
+ *
98
+ * @param Object $observer Onserver object
99
+ *
100
+ * @return void
101
+ */
102
+ public function orderAfterSave(Varien_Event_Observer $observer)
103
+ {
104
+ $order = $observer->getEvent()->getOrder();
105
+ $serviceId = $order->getFinanceService();
106
+
107
+ if (!$order->getFromQuote() || empty($serviceId)) {
108
+ return;
109
+ }
110
+
111
+ $service = Mage::getModel('paybyfinance/service')->load($serviceId);
112
+
113
+ $order_id = $order->getId();
114
+ $order->setStatus('pending');
115
+ $order->setFromQuote(false);
116
+ $order->save();
117
+ }
118
+
119
+ /**
120
+ * Checkout success event to redirect to Hitachi
121
+ *
122
+ * @param Object $observer Onserver object
123
+ *
124
+ * @return void
125
+ */
126
+ public function checkoutSuccess(Varien_Event_Observer $observer)
127
+ {
128
+ $lastOrderId = Mage::getSingleton('checkout/type_onepage')->getCheckout()->getLastOrderId();
129
+ if (!is_numeric($lastOrderId)) {
130
+ return;
131
+ }
132
+
133
+ $order = Mage::getModel('sales/order');
134
+ $order->load($lastOrderId);
135
+
136
+ if (!$order->getFinanceService()) {
137
+ return;
138
+ }
139
+
140
+ $payment = $order->getPayment();
141
+
142
+ if (!$payment) {
143
+ return;
144
+ }
145
+
146
+ Mage::getSingleton('paybyfinance/session')->setData('order_id', $lastOrderId);
147
+
148
+ Mage::app()->getResponse()->setRedirect(
149
+ Mage::getUrl('paybyfinance/checkout/redirectform', array('_secure' => true))
150
+ );
151
+ }
152
+
153
+ /**
154
+ * Get Finance information to the Payment Information block.
155
+ * Note this only works with a few payment methods like cc, but not with checkmo.
156
+ *
157
+ * @param Varien_Event_Observer $observer Observer
158
+ *
159
+ * @return HC_PayByFinance_Model_Observer
160
+ */
161
+ public function getPaymentInfo(Varien_Event_Observer $observer)
162
+ {
163
+ $payment = $observer->getEvent()->getPayment();
164
+ $transport = $observer->getEvent()->getTransport();
165
+ $order = $payment->getOrder();
166
+
167
+ if ($order->getFinanceService()) {
168
+ $serviceId = $order->getFinanceService();
169
+ $service = Mage::getModel('paybyfinance/service')->load($serviceId);
170
+ $transport->setData(
171
+ 'Finance Service',
172
+ 'ID:' . $serviceId . ' - ' . $service->getName()
173
+ );
174
+ $transport->setData('Finance Deposit', $order->getFinanceDeposit() . '%');
175
+ $transport->setData('Finance Amount', $order->getFinanceAmount());
176
+ $transport->setData('Finance Status', $order->getFinanceStatus());
177
+ $transport->setData('Finance applicationNo', $order->getFinanceApplicationNo());
178
+ }
179
+ return $this;
180
+ }
181
+
182
+ /**
183
+ * PayPal arbitrary items, total modifications (adds finance amount)
184
+ *
185
+ * @param Varien_Event_Observer $observer Observer
186
+ *
187
+ * @return HC_PayByFinance_Model_Observer
188
+ */
189
+ public function paypalPrepareLineItems(Varien_Event_Observer $observer)
190
+ {
191
+ $cart = $observer->getPaypalCart();
192
+ $order = $cart->getSalesEntity();
193
+ $address = $order->getShippingAddress();
194
+ $cart->addItem(
195
+ Mage::helper('paybyfinance')->__('Financed Amount'),
196
+ 1,
197
+ $address->getFinanceAmount()
198
+ );
199
+ return $this;
200
+ }
201
+
202
+ }
app/code/local/HC/PayByFinance/Model/Paypal/Api/Nvp.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Overrideing Mage_Paypal_Model_Api_Nvp::call()
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Paypal_Api_Nvp extends Mage_Paypal_Model_Api_Nvp
28
+ {
29
+ /**
30
+ * Do the API call
31
+ *
32
+ * @param string $methodName Method name
33
+ * @param array $request Request array
34
+ *
35
+ * @return array
36
+ * @throws Mage_Core_Exception
37
+ */
38
+ public function call($methodName, array $request)
39
+ {
40
+ if (isset($request['PAYMENTACTION'])
41
+ && $request['PAYMENTACTION'] == 'Authorization'
42
+ && isset($request['ITEMAMT'])
43
+ && isset($request['TOKEN'])
44
+ ) {
45
+ $amt = floatval($request['ITEMAMT']);
46
+ $order = $this->_cart->getSalesEntity();
47
+ $financed = ($order->getFinanceAmount());
48
+ $itemamt = $amt + $financed;
49
+ $request['ITEMAMT'] = sprintf('%.2F', $itemamt);
50
+ }
51
+
52
+ return parent::call($methodName, $request);
53
+ }
54
+ }
app/code/local/HC/PayByFinance/Model/Paypal/Hostedpro/Request.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Overrideing Mage_Paypal_Model_Hostedpro_Request::_getOrderData()
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Paypal_Hostedpro_Request extends Mage_Paypal_Model_Hostedpro_Request
28
+ {
29
+ /**
30
+ * Get order request data as array
31
+ *
32
+ * @param Mage_Sales_Model_Order $order Order
33
+ *
34
+ * @return array
35
+ */
36
+ protected function _getOrderData(Mage_Sales_Model_Order $order)
37
+ {
38
+ $request = array(
39
+ 'subtotal' => $this->_formatPrice(
40
+ (float) $order->getBaseGrandTotal()
41
+ - (float) $order->getBaseShippingAmount()
42
+ ),
43
+ 'tax' => $this->_formatPrice(0),
44
+ 'shipping' => $this->_formatPrice($order->getBaseShippingAmount()),
45
+ 'invoice' => $order->getIncrementId(),
46
+ 'address_override' => 'true',
47
+ 'currency_code' => $order->getBaseCurrencyCode(),
48
+ 'buyer_email' => $order->getCustomerEmail(),
49
+ 'discount' => $this->_formatPrice(
50
+ $order->getBaseGiftCardsAmount()
51
+ + abs($order->getBaseDiscountAmount())
52
+ + $order->getBaseCustomerBalanceAmount()
53
+ ),
54
+ );
55
+
56
+ // append to request billing address data
57
+ if ($billingAddress = $order->getBillingAddress()) {
58
+ $request = array_merge($request, $this->_getBillingAddress($billingAddress));
59
+ }
60
+
61
+ // append to request shipping address data
62
+ if ($shippingAddress = $order->getShippingAddress()) {
63
+ $request = array_merge($request, $this->_getShippingAddress($shippingAddress));
64
+ }
65
+
66
+ return $request;
67
+ }
68
+ }
app/code/local/HC/PayByFinance/Model/PaypalUk/Api/Nvp.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Overrideing Mage_PaypalUk_Model_Api_Nvp::call()
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_PaypalUk_Api_Nvp extends Mage_PaypalUk_Model_Api_Nvp
28
+ {
29
+ /**
30
+ * Do the API call
31
+ *
32
+ * @param string $methodName Method name
33
+ * @param array $request Request array
34
+ *
35
+ * @return array
36
+ * @throws Mage_Core_Exception
37
+ */
38
+ public function call($methodName, array $request)
39
+ {
40
+ if (isset($request['PAYMENTACTION'])
41
+ && $request['PAYMENTACTION'] == 'Authorization'
42
+ && isset($request['ITEMAMT'])
43
+ && isset($request['TOKEN'])
44
+ ) {
45
+ $amt = floatval($request['ITEMAMT']);
46
+ $order = $this->_cart->getSalesEntity();
47
+ $financed = ($order->getFinanceAmount());
48
+ $itemamt = $amt + $financed;
49
+ $request['ITEMAMT'] = sprintf('%.2F', $itemamt);
50
+ }
51
+
52
+ return parent::call($methodName, $request);
53
+ }
54
+ }
app/code/local/HC/PayByFinance/Model/Post.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Service Model
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Post extends Mage_Core_Model_Abstract
28
+ {
29
+ private $_adapter;
30
+
31
+ /**
32
+ * Set post adapter
33
+ *
34
+ * @param string $state test, simulation or live
35
+ *
36
+ * @return HC_PayByFinance_Model_Post_Abstract Adapter object
37
+ */
38
+ public function setPostAdapter($state)
39
+ {
40
+ $this->_adapter = Mage::getModel('paybyfinance/post_'.$state);
41
+ return $this->_adapter;
42
+ }
43
+
44
+ /**
45
+ * Gets the adapter object
46
+ *
47
+ * @return HC_PayByFinance_Model_Post_Abstract Adapter object
48
+ */
49
+ public function getPostAdapter()
50
+ {
51
+ return $this->_adapter;
52
+ }
53
+
54
+ /**
55
+ * Posts to the PBF via CURL
56
+ *
57
+ * @return string CURL response
58
+ */
59
+ public function post()
60
+ {
61
+ return $this->_adapter->post();
62
+ }
63
+
64
+ /**
65
+ * Get the redirect form
66
+ *
67
+ * @return string HTML form to redirect the user to PBF
68
+ */
69
+ public function getRedirectForm()
70
+ {
71
+ return $this->_adapter->getRedirectForm();
72
+ }
73
+
74
+ /**
75
+ * Set and prepare data for quote calls
76
+ *
77
+ * @param array $data Array of key and fields
78
+ *
79
+ * @return void
80
+ */
81
+ public function setQuoteData($data)
82
+ {
83
+ $helper = Mage::helper('paybyfinance');
84
+ $adapter = $this->getPostAdapter();
85
+
86
+ $fields = array(
87
+ 'id' => trim((string) Mage::getStoreConfig($helper::XML_PATH_PBF_ACCOUNT_ID1)),
88
+ 'id2' => trim((string) Mage::getStoreConfig($helper::XML_PATH_PBF_ACCOUNT_ID2)),
89
+ 'ver' => $adapter::PROTOCOL_VERSION,
90
+ 'eea' => Mage::getStoreConfig($helper::XML_PATH_ERROR_NOTIFY_EMAIL),
91
+ 'eurl' => Mage::getUrl('paybyfinance/checkout/response'),
92
+ 'acceptedURL' => Mage::getUrl('paybyfinance/checkout/response'),
93
+ 'referredURL' => Mage::getUrl('paybyfinance/checkout/response'),
94
+ 'declinedURL' => Mage::getUrl('paybyfinance/checkout/response'),
95
+ 'toStoreURL' => Mage::getUrl('paybyfinance/checkout/response'),
96
+ 'notificationURL' => Mage::getUrl('paybyfinance/notification'),
97
+ );
98
+ $data = array_merge($data, $fields);
99
+
100
+ $this->_adapter->setPostData($data);
101
+ }
102
+
103
+ /**
104
+ * Set and prepare data for notification post calls
105
+ *
106
+ * @param array $data Array of keys and fields
107
+ *
108
+ * @return void
109
+ */
110
+ public function setNotificationData($data)
111
+ {
112
+ $helper = Mage::helper('paybyfinance');
113
+ $adapter = $this->_adapter;
114
+
115
+ $fields = array(
116
+ 'id' => trim((string) Mage::getStoreConfig($helper::XML_PATH_PBF_ACCOUNT_ID1)),
117
+ 'id2' => trim((string) Mage::getStoreConfig($helper::XML_PATH_PBF_ACCOUNT_ID2)),
118
+ );
119
+ $data = array_merge($data, $fields);
120
+
121
+ $this->_adapter->setPostData($data);
122
+ }
123
+ }
app/code/local/HC/PayByFinance/Model/Post/Abstract.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Post Abstract Model
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ abstract class HC_PayByFinance_Model_Post_Abstract extends Mage_Core_Model_Abstract
28
+ {
29
+ const PROTOCOL_VERSION = '1.0';
30
+
31
+ private $_pbfInformation;
32
+
33
+ private $_ciphers = array(
34
+ 'RC4-SHA',
35
+ );
36
+
37
+ /**
38
+ * Hitachi Post Abstract Model SetPostData
39
+ *
40
+ * @param array $arrayData Post Data Array
41
+ *
42
+ * @return void
43
+ */
44
+ public function setPostData($arrayData)
45
+ {
46
+ foreach ($arrayData as &$value) {
47
+ $value = trim($value);
48
+ }
49
+ $this->_pbfInformation = $arrayData;
50
+ }
51
+
52
+ /**
53
+ * Hitachi Post Simulation Model
54
+ *
55
+ * @return post reponse object
56
+ */
57
+ public function post()
58
+ {
59
+ $ch = curl_init();
60
+ curl_setopt($ch, CURLOPT_URL, $this::NOTIFY_URL);
61
+ curl_setopt($ch, CURLOPT_POST, true);
62
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->_pbfInformation));
63
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
64
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
65
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
66
+ curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, implode(':', $this->_ciphers));
67
+ $response = curl_exec($ch);
68
+ curl_close($ch);
69
+
70
+ if ($response !== false) {
71
+ return $response;
72
+ }
73
+
74
+ return false;
75
+ }
76
+
77
+ /**
78
+ * Generate the User Redirect Form
79
+ *
80
+ * @return $string of the form html
81
+ */
82
+ public function getRedirectForm()
83
+ {
84
+ $helper = Mage::helper('paybyfinance');
85
+ $helper->log("getRedirectForm: \n" . $helper->arrayDump($this->_pbfInformation), 'post');
86
+
87
+ $block = Mage::app()->getLayout()->createBlock('paybyfinance/checkout_redirect')
88
+ ->setPostContent($this->_pbfInformation)
89
+ ->setPostUrl($this::POST_URL)
90
+ ->setMode($this::MODE)
91
+ ->setTemplate('paybyfinance/form.phtml');
92
+
93
+ return $block->toHtml();
94
+ }
95
+ }
app/code/local/HC/PayByFinance/Model/Post/Live.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Post Live Model
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Post_Live extends HC_PayByFinance_Model_Post_Abstract
28
+ {
29
+ const POST_URL = 'https://www.paybyfinance.co.uk/Ecommerce/etailer/createQuote.action';
30
+ const NOTIFY_URL = 'https://www.paybyfinance.co.uk/Ecommerce/etailer/notify.action';
31
+ const MODE = 'live';
32
+ }
app/code/local/HC/PayByFinance/Model/Post/Simulation.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Post Simulation Model
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Post_Simulation extends HC_PayByFinance_Model_Post_Abstract
28
+ {
29
+ const POST_URL = 'https://uat-www.creditmaster2.co.uk/Ecommerce/etailer/createQuote.action';
30
+ const NOTIFY_URL = 'https://uat-www.creditmaster2.co.uk/Ecommerce/etailer/notify.action';
31
+ const MODE = 'simulation';
32
+ }
app/code/local/HC/PayByFinance/Model/Post/Test.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Post TEst Model
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Post_Test extends HC_PayByFinance_Model_Post_Abstract
28
+ {
29
+ const POST_URL = 'https://uat-www.creditmaster2.co.uk/Ecommerce/etailer/createQuote.action';
30
+ const NOTIFY_URL = 'https://uat-www.creditmaster2.co.uk/Ecommerce/etailer/notify.action';
31
+ const MODE = 'test';
32
+ }
app/code/local/HC/PayByFinance/Model/Resource/Setup.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Setup resource model
20
+ *
21
+ * @uses Mage_Core_Model_Resource_Setup
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Model_Resource_Setup
30
+ extends Mage_Core_Model_Resource_Setup
31
+ {
32
+
33
+ }
app/code/local/HC/PayByFinance/Model/Sales/Order/Creditmemo/Financeamount.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Totals value on the credit memo
20
+ *
21
+ * @uses Mage_Sales_Model_Order_Invoice_Total_Abstract
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Model_Sales_Order_Creditmemo_FInanceamount
30
+ extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
31
+ {
32
+ /**
33
+ * collect
34
+ *
35
+ * @param Mage_Sales_Model_Order_Creditmemo $creditmemo Credit Memo object
36
+ *
37
+ * @return $this
38
+ */
39
+ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
40
+ {
41
+ $order = $creditmemo->getOrder();
42
+ $amount = $order->getFinanceAmount();
43
+ if ($amount == 0) {
44
+ return $this;
45
+ }
46
+
47
+ // Previous credit Memos.
48
+ foreach ($order->getCreditmemosCollection() as $previusMemo) {
49
+ if ((float) $previusMemo->getHcfinanced() != 0 && !$previusMemo->isCanceled()) {
50
+ return $this;
51
+ }
52
+ }
53
+
54
+ $creditmemo->setFinanceAmount($amount);
55
+ $creditmemo->setBaseFinanceAmount($order->getBaseFinanceAmount());
56
+
57
+ $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $creditmemo->getFinanceAmount());
58
+ $creditmemo->setBaseGrandTotal(
59
+ $creditmemo->getBaseGrandTotal() - $creditmemo->getBaseFinanceAmount()
60
+ );
61
+
62
+ return $this;
63
+ }
64
+ }
app/code/local/HC/PayByFinance/Model/Sales/Order/Invoice/Financeamount.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Totals value on the cart
20
+ *
21
+ * @uses Mage_Sales_Model_Order_Invoice_Total_Abstract
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Model_Sales_Order_Invoice_Financeamount
30
+ extends Mage_Sales_Model_Order_Invoice_Total_Abstract
31
+ {
32
+ /**
33
+ * collect
34
+ *
35
+ * @param Mage_Sales_Model_Order_Invoice $invoice Invoice object
36
+ *
37
+ * @return $this
38
+ */
39
+ public function collect(Mage_Sales_Model_Order_Invoice $invoice)
40
+ {
41
+ $order = $invoice->getOrder();
42
+ $amount = $order->getFinanceAmount();
43
+ if ($amount == 0) {
44
+ return $this;
45
+ }
46
+
47
+ // Previous invoices.
48
+ foreach ($order->getInvoiceCollection() as $previusInvoice) {
49
+ if ((float) $previusInvoice->getHcfinanced() != 0 && !$previusInvoice->isCanceled()) {
50
+ return $this;
51
+ }
52
+ }
53
+
54
+ $invoice->setFinanceAmount($amount);
55
+ $invoice->setBaseFinanceAmount($order->getBaseFinanceAmount());
56
+
57
+ $invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getFinanceAmount());
58
+ $invoice->setBaseGrandTotal(
59
+ $invoice->getBaseGrandTotal() - $invoice->getBaseFinanceAmount()
60
+ );
61
+
62
+ return $this;
63
+ }
64
+ }
app/code/local/HC/PayByFinance/Model/Sales/Quote/Financeamount.php ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Totals value on the cart
20
+ *
21
+ * @uses Mage_Sales_Model_Quote_Address_Total_Abstract
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Model_Sales_Quote_Financeamount
30
+ extends Mage_Sales_Model_Quote_Address_Total_Abstract
31
+ {
32
+ /**
33
+ * Constructor
34
+ */
35
+ public function __construct()
36
+ {
37
+ $this->setCode('financeamount');
38
+ }
39
+
40
+ /**
41
+ * collect
42
+ *
43
+ * @param Mage_Sales_Model_Quote_Address $address Address object
44
+ *
45
+ * @return self $this
46
+ */
47
+ public function collect(Mage_Sales_Model_Quote_Address $address)
48
+ {
49
+ $address->setFinanceAmount(0);
50
+
51
+ $items = $address->getAllItems();
52
+ if (!count($items)) {
53
+ return $this;
54
+ }
55
+
56
+ $session = Mage::getSingleton('paybyfinance/session');
57
+
58
+ if ($session->getData('enabled')) {
59
+ $calculator = Mage::getModel('paybyfinance/calculator');
60
+ $cartHelper = Mage::helper('paybyfinance/cart');
61
+
62
+ $helper = Mage::helper('paybyfinance');
63
+ $includeShipping = Mage::getStoreConfig(
64
+ $helper::XML_PATH_INCLUDE_SHIPPING
65
+ );
66
+
67
+ $shippingCost = 0;
68
+ if ($includeShipping) {
69
+ $shippingCost = $address->getShippingAmount();
70
+ }
71
+
72
+
73
+ $calculator
74
+ ->setService($session->getData('service'))
75
+ ->setDeposit($session->getData('deposit'))
76
+ ->setAmount($cartHelper->getEligibleAmount() + $shippingCost)
77
+ ->setDiscount($address->getDiscountAmount())
78
+ ->setGiftcard($address->getGiftCardsAmount());
79
+ $finance = $calculator->getResults();
80
+
81
+ $amt = ($finance->getFinanceAmount() * -1);
82
+ $address->setFinanceAmount($amt);
83
+ $address->setBaseFinanceAmount($amt);
84
+ $address->setGrandTotal($address->getGrandTotal() + $address->getFinanceAmount());
85
+ $address->setBaseGrandTotal(
86
+ $address->getBaseGrandTotal() + $address->getBaseFinanceAmount()
87
+ );
88
+ Mage::dispatchEvent(
89
+ 'paybyfinance_quote_financeamount_collect_after', array(
90
+ 'address' => $address,
91
+ 'amt' => $amt
92
+ )
93
+ );
94
+ }
95
+
96
+ return $this;
97
+ }
98
+
99
+ /**
100
+ * fetch
101
+ *
102
+ * @param Mage_Sales_Model_Quote_Address $address Address object
103
+ *
104
+ * @return self $this
105
+ */
106
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
107
+ {
108
+ $amount = $address->getFinanceAmount();
109
+ if ($amount != 0 && $address->getAddressType() == 'shipping') {
110
+ $address->addTotal(
111
+ array(
112
+ 'code' => 'financeamount',
113
+ 'title' => Mage::helper('paybyfinance')->__('Financed Amount'),
114
+ 'value' => $amount
115
+ )
116
+ );
117
+ }
118
+
119
+ return $this;
120
+ }
121
+ }
app/code/local/HC/PayByFinance/Model/Sales/Quote/Totalcost.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Total Cost value on the cart
20
+ *
21
+ * @uses Mage_Sales_Model_Quote_Address_Total_Abstract
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Model_Sales_Quote_Totalcost
30
+ extends Mage_Sales_Model_Quote_Address_Total_Abstract
31
+ {
32
+ /**
33
+ * Constructor
34
+ */
35
+ public function __construct()
36
+ {
37
+ $this->setCode('paybyfinance_totalcost');
38
+ }
39
+
40
+ /**
41
+ * collect
42
+ *
43
+ * @param Mage_Sales_Model_Quote_Address $address Address object
44
+ *
45
+ * @return self $this
46
+ */
47
+ public function collect(Mage_Sales_Model_Quote_Address $address)
48
+ {
49
+ return $this;
50
+ }
51
+
52
+ /**
53
+ * fetch
54
+ *
55
+ * @param Mage_Sales_Model_Quote_Address $address Address object
56
+ *
57
+ * @return self $this
58
+ */
59
+ public function fetch(Mage_Sales_Model_Quote_Address $address)
60
+ {
61
+ $session = Mage::getSingleton('paybyfinance/session');
62
+ $amount = $address->getQuote()->getSubtotal()
63
+ + $address->getShippingAmount()
64
+ + $address->getDiscountAmount()
65
+ - $address->getGiftCardsAmount();
66
+ if ($session->getData('enabled') && $address->getAddressType() == 'shipping') {
67
+ $address->addTotal(
68
+ array(
69
+ 'code' => 'paybyfinance_totalcost',
70
+ 'title' => Mage::helper('paybyfinance')->__('Total Cost'),
71
+ 'value' => $amount
72
+ )
73
+ );
74
+ }
75
+
76
+ return $this;
77
+ }
78
+ }
app/code/local/HC/PayByFinance/Model/Service.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Hitachi Service Model
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Service extends Mage_Core_Model_Abstract
28
+ {
29
+ /**
30
+ * Mage Constructor
31
+ *
32
+ * @return mixed Value.
33
+ */
34
+ public function _construct()
35
+ {
36
+ parent::_construct();
37
+ $this->_init('paybyfinance/service');
38
+ }
39
+ }
app/code/local/HC/PayByFinance/Model/Session.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Session storage
20
+ *
21
+ * @category HC
22
+ * @package PayByFinance
23
+ * @author Healthy Websites <support@healthywebsites.co.uk>
24
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
25
+ * @link http://www.healthywebsites.co.uk/
26
+ */
27
+ class HC_PayByFinance_Model_Session extends Mage_Core_Model_Session_Abstract
28
+ {
29
+ /**
30
+ * Constructor
31
+ *
32
+ * @return void.
33
+ */
34
+ public function __construct()
35
+ {
36
+ $this->init('paybyfinance');
37
+ }
38
+
39
+ }
app/code/local/HC/PayByFinance/controllers/Adminhtml/Paybyfinance/ServiceController.php ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Controller for services
20
+ *
21
+ * @uses Mage_Adminhtml_Controller_Action
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_Adminhtml_Paybyfinance_ServiceController
30
+ extends Mage_Adminhtml_Controller_Action
31
+ {
32
+ /**
33
+ * _initAction
34
+ *
35
+ * @return mixed Value.
36
+ */
37
+ protected function _initAction()
38
+ {
39
+ $helper = Mage::helper('paybyfinance');
40
+ $this->loadLayout()
41
+ ->_setActiveMenu('paybyfinance')
42
+ ->_addBreadcrumb(
43
+ $helper->__('Pay By Finance'),
44
+ $helper->__('Service')
45
+ );
46
+ return $this;
47
+ }
48
+
49
+ /**
50
+ * indexAction
51
+ *
52
+ * @return void.
53
+ */
54
+ public function indexAction()
55
+ {
56
+ $this->_title($this->__('Pay By Finance'))
57
+ ->_title($this->__('Services'));
58
+
59
+ $this->_initAction();
60
+ $this->renderLayout();
61
+ }
62
+
63
+ /**
64
+ * editAction
65
+ *
66
+ * @return void.
67
+ */
68
+ public function editAction()
69
+ {
70
+ $helper = Mage::helper('paybyfinance');
71
+ $serviceId = $this->getRequest()->getParam('id');
72
+ $serviceModel = Mage::getModel('paybyfinance/service')
73
+ ->load($serviceId);
74
+
75
+ if ($serviceModel->getId() || $serviceId == 0) {
76
+
77
+ Mage::register('service_data', $serviceModel);
78
+
79
+ $this->loadLayout();
80
+ $this->_setActiveMenu('adminhtml/paybyfinance_service');
81
+
82
+ $this->_addBreadcrumb(
83
+ $helper->__('Pay By FInance'), $helper->__('Pay By FInance')
84
+ );
85
+ $this->_addBreadcrumb(
86
+ $helper->__('Service'), $helper->__('Service')
87
+ );
88
+
89
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
90
+
91
+ $this->_addContent(
92
+ $this->getLayout()
93
+ ->createBlock(
94
+ 'paybyfinance/adminhtml_paybyfinance_service_edit'
95
+ )
96
+ )->_addLeft(
97
+ $this->getLayout()->createBlock(
98
+ 'paybyfinance/adminhtml_paybyfinance_service_edit_tabs'
99
+ )
100
+ );
101
+
102
+ $this->renderLayout();
103
+ } else {
104
+ Mage::getSingleton('adminhtml/session')
105
+ ->addError(
106
+ Mage::helper('paybyfinance')->__('Item does not exist')
107
+ );
108
+ $this->_redirect('*/*/');
109
+ }
110
+ }
111
+
112
+ /**
113
+ * New Service.
114
+ *
115
+ * @return mixed Value.
116
+ */
117
+ public function newAction()
118
+ {
119
+ $this->_forward('edit');
120
+ }
121
+
122
+ /**
123
+ * Save Service.
124
+ *
125
+ * @return mixed Value.
126
+ */
127
+ public function saveAction()
128
+ {
129
+ if ( $this->getRequest()->getPost() ) {
130
+ try {
131
+ $postData = $this->getRequest()->getPost();
132
+ $serviceModel = Mage::getModel('paybyfinance/service');
133
+
134
+ $serviceModel->setId($this->getRequest()->getParam('id'))
135
+ ->setName($postData['name'])
136
+ ->setType($postData['type'])
137
+ ->setApr($postData['apr'])
138
+ ->setTerm($postData['term'])
139
+ ->setDeferTerm($postData['defer_term'])
140
+ ->setOptionTerm($postData['option_term'])
141
+ ->setDeposit($postData['deposit'])
142
+ ->setFee($postData['fee'])
143
+ ->setMinAmount($postData['min_amount'])
144
+ ->setMultiplier($postData['multiplier'])
145
+ ->setRpm($postData['rpm'])
146
+ ->save();
147
+
148
+ Mage::getSingleton('adminhtml/session')->addSuccess(
149
+ Mage::helper('paybyfinance')
150
+ ->__('Service was successfully saved')
151
+ );
152
+ Mage::getSingleton('adminhtml/session')->setServiceData(false);
153
+ Mage::dispatchEvent(
154
+ 'paybyfinance_services_modified', array('service'=>$serviceModel)
155
+ );
156
+ $this->_redirect('*/*/');
157
+ return;
158
+ } catch (Exception $e) {
159
+ Mage::getSingleton('adminhtml/session')
160
+ ->addError($e->getMessage());
161
+ Mage::getSingleton('adminhtml/session')
162
+ ->setServiceData($this->getRequest()->getPost());
163
+ $this->_redirect(
164
+ '*/*/edit',
165
+ array('id' => $this->getRequest()->getParam('id'))
166
+ );
167
+ return;
168
+ }
169
+ }
170
+ $this->_redirect('*/*/');
171
+ }
172
+
173
+ /**
174
+ * Delete Service.
175
+ *
176
+ * @return mixed Value.
177
+ */
178
+ public function deleteAction()
179
+ {
180
+ if ($this->getRequest()->getParam('id') > 0 ) {
181
+ try {
182
+ $serviceModel = Mage::getModel('paybyfinance/service');
183
+
184
+ $serviceModel->setId($this->getRequest()->getParam('id'))
185
+ ->delete();
186
+
187
+ Mage::getSingleton('adminhtml/session')
188
+ ->addSuccess(
189
+ Mage::helper('paybyfinance')
190
+ ->__('Service was successfully deleted')
191
+ );
192
+ Mage::dispatchEvent(
193
+ 'paybyfinance_services_modified', array('service'=>$serviceModel)
194
+ );
195
+ $this->_redirect('*/*/');
196
+ } catch (Exception $e) {
197
+ Mage::getSingleton('adminhtml/session')
198
+ ->addError($e->getMessage());
199
+ $this->_redirect(
200
+ '*/*/edit',
201
+ array('id' => $this->getRequest()->getParam('id'))
202
+ );
203
+ }
204
+ }
205
+ $this->_redirect('*/*/');
206
+ }
207
+
208
+ /**
209
+ * Product grid for AJAX request. Sort and filter result for example.
210
+ *
211
+ * @return mixed Value.
212
+ */
213
+ public function gridAction()
214
+ {
215
+ $this->loadLayout();
216
+ $this->getResponse()->setBody(
217
+ $this->getLayout()
218
+ ->createBlock(
219
+ 'paybyfinance/adminhtml_paybyfinance_service_grid'
220
+ )->toHtml()
221
+ );
222
+ }
223
+ }
app/code/local/HC/PayByFinance/controllers/CheckoutController.php ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Controller for checkout actions
20
+ *
21
+ * @uses Mage_Adminhtml_Controller_Action
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_CheckoutController extends Mage_Core_Controller_Front_Action
30
+ {
31
+
32
+ /**
33
+ * Redirect form
34
+ *
35
+ * @return void
36
+ */
37
+ public function redirectformAction()
38
+ {
39
+ $session = Mage::getSingleton('paybyfinance/session');
40
+ $helper = Mage::helper('paybyfinance');
41
+ $cartHelper = Mage::helper('paybyfinance/cart');
42
+
43
+ $orderId = $session->getData('order_id');
44
+ if (!$orderId) {
45
+ echo "Invalid session";
46
+ return;
47
+ }
48
+ $order = Mage::getModel('sales/order')->load($orderId);
49
+ $eligibleProducts = $cartHelper->getEligibleProducts($order->getAllItems());
50
+ $eligibleAmount = $cartHelper->getEligibleAmount($order->getAllItems());
51
+ $serviceId = $order->getFinanceService();
52
+ $service = Mage::getModel('paybyfinance/service')->load($serviceId);
53
+ $address = $order->getBillingAddress();
54
+ $street = $address->getStreet();
55
+ $includeShipping = Mage::getStoreConfig($helper::XML_PATH_INCLUDE_SHIPPING);
56
+ $shippingCost = 0;
57
+ if ($includeShipping) {
58
+ $shippingCost = $order->getShippingAmount();
59
+ }
60
+ $mode = Mage::getStoreConfig($helper::XML_PATH_CONNECTION_MODE);
61
+
62
+ $calculator = Mage::getModel('paybyfinance/calculator');
63
+ $calculator->setService($serviceId)
64
+ ->setDeposit($order->getFinanceDeposit())
65
+ ->setAmount($eligibleAmount + $shippingCost)
66
+ ->setDiscount($order->getDiscountAmount())
67
+ ->setGiftcard($order->getGiftCardsAmount());
68
+ $financeResult = $calculator->getResults();
69
+
70
+ $post = Mage::getModel('paybyfinance/post');
71
+ $post->setPostAdapter(Mage::getStoreConfig($helper::XML_PATH_CONNECTION_MODE));
72
+
73
+ $productsInForm = array();
74
+ $productCount = 0;
75
+ $additionalItems = 0;
76
+ foreach ($eligibleProducts as $key => $product) {
77
+ $productsInForm['gc' . $productCount] = $product->getSku();
78
+ $productsInForm['pc' . $productCount] = $product->getSku();
79
+ $productsInForm['gd' . $productCount] = $product->getName();
80
+ $productsInForm['q' . $productCount] = intval($product->getQtyOrdered());
81
+ $productsInForm['gp' . $productCount] =
82
+ floor($product->getPriceInclTax() * 10000) / 10000;
83
+ $productCount++;
84
+ }
85
+
86
+ if ($includeShipping && $order->getShippingAmount() > 0) {
87
+ $shippingCost = $order->getShippingAmount();
88
+ $additionalItems++;
89
+ $productsInForm['gc' . ($productCount) ] = 'sc';
90
+ $productsInForm['pc' . ($productCount)] = 'sc';
91
+ $productsInForm['gd' . ($productCount)] = 'sc';
92
+ $productsInForm['q' . ($productCount)] = 1;
93
+ $productsInForm['gp' . ($productCount)] = number_format(
94
+ $shippingCost, 2, '.', ''
95
+ );
96
+ $productCount++;
97
+ }
98
+
99
+ $discount = (float) $order->getDiscountAmount();
100
+
101
+ if ($discount) {
102
+ $additionalItems++;
103
+ $productsInForm['gc' . ($productCount) ] = 'discount';
104
+ $productsInForm['pc' . ($productCount)] = 'discount';
105
+ $productsInForm['gd' . ($productCount)] = 'discount';
106
+ $productsInForm['q' . ($productCount)] = 1;
107
+ $productsInForm['gp' . ($productCount)] = number_format(
108
+ $discount, 2, '.', ''
109
+ );
110
+ $productCount++;
111
+ }
112
+
113
+ $giftcard = 0.0 - (float) $order->getGiftCardsAmount();
114
+
115
+ if ($giftcard) {
116
+ $additionalItems++;
117
+ $productsInForm['gc' . ($productCount) ] = 'giftcard';
118
+ $productsInForm['pc' . ($productCount)] = 'giftcard';
119
+ $productsInForm['gd' . ($productCount)] = 'giftcard';
120
+ $productsInForm['q' . ($productCount)] = 1;
121
+ $productsInForm['gp' . ($productCount)] = number_format(
122
+ $giftcard, 2, '.', ''
123
+ );
124
+ $productCount++;
125
+ }
126
+
127
+ $post->setQuoteData(
128
+ array_merge(
129
+ array(
130
+ 'cgid' => $service->getType(), // Service type
131
+ 'svtypename' => $service->getName(),
132
+ 'totalCashPrice' => $financeResult->getAmount()
133
+ - abs($discount)
134
+ - abs($giftcard),
135
+ 'totalGoodPrice' => $financeResult->getAmount()
136
+ - abs($discount)
137
+ - abs($giftcard),
138
+ 'damt' => $financeResult->getDeposit(),
139
+ 'loanAmt' => $financeResult->getFinanceAmount(),
140
+ 'term' => $service->getTerm(),
141
+ 'ratePerMonth' => floor($service->getRpm() * 1000) / 1000,
142
+ 'apr' => floor($service->getApr() * 1000) / 1000,
143
+ 'instalment' => $financeResult->getMonthlyPayment(), // monthly instalment
144
+ 'it' => count($eligibleProducts) + $additionalItems, // number of items
145
+ 'ro' => $order->getId(), // Order reference
146
+ 'title' => $address->getPrefix(),
147
+ 'firstname' => $address->getFirstname(),
148
+ 'surname' => $address->getLastname(),
149
+ 'street' => trim($street[0] . ' ' . (isset($street[1]) ? $street[1] : '')),
150
+ 'town' => $address->getCity(),
151
+ 'postcode' => $address->getPostcode(),
152
+ 'email' => $order->getCustomerEmail(),
153
+ ),
154
+ $productsInForm
155
+ )
156
+ );
157
+
158
+ // Generates the forwarder form
159
+ echo $post->getRedirectForm();
160
+ }
161
+
162
+ /**
163
+ * After the user has finished with the Finance forms, He's coming back here.
164
+ *
165
+ * @return void
166
+ */
167
+ public function responseAction()
168
+ {
169
+ $parameters = $this->getRequest()->getParams();
170
+ $coHelper = Mage::helper('paybyfinance/checkout');
171
+ $helper = Mage::helper('paybyfinance');
172
+ $helper->log("Response: \n" . $helper->arrayDump($parameters), 'post');
173
+
174
+ if (array_key_exists('ro', $parameters) && is_numeric($parameters['ro'])) {
175
+ $order = Mage::getModel('sales/order')->load($parameters['ro']);
176
+ }
177
+
178
+ // Unexpected error, PBF didn't send a correct order id (authentication error?)
179
+ if (!$order) {
180
+ $session = Mage::getSingleton('paybyfinance/session');
181
+ $order = Mage::getModel('sales/order')->load($session->getData('order_id'));
182
+ $coHelper->setUnexpectedError($order, $parameters);
183
+ $redirectUrl = 'paybyfinance/status/error';
184
+ } else {
185
+ $redirectUrl = $coHelper->processReturnStatus($order, $parameters);
186
+ }
187
+
188
+ $this->_redirect($redirectUrl);
189
+ }
190
+
191
+ }
app/code/local/HC/PayByFinance/controllers/NotificationController.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Controller for PBF pingback notifications
20
+ *
21
+ * @uses Mage_Adminhtml_Controller_Action
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_NotificationController extends Mage_Core_Controller_Front_Action
30
+ {
31
+ /**
32
+ * indexAction
33
+ *
34
+ * @return void.
35
+ */
36
+ public function indexAction()
37
+ {
38
+ $parameters = $this->getRequest()->getParams();
39
+ $helper = Mage::helper('paybyfinance');
40
+
41
+ if (!array_key_exists('order_ref', $parameters)
42
+ || !is_numeric($parameters['order_ref'])
43
+ || !array_key_exists('status', $parameters)
44
+ || !array_key_exists('applicationNo', $parameters)
45
+ ) {
46
+ $helper->log(
47
+ 'Error in notification parameters: ' . http_build_query($parameters),
48
+ 'notification'
49
+ );
50
+ echo "0";
51
+ die();
52
+ }
53
+
54
+ $orderId = $parameters['order_ref'];
55
+
56
+ $order = Mage::getModel('sales/order')->load($orderId);
57
+ if (!$order->getId()) {
58
+ $helper->log('Order does not exist: ' . $orderId, 'notification');
59
+ echo "0";
60
+ die();
61
+ }
62
+
63
+ $notificationHelper = Mage::helper('paybyfinance/notification');
64
+ $result = $notificationHelper->processOrder($order, $parameters);
65
+
66
+ if ($result) {
67
+ $helper->log(
68
+ 'Notification received successfully for order: ' . $orderId,
69
+ 'notification'
70
+ );
71
+ echo "1";
72
+ die(); // Success
73
+ } else {
74
+ echo "0";
75
+ die(); // Error saving the order
76
+ }
77
+ }
78
+ }
app/code/local/HC/PayByFinance/controllers/SelectorController.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Controller for selector operations
20
+ *
21
+ * @uses Mage_Adminhtml_Controller_Action
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_SelectorController extends Mage_Core_Controller_Front_Action
30
+ {
31
+ protected $_services;
32
+ protected $_amount;
33
+
34
+ /**
35
+ * Displaying the services as JSON via an AJAX call.
36
+ *
37
+ * @return void.
38
+ */
39
+ public function servicesAction()
40
+ {
41
+ $helper = Mage::helper('paybyfinance');
42
+
43
+ $json = $helper->getSelectorJSON(
44
+ $this->getServices(), $this->getAmount()
45
+ );
46
+
47
+ $this->getResponse()->setHeader('Content-type', 'application/json');
48
+ $this->getResponse()->setBody($json);
49
+ }
50
+
51
+ /**
52
+ * getAmount
53
+ *
54
+ * @return float Amount.
55
+ */
56
+ protected function getAmount()
57
+ {
58
+ if (!isset($this->_amount)) {
59
+ $cartHelper = Mage::helper('paybyfinance/cart');
60
+ $this->_amount = $cartHelper->getEligibleAmount()
61
+ + $cartHelper->getQuoteAdditionalAmount();
62
+ }
63
+
64
+ return $this->_amount;
65
+ }
66
+
67
+ /**
68
+ * Get available services
69
+ *
70
+ * @return HC_PayByFinance_Model_Mysql4_Service_Collection Services.
71
+ */
72
+ protected function getServices()
73
+ {
74
+ if (!isset($this->_services)) {
75
+ $amount = $this->getAmount();
76
+ $this->_services = Mage::getModel('paybyfinance/service')
77
+ ->getCollection()
78
+ ->addPriceFilter($amount)
79
+ ->load();
80
+ }
81
+
82
+ return $this->_services;
83
+ }
84
+ }
app/code/local/HC/PayByFinance/controllers/SessionController.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Controller for session storage operations
20
+ *
21
+ * @uses Mage_Adminhtml_Controller_Action
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_SessionController extends Mage_Core_Controller_Front_Action
30
+ {
31
+ /**
32
+ * indexAction
33
+ *
34
+ * @return void.
35
+ */
36
+ public function indexAction()
37
+ {
38
+ echo 'Hello Index!';
39
+ }
40
+
41
+ /**
42
+ * saveAction
43
+ *
44
+ * @throws Exception
45
+ *
46
+ * @return mixed Value.
47
+ */
48
+ public function saveAction()
49
+ {
50
+ $session = Mage::getSingleton('paybyfinance/session');
51
+ $service = (int) $this->getRequest()->getParam('service');
52
+ $deposit = (int) $this->getRequest()->getParam('deposit');
53
+ if ($this->getRequest()->getParam('enabled') == 1) {
54
+ $enabled = true;
55
+ } else {
56
+ $enabled = false;
57
+ }
58
+
59
+ if ($deposit > 60) {
60
+ throw new Exception("Deposit can't be bigger than 60%", 1);
61
+ }
62
+
63
+ if (!Mage::getModel('paybyfinance/service')->load($service)) {
64
+ throw new Exception("Invalid service id", 1);
65
+ }
66
+
67
+ $session->setData('enabled', $enabled);
68
+ $session->setData('service', $service);
69
+ $session->setData('deposit', $deposit);
70
+ }
71
+
72
+ }
app/code/local/HC/PayByFinance/controllers/StatusController.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ /**
19
+ * Controller for status pages
20
+ *
21
+ * @uses Mage_Adminhtml_Controller_Action
22
+ *
23
+ * @category HC
24
+ * @package PayByFinance
25
+ * @author Healthy Websites <support@healthywebsites.co.uk>
26
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
27
+ * @link http://www.healthywebsites.co.uk/
28
+ */
29
+ class HC_PayByFinance_StatusController extends Mage_Core_Controller_Front_Action
30
+ {
31
+ /**
32
+ * indexAction
33
+ *
34
+ * @return void.
35
+ */
36
+ public function indexAction()
37
+ {
38
+ echo 'Hello Index!';
39
+ }
40
+
41
+ /**
42
+ * accepted
43
+ *
44
+ * @return void
45
+ */
46
+ public function acceptedAction()
47
+ {
48
+ $this->loadLayout()->renderLayout();
49
+ }
50
+
51
+ /**
52
+ * referred
53
+ *
54
+ * @return void
55
+ */
56
+ public function referredAction()
57
+ {
58
+ $this->loadLayout()->renderLayout();
59
+ }
60
+
61
+ /**
62
+ * declined
63
+ *
64
+ * @return void
65
+ */
66
+ public function declinedAction()
67
+ {
68
+ $this->loadLayout()->renderLayout();
69
+ }
70
+
71
+ /**
72
+ * abandoned
73
+ *
74
+ * @return void
75
+ */
76
+ public function abandonedAction()
77
+ {
78
+ $this->loadLayout()->renderLayout();
79
+ }
80
+
81
+ /**
82
+ * error
83
+ *
84
+ * @return void
85
+ */
86
+ public function errorAction()
87
+ {
88
+ $this->loadLayout()->renderLayout();
89
+ }
90
+
91
+ }
app/code/local/HC/PayByFinance/etc/adminhtml.xml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+
4
+ <menu>
5
+ <paybyfinance module="paybyfinance">
6
+ <title>Pay By Finance</title>
7
+ <sort_order>71</sort_order>
8
+ <children>
9
+ <services module="paybyfinance">
10
+ <title>Services</title>
11
+ <sort_order>0</sort_order>
12
+ <action>adminhtml/paybyfinance_service</action>
13
+ </services>
14
+ <configuration>
15
+ <title>Configuration</title>
16
+ <sort_order>1</sort_order>
17
+ <action>adminhtml/system_config/edit/section/hc_paybyfinance</action>
18
+ </configuration>
19
+ </children>
20
+ </paybyfinance>
21
+ </menu>
22
+
23
+ <acl>
24
+ <resources>
25
+ <all>
26
+ <title>Allow Everything</title>
27
+ </all>
28
+ <admin>
29
+ <children>
30
+ <system>
31
+ <children>
32
+ <config>
33
+ <children>
34
+ <hc_paybyfinance>
35
+ <title>Hitachi Capital</title>
36
+ <sort_order>100</sort_order>
37
+ </hc_paybyfinance>
38
+ </children>
39
+ </config>
40
+ </children>
41
+ </system>
42
+ <paybyfinance>
43
+ <title>Paybyfinance Module</title>
44
+ <sort_order>200</sort_order>
45
+ </paybyfinance>
46
+ </children>
47
+ </admin>
48
+ </resources>
49
+ </acl>
50
+
51
+ </config>
app/code/local/HC/PayByFinance/etc/config.xml ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <HC_PayByFinance>
5
+ <version>1.0.2</version>
6
+ </HC_PayByFinance>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <paybyfinance>
11
+ <class>HC_PayByFinance_Block</class>
12
+ </paybyfinance>
13
+ </blocks>
14
+
15
+ <helpers>
16
+ <paybyfinance>
17
+ <class>HC_PayByFinance_Helper</class>
18
+ </paybyfinance>
19
+ </helpers>
20
+
21
+ <models>
22
+ <paybyfinance>
23
+ <class>HC_PayByFinance_Model</class>
24
+ <resourceModel>paybyfinance_mysql4</resourceModel>
25
+ </paybyfinance>
26
+ <paybyfinance_mysql4>
27
+ <class>HC_PayByFinance_Model_Mysql4</class>
28
+ <entities>
29
+ <service>
30
+ <table>paybyfinance_service</table>
31
+ </service>
32
+ <log>
33
+ <table>paybyfinance_log</table>
34
+ </log>
35
+ </entities>
36
+ </paybyfinance_mysql4>
37
+
38
+ <paypal>
39
+ <rewrite>
40
+ <api_nvp>HC_PayByFinance_Model_Paypal_Api_Nvp</api_nvp>
41
+ <hostedpro_request>HC_PayByFinance_Model_Paypal_Hostedpro_Request</hostedpro_request>
42
+ </rewrite>
43
+ </paypal>
44
+ <paypaluk>
45
+ <rewrite>
46
+ <api_nvp>HC_PayByFinance_Model_PaypalUk_Api_Nvp</api_nvp>
47
+ </rewrite>
48
+ </paypaluk>
49
+
50
+ </models>
51
+ <sales>
52
+ <quote>
53
+ <totals>
54
+ <financeamount>
55
+ <class>paybyfinance/sales_quote_financeamount</class>
56
+ <after>subtotal,shipping,discount</after>
57
+ <before>grand_total</before>
58
+ </financeamount>
59
+ <paybyfinance_totalcost>
60
+ <class>paybyfinance/sales_quote_totalcost</class>
61
+ <after>subtotal,shipping,discount</after>
62
+ <before>grand_total</before>
63
+ </paybyfinance_totalcost>
64
+ </totals>
65
+ </quote>
66
+ <order_invoice>
67
+ <totals>
68
+ <financeamount>
69
+ <class>paybyfinance/sales_order_invoice_financeamount</class>
70
+ <after>subtotal,shipping,discount</after>
71
+ <before>grand_total</before>
72
+ </financeamount>
73
+ </totals>
74
+ </order_invoice>
75
+ <order_creditmemo>
76
+ <totals>
77
+ <financeamount>
78
+ <class>paybyfinance/sales_order_creditmemo_financeamount</class>
79
+ <after>subtotal,shipping,discount</after>
80
+ <before>grand_total</before>
81
+ </financeamount>
82
+ </totals>
83
+ </order_creditmemo>
84
+ </sales>
85
+ <resources>
86
+ <paybyfinance_setup>
87
+ <setup>
88
+ <module>HC_PayByFinance</module>
89
+ <class>HC_PayByFinance_Model_Resource_Setup</class>
90
+ </setup>
91
+ <connection>
92
+ <use>core_setup</use>
93
+ </connection>
94
+ </paybyfinance_setup>
95
+ <paybyfinance_write>
96
+ <connection>
97
+ <use>core_write</use>
98
+ </connection>
99
+ </paybyfinance_write>
100
+ <paybyfinance_read>
101
+ <connection>
102
+ <use>core_read</use>
103
+ </connection>
104
+ </paybyfinance_read>
105
+ </resources>
106
+
107
+ <events>
108
+ <paybyfinance_services_modified>
109
+ <observers>
110
+ <paybyfinance>
111
+ <type>singleton</type>
112
+ <class>paybyfinance/observer</class>
113
+ <method>enterpriseCacheClear</method>
114
+ </paybyfinance>
115
+ </observers>
116
+ </paybyfinance_services_modified>
117
+ <checkout_onepage_controller_success_action>
118
+ <observers>
119
+ <paybyfinance_checkout_success_action>
120
+ <type>singleton</type>
121
+ <class>paybyfinance/observer</class>
122
+ <method>checkoutSuccess</method>
123
+ </paybyfinance_checkout_success_action>
124
+ </observers>
125
+ </checkout_onepage_controller_success_action>
126
+ <sales_convert_quote_address_to_order>
127
+ <observers>
128
+ <paybyfinance_salesquoteaddressconvert>
129
+ <type>singleton</type>
130
+ <class>paybyfinance/observer</class>
131
+ <method>convertQuoteAddressToOrder</method>
132
+ </paybyfinance_salesquoteaddressconvert>
133
+ </observers>
134
+ </sales_convert_quote_address_to_order>
135
+ <sales_order_save_after>
136
+ <observers>
137
+ <paybyfinance_salesordersaveObserver>
138
+ <type>singleton</type>
139
+ <class>paybyfinance/observer</class>
140
+ <method>orderAfterSave</method>
141
+ </paybyfinance_salesordersaveObserver>
142
+ </observers>
143
+ </sales_order_save_after>
144
+ <paypal_prepare_line_items>
145
+ <observers>
146
+ <hc_paypalpreparelineitemsObserver>
147
+ <type>singleton</type>
148
+ <class>paybyfinance/observer</class>
149
+ <method>paypalPrepareLineItems</method>
150
+ </hc_paypalpreparelineitemsObserver>
151
+ </observers>
152
+ </paypal_prepare_line_items>
153
+ </events>
154
+
155
+ </global>
156
+
157
+ <frontend>
158
+ <layout>
159
+ <updates>
160
+ <hc_paybyfinance>
161
+ <file>paybyfinance.xml</file>
162
+ </hc_paybyfinance>
163
+ </updates>
164
+ </layout>
165
+ <routers>
166
+ <hc_paybyfinance>
167
+ <use>standard</use>
168
+ <args>
169
+ <module>HC_PayByFinance</module>
170
+ <frontName>paybyfinance</frontName>
171
+ </args>
172
+ </hc_paybyfinance>
173
+ </routers>
174
+ </frontend>
175
+
176
+ <adminhtml>
177
+ <layout>
178
+ <updates>
179
+ <hc_paybyfinance>
180
+ <file>paybyfinance.xml</file>
181
+ </hc_paybyfinance>
182
+ </updates>
183
+ </layout>
184
+ <events>
185
+ <payment_info_block_prepare_specific_information>
186
+ <observers>
187
+ <hc_payment_info_specifics>
188
+ <class>paybyfinance/observer</class>
189
+ <method>getPaymentInfo</method>
190
+ </hc_payment_info_specifics>
191
+ </observers>
192
+ </payment_info_block_prepare_specific_information>
193
+ </events>
194
+ </adminhtml>
195
+
196
+ <admin>
197
+ <routers>
198
+ <adminhtml>
199
+ <use>admin</use>
200
+ <args>
201
+ <modules>
202
+ <paybyfinance before="Mage_Adminhtml">HC_PayByFinance_Adminhtml</paybyfinance>
203
+ </modules>
204
+ </args>
205
+ </adminhtml>
206
+ </routers>
207
+ </admin>
208
+
209
+ <default>
210
+ <hc_paybyfinance>
211
+ <general>
212
+ <active>1</active>
213
+ <minimum_price_product>500</minimum_price_product>
214
+ <minimum_price_basket>500</minimum_price_basket>
215
+ <enable_producttypes>simple</enable_producttypes>
216
+ <fixed_deposit>0</fixed_deposit>
217
+ <include_shipping>1</include_shipping>
218
+ </general>
219
+ <order_status>
220
+ <accepted>finance_accepted</accepted>
221
+ <referred>finance_referred</referred>
222
+ <declined>finance_declined</declined>
223
+ <abandoned>finance_abandoned</abandoned>
224
+ <error>finance_error</error>
225
+ </order_status>
226
+ <blocks_info>
227
+ <information>finance_information</information>
228
+ </blocks_info>
229
+ <account>
230
+ <connectionmode>test</connectionmode>
231
+ <id1></id1>
232
+ <id2></id2>
233
+ <erroremail></erroremail>
234
+ <retailername>{Retailer Name as appears on FCA register}</retailername>
235
+ <tradingname>trading as {Trading Name}</tradingname>
236
+ </account>
237
+ </hc_paybyfinance>
238
+ </default>
239
+ </config>
app/code/local/HC/PayByFinance/etc/system.xml ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <hc_paybyfinance translate="label">
5
+ <label>Hitachi Capital - Pay By Finance</label>
6
+ <tab>sales</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>410</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
+ <groups>
13
+ <general>
14
+ <label>General</label>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <sort_order>10</sort_order>
19
+ <fields>
20
+ <active translate="label">
21
+ <label>Enabled</label>
22
+ <frontend_type>select</frontend_type>
23
+ <source_model>adminhtml/system_config_source_yesno</source_model>
24
+ <sort_order>1</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>1</show_in_website>
27
+ <show_in_store>1</show_in_store>
28
+ </active>
29
+ <minimum_price_product>
30
+ <label>Minimum retail price per product</label>
31
+ <frontend_type>text</frontend_type>
32
+ <sort_order>2</sort_order>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>1</show_in_website>
35
+ <show_in_store>1</show_in_store>
36
+ </minimum_price_product>
37
+ <minimum_price_basket>
38
+ <label>Minimum basket price</label>
39
+ <frontend_type>text</frontend_type>
40
+ <sort_order>3</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ </minimum_price_basket>
45
+ <enable_producttypes>
46
+ <label>Enable products in product type</label>
47
+ <frontend_type>multiselect</frontend_type>
48
+ <source_model>paybyfinance/config_source_catalog_product_type</source_model>
49
+ <sort_order>4</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ </enable_producttypes>
54
+ <fixed_deposit translate="label">
55
+ <label>Fixed deposit only</label>
56
+ <frontend_type>select</frontend_type>
57
+ <source_model>adminhtml/system_config_source_yesno</source_model>
58
+ <sort_order>5</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>1</show_in_store>
62
+ </fixed_deposit>
63
+ <include_shipping translate="label">
64
+ <label>Include shipping in financed amount</label>
65
+ <frontend_type>select</frontend_type>
66
+ <source_model>adminhtml/system_config_source_yesno</source_model>
67
+ <sort_order>6</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>1</show_in_website>
70
+ <show_in_store>1</show_in_store>
71
+ </include_shipping>
72
+ </fields>
73
+ </general>
74
+ <order_status>
75
+ <label>Order Status</label>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ <show_in_store>1</show_in_store>
79
+ <sort_order>20</sort_order>
80
+ <fields>
81
+ <accepted>
82
+ <label>Finance accepted</label>
83
+ <frontend_type>select</frontend_type>
84
+ <source_model>adminhtml/system_config_source_order_status</source_model>
85
+ <sort_order>1</sort_order>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>1</show_in_website>
88
+ <show_in_store>1</show_in_store>
89
+ </accepted>
90
+ <referred>
91
+ <label>Finance referred</label>
92
+ <frontend_type>select</frontend_type>
93
+ <source_model>adminhtml/system_config_source_order_status</source_model>
94
+ <sort_order>2</sort_order>
95
+ <show_in_default>1</show_in_default>
96
+ <show_in_website>1</show_in_website>
97
+ <show_in_store>1</show_in_store>
98
+ </referred>
99
+ <declined>
100
+ <label>Finance declined</label>
101
+ <frontend_type>select</frontend_type>
102
+ <source_model>adminhtml/system_config_source_order_status</source_model>
103
+ <sort_order>3</sort_order>
104
+ <show_in_default>1</show_in_default>
105
+ <show_in_website>1</show_in_website>
106
+ <show_in_store>1</show_in_store>
107
+ </declined>
108
+ <abandoned>
109
+ <label>Finance abandoned</label>
110
+ <frontend_type>select</frontend_type>
111
+ <source_model>adminhtml/system_config_source_order_status</source_model>
112
+ <sort_order>4</sort_order>
113
+ <show_in_default>1</show_in_default>
114
+ <show_in_website>1</show_in_website>
115
+ <show_in_store>1</show_in_store>
116
+ </abandoned>
117
+ <error>
118
+ <label>Finance error</label>
119
+ <frontend_type>select</frontend_type>
120
+ <source_model>adminhtml/system_config_source_order_status</source_model>
121
+ <sort_order>5</sort_order>
122
+ <show_in_default>1</show_in_default>
123
+ <show_in_website>1</show_in_website>
124
+ <show_in_store>1</show_in_store>
125
+ </error>
126
+ </fields>
127
+ </order_status>
128
+ <blocks_info>
129
+ <label>Blocks Info</label>
130
+ <show_in_default>1</show_in_default>
131
+ <show_in_website>1</show_in_website>
132
+ <show_in_store>1</show_in_store>
133
+ <sort_order>40</sort_order>
134
+ <fields>
135
+ <information>
136
+ <label>Information</label>
137
+ <frontend_type>select</frontend_type>
138
+ <source_model>paybyfinance/config_source_cms_block</source_model>
139
+ <sort_order>1</sort_order>
140
+ <show_in_default>1</show_in_default>
141
+ <show_in_website>1</show_in_website>
142
+ <show_in_store>1</show_in_store>
143
+ </information>
144
+ <accepted>
145
+ <label>Accepted</label>
146
+ <frontend_type>select</frontend_type>
147
+ <source_model>paybyfinance/config_source_cms_block</source_model>
148
+ <sort_order>2</sort_order>
149
+ <show_in_default>1</show_in_default>
150
+ <show_in_website>1</show_in_website>
151
+ <show_in_store>1</show_in_store>
152
+ </accepted>
153
+ <referred>
154
+ <label>Referred</label>
155
+ <frontend_type>select</frontend_type>
156
+ <source_model>paybyfinance/config_source_cms_block</source_model>
157
+ <sort_order>3</sort_order>
158
+ <show_in_default>1</show_in_default>
159
+ <show_in_website>1</show_in_website>
160
+ <show_in_store>1</show_in_store>
161
+ </referred>
162
+ <declined>
163
+ <label>Declined</label>
164
+ <frontend_type>select</frontend_type>
165
+ <source_model>paybyfinance/config_source_cms_block</source_model>
166
+ <sort_order>4</sort_order>
167
+ <show_in_default>1</show_in_default>
168
+ <show_in_website>1</show_in_website>
169
+ <show_in_store>1</show_in_store>
170
+ </declined>
171
+ <abandoned>
172
+ <label>Abandoned</label>
173
+ <frontend_type>select</frontend_type>
174
+ <source_model>paybyfinance/config_source_cms_block</source_model>
175
+ <sort_order>5</sort_order>
176
+ <show_in_default>1</show_in_default>
177
+ <show_in_website>1</show_in_website>
178
+ <show_in_store>1</show_in_store>
179
+ </abandoned>
180
+ <error>
181
+ <label>Error</label>
182
+ <frontend_type>select</frontend_type>
183
+ <source_model>paybyfinance/config_source_cms_block</source_model>
184
+ <sort_order>6</sort_order>
185
+ <show_in_default>1</show_in_default>
186
+ <show_in_website>1</show_in_website>
187
+ <show_in_store>1</show_in_store>
188
+ </error>
189
+ </fields>
190
+ </blocks_info>
191
+
192
+ <account>
193
+ <label>Account Information</label>
194
+ <show_in_default>1</show_in_default>
195
+ <show_in_website>1</show_in_website>
196
+ <show_in_store>1</show_in_store>
197
+ <sort_order>50</sort_order>
198
+ <fields>
199
+ <connectionmode>
200
+ <label>Connection Mode</label>
201
+ <frontend_type>select</frontend_type>
202
+ <source_model>paybyfinance/config_source_connectionmode</source_model>
203
+ <sort_order>1</sort_order>
204
+ <show_in_default>1</show_in_default>
205
+ <show_in_website>1</show_in_website>
206
+ <show_in_store>1</show_in_store>
207
+ </connectionmode>
208
+ <id1>
209
+ <label>E-Tailer Account Id1</label>
210
+ <frontend_type>text</frontend_type>
211
+ <sort_order>2</sort_order>
212
+ <show_in_default>1</show_in_default>
213
+ <show_in_website>1</show_in_website>
214
+ <show_in_store>1</show_in_store>
215
+ </id1>
216
+ <id2>
217
+ <label>E-Tailer Account Id2</label>
218
+ <frontend_type>text</frontend_type>
219
+ <sort_order>3</sort_order>
220
+ <show_in_default>1</show_in_default>
221
+ <show_in_website>1</show_in_website>
222
+ <show_in_store>1</show_in_store>
223
+ </id2>
224
+ <erroremail>
225
+ <label>Error E-Mail Address</label>
226
+ <frontend_type>text</frontend_type>
227
+ <sort_order>4</sort_order>
228
+ <show_in_default>1</show_in_default>
229
+ <show_in_website>1</show_in_website>
230
+ <show_in_store>1</show_in_store>
231
+ </erroremail>
232
+ <retailername>
233
+ <label>Retailer Name as appears on FCA register</label>
234
+ <frontend_type>text</frontend_type>
235
+ <sort_order>5</sort_order>
236
+ <show_in_default>1</show_in_default>
237
+ <show_in_website>1</show_in_website>
238
+ <show_in_store>1</show_in_store>
239
+ </retailername>
240
+ <tradingname>
241
+ <label>Trading Name</label>
242
+ <frontend_type>text</frontend_type>
243
+ <sort_order>6</sort_order>
244
+ <show_in_default>1</show_in_default>
245
+ <show_in_website>1</show_in_website>
246
+ <show_in_store>1</show_in_store>
247
+ </tradingname>
248
+ </fields>
249
+ </account>
250
+ </groups>
251
+ </hc_paybyfinance>
252
+ </sections>
253
+ </config>
app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/abandoned.html ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <div class="page-head">
2
+ <h3>Your credit application has been abandoned</h3>
3
+ </div>
4
+ <p>
5
+ You have abandoned your finance application, please contact us if you experienced
6
+ a problem with your application or if you require assistance.<br /><br />
7
+ <strong>Your order number is: {{var order_id}}</strong>.<br/><br />
8
+ You should expect a refund in 3-5 business day for the deposit amount or alternatively you can pay the balance by phone by contacting us.
9
+ </p>
app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/accepted.html ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="page-head">
2
+ <h3>Congratulations, your credit application was successful!</h3>
3
+ </div>
4
+ <p>
5
+ You should have by now downloaded your documentation or requested for it to be posted out to you.<br /><br />
6
+ Please <strong>read this carefully</strong> checking that all the details are correct, then <strong>print and sign</strong> both the finance agreement and Direct Debit instruction.<br /><br />
7
+ Post both forms to the address shown on the finance agreement.<br /><br />
8
+ <strong>IMPORTANT: Please ensure you return your documentation to the Freepost address provided as soon as possible to avoid any delay in the delivery of your goods.&nbsp;
9
+ We cannot ship your goods out until Hitachi Capital receive this documentation.</strong><br /><br />
10
+ Following receipt of your finance agreement your goods will be dispatched.<br />
11
+ </p>
app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/declined.html ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="page-head">
2
+ <h3>Your credit application has been declined</h3>
3
+ </div>
4
+ <p>
5
+ We regret to inform you that your finance application on order number {{var order_id}} has been declined.<br /><br />
6
+ <strong>Please call us as we may be able to offer you alternative options.</strong><br /><br />
7
+ If we don’t hear from you, we will process the refund of your deposit in 3-5 days.<br /><br />
8
+ Your application was assessed using the credit scoring system by Hitachi Capital (UK) which calculates a credit score by allocating points to the information supplied by you.
9
+ The credit score is given to you by the Credit Reference Agency Experian who base their assessment on your credit history are also taken into account,
10
+ for example your payment history on any current or settled financial commitments. The credit score and the Experian score are added together
11
+ to produce a total credit score on your application<br /><br />
12
+ <strong>IMPORTANT: These checks are all carried out independently by Hitachi Capital UK Plc. and are not under our control.</strong><br /><br />
13
+ The Credit Reference Agency contacted in connection with your application was:<br /><br />
14
+ Experian Help Service<br />
15
+ PO Box 8000<br />
16
+ Nottingham<br />
17
+ NG1 5GX<br /><br />
18
+ You can obtain a credit report from Experian if you have any concerns by visiting <a href="http://www.experian.co.uk" target="_blank">www.experian.co.uk.</a><br /><br />
19
+ You can also contact Hitachi Capital on: Pay by Finance Team, 2 Apex View, Leeds, LS11 9BH
20
+ </p>
app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/error.html ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <div class="page-head">
2
+ <h3>An error has occurred while processing your application</h3>
3
+ </div>
4
+ <p>
5
+ please contact us if you require any further assistance.<br /><br />
6
+ <strong>Your order number is: {{var order_id}}</strong>.<br/><br />
7
+ You should expect a refund in 3-5 business day for the deposit amount or alternatively you can pay the balance by phone by contacting us.
8
+ </p>
app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/information.html ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="clear: both;" style="height: 15px;"></div>
2
+ <div id="main_information">
3
+ <h2>Financing Information</h2>
4
+
5
+ <p>Thanks for selecting to pay via finance. To complete this you will be directed to the checkout to pay the deposit and any non-finance products in your order.</p>
6
+
7
+ <p>Once you have completed this payment, you will be redirected to the Hitachi Capital Website to fill out your online credit application. This should not take more than 5 minutes and you will get an instant decision.</p>
8
+ <p><b><u>IMPORTANT</u>:</b> You will need print, sign and send the agreement provided by Hitachi Capital back to them before we can ship the products. Please do this as soon as possible after having the online application accepted to ensure we ship to you as soon as possible.</p>
9
+
10
+ <h2>Finance Criteria</h2>
11
+ <p>Before you continue, please ensure that you meet the following criteria:</p>
12
+
13
+ <ul>
14
+ <li>You are able to provide a residential address not a business address</li>
15
+ <li>You are a resident at this address</li>
16
+ <li>You are a UK resident for over 12 months and intend to stay in the UK</li>
17
+ <li>You are 18 or older</li>
18
+ <li>You or your partner is, in permanent paid employment (over 16 hours per week), retired and receiving a pension or are self employed</li>
19
+ <li>You are able to provide acceptable proof of address (if delivery address is different to that used in the credit agreement) and proof of signature</li>
20
+ <li>You are purchasing the product for consumer use and not business use</li>
21
+ </ul>
22
+
23
+ <p>If you fail to meet these criteria, please contact us</p>
24
+ </div>
app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/page-finance-options.html ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <h2>More information</h2>
2
+ <p>All we require is a minimum deposit of 10%, you can pay a higher deposit if you wish, and the order must have a value of at least £500.</p>
3
+ <p>Item Value: £500-£1000 - 6 months interest free credit.</p>
4
+ <p>Item Value: £1000 plus - 6 or 12 months interest free credit.</p>
5
+ <p>Credit is available to permanent UK residents only.</p>
6
+
7
+ <h2>Example of Finance Offer</h2>
8
+
9
+ <h4>12 Months Interest Free Credit</h4>
10
+ <p>Cash Price £1000.00<br/>
11
+ Deposit @ 10% £100.00<br/>
12
+ Charge for Credit £0<br/>
13
+ Total amount of Credit £900.00<br/>
14
+ APR 0% APR Representative<br/>
15
+ Number of Payments 12<br/>
16
+ Monthly Payment £75.00<br/>
17
+ Total Amount payable £1000.00<br/>
18
+ </p>
19
+
20
+ <h4>48 Months Interest Bearing</h4>
21
+ <p>
22
+ Cash Price £1000.00 <br/>
23
+ Deposit @ 10% £100.00<br/>
24
+ Charge for Credit £222.72<br/>
25
+ Total amount of Credit £900.00<br/>
26
+ APR 11.9% APR Representative<br/>
27
+ Number of Payments 48<br/>
28
+ Monthly Payment £23.39<br/>
29
+ Total Amount payable £1222.72<br/>
30
+ </p>
31
+
32
+ <p>We also offer 24, 36 or 48 months Interest Bearing Credit, on orders over £500.00. Please see previous example above of an Interest Bearing option.</p>
33
+
34
+ <h3>How do I choose to pay by interest free credit?</h3>
35
+ <p>Just select the interest-free credit option on the check out page or let the sales consultant know if you're buying in our showrooms.</p>
36
+
37
+ <h3>When do my repayments start?</h3>
38
+ <p>Your monthly repayments will begin one month after your purchase has been delivered.</p>
39
+
40
+ <h3>Are there any arrangement fees or hidden extras for credit?</h3>
41
+ <p>No. There are no arrangement fees or hidden extras.</p>
42
+
43
+ <p>Acceptance is subject to status. Credit provided by Hitachi Capital (UK) PLC trading as Hitachi Capital Consumer Finance, 2 Apex View, Leeds, LS11 9BH. Authorised and regulated by the Financial Conduct Authority.</p>
44
+
45
+ <p>NOTE - Finance is only applicable to UK residents</p>
46
+
47
+ <p>When you buy online from YourDomain.com you have the choice of applying for instant finance by adding your purchase to the shopping basket, selecting the option to PaybyFinance, and completing a finance application form. The whole process only takes a few minutes and is simple and secure. Once your finance application is approved, you will receive an e-mail advising you of how to download the finance agreement. Please read this carefully checking that all the details are correct, then either e-sign the agreement, if offered, or print and sign the finance agreement twice. Post the document to the address shown on the finance agreement. Following receipt of your finance agreement and a few additional checks, your goods will be dispatched</p>
48
+
49
+ <p><strong>YourDomain.com are licensed credit brokers</strong></p>
50
+
51
+ <p>Credit is subject to status and written quotations are available on request. The credit advertised is provided by one credit provider with whom we have a commercial relationship.</p>
52
+
53
+ <p><strong>Applying for online finance</strong></p>
54
+ <p>Applying for online finance couldn't be easier or more convenient. Once you've chosen the products you'd like to purchase, simply complete a brief online application form accessed via the 'checkout'. Just follow the simple instructions, entering your personal details as required and we'll do the rest.</p>
55
+
56
+ <p><strong>Your questions answered</strong></p>
57
+ <p>Here's some of the most commonly asked questions regarding online finance.</p>
58
+
59
+ <p><strong>Once my application is approved, what happens next?</strong></p>
60
+ <p>Within minutes of your application being approved, you will be presented with the option to sign your credit agreement. If you are offered the ability e-sign your credit agreement and choose to do so, a PDF of your credit agreement will be displayed on screen. You should read the credit agreement carefully before clicking all the relevant sections agreeing to its terms. Once you have agreed to the terms of the credit agreement (Retailer Name) will be notified and you need do nothing more. If you are presented with the ability to print and return your credit agreement you should print the PDF agreement, read it carefully and then sign the document following the instructions on the covering letter. This signed document should then be posted to the address shown on the covering letter of the credit agreement. Note that products will not be allocated to your order until your completed and signed agreement is returned and received by Hitachi Capital. Shipment of your goods will follow soon after your agreement has been returned to our finance company.</p>
61
+
62
+ <p><strong>Will you credit score me and if so, what does this mean?</strong></p>
63
+ <p>Credit scoring is the process used by financial services companies to evaluate the credit risk of new applicants. This technique will be applied to your application for online finance. Credit scoring works by awarding points for each answer given on the application form such as age, income and occupation, together with information obtained from credit reference agencies. This information allows us to produce consistent decisions, ensuring all our applicants are treated fairly. Credit scoring does not discriminate on the grounds of sex, race, religion or disability.</p>
64
+
65
+ <p><strong>If you decline my application, what is the reason?</strong></p>
66
+ <p>In addition to credit scoring, we also take into account confirmation of your identity, validation of certain application details, existing commitments and information held at the credit reference agencies. Though we are unable to provide you with a main reason for decline of your application, it is usually based on one, or a combination of the following:</p>
67
+ <ul>
68
+ <li>Your credit score (note that every finance company will score you differently)</li>
69
+ <li>Adverse credit reference agency information</li>
70
+ <li>You are considered to be overcommitted</li>
71
+ <li>You are aged under 18</li>
72
+ <li>Your existing account performance with other lenders</li>
73
+ </ul>
74
+
75
+ <p><strong>What type of information do credit reference agencies hold about me?</strong></p>
76
+ <p>Some of the information is public information, for example electoral roll, County Court Judgements and bankruptcies. Other lenders may also file information about accounts you hold with them for instance this could include your payment history and outstanding balance on these accounts. Any requests for credit, where a credit reference search has been undertaken, will also be filed, although the result of the request is not recorded.</p>
77
+
78
+ <p><strong>How do I obtain a copy of this information?</strong></p>
79
+ <p>You should send a cheque for £2.00 made payable to the relevant company, together with details of all addresses at which you have lived over the last 6 years:</p>
80
+ <p>Consumer Help Desk Experian Limited PO Box 8000 <br/>
81
+ Nottingham NG1 5GX</p>
82
+
83
+ <p>Equifax Ltd., Credit File Advice Centre. PO Box 1140.<br/>
84
+ Bradford, BD1 5US</p>
85
+
86
+ <p>Consumer Services, Callcredit Limited, PO Box 491,<br/>
87
+ Leeds, LS3 1WZ</p>
88
+
89
+ <p>The above listed agencies will provide details of information relating via these addresses. If you believe that the information is incorrect, you can ask the agency to correct it.</p>
90
+
91
+ <p><strong>If my application is not successful, can I re-apply?</strong></p>
92
+ <p>Yes. We acknowledge that your circumstances change and just because we have refused a previous application, it does not mean that we'll automatically turn down a further request. We do suggest however, that you leave at least 6 months between applications.</p>
93
+
94
+ <p><strong>Who is eligible to apply for online finance?</strong></p>
95
+ <p>To apply for finance, you must be over the age of 18, work at least 16 hours a week, or be retired with an income. You must also be a resident of the United Kingdom and have lived in the UK for the last 12 months or more. Unfortunately, we are unable to offer online finance to residents of Eire. Homemakers aren't excluded from applying under their own names; however we will require the employment details of your spouse in order to process your application.</p>
96
+
97
+ <p><strong>Can I request delivery to an address other than my home?</strong></p>
98
+ <p>In order to safeguard against fraudulent applications, we regret that we're able only to deliver goods to the home address of the applicant. Saturday morning deliveries can be arranged if this is more convenient for you.</p>
app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/referred.html ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <div class="page-head">
2
+ <h3>Your credit application has been referred</h3>
3
+ </div>
4
+ <p>
5
+ Your order # is: {{var order_id}}.<br/>
6
+ Your application has been referred to our Underwriting Department and you will receive a response by e-mail with our decision as soon as possible.&nbsp;
7
+ If you have any questions, please contact customer services.
8
+ </p>
app/code/local/HC/PayByFinance/sql/paybyfinance_setup/mysql4-install-1.0.2.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ $installer = $this;
19
+ $setup = Mage::getModel('eav/entity_setup', 'core_setup');
20
+
21
+ $installer->startSetup();
22
+
23
+ //set up finance amount fields
24
+ $setup->run(
25
+ "
26
+ ALTER TABLE {$setup->getTable('sales_flat_quote_address')} ADD COLUMN finance_amount decimal(12,4);
27
+ ALTER TABLE {$setup->getTable('sales_flat_order')} ADD COLUMN finance_amount decimal(12,4);
28
+ ALTER TABLE {$setup->getTable('sales_flat_invoice')} ADD COLUMN finance_amount decimal(12,4);
29
+
30
+ ALTER TABLE {$setup->getTable('sales_flat_quote_address')}
31
+ ADD COLUMN base_finance_amount decimal(12,4);
32
+ ALTER TABLE {$setup->getTable('sales_flat_order')} ADD COLUMN base_finance_amount decimal(12,4);
33
+ ALTER TABLE {$setup->getTable('sales_flat_invoice')} ADD COLUMN base_finance_amount decimal(12,4);
34
+
35
+ ALTER TABLE {$setup->getTable('sales_flat_quote_address')} ADD COLUMN finance_deposit decimal(12,4);
36
+ ALTER TABLE {$setup->getTable('sales_flat_order')} ADD COLUMN finance_deposit decimal(12,4);
37
+ ALTER TABLE {$setup->getTable('sales_flat_invoice')} ADD COLUMN finance_deposit decimal(12,4);
38
+
39
+ ALTER TABLE {$setup->getTable('sales_flat_quote_address')} ADD COLUMN finance_service int(11);
40
+ ALTER TABLE {$setup->getTable('sales_flat_order')} ADD COLUMN finance_service int(11);
41
+ ALTER TABLE {$setup->getTable('sales_flat_invoice')} ADD COLUMN finance_service int(11);
42
+
43
+ ALTER TABLE {$setup->getTable('sales_flat_order')} ADD COLUMN finance_status varchar(1);
44
+ ALTER TABLE {$setup->getTable('sales_flat_order')} ADD COLUMN finance_application_no varchar(50);
45
+ "
46
+ );
47
+
48
+ $installer->run(
49
+ "
50
+ DROP TABLE IF EXISTS {$this->getTable('paybyfinance_service')};
51
+ CREATE TABLE {$this->getTable('paybyfinance_service')} (
52
+ `name` varchar(255) NOT NULL default '',
53
+ `service_id` int(11) unsigned NOT NULL auto_increment,
54
+ `type` smallint(6) NOT NULL default '0',
55
+ `apr` double(10,8) NOT NULL default '0',
56
+ `term` smallint(6) NOT NULL default '0',
57
+ `defer_term` smallint(6) NOT NULL default '0',
58
+ `option_term` smallint(6) NOT NULL default '0',
59
+ `deposit` float(7,4) NOT NULL default '0',
60
+ `fee` decimal(9,4) NOT NULL default '0',
61
+ `min_amount` decimal(9,4) NOT NULL default '0',
62
+ `multiplier` double(10,8) NOT NULL default '0',
63
+ `rpm` double(10,8) NOT NULL default '0',
64
+ PRIMARY KEY (`service_id`)
65
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
66
+ "
67
+ );
68
+
69
+ $installer->run(
70
+ "
71
+ DROP TABLE IF EXISTS {$this->getTable('paybyfinance_log')};
72
+ CREATE TABLE {$this->getTable('paybyfinance_log')} (
73
+ `api_id` int(11) unsigned NOT NULL auto_increment,
74
+ `type` varchar(255) NOT NULL default '',
75
+ `flow` varchar(255) NOT NULL default '',
76
+ `time` varchar(255) NOT NULL default '',
77
+ `content` text NOT NULL default '',
78
+ PRIMARY KEY (`api_id`)
79
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
80
+ "
81
+ );
82
+
83
+ // Add test service.
84
+ $service = Mage::getModel('paybyfinance/service');
85
+ $service->setName('Interest bearing')
86
+ ->setType(31)
87
+ ->setApr(0)
88
+ ->setTerm(6)
89
+ ->setDeferTerm(0)
90
+ ->setOptionTerm(0)
91
+ ->setDeposit(0)
92
+ ->setFee(0)
93
+ ->setMinAmount(350)
94
+ ->setMultiplier(0.16666667)
95
+ ->setRpm(0)
96
+ ->save();
97
+
98
+ $service = Mage::getModel('paybyfinance/service');
99
+ $service->setName('Interest bearing')
100
+ ->setType(31)
101
+ ->setApr(0)
102
+ ->setTerm(12)
103
+ ->setDeferTerm(0)
104
+ ->setOptionTerm(0)
105
+ ->setDeposit(10)
106
+ ->setFee(0)
107
+ ->setMinAmount(1000)
108
+ ->setMultiplier(0.091680)
109
+ ->setRpm(0)
110
+ ->save();
111
+
112
+ $service = Mage::getModel('paybyfinance/service');
113
+ $service->setName('Interest free')
114
+ ->setType(32)
115
+ ->setApr(0)
116
+ ->setTerm(18)
117
+ ->setDeferTerm(0)
118
+ ->setOptionTerm(0)
119
+ ->setDeposit(10)
120
+ ->setFee(0)
121
+ ->setMinAmount(1000)
122
+ ->setMultiplier(0.091680)
123
+ ->setRpm(0)
124
+ ->save();
125
+
126
+ // Blocks.
127
+ $blocks = array(
128
+ 'information' => 'Finance Information',
129
+ 'accepted' => 'Finance Accepted',
130
+ 'referred' => 'Finance Referred',
131
+ 'declined' => 'Finance Declined',
132
+ 'abandoned' => 'Finance Abandoned',
133
+ 'error' => 'Finance Error',
134
+ );
135
+
136
+ foreach ($blocks as $key => $title) {
137
+ $content = file_get_contents(
138
+ 'app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/'.
139
+ $key.'.html'
140
+ );
141
+ $block = Mage::getModel('cms/block');
142
+ $block->setTitle($title);
143
+ $block->setIdentifier('paybyfinance-' . $key);
144
+ $block->setStores(array(0));
145
+ $block->setIsActive(1);
146
+ $block->setContent($content);
147
+ $block->save();
148
+
149
+ // Set default config values.
150
+ $installer->setConfigData(
151
+ 'hc_paybyfinance/blocks_info/'.$key,
152
+ $block->getId()
153
+ );
154
+ }
155
+
156
+ // Order statuses.
157
+ $statuses = array(
158
+ 'finance_accepted' => 'Finance Accepted',
159
+ 'finance_referred' => 'Finance Referred',
160
+ 'finance_declined' => 'Finance Declined',
161
+ 'finance_abandoned' => 'Finance Abandoned',
162
+ 'finance_error' => 'Finance Error',
163
+ );
164
+
165
+ foreach ($statuses as $key => $value) {
166
+ $status = Mage::getModel('sales/order_status');
167
+ $status->setStatus($key)->setLabel($value)
168
+ ->assignState(Mage_Sales_Model_Order::STATE_PROCESSING)
169
+ ->save();
170
+ }
171
+
172
+ $setup->addAttribute(
173
+ 'catalog_product', 'paybyfinance_enable', array(
174
+ 'group' => 'Hitachi Capital - Pay By Finance',
175
+ 'type' => 'int',
176
+ 'backend' => '',
177
+ 'frontend' => '',
178
+ 'label' => 'Enable Finance',
179
+ 'input' => 'select',
180
+ 'class' => '',
181
+ 'source' => 'paybyfinance/config_source_catalog_product_finance',
182
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
183
+ 'visible' => true,
184
+ 'required' => false,
185
+ 'user_defined' => false,
186
+ 'default' => '',
187
+ 'searchable' => false,
188
+ 'filterable' => true,
189
+ 'comparable' => true,
190
+ 'visible_on_front' => false,
191
+ 'visible_in_advanced_search' => false,
192
+ 'used_in_product_listing' => false,
193
+ 'used_for_sort_by' => false,
194
+ 'unique' => false,
195
+ 'apply_to' => '',
196
+ )
197
+ );
198
+
199
+ $content = file_get_contents(
200
+ 'app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/page-finance-options.html'
201
+ );
202
+ $cmsPage = Array (
203
+ 'title' => 'Finance Options',
204
+ 'root_template' => 'one_column',
205
+ 'identifier' => 'finance-options',
206
+ 'content' => $content,
207
+ 'is_active' => 1,
208
+ 'stores' => array(0),
209
+ 'sort_order' => 0
210
+ );
211
+
212
+ Mage::getModel('cms/page')->setData($cmsPage)->save();
213
+
214
+ $installer->endSetup();
app/code/local/HC/PayByFinance/sql/paybyfinance_setup/mysql4-upgrade-1.0.0-1.0.1.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ $updater = $this; // $this is class Mage_Eav_Model_Entity_Setup
19
+ $updater->startSetup();
20
+
21
+ $content = file_get_contents(
22
+ 'app/code/local/HC/PayByFinance/sql/paybyfinance_setup/html/page-finance-options.html'
23
+ );
24
+ $cmsPage = Array (
25
+ 'title' => 'Finance Options',
26
+ 'root_template' => 'one_column',
27
+ 'identifier' => 'finance-options',
28
+ 'content' => $content,
29
+ 'is_active' => 1,
30
+ 'stores' => array(0),
31
+ 'sort_order' => 0
32
+ );
33
+
34
+
35
+ Mage::getModel('cms/page')->setData($cmsPage)->save();
36
+
37
+ $updater->endSetup();
app/code/local/HC/PayByFinance/sql/paybyfinance_setup/mysql4-upgrade-1.0.1-1.0.2.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ $updater = $this; // $this is class Mage_Eav_Model_Entity_Setup
19
+ $updater->startSetup();
20
+
21
+ $updater->run(
22
+ "
23
+ ALTER TABLE {$this->getTable('paybyfinance_service')}
24
+ MODIFY COLUMN `fee` decimal(9,4);
25
+
26
+ ALTER TABLE {$this->getTable('paybyfinance_service')}
27
+ MODIFY COLUMN `min_amount` decimal(9,4);
28
+ "
29
+ );
30
+
31
+ $updater->endSetup();
app/design/adminhtml/default/default/layout/paybyfinance.xml ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+
3
+ <layout>
4
+ <adminhtml_paybyfinance_service_index>
5
+ <reference name="content">
6
+ <block type="paybyfinance/adminhtml_paybyfinance_service" name="pbf_service"></block>
7
+ </reference>
8
+ </adminhtml_paybyfinance_service_index>
9
+
10
+ <adminhtml_sales_order_view>
11
+ <reference name="left">
12
+ <reference name="sales_order_tabs">
13
+ <reference name="order_tab_info">
14
+ <reference name="order_totals">
15
+ <!-- <reference name="sales.order.view.totals.main"> -->
16
+ <block type="adminhtml/sales_order_totals_item" name="hcfinanced" template="sales/order/totals/item.phtml" before="adjustment_positive">
17
+ <action method="setSourceField"><value>finance_amount</value></action>
18
+ <action method="setLabel"><value>Financed Amount</value></action>
19
+ </block>
20
+ <!-- </reference> -->
21
+ </reference>
22
+ </reference>
23
+ </reference>
24
+ </reference>
25
+ </adminhtml_sales_order_view>
26
+
27
+ <adminhtml_sales_order_invoice_new>
28
+ <reference name="content">
29
+ <reference name="sales_invoice_create">
30
+ <reference name="form">
31
+ <reference name="order_items">
32
+ <reference name="invoice_totals">
33
+ <!-- <reference name="sales.order.view.totals.main"> -->
34
+ <block type="adminhtml/sales_order_totals_item" name="hcfinanced" template="sales/order/totals/item.phtml" before="adjustment_positive">
35
+ <action method="setSourceField"><value>finance_amount</value></action>
36
+ <action method="setLabel"><value>Financed Amount</value></action>
37
+ </block>
38
+ <!-- </reference> -->
39
+ </reference>
40
+ </reference>
41
+ </reference>
42
+ </reference>
43
+ </reference>
44
+ </adminhtml_sales_order_invoice_new>
45
+
46
+ <adminhtml_sales_order_invoice_updateqty>
47
+ <reference name="order_items">
48
+ <reference name="invoice_totals">
49
+ <!-- <reference name="sales.order.view.totals.main"> -->
50
+ <block type="adminhtml/sales_order_totals_item" name="hcfinanced" template="sales/order/totals/item.phtml" before="adjustment_positive">
51
+ <action method="setSourceField"><value>finance_amount</value></action>
52
+ <action method="setLabel"><value>Financed Amount</value></action>
53
+ </block>
54
+ <!-- </reference> -->
55
+ </reference>
56
+ </reference>
57
+ </adminhtml_sales_order_invoice_updateqty>
58
+
59
+ <adminhtml_sales_order_invoice_view>
60
+ <reference name="content">
61
+ <reference name="sales_invoice_view">
62
+ <reference name="form">
63
+ <reference name="invoice_totals">
64
+ <!-- <reference name="sales.order.view.totals.main"> -->
65
+ <block type="adminhtml/sales_order_totals_item" name="hcfinanced" template="sales/order/totals/item.phtml" before="adjustment_positive">
66
+ <action method="setSourceField"><value>finance_amount</value></action>
67
+ <action method="setLabel"><value>Financed Amount</value></action>
68
+ </block>
69
+ <!-- </reference> -->
70
+ </reference>
71
+ </reference>
72
+ </reference>
73
+ </reference>
74
+ </adminhtml_sales_order_invoice_view>
75
+
76
+ <adminhtml_sales_order_creditmemo_new>
77
+ <reference name="content">
78
+ <reference name="sales_creditmemo_create">
79
+ <reference name="form">
80
+ <reference name="order_items">
81
+ <reference name="creditmemo_totals">
82
+ <!-- <reference name="sales.order.view.totals.main"> -->
83
+ <block type="adminhtml/sales_order_totals_item" name="hcfinanced" template="sales/order/totals/item.phtml" before="adjustment_positive">
84
+ <action method="setSourceField"><value>finance_amount</value></action>
85
+ <action method="setLabel"><value>Financed Amount</value></action>
86
+ </block>
87
+ <!-- </reference> -->
88
+ </reference>
89
+ </reference>
90
+ </reference>
91
+ </reference>
92
+ </reference>
93
+ </adminhtml_sales_order_creditmemo_new>
94
+
95
+ <adminhtml_sales_order_creditmemo_updateqty>
96
+ <reference name="order_items">
97
+ <reference name="creditmemo_totals">
98
+ <!-- <reference name="sales.order.view.totals.main"> -->
99
+ <block type="adminhtml/sales_order_totals_item" name="hcfinanced" template="sales/order/totals/item.phtml" before="adjustment_positive">
100
+ <action method="setSourceField"><value>finance_amount</value></action>
101
+ <action method="setLabel"><value>Financed Amount</value></action>
102
+ </block>
103
+ <!-- </reference> -->
104
+ </reference>
105
+ </reference>
106
+ </adminhtml_sales_order_creditmemo_updateqty>
107
+
108
+ <adminhtml_sales_order_creditmemo_view>
109
+ <reference name="content">
110
+ <reference name="sales_creditmemo_view">
111
+ <reference name="form">
112
+ <reference name="creditmemo_totals">
113
+ <!-- <reference name="sales.order.view.totals.main"> -->
114
+ <block type="adminhtml/sales_order_totals_item" name="hcfinanced" template="sales/order/totals/item.phtml" before="adjustment_positive">
115
+ <action method="setSourceField"><value>finance_amount</value></action>
116
+ <action method="setLabel"><value>Financed Amount</value></action>
117
+ </block>
118
+ <!-- </reference> -->
119
+ </reference>
120
+ </reference>
121
+ </reference>
122
+ </reference>
123
+ </adminhtml_sales_order_creditmemo_view>
124
+ </layout>
app/design/frontend/base/default/layout/paybyfinance.xml ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+
4
+ <default>
5
+ <reference name="head">
6
+ <action method="addCss"><link>css/paybyfinance.css</link></action>
7
+ <action method="addItem">
8
+ <type>skin_css</type>
9
+ <name>css/paybyfinance-ie8.css</name>
10
+ <params/>
11
+ <if>lt IE 9</if>
12
+ </action>
13
+ <action method="addItem"><type>skin_js</type><name>js/paybyfinance/functions.js</name></action>
14
+ <action method="addItem"><type>skin_js</type><name>js/paybyfinance/slider.js</name></action>
15
+ </reference>
16
+ </default>
17
+
18
+ <catalog_product_view>
19
+ <reference name="product.info">
20
+ <block type="paybyfinance/selector" name="paybyfinance.selector" as="pbfselector" template="paybyfinance/selector.phtml">
21
+ <action method="addToParentGroup"><group>detailed_info</group></action>
22
+ <action method="setTitle" translate="value"><value>Pay by Finance</value></action>
23
+ </block>
24
+ </reference>
25
+ </catalog_product_view>
26
+
27
+ <checkout_cart_index>
28
+ <reference name="checkout.cart">
29
+ <block type="paybyfinance/selector" name="paybyfinance.selector.cart" as="cartpbfselector" template="paybyfinance/selector.phtml" />
30
+ </reference>
31
+ <reference name="checkout.cart.extra">
32
+ <block type="paybyfinance/selector" name="paybyfinance.selector" as="pbfselector" template="paybyfinance/selector.phtml" />
33
+ </reference>
34
+ </checkout_cart_index>
35
+
36
+ <checkout_onepage_index>
37
+ <reference name="head">
38
+ <action method="addItem"><type>skin_js</type><name>js/paybyfinance/checkout.js</name></action>
39
+ </reference>
40
+ <reference name="right">
41
+ <block type="paybyfinance/selector" name="paybyfinance.selector.cart" as="cartpbfselector" template="paybyfinance/selector.phtml" />
42
+ </reference>
43
+ </checkout_onepage_index>
44
+
45
+ <onestepcheckout_index_index>
46
+ <reference name="head">
47
+ <action method="addItem"><type>skin_js</type><name>js/paybyfinance/checkout.js</name></action>
48
+ </reference>
49
+ </onestepcheckout_index_index>
50
+
51
+ <hc_paybyfinance_status>
52
+ <remove name="right"/>
53
+ <remove name="left"/>
54
+ <reference name="root">
55
+ <action method="setTemplate"><template>page/1column.phtml</template></action>
56
+ </reference>
57
+ </hc_paybyfinance_status>
58
+
59
+ <hc_paybyfinance_status_accepted>
60
+ <update handle="hc_paybyfinance_status"/>
61
+ <reference name="content">
62
+ <block type="paybyfinance/status" name="paybyfinance.status" as ="pbfstatus" template="paybyfinance/status.phtml">
63
+ <action method="setType"><type>accepted</type></action>
64
+ </block>
65
+ </reference>
66
+ </hc_paybyfinance_status_accepted>
67
+
68
+ <hc_paybyfinance_status_referred>
69
+ <update handle="hc_paybyfinance_status"/>
70
+ <reference name="content">
71
+ <block type="paybyfinance/status" name="paybyfinance.status" as ="pbfstatus" template="paybyfinance/status.phtml">
72
+ <action method="setType"><type>referred</type></action>
73
+ </block>
74
+ </reference>
75
+ </hc_paybyfinance_status_referred>
76
+
77
+ <hc_paybyfinance_status_declined>
78
+ <update handle="hc_paybyfinance_status"/>
79
+ <reference name="content">
80
+ <block type="paybyfinance/status" name="paybyfinance.status" as ="pbfstatus" template="paybyfinance/status.phtml">
81
+ <action method="setType"><type>declined</type></action>
82
+ </block>
83
+ </reference>
84
+ </hc_paybyfinance_status_declined>
85
+
86
+ <hc_paybyfinance_status_abandoned>
87
+ <update handle="hc_paybyfinance_status"/>
88
+ <reference name="content">
89
+ <block type="paybyfinance/status" name="paybyfinance.status" as ="pbfstatus" template="paybyfinance/status.phtml">
90
+ <action method="setType"><type>abandoned</type></action>
91
+ </block>
92
+ </reference>
93
+ </hc_paybyfinance_status_abandoned>
94
+
95
+ <hc_paybyfinance_status_error>
96
+ <update handle="hc_paybyfinance_status"/>
97
+ <reference name="content">
98
+ <block type="paybyfinance/status" name="paybyfinance.status" as ="pbfstatus" template="paybyfinance/status.phtml">
99
+ <action method="setType"><type>error</type></action>
100
+ </block>
101
+ </reference>
102
+ </hc_paybyfinance_status_error>
103
+
104
+ <sales_order_view>
105
+ <reference name="my.account.wrapper">
106
+ <reference name="sales.order.view">
107
+ <reference name="order_items">
108
+ <reference name="order_totals">
109
+ <block type="paybyfinance/sales_order_totals" name="paybyfinance" template="paybyfinance/sales/order/totals.phtml" />
110
+ </reference>
111
+ </reference>
112
+ </reference>
113
+ </reference>
114
+ </sales_order_view>
115
+
116
+ <sales_order_invoice translate="label">
117
+ <reference name="my.account.wrapper">
118
+ <reference name="sales.order.invoice">
119
+ <reference name="invoice_items">
120
+ <reference name="invoice_totals">
121
+ <block type="paybyfinance/sales_order_totals" name="paybyfinance" template="paybyfinance/sales/order/totals.phtml" />
122
+ </reference>
123
+ </reference>
124
+ </reference>
125
+ </reference>
126
+ </sales_order_invoice>
127
+
128
+ <sales_order_creditmemo>
129
+ <reference name="my.account.wrapper">
130
+ <reference name="sales.order.creditmemo">
131
+ <reference name="creditmemo_items">
132
+ <reference name="creditmemo_totals">
133
+ <block type="paybyfinance/sales_order_totals" name="paybyfinance" template="paybyfinance/sales/order/totals.phtml" />
134
+ </reference>
135
+ </reference>
136
+ </reference>
137
+ </reference>
138
+ </sales_order_creditmemo>
139
+
140
+ <sales_order_print>
141
+ <reference name="content">
142
+ <reference name="sales.order.print">
143
+ <reference name="order_totals">
144
+ <block type="paybyfinance/sales_order_totals" name="paybyfinance" template="paybyfinance/sales/order/totals.phtml" />
145
+ </reference>
146
+ </reference>
147
+ </reference>
148
+ </sales_order_print>
149
+
150
+ <sales_order_printinvoice translate="label">
151
+ <reference name="content">
152
+ <reference name="sales.order.print.invoice">
153
+ <reference name="invoice_totals">
154
+ <block type="paybyfinance/sales_order_totals" name="paybyfinance" template="paybyfinance/sales/order/totals.phtml" />
155
+ </reference>
156
+ </reference>
157
+ </reference>
158
+ </sales_order_printinvoice>
159
+
160
+ <sales_order_printcreditmemo>
161
+ <reference name="content">
162
+ <reference name="sales.order.print.creditmemo">
163
+ <reference name="creditmemo_totals">
164
+ <block type="paybyfinance/sales_order_totals" name="paybyfinance" template="paybyfinance/sales/order/totals.phtml" />
165
+ </reference>
166
+ </reference>
167
+ </reference>
168
+ </sales_order_printcreditmemo>
169
+
170
+ <sales_email_order_items>
171
+ <reference name="items">
172
+ <reference name="order_totals">
173
+ <block type="paybyfinance/sales_order_totals" name="paybyfinance" template="paybyfinance/sales/order/totals.phtml" />
174
+ </reference>
175
+ </reference>
176
+ </sales_email_order_items>
177
+
178
+ <sales_email_order_invoice_items>
179
+ <reference name="items">
180
+ <reference name="invoice_totals">
181
+ <block type="paybyfinance/sales_order_totals" name="paybyfinance" template="paybyfinance/sales/order/totals.phtml" />
182
+ </reference>
183
+ </reference>
184
+ </sales_email_order_invoice_items>
185
+
186
+ <sales_email_order_creditmemo_items>
187
+ <reference name="items">
188
+ <reference name="creditmemo_totals">
189
+ <block type="paybyfinance/sales_order_totals" name="paybyfinance" template="paybyfinance/sales/order/totals.phtml" />
190
+ </reference>
191
+ </reference>
192
+ </sales_email_order_creditmemo_items>
193
+
194
+ </layout>
app/design/frontend/base/default/template/checkout/cart.phtml ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) 2014 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
+ /**
29
+ * Shopping cart template
30
+ *
31
+ * @see Mage_Checkout_Block_Cart
32
+ */
33
+ ?>
34
+ <div class="cart">
35
+ <div class="page-title title-buttons">
36
+ <h1><?php echo $this->__('Shopping Cart') ?></h1>
37
+ <?php if(!$this->hasError()): ?>
38
+ <ul class="checkout-types">
39
+ <?php foreach ($this->getMethods('top_methods') as $method): ?>
40
+ <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
41
+ <li><?php echo $methodHtml; ?></li>
42
+ <?php endif; ?>
43
+ <?php endforeach; ?>
44
+ </ul>
45
+ <?php endif; ?>
46
+ </div>
47
+ <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
48
+ <?php echo $this->getChildHtml('form_before') ?>
49
+ <form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
50
+ <?php echo $this->getBlockHtml('formkey'); ?>
51
+ <fieldset>
52
+ <table id="shopping-cart-table" class="data-table cart-table">
53
+ <col width="1" />
54
+ <col />
55
+ <col width="1" />
56
+ <?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
57
+ <col width="1" />
58
+ <?php endif ?>
59
+ <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
60
+ <col width="1" />
61
+ <?php endif; ?>
62
+ <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
63
+ <col width="1" />
64
+ <?php endif; ?>
65
+ <col width="1" />
66
+ <?php if ($this->helper('tax')->displayCartPriceExclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
67
+ <col width="1" />
68
+ <?php endif; ?>
69
+ <?php if ($this->helper('tax')->displayCartPriceInclTax() || $this->helper('tax')->displayCartBothPrices()): ?>
70
+ <col width="1" />
71
+ <?php endif; ?>
72
+ <col width="1" />
73
+
74
+ <?php $mergedCells = ($this->helper('tax')->displayCartBothPrices() ? 2 : 1); ?>
75
+ <thead>
76
+ <tr>
77
+ <th rowspan="<?php echo $mergedCells; ?>">&nbsp;</th>
78
+ <th rowspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Product Name') ?></span></th>
79
+ <th rowspan="<?php echo $mergedCells; ?>"></th>
80
+ <?php if ($this->helper('wishlist')->isAllowInCart()) : ?>
81
+ <th rowspan="<?php echo $mergedCells; ?>" class="a-center"><span class="nobr"><?php echo $this->__('Move to Wishlist') ?></span></th>
82
+ <?php endif ?>
83
+ <th class="a-center" colspan="<?php echo $mergedCells; ?>"><span class="nobr"><?php echo $this->__('Unit Price') ?></span></th>
84
+ <th rowspan="<?php echo $mergedCells; ?>" class="a-center"><?php echo $this->__('Qty') ?></th>
85
+ <th class="a-center" colspan="<?php echo $mergedCells; ?>"><?php echo $this->__('Subtotal') ?></th>
86
+ <th rowspan="<?php echo $mergedCells; ?>" class="a-center">&nbsp;</th>
87
+ </tr>
88
+ <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
89
+ <tr>
90
+ <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
91
+ <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
92
+ <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
93
+ <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
94
+ </tr>
95
+ <?php endif; ?>
96
+ </thead>
97
+ <tfoot>
98
+ <tr>
99
+ <td colspan="50" class="a-right">
100
+ <?php if($this->getContinueShoppingUrl()): ?>
101
+ <button type="button" title="<?php echo $this->__('Continue Shopping') ?>" class="button btn-continue" onclick="setLocation('<?php echo $this->getContinueShoppingUrl() ?>')"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></button>
102
+ <?php endif; ?>
103
+ <button type="submit" name="update_cart_action" value="update_qty" title="<?php echo $this->__('Update Shopping Cart'); ?>" class="button btn-update"><span><span><?php echo $this->__('Update Shopping Cart'); ?></span></span></button>
104
+ <button type="submit" name="update_cart_action" value="empty_cart" title="<?php echo $this->__('Clear Shopping Cart'); ?>" class="button btn-empty" id="empty_cart_button"><span><span><?php echo $this->__('Clear Shopping Cart'); ?></span></span></button>
105
+ <!--[if lt IE 8]>
106
+ <input type="hidden" id="update_cart_action_container" />
107
+ <script type="text/javascript">
108
+ //<![CDATA[
109
+ Event.observe(window, 'load', function()
110
+ {
111
+ // Internet Explorer (lt 8) does not support value attribute in button elements
112
+ $emptyCartButton = $('empty_cart_button');
113
+ $cartActionContainer = $('update_cart_action_container');
114
+ if ($emptyCartButton && $cartActionContainer) {
115
+ Event.observe($emptyCartButton, 'click', function()
116
+ {
117
+ $emptyCartButton.setAttribute('name', 'update_cart_action_temp');
118
+ $cartActionContainer.setAttribute('name', 'update_cart_action');
119
+ $cartActionContainer.setValue('empty_cart');
120
+ });
121
+ }
122
+
123
+ });
124
+ //]]>
125
+ </script>
126
+ <![endif]-->
127
+ </td>
128
+ </tr>
129
+ </tfoot>
130
+ <tbody>
131
+ <?php foreach($this->getItems() as $_item): ?>
132
+ <?php echo $this->getItemHtml($_item) ?>
133
+ <?php endforeach ?>
134
+ </tbody>
135
+ </table>
136
+ <script type="text/javascript">decorateTable('shopping-cart-table')</script>
137
+ </fieldset>
138
+ </form>
139
+ <div class="cart-collaterals">
140
+ <div class="col2-set">
141
+ <div class="col-1">
142
+ <?php echo $this->getChildHtml('cartpbfselector') ?>
143
+ <?php echo $this->getChildHtml('crosssell') ?>
144
+ </div>
145
+ <div class="col-2">
146
+ <?php /* Extensions placeholder */ ?>
147
+ <?php echo $this->getChildHtml('checkout.cart.extra') ?>
148
+ <?php echo $this->getChildHtml('coupon') ?>
149
+ <?php if (!$this->getIsVirtual()): echo $this->getChildHtml('shipping'); endif; ?>
150
+ </div>
151
+ </div>
152
+ <div class="totals">
153
+ <?php echo $this->getChildHtml('totals'); ?>
154
+ <?php if(!$this->hasError()): ?>
155
+ <ul class="checkout-types">
156
+ <?php foreach ($this->getMethods('methods') as $method): ?>
157
+ <?php if ($methodHtml = $this->getMethodHtml($method)): ?>
158
+ <li><?php echo $methodHtml; ?></li>
159
+ <?php endif; ?>
160
+ <?php endforeach; ?>
161
+ </ul>
162
+ <?php endif; ?>
163
+ </div>
164
+ </div>
165
+ </div>
app/design/frontend/base/default/template/checkout/cart/totals.phtml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento Enterprise Edition
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Magento Enterprise Edition License
8
+ * that is bundled with this package in the file LICENSE_EE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magentocommerce.com/license/enterprise-edition
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) 2014 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://www.magentocommerce.com/license/enterprise-edition
25
+ */
26
+ ?>
27
+ <?php
28
+ /**
29
+ * Shopping cart totals template
30
+ *
31
+ * @see Mage_Checkout_Block_Cart_Totals
32
+ * @var $this Mage_Checkout_Block_Cart_Totals
33
+ */
34
+ ?>
35
+ <?php if ($this->canApplyMsrp()): ?>
36
+ <div class="cart-msrp-totals"><?php echo $this->__('ORDER TOTAL WILL BE DISPLAYED BEFORE YOU SUBMIT THE ORDER'); ?></div>
37
+ <?php else: ?>
38
+ <table id="shopping-cart-totals-table">
39
+ <col />
40
+ <col width="1" />
41
+ <tfoot>
42
+ <?php echo str_replace('Grand Total', '* Grand Total', $this->renderTotals('footer')); ?>
43
+ </tfoot>
44
+ <tbody>
45
+ <?php echo $this->renderTotals(); ?>
46
+ </tbody>
47
+ </table>
48
+ * Grand total is the amount to be paid by credit/debit card
49
+ <?php endif; ?>
app/design/frontend/base/default/template/checkout/onepage/review/info.phtml ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento Enterprise Edition
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Magento Enterprise Edition License
8
+ * that is bundled with this package in the file LICENSE_EE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magentocommerce.com/license/enterprise-edition
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) 2014 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://www.magentocommerce.com/license/enterprise-edition
25
+ */
26
+ ?>
27
+ <?php echo $this->getChildHtml('items_before'); ?>
28
+ <div id="checkout-review-table-wrapper">
29
+ <table class="data-table" id="checkout-review-table">
30
+ <?php if ($this->helper('tax')->displayCartBothPrices()): $colspan = $rowspan = 2; else: $colspan = $rowspan = 1; endif; ?>
31
+ <col />
32
+ <col width="1" />
33
+ <col width="1" />
34
+ <col width="1" />
35
+ <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
36
+ <col width="1" />
37
+ <col width="1" />
38
+ <?php endif; ?>
39
+ <thead>
40
+ <tr>
41
+ <th rowspan="<?php echo $rowspan ?>"><?php echo $this->__('Product Name') ?></th>
42
+ <th colspan="<?php echo $colspan ?>" class="a-center"><?php echo $this->__('Price') ?></th>
43
+ <th rowspan="<?php echo $rowspan ?>" class="a-center"><?php echo $this->__('Qty') ?></th>
44
+ <th colspan="<?php echo $colspan ?>" class="a-center"><?php echo $this->__('Subtotal') ?></th>
45
+ </tr>
46
+ <?php if ($this->helper('tax')->displayCartBothPrices()): ?>
47
+ <tr>
48
+ <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
49
+ <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
50
+ <th class="a-right"><?php echo $this->helper('tax')->getIncExcTaxLabel(false) ?></th>
51
+ <th><?php echo $this->helper('tax')->getIncExcTaxLabel(true) ?></th>
52
+ </tr>
53
+ <?php endif; ?>
54
+ </thead>
55
+ <?php echo $this->getChildHtml('totals'); ?>
56
+ <tbody>
57
+ <?php foreach($this->getItems() as $_item): ?>
58
+ <?php echo $this->getItemHtml($_item)?>
59
+ <?php endforeach ?>
60
+ </tbody>
61
+ </table>
62
+ * Grand total is the amount to be paid by credit/debit card
63
+ </div>
64
+ <?php echo $this->getChildHtml('items_after'); ?>
65
+ <script type="text/javascript">
66
+ //<![CDATA[
67
+ decorateTable('checkout-review-table');
68
+ truncateOptions();
69
+ //]]>
70
+ </script>
71
+ <div id="checkout-review-submit">
72
+ <?php echo $this->getChildHtml('agreements') ?>
73
+ <div class="buttons-set" id="review-buttons-container">
74
+ <p class="f-left"><?php echo $this->__('Forgot an Item?') ?> <a href="<?php echo $this->getUrl('checkout/cart') ?>"><?php echo $this->__('Edit Your Cart') ?></a></p>
75
+ <?php echo $this->getChildHtml('button') ?>
76
+ <span class="please-wait" id="review-please-wait" style="display:none;">
77
+ <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Submitting order information...') ?>" title="<?php echo $this->__('Submitting order information...') ?>" class="v-middle" /> <?php echo $this->__('Submitting order information...') ?>
78
+ </span>
79
+ </div>
80
+ <script type="text/javascript">
81
+ //<![CDATA[
82
+ review = new Review('<?php echo $this->getUrl('checkout/onepage/saveOrder', array('form_key' => Mage::getSingleton('core/session')->getFormKey())) ?>', '<?php echo $this->getUrl('checkout/onepage/success') ?>', $('checkout-agreements'));
83
+ //]]>
84
+ </script>
85
+ </div>
app/design/frontend/base/default/template/checkout/onepage/review/totals.phtml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento Enterprise Edition
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Magento Enterprise Edition License
8
+ * that is bundled with this package in the file LICENSE_EE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magentocommerce.com/license/enterprise-edition
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) 2014 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://www.magentocommerce.com/license/enterprise-edition
25
+ */
26
+
27
+ /**
28
+ * @see Mage_Checkout_Block_Cart_Totals
29
+ */
30
+ ?>
31
+ <?php if ($this->getTotals()): ?>
32
+ <tfoot>
33
+ <?php $_colspan = $this->helper('tax')->displayCartBothPrices() ? 5 : 3; ?>
34
+ <?php echo $this->renderTotals(null, $_colspan); ?>
35
+ <?php echo str_replace('Grand Total', '* Grand Total', $this->renderTotals('footer', $_colspan)); ?>
36
+ <?php if ($this->needDisplayBaseGrandtotal()):?>
37
+ <tr>
38
+ <td class="a-right" colspan="<?php echo $_colspan; ?>">
39
+ <small><?php echo $this->helper('sales')->__('Your credit card will be charged for') ?></small>
40
+ </td>
41
+ <td class="a-right">
42
+ <small><?php echo $this->displayBaseGrandtotal() ?></small>
43
+ </td>
44
+ </tr>
45
+ <?php endif?>
46
+ </tfoot>
47
+ <?php endif; ?>
app/design/frontend/base/default/template/paybyfinance/form.phtml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ $_mode = $this->getMode();
19
+ ?>
20
+
21
+ <html>
22
+ <head>
23
+ <title>Redirecting...</title>
24
+ </head>
25
+ <body>
26
+ <form action="<?php echo $this->getPostUrl(); ?>" method="post" name="redirect">
27
+ <?php foreach ($this->getPostContent() as $key => $value) { ?>
28
+ <?php if ($_mode == 'simulation'): ?>
29
+ <br/> <label for="<?php echo htmlentities($key) ?>"><?php echo htmlentities($key) ?></label>
30
+ <?php endif; ?>
31
+ <input <?php echo $_mode=='simulation' ? '':'type="hidden"' ?> name="<?php echo htmlentities($key) ?>" value="<?php echo htmlentities($value) ?>" />
32
+ <?php } ?>
33
+ <input type="submit" value="Redirect" <?php if ($_mode != 'simulation'): ?>style="display: none;"<?php endif; ?>/>
34
+ </form>
35
+ <?php if ($_mode != 'simulation'): ?>
36
+ If your browser does not automatically redirect to Pay By Finance <a href="script:document.redirect.submit();">click here</a>
37
+ <script>document.redirect.submit();</script>
38
+ <?php endif; ?>
39
+ </body>
40
+ </html>
41
+
app/design/frontend/base/default/template/paybyfinance/sales/order/totals.phtml ADDED
File without changes
app/design/frontend/base/default/template/paybyfinance/selector-no.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <div class="paybyfinance-selector"><div id="paybyfinance">
2
+ <!--
3
+ <p class="error">There's no product eligible for finance in your cart.</p>
4
+ -->
5
+ </div></div>
app/design/frontend/base/default/template/paybyfinance/selector.phtml ADDED
@@ -0,0 +1,489 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Hitachi Capital Pay By Finance
4
+ *
5
+ * Hitachi Capital Pay By Finance Extension
6
+ *
7
+ * PHP version >= 5.3.*
8
+ *
9
+ * @category HC
10
+ * @package PayByFinance
11
+ * @author Healthy Websites <support@healthywebsites.co.uk>
12
+ * @copyright 2014 Hitachi Capital
13
+ * @license http://www.healthywebsites.co.uk/license.html HWS License
14
+ * @link http://www.healthywebsites.co.uk/
15
+ *
16
+ */
17
+
18
+ $_services = $this->getServices();
19
+ $_product = $this->getProduct(); // returns with null if we are not on the product page
20
+ $_data = json_decode($this->getJSON());
21
+ ?>
22
+
23
+ <div class="paybyfinance-selector"><div id="paybyfinance">
24
+
25
+ <?php if ($_product && !Mage::helper('paybyfinance')->isProductEligible($_product)): ?>
26
+ <p class="error">Product is not eligible for finance.</p>
27
+ <?php endif; ?>
28
+
29
+ <h3>Would you like to pay by Finance?</h3>
30
+ <?php if (!$_product): ?>
31
+ <input id="paybyfinance-no" type="radio" name="pbf-checkbox" value="" onclick="$('paybyfinance-container').hide(); $('pbf-cart-btn').show(); pbf_redraw();" checked>
32
+ <label for="paybyfinance-no">No</label><br>
33
+ <input id="paybyfinance-yes" type="radio" name="pbf-checkbox" value="paybyfinance" onclick="$('paybyfinance-container').show(); $('pbf-cart-btn').show(); pbf_redraw();">
34
+ <label for="paybyfinance-yes">Yes</label><br>
35
+ <?php endif; ?>
36
+ <div id="paybyfinance-container" <?php if (!$_product) echo 'style="display: none;"'; ?>>
37
+ <p>Finance Calculation for your <span class="calculated" id="pbf-ordervalue">-</span> order</p>
38
+ <p>I would like to pay a deposit of <span class="calculated" id="pbf-deposit">-</span></p>
39
+
40
+ <input id="pbf-input-deposit" name="pbf-input-deposit" class="pbf-input-hidden" type="range" min="0" max="6" value ="1"/>
41
+
42
+ <?php if (!$this->getIsFixedDepositOnly()): ?>
43
+ <div id="pbf-deposit-slider" class="healthy-slider clearfix"> <div class="slider-marker"></div> <div class="slider-pointer"></div> </div>
44
+
45
+ <ul id="pbf-deposit-ruler" class="healthy-ruler">
46
+ <li onclick="javascript:pbf_deposit(0);" class="ruler ruler-0">0%</li>
47
+ <li onclick="javascript:pbf_deposit(10);" class="ruler ruler-1">10%</li>
48
+ <li onclick="javascript:pbf_deposit(20);" class="ruler ruler-2">20%</li>
49
+ <li onclick="javascript:pbf_deposit(30);" class="ruler ruler-3">30%</li>
50
+ <li onclick="javascript:pbf_deposit(40);" class="ruler ruler-4">40%</li>
51
+ <li onclick="javascript:pbf_deposit(50);" class="ruler ruler-5">50%</li>
52
+ <li onclick="javascript:pbf_deposit(60);" class="ruler ruler-6">60%</li>
53
+ </ul>
54
+ <?php endif; ?>
55
+ <ul id="pbf-error" class="messages">
56
+ <li class="error-msg">
57
+ <ul>
58
+ <li id="pbf-error-msg"></li>
59
+ </ul>
60
+ </li>
61
+ </ul>
62
+
63
+ <div id="pbf-input-type-wrapper">
64
+ </div>
65
+
66
+ <p>I would like to pay over <span id="pbf-term-months" class="calculated"></span> months</p>
67
+
68
+ <div id="pbf-input-term-wrapper">
69
+ </div>
70
+
71
+
72
+
73
+ <table class="services">
74
+ <?php foreach ($_services as $_service): ?>
75
+ <tr>
76
+ <td>
77
+ <?php echo $_service->getName(); ?> (<?php echo $_service->getApr() ?>% APR Representative for <strong><?php echo $_service->getTerm(); ?> months</strong>)
78
+ </td>
79
+ <td>
80
+ <input type="radio" name="service" onclick="javascript:pbf_selector_recalculate();" value="<?php echo $_service->getId(); ?>" <?php echo $checked?'':'checked'; ?> />
81
+ </td>
82
+ </tr>
83
+ <?php $checked = true; ?>
84
+ <?php endforeach; ?>
85
+ </table>
86
+
87
+ <div class="paybyfinance-sum">
88
+ <table>
89
+ <tr>
90
+ <td>
91
+ <span id="pbf-term">10</span> Monthly payments of
92
+ </td>
93
+ <td style="text-align: right;">
94
+ <span id="pbf-monthly-payment">-</span>
95
+ </td>
96
+ </tr>
97
+
98
+ <tr>
99
+ <td colspan="2">
100
+ <span id="pbf-apr">10</span>% APR (representative)
101
+ </td>
102
+ </tr>
103
+
104
+ <tr>
105
+ <td>
106
+ Total Credit
107
+ </td>
108
+ <td id="pbf-totalcredit" style="text-align: right;">
109
+ -
110
+ </td>
111
+ </tr>
112
+
113
+ <tr id="pbf-interestpayable-tr">
114
+ <td>
115
+ Interest Payable
116
+ </td>
117
+ <td id="pbf-interestpayable" style="text-align: right;">
118
+ -
119
+ </td>
120
+ </tr>
121
+
122
+ <tr>
123
+ <td>
124
+ Total Amount Payable
125
+ </td>
126
+ <td id="pbf-payable" style="text-align: right;">
127
+ -
128
+ </td>
129
+ </tr>
130
+
131
+ </table>
132
+ </div>
133
+ <div class="pbf-footnote">
134
+ <p>The figures shown are an illustration based on the cost of goods. Final details including shipping and discounts where applicable will be displayed on the checkout page.</p>
135
+ <p>Credit is provided by Hitachi Capital Consumer Finance, a division of Hitachi Capital (UK) PLC authorised and regulated by the Financial Conduct Authority.</p>
136
+ <p><?php echo $this->getRetailerName(); ?> <?php echo $this->getTradingName(); ?> acts as a credit broker and is authorised and regulated by the Financial Conduct Authority.</p>
137
+ <p><strong>IMPORTANT:</strong> Hitachi Capital rounds down the monthly payments, which may result in your total amount payable being less than the total cash price.</p>
138
+ </div>
139
+ </div>
140
+ <?php if ($_product): ?>
141
+ <button id="pbf-productcart-btn" type="button" title="Add to Cart" class="button btn-cart" onclick="javascript:pbf_submit()"><span><span>Pay By Finance</span></span></button>
142
+ <?php else: ?>
143
+ <button id="pbf-cart-btn" type="button" title="Update" class="button btn-cart" onclick="javascript:pbf_update()"><span><span>Update</span></span></button>
144
+ <script type="text/javascript">
145
+ // Automatically refresh the widget totals in any interaction
146
+ $(document).observe("billing-request:completed", function(event) {
147
+ pbf_ajax_update();
148
+ });
149
+ $(document).observe("payment-method:switched", function(event) {
150
+ pbf_ajax_update();
151
+ });
152
+
153
+ Ajax.Responders.register({
154
+ onComplete: function(ee) {
155
+ if (ee.url.match(/onestepcheckout\/ajax\/(set_methods_separate|save_billing|add_coupon|add_giftcard)/)) {
156
+ pbf_ajax_update();
157
+ }
158
+ }
159
+ });
160
+ </script>
161
+ <?php endif; ?>
162
+ </div>
163
+ </div>
164
+
165
+ <script type="text/javascript">
166
+ var pbf_selector_data = <?php echo $this->getJSON(); ?>;
167
+ var pbf_selector_user = new Object();
168
+ var touchstatus = 'up';
169
+
170
+ function pbf_selector_recalculate() {
171
+ var value = $("pbf-input-deposit").value * 10;
172
+ var service_id = $$('#paybyfinance input:checked[name=service]')[0].value;
173
+ var service = pbf_selector_data.services[service_id];
174
+ var deposit = ((value / 100) * pbf_selector_data.amount);
175
+ var credit = (pbf_selector_data.amount - deposit);
176
+ var monthly = Math.floor((credit * service.multiplier) * 100) / 100; // No rounding issues, rounding always down
177
+ if (service.type == '32') {
178
+ monthly = Math.floor((credit / service.term) * 100) / 100;
179
+ }
180
+ var payable = (monthly * service.term + deposit);
181
+ var interestpayable = payable - credit - deposit;
182
+ currencyFormat = Healthy.Functions.currencyFormat;
183
+
184
+ $('pbf-apr').update(parseFloat(service.apr));
185
+ $('pbf-ordervalue').update("£" + currencyFormat(pbf_selector_data.amount));
186
+ $('pbf-deposit').update(value + "% = £" + currencyFormat(deposit));
187
+ $('pbf-totalcredit').update("£" + currencyFormat(credit));
188
+ $('pbf-term').update(service.term);
189
+ $('pbf-term-months').update(service.term);
190
+ $('pbf-monthly-payment').update('£' + currencyFormat(monthly));
191
+ $('pbf-interestpayable').update('£' + currencyFormat(interestpayable));
192
+ if(service.type == 31) {
193
+ //only show if it is an interest bearing service type
194
+ $('pbf-interestpayable-tr').show();
195
+ } else {
196
+ $('pbf-interestpayable-tr').hide();
197
+ }
198
+
199
+ $('pbf-payable').update('£' + currencyFormat(payable));
200
+
201
+ if (value < service.deposit) {
202
+ $('pbf-error-msg').update("The minimum deposit value is "+parseInt(service.deposit)+"%");
203
+ $('pbf-error').setStyle({height: 45+"px", opacity: 0.99});
204
+ if ($('pbf-productcart-btn')) {
205
+ Form.Element.disable('pbf-productcart-btn');
206
+ }
207
+ if ($('pbf-cart-btn')) {
208
+ Form.Element.disable('pbf-cart-btn');
209
+ }
210
+ } else if(credit < service.min_amount) {
211
+ $('pbf-error-msg').update("The minimum Finance Amount is £"+ currencyFormat(service.min_amount));
212
+ $('pbf-error').setStyle({height: 45+"px", opacity: 0.99});
213
+ if ($('pbf-productcart-btn')) {
214
+ Form.Element.disable('pbf-productcart-btn');
215
+ }
216
+ if ($('pbf-cart-btn')) {
217
+ Form.Element.disable('pbf-cart-btn');
218
+ }
219
+ } else {
220
+ $('pbf-error-msg').update(null);
221
+ $('pbf-error').setStyle({height: 0, opacity: 0});
222
+ if ($('pbf-productcart-btn')) {
223
+ Form.Element.enable('pbf-productcart-btn');
224
+ }
225
+ if ($('pbf-cart-btn')) {
226
+ Form.Element.enable('pbf-cart-btn');
227
+ }
228
+ }
229
+ }
230
+
231
+ function pbf_term_recalculate() {
232
+ var typewid = $("pbf-input-type");
233
+ var typeval = 0;
234
+ if (typewid) {
235
+ typeval = typewid.value;
236
+ }
237
+ var termval = $("pbf-input-term-"+typeval).value;
238
+ var service_id = pbf_selector_data['subterms'][typeval][termval].service_id;
239
+ pbf_selector_user.service = service_id;
240
+ if ($$('input[name="service"][value="'+service_id+'"]').length != 0) {
241
+ $$('input[name="service"][value="'+service_id+'"]')[0].checked = true;
242
+ }
243
+ <?php if ($this->getIsFixedDepositOnly()): ?>
244
+ $('pbf-input-deposit').value = parseInt(pbf_selector_data['services'][service_id].deposit) / 10;
245
+ <?php endif; ?>
246
+ pbf_selector_recalculate();
247
+ }
248
+
249
+ function pbf_type_recalculate() {
250
+ var typewid = $("pbf-input-type");
251
+ var value = 0;
252
+ if (typewid) {
253
+ value = typewid.value;
254
+ }
255
+ $$(".pbf-term-hide").each(function (elem) {
256
+ elem.hide();
257
+ });
258
+ if ($('pbf-term-ruler-'+value).select('li').length != 1) {
259
+ $('pbf-term-slider-'+value).show();
260
+ $('pbf-term-ruler-'+value).show();
261
+ }
262
+ window["termSlider"+value].change();
263
+ pbf_term_recalculate();
264
+ }
265
+
266
+ function pbf_deposit(val) {
267
+ $("pbf-input-deposit").value = val/10;
268
+ depositSlider.change();
269
+ pbf_selector_recalculate();
270
+ }
271
+
272
+ function pbf_term(key, val, service_id) {
273
+ $("pbf-input-term-"+key).value = val;
274
+ window["termSlider"+key].change();
275
+ pbf_term_recalculate();
276
+ }
277
+
278
+ function pbf_type(val) {
279
+ if ($("pbf-input-type")) {
280
+ $("pbf-input-type").value = val
281
+ typeSlider.change();
282
+ pbf_type_recalculate();
283
+ }
284
+ }
285
+
286
+ function pbf_submit()
287
+ {
288
+ var service_id = $$('#paybyfinance input:checked[name=service]')[0].value;
289
+ var deposit = $("pbf-input-deposit").value * 10;
290
+ var postBody = 'service=' + service_id + '&deposit=' + deposit + '&enabled=1';
291
+ new Ajax.Request('<?php echo Mage::getUrl("paybyfinance/session/save") ?>', {method: 'post', postBody: postBody,
292
+ onSuccess: function() {
293
+ productAddToCartForm.submit(this);
294
+ },
295
+ onFailure: function() {
296
+ alert("Failed to select Finance");
297
+ }
298
+ });
299
+ }
300
+
301
+ function pbf_ajax_update()
302
+ {
303
+ new Ajax.Request('<?php echo Mage::getUrl("paybyfinance/selector/services") ?>', {
304
+ onSuccess: function(response) {
305
+ pbf_selector_data = response.responseJSON;
306
+ if (pbf_selector_user.service) {
307
+ pbf_selector_data.service = pbf_selector_user.service;
308
+ }
309
+ pbf_full_reload();
310
+ pbf_selector_recalculate();
311
+ },
312
+ onFailure: function() {
313
+ alert("Failed to get finance services");
314
+ }
315
+ });
316
+ }
317
+
318
+ function pbf_redraw()
319
+ {
320
+ $$('#paybyfinance .healthy-slider').each(function(e) {
321
+ e.fire('pbf:redraw');
322
+ });
323
+ }
324
+
325
+ function pbf_update()
326
+ {
327
+ var service_id = $$('#paybyfinance input:checked[name=service]')[0].value;
328
+ if ($('paybyfinance-yes').checked) {
329
+ enabled = 1;
330
+ } else {
331
+ enabled = 0;
332
+ }
333
+
334
+ var deposit = $("pbf-input-deposit").value * 10;
335
+ var postBody = 'service=' + service_id + '&deposit=' + deposit + '&enabled=' + enabled;
336
+ new Ajax.Request('<?php echo Mage::getUrl("paybyfinance/session/save") ?>', {method: 'post', postBody: postBody,
337
+ onSuccess: function() {
338
+ if(document.getElementById('onestepcheckout-form')) {
339
+ //if we're using onestepcheckout
340
+ var url = '<?php echo $this->getUrl('onestepcheckout/ajax/set_methods_separate', array('_secure'=>true)); ?>';
341
+ get_separate_save_methods_function(url)();
342
+ if (enabled) {
343
+ hideCountries();
344
+ } else {
345
+ showCountries();
346
+ }
347
+ Form.Element.enable('pbf-cart-btn');
348
+ } else if (document.getElementById('checkoutSteps')) {
349
+ // OnePage checkout (Magento's default)
350
+ steppable = ["shipping_method", "payment", "review"]
351
+ var i = steppable.length;
352
+ while (i--) {
353
+ if (steppable[i] === checkout.currentStep) {
354
+ shipping.save();
355
+ }
356
+ }
357
+ Form.Element.disable('pbf-cart-btn');
358
+ } else {
359
+ // Any other
360
+ location.reload(true);
361
+ }
362
+ },
363
+ onFailure: function() {
364
+ alert("Failed to select Finance");
365
+ }
366
+ });
367
+ }
368
+
369
+ if ($('paybyfinance-yes')) {
370
+ if (pbf_selector_data.enabled == 1) {
371
+ $('paybyfinance-yes').checked = true;
372
+ $('paybyfinance-container').show();
373
+ } else {
374
+ $('pbf-cart-btn').hide();
375
+ }
376
+ }
377
+ if (pbf_selector_data.deposit !== null) {
378
+ $('pbf-input-deposit').value = pbf_selector_data.deposit / 10;
379
+ }
380
+
381
+ function pbf_reselect_service()
382
+ {
383
+ // Select previously selected service.
384
+ for (var key in pbf_selector_data.terms) {
385
+ if (pbf_selector_data.terms[key]['service_id'] == pbf_selector_data.service) {
386
+ sel = $('pbf-input-term');
387
+ if (sel) {
388
+ sel.value = key;
389
+ }
390
+ }
391
+ }
392
+ pbf_selector_data.subterms.each(function(subterms, key){
393
+ subterms.each(function(val, sk) {
394
+ if (val['service_id'] == pbf_selector_data.service) {
395
+ sel = $('pbf-input-term-'+key);
396
+ if (sel) {
397
+ sel.value = sk;
398
+ pbf_selector_data.types.each(function(type, tkey) {
399
+ if(val.type == type.type && $('pbf-input-type')) {
400
+ $('pbf-input-type').value = tkey;
401
+ }
402
+ });
403
+ }
404
+ }
405
+ });
406
+ })
407
+ }
408
+
409
+ function pbf_full_reload()
410
+ {
411
+ <?php if (!$this->getIsFixedDepositOnly()): ?>
412
+ depositSlider = new Healthy.Slider('pbf-deposit-slider', 'pbf-input-deposit', 'pbf-deposit-ruler', pbf_selector_recalculate);
413
+ <?php endif; ?>
414
+
415
+ inputType = '<div id="pbf-input-type-wrapper">';
416
+
417
+ if (pbf_selector_data.types.length >= 3) {
418
+ inputType += '<div class="healthy-slider-shorty clearfix">' +
419
+ '<input id="pbf-input-type" name="pbf-input-type" class="pbf-input-hidden" type="range" min="0" max="'+(pbf_selector_data.types.length-1)+'" value ="0"/>' +
420
+ '<div id="pbf-types-slider" class="healthy-slider"> <div class="slider-marker"></div> <div class="slider-pointer"></div> </div>' +
421
+ '<ul id="pbf-types-ruler" class="healthy-ruler">';
422
+ for (index = 0; index < pbf_selector_data.types.length; ++index) {
423
+ inputType += '<li style="width: '+(100/pbf_selector_data.types.length)+'" onclick="javascript:pbf_type('+index+');">'+selector_data.types[index].name+'</li>';
424
+ };
425
+ inputType += '</ul></div>';
426
+ } else if (pbf_selector_data.types.length == 2) {
427
+ inputType += '<div class="healthy-slider-toggle-wrapper">';
428
+ inputType += '<div class="healthy-slider-toggle clearfix">' +
429
+ '<input id="pbf-input-type" name="pbf-input-type" class="pbf-input-hidden" type="range" min="0" max="'+(pbf_selector_data.types.length-1)+'" value ="0"/>' +
430
+ '<div id="pbf-types-slider" class="healthy-slider"> <div class="slider-marker"></div> <div class="slider-pointer"></div> </div>' +
431
+ '<ul id="pbf-types-ruler" class="healthy-ruler ruler-toggle">';
432
+ for (index = 0; index < pbf_selector_data.types.length; ++index) {
433
+ inputType += '<li style="width: '+(100/pbf_selector_data.types.length)+'" onclick="javascript:pbf_type('+index+');" class="ruler-'+index+'"><div class="ruler-text ruler-text-'+index+'"><div class="ruler-tick">✓</div><span>'+pbf_selector_data.types[index].name+'</span></li>';
434
+ };
435
+ inputType += '</ul></div></div>';
436
+ }
437
+
438
+ inputType += '</div>';
439
+ $('pbf-input-type-wrapper').replace(inputType);
440
+
441
+ inputTerm = '<div id="pbf-input-term-wrapper">';
442
+ if (pbf_selector_data.terms.length > 1) {
443
+ inputTerm += '<input id="pbf-input-term" name="pbf-input-term" class="pbf-input-hidden" type="range" min="0" max="'+(pbf_selector_data.terms.length - 1)+'" value ="0"/>';
444
+ pbf_selector_data.types.each(function(type, key){
445
+ inputTerm += '<input id="pbf-input-term-'+key+'" name="pbf-input-term-'+key+'" class="pbf-input-hidden" type="range" min="0" max="'+(pbf_selector_data.subterms[key].length-1)+'" value ="0"/>';
446
+ inputTerm += '<div id="pbf-term-slider-'+key+'" class="healthy-slider pbf-term-hide"> <div class="slider-marker"></div> <div class="slider-pointer"></div> </div>';
447
+ inputTerm += '<ul id="pbf-term-ruler-'+key+'" class="healthy-ruler pbf-term-hide">';
448
+ pbf_selector_data.subterms[key].each(function(term, tkey){
449
+ inputTerm += '<li class="ruler ruler-'+tkey+'" style="width: '+100/pbf_selector_data.subterms[key].length+'%;" onclick="javascript:pbf_term('+key+', '+tkey+', '+term.service_id+');">'+term.term+'</li>';
450
+ });
451
+ inputTerm += '</ul>';
452
+ });
453
+ }
454
+
455
+ inputTerm += '</div>';
456
+ $('pbf-input-term-wrapper').replace(inputTerm);
457
+
458
+ pbf_reselect_service();
459
+
460
+ if (pbf_selector_data.terms.length > 1) {
461
+ pbf_selector_data.types.each(function(type, key){
462
+ if (!isNaN(key)) {
463
+ window["termSlider"+key] = new Healthy.Slider('pbf-term-slider-'+key, 'pbf-input-term-'+key, 'pbf-term-ruler-'+key, pbf_term_recalculate);
464
+ }
465
+ });
466
+ }
467
+
468
+ if (pbf_selector_data.types.length > 1) {
469
+ typeSlider = new Healthy.Slider('pbf-types-slider', 'pbf-input-type', 'pbf-types-ruler', pbf_type_recalculate);
470
+ }
471
+
472
+ if (pbf_selector_data.service !== null) {
473
+ selector = $$('input[name="service"][value="'+pbf_selector_data.service+'"]');
474
+ if (selector.length > 0) {
475
+ selector[0].checked = true;
476
+ }
477
+ }
478
+
479
+ pbf_selector_recalculate();
480
+ }
481
+
482
+
483
+ document.observe('dom:loaded', function() {
484
+ $('paybyfinance').addClassName('skip-animation');
485
+ pbf_full_reload()
486
+ $('paybyfinance').removeClassName('skip-animation');
487
+ });
488
+
489
+ </script>
app/design/frontend/base/default/template/paybyfinance/status.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <?php echo $this->getCmsBlock(); ?>
app/etc/modules/HC_PayByFinance.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HC_PayByFinance>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </HC_PayByFinance>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>HC_PayByFinance</name>
4
+ <version>1.0.2</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.healthywebsites.co.uk/license.html">Healthy Websites</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Hitachi Capital Pay By Finance</summary>
10
+ <description>Hitachi Capital Pay By Finance</description>
11
+ <notes>First stable release</notes>
12
+ <authors><author><name>Sandor Czettner</name><user>MAG000003395</user><email>support@healthywebsites.co.uk</email></author><author><name>Alistair Macneil</name><user>MAG000006529</user><email>support@healthywebsites.co.uk</email></author><author><name>Rhuaridh Clark</name><user>MAG002562063</user><email>support@healthywebsites.co.uk</email></author></authors>
13
+ <date>2015-02-20</date>
14
+ <time>13:13:37</time>
15
+ <contents><target name="magelocal"><dir><dir name="HC"><dir name="PayByFinance"><dir name="Block"><dir name="Adminhtml"><dir name="Paybyfinance"><dir name="Service"><dir name="Edit"><file name="Form.php" hash="f84c4ee4513626c1cd47c4009c68c8e1"/><dir name="Tab"><file name="Form.php" hash="4f6b1627468a444ba3bb677a5958e60b"/></dir><file name="Tabs.php" hash="97391f42c7fef94764ca26b104eb99d2"/></dir><file name="Edit.php" hash="c9da4058c93c7de4ad7cf1f5461848a5"/><file name="Grid.php" hash="3689c360077ba67532446396806f5d9a"/></dir><file name="Service.php" hash="190ceec90eb9aab516028e3cc3f5c237"/></dir></dir><dir name="Checkout"><file name="Redirect.php" hash="f1e6291f9cdc1de9201f185a30a364d4"/></dir><dir name="Sales"><dir name="Order"><file name="Totals.php" hash="4b4c6dff06b7414853af10f10056f457"/></dir></dir><file name="Selector.php" hash="3daddea9a422c1e384e507d621dce004"/><file name="Status.php" hash="115cd6b0690b9d176ba1f899500f9cce"/></dir><dir name="Helper"><file name="Cart.php" hash="aa661c00a455e130ee6a872fbb5da059"/><file name="Checkout.php" hash="a3f888029652f8c7fda270c8a210941e"/><file name="Data.php" hash="da611b9bac4dcdd47ddbcf7ce50ffe74"/><file name="Notification.php" hash="8a1c37ec6ca866eb924839e46a95013f"/></dir><dir name="Model"><file name="Calculator.php" hash="b8e7f85e696377268723b3b18ee0b69c"/><dir name="Config"><dir name="Source"><dir name="Catalog"><dir name="Product"><file name="Finance.php" hash="b0a58b1ed5168b98463d48ab7047952f"/><file name="Type.php" hash="a26c5ea4a5806bbd240e205b811c2681"/></dir></dir><dir name="Cms"><file name="Block.php" hash="a37f1c4fa25a39f6dc9519fc7738bafb"/></dir><file name="Connectionmode.php" hash="9bd8a9e867aaa938cfef679b401ed7ee"/><file name="Type.php" hash="0499fe8f0c4693d24f4dd7bc6f399a6c"/></dir></dir><file name="Log.php" hash="6fe2441f7ccba032a975b108437e744e"/><dir name="Mysql4"><dir name="Log"><file name="Collection.php" hash="5ab2160543c7e95911645f8f147e9ac3"/></dir><file name="Log.php" hash="24b64c4a23d8a9a1fd5a349e52a33425"/><dir name="Service"><file name="Collection.php" hash="cd55fd8a58ee4ad494eb2847c239c9c4"/></dir><file name="Service.php" hash="9eb8f62eb257f2e94b96f6e2bfaad8d8"/></dir><file name="Observer.php" hash="35350d53b4bee6f9a5672a047b04e4e0"/><dir name="Paypal"><dir name="Api"><file name="Nvp.php" hash="1eec140b29675438d8b0559310c44c08"/></dir><dir name="Hostedpro"><file name="Request.php" hash="1f9b1b6fbb454ef42f15423925f323ff"/></dir></dir><dir name="PaypalUk"><dir name="Api"><file name="Nvp.php" hash="2fd9f5bdb94a9f7577acf14cad16ba4a"/></dir></dir><dir name="Post"><file name="Abstract.php" hash="ef0b84824189fb3424077cb5553e3b48"/><file name="Live.php" hash="cbbaa70f34dd05d8d44172ff48b9d3ad"/><file name="Simulation.php" hash="7fe137fd5038de0180444e5cdbe0f2e2"/><file name="Test.php" hash="7e70abee772c138520daf1ed89d872dc"/></dir><file name="Post.php" hash="eb0bf627031857bb9074c3169c120e4a"/><dir name="Resource"><file name="Setup.php" hash="1036edfcdfbd1d428e32fe52a3f89398"/></dir><dir name="Sales"><dir name="Order"><dir name="Creditmemo"><file name="Financeamount.php" hash="93f141b164a19ea3b18d765904edfc07"/></dir><dir name="Invoice"><file name="Financeamount.php" hash="15f3dbe05fedc46878f471103ebf8a70"/></dir></dir><dir name="Quote"><file name="Financeamount.php" hash="1ea32cf0ad1d21f69a3ae397a97a535e"/><file name="Totalcost.php" hash="d0298a581489845284613d342abb396a"/></dir></dir><file name="Service.php" hash="2e725486173c9610bc19a4d527fe01da"/><file name="Session.php" hash="910ad62145d3cadca6145d8f509812ef"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Paybyfinance"><file name="ServiceController.php" hash="321cd52738e5c5ac7cfc23a9382d5a6f"/></dir></dir><file name="CheckoutController.php" hash="27edab31e5acfeb5893a7fd2630f8b6c"/><file name="NotificationController.php" hash="c5698028a816a46e2c25760e70243b2e"/><file name="SelectorController.php" hash="ac0ebd56dfbd394b8dc2998d69629f0c"/><file name="SessionController.php" hash="c1561b9ff48e7f36d8c707ef6b1e9f5b"/><file name="StatusController.php" hash="f41fe7bf5546492fd9730af1af522b7b"/></dir><dir name="etc"><file name="adminhtml.xml" hash="216df222a5f5d9fdcf29c238cfd78bd5"/><file name="config.xml" hash="ee58260932654892376deb9540d1f24a"/><file name="system.xml" hash="fcbda5e4a750b8e427f5b1609adb9462"/></dir><dir name="sql"><dir name="paybyfinance_setup"><dir name="html"><file name="abandoned.html" hash="424f900dbddc267f7dac72e67752df25"/><file name="accepted.html" hash="5a12318275410a8bf62d7508422d9503"/><file name="declined.html" hash="bd3e7565c3d98645629d9f6274e4bf24"/><file name="error.html" hash="4a448b052f101b2648dfe84423ad1313"/><file name="information.html" hash="b364458ba3d9ad7579fa4935e3449b46"/><file name="page-finance-options.html" hash="d6786a27e4bf82a73e3134df0f98888b"/><file name="referred.html" hash="5955befddbb2e274f350ba71458b6151"/></dir><file name="mysql4-install-1.0.2.php" hash="58377c7871b44c91af6143f660b884ad"/><file name="mysql4-upgrade-1.0.0-1.0.1.php" hash="e5cf36eff72823d06abb2b6fdda05a28"/><file name="mysql4-upgrade-1.0.1-1.0.2.php" hash="900abb408705c4d5fd994418c64b99d8"/></dir></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="paybyfinance"><file name="form.phtml" hash="ab934201f40613f9a870ab7acb0c2b12"/><dir><dir name="sales"><dir name="order"><file name="totals.phtml" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></dir><file name="selector-no.phtml" hash="b54c570f68254a2e879464a0b761c7db"/><file name="selector.phtml" hash="832a8e05fec7263aee2b171d73d84361"/><file name="status.phtml" hash="9e02cb668c470d72612bccc09e34c51a"/></dir><dir name="checkout"><dir name="cart"><file name="totals.phtml" hash="f14878e618aa3c8943f3728128aadaa6"/></dir><dir name="onepage"><dir name="review"><file name="info.phtml" hash="e4c7c70c798f1956ae7aaa5c09114fab"/><file name="totals.phtml" hash="f26e488359433c3814a1cd416006869a"/></dir></dir><file name="cart.phtml" hash="9f6b1873ed02e5e2ae1966e3e5a1910d"/></dir></dir><dir name="layout"><file name="paybyfinance.xml" hash="25dad1b01b3f78266b55ac7b4bb5c11e"/></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="paybyfinance.xml" hash="2093299071918ce8a306988ea8a788a0"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="js"><dir name="paybyfinance"><file name="checkout.js" hash="21051d8691dd773427d3e761403896ab"/><file name="functions.js" hash="98c27381b3f7eaeaa845271dbe763f05"/><file name="slider.js" hash="453a7468c528377d4b0db03848a62f93"/></dir></dir><dir name="css"><file name="paybyfinance.css" hash="25d02dc5cf228662c30d908d7c2f1356"/><file name="paybyfinance-ie8.css" hash="a6be9c7af8b95300bc62e4fe9ef252ac"/></dir><dir name="images"><dir name="paybyfinance"><file name="bullet.png" hash="ea2baab34b2eb7d0aacb7a67d5b080f1"/><file name="pointer-toggle.png" hash="e661d42aed7a5562f75828312c7a635a"/><file name="pointer.png" hash="68c58b28d6ebd77d415f8666c301a199"/><file name="progress.png" hash="6d46a109cc9e38a663678918142d89f2"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="HC_PayByFinance.xml" hash="1202534cbafc0da4499963aa80878c8f"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.4.38</min><max>5.6.6</max></php></required></dependencies>
18
+ </package>
skin/frontend/base/default/css/paybyfinance-ie8.css ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* IE8 hacks */
2
+ .healthy-slider {
3
+ display: none;
4
+ }
5
+ .healthy-ruler, .healthy-slider-toggle .healthy-ruler {
6
+ height: auto;
7
+ }
8
+
9
+ .paybyfinance-selector .healthy-slider-toggle-wrapper {
10
+ padding-top: 20px;
11
+ }
12
+
13
+ .healthy-ruler li, .healthy-slider-toggle .healthy-ruler li {
14
+ background: url(../images/paybyfinance/bullet.png) top center no-repeat;
15
+ margin-top: 0;
16
+ text-align: left;
17
+ float: none;
18
+ padding: 0 0 0 22px;
19
+ background-position: top left;
20
+ width: auto;
21
+ }
22
+
23
+ .healthy-slider-toggle .healthy-ruler li.ruler-0, .healthy-slider-toggle .healthy-ruler li.ruler-1 {
24
+ margin-left: 0;
25
+ margin-right: 0;
26
+ padding-right: 0;
27
+ text-align: left;
28
+ }
29
+
30
+ .paybyfinance-selector .healthy-ruler li.active {
31
+ background-position: left -100px;
32
+ }
skin/frontend/base/default/css/paybyfinance.css ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .paybyfinance-selector {
2
+ padding: 15px;
3
+ overflow: hidden;
4
+ margin-bottom: 20px;
5
+ box-sizing: border-box;
6
+ -webkit-box-sizing: border-box;
7
+ -moz-box-sizing: border-box;
8
+ }
9
+
10
+ .paybyfinance-selector .healthy-slider-shorty {
11
+ width: 60%;
12
+ margin: 0 auto;
13
+ }
14
+
15
+ .paybyfinance-selector .healthy-slider-toggle-wrapper {
16
+ background: #f4f4f4;
17
+ }
18
+
19
+ .healthy-slider-toggle-wrapper {
20
+ max-width: 480px;
21
+ margin: 0 auto;
22
+ padding-top: 10px;
23
+ }
24
+
25
+ .paybyfinance-selector .healthy-slider-toggle {
26
+ max-width: 160px;
27
+ width: 26%;
28
+ margin: 0 auto;
29
+ padding-bottom: 1px;
30
+ }
31
+
32
+ .paybyfinance-selector div {
33
+ box-sizing: border-box;
34
+ -webkit-box-sizing: border-box;
35
+ -moz-box-sizing: border-box;
36
+ }
37
+
38
+ .paybyfinance-selector .calculated {
39
+ color: #378AD6;
40
+ font-weight: bold;
41
+ }
42
+
43
+ .paybyfinance-selector .small {
44
+ font-size: 0.85em;
45
+ }
46
+
47
+ .paybyfinance-selector .paybyfinance-sum {
48
+ background: #f4f4f4;
49
+ border: 1px solid #ccc;
50
+ margin: 20px 0;
51
+ padding: 10px;
52
+ }
53
+
54
+ .paybyfinance-selector .paybyfinance-sum table {
55
+ width: 100%;
56
+ }
57
+
58
+ .pbf-input-hidden {
59
+ height: 0;
60
+ display: block;
61
+ margin: 0 auto;
62
+ -moz-opacity: 0.01;
63
+ opacity:.01;
64
+ filter: alpha(opacity=01);
65
+ position: relative;
66
+ width: 100%;
67
+ z-index: 1;
68
+ }
69
+
70
+ .paybyfinance-selector .services { display: none; }
71
+
72
+ .healthy-ruler {
73
+ width: 100%;
74
+ clear: both;
75
+ display: block;
76
+ height: 58px;
77
+ margin-bottom: 20px;
78
+ box-sizing: border-box;
79
+ -webkit-box-sizing: border-box;
80
+ -moz-box-sizing: border-box;
81
+ }
82
+
83
+ .pbf-term-hide {
84
+ margin-bottom: 0px;
85
+ }
86
+
87
+ .healthy-ruler .ruler {
88
+ background: url(../images/paybyfinance/bullet.png) top center no-repeat;
89
+ padding-top: 20px;
90
+ }
91
+
92
+ .healthy-ruler li {
93
+ cursor:pointer;cursor:hand;
94
+ display: block;
95
+ float: left;
96
+ margin-top: 20px;
97
+ padding-top: 20px;
98
+ text-align: center;
99
+ width: 14.285714286%;
100
+ }
101
+
102
+ .healthy-ruler li.active {
103
+ background-position: center -100px;
104
+ }
105
+
106
+ .healthy-slider-toggle .healthy-ruler {
107
+ height: 0;
108
+ }
109
+
110
+ .healthy-slider-toggle .healthy-ruler li {
111
+ background: none;
112
+ margin-top: -40px;
113
+ padding-top: 0;
114
+ width: 100%;
115
+ }
116
+
117
+ .healthy-slider-toggle .healthy-ruler li.active {
118
+ color: #378AD6;
119
+ }
120
+
121
+ .healthy-slider-toggle .healthy-ruler li div div {
122
+ visibility:hidden;
123
+ display: inline;
124
+ }
125
+
126
+ .healthy-slider-toggle .healthy-ruler li.active div div {
127
+ visibility:visible;
128
+ }
129
+
130
+ .healthy-slider-toggle .healthy-ruler .ruler-text-0 {
131
+ text-align: right;
132
+ padding-right: 20px;
133
+ }
134
+
135
+ .healthy-slider-toggle .healthy-ruler .ruler-text-1 {
136
+ text-align: left;
137
+ padding-left: 15px;
138
+ }
139
+
140
+ .healthy-slider-toggle .healthy-ruler .ruler-text-1 span {
141
+ display: block;
142
+ margin-left: 15px;
143
+ }
144
+
145
+ .healthy-slider-toggle .healthy-ruler .ruler-text-1 .ruler-tick {
146
+ display: block;
147
+ float: left;
148
+ }
149
+
150
+ .healthy-slider-toggle .healthy-ruler li.ruler-0 {
151
+ margin-left: -100%;
152
+ }
153
+
154
+ .healthy-slider-toggle .healthy-ruler li.ruler-1 {
155
+ margin-left: 100%;
156
+ margin-right: -100%;
157
+ }
158
+
159
+ .cart-forms .paybyfinance-selector {
160
+ background-color: #fff;
161
+ border: 1px solid #cccccc;
162
+ margin-bottom: 20px;
163
+ }
164
+
165
+ .healthy-slider {
166
+ background: #cfcfcf;
167
+ border-radius: 30px;
168
+ -moz-border-radius: 30px;
169
+ -webkit-border-radius: 30px;
170
+ border: 17px solid #e9e9e9;
171
+ clear: both;
172
+ display: block;
173
+ box-sizing: border-box;
174
+ -webkit-box-sizing: border-box;
175
+ -moz-box-sizing: border-box;
176
+ margin: 10px auto 0;
177
+ position: relative;
178
+ -moz-box-shadow: inset -4px 4px 10px #999;
179
+ -webkit-box-shadow: inset -4px 4px 10px #999;
180
+ box-shadow: inset -4px 4px 10px #999;
181
+ width: 100%;
182
+ }
183
+
184
+ .healthy-slider .slider-marker {
185
+ transition-property: width;
186
+ transition-duration: 0.15s;
187
+ background: url(../images/paybyfinance/progress.png);
188
+ border-radius: 13px;
189
+ -moz-border-radius: 13px;
190
+ -webkit-border-radius: 13px;
191
+ height: 22px;
192
+ }
193
+
194
+ .skip-animation .healthy-slider .slider-marker {
195
+ transition-property: none;
196
+ }
197
+
198
+ .paybyfinance-selector .healthy-slider-toggle .slider-marker
199
+ {
200
+ background: none;
201
+ }
202
+
203
+ .healthy-slider .slider-pointer {
204
+ transition-property: left;
205
+ transition-duration: 0.15s;
206
+ background: url(../images/paybyfinance/pointer.png);
207
+ display: block;
208
+ height: 104px;
209
+ transform: scale(0.75, 0.75);
210
+ -moz-transform: scale(0.75, 0.75);
211
+ -ms-transform: scale(0.75, 0.75);
212
+ -webkit-transform: scale(0.75, 0.75);
213
+ -o-transform: scale(0.75, 0.75);
214
+ top: -34px;
215
+ position: absolute;
216
+ width: 82px;
217
+ }
218
+
219
+ .skip-animation .healthy-slider .slider-pointer {
220
+ transition-property: none;
221
+ }
222
+
223
+ .healthy-slider-toggle .slider-pointer {
224
+ background: url(../images/paybyfinance/pointer-toggle.png);
225
+ }
226
+
227
+ .pbf-footnote {
228
+ font-size: 0.85em;
229
+ }
230
+
231
+ .pbf-footnote p {
232
+ margin-bottom: 0.5em;
233
+ }
234
+
235
+ #pbf-error {
236
+ transition-property: height, opacity;
237
+ transition-duration: 0.35s;
238
+ }
skin/frontend/base/default/images/paybyfinance/bullet.png ADDED
Binary file
skin/frontend/base/default/images/paybyfinance/pointer-toggle.png ADDED
Binary file
skin/frontend/base/default/images/paybyfinance/pointer.png ADDED
Binary file
skin/frontend/base/default/images/paybyfinance/progress.png ADDED
Binary file
skin/frontend/base/default/js/paybyfinance/checkout.js ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.observe('dom:loaded', function() {
2
+
3
+ selector_data = window.pbf_selector_data;
4
+ if (selector_data && selector_data.enabled) {
5
+ if(document.getElementById('onestepcheckout-form')) {
6
+ //if we're using onestepcheckout
7
+ $('billing_address').insert({
8
+ top: '<p class="paybyfinance-info">If you are paying by finance then goods MUST be delivered to your billing address. Products can not be delivered outside the UK.</p>',
9
+ });
10
+ hideCountries();
11
+ } else {
12
+ $('co-billing-form').insert({
13
+ top: '<p class="paybyfinance-info">If you are paying by finance then goods MUST be delivered to your billing address. Products can not be delivered outside the UK.</p>',
14
+ });
15
+ $('billing:use_for_shipping_yes').checked = true;
16
+ $('billing:use_for_shipping_no').up().hide();
17
+ $('billing:use_for_shipping_no').disabled = true;
18
+ hideCountries();
19
+ $('shipping-new-address-form').up().hide();
20
+ $('checkout-step-shipping').insert({
21
+ top: '<p class="paybyfinance-info-shipping">It is not possible to select a different shipping address when the order is being paid by finance.</p>'
22
+ });
23
+ if($('shipping-address-select') != null) {
24
+ $('shipping-address-select').observe('change', function() {
25
+ alert('If you are paying by finance then goods MUST be delivered to your billing address. Products can not be delivered outside the UK.');
26
+ });
27
+ }
28
+ $('billing:country_id').observe('focus', function() {
29
+ var inputs = this.form.getElements();
30
+ var idx = inputs.indexOf(this);
31
+ inputs[idx + 1].focus(); // handles submit buttons
32
+ inputs[idx + 1].select();
33
+ });
34
+ }
35
+ }
36
+ });
37
+
38
+ function hideCountries() {
39
+ $('billing:country_id').value = 'GB';
40
+ if (window.billingRegionUpdater) {
41
+ billingRegionUpdater.update();
42
+ }
43
+ var select2 = document.getElementById("billing:country_id");
44
+ for (var i = 0; i < select2.length; i++) {
45
+ if (select2.options[i].value != 'GB') {
46
+ select2.options[i].style.display = "none";
47
+ }
48
+ }
49
+ if(document.getElementById('onestepcheckout-form')) {
50
+ $('billing:use_for_shipping_yes').checked = true;
51
+ $('billing:use_for_shipping_yes').up().hide();
52
+ $('shipping_address').hide();
53
+ }
54
+ }
55
+
56
+ function showCountries() {
57
+ if (window.billingRegionUpdater) {
58
+ billingRegionUpdater.update();
59
+ }
60
+ var select2 = document.getElementById("billing:country_id");
61
+ for (var i = 0; i < select2.length; i++) {
62
+ select2.options[i].style.display = "block";
63
+ }
64
+ if(document.getElementById('onestepcheckout-form')) {
65
+ $('billing:use_for_shipping_yes').up().show();
66
+ }
67
+ }
skin/frontend/base/default/js/paybyfinance/functions.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ if (!Healthy) var Healthy = { };
2
+
3
+ Healthy.Functions = {
4
+ currencyFormat: function(value, d, t) {
5
+ if (!isNaN(parseFloat(value)) && isFinite(value)) {
6
+ value = parseFloat(value);
7
+ return value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
8
+ } else {
9
+ return 0;
10
+ }
11
+ },
12
+ };
skin/frontend/base/default/js/paybyfinance/slider.js ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ if (!Healthy) var Healthy = { };
2
+
3
+ Healthy.Slider = Class.create({
4
+ // Class instantiation will call initialize. See
5
+ // http://prototypejs.org/doc/latest/language/Class/create/
6
+ initialize: function(widget, inputField, ruler, onchange, options) {
7
+ var slider = this;
8
+
9
+ slider.inputField = $(inputField);
10
+ slider.max = slider.inputField.getAttribute('max');
11
+ slider.widget = $(widget);
12
+ slider.ruler = $(ruler);
13
+ slider.pointer = slider.widget.down('.slider-pointer');
14
+ slider.marker = slider.widget.down('.slider-marker');
15
+ slider.onchange = onchange;
16
+ slider.options = options || { };
17
+ slider.touchstatus = "up";
18
+
19
+ // Down.
20
+ Event.observe(slider.widget, 'touchstart', slider.touchStart.bind(slider));
21
+ Event.observe(slider.widget, 'mousedown', slider.touchStart.bind(slider));
22
+
23
+ // Move.
24
+ Event.observe(slider.widget, 'touchmove', slider.touchMove.bind(slider));
25
+ Event.observe(window, 'mousemove', slider.touchMove.bind(slider));
26
+
27
+ // Up.
28
+ Event.observe(slider.widget, 'touchend', slider.touchUp.bind(slider));
29
+ Event.observe(window, 'mouseup', slider.touchUp.bind(slider));
30
+
31
+ // Window resize or zoom
32
+ Event.observe(window, 'resize', slider.resize.bind(slider));
33
+
34
+ // Redraw custom event
35
+ Event.observe(slider.widget, 'pbf:redraw', slider.resize.bind(slider));
36
+
37
+ // Manual change on input.
38
+ Event.observe(slider.inputField, 'change', function(){
39
+ slider.draw(slider);
40
+ slider.onchange();
41
+ });
42
+
43
+ // This hack is required as hidden tabs has 0 width.
44
+ $$('.toggle-content.tabs').each(function(item) {
45
+ Event.observe(item, 'click', function() {
46
+ slider.draw(slider);
47
+ });
48
+ });
49
+ // Same for Enterprise.
50
+ $$('.collateral-tabs .tab span').each(function(item) {
51
+ Event.observe(item, 'click', function() {
52
+ window.setTimeout(function() {
53
+ slider.draw(slider);
54
+ }, 100);
55
+ });
56
+ });
57
+
58
+ slider.draw(slider);
59
+ this.onchange();
60
+ },
61
+
62
+ touchStart: function(e) {
63
+ e.preventDefault();
64
+ this.touchstatus = 'down';
65
+ },
66
+
67
+ touchMove: function(e) {
68
+ slider = this;
69
+ if (this.touchstatus == 'down') {
70
+ e.preventDefault();
71
+ slider.move(e);
72
+ }
73
+ },
74
+
75
+ touchUp: function(e) {
76
+ if (this.touchstatus == 'down') {
77
+ e.preventDefault();
78
+ this.touchstatus = 'up';
79
+ this.onchange();
80
+ }
81
+ },
82
+
83
+ change: function() {
84
+ this.draw(this);
85
+ },
86
+
87
+ resize: function() {
88
+ this.draw(this);
89
+ },
90
+
91
+ move: function (e) {
92
+ var slider = this;
93
+ var width = slider.widget.offsetWidth - 60;
94
+ var x = e.pageX - slider.widget.cumulativeOffset().left;
95
+ if (e && e.touches) x=e.touches[0].pageX - slider.widget.cumulativeOffset().left;
96
+ var percent = x / (width+41) * slider.max;
97
+ this.inputField.value = Math.round(percent);
98
+ if (slider.options.secondInput) {
99
+ $(slider.options.secondInput).value = percent;
100
+ }
101
+ slider.draw(slider);
102
+ },
103
+
104
+ getIeVersion: function() {
105
+ if (!Prototype.Browser.IE) {
106
+ return false;
107
+ }
108
+ if (window.ActiveXObject === undefined) return null;
109
+ if (!document.querySelector) return 7;
110
+ if (!document.addEventListener) return 8;
111
+ if (!window.atob) return 9;
112
+ if (!document.__proto__) return 10;
113
+ },
114
+
115
+ draw: function(slider) {
116
+ var width = parseInt(this.widget.offsetWidth) ;
117
+ if (width === 0 || isNaN(width)) {
118
+ width = parseInt(this.widget.up().up().offsetWidth);
119
+ }
120
+ if (width === 0 || isNaN(width)) {
121
+ width = parseInt(this.widget.up().up().up().offsetWidth);
122
+ }
123
+ if (width === 0 || isNaN(width)) {
124
+ width = parseInt(this.widget.up().up().up().up().offsetWidth);
125
+ }
126
+ if (width === 0 || isNaN(width)) {
127
+ width = parseInt(this.widget.up().up().up().up().up().offsetWidth);
128
+ }
129
+ if (width !== 0) {
130
+ width = width - 34;
131
+ }
132
+ if (slider.max !== "0") {
133
+ x = ((width / (parseInt(slider.max))) * slider.inputField.value) - 41;
134
+ ie = slider.getIeVersion();
135
+
136
+ shift = ((width) / (parseInt(slider.max)));
137
+
138
+ if (!this.ruler.hasClassName('ruler-toggle')) {
139
+ this.ruler.setStyle({width: (width + shift) + 'px'});
140
+ if (!ie || ie >= 9) {
141
+ cellShift = this.ruler.offsetWidth / (parseInt(slider.max)+1) / 2;
142
+
143
+ this.ruler.setStyle({marginLeft: '-' + (cellShift-17) + 'px'});
144
+ this.ruler.setStyle({marginRight: '-' + (cellShift-17) + 'px'});
145
+ }
146
+ }
147
+
148
+ if (slider.ruler.select('li').length !== 0) {
149
+ slider.ruler.select('li').each(function(el) {
150
+ el.removeClassName('active');
151
+ });
152
+
153
+ slider.ruler.select('li.ruler-'+ slider.inputField.value)[0].addClassName('active');
154
+ }
155
+
156
+ this.pointer.setStyle({left: x + 'px'});
157
+ this.marker.setStyle({width: (x + 41) + 'px'});
158
+ } else {
159
+ x = width / 2 - 41;
160
+ this.pointer.setStyle({left: x + 'px'});
161
+ this.marker.setStyle({width: (x + 41) + 'px'});
162
+ }
163
+ }
164
+
165
+ });