MercadoPagoTransparent - Version 0.0.1

Version Notes

Checkout Transparente disponível para: Brasil, Argentina e Mexico.

Checkout Standard disponível para: Brasil, Argentina, Mexico, Venezuela e Colombia.

Download this release

Release Info

Developer Developers MercadoPago Brasil
Extension MercadoPagoTransparent
Version 0.0.1
Comparing to
See all releases


Version 0.0.1

Files changed (68) hide show
  1. app/code/community/MercadoPago/.DS_Store +0 -0
  2. app/code/community/MercadoPago/Standard/Block/Form.php +34 -0
  3. app/code/community/MercadoPago/Standard/Block/Info.php +36 -0
  4. app/code/community/MercadoPago/Standard/Helper/Data.php +22 -0
  5. app/code/community/MercadoPago/Standard/Model/Checkout.php +250 -0
  6. app/code/community/MercadoPago/Standard/Model/Observer.php +107 -0
  7. app/code/community/MercadoPago/Standard/Model/Source/CategoryId.php +44 -0
  8. app/code/community/MercadoPago/Standard/Model/Source/Country.php +32 -0
  9. app/code/community/MercadoPago/Standard/Model/Source/Installments.php +37 -0
  10. app/code/community/MercadoPago/Standard/Model/Source/PaymentMethods.php +41 -0
  11. app/code/community/MercadoPago/Standard/Model/Source/TypeCheckout.php +31 -0
  12. app/code/community/MercadoPago/Standard/controllers/NotificationController.php +190 -0
  13. app/code/community/MercadoPago/Standard/controllers/PayController.php +64 -0
  14. app/code/community/MercadoPago/Standard/etc/config.xml +120 -0
  15. app/code/community/MercadoPago/Standard/etc/system.xml +256 -0
  16. app/code/community/MercadoPago/Transparent/.DS_Store +0 -0
  17. app/code/community/MercadoPago/Transparent/Block/.DS_Store +0 -0
  18. app/code/community/MercadoPago/Transparent/Block/Form.php +82 -0
  19. app/code/community/MercadoPago/Transparent/Block/Info.php +36 -0
  20. app/code/community/MercadoPago/Transparent/Block/Success.php +36 -0
  21. app/code/community/MercadoPago/Transparent/Helper/Data.php +22 -0
  22. app/code/community/MercadoPago/Transparent/Model/.DS_Store +0 -0
  23. app/code/community/MercadoPago/Transparent/Model/Resource/Setup.php +14 -0
  24. app/code/community/MercadoPago/Transparent/Model/Source/CategoryId.php +44 -0
  25. app/code/community/MercadoPago/Transparent/Model/Transparent.php +393 -0
  26. app/code/community/MercadoPago/Transparent/controllers/NotificacaoController.php +190 -0
  27. app/code/community/MercadoPago/Transparent/controllers/PayController.php +194 -0
  28. app/code/community/MercadoPago/Transparent/etc/config.xml +103 -0
  29. app/code/community/MercadoPago/Transparent/etc/system.xml +81 -0
  30. app/code/community/MercadoPago/TransparentTicket/Block/Form.php +50 -0
  31. app/code/community/MercadoPago/TransparentTicket/Block/Info.php +36 -0
  32. app/code/community/MercadoPago/TransparentTicket/Helper/Data.php +22 -0
  33. app/code/community/MercadoPago/TransparentTicket/Model/Transparent.php +86 -0
  34. app/code/community/MercadoPago/TransparentTicket/etc/config.xml +103 -0
  35. app/code/community/MercadoPago/TransparentTicket/etc/system.xml +74 -0
  36. app/design/adminhtml/default/default/template/mercadopago/standard/info.phtml +29 -0
  37. app/design/adminhtml/default/default/template/mercadopago/transparent/info.phtml +33 -0
  38. app/design/adminhtml/default/default/template/mercadopago/transparent_boleto/info.phtml +13 -0
  39. app/design/adminhtml/default/default/template/mercadopago/transparent_ticket/info.phtml +15 -0
  40. app/design/frontend/base/default/layout/mercadopago.xml +9 -0
  41. app/design/frontend/base/default/template/mercadopago/clean_page.phtml +48 -0
  42. app/design/frontend/base/default/template/mercadopago/standard/form.phtml +12 -0
  43. app/design/frontend/base/default/template/mercadopago/standard/info.phtml +36 -0
  44. app/design/frontend/base/default/template/mercadopago/standard/pay.phtml +51 -0
  45. app/design/frontend/base/default/template/mercadopago/transparent/form.phtml +175 -0
  46. app/design/frontend/base/default/template/mercadopago/transparent/info.phtml +33 -0
  47. app/design/frontend/base/default/template/mercadopago/transparent/success.phtml +229 -0
  48. app/design/frontend/base/default/template/mercadopago/transparent/sucesso.phtml +103 -0
  49. app/design/frontend/base/default/template/mercadopago/transparent_boleto/form.phtml +20 -0
  50. app/design/frontend/base/default/template/mercadopago/transparent_boleto/info.phtml +23 -0
  51. app/design/frontend/base/default/template/mercadopago/transparent_ticket/form.phtml +31 -0
  52. app/design/frontend/base/default/template/mercadopago/transparent_ticket/info.phtml +27 -0
  53. app/etc/modules/MercadoPago_Standard.xml +9 -0
  54. app/etc/modules/MercadoPago_Transparent.xml +9 -0
  55. app/etc/modules/MercadoPago_TransparentBoleto.xml +9 -0
  56. app/etc/modules/MercadoPago_TransparentTicket.xml +9 -0
  57. app/locale/es_AR/mercadopago.csv +114 -0
  58. app/locale/es_CO/mercadopago.csv +119 -0
  59. app/locale/es_ES/mercadopago.csv +41 -0
  60. app/locale/es_MX/mercadopago.csv +120 -0
  61. app/locale/pt_BR/mercadopago.csv +120 -0
  62. js/mercadopago/jquery-1.11.0.min.js +4 -0
  63. js/mercadopago/mercadopago.js +294 -0
  64. lib/mercadopago/mercadopago.php +342 -0
  65. package.xml +26 -0
  66. skin/frontend/base/default/mercadopago/.DS_Store +0 -0
  67. skin/frontend/base/default/mercadopago/css/style.css +222 -0
  68. skin/frontend/base/default/mercadopago/images/loading.gif +0 -0
app/code/community/MercadoPago/.DS_Store ADDED
Binary file
app/code/community/MercadoPago/Standard/Block/Form.php ADDED
@@ -0,0 +1,34 @@
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_Standard_Block_Form extends Mage_Payment_Block_Form_Cc{
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
+ ?>
app/code/community/MercadoPago/Standard/Block/Info.php ADDED
@@ -0,0 +1,36 @@
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_Standard_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/standard/info.phtml');
27
+ $this->setModuleName('Mage_Payment');
28
+ }
29
+
30
+
31
+ public function getOrder() {
32
+
33
+ return $this->getInfo();
34
+
35
+ }
36
+ }
app/code/community/MercadoPago/Standard/Helper/Data.php ADDED
@@ -0,0 +1,22 @@
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
+ <?php
18
+
19
+
20
+ class MercadoPago_Standard_Helper_Data extends Mage_Payment_Helper_Data{
21
+
22
+ }
app/code/community/MercadoPago/Standard/Model/Checkout.php ADDED
@@ -0,0 +1,250 @@
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_Standard_Model_Checkout 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
+ protected function _construct(){
43
+ $this->_init('mercadopago_standard/checkout');
44
+ }
45
+
46
+ public function postPago(){
47
+ //seta sdk php mercadopago
48
+ $client_id = Mage::getStoreConfig('payment/mercadopago_configuration/client_id');
49
+ $client_secret = Mage::getStoreConfig('payment/mercadopago_configuration/client_secret');
50
+ $mp = new MP($client_id, $client_secret);
51
+
52
+ //monta a prefernecia
53
+ $pref = $this->makePreference();
54
+
55
+ //faz o posto do pagamento
56
+ return $mp->create_preference($pref);
57
+ }
58
+
59
+ public function getOrderPlaceRedirectUrl() {
60
+
61
+ // requisicao vem da pagina de finalizacao de pedido
62
+ return Mage::getUrl('mercadopago_standard/pay', array('_secure' => true));
63
+
64
+ }
65
+
66
+ public function getDiscount($order){
67
+ $discount = 0;
68
+
69
+ $order = $order->getData();
70
+
71
+ if(isset($order['base_discount_amount']) && $order['base_discount_amount'] < 0) {
72
+ $discount = $order['base_discount_amount'];
73
+ }
74
+
75
+ return $discount;
76
+ }
77
+
78
+ function makePreference(){
79
+
80
+ //pega a order atual
81
+ $orderIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
82
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
83
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
84
+ $model = Mage::getModel('catalog/product');
85
+
86
+
87
+
88
+ //pega payment dentro da order para pegar as informacoes adicionadas pela funcao assignData()
89
+ $payment = $order->getPayment();
90
+
91
+ //init array preferneces
92
+ $arr = array();
93
+
94
+ //seta o external_reference para concilia��o futura
95
+ $arr['external_reference'] = $orderIncrementId;
96
+
97
+ //monta array de produtos
98
+ $arr['items'] = array();
99
+ foreach ($order->getAllVisibleItems() as $item) {
100
+
101
+ $prod = $model->loadByAttribute('sku', $item->getSku());
102
+
103
+ //get image
104
+ try{
105
+ $imagem = $prod->getImageUrl();
106
+ }catch(Exception $e){
107
+ $imagem = "";
108
+ }
109
+
110
+ $arr['items'][] = array(
111
+ "id" => $item->getSku(),
112
+ "title" => $item->getName(),
113
+ "description" => $item->getName(),
114
+ "picture_url" => $imagem,
115
+ "category_id" => Mage::getStoreConfig('payment/mercadopago_configuration/category_id'),
116
+ "quantity" => (int) number_format($item->getQtyOrdered(), 0, '.', ''),
117
+ "unit_price" => (float) number_format($prod->getPrice(), 2, '.', '')
118
+ );
119
+
120
+ }
121
+
122
+ //verifica se existe desconto, caso exista adiciona como um item
123
+ $discount = $this->getDiscount($order);
124
+
125
+ if($discount != 0){
126
+ $arr['items'][] = array(
127
+ "title" => "Discount by the Store",
128
+ "description" => "Discount by the Store",
129
+ "quantity" => (int) 1,
130
+ "unit_price" => (float) number_format($discount, 2, '.', '')
131
+ );
132
+ }
133
+
134
+
135
+ //pega dados de envio
136
+ if(method_exists($order->getShippingAddress(), "getData")){
137
+ $shipping = $order->getShippingAddress()->getData();
138
+ $arr['shipments']['receiver_address'] = array(
139
+ "floor" => "-",
140
+ "zip_code" => $shipping['postcode'],
141
+ "street_name" => $shipping['street'] . " - " . $shipping['city'] . " - " . $shipping['country_id'],
142
+ "apartment" => "-",
143
+ "street_number" => "0"
144
+ );
145
+ $arr['payer']['phone'] = array(
146
+ "area_code" => "-",
147
+ "number" => $shipping['telephone']
148
+ );
149
+ }
150
+
151
+ //adiciona o valor do frete nas preferencias
152
+ if($order->getBaseShippingAmount() != "" && $order->getBaseShippingAmount() > 0){
153
+ $arr['shipments']['cost'] = (float) $order->getBaseShippingAmount();
154
+ }
155
+
156
+
157
+ //pega informa�oes de cadastro do usuario
158
+ $billing_address = $order->getBillingAddress();
159
+ $billing_address = $billing_address->getData();
160
+
161
+ //formata a data do usuario para o padrao do mercado pago YYYY-MM-DDTHH:MM:SS
162
+ $arr['payer']['date_created'] = date('Y-m-d',$customer->getCreatedAtTimestamp()) . "T" . date('H:i:s',$customer->getCreatedAtTimestamp());
163
+
164
+ //set informa�oes do usuario
165
+ $arr['payer']['email'] = htmlentities($customer->getEmail());
166
+ $arr['payer']['first_name'] = htmlentities($customer->getFirstname());
167
+ $arr['payer']['last_name'] = htmlentities($customer->getLastname());
168
+
169
+ //set o documento do usuario
170
+ if(isset($payment['additional_information']['doc_number']) && $payment['additional_information']['doc_number'] != ""){
171
+ $arr['payer']['identification'] = array(
172
+ "type" => "CPF",
173
+ "number" => $payment['additional_information']['doc_number']
174
+ );
175
+ }
176
+
177
+ //set endereco do usuario
178
+ $arr['payer']['address'] = array(
179
+ "zip_code" => $billing_address['postcode'],
180
+ "street_name" => $billing_address['street'] . " - " . $billing_address['city'] . " - " . $billing_address['country_id'],
181
+ "street_number" => "0"
182
+ );
183
+
184
+ //setta as urls de retorno
185
+ $arr['back_urls'] = array(
186
+ "success" => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK,true) . "checkout/onepage/success",
187
+ "pending" => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK,true) . "checkout/onepage/success",
188
+ "failure" => Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK,true) . "checkout/onepage/success"
189
+ );
190
+
191
+ //define a url de notificacao
192
+ $arr['notification_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK,true) . "mercadopago_standard/notification";
193
+
194
+ //pega o email e o nome do usuario guest
195
+ if($arr['payer']['email'] == ""){
196
+ $arr['payer']['email'] = $order['customer_email'];
197
+ $arr['payer']['first_name'] = $order->getBillingAddress()->getFirstname();
198
+ $arr['payer']['last_name'] = $order->getBillingAddress()->getLastname();
199
+ }
200
+
201
+ // pega os meios de pagamento que ele dejexa excluir
202
+ $checkout = Mage::getModel('mercadopago_standard/checkout');
203
+ $excluded_payment_methods = $checkout->getConfigData('excluded_payment_methods');
204
+ $arr_epm = explode(",", $excluded_payment_methods);
205
+ if(count($arr_epm) > 0){
206
+ $arr['payment_methods']['excluded_payment_methods'] = array();
207
+
208
+ foreach($arr_epm as $m):
209
+ $arr['payment_methods']['excluded_payment_methods'][] = array("id" => $m);
210
+ endforeach;
211
+
212
+ }
213
+
214
+ //seta o numero de parcelas maxima aceita pelo lojista
215
+ $installments = $checkout->getConfigData('installments');
216
+ $arr['payment_methods']['installments'] = (int) $installments;
217
+
218
+
219
+ //define o retorno automatico ao finalizar o checkout
220
+ $auto_return = $checkout->getConfigData('auto_return');
221
+ if($auto_return == 1){
222
+ $arr['auto_return'] = "approved";
223
+ }
224
+
225
+ //adiciona o sponsor_id para as vendas serem identificadas
226
+ //$arr['sponsor_id'] = "";
227
+
228
+ return $arr;
229
+
230
+ }
231
+
232
+
233
+ public function getPayment($payment_id){
234
+ $model = $this;
235
+ $this->client_id = Mage::getStoreConfig('payment/mercadopago_configuration/client_id');
236
+ $this->client_secret = Mage::getStoreConfig('payment/mercadopago_configuration/client_secret');
237
+ $mp = new MP($this->client_id, $this->client_secret);
238
+ return $mp->get_payment($payment_id);
239
+ }
240
+
241
+ public function getMerchantOrder($merchant_order_id){
242
+ $model = $this;
243
+ $this->client_id = Mage::getStoreConfig('payment/mercadopago_configuration/client_id');
244
+ $this->client_secret = Mage::getStoreConfig('payment/mercadopago_configuration/client_secret');
245
+ $mp = new MP($this->client_id, $this->client_secret);
246
+ return $mp->get_merchant_order($merchant_order_id);
247
+ }
248
+ }
249
+
250
+ ?>
app/code/community/MercadoPago/Standard/Model/Observer.php ADDED
@@ -0,0 +1,107 @@
1
+ <?php
2
+ ini_set('display_errors',1);
3
+ ini_set('display_startup_erros',1);
4
+ error_reporting(E_ALL);
5
+
6
+ /**
7
+ *
8
+ * NOTICE OF LICENSE
9
+ *
10
+ * This source file is subject to the Open Software License (OSL).
11
+ * It is also available through the world-wide-web at this URL:
12
+ * http://opensource.org/licenses/osl-3.0.php
13
+ *
14
+ * @category Payment Gateway
15
+ * @package MercadoPago
16
+ * @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
17
+ * @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class MercadoPago_Standard_Model_Observer{
22
+
23
+ private $banners_credit_card = array(
24
+ "mla" => "http://imgmp.mlstatic.com/org-img/banners/ar/medios/online/468X60.jpg",
25
+ "mlb" => "http://imgmp.mlstatic.com/org-img/MLB/MP/BANNERS/tipo2_468X60.jpg",
26
+ "mco" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png",
27
+ "mlm" => "http://imgmp.mlstatic.com/org-img/banners/mx/medios/MLM_468X60.JPG"
28
+ );
29
+
30
+ private $banner_ticket = array(
31
+ "mla" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png",
32
+ "mlb" => "http://imgmp.mlstatic.com/org-img/MLB/MP/BANNERS/2014/230x60.png",
33
+ "mco" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png",
34
+ "mlm" => "https://a248.e.akamai.net/secure.mlstatic.com/components/resources/mp/css/assets/desktop-logo-mercadopago.png"
35
+ );
36
+
37
+ private $available_transparent_credit_cart = array('mla', 'mlb', 'mlm');
38
+ private $available_transparent_ticket = array('mla', 'mlb', 'mlm');
39
+
40
+ public function checkAndValidData($observer){
41
+ $this->availableCheckout();
42
+
43
+ $this->checkBanner('mercadopago_transparentticket', 'transparent');
44
+ $this->checkBanner('mercadopago_transparent', 'transparent');
45
+ $this->checkBanner('mercadopago_standard', 'checkout');
46
+ }
47
+
48
+
49
+ public function availableCheckout(){
50
+ //verifica se o pais selecionado possui integra��o para utilizar os checkouts transparents
51
+ $core = new Mage_Core_Model_Resource_Setup('core_setup');
52
+ $country = Mage::getStoreConfig('payment/mercadopago_configuration/country');
53
+
54
+ if(!in_array($country, $this->available_transparent_credit_cart)){
55
+ $core->setConfigData('payment/mercadopago_transparent/active', 0);
56
+ }
57
+
58
+ if(!in_array($country, $this->available_transparent_ticket)){
59
+ $core->setConfigData('payment/mercadopago_transparentticket/active', 0);
60
+ }
61
+
62
+
63
+ }
64
+
65
+ function checkBanner($model_path, $file){
66
+ //pega o model/file
67
+ $model = Mage::getModel($model_path . '/' . $file);
68
+
69
+ //pega o banner do tipo de checkout
70
+ $banner = $model->getConfigData('banner_checkout');
71
+
72
+ //pega o pais configurado
73
+ $country = Mage::getStoreConfig('payment/mercadopago_configuration/country');
74
+
75
+ if($model_path == "mercadopago_transparentticket"){
76
+ if($this->banner_ticket[$country] != $banner){
77
+ $this->setNewBanner($model_path, $country);
78
+ }
79
+ }else{
80
+ if($this->banners_credit_card[$country] != $banner){
81
+ $this->setNewBanner($model_path, $country);
82
+ }
83
+ }
84
+
85
+
86
+ }
87
+ public function setNewBanner($model, $country){
88
+ //instacia model do core para atualiza os dados no banco de dados
89
+ //no model n�o existe fun��o para fazer isso, por esse motivo foi feito assim
90
+ $core = new Mage_Core_Model_Resource_Setup('core_setup');
91
+ $core->setConfigData('payment/' . $model . '/banner_checkout', $this->getBannerByCountry($model, $country));
92
+ }
93
+
94
+ public function getBannerByCountry($model, $country){
95
+ $banner = "";
96
+
97
+ //caso seja boleto o banner � diferente
98
+ if($model == "mercadopago_transparentticket"){
99
+ $banner = $this->banner_ticket[$country];
100
+ }else{
101
+ $banner = $this->banners_credit_card[$country];
102
+ }
103
+
104
+ return $banner;
105
+ }
106
+
107
+ }
app/code/community/MercadoPago/Standard/Model/Source/CategoryId.php ADDED
@@ -0,0 +1,44 @@
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_Standard_Model_Source_CategoryId extends Mage_Payment_Model_Method_Abstract{
20
+
21
+ public function toOptionArray (){
22
+
23
+ $response = MPRestClient::get("/item_categories");
24
+ $response = $response['response'];
25
+
26
+ $cat = array();
27
+ $count = 0;
28
+ foreach($response as $v):
29
+ //force category others first
30
+ if($v['id'] == "others"):
31
+ $cat[0] = array('value' => $v['id'], 'label'=>Mage::helper('adminhtml')->__($v['description']));
32
+ else:
33
+ $count++;
34
+ $cat[$count] = array('value' => $v['id'], 'label'=>Mage::helper('adminhtml')->__($v['description']));
35
+ endif;
36
+
37
+ endforeach;
38
+
39
+ //force order by key
40
+ ksort($cat);
41
+ return $cat;
42
+
43
+ }
44
+ }
app/code/community/MercadoPago/Standard/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_Standard_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/Source/Installments.php ADDED
@@ -0,0 +1,37 @@
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_Standard_Model_Source_Installments extends Mage_Payment_Model_Method_Abstract{
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){
28
+
29
+ $inst[] = array(
30
+ 'value' => $i['installments'],
31
+ 'label'=>Mage::helper('adminhtml')->__($i['installments'] . " Parcela(s)")
32
+ );
33
+ }
34
+
35
+ return $inst;
36
+ }
37
+ }
app/code/community/MercadoPago/Standard/Model/Source/PaymentMethods.php ADDED
@@ -0,0 +1,41 @@
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_Standard_Model_Source_PaymentMethods extends Mage_Payment_Model_Method_Abstract{
20
+
21
+ public function toOptionArray (){
22
+
23
+ $country = strtoupper(Mage::getStoreConfig('payment/mercadopago_configuration/country'));
24
+ $methods = array();
25
+ //adiciona um valor vazio caso n�o queria excluir nada
26
+ $methods[] = array("value" => "", "label" => "");
27
+ $response = MPRestClient::get("/sites/" . $country . "/payment_methods");
28
+ $response = $response['response'];
29
+
30
+ foreach($response as $m){
31
+ if ( $m['id'] != 'account_money' ) {
32
+ $methods[] = array(
33
+ 'value' => $m['id'],
34
+ 'label'=>Mage::helper('adminhtml')->__($m['name'])
35
+ );
36
+ }
37
+ }
38
+
39
+ return $methods;
40
+ }
41
+ }
app/code/community/MercadoPago/Standard/Model/Source/TypeCheckout.php ADDED
@@ -0,0 +1,31 @@
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_Standard_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/Standard/controllers/NotificationController.php ADDED
@@ -0,0 +1,190 @@
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_Standard_NotificationController extends Mage_Core_Controller_Front_Action{
18
+
19
+ protected $_return = null;
20
+ protected $_order = null;
21
+ protected $_order_id = null;
22
+ protected $_mpcartid = null;
23
+ protected $_sendemail = false;
24
+ protected $_hash = null;
25
+
26
+ public function indexAction(){
27
+ $params = $this->getRequest()->getParams();
28
+ if (isset($params['id']) && isset($params['topic']) && $params['topic'] == 'payment'){
29
+ $model = Mage::getModel('mercadopago_standard/checkout');
30
+ $response = $model->getPayment($params['id']);
31
+
32
+ if($response['status'] == 200 || $response['status'] == 201):
33
+ $message = "";
34
+ $status = "";
35
+ $payment = $response['response']['collection'];
36
+
37
+ $order = Mage::getModel('sales/order')->loadByIncrementId($payment["external_reference"]);
38
+
39
+ //update info de status no pagamento
40
+ $payment_order = $order->getPayment();
41
+ $payment_order->setAdditionalInformation('status',$payment['status']);
42
+ $payment_order->setAdditionalInformation('status_detail',$payment['status_detail']);
43
+ $payment_order->setAdditionalInformation('payment_id',$payment['id']);
44
+
45
+ if($payment_order->getAdditionalInformation('cardholderName') == ""):
46
+ $payment_order->setAdditionalInformation('cardholderName', $payment['payer']['first_name'] . " " . $payment['payer']['last_name']);
47
+ endif;
48
+
49
+ if($payment_order->getAdditionalInformation('payment_method') == ""):
50
+ $payment_order->setAdditionalInformation('payment_method', $payment['payment_method_id']);
51
+ endif;
52
+
53
+ if($payment_order->getAdditionalInformation('statement_descriptor') == ""):
54
+ if(isset($payment['statement_descriptor'])):
55
+ $payment_order->setAdditionalInformation('statement_descriptor', $payment['statement_descriptor']);
56
+ endif;
57
+ endif;
58
+
59
+ if($payment_order->getAdditionalInformation('trunc_card') == ""):
60
+ if(isset($payment['last_four_digits'])):
61
+ $payment_order->setAdditionalInformation('trunc_card', "XXXXXXXXXXXX" . $payment['last_four_digits']);
62
+ endif;
63
+
64
+ endif;
65
+
66
+ $payment_order->save();
67
+
68
+ //adiciona informações sobre o comprador na order
69
+ if ($payment['payer']['first_name'])
70
+ $order->setCustomerFirstname($payment['payer']['first_name']);
71
+ if ($payment['payer']['last_name'])
72
+ $order->setCustomerLastname($payment['payer']['last_name']);
73
+ if ($payment['payer']['email'])
74
+ $order->setCustomerEmail($payment['payer']['email']);
75
+
76
+ $order->save();
77
+
78
+ switch ( $payment['status']) {
79
+
80
+ case 'approved':
81
+ //add status na order
82
+ $message = Mage::helper('mercadopago_transparent')->__('Automatic notification of the MercadoPago: The payment was approved.');
83
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_approved');
84
+
85
+ //cria a invoice
86
+ $invoice = $order->prepareInvoice();
87
+ $invoice->register()->pay();
88
+ Mage::getModel('core/resource_transaction')
89
+ ->addObject($invoice)
90
+ ->addObject($invoice->getOrder())
91
+ ->save();
92
+
93
+ $invoice->sendEmail(true, $message);
94
+ break;
95
+ case 'refunded':
96
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_refunded');
97
+ $message = Mage::helper('mercadopago_transparent')->__('Automatic notification of the MercadoPago: The payment was refunded.');
98
+ $order->cancel();
99
+ break;
100
+ case 'pending':
101
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_in_process');
102
+ $message = Mage::helper('mercadopago_transparent')->__('Automatic notification of the MercadoPago: The payment is being processed.');
103
+ break;
104
+ case 'in_process':
105
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_in_process');
106
+ $message = Mage::helper('mercadopago_transparent')->__('Automatic notification of the MercadoPago: The payment is being processed. Will be approved within 2 business days.');
107
+ break;
108
+ case 'in_mediation':
109
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_in_mediation');
110
+ $message = Mage::helper('mercadopago_transparent')->__('Automatic notification of the MercadoPago: The payment is in the process of Dispute, check the graphic account of the MercadoPago for more information.');
111
+ break;
112
+ case 'cancelled':
113
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_cancelled');
114
+ $message = Mage::helper('mercadopago_transparent')->__('Automatic notification of the MercadoPago: The payment was cancelled.');
115
+ $order->cancel();
116
+ break;
117
+ case 'rejected':
118
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_rejected');
119
+ $message = Mage::helper('mercadopago_transparent')->__('Automatic notification of the MercadoPago: The payment was rejected.');
120
+ break;
121
+ default:
122
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_in_process');
123
+ $message = '';
124
+ }
125
+
126
+ //adiciona informações do pagamento
127
+ $message .= Mage::helper('mercadopago_transparent')->__('<br/> Payment id: %s', $payment['id']);
128
+ $message .= Mage::helper('mercadopago_transparent')->__('<br/> Status: %s', $payment['status']);
129
+ $message .= Mage::helper('mercadopago_transparent')->__('<br/> Status Detail: %s', $payment['status_detail']);
130
+
131
+ $order->addStatusToHistory($status,$message, true);
132
+ $order->sendOrderUpdateEmail(true, $message);
133
+
134
+ $order->save();
135
+ echo $message;
136
+ else:
137
+ //caso de algum erro na consulta da ipn
138
+ header(' ', true, 404);
139
+ exit;
140
+ endif;
141
+
142
+ }elseif(isset($params['topic']) && $params['topic'] == 'merchant_order'){
143
+
144
+ $model = Mage::getModel('mercadopago_transparent/transparent');
145
+ $response = $model->getMerchantOrder($params['id']);
146
+
147
+ if($response['status'] == 200 || $response['status'] == 201):
148
+ $message = "";
149
+ $status = "";
150
+ $merchant_order = $response['response'];
151
+ $order = Mage::getModel('sales/order')->loadByIncrementId($merchant_order["external_reference"]);
152
+
153
+ switch ( $merchant_order['status']) {
154
+
155
+ case 'opened':
156
+ $message = 'Payment flow started. The order still dont have payments recorded.';
157
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_in_process');
158
+
159
+ $message .= "<br /> Merchant Order: " . $merchant_order['id'];
160
+ $message .= "<br /> Status: " . $merchant_order['status'];
161
+
162
+ $order->addStatusToHistory($status,$message);
163
+ $order->save();
164
+ echo $message;
165
+ break;
166
+
167
+ /*
168
+ case 'closed':
169
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_refunded');
170
+ $message = 'A payment was created and it was associated to the order.';
171
+ break;
172
+ case 'expired':
173
+ $status = Mage::getStoreConfig('payment/mercadopago_configuration/order_status_in_process');
174
+ $message = 'Order cancelled by the seller.';
175
+ break;
176
+ default:
177
+
178
+ $message = "";
179
+ */
180
+ }
181
+
182
+ else:
183
+ //caso de algum erro na consulta da ipn
184
+ header(' ', true, 404);
185
+ exit;
186
+ endif;
187
+ }
188
+
189
+ }
190
+ }
app/code/community/MercadoPago/Standard/controllers/PayController.php ADDED
@@ -0,0 +1,64 @@
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_Standard_PayController extends Mage_Core_Controller_Front_Action{
18
+
19
+ // /mercadopago_strandard/pay
20
+ public function indexAction(){
21
+ $init_point = "";
22
+
23
+
24
+ //chama model para fazer o post do pagamento
25
+ $response = Mage::getModel('mercadopago_standard/checkout')->postPago();
26
+
27
+ if($response['status'] == 200 || $response['status'] == 201):
28
+ $payment = $response['response'];
29
+ $init_point = $payment['init_point'];
30
+
31
+ endif;
32
+
33
+ $this->loadLayout();
34
+
35
+ //cria um block e adiciona uma view
36
+ $block = $this->getLayout()->createBlock(
37
+ 'Mage_Core_Block_Template',
38
+ 'mercadopago_standard/pay',
39
+ array('template' => 'mercadopago/standard/pay.phtml')
40
+ );
41
+
42
+ //envia as informações para view
43
+ $block->assign(
44
+ array(
45
+ "init_point" => $init_point,
46
+ "type_checkout" => Mage::getModel('mercadopago_standard/checkout')->getConfigData('type_checkout'),
47
+ "iframe_width" => Mage::getModel('mercadopago_standard/checkout')->getConfigData('iframe_width'),
48
+ "iframe_height" => Mage::getModel('mercadopago_standard/checkout')->getConfigData('iframe_height'),
49
+ "banner_checkout" => Mage::getModel('mercadopago_standard/checkout')->getConfigData('banner_checkout')
50
+ )
51
+ );
52
+
53
+ //insere o block
54
+ $this->getLayout()->getBlock('content')->append($block);
55
+ $this->_initLayoutMessages('core/session');
56
+
57
+ //adiciona uma clean page
58
+ $root = $this->getLayout()->getBlock('root');
59
+ $root->setTemplate("mercadopago/clean_page.phtml");
60
+
61
+ $this->renderLayout();
62
+ }
63
+
64
+ }
app/code/community/MercadoPago/Standard/etc/config.xml ADDED
@@ -0,0 +1,120 @@
1
+ <?xml version="1.0" ?>
2
+ <!--
3
+ /**
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL).
8
+ * It is also available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category Payment Gateway
12
+ * @package MercadoPago
13
+ * @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
14
+ * @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ -->
18
+ <config>
19
+ <modules>
20
+ <MercadoPago_Standard>
21
+ <version>2.0.0</version>
22
+ </MercadoPago_Standard>
23
+ </modules>
24
+
25
+ <global>
26
+ <models>
27
+ <mercadopago_standard>
28
+ <class>MercadoPago_Standard_Model</class>
29
+ </mercadopago_standard>
30
+ </models>
31
+ <blocks>
32
+ <mercadopago_standard>
33
+ <class>MercadoPago_Standard_Block</class>
34
+ </mercadopago_standard>
35
+ </blocks>
36
+ <helpers>
37
+ <mercadopago_standard>
38
+ <class>MercadoPago_Standard_Helper</class>
39
+ </mercadopago_standard>
40
+ </helpers>
41
+
42
+ <events>
43
+ <admin_system_config_changed_section_payment>
44
+ <observers>
45
+ <observer>
46
+ <class>MercadoPago_Standard_Model_Observer</class>
47
+ <method>checkAndValidData</method>
48
+ </observer>
49
+ </observers>
50
+ </admin_system_config_changed_section_payment>
51
+ </events>
52
+ </global>
53
+
54
+
55
+ <frontend>
56
+ <routers>
57
+ <mercadopago_standard>
58
+ <use>standard</use>
59
+ <args>
60
+ <module>MercadoPago_Standard</module>
61
+ <frontName>mercadopago_standard</frontName>
62
+ </args>
63
+ </mercadopago_standard>
64
+ </routers>
65
+ <translate>
66
+ <modules>
67
+ <mercadopago>
68
+ <files>
69
+ <default>mercadopago.csv</default>
70
+ </files>
71
+ </mercadopago>
72
+ </modules>
73
+ </translate>
74
+ </frontend>
75
+
76
+
77
+ <adminhtml>
78
+ <translate>
79
+ <modules>
80
+ <translations>
81
+ <files>
82
+ <default>mercadopago.csv</default>
83
+ </files>
84
+ </translations>
85
+ </modules>
86
+ </translate>
87
+ </adminhtml>
88
+
89
+
90
+ <default>
91
+ <payment>
92
+
93
+ <mercadopago_configuration>
94
+ <country>mlb</country>
95
+ <order_status_approved>processing</order_status_approved>
96
+ <order_status_refunded>pending</order_status_refunded>
97
+ <order_status_in_process>pending</order_status_in_process>
98
+ <order_status_in_mediation>pending</order_status_in_mediation>
99
+ <order_status_rejected>pending</order_status_rejected>
100
+ <order_status_cancelled>pending</order_status_cancelled>
101
+ </mercadopago_configuration>
102
+
103
+ <mercadopago_standard>
104
+ <active>1</active>
105
+ <model>MercadoPago_Standard_Model_Checkout</model>
106
+ <!-- nome do modulo na exibição para o comprador -->
107
+ <title>MercadoPago</title>
108
+ <allowspecific>0</allowspecific>
109
+ <banner_checkout>http://imgmp.mlstatic.com/org-img/MLB/MP/BANNERS/tipo2_468X60.jpg</banner_checkout>
110
+ <sort_order>-1</sort_order>
111
+ <installments>24</installments>
112
+ <type_checkout>iframe</type_checkout>
113
+ <auto_return>1</auto_return>
114
+ <iframe_width>900</iframe_width>
115
+ <iframe_height>600</iframe_height>
116
+ </mercadopago_standard>
117
+ </payment>
118
+ </default>
119
+
120
+ </config>
app/code/community/MercadoPago/Standard/etc/system.xml ADDED
@@ -0,0 +1,256 @@
1
+ <?xml version="1.0" ?>
2
+ <!--
3
+ /**
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL).
8
+ * It is also available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category Payment Gateway
12
+ * @package MercadoPago
13
+ * @author Gabriel Matsuoka (gabriel.matsuoka@gmail.com)
14
+ * @copyright Copyright (c) MercadoPago [http://www.mercadopago.com]
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ -->
18
+
19
+ <config>
20
+ <sections>
21
+ <payment translate="label">
22
+ <groups>
23
+
24
+ <mercadopago_configuration>
25
+ <label>MercadoPago - Configuration</label>
26
+ <sort_order>99</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>0</show_in_store>
30
+ <fields>
31
+
32
+ <client_id translate="label">
33
+ <label>Client Id</label>
34
+ <frontend_type>text</frontend_type>
35
+ <sort_order>3</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>0</show_in_store>
39
+ </client_id>
40
+
41
+ <client_secret translate="label">
42
+ <label>Client Secret</label>
43
+ <frontend_type>text</frontend_type>
44
+ <sort_order>4</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>1</show_in_website>
47
+ <show_in_store>0</show_in_store>
48
+ </client_secret>
49
+
50
+ <country translate="label">
51
+ <label>Country</label>
52
+ <frontend_type>select</frontend_type>
53
+ <source_model>MercadoPago_Standard_Model_Source_Country</source_model>
54
+ <sort_order>6</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>1</show_in_website>
57
+ <show_in_store>1</show_in_store>
58
+ </country>
59
+
60
+ <category_id translate="label">
61
+ <label>Category of your store</label>
62
+ <frontend_type>select</frontend_type>
63
+ <source_model>MercadoPago_Standard_Model_Source_CategoryId</source_model>
64
+ <sort_order>7</sort_order>
65
+ <show_in_default>1</show_in_default>
66
+ <show_in_website>1</show_in_website>
67
+ <show_in_store>0</show_in_store>
68
+ </category_id>
69
+
70
+ <order_status_approved translate="label">
71
+ <label>Choose the status of approved orders</label>
72
+ <comment>To manage the status available go to System > Order Statuses</comment>
73
+ <frontend_type>select</frontend_type>
74
+ <source_model>adminhtml/system_config_source_order_status</source_model>
75
+ <sort_order>8</sort_order>
76
+ <show_in_default>1</show_in_default>
77
+ <show_in_website>1</show_in_website>
78
+ <show_in_store>1</show_in_store>
79
+ </order_status_approved>
80
+
81
+ <order_status_refunded translate="label">
82
+ <label>Choose the status of refunded orders</label>
83
+ <comment>To manage the status available go to System > Order Statuses</comment>
84
+ <frontend_type>select</frontend_type>
85
+ <source_model>adminhtml/system_config_source_order_status</source_model>
86
+ <sort_order>9</sort_order>
87
+ <show_in_default>1</show_in_default>
88
+ <show_in_website>1</show_in_website>
89
+ <show_in_store>1</show_in_store>
90
+ </order_status_refunded>
91
+
92
+ <order_status_in_process translate="label">
93
+ <label>Choose the status when payment is pending</label>
94
+ <comment>To manage the status available go to System > Order Statuses</comment>
95
+ <frontend_type>select</frontend_type>
96
+ <source_model>adminhtml/system_config_source_order_status</source_model>
97
+ <sort_order>9</sort_order>
98
+ <show_in_default>1</show_in_default>
99
+ <show_in_website>1</show_in_website>
100
+ <show_in_store>1</show_in_store>
101
+ </order_status_in_process>
102
+
103
+ <order_status_in_mediation translate="label">
104
+ <label>Choose the status when client open a mediation</label>
105
+ <comment>To manage the status available go to System > Order Statuses</comment>
106
+ <frontend_type>select</frontend_type>
107
+ <source_model>adminhtml/system_config_source_order_status</source_model>
108
+ <sort_order>10</sort_order>
109
+ <show_in_default>1</show_in_default>
110
+ <show_in_website>1</show_in_website>
111
+ <show_in_store>1</show_in_store>
112
+ </order_status_in_mediation>
113
+
114
+ <order_status_rejected translate="label">
115
+ <label>Choose the status when payment was reject</label>
116
+ <comment>To manage the status available go to System > Order Statuses</comment>
117
+ <frontend_type>select</frontend_type>
118
+ <source_model>adminhtml/system_config_source_order_status</source_model>
119
+ <sort_order>11</sort_order>
120
+ <show_in_default>1</show_in_default>
121
+ <show_in_website>1</show_in_website>
122
+ <show_in_store>1</show_in_store>
123
+ </order_status_rejected>
124
+
125
+ <order_status_cancelled translate="label">
126
+ <label>Choose the status when payment was canceled</label>
127
+ <comment>To manage the status available go to System > Order Statuses</comment>
128
+ <frontend_type>select</frontend_type>
129
+ <source_model>adminhtml/system_config_source_order_status</source_model>
130
+ <sort_order>12</sort_order>
131
+ <show_in_default>1</show_in_default>
132
+ <show_in_website>1</show_in_website>
133
+ <show_in_store>1</show_in_store>
134
+ </order_status_cancelled>
135
+
136
+ </fields>
137
+ </mercadopago_configuration>
138
+
139
+
140
+ <mercadopago_standard module="mercadopago_standard">
141
+ <label>MercadoPago Standard - Credit Card, Ticket and Account Money</label>
142
+ <sort_order>102</sort_order>
143
+ <show_in_default>1</show_in_default>
144
+ <show_in_website>1</show_in_website>
145
+ <show_in_store>0</show_in_store>
146
+ <fields>
147
+ <active translate="label">
148
+ <label>Enabled</label>
149
+ <frontend_type>select</frontend_type>
150
+ <source_model>adminhtml/system_config_source_yesno</source_model>
151
+ <sort_order>1</sort_order>
152
+ <show_in_default>1</show_in_default>
153
+ <show_in_website>1</show_in_website>
154
+ <show_in_store>0</show_in_store>
155
+ <comment>For the operation of the Checkout Standard is necessary to configure the Credentials 'CLIENT_ID' and 'CLIENT_SECRET' in 'MercadoPago - Configuration'</comment>
156
+ </active>
157
+
158
+ <title translate="label">
159
+ <label>Payment Title</label>
160
+ <frontend_type>text</frontend_type>
161
+ <sort_order>2</sort_order>
162
+ <show_in_default>1</show_in_default>
163
+ <show_in_website>1</show_in_website>
164
+ <show_in_store>0</show_in_store>
165
+ </title>
166
+
167
+
168
+ <banner_checkout translate="label">
169
+ <label>Banner Checkout</label>
170
+ <frontend_type>text</frontend_type>
171
+ <sort_order>3</sort_order>
172
+ <show_in_default>1</show_in_default>
173
+ <show_in_website>1</show_in_website>
174
+ <show_in_store>0</show_in_store>
175
+ </banner_checkout>
176
+
177
+ <sort_order translate="label">
178
+ <label>Checkout Position</label>
179
+ <frontend_type>text</frontend_type>
180
+ <sort_order>4</sort_order>
181
+ <show_in_default>1</show_in_default>
182
+ <show_in_website>1</show_in_website>
183
+ <show_in_store>0</show_in_store>
184
+ <frontend_class>validate-number</frontend_class>
185
+ </sort_order>
186
+
187
+ <type_checkout>
188
+ <label>Type Checkout</label>
189
+ <frontend_type>select</frontend_type>
190
+ <source_model>MercadoPago_Standard_Model_Source_TypeCheckout</source_model>
191
+ <sort_order>5</sort_order>
192
+ <show_in_default>1</show_in_default>
193
+ <show_in_website>1</show_in_website>
194
+ <show_in_store>1</show_in_store>
195
+ </type_checkout>
196
+
197
+ <auto_return translate="label">
198
+ <label>Auto Redirect</label>
199
+ <frontend_type>select</frontend_type>
200
+ <source_model>adminhtml/system_config_source_yesno</source_model>
201
+ <sort_order>6</sort_order>
202
+ <show_in_default>1</show_in_default>
203
+ <show_in_website>1</show_in_website>
204
+ <show_in_store>0</show_in_store>
205
+ <comment>Auto-redirect the buyer when finishing the payment.</comment>
206
+ </auto_return>
207
+
208
+ <excluded_payment_methods translate="label">
209
+ <label>Exclude Payment Methods</label>
210
+ <comment>Select payment methods not accepted</comment>
211
+ <frontend_type>multiselect</frontend_type>
212
+ <source_model>MercadoPago_Standard_Model_Source_PaymentMethods</source_model>
213
+ <sort_order>8</sort_order>
214
+ <show_in_default>1</show_in_default>
215
+ <show_in_website>1</show_in_website>
216
+ <show_in_store>1</show_in_store>
217
+ <can_be_empty>1</can_be_empty>
218
+ </excluded_payment_methods>
219
+
220
+ <installments>
221
+ <label>Maximum number of accepted installments</label>
222
+ <frontend_type>select</frontend_type>
223
+ <source_model>MercadoPago_Standard_Model_Source_Installments</source_model>
224
+ <sort_order>9</sort_order>
225
+ <show_in_default>1</show_in_default>
226
+ <show_in_website>1</show_in_website>
227
+ <show_in_store>1</show_in_store>
228
+ </installments>
229
+
230
+
231
+ <iframe_width translate="label">
232
+ <label>Width Checkout Iframe</label>
233
+ <frontend_type>text</frontend_type>
234
+ <sort_order>10</sort_order>
235
+ <show_in_default>1</show_in_default>
236
+ <show_in_website>1</show_in_website>
237
+ <show_in_store>0</show_in_store>
238
+ <frontend_class>validate-number</frontend_class>
239
+ </iframe_width>
240
+
241
+ <iframe_height translate="label">
242
+ <label>Height Checkout Iframe</label>
243
+ <frontend_type>text</frontend_type>
244
+ <sort_order>11</sort_order>
245
+ <show_in_default>1</show_in_default>
246
+ <show_in_website>1</show_in_website>
247
+ <show_in_store>0</show_in_store>
248
+ <frontend_class>validate-number</frontend_class>
249
+ </iframe_height>
250
+
251
+ </fields>
252
+ </mercadopago_standard>
253
+ </groups>
254
+ </payment>
255
+ </sections>
256
+ </config>
app/code/community/MercadoPago/Transparent/.DS_Store ADDED
Binary file
app/code/community/MercadoPago/Transparent/Block/.DS_Store ADDED
Binary file
app/code/community/MercadoPago/Transparent/Block/Form.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
+
18
+ class MercadoPago_Transparent_Block_Form extends Mage_Payment_Block_Form_Cc{
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('mercadopago_transparent/transparent');
34
+ $public_key = $model->getConfigData('public_key');
35
+
36
+ //init js no header
37
+ $block = Mage::app()->getLayout()->createBlock('core/text', 'js_mercadopago');
38
+ $block->setText(
39
+ sprintf(
40
+ '
41
+ <script type="text/javascript">var PublicKeyMercadoPagoTransparent = "' . $public_key .'"; </script>
42
+ <script type="text/javascript" src="%s"></script>',
43
+ Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS, true) . 'mercadopago/mercadopago.js'
44
+ )
45
+ );
46
+
47
+ $head = Mage::app()->getLayout()->getBlock('after_body_start');
48
+
49
+ if($head){
50
+ $head->append($block);
51
+ }
52
+
53
+ return parent::_prepareLayout();
54
+ }
55
+
56
+ /*
57
+ *
58
+ * Fun��o especifica para mexico
59
+ *
60
+ */
61
+ function getCardsPaymentMethods(){
62
+ $payment_methods = Mage::getModel('mercadopago_transparent/transparent')->getPaymentMethods();
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 tickets
70
+ if(in_array($pm['payment_type_id'], $payment_methods_types)){
71
+ $types[] = $pm;
72
+ }
73
+ }
74
+
75
+ return $types;
76
+ }
77
+ }
78
+
79
+
80
+
81
+
82
+ ?>
app/code/community/MercadoPago/Transparent/Block/Info.php ADDED
@@ -0,0 +1,36 @@
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_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
+ public function getOrder() {
32
+
33
+ return $this->getInfo();
34
+
35
+ }
36
+ }
app/code/community/MercadoPago/Transparent/Block/Success.php ADDED
@@ -0,0 +1,36 @@
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_Transparent_Block_Success extends Mage_Core_Block_Template{
19
+
20
+ protected function _construct(){
21
+
22
+ parent::_construct();
23
+ $this->setTemplate('mercadopago/transparent/success.phtml');
24
+
25
+ return $this->toHtml();
26
+ }
27
+
28
+
29
+ public function getOrder() {
30
+
31
+ $orderIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
32
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
33
+
34
+ return $order;
35
+ }
36
+ }
app/code/community/MercadoPago/Transparent/Helper/Data.php ADDED
@@ -0,0 +1,22 @@
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
+ <?php
18
+
19
+
20
+ class MercadoPago_Transparent_Helper_Data extends Mage_Payment_Helper_Data{
21
+
22
+ }
app/code/community/MercadoPago/Transparent/Model/.DS_Store ADDED
Binary file
app/code/community/MercadoPago/Transparent/Model/Resource/Setup.php ADDED
@@ -0,0 +1,14 @@
1
+ <?php
2
+
3
+ /*
4
+ * To change this template, choose Tools | Templates
5
+ * and open the template in the editor.
6
+ */
7
+
8
+ class MercadoPago_Transparent_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup {
9
+
10
+ }
11
+
12
+
13
+
14
+ ?>
app/code/community/MercadoPago/Transparent/Model/Source/CategoryId.php ADDED
@@ -0,0 +1,44 @@
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_Transparent_Model_Source_CategoryId extends Mage_Payment_Model_Method_Abstract{
20
+
21
+ public function toOptionArray (){
22
+
23
+ $response = MPRestClient::get("/item_categories");
24
+ $response = $response['response'];
25
+
26
+ $cat = array();
27
+ $count = 0;
28
+ foreach($response as $v):
29
+ //force category others first
30
+ if($v['id'] == "others"):
31
+ $cat[0] = array('value' => $v['id'], 'label'=>Mage::helper('adminhtml')->__($v['description']));
32
+ else:
33
+ $count++;
34
+ $cat[$count] = array('value' => $v['id'], 'label'=>Mage::helper('adminhtml')->__($v['description']));
35
+ endif;
36
+
37
+ endforeach;
38
+
39
+ //force order by key
40
+ ksort($cat);
41
+ return $cat;
42
+
43
+ }
44
+ }
app/code/community/MercadoPago/Transparent/Model/Transparent.php ADDED
@@ -0,0 +1,393 @@
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_Transparent_Model_Transparent extends Mage_Payment_Model_Method_Abstract{
20
+
21
+ //configura o block do formulario e de informações sobre o pagamento
22
+ protected $_formBlockType = 'mercadopago_transparent/form';
23
+ protected $_infoBlockType = 'mercadopago_transparent/info';
24
+
25
+ protected $_code = 'mercadopago_transparent';
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_transparent')->__('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($info_form['card_token_id'] != ""):
90
+ $info->setAdditionalInformation('expiration_date', $info_form['cardExpirationMonth'] . "/" . $info_form['cardExpirationYear']);
91
+ $info->setAdditionalInformation('cardholderName', $info_form['cardholderName']);
92
+ $info->setAdditionalInformation('trunc_card', $info_form['trunc_card']);
93
+ endif;
94
+
95
+
96
+ //caso seja não tenha card_token_id
97
+ if($info_form['card_token_id'] == ""):
98
+ Mage::throwException(Mage::helper('mercadopago_transparent')->__('Verify the form data or wait until the validation of the payment data'));
99
+ return false;
100
+ endif;
101
+
102
+
103
+ return $this;
104
+ }
105
+
106
+ /**
107
+ * @return Mage_Checkout_Model_Session
108
+ */
109
+ protected function _getCheckout() {
110
+ return Mage::getSingleton('checkout/session');
111
+ }
112
+
113
+ /**
114
+ * Get admin checkout session namespace
115
+ *
116
+ * @return Mage_Adminhtml_Model_Session_Quote
117
+ */
118
+ protected function _getAdminCheckout() {
119
+ return Mage::getSingleton('adminhtml/session_quote');
120
+ }
121
+
122
+ /**
123
+ * Retrieves Quote
124
+ *
125
+ * @param integer $quoteId
126
+ * @return Mage_Sales_Model_Quote
127
+ */
128
+ protected function _getQuote($quoteId = null) {
129
+ if (!empty($quoteId)) {
130
+ return Mage::getModel('sales/quote')->load($quoteId);
131
+ }
132
+ else {
133
+ if(Mage::app()->getStore()->isAdmin()) {
134
+ return $this->_getAdminCheckout()->getQuote();
135
+ } else {
136
+ return $this->_getCheckout()->getQuote();
137
+ }
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Retrieves Order
143
+ *
144
+ * @param integer $incrementId
145
+ * @return Mage_Sales_Model_Order
146
+ */
147
+ protected function _getOrder($incrementId) {
148
+ return Mage::getModel('sales/order')->loadByIncrementId($incrementId);
149
+ }
150
+
151
+
152
+
153
+ public function getDiscount(){
154
+ $discount = 0;
155
+ $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
156
+
157
+ if(isset($totals['discount']) && $totals['discount']->getValue()) {
158
+ $discount = $totals['discount']->getValue();
159
+ }
160
+
161
+ return $discount;
162
+ }
163
+
164
+ public function postPago(){
165
+
166
+ //seta sdk php mercadopago
167
+ $client_id = Mage::getStoreConfig('payment/mercadopago_configuration/client_id');
168
+ $client_secret = Mage::getStoreConfig('payment/mercadopago_configuration/client_secret');
169
+
170
+ $mp = new MP($client_id, $client_secret);
171
+
172
+ //monta a preferencia
173
+ $pref = $this->makePreference();
174
+
175
+ //faz o post do pagamento
176
+ $response = $mp->create_custon_payment($pref);
177
+
178
+ if($response['status'] == 200 || $response['status'] == 201):
179
+ return $response;
180
+ else:
181
+ $e = "";
182
+ foreach($response['response']['cause'] as $error):
183
+ switch ($error['code']) {
184
+ case "106":
185
+ $e .= Mage::helper('mercadopago_transparent')->__('You can not make payments to users in other countries.');
186
+ break;
187
+
188
+ case "109":
189
+ $e .= Mage::helper('mercadopago_transparent')->__('Payment Method selected does not process payments in installments selected. Choose another card or another payment method.');
190
+ break;
191
+
192
+ case "126":
193
+ $e .= Mage::helper('mercadopago_transparent')->__('We could not process your payment. Error code: 126.');
194
+ break;
195
+
196
+ case "129":
197
+ $e .= Mage::helper('mercadopago_transparent')->__('Payment Method selected does not process payments for the selected amount. Choose another card or another payment method.');
198
+ break;
199
+
200
+ case "145":
201
+ $e .= Mage::helper('mercadopago_transparent')->__('We could not process your payment. Error code: 145.');
202
+ break;
203
+
204
+ case "150":
205
+ $e .= Mage::helper('mercadopago_transparent')->__('You can not make payments. Error code: 150.');
206
+ break;
207
+
208
+ case "151":
209
+ $e .= Mage::helper('mercadopago_transparent')->__('You can not make payments.');
210
+ break;
211
+
212
+ case "160":
213
+ $e .= Mage::helper('mercadopago_transparent')->__('We could not process your payment. Error code: 160.');
214
+ break;
215
+
216
+ case "204":
217
+ $e .= Mage::helper('mercadopago_transparent')->__('Payment Method selected is not available at this time. Choose another card or another payment method.');
218
+ break;
219
+
220
+ case "801":
221
+ $e .= Mage::helper('mercadopago_transparent')->__('You made a similar payment moments ago. Try again in a few minutes.');
222
+ break;
223
+
224
+ default:
225
+ $e .= Mage::helper('mercadopago_transparent')->__("We could not process your payment. %s", $this->htmlEscape(json_encode($error)));
226
+ break;
227
+ }
228
+
229
+ endforeach;
230
+
231
+ Mage::throwException($e);
232
+ return false;
233
+ endif;
234
+
235
+ }
236
+
237
+ function makePreference(){
238
+
239
+ $quote = $this->_getQuote();
240
+ $orderId = $quote->getReservedOrderId();
241
+ $order = $this->_getOrder($orderId);
242
+
243
+
244
+ $customer = Mage::getSingleton('customer/session')->getCustomer();
245
+ $model = Mage::getModel('catalog/product');
246
+
247
+
248
+ //pega payment dentro da order para pegar as informacoes adicionadas pela funcao assignData()
249
+ $payment = $order->getPayment();
250
+
251
+ //pega valor total da compra
252
+ $item_price = $order->getBaseGrandTotal();
253
+ if (!$item_price) {
254
+ $item_price = $order->getBasePrice() + $order->getBaseShippingAmount();
255
+ }
256
+
257
+ //pega o valor total da compra somando o frete
258
+ $item_price = number_format($item_price, 2, '.', '');
259
+
260
+ //setta informaçnoes
261
+ $arr = array();
262
+ $arr['external_reference'] = $orderId;
263
+ $arr['amount'] = (float) $item_price;
264
+ $arr['reason'] = Mage::helper('mercadopago_transparent')->__("Order # %s in store %s", $orderId, Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK,true));
265
+ //não é necessario settar currency_id, pois ja identifica no backend
266
+ //$arr['currency_id'] = "BRL";
267
+ $arr['installments'] = (int) $payment->getAdditionalInformation("installments");
268
+ $arr['payment_method_id'] = $payment->getAdditionalInformation("payment_method");
269
+ $arr['payer_email'] = htmlentities($customer->getEmail());
270
+
271
+ if($payment->getAdditionalInformation("card_token_id") != ""){
272
+ $arr['card_token_id'] = $payment->getAdditionalInformation("card_token_id");
273
+ }
274
+
275
+ if($payment->getAdditionalInformation("issuers") != ""){
276
+ $arr['card_issuer_id'] = (int) $payment->getAdditionalInformation("issuers");
277
+ }
278
+
279
+
280
+ //monta array de produtos
281
+ $arr['items'] = array();
282
+ foreach ($order->getAllVisibleItems() as $item) {
283
+
284
+ $prod = $model->loadByAttribute('sku', $item->getSku());
285
+
286
+ //get image
287
+ try{
288
+ $imagem = $prod->getImageUrl();
289
+ }catch(Exception $e){
290
+ $imagem = "";
291
+