Mundipagg_Integracao - Version 2.12.05

Version Notes

- bugfixes and performance improves

Download this release

Release Info

Developer mundipagg
Extension Mundipagg_Integracao
Version 2.12.05
Comparing to
See all releases


Code changes from version 2.11.02 to 2.12.05

Files changed (22) hide show
  1. app/code/community/Uecommerce/Mundipagg/Block/Parcelamento.php +67 -30
  2. app/code/community/Uecommerce/Mundipagg/Block/Standard/Partial.php +8 -0
  3. app/code/community/Uecommerce/Mundipagg/Helper/Data.php +0 -21
  4. app/code/community/Uecommerce/Mundipagg/Helper/Recurrence.php +38 -0
  5. app/code/community/Uecommerce/Mundipagg/Model/Adminvalidators/Offlineretry.php +1 -0
  6. app/code/community/Uecommerce/Mundipagg/Model/Api.php +34 -39
  7. app/code/community/Uecommerce/Mundipagg/Model/Observer.php +646 -296
  8. app/code/community/Uecommerce/Mundipagg/Model/Quote/Address/Interest.php +13 -2
  9. app/code/community/Uecommerce/Mundipagg/Model/Recurrencepayment.php +131 -0
  10. app/code/community/Uecommerce/Mundipagg/Model/Recurrency.php +5 -67
  11. app/code/community/Uecommerce/Mundipagg/Model/Source/Cctypes.php +2 -2
  12. app/code/community/Uecommerce/Mundipagg/Model/Standard.php +2461 -2435
  13. app/code/community/Uecommerce/Mundipagg/etc/config.xml +52 -9
  14. app/code/community/Uecommerce/Mundipagg/etc/system.xml +97 -0
  15. app/code/community/Uecommerce/Mundipagg/sql/mundipagg_setup/upgrade-2.11.01-2.12.01.php +123 -0
  16. app/code/community/Uecommerce/Mundipagg/sql/mundipagg_setup/upgrade-2.12.01-2.12.02.php +123 -0
  17. app/design/adminhtml/default/default/template/mundipagg/form.phtml +395 -299
  18. app/design/frontend/base/default/template/mundipagg/parcelamento.phtml +41 -4
  19. app/design/frontend/rwd/default/template/mundipagg/form.phtml +296 -150
  20. app/locale/en_US/Uecommerce_Mundipagg.csv +21 -1
  21. app/locale/pt_BR/Uecommerce_Mundipagg.csv +15 -1
  22. package.xml +6 -6
app/code/community/Uecommerce/Mundipagg/Block/Parcelamento.php CHANGED
@@ -1,36 +1,13 @@
1
<?php
2
- /**
3
- * Uecommerce
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Uecommerce EULA.
8
- * It is also available through the world-wide-web at this URL:
9
- * http://www.uecommerce.com.br/
10
- *
11
- * DISCLAIMER
12
- *
13
- * Do not edit or add to this file if you wish to upgrade the extension
14
- * to newer versions in the future. If you wish to customize the extension
15
- * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
- *
17
- * @category Uecommerce
18
- * @package Uecommerce_Mundipagg
19
- * @copyright Copyright (c) 2012 Uecommerce (http://www.uecommerce.com.br/)
20
- * @license http://www.uecommerce.com.br/
21
- */
22
-
23
- /**
24
- * Mundipagg Payment module
25
- *
26
- * @category Uecommerce
27
- * @package Uecommerce_Mundipagg
28
- * @author Uecommerce Dev Team
29
- */
30
31
class Uecommerce_Mundipagg_Block_Parcelamento extends Mage_Core_Block_Template
32
{
33
protected $_price = null;
34
35
protected function _construct()
36
{
@@ -44,6 +21,11 @@ class Uecommerce_Mundipagg_Block_Parcelamento extends Mage_Core_Block_Template
44
{
45
$this->setPrice($this->getData('price'));
46
$this->setParcelamentoProduto($this->getData('parcelamento_produto'));
47
}
48
49
public function setPrice($price)
@@ -66,7 +48,62 @@ class Uecommerce_Mundipagg_Block_Parcelamento extends Mage_Core_Block_Template
66
return $this->_parcelamento;
67
}
68
69
- /**
70
* Call it on category or product page
71
* echo $this->getLayout()->createBlock("mundipagg/parcelamento")->setData('price', $_product->getPrice())->toHtml();
72
*/
@@ -76,7 +113,7 @@ class Uecommerce_Mundipagg_Block_Parcelamento extends Mage_Core_Block_Template
76
77
if ($active) {
78
$parcelamento = Mage::getStoreConfig('payment/mundipagg_standard/product_pages_installment_default');
79
-
80
$installmentsHelper = Mage::helper('mundipagg/installments');
81
$installmentsHelper->displayTotal = false;
82
$parcelamentoMax = $installmentsHelper->getInstallmentForCreditCardType($parcelamento, $this->getPrice());
1
<?php
2
3
class Uecommerce_Mundipagg_Block_Parcelamento extends Mage_Core_Block_Template
4
{
5
protected $_price = null;
6
+ protected $_mundipagg_recurrence = null;
7
+ protected $_mundipagg_recurrences = null;
8
+ protected $_mundipagg_frequency = null;
9
+ protected $_mundipagg_recurrence_mix = null;
10
+ protected $_mundipagg_recurrence_discount = null;
11
12
protected function _construct()
13
{
21
{
22
$this->setPrice($this->getData('price'));
23
$this->setParcelamentoProduto($this->getData('parcelamento_produto'));
24
+ $this->setMundipaggRecurrence($this->getData('mundipagg_recurrence'));
25
+ $this->setMundipaggRecurrences($this->getData('mundipagg_recurrences'));
26
+ $this->setMundipaggFrequency($this->getData('mundipagg_frequency_enum'));
27
+ $this->setMundipaggRecurrenceMix($this->getData('mundipagg_recurrence_mix'));
28
+ $this->setMundipaggRecurrenceDiscount($this->getData('mundipagg_recurrence_discount'));
29
}
30
31
public function setPrice($price)
48
return $this->_parcelamento;
49
}
50
51
+ function getMundipaggRecurrence()
52
+ {
53
+ return $this->_mundipagg_recurrence;
54
+ }
55
+
56
+ function setMundipaggRecurrence($_mundipagg_recurrence)
57
+ {
58
+ $this->_mundipagg_recurrence = $_mundipagg_recurrence;
59
+ return $this;
60
+ }
61
+
62
+ function getMundipaggRecurrences()
63
+ {
64
+ return $this->_mundipagg_recurrences;
65
+ }
66
+
67
+ function getMundipaggFrequency()
68
+ {
69
+ return $this->_mundipagg_frequency;
70
+ }
71
+
72
+ function getMundipaggRecurrenceMix()
73
+ {
74
+ return $this->_mundipagg_recurrence_mix;
75
+ }
76
+
77
+ function getMundipaggRecurrenceDiscount()
78
+ {
79
+ return $this->_mundipagg_recurrence_discount;
80
+ }
81
+
82
+ function setMundipaggRecurrences($_mundipagg_recurrences)
83
+ {
84
+ $this->_mundipagg_recurrences = $_mundipagg_recurrences;
85
+ return $this;
86
+ }
87
+
88
+ function setMundipaggFrequency($_mundipagg_frequency)
89
+ {
90
+ $this->_mundipagg_frequency = $_mundipagg_frequency;
91
+ return $this;
92
+ }
93
+
94
+ function setMundipaggRecurrenceMix($_mundipagg_recurrence_mix)
95
+ {
96
+ $this->_mundipagg_recurrence_mix = $_mundipagg_recurrence_mix;
97
+ return $this;
98
+ }
99
+
100
+ function setMundipaggRecurrenceDiscount($_mundipagg_recurrence_discount)
101
+ {
102
+ $this->_mundipagg_recurrence_discount = $_mundipagg_recurrence_discount;
103
+ return $this;
104
+ }
105
+
106
+ /**
107
* Call it on category or product page
108
* echo $this->getLayout()->createBlock("mundipagg/parcelamento")->setData('price', $_product->getPrice())->toHtml();
109
*/
113
114
if ($active) {
115
$parcelamento = Mage::getStoreConfig('payment/mundipagg_standard/product_pages_installment_default');
116
+
117
$installmentsHelper = Mage::helper('mundipagg/installments');
118
$installmentsHelper->displayTotal = false;
119
$parcelamentoMax = $installmentsHelper->getInstallmentForCreditCardType($parcelamento, $this->getPrice());
app/code/community/Uecommerce/Mundipagg/Block/Standard/Partial.php CHANGED
@@ -110,6 +110,14 @@ class Uecommerce_Mundipagg_Block_Standard_Partial extends Mage_Checkout_Block_On
110
{
111
return Mage::getModel('mundipagg/fivecreditcards');
112
}
113
114
/**
115
* Get last quote that is in session
110
{
111
return Mage::getModel('mundipagg/fivecreditcards');
112
}
113
+
114
+ /**
115
+ * Return recurrence payment model
116
+ */
117
+ public function getRecurrencePayment()
118
+ {
119
+ return Mage::getModel('mundipagg/recurrencepayment');
120
+ }
121
122
/**
123
* Get last quote that is in session
app/code/community/Uecommerce/Mundipagg/Helper/Data.php CHANGED
@@ -105,18 +105,6 @@ class Uecommerce_Mundipagg_Helper_Data extends Mage_Core_Helper_Abstract {
105
case 'mundipagg_twocreditcards':
106
$num = 2;
107
break;
108
-
109
- case 'mundipagg_threecreditcards':
110
- $num = 3;
111
- break;
112
-
113
- case 'mundipagg_fourcreditcards':
114
- $num = 4;
115
- break;
116
-
117
- case 'mundipagg_fivecreditcards':
118
- $num = 5;
119
- break;
120
}
121
122
return $num;
@@ -138,15 +126,6 @@ class Uecommerce_Mundipagg_Helper_Data extends Mage_Core_Helper_Abstract {
138
case '2':
139
$method = 'mundipagg_twocreditcards';
140
break;
141
- case '3':
142
- $method = 'mundipagg_threecreditcards';
143
- break;
144
- case '4':
145
- $method = 'mundipagg_fourcreditcards';
146
- break;
147
- case '5':
148
- $method = 'mundipagg_fivecreditcards';
149
- break;
150
}
151
152
return $method;
105
case 'mundipagg_twocreditcards':
106
$num = 2;
107
break;
108
}
109
110
return $num;
126
case '2':
127
$method = 'mundipagg_twocreditcards';
128
break;
129
}
130
131
return $method;
app/code/community/Uecommerce/Mundipagg/Helper/Recurrence.php ADDED
@@ -0,0 +1,38 @@
1
+ <?php
2
+
3
+ class Uecommerce_Mundipagg_Helper_Recurrence extends Mage_Core_Helper_Abstract {
4
+ public function teste() {
5
+ $session = Mage::getSingleton('admin/session');
6
+
7
+ if ($session->isLoggedIn()) {
8
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
9
+ } else {
10
+ $quote = (Mage::getModel('checkout/type_onepage') !== false) ? Mage::getModel('checkout/type_onepage')->getQuote() : Mage::getModel('checkout/session')->getQuote();
11
+ }
12
+
13
+ // Get pre-authorized amount
14
+ $authorizedAmount = Mage::getSingleton('checkout/session')->getAuthorizedAmount();
15
+ $amount = (double)$quote->getGrandTotal() - $quote->getMundipaggInterest() - $authorizedAmount;
16
+
17
+ $result = array();
18
+ $amount = str_replace(',', '.', $amount);
19
+
20
+ $items = $quote->getAllItems();
21
+ $recurrent = false;
22
+ foreach ($items as $item) {
23
+
24
+ foreach ($item->getOptions() as $option) {
25
+ $product = $option->getProduct();
26
+ $product->load($product->getId());
27
+
28
+ if ($product->getMundipaggRecurrent()) {
29
+ $recurrent = true;
30
+ $frequency = $product->getMundipaggFrequencyEnum();
31
+ $interval = $product->getMundipaggRecurrences();
32
+ $recurrenceMix = $product->getMundipaggRecurrenceMix();
33
+ }
34
+ }
35
+ }
36
+
37
+ }
38
+ }
app/code/community/Uecommerce/Mundipagg/Model/Adminvalidators/Offlineretry.php CHANGED
@@ -10,6 +10,7 @@ class Uecommerce_Mundipagg_Model_Adminvalidators_Offlineretry extends Mage_Core_
10
'mundipagg_threecreditcards',
11
'mundipagg_fourcreditcards',
12
'mundipagg_fivecreditcards',
13
);
14
15
if ($value) {
10
'mundipagg_threecreditcards',
11
'mundipagg_fourcreditcards',
12
'mundipagg_fivecreditcards',
13
+ 'mundipagg_recurrencepayment',
14
);
15
16
if ($value) {
app/code/community/Uecommerce/Mundipagg/Model/Api.php CHANGED
@@ -1,32 +1,5 @@
1
<?php
2
- /**
3
- * Uecommerce
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Uecommerce EULA.
8
- * It is also available through the world-wide-web at this URL:
9
- * http://www.uecommerce.com.br/
10
- *
11
- * DISCLAIMER
12
- *
13
- * Do not edit or add to this file if you wish to upgrade the extension
14
- * to newer versions in the future. If you wish to customize the extension
15
- * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
- *
17
- * @category Uecommerce
18
- * @package Uecommerce_Mundipagg
19
- * @copyright Copyright (c) 2012 Uecommerce (http://www.uecommerce.com.br/)
20
- * @license http://www.uecommerce.com.br/
21
- */
22
-
23
- /**
24
- * Mundipagg Payment module
25
- *
26
- * @category Uecommerce
27
- * @package Uecommerce_Mundipagg
28
- * @author Uecommerce Dev Team
29
- */
30
class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard {
31
32
const TRANSACTION_NOT_FOUND = "Transaction not found";
@@ -121,9 +94,9 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
121
$creditcardTransactionData->CreditCard->SecurityCode = $paymentData['SecurityCode']; // Código de segurança
122
$creditcardTransactionData->CreditCard->ExpMonth = $paymentData['ExpMonth']; // Mês Exp
123
$creditcardTransactionData->CreditCard->ExpYear = $paymentData['ExpYear']; // Ano Exp
124
- $creditcardTransactionData->CreditCard->CreditCardBrand = $paymentData['CreditCardBrandEnum']; // Bandeira do cartão : Visa ,MasterCard ,Hipercard ,Amex */
125
$creditcardTransactionData->CreditCardOperation = $creditCardOperationEnum;
126
- /** Tipo de operação: AuthOnly | AuthAndCapture | AuthAndCaptureWithDelay */
127
$creditcardTransactionData->AmountInCents = intval(strval(($paymentData['AmountInCents']))); // Valor da transação
128
$creditcardTransactionData->InstallmentCount = $paymentData['InstallmentCount']; // Nº de parcelas
129
$creditcardTransactionData->Options->CurrencyIso = "BRL"; //Moeda do pedido
@@ -161,7 +134,9 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
161
162
$_request["CreditCardTransactionCollection"] = $this->ConvertCreditcardTransactionCollectionFromRequest($creditcardTransactionCollection, $standard);
163
164
- $_request = $recurrencyModel->generateRecurrences($_request, $installmentCount);
165
166
// Buyer data
167
$_request["Buyer"] = array();
@@ -1294,12 +1269,29 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1294
//if Magento order is not processing and MundiPagg order status is canceled, cancel the order on Magento
1295
if ($order->getState() != Mage_Sales_Model_Order::STATE_PROCESSING && $orderStatus == Uecommerce_Mundipagg_Model_Enum_OrderStatusEnum::CANCELED) {
1296
1297
- if ($order->getState() == Mage_Sales_Model_Order::STATE_CANCELED) {
1298
- $returnMessage = "OK | {$returnMessageLabel} | Order already canceled.";
1299
-
1300
- $helperLog->info($returnMessage);
1301
-
1302
- return $returnMessage;
1303
}
1304
1305
try {
@@ -1789,6 +1781,10 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1789
/**
1790
* Create invoice
1791
* @todo must be deprecated use Uecommerce_Mundipagg_Model_Order_Payment createInvoice
1792
* @return string OK|KO
1793
*/
1794
private function createInvoice($order, $data, $totalPaid, $status) {
@@ -1864,8 +1860,7 @@ class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard
1864
$newStatus = 'overpaid';
1865
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, 'overpaid');
1866
} else {
1867
- $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
1868
- $order->addStatusToHistory(Mage_Sales_Model_Order::STATE_PROCESSING, $comment = 'Boleto pago', true);
1869
}
1870
1871
$order->save();
1
<?php
2
+
3
class Uecommerce_Mundipagg_Model_Api extends Uecommerce_Mundipagg_Model_Standard {
4
5
const TRANSACTION_NOT_FOUND = "Transaction not found";
94
$creditcardTransactionData->CreditCard->SecurityCode = $paymentData['SecurityCode']; // Código de segurança
95
$creditcardTransactionData->CreditCard->ExpMonth = $paymentData['ExpMonth']; // Mês Exp
96
$creditcardTransactionData->CreditCard->ExpYear = $paymentData['ExpYear']; // Ano Exp
97
+ $creditcardTransactionData->CreditCard->CreditCardBrand = $paymentData['CreditCardBrandEnum']; // Bandeira do cartão : Visa ,MasterCard ,Hipercard ,Amex
98
$creditcardTransactionData->CreditCardOperation = $creditCardOperationEnum;
99
+ /** Tipo de operação: AuthOnly | AuthAndCapture | AuthAndCaptureWithDelay **/
100
$creditcardTransactionData->AmountInCents = intval(strval(($paymentData['AmountInCents']))); // Valor da transação
101
$creditcardTransactionData->InstallmentCount = $paymentData['InstallmentCount']; // Nº de parcelas
102
$creditcardTransactionData->Options->CurrencyIso = "BRL"; //Moeda do pedido
134
135
$_request["CreditCardTransactionCollection"] = $this->ConvertCreditcardTransactionCollectionFromRequest($creditcardTransactionCollection, $standard);
136
137
+ if($data['payment_method'] === 'mundipagg_recurrencepayment') {
138
+ $_request = $recurrencyModel->generateRecurrences($_request, $installmentCount);
139
+ }
140
141
// Buyer data
142
$_request["Buyer"] = array();
1269
//if Magento order is not processing and MundiPagg order status is canceled, cancel the order on Magento
1270
if ($order->getState() != Mage_Sales_Model_Order::STATE_PROCESSING && $orderStatus == Uecommerce_Mundipagg_Model_Enum_OrderStatusEnum::CANCELED) {
1271
1272
+ switch ($order->getState()) {
1273
+ case Mage_Sales_Model_Order::STATE_CANCELED:
1274
+ $returnMessage = 'OK | ' . $returnMessageLabel . ' | Order already canceled.';
1275
+ $helperLog->info($returnMessage);
1276
+ return $returnMessage;
1277
+ case Mage_Sales_Model_Order::STATE_COMPLETE:
1278
+ foreach ($order->getInvoiceCollection() as $invoice) {
1279
+ if ($invoice->canRefund()) {
1280
+ $invoices[] = $invoice;
1281
+ }
1282
+ }
1283
+
1284
+ if (!empty($invoices)) {
1285
+ $service = Mage::getModel('sales/service_order', $order);
1286
+ foreach ($invoices as $invoice) {
1287
+ $this->closeInvoice($invoice);
1288
+ $this->createCreditMemo($invoice, $service);
1289
+ }
1290
+ }
1291
+ $this->closeOrder($order);
1292
+ $returnMessage = 'OK | ' . $returnMessageLabel . ' | Order closed.';
1293
+ $helperLog->info($returnMessage);
1294
+ return $returnMessage;
1295
}
1296
1297
try {
1781
/**
1782
* Create invoice
1783
* @todo must be deprecated use Uecommerce_Mundipagg_Model_Order_Payment createInvoice
1784
+ * @param Mage_Sales_Model_Order $order
1785
+ * @param array $data
1786
+ * @param float $totalPaid
1787
+ * @param string $status
1788
* @return string OK|KO
1789
*/
1790
private function createInvoice($order, $data, $totalPaid, $status) {
1860
$newStatus = 'overpaid';
1861
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, 'overpaid');
1862
} else {
1863
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Boleto pago', true);
1864
}
1865
1866
$order->save();
app/code/community/Uecommerce/Mundipagg/Model/Observer.php CHANGED
@@ -1,34 +1,7 @@
1
<?php
2
3
- /**
4
- * Uecommerce
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Uecommerce EULA.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://www.uecommerce.com.br/
11
- *
12
- * DISCLAIMER
13
- *
14
- * Do not edit or add to this file if you wish to upgrade the extension
15
- * to newer versions in the future. If you wish to customize the extension
16
- * for your needs please refer to http://www.uecommerce.com.br/ for more information
17
- *
18
- * @category Uecommerce
19
- * @package Uecommerce_Mundipagg
20
- * @copyright Copyright (c) 2012 Uecommerce (http://www.uecommerce.com.br/)
21
- * @license http://www.uecommerce.com.br/
22
- */
23
-
24
- /**
25
- * Mundipagg Payment module
26
- *
27
- * @category Uecommerce
28
- * @package Uecommerce_Mundipagg
29
- * @author Uecommerce Dev Team
30
- */
31
class Uecommerce_Mundipagg_Model_Observer extends Uecommerce_Mundipagg_Model_Standard {
32
/*
33
* Update status and notify customer or not
34
*/
@@ -150,10 +123,6 @@ class Uecommerce_Mundipagg_Model_Observer extends Uecommerce_Mundipagg_Model_Sta
150
switch ($method->getCode()) {
151
case 'mundipagg_creditcardoneinstallment':
152
case 'mundipagg_creditcard':
153
- // case 'mundipagg_twocreditcards':
154
- // case 'mundipagg_threecreditcards':
155
- // case 'mundipagg_fourcreditcards':
156
- // case 'mundipagg_fivecreditcards':
157
$active = Mage::getStoreConfig('payment/' . $method->getCode() . '/active');
158
159
if ($active == '1') {
@@ -172,308 +141,689 @@ class Uecommerce_Mundipagg_Model_Observer extends Uecommerce_Mundipagg_Model_Sta
172
}
173
}
174
175
- public function removeInterest($observer) {
176
- $session = Mage::getSingleton('admin/session');
177
-
178
- if ($session->isLoggedIn()) {
179
- $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
180
- } else {
181
- $quote = Mage::getSingleton('checkout/session')->getQuote();
182
- }
183
-
184
- $quote->setMundipaggInterest(0.0);
185
- $quote->setMundipaggBaseInterest(0.0);
186
- $quote->setTotalsCollectedFlag(false)->collectTotals();
187
- $quote->save();
188
- }
189
-
190
- /**
191
- * Check if recurrency product is in cart in order to show only Mundipagg Credit Card payment
192
- */
193
- public function checkForRecurrency($observer) {
194
- $session = Mage::getSingleton('checkout/session');
195
- $recurrent = $session->getMundipaggRecurrency();
196
-
197
- if ($recurrent) {
198
- $instance = $observer->getMethodInstance();
199
- $result = $observer->getResult();
200
-
201
- switch ($instance->getCode()) {
202
- case 'mundipagg_boleto':
203
- case 'mundipagg_debit':
204
- case 'mundipagg_creditcardoneinstallment':
205
- case 'mundipagg_twocreditcards':
206
- case 'mundipagg_threecreditcards':
207
- case 'mundipagg_fourcreditcards':
208
- case 'mundipagg_fivecreditcards':
209
- $result->isAvailable = false;
210
- break;
211
- case 'mundipagg_creditcard':
212
- $result->isAvailable = true;
213
- break;
214
- default:
215
- $result->isAvailable = false;
216
- break;
217
- }
218
- }
219
- }
220
-
221
- /**
222
- * Add discount amount in the quote when partial payment
223
- *
224
- * @param type $observer
225
- */
226
- public function addDiscountWhenPartial($observer) {
227
- $session = Mage::getSingleton('checkout/session');
228
- if (!$session->getApprovalRequestSuccess() == 'partial') {
229
- $request = Mage::app()->getRequest();
230
- if (Mage::app()->getRequest()->getActionName() != 'partialPost' && $request->getModuleName() != 'mundipagg' && $request->getControllerName() != 'standard') {
231
- return $this;
232
- }
233
- }
234
- $quote = $observer->getEvent()->getQuote();
235
- $quoteid = $quote->getId();
236
-
237
- $reservedOrderId = $quote->getReservedOrderId();
238
-
239
- if (!$reservedOrderId) {
240
- return $this;
241
- }
242
-
243
- $order = Mage::getModel('sales/order')->loadByIncrementId($reservedOrderId);
244
-
245
- if (!$order->getId()) {
246
- return $this;
247
- }
248
-
249
- $payment = $order->getPayment();
250
251
- $interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information');
252
- $discountAmount = 0;
253
-
254
- if (isset($interestInformation)) {
255
- foreach ($interestInformation as $ii) {
256
- $discountAmount += (float)$ii->getValue();
257
- }
258
- }
259
-
260
- if ($quoteid) {
261
- $total = $quote->getBaseSubtotal();
262
- $quote->setSubtotal(0);
263
- $quote->setBaseSubtotal(0);
264
-
265
- $quote->setSubtotalWithDiscount(0);
266
- $quote->setBaseSubtotalWithDiscount(0);
267
-
268
- $quote->setGrandTotal(0);
269
- $quote->setBaseGrandTotal(0);
270
271
272
- $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
273
- foreach ($quote->getAllAddresses() as $address) {
274
275
- $discountAmount -= $address->getShippingAmount();
276
277
- $address->setSubtotal(0);
278
- $address->setBaseSubtotal(0);
279
280
- $address->setGrandTotal(0);
281
- $address->setBaseGrandTotal(0);
282
283
- $address->collectTotals();
284
285
- $quote->setSubtotal((float)$quote->getSubtotal() + $address->getSubtotal());
286
- $quote->setBaseSubtotal((float)$quote->getBaseSubtotal() + $address->getBaseSubtotal());
287
288
- $quote->setSubtotalWithDiscount(
289
- (float)$quote->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount()
290
- );
291
- $quote->setBaseSubtotalWithDiscount(
292
- (float)$quote->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount()
293
- );
294
295
- $quote->setGrandTotal((float)$quote->getGrandTotal() + $address->getGrandTotal());
296
- $quote->setBaseGrandTotal((float)$quote->getBaseGrandTotal() + $address->getBaseGrandTotal());
297
298
- $quote->save();
299
300
- $quote->setGrandTotal($quote->getBaseSubtotal() - $discountAmount)
301
- ->setBaseGrandTotal($quote->getBaseSubtotal() - $discountAmount)
302
- ->setSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)
303
- ->setBaseSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)
304
- ->save();
305
306
307
- if ($address->getAddressType() == $canAddItems) {
308
- //echo $address->setDiscountAmount; exit;
309
- $address->setSubtotalWithDiscount((float)$address->getSubtotalWithDiscount() - $discountAmount);
310
- $address->setGrandTotal((float)$address->getGrandTotal() - $discountAmount);
311
- $address->setBaseSubtotalWithDiscount((float)$address->getBaseSubtotalWithDiscount() - $discountAmount);
312
- $address->setBaseGrandTotal((float)$address->getBaseGrandTotal() - $discountAmount);
313
- if ($address->getDiscountDescription()) {
314
- $address->setDiscountAmount(-($address->getDiscountAmount() - $discountAmount));
315
- $address->setDiscountDescription($address->getDiscountDescription() . ', Discount to Partial Payment');
316
- $address->setBaseDiscountAmount(-($address->getBaseDiscountAmount() - $discountAmount));
317
- } else {
318
- $address->setDiscountAmount(-($discountAmount));
319
- $address->setDiscountDescription('Discount to Partial Payment');
320
- $address->setBaseDiscountAmount(-($discountAmount));
321
- }
322
- $address->save();
323
- }
324
- }
325
- //echo $quote->getGrandTotal();
326
-
327
- foreach ($quote->getAllItems() as $item) {
328
- //We apply discount amount based on the ratio between the GrandTotal and the RowTotal
329
- $rat = $item->getPriceInclTax() / $total;
330
- $ratdisc = $discountAmount * $rat;
331
- $item->setDiscountAmount(($item->getDiscountAmount() + $ratdisc) * $item->getQty());
332
- $item->setBaseDiscountAmount(($item->getBaseDiscountAmount() + $ratdisc) * $item->getQty())->save();
333
- }
334
- }
335
- }
336
337
- public function catalogProductSaveBefore($event) {
338
- $product = $event->getProduct();
339
- $recurrentOption = (boolean)$product->getMundipaggRecurrent();
340
341
- if ($recurrentOption) {
342
- $isRequired = true;
343
- } else {
344
- $isRequired = false;
345
- }
346
347
- try {
348
- $attribute = new Mage_Eav_Model_Entity_Attribute();
349
- $attribute->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'mundipagg_recurrences');
350
- $attribute->setIsRequired($isRequired);
351
- $attribute->save();
352
353
- } catch (Mage_Adminhtml_Exception $e) {
354
- $log = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
355
- $helper = Mage::helper('mundipagg');
356
357
- $errMsg = "{$helper->__("Internal error")}: {$e->getMessage()}";
358
- $log->error($helper->__("Unable to save product configuration: {$e}"));
359
360
- throw new Mage_Adminhtml_Exception($errMsg);
361
- }
362
363
- }
364
365
- public function checkRecurrencyFrequency(Varien_Event_Observer $observer) {
366
- $product = $observer->getProduct();
367
- $recurrent = (boolean)$product->getData('mundipagg_recurrent');
368
- $frequency = $product->getData('mundipagg_frequency_enum');
369
370
- if ($recurrent === true && $frequency == '0') {
371
- $helper = Mage::helper('mundipagg');
372
- $errMsg = $helper->__('Recurrency frequency is required');
373
374
- Mage::throwException($errMsg);
375
- }
376
- }
377
378
- /**
379
- * @param Varien_Event $event
380
- */
381
- public function cartCheckRecurrency($event) {
382
- /* @var Mage_Checkout_Model_Cart $cart */
383
- $cart = $event->getCart();
384
385
- /* @var Mage_Sales_Model_Quote $quote */
386
- $quote = $cart->getQuote();
387
388
- /* @var Mage_Sales_Model_Resource_Quote_Item_Collection $items */
389
- $items = $quote->getAllItems();
390
391
- /* @var Mage_Sales_Model_Quote_Item $item */
392
- foreach ($items as $item) {
393
394
- /* @var Mage_Sales_Model_Quote_Item_Option $option */
395
- foreach ($item->getOptions() as $option) {
396
- /* @var Mage_Catalog_Model_Product $product */
397
- $product = $option->getProduct();
398
- $product->load($product->getId());
399
400
- if ($product->getMundipaggRecurrent()) {
401
- $this->setQuoteRecurrencyFlag(true);
402
403
- return;
404
- }
405
- }
406
- }
407
408
- $this->setQuoteRecurrencyFlag(false);
409
- }
410
411
- /**
412
- * @param boolean $option
413
- *
414
- */
415
- private function setQuoteRecurrencyFlag($option) {
416
- $session = Mage::getSingleton('checkout/session');
417
- $session->setMundipaggRecurrency($option);
418
- }
419
-
420
- public function checkModuleVersion()
421
- {
422
- $localModuleVersion = $this->readModuleVersion();
423
- $repoVersion = $this->getRepoVersion();
424
- if(version_compare($localModuleVersion, $repoVersion, "<") == 1){
425
- $this->insertOldVersionNotification($localModuleVersion, $repoVersion);
426
}
427
}
428
429
- private function insertOldVersionNotification($oldVersion, $newVersion){
430
- $notification = mage::getModel("adminnotification/inbox");
431
- $data = [
432
- 'severity'=>Mage_AdminNotification_Model_Inbox::SEVERITY_MINOR
433
- ,'title'=> 'Nova versão do módulo de integração Mundipagg disponível.'
434
- ,'description'=>
435
- "Você está utilizando uma versão antiga do módulo de interação Mundipagg(v" . $oldVersion . "). Atualize para a versão v" . $newVersion . "<br>
436
- <a href='https://www.magentocommerce.com/magento-connect/mundipagg-payment-gateway.html' target='_blank'>Download Magento Connect</a><br>
437
- <a href='https://github.com/mundipagg/Magento.Integracao' target='_blank'>GitHub</a>
438
- "
439
- ,'url' =>"https://www.magentocommerce.com/magento-connect/mundipagg-payment-gateway.html"
440
- ,'is_read' => 0
441
- ,'is_remove'=>0
442
- ,'date_added'=> now()
443
- ];
444
- $notification->setData($data);
445
- $notification->save();
446
}
447
-
448
- private function readModuleVersion(){
449
- $configXml = Mage::getBaseDir('app') . "/code/community/Uecommerce/Mundipagg/etc/config.xml";
450
- if (file_exists($configXml)) {
451
- $xmlObj = simplexml_load_file($configXml);
452
- return $xmlObj->modules->Uecommerce_Mundipagg->version[0];
453
- }else{
454
- return 0;
455
- }
456
}
457
-
458
- private function getRepoVersion(){
459
- $url = "https://api.github.com/repos/mundipagg/Magento.Integracao/releases";
460
- $ch = curl_init();
461
-
462
- // Header
463
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
464
- curl_setopt($ch,CURLOPT_USERAGENT,'Mundipagg');
465
- // Set the url, number of POST vars, POST data
466
- curl_setopt($ch, CURLOPT_URL, $url);
467
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
468
- // Execute post
469
- $_response = curl_exec($ch);
470
-
471
- if (curl_errno($ch)) {
472
- $helperLog->info(curl_error($ch));
473
- }
474
- $response = (json_decode($_response));
475
- return str_replace("v", "",$response[0]->tag_name);
476
-
477
}
478
479
}
1
<?php
2
3
class Uecommerce_Mundipagg_Model_Observer extends Uecommerce_Mundipagg_Model_Standard {
4
+
5
/*
6
* Update status and notify customer or not
7
*/
123
switch ($method->getCode()) {
124
case 'mundipagg_creditcardoneinstallment':
125
case 'mundipagg_creditcard':
126
$active = Mage::getStoreConfig('payment/' . $method->getCode() . '/active');
127
128
if ($active == '1') {
141
}
142
}
143
144
+ public function removeInterest($observer) {
145
+ /*$session = Mage::getSingleton('admin/session');
146
147
+ if ($session->isLoggedIn()) {
148
+ $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
149
+ } else {
150
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
151
+ }
152
153
+ $quote->setMundipaggInterest(0.0);
154
+ $quote->setMundipaggBaseInterest(0.0);
155
+ $quote->setTotalsCollectedFlag(false)->collectTotals();
156
+ $quote->save();*/
157
+ }
158
159
+ public function recurrenceMixConflict()
160
+ {
161
+ $session = Mage::getSingleton('checkout/session');
162
163
+ $recurrent = $session->getMundipaggRecurrency();
164
+ if ($recurrent) {
165
+ $active = Mage::getStoreConfig('payment/mundipagg_recurrencepayment/active');
166
+
167
+ $quote = $session->getQuote();
168
+ if ($this->checkRecurrenceMix($quote) &&
169
+ $this->countTotalCartItems($quote) > 1
170
+ ) {
171
+ $msg = Mage::getStoreConfig('payment/mundipagg_recurrencepayment/conflict_message_recurrent_mix_mix');
172
+ $message = Mage::getModel('core/message_warning', $msg);
173
+ Mage::getSingleton('core/session')->addUniqueMessages($message);
174
+
175
+ return;
176
+ }
177
+ }
178
+ }
179
+
180
+ private function countTotalCartItems($quote)
181
+ {
182
+ $items = $quote->getAllItems();
183
+ $productQty = 0;
184
+ foreach ($items as $item) {
185
+
186
+ foreach ($item->getOptions() as $option) {
187
+ $product = $option->getProduct();
188
+ $product->load($product->getId());
189
+ if ($item->getQty()) {
190
+ $productQty += $item->getQty();
191
+ }
192
+ }
193
+ }
194
+ return $productQty;
195
+ }
196
+
197
+ /**
198
+ * Check if recurrency product is in cart in order to show
199
+ * only Mundipagg Credit Card payment
200
+ */
201
+ public function checkForRecurrency($observer) {
202
+ $session = Mage::getSingleton('checkout/session');
203
+ $recurrent = $session->getMundipaggRecurrency();
204
+
205
+ $instance = $observer->getMethodInstance();
206
+ $result = $observer->getResult();
207
+ $code = $instance->getCode();
208
+
209
+ if ($code === 'mundipagg_recurrencepayment'){
210
+ $result->isAvailable = false;
211
+ }
212
+ $active = Mage::getStoreConfig('payment/' . $code . '/active');
213
+ $thereIsrecurrentProduct = $this->checkRecurrence($session->getQuote());
214
+ $isMundipagg = strpos($code, "mundipagg_");
215
+
216
+ //0 => First string position = true.
217
+ if (
218
+ $isMundipagg === 0 &&
219
+ $thereIsrecurrentProduct &&
220
+ $active
221
+ ) {
222
+ $this->switchPaymentMethods($code, $result, $session->getQuote(), true);
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Enable/disable Mundipagg payment methods for recurrence
228
+ * @param string $code
229
+ * @param object $result
230
+ */
231
+ private function switchPaymentMethods($code, $result, $quote)
232
+ {
233
+ $itemAlone = $this->checkItemAlone($quote);
234
+ $recurenceMix = $this->checkRecurrenceMix($quote);
235
+
236
+ if ($recurenceMix && $itemAlone) {
237
+ $result->isAvailable = true;
238
+ return;
239
+ }
240
+
241
+ switch ($code) {
242
+ case 'mundipagg_boleto':
243
+ case 'mundipagg_debit':
244
+ case 'mundipagg_twocreditcards':
245
+ case 'mundipagg_creditcard':
246
+ if ($itemAlone && !$recurenceMix) {
247
+ $result->isAvailable = false;
248
+ break;
249
+ }
250
+ $result->isAvailable = true;
251
+ break;
252
+ case 'mundipagg_recurrencepayment':
253
+ if ($itemAlone && !$recurenceMix) {
254
+ $result->isAvailable = true;
255
+ break;
256
+ }
257
+ $result->isAvailable = false;
258
+ break;
259
+ default:
260
+ $result->isAvailable = false;
261
+ break;
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Check if exists a recurrent product in cart
267
+ */
268
+ private function checkRecurrence($quote)
269
+ {
270
+ $items = $quote->getAllItems();
271
+ foreach ($items as $item) {
272
+
273
+ foreach ($item->getOptions() as $option) {
274
+ $product = $option->getProduct();
275
+ $product->load($product->getId());
276
+ if ($product->getMundipaggRecurrent() === '1') {
277
+ return true;
278
+ }
279
+ }
280
+ }
281
+ return false;
282
+ }
283
+
284
+ /**
285
+ * @param Object $quote
286
+ * @return boolean
287
+ */
288
+ private function checkRecurrenceMix($quote) {
289
+ $items = $quote->getAllItems();
290
+ foreach ($items as $item) {
291
+
292
+ foreach ($item->getOptions() as $option) {
293
+ $product = $option->getProduct();
294
+ $product->load($product->getId());
295
+ if ($product->getMundipaggRecurrenceMix() === '1') {
296
+ return true;
297
+ }
298
+ }
299
+ }
300
+ return false;
301
+ }
302
+
303
+ /**
304
+ * @param Object $quote
305
+ * @return boolean
306
+ */
307
+ private function checkItemAlone($quote) {
308
+ $items = $quote->getAllItems();
309
+ $countItems = count($items);
310
+ if ($countItems > 1) {
311
+ return false;
312
+ }
313
+ foreach ($items as $item) {
314
+
315
+ foreach ($item->getOptions() as $option) {
316
+ $product = $option->getProduct();
317
+ $product->load($product->getId());
318
+ $productQty = $item->getQty();
319
+ if (
320
+ $productQty > 1
321
+ ) {
322
+ return false;
323
+ }
324
+ return true;
325
+ }
326
+ }
327
+ }
328
+
329
+ /*
330
+ * Recurrent product needs to be alone.
331
+ */
332
+ public function cartCheckRecurrencyConflicts($observer)
333
+ {
334
+ $recurrencePayment = Mage::getStoreConfig('payment/mundipagg_recurrencepayment/active');
335
+ if ($recurrencePayment === '1') {
336
+ $this->checkRecurrenceConflicts($observer);
337
+ }
338
+ }
339
340
+ private function checkRecurrenceConflicts($observer)
341
+ {
342
+ $event = $observer->getEvent();
343
+
344
+ if ($event->getQuoteItem()) {
345
+ $quote = $event->getQuoteItem()->getQuote();
346
+ } else {
347
+ $quote = $event->getCart()->getQuote();
348
+ }
349
+ $items = $quote->getAllItems();
350
+ $countItems = $this->countTotalCartItems($quote);
351
352
+ if ($countItems > 0) {
353
354
+ //Others + recurrent
355
+ $this->showRecurrentFirstError($quote, $items[0]);
356
+ $this->showOthersWithRecurrentError($items, $countItems);
357
+
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Show an error when a recurrent product is adeed with others.
363
+ */
364
+ private function showOthersWithRecurrentError($items, $countItems)
365
+ {
366
+ if ($countItems >1 && !$this->checkRecurrentAlone($items)) {
367
+ Mage::getSingleton('checkout/session')->addError(
368
+ Mage::getStoreConfig('payment/mundipagg_recurrencepayment/conflict_message_recurrent_mix_recurrent')
369
+ );
370
+ Mage::getSingleton('checkout/session')->addError($this->__(''));
371
+ return false;
372
+ }
373
+ }
374
+
375
+
376
+ /**
377
+ * Show an error when other products are added with a recurrent one;
378
+ */
379
+ private function showRecurrentFirstError($quote, $item)
380
+ {
381
+ if (
382
+ $this->itemIsOnlyRecurrent($item) &&
383
+ $this->countTotalCartItems($quote) > 1
384
+ ) {
385
+ Mage::getSingleton('checkout/session')->addError(
386
+ Mage::getStoreConfig('payment/mundipagg_recurrencepayment/conflict_message_recurrent_others')
387
+ );
388
+ Mage::getSingleton('checkout/session')->addError($this->__(''));
389
+ return false;
390
+ }
391
+ }
392
+
393
+ private function itemIsOnlyRecurrent($item)
394
+ {
395
+ foreach ($item->getOptions() as $option) {
396
+ $product = $option->getProduct();
397
+ $product->load($product->getId());
398
+ if (
399
+ $product->getMundipaggRecurrent() &&
400
+ !$product->getMundipaggRecurrenceMix()
401
+ ) {
402
+ return true;
403
+ }
404
+
405
+ }
406
+ return false;
407
+ }
408
+
409
+ /**
410
+ * Check if a recurrent product are alone in the cart
411
+ * @param type $product
412
+ */
413
+ private function checkRecurrentAlone($items)
414
+ {
415
+ foreach ($items as $item) {
416
+ foreach ($item->getOptions() as $option) {
417
+ $product = $option->getProduct();
418
+ $product->load($product->getId());
419
+ if (
420
+ $product->getMundipaggRecurrent() &&
421
+ !$product->getMundipaggRecurrenceMix()
422
+ ) {
423
+ return false;
424
+ }
425
+ }
426
+
427
+ }
428
+ return true;
429
+ }
430
+
431
+
432
+ /**
433
+ * Add discount amount in the quote when partial payment
434
+ *
435
+ * @param type $observer
436
+ */
437
+ public function addDiscountWhenPartial($observer) {
438
+ $session = Mage::getSingleton('checkout/session');
439
+ if (!$session->getApprovalRequestSuccess() == 'partial') {
440
+ $request = Mage::app()->getRequest();
441
+ if (
442
+ Mage::app()->getRequest()->getActionName() != 'partialPost' &&
443
+ $request->getModuleName() != 'mundipagg' &&
444
+ $request->getControllerName() != 'standard'
445
+ ) {
446
+ return $this;
447
+ }
448
+ }
449
+ $quote = $observer->getEvent()->getQuote();
450
+ $quoteid = $quote->getId();
451
452
+ $reservedOrderId = $quote->getReservedOrderId();
453
454
+ if (!$reservedOrderId) {
455
+ return $this;
456
+ }
457
458
+ $order = Mage::getModel('sales/order')->loadByIncrementId($reservedOrderId);
459
460
+ if (!$order->getId()) {
461
+ return $this;
462
+ }
463
464
+ $payment = $order->getPayment();
465
466
+ $interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information');
467
+ $discountAmount = 0;
468
469
+ if (isset($interestInformation)) {
470
+ foreach ($interestInformation as $ii) {
471
+ $discountAmount += (float) $ii->getValue();
472
+ }
473
+ }
474
475
+ if ($quoteid) {
476
+ $total = $quote->getBaseSubtotal();
477
+ $quote->setSubtotal(0);
478
+ $quote->setBaseSubtotal(0);
479
+
480
+ $quote->setSubtotalWithDiscount(0);
481
+ $quote->setBaseSubtotalWithDiscount(0);
482
+
483
+ $quote->setGrandTotal(0);
484
+ $quote->setBaseGrandTotal(0);
485
+
486
+ $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
487
+ foreach ($quote->getAllAddresses() as $address) {
488
+
489
+ $discountAmount -= $address->getShippingAmount();
490
+
491
+ $address->setSubtotal(0);
492
+ $address->setBaseSubtotal(0);
493
+
494
+ $address->setGrandTotal(0);
495
+ $address->setBaseGrandTotal(0);
496
+
497
+ $address->collectTotals();
498
+
499
+ $quote->setSubtotal((float) $quote->getSubtotal() + $address->getSubtotal());
500
+ $quote->setBaseSubtotal((float) $quote->getBaseSubtotal() + $address->getBaseSubtotal());
501
+
502
+ $quote->setSubtotalWithDiscount(
503
+ (float) $quote->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount()
504
+ );
505
+ $quote->setBaseSubtotalWithDiscount(
506
+ (float) $quote->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount()
507
+ );
508
+
509
+ $quote->setGrandTotal((float) $quote->getGrandTotal() + $address->getGrandTotal());
510
+ $quote->setBaseGrandTotal((float) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal());
511
+
512
+ $quote->save();
513
+
514
+ $quote->setGrandTotal($quote->getBaseSubtotal() - $discountAmount)
515
+ ->setBaseGrandTotal($quote->getBaseSubtotal() - $discountAmount)
516
+ ->setSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)
517
+ ->setBaseSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)
518
+ ->save();
519
+
520
+ if ($address->getAddressType() == $canAddItems) {
521
+ //echo $address->setDiscountAmount; exit;
522
+ $address->setSubtotalWithDiscount((float) $address->getSubtotalWithDiscount() - $discountAmount);
523
+ $address->setGrandTotal((float) $address->getGrandTotal() - $discountAmount);
524
+ $address->setBaseSubtotalWithDiscount((float) $address->getBaseSubtotalWithDiscount() - $discountAmount);
525
+ $address->setBaseGrandTotal((float) $address->getBaseGrandTotal() - $discountAmount);
526
+ if ($address->getDiscountDescription()) {
527
+ $address->setDiscountAmount(-($address->getDiscountAmount() - $discountAmount));
528
+ $address->setDiscountDescription($address->getDiscountDescription() . ', Discount to Partial Payment');
529
+ $address->setBaseDiscountAmount(-($address->getBaseDiscountAmount() - $discountAmount));
530
+ } else {
531
+ $address->setDiscountAmount(-($discountAmount));
532
+ $address->setDiscountDescription('Discount to Partial Payment');
533
+ $address->setBaseDiscountAmount(-($discountAmount));
534
+ }
535
+ $address->save();
536
+ }
537
+ }
538
539
+ foreach ($quote->getAllItems() as $item) {
540
+ //We apply discount amount based on the ratio between the GrandTotal and the RowTotal
541
+ $rat = $item->getPriceInclTax() / $total;
542
+ $ratdisc = $discountAmount * $rat;
543
+ $item->setDiscountAmount(($item->getDiscountAmount() + $ratdisc) * $item->getQty());
544
+ $item->setBaseDiscountAmount(($item->getBaseDiscountAmount() + $ratdisc) * $item->getQty())->save();
545
+ }
546
+ }
547
+ }
548
+
549
+ public function changeRecurrenceValues(Varien_Event_Observer $observer) {
550
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
551
+ $quoteid = $quote->getId();
552
+
553
+ $payment = $quote->getPayment();
554
+
555
+ $quoteItems = $quote->getAllItems();
556
+ $discountAmount = $this->getRecurrenceDiscount($quoteItems);
557
+
558
+ if ($quoteid) {
559
+ $total = $quote->getGrandTotal();
560
+
561
+ $quote->setSubtotal(0);
562
+ $quote->setBaseSubtotal(0);
563
+
564
+ $quote->setSubtotalWithDiscount(0);
565
+ $quote->setBaseSubtotalWithDiscount(0);
566
+
567
+ $quote->setGrandTotal(0);
568
+ $quote->setBaseGrandTotal(0);
569
+
570
+
571
+ $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
572
+ foreach ($quote->getAllAddresses() as $address) {
573
+
574
+ $address->setSubtotal(0);
575
+ $address->setBaseSubtotal(0);
576
+
577
+ $address->setGrandTotal(0);
578
+ $address->setBaseGrandTotal(0);
579
+
580
+ $address->collectTotals();
581
+
582
+ $quote->setSubtotal((float) $quote->getSubtotal() + $address->getSubtotal());
583
+ $quote->setBaseSubtotal((float) $quote->getBaseSubtotal() + $address->getBaseSubtotal());
584
+
585
+ $quote->setGrandTotal((float) $quote->getGrandTotal() + $address->getGrandTotal());
586
+ $quote->setBaseGrandTotal((float) $quote->getBaseGrandTotal() + $address->getBaseGrandTotal());
587
+
588
+ $quote->save();
589
+
590
+ $quote->setGrandTotal($quote->getBaseSubtotal() - $discountAmount)
591
+ ->setBaseGrandTotal($quote->getBaseSubtotal() - $discountAmount)
592
+ ->setSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)
593
+ ->setBaseSubtotalWithDiscount($quote->getBaseSubtotal() - $discountAmount)
594
+ ->save();
595
+
596
+ if (
597
+ $this->checkRecurrenceMix($quote) &&
598
+ $this->checkItemAlone($quote)
599
+ ) {
600
+ $paymentMethod = $quote->getPayment()->getMethod();
601
+ if (
602
+ $paymentMethod === 'mundipagg_recurrencepayment'
603
+ ) {
604
+ $totalWithDiscount = $this->getRecurrencePartial($total, $quoteItems);
605
+ if ($address->getAddressType() == $canAddItems) {
606
+ $msg = Mage::getStoreConfig('payment/mundipagg_recurrencepayment/recurrent_mix_message');
607
+ $address->setSubtotalWithDiscount((float) $totalWithDiscount);
608
+ $address->setGrandTotal((float) $totalWithDiscount);
609
+ $address->setBaseSubtotalWithDiscount((float) $totalWithDiscount);
610
+ $address->setBaseGrandTotal((float) $totalWithDiscount);
611
+ if ($address->getDiscountDescription()) {
612
+ $address->setDiscountAmount(-($address->getDiscountAmount()));
613
+ $address->setDiscountDescription(
614
+ $msg
615
+ );
616
+ $address->setBaseDiscountAmount($address->getBaseDiscountAmount());
617
+ } else {
618
+ $address->setDiscountAmount($totalWithDiscount);
619
+ $address->setDiscountDescription($msg);
620
+ }
621
+ $address->save();
622
+ }
623
+ } else {
624
+ if ($address->getAddressType() == $canAddItems) {
625
+ $msg = 'Desconto para pagamento avulso';
626
+ $address->setSubtotalWithDiscount((float) $address->getSubtotalWithDiscount() - $discountAmount);
627
+ $address->setGrandTotal((float) $address->getGrandTotal() - $discountAmount);
628
+ $address->setBaseSubtotalWithDiscount((float) $address->getBaseSubtotalWithDiscount() - $discountAmount);
629
+ $address->setBaseGrandTotal((float) $address->getBaseGrandTotal() - $discountAmount);
630
+ if ($address->getDiscountDescription()) {
631
+ $address->setDiscountAmount(-($address->getDiscountAmount() - $discountAmount));
632
+ $address->setDiscountDescription(
633
+ $address->getDiscountDescription() . $msg
634
+ );
635
+ $address->setBaseDiscountAmount(-($address->getBaseDiscountAmount() - $discountAmount));
636
+ } else {
637
+ $address->setDiscountAmount(-($discountAmount));
638
+ $address->setDiscountDescription($msg);
639
+ $address->setBaseDiscountAmount(-($discountAmount));
640
+ }
641
+ $address->save();
642
+ }
643
+ }
644
+ }
645
+ }
646
+ }
647
+ }
648
+
649
+ private function getRecurrencePartial($total, $items)
650
+ {
651
+ foreach($items as $item) {
652
+ $product = $item->getProduct();
653
+ $recurrence = $product->getMundipaggRecurrent();
654
+ $recurrences = $product->getMundipaggRecurrences();
655
+
656
+ if ($recurrence === '1' && $recurrences > 1) {
657
+ $frequency = $product->getMundipaggFrequencyEnum();
658
+
659
+ switch ($frequency) {
660
+ case 'Quarterly':
661
+ $recurrences *= 3;
662
+ break;
663
+ case 'Biannual':
664
+ $recurrences *= 6;
665
+ break;;
666
+ case 'Yearly':
667
+ $recurrences *= 12;
668
+ break;
669
+ }
670
+
671
+ return $total / $recurrences;
672
+ }
673
+ }
674
+ }
675
+
676
+ private function getRecurrenceDiscount( $items)
677
+ {
678
+ foreach($items as $item) {
679
+ $product = $item->getProduct();
680
+ $discount = $product->getMundipaggRecurrenceDiscount();
681
+ if ($discount > 0) {
682
+ return $discount;
683
+ }
684
+ }
685
+ }
686
687
+ public function catalogProductSaveBefore($event) {
688
+ $product = $event->getProduct();
689
+ $recurrentOption = (boolean)$product->getMundipaggRecurrent();
690
691
+ if ($recurrentOption) {
692
+ $isRequired = true;
693
+ } else {
694
+ $isRequired = false;
695
+ }
696
697
+ try {
698
+ $attribute = new Mage_Eav_Model_Entity_Attribute();
699
+ $attribute->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'mundipagg_recurrences');
700
+ $attribute->setIsRequired($isRequired);
701
+ $attribute->save();
702
703
+ } catch (Mage_Adminhtml_Exception $e) {
704
+ $log = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
705
+ $helper = Mage::helper('mundipagg');
706
707
+ $errMsg = "{$helper->__("Internal error")}: {$e->getMessage()}";
708
+ $log->error($helper->__("Unable to save product configuration: {$e}"));
709
710
+ throw new Mage_Adminhtml_Exception($errMsg);
711
+ }
712
713
+ }
714
715
+ public function checkRecurrencyFrequency(Varien_Event_Observer $observer) {
716
+ $product = $observer->getProduct();
717
+ $recurrent = (boolean)$product->getData('mundipagg_recurrent');
718
+ $frequency = $product->getData('mundipagg_frequency_enum');
719
720
+ if ($recurrent === true && $frequency == '0') {
721
+ $helper = Mage::helper('mundipagg');
722
+ $errMsg = $helper->__('Recurrency frequency is required');
723
724
+ Mage::throwException($errMsg);
725
+ }
726
+ }
727
728
+ /**
729
+ * @param Varien_Event $event
730
+ */
731
+ public function cartCheckRecurrency($event) {
732
+ /* @var Mage_Checkout_Model_Cart $cart */
733
+ $cart = $event->getCart();
734
735
+ /* @var Mage_Sales_Model_Quote $quote */
736
+ $quote = $cart->getQuote();
737
738
+ /* @var Mage_Sales_Model_Resource_Quote_Item_Collection $items */
739
+ $items = $quote->getAllItems();
740
741
+ /* @var Mage_Sales_Model_Quote_Item $item */
742
+ foreach ($items as $item) {
743
744
+ /* @var Mage_Sales_Model_Quote_Item_Option $option */
745
+ foreach ($item->getOptions() as $option) {
746
+ /* @var Mage_Catalog_Model_Product $product */
747
+ $product = $option->getProduct();
748
+ $product->load($product->getId());
749
750
+ if ($product->getMundipaggRecurrent()) {
751
+ $this->setQuoteRecurrencyFlag(true);
752
753
+ return;
754
+ }
755
}
756
}
757
+
758
+ $this->setQuoteRecurrencyFlag(false);
759
+ }
760
+
761
+ /**
762
+ * @param boolean $option
763
+ *
764
+ */
765
+ private function setQuoteRecurrencyFlag($option) {
766
+ $session = Mage::getSingleton('checkout/session');
767
+ $session->setMundipaggRecurrency($option);
768
+ }
769
770
+ public function checkModuleVersion()
771
+ {
772
+ $localModuleVersion = $this->readModuleVersion();
773
+ $repoVersion = $this->getRepoVersion();
774
+ if(version_compare($localModuleVersion, $repoVersion, "<") == 1){
775
+ $this->insertOldVersionNotification($localModuleVersion, $repoVersion);
776
}
777
+ }
778
+
779
+ private function insertOldVersionNotification($oldVersion, $newVersion){
780
+ $notification = mage::getModel("adminnotification/inbox");
781
+ $data = [
782
+ 'severity'=>Mage_AdminNotification_Model_Inbox::SEVERITY_MINOR
783
+ ,'title'=> 'Nova versão do módulo de integração Mundipagg disponível.'
784
+ ,'description'=>
785
+ "Você está utilizando uma versão antiga do módulo de interação Mundipagg(v" . $oldVersion . "). Atualize para a versão v" . $newVersion . "<br>
786
+ <a href='https://www.magentocommerce.com/magento-connect/mundipagg-payment-gateway.html' target='_blank'>Download Magento Connect</a><br>
787
+ <a href='https://github.com/mundipagg/Magento.Integracao' target='_blank'>GitHub</a>
788
+ "
789
+ ,'url' =>"https://www.magentocommerce.com/magento-connect/mundipagg-payment-gateway.html"
790
+ ,'is_read' => 0
791
+ ,'is_remove'=>0
792
+ ,'date_added'=> now()
793
+ ];
794
+ $notification->setData($data);
795
+ $notification->save();
796
+ }
797
+
798
+ private function readModuleVersion(){
799
+ $configXml = Mage::getBaseDir('app') . "/code/community/Uecommerce/Mundipagg/etc/config.xml";
800
+ if (file_exists($configXml)) {
801
+ $xmlObj = simplexml_load_file($configXml);
802
+ return $xmlObj->modules->Uecommerce_Mundipagg->version[0];
803
+ }else{
804
+ return 0;
805
}
806
+ }
807
+
808
+ private function getRepoVersion(){
809
+ $url = "https://api.github.com/repos/mundipagg/Magento.Integracao/releases";
810
+ $ch = curl_init();
811
+
812
+ // Header
813
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
814
+ curl_setopt($ch,CURLOPT_USERAGENT,'Mundipagg');
815
+ // Set the url, number of POST vars, POST data
816
+ curl_setopt($ch, CURLOPT_URL, $url);
817
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
818
+ // Execute post
819
+ $_response = curl_exec($ch);
820
+
821
+ if (curl_errno($ch)) {
822
+ $helperLog->info(curl_error($ch));
823
}
824
+ $response = (json_decode($_response));
825
+ return str_replace("v", "",$response[0]->tag_name);
826
+
827
+ }
828
829
}
app/code/community/Uecommerce/Mundipagg/Model/Quote/Address/Interest.php CHANGED
@@ -47,12 +47,14 @@ class Uecommerce_Mundipagg_Model_Quote_Address_Interest extends Mage_Sales_Model
47
}
48
49
$this->_setAddress($address);
50
-
51
parent::collect($address);
52
53
$quote = $address->getQuote();
54
$amount = $quote->getMundipaggInterest();
55
-
56
if($amount > 0) {
57
$this->_setBaseAmount(0.00);
58
$this->_setAmount(0.00);
@@ -62,6 +64,14 @@ class Uecommerce_Mundipagg_Model_Quote_Address_Interest extends Mage_Sales_Model
62
63
$this->_setBaseAmount($amount);
64
$this->_setAmount($amount);
65
} else {
66
$this->_setBaseAmount(0.00);
67
$this->_setAmount(0.00);
@@ -84,6 +94,7 @@ class Uecommerce_Mundipagg_Model_Quote_Address_Interest extends Mage_Sales_Model
84
'title' => Mage::helper('mundipagg')->__('Interest'),
85
'value' => $address->getMundipaggInterest()
86
));
87
}
88
}
89
}
47
}
48
49
$this->_setAddress($address);
50
+ $addressObj = $this->_getAddress();
51
+ $totals = $addressObj->$_totals;
52
+
53
parent::collect($address);
54
55
$quote = $address->getQuote();
56
$amount = $quote->getMundipaggInterest();
57
+
58
if($amount > 0) {
59
$this->_setBaseAmount(0.00);
60
$this->_setAmount(0.00);
64
65
$this->_setBaseAmount($amount);
66
$this->_setAmount($amount);
67
+
68
+
69
+ $shippingAmount = $totals['shipping_amount'];
70
+ $baseSubtotal = $totals['base_subtotal'];
71
+ $totalOrderAmount = $baseSubtotal + $shippingAmount + $amount;
72
+ $address->setGrandTotal($totalOrderAmount);
73
+ $address->setBaseGrandTotal($totalOrderAmount);
74
+ $address->save();
75
} else {
76
$this->_setBaseAmount(0.00);
77
$this->_setAmount(0.00);
94
'title' => Mage::helper('mundipagg')->__('Interest'),
95
'value' => $address->getMundipaggInterest()
96
));
97
+ $this->collect($address);
98
}
99
}
100
}
app/code/community/Uecommerce/Mundipagg/Model/Recurrencepayment.php ADDED
@@ -0,0 +1,131 @@
1
+ <?php
2
+
3
+ class Uecommerce_Mundipagg_Model_RecurrencePayment extends Uecommerce_Mundipagg_Model_Standard
4
+ {
5
+ /**
6
+ * Availability options
7
+ */
8
+ protected $_code = 'mundipagg_recurrencepayment';
9
+ protected $_formBlockType = 'mundipagg/standard_form';
10
+ protected $_infoBlockType = 'mundipagg/info';
11
+ protected $_isGateway = true;
12
+ protected $_canOrder = true;
13
+ protected $_canAuthorize = true;
14
+ protected $_canCapture = true;
15
+ protected $_canCapturePartial = false;
16
+ protected $_canRefund = true;
17
+ protected $_canVoid = true;
18
+ protected $_canUseInternal = true;
19
+ protected $_canUseCheckout = true;
20
+ protected $_canUseForMultishipping = true;
21
+ protected $_canSaveCc = false;
22
+ protected $_canFetchTransactionInfo = false;
23
+ protected $_canManageRecurringProfiles = false;
24
+ protected $_allowCurrencyCode = array('BRL', 'USD', 'EUR');
25
+ protected $_isInitializeNeeded = true;
26
+
27
+ /**
28
+ * @access public
29
+ * @param array $data
30
+ * @return Uecommerce_Mundipagg_Model_Standard
31
+ */
32
+ public function assignData($data)
33
+ {
34
+ $info = $this->getInfoInstance();
35
+
36
+ // Reset interests first
37
+ $this->resetInterest($info);
38
+
39
+ $cctype = $data[$this->_code.'_1_1_cc_type'];
40
+ $parcelsNumber = 1;
41
+ if (
42
+ isset($data[$this->_code.'_token_1_1']) &&
43
+ $data[$this->_code.'_token_1_1'] != 'new'
44
+ ) {
45
+ $cardonFile = Mage::getModel('mundipagg/cardonfile')->load($data[$this->_code.'_token_1_1']);
46
+ $cctype = Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cardonFile->getCcType());
47
+ }
48
+
49
+ /**
50
+ * @var $interest Uecommerce_Mundipagg_Helper_Installments
51
+ */
52
+ $interest = Mage::helper('mundipagg/installments')->getInterestForCard($parcelsNumber , $cctype);
53
+ $interestInformation = array();
54
+ $interestInformation[$this->_code.'_1_1'] = new Varien_Object();
55
+ $interestInformation[$this->_code.'_1_1']->setInterest(str_replace(',','.',$interest));
56
+
57
+ if ($interest > 0) {
58
+ $info->setAdditionalInformation('mundipagg_interest_information', array());
59
+ $info->setAdditionalInformation('mundipagg_interest_information',$interestInformation);
60
+ $this->applyInterest($info, $interest);
61
+
62
+ } else {
63
+ // If none of Cc parcels doens't have interest we reset interest
64
+ $this->resetInterest($info);
65
+ }
66
+
67
+ parent::assignData($data);
68
+ }
69
+
70
+ /**
71
+ * Prepare info instance for save
72
+ *
73
+ * @return Mage_Payment_Model_Abstract
74
+ */
75
+ public function prepareSave()
76
+ {
77
+ parent::prepareSave();
78
+ }
79
+
80
+ /**
81
+ * Instantiate state and set it to state object
82
+ *
83
+ * @param string $paymentAction
84
+ * @param Varien_Object
85
+ */
86
+ public function initialize($paymentAction, $stateObject)
87
+ {
88
+ $standard = Mage::getModel('mundipagg/standard');
89
+
90
+ switch($standard->getConfigData('payment_action')) {
91
+ case 'order':
92
+ $this->setCreditCardOperationEnum('AuthAndCapture');
93
+
94
+ $paymentAction = $orderAction = 'order';
95
+ break;
96
+
97
+ case 'authorize':
98
+ $this->setCreditCardOperationEnum('AuthOnly');
99
+
100
+ $paymentAction = $orderAction = 'authorize';
101
+ break;
102
+
103
+ case 'authorize_capture':
104
+ $this->setCreditCardOperationEnum('AuthAndCaptureWithDelay');
105
+
106
+ $paymentAction = $orderAction = 'authorize_capture';
107
+ break;
108
+ }
109
+
110
+ $payment = $this->getInfoInstance();
111
+ $order = $payment->getOrder();
112
+
113
+ switch ($paymentAction) {
114
+ case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE:
115
+ parent::authorize($payment, $order->getBaseTotalDue());
116
+ break;
117
+
118
+ case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE:
119
+ parent::authorize($payment, $order->getBaseTotalDue());
120
+ break;
121
+
122
+ case $orderAction:
123
+ parent::order($payment, $order->getBaseTotalDue());
124
+ break;
125
+
126
+ default:
127
+ parent::order($payment, $order->getBaseTotalDue());
128
+ break;
129
+ }
130
+ }
131
+ }
app/code/community/Uecommerce/Mundipagg/Model/Recurrency.php CHANGED
@@ -1,33 +1,4 @@
1
<?php
2
-
3
- /**
4
- * Uecommerce
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Uecommerce EULA.
9
- * It is also available through the world-wide-web at this URL:
10
- * http://www.uecommerce.com.br/
11
- *
12
- * DISCLAIMER
13
- *
14
- * Do not edit or add to this file if you wish to upgrade the extension
15
- * to newer versions in the future. If you wish to customize the extension
16
- * for your needs please refer to http://www.uecommerce.com.br/ for more information
17
- *
18
- * @category Uecommerce
19
- * @package Uecommerce_Mundipagg
20
- * @copyright Copyright (c) 2012 Uecommerce (http://www.uecommerce.com.br/)
21
- * @license http://www.uecommerce.com.br/
22
- */
23
-
24
- /**
25
- * Mundipagg Payment module
26
- *
27
- * @category Uecommerce
28
- * @package Uecommerce_Mundipagg
29
- * @author Uecommerce Dev Team
30
- */
31
class Uecommerce_Mundipagg_Model_Recurrency extends Varien_Object {
32
33
/**
@@ -172,7 +143,8 @@ class Uecommerce_Mundipagg_Model_Recurrency extends Varien_Object {
172
'DateToStartBilling' => $this->getFormattedDateToStartBilling($frequency, $interval),
173
'Frequency' => $frequency,
174
'Interval' => $interval,
175
- 'Recurrences' => ($_product->getMundipaggRecurrences() - 1)
176
);
177
178
$this->setData('recurrency', $this->_recurrency);
@@ -191,33 +163,8 @@ class Uecommerce_Mundipagg_Model_Recurrency extends Varien_Object {
191
*/
192
public function getFormattedDateToStartBilling($frequency, $interval) {
193
$date = new Zend_Date(Mage::getModel('core/date')->timestamp(), Zend_Date::TIMESTAMP);
194
-
195
- switch ($frequency) {
196
- case '0':
197
- $frequency = null;
198
- break;
199
-
200
- case 'Daily':
201
- $frequency = 'Day';
202
- break;
203
- case 'Weekly':
204
- $frequency = 'Week';
205
- break;
206
- case 'Monthly':
207
- $frequency = 'Month';
208
- break;
209
- case 'Yearly':
210
- $frequency = 'Year';
211
- break;
212
- }
213
-
214
- $function = 'add' . $frequency;
215
-
216
- if(is_null($frequency) === false){
217
- $date->{$function}($interval);
218
- }
219
-
220
- return $date->toString('yyyy-MM-ddTHH:mm:ss');
221
}
222
223
/**
@@ -305,20 +252,11 @@ class Uecommerce_Mundipagg_Model_Recurrency extends Varien_Object {
305
foreach ($this->getRecurrencesData() as $recurrency) {
306
$newCreditCardTransactionCollection = $_request['CreditCardTransactionCollection'][0];
307
308
- if ($recurrency->hasItem()) {
309
- $amountItem = $recurrency->getItem()->getItemFinalPrice();
310
-
311
- $amount = str_replace('.', '', number_format($amountItem, 2, '.', ''));
312
- } else {
313
- $amount = str_replace('.', '', number_format($recurrency->getProduct()->getFinalPrice(), 2, '.', ''));
314
- }
315
-
316
$itemRecurrency = $recurrency->getRecurrency();
317
- $newCreditCardTransactionCollection['AmountInCents'] = $amount;
318
$newCreditCardTransactionCollection['InstallmentCount'] = $installmentCount;
319
$newCreditCardTransactionCollection['Recurrency'] = $itemRecurrency;
320
$newCreditCardTransactionCollection['CreditCardOperation'] = 'AuthOnly';
321
- $_request['CreditCardTransactionCollection'][] = $newCreditCardTransactionCollection;
322
}
323
324
return $_request;
1
<?php
2
class Uecommerce_Mundipagg_Model_Recurrency extends Varien_Object {
3
4
/**
143
'DateToStartBilling' => $this->getFormattedDateToStartBilling($frequency, $interval),
144
'Frequency' => $frequency,
145
'Interval' => $interval,
146
+ 'OneDollarAuth' => true,
147
+ 'Recurrences' => ($_product->getMundipaggRecurrences())
148
);
149
150
$this->setData('recurrency', $this->_recurrency);
163
*/
164
public function getFormattedDateToStartBilling($frequency, $interval) {
165
$date = new Zend_Date(Mage::getModel('core/date')->timestamp(), Zend_Date::TIMESTAMP);
166
+ $data = $date->toString('yyyy-MM-ddTHH:mm:ss');
167
+ return $data;
168
}
169
170
/**
252
foreach ($this->getRecurrencesData() as $recurrency) {
253
$newCreditCardTransactionCollection = $_request['CreditCardTransactionCollection'][0];
254
255
$itemRecurrency = $recurrency->getRecurrency();
256
$newCreditCardTransactionCollection['InstallmentCount'] = $installmentCount;
257
$newCreditCardTransactionCollection['Recurrency'] = $itemRecurrency;
258
$newCreditCardTransactionCollection['CreditCardOperation'] = 'AuthOnly';
259
+ $_request['CreditCardTransactionCollection'][0] = $newCreditCardTransactionCollection;
260
}
261
262
return $_request;
app/code/community/Uecommerce/Mundipagg/Model/Source/Cctypes.php CHANGED
@@ -45,8 +45,8 @@ class Uecommerce_Mundipagg_Model_Source_Cctypes
45
public function getCcTypeForLabel($label){
46
$ccTypes = $this->toOptionArray();
47
foreach($ccTypes as $cc){
48
- if($cc['label'] == $label){
49
- return $cc['value'];
50
}
51
}
52
}
45
public function getCcTypeForLabel($label){
46
$ccTypes = $this->toOptionArray();
47
foreach($ccTypes as $cc){
48
+ if($cc['value'] == $label){
49
+ return $cc['label'];
50
}
51
}
52
}
app/code/community/Uecommerce/Mundipagg/Model/Standard.php CHANGED
@@ -1,2455 +1,2481 @@
1
<?php
2
- /**
3
- * Uecommerce
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the Uecommerce EULA.
8
- * It is also available through the world-wide-web at this URL:
9
- * http://www.uecommerce.com.br/
10
- *
11
- * DISCLAIMER
12
- *
13
- * Do not edit or add to this file if you wish to upgrade the extension
14
- * to newer versions in the future. If you wish to customize the extension
15
- * for your needs please refer to http://www.uecommerce.com.br/ for more information
16
- *
17
- * @category Uecommerce
18
- * @package Uecommerce_Mundipagg
19
- * @copyright Copyright (c) 2012 Uecommerce (http://www.uecommerce.com.br/)
20
- * @license http://www.uecommerce.com.br/
21
- */
22
-
23
- /**
24
- * Mundipagg Payment module
25
- *
26
- * @category Uecommerce
27
- * @package Uecommerce_Mundipagg
28
- * @author Uecommerce Dev Team
29
- */
30
class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abstract {
31
- /**
32
- * Availability options
33
- */
34
- protected $_code = 'mundipagg_standard';
35
- protected $_formBlockType = 'mundipagg/standard_form';
36
- protected $_infoBlockType = 'mundipagg/info';
37
- protected $_isGateway = true;
38
- protected $_canOrder = true;
39
- protected $_canAuthorize = true;
40
- protected $_canCapture = true;
41
- protected $_canCapturePartial = false;
42
- protected $_canRefund = true;
43
- protected $_canVoid = true;
44
- protected $_canUseInternal = false;
45
- protected $_canUseCheckout = false;
46
- protected $_canUseForMultishipping = true;
47
- protected $_canSaveCc = false;
48
- protected $_canFetchTransactionInfo = false;
49
- protected $_canManageRecurringProfiles = false;
50
- protected $_allowCurrencyCode = array('BRL', 'USD', 'EUR');
51
- protected $_isInitializeNeeded = true;
52
-
53
- /**
54
- * Transaction ID
55
- **/
56
- protected $_transactionId = null;
57
-
58
- /**
59
- * CreditCardOperationEnum na gateway
60
- * @var $CreditCardOperationEnum varchar
61
- */
62
- private $_creditCardOperationEnum;
63
-
64
- public function getUrl() {
65
- return $this->url;
66
- }
67
-
68
- public function setUrl($url) {
69
- $this->url = $url;
70
- }
71
-
72
- public function setmerchantKey($merchantKey) {
73
- $this->merchantKey = $merchantKey;
74
- }
75
-
76
- public function getmerchantKey() {
77
- return $this->merchantKey;
78
- }
79
-
80
- public function setEnvironment($environment) {
81
- $this->environment = $environment;
82
- }
83
-
84
- public function getEnvironment() {
85
- return $this->environment;
86
- }
87
-
88
- public function setPaymentMethodCode($paymentMethodCode) {
89
- $this->paymentMethodCode = $paymentMethodCode;
90
- }
91
-
92
- public function getPaymentMethodCode() {
93
- return $this->paymentMethodCode;
94
- }
95
-
96
- public function setAntiFraud($antiFraud) {
97
- $this->antiFraud = $antiFraud;
98
- }
99
-
100
- public function getAntiFraud() {
101
- return $this->antiFraud;
102
- }
103
-
104
- public function setBankNumber($bankNumber) {
105
- $this->bankNumber = $bankNumber;
106
- }
107
-
108
- public function getBankNumber() {
109
- return $this->bankNumber;
110
- }
111
-
112
- public function setDebug($debug) {
113
- $this->_debug = $debug;
114
- }
115
-
116
- public function getDebug() {
117
- return $this->_debug;
118
- }
119
-
120
- public function setDiasValidadeBoleto($diasValidadeBoleto) {
121
- $this->_diasValidadeBoleto = $diasValidadeBoleto;
122
- }
123
-
124
- public function getDiasValidadeBoleto() {
125
- return $this->_diasValidadeBoleto;
126
- }
127
-
128
- public function setInstrucoesCaixa($instrucoesCaixa) {
129
- $this->_instrucoesCaixa = $instrucoesCaixa;
130
- }
131
-
132
- public function getInstrucoesCaixa() {
133
- return $this->_instrucoesCaixa;
134
- }
135
-
136
- public function setCreditCardOperationEnum($creditCardOperationEnum) {
137
- $this->_creditCardOperationEnum = $creditCardOperationEnum;
138
- }
139
-
140
- public function getCreditCardOperationEnum() {
141
- return $this->_creditCardOperationEnum;
142
- }
143
-
144
- public function setParcelamento($parcelamento) {
145
- $this->parcelamento = $parcelamento;
146
- }
147
-
148
- public function getParcelamento() {
149
- return $this->parcelamento;
150
- }
151
-
152
- public function setParcelamentoMax($parcelamentoMax) {
153
- $this->parcelamentoMax = $parcelamentoMax;
154
- }
155
-
156
- public function getParcelamentoMax() {
157
- return $this->parcelamentoMax;
158
- }
159
-
160
- public function setPaymentAction($paymentAction) {
161
- $this->paymentAction = $paymentAction;
162
- }
163
-
164
- public function getPaymentAction() {
165
- return $this->paymentAction;
166
- }
167
-
168
- public function setCieloSku($cieloSku) {
169
- $this->cieloSku = $cieloSku;
170
- }
171
-
172
- public function getCieloSku() {
173
- return $this->cieloSku;
174
- }
175
-
176
- public function __construct($Store = null) {
177
- if (!($Store instanceof Mage_Core_Model_Store)) {
178
- $Store = null;
179
- }
180
- $this->setEnvironment($this->getConfigData('environment', $Store));
181
- switch ($this->getEnvironment()) {
182
- case 'localhost':
183
- case 'development':
184
- case 'staging':
185
- default:
186
- $environment = 'Staging';
187
- $this->setPaymentMethodCode(1);
188
- $this->setBankNumber(341);
189
- break;
190
- case 'production':
191
- $environment = 'Production';
192
- break;
193
- }
194
- $this->setmerchantKey(trim($this->getConfigData('merchantKey'.$environment, $Store)));
195
- $this->setUrl(trim($this->getConfigData('apiUrl'.$environment, $Store)));
196
- $this->setPaymentAction($this->getConfigData('payment_action', $Store));
197
- $this->setAntiFraud($this->getConfigData('antifraud', $Store));
198
- $this->setParcelamento($this->getConfigData('parcelamento', $Store));
199
- $this->setParcelamentoMax($this->getConfigData('parcelamento_max', $Store));
200
- $this->setDebug($this->getConfigData('debug', $Store));
201
- $this->setEnvironment($this->getConfigData('environment', $Store));
202
- $this->setCieloSku($this->getConfigData('cielo_sku', $Store));
203
- }
204
-
205
- public function getConfigData($field, $storeId = null)
206
- {
207
- if (null === $storeId) {
208
- $storeId = $this->getStore();
209
- }
210
- $code = $this->getCode();
211
- $path = 'payment/'.$code.'/'.$field;
212
- $data = Mage::getStoreConfig($path, $storeId);
213
- if(!$data && $code != 'mundipagg_standard') {
214
- $path = 'payment/mundipagg_standard/'.$field;
215
- $data = Mage::getStoreConfig($path, $storeId);
216
- }
217
- return $data;
218
- }
219
-
220
- /**
221
- * Armazena as informações passadas via formulário no frontend
222
- * @access public
223
- * @param array $data
224
- * @return Uecommerce_Mundipagg_Model_Standard
225
- */
226
- public function assignData($data) {
227
- if (!($data instanceof Varien_Object)) {
228
- $data = new Varien_Object($data);
229
- }
230
-
231
- $info = $this->getInfoInstance();
232
- $mundipagg = array();
233
- $helper = Mage::helper('mundipagg');
234
-
235
- foreach ($data->getData() as $id => $value) {
236
- $mundipagg[$id] = $value;
237
-
238
- // We verify if a CPF OR CNPJ is valid
239
- $posTaxvat = strpos($id, 'taxvat');
240
-
241
- if ($posTaxvat !== false && $value != '') {
242
- if (!$helper->validateCPF($value) && !$helper->validateCNPJ($value)) {
243
- $error = $helper->__('CPF or CNPJ is invalid');
244
-
245
- Mage::throwException($error);
246
- }
247
- }
248
- }
249
-
250
- if (!empty($mundipagg)) {
251
- $helperInstallments = Mage::helper('mundipagg/Installments');
252
-
253
- //Set Mundipagg Data in Session
254
- $session = Mage::getSingleton('checkout/session');
255
- $session->setMundipaggData($mundipagg);
256
-
257
- $info = $this->getInfoInstance();
258
-
259
- if (isset($mundipagg['mundipagg_type'])) {
260
- $info->setAdditionalInformation('PaymentMethod', $mundipagg['method']);
261
-
262
- switch ($mundipagg['method']) {
263
- case 'mundipagg_creditcard':
264
- if (isset($mundipagg['mundipagg_creditcard_1_1_cc_type'])) {
265
- if (array_key_exists('mundipagg_creditcard_credito_parcelamento_1_1', $mundipagg)) {
266
- if ($mundipagg['mundipagg_creditcard_credito_parcelamento_1_1'] > $helperInstallments->getMaxInstallments($mundipagg['mundipagg_creditcard_1_1_cc_type'])) {
267
- Mage::throwException($helper->__('it is not possible to divide by %s times', $mundipagg['mundipagg_creditcard_credito_parcelamento_1_1']));
268
- }
269
- }
270
- $info->setCcType($mundipagg['mundipagg_creditcard_1_1_cc_type'])
271
- ->setCcOwner($mundipagg['mundipagg_creditcard_cc_holder_name_1_1'])
272
- ->setCcLast4(substr($mundipagg['mundipagg_creditcard_1_1_cc_number'], -4))
273
- ->setCcNumber($mundipagg['mundipagg_creditcard_1_1_cc_number'])
274
- ->setCcCid($mundipagg['mundipagg_creditcard_cc_cid_1_1'])
275
- ->setCcExpMonth($mundipagg['mundipagg_creditcard_expirationMonth_1_1'])
276
- ->setCcExpYear($mundipagg['mundipagg_creditcard_expirationYear_1_1']);
277
- } else {
278
- $info->setAdditionalInformation('mundipagg_creditcard_token_1_1', $mundipagg['mundipagg_creditcard_token_1_1']);
279
- }
280
-
281
- break;
282
-
283
- default:
284
-
285
- $info->setCcType(null)
286
- ->setCcOwner(null)
287
- ->setCcLast4(null)
288
- ->setCcNumber(null)
289
- ->setCcCid(null)
290
- ->setCcExpMonth(null)
291
- ->setCcExpYear(null);
292
-
293
- break;
294
- }
295
-
296
- foreach ($mundipagg as $key => $value) {
297
- // We don't save CcNumber
298
- $posCcNumber = strpos($key, 'number');
299
-
300
- // We don't save Security Code
301
- $posCid = strpos($key, 'cid');
302
-
303
- // We don't save Cc Holder name
304
- $posHolderName = strpos($key, 'holder_name');
305
-
306
- if ($value != '' &&
307
- $posCcNumber === false &&
308
- $posCid === false &&
309
- $posHolderName === false
310
- ) {
311
- if (strpos($key, 'cc_type')) {
312
- $value = $helper->issuer($value);
313
- }
314
-
315
- $info->setAdditionalInformation($key, $value);
316
- }
317
- }
318
-
319
- // We check if quote grand total is equal to installments sum
320
- if ($mundipagg['method'] != 'mundipagg_boleto'
321
- && $mundipagg['method'] != 'mundipagg_creditcardoneinstallment'
322
- && $mundipagg['method'] != 'mundipagg_creditcard'
323
- ) {
324
- $num = $helper->getCreditCardsNumber($mundipagg['method']);
325
- $method = $helper->getPaymentMethod($num);
326
-
327
- (float)$grandTotal = $info->getQuote()->getGrandTotal();
328
- (float)$totalInstallmentsToken = 0;
329
- (float)$totalInstallmentsNew = 0;
330
- (float)$totalInstallments = 0;
331
-
332
- for ($i = 1; $i <= $num; $i++) {
333
-
334
- if (isset($mundipagg[$method . '_token_' . $num . '_' . $i]) && $mundipagg[$method . '_token_' . $num . '_' . $i] != 'new') {
335
- (float)$value = str_replace(',', '.', $mundipagg[$method . '_value_' . $num . '_' . $i]);
336
-
337
- if (array_key_exists($method . '_credito_parcelamento_' . $num . '_' . $i, $mundipagg)) {
338
- if (!array_key_exists($method . '_' . $num . '_' . $i . '_cc_type', $mundipagg)) {
339
- $cardonFile = Mage::getModel('mundipagg/cardonfile')->load($mundipagg[$method . '_token_' . $num . '_' . $i]);
340
-
341
- $mundipagg[$method . '_' . $num . '_' . $i . '_cc_type'] = Mage::helper('mundipagg')->getCardTypeByIssuer($cardonFile->getCcType());
342
- }
343
-
344
- if ($mundipagg[$method . '_credito_parcelamento_' . $num . '_' . $i] > $helperInstallments->getMaxInstallments($mundipagg[$method . '_' . $num . '_' . $i . '_cc_type'], $value)) {
345
- Mage::throwException($helper->__('it is not possible to divide by %s times', $mundipagg[$method . '_credito_parcelamento_' . $num . '_' . $i]));
346
- }
347
- }
348
-
349
- (float)$totalInstallmentsToken += $value;
350
- } else {
351
- (float)$value = str_replace(',', '.', $mundipagg[$method . '_new_value_' . $num . '_' . $i]);
352
-
353
- if (array_key_exists($method . '_new_credito_parcelamento_' . $num . '_' . $i, $mundipagg)) {
354
- if ($mundipagg[$method . '_new_credito_parcelamento_' . $num . '_' . $i] > $helperInstallments->getMaxInstallments($mundipagg[$method . '_' . $num . '_' . $i . '_cc_type'], $value)) {
355
- Mage::throwException($helper->__('it is not possible to divide by %s times', $mundipagg[$method . '_new_credito_parcelamento_' . $num . '_' . $i]));
356
- }
357
- }
358
-
359
- (float)$totalInstallmentsNew += $value;
360
- }
361
- }
362
-
363
- // Total Installments from token and Credit Card
364
- (float)$totalInstallments = $totalInstallmentsToken + $totalInstallmentsNew;
365
-
366
- // If an amount has already been authorized
367
- if (isset($mundipagg['multi']) && Mage::getSingleton('checkout/session')->getAuthorizedAmount()) {
368
- (float)$totalInstallments += (float)Mage::getSingleton('checkout/session')->getAuthorizedAmount();
369
-
370
- // Unset session
371
- Mage::getSingleton('checkout/session')->setAuthorizedAmount();
372
- }
373
-
374
- $epsilon = 0.00001;
375
- }
376
- } else {
377
- if (isset($mundipagg['method'])) {
378
- $info->setAdditionalInformation('PaymentMethod', $mundipagg['method']);
379
- }
380
- }
381
- }
382
-
383
- // Get customer_id from Quote (payment made on site) or from POST (payment made from API)
384
- if (Mage::getSingleton('customer/session')->isLoggedIn()) {
385
- if ($this->getQuote()->getCustomer()->getEntityId()) {
386
- $customerId = $this->getQuote()->getCustomer()->getEntityId();
387
- }
388
- } elseif (isset($mundipagg['entity_id'])) {
389
- $customerId = $mundipagg['entity_id'];
390
- }
391
-
392
- // We verifiy if token is from customer
393
- if (isset($customerId) && isset($mundipagg['method'])) {
394
- $num = $helper->getCreditCardsNumber($mundipagg['method']);
395
-
396
- if ($num == 0) {
397
- $num = 1;
398
- }
399
-
400
- foreach ($mundipagg as $key => $value) {
401
- $pos = strpos($key, 'token_' . $num);
402
-
403
- if ($pos !== false && $value != '' && $value != 'new') {
404
- $token = Mage::getModel('mundipagg/cardonfile')->load($value);
405
-
406
- if ($token->getId() && $token->getEntityId() == $customerId) {
407
- // Ok
408
- $info->setAdditionalInformation('CreditCardBrandEnum_' . $key, $token->getCcType());
409
- } else {
410
- $error = $helper->__('Token not found');
411
-
412
- //Log error
413
- Mage::log($error, null, 'Uecommerce_Mundipagg.log');
414
-
415
- Mage::throwException($error);
416
- }
417
- }
418
- }
419
- }
420
-
421
- return $this;
422
- }
423
-
424
- /**
425
- * Prepare info instance for save
426
- *
427
- * @return Mage_Payment_Model_Abstract
428
- */
429
- public function prepareSave() {
430
- $info = $this->getInfoInstance();
431
- if ($this->_canSaveCc) {
432
- $info->setCcNumberEnc($info->encrypt($info->getCcNumber()));
433
- }
434
-
435
- $info->setCcNumber(null);
436
-
437
- return $this;
438
- }
439
-
440
- /**
441
- * Get payment quote
442
- */
443
- public function getPayment() {
444
- return $this->getQuote()->getPayment();
445
- }
446
-
447
- /**
448
- * Get Modulo session namespace
449
- *
450
- * @return Uecommerce_Mundipagg_Model_Session
451
- */
452
- public function getSession() {
453
- return Mage::getSingleton('mundipagg/session');
454
- }
455
-
456
- /**
457
- * Get checkout session namespace
458
- *
459
- * @return Mage_Checkout_Model_Session
460
- */
461
- public function getCheckout() {
462
- return Mage::getSingleton('checkout/session');
463
- }
464
-
465
- /**
466
- * Get current quote
467
- *
468
- * @return Mage_Sales_Model_Quote
469
- */
470
- public function getQuote() {
471
- return $this->getCheckout()->getQuote();
472
- }
473
-
474
- /**
475
- * Check order availability
476
- *
477
- * @return bool
478
- */
479
- public function canOrder() {
480
- return $this->_canOrder;
481
- }
482
-
483
- /**
484
- * Check authorize availability
485
- *
486
- * @return bool
487
- */
488
- public function canAuthorize() {
489
- return $this->_canAuthorize;
490
- }
491
-
492
- /**
493
- * Check capture availability
494
- *
495
- * @return bool
496
- */
497
- public function canCapture() {
498
- return $this->_canCapture;
499
- }
500
-
501
- /**
502
- * Instantiate state and set it to state object
503
- *
504
- * @param string $paymentAction
505
- * @param Varien_Object
506
- */
507
- public function initialize($paymentAction, $stateObject) {
508
- // TODO move initialize method to appropriate model (Boleto, Creditcard ...)
509
- $paymentAction = $this->getPaymentAction();
510
-
511
- switch ($paymentAction) {
512
- case 'order':
513
- $this->setCreditCardOperationEnum('AuthAndCapture');
514
- break;
515
-
516
- case 'authorize':
517
- $this->setCreditCardOperationEnum('AuthOnly');
518
- break;
519
-
520
- case 'authorize_capture':
521
- $this->setCreditCardOperationEnum('AuthAndCaptureWithDelay');
522
- break;
523
- }
524
-
525
- $orderAction = Mage_Payment_Model_Method_Abstract::ACTION_ORDER;
526
- $payment = $this->getInfoInstance();
527
- $order = $payment->getOrder();
528
-
529
- // If payment method is Boleto Bancário we call "order" method
530
- if ($payment->getAdditionalInformation('PaymentMethod') == 'mundipagg_boleto') {
531
- $this->order($payment, $order->getBaseTotalDue());
532
-
533
- return $this;
534
- }
535
-
536
- // If it's a multi-payment types we force to ACTION_AUTHORIZE
537
- $num = Mage::helper('mundipagg')->getCreditCardsNumber($payment->getAdditionalInformation('PaymentMethod'));
538
-
539
- if ($num > 1) {
540
- $paymentAction = Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
541
- }
542
-
543
- switch ($paymentAction) {
544
- case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE:
545
- $payment->authorize($payment, $order->getBaseTotalDue());
546
- break;
547
-
548
- case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE:
549
- $payment->authorize($payment, $order->getBaseTotalDue());
550
- break;
551
-
552
- case $orderAction:
553
- $this->order($payment, $order->getBaseTotalDue());
554
- break;
555
-
556
- default:
557
- $this->order($payment, $order->getBaseTotalDue());
558
- break;
559
- }
560
- }
561
-
562
- /**
563
- * Authorize payment abstract method
564
- *
565
- * @param Varien_Object $payment
566
- * @param float $amount
567
- *
568
- * @return Mage_Payment_Model_Abstract