Version Notes
- Code improvements
- Improvements in javascript
- Successful page specific to MercadoPago
- API Cupom
- LOGS (Backend and Javascript)
Download this release
Release Info
Developer | Developers MercadoPago Brasil |
Extension | MercadoPagoTransparent |
Version | 0.0.3 |
Comparing to | |
See all releases |
Code changes from version 0.0.2 to 0.0.3
- app/code/community/MercadoPago/.DS_Store +0 -0
- app/code/community/MercadoPago/{Transparent/Block → Block/Custom}/Form.php +7 -17
- app/code/community/MercadoPago/{TransparentTicket/Block → Block/Custom}/Info.php +10 -9
- app/code/community/MercadoPago/Block/Customticket/Form.php +69 -0
- app/code/community/MercadoPago/Block/Customticket/Info.php +38 -0
- app/code/community/MercadoPago/{Transparent/Helper/Data.php → Block/Discount.php} +7 -3
- app/code/community/MercadoPago/{Standard/Block → Block/Standard}/Form.php +3 -10
- app/code/community/MercadoPago/{Standard/Block → Block/Standard}/Info.php +19 -15
- app/code/community/MercadoPago/{TransparentTicket/Helper/Data.php → Block/Standard/Pay.php} +8 -3
- app/code/community/MercadoPago/Block/Success.php +74 -0
- app/code/community/MercadoPago/{Transparent/Block/Info.php → Helper/Data.php} +13 -17
- app/code/community/MercadoPago/Model/Core.php +314 -0
- app/code/community/MercadoPago/Model/Custom/Payment.php +436 -0
- app/code/community/MercadoPago/Model/CustomTicket/Payment.php +82 -0
- app/code/community/MercadoPago/Model/Observer.php +146 -0
- app/code/community/MercadoPago/Model/Source/CategoryId.php +48 -0
- app/code/community/MercadoPago/Model/Source/Country.php +32 -0
- app/code/community/MercadoPago/{Standard/Model → Model}/Source/Installments.php +5 -1
- app/code/community/MercadoPago/Model/Source/PaymentMethods.php +45 -0
- app/code/community/MercadoPago/{Standard/Model → Model}/Source/TypeCheckout.php +8 -8
- app/code/community/MercadoPago/Model/Standard/Payment.php +298 -0
- app/code/community/MercadoPago/Standard/Helper/Data.php +0 -22
- app/code/community/MercadoPago/Standard/Model/Checkout.php +0 -250
- app/code/community/MercadoPago/Standard/Model/Observer.php +0 -107
- app/code/community/MercadoPago/Standard/Model/Source/CategoryId.php +0 -44
- app/code/community/MercadoPago/Standard/Model/Source/Country.php +0 -32
- app/code/community/MercadoPago/Standard/Model/Source/PaymentMethods.php +0 -41
- app/code/community/MercadoPago/Standard/controllers/NotificationController.php +0 -190
- app/code/community/MercadoPago/Standard/controllers/PayController.php +0 -64
- app/code/community/MercadoPago/Standard/etc/system.xml +0 -256
- app/code/community/MercadoPago/Transparent/.DS_Store +0 -0
- app/code/community/MercadoPago/Transparent/Block/.DS_Store +0 -0
- app/code/community/MercadoPago/Transparent/Block/Success.php +0 -36
- app/code/community/MercadoPago/Transparent/Model/.DS_Store +0 -0
- app/code/community/MercadoPago/Transparent/Model/Resource/Setup.php +0 -14
- app/code/community/MercadoPago/Transparent/Model/Source/CategoryId.php +0 -44
- app/code/community/MercadoPago/Transparent/Model/Transparent.php +0 -393
- app/code/community/MercadoPago/Transparent/controllers/NotificacaoController.php +0 -190
- app/code/community/MercadoPago/Transparent/controllers/PayController.php +0 -194
- app/code/community/MercadoPago/Transparent/etc/config.xml +0 -103
- app/code/community/MercadoPago/Transparent/etc/system.xml +0 -81
- app/code/community/MercadoPago/TransparentTicket/Block/Form.php +0 -50
- app/code/community/MercadoPago/TransparentTicket/Model/Transparent.php +0 -86
- app/code/community/MercadoPago/TransparentTicket/etc/config.xml +0 -103
- app/code/community/MercadoPago/TransparentTicket/etc/system.xml +0 -74
- app/code/community/MercadoPago/controllers/ApiController.php +81 -0
- app/code/community/MercadoPago/controllers/NotificationsController.php +347 -0
- app/code/community/MercadoPago/controllers/PayController.php +43 -0
- app/code/community/MercadoPago/controllers/SuccessController.php +37 -0
- app/code/community/MercadoPago/{Standard/etc → etc}/config.xml +72 -21
- app/code/community/MercadoPago/etc/system.xml +403 -0
- app/design/adminhtml/default/default/template/mercadopago/custom/info.phtml +9 -0
- app/design/adminhtml/default/default/template/mercadopago/custom_ticket/info.phtml +23 -0
- app/design/adminhtml/default/default/template/mercadopago/standard/info.phtml +7 -27
- app/design/adminhtml/default/default/template/mercadopago/transparent/info.phtml +0 -33
- app/design/adminhtml/default/default/template/mercadopago/transparent_boleto/info.phtml +0 -13
- app/design/adminhtml/default/default/template/mercadopago/transparent_ticket/info.phtml +0 -15
- app/design/frontend/base/default/layout/mercadopago.xml +0 -9
- app/design/frontend/base/default/template/mercadopago/{clean_page.phtml → clean.phtml} +1 -1
- app/design/frontend/base/default/template/mercadopago/{transparent → custom}/form.phtml +48 -35
- app/design/frontend/base/default/template/mercadopago/custom/info.phtml +14 -0
- app/design/frontend/base/default/template/mercadopago/custom_ticket/form.phtml +61 -0
- app/design/frontend/base/default/template/mercadopago/custom_ticket/info.phtml +34 -0
- app/design/frontend/base/default/template/mercadopago/discount.phtml +47 -0
- app/design/frontend/base/default/template/mercadopago/standard/form.phtml +1 -1
- app/design/frontend/base/default/template/mercadopago/standard/info.phtml +7 -29
- app/design/frontend/base/default/template/mercadopago/standard/pay.phtml +60 -50
- app/design/frontend/base/default/template/mercadopago/success.phtml +135 -0
- app/design/frontend/base/default/template/mercadopago/transparent/info.phtml +0 -33
- app/design/frontend/base/default/template/mercadopago/transparent/success.phtml +0 -229
- app/design/frontend/base/default/template/mercadopago/transparent/sucesso.phtml +0 -103
- app/design/frontend/base/default/template/mercadopago/transparent_boleto/form.phtml +0 -20
- app/design/frontend/base/default/template/mercadopago/transparent_boleto/info.phtml +0 -23
- app/design/frontend/base/default/template/mercadopago/transparent_ticket/form.phtml +0 -31
- app/design/frontend/base/default/template/mercadopago/transparent_ticket/info.phtml +0 -27
- app/etc/modules/{MercadoPago_Standard.xml → MercadoPago.xml} +2 -2
- app/etc/modules/MercadoPago_Transparent.xml +0 -9
- app/etc/modules/MercadoPago_TransparentTicket.xml +0 -9
- app/locale/es_AR/mercadopago.csv +13 -4
- app/locale/es_CO/mercadopago.csv +13 -5
- app/locale/es_ES/mercadopago.csv +122 -41
- app/locale/es_MX/mercadopago.csv +13 -5
- app/locale/pt_BR/mercadopago.csv +150 -0
- js/mercadopago/mercadopago.js +361 -92
- lib/mercadopago/mercadopago.php +146 -35
- package.xml +11 -7
- skin/frontend/base/default/mercadopago/.DS_Store +0 -0
- skin/frontend/base/default/mercadopago/css/style.css +67 -0
app/code/community/MercadoPago/.DS_Store
DELETED
Binary file
|
app/code/community/MercadoPago/{Transparent/Block → Block/Custom}/Form.php
RENAMED
@@ -15,22 +15,17 @@
|
|
15 |
*/
|
16 |
|
17 |
|
18 |
-
class
|
19 |
|
20 |
protected function _construct(){
|
21 |
-
|
22 |
-
// Route: /checkout/onepage
|
23 |
-
// inicia formulario para a escolha de pagamento
|
24 |
parent::_construct();
|
25 |
-
|
26 |
-
$this->setTemplate('mercadopago/transparent/form.phtml');
|
27 |
-
|
28 |
}
|
29 |
|
30 |
protected function _prepareLayout(){
|
31 |
|
32 |
//pega public key para settar no aquivo mercadopago.js
|
33 |
-
$model = Mage::getModel('
|
34 |
$public_key = $model->getConfigData('public_key');
|
35 |
|
36 |
//init js no header
|
@@ -38,7 +33,7 @@ class MercadoPago_Transparent_Block_Form extends Mage_Payment_Block_Form_Cc{
|
|
38 |
$block->setText(
|
39 |
sprintf(
|
40 |
'
|
41 |
-
<script type="text/javascript">var PublicKeyMercadoPagoTransparent = "' . $public_key
|
42 |
<script type="text/javascript" src="%s"></script>',
|
43 |
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS, true) . 'mercadopago/mercadopago.js'
|
44 |
)
|
@@ -55,18 +50,18 @@ class MercadoPago_Transparent_Block_Form extends Mage_Payment_Block_Form_Cc{
|
|
55 |
|
56 |
/*
|
57 |
*
|
58 |
-
*
|
59 |
*
|
60 |
*/
|
61 |
function getCardsPaymentMethods(){
|
62 |
-
$payment_methods = Mage::getModel('
|
63 |
$payment_methods_types = array("credit_card", "debit_card", "prepaid_card");
|
64 |
$types = array();
|
65 |
|
66 |
//percorre todos os payments methods
|
67 |
foreach($payment_methods['response'] as $pm){
|
68 |
|
69 |
-
//filtra por
|
70 |
if(in_array($pm['payment_type_id'], $payment_methods_types)){
|
71 |
$types[] = $pm;
|
72 |
}
|
@@ -75,8 +70,3 @@ class MercadoPago_Transparent_Block_Form extends Mage_Payment_Block_Form_Cc{
|
|
75 |
return $types;
|
76 |
}
|
77 |
}
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
?>
|
15 |
*/
|
16 |
|
17 |
|
18 |
+
class MercadoPago_Block_Custom_Form extends Mage_Payment_Block_Form_Cc{
|
19 |
|
20 |
protected function _construct(){
|
|
|
|
|
|
|
21 |
parent::_construct();
|
22 |
+
$this->setTemplate('mercadopago/custom/form.phtml');
|
|
|
|
|
23 |
}
|
24 |
|
25 |
protected function _prepareLayout(){
|
26 |
|
27 |
//pega public key para settar no aquivo mercadopago.js
|
28 |
+
$model = Mage::getModel('mercadopago/custom_payment');
|
29 |
$public_key = $model->getConfigData('public_key');
|
30 |
|
31 |
//init js no header
|
33 |
$block->setText(
|
34 |
sprintf(
|
35 |
'
|
36 |
+
<script type="text/javascript">var PublicKeyMercadoPagoTransparent = "' . $public_key .'";</script>
|
37 |
<script type="text/javascript" src="%s"></script>',
|
38 |
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS, true) . 'mercadopago/mercadopago.js'
|
39 |
)
|
50 |
|
51 |
/*
|
52 |
*
|
53 |
+
* fun��o especifica para mexico
|
54 |
*
|
55 |
*/
|
56 |
function getCardsPaymentMethods(){
|
57 |
+
$payment_methods = Mage::getModel('mercadopago/core')->getPaymentMethods();
|
58 |
$payment_methods_types = array("credit_card", "debit_card", "prepaid_card");
|
59 |
$types = array();
|
60 |
|
61 |
//percorre todos os payments methods
|
62 |
foreach($payment_methods['response'] as $pm){
|
63 |
|
64 |
+
//filtra por payment_methods
|
65 |
if(in_array($pm['payment_type_id'], $payment_methods_types)){
|
66 |
$types[] = $pm;
|
67 |
}
|
70 |
return $types;
|
71 |
}
|
72 |
}
|
|
|
|
|
|
|
|
|
|
app/code/community/MercadoPago/{TransparentTicket/Block → Block/Custom}/Info.php
RENAMED
@@ -15,22 +15,23 @@
|
|
15 |
*/
|
16 |
|
17 |
|
18 |
-
class
|
19 |
|
20 |
protected function _construct(){
|
21 |
-
|
22 |
-
// Route: /checkout/onepage
|
23 |
-
// inicia formulario para a escolha de pagamento
|
24 |
-
|
25 |
parent::_construct();
|
26 |
-
|
27 |
$this->setModuleName('Mage_Payment');
|
28 |
}
|
29 |
|
30 |
-
|
31 |
public function getOrder() {
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
}
|
36 |
}
|
15 |
*/
|
16 |
|
17 |
|
18 |
+
class MercadoPago_Block_Custom_Info extends Mage_Payment_Block_Info_Cc{
|
19 |
|
20 |
protected function _construct(){
|
|
|
|
|
|
|
|
|
21 |
parent::_construct();
|
22 |
+
$this->setTemplate('mercadopago/custom/info.phtml');
|
23 |
$this->setModuleName('Mage_Payment');
|
24 |
}
|
25 |
|
|
|
26 |
public function getOrder() {
|
27 |
+
return $this->getInfo();
|
28 |
+
}
|
29 |
|
30 |
+
public function getInfoPayment(){
|
31 |
+
|
32 |
+
$order_id = $this->getInfo()->getOrder()->getIncrementId();
|
33 |
+
$info_payments = Mage::getModel('mercadopago/core')->getInfoPaymentByOrder($order_id);
|
34 |
+
|
35 |
+
return $info_payments;
|
36 |
}
|
37 |
}
|
app/code/community/MercadoPago/Block/Customticket/Form.php
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
|
18 |
+
class MercadoPago_Block_Customticket_Form extends Mage_Payment_Block_Form_Cc{
|
19 |
+
|
20 |
+
protected function _construct(){
|
21 |
+
|
22 |
+
parent::_construct();
|
23 |
+
|
24 |
+
$this->setTemplate('mercadopago/custom_ticket/form.phtml');
|
25 |
+
|
26 |
+
}
|
27 |
+
|
28 |
+
protected function _prepareLayout(){
|
29 |
+
|
30 |
+
//pega public key para settar no aquivo mercadopago.js
|
31 |
+
$model = Mage::getModel('mercadopago/custom_payment');
|
32 |
+
$public_key = $model->getConfigData('public_key');
|
33 |
+
|
34 |
+
//init js no header
|
35 |
+
$block = Mage::app()->getLayout()->createBlock('core/text', 'js_mercadopago');
|
36 |
+
$block->setText(
|
37 |
+
sprintf(
|
38 |
+
'
|
39 |
+
<script type="text/javascript">var PublicKeyMercadoPagoTransparent = "' . $public_key .'";</script>
|
40 |
+
<script type="text/javascript" src="%s"></script>',
|
41 |
+
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS, true) . 'mercadopago/mercadopago.js'
|
42 |
+
)
|
43 |
+
);
|
44 |
+
|
45 |
+
$head = Mage::app()->getLayout()->getBlock('after_body_start');
|
46 |
+
|
47 |
+
if($head){
|
48 |
+
$head->append($block);
|
49 |
+
}
|
50 |
+
|
51 |
+
return parent::_prepareLayout();
|
52 |
+
}
|
53 |
+
|
54 |
+
function getTicketsOptions(){
|
55 |
+
$payment_methods = Mage::getModel('mercadopago/core')->getPaymentMethods();
|
56 |
+
$tickets = array();
|
57 |
+
|
58 |
+
//percorre todos os payments methods
|
59 |
+
foreach($payment_methods['response'] as $pm){
|
60 |
+
|
61 |
+
//filtra por tickets
|
62 |
+
if($pm['payment_type_id'] == "ticket"){
|
63 |
+
$tickets[] = $pm;
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
return $tickets;
|
68 |
+
}
|
69 |
+
}
|
app/code/community/MercadoPago/Block/Customticket/Info.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
|
18 |
+
class MercadoPago_Block_CustomTicket_Info extends Mage_Payment_Block_Info_Cc{
|
19 |
+
|
20 |
+
protected function _construct(){
|
21 |
+
parent::_construct();
|
22 |
+
$this->setTemplate('mercadopago/custom_ticket/info.phtml');
|
23 |
+
$this->setModuleName('Mage_Payment');
|
24 |
+
}
|
25 |
+
|
26 |
+
|
27 |
+
public function getOrder() {
|
28 |
+
return $this->getInfo();
|
29 |
+
}
|
30 |
+
|
31 |
+
public function getInfoPayment(){
|
32 |
+
|
33 |
+
$order_id = $this->getInfo()->getOrder()->getIncrementId();
|
34 |
+
$info_payments = Mage::getModel('mercadopago/core')->getInfoPaymentByOrder($order_id);
|
35 |
+
|
36 |
+
return $info_payments;
|
37 |
+
}
|
38 |
+
}
|
app/code/community/MercadoPago/{Transparent/Helper/Data.php → Block/Discount.php}
RENAMED
@@ -13,10 +13,14 @@
|
|
13 |
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
*/
|
16 |
-
?>
|
17 |
-
<?php
|
18 |
|
19 |
|
20 |
-
class
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
}
|
13 |
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
*/
|
|
|
|
|
16 |
|
17 |
|
18 |
+
class MercadoPago_Block_Discount extends Mage_Core_Block_Template{
|
19 |
|
20 |
+
protected function _construct(){
|
21 |
+
|
22 |
+
parent::_construct();
|
23 |
+
$this->setTemplate('mercadopago/discount.phtml');
|
24 |
+
|
25 |
+
}
|
26 |
}
|
app/code/community/MercadoPago/{Standard/Block → Block/Standard}/Form.php
RENAMED
@@ -15,20 +15,13 @@
|
|
15 |
*/
|
16 |
|
17 |
|
18 |
-
class
|
19 |
|
20 |
protected function _construct(){
|
21 |
-
|
22 |
-
// Route: /checkout/onepage
|
23 |
-
// inicia formulario para a escolha de pagamento
|
24 |
parent::_construct();
|
25 |
|
26 |
$this->setTemplate('mercadopago/standard/form.phtml');
|
27 |
|
28 |
}
|
29 |
-
}
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
?>
|
15 |
*/
|
16 |
|
17 |
|
18 |
+
class MercadoPago_Block_Standard_Form extends Mage_Payment_Block_Form_Cc{
|
19 |
|
20 |
protected function _construct(){
|
21 |
+
|
|
|
|
|
22 |
parent::_construct();
|
23 |
|
24 |
$this->setTemplate('mercadopago/standard/form.phtml');
|
25 |
|
26 |
}
|
27 |
+
}
|
|
|
|
|
|
|
|
|
|
app/code/community/MercadoPago/{Standard/Block → Block/Standard}/Info.php
RENAMED
@@ -15,22 +15,26 @@
|
|
15 |
*/
|
16 |
|
17 |
|
18 |
-
class
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
parent::_construct();
|
26 |
-
$this->setTemplate('mercadopago/standard/info.phtml');
|
27 |
-
$this->setModuleName('Mage_Payment');
|
28 |
-
}
|
29 |
-
|
30 |
-
|
31 |
-
public function getOrder() {
|
32 |
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
}
|
36 |
}
|
15 |
*/
|
16 |
|
17 |
|
18 |
+
class MercadoPago_Block_Standard_Info extends Mage_Payment_Block_Info_Cc{
|
19 |
|
20 |
+
protected function _construct(){
|
21 |
+
parent::_construct();
|
22 |
+
$this->setTemplate('mercadopago/standard/info.phtml');
|
23 |
+
$this->setModuleName('Mage_Payment');
|
24 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
|
27 |
+
public function getOrder() {
|
28 |
+
|
29 |
+
return $this->getInfo();
|
30 |
+
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getInfoPayment(){
|
34 |
+
|
35 |
+
$order_id = $this->getInfo()->getOrder()->getIncrementId();
|
36 |
+
$info_payments = Mage::getModel('mercadopago/core')->getInfoPaymentByOrder($order_id);
|
37 |
+
|
38 |
+
return $info_payments;
|
39 |
}
|
40 |
}
|
app/code/community/MercadoPago/{TransparentTicket/Helper/Data.php → Block/Standard/Pay.php}
RENAMED
@@ -13,10 +13,15 @@
|
|
13 |
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
*/
|
16 |
-
?>
|
17 |
-
<?php
|
18 |
|
19 |
|
20 |
-
class
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
}
|
13 |
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
*/
|
|
|
|
|
16 |
|
17 |
|
18 |
+
class MercadoPago_Block_Standard_Pay extends Mage_Core_Block_Template{
|
19 |
|
20 |
+
protected function _construct(){
|
21 |
+
|
22 |
+
parent::_construct();
|
23 |
+
|
24 |
+
$this->setTemplate('mercadopago/standard/pay.phtml');
|
25 |
+
|
26 |
+
}
|
27 |
}
|
app/code/community/MercadoPago/Block/Success.php
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
|
18 |
+
class MercadoPago_Block_Success extends Mage_Core_Block_Template{
|
19 |
+
|
20 |
+
protected function _construct(){
|
21 |
+
|
22 |
+
parent::_construct();
|
23 |
+
$this->setTemplate('mercadopago/success.phtml');
|
24 |
+
|
25 |
+
}
|
26 |
+
|
27 |
+
public function getOrder() {
|
28 |
+
$orderIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
|
29 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
|
30 |
+
return $order;
|
31 |
+
}
|
32 |
+
|
33 |
+
public function getPayment(){
|
34 |
+
$order = $this->getOrder();
|
35 |
+
$payment = $order->getPayment();
|
36 |
+
return $payment;
|
37 |
+
}
|
38 |
+
|
39 |
+
public function getTotal(){
|
40 |
+
$order = $this->getOrder();
|
41 |
+
$total = $order->getBaseGrandTotal();
|
42 |
+
|
43 |
+
if (!$total) {
|
44 |
+
$total = $order->getBasePrice() + $order->getBaseShippingAmount();
|
45 |
+
}
|
46 |
+
|
47 |
+
$total = number_format($total, 2, '.', '');
|
48 |
+
|
49 |
+
return $total;
|
50 |
+
}
|
51 |
+
|
52 |
+
public function getEntityId(){
|
53 |
+
$order = $this->getOrder();
|
54 |
+
|
55 |
+
return $order->getEntityId();
|
56 |
+
}
|
57 |
+
|
58 |
+
public function getPaymentMethod(){
|
59 |
+
$payment_method = $this->getPayment()->getMethodInstance()->getCode();
|
60 |
+
|
61 |
+
return $payment_method;
|
62 |
+
}
|
63 |
+
|
64 |
+
public function getInfoPayment(){
|
65 |
+
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
|
66 |
+
$info_payments = Mage::getModel('mercadopago/core')->getInfoPaymentByOrder($order_id);
|
67 |
+
|
68 |
+
return $info_payments;
|
69 |
+
}
|
70 |
+
|
71 |
+
public function getMessageByStatus($status, $status_detail, $payment_method, $amount, $installment){
|
72 |
+
return Mage::getModel('mercadopago/core')->getMessageByStatus($status, $status_detail, $payment_method, $amount, $installment);
|
73 |
+
}
|
74 |
+
}
|
app/code/community/MercadoPago/{Transparent/Block/Info.php → Helper/Data.php}
RENAMED
@@ -14,23 +14,19 @@
|
|
14 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
*/
|
16 |
|
17 |
-
|
18 |
-
class MercadoPago_Transparent_Block_Info extends Mage_Payment_Block_Info_Cc{
|
19 |
|
20 |
-
protected function _construct(){
|
21 |
-
|
22 |
-
// Route: /checkout/onepage
|
23 |
-
// inicia formulario para a escolha de pagamento
|
24 |
-
|
25 |
-
parent::_construct();
|
26 |
-
$this->setTemplate('mercadopago/transparent/info.phtml');
|
27 |
-
$this->setModuleName('Mage_Payment');
|
28 |
-
}
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
return $this->getInfo();
|
34 |
-
|
35 |
-
}
|
36 |
-
}
|
14 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
*/
|
16 |
|
17 |
+
class MercadoPago_Helper_Data extends Mage_Payment_Helper_Data{
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
public function log($message, $file = "mercadopago.log", $array = null){
|
21 |
+
//pega a configuração de log no admin, essa variavel vem como true por padrão
|
22 |
+
$action_log = Mage::getStoreConfig('payment/mercadopago/logs');
|
23 |
+
|
24 |
+
//caso tenha um array, transforma em json para melhor visualização
|
25 |
+
if(!is_null($array))
|
26 |
+
$message .= " - " . json_encode($array);
|
27 |
+
|
28 |
+
//set log
|
29 |
+
Mage::log($message, null, $file, $action_log);
|
30 |
+
}
|
31 |
|
32 |
+
}
|
|
|
|
|
|
|
|
|
|
app/code/community/MercadoPago/Model/Core.php
ADDED
@@ -0,0 +1,314 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
+
|
19 |
+
class MercadoPago_Model_Core extends Mage_Payment_Model_Method_Abstract{
|
20 |
+
|
21 |
+
|
22 |
+
protected $_code = 'mercadopago';
|
23 |
+
|
24 |
+
protected $_isGateway = true;
|
25 |
+
protected $_canOrder = true;
|
26 |
+
protected $_canAuthorize = true;
|
27 |
+
protected $_canCapture = true;
|
28 |
+
protected $_canCapturePartial = true;
|
29 |
+
protected $_canRefund = true;
|
30 |
+
protected $_canRefundInvoicePartial = true;
|
31 |
+
protected $_canVoid = true;
|
32 |
+
protected $_canUseInternal = true;
|
33 |
+
protected $_canUseCheckout = true;
|
34 |
+
protected $_canUseForMultishipping = true;
|
35 |
+
protected $_canFetchTransactionInfo = true;
|
36 |
+
protected $_canCreateBillingAgreement = true;
|
37 |
+
protected $_canReviewPayment = true;
|
38 |
+
|
39 |
+
|
40 |
+
/**
|
41 |
+
* @return Mage_Checkout_Model_Session
|
42 |
+
*/
|
43 |
+
protected function _getCheckout() {
|
44 |
+
return Mage::getSingleton('checkout/session');
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Get admin checkout session namespace
|
49 |
+
*
|
50 |
+
* @return Mage_Adminhtml_Model_Session_Quote
|
51 |
+
*/
|
52 |
+
protected function _getAdminCheckout() {
|
53 |
+
return Mage::getSingleton('adminhtml/session_quote');
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Retrieves Quote
|
58 |
+
*
|
59 |
+
* @param integer $quoteId
|
60 |
+
* @return Mage_Sales_Model_Quote
|
61 |
+
*/
|
62 |
+
protected function _getQuote($quoteId = null) {
|
63 |
+
if (!empty($quoteId)) {
|
64 |
+
return Mage::getModel('sales/quote')->load($quoteId);
|
65 |
+
}
|
66 |
+
else {
|
67 |
+
if(Mage::app()->getStore()->isAdmin()) {
|
68 |
+
return $this->_getAdminCheckout()->getQuote();
|
69 |
+
} else {
|
70 |
+
return $this->_getCheckout()->getQuote();
|
71 |
+
}
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Retrieves Order
|
77 |
+
*
|
78 |
+
* @param integer $incrementId
|
79 |
+
* @return Mage_Sales_Model_Order
|
80 |
+
*/
|
81 |
+
protected function _getOrder($incrementId) {
|
82 |
+
return Mage::getModel('sales/order')->loadByIncrementId($incrementId);
|
83 |
+
}
|
84 |
+
|
85 |
+
public function getInfoPaymentByOrder($order_id){
|
86 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
|
87 |
+
$payment = $order->getPayment();
|
88 |
+
$info_payments = array();
|
89 |
+
$fields = array(
|
90 |
+
array("field" => "cardholderName", "title" => "Card Holder Name: %s"),
|
91 |
+
array("field" => "trunc_card", "title" => "Card Number: %s"),
|
92 |
+
array("field" => "payment_method", "title" => "Payment Method: %s"),
|
93 |
+
array("field" => "expiration_date", "title" => "Expiration Date: %s"),
|
94 |
+
array("field" => "installments", "title" => "Installments: %s"),
|
95 |
+
array("field" => "statement_descriptor", "title" => "Statement Descriptor: %s"),
|
96 |
+
array("field" => "payment_id", "title" => "Payment id (MercadoPago): %s"),
|
97 |
+
array("field" => "status", "title" => "Payment Status: %s"),
|
98 |
+
array("field" => "status_detail", "title" => "Payment Detail: %s"),
|
99 |
+
array("field" => "activation_uri", "title" => "Generate Ticket")
|
100 |
+
);
|
101 |
+
|
102 |
+
foreach($fields as $field):
|
103 |
+
if($payment->getAdditionalInformation($field['field']) != ""):
|
104 |
+
$text = Mage::helper('mercadopago')->__($field['title'], $payment->getAdditionalInformation($field['field']));
|
105 |
+
$info_payments[$field['field']] = array(
|
106 |
+
"text" => $text,
|
107 |
+
"value" => $payment->getAdditionalInformation($field['field'])
|
108 |
+
);
|
109 |
+
endif;
|
110 |
+
endforeach;
|
111 |
+
|
112 |
+
return $info_payments;
|
113 |
+
}
|
114 |
+
|
115 |
+
protected function validStatusTwoPayments($status){
|
116 |
+
$array_status = explode(" | ", $status);
|
117 |
+
$status_verif = true;
|
118 |
+
$status_final = "";
|
119 |
+
foreach($array_status as $status):
|
120 |
+
|
121 |
+
if($status_final == ""){
|
122 |
+
$status_final = $status;
|
123 |
+
}else{
|
124 |
+
if($status_final != $status){
|
125 |
+
$status_verif = false;
|
126 |
+
}
|
127 |
+
}
|
128 |
+
endforeach;
|
129 |
+
|
130 |
+
if($status_verif === false){
|
131 |
+
$status_final = "other";
|
132 |
+
}
|
133 |
+
|
134 |
+
return $status_final;
|
135 |
+
}
|
136 |
+
|
137 |
+
public function getMessageByStatus($status, $status_detail, $payment_method, $installment, $amount){
|
138 |
+
$status = $this->validStatusTwoPayments($status);
|
139 |
+
$status_detail = $this->validStatusTwoPayments($status_detail);
|
140 |
+
|
141 |
+
$message = array(
|
142 |
+
"title" => "",
|
143 |
+
"message" => ""
|
144 |
+
);
|
145 |
+
|
146 |
+
|
147 |
+
switch ($status){
|
148 |
+
case "approved":
|
149 |
+
$message['title'] = Mage::helper('mercadopago')->__('Done, your payment was accredited!');
|
150 |
+
break;
|
151 |
+
|
152 |
+
case "in_process":
|
153 |
+
$message['title'] = Mage::helper('mercadopago')->__('We are processing the payment.');
|
154 |
+
$message['message'] = Mage::helper('mercadopago')->__('In less than 2 business days we will tell you by e-mail if it is accredited or if we need more information.');
|
155 |
+
break;
|
156 |
+
|
157 |
+
case 'authorized':
|
158 |
+
case "pending":
|
159 |
+
$message['title'] = Mage::helper('mercadopago')->__('We are processing the payment.');
|
160 |
+
$message['message'] = Mage::helper('mercadopago')->__('In less than an hour we will send you by e-mail the result.');
|
161 |
+
break;
|
162 |
+
|
163 |
+
case "rejected":
|
164 |
+
$message['title'] = Mage::helper('mercadopago')->__('We could not process your payment.');
|
165 |
+
|
166 |
+
switch ($status_detail){
|
167 |
+
case "cc_rejected_bad_filled_card_number":
|
168 |
+
$message['message'] = Mage::helper('mercadopago')->__('Check the card number.');
|
169 |
+
break;
|
170 |
+
|
171 |
+
case "cc_rejected_bad_filled_date":
|
172 |
+
$message['message'] = Mage::helper('mercadopago')->__('Check the expiration date.');
|
173 |
+
break;
|
174 |
+
|
175 |
+
case "cc_rejected_bad_filled_other":
|
176 |
+
$message['message'] = Mage::helper('mercadopago')->__('Check the data.');
|
177 |
+
break;
|
178 |
+
|
179 |
+
case "cc_rejected_bad_filled_security_code":
|
180 |
+
$message['message'] = Mage::helper('mercadopago')->__('Check the security code.');
|
181 |
+
break;
|
182 |
+
|
183 |
+
case "cc_rejected_blacklist":
|
184 |
+
$message['message'] = Mage::helper('mercadopago')->__('We could not process your payment.');
|
185 |
+
break;
|
186 |
+
|
187 |
+
case "cc_rejected_call_for_authorize":
|
188 |
+
$message['message'] = Mage::helper('mercadopago')->__('You must authorize to %s the payment of $ %s to MercadoPago.', strtoupper($payment_method), strtoupper($amount));
|
189 |
+
break;
|
190 |
+
|
191 |
+
case "cc_rejected_card_disabled":
|
192 |
+
$message['message'] = Mage::helper('mercadopago')->__('Call %s to activate your card.<br/>The phone is on the back of your card.', strtoupper($payment_method));
|
193 |
+
break;
|
194 |
+
|
195 |
+
case "cc_rejected_card_error":
|
196 |
+
$message['message'] = Mage::helper('mercadopago')->__('We could not process your payment.');
|
197 |
+
break;
|
198 |
+
|
199 |
+
case "cc_rejected_duplicated_payment":
|
200 |
+
$message['message'] = Mage::helper('mercadopago')->__('You already made a payment by that value.<br/>If you need to repay, use another card or other payment method.');
|
201 |
+
break;
|
202 |
+
|
203 |
+
case "cc_rejected_high_risk":
|
204 |
+
$message['message'] = Mage::helper('mercadopago')->__('Your payment was rejected.<br/>Choose another payment method, we recommend cash methods.');
|
205 |
+
break;
|
206 |
+
|
207 |
+
case "cc_rejected_insufficient_amount":
|
208 |
+
$message['message'] = Mage::helper('mercadopago')->__('Your %s do not have sufficient funds.', strtoupper($payment_method));
|
209 |
+
break;
|
210 |
+
|
211 |
+
case "cc_rejected_invalid_installments":
|
212 |
+
$message['message'] = Mage::helper('mercadopago')->__('%s does not process payments in %s installments.', strtoupper($payment_method), $installment);
|
213 |
+
break;
|
214 |
+
|
215 |
+
case "cc_rejected_max_attempts":
|
216 |
+
$message['message'] = Mage::helper('mercadopago')->__('You have got to the limit of allowed attempts.<br/>Choose another card or another payment method.');
|
217 |
+
break;
|
218 |
+
|
219 |
+
case "cc_rejected_other_reason":
|
220 |
+
$message['message'] = Mage::helper('mercadopago')->__('%s did not process the payment.', strtoupper($payment_method));
|
221 |
+
break;
|
222 |
+
|
223 |
+
}
|
224 |
+
|
225 |
+
break;
|
226 |
+
case "cancelled":
|
227 |
+
$message['title'] = Mage::helper('mercadopago')->__('Payments were canceled.');
|
228 |
+
$message['message'] = Mage::helper('mercadopago')->__('Contact for more information.');
|
229 |
+
break;
|
230 |
+
case "other":
|
231 |
+
$message['title'] = Mage::helper('mercadopago')->__('Thank you for your purchase!');
|
232 |
+
break;
|
233 |
+
}
|
234 |
+
|
235 |
+
return $message;
|
236 |
+
}
|
237 |
+
|
238 |
+
public function getPayment($payment_id){
|
239 |
+
$model = $this;
|
240 |
+
$this->client_id = Mage::getStoreConfig('payment/mercadopago/client_id');
|
241 |
+
$this->client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret');
|
242 |
+
$mp = new MP($this->client_id, $this->client_secret);
|
243 |
+
return $mp->get_payment($payment_id);
|
244 |
+
}
|
245 |
+
|
246 |
+
public function getMerchantOrder($merchant_order_id){
|
247 |
+
$model = $this;
|
248 |
+
$this->client_id = Mage::getStoreConfig('payment/mercadopago/client_id');
|
249 |
+
$this->client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret');
|
250 |
+
$mp = new MP($this->client_id, $this->client_secret);
|
251 |
+
|
252 |
+
return $mp->get("/merchant_orders/" . $merchant_order_id);
|
253 |
+
}
|
254 |
+
|
255 |
+
public function getPaymentMethods(){
|
256 |
+
$this->client_id = Mage::getStoreConfig('payment/mercadopago/client_id');
|
257 |
+
$this->client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret');
|
258 |
+
|
259 |
+
$mp = new MP ($this->client_id, $this->client_secret);
|
260 |
+
|
261 |
+
$payment_methods = $mp->get("/v1/payment_methods");
|
262 |
+
|
263 |
+
return $payment_methods;
|
264 |
+
}
|
265 |
+
|
266 |
+
public function getEmailCustomer(){
|
267 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
268 |
+
$email = $customer->getEmail();
|
269 |
+
|
270 |
+
if($email == ""){
|
271 |
+
$order = $this->_getOrder();
|
272 |
+
$email = $order['customer_email'];
|
273 |
+
}
|
274 |
+
|
275 |
+
return $email;
|
276 |
+
}
|
277 |
+
|
278 |
+
|
279 |
+
public function getAmount(){
|
280 |
+
$quote = $this->_getQuote();
|
281 |
+
$total = $quote->getBaseGrandTotal();
|
282 |
+
|
283 |
+
//caso o valor seja null setta um valor 0
|
284 |
+
if(is_null($total))
|
285 |
+
$total = 0;
|
286 |
+
|
287 |
+
return (float) $total;
|
288 |
+
}
|
289 |
+
|
290 |
+
public function validCoupon($id){
|
291 |
+
|
292 |
+
$this->client_id = Mage::getStoreConfig('payment/mercadopago/client_id');
|
293 |
+
$this->client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret');
|
294 |
+
|
295 |
+
$mp = new MP ($this->client_id, $this->client_secret);
|
296 |
+
|
297 |
+
$params = array(
|
298 |
+
"transaction_amount" => $this->getAmount(),
|
299 |
+
"payer_email" => $this->getEmailCustomer(),
|
300 |
+
"coupon_code" => $id
|
301 |
+
);
|
302 |
+
|
303 |
+
$details_discount = $mp->get("/discount_campaigns", $params);
|
304 |
+
|
305 |
+
//add value on return api discount
|
306 |
+
$details_discount['response']['transaction_amount'] = $params['transaction_amount'];
|
307 |
+
$details_discount['response']['params'] = $params;
|
308 |
+
|
309 |
+
|
310 |
+
return $details_discount;
|
311 |
+
|
312 |
+
}
|
313 |
+
|
314 |
+
}
|
app/code/community/MercadoPago/Model/Custom/Payment.php
ADDED
@@ -0,0 +1,436 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
+
|
19 |
+
class MercadoPago_Model_Custom_Payment extends Mage_Payment_Model_Method_Abstract{
|
20 |
+
|
21 |
+
//configura o block do formulario e de informações sobre o pagamento
|
22 |
+
protected $_formBlockType = 'mercadopago/custom_form';
|
23 |
+
protected $_infoBlockType = 'mercadopago/custom_info';
|
24 |
+
|
25 |
+
protected $_code = 'mercadopago_custom';
|
26 |
+
|
27 |
+
protected $_canSaveCc = false;
|
28 |
+
protected $_isGateway = true;
|
29 |
+
protected $_canAuthorize = true;
|
30 |
+
protected $_canCapture = true;
|
31 |
+
protected $_canVoid = true;
|
32 |
+
protected $_canCancelInvoice = true;
|
33 |
+
protected $_isInitializeNeeded = true;
|
34 |
+
protected $_canFetchTransactionInfo = true;
|
35 |
+
protected $_canCreateBillingAgreement = true;
|
36 |
+
protected $_canReviewPayment = true;
|
37 |
+
|
38 |
+
public function initialize($paymentAction, $stateObject) {
|
39 |
+
|
40 |
+
//verifica se o pagamento não é boleto, caso seja não tem card_token_id
|
41 |
+
if($this->getInfoInstance()->getAdditionalInformation('payment_type_id') != "ticket" && $this->getInfoInstance()->getAdditionalInformation('card_token_id') == ""):
|
42 |
+
Mage::throwException(Mage::helper('mercadopago')->__('Verify the form data or wait until the validation of the payment data'));
|
43 |
+
return false;
|
44 |
+
endif;
|
45 |
+
|
46 |
+
|
47 |
+
//continua o processo de pagamento
|
48 |
+
$response = $this->postPago();
|
49 |
+
|
50 |
+
if($response !== false):
|
51 |
+
|
52 |
+
$payment = $response['response'];
|
53 |
+
|
54 |
+
//set order_id
|
55 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($payment['external_reference']);
|
56 |
+
|
57 |
+
//set status
|
58 |
+
$this->getInfoInstance()->setAdditionalInformation('status', $payment['status']);
|
59 |
+
$this->getInfoInstance()->setAdditionalInformation('status_detail', $payment['status_detail']);
|
60 |
+
|
61 |
+
return true;
|
62 |
+
endif;
|
63 |
+
|
64 |
+
return false;
|
65 |
+
}
|
66 |
+
|
67 |
+
public function assignData($data){
|
68 |
+
|
69 |
+
// route /checkout/onepage/savePayment
|
70 |
+
if(!($data instanceof Varien_Object)){
|
71 |
+
$data = new Varien_Object($data);
|
72 |
+
}
|
73 |
+
|
74 |
+
//get array info
|
75 |
+
$info_form = $data->getData();
|
76 |
+
|
77 |
+
$info = $this->getInfoInstance();
|
78 |
+
$info->setAdditionalInformation('payment_type_id', "credit_card");
|
79 |
+
$info->setAdditionalInformation('card_token_id', $info_form['card_token_id']);
|
80 |
+
$info->setAdditionalInformation('payment_method', $info_form['payment_method']);
|
81 |
+
$info->setAdditionalInformation('installments', $info_form['installments']);
|
82 |
+
$info->setAdditionalInformation('doc_number', $info_form['doc_number']);
|
83 |
+
|
84 |
+
//caso tenha banco, adiciona nas informações adicionais
|
85 |
+
if(isset($info_form['issuers'])){
|
86 |
+
$info->setAdditionalInformation('issuers', $info_form['issuers']);
|
87 |
+
}
|
88 |
+
|
89 |
+
if(isset($info_form['coupon_code'])){
|
90 |
+
$info->setAdditionalInformation('coupon_code', $info_form['coupon_code']);
|
91 |
+
}
|
92 |
+
|
93 |
+
if($info_form['card_token_id'] != ""):
|
94 |
+
$info->setAdditionalInformation('expiration_date', $info_form['cardExpirationMonth'] . "/" . $info_form['cardExpirationYear']);
|
95 |
+
$info->setAdditionalInformation('cardholderName', $info_form['cardholderName']);
|
96 |
+
$info->setAdditionalInformation('trunc_card', $info_form['trunc_card']);
|
97 |
+
endif;
|
98 |
+
|
99 |
+
|
100 |
+
//caso seja não tenha card_token_id
|
101 |
+
/*if($info_form['card_token_id'] == ""):
|
102 |
+
Mage::throwException(Mage::helper('mercadopago')->__('Verify the form data or wait until the validation of the payment data'));
|
103 |
+
return false;
|
104 |
+
endif;*/
|
105 |
+
|
106 |
+
|
107 |
+
return $this;
|
108 |
+
}
|
109 |
+
|
110 |
+
public function getOrderPlaceRedirectUrl() {
|
111 |
+
// requisicao vem da pagina de finalizacao de pedido
|
112 |
+
return Mage::getUrl('mercadopago/success', array('_secure' => true));
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* @return Mage_Checkout_Model_Session
|
117 |
+
*/
|
118 |
+
protected function _getCheckout() {
|
119 |
+
return Mage::getSingleton('checkout/session');
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Get admin checkout session namespace
|
124 |
+
*
|
125 |
+
* @return Mage_Adminhtml_Model_Session_Quote
|
126 |
+
*/
|
127 |
+
protected function _getAdminCheckout() {
|
128 |
+
return Mage::getSingleton('adminhtml/session_quote');
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Retrieves Quote
|
133 |
+
*
|
134 |
+
* @param integer $quoteId
|
135 |
+
* @return Mage_Sales_Model_Quote
|
136 |
+
*/
|
137 |
+
protected function _getQuote($quoteId = null) {
|
138 |
+
if (!empty($quoteId)) {
|
139 |
+
return Mage::getModel('sales/quote')->load($quoteId);
|
140 |
+
}
|
141 |
+
else {
|
142 |
+
if(Mage::app()->getStore()->isAdmin()) {
|
143 |
+
return $this->_getAdminCheckout()->getQuote();
|
144 |
+
} else {
|
145 |
+
return $this->_getCheckout()->getQuote();
|
146 |
+
}
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Retrieves Order
|
152 |
+
*
|
153 |
+
* @param integer $incrementId
|
154 |
+
* @return Mage_Sales_Model_Order
|
155 |
+
*/
|
156 |
+
protected function _getOrder($incrementId) {
|
157 |
+
return Mage::getModel('sales/order')->loadByIncrementId($incrementId);
|
158 |
+
}
|
159 |
+
|
160 |
+
public function getDiscount(){
|
161 |
+
$discount = 0;
|
162 |
+
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
|
163 |
+
|
164 |
+
if(isset($totals['discount']) && $totals['discount']->getValue()) {
|
165 |
+
$discount = $totals['discount']->getValue();
|
166 |
+
}
|
167 |
+
|
168 |
+
return $discount;
|
169 |
+
}
|
170 |
+
|
171 |
+
public function postPago(){
|
172 |
+
Mage::helper('mercadopago')->log("init post pago", 'mercadopago-custom.log');
|
173 |
+
$core = Mage::getModel('mercadopago/core');
|
174 |
+
|
175 |
+
//seta sdk php mercadopago
|
176 |
+
$client_id = Mage::getStoreConfig('payment/mercadopago/client_id');
|
177 |
+
$client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret');
|
178 |
+
|
179 |
+
$mp = new MP($client_id, $client_secret);
|
180 |
+
|
181 |
+
//monta a preferencia
|
182 |
+
$pref = $this->makePreference();
|
183 |
+
Mage::helper('mercadopago')->log("make array", 'mercadopago-custom.log', $pref);
|
184 |
+
|
185 |
+
//faz o post do pagamento
|
186 |
+
$response = $mp->create_custon_payment($pref);
|
187 |
+
Mage::helper('mercadopago')->log("post pago", 'mercadopago-custom.log', $response);
|
188 |
+
|
189 |
+
if($response['status'] == 200 || $response['status'] == 201):
|
190 |
+
return $response;
|
191 |
+
else:
|
192 |
+
$e = "";
|
193 |
+
foreach($response['response']['cause'] as $error):
|
194 |
+
switch ($error['code']) {
|
195 |
+
case "106":
|
196 |
+
$e .= Mage::helper('mercadopago')->__('You can not make payments to users in other countries.');
|
197 |
+
break;
|
198 |
+
|
199 |
+
case "109":
|
200 |
+
$e .= Mage::helper('mercadopago')->__('Payment Method selected does not process payments in installments selected. Choose another card or another payment method.');
|
201 |
+
break;
|
202 |
+
|
203 |
+
case "126":
|
204 |
+
$e .= Mage::helper('mercadopago')->__('We could not process your payment. Error code: 126.');
|
205 |
+
break;
|
206 |
+
|
207 |
+
case "129":
|
208 |
+
$e .= Mage::helper('mercadopago')->__('Payment Method selected does not process payments for the selected amount. Choose another card or another payment method.');
|
209 |
+
break;
|
210 |
+
|
211 |
+
case "137":
|
212 |
+
$e .= Mage::helper('mercadopago')->__('The amount is required.');
|
213 |
+
break;
|
214 |
+
|
215 |
+
case "145":
|
216 |
+
$e .= Mage::helper('mercadopago')->__('We could not process your payment. Error code: 145.');
|
217 |
+
break;
|
218 |
+
|
219 |
+
case "150":
|
220 |
+
$e .= Mage::helper('mercadopago')->__('You can not make payments. Error code: 150.');
|
221 |
+
break;
|
222 |
+
|
223 |
+
case "151":
|
224 |
+
$e .= Mage::helper('mercadopago')->__('You can not make payments.');
|
225 |
+
break;
|
226 |
+
|
227 |
+
case "160":
|
228 |
+
$e .= Mage::helper('mercadopago')->__('We could not process your payment. Error code: 160.');
|
229 |
+
break;
|
230 |
+
|
231 |
+
case "204":
|
232 |
+
$e .= Mage::helper('mercadopago')->__('Payment Method selected is not available at this time. Choose another card or another payment method.');
|
233 |
+
break;
|
234 |
+
|
235 |
+
case "801":
|
236 |
+
$e .= Mage::helper('mercadopago')->__('You made a similar payment moments ago. Try again in a few minutes.');
|
237 |
+
break;
|
238 |
+
|
239 |
+
//validacao do coupon
|
240 |
+
case "campaign_code_doesnt_match":
|
241 |
+
$e .= Mage::helper('mercadopago')->__("Doesn't find a campaign with the given code.");
|
242 |
+
break;
|
243 |
+
|
244 |
+
default:
|
245 |
+
$e .= Mage::helper('mercadopago')->__("We could not process your payment. %s", json_encode($response));
|
246 |
+
break;
|
247 |
+
}
|
248 |
+
|
249 |
+
endforeach;
|
250 |
+
Mage::helper('mercadopago')->log("erro post pago: " . $e, 'mercadopago-custom.log');
|
251 |
+
Mage::helper('mercadopago')->log("response post pago: ", 'mercadopago-custom.log', $response);
|
252 |
+
Mage::throwException($e);
|
253 |
+
return false;
|
254 |
+
endif;
|
255 |
+
|
256 |
+
}
|
257 |
+
|
258 |
+
function makePreference(){
|
259 |
+
|
260 |
+
$core = Mage::getModel('mercadopago/core');
|
261 |
+
$quote = $this->_getQuote();
|
262 |
+
$orderId = $quote->getReservedOrderId();
|
263 |
+
$order = $this->_getOrder($orderId);
|
264 |
+
|
265 |
+
|
266 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
267 |
+
$model = Mage::getModel('catalog/product');
|
268 |
+
|
269 |
+
|
270 |
+
//pega payment dentro da order para pegar as informacoes adicionadas pela funcao assignData()
|
271 |
+
$payment = $order->getPayment();
|
272 |
+
|
273 |
+
//pega valor total da compra
|
274 |
+
$item_price = $order->getBaseGrandTotal();
|
275 |
+
if (!$item_price) {
|
276 |
+
$item_price = $order->getBasePrice() + $order->getBaseShippingAmount();
|
277 |
+
}
|
278 |
+
|
279 |
+
//pega o valor total da compra somando o frete
|
280 |
+
$item_price = number_format($item_price, 2, '.', '');
|
281 |
+
|
282 |
+
//setta informaçnoes
|
283 |
+
$arr = array();
|
284 |
+
$arr['external_reference'] = $orderId;
|
285 |
+
$arr['amount'] = (float) $item_price;
|
286 |
+
$arr['reason'] = Mage::helper('mercadopago')->__("Order # %s in store %s", $orderId, Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK,true));
|
287 |
+
//não é necessario settar currency_id, pois ja identifica no backend
|
288 |
+
//$arr['currency_id'] = "BRL";
|
289 |
+
$arr['installments'] = (int) $payment->getAdditionalInformation("installments");
|
290 |
+
$arr['payment_method_id'] = $payment->getAdditionalInformation("payment_method");
|
291 |
+
$arr['payer_email'] = htmlentities($customer->getEmail());
|
292 |
+
|
293 |
+
if($payment->getAdditionalInformation("card_token_id") != ""){
|
294 |
+
$arr['card_token_id'] = $payment->getAdditionalInformation("card_token_id");
|
295 |
+
}
|
296 |
+
|
297 |
+
if($payment->getAdditionalInformation("issuers") != ""){
|
298 |
+
$arr['card_issuer_id'] = (int) $payment->getAdditionalInformation("issuers");
|
299 |
+
}
|
300 |
+
|
301 |
+
//monta array de produtos
|
302 |
+
$arr['items'] = array();
|
303 |
+
foreach ($order->getAllVisibleItems() as $item) {
|
304 |
+
|
305 |
+
$prod = $model->loadByAttribute('sku', $item->getSku());
|
306 |
+
|
307 |
+
//get image
|
308 |
+
try{
|
309 |
+
$imagem = $prod->getImageUrl();
|
310 |
+
}catch(Exception $e){
|
311 |
+
$imagem = "";
|
312 |
+
}
|
313 |
+
|
314 |
+
$arr['items'][] = array(
|
315 |
+
"id" => $item->getSku(),
|
316 |
+
"title" => $item->getName(),
|
317 |
+
"description" => $item->getName(),
|
318 |
+
"picture_url" => $imagem,
|
319 |
+
"category_id" => Mage::getStoreConfig('payment/mercadopago/category_id'),
|
320 |
+
"quantity" => (int) number_format($item->getQtyOrdered(), 0, '.', ''),
|
321 |
+
"unit_price" => (float) number_format($prod->getPrice(), 2, '.', '')
|
322 |
+
);
|
323 |
+
|
324 |
+
}
|
325 |
+
|
326 |
+
|
327 |
+
//verifica se existe desconto, caso exista adiciona como um item
|
328 |
+
$discount = $this->getDiscount();
|
329 |
+
if($discount != 0){
|
330 |
+
$arr['items'][] = array(
|
331 |
+
"title" => "Discount by the Store",
|
332 |
+
"description" => "Discount by the Store",
|
333 |
+
"quantity" => (int) 1,
|
334 |
+
"unit_price" => (float) number_format($discount, 2, '.', '')
|
335 |
+
);
|
336 |
+
}
|
337 |
+
|
338 |
+
//pega dados de envio
|
339 |
+
if(method_exists($order->getShippingAddress(), "getData")){
|
340 |
+
$shipping = $order->getShippingAddress()->getData();
|
341 |
+
$arr['shipments']['receiver_address'] = array(
|
342 |
+
"floor" => "-",
|
343 |
+
"zip_code" => $shipping['postcode'],
|
344 |
+
"street_name" => $shipping['street'] . " - " . $shipping['city'] . " - " . $shipping['country_id'],
|
345 |
+
"apartment" => "-",
|
346 |
+
"street_number" => "0"
|
347 |
+
);
|
348 |
+
|
349 |
+
$arr['customer']['phone'] = array(
|
350 |
+
"area_code" => "-",
|
351 |
+
"number" => $shipping['telephone']
|
352 |
+
);
|
353 |
+
}
|
354 |
+
|
355 |
+
//formata a data do usuario para o padrao do mercado pago YYYY-MM-DDTHH:MM:SS
|
356 |
+
$date_creation_user = date('Y-m-d',$customer->getCreatedAtTimestamp()) . "T" . date('H:i:s',$customer->getCreatedAtTimestamp());
|
357 |
+
|
358 |
+
//$quote = Mage::getSingleton('checkout/session')->getQuote();
|
359 |
+
$billing_address = $quote->getBillingAddress();
|
360 |
+
$billing_address = $billing_address->getData();
|
361 |
+
|
362 |
+
//set informaçoes do usuario
|
363 |
+
$arr['customer']['registration_date'] = $date_creation_user;
|
364 |
+
$arr['customer']['email'] = htmlentities($customer->getEmail());
|
365 |
+
$arr['customer']['first_name'] = htmlentities($customer->getFirstname());
|
366 |
+
$arr['customer']['last_name'] = htmlentities($customer->getLastname());
|
367 |
+
|
368 |
+
//set o documento do usuario
|
369 |
+
if($payment['additional_information']['doc_number'] != ""){
|
370 |
+
$arr['customer']['identification'] = array(
|
371 |
+
"type" => "CPF",
|
372 |
+
"number" => $payment->getAdditionalInformation("doc_number")
|
373 |
+
);
|
374 |
+
}
|
375 |
+
|
376 |
+
//set endereco do usuario
|
377 |
+
$arr['customer']['address'] = array(
|
378 |
+
"zip_code" => $billing_address['postcode'],
|
379 |
+
"street_name" => $billing_address['street'] . " - " . $billing_address['city'] . " - " . $billing_address['country_id'],
|
380 |
+
"street_number" => "0"
|
381 |
+
);
|
382 |
+
|
383 |
+
//define a url de notificacao
|
384 |
+
$arr['notification_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK,true) . "mercadopago/notifications?checkout=custom";
|
385 |
+
|
386 |
+
//pega o email e o nome do usuario guest
|
387 |
+
if($arr['payer_email'] == "" && $arr['customer']['email'] == ""){
|
388 |
+
$arr['payer_email'] = $order['customer_email'];
|
389 |
+
$arr['customer']['email'] = $order['customer_email'];
|
390 |
+
$arr['customer']['first_name'] = $order->getBillingAddress()->getFirstname();
|
391 |
+
$arr['customer']['last_name'] = $order->getBillingAddress()->getLastname();
|
392 |
+
}
|
393 |
+
|
394 |
+
|
395 |
+
if($payment->getAdditionalInformation("coupon_code") != ""){
|
396 |
+
|
397 |
+
$coupon_code = $payment->getAdditionalInformation("coupon_code");
|
398 |
+
Mage::helper('mercadopago')->log("Validating coupon_code: " . $coupon_code, 'mercadopago-custom.log');
|
399 |
+
|
400 |
+
$coupon = $core->validCoupon($coupon_code);
|
401 |
+
Mage::helper('mercadopago')->log("Response API Coupon: " , 'mercadopago-custom.log', $coupon);
|
402 |
+
|
403 |
+
if( $coupon['status'] != 200){
|
404 |
+
if( $coupon['response']['error'] != "campaign-code-doesnt-match" &&
|
405 |
+
$coupon['response']['error'] != "amount-doesnt-match" &&
|
406 |
+
$coupon['response']['error'] != "transaction_amount_invalid"){
|
407 |
+
|
408 |
+
// caso não seja os erros mapeados acima (todos são informandos no formulario no momento que aplica os desconto)
|
409 |
+
// o coupon code é inserido no array para o post de pagamento
|
410 |
+
// caso de erro significa que o coupon não é mais valido para utilização
|
411 |
+
// pode ter ocorrido do usuario ja ter utilizado o coupon e mesmo assim prosseguir com o pagamento
|
412 |
+
|
413 |
+
$arr['coupon_code'] = $coupon_code;
|
414 |
+
Mage::helper('mercadopago')->log("Coupon applied. API response 400, error not mapped", 'mercadopago-custom.log');
|
415 |
+
}else{
|
416 |
+
Mage::helper('mercadopago')->log("Coupon invalid, not applied.", 'mercadopago-custom.log');
|
417 |
+
}
|
418 |
+
}else{
|
419 |
+
$arr['coupon_code'] = $coupon_code;
|
420 |
+
Mage::helper('mercadopago')->log("Coupon applied. API response 200.", 'mercadopago-custom.log');
|
421 |
+
|
422 |
+
}
|
423 |
+
}
|
424 |
+
|
425 |
+
//verifico se o sponsor é diferente de null (se existe)
|
426 |
+
$sponsor_id = Mage::getStoreConfig('payment/mercadopago/sponsor_id');
|
427 |
+
Mage::helper('mercadopago')->log("Sponsor_id", 'mercadopago-standard.log', $sponsor_id);
|
428 |
+
if($sponsor_id != null && $sponsor_id != ""){
|
429 |
+
Mage::helper('mercadopago')->log("Sponsor_id identificado", 'mercadopago-standard.log', $sponsor_id);
|
430 |
+
$arr['sponsor_id'] = (int) $sponsor_id;
|
431 |
+
}
|
432 |
+
|
433 |
+
return $arr;
|
434 |
+
|
435 |
+
}
|
436 |
+
}
|
app/code/community/MercadoPago/Model/CustomTicket/Payment.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
+
|
19 |
+
class MercadoPago_Model_CustomTicket_Payment extends Mage_Payment_Model_Method_Abstract{
|
20 |
+
|
21 |
+
//configura o lugar do arquivo para listar meios de pagamento
|
22 |
+
protected $_formBlockType = 'mercadopago/customticket_form';
|
23 |
+
protected $_infoBlockType = 'mercadopago/customticket_info';
|
24 |
+
|
25 |
+
protected $_code = 'mercadopago_customticket';
|
26 |
+
|
27 |
+
protected $_canSaveCc = false;
|
28 |
+
protected $_isGateway = true;
|
29 |
+
protected $_canAuthorize = true;
|
30 |
+
protected $_canCapture = true;
|
31 |
+
protected $_canVoid = true;
|
32 |
+
protected $_canCancelInvoice = true;
|
33 |
+
protected $_isInitializeNeeded = true;
|
34 |
+
protected $_canFetchTransactionInfo = true;
|
35 |
+
protected $_canCreateBillingAgreement = true;
|
36 |
+
protected $_canReviewPayment = true;
|
37 |
+
|
38 |
+
public function initialize($paymentAction, $stateObject) {
|
39 |
+
//chama model para fazer o post do pagamento
|
40 |
+
$response = Mage::getModel('mercadopago/custom_payment')->postPago();
|
41 |
+
|
42 |
+
if($response !== false):
|
43 |
+
$this->getInfoInstance()->setAdditionalInformation('activation_uri', $response['response']['activation_uri']);
|
44 |
+
return true;
|
45 |
+
endif;
|
46 |
+
|
47 |
+
return false;
|
48 |
+
|
49 |
+
}
|
50 |
+
|
51 |
+
public function assignData($data){
|
52 |
+
|
53 |
+
// route /checkout/onepage/savePayment
|
54 |
+
if(!($data instanceof Varien_Object)){
|
55 |
+
$data = new Varien_Object($data);
|
56 |
+
}
|
57 |
+
|
58 |
+
//get array info
|
59 |
+
$info_form = $data->getData();
|
60 |
+
|
61 |
+
$info = $this->getInfoInstance();
|
62 |
+
$info->setAdditionalInformation('payment_type_id', "ticket");
|
63 |
+
$info->setAdditionalInformation('payment_method', $info_form['payment_method_boleto']);
|
64 |
+
$info->setAdditionalInformation('card_token_id', "");
|
65 |
+
$info->setAdditionalInformation('installments', 1);
|
66 |
+
$info->setAdditionalInformation('doc_number', "");
|
67 |
+
|
68 |
+
if(isset($info_form['coupon_code'])){
|
69 |
+
$info->setAdditionalInformation('coupon_code', $info_form['coupon_code']);
|
70 |
+
}
|
71 |
+
|
72 |
+
return $this;
|
73 |
+
}
|
74 |
+
|
75 |
+
public function getOrderPlaceRedirectUrl() {
|
76 |
+
// requisicao vem da pagina de finalizacao de pedido
|
77 |
+
return Mage::getUrl('mercadopago/success', array('_secure' => true));
|
78 |
+
}
|
79 |
+
|
80 |
+
}
|
81 |
+
|
82 |
+
?>
|
app/code/community/MercadoPago/Model/Observer.php
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
+
|
19 |
+
class MercadoPago_Model_Observer{
|
20 |
+
|
21 |
+
private $banners = array(
|
22 |
+
"mercadopago_custom" => array(
|
23 |
+
"mla" => "http://imgmp.mlstatic.com/org-img/banners/ar/medios/online/468X60.jpg",
|
24 |
+
"mlb" => "http://imgmp.mlstatic.com/org-img/MLB/MP/BANNERS/tipo2_468X60.jpg",
|
25 |
+
"mco" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png",
|
26 |
+
"mlm" => "http://imgmp.mlstatic.com/org-img/banners/mx/medios/MLM_468X60.JPG"
|
27 |
+
),
|
28 |
+
"mercadopago_customticket" => array(
|
29 |
+
"mla" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png",
|
30 |
+
"mlb" => "http://imgmp.mlstatic.com/org-img/MLB/MP/BANNERS/2014/230x60.png",
|
31 |
+
"mco" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png",
|
32 |
+
"mlm" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png"
|
33 |
+
),
|
34 |
+
"mercadopago_standard" => array(
|
35 |
+
"mla" => "http://imgmp.mlstatic.com/org-img/banners/ar/medios/online/468X60.jpg",
|
36 |
+
"mlb" => "http://imgmp.mlstatic.com/org-img/MLB/MP/BANNERS/tipo2_468X60.jpg",
|
37 |
+
"mco" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png",
|
38 |
+
"mlm" => "http://imgmp.mlstatic.com/org-img/banners/mx/medios/MLM_468X60.JPG"
|
39 |
+
)
|
40 |
+
);
|
41 |
+
|
42 |
+
private $available_transparent_credit_cart = array('mla', 'mlb', 'mlm');
|
43 |
+
private $available_transparent_ticket = array('mla', 'mlb', 'mlm');
|
44 |
+
|
45 |
+
public function checkAndValidData($observer){
|
46 |
+
//verifica se o usuario é de teste ou nao
|
47 |
+
$this->setSponsor();
|
48 |
+
|
49 |
+
//verifica se o checkout esta disponível para o pais
|
50 |
+
$this->availableCheckout();
|
51 |
+
|
52 |
+
//verifica se os banners estao de acordo com o pais
|
53 |
+
$this->checkBanner('mercadopago_custom');
|
54 |
+
$this->checkBanner('mercadopago_customticket');
|
55 |
+
$this->checkBanner('mercadopago_standard');
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
public function availableCheckout(){
|
60 |
+
//verifica se o pais selecionado possui integracao para utilizar os checkouts transparents
|
61 |
+
$core = new Mage_Core_Model_Resource_Setup('core_setup');
|
62 |
+
$country = Mage::getStoreConfig('payment/mercadopago/country');
|
63 |
+
|
64 |
+
if(!in_array($country, $this->available_transparent_credit_cart)){
|
65 |
+
$core->setConfigData('payment/mercadopago_custom/active', 0);
|
66 |
+
}
|
67 |
+
|
68 |
+
if(!in_array($country, $this->available_transparent_ticket)){
|
69 |
+
$core->setConfigData('payment/mercadopago_customticket/active', 0);
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
function checkBanner($type_checkout){
|
74 |
+
//get country
|
75 |
+
$country = Mage::getStoreConfig('payment/mercadopago/country');
|
76 |
+
$default_banner = $this->banners[$type_checkout][$country];
|
77 |
+
|
78 |
+
//pega o banner do tipo de checkout
|
79 |
+
$current_banner = Mage::getStoreConfig('payment/' . $type_checkout . '/banner_checkout');
|
80 |
+
|
81 |
+
Mage::helper('mercadopago')->log("Type Checkout Path: " . $type_checkout, 'mercadopago.log');
|
82 |
+
Mage::helper('mercadopago')->log("Current Banner: " . $current_banner, 'mercadopago.log');
|
83 |
+
Mage::helper('mercadopago')->log("Default Banner: " . $default_banner, 'mercadopago.log');
|
84 |
+
|
85 |
+
//verifico se o banner esta na lista de banner default
|
86 |
+
//caso esteja verifico se esta de acordo com o pais
|
87 |
+
if(in_array($current_banner, $this->banners[$type_checkout])){
|
88 |
+
Mage::helper('mercadopago')->log("Banner default need update...", 'mercadopago.log');
|
89 |
+
|
90 |
+
if($default_banner != $current_banner){
|
91 |
+
//set o novo banner atualiza o banner
|
92 |
+
$core = new Mage_Core_Model_Resource_Setup('core_setup');
|
93 |
+
$core->setConfigData('payment/' . $type_checkout . '/banner_checkout', $default_banner);
|
94 |
+
|
95 |
+
Mage::helper('mercadopago')->log('payment/' . $type_checkout . '/banner_checkout setted ' . $default_banner, 'mercadopago.log');
|
96 |
+
}
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
|
101 |
+
public function setSponsor(){
|
102 |
+
Mage::helper('mercadopago')->log("Sponsor_id: " . Mage::getStoreConfig('payment/mercadopago/sponsor_id'), 'mercadopago.log');
|
103 |
+
|
104 |
+
$sponsor_id = "";
|
105 |
+
Mage::helper('mercadopago')->log("Valid user test", 'mercadopago.log');
|
106 |
+
|
107 |
+
$client_id = Mage::getStoreConfig('payment/mercadopago/client_id');
|
108 |
+
Mage::helper('mercadopago')->log("Get client id: " . $client_id, 'mercadopago.log');
|
109 |
+
|
110 |
+
$client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret');
|
111 |
+
Mage::helper('mercadopago')->log("Get client secret: " . $client_secret, 'mercadopago.log');
|
112 |
+
|
113 |
+
$mp = new MP($client_id, $client_secret);
|
114 |
+
$user = $mp->get("/users/me");
|
115 |
+
Mage::helper('mercadopago')->log("API Users response", 'mercadopago.log', $user);
|
116 |
+
|
117 |
+
//caso api retorne 403 (error no get) verifica se a mensagem e do usuario com test credentials
|
118 |
+
if( $user['status'] == 200 && !in_array("test_user", $user['response']['tags']) ){
|
119 |
+
|
120 |
+
$sponsor_id = 1;
|
121 |
+
$country = Mage::getStoreConfig('payment/mercadopago/country');
|
122 |
+
|
123 |
+
switch($user['response']['site_id']){
|
124 |
+
case 'MLA':
|
125 |
+
$sponsor_id = 186172525;
|
126 |
+
break;
|
127 |
+
case 'MLB':
|
128 |
+
$sponsor_id = 186175129;
|
129 |
+
break;
|
130 |
+
case 'MLM':
|
131 |
+
$sponsor_id = 186175064;
|
132 |
+
break;
|
133 |
+
default:
|
134 |
+
$sponsor_id = "";
|
135 |
+
break;
|
136 |
+
}
|
137 |
+
|
138 |
+
Mage::helper('mercadopago')->log("Sponsor id setted", 'mercadopago.log', $sponsor_id);
|
139 |
+
}
|
140 |
+
|
141 |
+
$core = new Mage_Core_Model_Resource_Setup('core_setup');
|
142 |
+
$core->setConfigData('payment/mercadopago/sponsor_id', $sponsor_id);
|
143 |
+
Mage::helper('mercadopago')->log("Sponsor saved", 'mercadopago.log', $sponsor_id);
|
144 |
+
}
|
145 |
+
|
146 |
+
}
|
app/code/community/MercadoPago/Model/Source/CategoryId.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
+
|
19 |
+
class MercadoPago_Model_Source_CategoryId extends Mage_Payment_Model_Method_Abstract{
|
20 |
+
|
21 |
+
public function toOptionArray (){
|
22 |
+
|
23 |
+
Mage::helper('mercadopago')->log("Get Categories... ", 'mercadopago.log');
|
24 |
+
|
25 |
+
$response = MPRestClient::get("/item_categories");
|
26 |
+
Mage::helper('mercadopago')->log("API item_categories", 'mercadopago.log', $response);
|
27 |
+
|
28 |
+
$response = $response['response'];
|
29 |
+
|
30 |
+
$cat = array();
|
31 |
+
$count = 0;
|
32 |
+
foreach($response as $v):
|
33 |
+
//force category others first
|
34 |
+
if($v['id'] == "others"):
|
35 |
+
$cat[0] = array('value' => $v['id'], 'label'=>Mage::helper('adminhtml')->__($v['description']));
|
36 |
+
else:
|
37 |
+
$count++;
|
38 |
+
$cat[$count] = array('value' => $v['id'], 'label'=>Mage::helper('adminhtml')->__($v['description']));
|
39 |
+
endif;
|
40 |
+
|
41 |
+
endforeach;
|
42 |
+
|
43 |
+
//force order by key
|
44 |
+
ksort($cat);
|
45 |
+
return $cat;
|
46 |
+
|
47 |
+
}
|
48 |
+
}
|
app/code/community/MercadoPago/Model/Source/Country.php
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
class MercadoPago_Model_Source_Country extends Mage_Payment_Model_Method_Abstract{
|
18 |
+
|
19 |
+
public function toOptionArray (){
|
20 |
+
|
21 |
+
$country = array();
|
22 |
+
$country[] = array('value' => "mla", 'label'=>Mage::helper('adminhtml')->__("Argentina"));
|
23 |
+
$country[] = array('value' => "mlb", 'label'=>Mage::helper('adminhtml')->__("Brasil"));
|
24 |
+
$country[] = array('value' => "mco", 'label'=>Mage::helper('adminhtml')->__("Colombia"));
|
25 |
+
$country[] = array('value' => "mlm", 'label'=>Mage::helper('adminhtml')->__("Mexico"));
|
26 |
+
|
27 |
+
//force order by key
|
28 |
+
ksort($country);
|
29 |
+
return $country;
|
30 |
+
|
31 |
+
}
|
32 |
+
}
|
app/code/community/MercadoPago/{Standard/Model → Model}/Source/Installments.php
RENAMED
@@ -16,12 +16,16 @@
|
|
16 |
|
17 |
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
|
19 |
-
class
|
20 |
|
21 |
public function toOptionArray (){
|
22 |
|
23 |
$inst = array();
|
|
|
|
|
24 |
$response = MPRestClient::get("/sites/MLB/payment_methods/melicard?marketplace=NONE");
|
|
|
|
|
25 |
$response = $response['response'];
|
26 |
|
27 |
foreach($response['payer_costs'] as $i){
|
16 |
|
17 |
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
|
19 |
+
class MercadoPago_Model_Source_Installments extends Mage_Payment_Model_Method_Abstract{
|
20 |
|
21 |
public function toOptionArray (){
|
22 |
|
23 |
$inst = array();
|
24 |
+
|
25 |
+
Mage::helper('mercadopago')->log("Get Site payment methods... ", 'mercadopago.log');
|
26 |
$response = MPRestClient::get("/sites/MLB/payment_methods/melicard?marketplace=NONE");
|
27 |
+
Mage::helper('mercadopago')->log("API sites payment methods", 'mercadopago.log', $response);
|
28 |
+
|
29 |
$response = $response['response'];
|
30 |
|
31 |
foreach($response['payer_costs'] as $i){
|
app/code/community/MercadoPago/Model/Source/PaymentMethods.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
+
|
19 |
+
class MercadoPago_Model_Source_PaymentMethods extends Mage_Payment_Model_Method_Abstract{
|
20 |
+
|
21 |
+
public function toOptionArray (){
|
22 |
+
|
23 |
+
Mage::helper('mercadopago')->log("Get payment methods by country... ", 'mercadopago.log');
|
24 |
+
|
25 |
+
$country = strtoupper(Mage::getStoreConfig('payment/mercadopago/country'));
|
26 |
+
$methods = array();
|
27 |
+
//adiciona um valor vazio caso nao queria excluir nada
|
28 |
+
$methods[] = array("value" => "", "label" => "");
|
29 |
+
$response = MPRestClient::get("/sites/" . $country . "/payment_methods");
|
30 |
+
Mage::helper('mercadopago')->log("API payment methods", 'mercadopago.log', $response);
|
31 |
+
|
32 |
+
$response = $response['response'];
|
33 |
+
|
34 |
+
foreach($response as $m){
|
35 |
+
if ( $m['id'] != 'account_money' ) {
|
36 |
+
$methods[] = array(
|
37 |
+
'value' => $m['id'],
|
38 |
+
'label'=>Mage::helper('adminhtml')->__($m['name'])
|
39 |
+
);
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
+
return $methods;
|
44 |
+
}
|
45 |
+
}
|
app/code/community/MercadoPago/{Standard/Model → Model}/Source/TypeCheckout.php
RENAMED
@@ -16,16 +16,16 @@
|
|
16 |
|
17 |
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
|
19 |
-
class
|
20 |
|
21 |
public function toOptionArray (){
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
}
|
31 |
}
|
16 |
|
17 |
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
|
19 |
+
class MercadoPago_Model_Source_TypeCheckout extends Mage_Payment_Model_Method_Abstract{
|
20 |
|
21 |
public function toOptionArray (){
|
22 |
|
23 |
+
$arr = array(
|
24 |
+
array("value"=> "iframe", 'label'=>Mage::helper('adminhtml')->__("Iframe")),
|
25 |
+
array("value"=> "redirect", 'label'=>Mage::helper('adminhtml')->__("Redirect")),
|
26 |
+
array("value"=> "lightbox", 'label'=>Mage::helper('adminhtml')->__("Lightbox"))
|
27 |
+
);
|
28 |
+
|
29 |
+
return $arr;
|
30 |
}
|
31 |
}
|
app/code/community/MercadoPago/Model/Standard/Payment.php
ADDED
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL).
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://opensource.org/licenses/osl-3.0.php
|
9 |
+
*
|
10 |
+
* @category Payment Gateway
|
11 |
+
* @package MercadoPago
|
12 |
+
* @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
|
13 |
+
* @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
|
14 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
15 |
+
*/
|
16 |
+
|
17 |
+
require_once(Mage::getBaseDir('lib') . '/mercadopago/mercadopago.php');
|
18 |
+
|
19 |
+
class MercadoPago_Model_Standard_Payment extends Mage_Payment_Model_Method_Abstract{
|
20 |
+
|
21 |
+
//configura o lugar do arquivo para listar meios de pagamento
|
22 |
+
protected $_formBlockType = 'mercadopago/standard_form';
|
23 |
+
protected $_infoBlockType = 'mercadopago/standard_info';
|
24 |
+
|
25 |
+
protected $_code = 'mercadopago_standard';
|
26 |
+
|
27 |
+
protected $_isGateway = true;
|
28 |
+
protected $_canOrder = true;
|
29 |
+
protected $_canAuthorize = true;
|
30 |
+
protected $_canCapture = true;
|
31 |
+
protected $_canCapturePartial = true;
|
32 |
+
protected $_canRefund = true;
|
33 |
+
protected $_canRefundInvoicePartial = true;
|
34 |
+
protected $_canVoid = true;
|
35 |
+
protected $_canUseInternal = true;
|
36 |
+
protected $_canUseCheckout = true;
|
37 |
+
protected $_canUseForMultishipping = true;
|
38 |
+
protected $_canFetchTransactionInfo = true;
|
39 |
+
protected $_canCreateBillingAgreement = true;
|
40 |
+
protected $_canReviewPayment = true;
|
41 |
+
|
42 |
+
public function postPago(){
|
43 |
+
|
44 |
+
$core = Mage::getModel('mercadopago/core');
|
45 |
+
|
46 |
+
//seta sdk php mercadopago
|
47 |
+
$client_id = Mage::getStoreConfig('payment/mercadopago/client_id');
|
48 |
+
$client_secret = Mage::getStoreConfig('payment/mercadopago/client_secret');
|
49 |
+
$mp = new MP($client_id, $client_secret);
|
50 |
+
|
51 |
+
//monta a prefernecia
|
52 |
+
$pref = $this->makePreference();
|
53 |
+
Mage::helper('mercadopago')->log("make array", 'mercadopago-standard.log', $pref);
|
54 |
+
|
55 |
+
//faz o posto do pagamento
|
56 |
+
$response = $mp->create_preference($pref);
|
57 |
+
Mage::helper('mercadopago')->log("create preference result", 'mercadopago-standard.log', $response);
|
58 |
+
|
59 |
+
$array_assign = array();
|
60 |
+
|
61 |
+
if($response['status'] == 200 || $response['status'] == 201):
|
62 |
+
$payment = $response['response'];
|
63 |
+
$init_point = $payment['init_point'];
|
64 |
+
|
65 |
+
$array_assign = array(
|
66 |
+
"init_point" => $init_point,
|
67 |
+
"type_checkout" => $this->getConfigData('type_checkout'),
|
68 |
+
"iframe_width" => $this->getConfigData('iframe_width'),
|
69 |
+
"iframe_height" => $this->getConfigData('iframe_height'),
|
70 |
+
"banner_checkout" => $this->getConfigData('banner_checkout'),
|
71 |
+
"status" => 201
|
72 |
+
);
|
73 |
+
|
74 |
+
Mage::helper('mercadopago')->log("Array preference ok", 'mercadopago-standard.log');
|
75 |
+
else:
|
76 |
+
$array_assign = array(
|
77 |
+
"message" => Mage::helper('mercadopago')->__('An error has occurred. Please refresh the page.'),
|
78 |
+
"json" => json_encode($response),
|
79 |
+
"status" => 400
|
80 |
+
);
|
81 |
+
|
82 |
+
Mage::helper('mercadopago')->log("Array preference error", 'mercadopago-standard.log');
|
83 |
+
endif;
|
84 |
+
|
85 |
+
return $array_assign;
|
86 |
+
}
|
87 |
+
|
88 |
+
public function getOrderPlaceRedirectUrl() {
|
89 |
+
// requisicao vem da pagina de finalizacao de pedido
|
90 |
+
return Mage::getUrl('mercadopago/pay', array('_secure' => true));
|
91 |
+
}
|
92 |
+
|
93 |
+
public function getDiscount($order){
|
94 |
+
$discount = 0;
|
95 |
+
$order = $order->getData();
|
96 |
+
|
97 |
+
if(isset($order['base_discount_amount']) && $order['base_discount_amount'] < 0) {
|
98 |
+
$discount = $order['base_discount_amount'];
|
99 |
+
}
|
100 |
+
|
101 |
+
return $discount;
|
102 |
+
}
|
103 |
+
|
104 |
+
function makePreference(){
|
105 |
+
|
106 |
+
//pega a order atual
|
107 |
+
$orderIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
|
108 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
|
109 |
+
$customer = Mage::getSingleton('customer/session')->getCustomer();
|
110 |
+
$model = Mage::getModel('catalog/product');
|
111 |
+
|
112 |
+
//pega payment dentro da order para pegar as informacoes adicionadas pela funcao assignData()
|
113 |
+
$payment = $order->getPayment();
|
114 |
+
|
115 |
+
//init array preferneces
|
116 |
+
$arr = array();
|
117 |
+
|
118 |
+
//seta o external_reference para conciliacao futura
|
119 |
+
$arr['external_reference'] = $orderIncrementId;
|
120 |
+
|
121 |
+
//monta array de produtos
|
122 |
+
$arr['items'] = array();
|
123 |
+
|
124 |
+
$total_item = 0;
|
125 |
+
foreach ($order->getAllVisibleItems() as $item) {
|
126 |
+
|
127 |
+
$prod = $model->loadByAttribute('sku', $item->getSku());
|
128 |
+
|
129 |
+
//get image
|
130 |
+
try{
|
131 |
+
$imagem = $prod->getImageUrl();
|
132 |
+
}catch(Exception $e){
|
133 |
+
$imagem = "";
|
134 |
+
}
|
135 |
+
|
136 |
+
$arr['items'][] = array(
|
137 |
+
"id" => $item->getSku(),
|
138 |
+
"title" => $item->getName(),
|
139 |
+
"description" => $item->getName(),
|
140 |
+
"picture_url" => $imagem,
|
141 |
+
"category_id" => Mage::getStoreConfig('payment/mercadopago/category_id'),
|
142 |
+
"quantity" => (int) number_format($item->getQtyOrdered(), 0, '.', ''),
|
143 |
+
"unit_price" => (float) number_format($prod->getFinalPrice(), 2, '.', '')
|
144 |
+
);
|
145 |
+
|
146 |
+
//faz uma soma dos itens para depois verificar com o valor total
|
147 |
+
$total_item += (float) number_format($prod->getFinalPrice(), 2, '.', '');
|
148 |
+
}
|
149 |
+
|
150 |
+
//pega valor total da compra
|
151 |
+
$order_amount = (float) $order->getBaseGrandTotal();
|
152 |
+
if (!$order_amount) {
|
153 |
+
$order_amount = (float) $order->getBasePrice() + $order->getBaseShippingAmount();
|
154 |
+
}
|
155 |
+
|
156 |
+
//adiciona o valor do frete para as variaveis bater
|
157 |
+
$total_item += (float) $order->getBaseShippingAmount();
|
158 |
+
|
159 |
+
// if respons�vel por verificar se existe diferen�a entre os pre�os,
|
160 |
+
// tanto maior quanto menor,
|
161 |
+
// calcula e adiciona como itens para ter o valor real do pedido
|
162 |
+
if($total_item > $order_amount || $total_item < $order_amount){
|
163 |
+
$diff_price = $order_amount - $total_item;
|
164 |
+
|
165 |
+
$arr['items'][] = array(
|
166 |
+
"title" => "Difference amount of the items with a total",
|
167 |
+
"description" => "Difference amount of the items with a total",
|
168 |
+
"category_id" => Mage::getStoreConfig('payment/mercadopago/category_id'),
|
169 |
+
"quantity" => 1,
|
170 |
+
"unit_price" => (float) $diff_price
|
171 |
+
);
|
172 |
+
|
173 |
+
Mage::helper('mercadopago')->log("Total itens: " . $total_item, 'mercadopago-standard.log');
|
174 |
+
Mage::helper('mercadopago')->log("Total order: " . $order_amount, 'mercadopago-standard.log');
|
175 |
+
Mage::helper('mercadopago')->log("Difference add itens: " . $diff_price, 'mercadopago-standard.log');
|
176 |
+
}
|
177 |
+
|
178 |
+
|
179 |
+
/*
|
180 |
+
//verifica se existe desconto, caso exista adiciona como um item
|
181 |
+
$discount = $this->getDiscount($order);
|
182 |
+
|
183 |
+
if($discount != 0){
|
184 |
+
$arr['items'][] = array(
|
185 |
+
"title" => "Discount by the Store",
|
186 |
+
"description" => "Discount by the Store",
|
187 |
+
"quantity" => (int) 1,
|
188 |
+
"unit_price" => (float) number_format($discount, 2, '.', '')
|
189 |
+
);
|
190 |
+
}*/
|
191 |
+
|
192 |
+
|
193 |
+
//pega dados de envio
|
194 |
+
if(method_exists($order->getShippingAddress(), "getData")){
|
195 |
+
$shipping = $order->getShippingAddress()->getData();
|
196 |
+
$arr['shipments']['receiver_address'] = array(
|
197 |
+
"floor" => "-",
|
198 |
+
"zip_code" => $shipping['postcode'],
|
199 |
+
"street_name" => $shipping['street'] . " - " . $shipping['city'] . " - " . $shipping['country_id'],
|
200 |
+
"apartment" => "-",
|
201 |
+
"street_number" => "0"
|
202 |
+
);
|
203 |
+
$arr['payer']['phone'] = array(
|
204 |
+
"area_code" => "-",
|
205 |
+
"number" => $shipping['telephone']
|
206 |
+
);
|
207 |
+
}
|
208 |
+
|
209 |
+
//adiciona o valor do frete nas preferencias
|
210 |
+
if($order->getBaseShippingAmount() != "" && $order->getBaseShippingAmount() > 0){
|
211 |
+
$arr['shipments']['cost'] = (float) $order->getBaseShippingAmount();
|
212 |
+
}
|
213 |
+
|
214 |
+
|
215 |
+
//pega informa�oes de cadastro do usuario
|
216 |
+
$billing_address = $order->getBillingAddress();
|
217 |
+
$billing_address = $billing_address->getData();
|
218 |
+
|
219 |
+
//formata a data do usuario para o padrao do mercado pago YYYY-MM-DDTHH:MM:SS
|
220 |
+
$arr['payer']['date_created'] = date('Y-m-d',$customer->getCreatedAtTimestamp()) . "T" . date('H:i:s',$customer->getCreatedAtTimestamp());
|
221 |
+
|
222 |
+
//set informa�oes do usuario
|
223 |
+
$arr['payer']['email'] = htmlentities($customer->getEmail());
|
224 |
+
$arr['payer']['first_name'] = htmlentities($customer->getFirstname());
|
225 |
+
$arr['payer']['last_name'] = htmlentities($customer->getLastname());
|
226 |
+
|
227 |
+
//set o documento do usuario
|
228 |
+
if(isset($payment['additional_information']['doc_number']) && $payment['additional_information']['doc_number'] != ""){
|
229 |