Allopass_Hipay - Version 1.7.0

Version Notes

Download this release

Release Info

Developer Kassim Belghait
Extension Allopass_Hipay
Version 1.7.0
Comparing to
See all releases


Code changes from version 1.6.2 to 1.7.0

Files changed (70) hide show
  1. app/code/community/Allopass/Hipay/Block/Adminhtml/Field/MappingCategory.php +137 -0
  2. app/code/community/Allopass/Hipay/Block/Adminhtml/Field/MappingShippingMethod.php +155 -0
  3. app/code/community/Allopass/Hipay/Block/Adminhtml/Field/Renderer/Label.php +18 -0
  4. app/code/community/Allopass/Hipay/Block/Adminhtml/Field/Renderer/List.php +44 -0
  5. app/code/community/Allopass/Hipay/Block/Adminhtml/System/Config/Form/Field/Expanded.php +23 -0
  6. app/code/community/Allopass/Hipay/Block/Adminhtml/System/Config/Form/Field/Information.php +34 -0
  7. app/code/community/Allopass/Hipay/Block/Adminhtml/System/Config/Form/Field/Notice.php +43 -26
  8. app/code/community/Allopass/Hipay/Block/Form/Abstract.php +9 -0
  9. app/code/community/Allopass/Hipay/Helper/Collection.php +308 -0
  10. app/code/community/Allopass/Hipay/Helper/Data.php +345 -69
  11. app/code/community/Allopass/Hipay/Model/Config.php +308 -285
  12. app/code/community/Allopass/Hipay/Model/Field/CategoryMapping.php +5 -0
  13. app/code/community/Allopass/Hipay/Model/Field/MappingShippingMethod.php +27 -0
  14. app/code/community/Allopass/Hipay/Model/Method/Abstract.php +155 -98
  15. app/code/community/Allopass/Hipay/Model/Method/AbstractOrder.php +86 -0
  16. app/code/community/Allopass/Hipay/Model/Method/Astropay.php +51 -0
  17. app/code/community/Allopass/Hipay/Model/Method/Aura.php +8 -0
  18. app/code/community/Allopass/Hipay/Model/Method/Banamex.php +7 -0
  19. app/code/community/Allopass/Hipay/Model/Method/Banco.php +7 -0
  20. app/code/community/Allopass/Hipay/Model/Method/Bbva.php +7 -0
  21. app/code/community/Allopass/Hipay/Model/Method/Boleto.php +7 -0
  22. app/code/community/Allopass/Hipay/Model/Method/Bradesco.php +7 -0
  23. app/code/community/Allopass/Hipay/Model/Method/Caixa.php +7 -0
  24. app/code/community/Allopass/Hipay/Model/Method/Cc.php +30 -6
  25. app/code/community/Allopass/Hipay/Model/Method/Dexia.php +1 -1
  26. app/code/community/Allopass/Hipay/Model/Method/Discover.php +5 -0
  27. app/code/community/Allopass/Hipay/Model/Method/Facilipay3x.php +7 -0
  28. app/code/community/Allopass/Hipay/Model/Method/Facilipay4x.php +8 -0
  29. app/code/community/Allopass/Hipay/Model/Method/Itau.php +7 -0
  30. app/code/community/Allopass/Hipay/Model/Method/Oxxo.php +7 -0
  31. app/code/community/Allopass/Hipay/Model/Method/PaypalApi.php +1 -81
  32. app/code/community/Allopass/Hipay/Model/Method/PostfinancecardApi.php +4 -87
  33. app/code/community/Allopass/Hipay/Model/Method/PostfinanceefinanceApi.php +1 -84
  34. app/code/community/Allopass/Hipay/Model/Method/Przelewy24Api.php +1 -84
  35. app/code/community/Allopass/Hipay/Model/Method/Santander.php +7 -0
  36. app/code/community/Allopass/Hipay/Model/Method/Santandercash.php +7 -0
  37. app/code/community/Allopass/Hipay/Model/Method/SisalApi.php +1 -80
  38. app/code/community/Allopass/Hipay/Model/Method/SofortApi.php +1 -83
  39. app/code/community/Allopass/Hipay/Model/Method/WebmoneyApi.php +2 -84
  40. app/code/community/Allopass/Hipay/Model/Method/YandexApi.php +2 -84
  41. app/code/community/Allopass/Hipay/Model/Observer.php +87 -37
  42. app/code/community/Allopass/Hipay/Model/Source/Product/Facilipay3x.php +15 -0
  43. app/code/community/Allopass/Hipay/Model/Source/Product/Facilipay4x.php +15 -0
  44. app/code/community/Allopass/Hipay/Model/SplitPayment.php +23 -23
  45. app/code/community/Allopass/Hipay/controllers/Adminhtml/PaymentController.php +94 -114
  46. app/code/community/Allopass/Hipay/controllers/AuraController.php +8 -0
  47. app/code/community/Allopass/Hipay/controllers/BanamexController.php +8 -0
  48. app/code/community/Allopass/Hipay/controllers/BancoController.php +8 -0
  49. app/code/community/Allopass/Hipay/controllers/BbvaController.php +8 -0
  50. app/code/community/Allopass/Hipay/controllers/BoletoController.php +8 -0
  51. app/code/community/Allopass/Hipay/controllers/BradescoController.php +8 -0
  52. app/code/community/Allopass/Hipay/controllers/CaixaController.php +8 -0
  53. app/code/community/Allopass/Hipay/controllers/DiscoverController.php +8 -0
  54. app/code/community/Allopass/Hipay/controllers/Facilipay3xController.php +8 -0
  55. app/code/community/Allopass/Hipay/controllers/Facilipay4xController.php +8 -0
  56. app/code/community/Allopass/Hipay/controllers/ItauController.php +8 -0
  57. app/code/community/Allopass/Hipay/controllers/OxxoController.php +8 -0
  58. app/code/community/Allopass/Hipay/controllers/SantanderCashController.php +8 -0
  59. app/code/community/Allopass/Hipay/controllers/SantanderController.php +8 -0
  60. app/code/community/Allopass/Hipay/etc/config.xml +491 -20
  61. app/code/community/Allopass/Hipay/etc/system.xml +4769 -232
  62. app/design/adminhtml/default/default/layout/hipay.xml +3 -0
  63. app/design/adminhtml/default/default/template/hipay/mapping.phtml +130 -0
  64. app/design/adminhtml/default/default/template/hipay/system/config/form/field/information.phtml +13 -0
  65. app/design/adminhtml/default/default/template/hipay/system/config/form/field/notice.phtml +2 -8
  66. app/design/frontend/base/default/template/hipay/form/cc.phtml +41 -2
  67. app/locale/en_US/Allopass_Hipay.csv +2 -0
  68. app/locale/fr_FR/Allopass_Hipay.csv +4 -2
  69. package.xml +1 -1
  70. skin/adminhtml/base/default/hipay/css/hipay.css +50 -0
app/code/community/Allopass/Hipay/Block/Adminhtml/Field/MappingCategory.php ADDED
@@ -0,0 +1,137 @@
1
+ <?php
2
+
3
+ class Allopass_Hipay_Block_Adminhtml_Field_MappingCategory extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ /**
6
+ * Renderer for List Category
7
+ *
8
+ * @var Allopass_Hipay_Block_Adminhtml_Field_Renderer_List
9
+ */
10
+ protected $_listRenderer;
11
+
12
+ /**
13
+ * Renderer for Label
14
+ *
15
+ * @var Allopass_Hipay_Block_Adminhtml_Field_Renderer_Label
16
+ */
17
+ protected $_labelRenderer;
18
+
19
+ /**
20
+ *
21
+ * @inheritdoc
22
+ */
23
+ public function getArrayRows()
24
+ {
25
+ $options = array();
26
+ $categories = Mage::helper('hipay')->getMagentoCategories();
27
+ $mappingSaved = $this->getElement()->getValue();
28
+
29
+ // Add All Magento categories in Array Rows
30
+ if (!array_key_exists($mappingSaved[key($mappingSaved)], 'magento_code')) {
31
+ if (!empty($categories) && is_array($categories)) {
32
+ foreach ($categories as $code => $label) {
33
+ $mapping = $this->_getHipayCategoryMapping($code);
34
+ $options[$code] = array(
35
+ 'magento_code' => $code,
36
+ 'magento_label' => $label,
37
+ 'hipay_category' => $this->_getHipayCategoryMapping($code),
38
+ 'class' => empty($mapping) ? 'warning-mapping' : ''
39
+ );
40
+ }
41
+ }
42
+ } else {
43
+ $options = $mappingSaved;
44
+ }
45
+
46
+ $this->getElement()->setValue($options);
47
+ return parent::getArrayRows();
48
+ }
49
+
50
+
51
+ /**
52
+ * Prepare to render for Mapping category
53
+ */
54
+ public function _prepareToRender()
55
+ {
56
+ $this->_addAfter = false;
57
+ $this->setTemplate('hipay/mapping.phtml');
58
+ $this->addColumn(
59
+ 'magento_category',
60
+ array(
61
+ 'label' => Mage::helper('hipay')->__('Magento category'),
62
+ 'renderer' => $this->_getLabelRenderer()
63
+ )
64
+ );
65
+
66
+ $this->addColumn(
67
+ 'hipay_category',
68
+ array(
69
+ 'label' => Mage::helper('hipay')->__('Hipay category'),
70
+ 'renderer' => $this->_getListOptionsRenderer()
71
+ )
72
+ );
73
+
74
+ }
75
+
76
+ /**
77
+ * Get Label Renderer ( No input select )
78
+ *
79
+ * @return Allopass_Hipay_Block_Adminhtml_Field_Renderer_Label
80
+ */
81
+ public function _getLabelRenderer()
82
+ {
83
+ if (!$this->_labelRenderer) {
84
+ $this->_labelRenderer = $this->getLayout()->createBlock('hipay/adminhtml_field_renderer_label', '');
85
+ }
86
+ return $this->_labelRenderer;
87
+ }
88
+
89
+ /**
90
+ * Get List Renderer
91
+ *
92
+ * @return Allopass_Hipay_Block_Adminhtml_Field_Renderer_Label
93
+ */
94
+ public function _getListOptionsRenderer()
95
+ {
96
+ $options = Mage::helper('hipay/collection')->getItemsCategory();
97
+ if (!$this->_listRenderer) {
98
+ $this->_listRenderer = $this->getLayout()->createBlock('hipay/adminhtml_field_renderer_list',
99
+ '',
100
+ array('is_render_to_js_template' => true));
101
+ $this->_listRenderer->setListOptions($options);
102
+ }
103
+ return $this->_listRenderer;
104
+ }
105
+
106
+ /**
107
+ * Extract hipay category from Mapping
108
+ *
109
+ * @param $codeMagentoCategory
110
+ * @return null|int
111
+ */
112
+ protected function _getHipayCategoryMapping($codeMagentoCategory)
113
+ {
114
+ $mappingSaved = $this->getElement()->getValue();
115
+ $id_hipay_category = null;
116
+ foreach ($mappingSaved as $mapping) {
117
+ if ($mapping['magento_category'] == $codeMagentoCategory) {
118
+ $id_hipay_category = $mapping['hipay_category'];
119
+ break;
120
+ }
121
+ }
122
+ return $id_hipay_category;
123
+ }
124
+
125
+
126
+ /**
127
+ * @inheritdoc
128
+ */
129
+ protected function _prepareArrayRow(Varien_Object $row)
130
+ {
131
+ $row->setData(
132
+ 'option_extra_attr_' . $this->_getListOptionsRenderer()
133
+ ->calcOptionHash($row->getData('hipay_category')),
134
+ 'selected="selected"'
135
+ );
136
+ }
137
+ }
app/code/community/Allopass/Hipay/Block/Adminhtml/Field/MappingShippingMethod.php ADDED
@@ -0,0 +1,155 @@
1
+ <?php
2
+
3
+ class Allopass_Hipay_Block_Adminhtml_Field_MappingShippingMethod extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
4
+ {
5
+ /**
6
+ * Renderer for List Category
7
+ *
8
+ * @var Allopass_Hipay_Block_Adminhtml_Field_Renderer_List
9
+ */
10
+ protected $_listRenderer;
11
+
12
+ /**
13
+ * Renderer for Label
14
+ *
15
+ * @var Allopass_Hipay_Block_Adminhtml_Field_Renderer_Label
16
+ */
17
+ protected $_labelRenderer;
18
+
19
+ /**
20
+ *
21
+ * @inheritdoc
22
+ */
23
+ public function getArrayRows()
24
+ {
25
+ $options = array();
26
+ $shippingMethod = Mage::helper('hipay')->getMagentoShippingMethods();
27
+ $mappingSaved = $this->getElement()->getValue();
28
+
29
+ // Add All Magento categories in Array Rows
30
+ if (!array_key_exists($mappingSaved[key($mappingSaved)], 'magento_code')) {
31
+ if (!empty($shippingMethod) && is_array($shippingMethod)) {
32
+ foreach ($shippingMethod as $code => $label) {
33
+ $mapping = $this->_getHipayDeliveryMapping($code);
34
+ $options[$code] =
35
+ array(
36
+ 'magento_code' => $code,
37
+ 'magento_label' => $label,
38
+ 'hipay_delivery_method' => $mapping['hipay_delivery_method'],
39
+ 'delay_preparation' => $mapping['delay_preparation'],
40
+ 'delay_delivery' => $mapping['delay_delivery'],
41
+ 'class' => empty($mapping) || (empty($mapping['hipay_delivery_method'])
42
+ || empty($mapping['delay_preparation']) || empty($mapping['delay_delivery']) ) ? 'warning-mapping' : ''
43
+ );
44
+ }
45
+ }
46
+ } else {
47
+ $options = $mappingSaved;
48
+ }
49
+
50
+ $this->getElement()->setValue($options);
51
+ return parent::getArrayRows();
52
+ }
53
+
54
+
55
+ /**
56
+ * Prepare to render for Shipping Method Mapping
57
+ */
58
+ public function _prepareToRender()
59
+ {
60
+ $this->_addAfter = false;
61
+ $this->setTemplate('hipay/mapping.phtml');
62
+ $this->addColumn(
63
+ 'magento_shipping_method',
64
+ array(
65
+ 'label' => Mage::helper('hipay')->__('Magento shipping method'),
66
+ 'style' => 'width: 400px;',
67
+ 'renderer' => $this->_getLabelRenderer()
68
+ )
69
+ );
70
+
71
+ $this->addColumn(
72
+ 'hipay_delivery_method',
73
+ array(
74
+ 'label' => Mage::helper('hipay')->__('Hipay delivery method'),
75
+ 'renderer' => $this->_getListOptionsRenderer()
76
+ )
77
+ );
78
+
79
+ $this->addColumn(
80
+ 'delay_preparation',
81
+ array(
82
+ 'label' => Mage::helper('hipay')->__('Order preparation delay'),
83
+ 'style' => 'width: 50px;',
84
+ )
85
+ );
86
+ $this->addColumn(
87
+ 'delay_delivery',
88
+ array(
89
+ 'label' => Mage::helper('hipay')->__('Delivery delay'),
90
+ 'style' => 'width: 50px;',
91
+ )
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Get Label Renderer ( No input select )
97
+ *
98
+ * @return Allopass_Hipay_Block_Adminhtml_Field_Renderer_Label
99
+ */
100
+ public function _getLabelRenderer()
101
+ {
102
+ if (!$this->_labelRenderer) {
103
+ $this->_labelRenderer = $this->getLayout()->createBlock('hipay/adminhtml_field_renderer_label', '');
104
+ }
105
+ return $this->_labelRenderer;
106
+ }
107
+
108
+ /**
109
+ * Get List Renderer
110
+ *
111
+ * @return Allopass_Hipay_Block_Adminhtml_Field_Renderer_Label
112
+ */
113
+ public function _getListOptionsRenderer()
114
+ {
115
+ if (!$this->_listRenderer) {
116
+ $options = Mage::helper('hipay/collection')->getItemsDelivery();
117
+ $this->_listRenderer = $this->getLayout()->createBlock('hipay/adminhtml_field_renderer_list',
118
+ '',
119
+ array('is_render_to_js_template' => true));
120
+ $this->_listRenderer->setListOptions($options);
121
+ }
122
+ return $this->_listRenderer;
123
+ }
124
+
125
+ /**
126
+ * Extract hipay delivery method from Mapping
127
+ *
128
+ * @param $codeMagentoCategory
129
+ * @return null|int
130
+ */
131
+ protected function _getHipayDeliveryMapping($codeMagentoCategory)
132
+ {
133
+ $mappingSaved = $this->getElement()->getValue();
134
+ foreach ($mappingSaved as $mapping) {
135
+ if ($mapping['magento_shipping_method'] == $codeMagentoCategory) {
136
+ return $mapping;
137
+ break;
138
+ }
139
+ }
140
+ return null;
141
+ }
142
+
143
+
144
+ /**
145
+ * @inheritdoc
146
+ */
147
+ protected function _prepareArrayRow(Varien_Object $row)
148
+ {
149
+ $row->setData(
150
+ 'option_extra_attr_' . $this->_getListOptionsRenderer()
151
+ ->calcOptionHash($row->getData('hipay_delivery_method')),
152
+ 'selected="selected"'
153
+ );
154
+ }
155
+ }
app/code/community/Allopass/Hipay/Block/Adminhtml/Field/Renderer/Label.php ADDED
@@ -0,0 +1,18 @@
1
+ <?php
2
+
3
+ class Allopass_Hipay_Block_Adminhtml_Field_Renderer_Label extends Mage_Core_Block_Text
4
+ {
5
+ /**
6
+ * Simple block to display just label with hidden input
7
+ *
8
+ * @return string
9
+ */
10
+ protected function _toHtml()
11
+ {
12
+ $html = '<div style="width: 300px;" class="#{class}">';
13
+ $html .= '<input type="text" value="#{magento_code}" name="' . $this->inputName . '" style="visibility: hidden;width: 0px ;height: 0px">';
14
+ $html .= '#{magento_label}';
15
+ $html .= '</div>';
16
+ return $html;
17
+ }
18
+ }
app/code/community/Allopass/Hipay/Block/Adminhtml/Field/Renderer/List.php ADDED
@@ -0,0 +1,44 @@
1
+ <?php
2
+
3
+ class Allopass_Hipay_Block_Adminhtml_Field_Renderer_List extends Mage_Core_Block_Html_Select
4
+ {
5
+ /**
6
+ * Original data source
7
+ *
8
+ * @var array
9
+ */
10
+ protected $_listOptions;
11
+
12
+ /**
13
+ * Return block List with prepared select
14
+ *
15
+ * @return string
16
+ */
17
+ public function _toHtml()
18
+ {
19
+ $this->setName($this->inputName);
20
+
21
+ switch ($this->column_name){
22
+ case "hipay_category":
23
+ $defaultValue = Mage::helper('hipay')->__('- Please select one category - ');
24
+ break;
25
+ case "hipay_delivery_method":
26
+ $defaultValue = Mage::helper('hipay')->__('- Please select one delivery method - ');
27
+ break;
28
+ }
29
+ $this->addOption('', $defaultValue);
30
+ foreach ($this->_listOptions as $key => $value) {
31
+ $this->addOption($key, $value);
32
+ }
33
+ return parent::_toHtml();
34
+ }
35
+
36
+ /**
37
+ * Init initial list of options
38
+ *
39
+ * @param $options
40
+ */
41
+ public function setListOptions($options){
42
+ $this->_listOptions = $options;
43
+ }
44
+ }
app/code/community/Allopass/Hipay/Block/Adminhtml/System/Config/Form/Field/Expanded.php ADDED
@@ -0,0 +1,23 @@
1
+ <?php
2
+ /**
3
+ * Class Allopass_Hipay_Block_Adminhtml_System_Config_Form_Field_Expanded
4
+ */
5
+ class Allopass_Hipay_Block_Adminhtml_System_Config_Form_Field_Expanded
6
+ extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
7
+ {
8
+ /**
9
+ * Return collapse state
10
+ *
11
+ * @param Varien_Data_Form_Element_Abstract $element
12
+ * @return bool
13
+ */
14
+ protected function _getCollapseState($element)
15
+ {
16
+ $extra = Mage::getSingleton('admin/session')->getUser()->getExtra();
17
+ if (isset($extra['configState'][$element->getId()])) {
18
+ return $extra['configState'][$element->getId()];
19
+ }
20
+
21
+ return true;
22
+ }
23
+ }
app/code/community/Allopass/Hipay/Block/Adminhtml/System/Config/Form/Field/Information.php ADDED
@@ -0,0 +1,34 @@
1
+ <?php
2
+
3
+ /**
4
+ * Class Allopass_Hipay_Block_Adminhtml_System_Config_Form_Field_Notice
5
+ */
6
+ class Allopass_Hipay_Block_Adminhtml_System_Config_Form_Field_Information extends Mage_Adminhtml_Block_System_Config_Form_Field
7
+ {
8
+
9
+ /**
10
+ * Check if columns are defined, set template
11
+ *
12
+ */
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+
17
+ if (!$this->getTemplate()) {
18
+ $this->setTemplate('hipay/system/config/form/field/information.phtml');
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Custom field
24
+ *
25
+ * @param Varien_Data_Form_Element_Abstract $element
26
+ * @return string
27
+ */
28
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
29
+ {
30
+ $element->setInformationsHipay($element->getData('tooltip'));
31
+ $this->setElement($element);
32
+ return $this->_toHtml();
33
+ }
34
+ }
app/code/community/Allopass/Hipay/Block/Adminhtml/System/Config/Form/Field/Notice.php CHANGED
@@ -5,35 +5,52 @@
5
*/
6
class Allopass_Hipay_Block_Adminhtml_System_Config_Form_Field_Notice extends Mage_Adminhtml_Block_System_Config_Form_Field
7
{
8
-
9
- /**
10
- * Check if columns are defined, set template
11
- *
12
- */
13
- public function __construct()
14
- {
15
- parent::__construct();
16
17
- if (!$this->getTemplate()) {
18
- $this->setTemplate('hipay/system/config/form/field/notice.phtml');
19
- }
20
- }
21
22
- /**
23
- * Custom field
24
- *
25
- * @param Varien_Data_Form_Element_Abstract $element
26
- * @return string
27
- */
28
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
29
- {
30
- $notices = array();
31
- if (!Mage::getStoreConfigFlag('hipay/hipay_basket/activate_basket', Mage::app()->getStore())) {
32
- $notices[] = Mage::helper('adminhtml')->__('You have to activate and configuring the support of basket before activate the payment method klarna.');
33
}
34
35
$element->setNoticesHipay($notices);
36
- $this->setElement($element);
37
- return $this->_toHtml();
38
- }
39
}
5
*/
6
class Allopass_Hipay_Block_Adminhtml_System_Config_Form_Field_Notice extends Mage_Adminhtml_Block_System_Config_Form_Field
7
{
8
9
+ /**
10
+ * Set template
11
+ *
12
+ */
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+ if (!$this->getTemplate()) {
17
+ $this->setTemplate('hipay/system/config/form/field/notice.phtml');
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Custom field
23
+ *
24
+ * @param Varien_Data_Form_Element_Abstract $element
25
+ * @return string
26
+ */
27
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
28
+ {
29
+ $notices = array();
30
+ $commonWarning = Mage::helper('hipay')->__('All mappings are not filled in, please check the information you entered.
31
+ If the mappings are not filled in, then Oney transactions will be denied.');
32
+
33
+ // Notice for block Mapping shipping method
34
+ if (preg_match('/mapping_shipping_method/', $element->getId())){
35
+ $nbMappingMissing = Mage::helper('hipay')->checkMappingShippingMethod();
36
+ if ($nbMappingMissing > 0) {
37
+ $notices[] = $commonWarning . '<div class="nb-mapping-missing">
38
+ ' . $nbMappingMissing . ' '. Mage::helper('hipay')->__('mappings delivery method are actually missing.') .'</div>';
39
+
40
+ }
41
+ }
42
43
+ // Notice for block Category
44
+ if (preg_match('/mapping_category/', $element->getId())){
45
+ $nbMappingMissing = Mage::helper('hipay')->checkMappingCategoryMethod();
46
+ if ($nbMappingMissing > 0) {
47
+ $notices[] = $commonWarning . '<div class="nb-mapping-missing">
48
+ ' . $nbMappingMissing . ' '. Mage::helper('hipay')->__('mappings categories are actually missing.') . '</div>';
49
+ }
50
}
51
52
$element->setNoticesHipay($notices);
53
+ $this->setElement($element);
54
+ return $this->_toHtml();
55
+ }
56
}
app/code/community/Allopass/Hipay/Block/Form/Abstract.php CHANGED
@@ -161,4 +161,13 @@ abstract class Allopass_Hipay_Block_Form_Abstract extends Mage_Payment_Block_For
161
));
162
return parent::_toHtml();
163
}
164
}
161
));
162
return parent::_toHtml();
163
}
164
+
165
+ /**
166
+ * Return the type for national identification number to BLOCK
167
+ * @return string
168
+ */
169
+ public function getTypeNationalIdentification()
170
+ {
171
+ return $this->getMethod()->getTypeNationalIdentification();
172
+ }
173
}
app/code/community/Allopass/Hipay/Helper/Collection.php ADDED
@@ -0,0 +1,308 @@
1
+ <?php
2
+
3
+ class Allopass_Hipay_Helper_Collection extends Mage_Core_Helper_Abstract
4
+ {
5
+ /**
6
+ *
7
+ * @var string $_JSON Json collection
8
+ */
9
+ private static $_JSON_CATEGORY = <<<EOT
10
+
11
+ [
12
+ {
13
+ "categoryCode":1,
14
+ "categoryName":"Home & Gardening"
15
+ },
16
+ {
17
+ "categoryCode":2,
18
+ "categoryName":"Clothing & Accessories"
19
+ },
20
+ {
21
+ "categoryCode":3,
22
+ "categoryName":"Home appliances"
23
+ },
24
+ {
25
+ "categoryCode":4,
26
+ "categoryName":"Sports & Recreations"
27
+ },
28
+ {
29
+ "categoryCode":5,
30
+ "categoryName":"Babies & Children"
31
+ },
32
+ {
33
+ "categoryCode":6,
34
+ "categoryName":"Hi-Fi, Photo & Video equipment"
35
+ },
36
+ {
37
+ "categoryCode":7,
38
+ "categoryName":"IT equipment"
39
+ },
40
+ {
41
+ "categoryCode":8,
42
+ "categoryName":"Phone & Internet services"
43
+ },
44
+ {
45
+ "categoryCode":9,
46
+ "categoryName":"Physical goods : Books, Media, Music & Movies"
47
+ },
48
+ {
49
+ "categoryCode":10,
50
+ "categoryName":"Digital goods : Books, Media, Music & Movies"
51
+ },
52
+ {
53
+ "categoryCode":11,
54
+ "categoryName":"Consoles & Video games"
55
+ },
56
+ {
57
+ "categoryCode":12,
58
+ "categoryName":"Gifts & Flowers"
59
+ },
60
+ {
61
+ "categoryCode":13,
62
+ "categoryName":"Health & Beauty"
63
+ },
64
+ {
65
+ "categoryCode":14,
66
+ "categoryName":"Car & Motorcycle"
67
+ },
68
+ {
69
+ "categoryCode":15,
70
+ "categoryName":"Traveling"
71
+ },
72
+ {
73
+ "categoryCode":16,
74
+ "categoryName":"Food & Gastronomy"
75
+ },
76
+ {
77
+ "categoryCode":17,
78
+ "categoryName":"Auctions & Group buying"
79
+ },
80
+ {
81
+ "categoryCode":18,
82
+ "categoryName":"Services to professionals"
83
+ },
84
+ {
85
+ "categoryCode":19,
86
+ "categoryName":"Services to individuals"
87
+ },
88
+ {
89
+ "categoryCode":20,
90
+ "categoryName":"Culture & Entertainment"
91
+ },
92
+ {
93
+ "categoryCode":21,
94
+ "categoryName":"Games (digital goods)"
95
+ },
96
+ {
97
+ "categoryCode":22,
98
+ "categoryName":"Games (physical goods)"
99
+ },
100
+ {
101
+ "categoryCode":23,
102
+ "categoryName":"Ticketing"
103
+ },
104
+ {
105
+ "categoryCode":24,
106
+ "categoryName":"Opticians, Opticians Goods and Eyeglasses"
107
+ }
108
+ ]
109
+
110
+ EOT;
111
+
112
+ /**
113
+ * JSON OBJECT for delivery method
114
+ *
115
+ * @var string $_JSON Json collection
116
+ */
117
+ private static $_JSON_DELIVERY = <<<EOT
118
+
119
+ [
120
+ {
121
+ "code":1,
122
+ "mode":"STORE",
123
+ "shipping":"STANDARD"
124
+ },
125
+ {
126
+ "code":2,
127
+ "mode":"STORE",
128
+ "shipping":"EXPRESS"
129
+ },
130
+ {
131
+ "code":3,
132
+ "mode":"STORE",
133
+ "shipping":"PRIORITY24H"
134
+ },
135
+ {
136
+ "code":4,
137
+ "mode":"STORE",
138
+ "shipping":"PRIORITY2H"
139
+ },
140
+ {
141
+ "code":5,
142
+ "mode":"STORE",
143
+ "shipping":"PRIORITY1H"
144
+ },
145
+ {
146
+ "code":6,
147
+ "mode":"STORE",
148
+ "shipping":"INSTANT"
149
+ },
150
+ {
151
+ "code":7,
152
+ "mode":"CARRIER",
153
+ "shipping":"STANDARD"
154
+ },
155
+ {
156
+ "code":8,
157
+ "mode":"CARRIER",
158
+ "shipping":"EXPRESS"
159
+ },
160
+ {
161
+ "code":9,
162
+ "mode":"CARRIER",
163
+ "shipping":"PRIORITY24H"
164
+ },
165
+ {
166
+ "code":10,
167
+ "mode":"CARRIER",
168
+ "shipping":"PRIORITY2H"
169
+ },
170
+ {
171
+ "code":11,
172
+ "mode":"STORE",
173
+ "shipping":"PRIORITY1H"
174
+ },
175
+ {
176
+ "code":12,
177
+ "mode":"CARRIER",
178
+ "shipping":"INSTANT"
179
+ },
180
+ {
181
+ "code":13,
182
+ "mode":"RELAYPOINT",
183
+ "shipping":"STANDARD"
184
+ },
185
+ {
186
+ "code":14,
187
+ "mode":"RELAYPOINT",
188
+ "shipping":"EXPRESS"
189
+ },
190
+ {
191
+ "code":15,
192
+ "mode":"RELAYPOINT",
193
+ "shipping":"PRIORITY24H"
194
+ },
195
+ {
196
+ "code":16,
197
+ "mode":"RELAYPOINT",
198
+ "shipping":"PRIORITY2H"
199
+ },
200
+ {
201
+ "code":17,
202
+ "mode":"RELAYPOINT",
203
+ "shipping":"PRIORITY1H"
204
+ },
205
+ {
206
+ "code":18,
207
+ "mode":"RELAYPOINT",
208
+ "shipping":"INSTANT"
209
+ },
210
+ {
211
+ "code":19,
212
+ "mode":"ELECTRONIC",
213
+ "shipping":"STANDARD"
214
+ },
215
+ {
216
+ "code":20,
217
+ "mode":"ELECTRONIC",
218
+ "shipping":"EXPRESS"
219
+ },
220
+ {
221
+ "code":21,
222
+ "mode":"ELECTRONIC",
223
+ "shipping":"PRIORITY24H"
224
+ },
225
+ {
226
+ "code":22,
227
+ "mode":"ELECTRONIC",
228
+ "shipping":"PRIORITY2H"
229
+ },
230
+ {
231
+ "code":23,
232
+ "mode":"ELECTRONIC",
233
+ "shipping":"PRIORITY1H"
234
+ },
235
+ {
236
+ "code":24,
237
+ "mode":"ELECTRONIC",
238
+ "shipping":"INSTANT"
239
+ },
240
+ {
241
+ "code":25,
242
+ "mode":"TRAVEL",
243
+ "shipping":"STANDARD"
244
+ },
245
+ {
246
+ "code":26,
247
+ "mode":"TRAVEL",
248
+ "shipping":"EXPRESS"
249
+ },
250
+ {
251
+ "code":27,
252
+ "mode":"TRAVEL",
253
+ "shipping":"PRIORITY24H"
254
+ },
255
+ {
256
+ "code":28,
257
+ "mode":"TRAVEL",
258
+ "shipping":"PRIORITY1H"
259
+ },
260
+ {
261
+ "code":29,
262
+ "mode":"TRAVEL",
263
+ "shipping":"INSTANT"
264
+ }
265
+ ]
266
+
267
+ EOT;
268
+ /**
269
+ * Return HiPay's Category
270
+ *
271
+ * @return array
272
+ */
273
+ public function getItemsCategory()
274
+ {
275
+ $jsonArr = json_decode(self::$_JSON_CATEGORY, true);
276
+ $collection = array();
277
+ foreach ($jsonArr as $item) {
278
+ $collection[$item['categoryCode']] = $item['categoryName'];
279
+ }
280
+ return $collection;
281
+ }
282
+
283
+ /**
284
+ * Return HiPay's delivery method Full json
285
+ *
286
+ * @return array
287
+ */
288
+ public static function getFullItemsDelivery()
289
+ {
290
+ return json_decode(self::$_JSON_DELIVERY, true);
291
+ }
292
+
293
+ /**
294
+ * Return HiPay's delivery method for listing
295
+ *
296
+ * @return array
297
+ */
298
+ public static function getItemsDelivery()
299
+ {
300
+ $jsonArr = json_decode(self::$_JSON_DELIVERY, true);
301
+ $collection = array();
302
+ foreach ($jsonArr as $item) {
303
+ $collection[$item['code']] = $item['mode'] . '-' . $item['shipping'];
304
+ }
305
+ return $collection;
306
+ }
307
+
308
+ }
app/code/community/Allopass/Hipay/Helper/Data.php CHANGED
@@ -26,6 +26,11 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
26
const STATE_AUTHORIZATION = '0';
27
const STATE_REFUND = '1';
28
const STATE_CAPTURE = '2';
29
30
/**
31
* Return to TPP Tax rate only if all products have the same tax
@@ -84,7 +89,7 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
84
* @param $capture
85
* @return array
86
*/
87
- private function processDiscount($order,$action, $basket)
88
{
89
$coupon = $order->getCouponCode();
90
if (!empty($coupon)) {
@@ -96,6 +101,7 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
96
$item['total_amount'] = 0;
97
$item['quantity'] = '1';
98
$item['unit_price'] = '0';
99
$basket[] = $item;
100
}
101
@@ -110,35 +116,36 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
110
* @param $capture
111
* @return array
112
*/
113
- private function processShipping($order, $action,$basket)
114
{
115
- if ($order->getBaseShippingAmount() > 0) {
116
- $useOrderCurrency = Mage::getStoreConfig('hipay/hipay_api/currency_transaction', Mage::app()->getStore());
117
-
118
- $item = array();
119
- $item['type'] = Allopass_Hipay_Helper_Data::TYPE_ITEM_BASKET_FEE;
120
- $item['product_reference'] = $order->getShippingDescription();
121
- $item['name'] = $order->getShippingDescription();
122
- $item['quantity'] = '1';
123
124
- if (!$useOrderCurrency){
125
- $item['unit_price'] =round( $order->getBaseShippingAmount(),3);
126
- $item['total_amount'] = round($order->getBaseShippingAmount(),3);
127
- $item['tax_rate'] = round($order->getBaseShippingTaxAmount() / $order->getBaseShippingAmount() * 100 ,2);
128
- }else{
129
- $item['unit_price'] =round( $order->getShippingAmount(),3);
130
- $item['total_amount'] = round($order->getShippingAmount(),3);
131
- $item['tax_rate'] = round($order->getShippingTaxAmount() / $order->getShippingAmount() * 100 ,2);
132
- }
133
134
- if ($action == Allopass_Hipay_Helper_Data::STATE_CAPTURE || $action == Allopass_Hipay_Helper_Data::STATE_REFUND){
135
- $item['product_reference'] = $order->getOrder()->getShippingDescription();
136
- $item['name'] = $order->getOrder()->getShippingDescription();
137
- }
138
139
- $basket[] = $item;
140
}
141
142
return $basket;
143
}
144
@@ -148,12 +155,13 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
148
*@param $product
149
*@param $quantity
150
*/
151
- private function returnUnitPrice($product,$quantity){
152
$useOrderCurrency = Mage::getStoreConfig('hipay/hipay_api/currency_transaction', Mage::app()->getStore());
153
154
if (!$useOrderCurrency) {
155
return $product->getBasePrice() + $product->getBaseTaxAmount() / $quantity;
156
- }else{
157
return $product->getPrice() + $product->getTaxAmount() / $quantity;
158
}
159
}
@@ -165,14 +173,14 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
165
* @param $product
166
* @param @action
167
*/
168
- private function addItem($product, $action,$products)
169
{
170
$item = array();
171
$useOrderCurrency = Mage::getStoreConfig('hipay/hipay_api/currency_transaction', Mage::app()->getStore());
172
173
// Select base Field according the action
174
- switch ($action)
175
- {
176
case Allopass_Hipay_Helper_Data::STATE_REFUND:
177
$base_discount = Allopass_Hipay_Helper_Data::FIELD_BASE_DISCOUNT_REFUNDED;
178
$base_hidden_tax = Allopass_Hipay_Helper_Data::FIELD_BASE_TAX_HIDDEN_REFUNDED;
@@ -192,32 +200,28 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
192
$taxPercent = $product->getData('tax_percent');
193
194
if (!$useOrderCurrency) {
195
- $hidden_tax = $product->getData('base_'+ $base_hidden_tax);
196
- $discount = $product->getData('base_'+ $base_discount);
197
$total_amount = $product->getBaseRowTotal() + $product->getBaseTaxAmount() + $product->getBaseHiddenTaxAmount() + Mage::helper('weee')->getRowWeeeAmountAfterDiscount($product) - $product->getBaseDiscountAmount();
198
- }else{
199
- $hidden_tax = $product->getData($base_hidden_tax);
200
- $discount = $product->getData($base_discount);
201
$total_amount = $product->getRowTotal() + $product->getTaxAmount() + $product->getHiddenTaxAmount() + Mage::helper('weee')->getRowWeeeAmountAfterDiscount($product) - $product->getDiscountAmount();
202
}
203
// Add information in basket only if the product is simple
204
- if ($item['quantity'] > 0 && $total_amount > 0 ) {
205
- if ($action == Allopass_Hipay_Helper_Data::STATE_CAPTURE || $action == Allopass_Hipay_Helper_Data::STATE_REFUND){
206
// To avoid 0.001 between original authorization and capture
207
foreach ($products as $key => $original) {
208
- if ($product->getSku() == $original->getSku()){
209
if ($original->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $original->isChildrenCalculated()) {
210
foreach ($original->getChildren() as $children) {
211
- $unitPrice = $this->returnUnitPrice($children,$item);
212
}
213
} else {
214
- $unitPrice = $this->returnUnitPrice($original,$original->getData('qty_ordered'));
215
}
216
}
217
}
218
- }else{
219
// Don't use unit price in product because we need a better precision
220
- $unitPrice = $this->returnUnitPrice($product,$item['quantity']);
221
}
222
223
// if store support EAN ( Please set the attribute on hipay config )
@@ -225,7 +229,6 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
225
$attribute = Mage::getStoreConfig('hipay/hipay_basket/attribute_ean', Mage::app()->getStore());
226
227
if (Mage::getStoreConfig('hipay/hipay_basket/load_product_ean', Mage::app()->getStore())) {
228
- $resource = Mage::getSingleton('catalog/product')->getResource();
229
$ean = $resource->getAttributeRawValue($product->getProductId(), $attribute,
230
Mage::app()->getStore());
231
} else {
@@ -248,11 +251,26 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
248
// According the configuration we use this trick to complete the discount with tax hidden
249
$item['discount'] = round($total_amount - ($unitPrice * $item['quantity']), 3);
250
251
return $item;
252
}
253
254
255
}
256
/**
257
* Return to TPP API basket informations
258
*
@@ -261,8 +279,11 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
261
* @return json
262
*
263
*/
264
- public function getCartInformation($order,$action = Allopass_Hipay_Helper_Data::STATE_AUTHORIZATION,$payment = null)
265
- {
266
$basket = array();
267
$products = $order->getAllVisibleItems();
268
@@ -270,10 +291,9 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
270
// Add each product in basket
271
// =============================================================== //
272
if ($action == Allopass_Hipay_Helper_Data::STATE_AUTHORIZATION) {
273
274
- $basket = $this->processDiscount($order, $action,$basket);
275
-
276
- $basket = $this->processShipping($order, $action,$basket);
277
278
foreach ($products as $key => $product) {
279
if ($product->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
@@ -298,11 +318,11 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
298
// =============================================================== //
299
// Add Shipping in basket
300
// =============================================================== //
301
- $basket = $this->processShipping($invoice, $action,$basket);
302
303
foreach ($invoice->getAllItems() as $product) {
304
- $item = $this->addItem($product, $action,$products);
305
- if ($item){
306
$basket[] = $item;
307
}
308
}
@@ -316,10 +336,10 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
316
// =============================================================== //
317
// Add Shipping in basket
318
// =============================================================== //
319
- $basket = $this->processShipping($creditMemo, $action,$basket);
320
321
foreach ($creditMemo->getAllItems() as $product) {
322
- $item = $this->addItem($product, $action,$products);
323
if ($item) {
324
$basket[] = $item;
325
}
@@ -455,7 +475,7 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
455
);
456
457
// First split is already paid
458
- if ($numberSplit == 1){
459
$data['status'] = Allopass_Hipay_Model_SplitPayment::SPLIT_PAYMENT_STATUS_COMPLETE;
460
}
461
@@ -489,21 +509,6 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
489
return false;
490
}
491
492
- public function getHipayMethods()
493
- {
494
- $methods = array();
495
-
496
- foreach (Mage::getStoreConfig('payment') as $code => $data) {
497
- if (strpos($code, 'hipay') !== false) {
498
- if (isset($data['model'])) {
499
- $methods[$code] = $data['model'];
500
- }
501
- }
502
- }
503
-
504
- return $methods;
505
- }
506
-
507
public function checkSignature(
508
$signature,
509
$fromNotification = false,
@@ -554,6 +559,21 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
554
return false;
555
}
556
557
public function checkIfCcExpDateIsValid(
558
$customer
559
) {
@@ -823,7 +843,7 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
823
824
/**
825
* Send email id payment is in Fraud status
826
- * @param Mage_Customer_Model_Customer $receiver
827
* @param Mage_Sales_Model_Order $order
828
* @param string $message
829
* @return Mage_Checkout_Helper_Data
@@ -1143,4 +1163,260 @@ class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
1143
1144
return $this;
1145
}
1146
}
26
const STATE_AUTHORIZATION = '0';
27
const STATE_REFUND = '1';
28
const STATE_CAPTURE = '2';
29
+ const EPSYLON = 0.00001;
30
+
31
+ const DEFAULT_CATEGORY_CODE = 1 ;
32
+
33
+ const LOG_INTERNAL_HIPAY = 'hipay_general_debug';
34
35
/**
36
* Return to TPP Tax rate only if all products have the same tax
89
* @param $capture
90
* @return array
91
*/
92
+ private function processDiscount($order, $action, $basket)
93
{
94
$coupon = $order->getCouponCode();
95
if (!empty($coupon)) {
101
$item['total_amount'] = 0;
102
$item['quantity'] = '1';
103
$item['unit_price'] = '0';
104
+ $item['product_category'] = self::DEFAULT_CATEGORY_CODE;
105
$basket[] = $item;
106
}
107
116
* @param $capture
117
* @return array
118
*/
119
+ private function processShipping($order, $action, $basket)
120
{
121
+ $useOrderCurrency = Mage::getStoreConfig('hipay/hipay_api/currency_transaction', Mage::app()->getStore());
122
123
+ $item = array();
124
+ $item['type'] = Allopass_Hipay_Helper_Data::TYPE_ITEM_BASKET_FEE;
125
+ $item['product_reference'] = $order->getShippingDescription();
126
+ $item['name'] = $order->getShippingDescription();
127
+ $item['quantity'] = '1';
128
129
+ if (!$useOrderCurrency) {
130
+ $item['unit_price'] = round($order->getBaseShippingAmount(), 3);
131
+ $item['total_amount'] = round($order->getBaseShippingAmount(), 3);
132
+ $item['tax_rate'] = round($order->getBaseShippingTaxAmount() / $order->getBaseShippingAmount() * 100,
133
+ 2);
134
+ } else {
135
+ $item['unit_price'] = round($order->getShippingAmount(), 3);
136
+ $item['total_amount'] = round($order->getShippingAmount(), 3);
137
+ $item['tax_rate'] = round($order->getShippingTaxAmount() / $order->getShippingAmount() * 100, 2);
138
+ }
139
140
+ if ($action == Allopass_Hipay_Helper_Data::STATE_CAPTURE || $action == Allopass_Hipay_Helper_Data::STATE_REFUND) {
141
+ $item['product_reference'] = $order->getOrder()->getShippingDescription();
142
+ $item['name'] = $order->getOrder()->getShippingDescription();
143
}
144
145
+ $item['product_category'] = self::DEFAULT_CATEGORY_CODE;
146
+ $basket[] = $item;
147
+
148
+
149
return $basket;
150
}
151
155
*@param $product
156
*@param $quantity
157
*/
158
+ private function returnUnitPrice($product, $quantity)
159
+ {
160
$useOrderCurrency = Mage::getStoreConfig('hipay/hipay_api/currency_transaction', Mage::app()->getStore());
161
162
if (!$useOrderCurrency) {
163
return $product->getBasePrice() + $product->getBaseTaxAmount() / $quantity;
164
+ } else {
165
return $product->getPrice() + $product->getTaxAmount() / $quantity;
166
}
167
}
173
* @param $product
174
* @param @action
175
*/
176
+ private function addItem($product, $action, $products = null)
177
{
178
$item = array();
179
$useOrderCurrency = Mage::getStoreConfig('hipay/hipay_api/currency_transaction', Mage::app()->getStore());
180
+ $resource = Mage::getSingleton('catalog/product')->getResource();
181
182
// Select base Field according the action
183
+ switch ($action) {
184
case Allopass_Hipay_Helper_Data::STATE_REFUND:
185
$base_discount = Allopass_Hipay_Helper_Data::FIELD_BASE_DISCOUNT_REFUNDED;
186
$base_hidden_tax = Allopass_Hipay_Helper_Data::FIELD_BASE_TAX_HIDDEN_REFUNDED;
200
$taxPercent = $product->getData('tax_percent');
201
202
if (!$useOrderCurrency) {
203
$total_amount = $product->getBaseRowTotal() + $product->getBaseTaxAmount() + $product->getBaseHiddenTaxAmount() + Mage::helper('weee')->getRowWeeeAmountAfterDiscount($product) - $product->getBaseDiscountAmount();
204
+ } else {
205
$total_amount = $product->getRowTotal() + $product->getTaxAmount() + $product->getHiddenTaxAmount() + Mage::helper('weee')->getRowWeeeAmountAfterDiscount($product) - $product->getDiscountAmount();
206
}
207
// Add information in basket only if the product is simple
208
+ if ($item['quantity'] > 0 && $total_amount > 0) {
209
+ if ($action == Allopass_Hipay_Helper_Data::STATE_CAPTURE || $action == Allopass_Hipay_Helper_Data::STATE_REFUND) {
210
// To avoid 0.001 between original authorization and capture
211
foreach ($products as $key => $original) {
212
+ if ($product->getSku() == $original->getSku()) {
213
if ($original->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $original->isChildrenCalculated()) {
214
foreach ($original->getChildren() as $children) {
215
+ $unitPrice = $this->returnUnitPrice($children, $item);
216
}
217
} else {
218
+ $unitPrice = $this->returnUnitPrice($original, $original->getData('qty_ordered'));
219
}
220
}
221
}
222
+ } else {
223
// Don't use unit price in product because we need a better precision
224
+ $unitPrice = $this->returnUnitPrice($product, $item['quantity']);
225
}
226
227
// if store support EAN ( Please set the attribute on hipay config )
229
$attribute = Mage::getStoreConfig('hipay/hipay_basket/attribute_ean', Mage::app()->getStore());
230
231
if (Mage::getStoreConfig('hipay/hipay_basket/load_product_ean', Mage::app()->getStore())) {
232
$ean = $resource->getAttributeRawValue($product->getProductId(), $attribute,
233
Mage::app()->getStore());
234
} else {
251
// According the configuration we use this trick to complete the discount with tax hidden
252
$item['discount'] = round($total_amount - ($unitPrice * $item['quantity']), 3);
253
254
+ // Process an product load if needed
255
+ $product = Mage::getModel('catalog/product')->load($product->getProductId());
256
+
257
+ // Load Mapping Category
258
+ $categoryIds = $product->getCategoryIds();
259
+ if (is_array($categoryIds) && !empty($categoryIds)) {
260
+ if (isset($categoryIds[0]) && $categoryIds[0]) {
261
+ $mapping = $this->getMappingCategory($categoryIds[0],Mage::app()->getStore());
262
+ if ($mapping){
263
+ $item['product_category'] = (int) $mapping['hipay_category'];
264
+ }
265
+ }
266
+ }
267
+
268
return $item;
269
}
270
271
272
}
273
+
274
/**
275
* Return to TPP API basket informations
276
*
279
* @return json
280
*
281
*/
282
+ public function getCartInformation(
283
+ $order,
284
+ $action = Allopass_Hipay_Helper_Data::STATE_AUTHORIZATION,
285
+ $payment = null
286
+ ) {
287
$basket = array();
288
$products = $order->getAllVisibleItems();
289
291
// Add each product in basket
292
// =============================================================== //
293
if ($action == Allopass_Hipay_Helper_Data::STATE_AUTHORIZATION) {
294
+ $basket = $this->processDiscount($order, $action, $basket);
295
296
+ $basket = $this->processShipping($order, $action, $basket);
297
298
foreach ($products as $key => $product) {
299
if ($product->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
318
// =============================================================== //
319
// Add Shipping in basket
320
// =============================================================== //
321
+ $basket = $this->processShipping($invoice, $action, $basket);
322
323
foreach ($invoice->getAllItems() as $product) {
324
+ $item = $this->addItem($product, $action, $products);
325
+ if ($item) {
326
$basket[] = $item;
327
}
328
}
336
// =============================================================== //
337
// Add Shipping in basket
338
// =============================================================== //
339
+ $basket = $this->processShipping($creditMemo, $action, $basket);
340
341
foreach ($creditMemo->getAllItems() as $product) {
342
+ $item = $this->addItem($product, $action, $products);
343
if ($item) {
344
$basket[] = $item;
345
}
475
);
476
477
// First split is already paid
478
+ if ($numberSplit == 1) {
479
$data['status'] = Allopass_Hipay_Model_SplitPayment::SPLIT_PAYMENT_STATUS_COMPLETE;
480
}
481
509
return false;
510
}
511
512
public function checkSignature(
513
$signature,
514
$fromNotification = false,
559
return false;
560
}
561
562
+ public function getHipayMethods()
563
+ {
564
+ $methods = array();
565
+
566
+ foreach (Mage::getStoreConfig('payment') as $code => $data) {
567
+ if (strpos($code, 'hipay') !== false) {
568
+ if (isset($data['model'])) {
569
+ $methods[$code] = $data['model'];
570
+ }
571
+ }
572
+ }
573
+
574
+ return $methods;
575
+ }
576
+
577
public function checkIfCcExpDateIsValid(
578
$customer
579
) {
843
844
/**
845
* Send email id payment is in Fraud status
846
+ * @param Mage_Customer_Model_Customer|Mage_Core_Model_Abstract $receiver
847
* @param Mage_Sales_Model_Order $order
848
* @param string $message
849
* @return Mage_Checkout_Helper_Data
1163
1164
return $this;
1165
}
1166
+
1167
+ /**
1168
+ * Debug internal process ( For cron per exemple )
1169
+ *
1170
+ * @param $debugData
1171
+ */
1172
+ public function debugInternalProcessHipay($debugData) {
1173
+ if ($this->getConfig()->isGeneralDebugEnabled()) {
1174
+ Mage::getModel('hipay/log_adapter', self::LOG_INTERNAL_HIPAY . '.log')->log($debugData);
1175
+ }
1176
+ }
1177
+
1178
+ /**
1179
+ * Get All Magento Categories (Level 2)
1180
+ *
1181
+ * If Store ID in context, get Category from root ID
1182
+ *
1183
+ * @return array
1184
+ */
1185
+ public function getMagentoCategories()
1186
+ {
1187
+ $options = array();
1188
+ $storeId = Mage::getSingleton('adminhtml/config_data')->getStore();
1189
+ $categories = Mage::getModel('catalog/category')
1190
+ ->getCollection()
1191
+ ->addAttributeToFilter('level', 2)
1192
+ ->addAttributeToSelect('name')
1193
+ ->addAttributeToSelect('id');
1194
+
1195
+ if ($storeId && !empty($storeId)) {
1196
+ $rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
1197
+ $categories = $categories->addAttributeToFilter('path', array('like' => "1/$rootCategoryId/%"));
1198
+ }
1199
+
1200
+ foreach ($categories as $category) {
1201
+ $options[$category->getId()] = $category->getName();
1202
+ }
1203
+
1204
+ return $options;
1205
+ }
1206
+
1207
+ /**
1208
+ * Get All Magento Shipping method
1209
+ *
1210
+ * According current store
1211
+ *
1212
+ * @return array
1213
+ */
1214
+ public function getMagentoShippingMethods()
1215
+ {
1216
+ $options = array();
1217
+ $store = Mage::getSingleton('adminhtml/config_data')->getStore();
1218
+
1219
+ // Get all carriers
1220
+ $carriers = Mage::getSingleton('shipping/config')->getAllCarriers($store);
1221
+ foreach ($carriers as $carrierCode => $carrierModel) {
1222
+ try {
1223
+ if (!$carrierModel->isActive()) {
1224
+ continue;
1225
+ }
1226
+
1227
+ $carrierMethods = $carrierModel->getAllowedMethods();
1228
+ if (!$carrierMethods) {
1229
+ continue;
1230
+ }
1231
+
1232
+ $carrierTitle = Mage::getStoreConfig('carriers/' . $carrierCode . '/title');
1233
+ foreach ($carrierMethods as $methodCode => $methodTitle) {
1234
+ $options[$carrierCode . '_' . $methodCode] = '[' . $carrierTitle . '] - ' . $methodTitle;
1235
+ }
1236
+ } catch (Exception $e) {
1237
+ // Log error and continue process listing
1238
+ continue;
1239
+ }
1240
+ }
1241
+ return $options;
1242
+ }
1243
+
1244
+ /**
1245
+ * Return the mapping if exists for one category
1246
+ *
1247
+ * @param $idCategory
1248
+ * @param $store
1249
+ * @return string
1250
+ */
1251
+ public function getMappingCategory($idCategory, $store = null)
1252
+ {
1253
+ $mappingCategories = unserialize($this->getConfig()->getConfigDataBasket('mapping_category',$store));
1254
+ if (is_array($mappingCategories) && !empty($mappingCategories)) {
1255
+ foreach ($mappingCategories as $key => $mapping) {
1256
+ if ($mapping['magento_category'] == $idCategory) {
1257
+ return $mapping['hipay_category'];
1258
+ }
1259
+ }
1260
+ $category = Mage::getModel('catalog/category')->load($idCategory);
1261
+ foreach ($mappingCategories as $key => $mapping ) {
1262
+ if (in_array($mapping['hipay_category'],$category->getParentIds())) {
1263
+ return $mapping;
1264
+ }
1265
+ }
1266
+ }
1267
+ return null;
1268
+ }
1269
+
1270
+ /**
1271
+ * Return the mapping if exist for one category
1272
+ *
1273
+ * @param $delivery_method Code
1274
+ * @param $store
1275
+ * @return string
1276
+ */
1277
+ public function getMappingShipping($codeShippingMethod, $store = null)
1278
+ {
1279
+ $mappingDeliveryMethod = unserialize($this->getConfig()->getConfigDataBasket('mapping_shipping_method',$store));
1280
+ if (is_array($mappingDeliveryMethod) && !empty($mappingDeliveryMethod)) {
1281
+ foreach ($mappingDeliveryMethod as $key => $mapping) {
1282
+ if ($mapping['magento_shipping_method'] == $codeShippingMethod) {
1283
+ return $mapping;
1284
+ }
1285
+ }
1286
+ }
1287
+ return null;
1288
+ }
1289
+
1290
+ /**
1291
+ * According the mapping, provide a approximated date delivery
1292
+ *
1293
+ * @return date format YYYY-MM-DD
1294
+ */
1295
+ function calculateEstimatedDate($mapping){
1296
+ if (is_array($mapping)){
1297
+ $today = new \Datetime();
1298
+ $daysDelay = $mapping['delay_preparation'] + $mapping['delay_delivery'];
1299
+ $interval = new \DateInterval ("P{$daysDelay}D");
1300
+ return $today->add($interval)->format("Y-m-d");
1301
+ }
1302
+
1303
+ return '';
1304
+ }
1305
+
1306
+ /**
1307
+ * Provide a delivery Method compatible with gateway
1308
+ *
1309
+ * @param $mapping array Result of mapping
1310
+ * @return null|string JSON
1311
+ */
1312
+ function calculateDeliveryMethod($mapping){
1313
+ if (is_array($mapping)) {
1314
+ $itemsDelivery = Mage::helper('hipay/collection')->getFullItemsDelivery();
1315
+ if ($itemsDelivery && is_array($itemsDelivery) && !empty($mapping['hipay_delivery_method'])) {
1316
+ return json_encode(array('mode' => $itemsDelivery[$mapping['hipay_delivery_method']]['mode'],
1317
+ 'shipping' => $itemsDelivery[$mapping['hipay_delivery_method']]['shipping']));
1318
+ }
1319
+ }
1320
+ return '';
1321
+ }
1322
+
1323
+ /**
1324
+ *
1325
+ * @param $codeShippingMethod
1326
+ * @param $store
1327
+ */
1328
+ public function processDeliveryInformation($codeShippingMethod, $store, $method, &$params)
1329
+ {
1330
+ $mapping = $this->getMappingShipping($codeShippingMethod,$store);
1331
+ $params['delivery_method'] = $this->calculateDeliveryMethod($mapping);
1332
+
1333
+ if (empty($params['delivery_method'])) {
1334
+ Mage::helper('hipay')->debugInternalProcessHipay('### Method processDeliveryInformation');
1335
+ Mage::helper('hipay')->debugInternalProcessHipay('### WARNING : Mapping for ' . $codeShippingMethod . ' is missing.');
1336
+ }
1337
+
1338
+ $params['delivery_date'] = $this->calculateEstimatedDate($mapping);
1339
+ }
1340
+
1341
+ /**
1342
+ * Check if send cart items is required or of option is activated
1343
+ *
1344
+ * @param $product_code
1345
+ * @return boolean
1346
+ */
1347
+ public function isSendCartItemsRequired($product_code)
1348
+ {
1349
+ if ($this->isCartItemsRequired($product_code) ||
1350
+ (Mage::getStoreConfigFlag('hipay/hipay_basket/activate_basket', Mage::app()->getStore()))){
1351
+ return true;
1352
+ }
1353
+ return false;
1354
+ }
1355
+
1356
+ /**
1357
+ * Delivery information and Cart Items are mandatory for some payment product
1358
+ *
1359
+ * @param string $product_code
1360
+ * @return boolean
1361
+ */
1362
+ public function isDeliveryMethodAndCartItemsRequired($product_code)
1363
+ {
1364
+ return in_array($product_code, ['3xcb', '3xcb-no-fees', '4xcb-no-fees', '4xcb']);
1365
+ }
1366
+
1367
+ /**
1368
+ * Cart Items are mandatory for some payment product
1369
+ *
1370
+ * @param string $product_code
1371
+ * @return boolean
1372
+ */
1373
+ public function isCartItemsRequired($product_code)
1374
+ {
1375
+ return in_array($product_code, ['klarnainvoice','3xcb', '3xcb-no-fees', '4xcb-no-fees', '4xcb']);
1376
+ }
1377
+
1378
+ /**
1379
+ * Check if all mapping Shipping are done
1380
+ *
1381
+ * @return int
1382
+ */
1383
+ public function checkMappingShippingMethod ()
1384
+ {
1385
+ $mappings = unserialize($this->getConfig()->getConfigDataBasket('mapping_shipping_method',$store));
1386
+ $magentoShippingMethod = $this->getMagentoShippingMethods();
1387
+ $nbMappingMissing = count($magentoShippingMethod);
1388
+ if (is_array($magentoShippingMethod) && is_array($mappings) ){
1389
+ $nbMapping = 0;
1390
+ foreach ($mappings as $mapping ) {
1391
+ if (!empty($mapping['hipay_delivery_method'])){
1392
+ $nbMapping++;
1393
+ }
1394
+ }
1395
+ $nbMappingMissing = count($magentoShippingMethod) - $nbMapping;
1396
+ }
1397
+ return $nbMappingMissing;
1398
+ }
1399
+
1400
+ /**
1401
+ * Check if all mapping Category are done
1402
+ *
1403
+ * @return int
1404
+ */
1405
+ public function checkMappingCategoryMethod ()
1406
+ {
1407
+ $mappings = unserialize($this->getConfig()->getConfigDataBasket('mapping_category',$store));
1408
+ $magentoCategory = $this->getMagentoCategories();
1409
+ $nbMappingMissing = count($magentoCategory);
1410
+
1411
+ if (is_array($magentoCategory) && is_array($mappings)){
1412
+ $nbMapping = 0;
1413
+ foreach ($mappings as $mapping ) {
1414
+ if (!empty($mapping['hipay_category'])){
1415
+ $nbMapping++;
1416
+ }
1417
+ }
1418
+ $nbMappingMissing = count($magentoCategory) - $nbMapping;
1419
+ }
1420
+ return $nbMappingMissing;
1421
+ }
1422
}
app/code/community/Allopass/Hipay/Model/Config.php CHANGED
@@ -1,274 +1,298 @@
1
<?php
2
class Allopass_Hipay_Model_Config extends Varien_Object
3
{
4
- const API_USERNAME = 'api_username';
5
-
6
- const API_PASSWORD = 'api_password';
7
-
8
- const API_TOKENJS_USERNAME = 'api_tokenjs_username';
9
-
10
- const API_TOKENJS_PUBLICKEY = 'api_tokenjs_publickey';
11
-
12
- const API_USERNAME_TEST = "api_username_test";
13
-
14
- const API_PASSWORD_TEST = 'api_password_test';
15
-
16
- const API_TOKENJS_USERNAME_TEST = 'api_tokenjs_username_test';
17
-
18
- const API_TOKENJS_PUBLICKEY_TEST = 'api_tokenjs_publickey_test';
19
-
20
- const SECRET_PASSPHRASE = 'secret_passphrase';
21
-
22
- const SECRET_PASSPHRASE_TEST = 'secret_passphrase_test';
23
-
24
- const VAULT_ENDPOINT_TEST = 'vault_endpoint_stage';
25
-
26
- const VAULT_ENDPOINT = 'vault_endpoint_production';
27
-
28
- const GATEWAY_ENDPOINT_TEST = 'gateway_endpoint_stage';
29
-
30
- const GATEWAY_ENDPOINT = 'gateway_endpoint_production';
31
32
33
/**
34
* Use as Helper
35
*
36
- * @param string $key Var path key
37
- * @param int $storeId Store View Id
38
- * @return mixed
39
*/
40
public function getConfigData($key, $storeId = null)
41
{
42
- return $this->getInternalConfig('hipay_api',$key, $storeId = null);
43
}
44
45
- /**
46
- * Internal to get config and cache it
47
- *
48
- * @param string $key context key
49
- * @param string $key Var path key
50
- * @param int $storeId Store View Id
51
- * @return mixed
52
- */
53
- private function getInternalConfig($key_api,$key, $storeId = null)
54
- {
55
- $index = 'hipay' . $key_api . $key . $storeId;
56
if (!$this->hasData($index)) {
57
$value = Mage::getStoreConfig('hipay/' . $key_api . '/' . $key, $storeId);
58
$this->setData($index, $value);
59
}
60
return $this->getData($index);
61
- }
62
63
/**
64
* Return config NORMAL ( HIPAY_API )
65
*
66
- * @param string $key Var path key
67
- * @param int $storeId Store View Id
68
- * @return mixed
69
*/
70
public function getConfig($key, $storeId = null)
71
{
72
- return $this->getInternalConfig('hipay_api',$key, $storeId = null);
73
}
74
75
/**
76
- * Return config MOTO ( HIPAY_MOT)
77
*
78
- * @param string $key Var path key
79
- * @param int $storeId Store View Id
80
- * @return mixed
81
*/
82
public function getConfigDataMoto($key, $storeId = null)
83
{
84
- return $this->getInternalConfig('hipay_api_moto',$key, $storeId = null);
85
- }
86
-
87
- /**
88
- * Return config var
89
- *
90
- * @param string $key Var path key
91
- * @param int $storeId Store View Id
92
- * @return mixed
93
- */
94
- public function getConfigFlag($key, $storeId = null)
95
- {
96
-
97
- if (!$this->hasData($key)) {
98
- $value = Mage::getStoreConfigFlag('hipay/hipay_api/' . $key, $storeId);
99
- $this->setData($key, $value);
100
- }
101
- return $this->getData($key);
102
- }
103
-
104
- public function getSecretPassphrase($storeId =null)
105
- {
106
- return $this->getConfigData(self::SECRET_PASSPHRASE,$storeId);
107
- }
108
-
109
- public function getSecretPassphraseTest($storeId =null)
110
- {
111
- return $this->getConfigData(self::SECRET_PASSPHRASE_TEST,$storeId);
112
- }
113
-
114
- public function getApiUsername($storeId =null)
115
- {
116
- return $this->getConfigData(self::API_USERNAME,$storeId);
117
- }
118
-
119
- public function getApiPassword($storeId=null)
120
- {
121
- return $this->getConfigData(self::API_PASSWORD,$storeId);
122
- }
123
-
124
- public function getApiTokenJSUsername($storeId=null)
125
- {
126
- return $this->getConfigData(self::API_TOKENJS_USERNAME,$storeId);
127
- }
128
-
129
- public function getApiTokenJSPublickey($storeId=null)
130
- {
131
- return $this->getConfigData(self::API_TOKENJS_PUBLICKEY,$storeId);
132
- }
133
-
134
- public function getApiUsernameTest($storeId =null)
135
- {
136
- return $this->getConfigData(self::API_USERNAME_TEST,$storeId);
137
- }
138
-
139
- public function getApiPasswordTest($storeId=null)
140
- {
141
- return $this->getConfigData(self::API_PASSWORD_TEST,$storeId);
142
- }
143
-
144
- public function getApiTokenJSUsernameTest($storeId=null)
145
- {
146
- return $this->getConfigData(self::API_TOKENJS_USERNAME_TEST,$storeId);
147
- }
148
- public function getApiTokenJSPublickeyTest($storeId=null)
149
- {
150
- return $this->getConfigData(self::API_TOKENJS_PUBLICKEY_TEST,$storeId);
151
- }
152
-
153
- public function getVaultEndpoint($storeId=null)
154
- {
155
- return $this->getConfigData(self::VAULT_ENDPOINT,$storeId);
156
- }
157
-
158
- public function getVaultEndpointTest($storeId=null)
159
- {
160
- return $this->getConfigData(self::VAULT_ENDPOINT_TEST,$storeId);
161
- }
162
-
163
- public function getGatewayEndpoint($storeId=null)
164
- {
165
- return $this->getConfigData(self::GATEWAY_ENDPOINT,$storeId);
166
- }
167
-
168
- public function getGatewayEndpointTest($storeId=null)
169
- {
170
- return $this->getConfigData(self::GATEWAY_ENDPOINT_TEST,$storeId);
171
- }
172
-
173
- public function getApiUsernameMoto($storeId =null)
174
- {
175
- return $this->getConfigDataMoto(self::API_USERNAME,$storeId);
176
- }
177
-
178
- public function getApiPasswordMoto($storeId=null)
179
- {
180
- return $this->getConfigDataMoto(self::API_PASSWORD,$storeId);
181
- }
182
-
183
- public function getApiUsernameTestMoto($storeId =null)
184
- {
185
- return $this->getConfigDataMoto(self::API_USERNAME_TEST,$storeId);
186
- }
187
-
188
- public function getApiPasswordTestMoto($storeId=null)
189
- {
190
- return $this->getConfigDataMoto(self::API_PASSWORD_TEST,$storeId);
191
- }
192
-
193
-
194
-
195
-
196
-
197
- /**
198
- * Retrieve array of credit card types
199
- *
200
- * @return array
201
- */
202
- public function getCcTypes()
203
- {
204
- $_types = Mage::getConfig()->getNode('global/payment_hipay/cc/types')->asArray();
205
-
206
- uasort($_types, array('Allopass_Hipay_Model_Config', 'compareCcTypes'));
207
-
208
- $types = array();
209
- foreach ($_types as $data) {
210
- if (isset($data['code']) && isset($data['name'])) {
211
- $types[$data['code']] = $data['name'];
212
- }
213
- }
214
- return $types;
215
- }
216
-
217
- /**
218
- * Retrieve array of credit card types to get code hipay equals to code Magento
219
- *
220
- * @return array
221
- */
222
- public function getCcTypesHipay()
223
- {
224
- $_types = Mage::getConfig()->getNode('global/payment_hipay/hosted/types')->asArray();
225
-
226
- $types = array();
227
- foreach ($_types as $data) {
228
- if (isset($data['code']) && isset($data['code_hipay'])) {
229
- $types[$data['code']] = $data['code_hipay'];
230
- }
231
- }
232
- return $types;
233
- }
234
-
235
- /**
236
- * Retrieve array of template types to display in hosted page
237
- *
238
- * @return array
239
- */
240
- public function getTemplateHosted()
241
- {
242
- $_templates = Mage::getConfig()->getNode('global/template_hipay/hosted')->asArray();
243
-
244
- $templates = array();
245
- foreach ($_templates as $data) {
246
- if (isset($data['value']) && isset($data['label'])) {
247
- $templates[$data['value']] = $data['label'];
248
- }
249
- }
250
- return $templates;
251
- }
252
-
253
- /**
254
- * Retrieve array of credit card types to get code hipay
255
- *
256
- * @return array
257
- */
258
- public function getCcTypesCodeHipay()
259
- {
260
- $_types = Mage::getConfig()->getNode('global/payment_hipay/hosted/types')->asArray();
261
-
262
- $types = array();
263
- foreach ($_types as $data) {
264
- if (isset($data['code_hipay']) && isset($data['name'])) {
265
- $types[$data['code_hipay']] = $data['name'];
266
- }
267
- }
268
- return $types;
269
- }
270
-
271
- /**
272
* Retrieve list of months translation
273
*
274
* @return array
@@ -277,53 +301,52 @@ class Allopass_Hipay_Model_Config extends Varien_Object
277
{
278
$data = Mage::app()->getLocale()->getTranslationList('month');
279
foreach ($data as $key => $value) {
280
- $monthNum = ($key < 10) ? '0'.$key : $key;
281
$data[$key] = $monthNum . ' - ' . $value;
282
}
283
return $data;
284
}
285
-
286
- /**
287
- * Retrieve array of available years
288
- *
289
- * @return array
290
- */
291
- public function getYears()
292
- {
293
- $years = array();
294
- $first = date("Y");
295
-
296
- for ($index=0; $index <= 10; $index++) {
297
- $year = $first + $index;
298
- $years[$year] = $year;
299
- }
300
- return $years;
301
- }
302
-
303
- /**
304
- * Statis Method for compare sort order of CC Types
305
- *
306
- * @param array $a
307
- * @param array $b
308
- * @return int
309
- */
310
- static function compareCcTypes($a, $b)
311
- {
312
- if (!isset($a['order'])) {
313
- $a['order'] = 0;
314
- }
315
-
316
- if (!isset($b['order'])) {
317
- $b['order'] = 0;
318
- }
319
-
320
- if ($a['order'] == $b['order']) {
321
- return 0;
322
- } else if ($a['order'] > $b['order']) {
323
- return 1;
324
- } else {
325
- return -1;
326
- }
327
-
328
- }
329
- }
1
<?php
2
+
3
class Allopass_Hipay_Model_Config extends Varien_Object
4
{
5
+ const API_USERNAME = 'api_username';
6
+
7
+ const API_PASSWORD = 'api_password';
8
+
9
+ const API_TOKENJS_USERNAME = 'api_tokenjs_username';
10
+
11
+ const API_TOKENJS_PUBLICKEY = 'api_tokenjs_publickey';
12
+
13
+ const API_USERNAME_TEST = "api_username_test";
14
+
15
+ const API_PASSWORD_TEST = 'api_password_test';
16
+
17
+ const API_TOKENJS_USERNAME_TEST = 'api_tokenjs_username_test';
18
+
19
+ const API_TOKENJS_PUBLICKEY_TEST = 'api_tokenjs_publickey_test';
20
+
21
+ const SECRET_PASSPHRASE = 'secret_passphrase';
22
+
23
+ const SECRET_PASSPHRASE_TEST = 'secret_passphrase_test';
24
+
25
+ const VAULT_ENDPOINT_TEST = 'vault_endpoint_stage';
26
+
27
+ const VAULT_ENDPOINT = 'vault_endpoint_production';
28
+
29
+ const GATEWAY_ENDPOINT_TEST = 'gateway_endpoint_stage';
30
+
31
+ const GATEWAY_ENDPOINT = 'gateway_endpoint_production';
32
+
33
+ const DEBUG_MODE = 'debug';
34
35
36
/**
37
* Use as Helper
38
*
39
+ * @param string $key Var path key
40
+ * @param int $storeId Store View Id
41
+ * @return mixed
42
*/
43
public function getConfigData($key, $storeId = null)
44
{
45
+ return $this->getInternalConfig('hipay_api', $key, $storeId = null);
46
}
47
48
+ /**
49
+ * Internal to get config and cache it
50
+ *
51
+ * @param string $key context key
52
+ * @param string $key Var path key
53
+ * @param int $storeId Store View Id
54
+ * @return mixed
55
+ */
56
+ private function getInternalConfig($key_api, $key, $storeId = null)
57
+ {
58
+ $index = 'hipay' . $key_api . $key . $storeId;
59
if (!$this->hasData($index)) {
60
$value = Mage::getStoreConfig('hipay/' . $key_api . '/' . $key, $storeId);
61
$this->setData($index, $value);
62
}
63
return $this->getData($index);
64
+ }
65
66
/**
67
* Return config NORMAL ( HIPAY_API )
68
*
69
+ * @param string $key Var path key
70
+ * @param int $storeId Store View Id
71
+ * @return mixed
72
*/
73
public function getConfig($key, $storeId = null)
74
{
75
+ return $this->getInternalConfig('hipay_api', $key, $storeId = null);
76
}
77
78
/**
79
+ * Return config MOTO ( HIPAY_MOTO)
80
*
81
+ * @param string $key Var path key
82
+ * @param int $storeId Store View Id
83
+ * @return mixed
84
*/
85
public function getConfigDataMoto($key, $storeId = null)
86
{
87
+ return $this->getInternalConfig('hipay_api_moto', $key, $storeId = null);
88
+ }
89
+
90
+ /**
91
+ * Return config BASKET
92
+ *
93
+ * @param string $key Path key
94
+ * @param int $storeId Store View Id
95
+ * @return mixed
96
+ */
97
+ public function getConfigDataBasket($key, $storeId = null)
98
+ {
99
+ return $this->getInternalConfig('hipay_basket', $key, $storeId = null);
100
+ }
101
+
102
+ /**
103
+ * Return config var
104
+ *
105
+ * @param string $key Var path key
106
+ * @param int $storeId Store View Id
107
+ * @return mixed
108
+ */
109
+ public function getConfigFlag($key, $storeId = null)
110
+ {
111
+ if (!$this->hasData($key)) {
112
+ $value = Mage::getStoreConfigFlag('hipay/hipay_api/' . $key, $storeId);
113
+ $this->setData($key, $value);
114
+ }
115
+ return $this->getData($key);
116
+ }
117
+
118
+ public function getSecretPassphrase($storeId = null)
119
+ {
120
+ return $this->getConfigData(self::SECRET_PASSPHRASE, $storeId);
121
+ }
122
+
123
+ public function getSecretPassphraseTest($storeId = null)
124
+ {
125
+ return $this->getConfigData(self::SECRET_PASSPHRASE_TEST, $storeId);
126
+ }
127
+
128
+ public function getApiUsername($storeId = null)
129
+ {
130
+ return $this->getConfigData(self::API_USERNAME, $storeId);
131
+ }
132
+
133
+ public function getApiPassword($storeId = null)
134
+ {
135
+ return $this->getConfigData(self::API_PASSWORD, $storeId);
136
+ }
137
+
138
+ public function getApiTokenJSUsername($storeId = null)
139
+ {
140
+ return $this->getConfigData(self::API_TOKENJS_USERNAME, $storeId);
141
+ }
142
+
143
+ public function getApiTokenJSPublickey($storeId = null)
144
+ {
145
+ return $this->getConfigData(self::API_TOKENJS_PUBLICKEY, $storeId);
146
+ }
147
+
148
+ public function getApiUsernameTest($storeId = null)
149
+ {
150
+ return $this->getConfigData(self::API_USERNAME_TEST, $storeId);
151
+ }
152
+
153
+ public function getApiPasswordTest($storeId = null)
154
+ {
155
+ return $this->getConfigData(self::API_PASSWORD_TEST, $storeId);
156
+ }
157
+
158
+ public function getApiTokenJSUsernameTest($storeId = null)
159
+ {
160
+ return $this->getConfigData(self::API_TOKENJS_USERNAME_TEST, $storeId);
161
+ }
162
+
163
+ public function getApiTokenJSPublickeyTest($storeId = null)
164
+ {
165
+ return $this->getConfigData(self::API_TOKENJS_PUBLICKEY_TEST, $storeId);
166
+ }
167
+
168
+ public function getVaultEndpoint($storeId = null)
169
+ {
170
+ return $this->getConfigData(self::VAULT_ENDPOINT, $storeId);
171
+ }
172
+
173
+ public function getVaultEndpointTest($storeId = null)
174
+ {
175
+ return $this->getConfigData(self::VAULT_ENDPOINT_TEST, $storeId);
176
+ }
177
+
178
+ public function getGatewayEndpoint($storeId = null)
179
+ {
180
+ return $this->getConfigData(self::GATEWAY_ENDPOINT, $storeId);
181
+ }
182
+
183
+ public function getGatewayEndpointTest($storeId = null)
184
+ {
185
+ return $this->getConfigData(self::GATEWAY_ENDPOINT_TEST, $storeId);
186
+ }
187
+
188
+ public function getApiUsernameMoto($storeId = null)
189
+ {
190
+ return $this->getConfigDataMoto(self::API_USERNAME, $storeId);
191
+ }
192
+
193
+ public function getApiPasswordMoto($storeId = null)
194
+ {
195
+ return $this->getConfigDataMoto(self::API_PASSWORD, $storeId);
196
+ }
197
+
198
+ public function getApiUsernameTestMoto($storeId = null)
199
+ {
200
+ return $this->getConfigDataMoto(self::API_USERNAME_TEST, $storeId);
201
+ }
202
+
203
+ public function getApiPasswordTestMoto($storeId = null)
204
+ {
205
+ return $this->getConfigDataMoto(self::API_PASSWORD_TEST, $storeId);
206
+ }
207
+
208
+ /**
209
+ * General log level
210
+ *
211
+ * @param int $storeId
212
+ *
213
+ * @return mixed
214
+ */
215
+ public function isGeneralDebugEnabled($storeId = null)
216
+ {
217
+ return $this->getConfigData(self::DEBUG_MODE, $storeId);
218
+ }
219
+
220
+
221
+ /**
222
+ * Retrieve array of credit card types
223
+ *
224
+ * @return array
225
+ */
226
+ public function getCcTypes()
227
+ {
228
+ $_types = Mage::getConfig()->getNode('global/payment_hipay/cc/types')->asArray();
229
+
230
+ uasort($_types, array('Allopass_Hipay_Model_Config', 'compareCcTypes'));
231
+
232
+ $types = array();
233
+ foreach ($_types as $data) {
234
+ if (isset($data['code']) && isset($data['name'])) {
235
+ $types[$data['code']] = $data['name'];
236
+ }
237
+ }
238
+ return $types;
239
+ }
240
+
241
+ /**
242
+ * Retrieve array of credit card types to get code hipay equals to code Magento
243
+ *
244
+ * @return array
245
+ */
246
+ public function getCcTypesHipay()
247
+ {
248
+ $_types = Mage::getConfig()->getNode('global/payment_hipay/hosted/types')->asArray();
249
+
250
+ $types = array();
251
+ foreach ($_types as $data) {
252
+ if (isset($data['code']) && isset($data['code_hipay'])) {
253
+ $types[$data['code']] = $data['code_hipay'];
254
+ }
255
+ }
256
+ return $types;
257
+ }
258
+
259
+ /**
260
+ * Retrieve array of template types to display in hosted page
261
+ *
262
+ * @return array
263
+ */
264
+ public function getTemplateHosted()
265
+ {
266
+ $_templates = Mage::getConfig()->getNode('global/template_hipay/hosted')->asArray();
267
+
268
+ $templates = array();
269
+ foreach ($_templates as $data) {
270
+ if (isset($data['value']) && isset($data['label'])) {
271
+ $templates[$data['value']] = $data['label'];
272
+ }
273
+ }
274
+ return $templates;
275
+ }
276
+
277
+ /**
278
+ * Retrieve array of credit card types to get code hipay
279
+ *
280
+ * @return array
281
+ */
282
+ public function getCcTypesCodeHipay()
283
+ {
284
+ $_types = Mage::getConfig()->getNode('global/payment_hipay/hosted/types')->asArray();
285
+
286
+ $types = array();
287
+ foreach ($_types as $data) {
288
+ if (isset($data['code_hipay']) && isset($data['name'])) {
289
+ $types[$data['code_hipay']] = $data['name'];
290
+ }
291
+ }
292
+ return $types;
293
+ }
294
+
295
+ /**
296
* Retrieve list of months translation
297
*
298
* @return array
301
{
302
$data = Mage::app()->getLocale()->getTranslationList('month');
303
foreach ($data as $key => $value) {
304
+ $monthNum = ($key < 10) ? '0' . $key : $key;
305
$data[$key] = $monthNum . ' - ' . $value;
306
}
307
return $data;
308
}
309
+
310
+ /**
311
+ * Retrieve array of available years
312
+ *
313
+ * @return array
314
+ */
315
+ public function getYears()
316
+ {
317
+ $years = array();
318
+ $first = date("Y");
319
+
320
+ for ($index = 0; $index <= 10; $index++) {
321
+ $year = $first + $index;
322
+ $years[$year] = $year;
323
+ }
324
+ return $years;
325
+ }
326
+
327
+ /**
328
+ * Statis Method for compare sort order of CC Types
329
+ *
330
+ * @param array $a
331
+ * @param array $b
332
+ * @return int
333
+ */
334
+ public static function compareCcTypes($a, $b)
335
+ {
336
+ if (!isset($a['order'])) {
337
+ $a['order'] = 0;
338
+ }
339
+
340
+ if (!isset($b['order'])) {
341
+ $b['order'] = 0;
342
+ }
343
+
344
+ if ($a['order'] == $b['order']) {
345
+ return 0;
346
+ } elseif ($a['order'] > $b['order']) {
347
+ return 1;
348
+ } else {
349
+ return -1;
350
+ }
351
+ }
352
+ }
app/code/community/Allopass/Hipay/Model/Field/CategoryMapping.php ADDED
@@ -0,0 +1,5 @@
1
+ <?php
2
+ class Allopass_Hipay_Model_Field_Field_CategoryMapping extends Mage_Adminhtml_Model_System_Config_Backend_Serialized_Array
3
+ {
4
+ protected $_eventPrefix = 'hipay_field_category_mapping';
5
+ }
app/code/community/Allopass/Hipay/Model/Field/MappingShippingMethod.php ADDED
@@ -0,0 +1,27 @@
1
+ <?php
2
+
3
+ class Allopass_Hipay_Model_Field_MappingShippingMethod extends Mage_Adminhtml_Model_System_Config_Backend_Serialized_Array
4
+ {
5
+ /**
6
+ *
7
+ * @return Mage_Core_Model_Abstract|void
8
+ */
9
+ protected function _beforeSave()
10
+ {
11
+ $values = $this->getValue();
12
+
13
+ foreach ($values as $key => $value) {
14
+ if (empty($value)) {
15
+ continue;
16
+ }
17
+
18
+ if (!empty($value['delay_preparation']) && !is_numeric($value['delay_preparation'])) {
19
+ Mage::throwException(Mage::helper('hipay')->__('Delay delivery is not a correct value for %s', $key));
20
+ } else if (!empty($value['delay_delivery']) && !is_numeric($value['delay_preparation'])) {
21
+ Mage::throwException(Mage::helper('hipay')->__('Delay delivery is not a correct value for %s', $key));
22
+ }
23
+ }
24
+ $this->setValue($values);
25
+ return parent::_beforeSave();
26
+ }
27
+ }
app/code/community/Allopass/Hipay/Model/Method/Abstract.php CHANGED
@@ -95,6 +95,7 @@ abstract class Allopass_Hipay_Model_Method_Abstract extends Mage_Payment_Model_M
95
public function assignInfoData($info, $data)
96
{
97
$oneclickMode = $data->getData($this->getCode() . '_oneclick');
98
$oneclickCard = $data->getData($this->getCode() . '_oneclick_card');
99
$splitPaymentId = $data->getData($this->getCode() . '_split_payment_id');
100
$token = $data->getData($this->getCode() . '_cc_token');
@@ -110,7 +111,8 @@ abstract class Allopass_Hipay_Model_Method_Abstract extends Mage_Payment_Model_M
110
/**
111
* A request instructing the payment gateway to cancel a previously authorized transaction.
112
* Only authorized transactions can be cancelled, captured transactions must be refunded.
113
- *
114
*/
115
public function cancelTransaction(Mage_Payment_Model_Info $payment)
116
{
@@ -156,7 +158,6 @@ abstract class Allopass_Hipay_Model_Method_Abstract extends Mage_Payment_Model_M
156
public function acceptPayment(Mage_Payment_Model_Info $payment)
157
{
158
parent::acceptPayment($payment);
159
-