Version Notes
Testado nas verões 1.4 e superiores do Magento Community Edition.
Download this release
Release Info
Developer | Fillipe Almeida Dutra |
Extension | Maxima_Cielo |
Version | 1.5.1 |
Comparing to | |
See all releases |
Code changes from version 1.5.0 to 1.5.1
- app/code/community/Maxima/Cielo/Block/Adminhtml/Order/View.php +73 -73
- app/code/community/Maxima/Cielo/Block/Form/Cc.php +234 -234
- app/code/community/Maxima/Cielo/Block/Form/Dc.php +111 -111
- app/code/community/Maxima/Cielo/Helper/Data.php +167 -167
- app/code/community/Maxima/Cielo/Model/Adminhtml/BuyPage.php +57 -57
- app/code/community/Maxima/Cielo/Model/Adminhtml/Environment.php +57 -57
- app/code/community/Maxima/Cielo/Model/Cc.php +460 -460
- app/code/community/Maxima/Cielo/Model/Cc/InstallmentType.php +44 -44
- app/code/community/Maxima/Cielo/Model/Cc/MaxInstallments.php +55 -55
- app/code/community/Maxima/Cielo/Model/Cc/Types.php +132 -132
- app/code/community/Maxima/Cielo/Model/Dc.php +405 -405
- app/code/community/Maxima/Cielo/Model/Dc/Types.php +72 -72
- app/code/community/Maxima/Cielo/Model/WebServiceOrder.php +547 -547
- app/code/community/Maxima/Cielo/controllers/AdminController.php +25 -1
- app/code/community/Maxima/Cielo/controllers/PayController.php +171 -171
- app/code/community/Maxima/Cielo/etc/config.xml +1 -1
- app/code/community/Maxima/Cielo/etc/system.xml +2 -2
- app/design/adminhtml/default/default/template/cielo/info/cc.phtml +345 -345
- app/design/adminhtml/default/default/template/cielo/info/dc.phtml +307 -307
- app/design/frontend/default/default/template/cielo/form/cc.phtml +227 -187
- app/design/frontend/default/default/template/cielo/form/dc.phtml +177 -138
- app/design/frontend/default/default/template/cielo/info/cc.phtml +63 -63
- app/design/frontend/default/default/template/cielo/info/dc.phtml +61 -61
- package.xml +4 -4
app/code/community/Maxima/Cielo/Block/Adminhtml/Order/View.php
CHANGED
@@ -1,73 +1,73 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Block_Adminhtml_Order_View extends Mage_Adminhtml_Block_Sales_Order_View
|
28 |
-
{
|
29 |
-
public function __construct()
|
30 |
-
{
|
31 |
-
parent::__construct();
|
32 |
-
|
33 |
-
$payment = $this->getOrder()->getPayment();
|
34 |
-
$method = $payment->getMethodInstance()->getCode();
|
35 |
-
$tid = $payment->getAdditionalInformation('Cielo_tid');
|
36 |
-
|
37 |
-
if(!$tid)
|
38 |
-
{
|
39 |
-
return;
|
40 |
-
}
|
41 |
-
|
42 |
-
if($method == "Maxima_Cielo_Cc")
|
43 |
-
{
|
44 |
-
$this->_addButton('maxima_cielo_capture', array
|
45 |
-
(
|
46 |
-
'label' => Mage::helper('Maxima_Cielo')->__('Capture'),
|
47 |
-
'onclick' => "captureCieloOrder('" . $tid . "', " . $this->getOrder()->getId() . ");",
|
48 |
-
'class' => 'go'
|
49 |
-
));
|
50 |
-
}
|
51 |
-
|
52 |
-
if($method == "Maxima_Cielo_Cc" || $method == "Maxima_Cielo_Dc")
|
53 |
-
{
|
54 |
-
$this->_addButton('maxima_cielo_consult', array
|
55 |
-
(
|
56 |
-
'label' => Mage::helper('Maxima_Cielo')->__('Consult WebService'),
|
57 |
-
'onclick' => "loadCieloWebServiceData('" . $tid . "', " . $this->getOrder()->getId() . ");",
|
58 |
-
'class' => 'go'
|
59 |
-
));
|
60 |
-
}
|
61 |
-
|
62 |
-
if($method == "Maxima_Cielo_Cc")
|
63 |
-
{
|
64 |
-
$this->_addButton('maxima_cielo_cancel', array
|
65 |
-
(
|
66 |
-
'label' => Mage::helper('Maxima_Cielo')->__('Cancel on Cielo'),
|
67 |
-
'onclick' => "cancelCieloOrder('" . $tid . "', " . $this->getOrder()->getId() . ");",
|
68 |
-
'class' => 'go'
|
69 |
-
));
|
70 |
-
}
|
71 |
-
}
|
72 |
-
}
|
73 |
-
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Block_Adminhtml_Order_View extends Mage_Adminhtml_Block_Sales_Order_View
|
28 |
+
{
|
29 |
+
public function __construct()
|
30 |
+
{
|
31 |
+
parent::__construct();
|
32 |
+
|
33 |
+
$payment = $this->getOrder()->getPayment();
|
34 |
+
$method = $payment->getMethodInstance()->getCode();
|
35 |
+
$tid = $payment->getAdditionalInformation('Cielo_tid');
|
36 |
+
|
37 |
+
if(!$tid)
|
38 |
+
{
|
39 |
+
return;
|
40 |
+
}
|
41 |
+
|
42 |
+
if($method == "Maxima_Cielo_Cc")
|
43 |
+
{
|
44 |
+
$this->_addButton('maxima_cielo_capture', array
|
45 |
+
(
|
46 |
+
'label' => Mage::helper('Maxima_Cielo')->__('Capture'),
|
47 |
+
'onclick' => "captureCieloOrder('" . $tid . "', " . $this->getOrder()->getId() . ");",
|
48 |
+
'class' => 'go'
|
49 |
+
));
|
50 |
+
}
|
51 |
+
|
52 |
+
if($method == "Maxima_Cielo_Cc" || $method == "Maxima_Cielo_Dc")
|
53 |
+
{
|
54 |
+
$this->_addButton('maxima_cielo_consult', array
|
55 |
+
(
|
56 |
+
'label' => Mage::helper('Maxima_Cielo')->__('Consult WebService'),
|
57 |
+
'onclick' => "loadCieloWebServiceData('" . $tid . "', " . $this->getOrder()->getId() . ");",
|
58 |
+
'class' => 'go'
|
59 |
+
));
|
60 |
+
}
|
61 |
+
|
62 |
+
if($method == "Maxima_Cielo_Cc")
|
63 |
+
{
|
64 |
+
$this->_addButton('maxima_cielo_cancel', array
|
65 |
+
(
|
66 |
+
'label' => Mage::helper('Maxima_Cielo')->__('Cancel on Cielo'),
|
67 |
+
'onclick' => "cancelCieloOrder('" . $tid . "', " . $this->getOrder()->getId() . ");",
|
68 |
+
'class' => 'go'
|
69 |
+
));
|
70 |
+
}
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
app/code/community/Maxima/Cielo/Block/Form/Cc.php
CHANGED
@@ -1,234 +1,234 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Block_Form_Cc extends Mage_Payment_Block_Form
|
28 |
-
{
|
29 |
-
protected function _construct()
|
30 |
-
{
|
31 |
-
parent::_construct();
|
32 |
-
$this->setTemplate('cielo/form/cc.phtml');
|
33 |
-
}
|
34 |
-
|
35 |
-
|
36 |
-
/**
|
37 |
-
*
|
38 |
-
* Lista opcoes de meses
|
39 |
-
*
|
40 |
-
*/
|
41 |
-
|
42 |
-
public function getMonths()
|
43 |
-
{
|
44 |
-
$months = array();
|
45 |
-
|
46 |
-
for($i = 1; $i <= 12; $i++)
|
47 |
-
{
|
48 |
-
$label = ($i < 10) ? ("0" . $i) : $i;
|
49 |
-
|
50 |
-
$months[] = array("num" => $i, "label" => $this->htmlEscape($label));
|
51 |
-
}
|
52 |
-
|
53 |
-
return $months;
|
54 |
-
}
|
55 |
-
|
56 |
-
/**
|
57 |
-
*
|
58 |
-
* Lista opcoes de anos
|
59 |
-
*
|
60 |
-
*/
|
61 |
-
|
62 |
-
public function getYears()
|
63 |
-
{
|
64 |
-
$years = array();
|
65 |
-
|
66 |
-
$initYear = (int) date("Y");
|
67 |
-
|
68 |
-
for($i = $initYear; $i <= $initYear + 10; $i++)
|
69 |
-
{
|
70 |
-
$years[] = array("num" => $i, "label" => $i);
|
71 |
-
}
|
72 |
-
|
73 |
-
return $years;
|
74 |
-
}
|
75 |
-
|
76 |
-
|
77 |
-
/**
|
78 |
-
*
|
79 |
-
* Lista opcoes de parcelamento
|
80 |
-
*
|
81 |
-
*/
|
82 |
-
|
83 |
-
public function getInstallments()
|
84 |
-
{
|
85 |
-
// pega dados de parcelamento
|
86 |
-
$maxInstallments = intval(Mage::getStoreConfig('payment/Maxima_Cielo_Cc/max_parcels_number'));
|
87 |
-
$minInstallmentValue = floatval(Mage::getStoreConfig('payment/Maxima_Cielo_Cc/min_parcels_value'));
|
88 |
-
|
89 |
-
$minInstallmentValue = ($minInstallmentValue <= 5.01) ? 5.01 : $minInstallmentValue;
|
90 |
-
|
91 |
-
// atualiza taxa de juros para 0,
|
92 |
-
// caso o usuario tenha voltado na navegacao
|
93 |
-
$quote = Mage::getSingleton('checkout/cart')->getQuote();
|
94 |
-
$quote->setInterest(0.0);
|
95 |
-
$quote->setBaseInterest(0.0);
|
96 |
-
|
97 |
-
$quote->setTotalsCollectedFlag(false)->collectTotals();
|
98 |
-
$quote->save();
|
99 |
-
|
100 |
-
// pega dados de juros
|
101 |
-
$withoutInterest = intval(Mage::getStoreConfig('payment/Maxima_Cielo_Cc/installment_without_interest'));
|
102 |
-
$interestValue = floatval(Mage::getStoreConfig('payment/Maxima_Cielo_Cc/installment_interest_value'));
|
103 |
-
|
104 |
-
// pega valores do pedido
|
105 |
-
$total = Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal();
|
106 |
-
|
107 |
-
$installments = array();
|
108 |
-
|
109 |
-
for($i = 1; $i <= $maxInstallments; $i++)
|
110 |
-
{
|
111 |
-
// caso nao haja juros na parcela
|
112 |
-
if($i <= $withoutInterest)
|
113 |
-
{
|
114 |
-
$orderTotal = $total;
|
115 |
-
$installmentValue = round($orderTotal / $i, 2);
|
116 |
-
}
|
117 |
-
// caso haja juros
|
118 |
-
else
|
119 |
-
{
|
120 |
-
$installmentValue = round(Mage::helper('Maxima_Cielo')->calcInstallmentValue($total, $interestValue / 100, $i), 2);
|
121 |
-
$orderTotal = $i * $installmentValue;
|
122 |
-
}
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
// confere se a parcela nao estah abaixo do minimo
|
127 |
-
if($minInstallmentValue >= 0 && $installmentValue < $minInstallmentValue)
|
128 |
-
{
|
129 |
-
break;
|
130 |
-
}
|
131 |
-
|
132 |
-
// monta o texto da parcela
|
133 |
-
if($i == 1)
|
134 |
-
{
|
135 |
-
$label = "À vista (" . Mage::helper('core')->currency(($total), true, false) . ")";
|
136 |
-
}
|
137 |
-
else
|
138 |
-
{
|
139 |
-
if($i <= $withoutInterest)
|
140 |
-
{
|
141 |
-
$label = $i . "x sem juros (" . Mage::helper('core')->currency(($installmentValue), true, false) . " cada)";
|
142 |
-
}
|
143 |
-
else
|
144 |
-
{
|
145 |
-
$label = $i . "x (" . Mage::helper('core')->currency(($installmentValue), true, false) . " cada)";
|
146 |
-
}
|
147 |
-
}
|
148 |
-
|
149 |
-
// adiciona no vetor de parcelas
|
150 |
-
$installments[] = array("num" => $i, "label" => $this->htmlEscape($label));
|
151 |
-
}
|
152 |
-
|
153 |
-
// caso o valor da parcela minima seja maior do que o valor da compra,
|
154 |
-
// deixa somente opcao a vista
|
155 |
-
if($minInstallmentValue > $total)
|
156 |
-
{
|
157 |
-
$label = "À vista (" . Mage::helper('core')->currency(($total), true, false) . ")";
|
158 |
-
$installments[] = array("num" => 1, "label" => $this->htmlEscape($label));
|
159 |
-
}
|
160 |
-
|
161 |
-
return $installments;
|
162 |
-
}
|
163 |
-
|
164 |
-
/**
|
165 |
-
*
|
166 |
-
* Retorna vetor com os codigos dos cartoes habilitados
|
167 |
-
*
|
168 |
-
*/
|
169 |
-
|
170 |
-
public function getAllowedCards()
|
171 |
-
{
|
172 |
-
$allowedCards = explode(",", Mage::getStoreConfig('payment/Maxima_Cielo_Cc/card_types'));
|
173 |
-
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toOptionArray();
|
174 |
-
|
175 |
-
$validCards = array();
|
176 |
-
|
177 |
-
foreach($allCards as $card)
|
178 |
-
{
|
179 |
-
if(in_array($card['value'], $allowedCards))
|
180 |
-
{
|
181 |
-
$validCards[] = $card;
|
182 |
-
}
|
183 |
-
}
|
184 |
-
|
185 |
-
return $validCards;
|
186 |
-
}
|
187 |
-
|
188 |
-
/**
|
189 |
-
*
|
190 |
-
* Retorna vetor com numero maximo de parcelamento aceito
|
191 |
-
* para cada bandeira
|
192 |
-
*
|
193 |
-
*/
|
194 |
-
|
195 |
-
public function getMaxCardsInstallments()
|
196 |
-
{
|
197 |
-
$maxInstallments = intval(Mage::getStoreConfig('payment/Maxima_Cielo_Cc/max_parcels_number'));
|
198 |
-
$installmentType = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/installments_type');
|
199 |
-
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toOptionArray();
|
200 |
-
|
201 |
-
$installmentsArray = array();
|
202 |
-
|
203 |
-
foreach($allCards as $card)
|
204 |
-
{
|
205 |
-
$installmentsNumber = $maxInstallments;
|
206 |
-
|
207 |
-
// caso loja
|
208 |
-
if($installmentType == '2')
|
209 |
-
{
|
210 |
-
$installmentsNumber = ($installmentsNumber > $card['inst_s']) ? $card['inst_s'] : $installmentsNumber;
|
211 |
-
}
|
212 |
-
// caso administradora
|
213 |
-
else if($installmentType == '3')
|
214 |
-
{
|
215 |
-
$installmentsNumber = ($installmentsNumber > $card['inst_a']) ? $card['inst_a'] : $installmentsNumber;
|
216 |
-
}
|
217 |
-
|
218 |
-
$installmentsArray[$card['value']] = $installmentsNumber;
|
219 |
-
}
|
220 |
-
|
221 |
-
return $installmentsArray;
|
222 |
-
}
|
223 |
-
|
224 |
-
/**
|
225 |
-
*
|
226 |
-
* Pega os valores da configuracao do modulo
|
227 |
-
*
|
228 |
-
*/
|
229 |
-
|
230 |
-
public function getConfigData($config)
|
231 |
-
{
|
232 |
-
return Mage::getStoreConfig('payment/Maxima_Cielo_Cc/' . $config);
|
233 |
-
}
|
234 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Block_Form_Cc extends Mage_Payment_Block_Form
|
28 |
+
{
|
29 |
+
protected function _construct()
|
30 |
+
{
|
31 |
+
parent::_construct();
|
32 |
+
$this->setTemplate('cielo/form/cc.phtml');
|
33 |
+
}
|
34 |
+
|
35 |
+
|
36 |
+
/**
|
37 |
+
*
|
38 |
+
* Lista opcoes de meses
|
39 |
+
*
|
40 |
+
*/
|
41 |
+
|
42 |
+
public function getMonths()
|
43 |
+
{
|
44 |
+
$months = array();
|
45 |
+
|
46 |
+
for($i = 1; $i <= 12; $i++)
|
47 |
+
{
|
48 |
+
$label = ($i < 10) ? ("0" . $i) : $i;
|
49 |
+
|
50 |
+
$months[] = array("num" => $i, "label" => $this->htmlEscape($label));
|
51 |
+
}
|
52 |
+
|
53 |
+
return $months;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
*
|
58 |
+
* Lista opcoes de anos
|
59 |
+
*
|
60 |
+
*/
|
61 |
+
|
62 |
+
public function getYears()
|
63 |
+
{
|
64 |
+
$years = array();
|
65 |
+
|
66 |
+
$initYear = (int) date("Y");
|
67 |
+
|
68 |
+
for($i = $initYear; $i <= $initYear + 10; $i++)
|
69 |
+
{
|
70 |
+
$years[] = array("num" => $i, "label" => $i);
|
71 |
+
}
|
72 |
+
|
73 |
+
return $years;
|
74 |
+
}
|
75 |
+
|
76 |
+
|
77 |
+
/**
|
78 |
+
*
|
79 |
+
* Lista opcoes de parcelamento
|
80 |
+
*
|
81 |
+
*/
|
82 |
+
|
83 |
+
public function getInstallments()
|
84 |
+
{
|
85 |
+
// pega dados de parcelamento
|
86 |
+
$maxInstallments = intval(Mage::getStoreConfig('payment/Maxima_Cielo_Cc/max_parcels_number'));
|
87 |
+
$minInstallmentValue = floatval(Mage::getStoreConfig('payment/Maxima_Cielo_Cc/min_parcels_value'));
|
88 |
+
|
89 |
+
$minInstallmentValue = ($minInstallmentValue <= 5.01) ? 5.01 : $minInstallmentValue;
|
90 |
+
|
91 |
+
// atualiza taxa de juros para 0,
|
92 |
+
// caso o usuario tenha voltado na navegacao
|
93 |
+
$quote = Mage::getSingleton('checkout/cart')->getQuote();
|
94 |
+
$quote->setInterest(0.0);
|
95 |
+
$quote->setBaseInterest(0.0);
|
96 |
+
|
97 |
+
$quote->setTotalsCollectedFlag(false)->collectTotals();
|
98 |
+
$quote->save();
|
99 |
+
|
100 |
+
// pega dados de juros
|
101 |
+
$withoutInterest = intval(Mage::getStoreConfig('payment/Maxima_Cielo_Cc/installment_without_interest'));
|
102 |
+
$interestValue = floatval(Mage::getStoreConfig('payment/Maxima_Cielo_Cc/installment_interest_value'));
|
103 |
+
|
104 |
+
// pega valores do pedido
|
105 |
+
$total = Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal();
|
106 |
+
|
107 |
+
$installments = array();
|
108 |
+
|
109 |
+
for($i = 1; $i <= $maxInstallments; $i++)
|
110 |
+
{
|
111 |
+
// caso nao haja juros na parcela
|
112 |
+
if($i <= $withoutInterest)
|
113 |
+
{
|
114 |
+
$orderTotal = $total;
|
115 |
+
$installmentValue = round($orderTotal / $i, 2);
|
116 |
+
}
|
117 |
+
// caso haja juros
|
118 |
+
else
|
119 |
+
{
|
120 |
+
$installmentValue = round(Mage::helper('Maxima_Cielo')->calcInstallmentValue($total, $interestValue / 100, $i), 2);
|
121 |
+
$orderTotal = $i * $installmentValue;
|
122 |
+
}
|
123 |
+
|
124 |
+
|
125 |
+
|
126 |
+
// confere se a parcela nao estah abaixo do minimo
|
127 |
+
if($minInstallmentValue >= 0 && $installmentValue < $minInstallmentValue)
|
128 |
+
{
|
129 |
+
break;
|
130 |
+
}
|
131 |
+
|
132 |
+
// monta o texto da parcela
|
133 |
+
if($i == 1)
|
134 |
+
{
|
135 |
+
$label = "À vista (" . Mage::helper('core')->currency(($total), true, false) . ")";
|
136 |
+
}
|
137 |
+
else
|
138 |
+
{
|
139 |
+
if($i <= $withoutInterest)
|
140 |
+
{
|
141 |
+
$label = $i . "x sem juros (" . Mage::helper('core')->currency(($installmentValue), true, false) . " cada)";
|
142 |
+
}
|
143 |
+
else
|
144 |
+
{
|
145 |
+
$label = $i . "x (" . Mage::helper('core')->currency(($installmentValue), true, false) . " cada)";
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
// adiciona no vetor de parcelas
|
150 |
+
$installments[] = array("num" => $i, "label" => $this->htmlEscape($label));
|
151 |
+
}
|
152 |
+
|
153 |
+
// caso o valor da parcela minima seja maior do que o valor da compra,
|
154 |
+
// deixa somente opcao a vista
|
155 |
+
if($minInstallmentValue > $total)
|
156 |
+
{
|
157 |
+
$label = "À vista (" . Mage::helper('core')->currency(($total), true, false) . ")";
|
158 |
+
$installments[] = array("num" => 1, "label" => $this->htmlEscape($label));
|
159 |
+
}
|
160 |
+
|
161 |
+
return $installments;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
*
|
166 |
+
* Retorna vetor com os codigos dos cartoes habilitados
|
167 |
+
*
|
168 |
+
*/
|
169 |
+
|
170 |
+
public function getAllowedCards()
|
171 |
+
{
|
172 |
+
$allowedCards = explode(",", Mage::getStoreConfig('payment/Maxima_Cielo_Cc/card_types'));
|
173 |
+
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toOptionArray();
|
174 |
+
|
175 |
+
$validCards = array();
|
176 |
+
|
177 |
+
foreach($allCards as $card)
|
178 |
+
{
|
179 |
+
if(in_array($card['value'], $allowedCards))
|
180 |
+
{
|
181 |
+
$validCards[] = $card;
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
return $validCards;
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
*
|
190 |
+
* Retorna vetor com numero maximo de parcelamento aceito
|
191 |
+
* para cada bandeira
|
192 |
+
*
|
193 |
+
*/
|
194 |
+
|
195 |
+
public function getMaxCardsInstallments()
|
196 |
+
{
|
197 |
+
$maxInstallments = intval(Mage::getStoreConfig('payment/Maxima_Cielo_Cc/max_parcels_number'));
|
198 |
+
$installmentType = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/installments_type');
|
199 |
+
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toOptionArray();
|
200 |
+
|
201 |
+
$installmentsArray = array();
|
202 |
+
|
203 |
+
foreach($allCards as $card)
|
204 |
+
{
|
205 |
+
$installmentsNumber = $maxInstallments;
|
206 |
+
|
207 |
+
// caso loja
|
208 |
+
if($installmentType == '2')
|
209 |
+
{
|
210 |
+
$installmentsNumber = ($installmentsNumber > $card['inst_s']) ? $card['inst_s'] : $installmentsNumber;
|
211 |
+
}
|
212 |
+
// caso administradora
|
213 |
+
else if($installmentType == '3')
|
214 |
+
{
|
215 |
+
$installmentsNumber = ($installmentsNumber > $card['inst_a']) ? $card['inst_a'] : $installmentsNumber;
|
216 |
+
}
|
217 |
+
|
218 |
+
$installmentsArray[$card['value']] = $installmentsNumber;
|
219 |
+
}
|
220 |
+
|
221 |
+
return $installmentsArray;
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
*
|
226 |
+
* Pega os valores da configuracao do modulo
|
227 |
+
*
|
228 |
+
*/
|
229 |
+
|
230 |
+
public function getConfigData($config)
|
231 |
+
{
|
232 |
+
return Mage::getStoreConfig('payment/Maxima_Cielo_Cc/' . $config);
|
233 |
+
}
|
234 |
+
}
|
app/code/community/Maxima/Cielo/Block/Form/Dc.php
CHANGED
@@ -1,111 +1,111 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Block_Form_Dc extends Mage_Payment_Block_Form
|
28 |
-
{
|
29 |
-
protected function _construct()
|
30 |
-
{
|
31 |
-
parent::_construct();
|
32 |
-
$this->setTemplate('cielo/form/dc.phtml');
|
33 |
-
}
|
34 |
-
|
35 |
-
/**
|
36 |
-
*
|
37 |
-
* Lista opcoes de meses
|
38 |
-
*
|
39 |
-
*/
|
40 |
-
|
41 |
-
public function getMonths()
|
42 |
-
{
|
43 |
-
$months = array();
|
44 |
-
|
45 |
-
for($i = 1; $i <= 12; $i++)
|
46 |
-
{
|
47 |
-
$label = ($i < 10) ? ("0" . $i) : $i;
|
48 |
-
|
49 |
-
$months[] = array("num" => $i, "label" => $this->htmlEscape($label));
|
50 |
-
}
|
51 |
-
|
52 |
-
return $months;
|
53 |
-
}
|
54 |
-
|
55 |
-
/**
|
56 |
-
*
|
57 |
-
* Lista opcoes de anos
|
58 |
-
*
|
59 |
-
*/
|
60 |
-
|
61 |
-
public function getYears()
|
62 |
-
{
|
63 |
-
$years = array();
|
64 |
-
|
65 |
-
$initYear = (int) date("Y");
|
66 |
-
|
67 |
-
for($i = $initYear; $i <= $initYear + 10; $i++)
|
68 |
-
{
|
69 |
-
$years[] = array("num" => $i, "label" => $i);
|
70 |
-
}
|
71 |
-
|
72 |
-
return $years;
|
73 |
-
}
|
74 |
-
|
75 |
-
|
76 |
-
/**
|
77 |
-
*
|
78 |
-
* Retorna vetor com os codigos dos cartoes habilitados
|
79 |
-
*
|
80 |
-
*/
|
81 |
-
|
82 |
-
public function getAllowedCards()
|
83 |
-
{
|
84 |
-
$allowedCards = explode(",", Mage::getStoreConfig('payment/Maxima_Cielo_Dc/card_types'));
|
85 |
-
$allCards = Mage::getModel('Maxima_Cielo/dc_types')->toOptionArray();
|
86 |
-
|
87 |
-
$validCards = array();
|
88 |
-
|
89 |
-
foreach($allCards as $card)
|
90 |
-
{
|
91 |
-
if(in_array($card['value'], $allowedCards))
|
92 |
-
{
|
93 |
-
$validCards[] = $card;
|
94 |
-
}
|
95 |
-
}
|
96 |
-
|
97 |
-
return $validCards;
|
98 |
-
}
|
99 |
-
|
100 |
-
|
101 |
-
/**
|
102 |
-
*
|
103 |
-
* Pega os valores da configuracao do modulo
|
104 |
-
*
|
105 |
-
*/
|
106 |
-
|
107 |
-
public function getConfigData($config)
|
108 |
-
{
|
109 |
-
return Mage::getStoreConfig('payment/Maxima_Cielo_Dc/' . $config);
|
110 |
-
}
|
111 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Block_Form_Dc extends Mage_Payment_Block_Form
|
28 |
+
{
|
29 |
+
protected function _construct()
|
30 |
+
{
|
31 |
+
parent::_construct();
|
32 |
+
$this->setTemplate('cielo/form/dc.phtml');
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
*
|
37 |
+
* Lista opcoes de meses
|
38 |
+
*
|
39 |
+
*/
|
40 |
+
|
41 |
+
public function getMonths()
|
42 |
+
{
|
43 |
+
$months = array();
|
44 |
+
|
45 |
+
for($i = 1; $i <= 12; $i++)
|
46 |
+
{
|
47 |
+
$label = ($i < 10) ? ("0" . $i) : $i;
|
48 |
+
|
49 |
+
$months[] = array("num" => $i, "label" => $this->htmlEscape($label));
|
50 |
+
}
|
51 |
+
|
52 |
+
return $months;
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
*
|
57 |
+
* Lista opcoes de anos
|
58 |
+
*
|
59 |
+
*/
|
60 |
+
|
61 |
+
public function getYears()
|
62 |
+
{
|
63 |
+
$years = array();
|
64 |
+
|
65 |
+
$initYear = (int) date("Y");
|
66 |
+
|
67 |
+
for($i = $initYear; $i <= $initYear + 10; $i++)
|
68 |
+
{
|
69 |
+
$years[] = array("num" => $i, "label" => $i);
|
70 |
+
}
|
71 |
+
|
72 |
+
return $years;
|
73 |
+
}
|
74 |
+
|
75 |
+
|
76 |
+
/**
|
77 |
+
*
|
78 |
+
* Retorna vetor com os codigos dos cartoes habilitados
|
79 |
+
*
|
80 |
+
*/
|
81 |
+
|
82 |
+
public function getAllowedCards()
|
83 |
+
{
|
84 |
+
$allowedCards = explode(",", Mage::getStoreConfig('payment/Maxima_Cielo_Dc/card_types'));
|
85 |
+
$allCards = Mage::getModel('Maxima_Cielo/dc_types')->toOptionArray();
|
86 |
+
|
87 |
+
$validCards = array();
|
88 |
+
|
89 |
+
foreach($allCards as $card)
|
90 |
+
{
|
91 |
+
if(in_array($card['value'], $allowedCards))
|
92 |
+
{
|
93 |
+
$validCards[] = $card;
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
return $validCards;
|
98 |
+
}
|
99 |
+
|
100 |
+
|
101 |
+
/**
|
102 |
+
*
|
103 |
+
* Pega os valores da configuracao do modulo
|
104 |
+
*
|
105 |
+
*/
|
106 |
+
|
107 |
+
public function getConfigData($config)
|
108 |
+
{
|
109 |
+
return Mage::getStoreConfig('payment/Maxima_Cielo_Dc/' . $config);
|
110 |
+
}
|
111 |
+
}
|
app/code/community/Maxima/Cielo/Helper/Data.php
CHANGED
@@ -1,167 +1,167 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Helper_Data extends Mage_Core_Helper_Abstract
|
28 |
-
{
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Formata o valor da compra de acordo com a definicao da Cielo
|
32 |
-
*
|
33 |
-
* @param string $originalValue
|
34 |
-
* @return string
|
35 |
-
*/
|
36 |
-
public function formatValueForCielo($originalValue)
|
37 |
-
{
|
38 |
-
if(strpos($originalValue, ".") == false)
|
39 |
-
{
|
40 |
-
$value = $originalValue . "00";
|
41 |
-
}
|
42 |
-
else
|
43 |
-
{
|
44 |
-
list($integers, $decimals) = explode(".", $originalValue);
|
45 |
-
|
46 |
-
if(strlen($decimals) > 2)
|
47 |
-
{
|
48 |
-
$decimals = substr($decimals, 0, 2);
|
49 |
-
}
|
50 |
-
|
51 |
-
while(strlen($decimals) < 2)
|
52 |
-
{
|
53 |
-
$decimals .= "0";
|
54 |
-
}
|
55 |
-
|
56 |
-
$value = $integers . $decimals;
|
57 |
-
}
|
58 |
-
|
59 |
-
return $value;
|
60 |
-
}
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Retorna mensagem adequada ao codigo de retorno da cielo
|
64 |
-
*
|
65 |
-
* @param string $statusCode
|
66 |
-
* @return string
|
67 |
-
*/
|
68 |
-
public function getStatusMessage($statusCode)
|
69 |
-
{
|
70 |
-
switch($statusCode)
|
71 |
-
{
|
72 |
-
case 1:
|
73 |
-
$label = "Em andamento";
|
74 |
-
break;
|
75 |
-
case 2:
|
76 |
-
$label = "Autenticada";
|
77 |
-
break;
|
78 |
-
case 3:
|
79 |
-
$label = "N�o autenticada";
|
80 |
-
break;
|
81 |
-
case 4:
|
82 |
-
$label = "Autorizada";
|
83 |
-
break;
|
84 |
-
case 5:
|
85 |
-
$label = "N�o autorizada";
|
86 |
-
break;
|
87 |
-
case 6:
|
88 |
-
$label = "Conclu�da";
|
89 |
-
break;
|
90 |
-
case 9:
|
91 |
-
$label = "Cancelada";
|
92 |
-
break;
|
93 |
-
case 10:
|
94 |
-
$label = "Em autentica��o";
|
95 |
-
break;
|
96 |
-
case 10:
|
97 |
-
$label = "Em cancelamento";
|
98 |
-
break;
|
99 |
-
default:
|
100 |
-
$label = "Erro (" . $statusCode . ")";
|
101 |
-
}
|
102 |
-
|
103 |
-
return htmlentities($label);
|
104 |
-
}
|
105 |
-
|
106 |
-
|
107 |
-
/**
|
108 |
-
* Retorna o valor de uma parcela, dados o valor total a ser parcelado,
|
109 |
-
* a taxa de juros e o numero de prestacoes
|
110 |
-
*
|
111 |
-
* @param string $total
|
112 |
-
* @param string $interest
|
113 |
-
* @param string $periods
|
114 |
-
* @return string
|
115 |
-
*/
|
116 |
-
public function calcInstallmentValue($total, $interest, $periods)
|
117 |
-
{
|
118 |
-
/*
|
119 |
-
* Formula do coeficiente:
|
120 |
-
*
|
121 |
-
* juros / ( 1 - 1 / (1 + i)^n )
|
122 |
-
*
|
123 |
-
*/
|
124 |
-
|
125 |
-
|
126 |
-
// calcula o coeficiente, seguindo a formula acima
|
127 |
-
$coefficient = pow((1 + $interest), $periods);
|
128 |
-
$coefficient = 1 / $coefficient;
|
129 |
-
$coefficient = 1 - $coefficient;
|
130 |
-
$coefficient = $interest / $coefficient;
|
131 |
-
|
132 |
-
// retorna o valor da parcela
|
133 |
-
return ($total * $coefficient);
|
134 |
-
}
|
135 |
-
|
136 |
-
|
137 |
-
/**
|
138 |
-
*
|
139 |
-
* Percorre um objeto XML, passando-o para HTML
|
140 |
-
*
|
141 |
-
*/
|
142 |
-
|
143 |
-
public function xmlToHtml($xmlNode, $tab = 0)
|
144 |
-
{
|
145 |
-
if(count($xmlNode) > 0)
|
146 |
-
{
|
147 |
-
$childrenNode = $xmlNode->children();
|
148 |
-
$childrenString = "";
|
149 |
-
|
150 |
-
// monta o valor do noh
|
151 |
-
foreach($childrenNode as $cn)
|
152 |
-
{
|
153 |
-
$childrenString .= $this->xmlToHtml($cn, $tab + 1);
|
154 |
-
}
|
155 |
-
|
156 |
-
$nodeString = "<div style='margin-left: " . ($tab * 25) . "px;'><b>" . $xmlNode->getName() . "</b></div>";
|
157 |
-
|
158 |
-
return $nodeString . $childrenString;
|
159 |
-
}
|
160 |
-
else
|
161 |
-
{
|
162 |
-
$nodeString = "<div style='margin-left: " . ($tab * 25) . "px;'><b>" . $xmlNode->getName() . ":</b> " . ((string) $xmlNode) . "</div>";
|
163 |
-
return $nodeString;
|
164 |
-
}
|
165 |
-
}
|
166 |
-
|
167 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Helper_Data extends Mage_Core_Helper_Abstract
|
28 |
+
{
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Formata o valor da compra de acordo com a definicao da Cielo
|
32 |
+
*
|
33 |
+
* @param string $originalValue
|
34 |
+
* @return string
|
35 |
+
*/
|
36 |
+
public function formatValueForCielo($originalValue)
|
37 |
+
{
|
38 |
+
if(strpos($originalValue, ".") == false)
|
39 |
+
{
|
40 |
+
$value = $originalValue . "00";
|
41 |
+
}
|
42 |
+
else
|
43 |
+
{
|
44 |
+
list($integers, $decimals) = explode(".", $originalValue);
|
45 |
+
|
46 |
+
if(strlen($decimals) > 2)
|
47 |
+
{
|
48 |
+
$decimals = substr($decimals, 0, 2);
|
49 |
+
}
|
50 |
+
|
51 |
+
while(strlen($decimals) < 2)
|
52 |
+
{
|
53 |
+
$decimals .= "0";
|
54 |
+
}
|
55 |
+
|
56 |
+
$value = $integers . $decimals;
|
57 |
+
}
|
58 |
+
|
59 |
+
return $value;
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Retorna mensagem adequada ao codigo de retorno da cielo
|
64 |
+
*
|
65 |
+
* @param string $statusCode
|
66 |
+
* @return string
|
67 |
+
*/
|
68 |
+
public function getStatusMessage($statusCode)
|
69 |
+
{
|
70 |
+
switch($statusCode)
|
71 |
+
{
|
72 |
+
case 1:
|
73 |
+
$label = "Em andamento";
|
74 |
+
break;
|
75 |
+
case 2:
|
76 |
+
$label = "Autenticada";
|
77 |
+
break;
|
78 |
+
case 3:
|
79 |
+
$label = "N�o autenticada";
|
80 |
+
break;
|
81 |
+
case 4:
|
82 |
+
$label = "Autorizada";
|
83 |
+
break;
|
84 |
+
case 5:
|
85 |
+
$label = "N�o autorizada";
|
86 |
+
break;
|
87 |
+
case 6:
|
88 |
+
$label = "Conclu�da";
|
89 |
+
break;
|
90 |
+
case 9:
|
91 |
+
$label = "Cancelada";
|
92 |
+
break;
|
93 |
+
case 10:
|
94 |
+
$label = "Em autentica��o";
|
95 |
+
break;
|
96 |
+
case 10:
|
97 |
+
$label = "Em cancelamento";
|
98 |
+
break;
|
99 |
+
default:
|
100 |
+
$label = "Erro (" . $statusCode . ")";
|
101 |
+
}
|
102 |
+
|
103 |
+
return htmlentities($label);
|
104 |
+
}
|
105 |
+
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Retorna o valor de uma parcela, dados o valor total a ser parcelado,
|
109 |
+
* a taxa de juros e o numero de prestacoes
|
110 |
+
*
|
111 |
+
* @param string $total
|
112 |
+
* @param string $interest
|
113 |
+
* @param string $periods
|
114 |
+
* @return string
|
115 |
+
*/
|
116 |
+
public function calcInstallmentValue($total, $interest, $periods)
|
117 |
+
{
|
118 |
+
/*
|
119 |
+
* Formula do coeficiente:
|
120 |
+
*
|
121 |
+
* juros / ( 1 - 1 / (1 + i)^n )
|
122 |
+
*
|
123 |
+
*/
|
124 |
+
|
125 |
+
|
126 |
+
// calcula o coeficiente, seguindo a formula acima
|
127 |
+
$coefficient = pow((1 + $interest), $periods);
|
128 |
+
$coefficient = 1 / $coefficient;
|
129 |
+
$coefficient = 1 - $coefficient;
|
130 |
+
$coefficient = $interest / $coefficient;
|
131 |
+
|
132 |
+
// retorna o valor da parcela
|
133 |
+
return ($total * $coefficient);
|
134 |
+
}
|
135 |
+
|
136 |
+
|
137 |
+
/**
|
138 |
+
*
|
139 |
+
* Percorre um objeto XML, passando-o para HTML
|
140 |
+
*
|
141 |
+
*/
|
142 |
+
|
143 |
+
public function xmlToHtml($xmlNode, $tab = 0)
|
144 |
+
{
|
145 |
+
if(count($xmlNode) > 0)
|
146 |
+
{
|
147 |
+
$childrenNode = $xmlNode->children();
|
148 |
+
$childrenString = "";
|
149 |
+
|
150 |
+
// monta o valor do noh
|
151 |
+
foreach($childrenNode as $cn)
|
152 |
+
{
|
153 |
+
$childrenString .= $this->xmlToHtml($cn, $tab + 1);
|
154 |
+
}
|
155 |
+
|
156 |
+
$nodeString = "<div style='margin-left: " . ($tab * 25) . "px;'><b>" . $xmlNode->getName() . "</b></div>";
|
157 |
+
|
158 |
+
return $nodeString . $childrenString;
|
159 |
+
}
|
160 |
+
else
|
161 |
+
{
|
162 |
+
$nodeString = "<div style='margin-left: " . ($tab * 25) . "px;'><b>" . $xmlNode->getName() . ":</b> " . ((string) $xmlNode) . "</div>";
|
163 |
+
return $nodeString;
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
}
|
app/code/community/Maxima/Cielo/Model/Adminhtml/BuyPage.php
CHANGED
@@ -1,58 +1,58 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Model_Adminhtml_BuyPage
|
28 |
-
{
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Formato vetor de vetores
|
32 |
-
*
|
33 |
-
* @return array
|
34 |
-
*/
|
35 |
-
public function toOptionArray()
|
36 |
-
{
|
37 |
-
return array
|
38 |
-
(
|
39 |
-
array('value' => 'cielo', 'label'=>Mage::helper('adminhtml')->__('Buy Page Cielo')),
|
40 |
-
array('value' => 'loja', 'label'=>Mage::helper('adminhtml')->__('Buy Page Loja')),
|
41 |
-
);
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Formato chave-valor
|
46 |
-
*
|
47 |
-
* @return array
|
48 |
-
*/
|
49 |
-
public function toArray()
|
50 |
-
{
|
51 |
-
return array
|
52 |
-
(
|
53 |
-
'cielo' => Mage::helper('adminhtml')->__('Buy Page Cielo'),
|
54 |
-
'loja' => Mage::helper('adminhtml')->__('Buy Page Loja'),
|
55 |
-
);
|
56 |
-
}
|
57 |
-
|
58 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Model_Adminhtml_BuyPage
|
28 |
+
{
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Formato vetor de vetores
|
32 |
+
*
|
33 |
+
* @return array
|
34 |
+
*/
|
35 |
+
public function toOptionArray()
|
36 |
+
{
|
37 |
+
return array
|
38 |
+
(
|
39 |
+
array('value' => 'cielo', 'label'=>Mage::helper('adminhtml')->__('Buy Page Cielo')),
|
40 |
+
array('value' => 'loja', 'label'=>Mage::helper('adminhtml')->__('Buy Page Loja')),
|
41 |
+
);
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Formato chave-valor
|
46 |
+
*
|
47 |
+
* @return array
|
48 |
+
*/
|
49 |
+
public function toArray()
|
50 |
+
{
|
51 |
+
return array
|
52 |
+
(
|
53 |
+
'cielo' => Mage::helper('adminhtml')->__('Buy Page Cielo'),
|
54 |
+
'loja' => Mage::helper('adminhtml')->__('Buy Page Loja'),
|
55 |
+
);
|
56 |
+
}
|
57 |
+
|
58 |
}
|
app/code/community/Maxima/Cielo/Model/Adminhtml/Environment.php
CHANGED
@@ -1,58 +1,58 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Model_Adminhtml_Environment
|
28 |
-
{
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Formato vetor de vetores
|
32 |
-
*
|
33 |
-
* @return array
|
34 |
-
*/
|
35 |
-
public function toOptionArray()
|
36 |
-
{
|
37 |
-
return array
|
38 |
-
(
|
39 |
-
array('value' => 'https://qasecommerce.cielo.com.br', 'label'=>Mage::helper('adminhtml')->__('Teste')),
|
40 |
-
array('value' => 'https://ecommerce.cielo.com.br', 'label'=>Mage::helper('adminhtml')->__('Produção')),
|
41 |
-
);
|
42 |
-
}
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Formato chave-valor
|
46 |
-
*
|
47 |
-
* @return array
|
48 |
-
*/
|
49 |
-
public function toArray()
|
50 |
-
{
|
51 |
-
return array
|
52 |
-
(
|
53 |
-
'https://qasecommerce.cielo.com.br' => Mage::helper('adminhtml')->__('Teste'),
|
54 |
-
'https://ecommerce.cielo.com.br' => Mage::helper('adminhtml')->__('Produção'),
|
55 |
-
);
|
56 |
-
}
|
57 |
-
|
58 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Model_Adminhtml_Environment
|
28 |
+
{
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Formato vetor de vetores
|
32 |
+
*
|
33 |
+
* @return array
|
34 |
+
*/
|
35 |
+
public function toOptionArray()
|
36 |
+
{
|
37 |
+
return array
|
38 |
+
(
|
39 |
+
array('value' => 'https://qasecommerce.cielo.com.br', 'label'=>Mage::helper('adminhtml')->__('Teste')),
|
40 |
+
array('value' => 'https://ecommerce.cielo.com.br', 'label'=>Mage::helper('adminhtml')->__('Produção')),
|
41 |
+
);
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Formato chave-valor
|
46 |
+
*
|
47 |
+
* @return array
|
48 |
+
*/
|
49 |
+
public function toArray()
|
50 |
+
{
|
51 |
+
return array
|
52 |
+
(
|
53 |
+
'https://qasecommerce.cielo.com.br' => Mage::helper('adminhtml')->__('Teste'),
|
54 |
+
'https://ecommerce.cielo.com.br' => Mage::helper('adminhtml')->__('Produção'),
|
55 |
+
);
|
56 |
+
}
|
57 |
+
|
58 |
}
|
app/code/community/Maxima/Cielo/Model/Cc.php
CHANGED
@@ -1,460 +1,460 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Model_Cc extends Mage_Payment_Model_Method_Abstract
|
28 |
-
{
|
29 |
-
|
30 |
-
protected $_code = 'Maxima_Cielo_Cc';
|
31 |
-
protected $_formBlockType = 'Maxima_Cielo/form_cc';
|
32 |
-
protected $_infoBlockType = 'Maxima_Cielo/info_cc';
|
33 |
-
protected $_canUseInternal = true;
|
34 |
-
protected $_canUseForMultishipping = false;
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Assign data to info model instance
|
38 |
-
*
|
39 |
-
* @param mixed $data
|
40 |
-
* @return Mage_Payment_Model_Info
|
41 |
-
*/
|
42 |
-
public function assignData($data)
|
43 |
-
{
|
44 |
-
if (!($data instanceof Varien_Object))
|
45 |
-
{
|
46 |
-
$data = new Varien_Object($data);
|
47 |
-
}
|
48 |
-
|
49 |
-
// salva a bandeira e o numero de parcelas
|
50 |
-
$info = $this->getInfoInstance();
|
51 |
-
$additionaldata = array
|
52 |
-
(
|
53 |
-
'parcels_number' => $data->getParcelsNumber()
|
54 |
-
);
|
55 |
-
|
56 |
-
$info->setCcType($data->getCcType())
|
57 |
-
->setCcNumber(Mage::helper('core')->encrypt($data->getCcNumber()))
|
58 |
-
->setCcOwner($data->getCcOwner())
|
59 |
-
->setCcExpMonth($data->getCcExpMonth())
|
60 |
-
->setCcExpYear($data->getCcExpYear())
|
61 |
-
->setCcCid(Mage::helper('core')->encrypt($data->getCcCid()))
|
62 |
-
->setAdditionalData(serialize($additionaldata));
|
63 |
-
|
64 |
-
|
65 |
-
// pega dados de juros
|
66 |
-
$withoutInterest = intval($this->getConfigData('installment_without_interest', $this->getStoreId()));
|
67 |
-
$interestValue = floatval($this->getConfigData('installment_interest_value', $this->getStoreId()));
|
68 |
-
|
69 |
-
|
70 |
-
// verifica se há juros
|
71 |
-
if($data->getParcelsNumber() > $withoutInterest)
|
72 |
-
{
|
73 |
-
$installmentValue = Mage::helper('Maxima_Cielo')->calcInstallmentValue
|
74 |
-
(
|
75 |
-
$info->getQuote()->getGrandTotal(),
|
76 |
-
$interestValue / 100,
|
77 |
-
$data->getParcelsNumber()
|
78 |
-
);
|
79 |
-
$installmentValue = round($installmentValue, 2);
|
80 |
-
$interest = ($installmentValue * $data->getParcelsNumber()) - $info->getQuote()->getGrandTotal();
|
81 |
-
|
82 |
-
$info->getQuote()->setInterest($info->getQuote()->getStore()->convertPrice($interest, false));
|
83 |
-
$info->getQuote()->setBaseInterest($interest);
|
84 |
-
|
85 |
-
$info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
|
86 |
-
$info->getQuote()->save();
|
87 |
-
}
|
88 |
-
else
|
89 |
-
{
|
90 |
-
$info->getQuote()->setInterest(0.0);
|
91 |
-
$info->getQuote()->setBaseInterest(0.0);
|
92 |
-
|
93 |
-
$info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
|
94 |
-
$info->getQuote()->save();
|
95 |
-
}
|
96 |
-
|
97 |
-
|
98 |
-
return $this;
|
99 |
-
}
|
100 |
-
|
101 |
-
|
102 |
-
/**
|
103 |
-
* Valida dados
|
104 |
-
*
|
105 |
-
* @param Mage_Payment_Model_Info $info
|
106 |
-
* @return Mage_Payment_Model_Abstract
|
107 |
-
*/
|
108 |
-
public function validate()
|
109 |
-
{
|
110 |
-
/*
|
111 |
-
* chama validacao do metodo abstrato
|
112 |
-
*/
|
113 |
-
parent::validate();
|
114 |
-
|
115 |
-
$info = $this->getInfoInstance();
|
116 |
-
$errorMsg = false;
|
117 |
-
|
118 |
-
if($this->getConfigData('buypage', $this->getStoreId()) != "loja")
|
119 |
-
return $this;
|
120 |
-
|
121 |
-
$availableTypes = Mage::getModel('Maxima_Cielo/cc_types')->getCodes();
|
122 |
-
$ccNumber = Mage::helper('core')->decrypt($info->getCcNumber());
|
123 |
-
|
124 |
-
// remove delimitadores do cartao, como "-" e espaco
|
125 |
-
$ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
|
126 |
-
$info->setCcNumber(Mage::helper('core')->encrypt($ccNumber));
|
127 |
-
|
128 |
-
$ccType = '';
|
129 |
-
|
130 |
-
// valida o numero do cartao de credito
|
131 |
-
if(in_array($info->getCcType(), $availableTypes))
|
132 |
-
{
|
133 |
-
if ($this->validateCcNum($ccNumber))
|
134 |
-
{
|
135 |
-
$ccType = 'OT';
|
136 |
-
$ccTypeRegExpList = array
|
137 |
-
(
|
138 |
-
//Solo, Switch or Maestro. International safe
|
139 |
-
/*
|
140 |
-
// Maestro / Solo
|
141 |
-
'SS' => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})'
|
142 |
-
. '|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})'
|
143 |
-
. '|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/',
|
144 |
-
*/
|
145 |
-
// Solo only
|
146 |
-
'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
|
147 |
-
'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)'
|
148 |
-
. '|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)'
|
149 |
-
. '|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))'
|
150 |
-
. '|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))'
|
151 |
-
. '|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
|
152 |
-
// Visa
|
153 |
-
'visa' => '/^4[0-9]{12}([0-9]{3})?$/',
|
154 |
-
// Master Card
|
155 |
-
'mastercard' => '/^5[1-5][0-9]{14}$/',
|
156 |
-
// American Express
|
157 |
-
'amex' => '/^3[47][0-9]{13}$/',
|
158 |
-
// Discovery
|
159 |
-
'discover' => '/^6011[0-9]{12}$/',
|
160 |
-
// JCB
|
161 |
-
'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/',
|
162 |
-
// Diners Club
|
163 |
-
'diners' => '/^3[0,6,8]\d{12}$/'
|
164 |
-
);
|
165 |
-
|
166 |
-
foreach ($ccTypeRegExpList as $ccTypeMatch => $ccTypeRegExp)
|
167 |
-
{
|
168 |
-
if (preg_match($ccTypeRegExp, $ccNumber))
|
169 |
-
{
|
170 |
-
$ccType = $ccTypeMatch;
|
171 |
-
break;
|
172 |
-
}
|
173 |
-
}
|
174 |
-
|
175 |
-
if ($info->getCcType() != 'elo' && ($ccType != $info->getCcType()))
|
176 |
-
{
|
177 |
-
$errorMsg = Mage::helper('Maxima_Cielo')->__('Credit card number mismatch with credit card type.');
|
178 |
-
}
|
179 |
-
}
|
180 |
-
else
|
181 |
-
{
|
182 |
-
$errorMsg = Mage::helper('Maxima_Cielo')->__('Invalid Credit Card Number');
|
183 |
-
}
|
184 |
-
|
185 |
-
}
|
186 |
-
else
|
187 |
-
{
|
188 |
-
$errorMsg = Mage::helper('Maxima_Cielo')->__('Credit card type is not allowed for this payment method.');
|
189 |
-
}
|
190 |
-
|
191 |
-
// valida o numero de verificacao
|
192 |
-
if ($errorMsg === false)
|
193 |
-
{
|
194 |
-
$verificationRegEx = $this->getVerificationRegEx();
|
195 |
-
$regExp = isset($verificationRegEx[$info->getCcType()]) ? $verificationRegEx[$info->getCcType()] : '';
|
196 |
-
|
197 |
-
if ($regExp != '' && (!$info->getCcCid() || !preg_match($regExp, Mage::helper('core')->decrypt($info->getCcCid()))))
|
198 |
-
{
|
199 |
-
$errorMsg = Mage::helper('Maxima_Cielo')->__('Please enter a valid credit card verification number.');
|
200 |
-
}
|
201 |
-
}
|
202 |
-
|
203 |
-
if (!$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth()))
|
204 |
-
{
|
205 |
-
$errorMsg = Mage::helper('Maxima_Cielo')->__('Incorrect credit card expiration date.');
|
206 |
-
}
|
207 |
-
|
208 |
-
if($errorMsg)
|
209 |
-
{
|
210 |
-
Mage::throwException($errorMsg);
|
211 |
-
}
|
212 |
-
|
213 |
-
//This must be after all validation conditions
|
214 |
-
//if ($this->getIsCentinelValidationEnabled())
|
215 |
-
//{
|
216 |
-
// $this->getCentinelValidator()->validate($this->getCentinelValidationData());
|
217 |
-
//}
|
218 |
-
|
219 |
-
return $this;
|
220 |
-
}
|
221 |
-
|
222 |
-
|
223 |
-
/**
|
224 |
-
* Validacao retirada do modelo cc da versao 1.7 do Magento
|
225 |
-
*
|
226 |
-
* @param string $cc_number
|
227 |
-
* @return bool
|
228 |
-
*/
|
229 |
-
public function validateCcNum($ccNumber)
|
230 |
-
{
|
231 |
-
$cardNumber = strrev($ccNumber);
|
232 |
-
$numSum = 0;
|
233 |
-
|
234 |
-
for ($i=0; $i<strlen($cardNumber); $i++)
|
235 |
-
{
|
236 |
-
$currentNum = substr($cardNumber, $i, 1);
|
237 |
-
|
238 |
-
/**
|
239 |
-
* Double every second digit
|
240 |
-
*/
|
241 |
-
if ($i % 2 == 1)
|
242 |
-
{
|
243 |
-
$currentNum *= 2;
|
244 |
-
}
|
245 |
-
|
246 |
-
/**
|
247 |
-
* Add digits of 2-digit numbers together
|
248 |
-
*/
|
249 |
-
if ($currentNum > 9)
|
250 |
-
{
|
251 |
-
$firstNum = $currentNum % 10;
|
252 |
-
$secondNum = ($currentNum - $firstNum) / 10;
|
253 |
-
$currentNum = $firstNum + $secondNum;
|
254 |
-
}
|
255 |
-
|
256 |
-
$numSum += $currentNum;
|
257 |
-
}
|
258 |
-
|
259 |
-
/**
|
260 |
-
* If the total has no remainder it's OK
|
261 |
-
*/
|
262 |
-
|
263 |
-
return ($numSum % 10 == 0);
|
264 |
-
}
|
265 |
-
|
266 |
-
|
267 |
-
/**
|
268 |
-
* Expressao regular retirada do modelo cc da versao 1.7 do Magento
|
269 |
-
*
|
270 |
-
* @return strig regExp
|
271 |
-
*/
|
272 |
-
|
273 |
-
public function getVerificationRegEx()
|
274 |
-
{
|
275 |
-
$verificationExpList = array
|
276 |
-
(
|
277 |
-
'visa' => '/^[0-9]{3}$/', // Visa
|
278 |
-
'mastercard' => '/^[0-9]{3}$/', // Master Card
|
279 |
-
'amex' => '/^[0-9]{4}$/', // American Express
|
280 |
-
'discover' => '/^[0-9]{3}$/', // Discovery
|
281 |
-
'SS' => '/^[0-9]{3,4}$/',
|
282 |
-
'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro
|
283 |
-
'SO' => '/^[0-9]{3,4}$/', // Solo
|
284 |
-
'OT' => '/^[0-9]{3,4}$/',
|
285 |
-
'JCB' => '/^[0-9]{3,4}$/' //JCB
|
286 |
-
);
|
287 |
-
return $verificationExpList;
|
288 |
-
}
|
289 |
-
|
290 |
-
|
291 |
-
/**
|
292 |
-
* Validacao retirada do modelo cc da versao 1.7 do Magento
|
293 |
-
*
|
294 |
-
* @return strig regExp
|
295 |
-
*/
|
296 |
-
|
297 |
-
protected function _validateExpDate($expYear, $expMonth)
|
298 |
-
{
|
299 |
-
$date = Mage::app()->getLocale()->date();
|
300 |
-
|
301 |
-
if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
|
302 |
-
|| ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1)))
|
303 |
-
{
|
304 |
-
return false;
|
305 |
-
}
|
306 |
-
|
307 |
-
return true;
|
308 |
-
}
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
/**
|
314 |
-
* Getter da instancia do pedido
|
315 |
-
*
|
316 |
-
* @return Mage_Sales_Model_Order
|
317 |
-
*/
|
318 |
-
public function getOrder()
|
319 |
-
{
|
320 |
-
if ($this->_order == null) {}
|
321 |
-
|
322 |
-
return $this->_order;
|
323 |
-
}
|
324 |
-
|
325 |
-
/**
|
326 |
-
* Setter do pedido
|
327 |
-
*
|
328 |
-
* @param Mage_Sales_Model_Order $order
|
329 |
-
*/
|
330 |
-
public function setOrder($order)
|
331 |
-
{
|
332 |
-
if ($order instanceof Mage_Sales_Model_Order)
|
333 |
-
{
|
334 |
-
$this->_order = $order;
|
335 |
-
}
|
336 |
-
elseif (is_numeric($order))
|
337 |
-
{
|
338 |
-
$this->_order = Mage::getModel('sales/order')->load($order);
|
339 |
-
}
|
340 |
-
else
|
341 |
-
{
|
342 |
-
$this->_order = null;
|
343 |
-
}
|
344 |
-
return $this;
|
345 |
-
}
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
/**
|
352 |
-
* Abre transacao com a Cielo para uma compra e redirectiona para a
|
353 |
-
* pagina de pagamento na Cielo. Em caso de erro, redireciona para pagina
|
354 |
-
* de erro.
|
355 |
-
*
|
356 |
-
* @return string
|
357 |
-
*/
|
358 |
-
public function getOrderPlaceRedirectUrl()
|
359 |
-
{
|
360 |
-
$info = $this->getInfoInstance();
|
361 |
-
$order = $info->getQuote();
|
362 |
-
$storeId = $this->getStoreId();
|
363 |
-
$payment = $order->getPayment();
|
364 |
-
$additionaldata = unserialize($payment->getData('additional_data'));
|
365 |
-
|
366 |
-
// coleta os dados necessarios
|
367 |
-
$value = Mage::helper('Maxima_Cielo')->formatValueForCielo($order->getGrandTotal());
|
368 |
-
$paymentType = $additionaldata["parcels_number"];
|
369 |
-
$ccType = $payment->getCcType();
|
370 |
-
$paymentParcels = $this->getConfigData('installments_type', $storeId);
|
371 |
-
$cieloNumber = $this->getConfigData('cielo_number', $storeId);
|
372 |
-
$cieloKey = $this->getConfigData('cielo_key', $storeId);
|
373 |
-
$autoCapture = $this->getConfigData('auto_capture', $storeId);
|
374 |
-
$environment = $this->getConfigData('environment', $storeId);
|
375 |
-
$sslFile = $this->getConfigData('ssl_file', $storeId);
|
376 |
-
|
377 |
-
// cria instancia do pedido
|
378 |
-
$webServiceOrder = Mage::getModel('Maxima_Cielo/webServiceOrder', array('enderecoBase' => $environment, 'caminhoCertificado' => $sslFile));
|
379 |
-
|
380 |
-
// preenche dados coletados
|
381 |
-
$webServiceOrderData = array
|
382 |
-
(
|
383 |
-
'ccType' => $ccType,
|
384 |
-
'cieloNumber' => $cieloNumber,
|
385 |
-
'cieloKey' => $cieloKey,
|
386 |
-
'capture' => ($autoCapture == 1) ? 'true' : 'false',
|
387 |
-
'autorize' => '1',
|
388 |
-
'clientOrderNumber' => $payment->getId(),
|
389 |
-
'clientOrderValue' => $value,
|
390 |
-
'postbackURL' => Mage::getUrl('cielo/pay/verify'),
|
391 |
-
'clientSoftDesc' => $this->getConfigData('softdescriptor', $storeId)
|
392 |
-
);
|
393 |
-
|
394 |
-
// conforme mostrado no manual versao 2.0, pagina 11,
|
395 |
-
// caso o cartao seja Dinners, Discover, Elo ou Amex
|
396 |
-
// o valor do flag autorizar deve ser 3
|
397 |
-
if($ccType == "diners" ||
|
398 |
-
$ccType == "discover" ||
|
399 |
-
$ccType == "elo" ||
|
400 |
-
$ccType == "amex" ||
|
401 |
-
!$this->getConfigData('autenticate', $storeId))
|
402 |
-
{
|
403 |
-
$webServiceOrderData['autorize'] = '3';
|
404 |
-
}
|
405 |
-
|
406 |
-
if($paymentType == "1")
|
407 |
-
{
|
408 |
-
$webServiceOrderData['paymentType'] = $paymentType;
|
409 |
-
$webServiceOrderData['paymentParcels'] = 1;
|
410 |
-
}
|
411 |
-
else
|
412 |
-
{
|
413 |
-
$webServiceOrderData['paymentType'] = $paymentParcels;
|
414 |
-
$webServiceOrderData['paymentParcels'] = $paymentType;
|
415 |
-
}
|
416 |
-
|
417 |
-
$webServiceOrder->setData($webServiceOrderData);
|
418 |
-
|
419 |
-
|
420 |
-
// caso seja buy page loja, passa dados do cliente
|
421 |
-
if($this->getConfigData('buypage', $storeId) == "loja")
|
422 |
-
{
|
423 |
-
$ccExpMonth = $info->getCcExpMonth();
|
424 |
-
$ccExpMonth = ($ccExpMonth < 10) ? ("0" . $ccExpMonth) : $ccExpMonth;
|
425 |
-
|
426 |
-
$ownerData = array
|
427 |
-
(
|
428 |
-
'number' => Mage::helper('core')->decrypt($info->getCcNumber()),
|
429 |
-
'exp_date' => $info->getCcExpYear() . $ccExpMonth,
|
430 |
-
'sec_code' => Mage::helper('core')->decrypt($info->getCcCid()),
|
431 |
-
'name' => $info->getCcOwner()
|
432 |
-
);
|
433 |
-
}
|
434 |
-
else
|
435 |
-
{
|
436 |
-
$ownerData = false;
|
437 |
-
}
|
438 |
-
|
439 |
-
$redirectUrl = $webServiceOrder->requestTransaction($ownerData);
|
440 |
-
Mage::getSingleton('core/session')->setData('cielo-transaction', $webServiceOrder);
|
441 |
-
|
442 |
-
if($redirectUrl == false)
|
443 |
-
{
|
444 |
-
// caso nao haja autenticacao, enviar para o tratamento final do pedido
|
445 |
-
if(($this->getConfigData('buypage', $storeId) == "loja") && ($webServiceOrderData['autorize'] == '3'))
|
446 |
-
{
|
447 |
-
return Mage::getUrl('cielo/pay/verify');
|
448 |
-
}
|
449 |
-
// erro nao indentificado
|
450 |
-
else
|
451 |
-
{
|
452 |
-
return Mage::getUrl('cielo/pay/failure');
|
453 |
-
}
|
454 |
-
}
|
455 |
-
else
|
456 |
-
{
|
457 |
-
return $redirectUrl;
|
458 |
-
}
|
459 |
-
}
|
460 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Model_Cc extends Mage_Payment_Model_Method_Abstract
|
28 |
+
{
|
29 |
+
|
30 |
+
protected $_code = 'Maxima_Cielo_Cc';
|
31 |
+
protected $_formBlockType = 'Maxima_Cielo/form_cc';
|
32 |
+
protected $_infoBlockType = 'Maxima_Cielo/info_cc';
|
33 |
+
protected $_canUseInternal = true;
|
34 |
+
protected $_canUseForMultishipping = false;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Assign data to info model instance
|
38 |
+
*
|
39 |
+
* @param mixed $data
|
40 |
+
* @return Mage_Payment_Model_Info
|
41 |
+
*/
|
42 |
+
public function assignData($data)
|
43 |
+
{
|
44 |
+
if (!($data instanceof Varien_Object))
|
45 |
+
{
|
46 |
+
$data = new Varien_Object($data);
|
47 |
+
}
|
48 |
+
|
49 |
+
// salva a bandeira e o numero de parcelas
|
50 |
+
$info = $this->getInfoInstance();
|
51 |
+
$additionaldata = array
|
52 |
+
(
|
53 |
+
'parcels_number' => $data->getParcelsNumber()
|
54 |
+
);
|
55 |
+
|
56 |
+
$info->setCcType($data->getCcType())
|
57 |
+
->setCcNumber(Mage::helper('core')->encrypt($data->getCcNumber()))
|
58 |
+
->setCcOwner($data->getCcOwner())
|
59 |
+
->setCcExpMonth($data->getCcExpMonth())
|
60 |
+
->setCcExpYear($data->getCcExpYear())
|
61 |
+
->setCcCid(Mage::helper('core')->encrypt($data->getCcCid()))
|
62 |
+
->setAdditionalData(serialize($additionaldata));
|
63 |
+
|
64 |
+
|
65 |
+
// pega dados de juros
|
66 |
+
$withoutInterest = intval($this->getConfigData('installment_without_interest', $this->getStoreId()));
|
67 |
+
$interestValue = floatval($this->getConfigData('installment_interest_value', $this->getStoreId()));
|
68 |
+
|
69 |
+
|
70 |
+
// verifica se há juros
|
71 |
+
if($data->getParcelsNumber() > $withoutInterest)
|
72 |
+
{
|
73 |
+
$installmentValue = Mage::helper('Maxima_Cielo')->calcInstallmentValue
|
74 |
+
(
|
75 |
+
$info->getQuote()->getGrandTotal(),
|
76 |
+
$interestValue / 100,
|
77 |
+
$data->getParcelsNumber()
|
78 |
+
);
|
79 |
+
$installmentValue = round($installmentValue, 2);
|
80 |
+
$interest = ($installmentValue * $data->getParcelsNumber()) - $info->getQuote()->getGrandTotal();
|
81 |
+
|
82 |
+
$info->getQuote()->setInterest($info->getQuote()->getStore()->convertPrice($interest, false));
|
83 |
+
$info->getQuote()->setBaseInterest($interest);
|
84 |
+
|
85 |
+
$info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
|
86 |
+
$info->getQuote()->save();
|
87 |
+
}
|
88 |
+
else
|
89 |
+
{
|
90 |
+
$info->getQuote()->setInterest(0.0);
|
91 |
+
$info->getQuote()->setBaseInterest(0.0);
|
92 |
+
|
93 |
+
$info->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
|
94 |
+
$info->getQuote()->save();
|
95 |
+
}
|
96 |
+
|
97 |
+
|
98 |
+
return $this;
|
99 |
+
}
|
100 |
+
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Valida dados
|
104 |
+
*
|
105 |
+
* @param Mage_Payment_Model_Info $info
|
106 |
+
* @return Mage_Payment_Model_Abstract
|
107 |
+
*/
|
108 |
+
public function validate()
|
109 |
+
{
|
110 |
+
/*
|
111 |
+
* chama validacao do metodo abstrato
|
112 |
+
*/
|
113 |
+
parent::validate();
|
114 |
+
|
115 |
+
$info = $this->getInfoInstance();
|
116 |
+
$errorMsg = false;
|
117 |
+
|
118 |
+
if($this->getConfigData('buypage', $this->getStoreId()) != "loja")
|
119 |
+
return $this;
|
120 |
+
|
121 |
+
$availableTypes = Mage::getModel('Maxima_Cielo/cc_types')->getCodes();
|
122 |
+
$ccNumber = Mage::helper('core')->decrypt($info->getCcNumber());
|
123 |
+
|
124 |
+
// remove delimitadores do cartao, como "-" e espaco
|
125 |
+
$ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
|
126 |
+
$info->setCcNumber(Mage::helper('core')->encrypt($ccNumber));
|
127 |
+
|
128 |
+
$ccType = '';
|
129 |
+
|
130 |
+
// valida o numero do cartao de credito
|
131 |
+
if(in_array($info->getCcType(), $availableTypes))
|
132 |
+
{
|
133 |
+
if ($this->validateCcNum($ccNumber))
|
134 |
+
{
|
135 |
+
$ccType = 'OT';
|
136 |
+
$ccTypeRegExpList = array
|
137 |
+
(
|
138 |
+
//Solo, Switch or Maestro. International safe
|
139 |
+
/*
|
140 |
+
// Maestro / Solo
|
141 |
+
'SS' => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})'
|
142 |
+
. '|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})'
|
143 |
+
. '|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/',
|
144 |
+
*/
|
145 |
+
// Solo only
|
146 |
+
'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
|
147 |
+
'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)'
|
148 |
+
. '|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)'
|
149 |
+
. '|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))'
|
150 |
+
. '|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))'
|
151 |
+
. '|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
|
152 |
+
// Visa
|
153 |
+
'visa' => '/^4[0-9]{12}([0-9]{3})?$/',
|
154 |
+
// Master Card
|
155 |
+
'mastercard' => '/^5[1-5][0-9]{14}$/',
|
156 |
+
// American Express
|
157 |
+
'amex' => '/^3[47][0-9]{13}$/',
|
158 |
+
// Discovery
|
159 |
+
'discover' => '/^6011[0-9]{12}$/',
|
160 |
+
// JCB
|
161 |
+
'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/',
|
162 |
+
// Diners Club
|
163 |
+
'diners' => '/^3[0,6,8]\d{12}$/'
|
164 |
+
);
|
165 |
+
|
166 |
+
foreach ($ccTypeRegExpList as $ccTypeMatch => $ccTypeRegExp)
|
167 |
+
{
|
168 |
+
if (preg_match($ccTypeRegExp, $ccNumber))
|
169 |
+
{
|
170 |
+
$ccType = $ccTypeMatch;
|
171 |
+
break;
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
if ($info->getCcType() != 'elo' && ($ccType != $info->getCcType()))
|
176 |
+
{
|
177 |
+
$errorMsg = Mage::helper('Maxima_Cielo')->__('Credit card number mismatch with credit card type.');
|
178 |
+
}
|
179 |
+
}
|
180 |
+
else
|
181 |
+
{
|
182 |
+
$errorMsg = Mage::helper('Maxima_Cielo')->__('Invalid Credit Card Number');
|
183 |
+
}
|
184 |
+
|
185 |
+
}
|
186 |
+
else
|
187 |
+
{
|
188 |
+
$errorMsg = Mage::helper('Maxima_Cielo')->__('Credit card type is not allowed for this payment method.');
|
189 |
+
}
|
190 |
+
|
191 |
+
// valida o numero de verificacao
|
192 |
+
if ($errorMsg === false)
|
193 |
+
{
|
194 |
+
$verificationRegEx = $this->getVerificationRegEx();
|
195 |
+
$regExp = isset($verificationRegEx[$info->getCcType()]) ? $verificationRegEx[$info->getCcType()] : '';
|
196 |
+
|
197 |
+
if ($regExp != '' && (!$info->getCcCid() || !preg_match($regExp, Mage::helper('core')->decrypt($info->getCcCid()))))
|
198 |
+
{
|
199 |
+
$errorMsg = Mage::helper('Maxima_Cielo')->__('Please enter a valid credit card verification number.');
|
200 |
+
}
|
201 |
+
}
|
202 |
+
|
203 |
+
if (!$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth()))
|
204 |
+
{
|
205 |
+
$errorMsg = Mage::helper('Maxima_Cielo')->__('Incorrect credit card expiration date.');
|
206 |
+
}
|
207 |
+
|
208 |
+
if($errorMsg)
|
209 |
+
{
|
210 |
+
Mage::throwException($errorMsg);
|
211 |
+
}
|
212 |
+
|
213 |
+
//This must be after all validation conditions
|
214 |
+
//if ($this->getIsCentinelValidationEnabled())
|
215 |
+
//{
|
216 |
+
// $this->getCentinelValidator()->validate($this->getCentinelValidationData());
|
217 |
+
//}
|
218 |
+
|
219 |
+
return $this;
|
220 |
+
}
|
221 |
+
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Validacao retirada do modelo cc da versao 1.7 do Magento
|
225 |
+
*
|
226 |
+
* @param string $cc_number
|
227 |
+
* @return bool
|
228 |
+
*/
|
229 |
+
public function validateCcNum($ccNumber)
|
230 |
+
{
|
231 |
+
$cardNumber = strrev($ccNumber);
|
232 |
+
$numSum = 0;
|
233 |
+
|
234 |
+
for ($i=0; $i<strlen($cardNumber); $i++)
|
235 |
+
{
|
236 |
+
$currentNum = substr($cardNumber, $i, 1);
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Double every second digit
|
240 |
+
*/
|
241 |
+
if ($i % 2 == 1)
|
242 |
+
{
|
243 |
+
$currentNum *= 2;
|
244 |
+
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Add digits of 2-digit numbers together
|
248 |
+
*/
|
249 |
+
if ($currentNum > 9)
|
250 |
+
{
|
251 |
+
$firstNum = $currentNum % 10;
|
252 |
+
$secondNum = ($currentNum - $firstNum) / 10;
|
253 |
+
$currentNum = $firstNum + $secondNum;
|
254 |
+
}
|
255 |
+
|
256 |
+
$numSum += $currentNum;
|
257 |
+
}
|
258 |
+
|
259 |
+
/**
|
260 |
+
* If the total has no remainder it's OK
|
261 |
+
*/
|
262 |
+
|
263 |
+
return ($numSum % 10 == 0);
|
264 |
+
}
|
265 |
+
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Expressao regular retirada do modelo cc da versao 1.7 do Magento
|
269 |
+
*
|
270 |
+
* @return strig regExp
|
271 |
+
*/
|
272 |
+
|
273 |
+
public function getVerificationRegEx()
|
274 |
+
{
|
275 |
+
$verificationExpList = array
|
276 |
+
(
|
277 |
+
'visa' => '/^[0-9]{3}$/', // Visa
|
278 |
+
'mastercard' => '/^[0-9]{3}$/', // Master Card
|
279 |
+
'amex' => '/^[0-9]{4}$/', // American Express
|
280 |
+
'discover' => '/^[0-9]{3}$/', // Discovery
|
281 |
+
'SS' => '/^[0-9]{3,4}$/',
|
282 |
+
'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro
|
283 |
+
'SO' => '/^[0-9]{3,4}$/', // Solo
|
284 |
+
'OT' => '/^[0-9]{3,4}$/',
|
285 |
+
'JCB' => '/^[0-9]{3,4}$/' //JCB
|
286 |
+
);
|
287 |
+
return $verificationExpList;
|
288 |
+
}
|
289 |
+
|
290 |
+
|
291 |
+
/**
|
292 |
+
* Validacao retirada do modelo cc da versao 1.7 do Magento
|
293 |
+
*
|
294 |
+
* @return strig regExp
|
295 |
+
*/
|
296 |
+
|
297 |
+
protected function _validateExpDate($expYear, $expMonth)
|
298 |
+
{
|
299 |
+
$date = Mage::app()->getLocale()->date();
|
300 |
+
|
301 |
+
if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
|
302 |
+
|| ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1)))
|
303 |
+
{
|
304 |
+
return false;
|
305 |
+
}
|
306 |
+
|
307 |
+
return true;
|
308 |
+
}
|
309 |
+
|
310 |
+
|
311 |
+
|
312 |
+
|
313 |
+
/**
|
314 |
+
* Getter da instancia do pedido
|
315 |
+
*
|
316 |
+
* @return Mage_Sales_Model_Order
|
317 |
+
*/
|
318 |
+
public function getOrder()
|
319 |
+
{
|
320 |
+
if ($this->_order == null) {}
|
321 |
+
|
322 |
+
return $this->_order;
|
323 |
+
}
|
324 |
+
|
325 |
+
/**
|
326 |
+
* Setter do pedido
|
327 |
+
*
|
328 |
+
* @param Mage_Sales_Model_Order $order
|
329 |
+
*/
|
330 |
+
public function setOrder($order)
|
331 |
+
{
|
332 |
+
if ($order instanceof Mage_Sales_Model_Order)
|
333 |
+
{
|
334 |
+
$this->_order = $order;
|
335 |
+
}
|
336 |
+
elseif (is_numeric($order))
|
337 |
+
{
|
338 |
+
$this->_order = Mage::getModel('sales/order')->load($order);
|
339 |
+
}
|
340 |
+
else
|
341 |
+
{
|
342 |
+
$this->_order = null;
|
343 |
+
}
|
344 |
+
return $this;
|
345 |
+
}
|
346 |
+
|
347 |
+
|
348 |
+
|
349 |
+
|
350 |
+
|
351 |
+
/**
|
352 |
+
* Abre transacao com a Cielo para uma compra e redirectiona para a
|
353 |
+
* pagina de pagamento na Cielo. Em caso de erro, redireciona para pagina
|
354 |
+
* de erro.
|
355 |
+
*
|
356 |
+
* @return string
|
357 |
+
*/
|
358 |
+
public function getOrderPlaceRedirectUrl()
|
359 |
+
{
|
360 |
+
$info = $this->getInfoInstance();
|
361 |
+
$order = $info->getQuote();
|
362 |
+
$storeId = $this->getStoreId();
|
363 |
+
$payment = $order->getPayment();
|
364 |
+
$additionaldata = unserialize($payment->getData('additional_data'));
|
365 |
+
|
366 |
+
// coleta os dados necessarios
|
367 |
+
$value = Mage::helper('Maxima_Cielo')->formatValueForCielo($order->getGrandTotal());
|
368 |
+
$paymentType = $additionaldata["parcels_number"];
|
369 |
+
$ccType = $payment->getCcType();
|
370 |
+
$paymentParcels = $this->getConfigData('installments_type', $storeId);
|
371 |
+
$cieloNumber = $this->getConfigData('cielo_number', $storeId);
|
372 |
+
$cieloKey = $this->getConfigData('cielo_key', $storeId);
|
373 |
+
$autoCapture = $this->getConfigData('auto_capture', $storeId);
|
374 |
+
$environment = $this->getConfigData('environment', $storeId);
|
375 |
+
$sslFile = $this->getConfigData('ssl_file', $storeId);
|
376 |
+
|
377 |
+
// cria instancia do pedido
|
378 |
+
$webServiceOrder = Mage::getModel('Maxima_Cielo/webServiceOrder', array('enderecoBase' => $environment, 'caminhoCertificado' => $sslFile));
|
379 |
+
|
380 |
+
// preenche dados coletados
|
381 |
+
$webServiceOrderData = array
|
382 |
+
(
|
383 |
+
'ccType' => $ccType,
|
384 |
+
'cieloNumber' => $cieloNumber,
|
385 |
+
'cieloKey' => $cieloKey,
|
386 |
+
'capture' => ($autoCapture == 1) ? 'true' : 'false',
|
387 |
+
'autorize' => '1',
|
388 |
+
'clientOrderNumber' => $payment->getId(),
|
389 |
+
'clientOrderValue' => $value,
|
390 |
+
'postbackURL' => Mage::getUrl('cielo/pay/verify'),
|
391 |
+
'clientSoftDesc' => $this->getConfigData('softdescriptor', $storeId)
|
392 |
+
);
|
393 |
+
|
394 |
+
// conforme mostrado no manual versao 2.0, pagina 11,
|
395 |
+
// caso o cartao seja Dinners, Discover, Elo ou Amex
|
396 |
+
// o valor do flag autorizar deve ser 3
|
397 |
+
if($ccType == "diners" ||
|
398 |
+
$ccType == "discover" ||
|
399 |
+
$ccType == "elo" ||
|
400 |
+
$ccType == "amex" ||
|
401 |
+
!$this->getConfigData('autenticate', $storeId))
|
402 |
+
{
|
403 |
+
$webServiceOrderData['autorize'] = '3';
|
404 |
+
}
|
405 |
+
|
406 |
+
if($paymentType == "1")
|
407 |
+
{
|
408 |
+
$webServiceOrderData['paymentType'] = $paymentType;
|
409 |
+
$webServiceOrderData['paymentParcels'] = 1;
|
410 |
+
}
|
411 |
+
else
|
412 |
+
{
|
413 |
+
$webServiceOrderData['paymentType'] = $paymentParcels;
|
414 |
+
$webServiceOrderData['paymentParcels'] = $paymentType;
|
415 |
+
}
|
416 |
+
|
417 |
+
$webServiceOrder->setData($webServiceOrderData);
|
418 |
+
|
419 |
+
|
420 |
+
// caso seja buy page loja, passa dados do cliente
|
421 |
+
if($this->getConfigData('buypage', $storeId) == "loja")
|
422 |
+
{
|
423 |
+
$ccExpMonth = $info->getCcExpMonth();
|
424 |
+
$ccExpMonth = ($ccExpMonth < 10) ? ("0" . $ccExpMonth) : $ccExpMonth;
|
425 |
+
|
426 |
+
$ownerData = array
|
427 |
+
(
|
428 |
+
'number' => Mage::helper('core')->decrypt($info->getCcNumber()),
|
429 |
+
'exp_date' => $info->getCcExpYear() . $ccExpMonth,
|
430 |
+
'sec_code' => Mage::helper('core')->decrypt($info->getCcCid()),
|
431 |
+
'name' => $info->getCcOwner()
|
432 |
+
);
|
433 |
+
}
|
434 |
+
else
|
435 |
+
{
|
436 |
+
$ownerData = false;
|
437 |
+
}
|
438 |
+
|
439 |
+
$redirectUrl = $webServiceOrder->requestTransaction($ownerData);
|
440 |
+
Mage::getSingleton('core/session')->setData('cielo-transaction', $webServiceOrder);
|
441 |
+
|
442 |
+
if($redirectUrl == false)
|
443 |
+
{
|
444 |
+
// caso nao haja autenticacao, enviar para o tratamento final do pedido
|
445 |
+
if(($this->getConfigData('buypage', $storeId) == "loja") && ($webServiceOrderData['autorize'] == '3'))
|
446 |
+
{
|
447 |
+
return Mage::getUrl('cielo/pay/verify');
|
448 |
+
}
|
449 |
+
// erro nao indentificado
|
450 |
+
else
|
451 |
+
{
|
452 |
+
return Mage::getUrl('cielo/pay/failure');
|
453 |
+
}
|
454 |
+
}
|
455 |
+
else
|
456 |
+
{
|
457 |
+
return $redirectUrl;
|
458 |
+
}
|
459 |
+
}
|
460 |
+
}
|
app/code/community/Maxima/Cielo/Model/Cc/InstallmentType.php
CHANGED
@@ -1,44 +1,44 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Model_Cc_InstallmentType
|
28 |
-
{
|
29 |
-
/**
|
30 |
-
*
|
31 |
-
* Opcoes de tipo de parcelamento
|
32 |
-
*
|
33 |
-
*/
|
34 |
-
|
35 |
-
public function toOptionArray()
|
36 |
-
{
|
37 |
-
$options = array();
|
38 |
-
|
39 |
-
$options['2'] = Mage::helper('adminhtml')->__('Loja');
|
40 |
-
$options['3'] = Mage::helper('adminhtml')->__('Administradora');
|
41 |
-
|
42 |
-
return $options;
|
43 |
-
}
|
44 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Model_Cc_InstallmentType
|
28 |
+
{
|
29 |
+
/**
|
30 |
+
*
|
31 |
+
* Opcoes de tipo de parcelamento
|
32 |
+
*
|
33 |
+
*/
|
34 |
+
|
35 |
+
public function toOptionArray()
|
36 |
+
{
|
37 |
+
$options = array();
|
38 |
+
|
39 |
+
$options['2'] = Mage::helper('adminhtml')->__('Loja');
|
40 |
+
$options['3'] = Mage::helper('adminhtml')->__('Administradora');
|
41 |
+
|
42 |
+
return $options;
|
43 |
+
}
|
44 |
+
}
|
app/code/community/Maxima/Cielo/Model/Cc/MaxInstallments.php
CHANGED
@@ -1,55 +1,55 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Model_Cc_MaxInstallments
|
28 |
-
{
|
29 |
-
/**
|
30 |
-
*
|
31 |
-
* Opcoes de numero de parcelas
|
32 |
-
*
|
33 |
-
*/
|
34 |
-
|
35 |
-
public function toOptionArray()
|
36 |
-
{
|
37 |
-
$options = array();
|
38 |
-
|
39 |
-
$options['1'] = Mage::helper('adminhtml')->__('1x - Sem parcelamento');
|
40 |
-
$options['2'] = Mage::helper('adminhtml')->__('2x');
|
41 |
-
$options['3'] = Mage::helper('adminhtml')->__('3x');
|
42 |
-
$options['4'] = Mage::helper('adminhtml')->__('4x');
|
43 |
-
$options['5'] = Mage::helper('adminhtml')->__('5x');
|
44 |
-
$options['6'] = Mage::helper('adminhtml')->__('6x');
|
45 |
-
$options['7'] = Mage::helper('adminhtml')->__('7x');
|
46 |
-
$options['8'] = Mage::helper('adminhtml')->__('8x');
|
47 |
-
$options['9'] = Mage::helper('adminhtml')->__('9x');
|
48 |
-
$options['10'] = Mage::helper('adminhtml')->__('10x');
|
49 |
-
$options['11'] = Mage::helper('adminhtml')->__('11x');
|
50 |
-
$options['12'] = Mage::helper('adminhtml')->__('12x');
|
51 |
-
|
52 |
-
|
53 |
-
return $options;
|
54 |
-
}
|
55 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Model_Cc_MaxInstallments
|
28 |
+
{
|
29 |
+
/**
|
30 |
+
*
|
31 |
+
* Opcoes de numero de parcelas
|
32 |
+
*
|
33 |
+
*/
|
34 |
+
|
35 |
+
public function toOptionArray()
|
36 |
+
{
|
37 |
+
$options = array();
|
38 |
+
|
39 |
+
$options['1'] = Mage::helper('adminhtml')->__('1x - Sem parcelamento');
|
40 |
+
$options['2'] = Mage::helper('adminhtml')->__('2x');
|
41 |
+
$options['3'] = Mage::helper('adminhtml')->__('3x');
|
42 |
+
$options['4'] = Mage::helper('adminhtml')->__('4x');
|
43 |
+
$options['5'] = Mage::helper('adminhtml')->__('5x');
|
44 |
+
$options['6'] = Mage::helper('adminhtml')->__('6x');
|
45 |
+
$options['7'] = Mage::helper('adminhtml')->__('7x');
|
46 |
+
$options['8'] = Mage::helper('adminhtml')->__('8x');
|
47 |
+
$options['9'] = Mage::helper('adminhtml')->__('9x');
|
48 |
+
$options['10'] = Mage::helper('adminhtml')->__('10x');
|
49 |
+
$options['11'] = Mage::helper('adminhtml')->__('11x');
|
50 |
+
$options['12'] = Mage::helper('adminhtml')->__('12x');
|
51 |
+
|
52 |
+
|
53 |
+
return $options;
|
54 |
+
}
|
55 |
+
}
|
app/code/community/Maxima/Cielo/Model/Cc/Types.php
CHANGED
@@ -1,133 +1,133 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Model_Cc_Types
|
28 |
-
{
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Formato vetor de vetores
|
32 |
-
*
|
33 |
-
* @return array
|
34 |
-
*/
|
35 |
-
public function toOptionArray()
|
36 |
-
{
|
37 |
-
/**
|
38 |
-
* value: indice
|
39 |
-
* label: descricao
|
40 |
-
* image: nome da imagem
|
41 |
-
* inst_s: numero maximo de parcelas para parcelamento na loja
|
42 |
-
* inst_a: numero maximo de parcelas para parcelamento na administradora
|
43 |
-
*/
|
44 |
-
|
45 |
-
return array
|
46 |
-
(
|
47 |
-
array
|
48 |
-
(
|
49 |
-
'value' => 'visa',
|
50 |
-
'label' => Mage::helper('adminhtml')->__('Visa'),
|
51 |
-
'image' => 'Visa.png',
|
52 |
-
'inst_s' => 12,
|
53 |
-
'inst_a' => 1
|
54 |
-
),
|
55 |
-
array
|
56 |
-
(
|
57 |
-
'value' => 'mastercard',
|
58 |
-
'label' => Mage::helper('adminhtml')->__('Mastercard'),
|
59 |
-
'image' => 'Master.png',
|
60 |
-
'inst_s' => 12,
|
61 |
-
'inst_a' => 1
|
62 |
-
),
|
63 |
-
array
|
64 |
-
(
|
65 |
-
'value' => 'diners',
|
66 |
-
'label' => Mage::helper('adminhtml')->__('Diners Club'),
|
67 |
-
'image' => 'Diners.png',
|
68 |
-
'inst_s' => 10,
|
69 |
-
'inst_a' => 1
|
70 |
-
),
|
71 |
-
array
|
72 |
-
(
|
73 |
-
'value' => 'discover',
|
74 |
-
'label' => Mage::helper('adminhtml')->__('Discover'),
|
75 |
-
'image' => 'Discover.png',
|
76 |
-
'inst_s' => 1,
|
77 |
-
'inst_a' => 1
|
78 |
-
),
|
79 |
-
array
|
80 |
-
(
|
81 |
-
'value' => 'elo',
|
82 |
-
'label' => Mage::helper('adminhtml')->__('Elo'),
|
83 |
-
'image' => 'Elo.png',
|
84 |
-
'inst_s' => 12,
|
85 |
-
'inst_a' => 1
|
86 |
-
),
|
87 |
-
array
|
88 |
-
(
|
89 |
-
'value' => 'amex',
|
90 |
-
'label' => Mage::helper('adminhtml')->__('American Express'),
|
91 |
-
'image' => 'Amex.png',
|
92 |
-
'inst_s' => 10,
|
93 |
-
'inst_a' => 24
|
94 |
-
)
|
95 |
-
);
|
96 |
-
}
|
97 |
-
|
98 |
-
/**
|
99 |
-
* Formato chave-valor
|
100 |
-
*
|
101 |
-
* @return array
|
102 |
-
*/
|
103 |
-
public function toArray()
|
104 |
-
{
|
105 |
-
return array
|
106 |
-
(
|
107 |
-
'visa' => Mage::helper('adminhtml')->__('Visa'),
|
108 |
-
'mastercard' => Mage::helper('adminhtml')->__('Mastercard'),
|
109 |
-
'diners' => Mage::helper('adminhtml')->__('Diners Club'),
|
110 |
-
'discover' => Mage::helper('adminhtml')->__('Discover'),
|
111 |
-
'elo' => Mage::helper('adminhtml')->__('Elo'),
|
112 |
-
'amex' => Mage::helper('adminhtml')->__('American Express'),
|
113 |
-
);
|
114 |
-
}
|
115 |
-
|
116 |
-
/**
|
117 |
-
* Formato chave
|
118 |
-
*
|
119 |
-
* @return array
|
120 |
-
*/
|
121 |
-
public function getCodes()
|
122 |
-
{
|
123 |
-
return array
|
124 |
-
(
|
125 |
-
'visa',
|
126 |
-
'mastercard',
|
127 |
-
'diners',
|
128 |
-
'discover',
|
129 |
-
'elo',
|
130 |
-
'amex'
|
131 |
-
);
|
132 |
-
}
|
133 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Model_Cc_Types
|
28 |
+
{
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Formato vetor de vetores
|
32 |
+
*
|
33 |
+
* @return array
|
34 |
+
*/
|
35 |
+
public function toOptionArray()
|
36 |
+
{
|
37 |
+
/**
|
38 |
+
* value: indice
|
39 |
+
* label: descricao
|
40 |
+
* image: nome da imagem
|
41 |
+
* inst_s: numero maximo de parcelas para parcelamento na loja
|
42 |
+
* inst_a: numero maximo de parcelas para parcelamento na administradora
|
43 |
+
*/
|
44 |
+
|
45 |
+
return array
|
46 |
+
(
|
47 |
+
array
|
48 |
+
(
|
49 |
+
'value' => 'visa',
|
50 |
+
'label' => Mage::helper('adminhtml')->__('Visa'),
|
51 |
+
'image' => 'Visa.png',
|
52 |
+
'inst_s' => 12,
|
53 |
+
'inst_a' => 1
|
54 |
+
),
|
55 |
+
array
|
56 |
+
(
|
57 |
+
'value' => 'mastercard',
|
58 |
+
'label' => Mage::helper('adminhtml')->__('Mastercard'),
|
59 |
+
'image' => 'Master.png',
|
60 |
+
'inst_s' => 12,
|
61 |
+
'inst_a' => 1
|
62 |
+
),
|
63 |
+
array
|
64 |
+
(
|
65 |
+
'value' => 'diners',
|
66 |
+
'label' => Mage::helper('adminhtml')->__('Diners Club'),
|
67 |
+
'image' => 'Diners.png',
|
68 |
+
'inst_s' => 10,
|
69 |
+
'inst_a' => 1
|
70 |
+
),
|
71 |
+
array
|
72 |
+
(
|
73 |
+
'value' => 'discover',
|
74 |
+
'label' => Mage::helper('adminhtml')->__('Discover'),
|
75 |
+
'image' => 'Discover.png',
|
76 |
+
'inst_s' => 1,
|
77 |
+
'inst_a' => 1
|
78 |
+
),
|
79 |
+
array
|
80 |
+
(
|
81 |
+
'value' => 'elo',
|
82 |
+
'label' => Mage::helper('adminhtml')->__('Elo'),
|
83 |
+
'image' => 'Elo.png',
|
84 |
+
'inst_s' => 12,
|
85 |
+
'inst_a' => 1
|
86 |
+
),
|
87 |
+
array
|
88 |
+
(
|
89 |
+
'value' => 'amex',
|
90 |
+
'label' => Mage::helper('adminhtml')->__('American Express'),
|
91 |
+
'image' => 'Amex.png',
|
92 |
+
'inst_s' => 10,
|
93 |
+
'inst_a' => 24
|
94 |
+
)
|
95 |
+
);
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Formato chave-valor
|
100 |
+
*
|
101 |
+
* @return array
|
102 |
+
*/
|
103 |
+
public function toArray()
|
104 |
+
{
|
105 |
+
return array
|
106 |
+
(
|
107 |
+
'visa' => Mage::helper('adminhtml')->__('Visa'),
|
108 |
+
'mastercard' => Mage::helper('adminhtml')->__('Mastercard'),
|
109 |
+
'diners' => Mage::helper('adminhtml')->__('Diners Club'),
|
110 |
+
'discover' => Mage::helper('adminhtml')->__('Discover'),
|
111 |
+
'elo' => Mage::helper('adminhtml')->__('Elo'),
|
112 |
+
'amex' => Mage::helper('adminhtml')->__('American Express'),
|
113 |
+
);
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Formato chave
|
118 |
+
*
|
119 |
+
* @return array
|
120 |
+
*/
|
121 |
+
public function getCodes()
|
122 |
+
{
|
123 |
+
return array
|
124 |
+
(
|
125 |
+
'visa',
|
126 |
+
'mastercard',
|
127 |
+
'diners',
|
128 |
+
'discover',
|
129 |
+
'elo',
|
130 |
+
'amex'
|
131 |
+
);
|
132 |
+
}
|
133 |
}
|
app/code/community/Maxima/Cielo/Model/Dc.php
CHANGED
@@ -1,405 +1,405 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Model_Dc extends Mage_Payment_Model_Method_Abstract
|
28 |
-
{
|
29 |
-
|
30 |
-
protected $_code = 'Maxima_Cielo_Dc';
|
31 |
-
protected $_formBlockType = 'Maxima_Cielo/form_dc';
|
32 |
-
protected $_infoBlockType = 'Maxima_Cielo/info_dc';
|
33 |
-
protected $_canUseInternal = true;
|
34 |
-
protected $_canUseForMultishipping = false;
|
35 |
-
|
36 |
-
/**
|
37 |
-
* Assign data to info model instance
|
38 |
-
*
|
39 |
-
* @param mixed $data
|
40 |
-
* @return Mage_Payment_Model_Info
|
41 |
-
*/
|
42 |
-
public function assignData($data)
|
43 |
-
{
|
44 |
-
if (!($data instanceof Varien_Object))
|
45 |
-
{
|
46 |
-
$data = new Varien_Object($data);
|
47 |
-
}
|
48 |
-
|
49 |
-
// salva a bandeira
|
50 |
-
$info = $this->getInfoInstance();
|
51 |
-
|
52 |
-
// converte nomenclatura da bandeira
|
53 |
-
if($data->getCcType() == "visa-electron")
|
54 |
-
{
|
55 |
-
$cardType = "visa";
|
56 |
-
}
|
57 |
-
else
|
58 |
-
{
|
59 |
-
$cardType = $data->getCcType();
|
60 |
-
}
|
61 |
-
|
62 |
-
$info->setCcType($cardType)
|
63 |
-
->setCcNumber(Mage::helper('core')->encrypt($data->getCcNumber()))
|
64 |
-
->setCcOwner($data->getCcOwner())
|
65 |
-
->setCcExpMonth($data->getCcExpMonth())
|
66 |
-
->setCcExpYear($data->getCcExpYear())
|
67 |
-
->setCcCid(Mage::helper('core')->encrypt($data->getCcCid()));
|
68 |
-
|
69 |
-
|
70 |
-
return $this;
|
71 |
-
}
|
72 |
-
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Valida dados
|
76 |
-
*
|
77 |
-
* @param Mage_Payment_Model_Info $info
|
78 |
-
* @return Mage_Payment_Model_Abstract
|
79 |
-
*/
|
80 |
-
public function validate()
|
81 |
-
{
|
82 |
-
/*
|
83 |
-
* chama validacao do metodo abstrato
|
84 |
-
*/
|
85 |
-
parent::validate();
|
86 |
-
|
87 |
-
if($this->getConfigData('buypage', $this->getStoreId()) != "loja")
|
88 |
-
return $this;
|
89 |
-
|
90 |
-
$info = $this->getInfoInstance();
|
91 |
-
$errorMsg = false;
|
92 |
-
|
93 |
-
$availableTypes = Mage::getModel('Maxima_Cielo/dc_types')->getCodes();
|
94 |
-
$ccNumber = Mage::helper('core')->decrypt($info->getCcNumber());
|
95 |
-
|
96 |
-
// remove delimitadores do cartao, como "-" e espaco
|
97 |
-
$ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
|
98 |
-
$info->setCcNumber(Mage::helper('core')->encrypt($ccNumber));
|
99 |
-
|
100 |
-
$ccType = '';
|
101 |
-
|
102 |
-
// valida o numero do cartao de credito
|
103 |
-
if(in_array($info->getCcType(), $availableTypes))
|
104 |
-
{
|
105 |
-
if ($this->validateCcNum($ccNumber))
|
106 |
-
{
|
107 |
-
$ccType = 'OT';
|
108 |
-
$ccTypeRegExpList = array
|
109 |
-
(
|
110 |
-
//Solo, Switch or Maestro. International safe
|
111 |
-
/*
|
112 |
-
// Maestro / Solo
|
113 |
-
'SS' => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})'
|
114 |
-
. '|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})'
|
115 |
-
. '|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/',
|
116 |
-
*/
|
117 |
-
// Solo only
|
118 |
-
'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
|
119 |
-
'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)'
|
120 |
-
. '|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)'
|
121 |
-
. '|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))'
|
122 |
-
. '|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))'
|
123 |
-
. '|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
|
124 |
-
// Visa
|
125 |
-
'visa' => '/^4[0-9]{12}([0-9]{3})?$/',
|
126 |
-
// Master Card
|
127 |
-
'mastercard' => '/^5[1-5][0-9]{14}$/',
|
128 |
-
// American Express
|
129 |
-
'amex' => '/^3[47][0-9]{13}$/',
|
130 |
-
// Discovery
|
131 |
-
'discover' => '/^6011[0-9]{12}$/',
|
132 |
-
// JCB
|
133 |
-
'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/',
|
134 |
-
// Diners Club
|
135 |
-
'diners' => '/^3[0,6,8]\d{12}$/'
|
136 |
-
);
|
137 |
-
|
138 |
-
foreach ($ccTypeRegExpList as $ccTypeMatch => $ccTypeRegExp)
|
139 |
-
{
|
140 |
-
if (preg_match($ccTypeRegExp, $ccNumber))
|
141 |
-
{
|
142 |
-
$ccType = $ccTypeMatch;
|
143 |
-
break;
|
144 |
-
}
|
145 |
-
}
|
146 |
-
|
147 |
-
if ($info->getCcType() != 'elo' && ($ccType != $info->getCcType()))
|
148 |
-
{
|
149 |
-
$errorMsg = Mage::helper('Maxima_Cielo')->__('Credit card number mismatch with credit card type.');
|
150 |
-
}
|
151 |
-
}
|
152 |
-
else
|
153 |
-
{
|
154 |
-
$errorMsg = Mage::helper('Maxima_Cielo')->__('Invalid Credit Card Number');
|
155 |
-
}
|
156 |
-
|
157 |
-
}
|
158 |
-
else
|
159 |
-
{
|
160 |
-
$errorMsg = Mage::helper('Maxima_Cielo')->__('Credit card type is not allowed for this payment method.');
|
161 |
-
}
|
162 |
-
|
163 |
-
// valida o numero de verificacao
|
164 |
-
if ($errorMsg === false)
|
165 |
-
{
|
166 |
-
$verificationRegEx = $this->getVerificationRegEx();
|
167 |
-
$regExp = isset($verificationRegEx[$info->getCcType()]) ? $verificationRegEx[$info->getCcType()] : '';
|
168 |
-
|
169 |
-
if ($regExp != '' && (!$info->getCcCid() || !preg_match($regExp, Mage::helper('core')->decrypt($info->getCcCid()))))
|
170 |
-
{
|
171 |
-
$errorMsg = Mage::helper('Maxima_Cielo')->__('Please enter a valid credit card verification number.');
|
172 |
-
}
|
173 |
-
}
|
174 |
-
|
175 |
-
if (!$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth()))
|
176 |
-
{
|
177 |
-
$errorMsg = Mage::helper('Maxima_Cielo')->__('Incorrect credit card expiration date.');
|
178 |
-
}
|
179 |
-
|
180 |
-
if($errorMsg)
|
181 |
-
{
|
182 |
-
Mage::throwException($errorMsg);
|
183 |
-
}
|
184 |
-
|
185 |
-
//This must be after all validation conditions
|
186 |
-
//if ($this->getIsCentinelValidationEnabled())
|
187 |
-
//{
|
188 |
-
// $this->getCentinelValidator()->validate($this->getCentinelValidationData());
|
189 |
-
//}
|
190 |
-
|
191 |
-
return $this;
|
192 |
-
}
|
193 |
-
|
194 |
-
|
195 |
-
/**
|
196 |
-
* Validacao retirada do modelo cc da versao 1.7 do Magento
|
197 |
-
*
|
198 |
-
* @param string $cc_number
|
199 |
-
* @return bool
|
200 |
-
*/
|
201 |
-
public function validateCcNum($ccNumber)
|
202 |
-
{
|
203 |
-
$cardNumber = strrev($ccNumber);
|
204 |
-
$numSum = 0;
|
205 |
-
|
206 |
-
for ($i=0; $i<strlen($cardNumber); $i++)
|
207 |
-
{
|
208 |
-
$currentNum = substr($cardNumber, $i, 1);
|
209 |
-
|
210 |
-
/**
|
211 |
-
* Double every second digit
|
212 |
-
*/
|
213 |
-
if ($i % 2 == 1)
|
214 |
-
{
|
215 |
-
$currentNum *= 2;
|
216 |
-
}
|
217 |
-
|
218 |
-
/**
|
219 |
-
* Add digits of 2-digit numbers together
|
220 |
-
*/
|
221 |
-
if ($currentNum > 9)
|
222 |
-
{
|
223 |
-
$firstNum = $currentNum % 10;
|
224 |
-
$secondNum = ($currentNum - $firstNum) / 10;
|
225 |
-
$currentNum = $firstNum + $secondNum;
|
226 |
-
}
|
227 |
-
|
228 |
-
$numSum += $currentNum;
|
229 |
-
}
|
230 |
-
|
231 |
-
/**
|
232 |
-
* If the total has no remainder it's OK
|
233 |
-
*/
|
234 |
-
|
235 |
-
return ($numSum % 10 == 0);
|
236 |
-
}
|
237 |
-
|
238 |
-
|
239 |
-
/**
|
240 |
-
* Expressao regular retirada do modelo cc da versao 1.7 do Magento
|
241 |
-
*
|
242 |
-
* @return strig regExp
|
243 |
-
*/
|
244 |
-
|
245 |
-
public function getVerificationRegEx()
|
246 |
-
{
|
247 |
-
$verificationExpList = array
|
248 |
-
(
|
249 |
-
'visa' => '/^[0-9]{3}$/', // Visa
|
250 |
-
'mastercard' => '/^[0-9]{3}$/', // Master Card
|
251 |
-
'amex' => '/^[0-9]{4}$/', // American Express
|
252 |
-
'discover' => '/^[0-9]{3}$/', // Discovery
|
253 |
-
'SS' => '/^[0-9]{3,4}$/',
|
254 |
-
'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro
|
255 |
-
'SO' => '/^[0-9]{3,4}$/', // Solo
|
256 |
-
'OT' => '/^[0-9]{3,4}$/',
|
257 |
-
'JCB' => '/^[0-9]{3,4}$/' //JCB
|
258 |
-
);
|
259 |
-
return $verificationExpList;
|
260 |
-
}
|
261 |
-
|
262 |
-
|
263 |
-
/**
|
264 |
-
* Validacao retirada do modelo cc da versao 1.7 do Magento
|
265 |
-
*
|
266 |
-
* @return strig regExp
|
267 |
-
*/
|
268 |
-
|
269 |
-
protected function _validateExpDate($expYear, $expMonth)
|
270 |
-
{
|
271 |
-
$date = Mage::app()->getLocale()->date();
|
272 |
-
|
273 |
-
if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
|
274 |
-
|| ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1)))
|
275 |
-
{
|
276 |
-
return false;
|
277 |
-
}
|
278 |
-
|
279 |
-
return true;
|
280 |
-
}
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
/**
|
286 |
-
* Getter da instancia do pedido
|
287 |
-
*
|
288 |
-
* @return Mage_Sales_Model_Order
|
289 |
-
*/
|
290 |
-
public function getOrder()
|
291 |
-
{
|
292 |
-
if ($this->_order == null) {}
|
293 |
-
|
294 |
-
return $this->_order;
|
295 |
-
}
|
296 |
-
|
297 |
-
/**
|
298 |
-
* Setter da instancia do pedido
|
299 |
-
*
|
300 |
-
* @param Mage_Sales_Model_Order $order
|
301 |
-
*/
|
302 |
-
public function setOrder($order)
|
303 |
-
{
|
304 |
-
if ($order instanceof Mage_Sales_Model_Order)
|
305 |
-
{
|
306 |
-
$this->_order = $order;
|
307 |
-
}
|
308 |
-
elseif (is_numeric($order))
|
309 |
-
{
|
310 |
-
$this->_order = Mage::getModel('sales/order')->load($order);
|
311 |
-
}
|
312 |
-
else
|
313 |
-
{
|
314 |
-
$this->_order = null;
|
315 |
-
}
|
316 |
-
return $this;
|
317 |
-
}
|
318 |
-
|
319 |
-
|
320 |
-
/**
|
321 |
-
* Formata o valor da compra de acordo com a definicao da Cielo
|
322 |
-
*
|
323 |
-
* @param string $originalValue
|
324 |
-
* @return string
|
325 |
-
*/
|
326 |
-
public function getOrderPlaceRedirectUrl()
|
327 |
-
{
|
328 |
-
$info = $this->getInfoInstance();
|
329 |
-
$order = $info->getQuote();
|
330 |
-
$storeId = $this->getStoreId();
|
331 |
-
$payment = $order->getPayment();
|
332 |
-
$additionaldata = unserialize($payment->getData('additional_data'));
|
333 |
-
|
334 |
-
// coleta os dados necessarios
|
335 |
-
$value = Mage::helper('Maxima_Cielo')->formatValueForCielo($order->getGrandTotal());
|
336 |
-
$paymentType = $additionaldata["parcels_number"];
|
337 |
-
$ccType = $payment->getCcType();
|
338 |
-
$paymentParcels = $this->getConfigData('installments_type', $storeId);
|
339 |
-
$cieloNumber = $this->getConfigData('cielo_number', $storeId);
|
340 |
-
$cieloKey = $this->getConfigData('cielo_key', $storeId);
|
341 |
-
$environment = $this->getConfigData('environment', $storeId);
|
342 |
-
$sslFile = $this->getConfigData('ssl_file', $storeId);
|
343 |
-
|
344 |
-
// cria instancia do pedido
|
345 |
-
$webServiceOrder = Mage::getModel('Maxima_Cielo/webServiceOrder', array('enderecoBase' => $environment, 'caminhoCertificado' => $sslFile));
|
346 |
-
|
347 |
-
// preenche dados coletados
|
348 |
-
$webServiceOrderData = array
|
349 |
-
(
|
350 |
-
'ccType' => $ccType,
|
351 |
-
'cieloNumber' => $cieloNumber,
|
352 |
-
'cieloKey' => $cieloKey,
|
353 |
-
'capture' => 'true',
|
354 |
-
'autorize' => '1',
|
355 |
-
'clientOrderNumber' => $payment->getId(),
|
356 |
-
'clientOrderValue' => $value,
|
357 |
-
'postbackURL' => Mage::getUrl('cielo/pay/verify'),
|
358 |
-
'paymentType' => 'A',
|
359 |
-
'paymentParcels' => 1,
|
360 |
-
'clientSoftDesc' => $this->getConfigData('softdescriptor', $storeId)
|
361 |
-
);
|
362 |
-
|
363 |
-
$webServiceOrder->setData($webServiceOrderData);
|
364 |
-
|
365 |
-
// caso seja buy page loja, passa dados do cliente
|
366 |
-
if($this->getConfigData('buypage', $storeId) == "loja")
|
367 |
-
{
|
368 |
-
$ccExpMonth = $info->getCcExpMonth();
|
369 |
-
$ccExpMonth = ($ccExpMonth < 10) ? ("0" . $ccExpMonth) : $ccExpMonth;
|
370 |
-
|
371 |
-
$ownerData = array
|
372 |
-
(
|
373 |
-
'number' => Mage::helper('core')->decrypt($info->getCcNumber()),
|
374 |
-
'exp_date' => $info->getCcExpYear() . $ccExpMonth,
|
375 |
-
'sec_code' => Mage::helper('core')->decrypt($info->getCcCid()),
|
376 |
-
'name' => $info->getCcOwner()
|
377 |
-
);
|
378 |
-
}
|
379 |
-
else
|
380 |
-
{
|
381 |
-
$ownerData = false;
|
382 |
-
}
|
383 |
-
|
384 |
-
$redirectUrl = $webServiceOrder->requestTransaction($ownerData);
|
385 |
-
Mage::getSingleton('core/session')->setData('cielo-transaction', $webServiceOrder);
|
386 |
-
|
387 |
-
if($redirectUrl == false)
|
388 |
-
{
|
389 |
-
// caso nao haja autenticacao, enviar para o tratamento final do pedido
|
390 |
-
if(($this->getConfigData('buypage', $storeId) == "loja"))
|
391 |
-
{
|
392 |
-
return Mage::getUrl('cielo/pay/verify');
|
393 |
-
}
|
394 |
-
// erro nao indentificado
|
395 |
-
else
|
396 |
-
{
|
397 |
-
return Mage::getUrl('cielo/pay/failure');
|
398 |
-
}
|
399 |
-
}
|
400 |
-
else
|
401 |
-
{
|
402 |
-
return $redirectUrl;
|
403 |
-
}
|
404 |
-
}
|
405 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Model_Dc extends Mage_Payment_Model_Method_Abstract
|
28 |
+
{
|
29 |
+
|
30 |
+
protected $_code = 'Maxima_Cielo_Dc';
|
31 |
+
protected $_formBlockType = 'Maxima_Cielo/form_dc';
|
32 |
+
protected $_infoBlockType = 'Maxima_Cielo/info_dc';
|
33 |
+
protected $_canUseInternal = true;
|
34 |
+
protected $_canUseForMultishipping = false;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Assign data to info model instance
|
38 |
+
*
|
39 |
+
* @param mixed $data
|
40 |
+
* @return Mage_Payment_Model_Info
|
41 |
+
*/
|
42 |
+
public function assignData($data)
|
43 |
+
{
|
44 |
+
if (!($data instanceof Varien_Object))
|
45 |
+
{
|
46 |
+
$data = new Varien_Object($data);
|
47 |
+
}
|
48 |
+
|
49 |
+
// salva a bandeira
|
50 |
+
$info = $this->getInfoInstance();
|
51 |
+
|
52 |
+
// converte nomenclatura da bandeira
|
53 |
+
if($data->getCcType() == "visa-electron")
|
54 |
+
{
|
55 |
+
$cardType = "visa";
|
56 |
+
}
|
57 |
+
else
|
58 |
+
{
|
59 |
+
$cardType = $data->getCcType();
|
60 |
+
}
|
61 |
+
|
62 |
+
$info->setCcType($cardType)
|
63 |
+
->setCcNumber(Mage::helper('core')->encrypt($data->getCcNumber()))
|
64 |
+
->setCcOwner($data->getCcOwner())
|
65 |
+
->setCcExpMonth($data->getCcExpMonth())
|
66 |
+
->setCcExpYear($data->getCcExpYear())
|
67 |
+
->setCcCid(Mage::helper('core')->encrypt($data->getCcCid()));
|
68 |
+
|
69 |
+
|
70 |
+
return $this;
|
71 |
+
}
|
72 |
+
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Valida dados
|
76 |
+
*
|
77 |
+
* @param Mage_Payment_Model_Info $info
|
78 |
+
* @return Mage_Payment_Model_Abstract
|
79 |
+
*/
|
80 |
+
public function validate()
|
81 |
+
{
|
82 |
+
/*
|
83 |
+
* chama validacao do metodo abstrato
|
84 |
+
*/
|
85 |
+
parent::validate();
|
86 |
+
|
87 |
+
if($this->getConfigData('buypage', $this->getStoreId()) != "loja")
|
88 |
+
return $this;
|
89 |
+
|
90 |
+
$info = $this->getInfoInstance();
|
91 |
+
$errorMsg = false;
|
92 |
+
|
93 |
+
$availableTypes = Mage::getModel('Maxima_Cielo/dc_types')->getCodes();
|
94 |
+
$ccNumber = Mage::helper('core')->decrypt($info->getCcNumber());
|
95 |
+
|
96 |
+
// remove delimitadores do cartao, como "-" e espaco
|
97 |
+
$ccNumber = preg_replace('/[\-\s]+/', '', $ccNumber);
|
98 |
+
$info->setCcNumber(Mage::helper('core')->encrypt($ccNumber));
|
99 |
+
|
100 |
+
$ccType = '';
|
101 |
+
|
102 |
+
// valida o numero do cartao de credito
|
103 |
+
if(in_array($info->getCcType(), $availableTypes))
|
104 |
+
{
|
105 |
+
if ($this->validateCcNum($ccNumber))
|
106 |
+
{
|
107 |
+
$ccType = 'OT';
|
108 |
+
$ccTypeRegExpList = array
|
109 |
+
(
|
110 |
+
//Solo, Switch or Maestro. International safe
|
111 |
+
/*
|
112 |
+
// Maestro / Solo
|
113 |
+
'SS' => '/^((6759[0-9]{12})|(6334|6767[0-9]{12})|(6334|6767[0-9]{14,15})'
|
114 |
+
. '|(5018|5020|5038|6304|6759|6761|6763[0-9]{12,19})|(49[013][1356][0-9]{12})'
|
115 |
+
. '|(633[34][0-9]{12})|(633110[0-9]{10})|(564182[0-9]{10}))([0-9]{2,3})?$/',
|
116 |
+
*/
|
117 |
+
// Solo only
|
118 |
+
'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
|
119 |
+
'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)'
|
120 |
+
. '|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)'
|
121 |
+
. '|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))'
|
122 |
+
. '|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))'
|
123 |
+
. '|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
|
124 |
+
// Visa
|
125 |
+
'visa' => '/^4[0-9]{12}([0-9]{3})?$/',
|
126 |
+
// Master Card
|
127 |
+
'mastercard' => '/^5[1-5][0-9]{14}$/',
|
128 |
+
// American Express
|
129 |
+
'amex' => '/^3[47][0-9]{13}$/',
|
130 |
+
// Discovery
|
131 |
+
'discover' => '/^6011[0-9]{12}$/',
|
132 |
+
// JCB
|
133 |
+
'JCB' => '/^(3[0-9]{15}|(2131|1800)[0-9]{11})$/',
|
134 |
+
// Diners Club
|
135 |
+
'diners' => '/^3[0,6,8]\d{12}$/'
|
136 |
+
);
|
137 |
+
|
138 |
+
foreach ($ccTypeRegExpList as $ccTypeMatch => $ccTypeRegExp)
|
139 |
+
{
|
140 |
+
if (preg_match($ccTypeRegExp, $ccNumber))
|
141 |
+
{
|
142 |
+
$ccType = $ccTypeMatch;
|
143 |
+
break;
|
144 |
+
}
|
145 |
+
}
|
146 |
+
|
147 |
+
if ($info->getCcType() != 'elo' && ($ccType != $info->getCcType()))
|
148 |
+
{
|
149 |
+
$errorMsg = Mage::helper('Maxima_Cielo')->__('Credit card number mismatch with credit card type.');
|
150 |
+
}
|
151 |
+
}
|
152 |
+
else
|
153 |
+
{
|
154 |
+
$errorMsg = Mage::helper('Maxima_Cielo')->__('Invalid Credit Card Number');
|
155 |
+
}
|
156 |
+
|
157 |
+
}
|
158 |
+
else
|
159 |
+
{
|
160 |
+
$errorMsg = Mage::helper('Maxima_Cielo')->__('Credit card type is not allowed for this payment method.');
|
161 |
+
}
|
162 |
+
|
163 |
+
// valida o numero de verificacao
|
164 |
+
if ($errorMsg === false)
|
165 |
+
{
|
166 |
+
$verificationRegEx = $this->getVerificationRegEx();
|
167 |
+
$regExp = isset($verificationRegEx[$info->getCcType()]) ? $verificationRegEx[$info->getCcType()] : '';
|
168 |
+
|
169 |
+
if ($regExp != '' && (!$info->getCcCid() || !preg_match($regExp, Mage::helper('core')->decrypt($info->getCcCid()))))
|
170 |
+
{
|
171 |
+
$errorMsg = Mage::helper('Maxima_Cielo')->__('Please enter a valid credit card verification number.');
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
if (!$this->_validateExpDate($info->getCcExpYear(), $info->getCcExpMonth()))
|
176 |
+
{
|
177 |
+
$errorMsg = Mage::helper('Maxima_Cielo')->__('Incorrect credit card expiration date.');
|
178 |
+
}
|
179 |
+
|
180 |
+
if($errorMsg)
|
181 |
+
{
|
182 |
+
Mage::throwException($errorMsg);
|
183 |
+
}
|
184 |
+
|
185 |
+
//This must be after all validation conditions
|
186 |
+
//if ($this->getIsCentinelValidationEnabled())
|
187 |
+
//{
|
188 |
+
// $this->getCentinelValidator()->validate($this->getCentinelValidationData());
|
189 |
+
//}
|
190 |
+
|
191 |
+
return $this;
|
192 |
+
}
|
193 |
+
|
194 |
+
|
195 |
+
/**
|
196 |
+
* Validacao retirada do modelo cc da versao 1.7 do Magento
|
197 |
+
*
|
198 |
+
* @param string $cc_number
|
199 |
+
* @return bool
|
200 |
+
*/
|
201 |
+
public function validateCcNum($ccNumber)
|
202 |
+
{
|
203 |
+
$cardNumber = strrev($ccNumber);
|
204 |
+
$numSum = 0;
|
205 |
+
|
206 |
+
for ($i=0; $i<strlen($cardNumber); $i++)
|
207 |
+
{
|
208 |
+
$currentNum = substr($cardNumber, $i, 1);
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Double every second digit
|
212 |
+
*/
|
213 |
+
if ($i % 2 == 1)
|
214 |
+
{
|
215 |
+
$currentNum *= 2;
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Add digits of 2-digit numbers together
|
220 |
+
*/
|
221 |
+
if ($currentNum > 9)
|
222 |
+
{
|
223 |
+
$firstNum = $currentNum % 10;
|
224 |
+
$secondNum = ($currentNum - $firstNum) / 10;
|
225 |
+
$currentNum = $firstNum + $secondNum;
|
226 |
+
}
|
227 |
+
|
228 |
+
$numSum += $currentNum;
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* If the total has no remainder it's OK
|
233 |
+
*/
|
234 |
+
|
235 |
+
return ($numSum % 10 == 0);
|
236 |
+
}
|
237 |
+
|
238 |
+
|
239 |
+
/**
|
240 |
+
* Expressao regular retirada do modelo cc da versao 1.7 do Magento
|
241 |
+
*
|
242 |
+
* @return strig regExp
|
243 |
+
*/
|
244 |
+
|
245 |
+
public function getVerificationRegEx()
|
246 |
+
{
|
247 |
+
$verificationExpList = array
|
248 |
+
(
|
249 |
+
'visa' => '/^[0-9]{3}$/', // Visa
|
250 |
+
'mastercard' => '/^[0-9]{3}$/', // Master Card
|
251 |
+
'amex' => '/^[0-9]{4}$/', // American Express
|
252 |
+
'discover' => '/^[0-9]{3}$/', // Discovery
|
253 |
+
'SS' => '/^[0-9]{3,4}$/',
|
254 |
+
'SM' => '/^[0-9]{3,4}$/', // Switch or Maestro
|
255 |
+
'SO' => '/^[0-9]{3,4}$/', // Solo
|
256 |
+
'OT' => '/^[0-9]{3,4}$/',
|
257 |
+
'JCB' => '/^[0-9]{3,4}$/' //JCB
|
258 |
+
);
|
259 |
+
return $verificationExpList;
|
260 |
+
}
|
261 |
+
|
262 |
+
|
263 |
+
/**
|
264 |
+
* Validacao retirada do modelo cc da versao 1.7 do Magento
|
265 |
+
*
|
266 |
+
* @return strig regExp
|
267 |
+
*/
|
268 |
+
|
269 |
+
protected function _validateExpDate($expYear, $expMonth)
|
270 |
+
{
|
271 |
+
$date = Mage::app()->getLocale()->date();
|
272 |
+
|
273 |
+
if (!$expYear || !$expMonth || ($date->compareYear($expYear) == 1)
|
274 |
+
|| ($date->compareYear($expYear) == 0 && ($date->compareMonth($expMonth) == 1)))
|
275 |
+
{
|
276 |
+
return false;
|
277 |
+
}
|
278 |
+
|
279 |
+
return true;
|
280 |
+
}
|
281 |
+
|
282 |
+
|
283 |
+
|
284 |
+
|
285 |
+
/**
|
286 |
+
* Getter da instancia do pedido
|
287 |
+
*
|
288 |
+
* @return Mage_Sales_Model_Order
|
289 |
+
*/
|
290 |
+
public function getOrder()
|
291 |
+
{
|
292 |
+
if ($this->_order == null) {}
|
293 |
+
|
294 |
+
return $this->_order;
|
295 |
+
}
|
296 |
+
|
297 |
+
/**
|
298 |
+
* Setter da instancia do pedido
|
299 |
+
*
|
300 |
+
* @param Mage_Sales_Model_Order $order
|
301 |
+
*/
|
302 |
+
public function setOrder($order)
|
303 |
+
{
|
304 |
+
if ($order instanceof Mage_Sales_Model_Order)
|
305 |
+
{
|
306 |
+
$this->_order = $order;
|
307 |
+
}
|
308 |
+
elseif (is_numeric($order))
|
309 |
+
{
|
310 |
+
$this->_order = Mage::getModel('sales/order')->load($order);
|
311 |
+
}
|
312 |
+
else
|
313 |
+
{
|
314 |
+
$this->_order = null;
|
315 |
+
}
|
316 |
+
return $this;
|
317 |
+
}
|
318 |
+
|
319 |
+
|
320 |
+
/**
|
321 |
+
* Formata o valor da compra de acordo com a definicao da Cielo
|
322 |
+
*
|
323 |
+
* @param string $originalValue
|
324 |
+
* @return string
|
325 |
+
*/
|
326 |
+
public function getOrderPlaceRedirectUrl()
|
327 |
+
{
|
328 |
+
$info = $this->getInfoInstance();
|
329 |
+
$order = $info->getQuote();
|
330 |
+
$storeId = $this->getStoreId();
|
331 |
+
$payment = $order->getPayment();
|
332 |
+
$additionaldata = unserialize($payment->getData('additional_data'));
|
333 |
+
|
334 |
+
// coleta os dados necessarios
|
335 |
+
$value = Mage::helper('Maxima_Cielo')->formatValueForCielo($order->getGrandTotal());
|
336 |
+
$paymentType = $additionaldata["parcels_number"];
|
337 |
+
$ccType = $payment->getCcType();
|
338 |
+
$paymentParcels = $this->getConfigData('installments_type', $storeId);
|
339 |
+
$cieloNumber = $this->getConfigData('cielo_number', $storeId);
|
340 |
+
$cieloKey = $this->getConfigData('cielo_key', $storeId);
|
341 |
+
$environment = $this->getConfigData('environment', $storeId);
|
342 |
+
$sslFile = $this->getConfigData('ssl_file', $storeId);
|
343 |
+
|
344 |
+
// cria instancia do pedido
|
345 |
+
$webServiceOrder = Mage::getModel('Maxima_Cielo/webServiceOrder', array('enderecoBase' => $environment, 'caminhoCertificado' => $sslFile));
|
346 |
+
|
347 |
+
// preenche dados coletados
|
348 |
+
$webServiceOrderData = array
|
349 |
+
(
|
350 |
+
'ccType' => $ccType,
|
351 |
+
'cieloNumber' => $cieloNumber,
|
352 |
+
'cieloKey' => $cieloKey,
|
353 |
+
'capture' => 'true',
|
354 |
+
'autorize' => '1',
|
355 |
+
'clientOrderNumber' => $payment->getId(),
|
356 |
+
'clientOrderValue' => $value,
|
357 |
+
'postbackURL' => Mage::getUrl('cielo/pay/verify'),
|
358 |
+
'paymentType' => 'A',
|
359 |
+
'paymentParcels' => 1,
|
360 |
+
'clientSoftDesc' => $this->getConfigData('softdescriptor', $storeId)
|
361 |
+
);
|
362 |
+
|
363 |
+
$webServiceOrder->setData($webServiceOrderData);
|
364 |
+
|
365 |
+
// caso seja buy page loja, passa dados do cliente
|
366 |
+
if($this->getConfigData('buypage', $storeId) == "loja")
|
367 |
+
{
|
368 |
+
$ccExpMonth = $info->getCcExpMonth();
|
369 |
+
$ccExpMonth = ($ccExpMonth < 10) ? ("0" . $ccExpMonth) : $ccExpMonth;
|
370 |
+
|
371 |
+
$ownerData = array
|
372 |
+
(
|
373 |
+
'number' => Mage::helper('core')->decrypt($info->getCcNumber()),
|
374 |
+
'exp_date' => $info->getCcExpYear() . $ccExpMonth,
|
375 |
+
'sec_code' => Mage::helper('core')->decrypt($info->getCcCid()),
|
376 |
+
'name' => $info->getCcOwner()
|
377 |
+
);
|
378 |
+
}
|
379 |
+
else
|
380 |
+
{
|
381 |
+
$ownerData = false;
|
382 |
+
}
|
383 |
+
|
384 |
+
$redirectUrl = $webServiceOrder->requestTransaction($ownerData);
|
385 |
+
Mage::getSingleton('core/session')->setData('cielo-transaction', $webServiceOrder);
|
386 |
+
|
387 |
+
if($redirectUrl == false)
|
388 |
+
{
|
389 |
+
// caso nao haja autenticacao, enviar para o tratamento final do pedido
|
390 |
+
if(($this->getConfigData('buypage', $storeId) == "loja"))
|
391 |
+
{
|
392 |
+
return Mage::getUrl('cielo/pay/verify');
|
393 |
+
}
|
394 |
+
// erro nao indentificado
|
395 |
+
else
|
396 |
+
{
|
397 |
+
return Mage::getUrl('cielo/pay/failure');
|
398 |
+
}
|
399 |
+
}
|
400 |
+
else
|
401 |
+
{
|
402 |
+
return $redirectUrl;
|
403 |
+
}
|
404 |
+
}
|
405 |
+
}
|
app/code/community/Maxima/Cielo/Model/Dc/Types.php
CHANGED
@@ -1,73 +1,73 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Model_Dc_Types
|
28 |
-
{
|
29 |
-
|
30 |
-
/**
|
31 |
-
* Formato vetor de vetores
|
32 |
-
*
|
33 |
-
* @return array
|
34 |
-
*/
|
35 |
-
public function toOptionArray()
|
36 |
-
{
|
37 |
-
return array
|
38 |
-
(
|
39 |
-
array
|
40 |
-
(
|
41 |
-
'value' => 'visa-electron',
|
42 |
-
'label' => Mage::helper('adminhtml')->__('Visa Electron (somente Bradesco)'),
|
43 |
-
'image' => 'Visa-Electron.png'
|
44 |
-
)
|
45 |
-
);
|
46 |
-
}
|
47 |
-
|
48 |
-
/**
|
49 |
-
* Formato chave-valor
|
50 |
-
*
|
51 |
-
* @return array
|
52 |
-
*/
|
53 |
-
public function toArray()
|
54 |
-
{
|
55 |
-
return array
|
56 |
-
(
|
57 |
-
'visa' => Mage::helper('adminhtml')->__('Visa Electron')
|
58 |
-
);
|
59 |
-
}
|
60 |
-
|
61 |
-
/**
|
62 |
-
* Formato chave
|
63 |
-
*
|
64 |
-
* @return array
|
65 |
-
*/
|
66 |
-
public function getCodes()
|
67 |
-
{
|
68 |
-
return array
|
69 |
-
(
|
70 |
-
'visa'
|
71 |
-
);
|
72 |
-
}
|
73 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Model_Dc_Types
|
28 |
+
{
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Formato vetor de vetores
|
32 |
+
*
|
33 |
+
* @return array
|
34 |
+
*/
|
35 |
+
public function toOptionArray()
|
36 |
+
{
|
37 |
+
return array
|
38 |
+
(
|
39 |
+
array
|
40 |
+
(
|
41 |
+
'value' => 'visa-electron',
|
42 |
+
'label' => Mage::helper('adminhtml')->__('Visa Electron (somente Bradesco)'),
|
43 |
+
'image' => 'Visa-Electron.png'
|
44 |
+
)
|
45 |
+
);
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Formato chave-valor
|
50 |
+
*
|
51 |
+
* @return array
|
52 |
+
*/
|
53 |
+
public function toArray()
|
54 |
+
{
|
55 |
+
return array
|
56 |
+
(
|
57 |
+
'visa' => Mage::helper('adminhtml')->__('Visa Electron')
|
58 |
+
);
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Formato chave
|
63 |
+
*
|
64 |
+
* @return array
|
65 |
+
*/
|
66 |
+
public function getCodes()
|
67 |
+
{
|
68 |
+
return array
|
69 |
+
(
|
70 |
+
'visa'
|
71 |
+
);
|
72 |
+
}
|
73 |
}
|
app/code/community/Maxima/Cielo/Model/WebServiceOrder.php
CHANGED
@@ -1,547 +1,547 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_Model_WebServiceOrder
|
28 |
-
{
|
29 |
-
public $ccType; // bandeira do cartao de credito
|
30 |
-
public $paymentType; // forma de pagameto (debito, credito - a vista ou parcelado)
|
31 |
-
public $paymentParcels; // numero de parcelas
|
32 |
-
|
33 |
-
public $clientOrderNumber; // clientOrderNumber
|
34 |
-
public $clientOrderValue; // clientOrderValue
|
35 |
-
public $clientOrderCurrency = "986"; // numero de indice da moeda utilizada (R$)
|
36 |
-
public $clientOrderDate; // data da operacao
|
37 |
-
public $clientOrderDescription; // descricao
|
38 |
-
public $clientOrderLocale = "PT"; // idioma
|
39 |
-
public $clientSoftDesc; // identificador que aparece na fatura do cliente
|
40 |
-
|
41 |
-
public $cieloNumber; // identificador da loja na cielo
|
42 |
-
public $cieloKey; // chave da loja a cielo
|
43 |
-
|
44 |
-
public $capture; // flag indicando quando pedido deve ser capturado
|
45 |
-
public $autorize; // flag indicando quando pedido deve ser autorizado
|
46 |
-
public $postbackURL; // url para qual o pagamento retornara o resultado da operacao
|
47 |
-
public $tid; // id da transacao
|
48 |
-
public $status; // status da transacao
|
49 |
-
private $_xmlResponse; // texto xml vindo da resposta da transacao
|
50 |
-
private $_transactionError; // erro ocorrido na transicao
|
51 |
-
|
52 |
-
private $_webServiceURL; // url do webservice da cielo
|
53 |
-
private $_SSLCertificatePath; // caminho no sistema de arquivos do certificado SSL
|
54 |
-
private $_URLAuthTag = "url-autenticacao"; // tag que armazena a url de autenticacao da transacao
|
55 |
-
|
56 |
-
const ENCODING = "ISO-8859-1"; // codificacao do xml
|
57 |
-
const VERSION = "1.2.0"; // versao do webservice da cielo
|
58 |
-
|
59 |
-
|
60 |
-
function __construct($params)
|
61 |
-
{
|
62 |
-
$baseURL = (isset($params['enderecoBase'])) ? $params['enderecoBase'] : "https://qasecommerce.cielo.com.br";
|
63 |
-
$certificatePath = (isset($params['caminhoCertificado']) &&
|
64 |
-
$params['caminhoCertificado'] != "") ? $params['caminhoCertificado'] : Mage::getModuleDir('', 'Maxima_Cielo') . "/ssl/VeriSignClass3PublicPrimaryCertificationAuthority-G5.crt";
|
65 |
-
|
66 |
-
$this->_webServiceURL = $baseURL . "/servicos/ecommwsec.do";
|
67 |
-
$this->_SSLCertificatePath = $certificatePath;
|
68 |
-
}
|
69 |
-
|
70 |
-
|
71 |
-
/**
|
72 |
-
*
|
73 |
-
* funcao utilizada para atribuir os valores base
|
74 |
-
* do pedido da cielo
|
75 |
-
*
|
76 |
-
* @param string $index
|
77 |
-
* @param string $value
|
78 |
-
*
|
79 |
-
* ou
|
80 |
-
*
|
81 |
-
* @param array $index
|
82 |
-
*/
|
83 |
-
|
84 |
-
public function setData($index, $value = null)
|
85 |
-
{
|
86 |
-
if(is_array($index))
|
87 |
-
{
|
88 |
-
foreach($index as $i => $v)
|
89 |
-
{
|
90 |
-
$this->$i = $v;
|
91 |
-
}
|
92 |
-
}
|
93 |
-
else
|
94 |
-
{
|
95 |
-
$this->$index = $value;
|
96 |
-
}
|
97 |
-
}
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
/**
|
102 |
-
*
|
103 |
-
* funcao responsavel por montar o xml de requisicao e
|
104 |
-
* realizar a criacao da transacao na cielo
|
105 |
-
*
|
106 |
-
* @param boolean $ownerIncluded
|
107 |
-
* @return boolean
|
108 |
-
*
|
109 |
-
*/
|
110 |
-
|
111 |
-
public function requestTransaction($ownerData)
|
112 |
-
{
|
113 |
-
$msg = $this->_getXMLHeader() . "\n";
|
114 |
-
|
115 |
-
$msg .= '<requisicao-transacao id="' . md5(date("YmdHisu")) . '" versao="' . self::VERSION . '">' . "\n ";
|
116 |
-
$msg .= $this->_getXMLCieloData() . "\n ";
|
117 |
-
$msg .= $this->_getXMLOwnerData($ownerData) . "\n ";
|
118 |
-
$msg .= $this->_getXMLOrderData() . "\n ";
|
119 |
-
$msg .= $this->_getXMLPaymentData() . "\n ";
|
120 |
-
$msg .= $this->_getXMLPostbackURL() . "\n ";
|
121 |
-
$msg .= $this->_getXMLAutorize() . "\n ";
|
122 |
-
$msg .= $this->_getXMLCapture() . "\n ";
|
123 |
-
$msg .= '</requisicao-transacao>';
|
124 |
-
|
125 |
-
$maxAttempts = 3;
|
126 |
-
|
127 |
-
while($maxAttempts > 0)
|
128 |
-
{
|
129 |
-
if($this->_sendRequest("mensagem=" . $msg, "Transacao"))
|
130 |
-
{
|
131 |
-
if($this->_hasConsultationError())
|
132 |
-
{
|
133 |
-
Mage::log($this->_transactionError);
|
134 |
-
return false;
|
135 |
-
}
|
136 |
-
|
137 |
-
$xml = simplexml_load_string($this->_xmlResponse);
|
138 |
-
|
139 |
-
// pega dados do xml
|
140 |
-
$this->tid = (string) $xml->tid;
|
141 |
-
$URLAuthTag = $this->_URLAuthTag;
|
142 |
-
|
143 |
-
return ((string) $xml->$URLAuthTag);
|
144 |
-
}
|
145 |
-
|
146 |
-
$maxAttempts--;
|
147 |
-
}
|
148 |
-
|
149 |
-
if($maxAttempts == 0)
|
150 |
-
{
|
151 |
-
Mage::log("[CIELO] Não conseguiu consultar o servidor.");
|
152 |
-
}
|
153 |
-
|
154 |
-
return false;
|
155 |
-
}
|
156 |
-
|
157 |
-
|
158 |
-
/**
|
159 |
-
*
|
160 |
-
* funcao responsavel por montar o xml de requisicao e
|
161 |
-
* realizar a consulta do status da transacao
|
162 |
-
*
|
163 |
-
* @return boolean | string
|
164 |
-
*
|
165 |
-
*/
|
166 |
-
|
167 |
-
public function requestConsultation()
|
168 |
-
{
|
169 |
-
$msg = $this->_getXMLHeader() . "\n";
|
170 |
-
$msg .= '<requisicao-consulta id="' . md5(date("YmdHisu")) . '" versao="' . self::VERSION . '">' . "\n ";
|
171 |
-
$msg .= '<tid>' . $this->tid . '</tid>' . "\n ";
|
172 |
-
$msg .= $this->_getXMLCieloData() . "\n ";
|
173 |
-
$msg .= '</requisicao-consulta>';
|
174 |
-
|
175 |
-
$maxAttempts = 3;
|
176 |
-
|
177 |
-
while($maxAttempts > 0)
|
178 |
-
{
|
179 |
-
if($this->_sendRequest("mensagem=" . $msg, "Consulta"))
|
180 |
-
{
|
181 |
-
if($this->_hasConsultationError())
|
182 |
-
{
|
183 |
-
Mage::log($this->_transactionError);
|
184 |
-
return false;
|
185 |
-
}
|
186 |
-
|
187 |
-
$xml = simplexml_load_string($this->_xmlResponse);
|
188 |
-
$this->status = (string) $xml->status;
|
189 |
-
|
190 |
-
return $this->status;
|
191 |
-
}
|
192 |
-
|
193 |
-
$maxAttempts--;
|
194 |
-
}
|
195 |
-
|
196 |
-
if($maxAttempts == 0)
|
197 |
-
{
|
198 |
-
Mage::log("[CIELO] Não conseguiu consultar o servidor.");
|
199 |
-
}
|
200 |
-
|
201 |
-
return false;
|
202 |
-
}
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
/**
|
207 |
-
*
|
208 |
-
* funcao responsavel por montar o xml de requisicao e
|
209 |
-
* realizar a captura da transacao
|
210 |
-
*
|
211 |
-
* @return boolean | string
|
212 |
-
*
|
213 |
-
*/
|
214 |
-
|
215 |
-
public function requestCapture($value)
|
216 |
-
{
|
217 |
-
$msg = $this->_getXMLHeader() . "\n";
|
218 |
-
$msg .= '<requisicao-captura id="' . md5(date("YmdHisu")) . '" versao="' . self::VERSION . '">' . "\n ";
|
219 |
-
$msg .= '<tid>' . $this->tid . '</tid>' . "\n ";
|
220 |
-
$msg .= $this->_getXMLCieloData() . "\n ";
|
221 |
-
$msg .= '<valor>' . $value . '</valor>' . "\n ";
|
222 |
-
$msg .= '</requisicao-captura>';
|
223 |
-
|
224 |
-
$maxAttempts = 3;
|
225 |
-
|
226 |
-
while($maxAttempts > 0)
|
227 |
-
{
|
228 |
-
if($this->_sendRequest("mensagem=" . $msg, "Captura"))
|
229 |
-
{
|
230 |
-
if($this->_hasConsultationError())
|
231 |
-
{
|
232 |
-
Mage::log($this->_transactionError);
|
233 |
-
return false;
|
234 |
-
}
|
235 |
-
|
236 |
-
$xml = simplexml_load_string($this->_xmlResponse);
|
237 |
-
$this->status = (string) $xml->status;
|
238 |
-
|
239 |
-
return $this->status;
|
240 |
-
}
|
241 |
-
|
242 |
-
$maxAttempts--;
|
243 |
-
}
|
244 |
-
|
245 |
-
if($maxAttempts == 0)
|
246 |
-
{
|
247 |
-
Mage::log("[CIELO] Não conseguiu consultar o servidor.");
|
248 |
-
}
|
249 |
-
|
250 |
-
return false;
|
251 |
-
}
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
/**
|
256 |
-
*
|
257 |
-
* funcao responsavel por montar o xml de requisicao e
|
258 |
-
* realizar o cancelamento da transacao
|
259 |
-
*
|
260 |
-
* @return boolean | string
|
261 |
-
*
|
262 |
-
*/
|
263 |
-
|
264 |
-
public function requestCancellation()
|
265 |
-
{
|
266 |
-
$msg = $this->_getXMLHeader() . "\n";
|
267 |
-
$msg .= '<requisicao-cancelamento id="' . md5(date("YmdHisu")) . '" versao="' . self::VERSION . '">' . "\n ";
|
268 |
-
$msg .= '<tid>' . $this->tid . '</tid>' . "\n ";
|
269 |
-
$msg .= $this->_getXMLCieloData() . "\n ";
|
270 |
-
$msg .= '</requisicao-cancelamento>';
|
271 |
-
|
272 |
-
$maxAttempts = 3;
|
273 |
-
|
274 |
-
while($maxAttempts > 0)
|
275 |
-
{
|
276 |
-
if($this->_sendRequest("mensagem=" . $msg, "Cancelamento"))
|
277 |
-
{
|
278 |
-
if($this->_hasConsultationError())
|
279 |
-
{
|
280 |
-
Mage::log($this->_transactionError);
|
281 |
-
return false;
|
282 |
-
}
|
283 |
-
|
284 |
-
$xml = simplexml_load_string($this->_xmlResponse);
|
285 |
-
$this->status = (string) $xml->status;
|
286 |
-
|
287 |
-
return $this->status;
|
288 |
-
}
|
289 |
-
|
290 |
-
$maxAttempts--;
|
291 |
-
}
|
292 |
-
|
293 |
-
if($maxAttempts == 0)
|
294 |
-
{
|
295 |
-
Mage::log("[CIELO] Não conseguiu consultar o servidor.");
|
296 |
-
}
|
297 |
-
|
298 |
-
return false;
|
299 |
-
}
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
/**
|
304 |
-
*
|
305 |
-
* funcao responsavel por conferir se houve erro na requisicao
|
306 |
-
*
|
307 |
-
* @return boolean
|
308 |
-
*
|
309 |
-
*/
|
310 |
-
|
311 |
-
private function _hasConsultationError()
|
312 |
-
{
|
313 |
-
// certificao SSL invalido
|
314 |
-
if(stripos($this->_xmlResponse, "SSL certificate problem") !== false)
|
315 |
-
{
|
316 |
-
$this->_transactionError = "Certificado SSL inválido.";
|
317 |
-
return true;
|
318 |
-
}
|
319 |
-
|
320 |
-
$xml = simplexml_load_string($this->_xmlResponse);
|
321 |
-
|
322 |
-
// tempo de requisicao expirou
|
323 |
-
if($xml == null)
|
324 |
-
{
|
325 |
-
$this->_transactionError = "Tempo de espera na requisição expirou.";
|
326 |
-
return true;
|
327 |
-
}
|
328 |
-
|
329 |
-
// retorno de erro da cielo
|
330 |
-
if($xml->getName() == "erro")
|
331 |
-
{
|
332 |
-
$this->_transactionError = "[CIELO: " . $xml->codigo . "] " . utf8_decode($xml->mensagem);
|
333 |
-
return true;
|
334 |
-
}
|
335 |
-
|
336 |
-
return false;
|
337 |
-
}
|
338 |
-
|
339 |
-
|
340 |
-
/**
|
341 |
-
*
|
342 |
-
* retorna a msg de erro da requisicao
|
343 |
-
*
|
344 |
-
* @return string
|
345 |
-
*
|
346 |
-
*/
|
347 |
-
|
348 |
-
public function getError()
|
349 |
-
{
|
350 |
-
return $this->_transactionError;
|
351 |
-
}
|
352 |
-
|
353 |
-
|
354 |
-
/**
|
355 |
-
*
|
356 |
-
* funcao que realiza a requisicao
|
357 |
-
*
|
358 |
-
* @param string $postMsg
|
359 |
-
* @param string $transacao
|
360 |
-
*
|
361 |
-
* @return string | boolean
|
362 |
-
*
|
363 |
-
*/
|
364 |
-
|
365 |
-
private function _sendRequest($postMsg, $transacao)
|
366 |
-
{
|
367 |
-
$curl_session = curl_init();
|
368 |
-
|
369 |
-
curl_setopt($curl_session, CURLOPT_URL, $this->_webServiceURL);
|
370 |
-
curl_setopt($curl_session, CURLOPT_FAILONERROR, true);
|
371 |
-
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, true);
|
372 |
-
curl_setopt($curl_session, CURLOPT_SSL_VERIFYHOST, 2);
|
373 |
-
curl_setopt($curl_session, CURLOPT_CAINFO, $this->_SSLCertificatePath);
|
374 |
-
curl_setopt($curl_session, CURLOPT_SSLVERSION, 3);
|
375 |
-
curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT, 10);
|
376 |
-
curl_setopt($curl_session, CURLOPT_TIMEOUT, 40);
|
377 |
-
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
|
378 |
-
curl_setopt($curl_session, CURLOPT_POST, true);
|
379 |
-
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $postMsg );
|
380 |
-
|
381 |
-
$this->_xmlResponse = curl_exec($curl_session);
|
382 |
-
|
383 |
-
if(!$this->_xmlResponse)
|
384 |
-
{
|
385 |
-
return false;
|
386 |
-
}
|
387 |
-
|
388 |
-
curl_close($curl_session);
|
389 |
-
|
390 |
-
return true;
|
391 |
-
}
|
392 |
-
|
393 |
-
/**
|
394 |
-
*
|
395 |
-
* funcao que que consulta o retorno xml
|
396 |
-
*
|
397 |
-
* @return string | boolean
|
398 |
-
*
|
399 |
-
*/
|
400 |
-
|
401 |
-
public function getXmlResponse()
|
402 |
-
{
|
403 |
-
try
|
404 |
-
{
|
405 |
-
return simplexml_load_string($this->_xmlResponse);
|
406 |
-
}
|
407 |
-
catch(Exception $e)
|
408 |
-
{
|
409 |
-
return false;
|
410 |
-
}
|
411 |
-
}
|
412 |
-
|
413 |
-
/**
|
414 |
-
*
|
415 |
-
* funcoes que montam o conteudo xml da requisicao
|
416 |
-
*
|
417 |
-
* @return string
|
418 |
-
*
|
419 |
-
*/
|
420 |
-
|
421 |
-
private function _getXMLHeader()
|
422 |
-
{
|
423 |
-
return '<?xml version="1.0" encoding="' . self::ENCODING . '" ?>';
|
424 |
-
}
|
425 |
-
|
426 |
-
private function _getXMLCieloData()
|
427 |
-
{
|
428 |
-
$msg = '<dados-ec>' . "\n " .
|
429 |
-
'<numero>'
|
430 |
-
. $this->cieloNumber .
|
431 |
-
'</numero>' . "\n " .
|
432 |
-
'<chave>'
|
433 |
-
. $this->cieloKey .
|
434 |
-
'</chave>' . "\n " .
|
435 |
-
'</dados-ec>';
|
436 |
-
|
437 |
-
return $msg;
|
438 |
-
}
|
439 |
-
|
440 |
-
private function _getXMLOwnerData($ownerData)
|
441 |
-
{
|
442 |
-
if(!$ownerData)
|
443 |
-
{
|
444 |
-
return "";
|
445 |
-
}
|
446 |
-
|
447 |
-
|
448 |
-
$msg = '<dados-portador>' . "\n " .
|
449 |
-
'<numero>'
|
450 |
-
. $ownerData['number'] .
|
451 |
-
'</numero>' . "\n " .
|
452 |
-
'<validade>'
|
453 |
-
. $ownerData['exp_date'] .
|
454 |
-
'</validade>' . "\n " .
|
455 |
-
'<indicador>'
|
456 |
-
. "1" .
|
457 |
-
'</indicador>' . "\n " .
|
458 |
-
'<codigo-seguranca>'
|
459 |
-
. $ownerData['sec_code'] .
|
460 |
-
'</codigo-seguranca>' . "\n " .
|
461 |
-
'<nome-portador>'
|
462 |
-
. $ownerData['name'] .
|
463 |
-
'</nome-portador>' . "\n " .
|
464 |
-
'</dados-portador>';
|
465 |
-
|
466 |
-
return $msg;
|
467 |
-
}
|
468 |
-
|
469 |
-
private function _getXMLOrderData()
|
470 |
-
{
|
471 |
-
$this->clientOrderDate = date("Y-m-d") . "T" . date("H:i:s");
|
472 |
-
|
473 |
-
$msg = '<dados-pedido>' . "\n " .
|
474 |
-
'<numero>'
|
475 |
-
. $this->clientOrderNumber .
|
476 |
-
'</numero>' . "\n " .
|
477 |
-
'<valor>'
|
478 |
-
. $this->clientOrderValue.
|
479 |
-
'</valor>' . "\n " .
|
480 |
-
'<moeda>'
|
481 |
-
. $this->clientOrderCurrency .
|
482 |
-
'</moeda>' . "\n " .
|
483 |
-
'<data-hora>'
|
484 |
-
. $this->clientOrderDate .
|
485 |
-
'</data-hora>' . "\n ";
|
486 |
-
|
487 |
-
if($this->clientOrderDescription != null && $this->clientOrderDescription != "")
|
488 |
-
{
|
489 |
-
$msg .= '<descricao>'
|
490 |
-
. $this->clientOrderDescription .
|
491 |
-
'</descricao>' . "\n ";
|
492 |
-
}
|
493 |
-
|
494 |
-
$msg .= '<idioma>'
|
495 |
-
. $this->clientOrderLocale .
|
496 |
-
'</idioma>' . "\n ";
|
497 |
-
|
498 |
-
if($this->clientSoftDesc != null && $this->clientSoftDesc != "")
|
499 |
-
{
|
500 |
-
'<softDescriptor>'
|
501 |
-
. $this->clientSoftDesc .
|
502 |
-
'</softDescriptor>' . "\n ";
|
503 |
-
}
|
504 |
-
|
505 |
-
$msg .= '</dados-pedido>';
|
506 |
-
|
507 |
-
return $msg;
|
508 |
-
}
|
509 |
-
|
510 |
-
private function _getXMLPaymentData()
|
511 |
-
{
|
512 |
-
$msg = '<forma-pagamento>' . "\n " .
|
513 |
-
'<bandeira>'
|
514 |
-
. $this->ccType .
|
515 |
-
'</bandeira>' . "\n " .
|
516 |
-
'<produto>'
|
517 |
-
. $this->paymentType .
|
518 |
-
'</produto>' . "\n " .
|
519 |
-
'<parcelas>'
|
520 |
-
. $this->paymentParcels .
|
521 |
-
'</parcelas>' . "\n " .
|
522 |
-
'</forma-pagamento>';
|
523 |
-
|
524 |
-
return $msg;
|
525 |
-
}
|
526 |
-
|
527 |
-
private function _getXMLPostbackURL()
|
528 |
-
{
|
529 |
-
$msg = '<url-retorno>' . $this->postbackURL . '</url-retorno>';
|
530 |
-
|
531 |
-
return $msg;
|
532 |
-
}
|
533 |
-
|
534 |
-
private function _getXMLAutorize()
|
535 |
-
{
|
536 |
-
$msg = '<autorizar>' . $this->autorize . '</autorizar>';
|
537 |
-
|
538 |
-
return $msg;
|
539 |
-
}
|
540 |
-
|
541 |
-
private function _getXMLCapture()
|
542 |
-
{
|
543 |
-
$msg = '<capturar>' . $this->capture . '</capturar>';
|
544 |
-
|
545 |
-
return $msg;
|
546 |
-
}
|
547 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_Model_WebServiceOrder
|
28 |
+
{
|
29 |
+
public $ccType; // bandeira do cartao de credito
|
30 |
+
public $paymentType; // forma de pagameto (debito, credito - a vista ou parcelado)
|
31 |
+
public $paymentParcels; // numero de parcelas
|
32 |
+
|
33 |
+
public $clientOrderNumber; // clientOrderNumber
|
34 |
+
public $clientOrderValue; // clientOrderValue
|
35 |
+
public $clientOrderCurrency = "986"; // numero de indice da moeda utilizada (R$)
|
36 |
+
public $clientOrderDate; // data da operacao
|
37 |
+
public $clientOrderDescription; // descricao
|
38 |
+
public $clientOrderLocale = "PT"; // idioma
|
39 |
+
public $clientSoftDesc; // identificador que aparece na fatura do cliente
|
40 |
+
|
41 |
+
public $cieloNumber; // identificador da loja na cielo
|
42 |
+
public $cieloKey; // chave da loja a cielo
|
43 |
+
|
44 |
+
public $capture; // flag indicando quando pedido deve ser capturado
|
45 |
+
public $autorize; // flag indicando quando pedido deve ser autorizado
|
46 |
+
public $postbackURL; // url para qual o pagamento retornara o resultado da operacao
|
47 |
+
public $tid; // id da transacao
|
48 |
+
public $status; // status da transacao
|
49 |
+
private $_xmlResponse; // texto xml vindo da resposta da transacao
|
50 |
+
private $_transactionError; // erro ocorrido na transicao
|
51 |
+
|
52 |
+
private $_webServiceURL; // url do webservice da cielo
|
53 |
+
private $_SSLCertificatePath; // caminho no sistema de arquivos do certificado SSL
|
54 |
+
private $_URLAuthTag = "url-autenticacao"; // tag que armazena a url de autenticacao da transacao
|
55 |
+
|
56 |
+
const ENCODING = "ISO-8859-1"; // codificacao do xml
|
57 |
+
const VERSION = "1.2.0"; // versao do webservice da cielo
|
58 |
+
|
59 |
+
|
60 |
+
function __construct($params)
|
61 |
+
{
|
62 |
+
$baseURL = (isset($params['enderecoBase'])) ? $params['enderecoBase'] : "https://qasecommerce.cielo.com.br";
|
63 |
+
$certificatePath = (isset($params['caminhoCertificado']) &&
|
64 |
+
$params['caminhoCertificado'] != "") ? $params['caminhoCertificado'] : Mage::getModuleDir('', 'Maxima_Cielo') . "/ssl/VeriSignClass3PublicPrimaryCertificationAuthority-G5.crt";
|
65 |
+
|
66 |
+
$this->_webServiceURL = $baseURL . "/servicos/ecommwsec.do";
|
67 |
+
$this->_SSLCertificatePath = $certificatePath;
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
/**
|
72 |
+
*
|
73 |
+
* funcao utilizada para atribuir os valores base
|
74 |
+
* do pedido da cielo
|
75 |
+
*
|
76 |
+
* @param string $index
|
77 |
+
* @param string $value
|
78 |
+
*
|
79 |
+
* ou
|
80 |
+
*
|
81 |
+
* @param array $index
|
82 |
+
*/
|
83 |
+
|
84 |
+
public function setData($index, $value = null)
|
85 |
+
{
|
86 |
+
if(is_array($index))
|
87 |
+
{
|
88 |
+
foreach($index as $i => $v)
|
89 |
+
{
|
90 |
+
$this->$i = $v;
|
91 |
+
}
|
92 |
+
}
|
93 |
+
else
|
94 |
+
{
|
95 |
+
$this->$index = $value;
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
/**
|
102 |
+
*
|
103 |
+
* funcao responsavel por montar o xml de requisicao e
|
104 |
+
* realizar a criacao da transacao na cielo
|
105 |
+
*
|
106 |
+
* @param boolean $ownerIncluded
|
107 |
+
* @return boolean
|
108 |
+
*
|
109 |
+
*/
|
110 |
+
|
111 |
+
public function requestTransaction($ownerData)
|
112 |
+
{
|
113 |
+
$msg = $this->_getXMLHeader() . "\n";
|
114 |
+
|
115 |
+
$msg .= '<requisicao-transacao id="' . md5(date("YmdHisu")) . '" versao="' . self::VERSION . '">' . "\n ";
|
116 |
+
$msg .= $this->_getXMLCieloData() . "\n ";
|
117 |
+
$msg .= $this->_getXMLOwnerData($ownerData) . "\n ";
|
118 |
+
$msg .= $this->_getXMLOrderData() . "\n ";
|
119 |
+
$msg .= $this->_getXMLPaymentData() . "\n ";
|
120 |
+
$msg .= $this->_getXMLPostbackURL() . "\n ";
|
121 |
+
$msg .= $this->_getXMLAutorize() . "\n ";
|
122 |
+
$msg .= $this->_getXMLCapture() . "\n ";
|
123 |
+
$msg .= '</requisicao-transacao>';
|
124 |
+
|
125 |
+
$maxAttempts = 3;
|
126 |
+
|
127 |
+
while($maxAttempts > 0)
|
128 |
+
{
|
129 |
+
if($this->_sendRequest("mensagem=" . $msg, "Transacao"))
|
130 |
+
{
|
131 |
+
if($this->_hasConsultationError())
|
132 |
+
{
|
133 |
+
Mage::log($this->_transactionError);
|
134 |
+
return false;
|
135 |
+
}
|
136 |
+
|
137 |
+
$xml = simplexml_load_string($this->_xmlResponse);
|
138 |
+
|
139 |
+
// pega dados do xml
|
140 |
+
$this->tid = (string) $xml->tid;
|
141 |
+
$URLAuthTag = $this->_URLAuthTag;
|
142 |
+
|
143 |
+
return ((string) $xml->$URLAuthTag);
|
144 |
+
}
|
145 |
+
|
146 |
+
$maxAttempts--;
|
147 |
+
}
|
148 |
+
|
149 |
+
if($maxAttempts == 0)
|
150 |
+
{
|
151 |
+
Mage::log("[CIELO] Não conseguiu consultar o servidor.");
|
152 |
+
}
|
153 |
+
|
154 |
+
return false;
|
155 |
+
}
|
156 |
+
|
157 |
+
|
158 |
+
/**
|
159 |
+
*
|
160 |
+
* funcao responsavel por montar o xml de requisicao e
|
161 |
+
* realizar a consulta do status da transacao
|
162 |
+
*
|
163 |
+
* @return boolean | string
|
164 |
+
*
|
165 |
+
*/
|
166 |
+
|
167 |
+
public function requestConsultation()
|
168 |
+
{
|
169 |
+
$msg = $this->_getXMLHeader() . "\n";
|
170 |
+
$msg .= '<requisicao-consulta id="' . md5(date("YmdHisu")) . '" versao="' . self::VERSION . '">' . "\n ";
|
171 |
+
$msg .= '<tid>' . $this->tid . '</tid>' . "\n ";
|
172 |
+
$msg .= $this->_getXMLCieloData() . "\n ";
|
173 |
+
$msg .= '</requisicao-consulta>';
|
174 |
+
|
175 |
+
$maxAttempts = 3;
|
176 |
+
|
177 |
+
while($maxAttempts > 0)
|
178 |
+
{
|
179 |
+
if($this->_sendRequest("mensagem=" . $msg, "Consulta"))
|
180 |
+
{
|
181 |
+
if($this->_hasConsultationError())
|
182 |
+
{
|
183 |
+
Mage::log($this->_transactionError);
|
184 |
+
return false;
|
185 |
+
}
|
186 |
+
|
187 |
+
$xml = simplexml_load_string($this->_xmlResponse);
|
188 |
+
$this->status = (string) $xml->status;
|
189 |
+
|
190 |
+
return $this->status;
|
191 |
+
}
|
192 |
+
|
193 |
+
$maxAttempts--;
|
194 |
+
}
|
195 |
+
|
196 |
+
if($maxAttempts == 0)
|
197 |
+
{
|
198 |
+
Mage::log("[CIELO] Não conseguiu consultar o servidor.");
|
199 |
+
}
|
200 |
+
|
201 |
+
return false;
|
202 |
+
}
|
203 |
+
|
204 |
+
|
205 |
+
|
206 |
+
/**
|
207 |
+
*
|
208 |
+
* funcao responsavel por montar o xml de requisicao e
|
209 |
+
* realizar a captura da transacao
|
210 |
+
*
|
211 |
+
* @return boolean | string
|
212 |
+
*
|
213 |
+
*/
|
214 |
+
|
215 |
+
public function requestCapture($value)
|
216 |
+
{
|
217 |
+
$msg = $this->_getXMLHeader() . "\n";
|
218 |
+
$msg .= '<requisicao-captura id="' . md5(date("YmdHisu")) . '" versao="' . self::VERSION . '">' . "\n ";
|
219 |
+
$msg .= '<tid>' . $this->tid . '</tid>' . "\n ";
|
220 |
+
$msg .= $this->_getXMLCieloData() . "\n ";
|
221 |
+
$msg .= '<valor>' . $value . '</valor>' . "\n ";
|
222 |
+
$msg .= '</requisicao-captura>';
|
223 |
+
|
224 |
+
$maxAttempts = 3;
|
225 |
+
|
226 |
+
while($maxAttempts > 0)
|
227 |
+
{
|
228 |
+
if($this->_sendRequest("mensagem=" . $msg, "Captura"))
|
229 |
+
{
|
230 |
+
if($this->_hasConsultationError())
|
231 |
+
{
|
232 |
+
Mage::log($this->_transactionError);
|
233 |
+
return false;
|
234 |
+
}
|
235 |
+
|
236 |
+
$xml = simplexml_load_string($this->_xmlResponse);
|
237 |
+
$this->status = (string) $xml->status;
|
238 |
+
|
239 |
+
return $this->status;
|
240 |
+
}
|
241 |
+
|
242 |
+
$maxAttempts--;
|
243 |
+
}
|
244 |
+
|
245 |
+
if($maxAttempts == 0)
|
246 |
+
{
|
247 |
+
Mage::log("[CIELO] Não conseguiu consultar o servidor.");
|
248 |
+
}
|
249 |
+
|
250 |
+
return false;
|
251 |
+
}
|
252 |
+
|
253 |
+
|
254 |
+
|
255 |
+
/**
|
256 |
+
*
|
257 |
+
* funcao responsavel por montar o xml de requisicao e
|
258 |
+
* realizar o cancelamento da transacao
|
259 |
+
*
|
260 |
+
* @return boolean | string
|
261 |
+
*
|
262 |
+
*/
|
263 |
+
|
264 |
+
public function requestCancellation()
|
265 |
+
{
|
266 |
+
$msg = $this->_getXMLHeader() . "\n";
|
267 |
+
$msg .= '<requisicao-cancelamento id="' . md5(date("YmdHisu")) . '" versao="' . self::VERSION . '">' . "\n ";
|
268 |
+
$msg .= '<tid>' . $this->tid . '</tid>' . "\n ";
|
269 |
+
$msg .= $this->_getXMLCieloData() . "\n ";
|
270 |
+
$msg .= '</requisicao-cancelamento>';
|
271 |
+
|
272 |
+
$maxAttempts = 3;
|
273 |
+
|
274 |
+
while($maxAttempts > 0)
|
275 |
+
{
|
276 |
+
if($this->_sendRequest("mensagem=" . $msg, "Cancelamento"))
|
277 |
+
{
|
278 |
+
if($this->_hasConsultationError())
|
279 |
+
{
|
280 |
+
Mage::log($this->_transactionError);
|
281 |
+
return false;
|
282 |
+
}
|
283 |
+
|
284 |
+
$xml = simplexml_load_string($this->_xmlResponse);
|
285 |
+
$this->status = (string) $xml->status;
|
286 |
+
|
287 |
+
return $this->status;
|
288 |
+
}
|
289 |
+
|
290 |
+
$maxAttempts--;
|
291 |
+
}
|
292 |
+
|
293 |
+
if($maxAttempts == 0)
|
294 |
+
{
|
295 |
+
Mage::log("[CIELO] Não conseguiu consultar o servidor.");
|
296 |
+
}
|
297 |
+
|
298 |
+
return false;
|
299 |
+
}
|
300 |
+
|
301 |
+
|
302 |
+
|
303 |
+
/**
|
304 |
+
*
|
305 |
+
* funcao responsavel por conferir se houve erro na requisicao
|
306 |
+
*
|
307 |
+
* @return boolean
|
308 |
+
*
|
309 |
+
*/
|
310 |
+
|
311 |
+
private function _hasConsultationError()
|
312 |
+
{
|
313 |
+
// certificao SSL invalido
|
314 |
+
if(stripos($this->_xmlResponse, "SSL certificate problem") !== false)
|
315 |
+
{
|
316 |
+
$this->_transactionError = "Certificado SSL inválido.";
|
317 |
+
return true;
|
318 |
+
}
|
319 |
+
|
320 |
+
$xml = simplexml_load_string($this->_xmlResponse);
|
321 |
+
|
322 |
+
// tempo de requisicao expirou
|
323 |
+
if($xml == null)
|
324 |
+
{
|
325 |
+
$this->_transactionError = "Tempo de espera na requisição expirou.";
|
326 |
+
return true;
|
327 |
+
}
|
328 |
+
|
329 |
+
// retorno de erro da cielo
|
330 |
+
if($xml->getName() == "erro")
|
331 |
+
{
|
332 |
+
$this->_transactionError = "[CIELO: " . $xml->codigo . "] " . utf8_decode($xml->mensagem);
|
333 |
+
return true;
|
334 |
+
}
|
335 |
+
|
336 |
+
return false;
|
337 |
+
}
|
338 |
+
|
339 |
+
|
340 |
+
/**
|
341 |
+
*
|
342 |
+
* retorna a msg de erro da requisicao
|
343 |
+
*
|
344 |
+
* @return string
|
345 |
+
*
|
346 |
+
*/
|
347 |
+
|
348 |
+
public function getError()
|
349 |
+
{
|
350 |
+
return $this->_transactionError;
|
351 |
+
}
|
352 |
+
|
353 |
+
|
354 |
+
/**
|
355 |
+
*
|
356 |
+
* funcao que realiza a requisicao
|
357 |
+
*
|
358 |
+
* @param string $postMsg
|
359 |
+
* @param string $transacao
|
360 |
+
*
|
361 |
+
* @return string | boolean
|
362 |
+
*
|
363 |
+
*/
|
364 |
+
|
365 |
+
private function _sendRequest($postMsg, $transacao)
|
366 |
+
{
|
367 |
+
$curl_session = curl_init();
|
368 |
+
|
369 |
+
curl_setopt($curl_session, CURLOPT_URL, $this->_webServiceURL);
|
370 |
+
curl_setopt($curl_session, CURLOPT_FAILONERROR, true);
|
371 |
+
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, true);
|
372 |
+
curl_setopt($curl_session, CURLOPT_SSL_VERIFYHOST, 2);
|
373 |
+
curl_setopt($curl_session, CURLOPT_CAINFO, $this->_SSLCertificatePath);
|
374 |
+
curl_setopt($curl_session, CURLOPT_SSLVERSION, 3);
|
375 |
+
curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT, 10);
|
376 |
+
curl_setopt($curl_session, CURLOPT_TIMEOUT, 40);
|
377 |
+
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
|
378 |
+
curl_setopt($curl_session, CURLOPT_POST, true);
|
379 |
+
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $postMsg );
|
380 |
+
|
381 |
+
$this->_xmlResponse = curl_exec($curl_session);
|
382 |
+
|
383 |
+
if(!$this->_xmlResponse)
|
384 |
+
{
|
385 |
+
return false;
|
386 |
+
}
|
387 |
+
|
388 |
+
curl_close($curl_session);
|
389 |
+
|
390 |
+
return true;
|
391 |
+
}
|
392 |
+
|
393 |
+
/**
|
394 |
+
*
|
395 |
+
* funcao que que consulta o retorno xml
|
396 |
+
*
|
397 |
+
* @return string | boolean
|
398 |
+
*
|
399 |
+
*/
|
400 |
+
|
401 |
+
public function getXmlResponse()
|
402 |
+
{
|
403 |
+
try
|
404 |
+
{
|
405 |
+
return simplexml_load_string($this->_xmlResponse);
|
406 |
+
}
|
407 |
+
catch(Exception $e)
|
408 |
+
{
|
409 |
+
return false;
|
410 |
+
}
|
411 |
+
}
|
412 |
+
|
413 |
+
/**
|
414 |
+
*
|
415 |
+
* funcoes que montam o conteudo xml da requisicao
|
416 |
+
*
|
417 |
+
* @return string
|
418 |
+
*
|
419 |
+
*/
|
420 |
+
|
421 |
+
private function _getXMLHeader()
|
422 |
+
{
|
423 |
+
return '<?xml version="1.0" encoding="' . self::ENCODING . '" ?>';
|
424 |
+
}
|
425 |
+
|
426 |
+
private function _getXMLCieloData()
|
427 |
+
{
|
428 |
+
$msg = '<dados-ec>' . "\n " .
|
429 |
+
'<numero>'
|
430 |
+
. $this->cieloNumber .
|
431 |
+
'</numero>' . "\n " .
|
432 |
+
'<chave>'
|
433 |
+
. $this->cieloKey .
|
434 |
+
'</chave>' . "\n " .
|
435 |
+
'</dados-ec>';
|
436 |
+
|
437 |
+
return $msg;
|
438 |
+
}
|
439 |
+
|
440 |
+
private function _getXMLOwnerData($ownerData)
|
441 |
+
{
|
442 |
+
if(!$ownerData)
|
443 |
+
{
|
444 |
+
return "";
|
445 |
+
}
|
446 |
+
|
447 |
+
|
448 |
+
$msg = '<dados-portador>' . "\n " .
|
449 |
+
'<numero>'
|
450 |
+
. $ownerData['number'] .
|
451 |
+
'</numero>' . "\n " .
|
452 |
+
'<validade>'
|
453 |
+
. $ownerData['exp_date'] .
|
454 |
+
'</validade>' . "\n " .
|
455 |
+
'<indicador>'
|
456 |
+
. "1" .
|
457 |
+
'</indicador>' . "\n " .
|
458 |
+
'<codigo-seguranca>'
|
459 |
+
. $ownerData['sec_code'] .
|
460 |
+
'</codigo-seguranca>' . "\n " .
|
461 |
+
'<nome-portador>'
|
462 |
+
. $ownerData['name'] .
|
463 |
+
'</nome-portador>' . "\n " .
|
464 |
+
'</dados-portador>';
|
465 |
+
|
466 |
+
return $msg;
|
467 |
+
}
|
468 |
+
|
469 |
+
private function _getXMLOrderData()
|
470 |
+
{
|
471 |
+
$this->clientOrderDate = date("Y-m-d") . "T" . date("H:i:s");
|
472 |
+
|
473 |
+
$msg = '<dados-pedido>' . "\n " .
|
474 |
+
'<numero>'
|
475 |
+
. $this->clientOrderNumber .
|
476 |
+
'</numero>' . "\n " .
|
477 |
+
'<valor>'
|
478 |
+
. $this->clientOrderValue.
|
479 |
+
'</valor>' . "\n " .
|
480 |
+
'<moeda>'
|
481 |
+
. $this->clientOrderCurrency .
|
482 |
+
'</moeda>' . "\n " .
|
483 |
+
'<data-hora>'
|
484 |
+
. $this->clientOrderDate .
|
485 |
+
'</data-hora>' . "\n ";
|
486 |
+
|
487 |
+
if($this->clientOrderDescription != null && $this->clientOrderDescription != "")
|
488 |
+
{
|
489 |
+
$msg .= '<descricao>'
|
490 |
+
. $this->clientOrderDescription .
|
491 |
+
'</descricao>' . "\n ";
|
492 |
+
}
|
493 |
+
|
494 |
+
$msg .= '<idioma>'
|
495 |
+
. $this->clientOrderLocale .
|
496 |
+
'</idioma>' . "\n ";
|
497 |
+
|
498 |
+
if($this->clientSoftDesc != null && $this->clientSoftDesc != "")
|
499 |
+
{
|
500 |
+
'<softDescriptor>'
|
501 |
+
. $this->clientSoftDesc .
|
502 |
+
'</softDescriptor>' . "\n ";
|
503 |
+
}
|
504 |
+
|
505 |
+
$msg .= '</dados-pedido>';
|
506 |
+
|
507 |
+
return $msg;
|
508 |
+
}
|
509 |
+
|
510 |
+
private function _getXMLPaymentData()
|
511 |
+
{
|
512 |
+
$msg = '<forma-pagamento>' . "\n " .
|
513 |
+
'<bandeira>'
|
514 |
+
. $this->ccType .
|
515 |
+
'</bandeira>' . "\n " .
|
516 |
+
'<produto>'
|
517 |
+
. $this->paymentType .
|
518 |
+
'</produto>' . "\n " .
|
519 |
+
'<parcelas>'
|
520 |
+
. $this->paymentParcels .
|
521 |
+
'</parcelas>' . "\n " .
|
522 |
+
'</forma-pagamento>';
|
523 |
+
|
524 |
+
return $msg;
|
525 |
+
}
|
526 |
+
|
527 |
+
private function _getXMLPostbackURL()
|
528 |
+
{
|
529 |
+
$msg = '<url-retorno>' . $this->postbackURL . '</url-retorno>';
|
530 |
+
|
531 |
+
return $msg;
|
532 |
+
}
|
533 |
+
|
534 |
+
private function _getXMLAutorize()
|
535 |
+
{
|
536 |
+
$msg = '<autorizar>' . $this->autorize . '</autorizar>';
|
537 |
+
|
538 |
+
return $msg;
|
539 |
+
}
|
540 |
+
|
541 |
+
private function _getXMLCapture()
|
542 |
+
{
|
543 |
+
$msg = '<capturar>' . $this->capture . '</capturar>';
|
544 |
+
|
545 |
+
return $msg;
|
546 |
+
}
|
547 |
+
}
|
app/code/community/Maxima/Cielo/controllers/AdminController.php
CHANGED
@@ -91,6 +91,7 @@ class Maxima_Cielo_AdminController extends Mage_Adminhtml_Controller_Action
|
|
91 |
$value = Mage::helper('Maxima_Cielo')->formatValueForCielo($order->getGrandTotal());
|
92 |
|
93 |
// pega os dados para requisicao e realiza a consulta
|
|
|
94 |
$cieloNumber = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/cielo_number');
|
95 |
$cieloKey = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/cielo_key');
|
96 |
$environment = Mage::getStoreConfig('payment/' . $methodCode . '/environment');
|
@@ -157,8 +158,12 @@ class Maxima_Cielo_AdminController extends Mage_Adminhtml_Controller_Action
|
|
157 |
return;
|
158 |
}
|
159 |
|
|
|
|
|
|
|
160 |
|
161 |
// pega os dados para requisicao e realiza a consulta
|
|
|
162 |
$cieloNumber = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/cielo_number');
|
163 |
$cieloKey = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/cielo_key');
|
164 |
$environment = Mage::getStoreConfig('payment/' . $methodCode . '/environment');
|
@@ -173,7 +178,26 @@ class Maxima_Cielo_AdminController extends Mage_Adminhtml_Controller_Action
|
|
173 |
// requisita cancelamento
|
174 |
$model->requestCancellation();
|
175 |
$xml = $model->getXmlResponse();
|
|
|
176 |
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
}
|
179 |
}
|
91 |
$value = Mage::helper('Maxima_Cielo')->formatValueForCielo($order->getGrandTotal());
|
92 |
|
93 |
// pega os dados para requisicao e realiza a consulta
|
94 |
+
$methodCode = $order->getPayment()->getMethodInstance()->getCode();
|
95 |
$cieloNumber = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/cielo_number');
|
96 |
$cieloKey = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/cielo_key');
|
97 |
$environment = Mage::getStoreConfig('payment/' . $methodCode . '/environment');
|
158 |
return;
|
159 |
}
|
160 |
|
161 |
+
// pega pedido correspondente
|
162 |
+
$orderId = $this->getRequest()->getParam('order');
|
163 |
+
$order = Mage::getModel('sales/order')->load($orderId);
|
164 |
|
165 |
// pega os dados para requisicao e realiza a consulta
|
166 |
+
$methodCode = $order->getPayment()->getMethodInstance()->getCode();
|
167 |
$cieloNumber = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/cielo_number');
|
168 |
$cieloKey = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/cielo_key');
|
169 |
$environment = Mage::getStoreConfig('payment/' . $methodCode . '/environment');
|
178 |
// requisita cancelamento
|
179 |
$model->requestCancellation();
|
180 |
$xml = $model->getXmlResponse();
|
181 |
+
$status = (string) $xml->status;
|
182 |
|
183 |
+
// tudo ok, transacao cancelada
|
184 |
+
if($status == 9)
|
185 |
+
{
|
186 |
+
$html = "<b>Pedido cancelado com sucesso!</b>
|
187 |
+
<button type=\"button\" title=\"Atualizar Informações\" onclick=\"document.location.reload(true)\">
|
188 |
+
<span>Recarregar Página</span>
|
189 |
+
</button><br /><br />";
|
190 |
+
|
191 |
+
// atualiza os dados da compra
|
192 |
+
$payment = $order->getPayment();
|
193 |
+
$payment->setAdditionalInformation('Cielo_status', $status);
|
194 |
+
$payment->save();
|
195 |
+
}
|
196 |
+
else
|
197 |
+
{
|
198 |
+
$html = "";
|
199 |
+
}
|
200 |
+
|
201 |
+
$this->getResponse()->setBody($html . Mage::helper('Maxima_Cielo')->xmlToHtml($xml));
|
202 |
}
|
203 |
}
|
app/code/community/Maxima/Cielo/controllers/PayController.php
CHANGED
@@ -1,172 +1,172 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
class Maxima_Cielo_PayController extends Mage_Core_Controller_Front_Action
|
28 |
-
{
|
29 |
-
/**
|
30 |
-
*
|
31 |
-
* Funcao responsavel por tratar o retorno da pagina de pagamento da Cielo.
|
32 |
-
* Confere a informacao retornada, limpa o objeto de requisicao da sessao e
|
33 |
-
* exibe mensagem com o resultado da acao.
|
34 |
-
*
|
35 |
-
*/
|
36 |
-
|
37 |
-
public function verifyAction()
|
38 |
-
{
|
39 |
-
if(!Mage::getSingleton('core/session')->getData('cielo-transaction'))
|
40 |
-
{
|
41 |
-
$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
42 |
-
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
|
43 |
-
return;
|
44 |
-
}
|
45 |
-
|
46 |
-
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
|
47 |
-
$order = Mage::getModel('sales/order')->load($orderId);
|
48 |
-
$payment = $order->getPayment();
|
49 |
-
|
50 |
-
// pega o pedido armazenado
|
51 |
-
$webServiceOrder = Mage::getSingleton('core/session')->getData('cielo-transaction');
|
52 |
-
Mage::getSingleton('core/session')->unsetData('cielo-transaction');
|
53 |
-
$autoCapture = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/auto_capture');
|
54 |
-
|
55 |
-
$this->loadLayout();
|
56 |
-
$block = $this->getLayout()->getBlock('Maxima_Cielo.success');
|
57 |
-
|
58 |
-
// realiza consulta ao status do pagamento
|
59 |
-
$status = $webServiceOrder->requestConsultation();
|
60 |
-
$xml = $webServiceOrder->getXmlResponse();
|
61 |
-
$eci = (isset($xml->autenticacao->eci)) ? ((string) $xml->autenticacao->eci) : "";
|
62 |
-
|
63 |
-
$block->setCieloStatus($status);
|
64 |
-
$block->setCieloTid($webServiceOrder->tid);
|
65 |
-
$payment->setAdditionalInformation('Cielo_tid', $webServiceOrder->tid);
|
66 |
-
$payment->setAdditionalInformation('Cielo_status', $status);
|
67 |
-
$payment->setAdditionalInformation('Cielo_cardType', $webServiceOrder->ccType);
|
68 |
-
$payment->setAdditionalInformation('Cielo_installments', $webServiceOrder->paymentParcels);
|
69 |
-
$payment->setAdditionalInformation('Cielo_eci', $eci);
|
70 |
-
$payment->save();
|
71 |
-
|
72 |
-
// possiveis status
|
73 |
-
// -1 nao foi possivel consultar
|
74 |
-
// 0 criada
|
75 |
-
// 1 em andamento
|
76 |
-
// 2 autenticada
|
77 |
-
// 3 nao autenticada
|
78 |
-
// 4 autorizada ou pendente de captura
|
79 |
-
// 5 nao autorizada
|
80 |
-
// 6 capturada
|
81 |
-
// 8 nao capturada
|
82 |
-
// 9 cancelada
|
83 |
-
// 10 em autenticacao
|
84 |
-
|
85 |
-
// tudo ok, transacao aprovada, salva no banco
|
86 |
-
if($block->getCieloStatus() == 6)
|
87 |
-
{
|
88 |
-
// se jah foi capturado e nao era pra ter sido, tem algo de errado
|
89 |
-
if(!$autoCapture && $payment->getMethodInstance()->getCode() == "Maxima_Cielo_Cc")
|
90 |
-
{
|
91 |
-
Mage::log("[Cielo] Pedido foi capturado, enquanto o flag indicava que nao deveria ter sido.");
|
92 |
-
}
|
93 |
-
else
|
94 |
-
{
|
95 |
-
if($order->canInvoice() && !$order->hasInvoices())
|
96 |
-
{
|
97 |
-
$invoiceId = Mage::getModel('sales/order_invoice_api')->create($order->getIncrementId(), array());
|
98 |
-
$invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceId);
|
99 |
-
|
100 |
-
// envia email de confirmacao de fatura
|
101 |
-
$invoice->sendEmail(true);
|
102 |
-
$invoice->setEmailSent(true);
|
103 |
-
$invoice->save();
|
104 |
-
}
|
105 |
-
}
|
106 |
-
}
|
107 |
-
// ainda em processo de autenticacao, nao faz nada... aguardar
|
108 |
-
else if($block->getCieloStatus() == 10)
|
109 |
-
{
|
110 |
-
|
111 |
-
}
|
112 |
-
// por algum motivo deu errado, deve tentar denovo
|
113 |
-
else
|
114 |
-
{
|
115 |
-
|
116 |
-
}
|
117 |
-
|
118 |
-
// envia email de nova compra
|
119 |
-
$order->sendNewOrderEmail();
|
120 |
-
$order->setEmailSent(true);
|
121 |
-
$order->save();
|
122 |
-
|
123 |
-
// limpa juros, caso nao tenha sido zerado
|
124 |
-
$quote = Mage::getSingleton('checkout/session')->getQuote();
|
125 |
-
|
126 |
-
if($quote)
|
127 |
-
{
|
128 |
-
$quote->setInterest(0.0);
|
129 |
-
$quote->setBaseInterest(0.0);
|
130 |
-
|
131 |
-
$quote->setTotalsCollectedFlag(false)->collectTotals();
|
132 |
-
$quote->save();
|
133 |
-
}
|
134 |
-
|
135 |
-
$this->renderLayout();
|
136 |
-
}
|
137 |
-
|
138 |
-
/**
|
139 |
-
*
|
140 |
-
* Funcao responsavel por tratar o caso de erro na comunicacao com o servidor da
|
141 |
-
* Cielo. Limpa objeto da sessao e mostra mensagem de erro.
|
142 |
-
*
|
143 |
-
*/
|
144 |
-
|
145 |
-
public function failureAction()
|
146 |
-
{
|
147 |
-
if(!Mage::getSingleton('core/session')->getData('cielo-transaction'))
|
148 |
-
{
|
149 |
-
$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
150 |
-
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
|
151 |
-
return;
|
152 |
-
}
|
153 |
-
|
154 |
-
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
|
155 |
-
$order = Mage::getModel('sales/order')->load($orderId);
|
156 |
-
$payment = $order->getPayment();
|
157 |
-
|
158 |
-
// pega o pedido armazenado
|
159 |
-
$webServiceOrder = Mage::getSingleton('core/session')->getData('cielo-transaction');
|
160 |
-
Mage::getSingleton('core/session')->unsetData('cielo-transaction');
|
161 |
-
|
162 |
-
$this->loadLayout();
|
163 |
-
$block = $this->getLayout()->getBlock('Maxima_Cielo.failure');
|
164 |
-
|
165 |
-
// preenche erro
|
166 |
-
$payment->setAdditionalInformation('Cielo_error', true);
|
167 |
-
$payment->setAdditionalInformation('Cielo_error_msg', $webServiceOrder->getError());
|
168 |
-
$payment->save();
|
169 |
-
|
170 |
-
$this->renderLayout();
|
171 |
-
}
|
172 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Maxima_Cielo_PayController extends Mage_Core_Controller_Front_Action
|
28 |
+
{
|
29 |
+
/**
|
30 |
+
*
|
31 |
+
* Funcao responsavel por tratar o retorno da pagina de pagamento da Cielo.
|
32 |
+
* Confere a informacao retornada, limpa o objeto de requisicao da sessao e
|
33 |
+
* exibe mensagem com o resultado da acao.
|
34 |
+
*
|
35 |
+
*/
|
36 |
+
|
37 |
+
public function verifyAction()
|
38 |
+
{
|
39 |
+
if(!Mage::getSingleton('core/session')->getData('cielo-transaction'))
|
40 |
+
{
|
41 |
+
$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
42 |
+
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
|
43 |
+
return;
|
44 |
+
}
|
45 |
+
|
46 |
+
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
|
47 |
+
$order = Mage::getModel('sales/order')->load($orderId);
|
48 |
+
$payment = $order->getPayment();
|
49 |
+
|
50 |
+
// pega o pedido armazenado
|
51 |
+
$webServiceOrder = Mage::getSingleton('core/session')->getData('cielo-transaction');
|
52 |
+
Mage::getSingleton('core/session')->unsetData('cielo-transaction');
|
53 |
+
$autoCapture = Mage::getStoreConfig('payment/Maxima_Cielo_Cc/auto_capture');
|
54 |
+
|
55 |
+
$this->loadLayout();
|
56 |
+
$block = $this->getLayout()->getBlock('Maxima_Cielo.success');
|
57 |
+
|
58 |
+
// realiza consulta ao status do pagamento
|
59 |
+
$status = $webServiceOrder->requestConsultation();
|
60 |
+
$xml = $webServiceOrder->getXmlResponse();
|
61 |
+
$eci = (isset($xml->autenticacao->eci)) ? ((string) $xml->autenticacao->eci) : "";
|
62 |
+
|
63 |
+
$block->setCieloStatus($status);
|
64 |
+
$block->setCieloTid($webServiceOrder->tid);
|
65 |
+
$payment->setAdditionalInformation('Cielo_tid', $webServiceOrder->tid);
|
66 |
+
$payment->setAdditionalInformation('Cielo_status', $status);
|
67 |
+
$payment->setAdditionalInformation('Cielo_cardType', $webServiceOrder->ccType);
|
68 |
+
$payment->setAdditionalInformation('Cielo_installments', $webServiceOrder->paymentParcels);
|
69 |
+
$payment->setAdditionalInformation('Cielo_eci', $eci);
|
70 |
+
$payment->save();
|
71 |
+
|
72 |
+
// possiveis status
|
73 |
+
// -1 nao foi possivel consultar
|
74 |
+
// 0 criada
|
75 |
+
// 1 em andamento
|
76 |
+
// 2 autenticada
|
77 |
+
// 3 nao autenticada
|
78 |
+
// 4 autorizada ou pendente de captura
|
79 |
+
// 5 nao autorizada
|
80 |
+
// 6 capturada
|
81 |
+
// 8 nao capturada
|
82 |
+
// 9 cancelada
|
83 |
+
// 10 em autenticacao
|
84 |
+
|
85 |
+
// tudo ok, transacao aprovada, salva no banco
|
86 |
+
if($block->getCieloStatus() == 6)
|
87 |
+
{
|
88 |
+
// se jah foi capturado e nao era pra ter sido, tem algo de errado
|
89 |
+
if(!$autoCapture && $payment->getMethodInstance()->getCode() == "Maxima_Cielo_Cc")
|
90 |
+
{
|
91 |
+
Mage::log("[Cielo] Pedido foi capturado, enquanto o flag indicava que nao deveria ter sido.");
|
92 |
+
}
|
93 |
+
else
|
94 |
+
{
|
95 |
+
if($order->canInvoice() && !$order->hasInvoices())
|
96 |
+
{
|
97 |
+
$invoiceId = Mage::getModel('sales/order_invoice_api')->create($order->getIncrementId(), array());
|
98 |
+
$invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceId);
|
99 |
+
|
100 |
+
// envia email de confirmacao de fatura
|
101 |
+
$invoice->sendEmail(true);
|
102 |
+
$invoice->setEmailSent(true);
|
103 |
+
$invoice->save();
|
104 |
+
}
|
105 |
+
}
|
106 |
+
}
|
107 |
+
// ainda em processo de autenticacao, nao faz nada... aguardar
|
108 |
+
else if($block->getCieloStatus() == 10)
|
109 |
+
{
|
110 |
+
|
111 |
+
}
|
112 |
+
// por algum motivo deu errado, deve tentar denovo
|
113 |
+
else
|
114 |
+
{
|
115 |
+
|
116 |
+
}
|
117 |
+
|
118 |
+
// envia email de nova compra
|
119 |
+
$order->sendNewOrderEmail();
|
120 |
+
$order->setEmailSent(true);
|
121 |
+
$order->save();
|
122 |
+
|
123 |
+
// limpa juros, caso nao tenha sido zerado
|
124 |
+
$quote = Mage::getSingleton('checkout/session')->getQuote();
|
125 |
+
|
126 |
+
if($quote)
|
127 |
+
{
|
128 |
+
$quote->setInterest(0.0);
|
129 |
+
$quote->setBaseInterest(0.0);
|
130 |
+
|
131 |
+
$quote->setTotalsCollectedFlag(false)->collectTotals();
|
132 |
+
$quote->save();
|
133 |
+
}
|
134 |
+
|
135 |
+
$this->renderLayout();
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
*
|
140 |
+
* Funcao responsavel por tratar o caso de erro na comunicacao com o servidor da
|
141 |
+
* Cielo. Limpa objeto da sessao e mostra mensagem de erro.
|
142 |
+
*
|
143 |
+
*/
|
144 |
+
|
145 |
+
public function failureAction()
|
146 |
+
{
|
147 |
+
if(!Mage::getSingleton('core/session')->getData('cielo-transaction'))
|
148 |
+
{
|
149 |
+
$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
150 |
+
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
|
151 |
+
return;
|
152 |
+
}
|
153 |
+
|
154 |
+
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
|
155 |
+
$order = Mage::getModel('sales/order')->load($orderId);
|
156 |
+
$payment = $order->getPayment();
|
157 |
+
|
158 |
+
// pega o pedido armazenado
|
159 |
+
$webServiceOrder = Mage::getSingleton('core/session')->getData('cielo-transaction');
|
160 |
+
Mage::getSingleton('core/session')->unsetData('cielo-transaction');
|
161 |
+
|
162 |
+
$this->loadLayout();
|
163 |
+
$block = $this->getLayout()->getBlock('Maxima_Cielo.failure');
|
164 |
+
|
165 |
+
// preenche erro
|
166 |
+
$payment->setAdditionalInformation('Cielo_error', true);
|
167 |
+
$payment->setAdditionalInformation('Cielo_error_msg', $webServiceOrder->getError());
|
168 |
+
$payment->save();
|
169 |
+
|
170 |
+
$this->renderLayout();
|
171 |
+
}
|
172 |
}
|
app/code/community/Maxima/Cielo/etc/config.xml
CHANGED
@@ -28,7 +28,7 @@
|
|
28 |
|
29 |
<modules>
|
30 |
<Maxima_Cielo>
|
31 |
-
<version>1.5.
|
32 |
</Maxima_Cielo>
|
33 |
</modules>
|
34 |
|
28 |
|
29 |
<modules>
|
30 |
<Maxima_Cielo>
|
31 |
+
<version>1.5.1</version>
|
32 |
</Maxima_Cielo>
|
33 |
</modules>
|
34 |
|
app/code/community/Maxima/Cielo/etc/system.xml
CHANGED
@@ -39,7 +39,7 @@
|
|
39 |
<comment>
|
40 |
<![CDATA[
|
41 |
<div>
|
42 |
-
Versão: 1.5.
|
43 |
Este módulo foi desenvolvido por Fillipe Almeida Dutra<br />
|
44 |
Contato: lawsann@gmail.com
|
45 |
<br /><br /><hr />
|
@@ -230,7 +230,7 @@
|
|
230 |
<comment>
|
231 |
<![CDATA[
|
232 |
<div>
|
233 |
-
Versão: 1.5.
|
234 |
Este módulo foi desenvolvido por Fillipe Almeida Dutra<br />
|
235 |
Contato: lawsann@gmail.com
|
236 |
<br /><br /><hr />
|
39 |
<comment>
|
40 |
<![CDATA[
|
41 |
<div>
|
42 |
+
Versão: 1.5.1<br />
|
43 |
Este módulo foi desenvolvido por Fillipe Almeida Dutra<br />
|
44 |
Contato: lawsann@gmail.com
|
45 |
<br /><br /><hr />
|
230 |
<comment>
|
231 |
<![CDATA[
|
232 |
<div>
|
233 |
+
Versão: 1.5.1<br />
|
234 |
Este módulo foi desenvolvido por Fillipe Almeida Dutra<br />
|
235 |
Contato: lawsann@gmail.com
|
236 |
<br /><br /><hr />
|
app/design/adminhtml/default/default/template/cielo/info/cc.phtml
CHANGED
@@ -1,346 +1,346 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
?>
|
28 |
-
Cartão de Crédito Cielo
|
29 |
-
<br /><br />
|
30 |
-
<?php
|
31 |
-
|
32 |
-
|
33 |
-
if($_info = $this->getInfo())
|
34 |
-
{
|
35 |
-
if($_info->getOrder())
|
36 |
-
{
|
37 |
-
$payment = $_info->getOrder()->getPayment();
|
38 |
-
|
39 |
-
if($payment->getAdditionalInformation ('Cielo_error'))
|
40 |
-
{
|
41 |
-
echo "Erro na transação: " . $payment->getAdditionalInformation ('Cielo_error');
|
42 |
-
}
|
43 |
-
else
|
44 |
-
{
|
45 |
-
$tid = $payment->getAdditionalInformation ('Cielo_tid');
|
46 |
-
$status = $payment->getAdditionalInformation ('Cielo_status');
|
47 |
-
$cardType = $payment->getAdditionalInformation ('Cielo_cardType');
|
48 |
-
$installments = $payment->getAdditionalInformation ('Cielo_installments');
|
49 |
-
|
50 |
-
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toArray();
|
51 |
-
$cardType = $allCards[$cardType];
|
52 |
-
$installments = ($installments == 1) ? 'À vista' : $installments . " vezes";
|
53 |
-
|
54 |
-
$html = "<b>ID Transação</b>: " . $tid . "<br />";
|
55 |
-
$html .= "<b>Status</b>: " . Mage::helper('Maxima_Cielo')->getStatusMessage($status) . "<br />";
|
56 |
-
$html .= "<b>Bandeira</b>: " . $cardType . "<br />";
|
57 |
-
$html .= "<b>Parcelamento</b>: " . $installments . "<br /><br />";
|
58 |
-
|
59 |
-
echo $html;
|
60 |
-
}
|
61 |
-
}
|
62 |
-
}
|
63 |
-
?>
|
64 |
-
|
65 |
-
<script type="text/javascript">// <![CDATA[
|
66 |
-
|
67 |
-
|
68 |
-
function captureCieloOrder(tid, orderId)
|
69 |
-
{
|
70 |
-
var url = '<?php echo $this->getUrl('cielo/admin/capture') ?>';
|
71 |
-
|
72 |
-
new Ajax.Request(url,
|
73 |
-
{
|
74 |
-
method : 'post',
|
75 |
-
parameters : "tid=" + tid + "&order=" + orderId,
|
76 |
-
onComplete : function(transport)
|
77 |
-
{
|
78 |
-
maximaModalWindow("Captura de Dados", transport.responseText, 600, 400);
|
79 |
-
}
|
80 |
-
});
|
81 |
-
}
|
82 |
-
|
83 |
-
|
84 |
-
function loadCieloWebServiceData(tid, orderId)
|
85 |
-
{
|
86 |
-
var url = '<?php echo $this->getUrl('cielo/admin/consult') ?>';
|
87 |
-
|
88 |
-
new Ajax.Request(url,
|
89 |
-
{
|
90 |
-
method : 'post',
|
91 |
-
parameters : "tid=" + tid + "&order=" + orderId,
|
92 |
-
onComplete : function(transport)
|
93 |
-
{
|
94 |
-
maximaModalWindow("Dados Cielo", transport.responseText, 600, 400);
|
95 |
-
}
|
96 |
-
});
|
97 |
-
}
|
98 |
-
|
99 |
-
|
100 |
-
function cancelCieloOrder(tid, orderId)
|
101 |
-
{
|
102 |
-
var cancellation = confirm("<?php echo $this->__("Do You really want to cancel this transaction on Cielo?"); ?>");
|
103 |
-
|
104 |
-
if(cancellation)
|
105 |
-
{
|
106 |
-
var url = '<?php echo $this->getUrl('cielo/admin/cancel') ?>';
|
107 |
-
|
108 |
-
new Ajax.Request(url,
|
109 |
-
{
|
110 |
-
method : 'post',
|
111 |
-
parameters : "tid=" + tid + "&order=" + orderId,
|
112 |
-
onComplete : function(transport)
|
113 |
-
{
|
114 |
-
maximaModalWindow("Cancelamento na Cielo", transport.responseText, 600, 400);
|
115 |
-
}
|
116 |
-
});
|
117 |
-
}
|
118 |
-
}
|
119 |
-
|
120 |
-
|
121 |
-
function maximaModalWindow(title, content, width, height)
|
122 |
-
{
|
123 |
-
$$('HTML')[0].setStyle({overflow: 'hidden'});
|
124 |
-
|
125 |
-
var viewport = document.viewport;
|
126 |
-
|
127 |
-
var windowWidth = (width) ? width : 300;
|
128 |
-
var windowHeight = (height) ? height : 200;
|
129 |
-
|
130 |
-
var styleWidth = width + 'px';
|
131 |
-
var styleHeight = height + 'px';
|
132 |
-
var styleTop = (viewport.getScrollOffsets()[1] + (viewport.getHeight() / 2)- (windowHeight / 2)) + 'px';
|
133 |
-
var styleLeftMargin = "-" + (windowWidth / 2) + 'px';
|
134 |
-
|
135 |
-
var windowBodyWidth = (windowWidth - 80) + 'px';
|
136 |
-
var windowBodyHeight = (windowHeight - 50) + 'px';
|
137 |
-
|
138 |
-
// mascara que cobre o fundo da tela
|
139 |
-
var mask = document.createElement("div");
|
140 |
-
mask.id = 'maxima-page-mask';
|
141 |
-
mask.setStyle
|
142 |
-
({
|
143 |
-
'width' : viewport.getWidth() + "px",
|
144 |
-
'height' : viewport.getHeight() + "px",
|
145 |
-
'position' : 'absolute',
|
146 |
-
'zIndex' : '9000',
|
147 |
-
'backgroundColor' : '#333333',
|
148 |
-
'top' : viewport.getScrollOffsets()[1] + 'px',
|
149 |
-
'left' : '0',
|
150 |
-
'display' : 'none'
|
151 |
-
});
|
152 |
-
|
153 |
-
|
154 |
-
// janela modal
|
155 |
-
var modalWindow = document.createElement("div");
|
156 |
-
modalWindow.id = 'maxima-modal-window';
|
157 |
-
$(modalWindow).setStyle
|
158 |
-
({
|
159 |
-
'width' : styleWidth,
|
160 |
-
'height' : styleHeight,
|
161 |
-
'top' : styleTop,
|
162 |
-
'marginLeft' : styleLeftMargin,
|
163 |
-
'position' : 'absolute',
|
164 |
-
'zIndex' : '9001',
|
165 |
-
'backgroundColor' : 'transparent',
|
166 |
-
'left' : '50%',
|
167 |
-
'display' : 'none',
|
168 |
-
'color' : '#333333',
|
169 |
-
'fontSize' : '11px'
|
170 |
-
});
|
171 |
-
|
172 |
-
// tabela que monta o layout da janela
|
173 |
-
var windowStructure = document.createElement("table");
|
174 |
-
var tableBody = document.createElement("tbody");
|
175 |
-
|
176 |
-
windowStructure.cellPadding = '0';
|
177 |
-
windowStructure.cellSpacing = '0';
|
178 |
-
windowStructure.border = '0';
|
179 |
-
|
180 |
-
var tr1WindowStructure = document.createElement("tr");
|
181 |
-
var tr2WindowStructure = document.createElement("tr");
|
182 |
-
var tr3WindowStructure = document.createElement("tr");
|
183 |
-
|
184 |
-
var td11WindowStructure = document.createElement("td");
|
185 |
-
var td12WindowStructure = document.createElement("td");
|
186 |
-
var td13WindowStructure = document.createElement("td");
|
187 |
-
var td21WindowStructure = document.createElement("td");
|
188 |
-
var td22WindowStructure = document.createElement("td");
|
189 |
-
var td23WindowStructure = document.createElement("td");
|
190 |
-
var td31WindowStructure = document.createElement("td");
|
191 |
-
var td32WindowStructure = document.createElement("td");
|
192 |
-
var td33WindowStructure = document.createElement("td");
|
193 |
-
|
194 |
-
var leftUpCorner = document.createElement("div");
|
195 |
-
$(leftUpCorner).setStyle
|
196 |
-
({
|
197 |
-
'height' : '10px',
|
198 |
-
'width' : '10px',
|
199 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>top_left.png\')'
|
200 |
-
});
|
201 |
-
td11WindowStructure.appendChild(leftUpCorner);
|
202 |
-
|
203 |
-
$(td12WindowStructure).setStyle
|
204 |
-
({
|
205 |
-
'height' : '10px',
|
206 |
-
'width' : (windowWidth - 20) + 'px',
|
207 |
-
'backgroundColor' : '#333333'
|
208 |
-
});
|
209 |
-
|
210 |
-
var rightUpCorner = document.createElement("div");
|
211 |
-
$(rightUpCorner).setStyle
|
212 |
-
({
|
213 |
-
'height' : '10px',
|
214 |
-
'width' : '10px',
|
215 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>top_right.png\')'
|
216 |
-
});
|
217 |
-
td13WindowStructure.appendChild(rightUpCorner);
|
218 |
-
|
219 |
-
$(td21WindowStructure).setStyle
|
220 |
-
({
|
221 |
-
'height' : (windowHeight - 20) + 'px',
|
222 |
-
'width' : '10px',
|
223 |
-
'backgroundColor' : '#333333'
|
224 |
-
});
|
225 |
-
|
226 |
-
$(td22WindowStructure).setStyle
|
227 |
-
({
|
228 |
-
'backgroundColor' : '#FFFFFF'
|
229 |
-
});
|
230 |
-
|
231 |
-
$(td23WindowStructure).setStyle
|
232 |
-
({
|
233 |
-
'height' : (windowHeight - 20) + 'px',
|
234 |
-
'width' : '10px',
|
235 |
-
'backgroundColor' : '#333333'
|
236 |
-
});
|
237 |
-
|
238 |
-
$(td31WindowStructure).setStyle
|
239 |
-
({
|
240 |
-
'height' : '10px',
|
241 |
-
'width' : '10px',
|
242 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>bottom_left.png\')'
|
243 |
-
});
|
244 |
-
|
245 |
-
$(td32WindowStructure).setStyle
|
246 |
-
({
|
247 |
-
'height' : '10px',
|
248 |
-
'width' : (windowWidth - 20) + 'px',
|
249 |
-
'backgroundColor' : '#333333'
|
250 |
-
});
|
251 |
-
|
252 |
-
$(td33WindowStructure).setStyle
|
253 |
-
({
|
254 |
-
'height' : '10px',
|
255 |
-
'width' : '10px',
|
256 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>bottom_right.png\')'
|
257 |
-
});
|
258 |
-
|
259 |
-
tr1WindowStructure.appendChild(td11WindowStructure);
|
260 |
-
tr1WindowStructure.appendChild(td12WindowStructure);
|
261 |
-
tr1WindowStructure.appendChild(td13WindowStructure);
|
262 |
-
tr2WindowStructure.appendChild(td21WindowStructure);
|
263 |
-
tr2WindowStructure.appendChild(td22WindowStructure);
|
264 |
-
tr2WindowStructure.appendChild(td23WindowStructure);
|
265 |
-
tr3WindowStructure.appendChild(td31WindowStructure);
|
266 |
-
tr3WindowStructure.appendChild(td32WindowStructure);
|
267 |
-
tr3WindowStructure.appendChild(td33WindowStructure);
|
268 |
-
|
269 |
-
tableBody.appendChild(tr1WindowStructure);
|
270 |
-
tableBody.appendChild(tr2WindowStructure);
|
271 |
-
tableBody.appendChild(tr3WindowStructure);
|
272 |
-
|
273 |
-
windowStructure.appendChild(tableBody);
|
274 |
-
|
275 |
-
modalWindow.appendChild(windowStructure);
|
276 |
-
|
277 |
-
// monta estrutura html
|
278 |
-
var windowHeader = document.createElement("div");
|
279 |
-
windowHeader.setStyle
|
280 |
-
({
|
281 |
-
'height' : '38px',
|
282 |
-
'width' : '100%',
|
283 |
-
'position' : 'relative',
|
284 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>header.png\')',
|
285 |
-
'backgroundRepeat' : 'repeat-x'
|
286 |
-
});
|
287 |
-
|
288 |
-
var titleDiv = document.createElement('div');
|
289 |
-
titleDiv.setStyle
|
290 |
-
({
|
291 |
-
'position' : 'absolute',
|
292 |
-
'top' : '8px',
|
293 |
-
'left' : '10px',
|
294 |
-
'color' : '#FFFFFF',
|
295 |
-
'fontSize' : '12px',
|
296 |
-
'fontWeight' : 'bold'
|
297 |
-
});
|
298 |
-
$(titleDiv).update(title);
|
299 |
-
|
300 |
-
var closeButton = document.createElement('div');
|
301 |
-
closeButton.setStyle
|
302 |
-
({
|
303 |
-
'position' : 'absolute',
|
304 |
-
'width' : '16px',
|
305 |
-
'height' : '16px',
|
306 |
-
'top' : '8px',
|
307 |
-
'right' : '5px',
|
308 |
-
'cursor' : 'pointer',
|
309 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>close.png\')',
|
310 |
-
});
|
311 |
-
|
312 |
-
var windowBody = document.createElement("div");
|
313 |
-
windowBody.setStyle
|
314 |
-
({
|
315 |
-
'width' : '100%',
|
316 |
-
'position' : 'relative',
|
317 |
-
'padding' : '15px',
|
318 |
-
'color' : '#333333',
|
319 |
-
'fontSize' : '12px',
|
320 |
-
'height' : windowHeight + "px",
|
321 |
-
'width' : windowWidth + "px",
|
322 |
-
'overflow' : 'auto'
|
323 |
-
});
|
324 |
-
$(windowBody).update(content);
|
325 |
-
|
326 |
-
windowHeader.appendChild(titleDiv);
|
327 |
-
windowHeader.appendChild(closeButton);
|
328 |
-
td22WindowStructure.appendChild(windowHeader);
|
329 |
-
td22WindowStructure.appendChild(windowBody);
|
330 |
-
|
331 |
-
document.body.appendChild(mask);
|
332 |
-
document.body.appendChild(modalWindow);
|
333 |
-
|
334 |
-
$(mask).appear({ duration: 0.2, from: 0, to: 0.5 });
|
335 |
-
$(modalWindow).appear({ duration: 0.2, from: 0, to: 1 });
|
336 |
-
|
337 |
-
$(closeButton).observe('click', function()
|
338 |
-
{
|
339 |
-
document.body.removeChild(mask);
|
340 |
-
document.body.removeChild(modalWindow);
|
341 |
-
$$('HTML')[0].setStyle({overflow: 'auto'});
|
342 |
-
});
|
343 |
-
|
344 |
-
|
345 |
-
}
|
346 |
// ]]></script>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
?>
|
28 |
+
Cartão de Crédito Cielo
|
29 |
+
<br /><br />
|
30 |
+
<?php
|
31 |
+
|
32 |
+
|
33 |
+
if($_info = $this->getInfo())
|
34 |
+
{
|
35 |
+
if($_info->getOrder())
|
36 |
+
{
|
37 |
+
$payment = $_info->getOrder()->getPayment();
|
38 |
+
|
39 |
+
if($payment->getAdditionalInformation ('Cielo_error'))
|
40 |
+
{
|
41 |
+
echo "Erro na transação: " . $payment->getAdditionalInformation ('Cielo_error');
|
42 |
+
}
|
43 |
+
else
|
44 |
+
{
|
45 |
+
$tid = $payment->getAdditionalInformation ('Cielo_tid');
|
46 |
+
$status = $payment->getAdditionalInformation ('Cielo_status');
|
47 |
+
$cardType = $payment->getAdditionalInformation ('Cielo_cardType');
|
48 |
+
$installments = $payment->getAdditionalInformation ('Cielo_installments');
|
49 |
+
|
50 |
+
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toArray();
|
51 |
+
$cardType = $allCards[$cardType];
|
52 |
+
$installments = ($installments == 1) ? 'À vista' : $installments . " vezes";
|
53 |
+
|
54 |
+
$html = "<b>ID Transação</b>: " . $tid . "<br />";
|
55 |
+
$html .= "<b>Status</b>: " . Mage::helper('Maxima_Cielo')->getStatusMessage($status) . "<br />";
|
56 |
+
$html .= "<b>Bandeira</b>: " . $cardType . "<br />";
|
57 |
+
$html .= "<b>Parcelamento</b>: " . $installments . "<br /><br />";
|
58 |
+
|
59 |
+
echo $html;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
}
|
63 |
+
?>
|
64 |
+
|
65 |
+
<script type="text/javascript">// <![CDATA[
|
66 |
+
|
67 |
+
|
68 |
+
function captureCieloOrder(tid, orderId)
|
69 |
+
{
|
70 |
+
var url = '<?php echo $this->getUrl('cielo/admin/capture') ?>';
|
71 |
+
|
72 |
+
new Ajax.Request(url,
|
73 |
+
{
|
74 |
+
method : 'post',
|
75 |
+
parameters : "tid=" + tid + "&order=" + orderId,
|
76 |
+
onComplete : function(transport)
|
77 |
+
{
|
78 |
+
maximaModalWindow("Captura de Dados", transport.responseText, 600, 400);
|
79 |
+
}
|
80 |
+
});
|
81 |
+
}
|
82 |
+
|
83 |
+
|
84 |
+
function loadCieloWebServiceData(tid, orderId)
|
85 |
+
{
|
86 |
+
var url = '<?php echo $this->getUrl('cielo/admin/consult') ?>';
|
87 |
+
|
88 |
+
new Ajax.Request(url,
|
89 |
+
{
|
90 |
+
method : 'post',
|
91 |
+
parameters : "tid=" + tid + "&order=" + orderId,
|
92 |
+
onComplete : function(transport)
|
93 |
+
{
|
94 |
+
maximaModalWindow("Dados Cielo", transport.responseText, 600, 400);
|
95 |
+
}
|
96 |
+
});
|
97 |
+
}
|
98 |
+
|
99 |
+
|
100 |
+
function cancelCieloOrder(tid, orderId)
|
101 |
+
{
|
102 |
+
var cancellation = confirm("<?php echo $this->__("Do You really want to cancel this transaction on Cielo?"); ?>");
|
103 |
+
|
104 |
+
if(cancellation)
|
105 |
+
{
|
106 |
+
var url = '<?php echo $this->getUrl('cielo/admin/cancel') ?>';
|
107 |
+
|
108 |
+
new Ajax.Request(url,
|
109 |
+
{
|
110 |
+
method : 'post',
|
111 |
+
parameters : "tid=" + tid + "&order=" + orderId,
|
112 |
+
onComplete : function(transport)
|
113 |
+
{
|
114 |
+
maximaModalWindow("Cancelamento na Cielo", transport.responseText, 600, 400);
|
115 |
+
}
|
116 |
+
});
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
|
121 |
+
function maximaModalWindow(title, content, width, height)
|
122 |
+
{
|
123 |
+
$$('HTML')[0].setStyle({overflow: 'hidden'});
|
124 |
+
|
125 |
+
var viewport = document.viewport;
|
126 |
+
|
127 |
+
var windowWidth = (width) ? width : 300;
|
128 |
+
var windowHeight = (height) ? height : 200;
|
129 |
+
|
130 |
+
var styleWidth = width + 'px';
|
131 |
+
var styleHeight = height + 'px';
|
132 |
+
var styleTop = (viewport.getScrollOffsets()[1] + (viewport.getHeight() / 2)- (windowHeight / 2)) + 'px';
|
133 |
+
var styleLeftMargin = "-" + (windowWidth / 2) + 'px';
|
134 |
+
|
135 |
+
var windowBodyWidth = (windowWidth - 80) + 'px';
|
136 |
+
var windowBodyHeight = (windowHeight - 50) + 'px';
|
137 |
+
|
138 |
+
// mascara que cobre o fundo da tela
|
139 |
+
var mask = document.createElement("div");
|
140 |
+
mask.id = 'maxima-page-mask';
|
141 |
+
mask.setStyle
|
142 |
+
({
|
143 |
+
'width' : viewport.getWidth() + "px",
|
144 |
+
'height' : viewport.getHeight() + "px",
|
145 |
+
'position' : 'absolute',
|
146 |
+
'zIndex' : '9000',
|
147 |
+
'backgroundColor' : '#333333',
|
148 |
+
'top' : viewport.getScrollOffsets()[1] + 'px',
|
149 |
+
'left' : '0',
|
150 |
+
'display' : 'none'
|
151 |
+
});
|
152 |
+
|
153 |
+
|
154 |
+
// janela modal
|
155 |
+
var modalWindow = document.createElement("div");
|
156 |
+
modalWindow.id = 'maxima-modal-window';
|
157 |
+
$(modalWindow).setStyle
|
158 |
+
({
|
159 |
+
'width' : styleWidth,
|
160 |
+
'height' : styleHeight,
|
161 |
+
'top' : styleTop,
|
162 |
+
'marginLeft' : styleLeftMargin,
|
163 |
+
'position' : 'absolute',
|
164 |
+
'zIndex' : '9001',
|
165 |
+
'backgroundColor' : 'transparent',
|
166 |
+
'left' : '50%',
|
167 |
+
'display' : 'none',
|
168 |
+
'color' : '#333333',
|
169 |
+
'fontSize' : '11px'
|
170 |
+
});
|
171 |
+
|
172 |
+
// tabela que monta o layout da janela
|
173 |
+
var windowStructure = document.createElement("table");
|
174 |
+
var tableBody = document.createElement("tbody");
|
175 |
+
|
176 |
+
windowStructure.cellPadding = '0';
|
177 |
+
windowStructure.cellSpacing = '0';
|
178 |
+
windowStructure.border = '0';
|
179 |
+
|
180 |
+
var tr1WindowStructure = document.createElement("tr");
|
181 |
+
var tr2WindowStructure = document.createElement("tr");
|
182 |
+
var tr3WindowStructure = document.createElement("tr");
|
183 |
+
|
184 |
+
var td11WindowStructure = document.createElement("td");
|
185 |
+
var td12WindowStructure = document.createElement("td");
|
186 |
+
var td13WindowStructure = document.createElement("td");
|
187 |
+
var td21WindowStructure = document.createElement("td");
|
188 |
+
var td22WindowStructure = document.createElement("td");
|
189 |
+
var td23WindowStructure = document.createElement("td");
|
190 |
+
var td31WindowStructure = document.createElement("td");
|
191 |
+
var td32WindowStructure = document.createElement("td");
|
192 |
+
var td33WindowStructure = document.createElement("td");
|
193 |
+
|
194 |
+
var leftUpCorner = document.createElement("div");
|
195 |
+
$(leftUpCorner).setStyle
|
196 |
+
({
|
197 |
+
'height' : '10px',
|
198 |
+
'width' : '10px',
|
199 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>top_left.png\')'
|
200 |
+
});
|
201 |
+
td11WindowStructure.appendChild(leftUpCorner);
|
202 |
+
|
203 |
+
$(td12WindowStructure).setStyle
|
204 |
+
({
|
205 |
+
'height' : '10px',
|
206 |
+
'width' : (windowWidth - 20) + 'px',
|
207 |
+
'backgroundColor' : '#333333'
|
208 |
+
});
|
209 |
+
|
210 |
+
var rightUpCorner = document.createElement("div");
|
211 |
+
$(rightUpCorner).setStyle
|
212 |
+
({
|
213 |
+
'height' : '10px',
|
214 |
+
'width' : '10px',
|
215 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>top_right.png\')'
|
216 |
+
});
|
217 |
+
td13WindowStructure.appendChild(rightUpCorner);
|
218 |
+
|
219 |
+
$(td21WindowStructure).setStyle
|
220 |
+
({
|
221 |
+
'height' : (windowHeight - 20) + 'px',
|
222 |
+
'width' : '10px',
|
223 |
+
'backgroundColor' : '#333333'
|
224 |
+
});
|
225 |
+
|
226 |
+
$(td22WindowStructure).setStyle
|
227 |
+
({
|
228 |
+
'backgroundColor' : '#FFFFFF'
|
229 |
+
});
|
230 |
+
|
231 |
+
$(td23WindowStructure).setStyle
|
232 |
+
({
|
233 |
+
'height' : (windowHeight - 20) + 'px',
|
234 |
+
'width' : '10px',
|
235 |
+
'backgroundColor' : '#333333'
|
236 |
+
});
|
237 |
+
|
238 |
+
$(td31WindowStructure).setStyle
|
239 |
+
({
|
240 |
+
'height' : '10px',
|
241 |
+
'width' : '10px',
|
242 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>bottom_left.png\')'
|
243 |
+
});
|
244 |
+
|
245 |
+
$(td32WindowStructure).setStyle
|
246 |
+
({
|
247 |
+
'height' : '10px',
|
248 |
+
'width' : (windowWidth - 20) + 'px',
|
249 |
+
'backgroundColor' : '#333333'
|
250 |
+
});
|
251 |
+
|
252 |
+
$(td33WindowStructure).setStyle
|
253 |
+
({
|
254 |
+
'height' : '10px',
|
255 |
+
'width' : '10px',
|
256 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>bottom_right.png\')'
|
257 |
+
});
|
258 |
+
|
259 |
+
tr1WindowStructure.appendChild(td11WindowStructure);
|
260 |
+
tr1WindowStructure.appendChild(td12WindowStructure);
|
261 |
+
tr1WindowStructure.appendChild(td13WindowStructure);
|
262 |
+
tr2WindowStructure.appendChild(td21WindowStructure);
|
263 |
+
tr2WindowStructure.appendChild(td22WindowStructure);
|
264 |
+
tr2WindowStructure.appendChild(td23WindowStructure);
|
265 |
+
tr3WindowStructure.appendChild(td31WindowStructure);
|
266 |
+
tr3WindowStructure.appendChild(td32WindowStructure);
|
267 |
+
tr3WindowStructure.appendChild(td33WindowStructure);
|
268 |
+
|
269 |
+
tableBody.appendChild(tr1WindowStructure);
|
270 |
+
tableBody.appendChild(tr2WindowStructure);
|
271 |
+
tableBody.appendChild(tr3WindowStructure);
|
272 |
+
|
273 |
+
windowStructure.appendChild(tableBody);
|
274 |
+
|
275 |
+
modalWindow.appendChild(windowStructure);
|
276 |
+
|
277 |
+
// monta estrutura html
|
278 |
+
var windowHeader = document.createElement("div");
|
279 |
+
windowHeader.setStyle
|
280 |
+
({
|
281 |
+
'height' : '38px',
|
282 |
+
'width' : '100%',
|
283 |
+
'position' : 'relative',
|
284 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>header.png\')',
|
285 |
+
'backgroundRepeat' : 'repeat-x'
|
286 |
+
});
|
287 |
+
|
288 |
+
var titleDiv = document.createElement('div');
|
289 |
+
titleDiv.setStyle
|
290 |
+
({
|
291 |
+
'position' : 'absolute',
|
292 |
+
'top' : '8px',
|
293 |
+
'left' : '10px',
|
294 |
+
'color' : '#FFFFFF',
|
295 |
+
'fontSize' : '12px',
|
296 |
+
'fontWeight' : 'bold'
|
297 |
+
});
|
298 |
+
$(titleDiv).update(title);
|
299 |
+
|
300 |
+
var closeButton = document.createElement('div');
|
301 |
+
closeButton.setStyle
|
302 |
+
({
|
303 |
+
'position' : 'absolute',
|
304 |
+
'width' : '16px',
|
305 |
+
'height' : '16px',
|
306 |
+
'top' : '8px',
|
307 |
+
'right' : '5px',
|
308 |
+
'cursor' : 'pointer',
|
309 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>close.png\')',
|
310 |
+
});
|
311 |
+
|
312 |
+
var windowBody = document.createElement("div");
|
313 |
+
windowBody.setStyle
|
314 |
+
({
|
315 |
+
'width' : '100%',
|
316 |
+
'position' : 'relative',
|
317 |
+
'padding' : '15px',
|
318 |
+
'color' : '#333333',
|
319 |
+
'fontSize' : '12px',
|
320 |
+
'height' : windowHeight + "px",
|
321 |
+
'width' : windowWidth + "px",
|
322 |
+
'overflow' : 'auto'
|
323 |
+
});
|
324 |
+
$(windowBody).update(content);
|
325 |
+
|
326 |
+
windowHeader.appendChild(titleDiv);
|
327 |
+
windowHeader.appendChild(closeButton);
|
328 |
+
td22WindowStructure.appendChild(windowHeader);
|
329 |
+
td22WindowStructure.appendChild(windowBody);
|
330 |
+
|
331 |
+
document.body.appendChild(mask);
|
332 |
+
document.body.appendChild(modalWindow);
|
333 |
+
|
334 |
+
$(mask).appear({ duration: 0.2, from: 0, to: 0.5 });
|
335 |
+
$(modalWindow).appear({ duration: 0.2, from: 0, to: 1 });
|
336 |
+
|
337 |
+
$(closeButton).observe('click', function()
|
338 |
+
{
|
339 |
+
document.body.removeChild(mask);
|
340 |
+
document.body.removeChild(modalWindow);
|
341 |
+
$$('HTML')[0].setStyle({overflow: 'auto'});
|
342 |
+
});
|
343 |
+
|
344 |
+
|
345 |
+
}
|
346 |
// ]]></script>
|
app/design/adminhtml/default/default/template/cielo/info/dc.phtml
CHANGED
@@ -1,308 +1,308 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
?>
|
28 |
-
Cartão de Débito Cielo
|
29 |
-
<br /><br />
|
30 |
-
<?php
|
31 |
-
|
32 |
-
|
33 |
-
if($_info = $this->getInfo())
|
34 |
-
{
|
35 |
-
if($_info->getOrder())
|
36 |
-
{
|
37 |
-
$payment = $_info->getOrder()->getPayment();
|
38 |
-
|
39 |
-
if($payment->getAdditionalInformation ('Cielo_error'))
|
40 |
-
{
|
41 |
-
echo "Erro na transação: " . $payment->getAdditionalInformation ('Cielo_error');
|
42 |
-
}
|
43 |
-
else
|
44 |
-
{
|
45 |
-
$tid = $payment->getAdditionalInformation ('Cielo_tid');
|
46 |
-
$status = $payment->getAdditionalInformation ('Cielo_status');
|
47 |
-
$cardType = $payment->getAdditionalInformation ('Cielo_cardType');
|
48 |
-
$installments = $payment->getAdditionalInformation ('Cielo_installments');
|
49 |
-
|
50 |
-
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toArray();
|
51 |
-
$cardType = $allCards[$cardType];
|
52 |
-
$installments = ($installments == 1) ? 'À vista' : $installments . " vezes";
|
53 |
-
|
54 |
-
$html = "<b>ID Transação</b>: " . $tid . "<br />";
|
55 |
-
$html .= "<b>Status</b>: " . Mage::helper('Maxima_Cielo')->getStatusMessage($status) . "<br />";
|
56 |
-
$html .= "<b>Bandeira</b>: " . $cardType . "<br />";
|
57 |
-
$html .= "<b>Parcelamento</b>: " . $installments . "<br /><br />";
|
58 |
-
|
59 |
-
echo $html;
|
60 |
-
}
|
61 |
-
}
|
62 |
-
}
|
63 |
-
?>
|
64 |
-
|
65 |
-
<script type="text/javascript">// <![CDATA[
|
66 |
-
|
67 |
-
function loadCieloWebServiceData(tid, orderId)
|
68 |
-
{
|
69 |
-
var url = '<?php echo $this->getUrl('cielo/admin/consult') ?>';
|
70 |
-
|
71 |
-
new Ajax.Request(url,
|
72 |
-
{
|
73 |
-
method : 'post',
|
74 |
-
parameters : "tid=" + tid + "&order=" + orderId,
|
75 |
-
onComplete : function(transport)
|
76 |
-
{
|
77 |
-
maximaModalWindow("Dados Cielo", transport.responseText, 600, 400);
|
78 |
-
}
|
79 |
-
});
|
80 |
-
}
|
81 |
-
|
82 |
-
|
83 |
-
function maximaModalWindow(title, content, width, height)
|
84 |
-
{
|
85 |
-
$$('HTML')[0].setStyle({overflow: 'hidden'});
|
86 |
-
|
87 |
-
var viewport = document.viewport;
|
88 |
-
|
89 |
-
var windowWidth = (width) ? width : 300;
|
90 |
-
var windowHeight = (height) ? height : 200;
|
91 |
-
|
92 |
-
var styleWidth = width + 'px';
|
93 |
-
var styleHeight = height + 'px';
|
94 |
-
var styleTop = (viewport.getScrollOffsets()[1] + (viewport.getHeight() / 2)- (windowHeight / 2)) + 'px';
|
95 |
-
var styleLeftMargin = "-" + (windowWidth / 2) + 'px';
|
96 |
-
|
97 |
-
var windowBodyWidth = (windowWidth - 80) + 'px';
|
98 |
-
var windowBodyHeight = (windowHeight - 50) + 'px';
|
99 |
-
|
100 |
-
// mascara que cobre o fundo da tela
|
101 |
-
var mask = document.createElement("div");
|
102 |
-
mask.id = 'maxima-page-mask';
|
103 |
-
mask.setStyle
|
104 |
-
({
|
105 |
-
'width' : viewport.getWidth() + "px",
|
106 |
-
'height' : viewport.getHeight() + "px",
|
107 |
-
'position' : 'absolute',
|
108 |
-
'zIndex' : '9000',
|
109 |
-
'backgroundColor' : '#333333',
|
110 |
-
'top' : viewport.getScrollOffsets()[1] + 'px',
|
111 |
-
'left' : '0',
|
112 |
-
'display' : 'none'
|
113 |
-
});
|
114 |
-
|
115 |
-
|
116 |
-
// janela modal
|
117 |
-
var modalWindow = document.createElement("div");
|
118 |
-
modalWindow.id = 'maxima-modal-window';
|
119 |
-
$(modalWindow).setStyle
|
120 |
-
({
|
121 |
-
'width' : styleWidth,
|
122 |
-
'height' : styleHeight,
|
123 |
-
'top' : styleTop,
|
124 |
-
'marginLeft' : styleLeftMargin,
|
125 |
-
'position' : 'absolute',
|
126 |
-
'zIndex' : '9001',
|
127 |
-
'backgroundColor' : 'transparent',
|
128 |
-
'left' : '50%',
|
129 |
-
'display' : 'none',
|
130 |
-
'color' : '#333333',
|
131 |
-
'fontSize' : '11px'
|
132 |
-
});
|
133 |
-
|
134 |
-
// tabela que monta o layout da janela
|
135 |
-
var windowStructure = document.createElement("table");
|
136 |
-
var tableBody = document.createElement("tbody");
|
137 |
-
|
138 |
-
windowStructure.cellPadding = '0';
|
139 |
-
windowStructure.cellSpacing = '0';
|
140 |
-
windowStructure.border = '0';
|
141 |
-
|
142 |
-
var tr1WindowStructure = document.createElement("tr");
|
143 |
-
var tr2WindowStructure = document.createElement("tr");
|
144 |
-
var tr3WindowStructure = document.createElement("tr");
|
145 |
-
|
146 |
-
var td11WindowStructure = document.createElement("td");
|
147 |
-
var td12WindowStructure = document.createElement("td");
|
148 |
-
var td13WindowStructure = document.createElement("td");
|
149 |
-
var td21WindowStructure = document.createElement("td");
|
150 |
-
var td22WindowStructure = document.createElement("td");
|
151 |
-
var td23WindowStructure = document.createElement("td");
|
152 |
-
var td31WindowStructure = document.createElement("td");
|
153 |
-
var td32WindowStructure = document.createElement("td");
|
154 |
-
var td33WindowStructure = document.createElement("td");
|
155 |
-
|
156 |
-
var leftUpCorner = document.createElement("div");
|
157 |
-
$(leftUpCorner).setStyle
|
158 |
-
({
|
159 |
-
'height' : '10px',
|
160 |
-
'width' : '10px',
|
161 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>top_left.png\')'
|
162 |
-
});
|
163 |
-
td11WindowStructure.appendChild(leftUpCorner);
|
164 |
-
|
165 |
-
$(td12WindowStructure).setStyle
|
166 |
-
({
|
167 |
-
'height' : '10px',
|
168 |
-
'width' : (windowWidth - 20) + 'px',
|
169 |
-
'backgroundColor' : '#333333'
|
170 |
-
});
|
171 |
-
|
172 |
-
var rightUpCorner = document.createElement("div");
|
173 |
-
$(rightUpCorner).setStyle
|
174 |
-
({
|
175 |
-
'height' : '10px',
|
176 |
-
'width' : '10px',
|
177 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>top_right.png\')'
|
178 |
-
});
|
179 |
-
td13WindowStructure.appendChild(rightUpCorner);
|
180 |
-
|
181 |
-
$(td21WindowStructure).setStyle
|
182 |
-
({
|
183 |
-
'height' : (windowHeight - 20) + 'px',
|
184 |
-
'width' : '10px',
|
185 |
-
'backgroundColor' : '#333333'
|
186 |
-
});
|
187 |
-
|
188 |
-
$(td22WindowStructure).setStyle
|
189 |
-
({
|
190 |
-
'backgroundColor' : '#FFFFFF'
|
191 |
-
});
|
192 |
-
|
193 |
-
$(td23WindowStructure).setStyle
|
194 |
-
({
|
195 |
-
'height' : (windowHeight - 20) + 'px',
|
196 |
-
'width' : '10px',
|
197 |
-
'backgroundColor' : '#333333'
|
198 |
-
});
|
199 |
-
|
200 |
-
$(td31WindowStructure).setStyle
|
201 |
-
({
|
202 |
-
'height' : '10px',
|
203 |
-
'width' : '10px',
|
204 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>bottom_left.png\')'
|
205 |
-
});
|
206 |
-
|
207 |
-
$(td32WindowStructure).setStyle
|
208 |
-
({
|
209 |
-
'height' : '10px',
|
210 |
-
'width' : (windowWidth - 20) + 'px',
|
211 |
-
'backgroundColor' : '#333333'
|
212 |
-
});
|
213 |
-
|
214 |
-
$(td33WindowStructure).setStyle
|
215 |
-
({
|
216 |
-
'height' : '10px',
|
217 |
-
'width' : '10px',
|
218 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>bottom_right.png\')'
|
219 |
-
});
|
220 |
-
|
221 |
-
tr1WindowStructure.appendChild(td11WindowStructure);
|
222 |
-
tr1WindowStructure.appendChild(td12WindowStructure);
|
223 |
-
tr1WindowStructure.appendChild(td13WindowStructure);
|
224 |
-
tr2WindowStructure.appendChild(td21WindowStructure);
|
225 |
-
tr2WindowStructure.appendChild(td22WindowStructure);
|
226 |
-
tr2WindowStructure.appendChild(td23WindowStructure);
|
227 |
-
tr3WindowStructure.appendChild(td31WindowStructure);
|
228 |
-
tr3WindowStructure.appendChild(td32WindowStructure);
|
229 |
-
tr3WindowStructure.appendChild(td33WindowStructure);
|
230 |
-
|
231 |
-
tableBody.appendChild(tr1WindowStructure);
|
232 |
-
tableBody.appendChild(tr2WindowStructure);
|
233 |
-
tableBody.appendChild(tr3WindowStructure);
|
234 |
-
|
235 |
-
windowStructure.appendChild(tableBody);
|
236 |
-
|
237 |
-
modalWindow.appendChild(windowStructure);
|
238 |
-
|
239 |
-
// monta estrutura html
|
240 |
-
var windowHeader = document.createElement("div");
|
241 |
-
windowHeader.setStyle
|
242 |
-
({
|
243 |
-
'height' : '38px',
|
244 |
-
'width' : '100%',
|
245 |
-
'position' : 'relative',
|
246 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>header.png\')',
|
247 |
-
'backgroundRepeat' : 'repeat-x'
|
248 |
-
});
|
249 |
-
|
250 |
-
var titleDiv = document.createElement('div');
|
251 |
-
titleDiv.setStyle
|
252 |
-
({
|
253 |
-
'position' : 'absolute',
|
254 |
-
'top' : '8px',
|
255 |
-
'left' : '10px',
|
256 |
-
'color' : '#FFFFFF',
|
257 |
-
'fontSize' : '12px',
|
258 |
-
'fontWeight' : 'bold'
|
259 |
-
});
|
260 |
-
$(titleDiv).update(title);
|
261 |
-
|
262 |
-
var closeButton = document.createElement('div');
|
263 |
-
closeButton.setStyle
|
264 |
-
({
|
265 |
-
'position' : 'absolute',
|
266 |
-
'width' : '16px',
|
267 |
-
'height' : '16px',
|
268 |
-
'top' : '8px',
|
269 |
-
'right' : '5px',
|
270 |
-
'cursor' : 'pointer',
|
271 |
-
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>close.png\')',
|
272 |
-
});
|
273 |
-
|
274 |
-
var windowBody = document.createElement("div");
|
275 |
-
windowBody.setStyle
|
276 |
-
({
|
277 |
-
'width' : '100%',
|
278 |
-
'position' : 'relative',
|
279 |
-
'padding' : '15px',
|
280 |
-
'color' : '#333333',
|
281 |
-
'fontSize' : '12px',
|
282 |
-
'height' : windowHeight + "px",
|
283 |
-
'width' : windowWidth + "px",
|
284 |
-
'overflow' : 'auto'
|
285 |
-
});
|
286 |
-
$(windowBody).update(content);
|
287 |
-
|
288 |
-
windowHeader.appendChild(titleDiv);
|
289 |
-
windowHeader.appendChild(closeButton);
|
290 |
-
td22WindowStructure.appendChild(windowHeader);
|
291 |
-
td22WindowStructure.appendChild(windowBody);
|
292 |
-
|
293 |
-
document.body.appendChild(mask);
|
294 |
-
document.body.appendChild(modalWindow);
|
295 |
-
|
296 |
-
$(mask).appear({ duration: 0.2, from: 0, to: 0.5 });
|
297 |
-
$(modalWindow).appear({ duration: 0.2, from: 0, to: 1 });
|
298 |
-
|
299 |
-
$(closeButton).observe('click', function()
|
300 |
-
{
|
301 |
-
document.body.removeChild(mask);
|
302 |
-
document.body.removeChild(modalWindow);
|
303 |
-
$$('HTML')[0].setStyle({overflow: 'auto'});
|
304 |
-
});
|
305 |
-
|
306 |
-
|
307 |
-
}
|
308 |
// ]]></script>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
?>
|
28 |
+
Cartão de Débito Cielo
|
29 |
+
<br /><br />
|
30 |
+
<?php
|
31 |
+
|
32 |
+
|
33 |
+
if($_info = $this->getInfo())
|
34 |
+
{
|
35 |
+
if($_info->getOrder())
|
36 |
+
{
|
37 |
+
$payment = $_info->getOrder()->getPayment();
|
38 |
+
|
39 |
+
if($payment->getAdditionalInformation ('Cielo_error'))
|
40 |
+
{
|
41 |
+
echo "Erro na transação: " . $payment->getAdditionalInformation ('Cielo_error');
|
42 |
+
}
|
43 |
+
else
|
44 |
+
{
|
45 |
+
$tid = $payment->getAdditionalInformation ('Cielo_tid');
|
46 |
+
$status = $payment->getAdditionalInformation ('Cielo_status');
|
47 |
+
$cardType = $payment->getAdditionalInformation ('Cielo_cardType');
|
48 |
+
$installments = $payment->getAdditionalInformation ('Cielo_installments');
|
49 |
+
|
50 |
+
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toArray();
|
51 |
+
$cardType = $allCards[$cardType];
|
52 |
+
$installments = ($installments == 1) ? 'À vista' : $installments . " vezes";
|
53 |
+
|
54 |
+
$html = "<b>ID Transação</b>: " . $tid . "<br />";
|
55 |
+
$html .= "<b>Status</b>: " . Mage::helper('Maxima_Cielo')->getStatusMessage($status) . "<br />";
|
56 |
+
$html .= "<b>Bandeira</b>: " . $cardType . "<br />";
|
57 |
+
$html .= "<b>Parcelamento</b>: " . $installments . "<br /><br />";
|
58 |
+
|
59 |
+
echo $html;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
}
|
63 |
+
?>
|
64 |
+
|
65 |
+
<script type="text/javascript">// <![CDATA[
|
66 |
+
|
67 |
+
function loadCieloWebServiceData(tid, orderId)
|
68 |
+
{
|
69 |
+
var url = '<?php echo $this->getUrl('cielo/admin/consult') ?>';
|
70 |
+
|
71 |
+
new Ajax.Request(url,
|
72 |
+
{
|
73 |
+
method : 'post',
|
74 |
+
parameters : "tid=" + tid + "&order=" + orderId,
|
75 |
+
onComplete : function(transport)
|
76 |
+
{
|
77 |
+
maximaModalWindow("Dados Cielo", transport.responseText, 600, 400);
|
78 |
+
}
|
79 |
+
});
|
80 |
+
}
|
81 |
+
|
82 |
+
|
83 |
+
function maximaModalWindow(title, content, width, height)
|
84 |
+
{
|
85 |
+
$$('HTML')[0].setStyle({overflow: 'hidden'});
|
86 |
+
|
87 |
+
var viewport = document.viewport;
|
88 |
+
|
89 |
+
var windowWidth = (width) ? width : 300;
|
90 |
+
var windowHeight = (height) ? height : 200;
|
91 |
+
|
92 |
+
var styleWidth = width + 'px';
|
93 |
+
var styleHeight = height + 'px';
|
94 |
+
var styleTop = (viewport.getScrollOffsets()[1] + (viewport.getHeight() / 2)- (windowHeight / 2)) + 'px';
|
95 |
+
var styleLeftMargin = "-" + (windowWidth / 2) + 'px';
|
96 |
+
|
97 |
+
var windowBodyWidth = (windowWidth - 80) + 'px';
|
98 |
+
var windowBodyHeight = (windowHeight - 50) + 'px';
|
99 |
+
|
100 |
+
// mascara que cobre o fundo da tela
|
101 |
+
var mask = document.createElement("div");
|
102 |
+
mask.id = 'maxima-page-mask';
|
103 |
+
mask.setStyle
|
104 |
+
({
|
105 |
+
'width' : viewport.getWidth() + "px",
|
106 |
+
'height' : viewport.getHeight() + "px",
|
107 |
+
'position' : 'absolute',
|
108 |
+
'zIndex' : '9000',
|
109 |
+
'backgroundColor' : '#333333',
|
110 |
+
'top' : viewport.getScrollOffsets()[1] + 'px',
|
111 |
+
'left' : '0',
|
112 |
+
'display' : 'none'
|
113 |
+
});
|
114 |
+
|
115 |
+
|
116 |
+
// janela modal
|
117 |
+
var modalWindow = document.createElement("div");
|
118 |
+
modalWindow.id = 'maxima-modal-window';
|
119 |
+
$(modalWindow).setStyle
|
120 |
+
({
|
121 |
+
'width' : styleWidth,
|
122 |
+
'height' : styleHeight,
|
123 |
+
'top' : styleTop,
|
124 |
+
'marginLeft' : styleLeftMargin,
|
125 |
+
'position' : 'absolute',
|
126 |
+
'zIndex' : '9001',
|
127 |
+
'backgroundColor' : 'transparent',
|
128 |
+
'left' : '50%',
|
129 |
+
'display' : 'none',
|
130 |
+
'color' : '#333333',
|
131 |
+
'fontSize' : '11px'
|
132 |
+
});
|
133 |
+
|
134 |
+
// tabela que monta o layout da janela
|
135 |
+
var windowStructure = document.createElement("table");
|
136 |
+
var tableBody = document.createElement("tbody");
|
137 |
+
|
138 |
+
windowStructure.cellPadding = '0';
|
139 |
+
windowStructure.cellSpacing = '0';
|
140 |
+
windowStructure.border = '0';
|
141 |
+
|
142 |
+
var tr1WindowStructure = document.createElement("tr");
|
143 |
+
var tr2WindowStructure = document.createElement("tr");
|
144 |
+
var tr3WindowStructure = document.createElement("tr");
|
145 |
+
|
146 |
+
var td11WindowStructure = document.createElement("td");
|
147 |
+
var td12WindowStructure = document.createElement("td");
|
148 |
+
var td13WindowStructure = document.createElement("td");
|
149 |
+
var td21WindowStructure = document.createElement("td");
|
150 |
+
var td22WindowStructure = document.createElement("td");
|
151 |
+
var td23WindowStructure = document.createElement("td");
|
152 |
+
var td31WindowStructure = document.createElement("td");
|
153 |
+
var td32WindowStructure = document.createElement("td");
|
154 |
+
var td33WindowStructure = document.createElement("td");
|
155 |
+
|
156 |
+
var leftUpCorner = document.createElement("div");
|
157 |
+
$(leftUpCorner).setStyle
|
158 |
+
({
|
159 |
+
'height' : '10px',
|
160 |
+
'width' : '10px',
|
161 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>top_left.png\')'
|
162 |
+
});
|
163 |
+
td11WindowStructure.appendChild(leftUpCorner);
|
164 |
+
|
165 |
+
$(td12WindowStructure).setStyle
|
166 |
+
({
|
167 |
+
'height' : '10px',
|
168 |
+
'width' : (windowWidth - 20) + 'px',
|
169 |
+
'backgroundColor' : '#333333'
|
170 |
+
});
|
171 |
+
|
172 |
+
var rightUpCorner = document.createElement("div");
|
173 |
+
$(rightUpCorner).setStyle
|
174 |
+
({
|
175 |
+
'height' : '10px',
|
176 |
+
'width' : '10px',
|
177 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>top_right.png\')'
|
178 |
+
});
|
179 |
+
td13WindowStructure.appendChild(rightUpCorner);
|
180 |
+
|
181 |
+
$(td21WindowStructure).setStyle
|
182 |
+
({
|
183 |
+
'height' : (windowHeight - 20) + 'px',
|
184 |
+
'width' : '10px',
|
185 |
+
'backgroundColor' : '#333333'
|
186 |
+
});
|
187 |
+
|
188 |
+
$(td22WindowStructure).setStyle
|
189 |
+
({
|
190 |
+
'backgroundColor' : '#FFFFFF'
|
191 |
+
});
|
192 |
+
|
193 |
+
$(td23WindowStructure).setStyle
|
194 |
+
({
|
195 |
+
'height' : (windowHeight - 20) + 'px',
|
196 |
+
'width' : '10px',
|
197 |
+
'backgroundColor' : '#333333'
|
198 |
+
});
|
199 |
+
|
200 |
+
$(td31WindowStructure).setStyle
|
201 |
+
({
|
202 |
+
'height' : '10px',
|
203 |
+
'width' : '10px',
|
204 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>bottom_left.png\')'
|
205 |
+
});
|
206 |
+
|
207 |
+
$(td32WindowStructure).setStyle
|
208 |
+
({
|
209 |
+
'height' : '10px',
|
210 |
+
'width' : (windowWidth - 20) + 'px',
|
211 |
+
'backgroundColor' : '#333333'
|
212 |
+
});
|
213 |
+
|
214 |
+
$(td33WindowStructure).setStyle
|
215 |
+
({
|
216 |
+
'height' : '10px',
|
217 |
+
'width' : '10px',
|
218 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>bottom_right.png\')'
|
219 |
+
});
|
220 |
+
|
221 |
+
tr1WindowStructure.appendChild(td11WindowStructure);
|
222 |
+
tr1WindowStructure.appendChild(td12WindowStructure);
|
223 |
+
tr1WindowStructure.appendChild(td13WindowStructure);
|
224 |
+
tr2WindowStructure.appendChild(td21WindowStructure);
|
225 |
+
tr2WindowStructure.appendChild(td22WindowStructure);
|
226 |
+
tr2WindowStructure.appendChild(td23WindowStructure);
|
227 |
+
tr3WindowStructure.appendChild(td31WindowStructure);
|
228 |
+
tr3WindowStructure.appendChild(td32WindowStructure);
|
229 |
+
tr3WindowStructure.appendChild(td33WindowStructure);
|
230 |
+
|
231 |
+
tableBody.appendChild(tr1WindowStructure);
|
232 |
+
tableBody.appendChild(tr2WindowStructure);
|
233 |
+
tableBody.appendChild(tr3WindowStructure);
|
234 |
+
|
235 |
+
windowStructure.appendChild(tableBody);
|
236 |
+
|
237 |
+
modalWindow.appendChild(windowStructure);
|
238 |
+
|
239 |
+
// monta estrutura html
|
240 |
+
var windowHeader = document.createElement("div");
|
241 |
+
windowHeader.setStyle
|
242 |
+
({
|
243 |
+
'height' : '38px',
|
244 |
+
'width' : '100%',
|
245 |
+
'position' : 'relative',
|
246 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>header.png\')',
|
247 |
+
'backgroundRepeat' : 'repeat-x'
|
248 |
+
});
|
249 |
+
|
250 |
+
var titleDiv = document.createElement('div');
|
251 |
+
titleDiv.setStyle
|
252 |
+
({
|
253 |
+
'position' : 'absolute',
|
254 |
+
'top' : '8px',
|
255 |
+
'left' : '10px',
|
256 |
+
'color' : '#FFFFFF',
|
257 |
+
'fontSize' : '12px',
|
258 |
+
'fontWeight' : 'bold'
|
259 |
+
});
|
260 |
+
$(titleDiv).update(title);
|
261 |
+
|
262 |
+
var closeButton = document.createElement('div');
|
263 |
+
closeButton.setStyle
|
264 |
+
({
|
265 |
+
'position' : 'absolute',
|
266 |
+
'width' : '16px',
|
267 |
+
'height' : '16px',
|
268 |
+
'top' : '8px',
|
269 |
+
'right' : '5px',
|
270 |
+
'cursor' : 'pointer',
|
271 |
+
'backgroundImage' : 'url(\'<?php echo $this->getSkinUrl() . "images/cielo/window/"; ?>close.png\')',
|
272 |
+
});
|
273 |
+
|
274 |
+
var windowBody = document.createElement("div");
|
275 |
+
windowBody.setStyle
|
276 |
+
({
|
277 |
+
'width' : '100%',
|
278 |
+
'position' : 'relative',
|
279 |
+
'padding' : '15px',
|
280 |
+
'color' : '#333333',
|
281 |
+
'fontSize' : '12px',
|
282 |
+
'height' : windowHeight + "px",
|
283 |
+
'width' : windowWidth + "px",
|
284 |
+
'overflow' : 'auto'
|
285 |
+
});
|
286 |
+
$(windowBody).update(content);
|
287 |
+
|
288 |
+
windowHeader.appendChild(titleDiv);
|
289 |
+
windowHeader.appendChild(closeButton);
|
290 |
+
td22WindowStructure.appendChild(windowHeader);
|
291 |
+
td22WindowStructure.appendChild(windowBody);
|
292 |
+
|
293 |
+
document.body.appendChild(mask);
|
294 |
+
document.body.appendChild(modalWindow);
|
295 |
+
|
296 |
+
$(mask).appear({ duration: 0.2, from: 0, to: 0.5 });
|
297 |
+
$(modalWindow).appear({ duration: 0.2, from: 0, to: 1 });
|
298 |
+
|
299 |
+
$(closeButton).observe('click', function()
|
300 |
+
{
|
301 |
+
document.body.removeChild(mask);
|
302 |
+
document.body.removeChild(modalWindow);
|
303 |
+
$$('HTML')[0].setStyle({overflow: 'auto'});
|
304 |
+
});
|
305 |
+
|
306 |
+
|
307 |
+
}
|
308 |
// ]]></script>
|
app/design/frontend/default/default/template/cielo/form/cc.phtml
CHANGED
@@ -1,188 +1,228 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
?>
|
28 |
-
<fieldset class="form-list">
|
29 |
-
<ul id="payment_form_Maxima_Cielo_Cc" style="display:none;">
|
30 |
-
<br />
|
31 |
-
<?php
|
32 |
-
|
33 |
-
$cardsData = $this->getAllowedCards();
|
34 |
-
|
35 |
-
$size = count($cardsData);
|
36 |
-
|
37 |
-
for($i = 0; $i < $size; $i++)
|
38 |
-
{
|
39 |
-
$value = $cardsData[$i]['value'];
|
40 |
-
$label = $cardsData[$i]['label'];
|
41 |
-
$img = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . "frontend/default/default/images/cielo/" . $cardsData[$i]['image'];
|
42 |
-
|
43 |
-
// abre agrupamento de bandeiras
|
44 |
-
if($i % 3 == 0)
|
45 |
-
{
|
46 |
-
?>
|
47 |
-
<li class="first">
|
48 |
-
<ul class="card-logo">
|
49 |
-
<?php
|
50 |
-
}
|
51 |
-
|
52 |
-
// bandeira em questao
|
53 |
-
?>
|
54 |
-
<li style="width: 70px; float: left;">
|
55 |
-
<label for="card-<?php echo $value; ?>"><img src="<?php echo $img; ?>" style="width: 40px;" title="<?php echo $label; ?>" /><br>
|
56 |
-
<input name="payment[cc_type]" type="radio" value="<?php echo $value; ?>" id="card-<?php echo $value; ?>"
|
57 |
-
onclick="maximaCieloUpdateInstallments('<?php echo $value; ?>')" class="validate-one-required-by-name" />
|
58 |
-
</label>
|
59 |
-
</li>
|
60 |
-
<?php
|
61 |
-
// fecha agrupamento de bandeiras
|
62 |
-
if(($i == $size - 1))
|
63 |
-
{
|
64 |
-
?>
|
65 |
-
</ul>
|
66 |
-
</li>
|
67 |
-
<?php
|
68 |
-
}
|
69 |
-
}
|
70 |
-
|
71 |
-
// dados do cartao
|
72 |
-
// somente mostrado em buy page loja
|
73 |
-
|
74 |
-
if($this->getConfigData('buypage') == "loja")
|
75 |
-
{
|
76 |
-
?>
|
77 |
-
<li>
|
78 |
-
<label for="cielo-card-number" class="required"><em>*</em><?php echo $this->__('Card Number') ?></label><br />
|
79 |
-
<div class="input-box">
|
80 |
-
<input name="payment[cc_number]" type="text" value="" id="cielo-card-number"
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
</
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
{
|
167 |
-
installmentsField.options[i].style.display = "
|
168 |
-
}
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
// ]]></script>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
?>
|
28 |
+
<fieldset class="form-list">
|
29 |
+
<ul id="payment_form_Maxima_Cielo_Cc" style="display:none;">
|
30 |
+
<br />
|
31 |
+
<?php
|
32 |
+
|
33 |
+
$cardsData = $this->getAllowedCards();
|
34 |
+
|
35 |
+
$size = count($cardsData);
|
36 |
+
|
37 |
+
for($i = 0; $i < $size; $i++)
|
38 |
+
{
|
39 |
+
$value = $cardsData[$i]['value'];
|
40 |
+
$label = $cardsData[$i]['label'];
|
41 |
+
$img = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . "frontend/default/default/images/cielo/" . $cardsData[$i]['image'];
|
42 |
+
|
43 |
+
// abre agrupamento de bandeiras
|
44 |
+
if($i % 3 == 0)
|
45 |
+
{
|
46 |
+
?>
|
47 |
+
<li class="first">
|
48 |
+
<ul class="card-logo">
|
49 |
+
<?php
|
50 |
+
}
|
51 |
+
|
52 |
+
// bandeira em questao
|
53 |
+
?>
|
54 |
+
<li style="width: 70px; float: left;">
|
55 |
+
<label for="card-<?php echo $value; ?>"><img src="<?php echo $img; ?>" style="width: 40px;" title="<?php echo $label; ?>" /><br>
|
56 |
+
<input name="payment[cc_type]" type="radio" value="<?php echo $value; ?>" id="card-<?php echo $value; ?>"
|
57 |
+
onclick="maximaCieloUpdateInstallments('<?php echo $value; ?>')" class="validate-one-required-by-name" />
|
58 |
+
</label>
|
59 |
+
</li>
|
60 |
+
<?php
|
61 |
+
// fecha agrupamento de bandeiras
|
62 |
+
if(($i == $size - 1))
|
63 |
+
{
|
64 |
+
?>
|
65 |
+
</ul>
|
66 |
+
</li>
|
67 |
+
<?php
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
// dados do cartao
|
72 |
+
// somente mostrado em buy page loja
|
73 |
+
|
74 |
+
if($this->getConfigData('buypage') == "loja")
|
75 |
+
{
|
76 |
+
?>
|
77 |
+
<li>
|
78 |
+
<label for="cielo-cc-card-number" class="required"><em>*</em><?php echo $this->__('Card Number') ?></label><br />
|
79 |
+
<div class="input-box">
|
80 |
+
<input name="payment[cc_number]" type="text" value="" id="cielo-cc-card-number"
|
81 |
+
title="<?php echo $this->__('Card Number') ?>" class="input-text required-entry validate-cc-number"
|
82 |
+
maxlength="16" onkeydown="return denyNotNumberDc(this, event);" autocomplete="off" />
|
83 |
+
</div>
|
84 |
+
</li>
|
85 |
+
<li>
|
86 |
+
<label for="cielo-cc-security-code" class="required"><em>*</em><?php echo $this->__('Verification Code') ?></label><br />
|
87 |
+
<div class="input-box">
|
88 |
+
<input name="payment[cc_cid]" type="text" value="" id="cielo-cc-security-code" title="<?php echo $this->__('Verification Code') ?>" class="input-text required-entry" style="width: 50px;" maxlength="4" onkeydown="return denyNotNumberDc(this, event);"
|
89 |
+
autocomplete="off" />
|
90 |
+
</div>
|
91 |
+
</li>
|
92 |
+
<li>
|
93 |
+
<label for="cielo-cc-card_expiration-mh" class="required"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
|
94 |
+
<div class="input-box">
|
95 |
+
<div class="v-fix">
|
96 |
+
<select id="cielo-cc-card_expiration-mh" name="payment[cc_exp_month]" class="month required-entry" autocomplete="off">
|
97 |
+
<option value="" selected="selected"><?php echo $this->__('Month') ?></option>
|
98 |
+
<?php foreach($this->getMonths() as $month): ?>
|
99 |
+
<option value="<?php echo $month['num'] ?>"><?php echo $month['label'] ?></option>
|
100 |
+
<?php endforeach ?>
|
101 |
+
</select>
|
102 |
+
</div>
|
103 |
+
<div class="v-fix">
|
104 |
+
<select id="cielo-cc-card_expiration-yr" name="payment[cc_exp_year]" class="year required-entry" autocomplete="off">
|
105 |
+
<option value="" selected="selected"><?php echo $this->__('Year') ?></option>
|
106 |
+
<?php foreach($this->getYears() as $year): ?>
|
107 |
+
<option value="<?php echo $year['num'] ?>"><?php echo $year['label'] ?></option>
|
108 |
+
<?php endforeach ?>
|
109 |
+
</select>
|
110 |
+
</div>
|
111 |
+
</div>
|
112 |
+
<li>
|
113 |
+
<label for="cielo-cc-card_owner" class="required"><em>*</em><?php echo $this->__('Name on Card') ?></label>
|
114 |
+
<div class="input-box">
|
115 |
+
<input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="cielo-cc-card_owner" name="payment[cc_owner]" value="" autocomplete="off">
|
116 |
+
<input type="hidden" id="cielo-current-cc-type" value="" />
|
117 |
+
</div>
|
118 |
+
</li>
|
119 |
+
</li>
|
120 |
+
<?php
|
121 |
+
}
|
122 |
+
?>
|
123 |
+
<li>
|
124 |
+
<br />
|
125 |
+
<label for="cielo-installments" class="required"><em>*</em><?php echo $this->__('Installments') ?> </label>
|
126 |
+
<div class="input-box">
|
127 |
+
<select id="cielo-installments" name="payment[parcels_number]">
|
128 |
+
<?php foreach($this->getInstallments() as $parcel): ?>
|
129 |
+
<option value="<?php echo $parcel['num'] ?>"><?php echo $parcel['label'] ?></option>
|
130 |
+
<?php endforeach ?>
|
131 |
+
</select>
|
132 |
+
</div>
|
133 |
+
</li>
|
134 |
+
<br />
|
135 |
+
</ul>
|
136 |
+
</fieldset>
|
137 |
+
<script type="text/javascript">// <![CDATA[
|
138 |
+
|
139 |
+
function maximaCieloUpdateInstallments(cardType)
|
140 |
+
{
|
141 |
+
var installmentsField = document.getElementById('cielo-installments');
|
142 |
+
|
143 |
+
// monta array com maximo de parcelas x bandeira cartao
|
144 |
+
var installmentsArray = new Array();
|
145 |
+
<?php
|
146 |
+
|
147 |
+
$cardsMaxInstallments = $this->getMaxCardsInstallments();
|
148 |
+
|
149 |
+
foreach($cardsMaxInstallments as $card => $maxInstallments)
|
150 |
+
{
|
151 |
+
echo "installmentsArray." . $card . " = " . $maxInstallments . ";\n";
|
152 |
+
}
|
153 |
+
|
154 |
+
?>
|
155 |
+
|
156 |
+
// ajusta valor do campo
|
157 |
+
if(installmentsField.value > installmentsArray[cardType])
|
158 |
+
{
|
159 |
+
installmentsField.value = 1;
|
160 |
+
}
|
161 |
+
|
162 |
+
// ajusta opcoes mostradas
|
163 |
+
for(var i = 0; i < installmentsField.options.length; i++)
|
164 |
+
{
|
165 |
+
if(installmentsArray[cardType] < (i + 1))
|
166 |
+
{
|
167 |
+
installmentsField.options[i].style.display = "none";
|
168 |
+
}
|
169 |
+
else
|
170 |
+
{
|
171 |
+
installmentsField.options[i].style.display = "block";
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
// limpa o restante do formulario
|
176 |
+
cleanCcForm(cardType);
|
177 |
+
}
|
178 |
+
|
179 |
+
function denyNotNumberCc(field, event)
|
180 |
+
{
|
181 |
+
var keyCode = ('which' in event) ? event.which : event.keyCode;
|
182 |
+
|
183 |
+
// teclas backspace e delete
|
184 |
+
if(keyCode == 8 || keyCode == 46)
|
185 |
+
return true;
|
186 |
+
|
187 |
+
// tecla tab
|
188 |
+
if(keyCode == 9)
|
189 |
+
return true;
|
190 |
+
|
191 |
+
// teclas <- e ->
|
192 |
+
if(keyCode == 37 || keyCode == 39)
|
193 |
+
return true;
|
194 |
+
|
195 |
+
// teclas home e end
|
196 |
+
if(keyCode == 36 || keyCode == 35)
|
197 |
+
return true;
|
198 |
+
|
199 |
+
// teclas numericas
|
200 |
+
if((keyCode >= 48 && keyCode <= 57) || (keyCode >= 96 && keyCode <= 105))
|
201 |
+
return true;
|
202 |
+
|
203 |
+
return false;
|
204 |
+
}
|
205 |
+
|
206 |
+
function cleanCcForm(cardType)
|
207 |
+
{
|
208 |
+
<?php
|
209 |
+
if($this->getConfigData('buypage') == "loja")
|
210 |
+
{
|
211 |
+
?>
|
212 |
+
var currentCcType = document.getElementById('cielo-current-cc-type').value;
|
213 |
+
document.getElementById('cielo-current-cc-type').value = cardType;
|
214 |
+
|
215 |
+
if(currentCcType != cardType)
|
216 |
+
{
|
217 |
+
document.getElementById('cielo-cc-card-number').value = "";
|
218 |
+
document.getElementById('cielo-cc-security-code').value = "";
|
219 |
+
document.getElementById('cielo-cc-card_expiration-mh').value = "";
|
220 |
+
document.getElementById('cielo-cc-card_expiration-yr').value = "";
|
221 |
+
document.getElementById('cielo-cc-card_owner').value = "";
|
222 |
+
}
|
223 |
+
<?php
|
224 |
+
}
|
225 |
+
?>
|
226 |
+
}
|
227 |
+
|
228 |
// ]]></script>
|
app/design/frontend/default/default/template/cielo/form/dc.phtml
CHANGED
@@ -1,139 +1,178 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
?>
|
28 |
-
<fieldset class="form-list">
|
29 |
-
<ul id="payment_form_Maxima_Cielo_Dc" style="display:none;">
|
30 |
-
<br />
|
31 |
-
<?php
|
32 |
-
|
33 |
-
$cardsData = $this->getAllowedCards();
|
34 |
-
|
35 |
-
$size = count($cardsData);
|
36 |
-
|
37 |
-
for($i = 0; $i < $size; $i++)
|
38 |
-
{
|
39 |
-
$value = $cardsData[$i]['value'];
|
40 |
-
$label = $cardsData[$i]['label'];
|
41 |
-
$img = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . "frontend/default/default/images/cielo/" . $cardsData[$i]['image'];
|
42 |
-
|
43 |
-
// abre agrupamento de bandeiras
|
44 |
-
if($i % 3 == 0)
|
45 |
-
{
|
46 |
-
?>
|
47 |
-
<li class="first">
|
48 |
-
<ul class="card-logo">
|
49 |
-
<?php
|
50 |
-
}
|
51 |
-
|
52 |
-
// bandeira em questao
|
53 |
-
?>
|
54 |
-
<li style="width: 70px; float: left;">
|
55 |
-
<label for="card-<?php echo $value; ?>"><img src="<?php echo $img; ?>" style="width: 40px;" title="<?php echo $label; ?>" /><br>
|
56 |
-
<input name="payment[cc_type]" type="radio" value="<?php echo $value; ?>" id="card-<?php echo $value; ?>"
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
</
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
//
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
<
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
</
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
// ]]></script>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
?>
|
28 |
+
<fieldset class="form-list">
|
29 |
+
<ul id="payment_form_Maxima_Cielo_Dc" style="display:none;">
|
30 |
+
<br />
|
31 |
+
<?php
|
32 |
+
|
33 |
+
$cardsData = $this->getAllowedCards();
|
34 |
+
|
35 |
+
$size = count($cardsData);
|
36 |
+
|
37 |
+
for($i = 0; $i < $size; $i++)
|
38 |
+
{
|
39 |
+
$value = $cardsData[$i]['value'];
|
40 |
+
$label = $cardsData[$i]['label'];
|
41 |
+
$img = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . "frontend/default/default/images/cielo/" . $cardsData[$i]['image'];
|
42 |
+
|
43 |
+
// abre agrupamento de bandeiras
|
44 |
+
if($i % 3 == 0)
|
45 |
+
{
|
46 |
+
?>
|
47 |
+
<li class="first">
|
48 |
+
<ul class="card-logo">
|
49 |
+
<?php
|
50 |
+
}
|
51 |
+
|
52 |
+
// bandeira em questao
|
53 |
+
?>
|
54 |
+
<li style="width: 70px; float: left;">
|
55 |
+
<label for="card-<?php echo $value; ?>"><img src="<?php echo $img; ?>" style="width: 40px;" title="<?php echo $label; ?>" /><br>
|
56 |
+
<input name="payment[cc_type]" type="radio" value="<?php echo $value; ?>" id="card-<?php echo $value; ?>"
|
57 |
+
class="validate-one-required-by-name" onclick="cleanDcForm('<?php echo $value; ?>');" />
|
58 |
+
</label>
|
59 |
+
</li>
|
60 |
+
<?php
|
61 |
+
// fecha agrupamento de bandeiras
|
62 |
+
if(($i == $size - 1))
|
63 |
+
{
|
64 |
+
?>
|
65 |
+
</ul>
|
66 |
+
</li>
|
67 |
+
<?php
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
// dados do cartao
|
72 |
+
// somente mostrado em buy page loja
|
73 |
+
|
74 |
+
if($this->getConfigData('buypage') == "loja")
|
75 |
+
{
|
76 |
+
?>
|
77 |
+
<li>
|
78 |
+
<label for="cielo-dc-card-number" class="required"><em>*</em><?php echo $this->__('Card Number') ?></label><br />
|
79 |
+
<div class="input-box">
|
80 |
+
<input name="payment[cc_number]" type="text" value="" id="cielo-dc-card-number"
|
81 |
+
title="<?php echo $this->__('Card Number') ?>" class="input-text required-entry validate-cc-number"
|
82 |
+
maxlength="16" onkeydown="return denyNotNumberDc(this, event);" autocomplete="off" />
|
83 |
+
</div>
|
84 |
+
</li>
|
85 |
+
<li>
|
86 |
+
<label for="cielo-dc-security-code" class="required"><em>*</em><?php echo $this->__('Verification Code') ?></label><br />
|
87 |
+
<div class="input-box">
|
88 |
+
<input name="payment[cc_cid]" type="text" value="" id="cielo-dc-security-code"
|
89 |
+
title="<?php echo $this->__('Verification Code') ?>" class="input-text required-entry"
|
90 |
+
style="width: 50px;" maxlength="4" onkeydown="return denyNotNumberDc(this, event);" autocomplete="off" />
|
91 |
+
</div>
|
92 |
+
</li>
|
93 |
+
<li>
|
94 |
+
<label for="cielo-dc-card_expiration-mh" class="required"><em>*</em><?php echo $this->__('Expiration Date') ?></label>
|
95 |
+
<div class="input-box">
|
96 |
+
<div class="v-fix">
|
97 |
+
<select id="cielo-dc-card_expiration-mh" name="payment[cc_exp_month]" class="month required-entry" autocomplete="off">
|
98 |
+
<option value="" selected="selected"><?php echo $this->__('Month') ?></option>
|
99 |
+
<?php foreach($this->getMonths() as $month): ?>
|
100 |
+
<option value="<?php echo $month['num'] ?>"><?php echo $month['label'] ?></option>
|
101 |
+
<?php endforeach ?>
|
102 |
+
</select>
|
103 |
+
</div>
|
104 |
+
<div class="v-fix">
|
105 |
+
<select id="cielo-dc-card_expiration-yr" name="payment[cc_exp_year]" class="year required-entry" autocomplete="off">
|
106 |
+
<option value="" selected="selected"><?php echo $this->__('Year') ?></option>
|
107 |
+
<?php foreach($this->getYears() as $year): ?>
|
108 |
+
<option value="<?php echo $year['num'] ?>"><?php echo $year['label'] ?></option>
|
109 |
+
<?php endforeach ?>
|
110 |
+
</select>
|
111 |
+
</div>
|
112 |
+
</div>
|
113 |
+
<li>
|
114 |
+
<label for="cielo-dc-card_owner" class="required"><em>*</em><?php echo $this->__('Name on Card') ?></label>
|
115 |
+
<div class="input-box">
|
116 |
+
<input type="text" title="<?php echo $this->__('Name on Card') ?>" class="input-text required-entry" id="cielo-dc-card_owner" name="payment[cc_owner]" value="" autocomplete="off" />
|
117 |
+
<input type="hidden" id="cielo-current-dc-type" value="" />
|
118 |
+
</div>
|
119 |
+
</li>
|
120 |
+
</li>
|
121 |
+
<?php
|
122 |
+
}
|
123 |
+
?>
|
124 |
+
<br />
|
125 |
+
</ul>
|
126 |
+
</fieldset>
|
127 |
+
<script type="text/javascript">// <![CDATA[
|
128 |
+
|
129 |
+
function denyNotNumberDc(field, event)
|
130 |
+
{
|
131 |
+
var keyCode = ('which' in event) ? event.which : event.keyCode;
|
132 |
+
|
133 |
+
// teclas backspace e delete
|
134 |
+
if(keyCode == 8 || keyCode == 46)
|
135 |
+
return true;
|
136 |
+
|
137 |
+
// tecla tab
|
138 |
+
if(keyCode == 9)
|
139 |
+
return true;
|
140 |
+
|
141 |
+
// teclas <- e ->
|
142 |
+
if(keyCode == 37 || keyCode == 39)
|
143 |
+
return true;
|
144 |
+
|
145 |
+
// teclas home e end
|
146 |
+
if(keyCode == 36 || keyCode == 35)
|
147 |
+
return true;
|
148 |
+
|
149 |
+
// teclas numericas
|
150 |
+
if((keyCode >= 48 && keyCode <= 57) || (keyCode >= 96 && keyCode <= 105))
|
151 |
+
return true;
|
152 |
+
|
153 |
+
return false;
|
154 |
+
}
|
155 |
+
|
156 |
+
function cleanDcForm(cardType)
|
157 |
+
{
|
158 |
+
<?php
|
159 |
+
if($this->getConfigData('buypage') == "loja")
|
160 |
+
{
|
161 |
+
?>
|
162 |
+
var currentCcType = document.getElementById('cielo-current-dc-type').value;
|
163 |
+
document.getElementById('cielo-current-dc-type').value = cardType;
|
164 |
+
|
165 |
+
if(currentCcType != cardType)
|
166 |
+
{
|
167 |
+
document.getElementById('cielo-dc-card-number').value = "";
|
168 |
+
document.getElementById('cielo-dc-security-code').value = "";
|
169 |
+
document.getElementById('cielo-dc-card_expiration-mh').value = "";
|
170 |
+
document.getElementById('cielo-dc-card_expiration-yr').value = "";
|
171 |
+
document.getElementById('cielo-dc-card_owner').value = "";
|
172 |
+
}
|
173 |
+
<?php
|
174 |
+
}
|
175 |
+
?>
|
176 |
+
}
|
177 |
+
|
178 |
// ]]></script>
|
app/design/frontend/default/default/template/cielo/info/cc.phtml
CHANGED
@@ -1,63 +1,63 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
?>
|
28 |
-
Cartão de Crédito Cielo
|
29 |
-
<br /><br />
|
30 |
-
<?php
|
31 |
-
|
32 |
-
|
33 |
-
if($_info = $this->getInfo())
|
34 |
-
{
|
35 |
-
if($_info->getOrder())
|
36 |
-
{
|
37 |
-
$payment = $_info->getOrder()->getPayment();
|
38 |
-
|
39 |
-
if($payment->getAdditionalInformation ('Cielo_error'))
|
40 |
-
{
|
41 |
-
echo "Erro na transação";
|
42 |
-
}
|
43 |
-
else
|
44 |
-
{
|
45 |
-
$tid = $payment->getAdditionalInformation ('Cielo_tid');
|
46 |
-
$status = $payment->getAdditionalInformation ('Cielo_status');
|
47 |
-
$cardType = $payment->getAdditionalInformation ('Cielo_cardType');
|
48 |
-
$installments = $payment->getAdditionalInformation ('Cielo_installments');
|
49 |
-
|
50 |
-
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toArray();
|
51 |
-
$cardType = $allCards[$cardType];
|
52 |
-
$installments = ($installments == 1) ? 'À vista' : $installments . " vezes";
|
53 |
-
|
54 |
-
$html = "<b>ID Transação</b>: " . $tid . "<br />";
|
55 |
-
$html .= "<b>Status</b>: " . Mage::helper('Maxima_Cielo')->getStatusMessage($status) . "<br />";
|
56 |
-
$html .= "<b>Bandeira</b>: " . $cardType . "<br />";
|
57 |
-
$html .= "<b>Parcelamento</b>: " . $installments;
|
58 |
-
|
59 |
-
echo $html;
|
60 |
-
}
|
61 |
-
}
|
62 |
-
}
|
63 |
-
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
?>
|
28 |
+
Cartão de Crédito Cielo
|
29 |
+
<br /><br />
|
30 |
+
<?php
|
31 |
+
|
32 |
+
|
33 |
+
if($_info = $this->getInfo())
|
34 |
+
{
|
35 |
+
if($_info->getOrder())
|
36 |
+
{
|
37 |
+
$payment = $_info->getOrder()->getPayment();
|
38 |
+
|
39 |
+
if($payment->getAdditionalInformation ('Cielo_error'))
|
40 |
+
{
|
41 |
+
echo "Erro na transação";
|
42 |
+
}
|
43 |
+
else
|
44 |
+
{
|
45 |
+
$tid = $payment->getAdditionalInformation ('Cielo_tid');
|
46 |
+
$status = $payment->getAdditionalInformation ('Cielo_status');
|
47 |
+
$cardType = $payment->getAdditionalInformation ('Cielo_cardType');
|
48 |
+
$installments = $payment->getAdditionalInformation ('Cielo_installments');
|
49 |
+
|
50 |
+
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toArray();
|
51 |
+
$cardType = $allCards[$cardType];
|
52 |
+
$installments = ($installments == 1) ? 'À vista' : $installments . " vezes";
|
53 |
+
|
54 |
+
$html = "<b>ID Transação</b>: " . $tid . "<br />";
|
55 |
+
$html .= "<b>Status</b>: " . Mage::helper('Maxima_Cielo')->getStatusMessage($status) . "<br />";
|
56 |
+
$html .= "<b>Bandeira</b>: " . $cardType . "<br />";
|
57 |
+
$html .= "<b>Parcelamento</b>: " . $installments;
|
58 |
+
|
59 |
+
echo $html;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
}
|
63 |
+
?>
|
app/design/frontend/default/default/template/cielo/info/dc.phtml
CHANGED
@@ -1,62 +1,62 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
-
* the billing forms with a Cielo's gateway Web Service.
|
6 |
-
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
-
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
-
*
|
9 |
-
* Contact: lawsann@gmail.com
|
10 |
-
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
-
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
-
*
|
13 |
-
* This program is free software: you can redistribute it and/or modify
|
14 |
-
* it under the terms of the GNU General Public License as published by
|
15 |
-
* the Free Software Foundation, either version 3 of the License, or
|
16 |
-
* (at your option) any later version.
|
17 |
-
*
|
18 |
-
* This program is distributed in the hope that it will be useful,
|
19 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
-
* GNU General Public License for more details.
|
22 |
-
*
|
23 |
-
* You should have received a copy of the GNU General Public License
|
24 |
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
-
*/
|
26 |
-
|
27 |
-
?>
|
28 |
-
Cartão de Débito Cielo
|
29 |
-
<br /><br />
|
30 |
-
<?php
|
31 |
-
|
32 |
-
|
33 |
-
if($_info = $this->getInfo())
|
34 |
-
{
|
35 |
-
if($_info->getOrder())
|
36 |
-
{
|
37 |
-
$payment = $_info->getOrder()->getPayment();
|
38 |
-
|
39 |
-
if($payment->getAdditionalInformation ('Cielo_error'))
|
40 |
-
{
|
41 |
-
echo "Erro na transação";
|
42 |
-
}
|
43 |
-
else
|
44 |
-
{
|
45 |
-
$tid = $payment->getAdditionalInformation ('Cielo_tid');
|
46 |
-
$status = $payment->getAdditionalInformation ('Cielo_status');
|
47 |
-
$cardType = $payment->getAdditionalInformation ('Cielo_cardType');
|
48 |
-
$installments = $payment->getAdditionalInformation ('Cielo_installments');
|
49 |
-
|
50 |
-
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toArray();
|
51 |
-
$cardType = $allCards[$cardType];
|
52 |
-
$installments = ($installments == 1) ? 'À vista' : $installments . " vezes";
|
53 |
-
|
54 |
-
$html = "<b>ID Transação</b>: " . $tid . "<br />";
|
55 |
-
$html .= "<b>Status</b>: " . Mage::helper('Maxima_Cielo')->getStatusMessage($status) . "<br />";
|
56 |
-
$html .= "<b>Bandeira</b>: " . $cardType;
|
57 |
-
|
58 |
-
echo $html;
|
59 |
-
}
|
60 |
-
}
|
61 |
-
}
|
62 |
?>
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/*
|
4 |
+
* Maxima Cielo Module - payment method module for Magento, integrating
|
5 |
+
* the billing forms with a Cielo's gateway Web Service.
|
6 |
+
* Copyright (C) 2012 Fillipe Almeida Dutra
|
7 |
+
* Belo Horizonte, Minas Gerais - Brazil
|
8 |
+
*
|
9 |
+
* Contact: lawsann@gmail.com
|
10 |
+
* Project link: http://code.google.com/p/magento-maxima-cielo/
|
11 |
+
* Group discussion: http://groups.google.com/group/cielo-magento
|
12 |
+
*
|
13 |
+
* This program is free software: you can redistribute it and/or modify
|
14 |
+
* it under the terms of the GNU General Public License as published by
|
15 |
+
* the Free Software Foundation, either version 3 of the License, or
|
16 |
+
* (at your option) any later version.
|
17 |
+
*
|
18 |
+
* This program is distributed in the hope that it will be useful,
|
19 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
* GNU General Public License for more details.
|
22 |
+
*
|
23 |
+
* You should have received a copy of the GNU General Public License
|
24 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
+
*/
|
26 |
+
|
27 |
+
?>
|
28 |
+
Cartão de Débito Cielo
|
29 |
+
<br /><br />
|
30 |
+
<?php
|
31 |
+
|
32 |
+
|
33 |
+
if($_info = $this->getInfo())
|
34 |
+
{
|
35 |
+
if($_info->getOrder())
|
36 |
+
{
|
37 |
+
$payment = $_info->getOrder()->getPayment();
|
38 |
+
|
39 |
+
if($payment->getAdditionalInformation ('Cielo_error'))
|
40 |
+
{
|
41 |
+
echo "Erro na transação";
|
42 |
+
}
|
43 |
+
else
|
44 |
+
{
|
45 |
+
$tid = $payment->getAdditionalInformation ('Cielo_tid');
|
46 |
+
$status = $payment->getAdditionalInformation ('Cielo_status');
|
47 |
+
$cardType = $payment->getAdditionalInformation ('Cielo_cardType');
|
48 |
+
$installments = $payment->getAdditionalInformation ('Cielo_installments');
|
49 |
+
|
50 |
+
$allCards = Mage::getModel('Maxima_Cielo/cc_types')->toArray();
|
51 |
+
$cardType = $allCards[$cardType];
|
52 |
+
$installments = ($installments == 1) ? 'À vista' : $installments . " vezes";
|
53 |
+
|
54 |
+
$html = "<b>ID Transação</b>: " . $tid . "<br />";
|
55 |
+
$html .= "<b>Status</b>: " . Mage::helper('Maxima_Cielo')->getStatusMessage($status) . "<br />";
|
56 |
+
$html .= "<b>Bandeira</b>: " . $cardType;
|
57 |
+
|
58 |
+
echo $html;
|
59 |
+
}
|
60 |
+
}
|
61 |
+
}
|
62 |
?>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Maxima_Cielo</name>
|
4 |
-
<version>1.5.
|
5 |
<stability>stable</stability>
|
6 |
<license>GPL</license>
|
7 |
<channel>community</channel>
|
@@ -14,9 +14,9 @@ Habilita pagamentos com cartão de crédito e débito. São acei
|
|
14 |
O módulo foi desenvolvido por Fillipe Almeida Dutra e testado junto aos utilizadores da comunidade brasileira de Magento.</description>
|
15 |
<notes>Testado nas verões 1.4 e superiores do Magento Community Edition.</notes>
|
16 |
<authors><author><name>Fillipe Almeida Dutra</name><user>lawsann</user><email>lawsann@gmail.com</email></author></authors>
|
17 |
-
<date>2012-10-
|
18 |
-
<time>
|
19 |
-
<contents><target name="magecommunity"><dir name="Maxima"><dir name="Cielo"><dir name="Block"><dir name="Adminhtml"><dir name="Order"><dir name="Invoice"><file name="Totals.php" hash="fac7909671ed73fa52b5843996998f7b"/></dir><file name="Totals.php" hash="ab7f4d158554ebe0e550b32a249058fa"/><file name="View.php" hash="
|
20 |
<compatible/>
|
21 |
<dependencies><required><php><min>5.0.0</min><max>5.4.7</max></php></required></dependencies>
|
22 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Maxima_Cielo</name>
|
4 |
+
<version>1.5.1</version>
|
5 |
<stability>stable</stability>
|
6 |
<license>GPL</license>
|
7 |
<channel>community</channel>
|
14 |
O módulo foi desenvolvido por Fillipe Almeida Dutra e testado junto aos utilizadores da comunidade brasileira de Magento.</description>
|
15 |
<notes>Testado nas verões 1.4 e superiores do Magento Community Edition.</notes>
|
16 |
<authors><author><name>Fillipe Almeida Dutra</name><user>lawsann</user><email>lawsann@gmail.com</email></author></authors>
|
17 |
+
<date>2012-10-15</date>
|
18 |
+
<time>14:01:56</time>
|
19 |
+
<contents><target name="magecommunity"><dir name="Maxima"><dir name="Cielo"><dir name="Block"><dir name="Adminhtml"><dir name="Order"><dir name="Invoice"><file name="Totals.php" hash="fac7909671ed73fa52b5843996998f7b"/></dir><file name="Totals.php" hash="ab7f4d158554ebe0e550b32a249058fa"/><file name="View.php" hash="207766547bd07f97e7dcb9661f83fea8"/></dir></dir><dir name="Form"><file name="Cc.php" hash="19868c2c84967b827e9cde298d9985ed"/><file name="Dc.php" hash="82be855db90140bf841c7a6b71afb0e5"/></dir><dir name="Info"><file name="Cc.php" hash="41586896cd9b0c652226afa15ddc07e4"/><file name="Dc.php" hash="bcc7d0eca2241b8720e6b9dc5b292eeb"/></dir><dir name="Sales"><dir name="Order"><file name="Totals.php" hash="d878200b6122dc3631ddb083cd432342"/></dir></dir><file name="Verify.php" hash="664bbb607431c20e41beaf134db4db50"/></dir><dir name="Helper"><file name="Data.php" hash="595ea404c400f8497fb72f7331a64d7b"/></dir><dir name="Model"><dir name="Adminhtml"><file name="BuyPage.php" hash="342e8bf44d413a445dcacc8b376c3cc0"/><file name="CardTypes.php" hash="1696a0ccf67c7904f98ccb5c2efc161e"/><file name="Environment.php" hash="ec4a2d2a46211e4fbf95f345b3b1052a"/></dir><dir name="Cc"><file name="InstallmentType.php" hash="313d57dca6f735b572fea2d7c984fc02"/><file name="MaxInstallments.php" hash="93fb137fe2af02d687d87e890cdd85ca"/><file name="Types.php" hash="041ccaaac8e85e8fbaf638c1d83c0ef3"/></dir><file name="Cc.php" hash="c4948de0ccfbc346362cb9ad5f270dfd"/><dir name="Dc"><file name="Types.php" hash="1457aadf53f4d3c80d23fd93bb6fee56"/></dir><file name="Dc.php" hash="70afddce0b0a9999bd5bd3f4194c648e"/><dir name="Order"><dir name="Invoice"><file name="Interest.php" hash="11e962528edf565b4406a075db7ea378"/></dir></dir><dir name="Quote"><dir name="Address"><file name="Interest.php" hash="c69a5a04d209ba2ca892b10d80969184"/></dir></dir><file name="WebServiceOrder.php" hash="0c495fff26e3b34a8baa4e563c2c2ccd"/></dir><dir name="controllers"><file name="AdminController.php" hash="7d6aa753b8810f96abc457dc6fa4e843"/><file name="PayController.php" hash="dcfe2921b2753fef20cc052cfd26c7a7"/></dir><dir name="etc"><file name="config.xml" hash="93439858442b12d59d07212bd03640c1"/><file name="system.xml" hash="fcc087ff1ac8b6ea8956fbe0f3ae6b30"/></dir><dir name="sql"><dir name="Maxima_Cielo_setup"><file name="mysql4-upgrade-1.0.1-1.1.0.php" hash="9bd53e35cc207dc9a360fcc681c8b254"/></dir></dir><dir name="ssl"><file name="VeriSignClass3PublicPrimaryCertificationAuthority-G5.crt" hash="6b5a035d28d43fe4977d1c46cb2a8b39"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Maxima_Cielo.xml" hash="00a3004d5beb73433796c5403860e213"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="cielo"><dir name="info"><file name="cc.phtml" hash="dc56957720585e2c2e69f2b6678d9454"/><file name="dc.phtml" hash="88eb317bc308178e0f266e936df7a492"/></dir></dir></dir></dir></dir></dir><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="cielo"><file name="failure.phtml" hash="6d6d4b84a77282db9ca31a1f605063ed"/><dir name="form"><file name="cc.phtml" hash="b2073cab6b932810c4a697c5b7696403"/><file name="dc.phtml" hash="cc09b58343b5e0fce4c9600fb80f06c5"/></dir><dir name="info"><file name="cc.phtml" hash="7a4e98abf31deba321f279a9a697b28c"/><file name="dc.phtml" hash="b33096d20724e073815700da90bb94bd"/></dir><file name="success.phtml" hash="20c2db462b509a8421396e18886b3748"/></dir></dir><dir name="layout"><file name="cielo.xml" hash="1c1bd75b9b3a4b7d8c870d7f1736c106"/></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="default"><dir name="default"><dir name="images"><dir name="cielo"><file name="Amex.png" hash="34cf5f947ce582e8cafbc2f7ad3819d7"/><file name="Diners.png" hash="85745410a56fae7438ee731c7c61bcbd"/><file name="Discover.png" hash="c15f20d619d498ca0106d86bd1315aa7"/><file name="Elo.png" hash="fac91b0c17c3f0c21830934c091ae288"/><file name="Master-maestro.png" hash="36f46a64478e57d032e250a7ea57b7dd"/><file name="Master.png" hash="c34cfa7178ad74a5988f20d002d96da5"/><file name="Visa-Electron.png" hash="6f7106bec98706ab13c8ffd91edac9fa"/><file name="Visa.png" hash="61cebb52052e510837ac9292f5421bff"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><dir name="cielo"><dir name="window"><file name="bottom_left.png" hash="8dc6008d2ab38fdb20037d70f256a669"/><file name="bottom_right.png" hash="e95738920909e6a6efff2f8993433c0b"/><file name="close.png" hash="ecd60c76155c81f292269effe55455bd"/><file name="header.png" hash="7844dbe18eea13be882075ea6b9ca896"/><file name="top_left.png" hash="5ec9623ada46737745c8a5462e464e07"/><file name="top_right.png" hash="1c334c616db562dbcd3377aaf3696872"/></dir></dir></dir></dir></dir></dir></target></contents>
|
20 |
<compatible/>
|
21 |
<dependencies><required><php><min>5.0.0</min><max>5.4.7</max></php></required></dependencies>
|
22 |
</package>
|