Allopass_Hipay - Version 1.6.0

Version Notes

Download this release

Release Info

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


Code changes from version 1.5.1 to 1.6.0

Files changed (36) hide show
  1. app/code/community/Allopass/Hipay/Block/Adminhtml/Customer/Edit/Tab/Card.php +2 -2
  2. app/code/community/Allopass/Hipay/Block/Adminhtml/PaymentProfile/Edit/Form.php +1 -1
  3. app/code/community/Allopass/Hipay/Block/Adminhtml/SplitPayment/Edit/Form.php +10 -2
  4. app/code/community/Allopass/Hipay/Block/Adminhtml/System/Config/Form/Field/Notice.php +39 -0
  5. app/code/community/Allopass/Hipay/Block/Card.php +1 -1
  6. app/code/community/Allopass/Hipay/Block/Checkout/Cart/Totals.php +48 -0
  7. app/code/community/Allopass/Hipay/Controller/Payment.php +298 -297
  8. app/code/community/Allopass/Hipay/Helper/Data.php +1146 -620
  9. app/code/community/Allopass/Hipay/Model/Api/Request.php +177 -108
  10. app/code/community/Allopass/Hipay/Model/Config.php +71 -10
  11. app/code/community/Allopass/Hipay/Model/Method/Abstract.php +1645 -1516
  12. app/code/community/Allopass/Hipay/Model/Method/Cc.php +27 -8
  13. app/code/community/Allopass/Hipay/Model/Method/Hosted.php +141 -121
  14. app/code/community/Allopass/Hipay/Model/Method/Klarna.php +29 -0
  15. app/code/community/Allopass/Hipay/Model/Observer.php +209 -226
  16. app/code/community/Allopass/Hipay/Model/PaymentProfile.php +1 -1
  17. app/code/community/Allopass/Hipay/Model/Rule/Condition/Address.php +202 -126
  18. app/code/community/Allopass/Hipay/Model/Source/Attributes.php +41 -0
  19. app/code/community/Allopass/Hipay/controllers/Adminhtml/PaymentController.php +293 -287
  20. app/code/community/Allopass/Hipay/controllers/KlarnaController.php +13 -0
  21. app/code/community/Allopass/Hipay/etc/config.xml +454 -383
  22. app/code/community/Allopass/Hipay/etc/system.xml +2352 -1549
  23. app/code/community/Allopass/Hipay/sql/allopass_hipay_setup/mysql4-upgrade-1.1.0-1.6.0.php +25 -0
  24. app/design/adminhtml/default/default/template/hipay/form/hosted.phtml +3 -0
  25. app/design/adminhtml/default/default/template/hipay/system/config/form/field/notice.phtml +19 -0
  26. app/design/frontend/base/default/layout/hipay.xml +1 -1
  27. app/design/frontend/base/default/template/hipay/card/account.phtml +1 -1
  28. app/design/frontend/base/default/template/hipay/checkout/tokenjs.phtml +2 -2
  29. app/design/frontend/base/default/template/hipay/form/cc.phtml +13 -2
  30. app/locale/en_US/Allopass_Hipay.csv +13 -8
  31. app/locale/en_US/template/email/hipay_hipay_api_moto.html +45 -0
  32. app/locale/fr_FR/Allopass_Hipay.csv +14 -7
  33. app/locale/fr_FR/template/email/hipay_hipay_api_moto.html +45 -0
  34. app/locale/it_IT/Allopass_Hipay.csv +10 -5
  35. app/locale/it_IT/template/email/hipay_hipay_api_moto.html +45 -0
  36. package.xml +1 -1
app/code/community/Allopass/Hipay/Block/Adminhtml/Customer/Edit/Tab/Card.php CHANGED
@@ -128,11 +128,11 @@ class Allopass_Hipay_Block_Adminhtml_Customer_Edit_Tab_Card extends
128
}
129
130
public function getTabLabel() {
131
- return Mage::helper('hipay')->__("Hipay's Cards");
132
133
}
134
public function getTabTitle() {
135
- return Mage::helper('hipay')->__("Hipay's Cards");
136
137
}
138
128
}
129
130
public function getTabLabel() {
131
+ return Mage::helper('hipay')->__("My Payment Cards");
132
133
}
134
public function getTabTitle() {
135
+ return Mage::helper('hipay')->__("My Payment Cards");
136
137
}
138
app/code/community/Allopass/Hipay/Block/Adminhtml/PaymentProfile/Edit/Form.php CHANGED
@@ -41,7 +41,7 @@ class Allopass_Hipay_Block_Adminhtml_PaymentProfile_Edit_Form extends Mage_Admin
41
'class' => 'required-entry validate-number',
42
'required' => true,
43
'name' => 'period_frequency',
44
- 'note'=>$this->__('Number of billing periods that make up one billing cycle.')
45
));
46
47
$fieldset->addField('period_max_cycles', 'text', array(
41
'class' => 'required-entry validate-number',
42
'required' => true,
43
'name' => 'period_frequency',
44
+ 'note'=>$this->__('Time to wait between installments in a billing cycle.')
45
));
46
47
$fieldset->addField('period_max_cycles', 'text', array(
app/code/community/Allopass/Hipay/Block/Adminhtml/SplitPayment/Edit/Form.php CHANGED
@@ -84,8 +84,16 @@ class Allopass_Hipay_Block_Adminhtml_SplitPayment_Edit_Form extends Mage_Adminht
84
'title' => Mage::helper('hipay')->__('Status'),
85
'name' => 'status',
86
'values' => Allopass_Hipay_Model_SplitPayment::getStatues(),
87
- )
88
- );
89
90
$form->setUseContainer(true);
91
$form->setValues($splitPayment->getData());
84
'title' => Mage::helper('hipay')->__('Status'),
85
'name' => 'status',
86
'values' => Allopass_Hipay_Model_SplitPayment::getStatues(),
87
+ ));
88
+
89
+ $fieldset->addField('split_number', 'text', array(
90
+ 'label' => Mage::helper('hipay')->__('Split number'),
91
+ 'title' => Mage::helper('hipay')->__('Split number'),
92
+ 'required' => false,
93
+ 'name' => 'split_number',
94
+ 'readonly' => false,
95
+ ));
96
+
97
98
$form->setUseContainer(true);
99
$form->setValues($splitPayment->getData());
app/code/community/Allopass/Hipay/Block/Adminhtml/System/Config/Form/Field/Notice.php ADDED
@@ -0,0 +1,39 @@
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_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
+ }
app/code/community/Allopass/Hipay/Block/Card.php CHANGED
@@ -17,7 +17,7 @@ class Allopass_Hipay_Block_Card extends Mage_Core_Block_Template
17
18
$this->setCards($cards);
19
20
- Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('root')->setHeaderTitle(Mage::helper('hipay')->__("Hipay's Cards"));
21
}
22
23
protected function _prepareLayout()
17
18
$this->setCards($cards);
19
20
+ Mage::app()->getFrontController()->getAction()->getLayout()->getBlock('root')->setHeaderTitle(Mage::helper('hipay')->__("My Payment Cards"));
21
}
22
23
protected function _prepareLayout()
app/code/community/Allopass/Hipay/Block/Checkout/Cart/Totals.php ADDED
@@ -0,0 +1,48 @@
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magento.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magento.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Checkout
24
+ * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ class Allopass_Hipay_Block_Checkout_Cart_Totals extends Mage_Checkout_Block_Cart_Totals
28
+ {
29
+ /**
30
+ * Check if we have display grand total in base currency
31
+ *
32
+ * @return bool
33
+ */
34
+ public function needDisplayBaseGrandtotal()
35
+ {
36
+ $quote = $this->getQuote();
37
+ $useOrderCurrency = Mage::getStoreConfig('hipay/hipay_api/currency_transaction', Mage::app()->getStore());
38
+
39
+ if (!$useOrderCurrency) {
40
+ if ($quote->getBaseCurrencyCode() != $quote->getQuoteCurrencyCode()) {
41
+ return true;
42
+ }
43
+ }
44
+
45
+ return false;
46
+ }
47
+
48
+ }
app/code/community/Allopass/Hipay/Controller/Payment.php CHANGED
@@ -1,314 +1,315 @@
1
<?php
2
class Allopass_Hipay_Controller_Payment extends Mage_Core_Controller_Front_Action
3
{
4
- /**
5
- *
6
- * @var Mage_Sales_Model_Order $order
7
- */
8
- protected $_order = null;
9
-
10
-
11
- /**
12
- * @return Mage_Core_Controller_Front_Action
13
- */
14
- public function preDispatch() {
15
- parent::preDispatch();
16
17
- }
18
19
-
20
- /**
21
- *
22
- * @return Allopass_Hipay_Model_Method_Abstract $methodInstance
23
- */
24
- protected function _getMethodInstance()
25
- {
26
- Mage::throwException("Method: '" . __METHOD__ . "' must be implemented!");
27
- }
28
29
- public function sendRequestAction()
30
- {
31
- $order = $this->getOrder();
32
- $payment = $order->getPayment();
33
34
- $methodInstance = $this->_getMethodInstance();
35
-
36
- try
37
- {
38
- $redirectUrl = $methodInstance->place($payment,$order->getBaseTotalDue());
39
- }
40
- catch (Exception $e)
41
- {
42
- Mage::logException($e);
43
- $this->getCheckout()->addError($e->getMessage());
44
- $this->_redirect('checkout/cart');
45
- return $this;
46
- }
47
-
48
-
49
- $this->_redirectUrl($redirectUrl);
50
-
51
- return $this;
52
-
53
- }
54
-
55
-
56
- public function acceptAction()
57
- {
58
- if(($profileIds = Mage::getSingleton('checkout/session')->getLastRecurringProfileIds()))
59
- {
60
- if(is_array($profileIds))
61
- {
62
- /* @var $gatewayResponse Allopass_Hipay_Model_Api_Response_Gateway */
63
- $gatewayResponse = Mage::getSingleton('hipay/api_response_gateway',$this->getRequest()->getParams());
64
- $collection = Mage::getModel('sales/recurring_profile')->getCollection()
65
- ->addFieldToFilter('profile_id', array('in' => $profileIds))
66
- ;
67
- $profiles = array();
68
- foreach ($collection as $profile) {
69
- //$referenceId = $gatewayResponse->getToken()."-".$profile->getId();
70
- $additionalInfo = array();
71
- $additionalInfo['ccType'] = $gatewayResponse->getBrand();
72
- $additionalInfo['ccExpMonth'] = $gatewayResponse->getCardExpiryMonth() ;
73
- $additionalInfo['ccExpYear'] = $gatewayResponse->getCardExpiryYear();
74
- $additionalInfo['token'] = $gatewayResponse->getToken();
75
- $additionalInfo['transaction_id'] = $gatewayResponse->getTransactionReference();
76
- $profile->setAdditionalInfo($additionalInfo);
77
- //$profile->setReferenceId($referenceId);
78
- $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE);
79
-
80
- $profile->save();
81
- }
82
- }
83
-
84
-
85
- $session = Mage::getSingleton('checkout/session');
86
- if (!$session->getLastSuccessQuoteId()) {
87
-
88
- $session->setLastSuccessQuoteId($this->getOrder()->getIncrementId());
89
- $session->setLastQuoteId($this->getOrder()->getId());
90
- }
91
-
92
- }
93
- /*else
94
- {
95
- $this->processResponse();
96
- }*/
97
- $this->processResponse();
98
99
- $url_redirect = Mage::helper('hipay')->getCheckoutSuccessPage($this->getOrder()->getPayment());
100
if (preg_match('/http/',$url_redirect)){
101
$this->_redirectUrl($url_redirect);
102
}else{
103
$this->_redirect($url_redirect);
104
}
105
-
106
- return $this;
107
- }
108
-
109
- public function pendingAction()
110
- {
111
- $this->processResponse();
112
-
113
- $this->_redirect($this->_getMethodInstance()->getConfigData('pending_redirect_page'));
114
-
115
- return $this;
116
- }
117
-
118
- public function declineAction()
119
- {
120
- $lastOrderId = $this->getOrder()->getIncrementId();
121
-
122
- Mage::getSingleton('checkout/session')->setLastQuoteId($lastOrderId);
123
- Mage::getSingleton('checkout/session')->setLastOrderId($lastOrderId);
124
-
125
- $this->processResponse();
126
-
127
- Mage::getSingleton('checkout/session')->addError("Your payment is declined. Please retry checkout with another payment card.");
128
-
129
- $this->_redirect('checkout/cart');
130
- return $this;
131
- }
132
133
-
134
- public function exceptionAction()
135
- {
136
-
137
- $lastOrderId = $this->getOrder()->getIncrementId();
138
-
139
- Mage::getSingleton('checkout/session')->setLastQuoteId($lastOrderId);
140
- Mage::getSingleton('checkout/session')->setLastOrderId($lastOrderId);
141
-
142
- Mage::getSingleton('checkout/session')->addError("An exception has occured. Please retry checkout.");
143
-
144
- $this->_redirect('checkout/cart');
145
- return $this;
146
- }
147
-
148
-
149
- public function cancelAction()
150
- {
151
- $this->processResponse();
152
- $this->_redirect('checkout/cart');
153
- return $this;
154
- }
155
-
156
- protected function processResponse()
157
- {
158
- $order = $this->getOrder();
159
- $payment = $order->getPayment();
160
-
161
- /* @var $gatewayResponse Allopass_Hipay_Model_Api_Response_Gateway */
162
- $gatewayResponse = Mage::getSingleton('hipay/api_response_gateway',$this->getRequest()->getParams());
163
-
164
- $this->_getMethodInstance()->processResponseToRedirect($gatewayResponse, $payment, $order->getBaseTotalDue());
165
- }
166
167
-
168
-
169
- /**
170
- *
171
- * @return Mage_Sales_Model_Order
172
- */
173
- protected function getOrder()
174
- {
175
- if(is_null($this->_order))
176
- {
177
-
178
- if(($profileIds = $this->getCheckout()->getLastRecurringProfileIds()))
179
- {
180
-
181
- if (is_array($profileIds)) {
182
-
183
- foreach ($profileIds as $profileId)
184
- {
185
- /* @var $profile Mage_Sales_Model_Recurring_Profile */
186
- $profile = Mage::getModel('sales/recurring_profile')->load($profileId);
187
- /* @var $_helperRecurring Allopass_Hipayrecurring_Helper_Data */
188
- $_helperRecurring = Mage::helper('hipayrecurring');
189
-
190
- if($_helperRecurring->isInitialProfileOrder($profile))
191
- $this->_order = $_helperRecurring->createOrderFromProfile($profile);
192
- else
193
- {
194
- $orderId = current($profile->getChildOrderIds());
195
- $this->_order = Mage::getModel('sales/order')->load($orderId);
196
-
197
- $additionalInfo = $profile->getAdditionalInfo();
198
-
199
- $this->_order->getPayment()->setCcType(isset($additionalInfo['ccType']) ? $additionalInfo['ccType'] : "");
200
- $this->_order->getPayment()->setCcExpMonth(isset($additionalInfo['ccExpMonth']) ? $additionalInfo['ccExpMonth'] : "");
201
- $this->_order->getPayment()->setCcExpYear(isset($additionalInfo['ccExpYear']) ? $additionalInfo['ccExpYear'] : "");
202
- $this->_order->getPayment()->setAdditionalInformation('token',isset($additionalInfo['token']) ? $additionalInfo['token'] : "");
203
- $this->_order->getPayment()->setAdditionalInformation('create_oneclick',isset($additionalInfo['create_oneclick']) ? $additionalInfo['create_oneclick'] : 1);
204
- $this->_order->getPayment()->setAdditionalInformation('use_oneclick',isset($additionalInfo['use_oneclick']) ? $additionalInfo['use_oneclick'] : 0);
205
- $this->_order->getPayment()->setAdditionalInformation('selected_oneclick_card',isset($additionalInfo['selected_oneclick_card']) ? $additionalInfo['selected_oneclick_card'] : 0);
206
- }
207
-
208
-
209
-
210
- return $this->_order; //because only one nominal item in cart is authorized and Hipay not manage many profiles
211
- }
212
-
213
-
214
- }
215
-
216
- Mage::throwException("An error occured. Profile Ids not present!");
217
-
218
-
219
-
220
- }
221
- else
222
- {
223
- $this->_order = Mage::getModel('sales/order')->load($this->getCheckout()->getLastOrderId());
224
- }
225
- }
226
-
227
- return $this->_order;
228
- }
229
-
230
- /**
231
- * Add method to calculate amount from recurring profile
232
- * @param Mage_Sales_Model_Recurring_Profile $profile
233
- * @return int $amount
234
- **/
235
- public function getAmountFromProfile(Mage_Sales_Model_Recurring_Profile $profile) {
236
- $amount = $profile->getBillingAmount() + $profile->getTaxAmount() + $profile->getShippingAmount();
237
-
238
- if($this->isInitialProfileOrder($profile))
239
- $amount += $profile->getInitAmount() ;
240
-
241
- return $amount;
242
- }
243
-
244
- protected function isInitialProfileOrder(Mage_Sales_Model_Recurring_Profile $profile)
245
- {
246
- if(count($profile->getChildOrderIds()) && current($profile->getChildOrderIds()) == "-1")
247
- return true;
248
-
249
- return false;
250
- }
251
-
252
-
253
- /**
254
- *
255
- * @return Mage_Checkout_Model_Session
256
- */
257
- protected function getCheckout()
258
- {
259
- return Mage::getSingleton('checkout/session');
260
- }
261
-
262
-
263
- public function updateDebitAmountAction()
264
- {
265
- /* @var $_helper Allopass_Hipay_Helper_Data */
266
- $_helper = Mage::helper('hipay');
267
- $response = array();
268
- $response['error'] = true;
269
- $response['success'] = false;
270
-
271
- $payment_profile_id = $this->getRequest()->getParam('payment_profile_id',false);
272
- $amount = $this->getCheckout()->getQuote()->getGrandTotal();
273
-
274
- $response['message'] = Mage::helper('hipay')->__('You will be debit of amount %s only after submit order.',Mage::app()->getStore()->getBaseCurrency()->format($amount, array(), true));
275
-
276
- if($payment_profile_id)
277
- {
278
- try {
279
-
280
- $splitPayment = $_helper->splitPayment((int)$payment_profile_id, $amount);
281
- $response['success'] = true;
282
- $response['error'] = false;
283
- $response['splitPayment'] = $splitPayment;
284
- $response['grandTotal'] = $amount;
285
- $firstAmount = $splitPayment[0]['amountToPay'];
286
- array_shift($splitPayment);
287
- $otherPayments = "<p><span>" . Mage::helper('hipay')->__("Your next payments:") . '</span><table class="data-table" id="split-payment-cc-table">';
288
- foreach ($splitPayment as $value)
289
- {
290
- $otherPayments .= '<tr>';
291
- $amount = Mage::app()->getStore()->getBaseCurrency()->format($value['amountToPay'], array(), true);
292
- $dateToPay = new Zend_Date($value['dateToPay']);
293
- $otherPayments .= '<td>' . $dateToPay->toString(Zend_Date::DATE_LONG) . "</td><td> " . $amount . '</td>' ;
294
- $otherPayments .= '</tr>';
295
- }
296
- $otherPayments .= '<table></p>';
297
-
298
- $response['labelSplitPayment'] = "<p><span>" . Mage::helper('hipay')->__('You will be debit of amount %s only after submit order.',Mage::app()->getStore()->getBaseCurrency()->format($firstAmount, array(), true)) . '</span></p>';
299
- $response['labelSplitPayment'] .= $otherPayments;
300
-
301
- } catch (Exception $e) {
302
303
- $response['message'] = $e->getMessage();
304
-
305
- }
306
-
307
-
308
- }
309
310
-
311
- $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
312
-
313
- }
314
- }
1
<?php
2
class Allopass_Hipay_Controller_Payment extends Mage_Core_Controller_Front_Action
3
{
4
+ /**
5
+ *
6
+ * @var Mage_Sales_Model_Order $order
7
+ */
8
+ protected $_order = null;
9
+
10
+
11
+ /**
12
+ * @return Mage_Core_Controller_Front_Action
13
+ */
14
+ public function preDispatch()
15
+ {
16
+ parent::preDispatch();
17
+ }
18
19
+
20
+ /**
21
+ *
22
+ * @return Allopass_Hipay_Model_Method_Abstract $methodInstance
23
+ */
24
+ protected function _getMethodInstance()
25
+ {
26
+ Mage::throwException("Method: '" . __METHOD__ . "' must be implemented!");
27
+ }
28
29
+ public function sendRequestAction()
30
+ {
31
+ $order = $this->getOrder();
32
+ $payment = $order->getPayment();
33
+ $amount= $order->getBaseTotalDue();
34
35
+ $methodInstance = $this->_getMethodInstance();
36
+ $useOrderCurrency = Mage::getStoreConfig('hipay/hipay_api/currency_transaction', Mage::app()->getStore());
37
38
+ if ($useOrderCurrency){
39
+ $amount = $order->getTotalDue();
40
+ }
41
+
42
+ try {
43
+ $redirectUrl = $methodInstance->place($payment, $amount);
44
+ } catch (Exception $e) {
45
+ Mage::logException($e);
46
+ $this->getCheckout()->addError($e->getMessage());
47
+ $this->_redirect('checkout/cart');
48
+ return $this;
49
+ }
50
+
51
+ $this->_redirectUrl($redirectUrl);
52
+
53
+ return $this;
54
+ }
55
+
56
+
57
+ public function acceptAction()
58
+ {
59
+ if (($profileIds = Mage::getSingleton('checkout/session')->getLastRecurringProfileIds())) {
60
+ if (is_array($profileIds)) {
61
+ /* @var $gatewayResponse Allopass_Hipay_Model_Api_Response_Gateway */
62
+ $gatewayResponse = Mage::getSingleton('hipay/api_response_gateway', $this->getRequest()->getParams());
63
+ $collection = Mage::getModel('sales/recurring_profile')->getCollection()
64
+ ->addFieldToFilter('profile_id', array('in' => $profileIds))
65
+ ;
66
+ $profiles = array();
67
+ foreach ($collection as $profile) {
68
+ //$referenceId = $gatewayResponse->getToken()."-".$profile->getId();
69
+ $additionalInfo = array();
70
+ $additionalInfo['ccType'] = $gatewayResponse->getBrand();
71
+ $additionalInfo['ccExpMonth'] = $gatewayResponse->getCardExpiryMonth() ;
72
+ $additionalInfo['ccExpYear'] = $gatewayResponse->getCardExpiryYear();
73
+ $additionalInfo['token'] = $gatewayResponse->getToken();
74
+ $additionalInfo['transaction_id'] = $gatewayResponse->getTransactionReference();
75
+ $profile->setAdditionalInfo($additionalInfo);
76
+ //$profile->setReferenceId($referenceId);
77
+ $profile->setState(Mage_Sales_Model_Recurring_Profile::STATE_ACTIVE);
78
+
79
+ $profile->save();
80
+ }
81
+ }
82
+
83
+
84
+ $session = Mage::getSingleton('checkout/session');
85
+ if (!$session->getLastSuccessQuoteId()) {
86
+ $session->setLastSuccessQuoteId($this->getOrder()->getIncrementId());
87
+ $session->setLastQuoteId($this->getOrder()->getId());
88
+ }
89
+ }
90
+
91
+ $this->processResponse();
92
+ $url_redirect = Mage::helper('hipay')->getCheckoutSuccessPage($this->getOrder()->getPayment());
93
94
if (preg_match('/http/',$url_redirect)){
95
$this->_redirectUrl($url_redirect);
96
}else{
97
$this->_redirect($url_redirect);
98
}
99
+
100
+ return $this;
101
+ }
102
+
103
+ public function pendingAction()
104
+ {
105
+ $this->processResponse();
106
+
107
+ $this->_redirect($this->_getMethodInstance()->getConfigData('pending_redirect_page'));
108
+
109
+ return $this;
110
+ }
111
+
112
+ public function declineAction()
113
+ {
114
+ $lastOrderId = $this->getOrder()->getIncrementId();
115
+
116
+ Mage::getSingleton('checkout/session')->setLastQuoteId($lastOrderId);
117
+ Mage::getSingleton('checkout/session')->setLastOrderId($lastOrderId);
118
+
119
+ $this->processResponse();
120
+
121
+ // Translate with Helper
122
+ Mage::getSingleton('checkout/session')->addError(Mage::helper('hipay')->__("Your payment is declined. Please retry checkout with another payment card."));
123
+
124
+ $this->_redirect(Mage::helper('hipay')->getCheckoutFailurePage($this->getOrder()->getPayment()));
125
+
126
+ return $this;
127
+ }
128
+
129
+
130
+ public function exceptionAction()
131
+ {
132
+ $lastOrderId = $this->getOrder()->getIncrementId();
133
+
134
+ Mage::getSingleton('checkout/session')->setLastQuoteId($lastOrderId);
135
+ Mage::getSingleton('checkout/session')->setLastOrderId($lastOrderId);
136
+
137
+ // Translate with Helper
138
+ Mage::getSingleton('checkout/session')->addError(Mage::helper('hipay')->__("An exception has occured. Please retry checkout."));
139
+
140
+ $this->_redirect('checkout/cart');
141
+ return $this;
142
+ }
143
+
144
+
145
+ public function cancelAction()
146
+ {
147
+ $this->processResponse();
148
+ $this->_redirect('checkout/cart');
149
+ return $this;
150
+ }
151
+
152
+ protected function processResponse()
153
+ {
154
+ $order = $this->getOrder();
155
+ $payment = $order->getPayment();
156
+
157
+ /* @var $gatewayResponse Allopass_Hipay_Model_Api_Response_Gateway */
158
+ $gatewayResponse = Mage::getSingleton('hipay/api_response_gateway', $this->getRequest()->getParams());
159
+
160
+ if (!$payment && $gatewayResponse->getData('order')){
161
+ $order = Mage::getModel('sales/order')->loadByIncrementId($gatewayResponse->getData('order'));
162
+ $this->_order = $order;
163
+ $payment = $order->getPayment();
164
+
165
+ $session = Mage::getSingleton('checkout/session');
166
+ if (!$session->getLastOrderId()) {
167
+ $session->setLastOrderId($this->getOrder()->getIncrementId());
168
+ }
169
+
170
+ if (!$session->getLastSuccessQuoteId()){
171
+ $session->setLastSuccessQuoteId($this->getOrder()->getIncrementId());
172
+ $session->setLastQuoteId($this->getOrder()->getId());
173
+ }
174
+ }else{
175
+ $order = $payment->getOrder();
176
+ }
177
178
+ return $this->_getMethodInstance()->processResponseToRedirect($gatewayResponse, $payment, $order->getBaseTotalDue());
179
+ }
180
181
+
182
+
183
+ /**
184
+ *
185
+ * @return Mage_Sales_Model_Order
186
+ */
187
+ protected function getOrder()
188
+ {
189
+ if (is_null($this->_order)) {
190
+ if (($profileIds = $this->getCheckout()->getLastRecurringProfileIds())) {
191
+ if (is_array($profileIds)) {
192
+ foreach ($profileIds as $profileId) {
193
+ /* @var $profile Mage_Sales_Model_Recurring_Profile */
194
+ $profile = Mage::getModel('sales/recurring_profile')->load($profileId);
195
+ /* @var $_helperRecurring Allopass_Hipayrecurring_Helper_Data */
196
+ $_helperRecurring = Mage::helper('hipayrecurring');
197
+
198
+ if ($_helperRecurring->isInitialProfileOrder($profile)) {
199
+ $this->_order = $_helperRecurring->createOrderFromProfile($profile);
200
+ } else {
201
+ $orderId = current($profile->getChildOrderIds());
202
+ $this->_order = Mage::getModel('sales/order')->load($orderId);
203
+
204
+ $additionalInfo = $profile->getAdditionalInfo();
205
+
206
+ $this->_order->getPayment()->setCcType(isset($additionalInfo['ccType']) ? $additionalInfo['ccType'] : "");
207
+ $this->_order->getPayment()->setCcExpMonth(isset($additionalInfo['ccExpMonth']) ? $additionalInfo['ccExpMonth'] : "");
208
+ $this->_order->getPayment()->setCcExpYear(isset($additionalInfo['ccExpYear']) ? $additionalInfo['ccExpYear'] : "");
209
+ $this->_order->getPayment()->setAdditionalInformation('token', isset($additionalInfo['token']) ? $additionalInfo['token'] : "");
210
+ $this->_order->getPayment()->setAdditionalInformation('create_oneclick', isset($additionalInfo['create_oneclick']) ? $additionalInfo['create_oneclick'] : 1);
211
+ $this->_order->getPayment()->setAdditionalInformation('use_oneclick', isset($additionalInfo['use_oneclick']) ? $additionalInfo['use_oneclick'] : 0);
212
+ $this->_order->getPayment()->setAdditionalInformation('selected_oneclick_card', isset($additionalInfo['selected_oneclick_card']) ? $additionalInfo['selected_oneclick_card'] : 0);
213
+ }
214
+
215
+
216
+
217
+ return $this->_order; //because only one nominal item in cart is authorized and Hipay not manage many profiles
218
+ }
219
+ }
220
+
221
+ Mage::throwException("An error occured. Profile Ids not present!");
222
+ } else {
223
+ $this->_order = Mage::getModel('sales/order')->load($this->getCheckout()->getLastOrderId());
224
+ }
225
+ }
226
+
227
+ return $this->_order;
228
+ }
229
+
230
+ /**
231
+ * Add method to calculate amount from recurring profile
232
+ * @param Mage_Sales_Model_Recurring_Profile $profile
233
+ * @return int $amount
234
+ **/
235
+ public function getAmountFromProfile(Mage_Sales_Model_Recurring_Profile $profile)
236
+ {
237
+ $amount = $profile->getBillingAmount() + $profile->getTaxAmount() + $profile->getShippingAmount();
238
+
239
+ if ($this->isInitialProfileOrder($profile)) {
240
+ $amount += $profile->getInitAmount() ;
241
+ }
242
+
243
+ return $amount;
244
+ }
245
+
246
+ protected function isInitialProfileOrder(Mage_Sales_Model_Recurring_Profile $profile)
247
+ {
248
+ if (count($profile->getChildOrderIds()) && current($profile->getChildOrderIds()) == "-1") {
249
+ return true;
250
+ }
251
+
252
+ return false;
253
+ }
254
+
255
+
256
+ /**
257
+ *
258
+ * @return Mage_Checkout_Model_Session
259
+ */
260
+ protected function getCheckout()
261
+ {
262
+ return Mage::getSingleton('checkout/session');
263
+ }
264
+
265
+
266
+ public function updateDebitAmountAction()
267
+ {
268
+ /* @var $_helper Allopass_Hipay_Helper_Data */
269
+ $_helper = Mage::helper('hipay');
270
+ $response = array();
271
+ $response['error'] = true;
272
+ $response['success'] = false;
273
+
274
+ $payment_profile_id = $this->getRequest()->getParam('payment_profile_id', false);
275
+ $amount = $this->getCheckout()->getQuote()->getGrandTotal();
276
+ $useOrderCurrency = Mage::getStoreConfig('hipay/hipay_api/currency_transaction', Mage::app()->getStore());
277
+
278
+ if ($useOrderCurrency) {
279
+ $currency = Mage::app()->getStore()->getCurrency();
280
+ } else {
281
+ $currency = Mage::app()->getStore()->getBaseCurrency();
282
+ }
283
284
+ $response['message'] = Mage::helper('hipay')->__('You will be debit of amount %s only after submit order.', $currency->format($amount, array(), true));
285
+
286
+ if ($payment_profile_id) {
287
+ try {
288
+ $splitPayment = $_helper->splitPayment((int)$payment_profile_id, $amount);
289
+ $response['success'] = true;
290
+ $response['error'] = false;
291
+ $response['splitPayment'] = $splitPayment;
292
+ $response['grandTotal'] = $amount;
293
+ $firstAmount = $splitPayment[0]['amountToPay'];
294
+ array_shift($splitPayment);
295
+ $otherPayments = "<p><span>" . Mage::helper('hipay')->__("Your next payments:") . '</span><table class="data-table" id="split-payment-cc-table">';
296
+ foreach ($splitPayment as $value) {
297
+ $otherPayments .= '<tr>';
298
+ $amount = $currency->format($value['amountToPay'], array(), true);
299
+ $dateToPay = new Zend_Date($value['dateToPay']);
300
+ $otherPayments .= '<td>' . $dateToPay->toString(Zend_Date::DATE_LONG) . "</td><td> " . $amount . '</td>' ;
301
+ $otherPayments .= '</tr>';
302
+ }
303
+ $otherPayments .= '<table></p>';
304
+
305
+ $response['labelSplitPayment'] = "<p><span>" . Mage::helper('hipay')->__('You will be debit of amount %s only after submit order.', $currency->format($firstAmount, array(), true)) . '</span></p>';
306
+ $response['labelSplitPayment'] .= $otherPayments;
307
+ } catch (Exception $e) {
308
+ $response['message'] = $e->getMessage();
309
+ }
310
+ }
311
312
+
313
+ $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
314
+ }
315
+ }
app/code/community/Allopass/Hipay/Helper/Data.php CHANGED
@@ -1,623 +1,1149 @@
1
<?php
2
class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
3
{
4
-
5
- /**
6
- *
7
- * @param Allopass_Hipay_Model_PaymentProfile|int $profile
8
- * @param float $amount
9
- */
10
- public function splitPayment($profile,$amount)
11
- {
12
- $paymentsSplit = array();
13
-
14
- if(is_int($profile))
15
- $profile = Mage::getModel('hipay/paymentProfile')->load($profile);
16
-
17
- if($profile)
18
- {
19
- $maxCycles = (int)$profile->getPeriodMaxCycles();
20
-
21
- $periodFrequency = (int)$profile->getPeriodFrequency();
22
- $periodUnit = $profile->getPeriodUnit();
23
-
24
- $todayDate = new Zend_Date();
25
-
26
- if($maxCycles < 1)
27
- Mage::throwException("Period max cycles is equals zero or negative for Payment Profile ID: ".$profile->getId());
28
-
29
-
30
- $part = (int)($amount / $maxCycles);
31
- //$reste = $amount%$maxCycles;
32
- $fmod = fmod($amount, $maxCycles);
33
-
34
- for ($i=0;$i<=($maxCycles-1);$i++)
35
- {
36
- $j = $i - 1;
37
- $todayClone = clone $todayDate;
38
- switch ($periodUnit)
39
- {
40
- case Allopass_Hipay_Model_PaymentProfile::PERIOD_UNIT_MONTH:
41
- {
42
- $dateToPay = $todayClone->addMonth($periodFrequency+$j)->getDate()->toString('yyyy-MM-dd');
43
- break;
44
- }
45
- case Allopass_Hipay_Model_PaymentProfile::PERIOD_UNIT_DAY:
46
- {
47
- $dateToPay = $todayClone->addDay($periodFrequency+$j)->getDate()->toString('yyyy-MM-dd');
48
-
49
- break;
50
- }
51
- case Allopass_Hipay_Model_PaymentProfile::PERIOD_UNIT_SEMI_MONTH://TODO test this case !!!
52
- {
53
- $dateToPay = $todayClone->addDay(15 + $periodFrequency+$j)->getDate()->toString('yyyy-MM-dd');
54
- break;
55
- }
56
- case Allopass_Hipay_Model_PaymentProfile::PERIOD_UNIT_WEEK:
57
- {
58
- $dateToPay = $todayClone->addWeek($periodFrequency+$j)->getDate()->toString('yyyy-MM-dd');
59
- break;
60
- }
61
- case Allopass_Hipay_Model_PaymentProfile::PERIOD_UNIT_YEAR:
62
- {
63
- $dateToPay = $todayClone->addYear($periodFrequency+$j)->getDate()->toString('yyyy-MM-dd');
64
- break;
65
- }
66
- }
67
-
68
- $amountToPay = $i==0 ? ($part + $fmod) : $part;
69
- $paymentsSplit[] = array('dateToPay'=>$dateToPay,'amountToPay'=>$amountToPay);
70
- }
71
-
72
- return $paymentsSplit;
73
-
74
- }
75
-
76
- Mage::throwException("Payment Profile not found");
77
-
78
- }
79
-
80
- /**
81
- *
82
- * @param Mage_Sales_Model_Order $order
83
- * @param Allopass_Hipay_Model_PaymentProfile|int $profile $profile
84
- */
85
- public function insertSplitPayment($order,$profile,$customerId,$cardToken)
86
- {
87
-
88
-
89
-
90
- if(is_int($profile))
91
- $profile = Mage::getModel('hipay/paymentProfile')->load($profile);
92
-
93
- if(!$this->splitPaymentsExists($order->getId()))
94
- {
95
-
96
- $paymentsSplit = $this->splitPayment($profile, $order->getBaseGrandTotal());
97
-
98
-
99
- //remove first element because is already paid
100
- array_shift($paymentsSplit);
101
-
102
-
103
- //remove last element because the first split is already paid
104
- //array_pop($paymentsSplit);
105
-
106
- foreach ($paymentsSplit as $split)
107
- {
108
- $splitPayment = Mage::getModel('hipay/splitPayment');
109
- $data = array('order_id'=>$order->getId(),
110
- 'real_order_id'=>(int)$order->getRealOrderId(),
111
- 'customer_id'=>$customerId,
112
- 'card_token'=>$cardToken,
113
- 'total_amount'=>$order->getBaseGrandTotal(),
114
- 'amount_to_pay'=>$split['amountToPay'],
115
- 'date_to_pay'=>$split['dateToPay'],
116
- 'method_code'=>$order->getPayment()->getMethod(),
117
- 'status'=>Allopass_Hipay_Model_SplitPayment::SPLIT_PAYMENT_STATUS_PENDING,
118
- );
119
-
120
- $splitPayment->setData($data);
121
-
122
-
123
- try {
124
- $splitPayment->save();
125
- } catch (Exception $e) {
126
-
127
- Mage::throwException("Error on save split payments!");
128
- }
129
- }
130
-
131
- }
132
- }
133
-
134
-
135
- /**
136
- *
137
- * @param int $orderId
138
- * @return boolean
139
- */
140
- public function splitPaymentsExists($orderId)
141
- {
142
- $collection = Mage::getModel('hipay/splitPayment')->getCollection()->addFieldToFilter('order_id',$orderId);
143
- if($collection->count())
144
- return true;
145
-
146
- return false;
147
- }
148
-
149
- public function getHipayMethods()
150
- {
151
- $methods = array();
152
-
153
- foreach (Mage::getStoreConfig('payment') as $code => $data) {
154
- if(strpos($code, 'hipay') !== false)
155
- {
156
- if (isset($data['model']))
157
- $methods[$code] = $data['model'];
158
- }
159
- }
160
-
161
- return $methods;
162
-
163
- }
164
-
165
- public function checkSignature($signature,$fromNotification = false,$response = null)
166
- {
167
- $passphrase =$this->getConfig()->getSecretPassphrase();
168
- if(!is_null($response))
169
- {
170
- $orderArr = $response->getOrder();
171
-
172
- /* @var $order Mage_Sales_Model_Order */
173
- $order = Mage::getModel('sales/order')->loadByIncrementId($orderArr['id']);
174
-
175
- if($order->getId())
176
- {
177
- $method = $order->getPayment()->getMethodInstance();
178
- if($method->getConfigData('is_test_mode'))
179
- {
180
- $passphrase = $this->getConfig()->getSecretPassphraseTest();
181
- }
182
- }
183
- }
184
-
185
-
186
- if(empty($passphrase) || empty($signature))
187
- return true;
188
-
189
- if($fromNotification)
190
- {
191
- $rawPostData = file_get_contents("php://input");
192
- if($signature == sha1($rawPostData . $passphrase));
193
- return true;
194
-
195
- return false;
196
- }
197
-
198
-
199
- $parameters = $this->_getRequest()->getParams();
200
- $string2compute = "";
201
- unset($parameters['hash']);
202
- ksort($parameters);
203
- foreach ($parameters as $name => $value) {
204
- if (strlen($value) > 0) {
205
- $string2compute .= $name . $value . $passphrase;
206
- }
207
- }
208
-
209
- if(sha1($string2compute) == $signature)
210
- return true;
211
-
212
- return false;
213
- }
214
-
215
- public function checkIfCcExpDateIsValid($customer)
216
- {
217
- if(is_int($customer))
218
- $customer = Mage::getModel('customer/customer')->load($customer);
219
-
220
- $expDate = $customer->getHipayCcExpDate();
221
- $alias = $customer->getHipayAliasOneclick();
222
- if(!empty($expDate) && !empty($alias))
223
- {
224
- list($expMonth,$expYear) = explode("-", $expDate);
225
-
226
- return $this->checkIfCcIsExpired($expMonth, $expYear);
227
-
228
- /*$today = new Zend_Date(Mage::app()->getLocale()->storeTimeStamp());
229
-
230
- $currentYear = (int)$today->getYear()->toString("YY");
231
- $currentMonth = (int)$today->getMonth()->toString("MM");
232
-
233
- if($currentYear > (int)$expYear)
234
- return false;
235
-
236
- if($currentYear == (int)$expYear && $currentMonth > (int)$expMonth)
237
- return false;
238
-
239
- return true;*/
240
-
241
- }
242
-
243
- return false;
244
- }
245
-
246
- public function checkIfCcIsExpired($expMonth,$expYear)
247
- {
248
- $today = new Zend_Date(Mage::app()->getLocale()->storeTimeStamp());
249
-
250
- $currentYear = (int)$today->getYear()->toString("YY");
251
- $currentMonth = (int)$today->getMonth()->toString("MM");
252
-
253
- if($currentYear > (int)$expYear)
254
- return false;
255
-
256
- if($currentYear == (int)$expYear && $currentMonth > (int)$expMonth)
257
- return false;
258
-
259
- return true;
260
- }
261
-
262
- /**
263
- *
264
- * @param Mage_Customer_Model_Customer $customer
265
- * @param Allopass_Hipay_Model_Api_Response_Gateway $response
266
- * @param boolean $isRecurring
267
- */
268
- public function responseToCustomer($customer,$response,$isRecurring = false)
269
- {
270
-
271
- $paymentMethod = $response->getPaymentMethod();
272
- $paymentProduct = $response->getPaymentProduct();
273
- $token = isset($paymentMethod['token']) ? $paymentMethod['token'] : $response->getData('cardtoken');
274
-
275
- if($isRecurring)
276
- $customer->setHipayAliasRecurring($token);
277
- else
278
- $customer->setHipayAliasOneclick($token );
279
-
280
- if(isset($paymentMethod['card_expiry_month']) && $paymentMethod['card_expiry_year'])
281
- $customer->setHipayCcExpDate($paymentMethod['card_expiry_month'] . "-" . $paymentMethod['card_expiry_year'] );
282
- else
283
- $customer->setHipayCcExpDate(substr($response->getData('cardexpiry'), 4,2) . "-" . substr($response->getData('cardexpiry'), 0,4) );
284
-
285
- $customer->setHipayCcNumberEnc(isset($paymentMethod['pan']) ? $paymentMethod['pan'] : $response->getData('cardpan'));
286
- //$customer->setHipayCcType(isset($paymentMethod['brand']) ? strtolower($paymentMethod['brand']) : strtolower($response->getData('cardbrand')));
287
- $customer->setHipayCcType($paymentProduct);
288
-
289
- $customer->getResource()->saveAttribute($customer, 'hipay_alias_oneclick');
290
- $customer->getResource()->saveAttribute($customer, 'hipay_cc_exp_date');
291
- $customer->getResource()->saveAttribute($customer, 'hipay_cc_number_enc');
292
- $customer->getResource()->saveAttribute($customer, 'hipay_cc_type');
293
-
294
- return $this;
295
- }
296
-
297
- protected function _cardTokenExist($ccToken,$customer_id=0)
298
- {
299
- $cards = Mage::getResourceModel('hipay/card_collection')
300
- ->addFieldToSelect('card_id')
301
- ->addFieldToFilter('cc_token', $ccToken);
302
-
303
- if($customer_id > 0)
304
- {
305
- $cards->addFieldToFilter('customer_id', $customer_id);
306
- }
307
-
308
- return $cards->count() > 0;
309
- }
310
-
311
- public function createCustomerCardFromResponse($customerId,$response,$isRecurring = false)
312
- {
313
-
314
- $paymentMethod = $response->getPaymentMethod();
315
- $paymentProduct = $response->getPaymentProduct();
316
- $token = isset($paymentMethod['token']) ? $paymentMethod['token'] : $response->getData('cardtoken');
317
-
318
- if($this->_cardTokenExist($token,$customerId))
319
- {
320
- return null;
321
- }
322
-
323
- $pan = isset($paymentMethod['pan']) ? $paymentMethod['pan'] : $response->getData('cardpan');
324
-
325
- $newCard = Mage::getModel('hipay/card');
326
- $newCard->setCustomerId($customerId);
327
- $newCard->setCcToken($token);
328
- $newCard->setCcNumberEnc($pan);
329
- $newCard->setCcType($paymentProduct);
330
- $newCard->setCcStatus(Allopass_Hipay_Model_Card::STATUS_ENABLED);
331
- $newCard->setName($this->__('Card %s - %s',$paymentProduct,$pan));
332
-
333
- if(isset($paymentMethod['card_expiry_month']) && $paymentMethod['card_expiry_year'])
334
- {
335
- $newCard->setCcExpMonth($paymentMethod['card_expiry_month']);
336
- $newCard->setCcExpYear($paymentMethod['card_expiry_year'] );
337
- }
338
- else
339
- {
340
- $newCard->setCcExpMonth(substr($response->getData('cardexpiry'), 4,2));
341
- $newCard->setCcExpYear(substr($response->getData('cardexpiry'), 0,4));
342
- }
343
-
344
- try {
345
- $newCard->save();
346
- return $newCard;
347
- } catch (Exception $e) {
348
- Mage::logException($e);
349
- }
350
-
351
- }
352
-
353
- public function reAddToCart($incrementId) {
354
-
355
- $cart = Mage::getSingleton('checkout/cart');
356
- $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
357
-
358
- if ($order->getId()) {
359
- $items = $order->getItemsCollection();
360
- foreach ($items as $item) {
361
- try {
362
- $cart->addOrderItem($item);
363
- } catch (Mage_Core_Exception $e) {
364
- if (Mage::getSingleton('checkout/session')->getUseNotice(true)) {
365
- Mage::getSingleton('checkout/session')->addNotice($e->getMessage());
366
- } else {
367
- Mage::getSingleton('checkout/session')->addError($e->getMessage());
368
- }
369
- } catch (Exception $e) {
370
- Mage::getSingleton('checkout/session')->addException($e, Mage::helper('checkout')->__('Cannot add the item to shopping cart.')
371
- );
372
- }
373
- }
374
- }
375
-
376
- $cart->save();
377
- }
378
-
379
-
380
- /**
381
- * Return message for gateway transaction request
382
- *
383
- * @param Mage_Payment_Model_Info $payment
384
- * @param string $requestType
385
- * @param string $lastTransactionId
386
- * @param float $amount
387
- * @param string $exception
388
- * @return bool|string
389
- */
390
- public function getTransactionMessage($payment, $requestType, $lastTransactionId, $amount = false,
391
- $exception = false,$additionalMessage = false
392
- ) {
393
- return $this->getExtendedTransactionMessage(
394
- $payment, $requestType, $lastTransactionId, $amount, $exception,$additionalMessage
395
- );
396
- }
397
-
398
- /**
399
- * Return message for gateway transaction request
400
- *
401
- * @param Mage_Payment_Model_Info $payment
402
- * @param string $requestType
403
- * @param string $lastTransactionId
404
- * @param float $amount
405
- * @param string $exception
406
- * @param string $additionalMessage Custom message, which will be added to the end of generated message
407
- * @return bool|string
408
- */
409
- public function getExtendedTransactionMessage($payment, $requestType, $lastTransactionId, $amount = false,
410
- $exception = false, $additionalMessage = false
411
- ) {
412
- $operation = 'Operation: ' . $requestType;// $this->_getOperation($requestType);
413
-
414
- if (!$operation) {
415
- return false;
416
- }
417
-
418
- if ($amount) {
419
- $amount = $this->__('amount: %s', $this->_formatPrice($payment, $amount));
420
- }
421
-
422
- if ($exception) {
423
- $result = $this->__('failed');
424
- } else {
425
- $result = $this->__('successful');
426
- }
427
-
428
- $card = $this->__('Credit Card: xxxx-%s', $payment->getCcLast4());
429
- $cardType = $this->__('Card type: %s',ucfirst($this->getCcTypeHipay($payment->getCcType())));
430
-
431
- $pattern = '%s - %s.<br /> %s<br /> %s.<br /> %s';
432
- $texts = array($operation,$result,$card, $amount,$cardType);
433
-
434
- if (!is_null($lastTransactionId)) {
435
- $pattern .= '<br />%s.';
436
- $texts[] = $this->__('Hipay Transaction ID %s', $lastTransactionId);
437
- }
438
-
439
- if ($additionalMessage) {
440
- $pattern .= '<br />%s.';
441
- $texts[] = $additionalMessage;
442
- }
443
- //$pattern .= '<br />%s';
444
- //$texts[] = $exception;
445
-
446
- return call_user_func_array(array($this, '__'), array_merge(array($pattern), $texts));
447
- }
448
-
449
- /**
450
- * Format price with currency sign
451
- * @param Mage_Payment_Model_Info $payment
452
- * @param float $amount
453
- * @return string
454
- */
455
- protected function _formatPrice($payment, $amount)
456
- {
457
- return $payment->getOrder()->getBaseCurrency()->formatTxt($amount);
458
- }
459
-
460
-
461
- /**
462
- * Send email id payment is in Fraud status
463
- * @param Mage_Customer_Model_Customer $receiver
464
- * @param Mage_Sales_Model_Order $order
465
- * @param string $message
466
- * @return Mage_Checkout_Helper_Data
467
- */
468
- public function sendFraudPaymentEmail($receiver,$order, $message,$email_key = 'fraud_payment')
469
- {
470
- $translate = Mage::getSingleton('core/translate');
471
- /* @var $translate Mage_Core_Model_Translate */
472
- $translate->setTranslateInline(false);
473
-
474
- $mailTemplate = Mage::getModel('core/email_template');
475
- /* @var $mailTemplate Mage_Core_Model_Email_Template */
476
-
477
- $template = Mage::getStoreConfig('hipay/'.$email_key.'/template', $order->getStoreId());
478
-
479
- $copyTo = $this->_getEmails('hipay/'.$email_key.'/copy_to', $order->getStoreId());
480
- $copyMethod = Mage::getStoreConfig('hipay/'.$email_key.'/copy_method', $order->getStoreId());
481
- if ($copyTo && $copyMethod == 'bcc') {
482
- $mailTemplate->addBcc($copyTo);
483
- }
484
-
485
- $sendTo = array(
486
- array(
487
- 'email' => $receiver->getEmail(),
488
- 'name' => $receiver->getName()
489
- )
490
- );
491
-
492
- if ($copyTo && $copyMethod == 'copy') {
493
- foreach ($copyTo as $email) {
494
- $sendTo[] = array(
495
- 'email' => $email,
496
- 'name' => null
497
- );
498
- }
499
- }
500
- $shippingMethod = '';
501
- if ($shippingInfo = $order->getShippingAddress()->getShippingMethod()) {
502
- $data = explode('_', $shippingInfo);
503
- $shippingMethod = $data[0];
504
- }
505
-
506
- $paymentMethod = '';
507
- if ($paymentInfo = $order->getPayment()) {
508
- $paymentMethod = $paymentInfo->getMethod();
509
- }
510
-
511
- $items = '';
512
- foreach ($order->getAllVisibleItems() as $_item) {
513
- /* @var $_item Mage_Sales_Model_Quote_Item */
514
- $items .= $_item->getProduct()->getName() . ' x '. $_item->getQty() . ' '
515
- . $order->getStoreCurrencyCode() . ' '
516
- . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
517
- }
518
- $total = $order->getStoreCurrencyCode() . ' ' . $order->getGrandTotal();
519
-
520
- foreach ($sendTo as $recipient) {
521
- $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$order->getStoreId()))
522
- ->sendTransactional(
523
- $template,
524
- Mage::getStoreConfig('hipay/'.$email_key.'/identity', $order->getStoreId()),
525
- $recipient['email'],
526
- $recipient['name'],
527
- array(
528
- 'reason' => $message,
529
- 'dateAndTime' => Mage::app()->getLocale()->date(),
530
- 'customer' => $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname(),
531
- 'customerEmail' => $order->getCustomerEmail(),
532
- 'billingAddress' => $order->getBillingAddress(),
533
- 'shippingAddress' => $order->getShippingAddress(),
534
- 'shippingMethod' => Mage::getStoreConfig('carriers/'.$shippingMethod.'/title'),
535
- 'paymentMethod' => Mage::getStoreConfig('payment/'.$paymentMethod.'/title'),
536
- 'items' => nl2br($items),
537
- 'total' => $total
538
- )
539
- );
540
- }
541
-
542
- $translate->setTranslateInline(true);
543
-
544
- return $this;
545
- }
546
-
547
- protected function _getEmails($configPath, $storeId)
548
- {
549
- $data = Mage::getStoreConfig($configPath, $storeId);
550
- if (!empty($data)) {
551
- return explode(',', $data);
552
- }
553
- return false;
554
- }
555
-
556
- /**
557
- *
558
- * @return Allopass_Hipay_Model_Config
559
- */
560
- protected function getConfig()
561
- {
562
- return Mage::getSingleton('hipay/config');
563
- }
564
-
565
- public function getCcTypeHipay($ccTypeMagento,$exceptionIfNotFound = false)
566
- {
567
- $ccTypes = Mage::getSingleton('hipay/config')->getCcTypesHipay();
568
-
569
- if(isset($ccTypes[$ccTypeMagento]))
570
- return $ccTypes[$ccTypeMagento];
571
-
572
- if($exceptionIfNotFound)
573
- Mage::throwException(Mage::helper('hipay')->__("Code Credit Card Type Hipay not found!"));
574
-
575
- return $ccTypeMagento;
576
- }
577
- /*
578
- * TPPMAG1-2 - JPN
579
- */
580
- public function is3dSecure($use3dSecure, $config3dsRules, $payment = false)
581
- {
582
- $params = 0;
583
- if($use3dSecure > 0 && !$payment){
584
- $params = 1;
585
- }else{
586
- switch ((int)$use3dSecure) {
587
- case 1:
588
- $params = 1;
589
- break;
590
- case 2:
591
- case 3:
592
- /* @var $rule Allopass_Hipay_Model_Rule */
593
- $rule = Mage::getModel('hipay/rule')->load($config3dsRules);
594
- if($rule->getId() && $rule->validate($payment->getOrder()) )
595
- {
596
- $params = 1;
597
- if((int)$use3dSecure == 3)//case for force 3ds if rules are validated
598
- $params = 2;
599
-
600
- }
601
- break;
602
- case 4:
603
- $params = 2;
604
- break;
605
- }
606
- }
607
- return $params;
608
- }
609
-
610
- /**
611
- * @param Mage_Sales_Model_Order_Payment $payment
612
- *
613
- * @return string
614
- */
615
- public function getCheckoutSuccessPage($payment) {
616
- // if empty success page magento
617
- return empty(Mage::getStoreConfig('payment/'.$payment->getMethod().'/success_redirect_page')) ?
618
- Mage::getUrl('checkout/onepage/success') :
619
- Mage::getStoreConfig('payment/'.$payment->getMethod().'/success_redirect_page');
620
- }
621
-
622
-
623
- }
1
<?php
2
+
3
class Allopass_Hipay_Helper_Data extends Mage_Core_Helper_Abstract
4
{
5
+ const TYPE_ITEM_BASKET_GOOD = "good";
6
+ const TYPE_ITEM_BASKET_FEE = "fee";
7
+ const TYPE_ITEM_BASKET_DISCOUNT = "discount";
8
+
9
+
10
+ const FIELD_BASE_INVOICED = 'row_invoiced';
11
+ const FIELD_BASE_DISCOUNT_INVOICED = 'discount_invoiced';
12
+ const FIELD_BASE_TAX_INVOICED = 'tax_invoiced';
13
+ const FIELD_BASE_ROW = 'row_total_incl_tax';
14
+ const FIELD_BASE_DISCOUNT = 'discount_amount';
15
+ const FIELD_BASE_TAX = 'tax_amount';
16
+ const FIELD_BASE_REFUNDED = 'amount_refunded';
17
+ const FIELD_DISCOUNT_REFUNDED = 'discount_refunded';
18
+ const FIELD_TAX_REFUNDED = 'tax_refunded';
19
+ const FIELD_BASE_DISCOUNT_REFUNDED = 'base_discount_refunded';
20
+ const FIELD_BASE_TAX_REFUNDED = '_base_tax_refunded';
21
+
22
+ const FIELD_BASE_TAX_HIDDEN_INVOICED = 'hidden_tax_invoiced';
23
+ const FIELD_BASE_TAX_HIDDEN_REFUNDED = 'hidden_tax_amount';
24
+ const FIELD_BASE_TAX_HIDDEN = 'hidden_tax_refunded';
25
+
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
32
+ *
33
+ * @param Mage_Sales_Model_Order
34
+ * @return json
35
+ */
36
+ public function getTaxeRateInformation($order)
37
+ {
38
+ $products = $order->getAllItems();
39
+ $taxPercentbasket = 0;
40
+
41
+ // =============================================================== //
42
+ // For each product in basket
43
+ // =============================================================== //
44
+ foreach ($products as $key => $product) {
45
+ $item = array();
46
+ // For configurable products
47
+ if ($product->getParentItem()) {
48
+ $productParent = $product->getParentItem();
49
+
50
+ // Check if simple product override configurable his parent
51
+ $tax_percent = $product->getData('tax_percent');
52
+
53
+ if (!empty($tax_percent) && $product->getData('tax_percent') > 0) {
54
+ $product->getData('tax_percent');
55
+ } else {
56
+ $productParent->getData('tax_percent');
57
+ }
58
+ } else {
59
+ $taxPercent = $product->getData('tax_percent');
60
+ }
61
+
62
+ // Checking
63
+ if ($product->getProductType() == 'simple') {
64
+ // Check if taxe rate is the same for all products
65
+ if ($taxPercentbasket == 0) {
66
+ $taxPercentbasket = $taxPercent;
67
+ } else {
68
+ if ($taxPercentbasket != $taxPercent) {
69
+ $taxPercentbasket = 0;
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
+ return $taxPercentbasket;
76
+ }
77
+
78
+
79
+ /**
80
+ * Add item discount in basket
81
+ *
82
+ * @param $order
83
+ * @param $refund
84
+ * @param $capture
85
+ * @return array
86
+ */
87
+ private function processDiscount($order,$action, $basket)
88
+ {
89
+ $coupon = $order->getCouponCode();
90
+ if (!empty($coupon)) {
91
+ $item = array();
92
+ $item['type'] = Allopass_Hipay_Helper_Data::TYPE_ITEM_BASKET_DISCOUNT;
93
+ $item['product_reference'] = $order->getCouponCode();
94
+ $item['name'] = $order->getDiscountDescription();
95
+ $item['discount'] = 0;
96
+ $item['total_amount'] = 0;
97
+ $item['quantity'] = '1';
98
+ $item['unit_price'] = '0';
99
+ $basket[] = $item;
100
+ }
101
+
102
+ return $basket;
103
+ }
104
+
105
+ /**
106
+ * Add item Shipping in basket
107
+ *
108
+ * @param $order
109
+ * @param $refund
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
+
145
+ /*
146
+ * Calculate unit price for one product and quantity
147
+ *
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
+ }
160
+
161
+ /**
162
+ *
163
+ * Add product in the basket
164
+ *
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;
179
+ break;
180
+ default:
181
+ $base_discount = Allopass_Hipay_Helper_Data::FIELD_BASE_DISCOUNT;
182
+ $base_hidden_tax = Allopass_Hipay_Helper_Data::FIELD_BASE_TAX_HIDDEN;
183
+ }
184
+
185
+ if ($action == Allopass_Hipay_Helper_Data::STATE_CAPTURE || $action == Allopass_Hipay_Helper_Data::STATE_REFUND) {
186
+ $item['quantity'] = intval($product->getData('qty'));
187
+ } else {
188
+ $item['quantity'] = intval($product->getData('qty_ordered'));
189
+ }
190
+
191
+ $sku = trim($product->getData('sku'));
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 )
224
+ if (Mage::getStoreConfig('hipay/hipay_basket/attribute_ean', Mage::app()->getStore())) {
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 {
232
+ // The custom attribute have to be present in quote and order
233
+ $ean = $product->getData($attribute);
234
+ }
235
+ }
236
+
237
+ $item['type'] = Allopass_Hipay_Helper_Data::TYPE_ITEM_BASKET_GOOD;
238
+ $item['tax_rate'] = Mage::app()->getStore()->roundPrice($taxPercent);
239
+ $item['unit_price'] = round($unitPrice, 3);
240
+ $item['total_amount'] = $total_amount;
241
+
242
+ if (!empty($ean) && $ean != 'null') {
243
+ $item['european_article_numbering'] = $ean;
244
+ }
245
+ $item['product_reference'] = $sku;
246
+ $item['name'] = $product->getName();
247
+
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
+ *
259
+ * @param Mage_Sales_Model_Order
260
+ * @param STATE_REFUND OU STATE_CAPTURE
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
+
269
+ // =============================================================== //
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) {
280
+ if ($product->isChildrenCalculated()) {
281
+ foreach ($product->getChildren() as $children) {
282
+ $basket[] = $this->addItem($children, $action);
283
+ }
284
+ } else {
285
+ $basket[] = $this->addItem($product, $action);
286
+ }
287
+ } else {
288
+ $basket[] = $this->addItem($product, $action);
289
+ }
290
+ }
291
+ }
292
+
293
+ // Partial capture
294
+ if ($action == Allopass_Hipay_Helper_Data::STATE_CAPTURE) {
295
+ if ($order->hasInvoices()) {
296
+ $invoice = $order->getInvoiceCollection()->getLastItem();
297
+
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
+ }
309
+ }
310
+ }
311
+
312
+ // Refund
313
+ if ($action == Allopass_Hipay_Helper_Data::STATE_REFUND) {
314
+ $creditMemo = $payment->getCreditmemo();
315
+
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
+ }
326
+ }
327
+
328
+ }
329
+
330
+ return json_encode($basket);
331
+ }
332
+
333
+ /**
334
+ *
335
+ * @param Allopass_Hipay_Model_PaymentProfile|int $profile
336
+ * @param float $amount
337
+ */
338
+ public function splitPayment(
339
+ $profile,
340
+ $amount,
341
+ $taxAmount = 0
342
+ ) {
343
+ $paymentsSplit = array();
344
+
345
+ if (is_int($profile)) {
346
+ $profile = Mage::getModel('hipay/paymentProfile')->load($profile);
347
+ }
348
+
349
+ if ($profile) {
350
+ $maxCycles = (int)$profile->getPeriodMaxCycles();
351
+
352
+ $periodFrequency = (int)$profile->getPeriodFrequency();
353
+ $periodUnit = $profile->getPeriodUnit();
354
+
355
+ $todayDate = new Zend_Date();
356
+
357
+ if ($maxCycles < 1) {
358
+ Mage::throwException("Period max cycles is equals zero or negative for Payment Profile ID: " . $profile->getId());
359
+ }
360
+
361
+ $part = (int)($amount / $maxCycles);
362
+ $taxPart = $taxAmount / $maxCycles;
363
+
364
+ //$reste = $amount%$maxCycles;
365
+ $fmod = fmod($amount, $maxCycles);
366
+
367
+ for ($i = 0; $i <= ($maxCycles - 1); $i++) {
368
+ $j = $i - 1;
369
+ $todayClone = clone $todayDate;
370
+ switch ($periodUnit) {
371
+ case Allopass_Hipay_Model_PaymentProfile::PERIOD_UNIT_MONTH: {
372
+ $dateToPay = $todayClone->addMonth($periodFrequency + $j)->getDate()->toString('yyyy-MM-dd');
373
+ break;
374
+ }
375
+ case Allopass_Hipay_Model_PaymentProfile::PERIOD_UNIT_DAY: {
376
+ $dateToPay = $todayClone->addDay($periodFrequency + $j)->getDate()->toString('yyyy-MM-dd');
377
+
378
+ break;
379
+ }
380
+ case Allopass_Hipay_Model_PaymentProfile::PERIOD_UNIT_SEMI_MONTH://TODO test this case !!!
381
+ {
382
+ $dateToPay = $todayClone->addDay(15 + $periodFrequency + $j)->getDate()->toString('yyyy-MM-dd');
383
+ break;
384
+ }
385
+ case Allopass_Hipay_Model_PaymentProfile::PERIOD_UNIT_WEEK: {
386
+ $dateToPay = $todayClone->addWeek($periodFrequency + $j)->getDate()->toString('yyyy-MM-dd');
387
+ break;
388
+ }
389
+ case Allopass_Hipay_Model_PaymentProfile::PERIOD_UNIT_YEAR: {
390
+ $dateToPay = $todayClone->addYear($periodFrequency + $j)->getDate()->toString('yyyy-MM-dd');
391
+ break;
392
+ }
393
+ }
394
+
395
+ $amountToPay = $i == 0 ? ($part + $fmod) : $part;
396
+ $paymentsSplit[] = array(
397
+ 'dateToPay' => $dateToPay,
398
+ 'amountToPay' => $amountToPay,
399
+ 'taxAmountToPay' => $taxPart,
400
+ 'totalAmount' => $taxAmount
401
+ );
402
+ }
403
+
404
+ return $paymentsSplit;
405
+ }
406
+
407
+ Mage::throwException("Payment Profile not found");
408
+ }
409
+
410
+ /**
411
+ *
412
+ * @param Mage_Sales_Model_Order $order
413
+ * @param Allopass_Hipay_Model_PaymentProfile|int $profile $profile
414
+ */
415
+ public function insertSplitPayment(
416
+ $order,
417
+ $profile,
418
+ $customerId,
419
+ $cardToken
420
+ ) {
421
+ $useOrderCurrency = Mage::getStoreConfig('hipay/hipay_api/currency_transaction', Mage::app()->getStore());
422
+
423
+ if ($useOrderCurrency) {
424
+ $total = $order->getGrandTotal();
425
+ } else {
426
+ $total = $order->getBaseGrandTotal();
427
+ }
428
+
429
+ if (is_int($profile)) {
430
+ $profile = Mage::getModel('hipay/paymentProfile')->load($profile);
431
+ }
432
+
433
+ if (!$this->splitPaymentsExists($order->getId())) {
434
+ $taxAmount = $order->getTaxAmount();
435
+ $paymentsSplit = $this->splitPayment($profile, $total, $taxAmount);
436
+
437
+ //remove last element because the first split is already paid
438
+ //array_pop($paymentsSplit);
439
+ $numberSplit = 1;
440
+ foreach ($paymentsSplit as $split) {
441
+ $splitPayment = Mage::getModel('hipay/splitPayment');
442
+ $data = array(
443
+ 'order_id' => $order->getId(),
444
+ 'real_order_id' => (int)$order->getRealOrderId(),
445
+ 'customer_id' => $customerId,
446
+ 'card_token' => $cardToken,
447
+ 'total_amount' => $total,
448
+ 'amount_to_pay' => $split['amountToPay'],
449
+ 'tax_amount_to_pay' => $split['taxAmountToPay'],
450
+ 'total_tax_amount' => $split['totalAmount'],
451
+ 'date_to_pay' => $split['dateToPay'],
452
+ 'method_code' => $order->getPayment()->getMethod(),
453
+ 'status' => Allopass_Hipay_Model_SplitPayment::SPLIT_PAYMENT_STATUS_PENDING,
454
+ 'split_number' => strval($numberSplit) . '-' . strval(count($paymentsSplit)),
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
+
462
+ $splitPayment->setData($data);
463
+
464
+ try {
465
+ $splitPayment->save();
466
+ } catch (Exception $e) {
467
+ Mage::throwException("Error on save split payments!");
468
+ }
469
+
470
+ $numberSplit++;
471
+ }
472
+ }
473
+ }
474
+
475
+
476
+ /**
477
+ *
478
+ * @param int $orderId
479
+ * @return boolean
480
+ */
481
+ public function splitPaymentsExists(
482
+ $orderId
483
+ ) {
484
+ $collection = Mage::getModel('hipay/splitPayment')->getCollection()->addFieldToFilter('order_id', $orderId);
485
+ if ($collection->count()) {
486
+ return true;
487
+ }
488
+
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,
510
+ $response = null
511
+ ) {
512
+ $passphrase = $this->getConfig()->getSecretPassphrase();
513
+ if (!is_null($response)) {
514
+ $orderArr = $response->getOrder();
515
+
516
+ /* @var $order Mage_Sales_Model_Order */
517
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderArr['id']);
518
+
519
+ if ($order->getId()) {
520
+ $method = $order->getPayment()->getMethodInstance();
521
+ if ($method->getConfigData('is_test_mode')) {
522
+ $passphrase = $this->getConfig()->getSecretPassphraseTest();
523
+ }
524
+ }
525
+ }
526
+
527
+
528
+ if (empty($passphrase) || empty($signature)) {
529
+ return true;
530
+ }
531
+
532
+ if ($fromNotification) {
533
+ $rawPostData = file_get_contents("php://input");
534
+ if ($signature == sha1($rawPostData . $passphrase)) {
535
+ ;
536
+ }
537
+ return true;
538
+
539
+ return false;
540
+ }
541
+
542
+
543
+ $parameters = $this->_getRequest()->getParams();
544
+ $string2compute = "";
545
+ unset($parameters['hash']);
546
+ ksort($parameters);
547
+ foreach ($parameters as $name => $value) {
548
+ if (strlen($value) > 0) {
549
+ $string2compute .= $name . $value . $passphrase;
550
+ }
551
+ }
552
+
553
+ if (sha1($string2compute) == $signature) {
554
+ return true;
555
+ }
556
+
557
+ return false;
558
+ }
559
+
560
+ public function checkIfCcExpDateIsValid(
561
+ $customer
562
+ ) {
563
+ if (is_int($customer)) {
564
+ $customer = Mage::getModel('customer/customer')->load($customer);
565
+ }
566
+
567
+ $expDate = $customer->getHipayCcExpDate();
568
+ $alias = $customer->getHipayAliasOneclick();
569
+ if (!empty($expDate) && !empty($alias)) {
570
+ list($expMonth, $expYear) = explode("-", $expDate);
571
+
572
+ return $this->checkIfCcIsExpired($expMonth, $expYear);
573
+
574
+ /*$today = new Zend_Date(Mage::app()->getLocale()->storeTimeStamp());
575
+
576
+ $currentYear = (int)$today->getYear()->toString("YY");
577
+ $currentMonth = (int)$today->getMonth()->toString("MM");
578
+
579
+ if($currentYear > (int)$expYear)
580
+ return false;
581
+
582
+ if($currentYear == (int)$expYear && $currentMonth > (int)$expMonth)
583
+ return false;
584
+
585
+ return true;*/
586
+ }
587
+
588
+ return false;
589
+ }
590
+
591
+ public function checkIfCcIsExpired(
592
+ $expMonth,
593
+ $expYear
594
+ ) {
595
+ $today = new Zend_Date(Mage::app()->getLocale()->storeTimeStamp());
596
+
597
+ $currentYear = (int)$today->getYear()->toString("YY");
598
+ $currentMonth = (int)$today->getMonth()->toString("MM");
599
+
600
+ if ($currentYear > (int)$expYear) {
601
+ return false;
602
+ }
603
+
604
+ if ($currentYear == (int)$expYear && $currentMonth > (int)$expMonth) {
605
+ return false;
606
+ }
607
+
608
+ return true;
609
+ }
610
+
611
+ /**
612
+ *
613
+ * @param Mage_Customer_Model_Customer $customer
614
+ * @param Allopass_Hipay_Model_Api_Response_Gateway $response
615
+ * @param boolean $isRecurring
616
+ */
617
+ public function responseToCustomer(
618
+ $customer,
619
+ $response,
620
+ $isRecurring = false
621
+ ) {
622
+ $paymentMethod = $response->getPaymentMethod();
623
+ $paymentProduct = $response->getPaymentProduct();
624
+ $token = isset($paymentMethod['token']) ? $paymentMethod['token'] : $response->getData('cardtoken');
625
+
626
+ if ($isRecurring) {
627
+ $customer->setHipayAliasRecurring($token);
628
+ } else {
629
+ $customer->setHipayAliasOneclick($token);
630
+ }
631
+
632
+ if (isset($paymentMethod['card_expiry_month']) && $paymentMethod['card_expiry_year']) {
633
+ $customer->setHipayCcExpDate($paymentMethod['card_expiry_month'] . "-" . $paymentMethod['card_expiry_year']);
634
+ } else {
635
+ $customer->setHipayCcExpDate(substr($response->getData('cardexpiry'), 4,
636
+ 2) . "-" . substr($response->getData('cardexpiry'), 0, 4));
637
+ }
638
+
639
+ $customer->setHipayCcNumberEnc(isset($paymentMethod['pan']) ? $paymentMethod['pan'] : $response->getData('cardpan'));
640
+ //$customer->setHipayCcType(isset($paymentMethod['brand']) ? strtolower($paymentMethod['brand']) : strtolower($response->getData('cardbrand')));
641
+ $customer->setHipayCcType($paymentProduct);
642
+
643
+ $customer->getResource()->saveAttribute($customer, 'hipay_alias_oneclick');
644
+ $customer->getResource()->saveAttribute($customer, 'hipay_cc_exp_date');
645
+ $customer->getResource()->saveAttribute($customer, 'hipay_cc_number_enc');
646
+ $customer->getResource()->saveAttribute($customer, 'hipay_cc_type');
647
+
648
+ return $this;
649
+ }
650
+
651
+ protected function _cardTokenExist(
652
+ $ccToken,
653
+ $customer_id = 0
654
+ ) {
655
+ $cards = Mage::getResourceModel('hipay/card_collection')
656
+ ->addFieldToSelect('card_id')
657
+ ->addFieldToFilter('cc_token', $ccToken);
658
+
659
+ if ($customer_id > 0) {
660
+ $cards->addFieldToFilter('customer_id', $customer_id);
661
+ }
662
+
663
+ return $cards->count() > 0;
664
+ }
665
+
666
+ public function createCustomerCardFromResponse(
667
+ $customerId,
668
+ $response,
669
+ $isRecurring = false
670
+ ) {
671
+ $paymentMethod = $response->getPaymentMethod();
672
+ $paymentProduct = $response->getPaymentProduct();
673
+ $token = isset($paymentMethod['token']) ? $paymentMethod['token'] : $response->getData('cardtoken');
674
+
675
+ if ($this->_cardTokenExist($token, $customerId)) {
676
+ return null;
677
+ }
678
+
679
+ $pan = isset($paymentMethod['pan']) ? $paymentMethod['pan'] : $response->getData('cardpan');
680
+
681
+ $newCard = Mage::getModel('hipay/card');
682
+ $newCard->setCustomerId($customerId);
683
+ $newCard->setCcToken($token);
684
+ $newCard->setCcNumberEnc($pan);
685
+ $newCard->setCcType($paymentProduct);
686
+ $newCard->setCcStatus(Allopass_Hipay_Model_Card::STATUS_ENABLED);
687
+ $newCard->setName($this->__('Card %s - %s', $paymentProduct, $pan));
688
+
689
+ if (isset($paymentMethod['card_expiry_month']) && $paymentMethod['card_expiry_year']) {
690
+ $newCard->setCcExpMonth($paymentMethod['card_expiry_month']);
691
+ $newCard->setCcExpYear($paymentMethod['card_expiry_year']);
692
+ } else {
693
+ $newCard->setCcExpMonth(substr($response->getData('cardexpiry'), 4, 2));
694
+ $newCard->setCcExpYear(substr($response->getData('cardexpiry'), 0, 4));
695
+ }
696
+
697
+ try {
698
+ $newCard->save();
699
+ return $newCard;
700
+ } catch (Exception $e) {
701
+ Mage::logException($e);
702
+ }
703
+ }
704
+
705
+ public function reAddToCart(
706
+ $incrementId
707
+ ) {
708
+ $cart = Mage::getSingleton('checkout/cart');
709
+ $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId);
710
+
711
+ if ($order->getId()) {
712
+ $items = $order->getItemsCollection();
713
+ foreach ($items as $item) {
714
+ try {
715
+ $cart->addOrderItem($item);
716
+ } catch (Mage_Core_Exception $e) {
717
+ if (Mage::getSingleton('checkout/session')->getUseNotice(true)) {
718
+ Mage::getSingleton('checkout/session')->addNotice($e->getMessage());
719
+ } else {
720
+ Mage::getSingleton('checkout/session')->addError($e->getMessage());
721
+ }
722
+ } catch (Exception $e) {
723
+ Mage::getSingleton('checkout/session')->addException($e,
724
+ Mage::helper('checkout')->__('Cannot add the item to shopping cart.')
725
+ );
726
+ }
727
+ }
728
+ }
729
+
730
+ $cart->save();
731
+ }
732
+
733
+
734
+ /**
735
+ * Return message for gateway transaction request
736
+ *
737
+ * @param Mage_Payment_Model_Info $payment
738
+ * @param string $requestType
739
+ * @param string $lastTransactionId
740
+ * @param float $amount
741
+ * @param string $exception
742
+ * @return bool|string
743
+ */
744
+ public function getTransactionMessage(
745
+ $payment,
746
+ $requestType,
747
+ $lastTransactionId,
748
+ $amount = false,
749
+ $exception = false,
750
+ $additionalMessage = false
751
+ ) {
752
+ return $this->getExtendedTransactionMessage(
753
+ $payment, $requestType, $lastTransactionId, $amount, $exception, $additionalMessage
754
+ );
755
+ }
756
+
757
+ /**
758
+ * Return message for gateway transaction request
759
+ *
760
+ * @param Mage_Payment_Model_Info $payment
761
+ * @param string $requestType
762
+ * @param string $lastTransactionId
763
+ * @param float $amount
764
+ * @param string $exception
765
+ * @param string $additionalMessage Custom message, which will be added to the end of generated message
766
+ * @return bool|string
767
+ */
768
+ public function getExtendedTransactionMessage(
769
+ $payment,
770
+ $requestType,
771
+ $lastTransactionId,
772
+ $amount = false,
773
+ $exception = false,
774
+ $additionalMessage = false
775
+ ) {
776
+ $operation = 'Operation: ' . $requestType;// $this->_getOperation($requestType);
777
+
778
+ if (!$operation) {
779
+ return false;
780
+ }
781
+
782
+ if ($amount) {
783
+ $amount = $this->__('amount: %s', $this->_formatPrice($payment, $amount));
784
+ }
785
+
786
+ if ($exception) {
787
+ $result = $this->__('failed');
788
+ } else {
789
+ $result = $this->__('successful');
790
+ }
791
+
792
+ $card = $this->__('Credit Card: xxxx-%s', $payment->getCcLast4());
793
+ $cardType = $this->__('Card type: %s', ucfirst($this->getCcTypeHipay($payment->getCcType())));
794
+
795
+ $pattern = '%s - %s.<br /> %s<br /> %s.<br /> %s';
796
+ $texts = array($operation, $result, $card, $amount, $cardType);
797
+
798
+ if (!is_null($lastTransactionId)) {
799
+ $pattern .= '<br />%s.';
800
+ $texts[] = $this->__('Hipay Transaction ID %s', $lastTransactionId);
801
+ }
802
+
803
+ if ($additionalMessage) {
804
+ $pattern .= '<br />%s.';
805
+ $texts[] = $additionalMessage;
806
+ }
807
+ //$pattern .= '<br />%s';
808
+ //$texts[] = $exception;
809
+
810
+ return call_user_func_array(array($this, '__'), array_merge(array($pattern), $texts));
811
+ }
812
+
813
+ /**
814
+ * Format price with currency sign
815
+ * @param Mage_Payment_Model_Info $payment
816
+ * @param float $amount
817
+ * @return string
818
+ */
819
+ protected function _formatPrice(
820
+ $payment,
821
+ $amount
822
+ ) {
823
+ return $payment->getOrder()->getBaseCurrency()->formatTxt($amount);
824
+ }
825
+
826
+
827
+ /**
828
+ * Send email id payment is in Fraud status
829
+ * @param Mage_Customer_Model_Customer $receiver
830
+ * @param Mage_Sales_Model_Order $order
831
+ * @param string $message
832
+ * @return Mage_Checkout_Helper_Data
833
+ */
834
+ public function sendFraudPaymentEmail(
835
+ $receiver,
836
+ $order,
837
+ $message,
838
+ $email_key = 'fraud_payment'
839
+ ) {
840
+ $translate = Mage::getSingleton('core/translate');
841
+ /* @var $translate Mage_Core_Model_Translate */
842
+ $translate->setTranslateInline(false);
843
+
844
+ $mailTemplate = Mage::getModel('core/email_template');
845
+ /* @var $mailTemplate Mage_Core_Model_Email_Template */
846
+
847
+ $template = Mage::getStoreConfig('hipay/' . $email_key . '/template', $order->getStoreId());
848
+
849
+ $copyTo = $this->_getEmails('hipay/' . $email_key . '/copy_to', $order->getStoreId());
850
+ $copyMethod = Mage::getStoreConfig('hipay/' . $email_key . '/copy_method', $order->getStoreId());
851
+ if ($copyTo && $copyMethod == 'bcc') {
852
+ $mailTemplate->addBcc($copyTo);
853
+ }
854
+
855
+ $sendTo = array(
856
+ array(
857
+ 'email' => $receiver->getEmail(),
858
+ 'name' => $receiver->getName()
859
+ )
860
+ );
861
+
862
+ if ($copyTo && $copyMethod == 'copy') {
863
+ foreach ($copyTo as $email) {
864
+ $sendTo[] = array(
865
+ 'email' => $email,
866
+ 'name' => null
867
+ );
868
+ }
869
+ }
870
+ $shippingMethod = '';
871
+ if ($shippingInfo = $order->getShippingAddress()->getShippingMethod()) {
872
+ $data = explode('_', $shippingInfo);
873
+ $shippingMethod = $data[0];
874
+ }
875
+
876
+ $paymentMethod = '';
877
+ if ($paymentInfo = $order->getPayment()) {
878
+ $paymentMethod = $paymentInfo->getMethod();
879
+ }
880
+
881
+ $items = '';
882
+ foreach ($order->getAllVisibleItems() as $_item) {
883
+ /* @var $_item Mage_Sales_Model_Quote_Item */
884
+ $items .= $_item->getProduct()->getName() . ' x ' . $_item->getQty() . ' '
885
+ . $order->getStoreCurrencyCode() . ' '
886
+ . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
887
+ }
888
+ $total = $order->getStoreCurrencyCode() . ' ' . $order->getGrandTotal();
889
+
890
+ foreach ($sendTo as $recipient) {
891
+ $mailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $order->getStoreId()))
892
+ ->sendTransactional(
893
+ $template,
894
+ Mage::getStoreConfig('hipay/' . $email_key . '/identity', $order->getStoreId()),
895
+ $recipient['email'],
896
+ $recipient['name'],
897
+ array(
898
+ 'reason' => $message,
899
+ 'dateAndTime' => Mage::app()->getLocale()->date(),
900
+ 'customer' => $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname(),
901
+ 'customerEmail' => $order->getCustomerEmail(),
902
+ 'billingAddress' => $order->getBillingAddress(),
903
+ 'shippingAddress' => $order->getShippingAddress(),
904
+ 'shippingMethod' => Mage::getStoreConfig('carriers/' . $shippingMethod . '/title'),
905
+ 'paymentMethod' => Mage::getStoreConfig('payment/' . $paymentMethod . '/title'),
906
+ 'items' => nl2br($items),
907
+ 'total' => $total
908
+ )
909
+ );
910
+ }
911
+
912
+ $translate->setTranslateInline(true);
913
+
914
+ return $this;
915
+ }
916
+
917
+ protected function _getEmails(
918
+ $configPath,
919
+ $storeId
920
+ ) {
921
+ $data = Mage::getStoreConfig($configPath, $storeId);
922
+ if (!empty($data)) {
923
+ return explode(',', $data);
924
+ }
925
+ return false;
926
+ }
927
+
928
+ /**
929
+ *
930
+ * @return Allopass_Hipay_Model_Config
931
+ */
932
+ protected function getConfig()
933
+ {
934
+ return Mage::getSingleton('hipay/config');
935
+ }
936
+
937
+ public function getCcTypeHipay(
938
+ $ccTypeMagento,
939
+ $exceptionIfNotFound = false
940
+ ) {
941
+ $ccTypes = Mage::getSingleton('hipay/config')->getCcTypesHipay();
942
+
943
+ if (isset($ccTypes[$ccTypeMagento])) {
944
+ return $ccTypes[$ccTypeMagento];
945
+ }
946
+
947
+ if ($exceptionIfNotFound) {
948
+ Mage::throwException(Mage::helper('hipay')->__("Code Credit Card Type Hipay not found!"));
949
+ }
950
+
951
+ return $ccTypeMagento;
952
+ }
953
+
954
+ /*
955
+ * TPPMAG1-2 - JPN
956
+ */
957
+ public function is3dSecure(
958
+ $use3dSecure,
959
+ $config3dsRules,
960
+ $payment = false
961
+ ) {
962
+ $params = 0;
963
+ if ($use3dSecure > 0 && !$payment) {
964
+ $params = 1;
965
+ } else {
966
+ switch ((int)$use3dSecure) {
967
+ case 1:
968
+ $params = 1;
969
+ break;
970
+ case 2:
971
+ case 3:
972
+ /* @var $rule Allopass_Hipay_Model_Rule */
973
+ $rule = Mage::getModel('hipay/rule')->load($config3dsRules);
974
+ if ($rule->getId() && $rule->validate($payment->getOrder())) {
975
+ $params = 1;
976
+
977
+ if ((int)$use3dSecure == 3) {//case for force 3ds if rules are validated
978
+ $params = 2;
979
+ }
980
+ }
981
+ break;
982
+ case 4:
983
+ $params = 2;
984
+ break;
985
+ }
986
+ }
987
+ return $params;
988
+ }
989
+
990
+ /**
991
+ * @param Mage_Sales_Model_Order_Payment $payment
992
+ *
993
+ * @return string
994
+ */
995
+ public function getCheckoutSuccessPage($payment)
996
+ {
997
+ // if empty success page magento
998
+ $url = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/success_redirect_page');
999
+ return empty($url) ? Mage::getUrl('checkout/onepage/success') : $url;
1000
+ }
1001
+
1002
+ /**
1003
+ * @param Mage_Sales_Model_Order_Payment $payment
1004
+ *
1005
+ * @return string
1006
+ */
1007
+ public function getCheckoutFailurePage($payment)
1008
+ {
1009
+ return is_null(Mage::getStoreConfig('payment/' . $payment->getMethod() . '/failure_redirect_page')) ?
1010
+ 'checkout/onepage/failure' :
1011
+ Mage::getStoreConfig('payment/' . $payment->getMethod() . '/failure_redirect_page');
1012
+ }
1013
+
1014
+ /**
1015
+ * Return informations for TPP about the request
1016
+ *
1017
+ * @return json
1018
+ */
1019
+ public function getRequestSource()
1020
+ {
1021
+ $request = array();
1022
+
1023
+ $request['source'] = 'CMS';
1024
+ $request['brand'] = 'magento';
1025
+ $request['brand_version'] = Mage::getVersion();
1026
+ $request['integration_version'] = strval(Mage::getConfig()->getNode('modules')->Allopass_Hipay->version);
1027
+
1028
+ return json_encode($request);
1029
+ }
1030
+
1031
+ /**
1032
+ * Return customs data from Hipay
1033
+ *
1034
+ * @param array $payment
1035
+ * @param float $amount
1036
+ *
1037
+ */
1038
+ public function getCustomData(
1039
+ $payment,
1040
+ $amount,
1041
+ $method,
1042
+ $split_number = null
1043
+ ) {
1044
+ $customData = array();
1045
+
1046
+ // Shipping description
1047
+ $customData['shipping_description'] = $payment->getOrder()->getShippingDescription();
1048
+
1049
+ // Customer information
1050
+ $customer = $payment->getOrder()->getCustomerId();
1051
+ $customerData = Mage::getModel('customer/customer')->load($customer);
1052
+ $codeCustomer = Mage::getModel('customer/group')->load($customerData->getGroupId())->getCustomerGroupCode();
1053
+ $customData['customer_code'] = $codeCustomer;
1054
+
1055
+ // Method payment information
1056
+ $customData['payment_code'] = $method->getCode();
1057
+ $customData['display_iframe'] = $method->getConfigData('display_iframe');
1058
+
1059
+ // Payment type
1060
+ if ($split_number) {
1061
+ $customData['payment_type'] = 'Split ' . $split_number;
1062
+ }
1063
+
1064
+ // Use Onclick
1065
+ if ($payment->getAdditionalInformation('use_oneclick') == '1') {
1066
+ $customData['payment_type'] = 'OneClick';
1067
+ }
1068
+
1069
+ return $customData;
1070
+ }
1071
+
1072
+ /**
1073
+ *
1074
+ * Send an email to customer to pay his order
1075
+ *
1076
+ * @param $receiver
1077
+ * @param $order
1078
+ * @param $message
1079
+ * @param string $email_key
1080
+ * @return $this
1081
+ */
1082
+ public function sendLinkPaymentEmail(
1083
+ $receiver,
1084
+ $order
1085
+ ) {