WooCommerce MercadoPago - Version 3.0.1

Version Description

Download this release

Release Info

Developer marcelohama
Plugin Icon 128x128 WooCommerce MercadoPago
Version 3.0.1
Comparing to
See all releases

Code changes from version 3.0.0 to 3.0.1

Files changed (98) hide show
  1. assets/css/custom_checkout_mercadopago.css +0 -0
  2. assets/images/MCO/CUPOM_MCO.jpg +0 -0
  3. assets/images/MCO/MCO.png +0 -0
  4. assets/images/MCO/banner_all_methods.png +0 -0
  5. assets/images/MCO/credit_card.png +0 -0
  6. assets/images/MCO/standard_mco.jpg +0 -0
  7. assets/images/MLA/CUPOM_MLA.jpg +0 -0
  8. assets/images/MLA/MLA.png +0 -0
  9. assets/images/MLA/banner_all_methods.png +0 -0
  10. assets/images/MLA/credit_card.png +0 -0
  11. assets/images/MLA/standard_mla.jpg +0 -0
  12. assets/images/MLB/CUPOM_MLB.jpg +0 -0
  13. assets/images/MLB/MLB.png +0 -0
  14. assets/images/MLB/banner_all_methods.png +0 -0
  15. assets/images/MLB/credit_card.png +0 -0
  16. assets/images/MLB/cupom1.jpg +0 -0
  17. assets/images/MLB/cupom2.jpg +0 -0
  18. assets/images/MLB/cupom3.jpg +0 -0
  19. assets/images/MLB/desconto_MLB.jpg +0 -0
  20. assets/images/MLB/standard_mlb.jpg +0 -0
  21. assets/images/MLC/CUPOM_MLC.jpg +0 -0
  22. assets/images/MLC/MLC.png +0 -0
  23. assets/images/MLC/banner_all_methods.png +0 -0
  24. assets/images/MLC/credit_card.png +0 -0
  25. assets/images/MLC/standard_mlc.gif +0 -0
  26. assets/images/MLM/CUPOM_MLM.jpg +0 -0
  27. assets/images/MLM/MLM.png +0 -0
  28. assets/images/MLM/banner_all_methods.png +0 -0
  29. assets/images/MLM/credit_card.png +0 -0
  30. assets/images/MLM/standard_mlm.jpg +0 -0
  31. assets/images/MLU/CUPOM_MLU.png +0 -0
  32. assets/images/MLU/MLU.png +0 -0
  33. assets/images/MLU/banner_all_methods.png +0 -0
  34. assets/images/MLU/credit_card.png +0 -0
  35. assets/images/MLU/standard_mlu.png +0 -0
  36. assets/images/MLV/CUPOM_MLV.jpg +0 -0
  37. assets/images/MLV/MLV.png +0 -0
  38. assets/images/MLV/banner_all_methods.png +0 -0
  39. assets/images/MLV/credit_card.png +0 -0
  40. assets/images/MLV/standard_mlv.jpg +0 -0
  41. assets/images/MPE/CUPOM_MPE.png +0 -0
  42. assets/images/MPE/MPE.png +0 -0
  43. assets/images/MPE/banner_all_methods.png +0 -0
  44. assets/images/MPE/credit_card.png +0 -0
  45. assets/images/MPE/standard_mpe.png +0 -0
  46. assets/images/bandeiras/amex.png +0 -0
  47. assets/images/bandeiras/boleto.png +0 -0
  48. assets/images/bandeiras/cash.png +0 -0
  49. assets/images/bandeiras/diners.png +0 -0
  50. assets/images/bandeiras/elo.png +0 -0
  51. assets/images/bandeiras/hipercard.png +0 -0
  52. assets/images/bandeiras/master.png +0 -0
  53. assets/images/bandeiras/melicard.png +0 -0
  54. assets/images/bandeiras/visa.png +0 -0
  55. assets/images/banner.png +0 -0
  56. assets/images/bar_code.png +0 -0
  57. assets/images/boleto.png +0 -0
  58. assets/images/cart.png +0 -0
  59. assets/images/check.png +0 -0
  60. assets/images/credit_card.png +0 -0
  61. assets/images/cvv.png +0 -0
  62. assets/images/error.png +0 -0
  63. assets/images/loading.gif +0 -0
  64. assets/images/mercadopago.png +0 -0
  65. assets/images/mplogo.png +0 -0
  66. assets/images/warning.png +0 -0
  67. assets/js/credit-card.js +0 -0
  68. assets/js/ticket.js +0 -0
  69. i18n/languages/woocommerce-mercadopago-es_AR.mo +0 -0
  70. i18n/languages/woocommerce-mercadopago-es_AR.po +3 -0
  71. i18n/languages/woocommerce-mercadopago-es_CL.mo +0 -0
  72. i18n/languages/woocommerce-mercadopago-es_CL.po +3 -0
  73. i18n/languages/woocommerce-mercadopago-es_CO.mo +0 -0
  74. i18n/languages/woocommerce-mercadopago-es_CO.po +3 -0
  75. i18n/languages/woocommerce-mercadopago-es_ES.mo +0 -0
  76. i18n/languages/woocommerce-mercadopago-es_ES.po +3 -0
  77. i18n/languages/woocommerce-mercadopago-es_MX.mo +0 -0
  78. i18n/languages/woocommerce-mercadopago-es_MX.po +6 -0
  79. i18n/languages/woocommerce-mercadopago-es_PE.mo +0 -0
  80. i18n/languages/woocommerce-mercadopago-es_PE.po +6 -0
  81. i18n/languages/woocommerce-mercadopago-es_UY.mo +0 -0
  82. i18n/languages/woocommerce-mercadopago-es_UY.po +6 -0
  83. i18n/languages/woocommerce-mercadopago-es_VE.mo +0 -0
  84. i18n/languages/woocommerce-mercadopago-es_VE.po +7 -1
  85. i18n/languages/woocommerce-mercadopago-pt_BR.mo +0 -0
  86. i18n/languages/woocommerce-mercadopago-pt_BR.po +7 -1
  87. i18n/languages/woocommerce-mercadopago.pot +3 -0
  88. includes/WC_WooMercadoPago_BasicGateway.php +3 -5
  89. includes/WC_WooMercadoPago_CustomGateway.php +7 -6
  90. includes/WC_WooMercadoPago_SubscriptionGateway.php +3 -5
  91. includes/WC_WooMercadoPago_TicketGateway.php +7 -6
  92. includes/class-wc-product-mp_recurrent.php +0 -0
  93. includes/sdk/lib/mercadopago.php +1 -1
  94. README.txt → readme.txt +20 -4
  95. templates/credit-card/payment-form.php +1082 -6
  96. templates/mp_main_settings.php +11 -0
  97. templates/ticket/ticket-form.php +579 -7
  98. woocommerce-mercadopago.php +57 -31
assets/css/custom_checkout_mercadopago.css CHANGED
File without changes
assets/images/MCO/CUPOM_MCO.jpg CHANGED
File without changes
assets/images/MCO/MCO.png CHANGED
File without changes
assets/images/MCO/banner_all_methods.png CHANGED
File without changes
assets/images/MCO/credit_card.png CHANGED
File without changes
assets/images/MCO/standard_mco.jpg CHANGED
File without changes
assets/images/MLA/CUPOM_MLA.jpg CHANGED
File without changes
assets/images/MLA/MLA.png CHANGED
File without changes
assets/images/MLA/banner_all_methods.png CHANGED
File without changes
assets/images/MLA/credit_card.png CHANGED
File without changes
assets/images/MLA/standard_mla.jpg CHANGED
File without changes
assets/images/MLB/CUPOM_MLB.jpg CHANGED
File without changes
assets/images/MLB/MLB.png CHANGED
File without changes
assets/images/MLB/banner_all_methods.png CHANGED
File without changes
assets/images/MLB/credit_card.png CHANGED
File without changes
assets/images/MLB/cupom1.jpg CHANGED
File without changes
assets/images/MLB/cupom2.jpg CHANGED
File without changes
assets/images/MLB/cupom3.jpg CHANGED
File without changes
assets/images/MLB/desconto_MLB.jpg CHANGED
File without changes
assets/images/MLB/standard_mlb.jpg CHANGED
File without changes
assets/images/MLC/CUPOM_MLC.jpg CHANGED
File without changes
assets/images/MLC/MLC.png CHANGED
File without changes
assets/images/MLC/banner_all_methods.png CHANGED
File without changes
assets/images/MLC/credit_card.png CHANGED
File without changes
assets/images/MLC/standard_mlc.gif CHANGED
File without changes
assets/images/MLM/CUPOM_MLM.jpg CHANGED
File without changes
assets/images/MLM/MLM.png CHANGED
File without changes
assets/images/MLM/banner_all_methods.png CHANGED
File without changes
assets/images/MLM/credit_card.png CHANGED
File without changes
assets/images/MLM/standard_mlm.jpg CHANGED
File without changes
assets/images/MLU/CUPOM_MLU.png CHANGED
File without changes
assets/images/MLU/MLU.png CHANGED
File without changes
assets/images/MLU/banner_all_methods.png CHANGED
File without changes
assets/images/MLU/credit_card.png CHANGED
File without changes
assets/images/MLU/standard_mlu.png CHANGED
File without changes
assets/images/MLV/CUPOM_MLV.jpg CHANGED
File without changes
assets/images/MLV/MLV.png CHANGED
File without changes
assets/images/MLV/banner_all_methods.png CHANGED
File without changes
assets/images/MLV/credit_card.png CHANGED
File without changes
assets/images/MLV/standard_mlv.jpg CHANGED
File without changes
assets/images/MPE/CUPOM_MPE.png CHANGED
File without changes
assets/images/MPE/MPE.png CHANGED
File without changes
assets/images/MPE/banner_all_methods.png CHANGED
File without changes
assets/images/MPE/credit_card.png CHANGED
File without changes
assets/images/MPE/standard_mpe.png CHANGED
File without changes
assets/images/bandeiras/amex.png CHANGED
File without changes
assets/images/bandeiras/boleto.png CHANGED
File without changes
assets/images/bandeiras/cash.png CHANGED
File without changes
assets/images/bandeiras/diners.png CHANGED
File without changes
assets/images/bandeiras/elo.png CHANGED
File without changes
assets/images/bandeiras/hipercard.png CHANGED
File without changes
assets/images/bandeiras/master.png CHANGED
File without changes
assets/images/bandeiras/melicard.png CHANGED
File without changes
assets/images/bandeiras/visa.png CHANGED
File without changes
assets/images/banner.png CHANGED
File without changes
assets/images/bar_code.png CHANGED
File without changes
assets/images/boleto.png CHANGED
File without changes
assets/images/cart.png CHANGED
File without changes
assets/images/check.png CHANGED
File without changes
assets/images/credit_card.png CHANGED
File without changes
assets/images/cvv.png CHANGED
File without changes
assets/images/error.png CHANGED
File without changes
assets/images/loading.gif CHANGED
File without changes
assets/images/mercadopago.png CHANGED
File without changes
assets/images/mplogo.png CHANGED
File without changes
assets/images/warning.png CHANGED
File without changes
assets/js/credit-card.js CHANGED
File without changes
assets/js/ticket.js CHANGED
File without changes
i18n/languages/woocommerce-mercadopago-es_AR.mo CHANGED
Binary file
i18n/languages/woocommerce-mercadopago-es_AR.po CHANGED
@@ -754,6 +754,9 @@ msgstr "Pago convertido de"
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
 
 
 
757
  msgid "Parameter cardIssuerId can not be null/empty"
758
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
759
 
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
757
+ msgid "Choose"
758
+ msgstr "Seleccione"
759
+
760
  msgid "Parameter cardIssuerId can not be null/empty"
761
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
762
 
i18n/languages/woocommerce-mercadopago-es_CL.mo CHANGED
Binary file
i18n/languages/woocommerce-mercadopago-es_CL.po CHANGED
@@ -754,6 +754,9 @@ msgstr "Pago convertido de"
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
 
 
 
757
  msgid "Parameter cardIssuerId can not be null/empty"
758
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
759
 
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
757
+ msgid "Choose"
758
+ msgstr "Seleccione"
759
+
760
  msgid "Parameter cardIssuerId can not be null/empty"
761
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
762
 
i18n/languages/woocommerce-mercadopago-es_CO.mo CHANGED
Binary file
i18n/languages/woocommerce-mercadopago-es_CO.po CHANGED
@@ -754,6 +754,9 @@ msgstr "Pago convertido de"
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
 
 
 
757
  msgid "Parameter cardIssuerId can not be null/empty"
758
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
759
 
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
757
+ msgid "Choose"
758
+ msgstr "Seleccione"
759
+
760
  msgid "Parameter cardIssuerId can not be null/empty"
761
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
762
 
i18n/languages/woocommerce-mercadopago-es_ES.mo CHANGED
Binary file
i18n/languages/woocommerce-mercadopago-es_ES.po CHANGED
@@ -754,6 +754,9 @@ msgstr "Pago convertido de"
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
 
 
 
757
  msgid "Parameter cardIssuerId can not be null/empty"
758
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
759
 
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
757
+ msgid "Choose"
758
+ msgstr "Seleccione"
759
+
760
  msgid "Parameter cardIssuerId can not be null/empty"
761
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
762
 
i18n/languages/woocommerce-mercadopago-es_MX.mo CHANGED
Binary file
i18n/languages/woocommerce-mercadopago-es_MX.po CHANGED
@@ -754,6 +754,9 @@ msgstr "Pago convertido de"
754
  msgid "Installments"
755
  msgstr "Mensualidades"
756
 
 
 
 
757
  msgid "Parameter cardIssuerId can not be null/empty"
758
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
759
 
@@ -1005,3 +1008,6 @@ msgstr "RAZÓN SOCIAL"
1005
 
1006
  msgid "CNPJ"
1007
  msgstr "CNPJ"
 
 
 
754
  msgid "Installments"
755
  msgstr "Mensualidades"
756
 
757
+ msgid "Choose"
758
+ msgstr "Seleccione"
759
+
760
  msgid "Parameter cardIssuerId can not be null/empty"
761
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
762
 
1008
 
1009
  msgid "CNPJ"
1010
  msgstr "CNPJ"
1011
+
1012
+ msgid "Custom Domain for IPN"
1013
+ msgstr "Dominio personalizado para IPN"
i18n/languages/woocommerce-mercadopago-es_PE.mo CHANGED
Binary file
i18n/languages/woocommerce-mercadopago-es_PE.po CHANGED
@@ -754,6 +754,9 @@ msgstr "Pago convertido de"
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
 
 
 
757
  msgid "Parameter cardIssuerId can not be null/empty"
758
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
759
 
@@ -1005,3 +1008,6 @@ msgstr "RAZÓN SOCIAL"
1005
 
1006
  msgid "CNPJ"
1007
  msgstr "CNPJ"
 
 
 
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
757
+ msgid "Choose"
758
+ msgstr "Seleccione"
759
+
760
  msgid "Parameter cardIssuerId can not be null/empty"
761
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
762
 
1008
 
1009
  msgid "CNPJ"
1010
  msgstr "CNPJ"
1011
+
1012
+ msgid "Custom Domain for IPN"
1013
+ msgstr "Dominio personalizado para IPN"
i18n/languages/woocommerce-mercadopago-es_UY.mo CHANGED
Binary file
i18n/languages/woocommerce-mercadopago-es_UY.po CHANGED
@@ -754,6 +754,9 @@ msgstr "Pago convertido de"
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
 
 
 
757
  msgid "Parameter cardIssuerId can not be null/empty"
758
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
759
 
@@ -1005,3 +1008,6 @@ msgstr "RAZÓN SOCIAL"
1005
 
1006
  msgid "CNPJ"
1007
  msgstr "CNPJ"
 
 
 
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
757
+ msgid "Choose"
758
+ msgstr "Seleccione"
759
+
760
  msgid "Parameter cardIssuerId can not be null/empty"
761
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
762
 
1008
 
1009
  msgid "CNPJ"
1010
  msgstr "CNPJ"
1011
+
1012
+ msgid "Custom Domain for IPN"
1013
+ msgstr "Dominio personalizado para IPN"
i18n/languages/woocommerce-mercadopago-es_VE.mo CHANGED
Binary file
i18n/languages/woocommerce-mercadopago-es_VE.po CHANGED
@@ -19,7 +19,7 @@ msgstr ""
19
  "X-Poedit-Basepath: ../Documents/woocommerce (MAMP)/wp-content/plugins/woo-mercado-pago-module\n"
20
  "X-Generator: Poedit 1.8.7\n"
21
  "Last-Translator: \n"
22
- "Language: es_MX\n"
23
  "X-Poedit-SearchPath-0: .\n"
24
 
25
  msgid "This is the <strong>oficial</strong> module of Mercado Pago for WooCommerce plugin. This module enables WooCommerce to use Mercado Pago as a payment Gateway for purchases made in your e-commerce store."
@@ -754,6 +754,9 @@ msgstr "Pago convertido de"
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
 
 
 
757
  msgid "Parameter cardIssuerId can not be null/empty"
758
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
759
 
@@ -1005,3 +1008,6 @@ msgstr "RAZÓN SOCIAL"
1005
 
1006
  msgid "CNPJ"
1007
  msgstr "CNPJ"
 
 
 
19
  "X-Poedit-Basepath: ../Documents/woocommerce (MAMP)/wp-content/plugins/woo-mercado-pago-module\n"
20
  "X-Generator: Poedit 1.8.7\n"
21
  "Last-Translator: \n"
22
+ "Language: es_VE\n"
23
  "X-Poedit-SearchPath-0: .\n"
24
 
25
  msgid "This is the <strong>oficial</strong> module of Mercado Pago for WooCommerce plugin. This module enables WooCommerce to use Mercado Pago as a payment Gateway for purchases made in your e-commerce store."
754
  msgid "Installments"
755
  msgstr "Cuotas"
756
 
757
+ msgid "Choose"
758
+ msgstr "Seleccione"
759
+
760
  msgid "Parameter cardIssuerId can not be null/empty"
761
  msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
762
 
1008
 
1009
  msgid "CNPJ"
1010
  msgstr "CNPJ"
1011
+
1012
+ msgid "Custom Domain for IPN"
1013
+ msgstr "Dominio personalizado para IPN"
i18n/languages/woocommerce-mercadopago-pt_BR.mo CHANGED
Binary file
i18n/languages/woocommerce-mercadopago-pt_BR.po CHANGED
@@ -19,7 +19,7 @@ msgstr ""
19
  "X-Poedit-Basepath: ../Documents/woocommerce (MAMP)/wp-content/plugins/woo-mercado-pago-module\n"
20
  "X-Generator: Poedit 1.8.7\n"
21
  "Last-Translator: \n"
22
- "Language: es_MX\n"
23
  "X-Poedit-SearchPath-0: .\n"
24
 
25
  msgid "This is the <strong>oficial</strong> module of Mercado Pago for WooCommerce plugin. This module enables WooCommerce to use Mercado Pago as a payment Gateway for purchases made in your e-commerce store."
@@ -754,6 +754,9 @@ msgstr "Pagamento convertido de"
754
  msgid "Installments"
755
  msgstr "Parcelas"
756
 
 
 
 
757
  msgid "Parameter cardIssuerId can not be null/empty"
758
  msgstr "O campo [Emitente do cartão] não pode ser nulo/vazio"
759
 
@@ -1005,3 +1008,6 @@ msgstr "RAZÃO SOCIAL"
1005
 
1006
  msgid "CNPJ"
1007
  msgstr "CNPJ"
 
 
 
19
  "X-Poedit-Basepath: ../Documents/woocommerce (MAMP)/wp-content/plugins/woo-mercado-pago-module\n"
20
  "X-Generator: Poedit 1.8.7\n"
21
  "Last-Translator: \n"
22
+ "Language: pt_BR\n"
23
  "X-Poedit-SearchPath-0: .\n"
24
 
25
  msgid "This is the <strong>oficial</strong> module of Mercado Pago for WooCommerce plugin. This module enables WooCommerce to use Mercado Pago as a payment Gateway for purchases made in your e-commerce store."
754
  msgid "Installments"
755
  msgstr "Parcelas"
756
 
757
+ msgid "Choose"
758
+ msgstr "Escolher"
759
+
760
  msgid "Parameter cardIssuerId can not be null/empty"
761
  msgstr "O campo [Emitente do cartão] não pode ser nulo/vazio"
762
 
1008
 
1009
  msgid "CNPJ"
1010
  msgstr "CNPJ"
1011
+
1012
+ msgid "Custom Domain for IPN"
1013
+ msgstr "Domínio Customizado para IPN"
i18n/languages/woocommerce-mercadopago.pot CHANGED
@@ -754,6 +754,9 @@ msgstr ""
754
  msgid "Installments"
755
  msgstr ""
756
 
 
 
 
757
  msgid "Parameter cardIssuerId can not be null/empty"
758
  msgstr ""
759
 
754
  msgid "Installments"
755
  msgstr ""
756
 
757
+ msgid "Choose"
758
+ msgstr ""
759
+
760
  msgid "Parameter cardIssuerId can not be null/empty"
761
  msgstr ""
762
 
includes/WC_WooMercadoPago_BasicGateway.php CHANGED
@@ -35,7 +35,7 @@ class WC_WooMercadoPago_BasicGateway extends WC_Payment_Gateway {
35
  $this->supports = array( 'products', 'refunds' );
36
  $this->icon = apply_filters(
37
  'woocommerce_mercadopago_icon',
38
- plugins_url( 'assets/images/mplogo.png', plugin_dir_path( __FILE__ ) )
39
  );
40
 
41
  $this->method_title = __( 'Mercado Pago - Basic Checkout', 'woocommerce-mercadopago' );
@@ -922,9 +922,7 @@ class WC_WooMercadoPago_BasicGateway extends WC_Payment_Gateway {
922
 
923
  // Do not set IPN url if it is a localhost.
924
  if ( ! strrpos( get_site_url(), 'localhost' ) ) {
925
- $preferences['notification_url'] = WC_Woo_Mercado_Pago_Module::workaround_ampersand_bug(
926
- esc_url( WC()->api_request_url( 'WC_WooMercadoPago_BasicGateway' ) )
927
- );
928
  }
929
 
930
  // Set sponsor ID.
@@ -1050,7 +1048,7 @@ class WC_WooMercadoPago_BasicGateway extends WC_Payment_Gateway {
1050
  $price_percent = $this->gateway_discount / 100;
1051
  if ( $price_percent > 0 ) {
1052
  $title .= ' (' . __( 'Discount of', 'woocommerce-mercadopago' ) . ' ' .
1053
- strip_tags( wc_price( $total * $price_percent ) ) . ' )';
1054
  }
1055
  return $title;
1056
  }
35
  $this->supports = array( 'products', 'refunds' );
36
  $this->icon = apply_filters(
37
  'woocommerce_mercadopago_icon',
38
+ plugins_url( 'assets/images/mercadopago.png', plugin_dir_path( __FILE__ ) )
39
  );
40
 
41
  $this->method_title = __( 'Mercado Pago - Basic Checkout', 'woocommerce-mercadopago' );
922
 
923
  // Do not set IPN url if it is a localhost.
924
  if ( ! strrpos( get_site_url(), 'localhost' ) ) {
925
+ $preferences['notification_url'] = WC()->api_request_url( 'WC_WooMercadoPago_BasicGateway' );
 
 
926
  }
927
 
928
  // Set sponsor ID.
1048
  $price_percent = $this->gateway_discount / 100;
1049
  if ( $price_percent > 0 ) {
1050
  $title .= ' (' . __( 'Discount of', 'woocommerce-mercadopago' ) . ' ' .
1051
+ strip_tags( wc_price( $total * $price_percent ) ) . ')';
1052
  }
1053
  return $title;
1054
  }
includes/WC_WooMercadoPago_CustomGateway.php CHANGED
@@ -827,9 +827,7 @@ class WC_WooMercadoPago_CustomGateway extends WC_Payment_Gateway {
827
 
828
  // Do not set IPN url if it is a localhost.
829
  if ( ! strrpos( get_site_url(), 'localhost' ) ) {
830
- $preferences['notification_url'] = WC_Woo_Mercado_Pago_Module::workaround_ampersand_bug(
831
- esc_url( WC()->api_request_url( 'WC_WooMercadoPago_CustomGateway' ) )
832
- );
833
  }
834
 
835
  // Discounts features.
@@ -1011,7 +1009,7 @@ class WC_WooMercadoPago_CustomGateway extends WC_Payment_Gateway {
1011
  $price_percent = $this->gateway_discount / 100;
1012
  if ( $price_percent > 0 ) {
1013
  $title .= ' (' . __( 'Discount of', 'woocommerce-mercadopago' ) . ' ' .
1014
- strip_tags( wc_price( $total * $price_percent ) ) . ' )';
1015
  }
1016
  }
1017
  }
@@ -1032,9 +1030,12 @@ class WC_WooMercadoPago_CustomGateway extends WC_Payment_Gateway {
1032
  }
1033
  global $woocommerce;
1034
  $w_cart = $woocommerce->cart;
1035
- // Check if we have SSL.
 
1036
  if ( empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ) {
1037
- return false;
 
 
1038
  }
1039
  // Check for recurrent product checkout.
1040
  if ( isset( $w_cart ) ) {
827
 
828
  // Do not set IPN url if it is a localhost.
829
  if ( ! strrpos( get_site_url(), 'localhost' ) ) {
830
+ $preferences['notification_url'] = WC()->api_request_url( 'WC_WooMercadoPago_CustomGateway' );
 
 
831
  }
832
 
833
  // Discounts features.
1009
  $price_percent = $this->gateway_discount / 100;
1010
  if ( $price_percent > 0 ) {
1011
  $title .= ' (' . __( 'Discount of', 'woocommerce-mercadopago' ) . ' ' .
1012
+ strip_tags( wc_price( $total * $price_percent ) ) . ')';
1013
  }
1014
  }
1015
  }
1030
  }
1031
  global $woocommerce;
1032
  $w_cart = $woocommerce->cart;
1033
+ // If we do not have SSL in production environment, we are not allowed to process.
1034
+ $_mp_debug_mode = get_option( '_mp_debug_mode', '' );
1035
  if ( empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ) {
1036
+ if ( empty ( $_mp_debug_mode ) ) {
1037
+ return false;
1038
+ }
1039
  }
1040
  // Check for recurrent product checkout.
1041
  if ( isset( $w_cart ) ) {
includes/WC_WooMercadoPago_SubscriptionGateway.php CHANGED
@@ -35,7 +35,7 @@ class WC_WooMercadoPago_SubscriptionGateway extends WC_Payment_Gateway {
35
  //$this->supports = array( 'products', 'refunds' );
36
  $this->icon = apply_filters(
37
  'woocommerce_mercadopago_icon',
38
- plugins_url( 'assets/images/mplogo.png', plugin_dir_path( __FILE__ ) )
39
  );
40
 
41
  $this->method_title = __( 'Mercado Pago - Subscription', 'woocommerce-mercadopago' );
@@ -663,9 +663,7 @@ class WC_WooMercadoPago_SubscriptionGateway extends WC_Payment_Gateway {
663
 
664
  // Do not set IPN url if it is a localhost.
665
  if ( ! strrpos( get_site_url(), 'localhost' ) ) {
666
- $preapproval['notification_url'] = WC_Woo_Mercado_Pago_Module::workaround_ampersand_bug(
667
- esc_url( WC()->api_request_url( 'WC_WooMercadoPago_SubscriptionGateway' ) )
668
- );
669
  }
670
 
671
  // Set sponsor ID.
@@ -793,7 +791,7 @@ class WC_WooMercadoPago_SubscriptionGateway extends WC_Payment_Gateway {
793
  $price_percent = $this->gateway_discount / 100;
794
  if ( $price_percent > 0 ) {
795
  $title .= ' (' . __( 'Discount of', 'woocommerce-mercadopago' ) . ' ' .
796
- strip_tags( wc_price( $total * $price_percent ) ) . ' )';
797
  }
798
  }
799
  }
35
  //$this->supports = array( 'products', 'refunds' );
36
  $this->icon = apply_filters(
37
  'woocommerce_mercadopago_icon',
38
+ plugins_url( 'assets/images/mercadopago.png', plugin_dir_path( __FILE__ ) )
39
  );
40
 
41
  $this->method_title = __( 'Mercado Pago - Subscription', 'woocommerce-mercadopago' );
663
 
664
  // Do not set IPN url if it is a localhost.
665
  if ( ! strrpos( get_site_url(), 'localhost' ) ) {
666
+ $preferences['notification_url'] = WC()->api_request_url( 'WC_WooMercadoPago_SubscriptionGateway' );
 
 
667
  }
668
 
669
  // Set sponsor ID.
791
  $price_percent = $this->gateway_discount / 100;
792
  if ( $price_percent > 0 ) {
793
  $title .= ' (' . __( 'Discount of', 'woocommerce-mercadopago' ) . ' ' .
794
+ strip_tags( wc_price( $total * $price_percent ) ) . ')';
795
  }
796
  }
797
  }
includes/WC_WooMercadoPago_TicketGateway.php CHANGED
@@ -864,9 +864,7 @@ class WC_WooMercadoPago_TicketGateway extends WC_Payment_Gateway {
864
 
865
  // Do not set IPN url if it is a localhost.
866
  if ( ! strrpos( get_site_url(), 'localhost' ) ) {
867
- $preferences['notification_url'] = WC_Woo_Mercado_Pago_Module::workaround_ampersand_bug(
868
- esc_url( WC()->api_request_url( 'WC_WooMercadoPago_TicketGateway' ) )
869
- );
870
  }
871
 
872
  // Discounts features.
@@ -999,7 +997,7 @@ class WC_WooMercadoPago_TicketGateway extends WC_Payment_Gateway {
999
  $price_percent = $this->gateway_discount / 100;
1000
  if ( $price_percent > 0 ) {
1001
  $title .= ' (' . __( 'Discount of', 'woocommerce-mercadopago' ) . ' ' .
1002
- strip_tags( wc_price( $total * $price_percent ) ) . ' )';
1003
  }
1004
  }
1005
  }
@@ -1020,9 +1018,12 @@ class WC_WooMercadoPago_TicketGateway extends WC_Payment_Gateway {
1020
  }
1021
  global $woocommerce;
1022
  $w_cart = $woocommerce->cart;
1023
- // Check if we have SSL.
 
1024
  if ( empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ) {
1025
- return false;
 
 
1026
  }
1027
  // Check for recurrent product checkout.
1028
  if ( isset( $w_cart ) ) {
864
 
865
  // Do not set IPN url if it is a localhost.
866
  if ( ! strrpos( get_site_url(), 'localhost' ) ) {
867
+ $preferences['notification_url'] = WC()->api_request_url( 'WC_WooMercadoPago_TicketGateway' );
 
 
868
  }
869
 
870
  // Discounts features.
997
  $price_percent = $this->gateway_discount / 100;
998
  if ( $price_percent > 0 ) {
999
  $title .= ' (' . __( 'Discount of', 'woocommerce-mercadopago' ) . ' ' .
1000
+ strip_tags( wc_price( $total * $price_percent ) ) . ')';
1001
  }
1002
  }
1003
  }
1018
  }
1019
  global $woocommerce;
1020
  $w_cart = $woocommerce->cart;
1021
+ // If we do not have SSL in production environment, we are not allowed to process.
1022
+ $_mp_debug_mode = get_option( '_mp_debug_mode', '' );
1023
  if ( empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ) {
1024
+ if ( empty ( $_mp_debug_mode ) ) {
1025
+ return false;
1026
+ }
1027
  }
1028
  // Check for recurrent product checkout.
1029
  if ( isset( $w_cart ) ) {
includes/class-wc-product-mp_recurrent.php CHANGED
File without changes
includes/sdk/lib/mercadopago.php CHANGED
@@ -12,7 +12,7 @@ $GLOBALS['LIB_LOCATION'] = dirname( __FILE__ );
12
 
13
  class MP {
14
 
15
- private $version = '3.0.0';
16
  private $client_id;
17
  private $client_secret;
18
  private $ll_access_token;
12
 
13
  class MP {
14
 
15
+ private $version = '3.0.1';
16
  private $client_id;
17
  private $client_secret;
18
  private $ll_access_token;
README.txt → readme.txt RENAMED
@@ -2,9 +2,10 @@
2
  Contributors: mercadopago, mercadolivre, claudiosanches
3
  Donate link: https://www.mercadopago.com.br/developers/
4
  Tags: ecommerce, mercadopago, woocommerce
5
- Requires at least: WooCommerce 2.6.x
6
- Tested up to: WooCommerce 3.0.0
7
- Stable tag: 3.0.0
 
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -30,6 +31,10 @@ Mercado Pago owns the highest security standards with PCI certification level 1
30
  * Subscriptions;
31
  * Seller's Protection Program.
32
 
 
 
 
 
33
  == Installation ==
34
 
35
  You have two ways to install this module: from your WordPress Store, or by downloading and manually copying the module directory.
@@ -40,7 +45,7 @@ You have two ways to install this module: from your WordPress Store, or by downl
40
  3. You should find the module read to be installed. Click install.
41
 
42
  = Manual Download =
43
- 1. Get the module sources from a repository (<a href="https://github.com/mercadopago/cart-woocommerce/archive/master.zip">Github</a> or <a href="https://downloads.wordpress.org/plugin/woocommerce-mercadopago.3.0.0.zip">WordPress Plugin Directory</a>);
44
  2. Unzip the folder and find "woocommerce-mercadopago" directory;
45
  3. Copy "woocommerce-mercadopago" directory to **[WordPressRootDirectory]/wp-content/plugins/** directory.
46
 
@@ -96,11 +101,22 @@ Please, check our FAQ at: https://www.mercadopago.com.br/ajuda/
96
 
97
  == Changelog ==
98
 
 
 
 
 
 
 
 
 
 
 
99
  = v3.0.0 - 25/09/2017 =
100
  * Features
101
  - All features already present in <a href="https://br.wordpress.org/plugins/woocommerce-mercadopago/">Woo-Mercado-Pago-Module 2.x</a>;
102
  - Customization of status mappings between order and payments.
103
  * Improvements
 
104
  - Optimization in HTTP requests and algorithms;
105
  - Removal of several redundancies;
106
  - HTML and Javascript separation;
2
  Contributors: mercadopago, mercadolivre, claudiosanches
3
  Donate link: https://www.mercadopago.com.br/developers/
4
  Tags: ecommerce, mercadopago, woocommerce
5
+ Requires at least: 4.8
6
+ Tested up to: 4.8
7
+ Requires PHP: 5.6
8
+ Stable tag: 3.0.1
9
  License: GPLv2 or later
10
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
 
31
  * Subscriptions;
32
  * Seller's Protection Program.
33
 
34
+ = Compatibility =
35
+
36
+ - WooCommerce 3.0 or later.
37
+
38
  == Installation ==
39
 
40
  You have two ways to install this module: from your WordPress Store, or by downloading and manually copying the module directory.
45
  3. You should find the module read to be installed. Click install.
46
 
47
  = Manual Download =
48
+ 1. Get the module sources from a repository (<a href="https://github.com/mercadopago/cart-woocommerce/archive/master.zip">Github</a> or <a href="https://downloads.wordpress.org/plugin/woocommerce-mercadopago.3.0.1.zip">WordPress Plugin Directory</a>);
49
  2. Unzip the folder and find "woocommerce-mercadopago" directory;
50
  3. Copy "woocommerce-mercadopago" directory to **[WordPressRootDirectory]/wp-content/plugins/** directory.
51
 
101
 
102
  == Changelog ==
103
 
104
+ = v3.0.1 (04/10/2017) =
105
+ * Bug fixes
106
+ - We fixed a Javascript problem that are occurring when payments were retried in custom checkout and tickets;
107
+ - Resolved the size of Mercado Pago icon in checkout form.
108
+ * Improvements
109
+ - Allowing absence of SSL if debug mode is enabled;
110
+ - Optmizations in form layout of custom checkout and tickets;
111
+ - Validating currency consistency before trying conversions;
112
+ - References to the new docummentations.
113
+
114
  = v3.0.0 - 25/09/2017 =
115
  * Features
116
  - All features already present in <a href="https://br.wordpress.org/plugins/woocommerce-mercadopago/">Woo-Mercado-Pago-Module 2.x</a>;
117
  - Customization of status mappings between order and payments.
118
  * Improvements
119
+ - Added CNPJ document for brazilian tickets;
120
  - Optimization in HTTP requests and algorithms;
121
  - Removal of several redundancies;
122
  - HTML and Javascript separation;
templates/credit-card/payment-form.php CHANGED
@@ -25,10 +25,9 @@ if ( ! defined( 'ABSPATH' ) ) {
25
  </div>
26
  </div>
27
 
28
- <fieldset id="custom_checkout_fieldset" style="margin:0px; background:white; display: none;">
29
 
30
- <div class="mp-box-inputs mp-line" id="mercadopago-form-coupon"
31
- style="padding:0px 12px 16px 12px;">
32
  <label for="couponCodeLabel">
33
  <?php echo esc_html__( 'Discount Coupon', 'woocommerce-mercadopago' ); ?>
34
  </label>
@@ -50,7 +49,7 @@ if ( ! defined( 'ABSPATH' ) ) {
50
  </div>
51
 
52
  <!-- payment method -->
53
- <div id="mercadopago-form-customer-and-card" style="padding:0px 12px 0px 12px;">
54
  <div class="mp-box-inputs mp-line">
55
  <label for="paymentMethodIdSelector">
56
  <?php echo esc_html__( 'Payment Method', 'woocommerce-mercadopago' ); ?> <em>*</em>
@@ -99,7 +98,7 @@ if ( ! defined( 'ABSPATH' ) ) {
99
  </div>
100
  </div> <!-- end mercadopago-form-osc -->
101
 
102
- <div id="mercadopago-form" style="padding:0px 12px 0px 12px;">
103
  <!-- Card Number -->
104
  <div class="mp-box-inputs mp-col-100">
105
  <label for="cardNumber">
@@ -272,9 +271,1086 @@ if ( ! defined( 'ABSPATH' ) ) {
272
 
273
  </fieldset>
274
 
275
- <script type="text/javascript" src="<?php echo $path_to_javascript; ?>"/>
276
 
277
  <script type="text/javascript">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  MPv1.text.apply = "<?php echo __( 'Apply', 'woocommerce-mercadopago' ); ?>";
279
  MPv1.text.remove = "<?php echo __( 'Remove', 'woocommerce-mercadopago' ); ?>";
280
  MPv1.text.coupon_empty = "<?php echo __( 'Please, inform your coupon code', 'woocommerce-mercadopago' ); ?>";
25
  </div>
26
  </div>
27
 
28
+ <fieldset id="custom_checkout_fieldset" style="margin:-1px; background:white; display: none;">
29
 
30
+ <div class="mp-box-inputs mp-line" id="mercadopago-form-coupon" style="padding:0px 24px 16px 24px;">
 
31
  <label for="couponCodeLabel">
32
  <?php echo esc_html__( 'Discount Coupon', 'woocommerce-mercadopago' ); ?>
33
  </label>
49
  </div>
50
 
51
  <!-- payment method -->
52
+ <div id="mercadopago-form-customer-and-card" style="padding:0px 24px 0px 24px;">
53
  <div class="mp-box-inputs mp-line">
54
  <label for="paymentMethodIdSelector">
55
  <?php echo esc_html__( 'Payment Method', 'woocommerce-mercadopago' ); ?> <em>*</em>
98
  </div>
99
  </div> <!-- end mercadopago-form-osc -->
100
 
101
+ <div id="mercadopago-form" style="padding:0px 24px 0px 24px;">
102
  <!-- Card Number -->
103
  <div class="mp-box-inputs mp-col-100">
104
  <label for="cardNumber">
271
 
272
  </fieldset>
273
 
274
+ <!--<script type="text/javascript" src="<?php echo $path_to_javascript; ?>"/>-->
275
 
276
  <script type="text/javascript">
277
+ ( function() {
278
+
279
+ var MPv1 = {
280
+ debug: true,
281
+ add_truncated_card: true,
282
+ site_id: "",
283
+ public_key: "",
284
+ coupon_of_discounts: {
285
+ discount_action_url: "",
286
+ payer_email: "",
287
+ default: true,
288
+ status: false
289
+ },
290
+ customer_and_card: {
291
+ default: true,
292
+ status: true
293
+ },
294
+ create_token_on: {
295
+ event: true, //if true create token on event, if false create on click and ignore others
296
+ keyup: false,
297
+ paste: true
298
+ },
299
+ inputs_to_create_discount: [
300
+ "couponCode",
301
+ "applyCoupon"
302
+ ],
303
+ inputs_to_create_token: [
304
+ "cardNumber",
305
+ "cardExpirationMonth",
306
+ "cardExpirationYear",
307
+ "cardholderName",
308
+ "securityCode",
309
+ "docType",
310
+ "docNumber"
311
+ ],
312
+ inputs_to_create_token_customer_and_card: [
313
+ "paymentMethodSelector",
314
+ "securityCode"
315
+ ],
316
+ selectors: {
317
+ // currency
318
+ currency_ratio: "#currency_ratio",
319
+ // coupom
320
+ couponCode: "#couponCode",
321
+ applyCoupon: "#applyCoupon",
322
+ mpCouponApplyed: "#mpCouponApplyed",
323
+ mpCouponError: "#mpCouponError",
324
+ campaign_id: "#campaign_id",
325
+ campaign: "#campaign",
326
+ discount: "#discount",
327
+ // customer cards
328
+ paymentMethodSelector: "#paymentMethodSelector",
329
+ pmCustomerAndCards: "#payment-methods-for-customer-and-cards",
330
+ pmListOtherCards: "#payment-methods-list-other-cards",
331
+ // card data
332
+ mpSecurityCodeCustomerAndCard: "#mp-securityCode-customer-and-card",
333
+ cardNumber: "#cardNumber",
334
+ cardExpirationMonth: "#cardExpirationMonth",
335
+ cardExpirationYear: "#cardExpirationYear",
336
+ cardholderName: "#cardholderName",
337
+ securityCode: "#securityCode",
338
+ docType: "#docType",
339
+ docNumber: "#docNumber",
340
+ issuer: "#issuer",
341
+ installments: "#installments",
342
+ // document
343
+ mpDoc: ".mp-doc",
344
+ mpIssuer: ".mp-issuer",
345
+ mpDocType: ".mp-docType",
346
+ mpDocNumber: ".mp-docNumber",
347
+ // payment method and checkout
348
+ paymentMethodId: "#paymentMethodId",
349
+ amount: "#amount",
350
+ token: "#token",
351
+ cardTruncated: "#cardTruncated",
352
+ site_id: "#site_id",
353
+ CustomerAndCard: "#CustomerAndCard",
354
+ box_loading: "#mp-box-loading",
355
+ submit: "#submit",
356
+ // tax resolution AG 51/2017
357
+ boxInstallments: "#mp-box-installments",
358
+ boxInstallmentsSelector: "#mp-box-installments-selector",
359
+ taxCFT: "#mp-box-input-tax-cft",
360
+ taxTEA: "#mp-box-input-tax-tea",
361
+ taxTextCFT: "#mp-tax-cft-text",
362
+ taxTextTEA: "#mp-tax-tea-text",
363
+ // form
364
+ form: "#mercadopago-form",
365
+ formCoupon: "#mercadopago-form-coupon",
366
+ formCustomerAndCard: "#mercadopago-form-customer-and-card",
367
+ utilities_fields: "#mercadopago-utilities"
368
+ },
369
+ text: {
370
+ choose: "Choose",
371
+ other_bank: "Other Bank",
372
+ discount_info1: "You will save",
373
+ discount_info2: "with discount from",
374
+ discount_info3: "Total of your purchase:",
375
+ discount_info4: "Total of your purchase with discount:",
376
+ discount_info5: "*Uppon payment approval",
377
+ discount_info6: "Terms and Conditions of Use",
378
+ coupon_empty: "Please, inform your coupon code",
379
+ apply: "Apply",
380
+ remove: "Remove"
381
+ },
382
+ paths: {
383
+ loading: "images/loading.gif",
384
+ check: "images/check.png",
385
+ error: "images/error.png"
386
+ }
387
+ }
388
+
389
+ // === Coupon of Discounts
390
+
391
+ MPv1.currencyIdToCurrency = function ( currency_id ) {
392
+ if ( currency_id == "ARS" ) {
393
+ return "$";
394
+ } else if ( currency_id == "BRL" ) {
395
+ return "R$";
396
+ } else if ( currency_id == "COP" ) {
397
+ return "$";
398
+ } else if ( currency_id == "CLP" ) {
399
+ return "$";
400
+ } else if ( currency_id == "MXN" ) {
401
+ return "$";
402
+ } else if ( currency_id == "VEF" ) {
403
+ return "Bs";
404
+ } else if ( currency_id == "PEN" ) {
405
+ return "S/";
406
+ } else if ( currency_id == "UYU" ) {
407
+ return "$U";
408
+ } else {
409
+ return "$";
410
+ }
411
+ }
412
+
413
+ MPv1.checkCouponEligibility = function () {
414
+ if ( document.querySelector( MPv1.selectors.couponCode).value == "" ) {
415
+ // Coupon code is empty.
416
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display = "none";
417
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display = "block";
418
+ document.querySelector( MPv1.selectors.mpCouponError ).innerHTML = MPv1.text.coupon_empty;
419
+ MPv1.coupon_of_discounts.status = false;
420
+ document.querySelector( MPv1.selectors.couponCode ).style.background = null;
421
+ document.querySelector( MPv1.selectors.applyCoupon ).value = MPv1.text.apply;
422
+ document.querySelector( MPv1.selectors.discount ).value = 0;
423
+ MPv1.cardsHandler();
424
+ } else if ( MPv1.coupon_of_discounts.status ) {
425
+ // We already have a coupon set, so we remove it.
426
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display = "none";
427
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display = "none";
428
+ MPv1.coupon_of_discounts.status = false;
429
+ document.querySelector( MPv1.selectors.applyCoupon ).style.background = null;
430
+ document.querySelector( MPv1.selectors.applyCoupon ).value = MPv1.text.apply;
431
+ document.querySelector( MPv1.selectors.couponCode ).value = "";
432
+ document.querySelector( MPv1.selectors.couponCode ).style.background = null;
433
+ document.querySelector( MPv1.selectors.discount ).value = 0;
434
+ MPv1.cardsHandler();
435
+ } else {
436
+ // Set loading.
437
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display = "none";
438
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display = "none";
439
+ document.querySelector( MPv1.selectors.couponCode ).style.background = "url(" + MPv1.paths.loading + ") 98% 50% no-repeat #fff";
440
+ document.querySelector( MPv1.selectors.applyCoupon ).disabled = true;
441
+
442
+ // Check if there are params in the url.
443
+ var url = MPv1.coupon_of_discounts.discount_action_url;
444
+ var sp = "?";
445
+ if ( url.indexOf( "?" ) >= 0 ) {
446
+ sp = "&";
447
+ }
448
+ url += sp + "site_id=" + MPv1.site_id;
449
+ url += "&coupon_id=" + document.querySelector( MPv1.selectors.couponCode ).value;
450
+ url += "&amount=" + document.querySelector( MPv1.selectors.amount ).value;
451
+ url += "&payer=" + MPv1.coupon_of_discounts.payer_email;
452
+ //url += "&payer=" + document.getElementById( "billing_email" ).value;
453
+
454
+ MPv1.AJAX({
455
+ url: url,
456
+ method : "GET",
457
+ timeout : 5000,
458
+ error: function() {
459
+ // Request failed.
460
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display = "none";
461
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display = "none";
462
+ MPv1.coupon_of_discounts.status = false;
463
+ document.querySelector( MPv1.selectors.applyCoupon ).style.background = null;
464
+ document.querySelector( MPv1.selectors.applyCoupon ).value = MPv1.text.apply;
465
+ document.querySelector( MPv1.selectors.couponCode ).value = "";
466
+ document.querySelector( MPv1.selectors.couponCode ).style.background = null;
467
+ document.querySelector( MPv1.selectors.discount ).value = 0;
468
+ MPv1.cardsHandler();
469
+ },
470
+ success : function ( status, response ) {
471
+ if ( response.status == 200 ) {
472
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display =
473
+ "block";
474
+ document.querySelector( MPv1.selectors.discount ).value =
475
+ response.response.coupon_amount;
476
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).innerHTML =
477
+ //"<div style='border-style: solid; border-width:thin; " +
478
+ //"border-color: #009EE3; padding: 8px 8px 8px 8px; margin-top: 4px;'>" +
479
+ MPv1.text.discount_info1 + " <strong>" +
480
+ MPv1.currencyIdToCurrency( response.response.currency_id ) + " " +
481
+ Math.round( response.response.coupon_amount * 100 ) / 100 +
482
+ "</strong> " + MPv1.text.discount_info2 + " " +
483
+ response.response.name + ".<br>" + MPv1.text.discount_info3 + " <strong>" +
484
+ MPv1.currencyIdToCurrency( response.response.currency_id ) + " " +
485
+ Math.round( MPv1.getAmountWithoutDiscount() * 100 ) / 100 +
486
+ "</strong><br>" + MPv1.text.discount_info4 + " <strong>" +
487
+ MPv1.currencyIdToCurrency( response.response.currency_id ) + " " +
488
+ Math.round( MPv1.getAmount() * 100 ) / 100 + "*</strong><br>" +
489
+ "<i>" + MPv1.text.discount_info5 + "</i><br>" +
490
+ "<a href='https://api.mercadolibre.com/campaigns/" +
491
+ response.response.id +
492
+ "/terms_and_conditions?format_type=html' target='_blank'>" +
493
+ MPv1.text.discount_info6 + "</a>";
494
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display =
495
+ "none";
496
+ MPv1.coupon_of_discounts.status = true;
497
+ document.querySelector( MPv1.selectors.couponCode ).style.background =
498
+ null;
499
+ document.querySelector( MPv1.selectors.couponCode ).style.background =
500
+ "url(" + MPv1.paths.check + ") 98% 50% no-repeat #fff";
501
+ document.querySelector( MPv1.selectors.applyCoupon ).value =
502
+ MPv1.text.remove;
503
+ MPv1.cardsHandler();
504
+ document.querySelector( MPv1.selectors.campaign_id ).value =
505
+ response.response.id;
506
+ document.querySelector( MPv1.selectors.campaign ).value =
507
+ response.response.name;
508
+ } else {
509
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display = "none";
510
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display = "block";
511
+ document.querySelector( MPv1.selectors.mpCouponError ).innerHTML = response.response.message;
512
+ MPv1.coupon_of_discounts.status = false;
513
+ document.querySelector( MPv1.selectors.couponCode ).style.background = null;
514
+ document.querySelector( MPv1.selectors.couponCode ).style.background = "url(" + MPv1.paths.error + ") 98% 50% no-repeat #fff";
515
+ document.querySelector( MPv1.selectors.applyCoupon ).value = MPv1.text.apply;
516
+ document.querySelector( MPv1.selectors.discount ).value = 0;
517
+ MPv1.cardsHandler();
518
+ }
519
+ document.querySelector( MPv1.selectors.applyCoupon ).disabled = false;
520
+ }
521
+ });
522
+ }
523
+ }
524
+
525
+ MPv1.getBin = function() {
526
+
527
+ var cardSelector = document.querySelector( MPv1.selectors.paymentMethodSelector );
528
+
529
+ if (cardSelector && cardSelector[cardSelector.options.selectedIndex].value != "-1") {
530
+ return cardSelector[cardSelector.options.selectedIndex]
531
+ .getAttribute( "first_six_digits" );
532
+ }
533
+
534
+ var ccNumber = document.querySelector( MPv1.selectors.cardNumber );
535
+ return ccNumber.value.replace( /[ .-]/g, "" ).slice( 0, 6 );
536
+
537
+ }
538
+
539
+ MPv1.clearOptions = function() {
540
+
541
+ var bin = MPv1.getBin();
542
+
543
+ if ( bin.length == 0 ) {
544
+
545
+ MPv1.hideIssuer();
546
+
547
+ var selectorInstallments = document.querySelector( MPv1.selectors.installments ),
548
+ fragment = document.createDocumentFragment(),
549
+ option = new Option( MPv1.text.choose + "...", "-1" );
550
+
551
+ selectorInstallments.options.length = 0;
552
+ fragment.appendChild( option );
553
+ selectorInstallments.appendChild( fragment );
554
+ selectorInstallments.setAttribute( "disabled", "disabled" );
555
+
556
+ }
557
+
558
+ }
559
+
560
+ MPv1.guessingPaymentMethod = function( event ) {
561
+
562
+ var bin = MPv1.getBin();
563
+ var amount = MPv1.getAmount();
564
+
565
+ if ( event.type == "keyup" ) {
566
+ if ( bin != null && bin.length == 6 ) {
567
+ Mercadopago.getPaymentMethod( {
568
+ "bin": bin
569
+ }, MPv1.setPaymentMethodInfo );
570
+ }
571
+ } else {
572
+ setTimeout( function() {
573
+ if ( bin.length >= 6 ) {
574
+ Mercadopago.getPaymentMethod( {
575
+ "bin": bin
576
+ }, MPv1.setPaymentMethodInfo );
577
+ }
578
+ }, 100 );
579
+ }
580
+
581
+ };
582
+
583
+ MPv1.setPaymentMethodInfo = function( status, response ) {
584
+
585
+ if ( status == 200 ) {
586
+
587
+ if ( MPv1.site_id != "MLM" ) {
588
+ // Guessing...
589
+ document.querySelector( MPv1.selectors.paymentMethodId ).value = response[0].id;
590
+ if ( MPv1.customer_and_card.status ) {
591
+ document.querySelector( MPv1.selectors.paymentMethodSelector )
592
+ .style.background = "url(" + response[0].secure_thumbnail + ") 90% 50% no-repeat #fff";
593
+ } else {
594
+ document.querySelector( MPv1.selectors.cardNumber ).style.background = "url(" +
595
+ response[0].secure_thumbnail + ") 98% 50% no-repeat #fff";
596
+ }
597
+ }
598
+
599
+ // Check if the security code (ex: Tarshop) is required.
600
+ var cardConfiguration = response[0].settings;
601
+ var bin = MPv1.getBin();
602
+ var amount = MPv1.getAmount();
603
+
604
+ Mercadopago.getInstallments(
605
+ { "bin": bin, "amount": amount },
606
+ MPv1.setInstallmentInfo
607
+ );
608
+
609
+ // Check if the issuer is necessary to pay.
610
+ var issuerMandatory = false, additionalInfo = response[0].additional_info_needed;
611
+
612
+ for ( var i=0; i<additionalInfo.length; i++ ) {
613
+ if ( additionalInfo[i] == "issuer_id" ) {
614
+ issuerMandatory = true;
615
+ }
616
+ };
617
+
618
+ if ( issuerMandatory && MPv1.site_id != "MLM" ) {
619
+ var payment_method_id = response[0].id;
620
+ MPv1.getIssuersPaymentMethod( payment_method_id );
621
+ } else {
622
+ MPv1.hideIssuer();
623
+ }
624
+
625
+ }
626
+
627
+ }
628
+
629
+ MPv1.changePaymetMethodSelector = function() {
630
+ var payment_method_id =
631
+ document.querySelector( MPv1.selectors.paymentMethodSelector ).value;
632
+ MPv1.getIssuersPaymentMethod( payment_method_id );
633
+ }
634
+
635
+ // === Issuers
636
+
637
+ MPv1.getIssuersPaymentMethod = function( payment_method_id ) {
638
+
639
+ var amount = MPv1.getAmount();
640
+
641
+ // flow: MLM mercadopagocard
642
+ if ( payment_method_id == "mercadopagocard" ) {
643
+ Mercadopago.getInstallments(
644
+ { "payment_method_id": payment_method_id, "amount": amount },
645
+ MPv1.setInstallmentInfo
646
+ );
647
+ }
648
+
649
+ Mercadopago.getIssuers( payment_method_id, MPv1.showCardIssuers );
650
+ MPv1.addListenerEvent(
651
+ document.querySelector( MPv1.selectors.issuer ),
652
+ "change",
653
+ MPv1.setInstallmentsByIssuerId
654
+ );
655
+
656
+ }
657
+
658
+ MPv1.showCardIssuers = function( status, issuers ) {
659
+
660
+ // If the API does not return any bank.
661
+ if ( issuers.length > 0 ) {
662
+ var issuersSelector = document.querySelector( MPv1.selectors.issuer );
663
+ var fragment = document.createDocumentFragment();
664
+
665
+ issuersSelector.options.length = 0;
666
+ var option = new Option( MPv1.text.choose + "...", "-1" );
667
+ fragment.appendChild( option );
668
+
669
+ for ( var i=0; i<issuers.length; i++ ) {
670
+ if ( issuers[i].name != "default" ) {
671
+ option = new Option( issuers[i].name, issuers[i].id );
672
+ } else {
673
+ option = new Option( "Otro", issuers[i].id );
674
+ }
675
+ fragment.appendChild( option );
676
+ }
677
+
678
+ issuersSelector.appendChild( fragment );
679
+ issuersSelector.removeAttribute( "disabled" );
680
+ } else {
681
+ MPv1.hideIssuer();
682
+ }
683
+
684
+ }
685
+
686
+ MPv1.setInstallmentsByIssuerId = function( status, response ) {
687
+
688
+ var issuerId = document.querySelector( MPv1.selectors.issuer ).value;
689
+ var amount = MPv1.getAmount();
690
+
691
+ if ( issuerId === "-1" ) {
692
+ return;
693
+ }
694
+
695
+ var params_installments = {
696
+ "bin": MPv1.getBin(),
697
+ "amount": amount,
698
+ "issuer_id": issuerId
699
+ }
700
+
701
+ if ( MPv1.site_id == "MLM" ) {
702
+ params_installments = {
703
+ "payment_method_id": document.querySelector(
704
+ MPv1.selectors.paymentMethodSelector
705
+ ).value,
706
+ "amount": amount,
707
+ "issuer_id": issuerId
708
+ }
709
+ }
710
+ Mercadopago.getInstallments( params_installments, MPv1.setInstallmentInfo );
711
+
712
+ }
713
+
714
+ MPv1.hideIssuer = function() {
715
+ var $issuer = document.querySelector( MPv1.selectors.issuer );
716
+ var opt = document.createElement( "option" );
717
+ opt.value = "-1";
718
+ opt.innerHTML = MPv1.text.other_bank;
719
+ opt.style = "font-size: 12px;";
720
+
721
+ $issuer.innerHTML = "";
722
+ $issuer.appendChild( opt );
723
+ $issuer.setAttribute( "disabled", "disabled" );
724
+ }
725
+
726
+ // === Installments
727
+
728
+ MPv1.setInstallmentInfo = function( status, response ) {
729
+
730
+ var selectorInstallments = document.querySelector( MPv1.selectors.installments );
731
+
732
+ if ( response.length > 0 ) {
733
+
734
+ var html_option = "<option value='-1'>" + MPv1.text.choose + "...</option>";
735
+ payerCosts = response[0].payer_costs;
736
+
737
+ // fragment.appendChild(option);
738
+ for ( var i=0; i<payerCosts.length; i++) {
739
+ // Resolution 51/2017
740
+ var dataInput = "";
741
+ if ( MPv1.site_id == "MLA" ) {
742
+ var tax = payerCosts[i].labels;
743
+ if ( tax.length > 0 ) {
744
+ for ( var l=0; l<tax.length; l++ ) {
745
+ if ( tax[l].indexOf( "CFT_" ) !== -1 ) {
746
+ dataInput = "data-tax='" + tax[l] + "'";
747
+ }
748
+ }
749
+ }
750
+ }
751
+ html_option += "<option value='" + payerCosts[i].installments + "' " + dataInput + ">" +
752
+ (payerCosts[i].recommended_message || payerCosts[i].installments) +
753
+ "</option>";
754
+ }
755
+
756
+ // Not take the user's selection if equal.
757
+ if ( selectorInstallments.innerHTML != html_option ) {
758
+ selectorInstallments.innerHTML = html_option;
759
+ }
760
+
761
+ selectorInstallments.removeAttribute( "disabled" );
762
+ MPv1.showTaxes();
763
+
764
+ }
765
+
766
+ }
767
+
768
+ MPv1.showTaxes = function() {
769
+ var selectorIsntallments = document.querySelector( MPv1.selectors.installments );
770
+ var tax = selectorIsntallments.options[selectorIsntallments.selectedIndex].getAttribute( "data-tax" );
771
+ var cft = "";
772
+ var tea = "";
773
+ if ( tax != null ) {
774
+ var tax_split = tax.split( "|" );
775
+ cft = tax_split[0].replace( "_", " ");
776
+ tea = tax_split[1].replace( "_", " ");
777
+ if ( cft == "CFT 0,00%" && tea == "TEA 0,00%" ) {
778
+ cft = "";
779
+ tea = "";
780
+ }
781
+ }
782
+ document.querySelector( MPv1.selectors.taxTextCFT ).innerHTML = cft;
783
+ document.querySelector( MPv1.selectors.taxTextTEA ).innerHTML = tea;
784
+ }
785
+
786
+ // === Customer & Cards
787
+
788
+ MPv1.cardsHandler = function() {
789
+
790
+ var cardSelector = document.querySelector( MPv1.selectors.paymentMethodSelector );
791
+ var type_checkout =
792
+ cardSelector[cardSelector.options.selectedIndex].getAttribute( "type_checkout" );
793
+ var amount = MPv1.getAmount();
794
+
795
+ if ( MPv1.customer_and_card.default ) {
796
+
797
+ if ( cardSelector &&
798
+ cardSelector[cardSelector.options.selectedIndex].value != "-1" &&
799
+ type_checkout == "customer_and_card" ) {
800
+
801
+ document.querySelector( MPv1.selectors.paymentMethodId )
802
+ .value = cardSelector[cardSelector.options.selectedIndex]
803
+ .getAttribute( "payment_method_id" );
804
+
805
+ MPv1.clearOptions();
806
+
807
+ MPv1.customer_and_card.status = true;
808
+
809
+ var _bin = cardSelector[cardSelector.options.selectedIndex]
810
+ .getAttribute( "first_six_digits" );
811
+
812
+ Mercadopago.getPaymentMethod(
813
+ { "bin": _bin },
814
+ MPv1.setPaymentMethodInfo
815
+ );
816
+
817
+ } else {
818
+
819
+ document.querySelector( MPv1.selectors.paymentMethodId )
820
+ .value = cardSelector.value != -1 ? cardSelector.value : "";
821
+ MPv1.customer_and_card.status = false;
822
+ MPv1.resetBackgroundCard();
823
+ MPv1.guessingPaymentMethod(
824
+ { type: "keyup" }
825
+ );
826
+
827
+ }
828
+
829
+ MPv1.setForm();
830
+
831
+ }
832
+
833
+ }
834
+
835
+ // === Payment Methods
836
+
837
+ MPv1.getPaymentMethods = function() {
838
+
839
+ var fragment = document.createDocumentFragment();
840
+ var paymentMethodsSelector =
841
+ document.querySelector( MPv1.selectors.paymentMethodSelector )
842
+ var mainPaymentMethodSelector =
843
+ document.querySelector( MPv1.selectors.paymentMethodSelector )
844
+
845
+ // Set loading.
846
+ mainPaymentMethodSelector.style.background =
847
+ "url(" + MPv1.paths.loading + ") 95% 50% no-repeat #fff";
848
+
849
+ // If customer and card.
850
+ if ( MPv1.customer_and_card.status ) {
851
+ paymentMethodsSelector = document.querySelector( MPv1.selectors.pmListOtherCards )
852
+ // Clean payment methods.
853
+ paymentMethodsSelector.innerHTML = "";
854
+ } else {
855
+ paymentMethodsSelector.innerHTML = "";
856
+ option = new Option( MPv1.text.choose + "...", "-1" );
857
+ fragment.appendChild( option );
858
+ }
859
+
860
+ Mercadopago.getAllPaymentMethods( function( code, payment_methods ) {
861
+
862
+ for ( var x=0; x < payment_methods.length; x++ ) {
863
+
864
+ var pm = payment_methods[x];
865
+
866
+ if ( ( pm.payment_type_id == "credit_card" || pm.payment_type_id == "debit_card" ||
867
+ pm.payment_type_id == "prepaid_card" ) && pm.status == "active" ) {
868
+
869
+ option = new Option( pm.name, pm.id );
870
+ option.setAttribute( "type_checkout", "custom" );
871
+ fragment.appendChild( option );
872
+
873
+ } // end if
874
+
875
+ } // end for
876
+
877
+ paymentMethodsSelector.appendChild( fragment );
878
+ mainPaymentMethodSelector.style.background = "#fff";
879
+
880
+ } );
881
+
882
+ }
883
+
884
+ // === Functions related to Create Tokens
885
+
886
+ MPv1.createTokenByEvent = function() {
887
+
888
+ var $inputs = MPv1.getForm().querySelectorAll( "[data-checkout]" );
889
+ var $inputs_to_create_token = MPv1.getInputsToCreateToken();
890
+
891
+ for (var x=0; x<$inputs.length; x++) {
892
+
893
+ var element = $inputs[x];
894
+
895
+ // Add events only in the required fields.
896
+ if ( $inputs_to_create_token
897
+ .indexOf( element.getAttribute( "data-checkout" ) ) > -1 ) {
898
+
899
+ var event = "focusout";
900
+
901
+ if ( element.nodeName == "SELECT" ) {
902
+ event = "change";
903
+ }
904
+
905
+ MPv1.addListenerEvent( element, event, MPv1.validateInputsCreateToken );
906
+
907
+ // For firefox.
908
+ MPv1.addListenerEvent( element, "blur", MPv1.validateInputsCreateToken );
909
+
910
+ if ( MPv1.create_token_on.keyup ) {
911
+ MPv1.addListenerEvent(element, "keyup", MPv1.validateInputsCreateToken );
912
+ }
913
+
914
+ if ( MPv1.create_token_on.paste ) {
915
+ MPv1.addListenerEvent(element, "paste", MPv1.validateInputsCreateToken );
916
+ }
917
+
918
+ }
919
+
920
+ }
921
+
922
+ }
923
+
924
+ MPv1.createTokenBySubmit = function() {
925
+ MPv1.addListenerEvent( document.querySelector( MPv1.selectors.form ), "submit", MPv1.doPay );
926
+ }
927
+
928
+ var doSubmit = false;
929
+
930
+ MPv1.doPay = function( event ) {
931
+ event.preventDefault();
932
+ if ( ! doSubmit ) {
933
+ MPv1.createToken();
934
+ return false;
935
+ }
936
+ }
937
+
938
+ MPv1.validateInputsCreateToken = function() {
939
+
940
+ var valid_to_create_token = true;
941
+ var $inputs = MPv1.getForm().querySelectorAll( "[data-checkout]" );
942
+ var $inputs_to_create_token = MPv1.getInputsToCreateToken();
943
+
944
+ for (var x=0; x<$inputs.length; x++) {
945
+
946
+ var element = $inputs[x];
947
+
948
+ // Check is a input to create token.
949
+ if ( $inputs_to_create_token
950
+ .indexOf( element.getAttribute( "data-checkout" ) ) > -1 ) {
951
+
952
+ if ( element.value == -1 || element.value == "" ) {
953
+ valid_to_create_token = false;
954
+ } // end if check values
955
+ } // end if check data-checkout
956
+ } // end for
957
+
958
+ if ( valid_to_create_token ) {
959
+ MPv1.createToken();
960
+ }
961
+
962
+ }
963
+
964
+ MPv1.createToken = function() {
965
+ MPv1.hideErrors();
966
+
967
+ // Show loading.
968
+ document.querySelector( MPv1.selectors.box_loading ).style.background =
969
+ "url(" + MPv1.paths.loading + ") 0 50% no-repeat #fff";
970
+
971
+ // Form.
972
+ var $form = MPv1.getForm();
973
+
974
+ Mercadopago.createToken( $form, MPv1.sdkResponseHandler );
975
+
976
+ return false;
977
+ }
978
+
979
+ MPv1.sdkResponseHandler = function( status, response ) {
980
+
981
+ // Hide loading.
982
+ document.querySelector( MPv1.selectors.box_loading ).style.background = "";
983
+
984
+ if ( status != 200 && status != 201 ) {
985
+ MPv1.showErrors( response );
986
+ } else {
987
+ var token = document.querySelector( MPv1.selectors.token );
988
+ token.value = response.id;
989
+
990
+ if ( MPv1.add_truncated_card ) {
991
+ var card = MPv1.truncateCard( response );
992
+ document.querySelector( MPv1.selectors.cardTruncated ).value = card;
993
+ }
994
+
995
+ if ( ! MPv1.create_token_on.event ) {
996
+ doSubmit = true;
997
+ btn = document.querySelector( MPv1.selectors.form );
998
+ btn.submit();
999
+ }
1000
+ }
1001
+
1002
+ }
1003
+
1004
+ // === Useful functions
1005
+
1006
+ MPv1.resetBackgroundCard = function() {
1007
+ document.querySelector( MPv1.selectors.paymentMethodSelector ).style.background =
1008
+ "no-repeat #fff";
1009
+ document.querySelector( MPv1.selectors.cardNumber ).style.background =
1010
+ "no-repeat #fff";
1011
+ }
1012
+
1013
+ MPv1.setForm = function() {
1014
+ if ( MPv1.customer_and_card.status ) {
1015
+ document.querySelector( MPv1.selectors.formDiv ).style.display = "none";
1016
+ document.querySelector( MPv1.selectors.mpSecurityCodeCustomerAndCard ).removeAttribute( "style" );
1017
+ } else {
1018
+ document.querySelector( MPv1.selectors.mpSecurityCodeCustomerAndCard ).style.display = "none";
1019
+ document.querySelector( MPv1.selectors.formDiv ).removeAttribute( "style" );
1020
+ }
1021
+
1022
+ Mercadopago.clearSession();
1023
+
1024
+ if ( MPv1.create_token_on.event ) {
1025
+ MPv1.createTokenByEvent();
1026
+ MPv1.validateInputsCreateToken();
1027
+ }
1028
+
1029
+ document.querySelector( MPv1.selectors.CustomerAndCard ).value =
1030
+ MPv1.customer_and_card.status;
1031
+ }
1032
+
1033
+ MPv1.getForm = function() {
1034
+ if ( MPv1.customer_and_card.status ) {
1035
+ return document.querySelector( MPv1.selectors.formCustomerAndCard );
1036
+ } else {
1037
+ return document.querySelector( MPv1.selectors.form );
1038
+ }
1039
+ }
1040
+
1041
+ MPv1.getInputsToCreateToken = function() {
1042
+ if ( MPv1.customer_and_card.status ) {
1043
+ return MPv1.inputs_to_create_token_customer_and_card;
1044
+ } else {
1045
+ return MPv1.inputs_to_create_token;
1046
+ }
1047
+ }
1048
+
1049
+ MPv1.truncateCard = function( response_card_token ) {
1050
+
1051
+ var first_six_digits;
1052
+ var last_four_digits;
1053
+
1054
+ if ( MPv1.customer_and_card.status ) {
1055
+ var cardSelector = document.querySelector( MPv1.selectors.paymentMethodSelector );
1056
+ first_six_digits = cardSelector[cardSelector.options.selectedIndex]
1057
+ .getAttribute( "first_six_digits" ).match( /.{1,4}/g )
1058
+ last_four_digits = cardSelector[cardSelector.options.selectedIndex]
1059
+ .getAttribute( "last_four_digits" )
1060
+ } else {
1061
+ first_six_digits = response_card_token.first_six_digits.match( /.{1,4}/g )
1062
+ last_four_digits = response_card_token.last_four_digits
1063
+ }
1064
+
1065
+ var card = first_six_digits[0] + " " +
1066
+ first_six_digits[1] + "** **** " + last_four_digits;
1067
+
1068
+ return card;
1069
+
1070
+ }
1071
+
1072
+ MPv1.getAmount = function() {
1073
+ return document.querySelector( MPv1.selectors.amount ).value;
1074
+ }
1075
+
1076
+ // === Show errors
1077
+
1078
+ MPv1.showErrors = function( response ) {
1079
+ var $form = MPv1.getForm();
1080
+
1081
+ for ( var x=0; x<response.cause.length; x++ ) {
1082
+ var error = response.cause[x];
1083
+ var $span = $form.querySelector( "#mp-error-" + error.code );
1084
+ var $input = $form.querySelector( $span.getAttribute( "data-main" ) );
1085
+
1086
+ $span.style.display = "inline-block";
1087
+ $input.classList.add( "mp-error-input" );
1088
+ }
1089
+
1090
+ return;
1091
+ }
1092
+
1093
+ MPv1.hideErrors = function() {
1094
+
1095
+ for ( var x = 0; x < document.querySelectorAll( "[data-checkout]" ).length; x++ ) {
1096
+ var $field = document.querySelectorAll( "[data-checkout]" )[x];
1097
+ $field.classList.remove( "mp-error-input" );
1098
+ } // end for
1099
+
1100
+ for ( var x = 0; x < document.querySelectorAll( ".mp-error" ).length; x++ ) {
1101
+ var $span = document.querySelectorAll( ".mp-error" )[x];
1102
+ $span.style.display = "none";
1103
+ }
1104
+
1105
+ return;
1106
+
1107
+ }
1108
+
1109
+ // === Add events to guessing
1110
+
1111
+ MPv1.addListenerEvent = function( el, eventName, handler ) {
1112
+ if ( el.addEventListener ) {
1113
+ el.addEventListener( eventName, handler );
1114
+ } else {
1115
+ el.attachEvent( "on" + eventName, function() {
1116
+ handler.call( el );
1117
+ });
1118
+ }
1119
+ };
1120
+
1121
+ MPv1.addListenerEvent(
1122
+ document.querySelector( MPv1.selectors.cardNumber ),
1123
+ "keyup", MPv1.guessingPaymentMethod
1124
+ );
1125
+ MPv1.addListenerEvent(
1126
+ document.querySelector( MPv1.selectors.cardNumber ),
1127
+ "keyup", MPv1.clearOptions
1128
+ );
1129
+ MPv1.addListenerEvent(
1130
+ document.querySelector( MPv1.selectors.cardNumber),
1131
+ "change", MPv1.guessingPaymentMethod
1132
+ );
1133
+
1134
+ MPv1.referer = (function () {
1135
+ var referer = window.location.protocol + "//" +
1136
+ window.location.hostname + ( window.location.port ? ":" + window.location.port: "" );
1137
+ return referer;
1138
+ })();
1139
+
1140
+ MPv1.AJAX = function( options ) {
1141
+ var useXDomain = !!window.XDomainRequest;
1142
+ var req = useXDomain ? new XDomainRequest() : new XMLHttpRequest()
1143
+ var data;
1144
+ options.url += ( options.url.indexOf( "?" ) >= 0 ? "&" : "?" ) + "referer=" + escape( MPv1.referer );
1145
+ options.requestedMethod = options.method;
1146
+ if ( useXDomain && options.method == "PUT" ) {
1147
+ options.method = "POST";
1148
+ options.url += "&_method=PUT";
1149
+ }
1150
+ req.open( options.method, options.url, true );
1151
+ req.timeout = options.timeout || 1000;
1152
+ if ( window.XDomainRequest ) {
1153
+ req.onload = function() {
1154
+ data = JSON.parse( req.responseText );
1155
+ if ( typeof options.success === "function" ) {
1156
+ options.success( options.requestedMethod === "POST" ? 201 : 200, data );
1157
+ }
1158
+ };
1159
+ req.onerror = req.ontimeout = function() {
1160
+ if ( typeof options.error === "function" ) {
1161
+ options.error( 400, {
1162
+ user_agent:window.navigator.userAgent, error : "bad_request", cause:[]
1163
+ });
1164
+ }
1165
+ };
1166
+ req.onprogress = function() {};
1167
+ } else {
1168
+ req.setRequestHeader( "Accept", "application/json" );
1169
+ if ( options.contentType ) {
1170
+ req.setRequestHeader( "Content-Type", options.contentType );
1171
+ } else {
1172
+ req.setRequestHeader( "Content-Type", "application/json" );
1173
+ }
1174
+ req.onreadystatechange = function() {
1175
+ if ( this.readyState === 4 ) {
1176
+ try {
1177
+ if ( this.status >= 200 && this.status < 400 ) {
1178
+ // Success!
1179
+ data = JSON.parse( this.responseText );
1180
+ if ( typeof options.success === "function" ) {
1181
+ options.success( this.status, data );
1182
+ }
1183
+ } else if ( this.status >= 400 ) {
1184
+ data = JSON.parse( this.responseText );
1185
+ if ( typeof options.error === "function" ) {
1186
+ options.error( this.status, data );
1187
+ }
1188
+ } else if ( typeof options.error === "function" ) {
1189
+ options.error( 503, {} );
1190
+ }
1191
+ } catch (e) {
1192
+ options.error( 503, {} );
1193
+ }
1194
+ }
1195
+ };
1196
+ }
1197
+ if ( options.method === "GET" || options.data == null || options.data == undefined ) {
1198
+ req.send();
1199
+ } else {
1200
+ req.send( JSON.stringify( options.data ) );
1201
+ }
1202
+ }
1203
+
1204
+ // === Initialization function
1205
+
1206
+ MPv1.Initialize = function( site_id, public_key, coupon_mode, discount_action_url, payer_email ) {
1207
+
1208
+ // Sets
1209
+ MPv1.site_id = site_id;
1210
+ MPv1.public_key = public_key;
1211
+ MPv1.coupon_of_discounts.default = coupon_mode;
1212
+ MPv1.coupon_of_discounts.discount_action_url = discount_action_url;
1213
+ MPv1.coupon_of_discounts.payer_email = payer_email;
1214
+
1215
+ Mercadopago.setPublishableKey( MPv1.public_key );
1216
+
1217
+ // flow coupon of discounts
1218
+ if ( MPv1.coupon_of_discounts.default ) {
1219
+ MPv1.addListenerEvent(
1220
+ document.querySelector( MPv1.selectors.applyCoupon ),
1221
+ "click",
1222
+ MPv1.checkCouponEligibility
1223
+ );
1224
+ } else {
1225
+ document.querySelector( MPv1.selectors.formCoupon ).style.display = "none";
1226
+ }
1227
+
1228
+ // Flow: customer & cards.
1229
+ var selectorPmCustomerAndCards = document.querySelector( MPv1.selectors.pmCustomerAndCards );
1230
+ if ( MPv1.customer_and_card.default && selectorPmCustomerAndCards.childElementCount > 0 ) {
1231
+ MPv1.addListenerEvent(
1232
+ document.querySelector( MPv1.selectors.paymentMethodSelector ),
1233
+ "change", MPv1.cardsHandler
1234
+ );
1235
+ MPv1.cardsHandler();
1236
+ } else {
1237
+ // If customer & cards is disabled or customer does not have cards.
1238
+ MPv1.customer_and_card.status = false;
1239
+ document.querySelector( MPv1.selectors.formCustomerAndCard ).style.display = "none";
1240
+ }
1241
+
1242
+ if ( MPv1.create_token_on.event ) {
1243
+ MPv1.createTokenByEvent();
1244
+ } else {
1245
+ MPv1.createTokenBySubmit()
1246
+ }
1247
+
1248
+ // flow: MLM
1249
+ if ( MPv1.site_id != "MLM" ) {
1250
+ Mercadopago.getIdentificationTypes();
1251
+ }
1252
+
1253
+ if ( MPv1.site_id == "MLM" ) {
1254
+
1255
+ // Hide documento for mex.
1256
+ document.querySelector( MPv1.selectors.mpDoc ).style.display = "none";
1257
+
1258
+ document.querySelector( MPv1.selectors.formCustomerAndCard ).removeAttribute( "style" );
1259
+ document.querySelector( MPv1.selectors.formCustomerAndCard ).style.padding = "0px 24px 0px 24px";
1260
+ document.querySelector( MPv1.selectors.mpSecurityCodeCustomerAndCard ).style.display = "none";
1261
+
1262
+ // Removing not used fields for this country.
1263
+ MPv1.inputs_to_create_token.splice(
1264
+ MPv1.inputs_to_create_token.indexOf( "docType" ),
1265
+ 1 );
1266
+ MPv1.inputs_to_create_token.splice(
1267
+ MPv1.inputs_to_create_token.indexOf( "docNumber" ),
1268
+ 1 );
1269
+
1270
+ MPv1.addListenerEvent(
1271
+ document.querySelector( MPv1.selectors.paymentMethodSelector ),
1272
+ "change",
1273
+ MPv1.changePaymetMethodSelector
1274
+ );
1275
+
1276
+ // Get payment methods and populate selector.
1277
+ MPv1.getPaymentMethods();
1278
+
1279
+ }
1280
+
1281
+ // flow: MLB AND MCO
1282
+ if ( MPv1.site_id == "MLB" ) {
1283
+
1284
+ document.querySelector( MPv1.selectors.mpDocType ).style.display = "none";
1285
+ document.querySelector( MPv1.selectors.mpIssuer ).style.display = "none";
1286
+ // Adjust css.
1287
+ document.querySelector( MPv1.selectors.docNumber ).classList.remove( "mp-col-75" );
1288
+ document.querySelector( MPv1.selectors.docNumber ).classList.add( "mp-col-100" );
1289
+
1290
+ } else if ( MPv1.site_id == "MCO" ) {
1291
+ document.querySelector( MPv1.selectors.mpIssuer ).style.display = "none";
1292
+ } else if ( MPv1.site_id == "MLA" ) {
1293
+ document.querySelector( MPv1.selectors.boxInstallmentsSelector ).classList.remove( "mp-col-100" );
1294
+ document.querySelector( MPv1.selectors.boxInstallmentsSelector ).classList.add( "mp-col-70" );
1295
+ document.querySelector( MPv1.selectors.taxCFT ).style.display = "block";
1296
+ document.querySelector( MPv1.selectors.taxTEA ).style.display = "block";
1297
+ MPv1.addListenerEvent( document.querySelector( MPv1.selectors.installments ), "change", MPv1.showTaxes );
1298
+ } else if ( MPv1.site_id == "MLC" ) {
1299
+ document.querySelector(MPv1.selectors.mpIssuer).style.display = "none";
1300
+ }
1301
+
1302
+ if ( MPv1.debug ) {
1303
+ document.querySelector( MPv1.selectors.utilities_fields ).style.display = "inline-block";
1304
+ }
1305
+
1306
+ document.querySelector( MPv1.selectors.site_id ).value = MPv1.site_id;
1307
+
1308
+ return;
1309
+
1310
+ }
1311
+
1312
+ this.MPv1 = MPv1;
1313
+
1314
+ } ).call();
1315
+
1316
+ // Overriding this function to give form padding attribute.
1317
+ MPv1.setForm = function() {
1318
+ if ( MPv1.customer_and_card.status ) {
1319
+ document.querySelector( MPv1.selectors.form ).style.display = "none";
1320
+ document.querySelector( MPv1.selectors.mpSecurityCodeCustomerAndCard ).removeAttribute( "style" );
1321
+ } else {
1322
+ document.querySelector( MPv1.selectors.mpSecurityCodeCustomerAndCard ).style.display = "none";
1323
+ document.querySelector( MPv1.selectors.form ).removeAttribute( "style" );
1324
+ document.querySelector( MPv1.selectors.form ).style.padding = "0px 24px 0px 24px";
1325
+ }
1326
+ Mercadopago.clearSession();
1327
+ if ( MPv1.create_token_on.event ) {
1328
+ MPv1.createTokenByEvent();
1329
+ MPv1.validateInputsCreateToken();
1330
+ }
1331
+ document.querySelector( MPv1.selectors.CustomerAndCard ).value = MPv1.customer_and_card.status;
1332
+ }
1333
+
1334
+ MPv1.getAmount = function() {
1335
+ return document.querySelector( MPv1.selectors.amount ).value - document.querySelector( MPv1.selectors.discount ).value;
1336
+ }
1337
+
1338
+ MPv1.getAmountWithoutDiscount = function() {
1339
+ return document.querySelector( MPv1.selectors.amount ).value;
1340
+ }
1341
+
1342
+ MPv1.showErrors = function( response ) {
1343
+ var $form = MPv1.getForm();
1344
+ for ( var x=0; x<response.cause.length; x++ ) {
1345
+ var error = response.cause[x];
1346
+ var $span = $form.querySelector( "#mp-error-" + error.code );
1347
+ var $input = $form.querySelector( $span.getAttribute( "data-main" ) );
1348
+ $span.style.display = "inline-block";
1349
+ $input.classList.add( "mp-error-input" );
1350
+ }
1351
+ return;
1352
+ }
1353
+
1354
  MPv1.text.apply = "<?php echo __( 'Apply', 'woocommerce-mercadopago' ); ?>";
1355
  MPv1.text.remove = "<?php echo __( 'Remove', 'woocommerce-mercadopago' ); ?>";
1356
  MPv1.text.coupon_empty = "<?php echo __( 'Please, inform your coupon code', 'woocommerce-mercadopago' ); ?>";
templates/mp_main_settings.php CHANGED
@@ -297,6 +297,17 @@
297
  </p>
298
  </td>
299
  </tr>
 
 
 
 
 
 
 
 
 
 
 
300
  </table>
301
 
302
  <table class="form-table" border="0.5" frame="hsides" rules="void">
297
  </p>
298
  </td>
299
  </tr>
300
+ <!--<tr>
301
+ <th scope="row"><label><?php echo __( 'Custom Domain for IPN', 'woocommerce-mercadopago' ); ?></label></th>
302
+ <td>
303
+ <input name="custom_domain" type="text" id="custom_domain" aria-describedby="tagline-description" value="<?php echo $custom_domain; ?>" class="regular-text"/>
304
+ <p class="description" id="tagline-description">
305
+ <?php echo sprintf( '%s',
306
+ __( 'If your store is hosted as a subdomain, please inform the complete store URL here.<br>Format should be as: <code>https://yourdomain.com/yoursubdomain</code>.', 'woocommerce-mercadopago' )
307
+ ); ?>
308
+ </p>
309
+ </td>
310
+ </tr>-->
311
  </table>
312
 
313
  <table class="form-table" border="0.5" frame="hsides" rules="void">
templates/ticket/ticket-form.php CHANGED
@@ -31,10 +31,10 @@ if ( ! defined( 'ABSPATH' ) ) {
31
  </div>
32
  </div>
33
 
34
- <fieldset id="ticket_checkout_fieldset" style="margin:0px; background:white; display: none;">
35
 
36
  <!-- coupom -->
37
- <div class="mp-box-inputs mp-line form-row" id="mercadopago-form-coupon-ticket" style="padding:0px 12px 16px 12px;" >
38
  <div class="form-col-8">
39
  <label for="couponCodeLabel"><?php echo esc_html__( 'Discount Coupon', 'woocommerce-mercadopago' ); ?></label>
40
  <input type="text" id="couponCodeTicket" name="mercadopago_ticket[coupon_code]"
@@ -148,19 +148,18 @@ if ( ! defined( 'ABSPATH' ) ) {
148
  <div class="form-col-4">
149
  <label for="zipcode"><?php echo esc_html__( 'ZIP', 'woocommerce-mercadopago' ); ?><em class="obrigatorio"> *</em></label>
150
  <input type="text" value="<?php echo $febraban['zipcode']; ?>"
151
- id="zipcode" class="form-control-mine" name="mercadopago_ticket[zipcode]"
152
- onkeydown="return (event.which >= 48 && event.which <= 57) || event.which == 8 || event.which == 46">
153
  <span class="erro_febraban" data-main="#zipcode" id="error_zipcode"><?php echo esc_html__( 'You must inform your ZIP', 'woocommerce-mercadopago' ); ?></span>
154
  </div>
155
  </div>
156
- <div class="form-col-12">
157
  <label>
158
  <span class="mensagem-febraban"><em class="obrigatorio">* </em><?php echo esc_html__( 'Needed informations due to brazilian bank compliances numbers 3.461/09, 3.598/12 and 3.656/13 of the Central Bank of Brazil.', 'woocommerce-mercadopago' ); ?></span>
159
  </label>
160
  </div>
161
  </div>
162
 
163
- <div style="padding:0px 36px 0px 36px; margin-left: -32px; margin-right: -32px;">
164
  <p>
165
  <?php
166
  if ( count( $payment_methods ) > 1 ) :
@@ -233,9 +232,582 @@ if ( ! defined( 'ABSPATH' ) ) {
233
  </div>
234
  </fieldset>
235
 
236
- <script type="text/javascript" src="<?php echo $path_to_javascript; ?>"/>
237
 
238
  <script type="text/javascript">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  MPv1Ticket.text.apply = "<?php echo __( 'Apply', 'woocommerce-mercadopago' ); ?>";
240
  MPv1Ticket.text.remove = "<?php echo __( 'Remove', 'woocommerce-mercadopago' ); ?>";
241
  MPv1Ticket.text.coupon_empty = "<?php echo __( 'Please, inform your coupon code', 'woocommerce-mercadopago' ); ?>";
31
  </div>
32
  </div>
33
 
34
+ <fieldset id="ticket_checkout_fieldset" style="margin:-1px; background:white; display: none;">
35
 
36
  <!-- coupom -->
37
+ <div class="mp-box-inputs mp-line form-row" id="mercadopago-form-coupon-ticket" style="padding:0px 24px 16px 24px;" >
38
  <div class="form-col-8">
39
  <label for="couponCodeLabel"><?php echo esc_html__( 'Discount Coupon', 'woocommerce-mercadopago' ); ?></label>
40
  <input type="text" id="couponCodeTicket" name="mercadopago_ticket[coupon_code]"
148
  <div class="form-col-4">
149
  <label for="zipcode"><?php echo esc_html__( 'ZIP', 'woocommerce-mercadopago' ); ?><em class="obrigatorio"> *</em></label>
150
  <input type="text" value="<?php echo $febraban['zipcode']; ?>"
151
+ id="zipcode" class="form-control-mine" name="mercadopago_ticket[zipcode]">
 
152
  <span class="erro_febraban" data-main="#zipcode" id="error_zipcode"><?php echo esc_html__( 'You must inform your ZIP', 'woocommerce-mercadopago' ); ?></span>
153
  </div>
154
  </div>
155
+ <div class="form-col-12" style="padding:0px 20px 0px 20px;">
156
  <label>
157
  <span class="mensagem-febraban"><em class="obrigatorio">* </em><?php echo esc_html__( 'Needed informations due to brazilian bank compliances numbers 3.461/09, 3.598/12 and 3.656/13 of the Central Bank of Brazil.', 'woocommerce-mercadopago' ); ?></span>
158
  </label>
159
  </div>
160
  </div>
161
 
162
+ <div style="padding:0px 24px 0px 24px;">
163
  <p>
164
  <?php
165
  if ( count( $payment_methods ) > 1 ) :
232
  </div>
233
  </fieldset>
234
 
235
+ <!--<script type="text/javascript" src="<?php echo $path_to_javascript; ?>"/>-->
236
 
237
  <script type="text/javascript">
238
+ ( function() {
239
+
240
+ var MPv1Ticket = {
241
+ site_id: "",
242
+ coupon_of_discounts: {
243
+ discount_action_url: "",
244
+ payer_email: "",
245
+ default: true,
246
+ status: false
247
+ },
248
+ inputs_to_create_discount: [
249
+ "couponCodeTicket",
250
+ "applyCouponTicket"
251
+ ],
252
+ inputs_to_validate_ticket: [
253
+ "firstname",
254
+ "lastname",
255
+ "docNumber",
256
+ "address",
257
+ "number",
258
+ "city",
259
+ "state",
260
+ "zipcode"
261
+ ],
262
+ selectors: {
263
+ // currency
264
+ currency_ratio: "#currency_ratioTicket",
265
+ // coupom
266
+ couponCode: "#couponCodeTicket",
267
+ applyCoupon: "#applyCouponTicket",
268
+ mpCouponApplyed: "#mpCouponApplyedTicket",
269
+ mpCouponError: "#mpCouponErrorTicket",
270
+ campaign_id: "#campaign_idTicket",
271
+ campaign: "#campaignTicket",
272
+ discount: "#discountTicket",
273
+ // payment method and checkout
274
+ paymentMethodId: "#paymentMethodIdTicket",
275
+ amount: "#amountTicket",
276
+ // other rules
277
+ boxFirstName: "#box-firstname",
278
+ boxLastName: "#box-lastname",
279
+ boxDocNumber: "#box-docnumber",
280
+ titleFirstName: ".title-name",
281
+ titleFirstNameRazaoSocial: ".title-razao-social",
282
+ titleDocNumber: ".title-cpf",
283
+ titleDocNumberCNPJ: ".title-cnpj",
284
+ radioTypeFisica: '#MPv1Ticket-docType-fisica',
285
+ radioTypeJuridica: '#MPv1Ticket-docType-juridica',
286
+ // febraban
287
+ firstname: "#febrabanFirstname",
288
+ lastname: "#febrabanLastname",
289
+ cpfcnpj: "#cpfcnpj",
290
+ address: "#febrabanAddress",
291
+ number: "#febrabanNumber",
292
+ city: "#febrabanCity",
293
+ state: "#febrabanState",
294
+ zipcode: "#febrabanZipcode",
295
+ // form
296
+ formCoupon: "#mercadopago-form-coupon-ticket",
297
+ formTicket: "#form-ticket",
298
+ box_loading: "#mp-box-loading",
299
+ submit: "#btnSubmit",
300
+ form: "#mercadopago-form-ticket"
301
+ },
302
+ text: {
303
+ discount_info1: "You will save",
304
+ discount_info2: "with discount from",
305
+ discount_info3: "Total of your purchase:",
306
+ discount_info4: "Total of your purchase with discount:",
307
+ discount_info5: "*Uppon payment approval",
308
+ discount_info6: "Terms and Conditions of Use",
309
+ coupon_empty: "Please, inform your coupon code",
310
+ apply: "Apply",
311
+ remove: "Remove"
312
+ },
313
+ paths: {
314
+ loading: "images/loading.gif",
315
+ check: "images/check.png",
316
+ error: "images/error.png"
317
+ }
318
+ }
319
+
320
+ // === Coupon of Discounts
321
+
322
+ MPv1Ticket.currencyIdToCurrency = function ( currency_id ) {
323
+ if ( currency_id == "ARS" ) {
324
+ return "$";
325
+ } else if ( currency_id == "BRL" ) {
326
+ return "R$";
327
+ } else if ( currency_id == "COP" ) {
328
+ return "$";
329
+ } else if ( currency_id == "CLP" ) {
330
+ return "$";
331
+ } else if ( currency_id == "MXN" ) {
332
+ return "$";
333
+ } else if ( currency_id == "VEF" ) {
334
+ return "Bs";
335
+ } else if ( currency_id == "PEN" ) {
336
+ return "S/";
337
+ } else if ( currency_id == "UYU" ) {
338
+ return "$U";
339
+ } else {
340
+ return "$";
341
+ }
342
+ }
343
+
344
+ MPv1Ticket.checkCouponEligibility = function () {
345
+ if ( document.querySelector( MPv1Ticket.selectors.couponCode ).value == "" ) {
346
+ // Coupon code is empty.
347
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display = "none";
348
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display = "block";
349
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).innerHTML = MPv1Ticket.text.coupon_empty;
350
+ MPv1Ticket.coupon_of_discounts.status = false;
351
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background = null;
352
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).value = MPv1Ticket.text.apply;
353
+ document.querySelector( MPv1Ticket.selectors.discount ).value = 0;
354
+ // --- No cards handler ---
355
+ } else if ( MPv1Ticket.coupon_of_discounts.status ) {
356
+ // We already have a coupon set, so we remove it.
357
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display = "none";
358
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display = "none";
359
+ MPv1Ticket.coupon_of_discounts.status = false;
360
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).style.background = null;
361
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).value = MPv1Ticket.text.apply;
362
+ document.querySelector( MPv1Ticket.selectors.couponCode ).value = "";
363
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background = null;
364
+ document.querySelector( MPv1Ticket.selectors.discount ).value = 0;
365
+ // --- No cards handler ---
366
+ } else {
367
+ // Set loading.
368
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display = "none";
369
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display = "none";
370
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background = "url(" + MPv1Ticket.paths.loading + ") 98% 50% no-repeat #fff";
371
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).disabled = true;
372
+
373
+ // Check if there are params in the url.
374
+ var url = MPv1Ticket.coupon_of_discounts.discount_action_url;
375
+ var sp = "?";
376
+ if ( url.indexOf( "?" ) >= 0 ) {
377
+ sp = "&";
378
+ }
379
+ url += sp + "site_id=" + MPv1Ticket.site_id;
380
+ url += "&coupon_id=" + document.querySelector( MPv1Ticket.selectors.couponCode ).value;
381
+ url += "&amount=" + document.querySelector( MPv1Ticket.selectors.amount ).value;
382
+ url += "&payer=" + MPv1Ticket.coupon_of_discounts.payer_email;
383
+
384
+ MPv1Ticket.AJAX({
385
+ url: url,
386
+ method : "GET",
387
+ timeout : 5000,
388
+ error: function() {
389
+ // Request failed.
390
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display = "none";
391
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display = "none";
392
+ MPv1Ticket.coupon_of_discounts.status = false;
393
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).style.background = null;
394
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).value = MPv1Ticket.text.apply;
395
+ document.querySelector( MPv1Ticket.selectors.couponCode ).value = "";
396
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background = null;
397
+ document.querySelector( MPv1Ticket.selectors.discount ).value = 0;
398
+ // --- No cards handler ---
399
+ },
400
+ success : function ( status, response ) {
401
+ if ( response.status == 200 ) {
402
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display =
403
+ "block";
404
+ document.querySelector( MPv1Ticket.selectors.discount ).value =
405
+ response.response.coupon_amount;
406
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).innerHTML =
407
+ MPv1Ticket.text.discount_info1 + " <strong>" +
408
+ MPv1Ticket.currencyIdToCurrency( response.response.currency_id ) + " " +
409
+ Math.round( response.response.coupon_amount * 100 ) / 100 +
410
+ "</strong> " + MPv1Ticket.text.discount_info2 + " " +
411
+ response.response.name + ".<br>" + MPv1Ticket.text.discount_info3 + " <strong>" +
412
+ MPv1Ticket.currencyIdToCurrency( response.response.currency_id ) + " " +
413
+ Math.round( MPv1Ticket.getAmountWithoutDiscount() * 100 ) / 100 +
414
+ "</strong><br>" + MPv1Ticket.text.discount_info4 + " <strong>" +
415
+ MPv1Ticket.currencyIdToCurrency( response.response.currency_id ) + " " +
416
+ Math.round( MPv1Ticket.getAmount() * 100 ) / 100 + "*</strong><br>" +
417
+ "<i>" + MPv1Ticket.text.discount_info5 + "</i><br>" +
418
+ "<a href='https://api.mercadolibre.com/campaigns/" +
419
+ response.response.id +
420
+ "/terms_and_conditions?format_type=html' target='_blank'>" +
421
+ MPv1Ticket.text.discount_info6 + "</a>";
422
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display =
423
+ "none";
424
+ MPv1Ticket.coupon_of_discounts.status = true;
425
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background =
426
+ null;
427
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background =
428
+ "url(" + MPv1Ticket.paths.check + ") 98% 50% no-repeat #fff";
429
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).value =
430
+ MPv1Ticket.text.remove;
431
+ // --- No cards handler ---
432
+ document.querySelector( MPv1Ticket.selectors.campaign_id ).value =
433
+ response.response.id;
434
+ document.querySelector( MPv1Ticket.selectors.campaign ).value =
435
+ response.response.name;
436
+ } else {
437
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display = "none";
438
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display = "block";
439
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).innerHTML = response.response.message;
440
+ MPv1Ticket.coupon_of_discounts.status = false;
441
+ document.querySelector(MPv1Ticket.selectors.couponCode).style.background = null;
442
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background = "url(" + MPv1Ticket.paths.error + ") 98% 50% no-repeat #fff";
443
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).value = MPv1Ticket.text.apply;
444
+ document.querySelector( MPv1Ticket.selectors.discount ).value = 0;
445
+ // --- No cards handler ---
446
+ }
447
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).disabled = false;
448
+ }
449
+ });
450
+ }
451
+ }
452
+
453
+ // === Initialization function
454
+
455
+ MPv1Ticket.addListenerEvent = function( el, eventName, handler ) {
456
+ if ( el.addEventListener ) {
457
+ el.addEventListener( eventName, handler );
458
+ } else {
459
+ el.attachEvent( "on" + eventName, function() {
460
+ handler.call( el );
461
+ } );
462
+ }
463
+ };
464
+
465
+ MPv1Ticket.referer = (function () {
466
+ var referer = window.location.protocol + "//" +
467
+ window.location.hostname + ( window.location.port ? ":" + window.location.port: "" );
468
+ return referer;
469
+ })();
470
+
471
+ MPv1Ticket.AJAX = function( options ) {
472
+ var useXDomain = !!window.XDomainRequest;
473
+ var req = useXDomain ? new XDomainRequest() : new XMLHttpRequest()
474
+ var data;
475
+ options.url += ( options.url.indexOf( "?" ) >= 0 ? "&" : "?" ) + "referer=" + escape( MPv1Ticket.referer );
476
+ options.requestedMethod = options.method;
477
+ if ( useXDomain && options.method == "PUT" ) {
478
+ options.method = "POST";
479
+ options.url += "&_method=PUT";
480
+ }
481
+ req.open( options.method, options.url, true );
482
+ req.timeout = options.timeout || 1000;
483
+ if ( window.XDomainRequest ) {
484
+ req.onload = function() {
485
+ data = JSON.parse( req.responseText );
486
+ if ( typeof options.success === "function" ) {
487
+ options.success( options.requestedMethod === "POST" ? 201 : 200, data );
488
+ }
489
+ };
490
+ req.onerror = req.ontimeout = function() {
491
+ if ( typeof options.error === "function" ) {
492
+ options.error( 400, {
493
+ user_agent:window.navigator.userAgent, error : "bad_request", cause:[]
494
+ });
495
+ }
496
+ };
497
+ req.onprogress = function() {};
498
+ } else {
499
+ req.setRequestHeader( "Accept", "application/json" );
500
+ if ( options.contentType ) {
501
+ req.setRequestHeader( "Content-Type", options.contentType );
502
+ } else {
503
+ req.setRequestHeader( "Content-Type", "application/json" );
504
+ }
505
+ req.onreadystatechange = function() {
506
+ if ( this.readyState === 4 ) {
507
+ try {
508
+ if ( this.status >= 200 && this.status < 400 ) {
509
+ // Success!
510
+ data = JSON.parse( this.responseText );
511
+ if ( typeof options.success === "function" ) {
512
+ options.success( this.status, data );
513
+ }
514
+ } else if ( this.status >= 400 ) {
515
+ data = JSON.parse( this.responseText );
516
+ if ( typeof options.error === "function" ) {
517
+ options.error( this.status, data );
518
+ }
519
+ } else if ( typeof options.error === "function" ) {
520
+ options.error( 503, {} );
521
+ }
522
+ } catch (e) {
523
+ options.error( 503, {} );
524
+ }
525
+ }
526
+ };
527
+ }
528
+ if ( options.method === "GET" || options.data == null || options.data == undefined ) {
529
+ req.send();
530
+ } else {
531
+ req.send( JSON.stringify( options.data ) );
532
+ }
533
+ }
534
+
535
+ // Form validation
536
+
537
+ var doSubmitTicket = false;
538
+
539
+ MPv1Ticket.doPay = function(febraban) {
540
+ if(!doSubmitTicket){
541
+ doSubmitTicket=true;
542
+ document.querySelector(MPv1Ticket.selectors.box_loading).style.background = "url("+MPv1Ticket.paths.loading+") 0 50% no-repeat #fff";
543
+ btn = document.querySelector(MPv1Ticket.selectors.form);
544
+ btn.submit();
545
+ }
546
+ }
547
+
548
+ MPv1Ticket.validateInputsTicket = function(event) {
549
+ event.preventDefault();
550
+ MPv1Ticket.hideErrors();
551
+ var valid_to_ticket = true;
552
+ var $inputs = MPv1Ticket.getForm().querySelectorAll("[data-checkout]");
553
+ var $inputs_to_validate_ticket = MPv1Ticket.inputs_to_validate_ticket;
554
+ var febraban = [];
555
+ var arr = [];
556
+ for (var x = 0; x < $inputs.length; x++) {
557
+ var element = $inputs[x];
558
+ if($inputs_to_validate_ticket.indexOf(element.getAttribute("data-checkout")) > -1){
559
+ if (element.value == -1 || element.value == "") {
560
+ arr.push(element.id);
561
+ valid_to_ticket = false;
562
+ } else {
563
+ febraban[element.id] = element.value;
564
+ }
565
+ }
566
+ }
567
+ if (!valid_to_ticket) {
568
+ MPv1Ticket.showErrors(arr);
569
+ } else {
570
+ MPv1Ticket.doPay(febraban);
571
+ }
572
+ }
573
+
574
+ MPv1Ticket.getForm = function(){
575
+ return document.querySelector(MPv1Ticket.selectors.form);
576
+ }
577
+
578
+ MPv1Ticket.addListenerEvent = function(el, eventName, handler){
579
+ if (el.addEventListener) {
580
+ el.addEventListener(eventName, handler);
581
+ } else {
582
+ el.attachEvent("on" + eventName, function(){
583
+ handler.call(el);
584
+ });
585
+ }
586
+ };
587
+
588
+ // Show/hide errors.
589
+
590
+ MPv1Ticket.showErrors = function(fields){
591
+ var $form = MPv1Ticket.getForm();
592
+ for(var x = 0; x < fields.length; x++){
593
+ var f = fields[x];
594
+ var $span = $form.querySelector("#error_" + f);
595
+ var $input = $form.querySelector($span.getAttribute("data-main"));
596
+ $span.style.display = "inline-block";
597
+ $input.classList.add("mp-error-input");
598
+ }
599
+ return;
600
+ }
601
+
602
+ MPv1Ticket.hideErrors = function(){
603
+ for(var x = 0; x < document.querySelectorAll("[data-checkout]").length; x++){
604
+ var $field = document.querySelectorAll("[data-checkout]")[x];
605
+ $field.classList.remove("mp-error-input");
606
+ } //end for
607
+ for(var x = 0; x < document.querySelectorAll(".erro_febraban").length; x++){
608
+ var $span = document.querySelectorAll(".erro_febraban")[x];
609
+ $span.style.display = "none";
610
+ }
611
+ return;
612
+ }
613
+
614
+ MPv1Ticket.actionsMLB = function() {
615
+ MPv1Ticket.initializeDocumentPessoaFisica();
616
+ MPv1Ticket.addListenerEvent(document.querySelector(MPv1Ticket.selectors.cpfcnpj), 'keyup', MPv1Ticket.execFormatDocument);
617
+ MPv1Ticket.addListenerEvent(document.querySelector(MPv1Ticket.selectors.radioTypeFisica), "change", MPv1Ticket.initializeDocumentPessoaFisica);
618
+ MPv1Ticket.addListenerEvent(document.querySelector(MPv1Ticket.selectors.radioTypeJuridica), "change", MPv1Ticket.initializeDocumentPessoaJuridica);
619
+ return;
620
+ }
621
+
622
+ MPv1Ticket.initializeDocumentPessoaFisica = function() {
623
+ // show elements
624
+ document.querySelector(MPv1Ticket.selectors.boxLastName).style.display = "block";
625
+ document.querySelector(MPv1Ticket.selectors.titleFirstName).style.display = "block";
626
+ document.querySelector(MPv1Ticket.selectors.titleDocNumber).style.display = "block";
627
+ // adjustment css
628
+ document.querySelector(MPv1Ticket.selectors.boxFirstName).classList.remove("form-col-8");
629
+ document.querySelector(MPv1Ticket.selectors.boxFirstName).classList.add("form-col-4");
630
+ // hide elements
631
+ document.querySelector(MPv1Ticket.selectors.titleFirstNameRazaoSocial).style.display = "none";
632
+ document.querySelector(MPv1Ticket.selectors.titleDocNumberCNPJ).style.display = "none";
633
+ // force max length CPF
634
+ document.querySelector(MPv1Ticket.selectors.cpfcnpj).maxLength = 14;
635
+ }
636
+
637
+ MPv1Ticket.initializeDocumentPessoaJuridica = function() {
638
+ // show elements
639
+ document.querySelector(MPv1Ticket.selectors.titleFirstNameRazaoSocial).style.display = "block";
640
+ document.querySelector(MPv1Ticket.selectors.titleDocNumberCNPJ).style.display = "block";
641
+ // adjustment css
642
+ document.querySelector(MPv1Ticket.selectors.boxFirstName).classList.remove("form-col-4");
643
+ document.querySelector(MPv1Ticket.selectors.boxFirstName).classList.add("form-col-8");
644
+ // Hide Elements
645
+ document.querySelector(MPv1Ticket.selectors.boxLastName).style.display = "none";
646
+ document.querySelector(MPv1Ticket.selectors.titleFirstName).style.display = "none";
647
+ document.querySelector(MPv1Ticket.selectors.titleDocNumber).style.display = "none";
648
+ // force max length CNPJ
649
+ document.querySelector(MPv1Ticket.selectors.cpfcnpj).maxLength = 18;
650
+ }
651
+
652
+ MPv1Ticket.validaCPF = function(strCPF) {
653
+ var Soma;
654
+ var Resto;
655
+ strCPF = strCPF.replace(/[.-\s]/g, "")
656
+ Soma = 0;
657
+ if (strCPF == "00000000000") {
658
+ return false;
659
+ }
660
+ for (i=1; i<=9; i++) {
661
+ Soma = Soma + parseInt(strCPF.substring(i-1, i)) * (11 - i);
662
+ }
663
+ Resto = (Soma * 10) % 11;
664
+ if ((Resto == 10) || (Resto == 11)) {
665
+ Resto = 0;
666
+ }
667
+ if (Resto != parseInt(strCPF.substring(9, 10)) ) {
668
+ return false;
669
+ }
670
+ Soma = 0;
671
+ for (i = 1; i <= 10; i++){
672
+ Soma = Soma + parseInt(strCPF.substring(i-1, i)) * (12 - i);
673
+ }
674
+ Resto = (Soma * 10) % 11;
675
+ if ((Resto == 10) || (Resto == 11)) {
676
+ Resto = 0;
677
+ }
678
+ if (Resto != parseInt(strCPF.substring(10, 11) ) ) {
679
+ return false;
680
+ }
681
+ return true;
682
+ }
683
+
684
+ MPv1Ticket.validaCNPJ = function(strCNPJ) {
685
+ strCNPJ = strCNPJ.replace(".","");
686
+ strCNPJ = strCNPJ.replace(".","");
687
+ strCNPJ = strCNPJ.replace(".","");
688
+ strCNPJ = strCNPJ.replace("-","");
689
+ strCNPJ = strCNPJ.replace("/","");
690
+ var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
691
+ digitos_iguais = 1;
692
+ if (strCNPJ.length < 14 && strCNPJ.length < 15) {
693
+ return false;
694
+ }
695
+ for (i = 0; i < strCNPJ.length - 1; i++) {
696
+ if (strCNPJ.charAt(i) != strCNPJ.charAt(i + 1)) {
697
+ digitos_iguais = 0;
698
+ break;
699
+ }
700
+ }
701
+ if (!digitos_iguais) {
702
+ tamanho = strCNPJ.length - 2
703
+ numeros = strCNPJ.substring(0,tamanho);
704
+ digitos = strCNPJ.substring(tamanho);
705
+ soma = 0;
706
+ pos = tamanho - 7;
707
+ for (i = tamanho; i >= 1; i--) {
708
+ soma += numeros.charAt(tamanho - i) * pos--;
709
+ if (pos < 2) {
710
+ pos = 9;
711
+ }
712
+ }
713
+ resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
714
+ if (resultado != digitos.charAt(0)) {
715
+ return false;
716
+ }
717
+ tamanho = tamanho + 1;
718
+ numeros = strCNPJ.substring(0,tamanho);
719
+ soma = 0;
720
+ pos = tamanho - 7;
721
+ for (i = tamanho; i >= 1; i--) {
722
+ soma += numeros.charAt(tamanho - i) * pos--;
723
+ if (pos < 2) {
724
+ pos = 9;
725
+ }
726
+ }
727
+ resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
728
+ if (resultado != digitos.charAt(1)) {
729
+ return false;
730
+ }
731
+ return true;
732
+ } else {
733
+ return false;
734
+ }
735
+ }
736
+
737
+ MPv1Ticket.execFormatDocument = function() {
738
+ v_obj= this;
739
+ setTimeout(function() {
740
+ v_obj.value = MPv1Ticket.formatDocument(v_obj.value)
741
+ }, 1)
742
+ }
743
+
744
+ MPv1Ticket.formatDocument = function(v) {
745
+ //Remove tudo o que não é dígito
746
+ v=v.replace(/\D/g,"")
747
+ if (document.querySelector(MPv1Ticket.selectors.radioTypeFisica).checked) { //CPF
748
+ //Coloca um ponto entre o terceiro e o quarto dígitos
749
+ v=v.replace(/(\d{3})(\d)/,"$1.$2")
750
+ //Coloca um ponto entre o terceiro e o quarto dígitos
751
+ //de novo (para o segundo bloco de números)
752
+ v=v.replace(/(\d{3})(\d)/,"$1.$2")
753
+ //Coloca um hífen entre o terceiro e o quarto dígitos
754
+ v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2")
755
+ } else { //CNPJ
756
+ //Coloca ponto entre o segundo e o terceiro dígitos
757
+ v=v.replace(/^(\d{2})(\d)/, "$1.$2")
758
+ //Coloca ponto entre o quinto e o sexto dígitos
759
+ v=v.replace(/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3")
760
+ //Coloca uma barra entre o oitavo e o nono dígitos
761
+ v=v.replace(/\.(\d{3})(\d)/, ".$1/$2")
762
+ //Coloca um hífen depois do bloco de quatro dígitos
763
+ v=v.replace(/(\d{4})(\d)/, "$1-$2")
764
+ }
765
+ return v
766
+ }
767
+
768
+ // ===
769
+
770
+ MPv1Ticket.Initialize = function( site_id, coupon_mode, discount_action_url, payer_email ) {
771
+
772
+ // Sets.
773
+ MPv1Ticket.site_id = site_id;
774
+ MPv1Ticket.coupon_of_discounts.default = coupon_mode;
775
+ MPv1Ticket.coupon_of_discounts.discount_action_url = discount_action_url;
776
+ MPv1Ticket.coupon_of_discounts.payer_email = payer_email;
777
+
778
+ // Flow coupon of discounts.
779
+ if ( MPv1Ticket.coupon_of_discounts.default ) {
780
+ MPv1Ticket.addListenerEvent(
781
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ),
782
+ "click",
783
+ MPv1Ticket.checkCouponEligibility
784
+ );
785
+ } else {
786
+ document.querySelector( MPv1Ticket.selectors.formCoupon ).style.display = "none";
787
+ }
788
+
789
+ // flow: MLB
790
+ if (MPv1Ticket.site_id == "MLB") {
791
+ MPv1Ticket.actionsMLB();
792
+ }
793
+
794
+ return;
795
+
796
+ }
797
+
798
+ this.MPv1Ticket = MPv1Ticket;
799
+
800
+ } ).call();
801
+
802
+ MPv1Ticket.getAmount = function() {
803
+ return document.querySelector( MPv1Ticket.selectors.amount )
804
+ .value - document.querySelector( MPv1Ticket.selectors.discount ).value;
805
+ }
806
+
807
+ MPv1Ticket.getAmountWithoutDiscount = function() {
808
+ return document.querySelector( MPv1Ticket.selectors.amount ).value;
809
+ }
810
+
811
  MPv1Ticket.text.apply = "<?php echo __( 'Apply', 'woocommerce-mercadopago' ); ?>";
812
  MPv1Ticket.text.remove = "<?php echo __( 'Remove', 'woocommerce-mercadopago' ); ?>";
813
  MPv1Ticket.text.coupon_empty = "<?php echo __( 'Please, inform your coupon code', 'woocommerce-mercadopago' ); ?>";
woocommerce-mercadopago.php CHANGED
@@ -3,14 +3,13 @@
3
  * Plugin Name: WooCommerce MercadoPago
4
  * Plugin URI: https://github.com/mercadopago/cart-woocommerce
5
  * Description: This is the <strong>oficial</strong> module of Mercado Pago for WooCommerce plugin. This module enables WooCommerce to use Mercado Pago as a payment Gateway for purchases made in your e-commerce store.
6
- * Version: 3.0.0
7
  * Author: Mercado Pago
8
  * Author URI: https://www.mercadopago.com.br/developers/
9
- * Requires at least: 4.4
10
- * Tested up to: 4.7
11
- *
12
  * Text Domain: woocommerce-mercadopago
13
  * Domain Path: /i18n/languages/
 
 
14
  *
15
  * @package MercadoPago
16
  * @category Core
@@ -22,6 +21,34 @@ if ( ! defined( 'ABSPATH' ) ) {
22
  exit;
23
  }
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  // Load Mercado Pago SDK
26
  require_once dirname( __FILE__ ) . '/includes/sdk/lib/mercadopago.php';
27
 
@@ -60,7 +87,7 @@ if ( ! class_exists( 'WC_Woo_Mercado_Pago_Module' ) ) :
60
  // ============================================================
61
 
62
  // General constants.
63
- const VERSION = '3.0.0';
64
  const MIN_PHP = 5.6;
65
 
66
  // Arrays to hold configurations for LatAm environment.
@@ -82,8 +109,6 @@ if ( ! class_exists( 'WC_Woo_Mercado_Pago_Module' ) ) :
82
  // Class constructor.
83
  private function __construct() {
84
 
85
- add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
86
-
87
  WC_Woo_Mercado_Pago_Module::$categories = WC_Woo_Mercado_Pago_Module::get_categories();
88
  WC_Woo_Mercado_Pago_Module::$country_configs = array(
89
  'MCO' => array(
@@ -146,7 +171,7 @@ if ( ! class_exists( 'WC_Woo_Mercado_Pago_Module' ) ) :
146
 
147
  // First of all, verify if WooCommerce is already installed.
148
  if ( class_exists( 'WC_Payment_Gateway' ) ) {
149
-
150
  // Adds each Mercado Pago gateway as available payment method.
151
  include_once dirname( __FILE__ ) . '/includes/WC_WooMercadoPago_BasicGateway.php';
152
  include_once dirname( __FILE__ ) . '/includes/WC_WooMercadoPago_CustomGateway.php';
@@ -162,7 +187,7 @@ if ( ! class_exists( 'WC_Woo_Mercado_Pago_Module' ) ) :
162
  include_once dirname( __FILE__ ) . '/includes/shipment/class-wc-mercadoenvios-package.php';
163
  add_filter( 'woocommerce_shipping_methods', array( $this, 'add_shipping' ) );
164
  add_filter( 'woocommerce_available_payment_gateways', array( $this, 'filter_payment_method_by_shipping' ) );
165
-
166
  // This adds custom links in the plugin page.
167
  add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'woomercadopago_settings_link' ) );
168
 
@@ -241,15 +266,6 @@ if ( ! class_exists( 'WC_Woo_Mercado_Pago_Module' ) ) :
241
  '</p></div>';
242
  }
243
 
244
- // Multi-language setup.
245
- public function load_plugin_textdomain() {
246
- load_plugin_textdomain(
247
- 'woocommerce-mercadopago',
248
- false,
249
- dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages/'
250
- );
251
- }
252
-
253
  // Add settings link on plugin page.
254
  public function woomercadopago_settings_link( $links ) {
255
  $plugin_links = array();
@@ -418,19 +434,22 @@ if ( ! class_exists( 'WC_Woo_Mercado_Pago_Module' ) ) :
418
  * @return a float that is the rate of conversion.
419
  */
420
  public static function get_conversion_rate( $used_currency ) {
 
421
  $email = ( wp_get_current_user()->ID != 0 ) ? wp_get_current_user()->user_email : null;
422
  MPRestClient::set_email( $email );
423
- $currency_obj = MPRestClient::get(
424
- array( 'uri' => '/currency_conversions/search?' .
425
- 'from=' . get_woocommerce_currency() .
426
- '&to=' . $used_currency
427
- ),
428
- WC_Woo_Mercado_Pago_Module::get_module_version()
429
- );
430
- if ( isset( $currency_obj['response'] ) ) {
431
- $currency_obj = $currency_obj['response'];
432
- if ( isset( $currency_obj['ratio'] ) ) {
433
- return ( (float) $currency_obj['ratio'] );
 
 
434
  }
435
  }
436
  return -1;
@@ -648,7 +667,7 @@ if ( ! class_exists( 'WC_Woo_Mercado_Pago_Module' ) ) :
648
  <option value="processing"' . ( $selection == 'processing' ? 'selected="selected"' : '' ) . '>' .
649
  __( "Update WooCommerce order to ", "woocommerce-mercadopago" ) . 'PROCESSING
650
  </option>
651
- <option value="on_hold"' . ( $selection == 'on_hold' ? 'selected="selected"' : '' ) . '>' .
652
  __( "Update WooCommerce order to ", "woocommerce-mercadopago" ) . 'ON-HOLD
653
  </option>
654
  <option value="completed"' . ( $selection == 'completed' ? 'selected="selected"' : '' ) . '>' .
@@ -925,6 +944,11 @@ if ( ! class_exists( 'WC_Woo_Mercado_Pago_Module' ) ) :
925
  } else {
926
  update_option( '_mp_store_identificator', '', true );
927
  }
 
 
 
 
 
928
  if ( isset( $_POST['currency_conversion_v0'] ) ) {
929
  update_option( '_mp_currency_conversion_v0', $_POST['currency_conversion_v0'], true );
930
  } else {
@@ -954,7 +978,7 @@ if ( ! class_exists( 'WC_Woo_Mercado_Pago_Module' ) ) :
954
  '<img width="14" height="14" src="' . plugins_url( 'assets/images/check.png', __FILE__ ) . '"> ' .
955
  __( 'WooCommerce is installed and enabled.', 'woocommerce-mercadopago' ) :
956
  '<img width="14" height="14" src="' . plugins_url( 'assets/images/error.png', __FILE__ ) . '"> ' .
957
- __( 'You don\'t have WooCommerce installed and enabled.', 'woocommerce-mercadopago' );
958
  // Creating PHP version message.
959
  $min_php_message = phpversion() >= WC_Woo_Mercado_Pago_Module::MIN_PHP ?
960
  '<img width="14" height="14" src="' . plugins_url( 'assets/images/check.png', __FILE__ ) . '"> ' .
@@ -1004,6 +1028,8 @@ if ( ! class_exists( 'WC_Woo_Mercado_Pago_Module' ) ) :
1004
  }
1005
  // Store identification.
1006
  $store_identificator = get_option( '_mp_store_identificator', 'WC-' );
 
 
1007
  // Debug mode.
1008
  $_mp_debug_mode = get_option( '_mp_debug_mode', '' );
1009
  if ( empty( $_mp_debug_mode ) ) {
3
  * Plugin Name: WooCommerce MercadoPago
4
  * Plugin URI: https://github.com/mercadopago/cart-woocommerce
5
  * Description: This is the <strong>oficial</strong> module of Mercado Pago for WooCommerce plugin. This module enables WooCommerce to use Mercado Pago as a payment Gateway for purchases made in your e-commerce store.
6
+ * Version: 3.0.1
7
  * Author: Mercado Pago
8
  * Author URI: https://www.mercadopago.com.br/developers/
 
 
 
9
  * Text Domain: woocommerce-mercadopago
10
  * Domain Path: /i18n/languages/
11
+ * WC requires at least: 3.0.0
12
+ * WC tested up to: 3.2.0
13
  *
14
  * @package MercadoPago
15
  * @category Core
21
  exit;
22
  }
23
 
24
+ /**
25
+ * Load plugin text domain.
26
+ *
27
+ * Need to require here before test for PHP version.
28
+ *
29
+ * @since 3.0.1
30
+ */
31
+ function wc_mercado_pago_load_plugin_textdomain() {
32
+ load_plugin_textdomain( 'woocommerce-mercadopago', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages/' );
33
+ }
34
+
35
+ add_action( 'init', 'wc_mercado_pago_load_plugin_textdomain' );
36
+
37
+ /**
38
+ * Notice about unsupported PHP version.
39
+ *
40
+ * @since 3.0.1
41
+ */
42
+ function wc_mercado_pago_unsupported_php_version_notice() {
43
+ echo '<div class="error"><p>' . esc_html__( 'WooCommerce Mercado Pago requires PHP version 5.6 or later. Please update your PHP version.', 'woocommerce-mercadopago' ) . '</p></div>';
44
+ }
45
+
46
+ // Check for PHP version and throw notice.
47
+ if ( version_compare( PHP_VERSION, '5.6', '<=' ) ) {
48
+ add_action( 'admin_notices', 'wc_mercado_pago_unsupported_php_version_notice' );
49
+ return;
50
+ }
51
+
52
  // Load Mercado Pago SDK
53
  require_once dirname( __FILE__ ) . '/includes/sdk/lib/mercadopago.php';
54
 
87
  // ============================================================
88
 
89
  // General constants.
90
+ const VERSION = '3.0.1';
91
  const MIN_PHP = 5.6;
92
 
93
  // Arrays to hold configurations for LatAm environment.
109
  // Class constructor.
110
  private function __construct() {
111
 
 
 
112
  WC_Woo_Mercado_Pago_Module::$categories = WC_Woo_Mercado_Pago_Module::get_categories();
113
  WC_Woo_Mercado_Pago_Module::$country_configs = array(
114
  'MCO' => array(
171
 
172
  // First of all, verify if WooCommerce is already installed.
173
  if ( class_exists( 'WC_Payment_Gateway' ) ) {
174
+
175
  // Adds each Mercado Pago gateway as available payment method.
176
  include_once dirname( __FILE__ ) . '/includes/WC_WooMercadoPago_BasicGateway.php';
177
  include_once dirname( __FILE__ ) . '/includes/WC_WooMercadoPago_CustomGateway.php';
187
  include_once dirname( __FILE__ ) . '/includes/shipment/class-wc-mercadoenvios-package.php';
188
  add_filter( 'woocommerce_shipping_methods', array( $this, 'add_shipping' ) );
189
  add_filter( 'woocommerce_available_payment_gateways', array( $this, 'filter_payment_method_by_shipping' ) );
190
+
191
  // This adds custom links in the plugin page.
192
  add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'woomercadopago_settings_link' ) );
193
 
266
  '</p></div>';
267
  }
268
 
 
 
 
 
 
 
 
 
 
269
  // Add settings link on plugin page.
270
  public function woomercadopago_settings_link( $links ) {
271
  $plugin_links = array();
434
  * @return a float that is the rate of conversion.
435
  */
436
  public static function get_conversion_rate( $used_currency ) {
437
+ $wc_currency = get_woocommerce_currency();
438
  $email = ( wp_get_current_user()->ID != 0 ) ? wp_get_current_user()->user_email : null;
439
  MPRestClient::set_email( $email );
440
+ if ( strlen( $wc_currency ) == 3 && strlen( $used_currency ) == 3 ) {
441
+ $currency_obj = MPRestClient::get(
442
+ array( 'uri' => '/currency_conversions/search?' .
443
+ 'from=' . get_woocommerce_currency() .
444
+ '&to=' . $used_currency
445
+ ),
446
+ WC_Woo_Mercado_Pago_Module::get_module_version()
447
+ );
448
+ if ( isset( $currency_obj['response'] ) ) {
449
+ $currency_obj = $currency_obj['response'];
450
+ if ( isset( $currency_obj['ratio'] ) ) {
451
+ return ( (float) $currency_obj['ratio'] );
452
+ }
453
  }
454
  }
455
  return -1;
667
  <option value="processing"' . ( $selection == 'processing' ? 'selected="selected"' : '' ) . '>' .
668
  __( "Update WooCommerce order to ", "woocommerce-mercadopago" ) . 'PROCESSING
669
  </option>
670
+ <option value="on_hold"' . ( $selection == 'on_hold' ? 'selected="selected"' : '' ) . '>' .
671
  __( "Update WooCommerce order to ", "woocommerce-mercadopago" ) . 'ON-HOLD
672
  </option>
673
  <option value="completed"' . ( $selection == 'completed' ? 'selected="selected"' : '' ) . '>' .
944
  } else {
945
  update_option( '_mp_store_identificator', '', true );
946
  }
947
+ /*if ( isset( $_POST['custom_domain'] ) ) {
948
+ update_option( '_mp_custom_domain', $_POST['custom_domain'], true );
949
+ } else {
950
+ update_option( '_mp_custom_domain', '', true );
951
+ }*/
952
  if ( isset( $_POST['currency_conversion_v0'] ) ) {
953
  update_option( '_mp_currency_conversion_v0', $_POST['currency_conversion_v0'], true );
954
  } else {
978
  '<img width="14" height="14" src="' . plugins_url( 'assets/images/check.png', __FILE__ ) . '"> ' .
979
  __( 'WooCommerce is installed and enabled.', 'woocommerce-mercadopago' ) :
980
  '<img width="14" height="14" src="' . plugins_url( 'assets/images/error.png', __FILE__ ) . '"> ' .
981
+ __( 'You don\'t have WooCommerce installed and enabled.', 'woocommerce-mercadopago' );
982
  // Creating PHP version message.
983
  $min_php_message = phpversion() >= WC_Woo_Mercado_Pago_Module::MIN_PHP ?
984
  '<img width="14" height="14" src="' . plugins_url( 'assets/images/check.png', __FILE__ ) . '"> ' .
1028
  }
1029
  // Store identification.
1030
  $store_identificator = get_option( '_mp_store_identificator', 'WC-' );
1031
+ // Custom domain for IPN.
1032
+ /*$custom_domain = get_option( '_mp_custom_domain', '' );*/
1033
  // Debug mode.
1034
  $_mp_debug_mode = get_option( '_mp_debug_mode', '' );
1035
  if ( empty( $_mp_debug_mode ) ) {