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
569
- */
570
- public function authorize(Varien_Object $payment, $amount) {
571
- try {
572
- if (!$this->canAuthorize()) {
573
- Mage::throwException(Mage::helper('payment')->__('Authorize action is not available.'));
574
- }
575
-
576
- // Load order
577
- $order = $payment->getOrder();
578
-
579
- // Proceed to authorization on Gateway
580
- $resultPayment = $this->doPayment($payment, $order);
581
- $helper = Mage::helper('mundipagg');
582
- $result = $helper->issetOr($resultPayment['result'], false);
583
- $ccResultCollection = $helper->issetOr($result['CreditCardTransactionResultCollection']);
584
-
585
- if ($result === false) {
586
- return $this->integrationTimeOut($order, $payment);
587
- }
588
-
589
- // Return error
590
- if (isset($resultPayment['error'])) {
591
- return $this->paymentError($payment, $resultPayment);
592
- }
593
-
594
- if (is_null($ccResultCollection) === false) {
595
- // We record transaction(s)
596
- if (count($ccResultCollection) == 1) {
597
- $trans = $ccResultCollection[0];
598
- $this->_addTransaction($payment, $trans['TransactionKey'], Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, $trans);
599
-
600
- } else {
601
- foreach ($ccResultCollection as $key => $trans) {
602
- $this->_addTransaction($payment, $trans['TransactionKey'], Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, $trans, $key);
603
- }
604
- }
605
- }
606
-
607
- // Return
608
- if (isset($resultPayment['error'])) {
609
- try {
610
- $payment->setSkipOrderProcessing(true)->save();
611
-
612
- if (empty($resultPayment['ErrorDescription']) === false) {
613
- Mage::throwException(Mage::helper('mundipagg')->__($resultPayment['ErrorDescription']));
614
- }
615
-
616
- } catch (Exception $e) {
617
- Mage::logException($e);
618
-
619
- return $this;
620
- }
621
- } else {
622
- $accPaymentAuthorizationAmount = sprintf($order->getPaymentAuthorizationAmount());
623
- $accGrandTotal = sprintf($order->getGrandTotal());
624
-
625
- // Send new order email when not in admin
626
- if ((Mage::app()->getStore()->getCode() != 'admin') && ($accPaymentAuthorizationAmount == $accGrandTotal)) {
627
- $order->sendNewOrderEmail();
628
- }
629
-
630
- // We can capture only if:
631
- // 1. Multiple Credit Cards Payment
632
- // 2. Anti fraud is disabled
633
- // 3. Payment action is "AuthorizeAndCapture"
634
- // 4. Authorization amount is equal to grand_total
635
- if (
636
- count($ccResultCollection) > 1
637
- && $this->getAntiFraud() == 0
638
- && $this->getPaymentAction() == 'order'
639
- && $accPaymentAuthorizationAmount == $accGrandTotal
640
- ) {
641
- $this->captureAndcreateInvoice($payment);
642
- }else if ($accPaymentAuthorizationAmount != $accGrandTotal){
643
- $order->cancel();
644
- $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
645
- $order->setStatus(Mage_Sales_Model_Order::STATE_CANCELED);
646
- $order->save();
647
  }
648
- }
649
- return $this;
650
-
651
- } catch (Exception $e) {
652
- Mage::logException($e);
653
- }
654
- }
655
-
656
- /**
657
- * Capture payment abstract method
658
- *
659
- * @param Varien_Object $payment
660
- * @param float $amount
661
- *
662
- * @return Mage_Payment_Model_Abstract
663
- */
664
- public function capture(Varien_Object $payment, $amount) {
665
- $helper = Mage::helper('mundipagg');
666
- $captureCase = $helper->issetOr($_POST['invoice']['capture_case'], 'offline');
667
-
668
- if ($captureCase === 'online') {
669
- $this->captureOnline($payment);
670
-
671
- return $this;
672
- }
673
-
674
- if (!$this->canCapture()) {
675
- Mage::throwException($helper->__('Capture action is not available.'));
676
- }
677
-
678
- if ($payment->getAdditionalInformation('PaymentMethod') == 'mundipagg_boleto') {
679
- Mage::throwException($helper->__('You cannot capture Boleto Bancário.'));
680
- }
681
-
682
- if ($this->getAntiFraud() == 1) {
683
- Mage::throwException($helper->__('You cannot capture having anti fraud activated.'));
684
- }
685
-
686
- // Already captured
687
- if ($payment->getAdditionalInformation('CreditCardTransactionStatusEnum') == 'Captured' || $payment->getAdditionalInformation('CreditCardTransactionStatus') == 'Captured') {
688
- return $this;
689
- }
690
-
691
- /* @var Mage_Sales_Model_Order_Payment $payment */
692
- $orderkeys = (array)$payment->getAdditionalInformation('OrderKey');
693
-
694
- if (empty($orderkeys)) {
695
- Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
696
-
697
- return false;
698
- }
699
-
700
- foreach ($orderkeys as $orderkey) {
701
- /* @var Uecommerce_Mundipagg_Model_Api $api */
702
- $api = Mage::getModel('mundipagg/api');
703
- //Call Gateway Api
704
- $capture = $api->saleCapture(['OrderKey' => $orderkey], $payment->getOrder()->getIncrementId());
705
- $ccTxnResultCollection = $helper->issetOr($capture['CreditCardTransactionResultCollection']);
706
-
707
- if (!is_array($ccTxnResultCollection)
708
- || is_null($ccTxnResultCollection)
709
- || empty($ccTxnResultCollection)
710
- ) {
711
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
712
-
713
- return false;
714
- }
715
-
716
- // Save transactions
717
- foreach ($ccTxnResultCollection as $txn) {
718
- $this->_addTransaction(
719
- $payment,
720
- $txn['TransactionKey'],
721
- Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE,
722
- $txn
723
- );
724
- }
725
- }
726
-
727
- return true;
728
- }
729
-
730
- /**
731
- * Online capture payment abstract methodl
732
- *
733
- * @param Varien_Object $payment
734
- * @return $this
735
- */
736
- public function captureOnline(Varien_Object $payment) {
737
- /* @var Uecommerce_Mundipagg_Helper_Data $helper */
738
- $helper = Mage::helper('mundipagg');
739
-
740
- if (!$this->canCapture()) {
741
- Mage::throwException($helper->__('Capture action is not available.'));
742
- }
743
-
744
- if ($payment->getAdditionalInformation('PaymentMethod') == 'mundipagg_boleto') {
745
- Mage::throwException($helper->__('You cannot capture Boleto Bancário.'));
746
- }
747
-
748
- if ($this->getAntiFraud() == 1) {
749
- Mage::throwException($helper->__('You cannot capture having anti fraud activated.'));
750
- }
751
-
752
- // Already captured
753
- if ($payment->getAdditionalInformation('CreditCardTransactionStatusEnum') == 'Captured'
754
- || $payment->getAdditionalInformation('CreditCardTransactionStatus') == 'Captured'
755
- ) {
756
- Mage::throwException($helper->__('Transactions already captured'));
757
- }
758
-
759
- /* @var Mage_Sales_Model_Order_Payment $payment */
760
- $orderkeys = (array)$payment->getAdditionalInformation('OrderKey');
761
-
762
- if (empty($orderkeys)) {
763
- Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
764
- }
765
-
766
- $captureNotAllowedMsg = $helper->__('Capture was not authorized in MundiPagg');
767
- $txnsNotAuthorized = 0;
768
-
769
- foreach ($orderkeys as $orderkey) {
770
- $data['OrderKey'] = $orderkey;
771
-
772
- //Call Gateway Api
773
- /* @var Uecommerce_Mundipagg_Model_Api $api */
774
- $api = Mage::getModel('mundipagg/api');
775
- $capture = $api->saleCapture($data, $payment->getOrder()->getIncrementId());
776
-
777
- $ccTxnResultCollection = $helper->issetOr($capture['CreditCardTransactionResultCollection']);
778
-
779
- if (!is_array($ccTxnResultCollection) || is_null($ccTxnResultCollection) || empty($ccTxnResultCollection)) {
780
- Mage::throwException($captureNotAllowedMsg);
781
- }
782
-
783
- $txnsNotAuthorized = 0;
784
-
785
- // Save transactions
786
- foreach ($ccTxnResultCollection as $txn) {
787
- $this->_addTransaction(
788
- $payment,
789
- $helper->issetOr($txn['TransactionKey']),
790
- Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE,
791
- $txn
792
- );
793
-
794
- $success = $helper->issetOr($txn['Success'], false);
795
-
796
- if ($success === false) {
797
- $txnsNotAuthorized++;
798
- }
799
- }
800
- }
801
-
802
- if ($txnsNotAuthorized === 1) {
803
- Mage::throwException($captureNotAllowedMsg);
804
- } elseif ($txnsNotAuthorized > 1) {
805
- Mage::throwException($helper->__('Capture partial authorized'));
806
- }
807
-
808
- $this->closeAuthorizationTxns($payment->getOrder());
809
-
810
- // if has just 1 invoice, update his grand total, adding the credit cards interests
811
- if (count($payment->getOrder()->getInvoiceCollection()) === 1) {
812
-
813
- /* @var Mage_Sales_Model_Order_Invoice $invoice */
814
- $invoice = $payment->getOrder()->getInvoiceCollection()->getItems()[0];
815
- $this->equalizeInvoiceTotals($invoice);
816
- }
817
- }
818
-
819
- public function closeAuthorizationTxns(Mage_Sales_Model_Order $order) {
820
- $txnsCollection = Mage::getModel('sales/order_payment_transaction')
821
- ->getCollection()
822
- ->addAttributeToFilter('order_id', array('eq' => $order->getId()));
823
-
824
- /* @var Mage_Paypal_Model_Payment_Transaction $txn */
825
- foreach ($txnsCollection as $txn) {
826
- if ($txn->getTxnType() === 'authorization') {
827
- $txn->setOrderPaymentObject($order->getPayment());
828
- $txn->setIsClosed(true)->save();
829
- }
830
- }
831
- }
832
-
833
- /**
834
- * Capture payment abstract method
835
- *
836
- * @param Varien_Object $payment
837
- * @param float $amount
838
- *
839
- * @return Mage_Payment_Model_Abstract
840
- */
841
- public function captureAndcreateInvoice(Varien_Object $payment) {
842
- $order = $payment->getOrder();
843
-
844
- // Capture
845
- $capture = $this->capture($payment, $order->getGrandTotal());
846
-
847
- // Error
848
- if (!$capture) {
849
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
850
-
851
- return $this;
852
- }
853
-
854
- // Create invoice
855
- $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(array());
856
- $invoice->register();
857
-
858
- $invoice->setCanVoidFlag(true);
859
- $invoice->getOrder()->setIsInProcess(true);
860
- $invoice->setState(2);
861
-
862
- if (Mage::helper('sales')->canSendNewInvoiceEmail($order->getStoreId())) {
863
- $invoice->setEmailSent(true);
864
- $invoice->sendEmail();
865
- }
866
-
867
- $invoice->save();
868
-
869
- $order->setBaseTotalPaid($order->getBaseGrandTotal());
870
- $order->setTotalPaid($order->getBaseGrandTotal());
871
- $order->addStatusHistoryComment('Captured online amount of R$' . $order->getBaseGrandTotal(), false);
872
- $order->save();
873
-
874
- $this->closeAuthorizationTxns($order);
875
- $this->equalizeInvoiceTotals($invoice);
876
-
877
- return $this;
878
- }
879
-
880
- /**
881
- * Order payment abstract method
882
- *
883
- * @param Varien_Object $payment
884
- * @param float $amount
885
- *
886
- * @return Mage_Payment_Model_Abstract
887
- */
888
- public function order(Varien_Object $payment, $amount) {
889
- if (!$this->canOrder()) {
890
- Mage::throwException(Mage::helper('payment')->__('Order action is not available.'));
891
- }
892
-
893
- // Load order
894
- $order = $payment->getOrder();
895
- $order = Mage::getModel('sales/order')->loadByIncrementId($order->getRealOrderId());
896
-
897
- // Proceed to payment on Gateway
898
- $resultPayment = $this->doPayment($payment, $order);
899
-
900
- $helper = Mage::helper('mundipagg');
901
- $result = $helper->issetOr($resultPayment['result'], false);
902
-
903
- if ($result === false) {
904
- return $this->integrationTimeOut($order, $payment);
905
- }
906
-
907
- // Return error
908
- if (isset($resultPayment['error'])) {
909
- return $this->paymentError($payment, $resultPayment);
910
- }
911
-
912
- if (isset($resultPayment['message'])) {
913
-
914
- $transactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER;
915
-
916
- // Xml
917
- $xml = $resultPayment['result'];
918
- $json = json_encode($xml);
919
-
920
- $resultPayment['result'] = array();
921
- $resultPayment['result'] = json_decode($json, true);
922
-
923
- switch ($resultPayment['message']) {
924
- // Boleto
925
- case 0:
926
- $boletoTransactionCollection = $helper->issetOr(
927
- $resultPayment['result']['BoletoTransactionResultCollection'][0]
928
- );
929
-
930
- $boletoUrl = $helper->issetOr($boletoTransactionCollection['BoletoUrl']);
931
-
932
- if (is_null($boletoUrl) === false) {
933
- $payment->setAdditionalInformation('BoletoUrl', $boletoUrl);
934
-
935
- // In order to show "Print Boleto" link in order email
936
- $order->getPayment()->setAdditionalInformation('BoletoUrl', $boletoUrl);
937
- }
938
-
939
- $transactionKey = $helper->issetOr($boletoTransactionCollection['TransactionKey']);
940
- $this->_addTransaction($payment, $transactionKey, $transactionType, $boletoTransactionCollection);
941
-
942
- // We record transaction(s)
943
- if (count($resultPayment['result']['BoletoTransactionResultCollection']) == 1) {
944
- $trans = $boletoTransactionCollection;
945
- $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans);
946
-
947
- } else {
948
- foreach ($boletoTransactionCollection as $key => $trans) {
949
- $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans, $key);
950
- }
951
- }
952
-
953
- $payment->setTransactionId($this->_transactionId);
954
- $payment->save();
955
-
956
- // Send new order email when not in admin
957
- if (Mage::app()->getStore()->getCode() != 'admin') {
958
- $order->sendNewOrderEmail();
959
- }
960
-
961
- break;
962
-
963
- // Credit Card
964
- case 1:
965
- $creditCardTransactionResultCollection = $result['CreditCardTransactionResultCollection'];
966
- $transactionsQty = count($creditCardTransactionResultCollection);
967
-
968
- // We record transaction(s)
969
- if ($transactionsQty == 1) {
970
- $transaction = $creditCardTransactionResultCollection[0];
971
-
972
- if (array_key_exists('TransactionKey', $transaction)) {
973
- $this->_addTransaction($payment, $transaction['TransactionKey'], $transactionType, $transaction);
974
- }
975
-
976
- } else {
977
- foreach ($creditCardTransactionResultCollection as $key => $trans) {
978
- if (array_key_exists('TransactionKey', $trans)) {
979
- $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans, $key);
980
- }
981
- }
982
- }
983
-
984
- // Send new order email when not in admin
985
- if (Mage::app()->getStore()->getCode() != 'admin') {
986
- $order->sendNewOrderEmail();
987
- }
988
-
989
- // Invoice
990
- $order = $payment->getOrder();
991
-
992
- if (!$order->canInvoice()) {
993
- // Log error
994
- Mage::logException(Mage::helper('core')->__('Cannot create an invoice.'));
995
- Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
996
- }
997
-
998
- // Create invoice
999
- $invoice = Mage::getModel('sales/service_order', $payment->getOrder())->prepareInvoice(array());
1000
- $invoice->register();
1001
-
1002
- // Set capture case to offline and register the invoice.
1003
- $invoice->setTransactionId($this->_transactionId);
1004
- $invoice->setCanVoidFlag(true);
1005
- $invoice->getOrder()->setIsInProcess(true);
1006
- $invoice->setState(2);
1007
-
1008
- // Send invoice if enabled
1009
- if (Mage::helper('sales')->canSendNewInvoiceEmail($order->getStoreId())) {
1010
- $invoice->setEmailSent(true);
1011
- $invoice->sendEmail();
1012
- }
1013
-
1014
- $invoice->save();
1015
-
1016
- $order->setBaseTotalPaid($order->getBaseGrandTotal());
1017
- $order->setTotalPaid($order->getBaseGrandTotal());
1018
- $order->addStatusHistoryComment('Captured online amount of R$' . $order->getBaseGrandTotal(), false);
1019
- $order->save();
1020
-
1021
- $payment->setLastTransId($this->_transactionId);
1022
- $payment->save();
1023
-
1024
- break;
1025
-
1026
- // Debit
1027
- case 4:
1028
- // We record transaction
1029
- $trans = $resultPayment['result'];
1030
-
1031
- $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans);
1032
- break;
1033
- }
1034
- }
1035
-
1036
- return $this;
1037
- }
1038
-
1039
- /**
1040
- * Proceed to payment
1041
- * @param object $order
1042
- */
1043
- public function doPayment($payment, $order) {
1044
- try {
1045
- $helper = Mage::helper('mundipagg');
1046
- $session = Mage::getSingleton('checkout/session');
1047
- $mundipaggData = $session->getMundipaggData();
1048
-
1049
- //Post data
1050
- $postData = Mage::app()->getRequest()->getPost();
1051
-
1052
- // Get customer taxvat
1053
- $taxvat = '';
1054
-
1055
- if ($order->getCustomerTaxvat() == '') {
1056
- $customerId = $order->getCustomerId();
1057
-
1058
- if ($customerId) {
1059
- $customer = Mage::getModel('customer/customer')->load($customerId);
1060
- $taxvat = $customer->getTaxvat();
1061
- }
1062
-
1063
- if ($taxvat != '') {
1064
- $order->setCustomerTaxvat($taxvat)->save();
1065
- }
1066
- } else {
1067
- $taxvat = $order->getCustomerTaxvat();
1068
- }
1069
-
1070
- // Data to pass to api
1071
- $data['customer_id'] = $order->getCustomerId();
1072
- $data['address_id'] = $order->getBillingAddress()->getCustomerAddressId();
1073
- $data['payment_method'] = isset($postData['payment']['method']) ? $postData['payment']['method'] : $mundipaggData['method'];
1074
- $type = $data['payment_method'];
1075
-
1076
- // 1 or more Credit Cards Payment
1077
- if ($data['payment_method'] != 'mundipagg_boleto' && $data['payment_method'] != 'mundipagg_debit') {
1078
- $num = $helper->getCreditCardsNumber($type);
1079
- $method = $helper->getPaymentMethod($num);
1080
-
1081
- if ($num == 0) {
1082
- $num = 1;
1083
- }
1084
-
1085
- for ($i = 1; $i <= $num; $i++) {
1086
- // New Credit Card
1087
- if (
1088
- !isset($postData['payment'][$method . '_token_' . $num . '_' . $i]) ||
1089
- (isset($postData['payment'][$method . '_token_' . $num . '_' . $i]) && $postData['payment'][$method . '_token_' . $num . '_' . $i] == 'new')
1090
- ) {
1091
- $data['payment'][$i]['HolderName'] = isset($postData['payment'][$method . '_cc_holder_name_' . $num . '_' . $i]) ? $postData['payment'][$method . '_cc_holder_name_' . $num . '_' . $i] : $mundipaggData[$method . '_cc_holder_name_' . $num . '_' . $i];
1092
- $data['payment'][$i]['CreditCardNumber'] = isset($postData['payment'][$method . '_' . $num . '_' . $i . '_cc_number']) ? $postData['payment'][$method . '_' . $num . '_' . $i . '_cc_number'] : $mundipaggData[$method . '_' . $num . '_' . $i . '_cc_number'];
1093
- $data['payment'][$i]['ExpMonth'] = isset($postData['payment'][$method . '_expirationMonth_' . $num . '_' . $i]) ? $postData['payment'][$method . '_expirationMonth_' . $num . '_' . $i] : $mundipaggData[$method . '_expirationMonth_' . $num . '_' . $i];
1094
- $data['payment'][$i]['ExpYear'] = isset($postData['payment'][$method . '_expirationYear_' . $num . '_' . $i]) ? $postData['payment'][$method . '_expirationYear_' . $num . '_' . $i] : $mundipaggData[$method . '_expirationYear_' . $num . '_' . $i];
1095
- $data['payment'][$i]['SecurityCode'] = isset($postData['payment'][$method . '_cc_cid_' . $num . '_' . $i]) ? $postData['payment'][$method . '_cc_cid_' . $num . '_' . $i] : $mundipaggData[$method . '_cc_cid_' . $num . '_' . $i];
1096
- $data['payment'][$i]['CreditCardBrandEnum'] = Mage::helper('mundipagg')->issuer(isset($postData['payment'][$method . '_' . $num . '_' . $i . '_cc_type']) ? $postData['payment'][$method . '_' . $num . '_' . $i . '_cc_type'] : $mundipaggData[$method . '_' . $num . '_' . $i . '_cc_type']);
1097
- $data['payment'][$i]['InstallmentCount'] = isset($postData['payment'][$method . '_new_credito_parcelamento_' . $num . '_' . $i]) ? $postData['payment'][$method . '_new_credito_parcelamento_' . $num . '_' . $i] : 1;
1098
- $data['payment'][$i]['token'] = isset($postData['payment'][$method . '_save_token_' . $num . '_' . $i]) ? $postData['payment'][$method . '_save_token_' . $num . '_' . $i] : null;
1099
-
1100
- if (isset($postData['payment'][$method . '_new_value_' . $num . '_' . $i]) && $postData['payment'][$method . '_new_value_' . $num . '_' . $i] != '') {
1101
- $data['payment'][$i]['AmountInCents'] = str_replace(',', '.', $postData['payment'][$method . '_new_value_' . $num . '_' . $i]);
1102
- $data['payment'][$i]['AmountInCents'] = $data['payment'][$i]['AmountInCents'] + Mage::helper('mundipagg/installments')->getInterestForCard($data['payment'][$i]['InstallmentCount'], isset($postData['payment'][$method . '_' . $num . '_' . $i . '_cc_type']) ? $postData['payment'][$method . '_' . $num . '_' . $i . '_cc_type'] : $mundipaggData[$method . '_' . $num . '_' . $i . '_cc_type'], $data['payment'][$i]['AmountInCents']);
1103
-
1104
- $data['payment'][$i]['AmountInCents'] = $data['payment'][$i]['AmountInCents'] * 100;
1105
- } else {
1106
- if (!isset($postData['partial'])) {
1107
- $data['payment'][$i]['AmountInCents'] = $order->getGrandTotal() * 100;
1108
- } else { // If partial payment we deduct authorized amount already processed
1109
- if (Mage::getSingleton('checkout/session')->getAuthorizedAmount()) {
1110
- $data['payment'][$i]['AmountInCents'] = ($order->getGrandTotal()) * 100 - Mage::getSingleton('checkout/session')->getAuthorizedAmount() * 100;
1111
- } else {
1112
- $data['payment'][$i]['AmountInCents'] = ($order->getGrandTotal()) * 100;
1113
- }
1114
- }
1115
- }
1116
-
1117
- $data['payment'][$i]['TaxDocumentNumber'] = isset($postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i]) ? $postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i] : $taxvat;
1118
-
1119
- } else { // Token
1120
- $data['payment'][$i]['card_on_file_id'] = isset($postData['payment'][$method . '_token_' . $num . '_' . $i]) ? $postData['payment'][$method . '_token_' . $num . '_' . $i] : $mundipaggData[$method . '_token_' . $num . '_' . $i];
1121
- $data['payment'][$i]['InstallmentCount'] = isset($postData['payment'][$method . '_credito_parcelamento_' . $num . '_' . $i]) ? $postData['payment'][$method . '_credito_parcelamento_' . $num . '_' . $i] : 1;
1122
-
1123
- if (isset($postData['payment'][$method . '_value_' . $num . '_' . $i]) && $postData['payment'][$method . '_value_' . $num . '_' . $i] != '') {
1124
- $data['payment'][$i]['AmountInCents'] = str_replace(',', '.', $postData['payment'][$method . '_value_' . $num . '_' . $i]);
1125
- $cardonFile = Mage::getModel('mundipagg/cardonfile')->load($postData['payment'][$method . '_token_' . $num . '_' . $i]);
1126
- $tokenCctype = Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cardonFile->getCcType());
1127
- $data['payment'][$i]['AmountInCents'] = $data['payment'][$i]['AmountInCents'] + Mage::helper('mundipagg/installments')->getInterestForCard($data['payment'][$i]['InstallmentCount'], $tokenCctype, $data['payment'][$i]['AmountInCents']);
1128
- $data['payment'][$i]['AmountInCents'] = $data['payment'][$i]['AmountInCents'] * 100;
1129
-
1130
- } else {
1131
- if (!isset($postData['partial'])) {
1132
- $data['payment'][$i]['AmountInCents'] = $order->getGrandTotal() * 100;
1133
- } else { // If partial payment we deduct authorized amount already processed
1134
- if (Mage::getSingleton('checkout/session')->getAuthorizedAmount()) {
1135
- $data['payment'][$i]['AmountInCents'] = ($order->getGrandTotal()) * 100 - Mage::getSingleton('checkout/session')->getAuthorizedAmount() * 100;
1136
- } else {
1137
- $data['payment'][$i]['AmountInCents'] = $order->getGrandTotal() * 100;
1138
- }
1139
- }
1140
- }
1141
-
1142
- $data['payment'][$i]['TaxDocumentNumber'] = isset($postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i]) ? $postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i] : $taxvat;
1143
- }
1144
-
1145
- if (Mage::helper('mundipagg')->validateCPF($data['payment'][$i]['TaxDocumentNumber'])) {
1146
- $data['PersonTypeEnum'] = 'Person';
1147
- $data['TaxDocumentTypeEnum'] = 'CPF';
1148
- $data['TaxDocumentNumber'] = $data['payment'][$i]['TaxDocumentNumber'];
1149
- }
1150
-
1151
- // We verify if a CNPJ is informed
1152
- if (Mage::helper('mundipagg')->validateCNPJ($data['payment'][$i]['TaxDocumentNumber'])) {
1153
- $data['PersonTypeEnum'] = 'Company';
1154
- $data['TaxDocumentTypeEnum'] = 'CNPJ';
1155
- $data['TaxDocumentNumber'] = $data['payment'][$i]['TaxDocumentNumber'];
1156
- }
1157
- }
1158
- }
1159
-
1160
- // Boleto Payment
1161
- if ($data['payment_method'] == 'mundipagg_boleto') {
1162
- $data['TaxDocumentNumber'] = isset($postData['payment']['boleto_taxvat']) ? $postData['payment']['boleto_taxvat'] : $taxvat;
1163
- $data['boleto_parcelamento'] = isset($postData['payment']['boleto_parcelamento']) ? $postData['payment']['boleto_parcelamento'] : 1;
1164
- $data['boleto_dates'] = isset($postData['payment']['boleto_dates']) ? $postData['payment']['boleto_dates'] : null;
1165
-
1166
- // We verify if a CPF is informed
1167
- if (Mage::helper('mundipagg')->validateCPF($data['TaxDocumentNumber'])) {
1168
- $data['PersonTypeEnum'] = 'Person';
1169
- $data['TaxDocumentTypeEnum'] = 'CPF';
1170
- }
1171
-
1172
- // We verify if a CNPJ is informed
1173
- if (Mage::helper('mundipagg')->validateCNPJ($data['TaxDocumentNumber'])) {
1174
- $data['PersonTypeEnum'] = 'Company';
1175
- $data['TaxDocumentTypeEnum'] = 'CNPJ';
1176
- }
1177
- }
1178
-
1179
- // Debit Payment
1180
- if ($data['payment_method'] == 'mundipagg_debit') {
1181
- $data['TaxDocumentNumber'] = isset($postData['payment']['taxvat']) ? $postData['payment']['taxvat'] : $taxvat;
1182
- $data['Bank'] = isset($postData['payment']['mundipagg_debit']) ? $postData['payment']['mundipagg_debit'] : $mundipaggData['mundipagg_debit'];
1183
-
1184
- // We verify if a CPF is informed
1185
- if (Mage::helper('mundipagg')->validateCPF($data['TaxDocumentNumber'])) {
1186
- $data['PersonTypeEnum'] = 'Person';
1187
- $data['TaxDocumentTypeEnum'] = 'CPF';
1188
- }
1189
-
1190
- // We verify if a CNPJ is informed
1191
- if (Mage::helper('mundipagg')->validateCNPJ($data['TaxDocumentNumber'])) {
1192
- $data['PersonTypeEnum'] = 'Company';
1193
- $data['TaxDocumentTypeEnum'] = 'CNPJ';
1194
- }
1195
- }
1196
-
1197
- // Unset MundipaggData data
1198
- $session->setMundipaggData();
1199
-
1200
- // Api
1201
- $api = Mage::getModel('mundipagg/api');
1202
- $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
1203
-
1204
- // Get approval request from gateway
1205
- switch ($type) {
1206
- case 'mundipagg_boleto':
1207
- $approvalRequest = $api->boletoTransaction($order, $data, $this);
1208
- break;
1209
-
1210
- case 'mundipagg_debit':
1211
- $approvalRequest = $api->debitTransaction($order, $data, $this);
1212
- break;
1213
-
1214
- case $type:
1215
- $approvalRequest = $api->creditCardTransaction($order, $data, $this);
1216
- break;
1217
-
1218
- default:
1219
- $approvalRequest = false;
1220
- }
1221
-
1222
- if ($approvalRequest === false) {
1223
- return false;
1224
- }
1225
-
1226
- // Set some data from Mundipagg
1227
- $payment = $this->setPaymentAdditionalInformation($approvalRequest, $payment);
1228
- $authorizedAmount = $order->getPaymentAuthorizationAmount();
1229
-
1230
- if (is_null($authorizedAmount)) {
1231
- $authorizedAmount = 0;
1232
- }
1233
-
1234
- // Payment gateway error
1235
- if (isset($approvalRequest['error'])) {
1236
-
1237
- if (isset($approvalRequest['ErrorItemCollection'])) {
1238
- $errorItemCollection = $approvalRequest['ErrorItemCollection'];
1239
-
1240
- foreach ($errorItemCollection as $i) {
1241
- $errorCode = $helper->issetOr($i['ErrorCode']);
1242
-
1243
- if ($errorCode == 504) {
1244
- $statusWithError = Uecommerce_Mundipagg_Model_Enum_CreditCardTransactionStatusEnum::WITH_ERROR;
1245
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess($statusWithError);
1246
-
1247
- return $approvalRequest;
1248
- }
1249
- }
1250
- }
1251
-
1252
- if (isset($approvalRequest['ErrorCode']) && $approvalRequest['ErrorCode'] == 'multi') {
1253
- // Partial payment
1254
-
1255
- // We set authorized amount
1256
- $orderGrandTotal = $order->getGrandTotal();
1257
-
1258
- foreach ($approvalRequest['result']->CreditCardTransactionResultCollection->CreditCardTransactionResult as $key => $result) {
1259
- if ($result->Success == true) {
1260
- $authorizedAmount += $result->AuthorizedAmountInCents * 0.01;
1261
- }
1262
- }
1263
-
1264
- // If authorized amount is the same as order grand total we can show success page
1265
- $epsilon = 0.1;
1266
-
1267
- if ($authorizedAmount != 0) {
1268
- if (($orderGrandTotal - $authorizedAmount) <= $epsilon) {
1269
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1270
- Mage::getSingleton('checkout/session')->setAuthorizedAmount();
1271
-
1272
- } else {
1273
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('partial');
1274
- Mage::getSingleton('checkout/session')->setAuthorizedAmount($authorizedAmount);
1275
- }
1276
-
1277
- $order->setPaymentAuthorizationAmount($authorizedAmount);
1278
- $order->save();
1279
-
1280
- } else {
1281
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1282
- }
1283
- } else {
1284
- $result = $helper->issetOr($approvalRequest['result'], false);
1285
-
1286
- if ($result !== false) {
1287
- $helperLog->info("{$logLabel} | Payment not authorized order will be canceled.");
1288
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1289
- }
1290
- }
1291
-
1292
- return $approvalRequest;
1293
- }
1294
-
1295
- switch ($approvalRequest['message']) {
1296
- // BoletoBancario
1297
- case 0:
1298
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1299
- break;
1300
-
1301
- // 1CreditCards
1302
- case 1: // AuthAndCapture
1303
- case 2: // AuthOnly
1304
- case 3: // AuthAndCaptureWithDelay
1305
- // We set authorized amount in session
1306
- $orderGrandTotal = $order->getGrandTotal();
1307
- $result = $helper->issetOr($approvalRequest['result']);
1308
- $orderResult = $helper->issetOr($result['OrderResult']);
1309
- $creditCardTransactionResultCollection = $result['CreditCardTransactionResultCollection'];
1310
- $transactionsQty = count($creditCardTransactionResultCollection);
1311
-
1312
- if ($transactionsQty == 1) {
1313
- $transaction = $creditCardTransactionResultCollection[0];
1314
- $success = $transaction['Success'];
1315
-
1316
- if ($success === true) {
1317
- $authorizedAmount += $transaction['AuthorizedAmountInCents'] * 0.01;
1318
- }
1319
- } else {
1320
- foreach ($creditCardTransactionResultCollection as $key => $transaction) {
1321
- $success = $transaction['Success'];
1322
-
1323
- if ($success === true) {
1324
- $authorizedAmount += $transaction['AuthorizedAmountInCents'] * 0.01;
1325
- }else{
1326
- $unauthorizedCreditCardMaskedNumber = $transaction['MaskedCreditCardNumber'];
1327
- }
1328
- }
1329
- }
1330
-
1331
- // If authorized amount is the same as order grand total we can show success page
1332
- $epsilon = 0.1;
1333
-
1334
- if (($orderGrandTotal - $authorizedAmount) <= $epsilon) {
1335
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1336
- Mage::getSingleton('checkout/session')->setAuthorizedAmount();
1337
-
1338
- if ($orderGrandTotal < $authorizedAmount) {
1339
- $interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information');
1340
- $newInterestInformation = array();
1341
- $newInterest = 0;
1342
-
1343
- if (count($interestInformation)) {
1344
- foreach ($interestInformation as $key => $ii) {
1345
- if (strpos($key, 'partial') !== false) {
1346
- if ($ii->hasValue()) {
1347
- $newInterest += (float)($ii->getInterest());
1348
- }
1349
- }
1350
-
1351
- }
1352
- }
1353
- $this->addInterestToOrder($order, $newInterest);
1354
- }
1355
-
1356
- } else {
1357
- if ($authorizedAmount != 0) {
1358
- if (($orderGrandTotal - $authorizedAmount) >= $epsilon) {
1359
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('partial');
1360
- Mage::getSingleton('checkout/session')->setAuthorizedAmount($authorizedAmount);
1361
-
1362
- $interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information');
1363
- $unauthorizedAmount = (float)($orderGrandTotal - $authorizedAmount);
1364
- $newInterestInformation = array();
1365
-
1366
- if (count($interestInformation)) {
1367
- foreach ($interestInformation as $key => $ii) {
1368
-
1369
- if ($ii->hasValue()) {
1370
- if ((float)($ii->getValue() + $ii->getInterest()) == (float)trim($unauthorizedAmount)) {
1371
- $this->removeInterestToOrder($order, $ii->getInterest());
1372
- } else {
1373
- $newInterestInformation[$key] = $ii;
1374
- }
1375
- } else {
1376
- if (($order->getGrandTotal() + $order->getMundipaggInterest()) == $unauthorizedAmount) {
1377
- $this->removeInterestToOrder($order, $ii->getInterest());
1378
- } else {
1379
- $newInterestInformation[$key] = $ii;
1380
- }
1381
- }
1382
- }
1383
-
1384
- $payment->setAdditionalInformation('mundipagg_interest_information', $newInterestInformation);
1385
- }
1386
- }
1387
- } else {
1388
- $result = $helper->issetOr($approvalRequest['result'], false);
1389
-
1390
- if ($result !== false) {
1391
- $helperLog->info("{$logLabel} | Payment not authorized order will be canceled.");
1392
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1393
- }
1394
- }
1395
- }
1396
-
1397
- $transactionKey = $transaction['TransactionKey'];
1398
- $creditCardTransactionStatusEnum = $transaction['CreditCardTransactionStatus'];
1399
-
1400
- try {
1401
- if ($transactionKey != null) {
1402
- $this->_transactionId = $transactionKey;
1403
-
1404
- $payment->setTransactionId($this->_transactionId);
1405
- $payment->save();
1406
- }
1407
- } catch (Exception $e) {
1408
- $helperLog->error($e->getMessage());
1409
- continue;
1410
- }
1411
- break;
1412
-
1413
- // Debit
1414
- case 4:
1415
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('debit');
1416
- Mage::getSingleton('checkout/session')->setBankRedirectUrl($approvalRequest['result']['BankRedirectUrl']);
1417
- break;
1418
- }
1419
-
1420
- $orderResult = $helper->issetOr($result['OrderResult']);
1421
-
1422
- if (isset($orderResult)) {
1423
- $newOrderKey = $orderResult['OrderKey'];
1424
- $orderPayment = $order->getPayment();
1425
- $orderKeys = (array)$orderPayment->getAdditionalInformation('OrderKey');
1426
-
1427
- if (is_null($orderKeys) || !is_array($orderKeys)) {
1428
- $orderKeys = [];
1429
- }
1430
-
1431
- if (!in_array($newOrderKey, $orderKeys)) {
1432
- $orderKeys[] = $newOrderKey;
1433
- }
1434
-
1435
- $orderPayment->setAdditionalInformation('OrderKey', $orderKeys);
1436
- $orderPayment->save();
1437
- }
1438
-
1439
- $order->setPaymentAuthorizationAmount($authorizedAmount);
1440
- $order->save();
1441
-
1442
- if ($authorizedAmount == $order->getGrandTotal()) {
1443
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1444
- }
1445
-
1446
- return $approvalRequest;
1447
-
1448
- } catch (Exception $e) {
1449
- //Api
1450
- $api = Mage::getModel('mundipagg/api');
1451
-
1452
- //Log error
1453
- Mage::logException($e);
1454
-
1455
- //Mail error
1456
- $api->mailError(print_r($e->getMessage(), 1));
1457
- }
1458
- }
1459
-
1460
- /**
1461
- * @param array $approvalRequest
1462
- * @param $payment
1463
- * @return mixed
1464
- */
1465
- private function setPaymentAdditionalInformation($approvalRequest, $payment) {
1466
- if (isset($approvalRequest['ErrorCode'])) {
1467
- $payment->setAdditionalInformation('ErrorCode', $approvalRequest['ErrorCode']);
1468
- }
1469
-
1470
- if (isset($approvalRequest['ErrorDescription'])) {
1471
- $payment->setAdditionalInformation('ErrorDescription', $approvalRequest['ErrorDescription']);
1472
- }
1473
-
1474
- if (isset($approvalRequest['OrderKey'])) {
1475
- $payment->setAdditionalInformation('OrderKey', $approvalRequest['OrderKey']);
1476
- }
1477
-
1478
- if (isset($approvalRequest['OrderReference'])) {
1479
- $payment->setAdditionalInformation('OrderReference', $approvalRequest['OrderReference']);
1480
- }
1481
-
1482
- if (isset($approvalRequest['CreateDate'])) {
1483
- $payment->setAdditionalInformation('CreateDate', $approvalRequest['CreateDate']);
1484
- }
1485
-
1486
- if (isset($approvalRequest['OrderStatusEnum'])) {
1487
- $payment->setAdditionalInformation('OrderStatusEnum', $approvalRequest['OrderStatusEnum']);
1488
- }
1489
-
1490
- if (isset($approvalRequest['TransactionKey'])) {
1491
- $payment->setAdditionalInformation('TransactionKey', $approvalRequest['TransactionKey']);
1492
- }
1493
-
1494
- if (isset($approvalRequest['OnlineDebitStatus'])) {
1495
- $payment->setAdditionalInformation('OnlineDebitStatus', $approvalRequest['OnlineDebitStatus']);
1496
- }
1497
-
1498
- if (isset($approvalRequest['TransactionKeyToBank'])) {
1499
- $payment->setAdditionalInformation('TransactionKeyToBank', $approvalRequest['TransactionKeyToBank']);
1500
- }
1501
-
1502
- if (isset($approvalRequest['TransactionReference'])) {
1503
- $payment->setAdditionalInformation('TransactionReference', $approvalRequest['TransactionReference']);
1504
- }
1505
-
1506
- if (array_key_exists('isRecurrency', $approvalRequest)) {
1507
- $payment->setAdditionalInformation('isRecurrency', $approvalRequest['isRecurrency']);
1508
- }
1509
-
1510
- return $payment;
1511
- }
1512
-
1513
- /**
1514
- * Set capture transaction ID and enable Void to invoice for informational purposes
1515
- * @param Mage_Sales_Model_Order_Invoice $invoice
1516
- * @param Mage_Sales_Model_Order_Payment $payment
1517
- * @return Mage_Payment_Model_Method_Abstract
1518
- */
1519
- public function processInvoice($invoice, $payment) {
1520
- if ($payment->getLastTransId()) {
1521
- $invoice->setTransactionId($payment->getLastTransId());
1522
- $invoice->setCanVoidFlag(true);
1523
-
1524
- if (Mage::helper('sales')->canSendNewInvoiceEmail($payment->getOrder()->getStoreId())) {
1525
- $invoice->setEmailSent(true);
1526
- $invoice->sendEmail();
1527
- }
1528
-
1529
- return $this;
1530
- }
1531
-
1532
- return false;
1533
- }
1534
-
1535
- /**
1536
- * Check void availability
1537
- *
1538
- * @return bool
1539
- */
1540
- public function canVoid(Varien_Object $payment) {
1541
- if ($payment instanceof Mage_Sales_Model_Order_Creditmemo) {
1542
- return false;
1543
- }
1544
-
1545
- return $this->_canVoid;
1546
- }
1547
-
1548
- public function void(Varien_Object $payment) {
1549
- if (!$this->canVoid($payment)) {
1550
- Mage::throwException(Mage::helper('payment')->__('Void action is not available.'));
1551
- }
1552
-
1553
- //Prepare data in order to void
1554
- if ($payment->getAdditionalInformation('OrderKey')) {
1555
- $transactions = Mage::getModel('sales/order_payment_transaction')
1556
- ->getCollection()
1557
- ->addAttributeToFilter('order_id', array('eq' => $payment->getOrder()->getEntityId()));
1558
-
1559
- foreach ($transactions as $key => $transaction) {
1560
- $TransactionKey = $transaction->getAdditionalInformation('TransactionKey');
1561
- $TransactionReference = $transaction->getAdditionalInformation('TransactionReference');
1562
- }
1563
-
1564
- $orderkeys = $payment->getAdditionalInformation('OrderKey');
1565
-
1566
- if (!is_array($orderkeys)) {
1567
- $orderkeys = array($orderkeys);
1568
- }
1569
-
1570
- foreach ($orderkeys as $orderkey) {
1571
- $data['ManageOrderOperationEnum'] = 'Cancel';
1572
- $data['OrderKey'] = $orderkey;
1573
-
1574
- //Call Gateway Api
1575
- $api = Mage::getModel('mundipagg/api');
1576
-
1577
- $void = $api->manageOrderRequest($data, $this);
1578
-
1579
- // Xml
1580
- $xml = $void['result'];
1581
- $json = json_encode($xml);
1582
-
1583
- $void['result'] = array();
1584
- $void['result'] = json_decode($json, true);
1585
-
1586
- // We record transaction(s)
1587
- if (count($void['result']['CreditCardTransactionResultCollection']) > 0) {
1588
- if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
1589
- $trans = $void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
1590
-
1591
- $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans);
1592
- } else {
1593
- foreach ($void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'] as $key => $trans) {
1594
- $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans, $key);
1595
- }
1596
- }
1597
- }
1598
-
1599
- if (isset($void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'])) {
1600
- $order = $payment->getOrder();
1601
- $order->setBaseDiscountRefunded($order->getBaseDiscountInvoiced());
1602
- $order->setBaseShippingRefunded($order->getBaseShippingAmount());
1603
- $order->setBaseShippingTaxRefunded($order->getBaseShippingTaxInvoiced());
1604
- $order->setBaseSubtotalRefunded($order->getBaseSubtotalInvoiced());
1605
- $order->setBaseTaxRefunded($order->getBaseTaxInvoiced());
1606
- $order->setBaseTotalOnlineRefunded($order->getBaseGrandTotal());
1607
- $order->setDiscountRefunded($order->getDiscountInvoiced());
1608
- $order->setShippinRefunded($order->getShippingInvoiced());
1609
- $order->setShippinTaxRefunded($order->getShippingTaxAmount());
1610
- $order->setSubtotalRefunded($order->getSubtotalInvoiced());
1611
- $order->setTaxRefunded($order->getTaxInvoiced());
1612
- $order->setTotalOnlineRefunded($order->getBaseGrandTotal());
1613
- $order->setTotalRefunded($order->getBaseGrandTotal());
1614
- $order->save();
1615
-
1616
- return $this;
1617
- } else {
1618
- $error = Mage::helper('mundipagg')->__('Unable to void order.');
1619
-
1620
- //Log error
1621
- Mage::log($error, null, 'Uecommerce_Mundipagg.log');
1622
-
1623
- Mage::throwException($error);
1624
- }
1625
- }
1626
- } else {
1627
- Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
1628
- }
1629
- }
1630
-
1631
- /**
1632
- * Check refund availability
1633
- *
1634
- * @return bool
1635
- */
1636
- public function canRefund() {
1637
- return $this->_canRefund;
1638
- }
1639
-
1640
- /**
1641
- * Set refund transaction id to payment object for informational purposes
1642
- * Candidate to be deprecated:
1643
- * there can be multiple refunds per payment, thus payment.refund_transactionId doesn't make big sense
1644
- *
1645
- * @param Mage_Sales_Model_Order_Invoice $invoice
1646
- * @param Mage_Sales_Model_Order_Payment $payment
1647
- * @return Mage_Payment_Model_Method_Abstract
1648
- */
1649
- public function processBeforeRefund($invoice, $payment) {
1650
- $payment->setRefundTransactionId($invoice->getTransactionId());
1651
-
1652
- return $this;
1653
- }
1654
-
1655
- /**
1656
- * Refund specified amount for payment
1657
- *
1658
- * @param Varien_Object $payment
1659
- * @param float $amount
1660
- *
1661
- * @return Mage_Payment_Model_Abstract
1662
- */
1663
- public function refund(Varien_Object $payment, $amount) {
1664
- if (!$this->canRefund()) {
1665
- Mage::throwException(Mage::helper('payment')->__('Refund action is not available.'));
1666
- }
1667
-
1668
- //Prepare data in order to refund
1669
- if ($payment->getAdditionalInformation('OrderKey')) {
1670
- $data['OrderKey'] = $payment->getAdditionalInformation('OrderKey');
1671
- $data['ManageOrderOperationEnum'] = 'Void';
1672
-
1673
- //Call Gateway Api
1674
- $api = Mage::getModel('mundipagg/api');
1675
-
1676
- $refund = $api->manageOrderRequest($data, $this);
1677
-
1678
- // Xml
1679
- $xml = $refund['result'];
1680
- $json = json_encode($xml);
1681
-
1682
- $refund['result'] = array();
1683
- $refund['result'] = json_decode($json, true);
1684
-
1685
- // We record transaction(s)
1686
- if (count($refund['result']['CreditCardTransactionResultCollection']) > 0) {
1687
- if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
1688
- $trans = $refund['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
1689
-
1690
- $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans);
1691
- } else {
1692
- foreach ($refund['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'] as $key => $trans) {
1693
- $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans, $key);
1694
- }
1695
- }
1696
- }
1697
-
1698
- if (isset($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult)) {
1699
- if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
1700
- $capturedAmountInCents = $manageOrderResult->CreditCardTransactionResultCollection->CreditCardTransactionResult->CapturedAmountInCents;
1701
- } else {
1702
- $capturedAmountInCents = 0;
1703
-
1704
- foreach ($refund['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'] as $key => $trans) {
1705
- $capturedAmountInCents += $trans['CapturedAmountInCents'];
1706
- }
1707
- }
1708
-
1709
- $order = $payment->getOrder();
1710
- $order->setBaseDiscountRefunded($order->getBaseDiscountInvoiced());
1711
- $order->setBaseShippingRefunded($order->getBaseShippingAmount());
1712
- $order->setBaseShippingTaxRefunded($order->getBaseShippingTaxInvoiced());
1713
- $order->setBaseSubtotalRefunded($order->getBaseSubtotalInvoiced());
1714
- $order->setBaseTaxRefunded($order->getBaseTaxInvoiced());
1715
- $order->setBaseTotalOnlineRefunded($capturedAmountInCents * 0.01);
1716
- $order->setDiscountRefunded($order->getDiscountInvoiced());
1717
- $order->setShippinRefunded($order->getShippingInvoiced());
1718
- $order->setShippinTaxRefunded($order->getShippingTaxAmount());
1719
- $order->setSubtotalRefunded($order->getSubtotalInvoiced());
1720
- $order->setTaxRefunded($order->getTaxInvoiced());
1721
- $order->setTotalOnlineRefunded($capturedAmountInCents * 0.01);
1722
- $order->setTotalRefunded($capturedAmountInCents * 0.01);
1723
- $order->save();
1724
-
1725
- return $this;
1726
- } else {
1727
- $error = Mage::helper('mundipagg')->__('Unable to refund order.');
1728
-
1729
- //Log error
1730
- Mage::log($error, null, 'Uecommerce_Mundipagg.log');
1731
-
1732
- Mage::throwException($error);
1733
- }
1734
- } else {
1735
- Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
1736
- }
1737
- }
1738
-
1739
- /**
1740
- * Validate
1741
- */
1742
- public function validate() {
1743
- parent::validate();
1744
-
1745
- $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
1746
-
1747
- if (!in_array($currencyCode, $this->_allowCurrencyCode)) {
1748
- Mage::throwException(Mage::helper('payment')->__('Selected currency code (' . $currencyCode . ') is not compatabile with Mundipagg'));
1749
- }
1750
-
1751
- $info = $this->getInfoInstance();
1752
-
1753
- $errorMsg = array();
1754
-
1755
- // Check if we are dealing with a new Credit Card
1756
- $isToken = $info->getAdditionalInformation('mundipagg_creditcard_token_1_1');
1757
-
1758
- if ($info->getAdditionalInformation('PaymentMethod') == 'mundipagg_creditcard' && ($isToken == '' || $isToken == 'new')) {
1759
- $availableTypes = $this->getCcTypes();
1760
-
1761
- $ccNumber = $info->getCcNumber();
1762
-
1763
- // refresh quote to remove promotions from others payment methods
1764
- try {
1765
- $this->getQuote()->save();
1766
-
1767
- } catch (Exception $e) {
1768
- $errorMsg[] = $e->getMessage();
1769
-
1770
- }
1771
-
1772
- // remove credit card number delimiters such as "-" and space
1773
- $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
1774
- $info->setCcNumber($ccNumber);
1775
-
1776
- if (in_array($info->getCcType(), $availableTypes)) {
1777
- if (!Mage::helper('mundipagg')->validateCcNum($ccNumber) && $info->getCcType() != 'HI') {
1778
- $errorMsg[] = Mage::helper('payment')->__('Invalid Credit Card Number');
1779
- }
1780
- } else {
1781
- $errorMsg[] = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
1782
- }
1783
-
1784
- if (!$info->getCcType()) {
1785
- $errorMsg[] = Mage::helper('payment')->__('Please select your credit card type.');
1786
- }
1787
-
1788
- if (!$info->getCcOwner()) {
1789
- $errorMsg[] = Mage::helper('payment')->__('Please enter your credit card holder name.');
1790
- }
1791
-
1792
- if ($info->getCcType() && $info->getCcType() != 'SS' && !Mage::helper('mundipagg')->validateExpDate('20' . $info->getCcExpYear(), $info->getCcExpMonth())) {
1793
- $errorMsg[] = Mage::helper('payment')->__('Incorrect credit card expiration date.');
1794
- }
1795
- }
1796
-
1797
- if ($errorMsg) {
1798
- $json = json_encode($errorMsg);
1799
- Mage::throwException($json);
1800
- }
1801
-
1802
- return $this;
1803
- }
1804
-
1805
- /**
1806
- * Redirect Url
1807
- *
1808
- * @return void
1809
- */
1810
- public function getOrderPlaceRedirectUrl() {
1811
- $statusWithError = Uecommerce_Mundipagg_Model_Enum_CreditCardTransactionStatusEnum::WITH_ERROR;
1812
-
1813
- switch (Mage::getSingleton('checkout/session')->getApprovalRequestSuccess()) {
1814
- case 'debit':
1815
- $redirectUrl = Mage::getSingleton('checkout/session')->getBankRedirectUrl();
1816
- break;
1817
-
1818
- case 'success':
1819
- $redirectUrl = Mage::getUrl('mundipagg/standard/success', array('_secure' => true));
1820
- break;
1821
-
1822
- case $statusWithError:
1823
- $redirectUrl = Mage::getUrl('mundipagg/standard/success', array('_secure' => true));
1824
- break;
1825
-
1826
- case 'partial':
1827
- $redirectUrl = Mage::getUrl('mundipagg/standard/partial', array('_secure' => true));
1828
- break;
1829
-
1830
- case 'cancel':
1831
- $redirectUrl = Mage::getUrl('mundipagg/standard/cancel', array('_secure' => true));
1832
- break;
1833
-
1834
- default:
1835
- $redirectUrl = Mage::getUrl('mundipagg/standard/cancel', array('_secure' => true));
1836
- break;
1837
- }
1838
-
1839
- return $redirectUrl;
1840
- }
1841
-
1842
- public function prepare() {
1843
-
1844
- }
1845
-
1846
- /**
1847
- * Get payment methods
1848
- */
1849
- public function getPaymentMethods() {
1850
- $payment_methods = $this->getConfigData('payment_methods');
1851
-
1852
- if ($payment_methods != '') {
1853
- $payment_methods = explode(",", $payment_methods);
1854
- } else {
1855
- $payment_methods = array();
1856
- }
1857
-
1858
- return $payment_methods;
1859
- }
1860
-
1861
- /**
1862
- * CCards
1863
- */
1864
- public function getCcTypes() {
1865
- $ccTypes = Mage::getStoreConfig('payment/mundipagg_standard/cc_types');
1866
-
1867
- if ($ccTypes != '') {
1868
- $ccTypes = explode(",", $ccTypes);
1869
- } else {
1870
- $ccTypes = array();
1871
- }
1872
-
1873
- return $ccTypes;
1874
- }
1875
-
1876
- /**
1877
- * Reset interest
1878
- */
1879
- public function resetInterest($info) {
1880
- if ($info->getQuote()->getMundipaggInterest() > 0 || $info->getQuote()->getMundipaggBaseInterest() > 0) {
1881
- $info->getQuote()->setMundipaggInterest(0.0);
1882
- $info->getQuote()->setMundipaggBaseInterest(0.0);
1883
- $info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
1884
- $info->getQuote()->save();
1885
- }
1886
-
1887
- return $info;
1888
- }
1889
-
1890
- /**
1891
- * Apply interest
1892
- */
1893
- public function applyInterest($info, $interest) {
1894
- $info->getQuote()->setMundipaggInterest($info->getQuote()->getStore()->convertPrice($interest, false));
1895
- $info->getQuote()->setMundipaggBaseInterest($interest);
1896
- $info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
1897
- $info->getQuote()->save();
1898
- }
1899
-
1900
- /**
1901
- * Remove interest to order when the total is not allowed.
1902
- *
1903
- * @param Mage_Sales_Model_Order $order
1904
- * @param float $interest
1905
- */
1906
- protected function removeInterestToOrder(Mage_Sales_Model_Order $order, $interest) {
1907
- $mundipaggInterest = $order->getMundipaggInterest();
1908
- $setInterest = (float)($mundipaggInterest - $interest);
1909
- $order->setMundipaggInterest(($setInterest) ? $setInterest : 0);
1910
- $order->setMundipaggBaseInterest(($setInterest) ? $setInterest : 0);
1911
- $order->setGrandTotal(($order->getGrandTotal() - $interest));
1912
- $order->setBaseGrandTotal(($order->getBaseGrandTotal() - $interest));
1913
- $order->save();
1914
- $info = $this->getInfoInstance();
1915
- $info->setPaymentInterest(($info->getPaymentInterest() - $setInterest));
1916
- $info->save();
1917
-
1918
- }
1919
-
1920
- /**
1921
- * Add interest to order
1922
- */
1923
- protected function addInterestToOrder(Mage_Sales_Model_Order $order, $interest) {
1924
- $mundipaggInterest = $order->getMundipaggInterest();
1925
- $setInterest = (float)($mundipaggInterest + $interest);
1926
- $order->setMundipaggInterest(($setInterest) ? $setInterest : 0);
1927
- $order->setMundipaggBaseInterest(($setInterest) ? $setInterest : 0);
1928
- $order->setGrandTotal(($order->getGrandTotal() + $interest));
1929
- $order->setBaseGrandTotal(($order->getBaseGrandTotal() + $interest));
1930
- $order->save();
1931
- }
1932
-
1933
- /**
1934
- * Add payment transaction
1935
- *
1936
- * @param Mage_Sales_Model_Order_Payment $payment
1937
- * @param string $transactionId
1938
- * @param string $transactionType
1939
- * @param array $transactionAdditionalInfo
1940
- * @return null|Mage_Sales_Model_Order_Payment_Transaction
1941
- */
1942
- public function _addTransaction(Mage_Sales_Model_Order_Payment $payment, $transactionId, $transactionType, $transactionAdditionalInfo, $num = 0) {
1943
- // Num
1944
- $num = $num + 1;
1945
-
1946
- // Transaction
1947
- $transaction = Mage::getModel('sales/order_payment_transaction');
1948
- $transaction->setOrderPaymentObject($payment);
1949
-
1950
- $transaction = $transaction->loadByTxnId($transactionId . '-' . $transactionType);
1951
-
1952
- $transaction->setTxnType($transactionType);
1953
- $transaction->setTxnId($transactionId . '-' . $transactionType);
1954
-
1955
- if ($transactionType == 'authorization') {
1956
- $ccTransactionStatus = $transactionAdditionalInfo['CreditCardTransactionStatus'];
1957
- $transactionOpenStatuses = array(
1958
- 'AuthorizedPendingCapture',
1959
- 'Captured',
1960
- 'PartialCapture',
1961
- 'WithError',
1962
- 'PendingAuthorize'
1963
- );
1964
-
1965
- $order = $payment->getOrder();
1966
- $orderIncrementId = $order->getIncrementId();
1967
-
1968
- $api = new Uecommerce_Mundipagg_Model_Api();
1969
- $orderInOfflineRetry = $api->orderIsInOfflineRetry($orderIncrementId);
1970
-
1971
- if (in_array($ccTransactionStatus, $transactionOpenStatuses)) {
1972
- $transaction->setIsClosed(0);
1973
- } else {
1974
- $transaction->setIsClosed(1);
1975
- }
1976
- }
1977
-
1978
- foreach ($transactionAdditionalInfo as $transKey => $value) {
1979
- if (!is_array($value)) {
1980
- $transaction->setAdditionalInformation($transKey, htmlspecialchars_decode($value));
1981
- $payment->setAdditionalInformation($num . '_' . $transKey, htmlspecialchars_decode($value));
1982
-
1983
- } else {
1984
-
1985
- if (empty($value)) {
1986
- $transaction->setAdditionalInformation($transKey, '');
1987
- $payment->setAdditionalInformation($num . '_' . $transKey, '');
1988
-
1989
- } else {
1990
- foreach ($value as $key2 => $value2) {
1991
- $transaction->setAdditionalInformation($key2, htmlspecialchars_decode($value2));
1992
- $payment->setAdditionalInformation($num . '_' . $key2, htmlspecialchars_decode($value2));
1993
- }
1994
- }
1995
- }
1996
- }
1997
-
1998
- return $transaction->save();
1999
- }
2000
-
2001
- /**
2002
- * Cancel order or not if is in offline retry time
2003
- *
2004
- * @author Ruan Azevedo <razevedo@mundipagg.com>
2005
- * @since 2016-06-21
2006
- * @param string $orderIncrementId
2007
- */
2008
- private function offlineRetryCancelOrSuccessOrder($orderIncrementId) {
2009
- $offlineRetryIsEnabled = Uecommerce_Mundipagg_Model_Offlineretry::offlineRetryIsEnabled();
2010
- $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
2011
- $logLabel = "Order #{$orderIncrementId}";
2012
-
2013
- if ($offlineRetryIsEnabled) {
2014
- $api = new Uecommerce_Mundipagg_Model_Api();
2015
- $message = "{$logLabel} | payment not authorized but order is in offline retry yet, not cancel.";
2016
- $helperLog->info($message);
2017
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
2018
-
2019
- }else{
2020
- $helperLog->info("{$logLabel} | Payment not authorized and store don't have offline retry, order will be canceled.");
2021
- Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
2022
- return;
2023
- }
2024
- }
2025
-
2026
- /**
2027
- * @param Mage_Sales_Model_Order $order
2028
- * @throws Exception
2029
- */
2030
- public static function transactionWithError(Mage_Sales_Model_Order $order, $comment = true) {
2031
- try {
2032
- if ($comment) {
2033
- $order->setState(
2034
- 'pending',
2035
- 'mundipagg_with_error',
2036
- 'With Error',
2037
- false
2038
- );
2039
- } else {
2040
- $order->setStatus('mundipagg_with_error');
2041
- }
2042
-
2043
- $order->save();
2044
-
2045
- } catch (Exception $e) {
2046
- $errMsg = "Unable to modify order status to 'mundipagg_with_error: {$e->getMessage()}";
2047
-
2048
- throw new Exception($errMsg);
2049
- }
2050
- }
2051
-
2052
- /**
2053
- * @param Mage_Sales_Model_Order_Payment $payment
2054
- * @param $resultPayment
2055
- * @return $this
2056
- */
2057
- private function paymentError(Mage_Sales_Model_Order_Payment $payment, $resultPayment) {
2058
- try {
2059
- $transactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER;
2060
- $helper = Mage::helper('mundipagg');
2061
- $result = $helper->issetOr($resultPayment['result']);
2062
- $ccTxnCollection = $helper->issetOr($result['CreditCardTransactionResultCollection']);
2063
-
2064
- // We record transaction(s)
2065
- if (is_null($ccTxnCollection) === false) {
2066
- if (count($ccTxnCollection) == 1) {
2067
- $trans = $ccTxnCollection[0];
2068
-
2069
- $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans);
2070
- } else {
2071
- foreach ($ccTxnCollection as $key => $trans) {
2072
- $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans, $key);
2073
- }
2074
- }
2075
- }
2076
-
2077
- if (isset($resultPayment['ErrorItemCollection'])) {
2078
- if (count($resultPayment['ErrorItemCollection']) == 1) {
2079
- foreach ($resultPayment['ErrorItemCollection']['ErrorItem'] as $key => $value) {
2080
- $payment->setAdditionalInformation($key, $value)->save();
2081
- }
2082
- } else {
2083
- foreach ($resultPayment['ErrorItemCollection'] as $key1 => $error) {
2084
- foreach ($error as $key2 => $value) {
2085
- $payment->setAdditionalInformation($key1 . '_' . $key2, $value)->save();
2086
- }
2087
- }
2088
- }
2089
- }
2090
-
2091
- $payment->setSkipOrderProcessing(true)->save();
2092
-
2093
- if (isset($resultPayment['ErrorDescription'])) {
2094
- Mage::throwException(Mage::helper('mundipagg')->__($resultPayment['ErrorDescription']));
2095
-
2096
- } else {
2097
- Mage::throwException(Mage::helper('mundipagg')->__('Error'));
2098
- }
2099
-
2100
- } catch (Exception $e) {
2101
- return $this;
2102
- }
2103
- }
2104
-
2105
- private function integrationTimeOut(Mage_Sales_Model_Order $order, Mage_Sales_Model_Order_Payment &$payment) {
2106
- $payment->setSkipOrderProcessing(true);
2107
- $payment->setAdditionalInformation('IntegrationError', Uecommerce_Mundipagg_Model_Api::INTEGRATION_TIMEOUT);
2108
-
2109
- $comment = Uecommerce_Mundipagg_Model_Api::INTEGRATION_TIMEOUT;
2110
- $order->addStatusHistoryComment($comment);
2111
- $order->save();
2112
-
2113
- $session = Mage::getSingleton('checkout/session');
2114
- $session->setApprovalRequestSuccess('success');
2115
-
2116
- return $this;
2117
- }
2118
-
2119
- /**
2120
- * @param array $mundiQueryResult
2121
- * @param Mage_Sales_Model_Order_Payment $payment
2122
- * @return bool|null
2123
- */
2124
- public function processQueryResults($mundiQueryResult, Mage_Sales_Model_Order_Payment $payment) {
2125
- $helper = Mage::helper('mundipagg');
2126
- $log = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
2127
-
2128
- $order = $payment->getOrder();
2129
- $log->setLogLabel("#{$order->getIncrementId()}");
2130
-
2131
- $saleDataCollection = $helper->issetOr($mundiQueryResult['SaleDataCollection']);
2132
-
2133
- if (is_null($saleDataCollection)) {
2134
- $log->info("SaleDataCollection is null. Method execution is over");
2135
-
2136
- return false;
2137
- }
2138
-
2139
- $saleData = null;
2140
- $dateFormat = 'Y-m-d';
2141
-
2142
- foreach ($saleDataCollection as $i) {
2143
- $createDate = $i['OrderData']['CreateDate'];
2144
- $transactionCreateDate = new DateTime($createDate);
2145
- $orderCreateDate = new DateTime($order->getCreatedAt());
2146
-
2147
- $formatTransDate = $transactionCreateDate->format($dateFormat);
2148
- $formatOrderDate = $orderCreateDate->format($dateFormat);
2149
-
2150
- if ($formatTransDate == $formatOrderDate) {
2151
- $saleData = $i;
2152
- continue;
2153
- }
2154
- }
2155
-
2156
- $creditCardTransactionDataCollection = $helper->issetOr(
2157
- $saleData['CreditCardTransactionDataCollection']
2158
- );
2159
-
2160
- if (is_null($creditCardTransactionDataCollection)) {
2161
- $log->info("CreditCardTransactionDataCollection is null. Method execution is over");
2162
-
2163
- return false;
2164
- }
2165
-
2166
- $transactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH;
2167
-
2168
- foreach ($creditCardTransactionDataCollection as $i) {
2169
- $transactionId = $i['TransactionKey'];
2170
- $this->_addTransaction($payment, $transactionId, $transactionType, $i);
2171
- }
2172
-
2173
- return true;
2174
- }
2175
-
2176
- public function removeIntegrationErrorInfo(Mage_Sales_Model_Order $order) {
2177
- $errMsg = null;
2178
- $log = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
2179
- $log->setLogLabel("#{$order->getIncrementId()}");
2180
-
2181
- $info = $order->getPayment()->getAdditionalInformation();
2182
-
2183
- if (!isset($info['IntegrationError'])) {
2184
- return;
2185
- }
2186
-
2187
- try {
2188
- $info = $order->getPayment()->getAdditionalInformation();
2189
 
2190
- unset($info['IntegrationError']);
2191
-
2192
- $order->getPayment()
2193
- ->setAdditionalInformation($info)
2194
- ->save();
2195
-
2196
- $log->info("IntegrationError message removed");
2197
-
2198
- } catch (Exception $e) {
2199
- $log->error($e, true);
2200
- }
2201
- }
2202
-
2203
- /**
2204
- * @param Mage_Sales_Model_Order $order
2205
- * @param boolean $option
2206
- */
2207
- public function setCanceledByNotificationFlag(&$order, $option) {
2208
- $order->getPayment()->setAdditionalInformation('voided_by_mundi_notification', $option);
2209
- }
2210
-
2211
- /**
2212
- * @param Mage_Sales_Model_Order $order
2213
- */
2214
- public function getCanceledByNotificationFlag($order) {
2215
- return $order->getPayment()->getAdditionalInformation('voided_by_mundi_notification');
2216
- }
2217
-
2218
- /**
2219
- * Equalize invoice base_grand_total and base_total with order totals
2220
- * Needed when order has 1 invoice and has credit card interests
2221
- *
2222
- * @param Mage_Sales_Model_Order_Invoice $invoice
2223
- */
2224
- public function equalizeInvoiceTotals(Mage_Sales_Model_Order_Invoice &$invoice) {
2225
- $invoice->setBaseGrandTotal($invoice->getOrder()->getBaseGrandTotal())
2226
- ->setGrandTotal($invoice->getOrder()->getGrandTotal())
2227
- ->save();
2228
- }
2229
 
2230
- /**
2231
- * @param Mage_Checkout_Model_Type_Onepage $onepage
2232
- * @param array $postData
2233
- * @return null|string $redirectRoute
2234
- * @throws Exception
2235
- */
2236
- public function retryAuthorization(Mage_Checkout_Model_Type_Onepage &$onepage, $postData) {
2237
- $redirectRoute = null;
2238
-
2239
- /* @var Uecommerce_Mundipagg_Helper_CheckoutSession $session */
2240
- $session = Mage::helper('mundipagg/checkoutSession');
2241
- $lastQuoteId = $session->getInstance()->getLastSuccessQuoteId();
2242
- $session->getInstance()->setQuoteId($lastQuoteId);
2243
-
2244
- /* @var Mage_Sales_Model_Quote $quote */
2245
- $quote = Mage::getModel('sales/quote')->load($lastQuoteId);
2246
- $quote->setIsActive(true);
2247
-
2248
- $onepage->setQuote($quote);
2249
-
2250
- // Get Reserved Order Id
2251
- $reservedOrderId = $quote->getReservedOrderId();
2252
-
2253
- if ($reservedOrderId == false) {
2254
- return $redirectRoute;
2255
- }
2256
-
2257
- $session->setApprovalRequest('partial');
2258
-
2259
- $order = Mage::getModel('sales/order')->loadByIncrementId($reservedOrderId);
2260
-
2261
- //
2262
- $additionalInfo = $order->getPayment()->getAdditionalInformation();
2263
- $num = 1;
2264
-
2265
- if ($additionalInfo['2_Success']) {
2266
- $num++;
2267
- }
2268
-
2269
- $idxToken = "mundipagg_twocreditcards_token_2_{$num}";
2270
-
2271
- switch (true) {
2272
- case isset($additionalInfo[$idxToken]) :
2273
- $order->getPayment()->setAdditionalInformation();
2274
- break;
2275
- }
2276
-
2277
- /* @var Uecommerce_Mundipagg_Helper_Data $helper */
2278
- $helper = Mage::helper('mundipagg');
2279
-
2280
- if ($order->getStatus() === 'pending' || $order->getStatus() === 'payment_review') {
2281
- if (empty($postData)) {
2282
- throw new Exception($helper->__('Invalid data'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2283
  // Mage::throwException($helper->__('Invalid data'));
2284
  // return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid data'));
2285
- }
2286
-
2287
- $paymentMethod = $helper->issetOr($postData['method']);
2288
-
2289
- if ($quote->isVirtual()) {
2290
- $quote->getBillingAddress()->setPaymentMethod($paymentMethod);
2291
- } else {
2292
- $quote->getShippingAddress()->setPaymentMethod($paymentMethod);
2293
- }
2294
-
2295
- $payment = $quote->getPayment();
2296
- $payment->importData($postData);
2297
-
2298
- $quote->save();
2299
-
2300
- switch ($paymentMethod) {
2301
- case 'mundipagg_creditcardoneinstallment':
2302
- $standard = Mage::getModel('mundipagg/creditcardoneinstallment');
2303
- break;
2304
- case 'mundipagg_creditcard':
2305
- $standard = Mage::getModel('mundipagg/creditcard');
2306
- break;
2307
-
2308
- case 'mundipagg_twocreditcards':
2309
- $standard = Mage::getModel('mundipagg/twocreditcards');
2310
- break;
2311
-
2312
- case 'mundipagg_threecreditcards':
2313
- $standard = Mage::getModel('mundipagg/threecreditcards');
2314
- break;
2315
-
2316
- case 'mundipagg_fourcreditcards':
2317
- $standard = Mage::getModel('mundipagg/fourcreditcards');
2318
- break;
2319
-
2320
- case 'mundipagg_fivecreditcards':
2321
- $standard = Mage::getModel('mundipagg/fivecreditcards');
2322
- break;
2323
-
2324
- default:
2325
- return 'mundipagg/standard/partial';
2326
- break;
2327
- }
2328
-
2329
- /* @var Uecommerce_Mundipagg_Model_Standard $standard */
2330
- $resultPayment = $standard->doPayment($payment, $order);
2331
- $txns = $helper->issetOr($resultPayment['result']['CreditCardTransactionResultCollection']);
2332
-
2333
- foreach ($txns as $txn) {
2334
- $standard->_addTransaction(
2335
- $order->getPayment(),
2336
- $helper->issetOr($txn['TransactionKey']),
2337
- Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH,
2338
- $txn,
2339
- $num - 1
2340
- );
2341
- }
2342
-
2343
- $order->getPayment()->save();
2344
 
2345
- // $this->replaceNotAuthorizedCcInfo($txns[0], $order->getPayment());
2346
 
2347
- $accAuthorizedAmount = sprintf($order->getData('payment_authorization_amount'));
2348
- $accGrandTotal = sprintf($order->getData('grand_total'));
2349
-
2350
- if ($standard->getAntiFraud() == 0 &&
2351
- $standard->getPaymentAction() === 'order' &&
2352
- $accAuthorizedAmount == $accGrandTotal
2353
- ) {
2354
- $standard->captureAndcreateInvoice($order->getPayment());
2355
- }
2356
-
2357
- switch ($session->getApprovalRequest()) {
2358
- case 'success':
2359
- // Send new order email when not in admin and payment is success
2360
- if (Mage::app()->getStore()->getCode() !== 'admin') {
2361
- $order->sendNewOrderEmail();
2362
- }
2363
- $redirectRoute = 'mundipagg/standard/success';
2364
- break;
2365
-
2366
- case 'partial':
2367
- $redirectRoute = 'mundipagg/standard/partial';
2368
- break;
2369
-
2370
- case 'cancel':
2371
- $redirectRoute = 'mundipagg/standard/cancel';
2372
- break;
2373
-
2374
- default:
2375
- throw new Exception("Unexpected approvalRequestSuccess: {$session->getApprovalRequest()}");
2376
- }
2377
- }
2378
-
2379
- return $redirectRoute;
2380
- }
2381
-
2382
- /**
2383
- * Replace the not authorized payment additional information
2384
- */
2385
- public function replaceNotAuthorizedCcInfo($mundiResponse, Mage_Sales_Model_Order_Payment &$payment) {
2386
- $info = $payment->getAdditionalInformation();
2387
- $ccQty = $info['mundipagg_type'][0];
2388
- $keys = array_keys($info);
2389
- $ccsData = [];
2390
- $otherData = [];
2391
-
2392
- // separate credit cards payment additional information
2393
- foreach ($keys as $key) {
2394
- $idxTwoInitialLetters = $key[0] . $key[1];
2395
- $value = $info[$key];
2396
-
2397
- if ($idxTwoInitialLetters === '1_') {
2398
- $ccsData[1][$key] = $value;
2399
- } elseif ($idxTwoInitialLetters === '2_') {
2400
- $ccsData[2][$key] = $value;
2401
- } else {
2402
- $otherData[$key] = $value;
2403
- }
2404
- }
2405
-
2406
- $notAuthorizedCc = null;
2407
-
2408
- // get just the not authorized credit card data
2409
- for ($i = 1; $i <= $ccQty; $i++) {
2410
- $idx = "{$i}_Success";
2411
- $success = $ccsData[$i][$idx];
2412
-
2413
- if ($success) {
2414
- // $notAuthorizedCc = $i === 1 ? 1 : 2;
2415
- if ($i === 1) {
2416
- $notAuthorizedCc = 1;
2417
- } else {
2418
- $notAuthorizedCc = 2;
2419
- }
2420
- break;
2421
- }
2422
- }
2423
 
2424
- $responseKeys = $this->extractTxnKeys($mundiResponse);
2425
- $key = null;
 
 
 
 
 
2426
 
2427
- foreach ($responseKeys as $key => $val) {
2428
- $idx = "{$notAuthorizedCc}_{$val}";
2429
- $ccsData[$idx] = isset($ccsData[$idx]) ? $ccsData[$idx] : null;
2430
- }
2431
 
2432
- $data = $otherData + $ccsData[1] + $ccsData[2];
 
 
2433
 
2434
- $payment->setAdditionalInformation($data)->save();
2435
- }
 
2436
 
2437
- public function extractTxnKeys($txn) {
2438
- $keys = [];
 
2439
 
2440
- foreach ($txn as $key => $val) {
2441
- if (is_array($txn[$key]) && !empty($txn[$key])) {
 
2442
 
2443
- foreach ($txn[$key] as $subKey => $subVal) {
2444
- $keys[] = $subKey;
2445
- }
 
2446
 
2447
- } else {
2448
- $keys[] = $key;
2449
- }
2450
- }
2451
 
2452
- return $keys;
2453
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2454
 
2455
  }
1
  <?php
2
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  class Uecommerce_Mundipagg_Model_Standard extends Mage_Payment_Model_Method_Abstract {
4
+
5
+ /**
6
+ * Availability options
7
+ */
8
+ protected $_code = 'mundipagg_standard';
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 = false;
19
+ protected $_canUseCheckout = false;
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
+ private $brands = [
27
+ 'VI' => 'Visa',
28
+ 'MC' => 'Mastercard',
29
+ 'AE' => 'Amex',
30
+ 'DI' => 'Diners',
31
+ 'HI' => 'Hipercard',
32
+ 'EL' => 'Elo'
33
+ ];
34
+
35
+ /**
36
+ * Transaction ID
37
+ * */
38
+ protected $_transactionId = null;
39
+
40
+ /**
41
+ * CreditCardOperationEnum na gateway
42
+ * @var $CreditCardOperationEnum varchar
43
+ */
44
+ private $_creditCardOperationEnum;
45
+
46
+ public function getUrl() {
47
+ return $this->url;
48
+ }
49
+
50
+ public function setUrl($url) {
51
+ $this->url = $url;
52
+ }
53
+
54
+ public function setmerchantKey($merchantKey) {
55
+ $this->merchantKey = $merchantKey;
56
+ }
57
+
58
+ public function getmerchantKey() {
59
+ return $this->merchantKey;
60
+ }
61
+
62
+ public function setEnvironment($environment) {
63
+ $this->environment = $environment;
64
+ }
65
+
66
+ public function getEnvironment() {
67
+ return $this->environment;
68
+ }
69
+
70
+ public function setPaymentMethodCode($paymentMethodCode) {
71
+ $this->paymentMethodCode = $paymentMethodCode;
72
+ }
73
+
74
+ public function getPaymentMethodCode() {
75
+ return $this->paymentMethodCode;
76
+ }
77
+
78
+ public function setAntiFraud($antiFraud) {
79
+ $this->antiFraud = $antiFraud;
80
+ }
81
+
82
+ public function getAntiFraud() {
83
+ return $this->antiFraud;
84
+ }
85
+
86
+ public function setBankNumber($bankNumber) {
87
+ $this->bankNumber = $bankNumber;
88
+ }
89
+
90
+ public function getBankNumber() {
91
+ return $this->bankNumber;
92
+ }
93
+
94
+ public function setDebug($debug) {
95
+ $this->_debug = $debug;
96
+ }
97
+
98
+ public function getDebug() {
99
+ return $this->_debug;
100
+ }
101
+
102
+ public function setDiasValidadeBoleto($diasValidadeBoleto) {
103
+ $this->_diasValidadeBoleto = $diasValidadeBoleto;
104
+ }
105
+
106
+ public function getDiasValidadeBoleto() {
107
+ return $this->_diasValidadeBoleto;
108
+ }
109
+
110
+ public function setInstrucoesCaixa($instrucoesCaixa) {
111
+ $this->_instrucoesCaixa = $instrucoesCaixa;
112
+ }
113
+
114
+ public function getInstrucoesCaixa() {
115
+ return $this->_instrucoesCaixa;
116
+ }
117
+
118
+ public function setCreditCardOperationEnum($creditCardOperationEnum) {
119
+ $this->_creditCardOperationEnum = $creditCardOperationEnum;
120
+ }
121
+
122
+ public function getCreditCardOperationEnum() {
123
+ return $this->_creditCardOperationEnum;
124
+ }
125
+
126
+ public function setParcelamento($parcelamento) {
127
+ $this->parcelamento = $parcelamento;
128
+ }
129
+
130
+ public function getParcelamento() {
131
+ return $this->parcelamento;
132
+ }
133
+
134
+ public function setParcelamentoMax($parcelamentoMax) {
135
+ $this->parcelamentoMax = $parcelamentoMax;
136
+ }
137
+
138
+ public function getParcelamentoMax() {
139
+ return $this->parcelamentoMax;
140
+ }
141
+
142
+ public function setPaymentAction($paymentAction) {
143
+ $this->paymentAction = $paymentAction;
144
+ }
145
+
146
+ public function getPaymentAction() {
147
+ return $this->paymentAction;
148
+ }
149
+
150
+ public function setCieloSku($cieloSku) {
151
+ $this->cieloSku = $cieloSku;
152
+ }
153
+
154
+ public function getCieloSku() {
155
+ return $this->cieloSku;
156
+ }
157
+
158
+ public function __construct($Store = null) {
159
+ if (!($Store instanceof Mage_Core_Model_Store)) {
160
+ $Store = null;
161
+ }
162
+ $this->setEnvironment($this->getConfigData('environment', $Store));
163
+ switch ($this->getEnvironment()) {
164
+ case 'localhost':
165
+ case 'development':
166
+ case 'staging':
167
+ default:
168
+ $environment = 'Staging';
169
+ $this->setPaymentMethodCode(1);
170
+ $this->setBankNumber(341);
171
+ break;
172
+ case 'production':
173
+ $environment = 'Production';
174
+ break;
175
+ }
176
+ $this->setmerchantKey(trim($this->getConfigData('merchantKey' . $environment, $Store)));
177
+ $this->setUrl(trim($this->getConfigData('apiUrl' . $environment, $Store)));
178
+ $this->setPaymentAction($this->getConfigData('payment_action', $Store));
179
+ $this->setAntiFraud($this->getConfigData('antifraud', $Store));
180
+ $this->setParcelamento($this->getConfigData('parcelamento', $Store));
181
+ $this->setParcelamentoMax($this->getConfigData('parcelamento_max', $Store));
182
+ $this->setDebug($this->getConfigData('debug', $Store));
183
+ $this->setEnvironment($this->getConfigData('environment', $Store));
184
+ $this->setCieloSku($this->getConfigData('cielo_sku', $Store));
185
+ }
186
+
187
+ public function getConfigData($field, $storeId = null) {
188
+ if (null === $storeId) {
189
+ $storeId = $this->getStore();
190
+ }
191
+ $code = $this->getCode();
192
+ $path = 'payment/' . $code . '/' . $field;
193
+ $data = Mage::getStoreConfig($path, $storeId);
194
+ if (!$data && $code != 'mundipagg_standard') {
195
+ $path = 'payment/mundipagg_standard/' . $field;
196
+ $data = Mage::getStoreConfig($path, $storeId);
197
+ }
198
+ return $data;
199
+ }
200
+
201
+ /**
202
+ * Armazena as informações passadas via formulário no frontend
203
+ * @access public
204
+ * @param array $data
205
+ * @return Uecommerce_Mundipagg_Model_Standard
206
+ */
207
+ public function assignData($data) {
208
+ if (!($data instanceof Varien_Object)) {
209
+ $data = new Varien_Object($data);
210
+ }
211
+
212
+ $info = $this->getInfoInstance();
213
+ $mundipagg = array();
214
+ $helper = Mage::helper('mundipagg');
215
+
216
+ foreach ($data->getData() as $id => $value) {
217
+ $mundipagg[$id] = $value;
218
+
219
+ // We verify if a CPF OR CNPJ is valid
220
+ $posTaxvat = strpos($id, 'taxvat');
221
+
222
+ if ($posTaxvat !== false && $value != '') {
223
+ if (!$helper->validateCPF($value) && !$helper->validateCNPJ($value)) {
224
+ $error = $helper->__('CPF or CNPJ is invalid');
225
+
226
+ Mage::throwException($error);
227
+ }
228
+ }
229
+ }
230
+
231
+ if (!empty($mundipagg)) {
232
+ $helperInstallments = Mage::helper('mundipagg/Installments');
233
+
234
+ //Set Mundipagg Data in Session
235
+ $session = Mage::getSingleton('checkout/session');
236
+ $session->setMundipaggData($mundipagg);
237
+
238
+ $info = $this->getInfoInstance();
239
+
240
+ if (isset($mundipagg['mundipagg_type'])) {
241
+ $info->setAdditionalInformation('PaymentMethod', $mundipagg['method']);
242
+
243
+ switch ($mundipagg['method']) {
244
+ case 'mundipagg_creditcard':
245
+ if (isset($mundipagg['mundipagg_creditcard_1_1_cc_type'])) {
246
+ if (array_key_exists('mundipagg_creditcard_credito_parcelamento_1_1', $mundipagg)) {
247
+ if ($mundipagg['mundipagg_creditcard_credito_parcelamento_1_1'] > $helperInstallments->getMaxInstallments($mundipagg['mundipagg_creditcard_1_1_cc_type'])) {
248
+ Mage::throwException($helper->__('it is not possible to divide by %s times', $mundipagg['mundipagg_creditcard_credito_parcelamento_1_1']));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  }
250
+ }
251
+ $info->setCcType($mundipagg['mundipagg_creditcard_1_1_cc_type'])
252
+ ->setCcOwner($mundipagg['mundipagg_creditcard_cc_holder_name_1_1'])
253
+ ->setCcLast4(substr($mundipagg['mundipagg_creditcard_1_1_cc_number'], -4))
254
+ ->setCcNumber($mundipagg['mundipagg_creditcard_1_1_cc_number'])
255
+ ->setCcCid($mundipagg['mundipagg_creditcard_cc_cid_1_1'])
256
+ ->setCcExpMonth($mundipagg['mundipagg_creditcard_expirationMonth_1_1'])
257
+ ->setCcExpYear($mundipagg['mundipagg_creditcard_expirationYear_1_1']);
258
+ } else {
259
+ $info->setAdditionalInformation('mundipagg_creditcard_token_1_1', $mundipagg['mundipagg_creditcard_token_1_1']);
260
+ }
261
+
262
+ break;
263
+
264
+ default:
265
+
266
+ $info->setCcType(null)
267
+ ->setCcOwner(null)
268
+ ->setCcLast4(null)
269
+ ->setCcNumber(null)
270
+ ->setCcCid(null)
271
+ ->setCcExpMonth(null)
272
+ ->setCcExpYear(null);
273
+
274
+ break;
275
+ }
276
+
277
+ foreach ($mundipagg as $key => $value) {
278
+ // We don't save CcNumber
279
+ $posCcNumber = strpos($key, 'number');
280
+
281
+ // We don't save Security Code
282
+ $posCid = strpos($key, 'cid');
283
+
284
+ // We don't save Cc Holder name
285
+ $posHolderName = strpos($key, 'holder_name');
286
+
287
+ if ($value != '' &&
288
+ $posCcNumber === false &&
289
+ $posCid === false &&
290
+ $posHolderName === false
291
+ ) {
292
+ if (strpos($key, 'cc_type')) {
293
+ $value = $helper->issuer($value);
294
+ }
295
+
296
+ $info->setAdditionalInformation($key, $value);
297
+ }
298
+ }
299
+
300
+ // We check if quote grand total is equal to installments sum
301
+ if ($mundipagg['method'] != 'mundipagg_boleto' && $mundipagg['method'] != 'mundipagg_creditcardoneinstallment' && $mundipagg['method'] != 'mundipagg_creditcard'
302
+ ) {
303
+ $num = $helper->getCreditCardsNumber($mundipagg['method']);
304
+ $method = $helper->getPaymentMethod($num);
305
+
306
+ (float) $grandTotal = $info->getQuote()->getGrandTotal();
307
+ (float) $totalInstallmentsToken = 0;
308
+ (float) $totalInstallmentsNew = 0;
309
+ (float) $totalInstallments = 0;
310
+
311
+ for ($i = 1; $i <= $num; $i++) {
312
+
313
+ if (isset($mundipagg[$method . '_token_' . $num . '_' . $i]) && $mundipagg[$method . '_token_' . $num . '_' . $i] != 'new') {
314
+ (float) $value = str_replace(',', '.', $mundipagg[$method . '_value_' . $num . '_' . $i]);
315
+
316
+ if (array_key_exists($method . '_credito_parcelamento_' . $num . '_' . $i, $mundipagg)) {
317
+ if (!array_key_exists($method . '_' . $num . '_' . $i . '_cc_type', $mundipagg)) {
318
+ $cardonFile = Mage::getModel('mundipagg/cardonfile')->load($mundipagg[$method . '_token_' . $num . '_' . $i]);
319
+
320
+ $mundipagg[$method . '_' . $num . '_' . $i . '_cc_type'] = Mage::helper('mundipagg')->getCardTypeByIssuer($cardonFile->getCcType());
321
+ }
322
+
323
+ if ($mundipagg[$method . '_credito_parcelamento_' . $num . '_' . $i] > $helperInstallments->getMaxInstallments($mundipagg[$method . '_' . $num . '_' . $i . '_cc_type'], $value)) {
324
+ Mage::throwException($helper->__('it is not possible to divide by %s times', $mundipagg[$method . '_credito_parcelamento_' . $num . '_' . $i]));
325
+ }
326
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
 
328
+ (float) $totalInstallmentsToken += $value;
329
+ } else {
330
+ (float) $value = str_replace(',', '.', $mundipagg[$method . '_new_value_' . $num . '_' . $i]);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
 
332
+ if (array_key_exists($method . '_new_credito_parcelamento_' . $num . '_' . $i, $mundipagg)) {
333
+ if ($mundipagg[$method . '_new_credito_parcelamento_' . $num . '_' . $i] > $helperInstallments->getMaxInstallments($mundipagg[$method . '_' . $num . '_' . $i . '_cc_type'], $value)) {
334
+ Mage::throwException($helper->__('it is not possible to divide by %s times', $mundipagg[$method . '_new_credito_parcelamento_' . $num . '_' . $i]));
335
+ }
336
+ }
337
+
338
+ (float) $totalInstallmentsNew += $value;
339
+ }
340
+ }
341
+
342
+ // Total Installments from token and Credit Card
343
+ (float) $totalInstallments = $totalInstallmentsToken + $totalInstallmentsNew;
344
+
345
+ // If an amount has already been authorized
346
+ if (isset($mundipagg['multi']) && Mage::getSingleton('checkout/session')->getAuthorizedAmount()) {
347
+ (float) $totalInstallments += (float) Mage::getSingleton('checkout/session')->getAuthorizedAmount();
348
+
349
+ // Unset session
350
+ Mage::getSingleton('checkout/session')->setAuthorizedAmount();
351
+ }
352
+
353
+ $epsilon = 0.00001;
354
+ }
355
+ } else {
356
+ if (isset($mundipagg['method'])) {
357
+ $info->setAdditionalInformation('PaymentMethod', $mundipagg['method']);
358
+ }
359
+ }
360
+ }
361
+
362
+ // Get customer_id from Quote (payment made on site) or from POST (payment made from API)
363
+ if (Mage::getSingleton('customer/session')->isLoggedIn()) {
364
+ if ($this->getQuote()->getCustomer()->getEntityId()) {
365
+ $customerId = $this->getQuote()->getCustomer()->getEntityId();
366
+ }
367
+ } elseif (isset($mundipagg['entity_id'])) {
368
+ $customerId = $mundipagg['entity_id'];
369
+ }
370
+
371
+ // We verifiy if token is from customer
372
+ if (isset($customerId) && isset($mundipagg['method'])) {
373
+ $num = $helper->getCreditCardsNumber($mundipagg['method']);
374
+
375
+ if ($num == 0) {
376
+ $num = 1;
377
+ }
378
+
379
+ foreach ($mundipagg as $key => $value) {
380
+ $pos = strpos($key, 'token_' . $num);
381
+
382
+ if ($pos !== false && $value != '' && $value != 'new') {
383
+ $token = Mage::getModel('mundipagg/cardonfile')->load($value);
384
+
385
+ if ($token->getId() && $token->getEntityId() == $customerId) {
386
+ // Ok
387
+ $info->setAdditionalInformation('CreditCardBrandEnum_' . $key, $token->getCcType());
388
+ } else {
389
+ $error = $helper->__('Token not found');
390
+
391
+ //Log error
392
+ Mage::log($error, null, 'Uecommerce_Mundipagg.log');
393
+
394
+ Mage::throwException($error);
395
+ }
396
+ }
397
+ }
398
+ }
399
+
400
+ return $this;
401
+ }
402
+
403
+ /**
404
+ * Prepare info instance for save
405
+ *
406
+ * @return Mage_Payment_Model_Abstract
407
+ */
408
+ public function prepareSave() {
409
+ $info = $this->getInfoInstance();
410
+ if ($this->_canSaveCc) {
411
+ $info->setCcNumberEnc($info->encrypt($info->getCcNumber()));
412
+ }
413
+
414
+ $info->setCcNumber(null);
415
+
416
+ return $this;
417
+ }
418
+
419
+ /**
420
+ * Get payment quote
421
+ */
422
+ public function getPayment() {
423
+ return $this->getQuote()->getPayment();
424
+ }
425
+
426
+ /**
427
+ * Get Modulo session namespace
428
+ *
429
+ * @return Uecommerce_Mundipagg_Model_Session
430
+ */
431
+ public function getSession() {
432
+ return Mage::getSingleton('mundipagg/session');
433
+ }
434
+
435
+ /**
436
+ * Get checkout session namespace
437
+ *
438
+ * @return Mage_Checkout_Model_Session
439
+ */
440
+ public function getCheckout() {
441
+ return Mage::getSingleton('checkout/session');
442
+ }
443
+
444
+ /**
445
+ * Get current quote
446
+ *
447
+ * @return Mage_Sales_Model_Quote
448
+ */
449
+ public function getQuote() {
450
+ return $this->getCheckout()->getQuote();
451
+ }
452
+
453
+ /**
454
+ * Check order availability
455
+ *
456
+ * @return bool
457
+ */
458
+ public function canOrder() {
459
+ return $this->_canOrder;
460
+ }
461
+
462
+ /**
463
+ * Check authorize availability
464
+ *
465
+ * @return bool
466
+ */
467
+ public function canAuthorize() {
468
+ return $this->_canAuthorize;
469
+ }
470
+
471
+ /**
472
+ * Check capture availability
473
+ *
474
+ * @return bool
475
+ */
476
+ public function canCapture() {
477
+ return $this->_canCapture;
478
+ }
479
+
480
+ /**
481
+ * Instantiate state and set it to state object
482
+ *
483
+ * @param string $paymentAction
484
+ * @param Varien_Object
485
+ */
486
+ public function initialize($paymentAction, $stateObject) {
487
+ // TODO move initialize method to appropriate model (Boleto, Creditcard ...)
488
+ $paymentAction = $this->getPaymentAction();
489
+
490
+ switch ($paymentAction) {
491
+ case 'order':
492
+ $this->setCreditCardOperationEnum('AuthAndCapture');
493
+ break;
494
+
495
+ case 'authorize':
496
+ $this->setCreditCardOperationEnum('AuthOnly');
497
+ break;
498
+
499
+ case 'authorize_capture':
500
+ $this->setCreditCardOperationEnum('AuthAndCaptureWithDelay');
501
+ break;
502
+ }
503
+
504
+ $orderAction = Mage_Payment_Model_Method_Abstract::ACTION_ORDER;
505
+ $payment = $this->getInfoInstance();
506
+ $order = $payment->getOrder();
507
+
508
+ // If payment method is Boleto Bancário we call "order" method
509
+ if ($payment->getAdditionalInformation('PaymentMethod') == 'mundipagg_boleto') {
510
+ $this->order($payment, $order->getBaseTotalDue());
511
+
512
+ return $this;
513
+ }
514
+
515
+ // If it's a multi-payment types we force to ACTION_AUTHORIZE
516
+ $num = Mage::helper('mundipagg')->getCreditCardsNumber($payment->getAdditionalInformation('PaymentMethod'));
517
+
518
+ if ($num > 1) {
519
+ $paymentAction = Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
520
+ }
521
+
522
+ switch ($paymentAction) {
523
+ case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE:
524
+ $payment->authorize($payment, $order->getBaseTotalDue());
525
+ break;
526
+
527
+ case Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE:
528
+ $payment->authorize($payment, $order->getBaseTotalDue());
529
+ break;
530
+
531
+ case $orderAction:
532
+ $this->order($payment, $order->getBaseTotalDue());
533
+ break;
534
+
535
+ default:
536
+ $this->order($payment, $order->getBaseTotalDue());
537
+ break;
538
+ }
539
+ }
540
+
541
+ /**
542
+ * Authorize payment abstract method
543
+ *
544
+ * @param Varien_Object $payment
545
+ * @param float $amount
546
+ *
547
+ * @return Mage_Payment_Model_Abstract
548
+ */
549
+ public function authorize(Varien_Object $payment, $amount) {
550
+ try {
551
+ if (!$this->canAuthorize()) {
552
+ Mage::throwException(Mage::helper('payment')->__('Authorize action is not available.'));
553
+ }
554
+
555
+ // Load order
556
+ $order = $payment->getOrder();
557
+
558
+ // Proceed to authorization on Gateway
559
+ $resultPayment = $this->doPayment($payment, $order);
560
+ $helper = Mage::helper('mundipagg');
561
+ $result = $helper->issetOr($resultPayment['result'], false);
562
+ $ccResultCollection = $helper->issetOr($result['CreditCardTransactionResultCollection']);
563
+
564
+ if ($result === false) {
565
+ return $this->integrationTimeOut($order, $payment);
566
+ }
567
+
568
+ // Return error
569
+ if (isset($resultPayment['error'])) {
570
+ return $this->paymentError($payment, $resultPayment);
571
+ }
572
+
573
+ if (is_null($ccResultCollection) === false) {
574
+ // We record transaction(s)
575
+ if (count($ccResultCollection) == 1) {
576
+ $trans = $ccResultCollection[0];
577
+ $this->_addTransaction($payment, $trans['TransactionKey'], Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, $trans);
578
+ } else {
579
+ foreach ($ccResultCollection as $key => $trans) {
580
+ $this->_addTransaction($payment, $trans['TransactionKey'], Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, $trans, $key);
581
+ }
582
+ }
583
+ }
584
+
585
+ // Return
586
+ if (isset($resultPayment['error'])) {
587
+ try {
588
+ $payment->setSkipOrderProcessing(true)->save();
589
+
590
+ if (empty($resultPayment['ErrorDescription']) === false) {
591
+ Mage::throwException(Mage::helper('mundipagg')->__($resultPayment['ErrorDescription']));
592
+ }
593
+ } catch (Exception $e) {
594
+ Mage::logException($e);
595
+
596
+ return $this;
597
+ }
598
+ } else {
599
+ $accPaymentAuthorizationAmount = sprintf($order->getPaymentAuthorizationAmount());
600
+ $accGrandTotal = sprintf($order->getGrandTotal());
601
+
602
+ // Send new order email when not in admin
603
+ if ((Mage::app()->getStore()->getCode() != 'admin') && ($accPaymentAuthorizationAmount == $accGrandTotal)) {
604
+ $order->sendNewOrderEmail();
605
+ }
606
+
607
+ // We can capture only if:
608
+ // 1. Multiple Credit Cards Payment
609
+ // 2. Anti fraud is disabled
610
+ // 3. Payment action is "AuthorizeAndCapture"
611
+ // 4. Authorization amount is equal to grand_total
612
+ if (
613
+ count($ccResultCollection) > 1 && $this->getAntiFraud() == 0 && $this->getPaymentAction() == 'order' && $accPaymentAuthorizationAmount == $accGrandTotal
614
+ ) {
615
+ $this->captureAndcreateInvoice($payment);
616
+ } else if ($accPaymentAuthorizationAmount < $accGrandTotal) {
617
+ $order->cancel();
618
+ $order->setState(Mage_Sales_Model_Order::STATE_CANCELED, true)->save();
619
+ $order->setStatus(Mage_Sales_Model_Order::STATE_CANCELED);
620
+ $order->save();
621
+ }
622
+ }
623
+ return $this;
624
+ } catch (Exception $e) {
625
+ Mage::logException($e);
626
+ }
627
+ }
628
+
629
+ /**
630
+ * Capture payment abstract method
631
+ *
632
+ * @param Varien_Object $payment
633
+ * @param float $amount
634
+ *
635
+ * @return Mage_Payment_Model_Abstract
636
+ */
637
+ public function capture(Varien_Object $payment, $amount) {
638
+ $helper = Mage::helper('mundipagg');
639
+ $captureCase = $helper->issetOr($_POST['invoice']['capture_case'], 'offline');
640
+
641
+ if ($captureCase === 'online') {
642
+ $this->captureOnline($payment);
643
+
644
+ return $this;
645
+ }
646
+
647
+ if (!$this->canCapture()) {
648
+ Mage::throwException($helper->__('Capture action is not available.'));
649
+ }
650
+
651
+ if ($payment->getAdditionalInformation('PaymentMethod') == 'mundipagg_boleto') {
652
+ Mage::throwException($helper->__('You cannot capture Boleto Bancário.'));
653
+ }
654
+
655
+ if ($this->getAntiFraud() == 1) {
656
+ Mage::throwException($helper->__('You cannot capture having anti fraud activated.'));
657
+ }
658
+
659
+ // Already captured
660
+ if ($payment->getAdditionalInformation('CreditCardTransactionStatusEnum') == 'Captured' || $payment->getAdditionalInformation('CreditCardTransactionStatus') == 'Captured') {
661
+ return $this;
662
+ }
663
+
664
+ /* @var Mage_Sales_Model_Order_Payment $payment */
665
+ $orderkeys = (array) $payment->getAdditionalInformation('OrderKey');
666
+
667
+ if (empty($orderkeys)) {
668
+ Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
669
+
670
+ return false;
671
+ }
672
+
673
+ foreach ($orderkeys as $orderkey) {
674
+ /* @var Uecommerce_Mundipagg_Model_Api $api */
675
+ $api = Mage::getModel('mundipagg/api');
676
+ //Call Gateway Api
677
+ $capture = $api->saleCapture(['OrderKey' => $orderkey], $payment->getOrder()->getIncrementId());
678
+ $ccTxnResultCollection = $helper->issetOr($capture['CreditCardTransactionResultCollection']);
679
+
680
+ if (!is_array($ccTxnResultCollection) || is_null($ccTxnResultCollection) || empty($ccTxnResultCollection)
681
+ ) {
682
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
683
+
684
+ return false;
685
+ }
686
+
687
+ // Save transactions
688
+ foreach ($ccTxnResultCollection as $txn) {
689
+ $this->_addTransaction(
690
+ $payment, $txn['TransactionKey'], Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $txn
691
+ );
692
+ }
693
+ }
694
+
695
+ return true;
696
+ }
697
+
698
+ /**
699
+ * Online capture payment abstract methodl
700
+ *
701
+ * @param Varien_Object $payment
702
+ * @return $this
703
+ */
704
+ public function captureOnline(Varien_Object $payment) {
705
+ /* @var Uecommerce_Mundipagg_Helper_Data $helper */
706
+ $helper = Mage::helper('mundipagg');
707
+
708
+ if (!$this->canCapture()) {
709
+ Mage::throwException($helper->__('Capture action is not available.'));
710
+ }
711
+
712
+ if ($payment->getAdditionalInformation('PaymentMethod') == 'mundipagg_boleto') {
713
+ Mage::throwException($helper->__('You cannot capture Boleto Bancário.'));
714
+ }
715
+
716
+ if ($this->getAntiFraud() == 1) {
717
+ Mage::throwException($helper->__('You cannot capture having anti fraud activated.'));
718
+ }
719
+
720
+ // Already captured
721
+ if ($payment->getAdditionalInformation('CreditCardTransactionStatusEnum') == 'Captured' || $payment->getAdditionalInformation('CreditCardTransactionStatus') == 'Captured'
722
+ ) {
723
+ Mage::throwException($helper->__('Transactions already captured'));
724
+ }
725
+
726
+ /* @var Mage_Sales_Model_Order_Payment $payment */
727
+ $orderkeys = (array) $payment->getAdditionalInformation('OrderKey');
728
+
729
+ if (empty($orderkeys)) {
730
+ Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
731
+ }
732
+
733
+ $captureNotAllowedMsg = $helper->__('Capture was not authorized in MundiPagg');
734
+ $txnsNotAuthorized = 0;
735
+
736
+ foreach ($orderkeys as $orderkey) {
737
+ $data['OrderKey'] = $orderkey;
738
+
739
+ //Call Gateway Api
740
+ /* @var Uecommerce_Mundipagg_Model_Api $api */
741
+ $api = Mage::getModel('mundipagg/api');
742
+ $capture = $api->saleCapture($data, $payment->getOrder()->getIncrementId());
743
+
744
+ $ccTxnResultCollection = $helper->issetOr($capture['CreditCardTransactionResultCollection']);
745
+
746
+ if (!is_array($ccTxnResultCollection) || is_null($ccTxnResultCollection) || empty($ccTxnResultCollection)) {
747
+ Mage::throwException($captureNotAllowedMsg);
748
+ }
749
+
750
+ $txnsNotAuthorized = 0;
751
+
752
+ // Save transactions
753
+ foreach ($ccTxnResultCollection as $txn) {
754
+ $this->_addTransaction(
755
+ $payment, $helper->issetOr($txn['TransactionKey']), Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $txn
756
+ );
757
+
758
+ $success = $helper->issetOr($txn['Success'], false);
759
+
760
+ if ($success === false) {
761
+ $txnsNotAuthorized++;
762
+ }
763
+ }
764
+ }
765
+
766
+ if ($txnsNotAuthorized === 1) {
767
+ Mage::throwException($captureNotAllowedMsg);
768
+ } elseif ($txnsNotAuthorized > 1) {
769
+ Mage::throwException($helper->__('Capture partial authorized'));
770
+ }
771
+
772
+ $this->closeAuthorizationTxns($payment->getOrder());
773
+
774
+ // if has just 1 invoice, update his grand total, adding the credit cards interests
775
+ if (count($payment->getOrder()->getInvoiceCollection()) === 1) {
776
+
777
+ /* @var Mage_Sales_Model_Order_Invoice $invoice */
778
+ $invoice = $payment->getOrder()->getInvoiceCollection()->getItems()[0];
779
+ $this->equalizeInvoiceTotals($invoice);
780
+ }
781
+ }
782
+
783
+ public function closeAuthorizationTxns(Mage_Sales_Model_Order $order) {
784
+ $txnsCollection = Mage::getModel('sales/order_payment_transaction')
785
+ ->getCollection()
786
+ ->addAttributeToFilter('order_id', array('eq' => $order->getId()));
787
+
788
+ /* @var Mage_Paypal_Model_Payment_Transaction $txn */
789
+ foreach ($txnsCollection as $txn) {
790
+ if ($txn->getTxnType() === 'authorization') {
791
+ $txn->setOrderPaymentObject($order->getPayment());
792
+ $txn->setIsClosed(true)->save();
793
+ }
794
+ }
795
+ }
796
+
797
+ /**
798
+ * Capture payment abstract method
799
+ *
800
+ * @param Varien_Object $payment
801
+ * @param float $amount
802
+ *
803
+ * @return Mage_Payment_Model_Abstract
804
+ */
805
+ public function captureAndcreateInvoice(Varien_Object $payment) {
806
+ $order = $payment->getOrder();
807
+
808
+ // Capture
809
+ $capture = $this->capture($payment, $order->getGrandTotal());
810
+
811
+ // Error
812
+ if (!$capture) {
813
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
814
+
815
+ return $this;
816
+ }
817
+
818
+ // Create invoice
819
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(array());
820
+ $invoice->register();
821
+
822
+ $invoice->setCanVoidFlag(true);
823
+ $invoice->getOrder()->setIsInProcess(true);
824
+ $invoice->setState(2);
825
+
826
+ if (Mage::helper('sales')->canSendNewInvoiceEmail($order->getStoreId())) {
827
+ $invoice->setEmailSent(true);
828
+ $invoice->sendEmail();
829
+ }
830
+
831
+ $invoice->save();
832
+
833
+ $order->setBaseTotalPaid($order->getBaseGrandTotal());
834
+ $order->setTotalPaid($order->getBaseGrandTotal());
835
+ $order->addStatusHistoryComment('Captured online amount of R$' . $order->getBaseGrandTotal(), false);
836
+ $order->save();
837
+
838
+ $this->closeAuthorizationTxns($order);
839
+ $this->equalizeInvoiceTotals($invoice);
840
+
841
+ return $this;
842
+ }
843
+
844
+ /**
845
+ * Order payment abstract method
846
+ *
847
+ * @param Varien_Object $payment
848
+ * @param float $amount
849
+ *
850
+ * @return Mage_Payment_Model_Abstract
851
+ */
852
+ public function order(Varien_Object $payment, $amount) {
853
+ if (!$this->canOrder()) {
854
+ Mage::throwException(Mage::helper('payment')->__('Order action is not available.'));
855
+ }
856
+
857
+ // Load order
858
+ $order = $payment->getOrder();
859
+ $order = Mage::getModel('sales/order')->loadByIncrementId($order->getRealOrderId());
860
+
861
+ // Proceed to payment on Gateway
862
+ $resultPayment = $this->doPayment($payment, $order);
863
+
864
+ $helper = Mage::helper('mundipagg');
865
+ $result = $helper->issetOr($resultPayment['result'], false);
866
+
867
+ if ($result === false) {
868
+ return $this->integrationTimeOut($order, $payment);
869
+ }
870
+
871
+ // Return error
872
+ if (isset($resultPayment['error'])) {
873
+ return $this->paymentError($payment, $resultPayment);
874
+ }
875
+
876
+ if (isset($resultPayment['message'])) {
877
+
878
+ $transactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER;
879
+
880
+ // Xml
881
+ $xml = $resultPayment['result'];
882
+ $json = json_encode($xml);
883
+
884
+ $resultPayment['result'] = array();
885
+ $resultPayment['result'] = json_decode($json, true);
886
+
887
+ switch ($resultPayment['message']) {
888
+ // Boleto
889
+ case 0:
890
+ $boletoTransactionCollection = $helper->issetOr(
891
+ $resultPayment['result']['BoletoTransactionResultCollection'][0]
892
+ );
893
+
894
+ $boletoUrl = $helper->issetOr($boletoTransactionCollection['BoletoUrl']);
895
+
896
+ if (is_null($boletoUrl) === false) {
897
+ $payment->setAdditionalInformation('BoletoUrl', $boletoUrl);
898
+
899
+ // In order to show "Print Boleto" link in order email
900
+ $order->getPayment()->setAdditionalInformation('BoletoUrl', $boletoUrl);
901
+ }
902
+
903
+ $transactionKey = $helper->issetOr($boletoTransactionCollection['TransactionKey']);
904
+ $this->_addTransaction($payment, $transactionKey, $transactionType, $boletoTransactionCollection);
905
+
906
+ // We record transaction(s)
907
+ if (count($resultPayment['result']['BoletoTransactionResultCollection']) == 1) {
908
+ $trans = $boletoTransactionCollection;
909
+ $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans);
910
+ } else {
911
+ foreach ($boletoTransactionCollection as $key => $trans) {
912
+ $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans, $key);
913
+ }
914
+ }
915
+
916
+ $payment->setTransactionId($this->_transactionId);
917
+ $payment->save();
918
+
919
+ // Send new order email when not in admin
920
+ if (Mage::app()->getStore()->getCode() != 'admin') {
921
+ $order->sendNewOrderEmail();
922
+ }
923
+
924
+ break;
925
+
926
+ // Credit Card
927
+ case 1:
928
+ $creditCardTransactionResultCollection = $result['CreditCardTransactionResultCollection'];
929
+ $transactionsQty = count($creditCardTransactionResultCollection);
930
+
931
+ // We record transaction(s)
932
+ if ($transactionsQty == 1) {
933
+ $transaction = $creditCardTransactionResultCollection[0];
934
+
935
+ if (array_key_exists('TransactionKey', $transaction)) {
936
+ $this->_addTransaction($payment, $transaction['TransactionKey'], $transactionType, $transaction);
937
+ }
938
+ } else {
939
+ foreach ($creditCardTransactionResultCollection as $key => $trans) {
940
+ if (array_key_exists('TransactionKey', $trans)) {
941
+ $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans, $key);
942
+ }
943
+ }
944
+ }
945
+
946
+ // Send new order email when not in admin
947
+ if (Mage::app()->getStore()->getCode() != 'admin') {
948
+ $order->sendNewOrderEmail();
949
+ }
950
+
951
+ // Invoice
952
+ $order = $payment->getOrder();
953
+
954
+ if (!$order->canInvoice()) {
955
+ // Log error
956
+ Mage::logException(Mage::helper('core')->__('Cannot create an invoice.'));
957
+ Mage::throwException(Mage::helper('core')->__('Cannot create an invoice.'));
958
+ }
959
+
960
+ // Create invoice
961
+ $invoice = Mage::getModel('sales/service_order', $payment->getOrder())->prepareInvoice(array());
962
+ $invoice->register();
963
+
964
+ // Set capture case to offline and register the invoice.
965
+ $invoice->setTransactionId($this->_transactionId);
966
+ $invoice->setCanVoidFlag(true);
967
+ $invoice->getOrder()->setIsInProcess(true);
968
+ $invoice->setState(2);
969
+
970
+ // Send invoice if enabled
971
+ if (Mage::helper('sales')->canSendNewInvoiceEmail($order->getStoreId())) {
972
+ $invoice->setEmailSent(true);
973
+ $invoice->sendEmail();
974
+ }
975
+
976
+ $invoice->save();
977
+
978
+ $order->setBaseTotalPaid($order->getBaseGrandTotal());
979
+ $order->setTotalPaid($order->getBaseGrandTotal());
980
+ $order->addStatusHistoryComment('Captured online amount of R$' . $order->getBaseGrandTotal(), false);
981
+ $order->save();
982
+
983
+ $payment->setLastTransId($this->_transactionId);
984
+ $payment->save();
985
+
986
+ break;
987
+
988
+ // Debit
989
+ case 4:
990
+ // We record transaction
991
+ $trans = $resultPayment['result'];
992
+
993
+ $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans);
994
+ break;
995
+ }
996
+ }
997
+
998
+ return $this;
999
+ }
1000
+
1001
+ /**
1002
+ * Proceed to payment
1003
+ * @param object $order
1004
+ */
1005
+ public function doPayment($payment, $order) {
1006
+ try {
1007
+ $helper = Mage::helper('mundipagg');
1008
+ $session = Mage::getSingleton('checkout/session');
1009
+ $mundipaggData = $session->getMundipaggData();
1010
+
1011
+ //Post data
1012
+ $postData = Mage::app()->getRequest()->getPost();
1013
+
1014
+ // Get customer taxvat
1015
+ $taxvat = '';
1016
+
1017
+ if ($order->getCustomerTaxvat() == '') {
1018
+ $customerId = $order->getCustomerId();
1019
+
1020
+ if ($customerId) {
1021
+ $customer = Mage::getModel('customer/customer')->load($customerId);
1022
+ $taxvat = $customer->getTaxvat();
1023
+ }
1024
+
1025
+ if ($taxvat != '') {
1026
+ $order->setCustomerTaxvat($taxvat)->save();
1027
+ }
1028
+ } else {
1029
+ $taxvat = $order->getCustomerTaxvat();
1030
+ }
1031
+
1032
+ // Data to pass to api
1033
+ $data['customer_id'] = $order->getCustomerId();
1034
+ $data['address_id'] = $order->getBillingAddress()->getCustomerAddressId();
1035
+ $data['payment_method'] = isset($postData['payment']['method']) ? $postData['payment']['method'] : $mundipaggData['method'];
1036
+ $method = $data['payment_method'];
1037
+
1038
+ // 1 or more Credit Cards Payment
1039
+ if (
1040
+ $method != 'mundipagg_boleto' &&
1041
+ $method != 'mundipagg_debit'
1042
+ ) {
1043
+ $num = $helper->getCreditCardsNumber($method);
1044
+
1045
+ if ($num == 0) {
1046
+ $num = 1;
1047
+ }
1048
+ if ($num > 1) {
1049
+ $method = $helper->getPaymentMethod($num);
1050
+ }
1051
+
1052
+ for ($i = 1; $i <= $num; $i++) {
1053
+ // New Credit Card
1054
+ if (
1055
+ !isset($postData['payment'][$method . '_token_' . $num . '_' . $i]) ||
1056
+ (isset($postData['payment'][$method . '_token_' . $num . '_' . $i]) &&
1057
+ $postData['payment'][$method . '_token_' . $num . '_' . $i] == 'new'
1058
+ )
1059
+ ) {
1060
+ if (isset($postData['payment'][$method . '_cc_holder_name_' . $num . '_' . $i])) {
1061
+ $data['payment'][$i]['HolderName'] = $postData['payment'][$method . '_cc_holder_name_' . $num . '_' . $i];
1062
+ } else {
1063
+ $data['payment'][$i]['HolderName'] = $mundipaggData[$method . '_cc_holder_name_' . $num . '_' . $i];
1064
+ }
1065
+
1066
+ if (isset($postData['payment'][$method . '_' . $num . '_' . $i . '_cc_number'])) {
1067
+ $data['payment'][$i]['CreditCardNumber'] = $postData['payment'][$method . '_' . $num . '_' . $i . '_cc_number'];
1068
+ } else {
1069
+ $data['payment'][$i]['CreditCardNumber'] = $mundipaggData[$method . '_' . $num . '_' . $i . '_cc_number'];
1070
+ }
1071
+
1072
+ if (isset($postData['payment'][$method . '_expirationMonth_' . $num . '_' . $i])) {
1073
+ $data['payment'][$i]['ExpMonth'] = $postData['payment'][$method . '_expirationMonth_' . $num . '_' . $i];
1074
+ } else {
1075
+ $data['payment'][$i]['ExpMonth'] = $mundipaggData[$method . '_expirationMonth_' . $num . '_' . $i];
1076
+ }
1077
+
1078
+ if (isset($postData['payment'][$method . '_expirationYear_' . $num . '_' . $i])) {
1079
+ $data['payment'][$i]['ExpYear'] = $postData['payment'][$method . '_expirationYear_' . $num . '_' . $i];
1080
+ } else {
1081
+ $data['payment'][$i]['ExpYear'] = $mundipaggData[$method . '_expirationYear_' . $num . '_' . $i];
1082
+ }
1083
+
1084
+ if (isset($postData['payment'][$method . '_cc_cid_' . $num . '_' . $i])) {
1085
+ $data['payment'][$i]['SecurityCode'] = $postData['payment'][$method . '_cc_cid_' . $num . '_' . $i];
1086
+ } else {
1087
+ $data['payment'][$i]['SecurityCode'] = $mundipaggData[$method . '_cc_cid_' . $num . '_' . $i];
1088
+ }
1089
+
1090
+ if (Mage::helper('mundipagg')->issuer(isset($postData['payment'][$method . '_' . $num . '_' . $i . '_cc_type']))) {
1091
+ $data['payment'][$i]['CreditCardBrandEnum'] = $this->brands[$postData['payment'][$method . '_' . $num . '_' . $i . '_cc_type']];
1092
+ } else {
1093
+ $data['payment'][$i]['CreditCardBrandEnum'] = $this->brands[$mundipaggData[$method . '_' . $num . '_' . $i . '_cc_type']];
1094
+ }
1095
+
1096
+ if (isset($postData['payment'][$method . '_new_credito_parcelamento_' . $num . '_' . $i])) {
1097
+ $data['payment'][$i]['InstallmentCount'] = $postData['payment'][$method . '_new_credito_parcelamento_' . $num . '_' . $i];
1098
+ } else {
1099
+ $data['payment'][$i]['InstallmentCount'] = 1;
1100
+ }
1101
+
1102
+ if (isset($postData['payment'][$method . '_save_token_' . $num . '_' . $i])) {
1103
+ $data['payment'][$i]['token'] = $postData['payment'][$method . '_save_token_' . $num . '_' . $i];
1104
+ } else {
1105
+ $data['payment'][$i]['token'] = null;
1106
+ }
1107
+
1108
+ $new = $method . '_new_value_' . $num . '_' . $i;
1109
+ if (
1110
+ isset($postData['payment'][$new]) &&
1111
+ $postData['payment'][$new] != ''
1112
+ ) {
1113
+ $data['payment'][$i]['AmountInCents'] = str_replace(',', '.', $postData['payment'][$new]);
1114
+
1115
+ if (isset($postData['payment'][$method . '_' . $num . '_' . $i . '_cc_type'])) {
1116
+ $cctype = $postData['payment'][$method . '_' . $num . '_' . $i . '_cc_type'];
1117
+ } else {
1118
+ $cctype = $mundipaggData[$method . '_' . $num . '_' . $i . '_cc_type'];
1119
+ }
1120
+
1121
+ $interest =
1122
+ Mage::helper('mundipagg/installments')->getInterestForCard(
1123
+ $data['payment'][$i]['InstallmentCount'],
1124
+ $cctype,
1125
+ $data['payment'][$i]['AmountInCents']
1126
+ );
1127
+
1128
+ $amountInCents = $data['payment'][$i]['AmountInCents'] + $interest;
1129
+ $data['payment'][$i]['AmountInCents'] = $amountInCents * 100;
1130
+ } else {
1131
+ if (!isset($postData['partial'])) {
1132
+ $data['payment'][$i]['AmountInCents'] = $order->getGrandTotal() * 100;
1133
+ } else { // If partial payment we deduct authorized amount already processed
1134
+ if (Mage::getSingleton('checkout/session')->getAuthorizedAmount()) {
1135
+ $data['payment'][$i]['AmountInCents'] = ($order->getGrandTotal()) * 100 - Mage::getSingleton('checkout/session')->getAuthorizedAmount() * 100;
1136
+ } else {
1137
+ $data['payment'][$i]['AmountInCents'] = ($order->getGrandTotal()) * 100;
1138
+ }
1139
+ }
1140
+ }
1141
+
1142
+ if (isset($postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i])) {
1143
+ $data['payment'][$i]['TaxDocumentNumber'] = $postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i];
1144
+ } else {
1145
+ $data['payment'][$i]['TaxDocumentNumber'] = $taxvat;
1146
+ }
1147
+ } else { // Token
1148
+ if (isset($postData['payment'][$method . '_token_' . $num . '_' . $i])) {
1149
+ $data['payment'][$i]['card_on_file_id'] = $postData['payment'][$method . '_token_' . $num . '_' . $i];
1150
+ } else {
1151
+ $data['payment'][$i]['card_on_file_id'] = $mundipaggData[$method . '_token_' . $num . '_' . $i];
1152
+ }
1153
+
1154
+ if (isset($postData['payment'][$method . '_credito_parcelamento_' . $num . '_' . $i])) {
1155
+ $data['payment'][$i]['InstallmentCount'] = $postData['payment'][$method . '_credito_parcelamento_' . $num . '_' . $i];
1156
+ } else {
1157
+ $data['payment'][$i]['InstallmentCount'] = 1;
1158
+ }
1159
+
1160
+ if (
1161
+ isset($postData['payment'][$method . '_value_' . $num . '_' . $i]) &&
1162
+ $postData['payment'][$method . '_value_' . $num . '_' . $i] != ''
1163
+ ) {
1164
+ $data['payment'][$i]['AmountInCents'] = str_replace(',', '.', $postData['payment'][$method . '_value_' . $num . '_' . $i]);
1165
+ $cardonFile = Mage::getModel('mundipagg/cardonfile')->load($postData['payment'][$method . '_token_' . $num . '_' . $i]);
1166
+ $tokenCctype = Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cardonFile->getCcType());
1167
+ $data['payment'][$i]['AmountInCents'] = $data['payment'][$i]['AmountInCents'] + Mage::helper('mundipagg/installments')
1168
+ ->getInterestForCard(
1169
+ $data['payment'][$i]['InstallmentCount'], $tokenCctype, $data['payment'][$i]['AmountInCents']
1170
+ );
1171
+ $data['payment'][$i]['AmountInCents'] = $data['payment'][$i]['AmountInCents'] * 100;
1172
+ } else {
1173
+ if (!isset($postData['partial'])) {
1174
+ $data['payment'][$i]['AmountInCents'] = $order->getGrandTotal() * 100;
1175
+ } else { // If partial payment we deduct authorized amount already processed
1176
+ if (Mage::getSingleton('checkout/session')->getAuthorizedAmount()) {
1177
+ $data['payment'][$i]['AmountInCents'] = ($order->getGrandTotal()) * 100 - Mage::getSingleton('checkout/session')->getAuthorizedAmount() * 100;
1178
+ } else {
1179
+ $data['payment'][$i]['AmountInCents'] = $order->getGrandTotal() * 100;
1180
+ }
1181
+ }
1182
+ }
1183
+
1184
+ if (isset($postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i])) {
1185
+ $data['payment'][$i]['TaxDocumentNumber'] = $postData['payment'][$method . '_cc_taxvat_' . $num . '_' . $i];
1186
+ } else {
1187
+ $data['payment'][$i]['TaxDocumentNumber'] = $taxvat;
1188
+ }
1189
+ }
1190
+
1191
+ if (Mage::helper('mundipagg')->validateCPF($data['payment'][$i]['TaxDocumentNumber'])) {
1192
+ $data['PersonTypeEnum'] = 'Person';
1193
+ $data['TaxDocumentTypeEnum'] = 'CPF';
1194
+ $data['TaxDocumentNumber'] = $data['payment'][$i]['TaxDocumentNumber'];
1195
+ }
1196
+
1197
+ // We verify if a CNPJ is informed
1198
+ if (Mage::helper('mundipagg')->validateCNPJ($data['payment'][$i]['TaxDocumentNumber'])) {
1199
+ $data['PersonTypeEnum'] = 'Company';
1200
+ $data['TaxDocumentTypeEnum'] = 'CNPJ';
1201
+ $data['TaxDocumentNumber'] = $data['payment'][$i]['TaxDocumentNumber'];
1202
+ }
1203
+ }
1204
+ }
1205
+
1206
+ // Boleto Payment
1207
+ if ($data['payment_method'] == 'mundipagg_boleto') {
1208
+ $data['TaxDocumentNumber'] = isset($postData['payment']['boleto_taxvat']) ? $postData['payment']['boleto_taxvat'] : $taxvat;
1209
+ $data['boleto_parcelamento'] = isset($postData['payment']['boleto_parcelamento']) ? $postData['payment']['boleto_parcelamento'] : 1;
1210
+ $data['boleto_dates'] = isset($postData['payment']['boleto_dates']) ? $postData['payment']['boleto_dates'] : null;
1211
+
1212
+ // We verify if a CPF is informed
1213
+ if (Mage::helper('mundipagg')->validateCPF($data['TaxDocumentNumber'])) {
1214
+ $data['PersonTypeEnum'] = 'Person';
1215
+ $data['TaxDocumentTypeEnum'] = 'CPF';
1216
+ }
1217
+
1218
+ // We verify if a CNPJ is informed
1219
+ if (Mage::helper('mundipagg')->validateCNPJ($data['TaxDocumentNumber'])) {
1220
+ $data['PersonTypeEnum'] = 'Company';
1221
+ $data['TaxDocumentTypeEnum'] = 'CNPJ';
1222
+ }
1223
+ }
1224
+
1225
+ // Debit Payment
1226
+ if ($data['payment_method'] == 'mundipagg_debit') {
1227
+ $data['TaxDocumentNumber'] = isset($postData['payment']['taxvat']) ? $postData['payment']['taxvat'] : $taxvat;
1228
+ $data['Bank'] = isset($postData['payment']['mundipagg_debit']) ? $postData['payment']['mundipagg_debit'] : $mundipaggData['mundipagg_debit'];
1229
+
1230
+ // We verify if a CPF is informed
1231
+ if (Mage::helper('mundipagg')->validateCPF($data['TaxDocumentNumber'])) {
1232
+ $data['PersonTypeEnum'] = 'Person';
1233
+ $data['TaxDocumentTypeEnum'] = 'CPF';
1234
+ }
1235
+
1236
+ // We verify if a CNPJ is informed
1237
+ if (Mage::helper('mundipagg')->validateCNPJ($data['TaxDocumentNumber'])) {
1238
+ $data['PersonTypeEnum'] = 'Company';
1239
+ $data['TaxDocumentTypeEnum'] = 'CNPJ';
1240
+ }
1241
+ }
1242
+
1243
+ // Unset MundipaggData data
1244
+ $session->setMundipaggData();
1245
+
1246
+ // Api
1247
+ $api = Mage::getModel('mundipagg/api');
1248
+ $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
1249
+
1250
+ // Get approval request from gateway
1251
+ switch ($method) {
1252
+ case 'mundipagg_boleto':
1253
+ $approvalRequest = $api->boletoTransaction($order, $data, $this);
1254
+ break;
1255
+
1256
+ case 'mundipagg_debit':
1257
+ $approvalRequest = $api->debitTransaction($order, $data, $this);
1258
+ break;
1259
+
1260
+ case $method:
1261
+ $approvalRequest = $api->creditCardTransaction($order, $data, $this);
1262
+ break;
1263
+
1264
+ default:
1265
+ $approvalRequest = false;
1266
+ }
1267
+
1268
+ if ($approvalRequest === false) {
1269
+ return false;
1270
+ }
1271
+
1272
+ // Set some data from Mundipagg
1273
+ $payment = $this->setPaymentAdditionalInformation($approvalRequest, $payment);
1274
+ $authorizedAmount = $order->getPaymentAuthorizationAmount();
1275
+
1276
+ if (is_null($authorizedAmount)) {
1277
+ $authorizedAmount = 0;
1278
+ }
1279
+
1280
+ // Payment gateway error
1281
+ if (isset($approvalRequest['error'])) {
1282
+
1283
+ if (isset($approvalRequest['ErrorItemCollection'])) {
1284
+ $errorItemCollection = $approvalRequest['ErrorItemCollection'];
1285
+
1286
+ foreach ($errorItemCollection as $i) {
1287
+ $errorCode = $helper->issetOr($i['ErrorCode']);
1288
+
1289
+ if ($errorCode == 504) {
1290
+ $statusWithError = Uecommerce_Mundipagg_Model_Enum_CreditCardTransactionStatusEnum::WITH_ERROR;
1291
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess($statusWithError);
1292
+
1293
+ return $approvalRequest;
1294
+ }
1295
+ }
1296
+ }
1297
+
1298
+ if (isset($approvalRequest['ErrorCode']) && $approvalRequest['ErrorCode'] == 'multi') {
1299
+ // Partial payment
1300
+ // We set authorized amount
1301
+ $orderGrandTotal = $order->getGrandTotal();
1302
+
1303
+ foreach ($approvalRequest['result']->CreditCardTransactionResultCollection->CreditCardTransactionResult as $key => $result) {
1304
+ if ($result->Success == true) {
1305
+ $authorizedAmount += $result->AuthorizedAmountInCents * 0.01;
1306
+ }
1307
+ }
1308
+
1309
+ // If authorized amount is the same as order grand total we can show success page
1310
+ $epsilon = 0.1;
1311
+
1312
+ if ($authorizedAmount != 0) {
1313
+ if (($orderGrandTotal - $authorizedAmount) <= $epsilon) {
1314
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1315
+ Mage::getSingleton('checkout/session')->setAuthorizedAmount();
1316
+ } else {
1317
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('partial');
1318
+ Mage::getSingleton('checkout/session')->setAuthorizedAmount($authorizedAmount);
1319
+ }
1320
+
1321
+ $order->setPaymentAuthorizationAmount($authorizedAmount);
1322
+ $order->save();
1323
+ } else {
1324
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1325
+ }
1326
+ } else {
1327
+ $result = $helper->issetOr($approvalRequest['result'], false);
1328
+
1329
+ if ($result !== false) {
1330
+ $helperLog->info("{$logLabel} | Payment not authorized order will be canceled.");
1331
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1332
+ }
1333
+ }
1334
+
1335
+ return $approvalRequest;
1336
+ }
1337
+
1338
+ switch ($approvalRequest['message']) {
1339
+ // BoletoBancario
1340
+ case 0:
1341
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1342
+ break;
1343
+
1344
+ // 1CreditCards
1345
+ case 1: // AuthAndCapture
1346
+ case 2: // AuthOnly
1347
+ case 3: // AuthAndCaptureWithDelay
1348
+ // We set authorized amount in session
1349
+ $orderGrandTotal = $order->getGrandTotal();
1350
+ $result = $helper->issetOr($approvalRequest['result']);
1351
+ $orderResult = $helper->issetOr($result['OrderResult']);
1352
+ $creditCardTransactionResultCollection = $result['CreditCardTransactionResultCollection'];
1353
+ $transactionsQty = count($creditCardTransactionResultCollection);
1354
+
1355
+ if ($transactionsQty == 1) {
1356
+ $transaction = $creditCardTransactionResultCollection[0];
1357
+ $success = $transaction['Success'];
1358
+
1359
+ if ($success === true) {
1360
+ $authorizedAmount += $transaction['AuthorizedAmountInCents'] * 0.01;
1361
+ }
1362
+ } else {
1363
+ foreach ($creditCardTransactionResultCollection as $key => $transaction) {
1364
+ $success = $transaction['Success'];
1365
+
1366
+ if ($success === true) {
1367
+ $authorizedAmount += $transaction['AuthorizedAmountInCents'] * 0.01;
1368
+ } else {
1369
+ $unauthorizedCreditCardMaskedNumber = $transaction['MaskedCreditCardNumber'];
1370
+ }
1371
+ }
1372
+ }
1373
+
1374
+ // If authorized amount is the same as order grand total we can show success page
1375
+ $epsilon = 0.1;
1376
+
1377
+ if (($orderGrandTotal - $authorizedAmount) <= $epsilon) {
1378
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1379
+ Mage::getSingleton('checkout/session')->setAuthorizedAmount();
1380
+
1381
+ if ($orderGrandTotal < $authorizedAmount) {
1382
+ $interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information');
1383
+ $newInterestInformation = array();
1384
+ $newInterest = 0;
1385
+
1386
+ if (count($interestInformation)) {
1387
+ foreach ($interestInformation as $key => $ii) {
1388
+ if (strpos($key, 'partial') !== false) {
1389
+ if ($ii->hasValue()) {
1390
+ $newInterest += (float) ($ii->getInterest());
1391
+ }
1392
+ }
1393
+ }
1394
+ }
1395
+ $this->addInterestToOrder($order, $newInterest);
1396
+ }
1397
+ } else {
1398
+ if ($authorizedAmount != 0) {
1399
+ if (($orderGrandTotal - $authorizedAmount) >= $epsilon) {
1400
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('partial');
1401
+ Mage::getSingleton('checkout/session')->setAuthorizedAmount($authorizedAmount);
1402
+
1403
+ $interestInformation = $payment->getAdditionalInformation('mundipagg_interest_information');
1404
+ $unauthorizedAmount = (float) ($orderGrandTotal - $authorizedAmount);
1405
+ $newInterestInformation = array();
1406
+
1407
+ if (count($interestInformation)) {
1408
+ foreach ($interestInformation as $key => $ii) {
1409
+
1410
+ if ($ii->hasValue()) {
1411
+ if ((float) ($ii->getValue() + $ii->getInterest()) == (float) trim($unauthorizedAmount)) {
1412
+ $this->removeInterestToOrder($order, $ii->getInterest());
1413
+ } else {
1414
+ $newInterestInformation[$key] = $ii;
1415
+ }
1416
+ } else {
1417
+ if (($order->getGrandTotal() + $order->getMundipaggInterest()) == $unauthorizedAmount) {
1418
+ $this->removeInterestToOrder($order, $ii->getInterest());
1419
+ } else {
1420
+ $newInterestInformation[$key] = $ii;
1421
+ }
1422
+ }
1423
+ }
1424
+
1425
+ $payment->setAdditionalInformation('mundipagg_interest_information', $newInterestInformation);
1426
+ }
1427
+ }
1428
+ } else {
1429
+ $result = $helper->issetOr($approvalRequest['result'], false);
1430
+
1431
+ if ($result !== false) {
1432
+ $helperLog->info("{$logLabel} | Payment not authorized order will be canceled.");
1433
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
1434
+ }
1435
+ }
1436
+ }
1437
+
1438
+ $transactionKey = $transaction['TransactionKey'];
1439
+ $creditCardTransactionStatusEnum = $transaction['CreditCardTransactionStatus'];
1440
+
1441
+ try {
1442
+ if ($transactionKey != null) {
1443
+ $this->_transactionId = $transactionKey;
1444
+
1445
+ $payment->setTransactionId($this->_transactionId);
1446
+ $payment->save();
1447
+ }
1448
+ } catch (Exception $e) {
1449
+ $helperLog->error($e->getMessage());
1450
+ continue;
1451
+ }
1452
+ break;
1453
+
1454
+ // Debit
1455
+ case 4:
1456
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('debit');
1457
+ Mage::getSingleton('checkout/session')->setBankRedirectUrl($approvalRequest['result']['BankRedirectUrl']);
1458
+ break;
1459
+ }
1460
+
1461
+ $orderResult = $helper->issetOr($result['OrderResult']);
1462
+
1463
+ if (isset($orderResult)) {
1464
+ $newOrderKey = $orderResult['OrderKey'];
1465
+ $orderPayment = $order->getPayment();
1466
+ $orderKeys = (array) $orderPayment->getAdditionalInformation('OrderKey');
1467
+
1468
+ if (is_null($orderKeys) || !is_array($orderKeys)) {
1469
+ $orderKeys = [];
1470
+ }
1471
+
1472
+ if (!in_array($newOrderKey, $orderKeys)) {
1473
+ $orderKeys[] = $newOrderKey;
1474
+ }
1475
+
1476
+ $orderPayment->setAdditionalInformation('OrderKey', $orderKeys);
1477
+ $orderPayment->save();
1478
+ }
1479
+
1480
+ $order->setPaymentAuthorizationAmount($authorizedAmount);
1481
+ $order->save();
1482
+
1483
+ if ($authorizedAmount == $order->getGrandTotal()) {
1484
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
1485
+ }
1486
+
1487
+ return $approvalRequest;
1488
+ } catch (Exception $e) {
1489
+ //Api
1490
+ $api = Mage::getModel('mundipagg/api');
1491
+
1492
+ //Log error
1493
+ Mage::logException($e);
1494
+
1495
+ //Mail error
1496
+ $api->mailError(print_r($e->getMessage(), 1));
1497
+ }
1498
+ }
1499
+
1500
+ /**
1501
+ * @param array $approvalRequest
1502
+ * @param $payment
1503
+ * @return mixed
1504
+ */
1505
+ private function setPaymentAdditionalInformation($approvalRequest, $payment) {
1506
+ if (isset($approvalRequest['ErrorCode'])) {
1507
+ $payment->setAdditionalInformation('ErrorCode', $approvalRequest['ErrorCode']);
1508
+ }
1509
+
1510
+ if (isset($approvalRequest['ErrorDescription'])) {
1511
+ $payment->setAdditionalInformation('ErrorDescription', $approvalRequest['ErrorDescription']);
1512
+ }
1513
+
1514
+ if (isset($approvalRequest['OrderKey'])) {
1515
+ $payment->setAdditionalInformation('OrderKey', $approvalRequest['OrderKey']);
1516
+ }
1517
+
1518
+ if (isset($approvalRequest['OrderReference'])) {
1519
+ $payment->setAdditionalInformation('OrderReference', $approvalRequest['OrderReference']);
1520
+ }
1521
+
1522
+ if (isset($approvalRequest['CreateDate'])) {
1523
+ $payment->setAdditionalInformation('CreateDate', $approvalRequest['CreateDate']);
1524
+ }
1525
+
1526
+ if (isset($approvalRequest['OrderStatusEnum'])) {
1527
+ $payment->setAdditionalInformation('OrderStatusEnum', $approvalRequest['OrderStatusEnum']);
1528
+ }
1529
+
1530
+ if (isset($approvalRequest['TransactionKey'])) {
1531
+ $payment->setAdditionalInformation('TransactionKey', $approvalRequest['TransactionKey']);
1532
+ }
1533
+
1534
+ if (isset($approvalRequest['OnlineDebitStatus'])) {
1535
+ $payment->setAdditionalInformation('OnlineDebitStatus', $approvalRequest['OnlineDebitStatus']);
1536
+ }
1537
+
1538
+ if (isset($approvalRequest['TransactionKeyToBank'])) {
1539
+ $payment->setAdditionalInformation('TransactionKeyToBank', $approvalRequest['TransactionKeyToBank']);
1540
+ }
1541
+
1542
+ if (isset($approvalRequest['TransactionReference'])) {
1543
+ $payment->setAdditionalInformation('TransactionReference', $approvalRequest['TransactionReference']);
1544
+ }
1545
+
1546
+ if (array_key_exists('isRecurrency', $approvalRequest)) {
1547
+ $payment->setAdditionalInformation('isRecurrency', $approvalRequest['isRecurrency']);
1548
+ }
1549
+
1550
+ return $payment;
1551
+ }
1552
+
1553
+ /**
1554
+ * Set capture transaction ID and enable Void to invoice for informational purposes
1555
+ * @param Mage_Sales_Model_Order_Invoice $invoice
1556
+ * @param Mage_Sales_Model_Order_Payment $payment
1557
+ * @return Mage_Payment_Model_Method_Abstract
1558
+ */
1559
+ public function processInvoice($invoice, $payment) {
1560
+ if ($payment->getLastTransId()) {
1561
+ $invoice->setTransactionId($payment->getLastTransId());
1562
+ $invoice->setCanVoidFlag(true);
1563
+
1564
+ if (Mage::helper('sales')->canSendNewInvoiceEmail($payment->getOrder()->getStoreId())) {
1565
+ $invoice->setEmailSent(true);
1566
+ $invoice->sendEmail();
1567
+ }
1568
+
1569
+ return $this;
1570
+ }
1571
+
1572
+ return false;
1573
+ }
1574
+
1575
+ /**
1576
+ * Check void availability
1577
+ *
1578
+ * @return bool
1579
+ */
1580
+ public function canVoid(Varien_Object $payment) {
1581
+ if ($payment instanceof Mage_Sales_Model_Order_Creditmemo) {
1582
+ return false;
1583
+ }
1584
+
1585
+ return $this->_canVoid;
1586
+ }
1587
+
1588
+ public function void(Varien_Object $payment) {
1589
+ if (!$this->canVoid($payment)) {
1590
+ Mage::throwException(Mage::helper('payment')->__('Void action is not available.'));
1591
+ }
1592
+
1593
+ //Prepare data in order to void
1594
+ if ($payment->getAdditionalInformation('OrderKey')) {
1595
+ $transactions = Mage::getModel('sales/order_payment_transaction')
1596
+ ->getCollection()
1597
+ ->addAttributeToFilter('order_id', array('eq' => $payment->getOrder()->getEntityId()));
1598
+
1599
+ foreach ($transactions as $key => $transaction) {
1600
+ $TransactionKey = $transaction->getAdditionalInformation('TransactionKey');
1601
+ $TransactionReference = $transaction->getAdditionalInformation('TransactionReference');
1602
+ }
1603
+
1604
+ $orderkeys = $payment->getAdditionalInformation('OrderKey');
1605
+
1606
+ if (!is_array($orderkeys)) {
1607
+ $orderkeys = array($orderkeys);
1608
+ }
1609
+
1610
+ foreach ($orderkeys as $orderkey) {
1611
+ $data['ManageOrderOperationEnum'] = 'Cancel';
1612
+ $data['OrderKey'] = $orderkey;
1613
+
1614
+ //Call Gateway Api
1615
+ $api = Mage::getModel('mundipagg/api');
1616
+
1617
+ $void = $api->manageOrderRequest($data, $this);
1618
+
1619
+ // Xml
1620
+ $xml = $void['result'];
1621
+ $json = json_encode($xml);
1622
+
1623
+ $void['result'] = array();
1624
+ $void['result'] = json_decode($json, true);
1625
+
1626
+ // We record transaction(s)
1627
+ if (count($void['result']['CreditCardTransactionResultCollection']) > 0) {
1628
+ if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
1629
+ $trans = $void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
1630
+
1631
+ $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans);
1632
+ } else {
1633
+ foreach ($void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'] as $key => $trans) {
1634
+ $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans, $key);
1635
+ }
1636
+ }
1637
+ }
1638
+
1639
+ if (isset($void['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'])) {
1640
+ $order = $payment->getOrder();
1641
+ $order->setBaseDiscountRefunded($order->getBaseDiscountInvoiced());
1642
+ $order->setBaseShippingRefunded($order->getBaseShippingAmount());
1643
+ $order->setBaseShippingTaxRefunded($order->getBaseShippingTaxInvoiced());
1644
+ $order->setBaseSubtotalRefunded($order->getBaseSubtotalInvoiced());
1645
+ $order->setBaseTaxRefunded($order->getBaseTaxInvoiced());
1646
+ $order->setBaseTotalOnlineRefunded($order->getBaseGrandTotal());
1647
+ $order->setDiscountRefunded($order->getDiscountInvoiced());
1648
+ $order->setShippinRefunded($order->getShippingInvoiced());
1649
+ $order->setShippinTaxRefunded($order->getShippingTaxAmount());
1650
+ $order->setSubtotalRefunded($order->getSubtotalInvoiced());
1651
+ $order->setTaxRefunded($order->getTaxInvoiced());
1652
+ $order->setTotalOnlineRefunded($order->getBaseGrandTotal());
1653
+ $order->setTotalRefunded($order->getBaseGrandTotal());
1654
+ $order->save();
1655
+
1656
+ return $this;
1657
+ } else {
1658
+ $error = Mage::helper('mundipagg')->__('Unable to void order.');
1659
+
1660
+ //Log error
1661
+ Mage::log($error, null, 'Uecommerce_Mundipagg.log');
1662
+
1663
+ Mage::throwException($error);
1664
+ }
1665
+ }
1666
+ } else {
1667
+ Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
1668
+ }
1669
+ }
1670
+
1671
+ /**
1672
+ * Check refund availability
1673
+ *
1674
+ * @return bool
1675
+ */
1676
+ public function canRefund() {
1677
+ return $this->_canRefund;
1678
+ }
1679
+
1680
+ /**
1681
+ * Set refund transaction id to payment object for informational purposes
1682
+ * Candidate to be deprecated:
1683
+ * there can be multiple refunds per payment, thus payment.refund_transactionId doesn't make big sense
1684
+ *
1685
+ * @param Mage_Sales_Model_Order_Invoice $invoice
1686
+ * @param Mage_Sales_Model_Order_Payment $payment
1687
+ * @return Mage_Payment_Model_Method_Abstract
1688
+ */
1689
+ public function processBeforeRefund($invoice, $payment) {
1690
+ $payment->setRefundTransactionId($invoice->getTransactionId());
1691
+
1692
+ return $this;
1693
+ }
1694
+
1695
+ /**
1696
+ * Refund specified amount for payment
1697
+ *
1698
+ * @param Varien_Object $payment
1699
+ * @param float $amount
1700
+ *
1701
+ * @return Mage_Payment_Model_Abstract
1702
+ */
1703
+ public function refund(Varien_Object $payment, $amount) {
1704
+ if (!$this->canRefund()) {
1705
+ Mage::throwException(Mage::helper('payment')->__('Refund action is not available.'));
1706
+ }
1707
+
1708
+ //Prepare data in order to refund
1709
+ if ($payment->getAdditionalInformation('OrderKey')) {
1710
+ $data['OrderKey'] = $payment->getAdditionalInformation('OrderKey');
1711
+ $data['ManageOrderOperationEnum'] = 'Void';
1712
+
1713
+ //Call Gateway Api
1714
+ $api = Mage::getModel('mundipagg/api');
1715
+
1716
+ $refund = $api->manageOrderRequest($data, $this);
1717
+
1718
+ // Xml
1719
+ $xml = $refund['result'];
1720
+ $json = json_encode($xml);
1721
+
1722
+ $refund['result'] = array();
1723
+ $refund['result'] = json_decode($json, true);
1724
+
1725
+ // We record transaction(s)
1726
+ if (count($refund['result']['CreditCardTransactionResultCollection']) > 0) {
1727
+ if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
1728
+ $trans = $refund['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'];
1729
+
1730
+ $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans);
1731
+ } else {
1732
+ foreach ($refund['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'] as $key => $trans) {
1733
+ $this->_addTransaction($payment, $trans['TransactionKey'], 'void', $trans, $key);
1734
+ }
1735
+ }
1736
+ }
1737
+
1738
+ if (isset($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult)) {
1739
+ if (count($xml->CreditCardTransactionResultCollection->CreditCardTransactionResult) == 1) {
1740
+ $capturedAmountInCents = $manageOrderResult->CreditCardTransactionResultCollection->CreditCardTransactionResult->CapturedAmountInCents;
1741
+ } else {
1742
+ $capturedAmountInCents = 0;
1743
+
1744
+ foreach ($refund['result']['CreditCardTransactionResultCollection']['CreditCardTransactionResult'] as $key => $trans) {
1745
+ $capturedAmountInCents += $trans['CapturedAmountInCents'];
1746
+ }
1747
+ }
1748
+
1749
+ $order = $payment->getOrder();
1750
+ $order->setBaseDiscountRefunded($order->getBaseDiscountInvoiced());
1751
+ $order->setBaseShippingRefunded($order->getBaseShippingAmount());
1752
+ $order->setBaseShippingTaxRefunded($order->getBaseShippingTaxInvoiced());
1753
+ $order->setBaseSubtotalRefunded($order->getBaseSubtotalInvoiced());
1754
+ $order->setBaseTaxRefunded($order->getBaseTaxInvoiced());
1755
+ $order->setBaseTotalOnlineRefunded($capturedAmountInCents * 0.01);
1756
+ $order->setDiscountRefunded($order->getDiscountInvoiced());
1757
+ $order->setShippinRefunded($order->getShippingInvoiced());
1758
+ $order->setShippinTaxRefunded($order->getShippingTaxAmount());
1759
+ $order->setSubtotalRefunded($order->getSubtotalInvoiced());
1760
+ $order->setTaxRefunded($order->getTaxInvoiced());
1761
+ $order->setTotalOnlineRefunded($capturedAmountInCents * 0.01);
1762
+ $order->setTotalRefunded($capturedAmountInCents * 0.01);
1763
+ $order->save();
1764
+
1765
+ return $this;
1766
+ } else {
1767
+ $error = Mage::helper('mundipagg')->__('Unable to refund order.');
1768
+
1769
+ //Log error
1770
+ Mage::log($error, null, 'Uecommerce_Mundipagg.log');
1771
+
1772
+ Mage::throwException($error);
1773
+ }
1774
+ } else {
1775
+ Mage::throwException(Mage::helper('mundipagg')->__('No OrderKey found.'));
1776
+ }
1777
+ }
1778
+
1779
+ /**
1780
+ * Validate
1781
+ */
1782
+ public function validate() {
1783
+ parent::validate();
1784
+
1785
+ $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
1786
+
1787
+ if (!in_array($currencyCode, $this->_allowCurrencyCode)) {
1788
+ Mage::throwException(Mage::helper('payment')->__('Selected currency code (' . $currencyCode . ') is not compatabile with Mundipagg'));
1789
+ }
1790
+
1791
+ $info = $this->getInfoInstance();
1792
+
1793
+ $errorMsg = array();
1794
+
1795
+ // Check if we are dealing with a new Credit Card
1796
+ $isToken = $info->getAdditionalInformation('mundipagg_creditcard_token_1_1');
1797
+
1798
+ if ($info->getAdditionalInformation('PaymentMethod') == 'mundipagg_creditcard' && ($isToken == '' || $isToken == 'new')) {
1799
+ $availableTypes = $this->getCcTypes();
1800
+
1801
+ $ccNumber = $info->getCcNumber();
1802
+
1803
+ // refresh quote to remove promotions from others payment methods
1804
+ try {
1805
+ $this->getQuote()->save();
1806
+ } catch (Exception $e) {
1807
+ $errorMsg[] = $e->getMessage();
1808
+ }
1809
+
1810
+ // remove credit card number delimiters such as "-" and space
1811
+ $ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
1812
+ $info->setCcNumber($ccNumber);
1813
+
1814
+ if (in_array($info->getCcType(), $availableTypes)) {
1815
+ if (!Mage::helper('mundipagg')->validateCcNum($ccNumber) && $info->getCcType() != 'HI') {
1816
+ $errorMsg[] = Mage::helper('payment')->__('Invalid Credit Card Number');
1817
+ }
1818
+ } else {
1819
+ $errorMsg[] = Mage::helper('payment')->__('Credit card type is not allowed for this payment method.');
1820
+ }
1821
+
1822
+ if (!$info->getCcType()) {
1823
+ $errorMsg[] = Mage::helper('payment')->__('Please select your credit card type.');
1824
+ }
1825
+
1826
+ if (!$info->getCcOwner()) {
1827
+ $errorMsg[] = Mage::helper('payment')->__('Please enter your credit card holder name.');
1828
+ }
1829
+
1830
+ if ($info->getCcType() && $info->getCcType() != 'SS' && !Mage::helper('mundipagg')->validateExpDate('20' . $info->getCcExpYear(), $info->getCcExpMonth())) {
1831
+ $errorMsg[] = Mage::helper('payment')->__('Incorrect credit card expiration date.');
1832
+ }
1833
+ }
1834
+
1835
+ if ($errorMsg) {
1836
+ $json = json_encode($errorMsg);
1837
+ Mage::throwException($json);
1838
+ }
1839
+
1840
+ return $this;
1841
+ }
1842
+
1843
+ /**
1844
+ * Redirect Url
1845
+ *
1846
+ * @return void
1847
+ */
1848
+ public function getOrderPlaceRedirectUrl() {
1849
+ $statusWithError = Uecommerce_Mundipagg_Model_Enum_CreditCardTransactionStatusEnum::WITH_ERROR;
1850
+
1851
+ switch (Mage::getSingleton('checkout/session')->getApprovalRequestSuccess()) {
1852
+ case 'debit':
1853
+ $redirectUrl = Mage::getSingleton('checkout/session')->getBankRedirectUrl();
1854
+ break;
1855
+
1856
+ case 'success':
1857
+ $redirectUrl = Mage::getUrl('mundipagg/standard/success', array('_secure' => true));
1858
+ break;
1859
+
1860
+ case $statusWithError:
1861
+ $redirectUrl = Mage::getUrl('mundipagg/standard/success', array('_secure' => true));
1862
+ break;
1863
+
1864
+ case 'partial':
1865
+ $redirectUrl = Mage::getUrl('mundipagg/standard/partial', array('_secure' => true));
1866
+ break;
1867
+
1868
+ case 'cancel':
1869
+ $redirectUrl = Mage::getUrl('mundipagg/standard/cancel', array('_secure' => true));
1870
+ break;
1871
+
1872
+ default:
1873
+ $redirectUrl = Mage::getUrl('mundipagg/standard/cancel', array('_secure' => true));
1874
+ break;
1875
+ }
1876
+
1877
+ return $redirectUrl;
1878
+ }
1879
+
1880
+ public function prepare() {
1881
+
1882
+ }
1883
+
1884
+ /**
1885
+ * Get payment methods
1886
+ */
1887
+ public function getPaymentMethods() {
1888
+ $payment_methods = $this->getConfigData('payment_methods');
1889
+
1890
+ if ($payment_methods != '') {
1891
+ $payment_methods = explode(",", $payment_methods);
1892
+ } else {
1893
+ $payment_methods = array();
1894
+ }
1895
+
1896
+ return $payment_methods;
1897
+ }
1898
+
1899
+ /**
1900
+ * CCards
1901
+ */
1902
+ public function getCcTypes() {
1903
+ $ccTypes = Mage::getStoreConfig('payment/mundipagg_standard/cc_types');
1904
+
1905
+ if ($ccTypes != '') {
1906
+ $ccTypes = explode(",", $ccTypes);
1907
+ } else {
1908
+ $ccTypes = array();
1909
+ }
1910
+
1911
+ return $ccTypes;
1912
+ }
1913
+
1914
+ /**
1915
+ * Reset interest
1916
+ */
1917
+ public function resetInterest($info) {
1918
+ if ($info->getQuote()->getMundipaggInterest() > 0 || $info->getQuote()->getMundipaggBaseInterest() > 0) {
1919
+ $info->getQuote()->setMundipaggInterest(0.0);
1920
+ $info->getQuote()->setMundipaggBaseInterest(0.0);
1921
+ $info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
1922
+ $info->getQuote()->save();
1923
+ }
1924
+
1925
+ return $info;
1926
+ }
1927
+
1928
+ /**
1929
+ * Apply interest
1930
+ */
1931
+ public function applyInterest($info, $interest) {
1932
+ $info->getQuote()->setMundipaggInterest($info->getQuote()->getStore()->convertPrice($interest, false));
1933
+ $info->getQuote()->setMundipaggBaseInterest($interest);
1934
+ $info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
1935
+ $info->getQuote()->save();
1936
+ }
1937
+
1938
+ /**
1939
+ * Remove interest to order when the total is not allowed.
1940
+ *
1941
+ * @param Mage_Sales_Model_Order $order
1942
+ * @param float $interest
1943
+ */
1944
+ protected function removeInterestToOrder(Mage_Sales_Model_Order $order, $interest) {
1945
+ $mundipaggInterest = $order->getMundipaggInterest();
1946
+ $setInterest = (float) ($mundipaggInterest - $interest);
1947
+ $order->setMundipaggInterest(($setInterest) ? $setInterest : 0);
1948
+ $order->setMundipaggBaseInterest(($setInterest) ? $setInterest : 0);
1949
+ $order->setGrandTotal(($order->getGrandTotal() - $interest));
1950
+ $order->setBaseGrandTotal(($order->getBaseGrandTotal() - $interest));
1951
+ $order->save();
1952
+ $info = $this->getInfoInstance();
1953
+ $info->setPaymentInterest(($info->getPaymentInterest() - $setInterest));
1954
+ $info->save();
1955
+ }
1956
+
1957
+ /**
1958
+ * Add interest to order
1959
+ */
1960
+ protected function addInterestToOrder(Mage_Sales_Model_Order $order, $interest) {
1961
+ $mundipaggInterest = $order->getMundipaggInterest();
1962
+ $setInterest = (float) ($mundipaggInterest + $interest);
1963
+ $order->setMundipaggInterest(($setInterest) ? $setInterest : 0);
1964
+ $order->setMundipaggBaseInterest(($setInterest) ? $setInterest : 0);
1965
+ $order->setGrandTotal(($order->getGrandTotal() + $interest));
1966
+ $order->setBaseGrandTotal(($order->getBaseGrandTotal() + $interest));
1967
+ $order->save();
1968
+ }
1969
+
1970
+ /**
1971
+ * Add payment transaction
1972
+ *
1973
+ * @param Mage_Sales_Model_Order_Payment $payment
1974
+ * @param string $transactionId
1975
+ * @param string $transactionType
1976
+ * @param array $transactionAdditionalInfo
1977
+ * @return null|Mage_Sales_Model_Order_Payment_Transaction
1978
+ */
1979
+ public function _addTransaction(Mage_Sales_Model_Order_Payment $payment, $transactionId, $transactionType, $transactionAdditionalInfo, $num = 0) {
1980
+ // Num
1981
+ $num = $num + 1;
1982
+
1983
+ // Transaction
1984
+ $transaction = Mage::getModel('sales/order_payment_transaction');
1985
+ $transaction->setOrderPaymentObject($payment);
1986
+
1987
+ $transaction = $transaction->loadByTxnId($transactionId . '-' . $transactionType);
1988
+
1989
+ $transaction->setTxnType($transactionType);
1990
+ $transaction->setTxnId($transactionId . '-' . $transactionType);
1991
+
1992
+ if ($transactionType == 'authorization') {
1993
+ $ccTransactionStatus = $transactionAdditionalInfo['CreditCardTransactionStatus'];
1994
+ $transactionOpenStatuses = array(
1995
+ 'AuthorizedPendingCapture',
1996
+ 'Captured',
1997
+ 'PartialCapture',
1998
+ 'WithError',
1999
+ 'PendingAuthorize'
2000
+ );
2001
+
2002
+ $order = $payment->getOrder();
2003
+ $orderIncrementId = $order->getIncrementId();
2004
+
2005
+ $api = new Uecommerce_Mundipagg_Model_Api();
2006
+ $orderInOfflineRetry = $api->orderIsInOfflineRetry($orderIncrementId);
2007
+
2008
+ if (in_array($ccTransactionStatus, $transactionOpenStatuses)) {
2009
+ $transaction->setIsClosed(0);
2010
+ } else {
2011
+ $transaction->setIsClosed(1);
2012
+ }
2013
+ }
2014
+
2015
+ foreach ($transactionAdditionalInfo as $transKey => $value) {
2016
+ if (!is_array($value)) {
2017
+ $transaction->setAdditionalInformation($transKey, htmlspecialchars_decode($value));
2018
+ $payment->setAdditionalInformation($num . '_' . $transKey, htmlspecialchars_decode($value));
2019
+ } else {
2020
+
2021
+ if (empty($value)) {
2022
+ $transaction->setAdditionalInformation($transKey, '');
2023
+ $payment->setAdditionalInformation($num . '_' . $transKey, '');
2024
+ } else {
2025
+ foreach ($value as $key2 => $value2) {
2026
+ $transaction->setAdditionalInformation($key2, htmlspecialchars_decode($value2));
2027
+ $payment->setAdditionalInformation($num . '_' . $key2, htmlspecialchars_decode($value2));
2028
+ }
2029
+ }
2030
+ }
2031
+ }
2032
+
2033
+ return $transaction->save();
2034
+ }
2035
+
2036
+ /**
2037
+ * Cancel order or not if is in offline retry time
2038
+ *
2039
+ * @author Ruan Azevedo <razevedo@mundipagg.com>
2040
+ * @since 2016-06-21
2041
+ * @param string $orderIncrementId
2042
+ */
2043
+ private function offlineRetryCancelOrSuccessOrder($orderIncrementId) {
2044
+ $offlineRetryIsEnabled = Uecommerce_Mundipagg_Model_Offlineretry::offlineRetryIsEnabled();
2045
+ $helperLog = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
2046
+ $logLabel = "Order #{$orderIncrementId}";
2047
+
2048
+ if ($offlineRetryIsEnabled) {
2049
+ $api = new Uecommerce_Mundipagg_Model_Api();
2050
+ $message = "{$logLabel} | payment not authorized but order is in offline retry yet, not cancel.";
2051
+ $helperLog->info($message);
2052
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('success');
2053
+ } else {
2054
+ $helperLog->info("{$logLabel} | Payment not authorized and store don't have offline retry, order will be canceled.");
2055
+ Mage::getSingleton('checkout/session')->setApprovalRequestSuccess('cancel');
2056
+ return;
2057
+ }
2058
+ }
2059
+
2060
+ /**
2061
+ * @param Mage_Sales_Model_Order $order
2062
+ * @throws Exception
2063
+ */
2064
+ public static function transactionWithError(Mage_Sales_Model_Order $order, $comment = true) {
2065
+ try {
2066
+ if ($comment) {
2067
+ $order->setState(
2068
+ 'pending', 'mundipagg_with_error', 'With Error', false
2069
+ );
2070
+ } else {
2071
+ $order->setStatus('mundipagg_with_error');
2072
+ }
2073
+
2074
+ $order->save();
2075
+ } catch (Exception $e) {
2076
+ $errMsg = "Unable to modify order status to 'mundipagg_with_error: {$e->getMessage()}";
2077
+
2078
+ throw new Exception($errMsg);
2079
+ }
2080
+ }
2081
+
2082
+ /**
2083
+ * @param Mage_Sales_Model_Order_Payment $payment
2084
+ * @param $resultPayment
2085
+ * @return $this
2086
+ */
2087
+ private function paymentError(Mage_Sales_Model_Order_Payment $payment, $resultPayment) {
2088
+ try {
2089
+ $transactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER;
2090
+ $helper = Mage::helper('mundipagg');
2091
+ $result = $helper->issetOr($resultPayment['result']);
2092
+ $ccTxnCollection = $helper->issetOr($result['CreditCardTransactionResultCollection']);
2093
+
2094
+ // We record transaction(s)
2095
+ if (is_null($ccTxnCollection) === false) {
2096
+ if (count($ccTxnCollection) == 1) {
2097
+ $trans = $ccTxnCollection[0];
2098
+
2099
+ $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans);
2100
+ } else {
2101
+ foreach ($ccTxnCollection as $key => $trans) {
2102
+ $this->_addTransaction($payment, $trans['TransactionKey'], $transactionType, $trans, $key);
2103
+ }
2104
+ }
2105
+ }
2106
+
2107
+ if (isset($resultPayment['ErrorItemCollection'])) {
2108
+ if (count($resultPayment['ErrorItemCollection']) == 1) {
2109
+ foreach ($resultPayment['ErrorItemCollection']['ErrorItem'] as $key => $value) {
2110
+ $payment->setAdditionalInformation($key, $value)->save();
2111
+ }
2112
+ } else {
2113
+ foreach ($resultPayment['ErrorItemCollection'] as $key1 => $error) {
2114
+ foreach ($error as $key2 => $value) {
2115
+ $payment->setAdditionalInformation($key1 . '_' . $key2, $value)->save();
2116
+ }
2117
+ }
2118
+ }
2119
+ }
2120
+
2121
+ $payment->setSkipOrderProcessing(true)->save();
2122
+
2123
+ if (isset($resultPayment['ErrorDescription'])) {
2124
+ Mage::throwException(Mage::helper('mundipagg')->__($resultPayment['ErrorDescription']));
2125
+ } else {
2126
+ Mage::throwException(Mage::helper('mundipagg')->__('Error'));
2127
+ }
2128
+ } catch (Exception $e) {
2129
+ return $this;
2130
+ }
2131
+ }
2132
+
2133
+ private function integrationTimeOut(Mage_Sales_Model_Order $order, Mage_Sales_Model_Order_Payment &$payment) {
2134
+ $payment->setSkipOrderProcessing(true);
2135
+ $payment->setAdditionalInformation('IntegrationError', Uecommerce_Mundipagg_Model_Api::INTEGRATION_TIMEOUT);
2136
+
2137
+ $comment = Uecommerce_Mundipagg_Model_Api::INTEGRATION_TIMEOUT;
2138
+ $order->addStatusHistoryComment($comment);
2139
+ $order->save();
2140
+
2141
+ $session = Mage::getSingleton('checkout/session');
2142
+ $session->setApprovalRequestSuccess('success');
2143
+
2144
+ return $this;
2145
+ }
2146
+
2147
+ /**
2148
+ * @param array $mundiQueryResult
2149
+ * @param Mage_Sales_Model_Order_Payment $payment
2150
+ * @return bool|null
2151
+ */
2152
+ public function processQueryResults($mundiQueryResult, Mage_Sales_Model_Order_Payment $payment) {
2153
+ $helper = Mage::helper('mundipagg');
2154
+ $log = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
2155
+
2156
+ $order = $payment->getOrder();
2157
+ $log->setLogLabel("#{$order->getIncrementId()}");
2158
+
2159
+ $saleDataCollection = $helper->issetOr($mundiQueryResult['SaleDataCollection']);
2160
+
2161
+ if (is_null($saleDataCollection)) {
2162
+ $log->info("SaleDataCollection is null. Method execution is over");
2163
+
2164
+ return false;
2165
+ }
2166
+
2167
+ $saleData = null;
2168
+ $dateFormat = 'Y-m-d';
2169
+
2170
+ foreach ($saleDataCollection as $i) {
2171
+ $createDate = $i['OrderData']['CreateDate'];
2172
+ $transactionCreateDate = new DateTime($createDate);
2173
+ $orderCreateDate = new DateTime($order->getCreatedAt());
2174
+
2175
+ $formatTransDate = $transactionCreateDate->format($dateFormat);
2176
+ $formatOrderDate = $orderCreateDate->format($dateFormat);
2177
+
2178
+ if ($formatTransDate == $formatOrderDate) {
2179
+ $saleData = $i;
2180
+ continue;
2181
+ }
2182
+ }
2183
+
2184
+ $creditCardTransactionDataCollection = $helper->issetOr(
2185
+ $saleData['CreditCardTransactionDataCollection']
2186
+ );
2187
+
2188
+ if (is_null($creditCardTransactionDataCollection)) {
2189
+ $log->info("CreditCardTransactionDataCollection is null. Method execution is over");
2190
+
2191
+ return false;
2192
+ }
2193
+
2194
+ $transactionType = Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH;
2195
+
2196
+ foreach ($creditCardTransactionDataCollection as $i) {
2197
+ $transactionId = $i['TransactionKey'];
2198
+ $this->_addTransaction($payment, $transactionId, $transactionType, $i);
2199
+ }
2200
+
2201
+ return true;
2202
+ }
2203
+
2204
+ public function removeIntegrationErrorInfo(Mage_Sales_Model_Order $order) {
2205
+ $errMsg = null;
2206
+ $log = new Uecommerce_Mundipagg_Helper_Log(__METHOD__);
2207
+ $log->setLogLabel("#{$order->getIncrementId()}");
2208
+
2209
+ $info = $order->getPayment()->getAdditionalInformation();
2210
+
2211
+ if (!isset($info['IntegrationError'])) {
2212
+ return;
2213
+ }
2214
+
2215
+ try {
2216
+ $info = $order->getPayment()->getAdditionalInformation();
2217
+
2218
+ unset($info['IntegrationError']);
2219
+
2220
+ $order->getPayment()
2221
+ ->setAdditionalInformation($info)
2222
+ ->save();
2223
+
2224
+ $log->info("IntegrationError message removed");
2225
+ } catch (Exception $e) {
2226
+ $log->error($e, true);
2227
+ }
2228
+ }
2229
+
2230
+ /**
2231
+ * @param Mage_Sales_Model_Order $order
2232
+ * @param boolean $option
2233
+ */
2234
+ public function setCanceledByNotificationFlag(&$order, $option) {
2235
+ $order->getPayment()->setAdditionalInformation('voided_by_mundi_notification', $option);
2236
+ }
2237
+
2238
+ /**
2239
+ * @param Mage_Sales_Model_Order $order
2240
+ */
2241
+ public function getCanceledByNotificationFlag($order) {
2242
+ return $order->getPayment()->getAdditionalInformation('voided_by_mundi_notification');
2243
+ }
2244
+
2245
+ /**
2246
+ * Equalize invoice base_grand_total and base_total with order totals
2247
+ * Needed when order has 1 invoice and has credit card interests
2248
+ *
2249
+ * @param Mage_Sales_Model_Order_Invoice $invoice
2250
+ */
2251
+ public function equalizeInvoiceTotals(Mage_Sales_Model_Order_Invoice &$invoice) {
2252
+ $invoice->setBaseGrandTotal($invoice->getOrder()->getBaseGrandTotal())
2253
+ ->setGrandTotal($invoice->getOrder()->getGrandTotal())
2254
+ ->save();
2255
+ }
2256
+
2257
+ /**
2258
+ * @param Mage_Checkout_Model_Type_Onepage $onepage
2259
+ * @param array $postData
2260
+ * @return null|string $redirectRoute
2261
+ * @throws Exception
2262
+ */
2263
+ public function retryAuthorization(Mage_Checkout_Model_Type_Onepage &$onepage, $postData) {
2264
+ $redirectRoute = null;
2265
+
2266
+ /* @var Uecommerce_Mundipagg_Helper_CheckoutSession $session */
2267
+ $session = Mage::helper('mundipagg/checkoutSession');
2268
+ $lastQuoteId = $session->getInstance()->getLastSuccessQuoteId();
2269
+ $session->getInstance()->setQuoteId($lastQuoteId);
2270
+
2271
+ /* @var Mage_Sales_Model_Quote $quote */
2272
+ $quote = Mage::getModel('sales/quote')->load($lastQuoteId);
2273
+ $quote->setIsActive(true);
2274
+
2275
+ $onepage->setQuote($quote);
2276
+
2277
+ // Get Reserved Order Id
2278
+ $reservedOrderId = $quote->getReservedOrderId();
2279
+
2280
+ if ($reservedOrderId == false) {
2281
+ return $redirectRoute;
2282
+ }
2283
+
2284
+ $session->setApprovalRequest('partial');
2285
+
2286
+ $order = Mage::getModel('sales/order')->loadByIncrementId($reservedOrderId);
2287
+
2288
+ //
2289
+ $additionalInfo = $order->getPayment()->getAdditionalInformation();
2290
+ $num = 1;
2291
+
2292
+ if ($additionalInfo['2_Success']) {
2293
+ $num++;
2294
+ }
2295
+
2296
+ $idxToken = "mundipagg_twocreditcards_token_2_{$num}";
2297
+
2298
+ switch (true) {
2299
+ case isset($additionalInfo[$idxToken]) :
2300
+ $order->getPayment()->setAdditionalInformation();
2301
+ break;
2302
+ }
2303
+
2304
+ /* @var Uecommerce_Mundipagg_Helper_Data $helper */
2305
+ $helper = Mage::helper('mundipagg');
2306
+
2307
+ if ($order->getStatus() === 'pending' || $order->getStatus() === 'payment_review') {
2308
+ if (empty($postData)) {
2309
+ throw new Exception($helper->__('Invalid data'));
2310
  // Mage::throwException($helper->__('Invalid data'));
2311
  // return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid data'));
2312
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2313
 
2314
+ $paymentMethod = $helper->issetOr($postData['method']);
2315
 
2316
+ if ($quote->isVirtual()) {
2317
+ $quote->getBillingAddress()->setPaymentMethod($paymentMethod);
2318
+ } else {
2319
+ $quote->getShippingAddress()->setPaymentMethod($paymentMethod);
2320
+ }
2321
+
2322
+ $payment = $quote->getPayment();
2323
+ $payment->importData($postData);
2324
+
2325
+ $quote->save();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2326
 
2327
+ switch ($paymentMethod) {
2328
+ case 'mundipagg_creditcardoneinstallment':
2329
+ $standard = Mage::getModel('mundipagg/creditcardoneinstallment');
2330
+ break;
2331
+ case 'mundipagg_creditcard':
2332
+ $standard = Mage::getModel('mundipagg/creditcard');
2333
+ break;
2334
 
2335
+ case 'mundipagg_twocreditcards':
2336
+ $standard = Mage::getModel('mundipagg/twocreditcards');
2337
+ break;
 
2338
 
2339
+ case 'mundipagg_threecreditcards':
2340
+ $standard = Mage::getModel('mundipagg/threecreditcards');
2341
+ break;
2342
 
2343
+ case 'mundipagg_fourcreditcards':
2344
+ $standard = Mage::getModel('mundipagg/fourcreditcards');
2345
+ break;
2346
 
2347
+ case 'mundipagg_fivecreditcards':
2348
+ $standard = Mage::getModel('mundipagg/fivecreditcards');
2349
+ break;
2350
 
2351
+ case 'mundipagg_recurrencepayment':
2352
+ $standard = Mage::getModel('mundipagg/recurrencepayment');
2353
+ break;
2354
 
2355
+ default:
2356
+ return 'mundipagg/standard/partial';
2357
+ break;
2358
+ }
2359
 
2360
+ /* @var Uecommerce_Mundipagg_Model_Standard $standard */
2361
+ $resultPayment = $standard->doPayment($payment, $order);
2362
+ $txns = $helper->issetOr($resultPayment['result']['CreditCardTransactionResultCollection']);
 
2363
 
2364
+ foreach ($txns as $txn) {
2365
+ $standard->_addTransaction(
2366
+ $order->getPayment(), $helper->issetOr($txn['TransactionKey']), Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, $txn, $num - 1
2367
+ );
2368
+ }
2369
+
2370
+ $order->getPayment()->save();
2371
+
2372
+ // $this->replaceNotAuthorizedCcInfo($txns[0], $order->getPayment());
2373
+
2374
+ $accAuthorizedAmount = sprintf($order->getData('payment_authorization_amount'));
2375
+ $accGrandTotal = sprintf($order->getData('grand_total'));
2376
+
2377
+ if ($standard->getAntiFraud() == 0 &&
2378
+ $standard->getPaymentAction() === 'order' &&
2379
+ $accAuthorizedAmount == $accGrandTotal
2380
+ ) {
2381
+ $standard->captureAndcreateInvoice($order->getPayment());
2382
+ }
2383
+
2384
+ switch ($session->getApprovalRequest()) {
2385
+ case 'success':
2386
+ // Send new order email when not in admin and payment is success
2387
+ if (Mage::app()->getStore()->getCode() !== 'admin') {
2388
+ $order->sendNewOrderEmail();
2389
+ }
2390
+ $redirectRoute = 'mundipagg/standard/success';
2391
+ break;
2392
+
2393
+ case 'partial':
2394
+ $redirectRoute = 'mundipagg/standard/partial';
2395
+ break;
2396
+
2397
+ case 'cancel':
2398
+ $redirectRoute = 'mundipagg/standard/cancel';
2399
+ break;
2400
+
2401
+ default:
2402
+ throw new Exception("Unexpected approvalRequestSuccess: {$session->getApprovalRequest()}");
2403
+ }
2404
+ }
2405
+
2406
+ return $redirectRoute;
2407
+ }
2408
+
2409
+ /**
2410
+ * Replace the not authorized payment additional information
2411
+ */
2412
+ public function replaceNotAuthorizedCcInfo($mundiResponse, Mage_Sales_Model_Order_Payment &$payment) {
2413
+ $info = $payment->getAdditionalInformation();
2414
+ $ccQty = $info['mundipagg_type'][0];
2415
+ $keys = array_keys($info);
2416
+ $ccsData = [];
2417
+ $otherData = [];
2418
+
2419
+ // separate credit cards payment additional information
2420
+ foreach ($keys as $key) {
2421
+ $idxTwoInitialLetters = $key[0] . $key[1];
2422
+ $value = $info[$key];
2423
+
2424
+ if ($idxTwoInitialLetters === '1_') {
2425
+ $ccsData[1][$key] = $value;
2426
+ } elseif ($idxTwoInitialLetters === '2_') {
2427
+ $ccsData[2][$key] = $value;
2428
+ } else {
2429
+ $otherData[$key] = $value;
2430
+ }
2431
+ }
2432
+
2433
+ $notAuthorizedCc = null;
2434
+
2435
+ // get just the not authorized credit card data
2436
+ for ($i = 1; $i <= $ccQty; $i++) {
2437
+ $idx = "{$i}_Success";
2438
+ $success = $ccsData[$i][$idx];
2439
+
2440
+ if ($success) {
2441
+ // $notAuthorizedCc = $i === 1 ? 1 : 2;
2442
+ if ($i === 1) {
2443
+ $notAuthorizedCc = 1;
2444
+ } else {
2445
+ $notAuthorizedCc = 2;
2446
+ }
2447
+ break;
2448
+ }
2449
+ }
2450
+
2451
+ $responseKeys = $this->extractTxnKeys($mundiResponse);
2452
+ $key = null;
2453
+
2454
+ foreach ($responseKeys as $key => $val) {
2455
+ $idx = "{$notAuthorizedCc}_{$val}";
2456
+ $ccsData[$idx] = isset($ccsData[$idx]) ? $ccsData[$idx] : null;
2457
+ }
2458
+
2459
+ $data = $otherData + $ccsData[1] + $ccsData[2];
2460
+
2461
+ $payment->setAdditionalInformation($data)->save();
2462
+ }
2463
+
2464
+ public function extractTxnKeys($txn) {
2465
+ $keys = [];
2466
+
2467
+ foreach ($txn as $key => $val) {
2468
+ if (is_array($txn[$key]) && !empty($txn[$key])) {
2469
+
2470
+ foreach ($txn[$key] as $subKey => $subVal) {
2471
+ $keys[] = $subKey;
2472
+ }
2473
+ } else {
2474
+ $keys[] = $key;
2475
+ }
2476
+ }
2477
+
2478
+ return $keys;
2479
+ }
2480
 
2481
  }
app/code/community/Uecommerce/Mundipagg/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <Uecommerce_Mundipagg>
5
- <version>2.11.02</version>
6
  </Uecommerce_Mundipagg>
7
  </modules>
8
 
@@ -42,6 +42,16 @@
42
  </checkRecurrencyFrequency>
43
  </observers>
44
  </catalog_product_save_before>
 
 
 
 
 
 
 
 
 
 
45
  <controller_action_predispatch>
46
  <observers>
47
  <sessionUpdate>
@@ -82,6 +92,22 @@
82
  </checkForRecurrency>
83
  </observers>
84
  </payment_method_is_active>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  <sales_quote_collect_totals_after>
86
  <observers>
87
  <mundipagg_discount_partial>
@@ -109,7 +135,24 @@
109
  </mundipagg_cart_check_recurrency>
110
  </observers>
111
  </checkout_cart_save_after>
112
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  </events>
114
 
115
 
@@ -309,13 +352,6 @@
309
  <integration_timeout_limit>30</integration_timeout_limit>
310
  <overwrite_magento_flags>1</overwrite_magento_flags>
311
  </mundipagg_standard>
312
- <mundipagg_creditcardoneinstallment>
313
- <model>mundipagg/creditcardoneinstallment</model>
314
- <active>0</active>
315
- <title><![CDATA[Cartão de Crédito à vista]]></title>
316
- <allowspecific>0</allowspecific>
317
- <payment_action>authorize</payment_action>
318
- </mundipagg_creditcardoneinstallment>
319
  <mundipagg_creditcard>
320
  <model>mundipagg/creditcard</model>
321
  <active>0</active>
@@ -368,6 +404,13 @@
368
  <allowspecific>0</allowspecific>
369
  <payment_action>authorize</payment_action>
370
  </mundipagg_debit>
 
 
 
 
 
 
 
371
  </payment>
372
  </default>
373
  </config>
2
  <config>
3
  <modules>
4
  <Uecommerce_Mundipagg>
5
+ <version>2.12.04</version>
6
  </Uecommerce_Mundipagg>
7
  </modules>
8
 
42
  </checkRecurrencyFrequency>
43
  </observers>
44
  </catalog_product_save_before>
45
+
46
+ <payment_method_is_active>
47
+ <observers>
48
+ <checkRecurrencyFrequency>
49
+ <class>Uecommerce_Mundipagg_Model_Observer</class>
50
+ <method>changeRecurrenceValues</method>
51
+ </checkRecurrencyFrequency>
52
+ </observers>
53
+ </payment_method_is_active>
54
+
55
  <controller_action_predispatch>
56
  <observers>
57
  <sessionUpdate>
92
  </checkForRecurrency>
93
  </observers>
94
  </payment_method_is_active>
95
+ <controller_action_predispatch_checkout>
96
+ <observers>
97
+ <recurrenceMixConflict>
98
+ <class>Uecommerce_Mundipagg_Model_Observer</class>
99
+ <method>recurrenceMixConflict</method>
100
+ </recurrenceMixConflict>
101
+ </observers>
102
+ </controller_action_predispatch_checkout>
103
+ <checkout_cart_update_items_after>
104
+ <observers>
105
+ <recurrenceMixConflict>
106
+ <class>Uecommerce_Mundipagg_Model_Observer</class>
107
+ <method>recurrenceMixConflict</method>
108
+ </recurrenceMixConflict>
109
+ </observers>
110
+ </checkout_cart_update_items_after>
111
  <sales_quote_collect_totals_after>
112
  <observers>
113
  <mundipagg_discount_partial>
135
  </mundipagg_cart_check_recurrency>
136
  </observers>
137
  </checkout_cart_save_after>
138
+ <checkout_cart_product_add_after>
139
+ <observers>
140
+ <mundipagg_cart_check_recurrency>
141
+ <type>singleton</type>
142
+ <class>Uecommerce_Mundipagg_Model_Observer</class>
143
+ <method>cartCheckRecurrencyConflicts</method>
144
+ </mundipagg_cart_check_recurrency>
145
+ </observers>
146
+ </checkout_cart_product_add_after>
147
+ <checkout_cart_update_items_after>
148
+ <observers>
149
+ <mundipagg_cart_check_recurrency>
150
+ <type>singleton</type>
151
+ <class>Uecommerce_Mundipagg_Model_Observer</class>
152
+ <method>cartCheckRecurrencyConflicts</method>
153
+ </mundipagg_cart_check_recurrency>
154
+ </observers>
155
+ </checkout_cart_update_items_after>
156
  </events>
157
 
158
 
352
  <integration_timeout_limit>30</integration_timeout_limit>
353
  <overwrite_magento_flags>1</overwrite_magento_flags>
354
  </mundipagg_standard>
 
 
 
 
 
 
 
355
  <mundipagg_creditcard>
356
  <model>mundipagg/creditcard</model>
357
  <active>0</active>
404
  <allowspecific>0</allowspecific>
405
  <payment_action>authorize</payment_action>
406
  </mundipagg_debit>
407
+ <mundipagg_recurrencepayment>
408
+ <model>mundipagg/recurrencepayment</model>
409
+ <active>0</active>
410
+ <title><![CDATA[Recorrência no checkout]]></title>
411
+ <allowspecific>0</allowspecific>
412
+ <payment_action>authorize</payment_action>
413
+ </mundipagg_recurrencepayment>
414
  </payment>
415
  </default>
416
  </config>
app/code/community/Uecommerce/Mundipagg/etc/system.xml CHANGED
@@ -897,6 +897,103 @@
897
  </sort_order>
898
  </fields>
899
  </mundipagg_debit>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
900
  </groups>
901
  </payment>
902
  </sections>
897
  </sort_order>
898
  </fields>
899
  </mundipagg_debit>
900
+ <mundipagg_recurrencepayment type="group" translate="label">
901
+ <label><![CDATA[MundiPagg - Recorrência no checkout]]></label>
902
+ <sort_order>430</sort_order>
903
+ <show_in_default>1</show_in_default>
904
+ <show_in_website>1</show_in_website>
905
+ <show_in_store>1</show_in_store>
906
+ <comment>
907
+ <![CDATA[<br><a href="http://www.mundipagg.com.br" target="_blank"><img title="MundiPagg" alt="MundiPagg" src="/skin/adminhtml/default/default/images/mundipagg/mundi-magento-admin-banner.png"/></a><br><br><br>]]></comment>
908
+ <fields>
909
+ <active translate="label">
910
+ <label>Enabled</label>
911
+ <frontend_type>select</frontend_type>
912
+ <source_model>adminhtml/system_config_source_yesno</source_model>
913
+ <sort_order>1</sort_order>
914
+ <show_in_default>1</show_in_default>
915
+ <show_in_website>1</show_in_website>
916
+ <show_in_store>1</show_in_store>
917
+ </active>
918
+
919
+ <title translate="label">
920
+ <label>Title</label>
921
+ <frontend_type>text</frontend_type>
922
+ <sort_order>2</sort_order>
923
+ <show_in_default>1</show_in_default>
924
+ <show_in_website>1</show_in_website>
925
+ <show_in_store>1</show_in_store>
926
+ <comment>
927
+ <![CDATA[Frase que irá aparecer no seu checkout para descrever a forma de pagamento.]]></comment>
928
+ </title>
929
+
930
+ <allowspecific translate="label">
931
+ <label>Payment from Applicable Countries</label>
932
+ <frontend_type>allowspecific</frontend_type>
933
+ <sort_order>60</sort_order>
934
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
935
+ <show_in_default>1</show_in_default>
936
+ <show_in_website>1</show_in_website>
937
+ <show_in_store>1</show_in_store>
938
+ </allowspecific>
939
+
940
+ <specificcountry translate="label">
941
+ <label>Payment from Specific Countries</label>
942
+ <frontend_type>multiselect</frontend_type>
943
+ <sort_order>61</sort_order>
944
+ <source_model>adminhtml/system_config_source_country</source_model>
945
+ <show_in_default>1</show_in_default>
946
+ <show_in_website>1</show_in_website>
947
+ <show_in_store>1</show_in_store>
948
+ </specificcountry>
949
+
950
+ <sort_order translate="label">
951
+ <label>Sort Order</label>
952
+ <frontend_type>text</frontend_type>
953
+ <sort_order>100</sort_order>
954
+ <show_in_default>1</show_in_default>
955
+ <show_in_website>1</show_in_website>
956
+ <show_in_store>1</show_in_store>
957
+ <frontend_class>validate-number</frontend_class>
958
+ </sort_order>
959
+ <conflict_message_recurrent_others translate="label">
960
+ <label>Mensagem de conflito Recorrente + Qualquer tipo</label>
961
+ <frontend_type>text</frontend_type>
962
+ <sort_order>100</sort_order>
963
+ <show_in_default>1</show_in_default>
964
+ <show_in_website>1</show_in_website>
965
+ <show_in_store>1</show_in_store>
966
+ <comment>Defina uma mensagem para esse conflito.</comment>
967
+ </conflict_message_recurrent_others>
968
+ <conflict_message_recurrent_mix_mix translate="label">
969
+ <label>Mensagem de conflito Misto + Misto/Avulso</label>
970
+ <frontend_type>text</frontend_type>
971
+ <sort_order>100</sort_order>
972
+ <show_in_default>1</show_in_default>
973
+ <show_in_website>1</show_in_website>
974
+ <show_in_store>1</show_in_store>
975
+ <comment>Defina uma mensagem para esse conflito.</comment>
976
+ </conflict_message_recurrent_mix_mix>
977
+ <conflict_message_recurrent_mix_recurrent translate="label">
978
+ <label>Mensagem de conflito Misto/Avulso + Recorrente</label>
979
+ <frontend_type>text</frontend_type>
980
+ <sort_order>100</sort_order>
981
+ <show_in_default>1</show_in_default>
982
+ <show_in_website>1</show_in_website>
983
+ <show_in_store>1</show_in_store>
984
+ <comment>Defina uma mensagem para esse conflito.</comment>
985
+ </conflict_message_recurrent_mix_recurrent>
986
+ <recurrent_mix_message translate="label">
987
+ <label>Mensagem da recorrência no checkout review</label>
988
+ <frontend_type>text</frontend_type>
989
+ <sort_order>100</sort_order>
990
+ <show_in_default>1</show_in_default>
991
+ <show_in_website>1</show_in_website>
992
+ <show_in_store>1</show_in_store>
993
+ <comment>Defina uma mensagem que será exibida na finalização do pedido.</comment>
994
+ </recurrent_mix_message>
995
+ </fields>
996
+ </mundipagg_recurrencepayment>
997
  </groups>
998
  </payment>
999
  </sections>
app/code/community/Uecommerce/Mundipagg/sql/mundipagg_setup/upgrade-2.11.01-2.12.01.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
3
+
4
+ $installer->startSetup();
5
+
6
+ $reader = Mage::getSingleton('core/resource')->getConnection('core_read');
7
+
8
+ $result = $reader->query('select attribute_code from '.$prefix.'eav_attribute WHERE attribute_code = "mundipagg_recurrent"')->fetchAll();
9
+
10
+ if (empty($result)) {
11
+ $recurrent = array(
12
+ 'attribute_set' => 'Default',
13
+ 'group' => 'Recorrência',
14
+ 'label' => 'Produto de assinatura?',
15
+ 'visible' => true,
16
+ 'type' => 'int',
17
+ 'input' => 'select',
18
+ 'source' => 'eav/entity_attribute_source_boolean',
19
+ 'system' => false,
20
+ 'required' => true,
21
+ 'used_in_product_listing' => true,
22
+ 'is_visible_on_front' => true,
23
+ 'visible_on_front' => true
24
+ );
25
+
26
+ $installer->addAttribute('catalog_product', 'mundipagg_recurrent', $recurrent);
27
+ }
28
+
29
+ $result = $reader->query('select attribute_code from '.$prefix.'eav_attribute WHERE attribute_code = "mundipagg_frequency_enum"')->fetchAll();
30
+
31
+ if (empty($result)) {
32
+ $frequency_enum = array(
33
+ 'attribute_set' => 'Default',
34
+ 'group' => 'Recorrência',
35
+ 'label' => 'Frequência',
36
+ 'note' => 'O valor colocado na aba "Prices / Preços" sera o valor pago por: semana / mensal / trimestral / semestral / anual',
37
+ 'visible' => true,
38
+ 'type' => 'varchar',
39
+ 'input' => 'select',
40
+ 'system' => false,
41
+ 'required' => true,
42
+ 'used_in_product_listing' => true,
43
+ 'is_visible_on_front' => true,
44
+ 'visible_on_front' => true,
45
+ 'frontend_input' => 'select',
46
+ 'source' => 'mundipagg/source_frequency'
47
+ );
48
+
49
+ $installer->addAttribute('catalog_product', 'mundipagg_frequency_enum', $frequency_enum);
50
+ }
51
+
52
+ $result = $reader->query('select attribute_code from '.$prefix.'eav_attribute WHERE attribute_code = "mundipagg_recurrences"')->fetchAll();
53
+
54
+ if (empty($result)) {
55
+ $recurrences = array(
56
+ 'attribute_set' => 'Default',
57
+ 'group' => 'Recorrência',
58
+ 'label' => 'Número de Ciclos',
59
+ 'note' => 'Número de ciclos que serão cobrados antes de uma renovação da parte do cliente.',
60
+ 'visible' => true,
61
+ 'type' => 'int',
62
+ 'input' => 'text',
63
+ 'system' => false,
64
+ 'required' => true,
65
+ 'used_in_product_listing' => true,
66
+ 'is_visible_on_front' => true,
67
+ 'visible_on_front' => true,
68
+ 'frontend_input' => 'text',
69
+ 'default' => '1'
70
+ );
71
+
72
+ $installer->addAttribute('catalog_product', 'mundipagg_recurrences', $recurrences);
73
+ }
74
+
75
+
76
+
77
+ $result = $reader->query('select attribute_code from '.$prefix.'eav_attribute WHERE attribute_code = "mundipagg_recurrence_mix"')->fetchAll();
78
+ if (empty($result)) {
79
+ $recurrenceMix = array(
80
+ 'attribute_set' => 'Default',
81
+ 'group' => 'Recorrência',
82
+ 'label' => 'Permitir venda avulsa?',
83
+ 'note' => 'O cliente escolhe se vai comprar com recorrência ou não.',
84
+ 'visible' => true,
85
+ 'type' => 'int',
86
+ 'input' => 'select',
87
+ 'system' => false,
88
+ 'required' => true,
89
+ 'used_in_product_listing' => true,
90
+ 'is_visible_on_front' => true,
91
+ 'visible_on_front' => true,
92
+ 'frontend_input' => 'select',
93
+ 'source' => 'eav/entity_attribute_source_boolean'
94
+ );
95
+
96
+ $installer->addAttribute('catalog_product', 'mundipagg_recurrence_mix', $recurrenceMix);
97
+ }
98
+
99
+ //
100
+ $result = $reader->query('select attribute_code from '.$prefix.'eav_attribute WHERE attribute_code = "mundipagg_recurrence_discount"')->fetchAll();
101
+ if (empty($result)) {
102
+ $recurrenceDiscount = array(
103
+ 'attribute_set' => 'Default',
104
+ 'group' => 'Recorrência',
105
+ 'label' => 'Desconto no valor à vista(%)',
106
+ 'note' => 'Porcentagem de desconto para compra à vista.',
107
+ 'visible' => true,
108
+ 'type' => 'int',
109
+ 'input' => 'text',
110
+ 'system' => false,
111
+ 'required' => false,
112
+ 'used_in_product_listing' => true,
113
+ 'is_visible_on_front' => true,
114
+ 'visible_on_front' => true,
115
+ 'frontend_input' => 'text',
116
+ 'default' => ''
117
+ );
118
+
119
+ $installer->addAttribute('catalog_product', 'mundipagg_recurrence_discount', $recurrenceDiscount);
120
+ }
121
+
122
+ $installer->cleanCache();
123
+ $installer->endSetup();
app/code/community/Uecommerce/Mundipagg/sql/mundipagg_setup/upgrade-2.12.01-2.12.02.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
3
+
4
+ $installer->startSetup();
5
+
6
+ $reader = Mage::getSingleton('core/resource')->getConnection('core_read');
7
+
8
+ $result = $reader->query('select attribute_code from '.$prefix.'eav_attribute WHERE attribute_code = "mundipagg_recurrent"')->fetchAll();
9
+
10
+ if (empty($result)) {
11
+ $recurrent = array(
12
+ 'attribute_set' => 'Default',
13
+ 'group' => 'Recorrência',
14
+ 'label' => 'Produto de assinatura?',
15
+ 'visible' => true,
16
+ 'type' => 'int',
17
+ 'input' => 'select',
18
+ 'source' => 'eav/entity_attribute_source_boolean',
19
+ 'system' => false,
20
+ 'required' => true,
21
+ 'used_in_product_listing' => true,
22
+ 'is_visible_on_front' => true,
23
+ 'visible_on_front' => true
24
+ );
25
+
26
+ $installer->addAttribute('catalog_product', 'mundipagg_recurrent', $recurrent);
27
+ }
28
+
29
+ $result = $reader->query('select attribute_code from '.$prefix.'eav_attribute WHERE attribute_code = "mundipagg_frequency_enum"')->fetchAll();
30
+
31
+ if (empty($result)) {
32
+ $frequency_enum = array(
33
+ 'attribute_set' => 'Default',
34
+ 'group' => 'Recorrência',
35
+ 'label' => 'Frequência',
36
+ 'note' => 'O valor colocado na aba "Prices / Preços" sera o valor pago por: semana / mensal / trimestral / semestral / anual',
37
+ 'visible' => true,
38
+ 'type' => 'varchar',
39
+ 'input' => 'select',
40
+ 'system' => false,
41
+ 'required' => true,
42
+ 'used_in_product_listing' => true,
43
+ 'is_visible_on_front' => true,
44
+ 'visible_on_front' => true,
45
+ 'frontend_input' => 'select',
46
+ 'source' => 'mundipagg/source_frequency'
47
+ );
48
+
49
+ $installer->addAttribute('catalog_product', 'mundipagg_frequency_enum', $frequency_enum);
50
+ }
51
+
52
+ $result = $reader->query('select attribute_code from '.$prefix.'eav_attribute WHERE attribute_code = "mundipagg_recurrences"')->fetchAll();
53
+
54
+ if (empty($result)) {
55
+ $recurrences = array(
56
+ 'attribute_set' => 'Default',
57
+ 'group' => 'Recorrência',
58
+ 'label' => 'Número de Ciclos',
59
+ 'note' => 'Número de ciclos que serão cobrados antes de uma renovação da parte do cliente.',
60
+ 'visible' => true,
61
+ 'type' => 'int',
62
+ 'input' => 'text',
63
+ 'system' => false,
64
+ 'required' => true,
65
+ 'used_in_product_listing' => true,
66
+ 'is_visible_on_front' => true,
67
+ 'visible_on_front' => true,
68
+ 'frontend_input' => 'text',
69
+ 'default' => '1'
70
+ );
71
+
72
+ $installer->addAttribute('catalog_product', 'mundipagg_recurrences', $recurrences);
73
+ }
74
+
75
+
76
+
77
+ $result = $reader->query('select attribute_code from '.$prefix.'eav_attribute WHERE attribute_code = "mundipagg_recurrence_mix"')->fetchAll();
78
+ if (empty($result)) {
79
+ $recurrenceMix = array(
80
+ 'attribute_set' => 'Default',
81
+ 'group' => 'Recorrência',
82
+ 'label' => 'Permitir venda avulsa?',
83
+ 'note' => 'O cliente escolhe se vai comprar com recorrência ou não.',
84
+ 'visible' => true,
85
+ 'type' => 'int',
86
+ 'input' => 'select',
87
+ 'system' => false,
88
+ 'required' => true,
89
+ 'used_in_product_listing' => true,
90
+ 'is_visible_on_front' => true,
91
+ 'visible_on_front' => true,
92
+ 'frontend_input' => 'select',
93
+ 'source' => 'eav/entity_attribute_source_boolean'
94
+ );
95
+
96
+ $installer->addAttribute('catalog_product', 'mundipagg_recurrence_mix', $recurrenceMix);
97
+ }
98
+
99
+ //
100
+ $result = $reader->query('select attribute_code from '.$prefix.'eav_attribute WHERE attribute_code = "mundipagg_recurrence_discount"')->fetchAll();
101
+ if (empty($result)) {
102
+ $recurrenceDiscount = array(
103
+ 'attribute_set' => 'Default',
104
+ 'group' => 'Recorrência',
105
+ 'label' => 'Desconto no valor à vista(%)',
106
+ 'note' => 'Porcentagem de desconto para compra à vista.',
107
+ 'visible' => true,
108
+ 'type' => 'int',
109
+ 'input' => 'text',
110
+ 'system' => false,
111
+ 'required' => false,
112
+ 'used_in_product_listing' => true,
113
+ 'is_visible_on_front' => true,
114
+ 'visible_on_front' => true,
115
+ 'frontend_input' => 'text',
116
+ 'default' => ''
117
+ );
118
+
119
+ $installer->addAttribute('catalog_product', 'mundipagg_recurrence_discount', $recurrenceDiscount);
120
+ }
121
+
122
+ $installer->cleanCache();
123
+ $installer->endSetup();
app/design/adminhtml/default/default/template/mundipagg/form.phtml CHANGED
@@ -1,32 +1,4 @@
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
  //Return Standard model
32
  $standard = $this->getStandard();
@@ -34,10 +6,10 @@ $standard = $this->getStandard();
34
  // Get Quote
35
  $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
36
 
37
- if($quote->isVirtual()) {
38
- $data = $quote->getBillingAddress();
39
  } else {
40
- $data = $quote->getShippingAddress();
41
  }
42
 
43
  $baseGrandTotal = $quote->getBaseGrandTotal();
@@ -62,318 +34,442 @@ $countCcs = count($ccs);
62
  $_code = $this->getMethodCode();
63
  ?>
64
  <style type="text/css">
65
- .issuers{
66
- text-align: center;
67
- padding-right: 10px;
68
- }
69
  </style>
70
  <fieldset class="form-list">
71
- <ul id="payment_form_<?php echo $_code ?>" style="display:none;">
72
- <div>
73
- <input type="hidden" id="baseGrandTotal" name="baseGrandTotal" value="<?php echo number_format($baseGrandTotal, "2", ",", ""); ?>"/>
74
- </div>
75
- <?php
76
- // START CREDIT CARD PAYMENT METHOD
77
- $num = 1;
78
-
79
- switch ($_code):
80
- case 'mundipagg_creditcardoneinstallment':
81
- $num = 1;
82
- $paymentMethod = '1CreditCardsOneInstallment';
83
- $paymentMethodLabel = $this->__('Credit Card');
84
- break;
85
-
86
- case 'mundipagg_creditcard':
87
- $num = 1;
88
- $paymentMethod = '1CreditCards';
89
- $paymentMethodLabel = $this->__('Credit Card');
90
- break;
91
-
92
- case 'mundipagg_twocreditcards':
93
- $num = 2;
94
- $paymentMethod = '2CreditCards';
95
- $paymentMethodLabel = $this->__('Pay with 2 Credit Cards');
96
- break;
97
 
98
- case 'mundipagg_threecreditcards':
99
- $num = 3;
100
- $paymentMethod = '3CreditCards';
101
- $paymentMethodLabel = $this->__('Pay with 3 Credit Cards');
102
- break;
 
103
 
104
- case 'mundipagg_fourcreditcards':
105
- $num = 4;
106
- $paymentMethod = '4CreditCards';
107
- $paymentMethodLabel = $this->__('Pay with 4 Credit Cards');
108
- break;
109
 
110
- case 'mundipagg_fivecreditcards':
111
- $num = 5;
112
- $paymentMethod = '5CreditCards';
113
- $paymentMethodLabel = $this->__('Pay with 5 Credit Cards');
114
- break;
115
- endswitch;
116
- ?>
117
  <li>
118
- <div id="<?php echo $_code; ?>">
119
- <?php if ( $_code == 'mundipagg_creditcardoneinstallment' || $_code == 'mundipagg_creditcard' || $_code == 'mundipagg_twocreditcards' || $_code == 'mundipagg_threecreditcards' || $_code == 'mundipagg_fourcreditcards' || $_code == 'mundipagg_fivecreditcards'): ?>
120
- <ul>
121
- <?php for($c=1;$c<=$num;$c++): ?>
122
- <input type="hidden" id="mundipagg_type" name="payment[mundipagg_type]" value="<?php echo $paymentMethod ; ?>"/>
 
 
 
 
 
 
123
  <?php $currentSelectedToken = null; ?>
124
- <?php if( $countCcs > 0 ):?>
125
- <li class="fields" style="margin-bottom: 5px;">
126
  <div class="field">
127
  <label class="required"><?php echo $this->__('Select a Credit Card or add a new one') ?><span class="required">*</span></label>
128
  <div class="input-box">
129
 
130
- <select id="<?php echo $_code; ?>_token_<?php echo $num; ?>_<?php echo $c;?>" data="group_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_token_<?php echo $num; ?>_<?php echo $c;?>]" class="required-entry tokens group_<?php echo $num; ?>_<?php echo $c;?>" onchange="token_or_not(<?php echo $num; ?>,<?php echo $c;?>,this)">
 
 
 
 
 
 
131
  <option value="">...</option>
132
  <?php
133
- foreach($ccs as $id => $cc):
134
 
135
- if($countCcs == 1){
136
- $currentSelectedToken = Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cc->getCcType());
137
- }
138
- $dataType = $currentSelectedToken?$currentSelectedToken:Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cc->getCcType());
139
- echo '<option value="'.$cc->getId().'" data="'.$dataType.'">'.$cc->getCcType().' '.$cc->getCreditCardMask().'</option>';
140
- endforeach;
 
 
141
  ?>
142
  <option value="new"><?php echo $this->__('New Credit Card') ?></option>
143
  </select>
144
  </div>
145
  </div>
146
- </li>
147
- <?php if($num != 1): ?>
148
- <div id="value_<?php echo $num; ?>_<?php echo $c;?>">
149
- <li class="fields" style="margin-bottom: 5px;">
150
- <div class="field">
151
- <label class="required"><?php echo $this->__('Value (Ex: 100,50)') ?> <span class="required">*</span></label>
152
- <div class="input-box">
153
- <input type="text" id="<?php echo $_code; ?>_value_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_value_<?php echo $num; ?>_<?php echo $c;?>]" title="<?php echo $this->__('Value (Ex: 100,50)') ?>" class="required-entry validate-greater-than-zero check_values group_<?php echo $num; ?>_<?php echo $c;?>" onchange="calculateInstallmentValue(this, <?php echo $num;?>, <?php echo $c;?>, '<?php echo Mage::getUrl('',array('_secure'=>true)); ?>');" onkeydown="remove_special_characters(event);" value=""/>
 
 
 
 
 
 
 
 
 
 
 
154
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  </div>
156
- </li>
157
  </div>
158
- <?php endif; ?>
159
- <?php if ($installmentsHelper->isInstallmentsEnabled() && $_code != 'mundipagg_creditcardoneinstallment'): ?>
160
- <div id="parcelamento_<?php echo $num; ?>_<?php echo $c;?>" <?php if($countCcs > 1): ?>style="display:none"<?php endif?>>
161
- <li class="fields" style="margin-bottom: 5px;">
162
- <div class="field">
163
- <label class="required"><?php echo $this->__('Credit options') ?> <?php if($num == 2):?><!--<a href="javascript:void(0);" onclick="javascript:void(0);">(<?php /*echo $this->__('click to update') */?>)</a>--><?php endif ?></label>
164
- <div class="input-box">
165
- <select id="<?php echo $_code; ?>_credito_parcelamento_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_credito_parcelamento_<?php echo $num; ?>_<?php echo $c;?>]" class="required-entry installment-token group_<?php echo $num; ?>_<?php echo $c;?>">
166
- <?php foreach($this->getInstallments($currentSelectedToken) as $key => $parcel): ?>
167
- <option value="<?php echo $key ?>"><?php echo $parcel ?></option>
168
- <?php endforeach ?>
169
- </select>
170
- </div>
 
 
171
  </div>
172
- </li>
 
 
 
173
  </div>
174
- <?php endif; ?>
175
- <?php endif; ?>
176
-
177
- <div id="<?php echo $_code; ?>_new_credit_card_<?php echo $num; ?>_<?php echo $c;?>" <?php if( $countCcs > 0 ) { ?>style="display:none"<?php } ?>>
178
-
179
- <li style="margin-bottom: 5px;">
180
- <div class="field">
181
- <label><?php echo $this->__('Credit Card Issuer') ?> <span class="required">*</span></label>
182
- <div class="input-box">
183
- <select id="<?php echo $_code; ?>_<?php echo $num; ?>_<?php echo $c;?>_cc_type" name="payment[<?php echo $_code; ?>_<?php echo $num; ?>_<?php echo $c;?>_cc_type]" class="required-entry validate-cc-type-select" onchange="cc_cid(this, <?php echo $num; ?>,<?php echo $c;?>);">
184
- <?php $_ccType = $this->getInfoData('creditCardType') ?>
185
- <option value=""></option>
186
- <?php $ccards = $standard->getCcTypes();?>
187
- <?php foreach($ccards as $ccard): ?>
188
- <option value="<?php echo $ccard;?>" <?php if($ccard==$_ccType): ?>selected="selected"<?php endif ?>><?php echo Mage::helper('mundipagg')->issuer($ccard);?></option>
189
- <?php endforeach ?>
190
- </select>
191
- </div>
192
- </div>
193
- </li>
194
- <li style="margin-bottom: 5px;">
195
- <div class="field">
196
- <label><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label>
197
- <div class="input-box">
198
- <input type="text" id="<?php echo $_code; ?>_<?php echo $num; ?>_<?php echo $c;?>_cc_number" name="payment[<?php echo $_code; ?>_<?php echo $num; ?>_<?php echo $c;?>_cc_number]" title="<?php echo $this->__('Credit Card Number') ?>" class="input-text required-entry validate-cc-number" onkeydown="remove_characters(event);" value=""/>
199
- </div>
200
- </div>
201
- </li>
202
- <li style="margin-bottom: 5px;">
203
- <div class="field">
204
- <label><?php echo $this->__('Credit Card Holder name') ?> <span class="required">*</span></label>
205
- <div class="input-box">
206
- <input type="text" id="<?php echo $_code; ?>_cc_holder_name_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_cc_holder_name_<?php echo $num; ?>_<?php echo $c;?>]" class="required-entry input-text" />
207
- </div>
208
- </div>
209
- </li>
210
- <li style="margin-bottom: 5px;">
211
- <div class="field">
212
- <label><?php echo $this->__('Expiration date') ?> <span class="required">*</span></label>
213
- <div class="input-box">
214
- <div class="v-fix">
215
- <select id="<?php echo $_code; ?>_expirationMonth_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_expirationMonth_<?php echo $num; ?>_<?php echo $c;?>]" style="width: 145px;" class="required-entry validate-cc-exp-new">
216
- <option value=""><?php echo $this->__('Month') ?></option>
217
- <option value="1">01 - <?php echo $this->__('January') ?></option>
218
- <option value="2">02 - <?php echo $this->__('February') ?></option>
219
- <option value="3">03 - <?php echo $this->__('March') ?></option>
220
- <option value="4">04 - <?php echo $this->__('April') ?></option>
221
- <option value="5">05 - <?php echo $this->__('May') ?></option>
222
- <option value="6">06 - <?php echo $this->__('June') ?></option>
223
- <option value="7">07 - <?php echo $this->__('July') ?></option>
224
- <option value="8">08 - <?php echo $this->__('August') ?></option>
225
- <option value="9">09 - <?php echo $this->__('September') ?></option>
226
- <option value="10">10 - <?php echo $this->__('October') ?></option>
227
- <option value="11">11 - <?php echo $this->__('November') ?></option>
228
- <option value="12">12 - <?php echo $this->__('December') ?></option>
229
- </select>
230
- </div>
231
- <div class="v-fix" style="padding-left:6px;">
232
- <select id="<?php echo $_code; ?>_expirationYear_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_expirationYear_<?php echo $num; ?>_<?php echo $c;?>]" style="width: 105px;" class="required-entry">
233
- <option value=""><?php echo $this->__('Year') ?></option>
234
- <?php
235
- $i = date('Y');
236
- $year = date('Y');
237
- $year10 = $year + 10;
238
- for( $i = $year; $i <= $year10; $i++ ):
239
- ?>
240
- <option value="<?php echo substr($i, -2);?>"><?php echo $i;?></option>
241
- <?php endfor; ?>
242
- </select>
243
- </div>
244
- </div>
245
- </div>
246
- </li>
247
- <li style="margin-bottom: 5px;">
248
- <div class="field">
249
- <label><?php echo $this->__('Card Verification Number') ?> <span class="required">*</span></label>
250
- <div class="input-box">
251
- <div class="v-fix">
252
- <input type="text" id="<?php echo $_code; ?>_cc_cid_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_cc_cid_<?php echo $num; ?>_<?php echo $c;?>]" style="width: 30px" class="required-entry input-text validate-cc-cvn validate-length" maxlength="4" onkeydown="remove_characters(event);"/>
253
- </div>
254
- <div class="v-fix" style="padding-left:6px;">
255
- <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
256
- </div>
257
- </div>
258
- </div>
259
- </li>
260
- <?php if($num != 1): ?>
261
- <li style="margin-bottom: 5px;">
262
- <div class="field">
263
- <label><?php echo $this->__('Value (Ex: 100,50)') ?> <span class="required">*</span></label>
264
- <div class="input-box">
265
- <input type="text" id="<?php echo $_code; ?>_new_value_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_new_value_<?php echo $num; ?>_<?php echo $c;?>]" title="<?php echo $this->__('Value (Ex: 100,50)') ?>" class="required-entry validate-greater-than-zero check_values" onchange="calculateInstallmentValue(this, <?php echo $num;?>, <?php echo $c;?>);" onkeydown="remove_special_characters(event);" value=""/>
266
- </div>
267
- </div>
268
- </li>
269
- <?php endif; ?>
270
- <?php if ($installmentsHelper->isInstallmentsEnabled() && $_code != 'mundipagg_creditcardoneinstallment'): ?>
271
  <li style="margin-bottom: 5px;">
272
  <div class="field">
273
- <label class="required"><?php echo $this->__('Credit options') ?> <?php if($num ==2): ?><!--<a href="javascript:void(0);" onclick="javascript:void(0);">(<?php /*echo $this->__('click to update') */?>)</a>--><?php endif ?></label>
 
274
  <div class="input-box">
275
- <select id="<?php echo $_code; ?>_new_credito_parcelamento_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_new_credito_parcelamento_<?php echo $num; ?>_<?php echo $c;?>]" onchange="checkInstallments(this, '<?php echo Mage::getUrl('',array('_secure'=>true)); ?>');">
276
- <?php foreach($this->getInstallments() as $key => $parcel): ?>
 
 
 
 
 
277
  <option value="<?php echo $key ?>"><?php echo $parcel ?></option>
278
  <?php endforeach ?>
279
  </select>
280
  </div>
281
  </div>
282
  </li>
283
- <?php endif; ?>
284
- <?php if ($standard->getConfigData('clearsale') && !$_taxvat->isEnabled() && Mage::getSingleton('adminhtml/session_quote')->getCustomer()->getTaxvat() == ''): ?>
285
- <li style="margin-bottom: 5px;">
286
- <div class="field">
287
- <label><?php echo $this->__('CPF ou CNPJ') ?> <span class="required">*</span></label>
288
- <div class="input-box">
289
- <input type="text" id="<?php echo $_code; ?>_cc_taxvat_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_cc_taxvat_<?php echo $num; ?>_<?php echo $c;?>]" title="<?php echo $this->__('CPF ou CNPJ') ?>" class="validar_cpf required-entry" onkeydown="remove_characters(event);"/>
290
- </div>
291
- </div>
292
- </li>
293
- <?php endif;?>
294
- <?php if($standard->getQuote()->getCheckoutMethod() != 'guest'): ?>
295
- <li>
296
- <div class="input-box" style="padding-top: 10px">
297
- <div class="field">
298
- <label><?php echo $this->__('Save Card On File') ?></label>
299
- <input type="checkbox" id="<?php echo $_code; ?>_save_token_<?php echo $num; ?>_<?php echo $c;?>" name="payment[<?php echo $_code; ?>_save_token_<?php echo $num; ?>_<?php echo $c;?>]" value="new"/>
300
- </div>
301
- </div>
302
- </li>
303
- <?php endif; ?>
304
- </div>
305
- <?php endfor; ?>
306
- </ul>
307
- <?php endif ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  </div>
309
  </li>
310
- <?php // END CREDIT CARD PAYMENT METHOD ?>
311
 
312
- <?php if ( $_code == 'mundipagg_boleto' ): ?>
313
- <li>
314
- <input type="hidden" id="mundipagg_type" name="payment[mundipagg_type]" value="BoletoBancario"/>
315
- <br/>
316
- <div id="mundipagg_boleto">
317
- <ul >
318
- <?php if(!$_taxvat->isEnabled() && Mage::getSingleton('adminhtml/session_quote')->getCustomer()->getTaxvat() == ''): ?>
319
- <li>
320
- <div class="input-box" style="float:left;">
321
- <label><?php echo $this->__('CPF ou CNPJ') ?> <span class="required">*</span></label><br/>
322
- <input type="text" id="<?php echo $_code ?>_boleto_taxvat" name="payment[boleto_taxvat]" title="<?php echo $this->__('Taxvat') ?>" class="validar_cpf required-entry" onkeydown="remove_characters(event);"/>
323
- </div>
324
- </li>
325
- <?php endif; ?>
326
- <li>
327
- <div id="boleto" style="float:left; text-align:center">
328
- <img src="<?php echo $this->getSkinUrl('images/mundipagg/boleto.jpg');?>" alt="<?php echo $this->__('Boleto Bancário') ?>" /> <?php echo $this->__('Print your boleto after you have placed your order.') ?>
329
- </div>
330
- </li>
331
- </ul>
332
- </div>
333
- </li>
334
- <?php endif ?>
335
- </ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  </fieldset>
337
 
338
  <script type="text/javascript">
339
  //<![CDATA[
340
- window.baseUrl = '<?php echo Mage::helper("adminhtml")->getUrl();?>';
341
- window.admin_area_url_installments_and_interest = '<?php echo Mage::helper("adminhtml")->getUrl("mundipagg/standard/installmentsandinterest"); ?>';
342
- window.installmentsandinterestUrl = '<?php echo Mage::helper("adminhtml")->getUrl("mundipagg/standard/installmentsandinterest",array("_secure"=>true)); ?>';
343
- window.ajaxLoaderGif = '<?php echo $this->getSkinUrl("images/mundipagg/ajax-loader.gif"); ?>';
344
- window.isInstallmentsEnabled = '<?php echo Mage::helper("mundipagg/installments")->isInstallmentsEnabled(); ?>';
 
345
 
346
- $$('.validate-cc-type-select').invoke('observe','change',function(){
347
- brand_select = this;
348
- amount = false;
349
- if(this.value != '') {
350
- this.up(3).select('select,input').each(function(sel){
351
- if(sel.readAttribute('id').indexOf('new_value') != -1){
352
- if(brand_select.value != '' && brand_select.value != undefined) {
353
- amount = sel.value;
 
354
  }
355
- }
356
- if(sel.readAttribute('id').indexOf('parcelamento') != -1){
357
 
358
- updateInstallments(brand_select.value, sel, amount);
359
- }
360
- });
361
- }
362
- });
363
 
364
- Validation.addAllThese([
365
- ['validate-cc-exp-new', '<?php echo $this->jsQuoteEscape( Mage::helper('mundipagg')->__('Incorrect credit card expiration date.') )?>', function(v, elm) {
366
- var ccExpMonth = v;
367
- var ccExpYear = $( elm.id.replace("_expirationMonth", "_expirationYear") ).value;
368
 
369
- var currentTime = new Date();
370
- var currentMonth = currentTime.getMonth() + 1;
371
- var currentYear = currentTime.getFullYear().toString().substr(2,2);
372
- if (ccExpMonth < currentMonth && ccExpYear == currentYear) {
373
- return false;
374
- }
375
- return true;
376
- }]
377
- ]);
378
  //]]>
379
  </script>
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  //Return Standard model
4
  $standard = $this->getStandard();
6
  // Get Quote
7
  $quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
8
 
9
+ if ($quote->isVirtual()) {
10
+ $data = $quote->getBillingAddress();
11
  } else {
12
+ $data = $quote->getShippingAddress();
13
  }
14
 
15
  $baseGrandTotal = $quote->getBaseGrandTotal();
34
  $_code = $this->getMethodCode();
35
  ?>
36
  <style type="text/css">
37
+ .issuers{
38
+ text-align: center;
39
+ padding-right: 10px;
40
+ }
41
  </style>
42
  <fieldset class="form-list">
43
+ <ul id="payment_form_<?php echo $_code ?>" style="display:none;">
44
+ <div>
45
+ <input type="hidden" id="baseGrandTotal" name="baseGrandTotal" value="<?php echo number_format($baseGrandTotal, "2", ",", ""); ?>"/>
46
+ </div>
47
+ <?php
48
+ // START CREDIT CARD PAYMENT METHOD
49
+ $num = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
+ switch ($_code):
52
+ case 'mundipagg_creditcardoneinstallment':
53
+ $num = 1;
54
+ $paymentMethod = '1CreditCardsOneInstallment';
55
+ $paymentMethodLabel = $this->__('Credit Card');
56
+ break;
57
 
58
+ case 'mundipagg_creditcard':
59
+ $num = 1;
60
+ $paymentMethod = '1CreditCards';
61
+ $paymentMethodLabel = $this->__('Credit Card');
62
+ break;
63
 
64
+ case 'mundipagg_twocreditcards':
65
+ $num = 2;
66
+ $paymentMethod = '2CreditCards';
67
+ $paymentMethodLabel = $this->__('Pay with 2 Credit Cards');
68
+ break;
69
+ endswitch;
70
+ ?>
71
  <li>
72
+ <div id="<?php echo $_code; ?>">
73
+ <?php
74
+ if (
75
+ $_code == 'mundipagg_creditcardoneinstallment' ||
76
+ $_code == 'mundipagg_creditcard' ||
77
+ $_code == 'mundipagg_twocreditcards'
78
+ ):
79
+ ?>
80
+ <ul>
81
+ <?php for ($c = 1; $c <= $num; $c++): ?>
82
+ <input type="hidden" id="mundipagg_type" name="payment[mundipagg_type]" value="<?php echo $paymentMethod; ?>"/>
83
  <?php $currentSelectedToken = null; ?>
84
+ <?php if ($countCcs > 0): ?>
85
+ <li class="fields" style="margin-bottom: 5px;">
86
  <div class="field">
87
  <label class="required"><?php echo $this->__('Select a Credit Card or add a new one') ?><span class="required">*</span></label>
88
  <div class="input-box">
89
 
90
+ <select
91
+ id="<?php echo $_code . '_token_' . $num . '_' . $c; ?>"
92
+ data="group_<?php echo $num . '_' . $c; ?>"
93
+ name="payment[<?php echo $_code . '_token_' . $num . '_' . $c; ?>]"
94
+ class="required-entry tokens group_<?php echo $num . '_' . $c; ?>"
95
+ onchange="token_or_not(<?php echo $num; ?>,<?php echo $c; ?>, this)"
96
+ >
97
  <option value="">...</option>
98
  <?php
99
+ foreach ($ccs as $id => $cc):
100
 
101
+ if ($countCcs == 1) {
102
+ $currentSelectedToken = Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cc->getCcType());
103
+ }
104
+ $dataType = $currentSelectedToken
105
+ ? $currentSelectedToken
106
+ : Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cc->getCcType());
107
+ echo '<option value="'.$cc->getId().'" data="'.$dataType.'">'.$cc->getCcType().' '.$cc->getCreditCardMask().'</option>';
108
+ endforeach;
109
  ?>
110
  <option value="new"><?php echo $this->__('New Credit Card') ?></option>
111
  </select>
112
  </div>
113
  </div>
114
+ </li>
115
+ <?php if ($num != 1): ?>
116
+ <div id="value_<?php echo $num . '_' . $c; ?>">
117
+ <li class="fields" style="margin-bottom: 5px;">
118
+ <div class="field">
119
+ <label class="required"><?php echo $this->__('Value (Ex: 100,50)') ?> <span class="required">*</span></label>
120
+ <div class="input-box">
121
+ <input
122
+ type="text" id="<?php echo $_code . '_value_' . $num . '_' . $c; ?>"
123
+ name="payment[<?php echo $_code . '_value_' . $num . '_' . $c; ?>]"
124
+ title="<?php echo $this->__('Value (Ex: 100,50)') ?>"
125
+ class="required-entry validate-greater-than-zero check_values group_<?php echo $num . '_' . $c; ?>"
126
+ onchange="calculateInstallmentValue(this, <?php echo $num; ?>, <?php echo $c; ?>, '<?php
127
+ echo Mage::getUrl('', array('_secure' => true));
128
+ ?>');"
129
+ onkeydown="remove_special_characters(event);"
130
+ value=""
131
+ />
132
+ </div>
133
  </div>
134
+ </li>
135
+ </div>
136
+ <?php endif; ?>
137
+ <?php
138
+ if (
139
+ $installmentsHelper->isInstallmentsEnabled() && $_code
140
+ != 'mundipagg_creditcardoneinstallment'):
141
+ ?>
142
+ <div id="parcelamento_<?php echo $num . '_' . $c; ?>" <?php
143
+ if ($countCcs> 1):
144
+ ?>style="display:none"<?php endif ?>
145
+ >
146
+ <li class="fields" style="margin-bottom: 5px;">
147
+ <div class="field">
148
+ <label class="required"><?php echo $this->__('Credit options') ?>
149
+ </label>
150
+ <div class="input-box">
151
+ <select
152
+ id="<?php echo $_code; ?>_credito_parcelamento_<?php echo $num . '_' . $c; ?>"
153
+ name="payment[<?php echo $_code; ?>_credito_parcelamento_<?php echo $num . '_' . $c; ?>]"
154
+ class="required-entry installment-token group_<?php echo $num . '_' . $c; ?>"
155
+ >
156
+ <?php foreach ($this->getInstallments($currentSelectedToken) as $key => $parcel): ?>
157
+ <option value="<?php echo $key ?>"><?php echo $parcel ?></option>
158
+ <?php endforeach ?>
159
+ </select>
160
+ </div>
161
+ </div>
162
+ </li>
163
+ </div>
164
+ <?php endif; ?>
165
+ <?php endif; ?>
166
+
167
+ <div
168
+ id="<?php echo $_code . '_new_credit_card_' . $num . '_' . $c; ?>"
169
+ <?php if ($countCcs > 0) { ?>
170
+ style="display:none"
171
+ <?php } ?>
172
+ >
173
+
174
+ <li style="margin-bottom: 5px;">
175
+ <div class="field">
176
+ <label><?php echo $this->__('Credit Card Issuer') ?> <span class="required">*</span></label>
177
+ <div class="input-box">
178
+ <select
179
+ id="<?php echo $_code . '_' . $num . '_' . $c . '_cc_type';?>"
180
+ name="payment[<?php echo $_code . '_' . $num . '_' . $c; ?>_cc_type]"
181
+ class="required-entry validate-cc-type-select"
182
+ onchange="cc_cid(this, <?php echo $num; ?>,<?php echo $c; ?>);"
183
+ >
184
+ <?php $_ccType = $this->getInfoData('creditCardType') ?>
185
+ <option value=""></option>
186
+ <?php $ccards = $standard->getCcTypes(); ?>
187
+ <?php foreach ($ccards as $ccard): ?>
188
+ <option
189
+ value="<?php echo $ccard; ?>"
190
+ <?php
191
+ if ($ccard == $_ccType): ?>
192
+ class=""
193
+ accesskey=""
194
+ selected="selected"
195
+ <?php endif ?>
196
+ ><?php echo Mage::helper('mundipagg')->issuer($ccard); ?>
197
+ </option>
198
+ <?php endforeach ?>
199
+ </select>
200
+ </div>
201
+ </div>
202
+ </li>
203
+ <li style="margin-bottom: 5px;">
204
+ <div class="field">
205
+ <label><?php echo $this->__('Credit Card Number') ?> <span class="required">*</span></label>
206
+ <div class="input-box">
207
+ <input
208
+ type="text"
209
+ id="<?php echo $_code . '_' . $num . '_' . $c . '_cc_number'; ?>"
210
+ name="payment[<?php echo $_code . '_' . $num . '_' . $c; ?>_cc_number]"
211
+ title="<?php echo $this->__('Credit Card Number') ?>"
212
+ class="input-text required-entry validate-cc-number"
213
+ onkeydown="remove_characters(event);"
214
+ value=""
215
+ />
216
+ </div>
217
+ </div>
218
+ </li>
219
+ <li style="margin-bottom: 5px;">
220
+ <div class="field">
221
+ <label><?php echo $this->__('Credit Card Holder name') ?> <span class="required">*</span></label>
222
+ <div class="input-box">
223
+ <input
224
+ type="text"
225
+ id="<?php echo $_code . '_cc_holder_name_' . $num . '_' . $c; ?>"
226
+ name="payment[<?php echo $_code . '_cc_holder_name_' . $num . '_' . $c; ?>]"
227
+ class="required-entry input-text"
228
+ />
229
+ </div>
230
+ </div>
231
+ </li>
232
+ <li style="margin-bottom: 5px;">
233
+ <div class="field">
234
+ <label><?php echo $this->__('Expiration date') ?> <span class="required">*</span></label>
235
+ <div class="input-box">
236
+ <div class="v-fix">
237
+ <select
238
+ id="<?php echo $_code . '_expirationMonth_' . $num . '_' . $c; ?>"
239
+ name="payment[<?php echo $_code . '_expirationMonth_' . $num . '_' . $c; ?>]"
240
+ style="width: 145px;" class="required-entry validate-cc-exp-new"
241
+ >
242
+ <option value=""><?php echo $this->__('Month') ?></option>
243
+ <option value="1">01 - <?php echo $this->__('January') ?></option>
244
+ <option value="2">02 - <?php echo $this->__('February') ?></option>
245
+ <option value="3">03 - <?php echo $this->__('March') ?></option>
246
+ <option value="4">04 - <?php echo $this->__('April') ?></option>
247
+ <option value="5">05 - <?php echo $this->__('May') ?></option>
248
+ <option value="6">06 - <?php echo $this->__('June') ?></option>
249
+ <option value="7">07 - <?php echo $this->__('July') ?></option>
250
+ <option value="8">08 - <?php echo $this->__('August') ?></option>
251
+ <option value="9">09 - <?php echo $this->__('September') ?></option>
252
+ <option value="10">10 - <?php echo $this->__('October') ?></option>
253
+ <option value="11">11 - <?php echo $this->__('November') ?></option>
254
+ <option value="12">12 - <?php echo $this->__('December') ?></option>
255
+ </select>
256
+ </div>
257
+ <div class="v-fix" style="padding-left:6px;">
258
+ <select
259
+ id="<?php echo $_code . '_expirationYear_' . $num . '_' . $c; ?>"
260
+ name="payment[<?php echo $_code . '_expirationYear_' . $num . '_' . $c; ?>]"
261
+ style="width: 105px;"
262
+ class="required-entry"
263
+ >
264
+ <option value=""><?php echo $this->__('Year') ?></option>
265
+ <?php
266
+ $i = date('Y');
267
+ $year = date('Y');
268
+ $year10 = $year + 10;
269
+ for ($i = $year; $i <= $year10; $i++):
270
+ ?>
271
+ <option value="<?php echo substr($i, -2); ?>"><?php echo $i; ?></option>
272
+ <?php endfor; ?>
273
+ </select>
274
  </div>
275
+ </div>
276
  </div>
277
+ </li>
278
+ <li style="margin-bottom: 5px;">
279
+ <div class="field">
280
+ <label><?php echo $this->__('Card Verification Number') ?> <span class="required">*</span></label>
281
+ <div class="input-box">
282
+ <div class="v-fix">
283
+ <input
284
+ type="text"
285
+ id="<?php echo $_code . '_cc_cid_' . $num . '_' . $c; ?>"
286
+ name="payment[<?php echo $_code . '_cc_cid_' . $num . '_' . $c; ?>]"
287
+ style="width: 30px"
288
+ class="required-entry input-text validate-cc-cvn validate-length"
289
+ maxlength="4"
290
+ onkeydown="remove_characters(event);"
291
+ />
292
  </div>
293
+ <div class="v-fix" style="padding-left:6px;">
294
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
295
+ </div>
296
+ </div>
297
  </div>
298
+ </li>
299
+ <?php if ($num != 1): ?>
300
+ <li style="margin-bottom: 5px;">
301
+ <div class="field">
302
+ <label><?php echo $this->__('Value (Ex: 100,50)') ?> <span class="required">*</span></label>
303
+ <div class="input-box">
304
+ <input
305
+ type="text"
306
+ id="<?php echo $_code . '_new_value_' . $num . '_' . $c; ?>"
307
+ name="payment[<?php echo $_code . '_new_value_' . $num . '_' . $c; ?>]"
308
+ title="<?php echo $this->__('Value (Ex: 100,50)') ?>"
309
+ class="required-entry validate-greater-than-zero check_values"
310
+ onchange="calculateInstallmentValue(this, <?php echo $num; ?>, <?php echo $c; ?>);"
311
+ onkeydown="remove_special_characters(event);"
312
+ value=""
313
+ />
314
+ </div>
315
+ </div>
316
+ </li>
317
+ <?php endif; ?>
318
+ <?php
319
+ if (
320
+ $installmentsHelper->isInstallmentsEnabled()
321
+ && $_code != 'mundipagg_creditcardoneinstallment'
322
+ ):
323
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  <li style="margin-bottom: 5px;">
325
  <div class="field">
326
+ <label class="required"><?php echo $this->__('Credit options') ?>
327
+ </label>
328
  <div class="input-box">
329
+ <select
330
+ id="<?php echo $_code . '_new_credito_parcelamento_' . $num . '_' . $c; ?>"
331
+ name="payment[<?php echo $_code . '_new_credito_parcelamento_' . $num . '_' . $c; ?>]"
332
+ onchange="checkInstallments(this, '<?php echo Mage::getUrl('', array(
333
+ '_secure' => true)); ?>');"
334
+ >
335
+ <?php foreach ($this->getInstallments() as $key => $parcel): ?>
336
  <option value="<?php echo $key ?>"><?php echo $parcel ?></option>
337
  <?php endforeach ?>
338
  </select>
339
  </div>
340
  </div>
341
  </li>
342
+ <?php endif; ?>
343
+ <?php if (
344
+ $standard->getConfigData('clearsale') &&
345
+ !$_taxvat->isEnabled() &&
346
+ Mage::getSingleton('adminhtml/session_quote')->getCustomer()->getTaxvat() == ''):
347
+ ?>
348
+ <li style="margin-bottom: 5px;">
349
+ <div class="field">
350
+ <label><?php echo $this->__('CPF ou CNPJ') ?> <span class="required">*</span></label>
351
+ <div class="input-box">
352
+ <input
353
+ type="text"
354
+ id="<?php echo $_code . '_cc_taxvat_' . $num . '_' . $c; ?>"
355
+ name="payment[<?php echo $_code . '_cc_taxvat_' . $num . '_' . $c; ?>]"
356
+ title="<?php echo $this->__('CPF ou CNPJ') ?>"
357
+ class="validar_cpf required-entry"
358
+ onkeydown="remove_characters(event);"/>
359
+ </div>
360
+ </div>
361
+ </li>
362
+ <?php endif; ?>
363
+ <?php
364
+ if (
365
+ $standard->getQuote()->getCheckoutMethod()
366
+ != 'guest'):
367
+ ?>
368
+ <li>
369
+ <div class="input-box" style="padding-top: 10px">
370
+ <div class="field">
371
+ <label><?php echo $this->__('Save Card On File') ?></label>
372
+ <input
373
+ type="checkbox"
374
+ id="<?php echo $_code . '_save_token_' . $num . '_' . $c; ?>"
375
+ name="payment[<?php echo $_code . '_save_token_' . $num . '_' . $c; ?>]"
376
+ value="new"
377
+ />
378
+ </div>
379
+ </div>
380
+ </li>
381
+ <?php endif; ?>
382
+ </div>
383
+ <?php endfor; ?>
384
+ </ul>
385
+ <?php endif ?>
386
  </div>
387
  </li>
388
+ <?php // END CREDIT CARD PAYMENT METHOD ?>
389
 
390
+ <?php if ($_code == 'mundipagg_boleto'): ?>
391
+ <li>
392
+ <input type="hidden" id="mundipagg_type" name="payment[mundipagg_type]" value="BoletoBancario"/>
393
+ <br/>
394
+ <div id="mundipagg_boleto">
395
+ <ul >
396
+ <?php
397
+ if (
398
+ !$_taxvat->isEnabled() &&
399
+ Mage::getSingleton('adminhtml/session_quote')->getCustomer()->getTaxvat() == ''
400
+ ):
401
+ ?>
402
+ <li>
403
+ <div class="input-box" style="float:left;">
404
+ <label><?php echo $this->__('CPF ou CNPJ') ?> <span class="required">*</span></label>
405
+ <br/>
406
+ <input
407
+ type="text"
408
+ id="<?php echo $_code . '_boleto_taxvat'; ?>"
409
+ name="payment[boleto_taxvat]"
410
+ title="<?php echo $this->__('Taxvat') ?>"
411
+ class="validar_cpf required-entry"
412
+ onkeydown="remove_characters(event);
413
+ "/>
414
+ </div>
415
+ </li>
416
+ <?php endif; ?>
417
+ <li>
418
+ <div id="boleto" style="float:left; text-align:center">
419
+ <img
420
+ src="<?php echo $this->getSkinUrl('images/mundipagg/boleto.jpg'); ?>"
421
+ alt="<?php echo $this->__('Boleto Bancário') ?>"
422
+ />
423
+ <?php echo $this->__('Print your boleto after you have placed your order.') ?>
424
+ </div>
425
+ </li>
426
+ </ul>
427
+ </div>
428
+ </li>
429
+ <?php endif ?>
430
+ </ul>
431
  </fieldset>
432
 
433
  <script type="text/javascript">
434
  //<![CDATA[
435
+ window.baseUrl = '<?php echo Mage::helper("adminhtml")->getUrl(); ?>';
436
+ window.admin_area_url_installments_and_interest = '<?php echo Mage::helper("adminhtml")->getUrl("mundipagg/standard/installmentsandinterest"); ?>';
437
+ window.installmentsandinterestUrl = '<?php echo Mage::helper("adminhtml")->getUrl("mundipagg/standard/installmentsandinterest", array(
438
+ "_secure" => true)); ?>';
439
+ window.ajaxLoaderGif = '<?php echo $this->getSkinUrl("images/mundipagg/ajax-loader.gif"); ?>';
440
+ window.isInstallmentsEnabled = '<?php echo Mage::helper("mundipagg/installments")->isInstallmentsEnabled(); ?>';
441
 
442
+ $$('.validate-cc-type-select').invoke('observe', 'change', function () {
443
+ brand_select = this;
444
+ amount = false;
445
+ if (this.value != '') {
446
+ this.up(3).select('select,input').each(function (sel) {
447
+ if (sel.readAttribute('id').indexOf('new_value') != -1) {
448
+ if (brand_select.value != '' && brand_select.value != undefined) {
449
+ amount = sel.value;
450
+ }
451
  }
452
+ if (sel.readAttribute('id').indexOf('parcelamento') != -1) {
 
453
 
454
+ updateInstallments(brand_select.value, sel, amount);
455
+ }
456
+ });
457
+ }
458
+ });
459
 
460
+ Validation.addAllThese([
461
+ ['validate-cc-exp-new', '<?php echo $this->jsQuoteEscape(Mage::helper('mundipagg')->__('Incorrect credit card expiration date.')) ?>', function (v, elm) {
462
+ var ccExpMonth = v;
463
+ var ccExpYear = $(elm.id.replace("_expirationMonth", "_expirationYear")).value;
464
 
465
+ var currentTime = new Date();
466
+ var currentMonth = currentTime.getMonth() + 1;
467
+ var currentYear = currentTime.getFullYear().toString().substr(2, 2);
468
+ if (ccExpMonth < currentMonth && ccExpYear == currentYear) {
469
+ return false;
470
+ }
471
+ return true;
472
+ }]
473
+ ]);
474
  //]]>
475
  </script>
app/design/frontend/base/default/template/mundipagg/parcelamento.phtml CHANGED
@@ -1,8 +1,45 @@
1
 
2
  <?php
3
- $parcelamento = $this->getParcelamento();
 
 
 
 
 
 
 
 
4
 
5
- if(!empty($parcelamento)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  ?>
7
- <?php echo $this->__('ou')?> <strong><?php echo $parcelamento; ?></strong>
8
- <?php endif;?>
1
 
2
  <?php
3
+ $_coreHelper = $this->helper('core');
4
+ $frequencyType = [
5
+ 'Daily' => 'Day',
6
+ 'Weekly' => 'Week',
7
+ 'Monthly' => 'Month',
8
+ 'Quarterly' => 'Quarter',
9
+ 'Biannual' => 'Semester',
10
+ 'Yearly' => 'Year'
11
+ ];
12
 
13
+ $parcelamento = $this->getParcelamento();
14
+ $recurrence = $this->getMundipaggRecurrence();
15
+ $recurrences = $this->getMundipaggRecurrences();
16
+ $frequency = $this->getMundipaggFrequency();
17
+ $recurrenceMix = $this->getMundipaggRecurrenceMix();
18
+ $reurrenceDiscount = $this->getMundipaggRecurrenceDiscount();
19
+ if ($recurrenceMix) {
20
+ echo '<strong>' .
21
+ 'ou ' .
22
+ $_coreHelper->formatPrice(($this->getPrice() / $recurrences)) .
23
+ ' ' . $this->__('by') . ' ' .
24
+ $recurrences . ' ' .
25
+ $this->__($frequencyType[$frequency] .'s') .
26
+ '</strong>'
27
+ ;
28
+ } elseif ($recurrence) {
29
+ echo '<strong>/' .
30
+ strtolower($this->__($frequencyType[$frequency])) .
31
+ ' ' . $this->__('by') . ' ' .
32
+ $recurrences . ' ' .
33
+ $this->__($frequencyType[$frequency] .'s') .
34
+ ' ('
35
+ . $this->__('Total') . ' ' .
36
+ $_coreHelper->formatPrice(($this->getPrice() * $recurrences)) .
37
+ ')' .
38
+ '</strong>'
39
+ ;
40
+ } else {
41
+ if (!empty($parcelamento)) {
42
+ echo $this->__('ou') . ' ' . '<strong>' . $parcelamento . '</strong>';
43
+ }
44
+ }
45
  ?>
 
 
app/design/frontend/rwd/default/template/mundipagg/form.phtml CHANGED
@@ -1,34 +1,4 @@
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
- //Return Standard model
31
- /* @var Uecommerce_Mundipagg_Block_Standard_Form $standard */
32
  $standard = $this->getStandard();
33
 
34
  // Get Quote
@@ -43,7 +13,6 @@ if ($quote->isVirtual()) {
43
  $data = $quote->getShippingAddress();
44
  }
45
 
46
-
47
  // Partial payment?
48
  $isPartial = Mage::getSingleton('checkout/session')->getApprovalRequestSuccess();
49
 
@@ -67,7 +36,15 @@ if ($data->getMundipaggInterest()) {
67
  $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat');
68
 
69
  // Get current currency symbol
70
- $currencySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
 
 
 
 
 
 
 
 
71
 
72
  //Credit Card Saved On File
73
  $ccs = $this->getCcs();
@@ -76,16 +53,80 @@ $countCcs = count($ccs);
76
 
77
  // Payment method
78
  $_code = $this->getMethodCode();
79
- ?>
80
 
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  <ul id="payment_form_<?php echo $_code ?>" style="display:none;">
83
  <div>
84
  <input type="hidden" id="baseGrandTotal" name="baseGrandTotal"
85
  value="<?php echo number_format($baseGrandTotal, "2", ",", ""); ?>"/>
86
  <?php if ($isPartial == 'partial'): ?>
87
- <input type="hidden" name="partial" id="partial" value="1"/>
88
- <input type="hidden" name="payment[multi]" id="multi" value="1"/>
89
  <?php endif; ?>
90
  </div>
91
  <?php
@@ -111,51 +152,57 @@ $_code = $this->getMethodCode();
111
  $paymentMethodLabel = $this->__('Pay with 2 Credit Cards');
112
  break;
113
 
114
- case 'mundipagg_threecreditcards':
115
- $num = 3;
116
- $paymentMethod = '3CreditCards';
117
- $paymentMethodLabel = $this->__('Pay with 3 Credit Cards');
118
- break;
119
-
120
- case 'mundipagg_fourcreditcards':
121
- $num = 4;
122
- $paymentMethod = '4CreditCards';
123
- $paymentMethodLabel = $this->__('Pay with 4 Credit Cards');
124
  break;
125
 
126
- case 'mundipagg_fivecreditcards':
127
- $num = 5;
128
- $paymentMethod = '5CreditCards';
129
- $paymentMethodLabel = $this->__('Pay with 5 Credit Cards');
130
- break;
131
  endswitch;
 
132
  ?>
133
  <li>
134
  <div id="<?php echo $_code; ?>">
135
- <?php if ($num != 1 && $isPartial != 'partial'): ?>
136
  <p></p>
137
  <div>
138
- <b><?php echo $this->__('Grand Total') ?>
139
- :</b> <?php echo $currencySymbol . number_format($baseGrandTotal, "2", ",", "."); ?>
140
  </div>
141
  <p></p>
142
- <?php endif ?>
143
- <?php if ($_code == 'mundipagg_creditcardoneinstallment' || $_code == 'mundipagg_creditcard' || $_code == 'mundipagg_twocreditcards' || $_code == 'mundipagg_threecreditcards' || $_code == 'mundipagg_fourcreditcards' || $_code == 'mundipagg_fivecreditcards'): ?>
 
 
 
 
 
 
144
  <ul>
145
- <?php for ($c = 1; $c <= $num; $c++): ?>
146
- <input type="hidden" id="mundipagg_type" name="payment[mundipagg_type]"
147
- value="<?php echo $paymentMethod; ?>"/>
148
- <?php $currentSelectedToken = null; ?>
149
- <?php if ($countCcs > 0): ?>
 
 
 
 
 
 
 
 
 
 
150
  <li class="fields" style="margin-bottom: 5px;">
151
  <div class="field">
152
  <label class="required"><?php echo $this->__('Select a Credit Card or add a new one') ?>
153
  <span class="required">*</span></label>
154
  <div class="input-box">
155
- <select id="<?php echo $_code; ?>_token_<?php echo $num; ?>_<?php echo $c; ?>"
156
- data="group_<?php echo $num; ?>_<?php echo $c; ?>"
157
- name="payment[<?php echo $_code; ?>_token_<?php echo $num; ?>_<?php echo $c; ?>]"
158
- class="required-entry tokens group_<?php echo $num; ?>_<?php echo $c; ?>"
159
  onchange="token_or_not(<?php echo $num; ?>,<?php echo $c; ?>,this)">
160
  <option value="">...</option>
161
  <?php
@@ -170,8 +217,30 @@ $_code = $this->getMethodCode();
170
  if ($countCcs == 1) {
171
  $currentSelectedToken = Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cc->getCcType());
172
  }
173
- $dataType = $currentSelectedToken ? $currentSelectedToken : Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cc->getCcType());
174
- echo '<option value="' . $cc->getId() . '" ' . $selected . ' data="' . $dataType . '">' . $cc->getCcType() . ' ' . $cc->getCreditCardMask() . '</option>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  endforeach;
176
  ?>
177
  <option value="new"><?php echo $this->__('New Credit Card') ?></option>
@@ -180,39 +249,59 @@ $_code = $this->getMethodCode();
180
  </div>
181
  </li>
182
  <?php if ($num != 1): ?>
183
- <div id="value_<?php echo $num; ?>_<?php echo $c; ?>">
184
  <li class="fields" style="margin-bottom: 5px;">
185
  <div class="field">
186
  <label class="required"><?php echo $this->__('Value (Ex: 100,50)') ?> <span
187
  class="required">*</span></label>
188
  <div class="input-box">
189
  <input type="text"
190
- id="<?php echo $_code; ?>_value_<?php echo $num; ?>_<?php echo $c; ?>"
191
- name="payment[<?php echo $_code; ?>_value_<?php echo $num; ?>_<?php echo $c; ?>]"
192
  title="<?php echo $this->__('Value (Ex: 100,50)') ?>"
193
- class="required-entry validate-greater-than-zero input-text check_values group_<?php echo $num; ?>_<?php echo $c; ?>"
194
- onchange="calculateInstallmentValue(this, <?php echo $num; ?>, <?php echo $c; ?>, '<?php echo Mage::getUrl('', array('_secure' => true)); ?>');"
195
- onkeydown="remove_special_characters(event);" value=""/>
 
 
 
 
 
 
 
196
  </div>
197
  </div>
198
  </li>
199
  </div>
200
  <?php endif; ?>
201
- <?php if ($installmentsHelper->isInstallmentsEnabled() && $_code != 'mundipagg_creditcardoneinstallment'): ?>
202
- <div id="parcelamento_<?php echo $num; ?>_<?php echo $c; ?>"
203
- <?php if ($countCcs > 1): ?>style="display:none"<?php endif ?>>
 
 
 
 
 
 
 
 
204
  <li class="fields" style="margin-bottom: 5px;">
205
  <div class="field">
206
- <label class="required"><?php echo $this->__('Credit options') ?>
207
- <?php if ($num == 2): ?><!--<a href="javascript:void(0);" onclick="javascript:void(0);">(<?php /*echo $this->__('click to update') */ ?>)</a>--><?php endif ?></label>
208
  <div class="input-box">
209
  <?php $this->getInstallments(); ?>
210
- <select id="<?php echo $_code; ?>_credito_parcelamento_<?php echo $num; ?>_<?php echo $c; ?>"
211
- name="payment[<?php echo $_code; ?>_credito_parcelamento_<?php echo $num; ?>_<?php echo $c; ?>]"
212
- class="required-entry installment-token group_<?php echo $num; ?>_<?php echo $c; ?>">
213
- <?php foreach ($this->getInstallments($currentSelectedToken) as $key => $parcel): ?>
214
- <option value="<?php echo $key ?>"><?php echo $parcel ?></option>
215
- <?php endforeach ?>
 
 
 
 
 
 
216
  </select>
217
  </div>
218
  </div>
@@ -221,8 +310,8 @@ $_code = $this->getMethodCode();
221
  <?php endif; ?>
222
  <?php endif; ?>
223
  <div class="division"></div>
224
- <div id="<?php echo $_code; ?>_new_credit_card_<?php echo $num; ?>_<?php echo $c; ?>"
225
- <?php if ($countCcs > 0) { ?>style="display:none"<?php } ?>>
226
 
227
  <li style="margin-bottom: 5px;">
228
  <div class="field">
@@ -236,27 +325,32 @@ $_code = $this->getMethodCode();
236
  ?>
237
  <?php foreach ($ccards as $ccard): ?>
238
  <li class="cc_brands">
239
- <div class="cc_brand_types <?php echo strtolower($ccard); ?>">
240
- &nbsp;</div>
241
- <!--<img src="<?php //echo $this->getSkinUrl('images/mundipagg/'.$ccard.'.png');?>" alt="<?php //echo $ccard ?>" border="0" class="cursor_hand" onclick="setCcType(this, '<?php //echo $_code; ?>', '<?php //echo $num; ?>', '<?php //echo $c;?>', '<?php //echo $ccard; ?>');">-->
 
 
242
  <input type="radio"
243
- name="payment[<?php echo $_code; ?>_<?php echo $num; ?>_<?php echo $c; ?>_credito_instituicao]"
244
- id="<?php echo $_code; ?>_<?php echo $num; ?>_<?php echo $c; ?>_credito_instituicao_<?php echo $ccard; ?>"
245
  value="<?php echo $ccard ?>"
246
  class="<?php if ($_i == 1): ?>validate-one-required-by-name<?php endif; ?>"
247
- onclick="setCcType(this, '<?php echo $_code; ?>', '<?php echo $num; ?>', '<?php echo $c; ?>', '<?php echo $ccard; ?>');">
 
248
  </li>
249
  <?php
250
  $_i++;
251
  endforeach
252
  ?>
253
  </ul>
254
- <p class="info-payment"><i>
255
- <small><?php echo $this->__('The flag is automatically selected after entering the credit card number below.'); ?></small>
256
- </i></p>
 
 
257
  <input type="hidden"
258
- name="payment[<?php echo $_code; ?>_<?php echo $num; ?>_<?php echo $c; ?>_cc_type]"
259
- id="<?php echo $_code; ?>_<?php echo $num; ?>_<?php echo $c; ?>_cc_type"
260
  value="" class="validate-cc-type-select"/>
261
  </div>
262
  </div>
@@ -266,12 +360,15 @@ $_code = $this->getMethodCode();
266
  <label class="required"><?php echo $this->__('Credit Card Number') ?> <span
267
  class="required">*</span></label>
268
  <div class="input-box">
269
- <input type="text"
270
- id="<?php echo $_code; ?>_<?php echo $num; ?>_<?php echo $c; ?>_cc_number"
271
- name="payment[<?php echo $_code; ?>_<?php echo $num; ?>_<?php echo $c; ?>_cc_number]"
272
- title="<?php echo $this->__('Credit Card Number') ?>"
273
- class="input-text required-entry validate-cc-number"
274
- onkeydown="remove_characters(event);" value=""/>
 
 
 
275
  </div>
276
  </div>
277
  </li>
@@ -281,9 +378,10 @@ $_code = $this->getMethodCode();
281
  class="required">*</span></label>
282
  <div class="input-box">
283
  <input type="text"
284
- id="<?php echo $_code; ?>_cc_holder_name_<?php echo $num; ?>_<?php echo $c; ?>"
285
- name="payment[<?php echo $_code; ?>_cc_holder_name_<?php echo $num; ?>_<?php echo $c; ?>]"
286
- class="required-entry input-text"/>
 
287
  </div>
288
  </div>
289
  </li>
@@ -293,8 +391,8 @@ $_code = $this->getMethodCode();
293
  class="required">*</span></label>
294
  <div class="input-box">
295
  <div class="v-fix">
296
- <select id="<?php echo $_code; ?>_expirationMonth_<?php echo $num; ?>_<?php echo $c; ?>"
297
- name="payment[<?php echo $_code; ?>_expirationMonth_<?php echo $num; ?>_<?php echo $c; ?>]"
298
  class="month required-entry validate-cc-exp-new">
299
  <option value=""><?php echo $this->__('Month') ?></option>
300
  <option value="1">01 - <?php echo $this->__('January') ?></option>
@@ -312,8 +410,8 @@ $_code = $this->getMethodCode();
312
  </select>
313
  </div>
314
  <div class="v-fix" style="padding-left:6px;">
315
- <select id="<?php echo $_code; ?>_expirationYear_<?php echo $num; ?>_<?php echo $c; ?>"
316
- name="payment[<?php echo $_code; ?>_expirationYear_<?php echo $num; ?>_<?php echo $c; ?>]"
317
  class="year required-entry">
318
  <option value=""><?php echo $this->__('Year') ?></option>
319
  <?php
@@ -331,20 +429,21 @@ $_code = $this->getMethodCode();
331
  </li>
332
  <li style="margin-bottom: 5px;">
333
  <div class="field">
334
- <label class="required"><?php echo $this->__('Card Verification Number') ?> <span
335
- class="required">*</span></label>
336
  <div class="input-box">
337
  <div class="v-fix">
338
- <input type="text"
339
- id="<?php echo $_code; ?>_cc_cid_<?php echo $num; ?>_<?php echo $c; ?>"
340
- name="payment[<?php echo $_code; ?>_cc_cid_<?php echo $num; ?>_<?php echo $c; ?>]"
341
- style="width: 55px"
342
- class="required-entry input-text validate-cc-cvn validate-length"
343
- maxlength="4" onkeydown="remove_characters(event);"/>
 
 
 
344
  </div>
345
  <div class="v-fix" style="padding-left:6px;">
346
- <a href="#"
347
- class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
348
  </div>
349
  </div>
350
  </div>
@@ -352,50 +451,70 @@ $_code = $this->getMethodCode();
352
  <?php if ($num != 1): ?>
353
  <li style="margin-bottom: 5px;">
354
  <div class="field">
355
- <label class="required"><?php echo $this->__('Value (Ex: 100,50)') ?> <span
356
- class="required">*</span></label>
357
  <div class="input-box">
358
- <input type="text"
359
- id="<?php echo $_code; ?>_new_value_<?php echo $num; ?>_<?php echo $c; ?>"
360
- name="payment[<?php echo $_code; ?>_new_value_<?php echo $num; ?>_<?php echo $c; ?>]"
361
- title="<?php echo $this->__('Value (Ex: 100,50)') ?>"
362
- class="required-entry input-text validate-greater-than-zero check_values"
363
- onchange="calculateInstallmentValue(this, <?php echo $num; ?>, <?php echo $c; ?>, '<?php echo Mage::getUrl('', array('_secure' => true)); ?>');"
364
- onkeydown="remove_special_characters(event);" value=""/>
 
 
 
 
 
 
 
 
365
  </div>
366
  </div>
367
  </li>
368
  <?php endif; ?>
369
- <?php if ($installmentsHelper->isInstallmentsEnabled() && $_code != 'mundipagg_creditcardoneinstallment'): ?>
 
 
 
 
 
370
  <li style="margin-bottom: 5px;">
371
  <div class="field">
372
- <label class="required"><?php echo $this->__('Credit options') ?>
373
- <?php if ($num == 2): ?><!--<a href="javascript:void(0);" onclick="javascript:void(0);">(<?php /*echo $this->__('click to update') */ ?>)</a>--><?php endif ?></label>
374
  <div class="input-box">
375
- <select id="<?php echo $_code; ?>_new_credito_parcelamento_<?php echo $num; ?>_<?php echo $c; ?>"
376
- name="payment[<?php echo $_code; ?>_new_credito_parcelamento_<?php echo $num; ?>_<?php echo $c; ?>]"
377
- onchange="checkInstallments(this, '<?php echo Mage::getUrl('', array('_secure' => true)); ?>');">
378
- <?php foreach ($this->getInstallments() as $key => $parcel): ?>
379
- <option value="<?php echo $key ?>"><?php echo $parcel ?></option>
380
- <?php endforeach ?>
 
 
381
  </select>
382
  </div>
383
 
384
  </div>
385
  </li>
386
  <?php endif; ?>
387
- <?php if ($standard->getConfigData('clearsale') && !$_taxvat->isEnabled() && Mage::getSingleton('customer/session')->getCustomer()->getTaxvat() == ''): ?>
 
 
 
 
 
 
388
  <li style="margin-bottom: 5px;">
389
  <div class="field">
390
- <label class="required"><?php echo $this->__('CPF ou CNPJ') ?> <span
391
- class="required">*</span></label>
392
  <div class="input-box">
393
- <input type="text"
394
- id="<?php echo $_code; ?>_cc_taxvat_<?php echo $num; ?>_<?php echo $c; ?>"
395
- name="payment[<?php echo $_code; ?>_cc_taxvat_<?php echo $num; ?>_<?php echo $c; ?>]"
396
- title="<?php echo $this->__('CPF ou CNPJ') ?>"
397
- class="validar_cpf required-entry"
398
- onkeydown="remove_characters(event);"/>
 
 
399
  </div>
400
  </div>
401
  </li>
@@ -407,10 +526,12 @@ $_code = $this->getMethodCode();
407
  <div class="input-box" style="padding-top: 10px">
408
  <div class="field">
409
  <label class="required"><?php echo $this->__('Save Card On File') ?></label>
410
- <input type="checkbox"
411
- id="<?php echo $_code; ?>_save_token_<?php echo $num; ?>_<?php echo $c; ?>"
412
- name="payment[<?php echo $_code; ?>_save_token_<?php echo $num; ?>_<?php echo $c; ?>]"
413
- value="new"/>
 
 
414
  </div>
415
 
416
  </div>
@@ -418,6 +539,20 @@ $_code = $this->getMethodCode();
418
  <?php endif; ?>
419
  <?php endif; ?>
420
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  <?php endfor; ?>
422
  </ul>
423
  <?php endif ?>
@@ -436,12 +571,23 @@ $_code = $this->getMethodCode();
436
  var ccExpMonth = v;
437
  var ccExpYear = $(elm.id.replace("_expirationMonth", "_expirationYear")).value;
438
 
 
 
 
 
 
 
 
 
 
 
439
  var currentTime = new Date();
440
  var currentMonth = currentTime.getMonth() + 1;
441
  var currentYear = currentTime.getFullYear().toString().substr(2, 2);
442
  if (ccExpMonth < currentMonth && ccExpYear == currentYear) {
443
  return false;
444
  }
 
445
  return true;
446
  }]
447
  ]);
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  $standard = $this->getStandard();
3
 
4
  // Get Quote
13
  $data = $quote->getShippingAddress();
14
  }
15
 
 
16
  // Partial payment?
17
  $isPartial = Mage::getSingleton('checkout/session')->getApprovalRequestSuccess();
18
 
36
  $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat');
37
 
38
  // Get current currency symbol
39
+ $currencySymbol =
40
+ Mage::app()
41
+ ->getLocale()
42
+ ->currency(
43
+ Mage::app()
44
+ ->getStore()
45
+ ->getCurrentCurrencyCode()
46
+ )
47
+ ->getSymbol();
48
 
49
  //Credit Card Saved On File
50
  $ccs = $this->getCcs();
53
 
54
  // Payment method
55
  $_code = $this->getMethodCode();
 
56
 
57
 
58
+ $cart = Mage::getSingleton('checkout/cart');
59
+ $cartQuote = $cart->getQuote();
60
+
61
+ $items = $cartQuote->getAllItems();
62
+ $recurrent = false;
63
+ foreach ($items as $item) {
64
+
65
+ foreach ($item->getOptions() as $option) {
66
+ $product = $option->getProduct();
67
+ $product->load($product->getId());
68
+
69
+ if ($product->getMundipaggRecurrent()) {
70
+ $recurrent = true;
71
+ $frequency = $product->getMundipaggFrequencyEnum();
72
+ $interval = $product->getMundipaggRecurrences();
73
+ $recurrenceMix = $product->getMundipaggRecurrenceMix();
74
+ }
75
+ }
76
+ }
77
+
78
+ $frequencyType = [
79
+ 'Daily' => 'Day',
80
+ 'Weekly' => 'Week',
81
+ 'Monthly' => 'Month',
82
+ 'Quarterly' => 'Quarter',
83
+ 'Biannual' => 'Semester',
84
+ 'Yearly' => 'Year'
85
+ ];
86
+
87
+ $recurrenceFinalDate = false;
88
+ $recurrenceTotalString = "";
89
+ $recFinal = "";
90
+ $recurrenceFinalDate = "";
91
+ if ($recurrent) {
92
+ $freq = $frequencyType[$frequency];
93
+
94
+ switch (strtolower($freq)) {
95
+ case 'quarter':
96
+ $interval *= 3;
97
+ $freq = 'Month';
98
+ break;
99
+ case 'semester':
100
+ $interval *= 6;
101
+ $freq = 'Month';
102
+ break;
103
+ }
104
+ $recFinal = strtotime('+' . $interval . ' ' . $freq . 's');
105
+ $recurrenceFinalDate = date('Y/m/01', $recFinal);
106
+ if ($recurrenceMix) {
107
+
108
+ $newBaseGrandTotal = $baseGrandTotal / $interval;
109
+ $recurrenceTotalString =
110
+ '<strong>' .
111
+ $currencySymbol .
112
+ number_format($newBaseGrandTotal, "2", ",", ".") . '/' .
113
+ strtolower($this->__($frequencyType[$frequency])) .
114
+ ' ' . $this->__('by') . ' ' .
115
+ $interval . ' ' .
116
+ $this->__($frequencyType[$frequency] .'s') .
117
+ '</strong>'.
118
+ '<p>Fim do ciclo: ' . date("m/Y", $recFinal) . "</p>";
119
+ }
120
+ }
121
+ ?>
122
+
123
  <ul id="payment_form_<?php echo $_code ?>" style="display:none;">
124
  <div>
125
  <input type="hidden" id="baseGrandTotal" name="baseGrandTotal"
126
  value="<?php echo number_format($baseGrandTotal, "2", ",", ""); ?>"/>
127
  <?php if ($isPartial == 'partial'): ?>
128
+ <input type="hidden" name="partial" id="partial" value="1"/>
129
+ <input type="hidden" name="payment[multi]" id="multi" value="1"/>
130
  <?php endif; ?>
131
  </div>
132
  <?php
152
  $paymentMethodLabel = $this->__('Pay with 2 Credit Cards');
153
  break;
154
 
155
+ case 'mundipagg_recurrencepayment':
156
+ $num = 1;
157
+ $paymentMethod = '1CreditCards';
158
+ $paymentMethodLabel = $this->__('Credit Card');
 
 
 
 
 
 
159
  break;
160
 
 
 
 
 
 
161
  endswitch;
162
+
163
  ?>
164
  <li>
165
  <div id="<?php echo $_code; ?>">
166
+ <?php if ($num != 1 && $isPartial != 'partial'){ ?>
167
  <p></p>
168
  <div>
169
+ <b><?php echo $this->__('Grand Total') ?>:</b>
170
+ <?php echo $currencySymbol . number_format($baseGrandTotal, "2", ",", "."); ?>
171
  </div>
172
  <p></p>
173
+ <?php } ?>
174
+ <?php
175
+ if (
176
+ $_code == 'mundipagg_creditcardoneinstallment' ||
177
+ $_code == 'mundipagg_creditcard' ||
178
+ $_code == 'mundipagg_twocreditcards' ||
179
+ $_code == 'mundipagg_recurrencepayment'
180
+ ): ?>
181
  <ul>
182
+ <?php for ($c = 1; $c <= $num; $c++): ?>
183
+ <input
184
+ type="hidden"
185
+ id="mundipagg_type"
186
+ name="payment[mundipagg_type]"
187
+ value="<?php echo $paymentMethod; ?>"
188
+ />
189
+ <?php $currentSelectedToken = null; ?>
190
+ <?php
191
+ if ($countCcs > 0) {
192
+ $ccsData = $ccs->getData();
193
+ $expiresAt = $ccsData[0]["expires_at"];
194
+ }
195
+ ?>
196
+ <?php if ($countCcs > 0): ?>
197
  <li class="fields" style="margin-bottom: 5px;">
198
  <div class="field">
199
  <label class="required"><?php echo $this->__('Select a Credit Card or add a new one') ?>
200
  <span class="required">*</span></label>
201
  <div class="input-box">
202
+ <select id="<?php echo $_code; ?>_token_<?php echo $num . '_' . $c; ?>"
203
+ data="group_<?php echo $num . '_' . $c; ?>"
204
+ name="payment[<?php echo $_code; ?>_token_<?php echo $num . '_' . $c; ?>]"
205
+ class="required-entry tokens group_<?php echo $num . '_' . $c; ?>"
206
  onchange="token_or_not(<?php echo $num; ?>,<?php echo $c; ?>,this)">
207
  <option value="">...</option>
208
  <?php
217
  if ($countCcs == 1) {
218
  $currentSelectedToken = Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cc->getCcType());
219
  }
220
+ $dataType =
221
+ $currentSelectedToken ? $currentSelectedToken :
222
+ Mage::getSingleton('mundipagg/source_cctypes')->getCcTypeForLabel($cc->getCcType());
223
+
224
+ $value = $cc->getId();
225
+ $mask = $cc->getCreditCardMask();
226
+
227
+ if ($_code === 'mundipagg_recurrencepayment') {
228
+ if (strtotime($recurrenceFinalDate) > strtotime($expiresAt)) {
229
+ $value = "";
230
+ $mask .= " (Data de validade do cartão menor do que a data da compra)";
231
+ }
232
+ }
233
+
234
+ echo '<option value="' .
235
+ $value .
236
+ '" ' .
237
+ $selected .
238
+ ' data="' .
239
+ $dataType . '">' .
240
+ $dataType .
241
+ ' ' .
242
+ $mask .
243
+ '</option>';
244
  endforeach;
245
  ?>
246
  <option value="new"><?php echo $this->__('New Credit Card') ?></option>
249
  </div>
250
  </li>
251
  <?php if ($num != 1): ?>
252
+ <div id="value_<?php echo $num . '_' . $c; ?>">
253
  <li class="fields" style="margin-bottom: 5px;">
254
  <div class="field">
255
  <label class="required"><?php echo $this->__('Value (Ex: 100,50)') ?> <span
256
  class="required">*</span></label>
257
  <div class="input-box">
258
  <input type="text"
259
+ id="<?php echo $_code; ?>_value_<?php echo $num . '_' . $c; ?>"
260
+ name="payment[<?php echo $_code; ?>_value_<?php echo $num . '_' . $c; ?>]"
261
  title="<?php echo $this->__('Value (Ex: 100,50)') ?>"
262
+ class="required-entry validate-greater-than-zero input-text check_values <?php echo 'group_' . $num . '_' . $c; ?>"
263
+ onchange="calculateInstallmentValue(
264
+ this,
265
+ <?php echo $num; ?>,
266
+ <?php echo $c; ?>,
267
+ '<?php echo Mage::getUrl('', array('_secure' => true)); ?>'
268
+ );"
269
+ onkeydown="remove_special_characters(event);"
270
+ value=""
271
+ />
272
  </div>
273
  </div>
274
  </li>
275
  </div>
276
  <?php endif; ?>
277
+ <?php
278
+ if (
279
+ $installmentsHelper->isInstallmentsEnabled() &&
280
+ $_code != 'mundipagg_creditcardoneinstallment' &&
281
+ $_code != 'mundipagg_recurrencepayment'
282
+ ):
283
+ ?>
284
+ <div
285
+ id="<?php echo 'parcelamento_' . $num . '_' . $c; ?>"
286
+ <?php if ($countCcs > 1): ?>style="display:none"<?php endif ?>
287
+ >
288
  <li class="fields" style="margin-bottom: 5px;">
289
  <div class="field">
290
+ <label class="required"><?php echo $this->__('Credit options') ?></label>
 
291
  <div class="input-box">
292
  <?php $this->getInstallments(); ?>
293
+ <select id="<?php echo $_code . '_credito_parcelamento_' . $num . '_' . $c; ?>"
294
+ name="payment[<?php echo $_code . '_credito_parcelamento_' . $num . '_' . $c; ?>]"
295
+ class="required-entry installment-token <?php echo 'group_' . $num . '_' . $c; ?>"
296
+ >
297
+ <?php
298
+ foreach (
299
+ $this->getInstallments($currentSelectedToken)
300
+ as $key => $parcel
301
+ ):
302
+ ?>
303
+ <option value="<?php echo $key ?>"><?php echo $parcel ?></option>
304
+ <?php endforeach ?>
305
  </select>
306
  </div>
307
  </div>
310
  <?php endif; ?>
311
  <?php endif; ?>
312
  <div class="division"></div>
313
+ <div id="<?php echo $_code . '_new_credit_card_' . $num . '_' . $c; ?>"
314
+ class=""<?php if ($countCcs > 0) { ?>style="display:none"<?php } ?>>
315
 
316
  <li style="margin-bottom: 5px;">
317
  <div class="field">
325
  ?>
326
  <?php foreach ($ccards as $ccard): ?>
327
  <li class="cc_brands">
328
+ <div
329
+ class="cc_brand_types <?php echo strtolower($ccard); ?>"
330
+ >
331
+ &nbsp;
332
+ </div>
333
  <input type="radio"
334
+ name="<?php echo 'payment[' . $_code . '_' . $num . '_' . $c . '_credito_instituicao]'; ?>"
335
+ id="<?php echo $_code . '_' . $num . '_' . $c . '_credito_instituicao_' . $ccard; ?>"
336
  value="<?php echo $ccard ?>"
337
  class="<?php if ($_i == 1): ?>validate-one-required-by-name<?php endif; ?>"
338
+ onclick="setCcType(this, '<?php echo $_code; ?>', '<?php echo $num; ?>', '<?php echo $c; ?>', '<?php echo $ccard; ?>');"
339
+ >
340
  </li>
341
  <?php
342
  $_i++;
343
  endforeach
344
  ?>
345
  </ul>
346
+ <p class="info-payment">
347
+ <i>
348
+ <small><?php echo $this->__('The flag is automatically selected after entering the credit card number below.'); ?></small>
349
+ </i>
350
+ </p>
351
  <input type="hidden"
352
+ name="<?php echo 'payment[' . $_code . '_' . $num . '_' . $c . '_cc_type]'; ?>"
353
+ id="<?php echo $_code . '_' . $num . '_' . $c . '_cc_type'; ?>"
354
  value="" class="validate-cc-type-select"/>
355
  </div>
356
  </div>
360
  <label class="required"><?php echo $this->__('Credit Card Number') ?> <span
361
  class="required">*</span></label>
362
  <div class="input-box">
363
+ <input
364
+ type="text"
365
+ id="<?php echo $_code . '_' . $num . '_' . $c; ?>_cc_number"
366
+ name="payment[<?php echo $_code . '_' . $num . '_' . $c; ?>_cc_number]"
367
+ title="<?php echo $this->__('Credit Card Number') ?>"
368
+ class="input-text required-entry validate-cc-number"
369
+ onkeydown="remove_characters(event);"
370
+ value=""
371
+ />
372
  </div>
373
  </div>
374
  </li>
378
  class="required">*</span></label>
379
  <div class="input-box">
380
  <input type="text"
381
+ id="<?php echo $_code . '_cc_holder_name_' . $num . '_' . $c; ?>"
382
+ name="payment[<?php echo $_code . '_cc_holder_name_' . $num . '_' . $c; ?>]"
383
+ class="required-entry input-text"
384
+ />
385
  </div>
386
  </div>
387
  </li>
391
  class="required">*</span></label>
392
  <div class="input-box">
393
  <div class="v-fix">
394
+ <select id="<?php echo $_code . '_expirationMonth_' . $num . '_' . $c; ?>"
395
+ name="payment[<?php echo $_code . '_expirationMonth_' . $num . '_' . $c; ?>]"
396
  class="month required-entry validate-cc-exp-new">
397
  <option value=""><?php echo $this->__('Month') ?></option>
398
  <option value="1">01 - <?php echo $this->__('January') ?></option>
410
  </select>
411
  </div>
412
  <div class="v-fix" style="padding-left:6px;">
413
+ <select id="<?php echo $_code . '_expirationYear_' . $num . '_' . $c; ?>"
414
+ name="payment[<?php echo $_code . '_expirationYear_' . $num . '_' . $c; ?>]"
415
  class="year required-entry">
416
  <option value=""><?php echo $this->__('Year') ?></option>
417
  <?php
429
  </li>
430
  <li style="margin-bottom: 5px;">
431
  <div class="field">
432
+ <label class="required"><?php echo $this->__('Card Verification Number') ?> <span class="required">*</span></label>
 
433
  <div class="input-box">
434
  <div class="v-fix">
435
+ <input
436
+ type="text"
437
+ id="<?php echo $_code . '_cc_cid_' . $num . '_' . $c; ?>"
438
+ name="payment[<?php echo $_code . '_cc_cid_' . $num . '_' . $c; ?>]"
439
+ style="width: 55px"
440
+ class="required-entry input-text validate-cc-cvn validate-length"
441
+ maxlength="4"
442
+ onkeydown="remove_characters(event);"
443
+ />
444
  </div>
445
  <div class="v-fix" style="padding-left:6px;">
446
+ <a href="#" class="cvv-what-is-this"><?php echo $this->__('What is this?') ?></a>
 
447
  </div>
448
  </div>
449
  </div>
451
  <?php if ($num != 1): ?>
452
  <li style="margin-bottom: 5px;">
453
  <div class="field">
454
+ <label class="required"><?php echo $this->__('Value (Ex: 100,50)') ?> <span class="required">*</span></label>
 
455
  <div class="input-box">
456
+ <input
457
+ type="text"
458
+ id="<?php echo $_code . '_new_value_' . $num . '_' . $c; ?>"
459
+ name="<?php echo 'payment[' . $_code . '_new_value_' . $num . '_' . $c . ']'; ?>"
460
+ title="<?php echo $this->__('Value (Ex: 100,50)') ?>"
461
+ class="required-entry input-text validate-greater-than-zero check_values"
462
+ onchange="calculateInstallmentValue(
463
+ this,
464
+ <?php echo $num; ?>,
465
+ <?php echo $c; ?>,
466
+ '<?php echo Mage::getUrl('', array('_secure' => true)); ?>'
467
+ );"
468
+ onkeydown="remove_special_characters(event);"
469
+ value=""
470
+ />
471
  </div>
472
  </div>
473
  </li>
474
  <?php endif; ?>
475
+ <?php
476
+ if ($installmentsHelper->isInstallmentsEnabled() &&
477
+ $_code != 'mundipagg_creditcardoneinstallment' &&
478
+ $_code != 'mundipagg_recurrencepayment'
479
+ ):
480
+ ?>
481
  <li style="margin-bottom: 5px;">
482
  <div class="field">
483
+ <label class="required"><?php echo $this->__('Credit options') ?></label>
 
484
  <div class="input-box">
485
+ <select
486
+ id="<?php echo $_code . '_new_credito_parcelamento_' . $num . '_' . $c; ?>"
487
+ name="<?php echo 'payment[' . $_code . '_new_credito_parcelamento_' . $num . '_' . $c . ']'; ?>"
488
+ onchange="checkInstallments(this, '<?php echo Mage::getUrl('', array('_secure' => true)); ?>');"
489
+ >
490
+ <?php foreach ($this->getInstallments() as $key => $parcel): ?>
491
+ <option value="<?php echo $key ?>"><?php echo $parcel ?></option>
492
+ <?php endforeach ?>
493
  </select>
494
  </div>
495
 
496
  </div>
497
  </li>
498
  <?php endif; ?>
499
+ <?php
500
+ if (
501
+ $standard->getConfigData('clearsale') &&
502
+ !$_taxvat->isEnabled() &&
503
+ Mage::getSingleton('customer/session')->getCustomer()->getTaxvat() == ''
504
+ ):
505
+ ?>
506
  <li style="margin-bottom: 5px;">
507
  <div class="field">
508
+ <label class="required"><?php echo $this->__('CPF ou CNPJ') ?> <span class="required">*</span></label>
 
509
  <div class="input-box">
510
+ <input
511
+ type="text"
512
+ id="<?php echo $_code . '_cc_taxvat_' . $num . '_' . $c; ?>"
513
+ name="<?php echo 'payment[' . $_code . '_cc_taxvat_' . $num . '_' . $c . ']'; ?>"
514
+ title="<?php echo $this->__('CPF ou CNPJ') ?>"
515
+ class="validar_cpf required-entry"
516
+ onkeydown="remove_characters(event);"
517
+ />
518
  </div>
519
  </div>
520
  </li>
526
  <div class="input-box" style="padding-top: 10px">
527
  <div class="field">
528
  <label class="required"><?php echo $this->__('Save Card On File') ?></label>
529
+ <input
530
+ type="checkbox"
531
+ id="<?php echo $_code . '_save_token_' . $num . '_' . $c; ?>"
532
+ name="<?php echo 'payment[' . $_code . '_save_token_' . $num . '_' . $c . ']'; ?>"
533
+ value="new"
534
+ />
535
  </div>
536
 
537
  </div>
539
  <?php endif; ?>
540
  <?php endif; ?>
541
  </div>
542
+ <?php
543
+ if ($recurrenceFinalDate) {
544
+ echo "<input id='recurrenceFinalDate' type='hidden' value='" . $recurrenceFinalDate . "' />";
545
+ } else {
546
+ echo "<input id='recurrenceFinalDate' type='hidden' value='' />";
547
+ }
548
+ ?>
549
+ <?php if ($_code === 'mundipagg_recurrencepayment') { ?>
550
+ <li style="margin-bottom: 5px;" class="recurrenceTotal">
551
+ <br>
552
+ <p><b><?php echo $this->__('Recurrent payment'); ?></b></p>
553
+ <p><?php echo $recurrenceTotalString; ?></p>
554
+ </li>
555
+ <?php } ?>
556
  <?php endfor; ?>
557
  </ul>
558
  <?php endif ?>
571
  var ccExpMonth = v;
572
  var ccExpYear = $(elm.id.replace("_expirationMonth", "_expirationYear")).value;
573
 
574
+ //Recurrence expiration check
575
+ var expiration = new Date("20" + ccExpYear + "/" + ('0000'+ccExpMonth).slice(-2) + "/01");
576
+
577
+ if (document.getElementById("recurrenceFinalDate").value.length > 0) {
578
+ var recurrenceExpiration = new Date(document.getElementById("recurrenceFinalDate").value);
579
+ if(expiration.getTime() < recurrenceExpiration.getTime()){
580
+ return false;
581
+ }
582
+ }
583
+
584
  var currentTime = new Date();
585
  var currentMonth = currentTime.getMonth() + 1;
586
  var currentYear = currentTime.getFullYear().toString().substr(2, 2);
587
  if (ccExpMonth < currentMonth && ccExpYear == currentYear) {
588
  return false;
589
  }
590
+
591
  return true;
592
  }]
593
  ]);
app/locale/en_US/Uecommerce_Mundipagg.csv CHANGED
@@ -44,7 +44,13 @@
44
  "Credit Card Holder name","Credit Card Holder name"
45
  "Credit Card Number","Credit Card Number"
46
  "Expiration date","Expiration date"
 
 
 
47
  "Month","Month"
 
 
 
48
  "January","January"
49
  "February","February"
50
  "March","March"
@@ -151,4 +157,18 @@
151
  "If you just update the module and its old version is below 2.0.0, you can click this button to generate the installments as were set in the old version of the module.","If you just update the module and its old version is below 2.0.0, you can click this button to generate the installments as were set in the old version of the module."
152
  "If you have already set manually, CAUTION! This function will reset all installments.","If you have already set manually, CAUTION! This function will reset all installments."
153
  "Back to shopping cart", "View Shopping Cart"
154
- "Not authorized credit card", "Not authorized credit card"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  "Credit Card Holder name","Credit Card Holder name"
45
  "Credit Card Number","Credit Card Number"
46
  "Expiration date","Expiration date"
47
+ "The payment finishes after the credit card expiration date","The payment finishes after the credit card expiration date"
48
+ "Day","Day"
49
+ "Week", "Week"
50
  "Month","Month"
51
+ "Quarter", "quarter"
52
+ "Semester", "semester"
53
+ "Year", "ano"
54
  "January","January"
55
  "February","February"
56
  "March","March"
157
  "If you just update the module and its old version is below 2.0.0, you can click this button to generate the installments as were set in the old version of the module.","If you just update the module and its old version is below 2.0.0, you can click this button to generate the installments as were set in the old version of the module."
158
  "If you have already set manually, CAUTION! This function will reset all installments.","If you have already set manually, CAUTION! This function will reset all installments."
159
  "Back to shopping cart", "View Shopping Cart"
160
+ "Not authorized credit card", "Not authorized credit card"
161
+ "by", "for"
162
+ "days", "days"
163
+ "weeks", "weeks"
164
+ "months", "months"
165
+ "Quarters", "quarters"
166
+ "Semester", "semester"
167
+ "years", "years"
168
+ "Recurrent payment", "Recurrent payment"
169
+ "Daily", "Daily"
170
+ "Weekly", "Weekly"
171
+ "Montly", "Montly"
172
+ "Quarterly", "Quarterly"
173
+ "Biannual", "Biannual"
174
+ "Yearly", "Yearly"
app/locale/pt_BR/Uecommerce_Mundipagg.csv CHANGED
@@ -42,7 +42,12 @@
42
  "Credit Card Holder name","Nome completo no Cartão de Crédito"
43
  "Credit Card Number","Número do Cartão de Crédito"
44
  "Expiration date","Data de expiração do Cartão de Crédito"
 
 
45
  "Month","Mês"
 
 
 
46
  "January","Janeiro"
47
  "February","Fevereiro"
48
  "March","Março"
@@ -178,6 +183,7 @@
178
  "The taxvat is invalid","O CPF ou CNPJ informado é inválido"
179
  "Check the values to pass on each card","Confira os valores a passar em cada cartão"
180
  "Expiration date of the incorrect card","Data de expiração do Cartão incorreta"
 
181
  "Total amount with interest: USD{%%%}","<b>Valor total c/ juros: </b>R${%%%}"
182
  "with interest","c/ juros"
183
  "without interest","s/ juros"
@@ -231,4 +237,12 @@
231
  "Transaction ID","ID da transação"
232
  "Acquirer message","Retorno da adquirente"
233
  "Back to shopping cart", "Voltar para carrinho de compras"
234
- "Not authorized credit card", "Cartão não autorizado"
 
 
 
 
 
 
 
 
42
  "Credit Card Holder name","Nome completo no Cartão de Crédito"
43
  "Credit Card Number","Número do Cartão de Crédito"
44
  "Expiration date","Data de expiração do Cartão de Crédito"
45
+ "Day","Dia"
46
+ "Week", "Semana"
47
  "Month","Mês"
48
+ "Quarter", "trimestre"
49
+ "Semester", "semestre"
50
+ "Year", "ano"
51
  "January","Janeiro"
52
  "February","Fevereiro"
53
  "March","Março"
183
  "The taxvat is invalid","O CPF ou CNPJ informado é inválido"
184
  "Check the values to pass on each card","Confira os valores a passar em cada cartão"
185
  "Expiration date of the incorrect card","Data de expiração do Cartão incorreta"
186
+ "The payment finishes after the credit card expiration date","A data de expiração do seu cartão é menor do que o final do ciclo de pagamento"
187
  "Total amount with interest: USD{%%%}","<b>Valor total c/ juros: </b>R${%%%}"
188
  "with interest","c/ juros"
189
  "without interest","s/ juros"
237
  "Transaction ID","ID da transação"
238
  "Acquirer message","Retorno da adquirente"
239
  "Back to shopping cart", "Voltar para carrinho de compras"
240
+ "Not authorized credit card", "Cartão não autorizado"
241
+ "by", "por"
242
+ "Days", "dias"
243
+ "Weeks", "semanas"
244
+ "Months", "meses"
245
+ "Quarters", "trimestres"
246
+ "Semester", "semestres"
247
+ "Years", "anos"
248
+ "Recurrent payment", "Pagamento recorrente"
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mundipagg_Integracao</name>
4
- <version>2.11.02</version>
5
  <stability>stable</stability>
6
  <license>MITL</license>
7
  <channel>community</channel>
@@ -26,11 +26,11 @@ A MundiPagg ir&#xE1; notificar a loja das atualiza&#xE7;&#xF5;es do status de pa
26
  &#xD;
27
  IMPORTANTE&#xD;
28
  Em qualquer procedimento de instala&#xE7;&#xE3;o ou update existem riscos, aconselhamos sempre criar backups de sua loja e efetuar qualquer procedimento em ambiente de desenvolvimento antes, nunca diretamente em produ&#xE7;&#xE3;o. N&#xE3;o nos responsabilizamos por eventuais incidentes causados por negligenciar este alerta ou por uso de produtos ou servi&#xE7;os de terceiros.</description>
29
- <notes>- Fix: remove duplicated boleto status</notes>
30
  <authors><author><name>mundipagg</name><user>mundi</user><email>mundi@mundipagg.com</email></author></authors>
31
- <date>2017-08-04</date>
32
- <time>14:12:42</time>
33
- <contents><target name="magecommunity"><dir name="Uecommerce"><dir name="Mundipagg"><dir name="Block"><dir name="Adminhtml"><dir name="Form"><dir name="Field"><file name="Installments.php" hash="ec8343e197cb194d978400bbdf64d446"/></dir></dir><dir name="Sales"><dir name="Order"><dir name="Creditmemo"><file name="Totals.php" hash="2140a7836eaa57e03727433ccddf93d6"/></dir><dir name="Invoice"><file name="Totals.php" hash="ee304d9034ae0763e5db464f933b8c27"/><file name="View.php" hash="b0e3c170cd0184a5dfbe4fa7a486b471"/></dir><file name="Totals.php" hash="71b20a4c0022c14a5f7f8d008aabe1da"/></dir><dir name="Transactions"><dir name="Detail"><file name="Grid.php" hash="d67911c431587e4327eec95540cf548a"/></dir></dir></dir><dir name="System"><dir name="Config"><dir name="Form"><file name="Button.php" hash="aa40a974b89c92ea9652c42e093d16f9"/></dir></dir></dir><file name="Version.php" hash="e3a89823e48e7a526a3afe8ce8c0d0ee"/></dir><dir name="Checkout"><dir name="Onepage"><dir name="Payment"><file name="Methods.php" hash="c903e413c47e3dea87ec09d609543a27"/></dir></dir></dir><file name="Info.php" hash="01f1a0c70a292c6c3bbaa2957569f420"/><file name="Parcelamento.php" hash="bbfad3557dd7c29e2a21a213cf915e0c"/><dir name="Sales"><dir name="Order"><dir name="Creditmemo"><file name="Totals.php" hash="be3e89b0e2f008fcc0293286d44df7da"/></dir><dir name="Invoice"><file name="Totals.php" hash="a39c41f45ef44b72d15cfd12fea4e9c6"/></dir><file name="Totals.php" hash="6f56aa360f48c715b30afd4e5cd4ddfa"/></dir></dir><dir name="Standard"><file name="Boleto.php" hash="4471015b8a82311f84e52e774460bf38"/><file name="Cancel.php" hash="095eaf31c6567fad440279aeb2994caa"/><file name="Debit.php" hash="c707d9572b6079457b9265cc09c920c6"/><file name="Fcancel.php" hash="4bc5b0fb68fb7fd11159788eafe958af"/><file name="Form.php" hash="e9a3d65f01c515bb5c931f704fc93340"/><file name="Partial.php" hash="fb5877a8f6c56ac1d6fc48eb864d8e60"/><file name="Redirect.php" hash="70f576c8d64c25e3ce627f6c36b2ff41"/><file name="Success.php" hash="b1b0bef88ed350d703da0e314ffad565"/></dir></dir><dir name="Controller"><file name="Abstract.php" hash="91d5069c18069fcb2a0a436fb768a194"/></dir><dir name="Helper"><file name="CheckoutSession.php" hash="21170a98bef7a3d6fc87044218251193"/><file name="Data.php" hash="eb9b6b62dcfa8ff71232de1f224a7d05"/><file name="Installments.php" hash="d0589866ed24ba418a4d1aaea503689e"/><file name="Log.php" hash="024416e493e894624f137b380e1c6d4b"/><file name="UnserializeArray.php" hash="83f968a1a32e0b974bb5607dd2f00463"/><file name="Util.php" hash="cab074ca10096c04e80950062de9bf28"/><file name="Version.php" hash="00066d5bf31a7c49db004f2bd0d5c462"/></dir><dir name="Model"><dir name="Adminvalidators"><dir name="Antifraud"><file name="Minval.php" hash="40a49fef644e180b50c896e9dab34c76"/></dir><file name="Debug.php" hash="80bedd2d18fc0ad3888208d7255048cf"/><file name="Offlineretry.php" hash="b869cce6f6cca51cb5d928776a9122c1"/><file name="Timeout.php" hash="d770cbef860e43d62e2bcbdff8b6fb35"/></dir><file name="Api.php" hash="d58ebdff17a610724977d8a8417f1533"/><file name="Boleto.php" hash="b129ff844ccb5a9289af7b154cd9681e"/><file name="Cardonfile.php" hash="98395928a16313f8b4127e4e210cf953"/><file name="Creditcard.php" hash="dfef330d704354bd61de929092ae2f29"/><file name="Creditcardoneinstallment.php" hash="9c8fb51f1e43856b9972af9dc96f090f"/><dir name="Customer"><file name="Session.php" hash="7f15498648de23cf4feb5143071ec260"/></dir><file name="Customers.php" hash="a779e96a969b83d1b38df351eb4670d0"/><file name="Debit.php" hash="0d9e0cc0950484b163f0c78a0113e997"/><dir name="Enum"><file name="BoletoTransactionStatusEnum.php" hash="3fed0a36bb76497b85c50016af34d47a"/><file name="CreditCardTransactionStatusEnum.php" hash="4546716f63e6df57061b222002157ccd"/><file name="OrderStatusEnum.php" hash="fd42020aab9d5507b5e0c26957cd1abb"/><file name="TransactionTypeEnum.php" hash="52fc4049a9f2b120ad3ed99e296268f9"/></dir><file name="Fivecreditcards.php" hash="f94a416aabbc03a255d8d63f14b0e9ac"/><file name="Fourcreditcards.php" hash="1699b5d214607effc273753d6fcb9ed4"/><file name="Observer.php" hash="fbfe5173aad82f01b3933766f3b60d48"/><file name="Offlineretry.php" hash="394849df4873908dd43d3c15f75dc9d0"/><dir name="Order"><dir name="Invoice"><file name="Interest.php" hash="6bba5e87bae1a7ee94a827819b2ea4ce"/></dir><file name="Payment.php" hash="3cd8879acffafa87ffa85f04acc4e671"/></dir><file name="Overwriteflags.php" hash="89aa88cc9d2c038bb1505c90bd850d24"/><file name="Payment.php" hash="6efc3b0ad9bab589934115387caf0fce"/><file name="Providervalidation.php" hash="4906944bae20e3f683d6e5c4ba5304e3"/><dir name="Quote"><dir name="Address"><file name="Interest.php" hash="93aa0189a8556597697dbb239dbf3be7"/></dir></dir><file name="Recurrency.php" hash="a15c756fbd5295301991679d6d256655"/><dir name="Resource"><dir name="Cardonfile"><file name="Collection.php" hash="7b7d13bc6d7be8e5e1c5f945d59117f6"/></dir><file name="Cardonfile.php" hash="47d0107a9b1c3415aaf8784298361e84"/><dir name="Customers"><file name="Collection.php" hash="6caadd817abbcda527ba6d102585f2ff"/></dir><file name="Customers.php" hash="f50289a4c8362ddf7a79e4aa7c8a6387"/><dir name="Offlineretry"><file name="Collection.php" hash="ece14459f92f4751c70b4dede0364b40"/></dir><file name="Offlineretry.php" hash="f18698d68581de1e756e956afb19106b"/><file name="Setup.php" hash="42bda31d8497e1b0983775e17f7325a5"/></dir><dir name="Source"><file name="Antifraud.php" hash="8362e0bb2209bbf904a7f9b2edd59cee"/><file name="Banks.php" hash="b5d456a807cdf750a6458144e955cf2c"/><file name="CctypeProductInstallments.php" hash="7837f6865c905ba8f5393d080ebc1b3d"/><file name="Cctypes.php" hash="b55eb988a6a09f24b1088f15644961d0"/><file name="Debit.php" hash="9366bc3b900cf96ad5d2bce7e8d93ba7"/><file name="Environment.php" hash="f22bf02692c02d3f8859601ccf9cf90c"/><file name="FControlEnvironment.php" hash="5159f6e4d86ee9d280285b7198fa01e9"/><file name="Frequency.php" hash="9752c73679dee78efc83f468fe45a946"/><file name="Installments.php" hash="b04c05b92f7b8b5c025f23aad4457917"/><file name="PaymentAction.php" hash="c16639be23fd85c285f474922fd528a7"/><file name="PaymentMethods.php" hash="e12514ad00bf3fe3fb4e569b11da2c10"/></dir><file name="Standard.php" hash="015d11b02f424ed9dea199b4a1493b46"/><dir name="System"><dir name="Config"><dir name="Backend"><file name="Installments.php" hash="f0901bf05acd0b2c3fda41965f949583"/></dir></dir></dir><file name="Threecreditcards.php" hash="d57c7083595ae31b0b4ebd3d859646b1"/><file name="Twocreditcards.php" hash="2b33d9bea49558d185824416f2c43a85"/><file name="Urlvalidation.php" hash="e3ccd751eea54e282d30624192537cd8"/></dir><dir name="Test"><dir name="Selenium"><file name="Abstract.php" hash="caf0cd5ca47b13fb00be4230d1bb9132"/><file name="BoletoTest.php" hash="0718dc551376686dc6daaa3b57ddd1f9"/><dir name="CcTypes"><file name="CreditcardTest.php" hash="fde35369e57eb70f29f8defe1d7f06af"/><file name="CreditcardoneinstallmentTest.php" hash="cabcf9a3f56497e32679c1d2d063a6d7"/><file name="FivecreditcardsTest.php" hash="a903b89e20b9e754df7ed22dc9e8eecf"/><file name="FourcheditcardsTest.php" hash="3619a03b24af1a768cbc87be430b4323"/><file name="ThreecreditcardsTest.php" hash="d59c7b8a7de6320cff170e435fbe6e9e"/><file name="TwocreditcardsTest.php" hash="58db59f790aa7c65a324e6a552c2e05c"/></dir><file name="CcTypes.php" hash="fdb1cb980444a4cd35ace6543b9f335e"/><file name="DebitTest.php" hash="1409a8f2de15e13792dcba2099a887cc"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="e5a51c9660f704bcbfb302d34493a5a6"/></dir><file name="ClearsaleController.php" hash="bc06365f0d577d66228d9f0c3e471089"/><file name="FcontrolController.php" hash="1af534f1cdadbfdbe702aed12c7a2e1d"/><file name="StandardController.php" hash="f5cff033df37c15ce4d0b9efdcd0f393"/><file name="StoneController.php" hash="80c6f59a868ac82fc22bcf586bbecfdd"/></dir><dir name="data"><dir name="mundipagg_setup"><file name="data-upgrade-2.9.1-2.9.2.php" hash="6c8f542f7f04755cf8d2e3e8cb517b51"/></dir></dir><dir name="etc"><file name="config.xml" hash="88f7997b2632e87875a7826b6d4e32d5"/><file name="jstranslator.xml" hash="8b1ea10d9b3072a795567dba6dae938c"/><file name="system.xml" hash="cf2fa5e327876d2873f06d4aacea7011"/><file name="wsdl.xml" hash="5de00c9ba9bdf8e3096911867f6d6364"/><file name="xtest.xml" hash="b34ee3b6e37a890b73374b5ea3a1c40f"/></dir><dir name="sql"><dir name="mundipagg_setup"><file name="install-0.3.0.php" hash="ede73bb07d71fec55340c4249ff4a258"/><file name="mysql4-upgrade-0.3.0-0.3.5.php" hash="d3c200cce4a814feaa0858c0c8abd928"/><file name="mysql4-upgrade-0.3.5-0.4.0.php" hash="297f1b37b7703f7a0d621d227c8cbeb9"/><file name="mysql4-upgrade-0.3.5-1.0.1.php" hash="d22a0a81e392885433ca58dc196c2a86"/><file name="mysql4-upgrade-0.4.0-1.0.1.php" hash="297f1b37b7703f7a0d621d227c8cbeb9"/><file name="mysql4-upgrade-0.4.1-0.4.2.php" hash="4a2962a1eb974c75e153f48cc77f00d4"/><file name="mysql4-upgrade-0.4.1-1.0.1.php" hash="d22a0a81e392885433ca58dc196c2a86"/><file name="mysql4-upgrade-1.0.0-1.0.1.php" hash="297f1b37b7703f7a0d621d227c8cbeb9"/><file name="mysql4-upgrade-1.0.1-1.0.2.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.10-1.0.11.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.11-2.0.0.php" hash="83c95c6060bb8678be3b8944a6823fd9"/><file name="mysql4-upgrade-1.0.2-1.0.3.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.3-1.0.4.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.4-1.0.5.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.5-1.0.6.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.6-1.0.7.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.7-1.0.8.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.8-1.0.9.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.9-1.0.10.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.0-2.0.1.php" hash="a437df63647a52381ed5e056ccbb0cff"/><file name="mysql4-upgrade-2.0.0-2.1.0.php" hash="30dc2c3c763893d3bac6b9fde0c56477"/><file name="mysql4-upgrade-2.0.1-2.0.2.php" hash="4959ae51e69913d8ac642bc2ab848464"/><file name="mysql4-upgrade-2.0.2-2.0.3.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.3-2.0.4.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.4-2.0.5.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.5-2.0.6.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.6-2.0.7.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.7-2.0.8.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.8-2.0.9.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.9-2.1.0.php" hash="3488f42f3d9e6a57ce4176c0a7954171"/><file name="mysql4-upgrade-2.1.2-2.1.3.php" hash="7d7823cb555a32295d179a96e2bf987a"/><file name="mysql4-upgrade-2.5.7-2.5.8.php" hash="45c4f1fd5336b7ce578c672e8f1d57b0"/><file name="mysql4-upgrade-2.5.8-2.6.0.php" hash="bf06e3d6ab5fa0c89629385db4231006"/><file name="mysql4-upgrade-2.7.4-2.8.0.php" hash="c53fbd135b7735b7bbe90e5c4c11e5b2"/><file name="mysql4-upgrade-2.9.4-2.9.5.php" hash="29f3b305a7e44f66f2fc9841b668048c"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="mundipagg.xml" hash="035fd61eb33327a613e5b3b91ddbc389"/></dir><dir name="template"><dir name="mundipagg"><file name="boleto.phtml" hash="11cc5b254644727d6bdded8a834965c7"/><file name="form.phtml" hash="566e1838cab471ce41a1f74156e3b3bf"/><dir name="payment"><dir name="info"><file name="mundipagg.phtml" hash="3b1d4412c62780275114e37b63615a65"/></dir></dir><dir name="system"><dir name="config"><file name="button.phtml" hash="6a7f6c88cf156d31d34a818ac37bd158"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="mundipagg.xml" hash="0dc6cc39164b57626ccf7a429bbbf3d7"/></dir><dir name="template"><dir name="mundipagg"><dir name="antifraud"><file name="clearsale.phtml" hash="088a189dd94401f39c90ad0a1471994f"/><file name="fcontrol.phtml" hash="8fe2da3913bd18a20f35235533080ab8"/><file name="stone.phtml" hash="681ddf22694c725bb6e84e79681936fa"/></dir><file name="boleto.phtml" hash="dc31735a2753812d36e3080bf5b01ac2"/><file name="cancel.phtml" hash="540639b1ccd698397286f668bbf23746"/><file name="debit.phtml" hash="78f60f0227e99ff0c1d7dbf6bd5aa202"/><file name="extras.phtml" hash="f3eba84e971e890922141d90f6bdd53f"/><file name="fcancel.phtml" hash="9ce1d7634acf519669e21978b41aa277"/><file name="form.phtml" hash="46d83199636924d8e5757643bca9344f"/><file name="parcelamento.phtml" hash="56a89503637e5ad753b0d410f2f5c7ad"/><file name="partial.phtml" hash="3349856adf83a8293bcb197a9fbd3267"/><dir name="payment"><dir name="info"><file name="mundipagg.phtml" hash="c110a21db08013d38add1b79977350e4"/></dir></dir><file name="redirect.phtml" hash="a8a1123eab776934c64f57b4f9cfd517"/><file name="success.phtml" hash="7afd82f246fdf50f9a72ebb15086a2b6"/><file name="totals.phtml" hash="5a78aa3fe60d4b13bf8451f23bb9edd9"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="template"><dir name="mundipagg"><file name="debit.phtml" hash="4d2ae58447d3893499556ae068f800f8"/><file name="form.phtml" hash="70e1acffe4ba9eddbf9651f6630c12ac"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Uecommerce_Mundipagg.xml" hash="b292eeabde8e2cd06db0c31aff54fd98"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Uecommerce_Mundipagg.csv" hash="fcc515b20632bb8256399042625e5972"/></dir><dir name="pt_BR"><file name="Uecommerce_Mundipagg.csv" hash="d77207cfecb35ad278afb272c9fae751"/></dir></target><target name="mageweb"><dir name="js"><dir name="uecommerce"><dir name="fcontrol"><file name="fingerprint-fcontrol.js" hash="33409e94c34847788fabbb3a5b038fd0"/><file name="hmlg-fcontrol-ed.min.js" hash="b8b6c945111b6edd7a90df2f5d3ff5cd"/></dir><file name="jquery-3.1.0.min.js" hash="05e51b1db558320f1939f9789ccf5c8f"/><file name="mundipagg.js" hash="1bbf52070bdd06b7b0687f6cced1886f"/><file name="recurrency.js" hash="6c0db9f70fea794eb55f1db3bd09b4aa"/></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><dir name="mundipagg"><file name="ajax-loader.gif" hash="7b9776076d5fceef4993b55c9383dedd"/><file name="boleto.jpg" hash="237570c55c811b4b13f73ab92f28e599"/><file name="mundi-magento-admin-banner.png" hash="296659392e39a619f0618d491b13df15"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="mundipagg.css" hash="90c32001f3a9b858c9506f5135c04972"/></dir><dir name="images"><dir name="mundipagg"><file name="001.png" hash="25d10d6fee7fc3e5dc48021a15de8fb0"/><file name="237.png" hash="cbea9caff342edd9b9b9509bbbbae6fb"/><file name="341.png" hash="3645161fc56322ec34ebfcc006390e5d"/><file name="AE.png" hash="40ea216476033961d50f452bf4bca4df"/><file name="DI.png" hash="0f4264379e7b8ba6b1a30a3d69240ae2"/><file name="EL.png" hash="ad180c308d285f73fc044121cb6aeac0"/><file name="HI.png" hash="c25430ddd8e441cc2fc3ef68219e7668"/><file name="MC.png" hash="836466c092121163320e9e6279f11f8b"/><file name="VBV.jpg" hash="1a7db765956829e80715a299b799f580"/><file name="VBV.png" hash="d6fb7de65fda842f03e2b9fc89d5e6aa"/><file name="VI.png" hash="cc0709d50773fa2815f7bfeb741a4219"/><file name="ajax-loader.gif" hash="7b9776076d5fceef4993b55c9383dedd"/><file name="boleto.jpg" hash="237570c55c811b4b13f73ab92f28e599"/><file name="cc_types.png" hash="fdae60f96ee668354161b5a865b8e7ef"/><file name="cielo_mastercard.png" hash="e2c2af12ea24f1b82490fdcc62fbb871"/><file name="cielo_visa.png" hash="d2f0c660714dc319b73c0dac9c9108d0"/></dir></dir></dir></dir><dir name="default"><dir name="default"><dir name="images"><dir name="mundipagg"><file name="EL.png" hash="ad180c308d285f73fc044121cb6aeac0"/><file name="HI.png" hash="c25430ddd8e441cc2fc3ef68219e7668"/><file name="ae.png" hash="40ea216476033961d50f452bf4bca4df"/><file name="boleto.jpg" hash="237570c55c811b4b13f73ab92f28e599"/><file name="cielo_mastercard.png" hash="e2c2af12ea24f1b82490fdcc62fbb871"/><file name="cielo_visa.png" hash="d2f0c660714dc319b73c0dac9c9108d0"/><file name="di.png" hash="0f4264379e7b8ba6b1a30a3d69240ae2"/><file name="mc.png" hash="836466c092121163320e9e6279f11f8b"/><file name="vi.png" hash="cc0709d50773fa2815f7bfeb741a4219"/></dir></dir></dir></dir></dir></target><target name="mage"><dir name="."><file name="README.md" hash=""/></dir></target></contents>
34
  <compatible/>
35
- <dependencies><required><php><min>5.4.0</min><max>7.2.0</max></php></required></dependencies>
36
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Mundipagg_Integracao</name>
4
+ <version>2.12.05</version>
5
  <stability>stable</stability>
6
  <license>MITL</license>
7
  <channel>community</channel>
26
  &#xD;
27
  IMPORTANTE&#xD;
28
  Em qualquer procedimento de instala&#xE7;&#xE3;o ou update existem riscos, aconselhamos sempre criar backups de sua loja e efetuar qualquer procedimento em ambiente de desenvolvimento antes, nunca diretamente em produ&#xE7;&#xE3;o. N&#xE3;o nos responsabilizamos por eventuais incidentes causados por negligenciar este alerta ou por uso de produtos ou servi&#xE7;os de terceiros.</description>
29
+ <notes>- bugfixes and performance improves</notes>
30
  <authors><author><name>mundipagg</name><user>mundi</user><email>mundi@mundipagg.com</email></author></authors>
31
+ <date>2017-09-05</date>
32
+ <time>18:57:06</time>
33
+ <contents><target name="magecommunity"><dir name="Uecommerce"><dir name="Mundipagg"><dir name="Block"><dir name="Adminhtml"><dir name="Form"><dir name="Field"><file name="Installments.php" hash="ec8343e197cb194d978400bbdf64d446"/></dir></dir><dir name="Sales"><dir name="Order"><dir name="Creditmemo"><file name="Totals.php" hash="2140a7836eaa57e03727433ccddf93d6"/></dir><dir name="Invoice"><file name="Totals.php" hash="ee304d9034ae0763e5db464f933b8c27"/><file name="View.php" hash="b0e3c170cd0184a5dfbe4fa7a486b471"/></dir><file name="Totals.php" hash="71b20a4c0022c14a5f7f8d008aabe1da"/></dir><dir name="Transactions"><dir name="Detail"><file name="Grid.php" hash="d67911c431587e4327eec95540cf548a"/></dir></dir></dir><dir name="System"><dir name="Config"><dir name="Form"><file name="Button.php" hash="aa40a974b89c92ea9652c42e093d16f9"/></dir></dir></dir><file name="Version.php" hash="e3a89823e48e7a526a3afe8ce8c0d0ee"/></dir><dir name="Checkout"><dir name="Onepage"><dir name="Payment"><file name="Methods.php" hash="c903e413c47e3dea87ec09d609543a27"/></dir></dir></dir><file name="Info.php" hash="01f1a0c70a292c6c3bbaa2957569f420"/><file name="Parcelamento.php" hash="004e3a97ac3299c7ca397732b9a2ac47"/><dir name="Sales"><dir name="Order"><dir name="Creditmemo"><file name="Totals.php" hash="be3e89b0e2f008fcc0293286d44df7da"/></dir><dir name="Invoice"><file name="Totals.php" hash="a39c41f45ef44b72d15cfd12fea4e9c6"/></dir><file name="Totals.php" hash="6f56aa360f48c715b30afd4e5cd4ddfa"/></dir></dir><dir name="Standard"><file name="Boleto.php" hash="4471015b8a82311f84e52e774460bf38"/><file name="Cancel.php" hash="095eaf31c6567fad440279aeb2994caa"/><file name="Debit.php" hash="c707d9572b6079457b9265cc09c920c6"/><file name="Fcancel.php" hash="4bc5b0fb68fb7fd11159788eafe958af"/><file name="Form.php" hash="e9a3d65f01c515bb5c931f704fc93340"/><file name="Partial.php" hash="35f80bd15bace480de71716e2c610b37"/><file name="Redirect.php" hash="70f576c8d64c25e3ce627f6c36b2ff41"/><file name="Success.php" hash="b1b0bef88ed350d703da0e314ffad565"/></dir></dir><dir name="Controller"><file name="Abstract.php" hash="91d5069c18069fcb2a0a436fb768a194"/></dir><dir name="Helper"><file name="CheckoutSession.php" hash="21170a98bef7a3d6fc87044218251193"/><file name="Data.php" hash="c20bb71c01f05143ce034ea58c0505e3"/><file name="Installments.php" hash="d0589866ed24ba418a4d1aaea503689e"/><file name="Log.php" hash="024416e493e894624f137b380e1c6d4b"/><file name="Recurrence.php" hash="7bf2fb2b8b00b897b9afbcfba461a086"/><file name="UnserializeArray.php" hash="83f968a1a32e0b974bb5607dd2f00463"/><file name="Util.php" hash="cab074ca10096c04e80950062de9bf28"/><file name="Version.php" hash="00066d5bf31a7c49db004f2bd0d5c462"/></dir><dir name="Model"><dir name="Adminvalidators"><dir name="Antifraud"><file name="Minval.php" hash="40a49fef644e180b50c896e9dab34c76"/></dir><file name="Debug.php" hash="80bedd2d18fc0ad3888208d7255048cf"/><file name="Offlineretry.php" hash="758f3f6e6fb23722da11594660c88c2f"/><file name="Timeout.php" hash="d770cbef860e43d62e2bcbdff8b6fb35"/></dir><file name="Api.php" hash="755c8160764d579ad0498e61ff093056"/><file name="Boleto.php" hash="b129ff844ccb5a9289af7b154cd9681e"/><file name="Cardonfile.php" hash="98395928a16313f8b4127e4e210cf953"/><file name="Creditcard.php" hash="dfef330d704354bd61de929092ae2f29"/><file name="Creditcardoneinstallment.php" hash="9c8fb51f1e43856b9972af9dc96f090f"/><dir name="Customer"><file name="Session.php" hash="7f15498648de23cf4feb5143071ec260"/></dir><file name="Customers.php" hash="a779e96a969b83d1b38df351eb4670d0"/><file name="Debit.php" hash="0d9e0cc0950484b163f0c78a0113e997"/><dir name="Enum"><file name="BoletoTransactionStatusEnum.php" hash="3fed0a36bb76497b85c50016af34d47a"/><file name="CreditCardTransactionStatusEnum.php" hash="4546716f63e6df57061b222002157ccd"/><file name="OrderStatusEnum.php" hash="fd42020aab9d5507b5e0c26957cd1abb"/><file name="TransactionTypeEnum.php" hash="52fc4049a9f2b120ad3ed99e296268f9"/></dir><file name="Fivecreditcards.php" hash="f94a416aabbc03a255d8d63f14b0e9ac"/><file name="Fourcreditcards.php" hash="1699b5d214607effc273753d6fcb9ed4"/><file name="Observer.php" hash="889d43b896f0fb7db64c3b8caf28a0ac"/><file name="Offlineretry.php" hash="394849df4873908dd43d3c15f75dc9d0"/><dir name="Order"><dir name="Invoice"><file name="Interest.php" hash="6bba5e87bae1a7ee94a827819b2ea4ce"/></dir><file name="Payment.php" hash="3cd8879acffafa87ffa85f04acc4e671"/></dir><file name="Overwriteflags.php" hash="89aa88cc9d2c038bb1505c90bd850d24"/><file name="Payment.php" hash="6efc3b0ad9bab589934115387caf0fce"/><file name="Providervalidation.php" hash="4906944bae20e3f683d6e5c4ba5304e3"/><dir name="Quote"><dir name="Address"><file name="Interest.php" hash="aa9c11ebdb47fff5dfee01d03c05738c"/></dir></dir><file name="Recurrencepayment.php" hash="bec72291599bbcb09d8b7c1ed1441348"/><file name="Recurrency.php" hash="1fc7c1337489ba2b2d44655d0ff9a9f2"/><dir name="Resource"><dir name="Cardonfile"><file name="Collection.php" hash="7b7d13bc6d7be8e5e1c5f945d59117f6"/></dir><file name="Cardonfile.php" hash="47d0107a9b1c3415aaf8784298361e84"/><dir name="Customers"><file name="Collection.php" hash="6caadd817abbcda527ba6d102585f2ff"/></dir><file name="Customers.php" hash="f50289a4c8362ddf7a79e4aa7c8a6387"/><dir name="Offlineretry"><file name="Collection.php" hash="ece14459f92f4751c70b4dede0364b40"/></dir><file name="Offlineretry.php" hash="f18698d68581de1e756e956afb19106b"/><file name="Setup.php" hash="42bda31d8497e1b0983775e17f7325a5"/></dir><dir name="Source"><file name="Antifraud.php" hash="8362e0bb2209bbf904a7f9b2edd59cee"/><file name="Banks.php" hash="b5d456a807cdf750a6458144e955cf2c"/><file name="CctypeProductInstallments.php" hash="7837f6865c905ba8f5393d080ebc1b3d"/><file name="Cctypes.php" hash="ff970683a542378d4698cadcc50f9479"/><file name="Debit.php" hash="9366bc3b900cf96ad5d2bce7e8d93ba7"/><file name="Environment.php" hash="f22bf02692c02d3f8859601ccf9cf90c"/><file name="FControlEnvironment.php" hash="5159f6e4d86ee9d280285b7198fa01e9"/><file name="Frequency.php" hash="9752c73679dee78efc83f468fe45a946"/><file name="Installments.php" hash="b04c05b92f7b8b5c025f23aad4457917"/><file name="PaymentAction.php" hash="c16639be23fd85c285f474922fd528a7"/><file name="PaymentMethods.php" hash="e12514ad00bf3fe3fb4e569b11da2c10"/></dir><file name="Standard.php" hash="8964b072eb7a41732946d6490aff0996"/><dir name="System"><dir name="Config"><dir name="Backend"><file name="Installments.php" hash="f0901bf05acd0b2c3fda41965f949583"/></dir></dir></dir><file name="Threecreditcards.php" hash="d57c7083595ae31b0b4ebd3d859646b1"/><file name="Twocreditcards.php" hash="2b33d9bea49558d185824416f2c43a85"/><file name="Urlvalidation.php" hash="e3ccd751eea54e282d30624192537cd8"/></dir><dir name="Test"><dir name="Selenium"><file name="Abstract.php" hash="caf0cd5ca47b13fb00be4230d1bb9132"/><file name="BoletoTest.php" hash="0718dc551376686dc6daaa3b57ddd1f9"/><dir name="CcTypes"><file name="CreditcardTest.php" hash="fde35369e57eb70f29f8defe1d7f06af"/><file name="CreditcardoneinstallmentTest.php" hash="cabcf9a3f56497e32679c1d2d063a6d7"/><file name="FivecreditcardsTest.php" hash="a903b89e20b9e754df7ed22dc9e8eecf"/><file name="FourcheditcardsTest.php" hash="3619a03b24af1a768cbc87be430b4323"/><file name="ThreecreditcardsTest.php" hash="d59c7b8a7de6320cff170e435fbe6e9e"/><file name="TwocreditcardsTest.php" hash="58db59f790aa7c65a324e6a552c2e05c"/></dir><file name="CcTypes.php" hash="fdb1cb980444a4cd35ace6543b9f335e"/><file name="DebitTest.php" hash="1409a8f2de15e13792dcba2099a887cc"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="e5a51c9660f704bcbfb302d34493a5a6"/></dir><file name="ClearsaleController.php" hash="bc06365f0d577d66228d9f0c3e471089"/><file name="FcontrolController.php" hash="1af534f1cdadbfdbe702aed12c7a2e1d"/><file name="StandardController.php" hash="f5cff033df37c15ce4d0b9efdcd0f393"/><file name="StoneController.php" hash="80c6f59a868ac82fc22bcf586bbecfdd"/></dir><dir name="data"><dir name="mundipagg_setup"><file name="data-upgrade-2.9.1-2.9.2.php" hash="6c8f542f7f04755cf8d2e3e8cb517b51"/></dir></dir><dir name="etc"><file name="config.xml" hash="609e57f8744da6e35ebc97a5d6068476"/><file name="jstranslator.xml" hash="8b1ea10d9b3072a795567dba6dae938c"/><file name="system.xml" hash="393a0c3747cacc83d7a8b7edb3100fcd"/><file name="wsdl.xml" hash="5de00c9ba9bdf8e3096911867f6d6364"/><file name="xtest.xml" hash="b34ee3b6e37a890b73374b5ea3a1c40f"/></dir><dir name="sql"><dir name="mundipagg_setup"><file name="install-0.3.0.php" hash="ede73bb07d71fec55340c4249ff4a258"/><file name="mysql4-upgrade-0.3.0-0.3.5.php" hash="d3c200cce4a814feaa0858c0c8abd928"/><file name="mysql4-upgrade-0.3.5-0.4.0.php" hash="297f1b37b7703f7a0d621d227c8cbeb9"/><file name="mysql4-upgrade-0.3.5-1.0.1.php" hash="d22a0a81e392885433ca58dc196c2a86"/><file name="mysql4-upgrade-0.4.0-1.0.1.php" hash="297f1b37b7703f7a0d621d227c8cbeb9"/><file name="mysql4-upgrade-0.4.1-0.4.2.php" hash="4a2962a1eb974c75e153f48cc77f00d4"/><file name="mysql4-upgrade-0.4.1-1.0.1.php" hash="d22a0a81e392885433ca58dc196c2a86"/><file name="mysql4-upgrade-1.0.0-1.0.1.php" hash="297f1b37b7703f7a0d621d227c8cbeb9"/><file name="mysql4-upgrade-1.0.1-1.0.2.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.10-1.0.11.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.11-2.0.0.php" hash="83c95c6060bb8678be3b8944a6823fd9"/><file name="mysql4-upgrade-1.0.2-1.0.3.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.3-1.0.4.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.4-1.0.5.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.5-1.0.6.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.6-1.0.7.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.7-1.0.8.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.8-1.0.9.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-1.0.9-1.0.10.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.0-2.0.1.php" hash="a437df63647a52381ed5e056ccbb0cff"/><file name="mysql4-upgrade-2.0.0-2.1.0.php" hash="30dc2c3c763893d3bac6b9fde0c56477"/><file name="mysql4-upgrade-2.0.1-2.0.2.php" hash="4959ae51e69913d8ac642bc2ab848464"/><file name="mysql4-upgrade-2.0.2-2.0.3.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.3-2.0.4.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.4-2.0.5.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.5-2.0.6.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.6-2.0.7.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.7-2.0.8.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.8-2.0.9.php" hash="4c18b9eb1e0a08d858dde48280eed2c0"/><file name="mysql4-upgrade-2.0.9-2.1.0.php" hash="3488f42f3d9e6a57ce4176c0a7954171"/><file name="mysql4-upgrade-2.1.2-2.1.3.php" hash="7d7823cb555a32295d179a96e2bf987a"/><file name="mysql4-upgrade-2.5.7-2.5.8.php" hash="45c4f1fd5336b7ce578c672e8f1d57b0"/><file name="mysql4-upgrade-2.5.8-2.6.0.php" hash="bf06e3d6ab5fa0c89629385db4231006"/><file name="mysql4-upgrade-2.7.4-2.8.0.php" hash="c53fbd135b7735b7bbe90e5c4c11e5b2"/><file name="mysql4-upgrade-2.9.4-2.9.5.php" hash="29f3b305a7e44f66f2fc9841b668048c"/><file name="upgrade-2.11.01-2.12.01.php" hash="92fb0bc84ba9d64d61ad346c526ccc96"/><file name="upgrade-2.12.01-2.12.02.php" hash="92fb0bc84ba9d64d61ad346c526ccc96"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="mundipagg.xml" hash="035fd61eb33327a613e5b3b91ddbc389"/></dir><dir name="template"><dir name="mundipagg"><file name="boleto.phtml" hash="11cc5b254644727d6bdded8a834965c7"/><file name="form.phtml" hash="65c36527fed11ab791a96a7b62d8b4c1"/><dir name="payment"><dir name="info"><file name="mundipagg.phtml" hash="3b1d4412c62780275114e37b63615a65"/></dir></dir><dir name="system"><dir name="config"><file name="button.phtml" hash="6a7f6c88cf156d31d34a818ac37bd158"/></dir></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="mundipagg.xml" hash="0dc6cc39164b57626ccf7a429bbbf3d7"/></dir><dir name="template"><dir name="mundipagg"><dir name="antifraud"><file name="clearsale.phtml" hash="088a189dd94401f39c90ad0a1471994f"/><file name="fcontrol.phtml" hash="8fe2da3913bd18a20f35235533080ab8"/><file name="stone.phtml" hash="681ddf22694c725bb6e84e79681936fa"/></dir><file name="boleto.phtml" hash="dc31735a2753812d36e3080bf5b01ac2"/><file name="cancel.phtml" hash="540639b1ccd698397286f668bbf23746"/><file name="debit.phtml" hash="78f60f0227e99ff0c1d7dbf6bd5aa202"/><file name="extras.phtml" hash="f3eba84e971e890922141d90f6bdd53f"/><file name="fcancel.phtml" hash="9ce1d7634acf519669e21978b41aa277"/><file name="form.phtml" hash="46d83199636924d8e5757643bca9344f"/><file name="parcelamento.phtml" hash="312421e96cf279c188fd5e06407ace9c"/><file name="partial.phtml" hash="3349856adf83a8293bcb197a9fbd3267"/><dir name="payment"><dir name="info"><file name="mundipagg.phtml" hash="c110a21db08013d38add1b79977350e4"/></dir></dir><file name="redirect.phtml" hash="a8a1123eab776934c64f57b4f9cfd517"/><file name="success.phtml" hash="7afd82f246fdf50f9a72ebb15086a2b6"/><file name="totals.phtml" hash="5a78aa3fe60d4b13bf8451f23bb9edd9"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="template"><dir name="mundipagg"><file name="debit.phtml" hash="4d2ae58447d3893499556ae068f800f8"/><file name="form.phtml" hash="4b75f752d2176210fb6e24f832c3f7ce"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Uecommerce_Mundipagg.xml" hash="b292eeabde8e2cd06db0c31aff54fd98"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Uecommerce_Mundipagg.csv" hash="5fa9b3084b033a3125bd6c0d4a8ad167"/></dir><dir name="pt_BR"><file name="Uecommerce_Mundipagg.csv" hash="22333a4cf4685a1c01af814746be290f"/></dir></target><target name="mageweb"><dir name="js"><dir name="uecommerce"><dir name="fcontrol"><file name="fingerprint-fcontrol.js" hash="33409e94c34847788fabbb3a5b038fd0"/><file name="hmlg-fcontrol-ed.min.js" hash="b8b6c945111b6edd7a90df2f5d3ff5cd"/></dir><file name="jquery-3.1.0.min.js" hash="05e51b1db558320f1939f9789ccf5c8f"/><file name="mundipagg.js" hash="1bbf52070bdd06b7b0687f6cced1886f"/><file name="recurrency.js" hash="6c0db9f70fea794eb55f1db3bd09b4aa"/></dir></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><dir name="mundipagg"><file name="ajax-loader.gif" hash="7b9776076d5fceef4993b55c9383dedd"/><file name="boleto.jpg" hash="237570c55c811b4b13f73ab92f28e599"/><file name="mundi-magento-admin-banner.png" hash="296659392e39a619f0618d491b13df15"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="mundipagg.css" hash="90c32001f3a9b858c9506f5135c04972"/></dir><dir name="images"><dir name="mundipagg"><file name="001.png" hash="25d10d6fee7fc3e5dc48021a15de8fb0"/><file name="237.png" hash="cbea9caff342edd9b9b9509bbbbae6fb"/><file name="341.png" hash="3645161fc56322ec34ebfcc006390e5d"/><file name="AE.png" hash="40ea216476033961d50f452bf4bca4df"/><file name="DI.png" hash="0f4264379e7b8ba6b1a30a3d69240ae2"/><file name="EL.png" hash="ad180c308d285f73fc044121cb6aeac0"/><file name="HI.png" hash="c25430ddd8e441cc2fc3ef68219e7668"/><file name="MC.png" hash="836466c092121163320e9e6279f11f8b"/><file name="VBV.jpg" hash="1a7db765956829e80715a299b799f580"/><file name="VBV.png" hash="d6fb7de65fda842f03e2b9fc89d5e6aa"/><file name="VI.png" hash="cc0709d50773fa2815f7bfeb741a4219"/><file name="ajax-loader.gif" hash="7b9776076d5fceef4993b55c9383dedd"/><file name="boleto.jpg" hash="237570c55c811b4b13f73ab92f28e599"/><file name="cc_types.png" hash="fdae60f96ee668354161b5a865b8e7ef"/><file name="cielo_mastercard.png" hash="e2c2af12ea24f1b82490fdcc62fbb871"/><file name="cielo_visa.png" hash="d2f0c660714dc319b73c0dac9c9108d0"/></dir></dir></dir></dir><dir name="default"><dir name="default"><dir name="images"><dir name="mundipagg"><file name="EL.png" hash="ad180c308d285f73fc044121cb6aeac0"/><file name="HI.png" hash="c25430ddd8e441cc2fc3ef68219e7668"/><file name="ae.png" hash="40ea216476033961d50f452bf4bca4df"/><file name="boleto.jpg" hash="237570c55c811b4b13f73ab92f28e599"/><file name="cielo_mastercard.png" hash="e2c2af12ea24f1b82490fdcc62fbb871"/><file name="cielo_visa.png" hash="d2f0c660714dc319b73c0dac9c9108d0"/><file name="di.png" hash="0f4264379e7b8ba6b1a30a3d69240ae2"/><file name="mc.png" hash="836466c092121163320e9e6279f11f8b"/><file name="vi.png" hash="cc0709d50773fa2815f7bfeb741a4219"/></dir></dir></dir></dir></dir></target><target name="mage"><dir name="."><file name="README.md" hash=""/><file name="modman" hash=""/></dir></target></contents>
34
  <compatible/>
35
+ <dependencies><required><php><min>5.4.0</min><max>7.1.0</max></php></required></dependencies>
36
  </package>