WooCommerce MercadoPago - Version old.2.2.13

Version Description

Download this release

Release Info

Developer mercadopago
Plugin Icon 128x128 WooCommerce MercadoPago
Version old.2.2.13
Comparing to
See all releases

Code changes from version old.2.1.0 to old.2.2.13

Files changed (50) hide show
  1. README.txt +220 -104
  2. admin/class-wc-mercadoenvios-admin-orders.php +86 -0
  3. assets/css/custom_checkout_mercadopago.css +159 -21
  4. images/MLU/CUPOM_MLU.png +0 -0
  5. images/MLU/MLU.png +0 -0
  6. images/MLU/banner_all_methods.png +0 -0
  7. images/MLU/credit_card.png +0 -0
  8. images/MLU/standard_mlu.png +0 -0
  9. images/MPE/CUPOM_MPE.png +0 -0
  10. images/MPE/MPE.png +0 -0
  11. images/MPE/banner_all_methods.png +0 -0
  12. images/MPE/credit_card.png +0 -0
  13. images/MPE/standard_mpe.png +0 -0
  14. images/bar_code.png +0 -0
  15. images/cart.png +0 -0
  16. images/credit_card.png +0 -0
  17. images/cvv.png +0 -0
  18. languages/woocommerce-mercadopago-module-es_AR.mo +0 -0
  19. languages/woocommerce-mercadopago-module-es_AR.po +320 -5
  20. languages/woocommerce-mercadopago-module-es_CL.mo +0 -0
  21. languages/woocommerce-mercadopago-module-es_CL.po +320 -5
  22. languages/woocommerce-mercadopago-module-es_CO.mo +0 -0
  23. languages/woocommerce-mercadopago-module-es_CO.po +320 -5
  24. languages/woocommerce-mercadopago-module-es_ES.mo +0 -0
  25. languages/woocommerce-mercadopago-module-es_ES.po +320 -5
  26. languages/woocommerce-mercadopago-module-es_MX.mo +0 -0
  27. languages/woocommerce-mercadopago-module-es_MX.po +320 -5
  28. languages/woocommerce-mercadopago-module-es_PE.mo +0 -0
  29. languages/woocommerce-mercadopago-module-es_PE.po +320 -5
  30. languages/woocommerce-mercadopago-module-es_UY.mo +0 -0
  31. languages/woocommerce-mercadopago-module-es_UY.po +1090 -0
  32. languages/woocommerce-mercadopago-module-es_VE.mo +0 -0
  33. languages/woocommerce-mercadopago-module-es_VE.po +320 -5
  34. languages/woocommerce-mercadopago-module-pt_BR.mo +0 -0
  35. languages/woocommerce-mercadopago-module-pt_BR.po +453 -65
  36. languages/woocommerce-mercadopago-module.pot +677 -370
  37. mercadopago-module.php +518 -103
  38. mercadopago/class-wc-product-mp_recurrent.php +362 -0
  39. mercadopago/css/woo-mercadopago-module.css +0 -14
  40. mercadopago/mercadopago-custom-gateway.php +1490 -772
  41. mercadopago/mercadopago-gateway.php +1622 -628
  42. mercadopago/mercadopago-subscription-gateway.php +1476 -0
  43. mercadopago/mercadopago-ticket-gateway.php +1503 -653
  44. mercadopago/sdk/lib/mercadopago.php +1200 -787
  45. shipment/abstract-wc-mercadoenvios-shipping.php +352 -0
  46. shipment/class-wc-mercadoenvios-package.php +257 -0
  47. shipment/class-wc-mercadoenvios-shipping-express.php +35 -0
  48. shipment/class-wc-mercadoenvios-shipping-normal.php +35 -0
  49. templates/credit-card/payment-form.php +1203 -964
  50. templates/ticket/ticket-form.php +608 -297
README.txt CHANGED
@@ -1,24 +1,24 @@
1
  === Woo Mercado Pago Module Oficial ===
2
- Contributors: mercadopago, mercadolivre
3
  Donate link: https://www.mercadopago.com.br/developers/
4
  Tags: ecommerce, mercadopago, woocommerce
5
- Requires at least: WooCommerce 2.1.x
6
- Tested up to: WooCommerce 2.5.x
7
- Stable tag: 2.1.0
8
  License: GPLv2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- This is the oficial module of Mercado Pago for WooCommerce plugin.
12
 
13
  == Description ==
14
 
15
- This module enables WooCommerce to use Mercado Pago as a payment Gateway for purchases made in your e-commerce store.
16
 
17
  = Why chose Mercado Pago =
18
  Mercado Pago owns the highest security standards with PCI certification level 1 and a specialized internal team working on fraud analysis. With Mercado Pago, you will be able to accept payments from the most common brands of credit card, offer purchase installments options and receive your payment with antecipation. You can also enable your customers to pay in the web or in their mobile devices.
19
 
20
  = Mercado Pago Main Features =
21
- * Online and real-time processment through IPN mechanism;
22
  * High approval rate with a robust fraud analysis;
23
  * Potential new customers with a base of more than 120 millions of users in Latin America;
24
  * PCI Level 1 Certification;
@@ -27,11 +27,12 @@ Mercado Pago owns the highest security standards with PCI certification level 1
27
  * Anticipation of receivables in D+2 or D+14 (According to Mercado Pago terms and conditions);
28
  * Payment in one click with Mercado Pago basic and custom checkouts;
29
  * Payment via tickets;
 
30
  * Seller's Protection Program.
31
 
32
  == Installation ==
33
 
34
- You have two way to install this module: from your WordPress Store, or by downloading and manually copying the module directory.
35
 
36
  = Install from WordPress =
37
  1. On your store administration, go to **Plugins** option in sidebar;
@@ -39,7 +40,7 @@ You have two way to install this module: from your WordPress Store, or by downlo
39
  3. You should find the module read to be installed. Click install.
40
 
41
  = Manual Download =
42
- 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/woo-mercado-pago-module.2.1.0.zip">WordPress Plugin Directory</a>);
43
  2. Unzip the folder and find "woo-mercado-pago-module" directory;
44
  3. Copy "woo-mercado-pago-module" directory to **[WordPressRootDirectory]/wp-content/plugins/** directory.
45
 
@@ -47,40 +48,29 @@ To confirm that your module is really installed, you can click in **Plugins** it
47
 
48
  = Configuration =
49
  1. On your store administration, go to **WooCommerce > Settings > Checkout** tab. In **Checkout Options**, you can find configurations for **Mercado Pago - Basic Checkout**, **Mercado Pago - Custom Checkout**, and **Mercado Pago - Ticket**.
50
- * To get your **Client_id** and **Client_secret** for your country, you can go to:
51
- * Argentina: https://www.mercadopago.com/mla/account/credentials?type=basic
52
- * Brazil: https://www.mercadopago.com/mlb/account/credentials?type=basic
53
- * Chile: https://www.mercadopago.com/mlc/account/credentials?type=basic
54
- * Colombia: https://www.mercadopago.com/mco/account/credentials?type=basic
55
- * Mexico: https://www.mercadopago.com/mlm/account/credentials?type=basic
56
- * Peru: https://www.mercadopago.com/mpe/account/credentials?type=basic
57
- * Venezuela: https://www.mercadopago.com/mlv/account/credentials?type=basic
58
- * And to get your **Public Key**/**Access Token** you can go to:
59
- * Argentina: https://www.mercadopago.com/mla/account/credentials?type=custom
60
- * Brazil: https://www.mercadopago.com/mlb/account/credentials?type=custom
61
- * Chile: https://www.mercadopago.com/mlc/account/credentials?type=custom
62
- * Colombia: https://www.mercadopago.com/mco/account/credentials?type=custom
63
- * Mexico: https://www.mercadopago.com/mlm/account/credentials?type=custom
64
- * Peru: https://www.mercadopago.com/mpe/account/credentials?type=custom
65
- * Venezuela: https://www.mercadopago.com/mlv/account/credentials?type=custom
66
  2. For the solutions **Mercado Pago - Basic Checkout**, **Mercado Pago - Custom Checkout**, and **Mercado Pago - Ticket**, you can:
67
- * Enable/Disable you plugin (for all solutions);
68
- * Set up your credentials (Client_id/Client_secret for Basic, Public Key/Access Token for Custom and Ticket);
69
- * Check your IPN URL, where you will get notified about payment updates (for all solutions);
70
- * Set the title of the payment option that will be shown to your customers (for all solutions);
71
- * Set the description of the payment option that will be shown to your customers (for all solutions);
72
- * Set the description that will be shown in your customer's invoice (for Custom and Ticket);
73
- * Enable coupon of campaigns for discounts (for Custom and Ticket);
74
- * Set binary mode that when charging a credit card, only [approved] or [reject] status will be taken (only for Custom);
75
- * Set the category of your store (for all solutions);
76
- * Set a prefix to identify your store, when you have multiple stores for only one Mercado Pago account (for all solutions);
77
- * Define how your customers will interact with Mercado Pago to pay their orders (only for Basic);
78
- * Configure the after-pay return behavior (only for Basic);
79
- * Configure the maximum installments allowed for your customers (only for Basic);
80
- * Configure the payment methods that you want to not work with Mercado Pago (only for Basic);
81
- * Enable currency conversion (for all solutions);
82
- * Enable/disable sandbox mode, where you can test your payments in Mercado Pago sandbox environment (for all solutions);
83
- * Enables/disable system logs (for all solutions).
 
 
 
84
 
85
  = In this video, we show how you can install and configure from your WordPress store =
86
 
@@ -100,103 +90,229 @@ Please, check our FAQ at: https://www.mercadopago.com.br/ajuda/
100
 
101
  2. `One Click Payment`
102
 
103
- 3. `Tickets`
104
 
105
- 4. `Discount Coupon`
106
-
107
- 5. `Configuration of Basic Checkout`
108
 
109
  == Changelog ==
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  = v2.1.0 (25/07/2016) =
112
- * Mercado Pago Discount Coupon
113
- - This feature lets Mercado Pago and merchants to use campaigns of discount created in their Mercado Pago accounts.
114
- * Currency Conversion
115
- - Added an option to try to use Mercado Pago currency ratio, to automatically convert any currencies to supported/used currency.
116
  * Improvements
117
  - Improved credentials validation algorithm;
118
  - Improved checkout data, with more clean and sanitized info for product image and description.
119
 
120
  = v2.0.5 (07/07/2016) =
121
- * Bug fixes
122
- - Fixed the informative URL of ticket IPN in admin page.
123
  * Improvements
124
  - Improved IPN behavior to handle consistent messages with absent IDs.
 
 
125
 
126
  = v2.0.4 (29/06/2016) =
 
 
127
  * Bug fixes
128
  - We have wrote a snippet to handle the absent shipment cost problem;
129
  - Fixed some URLs of the credentials link for Basic Checkout.
130
- * Improvements
131
- - Added a message in admin view when currency is different from used locally (used in credential's country).
132
 
133
  = v2.0.3 (21/06/2016) =
134
- * Bug fix in Basic Checkout for WooCommerce v2.6.x
135
- In WooCommerce v2.6.x, there was a bug related with the ampersand char that was wrongly converted to #38; on URLs and breaking the checkout flow. This update should place a fix to this problem.
136
-
137
  = v2.0.2 (13/06/2016) =
138
- * Rollout to Peru
139
- This plugin is now supporting Peru, which includes Basic Checkout, Custom Checkout, Tickets, and local language translations.
140
- * Fix a PHP version issue
141
- It was reported to us an issue in a function that uses an assign made directly from an array field. This feature is available in PHP 5.4.x or above and we've made an update to support older versions.
142
- * Fix a tax issue
143
- It wasn't been correctly added to the total value in Mercado Pago gateway.
144
-
145
  = v2.0.1 (09/06/2016) =
146
- * Customer Cards (One Click Payment)
147
- This feature allows customers to proceed to checkout with only one click. As Mercado Pago owns PCI standards, it can securely store credit card sensitive data and so register the customer card in the first time he uses it. Next time the customer comes back, he can use his card again, only by inserting its CVV code.
148
- * SSL verifications for custom checkout and ticket
149
- Custom Checkout and Ticket solutions can only be used with SSL certification. As the module behaves inconsistently if there is no SSL, we've put a watchdog to lock the solution if it is active without SSL.
150
- * Enabling any type of currency without disabling module (now, error message from API)
151
- Now, merchants have the option to use currencies of their choices in WooCommerce. Pay attention that Woo Mercado Pago will always set the currency related to the country of the Mercado Pago credentials.
152
 
153
  = v2.0.0 (01/06/2016) =
154
- * Custom Checkout for LatAm
155
- Offer a checkout fully customized to your brand experience with our simple-to-use payments API.
156
- * Ticket for LatAm
157
- Now, customer can pay orders with bank tickets.
158
- * Removed possibility to setting supportable but invalid currency
159
- We've made a fix to prevent users to select a valid currency (such as ARS), but for a different country set by credentials origin (such as MLB - Mercado Pago Brazil).
160
 
161
  = v1.0.5 (29/04/2016) =
162
- * Removal of extra shipment setup in checkout view
163
- We have made a workaround to prevent an extra shipment screen to appear.
164
- * Translation to es_ES
165
- Users can select Spain as module country, and translation should be ok.
166
- * Some bug fixes and code improvements
167
 
168
  = v1.0.4 (15/04/2016) =
169
- * Added a link to module settings page in plugin page
170
- We've increased the module description informations. Also we've put a link to make a vote on us. Please, VOTE US 5 STARS. Any feedback will be welcome!
171
- * Fixed status change when processing with two cards
172
- When using payments with two cards in Basic Checkout, the flow of order status wasn't correct in some cases when async IPN events occurs. We've made some adjustments to fix it.
173
 
174
  = v1.0.3 (23/03/2016) =
175
  * Improving algorithm when processing IPN
176
  Async calls and processment were refined.
177
 
178
  = v1.0.2 (23/03/2016) =
179
- * IPN URL wasn’t triggered when topic=payment
180
- Fixed a bug for some specific IPN messages of Mercado Pago.
181
 
182
  = v1.0.1 (23/03/2016) =
183
- * Added payment ID in order custom fields information
184
- Added some good informations about the payment in the order view.
185
- * Removed some unused files/code
186
- We've made some code cleaning.
187
- * Redesign of the logic of preferences when creating cart, separating items
188
- Itens are now separated in cart description. This increases the readability and consistency of informations in API level.
189
- * Proper information of shipment cost
190
- Previously, the shipment cost was passed together with the cart total order amount.
191
 
192
  = v1.0.0 (16/03/2016) =
193
- * LatAm Basic Checkout support
194
- Great for merchants who want to get going quickly and easily. This is the basic payment integration with Mercado Pago.
195
- * Set of configurable fields and customizations
196
- Title, description, category, and external reference customizations, integrations via iframe, modal, and redirection, with configurable auto-returning, max installments and payment method exclusion setup.
197
- * Sandbox and debug options
198
- Basicer can test orders by enabling debug mode or using sandbox environment.
199
-
200
  == Upgrade Notice ==
201
 
202
- If you're migrating from version 1.x.x to 2.x.x, please be sure to make a backup of your site and database, as there are many additional features and modifications between these versions.
1
  === Woo Mercado Pago Module Oficial ===
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: 2.2.13
8
  License: GPLv2 or later
9
+ License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Offer to your clients the best experience in e-Commerce by using Mercado Pago as your payment method.
12
 
13
  == Description ==
14
 
15
+ This module enables WooCommerce to use Mercado Pago as a payment method for purchases in your e-commerce store. By offering a nice set of tools like LatAm support, several card acquires, tickets, discounts, subscriptions, and many others e-Commerce features, this plugin wants to bring the best experience in payment checkouts.
16
 
17
  = Why chose Mercado Pago =
18
  Mercado Pago owns the highest security standards with PCI certification level 1 and a specialized internal team working on fraud analysis. With Mercado Pago, you will be able to accept payments from the most common brands of credit card, offer purchase installments options and receive your payment with antecipation. You can also enable your customers to pay in the web or in their mobile devices.
19
 
20
  = Mercado Pago Main Features =
21
+ * Online and real-time processment through IPN/Webhook mechanism;
22
  * High approval rate with a robust fraud analysis;
23
  * Potential new customers with a base of more than 120 millions of users in Latin America;
24
  * PCI Level 1 Certification;
27
  * Anticipation of receivables in D+2 or D+14 (According to Mercado Pago terms and conditions);
28
  * Payment in one click with Mercado Pago basic and custom checkouts;
29
  * Payment via tickets;
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.
36
 
37
  = Install from WordPress =
38
  1. On your store administration, go to **Plugins** option in sidebar;
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/woo-mercado-pago-module.2.2.13.zip">WordPress Plugin Directory</a>);
44
  2. Unzip the folder and find "woo-mercado-pago-module" directory;
45
  3. Copy "woo-mercado-pago-module" directory to **[WordPressRootDirectory]/wp-content/plugins/** directory.
46
 
48
 
49
  = Configuration =
50
  1. On your store administration, go to **WooCommerce > Settings > Checkout** tab. In **Checkout Options**, you can find configurations for **Mercado Pago - Basic Checkout**, **Mercado Pago - Custom Checkout**, and **Mercado Pago - Ticket**.
51
+ * To get your **Client_id** and **Client_secret** for your country, you can go to: <a href="https://www.mercadopago.com/mla/account/credentials?type=basic">Argentina</a>, <a href="https://www.mercadopago.com/mlb/account/credentials?type=basic">Brazil</a>, <a href="https://www.mercadopago.com/mlc/account/credentials?type=basic">Chile</a>, <a href="https://www.mercadopago.com/mco/account/credentials?type=basic">Colombia</a>, <a href="https://www.mercadopago.com/mlm/account/credentials?type=basic">Mexico</a>, <a href="https://www.mercadopago.com/mpe/account/credentials?type=basic">Peru</a>, <a href="https://www.mercadopago.com/mlu/account/credentials?type=basic">Uruguay</a>, and <a href="https://www.mercadopago.com/mlv/account/credentials?type=basic">Venezuela</a>.
52
+ * And to get your **Public Key**/**Access Token** you can go to: <a href="https://www.mercadopago.com/mla/account/credentials?type=custom">Argentina</a>, <a href="https://www.mercadopago.com/mlb/account/credentials?type=custom">Brazil</a>, <a href="https://www.mercadopago.com/mlc/account/credentials?type=custom">Chile</a>, <a href="https://www.mercadopago.com/mco/account/credentials?type=custom">Colombia</a>, <a href="https://www.mercadopago.com/mlm/account/credentials?type=custom">Mexico</a>, <a href="https://www.mercadopago.com/mpe/account/credentials?type=custom">Peru</a>, <a href="https://www.mercadopago.com/mlu/account/credentials?type=custom">Uruguay</a>, and <a href="https://www.mercadopago.com/mlv/account/credentials?type=custom">Venezuela</a>.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  2. For the solutions **Mercado Pago - Basic Checkout**, **Mercado Pago - Custom Checkout**, and **Mercado Pago - Ticket**, you can:
54
+ * Enable/Disable your plugin, so you can allow specific solutions for your business;
55
+ * Set up your credentials (Client_id/Client_secret for Basic Checkout and Subscriptions, Public Key/Access Token for Custom Checkout and Ticket);
56
+ * Check your IPN URL, where you will get notified about payment updates;
57
+ * Set the title of the payment option that will be shown to your customers;
58
+ * Set the description of the payment option that will be shown to your customers;
59
+ * Set the description that will be shown in your customer's invoice (for Custom Checkout and Ticket);
60
+ * Set binary mode that when charging a credit card, only [approved] or [reject] status will be taken (for Custom Checkout);
61
+ * Set the category of your store;
62
+ * Set stock reduction behavior (for Ticket);
63
+ * Set a prefix to identify your store, when you have multiple stores for only one Mercado Pago account;
64
+ * Define how your customers will interact with Mercado Pago to pay their orders (Basic Checkout and Subscriptions);
65
+ * Define discounts by payment method;
66
+ * Configure the after-pay return behavior (Basic Checkout);
67
+ * Configure the maximum installments allowed for your customers (for Basic Checkout);
68
+ * Configure the payment acquirers that you want to not work with Mercado Pago (for Basic Checkout);
69
+ * Configure call-back URLs for after-pay behavior (for Basic Checkout and Subscriptions);
70
+ * Enable coupon of campaigns for discounts (for Custom Checkout and Ticket);
71
+ * Enable currency conversion;
72
+ * Enable/disable sandbox mode, where you can test your payments in Mercado Pago sandbox environment (for Basic Checkout and Custom Checkout);
73
+ * Enables/disable system logs.
74
 
75
  = In this video, we show how you can install and configure from your WordPress store =
76
 
90
 
91
  2. `One Click Payment`
92
 
93
+ 3. `Tickets & Discounts`
94
 
95
+ 4. `Plugin Options`
 
 
96
 
97
  == Changelog ==
98
 
99
+ = v2.2.13 (28/08/2017) =
100
+ * Bug fixes
101
+ - Fixing a bug in Custom Checkout, that wasn't showing the form.
102
+
103
+ = v2.2.12 (14/08/2017) =
104
+ * Improvements
105
+ - Improved layout alignment for custom checkout and tickets;
106
+ - Added a checklist for platform statuses of cURL, SSL and PHP verification;
107
+ - Added the ticket view after the checkout.
108
+ * Bug fixes
109
+ - Fixed a bug that was locking inputs in ticket fields for Brazil.
110
+
111
+ = v2.2.11 (24/07/2017) =
112
+ * Improvements
113
+ - Improved credential validation algorithm;
114
+ - Added FEBRABAN rules for brazilian tickets.
115
+ * Bug fixes
116
+ - Resolved a bug when converting currency.
117
+
118
+ = v2.2.10 (04/07/2017) =
119
+ * Bug fixes
120
+ - Fixed a bug in subscriptions, where a recurrent product wasn't possible to be bought if its end-date is blank.
121
+
122
+ = v2.2.9 (29/06/2017) =
123
+ * Bug fixes
124
+ - Fixed a bug in Mercado Envios for WooCommerce 3.x, involving use of undeclared variable.
125
+
126
+ = v2.2.8 (26/06/2017) =
127
+ * Improvements
128
+ - Integrated error log API. This can help to debug any cURL requests;
129
+ - Increased stability.
130
+
131
+ = v2.2.7 (01/06/2017) =
132
+ * Improvements
133
+ - Optimizations in checkout JavaScript;
134
+ - Additional checking for test users within checkout process.
135
+ * Bug fixes
136
+ - Properly changing order status when paying with Basic Checkout using two cards.
137
+
138
+ = v2.2.6 (18/05/2017) =
139
+ * Improvements
140
+ - Increased stability for internal payment process.
141
+ * Bug fixes
142
+ - Fixed a bug related to shipping value not added to total amount;
143
+ - Not showing ticket button when payment method is not applicable;
144
+ - Removed unused snippet from ticket solution, handling an unexpected warning.
145
+
146
+ = v2.2.5 (08/05/2017) =
147
+ * Bug fixes
148
+ - Added support for WooCommerce/WordPress functions to handle warnings;
149
+ - Algorithm of Chile/Colombia when removing decimals.
150
+
151
+ = v2.2.4 (03/05/2017) =
152
+ * Improvements
153
+ - Increased support to older versions of PHP;
154
+ - Optimized calls of WordPress/WooCommerce specific functions.
155
+
156
+ = v2.2.3 (02/05/2017) =
157
+ * Bug fixes
158
+ - Resolved a bug related to the missing menus in Appearance.
159
+
160
+ = v2.2.2 (27/04/2017) =
161
+ * Improvements
162
+ - When using Mercado Envios, the plugin now sends an email with tracking ID to the merchant and customer.
163
+ * Bug fixes
164
+ - Resolved a bug related with non-persisted data of Simple Products;
165
+ - Resolved the status update for "in_procerss" in the basic checkout.
166
+
167
+ = v2.2.1 (13/04/2017) =
168
+ * Features
169
+ - Discount by payment method. Merchants can give a discount to their customers if the payment is made with a given gateway.
170
+ * Improvements
171
+ - Support for WooCommerce 3.0.0.
172
+
173
+ = v2.2.0 (03/04/2017) =
174
+ * Features
175
+ - Recurrent Payments. This feature allow merchants to create subscriptions and charge their customers periodically. For now, available only to Argentina, Brazil and Mexico.
176
+
177
+ = v2.1.9 (23/03/2017) =
178
+ * Features
179
+ - Mercado Envios for Basic Checkout. Now, merchants can use Mercado Envios services to ship products to their customers. For now, only available to Argentina, Brazil, and Mexico.
180
+
181
+ = v2.1.8 (13/02/2017) =
182
+ * Features
183
+ - Rollout to Uruguay. This plugin is now supporting Uruguay for Basic Checkout and its local language translations.
184
+ * Improvements
185
+ - Conformity with Argentina's E 51/2017 resolution to show up CFT/TEA amounts;
186
+ - Removed decimals from Chile and Colombia currencies, as they aren't used.
187
+ * Bug fixes
188
+ - Fixed and improved the coupon algorithm.
189
+
190
+ = v2.1.7 (12/12/2016) =
191
+ * Bug fixes
192
+ - When ticket payment method was enabled, the button for print ticket was appearing for other methods.
193
+
194
+ = v2.1.6 (09/12/2016) =
195
+ * Features
196
+ - Cancel/Refund API integration. Now, merchants can cancel and refund orders through store back-office. Options available in order details, order actions;
197
+ - Back url (checkout callback) configurable in back-office for basic checkout solution.
198
+ * Improvements
199
+ - Added option to select when (payment approval or order generation) to reduce stocks for tickets solution;
200
+ - Payment with ticket with order description at finish.
201
+
202
+ = v2.1.5 (16/11/2016) =
203
+ * Improvements
204
+ - Analytics of module settings.
205
+ * Bug fixes
206
+ - Fixed issue in ticket solution that was printing [null] in ticket description.
207
+
208
+ = v2.1.4 (20/10/2016) =
209
+ * Features
210
+ - Two Card Payment Configuration. Merchants can configure this feature in back-office through settings page.
211
+ * Improvements
212
+ - Removed some redundant notice messages;
213
+ - Improved algorithm to process settings page flow and checkout;
214
+ - Refactored code to meet WordPress coding standards.
215
+ * Bug fixes
216
+ - Fixed a SSL issue related to ticket solution (the open locker) in gateway selection.
217
+
218
+ = v2.1.3 (15/09/2016) =
219
+ * Improvements
220
+ - A few improvements in performance;
221
+ - Improved translations;
222
+ - Improved security with URL access via SSL in all module flow.
223
+
224
+ = v2.1.2 (18/08/2016) =
225
+ * Improvements
226
+ - Improved performance for both client and server sides.
227
+ * Bug fixes
228
+ - Fixed the product list for multiple items in Basic Checkout form.
229
+
230
+ = v2.1.1 (02/08/2016) =
231
+ * Improvements
232
+ - Improved log messages when applying discounts;
233
+ - Added a link to reprint ticket in customer account order page.
234
+ * Bug fixes
235
+ - Fixed tax fee for shipments.
236
+
237
  = v2.1.0 (25/07/2016) =
238
+ * Features
239
+ - Mercado Pago Discount Coupon. This feature lets Mercado Pago and merchants to use campaigns of discount created in their Mercado Pago accounts. Want to see how it works on-the-fly? Please check this video: <a href="https://www.youtube.com/watch?v=eQ2YYoWvzKQ">Discount Coupons</a>;
240
+ - Currency Conversion. Added an option to try to use Mercado Pago currency ratio, to automatically convert any currencies to supported/used currency.
 
241
  * Improvements
242
  - Improved credentials validation algorithm;
243
  - Improved checkout data, with more clean and sanitized info for product image and description.
244
 
245
  = v2.0.5 (07/07/2016) =
 
 
246
  * Improvements
247
  - Improved IPN behavior to handle consistent messages with absent IDs.
248
+ * Bug fixes
249
+ - Fixed the informative URL of ticket IPN in admin page.
250
 
251
  = v2.0.4 (29/06/2016) =
252
+ * Improvements
253
+ - Added a message in admin view when currency is different from used locally (used in credential's country).
254
  * Bug fixes
255
  - We have wrote a snippet to handle the absent shipment cost problem;
256
  - Fixed some URLs of the credentials link for Basic Checkout.
 
 
257
 
258
  = v2.0.3 (21/06/2016) =
259
+ * Bug fixes
260
+ - Basic Checkout for WooCommerce v2.6.x. In WooCommerce v2.6.x, there was a bug related with the ampersand char that was wrongly converted to #38; on URLs and breaking the checkout flow. This update should place a fix to this problem.
261
+
262
  = v2.0.2 (13/06/2016) =
263
+ * Features
264
+ - Rollout to Peru. This plugin is now supporting Peru, which includes Basic Checkout, Custom Checkout, Tickets, and local language translations.
265
+ * Bug fixes
266
+ - Fix a PHP version issue. It was reported to us an issue in a function that uses an assign made directly from an array field. This feature is available in PHP 5.4.x or above and we've made an update to support older versions;
267
+ - Fix a tax issue. It wasn't been correctly added to the total value in Mercado Pago gateway.
268
+
 
269
  = v2.0.1 (09/06/2016) =
270
+ * Features
271
+ - Customer Cards (One Click Payment). This feature allows customers to proceed to checkout with only one click. As Mercado Pago owns PCI standards, it can securely store credit card sensitive data and so register the customer card in the first time he uses it. Next time the customer comes back, he can use his card again, only by inserting its CVV code. Want to see how it works on-the-fly? Please check this video: <a href="https://www.youtube.com/watch?v=_KB8CtDei_4">Custom Checkout + Customer Cards</a>.
272
+ * Improvements
273
+ - SSL verifications for custom checkout and ticket. Custom Checkout and Ticket solutions can only be used with SSL certification. As the module behaves inconsistently if there is no SSL, we've put a watchdog to lock the solution if it is active without SSL;
274
+ - Enabling any type of currency without disabling module (now, error message from API). Now, merchants have the option to use currencies of their choices in WooCommerce. Pay attention that Woo Mercado Pago will always set the currency related to the country of the Mercado Pago credentials.
 
275
 
276
  = v2.0.0 (01/06/2016) =
277
+ * Features
278
+ - Custom Checkout for LatAm. Offer a checkout fully customized to your brand experience with our simple-to-use payments API. Want to see how it works on-the-fly? Please check this video: <a href="https://www.youtube.com/watch?v=_KB8CtDei_4">Custom Checkout + Customer Cards</a>;
279
+ - Ticket for LatAm. Now, customer can pay orders with bank tickets. Want to see how it works on-the-fly? Please check this video: <a href="https://www.youtube.com/watch?v=97VSVx5Uaj0">Tickets</a>.
280
+ * Improvements
281
+ - Removed possibility to setting supportable but invalid currency. We've made a fix to prevent users to select a valid currency (such as ARS), but for a different country set by credentials origin (such as MLB - Mercado Pago Brazil).
 
282
 
283
  = v1.0.5 (29/04/2016) =
284
+ * Improvements
285
+ - Removal of extra shipment setup in checkout view. We have made a workaround to prevent an extra shipment screen to appear;
286
+ - Translation to es_ES. Users can select Spain as module country, and translation should be ok.
287
+ * Bug fixes
288
+ - Some bug fixes to stabilize the module.
289
 
290
  = v1.0.4 (15/04/2016) =
291
+ * Improvements
292
+ - Added a link to module settings page in plugin page. We've increased the module description informations. Also we've put a link to make a vote on us. Please, VOTE US 5 STARS. Any feedback will be welcome!
293
+ - Fixed status change when processing with two cards. When using payments with two cards in Basic Checkout, the flow of order status wasn't correct in some cases when async IPN events occurs. We've made some adjustments to fix it.
 
294
 
295
  = v1.0.3 (23/03/2016) =
296
  * Improving algorithm when processing IPN
297
  Async calls and processment were refined.
298
 
299
  = v1.0.2 (23/03/2016) =
300
+ * Bug fixes
301
+ - IPN URL wasn’t triggered when topic=payment. Fixed a bug for some specific IPN messages of Mercado Pago.
302
 
303
  = v1.0.1 (23/03/2016) =
304
+ * Improvements
305
+ - Added payment ID in order custom fields information. Added some good informations about the payment in the order view;
306
+ - Removed some unused files/code. We've made some code cleaning;
307
+ - Redesign of the logic of preferences when creating cart, separating items. Itens are now separated in cart description. This increases the readability and consistency of informations in API level;
308
+ - Proper information of shipment cost. Previously, the shipment cost was passed together with the cart total order amount.
 
 
 
309
 
310
  = v1.0.0 (16/03/2016) =
311
+ * Features
312
+ - LatAm Basic Checkout support. Great for merchants who want to get going quickly and easily. This is the basic payment integration with Mercado Pago. Want to see how it works on-the-fly? Please check this video: <a href="https://www.youtube.com/watch?v=DgOsX1eXjBU">Basic Checkout</a>;
313
+ - Set of configurable fields and customizations. Title, description, category, and external reference customizations, integrations via iframe, modal, and redirection, with configurable auto-returning, max installments and payment method exclusion setup;
314
+ - Sandbox and debug options. Basicer can test orders by enabling debug mode or using sandbox environment.
315
+
 
 
316
  == Upgrade Notice ==
317
 
318
+ If you're migrating from version 1.x.x to 2.x.x, please be sure to make a backup of your site and database, as there are many additional features and modifications between these versions.
admin/class-wc-mercadoenvios-admin-orders.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin orders actions.
4
+ *
5
+ * @package WooCommerce_MercadoEnvios/Admin/Orders
6
+ * @version 2.2.2
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+
14
+ include_once dirname( __FILE__ ) . '/../mercadopago/sdk/lib/mercadopago.php';
15
+
16
+ /**
17
+ * MercadoEnvios orders.
18
+ */
19
+ class WC_MercadoEnvios_Admin_Orders {
20
+
21
+ /**
22
+ * Initialize the order actions.
23
+ */
24
+ public function __construct() {
25
+ add_action( 'add_meta_boxes', array( $this, 'register_metabox' ) );
26
+ }
27
+
28
+ /**
29
+ * Register tracking code metabox.
30
+ */
31
+ public function register_metabox() {
32
+ add_meta_box(
33
+ 'wc_mercadoenvios',
34
+ 'Mercado Envios',
35
+ array( $this, 'metabox_content' ),
36
+ 'shop_order',
37
+ 'side',
38
+ 'high'
39
+ );
40
+ }
41
+
42
+ /**
43
+ * Tracking code metabox content.
44
+ *
45
+ * @param WC_Post $post Post data.
46
+ */
47
+ public function metabox_content( $post ) {
48
+
49
+ $order = wc_get_order( $post->ID );
50
+ // WooCommerce 3.0 or later.
51
+ if ( method_exists( $order, 'get_meta' ) ) {
52
+ $shipment_id = $order->get_meta( '_mercadoenvios_shipment_id' );
53
+ $status = $order->get_meta( '_mercadoenvios_status' );
54
+ $tracking_number = $order->get_meta( '_mercadoenvios_tracking_number' );
55
+ } else {
56
+ $shipment_id = get_post_meta( $post->ID, '_mercadoenvios_shipment_id', true );
57
+ $status = get_post_meta( $post->ID, '_mercadoenvios_status', true );
58
+ $tracking_number = get_post_meta( $post->ID, '_mercadoenvios_tracking_number', true );
59
+ }
60
+
61
+ if ( isset( $status ) && $status != '' && $status != 'pending' ) {
62
+ echo '<label for="mercadoenvios_tracking_code">' . esc_html__( 'Tracking code:', 'woocommerce-mercadopago-module' ) . '</label><br />';
63
+ echo '<input type="text" id="mercadoenvios_tracking_code" name="mercadoenvios_tracking_code" value="' . esc_attr( $tracking_number ) . '" style="width: 100%;" />';
64
+
65
+ // Check exist shipment_id
66
+ if ( isset( $shipment_id ) && $shipment_id != '' ) {
67
+ $checkout_standard = new WC_WooMercadoPago_Gateway();
68
+ $client_id = $checkout_standard->get_option( 'client_id' );
69
+ $client_secret = $checkout_standard->get_option( 'client_secret' );
70
+
71
+ $this->mp = new MP(
72
+ WC_WooMercadoPago_Module::get_module_version(),
73
+ $client_id,
74
+ $client_secret
75
+ );
76
+
77
+ echo '<label for="mercadoenvios_tracking_number">' . esc_html__( 'Tag:', 'woocommerce-mercadopago-module' ) . '</label><br />';
78
+ echo '<a href="https://api.mercadolibre.com/shipment_labels?shipment_ids=' . esc_attr( $shipment_id ) . '&savePdf=Y&access_token=' . $this->mp->get_access_token() . '" class="button-primary" target="_blank">' . esc_html__( 'Print', 'woocommerce-mercadopago-module' ) . '</a>';
79
+ }
80
+ } else {
81
+ echo '<label for="mercadoenvios_tracking_number">' . esc_html__( 'Shipping is pending', 'woocommerce-mercadopago-module' ) . '</label><br />';
82
+ }
83
+ }
84
+ }
85
+
86
+ new WC_MercadoEnvios_Admin_Orders();
assets/css/custom_checkout_mercadopago.css CHANGED
@@ -7,7 +7,7 @@ body{
7
  #mp-box-form{
8
  padding: 15px 10px;
9
  margin: 30px auto;
10
- width: 320px;
11
  background-color: #fff;
12
  overflow: auto;
13
  border-radius: 5px;
@@ -69,7 +69,7 @@ body{
69
 
70
  .mp-box-inputs label{
71
  text-transform: uppercase;
72
- font-size: 14px;
73
  font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
74
  margin: 0 0 5px 0;
75
  display: block;
@@ -87,7 +87,6 @@ body{
87
  border-radius: 3px;
88
  color: #666;
89
  height: 40px;
90
- font-size: 20px;
91
  }
92
 
93
  .mp-box-inputs input:focus, .mp-box-inputs select:focus{
@@ -120,6 +119,21 @@ body{
120
  display: none;
121
  }
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  #submit{
124
  color: #fff;
125
  background-color: #337ab7;
@@ -139,16 +153,109 @@ body{
139
  }
140
 
141
  .mp-discount{
142
- text-transform: uppercase;
143
- font-size: 12px;
144
- /*color: #009EE3;*/
145
- color: #333333;
146
- display: none;
147
- font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
148
- clear: both;
149
- float: left;
150
  }
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  /*
153
  *
154
  *
@@ -157,14 +264,45 @@ body{
157
  *
158
  */
159
 
160
- .mp-error{
161
- text-transform: uppercase;
162
- font-size: 10px;
163
- color: red;
164
- font-weight: bold;
165
- display: none;
166
- font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
167
- clear: both;
168
- float: left;
169
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
7
  #mp-box-form{
8
  padding: 15px 10px;
9
  margin: 30px auto;
10
+ width: 400px;
11
  background-color: #fff;
12
  overflow: auto;
13
  border-radius: 5px;
69
 
70
  .mp-box-inputs label{
71
  text-transform: uppercase;
72
+ font-size: 12px;
73
  font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
74
  margin: 0 0 5px 0;
75
  display: block;
87
  border-radius: 3px;
88
  color: #666;
89
  height: 40px;
 
90
  }
91
 
92
  .mp-box-inputs input:focus, .mp-box-inputs select:focus{
119
  display: none;
120
  }
121
 
122
+ .mp-btn, .ch-btn {
123
+ background-color: #009ee3;
124
+ border: 1px solid #009ee3;
125
+ border-radius: 4px;
126
+ color: #fff;
127
+ display: inline-block;
128
+ font-family: Arial,sans-serif;
129
+ font-size: 18px;
130
+ font-weight: normal;
131
+ margin: 0;
132
+ padding: 10px;
133
+ text-align: center;
134
+ width: 100%;
135
+ }
136
+
137
  #submit{
138
  color: #fff;
139
  background-color: #337ab7;
153
  }
154
 
155
  .mp-discount{
156
+ text-transform: uppercase;
157
+ font-size: 12px;
158
+ /*color: #009EE3;*/
159
+ color: #333333;
160
+ display: none;
161
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
162
+ clear: both;
163
+ float: left;
164
  }
165
 
166
+ #mpCouponApplyed{
167
+ display: none;
168
+ border-style: solid;
169
+ border-width: thin;
170
+ border-color: #009EE3;
171
+ padding: 8px 8px 8px 8px;
172
+ }
173
+
174
+ #mpCouponApplyedTicket{
175
+ display: none;
176
+ border-style: solid;
177
+ border-width: thin;
178
+ border-color: #009EE3;
179
+ padding: 8px 8px 8px 8px;
180
+ }
181
+
182
+ #mercadopago-form-coupon .mp-box-message{
183
+ margin: -5px 0 5px;
184
+ }
185
+
186
+ [class^=form-col-]{
187
+ position: relative;
188
+ min-height: 1px;
189
+ padding-right: 5px;
190
+ padding-left: 5px;
191
+ float: left;
192
+ -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
193
+ -moz-box-sizing: border-box; /* Firefox, other Gecko */
194
+ box-sizing: border-box;
195
+ }
196
+
197
+ .form-col-1{
198
+ width: 8.33333333%;
199
+ }
200
+ .form-col-2{
201
+ width: 16.66666667%;
202
+ }
203
+ .form-col-3{
204
+ width: 25%;
205
+ }
206
+ .form-col-4{
207
+ width: 33.33333333%;
208
+ }
209
+ .form-col-5{
210
+ width: 41.66666667%;
211
+ }
212
+ .form-col-6{
213
+ width: 50%;
214
+ }
215
+ .form-col-7{
216
+ width: 58.33333333%;
217
+ }
218
+ .form-col-8{
219
+ width: 66.66666667%;
220
+ }
221
+ .form-col-9{
222
+ width: 75%;
223
+ }
224
+ .form-col-10{
225
+ width: 83.33333333%;
226
+ }
227
+ .form-col-11{
228
+ width: 91.66666667%;
229
+ }
230
+ .form-col-12{
231
+ width: 100%;
232
+ }
233
+
234
+ .form-control-mine {
235
+ width: 100%;
236
+ padding: 5px;
237
+ font-size: 16px;
238
+ color: #555;
239
+ background-color: #fff;
240
+ background-image: none;
241
+ border: 1px solid #ccc;
242
+ border-radius: 4px;
243
+ margin-bottom: 12px;
244
+ }
245
+
246
+ select#fixed {
247
+ -webkit-appearance: none;
248
+ }
249
+
250
+ .mensagem-febraban{
251
+ text-transform: uppercase;
252
+ font-size: 12px;
253
+ display: block;
254
+ margin-top: 8px;
255
+ margin-bottom: 16px;
256
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
257
+ }
258
+
259
  /*
260
  *
261
  *
264
  *
265
  */
266
 
267
+ .mp-error{
268
+ text-transform: uppercase;
269
+ font-size: 10px;
270
+ margin-bottom: 12px;
271
+ color: red;
272
+ font-weight: bold;
273
+ display: none;
274
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
275
+ clear: both;
276
+ float: left;
277
+ }
278
+
279
+ .erro_febraban{
280
+ text-transform: uppercase;
281
+ font-size: 10px;
282
+ margin-left: -10px;
283
+ margin-right: -10px;
284
+ margin-bottom: 12px;
285
+ color: red;
286
+ font-weight: bold;
287
+ display: none;
288
+ font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
289
+ clear: both;
290
+ }
291
+
292
+ #mp-box-input-tax-tea{
293
+ font-weight: 300;
294
+ text-align: center;
295
+ color: #333;
296
+ font-size: 12px;
297
+ display: none;
298
+ }
299
+
300
+ #mp-box-input-tax-cft{
301
+ font-weight: 300;
302
+ text-align: center;
303
+ color: #333;
304
+ font-size: 20px;
305
+ margin-top: 16px;
306
+ display: none;
307
+ }
308
 
images/MLU/CUPOM_MLU.png ADDED
Binary file
images/MLU/MLU.png ADDED
Binary file
images/MLU/banner_all_methods.png ADDED
Binary file
images/MLU/credit_card.png ADDED
Binary file
images/MLU/standard_mlu.png ADDED
Binary file
images/MPE/CUPOM_MPE.png CHANGED
File without changes
images/MPE/MPE.png CHANGED
File without changes
images/MPE/banner_all_methods.png CHANGED
File without changes
images/MPE/credit_card.png CHANGED
File without changes
images/MPE/standard_mpe.png CHANGED
File without changes
images/bar_code.png CHANGED
File without changes
images/cart.png ADDED
Binary file
images/credit_card.png CHANGED
File without changes
images/cvv.png CHANGED
File without changes
languages/woocommerce-mercadopago-module-es_AR.mo CHANGED
Binary file
languages/woocommerce-mercadopago-module-es_AR.po CHANGED
@@ -673,7 +673,7 @@ msgid "Please, select the ticket issuer of your preference."
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
- msgstr "Haga clic en el botón "PLACE ORDER". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
@@ -739,7 +739,7 @@ msgid "Discount Coupon"
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
- msgstr "MONEDA CONVERTIDA: "La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
@@ -747,8 +747,8 @@ msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
- msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio"
751
- msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago"
752
 
753
  msgid " is: "
754
  msgstr " es: "
@@ -772,4 +772,319 @@ msgid "Terms and Conditions of Use"
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
- msgstr "Pago convertido de"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
+ msgstr "Haga clic en el botón "Realizar el pedido". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
+ msgstr "MONEDA CONVERTIDA: La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
+ msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio."
751
+ msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago."
752
 
753
  msgid " is: "
754
  msgstr " es: "
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
+ msgstr "Pago convertido de"
776
+
777
+ msgid "Rate Us"
778
+ msgstr "Calificar"
779
+
780
+ msgid "Report Issue"
781
+ msgstr "Informar Problema"
782
+
783
+ msgid "Two Cards Mode"
784
+ msgstr "Modo de Dos Tarjetas"
785
+
786
+ msgid "Payments with Two Cards"
787
+ msgstr "Pagos con Dos Tarjetas"
788
+
789
+ msgid "Your customer will be able to use two different cards to pay the order."
790
+ msgstr "Su cliente será capaz de utilizar dos tarjetas diferentes para pagar el pedido."
791
+
792
+ msgid "Your Mercado Pago credentials Access Token appears to be misconfigured."
793
+ msgstr "La credencial Mercado Pago Access Token parece estar mal configurada."
794
+
795
+ msgid "Cancel Order"
796
+ msgstr "Cancelar la Compra"
797
+
798
+ msgid "Refund Order"
799
+ msgstr "Reembolso de Compra"
800
+
801
+ msgid "Back URL Options"
802
+ msgstr "Opciones de URL de Callback"
803
+
804
+ msgid "Sucess URL"
805
+ msgstr "URL de Éxito"
806
+
807
+ msgid "Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page."
808
+ msgstr "Donde los clientes serán redirigidos después de una compra exitosa. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
809
+
810
+ msgid "Failure URL"
811
+ msgstr "URL de Pago Rechazado"
812
+
813
+ msgid "Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page."
814
+ msgstr "Donde los clientes serán redirigidos después de una compra rechazada. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
815
+
816
+ msgid "Pending URL"
817
+ msgstr "URL de Pago Pendiente"
818
+
819
+ msgid "Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page."
820
+ msgstr "Donde los clientes ​serán redirigidos después de una compra pendiente. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
821
+
822
+ msgid "Stock Reduce"
823
+ msgstr "Reducir Inventario"
824
+
825
+ msgid "Reduce Stock in Order Generation"
826
+ msgstr "Reducir Inventario en la Orden"
827
+
828
+ msgid "Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval."
829
+ msgstr "Activar esta opción para reducir el inventario mediante la creación de un pedido. Desactivar para reducir sólo <strong>después</strong> de la aprobación del pago."
830
+
831
+ msgid "Recurrent Product"
832
+ msgstr "Producto Recurrente"
833
+
834
+ msgid "Frequency"
835
+ msgstr "Frecuencia"
836
+
837
+ msgid "Amount of time (in days or months) for the execution of the next payment."
838
+ msgstr "Cantidad de tiempo (en días o meses) para la ejecución del próximo pago."
839
+
840
+ msgid "Start date"
841
+ msgstr "Fecha de inicio"
842
+
843
+ msgid "First payment date (effective debit). Defaults to now if blank."
844
+ msgstr "Primera fecha de pago (débito efectivo). De forma predeterminada ahora, si está en blanco."
845
+
846
+ msgid "End date"
847
+ msgstr "Fecha final"
848
+
849
+ msgid "Deadline to generate new charges. Defaults to never if blank."
850
+ msgstr "Fecha límite para generar nuevos cargos. De forma predeterminada como nunca, si está en blanco."
851
+
852
+ msgid "Days"
853
+ msgstr "Días"
854
+
855
+ msgid "Months"
856
+ msgstr "Meses"
857
+
858
+ msgid "Indicates the period of time."
859
+ msgstr "Indica el período de tiempo."
860
+
861
+ msgid "The amount to charge the payer each period. Should be informed including taxes and discounts."
862
+ msgstr "La cantidad para cobrar el pagador en cada período. Debe ser informada incluyendo impuestos y descuentos."
863
+
864
+ msgid "Amount charged"
865
+ msgstr "Cantidad de cobro"
866
+
867
+ msgid "Uruguay"
868
+ msgstr "Uruguay"
869
+
870
+ msgid "Frequency type"
871
+ msgstr "Tipo de frecuencia"
872
+
873
+ msgid "Transaction amount"
874
+ msgstr "Valor de la transacción"
875
+
876
+ msgid "A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders."
877
+ msgstr "Un producto recurrente es una suscripción que debe adquirirse por separado en su carrito. Por favor, hace los pedidos por separado."
878
+
879
+ msgid "Subscription"
880
+ msgstr "Suscripción"
881
+
882
+ msgid "Enable Subscription"
883
+ msgstr "Habilitar Suscripción"
884
+
885
+ msgid "Subscription is Inactive"
886
+ msgstr "La Suscripción está Inactiva"
887
+
888
+ msgid "Subscribe with Mercado Pago"
889
+ msgstr "Suscribirse con Mercado Pago"
890
+
891
+ msgid "For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:"
892
+ msgstr "Para esta solución, usted debe configurar su URL de IPN. Puede acceder a ella en su cuenta para su específico país en:"
893
+
894
+ msgid "Discount by Gateway"
895
+ msgstr "Descuento por Gateway"
896
+
897
+ msgid "Give a percentual discount for your customers if they use this payment gateway."
898
+ msgstr "Dé un descuento porcentual para sus clientes si utilizan este medio de pago."
899
+
900
+ msgid "This field should be an integer greater or equal 0 and smaller than 100."
901
+ msgstr "Este campo debe ser un número entero mayor o igual 0 y menor que 100."
902
+
903
+ msgid "Discount Of"
904
+ msgstr "Descuento de"
905
+
906
+ msgid "Mercado Pago Subscription"
907
+ msgstr "Suscripción Mercado Pago"
908
+
909
+ msgid "Payment ID:"
910
+ msgstr "ID de Pago:"
911
+
912
+ msgid "Amount:"
913
+ msgstr "Cantidad:"
914
+
915
+ msgid "This operation could not be completed."
916
+ msgstr "Esta operación no se puede completar."
917
+
918
+ msgid "Operation successfully completed."
919
+ msgstr "La operación se realizó con éxito."
920
+
921
+ msgid "Refund Payment"
922
+ msgstr "Reembolso de Pago"
923
+
924
+ msgid "Cancel Payment"
925
+ msgstr "Cancelar Pago"
926
+
927
+ msgid "Mercado Pago - Subscription"
928
+ msgstr "Mercado Pago - Suscripcións"
929
+
930
+ msgid "Mercado Envios is a shipping method available only for payments with Mercado Pago."
931
+ msgstr "Mercado Envios es un método de envío disponible sólo para los pagos con Mercado Pago."
932
+
933
+ msgid "Free Shipping"
934
+ msgstr "Envío Gratuito"
935
+
936
+ msgid "Day"
937
+ msgstr "Día"
938
+
939
+ msgid "Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module."
940
+ msgstr "Habilitar los dos métodos de envío de Mercado Envios (Express y Normal) para el correcto funcionamiento del módulo."
941
+
942
+ msgid "Mercado Envios"
943
+ msgstr "Mercado Envios"
944
+
945
+ msgid "This controls the title which the user sees during checkout."
946
+ msgstr "Controla el título que se muestra al cliente durante el pago."
947
+
948
+ msgid "Enable free shipping for this shipping method"
949
+ msgstr "Habilitar el envío gratuito para este método de envío"
950
+
951
+ msgid "Delivery Time"
952
+ msgstr "Tiempo de Entrega"
953
+
954
+ msgid "Show estimated delivery time"
955
+ msgstr "Mostrar el tiempo estimado de entrega"
956
+
957
+ msgid "Display the estimated delivery time in working days."
958
+ msgstr "Mostrar el tiempo estimado de entrega en días laborables."
959
+
960
+ msgid "Buyer initiates complaint and requested a refund."
961
+ msgstr "El comprador ha iniciado una discusión y pide un extorno."
962
+
963
+ msgid "In return to sender"
964
+ msgstr "Volviendo al remitente"
965
+
966
+ msgid "Missing recipient for delivery"
967
+ msgstr "Destinatario ausente para envío"
968
+
969
+ msgid "Delayed shipping"
970
+ msgstr "Envío retrasado"
971
+
972
+ msgid "Unsuccessful"
973
+ msgstr "Fracasado"
974
+
975
+ msgid "Tag printed"
976
+ msgstr "Etiqueta impresa"
977
+
978
+ msgid "Tag ready to print"
979
+ msgstr "Etiquetar lista para imprimir"
980
+
981
+ msgid "Tracking code:"
982
+ msgstr "Código de rastreamiento:"
983
+
984
+ msgid "Tag:"
985
+ msgstr "Etiqueta:"
986
+
987
+ msgid "Shipping is pending"
988
+ msgstr "Envío pendiente"
989
+
990
+ msgid "Tutorial"
991
+ msgstr "Tutorial"
992
+
993
+ msgid "Discount Of "
994
+ msgstr "Descuento De "
995
+
996
+ msgid "Make this product a subscription."
997
+ msgstr "Hacer deste producto una suscripción."
998
+
999
+ msgid "Order"
1000
+ msgstr "Pedido"
1001
+
1002
+ msgid "Mercado Envios Tracking ID"
1003
+ msgstr "Código de rastreamiento de Mercado Envíos"
1004
+
1005
+ msgid "Hello,"
1006
+ msgstr "Hola,"
1007
+
1008
+ msgid "Your order"
1009
+ msgstr "Su pedido"
1010
+
1011
+ msgid "made in"
1012
+ msgstr "hecho en"
1013
+
1014
+ msgid "used Mercado Envios as its shipment method."
1015
+ msgstr "utilizó el Mercado Envíos como su medio de envío."
1016
+
1017
+ msgid "You can track it with the following Tracking ID:"
1018
+ msgstr "Usted puedes rastrearlo con lo siguiente código de rastreamiento:"
1019
+
1020
+ msgid "Best regards."
1021
+ msgstr "Saludos."
1022
+
1023
+ msgid "SELECT..."
1024
+ msgstr "SELECCIONE..."
1025
+
1026
+ msgid "NAME"
1027
+ msgstr "NOMBRE"
1028
+
1029
+ msgid "SURNAME"
1030
+ msgstr "APELLIDO"
1031
+
1032
+ msgid "DOCUMENT"
1033
+ msgstr "DOCUMENTO"
1034
+
1035
+ msgid "ADDRESS"
1036
+ msgstr "DIRECCIÓN"
1037
+
1038
+ msgid "NUMBER"
1039
+ msgstr "NÚMERO"
1040
+
1041
+ msgid "CITY"
1042
+ msgstr "CIUDAD"
1043
+
1044
+ msgid "STATE"
1045
+ msgstr "ESTADO"
1046
+
1047
+ msgid "ZIP"
1048
+ msgstr "CÓDIGO POSTAL"
1049
+
1050
+ msgid "You must inform you NAME"
1051
+ msgstr "Obligatorio informar su NOMBRE"
1052
+
1053
+ msgid "You must inform your SURNAME"
1054
+ msgstr "Obligatorio informar su APELLIDO"
1055
+
1056
+ msgid "You must inform your DOCUMENT"
1057
+ msgstr "Obligatorio informar su DOCUMENTO"
1058
+
1059
+ msgid "You must inform your ADDRESS"
1060
+ msgstr "Obligatorio informar su DIRECCIÓN"
1061
+
1062
+ msgid "You must inform your ADDRESS NUMBER"
1063
+ msgstr "Obligatorio informar su NÚMERO"
1064
+
1065
+ msgid "You must inform your CITY"
1066
+ msgstr "Obligatorio informar su CIUDAD"
1067
+
1068
+ msgid "You must inform your STATE"
1069
+ msgstr "Obligatorio informar su ESTADO"
1070
+
1071
+ msgid "You must inform your ZIP"
1072
+ msgstr "Obligatorio informar su CÓDIGO POSTAL"
1073
+
1074
+ msgid "Your PHP version is OK."
1075
+ msgstr "Su versión de PHP está bien."
1076
+
1077
+ msgid "Your PHP version do not support this module. You have %s, minimal required is %s."
1078
+ msgstr "Su versión de PHP no soporta este módulo. Tienes %s, la mínima requerida es %s."
1079
+
1080
+ msgid "cURL is installed."
1081
+ msgstr "cURL está instalado."
1082
+
1083
+ msgid "cURL is not installed."
1084
+ msgstr "cURL no está instalado."
1085
+
1086
+ msgid "SSL is missing in your site."
1087
+ msgstr "Falta el SSL en su sitio."
1088
+
1089
+ msgid "Your site has SSL enabled."
1090
+ msgstr "Su sitio tiene SSL habilitado."
languages/woocommerce-mercadopago-module-es_CL.mo CHANGED
Binary file
languages/woocommerce-mercadopago-module-es_CL.po CHANGED
@@ -673,7 +673,7 @@ msgid "Please, select the ticket issuer of your preference."
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
- msgstr "Haga clic en el botón "PLACE ORDER". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
@@ -739,7 +739,7 @@ msgid "Discount Coupon"
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
- msgstr "MONEDA CONVERTIDA: "La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
@@ -747,8 +747,8 @@ msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
- msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio"
751
- msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago"
752
 
753
  msgid " is: "
754
  msgstr " es: "
@@ -772,4 +772,319 @@ msgid "Terms and Conditions of Use"
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
- msgstr "Pago convertido de"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
+ msgstr "Haga clic en el botón "Realizar el pedido". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
+ msgstr "MONEDA CONVERTIDA: La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
+ msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio."
751
+ msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago."
752
 
753
  msgid " is: "
754
  msgstr " es: "
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
+ msgstr "Pago convertido de"
776
+
777
+ msgid "Rate Us"
778
+ msgstr "Calificar"
779
+
780
+ msgid "Report Issue"
781
+ msgstr "Informar Problema"
782
+
783
+ msgid "Two Cards Mode"
784
+ msgstr "Modo de Dos Tarjetas"
785
+
786
+ msgid "Payments with Two Cards"
787
+ msgstr "Pagos con Dos Tarjetas"
788
+
789
+ msgid "Your customer will be able to use two different cards to pay the order."
790
+ msgstr "Su cliente será capaz de utilizar dos tarjetas diferentes para pagar el pedido."
791
+
792
+ msgid "Your Mercado Pago credentials Access Token appears to be misconfigured."
793
+ msgstr "La credencial Mercado Pago Access Token parece estar mal configurada."
794
+
795
+ msgid "Cancel Order"
796
+ msgstr "Cancelar la Compra"
797
+
798
+ msgid "Refund Order"
799
+ msgstr "Reembolso de Compra"
800
+
801
+ msgid "Back URL Options"
802
+ msgstr "Opciones de URL de Callback"
803
+
804
+ msgid "Sucess URL"
805
+ msgstr "URL de Éxito"
806
+
807
+ msgid "Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page."
808
+ msgstr "Donde los clientes serán redirigidos después de una compra exitosa. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
809
+
810
+ msgid "Failure URL"
811
+ msgstr "URL de Pago Rechazado"
812
+
813
+ msgid "Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page."
814
+ msgstr "Donde los clientes serán redirigidos después de una compra rechazada. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
815
+
816
+ msgid "Pending URL"
817
+ msgstr "URL de Pago Pendiente"
818
+
819
+ msgid "Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page."
820
+ msgstr "Donde los clientes ​serán redirigidos después de una compra pendiente. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
821
+
822
+ msgid "Stock Reduce"
823
+ msgstr "Reducir Inventario"
824
+
825
+ msgid "Reduce Stock in Order Generation"
826
+ msgstr "Reducir Inventario en la Orden"
827
+
828
+ msgid "Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval."
829
+ msgstr "Activar esta opción para reducir el inventario mediante la creación de un pedido. Desactivar para reducir sólo <strong>después</strong> de la aprobación del pago."
830
+
831
+ msgid "Recurrent Product"
832
+ msgstr "Producto Recurrente"
833
+
834
+ msgid "Frequency"
835
+ msgstr "Frecuencia"
836
+
837
+ msgid "Amount of time (in days or months) for the execution of the next payment."
838
+ msgstr "Cantidad de tiempo (en días o meses) para la ejecución del próximo pago."
839
+
840
+ msgid "Start date"
841
+ msgstr "Fecha de inicio"
842
+
843
+ msgid "First payment date (effective debit). Defaults to now if blank."
844
+ msgstr "Primera fecha de pago (débito efectivo). De forma predeterminada ahora, si está en blanco."
845
+
846
+ msgid "End date"
847
+ msgstr "Fecha final"
848
+
849
+ msgid "Deadline to generate new charges. Defaults to never if blank."
850
+ msgstr "Fecha límite para generar nuevos cargos. De forma predeterminada como nunca, si está en blanco."
851
+
852
+ msgid "Days"
853
+ msgstr "Días"
854
+
855
+ msgid "Months"
856
+ msgstr "Meses"
857
+
858
+ msgid "Indicates the period of time."
859
+ msgstr "Indica el período de tiempo."
860
+
861
+ msgid "The amount to charge the payer each period. Should be informed including taxes and discounts."
862
+ msgstr "La cantidad para cobrar el pagador en cada período. Debe ser informada incluyendo impuestos y descuentos."
863
+
864
+ msgid "Amount charged"
865
+ msgstr "Cantidad de cobro"
866
+
867
+ msgid "Uruguay"
868
+ msgstr "Uruguay"
869
+
870
+ msgid "Frequency type"
871
+ msgstr "Tipo de frecuencia"
872
+
873
+ msgid "Transaction amount"
874
+ msgstr "Valor de la transacción"
875
+
876
+ msgid "A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders."
877
+ msgstr "Un producto recurrente es una suscripción que debe adquirirse por separado en su carrito. Por favor, hace los pedidos por separado."
878
+
879
+ msgid "Subscription"
880
+ msgstr "Suscripción"
881
+
882
+ msgid "Enable Subscription"
883
+ msgstr "Habilitar Suscripción"
884
+
885
+ msgid "Subscription is Inactive"
886
+ msgstr "La Suscripción está Inactiva"
887
+
888
+ msgid "Subscribe with Mercado Pago"
889
+ msgstr "Suscribirse con Mercado Pago"
890
+
891
+ msgid "For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:"
892
+ msgstr "Para esta solución, usted debe configurar su URL de IPN. Puede acceder a ella en su cuenta para su específico país en:"
893
+
894
+ msgid "Discount by Gateway"
895
+ msgstr "Descuento por Gateway"
896
+
897
+ msgid "Give a percentual discount for your customers if they use this payment gateway."
898
+ msgstr "Dé un descuento porcentual para sus clientes si utilizan este medio de pago."
899
+
900
+ msgid "This field should be an integer greater or equal 0 and smaller than 100."
901
+ msgstr "Este campo debe ser un número entero mayor o igual 0 y menor que 100."
902
+
903
+ msgid "Discount Of"
904
+ msgstr "Descuento de"
905
+
906
+ msgid "Mercado Pago Subscription"
907
+ msgstr "Suscripción Mercado Pago"
908
+
909
+ msgid "Payment ID:"
910
+ msgstr "ID de Pago:"
911
+
912
+ msgid "Amount:"
913
+ msgstr "Cantidad:"
914
+
915
+ msgid "This operation could not be completed."
916
+ msgstr "Esta operación no se puede completar."
917
+
918
+ msgid "Operation successfully completed."
919
+ msgstr "La operación se realizó con éxito."
920
+
921
+ msgid "Refund Payment"
922
+ msgstr "Reembolso de Pago"
923
+
924
+ msgid "Cancel Payment"
925
+ msgstr "Cancelar Pago"
926
+
927
+ msgid "Mercado Pago - Subscription"
928
+ msgstr "Mercado Pago - Suscripcións"
929
+
930
+ msgid "Mercado Envios is a shipping method available only for payments with Mercado Pago."
931
+ msgstr "Mercado Envios es un método de envío disponible sólo para los pagos con Mercado Pago."
932
+
933
+ msgid "Free Shipping"
934
+ msgstr "Envío Gratuito"
935
+
936
+ msgid "Day"
937
+ msgstr "Día"
938
+
939
+ msgid "Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module."
940
+ msgstr "Habilitar los dos métodos de envío de Mercado Envios (Express y Normal) para el correcto funcionamiento del módulo."
941
+
942
+ msgid "Mercado Envios"
943
+ msgstr "Mercado Envios"
944
+
945
+ msgid "This controls the title which the user sees during checkout."
946
+ msgstr "Controla el título que se muestra al cliente durante el pago."
947
+
948
+ msgid "Enable free shipping for this shipping method"
949
+ msgstr "Habilitar el envío gratuito para este método de envío"
950
+
951
+ msgid "Delivery Time"
952
+ msgstr "Tiempo de Entrega"
953
+
954
+ msgid "Show estimated delivery time"
955
+ msgstr "Mostrar el tiempo estimado de entrega"
956
+
957
+ msgid "Display the estimated delivery time in working days."
958
+ msgstr "Mostrar el tiempo estimado de entrega en días laborables."
959
+
960
+ msgid "Buyer initiates complaint and requested a refund."
961
+ msgstr "El comprador ha iniciado una discusión y pide un extorno."
962
+
963
+ msgid "In return to sender"
964
+ msgstr "Volviendo al remitente"
965
+
966
+ msgid "Missing recipient for delivery"
967
+ msgstr "Destinatario ausente para envío"
968
+
969
+ msgid "Delayed shipping"
970
+ msgstr "Envío retrasado"
971
+
972
+ msgid "Unsuccessful"
973
+ msgstr "Fracasado"
974
+
975
+ msgid "Tag printed"
976
+ msgstr "Etiqueta impresa"
977
+
978
+ msgid "Tag ready to print"
979
+ msgstr "Etiquetar lista para imprimir"
980
+
981
+ msgid "Tracking code:"
982
+ msgstr "Código de rastreamiento:"
983
+
984
+ msgid "Tag:"
985
+ msgstr "Etiqueta:"
986
+
987
+ msgid "Shipping is pending"
988
+ msgstr "Envío pendiente"
989
+
990
+ msgid "Tutorial"
991
+ msgstr "Tutorial"
992
+
993
+ msgid "Discount Of "
994
+ msgstr "Descuento De "
995
+
996
+ msgid "Make this product a subscription."
997
+ msgstr "Hacer deste producto una suscripción."
998
+
999
+ msgid "Order"
1000
+ msgstr "Pedido"
1001
+
1002
+ msgid "Mercado Envios Tracking ID"
1003
+ msgstr "Código de rastreamiento de Mercado Envíos"
1004
+
1005
+ msgid "Hello,"
1006
+ msgstr "Hola,"
1007
+
1008
+ msgid "Your order"
1009
+ msgstr "Su pedido"
1010
+
1011
+ msgid "made in"
1012
+ msgstr "hecho en"
1013
+
1014
+ msgid "used Mercado Envios as its shipment method."
1015
+ msgstr "utilizó el Mercado Envíos como su medio de envío."
1016
+
1017
+ msgid "You can track it with the following Tracking ID:"
1018
+ msgstr "Usted puedes rastrearlo con lo siguiente código de rastreamiento:"
1019
+
1020
+ msgid "Best regards."
1021
+ msgstr "Saludos."
1022
+
1023
+ msgid "SELECT..."
1024
+ msgstr "SELECCIONE..."
1025
+
1026
+ msgid "NAME"
1027
+ msgstr "NOMBRE"
1028
+
1029
+ msgid "SURNAME"
1030
+ msgstr "APELLIDO"
1031
+
1032
+ msgid "DOCUMENT"
1033
+ msgstr "DOCUMENTO"
1034
+
1035
+ msgid "ADDRESS"
1036
+ msgstr "DIRECCIÓN"
1037
+
1038
+ msgid "NUMBER"
1039
+ msgstr "NÚMERO"
1040
+
1041
+ msgid "CITY"
1042
+ msgstr "CIUDAD"
1043
+
1044
+ msgid "STATE"
1045
+ msgstr "ESTADO"
1046
+
1047
+ msgid "ZIP"
1048
+ msgstr "CÓDIGO POSTAL"
1049
+
1050
+ msgid "You must inform you NAME"
1051
+ msgstr "Obligatorio informar su NOMBRE"
1052
+
1053
+ msgid "You must inform your SURNAME"
1054
+ msgstr "Obligatorio informar su APELLIDO"
1055
+
1056
+ msgid "You must inform your DOCUMENT"
1057
+ msgstr "Obligatorio informar su DOCUMENTO"
1058
+
1059
+ msgid "You must inform your ADDRESS"
1060
+ msgstr "Obligatorio informar su DIRECCIÓN"
1061
+
1062
+ msgid "You must inform your ADDRESS NUMBER"
1063
+ msgstr "Obligatorio informar su NÚMERO"
1064
+
1065
+ msgid "You must inform your CITY"
1066
+ msgstr "Obligatorio informar su CIUDAD"
1067
+
1068
+ msgid "You must inform your STATE"
1069
+ msgstr "Obligatorio informar su ESTADO"
1070
+
1071
+ msgid "You must inform your ZIP"
1072
+ msgstr "Obligatorio informar su CÓDIGO POSTAL"
1073
+
1074
+ msgid "Your PHP version is OK."
1075
+ msgstr "Su versión de PHP está bien."
1076
+
1077
+ msgid "Your PHP version do not support this module. You have %s, minimal required is %s."
1078
+ msgstr "Su versión de PHP no soporta este módulo. Tienes %s, la mínima requerida es %s."
1079
+
1080
+ msgid "cURL is installed."
1081
+ msgstr "cURL está instalado."
1082
+
1083
+ msgid "cURL is not installed."
1084
+ msgstr "cURL no está instalado."
1085
+
1086
+ msgid "SSL is missing in your site."
1087
+ msgstr "Falta el SSL en su sitio."
1088
+
1089
+ msgid "Your site has SSL enabled."
1090
+ msgstr "Su sitio tiene SSL habilitado."
languages/woocommerce-mercadopago-module-es_CO.mo CHANGED
Binary file
languages/woocommerce-mercadopago-module-es_CO.po CHANGED
@@ -673,7 +673,7 @@ msgid "Please, select the ticket issuer of your preference."
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
- msgstr "Haga clic en el botón "PLACE ORDER". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
@@ -739,7 +739,7 @@ msgid "Discount Coupon"
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
- msgstr "MONEDA CONVERTIDA: "La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
@@ -747,8 +747,8 @@ msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
- msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio"
751
- msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago"
752
 
753
  msgid " is: "
754
  msgstr " es: "
@@ -772,4 +772,319 @@ msgid "Terms and Conditions of Use"
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
- msgstr "Pago convertido de"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
+ msgstr "Haga clic en el botón "Realizar el pedido". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
+ msgstr "MONEDA CONVERTIDA: La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
+ msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio."
751
+ msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago."
752
 
753
  msgid " is: "
754
  msgstr " es: "
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
+ msgstr "Pago convertido de"
776
+
777
+ msgid "Rate Us"
778
+ msgstr "Calificar"
779
+
780
+ msgid "Report Issue"
781
+ msgstr "Informar Problema"
782
+
783
+ msgid "Two Cards Mode"
784
+ msgstr "Modo de Dos Tarjetas"
785
+
786
+ msgid "Payments with Two Cards"
787
+ msgstr "Pagos con Dos Tarjetas"
788
+
789
+ msgid "Your customer will be able to use two different cards to pay the order."
790
+ msgstr "Su cliente será capaz de utilizar dos tarjetas diferentes para pagar el pedido."
791
+
792
+ msgid "Your Mercado Pago credentials Access Token appears to be misconfigured."
793
+ msgstr "La credencial Mercado Pago Access Token parece estar mal configurada."
794
+
795
+ msgid "Cancel Order"
796
+ msgstr "Cancelar la Compra"
797
+
798
+ msgid "Refund Order"
799
+ msgstr "Reembolso de Compra"
800
+
801
+ msgid "Back URL Options"
802
+ msgstr "Opciones de URL de Callback"
803
+
804
+ msgid "Sucess URL"
805
+ msgstr "URL de Éxito"
806
+
807
+ msgid "Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page."
808
+ msgstr "Donde los clientes serán redirigidos después de una compra exitosa. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
809
+
810
+ msgid "Failure URL"
811
+ msgstr "URL de Pago Rechazado"
812
+
813
+ msgid "Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page."
814
+ msgstr "Donde los clientes serán redirigidos después de una compra rechazada. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
815
+
816
+ msgid "Pending URL"
817
+ msgstr "URL de Pago Pendiente"
818
+
819
+ msgid "Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page."
820
+ msgstr "Donde los clientes ​serán redirigidos después de una compra pendiente. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
821
+
822
+ msgid "Stock Reduce"
823
+ msgstr "Reducir Inventario"
824
+
825
+ msgid "Reduce Stock in Order Generation"
826
+ msgstr "Reducir Inventario en la Orden"
827
+
828
+ msgid "Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval."
829
+ msgstr "Activar esta opción para reducir el inventario mediante la creación de un pedido. Desactivar para reducir sólo <strong>después</strong> de la aprobación del pago."
830
+
831
+ msgid "Recurrent Product"
832
+ msgstr "Producto Recurrente"
833
+
834
+ msgid "Frequency"
835
+ msgstr "Frecuencia"
836
+
837
+ msgid "Amount of time (in days or months) for the execution of the next payment."
838
+ msgstr "Cantidad de tiempo (en días o meses) para la ejecución del próximo pago."
839
+
840
+ msgid "Start date"
841
+ msgstr "Fecha de inicio"
842
+
843
+ msgid "First payment date (effective debit). Defaults to now if blank."
844
+ msgstr "Primera fecha de pago (débito efectivo). De forma predeterminada ahora, si está en blanco."
845
+
846
+ msgid "End date"
847
+ msgstr "Fecha final"
848
+
849
+ msgid "Deadline to generate new charges. Defaults to never if blank."
850
+ msgstr "Fecha límite para generar nuevos cargos. De forma predeterminada como nunca, si está en blanco."
851
+
852
+ msgid "Days"
853
+ msgstr "Días"
854
+
855
+ msgid "Months"
856
+ msgstr "Meses"
857
+
858
+ msgid "Indicates the period of time."
859
+ msgstr "Indica el período de tiempo."
860
+
861
+ msgid "The amount to charge the payer each period. Should be informed including taxes and discounts."
862
+ msgstr "La cantidad para cobrar el pagador en cada período. Debe ser informada incluyendo impuestos y descuentos."
863
+
864
+ msgid "Amount charged"
865
+ msgstr "Cantidad de cobro"
866
+
867
+ msgid "Uruguay"
868
+ msgstr "Uruguay"
869
+
870
+ msgid "Frequency type"
871
+ msgstr "Tipo de frecuencia"
872
+
873
+ msgid "Transaction amount"
874
+ msgstr "Valor de la transacción"
875
+
876
+ msgid "A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders."
877
+ msgstr "Un producto recurrente es una suscripción que debe adquirirse por separado en su carrito. Por favor, hace los pedidos por separado."
878
+
879
+ msgid "Subscription"
880
+ msgstr "Suscripción"
881
+
882
+ msgid "Enable Subscription"
883
+ msgstr "Habilitar Suscripción"
884
+
885
+ msgid "Subscription is Inactive"
886
+ msgstr "La Suscripción está Inactiva"
887
+
888
+ msgid "Subscribe with Mercado Pago"
889
+ msgstr "Suscribirse con Mercado Pago"
890
+
891
+ msgid "For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:"
892
+ msgstr "Para esta solución, usted debe configurar su URL de IPN. Puede acceder a ella en su cuenta para su específico país en:"
893
+
894
+ msgid "Discount by Gateway"
895
+ msgstr "Descuento por Gateway"
896
+
897
+ msgid "Give a percentual discount for your customers if they use this payment gateway."
898
+ msgstr "Dé un descuento porcentual para sus clientes si utilizan este medio de pago."
899
+
900
+ msgid "This field should be an integer greater or equal 0 and smaller than 100."
901
+ msgstr "Este campo debe ser un número entero mayor o igual 0 y menor que 100."
902
+
903
+ msgid "Discount Of"
904
+ msgstr "Descuento de"
905
+
906
+ msgid "Mercado Pago Subscription"
907
+ msgstr "Suscripción Mercado Pago"
908
+
909
+ msgid "Payment ID:"
910
+ msgstr "ID de Pago:"
911
+
912
+ msgid "Amount:"
913
+ msgstr "Cantidad:"
914
+
915
+ msgid "This operation could not be completed."
916
+ msgstr "Esta operación no se puede completar."
917
+
918
+ msgid "Operation successfully completed."
919
+ msgstr "La operación se realizó con éxito."
920
+
921
+ msgid "Refund Payment"
922
+ msgstr "Reembolso de Pago"
923
+
924
+ msgid "Cancel Payment"
925
+ msgstr "Cancelar Pago"
926
+
927
+ msgid "Mercado Pago - Subscription"
928
+ msgstr "Mercado Pago - Suscripcións"
929
+
930
+ msgid "Mercado Envios is a shipping method available only for payments with Mercado Pago."
931
+ msgstr "Mercado Envios es un método de envío disponible sólo para los pagos con Mercado Pago."
932
+
933
+ msgid "Free Shipping"
934
+ msgstr "Envío Gratuito"
935
+
936
+ msgid "Day"
937
+ msgstr "Día"
938
+
939
+ msgid "Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module."
940
+ msgstr "Habilitar los dos métodos de envío de Mercado Envios (Express y Normal) para el correcto funcionamiento del módulo."
941
+
942
+ msgid "Mercado Envios"
943
+ msgstr "Mercado Envios"
944
+
945
+ msgid "This controls the title which the user sees during checkout."
946
+ msgstr "Controla el título que se muestra al cliente durante el pago."
947
+
948
+ msgid "Enable free shipping for this shipping method"
949
+ msgstr "Habilitar el envío gratuito para este método de envío"
950
+
951
+ msgid "Delivery Time"
952
+ msgstr "Tiempo de Entrega"
953
+
954
+ msgid "Show estimated delivery time"
955
+ msgstr "Mostrar el tiempo estimado de entrega"
956
+
957
+ msgid "Display the estimated delivery time in working days."
958
+ msgstr "Mostrar el tiempo estimado de entrega en días laborables."
959
+
960
+ msgid "Buyer initiates complaint and requested a refund."
961
+ msgstr "El comprador ha iniciado una discusión y pide un extorno."
962
+
963
+ msgid "In return to sender"
964
+ msgstr "Volviendo al remitente"
965
+
966
+ msgid "Missing recipient for delivery"
967
+ msgstr "Destinatario ausente para envío"
968
+
969
+ msgid "Delayed shipping"
970
+ msgstr "Envío retrasado"
971
+
972
+ msgid "Unsuccessful"
973
+ msgstr "Fracasado"
974
+
975
+ msgid "Tag printed"
976
+ msgstr "Etiqueta impresa"
977
+
978
+ msgid "Tag ready to print"
979
+ msgstr "Etiquetar lista para imprimir"
980
+
981
+ msgid "Tracking code:"
982
+ msgstr "Código de rastreamiento:"
983
+
984
+ msgid "Tag:"
985
+ msgstr "Etiqueta:"
986
+
987
+ msgid "Shipping is pending"
988
+ msgstr "Envío pendiente"
989
+
990
+ msgid "Tutorial"
991
+ msgstr "Tutorial"
992
+
993
+ msgid "Discount Of "
994
+ msgstr "Descuento De "
995
+
996
+ msgid "Make this product a subscription."
997
+ msgstr "Hacer deste producto una suscripción."
998
+
999
+ msgid "Order"
1000
+ msgstr "Pedido"
1001
+
1002
+ msgid "Mercado Envios Tracking ID"
1003
+ msgstr "Código de rastreamiento de Mercado Envíos"
1004
+
1005
+ msgid "Hello,"
1006
+ msgstr "Hola,"
1007
+
1008
+ msgid "Your order"
1009
+ msgstr "Su pedido"
1010
+
1011
+ msgid "made in"
1012
+ msgstr "hecho en"
1013
+
1014
+ msgid "used Mercado Envios as its shipment method."
1015
+ msgstr "utilizó el Mercado Envíos como su medio de envío."
1016
+
1017
+ msgid "You can track it with the following Tracking ID:"
1018
+ msgstr "Usted puedes rastrearlo con lo siguiente código de rastreamiento:"
1019
+
1020
+ msgid "Best regards."
1021
+ msgstr "Saludos."
1022
+
1023
+ msgid "SELECT..."
1024
+ msgstr "SELECCIONE..."
1025
+
1026
+ msgid "NAME"
1027
+ msgstr "NOMBRE"
1028
+
1029
+ msgid "SURNAME"
1030
+ msgstr "APELLIDO"
1031
+
1032
+ msgid "DOCUMENT"
1033
+ msgstr "DOCUMENTO"
1034
+
1035
+ msgid "ADDRESS"
1036
+ msgstr "DIRECCIÓN"
1037
+
1038
+ msgid "NUMBER"
1039
+ msgstr "NÚMERO"
1040
+
1041
+ msgid "CITY"
1042
+ msgstr "CIUDAD"
1043
+
1044
+ msgid "STATE"
1045
+ msgstr "ESTADO"
1046
+
1047
+ msgid "ZIP"
1048
+ msgstr "CÓDIGO POSTAL"
1049
+
1050
+ msgid "You must inform you NAME"
1051
+ msgstr "Obligatorio informar su NOMBRE"
1052
+
1053
+ msgid "You must inform your SURNAME"
1054
+ msgstr "Obligatorio informar su APELLIDO"
1055
+
1056
+ msgid "You must inform your DOCUMENT"
1057
+ msgstr "Obligatorio informar su DOCUMENTO"
1058
+
1059
+ msgid "You must inform your ADDRESS"
1060
+ msgstr "Obligatorio informar su DIRECCIÓN"
1061
+
1062
+ msgid "You must inform your ADDRESS NUMBER"
1063
+ msgstr "Obligatorio informar su NÚMERO"
1064
+
1065
+ msgid "You must inform your CITY"
1066
+ msgstr "Obligatorio informar su CIUDAD"
1067
+
1068
+ msgid "You must inform your STATE"
1069
+ msgstr "Obligatorio informar su ESTADO"
1070
+
1071
+ msgid "You must inform your ZIP"
1072
+ msgstr "Obligatorio informar su CÓDIGO POSTAL"
1073
+
1074
+ msgid "Your PHP version is OK."
1075
+ msgstr "Su versión de PHP está bien."
1076
+
1077
+ msgid "Your PHP version do not support this module. You have %s, minimal required is %s."
1078
+ msgstr "Su versión de PHP no soporta este módulo. Tienes %s, la mínima requerida es %s."
1079
+
1080
+ msgid "cURL is installed."
1081
+ msgstr "cURL está instalado."
1082
+
1083
+ msgid "cURL is not installed."
1084
+ msgstr "cURL no está instalado."
1085
+
1086
+ msgid "SSL is missing in your site."
1087
+ msgstr "Falta el SSL en su sitio."
1088
+
1089
+ msgid "Your site has SSL enabled."
1090
+ msgstr "Su sitio tiene SSL habilitado."
languages/woocommerce-mercadopago-module-es_ES.mo CHANGED
Binary file
languages/woocommerce-mercadopago-module-es_ES.po CHANGED
@@ -673,7 +673,7 @@ msgid "Please, select the ticket issuer of your preference."
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
- msgstr "Haga clic en el botón "PLACE ORDER". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
@@ -739,7 +739,7 @@ msgid "Discount Coupon"
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
- msgstr "MONEDA CONVERTIDA: "La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
@@ -747,8 +747,8 @@ msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
- msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio"
751
- msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago"
752
 
753
  msgid " is: "
754
  msgstr " es: "
@@ -772,4 +772,319 @@ msgid "Terms and Conditions of Use"
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
- msgstr "Pago convertido de"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
+ msgstr "Haga clic en el botón "Realizar el pedido". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
+ msgstr "MONEDA CONVERTIDA: La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
+ msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio."
751
+ msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago."
752
 
753
  msgid " is: "
754
  msgstr " es: "
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
+ msgstr "Pago convertido de"
776
+
777
+ msgid "Rate Us"
778
+ msgstr "Calificar"
779
+
780
+ msgid "Report Issue"
781
+ msgstr "Informar Problema"
782
+
783
+ msgid "Two Cards Mode"
784
+ msgstr "Modo de Dos Tarjetas"
785
+
786
+ msgid "Payments with Two Cards"
787
+ msgstr "Pagos con Dos Tarjetas"
788
+
789
+ msgid "Your customer will be able to use two different cards to pay the order."
790
+ msgstr "Su cliente será capaz de utilizar dos tarjetas diferentes para pagar el pedido."
791
+
792
+ msgid "Your Mercado Pago credentials Access Token appears to be misconfigured."
793
+ msgstr "La credencial Mercado Pago Access Token parece estar mal configurada."
794
+
795
+ msgid "Cancel Order"
796
+ msgstr "Cancelar la Compra"
797
+
798
+ msgid "Refund Order"
799
+ msgstr "Reembolso de Compra"
800
+
801
+ msgid "Back URL Options"
802
+ msgstr "Opciones de URL de Callback"
803
+
804
+ msgid "Sucess URL"
805
+ msgstr "URL de Éxito"
806
+
807
+ msgid "Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page."
808
+ msgstr "Donde los clientes serán redirigidos después de una compra exitosa. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
809
+
810
+ msgid "Failure URL"
811
+ msgstr "URL de Pago Rechazado"
812
+
813
+ msgid "Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page."
814
+ msgstr "Donde los clientes serán redirigidos después de una compra rechazada. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
815
+
816
+ msgid "Pending URL"
817
+ msgstr "URL de Pago Pendiente"
818
+
819
+ msgid "Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page."
820
+ msgstr "Donde los clientes ​serán redirigidos después de una compra pendiente. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
821
+
822
+ msgid "Stock Reduce"
823
+ msgstr "Reducir Inventario"
824
+
825
+ msgid "Reduce Stock in Order Generation"
826
+ msgstr "Reducir Inventario en la Orden"
827
+
828
+ msgid "Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval."
829
+ msgstr "Activar esta opción para reducir el inventario mediante la creación de un pedido. Desactivar para reducir sólo <strong>después</strong> de la aprobación del pago."
830
+
831
+ msgid "Recurrent Product"
832
+ msgstr "Producto Recurrente"
833
+
834
+ msgid "Frequency"
835
+ msgstr "Frecuencia"
836
+
837
+ msgid "Amount of time (in days or months) for the execution of the next payment."
838
+ msgstr "Cantidad de tiempo (en días o meses) para la ejecución del próximo pago."
839
+
840
+ msgid "Start date"
841
+ msgstr "Fecha de inicio"
842
+
843
+ msgid "First payment date (effective debit). Defaults to now if blank."
844
+ msgstr "Primera fecha de pago (débito efectivo). De forma predeterminada ahora, si está en blanco."
845
+
846
+ msgid "End date"
847
+ msgstr "Fecha final"
848
+
849
+ msgid "Deadline to generate new charges. Defaults to never if blank."
850
+ msgstr "Fecha límite para generar nuevos cargos. De forma predeterminada como nunca, si está en blanco."
851
+
852
+ msgid "Days"
853
+ msgstr "Días"
854
+
855
+ msgid "Months"
856
+ msgstr "Meses"
857
+
858
+ msgid "Indicates the period of time."
859
+ msgstr "Indica el período de tiempo."
860
+
861
+ msgid "The amount to charge the payer each period. Should be informed including taxes and discounts."
862
+ msgstr "La cantidad para cobrar el pagador en cada período. Debe ser informada incluyendo impuestos y descuentos."
863
+
864
+ msgid "Amount charged"
865
+ msgstr "Cantidad de cobro"
866
+
867
+ msgid "Uruguay"
868
+ msgstr "Uruguay"
869
+
870
+ msgid "Frequency type"
871
+ msgstr "Tipo de frecuencia"
872
+
873
+ msgid "Transaction amount"
874
+ msgstr "Valor de la transacción"
875
+
876
+ msgid "A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders."
877
+ msgstr "Un producto recurrente es una suscripción que debe adquirirse por separado en su carrito. Por favor, hace los pedidos por separado."
878
+
879
+ msgid "Subscription"
880
+ msgstr "Suscripción"
881
+
882
+ msgid "Enable Subscription"
883
+ msgstr "Habilitar Suscripción"
884
+
885
+ msgid "Subscription is Inactive"
886
+ msgstr "La Suscripción está Inactiva"
887
+
888
+ msgid "Subscribe with Mercado Pago"
889
+ msgstr "Suscribirse con Mercado Pago"
890
+
891
+ msgid "For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:"
892
+ msgstr "Para esta solución, usted debe configurar su URL de IPN. Puede acceder a ella en su cuenta para su específico país en:"
893
+
894
+ msgid "Discount by Gateway"
895
+ msgstr "Descuento por Gateway"
896
+
897
+ msgid "Give a percentual discount for your customers if they use this payment gateway."
898
+ msgstr "Dé un descuento porcentual para sus clientes si utilizan este medio de pago."
899
+
900
+ msgid "This field should be an integer greater or equal 0 and smaller than 100."
901
+ msgstr "Este campo debe ser un número entero mayor o igual 0 y menor que 100."
902
+
903
+ msgid "Discount Of"
904
+ msgstr "Descuento de"
905
+
906
+ msgid "Mercado Pago Subscription"
907
+ msgstr "Suscripción Mercado Pago"
908
+
909
+ msgid "Payment ID:"
910
+ msgstr "ID de Pago:"
911
+
912
+ msgid "Amount:"
913
+ msgstr "Cantidad:"
914
+
915
+ msgid "This operation could not be completed."
916
+ msgstr "Esta operación no se puede completar."
917
+
918
+ msgid "Operation successfully completed."
919
+ msgstr "La operación se realizó con éxito."
920
+
921
+ msgid "Refund Payment"
922
+ msgstr "Reembolso de Pago"
923
+
924
+ msgid "Cancel Payment"
925
+ msgstr "Cancelar Pago"
926
+
927
+ msgid "Mercado Pago - Subscription"
928
+ msgstr "Mercado Pago - Suscripcións"
929
+
930
+ msgid "Mercado Envios is a shipping method available only for payments with Mercado Pago."
931
+ msgstr "Mercado Envios es un método de envío disponible sólo para los pagos con Mercado Pago."
932
+
933
+ msgid "Free Shipping"
934
+ msgstr "Envío Gratuito"
935
+
936
+ msgid "Day"
937
+ msgstr "Día"
938
+
939
+ msgid "Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module."
940
+ msgstr "Habilitar los dos métodos de envío de Mercado Envios (Express y Normal) para el correcto funcionamiento del módulo."
941
+
942
+ msgid "Mercado Envios"
943
+ msgstr "Mercado Envios"
944
+
945
+ msgid "This controls the title which the user sees during checkout."
946
+ msgstr "Controla el título que se muestra al cliente durante el pago."
947
+
948
+ msgid "Enable free shipping for this shipping method"
949
+ msgstr "Habilitar el envío gratuito para este método de envío"
950
+
951
+ msgid "Delivery Time"
952
+ msgstr "Tiempo de Entrega"
953
+
954
+ msgid "Show estimated delivery time"
955
+ msgstr "Mostrar el tiempo estimado de entrega"
956
+
957
+ msgid "Display the estimated delivery time in working days."
958
+ msgstr "Mostrar el tiempo estimado de entrega en días laborables."
959
+
960
+ msgid "Buyer initiates complaint and requested a refund."
961
+ msgstr "El comprador ha iniciado una discusión y pide un extorno."
962
+
963
+ msgid "In return to sender"
964
+ msgstr "Volviendo al remitente"
965
+
966
+ msgid "Missing recipient for delivery"
967
+ msgstr "Destinatario ausente para envío"
968
+
969
+ msgid "Delayed shipping"
970
+ msgstr "Envío retrasado"
971
+
972
+ msgid "Unsuccessful"
973
+ msgstr "Fracasado"
974
+
975
+ msgid "Tag printed"
976
+ msgstr "Etiqueta impresa"
977
+
978
+ msgid "Tag ready to print"
979
+ msgstr "Etiquetar lista para imprimir"
980
+
981
+ msgid "Tracking code:"
982
+ msgstr "Código de rastreamiento:"
983
+
984
+ msgid "Tag:"
985
+ msgstr "Etiqueta:"
986
+
987
+ msgid "Shipping is pending"
988
+ msgstr "Envío pendiente"
989
+
990
+ msgid "Tutorial"
991
+ msgstr "Tutorial"
992
+
993
+ msgid "Discount Of "
994
+ msgstr "Descuento De "
995
+
996
+ msgid "Make this product a subscription."
997
+ msgstr "Hacer deste producto una suscripción."
998
+
999
+ msgid "Order"
1000
+ msgstr "Pedido"
1001
+
1002
+ msgid "Mercado Envios Tracking ID"
1003
+ msgstr "Código de rastreamiento de Mercado Envíos"
1004
+
1005
+ msgid "Hello,"
1006
+ msgstr "Hola,"
1007
+
1008
+ msgid "Your order"
1009
+ msgstr "Su pedido"
1010
+
1011
+ msgid "made in"
1012
+ msgstr "hecho en"
1013
+
1014
+ msgid "used Mercado Envios as its shipment method."
1015
+ msgstr "utilizó el Mercado Envíos como su medio de envío."
1016
+
1017
+ msgid "You can track it with the following Tracking ID:"
1018
+ msgstr "Usted puedes rastrearlo con lo siguiente código de rastreamiento:"
1019
+
1020
+ msgid "Best regards."
1021
+ msgstr "Saludos."
1022
+
1023
+ msgid "SELECT..."
1024
+ msgstr "SELECCIONE..."
1025
+
1026
+ msgid "NAME"
1027
+ msgstr "NOMBRE"
1028
+
1029
+ msgid "SURNAME"
1030
+ msgstr "APELLIDO"
1031
+
1032
+ msgid "DOCUMENT"
1033
+ msgstr "DOCUMENTO"
1034
+
1035
+ msgid "ADDRESS"
1036
+ msgstr "DIRECCIÓN"
1037
+
1038
+ msgid "NUMBER"
1039
+ msgstr "NÚMERO"
1040
+
1041
+ msgid "CITY"
1042
+ msgstr "CIUDAD"
1043
+
1044
+ msgid "STATE"
1045
+ msgstr "ESTADO"
1046
+
1047
+ msgid "ZIP"
1048
+ msgstr "CÓDIGO POSTAL"
1049
+
1050
+ msgid "You must inform you NAME"
1051
+ msgstr "Obligatorio informar su NOMBRE"
1052
+
1053
+ msgid "You must inform your SURNAME"
1054
+ msgstr "Obligatorio informar su APELLIDO"
1055
+
1056
+ msgid "You must inform your DOCUMENT"
1057
+ msgstr "Obligatorio informar su DOCUMENTO"
1058
+
1059
+ msgid "You must inform your ADDRESS"
1060
+ msgstr "Obligatorio informar su DIRECCIÓN"
1061
+
1062
+ msgid "You must inform your ADDRESS NUMBER"
1063
+ msgstr "Obligatorio informar su NÚMERO"
1064
+
1065
+ msgid "You must inform your CITY"
1066
+ msgstr "Obligatorio informar su CIUDAD"
1067
+
1068
+ msgid "You must inform your STATE"
1069
+ msgstr "Obligatorio informar su ESTADO"
1070
+
1071
+ msgid "You must inform your ZIP"
1072
+ msgstr "Obligatorio informar su CÓDIGO POSTAL"
1073
+
1074
+ msgid "Your PHP version is OK."
1075
+ msgstr "Su versión de PHP está bien."
1076
+
1077
+ msgid "Your PHP version do not support this module. You have %s, minimal required is %s."
1078
+ msgstr "Su versión de PHP no soporta este módulo. Tienes %s, la mínima requerida es %s."
1079
+
1080
+ msgid "cURL is installed."
1081
+ msgstr "cURL está instalado."
1082
+
1083
+ msgid "cURL is not installed."
1084
+ msgstr "cURL no está instalado."
1085
+
1086
+ msgid "SSL is missing in your site."
1087
+ msgstr "Falta el SSL en su sitio."
1088
+
1089
+ msgid "Your site has SSL enabled."
1090
+ msgstr "Su sitio tiene SSL habilitado."
languages/woocommerce-mercadopago-module-es_MX.mo CHANGED
Binary file
languages/woocommerce-mercadopago-module-es_MX.po CHANGED
@@ -673,7 +673,7 @@ msgid "Please, select the ticket issuer of your preference."
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
- msgstr "Haga clic en el botón "PLACE ORDER". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
@@ -739,7 +739,7 @@ msgid "Discount Coupon"
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
- msgstr "MONEDA CONVERTIDA: "La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
@@ -747,8 +747,8 @@ msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
- msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio"
751
- msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago"
752
 
753
  msgid " is: "
754
  msgstr " es: "
@@ -772,4 +772,319 @@ msgid "Terms and Conditions of Use"
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
- msgstr "Pago convertido de"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
+ msgstr "Haga clic en el botón "Realizar el pedido". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
+ msgstr "MONEDA CONVERTIDA: La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
+ msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio."
751
+ msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago."
752
 
753
  msgid " is: "
754
  msgstr " es: "
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
+ msgstr "Pago convertido de"
776
+
777
+ msgid "Rate Us"
778
+ msgstr "Calificar"
779
+
780
+ msgid "Report Issue"
781
+ msgstr "Informar Problema"
782
+
783
+ msgid "Two Cards Mode"
784
+ msgstr "Modo de Dos Tarjetas"
785
+
786
+ msgid "Payments with Two Cards"
787
+ msgstr "Pagos con Dos Tarjetas"
788
+
789
+ msgid "Your customer will be able to use two different cards to pay the order."
790
+ msgstr "Su cliente será capaz de utilizar dos tarjetas diferentes para pagar el pedido."
791
+
792
+ msgid "Your Mercado Pago credentials Access Token appears to be misconfigured."
793
+ msgstr "La credencial Mercado Pago Access Token parece estar mal configurada."
794
+
795
+ msgid "Cancel Order"
796
+ msgstr "Cancelar la Compra"
797
+
798
+ msgid "Refund Order"
799
+ msgstr "Reembolso de Compra"
800
+
801
+ msgid "Back URL Options"
802
+ msgstr "Opciones de URL de Callback"
803
+
804
+ msgid "Sucess URL"
805
+ msgstr "URL de Éxito"
806
+
807
+ msgid "Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page."
808
+ msgstr "Donde los clientes serán redirigidos después de una compra exitosa. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
809
+
810
+ msgid "Failure URL"
811
+ msgstr "URL de Pago Rechazado"
812
+
813
+ msgid "Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page."
814
+ msgstr "Donde los clientes serán redirigidos después de una compra rechazada. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
815
+
816
+ msgid "Pending URL"
817
+ msgstr "URL de Pago Pendiente"
818
+
819
+ msgid "Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page."
820
+ msgstr "Donde los clientes ​serán redirigidos después de una compra pendiente. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
821
+
822
+ msgid "Stock Reduce"
823
+ msgstr "Reducir Inventario"
824
+
825
+ msgid "Reduce Stock in Order Generation"
826
+ msgstr "Reducir Inventario en la Orden"
827
+
828
+ msgid "Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval."
829
+ msgstr "Activar esta opción para reducir el inventario mediante la creación de un pedido. Desactivar para reducir sólo <strong>después</strong> de la aprobación del pago."
830
+
831
+ msgid "Recurrent Product"
832
+ msgstr "Producto Recurrente"
833
+
834
+ msgid "Frequency"
835
+ msgstr "Frecuencia"
836
+
837
+ msgid "Amount of time (in days or months) for the execution of the next payment."
838
+ msgstr "Cantidad de tiempo (en días o meses) para la ejecución del próximo pago."
839
+
840
+ msgid "Start date"
841
+ msgstr "Fecha de inicio"
842
+
843
+ msgid "First payment date (effective debit). Defaults to now if blank."
844
+ msgstr "Primera fecha de pago (débito efectivo). De forma predeterminada ahora, si está en blanco."
845
+
846
+ msgid "End date"
847
+ msgstr "Fecha final"
848
+
849
+ msgid "Deadline to generate new charges. Defaults to never if blank."
850
+ msgstr "Fecha límite para generar nuevos cargos. De forma predeterminada como nunca, si está en blanco."
851
+
852
+ msgid "Days"
853
+ msgstr "Días"
854
+
855
+ msgid "Months"
856
+ msgstr "Meses"
857
+
858
+ msgid "Indicates the period of time."
859
+ msgstr "Indica el período de tiempo."
860
+
861
+ msgid "The amount to charge the payer each period. Should be informed including taxes and discounts."
862
+ msgstr "La cantidad para cobrar el pagador en cada período. Debe ser informada incluyendo impuestos y descuentos."
863
+
864
+ msgid "Amount charged"
865
+ msgstr "Cantidad de cobro"
866
+
867
+ msgid "Uruguay"
868
+ msgstr "Uruguay"
869
+
870
+ msgid "Frequency type"
871
+ msgstr "Tipo de frecuencia"
872
+
873
+ msgid "Transaction amount"
874
+ msgstr "Valor de la transacción"
875
+
876
+ msgid "A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders."
877
+ msgstr "Un producto recurrente es una suscripción que debe adquirirse por separado en su carrito. Por favor, hace los pedidos por separado."
878
+
879
+ msgid "Subscription"
880
+ msgstr "Suscripción"
881
+
882
+ msgid "Enable Subscription"
883
+ msgstr "Habilitar Suscripción"
884
+
885
+ msgid "Subscription is Inactive"
886
+ msgstr "La Suscripción está Inactiva"
887
+
888
+ msgid "Subscribe with Mercado Pago"
889
+ msgstr "Suscribirse con Mercado Pago"
890
+
891
+ msgid "For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:"
892
+ msgstr "Para esta solución, usted debe configurar su URL de IPN. Puede acceder a ella en su cuenta para su específico país en:"
893
+
894
+ msgid "Discount by Gateway"
895
+ msgstr "Descuento por Gateway"
896
+
897
+ msgid "Give a percentual discount for your customers if they use this payment gateway."
898
+ msgstr "Dé un descuento porcentual para sus clientes si utilizan este medio de pago."
899
+
900
+ msgid "This field should be an integer greater or equal 0 and smaller than 100."
901
+ msgstr "Este campo debe ser un número entero mayor o igual 0 y menor que 100."
902
+
903
+ msgid "Discount Of"
904
+ msgstr "Descuento de"
905
+
906
+ msgid "Mercado Pago Subscription"
907
+ msgstr "Suscripción Mercado Pago"
908
+
909
+ msgid "Payment ID:"
910
+ msgstr "ID de Pago:"
911
+
912
+ msgid "Amount:"
913
+ msgstr "Cantidad:"
914
+
915
+ msgid "This operation could not be completed."
916
+ msgstr "Esta operación no se puede completar."
917
+
918
+ msgid "Operation successfully completed."
919
+ msgstr "La operación se realizó con éxito."
920
+
921
+ msgid "Refund Payment"
922
+ msgstr "Reembolso de Pago"
923
+
924
+ msgid "Cancel Payment"
925
+ msgstr "Cancelar Pago"
926
+
927
+ msgid "Mercado Pago - Subscription"
928
+ msgstr "Mercado Pago - Suscripcións"
929
+
930
+ msgid "Mercado Envios is a shipping method available only for payments with Mercado Pago."
931
+ msgstr "Mercado Envios es un método de envío disponible sólo para los pagos con Mercado Pago."
932
+
933
+ msgid "Free Shipping"
934
+ msgstr "Envío Gratuito"
935
+
936
+ msgid "Day"
937
+ msgstr "Día"
938
+
939
+ msgid "Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module."
940
+ msgstr "Habilitar los dos métodos de envío de Mercado Envios (Express y Normal) para el correcto funcionamiento del módulo."
941
+
942
+ msgid "Mercado Envios"
943
+ msgstr "Mercado Envios"
944
+
945
+ msgid "This controls the title which the user sees during checkout."
946
+ msgstr "Controla el título que se muestra al cliente durante el pago."
947
+
948
+ msgid "Enable free shipping for this shipping method"
949
+ msgstr "Habilitar el envío gratuito para este método de envío"
950
+
951
+ msgid "Delivery Time"
952
+ msgstr "Tiempo de Entrega"
953
+
954
+ msgid "Show estimated delivery time"
955
+ msgstr "Mostrar el tiempo estimado de entrega"
956
+
957
+ msgid "Display the estimated delivery time in working days."
958
+ msgstr "Mostrar el tiempo estimado de entrega en días laborables."
959
+
960
+ msgid "Buyer initiates complaint and requested a refund."
961
+ msgstr "El comprador ha iniciado una discusión y pide un extorno."
962
+
963
+ msgid "In return to sender"
964
+ msgstr "Volviendo al remitente"
965
+
966
+ msgid "Missing recipient for delivery"
967
+ msgstr "Destinatario ausente para envío"
968
+
969
+ msgid "Delayed shipping"
970
+ msgstr "Envío retrasado"
971
+
972
+ msgid "Unsuccessful"
973
+ msgstr "Fracasado"
974
+
975
+ msgid "Tag printed"
976
+ msgstr "Etiqueta impresa"
977
+
978
+ msgid "Tag ready to print"
979
+ msgstr "Etiquetar lista para imprimir"
980
+
981
+ msgid "Tracking code:"
982
+ msgstr "Código de rastreamiento:"
983
+
984
+ msgid "Tag:"
985
+ msgstr "Etiqueta:"
986
+
987
+ msgid "Shipping is pending"
988
+ msgstr "Envío pendiente"
989
+
990
+ msgid "Tutorial"
991
+ msgstr "Tutorial"
992
+
993
+ msgid "Discount Of "
994
+ msgstr "Descuento De "
995
+
996
+ msgid "Make this product a subscription."
997
+ msgstr "Hacer deste producto una suscripción."
998
+
999
+ msgid "Order"
1000
+ msgstr "Pedido"
1001
+
1002
+ msgid "Mercado Envios Tracking ID"
1003
+ msgstr "Código de rastreamiento de Mercado Envíos"
1004
+
1005
+ msgid "Hello,"
1006
+ msgstr "Hola,"
1007
+
1008
+ msgid "Your order"
1009
+ msgstr "Su pedido"
1010
+
1011
+ msgid "made in"
1012
+ msgstr "hecho en"
1013
+
1014
+ msgid "used Mercado Envios as its shipment method."
1015
+ msgstr "utilizó el Mercado Envíos como su medio de envío."
1016
+
1017
+ msgid "You can track it with the following Tracking ID:"
1018
+ msgstr "Usted puedes rastrearlo con lo siguiente código de rastreamiento:"
1019
+
1020
+ msgid "Best regards."
1021
+ msgstr "Saludos."
1022
+
1023
+ msgid "SELECT..."
1024
+ msgstr "SELECCIONE..."
1025
+
1026
+ msgid "NAME"
1027
+ msgstr "NOMBRE"
1028
+
1029
+ msgid "SURNAME"
1030
+ msgstr "APELLIDO"
1031
+
1032
+ msgid "DOCUMENT"
1033
+ msgstr "DOCUMENTO"
1034
+
1035
+ msgid "ADDRESS"
1036
+ msgstr "DIRECCIÓN"
1037
+
1038
+ msgid "NUMBER"
1039
+ msgstr "NÚMERO"
1040
+
1041
+ msgid "CITY"
1042
+ msgstr "CIUDAD"
1043
+
1044
+ msgid "STATE"
1045
+ msgstr "ESTADO"
1046
+
1047
+ msgid "ZIP"
1048
+ msgstr "CÓDIGO POSTAL"
1049
+
1050
+ msgid "You must inform you NAME"
1051
+ msgstr "Obligatorio informar su NOMBRE"
1052
+
1053
+ msgid "You must inform your SURNAME"
1054
+ msgstr "Obligatorio informar su APELLIDO"
1055
+
1056
+ msgid "You must inform your DOCUMENT"
1057
+ msgstr "Obligatorio informar su DOCUMENTO"
1058
+
1059
+ msgid "You must inform your ADDRESS"
1060
+ msgstr "Obligatorio informar su DIRECCIÓN"
1061
+
1062
+ msgid "You must inform your ADDRESS NUMBER"
1063
+ msgstr "Obligatorio informar su NÚMERO"
1064
+
1065
+ msgid "You must inform your CITY"
1066
+ msgstr "Obligatorio informar su CIUDAD"
1067
+
1068
+ msgid "You must inform your STATE"
1069
+ msgstr "Obligatorio informar su ESTADO"
1070
+
1071
+ msgid "You must inform your ZIP"
1072
+ msgstr "Obligatorio informar su CÓDIGO POSTAL"
1073
+
1074
+ msgid "Your PHP version is OK."
1075
+ msgstr "Su versión de PHP está bien."
1076
+
1077
+ msgid "Your PHP version do not support this module. You have %s, minimal required is %s."
1078
+ msgstr "Su versión de PHP no soporta este módulo. Tienes %s, la mínima requerida es %s."
1079
+
1080
+ msgid "cURL is installed."
1081
+ msgstr "cURL está instalado."
1082
+
1083
+ msgid "cURL is not installed."
1084
+ msgstr "cURL no está instalado."
1085
+
1086
+ msgid "SSL is missing in your site."
1087
+ msgstr "Falta el SSL en su sitio."
1088
+
1089
+ msgid "Your site has SSL enabled."
1090
+ msgstr "Su sitio tiene SSL habilitado."
languages/woocommerce-mercadopago-module-es_PE.mo CHANGED
Binary file
languages/woocommerce-mercadopago-module-es_PE.po CHANGED
@@ -673,7 +673,7 @@ msgid "Please, select the ticket issuer of your preference."
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
- msgstr "Haga clic en el botón "PLACE ORDER". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
@@ -739,7 +739,7 @@ msgid "Discount Coupon"
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
- msgstr "MONEDA CONVERTIDA: "La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
@@ -747,8 +747,8 @@ msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
- msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio"
751
- msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago"
752
 
753
  msgid " is: "
754
  msgstr " es: "
@@ -772,4 +772,319 @@ msgid "Terms and Conditions of Use"
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
- msgstr "Pago convertido de"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
+ msgstr "Haga clic en el botón "Realizar el pedido". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
+ msgstr "MONEDA CONVERTIDA: La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
+ msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio."
751
+ msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago."
752
 
753
  msgid " is: "
754
  msgstr " es: "
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
+ msgstr "Pago convertido de"
776
+
777
+ msgid "Rate Us"
778
+ msgstr "Calificar"
779
+
780
+ msgid "Report Issue"
781
+ msgstr "Informar Problema"
782
+
783
+ msgid "Two Cards Mode"
784
+ msgstr "Modo de Dos Tarjetas"
785
+
786
+ msgid "Payments with Two Cards"
787
+ msgstr "Pagos con Dos Tarjetas"
788
+
789
+ msgid "Your customer will be able to use two different cards to pay the order."
790
+ msgstr "Su cliente será capaz de utilizar dos tarjetas diferentes para pagar el pedido."
791
+
792
+ msgid "Your Mercado Pago credentials Access Token appears to be misconfigured."
793
+ msgstr "La credencial Mercado Pago Access Token parece estar mal configurada."
794
+
795
+ msgid "Cancel Order"
796
+ msgstr "Cancelar la Compra"
797
+
798
+ msgid "Refund Order"
799
+ msgstr "Reembolso de Compra"
800
+
801
+ msgid "Back URL Options"
802
+ msgstr "Opciones de URL de Callback"
803
+
804
+ msgid "Sucess URL"
805
+ msgstr "URL de Éxito"
806
+
807
+ msgid "Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page."
808
+ msgstr "Donde los clientes serán redirigidos después de una compra exitosa. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
809
+
810
+ msgid "Failure URL"
811
+ msgstr "URL de Pago Rechazado"
812
+
813
+ msgid "Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page."
814
+ msgstr "Donde los clientes serán redirigidos después de una compra rechazada. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
815
+
816
+ msgid "Pending URL"
817
+ msgstr "URL de Pago Pendiente"
818
+
819
+ msgid "Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page."
820
+ msgstr "Donde los clientes ​serán redirigidos después de una compra pendiente. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
821
+
822
+ msgid "Stock Reduce"
823
+ msgstr "Reducir Inventario"
824
+
825
+ msgid "Reduce Stock in Order Generation"
826
+ msgstr "Reducir Inventario en la Orden"
827
+
828
+ msgid "Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval."
829
+ msgstr "Activar esta opción para reducir el inventario mediante la creación de un pedido. Desactivar para reducir sólo <strong>después</strong> de la aprobación del pago."
830
+
831
+ msgid "Recurrent Product"
832
+ msgstr "Producto Recurrente"
833
+
834
+ msgid "Frequency"
835
+ msgstr "Frecuencia"
836
+
837
+ msgid "Amount of time (in days or months) for the execution of the next payment."
838
+ msgstr "Cantidad de tiempo (en días o meses) para la ejecución del próximo pago."
839
+
840
+ msgid "Start date"
841
+ msgstr "Fecha de inicio"
842
+
843
+ msgid "First payment date (effective debit). Defaults to now if blank."
844
+ msgstr "Primera fecha de pago (débito efectivo). De forma predeterminada ahora, si está en blanco."
845
+
846
+ msgid "End date"
847
+ msgstr "Fecha final"
848
+
849
+ msgid "Deadline to generate new charges. Defaults to never if blank."
850
+ msgstr "Fecha límite para generar nuevos cargos. De forma predeterminada como nunca, si está en blanco."
851
+
852
+ msgid "Days"
853
+ msgstr "Días"
854
+
855
+ msgid "Months"
856
+ msgstr "Meses"
857
+
858
+ msgid "Indicates the period of time."
859
+ msgstr "Indica el período de tiempo."
860
+
861
+ msgid "The amount to charge the payer each period. Should be informed including taxes and discounts."
862
+ msgstr "La cantidad para cobrar el pagador en cada período. Debe ser informada incluyendo impuestos y descuentos."
863
+
864
+ msgid "Amount charged"
865
+ msgstr "Cantidad de cobro"
866
+
867
+ msgid "Uruguay"
868
+ msgstr "Uruguay"
869
+
870
+ msgid "Frequency type"
871
+ msgstr "Tipo de frecuencia"
872
+
873
+ msgid "Transaction amount"
874
+ msgstr "Valor de la transacción"
875
+
876
+ msgid "A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders."
877
+ msgstr "Un producto recurrente es una suscripción que debe adquirirse por separado en su carrito. Por favor, hace los pedidos por separado."
878
+
879
+ msgid "Subscription"
880
+ msgstr "Suscripción"
881
+
882
+ msgid "Enable Subscription"
883
+ msgstr "Habilitar Suscripción"
884
+
885
+ msgid "Subscription is Inactive"
886
+ msgstr "La Suscripción está Inactiva"
887
+
888
+ msgid "Subscribe with Mercado Pago"
889
+ msgstr "Suscribirse con Mercado Pago"
890
+
891
+ msgid "For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:"
892
+ msgstr "Para esta solución, usted debe configurar su URL de IPN. Puede acceder a ella en su cuenta para su específico país en:"
893
+
894
+ msgid "Discount by Gateway"
895
+ msgstr "Descuento por Gateway"
896
+
897
+ msgid "Give a percentual discount for your customers if they use this payment gateway."
898
+ msgstr "Dé un descuento porcentual para sus clientes si utilizan este medio de pago."
899
+
900
+ msgid "This field should be an integer greater or equal 0 and smaller than 100."
901
+ msgstr "Este campo debe ser un número entero mayor o igual 0 y menor que 100."
902
+
903
+ msgid "Discount Of"
904
+ msgstr "Descuento de"
905
+
906
+ msgid "Mercado Pago Subscription"
907
+ msgstr "Suscripción Mercado Pago"
908
+
909
+ msgid "Payment ID:"
910
+ msgstr "ID de Pago:"
911
+
912
+ msgid "Amount:"
913
+ msgstr "Cantidad:"
914
+
915
+ msgid "This operation could not be completed."
916
+ msgstr "Esta operación no se puede completar."
917
+
918
+ msgid "Operation successfully completed."
919
+ msgstr "La operación se realizó con éxito."
920
+
921
+ msgid "Refund Payment"
922
+ msgstr "Reembolso de Pago"
923
+
924
+ msgid "Cancel Payment"
925
+ msgstr "Cancelar Pago"
926
+
927
+ msgid "Mercado Pago - Subscription"
928
+ msgstr "Mercado Pago - Suscripcións"
929
+
930
+ msgid "Mercado Envios is a shipping method available only for payments with Mercado Pago."
931
+ msgstr "Mercado Envios es un método de envío disponible sólo para los pagos con Mercado Pago."
932
+
933
+ msgid "Free Shipping"
934
+ msgstr "Envío Gratuito"
935
+
936
+ msgid "Day"
937
+ msgstr "Día"
938
+
939
+ msgid "Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module."
940
+ msgstr "Habilitar los dos métodos de envío de Mercado Envios (Express y Normal) para el correcto funcionamiento del módulo."
941
+
942
+ msgid "Mercado Envios"
943
+ msgstr "Mercado Envios"
944
+
945
+ msgid "This controls the title which the user sees during checkout."
946
+ msgstr "Controla el título que se muestra al cliente durante el pago."
947
+
948
+ msgid "Enable free shipping for this shipping method"
949
+ msgstr "Habilitar el envío gratuito para este método de envío"
950
+
951
+ msgid "Delivery Time"
952
+ msgstr "Tiempo de Entrega"
953
+
954
+ msgid "Show estimated delivery time"
955
+ msgstr "Mostrar el tiempo estimado de entrega"
956
+
957
+ msgid "Display the estimated delivery time in working days."
958
+ msgstr "Mostrar el tiempo estimado de entrega en días laborables."
959
+
960
+ msgid "Buyer initiates complaint and requested a refund."
961
+ msgstr "El comprador ha iniciado una discusión y pide un extorno."
962
+
963
+ msgid "In return to sender"
964
+ msgstr "Volviendo al remitente"
965
+
966
+ msgid "Missing recipient for delivery"
967
+ msgstr "Destinatario ausente para envío"
968
+
969
+ msgid "Delayed shipping"
970
+ msgstr "Envío retrasado"
971
+
972
+ msgid "Unsuccessful"
973
+ msgstr "Fracasado"
974
+
975
+ msgid "Tag printed"
976
+ msgstr "Etiqueta impresa"
977
+
978
+ msgid "Tag ready to print"
979
+ msgstr "Etiquetar lista para imprimir"
980
+
981
+ msgid "Tracking code:"
982
+ msgstr "Código de rastreamiento:"
983
+
984
+ msgid "Tag:"
985
+ msgstr "Etiqueta:"
986
+
987
+ msgid "Shipping is pending"
988
+ msgstr "Envío pendiente"
989
+
990
+ msgid "Tutorial"
991
+ msgstr "Tutorial"
992
+
993
+ msgid "Discount Of "
994
+ msgstr "Descuento De "
995
+
996
+ msgid "Make this product a subscription."
997
+ msgstr "Hacer deste producto una suscripción."
998
+
999
+ msgid "Order"
1000
+ msgstr "Pedido"
1001
+
1002
+ msgid "Mercado Envios Tracking ID"
1003
+ msgstr "Código de rastreamiento de Mercado Envíos"
1004
+
1005
+ msgid "Hello,"
1006
+ msgstr "Hola,"
1007
+
1008
+ msgid "Your order"
1009
+ msgstr "Su pedido"
1010
+
1011
+ msgid "made in"
1012
+ msgstr "hecho en"
1013
+
1014
+ msgid "used Mercado Envios as its shipment method."
1015
+ msgstr "utilizó el Mercado Envíos como su medio de envío."
1016
+
1017
+ msgid "You can track it with the following Tracking ID:"
1018
+ msgstr "Usted puedes rastrearlo con lo siguiente código de rastreamiento:"
1019
+
1020
+ msgid "Best regards."
1021
+ msgstr "Saludos."
1022
+
1023
+ msgid "SELECT..."
1024
+ msgstr "SELECCIONE..."
1025
+
1026
+ msgid "NAME"
1027
+ msgstr "NOMBRE"
1028
+
1029
+ msgid "SURNAME"
1030
+ msgstr "APELLIDO"
1031
+
1032
+ msgid "DOCUMENT"
1033
+ msgstr "DOCUMENTO"
1034
+
1035
+ msgid "ADDRESS"
1036
+ msgstr "DIRECCIÓN"
1037
+
1038
+ msgid "NUMBER"
1039
+ msgstr "NÚMERO"
1040
+
1041
+ msgid "CITY"
1042
+ msgstr "CIUDAD"
1043
+
1044
+ msgid "STATE"
1045
+ msgstr "ESTADO"
1046
+
1047
+ msgid "ZIP"
1048
+ msgstr "CÓDIGO POSTAL"
1049
+
1050
+ msgid "You must inform you NAME"
1051
+ msgstr "Obligatorio informar su NOMBRE"
1052
+
1053
+ msgid "You must inform your SURNAME"
1054
+ msgstr "Obligatorio informar su APELLIDO"
1055
+
1056
+ msgid "You must inform your DOCUMENT"
1057
+ msgstr "Obligatorio informar su DOCUMENTO"
1058
+
1059
+ msgid "You must inform your ADDRESS"
1060
+ msgstr "Obligatorio informar su DIRECCIÓN"
1061
+
1062
+ msgid "You must inform your ADDRESS NUMBER"
1063
+ msgstr "Obligatorio informar su NÚMERO"
1064
+
1065
+ msgid "You must inform your CITY"
1066
+ msgstr "Obligatorio informar su CIUDAD"
1067
+
1068
+ msgid "You must inform your STATE"
1069
+ msgstr "Obligatorio informar su ESTADO"
1070
+
1071
+ msgid "You must inform your ZIP"
1072
+ msgstr "Obligatorio informar su CÓDIGO POSTAL"
1073
+
1074
+ msgid "Your PHP version is OK."
1075
+ msgstr "Su versión de PHP está bien."
1076
+
1077
+ msgid "Your PHP version do not support this module. You have %s, minimal required is %s."
1078
+ msgstr "Su versión de PHP no soporta este módulo. Tienes %s, la mínima requerida es %s."
1079
+
1080
+ msgid "cURL is installed."
1081
+ msgstr "cURL está instalado."
1082
+
1083
+ msgid "cURL is not installed."
1084
+ msgstr "cURL no está instalado."
1085
+
1086
+ msgid "SSL is missing in your site."
1087
+ msgstr "Falta el SSL en su sitio."
1088
+
1089
+ msgid "Your site has SSL enabled."
1090
+ msgstr "Su sitio tiene SSL habilitado."
languages/woocommerce-mercadopago-module-es_UY.mo ADDED
Binary file
languages/woocommerce-mercadopago-module-es_UY.po ADDED
@@ -0,0 +1,1090 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # WordPress Blank Pot
2
+ # Copyright (C) 2014 ...
3
+ # This file is distributed under the GNU General Public License v2 or later.
4
+ msgid ""
5
+ msgstr ""
6
+ "Project-Id-Version: WordPress Blank Pot v1.0.0\n"
7
+ "POT-Creation-Date: 2016-05-23 14:52-0300\n"
8
+ "PO-Revision-Date: \n"
9
+ "Language-Team: Product Development <translations@example.com>\n"
10
+ "Report-Msgid-Bugs-To: Translator Name <translations@example.com>\n"
11
+ "MIME-Version: 1.0\n"
12
+ "Content-Type: text/plain; charset=UTF-8\n"
13
+ "Content-Transfer-Encoding: 8bit\n"
14
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "X-Textdomain-Support: yesX-Generator: Poedit 1.6.4\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "X-Poedit-KeywordsList: __;_e;esc_html_e;esc_html_x:1,2c;esc_html__;esc_attr_e;esc_attr_x:1,2c;esc_attr__;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;_x:1,2c;_n:1,2;"
18
+ "_n_noop:1,2;__ngettext:1,2;__ngettext_noop:1,2;_c,_nc:4c,1,2\n"
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_UY\n"
23
+ "X-Poedit-SearchPath-0: .\n"
24
+
25
+ #. Description of the plugin/theme
26
+ 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."
27
+ msgstr "Este es el módulo <strong>oficial</strong> de Mercado Pago para el plugin WooCommerce. Este módulo habilita el uso de Mercado Pago en WooCommerce como medio de pago para compras realizadas en su tienda virtual."
28
+
29
+ #: mercadopago-module.php:69
30
+ #, php-format
31
+ msgid "Woo Mercado Pago Module depends on the last version of %s to execute!"
32
+ msgstr "Woo Mercado Pago Module depende de la última versión de %s para ejecutarse!"
33
+
34
+ #: mercadopago-module.php:109
35
+ msgid "Basic Checkout"
36
+ msgstr "Checkout Básico"
37
+
38
+ #: mercadopago-module.php:113
39
+ msgid "Custom Checkout"
40
+ msgstr "Checkout Personalizado"
41
+
42
+ #: mercadopago/mercadopago-custom-gateway.php:48
43
+ msgid "Mercado Pago - Custom Checkout"
44
+ msgstr "Mercado Pago - Checkout Personalizado"
45
+
46
+ #: mercadopago/mercadopago-custom-gateway.php:51 mercadopago/mercadopago-gateway.php:54
47
+ msgid "This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store."
48
+ msgstr "Este módulo habilita el uso de Mercado Pago en WooCommerce como medio de pago para compras realizadas en su tienda virtual."
49
+
50
+ #: mercadopago/mercadopago-custom-gateway.php:126 mercadopago/mercadopago-custom-gateway.php:791 mercadopago/mercadopago-gateway.php:125
51
+ #: mercadopago/mercadopago-gateway.php:716
52
+ msgid "Argentine"
53
+ msgstr "Argentina"
54
+
55
+ #: mercadopago/mercadopago-custom-gateway.php:127 mercadopago/mercadopago-custom-gateway.php:792 mercadopago/mercadopago-gateway.php:126
56
+ #: mercadopago/mercadopago-gateway.php:717
57
+ msgid "Brazil"
58
+ msgstr "Brasil"
59
+
60
+ #: mercadopago/mercadopago-custom-gateway.php:128 mercadopago/mercadopago-custom-gateway.php:794 mercadopago/mercadopago-gateway.php:127
61
+ #: mercadopago/mercadopago-gateway.php:719
62
+ msgid "Chile"
63
+ msgstr "Chile"
64
+
65
+ #: mercadopago/mercadopago-custom-gateway.php:129 mercadopago/mercadopago-custom-gateway.php:793 mercadopago/mercadopago-gateway.php:128
66
+ #: mercadopago/mercadopago-gateway.php:718
67
+ msgid "Colombia"
68
+ msgstr "Colombia"
69
+
70
+ #: mercadopago/mercadopago-custom-gateway.php:130 mercadopago/mercadopago-custom-gateway.php:795 mercadopago/mercadopago-gateway.php:129
71
+ #: mercadopago/mercadopago-gateway.php:720
72
+ msgid "Mexico"
73
+ msgstr "México"
74
+
75
+ #: mercadopago/mercadopago-custom-gateway.php:132 mercadopago/mercadopago-gateway.php:130
76
+ msgid "or"
77
+ msgstr "o"
78
+
79
+ #: mercadopago/mercadopago-custom-gateway.php:133 mercadopago/mercadopago-custom-gateway.php:796 mercadopago/mercadopago-gateway.php:131
80
+ #: mercadopago/mercadopago-gateway.php:721
81
+ msgid "Venezuela"
82
+ msgstr "Venezuela"
83
+
84
+ #: mercadopago/mercadopago-custom-gateway.php:145 mercadopago/mercadopago-gateway.php:151
85
+ msgid "Your credentials are <strong>valid</strong> for"
86
+ msgstr "Sus credenciales <strong>son válidas</strong> para"
87
+
88
+ #: mercadopago/mercadopago-custom-gateway.php:151 mercadopago/mercadopago-custom-gateway.php:156 mercadopago/mercadopago-gateway.php:161
89
+ #: mercadopago/mercadopago-gateway.php:170
90
+ msgid "Your credentials are <strong>not valid</strong>!"
91
+ msgstr "Sus credenciales <strong>no son válidas</strong>!"
92
+
93
+ #: mercadopago/mercadopago-custom-gateway.php:169 mercadopago/mercadopago-gateway.php:211
94
+ msgid "Enable/Disable"
95
+ msgstr "Habilitar/Deshabilitar"
96
+
97
+ #: mercadopago/mercadopago-custom-gateway.php:171
98
+ msgid "Enable Custom Checkout"
99
+ msgstr "Habilitar Checkout Personalizado"
100
+
101
+ #: mercadopago/mercadopago-custom-gateway.php:175 mercadopago/mercadopago-gateway.php:217
102
+ msgid "Mercado Pago Credentials"
103
+ msgstr "Credenciales de Mercado Pago"
104
+
105
+ #: mercadopago/mercadopago-custom-gateway.php:177 mercadopago/mercadopago-gateway.php:219
106
+ msgid "You can obtain your credentials for"
107
+ msgstr "Puedes obtener tus credenciales para"
108
+
109
+ #: mercadopago/mercadopago-custom-gateway.php:182
110
+ msgid "Insert your Mercado Pago Public key."
111
+ msgstr "Inserte su Public Key de Mercado Pago."
112
+
113
+ #: mercadopago/mercadopago-custom-gateway.php:189
114
+ msgid "Insert your Mercado Pago Access token."
115
+ msgstr "Inserte su Access Token de Mercado Pago."
116
+
117
+ #: mercadopago/mercadopago-custom-gateway.php:194 mercadopago/mercadopago-gateway.php:236
118
+ msgid "Instant Payment Notification (IPN) URL"
119
+ msgstr "URL da Notificación Instantanea de Pago (IPN)"
120
+
121
+ #: mercadopago/mercadopago-custom-gateway.php:196 mercadopago/mercadopago-gateway.php:238
122
+ msgid "Your IPN URL to receive instant payment notifications is"
123
+ msgstr "Su URL de IPN para recibir notificaciones instantáneas de pago es"
124
+
125
+ #: mercadopago/mercadopago-custom-gateway.php:199 mercadopago/mercadopago-gateway.php:241
126
+ msgid "Checkout Options"
127
+ msgstr "Opciones de Checkout"
128
+
129
+ #: mercadopago/mercadopago-custom-gateway.php:204 mercadopago/mercadopago-gateway.php:246
130
+ msgid "Title"
131
+ msgstr "Título"
132
+
133
+ #: mercadopago/mercadopago-custom-gateway.php:206 mercadopago/mercadopago-gateway.php:248
134
+ msgid "Title shown to the client in the checkout."
135
+ msgstr "Título mostrado al cliente en el checkout."
136
+
137
+ #: mercadopago/mercadopago-custom-gateway.php:207 mercadopago/mercadopago-custom-gateway.php:219 mercadopago/mercadopago-gateway.php:249
138
+ msgid "Mercado Pago"
139
+ msgstr "Mercado Pago"
140
+
141
+ #: mercadopago/mercadopago-custom-gateway.php:210 mercadopago/mercadopago-gateway.php:252
142
+ msgid "Description"
143
+ msgstr "Descripción"
144
+
145
+ #: mercadopago/mercadopago-custom-gateway.php:212 mercadopago/mercadopago-gateway.php:254
146
+ msgid "Description shown to the client in the checkout."
147
+ msgstr "Descripción mostrada al cliente en el checkout."
148
+
149
+ #: mercadopago/mercadopago-custom-gateway.php:213 mercadopago/mercadopago-gateway.php:255 mercadopago/mercadopago-gateway.php:432
150
+ msgid "Pay with Mercado Pago"
151
+ msgstr "Pagar con Mercado Pago"
152
+
153
+ #: mercadopago/mercadopago-custom-gateway.php:216
154
+ msgid "Statement Descriptor"
155
+ msgstr "Descripción de la Factura"
156
+
157
+ #: mercadopago/mercadopago-custom-gateway.php:218
158
+ msgid "The description that will be shown in your customer's invoice."
159
+ msgstr "La descripción que se muestra en la factura de su cliente."
160
+
161
+ #: mercadopago/mercadopago-custom-gateway.php:222
162
+ msgid "Binary Mode"
163
+ msgstr "Modo binario"
164
+
165
+ #: mercadopago/mercadopago-custom-gateway.php:224
166
+ msgid "Enable binary mode for checkout status"
167
+ msgstr "Activar el modo binario para el estado del checkout"
168
+
169
+ #: mercadopago/mercadopago-custom-gateway.php:226
170
+ msgid "When charging a credit card, only [approved] or [reject] status will be taken."
171
+ msgstr "Al cargar una tarjeta de crédito, sólo los estados [aprobado] o [rechazar] seran tomados."
172
+
173
+ #: mercadopago/mercadopago-custom-gateway.php:229
174
+ msgid "Ticket"
175
+ msgstr "Ticket"
176
+
177
+ #: mercadopago/mercadopago-custom-gateway.php:231
178
+ msgid "Enable Ticket for Custom Checkout"
179
+ msgstr "Habilitar Ticket para Checkout Personalizado"
180
+
181
+ #: mercadopago/mercadopago-custom-gateway.php:233
182
+ msgid "Let your customer pay you with tickets"
183
+ msgstr "Deje que su cliente le paga con tickets"
184
+
185
+ #: mercadopago/mercadopago-custom-gateway.php:236 mercadopago/mercadopago-gateway.php:258
186
+ msgid "Store Category"
187
+ msgstr "Categoría de la tienda"
188
+
189
+ #: mercadopago/mercadopago-custom-gateway.php:238 mercadopago/mercadopago-gateway.php:260
190
+ msgid "Define which type of products your store sells."
191
+ msgstr "Defina el tipo de productos que su tienda vende."
192
+
193
+ #: mercadopago/mercadopago-custom-gateway.php:242 mercadopago/mercadopago-gateway.php:264
194
+ msgid "Store Identificator"
195
+ msgstr "Identificador de la tienda"
196
+
197
+ #: mercadopago/mercadopago-custom-gateway.php:244 mercadopago/mercadopago-gateway.php:266
198
+ msgid "Please, inform a prefix to your store."
199
+ msgstr "Por favor, informe un prefijo para su tienda."
200
+
201
+ #: mercadopago/mercadopago-custom-gateway.php:244 mercadopago/mercadopago-gateway.php:266
202
+ msgid ""
203
+ "If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same "
204
+ "identificators."
205
+ msgstr ""
206
+ "Si esta utilizando su cuenta Mercado Pago para múltiples tiendas, asegúrese que este prefijo sea único para no generar pedidos con el mismo identificador."
207
+
208
+ #: mercadopago/mercadopago-custom-gateway.php:248 mercadopago/mercadopago-gateway.php:318
209
+ msgid "Test and Debug Options"
210
+ msgstr "Opciones de Prueba y Debug"
211
+
212
+ #: mercadopago/mercadopago-custom-gateway.php:253 mercadopago/mercadopago-gateway.php:323
213
+ msgid "Mercado Pago Sandbox"
214
+ msgstr "Sandbox Mercado Pago"
215
+
216
+ #: mercadopago/mercadopago-custom-gateway.php:255 mercadopago/mercadopago-gateway.php:325
217
+ msgid "Enable Mercado Pago Sandbox"
218
+ msgstr "Habilitar el sandbox de Mercado Pago"
219
+
220
+ #: mercadopago/mercadopago-custom-gateway.php:257 mercadopago/mercadopago-gateway.php:327
221
+ msgid "This option allows you to test payments inside a sandbox environment."
222
+ msgstr "Esta opción permite simular un flujo de pagos completo en nuestro entorno Sandbox."
223
+
224
+ #: mercadopago/mercadopago-custom-gateway.php:260 mercadopago/mercadopago-gateway.php:330
225
+ msgid "Debug and Log"
226
+ msgstr "Debug y Log"
227
+
228
+ #: mercadopago/mercadopago-custom-gateway.php:262 mercadopago/mercadopago-gateway.php:332
229
+ msgid "Enable log"
230
+ msgstr "Habilitar Log"
231
+
232
+ #: mercadopago/mercadopago-custom-gateway.php:264 mercadopago/mercadopago-gateway.php:334
233
+ msgid "Register event logs of Mercado Pago, such as API requests, in the file"
234
+ msgstr "Registrar logs de eventos de Mercado Pago, como llamadas a la API, dentro del archivo"
235
+
236
+ #: mercadopago/mercadopago-custom-gateway.php:265 mercadopago/mercadopago-gateway.php:335
237
+ msgid "File location: "
238
+ msgstr "Local del archivo: "
239
+
240
+ #: mercadopago/mercadopago-custom-gateway.php:281 mercadopago/mercadopago-gateway.php:351
241
+ #, php-format
242
+ msgid "Please, rate us %s on WordPress.org and give your feedback to help improve this module!"
243
+ msgstr "Por favor, califíquenos con %s en WordPress.org y de su feedback para ayudar a mejorar este módulo!"
244
+
245
+ #: mercadopago/mercadopago-custom-gateway.php:332
246
+ msgid "Payment Method"
247
+ msgstr "Medios de Pago"
248
+
249
+ #: mercadopago/mercadopago-custom-gateway.php:333
250
+ msgid "Credit card number"
251
+ msgstr "Número de tarjeta de crédito"
252
+
253
+ #: mercadopago/mercadopago-custom-gateway.php:334
254
+ msgid "Expiration month"
255
+ msgstr "Mes de expiración"
256
+
257
+ #: mercadopago/mercadopago-custom-gateway.php:335
258
+ msgid "Expiration year"
259
+ msgstr "Año de expiración"
260
+
261
+ #: mercadopago/mercadopago-custom-gateway.php:336
262
+ msgid "Year"
263
+ msgstr "Año"
264
+
265
+ #: mercadopago/mercadopago-custom-gateway.php:337
266
+ msgid "Month"
267
+ msgstr "Mes"
268
+
269
+ #: mercadopago/mercadopago-custom-gateway.php:338
270
+ msgid "Card holder name"
271
+ msgstr "Nombre del titular de la tarjeta"
272
+
273
+ #: mercadopago/mercadopago-custom-gateway.php:339
274
+ msgid "Security code"
275
+ msgstr "Código de seguridad"
276
+
277
+ #: mercadopago/mercadopago-custom-gateway.php:340
278
+ msgid "Document Type"
279
+ msgstr "Tipo de Documento"
280
+
281
+ #: mercadopago/mercadopago-custom-gateway.php:341
282
+ msgid "Document number"
283
+ msgstr "Número de Documento"
284
+
285
+ #: mercadopago/mercadopago-custom-gateway.php:342
286
+ msgid "Issuer"
287
+ msgstr "Emisor"
288
+
289
+ #: mercadopago/mercadopago-custom-gateway.php:343
290
+ msgid "Installments"
291
+ msgstr "Cuotas"
292
+
293
+ #: mercadopago/mercadopago-custom-gateway.php:347
294
+ msgid "Parameter cardNumber can not be null/empty"
295
+ msgstr "Parámetro [Número de tarjeta] no puede ser nulo/vacío"
296
+
297
+ #: mercadopago/mercadopago-custom-gateway.php:348
298
+ msgid "Invalid Card Number"
299
+ msgstr "Número de tarjeta inválido"
300
+
301
+ #: mercadopago/mercadopago-custom-gateway.php:350 mercadopago/mercadopago-custom-gateway.php:351 mercadopago/mercadopago-custom-gateway.php:352
302
+ #: mercadopago/mercadopago-custom-gateway.php:353
303
+ msgid "Invalid Expiration Date"
304
+ msgstr "Fecha de expiración inválida"
305
+
306
+ #: mercadopago/mercadopago-custom-gateway.php:355
307
+ msgid "Parameter cardholderName can not be null/empty"
308
+ msgstr "Parámetro [Nombre del titular] no puede ser nulo/vacío"
309
+
310
+ #: mercadopago/mercadopago-custom-gateway.php:356
311
+ msgid "Invalid Card Holder Name"
312
+ msgstr "Nombre del titular de la tarjeta inválido"
313
+
314
+ #: mercadopago/mercadopago-custom-gateway.php:358
315
+ msgid "Parameter securityCode can not be null/empty"
316
+ msgstr "Parámetro [Código de seguridad] no puede ser nulo/vacío"
317
+
318
+ #: mercadopago/mercadopago-custom-gateway.php:359
319
+ msgid "Invalid Security Code"
320
+ msgstr "Código de seguridad inválido"
321
+
322
+ #: mercadopago/mercadopago-custom-gateway.php:361
323
+ msgid "Parameter docType can not be null/empty"
324
+ msgstr "Parámetro [Tipo de Documento] no puede ser nulo/vacío"
325
+
326
+ #: mercadopago/mercadopago-custom-gateway.php:362
327
+ msgid "Invalid Document Type"
328
+ msgstr "Tipo de Documento inválido"
329
+
330
+ #: mercadopago/mercadopago-custom-gateway.php:364
331
+ msgid "Parameter docNumber can not be null/empty"
332
+ msgstr "Parámetro [Número del Documento] no puede ser nulo/vacío"
333
+
334
+ #: mercadopago/mercadopago-custom-gateway.php:365
335
+ msgid "Invalid Document Number"
336
+ msgstr "Número del Documento inválido"
337
+
338
+ #: mercadopago/mercadopago-custom-gateway.php:367
339
+ msgid "The parameter cardholder.document.subtype can not be null or empty"
340
+ msgstr "Parámetro [Subtipo del documento] no puede ser nulo/vacío"
341
+
342
+ #: mercadopago/mercadopago-custom-gateway.php:368
343
+ msgid "Invalid Document Sub Type"
344
+ msgstr "Subtipo del documento inválido"
345
+
346
+ #: mercadopago/mercadopago-custom-gateway.php:370
347
+ msgid "Parameter cardIssuerId can not be null/empty"
348
+ msgstr "Parámetro [Emisor] no puede ser nulo/vacío"
349
+
350
+ #: mercadopago/mercadopago-custom-gateway.php:402 mercadopago/mercadopago-custom-gateway.php:943 mercadopago/mercadopago-gateway.php:869
351
+ msgid "Payment approved."
352
+ msgstr "Pago aprobado."
353
+
354
+ #: mercadopago/mercadopago-custom-gateway.php:416 mercadopago/mercadopago-custom-gateway.php:805
355
+ msgid "Your payment is under review. In less than 1h, you should be notified by email."
356
+ msgstr "Su pago está en revisión. En menos de 1 hora, usted será notificado por correo electrónico."
357
+
358
+ #: mercadopago/mercadopago-custom-gateway.php:418
359
+ msgid "Check your order resume"
360
+ msgstr "Ver su hoja de pedido"
361
+
362
+ #: mercadopago/mercadopago-custom-gateway.php:431
363
+ msgid "Your payment was refused. You can try again."
364
+ msgstr "Su pago fue rechazado. Puede intentarlo de nuevo."
365
+
366
+ #: mercadopago/mercadopago-custom-gateway.php:435 mercadopago/mercadopago-custom-gateway.php:819 mercadopago/mercadopago-gateway.php:460
367
+ msgid "Click to try again"
368
+ msgstr "Haga clic para intentarlo de nuevo"
369
+
370
+ #: mercadopago/mercadopago-custom-gateway.php:455
371
+ msgid "A problem was occurred when processing your payment. Are you sure you have correctly filled all information in the checkout form?"
372
+ msgstr "Un problema se produjo al procesar su pago. ¿Esta seguro que ha rellenado correctamente toda la información en el formulario de checkout?"
373
+
374
+ #: mercadopago/mercadopago-custom-gateway.php:544
375
+ msgid "Shipping"
376
+ msgstr "Envío"
377
+
378
+ #: mercadopago/mercadopago-custom-gateway.php:545
379
+ msgid "Shipping service used by store"
380
+ msgstr "Servicio de envío utilizado por la tienda"
381
+
382
+ #: mercadopago/mercadopago-custom-gateway.php:721 mercadopago/mercadopago-gateway.php:649
383
+ msgid "WooCommerce &gt; System Status &gt; Logs"
384
+ msgstr "WooCommerce &gt; Estado del Sistema &gt; Logs"
385
+
386
+ #: mercadopago/mercadopago-custom-gateway.php:766 mercadopago/mercadopago-custom-gateway.php:779 mercadopago/mercadopago-gateway.php:694
387
+ #: mercadopago/mercadopago-gateway.php:705
388
+ msgid "Mercado Pago is Inactive"
389
+ msgstr "Mercado Pago Inactivo"
390
+
391
+ #: mercadopago/mercadopago-custom-gateway.php:769
392
+ msgid "Your Mercado Pago credentials Public Key/Access Token appears to be misconfigured."
393
+ msgstr "Sus credenciales Client_id/Client_secret de Mercado Pago parecen no estar debidamente configuradas."
394
+
395
+ #: mercadopago/mercadopago-custom-gateway.php:771 mercadopago/mercadopago-gateway.php:698
396
+ msgid "Click here and configure!"
397
+ msgstr "Haga click aquí y configure!"
398
+
399
+ #: mercadopago/mercadopago-custom-gateway.php:782 mercadopago/mercadopago-gateway.php:708
400
+ msgid "The currency"
401
+ msgstr "La moneda"
402
+
403
+ #: mercadopago/mercadopago-custom-gateway.php:783 mercadopago/mercadopago-gateway.php:708
404
+ msgid "is not supported. Supported currencies are: ARS, BRL, CLP, COP, MXN, PEN, VEF."
405
+ msgstr "no es soportada. Las monedas soportadas son: ARS, BRL, CLP, COP, MXN, PEN, VEF."
406
+
407
+ #: mercadopago/mercadopago-custom-gateway.php:797
408
+ msgid "Peru"
409
+ msgstr "Perú"
410
+
411
+ #: mercadopago/mercadopago-custom-gateway.php:809
412
+ msgid "Click to check your order"
413
+ msgstr "Haga clic para comprobar su pedido"
414
+
415
+ #: mercadopago/mercadopago-custom-gateway.php:814 mercadopago/mercadopago-gateway.php:457
416
+ msgid "An error occurred when proccessing your payment. Please try again or contact us for assistence."
417
+ msgstr "Se ha producido un error en el procesamiento de su pago. Por favor, inténtelo de nuevo o póngase en contacto con nosotros para Asistencia."
418
+
419
+ #: mercadopago/mercadopago-custom-gateway.php:816
420
+ msgid "Reason is: "
421
+ msgstr "La razón es:"
422
+
423
+ #: mercadopago/mercadopago-custom-gateway.php:849 mercadopago/mercadopago-gateway.php:748
424
+ msgid "Mercado Pago Request Failure"
425
+ msgstr "La solicitud de Mercado Pago ha fallado."
426
+
427
+ #: mercadopago/mercadopago-custom-gateway.php:918 mercadopago/mercadopago-gateway.php:822
428
+ msgid "Payer email"
429
+ msgstr "Email del comprador"
430
+
431
+ #: mercadopago/mercadopago-custom-gateway.php:926 mercadopago/mercadopago-gateway.php:829
432
+ msgid "Payment type"
433
+ msgstr "Medio de pago"
434
+
435
+ #: mercadopago/mercadopago-custom-gateway.php:934 mercadopago/mercadopago-gateway.php:841
436
+ msgid "Mercado Pago Payment ID"
437
+ msgstr "ID de pago de Mercado Pago"
438
+
439
+ #: mercadopago/mercadopago-custom-gateway.php:950 mercadopago/mercadopago-gateway.php:875
440
+ msgid "Customer haven't paid yet."
441
+ msgstr "El cliente todavía no efectuó el pago."
442
+
443
+ #: mercadopago/mercadopago-custom-gateway.php:957 mercadopago/mercadopago-gateway.php:881
444
+ msgid "Payment under review."
445
+ msgstr "El pago está pendiente de revisión."
446
+
447
+ #: mercadopago/mercadopago-custom-gateway.php:964 mercadopago/mercadopago-gateway.php:887
448
+ msgid "The payment was refused. The customer can try again."
449
+ msgstr "El pago fue rechazado. El cliente puede intentar nuevamente."
450
+
451
+ #: mercadopago/mercadopago-custom-gateway.php:971 mercadopago/mercadopago-gateway.php:893
452
+ msgid "The payment was refunded to the customer."
453
+ msgstr "El pago fue devuelto al cliente."
454
+
455
+ #: mercadopago/mercadopago-custom-gateway.php:978 mercadopago/mercadopago-gateway.php:899
456
+ msgid "The payment was cancelled."
457
+ msgstr "El pago fue cancelado."
458
+
459
+ #: mercadopago/mercadopago-custom-gateway.php:984 mercadopago/mercadopago-custom-gateway.php:990 mercadopago/mercadopago-gateway.php:904
460
+ #: mercadopago/mercadopago-gateway.php:909
461
+ msgid "The payment is under mediation or it was charged-back."
462
+ msgstr "El pago esta en mediación o la compra fue desconocida por el cliente."
463
+
464
+ #: mercadopago/mercadopago-gateway.php:51
465
+ msgid "Mercado Pago - Basic Checkout"
466
+ msgstr "Mercado Pago - Checkout Básico"
467
+
468
+ #: mercadopago/mercadopago-gateway.php:148
469
+ msgid "Select the payment methods that you <strong>don't</strong> want to receive with Mercado Pago."
470
+ msgstr "Selecione los medios de pago que <strong>no</strong> desea aceptar con Mercado Pago."
471
+
472
+ #: mercadopago/mercadopago-gateway.php:158 mercadopago/mercadopago-gateway.php:167
473
+ msgid "Configure your Client_id and Client_secret to have access to more options."
474
+ msgstr "Configure su Client_id y Client_secret para tener acceso a más opciones."
475
+
476
+ #: mercadopago/mercadopago-gateway.php:184 mercadopago/mercadopago-gateway.php:192 mercadopago/mercadopago-gateway.php:202
477
+ msgid "This field should be an integer."
478
+ msgstr "Este campo debe ser un número."
479
+
480
+ #: mercadopago/mercadopago-gateway.php:187
481
+ msgid "If your integration method is iFrame, please inform the payment iFrame width."
482
+ msgstr "Si su modo de apertura es iFrame, indique el ancho del iFrame."
483
+
484
+ #: mercadopago/mercadopago-gateway.php:195
485
+ msgid "If your integration method is iFrame, please inform the payment iFrame height."
486
+ msgstr "Si su modo de apertura es iFrame, indique el alto del iFrame."
487
+
488
+ #: mercadopago/mercadopago-gateway.php:205
489
+ msgid "Select the max number of installments for your customers."
490
+ msgstr "Seleccione el número máximo de cuotas disponibles para sus clientes."
491
+
492
+ #: mercadopago/mercadopago-gateway.php:213
493
+ msgid "Enable Basic Checkout"
494
+ msgstr "Habilitar el Checkout Básico"
495
+
496
+ #: mercadopago/mercadopago-gateway.php:224
497
+ msgid "Insert your Mercado Pago Client_id."
498
+ msgstr "Inserte su Client_id de Mercado Pago."
499
+
500
+ #: mercadopago/mercadopago-gateway.php:231
501
+ msgid "Insert your Mercado Pago Client_secret."
502
+ msgstr "Inserte su Client_secret de Mercado Pago."
503
+
504
+ #: mercadopago/mercadopago-gateway.php:270
505
+ msgid "Integration Method"
506
+ msgstr "Método de integración"
507
+
508
+ #: mercadopago/mercadopago-gateway.php:272
509
+ msgid ""
510
+ "Select how your clients should interact with Mercado Pago. Modal Window (inside your store), Redirect (Client is redirected to Mercado Pago), or iFrame (an "
511
+ "internal window is embedded to the page layout)."
512
+ msgstr ""
513
+ "Seleccione la forma en que sus clientes deben interactuar con Mercado Pago. Ventana Modal (Dentro de su tienda), Redireccionamiento (El cliente es "
514
+ "redireccionado a Mercado Pago), o iFrame (Ventana de pago incorporada a su página)."
515
+
516
+ #: mercadopago/mercadopago-gateway.php:275
517
+ msgid "iFrame"
518
+ msgstr "iFrame"
519
+
520
+ #: mercadopago/mercadopago-gateway.php:276
521
+ msgid "Modal Window"
522
+ msgstr "Ventana modal"
523
+
524
+ #: mercadopago/mercadopago-gateway.php:277
525
+ msgid "Redirect"
526
+ msgstr "Redireccionamiento"
527
+
528
+ #: mercadopago/mercadopago-gateway.php:281
529
+ msgid "iFrame Width"
530
+ msgstr "Ancho del iFrame"
531
+
532
+ #: mercadopago/mercadopago-gateway.php:287
533
+ msgid "iFrame Height"
534
+ msgstr "Alto del iFrame"
535
+
536
+ #: mercadopago/mercadopago-gateway.php:293
537
+ msgid "Auto Return"
538
+ msgstr "Redirección automática"
539
+
540
+ #: mercadopago/mercadopago-gateway.php:295
541
+ msgid "Automatic Return After Payment"
542
+ msgstr "Redirección Automática luego del pago"
543
+
544
+ #: mercadopago/mercadopago-gateway.php:297
545
+ msgid "After the payment, client is automatically redirected."
546
+ msgstr "Después del pago, el cliente será redireccionado automáticamente."
547
+
548
+ #: mercadopago/mercadopago-gateway.php:300
549
+ msgid "Payment Options"
550
+ msgstr "Opciones de Pago"
551
+
552
+ #: mercadopago/mercadopago-gateway.php:305
553
+ msgid "Max installments"
554
+ msgstr "Número máximo de cuotas"
555
+
556
+ #: mercadopago/mercadopago-gateway.php:311
557
+ msgid "Exclude Payment Methods"
558
+ msgstr "Excluir medios de pago"
559
+
560
+ #: mercadopago/mercadopago-gateway.php:428
561
+ msgid "Thank you for your order. Please, proceed with your payment clicking in the bellow button."
562
+ msgstr "Gracias por su compra. Por favor, prosiga a la página de pago haciendo click en el botón de abajo."
563
+
564
+ #: mercadopago/mercadopago-gateway.php:436
565
+ msgid "Cancel order &amp; Clear cart"
566
+ msgstr "Cancelar &amp; Limpiar carrito"
567
+
568
+ #: mercadopago/mercadopago-gateway.php:446
569
+ msgid "Thank you for your order. Proceed with your payment completing the following information."
570
+ msgstr "Gracias por su compra. Prosiga con su pago completando la información abajo."
571
+
572
+ #: mercadopago/mercadopago-gateway.php:697
573
+ msgid "Your Mercado Pago credentials Client_id/Client_secret appears to be misconfigured."
574
+ msgstr "Sus credenciales Client_id/Client_secret de Mercado Pago parecen no estar debidamente configuradas."
575
+
576
+ msgid " as it appears in your card ..."
577
+ msgstr " tal como aparece en su tarjeta ..."
578
+
579
+ msgid "Done, your payment was accredited!"
580
+ msgstr "Listo, su pago ha sido aceptado!"
581
+
582
+ msgid "We are processing the payment. In less than an hour we will e-mail you the results."
583
+ msgstr "Estamos procesando su pago. En menos de una hora le enviaremos el resultado por correo electrónico."
584
+
585
+ msgid "We are processing the payment. In less than 2 business days we will tell you by e-mail whether it has accredited or we need more information."
586
+ msgstr "Estamos procesando su pago. En menos de 2 días le enviaremos por correo electrónico si se ha aprobado el pago o si se necesita información adicional."
587
+
588
+ msgid "Check the card number."
589
+ msgstr "Compruebe el número de tarjeta."
590
+
591
+ msgid "Check the expiration date."
592
+ msgstr "Compruebe la fecha de expiración."
593
+
594
+ msgid "Check the information."
595
+ msgstr "Compruebe la información informada."
596
+
597
+ msgid "Check the security code."
598
+ msgstr "Compruebe el código de seguridad informado."
599
+
600
+ msgid "We could not process your payment."
601
+ msgstr "No se puede procesar su pago."
602
+
603
+ msgid "You must authorize the payment of your orders."
604
+ msgstr "Usted debe autorizar los pagos de sus órdenes."
605
+
606
+ msgid "Call your card issuer to activate your card. The phone is on the back of your card."
607
+ msgstr "Póngase en contacto con el emisor de su tarjeta para activarla. El teléfono se encuentra en la parte posterior de su tarjeta."
608
+
609
+ msgid "You already made a payment for that amount. If you need to repay, use another card or other payment method."
610
+ msgstr "Usted ya realizó un pago de este importe. Si tiene que pagar de nuevo, utilizar otra tarjeta u otro medio de pago."
611
+
612
+ msgid "Your payment was rejected. Choose another payment method. We recommend cash."
613
+ msgstr "Su pago fue rechazado. Por favor seleccione otro medio de pago. Se recomienda en efectivo."
614
+
615
+ msgid "Your payment do not have sufficient funds."
616
+ msgstr "Su pago no tiene fondos suficientes."
617
+
618
+ msgid "Your payment does not process payments with selected installments."
619
+ msgstr "El pago no puede procesar la cuota seleccionada."
620
+
621
+ msgid "You have reached the limit of allowed attempts. Choose another card or another payment method."
622
+ msgstr "Has alcanzado el límite de intentos permitidos. Elija otra tarjeta u otro medio de pago."
623
+
624
+ msgid "This payment method did not process the payment."
625
+ msgstr "Esta medio de pago no puede procesar su pago."
626
+
627
+ msgid "Mercado Pago - Ticket"
628
+ msgstr "Mercado Pago - Ticket"
629
+
630
+ msgid "Mercado Pago - Credit Card"
631
+ msgstr "Mercado Pago - Tarjeta de Crédito"
632
+
633
+ msgid "Ticket Options"
634
+ msgstr "Opciones de Ticket"
635
+
636
+ msgid "Enable Ticket Payment Method"
637
+ msgstr "Habilitar Pago con Ticket"
638
+
639
+ msgid "Other Bank"
640
+ msgstr "Otro Banco"
641
+
642
+ msgid "Choose"
643
+ msgstr "Escoger"
644
+
645
+ msgid "A problem was occurred when processing your payment. Please, try again."
646
+ msgstr "Un problema se produjo al procesar su pago. Por favor, inténtelo de nuevo."
647
+
648
+ msgid "Thank you for your order. Please, pay the ticket to get your order approved."
649
+ msgstr "Gracias por su orden. Por favor, realice el pago del ticket para tener su orden aprobada."
650
+
651
+ msgid "Waiting for the ticket payment."
652
+ msgstr "Esperando el pago del ticket."
653
+
654
+ msgid "Print the Ticket"
655
+ msgstr "Imprimir el ticket"
656
+
657
+ msgid "To reprint the ticket click "
658
+ msgstr "Para imprimir nuevamente el ticket hace clic "
659
+
660
+ msgid "here"
661
+ msgstr "aquí"
662
+
663
+ msgid "Custom Checkout is Inactive"
664
+ msgstr "Checkout Personalizado Inactivo"
665
+
666
+ msgid "Basic Checkout is Inactive"
667
+ msgstr "Checkout Básico Inactivo"
668
+
669
+ msgid "Ticket is Inactive"
670
+ msgstr "Ticket Inactivo"
671
+
672
+ msgid "Please, select the ticket issuer of your preference."
673
+ msgstr "Por favor, seleccione el emisor de su elección."
674
+
675
+ msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
+ msgstr "Haga clic en el botón "Realizar el pedido". El ticket será generado y usted será redirigido a imprimirlo."
677
+
678
+ msgid "Important: The order will be confirmed only after the payment approval."
679
+ msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
680
+
681
+ msgid "Your Mercado Pago credential Access Token appears to be misconfigured."
682
+ msgstr "Su credencial Access Token de Mercado de Pago parece estar desconfigurada."
683
+
684
+ msgid "Your Card"
685
+ msgstr "Sus Tarjetas"
686
+
687
+ msgid "Other Cards"
688
+ msgstr "Otras Tarjetas"
689
+
690
+ msgid "Other Card"
691
+ msgstr "Otra Tarjeta"
692
+
693
+ msgid "ended in"
694
+ msgstr "terminado en"
695
+
696
+ msgid "Your site appears to not have SSL certification. SSL is a pre-requisite because the payment process is made in your server."
697
+ msgstr "Su sitio parece no tener certificación SSL. SSL es un requisito para transaccionar desde su servidor."
698
+
699
+ msgid "ATTENTION: The currency"
700
+ msgstr "ATENCIÓN: La moneda"
701
+
702
+ msgid "defined in WooCommerce is different from the one used in your credentials country.<br>The currency for transactions in this payment method will be"
703
+ msgstr "que se define en WooCommerce es diferente de la utilizada en el país de sus credenciales.<br>La moneda para las transacciones realizadas por este medio de pago será"
704
+
705
+ msgid "Currency conversions should be made outside this module."
706
+ msgstr "Conversiones de monedas deben hacerse fuera de este módulo."
707
+
708
+ msgid "Coupons"
709
+ msgstr "Cupones"
710
+
711
+ msgid "Enable coupons of discounts"
712
+ msgstr "Activar los cupones de descuento"
713
+
714
+ msgid "If there is a Mercado Pago campaign, allow your store to give discounts to customers."
715
+ msgstr "Si hay una campaña de Mercado Pago, permitir a su tienda hacer descuentos para los clientes."
716
+
717
+ msgid "You will save"
718
+ msgstr "Usted ahorrará"
719
+
720
+ msgid "Apply"
721
+ msgstr "Aplicar"
722
+
723
+ msgid "Remove"
724
+ msgstr "Eliminar"
725
+
726
+ msgid "Please, inform your coupon code"
727
+ msgstr "Por favor, introduzca el código de su cupón"
728
+
729
+ msgid "Please, inform your email in billing address to use this feature"
730
+ msgstr "Por favor, introduzca su email en la dirección de facturación para utilizar este servicio"
731
+
732
+ msgid "Discount for %s coupon"
733
+ msgstr "Descuento para el cupón %s"
734
+
735
+ msgid "Discount provided by store"
736
+ msgstr "Descuento dado por la tienda"
737
+
738
+ msgid "Discount Coupon"
739
+ msgstr "Cupón de Descuento"
740
+
741
+ msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
+ msgstr "MONEDA CONVERTIDA: La tasa de conversión de moneda de"
743
+
744
+ msgid "ERROR: It was not possible to convert the unsupported currency"
745
+ msgstr "ERROR: No fue posible convertir la moneda no soportada"
746
+
747
+ msgid "to"
748
+ msgstr "para"
749
+
750
+ msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio."
751
+ msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago."
752
+
753
+ msgid " is: "
754
+ msgstr " es: "
755
+
756
+ msgid "Currency Conversion"
757
+ msgstr "Conversión de Moneda"
758
+
759
+ msgid "with discount from"
760
+ msgstr "con descuento de"
761
+
762
+ msgid "Total of your purchase:"
763
+ msgstr "Total de su compra:"
764
+
765
+ msgid "Total of your purchase with discount:"
766
+ msgstr "Total de su compra con descuento:"
767
+
768
+ msgid "*Uppon payment approval"
769
+ msgstr "*Con la aprobación de pago"
770
+
771
+ msgid "Terms and Conditions of Use"
772
+ msgstr "Términos y Condiciones de Uso"
773
+
774
+ msgid "Payment converted from"
775
+ msgstr "Pago convertido de"
776
+
777
+ msgid "Rate Us"
778
+ msgstr "Calificar"
779
+
780
+ msgid "Report Issue"
781
+ msgstr "Informar Problema"
782
+
783
+ msgid "Two Cards Mode"
784
+ msgstr "Modo de Dos Tarjetas"
785
+
786
+ msgid "Payments with Two Cards"
787
+ msgstr "Pagos con Dos Tarjetas"
788
+
789
+ msgid "Your customer will be able to use two different cards to pay the order."
790
+ msgstr "Su cliente será capaz de utilizar dos tarjetas diferentes para pagar el pedido."
791
+
792
+ msgid "Your Mercado Pago credentials Access Token appears to be misconfigured."
793
+ msgstr "La credencial Mercado Pago Access Token parece estar mal configurada."
794
+
795
+ msgid "Cancel Order"
796
+ msgstr "Cancelar la Compra"
797
+
798
+ msgid "Refund Order"
799
+ msgstr "Reembolso de Compra"
800
+
801
+ msgid "Back URL Options"
802
+ msgstr "Opciones de URL de Callback"
803
+
804
+ msgid "Sucess URL"
805
+ msgstr "URL de Éxito"
806
+
807
+ msgid "Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page."
808
+ msgstr "Donde los clientes serán redirigidos después de una compra exitosa. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
809
+
810
+ msgid "Failure URL"
811
+ msgstr "URL de Pago Rechazado"
812
+
813
+ msgid "Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page."
814
+ msgstr "Donde los clientes serán redirigidos después de una compra rechazada. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
815
+
816
+ msgid "Pending URL"
817
+ msgstr "URL de Pago Pendiente"
818
+
819
+ msgid "Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page."
820
+ msgstr "Donde los clientes ​serán redirigidos después de una compra pendiente. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
821
+
822
+ msgid "Stock Reduce"
823
+ msgstr "Reducir Inventario"
824
+
825
+ msgid "Reduce Stock in Order Generation"
826
+ msgstr "Reducir Inventario en la Orden"
827
+
828
+ msgid "Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval."
829
+ msgstr "Activar esta opción para reducir el inventario mediante la creación de un pedido. Desactivar para reducir sólo <strong>después</strong> de la aprobación del pago."
830
+
831
+ msgid "Recurrent Product"
832
+ msgstr "Producto Recurrente"
833
+
834
+ msgid "Frequency"
835
+ msgstr "Frecuencia"
836
+
837
+ msgid "Amount of time (in days or months) for the execution of the next payment."
838
+ msgstr "Cantidad de tiempo (en días o meses) para la ejecución del próximo pago."
839
+
840
+ msgid "Start date"
841
+ msgstr "Fecha de inicio"
842
+
843
+ msgid "First payment date (effective debit). Defaults to now if blank."
844
+ msgstr "Primera fecha de pago (débito efectivo). De forma predeterminada ahora, si está en blanco."
845
+
846
+ msgid "End date"
847
+ msgstr "Fecha final"
848
+
849
+ msgid "Deadline to generate new charges. Defaults to never if blank."
850
+ msgstr "Fecha límite para generar nuevos cargos. De forma predeterminada como nunca, si está en blanco."
851
+
852
+ msgid "Days"
853
+ msgstr "Días"
854
+
855
+ msgid "Months"
856
+ msgstr "Meses"
857
+
858
+ msgid "Indicates the period of time."
859
+ msgstr "Indica el período de tiempo."
860
+
861
+ msgid "The amount to charge the payer each period. Should be informed including taxes and discounts."
862
+ msgstr "La cantidad para cobrar el pagador en cada período. Debe ser informada incluyendo impuestos y descuentos."
863
+
864
+ msgid "Amount charged"
865
+ msgstr "Cantidad de cobro"
866
+
867
+ msgid "Uruguay"
868
+ msgstr "Uruguay"
869
+
870
+ msgid "Frequency type"
871
+ msgstr "Tipo de frecuencia"
872
+
873
+ msgid "Transaction amount"
874
+ msgstr "Valor de la transacción"
875
+
876
+ msgid "A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders."
877
+ msgstr "Un producto recurrente es una suscripción que debe adquirirse por separado en su carrito. Por favor, hace los pedidos por separado."
878
+
879
+ msgid "Subscription"
880
+ msgstr "Suscripción"
881
+
882
+ msgid "Enable Subscription"
883
+ msgstr "Habilitar Suscripción"
884
+
885
+ msgid "Subscription is Inactive"
886
+ msgstr "La Suscripción está Inactiva"
887
+
888
+ msgid "Subscribe with Mercado Pago"
889
+ msgstr "Suscribirse con Mercado Pago"
890
+
891
+ msgid "For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:"
892
+ msgstr "Para esta solución, usted debe configurar su URL de IPN. Puede acceder a ella en su cuenta para su específico país en:"
893
+
894
+ msgid "Discount by Gateway"
895
+ msgstr "Descuento por Gateway"
896
+
897
+ msgid "Give a percentual discount for your customers if they use this payment gateway."
898
+ msgstr "Dé un descuento porcentual para sus clientes si utilizan este medio de pago."
899
+
900
+ msgid "This field should be an integer greater or equal 0 and smaller than 100."
901
+ msgstr "Este campo debe ser un número entero mayor o igual 0 y menor que 100."
902
+
903
+ msgid "Discount Of"
904
+ msgstr "Descuento de"
905
+
906
+ msgid "Mercado Pago Subscription"
907
+ msgstr "Suscripción Mercado Pago"
908
+
909
+ msgid "Payment ID:"
910
+ msgstr "ID de Pago:"
911
+
912
+ msgid "Amount:"
913
+ msgstr "Cantidad:"
914
+
915
+ msgid "This operation could not be completed."
916
+ msgstr "Esta operación no se puede completar."
917
+
918
+ msgid "Operation successfully completed."
919
+ msgstr "La operación se realizó con éxito."
920
+
921
+ msgid "Refund Payment"
922
+ msgstr "Reembolso de Pago"
923
+
924
+ msgid "Cancel Payment"
925
+ msgstr "Cancelar Pago"
926
+
927
+ msgid "Mercado Pago - Subscription"
928
+ msgstr "Mercado Pago - Suscripcións"
929
+
930
+ msgid "Mercado Envios is a shipping method available only for payments with Mercado Pago."
931
+ msgstr "Mercado Envios es un método de envío disponible sólo para los pagos con Mercado Pago."
932
+
933
+ msgid "Free Shipping"
934
+ msgstr "Envío Gratuito"
935
+
936
+ msgid "Day"
937
+ msgstr "Día"
938
+
939
+ msgid "Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module."
940
+ msgstr "Habilitar los dos métodos de envío de Mercado Envios (Express y Normal) para el correcto funcionamiento del módulo."
941
+
942
+ msgid "Mercado Envios"
943
+ msgstr "Mercado Envios"
944
+
945
+ msgid "This controls the title which the user sees during checkout."
946
+ msgstr "Controla el título que se muestra al cliente durante el pago."
947
+
948
+ msgid "Enable free shipping for this shipping method"
949
+ msgstr "Habilitar el envío gratuito para este método de envío"
950
+
951
+ msgid "Delivery Time"
952
+ msgstr "Tiempo de Entrega"
953
+
954
+ msgid "Show estimated delivery time"
955
+ msgstr "Mostrar el tiempo estimado de entrega"
956
+
957
+ msgid "Display the estimated delivery time in working days."
958
+ msgstr "Mostrar el tiempo estimado de entrega en días laborables."
959
+
960
+ msgid "Buyer initiates complaint and requested a refund."
961
+ msgstr "El comprador ha iniciado una discusión y pide un extorno."
962
+
963
+ msgid "In return to sender"
964
+ msgstr "Volviendo al remitente"
965
+
966
+ msgid "Missing recipient for delivery"
967
+ msgstr "Destinatario ausente para envío"
968
+
969
+ msgid "Delayed shipping"
970
+ msgstr "Envío retrasado"
971
+
972
+ msgid "Unsuccessful"
973
+ msgstr "Fracasado"
974
+
975
+ msgid "Tag printed"
976
+ msgstr "Etiqueta impresa"
977
+
978
+ msgid "Tag ready to print"
979
+ msgstr "Etiquetar lista para imprimir"
980
+
981
+ msgid "Tracking code:"
982
+ msgstr "Código de rastreamiento:"
983
+
984
+ msgid "Tag:"
985
+ msgstr "Etiqueta:"
986
+
987
+ msgid "Shipping is pending"
988
+ msgstr "Envío pendiente"
989
+
990
+ msgid "Tutorial"
991
+ msgstr "Tutorial"
992
+
993
+ msgid "Discount Of "
994
+ msgstr "Descuento De "
995
+
996
+ msgid "Make this product a subscription."
997
+ msgstr "Hacer deste producto una suscripción."
998
+
999
+ msgid "Order"
1000
+ msgstr "Pedido"
1001
+
1002
+ msgid "Mercado Envios Tracking ID"
1003
+ msgstr "Código de rastreamiento de Mercado Envíos"
1004
+
1005
+ msgid "Hello,"
1006
+ msgstr "Hola,"
1007
+
1008
+ msgid "Your order"
1009
+ msgstr "Su pedido"
1010
+
1011
+ msgid "made in"
1012
+ msgstr "hecho en"
1013
+
1014
+ msgid "used Mercado Envios as its shipment method."
1015
+ msgstr "utilizó el Mercado Envíos como su medio de envío."
1016
+
1017
+ msgid "You can track it with the following Tracking ID:"
1018
+ msgstr "Usted puedes rastrearlo con lo siguiente código de rastreamiento:"
1019
+
1020
+ msgid "Best regards."
1021
+ msgstr "Saludos."
1022
+
1023
+ msgid "SELECT..."
1024
+ msgstr "SELECCIONE..."
1025
+
1026
+ msgid "NAME"
1027
+ msgstr "NOMBRE"
1028
+
1029
+ msgid "SURNAME"
1030
+ msgstr "APELLIDO"
1031
+
1032
+ msgid "DOCUMENT"
1033
+ msgstr "DOCUMENTO"
1034
+
1035
+ msgid "ADDRESS"
1036
+ msgstr "DIRECCIÓN"
1037
+
1038
+ msgid "NUMBER"
1039
+ msgstr "NÚMERO"
1040
+
1041
+ msgid "CITY"
1042
+ msgstr "CIUDAD"
1043
+
1044
+ msgid "STATE"
1045
+ msgstr "ESTADO"
1046
+
1047
+ msgid "ZIP"
1048
+ msgstr "CÓDIGO POSTAL"
1049
+
1050
+ msgid "You must inform you NAME"
1051
+ msgstr "Obligatorio informar su NOMBRE"
1052
+
1053
+ msgid "You must inform your SURNAME"
1054
+ msgstr "Obligatorio informar su APELLIDO"
1055
+
1056
+ msgid "You must inform your DOCUMENT"
1057
+ msgstr "Obligatorio informar su DOCUMENTO"
1058
+
1059
+ msgid "You must inform your ADDRESS"
1060
+ msgstr "Obligatorio informar su DIRECCIÓN"
1061
+
1062
+ msgid "You must inform your ADDRESS NUMBER"
1063
+ msgstr "Obligatorio informar su NÚMERO"
1064
+
1065
+ msgid "You must inform your CITY"
1066
+ msgstr "Obligatorio informar su CIUDAD"
1067
+
1068
+ msgid "You must inform your STATE"
1069
+ msgstr "Obligatorio informar su ESTADO"
1070
+
1071
+ msgid "You must inform your ZIP"
1072
+ msgstr "Obligatorio informar su CÓDIGO POSTAL"
1073
+
1074
+ msgid "Your PHP version is OK."
1075
+ msgstr "Su versión de PHP está bien."
1076
+
1077
+ msgid "Your PHP version do not support this module. You have %s, minimal required is %s."
1078
+ msgstr "Su versión de PHP no soporta este módulo. Tienes %s, la mínima requerida es %s."
1079
+
1080
+ msgid "cURL is installed."
1081
+ msgstr "cURL está instalado."
1082
+
1083
+ msgid "cURL is not installed."
1084
+ msgstr "cURL no está instalado."
1085
+
1086
+ msgid "SSL is missing in your site."
1087
+ msgstr "Falta el SSL en su sitio."
1088
+
1089
+ msgid "Your site has SSL enabled."
1090
+ msgstr "Su sitio tiene SSL habilitado."
languages/woocommerce-mercadopago-module-es_VE.mo CHANGED
Binary file
languages/woocommerce-mercadopago-module-es_VE.po CHANGED
@@ -673,7 +673,7 @@ msgid "Please, select the ticket issuer of your preference."
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
- msgstr "Haga clic en el botón "PLACE ORDER". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
@@ -739,7 +739,7 @@ msgid "Discount Coupon"
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
- msgstr "MONEDA CONVERTIDA: "La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
@@ -747,8 +747,8 @@ msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
- msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio"
751
- msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago"
752
 
753
  msgid " is: "
754
  msgstr " es: "
@@ -772,4 +772,319 @@ msgid "Terms and Conditions of Use"
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
- msgstr "Pago convertido de"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
  msgstr "Por favor, seleccione el emisor de su elección."
674
 
675
  msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
676
+ msgstr "Haga clic en el botón "Realizar el pedido". El ticket será generado y usted será redirigido a imprimirlo."
677
 
678
  msgid "Important: The order will be confirmed only after the payment approval."
679
  msgstr "Importante: La solicitud sólo será confirmada después de la aprobación del pago."
739
  msgstr "Cupón de Descuento"
740
 
741
  msgid "CURRENCY CONVERTED: The currency conversion ratio from"
742
+ msgstr "MONEDA CONVERTIDA: La tasa de conversión de moneda de"
743
 
744
  msgid "ERROR: It was not possible to convert the unsupported currency"
745
  msgstr "ERROR: No fue posible convertir la moneda no soportada"
747
  msgid "to"
748
  msgstr "para"
749
 
750
+ msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio."
751
+ msgstr "Si la moneda utilizada en WooCommerce es diferente o no soportada por Mercado Pago, convierte los importes de sus transacciones con la tasa de conversión de Mercado Pago."
752
 
753
  msgid " is: "
754
  msgstr " es: "
772
  msgstr "Términos y Condiciones de Uso"
773
 
774
  msgid "Payment converted from"
775
+ msgstr "Pago convertido de"
776
+
777
+ msgid "Rate Us"
778
+ msgstr "Calificar"
779
+
780
+ msgid "Report Issue"
781
+ msgstr "Informar Problema"
782
+
783
+ msgid "Two Cards Mode"
784
+ msgstr "Modo de Dos Tarjetas"
785
+
786
+ msgid "Payments with Two Cards"
787
+ msgstr "Pagos con Dos Tarjetas"
788
+
789
+ msgid "Your customer will be able to use two different cards to pay the order."
790
+ msgstr "Su cliente será capaz de utilizar dos tarjetas diferentes para pagar el pedido."
791
+
792
+ msgid "Your Mercado Pago credentials Access Token appears to be misconfigured."
793
+ msgstr "La credencial Mercado Pago Access Token parece estar mal configurada."
794
+
795
+ msgid "Cancel Order"
796
+ msgstr "Cancelar la Compra"
797
+
798
+ msgid "Refund Order"
799
+ msgstr "Reembolso de Compra"
800
+
801
+ msgid "Back URL Options"
802
+ msgstr "Opciones de URL de Callback"
803
+
804
+ msgid "Sucess URL"
805
+ msgstr "URL de Éxito"
806
+
807
+ msgid "Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page."
808
+ msgstr "Donde los clientes serán redirigidos después de una compra exitosa. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
809
+
810
+ msgid "Failure URL"
811
+ msgstr "URL de Pago Rechazado"
812
+
813
+ msgid "Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page."
814
+ msgstr "Donde los clientes serán redirigidos después de una compra rechazada. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
815
+
816
+ msgid "Pending URL"
817
+ msgstr "URL de Pago Pendiente"
818
+
819
+ msgid "Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page."
820
+ msgstr "Donde los clientes ​serán redirigidos después de una compra pendiente. Dejar en blanco para redirigir a la página estándar de resumen de compra en la tienda."
821
+
822
+ msgid "Stock Reduce"
823
+ msgstr "Reducir Inventario"
824
+
825
+ msgid "Reduce Stock in Order Generation"
826
+ msgstr "Reducir Inventario en la Orden"
827
+
828
+ msgid "Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval."
829
+ msgstr "Activar esta opción para reducir el inventario mediante la creación de un pedido. Desactivar para reducir sólo <strong>después</strong> de la aprobación del pago."
830
+
831
+ msgid "Recurrent Product"
832
+ msgstr "Producto Recurrente"
833
+
834
+ msgid "Frequency"
835
+ msgstr "Frecuencia"
836
+
837
+ msgid "Amount of time (in days or months) for the execution of the next payment."
838
+ msgstr "Cantidad de tiempo (en días o meses) para la ejecución del próximo pago."
839
+
840
+ msgid "Start date"
841
+ msgstr "Fecha de inicio"
842
+
843
+ msgid "First payment date (effective debit). Defaults to now if blank."
844
+ msgstr "Primera fecha de pago (débito efectivo). De forma predeterminada ahora, si está en blanco."
845
+
846
+ msgid "End date"
847
+ msgstr "Fecha final"
848
+
849
+ msgid "Deadline to generate new charges. Defaults to never if blank."
850
+ msgstr "Fecha límite para generar nuevos cargos. De forma predeterminada como nunca, si está en blanco."
851
+
852
+ msgid "Days"
853
+ msgstr "Días"
854
+
855
+ msgid "Months"
856
+ msgstr "Meses"
857
+
858
+ msgid "Indicates the period of time."
859
+ msgstr "Indica el período de tiempo."
860
+
861
+ msgid "The amount to charge the payer each period. Should be informed including taxes and discounts."
862
+ msgstr "La cantidad para cobrar el pagador en cada período. Debe ser informada incluyendo impuestos y descuentos."
863
+
864
+ msgid "Amount charged"
865
+ msgstr "Cantidad de cobro"
866
+
867
+ msgid "Uruguay"
868
+ msgstr "Uruguay"
869
+
870
+ msgid "Frequency type"
871
+ msgstr "Tipo de frecuencia"
872
+
873
+ msgid "Transaction amount"
874
+ msgstr "Valor de la transacción"
875
+
876
+ msgid "A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders."
877
+ msgstr "Un producto recurrente es una suscripción que debe adquirirse por separado en su carrito. Por favor, hace los pedidos por separado."
878
+
879
+ msgid "Subscription"
880
+ msgstr "Suscripción"
881
+
882
+ msgid "Enable Subscription"
883
+ msgstr "Habilitar Suscripción"
884
+
885
+ msgid "Subscription is Inactive"
886
+ msgstr "La Suscripción está Inactiva"
887
+
888
+ msgid "Subscribe with Mercado Pago"
889
+ msgstr "Suscribirse con Mercado Pago"
890
+
891
+ msgid "For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:"
892
+ msgstr "Para esta solución, usted debe configurar su URL de IPN. Puede acceder a ella en su cuenta para su específico país en:"
893
+
894
+ msgid "Discount by Gateway"
895
+ msgstr "Descuento por Gateway"
896
+
897
+ msgid "Give a percentual discount for your customers if they use this payment gateway."
898
+ msgstr "Dé un descuento porcentual para sus clientes si utilizan este medio de pago."
899
+
900
+ msgid "This field should be an integer greater or equal 0 and smaller than 100."
901
+ msgstr "Este campo debe ser un número entero mayor o igual 0 y menor que 100."
902
+
903
+ msgid "Discount Of"
904
+ msgstr "Descuento de"
905
+
906
+ msgid "Mercado Pago Subscription"
907
+ msgstr "Suscripción Mercado Pago"
908
+
909
+ msgid "Payment ID:"
910
+ msgstr "ID de Pago:"
911
+
912
+ msgid "Amount:"
913
+ msgstr "Cantidad:"
914
+
915
+ msgid "This operation could not be completed."
916
+ msgstr "Esta operación no se puede completar."
917
+
918
+ msgid "Operation successfully completed."
919
+ msgstr "La operación se realizó con éxito."
920
+
921
+ msgid "Refund Payment"
922
+ msgstr "Reembolso de Pago"
923
+
924
+ msgid "Cancel Payment"
925
+ msgstr "Cancelar Pago"
926
+
927
+ msgid "Mercado Pago - Subscription"
928
+ msgstr "Mercado Pago - Suscripcións"
929
+
930
+ msgid "Mercado Envios is a shipping method available only for payments with Mercado Pago."
931
+ msgstr "Mercado Envios es un método de envío disponible sólo para los pagos con Mercado Pago."
932
+
933
+ msgid "Free Shipping"
934
+ msgstr "Envío Gratuito"
935
+
936
+ msgid "Day"
937
+ msgstr "Día"
938
+
939
+ msgid "Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module."
940
+ msgstr "Habilitar los dos métodos de envío de Mercado Envios (Express y Normal) para el correcto funcionamiento del módulo."
941
+
942
+ msgid "Mercado Envios"
943
+ msgstr "Mercado Envios"
944
+
945
+ msgid "This controls the title which the user sees during checkout."
946
+ msgstr "Controla el título que se muestra al cliente durante el pago."
947
+
948
+ msgid "Enable free shipping for this shipping method"
949
+ msgstr "Habilitar el envío gratuito para este método de envío"
950
+
951
+ msgid "Delivery Time"
952
+ msgstr "Tiempo de Entrega"
953
+
954
+ msgid "Show estimated delivery time"
955
+ msgstr "Mostrar el tiempo estimado de entrega"
956
+
957
+ msgid "Display the estimated delivery time in working days."
958
+ msgstr "Mostrar el tiempo estimado de entrega en días laborables."
959
+
960
+ msgid "Buyer initiates complaint and requested a refund."
961
+ msgstr "El comprador ha iniciado una discusión y pide un extorno."
962
+
963
+ msgid "In return to sender"
964
+ msgstr "Volviendo al remitente"
965
+
966
+ msgid "Missing recipient for delivery"
967
+ msgstr "Destinatario ausente para envío"
968
+
969
+ msgid "Delayed shipping"
970
+ msgstr "Envío retrasado"
971
+
972
+ msgid "Unsuccessful"
973
+ msgstr "Fracasado"
974
+
975
+ msgid "Tag printed"
976
+ msgstr "Etiqueta impresa"
977
+
978
+ msgid "Tag ready to print"
979
+ msgstr "Etiquetar lista para imprimir"
980
+
981
+ msgid "Tracking code:"
982
+ msgstr "Código de rastreamiento:"
983
+
984
+ msgid "Tag:"
985
+ msgstr "Etiqueta:"
986
+
987
+ msgid "Shipping is pending"
988
+ msgstr "Envío pendiente"
989
+
990
+ msgid "Tutorial"
991
+ msgstr "Tutorial"
992
+
993
+ msgid "Discount Of "
994
+ msgstr "Descuento De "
995
+
996
+ msgid "Make this product a subscription."
997
+ msgstr "Hacer deste producto una suscripción."
998
+
999
+ msgid "Order"
1000
+ msgstr "Pedido"
1001
+
1002
+ msgid "Mercado Envios Tracking ID"
1003
+ msgstr "Código de rastreamiento de Mercado Envíos"
1004
+
1005
+ msgid "Hello,"
1006
+ msgstr "Hola,"
1007
+
1008
+ msgid "Your order"
1009
+ msgstr "Su pedido"
1010
+
1011
+ msgid "made in"
1012
+ msgstr "hecho en"
1013
+
1014
+ msgid "used Mercado Envios as its shipment method."
1015
+ msgstr "utilizó el Mercado Envíos como su medio de envío."
1016
+
1017
+ msgid "You can track it with the following Tracking ID:"
1018
+ msgstr "Usted puedes rastrearlo con lo siguiente código de rastreamiento:"
1019
+
1020
+ msgid "Best regards."
1021
+ msgstr "Saludos."
1022
+
1023
+ msgid "SELECT..."
1024
+ msgstr "SELECCIONE..."
1025
+
1026
+ msgid "NAME"
1027
+ msgstr "NOMBRE"
1028
+
1029
+ msgid "SURNAME"
1030
+ msgstr "APELLIDO"
1031
+
1032
+ msgid "DOCUMENT"
1033
+ msgstr "DOCUMENTO"
1034
+
1035
+ msgid "ADDRESS"
1036
+ msgstr "DIRECCIÓN"
1037
+
1038
+ msgid "NUMBER"
1039
+ msgstr "NÚMERO"
1040
+
1041
+ msgid "CITY"
1042
+ msgstr "CIUDAD"
1043
+
1044
+ msgid "STATE"
1045
+ msgstr "ESTADO"
1046
+
1047
+ msgid "ZIP"
1048
+ msgstr "CÓDIGO POSTAL"
1049
+
1050
+ msgid "You must inform you NAME"
1051
+ msgstr "Obligatorio informar su NOMBRE"
1052
+
1053
+ msgid "You must inform your SURNAME"
1054
+ msgstr "Obligatorio informar su APELLIDO"
1055
+
1056
+ msgid "You must inform your DOCUMENT"
1057
+ msgstr "Obligatorio informar su DOCUMENTO"
1058
+
1059
+ msgid "You must inform your ADDRESS"
1060
+ msgstr "Obligatorio informar su DIRECCIÓN"
1061
+
1062
+ msgid "You must inform your ADDRESS NUMBER"
1063
+ msgstr "Obligatorio informar su NÚMERO"
1064
+
1065
+ msgid "You must inform your CITY"
1066
+ msgstr "Obligatorio informar su CIUDAD"
1067
+
1068
+ msgid "You must inform your STATE"
1069
+ msgstr "Obligatorio informar su ESTADO"
1070
+
1071
+ msgid "You must inform your ZIP"
1072
+ msgstr "Obligatorio informar su CÓDIGO POSTAL"
1073
+
1074
+ msgid "Your PHP version is OK."
1075
+ msgstr "Su versión de PHP está bien."
1076
+
1077
+ msgid "Your PHP version do not support this module. You have %s, minimal required is %s."
1078
+ msgstr "Su versión de PHP no soporta este módulo. Tienes %s, la mínima requerida es %s."
1079
+
1080
+ msgid "cURL is installed."
1081
+ msgstr "cURL está instalado."
1082
+
1083
+ msgid "cURL is not installed."
1084
+ msgstr "cURL no está instalado."
1085
+
1086
+ msgid "SSL is missing in your site."
1087
+ msgstr "Falta el SSL en su sitio."
1088
+
1089
+ msgid "Your site has SSL enabled."
1090
+ msgstr "Su sitio tiene SSL habilitado."
languages/woocommerce-mercadopago-module-pt_BR.mo CHANGED
Binary file
languages/woocommerce-mercadopago-module-pt_BR.po CHANGED
@@ -28,7 +28,7 @@ msgstr "Este é o módulo <strong>oficial</strong> do Mercado Pago para o plugin
28
  #: mercadopago-module.php:69
29
  #, php-format
30
  msgid "Woo Mercado Pago Module depends on the last version of %s to execute!"
31
- msgstr "Woo Mercado Pago Module depends on the last version of %s to execute!"
32
 
33
  #: mercadopago-module.php:109
34
  msgid "Basic Checkout"
@@ -42,54 +42,72 @@ msgstr "Checkout Transparente"
42
  msgid "Mercado Pago - Custom Checkout"
43
  msgstr "Mercado Pago - Checkout Transparente"
44
 
45
- #: mercadopago/mercadopago-custom-gateway.php:51 mercadopago/mercadopago-gateway.php:54
 
46
  msgid "This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store."
47
  msgstr "Este módulo habilita o WooCommerce a usar o Mercado Pago como meio de pagamento para compras realizadas em sua loja virtual."
48
 
49
- #: mercadopago/mercadopago-custom-gateway.php:126 mercadopago/mercadopago-custom-gateway.php:791 mercadopago/mercadopago-gateway.php:125
 
 
50
  #: mercadopago/mercadopago-gateway.php:716
51
  msgid "Argentine"
52
  msgstr "Argentina"
53
 
54
- #: mercadopago/mercadopago-custom-gateway.php:127 mercadopago/mercadopago-custom-gateway.php:792 mercadopago/mercadopago-gateway.php:126
 
 
55
  #: mercadopago/mercadopago-gateway.php:717
56
  msgid "Brazil"
57
  msgstr "Brasil"
58
 
59
- #: mercadopago/mercadopago-custom-gateway.php:128 mercadopago/mercadopago-custom-gateway.php:794 mercadopago/mercadopago-gateway.php:127
 
 
60
  #: mercadopago/mercadopago-gateway.php:719
61
  msgid "Chile"
62
  msgstr "Chile"
63
 
64
- #: mercadopago/mercadopago-custom-gateway.php:129 mercadopago/mercadopago-custom-gateway.php:793 mercadopago/mercadopago-gateway.php:128
 
 
65
  #: mercadopago/mercadopago-gateway.php:718
66
  msgid "Colombia"
67
  msgstr "Colômbia"
68
 
69
- #: mercadopago/mercadopago-custom-gateway.php:130 mercadopago/mercadopago-custom-gateway.php:795 mercadopago/mercadopago-gateway.php:129
 
 
70
  #: mercadopago/mercadopago-gateway.php:720
71
  msgid "Mexico"
72
  msgstr "México"
73
 
74
- #: mercadopago/mercadopago-custom-gateway.php:132 mercadopago/mercadopago-gateway.php:130
 
75
  msgid "or"
76
  msgstr "ou"
77
 
78
- #: mercadopago/mercadopago-custom-gateway.php:133 mercadopago/mercadopago-custom-gateway.php:796 mercadopago/mercadopago-gateway.php:131
 
 
79
  #: mercadopago/mercadopago-gateway.php:721
80
  msgid "Venezuela"
81
  msgstr "Venezuela"
82
 
83
- #: mercadopago/mercadopago-custom-gateway.php:145 mercadopago/mercadopago-gateway.php:151
 
84
  msgid "Your credentials are <strong>valid</strong> for"
85
  msgstr "Suas credenciais <strong>são válidas</strong> para"
86
 
87
- #: mercadopago/mercadopago-custom-gateway.php:151 mercadopago/mercadopago-custom-gateway.php:156 mercadopago/mercadopago-gateway.php:161
 
 
88
  #: mercadopago/mercadopago-gateway.php:170
89
  msgid "Your credentials are <strong>not valid</strong>!"
90
  msgstr "Suas credenciais <strong>não são válidas</strong>!"
91
 
92
- #: mercadopago/mercadopago-custom-gateway.php:169 mercadopago/mercadopago-gateway.php:211
 
93
  msgid "Enable/Disable"
94
  msgstr "Habilitar/Desabilitar"
95
 
@@ -97,11 +115,13 @@ msgstr "Habilitar/Desabilitar"
97
  msgid "Enable Custom Checkout"
98
  msgstr "Habilitar o Checkout Transparente"
99
 
100
- #: mercadopago/mercadopago-custom-gateway.php:175 mercadopago/mercadopago-gateway.php:217
 
101
  msgid "Mercado Pago Credentials"
102
  msgstr "Credenciais do Mercado Pago"
103
 
104
- #: mercadopago/mercadopago-custom-gateway.php:177 mercadopago/mercadopago-gateway.php:219
 
105
  msgid "You can obtain your credentials for"
106
  msgstr "Você pode obter suas credenciais para"
107
 
@@ -113,39 +133,50 @@ msgstr "Insira sua Public Key do Mercado Pago."
113
  msgid "Insert your Mercado Pago Access token."
114
  msgstr "Insira seu Access Token do Mercado Pago."
115
 
116
- #: mercadopago/mercadopago-custom-gateway.php:194 mercadopago/mercadopago-gateway.php:236
 
117
  msgid "Instant Payment Notification (IPN) URL"
118
  msgstr "URL de Notificações Instantâneas de Pagamento (IPN)"
119
 
120
- #: mercadopago/mercadopago-custom-gateway.php:196 mercadopago/mercadopago-gateway.php:238
 
121
  msgid "Your IPN URL to receive instant payment notifications is"
122
  msgstr "Sua URL de IPN para receber notificações instantâneas de pagamentos é"
123
 
124
- #: mercadopago/mercadopago-custom-gateway.php:199 mercadopago/mercadopago-gateway.php:241
 
125
  msgid "Checkout Options"
126
  msgstr "Opções de Checkout"
127
 
128
- #: mercadopago/mercadopago-custom-gateway.php:204 mercadopago/mercadopago-gateway.php:246
 
129
  msgid "Title"
130
  msgstr "Título"
131
 
132
- #: mercadopago/mercadopago-custom-gateway.php:206 mercadopago/mercadopago-gateway.php:248
 
133
  msgid "Title shown to the client in the checkout."
134
  msgstr "Título mostrado ao cliente durante o checkout."
135
 
136
- #: mercadopago/mercadopago-custom-gateway.php:207 mercadopago/mercadopago-custom-gateway.php:219 mercadopago/mercadopago-gateway.php:249
 
 
137
  msgid "Mercado Pago"
138
  msgstr "Mercado Pago"
139
 
140
- #: mercadopago/mercadopago-custom-gateway.php:210 mercadopago/mercadopago-gateway.php:252
 
141
  msgid "Description"
142
  msgstr "Descrição"
143
 
144
- #: mercadopago/mercadopago-custom-gateway.php:212 mercadopago/mercadopago-gateway.php:254
 
145
  msgid "Description shown to the client in the checkout."
146
  msgstr "Descrição mostrada ao cliente durante o checkout."
147
 
148
- #: mercadopago/mercadopago-custom-gateway.php:213 mercadopago/mercadopago-gateway.php:255 mercadopago/mercadopago-gateway.php:432
 
 
149
  msgid "Pay with Mercado Pago"
150
  msgstr "Pagar com Mercado Pago"
151
 
@@ -181,59 +212,73 @@ msgstr "Habilitar Boleto para o Checkout Transparente"
181
  msgid "Let your customer pay you with tickets"
182
  msgstr "Permitir que seus clientes façam pagamentos por boletos"
183
 
184
- #: mercadopago/mercadopago-custom-gateway.php:236 mercadopago/mercadopago-gateway.php:258
 
185
  msgid "Store Category"
186
  msgstr "Categoria da loja"
187
 
188
- #: mercadopago/mercadopago-custom-gateway.php:238 mercadopago/mercadopago-gateway.php:260
 
189
  msgid "Define which type of products your store sells."
190
  msgstr "Defina qual o tipo dos produtos que sua loja vende."
191
 
192
- #: mercadopago/mercadopago-custom-gateway.php:242 mercadopago/mercadopago-gateway.php:264
 
193
  msgid "Store Identificator"
194
  msgstr "Identificador da Loja"
195
 
196
- #: mercadopago/mercadopago-custom-gateway.php:244 mercadopago/mercadopago-gateway.php:266
 
197
  msgid "Please, inform a prefix to your store."
198
  msgstr "Por favor, informe um prefixo para sua loja."
199
 
200
- #: mercadopago/mercadopago-custom-gateway.php:244 mercadopago/mercadopago-gateway.php:266
 
201
  msgid "If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same identificators."
202
  msgstr "Se estiver usando sua conta Mercado Pago para múltiplas lojas então você deverá assegurar-se que este prefixo seja único pois o Mercado Pago não permitirá pedidos com um mesmo identificador."
203
 
204
- #: mercadopago/mercadopago-custom-gateway.php:248 mercadopago/mercadopago-gateway.php:318
 
205
  msgid "Test and Debug Options"
206
  msgstr "Opções de Teste e Debug"
207
 
208
- #: mercadopago/mercadopago-custom-gateway.php:253 mercadopago/mercadopago-gateway.php:323
 
209
  msgid "Mercado Pago Sandbox"
210
  msgstr "Sandbox Mercado Pago"
211
 
212
- #: mercadopago/mercadopago-custom-gateway.php:255 mercadopago/mercadopago-gateway.php:325
 
213
  msgid "Enable Mercado Pago Sandbox"
214
  msgstr "Habilitar o sandbox do Mercado Pago"
215
 
216
- #: mercadopago/mercadopago-custom-gateway.php:257 mercadopago/mercadopago-gateway.php:327
 
217
  msgid "This option allows you to test payments inside a sandbox environment."
218
  msgstr "Esta opção permite a você testar pagamentos em um ambiente sandbox."
219
 
220
- #: mercadopago/mercadopago-custom-gateway.php:260 mercadopago/mercadopago-gateway.php:330
 
221
  msgid "Debug and Log"
222
  msgstr "Debug e Log"
223
 
224
- #: mercadopago/mercadopago-custom-gateway.php:262 mercadopago/mercadopago-gateway.php:332
 
225
  msgid "Enable log"
226
  msgstr "Habilitar Log"
227
 
228
- #: mercadopago/mercadopago-custom-gateway.php:264 mercadopago/mercadopago-gateway.php:334
 
229
  msgid "Register event logs of Mercado Pago, such as API requests, in the file"
230
  msgstr "Registrar logs de eventos do Mercado Pago, como requisições à API, dentro do arquivo"
231
 
232
- #: mercadopago/mercadopago-custom-gateway.php:265 mercadopago/mercadopago-gateway.php:335
 
233
  msgid "File location: "
234
  msgstr "Local do arquivo: "
235
 
236
- #: mercadopago/mercadopago-custom-gateway.php:281 mercadopago/mercadopago-gateway.php:351
 
237
  #, php-format
238
  msgid "Please, rate us %s on WordPress.org and give your feedback to help improve this module!"
239
  msgstr "Por favor, avalie-nos com %s na WordPress.org e dê seu feedback para ajudar a melhorar este módulo!"
@@ -276,7 +321,7 @@ msgstr "Tipo de documento"
276
 
277
  #: mercadopago/mercadopago-custom-gateway.php:341
278
  msgid "Document number"
279
- msgstr "Número do documento"
280
 
281
  #: mercadopago/mercadopago-custom-gateway.php:342
282
  msgid "Issuer"
@@ -294,7 +339,9 @@ msgstr "O campo [Número do cartão] não pode ser nulo/vazio"
294
  msgid "Invalid Card Number"
295
  msgstr "Número do cartão inválido"
296
 
297
- #: mercadopago/mercadopago-custom-gateway.php:350 mercadopago/mercadopago-custom-gateway.php:351 mercadopago/mercadopago-custom-gateway.php:352
 
 
298
  #: mercadopago/mercadopago-custom-gateway.php:353
299
  msgid "Invalid Expiration Date"
300
  msgstr "Data de expiração inválida"
@@ -343,11 +390,14 @@ msgstr "Subtipo do documento inválido"
343
  msgid "Parameter cardIssuerId can not be null/empty"
344
  msgstr "O campo [Emitente do cartão] não pode ser nulo/vazio"
345
 
346
- #: mercadopago/mercadopago-custom-gateway.php:402 mercadopago/mercadopago-custom-gateway.php:943 mercadopago/mercadopago-gateway.php:869
 
 
347
  msgid "Payment approved."
348
  msgstr "Pagamento aprovado."
349
 
350
- #: mercadopago/mercadopago-custom-gateway.php:416 mercadopago/mercadopago-custom-gateway.php:805
 
351
  msgid "Your payment is under review. In less than 1h, you should be notified by email."
352
  msgstr "Seu pagamento está sob análise. Em menos de 1h, você deverá ser notificado por email."
353
 
@@ -359,7 +409,9 @@ msgstr "Ver o resumo do pedido"
359
  msgid "Your payment was refused. You can try again."
360
  msgstr "Seu pagamento foi rejeitado. Você pode tentar novamente."
361
 
362
- #: mercadopago/mercadopago-custom-gateway.php:435 mercadopago/mercadopago-custom-gateway.php:819 mercadopago/mercadopago-gateway.php:460
 
 
363
  msgid "Click to try again"
364
  msgstr "Clique para tentar novamente"
365
 
@@ -375,11 +427,14 @@ msgstr "Método de envio"
375
  msgid "Shipping service used by store"
376
  msgstr "Serviço de envio usado pela loja"
377
 
378
- #: mercadopago/mercadopago-custom-gateway.php:721 mercadopago/mercadopago-gateway.php:649
 
379
  msgid "WooCommerce &gt; System Status &gt; Logs"
380
  msgstr "WooCommerce &gt; Status de Sistema &gt; Logs"
381
 
382
- #: mercadopago/mercadopago-custom-gateway.php:766 mercadopago/mercadopago-custom-gateway.php:779 mercadopago/mercadopago-gateway.php:694
 
 
383
  #: mercadopago/mercadopago-gateway.php:705
384
  msgid "Mercado Pago is Inactive"
385
  msgstr "O Mercado Pago está inativo"
@@ -388,15 +443,18 @@ msgstr "O Mercado Pago está inativo"
388
  msgid "Your Mercado Pago credentials Public Key/Access Token appears to be misconfigured."
389
  msgstr "Suas credenciais Public Key/Access Token do Mercado Pago parecem estar desconfiguradas."
390
 
391
- #: mercadopago/mercadopago-custom-gateway.php:771 mercadopago/mercadopago-gateway.php:698
 
392
  msgid "Click here and configure!"
393
  msgstr "Clique aqui e configure!"
394
 
395
- #: mercadopago/mercadopago-custom-gateway.php:782 mercadopago/mercadopago-gateway.php:708
 
396
  msgid "The currency"
397
  msgstr "As moedas"
398
 
399
- #: mercadopago/mercadopago-custom-gateway.php:783 mercadopago/mercadopago-gateway.php:708
 
400
  msgid "is not supported. Supported currencies are: ARS, BRL, CLP, COP, MXN, VEF."
401
  msgstr "não são suportadas. As moedas suportadas são: ARS, BRL, CLP, COP, MXN, VEF."
402
 
@@ -408,7 +466,8 @@ msgstr "Peru"
408
  msgid "Click to check your order"
409
  msgstr "Clique para ver o resumo do seu pedido"
410
 
411
- #: mercadopago/mercadopago-custom-gateway.php:814 mercadopago/mercadopago-gateway.php:457
 
412
  msgid "An error occurred when proccessing your payment. Please try again or contact us for assistence."
413
  msgstr "Um erro ocorreu ao processar seu pagamento. Por favor tente novamente ou nos contacte para assistência."
414
 
@@ -416,43 +475,54 @@ msgstr "Um erro ocorreu ao processar seu pagamento. Por favor tente novamente ou
416
  msgid "Reason is: "
417
  msgstr "Causa: "
418
 
419
- #: mercadopago/mercadopago-custom-gateway.php:849 mercadopago/mercadopago-gateway.php:748
 
420
  msgid "Mercado Pago Request Failure"
421
  msgstr "Falha na Requisição do Mercado Pago"
422
 
423
- #: mercadopago/mercadopago-custom-gateway.php:918 mercadopago/mercadopago-gateway.php:822
 
424
  msgid "Payer email"
425
  msgstr "Email do pagador"
426
 
427
- #: mercadopago/mercadopago-custom-gateway.php:926 mercadopago/mercadopago-gateway.php:829
 
428
  msgid "Payment type"
429
  msgstr "Tipo de pagamento"
430
 
431
- #: mercadopago/mercadopago-custom-gateway.php:934 mercadopago/mercadopago-gateway.php:841
 
432
  msgid "Mercado Pago Payment ID"
433
  msgstr "ID de Pagamento do Mercado Pago"
434
 
435
- #: mercadopago/mercadopago-custom-gateway.php:950 mercadopago/mercadopago-gateway.php:875
 
436
  msgid "Customer haven't paid yet."
437
  msgstr "O cliente ainda não realizou o pagamento."
438
 
439
- #: mercadopago/mercadopago-custom-gateway.php:957 mercadopago/mercadopago-gateway.php:881
 
440
  msgid "Payment under review."
441
  msgstr "O pagamento está em revisão."
442
 
443
- #: mercadopago/mercadopago-custom-gateway.php:964 mercadopago/mercadopago-gateway.php:887
 
444
  msgid "The payment was refused. The customer can try again."
445
  msgstr "O pagamento foi recusado. O cliente pode tentar novamente."
446
 
447
- #: mercadopago/mercadopago-custom-gateway.php:971 mercadopago/mercadopago-gateway.php:893
 
448
  msgid "The payment was refunded to the customer."
449
  msgstr "O pagamento foi estornado ao cliente."
450
 
451
- #: mercadopago/mercadopago-custom-gateway.php:978 mercadopago/mercadopago-gateway.php:899
 
452
  msgid "The payment was cancelled."
453
  msgstr "O pagamento foi cancelado."
454
 
455
- #: mercadopago/mercadopago-custom-gateway.php:984 mercadopago/mercadopago-custom-gateway.php:990 mercadopago/mercadopago-gateway.php:904
 
 
456
  #: mercadopago/mercadopago-gateway.php:909
457
  msgid "The payment is under mediation or it was charged-back."
458
  msgstr "O pagamento está em mediação ou a compra não foi reconhecida pelo cliente."
@@ -465,11 +535,14 @@ msgstr "Mercado Pago - Checkout Básico"
465
  msgid "Select the payment methods that you <strong>don't</strong> want to receive with Mercado Pago."
466
  msgstr "Selecione os meios de pagamento que <strong>não</strong> gostaria de receber com o Mercado Pago."
467
 
468
- #: mercadopago/mercadopago-gateway.php:158 mercadopago/mercadopago-gateway.php:167
 
469
  msgid "Configure your Client_id and Client_secret to have access to more options."
470
  msgstr "Configure seu Client_id e Client_secret para ter acesso a mais opções."
471
 
472
- #: mercadopago/mercadopago-gateway.php:184 mercadopago/mercadopago-gateway.php:192 mercadopago/mercadopago-gateway.php:202
 
 
473
  msgid "This field should be an integer."
474
  msgstr "Este campo deve ser um número inteiro."
475
 
@@ -664,8 +737,8 @@ msgstr "O Boleto está Inativo"
664
  msgid "Please, select the ticket issuer of your preference."
665
  msgstr "Por favor, selecione o emissor de sua preferência."
666
 
667
- msgid "Click "Place order" button. The ticket will be generated and you will be redirected to print it."
668
- msgstr "Clique no botão "FINALIZAR COMPRA". O boleto será gerado e você será redirecionado para imprimí-lo."
669
 
670
  msgid "Important: The order will be confirmed only after the payment approval."
671
  msgstr "Importante: O pedido só será confirmado após a aprovação do pagamento."
@@ -739,8 +812,8 @@ msgstr "ERRO: Não foi possível converter a moeda não suportada"
739
  msgid "to"
740
  msgstr "para"
741
 
742
- msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio"
743
- msgstr "Se a moeda utilizada pelo WooCommerce for diferente ou não suportada pelo Mercado Pago, converte os valores de suas transações usando a taxa de conversão do Mercado Pago"
744
 
745
  msgid " is: "
746
  msgstr " é: "
@@ -764,4 +837,319 @@ msgid "Terms and Conditions of Use"
764
  msgstr "Termos e condições"
765
 
766
  msgid "Payment converted from"
767
- msgstr "Pagamento convertido de"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  #: mercadopago-module.php:69
29
  #, php-format
30
  msgid "Woo Mercado Pago Module depends on the last version of %s to execute!"
31
+ msgstr "Woo Mercado Pago Module depende da última versão do %s para executar!"
32
 
33
  #: mercadopago-module.php:109
34
  msgid "Basic Checkout"
42
  msgid "Mercado Pago - Custom Checkout"
43
  msgstr "Mercado Pago - Checkout Transparente"
44
 
45
+ #: mercadopago/mercadopago-custom-gateway.php:51
46
+ #: mercadopago/mercadopago-gateway.php:54
47
  msgid "This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store."
48
  msgstr "Este módulo habilita o WooCommerce a usar o Mercado Pago como meio de pagamento para compras realizadas em sua loja virtual."
49
 
50
+ #: mercadopago/mercadopago-custom-gateway.php:126
51
+ #: mercadopago/mercadopago-custom-gateway.php:791
52
+ #: mercadopago/mercadopago-gateway.php:125
53
  #: mercadopago/mercadopago-gateway.php:716
54
  msgid "Argentine"
55
  msgstr "Argentina"
56
 
57
+ #: mercadopago/mercadopago-custom-gateway.php:127
58
+ #: mercadopago/mercadopago-custom-gateway.php:792
59
+ #: mercadopago/mercadopago-gateway.php:126
60
  #: mercadopago/mercadopago-gateway.php:717
61
  msgid "Brazil"
62
  msgstr "Brasil"
63
 
64
+ #: mercadopago/mercadopago-custom-gateway.php:128
65
+ #: mercadopago/mercadopago-custom-gateway.php:794
66
+ #: mercadopago/mercadopago-gateway.php:127
67
  #: mercadopago/mercadopago-gateway.php:719
68
  msgid "Chile"
69
  msgstr "Chile"
70
 
71
+ #: mercadopago/mercadopago-custom-gateway.php:129
72
+ #: mercadopago/mercadopago-custom-gateway.php:793
73
+ #: mercadopago/mercadopago-gateway.php:128
74
  #: mercadopago/mercadopago-gateway.php:718
75
  msgid "Colombia"
76
  msgstr "Colômbia"
77
 
78
+ #: mercadopago/mercadopago-custom-gateway.php:130
79
+ #: mercadopago/mercadopago-custom-gateway.php:795
80
+ #: mercadopago/mercadopago-gateway.php:129
81
  #: mercadopago/mercadopago-gateway.php:720
82
  msgid "Mexico"
83
  msgstr "México"
84
 
85
+ #: mercadopago/mercadopago-custom-gateway.php:132
86
+ #: mercadopago/mercadopago-gateway.php:130
87
  msgid "or"
88
  msgstr "ou"
89
 
90
+ #: mercadopago/mercadopago-custom-gateway.php:133
91
+ #: mercadopago/mercadopago-custom-gateway.php:796
92
+ #: mercadopago/mercadopago-gateway.php:131
93
  #: mercadopago/mercadopago-gateway.php:721
94
  msgid "Venezuela"
95
  msgstr "Venezuela"
96
 
97
+ #: mercadopago/mercadopago-custom-gateway.php:145
98
+ #: mercadopago/mercadopago-gateway.php:151
99
  msgid "Your credentials are <strong>valid</strong> for"
100
  msgstr "Suas credenciais <strong>são válidas</strong> para"
101
 
102
+ #: mercadopago/mercadopago-custom-gateway.php:151
103
+ #: mercadopago/mercadopago-custom-gateway.php:156
104
+ #: mercadopago/mercadopago-gateway.php:161
105
  #: mercadopago/mercadopago-gateway.php:170
106
  msgid "Your credentials are <strong>not valid</strong>!"
107
  msgstr "Suas credenciais <strong>não são válidas</strong>!"
108
 
109
+ #: mercadopago/mercadopago-custom-gateway.php:169
110
+ #: mercadopago/mercadopago-gateway.php:211
111
  msgid "Enable/Disable"
112
  msgstr "Habilitar/Desabilitar"
113
 
115
  msgid "Enable Custom Checkout"
116
  msgstr "Habilitar o Checkout Transparente"
117
 
118
+ #: mercadopago/mercadopago-custom-gateway.php:175
119
+ #: mercadopago/mercadopago-gateway.php:217
120
  msgid "Mercado Pago Credentials"
121
  msgstr "Credenciais do Mercado Pago"
122
 
123
+ #: mercadopago/mercadopago-custom-gateway.php:177
124
+ #: mercadopago/mercadopago-gateway.php:219
125
  msgid "You can obtain your credentials for"
126
  msgstr "Você pode obter suas credenciais para"
127
 
133
  msgid "Insert your Mercado Pago Access token."
134
  msgstr "Insira seu Access Token do Mercado Pago."
135
 
136
+ #: mercadopago/mercadopago-custom-gateway.php:194
137
+ #: mercadopago/mercadopago-gateway.php:236
138
  msgid "Instant Payment Notification (IPN) URL"
139
  msgstr "URL de Notificações Instantâneas de Pagamento (IPN)"
140
 
141
+ #: mercadopago/mercadopago-custom-gateway.php:196
142
+ #: mercadopago/mercadopago-gateway.php:238
143
  msgid "Your IPN URL to receive instant payment notifications is"
144
  msgstr "Sua URL de IPN para receber notificações instantâneas de pagamentos é"
145
 
146
+ #: mercadopago/mercadopago-custom-gateway.php:199
147
+ #: mercadopago/mercadopago-gateway.php:241
148
  msgid "Checkout Options"
149
  msgstr "Opções de Checkout"
150
 
151
+ #: mercadopago/mercadopago-custom-gateway.php:204
152
+ #: mercadopago/mercadopago-gateway.php:246
153
  msgid "Title"
154
  msgstr "Título"
155
 
156
+ #: mercadopago/mercadopago-custom-gateway.php:206
157
+ #: mercadopago/mercadopago-gateway.php:248
158
  msgid "Title shown to the client in the checkout."
159
  msgstr "Título mostrado ao cliente durante o checkout."
160
 
161
+ #: mercadopago/mercadopago-custom-gateway.php:207
162
+ #: mercadopago/mercadopago-custom-gateway.php:219
163
+ #: mercadopago/mercadopago-gateway.php:249
164
  msgid "Mercado Pago"
165
  msgstr "Mercado Pago"
166
 
167
+ #: mercadopago/mercadopago-custom-gateway.php:210
168
+ #: mercadopago/mercadopago-gateway.php:252
169
  msgid "Description"
170
  msgstr "Descrição"
171
 
172
+ #: mercadopago/mercadopago-custom-gateway.php:212
173
+ #: mercadopago/mercadopago-gateway.php:254
174
  msgid "Description shown to the client in the checkout."
175
  msgstr "Descrição mostrada ao cliente durante o checkout."
176
 
177
+ #: mercadopago/mercadopago-custom-gateway.php:213
178
+ #: mercadopago/mercadopago-gateway.php:255
179
+ #: mercadopago/mercadopago-gateway.php:432
180
  msgid "Pay with Mercado Pago"
181
  msgstr "Pagar com Mercado Pago"
182
 
212
  msgid "Let your customer pay you with tickets"
213
  msgstr "Permitir que seus clientes façam pagamentos por boletos"
214
 
215
+ #: mercadopago/mercadopago-custom-gateway.php:236
216
+ #: mercadopago/mercadopago-gateway.php:258
217
  msgid "Store Category"
218
  msgstr "Categoria da loja"
219
 
220
+ #: mercadopago/mercadopago-custom-gateway.php:238
221
+ #: mercadopago/mercadopago-gateway.php:260
222
  msgid "Define which type of products your store sells."
223
  msgstr "Defina qual o tipo dos produtos que sua loja vende."
224
 
225
+ #: mercadopago/mercadopago-custom-gateway.php:242
226
+ #: mercadopago/mercadopago-gateway.php:264
227
  msgid "Store Identificator"
228
  msgstr "Identificador da Loja"
229
 
230
+ #: mercadopago/mercadopago-custom-gateway.php:244
231
+ #: mercadopago/mercadopago-gateway.php:266
232
  msgid "Please, inform a prefix to your store."
233
  msgstr "Por favor, informe um prefixo para sua loja."
234
 
235
+ #: mercadopago/mercadopago-custom-gateway.php:244
236
+ #: mercadopago/mercadopago-gateway.php:266
237
  msgid "If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same identificators."
238
  msgstr "Se estiver usando sua conta Mercado Pago para múltiplas lojas então você deverá assegurar-se que este prefixo seja único pois o Mercado Pago não permitirá pedidos com um mesmo identificador."
239
 
240
+ #: mercadopago/mercadopago-custom-gateway.php:248
241
+ #: mercadopago/mercadopago-gateway.php:318
242
  msgid "Test and Debug Options"
243
  msgstr "Opções de Teste e Debug"
244
 
245
+ #: mercadopago/mercadopago-custom-gateway.php:253
246
+ #: mercadopago/mercadopago-gateway.php:323
247
  msgid "Mercado Pago Sandbox"
248
  msgstr "Sandbox Mercado Pago"
249
 
250
+ #: mercadopago/mercadopago-custom-gateway.php:255
251
+ #: mercadopago/mercadopago-gateway.php:325
252
  msgid "Enable Mercado Pago Sandbox"
253
  msgstr "Habilitar o sandbox do Mercado Pago"
254
 
255
+ #: mercadopago/mercadopago-custom-gateway.php:257
256
+ #: mercadopago/mercadopago-gateway.php:327
257
  msgid "This option allows you to test payments inside a sandbox environment."
258
  msgstr "Esta opção permite a você testar pagamentos em um ambiente sandbox."
259
 
260
+ #: mercadopago/mercadopago-custom-gateway.php:260
261
+ #: mercadopago/mercadopago-gateway.php:330
262
  msgid "Debug and Log"
263
  msgstr "Debug e Log"
264
 
265
+ #: mercadopago/mercadopago-custom-gateway.php:262
266
+ #: mercadopago/mercadopago-gateway.php:332
267
  msgid "Enable log"
268
  msgstr "Habilitar Log"
269
 
270
+ #: mercadopago/mercadopago-custom-gateway.php:264
271
+ #: mercadopago/mercadopago-gateway.php:334
272
  msgid "Register event logs of Mercado Pago, such as API requests, in the file"
273
  msgstr "Registrar logs de eventos do Mercado Pago, como requisições à API, dentro do arquivo"
274
 
275
+ #: mercadopago/mercadopago-custom-gateway.php:265
276
+ #: mercadopago/mercadopago-gateway.php:335
277
  msgid "File location: "
278
  msgstr "Local do arquivo: "
279
 
280
+ #: mercadopago/mercadopago-custom-gateway.php:281
281
+ #: mercadopago/mercadopago-gateway.php:351
282
  #, php-format
283
  msgid "Please, rate us %s on WordPress.org and give your feedback to help improve this module!"
284
  msgstr "Por favor, avalie-nos com %s na WordPress.org e dê seu feedback para ajudar a melhorar este módulo!"
321
 
322
  #: mercadopago/mercadopago-custom-gateway.php:341
323
  msgid "Document number"
324
+ msgstr "Número do CPF"
325
 
326
  #: mercadopago/mercadopago-custom-gateway.php:342
327
  msgid "Issuer"
339
  msgid "Invalid Card Number"
340
  msgstr "Número do cartão inválido"
341
 
342
+ #: mercadopago/mercadopago-custom-gateway.php:350
343
+ #: mercadopago/mercadopago-custom-gateway.php:351
344
+ #: mercadopago/mercadopago-custom-gateway.php:352
345
  #: mercadopago/mercadopago-custom-gateway.php:353
346
  msgid "Invalid Expiration Date"
347
  msgstr "Data de expiração inválida"
390
  msgid "Parameter cardIssuerId can not be null/empty"
391
  msgstr "O campo [Emitente do cartão] não pode ser nulo/vazio"
392
 
393
+ #: mercadopago/mercadopago-custom-gateway.php:402
394
+ #: mercadopago/mercadopago-custom-gateway.php:943
395
+ #: mercadopago/mercadopago-gateway.php:869
396
  msgid "Payment approved."
397
  msgstr "Pagamento aprovado."
398
 
399
+ #: mercadopago/mercadopago-custom-gateway.php:416
400
+ #: mercadopago/mercadopago-custom-gateway.php:805
401
  msgid "Your payment is under review. In less than 1h, you should be notified by email."
402
  msgstr "Seu pagamento está sob análise. Em menos de 1h, você deverá ser notificado por email."
403
 
409
  msgid "Your payment was refused. You can try again."
410
  msgstr "Seu pagamento foi rejeitado. Você pode tentar novamente."
411
 
412
+ #: mercadopago/mercadopago-custom-gateway.php:435
413
+ #: mercadopago/mercadopago-custom-gateway.php:819
414
+ #: mercadopago/mercadopago-gateway.php:460
415
  msgid "Click to try again"
416
  msgstr "Clique para tentar novamente"
417
 
427
  msgid "Shipping service used by store"
428
  msgstr "Serviço de envio usado pela loja"
429
 
430
+ #: mercadopago/mercadopago-custom-gateway.php:721
431
+ #: mercadopago/mercadopago-gateway.php:649
432
  msgid "WooCommerce &gt; System Status &gt; Logs"
433
  msgstr "WooCommerce &gt; Status de Sistema &gt; Logs"
434
 
435
+ #: mercadopago/mercadopago-custom-gateway.php:766
436
+ #: mercadopago/mercadopago-custom-gateway.php:779
437
+ #: mercadopago/mercadopago-gateway.php:694
438
  #: mercadopago/mercadopago-gateway.php:705
439
  msgid "Mercado Pago is Inactive"
440
  msgstr "O Mercado Pago está inativo"
443
  msgid "Your Mercado Pago credentials Public Key/Access Token appears to be misconfigured."
444
  msgstr "Suas credenciais Public Key/Access Token do Mercado Pago parecem estar desconfiguradas."
445
 
446
+ #: mercadopago/mercadopago-custom-gateway.php:771
447
+ #: mercadopago/mercadopago-gateway.php:698
448
  msgid "Click here and configure!"
449
  msgstr "Clique aqui e configure!"
450
 
451
+ #: mercadopago/mercadopago-custom-gateway.php:782
452
+ #: mercadopago/mercadopago-gateway.php:708
453
  msgid "The currency"
454
  msgstr "As moedas"
455
 
456
+ #: mercadopago/mercadopago-custom-gateway.php:783
457
+ #: mercadopago/mercadopago-gateway.php:708
458
  msgid "is not supported. Supported currencies are: ARS, BRL, CLP, COP, MXN, VEF."
459
  msgstr "não são suportadas. As moedas suportadas são: ARS, BRL, CLP, COP, MXN, VEF."
460
 
466
  msgid "Click to check your order"
467
  msgstr "Clique para ver o resumo do seu pedido"
468
 
469
+ #: mercadopago/mercadopago-custom-gateway.php:814
470
+ #: mercadopago/mercadopago-gateway.php:457
471
  msgid "An error occurred when proccessing your payment. Please try again or contact us for assistence."
472
  msgstr "Um erro ocorreu ao processar seu pagamento. Por favor tente novamente ou nos contacte para assistência."
473
 
475
  msgid "Reason is: "
476
  msgstr "Causa: "
477
 
478
+ #: mercadopago/mercadopago-custom-gateway.php:849
479
+ #: mercadopago/mercadopago-gateway.php:748
480
  msgid "Mercado Pago Request Failure"
481
  msgstr "Falha na Requisição do Mercado Pago"
482
 
483
+ #: mercadopago/mercadopago-custom-gateway.php:918
484
+ #: mercadopago/mercadopago-gateway.php:822
485
  msgid "Payer email"
486
  msgstr "Email do pagador"
487
 
488
+ #: mercadopago/mercadopago-custom-gateway.php:926
489
+ #: mercadopago/mercadopago-gateway.php:829
490
  msgid "Payment type"
491
  msgstr "Tipo de pagamento"
492
 
493
+ #: mercadopago/mercadopago-custom-gateway.php:934
494
+ #: mercadopago/mercadopago-gateway.php:841
495
  msgid "Mercado Pago Payment ID"
496
  msgstr "ID de Pagamento do Mercado Pago"
497
 
498
+ #: mercadopago/mercadopago-custom-gateway.php:950
499
+ #: mercadopago/mercadopago-gateway.php:875
500
  msgid "Customer haven't paid yet."
501
  msgstr "O cliente ainda não realizou o pagamento."
502
 
503
+ #: mercadopago/mercadopago-custom-gateway.php:957
504
+ #: mercadopago/mercadopago-gateway.php:881
505
  msgid "Payment under review."
506
  msgstr "O pagamento está em revisão."
507
 
508
+ #: mercadopago/mercadopago-custom-gateway.php:964
509
+ #: mercadopago/mercadopago-gateway.php:887
510
  msgid "The payment was refused. The customer can try again."
511
  msgstr "O pagamento foi recusado. O cliente pode tentar novamente."
512
 
513
+ #: mercadopago/mercadopago-custom-gateway.php:971
514
+ #: mercadopago/mercadopago-gateway.php:893
515
  msgid "The payment was refunded to the customer."
516
  msgstr "O pagamento foi estornado ao cliente."
517
 
518
+ #: mercadopago/mercadopago-custom-gateway.php:978
519
+ #: mercadopago/mercadopago-gateway.php:899
520
  msgid "The payment was cancelled."
521
  msgstr "O pagamento foi cancelado."
522
 
523
+ #: mercadopago/mercadopago-custom-gateway.php:984
524
+ #: mercadopago/mercadopago-custom-gateway.php:990
525
+ #: mercadopago/mercadopago-gateway.php:904
526
  #: mercadopago/mercadopago-gateway.php:909
527
  msgid "The payment is under mediation or it was charged-back."
528
  msgstr "O pagamento está em mediação ou a compra não foi reconhecida pelo cliente."
535
  msgid "Select the payment methods that you <strong>don't</strong> want to receive with Mercado Pago."
536
  msgstr "Selecione os meios de pagamento que <strong>não</strong> gostaria de receber com o Mercado Pago."
537
 
538
+ #: mercadopago/mercadopago-gateway.php:158
539
+ #: mercadopago/mercadopago-gateway.php:167
540
  msgid "Configure your Client_id and Client_secret to have access to more options."
541
  msgstr "Configure seu Client_id e Client_secret para ter acesso a mais opções."
542
 
543
+ #: mercadopago/mercadopago-gateway.php:184
544
+ #: mercadopago/mercadopago-gateway.php:192
545
+ #: mercadopago/mercadopago-gateway.php:202
546
  msgid "This field should be an integer."
547
  msgstr "Este campo deve ser um número inteiro."
548
 
737
  msgid "Please, select the ticket issuer of your preference."
738
  msgstr "Por favor, selecione o emissor de sua preferência."
739
 
740
+ msgid "Click \"Place order\" button. The ticket will be generated and you will be redirected to print it."
741
+ msgstr "Clique no botão \"Finalizar compra\". O boleto será gerado e você será redirecionado para imprimí-lo."
742
 
743
  msgid "Important: The order will be confirmed only after the payment approval."
744
  msgstr "Importante: O pedido só será confirmado após a aprovação do pagamento."
812
  msgid "to"
813
  msgstr "para"
814
 
815
+ msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio."
816
+ msgstr "Se a moeda utilizada pelo WooCommerce for diferente ou não suportada pelo Mercado Pago, converte os valores de suas transações usando a taxa de conversão do Mercado Pago."
817
 
818
  msgid " is: "
819
  msgstr " é: "
837
  msgstr "Termos e condições"
838
 
839
  msgid "Payment converted from"
840
+ msgstr "Pagamento convertido de"
841
+
842
+ msgid "Rate Us"
843
+ msgstr "Avalie"
844
+
845
+ msgid "Report Issue"
846
+ msgstr "Informar Problema"
847
+
848
+ msgid "Two Cards Mode"
849
+ msgstr "Modo Dois Cartões"
850
+
851
+ msgid "Payments with Two Cards"
852
+ msgstr "Pagamento com Dois Cartões"
853
+
854
+ msgid "Your customer will be able to use two different cards to pay the order."
855
+ msgstr "Seus clientes poderão utilizar dois diferentes cartões para pagar pedidos."
856
+
857
+ msgid "Your Mercado Pago credentials Access Token appears to be misconfigured."
858
+ msgstr "Sua credencial Access Token do Mercado Pago parece estar desconfigurada."
859
+
860
+ msgid "Cancel Order"
861
+ msgstr "Cancelar Pedido"
862
+
863
+ msgid "Refund Order"
864
+ msgstr "Extornar Pedido"
865
+
866
+ msgid "Back URL Options"
867
+ msgstr "Opções de URL de Retorno"
868
+
869
+ msgid "Sucess URL"
870
+ msgstr "URL de Sucesso"
871
+
872
+ msgid "Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page."
873
+ msgstr "Onde os clientes deverão ser redirecionados após uma compra bem-sucedida. Deixe em branco para redirecionar para a página padrão de resumo de pedido da loja."
874
+
875
+ msgid "Failure URL"
876
+ msgstr "URL de Falha"
877
+
878
+ msgid "Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page."
879
+ msgstr "Onde os clientes deverão ser redirecionados após uma compra ter falhado. Deixe em branco para redirecionar para a página padrão de resumo de pedido da loja."
880
+
881
+ msgid "Pending URL"
882
+ msgstr "URL de Pendência"
883
+
884
+ msgid "Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page."
885
+ msgstr "Onde os clientes deverão ser redirecionados após uma compra entrar em análise. Deixe em branco para redirecionar para a página padrão de resumo de pedido da loja."
886
+
887
+ msgid "Stock Reduce"
888
+ msgstr "Redução de Estoque"
889
+
890
+ msgid "Reduce Stock in Order Generation"
891
+ msgstr "Reduzir Estoque ao Gerar Pedido"
892
+
893
+ msgid "Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval."
894
+ msgstr "Habilite esta opção para reduzir o estoque ao se criar um pedido. Desabilite para reduzir somente <strong>depois</strong> da aprovação do pagamento."
895
+
896
+ msgid "Recurrent Product"
897
+ msgstr "Produto Recorrente"
898
+
899
+ msgid "Frequency"
900
+ msgstr "Frequência"
901
+
902
+ msgid "Amount of time (in days or months) for the execution of the next payment."
903
+ msgstr "Quantia de tempo (em dias ou meses) para a cobrança do próximo pagamento."
904
+
905
+ msgid "Start date"
906
+ msgstr "Data de início"
907
+
908
+ msgid "First payment date (effective debit). Defaults to now if blank."
909
+ msgstr "Data do primeiro pagamento (débito efetivo). Por padrão agora, se deixado em branco."
910
+
911
+ msgid "End date"
912
+ msgstr "Data final"
913
+
914
+ msgid "Deadline to generate new charges. Defaults to never if blank."
915
+ msgstr "Data limite para gerar nova cobrança. Por padrão nunca, se deixado em branco."
916
+
917
+ msgid "Days"
918
+ msgstr "Dias"
919
+
920
+ msgid "Months"
921
+ msgstr "Meses"
922
+
923
+ msgid "Indicates the period of time."
924
+ msgstr "Indica o período de tempo."
925
+
926
+ msgid "The amount to charge the payer each period. Should be informed including taxes and discounts."
927
+ msgstr "A quantia a cobrar o pagador em cada período. Deve ser informada incluindo impostos e descontos."
928
+
929
+ msgid "Amount charged"
930
+ msgstr "Quantia cobrada"
931
+
932
+ msgid "Uruguay"
933
+ msgstr "Uruguai"
934
+
935
+ msgid "Frequency type"
936
+ msgstr "Tipo de frequência"
937
+
938
+ msgid "Transaction amount"
939
+ msgstr "Quantia transacionada"
940
+
941
+ msgid "A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders."
942
+ msgstr "Um produto recorrente é uma assinatura que deve ser comprada isoladamente em seu carrinho. Por favor, crie pedidos separadamente."
943
+
944
+ msgid "Subscription"
945
+ msgstr "Assinaturas"
946
+
947
+ msgid "Enable Subscription"
948
+ msgstr "Habilitar Assinaturas"
949
+
950
+ msgid "Subscription is Inactive"
951
+ msgstr "Assinaturas está Desabilitada"
952
+
953
+ msgid "Subscribe with Mercado Pago"
954
+ msgstr "Assine com Mercado Pago"
955
+
956
+ msgid "For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:"
957
+ msgstr "Para esta solução, você precisa configurar sua URL de IPN. Você pode acessa-la em sua conta específica para seu país em:"
958
+
959
+ msgid "Discount by Gateway"
960
+ msgstr "Desconto por Gateway"
961
+
962
+ msgid "Give a percentual discount for your customers if they use this payment gateway."
963
+ msgstr "Dê um desconto porcentual para seus clientes caso eles usem este método de pagamento."
964
+
965
+ msgid "This field should be an integer greater or equal 0 and smaller than 100."
966
+ msgstr "Este campo deve ser um inteiro maior ou igual a 0 e menor que 100."
967
+
968
+ msgid "Discount Of"
969
+ msgstr "Desconto de"
970
+
971
+ msgid "Mercado Pago Subscription"
972
+ msgstr "Assinaturas Mercado Pago"
973
+
974
+ msgid "Payment ID:"
975
+ msgstr "ID de pagamento:"
976
+
977
+ msgid "Amount:"
978
+ msgstr "Quantidade:"
979
+
980
+ msgid "This operation could not be completed."
981
+ msgstr "Esta operação não pode ser completada."
982
+
983
+ msgid "Operation successfully completed."
984
+ msgstr "A operação foi realizada com sucesso."
985
+
986
+ msgid "Refund Payment"
987
+ msgstr "Extornar Pgto"
988
+
989
+ msgid "Cancel Payment"
990
+ msgstr "Cancelar Pgto"
991
+
992
+ msgid "Mercado Pago - Subscription"
993
+ msgstr "Mercado Pago - Assinaturas"
994
+
995
+ msgid "Mercado Envios is a shipping method available only for payments with Mercado Pago."
996
+ msgstr "Mercado Envios é um método de envio disponível apenas para pagamentos com Mercado Pago."
997
+
998
+ msgid "Free Shipping"
999
+ msgstr "Envio Grátis"
1000
+
1001
+ msgid "Day"
1002
+ msgstr "Dia"
1003
+
1004
+ msgid "Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module."
1005
+ msgstr "Habilitar os dois métodos de envio do Mercado Envios (Expresso e Normal) para o devido funcionamento do módulo."
1006
+
1007
+ msgid "Mercado Envios"
1008
+ msgstr "Mercado Envios"
1009
+
1010
+ msgid "This controls the title which the user sees during checkout."
1011
+ msgstr "Controla o título que é mostrado ao cliente vê durante o checkout."
1012
+
1013
+ msgid "Enable free shipping for this shipping method"
1014
+ msgstr "Habilitar envio gratuito para este método de envio"
1015
+
1016
+ msgid "Delivery Time"
1017
+ msgstr "Tempo de Envio"
1018
+
1019
+ msgid "Show estimated delivery time"
1020
+ msgstr "Mostrar tempo estimado de entrega"
1021
+
1022
+ msgid "Display the estimated delivery time in working days."
1023
+ msgstr "Mostrar o tempo estimado de entrega em dias úteis."
1024
+
1025
+ msgid "Buyer initiates complaint and requested a refund."
1026
+ msgstr "O comprador iniciou uma discussão e requisita um extorno."
1027
+
1028
+ msgid "In return to sender"
1029
+ msgstr "Retornando ao remetente"
1030
+
1031
+ msgid "Missing recipient for delivery"
1032
+ msgstr "Destinatário ausente" para envio
1033
+
1034
+ msgid "Delayed shipping"
1035
+ msgstr "Envio atrasado"
1036
+
1037
+ msgid "Unsuccessful"
1038
+ msgstr "Mal sucedido"
1039
+
1040
+ msgid "Tag printed"
1041
+ msgstr "Etiqueta imprimida"
1042
+
1043
+ msgid "Tag ready to print"
1044
+ msgstr "Etiqueta pronta para impressão"
1045
+
1046
+ msgid "Tracking code:"
1047
+ msgstr "Código de rastreamento:"
1048
+
1049
+ msgid "Tag:"
1050
+ msgstr "Etiqueta:"
1051
+
1052
+ msgid "Shipping is pending"
1053
+ msgstr "Envio pendente"
1054
+
1055
+ msgid "Tutorial"
1056
+ msgstr "Tutorial"
1057
+
1058
+ msgid "Discount Of "
1059
+ msgstr "Desconto De "
1060
+
1061
+ msgid "Make this product a subscription."
1062
+ msgstr "Fazer deste produto uma assinatura."
1063
+
1064
+ msgid "Order"
1065
+ msgstr "Pedido"
1066
+
1067
+ msgid "Mercado Envios Tracking ID"
1068
+ msgstr "ID de rastreamento do Mercado Envios"
1069
+
1070
+ msgid "Hello,"
1071
+ msgstr "Olá,"
1072
+
1073
+ msgid "Your order"
1074
+ msgstr "Seu pedido"
1075
+
1076
+ msgid "made in"
1077
+ msgstr "feito em"
1078
+
1079
+ msgid "used Mercado Envios as its shipment method."
1080
+ msgstr "usou o Mercado Envios como método de envio."
1081
+
1082
+ msgid "You can track it with the following Tracking ID:"
1083
+ msgstr "Você pode rastrea-lo com o seguinte ID de rastreamento:"
1084
+
1085
+ msgid "Best regards."
1086
+ msgstr "Atenciosamente."
1087
+
1088
+ msgid "SELECT..."
1089
+ msgstr "SELECIONE..."
1090
+
1091
+ msgid "NAME"
1092
+ msgstr "NOME"
1093
+
1094
+ msgid "SURNAME"
1095
+ msgstr "SOBRENOME"
1096
+
1097
+ msgid "DOCUMENT"
1098
+ msgstr "CPF"
1099
+
1100
+ msgid "ADDRESS"
1101
+ msgstr "ENDEREÇO"
1102
+
1103
+ msgid "NUMBER"
1104
+ msgstr "NÚMERO"
1105
+
1106
+ msgid "CITY"
1107
+ msgstr "CIDADE"
1108
+
1109
+ msgid "STATE"
1110
+ msgstr "ESTADO"
1111
+
1112
+ msgid "ZIP"
1113
+ msgstr "CEP"
1114
+
1115
+ msgid "You must inform you NAME"
1116
+ msgstr "Obrigatório o preenchimento do Nome"
1117
+
1118
+ msgid "You must inform your SURNAME"
1119
+ msgstr "Obrigatório o preenchimento do Sobrenome"
1120
+
1121
+ msgid "You must inform your DOCUMENT"
1122
+ msgstr "Obrigatório o preenchimento do CPF"
1123
+
1124
+ msgid "You must inform your ADDRESS"
1125
+ msgstr "Obrigatório o preenchimento do Endereço"
1126
+
1127
+ msgid "You must inform your ADDRESS NUMBER"
1128
+ msgstr "Obrigatório o preenchimento do número residencial"
1129
+
1130
+ msgid "You must inform your CITY"
1131
+ msgstr "Obrigatório informar a cidade"
1132
+
1133
+ msgid "You must inform your STATE"
1134
+ msgstr "Obrigatório informar o estado"
1135
+
1136
+ msgid "You must inform your ZIP"
1137
+ msgstr "Obrigatório informar o CEP"
1138
+
1139
+ msgid "Your PHP version is OK."
1140
+ msgstr "Sua versão do PHP está OK."
1141
+
1142
+ msgid "Your PHP version do not support this module. You have %s, minimal required is %s."
1143
+ msgstr "Sua versão do PHP não suporta este módulo. Sua versão é %s, a mínima requerida é %s."
1144
+
1145
+ msgid "cURL is installed."
1146
+ msgstr "cURL está instalado."
1147
+
1148
+ msgid "cURL is not installed."
1149
+ msgstr "cURL não está instalado."
1150
+
1151
+ msgid "SSL is missing in your site."
1152
+ msgstr "Está faltando SSL em seu site."
1153
+
1154
+ msgid "Your site has SSL enabled."
1155
+ msgstr "Seu site possui SSL habilitado."
languages/woocommerce-mercadopago-module.pot CHANGED
@@ -1,571 +1,566 @@
1
  # WordPress Blank Pot
2
  # Copyright (C) 2014 ...
3
  # This file is distributed under the GNU General Public License v2 or later.
4
- #, fuzzy
5
  msgid ""
6
  msgstr ""
7
- "Project-Id-Version: "
8
- "WordPress Blank Pot "
9
- "v1.0.0\n"
10
- "POT-Creation-Date: "
11
- "2016-03-04 17:44-0300\n"
12
  "PO-Revision-Date: \n"
13
- "Last-Translator: Your "
14
- "Name <you@example.com>\n"
15
- "Language-Team: Your Team "
16
- "<translations@example."
17
- "com>\n"
18
- "Report-Msgid-Bugs-To: "
19
- "Translator Name "
20
- "<translations@example."
21
- "com>\n"
22
  "MIME-Version: 1.0\n"
23
- "Content-Type: text/"
24
- "plain; charset=UTF-8\n"
25
- "Content-Transfer-"
26
- "Encoding: 8bit\n"
27
- "Plural-Forms: "
28
- "nplurals=2; plural=n != "
29
- "1;\n"
30
- "X-Textdomain-Support: "
31
- "yesX-Generator: Poedit "
32
- "1.6.4\n"
33
- "X-Poedit-SourceCharset: "
34
- "UTF-8\n"
35
- "X-Poedit-KeywordsList: "
36
- "__;_e;esc_html_e;"
37
- "esc_html_x:1,2c;"
38
- "esc_html__;esc_attr_e;"
39
- "esc_attr_x:1,2c;"
40
- "esc_attr__;_ex:1,2c;"
41
- "_nx:4c,1,2;"
42
- "_nx_noop:4c,1,2;_x:1,2c;"
43
- "_n:1,2;_n_noop:1,2;"
44
- "__ngettext:1,2;"
45
- "__ngettext_noop:1,2;_c,"
46
- "_nc:4c,1,2\n"
47
- "X-Poedit-Basepath: ..\n"
48
  "Language: en_US\n"
49
- "X-Generator: Poedit "
50
- "1.8.7\n"
51
- "X-Poedit-"
52
- "SearchPath-0: .\n"
53
 
54
  #. Description of the plugin/theme
55
  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."
56
  msgstr ""
57
 
58
- #: mercadopago-module.php:66
59
- #, php-format
60
- msgid ""
61
- "Woo Mercado Pago Module "
62
- "depends on the "
63
- "last version of %s to "
64
- "execute!"
65
  msgstr ""
66
 
67
- #: mercadopago-module.php:110
68
- msgid "Settings"
69
  msgstr ""
70
 
71
- #: mercadopago/mercadopago-gateway.php:63
72
- msgid ""
73
- "This module enables "
74
- "WooCommerce to use "
75
- "Mercado Pago as payment "
76
- "method for purchases "
77
- "made in your virtual "
78
- "store."
 
 
79
  msgstr ""
80
 
81
- #: mercadopago/mercadopago-gateway.php:133
 
82
  msgid "Argentine"
83
  msgstr ""
84
 
85
- #: mercadopago/mercadopago-gateway.php:134
 
86
  msgid "Brazil"
87
  msgstr ""
88
 
89
- #: mercadopago/mercadopago-gateway.php:135
 
90
  msgid "Chile"
91
  msgstr ""
92
 
93
- #: mercadopago/mercadopago-gateway.php:136
 
94
  msgid "Colombia"
95
  msgstr ""
96
 
97
- #: mercadopago/mercadopago-gateway.php:137
 
98
  msgid "Mexico"
99
  msgstr ""
100
 
101
- #: mercadopago/mercadopago-gateway.php:138
102
  msgid "or"
103
  msgstr ""
104
 
105
- #: mercadopago/mercadopago-gateway.php:139
 
106
  msgid "Venezuela"
107
  msgstr ""
108
 
109
- #: mercadopago/mercadopago-gateway.php:154
110
- msgid ""
111
- "Select the payment "
112
- "methods that you "
113
- "<strong>don't</strong> "
114
- "want to receive with "
115
- "Mercado Pago."
116
  msgstr ""
117
 
118
- #: mercadopago/mercadopago-gateway.php:157
119
- msgid ""
120
- "Your credentials are "
121
- "<strong>valid</strong> "
122
- "for"
123
  msgstr ""
124
 
125
- #: mercadopago/mercadopago-gateway.php:164
126
- #: mercadopago/mercadopago-gateway.php:173
127
- msgid ""
128
- "Configure your Client_id "
129
- "and Client_secret to "
130
- "have access to more "
131
- "options."
132
  msgstr ""
133
 
134
- #: mercadopago/mercadopago-gateway.php:167
135
- #: mercadopago/mercadopago-gateway.php:176
136
- msgid ""
137
- "Your credentials are "
138
- "<strong>not valid</"
139
- "strong>!"
140
  msgstr ""
141
 
142
- #: mercadopago/mercadopago-gateway.php:190
143
- #: mercadopago/mercadopago-gateway.php:198
144
- #: mercadopago/mercadopago-gateway.php:208
145
- msgid ""
146
- "This field should be an "
147
- "integer."
148
  msgstr ""
149
 
150
- #: mercadopago/mercadopago-gateway.php:193
151
- msgid ""
152
- "If your integration "
153
- "method is iFrame, please "
154
- "inform the payment "
155
- "iFrame width."
156
  msgstr ""
157
 
158
- #: mercadopago/mercadopago-gateway.php:201
159
- msgid ""
160
- "If your integration "
161
- "method is iFrame, please "
162
- "inform the payment "
163
- "iFrame height."
164
  msgstr ""
165
 
166
- #: mercadopago/mercadopago-gateway.php:211
167
- msgid ""
168
- "Select the max number of "
169
- "installments for your "
170
- "customers."
171
  msgstr ""
172
 
173
- #: mercadopago/mercadopago-gateway.php:217
174
- msgid "Enable/Disable"
175
  msgstr ""
176
 
177
- #: mercadopago/mercadopago-gateway.php:219
178
- msgid ""
179
- "Enable Mercado Pago "
180
- "Module"
181
  msgstr ""
182
 
183
- #: mercadopago/mercadopago-gateway.php:223
184
- msgid ""
185
- "Mercado Pago Credentials"
186
  msgstr ""
187
 
188
- #: mercadopago/mercadopago-gateway.php:225
189
- msgid ""
190
- "You can obtain your "
191
- "credentials for"
192
  msgstr ""
193
 
194
- #: mercadopago/mercadopago-gateway.php:228
195
- msgid ""
196
- "Mercado Pago Client_id"
197
  msgstr ""
198
 
199
- #: mercadopago/mercadopago-gateway.php:230
200
- msgid ""
201
- "Insert your Mercado Pago "
202
- "Client_id."
203
  msgstr ""
204
 
205
- #: mercadopago/mercadopago-gateway.php:235
206
- msgid ""
207
- "Mercado Pago "
208
- "Client_secret"
209
  msgstr ""
210
 
211
- #: mercadopago/mercadopago-gateway.php:237
212
- msgid ""
213
- "Insert your Mercado Pago "
214
- "Client_secret."
215
  msgstr ""
216
 
217
- #: mercadopago/mercadopago-gateway.php:265
218
- msgid "Custom Checkout"
219
  msgstr ""
220
 
221
- #: mercadopago/mercadopago-gateway.php:267
222
- msgid "Enable Custom Checkout"
223
  msgstr ""
224
 
225
- #: mercadopago/mercadopago-gateway.php:269
226
- msgid "This option allows your store to present the custom checkout to your customers."
227
  msgstr ""
228
 
229
- #: mercadopago/mercadopago-gateway.php:242
230
- msgid ""
231
- "Instant Payment "
232
- "Notification (IPN) URL"
233
  msgstr ""
234
 
235
- #: mercadopago/mercadopago-gateway.php:244
236
- msgid ""
237
- "Your IPN URL to receive "
238
- "instant payment "
239
- "notifications is"
240
  msgstr ""
241
 
242
- #: mercadopago/mercadopago-gateway.php:247
243
- msgid "Checkout Options"
244
  msgstr ""
245
 
246
- #: mercadopago/mercadopago-gateway.php:252
247
- msgid "Title"
248
  msgstr ""
249
 
250
- #: mercadopago/mercadopago-gateway.php:254
251
- msgid ""
252
- "Title shown to the "
253
- "client in the checkout."
254
  msgstr ""
255
 
256
- #: mercadopago/mercadopago-gateway.php:258
257
- msgid "Description"
258
  msgstr ""
259
 
260
- #: mercadopago/mercadopago-gateway.php:260
261
- msgid ""
262
- "Description shown to the "
263
- "client in the checkout."
264
  msgstr ""
265
 
266
- #: mercadopago/mercadopago-gateway.php:261
267
- #: mercadopago/mercadopago-gateway.php:406
268
- msgid ""
269
- "Pay with Mercado Pago"
270
  msgstr ""
271
 
272
- #: mercadopago/mercadopago-gateway.php:264
273
- msgid "Store Category"
274
  msgstr ""
275
 
276
- #: mercadopago/mercadopago-gateway.php:266
277
- msgid ""
278
- "Define which type of "
279
- "products your store "
280
- "sells."
281
  msgstr ""
282
 
283
- #: mercadopago/mercadopago-gateway.php:270
284
- msgid "Store Identificator"
285
  msgstr ""
286
 
287
- #: mercadopago/mercadopago-gateway.php:272
288
- msgid ""
289
- "Please, inform a prefix "
290
- "to your store."
291
  msgstr ""
292
 
293
- #: mercadopago/mercadopago-gateway.php:272
294
- msgid ""
295
- "If you use your Mercado "
296
- "Pago account on multiple "
297
- "stores you should make "
298
- "sure that this prefix is "
299
- "unique as Mercado Pago "
300
- "will not allow orders "
301
- "with same identificators."
302
  msgstr ""
303
 
304
- #: mercadopago/mercadopago-gateway.php:276
305
- msgid "Integration Method"
306
  msgstr ""
307
 
308
- #: mercadopago/mercadopago-gateway.php:278
309
- msgid ""
310
- "Select how your clients "
311
- "should interact with "
312
- "Mercado Pago. Modal "
313
- "Window (inside your "
314
- "store), Redirect (Client "
315
- "is redirected to Mercado "
316
- "Pago), or iFrame (an "
317
- "internal window is "
318
- "embedded to the page "
319
- "layout)."
320
  msgstr ""
321
 
322
- #: mercadopago/mercadopago-gateway.php:281
323
- msgid "iFrame"
324
  msgstr ""
325
 
326
- #: mercadopago/mercadopago-gateway.php:282
327
- msgid "Modal Window"
328
  msgstr ""
329
 
330
- #: mercadopago/mercadopago-gateway.php:283
331
- msgid "Redirect"
332
  msgstr ""
333
 
334
- #: mercadopago/mercadopago-gateway.php:287
335
- msgid "iFrame Width"
336
  msgstr ""
337
 
338
- #: mercadopago/mercadopago-gateway.php:293
339
- msgid "iFrame Height"
340
  msgstr ""
341
 
342
- #: mercadopago/mercadopago-gateway.php:299
343
- msgid "Auto Return"
344
  msgstr ""
345
 
346
- #: mercadopago/mercadopago-gateway.php:301
347
- msgid ""
348
- "Automatic Return After "
349
- "Payment"
350
  msgstr ""
351
 
352
- #: mercadopago/mercadopago-gateway.php:303
353
- msgid ""
354
- "After the payment, "
355
- "client is automatically "
356
- "redirected."
357
  msgstr ""
358
 
359
- #: mercadopago/mercadopago-gateway.php:306
360
- msgid "Payment Options"
361
  msgstr ""
362
 
363
- #: mercadopago/mercadopago-gateway.php:311
364
- msgid "Max installments"
365
  msgstr ""
366
 
367
- #: mercadopago/mercadopago-gateway.php:339
368
- msgid "Payment with 2 Credit Card"
369
  msgstr ""
370
 
371
- #: mercadopago/mercadopago-gateway.php:341
372
- msgid "Enable payments with 2 credit cards"
373
  msgstr ""
374
 
375
- #: mercadopago/mercadopago-gateway.php:343
376
- msgid "Enable this option to let your customers use 2 credit cards to pay orders."
377
  msgstr ""
378
 
379
- #: mercadopago/mercadopago-gateway.php:317
380
- msgid ""
381
- "Exclude Payment Methods"
382
  msgstr ""
383
 
384
- #: mercadopago/mercadopago-gateway.php:324
385
- msgid ""
386
- "Test and Debug Options"
387
  msgstr ""
388
 
389
- #: mercadopago/mercadopago-gateway.php:329
390
- msgid ""
391
- "Mercado Pago Sandbox"
392
  msgstr ""
393
 
394
- #: mercadopago/mercadopago-gateway.php:331
395
- msgid ""
396
- "Enable Mercado Pago "
397
- "Sandbox"
398
  msgstr ""
399
 
400
- #: mercadopago/mercadopago-gateway.php:333
401
- msgid ""
402
- "This option allows you "
403
- "to test payments inside "
404
- "a sandbox environment."
405
  msgstr ""
406
 
407
- #: mercadopago/mercadopago-gateway.php:336
408
- msgid "Debug and Log"
409
  msgstr ""
410
 
411
- #: mercadopago/mercadopago-gateway.php:338
412
- msgid "Enable log"
 
413
  msgstr ""
414
 
415
- #: mercadopago/mercadopago-gateway.php:340
416
- #, php-format
417
- msgid ""
418
- "Register event logs of "
419
- "Mercado Pago, such as "
420
- "API requests, in the "
421
- "file"
422
  msgstr ""
423
 
424
- #: mercadopago/mercadopago-gateway.php:380
425
- #, php-format
426
- msgid "File location: "
427
  msgstr ""
428
 
429
- #: mercadopago/mercadopago-gateway.php:398
430
- #, php-format
431
- msgid "Please, rate us %s on WordPress.org and give your feedback to help improve this module!"
432
  msgstr ""
433
 
434
- #: mercadopago/mercadopago-gateway.php:402
435
- msgid ""
436
- "Thank you for your "
437
- "order. Please, proceed "
438
- "with your payment "
439
- "clicking in the bellow "
440
- "button."
441
  msgstr ""
442
 
443
- #: mercadopago/mercadopago-gateway.php:410
444
- msgid ""
445
- "Cancel order &amp; Clear "
446
- "cart"
447
  msgstr ""
448
 
449
- #: mercadopago/mercadopago-gateway.php:420
450
- msgid ""
451
- "Thank you for your "
452
- "order. Proceed with your "
453
- "payment completing the "
454
- "following information."
455
  msgstr ""
456
 
457
- #: mercadopago/mercadopago-gateway.php:431
458
- msgid ""
459
- "An error occurred when "
460
- "proccessing your "
461
- "payment. Please try "
462
- "again or contact us for "
463
- "assistence."
464
  msgstr ""
465
 
466
- #: mercadopago/mercadopago-gateway.php:434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
467
  msgid "Click to try again"
468
  msgstr ""
469
 
470
- #: mercadopago/mercadopago-gateway.php:675
471
- #: mercadopago/mercadopago-gateway.php:686
472
- msgid ""
473
- "Mercado Pago is Inactive"
474
  msgstr ""
475
 
476
- #: mercadopago/mercadopago-gateway.php:678
477
- msgid ""
478
- "Your Mercado Pago "
479
- "credentials Client_id/"
480
- "Client_secret appears to "
481
- "be misconfigured."
482
  msgstr ""
483
 
484
- #: mercadopago/mercadopago-gateway.php:679
485
- msgid ""
486
- "Click here and configure!"
 
 
 
487
  msgstr ""
488
 
489
- #: mercadopago/mercadopago-gateway.php:689
 
 
 
 
 
 
 
 
 
 
 
 
 
490
  msgid "The currency"
491
  msgstr ""
492
 
493
- #: mercadopago/mercadopago-gateway.php:689
494
- msgid ""
495
- "is not supported. "
496
- "Supported currencies "
497
- "are: ARS, BRL, CLP, COP, "
498
- "MXN, PEN, USD, VEF."
499
  msgstr ""
500
 
501
- #: mercadopago/mercadopago-gateway.php:712
502
- msgid "WooCommerce &gt; System Status &gt; Logs"
503
  msgstr ""
504
 
505
- #: mercadopago/mercadopago-gateway.php:714
506
- msgid ""
507
- "Mercado Pago Request "
508
- "Failure"
509
  msgstr ""
510
 
511
- #: mercadopago/mercadopago-gateway.php:791
512
- msgid ""
513
- "Mercado Pago Transaction "
514
- "ID"
 
 
515
  msgstr ""
516
 
517
- #: mercadopago/mercadopago-gateway.php:798
 
 
 
 
518
  msgid "Payer email"
519
  msgstr ""
520
 
521
- #: mercadopago/mercadopago-gateway.php:805
522
  msgid "Payment type"
523
  msgstr ""
524
 
525
- #: mercadopago/mercadopago-gateway.php:810
526
- msgid "Payment approved."
527
  msgstr ""
528
 
529
- #: mercadopago/mercadopago-gateway.php:816
530
- msgid ""
531
- "Customer haven't paid "
532
- "yet."
533
  msgstr ""
534
 
535
- #: mercadopago/mercadopago-gateway.php:821
536
- msgid ""
537
- "Payment under review."
538
  msgstr ""
539
 
540
- #: mercadopago/mercadopago-gateway.php:826
541
- msgid ""
542
- "The payment was refused. "
543
- "The customer can try "
544
- "again."
545
  msgstr ""
546
 
547
- #: mercadopago/mercadopago-gateway.php:832
548
- msgid ""
549
- "The payment was refunded "
550
- "to the customer."
551
  msgstr ""
552
 
553
- #: mercadopago/mercadopago-gateway.php:838
554
- msgid ""
555
- "The payment was "
556
- "cancelled."
557
  msgstr ""
558
 
559
- #: mercadopago/mercadopago-gateway.php:843
560
- msgid "Mercado Pago Payment ID"
 
561
  msgstr ""
562
 
563
- #: mercadopago/mercadopago-gateway.php:843
564
- #: mercadopago/mercadopago-gateway.php:848
565
- msgid ""
566
- "The payment is under "
567
- "mediation or it was "
568
- "charged-back."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
569
  msgstr ""
570
 
571
  msgid " as it appears in your card ..."
@@ -619,9 +614,6 @@ msgstr ""
619
  msgid "This payment method did not process the payment."
620
  msgstr ""
621
 
622
- msgid "Ticket"
623
- msgstr ""
624
-
625
  msgid "Mercado Pago - Ticket"
626
  msgstr ""
627
 
@@ -745,7 +737,7 @@ msgstr ""
745
  msgid "to"
746
  msgstr ""
747
 
748
- msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio"
749
  msgstr ""
750
 
751
  msgid " is: "
@@ -770,4 +762,319 @@ msgid "Terms and Conditions of Use"
770
  msgstr ""
771
 
772
  msgid "Payment converted from"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
773
  msgstr ""
1
  # WordPress Blank Pot
2
  # Copyright (C) 2014 ...
3
  # This file is distributed under the GNU General Public License v2 or later.
 
4
  msgid ""
5
  msgstr ""
6
+ "Project-Id-Version: WordPress Blank Pot v1.0.0\n"
7
+ "POT-Creation-Date: 2016-05-23 14:12-0300\n"
 
 
 
8
  "PO-Revision-Date: \n"
9
+ "Language-Team: Product Development <modulos@mercadopago.com>\n"
10
+ "Report-Msgid-Bugs-To: Marcelo Tomio Hama <marcelo.hama@mercadolivre.com>\n"
 
 
 
 
 
 
 
11
  "MIME-Version: 1.0\n"
12
+ "Content-Type: text/plain; charset=UTF-8\n"
13
+ "Content-Transfer-Encoding: 8bit\n"
14
+ "Plural-Forms: nplurals=2; plural=(n > 1);\n"
15
+ "X-Textdomain-Support: yesX-Generator: Poedit 1.6.4\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "X-Poedit-KeywordsList: __;_e;esc_html_e;esc_html_x:1,2c;esc_html__;esc_attr_e;esc_attr_x:1,2c;esc_attr__;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;_x:1,2c;_n:1,2;_n_noop:1,2;__ngettext:1,2;__ngettext_noop:1,2;_c,_nc:4c,1,2\n"
18
+ "X-Poedit-Basepath: \n"
19
+ "X-Generator: Poedit 1.8.7\n"
20
+ "Last-Translator: \n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  "Language: en_US\n"
22
+ "X-Poedit-SearchPath-0: .\n"
 
 
 
23
 
24
  #. Description of the plugin/theme
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."
26
  msgstr ""
27
 
28
+ #: mercadopago-module.php:69
29
+ msgid "Woo Mercado Pago Module depends on the last version of %s to execute!"
 
 
 
 
 
30
  msgstr ""
31
 
32
+ #: mercadopago-module.php:109
33
+ msgid "Basic Checkout"
34
  msgstr ""
35
 
36
+ #: mercadopago-module.php:113
37
+ msgid "Custom Checkout"
38
+ msgstr ""
39
+
40
+ #: mercadopago/mercadopago-custom-gateway.php:48
41
+ msgid "Mercado Pago - Custom Checkout"
42
+ msgstr ""
43
+
44
+ #: mercadopago/mercadopago-custom-gateway.php:51 mercadopago/mercadopago-gateway.php:54
45
+ msgid "This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store."
46
  msgstr ""
47
 
48
+ #: mercadopago/mercadopago-custom-gateway.php:126 mercadopago/mercadopago-custom-gateway.php:791 mercadopago/mercadopago-gateway.php:125
49
+ #: mercadopago/mercadopago-gateway.php:716
50
  msgid "Argentine"
51
  msgstr ""
52
 
53
+ #: mercadopago/mercadopago-custom-gateway.php:127 mercadopago/mercadopago-custom-gateway.php:792 mercadopago/mercadopago-gateway.php:126
54
+ #: mercadopago/mercadopago-gateway.php:717
55
  msgid "Brazil"
56
  msgstr ""
57
 
58
+ #: mercadopago/mercadopago-custom-gateway.php:128 mercadopago/mercadopago-custom-gateway.php:794 mercadopago/mercadopago-gateway.php:127
59
+ #: mercadopago/mercadopago-gateway.php:719
60
  msgid "Chile"
61
  msgstr ""
62
 
63
+ #: mercadopago/mercadopago-custom-gateway.php:129 mercadopago/mercadopago-custom-gateway.php:793 mercadopago/mercadopago-gateway.php:128
64
+ #: mercadopago/mercadopago-gateway.php:718
65
  msgid "Colombia"
66
  msgstr ""
67
 
68
+ #: mercadopago/mercadopago-custom-gateway.php:130 mercadopago/mercadopago-custom-gateway.php:795 mercadopago/mercadopago-gateway.php:129
69
+ #: mercadopago/mercadopago-gateway.php:720
70
  msgid "Mexico"
71
  msgstr ""
72
 
73
+ #: mercadopago/mercadopago-custom-gateway.php:132 mercadopago/mercadopago-gateway.php:130
74
  msgid "or"
75
  msgstr ""
76
 
77
+ #: mercadopago/mercadopago-custom-gateway.php:133 mercadopago/mercadopago-custom-gateway.php:796 mercadopago/mercadopago-gateway.php:131
78
+ #: mercadopago/mercadopago-gateway.php:721
79
  msgid "Venezuela"
80
  msgstr ""
81
 
82
+ #: mercadopago/mercadopago-custom-gateway.php:145 mercadopago/mercadopago-gateway.php:151
83
+ msgid "Your credentials are <strong>valid</strong> for"
 
 
 
 
 
84
  msgstr ""
85
 
86
+ #: mercadopago/mercadopago-custom-gateway.php:151 mercadopago/mercadopago-custom-gateway.php:156 mercadopago/mercadopago-gateway.php:161
87
+ #: mercadopago/mercadopago-gateway.php:170
88
+ msgid "Your credentials are <strong>not valid</strong>!"
 
 
89
  msgstr ""
90
 
91
+ #: mercadopago/mercadopago-custom-gateway.php:169 mercadopago/mercadopago-gateway.php:211
92
+ msgid "Enable/Disable"
 
 
 
 
 
93
  msgstr ""
94
 
95
+ #: mercadopago/mercadopago-custom-gateway.php:171
96
+ msgid "Enable Custom Checkout"
 
 
 
 
97
  msgstr ""
98
 
99
+ #: mercadopago/mercadopago-custom-gateway.php:175 mercadopago/mercadopago-gateway.php:217
100
+ msgid "Mercado Pago Credentials"
 
 
 
 
101
  msgstr ""
102
 
103
+ #: mercadopago/mercadopago-custom-gateway.php:177 mercadopago/mercadopago-gateway.php:219
104
+ msgid "You can obtain your credentials for"
 
 
 
 
105
  msgstr ""
106
 
107
+ #: mercadopago/mercadopago-custom-gateway.php:182
108
+ msgid "Insert your Mercado Pago Public key."
 
 
 
 
109
  msgstr ""
110
 
111
+ #: mercadopago/mercadopago-custom-gateway.php:189
112
+ msgid "Insert your Mercado Pago Access token."
 
 
 
113
  msgstr ""
114
 
115
+ #: mercadopago/mercadopago-custom-gateway.php:194 mercadopago/mercadopago-gateway.php:236
116
+ msgid "Instant Payment Notification (IPN) URL"
117
  msgstr ""
118
 
119
+ #: mercadopago/mercadopago-custom-gateway.php:196 mercadopago/mercadopago-gateway.php:238
120
+ msgid "Your IPN URL to receive instant payment notifications is"
 
 
121
  msgstr ""
122
 
123
+ #: mercadopago/mercadopago-custom-gateway.php:199 mercadopago/mercadopago-gateway.php:241
124
+ msgid "Checkout Options"
 
125
  msgstr ""
126
 
127
+ #: mercadopago/mercadopago-custom-gateway.php:204 mercadopago/mercadopago-gateway.php:246
128
+ msgid "Title"
 
 
129
  msgstr ""
130
 
131
+ #: mercadopago/mercadopago-custom-gateway.php:206 mercadopago/mercadopago-gateway.php:248
132
+ msgid "Title shown to the client in the checkout."
 
133
  msgstr ""
134
 
135
+ #: mercadopago/mercadopago-custom-gateway.php:207 mercadopago/mercadopago-custom-gateway.php:219 mercadopago/mercadopago-gateway.php:249
136
+ msgid "Mercado Pago"
 
 
137
  msgstr ""
138
 
139
+ #: mercadopago/mercadopago-custom-gateway.php:210 mercadopago/mercadopago-gateway.php:252
140
+ msgid "Description"
 
 
141
  msgstr ""
142
 
143
+ #: mercadopago/mercadopago-custom-gateway.php:212 mercadopago/mercadopago-gateway.php:254
144
+ msgid "Description shown to the client in the checkout."
 
 
145
  msgstr ""
146
 
147
+ #: mercadopago/mercadopago-custom-gateway.php:213 mercadopago/mercadopago-gateway.php:255 mercadopago/mercadopago-gateway.php:432
148
+ msgid "Pay with Mercado Pago"
149
  msgstr ""
150
 
151
+ #: mercadopago/mercadopago-custom-gateway.php:216
152
+ msgid "Statement Descriptor"
153
  msgstr ""
154
 
155
+ #: mercadopago/mercadopago-custom-gateway.php:218
156
+ msgid "The description that will be shown in your customer's invoice."
157
  msgstr ""
158
 
159
+ #: mercadopago/mercadopago-custom-gateway.php:222
160
+ msgid "Binary Mode"
 
 
161
  msgstr ""
162
 
163
+ #: mercadopago/mercadopago-custom-gateway.php:224
164
+ msgid "Enable binary mode for checkout status"
 
 
 
165
  msgstr ""
166
 
167
+ #: mercadopago/mercadopago-custom-gateway.php:226
168
+ msgid "When charging a credit card, only [approved] or [reject] status will be taken."
169
  msgstr ""
170
 
171
+ #: mercadopago/mercadopago-custom-gateway.php:229
172
+ msgid "Ticket"
173
  msgstr ""
174
 
175
+ #: mercadopago/mercadopago-custom-gateway.php:231
176
+ msgid "Enable Ticket for Custom Checkout"
 
 
177
  msgstr ""
178
 
179
+ #: mercadopago/mercadopago-custom-gateway.php:233
180
+ msgid "Let your customer pay you with tickets"
181
  msgstr ""
182
 
183
+ #: mercadopago/mercadopago-custom-gateway.php:236 mercadopago/mercadopago-gateway.php:258
184
+ msgid "Store Category"
 
 
185
  msgstr ""
186
 
187
+ #: mercadopago/mercadopago-custom-gateway.php:238 mercadopago/mercadopago-gateway.php:260
188
+ msgid "Define which type of products your store sells."
 
 
189
  msgstr ""
190
 
191
+ #: mercadopago/mercadopago-custom-gateway.php:242 mercadopago/mercadopago-gateway.php:264
192
+ msgid "Store Identificator"
193
  msgstr ""
194
 
195
+ #: mercadopago/mercadopago-custom-gateway.php:244 mercadopago/mercadopago-gateway.php:266
196
+ msgid "Please, inform a prefix to your store."
 
 
 
197
  msgstr ""
198
 
199
+ #: mercadopago/mercadopago-custom-gateway.php:244 mercadopago/mercadopago-gateway.php:266
200
+ msgid "If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same identificators."
201
  msgstr ""
202
 
203
+ #: mercadopago/mercadopago-custom-gateway.php:248 mercadopago/mercadopago-gateway.php:318
204
+ msgid "Test and Debug Options"
 
 
205
  msgstr ""
206
 
207
+ #: mercadopago/mercadopago-custom-gateway.php:253 mercadopago/mercadopago-gateway.php:323
208
+ msgid "Mercado Pago Sandbox"
 
 
 
 
 
 
 
209
  msgstr ""
210
 
211
+ #: mercadopago/mercadopago-custom-gateway.php:255 mercadopago/mercadopago-gateway.php:325
212
+ msgid "Enable Mercado Pago Sandbox"
213
  msgstr ""
214
 
215
+ #: mercadopago/mercadopago-custom-gateway.php:257 mercadopago/mercadopago-gateway.php:327
216
+ msgid "This option allows you to test payments inside a sandbox environment."
 
 
 
 
 
 
 
 
 
 
217
  msgstr ""
218
 
219
+ #: mercadopago/mercadopago-custom-gateway.php:260 mercadopago/mercadopago-gateway.php:330
220
+ msgid "Debug and Log"
221
  msgstr ""
222
 
223
+ #: mercadopago/mercadopago-custom-gateway.php:262 mercadopago/mercadopago-gateway.php:332
224
+ msgid "Enable log"
225
  msgstr ""
226
 
227
+ #: mercadopago/mercadopago-custom-gateway.php:264 mercadopago/mercadopago-gateway.php:334
228
+ msgid "Register event logs of Mercado Pago, such as API requests, in the file"
229
  msgstr ""
230
 
231
+ #: mercadopago/mercadopago-custom-gateway.php:265 mercadopago/mercadopago-gateway.php:335
232
+ msgid "File location: "
233
  msgstr ""
234
 
235
+ #: mercadopago/mercadopago-custom-gateway.php:281 mercadopago/mercadopago-gateway.php:351
236
+ msgid "Please, rate us %s on WordPress.org and give your feedback to help improve this module!"
237
  msgstr ""
238
 
239
+ #: mercadopago/mercadopago-custom-gateway.php:332
240
+ msgid "Payment Method"
241
  msgstr ""
242
 
243
+ #: mercadopago/mercadopago-custom-gateway.php:333
244
+ msgid "Credit card number"
 
 
245
  msgstr ""
246
 
247
+ #: mercadopago/mercadopago-custom-gateway.php:334
248
+ msgid "Expiration month"
 
 
 
249
  msgstr ""
250
 
251
+ #: mercadopago/mercadopago-custom-gateway.php:335
252
+ msgid "Expiration year"
253
  msgstr ""
254
 
255
+ #: mercadopago/mercadopago-custom-gateway.php:336
256
+ msgid "Year"
257
  msgstr ""
258
 
259
+ #: mercadopago/mercadopago-custom-gateway.php:337
260
+ msgid "Month"
261
  msgstr ""
262
 
263
+ #: mercadopago/mercadopago-custom-gateway.php:338
264
+ msgid "Card holder name"
265
  msgstr ""
266
 
267
+ #: mercadopago/mercadopago-custom-gateway.php:339
268
+ msgid "Security code"
269
  msgstr ""
270
 
271
+ #: mercadopago/mercadopago-custom-gateway.php:340
272
+ msgid "Document Type"
 
273
  msgstr ""
274
 
275
+ #: mercadopago/mercadopago-custom-gateway.php:341
276
+ msgid "Document number"
 
277
  msgstr ""
278
 
279
+ #: mercadopago/mercadopago-custom-gateway.php:342
280
+ msgid "Issuer"
 
281
  msgstr ""
282
 
283
+ #: mercadopago/mercadopago-custom-gateway.php:343
284
+ msgid "Installments"
 
 
285
  msgstr ""
286
 
287
+ #: mercadopago/mercadopago-custom-gateway.php:347
288
+ msgid "Parameter cardNumber can not be null/empty"
 
 
 
289
  msgstr ""
290
 
291
+ #: mercadopago/mercadopago-custom-gateway.php:348
292
+ msgid "Invalid Card Number"
293
  msgstr ""
294
 
295
+ #: mercadopago/mercadopago-custom-gateway.php:350 mercadopago/mercadopago-custom-gateway.php:351 mercadopago/mercadopago-custom-gateway.php:352
296
+ #: mercadopago/mercadopago-custom-gateway.php:353
297
+ msgid "Invalid Expiration Date"
298
  msgstr ""
299
 
300
+ #: mercadopago/mercadopago-custom-gateway.php:355
301
+ msgid "Parameter cardholderName can not be null/empty"
 
 
 
 
 
302
  msgstr ""
303
 
304
+ #: mercadopago/mercadopago-custom-gateway.php:356
305
+ msgid "Invalid Card Holder Name"
 
306
  msgstr ""
307
 
308
+ #: mercadopago/mercadopago-custom-gateway.php:358
309
+ msgid "Parameter securityCode can not be null/empty"
 
310
  msgstr ""
311
 
312
+ #: mercadopago/mercadopago-custom-gateway.php:359
313
+ msgid "Invalid Security Code"
 
 
 
 
 
314
  msgstr ""
315
 
316
+ #: mercadopago/mercadopago-custom-gateway.php:361
317
+ msgid "Parameter docType can not be null/empty"
 
 
318
  msgstr ""
319
 
320
+ #: mercadopago/mercadopago-custom-gateway.php:362
321
+ msgid "Invalid Document Type"
 
 
 
 
322
  msgstr ""
323
 
324
+ #: mercadopago/mercadopago-custom-gateway.php:364
325
+ msgid "Parameter docNumber can not be null/empty"
 
 
 
 
 
326
  msgstr ""
327
 
328
+ #: mercadopago/mercadopago-custom-gateway.php:365
329
+ msgid "Invalid Document Number"
330
+ msgstr ""
331
+
332
+ #: mercadopago/mercadopago-custom-gateway.php:367
333
+ msgid "The parameter cardholder.document.subtype can not be null or empty"
334
+ msgstr ""
335
+
336
+ #: mercadopago/mercadopago-custom-gateway.php:368
337
+ msgid "Invalid Document Sub Type"
338
+ msgstr ""
339
+
340
+ #: mercadopago/mercadopago-custom-gateway.php:370
341
+ msgid "Parameter cardIssuerId can not be null/empty"
342
+ msgstr ""
343
+
344
+ #: mercadopago/mercadopago-custom-gateway.php:402 mercadopago/mercadopago-custom-gateway.php:943 mercadopago/mercadopago-gateway.php:869
345
+ msgid "Payment approved."
346
+ msgstr ""
347
+
348
+ #: mercadopago/mercadopago-custom-gateway.php:416 mercadopago/mercadopago-custom-gateway.php:805
349
+ msgid "Your payment is under review. In less than 1h, you should be notified by email."
350
+ msgstr ""
351
+
352
+ #: mercadopago/mercadopago-custom-gateway.php:418
353
+ msgid "Check your order resume"
354
+ msgstr ""
355
+
356
+ #: mercadopago/mercadopago-custom-gateway.php:431
357
+ msgid "Your payment was refused. You can try again."
358
+ msgstr ""
359
+
360
+ #: mercadopago/mercadopago-custom-gateway.php:435 mercadopago/mercadopago-custom-gateway.php:819 mercadopago/mercadopago-gateway.php:460
361
  msgid "Click to try again"
362
  msgstr ""
363
 
364
+ #: mercadopago/mercadopago-custom-gateway.php:455
365
+ msgid "A problem was occurred when processing your payment. Are you sure you have correctly filled all information in the checkout form?"
 
 
366
  msgstr ""
367
 
368
+ #: mercadopago/mercadopago-custom-gateway.php:544
369
+ msgid "Shipping"
 
 
 
 
370
  msgstr ""
371
 
372
+ #: mercadopago/mercadopago-custom-gateway.php:545
373
+ msgid "Shipping service used by store"
374
+ msgstr ""
375
+
376
+ #: mercadopago/mercadopago-custom-gateway.php:721 mercadopago/mercadopago-gateway.php:649
377
+ msgid "WooCommerce &gt; System Status &gt; Logs"
378
  msgstr ""
379
 
380
+ #: mercadopago/mercadopago-custom-gateway.php:766 mercadopago/mercadopago-custom-gateway.php:779 mercadopago/mercadopago-gateway.php:694
381
+ #: mercadopago/mercadopago-gateway.php:705
382
+ msgid "Mercado Pago is Inactive"
383
+ msgstr ""
384
+
385
+ #: mercadopago/mercadopago-custom-gateway.php:769
386
+ msgid "Your Mercado Pago credentials Public Key/Access Token appears to be misconfigured."
387
+ msgstr ""
388
+
389
+ #: mercadopago/mercadopago-custom-gateway.php:771 mercadopago/mercadopago-gateway.php:698
390
+ msgid "Click here and configure!"
391
+ msgstr ""
392
+
393
+ #: mercadopago/mercadopago-custom-gateway.php:782 mercadopago/mercadopago-gateway.php:708
394
  msgid "The currency"
395
  msgstr ""
396
 
397
+ #: mercadopago/mercadopago-custom-gateway.php:783 mercadopago/mercadopago-gateway.php:708
398
+ msgid "is not supported. Supported currencies are: ARS, BRL, CLP, COP, MXN, VEF."
 
 
 
 
399
  msgstr ""
400
 
401
+ #: mercadopago/mercadopago-custom-gateway.php:797
402
+ msgid "Peru"
403
  msgstr ""
404
 
405
+ #: mercadopago/mercadopago-custom-gateway.php:809
406
+ msgid "Click to check your order"
 
 
407
  msgstr ""
408
 
409
+ #: mercadopago/mercadopago-custom-gateway.php:814 mercadopago/mercadopago-gateway.php:457
410
+ msgid "An error occurred when proccessing your payment. Please try again or contact us for assistence."
411
+ msgstr ""
412
+
413
+ #: mercadopago/mercadopago-custom-gateway.php:816
414
+ msgid "Reason is: "
415
  msgstr ""
416
 
417
+ #: mercadopago/mercadopago-custom-gateway.php:849 mercadopago/mercadopago-gateway.php:748
418
+ msgid "Mercado Pago Request Failure"
419
+ msgstr ""
420
+
421
+ #: mercadopago/mercadopago-custom-gateway.php:918 mercadopago/mercadopago-gateway.php:822
422
  msgid "Payer email"
423
  msgstr ""
424
 
425
+ #: mercadopago/mercadopago-custom-gateway.php:926 mercadopago/mercadopago-gateway.php:829
426
  msgid "Payment type"
427
  msgstr ""
428
 
429
+ #: mercadopago/mercadopago-custom-gateway.php:934 mercadopago/mercadopago-gateway.php:841
430
+ msgid "Mercado Pago Payment ID"
431
  msgstr ""
432
 
433
+ #: mercadopago/mercadopago-custom-gateway.php:950 mercadopago/mercadopago-gateway.php:875
434
+ msgid "Customer haven't paid yet."
 
 
435
  msgstr ""
436
 
437
+ #: mercadopago/mercadopago-custom-gateway.php:957 mercadopago/mercadopago-gateway.php:881
438
+ msgid "Payment under review."
 
439
  msgstr ""
440
 
441
+ #: mercadopago/mercadopago-custom-gateway.php:964 mercadopago/mercadopago-gateway.php:887
442
+ msgid "The payment was refused. The customer can try again."
 
 
 
443
  msgstr ""
444
 
445
+ #: mercadopago/mercadopago-custom-gateway.php:971 mercadopago/mercadopago-gateway.php:893
446
+ msgid "The payment was refunded to the customer."
 
 
447
  msgstr ""
448
 
449
+ #: mercadopago/mercadopago-custom-gateway.php:978 mercadopago/mercadopago-gateway.php:899
450
+ msgid "The payment was cancelled."
 
 
451
  msgstr ""
452
 
453
+ #: mercadopago/mercadopago-custom-gateway.php:984 mercadopago/mercadopago-custom-gateway.php:990 mercadopago/mercadopago-gateway.php:904
454
+ #: mercadopago/mercadopago-gateway.php:909
455
+ msgid "The payment is under mediation or it was charged-back."
456
  msgstr ""
457
 
458
+ #: mercadopago/mercadopago-gateway.php:51
459
+ msgid "Mercado Pago - Basic Checkout"
460
+ msgstr ""
461
+
462
+ #: mercadopago/mercadopago-gateway.php:148
463
+ msgid "Select the payment methods that you <strong>don't</strong> want to receive with Mercado Pago."
464
+ msgstr ""
465
+
466
+ #: mercadopago/mercadopago-gateway.php:158 mercadopago/mercadopago-gateway.php:167
467
+ msgid "Configure your Client_id and Client_secret to have access to more options."
468
+ msgstr ""
469
+
470
+ #: mercadopago/mercadopago-gateway.php:184 mercadopago/mercadopago-gateway.php:192 mercadopago/mercadopago-gateway.php:202
471
+ msgid "This field should be an integer."
472
+ msgstr ""
473
+
474
+ #: mercadopago/mercadopago-gateway.php:187
475
+ msgid "If your integration method is iFrame, please inform the payment iFrame width."
476
+ msgstr ""
477
+
478
+ #: mercadopago/mercadopago-gateway.php:195
479
+ msgid "If your integration method is iFrame, please inform the payment iFrame height."
480
+ msgstr ""
481
+
482
+ #: mercadopago/mercadopago-gateway.php:205
483
+ msgid "Select the max number of installments for your customers."
484
+ msgstr ""
485
+
486
+ #: mercadopago/mercadopago-gateway.php:213
487
+ msgid "Enable Basic Checkout"
488
+ msgstr ""
489
+
490
+ #: mercadopago/mercadopago-gateway.php:224
491
+ msgid "Insert your Mercado Pago Client_id."
492
+ msgstr ""
493
+
494
+ #: mercadopago/mercadopago-gateway.php:231
495
+ msgid "Insert your Mercado Pago Client_secret."
496
+ msgstr ""
497
+
498
+ #: mercadopago/mercadopago-gateway.php:270
499
+ msgid "Integration Method"
500
+ msgstr ""
501
+
502
+ #: mercadopago/mercadopago-gateway.php:272
503
+ msgid "Select how your clients should interact with Mercado Pago. Modal Window (inside your store), Redirect (Client is redirected to Mercado Pago), or iFrame (an internal window is embedded to the page layout)."
504
+ msgstr ""
505
+
506
+ #: mercadopago/mercadopago-gateway.php:275
507
+ msgid "iFrame"
508
+ msgstr ""
509
+
510
+ #: mercadopago/mercadopago-gateway.php:276
511
+ msgid "Modal Window"
512
+ msgstr ""
513
+
514
+ #: mercadopago/mercadopago-gateway.php:277
515
+ msgid "Redirect"
516
+ msgstr ""
517
+
518
+ #: mercadopago/mercadopago-gateway.php:281
519
+ msgid "iFrame Width"
520
+ msgstr ""
521
+
522
+ #: mercadopago/mercadopago-gateway.php:287
523
+ msgid "iFrame Height"
524
+ msgstr ""
525
+
526
+ #: mercadopago/mercadopago-gateway.php:293
527
+ msgid "Auto Return"
528
+ msgstr ""
529
+
530
+ #: mercadopago/mercadopago-gateway.php:295
531
+ msgid "Automatic Return After Payment"
532
+ msgstr ""
533
+
534
+ #: mercadopago/mercadopago-gateway.php:297
535
+ msgid "After the payment, client is automatically redirected."
536
+ msgstr ""
537
+
538
+ #: mercadopago/mercadopago-gateway.php:300
539
+ msgid "Payment Options"
540
+ msgstr ""
541
+
542
+ #: mercadopago/mercadopago-gateway.php:305
543
+ msgid "Max installments"
544
+ msgstr ""
545
+
546
+ #: mercadopago/mercadopago-gateway.php:311
547
+ msgid "Exclude Payment Methods"
548
+ msgstr ""
549
+
550
+ #: mercadopago/mercadopago-gateway.php:428
551
+ msgid "Thank you for your order. Please, proceed with your payment clicking in the bellow button."
552
+ msgstr ""
553
+
554
+ #: mercadopago/mercadopago-gateway.php:436
555
+ msgid "Cancel order &amp; Clear cart"
556
+ msgstr ""
557
+
558
+ #: mercadopago/mercadopago-gateway.php:446
559
+ msgid "Thank you for your order. Proceed with your payment completing the following information."
560
+ msgstr ""
561
+
562
+ #: mercadopago/mercadopago-gateway.php:697
563
+ msgid "Your Mercado Pago credentials Client_id/Client_secret appears to be misconfigured."
564
  msgstr ""
565
 
566
  msgid " as it appears in your card ..."
614
  msgid "This payment method did not process the payment."
615
  msgstr ""
616
 
 
 
 
617
  msgid "Mercado Pago - Ticket"
618
  msgstr ""
619
 
737
  msgid "to"
738
  msgstr ""
739
 
740
+ msgid "If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio."
741
  msgstr ""
742
 
743
  msgid " is: "
762
  msgstr ""
763
 
764
  msgid "Payment converted from"
765
+ msgstr ""
766
+
767
+ msgid "Rate Us"
768
+ msgstr ""
769
+
770
+ msgid "Report Issue"
771
+ msgstr ""
772
+
773
+ msgid "Two Cards Mode"
774
+ msgstr ""
775
+
776
+ msgid "Payments with Two Cards"
777
+ msgstr ""
778
+
779
+ msgid "Your customer will be able to use two different cards to pay the order."
780
+ msgstr ""
781
+
782
+ msgid "Your Mercado Pago credentials Access Token appears to be misconfigured."
783
+ msgstr ""
784
+
785
+ msgid "Cancel Order"
786
+ msgstr ""
787
+
788
+ msgid "Refund Order"
789
+ msgstr ""
790
+
791
+ msgid "Back URL Options"
792
+ msgstr ""
793
+
794
+ msgid "Sucess URL"
795
+ msgstr ""
796
+
797
+ msgid "Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page."
798
+ msgstr ""
799
+
800
+ msgid "Failure URL"
801
+ msgstr ""
802
+
803
+ msgid "Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page."
804
+ msgstr ""
805
+
806
+ msgid "Pending URL"
807
+ msgstr ""
808
+
809
+ msgid "Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page."
810
+ msgstr ""
811
+
812
+ msgid "Stock Reduce"
813
+ msgstr ""
814
+
815
+ msgid "Reduce Stock in Order Generation"
816
+ msgstr ""
817
+
818
+ msgid "Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval."
819
+ msgstr ""
820
+
821
+ msgid "Recurrent Product"
822
+ msgstr ""
823
+
824
+ msgid "Frequency"
825
+ msgstr ""
826
+
827
+ msgid "Amount of time (in days or months) for the execution of the next payment."
828
+ msgstr ""
829
+
830
+ msgid "Start date"
831
+ msgstr ""
832
+
833
+ msgid "First payment date (effective debit). Defaults to now if blank."
834
+ msgstr ""
835
+
836
+ msgid "End date"
837
+ msgstr ""
838
+
839
+ msgid "Deadline to generate new charges. Defaults to never if blank."
840
+ msgstr ""
841
+
842
+ msgid "Days"
843
+ msgstr ""
844
+
845
+ msgid "Months"
846
+ msgstr ""
847
+
848
+ msgid "Indicates the period of time."
849
+ msgstr ""
850
+
851
+ msgid "The amount to charge the payer each period. Should be informed including taxes and discounts."
852
+ msgstr ""
853
+
854
+ msgid "Amount charged"
855
+ msgstr ""
856
+
857
+ msgid "Uruguay"
858
+ msgstr ""
859
+
860
+ msgid "Frequency type"
861
+ msgstr ""
862
+
863
+ msgid "Transaction amount"
864
+ msgstr ""
865
+
866
+ msgid "A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders."
867
+ msgstr ""
868
+
869
+ msgid "Subscription"
870
+ msgstr ""
871
+
872
+ msgid "Enable Subscription"
873
+ msgstr ""
874
+
875
+ msgid "Subscription is Inactive"
876
+ msgstr ""
877
+
878
+ msgid "Subscribe with Mercado Pago"
879
+ msgstr ""
880
+
881
+ msgid "For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:"
882
+ msgstr ""
883
+
884
+ msgid "Discount by Gateway"
885
+ msgstr ""
886
+
887
+ msgid "Give a percentual discount for your customers if they use this payment gateway."
888
+ msgstr ""
889
+
890
+ msgid "This field should be an integer greater or equal 0 and smaller than 100."
891
+ msgstr ""
892
+
893
+ msgid "Discount Of"
894
+ msgstr ""
895
+
896
+ msgid "Mercado Pago Subscription"
897
+ msgstr ""
898
+
899
+ msgid "Payment ID:"
900
+ msgstr ""
901
+
902
+ msgid "Amount:"
903
+ msgstr ""
904
+
905
+ msgid "This operation could not be completed."
906
+ msgstr ""
907
+
908
+ msgid "Operation successfully completed."
909
+ msgstr ""
910
+
911
+ msgid "Refund Payment"
912
+ msgstr ""
913
+
914
+ msgid "Cancel Payment"
915
+ msgstr ""
916
+
917
+ msgid "Mercado Pago - Subscription"
918
+ msgstr ""
919
+
920
+ msgid "Mercado Envios is a shipping method available only for payments with Mercado Pago."
921
+ msgstr ""
922
+
923
+ msgid "Free Shipping"
924
+ msgstr ""
925
+
926
+ msgid "Day"
927
+ msgstr ""
928
+
929
+ msgid "Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module."
930
+ msgstr ""
931
+
932
+ msgid "Mercado Envios"
933
+ msgstr ""
934
+
935
+ msgid "This controls the title which the user sees during checkout."
936
+ msgstr ""
937
+
938
+ msgid "Enable free shipping for this shipping method"
939
+ msgstr ""
940
+
941
+ msgid "Delivery Time"
942
+ msgstr ""
943
+
944
+ msgid "Show estimated delivery time"
945
+ msgstr ""
946
+
947
+ msgid "Display the estimated delivery time in working days."
948
+ msgstr ""
949
+
950
+ msgid "Buyer initiates complaint and requested a refund."
951
+ msgstr ""
952
+
953
+ msgid "In return to sender"
954
+ msgstr ""
955
+
956
+ msgid "Missing recipient for delivery"
957
+ msgstr ""
958
+
959
+ msgid "Sending the delayed path"
960
+ msgstr ""
961
+
962
+ msgid "Unsuccessful"
963
+ msgstr ""
964
+
965
+ msgid "Tag printed"
966
+ msgstr ""
967
+
968
+ msgid "Tag ready to print"
969
+ msgstr ""
970
+
971
+ msgid "Tracking code:"
972
+ msgstr ""
973
+
974
+ msgid "Ticket:"
975
+ msgstr ""
976
+
977
+ msgid "Shipping is pending"
978
+ msgstr ""
979
+
980
+ msgid "Tutorial"
981
+ msgstr ""
982
+
983
+ msgid "Discount Of "
984
+ msgstr ""
985
+
986
+ msgid "Make this product a subscription."
987
+ msgstr ""
988
+
989
+ msgid "Order"
990
+ msgstr ""
991
+
992
+ msgid "Mercado Envios Tracking ID"
993
+ msgstr ""
994
+
995
+ msgid "Hello,"
996
+ msgstr ""
997
+
998
+ msgid "Your order"
999
+ msgstr ""
1000
+
1001
+ msgid "made in"
1002
+ msgstr ""
1003
+
1004
+ msgid "used Mercado Envios as its shipment method."
1005
+ msgstr ""
1006
+
1007
+ msgid "You can track it with the following Tracking ID:"
1008
+ msgstr ""
1009
+
1010
+ msgid "Best regards."
1011
+ msgstr ""
1012
+
1013
+ msgid "SELECT..."
1014
+ msgstr ""
1015
+
1016
+ msgid "NAME"
1017
+ msgstr ""
1018
+
1019
+ msgid "SURNAME"
1020
+ msgstr ""
1021
+
1022
+ msgid "DOCUMENT"
1023
+ msgstr ""
1024
+
1025
+ msgid "ADDRESS"
1026
+ msgstr ""
1027
+
1028
+ msgid "NUMBER"
1029
+ msgstr ""
1030
+
1031
+ msgid "CITY"
1032
+ msgstr ""
1033
+
1034
+ msgid "STATE"
1035
+ msgstr ""
1036
+
1037
+ msgid "ZIP"
1038
+ msgstr ""
1039
+
1040
+ msgid "You must inform you NAME"
1041
+ msgstr ""
1042
+
1043
+ msgid "You must inform your SURNAME"
1044
+ msgstr ""
1045
+
1046
+ msgid "You must inform your DOCUMENT"
1047
+ msgstr ""
1048
+
1049
+ msgid "You must inform your ADDRESS"
1050
+ msgstr ""
1051
+
1052
+ msgid "You must inform your ADDRESS NUMBER"
1053
+ msgstr ""
1054
+
1055
+ msgid "You must inform your CITY"
1056
+ msgstr ""
1057
+
1058
+ msgid "You must inform your STATE"
1059
+ msgstr ""
1060
+
1061
+ msgid "You must inform your ZIP"
1062
+ msgstr ""
1063
+
1064
+ msgid "Your PHP version is OK."
1065
+ msgstr ""
1066
+
1067
+ msgid "Your PHP version do not support this module. You have %s, minimal required is %s."
1068
+ msgstr ""
1069
+
1070
+ msgid "cURL is installed."
1071
+ msgstr ""
1072
+
1073
+ msgid "cURL is not installed."
1074
+ msgstr ""
1075
+
1076
+ msgid "SSL is missing in your site."
1077
+ msgstr ""
1078
+
1079
+ msgid "Your site has SSL enabled."
1080
  msgstr ""
mercadopago-module.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Plugin Name: Woo Mercado Pago Module
4
  * Plugin URI: https://github.com/mercadopago/cart-woocommerce
@@ -6,123 +7,537 @@
6
  * Author: Mercado Pago
7
  * Author URI: https://www.mercadopago.com.br/developers/
8
  * Developer: Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
9
- * Copyright: Copyright(c) MercadoPago [http://www.mercadopago.com]
10
- * Version: 2.1.0
11
- * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
12
  * Text Domain: woocommerce-mercadopago-module
13
  * Domain Path: /languages/
14
  */
15
 
16
- /**
17
- * Implementation references:
18
- * 1. https://docs.woothemes.com/document/payment-gateway-api/
19
- * 2. https://www.mercadopago.com.br/developers/en/api-docs/
20
- */
21
-
22
- // Exit if accessed directly
23
- if ( !defined( 'ABSPATH' ) ) {
24
  exit;
25
  }
26
 
27
- // Check if class is already loaded
28
- if ( !class_exists( 'WC_WooMercadoPago_Module' ) ) :
29
 
30
- // WooCommerce MercadoPago Module main class
31
- class WC_WooMercadoPago_Module {
32
 
33
- // Singleton design pattern
34
- protected static $instance = null;
35
- public static function initMercadoPagoGatewayClass() {
36
- if ( null == self::$instance ) {
37
- self::$instance = new self;
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
- return self::$instance;
40
- }
41
 
42
- // Class constructor
43
- private function __construct() {
44
- // load plugin text domain
45
- add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
46
- // verify if WooCommerce is already installed
47
- if ( class_exists( 'WC_Payment_Gateway' ) ) {
48
- include_once 'mercadopago/mercadopago-gateway.php';
49
- include_once 'mercadopago/mercadopago-custom-gateway.php';
50
- include_once 'mercadopago/mercadopago-ticket-gateway.php';
51
- add_filter( 'woocommerce_payment_gateways', array( $this, 'addGateway' ) );
52
- add_filter( 'woomercadopago_settings_link_' . plugin_basename( __FILE__ ), array( $this, 'woomercadopago_settings_link' ) );
53
- } else {
54
- add_action( 'admin_notices', array( $this, 'notifyWooCommerceMiss' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
- }
57
-
58
- // As well as defining your class, you need to also tell WooCommerce (WC) that
59
- // it exists. Do this by filtering woocommerce_payment_gateways.
60
- public function addGateway( $methods ) {
61
- $methods[] = 'WC_WooMercadoPago_Gateway';
62
- $methods[] = 'WC_WooMercadoPagoCustom_Gateway';
63
- $methods[] = 'WC_WooMercadoPagoTicket_Gateway';
64
- return $methods;
65
- }
66
-
67
- // Places a warning error to notify user that WooCommerce is missing
68
- public function notifyWooCommerceMiss() {
69
- echo
70
- '<div class="error"><p>' . sprintf(
71
- __( 'Woo Mercado Pago Module depends on the last version of %s to execute!', 'woocommerce-mercadopago-module' ),
72
- '<a href="http://wordpress.org/extend/plugins/woocommerce/">' . 'WooCommerce' . '</a>'
73
- ) .
74
- '</p></div>';
75
- }
76
-
77
- // Multi-language plugin
78
- public function load_plugin_textdomain() {
79
- $locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-mercadopago-module' );
80
- load_textdomain(
81
- 'woocommerce-mercadopago-module',
82
- trailingslashit(WP_LANG_DIR ) . 'woocommerce-mercadopago-module/woocommerce-mercadopago-module-' . $locale . '.mo'
83
- );
84
- load_plugin_textdomain( 'woocommerce-mercadopago-module', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
85
- }
86
-
87
- public static function woocommerceInstance() {
88
- if ( function_exists( 'WC' ) ) {
89
- return WC();
90
- } else {
91
- global $woocommerce;
92
- return $woocommerce;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  }
95
-
96
- public static function getTemplatesPath() {
97
- return plugin_dir_path( __FILE__ ) . 'templates/';
 
 
 
 
 
 
98
  }
99
-
100
- }
101
-
102
- // Payment gateways should be created as additional plugins that hook into WooCommerce.
103
- // Inside the plugin, you need to create a class after plugins are loaded
104
- add_action( 'plugins_loaded', array( 'WC_WooMercadoPago_Module', 'initMercadoPagoGatewayClass' ), 0 );
105
-
106
- // Add settings link on plugin page
107
- function woomercadopago_settings_link( $links ) {
108
- $plugin_links = array();
109
- $plugin_links[] = '<a href="' . esc_url( admin_url(
110
- 'admin.php?page=wc-settings&tab=checkout&section=WC_WooMercadoPago_Gateway' ) ) . '">' .
111
- __( 'Basic Checkout', 'woocommerce-mercadopago-module' ) .
112
- '</a>';
113
- $plugin_links[] = '<a href="' . esc_url( admin_url(
114
- 'admin.php?page=wc-settings&tab=checkout&section=WC_WooMercadoPagoCustom_Gateway' ) ) . '">' .
115
- __( 'Custom Checkout', 'woocommerce-mercadopago-module' ) .
116
- '</a>';
117
- $plugin_links[] = '<a href="' . esc_url( admin_url(
118
- 'admin.php?page=wc-settings&tab=checkout&section=WC_WooMercadoPagoTicket_Gateway' ) ) . '">' .
119
- __( 'Ticket', 'woocommerce-mercadopago-module' ) .
120
- '</a>';
121
- return array_merge( $plugin_links, $links );
122
- }
123
- $plugin = plugin_basename( __FILE__ );
124
- add_filter( "plugin_action_links_$plugin", 'woomercadopago_settings_link' );
125
 
126
- endif;
 
 
 
 
 
127
 
128
- ?>
1
  <?php
2
+
3
  /**
4
  * Plugin Name: Woo Mercado Pago Module
5
  * Plugin URI: https://github.com/mercadopago/cart-woocommerce
7
  * Author: Mercado Pago
8
  * Author URI: https://www.mercadopago.com.br/developers/
9
  * Developer: Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
10
+ * Copyright: Copyright(c) MercadoPago [https://www.mercadopago.com]
11
+ * Version: 2.2.13
12
+ * License: https://www.gnu.org/licenses/gpl.html GPL version 2 or higher
13
  * Text Domain: woocommerce-mercadopago-module
14
  * Domain Path: /languages/
15
  */
16
 
17
+ // Exit if accessed directly.
18
+ if ( ! defined( 'ABSPATH' ) ) {
 
 
 
 
 
 
19
  exit;
20
  }
21
 
22
+ require_once dirname( __FILE__ ) . '/mercadopago/sdk/lib/mercadopago.php';
 
23
 
24
+ // Load module class if it wasn't loaded yet.
25
+ if ( ! class_exists( 'WC_WooMercadoPago_Module' ) ) :
26
 
27
+ /**
28
+ * Summary: WooCommerce MercadoPago Module main class.
29
+ * Description: Used as a kind of manager to enable/disable each Mercado Pago gateway.
30
+ * @since 1.0.0
31
+ */
32
+ class WC_WooMercadoPago_Module {
33
+
34
+ const VERSION = '2.2.13';
35
+ const MIN_PHP = 5.6;
36
+
37
+ // Singleton design pattern
38
+ protected static $instance = null;
39
+ public static function init_mercado_pago_gateway_class() {
40
+ if ( null == self::$instance ) {
41
+ self::$instance = new self;
42
+ }
43
+ return self::$instance;
44
  }
 
 
45
 
46
+ // Class constructor.
47
+ private function __construct() {
48
+
49
+ add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
50
+
51
+ // Verify if WooCommerce is already installed.
52
+ if ( class_exists( 'WC_Payment_Gateway' ) ) {
53
+
54
+ // Gateways
55
+ include_once dirname( __FILE__ ) . '/mercadopago/mercadopago-gateway.php';
56
+ include_once dirname( __FILE__ ) . '/mercadopago/mercadopago-custom-gateway.php';
57
+ include_once dirname( __FILE__ ) . '/mercadopago/mercadopago-ticket-gateway.php';
58
+ include_once dirname( __FILE__ ) . '/mercadopago/mercadopago-subscription-gateway.php';
59
+
60
+ include_once dirname( __FILE__ ) . '/mercadopago/class-wc-product-mp_recurrent.php';
61
+
62
+ // Shipping.
63
+ include_once dirname( __FILE__ ) . '/shipment/abstract-wc-mercadoenvios-shipping.php';
64
+ include_once dirname( __FILE__ ) . '/shipment/class-wc-mercadoenvios-shipping-normal.php';
65
+ include_once dirname( __FILE__ ) . '/shipment/class-wc-mercadoenvios-shipping-express.php';
66
+ include_once dirname( __FILE__ ) . '/shipment/class-wc-mercadoenvios-package.php';
67
+
68
+ add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) );
69
+ add_filter(
70
+ 'plugin_action_links_' . plugin_basename( __FILE__ ),
71
+ array( $this, 'woomercadopago_settings_link' ) );
72
+
73
+ add_filter( 'woocommerce_shipping_methods', array( $this, 'add_shipping' ) );
74
+ add_filter(
75
+ 'woocommerce_available_payment_gateways',
76
+ array( $this, 'filter_payment_method_by_shipping' )
77
+ );
78
+
79
+ } else {
80
+ add_action( 'admin_notices', array( $this, 'notify_woocommerce_miss' ) );
81
+ }
82
+
83
+ if ( is_admin() ) {
84
+ $this->admin_includes();
85
+ }
86
+
87
  }
88
+
89
+ /**
90
+ * Admin includes.
91
+ */
92
+ private function admin_includes() {
93
+ include_once dirname( __FILE__ ) . '/admin/class-wc-mercadoenvios-admin-orders.php';
94
+ }
95
+
96
+ // As well as defining your class, you need to also tell WooCommerce (WC) that
97
+ // it exists. Do this by filtering woocommerce_payment_gateways.
98
+ public function add_gateway( $methods ) {
99
+ $methods[] = 'WC_WooMercadoPago_Gateway';
100
+ $methods[] = 'WC_WooMercadoPagoCustom_Gateway';
101
+ $methods[] = 'WC_WooMercadoPagoTicket_Gateway';
102
+ $methods[] = 'WC_WooMercadoPagoSubscription_Gateway';
103
+ return $methods;
104
+ }
105
+
106
+ // woocommerce_shipping_methods
107
+ public function add_shipping( $methods ) {
108
+ $methods['mercadoenvios-normal'] = 'WC_MercadoEnvios_Shipping_Normal';
109
+ $methods['mercadoenvios-express'] = 'WC_MercadoEnvios_Shipping_Express';
110
+ return $methods;
111
+ }
112
+
113
+ // When selected Mercado Envios the payment can be made only with Mercado Pago Basic (Standard)
114
+ public function filter_payment_method_by_shipping( $methods ) {
115
+
116
+ $session = WC()->session;
117
+ if ( ! isset( $session ) ) {
118
+ return $methods;
119
+ }
120
+
121
+ $chosen_methods = $session->get( 'chosen_shipping_methods' );
122
+ $chosen_shipping = $chosen_methods[0];
123
+
124
+ // Check shipping methods is a Mercado Envios.
125
+ if ( strpos( $chosen_shipping, 'mercadoenvios-normal' ) !== false || strpos( $chosen_shipping, 'mercadoenvios-express' ) !== false ) {
126
+ $new_array = array();
127
+ foreach ( $methods as $payment_method => $payment_method_object ) {
128
+ if ( $payment_method == 'woocommerce-mercadopago-module' ) {
129
+ $new_array['woocommerce-mercadopago-module'] = $payment_method_object;
130
+ }
131
+ }
132
+ // Return new array shipping methods (only Mercado Pago Basic).
133
+ return $new_array;
134
+ }
135
+
136
+ // Return all shipping methods.
137
+ return $methods;
138
+ }
139
+
140
+ /**
141
+ * Summary: Places a warning error to notify user that WooCommerce is missing.
142
+ * Description: Places a warning error to notify user that WooCommerce is missing.
143
+ */
144
+ public function notify_woocommerce_miss() {
145
+ echo
146
+ '<div class="error"><p>' .
147
+ sprintf(
148
+ __( 'Woo Mercado Pago Module depends on the last version of %s to execute!', 'woocommerce-mercadopago-module' ),
149
+ '<a href="https://wordpress.org/extend/plugins/woocommerce/">WooCommerce</a>'
150
+ ) .
151
+ '</p></div>';
152
+ }
153
+
154
+ // Multi-language plugin.
155
+ public function load_plugin_textdomain() {
156
+ $locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-mercadopago-module' );
157
+ $module_root = 'woocommerce-mercadopago-module/woocommerce-mercadopago-module-';
158
+ load_textdomain(
159
+ 'woocommerce-mercadopago-module',
160
+ trailingslashit( WP_LANG_DIR ) . $module_root . $locale . '.mo'
161
+ );
162
+ load_plugin_textdomain(
163
+ 'woocommerce-mercadopago-module',
164
+ false,
165
+ dirname( plugin_basename( __FILE__ ) ) . '/languages/'
166
+ );
167
+ }
168
+
169
+ // Add settings link on plugin page
170
+ public function woomercadopago_settings_link( $links ) {
171
+ $plugin_links = array();
172
+ $plugin_links[] = '<a href="' . esc_url( admin_url(
173
+ 'admin.php?page=wc-settings&tab=checkout&section=WC_WooMercadoPago_Gateway' ) ) .
174
+ '">' . __( 'Basic Checkout', 'woocommerce-mercadopago-module' ) . '</a>';
175
+ $plugin_links[] = '<a href="' . esc_url( admin_url(
176
+ 'admin.php?page=wc-settings&tab=checkout&section=WC_WooMercadoPagoCustom_Gateway' ) ) .
177
+ '">' . __( 'Custom Checkout', 'woocommerce-mercadopago-module' ) . '</a>';
178
+ $plugin_links[] = '<a href="' . esc_url( admin_url(
179
+ 'admin.php?page=wc-settings&tab=checkout&section=WC_WooMercadoPagoTicket_Gateway' ) ) .
180
+ '">' . __( 'Ticket', 'woocommerce-mercadopago-module' ) . '</a>';
181
+ $plugin_links[] = '<a href="' . esc_url( admin_url(
182
+ 'admin.php?page=wc-settings&tab=checkout&section=WC_WooMercadoPagoSubscription_Gateway' ) ) .
183
+ '">' . __( 'Subscription', 'woocommerce-mercadopago-module' ) . '</a>';
184
+ $plugin_links[] = '<br><a target="_blank" href="' .
185
+ 'https://github.com/mercadopago/cart-woocommerce#installation' .
186
+ '">' . __( 'Tutorial', 'woocommerce-mercadopago-module' ) . '</a>';
187
+ $plugin_links[] = '<a target="_blank" href="' .
188
+ 'https://wordpress.org/support/view/plugin-reviews/woo-mercado-pago-module?filter=5#postform' .
189
+ '">' . sprintf(
190
+ __( 'Rate Us', 'woocommerce-mercadopago-module' ) . ' %s',
191
+ '&#9733;&#9733;&#9733;&#9733;&#9733;'
192
+ ) . '</a>';
193
+ $plugin_links[] = '<a target="_blank" href="' .
194
+ 'https://wordpress.org/support/plugin/woo-mercado-pago-module#postform' .
195
+ '">' . __( 'Report Issue', 'woocommerce-mercadopago-module' ) . '</a>';
196
+ return array_merge($plugin_links, $links);
197
+ }
198
+
199
+ /**
200
+ * Summary: Get store categories from Mercado Pago.
201
+ * Description: Trigger API to get available categories and proper description.
202
+ * @return an array with found categories and a description for its selector title.
203
+ */
204
+ public static function get_categories() {
205
+
206
+ $store_categories_id = array();
207
+ $store_categories_description = array();
208
+
209
+ // Get Mercado Pago store categories.
210
+ $categories = MPRestClient::get(
211
+ array( 'uri' => '/item_categories' ),
212
+ WC_WooMercadoPago_Module::get_module_version()
213
+ );
214
+ foreach ( $categories['response'] as $category ) {
215
+ array_push(
216
+ $store_categories_id, str_replace( '_', ' ', $category['id'] )
217
+ );
218
+ array_push(
219
+ $store_categories_description, str_replace( '_', ' ', $category['description'] )
220
+ );
221
+ }
222
+
223
+ return array(
224
+ 'store_categories_id' => $store_categories_id,
225
+ 'store_categories_description' => $store_categories_description
226
+ );
227
+
228
  }
229
+
230
+ /**
231
+ * Summary: Get the rate of conversion between two currencies.
232
+ * Description: The currencies are the one used in WooCommerce and the one used in $site_id.
233
+ * @return a float that is the rate of conversion.
234
+ */
235
+ public static function get_conversion_rate( $used_currency ) {
236
+ $currency_obj = MPRestClient::get(
237
+ array( 'uri' => '/currency_conversions/search?' .
238
+ 'from=' . get_woocommerce_currency() .
239
+ '&to=' . $used_currency
240
+ ),
241
+ WC_WooMercadoPago_Module::get_module_version()
242
+ );
243
+ if ( isset( $currency_obj['response'] ) ) {
244
+ $currency_obj = $currency_obj['response'];
245
+ if ( isset( $currency_obj['ratio'] ) ) {
246
+ return ( (float) $currency_obj['ratio'] );
247
+ }
248
+ }
249
+ return -1;
250
+ }
251
+
252
+ // Get WooCommerce instance
253
+ public static function woocommerce_instance() {
254
+ if ( function_exists( 'WC' ) ) {
255
+ return WC();
256
+ } else {
257
+ global $woocommerce;
258
+ return $woocommerce;
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Summary: Find template's folder.
264
+ * Description: Find template's folder.
265
+ * @return a string that identifies the path.
266
+ */
267
+ public static function get_templates_path() {
268
+ return plugin_dir_path( __FILE__ ) . 'templates/';
269
+ }
270
+
271
+ /**
272
+ * Summary: Get module's version.
273
+ * Description: Get module's version.
274
+ * @return a string with the given version.
275
+ */
276
+ public static function get_module_version() {
277
+ return WC_WooMercadoPago_Module::VERSION;
278
+ }
279
+
280
+ /**
281
+ * Summary: Get client id from access token.
282
+ * Description: Get client id from access token.
283
+ * @return the client id.
284
+ */
285
+ public static function get_client_id( $at ) {
286
+ $t = explode ( '-', $at );
287
+ if ( count( $t ) > 0 ) {
288
+ return $t[1];
289
+ }
290
+ return '';
291
+ }
292
+
293
+ /**
294
+ * Summary: Builds up the array for the mp_install table, with info related with checkout.
295
+ * Description: Builds up the array for the mp_install table, with info related with checkout.
296
+ * @return an array with the module informations.
297
+ */
298
+ public static function get_common_settings() {
299
+
300
+ $w = WC_WooMercadoPago_Module::woocommerce_instance();
301
+
302
+ $infra_data = array(
303
+ 'module_version' => WC_WooMercadoPago_Module::VERSION,
304
+ 'platform' => 'WooCommerce',
305
+ 'platform_version' => $w->version,
306
+ 'code_version' => phpversion(),
307
+ 'so_server' => PHP_OS
308
+ );
309
+
310
+ return $infra_data;
311
+
312
+ }
313
+
314
+ /**
315
+ * Summary: Get preference data for a specific country.
316
+ * Description: Get preference data for a specific country.
317
+ * @return an array with sponsor id, country name, banner image for checkout, and currency.
318
+ */
319
+ public static function get_country_config( $site_id ) {
320
+ switch ( $site_id ) {
321
+ case 'MLA':
322
+ return array(
323
+ 'sponsor_id' => 208682286,
324
+ 'country_name' => __( 'Argentine', 'woocommerce-mercadopago-module' ),
325
+ 'checkout_banner' => plugins_url(
326
+ 'images/MLA/standard_mla.jpg',
327
+ __FILE__
328
+ ),
329
+ 'checkout_banner_custom' => plugins_url(
330
+ 'images/MLA/credit_card.png',
331
+ __FILE__
332
+ ),
333
+ 'currency' => 'ARS'
334
+ );
335
+ case 'MLB':
336
+ return array(
337
+ 'sponsor_id' => 208686191,
338
+ 'country_name' => __( 'Brazil', 'woocommerce-mercadopago-module' ),
339
+ 'checkout_banner' => plugins_url(
340
+ 'images/MLB/standard_mlb.jpg',
341
+ __FILE__
342
+ ),
343
+ 'checkout_banner_custom' => plugins_url(
344
+ 'images/MLB/credit_card.png',
345
+ __FILE__
346
+ ),
347
+ 'currency' => 'BRL'
348
+ );
349
+ case 'MCO':
350
+ return array(
351
+ 'sponsor_id' => 208687643,
352
+ 'country_name' => __( 'Colombia', 'woocommerce-mercadopago-module' ),
353
+ 'checkout_banner' => plugins_url(
354
+ 'images/MCO/standard_mco.jpg',
355
+ __FILE__
356
+ ),
357
+ 'checkout_banner_custom' => plugins_url(
358
+ 'images/MCO/credit_card.png',
359
+ __FILE__
360
+ ),
361
+ 'currency' => 'COP'
362
+ );
363
+ case 'MLC':
364
+ return array(
365
+ 'sponsor_id' => 208690789,
366
+ 'country_name' => __( 'Chile', 'woocommerce-mercadopago-module' ),
367
+ 'checkout_banner' => plugins_url(
368
+ 'images/MLC/standard_mlc.gif',
369
+ __FILE__
370
+ ),
371
+ 'checkout_banner_custom' => plugins_url(
372
+ 'images/MLC/credit_card.png',
373
+ __FILE__
374
+ ),
375
+ 'currency' => 'CLP'
376
+ );
377
+ case 'MLM':
378
+ return array(
379
+ 'sponsor_id' => 208692380,
380
+ 'country_name' => __( 'Mexico', 'woocommerce-mercadopago-module' ),
381
+ 'checkout_banner' => plugins_url(
382
+ 'images/MLM/standard_mlm.jpg',
383
+ __FILE__
384
+ ),
385
+ 'checkout_banner_custom' => plugins_url(
386
+ 'images/MLM/credit_card.png',
387
+ __FILE__
388
+ ),
389
+ 'currency' => 'MXN'
390
+ );
391
+ case 'MLV':
392
+ return array(
393
+ 'sponsor_id' => 208692735,
394
+ 'country_name' => __( 'Venezuela', 'woocommerce-mercadopago-module' ),
395
+ 'checkout_banner' => plugins_url(
396
+ 'images/MLV/standard_mlv.jpg',
397
+ __FILE__
398
+ ),
399
+ 'checkout_banner_custom' => plugins_url(
400
+ 'images/MLV/credit_card.png',
401
+ __FILE__
402
+ ),
403
+ 'currency' => 'VEF'
404
+ );
405
+ case 'MPE':
406
+ return array(
407
+ 'sponsor_id' => 216998692,
408
+ 'country_name' => __( 'Peru', 'woocommerce-mercadopago-module' ),
409
+ 'checkout_banner' => plugins_url(
410
+ 'images/MPE/standard_mpe.png',
411
+ __FILE__
412
+ ),
413
+ 'checkout_banner_custom' => plugins_url(
414
+ 'images/MPE/credit_card.png',
415
+ __FILE__
416
+ ),
417
+ 'currency' => 'PEN'
418
+ );
419
+ case 'MLU':
420
+ return array(
421
+ 'sponsor_id' => 243692679,
422
+ 'country_name' => __( 'Uruguay', 'woocommerce-mercadopago-module' ),
423
+ 'checkout_banner' => plugins_url(
424
+ 'images/MLU/standard_mlu.png',
425
+ __FILE__
426
+ ),
427
+ 'checkout_banner_custom' => plugins_url(
428
+ 'images/MLU/credit_card.png',
429
+ __FILE__
430
+ ),
431
+ 'currency' => 'UYU'
432
+ );
433
+ default: // set Argentina as default country
434
+ return array(
435
+ 'sponsor_id' => 208682286,
436
+ 'country_name' => __( 'Argentine', 'woocommerce-mercadopago-module' ),
437
+ 'checkout_banner' => plugins_url(
438
+ 'images/MLA/standard_mla.jpg',
439
+ __FILE__
440
+ ),
441
+ 'checkout_banner_custom' => plugins_url(
442
+ 'images/MLA/credit_card.png',
443
+ __FILE__
444
+ ),
445
+ 'currency' => 'ARS'
446
+ );
447
+ }
448
+ }
449
+
450
+ public static function build_currency_conversion_err_msg( $currency ) {
451
+ return '<img width="12" height="12" src="' .
452
+ plugins_url( 'images/error.png', __FILE__ ) .
453
+ '"> ' .
454
+ __( 'ERROR: It was not possible to convert the unsupported currency', 'woocommerce-mercadopago-module' ) .
455
+ ' ' . get_woocommerce_currency() . ' ' .
456
+ __( 'to', 'woocommerce-mercadopago-module' ) . ' ' . $currency . '. ' .
457
+ __( 'Currency conversions should be made outside this module.', 'woocommerce-mercadopago-module' );
458
+ }
459
+
460
+ public static function build_currency_not_converted_msg( $currency, $country_name ) {
461
+ return '<img width="12" height="12" src="' .
462
+ plugins_url( 'images/warning.png', __FILE__ ) .
463
+ '"> ' .
464
+ __( 'ATTENTION: The currency', 'woocommerce-mercadopago-module' ) .
465
+ ' ' . get_woocommerce_currency() . ' ' .
466
+ __( 'defined in WooCommerce is different from the one used in your credentials country.<br>The currency for transactions in this payment method will be', 'woocommerce-mercadopago-module' ) .
467
+ ' ' . $currency . ' (' . $country_name . '). ' .
468
+ __( 'Currency conversions should be made outside this module.', 'woocommerce-mercadopago-module' );
469
+ }
470
+
471
+ public static function build_currency_converted_msg( $currency, $currency_ratio ) {
472
+ return '<img width="12" height="12" src="' .
473
+ plugins_url( 'images/check.png', __FILE__ ) .
474
+ '"> ' .
475
+ __( 'CURRENCY CONVERTED: The currency conversion ratio from', 'woocommerce-mercadopago-module' ) .
476
+ ' ' . get_woocommerce_currency() . ' ' .
477
+ __( 'to', 'woocommerce-mercadopago-module' ) . ' ' . $currency .
478
+ __( ' is: ', 'woocommerce-mercadopago-module' ) . $currency_ratio . ".";
479
+ }
480
+
481
+ public static function build_valid_credentials_msg( $country_name, $site_id ) {
482
+ return '<img width="12" height="12" src="' .
483
+ plugins_url( 'images/check.png', __FILE__ ) .
484
+ '"> ' .
485
+ __( 'Your credentials are <strong>valid</strong> for', 'woocommerce-mercadopago-module' ) .
486
+ ': ' . $country_name . ' <img width="18.6" height="12" src="' . plugins_url(
487
+ 'images/' . $site_id . '/' . $site_id . '.png', __FILE__
488
+ ) . '"> ';
489
+ }
490
+
491
+ // Check if an order is recurrent.
492
+ public static function is_subscription( $items ) {
493
+ $is_subscription = false;
494
+ if ( sizeof( $items ) == 1 ) {
495
+ foreach ( $items as $cart_item_key => $cart_item ) {
496
+ $is_recurrent = get_post_meta( $cart_item['product_id'], '_mp_recurring_is_recurrent', true );
497
+ if ( $is_recurrent == 'yes' ) {
498
+ $is_subscription = true;
499
+ }
500
+ }
501
+ }
502
+ return $is_subscription;
503
+ }
504
+
505
+ public static function build_invalid_credentials_msg() {
506
+ return '<img width="12" height="12" src="' .
507
+ plugins_url( 'images/error.png', __FILE__ ) .
508
+ '"> ' .
509
+ __( 'Your credentials are <strong>not valid</strong>!', 'woocommerce-mercadopago-module' );
510
+ }
511
+
512
+ // Fix to URL Problem : #038; replaces & and breaks the navigation.
513
+ public static function workaround_ampersand_bug( $link ) {
514
+ return str_replace( '\/', '/', str_replace( '&#038;', '&', $link) );
515
+ }
516
+
517
+ // Converts HTML entities to readable UTF8
518
+ public static function utf8_ansi( $str = '' ) {
519
+ $str = str_replace( '\u', 'u', $str );
520
+ $str = preg_replace( '/u([\da-fA-F]{4})/', '&#x\1;', $str );
521
+ return html_entity_decode( $str );
522
+ }
523
+
524
  }
525
+
526
+ // ==========================================================================================
527
+
528
+ // add our own item to the order actions meta box
529
+ add_action( 'woocommerce_order_actions', 'add_mp_order_meta_box_actions' );
530
+ // define the item in the meta box by adding an item to the $actions array
531
+ function add_mp_order_meta_box_actions( $actions ) {
532
+ $actions['cancel_order'] = __( 'Cancel Order', 'woocommerce-mercadopago-module' );
533
+ return $actions;
534
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535
 
536
+ // Payment gateways should be created as additional plugins that hook into WooCommerce.
537
+ // Inside the plugin, you need to create a class after plugins are loaded.
538
+ add_action(
539
+ 'plugins_loaded',
540
+ array( 'WC_WooMercadoPago_Module', 'init_mercado_pago_gateway_class' ), 0
541
+ );
542
 
543
+ endif;
mercadopago/class-wc-product-mp_recurrent.php ADDED
@@ -0,0 +1,362 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Part of Woo Mercado Pago Module
5
+ * Author - Mercado Pago
6
+ * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
7
+ * Copyright - Copyright(c) MercadoPago [https://www.mercadopago.com]
8
+ * License - https://www.gnu.org/licenses/gpl.html GPL version 2 or higher
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit; // Exit if accessed directly
13
+ }
14
+
15
+ add_action( 'add_meta_boxes', 'add_meta_boxes' );
16
+ function add_meta_boxes() {
17
+ add_meta_box(
18
+ 'woocommerce-mp-order-action-refund',
19
+ __( 'Mercado Pago Subscription', 'woocommerce-mercadopago-module' ),
20
+ 'mp_subscription_order_refund_cancel_box',
21
+ 'shop_order',
22
+ 'side',
23
+ 'default'
24
+ );
25
+ }
26
+
27
+ function mp_subscription_order_refund_cancel_box() {
28
+
29
+ global $post;
30
+ $order = wc_get_order( $post->ID );
31
+ $order_id = trim( str_replace( '#', '', $order->get_order_number() ) );
32
+
33
+ $payments = get_post_meta(
34
+ $order_id,
35
+ '_Mercado_Pago_Sub_Payment_IDs',
36
+ true
37
+ );
38
+
39
+ $options = '';
40
+ if ( ! empty( $payments ) ) {
41
+ $payment_structs = array();
42
+ $payment_ids = explode( ', ', $payments );
43
+ foreach ( $payment_ids as $p_id ) {
44
+ $options .= '<option value="' . $p_id . '">' . $p_id . '</option>';
45
+ }
46
+ }
47
+
48
+ if ( $options == '' ) {
49
+ return;
50
+ }
51
+
52
+ $domain = get_site_url() . '/index.php' . '/woocommerce-mercadopago-module/';
53
+ $domain .= '?wc-api=WC_WooMercadoPagoSubscription_Gateway';
54
+ $subscription_js = '<script type="text/javascript">
55
+ ( function() {
56
+ var MPSubscription = {}
57
+ MPSubscription.callSubscriptionCancel = function () {
58
+ var url = "' . $domain . '";
59
+ url += "&action_mp_payment_id=" + document.getElementById("payment_id").value;
60
+ url += "&action_mp_payment_amount=" + document.getElementById("payment_amount").value;
61
+ url += "&action_mp_payment_action=cancel";
62
+ document.getElementById("sub_pay_cancel_btn").disabled = true;
63
+ MPSubscription.AJAX({
64
+ url: url,
65
+ method : "GET",
66
+ timeout : 5000,
67
+ error: function() {
68
+ document.getElementById("sub_pay_cancel_btn").disabled = false;
69
+ alert("' . __( 'This operation could not be completed.', 'woocommerce-mercadopago-module' ) . '");
70
+ },
71
+ success : function ( status, data ) {
72
+ document.getElementById("sub_pay_cancel_btn").disabled = false;
73
+ var mp_status = data.status;
74
+ var mp_message = data.message;
75
+ if (data.status == 200) {
76
+ alert("' . __( 'Operation successfully completed.', 'woocommerce-mercadopago-module' ) . '");
77
+ } else {
78
+ alert(mp_message);
79
+ }
80
+ }
81
+ });
82
+ }
83
+ MPSubscription.callSubscriptionRefund = function () {
84
+ var url = "' . $domain . '";
85
+ url += "&action_mp_payment_id=" + document.getElementById("payment_id").value;
86
+ url += "&action_mp_payment_amount=" + document.getElementById("payment_amount").value;
87
+ url += "&action_mp_payment_action=refund";
88
+ document.getElementById("sub_pay_refund_btn").disabled = true;
89
+ MPSubscription.AJAX({
90
+ url: url,
91
+ method : "GET",
92
+ timeout : 5000,
93
+ error: function() {
94
+ document.getElementById("sub_pay_refund_btn").disabled = false;
95
+ alert("' . __( 'This operation could not be completed.', 'woocommerce-mercadopago-module' ) . '");
96
+ },
97
+ success : function ( status, data ) {
98
+ document.getElementById("sub_pay_refund_btn").disabled = false;
99
+ var mp_status = data.status;
100
+ var mp_message = data.message;
101
+ if (data.status == 200) {
102
+ alert("' . __( 'Operation successfully completed.', 'woocommerce-mercadopago-module' ) . '");
103
+ } else {
104
+ alert(mp_message);
105
+ }
106
+ }
107
+ });
108
+ }
109
+ MPSubscription.AJAX = function( options ) {
110
+ var useXDomain = !!window.XDomainRequest;
111
+ var req = useXDomain ? new XDomainRequest() : new XMLHttpRequest()
112
+ var data;
113
+ options.url += ( options.url.indexOf( "?" ) >= 0 ? "&" : "?" );
114
+ options.requestedMethod = options.method;
115
+ if ( useXDomain && options.method == "PUT" ) {
116
+ options.method = "POST";
117
+ options.url += "&_method=PUT";
118
+ }
119
+ req.open( options.method, options.url, true );
120
+ req.timeout = options.timeout || 1000;
121
+ if ( window.XDomainRequest ) {
122
+ req.onload = function() {
123
+ data = JSON.parse( req.responseText );
124
+ if ( typeof options.success === "function" ) {
125
+ options.success( options.requestedMethod === "POST" ? 201 : 200, data );
126
+ }
127
+ };
128
+ req.onerror = req.ontimeout = function() {
129
+ if ( typeof options.error === "function" ) {
130
+ options.error( 400, {
131
+ user_agent:window.navigator.userAgent, error : "bad_request", cause:[]
132
+ });
133
+ }
134
+ };
135
+ req.onprogress = function() {};
136
+ } else {
137
+ req.setRequestHeader( "Accept", "application/json" );
138
+ if ( options.contentType ) {
139
+ req.setRequestHeader( "Content-Type", options.contentType );
140
+ } else {
141
+ req.setRequestHeader( "Content-Type", "application/json" );
142
+ }
143
+ req.onreadystatechange = function() {
144
+ if ( this.readyState === 4 ) {
145
+ if ( this.status >= 200 && this.status < 400 ) {
146
+ // Success!
147
+ data = JSON.parse( this.responseText );
148
+ if ( typeof options.success === "function" ) {
149
+ options.success( this.status, data );
150
+ }
151
+ } else if ( this.status >= 400 ) {
152
+ data = JSON.parse( this.responseText );
153
+ if ( typeof options.error === "function" ) {
154
+ options.error( this.status, data );
155
+ }
156
+ } else if ( typeof options.error === "function" ) {
157
+ options.error( 503, {} );
158
+ }
159
+ }
160
+ };
161
+ }
162
+ if ( options.method === "GET" || options.data == null || options.data == undefined ) {
163
+ req.send();
164
+ } else {
165
+ req.send( JSON.stringify( options.data ) );
166
+ }
167
+ }
168
+
169
+ this.MPSubscription = MPSubscription;
170
+
171
+ } ).call();
172
+
173
+ </script>';
174
+
175
+ $subscription_meta_box = '<table>' .
176
+ '<tr class="total">' .
177
+ '<td><label for="payment_id" style="margin-right:1px;">' .
178
+ __( 'Payment ID:', 'woocommerce-mercadopago-module' ) .
179
+ '</label></td>' .
180
+ '<td><select id="payment_id" name="refund_payment_id" style="margin-left:1px;">' .
181
+ $options .
182
+ '</select></td>' .
183
+ '</tr>' .
184
+ '<tr class="total">' .
185
+ '<td><label for="payment_amount" style="margin-right:1px;">' .
186
+ __( 'Amount:', 'woocommerce-mercadopago-module' ) .
187
+ '</label></td>' .
188
+ '<td><input type="number" class="text amount_input" id="payment_amount" value="0" name="payment_amount"' .
189
+ ' placeholder="Decimal" min="0" step="0.01" value="0.00" style="width:117px; margin-left:1px;"' .
190
+ ' ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/"/>' .
191
+ '</td>' .
192
+ '</tr>' .
193
+ '<tr class="total">' .
194
+ '<td><input onclick="MPSubscription.callSubscriptionRefund();" type="button"' .
195
+ ' id="sub_pay_refund_btn" class="button button-primary" style="margin-left:1px; margin-top:2px;"' .
196
+ ' name="refund" value="' . __( 'Refund Payment', 'woocommerce-mercadopago-module' ) .
197
+ '" style="margin-right:1px;"></td>' .
198
+ '<td><input onclick="MPSubscription.callSubscriptionCancel();" type="button"' .
199
+ ' id="sub_pay_cancel_btn" class="button button-primary" style="margin-right:1px; margin-top:2px;"' .
200
+ ' name="cancel" value="' . __( 'Cancel Payment', 'woocommerce-mercadopago-module' ) .
201
+ '" style="margin-left:1px;"></td>' .
202
+ '</tr>' .
203
+ '</table>';
204
+
205
+ echo $subscription_js . $subscription_meta_box;
206
+
207
+ }
208
+
209
+ // Makes the recurrent product individually sold
210
+ add_filter( 'woocommerce_is_sold_individually', 'default_no_quantities', 10, 2 );
211
+ function default_no_quantities( $individually, $product ) {
212
+ if ( method_exists( $product, 'get_id' ) ) {
213
+ $product_id = $product->get_id();
214
+ } else {
215
+ $product_id = $product->id;
216
+ }
217
+ $is_recurrent = get_post_meta( $product_id, '_mp_recurring_is_recurrent', true );
218
+ if ( $is_recurrent == 'yes' ) {
219
+ $individually = true;
220
+ }
221
+ return $individually;
222
+ }
223
+
224
+ // Prevent selling recurrent products together with other products
225
+ add_action( 'woocommerce_check_cart_items', 'check_recurrent_product_singularity' );
226
+ function check_recurrent_product_singularity() {
227
+ global $woocommerce;
228
+ $w_cart = $woocommerce->cart;
229
+ if ( ! isset( $w_cart ) ) {
230
+ return;
231
+ }
232
+ $items = $w_cart->get_cart();
233
+ if ( sizeof( $items ) > 1 ) {
234
+ foreach ( $items as $cart_item_key => $cart_item ) {
235
+ $is_recurrent = get_post_meta( $cart_item['product_id'], '_mp_recurring_is_recurrent', true );
236
+ if ( $is_recurrent == 'yes' ) {
237
+ wc_add_notice(
238
+ __( 'A recurrent product is a signature that should be bought isolated in your cart. Please, create separated orders.', 'woocommerce-mercadopago-module' ),
239
+ 'error'
240
+ );
241
+ }
242
+ }
243
+ }
244
+ }
245
+
246
+ // Validate product date availability.
247
+ add_filter( 'woocommerce_is_purchasable', 'filter_woocommerce_is_purchasable', 10, 2 );
248
+ function filter_woocommerce_is_purchasable( $purchasable, $product ) {
249
+ if ( method_exists( $product, 'get_id' ) ) {
250
+ $product_id = $product->get_id();
251
+ } else {
252
+ $product_id = $product->id;
253
+ }
254
+ // skip this check if product is not a subscription
255
+ $is_recurrent = get_post_meta( $product_id, '_mp_recurring_is_recurrent', true );
256
+ if ( $is_recurrent !== 'yes' ) {
257
+ return $purchasable;
258
+ }
259
+ $today_date = date( 'Y-m-d' );
260
+ $end_date = get_post_meta( $product_id, '_mp_recurring_end_date', true );
261
+ // If there is no date, we should just return the original value.
262
+ if ( ! isset( $end_date ) || empty( $end_date ) ) {
263
+ return $purchasable;
264
+ }
265
+ // If end date had passed, this product is no longer available.
266
+ $days_diff = ( strtotime( $today_date ) - strtotime( $end_date ) ) / 86400;
267
+ if ( $days_diff >= 0 ) {
268
+ return false;
269
+ }
270
+ return $purchasable;
271
+ }
272
+
273
+ // Add the settings under 'general' sub-menu.
274
+ add_action( 'woocommerce_product_options_general_product_data', 'mp_add_recurrent_settings' );
275
+ function mp_add_recurrent_settings() {
276
+
277
+ //global $woocommerce, $post, $thepostid;
278
+ wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
279
+ //$thepostid = $post->ID;
280
+
281
+ echo '<div class="options_group show_if_simple">';
282
+
283
+ woocommerce_wp_checkbox(
284
+ array(
285
+ 'id' => '_mp_recurring_is_recurrent',
286
+ 'label' => __( 'Recurrent Product', 'woocommerce-mercadopago-module' ),
287
+ 'description' => __( 'Make this product a subscription.', 'woocommerce-mercadopago-module' )
288
+ )
289
+ );
290
+
291
+ woocommerce_wp_text_input(
292
+ array(
293
+ 'id' => '_mp_recurring_frequency',
294
+ 'label' => __( 'Frequency', 'woocommerce-mercadopago-module' ),
295
+ 'placeholder' => '1',
296
+ 'desc_tip' => 'true',
297
+ 'description' => __( 'Amount of time (in days or months) for the execution of the next payment.', 'woocommerce-mercadopago-module' ),
298
+ 'type' => 'number'
299
+ )
300
+ );
301
+
302
+ woocommerce_wp_select(
303
+ array(
304
+ 'id' => '_mp_recurring_frequency_type',
305
+ 'label' => __( 'Frequency type', 'woocommerce-mercadopago-module' ),
306
+ 'desc_tip' => 'true',
307
+ 'description' => __( 'Indicates the period of time.', 'woocommerce-mercadopago-module' ),
308
+ 'options' => array(
309
+ 'days' => __( 'Days', 'woocommerce-mercadopago-module' ),
310
+ 'months' => __( 'Months', 'woocommerce-mercadopago-module' )
311
+ )
312
+ )
313
+ );
314
+
315
+ woocommerce_wp_text_input(
316
+ array(
317
+ 'id' => '_mp_recurring_end_date',
318
+ 'label' => __( 'End date', 'woocommerce-mercadopago-module' ),
319
+ 'placeholder' => _x( 'YYYY-MM-DD', 'placeholder', 'woocommerce-mercadopago-module' ),
320
+ 'desc_tip' => 'true',
321
+ 'description' => __( 'Deadline to generate new charges. Defaults to never if blank.', 'woocommerce-mercadopago-module' ),
322
+ 'class' => 'date-picker',
323
+ 'custom_attributes' => array( 'pattern' => "[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" )
324
+ )
325
+ );
326
+
327
+ echo '</div>';
328
+ }
329
+
330
+ // Persists the options saved in product metadata.
331
+ add_action( 'woocommerce_process_product_meta', 'mp_save_recurrent_settings' );
332
+ function mp_save_recurrent_settings( $post_id ) {
333
+
334
+ $_mp_recurring_is_recurrent = $_POST['_mp_recurring_is_recurrent'];
335
+ if ( ! empty( $_mp_recurring_is_recurrent ) ) {
336
+ update_post_meta( $post_id, '_mp_recurring_is_recurrent', esc_attr( $_mp_recurring_is_recurrent ) );
337
+ } else {
338
+ update_post_meta( $post_id, '_mp_recurring_is_recurrent', esc_attr( null ) );
339
+ }
340
+
341
+ $_mp_recurring_frequency = $_POST['_mp_recurring_frequency'];
342
+ if ( ! empty( $_mp_recurring_frequency ) ) {
343
+ update_post_meta( $post_id, '_mp_recurring_frequency', esc_attr( $_mp_recurring_frequency ) );
344
+ } else {
345
+ update_post_meta( $post_id, '_mp_recurring_frequency', esc_attr( 1 ) );
346
+ }
347
+
348
+ $_mp_recurring_frequency_type = $_POST['_mp_recurring_frequency_type'];
349
+ if ( ! empty( $_mp_recurring_frequency_type ) ) {
350
+ update_post_meta( $post_id, '_mp_recurring_frequency_type', esc_attr( $_mp_recurring_frequency_type ) );
351
+ } else {
352
+ update_post_meta( $post_id, '_mp_recurring_frequency_type', esc_attr( 'days' ) );
353
+ }
354
+
355
+ $_mp_recurring_end_date = $_POST['_mp_recurring_end_date'];
356
+ if ( ! empty( $_mp_recurring_end_date ) ) {
357
+ update_post_meta( $post_id, '_mp_recurring_end_date', esc_attr( $_mp_recurring_end_date ) );
358
+ } else {
359
+ update_post_meta( $post_id, '_mp_recurring_end_date', esc_attr( null ) );
360
+ }
361
+
362
+ }
mercadopago/css/woo-mercadopago-module.css DELETED
@@ -1,14 +0,0 @@
1
- .mp-btn, .ch-btn {
2
- background-color: #009ee3;
3
- border: 1px solid #009ee3;
4
- border-radius: 4px;
5
- color: #fff;
6
- display: inline-block;
7
- font-family: Arial,sans-serif;
8
- font-size: 18px;
9
- font-weight: normal;
10
- margin: 0;
11
- padding: 10px;
12
- text-align: center;
13
- width: 100%;
14
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
mercadopago/mercadopago-custom-gateway.php CHANGED
@@ -1,65 +1,77 @@
1
  <?php
 
2
  /**
3
  * Part of Woo Mercado Pago Module
4
  * Author - Mercado Pago
5
  * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
6
- * Copyright - Copyright(c) MercadoPago [http://www.mercadopago.com]
7
- * License - http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
8
  */
9
 
10
  // This include Mercado Pago library SDK
11
- require_once "sdk/lib/mercadopago.php";
12
 
13
- // Extending from WooCommerce Payment Gateway class.
14
- // This extension implements the custom checkout.
 
 
 
15
  class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
16
 
17
- // This array stores each banner image, depending on the country it belongs to or on
18
- // the type of checkout we use.
19
- private $banners_mercadopago_credit = array(
20
- "MLA" => 'MLA/credit_card.png',
21
- "MLB" => 'MLB/credit_card.png',
22
- "MCO" => 'MCO/credit_card.png',
23
- "MLC" => 'MLC/credit_card.png',
24
- "MPE" => 'MPE/credit_card.png',
25
- "MLV" => 'MLV/credit_card.png',
26
- "MLM" => 'MLM/credit_card.png'
27
- );
28
-
29
- // Sponsor ID array by country
30
- private $sponsor_id = array(
31
- "MLA" => '208682286',
32
- "MLB" => '208686191',
33
- "MCO" => '208687643',
34
- "MLC" => '208690789',
35
- "MPE" => '216998692',
36
- "MLV" => '208692735',
37
- "MLM" => '208692380'
38
- );
39
-
40
- // Required inherited method from WC_Payment_Gateway class: __construct.
41
- // Please check:
42
- // [https://docs.woothemes.com/wc-apidocs/class-WC_Payment_Gateway.html]
43
- // for documentation and further information.
44
- public function __construct() {
45
-
46
- // These fields are declared because we use them dinamically in our gateway class.
47
- $this->domain = get_site_url() . '/index.php';
48
- $this->currency_ratio = -1;
49
  $this->site_id = null;
50
- $this->isTestUser = false;
 
 
 
 
 
 
51
  $this->store_categories_id = array();
52
- $this->store_categories_description = array();
53
-
54
- // Within your constructor, you should define the following variables.
 
55
  $this->id = 'woocommerce-mercadopago-custom-module';
 
56
  $this->method_title = __( 'Mercado Pago - Credit Card', 'woocommerce-mercadopago-module' );
57
  $this->method_description = '<img width="200" height="52" src="' .
58
- plugins_url( 'images/mplogo.png', plugin_dir_path( __FILE__ ) ) . '"><br><br>' . '<strong>' .
59
- wordwrap( __( 'This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store.', 'woocommerce-mercadopago-module' ), 80, "\n" ) .
60
- '</strong>';
61
-
62
- // These fields are used in our Mercado Pago Module configuration page.
 
 
 
 
 
 
63
  $this->public_key = $this->get_option( 'public_key' );
64
  $this->access_token = $this->get_option( 'access_token' );
65
  $this->title = $this->get_option( 'title' );
@@ -69,60 +81,111 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
69
  $this->binary_mode = $this->get_option( 'binary_mode' );
70
  $this->category_id = $this->get_option( 'category_id' );
71
  $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' );
72
- $this->currency_conversion = $this->get_option('currency_conversion', false);
 
73
  $this->sandbox = $this->get_option( 'sandbox', false );
74
  $this->debug = $this->get_option( 'debug', false );
75
-
 
 
 
 
 
 
 
 
 
76
  // Render our configuration page and init/load fields.
77
  $this->init_form_fields();
78
  $this->init_settings();
79
-
80
- // Hook actions for WordPress.
81
- add_action( // Used by IPN to receive IPN incomings.
82
  'woocommerce_api_wc_woomercadopagocustom_gateway',
83
- array($this, 'process_http_request')
84
  );
85
- add_action( // Used by IPN to process valid incomings.
 
86
  'valid_mercadopagocustom_ipn_request',
87
- array($this, 'successful_request')
88
  );
89
- add_action( // Used in settings page to hook "save settings" action.
 
 
 
 
 
 
90
  'woocommerce_update_options_payment_gateways_' . $this->id,
91
  array( $this, 'process_admin_options' )
92
  );
93
- add_action( // Scripts for custom checkout
 
94
  'wp_enqueue_scripts',
95
- array( $this, 'customCheckoutScripts' )
96
  );
97
- add_action( // Apply the discounts
 
98
  'woocommerce_cart_calculate_fees',
99
  array( $this, 'add_discount_custom' ), 10
100
  );
101
-
102
- // Verify if public_key or client_secret is empty.
103
- if ( ( empty( $this->public_key ) || empty( $this->access_token ) ) && $this->enabled == 'yes' ) {
104
- add_action( 'admin_notices', array( $this, 'credentialsMissingMessage' ) );
105
- } else {
106
- add_action( // Verify if SSL is supported.
107
- 'admin_notices', array( $this, 'checkSSLAbsence' )
108
- );
109
- }
 
110
 
111
- // Logging and debug.
112
- if ( 'yes' == $this->debug ) {
113
- if ( class_exists( 'WC_Logger' ) ) {
114
- $this->log = new WC_Logger();
 
 
 
 
 
 
 
115
  } else {
116
- $this->log = WC_MercadoPago_Module::woocommerce_instance()->logger();
 
 
 
 
 
 
 
 
 
117
  }
118
  }
119
-
120
  }
121
-
122
- // Required inherited method from WC_Payment_Gateway class: init_form_fields.
123
- // Initialise Gateway settings form fields with a customized page.
 
 
124
  public function init_form_fields() {
125
-
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  $api_secret_locale = sprintf(
127
  '<a href="https://www.mercadopago.com/mla/account/credentials?type=custom" target="_blank">%s</a>, ' .
128
  '<a href="https://www.mercadopago.com/mlb/account/credentials?type=custom" target="_blank">%s</a>, ' .
@@ -140,91 +203,100 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
140
  __( 'or', 'woocommerce-mercadopago-module' ),
141
  __( 'Venezuela', 'woocommerce-mercadopago-module' )
142
  );
143
-
144
  // Trigger API to get payment methods and site_id, also validates public_key/access_token.
145
- if ( $this->validateCredentials() ) {
146
- try {
147
- // checking the currency
148
- $this->currency_message = "";
149
- if ( !$this->isSupportedCurrency() && 'yes' == $this->settings[ 'enabled' ] ) {
150
- if ( $this->currency_conversion == 'no' ) {
151
- $this->currency_ratio = -1;
152
- $this->currency_message .= '<img width="12" height="12" src="' .
153
- plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' .
154
- ' ' . __( 'ATTENTION: The currency', 'woocommerce-mercadopago-module' ) . ' ' . get_woocommerce_currency() .
155
- ' ' . __( 'defined in WooCommerce is different from the one used in your credentials country.<br>The currency for transactions in this payment method will be', 'woocommerce-mercadopago-module' ) .
156
- ' ' . $this->getCurrencyId( $this->site_id ) . ' (' . $this->getCountryName( $this->site_id ) . ').' .
157
- ' ' . __( 'Currency conversions should be made outside this module.', 'woocommerce-mercadopago-module' );
158
- } else if ( $this->currency_conversion == 'yes' && $this->currency_ratio != -1 ) {
159
- $this->currency_message .= '<img width="12" height="12" src="' .
160
- plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '">' .
161
- ' ' . __( 'CURRENCY CONVERTED: The currency conversion ratio from', 'woocommerce-mercadopago-module' ) . ' ' . get_woocommerce_currency() .
162
- ' ' . __( 'to', 'woocommerce-mercadopago-module' ) . ' ' . $this->getCurrencyId( $this->site_id ) . __( ' is: ', 'woocommerce-mercadopago-module' ) . $this->currency_ratio . ".";
163
- } else {
164
- $this->currency_ratio = -1;
165
- $this->currency_message .= '<img width="12" height="12" src="' .
166
- plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '">' .
167
- ' ' . __( 'ERROR: It was not possible to convert the unsupported currency', 'woocommerce-mercadopago-module' ) . ' ' . get_woocommerce_currency() .
168
- ' ' . __( 'to', 'woocommerce-mercadopago-module' ) . ' ' . $this->getCurrencyId( $this->site_id ) . '.' .
169
- ' ' . __( 'Currency conversions should be made outside this module.', 'woocommerce-mercadopago-module' );
170
- }
171
  } else {
172
  $this->currency_ratio = -1;
 
 
 
 
173
  }
174
- $this->credentials_message = '<img width="12" height="12" src="' .
175
- plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '">' .
176
- ' ' . __( 'Your credentials are <strong>valid</strong> for', 'woocommerce-mercadopago-module' ) .
177
- ': ' . $this->getCountryName( $this->site_id ) . ' <img width="18.6" height="12" src="' .
178
- plugins_url( 'images/' . $this->site_id . '/' . $this->site_id . '.png', plugin_dir_path( __FILE__ ) ) . '"> ';
179
- } catch ( MercadoPagoException $e ) {
180
- $this->credentials_message = '<img width="12" height="12" src="' .
181
- plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '">' .
182
- ' ' . __( 'Your credentials are <strong>not valid</strong>!', 'woocommerce-mercadopago-module' );
183
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  } else {
185
- $this->credentials_message = '<img width="12" height="12" src="' .
186
- plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '">' .
187
- ' ' . __( 'Your credentials are <strong>not valid</strong>!', 'woocommerce-mercadopago-module' );
188
- }
189
-
190
- // Fills categoy selector. We do not need credentials to make this call.
191
- $categories = MPRestClient::get( array( "uri" => "/item_categories" ) );
192
- foreach ( $categories[ "response" ] as $category ) {
193
- array_push( $this->store_categories_id, str_replace( "_", " ", $category[ 'id' ] ) );
194
- array_push( $this->store_categories_description, str_replace( "_", " ", $category[ 'description' ] ) );
195
- }
196
-
197
  // This array draws each UI (text, selector, checkbox, label, etc).
198
  $this->form_fields = array(
199
  'enabled' => array(
200
  'title' => __( 'Enable/Disable', 'woocommerce-mercadopago-module' ),
201
  'type' => 'checkbox',
202
  'label' => __( 'Enable Custom Checkout', 'woocommerce-mercadopago-module' ),
203
- 'default' => 'yes'
204
  ),
205
  'credentials_title' => array(
206
  'title' => __( 'Mercado Pago Credentials', 'woocommerce-mercadopago-module' ),
207
  'type' => 'title',
208
- 'description' => sprintf( '%s', $this->credentials_message ) . '<br>' . sprintf( __( 'You can obtain your credentials for', 'woocommerce-mercadopago-module' ) . ' %s.', $api_secret_locale )
 
 
 
209
  ),
210
  'public_key' => array(
211
  'title' => 'Public key',
212
  'type' => 'text',
213
- 'description' => __( 'Insert your Mercado Pago Public key.', 'woocommerce-mercadopago-module' ),
 
214
  'default' => '',
215
  'required' => true
216
  ),
217
  'access_token' => array(
218
  'title' => 'Access token',
219
  'type' => 'text',
220
- 'description' => __( 'Insert your Mercado Pago Access token.', 'woocommerce-mercadopago-module' ),
 
221
  'default' => '',
222
  'required' => true
223
  ),
224
  'ipn_url' => array(
225
- 'title' => __( 'Instant Payment Notification (IPN) URL', 'woocommerce-mercadopago-module' ),
 
226
  'type' => 'title',
227
- 'description' => sprintf( __( 'Your IPN URL to receive instant payment notifications is', 'woocommerce-mercadopago-module' ) . '<br>%s', '<code>' . $this->domain . '/woocommerce-mercadopago-module/?wc-api=WC_WooMercadoPagoCustom_Gateway' . '</code>.' )
 
 
 
228
  ),
229
  'checkout_options_title' => array(
230
  'title' => __( 'Checkout Options', 'woocommerce-mercadopago-module' ),
@@ -234,13 +306,15 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
234
  'title' => array(
235
  'title' => __( 'Title', 'woocommerce-mercadopago-module' ),
236
  'type' => 'text',
237
- 'description' => __( 'Title shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
 
238
  'default' => __( 'Mercado Pago - Credit Card', 'woocommerce-mercadopago-module' )
239
  ),
240
  'description' => array(
241
  'title' => __( 'Description', 'woocommerce-mercadopago-module' ),
242
  'type' => 'textarea',
243
- 'description' => __( 'Description shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
 
244
  'default' => __( 'Pay with Mercado Pago', 'woocommerce-mercadopago-module' )
245
  ),
246
  'statement_descriptor' => array(
@@ -250,38 +324,51 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
250
  'default' => __( 'Mercado Pago', 'woocommerce-mercadopago-module' )
251
  ),
252
  'coupon_mode' => array(
253
- 'title' => __( 'Coupons', 'woocommerce-mercadopago-module' ),
254
- 'type' => 'checkbox',
255
- 'label' => __( 'Enable coupons of discounts', 'woocommerce-mercadopago-module' ),
256
  'default' => 'no',
257
- 'description' => __( 'If there is a Mercado Pago campaign, allow your store to give discounts to customers.', 'woocommerce-mercadopago-module' )
 
258
  ),
259
  'binary_mode' => array(
260
- 'title' => __( 'Binary Mode', 'woocommerce-mercadopago-module' ),
261
- 'type' => 'checkbox',
262
- 'label' => __( 'Enable binary mode for checkout status', 'woocommerce-mercadopago-module' ),
263
  'default' => 'no',
264
- 'description' => __( 'When charging a credit card, only [approved] or [reject] status will be taken.', 'woocommerce-mercadopago-module' )
 
265
  ),
266
  'category_id' => array(
267
  'title' => __( 'Store Category', 'woocommerce-mercadopago-module' ),
268
  'type' => 'select',
269
- 'description' => __( 'Define which type of products your store sells.', 'woocommerce-mercadopago-module' ),
 
270
  'options' => $this->store_categories_id
271
  ),
272
  'invoice_prefix' => array(
273
  'title' => __( 'Store Identificator', 'woocommerce-mercadopago-module' ),
274
  'type' => 'text',
275
- 'description' => __( 'Please, inform a prefix to your store.', 'woocommerce-mercadopago-module' ) . ' ' . __( 'If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same identificators.', 'woocommerce-mercadopago-module' ),
 
 
 
276
  'default' => 'WC-'
277
  ),
278
  'currency_conversion' => array(
279
  'title' => __( 'Currency Conversion', 'woocommerce-mercadopago-module' ),
280
  'type' => 'checkbox',
281
- 'label' => __( 'If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio', 'woocommerce-mercadopago-module' ),
 
282
  'default' => 'no',
283
  'description' => sprintf( '%s', $this->currency_message )
284
  ),
 
 
 
 
 
 
285
  'testing' => array(
286
  'title' => __( 'Test and Debug Options', 'woocommerce-mercadopago-module' ),
287
  'type' => 'title',
@@ -292,49 +379,319 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
292
  'type' => 'checkbox',
293
  'label' => __( 'Enable Mercado Pago Sandbox', 'woocommerce-mercadopago-module' ),
294
  'default' => 'no',
295
- 'description' => __( 'This option allows you to test payments inside a sandbox environment.', 'woocommerce-mercadopago-module' ),
 
296
  ),
297
  'debug' => array(
298
  'title' => __( 'Debug and Log', 'woocommerce-mercadopago-module' ),
299
  'type' => 'checkbox',
300
  'label' => __( 'Enable log', 'woocommerce-mercadopago-module' ),
301
  'default' => 'no',
302
- 'description' => sprintf( __( 'Register event logs of Mercado Pago, such as API requests, in the file', 'woocommerce-mercadopago-module' ) .
303
- ' %s.', $this->buildLogPathString() . '.<br>' . __( 'File location: ', 'woocommerce-mercadopago-module' ) .
304
- '<code>wordpress/wp-content/uploads/wc-logs/' . $this->id . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log</code>')
 
 
 
305
  )
306
  );
307
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  }
309
-
310
- public function admin_options() {
311
- $this->validate_settings_fields();
312
- if ( count( $this->errors ) > 0 ) {
313
- $this->display_errors();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  } else {
316
- echo wpautop( $this->method_description );
317
- ?>
318
- <p><a href="https://wordpress.org/support/view/plugin-reviews/woo-mercado-pago-module?filter=5#postform" target="_blank" class="button button-primary">
319
- <?php esc_html_e( sprintf( __( 'Please, rate us %s on WordPress.org and give your feedback to help improve this module!', 'woocommerce-mercadopago-module' ), '&#9733;&#9733;&#9733;&#9733;&#9733;' ) ); ?>
320
- </a></p>
321
- <table class="form-table">
322
- <?php $this->generate_settings_html(); ?>
323
- </table>
324
- <?php
325
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  }
 
327
  }
328
-
329
  /*
330
  * ========================================================================
331
- * CHECKOUT BUSINESS RULES
332
  * ========================================================================
333
  */
334
-
335
- public function customCheckoutScripts() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
336
  if ( is_checkout() && $this->is_available() ) {
337
- if ( !get_query_var( 'order-received' ) ) {
338
  wp_enqueue_style(
339
  'woocommerce-mercadopago-style', plugins_url(
340
  'assets/css/custom_checkout_mercadopago.css',
@@ -345,7 +702,7 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
345
  }
346
  }
347
  }
348
-
349
  public function payment_fields() {
350
  $amount = $this->get_order_total();
351
 
@@ -353,133 +710,183 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
353
  'public_key' => $this->public_key,
354
  'site_id' => $this->site_id,
355
  'images_path' => plugins_url( 'images/', plugin_dir_path( __FILE__ ) ),
356
- 'banner_path' => plugins_url( 'images/' .
357
- $this->banners_mercadopago_credit[ $this->site_id ], plugin_dir_path( __FILE__ ) ),
358
- 'amount' => $amount * ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ),
359
  'coupon_mode' => $this->coupon_mode,
360
  'is_currency_conversion' => $this->currency_ratio,
361
  'woocommerce_currency' => get_woocommerce_currency(),
362
- 'account_currency' => $this->getCurrencyId( $this->site_id ),
363
- 'discount_action_url' => $this->domain . '/woocommerce-mercadopago-module/?wc-api=WC_WooMercadoPagoCustom_Gateway',
 
364
  'form_labels' => array(
365
- "form" => array(
366
- "payment_converted" => __("Payment converted from", "woocommerce-mercadopago-module" ),
367
- "to" => __("to", "woocommerce-mercadopago-module" ),
368
- "coupon_empty" => __( "Please, inform your coupon code", "woocommerce-mercadopago-module" ),
369
- 'apply' => __( "Apply", "woocommerce-mercadopago-module" ),
370
- 'remove' => __( "Remove", "woocommerce-mercadopago-module" ),
371
- 'discount_info1' => __( "You will save", "woocommerce-mercadopago-module" ),
372
- 'discount_info2' => __( "with discount from", "woocommerce-mercadopago-module" ),
373
- 'discount_info3' => __( "Total of your purchase:", "woocommerce-mercadopago-module" ),
374
- 'discount_info4' => __( "Total of your purchase with discount:", "woocommerce-mercadopago-module" ),
375
- 'discount_info5' => __( "*Uppon payment approval", "woocommerce-mercadopago-module" ),
376
- 'discount_info6' => __( "Terms and Conditions of Use", "woocommerce-mercadopago-module" ),
377
- 'coupon_of_discounts' => __( "Discount Coupon", "woocommerce-mercadopago-module" ),
378
- 'label_other_bank' => __( "Other Bank", "woocommerce-mercadopago-module" ),
379
- 'label_choose' => __( "Choose", "woocommerce-mercadopago-module" ),
380
- "your_card" => __( "Your Card", 'woocommerce-mercadopago-module' ),
381
- "other_cards" => __( "Other Cards", 'woocommerce-mercadopago-module' ),
382
- "other_card" => __( "Other Card", 'woocommerce-mercadopago-module' ),
383
- "ended_in" => __( "ended in", 'woocommerce-mercadopago-module' ),
384
- "card_holder_placeholder" => __( " as it appears in your card ...", 'woocommerce-mercadopago-module' ),
385
- "payment_method" => __( "Payment Method", 'woocommerce-mercadopago-module' ),
386
- "credit_card_number" => __( "Credit card number", 'woocommerce-mercadopago-module' ),
387
- "expiration_month" => __( "Expiration month", 'woocommerce-mercadopago-module' ),
388
- "expiration_year" => __( "Expiration year", 'woocommerce-mercadopago-module' ),
389
- "year" => __( "Year", 'woocommerce-mercadopago-module' ),
390
- "month" => __( "Month", 'woocommerce-mercadopago-module' ),
391
- "card_holder_name" => __( "Card holder name", 'woocommerce-mercadopago-module' ),
392
- "security_code" => __( "Security code", 'woocommerce-mercadopago-module' ),
393
- "document_type" => __( "Document Type", 'woocommerce-mercadopago-module' ),
394
- "document_number" => __( "Document number", 'woocommerce-mercadopago-module' ),
395
- "issuer" => __( "Issuer", 'woocommerce-mercadopago-module' ),
396
- "installments" => __( "Installments", 'woocommerce-mercadopago-module' )
397
- ),
398
- "error" => array(
399
- //card number
400
- "205" => __( "Parameter cardNumber can not be null/empty", 'woocommerce-mercadopago-module' ),
401
- "E301" => __( "Invalid Card Number", 'woocommerce-mercadopago-module' ),
402
- //expiration date
403
- "208" => __( "Invalid Expiration Date", 'woocommerce-mercadopago-module' ),
404
- "209" => __( "Invalid Expiration Date", 'woocommerce-mercadopago-module' ),
405
- "325" => __( "Invalid Expiration Date", 'woocommerce-mercadopago-module' ),
406
- "326" => __( "Invalid Expiration Date", 'woocommerce-mercadopago-module' ),
407
- //card holder name
408
- "221" => __( "Parameter cardholderName can not be null/empty", 'woocommerce-mercadopago-module' ),
409
- "316" => __( "Invalid Card Holder Name", 'woocommerce-mercadopago-module' ),
410
- //security code
411
- "224" => __( "Parameter securityCode can not be null/empty", 'woocommerce-mercadopago-module' ),
412
- "E302" => __( "Invalid Security Code", 'woocommerce-mercadopago-module' ),
413
- //doc type
414
- "212" => __( "Parameter docType can not be null/empty", 'woocommerce-mercadopago-module' ),
415
- "322" => __( "Invalid Document Type", 'woocommerce-mercadopago-module' ),
416
- //doc number
417
- "214" => __( "Parameter docNumber can not be null/empty", 'woocommerce-mercadopago-module' ),
418
- "324" => __( "Invalid Document Number", 'woocommerce-mercadopago-module' ),
419
- //doc sub type
420
- "213" => __( "The parameter cardholder.document.subtype can not be null or empty", 'woocommerce-mercadopago-module' ),
421
- "323" => __( "Invalid Document Sub Type", 'woocommerce-mercadopago-module' ),
422
- //issuer
423
- "220" => __( "Parameter cardIssuerId can not be null/empty", 'woocommerce-mercadopago-module' )
 
 
 
 
 
424
  )
425
  )
426
  );
427
 
428
- try { // find logged user
 
 
 
 
 
429
  if ( wp_get_current_user()->ID != 0 ) {
430
- $mp = new MP( $this->access_token );
431
  $logged_user_email = wp_get_current_user()->user_email;
432
- $customer = $mp->get_or_create_customer( $logged_user_email );
433
- $customer_cards = $customer[ 'cards' ];
434
- $parameters[ 'customerId' ] = $customer[ 'id' ];
435
- $parameters[ 'customer_cards' ] = $customer_cards;
436
  }
437
- } catch (Exception $e) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
  if ( 'yes' == $this->debug ) {
439
- $this->log->add( $this->id, $this->id .
440
- ': @[process_fields] - There is a problem when retrieving information for cards: ' .
441
- json_encode( array( "status" => $e->getCode(), "message" => $e->getMessage() ) )
 
442
  );
443
  }
444
  }
 
445
 
446
  wc_get_template(
447
  'credit-card/payment-form.php',
448
  $parameters,
449
  'woocommerce/mercadopago/',
450
- WC_WooMercadoPago_Module::getTemplatesPath()
451
  );
452
  }
453
-
454
- // This function is called after we click on [place_order] button, and each field is passed to this
455
- // function through $_POST variable.
 
 
 
 
456
  public function process_payment( $order_id ) {
457
- $order = new WC_Order( $order_id );
458
- // we have got parameters from checkout page, now its time to charge the card
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
  if ( 'yes' == $this->debug ) {
460
- $this->log->add( $this->id, $this->id .
461
- ': @[process_payment] - Received [$_POST] from customer front-end page: ' .
462
- json_encode( $_POST, JSON_PRETTY_PRINT ) );
463
- }
464
- // Mexico country case
465
- if ( $_POST[ 'mercadopago_custom' ][ 'paymentMethodId' ] == "" || empty( $_POST[ 'mercadopago_custom' ][ 'paymentMethodId' ] ) ) {
466
- $_POST[ 'mercadopago_custom' ][ 'paymentMethodId' ] = $_POST[ 'mercadopago_custom' ][ 'paymentMethodSelector' ];
467
- }
468
- if ( isset( $_POST[ 'mercadopago_custom' ][ 'amount' ] ) && !empty( $_POST[ 'mercadopago_custom' ][ 'amount' ] ) &&
469
- isset( $_POST[ 'mercadopago_custom' ][ 'token' ] ) && !empty( $_POST[ 'mercadopago_custom' ][ 'token' ] ) &&
470
- isset( $_POST[ 'mercadopago_custom' ][ 'paymentMethodId' ] ) && !empty( $_POST[ 'mercadopago_custom' ][ 'paymentMethodId' ] ) &&
471
- isset( $_POST[ 'mercadopago_custom' ][ 'installments' ] ) && !empty( $_POST[ 'mercadopago_custom' ][ 'installments' ] ) && $_POST[ 'mercadopago_custom' ][ 'installments' ] != -1 ) {
472
- $post = $_POST;
473
- $response = $this->createUrl( $order, $post );
474
- if ( array_key_exists( 'status', $response ) ) {
475
- switch ( $response[ 'status' ] ) {
476
- case 'approved':
477
- WC()->cart->empty_cart();
478
- wc_add_notice(
479
- '<p>' . __( $this->getOrderStatus( 'accredited' ), 'woocommerce-mercadopago-module') . '</p>',
480
- 'notice'
481
- );
482
- $order->add_order_note(
 
 
 
 
 
 
 
 
483
  'Mercado Pago: ' .
484
  __( 'Payment approved.', 'woocommerce-mercadopago-module' )
485
  );
@@ -488,19 +895,23 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
488
  'redirect' => $order->get_checkout_order_received_url()
489
  );
490
  break;
491
- case 'pending':
492
- // order approved/pending, we just redirect to the thankyou page
493
- return array(
494
  'result' => 'success',
495
  'redirect' => $order->get_checkout_order_received_url()
496
  );
497
  break;
498
- case 'in_process':
499
- // for pending, we don't know if the purchase will be made, so we must inform this status
500
- WC()->cart->empty_cart();
501
  wc_add_notice(
502
- '<p>' . __( $this->getOrderStatus( $response[ 'status_detail' ] ), 'woocommerce-mercadopago-module') . '</p>' .
503
- '<p><a class="button" href="' . esc_url( $order->get_checkout_order_received_url() ) . '">' .
 
 
 
 
504
  __( 'Check your order resume', 'woocommerce-mercadopago-module' ) .
505
  '</a></p>',
506
  'notice'
@@ -510,12 +921,15 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
510
  'redirect' => $order->get_checkout_payment_url( true )
511
  );
512
  break;
513
- case 'rejected':
514
- // if rejected is received, the order will not proceed until another payment try,
515
- // so we must inform this status
516
  wc_add_notice(
517
- '<p>' . __( 'Your payment was refused. You can try again.', 'woocommerce-mercadopago-module' ) .
518
- '<br>' . __( $this->getOrderStatus( $response[ 'status_detail' ] ), 'woocommerce-mercadopago-module') . '</p>' .
 
 
 
519
  '<p><a class="button" href="' . esc_url( $order->get_checkout_payment_url() ) . '">' .
520
  __( 'Click to try again', 'woocommerce-mercadopago-module' ) .
521
  '</a></p>',
@@ -533,365 +947,615 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
533
  default:
534
  break;
535
  }
536
- }
537
  } else {
538
- // process when fields are imcomplete
539
  wc_add_notice(
540
- '<p>' . __( 'A problem was occurred when processing your payment. Are you sure you have correctly filled all information in the checkout form?', 'woocommerce-mercadopago-module' ) . '</p>',
 
 
541
  'error'
542
  );
 
 
 
 
543
  }
544
  }
545
 
546
- protected function createUrl( $order, $post_from_form ) {
547
-
548
- $mp = new MP( $this->access_token );
549
- // Checks for sandbox mode
550
- if ( 'yes' == $this->sandbox ) {
551
- $mp->sandbox_mode( true );
552
- if ( 'yes' == $this->debug ) {
553
- $this->log->add( $this->id, $this->id . ': @[createUrl] - sandbox mode is enabled' );
554
- }
555
- } else {
556
- $mp->sandbox_mode( false );
557
- }
558
-
559
- // Creates the order parameters by checking the cart configuration
560
- $preferences = $this->createPreferences( $order, $post_from_form );
561
- try {
562
- // Create order preferences with Mercado Pago API request
563
- $checkout_info = $mp->post( "/v1/payments", json_encode( $preferences ) );
564
- if ( 'yes' == $this->debug ) {
565
- $this->log->add( $this->id, $this->id .
566
- ': @[createUrl] - Received [$checkout_info] from Mercado Pago API: ' .
567
- json_encode( $checkout_info, JSON_PRETTY_PRINT ) );
568
- }
569
- if ( is_wp_error( $checkout_info ) ||
570
- $checkout_info[ 'status' ] < 200 || $checkout_info[ 'status' ] >= 300 ) {
571
- if ( 'yes' == $this->debug ) {
572
- $this->log->add( $this->id, $this->id .
573
- ': @[createUrl] - payment creation failed with error: ' .
574
- $checkout_info[ 'response' ][ 'status' ] );
575
- }
576
- return false;
577
- } else {
578
- return $checkout_info[ 'response' ];
579
- }
580
- } catch ( MercadoPagoException $e ) {
581
- if ( 'yes' == $this->debug ) {
582
- $this->log->add( $this->id, $this->id .
583
- ': @[createUrl] - payment creation failed with exception: ' .
584
- json_encode( array( "status" => $e->getCode(), "message" => $e->getMessage() ) ) );
585
- }
586
- return false;
587
- }
588
 
589
- }
590
-
591
- private function createPreferences( $order, $post_from_form ) {
 
592
 
593
- // Here we build the array that contains ordered itens, from customer cart
594
  $items = array();
595
- $purchase_description = "";
596
  if ( sizeof( $order->get_items() ) > 0 ) {
597
  foreach ( $order->get_items() as $item ) {
598
  if ( $item['qty'] ) {
599
- $product = new WC_product( $item[ 'product_id' ] );
600
- $purchase_description =
601
- $purchase_description . ' ' .
602
- ( $product->post->post_title . ' x ' . $item[ 'qty' ] );
603
- array_push( $items, array(
604
- 'id' => $item[ 'product_id' ],
605
- 'title' => ( $product->post->post_title . ' x ' . $item[ 'qty' ] ),
606
- 'description' => sanitize_file_name( (
607
- // This handles description width limit of Mercado Pago
608
- strlen( $product->post->post_content ) > 230 ?
609
- substr( $product->post->post_content, 0, 230 ) . "..." :
 
 
 
 
610
  $product->post->post_content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
611
  ) ),
612
  'picture_url' => wp_get_attachment_url( $product->get_image_id() ),
613
- 'category_id' => $this->store_categories_id[ $this->category_id ],
614
  'quantity' => 1,
615
- 'unit_price' => floor( ( (float) $item[ 'line_total' ] + (float) $item[ 'line_tax' ] ) *
616
- ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ) * 100 ) / 100,
617
- ));
618
  }
619
  }
620
  }
621
-
622
- // Creates the shipment cost structure
623
- $shipping_cost = (float) $order->get_total_shipping();
624
- if ( $shipping_cost > 0 ) {
625
- $item = array(
626
- 'title' => $this->workaroundAmperSandBug( $this->workaroundAmperSandBug( $order->get_shipping_to_display() ) ),
627
- 'description' => __( 'Shipping service used by store', 'woocommerce-mercadopago-module' ),
628
- 'quantity' => 1,
629
- 'category_id' => $this->store_categories_id[ $this->category_id ],
630
- 'unit_price' => $shipping_cost * ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 )
631
- );
632
- $items[] = $item;
633
- }
634
-
635
- // Discounts features
636
- if ( isset( $post_from_form[ 'mercadopago_custom' ][ 'discount' ] ) &&
637
- $post_from_form[ 'mercadopago_custom' ][ 'discount' ] != "" &&
638
- $post_from_form[ 'mercadopago_custom' ][ 'discount' ] > 0 &&
639
- isset( $post_from_form[ 'mercadopago_custom' ][ 'coupon_code' ] ) &&
640
- $post_from_form[ 'mercadopago_custom' ][ 'coupon_code' ] != "" &&
641
- WC()->session->chosen_payment_method == "woocommerce-mercadopago-custom-module" ) {
642
- $item = array(
643
- 'title' => __( 'Discount', 'woocommerce-mercadopago-module' ),
644
- 'description' => __( 'Discount provided by store', 'woocommerce-mercadopago-module' ),
645
- 'quantity' => 1,
646
- 'category_id' => $this->store_categories_id[ $this->category_id ],
647
- 'unit_price' => - ( (float) $post_from_form[ 'mercadopago_custom' ][ 'discount' ] )
648
- );
649
- $items[] = $item;
650
- }
651
-
652
- // Build additional information from the customer data
653
- $payer_additional_info = array(
654
- 'first_name' => $order->billing_first_name,
655
- 'last_name' => $order->billing_last_name,
656
- //'registration_date' =>
657
- 'phone' => array(
658
- //'area_code' =>
659
- 'number' => $order->billing_phone
660
- ),
661
- 'address' => array(
662
- 'zip_code' => $order->billing_postcode,
663
- //'street_number' =>
664
- 'street_name' => $order->billing_address_1 . ' / ' .
665
- $order->billing_city . ' ' .
666
- $order->billing_state . ' ' .
667
- $order->billing_country
668
- )
669
- );
670
-
671
- // Create the shipment address information set
672
- $shipments = array(
673
- 'receiver_address' => array(
674
- 'zip_code' => $order->shipping_postcode,
675
- //'street_number' =>
676
- 'street_name' => $order->shipping_address_1 . ' ' .
677
- $order->shipping_address_2 . ' ' .
678
- $order->shipping_city . ' ' .
679
- $order->shipping_state . ' ' .
680
- $order->shipping_country,
681
- //'floor' =>
682
- 'apartment' => $order->shipping_address_2
683
- )
684
- );
685
-
686
- // The payment preference
687
- $payment_preference = array (
688
- 'transaction_amount' => floor( ( (float) $post_from_form[ 'mercadopago_custom' ][ 'amount' ] ) * 100 ) / 100,
689
- 'token' => $post_from_form[ 'mercadopago_custom' ][ 'token' ],
690
- 'description' => $purchase_description,
691
- 'installments' => (int) $post_from_form[ 'mercadopago_custom' ][ 'installments' ],
692
- 'payment_method_id' => $post_from_form[ 'mercadopago_custom' ][ 'paymentMethodId' ],
693
- 'payer' => array(
694
- 'email' => $order->billing_email
695
- ),
696
- 'external_reference' => $this->invoice_prefix . $order->id,
697
- 'statement_descriptor' => $this->statement_descriptor,
698
- 'binary_mode' => ($this->binary_mode == "yes"),
699
- 'additional_info' => array(
700
- 'items' => $items,
701
- 'payer' => $payer_additional_info,
702
- 'shipments' => $shipments
703
- )
704
- );
705
-
706
- // Customer's Card Feature, add only if it has issuer id
707
- if ( array_key_exists( 'token', $post_from_form[ 'mercadopago_custom' ] ) ) {
708
- $payment_preference[ 'metadata' ][ 'token' ] = $post_from_form[ 'mercadopago_custom' ][ 'token' ];
709
- if ( array_key_exists( 'issuer', $post_from_form[ 'mercadopago_custom' ] ) ) {
710
- if ( !empty( $post_from_form[ 'mercadopago_custom' ][ 'issuer' ] ) ) {
711
- $payment_preference[ 'issuer_id' ] = (integer) $post_from_form[ 'mercadopago_custom' ][ 'issuer' ];
712
- }
713
- }
714
- if ( !empty( $post_from_form[ 'mercadopago_custom' ][ 'CustomerId' ] ) ) {
715
- $payment_preference[ 'payer' ][ 'id' ] = $post_from_form[ 'mercadopago_custom' ][ 'CustomerId' ];
716
- }
717
- }
718
-
719
- // Do not set IPN url if it is a localhost!
720
- $notification_url = $this->domain . '/woocommerce-mercadopago-module/?wc-api=WC_WooMercadoPagoCustom_Gateway';
721
- if ( !strrpos( $notification_url, "localhost" ) ) {
722
- $payment_preference['notification_url'] = $this->workaroundAmperSandBug( $notification_url );
723
- }
724
-
725
- // Discounts features
726
- if ( isset( $post_from_form[ 'mercadopago_custom' ][ 'discount' ] ) &&
727
- $post_from_form[ 'mercadopago_custom' ][ 'discount' ] != "" &&
728
- $post_from_form[ 'mercadopago_custom' ][ 'discount' ] > 0 &&
729
- isset( $post_from_form[ 'mercadopago_custom' ][ 'coupon_code' ] ) &&
730
- $post_from_form[ 'mercadopago_custom' ][ 'coupon_code' ] != "" &&
731
- WC()->session->chosen_payment_method == "woocommerce-mercadopago-custom-module" ) {
732
- $payment_preference[ 'campaign_id' ] = (int) $post_from_form[ 'mercadopago_custom' ][ 'campaign_id' ];
733
- $payment_preference[ 'coupon_amount' ] = ( (float) $post_from_form[ 'mercadopago_custom' ][ 'discount' ] );
734
- $payment_preference[ 'coupon_code' ] = strtoupper( $post_from_form[ 'mercadopago_custom' ][ 'coupon_code' ] );
735
- }
736
-
737
- if ( !$this->isTestUser ) {
738
- $preferences[ 'sponsor_id' ] = (int) ( $this->sponsor_id[ $this->site_id ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
739
  }
740
 
741
  if ( 'yes' == $this->debug ) {
742
- $this->log->add( $this->id, $this->id .
743
- ': @[createPreferences] - Returning just created [$payment_preference] structure: ' .
744
- json_encode( $payment_preference, JSON_PRETTY_PRINT ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
745
  }
 
746
 
747
- $payment_preference = apply_filters(
748
- 'woocommerce_mercadopago_module_custom_preferences',
749
- $payment_preference, $order
750
- );
751
- return $payment_preference;
752
- }
753
 
754
- public function checkAndSaveCustomerCard( $checkout_info ) {
755
- if ( 'yes' == $this->debug ) {
756
- $this->log->add( $this->id, $this->id .
757
- ': @[checkAndSaveCustomerCard] - Checking info to create card: ' .
758
- json_encode( $checkout_info, JSON_PRETTY_PRINT ) );
 
759
  }
 
760
  $custId = null;
761
- $token = null;
762
  $issuer_id = null;
763
  $payment_method_id = null;
764
- if ( isset( $checkout_info[ 'payer' ][ 'id' ] ) && !empty( $checkout_info[ 'payer' ][ 'id' ] ) ) {
765
- $custId = $checkout_info[ 'payer' ][ 'id' ];
766
- } else {
767
- return;
768
- }
769
- if ( isset( $checkout_info[ 'metadata' ][ 'token' ] ) && !empty( $checkout_info[ 'metadata' ][ 'token' ] ) ) {
770
- $token = $checkout_info[ 'metadata' ][ 'token' ];
771
- } else {
772
- return;
773
- }
774
- if ( isset( $checkout_info[ 'issuer_id' ] ) && !empty( $checkout_info[ 'issuer_id' ] ) ) {
775
- $issuer_id = (integer)( $checkout_info[ 'issuer_id' ] );
776
- }
777
- if ( isset( $checkout_info[ 'payment_method_id' ] ) && !empty( $checkout_info[ 'payment_method_id' ] ) ) {
778
- $payment_method_id = $checkout_info[ 'payment_method_id' ];
779
- }
780
- try {
781
- $mp = new MP( $this->access_token );
782
- $mp->create_card_in_customer( $custId, $token, $payment_method_id, $issuer_id );
 
 
 
783
  } catch ( MercadoPagoException $e ) {
784
  if ( 'yes' == $this->debug ) {
785
- $this->log->add( $this->id, $this->id .
786
- ': @[checkAndSaveCustomerCard] - card creation failed: ' .
787
- json_encode( array( "status" => $e->getCode(), "message" => $e->getMessage() ) ) );
 
 
788
  }
789
  }
 
790
  }
791
 
 
 
 
 
792
  public function add_discount_custom() {
 
 
 
 
793
  if ( is_admin() && ! defined( 'DOING_AJAX' ) || is_cart() ) {
794
  return;
795
  }
796
- if ( 'yes' == $this->debug ) {
797
- $this->log->add( $this->id, $this->id . ': @[add_discount_custom] - Custom checkout trying to apply discount...' );
798
- }
799
- if ( isset( $_POST[ 'mercadopago_custom' ][ 'discount' ] ) &&
800
- $_POST[ 'mercadopago_custom' ][ 'discount' ] != "" &&
801
- $_POST[ 'mercadopago_custom' ][ 'discount' ] > 0 &&
802
- isset( $_POST[ 'mercadopago_custom' ][ 'coupon_code' ] ) &&
803
- $_POST[ 'mercadopago_custom' ][ 'coupon_code' ] != "" &&
804
- WC()->session->chosen_payment_method == "woocommerce-mercadopago-custom-module" ) {
805
- $value = ( $_POST[ 'mercadopago_custom' ][ 'discount' ] ) /
 
 
 
 
 
806
  ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 );
807
  global $woocommerce;
808
- if ( apply_filters( 'wc_mercadopagocustom_module_apply_discount', 0 < $value, $woocommerce->cart ) ) {
809
- $woocommerce->cart->add_fee(
810
- sprintf( __( 'Discount for %s coupon', 'woocommerce-mercadopago-module' ), esc_attr( $_POST[ 'mercadopago_custom' ][ 'campaign' ] ) ),
811
- ( $value * -1 ), true
 
 
 
 
812
  );
813
  }
814
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
815
  }
816
 
817
  /*
818
  * ========================================================================
819
- * AUXILIARY AND FEEDBACK METHODS
820
  * ========================================================================
821
  */
822
 
823
- // Fix to URL Problem : #038; replaces & and breaks the navigation
824
- function workaroundAmperSandBug( $link ) {
825
- return str_replace('&#038;', '&', $link);
826
- }
 
 
827
 
828
- // Check if we have valid credentials.
829
- public function validateCredentials() {
830
- if ( empty( $this->public_key ) ) return false;
831
- if ( empty( $this->access_token ) ) return false;
832
- if ( strlen( $this->public_key ) > 0 && strlen( $this->access_token ) > 0 ) {
833
- try {
834
- $mp = new MP( $this->access_token );
835
- $get_request = $mp->get( "/users/me?access_token=" . $this->access_token );
836
- if ( isset( $get_request[ 'response' ][ 'site_id' ] ) ) {
837
- $this->isTestUser = in_array( 'test_user', $get_request[ 'response' ][ 'tags' ] );
838
- $this->site_id = $get_request[ 'response' ][ 'site_id' ];
839
- // check for auto converstion of currency
840
- $currency_obj = MPRestClient::get_ml( array( "uri" =>
841
- "/currency_conversions/search?from=" .
842
- get_woocommerce_currency() .
843
- "&to=" .
844
- $this->getCurrencyId( $this->site_id )
845
- ) );
846
- if ( isset( $currency_obj[ 'response' ] ) ) {
847
- $currency_obj = $currency_obj[ 'response' ];
848
- if ( isset( $currency_obj['ratio'] ) ) {
849
- $this->currency_ratio = (float) $currency_obj['ratio'];
850
- } else {
851
- $this->currency_ratio = -1;
852
- }
853
- } else {
854
- $this->currency_ratio = -1;
855
- }
856
- return true;
857
- } else return false;
858
- } catch ( MercadoPagoException $e ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
859
  return false;
860
  }
 
 
 
 
 
 
 
 
 
 
 
861
  }
 
862
  return false;
 
863
  }
864
 
865
- // Build the string representing the path to the log file
866
- protected function buildLogPathString() {
867
- return '<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' .
868
  esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' .
869
  __( 'WooCommerce &gt; System Status &gt; Logs', 'woocommerce-mercadopago-module' ) . '</a>';
870
  }
871
-
872
  // Return boolean indicating if currency is supported.
873
- protected function isSupportedCurrency() {
874
- return get_woocommerce_currency() == $this->getCurrencyId( $this->site_id );
875
  }
876
 
877
- // Get currency id for a country
878
- protected function getCurrencyId( $site_id ) {
879
- switch ( $site_id ) {
880
- case 'MLA': return 'ARS';
881
- case 'MLB': return 'BRL';
882
- case 'MCO': return 'COP';
883
- case 'MLC': return 'CLP';
884
- case 'MLM': return 'MXN';
885
- case 'MLV': return 'VEF';
886
- case 'MPE': return 'PEN';
887
- default: return '';
 
888
  }
 
 
 
 
 
 
 
 
 
 
 
889
  }
890
 
891
- public function checkSSLAbsence() {
892
- if ( empty( $_SERVER[ 'HTTPS' ] ) || $_SERVER[ 'HTTPS' ] == 'off' ) {
893
- if ( 'yes' == $this->settings[ 'enabled' ] ) {
894
- echo '<div class="error"><p><strong>' .
895
  __( 'Custom Checkout is Inactive', 'woocommerce-mercadopago-module' ) .
896
  '</strong>: ' .
897
  sprintf(
@@ -901,21 +1565,9 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
901
  }
902
  }
903
 
904
- // Called automatically by WooCommerce, verify if Module is available to use.
905
- public function is_available() {
906
- // check SSL connection, as we can't use normal http in custom checkout
907
- if ( empty( $_SERVER[ 'HTTPS' ] ) || $_SERVER[ 'HTTPS' ] == 'off' ) {
908
- return false;
909
- }
910
- $available = ( 'yes' == $this->settings[ 'enabled' ] ) &&
911
- !empty( $this->public_key ) &&
912
- !empty( $this->access_token );
913
- return $available;
914
- }
915
-
916
  // Get the URL to admin page.
917
  protected function admin_url() {
918
- if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
919
  return admin_url(
920
  'admin.php?page=wc-settings&tab=checkout&section=wc_woomercadopagocustom_gateway'
921
  );
@@ -926,31 +1578,15 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
926
  }
927
 
928
  // Notify that public_key and/or access_token are not valid.
929
- public function credentialsMissingMessage() {
930
- echo '<div class="error"><p><strong>' .
931
  __( 'Custom Checkout is Inactive', 'woocommerce-mercadopago-module' ) .
932
  '</strong>: ' .
933
- sprintf(
934
- __( 'Your Mercado Pago credentials Public Key/Access Token appears to be misconfigured.', 'woocommerce-mercadopago-module' ) . ' %s',
935
- '<a href="' . $this->admin_url() . '">' .
936
- __( 'Click here and configure!', 'woocommerce-mercadopago-module' ) . '</a>' ) .
937
  '</p></div>';
938
  }
939
-
940
- public function getCountryName( $site_id ) {
941
- $country = $site_id;
942
- switch ( $site_id ) {
943
- case 'MLA': return __( 'Argentine', 'woocommerce-mercadopago-module' );
944
- case 'MLB': return __( 'Brazil', 'woocommerce-mercadopago-module' );
945
- case 'MCO': return __( 'Colombia', 'woocommerce-mercadopago-module' );
946
- case 'MLC': return __( 'Chile', 'woocommerce-mercadopago-module' );
947
- case 'MLM': return __( 'Mexico', 'woocommerce-mercadopago-module' );
948
- case 'MLV': return __( 'Venezuela', 'woocommerce-mercadopago-module' );
949
- case 'MPE': return __( 'Peru', 'woocommerce-mercadopago-module' );
950
- }
951
- }
952
 
953
- public function getOrderStatus( $status_detail ) {
954
  switch ( $status_detail ) {
955
  case 'accredited':
956
  return __( 'Done, your payment was accredited!', 'woocommerce-mercadopago-module' );
@@ -990,55 +1626,60 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
990
  return __( 'This payment method did not process the payment.', 'woocommerce-mercadopago-module' );
991
  }
992
  }
993
-
994
  /*
995
  * ========================================================================
996
- * IPN MECHANICS
997
  * ========================================================================
998
  */
999
 
1000
- // [Server Side] This call checks any incoming notifications from Mercado Pago server.
 
 
 
1001
  public function process_http_request() {
1002
  @ob_clean();
1003
  if ( 'yes' == $this->debug ) {
1004
- $this->log->add( $this->id, $this->id .
1005
- ': @[process_http_request] - Received _get content: ' .
1006
- json_encode( $_GET, JSON_PRETTY_PRINT ) );
1007
- }
1008
- if ( isset( $_GET[ 'coupon_id' ] ) && $_GET[ 'coupon_id' ] != '' ) {
1009
- // process coupon evaluations
1010
- if ( isset( $_GET[ 'payer' ] ) && $_GET[ 'payer' ] != '' ) {
1011
- $logged_user_email = $_GET[ 'payer' ];
1012
- $coupon_id = $_GET[ 'coupon_id' ];
1013
- $mp = new MP( $this->access_token );
1014
- if ( 'yes' == $this->sandbox )
1015
- $mp->sandbox_mode( true );
1016
- else
1017
- $mp->sandbox_mode( false );
1018
- $response = $mp->check_discount_campaigns(
1019
- $_GET[ 'amount' ],
1020
- $logged_user_email,
1021
- $coupon_id
1022
- );
1023
- header( 'HTTP/1.1 200 OK' );
1024
- header( 'Content-Type: application/json' );
 
1025
  echo json_encode( $response );
1026
  } else {
1027
  $obj = new stdClass();
1028
  $obj->status = 404;
1029
  $obj->response = array(
1030
- 'message' => __( 'Please, inform your email in billing address to use this feature', 'woocommerce-mercadopago-module' ),
 
1031
  'error' => 'payer_not_found',
1032
  'status' => 404,
1033
  'cause' => array()
1034
  );
1035
  header( 'HTTP/1.1 200 OK' );
1036
- header( 'Content-Type: application/json' );
1037
  echo json_encode( $obj );
1038
  }
1039
- exit(0);
1040
  } else {
1041
- // process IPN messages
1042
  $data = $this->check_ipn_request_is_valid( $_GET );
1043
  if ( $data ) {
1044
  header( 'HTTP/1.1 200 OK' );
@@ -1046,25 +1687,31 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
1046
  }
1047
  }
1048
  }
1049
-
1050
- // Get received data from IPN and checks if we have an associated
1051
- // payment. If we have these information, we return data to be
1052
- // processed by successful_request function.
 
 
 
1053
  public function check_ipn_request_is_valid( $data ) {
1054
-
1055
- if ( !isset( $data[ 'data_id' ] ) || !isset( $data[ 'type' ] ) ) {
1056
  if ( 'yes' == $this->debug ) {
1057
- $this->log->add( $this->id, $this->id .
1058
- ': @[check_ipn_request_is_valid] - data_id or type not set: ' .
1059
- json_encode( $data, JSON_PRETTY_PRINT ) );
 
 
1060
  }
1061
- // at least, check if its a v0 ipn
1062
- if ( !isset( $data[ 'id' ] ) || !isset( $data[ 'topic' ] ) ) {
1063
  if ( 'yes' == $this->debug ) {
1064
  $this->log->add(
1065
- $this->id, $this->id .
1066
- ': @[check_ipn_request_is_valid] - Mercado Pago Request Failure: ' .
1067
- json_encode( $_GET, JSON_PRETTY_PRINT ) );
 
1068
  }
1069
  wp_die( __( 'Mercado Pago Request Failure', 'woocommerce-mercadopago-module' ) );
1070
  } else {
@@ -1073,144 +1720,215 @@ class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
1073
  // No ID? No process!
1074
  return false;
1075
  }
1076
-
1077
- $mp = new MP( $this->access_token );
1078
- if ( 'yes' == $this->sandbox )
1079
- $mp->sandbox_mode( true );
1080
- else
1081
- $mp->sandbox_mode( false );
 
1082
  try {
1083
- $access_token = array( "access_token" => $mp->get_access_token() );
1084
- if ( $data[ "type" ] == 'payment' ) {
1085
- $payment_info = $mp->get( "/v1/payments/" . $data[ "data_id" ], $access_token, false );
1086
- if ( !is_wp_error( $payment_info ) &&
1087
- ( $payment_info[ "status" ] == 200 || $payment_info[ "status" ] == 201 ) ) {
1088
- return $payment_info[ 'response' ];
 
 
 
1089
  } else {
1090
- if ( 'yes' == $this->debug ) {
1091
- $this->log->add( $this->id, $this->id .
1092
- ': @[check_ipn_request_is_valid] - error when processing received data: ' .
1093
- json_encode( $payment_info, JSON_PRETTY_PRINT ) );
 
 
1094
  }
1095
  return false;
1096
  }
1097
  }
1098
  } catch ( MercadoPagoException $e ) {
1099
  if ( 'yes' == $this->debug ) {
1100
- $this->log->add( $this->id, $this->id .
1101
- ': @[check_ipn_request_is_valid] - MercadoPagoException: ' .
1102
- json_encode( array( "status" => $e->getCode(), "message" => $e->getMessage() ) ) );
 
 
1103
  }
1104
  return false;
1105
  }
1106
  return true;
1107
  }
1108
-
1109
- // Properly handles each case of notification, based in payment status.
 
 
 
1110
  public function successful_request( $data ) {
 
1111
  if ( 'yes' == $this->debug ) {
1112
- $this->log->add( $this->id, $this->id .
1113
- ': @[successful_request] - starting to process ipn update...' );
1114
- }
1115
- $order_key = $data[ 'external_reference' ];
1116
- if ( !empty( $order_key ) ) {
1117
- $order_id = (int) str_replace( $this->invoice_prefix, '', $order_key );
1118
- $order = new WC_Order( $order_id );
1119
- // Checks whether the invoice number matches the order, if true processes the payment
1120
- if ( $order->id === $order_id ) {
1121
- if ( 'yes' == $this->debug ) {
1122
- $this->log->add( $this->id, $this->id .
1123
- ': @[successful_request] - got order with ID ' . $order->id .
1124
- ' and status ' . $data[ 'status' ] );
1125
- }
1126
- // Order details.
1127
- if ( !empty( $data[ 'payer' ][ 'email' ] ) ) {
1128
- update_post_meta(
1129
- $order_id,
1130
- __( 'Payer email',
1131
- 'woocommerce-mercadopago-module' ),
1132
- $data[ 'payer' ][ 'email' ]
1133
- );
1134
- }
1135
- if ( !empty( $data[ 'payment_type_id' ] ) ) {
1136
- update_post_meta(
1137
- $order_id,
1138
- __( 'Payment type',
1139
- 'woocommerce-mercadopago-module' ),
1140
- $data[ 'payment_type_id' ]
1141
- );
1142
- }
1143
- if ( !empty( $data ) ) {
1144
- update_post_meta(
1145
- $order_id,
1146
- __( 'Mercado Pago Payment ID',
1147
- 'woocommerce-mercadopago-module' ),
1148
- $data[ 'id' ]
1149
- );
1150
- }
1151
- // Switch the status and update in WooCommerce
1152
- switch ( $data[ 'status' ] ) {
1153
- case 'approved':
1154
- $order->add_order_note(
1155
- 'Mercado Pago: ' . __( 'Payment approved.',
1156
- 'woocommerce-mercadopago-module' )
1157
- );
1158
- $this->checkAndSaveCustomerCard( $data );
1159
- $order->payment_complete();
1160
- break;
1161
- case 'pending':
1162
- $order->add_order_note(
1163
- 'Mercado Pago: ' . __( 'Customer haven\'t paid yet.',
1164
- 'woocommerce-mercadopago-module' )
1165
- );
1166
- break;
1167
- case 'in_process':
1168
- $order->update_status(
1169
- 'on-hold',
1170
- 'Mercado Pago: ' . __( 'Payment under review.',
1171
- 'woocommerce-mercadopago-module' )
1172
- );
1173
- break;
1174
- case 'rejected':
1175
- $order->update_status(
1176
- 'failed',
1177
- 'Mercado Pago: ' . __( 'The payment was refused. The customer can try again.',
1178
- 'woocommerce-mercadopago-module' )
1179
- );
1180
- break;
1181
- case 'refunded':
1182
- $order->update_status(
1183
- 'refunded',
1184
- 'Mercado Pago: ' . __( 'The payment was refunded to the customer.',
1185
- 'woocommerce-mercadopago-module' )
1186
- );
1187
- break;
1188
- case 'cancelled':
1189
- $order->update_status(
1190
- 'cancelled',
1191
- 'Mercado Pago: ' . __( 'The payment was cancelled.',
1192
- 'woocommerce-mercadopago-module' )
1193
- );
1194
- break;
1195
- case 'in_mediation':
1196
- $order->add_order_note(
1197
- 'Mercado Pago: ' . __( 'The payment is under mediation or it was charged-back.',
1198
- 'woocommerce-mercadopago-module' )
1199
- );
1200
- break;
1201
- case 'charged-back':
1202
- $order->add_order_note(
1203
- 'Mercado Pago: ' . __( 'The payment is under mediation or it was charged-back.',
1204
- 'woocommerce-mercadopago-module' )
1205
- );
1206
- break;
1207
- default:
1208
- break;
1209
- }
1210
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1211
  }
1212
  }
1213
 
1214
  }
1215
 
1216
- new WC_WooMercadoPagoCustom_Gateway();
1
  <?php
2
+
3
  /**
4
  * Part of Woo Mercado Pago Module
5
  * Author - Mercado Pago
6
  * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
7
+ * Copyright - Copyright(c) MercadoPago [https://www.mercadopago.com]
8
+ * License - https://www.gnu.org/licenses/gpl.html GPL version 2 or higher
9
  */
10
 
11
  // This include Mercado Pago library SDK
12
+ require_once dirname( __FILE__ ) . '/sdk/lib/mercadopago.php';
13
 
14
+ /**
15
+ * Summary: Extending from WooCommerce Payment Gateway class.
16
+ * Description: This class implements Mercado Pago custom checkout.
17
+ * @since 2.0.0
18
+ */
19
  class WC_WooMercadoPagoCustom_Gateway extends WC_Payment_Gateway {
20
 
21
+ public function __construct( $is_instance = false ) {
22
+
23
+ // Creating PHP version message.
24
+ $min_php_message = phpversion() >= WC_WooMercadoPago_Module::MIN_PHP ?
25
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
26
+ __( 'Your PHP version is OK.', 'woocommerce-mercadopago-module' ) :
27
+ '<img width="14" height="14" src="' . plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
28
+ sprintf(
29
+ __( 'Your PHP version do not support this module. You have %s, minimal required is %s.', 'woocommerce-mercadopago-module' ),
30
+ phpversion(), WC_WooMercadoPago_Module::MIN_PHP
31
+ );
32
+ // Check cURL.
33
+ $curl_message = in_array( 'curl', get_loaded_extensions() ) ?
34
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
35
+ __( 'cURL is installed.', 'woocommerce-mercadopago-module' ) :
36
+ '<img width="14" height="14" src="' . plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
37
+ __( 'cURL is not installed.', 'woocommerce-mercadopago-module' );
38
+ // Check SSL.
39
+ $is_ssl_message = empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ?
40
+ '<img width="14" height="14" src="' . plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
41
+ __( 'SSL is missing in your site.', 'woocommerce-mercadopago-module' ) :
42
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
43
+ __( 'Your site has SSL enabled.', 'woocommerce-mercadopago-module' );
44
+
45
+ // Mercado Pago fields.
46
+ $this->mp = null;
 
 
 
 
 
 
47
  $this->site_id = null;
48
+ $this->collector_id = null;
49
+ $this->currency_ratio = -1;
50
+ $this->is_test_user = false;
51
+
52
+ // Auxiliary fields.
53
+ $this->currency_message = '';
54
+ $this->country_configs = array();
55
  $this->store_categories_id = array();
56
+ $this->store_categories_description = array();
57
+
58
+ // WooCommerce fields.
59
+ $this->supports = array( 'products', 'refunds' );
60
  $this->id = 'woocommerce-mercadopago-custom-module';
61
+ $this->domain = get_site_url() . '/index.php';
62
  $this->method_title = __( 'Mercado Pago - Credit Card', 'woocommerce-mercadopago-module' );
63
  $this->method_description = '<img width="200" height="52" src="' .
64
+ plugins_url(
65
+ 'images/mplogo.png',
66
+ plugin_dir_path( __FILE__ )
67
+ ) . '"><br><br>' . '<strong>' .
68
+ __( 'This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store.', 'woocommerce-mercadopago-module' ) .
69
+ '</strong>' . '<br><br>' .
70
+ $min_php_message . '<br>' .
71
+ $is_ssl_message . '<br>' .
72
+ $curl_message;
73
+
74
+ // Fields used in Mercado Pago Module configuration page.
75
  $this->public_key = $this->get_option( 'public_key' );
76
  $this->access_token = $this->get_option( 'access_token' );
77
  $this->title = $this->get_option( 'title' );
81
  $this->binary_mode = $this->get_option( 'binary_mode' );
82
  $this->category_id = $this->get_option( 'category_id' );
83
  $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' );
84
+ $this->currency_conversion = $this->get_option( 'currency_conversion', false );
85
+ $this->gateway_discount = $this->get_option( 'gateway_discount', 0 );
86
  $this->sandbox = $this->get_option( 'sandbox', false );
87
  $this->debug = $this->get_option( 'debug', false );
88
+
89
+ // Logging and debug.
90
+ if ( 'yes' == $this->debug) {
91
+ if ( class_exists( 'WC_Logger' ) ) {
92
+ $this->log = new WC_Logger();
93
+ } else {
94
+ $this->log = WC_MercadoPago_Module::woocommerce_instance()->logger();
95
+ }
96
+ }
97
+
98
  // Render our configuration page and init/load fields.
99
  $this->init_form_fields();
100
  $this->init_settings();
101
+
102
+ // Used by IPN to receive IPN incomings.
103
+ add_action(
104
  'woocommerce_api_wc_woomercadopagocustom_gateway',
105
+ array( $this, 'process_http_request' )
106
  );
107
+ // Used by IPN to process valid incomings.
108
+ add_action(
109
  'valid_mercadopagocustom_ipn_request',
110
+ array( $this, 'successful_request' )
111
  );
112
+ // process the cancel order meta box order action
113
+ add_action(
114
+ 'woocommerce_order_action_cancel_order',
115
+ array( $this, 'process_cancel_order_meta_box_actions' )
116
+ );
117
+ // Used in settings page to hook "save settings" action.
118
+ add_action(
119
  'woocommerce_update_options_payment_gateways_' . $this->id,
120
  array( $this, 'process_admin_options' )
121
  );
122
+ // Scripts for custom checkout.
123
+ add_action(
124
  'wp_enqueue_scripts',
125
+ array( $this, 'custom_checkout_scripts' )
126
  );
127
+ // Apply the discounts.
128
+ add_action(
129
  'woocommerce_cart_calculate_fees',
130
  array( $this, 'add_discount_custom' ), 10
131
  );
132
+ // Display discount in payment method title.
133
+ add_filter(
134
+ 'woocommerce_gateway_title',
135
+ array( $this, 'get_payment_method_title_custom' ), 10, 2
136
+ );
137
+ // Used in settings page to hook "save settings" action.
138
+ add_action(
139
+ 'woocommerce_update_options_payment_gateways_' . $this->id,
140
+ array( $this, 'custom_process_admin_options' )
141
+ );
142
 
143
+ if ( ! empty( $this->settings['enabled'] ) && $this->settings['enabled'] == 'yes' ) {
144
+ if ( $is_instance ) {
145
+ if ( empty( $this->public_key) || empty( $this->access_token ) ) {
146
+ // Verify if public_key or access_token is empty.
147
+ add_action( 'admin_notices', array( $this, 'credentials_missing_message' ) );
148
+ } else {
149
+ if ( empty( $this->sandbox) && $this->sandbox == 'no' ) {
150
+ // Verify if SSL is supported.
151
+ add_action( 'admin_notices', array( $this, 'check_ssl_absence' ) );
152
+ }
153
+ }
154
  } else {
155
+ // Scripts for order configuration.
156
+ add_action(
157
+ 'woocommerce_after_checkout_form',
158
+ array( $this, 'add_checkout_script' )
159
+ );
160
+ // Checkout updates.
161
+ add_action(
162
+ 'woocommerce_thankyou',
163
+ array( $this, 'update_checkout_status' )
164
+ );
165
  }
166
  }
167
+
168
  }
169
+
170
+ /**
171
+ * Summary: Initialise Gateway Settings Form Fields.
172
+ * Description: Initialise Gateway settings form fields with a customized page.
173
+ */
174
  public function init_form_fields() {
175
+
176
+ // If module is disabled, we do not need to load and process the settings page.
177
+ if ( empty( $this->settings['enabled'] ) || 'no' == $this->settings['enabled'] ) {
178
+ $this->form_fields = array(
179
+ 'enabled' => array(
180
+ 'title' => __( 'Enable/Disable', 'woocommerce-mercadopago-module' ),
181
+ 'type' => 'checkbox',
182
+ 'label' => __( 'Enable Custom Checkout', 'woocommerce-mercadopago-module' ),
183
+ 'default' => 'no'
184
+ )
185
+ );
186
+ return;
187
+ }
188
+
189
  $api_secret_locale = sprintf(
190
  '<a href="https://www.mercadopago.com/mla/account/credentials?type=custom" target="_blank">%s</a>, ' .
191
  '<a href="https://www.mercadopago.com/mlb/account/credentials?type=custom" target="_blank">%s</a>, ' .
203
  __( 'or', 'woocommerce-mercadopago-module' ),
204
  __( 'Venezuela', 'woocommerce-mercadopago-module' )
205
  );
206
+
207
  // Trigger API to get payment methods and site_id, also validates public_key/access_token.
208
+ if ( $this->validate_credentials() ) {
209
+ // checking the currency.
210
+ $this->currency_message = '';
211
+ if ( ! $this->is_supported_currency() && 'yes' == $this->settings['enabled'] ) {
212
+ if ( $this->currency_conversion == 'no' ) {
213
+ $this->currency_ratio = -1;
214
+ $this->currency_message .= WC_WooMercadoPago_Module::build_currency_not_converted_msg(
215
+ $this->country_configs['currency'],
216
+ $this->country_configs['country_name']
217
+ );
218
+ } elseif ( $this->currency_conversion == 'yes' && $this->currency_ratio != -1 ) {
219
+ $this->currency_message .= WC_WooMercadoPago_Module::build_currency_converted_msg(
220
+ $this->country_configs['currency'],
221
+ $this->currency_ratio
222
+ );
 
 
 
 
 
 
 
 
 
 
 
223
  } else {
224
  $this->currency_ratio = -1;
225
+ $this->currency_message .=
226
+ WC_WooMercadoPago_Module::build_currency_conversion_err_msg(
227
+ $this->country_configs['currency']
228
+ );
229
  }
230
+ } else {
231
+ $this->currency_ratio = -1;
 
 
 
 
 
 
 
232
  }
233
+ $this->credentials_message = WC_WooMercadoPago_Module::build_valid_credentials_msg(
234
+ $this->country_configs['country_name'],
235
+ $this->site_id
236
+ );
237
+ } else {
238
+ $this->credentials_message = WC_WooMercadoPago_Module::build_invalid_credentials_msg();
239
+ }
240
+
241
+ // fill categories (can be handled without credentials).
242
+ $categories = WC_WooMercadoPago_Module::get_categories();
243
+ $this->store_categories_id = $categories['store_categories_id'];
244
+ $this->store_categories_description = $categories['store_categories_description'];
245
+
246
+ // Validate discount field.
247
+ if ( ! is_numeric( $this->gateway_discount ) ) {
248
+ $this->gateway_discount_desc = '<img width="12" height="12" src="' .
249
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
250
+ __( 'This field should be an integer greater or equal 0 and smaller than 100.', 'woocommerce-mercadopago-module' );
251
+ } elseif ( $this->gateway_discount < 0 || $this->gateway_discount >= 100 ) {
252
+ $this->gateway_discount_desc = '<img width="12" height="12" src="' .
253
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
254
+ __( 'This field should be an integer greater or equal 0 and smaller than 100.', 'woocommerce-mercadopago-module' );
255
  } else {
256
+ $this->gateway_discount_desc =
257
+ __( 'Give a percentual discount for your customers if they use this payment gateway.', 'woocommerce-mercadopago-module' );
258
+ }
259
+
 
 
 
 
 
 
 
 
260
  // This array draws each UI (text, selector, checkbox, label, etc).
261
  $this->form_fields = array(
262
  'enabled' => array(
263
  'title' => __( 'Enable/Disable', 'woocommerce-mercadopago-module' ),
264
  'type' => 'checkbox',
265
  'label' => __( 'Enable Custom Checkout', 'woocommerce-mercadopago-module' ),
266
+ 'default' => 'no'
267
  ),
268
  'credentials_title' => array(
269
  'title' => __( 'Mercado Pago Credentials', 'woocommerce-mercadopago-module' ),
270
  'type' => 'title',
271
+ 'description' => sprintf( '%s', $this->credentials_message ) . '<br>' . sprintf(
272
+ __( 'You can obtain your credentials for', 'woocommerce-mercadopago-module' ) .
273
+ ' %s.', $api_secret_locale
274
+ )
275
  ),
276
  'public_key' => array(
277
  'title' => 'Public key',
278
  'type' => 'text',
279
+ 'description' =>
280
+ __( 'Insert your Mercado Pago Public key.', 'woocommerce-mercadopago-module' ),
281
  'default' => '',
282
  'required' => true
283
  ),
284
  'access_token' => array(
285
  'title' => 'Access token',
286
  'type' => 'text',
287
+ 'description' =>
288
+ __( 'Insert your Mercado Pago Access token.', 'woocommerce-mercadopago-module' ),
289
  'default' => '',
290
  'required' => true
291
  ),
292
  'ipn_url' => array(
293
+ 'title' =>
294
+ __( 'Instant Payment Notification (IPN) URL', 'woocommerce-mercadopago-module' ),
295
  'type' => 'title',
296
+ 'description' => sprintf(
297
+ __( 'Your IPN URL to receive instant payment notifications is', 'woocommerce-mercadopago-module' ) .
298
+ '<br>%s', '<code>' . WC()->api_request_url( 'WC_WooMercadoPagoCustom_Gateway' ) . '</code>.'
299
+ )
300
  ),
301
  'checkout_options_title' => array(
302
  'title' => __( 'Checkout Options', 'woocommerce-mercadopago-module' ),
306
  'title' => array(
307
  'title' => __( 'Title', 'woocommerce-mercadopago-module' ),
308
  'type' => 'text',
309
+ 'description' =>
310
+ __( 'Title shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
311
  'default' => __( 'Mercado Pago - Credit Card', 'woocommerce-mercadopago-module' )
312
  ),
313
  'description' => array(
314
  'title' => __( 'Description', 'woocommerce-mercadopago-module' ),
315
  'type' => 'textarea',
316
+ 'description' =>
317
+ __( 'Description shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
318
  'default' => __( 'Pay with Mercado Pago', 'woocommerce-mercadopago-module' )
319
  ),
320
  'statement_descriptor' => array(
324
  'default' => __( 'Mercado Pago', 'woocommerce-mercadopago-module' )
325
  ),
326
  'coupon_mode' => array(
327
+ 'title' => __( 'Coupons', 'woocommerce-mercadopago-module' ),
328
+ 'type' => 'checkbox',
329
+ 'label' => __( 'Enable coupons of discounts', 'woocommerce-mercadopago-module' ),
330
  'default' => 'no',
331
+ 'description' =>
332
+ __( 'If there is a Mercado Pago campaign, allow your store to give discounts to customers.', 'woocommerce-mercadopago-module' )
333
  ),
334
  'binary_mode' => array(
335
+ 'title' => __( 'Binary Mode', 'woocommerce-mercadopago-module' ),
336
+ 'type' => 'checkbox',
337
+ 'label' => __( 'Enable binary mode for checkout status', 'woocommerce-mercadopago-module' ),
338
  'default' => 'no',
339
+ 'description' =>
340
+ __( 'When charging a credit card, only [approved] or [reject] status will be taken.', 'woocommerce-mercadopago-module' )
341
  ),
342
  'category_id' => array(
343
  'title' => __( 'Store Category', 'woocommerce-mercadopago-module' ),
344
  'type' => 'select',
345
+ 'description' =>
346
+ __( 'Define which type of products your store sells.', 'woocommerce-mercadopago-module' ),
347
  'options' => $this->store_categories_id
348
  ),
349
  'invoice_prefix' => array(
350
  'title' => __( 'Store Identificator', 'woocommerce-mercadopago-module' ),
351
  'type' => 'text',
352
+ 'description' =>
353
+ __( 'Please, inform a prefix to your store.', 'woocommerce-mercadopago-module' )
354
+ . ' ' .
355
+ __( 'If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same identificators.', 'woocommerce-mercadopago-module' ),
356
  'default' => 'WC-'
357
  ),
358
  'currency_conversion' => array(
359
  'title' => __( 'Currency Conversion', 'woocommerce-mercadopago-module' ),
360
  'type' => 'checkbox',
361
+ 'label' =>
362
+ __( 'If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio.', 'woocommerce-mercadopago-module' ),
363
  'default' => 'no',
364
  'description' => sprintf( '%s', $this->currency_message )
365
  ),
366
+ 'gateway_discount' => array(
367
+ 'title' => __( 'Discount by Gateway', 'woocommerce-mercadopago-module' ),
368
+ 'type' => 'number',
369
+ 'description' => $this->gateway_discount_desc,
370
+ 'default' => '0'
371
+ ),
372
  'testing' => array(
373
  'title' => __( 'Test and Debug Options', 'woocommerce-mercadopago-module' ),
374
  'type' => 'title',
379
  'type' => 'checkbox',
380
  'label' => __( 'Enable Mercado Pago Sandbox', 'woocommerce-mercadopago-module' ),
381
  'default' => 'no',
382
+ 'description' =>
383
+ __( 'This option allows you to test payments inside a sandbox environment.', 'woocommerce-mercadopago-module' ),
384
  ),
385
  'debug' => array(
386
  'title' => __( 'Debug and Log', 'woocommerce-mercadopago-module' ),
387
  'type' => 'checkbox',
388
  'label' => __( 'Enable log', 'woocommerce-mercadopago-module' ),
389
  'default' => 'no',
390
+ 'description' => sprintf(
391
+ __( 'Register event logs of Mercado Pago, such as API requests, in the file', 'woocommerce-mercadopago-module' ) .
392
+ ' %s.', $this->build_log_path_string() . '.<br>' .
393
+ __( 'File location: ', 'woocommerce-mercadopago-module' ) .
394
+ '<code>wordpress/wp-content/uploads/wc-logs/' . $this->id . '-' .
395
+ sanitize_file_name( wp_hash( $this->id ) ) . '.log</code>' )
396
  )
397
  );
398
+
399
+ }
400
+
401
+ /**
402
+ * Processes and saves options.
403
+ * If there is an error thrown, will continue to save and validate fields, but will leave the
404
+ * erroring field out.
405
+ * @return bool was anything saved?
406
+ */
407
+ public function custom_process_admin_options() {
408
+ $this->init_settings();
409
+
410
+ $post_data = $this->get_post_data();
411
+
412
+ foreach ( $this->get_form_fields() as $key => $field ) {
413
+ if ( 'title' !== $this->get_field_type( $field ) ) {
414
+ try {
415
+ $this->settings[$key] = $this->get_field_value( $key, $field, $post_data );
416
+ } catch ( Exception $e ) {
417
+ $this->add_error( $e->getMessage() );
418
+ }
419
+ }
420
+ }
421
+
422
+ if ( ! empty( $this->settings['public_key'] ) && ! empty( $this->settings['access_token'] ) ) {
423
+ $this->mp = new MP(
424
+ WC_WooMercadoPago_Module::get_module_version(),
425
+ $this->settings['access_token']
426
+ );
427
+ } else {
428
+ $this->mp = null;
429
+ }
430
+
431
+ // analytics
432
+ if ( $this->mp != null && ! $this->is_test_user ) {
433
+ $infra_data = WC_WooMercadoPago_Module::get_common_settings();
434
+ $infra_data['checkout_custom_credit_card'] = ( $this->settings['enabled'] == 'yes' ? 'true' : 'false' );
435
+ $infra_data['checkout_custom_credit_card_coupon'] = ( $this->settings['coupon_mode'] == 'yes' ? 'true' : 'false' );
436
+ $response = $this->mp->analytics_save_settings( $infra_data );
437
+ if ( 'yes' == $this->debug) {
438
+ $this->log->add(
439
+ $this->id,
440
+ '[custom_process_admin_options] - analytics info response: ' .
441
+ json_encode( $response, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
442
+ );
443
+ }
444
+ }
445
+
446
+ return update_option(
447
+ $this->get_option_key(),
448
+ apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings )
449
+ );
450
  }
451
+
452
+ /**
453
+ * Handles the manual order refunding in server-side.
454
+ */
455
+ public function process_refund( $order_id, $amount = null, $reason = '' ) {
456
+
457
+ $payments = get_post_meta(
458
+ $order_id,
459
+ '_Mercado_Pago_Payment_IDs',
460
+ true
461
+ );
462
+
463
+ // Validate.
464
+ if ( $this->mp == null || empty( $payments ) ) {
465
+ if ( 'yes' == $this->debug ) {
466
+ $this->log->add(
467
+ $this->id,
468
+ '[process_refund] - no payments or credentials invalid'
469
+ );
470
+ }
471
  return false;
472
+ }
473
+
474
+ $total_available = 0;
475
+ $payment_structs = array();
476
+ $payment_ids = explode( ', ', $payments );
477
+ foreach ( $payment_ids as $p_id ) {
478
+ $p = get_post_meta(
479
+ $order_id,
480
+ 'Mercado Pago - Payment ' . $p_id,
481
+ true
482
+ );
483
+ $p = explode( '/', $p );
484
+ $paid_arr = explode( ' ', substr( $p[2], 1, -1 ) );
485
+ $paid = ( (float) $paid_arr[1] );
486
+ $refund_arr = explode( ' ', substr( $p[3], 1, -1 ) );
487
+ $refund = ( (float) $refund_arr[1] );
488
+ $p_struct = array(
489
+ 'id' => $p_id,
490
+ 'available_to_refund' => $paid - $refund
491
+ );
492
+ $total_available += $paid - $refund;
493
+ $payment_structs[] = $p_struct;
494
+ }
495
+
496
+ if ( 'yes' == $this->debug ) {
497
+ $this->log->add(
498
+ $this->id,
499
+ '[process_refund] - refunding ' . $amount . ' because of ' . $reason . ' and payments ' .
500
+ json_encode( $payment_structs, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
501
+ );
502
+ }
503
+
504
+ // Do not allow refund more than available or invalid amounts.
505
+ if ( $amount > $total_available || $amount <= 0 ) {
506
+ return false;
507
+ }
508
+
509
+ $remaining_to_refund = $amount;
510
+ foreach ( $payment_structs as $to_refund ) {
511
+ if ( $remaining_to_refund <= $to_refund['available_to_refund'] ) {
512
+ // We want to refund an amount that is less than the available for this payment, so we
513
+ // can just refund and return.
514
+ $response = $this->mp->partial_refund_payment(
515
+ $to_refund['id'],
516
+ $remaining_to_refund,
517
+ $reason,
518
+ $this->invoice_prefix . $order_id
519
+ );
520
+ $message = $response['response']['message'];
521
+ $status = $response['status'];
522
+ if ( 'yes' == $this->debug ) {
523
+ $this->log->add(
524
+ $this->id,
525
+ '[process_refund] - refund payment of id ' . $p_id .
526
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
527
+ );
528
+ }
529
+ if ( $status >= 200 && $status < 300 ) {
530
+ return true;
531
+ } else {
532
+ return false;
533
+ }
534
+ } elseif ( $to_refund['available_to_refund'] > 0 ) {
535
+ // We want to refund an amount that exceeds the available for this payment, so we
536
+ // totally refund this payment, and try to complete refund in other/next payments.
537
+ $response = $this->mp->partial_refund_payment(
538
+ $to_refund['id'],
539
+ $to_refund['available_to_refund'],
540
+ $reason,
541
+ $this->invoice_prefix . $order_id
542
+ );
543
+ $message = $response['response']['message'];
544
+ $status = $response['status'];
545
+ if ( 'yes' == $this->debug ) {
546
+ $this->log->add(
547
+ $this->id,
548
+ '[process_refund] - refund payment of id ' . $p_id .
549
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
550
+ );
551
+ }
552
+ if ( $status < 200 || $status >= 300 ) {
553
+ return false;
554
+ }
555
+ $remaining_to_refund -= $to_refund['available_to_refund'];
556
+ }
557
+ if ( $remaining_to_refund == 0 )
558
+ return true;
559
+ }
560
+
561
+ // Reaching here means that there we run out of payments, and there is an amount
562
+ // remaining to be refund, which is impossible as it implies refunding more than
563
+ // available on paid amounts.
564
+ return false;
565
+
566
+ }
567
+
568
+ /**
569
+ * Handles the manual order cancellation in server-side.
570
+ */
571
+ public function process_cancel_order_meta_box_actions( $order ) {
572
+
573
+ // WooCommerce 3.0 or later.
574
+ if ( method_exists( $order, 'get_meta' ) ) {
575
+ $used_gateway = $order->get_meta( '_used_gateway' );
576
+ $payments = $order->get_meta( '_Mercado_Pago_Payment_IDs' );
577
  } else {
578
+ $used_gateway = get_post_meta( $order->id, '_used_gateway', true );
579
+ $payments = get_post_meta( $order->id, '_Mercado_Pago_Payment_IDs', true );
580
+ }
581
+
582
+ if ( $used_gateway != 'WC_WooMercadoPagoCustom_Gateway' ) {
583
+ return;
584
+ }
585
+
586
+ if ( 'yes' == $this->debug ) {
587
+ $this->log->add(
588
+ $this->id,
589
+ '[process_cancel_order_meta_box_actions] - cancelling payments for ' . $payments
590
+ );
591
+ }
592
+
593
+ if ( $this->mp != null && ! empty( $payments ) ) {
594
+ $payment_ids = explode( ', ', $payments );
595
+ foreach ( $payment_ids as $p_id ) {
596
+ $response = $this->mp->cancel_payment( $p_id );
597
+ $message = $response['response']['message'];
598
+ $status = $response['status'];
599
+ if ( 'yes' == $this->debug ) {
600
+ $this->log->add(
601
+ $this->id,
602
+ '[process_cancel_order_meta_box_actions] - cancel payment of id ' . $p_id .
603
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
604
+ );
605
+ }
606
+ }
607
+ } else {
608
+ if ( 'yes' == $this->debug ) {
609
+ $this->log->add(
610
+ $this->id,
611
+ '[process_cancel_order_meta_box_actions] - no payments or credentials invalid'
612
+ );
613
+ }
614
  }
615
+
616
  }
617
+
618
  /*
619
  * ========================================================================
620
+ * CHECKOUT BUSINESS RULES (CLIENT SIDE)
621
  * ========================================================================
622
  */
623
+
624
+ public function add_checkout_script() {
625
+
626
+ $public_key = $this->get_option( 'public_key' );
627
+
628
+ if ( ! empty( $public_key ) && ! $this->is_test_user ) {
629
+
630
+ $w = WC_WooMercadoPago_Module::woocommerce_instance();
631
+ $logged_user_email = null;
632
+ $payments = array();
633
+ $gateways = WC()->payment_gateways->get_available_payment_gateways();
634
+ foreach ( $gateways as $g ) {
635
+ $payments[] = $g->id;
636
+ }
637
+ $payments = str_replace( '-', '_', implode( ', ', $payments ) );
638
+
639
+ if ( wp_get_current_user()->ID != 0 ) {
640
+ $logged_user_email = wp_get_current_user()->user_email;
641
+ }
642
+
643
+ ?>
644
+ <script src="https://secure.mlstatic.com/modules/javascript/analytics.js"></script>
645
+ <script type="text/javascript">
646
+ var MA = ModuleAnalytics;
647
+ MA.setPublicKey( '<?php echo $public_key; ?>' );
648
+ MA.setPlatform( 'WooCommerce' );
649
+ MA.setPlatformVersion( '<?php echo $w->version; ?>' );
650
+ MA.setModuleVersion( '<?php echo WC_WooMercadoPago_Module::VERSION; ?>' );
651
+ MA.setPayerEmail( '<?php echo ( $logged_user_email != null ? $logged_user_email : "" ); ?>' );
652
+ MA.setUserLogged( <?php echo ( empty( $logged_user_email ) ? 0 : 1 ); ?> );
653
+ MA.setInstalledModules( '<?php echo $payments; ?>' );
654
+ MA.post();
655
+ </script>
656
+ <?php
657
+
658
+ }
659
+
660
+ }
661
+
662
+ public function update_checkout_status( $order_id ) {
663
+
664
+ $public_key = $this->get_option( 'public_key' );
665
+
666
+ if ( ! empty( $public_key ) && ! $this->is_test_user ) {
667
+
668
+ if ( get_post_meta( $order_id, '_used_gateway', true ) != 'WC_WooMercadoPagoCustom_Gateway' ) {
669
+ return;
670
+ }
671
+
672
+ if ( 'yes' == $this->debug ) {
673
+ $this->log->add(
674
+ $this->id,
675
+ '[update_checkout_status] - updating order of ID ' . $order_id
676
+ );
677
+ }
678
+
679
+ echo '<script src="https://secure.mlstatic.com/modules/javascript/analytics.js"></script>
680
+ <script type="text/javascript">
681
+ var MA = ModuleAnalytics;
682
+ MA.setPublicKey( "' . $public_key . '" );
683
+ MA.setPaymentType("credit_card");
684
+ MA.setCheckoutType("custom");
685
+ MA.put();
686
+ </script>';
687
+
688
+ }
689
+
690
+ }
691
+
692
+ public function custom_checkout_scripts() {
693
  if ( is_checkout() && $this->is_available() ) {
694
+ if ( ! get_query_var( 'order-received' ) ) {
695
  wp_enqueue_style(
696
  'woocommerce-mercadopago-style', plugins_url(
697
  'assets/css/custom_checkout_mercadopago.css',
702
  }
703
  }
704
  }
705
+
706
  public function payment_fields() {
707
  $amount = $this->get_order_total();
708
 
710
  'public_key' => $this->public_key,
711
  'site_id' => $this->site_id,
712
  'images_path' => plugins_url( 'images/', plugin_dir_path( __FILE__ ) ),
713
+ 'banner_path' => $this->country_configs['checkout_banner_custom'],
714
+ 'amount' => $amount *
715
+ ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ),
716
  'coupon_mode' => $this->coupon_mode,
717
  'is_currency_conversion' => $this->currency_ratio,
718
  'woocommerce_currency' => get_woocommerce_currency(),
719
+ 'account_currency' => $this->country_configs['currency'],
720
+ 'discount_action_url' => $this->domain .
721
+ '/woocommerce-mercadopago-module/?wc-api=WC_WooMercadoPagoCustom_Gateway',
722
  'form_labels' => array(
723
+ 'form' => array(
724
+ 'payment_converted' =>
725
+ __( 'Payment converted from', 'woocommerce-mercadopago-module' ),
726
+ 'to' => __( 'to', 'woocommerce-mercadopago-module' ),
727
+ 'coupon_empty' =>
728
+ __( 'Please, inform your coupon code', 'woocommerce-mercadopago-module' ),
729
+ 'apply' => __( 'Apply', 'woocommerce-mercadopago-module' ),
730
+ 'remove' => __( 'Remove', 'woocommerce-mercadopago-module' ),
731
+ 'discount_info1' => __( 'You will save', 'woocommerce-mercadopago-module' ),
732
+ 'discount_info2' => __( 'with discount from', 'woocommerce-mercadopago-module' ),
733
+ 'discount_info3' => __( 'Total of your purchase:', 'woocommerce-mercadopago-module' ),
734
+ 'discount_info4' =>
735
+ __( 'Total of your purchase with discount:', 'woocommerce-mercadopago-module' ),
736
+ 'discount_info5' => __( '*Uppon payment approval', 'woocommerce-mercadopago-module' ),
737
+ 'discount_info6' =>
738
+ __( 'Terms and Conditions of Use', 'woocommerce-mercadopago-module' ),
739
+ 'coupon_of_discounts' => __( 'Discount Coupon', 'woocommerce-mercadopago-module' ),
740
+ 'label_other_bank' => __( 'Other Bank', 'woocommerce-mercadopago-module' ),
741
+ 'label_choose' => __( 'Choose', 'woocommerce-mercadopago-module' ),
742
+ 'your_card' => __( 'Your Card', 'woocommerce-mercadopago-module' ),
743
+ 'other_cards' => __( 'Other Cards', 'woocommerce-mercadopago-module' ),
744
+ 'other_card' => __( 'Other Card', 'woocommerce-mercadopago-module' ),
745
+ 'ended_in' => __( 'ended in', 'woocommerce-mercadopago-module' ),
746
+ 'card_holder_placeholder' =>
747
+ __( ' as it appears in your card ...', 'woocommerce-mercadopago-module' ),
748
+ 'payment_method' => __( 'Payment Method', 'woocommerce-mercadopago-module' ),
749
+ 'credit_card_number' => __( 'Credit card number', 'woocommerce-mercadopago-module' ),
750
+ 'expiration_month' => __( 'Expiration month', 'woocommerce-mercadopago-module' ),
751
+ 'expiration_year' => __( 'Expiration year', 'woocommerce-mercadopago-module' ),
752
+ 'year' => __( 'Year', 'woocommerce-mercadopago-module' ),
753
+ 'month' => __( 'Month', 'woocommerce-mercadopago-module' ),
754
+ 'card_holder_name' => __( 'Card holder name', 'woocommerce-mercadopago-module' ),
755
+ 'security_code' => __( 'Security code', 'woocommerce-mercadopago-module' ),
756
+ 'document_type' => __( 'Document Type', 'woocommerce-mercadopago-module' ),
757
+ 'document_number' => __( 'Document number', 'woocommerce-mercadopago-module' ),
758
+ 'issuer' => __( 'Issuer', 'woocommerce-mercadopago-module' ),
759
+ 'installments' => __( 'Installments', 'woocommerce-mercadopago-module' )
760
+ ),
761
+ 'error' => array(
762
+ // Card number.
763
+ '205' => __( 'Parameter cardNumber can not be null/empty', 'woocommerce-mercadopago-module' ),
764
+ 'E301' => __( 'Invalid Card Number', 'woocommerce-mercadopago-module' ),
765
+ // Expiration date.
766
+ '208' => __( 'Invalid Expiration Date', 'woocommerce-mercadopago-module' ),
767
+ '209' => __( 'Invalid Expiration Date', 'woocommerce-mercadopago-module' ),
768
+ '325' => __( 'Invalid Expiration Date', 'woocommerce-mercadopago-module' ),
769
+ '326' => __( 'Invalid Expiration Date', 'woocommerce-mercadopago-module' ),
770
+ // Card holder name.
771
+ '221' => __( 'Parameter cardholderName can not be null/empty', 'woocommerce-mercadopago-module' ),
772
+ '316' => __( 'Invalid Card Holder Name', 'woocommerce-mercadopago-module' ),
773
+ // Security code.
774
+ '224' => __( 'Parameter securityCode can not be null/empty', 'woocommerce-mercadopago-module' ),
775
+ 'E302' => __( 'Invalid Security Code', 'woocommerce-mercadopago-module' ),
776
+ // Doc type.
777
+ '212' => __( 'Parameter docType can not be null/empty', 'woocommerce-mercadopago-module' ),
778
+ '322' => __( 'Invalid Document Type', 'woocommerce-mercadopago-module' ),
779
+ // Doc number.
780
+ '214' => __( 'Parameter docNumber can not be null/empty', 'woocommerce-mercadopago-module' ),
781
+ '324' => __( 'Invalid Document Number', 'woocommerce-mercadopago-module' ),
782
+ // Doc sub type.
783
+ '213' => __( 'The parameter cardholder.document.subtype can not be null or empty', 'woocommerce-mercadopago-module' ),
784
+ '323' => __( 'Invalid Document Sub Type', 'woocommerce-mercadopago-module' ),
785
+ // Issuer.
786
+ '220' => __( 'Parameter cardIssuerId can not be null/empty', 'woocommerce-mercadopago-module' )
787
  )
788
  )
789
  );
790
 
791
+ // Find logged user.
792
+ $customer_cards = array();
793
+ try {
794
+ $logged_user_email = null;
795
+ $parameters['customerId'] = null;
796
+ $parameters['payer_email'] = null;
797
  if ( wp_get_current_user()->ID != 0 ) {
 
798
  $logged_user_email = wp_get_current_user()->user_email;
 
 
 
 
799
  }
800
+ if ( isset( $logged_user_email ) ) {
801
+ $customer = $this->mp->get_or_create_customer( $logged_user_email);
802
+ if ( isset( $logged_user_email ) ) {
803
+ $parameters['payer_email'] = $logged_user_email;
804
+ }
805
+ if ( isset( $customer['id'] ) ) {
806
+ $parameters['customerId'] = $customer['id'];
807
+ }
808
+ if ( isset( $customer['cards'] ) ) {
809
+ $customer_cards = $customer['cards'];
810
+ }
811
+ } else {
812
+ $parameters['coupon_mode'] = 'no';
813
+ }
814
+ } catch ( Exception $e ) {
815
+ $parameters['coupon_mode'] = 'no';
816
  if ( 'yes' == $this->debug ) {
817
+ $this->log->add(
818
+ $this->id,
819
+ '[process_fields] - there is a problem when retrieving information for cards: ' .
820
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
821
  );
822
  }
823
  }
824
+ $parameters['customer_cards'] = $customer_cards;
825
 
826
  wc_get_template(
827
  'credit-card/payment-form.php',
828
  $parameters,
829
  'woocommerce/mercadopago/',
830
+ WC_WooMercadoPago_Module::get_templates_path()
831
  );
832
  }
833
+
834
+ /**
835
+ * Summary: Handle the payment and processing the order.
836
+ * Description: This function is called after we click on [place_order] button, and each field is
837
+ * passed to this function through $_POST variable.
838
+ * @return an array containing the result of the processment and the URL to redirect.
839
+ */
840
  public function process_payment( $order_id ) {
841
+
842
+ if ( ! isset( $_POST['mercadopago_custom'] ) ) {
843
+ return;
844
+ }
845
+
846
+ $order = wc_get_order( $order_id );
847
+ $custom_checkout = $_POST['mercadopago_custom'];
848
+
849
+ // WooCommerce 3.0 or later.
850
+ if ( method_exists( $order, 'update_meta_data' ) ) {
851
+ $order->update_meta_data( '_used_gateway', 'WC_WooMercadoPagoCustom_Gateway' );
852
+ $order->save();
853
+ } else {
854
+ update_post_meta( $order_id, '_used_gateway', 'WC_WooMercadoPagoCustom_Gateway' );
855
+ }
856
+
857
+ // We have got parameters from checkout page, now its time to charge the card.
858
  if ( 'yes' == $this->debug ) {
859
+ $this->log->add(
860
+ $this->id,
861
+ '[process_payment] - Received [$_POST] from customer front-end page: ' .
862
+ json_encode( $_POST, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
863
+ );
864
+ }
865
+
866
+ // Mexico country case.
867
+ if ( $custom_checkout['paymentMethodId'] == '' || empty( $custom_checkout['paymentMethodId'] ) ) {
868
+ $custom_checkout['paymentMethodId'] = $custom_checkout['paymentMethodSelector'];
869
+ }
870
+
871
+ if ( isset( $custom_checkout['amount'] ) && ! empty( $custom_checkout['amount'] ) &&
872
+ isset( $custom_checkout['token'] ) && ! empty( $custom_checkout['token'] ) &&
873
+ isset( $custom_checkout['paymentMethodId'] ) && ! empty( $custom_checkout['paymentMethodId'] ) &&
874
+ isset( $custom_checkout['installments'] ) && ! empty( $custom_checkout['installments'] ) &&
875
+ $custom_checkout['installments'] != -1 ) {
876
+
877
+ $response = self::create_url( $order, $custom_checkout );
878
+
879
+ if ( array_key_exists( 'status', $response ) ) {
880
+ switch ( $response['status'] ) {
881
+ case 'approved':
882
+ WC()->cart->empty_cart();
883
+ wc_add_notice(
884
+ '<p>' .
885
+ __( $this->get_order_status( 'accredited' ), 'woocommerce-mercadopago-module' ) .
886
+ '</p>',
887
+ 'notice'
888
+ );
889
+ $order->add_order_note(
890
  'Mercado Pago: ' .
891
  __( 'Payment approved.', 'woocommerce-mercadopago-module' )
892
  );
895
  'redirect' => $order->get_checkout_order_received_url()
896
  );
897
  break;
898
+ case 'pending':
899
+ // Order approved/pending, we just redirect to the thankyou page.
900
+ return array(
901
  'result' => 'success',
902
  'redirect' => $order->get_checkout_order_received_url()
903
  );
904
  break;
905
+ case 'in_process':
906
+ // For pending, we don't know if the purchase will be made, so we must inform this status.
907
+ WC()->cart->empty_cart();
908
  wc_add_notice(
909
+ '<p>' .
910
+ __( $this->get_order_status( $response['status_detail'] ), 'woocommerce-mercadopago-module' ) .
911
+ '</p>' .
912
+ '<p><a class="button" href="' .
913
+ esc_url( $order->get_checkout_order_received_url() ) .
914
+ '">' .
915
  __( 'Check your order resume', 'woocommerce-mercadopago-module' ) .
916
  '</a></p>',
917
  'notice'
921
  'redirect' => $order->get_checkout_payment_url( true )
922
  );
923
  break;
924
+ case 'rejected':
925
+ // If rejected is received, the order will not proceed until another payment try,
926
+ // so we must inform this status.
927
  wc_add_notice(
928
+ '<p>' .
929
+ __( 'Your payment was refused. You can try again.', 'woocommerce-mercadopago-module' ) .
930
+ '<br>' .
931
+ __( $this->get_order_status( $response['status_detail'] ), 'woocommerce-mercadopago-module' ) .
932
+ '</p>' .
933
  '<p><a class="button" href="' . esc_url( $order->get_checkout_payment_url() ) . '">' .
934
  __( 'Click to try again', 'woocommerce-mercadopago-module' ) .
935
  '</a></p>',
947
  default:
948
  break;
949
  }
950
+ }
951
  } else {
952
+ // Process when fields are imcomplete.
953
  wc_add_notice(
954
+ '<p>' .
955
+ __( 'A problem was occurred when processing your payment. Are you sure you have correctly filled all information in the checkout form?', 'woocommerce-mercadopago-module' ) .
956
+ '</p>',
957
  'error'
958
  );
959
+ return array(
960
+ 'result' => 'fail',
961
+ 'redirect' => '',
962
+ );
963
  }
964
  }
965
 
966
+ /**
967
+ * Summary: Build Mercado Pago preference.
968
+ * Description: Create Mercado Pago preference and get init_point URL based in the order options
969
+ * from the cart.
970
+ * @return the preference object.
971
+ */
972
+ private function build_payment_preference( $order, $custom_checkout ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973
 
974
+ // A string to register items (workaround to deal with API problem that shows only first item).
975
+ $list_of_items = array();
976
+ $order_total = 0;
977
+ $discount_amount_of_items = 0;
978
 
979
+ // Here we build the array that contains ordered items, from customer cart.
980
  $items = array();
 
981
  if ( sizeof( $order->get_items() ) > 0 ) {
982
  foreach ( $order->get_items() as $item ) {
983
  if ( $item['qty'] ) {
984
+ $product = new WC_product( $item['product_id'] );
985
+
986
+ // WooCommerce 3.0 or later.
987
+ if ( method_exists( $product, 'get_description' ) ) {
988
+ $product_title = WC_WooMercadoPago_Module::utf8_ansi(
989
+ $product->get_name()
990
+ );
991
+ $product_content = WC_WooMercadoPago_Module::utf8_ansi(
992
+ $product->get_description()
993
+ );
994
+ } else {
995
+ $product_title = WC_WooMercadoPago_Module::utf8_ansi(
996
+ $product->post->post_title
997
+ );
998
+ $product_content = WC_WooMercadoPago_Module::utf8_ansi(
999
  $product->post->post_content
1000
+ );
1001
+ }
1002
+
1003
+ // Calculate discount for payment method.
1004
+ $unit_price = floor( ( (float) $item['line_total'] + (float) $item['line_tax'] ) *
1005
+ ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ) * 100 ) / 100;
1006
+ if ( is_numeric( $this->gateway_discount ) ) {
1007
+ if ( $this->gateway_discount >= 0 && $this->gateway_discount < 100 ) {
1008
+ $price_percent = $this->gateway_discount / 100;
1009
+ $discount = $unit_price * $price_percent;
1010
+ if ( $discount > 0 ) {
1011
+ $discount_amount_of_items += $discount;
1012
+ }
1013
+ }
1014
+ }
1015
+
1016
+ // Remove decimals if MCO/MLC
1017
+ if ( $this->site_id == 'MCO' || $this->site_id == 'MLC' ) {
1018
+ $unit_price = floor( $unit_price );
1019
+ $discount_amount_of_items = floor( $discount_amount_of_items );
1020
+ }
1021
+
1022
+ $order_total += $unit_price;
1023
+
1024
+ array_push( $list_of_items, $product_title . ' x ' . $item['qty'] );
1025
+ array_push( $items, array(
1026
+ 'id' => $item['product_id'],
1027
+ 'title' => ( html_entity_decode( $product_title ) . ' x ' . $item['qty'] ),
1028
+ 'description' => sanitize_file_name( html_entity_decode(
1029
+ // This handles description width limit of Mercado Pago.
1030
+ ( strlen( $product_content ) > 230 ?
1031
+ substr( $product_content, 0, 230 ) . '...' :
1032
+ $product_content )
1033
  ) ),
1034
  'picture_url' => wp_get_attachment_url( $product->get_image_id() ),
1035
+ 'category_id' => $this->store_categories_id[$this->category_id],
1036
  'quantity' => 1,
1037
+ 'unit_price' => $unit_price
1038
+ ) );
 
1039
  }
1040
  }
1041
  }
1042
+
1043
+ // Creates the shipment cost structure.
1044
+ $ship_cost = ( (float) $order->get_total_shipping() + (float) $order->get_shipping_tax() ) *
1045
+ ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 );
1046
+
1047
+ // Remove decimals if MCO/MLC
1048
+ if ( $this->site_id == 'MCO' || $this->site_id == 'MLC' ) {
1049
+ $ship_cost = floor( $ship_cost );
1050
+ }
1051
+
1052
+ if ( $ship_cost > 0 ) {
1053
+ $order_total += $ship_cost;
1054
+ $item = array(
1055
+ 'id' => 2147483647,
1056
+ 'title' => sanitize_file_name( $order->get_shipping_to_display() ),
1057
+ 'description' => __( 'Shipping service used by store', 'woocommerce-mercadopago-module' ),
1058
+ 'category_id' => $this->store_categories_id[$this->category_id],
1059
+ 'quantity' => 1,
1060
+ 'unit_price' => floor( $ship_cost * 100 ) / 100
1061
+ );
1062
+ $items[] = $item;
1063
+ }
1064
+
1065
+ // Discounts features.
1066
+ if ( isset( $custom_checkout['discount'] ) && $custom_checkout['discount'] != '' &&
1067
+ $custom_checkout['discount'] > 0 && isset( $custom_checkout['coupon_code'] ) &&
1068
+ $custom_checkout['coupon_code'] != '' &&
1069
+ WC()->session->chosen_payment_method == 'woocommerce-mercadopago-custom-module' ) {
1070
+
1071
+ // Remove decimals if MCO/MLC
1072
+ if ( $this->site_id == 'MCO' || $this->site_id == 'MLC' ) {
1073
+ $custom_checkout['discount'] = floor( $custom_checkout['discount'] );
1074
+ }
1075
+
1076
+ $item = array(
1077
+ 'id' => 2147483646,
1078
+ 'title' => __( 'Discount', 'woocommerce-mercadopago-module' ),
1079
+ 'description' => __( 'Discount provided by store', 'woocommerce-mercadopago-module' ),
1080
+ 'quantity' => 1,
1081
+ 'category_id' => $this->store_categories_id[$this->category_id],
1082
+ 'unit_price' => -( (float) $custom_checkout['discount'] )
1083
+ );
1084
+ $items[] = $item;
1085
+ }
1086
+
1087
+ // Build additional information from the customer data.
1088
+ if ( method_exists( $order, 'get_id' ) ) {
1089
+ // Build additional information from the customer data.
1090
+ $payer_additional_info = array(
1091
+ 'first_name' => html_entity_decode( $order->get_billing_first_name() ),
1092
+ 'last_name' => html_entity_decode( $order->get_billing_last_name() ),
1093
+ //'registration_date' =>
1094
+ 'phone' => array(
1095
+ //'area_code' =>
1096
+ 'number' => $order->get_billing_phone(),
1097
+ ),
1098
+ 'address' => array(
1099
+ 'zip_code' => $order->get_billing_postcode(),
1100
+ //'street_number' =>
1101
+ 'street_name' => html_entity_decode(
1102
+ $order->get_billing_address_1() . ' / ' .
1103
+ $order->get_billing_city() . ' ' .
1104
+ $order->get_billing_state() . ' ' .
1105
+ $order->get_billing_country()
1106
+ )
1107
+ )
1108
+ );
1109
+ // Create the shipment address information set.
1110
+ $shipments = array(
1111
+ 'receiver_address' => array(
1112
+ 'zip_code' => $order->get_shipping_postcode(),
1113
+ //'street_number' =>
1114
+ 'street_name' => html_entity_decode(
1115
+ $order->get_shipping_address_1() . ' ' .
1116
+ $order->get_shipping_address_2() . ' ' .
1117
+ $order->get_shipping_city() . ' ' .
1118
+ $order->get_shipping_state() . ' ' .
1119
+ $order->get_shipping_country()
1120
+ ),
1121
+ //'floor' =>
1122
+ 'apartment' => $order->get_shipping_address_2()
1123
+ )
1124
+ );
1125
+ // The payment preference.
1126
+ $preferences = array(
1127
+ 'transaction_amount' => floor( ( (float) ( $order_total - $discount_amount_of_items ) ) * 100 ) / 100,
1128
+ 'token' => $custom_checkout['token'],
1129
+ 'description' => implode( ', ', $list_of_items ),
1130
+ 'installments' => (int) $custom_checkout['installments'],
1131
+ 'payment_method_id' => $custom_checkout['paymentMethodId'],
1132
+ 'payer' => array(
1133
+ 'email' => $order->get_billing_email()
1134
+ ),
1135
+ 'external_reference' => $this->invoice_prefix . $order->get_id(),
1136
+ 'statement_descriptor' => $this->statement_descriptor,
1137
+ 'binary_mode' => ( $this->binary_mode == 'yes' ),
1138
+ 'additional_info' => array(
1139
+ 'items' => $items,
1140
+ 'payer' => $payer_additional_info,
1141
+ 'shipments' => $shipments
1142
+ )
1143
+ );
1144
+ } else {
1145
+ // Build additional information from the customer data.
1146
+ $payer_additional_info = array(
1147
+ 'first_name' => html_entity_decode( $order->billing_first_name ),
1148
+ 'last_name' => html_entity_decode( $order->billing_last_name ),
1149
+ //'registration_date' =>
1150
+ 'phone' => array(
1151
+ //'area_code' =>
1152
+ 'number' => $order->billing_phone
1153
+ ),
1154
+ 'address' => array(
1155
+ 'zip_code' => $order->billing_postcode,
1156
+ //'street_number' =>
1157
+ 'street_name' => html_entity_decode(
1158
+ $order->billing_address_1 . ' / ' .
1159
+ $order->billing_city . ' ' .
1160
+ $order->billing_state . ' ' .
1161
+ $order->billing_country
1162
+ )
1163
+ )
1164
+ );
1165
+ // Create the shipment address information set.
1166
+ $shipments = array(
1167
+ 'receiver_address' => array(
1168
+ 'zip_code' => $order->shipping_postcode,
1169
+ //'street_number' =>
1170
+ 'street_name' => html_entity_decode(
1171
+ $order->shipping_address_1 . ' ' .
1172
+ $order->shipping_address_2 . ' ' .
1173
+ $order->shipping_city . ' ' .
1174
+ $order->shipping_state . ' ' .
1175
+ $order->shipping_country
1176
+ ),
1177
+ //'floor' =>
1178
+ 'apartment' => $order->shipping_address_2
1179
+ )
1180
+ );
1181
+ // The payment preference.
1182
+ $preferences = array(
1183
+ 'transaction_amount' => floor( ( (float) ( $order_total - $discount_amount_of_items ) ) * 100 ) / 100,
1184
+ 'token' => $custom_checkout['token'],
1185
+ 'description' => implode( ', ', $list_of_items ),
1186
+ 'installments' => (int) $custom_checkout['installments'],
1187
+ 'payment_method_id' => $custom_checkout['paymentMethodId'],
1188
+ 'payer' => array(
1189
+ 'email' => $order->billing_email
1190
+ ),
1191
+ 'external_reference' => $this->invoice_prefix . $order->id,
1192
+ 'statement_descriptor' => $this->statement_descriptor,
1193
+ 'binary_mode' => ( $this->binary_mode == 'yes' ),
1194
+ 'additional_info' => array(
1195
+ 'items' => $items,
1196
+ 'payer' => $payer_additional_info,
1197
+ 'shipments' => $shipments
1198
+ )
1199
+ );
1200
+ }
1201
+
1202
+ // Customer's Card Feature, add only if it has issuer id.
1203
+ if ( array_key_exists( 'token', $custom_checkout ) ) {
1204
+ $preferences['metadata']['token'] = $custom_checkout['token'];
1205
+ if ( array_key_exists( 'issuer', $custom_checkout ) ) {
1206
+ if ( ! empty( $custom_checkout['issuer'] ) ) {
1207
+ $preferences['issuer_id'] = (integer) $custom_checkout['issuer'];
1208
+ }
1209
+ }
1210
+ if ( ! empty( $custom_checkout['CustomerId'] ) ) {
1211
+ $preferences['payer']['id'] = $custom_checkout['CustomerId'];
1212
+ }
1213
+ }
1214
+
1215
+ // Do not set IPN url if it is a localhost.
1216
+ if ( ! strrpos( $this->domain, 'localhost' ) ) {
1217
+ $preferences['notification_url'] = WC_WooMercadoPago_Module::workaround_ampersand_bug(
1218
+ WC()->api_request_url( 'WC_WooMercadoPagoCustom_Gateway' )
1219
+ );
1220
+ }
1221
+
1222
+ // Discounts features.
1223
+ if ( isset( $custom_checkout['discount'] ) && $custom_checkout['discount'] != '' &&
1224
+ $custom_checkout['discount'] > 0 && isset( $custom_checkout['coupon_code'] ) &&
1225
+ $custom_checkout['coupon_code'] != '' &&
1226
+ WC()->session->chosen_payment_method == 'woocommerce-mercadopago-custom-module' ) {
1227
+
1228
+ $preferences['campaign_id'] = (int) $custom_checkout['campaign_id'];
1229
+ $preferences['coupon_amount'] = ( (float) $custom_checkout['discount'] );
1230
+ $preferences['coupon_code'] = strtoupper( $custom_checkout['coupon_code'] );
1231
+ }
1232
+
1233
+ // Set sponsor ID.
1234
+ if ( ! $this->is_test_user ) {
1235
+ $preferences['sponsor_id'] = $this->country_configs['sponsor_id'];
1236
  }
1237
 
1238
  if ( 'yes' == $this->debug ) {
1239
+ $this->log->add(
1240
+ $this->id,
1241
+ '[build_payment_preference] - returning just created [$preferences] structure: ' .
1242
+ json_encode( $preferences, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1243
+ );
1244
+ }
1245
+
1246
+ $preferences = apply_filters(
1247
+ 'woocommerce_mercadopago_module_custom_preferences',
1248
+ $preferences, $order
1249
+ );
1250
+ return $preferences;
1251
+ }
1252
+
1253
+ // --------------------------------------------------
1254
+
1255
+ protected function create_url( $order, $custom_checkout ) {
1256
+
1257
+ // Creates the order parameters by checking the cart configuration.
1258
+ $preferences = $this->build_payment_preference( $order, $custom_checkout );
1259
+
1260
+ // Checks for sandbox mode.
1261
+ if ( 'yes' == $this->sandbox ) {
1262
+ $this->mp->sandbox_mode( true );
1263
+ if ( 'yes' == $this->debug) {
1264
+ $this->log->add(
1265
+ $this->id,
1266
+ '[create_url] - sandbox mode is enabled'
1267
+ );
1268
+ }
1269
+ } else {
1270
+ $this->mp->sandbox_mode( false );
1271
+ }
1272
+
1273
+ // Create order preferences with Mercado Pago API request.
1274
+ try {
1275
+ $checkout_info = $this->mp->post( '/v1/payments', json_encode( $preferences) );
1276
+ if ( $checkout_info['status'] < 200 || $checkout_info['status'] >= 300 ) {
1277
+ // Mercado Pago trowed an error.
1278
+ if ( 'yes' == $this->debug ) {
1279
+ $this->log->add(
1280
+ $this->id,
1281
+ '[create_url] - mercado pago gave error, payment creation failed with error: ' .
1282
+ $checkout_info['response']['message'] );
1283
+ }
1284
+ return false;
1285
+ } elseif ( is_wp_error( $checkout_info ) ) {
1286
+ // WordPress throwed an error.
1287
+ if ( 'yes' == $this->debug ) {
1288
+ $this->log->add(
1289
+ $this->id,
1290
+ '[create_url] - wordpress gave error, payment creation failed with error: ' .
1291
+ $checkout_info['response']['message'] );
1292
+ }
1293
+ return false;
1294
+ } else {
1295
+ // Obtain the URL.
1296
+ if ( 'yes' == $this->debug ) {
1297
+ $this->log->add(
1298
+ $this->id,
1299
+ '[create_url] - payment link generated with success from mercado pago, with structure as follow: ' .
1300
+ json_encode( $checkout_info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE ) );
1301
+ }
1302
+ return $checkout_info['response'];
1303
+ }
1304
+ } catch ( MercadoPagoException $e ) {
1305
+ // Something went wrong with the payment creation.
1306
+ if ( 'yes' == $this->debug ) {
1307
+ $this->log->add(
1308
+ $this->id,
1309
+ '[create_url] - payment creation failed with exception: ' .
1310
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
1311
+ );
1312
+ }
1313
+ return false;
1314
  }
1315
+ }
1316
 
1317
+ /**
1318
+ * Summary: Check if we have existing customer card, if not we create and save it.
1319
+ * Description: Check if we have existing customer card, if not we create and save it.
1320
+ * @return boolean true/false depending on the validation result.
1321
+ */
1322
+ public function check_and_save_customer_card( $checkout_info ) {
1323
 
1324
+ if ( 'yes' == $this->debug ) {
1325
+ $this->log->add(
1326
+ $this->id,
1327
+ ': @[check_and_save_customer_card] - checking info to create card: ' .
1328
+ json_encode( $checkout_info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1329
+ );
1330
  }
1331
+
1332
  $custId = null;
1333
+ $token = null;
1334
  $issuer_id = null;
1335
  $payment_method_id = null;
1336
+
1337
+ if ( isset( $checkout_info['payer']['id'] ) && ! empty( $checkout_info['payer']['id'] ) ) {
1338
+ $custId = $checkout_info['payer']['id'];
1339
+ } else {
1340
+ return;
1341
+ }
1342
+
1343
+ if ( isset( $checkout_info['metadata']['token'] ) && ! empty( $checkout_info['metadata']['token'] ) ) {
1344
+ $token = $checkout_info['metadata']['token'];
1345
+ } else {
1346
+ return;
1347
+ }
1348
+
1349
+ if ( isset( $checkout_info['issuer_id'] ) && ! empty( $checkout_info['issuer_id'] ) ) {
1350
+ $issuer_id = (integer) ( $checkout_info['issuer_id'] );
1351
+ }
1352
+ if ( isset( $checkout_info['payment_method_id'] ) && ! empty( $checkout_info['payment_method_id'] ) ) {
1353
+ $payment_method_id = $checkout_info['payment_method_id'];
1354
+ }
1355
+
1356
+ try {
1357
+ $this->mp->create_card_in_customer( $custId, $token, $payment_method_id, $issuer_id );
1358
  } catch ( MercadoPagoException $e ) {
1359
  if ( 'yes' == $this->debug ) {
1360
+ $this->log->add(
1361
+ $this->id,
1362
+ '[check_and_save_customer_card] - card creation failed: ' .
1363
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
1364
+ );
1365
  }
1366
  }
1367
+
1368
  }
1369
 
1370
+ /**
1371
+ * Summary: Receive post data and applies a discount based in the received values.
1372
+ * Description: Receive post data and applies a discount based in the received values.
1373
+ */
1374
  public function add_discount_custom() {
1375
+
1376
+ if ( ! isset( $_POST['mercadopago_custom'] ) )
1377
+ return;
1378
+
1379
  if ( is_admin() && ! defined( 'DOING_AJAX' ) || is_cart() ) {
1380
  return;
1381
  }
1382
+
1383
+ $mercadopago_custom = $_POST['mercadopago_custom'];
1384
+ if ( isset( $mercadopago_custom['discount'] ) && $mercadopago_custom['discount'] != '' &&
1385
+ $mercadopago_custom['discount'] > 0 && isset( $mercadopago_custom['coupon_code'] ) &&
1386
+ $mercadopago_custom['coupon_code'] != '' &&
1387
+ WC()->session->chosen_payment_method == 'woocommerce-mercadopago-custom-module' ) {
1388
+
1389
+ if ( 'yes' == $this->debug ) {
1390
+ $this->log->add(
1391
+ $this->id,
1392
+ '[add_discount_custom] - custom checkout trying to apply discount...'
1393
+ );
1394
+ }
1395
+
1396
+ $value = ( $mercadopago_custom['discount'] ) /
1397
  ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 );
1398
  global $woocommerce;
1399
+ if ( apply_filters(
1400
+ 'wc_mercadopagocustom_module_apply_discount',
1401
+ 0 < $value, $woocommerce->cart )
1402
+ ) {
1403
+ $woocommerce->cart->add_fee( sprintf(
1404
+ __( 'Discount for %s coupon', 'woocommerce-mercadopago-module' ),
1405
+ esc_attr( $mercadopago_custom['campaign']
1406
+ ) ), ( $value * -1 ), false
1407
  );
1408
  }
1409
  }
1410
+
1411
+ }
1412
+
1413
+ // Display the discount in payment method title.
1414
+ public function get_payment_method_title_custom( $title, $id ) {
1415
+
1416
+ if ( ! is_checkout() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1417
+ return $title;
1418
+ }
1419
+
1420
+ if ( $title != $this->title || $this->gateway_discount == 0 ) {
1421
+ return $title;
1422
+ }
1423
+
1424
+ $total = (float) WC()->cart->subtotal;
1425
+ if ( is_numeric( $this->gateway_discount ) ) {
1426
+ if ( $this->gateway_discount >= 0 && $this->gateway_discount < 100 ) {
1427
+ $price_percent = $this->gateway_discount / 100;
1428
+ if ( $price_percent > 0 ) {
1429
+ $title .= ' (' . __( 'Discount Of ', 'woocommerce-mercadopago-module' ) .
1430
+ strip_tags( wc_price( $total * $price_percent ) ) . ' )';
1431
+ }
1432
+ }
1433
+ }
1434
+
1435
+ return $title;
1436
  }
1437
 
1438
  /*
1439
  * ========================================================================
1440
+ * AUXILIARY AND FEEDBACK METHODS (SERVER SIDE)
1441
  * ========================================================================
1442
  */
1443
 
1444
+ /**
1445
+ * Summary: Check if we have valid credentials.
1446
+ * Description: Check if we have valid credentials.
1447
+ * @return boolean true/false depending on the validation result.
1448
+ */
1449
+ public function validate_credentials() {
1450
 
1451
+ if ( empty( $this->public_key ) || empty( $this->access_token ) ) {
1452
+ return false;
1453
+ }
1454
+
1455
+ if ( strpos( $this->public_key, 'APP_USR' ) === false && strpos( $this->public_key, 'TEST' ) === false ) {
1456
+ return false;
1457
+ }
1458
+
1459
+ if ( strpos( $this->access_token, 'APP_USR' ) === false && strpos( $this->access_token, 'TEST' ) === false ) {
1460
+ return false;
1461
+ }
1462
+
1463
+ try {
1464
+
1465
+ $this->mp = new MP(
1466
+ WC_WooMercadoPago_Module::get_module_version(),
1467
+ $this->access_token
1468
+ );
1469
+ $get_request = $this->mp->get(
1470
+ '/users/me?access_token=' . $this->access_token
1471
+ );
1472
+
1473
+ if ( isset( $get_request['response']['site_id'] ) ) {
1474
+
1475
+ // TODO: revalidate MLU
1476
+ if ( $get_request['response']['site_id'] == 'MLU' ) {
1477
+ $this->mp = null;
1478
+ return false;
1479
+ }
1480
+
1481
+ $this->is_test_user = in_array( 'test_user', $get_request['response']['tags'] );
1482
+ $this->site_id = $get_request['response']['site_id'];
1483
+ $this->collector_id = $get_request['response']['id'];
1484
+ $this->country_configs = WC_WooMercadoPago_Module::get_country_config( $this->site_id );
1485
+
1486
+ // Check for auto converstion of currency (only if it is enabled).
1487
+ $this->currency_ratio = -1;
1488
+ if ( $this->currency_conversion == 'yes' ) {
1489
+ $this->currency_ratio = WC_WooMercadoPago_Module::get_conversion_rate(
1490
+ $this->country_configs['currency']
1491
+ );
1492
+ }
1493
+
1494
+ return true;
1495
+
1496
+ } else {
1497
+ $this->mp = null;
1498
  return false;
1499
  }
1500
+
1501
+ } catch ( MercadoPagoException $e ) {
1502
+ if ( 'yes' == $this->debug ) {
1503
+ $this->log->add(
1504
+ $this->id,
1505
+ '[validate_credentials] - while validating credentials, got exception: ' .
1506
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
1507
+ );
1508
+ }
1509
+ $this->mp = null;
1510
+ return false;
1511
  }
1512
+
1513
  return false;
1514
+
1515
  }
1516
 
1517
+ // Build the string representing the path to the log file.
1518
+ protected function build_log_path_string() {
1519
+ return '<a href="' . esc_url(admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' .
1520
  esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' .
1521
  __( 'WooCommerce &gt; System Status &gt; Logs', 'woocommerce-mercadopago-module' ) . '</a>';
1522
  }
1523
+
1524
  // Return boolean indicating if currency is supported.
1525
+ protected function is_supported_currency() {
1526
+ return get_woocommerce_currency() == $this->country_configs['currency'];
1527
  }
1528
 
1529
+ // Called automatically by WooCommerce, verify if Module is available to use.
1530
+ public function is_available() {
1531
+ if ( ! did_action( 'wp_loaded' ) ) {
1532
+ return false;
1533
+ }
1534
+ global $woocommerce;
1535
+ $w_cart = $woocommerce->cart;
1536
+ // Check if we have SSL.
1537
+ if ( empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ) {
1538
+ if ( empty( $this->sandbox ) && $this->sandbox == 'no' ) {
1539
+ return false;
1540
+ }
1541
  }
1542
+ // Check for recurrent product checkout.
1543
+ if ( isset( $w_cart ) ) {
1544
+ if ( WC_WooMercadoPago_Module::is_subscription( $w_cart->get_cart() ) ) {
1545
+ return false;
1546
+ }
1547
+ }
1548
+ // Check if this gateway is enabled and well configured.
1549
+ $available = ( 'yes' == $this->settings['enabled'] ) &&
1550
+ ! empty( $this->public_key ) &&
1551
+ ! empty( $this->access_token) ;
1552
+ return $available;
1553
  }
1554
 
1555
+ public function check_ssl_absence() {
1556
+ if ( empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ) {
1557
+ if ( 'yes' == $this->settings['enabled'] ) {
1558
+ echo '<div class="error"><p><strong>' .
1559
  __( 'Custom Checkout is Inactive', 'woocommerce-mercadopago-module' ) .
1560
  '</strong>: ' .
1561
  sprintf(
1565
  }
1566
  }
1567
 
 
 
 
 
 
 
 
 
 
 
 
 
1568
  // Get the URL to admin page.
1569
  protected function admin_url() {
1570
+ if (defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
1571
  return admin_url(
1572
  'admin.php?page=wc-settings&tab=checkout&section=wc_woomercadopagocustom_gateway'
1573
  );
1578
  }
1579
 
1580
  // Notify that public_key and/or access_token are not valid.
1581
+ public function credentials_missing_message() {
1582
+ echo '<div class="error"><p><strong>' .
1583
  __( 'Custom Checkout is Inactive', 'woocommerce-mercadopago-module' ) .
1584
  '</strong>: ' .
1585
+ __( 'Your Mercado Pago credentials Public Key/Access Token appears to be misconfigured.', 'woocommerce-mercadopago-module' ) .
 
 
 
1586
  '</p></div>';
1587
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
1588
 
1589
+ public function get_order_status( $status_detail ) {
1590
  switch ( $status_detail ) {
1591
  case 'accredited':
1592
  return __( 'Done, your payment was accredited!', 'woocommerce-mercadopago-module' );
1626
  return __( 'This payment method did not process the payment.', 'woocommerce-mercadopago-module' );
1627
  }
1628
  }
1629
+
1630
  /*
1631
  * ========================================================================
1632
+ * IPN MECHANICS (SERVER SIDE)
1633
  * ========================================================================
1634
  */
1635
 
1636
+ /**
1637
+ * Summary: This call checks any incoming notifications from Mercado Pago server.
1638
+ * Description: This call checks any incoming notifications from Mercado Pago server.
1639
+ */
1640
  public function process_http_request() {
1641
  @ob_clean();
1642
  if ( 'yes' == $this->debug ) {
1643
+ $this->log->add(
1644
+ $this->id,
1645
+ '[process_http_request] - Received _get content: ' .
1646
+ json_encode( $_GET, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1647
+ );
1648
+ }
1649
+ if ( isset( $_GET['coupon_id'] ) && $_GET['coupon_id'] != '' ) {
1650
+ // Process coupon evaluations.
1651
+ if ( isset( $_GET['payer'] ) && $_GET['payer'] != '' ) {
1652
+ $logged_user_email = $_GET['payer'];
1653
+ $coupon_id = $_GET['coupon_id'];
1654
+ if ( 'yes' == $this->sandbox )
1655
+ $this->mp->sandbox_mode( true );
1656
+ else
1657
+ $this->mp->sandbox_mode( false );
1658
+ $response = $this->mp->check_discount_campaigns(
1659
+ $_GET['amount'],
1660
+ $logged_user_email,
1661
+ $coupon_id
1662
+ );
1663
+ header( 'HTTP/1.1 200 OK' );
1664
+ header( 'Content-Type: application/json' );
1665
  echo json_encode( $response );
1666
  } else {
1667
  $obj = new stdClass();
1668
  $obj->status = 404;
1669
  $obj->response = array(
1670
+ 'message' =>
1671
+ __( 'Please, inform your email in billing address to use this feature', 'woocommerce-mercadopago-module' ),
1672
  'error' => 'payer_not_found',
1673
  'status' => 404,
1674
  'cause' => array()
1675
  );
1676
  header( 'HTTP/1.1 200 OK' );
1677
+ header( 'Content-Type: application/json' );
1678
  echo json_encode( $obj );
1679
  }
1680
+ exit( 0 );
1681
  } else {
1682
+ // Process IPN messages.
1683
  $data = $this->check_ipn_request_is_valid( $_GET );
1684
  if ( $data ) {
1685
  header( 'HTTP/1.1 200 OK' );
1687
  }
1688
  }
1689
  }
1690
+
1691
+ /**
1692
+ * Summary: Get received data from IPN and checks if its a merchant_order or a payment.
1693
+ * Description: If we have these information, we return data to be processed by
1694
+ * successful_request function.
1695
+ * @return boolean indicating if it was successfuly processed.
1696
+ */
1697
  public function check_ipn_request_is_valid( $data ) {
1698
+
1699
+ if ( ! isset( $data['data_id'] ) || ! isset( $data['type'] ) ) {
1700
  if ( 'yes' == $this->debug ) {
1701
+ $this->log->add(
1702
+ $this->id,
1703
+ '[check_ipn_request_is_valid] - data_id or type not set: ' .
1704
+ json_encode( $data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1705
+ );
1706
  }
1707
+ // At least, check if its a v0 ipn.
1708
+ if ( ! isset( $data['id'] ) || ! isset( $data['topic'] ) ) {
1709
  if ( 'yes' == $this->debug ) {
1710
  $this->log->add(
1711
+ $this->id,
1712
+ '[check_ipn_request_is_valid] - Mercado Pago Request failure: ' .
1713
+ json_encode( $_GET, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1714
+ );
1715
  }
1716
  wp_die( __( 'Mercado Pago Request Failure', 'woocommerce-mercadopago-module' ) );
1717
  } else {
1720
  // No ID? No process!
1721
  return false;
1722
  }
1723
+
1724
+ if ( 'yes' == $this->sandbox ) {
1725
+ $this->mp->sandbox_mode( true );
1726
+ } else {
1727
+ $this->mp->sandbox_mode( false );
1728
+ }
1729
+
1730
  try {
1731
+ // Get the payment reported by the IPN.
1732
+ if ( $data['type'] == 'payment' ) {
1733
+ $access_token = array( 'access_token' => $this->mp->get_access_token() );
1734
+ $payment_info = $this->mp->get(
1735
+ '/v1/payments/' . $data['data_id'], $access_token, false
1736
+ );
1737
+ if ( ! is_wp_error( $payment_info ) &&
1738
+ ( $payment_info['status'] == 200 || $payment_info['status'] == 201 ) ) {
1739
+ return $payment_info['response'];
1740
  } else {
1741
+ if ( 'yes' == $this->debug) {
1742
+ $this->log->add(
1743
+ $this->id,
1744
+ '[check_ipn_request_is_valid] - error when processing received data: ' .
1745
+ json_encode( $payment_info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1746
+ );
1747
  }
1748
  return false;
1749
  }
1750
  }
1751
  } catch ( MercadoPagoException $e ) {
1752
  if ( 'yes' == $this->debug ) {
1753
+ $this->log->add(
1754
+ $this->id,
1755
+ '[check_ipn_request_is_valid] - MercadoPagoException: ' .
1756
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
1757
+ );
1758
  }
1759
  return false;
1760
  }
1761
  return true;
1762
  }
1763
+
1764
+ /**
1765
+ * Summary: Properly handles each case of notification, based in payment status.
1766
+ * Description: Properly handles each case of notification, based in payment status.
1767
+ */
1768
  public function successful_request( $data ) {
1769
+
1770
  if ( 'yes' == $this->debug ) {
1771
+ $this->log->add(
1772
+ $this->id,
1773
+ '[successful_request] - starting to process ipn update...'
1774
+ );
1775
+ }
1776
+
1777
+ // Get the order and check its presence.
1778
+ $order_key = $data['external_reference'];
1779
+ if ( empty( $order_key ) ) {
1780
+ return;
1781
+ }
1782
+ $id = (int) str_replace( $this->invoice_prefix, '', $order_key );
1783
+ $order = wc_get_order( $id );
1784
+
1785
+ // Check if order exists.
1786
+ if ( ! $order ) {
1787
+ return;
1788
+ }
1789
+
1790
+ // WooCommerce 3.0 or later.
1791
+ if ( method_exists( $order, 'get_id' ) ) {
1792
+ $order_id = $order->get_id();
1793
+ } else {
1794
+ $order_id = $order->id;
1795
+ }
1796
+
1797
+ // Check if we have the correct order.
1798
+ if ( $order_id !== $id ) {
1799
+ return;
1800
+ }
1801
+
1802
+ if ( 'yes' == $this->debug ) {
1803
+ $this->log->add(
1804
+ $this->id,
1805
+ '[successful_request] - updating metadata and status with data: ' .
1806
+ json_encode( $data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1807
+ );
1808
+ }
1809
+
1810
+ // Here, we process the status... this is the business rules!
1811
+ // Reference: https://www.mercadopago.com.br/developers/en/api-docs/basic-checkout/ipn/payment-status/
1812
+ $status = isset( $data['status'] ) ? $data['status'] : 'pending';
1813
+ $total_paid = isset( $data['transaction_details']['total_paid_amount'] ) ? $data['transaction_details']['total_paid_amount'] : 0.00;
1814
+ $total_refund = isset( $data['transaction_amount_refunded'] ) ? $data['transaction_amount_refunded'] : 0.00;
1815
+ $total = $data['transaction_amount'];
1816
+
1817
+ if ( method_exists( $order, 'update_meta_data' ) ) {
1818
+ $order->update_meta_data( '_used_gateway', 'WC_WooMercadoPagoCustom_Gateway' );
1819
+
1820
+ if ( ! empty( $data['payer']['email'] ) ) {
1821
+ $order->update_meta_data( __( 'Payer email', 'woocommerce-mercadopago-module' ), $data['payer']['email'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1822
  }
1823
+
1824
+ if ( ! empty( $data['payment_type_id'] ) ) {
1825
+ $order->update_meta_data( __( 'Payment type', 'woocommerce-mercadopago-module' ), $data['payment_type_id'] );
1826
+ }
1827
+
1828
+ $payment_id = $data['id'];
1829
+
1830
+ $order->update_meta_data( 'Mercado Pago - Payment ' . $payment_id,
1831
+ 'Mercado Pago - Payment ' . $payment_id,
1832
+ '[Date ' . date( 'Y-m-d H:i:s', strtotime( $data['date_created'] ) ) .
1833
+ ']/[Amount ' . $total .
1834
+ ']/[Paid ' . $total_paid .
1835
+ ']/[Refund ' . $total_refund . ']'
1836
+ );
1837
+
1838
+ $order->update_meta_data( '_Mercado_Pago_Payment_IDs', $payment_id );
1839
+ $order->save();
1840
+
1841
+ } else {
1842
+ update_post_meta( $order_id, '_used_gateway', 'WC_WooMercadoPagoCustom_Gateway' );
1843
+
1844
+ if ( ! empty( $data['payer']['email'] ) ) {
1845
+ update_post_meta(
1846
+ $order_id,
1847
+ __( 'Payer email', 'woocommerce-mercadopago-module' ),
1848
+ $data['payer']['email']
1849
+ );
1850
+ }
1851
+ if ( ! empty( $data['payment_type_id'] ) ) {
1852
+ update_post_meta(
1853
+ $order_id,
1854
+ __( 'Payment type', 'woocommerce-mercadopago-module' ),
1855
+ $data['payment_type_id']
1856
+ );
1857
+ }
1858
+ $payment_id = $data['id'];
1859
+ update_post_meta(
1860
+ $order_id,
1861
+ 'Mercado Pago - Payment ' . $payment_id,
1862
+ '[Date ' . date( 'Y-m-d H:i:s', strtotime( $data['date_created'] ) ) .
1863
+ ']/[Amount ' . $total .
1864
+ ']/[Paid ' . $total_paid .
1865
+ ']/[Refund ' . $total_refund . ']'
1866
+ );
1867
+ update_post_meta(
1868
+ $order_id,
1869
+ '_Mercado_Pago_Payment_IDs',
1870
+ $payment_id
1871
+ );
1872
+ }
1873
+
1874
+ // Switch the status and update in WooCommerce
1875
+ switch ( $status ) {
1876
+ case 'approved':
1877
+ $order->add_order_note(
1878
+ 'Mercado Pago: ' . __( 'Payment approved.', 'woocommerce-mercadopago-module' )
1879
+ );
1880
+ $this->check_and_save_customer_card( $data );
1881
+ $order->payment_complete();
1882
+ break;
1883
+ case 'pending':
1884
+ $order->add_order_note(
1885
+ 'Mercado Pago: ' . __( 'Customer haven\'t paid yet.', 'woocommerce-mercadopago-module' )
1886
+ );
1887
+ break;
1888
+ case 'in_process':
1889
+ $order->update_status(
1890
+ 'on-hold',
1891
+ 'Mercado Pago: ' . __( 'Payment under review.', 'woocommerce-mercadopago-module' )
1892
+ );
1893
+ break;
1894
+ case 'rejected':
1895
+ $order->update_status(
1896
+ 'failed',
1897
+ 'Mercado Pago: ' .
1898
+ __( 'The payment was refused. The customer can try again.', 'woocommerce-mercadopago-module' )
1899
+ );
1900
+ break;
1901
+ case 'refunded':
1902
+ $order->update_status(
1903
+ 'refunded',
1904
+ 'Mercado Pago: ' .
1905
+ __( 'The payment was refunded to the customer.', 'woocommerce-mercadopago-module' )
1906
+ );
1907
+ break;
1908
+ case 'cancelled':
1909
+ $order->update_status(
1910
+ 'cancelled',
1911
+ 'Mercado Pago: ' .
1912
+ __( 'The payment was cancelled.', 'woocommerce-mercadopago-module' )
1913
+ );
1914
+ break;
1915
+ case 'in_mediation':
1916
+ $order->add_order_note(
1917
+ 'Mercado Pago: ' .
1918
+ __( 'The payment is under mediation or it was charged-back.', 'woocommerce-mercadopago-module' )
1919
+ );
1920
+ break;
1921
+ case 'charged-back':
1922
+ $order->add_order_note(
1923
+ 'Mercado Pago: ' .
1924
+ __( 'The payment is under mediation or it was charged-back.', 'woocommerce-mercadopago-module' )
1925
+ );
1926
+ break;
1927
+ default:
1928
+ break;
1929
  }
1930
  }
1931
 
1932
  }
1933
 
1934
+ new WC_WooMercadoPagoCustom_Gateway( true );
mercadopago/mercadopago-gateway.php CHANGED
@@ -1,139 +1,199 @@
1
  <?php
 
2
  /**
3
  * Part of Woo Mercado Pago Module
4
  * Author - Mercado Pago
5
  * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
6
- * Copyright - Copyright(c) MercadoPago [http://www.mercadopago.com]
7
- * License - http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
8
  */
9
 
10
  // This include Mercado Pago library SDK
11
- require_once "sdk/lib/mercadopago.php";
12
 
13
- // Extending from WooCommerce Payment Gateway class.
14
- // This class implements Mercado Pago Basic checkout.
 
 
 
15
  class WC_WooMercadoPago_Gateway extends WC_Payment_Gateway {
16
-
17
- // This array stores each banner image, depending on the country it belongs to or on
18
- // the type of checkout we use.
19
- private $banners_mercadopago_standard = array(
20
- "MLA" => 'MLA/standard_mla.jpg',
21
- "MLB" => 'MLB/standard_mlb.jpg',
22
- "MCO" => 'MCO/standard_mco.jpg',
23
- "MLC" => 'MLC/standard_mlc.gif',
24
- "MPE" => 'MPE/standard_mpe.png',
25
- "MLV" => 'MLV/standard_mlv.jpg',
26
- "MLM" => 'MLM/standard_mlm.jpg'
27
- );
28
-
29
- // Sponsor ID array by country
30
- private $sponsor_id = array(
31
- "MLA" => '208682286',
32
- "MLB" => '208686191',
33
- "MCO" => '208687643',
34
- "MLC" => '208690789',
35
- "MPE" => '216998692',
36
- "MLV" => '208692735',
37
- "MLM" => '208692380'
38
- );
39
-
40
- // Required inherited method from WC_Payment_Gateway class: __construct.
41
- // Please check:
42
- // [https://docs.woothemes.com/wc-apidocs/class-WC_Payment_Gateway.html]
43
- // for documentation and further information.
44
  public function __construct() {
45
 
46
- // These fields are declared because we use them dinamically in our gateway class.
47
- $this->domain = get_site_url() . '/index.php';
48
- $this->currency_ratio = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  $this->site_id = null;
50
- $this->isTestUser = false;
 
 
 
 
 
51
  $this->payment_methods = array();
 
52
  $this->store_categories_id = array();
53
- $this->store_categories_description = array();
54
-
55
- // Within your constructor, you should define the following variables.
 
56
  $this->id = 'woocommerce-mercadopago-module';
 
57
  $this->icon = apply_filters(
58
  'woocommerce_mercadopago_icon',
59
  plugins_url( 'images/mercadopago.png', plugin_dir_path( __FILE__ ) )
60
  );
61
  $this->method_title = __( 'Mercado Pago - Basic Checkout', 'woocommerce-mercadopago-module' );
62
  $this->method_description = '<img width="200" height="52" src="' .
63
- plugins_url( 'images/mplogo.png', plugin_dir_path( __FILE__ ) ) . '"><br><br>' . '<strong>' .
64
- wordwrap( __( 'This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store.', 'woocommerce-mercadopago-module' ), 80, "\n" ) .
65
- '</strong>';
66
-
67
- // These fields are used in our Mercado Pago Module configuration page.
 
 
 
 
 
 
68
  $this->client_id = $this->get_option( 'client_id' );
69
  $this->client_secret = $this->get_option( 'client_secret' );
70
  $this->title = $this->get_option( 'title' );
71
  $this->description = $this->get_option( 'description' );
72
  $this->category_id = $this->get_option( 'category_id' );
73
  $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' );
74
- $this->method = $this->get_option( 'method', 'modal' );
75
  $this->iframe_width = $this->get_option( 'iframe_width', 640 );
76
  $this->iframe_height = $this->get_option( 'iframe_height', 800 );
77
  $this->auto_return = $this->get_option( 'auto_return', true );
78
- $this->currency_conversion = $this->get_option('currency_conversion', false);
 
 
 
79
  $this->installments = $this->get_option( 'installments', '24' );
80
  $this->ex_payments = $this->get_option( 'ex_payments', 'n/d' );
81
- $this->sandbox = $this->get_option('sandbox', false);
82
- $this->debug = $this->get_option('debug');
83
-
 
 
 
 
 
 
 
 
 
 
 
 
84
  // Render our configuration page and init/load fields.
85
  $this->init_form_fields();
86
  $this->init_settings();
87
 
88
- // Hook actions for WordPress.
89
- add_action( // Used by IPN to receive IPN incomings.
90
  'woocommerce_api_wc_woomercadopago_gateway',
91
  array( $this, 'check_ipn_response' )
92
  );
93
- add_action( // Used by IPN to process valid incomings.
 
94
  'valid_mercadopago_ipn_request',
95
  array( $this, 'successful_request' )
96
  );
97
- add_action( // Used by WordPress to render the custom checkout page.
 
 
 
 
 
 
98
  'woocommerce_receipt_' . $this->id,
99
  array( $this, 'receipt_page' )
100
  );
101
- add_action( // Used to fix CSS in some older WordPress/WooCommerce versions.
 
102
  'wp_head',
103
  array( $this, 'css' )
104
  );
105
- add_action( // Used in settings page to hook "save settings" action.
 
106
  'woocommerce_update_options_payment_gateways_' . $this->id,
107
- array( $this, 'process_admin_options' )
 
 
 
 
 
 
 
 
 
 
108
  );
109
-
 
 
 
 
 
110
  // Verify if client_id or client_secret is empty.
111
  if ( empty( $this->client_id ) || empty( $this->client_secret ) ) {
112
- add_action( 'admin_notices', array( $this, 'clientIdOrSecretMissingMessage' ) );
113
- }
114
-
115
- // Logging and debug.
116
- if ( 'yes' == $this->debug ) {
117
- if ( class_exists( 'WC_Logger' ) ) {
118
- $this->log = new WC_Logger();
119
- } else {
120
- $this->log = WC_MercadoPago_Module::woocommerceInstance()->logger();
121
  }
122
  }
123
-
124
  }
125
-
126
- // Required inherited method from WC_Payment_Gateway class: init_form_fields.
127
- // Initialise Gateway settings form fields with a customized page.
 
 
128
  public function init_form_fields() {
129
-
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  $api_secret_locale = sprintf(
131
  '<a href="https://www.mercadopago.com/mla/account/credentials?type=basic" target="_blank">%s</a>, ' .
132
  '<a href="https://www.mercadopago.com/mlb/account/credentials?type=basic" target="_blank">%s</a>, ' .
133
  '<a href="https://www.mercadopago.com/mlc/account/credentials?type=basic" target="_blank">%s</a>, ' .
134
  '<a href="https://www.mercadopago.com/mco/account/credentials?type=basic" target="_blank">%s</a>, ' .
135
  '<a href="https://www.mercadopago.com/mlm/account/credentials?type=basic" target="_blank">%s</a>, ' .
136
- '<a href="https://www.mercadopago.com/mpe/account/credentials?type=basic" target="_blank">%s</a> %s ' .
 
137
  '<a href="https://www.mercadopago.com/mlv/account/credentials?type=basic" target="_blank">%s</a>',
138
  __( 'Argentine', 'woocommerce-mercadopago-module' ),
139
  __( 'Brazil', 'woocommerce-mercadopago-module' ),
@@ -141,101 +201,97 @@ class WC_WooMercadoPago_Gateway extends WC_Payment_Gateway {
141
  __( 'Colombia', 'woocommerce-mercadopago-module' ),
142
  __( 'Mexico', 'woocommerce-mercadopago-module' ),
143
  __( 'Peru', 'woocommerce-mercadopago-module' ),
 
144
  __( 'or', 'woocommerce-mercadopago-module' ),
145
  __( 'Venezuela', 'woocommerce-mercadopago-module' )
146
  );
147
-
148
  // Trigger API to get payment methods and site_id, also validates Client_id/Client_secret.
149
- if ( $this->validateCredentials() ) {
150
- try {
151
- // checking the currency
152
- $this->currency_message = "";
153
- if ( !$this->isSupportedCurrency() && 'yes' == $this->settings[ 'enabled' ] ) {
154
- if ( $this->currency_conversion == 'no' ) {
155
- $this->currency_ratio = -1;
156
- $this->currency_message .= '<img width="12" height="12" src="' .
157
- plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' .
158
- ' ' . __( 'ATTENTION: The currency', 'woocommerce-mercadopago-module' ) . ' ' . get_woocommerce_currency() .
159
- ' ' . __( 'defined in WooCommerce is different from the one used in your credentials country.<br>The currency for transactions in this payment method will be', 'woocommerce-mercadopago-module' ) .
160
- ' ' . $this->getCurrencyId( $this->site_id ) . ' (' . $this->getCountryName( $this->site_id ) . ').' .
161
- ' ' . __( 'Currency conversions should be made outside this module.', 'woocommerce-mercadopago-module' );
162
- } else if ( $this->currency_conversion == 'yes' && $this->currency_ratio != -1 ) {
163
- $this->currency_message .= '<img width="12" height="12" src="' .
164
- plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '">' .
165
- ' ' . __( 'CURRENCY CONVERTED: The currency conversion ratio from', 'woocommerce-mercadopago-module' ) . ' ' . get_woocommerce_currency() .
166
- ' ' . __( 'to', 'woocommerce-mercadopago-module' ) . ' ' . $this->getCurrencyId( $this->site_id ) . __( ' is: ', 'woocommerce-mercadopago-module' ) . $this->currency_ratio . ".";
167
- } else {
168
- $this->currency_ratio = -1;
169
- $this->currency_message .= '<img width="12" height="12" src="' .
170
- plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '">' .
171
- ' ' . __( 'ERROR: It was not possible to convert the unsupported currency', 'woocommerce-mercadopago-module' ) . ' ' . get_woocommerce_currency() .
172
- ' ' . __( 'to', 'woocommerce-mercadopago-module' ) . ' ' . $this->getCurrencyId( $this->site_id ) . '.' .
173
- ' ' . __( 'Currency conversions should be made outside this module.', 'woocommerce-mercadopago-module' );
174
- }
175
  } else {
176
  $this->currency_ratio = -1;
 
 
 
177
  }
178
- $this->credentials_message = '<img width="12" height="12" src="' .
179
- plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '">' .
180
- ' ' . __( 'Your credentials are <strong>valid</strong> for', 'woocommerce-mercadopago-module' ) .
181
- ': ' . $this->getCountryName( $this->site_id ) . ' <img width="18.6" height="12" src="' .
182
- plugins_url( 'images/' . $this->site_id . '/' . $this->site_id . '.png', plugin_dir_path( __FILE__ ) ) . '"> ';
183
- $this->payment_desc =
184
- __( 'Select the payment methods that you <strong>don\'t</strong> want to receive with Mercado Pago.', 'woocommerce-mercadopago-module' );
185
- } catch ( MercadoPagoException $e ) {
186
- array_push( $this->payment_methods, "n/d" );
187
- $this->payment_desc = '<img width="12" height="12" src="' .
188
- plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' .
189
- ' ' . __( 'Configure your Client_id and Client_secret to have access to more options.', 'woocommerce-mercadopago-module' );
190
- $this->credentials_message = '<img width="12" height="12" src="' .
191
- plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '">' .
192
- ' ' . __( 'Your credentials are <strong>not valid</strong>!', 'woocommerce-mercadopago-module' );
193
  }
 
 
 
 
 
 
194
  } else {
195
- array_push( $this->payment_methods, "n/d" );
 
196
  $this->payment_desc = '<img width="12" height="12" src="' .
197
- plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' .
198
- ' ' . __( 'Configure your Client_id and Client_secret to have access to more options.', 'woocommerce-mercadopago-module' );
199
- $this->credentials_message = '<img width="12" height="12" src="' .
200
- plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '">' .
201
- ' ' . __( 'Your credentials are <strong>not valid</strong>!', 'woocommerce-mercadopago-module' );
202
  }
203
-
204
- // Fills categoy selector. We do not need credentials to make this call.
205
- $categories = MPRestClient::get( array( "uri" => "/item_categories" ) );
206
- foreach ( $categories[ "response" ] as $category ) {
207
- array_push( $this->store_categories_id, str_replace( "_", " ", $category[ 'id' ] ) );
208
- array_push( $this->store_categories_description, str_replace( "_", " ", $category[ 'description' ] ) );
209
- }
210
-
211
  // Checks validity of iFrame width/height fields.
212
- if ( !is_numeric( $this->iframe_width ) ) {
213
  $this->iframe_width_desc = '<img width="12" height="12" src="' .
214
- plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' .
215
- ' ' . __( 'This field should be an integer.', 'woocommerce-mercadopago-module' );
216
  } else {
217
  $this->iframe_width_desc =
218
  __( 'If your integration method is iFrame, please inform the payment iFrame width.', 'woocommerce-mercadopago-module' );
219
  }
220
- if ( !is_numeric( $this->iframe_height ) ) {
221
  $this->iframe_height_desc = '<img width="12" height="12" src="' .
222
- plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' .
223
- ' ' . __( 'This field should be an integer.', 'woocommerce-mercadopago-module' );
224
  } else {
225
  $this->iframe_height_desc =
226
  __( 'If your integration method is iFrame, please inform the payment iFrame height.', 'woocommerce-mercadopago-module' );
227
  }
228
-
229
  // Checks if max installments is a number.
230
- if ( !is_numeric( $this->installments ) ) {
231
  $this->installments_desc = '<img width="12" height="12" src="' .
232
- plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' .
233
- ' ' . __( 'This field should be an integer.', 'woocommerce-mercadopago-module' );
234
  } else {
235
  $this->installments_desc =
236
  __( 'Select the max number of installments for your customers.', 'woocommerce-mercadopago-module' );
237
  }
238
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  // This array draws each UI (text, selector, checkbox, label, etc).
240
  $this->form_fields = array(
241
  'enabled' => array(
@@ -247,26 +303,35 @@ class WC_WooMercadoPago_Gateway extends WC_Payment_Gateway {
247
  'credentials_title' => array(
248
  'title' => __( 'Mercado Pago Credentials', 'woocommerce-mercadopago-module' ),
249
  'type' => 'title',
250
- 'description' => sprintf( '%s', $this->credentials_message ) . '<br>' . sprintf( __( 'You can obtain your credentials for', 'woocommerce-mercadopago-module' ) . ' %s.', $api_secret_locale )
 
 
 
251
  ),
252
  'client_id' => array(
253
  'title' => 'Client_id',
254
  'type' => 'text',
255
- 'description' => __( 'Insert your Mercado Pago Client_id.', 'woocommerce-mercadopago-module' ),
 
256
  'default' => '',
257
  'required' => true
258
  ),
259
  'client_secret' => array(
260
  'title' => 'Client_secret',
261
  'type' => 'text',
262
- 'description' => __( 'Insert your Mercado Pago Client_secret.', 'woocommerce-mercadopago-module' ),
 
263
  'default' => '',
264
  'required' => true
265
  ),
266
  'ipn_url' => array(
267
- 'title' => __( 'Instant Payment Notification (IPN) URL', 'woocommerce-mercadopago-module' ),
 
268
  'type' => 'title',
269
- 'description' => sprintf( __( 'Your IPN URL to receive instant payment notifications is', 'woocommerce-mercadopago-module' ) . '<br>%s', '<code>' . $this->domain . '/' . $this->id . '/?wc-api=WC_WooMercadoPago_Gateway' . '</code>.' )
 
 
 
270
  ),
271
  'checkout_options_title' => array(
272
  'title' => __( 'Checkout Options', 'woocommerce-mercadopago-module' ),
@@ -276,25 +341,31 @@ class WC_WooMercadoPago_Gateway extends WC_Payment_Gateway {
276
  'title' => array(
277
  'title' => __( 'Title', 'woocommerce-mercadopago-module' ),
278
  'type' => 'text',
279
- 'description' => __( 'Title shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
 
280
  'default' => __( 'Mercado Pago', 'woocommerce-mercadopago-module' )
281
  ),
282
  'description' => array(
283
  'title' => __( 'Description', 'woocommerce-mercadopago-module' ),
284
  'type' => 'textarea',
285
- 'description' => __( 'Description shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
 
286
  'default' => __( 'Pay with Mercado Pago', 'woocommerce-mercadopago-module' )
287
  ),
288
  'category_id' => array(
289
  'title' => __( 'Store Category', 'woocommerce-mercadopago-module' ),
290
  'type' => 'select',
291
- 'description' => __( 'Define which type of products your store sells.', 'woocommerce-mercadopago-module' ),
 
292
  'options' => $this->store_categories_id
293
  ),
294
  'invoice_prefix' => array(
295
  'title' => __( 'Store Identificator', 'woocommerce-mercadopago-module' ),
296
  'type' => 'text',
297
- 'description' => __( 'Please, inform a prefix to your store.', 'woocommerce-mercadopago-module' ) . ' ' . __( 'If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same identificators.', 'woocommerce-mercadopago-module' ),
 
 
 
298
  'default' => 'WC-'
299
  ),
300
  'method' => array(
@@ -325,7 +396,31 @@ class WC_WooMercadoPago_Gateway extends WC_Payment_Gateway {
325
  'type' => 'checkbox',
326
  'label' => __( 'Automatic Return After Payment', 'woocommerce-mercadopago-module' ),
327
  'default' => 'yes',
328
- 'description' => __( 'After the payment, client is automatically redirected.', 'woocommerce-mercadopago-module' ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  ),
330
  'payment_title' => array(
331
  'title' => __( 'Payment Options', 'woocommerce-mercadopago-module' ),
@@ -335,7 +430,8 @@ class WC_WooMercadoPago_Gateway extends WC_Payment_Gateway {
335
  'currency_conversion' => array(
336
  'title' => __( 'Currency Conversion', 'woocommerce-mercadopago-module' ),
337
  'type' => 'checkbox',
338
- 'label' => __( 'If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio', 'woocommerce-mercadopago-module' ),
 
339
  'default' => 'no',
340
  'description' => sprintf( '%s', $this->currency_message )
341
  ),
@@ -346,431 +442,1003 @@ class WC_WooMercadoPago_Gateway extends WC_Payment_Gateway {
346
  'default' => '24'
347
  ),
348
  'ex_payments' => array(
349
- 'title' => __( 'Exclude Payment Methods', 'woocommerce-mercadopago-module' ),
350
- 'description' => $this->payment_desc,
351
- 'type' => 'multiselect',
352
- 'options' => $this->payment_methods,
353
- 'default' => ''
354
- ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  'testing' => array(
356
  'title' => __( 'Test and Debug Options', 'woocommerce-mercadopago-module' ),
357
  'type' => 'title',
358
  'description' => ''
359
  ),
360
- 'sandbox' => array(
361
- 'title' => __( 'Mercado Pago Sandbox', 'woocommerce-mercadopago-module' ),
362
- 'type' => 'checkbox',
363
- 'label' => __( 'Enable Mercado Pago Sandbox', 'woocommerce-mercadopago-module' ),
364
- 'default' => 'no',
365
- 'description' => __( 'This option allows you to test payments inside a sandbox environment.', 'woocommerce-mercadopago-module' ),
366
- ),
 
367
  'debug' => array(
368
  'title' => __( 'Debug and Log', 'woocommerce-mercadopago-module' ),
369
  'type' => 'checkbox',
370
  'label' => __( 'Enable log', 'woocommerce-mercadopago-module' ),
371
  'default' => 'no',
372
- 'description' => sprintf( __( 'Register event logs of Mercado Pago, such as API requests, in the file', 'woocommerce-mercadopago-module' ) .
373
- ' %s.', $this->buildLogPathString() . '.<br>' . __( 'File location: ', 'woocommerce-mercadopago-module' ) .
374
- '<code>wordpress/wp-content/uploads/wc-logs/' . $this->id . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log</code>')
 
 
 
375
  )
376
  );
377
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
  }
379
-
380
- public function admin_options() {
381
- $this->validate_settings_fields();
382
- if ( count( $this->errors ) > 0 ) {
383
- $this->display_errors();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  } else {
386
- echo wpautop( $this->method_description );
387
- ?>
388
- <p><a href="https://wordpress.org/support/view/plugin-reviews/woo-mercado-pago-module?filter=5#postform" target="_blank" class="button button-primary">
389
- <?php esc_html_e( sprintf( __( 'Please, rate us %s on WordPress.org and give your feedback to help improve this module!', 'woocommerce-mercadopago-module' ), '&#9733;&#9733;&#9733;&#9733;&#9733;' ) ); ?>
390
- </a></p>
391
- <table class="form-table">
392
- <?php $this->generate_settings_html(); ?>
393
- </table>
394
- <?php
395
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
  }
 
397
  }
398
-
399
  /*
400
  * ========================================================================
401
- * CHECKOUT BUSINESS RULES
402
  * ========================================================================
403
  */
404
-
405
  public function payment_fields() {
406
  // basic checkout
407
- if ($description = $this->get_description() ) {
408
- echo wpautop( wptexturize( $description ) );
409
- }
410
- if ( $this->supports( 'default_credit_card_form' ) ) {
411
- $this->credit_card_form();
412
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  }
414
-
415
- // 1. First step occurs when the customer selects Mercado Pago and proceed to
416
- // checkout. This method verify which integration method was selected and
417
- // makes the build for the checkout URL.
 
 
 
 
418
  public function process_payment( $order_id ) {
419
- $order = new WC_Order( $order_id );
420
- // Check for the type of integration.
 
 
 
 
 
 
 
421
  if ( 'redirect' == $this->method ) {
422
- if ( 'yes' == $this->debug ) {
423
- $this->log->add( $this->id, $this->id . ': @[process_payment] - customer being redirected to Mercado Pago environment.' );
 
 
 
 
424
  }
425
  return array(
426
  'result' => 'success',
427
- 'redirect' => $this->createUrl( $order )
428
  );
429
- } else if ( 'modal' == $this->method || 'iframe' == $this->method ) {
 
430
  if ( 'yes' == $this->debug ) {
431
- $this->log->add( $this->id, $this->id . ': @[process_payment] - preparing to render Mercado Pago checkout view.' );
432
- }
433
- if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
434
- return array(
435
- 'result' => 'success',
436
- 'redirect' => $order->get_checkout_payment_url( true )
437
- );
438
- } else {
439
- return array(
440
- 'result' => 'success',
441
- 'redirect' => add_query_arg( 'order', $order->id, add_query_arg( 'key', $order->order_key, get_permalink( woocommerce_get_page_id( 'pay' ) ) ) )
442
  );
443
  }
 
 
 
 
444
  }
445
  }
446
 
447
- // 2. Order page and this generates the form that shows the pay button. This step
448
- // generates the form to proceed to checkout.
 
 
 
 
449
  public function receipt_page( $order ) {
450
- echo $this->renderOrderForm( $order );
451
  }
 
452
  // --------------------------------------------------
453
- public function renderOrderForm( $order_id ) {
454
- $order = new WC_Order( $order_id );
455
- $url = $this->createUrl( $order );
 
 
 
456
  if ( $url ) {
457
- // Display checkout.
458
  $html =
459
- $this->iframe_width_desc = '<img width="468" height="60" src="' .
460
- plugins_url( 'images/' . $this->banners_mercadopago_standard[ $this->site_id ], plugin_dir_path( __FILE__ ) ) . '">';
461
- if ( 'iframe' != $this->method ) {
462
  if ( 'yes' == $this->debug ) {
463
- $this->log->add( $this->id, $this->id . ': @[renderOrderForm] - rendering Mercado Pago lightbox (modal window).' );
 
 
 
464
  }
465
- $html .= '<p></p><p>' . wordwrap(
466
- __( 'Thank you for your order. Please, proceed with your payment clicking in the bellow button.', 'woocommerce-mercadopago-module' ),
467
- 60, '<br>') . '</p>';
468
  $html .=
469
- '<a id="submit-payment" href="' . $url . '" name="MP-Checkout" class="button alt" mp-mode="modal">' .
470
- __( 'Pay with Mercado Pago', 'woocommerce-mercadopago-module' ) .
471
- '</a> ';
 
 
472
  $html .=
473
- '<a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">' .
474
- __( 'Cancel order &amp; Clear cart', 'woocommerce-mercadopago-module' ) .
475
- '</a><style type="text/css">#MP-Checkout-dialog #MP-Checkout-IFrame { bottom: -28px !important; height: 590px !important; }</style>';
476
- // Includes javascript.
477
- $html .=
478
- '<script type="text/javascript">(function(){function $MPBR_load(){window.$MPBR_loaded !== true && (function(){var s = document.createElement("script");s.type = "text/javascript";s.async = true;s.src = ("https:"==document.location.protocol?"https://www.mercadopago.com/org-img/jsapi/mptools/buttons/":"http://mp-tools.mlstatic.com/buttons/")+"render.js";var x = document.getElementsByTagName("script")[0];x.parentNode.insertBefore(s, x);window.$MPBR_loaded = true;})();}window.$MPBR_loaded !== true ? (window.attachEvent ? window.attachEvent("onload", $MPBR_load) : window.addEventListener("load", $MPBR_load, false)) : null;})();</script>';
 
 
 
 
 
 
 
479
  } else {
 
480
  if ( 'yes' == $this->debug ) {
481
- $this->log->add( $this->id, $this->id . ': @[renderOrderForm] - embedding Mercado Pago iFrame.' );
 
 
 
482
  }
483
- $html .= '<p></p><p>' . wordwrap(
484
- __( 'Thank you for your order. Proceed with your payment completing the following information.', 'woocommerce-mercadopago-module' ),
485
- 60, '<br>' ) . '</p>';
486
  $html .=
487
- '<iframe src="' . $url . '" name="MP-Checkout" ' .
 
 
 
 
 
488
  'width="' . ( is_numeric( (int) $this->iframe_width ) ? $this->iframe_width : 640 ) . '" ' .
489
  'height="' . ( is_numeric( (int) $this->iframe_height ) ? $this->iframe_height : 800 ) . '" ' .
490
  'frameborder="0" scrolling="no" id="checkout_mercadopago"></iframe>';
491
  }
492
  return $html;
493
  } else {
494
- $html =
495
- '<p>' . __( 'An error occurred when proccessing your payment. Please try again or contact us for assistence.', 'woocommerce-mercadopago-module' ) . '</p>';
 
 
 
 
 
 
 
 
 
 
496
  $html .=
497
  '<a class="button" href="' . esc_url( $order->get_checkout_payment_url() ) . '">' .
498
- __( 'Click to try again', 'woocommerce-mercadopago-module' ) .
499
  '</a>';
500
  return $html;
501
  }
502
  }
503
-
504
- // 3. Create Mercado Pago preference and get init_point URL based in the
505
- // order options from the cart.
506
- public function buildPaymentPreference( $order ) {
507
 
508
- // Here we build the array that contains ordered itens, from customer cart
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
  $items = array();
510
  if ( sizeof( $order->get_items() ) > 0 ) {
511
  foreach ( $order->get_items() as $item ) {
512
  if ( $item['qty'] ) {
513
- $product = new WC_product( $item[ 'product_id' ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
514
  array_push( $items, array(
515
- 'id' => $item[ 'product_id' ],
516
- 'title' => ( $product->post->post_title . ' x ' . $item[ 'qty' ] ),
517
- 'description' => sanitize_file_name( (
518
  // This handles description width limit of Mercado Pago.
519
- strlen( $product->post->post_content ) > 230 ?
520
- substr( $product->post->post_content, 0, 230 ) . "..." :
521
- $product->post->post_content
522
  ) ),
523
- 'picture_url' => wp_get_attachment_url( $product->get_image_id() ),
524
- 'category_id' => $this->store_categories_id[ $this->category_id ],
 
 
 
525
  'quantity' => 1,
526
- 'unit_price' => ( ( (float) $item[ 'line_total' ] + (float) $item[ 'line_tax' ] ) ) *
527
- ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ),
528
- 'currency_id' => $this->getCurrencyId($this->site_id)
529
- ));
530
  }
531
  }
532
- // shipment cost as an item (workaround to prevent API showing shipment setup again)
533
- array_push($items, array(
534
- 'title' => $this->workaroundAmperSandBug( $this->workaroundAmperSandBug( $order->get_shipping_to_display() ) ),
535
- 'description' => __( 'Shipping service used by store', 'woocommerce-mercadopago-module' ),
536
- 'category_id' => $this->store_categories_id[$this->category_id],
537
- 'quantity' => 1,
538
- 'unit_price' => (float)$order->get_total_shipping() *
539
- ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ),
540
- 'currency_id' => $this->getCurrencyId($this->site_id)
541
- ));
542
- }
543
-
544
- // Find excluded payment methods. If 'n/d' is in array index, we should
545
- // disconsider the remaining values.
546
- $excluded_payment_methods = array();
547
- if ( is_array( $this->ex_payments ) || is_object( $this->ex_payments ) ) {
548
- try { // in some PHP versions, $this->ex_payments is interpreted as a not iterable object
549
- foreach ( $this->ex_payments as $excluded ) {
550
- if ( $excluded == 0 ) // if "n/d" is selected, we just not add any items to the array
551
- break;
552
- array_push( $excluded_payment_methods, array(
553
- "id" => $this->payment_methods[ $excluded ]
554
- ));
555
- }
556
- } catch ( MercadoPagoException $e ) {
557
- if ( 'yes' == $this->debug ) {
558
- $this->log->add(
559
- $this->id, $this->id .
560
- ': @[DEBUG] - excluded payments: exception caught: ' .
561
- json_encode( array( "status" => $e->getCode(), "message" => $e->getMessage() ) ) );
562
  }
563
- }
564
- }
565
- $payment_methods = array(
566
- 'installments' => ( is_numeric( (int) $this->installments) ? (int) $this->installments : 24 ),
567
- 'default_installments' => 1
568
- );
569
- // Set excluded payment methods.
570
- if ( count( $excluded_payment_methods ) > 0 ) {
571
- $payment_methods[ 'excluded_payment_methods' ] = $excluded_payment_methods;
572
- }
573
-
574
- // Create Mercado Pago preference.
575
- $preferences = array(
576
- 'items' => $items,
577
- // Payer should be filled with billing info because orders can be made with non-logged customers.
578
- 'payer' => array(
579
- 'name' => $order->billing_first_name,
580
- 'surname' => $order->billing_last_name,
581
- 'email' => $order->billing_email,
582
- 'phone' => array(
583
- 'number' => $order->billing_phone
584
- ),
585
- 'address' => array(
586
- 'street_name' => $order->billing_address_1 . ' / ' .
587
- $order->billing_city . ' ' .
588
- $order->billing_state . ' ' .
589
- $order->billing_country,
590
- 'zip_code' => $order->billing_postcode
591
- )
592
- ),
593
- 'back_urls' => array(
594
- 'success' => $this->workaroundAmperSandBug( esc_url( $this->get_return_url( $order ) ) ),
595
- 'failure' => $this->workaroundAmperSandBug( str_replace( '&amp;', '&', $order->get_cancel_order_url() ) ),
596
- 'pending' => $this->workaroundAmperSandBug( esc_url( $this->get_return_url( $order ) ) )
597
- ),
598
- //'marketplace' =>
599
- //'marketplace_fee' =>
600
- 'shipments' => array(
601
- //'cost' => (float) $order->get_total_shipping(),
602
- //'mode' =>
603
- 'receiver_address' => array(
604
- 'zip_code' => $order->shipping_postcode,
605
- //'street_number' =>
606
- 'street_name' => $order->shipping_address_1 . ' ' .
607
- $order->shipping_city . ' ' .
608
- $order->shipping_state . ' ' .
609
- $order->shipping_country,
610
- //'floor' =>
611
- 'apartment' => $order->shipping_address_2
612
- )
613
- ),
614
- 'payment_methods' => $payment_methods,
615
- 'notification_url' => $this->domain . '/' . $this->id . '/?wc-api=WC_WooMercadoPago_Gateway',
616
- 'external_reference' => $this->invoice_prefix . $order->id
617
- //'additional_info' => $order->customer_message
618
- //'expires' =>
619
- //'expiration_date_from' =>
620
- //'expiration_date_to' =>
621
  );
622
- // Set sponsor ID
623
- if ( !$this->isTestUser ) {
624
- $preferences[ 'sponsor_id' ] = (int) ( $this->sponsor_id[ $this->site_id ] );
625
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
626
  // Auto return options.
627
  if ( 'yes' == $this->auto_return ) {
628
- $preferences[ 'auto_return' ] = "approved";
629
  }
 
630
  if ( 'yes' == $this->debug ) {
631
  $this->log->add(
632
- $this->id, $this->id .
633
- ': @[buildPaymentPreference] - requesting mercado pago preference creation with following structure: ' .
634
- json_encode( $preferences, JSON_PRETTY_PRINT ) );
635
  }
636
- $preferences = apply_filters( 'woocommerce_mercadopago_module_preferences', $preferences, $order );
 
 
 
 
637
  return $preferences;
638
  }
 
639
  // --------------------------------------------------
640
- protected function createUrl( $order ) {
641
- // Creates the order parameters by checking the cart configuration.
642
- $preferences = $this->buildPaymentPreference( $order );
643
- $mp = new MP( $this->client_id, $this->client_secret );
644
  // Checks for sandbox mode.
645
  if ( 'yes' == $this->sandbox ) {
646
- $mp->sandbox_mode( true );
647
  if ( 'yes' == $this->debug ) {
648
- $this->log->add( $this->id, $this->id . ': @[createUrl] - sandbox mode is enabled' );
 
 
 
649
  }
650
  } else {
651
- $mp->sandbox_mode( false );
652
  }
 
 
 
653
  // Create order preferences with Mercado Pago API request.
654
  try {
655
- $checkout_info = $mp->create_preference( json_encode( $preferences ) );
656
- if ( is_wp_error( $checkout_info ) || $checkout_info[ 'status' ] < 200 || $checkout_info[ 'status' ] >= 300 ) {
 
 
 
 
 
 
 
 
 
 
657
  if ( 'yes' == $this->debug ) {
658
- $this->log->add( $this->id, $this->id . ': @[createUrl] - payment creation failed with error: ' . $checkout_info[ 'response' ][ 'status' ] );
 
 
 
659
  }
660
  return false;
661
  } else {
 
662
  if ( 'yes' == $this->debug ) {
663
- $this->log->add( $this->id, $this->id .
664
- ': @[createUrl] - payment link generated with success from mercado pago, with structure as follow: ' .
665
- json_encode( $checkout_info, JSON_PRETTY_PRINT ) );
 
666
  }
667
- if ( 'yes' == $this->sandbox ) {
668
- return $checkout_info[ 'response' ][ 'sandbox_init_point' ];
669
  } else {
670
- return $checkout_info[ 'response' ][ 'init_point' ];
671
  }
672
  }
673
  } catch ( MercadoPagoException $e ) {
 
674
  if ( 'yes' == $this->debug ) {
675
  $this->log->add(
676
- $this->id, $this->id .
677
- ': @[createUrl] - payment creation failed with exception: ' .
678
- json_encode( array( "status" => $e->getCode(), "message" => $e->getMessage() ) ) );
 
679
  }
680
  return false;
681
  }
 
682
  }
683
-
684
  /*
685
  * ========================================================================
686
- * AUXILIARY AND FEEDBACK METHODS
687
  * ========================================================================
688
  */
689
 
690
- // Fix to URL Problem : #038; replaces & and breaks the navigation
691
- function workaroundAmperSandBug( $link ) {
692
- return str_replace('&#038;', '&', $link);
693
- }
 
 
694
 
695
- // Check if we have valid credentials.
696
- public function validateCredentials() {
697
- if ( empty( $this->client_id ) ) return false;
698
- if ( empty( $this->client_secret ) ) return false;
699
- if ( strlen( $this->client_id ) > 0 && strlen( $this->client_secret ) > 0 ) {
700
- try {
701
- $mp = new MP( $this->client_id, $this->client_secret );
702
- $access_token = $mp->get_access_token();
703
- $get_request = $mp->get( "/users/me?access_token=" . $access_token );
704
- if ( isset( $get_request[ 'response' ][ 'site_id' ] ) ) {
705
- $this->isTestUser = in_array( 'test_user', $get_request[ 'response' ][ 'tags' ] );
706
- $this->site_id = $get_request[ 'response' ][ 'site_id' ];
707
- $payments = $mp->get( "/v1/payment_methods/?access_token=" . $access_token );
708
- array_push( $this->payment_methods, "n/d" );
709
- foreach ( $payments[ "response" ] as $payment ) {
710
- array_push( $this->payment_methods, str_replace( "_", " ", $payment[ 'id' ] ) );
711
- }
712
- // check for auto converstion of currency
713
- $this->currency_ratio = 1;
714
- $currency_obj = MPRestClient::get_ml( array( "uri" =>
715
- "/currency_conversions/search?from=" .
716
- get_woocommerce_currency() .
717
- "&to=" .
718
- $this->getCurrencyId( $this->site_id )
719
- ) );
720
- if ( isset( $currency_obj[ 'response' ] ) ) {
721
- $currency_obj = $currency_obj[ 'response' ];
722
- if ( isset( $currency_obj['ratio'] ) ) {
723
- $this->currency_ratio = (float) $currency_obj['ratio'];
724
- } else {
725
- $this->currency_ratio = -1;
726
- }
727
- } else {
728
- $this->currency_ratio = -1;
729
- }
730
- return true;
731
- } else return false;
732
- } catch ( MercadoPagoException $e ) {
 
 
 
 
 
 
733
  return false;
734
  }
 
 
 
 
 
 
 
 
 
 
 
735
  }
 
736
  return false;
 
737
  }
738
-
739
- // Build the string representing the path to the log file
740
- protected function buildLogPathString() {
741
  return '<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' .
742
  esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' .
743
  __( 'WooCommerce &gt; System Status &gt; Logs', 'woocommerce-mercadopago-module' ) . '</a>';
744
  }
745
 
746
  // Return boolean indicating if currency is supported.
747
- protected function isSupportedCurrency() {
748
- return get_woocommerce_currency() == $this->getCurrencyId( $this->site_id );
749
- }
750
-
751
- // Get currency id for a country
752
- protected function getCurrencyId( $site_id ) {
753
- switch ( $site_id ) {
754
- case 'MLA': return 'ARS';
755
- case 'MLB': return 'BRL';
756
- case 'MCO': return 'COP';
757
- case 'MLC': return 'CLP';
758
- case 'MLM': return 'MXN';
759
- case 'MLV': return 'VEF';
760
- case 'MPE': return 'PEN';
761
- default: return '';
762
- }
763
  }
764
 
765
  // Called automatically by WooCommerce, verify if Module is available to use.
766
  public function is_available() {
767
- // Test if is valid for use.
768
- $available = ( 'yes' == $this->settings[ 'enabled' ] ) &&
769
- ! empty( $this->client_id ) &&
770
- ! empty( $this->client_secret );
 
 
 
 
 
 
 
 
 
 
 
771
  return $available;
772
  }
773
-
774
  // Fix css for Mercado Pago in specific cases.
775
  public function css() {
776
  if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
@@ -778,11 +1446,12 @@ class WC_WooMercadoPago_Gateway extends WC_Payment_Gateway {
778
  } else {
779
  $page_id = woocommerce_get_page_id( 'checkout' );
780
  }
781
- if ( is_page($page_id ) ) {
782
- echo '<style type="text/css">#MP-Checkout-dialog { z-index: 9999 !important; }</style>' . PHP_EOL;
 
783
  }
784
  }
785
-
786
  // Get the URL to admin page.
787
  protected function admin_url() {
788
  if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
@@ -796,230 +1465,555 @@ class WC_WooMercadoPago_Gateway extends WC_Payment_Gateway {
796
  }
797
 
798
  // Notify that Client_id and/or Client_secret are not valid.
799
- public function clientIdOrSecretMissingMessage() {
800
- echo '<div class="error"><p><strong>' .
801
  __( 'Basic Checkout is Inactive', 'woocommerce-mercadopago-module' ) .
802
  '</strong>: ' .
803
- sprintf(
804
- __( 'Your Mercado Pago credentials Client_id/Client_secret appears to be misconfigured.', 'woocommerce-mercadopago-module' ) . ' %s',
805
- '<a href="' . $this->admin_url() . '">' . __( 'Click here and configure!', 'woocommerce-mercadopago-module' ) . '</a>' ) .
806
  '</p></div>';
807
  }
808
-
809
- public function getCountryName( $site_id ) {
810
- switch ( $site_id ) {
811
- case 'MLA': return __( 'Argentine', 'woocommerce-mercadopago-module' );
812
- case 'MLB': return __( 'Brazil', 'woocommerce-mercadopago-module' );
813
- case 'MCO': return __( 'Colombia', 'woocommerce-mercadopago-module' );
814
- case 'MLC': return __( 'Chile', 'woocommerce-mercadopago-module' );
815
- case 'MLM': return __( 'Mexico', 'woocommerce-mercadopago-module' );
816
- case 'MLV': return __( 'Venezuela', 'woocommerce-mercadopago-module' );
817
- case 'MPE': return __( 'Peru', 'woocommerce-mercadopago-module' );
818
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
819
  }
820
-
821
  /*
822
  * ========================================================================
823
- * IPN MECHANICS
824
  * ========================================================================
825
  */
826
-
827
- // This call checks any incoming notifications from Mercado Pago server.
 
 
 
828
  public function check_ipn_response() {
 
829
  @ob_clean();
 
830
  if ( 'yes' == $this->debug ) {
831
- $this->log->add( $this->id, $this->id .
832
- ': @[check_ipn_response] - Received _get content: ' .
833
- json_encode( $_GET, JSON_PRETTY_PRINT ) );
834
- }
835
- $data = $this->check_ipn_request_is_valid( $_GET );
836
- if ( $data ) {
837
- header( 'HTTP/1.1 200 OK' );
838
- do_action( 'valid_mercadopago_ipn_request', $data );
839
- }
840
- }
841
-
842
- // Get received data from IPN and checks if we have a merchant_order or
843
- // payment associated. If we have these information, we return data to be
844
- // processed by successful_request function.
845
- public function check_ipn_request_is_valid( $data ) {
846
-
847
- if ( !isset( $data[ 'id' ] ) || !isset( $data[ 'topic' ] ) ) {
848
- if ( 'yes' == $this->debug ) {
849
- $this->log->add( $this->id, $this->id .
850
- ': @[check_ipn_request_is_valid] - data_id or type not set: ' .
851
- json_encode( $data, JSON_PRETTY_PRINT ) );
852
- }
853
- // at least, check if its a v0 ipn
854
- if ( !isset( $data[ 'data_id' ] ) || !isset( $data[ 'type' ] ) ) {
855
- if ( 'yes' == $this->debug ) {
856
- $this->log->add(
857
- $this->id, $this->id .
858
- ': @[check_ipn_response] - Mercado Pago Request Failure: ' .
859
- json_encode( $_GET, JSON_PRETTY_PRINT ) );
860
- }
861
- wp_die( __( 'Mercado Pago Request Failure', 'woocommerce-mercadopago-module' ) );
862
- } else {
863
- header( 'HTTP/1.1 200 OK' );
864
- }
865
- // No ID? No process!
866
- return false;
867
- }
868
-
869
- // Create MP object and setup sandbox mode.
870
- $mp = new MP( $this->client_id, $this->client_secret );
871
- if ( 'yes' == $this->sandbox ) {
872
- $mp->sandbox_mode( true );
873
- } else {
874
- $mp->sandbox_mode( false );
875
  }
876
- try { // Get the merchant_order reported by the IPN. Glossary of attributes response in https://developers.mercadopago.com
877
- $params = array( "access_token" => $mp->get_access_token() );
878
- if ( $data[ "topic" ] == 'merchant_order' ) {
879
- $merchant_order_info = $mp->get( "/merchant_orders/" . $_GET[ "id" ], $params, false );
880
- // If the payment's transaction amount is equal (or bigger) than the merchant order's amount you can release your items
881
- if ( !is_wp_error( $merchant_order_info ) && ($merchant_order_info[ "status" ] == 200 ) ) {
882
- $payments = $merchant_order_info[ "response" ][ "payments" ];
883
- // check if we have more than one payment method
884
- if ( sizeof( $payments ) >= 1 ) { // We have payments
885
- return $merchant_order_info[ 'response' ];
886
- } else { // We have no payments?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
887
  if ( 'yes' == $this->debug ) {
888
- $this->log->add( $this->id, $this->id . ': @[check_ipn_request_is_valid] - order received but has no payment' );
 
 
 
889
  }
890
- return false;
891
  }
 
892
  } else {
893
  if ( 'yes' == $this->debug ) {
894
- $this->log->add( $this->id, $this->id . ': @[check_ipn_request_is_valid] - got status not equal 200 or some error' );
 
 
 
 
895
  }
896
- return false;
897
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
898
  }
899
- } catch ( MercadoPagoException $e ) {
 
 
 
 
 
 
 
 
 
 
900
  if ( 'yes' == $this->debug ) {
901
- $this->log->add( $this->id, $this->id .
902
- ': @[check_ipn_request_is_valid] - GOT EXCEPTION: ' .
903
- json_encode( array( "status" => $e->getCode(), "message" => $e->getMessage() ) ) );
 
904
  }
905
- return false;
 
906
  }
907
- return true;
908
  }
909
-
910
- // Properly handles each case of notification, based in payment status.
 
 
 
911
  public function successful_request( $data ) {
 
912
  if ( 'yes' == $this->debug ) {
913
- $this->log->add( $this->id, $this->id . ': @[successful_request] - starting to process ipn update...' );
 
 
 
914
  }
915
- $order_key = $data[ 'external_reference' ];
916
- if ( !empty( $order_key ) ) {
917
- $order_id = (int) str_replace( $this->invoice_prefix, '', $order_key );
918
- $order = new WC_Order( $order_id );
919
- // Checks whether the invoice number matches the order. If true processes the payment.
920
- if ( $order->id === $order_id ) {
921
- if ( 'yes' == $this->debug ) {
922
- $this->log->add( $this->id, $this->id . ': @[successful_request] - got order with ID ' . $order->id . ' and status ' . $data[ 'payments' ][ 0 ][ 'status' ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
923
  }
924
- // Order details.
925
- if ( !empty( $data[ 'payer' ][ 'email' ] ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
926
  update_post_meta(
927
  $order_id,
928
- __( 'Payer email', 'woocommerce-mercadopago-module' ),
929
- $data[ 'payer' ][ 'email' ]
 
 
 
930
  );
931
  }
932
- if ( !empty( $data[ 'payment_type' ] ) ) {
933
  update_post_meta(
934
  $order_id,
935
- __( 'Payment type', 'woocommerce-mercadopago-module' ),
936
- $data[ 'payment_type' ]
937
  );
938
  }
939
- if ( !empty( $data[ 'payments' ] ) ) {
940
- $payment_ids = array();
941
- foreach ( $data[ 'payments' ] as $payment ) {
942
- $payment_ids[] = $payment[ 'id' ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
943
  }
944
- if ( sizeof( $payment_ids ) > 0 ) {
945
- update_post_meta(
946
- $order_id,
947
- __( 'Mercado Pago Payment ID', 'woocommerce-mercadopago-module' ),
948
- implode( ', ', $payment_ids )
949
- );
950
  }
951
- }
952
- // Here, we process the status...
953
- $status = 'pending';
954
- if ( sizeof( $data[ 'payments' ] ) == 1 ) {
955
- // if there's only one payment, then we get its status
956
- $status = $data[ 'payments' ][ 0 ][ 'status' ];
957
- } else if ( sizeof( $data[ 'payments' ] ) > 1 ) {
958
- // otherwise, we check payment sum
959
- $total_paid = 0.00;
960
- foreach ( $data[ 'payments' ] as $payment ) {
961
- if ( $payment[ 'status' ] === 'approved' ) {
962
- $total_paid = $total_paid + (float) $payment[ 'total_paid_amount' ];
963
- }
 
 
 
 
 
 
 
 
964
  }
965
- $total = $data[ 'shipping_cost' ] + $data[ 'total_amount' ];
966
- if ( $total_paid >= $total ) {
967
- // At this point, the sum of approved payments are above or equal than the total order amount, so it is approved
968
- $status = 'approved';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
969
  }
970
- }
971
- // Switch the status and update in WooCommerce
972
- switch ( $status ) {
973
- case 'approved':
974
- $order->add_order_note(
975
- 'Mercado Pago: ' . __( 'Payment approved.', 'woocommerce-mercadopago-module' )
976
- );
977
- $order->payment_complete();
978
- break;
979
- case 'pending':
980
- $order->add_order_note(
981
- 'Mercado Pago: ' . __( 'Customer haven\'t paid yet.', 'woocommerce-mercadopago-module' )
982
- );
983
- break;
984
- case 'in_process':
985
- $order->update_status(
986
- 'on-hold',
987
- 'Mercado Pago: ' . __( 'Payment under review.', 'woocommerce-mercadopago-module' )
988
- );
989
- break;
990
- case 'rejected':
991
- $order->update_status(
992
- 'failed',
993
- 'Mercado Pago: ' . __( 'The payment was refused. The customer can try again.', 'woocommerce-mercadopago-module' )
994
- );
995
- break;
996
- case 'refunded':
997
- $order->update_status(
998
- 'refunded',
999
- 'Mercado Pago: ' . __( 'The payment was refunded to the customer.', 'woocommerce-mercadopago-module' )
1000
- );
1001
- break;
1002
- case 'cancelled':
1003
- $order->update_status(
1004
- 'cancelled',
1005
- 'Mercado Pago: ' . __( 'The payment was cancelled.', 'woocommerce-mercadopago-module' )
1006
- );
1007
- break;
1008
- case 'in_mediation':
1009
- $order->add_order_note(
1010
- 'Mercado Pago: ' . __( 'The payment is under mediation or it was charged-back.', 'woocommerce-mercadopago-module' )
1011
- );
1012
- break;
1013
- case 'charged-back':
1014
- $order->add_order_note(
1015
- 'Mercado Pago: ' . __( 'The payment is under mediation or it was charged-back.', 'woocommerce-mercadopago-module' )
 
 
 
1016
  );
1017
- break;
1018
- default:
1019
- break;
1020
  }
 
1021
  }
1022
  }
 
1023
  }
1024
-
1025
- }
1
  <?php
2
+
3
  /**
4
  * Part of Woo Mercado Pago Module
5
  * Author - Mercado Pago
6
  * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
7
+ * Copyright - Copyright(c) MercadoPago [https://www.mercadopago.com]
8
+ * License - https://www.gnu.org/licenses/gpl.html GPL version 2 or higher
9
  */
10
 
11
  // This include Mercado Pago library SDK
12
+ require_once dirname( __FILE__ ) . '/sdk/lib/mercadopago.php';
13
 
14
+ /**
15
+ * Summary: Extending from WooCommerce Payment Gateway class.
16
+ * Description: This class implements Mercado Pago Basic checkout.
17
+ * @since 1.0.0
18
+ */
19
  class WC_WooMercadoPago_Gateway extends WC_Payment_Gateway {
20
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  public function __construct() {
22
 
23
+ // Creating PHP version message.
24
+ $min_php_message = phpversion() >= WC_WooMercadoPago_Module::MIN_PHP ?
25
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
26
+ __( 'Your PHP version is OK.', 'woocommerce-mercadopago-module' ) :
27
+ '<img width="14" height="14" src="' . plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
28
+ sprintf(
29
+ __( 'Your PHP version do not support this module. You have %s, minimal required is %s.', 'woocommerce-mercadopago-module' ),
30
+ phpversion(), WC_WooMercadoPago_Module::MIN_PHP
31
+ );
32
+ // Check cURL.
33
+ $curl_message = in_array( 'curl', get_loaded_extensions() ) ?
34
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
35
+ __( 'cURL is installed.', 'woocommerce-mercadopago-module' ) :
36
+ '<img width="14" height="14" src="' . plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
37
+ __( 'cURL is not installed.', 'woocommerce-mercadopago-module' );
38
+ // Check SSL.
39
+ $is_ssl_message = empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ?
40
+ '<img width="14" height="14" src="' . plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
41
+ __( 'SSL is missing in your site.', 'woocommerce-mercadopago-module' ) :
42
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
43
+ __( 'Your site has SSL enabled.', 'woocommerce-mercadopago-module' );
44
+
45
+ // Mercado Pago fields.
46
+ $this->mp = null;
47
  $this->site_id = null;
48
+ $this->collector_id = null;
49
+ $this->currency_ratio = -1;
50
+ $this->is_test_user = false;
51
+
52
+ // Auxiliary fields.
53
+ $this->currency_message = '';
54
  $this->payment_methods = array();
55
+ $this->country_configs = array();
56
  $this->store_categories_id = array();
57
+ $this->store_categories_description = array();
58
+
59
+ // WooCommerce fields.
60
+ $this->supports = array( 'products', 'refunds' );
61
  $this->id = 'woocommerce-mercadopago-module';
62
+ $this->domain = get_site_url() . '/index.php';
63
  $this->icon = apply_filters(
64
  'woocommerce_mercadopago_icon',
65
  plugins_url( 'images/mercadopago.png', plugin_dir_path( __FILE__ ) )
66
  );
67
  $this->method_title = __( 'Mercado Pago - Basic Checkout', 'woocommerce-mercadopago-module' );
68
  $this->method_description = '<img width="200" height="52" src="' .
69
+ plugins_url(
70
+ 'images/mplogo.png',
71
+ plugin_dir_path( __FILE__ )
72
+ ) . '"><br><br>' . '<strong>' .
73
+ __( 'This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store.', 'woocommerce-mercadopago-module' ) .
74
+ '</strong>' . '<br><br>' .
75
+ $min_php_message . '<br>' .
76
+ $is_ssl_message . '<br>' .
77
+ $curl_message;
78
+
79
+ // Fields used in Mercado Pago Module configuration page.
80
  $this->client_id = $this->get_option( 'client_id' );
81
  $this->client_secret = $this->get_option( 'client_secret' );
82
  $this->title = $this->get_option( 'title' );
83
  $this->description = $this->get_option( 'description' );
84
  $this->category_id = $this->get_option( 'category_id' );
85
  $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' );
86
+ $this->method = $this->get_option( 'method', 'iframe' );
87
  $this->iframe_width = $this->get_option( 'iframe_width', 640 );
88
  $this->iframe_height = $this->get_option( 'iframe_height', 800 );
89
  $this->auto_return = $this->get_option( 'auto_return', true );
90
+ $this->success_url = $this->get_option( 'success_url', '' );
91
+ $this->failure_url = $this->get_option( 'failure_url', '' );
92
+ $this->pending_url = $this->get_option( 'pending_url', '' );
93
+ $this->currency_conversion = $this->get_option( 'currency_conversion', false );
94
  $this->installments = $this->get_option( 'installments', '24' );
95
  $this->ex_payments = $this->get_option( 'ex_payments', 'n/d' );
96
+ $this->gateway_discount = $this->get_option( 'gateway_discount', 0 );
97
+ $this->payment_split_mode = 'inactive';
98
+ //$this->sandbox = $this->get_option( 'sandbox', false );
99
+ $this->sandbox = 'no';
100
+ $this->debug = $this->get_option( 'debug' );
101
+
102
+ // Logging and debug.
103
+ if ( 'yes' == $this->debug ) {
104
+ if ( class_exists( 'WC_Logger' ) ) {
105
+ $this->log = new WC_Logger();
106
+ } else {
107
+ $this->log = WC_MercadoPago_Module::woocommerce_instance()->logger();
108
+ }
109
+ }
110
+
111
  // Render our configuration page and init/load fields.
112
  $this->init_form_fields();
113
  $this->init_settings();
114
 
115
+ // Used by IPN to receive IPN incomings.
116
+ add_action(
117
  'woocommerce_api_wc_woomercadopago_gateway',
118
  array( $this, 'check_ipn_response' )
119
  );
120
+ // Used by IPN to process valid incomings.
121
+ add_action(
122
  'valid_mercadopago_ipn_request',
123
  array( $this, 'successful_request' )
124
  );
125
+ // Process the cancel order meta box order action.
126
+ add_action(
127
+ 'woocommerce_order_action_cancel_order',
128
+ array( $this, 'process_cancel_order_meta_box_actions' )
129
+ );
130
+ // Used by WordPress to render the custom checkout page.
131
+ add_action(
132
  'woocommerce_receipt_' . $this->id,
133
  array( $this, 'receipt_page' )
134
  );
135
+ // Used to fix CSS in some older WordPress/WooCommerce versions.
136
+ add_action(
137
  'wp_head',
138
  array( $this, 'css' )
139
  );
140
+ // Used in settings page to hook "save settings" action.
141
+ add_action(
142
  'woocommerce_update_options_payment_gateways_' . $this->id,
143
+ array( $this, 'custom_process_admin_options' )
144
+ );
145
+ // Scripts for order configuration.
146
+ add_action(
147
+ 'woocommerce_after_checkout_form',
148
+ array( $this, 'add_checkout_script' )
149
+ );
150
+ // Display discount in payment method title.
151
+ add_filter(
152
+ 'woocommerce_gateway_title',
153
+ array( $this, 'get_payment_method_title_basic' ), 10, 2
154
  );
155
+ // Checkout updates.
156
+ add_action(
157
+ 'woocommerce_thankyou',
158
+ array( $this, 'update_checkout_status' )
159
+ );
160
+
161
  // Verify if client_id or client_secret is empty.
162
  if ( empty( $this->client_id ) || empty( $this->client_secret ) ) {
163
+ if ( ! empty( $this->settings['enabled'] ) && 'yes' == $this->settings['enabled'] ) {
164
+ add_action( 'admin_notices', array( $this, 'client_id_or_secret_missing_message' ) );
 
 
 
 
 
 
 
165
  }
166
  }
167
+
168
  }
169
+
170
+ /**
171
+ * Summary: Initialise Gateway Settings Form Fields.
172
+ * Description: Initialise Gateway settings form fields with a customized page.
173
+ */
174
  public function init_form_fields() {
175
+
176
+ // If module is disabled, we do not need to load and process the settings page.
177
+ if ( empty( $this->settings['enabled'] ) || 'no' == $this->settings['enabled'] ) {
178
+ $this->form_fields = array(
179
+ 'enabled' => array(
180
+ 'title' => __( 'Enable/Disable', 'woocommerce-mercadopago-module' ),
181
+ 'type' => 'checkbox',
182
+ 'label' => __( 'Enable Basic Checkout', 'woocommerce-mercadopago-module' ),
183
+ 'default' => 'no'
184
+ )
185
+ );
186
+ return;
187
+ }
188
+
189
  $api_secret_locale = sprintf(
190
  '<a href="https://www.mercadopago.com/mla/account/credentials?type=basic" target="_blank">%s</a>, ' .
191
  '<a href="https://www.mercadopago.com/mlb/account/credentials?type=basic" target="_blank">%s</a>, ' .
192
  '<a href="https://www.mercadopago.com/mlc/account/credentials?type=basic" target="_blank">%s</a>, ' .
193
  '<a href="https://www.mercadopago.com/mco/account/credentials?type=basic" target="_blank">%s</a>, ' .
194
  '<a href="https://www.mercadopago.com/mlm/account/credentials?type=basic" target="_blank">%s</a>, ' .
195
+ '<a href="https://www.mercadopago.com/mpe/account/credentials?type=basic" target="_blank">%s</a>, ' .
196
+ '<a href="https://www.mercadopago.com/mlu/account/credentials?type=basic" target="_blank">%s</a> %s ' .
197
  '<a href="https://www.mercadopago.com/mlv/account/credentials?type=basic" target="_blank">%s</a>',
198
  __( 'Argentine', 'woocommerce-mercadopago-module' ),
199
  __( 'Brazil', 'woocommerce-mercadopago-module' ),
201
  __( 'Colombia', 'woocommerce-mercadopago-module' ),
202
  __( 'Mexico', 'woocommerce-mercadopago-module' ),
203
  __( 'Peru', 'woocommerce-mercadopago-module' ),
204
+ __( 'Uruguay', 'woocommerce-mercadopago-module' ),
205
  __( 'or', 'woocommerce-mercadopago-module' ),
206
  __( 'Venezuela', 'woocommerce-mercadopago-module' )
207
  );
208
+
209
  // Trigger API to get payment methods and site_id, also validates Client_id/Client_secret.
210
+ if ( $this->validate_credentials() ) {
211
+ // Checking the currency.
212
+ $this->currency_message = '';
213
+ if ( ! $this->is_supported_currency() && 'yes' == $this->settings['enabled'] ) {
214
+ if ( $this->currency_conversion == 'no' ) {
215
+ $this->currency_ratio = -1;
216
+ $this->currency_message .= WC_WooMercadoPago_Module::build_currency_not_converted_msg(
217
+ $this->country_configs['currency'],
218
+ $this->country_configs['country_name']
219
+ );
220
+ } elseif ( $this->currency_conversion == 'yes' && $this->currency_ratio != -1) {
221
+ $this->currency_message .= WC_WooMercadoPago_Module::build_currency_converted_msg(
222
+ $this->country_configs['currency'],
223
+ $this->currency_ratio
224
+ );
 
 
 
 
 
 
 
 
 
 
 
225
  } else {
226
  $this->currency_ratio = -1;
227
+ $this->currency_message .= WC_WooMercadoPago_Module::build_currency_conversion_err_msg(
228
+ $this->country_configs['currency']
229
+ );
230
  }
231
+ } else {
232
+ $this->currency_ratio = -1;
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  }
234
+ $this->credentials_message = WC_WooMercadoPago_Module::build_valid_credentials_msg(
235
+ $this->country_configs['country_name'],
236
+ $this->site_id
237
+ );
238
+ $this->payment_desc =
239
+ __( 'Select the payment methods that you <strong>don\'t</strong> want to receive with Mercado Pago.', 'woocommerce-mercadopago-module' );
240
  } else {
241
+ array_push( $this->payment_methods, 'n/d' );
242
+ $this->credentials_message = WC_WooMercadoPago_Module::build_invalid_credentials_msg();
243
  $this->payment_desc = '<img width="12" height="12" src="' .
244
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
245
+ __( 'Configure your Client_id and Client_secret to have access to more options.', 'woocommerce-mercadopago-module' );
 
 
 
246
  }
247
+
248
+ // fill categories (can be handled without credentials).
249
+ $categories = WC_WooMercadoPago_Module::get_categories();
250
+ $this->store_categories_id = $categories['store_categories_id'];
251
+ $this->store_categories_description = $categories['store_categories_description'];
252
+
 
 
253
  // Checks validity of iFrame width/height fields.
254
+ if ( ! is_numeric( $this->iframe_width) ) {
255
  $this->iframe_width_desc = '<img width="12" height="12" src="' .
256
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
257
+ __( 'This field should be an integer.', 'woocommerce-mercadopago-module' );
258
  } else {
259
  $this->iframe_width_desc =
260
  __( 'If your integration method is iFrame, please inform the payment iFrame width.', 'woocommerce-mercadopago-module' );
261
  }
262
+ if ( ! is_numeric( $this->iframe_height) ) {
263
  $this->iframe_height_desc = '<img width="12" height="12" src="' .
264
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
265
+ __( 'This field should be an integer.', 'woocommerce-mercadopago-module' );
266
  } else {
267
  $this->iframe_height_desc =
268
  __( 'If your integration method is iFrame, please inform the payment iFrame height.', 'woocommerce-mercadopago-module' );
269
  }
270
+
271
  // Checks if max installments is a number.
272
+ if ( ! is_numeric( $this->installments ) ) {
273
  $this->installments_desc = '<img width="12" height="12" src="' .
274
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
275
+ __( 'This field should be an integer.', 'woocommerce-mercadopago-module' );
276
  } else {
277
  $this->installments_desc =
278
  __( 'Select the max number of installments for your customers.', 'woocommerce-mercadopago-module' );
279
  }
280
+
281
+ // Validate discount field.
282
+ if ( ! is_numeric( $this->gateway_discount ) ) {
283
+ $this->gateway_discount_desc = '<img width="12" height="12" src="' .
284
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
285
+ __( 'This field should be an integer greater or equal 0 and smaller than 100.', 'woocommerce-mercadopago-module' );
286
+ } elseif ( $this->gateway_discount < 0 || $this->gateway_discount >= 100 ) {
287
+ $this->gateway_discount_desc = '<img width="12" height="12" src="' .
288
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
289
+ __( 'This field should be an integer greater or equal 0 and smaller than 100.', 'woocommerce-mercadopago-module' );
290
+ } else {
291
+ $this->gateway_discount_desc =
292
+ __( 'Give a percentual discount for your customers if they use this payment gateway.', 'woocommerce-mercadopago-module' );
293
+ }
294
+
295
  // This array draws each UI (text, selector, checkbox, label, etc).
296
  $this->form_fields = array(
297
  'enabled' => array(
303
  'credentials_title' => array(
304
  'title' => __( 'Mercado Pago Credentials', 'woocommerce-mercadopago-module' ),
305
  'type' => 'title',
306
+ 'description' => sprintf( '%s', $this->credentials_message ) . '<br>' . sprintf(
307
+ __( 'You can obtain your credentials for', 'woocommerce-mercadopago-module' ) .
308
+ ' %s.', $api_secret_locale
309
+ )
310
  ),
311
  'client_id' => array(
312
  'title' => 'Client_id',
313
  'type' => 'text',
314
+ 'description' =>
315
+ __( 'Insert your Mercado Pago Client_id.', 'woocommerce-mercadopago-module' ),
316
  'default' => '',
317
  'required' => true
318
  ),
319
  'client_secret' => array(
320
  'title' => 'Client_secret',
321
  'type' => 'text',
322
+ 'description' =>
323
+ __( 'Insert your Mercado Pago Client_secret.', 'woocommerce-mercadopago-module' ),
324
  'default' => '',
325
  'required' => true
326
  ),
327
  'ipn_url' => array(
328
+ 'title' =>
329
+ __( 'Instant Payment Notification (IPN) URL', 'woocommerce-mercadopago-module' ),
330
  'type' => 'title',
331
+ 'description' => sprintf(
332
+ __( 'Your IPN URL to receive instant payment notifications is', 'woocommerce-mercadopago-module' ) .
333
+ '<br>%s', '<code>' . WC()->api_request_url( 'WC_WooMercadoPago_Gateway' ) . '</code>.'
334
+ )
335
  ),
336
  'checkout_options_title' => array(
337
  'title' => __( 'Checkout Options', 'woocommerce-mercadopago-module' ),
341
  'title' => array(
342
  'title' => __( 'Title', 'woocommerce-mercadopago-module' ),
343
  'type' => 'text',
344
+ 'description' =>
345
+ __( 'Title shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
346
  'default' => __( 'Mercado Pago', 'woocommerce-mercadopago-module' )
347
  ),
348
  'description' => array(
349
  'title' => __( 'Description', 'woocommerce-mercadopago-module' ),
350
  'type' => 'textarea',
351
+ 'description' =>
352
+ __( 'Description shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
353
  'default' => __( 'Pay with Mercado Pago', 'woocommerce-mercadopago-module' )
354
  ),
355
  'category_id' => array(
356
  'title' => __( 'Store Category', 'woocommerce-mercadopago-module' ),
357
  'type' => 'select',
358
+ 'description' =>
359
+ __( 'Define which type of products your store sells.', 'woocommerce-mercadopago-module' ),
360
  'options' => $this->store_categories_id
361
  ),
362
  'invoice_prefix' => array(
363
  'title' => __( 'Store Identificator', 'woocommerce-mercadopago-module' ),
364
  'type' => 'text',
365
+ 'description' =>
366
+ __( 'Please, inform a prefix to your store.', 'woocommerce-mercadopago-module' )
367
+ . ' ' .
368
+ __( 'If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same identificators.', 'woocommerce-mercadopago-module' ),
369
  'default' => 'WC-'
370
  ),
371
  'method' => array(
396
  'type' => 'checkbox',
397
  'label' => __( 'Automatic Return After Payment', 'woocommerce-mercadopago-module' ),
398
  'default' => 'yes',
399
+ 'description' =>
400
+ __( 'After the payment, client is automatically redirected.', 'woocommerce-mercadopago-module' ),
401
+ ),
402
+ 'back_url_title' => array(
403
+ 'title' => __( 'Back URL Options', 'woocommerce-mercadopago-module' ),
404
+ 'type' => 'title',
405
+ 'description' => ''
406
+ ),
407
+ 'success_url' => array(
408
+ 'title' => __( 'Sucess URL', 'woocommerce-mercadopago-module' ),
409
+ 'type' => 'text',
410
+ 'description' => __( 'Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page.', 'woocommerce-mercadopago-module' ),
411
+ 'default' => ''
412
+ ),
413
+ 'failure_url' => array(
414
+ 'title' => __( 'Failure URL', 'woocommerce-mercadopago-module' ),
415
+ 'type' => 'text',
416
+ 'description' => __( 'Where customers should be redirected after a failed purchase. Let blank to redirect to the default store order resume page.', 'woocommerce-mercadopago-module' ),
417
+ 'default' => ''
418
+ ),
419
+ 'pending_url' => array(
420
+ 'title' => __( 'Pending URL', 'woocommerce-mercadopago-module' ),
421
+ 'type' => 'text',
422
+ 'description' => __( 'Where customers should be redirected after a pending purchase. Let blank to redirect to the default store order resume page.', 'woocommerce-mercadopago-module' ),
423
+ 'default' => ''
424
  ),
425
  'payment_title' => array(
426
  'title' => __( 'Payment Options', 'woocommerce-mercadopago-module' ),
430
  'currency_conversion' => array(
431
  'title' => __( 'Currency Conversion', 'woocommerce-mercadopago-module' ),
432
  'type' => 'checkbox',
433
+ 'label' =>
434
+ __( 'If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio.', 'woocommerce-mercadopago-module' ),
435
  'default' => 'no',
436
  'description' => sprintf( '%s', $this->currency_message )
437
  ),
442
  'default' => '24'
443
  ),
444
  'ex_payments' => array(
445
+ 'title' => __( 'Exclude Payment Methods', 'woocommerce-mercadopago-module' ),
446
+ 'description' => $this->payment_desc,
447
+ 'type' => 'multiselect',
448
+ 'options' => $this->payment_methods,
449
+ 'default' => ''
450
+ ),
451
+ 'gateway_discount' => array(
452
+ 'title' => __( 'Discount by Gateway', 'woocommerce-mercadopago-module' ),
453
+ 'type' => 'number',
454
+ 'description' => $this->gateway_discount_desc,
455
+ 'default' => '0'
456
+ ),
457
+ 'payment_split_mode' => array(
458
+ 'title' => __( 'Two Cards Mode', 'woocommerce-mercadopago-module' ),
459
+ 'type' => 'checkbox',
460
+ 'label' => __( 'Payments with Two Cards', 'woocommerce-mercadopago-module' ),
461
+ 'default' => ( $this->payment_split_mode == 'active' ? 'yes' : 'no' ),
462
+ 'description' =>
463
+ __( 'Your customer will be able to use two different cards to pay the order.', 'woocommerce-mercadopago-module' ),
464
+ ),
465
  'testing' => array(
466
  'title' => __( 'Test and Debug Options', 'woocommerce-mercadopago-module' ),
467
  'type' => 'title',
468
  'description' => ''
469
  ),
470
+ //'sandbox' => array(
471
+ // 'title' => __( 'Mercado Pago Sandbox', 'woocommerce-mercadopago-module' ),
472
+ // 'type' => 'checkbox',
473
+ // 'label' => __( 'Enable Mercado Pago Sandbox', 'woocommerce-mercadopago-module' ),
474
+ // 'default' => 'no',
475
+ // 'description' =>
476
+ // __( 'This option allows you to test payments inside a sandbox environment.', 'woocommerce-mercadopago-module' ),
477
+ //),
478
  'debug' => array(
479
  'title' => __( 'Debug and Log', 'woocommerce-mercadopago-module' ),
480
  'type' => 'checkbox',
481
  'label' => __( 'Enable log', 'woocommerce-mercadopago-module' ),
482
  'default' => 'no',
483
+ 'description' => sprintf(
484
+ __( 'Register event logs of Mercado Pago, such as API requests, in the file', 'woocommerce-mercadopago-module' ) .
485
+ ' %s.', $this->build_log_path_string() . '.<br>' .
486
+ __( 'File location: ', 'woocommerce-mercadopago-module' ) .
487
+ '<code>wordpress/wp-content/uploads/wc-logs/' . $this->id . '-' .
488
+ sanitize_file_name( wp_hash( $this->id) ) . '.log</code>' )
489
  )
490
  );
491
+
492
+ }
493
+
494
+ /**
495
+ * Processes and saves options.
496
+ * If there is an error thrown, will continue to save and validate fields, but will leave the
497
+ * erroring field out.
498
+ * @return bool was anything saved?
499
+ */
500
+ public function custom_process_admin_options() {
501
+ $this->init_settings();
502
+
503
+ $post_data = $this->get_post_data();
504
+
505
+ foreach ( $this->get_form_fields() as $key => $field ) {
506
+ if ( 'title' !== $this->get_field_type( $field ) ) {
507
+ try {
508
+ if ( $key == 'payment_split_mode' ) {
509
+ // We dont save split mode as it should come from api.
510
+ $value = $this->get_field_value( $key, $field, $post_data );
511
+ $this->payment_split_mode = ( $value == 'yes' ? 'active' : 'inactive' );
512
+ } else {
513
+ $this->settings[$key] = $this->get_field_value( $key, $field, $post_data );
514
+ }
515
+ } catch ( Exception $e ) {
516
+ $this->add_error( $e->getMessage() );
517
+ }
518
+ }
519
+ }
520
+
521
+ if ( ! empty( $this->settings['client_id'] ) && ! empty( $this->settings['client_secret'] ) ) {
522
+ $this->mp = new MP(
523
+ WC_WooMercadoPago_Module::get_module_version(),
524
+ $this->settings['client_id'],
525
+ $this->settings['client_secret']
526
+ );
527
+ } else {
528
+ $this->mp = null;
529
+ }
530
+
531
+ // analytics
532
+ if ( $this->mp != null && ! $this->is_test_user ) {
533
+ $infra_data = WC_WooMercadoPago_Module::get_common_settings();
534
+ $infra_data['checkout_basic'] = ( $this->settings['enabled'] == 'yes' ? 'true' : 'false' );
535
+ $infra_data['two_cards'] = ( $this->payment_split_mode == 'active' ? 'true' : 'false' );
536
+ $response = $this->mp->analytics_save_settings( $infra_data );
537
+ if ( 'yes' == $this->debug) {
538
+ $this->log->add(
539
+ $this->id,
540
+ '[custom_process_admin_options] - analytics response: ' .
541
+ json_encode( $response, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
542
+ );
543
+ }
544
+ }
545
+
546
+ // two cards mode
547
+ if ( $this->mp != null ) {
548
+ $response = $this->mp->set_two_cards_mode( $this->payment_split_mode );
549
+ }
550
+
551
+ return update_option(
552
+ $this->get_option_key(),
553
+ apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings )
554
+ );
555
  }
556
+
557
+ /**
558
+ * Handles the manual order refunding in server-side.
559
+ */
560
+ public function process_refund( $order_id, $amount = null, $reason = '' ) {
561
+
562
+ $payments = get_post_meta(
563
+ $order_id,
564
+ '_Mercado_Pago_Payment_IDs',
565
+ true
566
+ );
567
+
568
+ // Validate.
569
+ if ( $this->mp == null || empty( $payments ) ) {
570
+ if ( 'yes' == $this->debug ) {
571
+ $this->log->add(
572
+ $this->id,
573
+ '[process_refund] - no payments or credentials invalid'
574
+ );
575
+ }
576
+ return false;
577
+ }
578
+
579
+ $total_available = 0;
580
+ $payment_structs = array();
581
+ $payment_ids = explode( ', ', $payments );
582
+ foreach ( $payment_ids as $p_id ) {
583
+ $p = get_post_meta(
584
+ $order_id,
585
+ 'Mercado Pago - Payment ' . $p_id,
586
+ true
587
+ );
588
+ $p = explode( '/', $p );
589
+ $paid_arr = explode( ' ', substr( $p[2], 1, -1 ) );
590
+ $paid = ( (float) $paid_arr[1] );
591
+ $refund_arr = explode( ' ', substr( $p[3], 1, -1 ) );
592
+ $refund = ( (float) $refund_arr[1] );
593
+ $p_struct = array(
594
+ 'id' => $p_id,
595
+ 'available_to_refund' => $paid - $refund
596
+ );
597
+ $total_available += $paid - $refund;
598
+ $payment_structs[] = $p_struct;
599
+ }
600
+
601
+ if ( 'yes' == $this->debug ) {
602
+ $this->log->add(
603
+ $this->id,
604
+ '[process_refund] - refunding ' . $amount . ' because of ' . $reason . ' and payments ' .
605
+ json_encode( $payment_structs, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
606
+ );
607
+ }
608
+
609
+ // Do not allow refund more than available or invalid amounts.
610
+ if ( $amount > $total_available || $amount <= 0 ) {
611
  return false;
612
+ }
613
+
614
+ $remaining_to_refund = $amount;
615
+ foreach ( $payment_structs as $to_refund ) {
616
+ if ( $remaining_to_refund <= $to_refund['available_to_refund'] ) {
617
+ // We want to refund an amount that is less than the available for this payment, so we
618
+ // can just refund and return.
619
+ $response = $this->mp->partial_refund_payment(
620
+ $to_refund['id'],
621
+ $remaining_to_refund,
622
+ $reason,
623
+ $this->invoice_prefix . $order_id
624
+ );
625
+ $message = $response['response']['message'];
626
+ $status = $response['status'];
627
+ if ( 'yes' == $this->debug ) {
628
+ $this->log->add(
629
+ $this->id,
630
+ '[process_refund] - refund payment of id ' . $p_id .
631
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
632
+ );
633
+ }
634
+ if ( $status >= 200 && $status < 300 ) {
635
+ return true;
636
+ } else {
637
+ return false;
638
+ }
639
+ } elseif ( $to_refund['available_to_refund'] > 0 ) {
640
+ // We want to refund an amount that exceeds the available for this payment, so we
641
+ // totally refund this payment, and try to complete refund in other/next payments.
642
+ $response = $this->mp->partial_refund_payment(
643
+ $to_refund['id'],
644
+ $to_refund['available_to_refund'],
645
+ $reason,
646
+ $this->invoice_prefix . $order_id
647
+ );
648
+ $message = $response['response']['message'];
649
+ $status = $response['status'];
650
+ if ( 'yes' == $this->debug ) {
651
+ $this->log->add(
652
+ $this->id,
653
+ '[process_refund] - refund payment of id ' . $p_id .
654
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
655
+ );
656
+ }
657
+ if ( $status < 200 || $status >= 300 ) {
658
+ return false;
659
+ }
660
+ $remaining_to_refund -= $to_refund['available_to_refund'];
661
+ }
662
+ if ( $remaining_to_refund == 0 )
663
+ return true;
664
+ }
665
+
666
+ // Reaching here means that there we run out of payments, and there is an amount
667
+ // remaining to be refund, which is impossible as it implies refunding more than
668
+ // available on paid amounts.
669
+ return false;
670
+
671
+ }
672
+
673
+ /**
674
+ * Handles the manual order cancellation in server-side.
675
+ */
676
+ public function process_cancel_order_meta_box_actions( $order ) {
677
+
678
+ // WooCommerce 3.0 or later.
679
+ if ( method_exists( $order, 'get_meta' ) ) {
680
+ $used_gateway = $order->get_meta( '_used_gateway' );
681
+ $payments = $order->get_meta( '_Mercado_Pago_Payment_IDs' );
682
  } else {
683
+ $used_gateway = get_post_meta( $order->id, '_used_gateway', true );
684
+ $payments = get_post_meta( $order->id, '_Mercado_Pago_Payment_IDs', true );
685
+ }
686
+
687
+ if ( $used_gateway != 'WC_WooMercadoPago_Gateway' ) {
688
+ return;
689
+ }
690
+
691
+ if ( 'yes' == $this->debug ) {
692
+ $this->log->add(
693
+ $this->id,
694
+ '[process_cancel_order_meta_box_actions] - cancelling payments for ' . $payments
695
+ );
696
+ }
697
+
698
+ if ( $this->mp != null && ! empty( $payments ) ) {
699
+ $payment_ids = explode( ', ', $payments );
700
+ foreach ( $payment_ids as $p_id ) {
701
+ $response = $this->mp->cancel_payment( $p_id );
702
+ $message = $response['response']['message'];
703
+ $status = $response['status'];
704
+ if ( 'yes' == $this->debug ) {
705
+ $this->log->add(
706
+ $this->id,
707
+ '[process_cancel_order_meta_box_actions] - cancel payment of id ' . $p_id .
708
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
709
+ );
710
+ }
711
+ }
712
+ } else {
713
+ if ( 'yes' == $this->debug ) {
714
+ $this->log->add(
715
+ $this->id,
716
+ '[process_cancel_order_meta_box_actions] - no payments or credentials invalid'
717
+ );
718
+ }
719
  }
720
+
721
  }
722
+
723
  /*
724
  * ========================================================================
725
+ * CHECKOUT BUSINESS RULES (CLIENT SIDE)
726
  * ========================================================================
727
  */
728
+
729
  public function payment_fields() {
730
  // basic checkout
731
+ if ( $description = $this->get_description() ) {
732
+ echo wpautop(wptexturize( $description ) );
733
+ }
734
+ if ( $this->supports( 'default_credit_card_form' ) ) {
735
+ $this->credit_card_form();
736
+ }
737
+ }
738
+
739
+ public function add_checkout_script() {
740
+
741
+ $client_id = $this->get_option( 'client_id' );
742
+
743
+ if ( ! empty( $client_id ) && ! $this->is_test_user ) {
744
+
745
+ $w = WC_WooMercadoPago_Module::woocommerce_instance();
746
+ $logged_user_email = null;
747
+ $payments = array();
748
+ $gateways = WC()->payment_gateways->get_available_payment_gateways();
749
+ foreach ( $gateways as $g ) {
750
+ $payments[] = $g->id;
751
+ }
752
+ $payments = str_replace( '-', '_', implode( ', ', $payments ) );
753
+
754
+ if ( wp_get_current_user()->ID != 0 ) {
755
+ $logged_user_email = wp_get_current_user()->user_email;
756
+ }
757
+
758
+ ?>
759
+ <script src="https://secure.mlstatic.com/modules/javascript/analytics.js"></script>
760
+ <script type="text/javascript">
761
+ var MA = ModuleAnalytics;
762
+ MA.setToken( '<?php echo $client_id; ?>' );
763
+ MA.setPlatform( 'WooCommerce' );
764
+ MA.setPlatformVersion( '<?php echo $w->version; ?>' );
765
+ MA.setModuleVersion( '<?php echo WC_WooMercadoPago_Module::VERSION; ?>' );
766
+ MA.setPayerEmail( '<?php echo ( $logged_user_email != null ? $logged_user_email : "" ); ?>' );
767
+ MA.setUserLogged( <?php echo ( empty( $logged_user_email ) ? 0 : 1 ); ?> );
768
+ MA.setInstalledModules( '<?php echo $payments; ?>' );
769
+ MA.post();
770
+ </script>
771
+ <?php
772
+
773
+ }
774
+
775
+ }
776
+
777
+ public function update_checkout_status( $order_id ) {
778
+
779
+ $client_id = $this->get_option( 'client_id' );
780
+
781
+ if ( ! empty( $client_id ) && ! $this->is_test_user ) {
782
+
783
+ if ( get_post_meta( $order_id, '_used_gateway', true ) != 'WC_WooMercadoPago_Gateway' ) {
784
+ return;
785
+ }
786
+
787
+ if ( 'yes' == $this->debug ) {
788
+ $this->log->add(
789
+ $this->id,
790
+ '[update_checkout_status] - updating order of ID ' . $order_id
791
+ );
792
+ }
793
+
794
+ echo '<script src="https://secure.mlstatic.com/modules/javascript/analytics.js"></script>
795
+ <script type="text/javascript">
796
+ var MA = ModuleAnalytics;
797
+ MA.setToken( ' . $client_id . ' );
798
+ MA.setPaymentType("basic");
799
+ MA.setCheckoutType("basic");
800
+ MA.put();
801
+ </script>';
802
+
803
+ }
804
+
805
  }
806
+
807
+ /**
808
+ * Summary: Handle the payment and processing the order.
809
+ * Description: First step occurs when the customer selects Mercado Pago and proceed to checkout.
810
+ * This method verify which integration method was selected and makes the build for the checkout
811
+ * URL.
812
+ * @return an array containing the result of the processment and the URL to redirect.
813
+ */
814
  public function process_payment( $order_id ) {
815
+ $order = wc_get_order( $order_id );
816
+
817
+ if ( method_exists( $order, 'update_meta_data' ) ) {
818
+ $order->update_meta_data( '_used_gateway', 'WC_WooMercadoPago_Gateway' );
819
+ $order->save();
820
+ } else {
821
+ update_post_meta( $order_id, '_used_gateway', 'WC_WooMercadoPago_Gateway' );
822
+ }
823
+
824
  if ( 'redirect' == $this->method ) {
825
+ // The checkout is made by redirecting customer to Mercado Pago.
826
+ if ( 'yes' == $this->debug) {
827
+ $this->log->add(
828
+ $this->id,
829
+ '[process_payment] - customer being redirected to Mercado Pago.'
830
+ );
831
  }
832
  return array(
833
  'result' => 'success',
834
+ 'redirect' => $this->create_url( $order )
835
  );
836
+ } elseif ( 'modal' == $this->method || 'iframe' == $this->method ) {
837
+ // The checkout is made by customizing the view, either by iframe or showing a modal.
838
  if ( 'yes' == $this->debug ) {
839
+ $this->log->add(
840
+ $this->id,
841
+ '[process_payment] - preparing to render Mercado Pago checkout view.'
 
 
 
 
 
 
 
 
842
  );
843
  }
844
+ return array(
845
+ 'result' => 'success',
846
+ 'redirect' => $order->get_checkout_payment_url( true )
847
+ );
848
  }
849
  }
850
 
851
+ /**
852
+ * Summary: Show the custom renderization for the checkout.
853
+ * Description: Order page and this generates the form that shows the pay button. This step
854
+ * generates the form to proceed to checkout.
855
+ * @return the html to be rendered.
856
+ */
857
  public function receipt_page( $order ) {
858
+ echo $this->render_order_form( $order );
859
  }
860
+
861
  // --------------------------------------------------
862
+
863
+ public function render_order_form( $order_id ) {
864
+
865
+ $order = wc_get_order( $order_id );
866
+ $url = $this->create_url( $order );
867
+
868
  if ( $url ) {
 
869
  $html =
870
+ '<img width="468" height="60" src="' . $this->country_configs['checkout_banner'] . '">';
871
+ if ( 'modal' == $this->method ) {
872
+ // The checkout is made by displaying a modal to the customer.
873
  if ( 'yes' == $this->debug ) {
874
+ $this->log->add(
875
+ $this->id,
876
+ '[render_order_form] - rendering Mercado Pago lightbox (modal window).'
877
+ );
878
  }
 
 
 
879
  $html .=
880
+ '<p></p><p>' . wordwrap(
881
+ __( 'Thank you for your order. Please, proceed with your payment clicking in the bellow button.', 'woocommerce-mercadopago-module' ),
882
+ 60, '<br>'
883
+ ) . '</p>';
884
+ // === Buttons.
885
  $html .=
886
+ '<a id="submit-payment" href="' . esc_url( $url ) . '" name="MP-Checkout" class="button alt" mp-mode="modal">' .
887
+ __( 'Pay with Mercado Pago', 'woocommerce-mercadopago-module' ) .
888
+ '</a> <a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">' .
889
+ __( 'Cancel order &amp; Clear cart', 'woocommerce-mercadopago-module' ) .
890
+ '</a>';
891
+
892
+ // === Style.
893
+ $html .= '<style type="text/css">';
894
+ $html .= '#MP-Checkout-dialog #MP-Checkout-IFrame { bottom: -28px !important; height: 590px !important; }';
895
+ $html .= '</style>';
896
+ // === Includes the javascript of lightbox.
897
+ $html .= '<script type="text/javascript" src="//secure.mlstatic.com/mptools/render.js"></script>';
898
+ $html .= '<script type="text/javascript">(function() { $MPC.openCheckout({ url: "' . esc_url( $url ) . '", mode: "modal" }); })();</script>';
899
  } else {
900
+ // The checkout is made by rendering Mercado Pago form within a iframe.
901
  if ( 'yes' == $this->debug ) {
902
+ $this->log->add(
903
+ $this->id,
904
+ '[render_order_form] - embedding Mercado Pago iframe.'
905
+ );
906
  }
 
 
 
907
  $html .=
908
+ '<p></p><p>' . wordwrap(
909
+ __( 'Thank you for your order. Proceed with your payment completing the following information.', 'woocommerce-mercadopago-module' ),
910
+ 60, '<br>'
911
+ ) . '</p>';
912
+ $html .=
913
+ '<iframe src="' . esc_url( $url ) . '" name="MP-Checkout" ' .
914
  'width="' . ( is_numeric( (int) $this->iframe_width ) ? $this->iframe_width : 640 ) . '" ' .
915
  'height="' . ( is_numeric( (int) $this->iframe_height ) ? $this->iframe_height : 800 ) . '" ' .
916
  'frameborder="0" scrolling="no" id="checkout_mercadopago"></iframe>';
917
  }
918
  return $html;
919
  } else {
920
+ // Reaching at this point means that the URL could not be build by some reason.
921
+ if ( 'yes' == $this->debug ) {
922
+ $this->log->add(
923
+ $this->id,
924
+ '[render_order_form] - unable to build Mercado Pago checkout URL.'
925
+ );
926
+ }
927
+ $html = '<script type="text/javascript" src="//secure.mlstatic.com/mptools/render.js"></script>';
928
+ $html .=
929
+ '<p>' .
930
+ __( 'An error occurred when proccessing your payment. Please try again or contact us for assistence.', 'woocommerce-mercadopago-module' ) .
931
+ '</p>';
932
  $html .=
933
  '<a class="button" href="' . esc_url( $order->get_checkout_payment_url() ) . '">' .
934
+ __( 'Click to try again', 'woocommerce-mercadopago-module' ) .
935
  '</a>';
936
  return $html;
937
  }
938
  }
 
 
 
 
939
 
940
+ /**
941
+ * Summary: Build Mercado Pago preference.
942
+ * Description: Create Mercado Pago preference and get init_point URL based in the order options
943
+ * from the cart.
944
+ * @return the preference object.
945
+ */
946
+ public function build_payment_preference( $order ) {
947
+
948
+ // A string to register items (workaround to deal with API problem that shows only first item)
949
+ $list_of_items = array();
950
+
951
+ // Selected shipping
952
+ $selected_shipping = $order->get_shipping_method();
953
+
954
+ // Here we build the array that contains ordered items, from customer cart
955
  $items = array();
956
  if ( sizeof( $order->get_items() ) > 0 ) {
957
  foreach ( $order->get_items() as $item ) {
958
  if ( $item['qty'] ) {
959
+ $product = new WC_product( $item['product_id'] );
960
+
961
+ // WooCommerce 3.0 or later.
962
+ if ( method_exists( $product, 'get_description' ) ) {
963
+ $product_title = WC_WooMercadoPago_Module::utf8_ansi(
964
+ $product->get_name()
965
+ );
966
+ $product_content = WC_WooMercadoPago_Module::utf8_ansi(
967
+ $product->get_description()
968
+ );
969
+ } else {
970
+ $product_title = WC_WooMercadoPago_Module::utf8_ansi(
971
+ $product->post->post_title
972
+ );
973
+ $product_content = WC_WooMercadoPago_Module::utf8_ansi(
974
+ $product->post->post_content
975
+ );
976
+ }
977
+
978
+ // Calculate discount for payment method.
979
+ $unit_price = floor( ( (float) $item['line_total'] + (float) $item['line_tax'] ) *
980
+ ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ) * 100 ) / 100;
981
+ if ( is_numeric( $this->gateway_discount ) ) {
982
+ if ( $this->gateway_discount >= 0 && $this->gateway_discount < 100 ) {
983
+ $price_percent = $this->gateway_discount / 100;
984
+ $discount = $unit_price * $price_percent;
985
+ if ( $discount > 0 ) {
986
+ $unit_price -= $discount;
987
+ }
988
+ }
989
+ }
990
+
991
+ // Remove decimals if MCO/MLC
992
+ if ( $this->site_id == 'MCO' || $this->site_id == 'MLC' ) {
993
+ $unit_price = floor( $unit_price );
994
+ }
995
+
996
+ array_push( $list_of_items, $product_title . ' x ' . $item['qty'] );
997
  array_push( $items, array(
998
+ 'id' => $item['product_id'],
999
+ 'title' => ( html_entity_decode( $product_title ) . ' x ' . $item['qty'] ),
1000
+ 'description' => sanitize_file_name( html_entity_decode(
1001
  // This handles description width limit of Mercado Pago.
1002
+ ( strlen( $product_content ) > 230 ?
1003
+ substr( $product_content, 0, 230 ) . '...' :
1004
+ $product_content )
1005
  ) ),
1006
+ 'picture_url' => ( sizeof( $order->get_items() ) > 1 ?
1007
+ plugins_url( 'images/cart.png', plugin_dir_path( __FILE__ ) ) :
1008
+ wp_get_attachment_url( $product->get_image_id() )
1009
+ ),
1010
+ 'category_id' => $this->store_categories_id[$this->category_id],
1011
  'quantity' => 1,
1012
+ 'unit_price' => $unit_price,
1013
+ 'currency_id' => $this->country_configs['currency']
1014
+ ) );
 
1015
  }
1016
  }
1017
+
1018
+ // Check if is NOT Mercado Envios.
1019
+ if ( strpos( $selected_shipping, 'Mercado Envios' ) !== 0 ) {
1020
+ // Shipment cost as an item (workaround to prevent API showing shipment setup again).
1021
+ $ship_cost = ( (float) $order->get_total_shipping() + (float) $order->get_shipping_tax() ) *
1022
+ ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 );
1023
+ // Remove decimals if MCO/MLC
1024
+ if ( $this->site_id == 'MCO' || $this->site_id == 'MLC' ) {
1025
+ $ship_cost = floor( $ship_cost );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1026
  }
1027
+ if ( $ship_cost > 0 ) {
1028
+ array_push(
1029
+ $list_of_items,
1030
+ __( 'Shipping service used by store', 'woocommerce-mercadopago-module' )
1031
+ );
1032
+ array_push( $items, array(
1033
+ 'id' => 2147483647,
1034
+ 'title' => implode( ', ', $list_of_items ),
1035
+ 'description' => implode( ', ', $list_of_items ),
1036
+ 'category_id' => $this->store_categories_id[$this->category_id],
1037
+ 'quantity' => 1,
1038
+ 'unit_price' => floor( $ship_cost * 100 ) / 100,
1039
+ 'currency_id' => $this->country_configs['currency']
1040
+ ) );
1041
+ }
1042
+ }
1043
+
1044
+ // String of item names (workaround to deal with API problem that shows only first item).
1045
+ $items[0]['title'] = implode( ', ', $list_of_items );
1046
+ }
1047
+
1048
+ // Find excluded methods. If 'n/d' is in array, we should disconsider the remaining values.
1049
+ $excluded_payment_methods = array();
1050
+ if ( is_array( $this->ex_payments ) || is_object( $this->ex_payments ) ) {
1051
+ foreach ( $this->ex_payments as $excluded ) {
1052
+ // if 'n/d' is selected, we just not add any items to the array.
1053
+ if ( $excluded == 0 )
1054
+ break;
1055
+ array_push( $excluded_payment_methods, array(
1056
+ 'id' => $this->payment_methods[$excluded]
1057
+ ) );
1058
+ }
1059
+ }
1060
+ $payment_methods = array(
1061
+ 'installments' => ( is_numeric( (int) $this->installments) ? (int) $this->installments : 24 ),
1062
+ 'default_installments' => 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1063
  );
1064
+ // Set excluded payment methods.
1065
+ if ( count( $excluded_payment_methods ) > 0 ) {
1066
+ $payment_methods['excluded_payment_methods'] = $excluded_payment_methods;
1067
  }
1068
+
1069
+ // WooCommerce 3.0 or later.
1070
+ if ( method_exists( $order, 'get_id' ) ) {
1071
+ // Create Mercado Pago preference.
1072
+ $preferences = array(
1073
+ 'items' => $items,
1074
+ // Payer should be filled with billing info as orders can be made with non-logged users.
1075
+ 'payer' => array(
1076
+ 'name' => html_entity_decode( $order->get_billing_first_name() ),
1077
+ 'surname' => html_entity_decode( $order->get_billing_last_name() ),
1078
+ 'email' => $order->get_billing_email(),
1079
+ 'phone' => array(
1080
+ 'number' => $order->get_billing_phone()
1081
+ ),
1082
+ 'address' => array(
1083
+ 'street_name' => html_entity_decode(
1084
+ $order->get_billing_address_1() . ' / ' .
1085
+ $order->get_billing_city() . ' ' .
1086
+ $order->get_billing_state() . ' ' .
1087
+ $order->get_billing_country()
1088
+ ),
1089
+ 'zip_code' => $order->get_billing_postcode()
1090
+ )
1091
+ ),
1092
+ 'back_urls' => array(
1093
+ 'success' => ( empty( $this->success_url ) ?
1094
+ WC_WooMercadoPago_Module::workaround_ampersand_bug(
1095
+ esc_url( $this->get_return_url( $order ) )
1096
+ ) : $this->success_url
1097
+ ),
1098
+ 'failure' => ( empty( $this->failure_url ) ?
1099
+ WC_WooMercadoPago_Module::workaround_ampersand_bug(
1100
+ str_replace( '&amp;', '&', $order->get_cancel_order_url() )
1101
+ ) : $this->failure_url
1102
+ ),
1103
+ 'pending' => ( empty( $this->pending_url ) ?
1104
+ WC_WooMercadoPago_Module::workaround_ampersand_bug(
1105
+ esc_url( $this->get_return_url( $order) )
1106
+ ) : $this->pending_url
1107
+ )
1108
+ ),
1109
+ //'marketplace' =>
1110
+ //'marketplace_fee' =>
1111
+ 'shipments' => array(
1112
+ //'cost' =>
1113
+ //'mode' =>
1114
+ 'receiver_address' => array(
1115
+ 'zip_code' => $order->get_shipping_postcode(),
1116
+ //'street_number' =>
1117
+ 'street_name' => html_entity_decode(
1118
+ $order->get_shipping_address_1() . ' ' .
1119
+ $order->get_shipping_city() . ' ' .
1120
+ $order->get_shipping_state() . ' ' .
1121
+ $order->get_shipping_country()
1122
+ ),
1123
+ //'floor' =>
1124
+ 'apartment' => $order->get_shipping_address_2()
1125
+ )
1126
+ ),
1127
+ 'payment_methods' => $payment_methods,
1128
+ //'notification_url' =>
1129
+ 'external_reference' => $this->invoice_prefix . $order->get_id()
1130
+ //'additional_info' =>
1131
+ //'expires' =>
1132
+ //'expiration_date_from' =>
1133
+ //'expiration_date_to' =>
1134
+ );
1135
+ } else {
1136
+ // Create Mercado Pago preference.
1137
+ $preferences = array(
1138
+ 'items' => $items,
1139
+ // Payer should be filled with billing info as orders can be made with non-logged users.
1140
+ 'payer' => array(
1141
+ 'name' => html_entity_decode( $order->billing_first_name ),
1142
+ 'surname' => html_entity_decode( $order->billing_last_name ),
1143
+ 'email' => $order->billing_email,
1144
+ 'phone' => array(
1145
+ 'number' => $order->billing_phone
1146
+ ),
1147
+ 'address' => array(
1148
+ 'street_name' => html_entity_decode(
1149
+ $order->billing_address_1 . ' / ' .
1150
+ $order->billing_city . ' ' .
1151
+ $order->billing_state . ' ' .
1152
+ $order->billing_country
1153
+ ),
1154
+ 'zip_code' => $order->billing_postcode
1155
+ )
1156
+ ),
1157
+ 'back_urls' => array(
1158
+ 'success' => ( empty( $this->success_url ) ?
1159
+ WC_WooMercadoPago_Module::workaround_ampersand_bug(
1160
+ esc_url( $this->get_return_url( $order) )
1161
+ ) : $this->success_url
1162
+ ),
1163
+ 'failure' => ( empty( $this->failure_url ) ?
1164
+ WC_WooMercadoPago_Module::workaround_ampersand_bug(
1165
+ str_replace( '&amp;', '&', $order->get_cancel_order_url() )
1166
+ ) : $this->failure_url
1167
+ ),
1168
+ 'pending' => ( empty( $this->pending_url ) ?
1169
+ WC_WooMercadoPago_Module::workaround_ampersand_bug(
1170
+ esc_url( $this->get_return_url( $order) )
1171
+ ) : $this->pending_url
1172
+ )
1173
+ ),
1174
+ //'marketplace' =>
1175
+ //'marketplace_fee' =>
1176
+ 'shipments' => array(
1177
+ //'cost' =>
1178
+ //'mode' =>
1179
+ 'receiver_address' => array(
1180
+ 'zip_code' => $order->shipping_postcode,
1181
+ //'street_number' =>
1182
+ 'street_name' => html_entity_decode(
1183
+ $order->shipping_address_1 . ' ' .
1184
+ $order->shipping_city . ' ' .
1185
+ $order->shipping_state . ' ' .
1186
+ $order->shipping_country
1187
+ ),
1188
+ //'floor' =>
1189
+ 'apartment' => $order->shipping_address_2
1190
+ )
1191
+ ),
1192
+ 'payment_methods' => $payment_methods,
1193
+ //'notification_url' =>
1194
+ 'external_reference' => $this->invoice_prefix . $order->id
1195
+ //'additional_info' =>
1196
+ //'expires' =>
1197
+ //'expiration_date_from' =>
1198
+ //'expiration_date_to' =>
1199
+ );
1200
+ }
1201
+
1202
+ // Set Mercado Envios
1203
+ if ( strpos($selected_shipping, 'Mercado Envios' ) === 0 ) {
1204
+ $preferences['shipments']['mode'] = 'me2';
1205
+
1206
+ foreach ( $order->get_shipping_methods() as $shipping ) {
1207
+
1208
+ $preferences['shipments']['dimensions'] = $shipping['dimensions'];
1209
+ $preferences['shipments']['default_shipping_method'] = (int) $shipping['shipping_method_id'];
1210
+ $preferences['shipments']['free_methods'] = array();
1211
+
1212
+ // Get shipping method id
1213
+ $prepare_method_id = explode( ':', $shipping['method_id'] );
1214
+
1215
+ // Get instance_id
1216
+ $shipping_id = $prepare_method_id[count( $prepare_method_id ) - 1];
1217
+
1218
+ // TODO: REFACTOR
1219
+ // Get zone by instance_id
1220
+ $shipping_zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $shipping_id );
1221
+
1222
+ // Get all shipping and filter by free_shipping (Mercado Envios)
1223
+ foreach ($shipping_zone->get_shipping_methods() as $key => $shipping_object) {
1224
+
1225
+ // Check is a free method
1226
+ if ($shipping_object->get_option( 'free_shipping' ) == 'yes' ) {
1227
+ // Get shipping method id (Mercado Envios)
1228
+ $shipping_method_id = $shipping_object->get_shipping_method_id( $this->site_id );
1229
+ $preferences['shipments']['free_methods'][] = array( 'id' => (int) $shipping_method_id );
1230
+ }
1231
+ }
1232
+ }
1233
+ }
1234
+
1235
+ // Do not set IPN url if it is a localhost.
1236
+ if ( ! strrpos( $this->domain, 'localhost' ) ) {
1237
+ $preferences['notification_url'] = WC_WooMercadoPago_Module::workaround_ampersand_bug(
1238
+ WC()->api_request_url( 'WC_WooMercadoPago_Gateway' )
1239
+ );
1240
+ }
1241
+
1242
+ // Set sponsor ID.
1243
+ if ( ! $this->is_test_user ) {
1244
+ $preferences['sponsor_id'] = $this->country_configs['sponsor_id'];
1245
+ }
1246
+
1247
  // Auto return options.
1248
  if ( 'yes' == $this->auto_return ) {
1249
+ $preferences['auto_return'] = 'approved';
1250
  }
1251
+
1252
  if ( 'yes' == $this->debug ) {
1253
  $this->log->add(
1254
+ $this->id,
1255
+ '[build_payment_preference] - preference created with following structure: ' .
1256
+ json_encode( $preferences, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE ) );
1257
  }
1258
+
1259
+ $preferences = apply_filters(
1260
+ 'woocommerce_mercadopago_module_preferences', $preferences, $order
1261
+ );
1262
+
1263
  return $preferences;
1264
  }
1265
+
1266
  // --------------------------------------------------
1267
+
1268
+ protected function create_url( $order ) {
1269
+
 
1270
  // Checks for sandbox mode.
1271
  if ( 'yes' == $this->sandbox ) {
1272
+ $this->mp->sandbox_mode( true);
1273
  if ( 'yes' == $this->debug ) {
1274
+ $this->log->add(
1275
+ $this->id,
1276
+ '[create_url] - sandbox mode is enabled'
1277
+ );
1278
  }
1279
  } else {
1280
+ $this->mp->sandbox_mode( false );
1281
  }
1282
+
1283
+ // Creates the order parameters by checking the cart configuration.
1284
+ $preferences = $this->build_payment_preference( $order );
1285
  // Create order preferences with Mercado Pago API request.
1286
  try {
1287
+ $checkout_info = $this->mp->create_preference( json_encode( $preferences ) );
1288
+ if ( $checkout_info['status'] < 200 || $checkout_info['status'] >= 300 ) {
1289
+ // Mercado Pago trowed an error.
1290
+ if ( 'yes' == $this->debug ) {
1291
+ $this->log->add(
1292
+ $this->id,
1293
+ '[create_url] - mercado pago gave error, payment creation failed with error: ' .
1294
+ $checkout_info['response']['message'] );
1295
+ }
1296
+ return false;
1297
+ } elseif ( is_wp_error( $checkout_info ) ) {
1298
+ // WordPress throwed an error.
1299
  if ( 'yes' == $this->debug ) {
1300
+ $this->log->add(
1301
+ $this->id,
1302
+ '[create_url] - wordpress gave error, payment creation failed with error: ' .
1303
+ $checkout_info['response']['message'] );
1304
  }
1305
  return false;
1306
  } else {
1307
+ // Obtain the URL.
1308
  if ( 'yes' == $this->debug ) {
1309
+ $this->log->add(
1310
+ $this->id,
1311
+ '[create_url] - payment link generated with success from mercado pago, with structure as follow: ' .
1312
+ json_encode( $checkout_info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE ) );
1313
  }
1314
+ if ( 'yes' == $this->sandbox) {
1315
+ return $checkout_info['response']['sandbox_init_point'];
1316
  } else {
1317
+ return $checkout_info['response']['init_point'];
1318
  }
1319
  }
1320
  } catch ( MercadoPagoException $e ) {
1321
+ // Something went wrong with the payment creation.
1322
  if ( 'yes' == $this->debug ) {
1323
  $this->log->add(
1324
+ $this->id,
1325
+ '[create_url] - payment creation failed with exception: ' .
1326
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
1327
+ );
1328
  }
1329
  return false;
1330
  }
1331
+
1332
  }
1333
+
1334
  /*
1335
  * ========================================================================
1336
+ * AUXILIARY AND FEEDBACK METHODS (SERVER SIDE)
1337
  * ========================================================================
1338
  */
1339
 
1340
+ /**
1341
+ * Summary: Check if we have valid credentials.
1342
+ * Description: Check if we have valid credentials.
1343
+ * @return boolean true/false depending on the validation result.
1344
+ */
1345
+ public function validate_credentials() {
1346
 
1347
+ if ( empty( $this->client_id ) || empty( $this->client_secret ) ) {
1348
+ return false;
1349
+ }
1350
+
1351
+ if ( ! is_numeric( $this->client_id ) ) {
1352
+ return false;
1353
+ }
1354
+
1355
+ try {
1356
+
1357
+ $this->mp = new MP(
1358
+ WC_WooMercadoPago_Module::get_module_version(),
1359
+ $this->client_id,
1360
+ $this->client_secret
1361
+ );
1362
+ $access_token = $this->mp->get_access_token();
1363
+ $get_request = $this->mp->get( '/users/me?access_token=' . $access_token );
1364
+
1365
+ if ( isset( $get_request['response']['site_id'] ) ) {
1366
+
1367
+ $this->is_test_user = in_array( 'test_user', $get_request['response']['tags'] );
1368
+ $this->site_id = $get_request['response']['site_id'];
1369
+ $this->collector_id = $get_request['response']['id'];
1370
+ $this->country_configs = WC_WooMercadoPago_Module::get_country_config( $this->site_id );
1371
+ $this->payment_split_mode = $this->mp->check_two_cards();
1372
+
1373
+ $payments = $this->mp->get( '/v1/payment_methods/?access_token=' . $access_token );
1374
+ array_push( $this->payment_methods, 'n/d' );
1375
+ foreach ( $payments['response'] as $payment ) {
1376
+ array_push( $this->payment_methods, str_replace( '_', ' ', $payment['id'] ) );
1377
+ }
1378
+
1379
+ // Check for auto converstion of currency (only if it is enabled).
1380
+ $this->currency_ratio = -1;
1381
+ if ( $this->currency_conversion == 'yes' ) {
1382
+ $this->currency_ratio = WC_WooMercadoPago_Module::get_conversion_rate(
1383
+ $this->country_configs['currency']
1384
+ );
1385
+ }
1386
+
1387
+ return true;
1388
+
1389
+ } else {
1390
+ $this->mp = null;
1391
  return false;
1392
  }
1393
+
1394
+ } catch ( MercadoPagoException $e ) {
1395
+ if ( 'yes' == $this->debug) {
1396
+ $this->log->add(
1397
+ $this->id,
1398
+ '[validate_credentials] - while validating credentials, got exception: ' .
1399
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
1400
+ );
1401
+ }
1402
+ $this->mp = null;
1403
+ return false;
1404
  }
1405
+
1406
  return false;
1407
+
1408
  }
1409
+
1410
+ // Build the string representing the path to the log file.
1411
+ protected function build_log_path_string() {
1412
  return '<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' .
1413
  esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' .
1414
  __( 'WooCommerce &gt; System Status &gt; Logs', 'woocommerce-mercadopago-module' ) . '</a>';
1415
  }
1416
 
1417
  // Return boolean indicating if currency is supported.
1418
+ protected function is_supported_currency() {
1419
+ return get_woocommerce_currency() == $this->country_configs['currency'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1420
  }
1421
 
1422
  // Called automatically by WooCommerce, verify if Module is available to use.
1423
  public function is_available() {
1424
+ if ( ! did_action( 'wp_loaded' ) ) {
1425
+ return false;
1426
+ }
1427
+ global $woocommerce;
1428
+ $w_cart = $woocommerce->cart;
1429
+ // Check for recurrent product checkout.
1430
+ if ( isset( $w_cart ) ) {
1431
+ if ( WC_WooMercadoPago_Module::is_subscription( $w_cart->get_cart() ) ) {
1432
+ return false;
1433
+ }
1434
+ }
1435
+ // Check if this gateway is enabled and well configured.
1436
+ $available = ( 'yes' == $this->settings['enabled'] ) &&
1437
+ ! empty( $this->client_id ) &&
1438
+ ! empty( $this->client_secret );
1439
  return $available;
1440
  }
1441
+
1442
  // Fix css for Mercado Pago in specific cases.
1443
  public function css() {
1444
  if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
1446
  } else {
1447
  $page_id = woocommerce_get_page_id( 'checkout' );
1448
  }
1449
+ if ( is_page( $page_id ) ) {
1450
+ echo '<style type="text/css">#MP-Checkout-dialog { z-index: 9999 !important; }</style>' .
1451
+ PHP_EOL;
1452
  }
1453
  }
1454
+
1455
  // Get the URL to admin page.
1456
  protected function admin_url() {
1457
  if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
1465
  }
1466
 
1467
  // Notify that Client_id and/or Client_secret are not valid.
1468
+ public function client_id_or_secret_missing_message() {
1469
+ echo '<div class="error"><p><strong>' .
1470
  __( 'Basic Checkout is Inactive', 'woocommerce-mercadopago-module' ) .
1471
  '</strong>: ' .
1472
+ __( 'Your Mercado Pago credentials Client_id/Client_secret appears to be misconfigured.', 'woocommerce-mercadopago-module' ) .
 
 
1473
  '</p></div>';
1474
  }
1475
+
1476
+ // Display the discount in payment method title.
1477
+ public function get_payment_method_title_basic( $title, $id ) {
1478
+
1479
+ if ( ! is_checkout() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1480
+ return $title;
 
 
 
 
1481
  }
1482
+
1483
+ if ( $title != $this->title || $this->gateway_discount == 0 ) {
1484
+ return $title;
1485
+ }
1486
+
1487
+ if ( WC()->session->chosen_payment_method == 'woocommerce-mercadopago-subscription-module' ) {
1488
+ return $title;
1489
+ }
1490
+
1491
+ $total = (float) WC()->cart->subtotal;
1492
+ if ( is_numeric( $this->gateway_discount ) ) {
1493
+ if ( $this->gateway_discount >= 0 && $this->gateway_discount < 100 ) {
1494
+ $price_percent = $this->gateway_discount / 100;
1495
+ if ( $price_percent > 0 ) {
1496
+ $title .= ' (' . __( 'Discount Of ', 'woocommerce-mercadopago-module' ) .
1497
+ strip_tags( wc_price( $total * $price_percent ) ) . ' )';
1498
+ }
1499
+ }
1500
+ }
1501
+
1502
+ return $title;
1503
  }
1504
+
1505
  /*
1506
  * ========================================================================
1507
+ * IPN MECHANICS (SERVER SIDE)
1508
  * ========================================================================
1509
  */
1510
+
1511
+ /**
1512
+ * Summary: This call checks any incoming notifications from Mercado Pago server.
1513
+ * Description: This call checks any incoming notifications from Mercado Pago server.
1514
+ */
1515
  public function check_ipn_response() {
1516
+
1517
  @ob_clean();
1518
+
1519
  if ( 'yes' == $this->debug ) {
1520
+ $this->log->add(
1521
+ $this->id,
1522
+ '[check_ipn_response] - received _get content: ' .
1523
+ json_encode( $_GET, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1524
+ );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1525
  }
1526
+
1527
+ // Setup sandbox mode.
1528
+ $this->mp->sandbox_mode( 'yes' == $this->sandbox );
1529
+
1530
+ // Over here, $_GET should come with this JSON structure:
1531
+ // {
1532
+ // "topic": <string>,
1533
+ // "id": <string>
1534
+ // }
1535
+ // If not, the IPN is corrupted in some way.
1536
+ $data = $_GET;
1537
+ if ( isset( $data['id'] ) && isset( $data['topic'] ) ) {
1538
+
1539
+ // We have received a normal IPN call for this gateway, start process by getting the access token...
1540
+ $access_token = array( 'access_token' => $this->mp->get_access_token() );
1541
+
1542
+ // Now, we should handle the topic type that has come...
1543
+ if ( $data['topic'] == 'merchant_order' ) {
1544
+
1545
+ // Get the merchant_order reported by the IPN.
1546
+ $merchant_order_info = $this->mp->get( '/merchant_orders/' . $data['id'], $access_token, false );
1547
+ if ( ! is_wp_error( $merchant_order_info ) && ( $merchant_order_info['status'] == 200 || $merchant_order_info['status'] == 201 ) ) {
1548
+ $payments = $merchant_order_info['response']['payments'];
1549
+ // If the payment's transaction amount is equal (or bigger) than the merchant order's amount we can release the items.
1550
+ if ( sizeof( $payments ) >= 1 ) {
1551
+ // We have payments...
1552
+ $merchant_order_info['response']['ipn_type'] = 'merchant_order';
1553
+ do_action( 'valid_mercadopago_ipn_request', $merchant_order_info['response'] );
1554
+ } else {
1555
+ // We have no payments?
1556
  if ( 'yes' == $this->debug ) {
1557
+ $this->log->add(
1558
+ $this->id,
1559
+ '[check_ipn_response] - order received but has no payment'
1560
+ );
1561
  }
 
1562
  }
1563
+ header( 'HTTP/1.1 200 OK' );
1564
  } else {
1565
  if ( 'yes' == $this->debug ) {
1566
+ $this->log->add(
1567
+ $this->id,
1568
+ '[check_ipn_response] - got status not equal 200: ' .
1569
+ json_encode( $preapproval_info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1570
+ );
1571
  }
 
1572
  }
1573
+
1574
+ } elseif ( $data['topic'] == 'payment' ) {
1575
+
1576
+ $payment_info = $this->mp->get( '/v1/payments/' . $data['id'], $access_token, false );
1577
+ if ( ! is_wp_error( $payment_info ) && ( $payment_info['status'] == 200 || $payment_info['status'] == 201 ) ) {
1578
+ $payments = $payment_info['response']['payments'];
1579
+ // If the payment's transaction amount is equal (or bigger) than the merchant order's amount we can release the items.
1580
+ if ( sizeof( $payments ) >= 1 ) {
1581
+ // We have payments...
1582
+ $payment_info['response']['ipn_type'] = 'payment';
1583
+ do_action( 'valid_mercadopago_ipn_request', $payment_info['response'] );
1584
+ } else {
1585
+ // We have no payments?
1586
+ if ( 'yes' == $this->debug ) {
1587
+ $this->log->add(
1588
+ $this->id,
1589
+ '[check_ipn_response] - order received but has no payment'
1590
+ );
1591
+ }
1592
+ }
1593
+ header( 'HTTP/1.1 200 OK' );
1594
+ } else {
1595
+ if ( 'yes' == $this->debug) {
1596
+ $this->log->add(
1597
+ $this->id,
1598
+ '[check_ipn_request_is_valid] - error when processing received data: ' .
1599
+ json_encode( $payment_info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1600
+ );
1601
+ }
1602
+ }
1603
+
1604
+ } else {
1605
+
1606
+ // We have received an unhandled topic...
1607
+ $this->log->add(
1608
+ $this->id,
1609
+ '[check_ipn_response] - request failure, received an unhandled topic'
1610
+ );
1611
+
1612
  }
1613
+
1614
+ } elseif ( isset( $data['data_id'] ) && isset( $data['type'] ) ) {
1615
+
1616
+ // We have received a bad, however valid) IPN call for this gateway (data is set for API V1).
1617
+ // At least, we should respond 200 to notify server that we already received it.
1618
+ header( 'HTTP/1.1 200 OK' );
1619
+
1620
+ } else {
1621
+
1622
+ // Reaching here means that we received an IPN call but there are no data!
1623
+ // Just kills the processment. No IDs? No process!
1624
  if ( 'yes' == $this->debug ) {
1625
+ $this->log->add(
1626
+ $this->id,
1627
+ '[check_ipn_response] - request failure, received ipn call with no data'
1628
+ );
1629
  }
1630
+ wp_die( __( 'Mercado Pago Request Failure', 'woocommerce-mercadopago-module' ) );
1631
+
1632
  }
1633
+
1634
  }
1635
+
1636
+ /**
1637
+ * Summary: Properly handles each case of notification, based in payment status.
1638
+ * Description: Properly handles each case of notification, based in payment status.
1639
+ */
1640
  public function successful_request( $data ) {
1641
+
1642
  if ( 'yes' == $this->debug ) {
1643
+ $this->log->add(
1644
+ $this->id,
1645
+ '[successful_request] - starting to process ipn update...'
1646
+ );
1647
  }
1648
+
1649
+ // Get the order and check its presence.
1650
+ $order_key = $data['external_reference'];
1651
+ if ( empty( $order_key ) ) {
1652
+ return;
1653
+ }
1654
+ $id = (int) str_replace( $this->invoice_prefix, '', $order_key );
1655
+ $order = wc_get_order( $id );
1656
+
1657
+ // Check if order exists.
1658
+ if ( ! $order ) {
1659
+ return;
1660
+ }
1661
+
1662
+ // WooCommerce 3.0 or later.
1663
+ if ( method_exists( $order, 'get_id' ) ) {
1664
+ $order_id = $order->get_id();
1665
+ } else {
1666
+ $order_id = $order->id;
1667
+ }
1668
+
1669
+ // Check if we have the correct order.
1670
+ if ( $order_id !== $id ) {
1671
+ return;
1672
+ }
1673
+
1674
+ if ( 'yes' == $this->debug ) {
1675
+ $this->log->add(
1676
+ $this->id,
1677
+ '[successful_request] - updating metadata and status with data: ' .
1678
+ json_encode( $data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1679
+ );
1680
+ }
1681
+
1682
+ // Here, we process the status... this is the business rules!
1683
+ // Reference: https://www.mercadopago.com.br/developers/en/api-docs/basic-checkout/ipn/payment-status/
1684
+ $status = 'pending';
1685
+ $payments = $data['payments'];
1686
+
1687
+ if ( sizeof( $payments ) == 1 ) {
1688
+ // If we have only one payment, just set status as its status
1689
+ $status = $payments[0]['status'];
1690
+ } elseif ( sizeof( $payments ) > 1 ) {
1691
+ // However, if we have multiple payments, the overall payment have some rules...
1692
+ $total_paid = 0.00;
1693
+ $total_refund = 0.00;
1694
+ $total = $data['shipping_cost'] + $data['total_amount'];
1695
+ // Grab some information...
1696
+ foreach ( $data['payments'] as $payment ) {
1697
+ if ( $payment['status'] === 'approved' ) {
1698
+ // Get the total paid amount, considering only approved incomings.
1699
+ $total_paid += (float) $payment['total_paid_amount'];
1700
+ } elseif ( $payment['status'] === 'refunded' ) {
1701
+ // Get the total refounded amount.
1702
+ $total_refund += (float) $payment['amount_refunded'];
1703
+ }
1704
+ }
1705
+ if ( $total_paid >= $total ) {
1706
+ $status = 'approved';
1707
+ } elseif ( $total_refund >= $total ) {
1708
+ $status = 'refunded';
1709
+ } else {
1710
+ $status = 'pending';
1711
+ }
1712
+ }
1713
+
1714
+ // WooCommerce 3.0 or later.
1715
+ if ( method_exists( $order, 'update_meta_data' ) ) {
1716
+ // Updates the type of gateway.
1717
+ $order->update_meta_data( '_used_gateway', 'WC_WooMercadoPago_Gateway' );
1718
+
1719
+ if ( ! empty( $data['payer']['email'] ) ) {
1720
+ $order->update_meta_data( __( 'Payer email', 'woocommerce-mercadopago-module' ), $data['payer']['email'] );
1721
+ }
1722
+ if ( ! empty( $data['payment_type'] ) ) {
1723
+ $order->update_meta_data( __( 'Payment type', 'woocommerce-mercadopago-module' ), $data['payment_type'] );
1724
+ }
1725
+ if ( ! empty( $data['payments'] ) ) {
1726
+ $payment_ids = array();
1727
+ foreach ( $data['payments'] as $payment ) {
1728
+ $payment_ids[] = $payment['id'];
1729
+ $order->update_meta_data( 'Mercado Pago - Payment ' . $payment['id'],
1730
+ '[Date ' . date( 'Y-m-d H:i:s', strtotime( $payment['date_created'] ) ) .
1731
+ ']/[Amount ' . $payment['transaction_amount'] .
1732
+ ']/[Paid ' . $payment['total_paid_amount'] .
1733
+ ']/[Refund ' . $payment['amount_refunded'] . ']'
1734
+ );
1735
+ }
1736
+ if ( sizeof( $payment_ids ) > 0 ) {
1737
+ $order->update_meta_data( '_Mercado_Pago_Payment_IDs', implode( ', ', $payment_ids ) );
1738
  }
1739
+ }
1740
+
1741
+ $order->save();
1742
+ } else {
1743
+ // Updates the type of gateway.
1744
+ update_post_meta( $order->id, '_used_gateway', 'WC_WooMercadoPago_Gateway' );
1745
+
1746
+ if ( ! empty( $data['payer']['email'] ) ) {
1747
+ update_post_meta(
1748
+ $order_id,
1749
+ __( 'Payer email', 'woocommerce-mercadopago-module' ),
1750
+ $data['payer']['email']
1751
+ );
1752
+ }
1753
+ if ( ! empty( $data['payment_type'] ) ) {
1754
+ update_post_meta(
1755
+ $order_id,
1756
+ __( 'Payment type', 'woocommerce-mercadopago-module' ),
1757
+ $data['payment_type']
1758
+ );
1759
+ }
1760
+ if ( ! empty( $data['payments'] ) ) {
1761
+ $payment_ids = array();
1762
+ foreach ( $data['payments'] as $payment ) {
1763
+ $payment_ids[] = $payment['id'];
1764
  update_post_meta(
1765
  $order_id,
1766
+ 'Mercado Pago - Payment ' . $payment['id'],
1767
+ '[Date ' . date( 'Y-m-d H:i:s', strtotime( $payment['date_created'] ) ) .
1768
+ ']/[Amount ' . $payment['transaction_amount'] .
1769
+ ']/[Paid ' . $payment['total_paid_amount'] .
1770
+ ']/[Refund ' . $payment['amount_refunded'] . ']'
1771
  );
1772
  }
1773
+ if ( sizeof( $payment_ids ) > 0 ) {
1774
  update_post_meta(
1775
  $order_id,
1776
+ '_Mercado_Pago_Payment_IDs',
1777
+ implode( ', ', $payment_ids )
1778
  );
1779
  }
1780
+ }
1781
+ }
1782
+
1783
+ // Switch the status and update in WooCommerce.
1784
+ switch ( $status ) {
1785
+ case 'approved':
1786
+ $order->add_order_note(
1787
+ 'Mercado Pago: ' .
1788
+ __( 'Payment approved.', 'woocommerce-mercadopago-module' )
1789
+ );
1790
+ $order->payment_complete();
1791
+ break;
1792
+ case 'pending':
1793
+ $order->add_order_note(
1794
+ 'Mercado Pago: ' .
1795
+ __( 'Customer haven\'t paid yet.', 'woocommerce-mercadopago-module' )
1796
+ );
1797
+ break;
1798
+ case 'in_process':
1799
+ $order->update_status(
1800
+ 'on-hold',
1801
+ 'Mercado Pago: ' .
1802
+ __( 'Payment under review.', 'woocommerce-mercadopago-module' )
1803
+ );
1804
+ break;
1805
+ case 'rejected':
1806
+ $order->update_status(
1807
+ 'failed',
1808
+ 'Mercado Pago: ' .
1809
+ __( 'The payment was refused. The customer can try again.', 'woocommerce-mercadopago-module' )
1810
+ );
1811
+ break;
1812
+ case 'refunded':
1813
+ $order->update_status(
1814
+ 'refunded',
1815
+ 'Mercado Pago: ' .
1816
+ __( 'The payment was refunded to the customer.', 'woocommerce-mercadopago-module' )
1817
+ );
1818
+ break;
1819
+ case 'cancelled':
1820
+ $order->update_status(
1821
+ 'cancelled',
1822
+ 'Mercado Pago: ' .
1823
+ __( 'The payment was cancelled.', 'woocommerce-mercadopago-module' )
1824
+ );
1825
+ break;
1826
+ case 'in_mediation':
1827
+ $order->add_order_note(
1828
+ 'Mercado Pago: ' .
1829
+ __( 'The payment is under mediation or it was charged-back.', 'woocommerce-mercadopago-module' )
1830
+ );
1831
+ break;
1832
+ case 'charged-back':
1833
+ $order->add_order_note(
1834
+ 'Mercado Pago: ' .
1835
+ __( 'The payment is under mediation or it was charged-back.', 'woocommerce-mercadopago-module' )
1836
+ );
1837
+ break;
1838
+ default:
1839
+ break;
1840
+ }
1841
+
1842
+ $this->check_mercado_envios( $data );
1843
+
1844
+ }
1845
+
1846
+ /**
1847
+ * Summary: Check IPN data and updates Mercado Envios tag and informaitons.
1848
+ * Description: Check IPN data and updates Mercado Envios tag and informaitons.
1849
+ */
1850
+ public function check_mercado_envios( $merchant_order ) {
1851
+
1852
+ $order_key = $merchant_order['external_reference'];
1853
+
1854
+ if ( ! empty( $order_key ) ) {
1855
+ $order_id = (int) str_replace( $this->invoice_prefix, '', $order_key );
1856
+ $order = wc_get_order( $order_id );
1857
+
1858
+ if ( count( $merchant_order['shipments'] ) > 0 ) {
1859
+ foreach ( $merchant_order['shipments'] as $shipment ) {
1860
+
1861
+ $shipment_id = $shipment['id'];
1862
+
1863
+ // Get shipping data on merchant_order.
1864
+ $shipment_name = $shipment['shipping_option']['name'];
1865
+ $shipment_cost = $shipment['shipping_option']['cost'];
1866
+ $shipping_method_id = $shipment['shipping_option']['shipping_method_id'];
1867
+
1868
+ // Get data shipping selected on checkout.
1869
+ $shipping_meta = $order->get_items( 'shipping' );
1870
+ $order_item_shipping_id = null;
1871
+ $method_id = null;
1872
+ foreach ( $shipping_meta as $key => $shipping ) {
1873
+ $order_item_shipping_id = $key;
1874
+ $method_id = $shipping['method_id'];
1875
  }
1876
+
1877
+ $free_shipping_text = '';
1878
+ $free_shipping_status = 'no';
1879
+ if ( $shipment_cost == 0 ) {
1880
+ $free_shipping_status = 'yes';
1881
+ $free_shipping_text = ' (' . __( 'Free Shipping', 'woocommerce' ) . ')';
1882
  }
1883
+
1884
+ // WooCommerce 3.0 or later.
1885
+ if ( method_exists( $order, 'get_id' ) ) {
1886
+ $shipping_item = $order->get_item( $order_item_shipping_id );
1887
+ $shipping_item->set_order_id( $order->get_id() );
1888
+
1889
+ // Update shipping cost and method title.
1890
+ $shipping_item->set_props( array(
1891
+ 'method_title' => 'Mercado Envios - ' . $shipment_name . $free_shipping_text,
1892
+ 'method_id' => $method_id,
1893
+ 'total' => wc_format_decimal( $shipment_cost ),
1894
+ ) );
1895
+ $shipping_item->save();
1896
+ $this->calculate_shipping();
1897
+ } else {
1898
+ // Update shipping cost and method title.
1899
+ $r = $order->update_shipping( $order_item_shipping_id, array(
1900
+ 'method_title' => 'Mercado Envios - ' . $shipment_name . $free_shipping_text,
1901
+ 'method_id' => $method_id,
1902
+ 'cost' => wc_format_decimal( $shipment_cost )
1903
+ ) );
1904
  }
1905
+
1906
+ // WTF?
1907
+ // https://docs.woocommerce.com/wc-apidocs/source-class-WC_Abstract_Order.html#541
1908
+ // FORCE UPDATE SHIPPING
1909
+ $order->set_total( wc_format_decimal( $shipment_cost ) , 'shipping' );
1910
+
1911
+ // Update total order.
1912
+ $order->set_total(
1913
+ wc_format_decimal( $order->get_subtotal() )
1914
+ + wc_format_decimal( $order->get_total_shipping() )
1915
+ + wc_format_decimal( $order->get_total_tax() )
1916
+ - wc_format_decimal( $order->get_total_discount() )
1917
+ );
1918
+
1919
+ // Update additional info.
1920
+ wc_update_order_item_meta( $order_item_shipping_id, 'shipping_method_id', $shipping_method_id );
1921
+ wc_update_order_item_meta( $order_item_shipping_id, 'free_shipping', $free_shipping_status );
1922
+
1923
+ $access_token = $this->mp->get_access_token();
1924
+ $request = array(
1925
+ 'uri' => '/shipments/' . $shipment_id,
1926
+ 'params' => array(
1927
+ 'access_token' => $access_token
1928
+ )
1929
+ );
1930
+
1931
+ $shipments_data = MeliRestClient::get( $request, '' );
1932
+
1933
+ switch ( $shipments_data['response']['substatus'] ) {
1934
+
1935
+ case 'ready_to_print':
1936
+ $substatus_description = __( 'Tag ready to print', 'woocommerce-mercadopago-module' );
1937
+ break;
1938
+ case 'printed':
1939
+ $substatus_description = __( 'Tag printed', 'woocommerce-mercadopago-module' );
1940
+ break;
1941
+ case 'stale':
1942
+ $substatus_description = __( 'Unsuccessful', 'woocommerce-mercadopago-module' );
1943
+ break;
1944
+ case 'delayed':
1945
+ $substatus_description = __( 'Delayed shipping', 'woocommerce-mercadopago-module' );
1946
+ break;
1947
+ case 'receiver_absent':
1948
+ $substatus_description = __( 'Missing recipient for delivery', 'woocommerce-mercadopago-module' );
1949
+ break;
1950
+ case 'returning_to_sender':
1951
+ $substatus_description = __( 'In return to sender', 'woocommerce-mercadopago-module' );
1952
+ break;
1953
+ case 'claimed_me':
1954
+ $substatus_description = __( 'Buyer initiates complaint and requested a refund.', 'woocommerce-mercadopago-module' );
1955
+ break;
1956
+ default:
1957
+ $substatus_description = $shipments_data['response']['substatus'];
1958
+ break;
1959
  }
1960
+
1961
+ if ( $substatus_description == '' ) {
1962
+ $substatus_description = $shipments_data['response']['status'];
1963
+ }
1964
+
1965
+ $order->add_order_note( 'Mercado Envios: ' . $substatus_description );
1966
+
1967
+ $this->log->add(
1968
+ $this->id,
1969
+ '[check_mercado_envios] - Mercado Envios - shipments_data : ' .
1970
+ json_encode( $shipments_data, JSON_PRETTY_PRINT )
1971
+ );
1972
+
1973
+ // Add tracking number in meta data to use in order page.
1974
+ update_post_meta( $order_id, '_mercadoenvios_tracking_number', $shipments_data['response']['tracking_number'] );
1975
+ // Add shipiment_id in meta data to use in order page.
1976
+ update_post_meta( $order_id, '_mercadoenvios_shipment_id', $shipment_id );
1977
+ // Add status in meta data to use in order page.
1978
+ update_post_meta( $order_id, '_mercadoenvios_status', $shipments_data['response']['status'] );
1979
+ // Add substatus in meta data to use in order page.
1980
+ update_post_meta( $order_id, '_mercadoenvios_substatus', $shipments_data['response']['substatus'] );
1981
+
1982
+ // Send email to customer.
1983
+ $tracking_id = $shipments_data['response']['tracking_number'];
1984
+ if ( isset( $order->billing_email ) && isset( $tracking_id ) ) {
1985
+ $list_of_items = array();
1986
+ $items = $order->get_items();
1987
+ foreach ( $items as $item ) {
1988
+ $product = new WC_product( $item['product_id'] );
1989
+ if ( method_exists( $product, 'get_description' ) ) {
1990
+ $product_title = WC_WooMercadoPago_Module::utf8_ansi(
1991
+ $product->get_name()
1992
+ );
1993
+ } else {
1994
+ $product_title = WC_WooMercadoPago_Module::utf8_ansi(
1995
+ $product->post->post_title
1996
+ );
1997
+ }
1998
+ array_push( $list_of_items, $product_title . ' x ' . $item['qty'] );
1999
+ }
2000
+ wp_mail(
2001
+ $order->billing_email,
2002
+ __( 'Order', 'woocommerce-mercadopago-module' ) . ' ' . $order_id . ' - ' . __( 'Mercado Envios Tracking ID', 'woocommerce-mercadopago-module' ),
2003
+ __( 'Hello,', 'woocommerce-mercadopago-module' ) . "\r\n\r\n" .
2004
+ __( 'Your order', 'woocommerce-mercadopago-module' ) . ' ' . ' [ ' . implode( ', ', $list_of_items ) . ' ] ' .
2005
+ __( 'made in', 'woocommerce-mercadopago-module' ) . ' ' . get_site_url() . ' ' .
2006
+ __( 'used Mercado Envios as its shipment method.', 'woocommerce-mercadopago-module' ) . "\r\n" .
2007
+ __( 'You can track it with the following Tracking ID:', 'woocommerce-mercadopago-module' ) . ' ' . $tracking_id . ".\r\n\r\n" .
2008
+ __( 'Best regards.', 'woocommerce-mercadopago-module' )
2009
  );
2010
+ }
2011
+
 
2012
  }
2013
+
2014
  }
2015
  }
2016
+
2017
  }
2018
+
2019
+ }
mercadopago/mercadopago-subscription-gateway.php ADDED
@@ -0,0 +1,1476 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Part of Woo Mercado Pago Module
5
+ * Author - Mercado Pago
6
+ * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
7
+ * Copyright - Copyright(c) MercadoPago [https://www.mercadopago.com]
8
+ * License - https://www.gnu.org/licenses/gpl.html GPL version 2 or higher
9
+ */
10
+
11
+ // This include Mercado Pago library SDK
12
+ require_once dirname( __FILE__ ) . '/sdk/lib/mercadopago.php';
13
+
14
+ /**
15
+ * Summary: Extending from WooCommerce Payment Gateway class.
16
+ * Description: This class implements Mercado Pago Subscription checkout.
17
+ * @since 2.2.0
18
+ */
19
+ class WC_WooMercadoPagoSubscription_Gateway extends WC_Payment_Gateway {
20
+
21
+ public function __construct() {
22
+
23
+ // Creating PHP version message.
24
+ $min_php_message = phpversion() >= WC_WooMercadoPago_Module::MIN_PHP ?
25
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
26
+ __( 'Your PHP version is OK.', 'woocommerce-mercadopago-module' ) :
27
+ '<img width="14" height="14" src="' . plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
28
+ sprintf(
29
+ __( 'Your PHP version do not support this module. You have %s, minimal required is %s.', 'woocommerce-mercadopago-module' ),
30
+ phpversion(), WC_WooMercadoPago_Module::MIN_PHP
31
+ );
32
+ // Check cURL.
33
+ $curl_message = in_array( 'curl', get_loaded_extensions() ) ?
34
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
35
+ __( 'cURL is installed.', 'woocommerce-mercadopago-module' ) :
36
+ '<img width="14" height="14" src="' . plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
37
+ __( 'cURL is not installed.', 'woocommerce-mercadopago-module' );
38
+ // Check SSL.
39
+ $is_ssl_message = empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ?
40
+ '<img width="14" height="14" src="' . plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
41
+ __( 'SSL is missing in your site.', 'woocommerce-mercadopago-module' ) :
42
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
43
+ __( 'Your site has SSL enabled.', 'woocommerce-mercadopago-module' );
44
+
45
+ // Mercado Pago fields.
46
+ $this->mp = null;
47
+ $this->site_id = null;
48
+ $this->currency_ratio = -1;
49
+ $this->is_test_user = false;
50
+
51
+ // Auxiliary fields.
52
+ $this->currency_message = '';
53
+ $this->payment_methods = array();
54
+ $this->country_configs = array();
55
+
56
+ // WooCommerce fields.
57
+ //$this->supports = array( 'products', 'refunds' );
58
+ $this->id = 'woocommerce-mercadopago-subscription-module';
59
+ $this->domain = get_site_url() . '/index.php';
60
+ $this->method_title = __( 'Mercado Pago - Subscription', 'woocommerce-mercadopago-module' );
61
+ $this->method_description = '<img width="200" height="52" src="' .
62
+ plugins_url(
63
+ 'images/mplogo.png',
64
+ plugin_dir_path( __FILE__ )
65
+ ) . '"><br><br>' . '<strong>' .
66
+ __( 'This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store.', 'woocommerce-mercadopago-module' ) .
67
+ '</strong>' . '<br><br>' .
68
+ $min_php_message . '<br>' .
69
+ $is_ssl_message . '<br>' .
70
+ $curl_message;
71
+
72
+ // Fields used in Mercado Pago Module configuration page.
73
+ $this->client_id = $this->get_option( 'client_id' );
74
+ $this->client_secret = $this->get_option( 'client_secret' );
75
+ $this->title = $this->get_option( 'title' );
76
+ $this->description = $this->get_option( 'description' );
77
+ $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' );
78
+ $this->method = $this->get_option( 'method', 'iframe' );
79
+ $this->iframe_width = $this->get_option( 'iframe_width', 640 );
80
+ $this->iframe_height = $this->get_option( 'iframe_height', 800 );
81
+ $this->success_url = $this->get_option( 'success_url', '' );
82
+ $this->currency_conversion = $this->get_option( 'currency_conversion', false );
83
+ $this->gateway_discount = 0;
84
+ $this->debug = $this->get_option( 'debug' );
85
+
86
+ // Logging and debug.
87
+ if ( 'yes' == $this->debug ) {
88
+ if ( class_exists( 'WC_Logger' ) ) {
89
+ $this->log = new WC_Logger();
90
+ } else {
91
+ $this->log = WC_MercadoPago_Module::woocommerce_instance()->logger();
92
+ }
93
+ }
94
+
95
+ // Render our configuration page and init/load fields.
96
+ $this->init_form_fields();
97
+ $this->init_settings();
98
+
99
+ // Used by IPN to receive IPN incomings.
100
+ add_action(
101
+ 'woocommerce_api_wc_woomercadopagosubscription_gateway',
102
+ array( $this, 'check_ipn_response' )
103
+ );
104
+ // Used by IPN to process valid incomings.
105
+ add_action(
106
+ 'valid_mercadopagosubscription_ipn_request',
107
+ array( $this, 'successful_request' )
108
+ );
109
+ // process the cancel order meta box order action
110
+ add_action(
111
+ 'woocommerce_order_action_cancel_order',
112
+ array( $this, 'process_cancel_order_meta_box_actions' )
113
+ );
114
+ // Used by WordPress to render the custom checkout page.
115
+ add_action(
116
+ 'woocommerce_receipt_' . $this->id,
117
+ array( $this, 'receipt_page' )
118
+ );
119
+ // Used to fix CSS in some older WordPress/WooCommerce versions.
120
+ add_action(
121
+ 'wp_head',
122
+ array( $this, 'css' )
123
+ );
124
+ // Used in settings page to hook "save settings" action.
125
+ add_action(
126
+ 'woocommerce_update_options_payment_gateways_' . $this->id,
127
+ array( $this, 'process_admin_options' )
128
+ );
129
+ // Scripts for order configuration.
130
+ add_action(
131
+ 'woocommerce_after_checkout_form',
132
+ array( $this, 'add_checkout_script' )
133
+ );
134
+ // Display discount in payment method title.
135
+ add_filter(
136
+ 'woocommerce_gateway_title',
137
+ array( $this, 'get_payment_method_title_subscription' ), 10, 2
138
+ );
139
+ // Checkout updates.
140
+ add_action(
141
+ 'woocommerce_thankyou',
142
+ array( $this, 'update_checkout_status' )
143
+ );
144
+
145
+ // Verify if client_id or client_secret is empty.
146
+ if ( empty( $this->client_id ) || empty( $this->client_secret ) ) {
147
+ if ( ! empty( $this->settings['enabled'] ) && 'yes' == $this->settings['enabled'] ) {
148
+ add_action( 'admin_notices', array( $this, 'client_id_or_secret_missing_message' ) );
149
+ }
150
+ }
151
+
152
+ }
153
+
154
+ /**
155
+ * Summary: Initialise Gateway Settings Form Fields.
156
+ * Description: Initialise Gateway settings form fields with a customized page.
157
+ */
158
+ public function init_form_fields() {
159
+
160
+ // If module is disabled, we do not need to load and process the settings page.
161
+ if ( empty( $this->settings['enabled'] ) || 'no' == $this->settings['enabled'] ) {
162
+ $this->form_fields = array(
163
+ 'enabled' => array(
164
+ 'title' => __( 'Enable/Disable', 'woocommerce-mercadopago-module' ),
165
+ 'type' => 'checkbox',
166
+ 'label' => __( 'Enable Subscription', 'woocommerce-mercadopago-module' ),
167
+ 'default' => 'no'
168
+ )
169
+ );
170
+ return;
171
+ }
172
+
173
+ $api_secret_locale = sprintf(
174
+ '<a href="https://www.mercadopago.com/mla/account/credentials?type=basic" target="_blank">%s</a>, ' .
175
+ '<a href="https://www.mercadopago.com/mlb/account/credentials?type=basic" target="_blank">%s</a> %s ' .
176
+ '<a href="https://www.mercadopago.com/mlm/account/credentials?type=basic" target="_blank">%s</a>, ',
177
+ __( 'Argentine', 'woocommerce-mercadopago-module' ),
178
+ __( 'Brazil', 'woocommerce-mercadopago-module' ),
179
+ __( 'or', 'woocommerce-mercadopago-module' ),
180
+ __( 'Mexico', 'woocommerce-mercadopago-module' )
181
+ );
182
+
183
+ $ipn_locale = sprintf(
184
+ '<a href="https://www.mercadopago.com.ar/ipn-notifications" target="_blank">%s</a>, ' .
185
+ '<a href="https://www.mercadopago.com.br/ipn-notifications" target="_blank">%s</a> %s ' .
186
+ '<a href="https://www.mercadopago.com.mx/ipn-notifications" target="_blank">%s</a>, ',
187
+ __( 'Argentine', 'woocommerce-mercadopago-module' ),
188
+ __( 'Brazil', 'woocommerce-mercadopago-module' ),
189
+ __( 'or', 'woocommerce-mercadopago-module' ),
190
+ __( 'Mexico', 'woocommerce-mercadopago-module' )
191
+ );
192
+
193
+ // Trigger API to get payment methods and site_id, also validates Client_id/Client_secret.
194
+ if ( $this->validate_credentials() ) {
195
+ // Checking the currency.
196
+ $this->currency_message = '';
197
+ if ( ! $this->is_supported_currency() && 'yes' == $this->settings['enabled'] ) {
198
+ if ( $this->currency_conversion == 'no' ) {
199
+ $this->currency_ratio = -1;
200
+ $this->currency_message .= WC_WooMercadoPago_Module::build_currency_not_converted_msg(
201
+ $this->country_configs['currency'],
202
+ $this->country_configs['country_name']
203
+ );
204
+ } elseif ( $this->currency_conversion == 'yes' && $this->currency_ratio != -1) {
205
+ $this->currency_message .= WC_WooMercadoPago_Module::build_currency_converted_msg(
206
+ $this->country_configs['currency'],
207
+ $this->currency_ratio
208
+ );
209
+ } else {
210
+ $this->currency_ratio = -1;
211
+ $this->currency_message .= WC_WooMercadoPago_Module::build_currency_conversion_err_msg(
212
+ $this->country_configs['currency']
213
+ );
214
+ }
215
+ } else {
216
+ $this->currency_ratio = -1;
217
+ }
218
+ $this->credentials_message = WC_WooMercadoPago_Module::build_valid_credentials_msg(
219
+ $this->country_configs['country_name'],
220
+ $this->site_id
221
+ );
222
+ } else {
223
+ array_push( $this->payment_methods, 'n/d' );
224
+ $this->credentials_message = WC_WooMercadoPago_Module::build_invalid_credentials_msg();
225
+ }
226
+
227
+ // Checks validity of iFrame width/height fields.
228
+ if ( ! is_numeric( $this->iframe_width ) ) {
229
+ $this->iframe_width_desc = '<img width="12" height="12" src="' .
230
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
231
+ __( 'This field should be an integer.', 'woocommerce-mercadopago-module' );
232
+ } else {
233
+ $this->iframe_width_desc =
234
+ __( 'If your integration method is iFrame, please inform the payment iFrame width.', 'woocommerce-mercadopago-module' );
235
+ }
236
+ if ( ! is_numeric( $this->iframe_height ) ) {
237
+ $this->iframe_height_desc = '<img width="12" height="12" src="' .
238
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
239
+ __( 'This field should be an integer.', 'woocommerce-mercadopago-module' );
240
+ } else {
241
+ $this->iframe_height_desc =
242
+ __( 'If your integration method is iFrame, please inform the payment iFrame height.', 'woocommerce-mercadopago-module' );
243
+ }
244
+
245
+ // This array draws each UI (text, selector, checkbox, label, etc).
246
+ $this->form_fields = array(
247
+ 'enabled' => array(
248
+ 'title' => __( 'Enable/Disable', 'woocommerce-mercadopago-module' ),
249
+ 'type' => 'checkbox',
250
+ 'label' => __( 'Enable Subscription', 'woocommerce-mercadopago-module' ),
251
+ 'default' => 'no'
252
+ ),
253
+ 'credentials_title' => array(
254
+ 'title' => __( 'Mercado Pago Credentials', 'woocommerce-mercadopago-module' ),
255
+ 'type' => 'title',
256
+ 'description' => sprintf( '%s', $this->credentials_message ) . '<br>' . sprintf(
257
+ __( 'You can obtain your credentials for', 'woocommerce-mercadopago-module' ) .
258
+ ' %s.', $api_secret_locale
259
+ )
260
+ ),
261
+ 'client_id' => array(
262
+ 'title' => 'Client_id',
263
+ 'type' => 'text',
264
+ 'description' =>
265
+ __( 'Insert your Mercado Pago Client_id.', 'woocommerce-mercadopago-module' ),
266
+ 'default' => '',
267
+ 'required' => true
268
+ ),
269
+ 'client_secret' => array(
270
+ 'title' => 'Client_secret',
271
+ 'type' => 'text',
272
+ 'description' =>
273
+ __( 'Insert your Mercado Pago Client_secret.', 'woocommerce-mercadopago-module' ),
274
+ 'default' => '',
275
+ 'required' => true
276
+ ),
277
+ 'ipn_url' => array(
278
+ 'title' =>
279
+ __( 'Instant Payment Notification (IPN) URL', 'woocommerce-mercadopago-module' ),
280
+ 'type' => 'title',
281
+ 'description' => sprintf(
282
+ __( 'For this solution, you need to configure your IPN URL. You can access it in your account for your specific country in:', 'woocommerce-mercadopago-module' ) .
283
+ '<br>' . ' %s.', $ipn_locale . '. ' . sprintf(
284
+ __( 'Your IPN URL to receive instant payment notifications is', 'woocommerce-mercadopago-module' ) .
285
+ ':<br>%s', '<code>' . WC()->api_request_url( 'WC_WooMercadoPagoSubscription_Gateway' ) . '</code>' )
286
+ )
287
+ ),
288
+ 'checkout_options_title' => array(
289
+ 'title' => __( 'Checkout Options', 'woocommerce-mercadopago-module' ),
290
+ 'type' => 'title',
291
+ 'description' => ''
292
+ ),
293
+ 'title' => array(
294
+ 'title' => __( 'Title', 'woocommerce-mercadopago-module' ),
295
+ 'type' => 'text',
296
+ 'description' =>
297
+ __( 'Title shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
298
+ 'default' => __( 'Mercado Pago', 'woocommerce-mercadopago-module' )
299
+ ),
300
+ 'description' => array(
301
+ 'title' => __( 'Description', 'woocommerce-mercadopago-module' ),
302
+ 'type' => 'textarea',
303
+ 'description' =>
304
+ __( 'Description shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
305
+ 'default' => __( 'Subscribe with Mercado Pago', 'woocommerce-mercadopago-module' )
306
+ ),
307
+ 'invoice_prefix' => array(
308
+ 'title' => __( 'Store Identificator', 'woocommerce-mercadopago-module' ),
309
+ 'type' => 'text',
310
+ 'description' =>
311
+ __( 'Please, inform a prefix to your store.', 'woocommerce-mercadopago-module' )
312
+ . ' ' .
313
+ __( 'If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same identificators.', 'woocommerce-mercadopago-module' ),
314
+ 'default' => 'WC-'
315
+ ),
316
+ 'method' => array(
317
+ 'title' => __( 'Integration Method', 'woocommerce-mercadopago-module' ),
318
+ 'type' => 'select',
319
+ 'description' => __( 'Select how your clients should interact with Mercado Pago. Modal Window (inside your store), Redirect (Client is redirected to Mercado Pago), or iFrame (an internal window is embedded to the page layout).', 'woocommerce-mercadopago-module' ),
320
+ 'default' => 'iframe',
321
+ 'options' => array(
322
+ 'iframe' => __( 'iFrame', 'woocommerce-mercadopago-module' ),
323
+ 'modal' => __( 'Modal Window', 'woocommerce-mercadopago-module' ),
324
+ 'redirect' => __( 'Redirect', 'woocommerce-mercadopago-module' )
325
+ )
326
+ ),
327
+ 'iframe_width' => array(
328
+ 'title' => __( 'iFrame Width', 'woocommerce-mercadopago-module' ),
329
+ 'type' => 'text',
330
+ 'description' => $this->iframe_width_desc,
331
+ 'default' => '640'
332
+ ),
333
+ 'iframe_height' => array(
334
+ 'title' => __( 'iFrame Height', 'woocommerce-mercadopago-module' ),
335
+ 'type' => 'text',
336
+ 'description' => $this->iframe_height_desc,
337
+ 'default' => '800'
338
+ ),
339
+ 'back_url_title' => array(
340
+ 'title' => __( 'Back URL Options', 'woocommerce-mercadopago-module' ),
341
+ 'type' => 'title',
342
+ 'description' => ''
343
+ ),
344
+ 'success_url' => array(
345
+ 'title' => __( 'Sucess URL', 'woocommerce-mercadopago-module' ),
346
+ 'type' => 'text',
347
+ 'description' => __( 'Where customers should be redirected after a successful purchase. Let blank to redirect to the default store order resume page.', 'woocommerce-mercadopago-module' ),
348
+ 'default' => ''
349
+ ),
350
+ 'payment_title' => array(
351
+ 'title' => __( 'Payment Options', 'woocommerce-mercadopago-module' ),
352
+ 'type' => 'title',
353
+ 'description' => ''
354
+ ),
355
+ 'currency_conversion' => array(
356
+ 'title' => __( 'Currency Conversion', 'woocommerce-mercadopago-module' ),
357
+ 'type' => 'checkbox',
358
+ 'label' =>
359
+ __( 'If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio.', 'woocommerce-mercadopago-module' ),
360
+ 'default' => 'no',
361
+ 'description' => sprintf( '%s', $this->currency_message )
362
+ ),
363
+ 'testing' => array(
364
+ 'title' => __( 'Test and Debug Options', 'woocommerce-mercadopago-module' ),
365
+ 'type' => 'title',
366
+ 'description' => ''
367
+ ),
368
+ 'debug' => array(
369
+ 'title' => __( 'Debug and Log', 'woocommerce-mercadopago-module' ),
370
+ 'type' => 'checkbox',
371
+ 'label' => __( 'Enable log', 'woocommerce-mercadopago-module' ),
372
+ 'default' => 'no',
373
+ 'description' => sprintf(
374
+ __( 'Register event logs of Mercado Pago, such as API requests, in the file', 'woocommerce-mercadopago-module' ) .
375
+ ' %s.', $this->build_log_path_string() . '.<br>' .
376
+ __( 'File location: ', 'woocommerce-mercadopago-module' ) .
377
+ '<code>wordpress/wp-content/uploads/wc-logs/' . $this->id . '-' .
378
+ sanitize_file_name( wp_hash( $this->id) ) . '.log</code>' )
379
+ )
380
+ );
381
+
382
+ }
383
+
384
+ /**
385
+ * Processes and saves options.
386
+ * If there is an error thrown, will continue to save and validate fields, but will leave the
387
+ * erroring field out.
388
+ * @return bool was anything saved?
389
+ */
390
+ public function custom_process_admin_options() {
391
+ $this->init_settings();
392
+
393
+ if ( ! empty( $this->settings['client_id'] ) && ! empty( $this->settings['client_secret'] ) ) {
394
+ $this->mp = new MP(
395
+ WC_WooMercadoPago_Module::get_module_version(),
396
+ $this->settings['client_id'],
397
+ $this->settings['client_secret']
398
+ );
399
+ } else {
400
+ $this->mp = null;
401
+ }
402
+
403
+ // analytics
404
+ if ( $this->mp != null && ! $this->is_test_user ) {
405
+ $infra_data = WC_WooMercadoPago_Module::get_common_settings();
406
+ $infra_data['checkout_subscription'] = ( $this->settings['enabled'] == 'yes' ? 'true' : 'false' );
407
+ $response = $this->mp->analytics_save_settings( $infra_data );
408
+ if ( 'yes' == $this->debug) {
409
+ $this->log->add(
410
+ $this->id,
411
+ '[custom_process_admin_options] - analytics response: ' .
412
+ json_encode( $response, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
413
+ );
414
+ }
415
+ }
416
+
417
+ return update_option(
418
+ $this->get_option_key(),
419
+ apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings )
420
+ );
421
+ }
422
+
423
+ /**
424
+ * Handles the manual order cancellation in server-side.
425
+ */
426
+ public function process_cancel_order_meta_box_actions( $order ) {
427
+ // WooCommerce 3.0 or later.
428
+ if ( method_exists( $order, 'get_meta' ) ) {
429
+ $used_gateway = $order->get_meta( '_used_gateway' );
430
+ $preapproval = $order->get_meta( 'Mercado Pago Pre-Approval' );
431
+ } else {
432
+ $used_gateway = get_post_meta( $order->id, '_used_gateway', true );
433
+ $preapproval = get_post_meta( $order->id, 'Mercado Pago Pre-Approval', true );
434
+ }
435
+
436
+ if ( $used_gateway != 'WC_WooMercadoPagoSubscription_Gateway' ) {
437
+ return;
438
+ }
439
+
440
+ $preapproval = explode( '/', $preapproval );
441
+ $preapproval = explode( ' ', substr( $preapproval[0], 1, -1 ) );
442
+ $preapproval_id = $preapproval[1];
443
+
444
+ if ( 'yes' == $this->debug ) {
445
+ $this->log->add(
446
+ $this->id,
447
+ '[process_cancel_order_meta_box_actions] - cancelling preapproval for ' . $preapproval_id
448
+ );
449
+ }
450
+
451
+ if ( $this->mp != null && ! empty( $preapproval_id ) ) {
452
+ $response = $this->mp->cancel_preapproval_payment( $preapproval_id );
453
+ $message = $response['response']['message'];
454
+ $status = $response['status'];
455
+ if ( 'yes' == $this->debug ) {
456
+ $this->log->add(
457
+ $this->id,
458
+ '[process_cancel_order_meta_box_actions] - cancel preapproval of id ' . $preapproval_id .
459
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
460
+ );
461
+ }
462
+ } else {
463
+ if ( 'yes' == $this->debug ) {
464
+ $this->log->add(
465
+ $this->id,
466
+ '[process_cancel_order_meta_box_actions] - no preapproval or credentials invalid'
467
+ );
468
+ }
469
+ }
470
+
471
+ }
472
+
473
+ /*
474
+ * ========================================================================
475
+ * CHECKOUT BUSINESS RULES (CLIENT SIDE)
476
+ * ========================================================================
477
+ */
478
+
479
+ public function payment_fields() {
480
+ // subscription checkout
481
+ if ( $description = $this->get_description() ) {
482
+ echo wpautop(wptexturize( $description ) );
483
+ }
484
+ if ( $this->supports( 'default_credit_card_form' ) ) {
485
+ $this->credit_card_form();
486
+ }
487
+ }
488
+
489
+ public function add_checkout_script() {
490
+
491
+ $client_id = $this->get_option( 'client_id' );
492
+
493
+ if ( ! empty( $client_id ) && ! $this->is_test_user ) {
494
+
495
+ $w = WC_WooMercadoPago_Module::woocommerce_instance();
496
+ $logged_user_email = null;
497
+ $payments = array();
498
+ $gateways = WC()->payment_gateways->get_available_payment_gateways();
499
+ foreach ( $gateways as $g ) {
500
+ $payments[] = $g->id;
501
+ }
502
+ $payments = str_replace( '-', '_', implode( ', ', $payments ) );
503
+
504
+ if ( wp_get_current_user()->ID != 0 ) {
505
+ $logged_user_email = wp_get_current_user()->user_email;
506
+ }
507
+
508
+ ?>
509
+ <script src="https://secure.mlstatic.com/modules/javascript/analytics.js"></script>
510
+ <script type="text/javascript">
511
+ var MA = ModuleAnalytics;
512
+ MA.setToken( '<?php echo $client_id; ?>' );
513
+ MA.setPlatform( 'WooCommerce' );
514
+ MA.setPlatformVersion( '<?php echo $w->version; ?>' );
515
+ MA.setModuleVersion( '<?php echo WC_WooMercadoPago_Module::VERSION; ?>' );
516
+ MA.setPayerEmail( '<?php echo ( $logged_user_email != null ? $logged_user_email : "" ); ?>' );
517
+ MA.setUserLogged( <?php echo ( empty( $logged_user_email ) ? 0 : 1 ); ?> );
518
+ MA.setInstalledModules( '<?php echo $payments; ?>' );
519
+ MA.post();
520
+ </script>
521
+ <?php
522
+
523
+ }
524
+
525
+ }
526
+
527
+ public function update_checkout_status( $order_id ) {
528
+
529
+ $client_id = $this->get_option( 'client_id' );
530
+
531
+ if ( ! empty( $client_id ) && ! $this->is_test_user ) {
532
+
533
+ if ( get_post_meta( $order_id, '_used_gateway', true ) != 'WC_WooMercadoPagoSubscription_Gateway' ) {
534
+ return;
535
+ }
536
+
537
+ if ( 'yes' == $this->debug ) {
538
+ $this->log->add(
539
+ $this->id,
540
+ '[update_checkout_status] - updating order of ID ' . $order_id
541
+ );
542
+ }
543
+
544
+ echo '<script src="https://secure.mlstatic.com/modules/javascript/analytics.js"></script>
545
+ <script type="text/javascript">
546
+ var MA = ModuleAnalytics;
547
+ MA.setToken( ' . $client_id . ' );
548
+ MA.setPaymentType("subscription");
549
+ MA.setCheckoutType("subscription");
550
+ MA.put();
551
+ </script>';
552
+
553
+ }
554
+
555
+ }
556
+
557
+ /**
558
+ * Summary: Handle the payment and processing the order.
559
+ * Description: First step occurs when the customer selects Mercado Pago and proceed to checkout.
560
+ * This method verify which integration method was selected and makes the build for the checkout
561
+ * URL.
562
+ * @return an array containing the result of the processment and the URL to redirect.
563
+ */
564
+ public function process_payment( $order_id ) {
565
+ $order = wc_get_order( $order_id );
566
+
567
+ // WooCommerce 3.0 or later.
568
+ if ( method_exists( $order, 'update_meta_data' ) ) {
569
+ $order->update_meta_data( '_used_gateway', 'WC_WooMercadoPagoSubscription_Gateway' );
570
+ $order->save();
571
+ } else {
572
+ update_post_meta( $order_id, '_used_gateway', 'WC_WooMercadoPagoSubscription_Gateway' );
573
+ }
574
+
575
+ if ( 'redirect' == $this->method ) {
576
+ // The checkout is made by redirecting customer to Mercado Pago.
577
+ if ( 'yes' == $this->debug) {
578
+ $this->log->add(
579
+ $this->id,
580
+ '[process_payment] - customer being redirected to Mercado Pago.'
581
+ );
582
+ }
583
+ return array(
584
+ 'result' => 'success',
585
+ 'redirect' => $this->create_url( $order )
586
+ );
587
+ } elseif ( 'modal' == $this->method || 'iframe' == $this->method ) {
588
+ // The checkout is made by customizing the view, either by iframe or showing a modal.
589
+ if ( 'yes' == $this->debug ) {
590
+ $this->log->add(
591
+ $this->id,
592
+ '[process_payment] - preparing to render Mercado Pago checkout view.'
593
+ );
594
+ }
595
+ return array(
596
+ 'result' => 'success',
597
+ 'redirect' => $order->get_checkout_payment_url( true )
598
+ );
599
+ }
600
+ }
601
+
602
+ /**
603
+ * Summary: Show the custom renderization for the checkout.
604
+ * Description: Order page and this generates the form that shows the pay button. This step
605
+ * generates the form to proceed to checkout.
606
+ * @return the html to be rendered.
607
+ */
608
+ public function receipt_page( $order ) {
609
+ echo $this->render_order_form( $order );
610
+ }
611
+
612
+ // --------------------------------------------------
613
+
614
+ public function render_order_form( $order_id ) {
615
+
616
+ $order = wc_get_order( $order_id );
617
+ $url = $this->create_url( $order );
618
+
619
+ if ( $url ) {
620
+ $html =
621
+ '<img width="468" height="60" src="' . $this->country_configs['checkout_banner'] . '">';
622
+ if ( 'modal' == $this->method ) {
623
+ // The checkout is made by displaying a modal to the customer.
624
+ if ( 'yes' == $this->debug ) {
625
+ $this->log->add(
626
+ $this->id,
627
+ '[render_order_form] - rendering Mercado Pago lightbox (modal window).'
628
+ );
629
+ }
630
+ $html .= '<p></p><p>' . wordwrap(
631
+ __( 'Thank you for your order. Please, proceed with your payment clicking in the bellow button.', 'woocommerce-mercadopago-module' ),
632
+ 60, '<br>'
633
+ ) . '</p>';
634
+ $html .=
635
+ '<a id="submit-payment" href="' . $url .
636
+ '" name="MP-Checkout" class="button alt" mp-mode="modal">' .
637
+ __( 'Pay with Mercado Pago', 'woocommerce-mercadopago-module' ) .
638
+ '</a> ';
639
+ $html .=
640
+ '<a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">' .
641
+ __( 'Cancel order &amp; Clear cart', 'woocommerce-mercadopago-module' ) .
642
+ '</a><style type="text/css">#MP-Checkout-dialog #MP-Checkout-IFrame { bottom: -28px !important; height: 590px !important; }</style>';
643
+ // Includes the javascript of lightbox.
644
+ $html .=
645
+ '<script type="text/javascript">(function(){function $MPBR_load(){window.$MPBR_loaded !== true && (function(){var s = document.createElement("script");s.type = "text/javascript";s.async = true;s.src = ("https:"==document.location.protocol?"https://www.mercadopago.com/org-img/jsapi/mptools/buttons/":"https://mp-tools.mlstatic.com/buttons/")+"render.js";var x = document.getElementsByTagName("script")[0];x.parentNode.insertBefore(s, x);window.$MPBR_loaded = true;})();}window.$MPBR_loaded !== true ? (window.attachEvent ? window.attachEvent("onload", $MPBR_load) : window.addEventListener("load", $MPBR_load, false) ) : null;})();</script>';
646
+ } else {
647
+ // The checkout is made by rendering Mercado Pago form within a iframe.
648
+ if ( 'yes' == $this->debug ) {
649
+ $this->log->add(
650
+ $this->id,
651
+ '[render_order_form] - embedding Mercado Pago iframe.'
652
+ );
653
+ }
654
+ $html .= '<p></p><p>' . wordwrap(
655
+ __( 'Thank you for your order. Proceed with your payment completing the following information.', 'woocommerce-mercadopago-module' ),
656
+ 60, '<br>'
657
+ ) . '</p>';
658
+ $html .= '<iframe src="' . $url . '" name="MP-Checkout" ' .
659
+ 'width="' . ( is_numeric( (int) $this->iframe_width ) ? $this->iframe_width : 640 ) .
660
+ '" ' .
661
+ 'height="' . ( is_numeric( (int) $this->iframe_height ) ? $this->iframe_height : 800 ) .
662
+ '" ' .
663
+ 'frameborder="0" scrolling="no" id="checkout_mercadopago"></iframe>';
664
+ }
665
+ return $html;
666
+ } else {
667
+ // Reaching at this point means that the URL could not be build by some reason.
668
+ if ( 'yes' == $this->debug ) {
669
+ $this->log->add(
670
+ $this->id,
671
+ '[render_order_form] - unable to build Mercado Pago checkout URL.'
672
+ );
673
+ }
674
+ $html = '<p>' .
675
+ __( 'An error occurred when proccessing your payment. Please try again or contact us for assistence.', 'woocommerce-mercadopago-module' ) .
676
+ '</p>';
677
+ $html .= '<a class="button" href="' . esc_url( $order->get_checkout_payment_url() ) . '">' .
678
+ __( 'Click to try again', 'woocommerce-mercadopago-module' ) .
679
+ '</a>';
680
+ return $html;
681
+ }
682
+ }
683
+
684
+ /**
685
+ * Summary: Build Mercado Pago preapproval.
686
+ * Description: Create Mercado Pago preapproval structure and get init_point URL based in the order options
687
+ * from the cart.
688
+ * @return the preapproval structure.
689
+ */
690
+ public function build_preapproval( $order ) {
691
+
692
+ // Here we build the array that contains ordered items, from customer cart
693
+ $preapproval = null;
694
+
695
+ $arr = $order->get_items();
696
+ foreach ( $order->get_items() as $item ) {
697
+ if ( $item['qty'] ) {
698
+ $product = new WC_product( $item['product_id'] );
699
+
700
+ // WooCommerce 3.0 or later.
701
+ if ( method_exists( $product, 'get_name' ) ) {
702
+ $product_title = WC_WooMercadoPago_Module::utf8_ansi(
703
+ $product->get_name()
704
+ );
705
+ } else {
706
+ $product_title = WC_WooMercadoPago_Module::utf8_ansi(
707
+ $product->post->post_title
708
+ );
709
+ }
710
+
711
+ $unit_price = floor( ( (float) $item['line_total'] + (float) $item['line_tax'] ) *
712
+ ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ) * 100 ) / 100;
713
+
714
+ // Add shipment cost
715
+ $unit_price += ( (float) $order->get_total_shipping() + (float) $order->get_shipping_tax() ) *
716
+ ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 );
717
+
718
+ // Round to two decimals.
719
+ $unit_price = floor( $unit_price * 100 ) / 100;
720
+
721
+ // Remove decimals if MCO/MLC
722
+ if ( $this->site_id == 'MCO' || $this->site_id == 'MLC' ) {
723
+ $unit_price = floor( $unit_price );
724
+ }
725
+
726
+ // Get the custom fields
727
+ $frequency = get_post_meta( $item['product_id'], '_mp_recurring_frequency', true );
728
+ $frequency_type = get_post_meta( $item['product_id'], '_mp_recurring_frequency_type', true );
729
+ $start_date = get_post_meta( $item['product_id'], '_mp_recurring_start_date', true );
730
+ $end_date = get_post_meta( $item['product_id'], '_mp_recurring_end_date', true );
731
+
732
+ // WooCommerce 3.0 or later.
733
+ if ( method_exists( $order, 'get_id' ) ) {
734
+ // Creates the pre-approval structure
735
+ $preapproval = array(
736
+ 'payer_email' => $order->get_billing_email(),
737
+ 'back_url' => ( empty( $this->success_url ) ?
738
+ WC_WooMercadoPago_Module::workaround_ampersand_bug(
739
+ esc_url( $this->get_return_url( $order ) )
740
+ ) : $this->success_url
741
+ ),
742
+ 'reason' => $product_title,
743
+ 'external_reference' => $this->invoice_prefix . $order->get_id(),
744
+ 'auto_recurring' => array(
745
+ 'frequency' => $frequency,
746
+ 'frequency_type' => $frequency_type,
747
+ 'transaction_amount' => $unit_price,
748
+ 'currency_id' => $this->country_configs['currency']
749
+ )
750
+ );
751
+ } else {
752
+ // Creates the pre-approval structure
753
+ $preapproval = array(
754
+ 'payer_email' => $order->billing_email,
755
+ 'back_url' => ( empty( $this->success_url ) ?
756
+ WC_WooMercadoPago_Module::workaround_ampersand_bug(
757
+ esc_url( $this->get_return_url( $order) )
758
+ ) : $this->success_url
759
+ ),
760
+ 'reason' => $product_title,
761
+ 'external_reference' => $this->invoice_prefix . $order->id,
762
+ 'auto_recurring' => array(
763
+ 'frequency' => $frequency,
764
+ 'frequency_type' => $frequency_type,
765
+ 'transaction_amount' => $unit_price,
766
+ 'currency_id' => $this->country_configs['currency']
767
+ )
768
+ );
769
+ }
770
+
771
+ if ( isset( $start_date ) && ! empty( $start_date ) )
772
+ $preapproval['auto_recurring']['start_date'] = $start_date . 'T16:00:00.000-03:00';
773
+ if ( isset( $end_date ) && ! empty( $end_date ) )
774
+ $preapproval['auto_recurring']['end_date'] = $end_date . 'T16:00:00.000-03:00';
775
+ // Do not set IPN url if it is a localhost.
776
+ if ( ! strrpos( $this->domain, 'localhost' ) ) {
777
+ $preapproval['notification_url'] = WC_WooMercadoPago_Module::workaround_ampersand_bug(
778
+ WC()->api_request_url( 'WC_WooMercadoPagoSubscription_Gateway' )
779
+ );
780
+ }
781
+ // Set sponsor ID.
782
+ if ( ! $this->is_test_user ) {
783
+ $preapproval['sponsor_id'] = $this->country_configs['sponsor_id'];
784
+ }
785
+ // Log debug message.
786
+ if ( 'yes' == $this->debug ) {
787
+ $this->log->add(
788
+ $this->id,
789
+ '[build_preapproval] - preapproval created with following structure: ' .
790
+ json_encode( $preapproval, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE ) );
791
+ }
792
+ }
793
+ }
794
+
795
+ return $preapproval;
796
+ }
797
+
798
+ // --------------------------------------------------
799
+
800
+ protected function create_url( $order ) {
801
+
802
+ $this->mp->sandbox_mode( false );
803
+
804
+ // Creates the order parameters by checking the cart configuration.
805
+ $preapproval_payment = $this->build_preapproval( $order );
806
+ // Create order preferences with Mercado Pago API request.
807
+ try {
808
+ $checkout_info = $this->mp->create_preapproval_payment( json_encode( $preapproval_payment ) );
809
+ if ( $checkout_info['status'] < 200 || $checkout_info['status'] >= 300 ) {
810
+ // Mercado Pago trowed an error.
811
+ if ( 'yes' == $this->debug ) {
812
+ $this->log->add(
813
+ $this->id,
814
+ '[create_url] - mercado pago gave error, payment creation failed with error: ' .
815
+ $checkout_info['response']['message']
816
+ );
817
+ }
818
+ return false;
819
+ } elseif ( is_wp_error( $checkout_info ) ) {
820
+ // WordPress throwed an error.
821
+ if ( 'yes' == $this->debug ) {
822
+ $this->log->add(
823
+ $this->id,
824
+ '[create_url] - wordpress gave error, payment creation failed with error: ' .
825
+ $checkout_info['response']['message']
826
+ );
827
+ }
828
+ return false;
829
+ } else {
830
+ // Obtain the URL.
831
+ if ( 'yes' == $this->debug ) {
832
+ $this->log->add(
833
+ $this->id,
834
+ '[create_url] - pre-approval link generated with success from mercado pago, with structure as follow: ' .
835
+ json_encode( $checkout_info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
836
+ );
837
+ }
838
+ return $checkout_info['response']['init_point'];
839
+ }
840
+ } catch ( MercadoPagoException $e ) {
841
+ // Something went wrong with the payment creation.
842
+ if ( 'yes' == $this->debug ) {
843
+ $this->log->add(
844
+ $this->id,
845
+ '[create_url] - payment creation failed with exception: ' .
846
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
847
+ );
848
+ }
849
+ return false;
850
+ }
851
+
852
+ }
853
+
854
+ // Display the discount in payment method title.
855
+ public function get_payment_method_title_subscription( $title, $id ) {
856
+
857
+ if ( ! is_checkout() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
858
+ return $title;
859
+ }
860
+
861
+ if ( $title != $this->title || $this->gateway_discount == 0 ) {
862
+ return $title;
863
+ }
864
+
865
+ $total = (float) WC()->cart->subtotal;
866
+ if ( is_numeric( $this->gateway_discount ) ) {
867
+ if ( $this->gateway_discount >= 0 && $this->gateway_discount < 100 ) {
868
+ $price_percent = $this->gateway_discount / 100;
869
+ if ( $price_percent > 0 ) {
870
+ $title .= ' (' . __( 'Discount Of ', 'woocommerce-mercadopago-module' ) .
871
+ strip_tags( wc_price( $total * $price_percent ) ) . ' )';
872
+ }
873
+ }
874
+ }
875
+
876
+ return $title;
877
+ }
878
+
879
+ /*
880
+ * ========================================================================
881
+ * AUXILIARY AND FEEDBACK METHODS (SERVER SIDE)
882
+ * ========================================================================
883
+ */
884
+
885
+ /**
886
+ * Summary: Check if we have valid credentials.
887
+ * Description: Check if we have valid credentials.
888
+ * @return boolean true/false depending on the validation result.
889
+ */
890
+ public function validate_credentials() {
891
+
892
+ if ( empty( $this->client_id ) || empty( $this->client_secret ) ) {
893
+ return false;
894
+ }
895
+
896
+ if ( ! is_numeric( $this->client_id ) ) {
897
+ return false;
898
+ }
899
+
900
+ try {
901
+
902
+ $this->mp = new MP(
903
+ WC_WooMercadoPago_Module::get_module_version(),
904
+ $this->client_id,
905
+ $this->client_secret
906
+ );
907
+ $access_token = $this->mp->get_access_token();
908
+ $get_request = $this->mp->get( '/users/me?access_token=' . $access_token );
909
+
910
+ if ( isset( $get_request['response']['site_id'] ) ) {
911
+
912
+ $s_id = $get_request['response']['site_id'];
913
+ if ( $s_id != 'MLA' && $s_id != 'MLB' && $s_id != 'MLM') {
914
+ $this->mp = null;
915
+ return false;
916
+ }
917
+
918
+ $this->is_test_user = in_array( 'test_user', $get_request['response']['tags'] );
919
+ $this->site_id = $get_request['response']['site_id'];
920
+ $this->country_configs = WC_WooMercadoPago_Module::get_country_config( $this->site_id );
921
+
922
+ $payments = $this->mp->get( '/v1/payment_methods/?access_token=' . $access_token );
923
+ array_push( $this->payment_methods, 'n/d' );
924
+ foreach ( $payments['response'] as $payment ) {
925
+ array_push( $this->payment_methods, str_replace( '_', ' ', $payment['id'] ) );
926
+ }
927
+
928
+ // Check for auto converstion of currency (only if it is enabled).
929
+ $this->currency_ratio = -1;
930
+ if ( $this->currency_conversion == 'yes' ) {
931
+ $this->currency_ratio = WC_WooMercadoPago_Module::get_conversion_rate(
932
+ $this->country_configs['currency']
933
+ );
934
+ }
935
+
936
+ return true;
937
+
938
+ } else {
939
+ $this->mp = null;
940
+ return false;
941
+ }
942
+
943
+ } catch ( MercadoPagoException $e ) {
944
+ if ( 'yes' == $this->debug) {
945
+ $this->log->add(
946
+ $this->id,
947
+ '[validate_credentials] - while validating credentials, got exception: ' .
948
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
949
+ );
950
+ }
951
+ $this->mp = null;
952
+ return false;
953
+ }
954
+
955
+ return false;
956
+
957
+ }
958
+
959
+ // Build the string representing the path to the log file.
960
+ protected function build_log_path_string() {
961
+ return '<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' .
962
+ esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' .
963
+ __( 'WooCommerce &gt; System Status &gt; Logs', 'woocommerce-mercadopago-module' ) . '</a>';
964
+ }
965
+
966
+ // Return boolean indicating if currency is supported.
967
+ protected function is_supported_currency() {
968
+ return get_woocommerce_currency() == $this->country_configs['currency'];
969
+ }
970
+
971
+ // Called automatically by WooCommerce, verify if Module is available to use.
972
+ public function is_available() {
973
+ if ( ! did_action( 'wp_loaded' ) ) {
974
+ return false;
975
+ }
976
+ global $woocommerce;
977
+ $w_cart = $woocommerce->cart;
978
+ // Check for recurrent product checkout.
979
+ if ( isset( $w_cart ) ) {
980
+ if ( ! WC_WooMercadoPago_Module::is_subscription( $w_cart->get_cart() ) ) {
981
+ return false;
982
+ }
983
+ }
984
+ $available = ( 'yes' == $this->settings['enabled'] ) &&
985
+ ! empty( $this->client_id ) &&
986
+ ! empty( $this->client_secret );
987
+ return $available;
988
+ }
989
+
990
+ // Fix css for Mercado Pago in specific cases.
991
+ public function css() {
992
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
993
+ $page_id = wc_get_page_id( 'checkout' );
994
+ } else {
995
+ $page_id = woocommerce_get_page_id( 'checkout' );
996
+ }
997
+ if ( is_page( $page_id ) ) {
998
+ echo '<style type="text/css">#MP-Checkout-dialog { z-index: 9999 !important; }</style>' .
999
+ PHP_EOL;
1000
+ }
1001
+ }
1002
+
1003
+ // Get the URL to admin page.
1004
+ protected function admin_url() {
1005
+ if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
1006
+ return admin_url(
1007
+ 'admin.php?page=wc-settings&tab=checkout&section=WC_WooMercadoPagoSubscription_Gateway'
1008
+ );
1009
+ }
1010
+ return admin_url(
1011
+ 'admin.php?page=woocommerce_settings&tab=payment_gateways&section=WC_WooMercadoPagoSubscription_Gateway'
1012
+ );
1013
+ }
1014
+
1015
+ // Notify that Client_id and/or Client_secret are not valid.
1016
+ public function client_id_or_secret_missing_message() {
1017
+ echo '<div class="error"><p><strong>' .
1018
+ __( 'Subscription is Inactive', 'woocommerce-mercadopago-module' ) .
1019
+ '</strong>: ' .
1020
+ __( 'Your Mercado Pago credentials Client_id/Client_secret appears to be misconfigured.', 'woocommerce-mercadopago-module' ) .
1021
+ '</p></div>';
1022
+ }
1023
+
1024
+ /*
1025
+ * ========================================================================
1026
+ * IPN MECHANICS (SERVER SIDE)
1027
+ * ========================================================================
1028
+ */
1029
+
1030
+ /**
1031
+ * Summary: This call checks any incoming notifications from Mercado Pago server.
1032
+ * Description: This call checks any incoming notifications from Mercado Pago server.
1033
+ */
1034
+ public function check_ipn_response() {
1035
+
1036
+ @ob_clean();
1037
+
1038
+ if ( 'yes' == $this->debug ) {
1039
+ $this->log->add(
1040
+ $this->id,
1041
+ '[check_ipn_response] - received _get content: ' .
1042
+ json_encode( $_GET, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1043
+ );
1044
+ }
1045
+
1046
+ // Setup sandbox mode.
1047
+ $this->mp->sandbox_mode( false );
1048
+
1049
+ // Over here, $_GET should come with this JSON structure:
1050
+ // {
1051
+ // "topic": <string>,
1052
+ // "id": <string>
1053
+ // }
1054
+ // If not, the IPN is corrupted in some way.
1055
+ $data = $_GET;
1056
+ if ( isset( $data['action_mp_payment_id'] ) && isset( $data['action_mp_payment_amount'] ) ) {
1057
+
1058
+ if ( $data['action_mp_payment_action'] === 'cancel' ) {
1059
+
1060
+ if ( 'yes' == $this->debug ) {
1061
+ $this->log->add(
1062
+ $this->id,
1063
+ '[check_ipn_response] - cancelling payment of ID ' . $data['action_mp_payment_id']
1064
+ );
1065
+ }
1066
+
1067
+ if ( $this->mp != null && ! empty( $data['action_mp_payment_id'] ) ) {
1068
+ $response = $this->mp->cancel_payment( $data['action_mp_payment_id'] );
1069
+ $message = $response['response']['message'];
1070
+ $status = $response['status'];
1071
+ if ( 'yes' == $this->debug ) {
1072
+ $this->log->add(
1073
+ $this->id,
1074
+ '[check_ipn_response] - cancel payment of id ' . $data['action_mp_payment_id'] .
1075
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
1076
+ );
1077
+ }
1078
+ if ( $status >= 200 && $status < 300 ) {
1079
+ header( 'HTTP/1.1 200 OK' );
1080
+ echo json_encode( array(
1081
+ 'status' => 200,
1082
+ 'message' => __( 'Operation successfully completed.', 'woocommerce-mercadopago-module' )
1083
+ ) );
1084
+ } else {
1085
+ header( 'HTTP/1.1 200 OK' );
1086
+ echo json_encode( array(
1087
+ 'status' => $status,
1088
+ 'message' => $message
1089
+ ) );
1090
+ }
1091
+ } else {
1092
+ if ( 'yes' == $this->debug ) {
1093
+ $this->log->add(
1094
+ $this->id,
1095
+ '[check_ipn_response] - no payments or credentials invalid'
1096
+ );
1097
+ }
1098
+ header( 'HTTP/1.1 500 OK' );
1099
+ }
1100
+
1101
+ } elseif ( $data['action_mp_payment_action'] === 'refund' ) {
1102
+
1103
+ if ( 'yes' == $this->debug ) {
1104
+ $this->log->add(
1105
+ $this->id,
1106
+ '[check_ipn_response] - refunding payment of ID ' . $data['action_mp_payment_id']
1107
+ );
1108
+ }
1109
+
1110
+ if ( $this->mp != null && ! empty( $data['action_mp_payment_id'] ) ) {
1111
+ $response = $this->mp->partial_refund_payment(
1112
+ $data['action_mp_payment_id'],
1113
+ (float) str_replace( ',', '.', $data['action_mp_payment_amount'] ),
1114
+ // TODO: here, we should improve by placing the actual reason and the external refarence
1115
+ __( 'Refund Payment', 'woocommerce-mercadopago-module' ) . ' ' . $data['action_mp_payment_id'],
1116
+ __( 'Refund Payment', 'woocommerce-mercadopago-module' ) . ' ' . $data['action_mp_payment_id']
1117
+ );
1118
+ $message = $response['response']['message'];
1119
+ $status = $response['status'];
1120
+ if ( 'yes' == $this->debug ) {
1121
+ $this->log->add(
1122
+ $this->id,
1123
+ '[check_ipn_response] - refund payment of id ' . $data['action_mp_payment_id'] .
1124
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
1125
+ );
1126
+ }
1127
+ if ( $status >= 200 && $status < 300 ) {
1128
+ header( 'HTTP/1.1 200 OK' );
1129
+ echo json_encode( array(
1130
+ 'status' => 200,
1131
+ 'message' => __( 'Operation successfully completed.', 'woocommerce-mercadopago-module' )
1132
+ ) );
1133
+ } else {
1134
+ header( 'HTTP/1.1 200 OK' );
1135
+ echo json_encode( array(
1136
+ 'status' => $status,
1137
+ 'message' => $message
1138
+ ) );
1139
+ }
1140
+ } else {
1141
+ if ( 'yes' == $this->debug ) {
1142
+ $this->log->add(
1143
+ $this->id,
1144
+ '[check_ipn_response] - no payments or credentials invalid'
1145
+ );
1146
+ }
1147
+ header( 'HTTP/1.1 500 OK' );
1148
+ }
1149
+
1150
+ }
1151
+
1152
+ } elseif ( isset( $data['id'] ) && isset( $data['topic'] ) ) {
1153
+
1154
+ // We have received a normal IPN call for this gateway, start process by getting the access token...
1155
+ $access_token = array( 'access_token' => $this->mp->get_access_token() );
1156
+
1157
+ // Now, we should handle the topic type that has come...
1158
+ if ( $data['topic'] == 'payment' ) {
1159
+
1160
+ // Get the payment of a preapproval.
1161
+ $payment_info = $this->mp->get( '/v1/payments/' . $data['id'], $access_token, false );
1162
+ if ( ! is_wp_error( $payment_info ) && ( $payment_info['status'] == 200 || $payment_info['status'] == 201 ) ) {
1163
+ $payment_info['response']['ipn_type'] = 'payment';
1164
+ do_action( 'valid_mercadopagosubscription_ipn_request', $payment_info['response'] );
1165
+ header( 'HTTP/1.1 200 OK' );
1166
+ } else {
1167
+ if ( 'yes' == $this->debug) {
1168
+ $this->log->add(
1169
+ $this->id,
1170
+ '[check_ipn_response] - got status not equal 200: ' .
1171
+ json_encode( $payment_info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1172
+ );
1173
+ }
1174
+ return false;
1175
+ }
1176
+
1177
+ } elseif ( $data['topic'] == 'preapproval' ) {
1178
+
1179
+ // Get the preapproval reported by the IPN.
1180
+ $preapproval_info = $this->mp->get_preapproval_payment( $_GET['id'] );
1181
+ if ( ! is_wp_error( $preapproval_info ) && ( $preapproval_info['status'] == 200 || $preapproval_info['status'] == 201 ) ) {
1182
+ $preapproval_info['response']['ipn_type'] = 'preapproval';
1183
+ do_action( 'valid_mercadopagosubscription_ipn_request', $preapproval_info['response'] );
1184
+ header( 'HTTP/1.1 200 OK' );
1185
+ } else {
1186
+ if ( 'yes' == $this->debug ) {
1187
+ $this->log->add(
1188
+ $this->id,
1189
+ '[check_ipn_response] - got status not equal 200: ' .
1190
+ json_encode( $preapproval_info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1191
+ );
1192
+ }
1193
+ }
1194
+
1195
+ } else {
1196
+
1197
+ // We have received an unhandled topic...
1198
+ $this->log->add(
1199
+ $this->id,
1200
+ '[check_ipn_response] - request failure, received an unhandled topic'
1201
+ );
1202
+
1203
+ }
1204
+
1205
+ } elseif ( isset( $data['data_id'] ) && isset( $data['type'] ) ) {
1206
+
1207
+ // We have received a bad, however valid) IPN call for this gateway (data is set for API V1).
1208
+ // At least, we should respond 200 to notify server that we already received it.
1209
+ header( 'HTTP/1.1 200 OK' );
1210
+
1211
+ } else {
1212
+
1213
+ // Reaching here means that we received an IPN call but there are no data!
1214
+ // Just kills the processment. No IDs? No process!
1215
+ if ( 'yes' == $this->debug ) {
1216
+ $this->log->add(
1217
+ $this->id,
1218
+ '[check_ipn_response] - request failure, received ipn call with no data'
1219
+ );
1220
+ }
1221
+ wp_die( __( 'Mercado Pago Request Failure', 'woocommerce-mercadopago-module' ) );
1222
+
1223
+ }
1224
+
1225
+ exit;
1226
+
1227
+ }
1228
+
1229
+ /**
1230
+ * Summary: Properly handles each case of notification, based in payment status.
1231
+ * Description: Properly handles each case of notification, based in payment status.
1232
+ */
1233
+ public function successful_request( $data ) {
1234
+
1235
+ if ( 'yes' == $this->debug ) {
1236
+ $this->log->add(
1237
+ $this->id,
1238
+ '[successful_request] - starting to process ipn update...'
1239
+ );
1240
+ }
1241
+
1242
+ // Get the order and check its presence.
1243
+ $order_key = $data['external_reference'];
1244
+ if ( empty( $order_key ) ) {
1245
+ return;
1246
+ }
1247
+
1248
+ $id = (int) str_replace( $this->invoice_prefix, '', $order_key );
1249
+ $order = wc_get_order( $id );
1250
+
1251
+ // Check if order exists.
1252
+ if ( ! $order ) {
1253
+ return;
1254
+ }
1255
+
1256
+ // WooCommerce 3.0 or later.
1257
+ if ( method_exists( $order, 'get_id' ) ) {
1258
+ $order_id = $order->get_id();
1259
+ } else {
1260
+ $order_id = $order->id;
1261
+ }
1262
+
1263
+ // Check if we have the correct order.
1264
+ if ( $order_id !== $id ) {
1265
+ return;
1266
+ }
1267
+
1268
+ if ( 'yes' == $this->debug ) {
1269
+ $this->log->add(
1270
+ $this->id,
1271
+ '[successful_request] - updating metadata and status with data: ' .
1272
+ json_encode( $data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1273
+ );
1274
+ }
1275
+
1276
+ // WooCommerce 3.0 or later.
1277
+ if ( method_exists( $order, 'update_meta_data' ) ) {
1278
+ $order->update_meta_data( '_used_gateway', 'WC_WooMercadoPagoSubscription_Gateway' );
1279
+
1280
+ // Here, we process the status... this is the business rules!
1281
+ // Reference: https://www.mercadopago.com.br/developers/en/api-docs/basic-checkout/ipn/payment-status/
1282
+ $status = isset( $data['status'] ) ? $data['status'] : 'pending';
1283
+
1284
+ // Updates the order metadata.
1285
+ if ( $data['ipn_type'] == 'payment' ) {
1286
+ $total_paid = isset( $data['transaction_details']['total_paid_amount'] ) ? $data['transaction_details']['total_paid_amount'] : 0.00;
1287
+ $total_refund = isset( $data['transaction_amount_refunded'] ) ? $data['transaction_amount_refunded'] : 0.00;
1288
+ $total = $data['transaction_amount'];
1289
+ if ( ! empty( $data['payer']['email'] ) ) {
1290
+ $order->update_meta_data(
1291
+ __( 'Payer email', 'woocommerce-mercadopago-module' ),
1292
+ $data['payer']['email']
1293
+ );
1294
+ }
1295
+ if ( ! empty( $data['payment_type_id'] ) ) {
1296
+ $order->update_meta_data(
1297
+ __( 'Payment type', 'woocommerce-mercadopago-module' ),
1298
+ $data['payment_type_id']
1299
+ );
1300
+ }
1301
+ if ( ! empty( $data['id'] ) ) {
1302
+ $order->update_meta_data(
1303
+ 'Mercado Pago - Payment ID ' . $data['id'],
1304
+ '[Date ' . date( 'Y-m-d H:i:s', strtotime( $data['date_created'] ) ) .
1305
+ ']/[Amount ' . $total .
1306
+ ']/[Paid ' . $total_paid .
1307
+ ']/[Refund ' . $total_refund . ']'
1308
+ );
1309
+ $payment_ids_str = $order->get_meta( '_Mercado_Pago_Sub_Payment_IDs' );
1310
+ $payment_ids = array();
1311
+ if ( ! empty( $payment_ids_str ) ) {
1312
+ $payment_ids = explode( ', ', $payment_ids_str );
1313
+ }
1314
+ $payment_ids[] = $data['id'];
1315
+ $order->update_meta_data(
1316
+ '_Mercado_Pago_Sub_Payment_IDs',
1317
+ implode( ', ', $payment_ids )
1318
+ );
1319
+ }
1320
+ $order->save();
1321
+ } elseif ( $data['ipn_type'] == 'preapproval' ) {
1322
+ $status = $data['status'];
1323
+ if ( ! empty( $data['payer_email'] ) ) {
1324
+ $order->update_meta_data(
1325
+ __( 'Payer email', 'woocommerce-mercadopago-module' ),
1326
+ $data['payer_email']
1327
+ );
1328
+ }
1329
+ if ( ! empty( $data['id'] ) ) {
1330
+ $order->update_meta_data(
1331
+ 'Mercado Pago Pre-Approval',
1332
+ '[ID ' . $data['id'] .
1333
+ ']/[Date ' . date( 'Y-m-d H:i:s', strtotime( $data['date_created'] ) ) .
1334
+ ']/[Amount ' . $data['auto_recurring']['transaction_amount'] .
1335
+ ']/[End ' . date( 'Y-m-d', strtotime( $data['auto_recurring']['end_date'] ) ) . ']'
1336
+ );
1337
+ }
1338
+
1339
+ $order->save();
1340
+ }
1341
+ } else {
1342
+ update_post_meta( $order->id, '_used_gateway', 'WC_WooMercadoPagoSubscription_Gateway' );
1343
+
1344
+ // Here, we process the status... this is the business rules!
1345
+ // Reference: https://www.mercadopago.com.br/developers/en/api-docs/basic-checkout/ipn/payment-status/
1346
+ $status = isset( $data['status'] ) ? $data['status'] : 'pending';
1347
+
1348
+ // Updates the order metadata.
1349
+ if ( $data['ipn_type'] == 'payment' ) {
1350
+ $total_paid = isset( $data['transaction_details']['total_paid_amount'] ) ? $data['transaction_details']['total_paid_amount'] : 0.00;
1351
+ $total_refund = isset( $data['transaction_amount_refunded'] ) ? $data['transaction_amount_refunded'] : 0.00;
1352
+ $total = $data['transaction_amount'];
1353
+ if ( ! empty( $data['payer']['email'] ) ) {
1354
+ update_post_meta(
1355
+ $order_id,
1356
+ __( 'Payer email', 'woocommerce-mercadopago-module' ),
1357
+ $data['payer']['email']
1358
+ );
1359
+ }
1360
+ if ( ! empty( $data['payment_type_id'] ) ) {
1361
+ update_post_meta(
1362
+ $order_id,
1363
+ __( 'Payment type', 'woocommerce-mercadopago-module' ),
1364
+ $data['payment_type_id']
1365
+ );
1366
+ }
1367
+ if ( ! empty( $data['id'] ) ) {
1368
+ update_post_meta(
1369
+ $order_id,
1370
+ 'Mercado Pago - Payment ID ' . $data['id'],
1371
+ '[Date ' . date( 'Y-m-d H:i:s', strtotime( $data['date_created'] ) ) .
1372
+ ']/[Amount ' . $total .
1373
+ ']/[Paid ' . $total_paid .
1374
+ ']/[Refund ' . $total_refund . ']'
1375
+ );
1376
+ $payment_ids_str = get_post_meta(
1377
+ $order->id,
1378
+ '_Mercado_Pago_Sub_Payment_IDs',
1379
+ true
1380
+ );
1381
+ $payment_ids = array();
1382
+ if ( ! empty( $payment_ids_str ) ) {
1383
+ $payment_ids = explode( ', ', $payment_ids_str );
1384
+ }
1385
+ $payment_ids[] = $data['id'];
1386
+ update_post_meta(
1387
+ $order_id,
1388
+ '_Mercado_Pago_Sub_Payment_IDs',
1389
+ implode( ', ', $payment_ids )
1390
+ );
1391
+ }
1392
+ } elseif ( $data['ipn_type'] == 'preapproval' ) {
1393
+ $status = $data['status'];
1394
+ if ( ! empty( $data['payer_email'] ) ) {
1395
+ update_post_meta(
1396
+ $order_id,
1397
+ __( 'Payer email', 'woocommerce-mercadopago-module' ),
1398
+ $data['payer_email']
1399
+ );
1400
+ }
1401
+ if ( ! empty( $data['id'] ) ) {
1402
+ update_post_meta(
1403
+ $order_id,
1404
+ 'Mercado Pago Pre-Approval',
1405
+ '[ID ' . $data['id'] .
1406
+ ']/[Date ' . date( 'Y-m-d H:i:s', strtotime( $data['date_created'] ) ) .
1407
+ ']/[Amount ' . $data['auto_recurring']['transaction_amount'] .
1408
+ ']/[End ' . date( 'Y-m-d', strtotime( $data['auto_recurring']['end_date'] ) ) . ']'
1409
+ );
1410
+ }
1411
+ }
1412
+ }
1413
+
1414
+ // Switch the status and update in WooCommerce.
1415
+ switch ( $status ) {
1416
+ case 'authorized':
1417
+ case 'approved':
1418
+ $order->add_order_note(
1419
+ 'Mercado Pago: ' .
1420
+ __( 'Payment approved.', 'woocommerce-mercadopago-module' )
1421
+ );
1422
+ $order->payment_complete();
1423
+ break;
1424
+ case 'pending':
1425
+ $order->add_order_note(
1426
+ 'Mercado Pago: ' .
1427
+ __( 'Customer haven\'t paid yet.', 'woocommerce-mercadopago-module' )
1428
+ );
1429
+ break;
1430
+ case 'in_process':
1431
+ $order->update_status(
1432
+ 'on-hold',
1433
+ 'Mercado Pago: ' .
1434
+ __( 'Payment under review.', 'woocommerce-mercadopago-module' )
1435
+ );
1436
+ break;
1437
+ case 'rejected':
1438
+ $order->update_status(
1439
+ 'failed',
1440
+ 'Mercado Pago: ' .
1441
+ __( 'The payment was refused. The customer can try again.', 'woocommerce-mercadopago-module' )
1442
+ );
1443
+ break;
1444
+ case 'refunded':
1445
+ $order->update_status(
1446
+ 'refunded',
1447
+ 'Mercado Pago: ' .
1448
+ __( 'The payment was refunded to the customer.', 'woocommerce-mercadopago-module' )
1449
+ );
1450
+ break;
1451
+ case 'cancelled':
1452
+ $order->update_status(
1453
+ 'cancelled',
1454
+ 'Mercado Pago: ' .
1455
+ __( 'The payment was cancelled.', 'woocommerce-mercadopago-module' )
1456
+ );
1457
+ break;
1458
+ case 'in_mediation':
1459
+ $order->add_order_note(
1460
+ 'Mercado Pago: ' .
1461
+ __( 'The payment is under mediation or it was charged-back.', 'woocommerce-mercadopago-module' )
1462
+ );
1463
+ break;
1464
+ case 'charged-back':
1465
+ $order->add_order_note(
1466
+ 'Mercado Pago: ' .
1467
+ __( 'The payment is under mediation or it was charged-back.', 'woocommerce-mercadopago-module' )
1468
+ );
1469
+ break;
1470
+ default:
1471
+ break;
1472
+ }
1473
+
1474
+ }
1475
+
1476
+ }
mercadopago/mercadopago-ticket-gateway.php CHANGED
@@ -1,113 +1,192 @@
1
  <?php
 
2
  /**
3
  * Part of Woo Mercado Pago Module
4
  * Author - Mercado Pago
5
  * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
6
- * Copyright - Copyright(c) MercadoPago [http://www.mercadopago.com]
7
- * License - http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
8
  */
9
 
10
  // This include Mercado Pago library SDK
11
- require_once "sdk/lib/mercadopago.php";
12
 
13
- // Extending from WooCommerce Payment Gateway class.
14
- // This extension implements the ticket payment method.
 
 
 
15
  class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
16
-
17
- // Sponsor ID array by country
18
- private $sponsor_id = array(
19
- "MLA" => '208682286',
20
- "MLB" => '208686191',
21
- "MCO" => '208687643',
22
- "MLC" => '208690789',
23
- "MPE" => '216998692',
24
- "MLV" => '208692735',
25
- "MLM" => '208692380'
26
- );
27
-
28
- // Required inherited method from WC_Payment_Gateway class: __construct.
29
- // Please check:
30
- // [https://docs.woothemes.com/wc-apidocs/class-WC_Payment_Gateway.html]
31
- // for documentation and further information.
32
- public function __construct() {
33
-
34
- // These fields are declared because we use them dinamically in our gateway class.
35
- $this->domain = get_site_url() . '/index.php';
36
- $this->currency_ratio = -1;
 
 
 
 
 
 
37
  $this->site_id = null;
38
- $this->isTestUser = false;
 
 
 
 
 
39
  $this->payment_methods = array();
 
40
  $this->store_categories_id = array();
41
- $this->store_categories_description = array();
42
-
43
- // Within your constructor, you should define the following variables.
 
44
  $this->id = 'woocommerce-mercadopago-ticket-module';
 
45
  $this->method_title = __( 'Mercado Pago - Ticket', 'woocommerce-mercadopago-module' );
46
  $this->method_description = '<img width="200" height="52" src="' .
47
- plugins_url( 'images/mplogo.png', plugin_dir_path( __FILE__ ) ) . '"><br><br>' . '<strong>' .
48
- wordwrap( __( 'This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store.', 'woocommerce-mercadopago-module' ), 80, "\n" ) .
49
- '</strong>';
50
-
51
- // These fields are used in our Mercado Pago Module configuration page.
 
 
 
 
 
 
52
  $this->access_token = $this->get_option( 'access_token' );
53
  $this->title = $this->get_option( 'title' );
54
  $this->description = $this->get_option( 'description' );
55
  $this->coupon_mode = $this->get_option( 'coupon_mode' );
56
  $this->category_id = $this->get_option( 'category_id' );
57
  $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' );
58
- $this->currency_conversion = $this->get_option('currency_conversion', false);
 
 
59
  $this->debug = $this->get_option( 'debug' );
60
-
 
 
 
 
 
 
 
 
 
61
  // Render our configuration page and init/load fields.
62
  $this->init_form_fields();
63
  $this->init_settings();
64
-
65
- // Hook actions for WordPress.
66
- add_action( // Used by IPN to receive IPN incomings.
67
  'woocommerce_api_wc_woomercadopagoticket_gateway',
68
- array($this, 'process_http_request')
69
  );
70
- add_action( // Used by IPN to process valid incomings.
 
71
  'valid_mercadopagoticket_ipn_request',
72
- array($this, 'successful_request')
 
 
 
 
 
73
  );
74
- add_action( // Used in settings page to hook "save settings" action.
 
75
  'woocommerce_update_options_payment_gateways_' . $this->id,
76
  array( $this, 'process_admin_options' )
77
  );
78
- add_action( // Scripts for custom checkout
 
79
  'wp_enqueue_scripts',
80
- array( $this, 'ticketCheckoutScripts' )
81
  );
82
- add_action( // Apply the discounts
 
83
  'woocommerce_cart_calculate_fees',
84
  array( $this, 'add_discount_ticket' ), 10
85
  );
86
-
87
- // Verify if access token is empty.
88
- if ( empty( $this->access_token ) && $this->enabled == 'yes' ) {
89
- add_action( 'admin_notices', array( $this, 'credentialsMissingMessage' ) );
90
- } else {
91
- add_action( // Verify if SSL is supported.
92
- 'admin_notices', array( $this, 'checkSSLAbsence' )
93
- );
94
- }
 
 
 
 
 
 
95
 
96
- // Logging and debug.
97
- if ( 'yes' == $this->debug ) {
98
- if ( class_exists( 'WC_Logger' ) ) {
99
- $this->log = new WC_Logger();
 
 
 
 
 
100
  } else {
101
- $this->log = WC_MercadoPago_Module::woocommerce_instance()->logger();
 
 
 
 
 
 
 
 
 
102
  }
103
  }
104
-
105
  }
106
-
107
- // Required inherited method from WC_Payment_Gateway class: init_form_fields.
108
- // Initialise Gateway settings form fields with a customized page.
 
 
109
  public function init_form_fields() {
110
-
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  $api_secret_locale = sprintf(
112
  '<a href="https://www.mercadopago.com/mla/account/credentials?type=custom" target="_blank">%s</a>, ' .
113
  '<a href="https://www.mercadopago.com/mlb/account/credentials?type=custom" target="_blank">%s</a>, ' .
@@ -125,84 +204,92 @@ class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
125
  __( 'or', 'woocommerce-mercadopago-module' ),
126
  __( 'Venezuela', 'woocommerce-mercadopago-module' )
127
  );
128
-
129
  // Trigger API to get payment methods and site_id, also validates access_token.
130
- if ( $this->validateCredentials() ) {
131
- try {
132
- // checking the currency
133
- $this->currency_message = "";
134
- if ( !$this->isSupportedCurrency() && 'yes' == $this->settings[ 'enabled' ] ) {
135
- if ( $this->currency_conversion == 'no' ) {
136
- $this->currency_ratio = -1;
137
- $this->currency_message .= '<img width="12" height="12" src="' .
138
- plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' .
139
- ' ' . __( 'ATTENTION: The currency', 'woocommerce-mercadopago-module' ) . ' ' . get_woocommerce_currency() .
140
- ' ' . __( 'defined in WooCommerce is different from the one used in your credentials country.<br>The currency for transactions in this payment method will be', 'woocommerce-mercadopago-module' ) .
141
- ' ' . $this->getCurrencyId( $this->site_id ) . ' (' . $this->getCountryName( $this->site_id ) . ').' .
142
- ' ' . __( 'Currency conversions should be made outside this module.', 'woocommerce-mercadopago-module' );
143
- } else if ( $this->currency_conversion == 'yes' && $this->currency_ratio != -1 ) {
144
- $this->currency_message .= '<img width="12" height="12" src="' .
145
- plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '">' .
146
- ' ' . __( 'CURRENCY CONVERTED: The currency conversion ratio from', 'woocommerce-mercadopago-module' ) . ' ' . get_woocommerce_currency() .
147
- ' ' . __( 'to', 'woocommerce-mercadopago-module' ) . ' ' . $this->getCurrencyId( $this->site_id ) . __( ' is: ', 'woocommerce-mercadopago-module' ) . $this->currency_ratio . ".";
148
- } else {
149
- $this->currency_ratio = -1;
150
- $this->currency_message .= '<img width="12" height="12" src="' .
151
- plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '">' .
152
- ' ' . __( 'ERROR: It was not possible to convert the unsupported currency', 'woocommerce-mercadopago-module' ) . ' ' . get_woocommerce_currency() .
153
- ' ' . __( 'to', 'woocommerce-mercadopago-module' ) . ' ' . $this->getCurrencyId( $this->site_id ) . '.' .
154
- ' ' . __( 'Currency conversions should be made outside this module.', 'woocommerce-mercadopago-module' );
155
- }
156
  } else {
157
  $this->currency_ratio = -1;
 
 
 
 
158
  }
159
- $this->credentials_message = '<img width="12" height="12" src="' .
160
- plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '">' .
161
- ' ' . __( 'Your credentials are <strong>valid</strong> for', 'woocommerce-mercadopago-module' ) .
162
- ': ' . $this->getCountryName( $this->site_id ) . ' <img width="18.6" height="12" src="' .
163
- plugins_url( 'images/' . $this->site_id . '/' . $this->site_id . '.png', plugin_dir_path( __FILE__ ) ) . '"> ';
164
- } catch ( MercadoPagoException $e ) {
165
- $this->credentials_message = '<img width="12" height="12" src="' .
166
- plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '">' .
167
- ' ' . __( 'Your credentials are <strong>not valid</strong>!', 'woocommerce-mercadopago-module' );
168
  }
 
 
 
 
169
  } else {
170
- $this->credentials_message = '<img width="12" height="12" src="' .
171
- plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '">' .
172
- ' ' . __( 'Your credentials are <strong>not valid</strong>!', 'woocommerce-mercadopago-module' );
173
  }
174
-
175
- // Fills categoy selector. We do not need credentials to make this call.
176
- $categories = MPRestClient::get( array( "uri" => "/item_categories" ) );
177
- foreach ( $categories[ "response" ] as $category ) {
178
- array_push( $this->store_categories_id, str_replace( "_", " ", $category[ 'id' ] ) );
179
- array_push( $this->store_categories_description, str_replace( "_", " ", $category[ 'description' ] ) );
 
 
 
 
 
 
 
 
 
 
 
 
180
  }
181
-
182
  // This array draws each UI (text, selector, checkbox, label, etc).
183
  $this->form_fields = array(
184
  'enabled' => array(
185
  'title' => __( 'Enable/Disable', 'woocommerce-mercadopago-module' ),
186
  'type' => 'checkbox',
187
  'label' => __( 'Enable Ticket Payment Method', 'woocommerce-mercadopago-module' ),
188
- 'default' => 'yes'
189
  ),
190
  'credentials_title' => array(
191
  'title' => __( 'Mercado Pago Credentials', 'woocommerce-mercadopago-module' ),
192
  'type' => 'title',
193
- 'description' => sprintf( '%s', $this->credentials_message ) . '<br>' . sprintf( __( 'You can obtain your credentials for', 'woocommerce-mercadopago-module' ) . ' %s.', $api_secret_locale )
 
 
 
194
  ),
195
  'access_token' => array(
196
  'title' => 'Access token',
197
  'type' => 'text',
198
- 'description' => __( 'Insert your Mercado Pago Access token.', 'woocommerce-mercadopago-module' ),
 
199
  'default' => '',
200
  'required' => true
201
  ),
202
  'ipn_url' => array(
203
- 'title' => __( 'Instant Payment Notification (IPN) URL', 'woocommerce-mercadopago-module' ),
 
204
  'type' => 'title',
205
- 'description' => sprintf( __( 'Your IPN URL to receive instant payment notifications is', 'woocommerce-mercadopago-module' ) . '<br>%s', '<code>' . $this->domain . '/woocommerce-mercadopago-module/?wc-api=WC_WooMercadoPagoTicket_Gateway' . '</code>.' )
 
 
 
206
  ),
207
  'checkout_options_title' => array(
208
  'title' => __( 'Ticket Options', 'woocommerce-mercadopago-module' ),
@@ -212,41 +299,63 @@ class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
212
  'title' => array(
213
  'title' => __( 'Title', 'woocommerce-mercadopago-module' ),
214
  'type' => 'text',
215
- 'description' => __( 'Title shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
 
216
  'default' => __( 'Mercado Pago - Ticket', 'woocommerce-mercadopago-module' )
217
  ),
218
  'description' => array(
219
  'title' => __( 'Description', 'woocommerce-mercadopago-module' ),
220
  'type' => 'textarea',
221
- 'description' => __( 'Description shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
 
222
  'default' => __( 'Pay with Mercado Pago', 'woocommerce-mercadopago-module' )
223
  ),
224
  'coupon_mode' => array(
225
- 'title' => __( 'Coupons', 'woocommerce-mercadopago-module' ),
226
- 'type' => 'checkbox',
227
- 'label' => __( 'Enable coupons of discounts', 'woocommerce-mercadopago-module' ),
228
  'default' => 'no',
229
- 'description' => __( 'If there is a Mercado Pago campaign, allow your store to give discounts to customers.', 'woocommerce-mercadopago-module' )
 
230
  ),
231
  'category_id' => array(
232
  'title' => __( 'Store Category', 'woocommerce-mercadopago-module' ),
233
  'type' => 'select',
234
- 'description' => __( 'Define which type of products your store sells.', 'woocommerce-mercadopago-module' ),
 
235
  'options' => $this->store_categories_id
236
  ),
237
  'invoice_prefix' => array(
238
  'title' => __( 'Store Identificator', 'woocommerce-mercadopago-module' ),
239
  'type' => 'text',
240
- 'description' => __( 'Please, inform a prefix to your store.', 'woocommerce-mercadopago-module' ) . ' ' . __( 'If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same identificators.', 'woocommerce-mercadopago-module' ),
 
 
 
241
  'default' => 'WC-'
242
  ),
243
  'currency_conversion' => array(
244
  'title' => __( 'Currency Conversion', 'woocommerce-mercadopago-module' ),
245
  'type' => 'checkbox',
246
- 'label' => __( 'If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio', 'woocommerce-mercadopago-module' ),
 
247
  'default' => 'no',
248
  'description' => sprintf( '%s', $this->currency_message )
249
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  'testing' => array(
251
  'title' => __( 'Test and Debug Options', 'woocommerce-mercadopago-module' ),
252
  'type' => 'title',
@@ -257,42 +366,339 @@ class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
257
  'type' => 'checkbox',
258
  'label' => __( 'Enable log', 'woocommerce-mercadopago-module' ),
259
  'default' => 'no',
260
- 'description' => sprintf( __( 'Register event logs of Mercado Pago, such as API requests, in the file', 'woocommerce-mercadopago-module' ) .
261
- ' %s.', $this->buildLogPathString() . '.<br>' . __( 'File location: ', 'woocommerce-mercadopago-module' ) .
262
- '<code>wordpress/wp-content/uploads/wc-logs/' . $this->id . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log</code>')
 
 
 
263
  )
264
  );
265
-
266
  }
267
-
268
- public function admin_options() {
269
- $this->validate_settings_fields();
270
- if ( count( $this->errors ) > 0 ) {
271
- $this->display_errors();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
273
  } else {
274
- echo wpautop( $this->method_description );
275
- ?>
276
- <p><a href="https://wordpress.org/support/view/plugin-reviews/woo-mercado-pago-module?filter=5#postform" target="_blank" class="button button-primary">
277
- <?php esc_html_e( sprintf( __( 'Please, rate us %s on WordPress.org and give your feedback to help improve this module!', 'woocommerce-mercadopago-module' ), '&#9733;&#9733;&#9733;&#9733;&#9733;' ) ); ?>
278
- </a></p>
279
- <table class="form-table">
280
- <?php $this->generate_settings_html(); ?>
281
- </table>
282
- <?php
283
- return true;
 
 
 
284
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  }
286
-
287
  /*
288
  * ========================================================================
289
- * CHECKOUT BUSINESS RULES
290
  * ========================================================================
291
  */
292
-
293
- public function ticketCheckoutScripts() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  if ( is_checkout() && $this->is_available() ) {
295
- if ( !get_query_var( 'order-received' ) ) {
296
  wp_enqueue_style(
297
  'woocommerce-mercadopago-style', plugins_url(
298
  'assets/css/custom_checkout_mercadopago.css',
@@ -311,397 +717,775 @@ class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
311
  'payment_methods' => $this->payment_methods,
312
  'site_id' => $this->site_id,
313
  'images_path' => plugins_url( 'images/', plugin_dir_path( __FILE__ ) ),
314
- 'amount' => $amount * ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ),
315
  'coupon_mode' => $this->coupon_mode,
316
  'is_currency_conversion' => $this->currency_ratio,
317
  'woocommerce_currency' => get_woocommerce_currency(),
318
- 'account_currency' => $this->getCurrencyId( $this->site_id ),
319
- 'discount_action_url' => $this->domain . '/woocommerce-mercadopago-module/?wc-api=WC_WooMercadoPagoTicket_Gateway',
 
320
  'form_labels' => array(
321
- "form" => array(
322
- "payment_converted" => __("Payment converted from", "woocommerce-mercadopago-module" ),
323
- "to" => __("to", "woocommerce-mercadopago-module" ),
324
- "coupon_empty" => __( "Please, inform your coupon code", "woocommerce-mercadopago-module" ),
325
- 'apply' => __( "Apply", "woocommerce-mercadopago-module" ),
326
- 'remove' => __( "Remove", "woocommerce-mercadopago-module" ),
327
- 'discount_info1' => __( "You will save", "woocommerce-mercadopago-module" ),
328
- 'discount_info2' => __( "with discount from", "woocommerce-mercadopago-module" ),
329
- 'discount_info3' => __( "Total of your purchase:", "woocommerce-mercadopago-module" ),
330
- 'discount_info4' => __( "Total of your purchase with discount:", "woocommerce-mercadopago-module" ),
331
- 'discount_info5' => __( "*Uppon payment approval", "woocommerce-mercadopago-module" ),
332
- 'discount_info6' => __( "Terms and Conditions of Use", "woocommerce-mercadopago-module" ),
333
- 'coupon_of_discounts' => __( "Discount Coupon", "woocommerce-mercadopago-module" ),
334
- 'label_choose' => __( "Choose", "woocommerce-mercadopago-module" ),
335
- "issuer_selection" => __( 'Please, select the ticket issuer of your preference.', 'woocommerce-mercadopago-module' ),
336
- "payment_instructions" => __( 'Click "Place order" button. The ticket will be generated and you will be redirected to print it.', 'woocommerce-mercadopago-module' ),
337
- "ticket_note" => __( 'Important: The order will be confirmed only after the payment approval.', 'woocommerce-mercadopago-module' )
338
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  )
340
  );
341
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
  wc_get_template(
343
  'ticket/ticket-form.php',
344
  $parameters,
345
  'woocommerce/mercadopago/',
346
- WC_WooMercadoPago_Module::getTemplatesPath()
347
  );
348
  }
349
-
350
- // This function is called after we clock on [place_order] button, and each field is passed to this
351
- // function through $_POST variable.
 
 
 
 
352
  public function process_payment( $order_id ) {
353
- $order = new WC_Order( $order_id );
354
- // we have got parameters from checkout page, now its time to charge the card
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  if ( 'yes' == $this->debug ) {
356
- $this->log->add( $this->id, $this->id .
357
- ': @[process_payment] - Received [$_POST] from customer front-end page: ' .
358
- json_encode( $_POST, JSON_PRETTY_PRINT ) );
 
 
359
  }
360
-
361
- if ( isset( $_POST[ 'mercadopago_ticket' ][ 'amount' ] ) && !empty( $_POST[ 'mercadopago_ticket' ][ 'amount' ] ) &&
362
- isset( $_POST[ 'mercadopago_ticket' ][ 'paymentMethodId' ] ) && !empty( $_POST[ 'mercadopago_ticket' ][ 'paymentMethodId' ] ) ) {
363
- return $this->createUrl( $order, $_POST );
364
- } else {
365
- // process when fields are imcomplete
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  wc_add_notice(
367
- '<p>' . __( 'A problem was occurred when processing your payment. Please, try again.', 'woocommerce-mercadopago-module' ) . '</p>',
 
 
368
  'error'
369
  );
370
  return array(
371
- 'result' => 'fail',
372
  'redirect' => '',
373
  );
374
- }
 
375
  }
376
 
377
- protected function createUrl( $order, $post_from_form ) {
 
 
 
 
 
 
378
 
379
- $mp = new MP( $this->access_token );
380
- $mp->sandbox_mode( false );
 
 
381
 
382
- // Creates the order parameters by checking the cart configuration
383
- $preferences = $this->createPreferences( $order, $post_from_form );
384
- try {
385
- // Create order preferences with Mercado Pago API request
386
- $ticket_info = $mp->create_payment( json_encode( $preferences ) );
387
- if ( 'yes' == $this->debug ) {
388
- $this->log->add( $this->id, $this->id .
389
- ': @[createUrl] - Received [$checkout_info] from Mercado Pago API: ' .
390
- json_encode( $ticket_info, JSON_PRETTY_PRINT ) );
391
- }
392
- if ( is_wp_error( $ticket_info ) ||
393
- $ticket_info[ 'status' ] < 200 || $ticket_info[ 'status' ] >= 300 ) {
394
- if ( 'yes' == $this->debug ) {
395
- $this->log->add( $this->id, $this->id .
396
- ': @[createUrl] - payment creation failed with error: ' .
397
- $ticket_info[ 'response' ][ 'status' ] );
398
- }
399
- } else {
400
- $response = $ticket_info[ 'response' ];
401
- if ( array_key_exists( 'status', $response ) ) {
402
- if ( $response[ 'status' ] == "pending" && $response[ 'status_detail' ] == "pending_waiting_payment" ) {
403
- WC()->cart->empty_cart();
404
-
405
- $html = '<p></p><p>' . wordwrap(
406
- __( 'Thank you for your order. Please, pay the ticket to get your order approved.', 'woocommerce-mercadopago-module'),
407
- 60, '<br>') . '</p>';
408
- $html .=
409
- '<a id="submit-payment" target="_blank" href="' . $response[ 'transaction_details' ][ 'external_resource_url' ] . '" class="button alt">' .
410
- __( 'Print the Ticket', 'woocommerce-mercadopago-module' ) .
411
- '</a> ';
412
-
413
- wc_add_notice(
414
- '<p>' . $html . '</p>',
415
- 'notice'
416
- );
417
- $order->add_order_note(
418
- 'Mercado Pago: ' .
419
- __( 'Waiting for the ticket payment.', 'woocommerce-mercadopago-module' )
420
  );
421
- $order->add_order_note(
422
- 'Mercado Pago: ' .
423
- __( 'To reprint the ticket click ', 'woocommerce-mercadopago-module' ) .
424
- '<a href="' . $response[ 'transaction_details' ][ 'external_resource_url' ] . '">' .
425
- __( 'here', 'woocommerce-mercadopago-module' ) .
426
- '</a>'
427
  );
428
-
429
- return array(
430
- 'result' => 'success',
431
- 'redirect' => $order->get_checkout_payment_url( true )
432
  );
433
- }
434
- }
435
- }
436
- } catch ( MercadoPagoException $e ) {
437
- if ( 'yes' == $this->debug ) {
438
- $this->log->add(
439
- $this->id, $this->id .
440
- ': @[createUrl] - payment creation failed with exception: ' .
441
- json_encode( array( "status" => $e->getCode(), "message" => $e->getMessage() ) ) );
442
- }
443
- }
444
- return false;
445
 
446
- }
447
-
448
- private function createPreferences( $order, $post_from_form ) {
 
 
 
 
 
 
 
 
 
449
 
450
- // Here we build the array that contains ordered itens, from customer cart
451
- $items = array();
452
- $purchase_description = "";
453
- if ( sizeof( $order->get_items() ) > 0 ) {
454
- foreach ( $order->get_items() as $item ) {
455
- if ( $item['qty'] ) {
456
- $product = new WC_product( $item[ 'product_id' ] );
457
- $purchase_description =
458
- $purchase_description . ' ' .
459
- ( $product->post->post_title . ' x ' . $item[ 'qty' ] );
460
  array_push( $items, array(
461
- 'id' => $item[ 'product_id' ],
462
- 'title' => ( $product->post->post_title . ' x ' . $item[ 'qty' ] ),
463
- 'description' => sanitize_file_name( (
464
- // This handles description width limit of Mercado Pago
465
- strlen( $product->post->post_content ) > 230 ?
466
- substr( $product->post->post_content, 0, 230 ) . "..." :
467
- $product->post->post_content
468
  ) ),
469
  'picture_url' => wp_get_attachment_url( $product->get_image_id() ),
470
- 'category_id' => $this->store_categories_id[ $this->category_id ],
471
  'quantity' => 1,
472
- 'unit_price' => floor( ( (float) $item[ 'line_total' ] + (float) $item[ 'line_tax' ] ) *
473
- ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ) * 100 ) / 100,
474
- ));
475
  }
476
  }
477
  }
478
-
479
- // Creates the shipment cost structure
480
- $shipping_cost = (float) $order->get_total_shipping();
481
- if ( $shipping_cost > 0 ) {
482
- $item = array(
483
- 'title' => $this->workaroundAmperSandBug( $this->workaroundAmperSandBug( $order->get_shipping_to_display() ) ),
484
- 'description' => __( 'Shipping service used by store', 'woocommerce-mercadopago-module' ),
485
- 'quantity' => 1,
486
- 'category_id' => $this->store_categories_id[ $this->category_id ],
487
- 'unit_price' => $shipping_cost * ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 )
488
- );
489
- $items[] = $item;
490
- }
491
-
492
- // Discounts features
493
- if ( isset( $post_from_form[ 'mercadopago_ticket' ][ 'discount' ] ) &&
494
- $post_from_form[ 'mercadopago_ticket' ][ 'discount' ] != "" &&
495
- $post_from_form[ 'mercadopago_ticket' ][ 'discount' ] > 0 &&
496
- isset( $post_from_form[ 'mercadopago_ticket' ][ 'coupon_code' ] ) &&
497
- $post_from_form[ 'mercadopago_ticket' ][ 'coupon_code' ] != "" &&
498
- WC()->session->chosen_payment_method == "woocommerce-mercadopago-ticket-module" ) {
499
- $item = array(
500
- 'title' => __( 'Discount', 'woocommerce-mercadopago-module' ),
501
- 'description' => __( 'Discount provided by store', 'woocommerce-mercadopago-module' ),
502
- 'quantity' => 1,
503
- 'category_id' => $this->store_categories_id[ $this->category_id ],
504
- 'unit_price' => - ( (float) $post_from_form[ 'mercadopago_ticket' ][ 'discount' ] )
505
- );
506
- $items[] = $item;
507
- }
508
-
509
- // Build additional information from the customer data
510
- $payer_additional_info = array(
511
- 'first_name' => $order->billing_first_name,
512
- 'last_name' => $order->billing_last_name,
513
- //'registration_date' =>
514
- 'phone' => array(
515
- //'area_code' =>
516
- 'number' => $order->billing_phone
517
- ),
518
- 'address' => array(
519
- 'zip_code' => $order->billing_postcode,
520
- //'street_number' =>
521
- 'street_name' => $order->billing_address_1 . ' / ' .
522
- $order->billing_city . ' ' .
523
- $order->billing_state . ' ' .
524
- $order->billing_country
525
- )
526
- );
527
-
528
- // Create the shipment address information set
529
- $shipments = array(
530
- 'receiver_address' => array(
531
- 'zip_code' => $order->shipping_postcode,
532
- //'street_number' =>
533
- 'street_name' => $order->shipping_address_1 . ' ' .
534
- $order->shipping_address_2 . ' ' .
535
- $order->shipping_city . ' ' .
536
- $order->shipping_state . ' ' .
537
- $order->shipping_country,
538
- //'floor' =>
539
- 'apartment' => $order->shipping_address_2
540
- )
541
- );
542
-
543
- // The payment preference
544
- $payment_preference = array (
545
- 'transaction_amount' => floor( ( (float) $post_from_form[ 'mercadopago_ticket' ][ 'amount' ] ) * 100 ) / 100,
546
- 'description' => $purchase_description,
547
- 'payment_method_id' => $post_from_form[ 'mercadopago_ticket' ][ 'paymentMethodId' ],
548
- 'payer' => array(
549
- 'email' => $order->billing_email
550
- ),
551
- 'external_reference' => $this->invoice_prefix . $order->id,
552
- 'additional_info' => array(
553
- 'items' => $items,
554
- 'payer' => $payer_additional_info,
555
- 'shipments' => $shipments
556
- )
557
- );
558
-
559
- // Do not set IPN url if it is a localhost!
560
- $notification_url = $this->domain . '/woocommerce-mercadopago-module/?wc-api=WC_WooMercadoPagoTicket_Gateway';
561
- if ( !strrpos( $notification_url, "localhost" ) ) {
562
- $payment_preference['notification_url'] = $this->workaroundAmperSandBug( $notification_url );
563
- }
564
-
565
- // Discounts features
566
- if ( isset( $post_from_form[ 'mercadopago_ticket' ][ 'discount' ] ) &&
567
- $post_from_form[ 'mercadopago_ticket' ][ 'discount' ] != "" &&
568
- $post_from_form[ 'mercadopago_ticket' ][ 'discount' ] > 0 &&
569
- isset( $post_from_form[ 'mercadopago_ticket' ][ 'coupon_code' ] ) &&
570
- $post_from_form[ 'mercadopago_ticket' ][ 'coupon_code' ] != "" &&
571
- WC()->session->chosen_payment_method == "woocommerce-mercadopago-ticket-module" ) {
572
- $payment_preference[ 'campaign_id' ] = (int) $post_from_form[ 'mercadopago_ticket' ][ 'campaign_id' ];
573
- $payment_preference[ 'coupon_amount' ] = ( (float) $post_from_form[ 'mercadopago_ticket' ][ 'discount' ] );
574
- $payment_preference[ 'coupon_code' ] = strtoupper( $post_from_form[ 'mercadopago_ticket' ][ 'coupon_code' ] );
575
- }
576
-
577
- if ( !$this->isTestUser ) {
578
- $preferences[ 'sponsor_id' ] = (int) ( $this->sponsor_id[ $this->site_id ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579
  }
580
 
581
  if ( 'yes' == $this->debug ) {
582
- $this->log->add( $this->id, $this->id .
583
- ': @[createPreferences] - Returning just created [$payment_preference] structure: ' .
584
- json_encode( $payment_preference, JSON_PRETTY_PRINT ) );
 
 
585
  }
586
 
587
- $payment_preference = apply_filters(
588
- 'woocommerce_mercadopago_module_ticket_preferences',
589
- $payment_preference, $order
590
- );
591
- return $payment_preference;
 
 
 
 
 
 
 
 
592
 
593
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
594
 
595
- public function add_discount_ticket() {
596
  if ( is_admin() && ! defined( 'DOING_AJAX' ) || is_cart() ) {
597
  return;
598
  }
599
- if ( 'yes' == $this->debug ) {
600
- $this->log->add( $this->id, $this->id . ': @[add_discount_ticket] - Ticket trying to apply discount...' );
601
- }
602
- if ( isset( $_POST[ 'mercadopago_ticket' ][ 'discount' ] ) &&
603
- $_POST[ 'mercadopago_ticket' ][ 'discount' ] != "" &&
604
- $_POST[ 'mercadopago_ticket' ][ 'discount' ] > 0 &&
605
- isset( $_POST[ 'mercadopago_ticket' ][ 'coupon_code' ] ) &&
606
- $_POST[ 'mercadopago_ticket' ][ 'coupon_code' ] != "" &&
607
- WC()->session->chosen_payment_method == "woocommerce-mercadopago-ticket-module" ) {
608
- $value = ( $_POST[ 'mercadopago_ticket' ][ 'discount' ] ) /
609
- ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 );
 
 
 
 
 
 
610
  global $woocommerce;
611
- if ( apply_filters( 'wc_mercadopagoticket_module_apply_discount', 0 < $value, $woocommerce->cart ) ) {
612
- $woocommerce->cart->add_fee(
613
- sprintf( __( 'Discount for %s coupon', 'woocommerce-mercadopago-module' ), esc_attr( $_POST[ 'mercadopago_ticket' ][ 'campaign' ] ) ),
614
- ( $value * -1 ), true
 
 
 
 
615
  );
616
  }
617
  }
 
618
  }
619
 
620
- /*
621
- * ========================================================================
622
- * AUXILIARY AND FEEDBACK METHODS
623
- * ========================================================================
624
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
 
626
- // Fix to URL Problem : #038; replaces & and breaks the navigation
627
- function workaroundAmperSandBug( $link ) {
628
- return str_replace('&#038;', '&', $link);
629
  }
630
 
631
- // Check if we have valid credentials.
632
- public function validateCredentials() {
633
- if ( empty( $this->access_token ) ) return false;
634
- if ( strlen( $this->access_token ) > 0 ) {
635
- try {
636
- $mp = new MP( $this->access_token );
637
- $get_request = $mp->get( "/users/me?access_token=" . $this->access_token );
638
- if ( isset( $get_request[ 'response' ][ 'site_id' ] ) ) {
639
- $this->isTestUser = in_array( 'test_user', $get_request[ 'response' ][ 'tags' ] );
640
- $this->site_id = $get_request[ 'response' ][ 'site_id' ];
641
- // get ticket payments
642
- $payments = $mp->get( "/v1/payment_methods/?access_token=" . $this->access_token );
643
- foreach ( $payments[ "response" ] as $payment ) {
644
- if ( $payment[ 'payment_type_id' ] != 'account_money' && $payment[ 'payment_type_id' ] != 'credit_card' &&
645
- $payment[ 'payment_type_id' ] != 'debit_card' && $payment[ 'payment_type_id' ] != 'prepaid_card' ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
646
  array_push( $this->payment_methods, $payment );
647
  }
648
  }
649
- // check for auto converstion of currency
650
- $currency_obj = MPRestClient::get_ml( array( "uri" =>
651
- "/currency_conversions/search?from=" .
652
- get_woocommerce_currency() .
653
- "&to=" .
654
- $this->getCurrencyId( $this->site_id )
655
- ) );
656
- if ( isset( $currency_obj[ 'response' ] ) ) {
657
- $currency_obj = $currency_obj[ 'response' ];
658
- if ( isset( $currency_obj['ratio'] ) ) {
659
- $this->currency_ratio = (float) $currency_obj['ratio'];
660
- } else {
661
- $this->currency_ratio = -1;
662
- }
663
- } else {
664
- $this->currency_ratio = -1;
665
- }
666
- return true;
667
- } else return false;
668
- } catch ( MercadoPagoException $e ) {
669
  return false;
670
  }
 
 
 
 
 
 
 
 
 
 
 
671
  }
 
672
  return false;
 
673
  }
674
 
675
- // Build the string representing the path to the log file
676
- protected function buildLogPathString() {
677
  return '<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' .
678
  esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' .
679
  __( 'WooCommerce &gt; System Status &gt; Logs', 'woocommerce-mercadopago-module' ) . '</a>';
680
  }
681
-
682
  // Return boolean indicating if currency is supported.
683
- protected function isSupportedCurrency() {
684
- return get_woocommerce_currency() == $this->getCurrencyId( $this->site_id );
685
  }
686
 
687
- // Get currency id for a country
688
- protected function getCurrencyId( $site_id ) {
689
- switch ( $site_id ) {
690
- case 'MLA': return 'ARS';
691
- case 'MLB': return 'BRL';
692
- case 'MCO': return 'COP';
693
- case 'MLC': return 'CLP';
694
- case 'MLM': return 'MXN';
695
- case 'MLV': return 'VEF';
696
- case 'MPE': return 'PEN';
697
- default: return '';
698
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
699
  }
700
 
701
- public function checkSSLAbsence() {
702
- if ( empty( $_SERVER[ 'HTTPS' ] ) || $_SERVER[ 'HTTPS' ] == 'off' ) {
703
- if ( 'yes' == $this->settings[ 'enabled' ] ) {
704
- echo '<div class="error"><p><strong>' .
705
  __( 'Ticket is Inactive', 'woocommerce-mercadopago-module' ) .
706
  '</strong>: ' .
707
  sprintf(
@@ -711,17 +1495,6 @@ class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
711
  }
712
  }
713
 
714
- // Called automatically by WooCommerce, verify if Module is available to use.
715
- public function is_available() {
716
- // check SSL connection, as we can't use normal http in custom checkout
717
- if ( empty( $_SERVER[ 'HTTPS' ] ) || $_SERVER[ 'HTTPS' ] == 'off' ) {
718
- return false;
719
- }
720
- $available = ( 'yes' == $this->settings[ 'enabled' ] ) &&
721
- ! empty( $this->access_token );
722
- return $available;
723
- }
724
-
725
  // Get the URL to admin page.
726
  protected function admin_url() {
727
  if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
@@ -735,78 +1508,64 @@ class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
735
  }
736
 
737
  // Notify that access_token are not valid.
738
- public function credentialsMissingMessage() {
739
- echo '<div class="error"><p><strong>' .
740
  __( 'Ticket is Inactive', 'woocommerce-mercadopago-module' ) .
741
  '</strong>: ' .
742
- sprintf(
743
- __( 'Your Mercado Pago credentials Access Token appears to be misconfigured.', 'woocommerce-mercadopago-module' ) . ' %s',
744
- '<a href="' . $this->admin_url() . '">' .
745
- __( 'Click here and configure!', 'woocommerce-mercadopago-module' ) . '</a>' ) .
746
  '</p></div>';
747
  }
748
-
749
- public function getCountryName( $site_id ) {
750
- $country = $site_id;
751
- switch ( $site_id ) {
752
- case 'MLA': return __( 'Argentine', 'woocommerce-mercadopago-module' );
753
- case 'MLB': return __( 'Brazil', 'woocommerce-mercadopago-module' );
754
- case 'MCO': return __( 'Colombia', 'woocommerce-mercadopago-module' );
755
- case 'MLC': return __( 'Chile', 'woocommerce-mercadopago-module' );
756
- case 'MLM': return __( 'Mexico', 'woocommerce-mercadopago-module' );
757
- case 'MLV': return __( 'Venezuela', 'woocommerce-mercadopago-module' );
758
- case 'MPE': return __( 'Peru', 'woocommerce-mercadopago-module' );
759
- }
760
- }
761
-
762
  /*
763
- * ========================================================================
764
- * IPN MECHANICS
765
- * ========================================================================
766
- */
767
-
768
- // [Server Side] This call checks any incoming notifications from Mercado Pago server.
 
 
 
769
  public function process_http_request() {
770
  @ob_clean();
771
  if ( 'yes' == $this->debug ) {
772
- $this->log->add( $this->id, $this->id .
773
- ': @[process_http_request] - Received _get content: ' .
774
- json_encode( $_GET, JSON_PRETTY_PRINT ) );
775
- }
776
- if ( isset( $_GET[ 'coupon_id' ] ) && $_GET[ 'coupon_id' ] != '' ) {
777
- // process coupon evaluations
778
- if ( isset( $_GET[ 'payer' ] ) && $_GET[ 'payer' ] != '' ) {
779
- $logged_user_email = $_GET[ 'payer' ];
780
- $coupon_id = $_GET[ 'coupon_id' ];
781
- $mp = new MP( $this->access_token );
782
- if ( 'yes' == $this->sandbox )
783
- $mp->sandbox_mode( true );
784
- else
785
- $mp->sandbox_mode( false );
786
- $response = $mp->check_discount_campaigns(
787
- $_GET[ 'amount' ],
788
- $logged_user_email,
789
- $coupon_id
790
- );
791
- header( 'HTTP/1.1 200 OK' );
792
- header( 'Content-Type: application/json' );
793
  echo json_encode( $response );
794
  } else {
795
  $obj = new stdClass();
796
  $obj->status = 404;
797
  $obj->response = array(
798
- 'message' => __( 'Please, inform your email in billing address to use this feature', 'woocommerce-mercadopago-module' ),
 
799
  'error' => 'payer_not_found',
800
  'status' => 404,
801
  'cause' => array()
802
  );
803
  header( 'HTTP/1.1 200 OK' );
804
- header( 'Content-Type: application/json' );
805
  echo json_encode( $obj );
806
  }
807
- exit(0);
808
  } else {
809
- // process IPN messages
810
  $data = $this->check_ipn_request_is_valid( $_GET );
811
  if ( $data ) {
812
  header( 'HTTP/1.1 200 OK' );
@@ -814,25 +1573,31 @@ class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
814
  }
815
  }
816
  }
817
-
818
- // Get received data from IPN and checks if we have an associated
819
- // payment. If we have these information, we return data to be
820
- // processed by successful_request function.
 
 
 
821
  public function check_ipn_request_is_valid( $data ) {
822
-
823
- if ( !isset( $data[ 'data_id' ] ) || !isset( $data[ 'type' ] ) ) {
824
  if ( 'yes' == $this->debug ) {
825
- $this->log->add( $this->id, $this->id .
826
- ': @[check_ipn_request_is_valid] - data_id or type not set: ' .
827
- json_encode( $data, JSON_PRETTY_PRINT ) );
 
 
828
  }
829
- // at least, check if its a v0 ipn
830
- if ( !isset( $data[ 'id' ] ) || !isset( $data[ 'topic' ] ) ) {
831
  if ( 'yes' == $this->debug ) {
832
  $this->log->add(
833
- $this->id, $this->id .
834
- ': @[check_ipn_response] - Mercado Pago Request Failure: ' .
835
- json_encode( $_GET, JSON_PRETTY_PRINT ) );
 
836
  }
837
  wp_die( __( 'Mercado Pago Request Failure', 'woocommerce-mercadopago-module' ) );
838
  } else {
@@ -841,21 +1606,26 @@ class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
841
  // No ID? No process!
842
  return false;
843
  }
844
-
845
- $mp = new MP( $this->access_token );
846
- $mp->sandbox_mode( false );
847
  try {
848
- $access_token = array( "access_token" => $mp->get_access_token() );
849
- if ( $data[ "type" ] == 'payment' ) {
850
- $payment_info = $mp->get( "/v1/payments/" . $data[ "data_id" ], $access_token, false );
851
- if ( !is_wp_error( $payment_info ) &&
852
- ( $payment_info[ "status" ] == 200 || $payment_info[ "status" ] == 201 ) ) {
853
- return $payment_info[ 'response' ];
 
 
 
854
  } else {
855
  if ( 'yes' == $this->debug ) {
856
- $this->log->add( $this->id, $this->id .
857
- ': @[check_ipn_request_is_valid] - error when processing received data: ' .
858
- json_encode( $payment_info, JSON_PRETTY_PRINT ) );
 
 
859
  }
860
  return false;
861
  }
@@ -863,119 +1633,199 @@ class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
863
  } catch ( MercadoPagoException $e ) {
864
  if ( 'yes' == $this->debug ) {
865
  $this->log->add(
866
- $this->id, $this->id .
867
- ': @[check_ipn_request_is_valid] - MercadoPagoException: ' .
868
- json_encode( array( "status" => $e->getCode(), "message" => $e->getMessage() ) ) );
 
869
  }
870
  return false;
871
  }
872
  return true;
873
  }
874
-
875
- // Properly handles each case of notification, based in payment status.
 
 
 
876
  public function successful_request( $data ) {
 
877
  if ( 'yes' == $this->debug ) {
878
- $this->log->add( $this->id, $this->id .
879
- ': @[successful_request] - starting to process ipn update...' );
880
- }
881
- $order_key = $data[ 'external_reference' ];
882
- if ( !empty( $order_key ) ) {
883
- $order_id = (int) str_replace( $this->invoice_prefix, '', $order_key );
884
- $order = new WC_Order( $order_id );
885
- // Checks whether the invoice number matches the order, if true processes the payment
886
- if ( $order->id === $order_id ) {
887
- if ( 'yes' == $this->debug ) {
888
- $this->log->add( $this->id, $this->id .
889
- ': @[successful_request] - got order with ID ' . $order->id .
890
- ' and status ' . $data[ 'status' ] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
891
  }
892
- // Order details.
893
- if ( !empty( $data[ 'payer' ][ 'email' ] ) ) {
894
- update_post_meta(
895
- $order_id,
896
- __( 'Payer email',
897
- 'woocommerce-mercadopago-module' ),
898
- $data[ 'payer' ][ 'email' ]
899
- );
900
  }
901
- if ( !empty( $data[ 'payment_type_id' ] ) ) {
902
- update_post_meta(
903
- $order_id,
904
- __( 'Payment type',
905
- 'woocommerce-mercadopago-module' ),
906
- $data[ 'payment_type_id' ]
907
  );
908
- }
909
- if ( !empty( $data ) ) {
910
- update_post_meta(
911
- $order_id,
912
- __( 'Mercado Pago Payment ID',
913
- 'woocommerce-mercadopago-module' ),
914
- $data[ 'id' ]
915
  );
916
  }
917
- // Switch the status and update in WooCommerce
918
- switch ( $data[ 'status' ] ) {
919
- case 'approved':
920
- $order->add_order_note(
921
- 'Mercado Pago: ' . __( 'Payment approved.',
922
- 'woocommerce-mercadopago-module' )
923
- );
924
- $order->payment_complete();
925
- break;
926
- case 'pending':
927
- $order->add_order_note(
928
- 'Mercado Pago: ' . __( 'Customer haven\'t paid yet.',
929
- 'woocommerce-mercadopago-module' )
930
- );
931
- break;
932
- case 'in_process':
933
- $order->update_status(
934
- 'on-hold',
935
- 'Mercado Pago: ' . __( 'Payment under review.',
936
- 'woocommerce-mercadopago-module' )
937
- );
938
- break;
939
- case 'rejected':
940
- $order->update_status(
941
- 'failed',
942
- 'Mercado Pago: ' . __( 'The payment was refused. The customer can try again.',
943
- 'woocommerce-mercadopago-module' )
944
- );
945
- break;
946
- case 'refunded':
947
- $order->update_status(
948
- 'refunded',
949
- 'Mercado Pago: ' . __( 'The payment was refunded to the customer.',
950
- 'woocommerce-mercadopago-module' )
951
- );
952
- break;
953
- case 'cancelled':
954
- $order->update_status(
955
- 'cancelled',
956
- 'Mercado Pago: ' . __( 'The payment was cancelled.',
957
- 'woocommerce-mercadopago-module' )
958
- );
959
- break;
960
- case 'in_mediation':
961
- $order->add_order_note(
962
- 'Mercado Pago: ' . __( 'The payment is under mediation or it was charged-back.',
963
- 'woocommerce-mercadopago-module' )
964
- );
965
- break;
966
- case 'charged-back':
967
- $order->add_order_note(
968
- 'Mercado Pago: ' . __( 'The payment is under mediation or it was charged-back.',
969
- 'woocommerce-mercadopago-module' )
970
- );
971
- break;
972
- default:
973
- break;
974
- }
975
- }
976
  }
977
  }
978
-
979
  }
980
 
981
- new WC_WooMercadoPagoTicket_Gateway();
1
  <?php
2
+
3
  /**
4
  * Part of Woo Mercado Pago Module
5
  * Author - Mercado Pago
6
  * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
7
+ * Copyright - Copyright(c) MercadoPago [https://www.mercadopago.com]
8
+ * License - https://www.gnu.org/licenses/gpl.html GPL version 2 or higher
9
  */
10
 
11
  // This include Mercado Pago library SDK
12
+ require_once dirname( __FILE__ ) . '/sdk/lib/mercadopago.php';
13
 
14
+ /**
15
+ * Summary: Extending from WooCommerce Payment Gateway class.
16
+ * Description: This class implements Mercado Pago ticket payment method.
17
+ * @since 2.0.0
18
+ */
19
  class WC_WooMercadoPagoTicket_Gateway extends WC_Payment_Gateway {
20
+
21
+ public function __construct( $is_instance = false ) {
22
+
23
+ // Creating PHP version message.
24
+ $min_php_message = phpversion() >= WC_WooMercadoPago_Module::MIN_PHP ?
25
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
26
+ __( 'Your PHP version is OK.', 'woocommerce-mercadopago-module' ) :
27
+ '<img width="14" height="14" src="' . plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
28
+ sprintf(
29
+ __( 'Your PHP version do not support this module. You have %s, minimal required is %s.', 'woocommerce-mercadopago-module' ),
30
+ phpversion(), WC_WooMercadoPago_Module::MIN_PHP
31
+ );
32
+ // Check cURL.
33
+ $curl_message = in_array( 'curl', get_loaded_extensions() ) ?
34
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
35
+ __( 'cURL is installed.', 'woocommerce-mercadopago-module' ) :
36
+ '<img width="14" height="14" src="' . plugins_url( 'images/error.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
37
+ __( 'cURL is not installed.', 'woocommerce-mercadopago-module' );
38
+ // Check SSL.
39
+ $is_ssl_message = empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ?
40
+ '<img width="14" height="14" src="' . plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
41
+ __( 'SSL is missing in your site.', 'woocommerce-mercadopago-module' ) :
42
+ '<img width="14" height="14" src="' . plugins_url( 'images/check.png', plugin_dir_path( __FILE__ ) ) . '"> ' .
43
+ __( 'Your site has SSL enabled.', 'woocommerce-mercadopago-module' );
44
+
45
+ // Mercado Pago fields.
46
+ $this->mp = null;
47
  $this->site_id = null;
48
+ $this->collector_id = null;
49
+ $this->currency_ratio = -1;
50
+ $this->is_test_user = false;
51
+
52
+ // Auxiliary fields.
53
+ $this->currency_message = '';
54
  $this->payment_methods = array();
55
+ $this->country_configs = array();
56
  $this->store_categories_id = array();
57
+ $this->store_categories_description = array();
58
+
59
+ // WooCommerce fields.
60
+ $this->supports = array( 'products', 'refunds' );
61
  $this->id = 'woocommerce-mercadopago-ticket-module';
62
+ $this->domain = get_site_url() . '/index.php';
63
  $this->method_title = __( 'Mercado Pago - Ticket', 'woocommerce-mercadopago-module' );
64
  $this->method_description = '<img width="200" height="52" src="' .
65
+ plugins_url(
66
+ 'images/mplogo.png',
67
+ plugin_dir_path( __FILE__ )
68
+ ) . '"><br><br>' . '<strong>' .
69
+ __( 'This module enables WooCommerce to use Mercado Pago as payment method for purchases made in your virtual store.', 'woocommerce-mercadopago-module' ) .
70
+ '</strong>' . '<br><br>' .
71
+ $min_php_message . '<br>' .
72
+ $is_ssl_message . '<br>' .
73
+ $curl_message;
74
+
75
+ // Fields used in Mercado Pago Module configuration page.
76
  $this->access_token = $this->get_option( 'access_token' );
77
  $this->title = $this->get_option( 'title' );
78
  $this->description = $this->get_option( 'description' );
79
  $this->coupon_mode = $this->get_option( 'coupon_mode' );
80
  $this->category_id = $this->get_option( 'category_id' );
81
  $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' );
82
+ $this->currency_conversion = $this->get_option( 'currency_conversion', false );
83
+ $this->gateway_discount = $this->get_option( 'gateway_discount', 0 );
84
+ $this->reduce_stock_on_order_gen = $this->get_option( 'reduce_stock_on_order_gen', false );
85
  $this->debug = $this->get_option( 'debug' );
86
+
87
+ // Logging and debug.
88
+ if ( 'yes' == $this->debug ) {
89
+ if ( class_exists( 'WC_Logger' ) ) {
90
+ $this->log = new WC_Logger();
91
+ } else {
92
+ $this->log = WC_MercadoPago_Module::woocommerce_instance()->logger();
93
+ }
94
+ }
95
+
96
  // Render our configuration page and init/load fields.
97
  $this->init_form_fields();
98
  $this->init_settings();
99
+
100
+ // Used by IPN to receive IPN incomings.
101
+ add_action(
102
  'woocommerce_api_wc_woomercadopagoticket_gateway',
103
+ array( $this, 'process_http_request' )
104
  );
105
+ // Used by IPN to process valid incomings.
106
+ add_action(
107
  'valid_mercadopagoticket_ipn_request',
108
+ array( $this, 'successful_request' )
109
+ );
110
+ // process the cancel order meta box order action
111
+ add_action(
112
+ 'woocommerce_order_action_cancel_order',
113
+ array( $this, 'process_cancel_order_meta_box_actions' )
114
  );
115
+ // Used in settings page to hook "save settings" action.
116
+ add_action(
117
  'woocommerce_update_options_payment_gateways_' . $this->id,
118
  array( $this, 'process_admin_options' )
119
  );
120
+ // Scripts for custom checkout.
121
+ add_action(
122
  'wp_enqueue_scripts',
123
+ array( $this, 'ticket_checkout_scripts' )
124
  );
125
+ // Apply the discounts.
126
+ add_action(
127
  'woocommerce_cart_calculate_fees',
128
  array( $this, 'add_discount_ticket' ), 10
129
  );
130
+ // Used in settings page to hook "save settings" action.
131
+ add_action(
132
+ 'woocommerce_update_options_payment_gateways_' . $this->id,
133
+ array( $this, 'custom_process_admin_options' )
134
+ );
135
+ // Display discount in payment method title.
136
+ add_filter(
137
+ 'woocommerce_gateway_title',
138
+ array( $this, 'get_payment_method_title_ticket' ), 10, 2
139
+ );
140
+ // Customizes thank you page.
141
+ add_filter(
142
+ 'woocommerce_thankyou_order_received_text',
143
+ array( $this, 'show_ticket_button' ), 10, 2
144
+ );
145
 
146
+ if ( ! empty( $this->settings['enabled'] ) && $this->settings['enabled'] == 'yes' ) {
147
+ if ( $is_instance ) {
148
+ if ( empty( $this->access_token ) ) {
149
+ // Verify if access token is empty.
150
+ add_action( 'admin_notices', array( $this, 'credentials_missing_message' ) );
151
+ } else {
152
+ // Verify if SSL is supported.
153
+ add_action( 'admin_notices', array( $this, 'check_ssl_absence' ) );
154
+ }
155
  } else {
156
+ // Scripts for order configuration.
157
+ add_action(
158
+ 'woocommerce_after_checkout_form',
159
+ array( $this, 'add_checkout_script' )
160
+ );
161
+ // Checkout updates.
162
+ add_action(
163
+ 'woocommerce_thankyou',
164
+ array( $this, 'update_checkout_status' )
165
+ );
166
  }
167
  }
168
+
169
  }
170
+
171
+ /**
172
+ * Summary: Initialise Gateway Settings Form Fields.
173
+ * Description: Initialise Gateway settings form fields with a customized page.
174
+ */
175
  public function init_form_fields() {
176
+
177
+ // If module is disabled, we do not need to load and process the settings page.
178
+ if ( empty( $this->settings['enabled'] ) || 'no' == $this->settings['enabled'] ) {
179
+ $this->form_fields = array(
180
+ 'enabled' => array(
181
+ 'title' => __( 'Enable/Disable', 'woocommerce-mercadopago-module' ),
182
+ 'type' => 'checkbox',
183
+ 'label' => __( 'Enable Ticket Payment Method', 'woocommerce-mercadopago-module' ),
184
+ 'default' => 'no'
185
+ )
186
+ );
187
+ return;
188
+ }
189
+
190
  $api_secret_locale = sprintf(
191
  '<a href="https://www.mercadopago.com/mla/account/credentials?type=custom" target="_blank">%s</a>, ' .
192
  '<a href="https://www.mercadopago.com/mlb/account/credentials?type=custom" target="_blank">%s</a>, ' .
204
  __( 'or', 'woocommerce-mercadopago-module' ),
205
  __( 'Venezuela', 'woocommerce-mercadopago-module' )
206
  );
207
+
208
  // Trigger API to get payment methods and site_id, also validates access_token.
209
+ if ( $this->validate_credentials() ) {
210
+ // checking the currency
211
+ $this->currency_message = '';
212
+ if ( ! $this->is_supported_currency() && 'yes' == $this->settings['enabled'] ) {
213
+ if ( $this->currency_conversion == 'no' ) {
214
+ $this->currency_ratio = -1;
215
+ $this->currency_message .= WC_WooMercadoPago_Module::build_currency_not_converted_msg(
216
+ $this->country_configs['currency'],
217
+ $this->country_configs['country_name']
218
+ );
219
+ } elseif ( $this->currency_conversion == 'yes' && $this->currency_ratio != -1 ) {
220
+ $this->currency_message .= WC_WooMercadoPago_Module::build_currency_converted_msg(
221
+ $this->country_configs['currency'],
222
+ $this->currency_ratio
223
+ );
 
 
 
 
 
 
 
 
 
 
 
224
  } else {
225
  $this->currency_ratio = -1;
226
+ $this->currency_message .=
227
+ WC_WooMercadoPago_Module::build_currency_conversion_err_msg(
228
+ $this->country_configs['currency']
229
+ );
230
  }
231
+ } else {
232
+ $this->currency_ratio = -1;
 
 
 
 
 
 
 
233
  }
234
+ $this->credentials_message = WC_WooMercadoPago_Module::build_valid_credentials_msg(
235
+ $this->country_configs['country_name'],
236
+ $this->site_id
237
+ );
238
  } else {
239
+ $this->credentials_message = WC_WooMercadoPago_Module::build_invalid_credentials_msg();
 
 
240
  }
241
+
242
+ // fill categories (can be handled without credentials).
243
+ $categories = WC_WooMercadoPago_Module::get_categories();
244
+ $this->store_categories_id = $categories['store_categories_id'];
245
+ $this->store_categories_description = $categories['store_categories_description'];
246
+
247
+ // Validate discount field.
248
+ if ( ! is_numeric( $this->gateway_discount ) ) {
249
+ $this->gateway_discount_desc = '<img width="12" height="12" src="' .
250
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
251
+ __( 'This field should be an integer greater or equal 0 and smaller than 100.', 'woocommerce-mercadopago-module' );
252
+ } elseif ( $this->gateway_discount < 0 || $this->gateway_discount >= 100 ) {
253
+ $this->gateway_discount_desc = '<img width="12" height="12" src="' .
254
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
255
+ __( 'This field should be an integer greater or equal 0 and smaller than 100.', 'woocommerce-mercadopago-module' );
256
+ } else {
257
+ $this->gateway_discount_desc =
258
+ __( 'Give a percentual discount for your customers if they use this payment gateway.', 'woocommerce-mercadopago-module' );
259
  }
260
+
261
  // This array draws each UI (text, selector, checkbox, label, etc).
262
  $this->form_fields = array(
263
  'enabled' => array(
264
  'title' => __( 'Enable/Disable', 'woocommerce-mercadopago-module' ),
265
  'type' => 'checkbox',
266
  'label' => __( 'Enable Ticket Payment Method', 'woocommerce-mercadopago-module' ),
267
+ 'default' => 'no'
268
  ),
269
  'credentials_title' => array(
270
  'title' => __( 'Mercado Pago Credentials', 'woocommerce-mercadopago-module' ),
271
  'type' => 'title',
272
+ 'description' => sprintf( '%s', $this->credentials_message ) . '<br>' . sprintf(
273
+ __( 'You can obtain your credentials for', 'woocommerce-mercadopago-module' ) .
274
+ ' %s.', $api_secret_locale
275
+ )
276
  ),
277
  'access_token' => array(
278
  'title' => 'Access token',
279
  'type' => 'text',
280
+ 'description' =>
281
+ __( 'Insert your Mercado Pago Access token.', 'woocommerce-mercadopago-module' ),
282
  'default' => '',
283
  'required' => true
284
  ),
285
  'ipn_url' => array(
286
+ 'title' =>
287
+ __( 'Instant Payment Notification (IPN) URL', 'woocommerce-mercadopago-module' ),
288
  'type' => 'title',
289
+ 'description' => sprintf(
290
+ __( 'Your IPN URL to receive instant payment notifications is', 'woocommerce-mercadopago-module' ) .
291
+ '<br>%s', '<code>' . WC()->api_request_url( 'WC_WooMercadoPagoTicket_Gateway' ) . '</code>.'
292
+ )
293
  ),
294
  'checkout_options_title' => array(
295
  'title' => __( 'Ticket Options', 'woocommerce-mercadopago-module' ),
299
  'title' => array(
300
  'title' => __( 'Title', 'woocommerce-mercadopago-module' ),
301
  'type' => 'text',
302
+ 'description' =>
303
+ __( 'Title shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
304
  'default' => __( 'Mercado Pago - Ticket', 'woocommerce-mercadopago-module' )
305
  ),
306
  'description' => array(
307
  'title' => __( 'Description', 'woocommerce-mercadopago-module' ),
308
  'type' => 'textarea',
309
+ 'description' =>
310
+ __( 'Description shown to the client in the checkout.', 'woocommerce-mercadopago-module' ),
311
  'default' => __( 'Pay with Mercado Pago', 'woocommerce-mercadopago-module' )
312
  ),
313
  'coupon_mode' => array(
314
+ 'title' => __( 'Coupons', 'woocommerce-mercadopago-module' ),
315
+ 'type' => 'checkbox',
316
+ 'label' => __( 'Enable coupons of discounts', 'woocommerce-mercadopago-module' ),
317
  'default' => 'no',
318
+ 'description' =>
319
+ __( 'If there is a Mercado Pago campaign, allow your store to give discounts to customers.', 'woocommerce-mercadopago-module' )
320
  ),
321
  'category_id' => array(
322
  'title' => __( 'Store Category', 'woocommerce-mercadopago-module' ),
323
  'type' => 'select',
324
+ 'description' =>
325
+ __( 'Define which type of products your store sells.', 'woocommerce-mercadopago-module' ),
326
  'options' => $this->store_categories_id
327
  ),
328
  'invoice_prefix' => array(
329
  'title' => __( 'Store Identificator', 'woocommerce-mercadopago-module' ),
330
  'type' => 'text',
331
+ 'description' =>
332
+ __( 'Please, inform a prefix to your store.', 'woocommerce-mercadopago-module' )
333
+ . ' ' .
334
+ __( 'If you use your Mercado Pago account on multiple stores you should make sure that this prefix is unique as Mercado Pago will not allow orders with same identificators.', 'woocommerce-mercadopago-module' ),
335
  'default' => 'WC-'
336
  ),
337
  'currency_conversion' => array(
338
  'title' => __( 'Currency Conversion', 'woocommerce-mercadopago-module' ),
339
  'type' => 'checkbox',
340
+ 'label' =>
341
+ __( 'If the used currency in WooCommerce is different or not supported by Mercado Pago, convert values of your transactions using Mercado Pago currency ratio.', 'woocommerce-mercadopago-module' ),
342
  'default' => 'no',
343
  'description' => sprintf( '%s', $this->currency_message )
344
  ),
345
+ 'reduce_stock_on_order_gen' => array(
346
+ 'title' => __( 'Stock Reduce', 'woocommerce-mercadopago-module' ),
347
+ 'type' => 'checkbox',
348
+ 'label' =>
349
+ __( 'Reduce Stock in Order Generation', 'woocommerce-mercadopago-module' ),
350
+ 'default' => 'no',
351
+ 'description' => __( 'Enable this to reduce the stock on order creation. Disable this to reduce <strong>after</strong> the payment approval.', 'woocommerce-mercadopago-module' )
352
+ ),
353
+ 'gateway_discount' => array(
354
+ 'title' => __( 'Discount by Gateway', 'woocommerce-mercadopago-module' ),
355
+ 'type' => 'number',
356
+ 'description' => $this->gateway_discount_desc,
357
+ 'default' => '0'
358
+ ),
359
  'testing' => array(
360
  'title' => __( 'Test and Debug Options', 'woocommerce-mercadopago-module' ),
361
  'type' => 'title',
366
  'type' => 'checkbox',
367
  'label' => __( 'Enable log', 'woocommerce-mercadopago-module' ),
368
  'default' => 'no',
369
+ 'description' => sprintf(
370
+ __( 'Register event logs of Mercado Pago, such as API requests, in the file', 'woocommerce-mercadopago-module' ) .
371
+ ' %s.', $this->build_log_path_string() . '.<br>' .
372
+ __( 'File location: ', 'woocommerce-mercadopago-module' ) .
373
+ '<code>wordpress/wp-content/uploads/wc-logs/' . $this->id . '-' .
374
+ sanitize_file_name( wp_hash( $this->id ) ) . '.log</code>' )
375
  )
376
  );
377
+
378
  }
379
+
380
+ /**
381
+ * Processes and saves options.
382
+ * If there is an error thrown, will continue to save and validate fields, but will leave the
383
+ * erroring field out.
384
+ * @return bool was anything saved?
385
+ */
386
+ public function custom_process_admin_options() {
387
+ $this->init_settings();
388
+
389
+ $post_data = $this->get_post_data();
390
+
391
+ foreach ( $this->get_form_fields() as $key => $field ) {
392
+ if ( 'title' !== $this->get_field_type( $field ) ) {
393
+ try {
394
+ $this->settings[$key] = $this->get_field_value( $key, $field, $post_data );
395
+ } catch ( Exception $e ) {
396
+ $this->add_error( $e->getMessage() );
397
+ }
398
+ }
399
+ }
400
+
401
+ if ( ! empty( $this->settings['access_token'] ) ) {
402
+ $this->mp = new MP(
403
+ WC_WooMercadoPago_Module::get_module_version(),
404
+ $this->settings['access_token']
405
+ );
406
+ } else {
407
+ $this->mp = null;
408
+ }
409
+
410
+ // analytics
411
+ if ( $this->mp != null && ! $this->is_test_user ) {
412
+ $infra_data = WC_WooMercadoPago_Module::get_common_settings();
413
+ $infra_data['checkout_custom_ticket'] = ( $this->settings['enabled'] == 'yes' ? 'true' : 'false' );
414
+ $infra_data['checkout_custom_ticket_coupon'] = ( $this->settings['coupon_mode'] == 'yes' ? 'true' : 'false' );
415
+ $response = $this->mp->analytics_save_settings( $infra_data );
416
+ if ( 'yes' == $this->debug) {
417
+ $this->log->add(
418
+ $this->id,
419
+ '[custom_process_admin_options] - analytics info response: ' .
420
+ json_encode( $response, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
421
+ );
422
+ }
423
+ }
424
+
425
+ return update_option(
426
+ $this->get_option_key(),
427
+ apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->settings )
428
+ );
429
+ }
430
+
431
+ /**
432
+ * Handles the manual order refunding in server-side.
433
+ */
434
+ public function process_refund( $order_id, $amount = null, $reason = '' ) {
435
+
436
+ $payments = get_post_meta(
437
+ $order_id,
438
+ '_Mercado_Pago_Payment_IDs',
439
+ true
440
+ );
441
+
442
+ // Validate.
443
+ if ( $this->mp == null || empty( $payments ) ) {
444
+ if ( 'yes' == $this->debug ) {
445
+ $this->log->add(
446
+ $this->id,
447
+ '[process_refund] - no payments or credentials invalid'
448
+ );
449
+ }
450
  return false;
451
+ }
452
+
453
+ $total_available = 0;
454
+ $payment_structs = array();
455
+ $payment_ids = explode( ', ', $payments );
456
+ foreach ( $payment_ids as $p_id ) {
457
+ $p = get_post_meta(
458
+ $order_id,
459
+ 'Mercado Pago - Payment ' . $p_id,
460
+ true
461
+ );
462
+ $p = explode( '/', $p );
463
+ $paid_arr = explode( ' ', substr( $p[2], 1, -1 ) );
464
+ $paid = ( (float) $paid_arr[1] );
465
+ $refund_arr = explode( ' ', substr( $p[3], 1, -1 ) );
466
+ $refund = ( (float) $refund_arr[1] );
467
+ $p_struct = array(
468
+ 'id' => $p_id,
469
+ 'available_to_refund' => $paid - $refund
470
+ );
471
+ $total_available += $paid - $refund;
472
+ $payment_structs[] = $p_struct;
473
+ }
474
+
475
+ if ( 'yes' == $this->debug ) {
476
+ $this->log->add(
477
+ $this->id,
478
+ '[process_refund] - refunding ' . $amount . ' because of ' . $reason . ' and payments ' .
479
+ json_encode( $payment_structs, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
480
+ );
481
+ }
482
+
483
+ // Do not allow refund more than available or invalid amounts.
484
+ if ( $amount > $total_available || $amount <= 0 ) {
485
+ return false;
486
+ }
487
+
488
+ $remaining_to_refund = $amount;
489
+ foreach ( $payment_structs as $to_refund ) {
490
+ if ( $remaining_to_refund <= $to_refund['available_to_refund'] ) {
491
+ // We want to refund an amount that is less than the available for this payment, so we
492
+ // can just refund and return.
493
+ $response = $this->mp->partial_refund_payment(
494
+ $to_refund['id'],
495
+ $remaining_to_refund,
496
+ $reason,
497
+ $this->invoice_prefix . $order_id
498
+ );
499
+ $message = $response['response']['message'];
500
+ $status = $response['status'];
501
+ if ( 'yes' == $this->debug ) {
502
+ $this->log->add(
503
+ $this->id,
504
+ '[process_refund] - refund payment of id ' . $p_id .
505
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
506
+ );
507
+ }
508
+ if ( $status >= 200 && $status < 300 ) {
509
+ return true;
510
+ } else {
511
+ return false;
512
+ }
513
+ } elseif ( $to_refund['available_to_refund'] > 0 ) {
514
+ // We want to refund an amount that exceeds the available for this payment, so we
515
+ // totally refund this payment, and try to complete refund in other/next payments.
516
+ $response = $this->mp->partial_refund_payment(
517
+ $to_refund['id'],
518
+ $to_refund['available_to_refund'],
519
+ $reason,
520
+ $this->invoice_prefix . $order_id
521
+ );
522
+ $message = $response['response']['message'];
523
+ $status = $response['status'];
524
+ if ( 'yes' == $this->debug ) {
525
+ $this->log->add(
526
+ $this->id,
527
+ '[process_refund] - refund payment of id ' . $p_id .
528
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
529
+ );
530
+ }
531
+ if ( $status < 200 || $status >= 300 ) {
532
+ return false;
533
+ }
534
+ $remaining_to_refund -= $to_refund['available_to_refund'];
535
+ }
536
+ if ( $remaining_to_refund == 0 )
537
+ return true;
538
+ }
539
+
540
+ // Reaching here means that there we run out of payments, and there is an amount
541
+ // remaining to be refund, which is impossible as it implies refunding more than
542
+ // available on paid amounts.
543
+ return false;
544
+
545
+ }
546
+
547
+ /**
548
+ * Handles the manual order cancellation in server-side.
549
+ */
550
+ public function process_cancel_order_meta_box_actions( $order ) {
551
+
552
+ // WooCommerce 3.0 or later.
553
+ if ( method_exists( $order, 'get_meta' ) ) {
554
+ $used_gateway = $order->get_meta( '_used_gateway' );
555
+ $payments = $order->get_meta( '_Mercado_Pago_Payment_IDs' );
556
  } else {
557
+ $used_gateway = get_post_meta( $order->id, '_used_gateway', true );
558
+ $payments = get_post_meta( $order->id, '_Mercado_Pago_Payment_IDs', true );
559
+ }
560
+
561
+ if ( $used_gateway != 'WC_WooMercadoPago_Gateway' ) {
562
+ return;
563
+ }
564
+
565
+ if ( 'yes' == $this->debug ) {
566
+ $this->log->add(
567
+ $this->id,
568
+ '[process_cancel_order_meta_box_actions] - cancelling payments for ' . $payments
569
+ );
570
  }
571
+
572
+ if ( $this->mp != null && ! empty( $payments ) ) {
573
+ $payment_ids = explode( ', ', $payments );
574
+ foreach ( $payment_ids as $p_id ) {
575
+ $response = $this->mp->cancel_payment( $p_id );
576
+ $message = $response['response']['message'];
577
+ $status = $response['status'];
578
+ if ( 'yes' == $this->debug ) {
579
+ $this->log->add(
580
+ $this->id,
581
+ '[process_cancel_order_meta_box_actions] - cancel payment of id ' . $p_id .
582
+ ' => ' . ( $status >= 200 && $status < 300 ? 'SUCCESS' : 'FAIL - ' . $message )
583
+ );
584
+ }
585
+ }
586
+ } else {
587
+ if ( 'yes' == $this->debug ) {
588
+ $this->log->add(
589
+ $this->id,
590
+ '[process_cancel_order_meta_box_actions] - no payments or credentials invalid'
591
+ );
592
+ }
593
+ }
594
+
595
  }
596
+
597
  /*
598
  * ========================================================================
599
+ * CHECKOUT BUSINESS RULES (CLIENT SIDE)
600
  * ========================================================================
601
  */
602
+
603
+ public function add_checkout_script() {
604
+
605
+ $client_id = WC_WooMercadoPago_Module::get_client_id( $this->get_option( 'access_token' ) );
606
+
607
+ if ( ! empty( $client_id ) && ! $this->is_test_user ) {
608
+
609
+ $w = WC_WooMercadoPago_Module::woocommerce_instance();
610
+ $logged_user_email = null;
611
+ $payments = array();
612
+ $gateways = WC()->payment_gateways->get_available_payment_gateways();
613
+ foreach ( $gateways as $g ) {
614
+ $payments[] = $g->id;
615
+ }
616
+ $payments = str_replace( '-', '_', implode( ', ', $payments ) );
617
+
618
+ if ( wp_get_current_user()->ID != 0 ) {
619
+ $logged_user_email = wp_get_current_user()->user_email;
620
+ }
621
+
622
+ ?>
623
+ <script src="https://secure.mlstatic.com/modules/javascript/analytics.js"></script>
624
+ <script type="text/javascript">
625
+ var MA = ModuleAnalytics;
626
+ MA.setToken( '<?php echo $client_id; ?>' );
627
+ MA.setPlatform( 'WooCommerce' );
628
+ MA.setPlatformVersion( '<?php echo $w->version; ?>' );
629
+ MA.setModuleVersion( '<?php echo WC_WooMercadoPago_Module::VERSION; ?>' );
630
+ MA.setPayerEmail( '<?php echo ( $logged_user_email != null ? $logged_user_email : "" ); ?>' );
631
+ MA.setUserLogged( <?php echo ( empty( $logged_user_email ) ? 0 : 1 ); ?> );
632
+ MA.setInstalledModules( '<?php echo $payments; ?>' );
633
+ MA.post();
634
+ </script>
635
+ <?php
636
+
637
+ }
638
+
639
+ }
640
+
641
+ public function update_checkout_status( $order_id ) {
642
+
643
+ $access_token = WC_WooMercadoPago_Module::get_client_id( $this->get_option( 'access_token' ) );
644
+
645
+ if ( ! empty( $access_token ) && ! $this->is_test_user ) {
646
+
647
+ if ( get_post_meta( $order_id, '_used_gateway', true ) != 'WC_WooMercadoPagoTicket_Gateway' ) {
648
+ return;
649
+ }
650
+
651
+ if ( 'yes' == $this->debug ) {
652
+ $this->log->add(
653
+ $this->id,
654
+ '[update_checkout_status] - updating order of ID ' . $order_id
655
+ );
656
+ }
657
+
658
+ echo '<script src="https://secure.mlstatic.com/modules/javascript/analytics.js"></script>
659
+ <script type="text/javascript">
660
+ var MA = ModuleAnalytics;
661
+ MA.setToken( ' . $access_token . ' );
662
+ MA.setPaymentType("ticket");
663
+ MA.setCheckoutType("custom");
664
+ MA.put();
665
+ </script>';
666
+
667
+ }
668
+
669
+ }
670
+
671
+ public function show_ticket_button( $thankyoutext, $order ) {
672
+ // WooCommerce 3.0 or later.
673
+ if ( method_exists( $order, 'get_meta' ) ) {
674
+ $used_gateway = $order->get_meta( '_used_gateway' );
675
+ $transaction_details = $order->get_meta( '_transaction_details_ticket' );
676
+ } else {
677
+ $used_gateway = get_post_meta( $order->id, '_used_gateway', true );
678
+ $transaction_details = get_post_meta( $order->id, '_transaction_details_ticket', true );
679
+ }
680
+
681
+ // Prevent showing ticket button for other payment methods.
682
+ if ( empty( $transaction_details ) || $used_gateway != 'WC_WooMercadoPagoTicket_Gateway' ) {
683
+ return;
684
+ }
685
+
686
+ $html = '<p>' .
687
+ __( 'Thank you for your order. Please, pay the ticket to get your order approved.', 'woocommerce-mercadopago-module' ) .
688
+ '</p>';
689
+ $html .= '<p><iframe src="' . $transaction_details . '" style="width:100%; height:1000px;"></iframe></p>';
690
+ $html .= '<a id="submit-payment" target="_blank" href="' .
691
+ $transaction_details . '" class="button alt"' .
692
+ ' style="font-size:1.25rem; width:75%; height:48px; line-height:24px; text-align:center;">' .
693
+ __( 'Print the Ticket', 'woocommerce-mercadopago-module' ) .
694
+ '</a> ';
695
+ $added_text = '<p>' . $html . '</p>';
696
+ return $added_text;
697
+ }
698
+
699
+ public function ticket_checkout_scripts() {
700
  if ( is_checkout() && $this->is_available() ) {
701
+ if ( ! get_query_var( 'order-received' ) ) {
702
  wp_enqueue_style(
703
  'woocommerce-mercadopago-style', plugins_url(
704
  'assets/css/custom_checkout_mercadopago.css',
717
  'payment_methods' => $this->payment_methods,
718
  'site_id' => $this->site_id,
719
  'images_path' => plugins_url( 'images/', plugin_dir_path( __FILE__ ) ),
720
+ 'amount' => $amount * ( ( float ) $this->currency_ratio > 0 ? ( float ) $this->currency_ratio : 1 ),
721
  'coupon_mode' => $this->coupon_mode,
722
  'is_currency_conversion' => $this->currency_ratio,
723
  'woocommerce_currency' => get_woocommerce_currency(),
724
+ 'account_currency' => $this->country_configs['currency'],
725
+ 'discount_action_url' => $this->domain .
726
+ '/woocommerce-mercadopago-module/?wc-api=WC_WooMercadoPagoTicket_Gateway',
727
  'form_labels' => array(
728
+ 'febraban' => array(
729
+ 'firstname' => '',
730
+ 'lastname' => '',
731
+ 'docNumber' => '',
732
+ 'address' => '',
733
+ 'number' => '',
734
+ 'city' => '',
735
+ 'state' => '',
736
+ 'zipcode' => ''
737
+ ),
738
+ 'form' => array(
739
+ 'payment_converted' =>
740
+ __( 'Payment converted from', 'woocommerce-mercadopago-module' ),
741
+ 'to' => __( 'to', 'woocommerce-mercadopago-module' ),
742
+ 'coupon_empty' =>
743
+ __( 'Please, inform your coupon code', 'woocommerce-mercadopago-module' ),
744
+ 'apply' => __( 'Apply', 'woocommerce-mercadopago-module' ),
745
+ 'remove' => __( 'Remove', 'woocommerce-mercadopago-module' ),
746
+ 'discount_info1' => __( 'You will save', 'woocommerce-mercadopago-module' ),
747
+ 'discount_info2' => __( 'with discount from', 'woocommerce-mercadopago-module' ),
748
+ 'discount_info3' => __( 'Total of your purchase:', 'woocommerce-mercadopago-module' ),
749
+ 'discount_info4' =>
750
+ __( 'Total of your purchase with discount:', 'woocommerce-mercadopago-module' ),
751
+ 'discount_info5' => __( '*Uppon payment approval', 'woocommerce-mercadopago-module' ),
752
+ 'discount_info6' =>
753
+ __( 'Terms and Conditions of Use', 'woocommerce-mercadopago-module' ),
754
+ 'coupon_of_discounts' => __( 'Discount Coupon', 'woocommerce-mercadopago-module' ),
755
+ 'label_choose' => __( 'Choose', 'woocommerce-mercadopago-module' ),
756
+ 'issuer_selection' =>
757
+ __( 'Please, select the ticket issuer of your preference.', 'woocommerce-mercadopago-module' ),
758
+ 'payment_instructions' =>
759
+ __( 'Click "Place order" button. The ticket will be generated and you will be redirected to print it.', 'woocommerce-mercadopago-module' ),
760
+ 'ticket_note' =>
761
+ __( 'Important: The order will be confirmed only after the payment approval.', 'woocommerce-mercadopago-module' ),
762
+ 'febraban_rules' => __( 'Informações solicitadas em conformidade com as normas das circulares Nro. 3.461/09, 3.598/12 e 3.656/13 do Banco Central do Brasil.', 'woocommerce-mercadopago-module' ),
763
+ 'select' => __( 'SELECT...', 'woocommerce-mercadopago-module' ),
764
+ 'name' => __( 'NAME', 'woocommerce-mercadopago-module' ),
765
+ 'surname' => __( 'SURNAME', 'woocommerce-mercadopago-module' ),
766
+ 'docNumber' => __( 'DOCUMENT', 'woocommerce-mercadopago-module' ),
767
+ 'address' => __( 'ADDRESS', 'woocommerce-mercadopago-module' ),
768
+ 'number' => __( 'NUMBER', 'woocommerce-mercadopago-module' ),
769
+ 'city' => __( 'CITY', 'woocommerce-mercadopago-module' ),
770
+ 'state' => __( 'STATE', 'woocommerce-mercadopago-module' ),
771
+ 'zipcode' => __( 'ZIP', 'woocommerce-mercadopago-module' ),
772
+ 'FEB001' => __( 'You must inform you NAME', 'woocommerce-mercadopago-module' ),
773
+ 'FEB002' => __( 'You must inform your SURNAME', 'woocommerce-mercadopago-module' ),
774
+ 'FEB003' => __( 'You must inform your DOCUMENT', 'woocommerce-mercadopago-module' ),
775
+ 'FEB004' => __( 'You must inform your ADDRESS', 'woocommerce-mercadopago-module' ),
776
+ 'FEB005' => __( 'You must inform your ADDRESS NUMBER', 'woocommerce-mercadopago-module' ),
777
+ 'FEB006' => __( 'You must inform your CITY', 'woocommerce-mercadopago-module' ),
778
+ 'FEB007' => __( 'You must inform your STATE', 'woocommerce-mercadopago-module' ),
779
+ 'FEB008' => __( 'You must inform your ZIP', 'woocommerce-mercadopago-module' )
780
+ )
781
  )
782
  );
783
 
784
+ // Find logged user.
785
+ try {
786
+ $logged_user_email = null;
787
+ $parameters['payer_email'] = null;
788
+ if ( wp_get_current_user()->ID != 0 ) {
789
+ $logged_user_email = wp_get_current_user()->user_email;
790
+ $address = get_user_meta( wp_get_current_user()->ID, 'shipping_address_1', true );
791
+ $address_2 = get_user_meta( wp_get_current_user()->ID, 'shipping_address_2', true );
792
+ $address .= ( ! empty( $address_2 ) ? ' - ' . $address_2 : '' );
793
+ $country = get_user_meta( wp_get_current_user()->ID, 'shipping_country', true );
794
+ $address .= ( ! empty( $country ) ? ' - ' . $country : '' );
795
+ $parameters['form_labels']['febraban'] = array(
796
+ 'firstname' => wp_get_current_user()->user_firstname,
797
+ 'lastname' => wp_get_current_user()->user_lastname,
798
+ 'docNumber' => '',
799
+ 'address' => $address,
800
+ 'number' => '',
801
+ 'city' => get_user_meta( wp_get_current_user()->ID, 'shipping_city', true ),
802
+ 'state' => get_user_meta( wp_get_current_user()->ID, 'shipping_state', true ),
803
+ 'zipcode' => get_user_meta( wp_get_current_user()->ID, 'shipping_postcode', true )
804
+ );
805
+ }
806
+ if ( isset( $logged_user_email ) ) {
807
+ if ( isset( $logged_user_email ) ) {
808
+ $parameters['payer_email'] = $logged_user_email;
809
+ }
810
+ } else {
811
+ $parameters['coupon_mode'] = 'no';
812
+ }
813
+ } catch ( Exception $e ) {
814
+ $parameters['coupon_mode'] = 'no';
815
+ if ( 'yes' == $this->debug ) {
816
+ $this->log->add(
817
+ $this->id,
818
+ '[process_fields] - there is a problem when retrieving information for cards: ' .
819
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
820
+ );
821
+ }
822
+ }
823
+
824
  wc_get_template(
825
  'ticket/ticket-form.php',
826
  $parameters,
827
  'woocommerce/mercadopago/',
828
+ WC_WooMercadoPago_Module::get_templates_path()
829
  );
830
  }
831
+
832
+ /**
833
+ * Summary: Handle the payment and processing the order.
834
+ * Description: This function is called after we click on [place_order] button, and each field is
835
+ * passed to this function through $_POST variable.
836
+ * @return an array containing the result of the processment and the URL to redirect.
837
+ */
838
  public function process_payment( $order_id ) {
839
+
840
+ if ( ! isset( $_POST['mercadopago_ticket'] ) ) {
841
+ return;
842
+ }
843
+
844
+ $order = wc_get_order( $order_id );
845
+ $mercadopago_ticket = $_POST['mercadopago_ticket'];
846
+
847
+ // WooCommerce 3.0 or later.
848
+ if ( method_exists( $order, 'update_meta_data' ) ) {
849
+ $order->update_meta_data( '_used_gateway', 'WC_WooMercadoPagoTicket_Gateway' );
850
+ $order->save();
851
+ } else {
852
+ update_post_meta( $order_id, '_used_gateway', 'WC_WooMercadoPagoTicket_Gateway' );
853
+ }
854
+
855
+ // We have got parameters from checkout page, now its time to charge the card.
856
  if ( 'yes' == $this->debug ) {
857
+ $this->log->add(
858
+ $this->id,
859
+ '[process_payment] - Received [$_POST] from customer front-end page: ' .
860
+ json_encode( $_POST, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
861
+ );
862
  }
863
+
864
+ if ( isset( $mercadopago_ticket['amount'] ) && ! empty( $mercadopago_ticket['amount'] ) &&
865
+ isset( $mercadopago_ticket['paymentMethodId'] ) && ! empty( $mercadopago_ticket['paymentMethodId'] ) ) {
866
+ if ( $this->site_id == 'MLB' ) {
867
+ if ( isset( $mercadopago_ticket['firstname'] ) && ! empty( $mercadopago_ticket['firstname'] ) &&
868
+ isset( $mercadopago_ticket['lastname'] ) && ! empty( $mercadopago_ticket['lastname'] ) &&
869
+ isset( $mercadopago_ticket['docNumber'] ) && ! empty( $mercadopago_ticket['docNumber'] ) &&
870
+ isset( $mercadopago_ticket['address'] ) && ! empty( $mercadopago_ticket['address'] ) &&
871
+ isset( $mercadopago_ticket['number'] ) && ! empty( $mercadopago_ticket['number'] ) &&
872
+ isset( $mercadopago_ticket['city'] ) && ! empty( $mercadopago_ticket['city'] ) &&
873
+ isset( $mercadopago_ticket['state'] ) && ! empty( $mercadopago_ticket['state'] ) &&
874
+ isset( $mercadopago_ticket['zipcode'] ) && ! empty( $mercadopago_ticket['zipcode'] ) ) {
875
+
876
+ return self::create_url( $order, $mercadopago_ticket );
877
+
878
+ } else {
879
+ wc_add_notice(
880
+ '<p>' .
881
+ __( 'A problem was occurred when processing your payment. Are you sure you have correctly filled all information in the checkout form?', 'woocommerce-mercadopago-module' ) .
882
+ '</p>',
883
+ 'error'
884
+ );
885
+ return array(
886
+ 'result' => 'fail',
887
+ 'redirect' => '',
888
+ );
889
+ }
890
+ }
891
+ return self::create_url( $order, $mercadopago_ticket );
892
+ } else {
893
+ // process when fields are imcomplete.
894
  wc_add_notice(
895
+ '<p>' .
896
+ __( 'A problem was occurred when processing your payment. Please, try again.', 'woocommerce-mercadopago-module' ) .
897
+ '</p>',
898
  'error'
899
  );
900
  return array(
901
+ 'result' => 'fail',
902
  'redirect' => '',
903
  );
904
+ }
905
+
906
  }
907
 
908
+ /**
909
+ * Summary: Build Mercado Pago preference.
910
+ * Description: Create Mercado Pago preference and get init_point URL based in the order options
911
+ * from the cart.
912
+ * @return the preference object.
913
+ */
914
+ private function build_payment_preference( $order, $ticket_checkout ) {
915
 
916
+ // A string to register items (workaround to deal with API problem that shows only first item).
917
+ $list_of_items = array();
918
+ $order_total = 0;
919
+ $discount_amount_of_items = 0;
920
 
921
+ // Here we build the array that contains ordered items, from customer cart.
922
+ $items = array();
923
+ if ( sizeof( $order->get_items() ) > 0 ) {
924
+ foreach ( $order->get_items() as $item ) {
925
+ if ( $item['qty'] ) {
926
+ $product = new WC_product( $item['product_id'] );
927
+
928
+ // WooCommerce 3.0 or later.
929
+ if ( method_exists( $product, 'get_description' ) ) {
930
+ $product_title = WC_WooMercadoPago_Module::utf8_ansi(
931
+ $product->get_name()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
932
  );
933
+ $product_content = WC_WooMercadoPago_Module::utf8_ansi(
934
+ $product->get_description()
 
 
 
 
935
  );
936
+ } else {
937
+ $product_title = WC_WooMercadoPago_Module::utf8_ansi(
938
+ $product->post->post_title
 
939
  );
940
+ $product_content = WC_WooMercadoPago_Module::utf8_ansi(
941
+ $product->post->post_content
942
+ );
943
+ }
 
 
 
 
 
 
 
 
944
 
945
+ // Calculate discount for payment method.
946
+ $unit_price = floor( ( (float) $item['line_total'] + (float) $item['line_tax'] ) *
947
+ ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 ) * 100 ) / 100;
948
+ if ( is_numeric( $this->gateway_discount ) ) {
949
+ if ( $this->gateway_discount >= 0 && $this->gateway_discount < 100 ) {
950
+ $price_percent = $this->gateway_discount / 100;
951
+ $discount = $unit_price * $price_percent;
952
+ if ( $discount > 0 ) {
953
+ $discount_amount_of_items += $discount;
954
+ }
955
+ }
956
+ }
957
 
958
+ // Remove decimals if MCO/MLC
959
+ if ( $this->site_id == 'MCO' || $this->site_id == 'MLC' ) {
960
+ $unit_price = floor( $unit_price );
961
+ $discount_amount_of_items = floor( $discount_amount_of_items );
962
+ }
963
+
964
+ $order_total += $unit_price;
965
+
966
+ array_push( $list_of_items, $product_title . ' x ' . $item['qty'] );
 
967
  array_push( $items, array(
968
+ 'id' => $item['product_id'],
969
+ 'title' => ( html_entity_decode( $product_title ) . ' x ' . $item['qty'] ),
970
+ 'description' => sanitize_file_name( html_entity_decode(
971
+ // This handles description width limit of Mercado Pago.
972
+ ( strlen( $product_content ) > 230 ?
973
+ substr( $product_content, 0, 230 ) . '...' :
974
+ $product_content )
975
  ) ),
976
  'picture_url' => wp_get_attachment_url( $product->get_image_id() ),
977
+ 'category_id' => $this->store_categories_id[$this->category_id],
978
  'quantity' => 1,
979
+ 'unit_price' => $unit_price
980
+ ) );
 
981
  }
982
  }
983
  }
984
+
985
+ // Creates the shipment cost structure.
986
+ $ship_cost = ( (float) $order->get_total_shipping() + (float) $order->get_shipping_tax() ) *
987
+ ( (float) $this->currency_ratio > 0 ? (float) $this->currency_ratio : 1 );
988
+
989
+ // Remove decimals if MCO/MLC
990
+ if ( $this->site_id == 'MCO' || $this->site_id == 'MLC' ) {
991
+ $ship_cost = floor( $ship_cost );
992
+ }
993
+
994
+ if ( $ship_cost > 0 ) {
995
+ $order_total += $ship_cost;
996
+ $item = array(
997
+ 'id' => 2147483647,
998
+ 'title' => sanitize_file_name( $order->get_shipping_to_display() ),
999
+ 'description' => __( 'Shipping service used by store', 'woocommerce-mercadopago-module' ),
1000
+ 'category_id' => $this->store_categories_id[$this->category_id],
1001
+ 'quantity' => 1,
1002
+ 'unit_price' => floor( $ship_cost * 100 ) / 100
1003
+ );
1004
+ $items[] = $item;
1005
+ }
1006
+
1007
+ // Discounts features.
1008
+ if ( isset( $ticket_checkout['discount'] ) && $ticket_checkout['discount'] != '' &&
1009
+ $ticket_checkout['discount'] > 0 && isset( $ticket_checkout['coupon_code'] ) &&
1010
+ $ticket_checkout['coupon_code'] != '' &&
1011
+ WC()->session->chosen_payment_method == 'woocommerce-mercadopago-ticket-module' ) {
1012
+
1013
+ // Remove decimals if MCO/MLC
1014
+ if ( $this->site_id == 'MCO' || $this->site_id == 'MLC' ) {
1015
+ $ticket_checkout['discount'] = floor( $ticket_checkout['discount'] );
1016
+ }
1017
+
1018
+ $item = array(
1019
+ 'id' => 2147483646,
1020
+ 'title' => __( 'Discount', 'woocommerce-mercadopago-module' ),
1021
+ 'description' => __( 'Discount provided by store', 'woocommerce-mercadopago-module' ),
1022
+ 'category_id' => $this->store_categories_id[$this->category_id],
1023
+ 'quantity' => 1,
1024
+ 'unit_price' => -( ( float ) $ticket_checkout['discount'] )
1025
+ );
1026
+ $items[] = $item;
1027
+ }
1028
+
1029
+ if ( method_exists( $order, 'get_id' ) ) {
1030
+ // Build additional information from the customer data.
1031
+ $payer_additional_info = array(
1032
+ 'first_name' => html_entity_decode( $order->get_billing_first_name() ),
1033
+ 'last_name' => html_entity_decode( $order->get_billing_last_name() ),
1034
+ //'registration_date' =>
1035
+ 'phone' => array(
1036
+ //'area_code' =>
1037
+ 'number' => $order->get_billing_phone()
1038
+ ),
1039
+ 'address' => array(
1040
+ 'zip_code' => $order->get_billing_postcode(),
1041
+ 'street_name' => html_entity_decode(
1042
+ $order->get_billing_address_1() . ' ' .
1043
+ $order->get_billing_address_2() . ' ' .
1044
+ $order->get_billing_city() . ' ' .
1045
+ $order->get_billing_state() . ' ' .
1046
+ $order->get_billing_country()
1047
+ )
1048
+ //'street_number' =>
1049
+ )
1050
+ );
1051
+ // Create the shipment address information set.
1052
+ $shipments = array(
1053
+ 'receiver_address' => array(
1054
+ 'zip_code' => $order->get_shipping_postcode(),
1055
+ 'street_name' => html_entity_decode(
1056
+ $order->get_shipping_address_1() . ' ' .
1057
+ $order->get_shipping_address_2() . ' ' .
1058
+ $order->get_shipping_city() . ' ' .
1059
+ $order->get_shipping_state() . ' ' .
1060
+ $order->get_shipping_country()
1061
+ )
1062
+ //'street_number' =>
1063
+ //'floor' =>
1064
+ //'apartment' =>
1065
+ )
1066
+ );
1067
+ // The payment preference.
1068
+ $preferences = array(
1069
+ 'transaction_amount' => floor( ( ( float ) ( $order_total - $discount_amount_of_items ) ) * 100 ) / 100,
1070
+ 'description' => implode( ', ', $list_of_items ),
1071
+ 'payment_method_id' => $ticket_checkout['paymentMethodId'],
1072
+ 'payer' => array(
1073
+ 'email' => $order->get_billing_email()
1074
+ ),
1075
+ 'external_reference' => $this->invoice_prefix . $order->get_id(),
1076
+ 'additional_info' => array(
1077
+ 'items' => $items,
1078
+ 'payer' => $payer_additional_info,
1079
+ 'shipments' => $shipments
1080
+ )
1081
+ );
1082
+ } else {
1083
+ // Build additional information from the customer data.
1084
+ $payer_additional_info = array(
1085
+ 'first_name' => html_entity_decode( $order->billing_first_name ),
1086
+ 'last_name' => html_entity_decode( $order->billing_last_name ),
1087
+ //'registration_date' =>
1088
+ 'phone' => array(
1089
+ //'area_code' =>
1090
+ 'number' => $order->billing_phone
1091
+ ),
1092
+ 'address' => array(
1093
+ 'zip_code' => $order->billing_postcode,
1094
+ 'street_name' => html_entity_decode(
1095
+ $order->billing_address_1 . ' ' .
1096
+ $order->billing_address_2 . ' ' .
1097
+ $order->billing_city . ' ' .
1098
+ $order->billing_state . ' ' .
1099
+ $order->billing_country
1100
+ )
1101
+ //'street_number' =>
1102
+ )
1103
+ );
1104
+ // Create the shipment address information set.
1105
+ $shipments = array(
1106
+ 'receiver_address' => array(
1107
+ 'zip_code' => $order->shipping_postcode,
1108
+ 'street_name' => html_entity_decode(
1109
+ $order->shipping_address_1 . ' ' .
1110
+ $order->shipping_address_2 . ' ' .
1111
+ $order->shipping_city . ' ' .
1112
+ $order->shipping_state . ' ' .
1113
+ $order->shipping_country
1114
+ )
1115
+ //'street_number' =>
1116
+ //'floor' =>
1117
+ //'apartment' =>
1118
+ )
1119
+ );
1120
+ // The payment preference.
1121
+ $preferences = array(
1122
+ 'transaction_amount' => floor( ( ( float ) ( $order_total - $discount_amount_of_items ) ) * 100 ) / 100,
1123
+ 'description' => implode( ', ', $list_of_items ),
1124
+ 'payment_method_id' => $ticket_checkout['paymentMethodId'],
1125
+ 'payer' => array(
1126
+ 'email' => $order->billing_email
1127
+ ),
1128
+ 'external_reference' => $this->invoice_prefix . $order->id,
1129
+ 'additional_info' => array(
1130
+ 'items' => $items,
1131
+ 'payer' => $payer_additional_info,
1132
+ 'shipments' => $shipments
1133
+ )
1134
+ );
1135
+ }
1136
+
1137
+ // FEBRABAN rules.
1138
+ if ( $this->site_id == 'MLB' ) {
1139
+ $preferences['payer']['first_name'] = $ticket_checkout['firstname'];
1140
+ $preferences['payer']['last_name'] = $ticket_checkout['lastname'];
1141
+ $preferences['payer']['identification']['type'] = 'CPF';
1142
+ $preferences['payer']['identification']['number'] = $ticket_checkout['docNumber'];
1143
+ $preferences['payer']['address']['street_name'] = $ticket_checkout['address'];
1144
+ $preferences['payer']['address']['street_number'] = $ticket_checkout['number'];
1145
+ $preferences['payer']['address']['neighborhood'] = $ticket_checkout['city'];
1146
+ $preferences['payer']['address']['city'] = $ticket_checkout['city'];
1147
+ $preferences['payer']['address']['federal_unit'] = $ticket_checkout['state'];
1148
+ }
1149
+
1150
+ // Do not set IPN url if it is a localhost.
1151
+ if ( ! strrpos( $this->domain, 'localhost' ) ) {
1152
+ $preferences['notification_url'] = WC_WooMercadoPago_Module::workaround_ampersand_bug(
1153
+ WC()->api_request_url( 'WC_WooMercadoPagoTicket_Gateway' )
1154
+ );
1155
+ }
1156
+
1157
+ // Discounts features.
1158
+ if ( isset( $ticket_checkout['discount'] ) && $ticket_checkout['discount'] != '' &&
1159
+ $ticket_checkout['discount'] > 0 && isset( $ticket_checkout['coupon_code'] ) &&
1160
+ $ticket_checkout['coupon_code'] != '' &&
1161
+ WC()->session->chosen_payment_method == 'woocommerce-mercadopago-ticket-module' ) {
1162
+
1163
+ $preferences['campaign_id'] = (int) $ticket_checkout['campaign_id'];
1164
+ $preferences['coupon_amount'] = ( (float) $ticket_checkout['discount'] );
1165
+ $preferences['coupon_code'] = strtoupper( $ticket_checkout['coupon_code'] );
1166
+ }
1167
+
1168
+ // Set sponsor ID.
1169
+ if ( ! $this->is_test_user ) {
1170
+ $preferences['sponsor_id'] = $this->country_configs['sponsor_id'];
1171
  }
1172
 
1173
  if ( 'yes' == $this->debug ) {
1174
+ $this->log->add(
1175
+ $this->id,
1176
+ '[build_payment_preference] - returning just created [$preferences] structure: ' .
1177
+ json_encode( $preferences, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1178
+ );
1179
  }
1180
 
1181
+ $preferences = apply_filters(
1182
+ 'woocommerce_mercadopago_module_ticket_preferences',
1183
+ $preferences, $order
1184
+ );
1185
+ return $preferences;
1186
+ }
1187
+
1188
+ // --------------------------------------------------
1189
+
1190
+ protected function create_url( $order, $ticket_checkout ) {
1191
+
1192
+ // Creates the order parameters by checking the cart configuration.
1193
+ $preferences = $this->build_payment_preference( $order, $ticket_checkout );
1194
 
1195
+ $this->mp->sandbox_mode( false );
1196
+
1197
+ // Create order preferences with Mercado Pago API request.
1198
+ try {
1199
+ $ticket_info = $this->mp->create_payment( json_encode( $preferences ) );
1200
+ if ( $ticket_info['status'] < 200 || $ticket_info['status'] >= 300 ) {
1201
+ // Mercado Pago trowed an error.
1202
+ if ( 'yes' == $this->debug ) {
1203
+ $this->log->add(
1204
+ $this->id,
1205
+ '[create_url] - mercado pago gave error, payment creation failed with error: ' .
1206
+ $ticket_info['response']['message'] );
1207
+ }
1208
+ return false;
1209
+ } elseif ( is_wp_error( $ticket_info ) ) {
1210
+ // WordPress throwed an error.
1211
+ if ( 'yes' == $this->debug ) {
1212
+ $this->log->add(
1213
+ $this->id,
1214
+ '[create_url] - wordpress gave error, payment creation failed with error: ' .
1215
+ $ticket_info['response']['message'] );
1216
+ }
1217
+ return false;
1218
+ } else {
1219
+ // Obtain the URL.
1220
+ $response = $ticket_info['response'];
1221
+ if ( array_key_exists( 'status', $response ) ) {
1222
+ if ( $response['status'] == 'pending' ) {
1223
+ if ( $response['status_detail'] == 'pending_waiting_payment' ) {
1224
+ WC()->cart->empty_cart();
1225
+ if ( $this->reduce_stock_on_order_gen == 'yes' ) {
1226
+ $order->reduce_order_stock();
1227
+ }
1228
+ /*$html = '<p></p><p>' . wordwrap(
1229
+ __( 'Thank you for your order. Please, pay the ticket to get your order approved.', 'woocommerce-mercadopago-module' ),
1230
+ 60, '<br>'
1231
+ ) . '</p>';
1232
+ $html .= '<a id="submit-payment" target="_blank" href="' .
1233
+ $response['transaction_details']['external_resource_url'] .
1234
+ '" class="button alt">' .
1235
+ __( 'Print the Ticket', 'woocommerce-mercadopago-module' ) .
1236
+ '</a> ';
1237
+ wc_add_notice( '<p>' . $html . '</p>', 'notice' );*/
1238
+
1239
+ // WooCommerce 3.0 or later.
1240
+ if ( method_exists( $order, 'update_meta_data' ) ) {
1241
+ $order->update_meta_data( '_transaction_details_ticket', $response['transaction_details']['external_resource_url'] );
1242
+ $order->save();
1243
+ } else {
1244
+ update_post_meta(
1245
+ $order->id,
1246
+ '_transaction_details_ticket',
1247
+ $response['transaction_details']['external_resource_url']
1248
+ );
1249
+ }
1250
+
1251
+ $order->add_order_note(
1252
+ 'Mercado Pago: ' .
1253
+ __( 'Customer haven\'t paid yet.', 'woocommerce-mercadopago-module' )
1254
+ );
1255
+ $order->add_order_note(
1256
+ 'Mercado Pago: ' .
1257
+ __( 'To reprint the ticket click ', 'woocommerce-mercadopago-module' ) .
1258
+ '<a target="_blank" href="' .
1259
+ $response['transaction_details']['external_resource_url'] . '">' .
1260
+ __( 'here', 'woocommerce-mercadopago-module' ) .
1261
+ '</a>', 1, false
1262
+ );
1263
+
1264
+ /*return array(
1265
+ 'result' => 'success',
1266
+ 'redirect' => $order->get_checkout_payment_url( true )
1267
+ );*/
1268
+ return array(
1269
+ 'result' => 'success',
1270
+ 'redirect' => $order->get_checkout_order_received_url()
1271
+ );
1272
+ }
1273
+ }
1274
+ }
1275
+ return false;
1276
+ }
1277
+ } catch ( MercadoPagoException $e ) {
1278
+ // Something went wrong with the payment creation.
1279
+ if ( 'yes' == $this->debug ) {
1280
+ $this->log->add(
1281
+ $this->id,
1282
+ '[create_url] - payment creation failed with exception: ' .
1283
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
1284
+ );
1285
+ }
1286
+ }
1287
+ return false;
1288
+ }
1289
+
1290
+ /**
1291
+ * Summary: Receive post data and applies a discount based in the received values.
1292
+ * Description: Receive post data and applies a discount based in the received values.
1293
+ */
1294
+ public function add_discount_ticket() {
1295
+
1296
+ if ( ! isset( $_POST['mercadopago_ticket'] ) )
1297
+ return;
1298
 
 
1299
  if ( is_admin() && ! defined( 'DOING_AJAX' ) || is_cart() ) {
1300
  return;
1301
  }
1302
+
1303
+ $mercadopago_ticket = $_POST['mercadopago_ticket'];
1304
+ if ( isset( $mercadopago_ticket['discount'] ) && $mercadopago_ticket['discount'] != '' &&
1305
+ $mercadopago_ticket['discount'] > 0 && isset( $mercadopago_ticket['coupon_code'] ) &&
1306
+ $mercadopago_ticket['coupon_code'] != '' &&
1307
+ WC()->session->chosen_payment_method == 'woocommerce-mercadopago-ticket-module' ) {
1308
+
1309
+ if ( 'yes' == $this->debug ) {
1310
+ $this->log->add(
1311
+ $this->id,
1312
+ '[add_discount_ticket] - ticket trying to apply discount...'
1313
+ );
1314
+ }
1315
+
1316
+ $value = ( $mercadopago_ticket['discount'] ) /
1317
+ ( ( float ) $this->currency_ratio > 0 ? ( float ) $this->currency_ratio : 1 );
1318
+
1319
  global $woocommerce;
1320
+ if ( apply_filters(
1321
+ 'wc_mercadopagoticket_module_apply_discount',
1322
+ 0 < $value, $woocommerce->cart )
1323
+ ) {
1324
+ $woocommerce->cart->add_fee( sprintf(
1325
+ __( 'Discount for %s coupon', 'woocommerce-mercadopago-module' ),
1326
+ esc_attr( $mercadopago_ticket['campaign']
1327
+ ) ), ( $value * -1 ), false
1328
  );
1329
  }
1330
  }
1331
+
1332
  }
1333
 
1334
+ // Display the discount in payment method title.
1335
+ public function get_payment_method_title_ticket( $title, $id ) {
1336
+
1337
+ if ( ! is_checkout() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1338
+ return $title;
1339
+ }
1340
+
1341
+ if ( $title != $this->title || $this->gateway_discount == 0 ) {
1342
+ return $title;
1343
+ }
1344
+
1345
+ $total = (float) WC()->cart->subtotal;
1346
+ if ( is_numeric( $this->gateway_discount ) ) {
1347
+ if ( $this->gateway_discount >= 0 && $this->gateway_discount < 100 ) {
1348
+ $price_percent = $this->gateway_discount / 100;
1349
+ if ( $price_percent > 0 ) {
1350
+ $title .= ' (' . __( 'Discount Of ', 'woocommerce-mercadopago-module' ) .
1351
+ strip_tags( wc_price( $total * $price_percent ) ) . ' )';
1352
+ }
1353
+ }
1354
+ }
1355
 
1356
+ return $title;
 
 
1357
  }
1358
 
1359
+ /*
1360
+ * ========================================================================
1361
+ * AUXILIARY AND FEEDBACK METHODS (SERVER SIDE)
1362
+ * ========================================================================
1363
+ */
1364
+
1365
+ /**
1366
+ * Summary: Check if we have valid credentials.
1367
+ * Description: Check if we have valid credentials.
1368
+ * @return boolean true/false depending on the validation result.
1369
+ */
1370
+ public function validate_credentials() {
1371
+
1372
+ if ( empty( $this->access_token ) ) {
1373
+ return false;
1374
+ }
1375
+
1376
+ if ( strpos( $this->access_token, 'APP_USR' ) === false && strpos( $this->access_token, 'TEST' ) === false ) {
1377
+ return false;
1378
+ }
1379
+
1380
+ try {
1381
+
1382
+ $this->mp = new MP(
1383
+ WC_WooMercadoPago_Module::get_module_version(),
1384
+ $this->access_token
1385
+ );
1386
+ $get_request = $this->mp->get( '/users/me?access_token=' . $this->access_token );
1387
+
1388
+ if ( isset( $get_request['response']['site_id'] ) ) {
1389
+
1390
+ // TODO: revalidate MLU
1391
+ if ( $get_request['response']['site_id'] == 'MLU' ) {
1392
+ $this->mp = null;
1393
+ return false;
1394
+ }
1395
+
1396
+ $this->is_test_user = in_array( 'test_user', $get_request['response']['tags'] );
1397
+ $this->site_id = $get_request['response']['site_id'];
1398
+ $this->collector_id = $get_request['response']['id'];
1399
+ $this->country_configs = WC_WooMercadoPago_Module::get_country_config( $this->site_id );
1400
+
1401
+ // Get ticket payments.
1402
+ $payments = $this->mp->get( '/v1/payment_methods/?access_token=' . $this->access_token );
1403
+ foreach ( $payments['response'] as $payment ) {
1404
+ if ( isset( $payment['payment_type_id'] ) ) {
1405
+ if ( $payment['payment_type_id'] != 'account_money' &&
1406
+ $payment['payment_type_id'] != 'credit_card' &&
1407
+ $payment['payment_type_id'] != 'debit_card' &&
1408
+ $payment['payment_type_id'] != 'prepaid_card' ) {
1409
+
1410
  array_push( $this->payment_methods, $payment );
1411
  }
1412
  }
1413
+ }
1414
+
1415
+ // Check if there are available payments with ticket.
1416
+ if ( count( $this->payment_methods ) == 0 ) {
1417
+ return false;
1418
+ }
1419
+
1420
+ // Check for auto converstion of currency.
1421
+ $this->currency_ratio = -1;
1422
+ if ( $this->currency_conversion == 'yes' ) {
1423
+ $this->currency_ratio = WC_WooMercadoPago_Module::get_conversion_rate(
1424
+ $this->country_configs['currency']
1425
+ );
1426
+ }
1427
+
1428
+ return true;
1429
+
1430
+ } else {
1431
+ $this->mp = null;
 
1432
  return false;
1433
  }
1434
+
1435
+ } catch ( MercadoPagoException $e ) {
1436
+ if ( 'yes' == $this->debug ) {
1437
+ $this->log->add(
1438
+ $this->id,
1439
+ '[validate_credentials] - while validating credentials, got exception: ' .
1440
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
1441
+ );
1442
+ }
1443
+ $this->mp = null;
1444
+ return false;
1445
  }
1446
+
1447
  return false;
1448
+
1449
  }
1450
 
1451
+ // Build the string representing the path to the log file.
1452
+ protected function build_log_path_string() {
1453
  return '<a href="' . esc_url( admin_url( 'admin.php?page=wc-status&tab=logs&log_file=' .
1454
  esc_attr( $this->id ) . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.log' ) ) . '">' .
1455
  __( 'WooCommerce &gt; System Status &gt; Logs', 'woocommerce-mercadopago-module' ) . '</a>';
1456
  }
1457
+
1458
  // Return boolean indicating if currency is supported.
1459
+ protected function is_supported_currency() {
1460
+ return get_woocommerce_currency() == $this->country_configs['currency'];
1461
  }
1462
 
1463
+ // Called automatically by WooCommerce, verify if Module is available to use.
1464
+ public function is_available() {
1465
+ if ( ! did_action( 'wp_loaded' ) ) {
1466
+ return false;
 
 
 
 
 
 
 
1467
  }
1468
+ global $woocommerce;
1469
+ $w_cart = $woocommerce->cart;
1470
+ // Check if we have SSL.
1471
+ if ( empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ) {
1472
+ return false;
1473
+ }
1474
+ // Check for recurrent product checkout.
1475
+ if ( isset( $w_cart ) ) {
1476
+ if ( WC_WooMercadoPago_Module::is_subscription( $w_cart->get_cart() ) ) {
1477
+ return false;
1478
+ }
1479
+ }
1480
+ // Check if this gateway is enabled and well configured.
1481
+ $available = ( 'yes' == $this->settings['enabled'] ) && ! empty( $this->access_token );
1482
+ return $available;
1483
  }
1484
 
1485
+ public function check_ssl_absence() {
1486
+ if ( empty( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] == 'off' ) {
1487
+ if ( 'yes' == $this->settings['enabled'] ) {
1488
+ echo '<div class="error"><p><strong>' .
1489
  __( 'Ticket is Inactive', 'woocommerce-mercadopago-module' ) .
1490
  '</strong>: ' .
1491
  sprintf(
1495
  }
1496
  }
1497
 
 
 
 
 
 
 
 
 
 
 
 
1498
  // Get the URL to admin page.
1499
  protected function admin_url() {
1500
  if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) {
1508
  }
1509
 
1510
  // Notify that access_token are not valid.
1511
+ public function credentials_missing_message() {
1512
+ echo '<div class="error"><p><strong>' .
1513
  __( 'Ticket is Inactive', 'woocommerce-mercadopago-module' ) .
1514
  '</strong>: ' .
1515
+ __( 'Your Mercado Pago credentials Access Token appears to be misconfigured.', 'woocommerce-mercadopago-module' ) .
 
 
 
1516
  '</p></div>';
1517
  }
1518
+
 
 
 
 
 
 
 
 
 
 
 
 
 
1519
  /*
1520
+ * ========================================================================
1521
+ * IPN MECHANICS (SERVER SIDE)
1522
+ * ========================================================================
1523
+ */
1524
+
1525
+ /**
1526
+ * Summary: This call checks any incoming notifications from Mercado Pago server.
1527
+ * Description: This call checks any incoming notifications from Mercado Pago server.
1528
+ */
1529
  public function process_http_request() {
1530
  @ob_clean();
1531
  if ( 'yes' == $this->debug ) {
1532
+ $this->log->add(
1533
+ $this->id,
1534
+ '[process_http_request] - Received _get content: ' .
1535
+ json_encode( $_GET, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1536
+ );
1537
+ }
1538
+ if ( isset( $_GET['coupon_id'] ) && $_GET['coupon_id'] != '' ) {
1539
+ // process coupon evaluations.
1540
+ if ( isset( $_GET['payer'] ) && $_GET['payer'] != '' ) {
1541
+ $logged_user_email = $_GET['payer'];
1542
+ $coupon_id = $_GET['coupon_id'];
1543
+ $this->mp->sandbox_mode( false );
1544
+ $response = $this->mp->check_discount_campaigns(
1545
+ $_GET['amount'],
1546
+ $logged_user_email,
1547
+ $coupon_id
1548
+ );
1549
+ header( 'HTTP/1.1 200 OK' );
1550
+ header( 'Content-Type: application/json' );
 
 
1551
  echo json_encode( $response );
1552
  } else {
1553
  $obj = new stdClass();
1554
  $obj->status = 404;
1555
  $obj->response = array(
1556
+ 'message' =>
1557
+ __( 'Please, inform your email in billing address to use this feature', 'woocommerce-mercadopago-module' ),
1558
  'error' => 'payer_not_found',
1559
  'status' => 404,
1560
  'cause' => array()
1561
  );
1562
  header( 'HTTP/1.1 200 OK' );
1563
+ header( 'Content-Type: application/json' );
1564
  echo json_encode( $obj );
1565
  }
1566
+ exit( 0 );
1567
  } else {
1568
+ // process IPN messages.
1569
  $data = $this->check_ipn_request_is_valid( $_GET );
1570
  if ( $data ) {
1571
  header( 'HTTP/1.1 200 OK' );
1573
  }
1574
  }
1575
  }
1576
+
1577
+ /**
1578
+ * Summary: Get received data from IPN and checks if its a merchant_order or a payment.
1579
+ * Description: If we have these information, we return data to be processed by
1580
+ * successful_request function.
1581
+ * @return boolean indicating if it was successfuly processed.
1582
+ */
1583
  public function check_ipn_request_is_valid( $data ) {
1584
+
1585
+ if ( ! isset( $data['data_id'] ) || ! isset( $data['type'] ) ) {
1586
  if ( 'yes' == $this->debug ) {
1587
+ $this->log->add(
1588
+ $this->id,
1589
+ '[check_ipn_request_is_valid] - data_id or type not set: ' .
1590
+ json_encode( $data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1591
+ );
1592
  }
1593
+ // at least, check if its a v0 ipn.
1594
+ if ( ! isset( $data['id'] ) || ! isset( $data['topic'] ) ) {
1595
  if ( 'yes' == $this->debug ) {
1596
  $this->log->add(
1597
+ $this->id,
1598
+ '[check_ipn_response] - Mercado Pago Request Failure: ' .
1599
+ json_encode( $_GET, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1600
+ );
1601
  }
1602
  wp_die( __( 'Mercado Pago Request Failure', 'woocommerce-mercadopago-module' ) );
1603
  } else {
1606
  // No ID? No process!
1607
  return false;
1608
  }
1609
+
1610
+ $this->mp->sandbox_mode( false );
1611
+
1612
  try {
1613
+ // Get the payment reported by the IPN.
1614
+ if ( $data['type'] == 'payment' ) {
1615
+ $access_token = array( 'access_token' => $this->mp->get_access_token() );
1616
+ $payment_info = $this->mp->get(
1617
+ '/v1/payments/' . $data['data_id'], $access_token, false
1618
+ );
1619
+ if ( ! is_wp_error( $payment_info ) &&
1620
+ ( $payment_info['status'] == 200 || $payment_info['status'] == 201 ) ) {
1621
+ return $payment_info['response'];
1622
  } else {
1623
  if ( 'yes' == $this->debug ) {
1624
+ $this->log->add(
1625
+ $this->id,
1626
+ '[check_ipn_request_is_valid] - error when processing received data: ' .
1627
+ json_encode( $payment_info, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1628
+ );
1629
  }
1630
  return false;
1631
  }
1633
  } catch ( MercadoPagoException $e ) {
1634
  if ( 'yes' == $this->debug ) {
1635
  $this->log->add(
1636
+ $this->id,
1637
+ '[check_ipn_request_is_valid] - MercadoPagoException: ' .
1638
+ json_encode( array( 'status' => $e->getCode(), 'message' => $e->getMessage() ) )
1639
+ );
1640
  }
1641
  return false;
1642
  }
1643
  return true;
1644
  }
1645
+
1646
+ /**
1647
+ * Summary: Properly handles each case of notification, based in payment status.
1648
+ * Description: Properly handles each case of notification, based in payment status.
1649
+ */
1650
  public function successful_request( $data ) {
1651
+
1652
  if ( 'yes' == $this->debug ) {
1653
+ $this->log->add(
1654
+ $this->id,
1655
+ '[successful_request] - starting to process ipn update...'
1656
+ );
1657
+ }
1658
+
1659
+ // Get the order and check its presence.
1660
+ $order_key = $data['external_reference'];
1661
+ if ( empty( $order_key ) ) {
1662
+ return;
1663
+ }
1664
+ $id = (int) str_replace( $this->invoice_prefix, '', $order_key );
1665
+ $order = wc_get_order( $id );
1666
+
1667
+ // Check if order exists.
1668
+ if ( ! $order ) {
1669
+ return;
1670
+ }
1671
+
1672
+ // WooCommerce 3.0 or later.
1673
+ if ( method_exists( $order, 'get_id' ) ) {
1674
+ $order_id = $order->get_id();
1675
+ } else {
1676
+ $order_id = $order->id;
1677
+ }
1678
+
1679
+ // Check if we have the correct order.
1680
+ if ( $order_id !== $id ) {
1681
+ return;
1682
+ }
1683
+
1684
+ if ( 'yes' == $this->debug ) {
1685
+ $this->log->add(
1686
+ $this->id,
1687
+ '[successful_request] - updating metadata and status with data: ' .
1688
+ json_encode( $data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
1689
+ );
1690
+ }
1691
+
1692
+ // Here, we process the status... this is the business rules!
1693
+ // Reference: https://www.mercadopago.com.br/developers/en/api-docs/basic-checkout/ipn/payment-status/
1694
+ $status = isset( $data['status'] ) ? $data['status'] : 'pending';
1695
+ $total_paid = isset( $data['transaction_details']['total_paid_amount'] ) ? $data['transaction_details']['total_paid_amount'] : 0.00;
1696
+ $total_refund = isset( $data['transaction_amount_refunded'] ) ? $data['transaction_amount_refunded'] : 0.00;
1697
+ $total = $data['transaction_amount'];
1698
+
1699
+ // WooCommerce 3.0 or later.
1700
+ if ( method_exists( $order, 'update_meta_data' ) ) {
1701
+ $order->update_meta_data( '_used_gateway', 'WC_WooMercadoPagoTicket_Gateway' );
1702
+
1703
+ if ( ! empty( $data['payer']['email'] ) ) {
1704
+ $order->update_meta_data( __( 'Payer email', 'woocommerce-mercadopago-module' ), $data['payer']['email'] );
1705
+ }
1706
+ if ( ! empty( $data['payment_type_id'] ) ) {
1707
+ $order->update_meta_data( __( 'Payment type', 'woocommerce-mercadopago-module' ), $data['payment_type_id'] );
1708
+ }
1709
+ $payment_id = $data['id'];
1710
+ $order->update_meta_data(
1711
+ 'Mercado Pago - Payment ' . $payment_id,
1712
+ '[Date ' . date( 'Y-m-d H:i:s', strtotime( $data['date_created'] ) ) .
1713
+ ']/[Amount ' . $total .
1714
+ ']/[Paid ' . $total_paid .
1715
+ ']/[Refund ' . $total_refund . ']'
1716
+ );
1717
+ $order->update_meta_data( '_Mercado_Pago_Payment_IDs', $payment_id );
1718
+
1719
+ $order->save();
1720
+ } else {
1721
+ update_post_meta( $order->id, '_used_gateway', 'WC_WooMercadoPagoTicket_Gateway' );
1722
+
1723
+ if ( ! empty( $data['payer']['email'] ) ) {
1724
+ update_post_meta(
1725
+ $order_id,
1726
+ __( 'Payer email', 'woocommerce-mercadopago-module' ),
1727
+ $data['payer']['email']
1728
+ );
1729
+ }
1730
+ if ( ! empty( $data['payment_type_id'] ) ) {
1731
+ update_post_meta(
1732
+ $order_id,
1733
+ __( 'Payment type', 'woocommerce-mercadopago-module' ),
1734
+ $data['payment_type_id']
1735
+ );
1736
+ }
1737
+ $payment_id = $data['id'];
1738
+ update_post_meta(
1739
+ $order_id,
1740
+ 'Mercado Pago - Payment ' . $payment_id,
1741
+ '[Date ' . date( 'Y-m-d H:i:s', strtotime( $data['date_created'] ) ) .
1742
+ ']/[Amount ' . $total .
1743
+ ']/[Paid ' . $total_paid .
1744
+ ']/[Refund ' . $total_refund . ']'
1745
+ );
1746
+ update_post_meta(
1747
+ $order_id,
1748
+ '_Mercado_Pago_Payment_IDs',
1749
+ $payment_id
1750
+ );
1751
+ }
1752
+
1753
+ // Switch the status and update in WooCommerce.
1754
+ switch ( $status ) {
1755
+ case 'approved':
1756
+ $order->add_order_note(
1757
+ 'Mercado Pago: ' . __( 'Payment approved.', 'woocommerce-mercadopago-module' )
1758
+ );
1759
+ if ( $this->reduce_stock_on_order_gen == 'no' ) {
1760
+ $order->payment_complete();
1761
+ } else {
1762
+ $order->update_status( 'processing' );
1763
  }
1764
+ break;
1765
+ case 'pending':
1766
+ // decrease stock if not yet decreased and order not exists.
1767
+ $notes = $order->get_customer_order_notes();
1768
+ $has_note = false;
1769
+ if ( sizeof( $notes ) > 1 ) {
1770
+ $has_note = true;
1771
+ break;
1772
  }
1773
+ if ( ! $has_note ) {
1774
+ $order->add_order_note(
1775
+ 'Mercado Pago: ' .
1776
+ __( 'Waiting for the ticket payment.', 'woocommerce-mercadopago-module' )
 
 
1777
  );
1778
+ $order->add_order_note(
1779
+ 'Mercado Pago: ' .
1780
+ __( 'Waiting for the ticket payment.', 'woocommerce-mercadopago-module' ),
1781
+ 1, false
 
 
 
1782
  );
1783
  }
1784
+ break;
1785
+ case 'in_process':
1786
+ $order->update_status(
1787
+ 'on-hold',
1788
+ 'Mercado Pago: ' . __( 'Payment under review.', 'woocommerce-mercadopago-module' )
1789
+ );
1790
+ break;
1791
+ case 'rejected':
1792
+ $order->update_status(
1793
+ 'failed',
1794
+ 'Mercado Pago: ' .
1795
+ __( 'The payment was refused. The customer can try again.', 'woocommerce-mercadopago-module' )
1796
+ );
1797
+ break;
1798
+ case 'refunded':
1799
+ $order->update_status(
1800
+ 'refunded',
1801
+ 'Mercado Pago: ' .
1802
+ __( 'The payment was refunded to the customer.', 'woocommerce-mercadopago-module' )
1803
+ );
1804
+ break;
1805
+ case 'cancelled':
1806
+ $order->update_status(
1807
+ 'cancelled',
1808
+ 'Mercado Pago: ' .
1809
+ __( 'The payment was cancelled.', 'woocommerce-mercadopago-module' )
1810
+ );
1811
+ break;
1812
+ case 'in_mediation':
1813
+ $order->add_order_note(
1814
+ 'Mercado Pago: ' .
1815
+ __( 'The payment is under mediation or it was charged-back.', 'woocommerce-mercadopago-module' )
1816
+ );
1817
+ break;
1818
+ case 'charged-back':
1819
+ $order->add_order_note(
1820
+ 'Mercado Pago: ' .
1821
+ __( 'The payment is under mediation or it was charged-back.', 'woocommerce-mercadopago-module' )
1822
+ );
1823
+ break;
1824
+ default:
1825
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1826
  }
1827
  }
1828
+
1829
  }
1830
 
1831
+ new WC_WooMercadoPagoTicket_Gateway( true );
mercadopago/sdk/lib/mercadopago.php CHANGED
@@ -1,527 +1,756 @@
1
  <?php
2
 
3
  /**
4
- * MercadoPago Integration Library
5
- * Access MercadoPago for payments integration
6
- *
7
- * @author hcasatti
8
- *
9
  */
10
- $GLOBALS["LIB_LOCATION"] = dirname(__FILE__);
 
11
 
12
  class MP {
13
 
14
- const version = "0.5.2";
15
-
16
- private $client_id;
17
- private $client_secret;
18
- private $ll_access_token;
19
- private $access_data;
20
- private $sandbox = FALSE;
21
-
22
- function __construct() {
23
- $i = func_num_args();
24
-
25
- if ($i > 2 || $i < 1) {
26
- throw new MercadoPagoException("Invalid arguments. Use CLIENT_ID and CLIENT SECRET, or ACCESS_TOKEN");
27
- }
28
-
29
- if ($i == 1) {
30
- $this->ll_access_token = func_get_arg(0);
31
- }
32
-
33
- if ($i == 2) {
34
- $this->client_id = func_get_arg(0);
35
- $this->client_secret = func_get_arg(1);
36
- }
37
- }
38
-
39
- public function sandbox_mode($enable = NULL) {
40
- if (!is_null($enable)) {
41
- $this->sandbox = $enable === TRUE;
42
- }
43
-
44
- return $this->sandbox;
45
- }
46
-
47
- /**
48
- * Get Access Token for API use
49
- */
50
- public function get_access_token() {
51
- if (isset ($this->ll_access_token) && !is_null($this->ll_access_token)) {
52
- return $this->ll_access_token;
53
- }
54
-
55
- $app_client_values = array(
56
- 'client_id' => $this->client_id,
57
- 'client_secret' => $this->client_secret,
58
- 'grant_type' => 'client_credentials'
59
- );
60
-
61
- $access_data = MPRestClient::post(array(
62
- "uri" => "/oauth/token",
63
- "data" => $app_client_values,
64
- "headers" => array(
65
- "content-type" => "application/x-www-form-urlencoded"
66
- )
67
- ));
68
-
69
- if ($access_data["status"] != 200) {
70
- throw new MercadoPagoException ($access_data['response']['message'], $access_data['status']);
71
- }
72
-
73
- $this->access_data = $access_data['response'];
74
-
75
- return $this->access_data['access_token'];
76
- }
77
-
78
- /* APIs v1 */
79
- /**
80
- * Create a payment v1
81
- * @param array $preference
82
- * @return array(json)
83
- */
84
- public function search_paymentV1($id) {
85
- $request = array(
86
- "uri" => "/v1/payments/" . $id,
87
- "params" => array(
88
- "access_token" => $this->get_access_token()
89
- )
90
- );
91
- $payment = MPRestClient::get($request);
92
- return $payment;
93
- }
94
- public function get_or_create_customer($payer_email) {
95
- $customer = $this->search_customer($payer_email);
96
- if ($customer['status'] == 200 && $customer['response']['paging']['total'] > 0) {
97
- $customer = $customer['response']['results'][0];
98
- } else {
99
- $resp = $this->create_customer($payer_email);
100
- $customer = $resp['response'];
101
- }
102
- return $customer;
103
- }
104
- public function create_customer($email) {
105
- $request = array(
106
- "uri" => "/v1/customers",
107
- "params" => array(
108
- "access_token" => $this->get_access_token()
109
- ),
110
- "data" => array(
111
- "email" => $email
112
- )
113
- );
114
- $customer = MPRestClient::post($request);
115
- return $customer;
116
- }
117
- public function search_customer($email) {
118
- $request = array(
119
- "uri" => "/v1/customers/search",
120
- "params" => array(
121
- "access_token" => $this->get_access_token(),
122
- "email" => $email
123
- )
124
- );
125
- $customer = MPRestClient::get($request);
126
- return $customer;
127
- }
128
- public function create_card_in_customer($customer_id, $token, $payment_method_id = null, $issuer_id = null) {
129
- $request = array(
130
- "uri" => "/v1/customers/" . $customer_id . "/cards",
131
- "params" => array(
132
- "access_token" => $this->get_access_token()
133
- ),
134
- "data" => array(
135
- "token" => $token,
136
- "issuer_id" => $issuer_id,
137
- "payment_method_id" => $payment_method_id
138
- )
139
- );
140
- $card = MPRestClient::post($request);
141
- return $card;
142
- }
143
- public function get_all_customer_cards($customer_id, $token) {
144
- $request = array(
145
- "uri" => "/v1/customers/" . $customer_id . "/cards",
146
- "params" => array(
147
- "access_token" => $this->get_access_token()
148
- )
149
- );
150
- $cards = MPRestClient::get($request);
151
- return $cards;
152
- }
153
-
154
- public function check_discount_campaigns($transaction_amount, $payer_email, $coupon_code) {
155
- $request = array(
156
- "uri" => "/discount_campaigns",
157
- "params" => array(
158
- "access_token" => $this->get_access_token(),
159
- "transaction_amount" => $transaction_amount,
160
- "payer_email" => $payer_email,
161
- "coupon_code" => $coupon_code
162
- )
163
- );
164
-
165
- $discount_info = MPRestClient::get($request);
166
- return $discount_info;
167
- }
168
-
169
- /**
170
- * Get information for specific payment
171
- * @param int $id
172
- * @return array(json)
173
- */
174
- public function get_payment($id) {
175
- $uri_prefix = $this->sandbox ? "/sandbox" : "";
176
-
177
- $request = array(
178
- "uri" => $uri_prefix."/collections/notifications/{$id}",
179
- "params" => array(
180
- "access_token" => $this->get_access_token()
181
- )
182
- );
183
-
184
- $payment_info = MPRestClient::get($request);
185
- return $payment_info;
186
- }
187
- public function get_payment_info($id) {
188
- return $this->get_payment($id);
189
- }
190
-
191
- /**
192
- * Get information for specific authorized payment
193
- * @param id
194
- * @return array(json)
195
- */
196
- public function get_authorized_payment($id) {
197
- $request = array(
198
- "uri" => "/authorized_payments/{$id}",
199
- "params" => array(
200
- "access_token" => $this->get_access_token()
201
- )
202
- );
203
-
204
- $authorized_payment_info = MPRestClient::get($request);
205
- return $authorized_payment_info;
206
- }
207
-
208
- /**
209
- * Refund accredited payment
210
- * @param int $id
211
- * @return array(json)
212
- */
213
- public function refund_payment($id) {
214
- $request = array(
215
- "uri" => "/collections/{$id}",
216
- "params" => array(
217
- "access_token" => $this->get_access_token()
218
- ),
219
- "data" => array(
220
- "status" => "refunded"
221
- )
222
- );
223
-
224
- $response = MPRestClient::put($request);
225
- return $response;
226
- }
227
-
228
- /**
229
- * Cancel pending payment
230
- * @param int $id
231
- * @return array(json)
232
- */
233
- public function cancel_payment($id) {
234
- $request = array(
235
- "uri" => "/collections/{$id}",
236
- "params" => array(
237
- "access_token" => $this->get_access_token()
238
- ),
239
- "data" => array(
240
- "status" => "cancelled"
241
- )
242
- );
243
-
244
- $response = MPRestClient::put($request);
245
- return $response;
246
- }
247
-
248
- /**
249
- * Cancel preapproval payment
250
- * @param int $id
251
- * @return array(json)
252
- */
253
- public function cancel_preapproval_payment($id) {
254
- $request = array(
255
- "uri" => "/preapproval/{$id}",
256
- "params" => array(
257
- "access_token" => $this->get_access_token()
258
- ),
259
- "data" => array(
260
- "status" => "cancelled"
261
- )
262
- );
263
-
264
- $response = MPRestClient::put($request);
265
- return $response;
266
- }
267
-
268
- /**
269
- * Search payments according to filters, with pagination
270
- * @param array $filters
271
- * @param int $offset
272
- * @param int $limit
273
- * @return array(json)
274
- */
275
- public function search_payment($filters, $offset = 0, $limit = 0) {
276
- $filters["offset"] = $offset;
277
- $filters["limit"] = $limit;
278
-
279
- $uri_prefix = $this->sandbox ? "/sandbox" : "";
280
-
281
- $request = array(
282
- "uri" => $uri_prefix."/collections/search",
283
- "params" => array_merge ($filters, array(
284
- "access_token" => $this->get_access_token()
285
- ))
286
- );
287
-
288
- $collection_result = MPRestClient::get($request);
289
- return $collection_result;
290
- }
291
-
292
- /**
293
- * Create a checkout preference
294
- * @param array $preference
295
- * @return array(json)
296
- */
297
- public function create_preference($preference) {
298
- $request = array(
299
- "uri" => "/checkout/preferences",
300
- "params" => array(
301
- "access_token" => $this->get_access_token()
302
- ),
303
- "headers" => array(
304
- "user-agent" => "platform:desktop,type:woocommerce,so:2.1.0"
305
- ),
306
- "data" => $preference
307
- );
308
-
309
- $preference_result = MPRestClient::post($request);
310
- return $preference_result;
311
- }
312
-
313
- /**
314
- * Update a checkout preference
315
- * @param string $id
316
- * @param array $preference
317
- * @return array(json)
318
- */
319
- public function update_preference($id, $preference) {
320
- $request = array(
321
- "uri" => "/checkout/preferences/{$id}",
322
- "params" => array(
323
- "access_token" => $this->get_access_token()
324
- ),
325
- "data" => $preference
326
- );
327
-
328
- $preference_result = MPRestClient::put($request);
329
- return $preference_result;
330
- }
331
-
332
- /**
333
- * Get a checkout preference
334
- * @param string $id
335
- * @return array(json)
336
- */
337
- public function get_preference($id) {
338
- $request = array(
339
- "uri" => "/checkout/preferences/{$id}",
340
- "params" => array(
341
- "access_token" => $this->get_access_token()
342
- )
343
- );
344
-
345
- $preference_result = MPRestClient::get($request);
346
- return $preference_result;
347
- }
348
-
349
- /**
350
- * Create a checkout preference
351
- * @param array $preference
352
- * @return array(json)
353
- */
354
- public function create_payment($preference) {
355
- $request = array(
356
- "uri" => "/v1/payments",
357
- "params" => array(
358
- "access_token" => $this->get_access_token()
359
- ),
360
- "headers" => array(
361
- "X-Tracking-Id" => "platform:v1-whitelabel,type:woocommerce,so:2.1.0"
362
- ),
363
- "data" => $preference
364
- );
365
- $payment = MPRestClient::post($request);
366
- return $payment;
367
- }
368
-
369
- /**
370
- * Create a preapproval payment
371
- * @param array $preapproval_payment
372
- * @return array(json)
373
- */
374
- public function create_preapproval_payment($preapproval_payment) {
375
- $request = array(
376
- "uri" => "/preapproval",
377
- "params" => array(
378
- "access_token" => $this->get_access_token()
379
- ),
380
- "data" => $preapproval_payment
381
- );
382
-
383
- $preapproval_payment_result = MPRestClient::post($request);
384
- return $preapproval_payment_result;
385
- }
386
-
387
- /**
388
- * Get a preapproval payment
389
- * @param string $id
390
- * @return array(json)
391
- */
392
- public function get_preapproval_payment($id) {
393
- $request = array(
394
- "uri" => "/preapproval/{$id}",
395
- "params" => array(
396
- "access_token" => $this->get_access_token()
397
- )
398
- );
399
-
400
- $preapproval_payment_result = MPRestClient::get($request);
401
- return $preapproval_payment_result;
402
- }
403
-
404
- /**
405
- * Update a preapproval payment
406
- * @param string $preapproval_payment, $id
407
- * @return array(json)
408
- */
409
-
410
- public function update_preapproval_payment($id, $preapproval_payment) {
411
- $request = array(
412
- "uri" => "/preapproval/{$id}",
413
- "params" => array(
414
- "access_token" => $this->get_access_token()
415
- ),
416
- "data" => $preapproval_payment
417
- );
418
-
419
- $preapproval_payment_result = MPRestClient::put($request);
420
- return $preapproval_payment_result;
421
- }
422
-
423
- /* Generic resource call methods */
424
-
425
- /**
426
- * Generic resource get
427
- * @param request
428
- * @param params (deprecated)
429
- * @param authenticate = true (deprecated)
430
- */
431
- public function get($request, $params = null, $authenticate = true) {
432
- if (is_string ($request)) {
433
- $request = array(
434
- "uri" => $request,
435
- "params" => $params,
436
- "authenticate" => $authenticate
437
- );
438
- }
439
-
440
- $request["params"] = isset ($request["params"]) && is_array ($request["params"]) ? $request["params"] : array();
441
-
442
- if (!isset ($request["authenticate"]) || $request["authenticate"] !== false) {
443
- $request["params"]["access_token"] = $this->get_access_token();
444
- }
445
-
446
- $result = MPRestClient::get($request);
447
- return $result;
448
- }
449
-
450
- /**
451
- * Generic resource post
452
- * @param request
453
- * @param data (deprecated)
454
- * @param params (deprecated)
455
- */
456
- public function post($request, $data = null, $params = null) {
457
- if (is_string ($request)) {
458
- $request = array(
459
- "uri" => $request,
460
- "data" => $data,
461
- "params" => $params
462
- );
463
- }
464
-
465
- $request["params"] = isset ($request["params"]) && is_array ($request["params"]) ? $request["params"] : array();
466
-
467
- if (!isset ($request["authenticate"]) || $request["authenticate"] !== false) {
468
- $request["params"]["access_token"] = $this->get_access_token();
469
- }
470
-
471
- $result = MPRestClient::post($request);
472
- return $result;
473
- }
474
-
475
- /**
476
- * Generic resource put
477
- * @param request
478
- * @param data (deprecated)
479
- * @param params (deprecated)
480
- */
481
- public function put($request, $data = null, $params = null) {
482
- if (is_string ($request)) {
483
- $request = array(
484
- "uri" => $request,
485
- "data" => $data,
486
- "params" => $params
487
- );
488
- }
489
-
490
- $request["params"] = isset ($request["params"]) && is_array ($request["params"]) ? $request["params"] : array();
491
-
492
- if (!isset ($request["authenticate"]) || $request["authenticate"] !== false) {
493
- $request["params"]["access_token"] = $this->get_access_token();
494
- }
495
-
496
- $result = MPRestClient::put($request);
497
- return $result;
498
- }
499
-
500
- /**
501
- * Generic resource delete
502
- * @param request
503
- * @param data (deprecated)
504
- * @param params (deprecated)
505
- */
506
- public function delete($request, $params = null) {
507
- if (is_string ($request)) {
508
- $request = array(
509
- "uri" => $request,
510
- "params" => $params
511
- );
512
- }
513
-
514
- $request["params"] = isset ($request["params"]) && is_array ($request["params"]) ? $request["params"] : array();
515
-
516
- if (!isset ($request["authenticate"]) || $request["authenticate"] !== false) {
517
- $request["params"]["access_token"] = $this->get_access_token();
518
- }
519
-
520
- $result = MPRestClient::delete($request);
521
- return $result;
522
- }
523
-
524
- /* **************************************************************************************** */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
 
526
  }
527
 
@@ -529,287 +758,471 @@ class MP {
529
  * MercadoPago cURL RestClient
530
  */
531
  class MPRestClient {
532
- const API_BASE_URL = "https://api.mercadopago.com";
533
- const API_BASE_ML_URL = "https://api.mercadolibre.com";
534
-
535
- private static function build_request_ml($request) {
536
- if (!extension_loaded ("curl")) {
537
- throw new MercadoPagoException("cURL extension not found. You need to enable cURL in your php.ini or another configuration you have.");
538
- }
539
-
540
- if (!isset($request["method"])) {
541
- throw new MercadoPagoException("No HTTP METHOD specified");
542
- }
543
-
544
- if (!isset($request["uri"])) {
545
- throw new MercadoPagoException("No URI specified");
546
- }
547
-
548
- // Set headers
549
- $headers = array("accept: application/json");
550
- $json_content = true;
551
- $form_content = false;
552
- $default_content_type = true;
553
-
554
- if (isset($request["headers"]) && is_array($request["headers"])) {
555
- foreach ($request["headers"] as $h => $v) {
556
- $h = strtolower($h);
557
- $v = strtolower($v);
558
-
559
- if ($h == "content-type") {
560
- $default_content_type = false;
561
- $json_content = $v == "application/json";
562
- $form_content = $v == "application/x-www-form-urlencoded";
563
- }
564
-
565
- array_push ($headers, $h.": ".$v);
566
- }
567
- }
568
- if ($default_content_type) {
569
- array_push($headers, "content-type: application/json");
570
- }
571
-
572
- // Build $connect
573
- $connect = curl_init();
574
-
575
- curl_setopt($connect, CURLOPT_USERAGENT, "MercadoPago PHP SDK v" . MP::version);
576
- curl_setopt($connect, CURLOPT_RETURNTRANSFER, true);
577
- curl_setopt($connect, CURLOPT_SSL_VERIFYPEER, true);
578
- curl_setopt($connect, CURLOPT_CAINFO, $GLOBALS["LIB_LOCATION"] . "/cacert.pem");
579
- curl_setopt($connect, CURLOPT_CUSTOMREQUEST, $request["method"]);
580
- curl_setopt($connect, CURLOPT_HTTPHEADER, $headers);
581
-
582
- // Set parameters and url
583
- if (isset ($request["params"]) && is_array($request["params"]) && count($request["params"]) > 0) {
584
- $request["uri"] .= (strpos($request["uri"], "?") === false) ? "?" : "&";
585
- $request["uri"] .= self::build_query($request["params"]);
586
- }
587
- curl_setopt($connect, CURLOPT_URL, self::API_BASE_ML_URL . $request["uri"]);
588
-
589
- // Set data
590
- if (isset($request["data"])) {
591
- if ($json_content) {
592
- if (gettype($request["data"]) == "string") {
593
- json_decode($request["data"], true);
594
- } else {
595
- $request["data"] = json_encode($request["data"]);
596
- }
597
-
598
- if(function_exists('json_last_error')) {
599
- $json_error = json_last_error();
600
- if ($json_error != JSON_ERROR_NONE) {
601
- throw new MercadoPagoException("JSON Error [{$json_error}] - Data: ".$request["data"]);
602
- }
603
- }
604
- } else if ($form_content) {
605
- $request["data"] = self::build_query($request["data"]);
606
- }
607
-
608
- curl_setopt($connect, CURLOPT_POSTFIELDS, $request["data"]);
609
- }
610
-
611
- return $connect;
612
- }
613
-
614
- private static function build_request($request) {
615
- if (!extension_loaded ("curl")) {
616
- throw new MercadoPagoException("cURL extension not found. You need to enable cURL in your php.ini or another configuration you have.");
617
- }
618
-
619
- if (!isset($request["method"])) {
620
- throw new MercadoPagoException("No HTTP METHOD specified");
621
- }
622
-
623
- if (!isset($request["uri"])) {
624
- throw new MercadoPagoException("No URI specified");
625
- }
626
-
627
- // Set headers
628
- $headers = array("accept: application/json");
629
- $json_content = true;
630
- $form_content = false;
631
- $default_content_type = true;
632
-
633
- if (isset($request["headers"]) && is_array($request["headers"])) {
634
- foreach ($request["headers"] as $h => $v) {
635
- $h = strtolower($h);
636
- $v = strtolower($v);
637
-
638
- if ($h == "content-type") {
639
- $default_content_type = false;
640
- $json_content = $v == "application/json";
641
- $form_content = $v == "application/x-www-form-urlencoded";
642
- }
643
-
644
- array_push ($headers, $h.": ".$v);
645
- }
646
- }
647
- if ($default_content_type) {
648
- array_push($headers, "content-type: application/json");
649
- }
650
-
651
- // Build $connect
652
- $connect = curl_init();
653
-
654
- curl_setopt($connect, CURLOPT_USERAGENT, "MercadoPago PHP SDK v" . MP::version);
655
- curl_setopt($connect, CURLOPT_RETURNTRANSFER, true);
656
- curl_setopt($connect, CURLOPT_SSL_VERIFYPEER, true);
657
- curl_setopt($connect, CURLOPT_CAINFO, $GLOBALS["LIB_LOCATION"] . "/cacert.pem");
658
- curl_setopt($connect, CURLOPT_CUSTOMREQUEST, $request["method"]);
659
- curl_setopt($connect, CURLOPT_HTTPHEADER, $headers);
660
-
661
- // Set parameters and url
662
- if (isset ($request["params"]) && is_array($request["params"]) && count($request["params"]) > 0) {
663
- $request["uri"] .= (strpos($request["uri"], "?") === false) ? "?" : "&";
664
- $request["uri"] .= self::build_query($request["params"]);
665
- }
666
- curl_setopt($connect, CURLOPT_URL, self::API_BASE_URL . $request["uri"]);
667
-
668
- // Set data
669
- if (isset($request["data"])) {
670
- if ($json_content) {
671
- if (gettype($request["data"]) == "string") {
672
- json_decode($request["data"], true);
673
- } else {
674
- $request["data"] = json_encode($request["data"]);
675
- }
676
-
677
- if(function_exists('json_last_error')) {
678
- $json_error = json_last_error();
679
- if ($json_error != JSON_ERROR_NONE) {
680
- throw new MercadoPagoException("JSON Error [{$json_error}] - Data: ".$request["data"]);
681
- }
682
- }
683
- } else if ($form_content) {
684
- $request["data"] = self::build_query($request["data"]);
685
- }
686
-
687
- curl_setopt($connect, CURLOPT_POSTFIELDS, $request["data"]);
688
- }
689
-
690
- return $connect;
691
- }
692
-
693
- private static function exec_ml($request) {
694
- // private static function exec($method, $uri, $data, $content_type) {
695
-
696
- $connect = self::build_request_ml($request);
697
-
698
- $api_result = curl_exec($connect);
699
- $api_http_code = curl_getinfo($connect, CURLINFO_HTTP_CODE);
700
-
701
- if ($api_result === FALSE) {
702
- throw new MercadoPagoException (curl_error ($connect));
703
- }
704
-
705
- $response = array(
706
- "status" => $api_http_code,
707
- "response" => json_decode($api_result, true)
708
- );
709
-
710
- /*if ($response['status'] >= 400) {
711
- $message = $response['response']['message'];
712
- if (isset ($response['response']['cause'])) {
713
- if (isset ($response['response']['cause']['code']) && isset ($response['response']['cause']['description'])) {
714
- $message .= " - ".$response['response']['cause']['code'].': '.$response['response']['cause']['description'];
715
- } else if (is_array ($response['response']['cause'])) {
716
- foreach ($response['response']['cause'] as $cause) {
717
- $message .= " - ".$cause['code'].': '.$cause['description'];
718
- }
719
- }
720
- }
721
-
722
- throw new MercadoPagoException ($message, $response['status']);
723
- }*/
724
-
725
- curl_close($connect);
726
-
727
- return $response;
728
- }
729
-
730
- private static function exec($request) {
731
- // private static function exec($method, $uri, $data, $content_type) {
732
-
733
- $connect = self::build_request($request);
734
-
735
- $api_result = curl_exec($connect);
736
- $api_http_code = curl_getinfo($connect, CURLINFO_HTTP_CODE);
737
-
738
- if ($api_result === FALSE) {
739
- throw new MercadoPagoException (curl_error ($connect));
740
- }
741
-
742
- $response = array(
743
- "status" => $api_http_code,
744
- "response" => json_decode($api_result, true)
745
- );
746
-
747
- /*if ($response['status'] >= 400) {
748
- $message = $response['response']['message'];
749
- if (isset ($response['response']['cause'])) {
750
- if (isset ($response['response']['cause']['code']) && isset ($response['response']['cause']['description'])) {
751
- $message .= " - ".$response['response']['cause']['code'].': '.$response['response']['cause']['description'];
752
- } else if (is_array ($response['response']['cause'])) {
753
- foreach ($response['response']['cause'] as $cause) {
754
- $message .= " - ".$cause['code'].': '.$cause['description'];
755
- }
756
- }
757
- }
758
-
759
- throw new MercadoPagoException ($message, $response['status']);
760
- }*/
761
-
762
- curl_close($connect);
763
-
764
- return $response;
765
- }
766
-
767
- private static function build_query($params) {
768
- if (function_exists("http_build_query")) {
769
- return http_build_query($params, "", "&");
770
- } else {
771
- foreach ($params as $name => $value) {
772
- $elements[] = "{$name}=" . urlencode($value);
773
- }
774
 
775
- return implode("&", $elements);
776
- }
777
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
778
 
779
- public static function get_ml($request) {
780
- $request["method"] = "GET";
 
 
 
 
 
 
781
 
782
- return self::exec_ml($request);
783
- }
784
 
785
- public static function get($request) {
786
- $request["method"] = "GET";
 
 
 
787
 
788
- return self::exec($request);
789
- }
790
 
791
- public static function post($request) {
792
- $request["method"] = "POST";
793
 
794
- return self::exec($request);
795
- }
796
 
797
- public static function put($request) {
798
- $request["method"] = "PUT";
799
 
800
- return self::exec($request);
801
- }
802
 
803
- public static function delete($request) {
804
- $request["method"] = "DELETE";
805
 
806
- return self::exec($request);
807
- }
808
  }
809
 
810
  class MercadoPagoException extends Exception {
811
- public function __construct($message, $code = 500, Exception $previous = null) {
812
- // Default code 500
813
- parent::__construct($message, $code, $previous);
814
- }
815
- }
1
  <?php
2
 
3
  /**
4
+ * Part of Woo Mercado Pago Module - MercadoPago Integration Library, Access MercadoPago for payments integration
5
+ * Author - Mercado Pago
6
+ * Developer - hcasatti, Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
7
+ * Copyright - Copyright(c) MercadoPago [https://www.mercadopago.com]
8
+ * License - https://www.gnu.org/licenses/gpl.html GPL version 2 or higher
9
  */
10
+
11
+ $GLOBALS['LIB_LOCATION'] = dirname( __FILE__ );
12
 
13
  class MP {
14
 
15
+ private $version = '2.2.13';
16
+ private $client_id;
17
+ private $client_secret;
18
+ private $ll_access_token;
19
+ private $sandbox = FALSE;
20
+
21
+ /**
22
+ * Summary: Constructor.
23
+ * Description: Build an object with module version and credentials.
24
+ */
25
+ function __construct() {
26
+
27
+ $i = func_num_args();
28
+
29
+ if ( $i > 3 || $i < 2 ) {
30
+ throw new MercadoPagoException(
31
+ 'Invalid arguments. Use CLIENT_ID and CLIENT SECRET, or ACCESS_TOKEN'
32
+ );
33
+ }
34
+
35
+ if ( $i == 2 ) {
36
+ $this->version = func_get_arg( 0 );
37
+ $this->ll_access_token = func_get_arg( 1 );
38
+ }
39
+
40
+ if ( $i == 3 ) {
41
+ $this->version = func_get_arg( 0 );
42
+ $this->client_id = func_get_arg( 1 );
43
+ $this->client_secret = func_get_arg( 2 );
44
+ }
45
+
46
+ }
47
+
48
+ public function sandbox_mode( $enable = NULL ) {
49
+ if ( ! is_null( $enable ) ) {
50
+ $this->sandbox = $enable === TRUE;
51
+ }
52
+ return $this->sandbox;
53
+ }
54
+
55
+ /**
56
+ * Summary: Get Access Token for API use.
57
+ * Description: Get Access Token for API use.
58
+ * @return a string that identifies the access token.
59
+ */
60
+ public function get_access_token() {
61
+
62
+ if ( isset( $this->ll_access_token ) && ! is_null( $this->ll_access_token ) ) {
63
+ return $this->ll_access_token;
64
+ }
65
+
66
+ $app_client_values = array(
67
+ 'client_id' => $this->client_id,
68
+ 'client_secret' => $this->client_secret,
69
+ 'grant_type' => 'client_credentials'
70
+ );
71
+
72
+ $access_data = MPRestClient::post(
73
+ array(
74
+ 'uri' => '/oauth/token',
75
+ 'data' => $app_client_values,
76
+ 'headers' => array(
77
+ 'content-type' => 'application/x-www-form-urlencoded'
78
+ )
79
+ ),
80
+ $this->version
81
+ );
82
+
83
+ if ( $access_data['status'] != 200 ) {
84
+ return null;
85
+ }
86
+
87
+ $access_data = $access_data['response'];
88
+ return $access_data['access_token'];
89
+
90
+ }
91
+
92
+ /**
93
+ * Summary: Search for a payment given its id.
94
+ * Description: Search for a payment given its id.
95
+ * @param string $id
96
+ * @return array( json )
97
+ */
98
+ public function search_paymentV1( $id ) {
99
+
100
+ $request = array(
101
+ 'uri' => '/v1/payments/' . $id,
102
+ 'params' => array(
103
+ 'access_token' => $this->get_access_token()
104
+ )
105
+ );
106
+
107
+ $payment = MPRestClient::get( $request, $this->version );
108
+ return $payment;
109
+
110
+ }
111
+
112
+ //=== CUSTOMER CARDS FUNCTIONS ===
113
+
114
+ /**
115
+ * Summary: Trigger API to find a card owner and create him if dont find.
116
+ * Description: Trigger API to find a card owner and create him if dont find.
117
+ * @param string $payer_email
118
+ * @return array( json )
119
+ */
120
+ public function get_or_create_customer( $payer_email ) {
121
+
122
+ $customer = $this->search_customer( $payer_email );
123
+
124
+ if ( $customer['status'] == 200 && $customer['response']['paging']['total'] > 0 ) {
125
+ $customer = $customer['response']['results'][0];
126
+ } else {
127
+ $resp = $this->create_customer( $payer_email );
128
+ $customer = $resp['response'];
129
+ }
130
+
131
+ return $customer;
132
+
133
+ }
134
+
135
+ /**
136
+ * Summary: Create a card owner.
137
+ * Description: Create a card owner.
138
+ * @param string $payer_email
139
+ * @return array( json )
140
+ */
141
+ public function create_customer( $email ) {
142
+
143
+ $request = array(
144
+ 'uri' => '/v1/customers',
145
+ 'params' => array(
146
+ 'access_token' => $this->get_access_token()
147
+ ),
148
+ 'data' => array(
149
+ 'email' => $email
150
+ )
151
+ );
152
+
153
+ $customer = MPRestClient::post( $request, $this->version );
154
+ return $customer;
155
+
156
+ }
157
+
158
+ /**
159
+ * Summary: Try to find a card owner.
160
+ * Description: Try to find a card owner.
161
+ * @param string $payer_email
162
+ * @return array( json )
163
+ */
164
+ public function search_customer( $email ) {
165
+
166
+ $request = array(
167
+ 'uri' => '/v1/customers/search',
168
+ 'params' => array(
169
+ 'access_token' => $this->get_access_token(),
170
+ 'email' => $email
171
+ )
172
+ );
173
+
174
+ $customer = MPRestClient::get( $request, $this->version );
175
+ return $customer;
176
+
177
+ }
178
+
179
+ /**
180
+ * Summary: Given a customer, create a card for him.
181
+ * Description: Given a customer, create a card for him.
182
+ * @param string $customer_id
183
+ * @param string $token
184
+ * @param string $payment_method_id
185
+ * @param string $issuer_id
186
+ * @return array( json )
187
+ */
188
+ public function create_card_in_customer( $customer_id, $token, $payment_method_id = null,
189
+ $issuer_id = null ) {
190
+
191
+ $request = array(
192
+ 'uri' => '/v1/customers/' . $customer_id . '/cards',
193
+ 'params' => array(
194
+ 'access_token' => $this->get_access_token()
195
+ ),
196
+ 'data' => array(
197
+ 'token' => $token,
198
+ 'issuer_id' => $issuer_id,
199
+ 'payment_method_id' => $payment_method_id
200
+ )
201
+ );
202
+
203
+ $card = MPRestClient::post( $request, $this->version );
204
+ return $card;
205
+
206
+ }
207
+
208
+ /**
209
+ * Summary: Given a customer, find all of his cards.
210
+ * Description: Given a customer, find all of his cards.
211
+ * @param string $customer_id
212
+ * @param string $token
213
+ * @return array( json )
214
+ */
215
+ public function get_all_customer_cards( $customer_id, $token ) {
216
+
217
+ $request = array(
218
+ 'uri' => '/v1/customers/' . $customer_id . '/cards',
219
+ 'params' => array(
220
+ 'access_token' => $this->get_access_token()
221
+ )
222
+ );
223
+
224
+ $cards = MPRestClient::get( $request, $this->version );
225
+ return $cards;
226
+
227
+ }
228
+
229
+ //=== COUPOM AND DISCOUNTS FUNCTIONS ===
230
+
231
+ /**
232
+ * Summary: Check for discounts for a combination of amount, payer and coupm code.
233
+ * Description: Check for discounts for a combination of amount, payer and coupm code.
234
+ * @param string $transaction_amount
235
+ * @param string $payer_email
236
+ * @param string $coupon_code
237
+ * @return array( json )
238
+ */
239
+ public function check_discount_campaigns( $transaction_amount, $payer_email, $coupon_code ) {
240
+
241
+ $request = array(
242
+ 'uri' => '/discount_campaigns',
243
+ 'params' => array(
244
+ 'access_token' => $this->get_access_token(),
245
+ 'transaction_amount' => $transaction_amount,
246
+ 'payer_email' => $payer_email,
247
+ 'coupon_code' => $coupon_code
248
+ )
249
+ );
250
+
251
+ $discount_info = MPRestClient::get( $request, $this->version );
252
+ return $discount_info;
253
+
254
+ }
255
+
256
+ //=== ACCOUNT SETTINGS FUNCTIONS ===
257
+
258
+ /**
259
+ * Summary: Check the status of a account regarding its option to use two cards for pay.
260
+ * Description: Check the status of a account regarding its option to use two cards for pay.
261
+ * @return array( json )
262
+ */
263
+ public function check_two_cards() {
264
+
265
+ $request = array(
266
+ 'uri' => '/account/settings?access_token=' . $this->get_access_token()
267
+ );
268
+
269
+ $two_cards_info = MPRestClient::get( $request, $this->version );
270
+ if ( $two_cards_info['status'] == 200 )
271
+ return $two_cards_info['response']['two_cards'];
272
+ else {
273
+ return 'inactive';
274
+ }
275
+
276
+ }
277
+
278
+ /**
279
+ * Summary: Set paymennts with two cards for the merchant.
280
+ * Description: Set paymennts with two cards for the merchant.
281
+ * @param string $mode ( should be 'active' or 'inactive' string )
282
+ * @return array( json )
283
+ */
284
+ public function set_two_cards_mode( $mode ) {
285
+
286
+ $request = array(
287
+ 'uri' => '/account/settings?access_token=' . $this->get_access_token(),
288
+ 'data' => array(
289
+ 'two_cards' => $mode
290
+ ),
291
+ 'headers' => array(
292
+ 'content-type' => 'application/json'
293
+ )
294
+ );
295
+
296
+ $two_cards_info = MPRestClient::put( $request, $this->version );
297
+ return $two_cards_info;
298
+
299
+ }
300
+
301
+ //=== CHECKOUT AUXILIARY FUNCTIONS ===
302
+
303
+ /**
304
+ * Summary: Get information for specific payment.
305
+ * Description: Get information for specific payment.
306
+ * @param int $id
307
+ * @return array( json )
308
+ */
309
+ public function get_payment_info( $id ) {
310
+
311
+ $uri_prefix = $this->sandbox ? '/sandbox' : '';
312
+
313
+ $request = array(
314
+ 'uri' => $uri_prefix.'/collections/notifications/{$id}',
315
+ 'params' => array(
316
+ 'access_token' => $this->get_access_token()
317
+ )
318
+ );
319
+
320
+ $payment_info = MPRestClient::get( $request, $this->version );
321
+ return $payment_info;
322
+
323
+ }
324
+
325
+ /**
326
+ * Summary: Search payments according to filters, with pagination.
327
+ * Description: Search payments according to filters, with pagination.
328
+ * @param array $filters
329
+ * @param int $offset
330
+ * @param int $limit
331
+ * @return array( json )
332
+ */
333
+ public function search_payment( $filters, $offset = 0, $limit = 0 ) {
334
+
335
+ $filters['offset'] = $offset;
336
+ $filters['limit'] = $limit;
337
+
338
+ $uri_prefix = $this->sandbox ? '/sandbox' : '';
339
+
340
+ $request = array(
341
+ 'uri' => $uri_prefix . '/collections/search',
342
+ 'params' => array_merge ( $filters, array(
343
+ 'access_token' => $this->get_access_token()
344
+ ) )
345
+ );
346
+
347
+ $collection_result = MPRestClient::get( $request, $this->version );
348
+ return $collection_result;
349
+
350
+ }
351
+
352
+ /**
353
+ * Summary: Get information for specific authorized payment.
354
+ * Description: Get information for specific authorized payment.
355
+ * @param id
356
+ * @return array( json )
357
+ */
358
+ public function get_authorized_payment( $id ) {
359
+
360
+ $request = array(
361
+ 'uri' => '/authorized_payments/{$id}',
362
+ 'params' => array(
363
+ 'access_token' => $this->get_access_token()
364
+ )
365
+ );
366
+
367
+ $authorized_payment_info = MPRestClient::get( $request, $this->version );
368
+ return $authorized_payment_info;
369
+
370
+ }
371
+
372
+ /**
373
+ * Summary: Create a checkout preference.
374
+ * Description: Create a checkout preference.
375
+ * @param array $preference
376
+ * @return array( json )
377
+ */
378
+ public function create_preference( $preference ) {
379
+
380
+ $request = array(
381
+ 'uri' => '/checkout/preferences',
382
+ 'params' => array(
383
+ 'access_token' => $this->get_access_token()
384
+ ),
385
+ 'headers' => array(
386
+ 'user-agent' => 'platform:desktop,type:woocommerce,so:' . $this->version
387
+ ),
388
+ 'data' => $preference
389
+ );
390
+
391
+ $preference_result = MPRestClient::post( $request, $this->version );
392
+ return $preference_result;
393
+
394
+ }
395
+
396
+ /**
397
+ * Summary: Update a checkout preference.
398
+ * Description: Update a checkout preference.
399
+ * @param string $id
400
+ * @param array $preference
401
+ * @return array( json )
402
+ */
403
+ public function update_preference( $id, $preference ) {
404
+
405
+ $request = array(
406
+ 'uri' => '/checkout/preferences/{$id}',
407
+ 'params' => array(
408
+ 'access_token' => $this->get_access_token()
409
+ ),
410
+ 'data' => $preference
411
+ );
412
+
413
+ $preference_result = MPRestClient::put( $request, $this->version );
414
+ return $preference_result;
415
+
416
+ }
417
+
418
+ /**
419
+ * Summary: Get a checkout preference.
420
+ * Description: Get a checkout preference.
421
+ * @param string $id
422
+ * @return array( json )
423
+ */
424
+ public function get_preference( $id ) {
425
+
426
+ $request = array(
427
+ 'uri' => '/checkout/preferences/{$id}',
428
+ 'params' => array(
429
+ 'access_token' => $this->get_access_token()
430
+ )
431
+ );
432
+
433
+ $preference_result = MPRestClient::get( $request, $this->version );
434
+ return $preference_result;
435
+
436
+ }
437
+
438
+ /**
439
+ * Summary: Create a checkout preference.
440
+ * Description: Create a checkout preference.
441
+ * @param array $preference
442
+ * @return array( json )
443
+ */
444
+ public function create_payment( $preference ) {
445
+
446
+ $request = array(
447
+ 'uri' => '/v1/payments',
448
+ 'params' => array(
449
+ 'access_token' => $this->get_access_token()
450
+ ),
451
+ 'headers' => array(
452
+ 'X-Tracking-Id' => 'platform:v1-whitelabel,type:woocommerce,so:' . $this->version
453
+ ),
454
+ 'data' => $preference
455
+ );
456
+
457
+ $payment = MPRestClient::post( $request, $this->version );
458
+ return $payment;
459
+ }
460
+
461
+ /**
462
+ * Summary: Create a preapproval payment.
463
+ * Description: Create a preapproval payment.
464
+ * @param array $preapproval_payment
465
+ * @return array( json )
466
+ */
467
+ public function create_preapproval_payment( $preapproval_payment ) {
468
+
469
+ $request = array(
470
+ 'uri' => '/preapproval',
471
+ 'params' => array(
472
+ 'access_token' => $this->get_access_token()
473
+ ),
474
+ 'data' => $preapproval_payment
475
+ );
476
+
477
+ $preapproval_payment_result = MPRestClient::post( $request, $this->version );
478
+ return $preapproval_payment_result;
479
+
480
+ }
481
+
482
+ /**
483
+ * Summary: Get a preapproval payment.
484
+ * Description: Get a preapproval payment.
485
+ * @param string $id
486
+ * @return array( json )
487
+ */
488
+ public function get_preapproval_payment( $id ) {
489
+
490
+ $request = array(
491
+ 'uri' => '/preapproval/' . $id,
492
+ 'params' => array(
493
+ 'access_token' => $this->get_access_token()
494
+ )
495
+ );
496
+
497
+ $preapproval_payment_result = MPRestClient::get( $request, $this->version );
498
+ return $preapproval_payment_result;
499
+
500
+ }
501
+
502
+ /**
503
+ * Summary: Update a preapproval payment.
504
+ * Description: Update a preapproval payment.
505
+ * @param string $preapproval_payment, $id
506
+ * @return array( json )
507
+ */
508
+ public function update_preapproval_payment( $id, $preapproval_payment ) {
509
+
510
+ $request = array(
511
+ 'uri' => '/preapproval/' . $id,
512
+ 'params' => array(
513
+ 'access_token' => $this->get_access_token()
514
+ ),
515
+ 'data' => $preapproval_payment
516
+ );
517
+
518
+ $preapproval_payment_result = MPRestClient::put( $request, $this->version );
519
+ return $preapproval_payment_result;
520
+
521
+ }
522
+
523
+ /**
524
+ * Summary: Cancel preapproval payment.
525
+ * Description: Cancel preapproval payment.
526
+ * @param int $id
527
+ * @return array( json )
528
+ */
529
+ public function cancel_preapproval_payment( $id ) {
530
+
531
+ $request = array(
532
+ 'uri' => '/preapproval/' . $id,
533
+ 'params' => array(
534
+ 'access_token' => $this->get_access_token()
535
+ ),
536
+ 'data' => array(
537
+ 'status' => 'cancelled'
538
+ )
539
+ );
540
+
541
+ $response = MPRestClient::put( $request, $this->version );
542
+ return $response;
543
+
544
+ }
545
+
546
+ //=== REFUND AND CANCELING FLOW FUNCTIONS ===
547
+
548
+ /**
549
+ * Summary: Refund accredited payment.
550
+ * Description: Refund accredited payment.
551
+ * @param int $id
552
+ * @return array( json )
553
+ */
554
+ public function refund_payment( $id ) {
555
+
556
+ $request = array(
557
+ 'uri' => '/collections/' . $id,
558
+ 'params' => array(
559
+ 'access_token' => $this->get_access_token()
560
+ ),
561
+ 'data' => '{"status":"refunded"}'
562
+ );
563
+
564
+ $response = MPRestClient::put( $request, $this->version );
565
+ return $response;
566
+
567
+ }
568
+
569
+ /**
570
+ * Summary: Partially refund accredited payment.
571
+ * Description: Partially refund accredited payment.
572
+ * @param int $id
573
+ * @return array( json )
574
+ */
575
+ public function partial_refund_payment( $id, $amount, $reason, $external_reference ) {
576
+
577
+ $request = array(
578
+ 'uri' => '/collections/' . $id . '/refunds?access_token=' . $this->get_access_token(),
579
+ 'data' => array(
580
+ 'amount' => $amount,
581
+ 'metadata' => array(
582
+ 'metadata' => $reason,
583
+ 'external_reference' => $external_reference
584
+ )
585
+ )
586
+ );
587
+
588
+ $response = MPRestClient::post( $request, $this->version );
589
+ return $response;
590
+
591
+ }
592
+
593
+ /**
594
+ * Summary: Cancel pending payment.
595
+ * Description: Cancel pending payment.
596
+ * @param int $id
597
+ * @return array( json )
598
+ */
599
+ public function cancel_payment( $id ) {
600
+
601
+ $request = array(
602
+ 'uri' => '/collections/' . $id,
603
+ 'params' => array(
604
+ 'access_token' => $this->get_access_token()
605
+ ),
606
+ 'data' => '{"status":"cancelled"}'
607
+ );
608
+
609
+ $response = MPRestClient::put( $request, $this->version );
610
+ return $response;
611
+
612
+ }
613
+
614
+ //=== GENERIC RESOURCE CALL METHODS ===
615
+
616
+ /**
617
+ * Summary: Generic resource get.
618
+ * Description: Generic resource get.
619
+ * @param request
620
+ * @param params (deprecated)
621
+ * @param authenticate = true (deprecated)
622
+ */
623
+ public function get( $request, $params = null, $authenticate = true ) {
624
+
625
+ if ( is_string ( $request ) ) {
626
+ $request = array(
627
+ 'uri' => $request,
628
+ 'params' => $params,
629
+ 'authenticate' => $authenticate
630
+ );
631
+ }
632
+
633
+ $request['params'] = isset( $request['params'] ) && is_array( $request['params'] ) ?
634
+ $request['params'] :
635
+ array();
636
+
637
+ if ( ! isset( $request['authenticate'] ) || $request['authenticate'] !== false ) {
638
+ $request['params']['access_token'] = $this->get_access_token();
639
+ }
640
+
641
+ $result = MPRestClient::get( $request, $this->version );
642
+ return $result;
643
+
644
+ }
645
+
646
+ /**
647
+ * Summary: Generic resource post.
648
+ * Description: Generic resource get.
649
+ * @param request
650
+ * @param data (deprecated)
651
+ * @param params (deprecated)
652
+ */
653
+ public function post( $request, $data = null, $params = null ) {
654
+
655
+ if ( is_string ( $request ) ) {
656
+ $request = array(
657
+ 'uri' => $request,
658
+ 'data' => $data,
659
+ 'params' => $params
660
+ );
661
+ }
662
+
663
+ $request['params'] = isset( $request['params'] ) && is_array( $request['params'] ) ?
664
+ $request["params"] :
665
+ array();
666
+
667
+ if ( ! isset ( $request['authenticate'] ) || $request['authenticate'] !== false ) {
668
+ $request['params']['access_token'] = $this->get_access_token();
669
+ }
670
+
671
+ $result = MPRestClient::post( $request, $this->version );
672
+ return $result;
673
+
674
+ }
675
+
676
+ /**
677
+ * Summary: Generic resource put.
678
+ * Description: Generic resource put.
679
+ * @param request
680
+ * @param data (deprecated)
681
+ * @param params (deprecated)
682
+ */
683
+ public function put( $request, $data = null, $params = null ) {
684
+
685
+ if ( is_string ( $request ) ) {
686
+ $request = array(
687
+ 'uri' => $request,
688
+ 'data' => $data,
689
+ 'params' => $params
690
+ );
691
+ }
692
+
693
+ $request['params'] = isset( $request['params'] ) && is_array( $request['params'] ) ?
694
+ $request['params'] :
695
+ array();
696
+
697
+ if ( ! isset ( $request['authenticate'] ) || $request['authenticate'] !== false ) {
698
+ $request['params']['access_token'] = $this->get_access_token();
699
+ }
700
+
701
+ $result = MPRestClient::put( $request, $this->version );
702
+ return $result;
703
+
704
+ }
705
+
706
+ /**
707
+ * Summary: Generic resource delete.
708
+ * Description: Generic resource delete.
709
+ * @param request
710
+ * @param data (deprecated)
711
+ * @param params (deprecated)
712
+ */
713
+ public function delete( $request, $params = null ) {
714
+
715
+ if ( is_string ( $request ) ) {
716
+ $request = array(
717
+ 'uri' => $request,
718
+ 'params' => $params
719
+ );
720
+ }
721
+
722
+ $request['params'] = isset( $request['params'] ) && is_array( $request['params'] ) ?
723
+ $request['params'] :
724
+ array();
725
+
726
+ if ( ! isset( $request['authenticate'] ) || $request['authenticate'] !== false ) {
727
+ $request['params']['access_token'] = $this->get_access_token();
728
+ }
729
+
730
+ $result = MPRestClient::delete( $request, $this->version );
731
+ return $result;
732
+
733
+ }
734
+
735
+ //=== MODULE ANALYTICS FUNCTIONS ===
736
+
737
+ /**
738
+ * Summary: Save the settings of the module for analytics purposes.
739
+ * Description: Save the settings of the module for analytics purposes.
740
+ * @param array( json )
741
+ * @return array( json )
742
+ */
743
+ public function analytics_save_settings( $module_info ) {
744
+
745
+ $request = array(
746
+ 'uri' => '/modules/tracking/settings?access_token=' . $this->get_access_token(),
747
+ 'data' => $module_info
748
+ );
749
+
750
+ $result = MPRestClient::post( $request, $this->version );
751
+ return $result;
752
+
753
+ }
754
 
755
  }
756
 
758
  * MercadoPago cURL RestClient
759
  */
760
  class MPRestClient {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
761
 
762
+ const API_BASE_URL = 'https://api.mercadopago.com';
763
+ private static $check_loop = 0;
764
+
765
+ private static function build_request( $request, $version ) {
766
+
767
+ if ( ! extension_loaded ( 'curl' ) ) {
768
+ throw new MercadoPagoException( 'cURL extension not found. You need to enable cURL in your php.ini or another configuration you have.' );
769
+ }
770
+
771
+ if ( ! isset( $request['method'] ) ) {
772
+ throw new MercadoPagoException( 'No HTTP METHOD specified' );
773
+ }
774
+
775
+ if ( ! isset( $request['uri'] ) ) {
776
+ throw new MercadoPagoException( 'No URI specified' );
777
+ }
778
+
779
+ // Set headers
780
+ $headers = array( 'accept: application/json' );
781
+ $json_content = true;
782
+ $form_content = false;
783
+ $default_content_type = true;
784
+
785
+ if ( isset( $request['headers'] ) && is_array( $request['headers'] ) ) {
786
+ foreach ( $request['headers'] as $h => $v ) {
787
+ $h = strtolower( $h );
788
+ $v = strtolower( $v );
789
+ if ( $h == 'content-type' ) {
790
+ $default_content_type = false;
791
+ $json_content = $v == 'application/json';
792
+ $form_content = $v == 'application/x-www-form-urlencoded';
793
+ }
794
+ array_push ( $headers, $h . ': ' . $v );
795
+ }
796
+ }
797
+ if ( $default_content_type ) {
798
+ array_push( $headers, 'content-type: application/json' );
799
+ }
800
+
801
+ // Build $connect
802
+ $connect = curl_init();
803
+
804
+ curl_setopt(
805
+ $connect,
806
+ CURLOPT_USERAGENT,
807
+ 'platform:v1-whitelabel,type:woocommerce,so:' . $version );
808
+ curl_setopt(
809
+ $connect,
810
+ CURLOPT_RETURNTRANSFER,
811
+ true );
812
+ curl_setopt(
813
+ $connect,
814
+ CURLOPT_SSL_VERIFYPEER,
815
+ true );
816
+ curl_setopt(
817
+ $connect,
818
+ CURLOPT_CAINFO,
819
+ $GLOBALS['LIB_LOCATION'] . '/cacert.pem' );
820
+ curl_setopt(
821
+ $connect,
822
+ CURLOPT_CUSTOMREQUEST,
823
+ $request['method'] );
824
+ curl_setopt(
825
+ $connect,
826
+ CURLOPT_HTTPHEADER,
827
+ $headers );
828
+
829
+ // Set parameters and url
830
+ if ( isset( $request['params'] ) && is_array( $request['params'] ) ) {
831
+ if ( count( $request['params'] > 0 ) ) {
832
+ $request['uri'] .= ( strpos( $request['uri'], '?' ) === false ) ? '?' : '&';
833
+ $request['uri'] .= self::build_query( $request['params'] );
834
+ }
835
+ }
836
+ curl_setopt( $connect, CURLOPT_URL, MPRestClient::API_BASE_URL . $request['uri'] );
837
+
838
+ // Set data
839
+ if ( isset( $request['data'] ) ) {
840
+ if ( $json_content ) {
841
+ if ( gettype( $request['data'] ) == 'string' ) {
842
+ json_decode( $request['data'], true );
843
+ } else {
844
+ $request['data'] = json_encode( $request['data'] );
845
+ }
846
+ if( function_exists( 'json_last_error' ) ) {
847
+ $json_error = json_last_error();
848
+ if ( $json_error != JSON_ERROR_NONE ) {
849
+ throw new MercadoPagoException(
850
+ "JSON Error [{$json_error}] - Data: " . $request['data']
851
+ );
852
+ }
853
+ }
854
+ } elseif ( $form_content ) {
855
+ $request['data'] = self::build_query( $request['data'] );
856
+ }
857
+ curl_setopt( $connect, CURLOPT_POSTFIELDS, $request['data'] );
858
+ }
859
+
860
+ return $connect;
861
+
862
+ }
863
+
864
+ private static function exec( $request, $version ) {
865
+
866
+ $response = null;
867
+ $connect = self::build_request( $request, $version );
868
+
869
+ $api_result = curl_exec( $connect );
870
+ $api_http_code = curl_getinfo( $connect, CURLINFO_HTTP_CODE );
871
+
872
+ if ( $api_result === FALSE ) {
873
+ throw new MercadoPagoException ( curl_error ( $connect ) );
874
+ }
875
+
876
+ if ( $api_http_code != null && $api_result != null ) {
877
+ // A common response without error.
878
+ $response = array (
879
+ 'status' => $api_http_code,
880
+ 'response' => json_decode( $api_result, true )
881
+ );
882
+ }
883
+
884
+ // Error log API.
885
+ if ( $response != null && $response['status'] >= 400 && self::$check_loop == 0 ) {
886
+ try {
887
+ self::$check_loop = 1;
888
+ $message = null;
889
+ $payloads = null;
890
+ $endpoint = null;
891
+ $errors = array();
892
+ if ( isset( $response['response'] ) ) {
893
+ if ( isset($response['response']['message'] ) ) {
894
+ $message = $response['response']['message'];
895
+ }
896
+ if ( isset( $response['response']['cause'] ) ) {
897
+ if ( isset( $response['response']['cause']['code'] ) && isset( $response['response']['cause']['description'] ) ) {
898
+ $message .= ' - ' . $response['response']['cause']['code'] . ': ' . $response['response']['cause']['description'];
899
+ } elseif ( is_array( $response['response']['cause'] ) ) {
900
+ foreach ( $response['response']['cause'] as $cause ) {
901
+ $message .= ' - ' . $cause['code'] . ': ' . $cause['description'];
902
+ }
903
+ }
904
+ }
905
+ }
906
+ if ( $request != null ) {
907
+ if ( isset( $request['data'] ) ) {
908
+ if ( $request['data'] != null ) {
909
+ $payloads = json_encode( $request['data'] );
910
+ }
911
+ }
912
+ if ( isset( $request['uri'] ) ) {
913
+ if ( $request['uri'] != null ) {
914
+ $endpoint = $request['uri'];
915
+ }
916
+ }
917
+ }
918
+ // Send error.
919
+ $errors[] = array(
920
+ 'endpoint' => $endpoint,
921
+ 'message' => $message,
922
+ 'payloads' => $payloads
923
+ );
924
+ self::sendErrorLog( $response['status'], $errors, $version );
925
+ } catch ( Exception $e ) {
926
+ throw new MercadoPagoException( 'error to call API LOGS' . $e );
927
+ }
928
+ }
929
+
930
+ self::$check_loop = 0;
931
+
932
+ curl_close( $connect );
933
+
934
+ return $response;
935
+ }
936
+
937
+ private static function sendErrorLog( $code, $errors, $version ) {
938
+ $data = array(
939
+ 'code' => $code,
940
+ 'module' => 'WooCommerce',
941
+ 'module_version' => $version,
942
+ 'url_store' => $_SERVER['HTTP_HOST'],
943
+ 'errors' => $errors
944
+ );
945
+ $request = array(
946
+ 'uri' => '/modules/log',
947
+ 'data' => $data
948
+ );
949
+ $result_response = MPRestClient::post( $request, $version );
950
+ return $result_response;
951
+ }
952
+
953
+ private static function build_query( $params ) {
954
+
955
+ if ( function_exists( 'http_build_query' ) ) {
956
+ return http_build_query( $params, '', '&' );
957
+ } else {
958
+ foreach ( $params as $name => $value ) {
959
+ $elements[] = "{$name}=" . urlencode( $value );
960
+ }
961
+ return implode( '&', $elements );
962
+ }
963
+
964
+ }
965
+
966
+ public static function get( $request, $version ) {
967
+ $request['method'] = 'GET';
968
+
969
+ return self::exec( $request, $version );
970
+ }
971
+
972
+ public static function post( $request, $version ) {
973
+ $request['method'] = 'POST';
974
+
975
+ return self::exec( $request, $version );
976
+ }
977
+
978
+ public static function put( $request, $version ) {
979
+ $request['method'] = 'PUT';
980
+
981
+ return self::exec( $request, $version );
982
+ }
983
+
984
+ public static function delete( $request, $version ) {
985
+ $request['method'] = 'DELETE';
986
+
987
+ return self::exec( $request, $version );
988
+ }
989
+
990
+ }
991
+
992
+ class MeliRestClient {
993
+
994
+ const API_BASE_URL = 'https://api.mercadolibre.com';
995
+ private static $check_loop = 0;
996
+
997
+ private static function build_request( $request, $version ) {
998
+
999
+ if ( ! extension_loaded ( 'curl' ) ) {
1000
+ throw new MercadoPagoException( 'cURL extension not found. You need to enable cURL in your php.ini or another configuration you have.' );
1001
+ }
1002
+
1003
+ if ( ! isset( $request['method'] ) ) {
1004
+ throw new MercadoPagoException( 'No HTTP METHOD specified' );
1005
+ }
1006
+
1007
+ if ( ! isset( $request['uri'] ) ) {
1008
+ throw new MercadoPagoException( 'No URI specified' );
1009
+ }
1010
+
1011
+ // Set headers
1012
+ $headers = array( 'accept: application/json' );
1013
+ $json_content = true;
1014
+ $form_content = false;
1015
+ $default_content_type = true;
1016
+
1017
+ if ( isset( $request['headers'] ) && is_array( $request['headers'] ) ) {
1018
+ foreach ( $request['headers'] as $h => $v ) {
1019
+ $h = strtolower( $h );
1020
+ $v = strtolower( $v );
1021
+ if ( $h == 'content-type' ) {
1022
+ $default_content_type = false;
1023
+ $json_content = $v == 'application/json';
1024
+ $form_content = $v == 'application/x-www-form-urlencoded';
1025
+ }
1026
+ array_push ( $headers, $h . ': ' . $v );
1027
+ }
1028
+ }
1029
+ if ( $default_content_type ) {
1030
+ array_push( $headers, 'content-type: application/json' );
1031
+ }
1032
+
1033
+ // Build $connect
1034
+ $connect = curl_init();
1035
+
1036
+ curl_setopt(
1037
+ $connect,
1038
+ CURLOPT_USERAGENT,
1039
+ 'platform:v1-whitelabel,type:woocommerce,so:' . $version );
1040
+ curl_setopt(
1041
+ $connect,
1042
+ CURLOPT_RETURNTRANSFER,
1043
+ true );
1044
+ curl_setopt(
1045
+ $connect,
1046
+ CURLOPT_SSL_VERIFYPEER,
1047
+ true );
1048
+ curl_setopt(
1049
+ $connect,
1050
+ CURLOPT_CAINFO,
1051
+ $GLOBALS['LIB_LOCATION'] . '/cacert.pem' );
1052
+ curl_setopt(
1053
+ $connect,
1054
+ CURLOPT_CUSTOMREQUEST,
1055
+ $request['method'] );
1056
+ curl_setopt(
1057
+ $connect,
1058
+ CURLOPT_HTTPHEADER,
1059
+ $headers );
1060
+
1061
+ // Set parameters and url
1062
+ if ( isset( $request['params'] ) && is_array( $request['params'] ) ) {
1063
+ if ( count( $request['params'] > 0 ) ) {
1064
+ $request['uri'] .= ( strpos( $request['uri'], '?' ) === false ) ? '?' : '&';
1065
+ $request['uri'] .= self::build_query( $request['params'] );
1066
+ }
1067
+ }
1068
+ curl_setopt( $connect, CURLOPT_URL, MeliRestClient::API_BASE_URL . $request['uri'] );
1069
+
1070
+ // Set data
1071
+ if ( isset( $request['data'] ) ) {
1072
+ if ( $json_content ) {
1073
+ if ( gettype( $request['data'] ) == 'string' ) {
1074
+ json_decode( $request['data'], true );
1075
+ } else {
1076
+ $request['data'] = json_encode( $request['data'] );
1077
+ }
1078
+ if( function_exists( 'json_last_error' ) ) {
1079
+ $json_error = json_last_error();
1080
+ if ( $json_error != JSON_ERROR_NONE ) {
1081
+ throw new MercadoPagoException(
1082
+ "JSON Error [{$json_error}] - Data: " . $request['data']
1083
+ );
1084
+ }
1085
+ }
1086
+ } elseif ( $form_content ) {
1087
+ $request['data'] = self::build_query( $request['data'] );
1088
+ }
1089
+ curl_setopt( $connect, CURLOPT_POSTFIELDS, $request['data'] );
1090
+ }
1091
+
1092
+ return $connect;
1093
+ }
1094
+
1095
+ private static function exec( $request, $version ) {
1096
+
1097
+ $response = null;
1098
+ $connect = self::build_request( $request, $version );
1099
+
1100
+ $api_result = curl_exec( $connect );
1101
+ $api_http_code = curl_getinfo( $connect, CURLINFO_HTTP_CODE );
1102
+
1103
+ if ( $api_result === FALSE ) {
1104
+ throw new MercadoPagoException ( curl_error ( $connect ) );
1105
+ }
1106
+
1107
+ if ( $api_http_code != null && $api_result != null ) {
1108
+ // A common response without error.
1109
+ $response = array (
1110
+ 'status' => $api_http_code,
1111
+ 'response' => json_decode( $api_result, true ),
1112
+ );
1113
+ }
1114
+
1115
+ // Error log API.
1116
+ if ( $response != null && $response['status'] >= 400 && self::$check_loop == 0 ) {
1117
+ try {
1118
+ self::$check_loop = 1;
1119
+ $message = null;
1120
+ $payloads = null;
1121
+ $endpoint = null;
1122
+ $errors = array();
1123
+ if ( isset( $response['response'] ) ) {
1124
+ if ( isset($response['response']['message'] ) ) {
1125
+ $message = $response['response']['message'];
1126
+ }
1127
+ if ( isset( $response['response']['cause'] ) ) {
1128
+ if ( isset( $response['response']['cause']['code'] ) && isset( $response['response']['cause']['description'] ) ) {
1129
+ $message .= ' - ' . $response['response']['cause']['code'] . ': ' . $response['response']['cause']['description'];
1130
+ } elseif ( is_array( $response['response']['cause'] ) ) {
1131
+ foreach ( $response['response']['cause'] as $cause ) {
1132
+ $message .= ' - ' . $cause['code'] . ': ' . $cause['description'];
1133
+ }
1134
+ }
1135
+ }
1136
+ }
1137
+ if ( $request != null ) {
1138
+ if ( isset( $request['data'] ) ) {
1139
+ if ( $request['data'] != null ) {
1140
+ $payloads = json_encode( $request['data'] );
1141
+ }
1142
+ }
1143
+ if ( isset( $request['uri'] ) ) {
1144
+ if ( $request['uri'] != null ) {
1145
+ $endpoint = $request['uri'];
1146
+ }
1147
+ }
1148
+ }
1149
+ // Send error.
1150
+ $errors[] = array(
1151
+ 'endpoint' => $endpoint,
1152
+ 'message' => $message,
1153
+ 'payloads' => $payloads
1154
+ );
1155
+ self::sendErrorLog( $response['status'], $errors, $version );
1156
+ } catch ( Exception $e ) {
1157
+ throw new MercadoPagoException( 'error to call API LOGS' . $e );
1158
+ }
1159
+ }
1160
+
1161
+ self::$check_loop = 0;
1162
+
1163
+ curl_close( $connect );
1164
+
1165
+ return $response;
1166
+ }
1167
+
1168
+ private static function sendErrorLog( $code, $errors, $version ) {
1169
+ $data = array(
1170
+ 'code' => $code,
1171
+ 'module' => 'WooCommerce',
1172
+ 'module_version' => $version,
1173
+ 'url_store' => $_SERVER['HTTP_HOST'],
1174
+ 'errors' => $errors
1175
+ );
1176
+ $request = array(
1177
+ 'uri' => '/modules/log',
1178
+ 'data' => $data
1179
+ );
1180
+ $result_response = MeLiRestClient::post( $request, $version );
1181
+ return $result_response;
1182
+ }
1183
+
1184
+ private static function build_query( $params ) {
1185
 
1186
+ if ( function_exists( 'http_build_query' ) ) {
1187
+ return http_build_query( $params, '', '&' );
1188
+ } else {
1189
+ foreach ( $params as $name => $value ) {
1190
+ $elements[] = "{$name}=" . urlencode( $value );
1191
+ }
1192
+ return implode( '&', $elements );
1193
+ }
1194
 
1195
+ }
 
1196
 
1197
+ public static function get( $request, $version ) {
1198
+ $request['method'] = 'GET';
1199
+
1200
+ return self::exec( $request, $version );
1201
+ }
1202
 
1203
+ public static function post( $request, $version ) {
1204
+ $request['method'] = 'POST';
1205
 
1206
+ return self::exec( $request, $version );
1207
+ }
1208
 
1209
+ public static function put( $request, $version ) {
1210
+ $request['method'] = 'PUT';
1211
 
1212
+ return self::exec( $request, $version );
1213
+ }
1214
 
1215
+ public static function delete( $request, $version ) {
1216
+ $request['method'] = 'DELETE';
1217
 
1218
+ return self::exec( $request, $version );
1219
+ }
1220
 
 
 
1221
  }
1222
 
1223
  class MercadoPagoException extends Exception {
1224
+ public function __construct( $message, $code = 500, Exception $previous = null ) {
1225
+ // Default code 500
1226
+ parent::__construct( $message, $code, $previous );
1227
+ }
1228
+ }
shipment/abstract-wc-mercadoenvios-shipping.php ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Text Domain: woocommerce-mercadopago-module
5
+ * Domain Path: /languages/
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ /**
13
+ * Mercado Envios Shipping Method for Mercado Pago.
14
+ *
15
+ * A simple shipping method allowing free pickup as a shipping method for Mercado Pago.
16
+ *
17
+ * @class WC_MercadoPago_Shipping_MercadoEnvios
18
+ * @version 2.2.0
19
+ * @package WooCommerce/Classes/Shipping
20
+ * @author Mercado Pago
21
+ */
22
+
23
+ include_once dirname( __FILE__ ) . '/../mercadopago/sdk/lib/mercadopago.php';
24
+
25
+ abstract class WC_MercadoEnvios_Shipping extends WC_Shipping_Method {
26
+
27
+ protected $shipments_id = array();
28
+
29
+ /**
30
+ * Constructor.
31
+ */
32
+ public function __construct( $instance_id = 0 ) {
33
+
34
+ add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
35
+
36
+ $this->instance_id = absint( $instance_id );
37
+ $this->method_description = __( 'Mercado Envios is a shipping method available only for payments with Mercado Pago.', 'woocommerce-mercadopago-module' );
38
+ $this->supports = array(
39
+ 'shipping-zones',
40
+ 'instance-settings',
41
+ 'instance-settings-modal',
42
+ );
43
+
44
+ // Log.
45
+ $this->log = new WC_Logger();
46
+ $this->init();
47
+
48
+ }
49
+
50
+ /**
51
+ * Initialize local pickup.
52
+ */
53
+ public function init() {
54
+
55
+ // Load the settings.
56
+ $this->init_form_fields();
57
+ $this->init_settings();
58
+
59
+ // Define user set variables.
60
+ $this->title = $this->get_option( 'title' );
61
+ $this->tax_status = $this->get_option( 'tax_status' );
62
+ $this->cost = $this->get_option( 'cost' );
63
+ $this->free_shipping = $this->get_option( 'free_shipping' );
64
+ $this->show_delivery_time = $this->get_option( 'show_delivery_time' );
65
+
66
+ // Actions.
67
+ add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
68
+
69
+ }
70
+
71
+ // Multi-language plugin.
72
+ public function load_plugin_textdomain() {
73
+ $locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-mercadopago-module' );
74
+ $module_root = 'woocommerce-mercadopago-module/woocommerce-mercadopago-module-';
75
+ load_textdomain(
76
+ 'woocommerce-mercadopago-module',
77
+ trailingslashit( WP_LANG_DIR ) . $module_root . $locale . '.mo'
78
+ );
79
+ load_plugin_textdomain(
80
+ 'woocommerce-mercadopago-module',
81
+ false,
82
+ dirname( plugin_basename( __FILE__ ) ) . '/languages/'
83
+ );
84
+ }
85
+
86
+ /**
87
+ * Calculate shipping function.
88
+ */
89
+ public function calculate_shipping( $package = array() ) {
90
+
91
+ $checkout_standard = new WC_WooMercadoPago_Gateway();
92
+
93
+ if ( $checkout_standard->get_option( 'enabled' ) != 'yes' ) {
94
+ $this->log->add(
95
+ $this->id,
96
+ '[calculate_shipping] mercado pago standard needs to be active... '
97
+ );
98
+ return;
99
+ }
100
+
101
+ $client_id = $checkout_standard->get_option( 'client_id' );
102
+ $client_secret = $checkout_standard->get_option( 'client_secret' );
103
+
104
+ $site_id = $checkout_standard->site_id;
105
+ $shipping_method_id = $this->get_shipping_method_id( $site_id );
106
+
107
+ $this->mp = new MP(
108
+ WC_WooMercadoPago_Module::get_module_version(),
109
+ $client_id,
110
+ $client_secret
111
+ );
112
+
113
+ // Object package.
114
+ $me_package = new WC_MercadoEnvios_Package( $package );
115
+ $dimensions = $me_package->get_data();
116
+
117
+ // Set zipcode.
118
+ $zip_code = $package['destination']['postcode'];
119
+
120
+ // Height x width x length (centimeters), weight (grams).
121
+ $params = array(
122
+ 'dimensions' => (int) $dimensions['height'] . 'x' . (int) $dimensions['width'] . 'x' .
123
+ (int) $dimensions['length'] . ',' . $dimensions['weight'] * 1000,
124
+ 'zip_code' => preg_replace( '([^0-9])', '', sanitize_text_field( $zip_code ) ),
125
+ 'item_price' => $package['contents_cost'],
126
+ 'access_token' => $this->mp->get_access_token()
127
+ );
128
+
129
+ if ( $this->get_option( 'free_shipping' ) == 'yes' ) {
130
+ $params['free_method'] = $shipping_method_id;
131
+ } else {
132
+ $list_shipping_methods = $this->get_shipping_methods_zone_by_shipping_id( $this->instance_id );
133
+ foreach ( $list_shipping_methods as $key => $shipping_object ) {
134
+ if ( $key == 'mercadoenvios-normal' || $key == 'mercadoenvios-express' ) {
135
+ // WTF?
136
+ $shipping_object = new $shipping_object( $shipping_object->instance_id );
137
+ if ( $shipping_object->get_option( 'free_shipping' ) == 'yes' ) {
138
+ $temp_shipping_method_id = $shipping_object->get_shipping_method_id( $checkout_standard->site_id );
139
+ $params['free_method'] = $temp_shipping_method_id;
140
+ }
141
+ }
142
+ }
143
+ }
144
+
145
+ $response = $this->mp->get( '/shipping_options', $params );
146
+ $this->log->add( $this->id, '[calculate_shipping] Params sent: ' . json_encode( $params, JSON_PRETTY_PRINT ) );
147
+ $this->log->add( $this->id, '[calculate_shipping] Shipments Response API: ' . json_encode( $response, JSON_PRETTY_PRINT ) );
148
+
149
+ if ( $response['status'] != 200 ) {
150
+ $this->log->add(
151
+ $this->id,
152
+ '[calculate_shipping] got response different of 200... returning false.'
153
+ );
154
+ return false;
155
+ }
156
+
157
+ // $shippiments = array();
158
+ foreach ( $response['response']['options'] as $shipping ) {
159
+ if ( $shipping_method_id == $shipping['shipping_method_id'] ) {
160
+ $label_free_shipping = '';
161
+ if ( $this->get_option( 'free_shipping' ) == 'yes' || $shipping['cost'] == 0 ) {
162
+ $label_free_shipping = __( 'Free Shipping', 'woocommerce-mercadopago-module' );
163
+ }
164
+ $label_delivery_time = '';
165
+ if ( $this->get_option( 'show_delivery_time' ) == 'yes' ) {
166
+ $days = $shipping['estimated_delivery_time']['shipping'] / 24;
167
+ if ( $days <= 1 ) {
168
+ $label_delivery_time = $days . ' ' . __( 'Day', 'woocommerce-mercadopago-module' );
169
+ } else {
170
+ $label_delivery_time = $days . ' ' . __( 'Days', 'woocommerce-mercadopago-module' );
171
+ }
172
+ }
173
+ $separator = '';
174
+ if ( $label_free_shipping != '' && $label_delivery_time != '' ) {
175
+ $separator = ' - ';
176
+ }
177
+ $label_info = '';
178
+ if ( $label_free_shipping != '' || $label_delivery_time ) {
179
+ $label_info = ' (' . $label_delivery_time . $separator . $label_free_shipping . ')';
180
+ }
181
+ $option = array(
182
+ 'label' => 'Mercado Envios - ' . $shipping['name'] . $label_info,
183
+ 'package' => $package,
184
+ 'cost' => (float) $shipping['cost'],
185
+ 'meta_data' => array(
186
+ 'dimensions' => $params['dimensions'],
187
+ 'shipping_method_id' => $shipping_method_id,
188
+ 'free_shipping' => $this->get_option( 'free_shipping' )
189
+ )
190
+ );
191
+ $this->log->add(
192
+ $this->id,
193
+ '-----> Optiond added: ' . json_encode( $option, JSON_PRETTY_PRINT )
194
+ );
195
+ $this->add_rate( $option );
196
+ }
197
+ }
198
+
199
+ }
200
+
201
+ /**
202
+ * Replace comma by dot.
203
+ *
204
+ * @param mixed $value Value to fix.
205
+ *
206
+ * @return mixed
207
+ */
208
+ private function fix_format( $value ) {
209
+ $value = str_replace( ',', '.', $value );
210
+ return $value;
211
+ }
212
+
213
+ /**
214
+ * Init form fields.
215
+ */
216
+ public function init_form_fields() {
217
+
218
+ // Force quit loop.
219
+ $mp = WC_WooMercadoPago_Module::init_mercado_pago_gateway_class();
220
+ if ( isset( $mp->mercado_envios_loop ) && $mp->mercado_envios_loop ) {
221
+ return false;
222
+ }
223
+
224
+ $warning_active_shipping_methods = '';
225
+
226
+ if ( $this->show_message_shipping_methods() ) {
227
+ $warning_active_shipping_methods = '<img width="12" height="12" src="' .
228
+ plugins_url( 'images/warning.png', plugin_dir_path( __FILE__ ) ) . '">' . ' ' .
229
+ __( 'Enable the two shipping methods the Mercado Envios (Express and Normal) for the proper functioning of the module.', 'woocommerce-mercadopago-module' );
230
+ }
231
+
232
+ $this->instance_form_fields = array(
233
+ 'mercado_envios_title' => array(
234
+ 'title' => __( 'Mercado Envios', 'woocommerce-mercadopago-module' ),
235
+ 'type' => 'title',
236
+ 'description' => sprintf( '%s', $warning_active_shipping_methods )
237
+ ),
238
+ // 'enabled' => array(
239
+ // 'title' => __( 'Enable/Disable', 'woocommerce-mercadopago-module' ),
240
+ // 'type' => 'checkbox',
241
+ // 'label' => __( 'Enable this shipping method', 'woocommerce-mercadopago-module' ),
242
+ // 'default' => 'yes',
243
+ // ),
244
+ 'title' => array(
245
+ 'title' => __( 'Mercado Envios', 'woocommerce-mercadopago-module' ),
246
+ 'type' => 'text',
247
+ 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-mercadopago-module' ),
248
+ 'default' => __( 'Mercado Envios', 'woocommerce-mercadopago-module' ),
249
+ 'desc_tip' => true,
250
+ ),
251
+ 'free_shipping' => array(
252
+ 'title' => __( 'Free Shipping', 'woocommerce-mercadopago-module' ),
253
+ 'type' => 'checkbox',
254
+ 'label' => __( 'Enable free shipping for this shipping method', 'woocommerce-mercadopago-module' ),
255
+ 'default' => 'no',
256
+ ),
257
+ 'show_delivery_time' => array(
258
+ 'title' => __( 'Delivery Time', 'woocommerce-mercadopago-module' ),
259
+ 'type' => 'checkbox',
260
+ 'label' => __( 'Show estimated delivery time', 'woocommerce-mercadopago-module' ),
261
+ 'description' => __( 'Display the estimated delivery time in working days.', 'woocommerce-mercadopago-module' ),
262
+ 'desc_tip' => true,
263
+ 'default' => 'no',
264
+ )
265
+ );
266
+
267
+ }
268
+
269
+ /**
270
+ * Return shipping methods by zone and shipping id.
271
+ */
272
+ public function get_shipping_methods_zone_by_shipping_id( $shipping_id ) {
273
+ $shipping_zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $shipping_id );
274
+ // Set looping shipping methods.
275
+ $mp = WC_WooMercadoPago_Module::init_mercado_pago_gateway_class();
276
+ $mp->mercado_envios_loop = true;
277
+ $shipping_methods_list = array();
278
+ foreach ( $shipping_zone->get_shipping_methods() as $key => $shipping_object ) {
279
+ $shipping_methods_list[$shipping_object->id] = $shipping_object;
280
+ }
281
+ $mp->mercado_envios_loop = false;
282
+ return $shipping_methods_list;
283
+ }
284
+
285
+ /**
286
+ * Validate if it is necessary to enable message.
287
+ */
288
+ public function show_message_shipping_methods() {
289
+ // Check if is admin.
290
+ if ( is_admin() ) {
291
+ if ( $this->instance_id > 0 ) {
292
+ $shipping_methods_list = $this->get_shipping_methods_zone_by_shipping_id( $this->instance_id );
293
+ $shipping_methods = array();
294
+ foreach ( $shipping_methods_list as $key => $shipping_object ) {
295
+ $shipping_methods[$shipping_object->id] = $shipping_object->is_enabled();
296
+ }
297
+ if ( isset($shipping_methods['mercadoenvios-normal'] ) && isset( $shipping_methods['mercadoenvios-express'] ) ) {
298
+ if ( $shipping_methods['mercadoenvios-normal'] === true && $shipping_methods['mercadoenvios-express'] === true ) {
299
+ // Add settings.
300
+ $this->update_settings_api( 'true' );
301
+ // Not display message.
302
+ return false;
303
+ } elseif ( $shipping_methods['mercadoenvios-normal'] === false && $shipping_methods['mercadoenvios-express'] === false ) {
304
+ // Remove settings.
305
+ $this->update_settings_api( 'false' );
306
+ // Not display message.
307
+ return false;
308
+ }
309
+ }
310
+ // Show message.
311
+ return true;
312
+ } else {
313
+ return false;
314
+ }
315
+ }
316
+ }
317
+
318
+ /**
319
+ * Return shipping method id Mercado Envios.
320
+ */
321
+ public function get_shipping_method_id( $site_id ) {
322
+ return $this->shipments_id[$site_id];
323
+ }
324
+
325
+ /**
326
+ * Update settings api.
327
+ */
328
+ public function update_settings_api( $status ) {
329
+ $checkout_standard = new WC_WooMercadoPago_Gateway();
330
+ $client_id = $checkout_standard->get_option( 'client_id' );
331
+ $client_secret = $checkout_standard->get_option( 'client_secret' );
332
+
333
+ if ( $client_id != '' && $client_secret != '' ) {
334
+ $this->mp = new MP(
335
+ WC_WooMercadoPago_Module::get_module_version(),
336
+ $client_id,
337
+ $client_secret
338
+ );
339
+ // Get default data.
340
+ $infra_data = WC_WooMercadoPago_Module::get_common_settings();
341
+ $infra_data['mercado_envios'] = $status;
342
+ // Request.
343
+ $response = $this->mp->analytics_save_settings( $infra_data );
344
+ $this->log->add(
345
+ $this->id,
346
+ '[update_settings_api] - analytics response: ' .
347
+ json_encode( $response, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE )
348
+ );
349
+ }
350
+ }
351
+
352
+ }
shipment/class-wc-mercadoenvios-package.php ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mercado Envios Package.
4
+ * @since 3.0.0
5
+ * @version 3.0.0
6
+ * @reference WooCommerce Correios
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit; // Exit if accessed directly.
11
+ }
12
+
13
+ /**
14
+ * WC_Mercado_Envios_Package class.
15
+ */
16
+ class WC_MercadoEnvios_Package {
17
+
18
+ /**
19
+ * Order package.
20
+ *
21
+ * @var array
22
+ */
23
+ protected $package = array();
24
+
25
+ /**
26
+ * Sets the package.
27
+ *
28
+ * @param array $package Package to calcule.
29
+ *
30
+ * @return array
31
+ */
32
+ public function __construct( $package = array() ) {
33
+ $this->package = $package;
34
+ }
35
+
36
+ /**
37
+ * Replace comma by dot.
38
+ *
39
+ * @param mixed $value Value to fix.
40
+ *
41
+ * @return mixed
42
+ */
43
+ private function fix_format( $value ) {
44
+ $value = str_replace( ',', '.', $value );
45
+
46
+ return $value;
47
+ }
48
+
49
+ /**
50
+ * Extracts the weight and dimensions from the package.
51
+ *
52
+ * @return array
53
+ */
54
+ protected function get_package_data() {
55
+ $count = 0;
56
+ $height = array();
57
+ $width = array();
58
+ $length = array();
59
+ $weight = array();
60
+
61
+ // Shipping per item.
62
+ foreach ( $this->package['contents'] as $item_id => $values ) {
63
+ $product = $values['data'];
64
+ $qty = $values['quantity'];
65
+
66
+ if ( $qty > 0 && $product->needs_shipping() ) {
67
+
68
+ // WooCommerce 3.0 or later.
69
+ if ( method_exists( $product, 'get_height' ) ) {
70
+ $_height = wc_get_dimension( $this->fix_format( $product->get_height() ), 'cm' );
71
+ $_width = wc_get_dimension( $this->fix_format( $product->get_width() ), 'cm' );
72
+ $_length = wc_get_dimension( $this->fix_format( $product->get_length() ), 'cm' );
73
+ $_weight = wc_get_weight( $this->fix_format( $product->get_weight() ), 'kg' );
74
+ } else {
75
+ $_height = wc_get_dimension( $this->fix_format( $product->height ), 'cm' );
76
+ $_width = wc_get_dimension( $this->fix_format( $product->width ), 'cm' );
77
+ $_length = wc_get_dimension( $this->fix_format( $product->length ), 'cm' );
78
+ $_weight = wc_get_weight( $this->fix_format( $product->weight ), 'kg' );
79
+ }
80
+
81
+ $height[ $count ] = $_height;
82
+ $width[ $count ] = $_width;
83
+ $length[ $count ] = $_length;
84
+ $weight[ $count ] = $_weight;
85
+
86
+ if ( $qty > 1 ) {
87
+ $n = $count;
88
+ for ( $i = 0; $i < $qty; $i++ ) {
89
+ $height[ $n ] = $_height;
90
+ $width[ $n ] = $_width;
91
+ $length[ $n ] = $_length;
92
+ $weight[ $n ] = $_weight;
93
+ $n++;
94
+ }
95
+ $count = $n;
96
+ }
97
+
98
+ $count++;
99
+ }
100
+ }
101
+
102
+ return array(
103
+ 'height' => array_values( $height ),
104
+ 'length' => array_values( $length ),
105
+ 'width' => array_values( $width ),
106
+ 'weight' => array_sum( $weight ),
107
+ );
108
+ }
109
+
110
+ /**
111
+ * Calculates the cubage of all products.
112
+ *
113
+ * @param array $height Package height.
114
+ * @param array $width Package width.
115
+ * @param array $length Package length.
116
+ *
117
+ * @return int
118
+ */
119
+ protected function cubage_total( $height, $width, $length ) {
120
+ // Sets the cubage of all products.
121
+ $all = array();
122
+ $total = 0;
123
+ $total_items = count( $height );
124
+
125
+ for ( $i = 0; $i < $total_items; $i++ ) {
126
+ $all[ $i ] = $height[ $i ] * $width[ $i ] * $length[ $i ];
127
+ }
128
+
129
+ foreach ( $all as $value ) {
130
+ $total += $value;
131
+ }
132
+
133
+ return $total;
134
+ }
135
+
136
+ /**
137
+ * Get the max values.
138
+ *
139
+ * @param array $height Package height.
140
+ * @param array $width Package width.
141
+ * @param array $length Package length.
142
+ *
143
+ * @return array
144
+ */
145
+ protected function get_max_values( $height, $width, $length ) {
146
+ $find = array(
147
+ 'height' => max( $height ),
148
+ 'width' => max( $width ),
149
+ 'length' => max( $length ),
150
+ );
151
+
152
+ return $find;
153
+ }
154
+
155
+ /**
156
+ * Calculates the square root of the scaling of all products.
157
+ *
158
+ * @param array $height Package height.
159
+ * @param array $width Package width.
160
+ * @param array $length Package length.
161
+ * @param array $max_values Package bigger values.
162
+ *
163
+ * @return float
164
+ */
165
+ protected function calculate_root( $height, $width, $length, $max_values ) {
166
+ $cubage_total = $this->cubage_total( $height, $width, $length );
167
+ $root = 0;
168
+ $biggest = max( $max_values );
169
+
170
+ if ( 0 !== $cubage_total && 0 !== $biggest ) {
171
+ // Dividing the value of scaling of all products.
172
+ // With the measured value of greater.
173
+ $division = $cubage_total / $biggest;
174
+ // Total square root.
175
+ $root = round( sqrt( $division ), 1 );
176
+ }
177
+
178
+ return $root;
179
+ }
180
+
181
+ /**
182
+ * Sets the final cubage.
183
+ *
184
+ * @param array $height Package height.
185
+ * @param array $width Package width.
186
+ * @param array $length Package length.
187
+ *
188
+ * @return array
189
+ */
190
+ protected function get_cubage( $height, $width, $length ) {
191
+ $cubage = array();
192
+ $max_values = $this->get_max_values( $height, $width, $length );
193
+ $root = $this->calculate_root( $height, $width, $length, $max_values );
194
+ $greatest = array_search( max( $max_values ), $max_values, true );
195
+
196
+ switch ( $greatest ) {
197
+ case 'height' :
198
+ $cubage = array(
199
+ 'height' => max( $height ),
200
+ 'width' => $root,
201
+ 'length' => $root,
202
+ );
203
+ break;
204
+ case 'width' :
205
+ $cubage = array(
206
+ 'height' => $root,
207
+ 'width' => max( $width ),
208
+ 'length' => $root,
209
+ );
210
+ break;
211
+ case 'length' :
212
+ $cubage = array(
213
+ 'height' => $root,
214
+ 'width' => $root,
215
+ 'length' => max( $length ),
216
+ );
217
+ break;
218
+
219
+ default :
220
+ $cubage = array(
221
+ 'height' => 0,
222
+ 'width' => 0,
223
+ 'length' => 0,
224
+ );
225
+ break;
226
+ }
227
+
228
+ return $cubage;
229
+ }
230
+
231
+ /**
232
+ * Get the package data.
233
+ *
234
+ * @return array
235
+ */
236
+ public function get_data() {
237
+ // Get the package data.
238
+ $data = apply_filters( 'woocommerce_mercado_envios_default_package', $this->get_package_data() );
239
+
240
+ if ( ! empty( $data['height'] ) && ! empty( $data['width'] ) && ! empty( $data['length'] ) ) {
241
+ $cubage = $this->get_cubage( $data['height'], $data['width'], $data['length'] );
242
+ } else {
243
+ $cubage = array(
244
+ 'height' => 0,
245
+ 'width' => 0,
246
+ 'length' => 0,
247
+ );
248
+ }
249
+
250
+ return array(
251
+ 'height' => apply_filters( 'woocommerce_mercado_envios_package_height', $cubage['height'] ),
252
+ 'width' => apply_filters( 'woocommerce_mercado_envios_package_width', $cubage['width'] ),
253
+ 'length' => apply_filters( 'woocommerce_mercado_envios_package_length', $cubage['length'] ),
254
+ 'weight' => apply_filters( 'woocommerce_mercado_envios_package_weight', $data['weight'] ),
255
+ );
256
+ }
257
+ }
shipment/class-wc-mercadoenvios-shipping-express.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ /**
8
+ * Mercado Envios Shipping Method for Mercado Pago.
9
+ *
10
+ * A simple shipping method allowing free pickup as a shipping method for Mercado Pago.
11
+ *
12
+ * @class WC_MercadoPago_Shipping_MercadoEnvios
13
+ * @version 2.2.0
14
+ * @package WooCommerce/Classes/Shipping
15
+ * @author Mercado Pago
16
+ */
17
+
18
+ class WC_MercadoEnvios_Shipping_Express extends WC_MercadoEnvios_Shipping {
19
+
20
+ protected $shipments_id = array(
21
+ 'MLA' => 73330,
22
+ 'MLB' => 182,
23
+ 'MLM' => 501345
24
+ );
25
+
26
+ /**
27
+ * Constructor.
28
+ */
29
+ public function __construct( $instance_id = 0 ) {
30
+ $this->id = 'mercadoenvios-express';
31
+ $this->method_title = __( 'Mercado Envios - Express', 'woocommerce-mercadopago-module' );
32
+ parent::__construct( $instance_id );
33
+ }
34
+
35
+ }
shipment/class-wc-mercadoenvios-shipping-normal.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ /**
8
+ * Mercado Envios Shipping Method for Mercado Pago.
9
+ *
10
+ * A simple shipping method allowing free pickup as a shipping method for Mercado Pago.
11
+ *
12
+ * @class WC_MercadoPago_Shipping_MercadoEnvios
13
+ * @version 2.2.0
14
+ * @package WooCommerce/Classes/Shipping
15
+ * @author Mercado Pago
16
+ */
17
+
18
+ class WC_MercadoEnvios_Shipping_Normal extends WC_MercadoEnvios_Shipping {
19
+
20
+ protected $shipments_id = array(
21
+ 'MLA' => 73328,
22
+ 'MLB' => 100009,
23
+ 'MLM' => 501245
24
+ );
25
+
26
+ /**
27
+ * Constructor.
28
+ */
29
+ public function __construct( $instance_id = 0 ) {
30
+ $this->id = 'mercadoenvios-normal';
31
+ $this->method_title = __( 'Mercado Envios - Normal', 'woocommerce-mercadopago-module' );
32
+ parent::__construct( $instance_id );
33
+ }
34
+
35
+ }
templates/credit-card/payment-form.php CHANGED
@@ -1,172 +1,255 @@
1
  <?php
 
2
  /**
3
  * Part of Woo Mercado Pago Module
4
  * Author - Mercado Pago
5
  * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
6
- * Copyright - Copyright(c) MercadoPago [http://www.mercadopago.com]
7
- * License - http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
8
  */
9
 
10
- if ( !defined( 'ABSPATH' ) ) {
11
  exit;
12
  }
 
13
  ?>
14
 
15
- <div width="100%" style="margin:1px; padding:36px 36px 16px 36px; background:white; ">
16
- <img class="logo" src="<?php echo ( $images_path . 'mplogo.png' ); ?>" width="156" height="40" />
17
- <?php if ( !empty( $banner_path ) ) { ?>
18
- <img class="mp-creditcard-banner" src="<?php echo $banner_path; ?>" width="312" height="40" />
19
- <?php } ?>
20
  </div>
21
- <fieldset style="background:white; ">
22
-
23
- <div class="mp-box-inputs mp-line" id="mercadopago-form-coupon" style="padding:0px 36px 16px 36px;">
24
- <label for="couponCodeLabel"><?php echo $form_labels['form']['coupon_of_discounts']; ?></label>
25
- <div class="mp-box-inputs mp-col-65">
26
- <input type="text" id="couponCode" name="mercadopago_custom[coupon_code]" autocomplete="off" maxlength="24" />
27
- <span class="mp-discount" id="mpCouponApplyed" ></span>
28
- <span class="mp-error" id="mpCouponError" ></span>
29
- </div>
30
- <div class="mp-box-inputs mp-col-10">
31
- <div id="mp-separete-date"></div>
32
- </div>
33
- <div class="mp-box-inputs mp-col-25">
34
- <input type="button" class="button" id="applyCoupon" value="<?php echo $form_labels['form']['apply']; ?>" >
35
- </div>
36
- </div>
 
 
 
 
 
 
 
37
 
38
  <!-- payment method -->
39
- <div id="mercadopago-form-customer-and-card" style="padding:0px 36px 0px 36px;">
40
  <div class="mp-box-inputs mp-line">
41
- <label for="paymentMethodIdSelector"><?php echo $form_labels['form']['payment_method']; ?> <em>*</em></label>
42
- <select id="paymentMethodSelector" name="mercadopago_custom[paymentMethodSelector]" data-checkout='cardId'>
43
- <optgroup label=<?php echo $form_labels['form']['your_card']; ?> id="payment-methods-for-customer-and-cards">
44
- <?php foreach ( $customer_cards as $card) { ?>
45
- <option value=<?php echo $card["id"]; ?>
46
- first_six_digits=<?php echo $card["first_six_digits"]; ?>
47
- last_four_digits=<?php echo $card["last_four_digits"]; ?>
48
- security_code_length=<?php echo $card["security_code"]["length"]; ?>
49
- type_checkout="customer_and_card"
50
- payment_method_id=<?php echo $card["payment_method"]["id"]; ?>>
51
- <?php echo ucfirst($card["payment_method"]["name"]); ?> <?php echo $form_labels['form']['ended_in']; ?> <?php echo $card["last_four_digits"]; ?>
52
- </option>
53
- <?php } ?>
54
- </optgroup>
55
- <optgroup label="<?php echo $form_labels['form']['other_cards']; ?>" id="payment-methods-list-other-cards">
56
- <option value="-1"><?php echo $form_labels['form']['other_card']; ?></option>
57
- </optgroup>
58
- </select>
59
- </div>
60
- <div class="mp-box-inputs mp-line" id="mp-securityCode-customer-and-card">
61
- <div class="mp-box-inputs mp-col-45">
62
- <label for="customer-and-card-securityCode"><?php echo $form_labels['form']['security_code']; ?> <em>*</em></label>
63
- <input type="text" id="customer-and-card-securityCode" data-checkout="securityCode" autocomplete="off" maxlength="4"
64
- style="padding: 8px; background: url( <?php echo ( $images_path . 'cvv.png' ); ?> ) 98% 50% no-repeat;"/>
65
- <span class="mp-error" id="mp-error-224" data-main="#customer-and-card-securityCode"> <?php echo $form_labels['error']['224']; ?> </span>
66
- <span class="mp-error" id="mp-error-E302" data-main="#customer-and-card-securityCode"> <?php echo $form_labels['error']['E302']; ?> </span>
67
- <span class="mp-error" id="mp-error-E203" data-main="#customer-and-card-securityCode"> <?php echo $form_labels['error']['E203']; ?> </span>
68
- </div>
69
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  </div> <!-- end mercadopago-form-osc -->
71
 
72
- <div id="mercadopago-form" style="padding:0px 36px 0px 36px;">
73
  <!-- Card Number -->
74
- <div class="mp-box-inputs mp-col-100">
75
- <label for="cardNumber"><?php echo $form_labels['form']['credit_card_number']; ?> <em>*</em></label>
76
- <input type="text" id="cardNumber" data-checkout="cardNumber" autocomplete="off" maxlength="19"/>
77
- <span class="mp-error" id="mp-error-205" data-main="#cardNumber"> <?php echo $form_labels['error']['205']; ?> </span>
78
- <span class="mp-error" id="mp-error-E301" data-main="#cardNumber"> <?php echo $form_labels['error']['E301']; ?> </span>
79
- </div>
80
- <!-- Expiry Date -->
81
- <div class="mp-box-inputs mp-line">
82
- <div class="mp-box-inputs mp-col-45">
83
- <label for="cardExpirationMonth"><?php echo $form_labels['form']['expiration_month']; ?> <em>*</em></label>
84
- <select id="cardExpirationMonth" data-checkout="cardExpirationMonth" name="mercadopago_custom[cardExpirationMonth]">
 
 
 
 
 
 
 
 
 
 
85
  <option value="-1"> <?php echo $form_labels['form']['month']; ?> </option>
86
- <?php for ($x=1; $x<=12; $x++): ?>
87
- <option value="<?php echo $x; ?>"> <?php echo $x; ?></option>
88
- <?php endfor; ?>
89
- </select>
90
- </div>
91
- <div class="mp-box-inputs mp-col-10">
92
- <div id="mp-separete-date">
93
- /
94
- </div>
95
- </div>
96
  <div class="mp-box-inputs mp-col-45">
97
- <label for="cardExpirationYear"><?php echo $form_labels['form']['expiration_year']; ?> <em>*</em></label>
98
- <select id="cardExpirationYear" data-checkout="cardExpirationYear" name="mercadopago_custom[cardExpirationYear]">
99
- <option value="-1"> <?php echo $form_labels['form']['year']; ?> </option>
100
- <?php for ($x=date("Y"); $x<= date("Y") + 10; $x++): ?>
101
- <option value="<?php echo $x; ?>"> <?php echo $x; ?> </option>
102
- <?php endfor; ?>
103
- </select>
104
- </div>
105
- <span class="mp-error" id="mp-error-208" data-main="#cardExpirationMonth"> <?php echo $form_labels['error']['208']; ?> </span>
 
 
 
 
 
106
  <span class="mp-error" id="mp-error-209" data-main="#cardExpirationYear"> </span>
107
- <span class="mp-error" id="mp-error-325" data-main="#cardExpirationMonth"> <?php echo $form_labels['error']['325']; ?> </span>
 
 
108
  <span class="mp-error" id="mp-error-326" data-main="#cardExpirationYear"> </span>
109
  </div>
110
  <!-- Card Holder Name -->
111
- <div class="mp-box-inputs mp-col-100">
112
- <label for="cardholderName"><?php echo $form_labels['form']['card_holder_name']; ?> <em>*</em></label>
113
- <input type="text" id="cardholderName" name="mercadopago_custom[cardholderName]" data-checkout="cardholderName" autocomplete="off" />
114
- <span class="mp-error" id="mp-error-221" data-main="#cardholderName"> <?php echo $form_labels['error']['221']; ?> </span>
115
- <span class="mp-error" id="mp-error-316" data-main="#cardholderName"> <?php echo $form_labels['error']['316']; ?> </span>
116
- </div>
117
- <!-- CVV -->
118
- <div class="mp-box-inputs mp-line">
119
- <div class="mp-box-inputs mp-col-45">
120
- <label for="securityCode"><?php echo $form_labels['form']['security_code']; ?> <em>*</em></label>
121
- <input type="text" id="securityCode" data-checkout="securityCode" autocomplete="off" maxlength="4" style="padding: 8px; background: url( <?php echo ( $images_path . 'cvv.png' ); ?> ) 98% 50% no-repeat;" />
122
- <span class="mp-error" id="mp-error-224" data-main="#securityCode"> <?php echo $form_labels['error']['224']; ?> </span>
123
- <span class="mp-error" id="mp-error-E302" data-main="#securityCode"> <?php echo $form_labels['error']['E302']; ?> </span>
124
- </div>
125
- </div>
126
- <!-- Document Type -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  <div class="mp-box-inputs mp-col-100 mp-doc">
128
- <div class="mp-box-inputs mp-col-35 mp-docType">
129
- <label for="docType"><?php echo $form_labels['form']['document_type']; ?> <em>*</em></label>
130
- <select id="docType" data-checkout="docType" name="mercadopago_custom[docType]"></select>
131
- <span class="mp-error" id="mp-error-212" data-main="#docType"> <?php echo $form_labels['error']['212']; ?> </span>
132
- <span class="mp-error" id="mp-error-322" data-main="#docType"> <?php echo $form_labels['error']['322']; ?> </span>
133
- </div>
134
- <div class="mp-box-inputs mp-col-65 mp-docNumber">
135
- <label for="docNumber"><?php echo $form_labels['form']['document_number']; ?> <em>*</em></label>
136
- <input type="text" id="docNumber" data-checkout="docNumber" name="mercadopago_custom[docNumber]" autocomplete="off" />
137
- <span class="mp-error" id="mp-error-214" data-main="#docNumber"> <?php echo $form_labels['error']['214']; ?> </span>
138
- <span class="mp-error" id="mp-error-324" data-main="#docNumber"> <?php echo $form_labels['error']['324']; ?> </span>
139
- </div>
140
- </div>
141
- <!-- Issuer -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  <div class="mp-box-inputs mp-col-100 mp-issuer">
143
- <label for="issuer"><?php echo $form_labels['form']['issuer']; ?> <em>*</em></label>
144
- <select id="issuer" data-checkout="issuer" name="mercadopago_custom[issuer]"></select>
145
- <span class="mp-error" id="mp-error-220" data-main="#issuer"> <?php echo $form_labels['error']['220']; ?> </span>
146
- </div>
 
 
 
 
147
  </div> <!-- end #mercadopago-form -->
148
 
149
- <div class="mp-box-inputs mp-col-100" style="padding:0px 36px 0px 36px;">
150
- <label for="installments">
151
- <?php echo $form_labels['form']['installments']; ?>
152
- <?php if ($is_currency_conversion > 0) { ?>
153
- <?php echo "(" . $form_labels['form']['payment_converted'] . " " . $woocommerce_currency . " " . $form_labels['form']['to'] . " " . $account_currency . ")"; ?>
154
- <?php } ?>
155
- <em>*</em>
156
- </label>
157
- <select id="installments" data-checkout="installments" name="mercadopago_custom[installments]"></select>
158
- </div>
159
- <div class="mp-box-inputs mp-line" style="padding:0px 36px 0px 36px;">
160
- <!-- <div class="mp-box-inputs mp-col-50">
161
- <input type="submit" id="submit" value="Pay">
162
- </div> -->
 
 
 
 
 
 
 
 
163
  <!-- NOT DELETE LOADING-->
164
  <div class="mp-box-inputs mp-col-25">
165
- <div id="mp-box-loading"></div>
166
  </div>
167
- </div>
168
- <div class="mp-box-inputs mp-col-100" id="mercadopago-utilities" style="padding:0px 36px 0px 36px;">
169
- <input type="hidden" id="site_id" name="mercadopago_custom[site_id]"/>
 
 
170
  <input type="hidden" id="amount" value='<?php echo $amount; ?>' name="mercadopago_custom[amount]"/>
171
  <input type="hidden" id="campaign_id" name="mercadopago_custom[campaign_id]"/>
172
  <input type="hidden" id="campaign" name="mercadopago_custom[campaign]"/>
@@ -176,962 +259,1118 @@ if ( !defined( 'ABSPATH' ) ) {
176
  <input type="hidden" id="cardTruncated" name="mercadopago_custom[cardTruncated]"/>
177
  <input type="hidden" id="CustomerAndCard" name="mercadopago_custom[CustomerAndCard]"/>
178
  <input type="hidden" id="CustomerId" value='<?php echo $customerId; ?>' name="mercadopago_custom[CustomerId]"/>
179
- </div>
180
 
181
  </fieldset>
182
 
183
  <script type="text/javascript">
184
-
185
- (function() {
186
-
187
- var MPv1 = {
188
- debug: true,
189
- add_truncated_card: true,
190
- site_id: '',
191
- public_key: '',
192
- coupon_of_discounts: {
193
- discount_action_url: '',
 
194
  default: true,
195
  status: false
196
- },
197
- customer_and_card: {
198
- default: true,
199
- status: true
200
- },
201
- create_token_on: {
202
- event: true, //if true create token on event, if false create on click and ignore others events. eg: paste or keyup
203
- keyup: false,
204
- paste: true
205
- },
206
-
207
- inputs_to_create_discount: [
208
  "couponCode",
209
  "applyCoupon"
210
  ],
211
-
212
- inputs_to_create_token: [
213
- "cardNumber",
214
- "cardExpirationMonth",
215
- "cardExpirationYear",
216
- "cardholderName",
217
- "securityCode",
218
- "docType",
219
- "docNumber"
220
- ],
221
-
222
- inputs_to_create_token_customer_and_card: [
223
- "paymentMethodSelector",
224
- "securityCode"
225
- ],
226
-
227
- selectors: {
228
-
229
- couponCode: "#couponCode",
230
  applyCoupon: "#applyCoupon",
231
  mpCouponApplyed: "#mpCouponApplyed",
232
  mpCouponError: "#mpCouponError",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
 
234
- paymentMethodSelector: "#paymentMethodSelector",
235
- pmCustomerAndCards: "#payment-methods-for-customer-and-cards",
236
- pmListOtherCards: "#payment-methods-list-other-cards",
237
- mpSecurityCodeCustomerAndCard: "#mp-securityCode-customer-and-card",
238
-
239
- cardNumber: "#cardNumber",
240
- cardExpirationMonth: "#cardExpirationMonth",
241
- cardExpirationYear: "#cardExpirationYear",
242
- cardholderName: "#cardholderName",
243
- securityCode: "#securityCode",
244
- docType: "#docType",
245
- docNumber: "#docNumber",
246
- issuer: "#issuer",
247
- installments: "#installments",
248
-
249
- mpDoc: ".mp-doc",
250
- mpIssuer: ".mp-issuer",
251
- mpDocType: ".mp-docType",
252
- mpDocNumber: ".mp-docNumber",
253
- // mpPaymentMethodSelector: ".mp-paymentMethodsSelector",
254
-
255
- paymentMethodId: "#paymentMethodId",
256
- amount: "#amount",
257
- token: "#token",
258
- campaign_id: "#campaign_id",
259
- campaign: "#campaign",
260
- discount: "#discount",
261
- cardTruncated: "#cardTruncated",
262
- site_id: "#site_id",
263
- CustomerAndCard: '#CustomerAndCard',
264
-
265
- box_loading: "#mp-box-loading",
266
- submit: "#submit",
267
- form: '#mercadopago-form',
268
- formCoupon: '#mercadopago-form-coupon',
269
- formCustomerAndCard: '#mercadopago-form-customer-and-card',
270
- utilities_fields: "#mercadopago-utilities"
271
- },
272
- text: {
273
- choose: "Choose",
274
- other_bank: "Other Bank",
275
- discount_info1: "You will save",
276
- discount_info2: "with discount from",
277
- discount_info3: "Total of your purchase:",
278
- discount_info4: "Total of your purchase with discount:",
279
- discount_info5: "*Uppon payment approval",
280
- discount_info6: "Terms and Conditions of Use",
281
- coupon_empty: "Please, inform your coupon code",
282
- apply: "Apply",
283
- remove: "Remove"
284
- },
285
- paths: {
286
- loading: "images/loading.gif",
287
- check: "images/check.png",
288
- error: "images/error.png"
289
- }
290
- }
291
-
292
- /*
293
- * Coupon of Discounts
294
- */
295
-
296
- MPv1.currencyIdToCurrency = function (currency_id) {
297
- if ( currency_id == 'ARS' ) {
298
- return '$';
299
- } else if ( currency_id == 'BRL' ) {
300
- return 'R$';
301
- } else if ( currency_id == 'COP' ) {
302
- return '$';
303
- } else if ( currency_id == 'CLP' ) {
304
- return '$';
305
- } else if ( currency_id == 'MXN' ) {
306
- return '$';
307
- } else if ( currency_id == 'VEF' ) {
308
- return 'Bs';
309
- } else if ( currency_id == 'PEN' ) {
310
- return 'S/';
311
- } else {
312
- return '$';
313
- }
314
- }
315
-
316
- MPv1.checkCouponEligibility = function () {
317
- if ( document.querySelector(MPv1.selectors.couponCode).value == "" ) {
318
- // coupon code is empty
319
- document.querySelector(MPv1.selectors.mpCouponApplyed).style.display = 'none';
320
- document.querySelector(MPv1.selectors.mpCouponError).style.display = 'block';
321
- document.querySelector(MPv1.selectors.mpCouponError).innerHTML = MPv1.text.coupon_empty;
322
  MPv1.coupon_of_discounts.status = false;
323
- document.querySelector(MPv1.selectors.couponCode).style.background = null;
324
- document.querySelector(MPv1.selectors.applyCoupon).value = MPv1.text.apply;
325
- document.querySelector(MPv1.selectors.discount).value = 0;
326
  MPv1.cardsHandler();
327
- } else if ( MPv1.coupon_of_discounts.status ) {
328
- // we already have a coupon set, so we remove it
329
- document.querySelector(MPv1.selectors.mpCouponApplyed).style.display = 'none';
330
- document.querySelector(MPv1.selectors.mpCouponError).style.display = 'none';
331
  MPv1.coupon_of_discounts.status = false;
332
- document.querySelector(MPv1.selectors.applyCoupon).style.background = null;
333
- document.querySelector(MPv1.selectors.applyCoupon).value = MPv1.text.apply;
334
- document.querySelector(MPv1.selectors.couponCode).value = "";
335
- document.querySelector(MPv1.selectors.couponCode).style.background = null;
336
- document.querySelector(MPv1.selectors.discount).value = 0;
337
- MPv1.cardsHandler();
338
- } else {
339
- // set loading
340
- document.querySelector(MPv1.selectors.mpCouponApplyed).style.display = 'none';
341
- document.querySelector(MPv1.selectors.mpCouponError).style.display = 'none';
342
- document.querySelector(MPv1.selectors.couponCode).style.background = "url("+MPv1.paths.loading+") 98% 50% no-repeat #fff";
343
- document.querySelector(MPv1.selectors.applyCoupon).disabled = true;
344
- var request = new XMLHttpRequest();
345
- request.open(
346
- 'GET',
347
- MPv1.coupon_of_discounts.discount_action_url +
348
- "&coupon_id=" + document.querySelector(MPv1.selectors.couponCode).value +
349
- "&amount=" + document.querySelector(MPv1.selectors.amount).value +
350
- "&payer=" + document.getElementById("billing_email").value,
351
- true
352
- );
353
- request.onreadystatechange = function() {
354
- if (request.readyState == 4) {
355
- if (request.status == 200) {
356
- var response = JSON.parse(request.responseText);
357
- if (response.status == 200) {
358
- document.querySelector(MPv1.selectors.mpCouponApplyed).style.display = 'block';
359
- document.querySelector(MPv1.selectors.discount).value = response.response.coupon_amount;
360
- document.querySelector(MPv1.selectors.mpCouponApplyed).innerHTML =
361
- "<div style='border-style: solid; border-width:thin; border-color: #009EE3; padding: 8px 8px 8px 8px; margin-top: 4px;'>" +
362
- MPv1.text.discount_info1 + " <strong>" + MPv1.currencyIdToCurrency(response.response.currency_id) + " " +
363
- Math.round(response.response.coupon_amount*100)/100 + "</strong> " + MPv1.text.discount_info2 + " " + response.response.name + ".<br>" +
364
- MPv1.text.discount_info3 + " <strong>" + MPv1.currencyIdToCurrency(response.response.currency_id) +
365
- " " + Math.round(MPv1.getAmountWithoutDiscount()*100)/100 + "</strong><br>" +
366
- MPv1.text.discount_info4 + " <strong>" + MPv1.currencyIdToCurrency(response.response.currency_id) +
367
- " " + Math.round(MPv1.getAmount()*100)/100 + "*</strong><br>" +
368
- "<i>" + MPv1.text.discount_info5 + "</i><br>" +
369
- "<a href='https://api.mercadolibre.com/campaigns/" + response.response.id + "/terms_and_conditions?format_type=html' target='_blank'>" +
370
- MPv1.text.discount_info6 + "</a></div>";
371
- document.querySelector(MPv1.selectors.mpCouponError).style.display = 'none';
372
- MPv1.coupon_of_discounts.status = true;
373
- document.querySelector(MPv1.selectors.couponCode).style.background = null;
374
- document.querySelector(MPv1.selectors.couponCode).style.background = "url("+MPv1.paths.check+") 98% 50% no-repeat #fff";
375
- document.querySelector(MPv1.selectors.applyCoupon).value = MPv1.text.remove;
376
- MPv1.cardsHandler();
377
- document.querySelector(MPv1.selectors.campaign_id).value = response.response.id;
378
- document.querySelector(MPv1.selectors.campaign).value = response.response.name;
379
- } else if (response.status == 400 || response.status == 404) {
380
- document.querySelector(MPv1.selectors.mpCouponApplyed).style.display = 'none';
381
- document.querySelector(MPv1.selectors.mpCouponError).style.display = 'block';
382
- document.querySelector(MPv1.selectors.mpCouponError).innerHTML = response.response.message;
383
- MPv1.coupon_of_discounts.status = false;
384
- document.querySelector(MPv1.selectors.couponCode).style.background = null;
385
- document.querySelector(MPv1.selectors.couponCode).style.background = "url("+MPv1.paths.error+") 98% 50% no-repeat #fff";
386
- document.querySelector(MPv1.selectors.applyCoupon).value = MPv1.text.apply;
387
- document.querySelector(MPv1.selectors.discount).value = 0;
388
- MPv1.cardsHandler();
389
- }
390
- } else {
391
- // request failed
392
- document.querySelector(MPv1.selectors.mpCouponApplyed).style.display = 'none';
393
- document.querySelector(MPv1.selectors.mpCouponError).style.display = 'none';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  MPv1.coupon_of_discounts.status = false;
395
- document.querySelector(MPv1.selectors.applyCoupon).style.background = null;
396
- document.querySelector(MPv1.selectors.applyCoupon).value = MPv1.text.apply;
397
- document.querySelector(MPv1.selectors.couponCode).value = "";
398
- document.querySelector(MPv1.selectors.couponCode).style.background = null;
399
- document.querySelector(MPv1.selectors.discount).value = 0;
400
- MPv1.cardsHandler();
401
  }
402
- document.querySelector(MPv1.selectors.applyCoupon).disabled = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  }
404
  };
405
- request.send(null);
 
 
 
 
 
 
 
406
  }
 
 
 
 
 
 
 
407
  }
408
 
409
- MPv1.getBin = function() {
410
- var cardSelector = document.querySelector(MPv1.selectors.paymentMethodSelector);
411
- if (cardSelector && cardSelector[cardSelector.options.selectedIndex].value != "-1") {
412
- return cardSelector[cardSelector.options.selectedIndex].getAttribute('first_six_digits');
413
- }
414
-
415
- var ccNumber = document.querySelector(MPv1.selectors.cardNumber);
416
- return ccNumber.value.replace(/[ .-]/g, '').slice(0, 6);
417
- }
418
-
419
- MPv1.clearOptions = function() {
420
- var bin = MPv1.getBin();
421
-
422
- if (bin.length == 0) {
423
- MPv1.hideIssuer();
424
-
425
- var selectorInstallments = document.querySelector(MPv1.selectors.installments),
426
- fragment = document.createDocumentFragment(),
427
- option = new Option(MPv1.text.choose + "...", '-1');
428
-
429
- selectorInstallments.options.length = 0;
430
- fragment.appendChild(option);
431
- selectorInstallments.appendChild(fragment);
432
- selectorInstallments.setAttribute('disabled', 'disabled');
433
- }
434
- }
435
-
436
- MPv1.guessingPaymentMethod = function(event) {
437
-
438
- var bin = MPv1.getBin();
439
- var amount = MPv1.getAmount();
440
-
441
- if (event.type == "keyup") {
442
- if (bin != null && bin.length == 6) {
443
- Mercadopago.getPaymentMethod({
444
- "bin": bin
445
- }, MPv1.setPaymentMethodInfo);
446
- }
447
- } else {
448
- setTimeout(function() {
449
- if (bin.length >= 6) {
450
- Mercadopago.getPaymentMethod({
451
- "bin": bin
452
- }, MPv1.setPaymentMethodInfo);
453
- }
454
- }, 100);
455
- }
456
- };
457
-
458
- MPv1.setPaymentMethodInfo = function(status, response) {
459
-
460
- if (status == 200) {
461
-
462
- if (MPv1.site_id != "MLM") {
463
- //guessing
464
- document.querySelector(MPv1.selectors.paymentMethodId).value = response[0].id;
465
-
466
- if (MPv1.customer_and_card.status) {
467
- document.querySelector(MPv1.selectors.paymentMethodSelector).style.background = "url(" + response[0].secure_thumbnail + ") 95% 50% no-repeat #fff";
468
- } else {
469
- document.querySelector(MPv1.selectors.cardNumber).style.background = "url(" + response[0].secure_thumbnail + ") 98% 50% no-repeat #fff";
470
- }
471
-
472
- }
473
-
474
- // check if the security code (ex: Tarshop) is required
475
- var cardConfiguration = response[0].settings;
476
- var bin = MPv1.getBin();
477
- var amount = MPv1.getAmount();
478
-
479
- Mercadopago.getInstallments({
480
- "bin": bin,
481
- "amount": amount
482
- }, MPv1.setInstallmentInfo);
483
-
484
- // check if the issuer is necessary to pay
485
- var issuerMandatory = false,
486
- additionalInfo = response[0].additional_info_needed;
487
-
488
- for (var i = 0; i < additionalInfo.length; i++) {
489
- if (additionalInfo[i] == "issuer_id") {
490
- issuerMandatory = true;
491
- }
492
- };
493
- if (issuerMandatory && MPv1.site_id != "MLM") {
494
- var payment_method_id = response[0].id;
495
- MPv1.getIssuersPaymentMethod(payment_method_id);
496
- } else {
497
- MPv1.hideIssuer();
498
- }
499
- }
500
- }
501
-
502
-
503
- MPv1.changePaymetMethodSelector = function() {
504
- var payment_method_id = document.querySelector(MPv1.selectors.paymentMethodSelector).value;
505
- MPv1.getIssuersPaymentMethod(payment_method_id);
506
-
507
- }
508
-
509
-
510
- /*
511
- *
512
- *
513
- * Issuers
514
- *
515
- */
516
-
517
- MPv1.getIssuersPaymentMethod = function(payment_method_id) {
518
- var amount = MPv1.getAmount();
519
-
520
- //flow: MLM mercadopagocard
521
- if (payment_method_id == 'mercadopagocard') {
522
- Mercadopago.getInstallments({
523
- "payment_method_id": payment_method_id,
524
- "amount": amount
525
- }, MPv1.setInstallmentInfo);
526
- }
527
-
528
- Mercadopago.getIssuers(payment_method_id, MPv1.showCardIssuers);
529
- MPv1.addListenerEvent(document.querySelector(MPv1.selectors.issuer), 'change', MPv1.setInstallmentsByIssuerId);
530
- }
531
-
532
-
533
- MPv1.showCardIssuers = function(status, issuers) {
534
-
535
- //if the API does not return any bank
536
- if (issuers.length > 0) {
537
- var issuersSelector = document.querySelector(MPv1.selectors.issuer),
538
- fragment = document.createDocumentFragment();
539
-
540
- issuersSelector.options.length = 0;
541
- var option = new Option(MPv1.text.choose + "...", '-1');
542
- fragment.appendChild(option);
543
-
544
- for (var i = 0; i < issuers.length; i++) {
545
- if (issuers[i].name != "default") {
546
- option = new Option(issuers[i].name, issuers[i].id);
547
- } else {
548
- option = new Option("Otro", issuers[i].id);
549
- }
550
- fragment.appendChild(option);
551
- }
552
- issuersSelector.appendChild(fragment);
553
- issuersSelector.removeAttribute('disabled');
554
- //document.querySelector(MPv1.selectors.issuer).removeAttribute('style');
555
- } else {
556
- MPv1.hideIssuer();
557
- }
558
- }
559
-
560
- MPv1.setInstallmentsByIssuerId = function(status, response) {
561
- var issuerId = document.querySelector(MPv1.selectors.issuer).value;
562
- var amount = MPv1.getAmount();
563
-
564
- if (issuerId === '-1') {
565
- return;
566
- }
567
-
568
- var params_installments = {
569
- "bin": MPv1.getBin(),
570
- "amount": amount,
571
- "issuer_id": issuerId
572
- }
573
-
574
- if (MPv1.site_id == "MLM") {
575
- params_installments = {
576
- "payment_method_id": document.querySelector(MPv1.selectors.paymentMethodSelector).value,
577
- "amount": amount,
578
- "issuer_id": issuerId
579
- }
580
- }
581
-
582
- Mercadopago.getInstallments(params_installments, MPv1.setInstallmentInfo);
583
- }
584
-
585
- MPv1.hideIssuer = function() {
586
- var $issuer = document.querySelector(MPv1.selectors.issuer);
587
- var opt = document.createElement('option');
588
- opt.value = "-1";
589
- opt.innerHTML = MPv1.text.other_bank;
590
-
591
- $issuer.innerHTML = "";
592
- $issuer.appendChild(opt);
593
- $issuer.setAttribute('disabled', 'disabled');
594
- }
595
-
596
- /*
597
- *
598
- *
599
- * Installments
600
- *
601
- */
602
-
603
- MPv1.setInstallmentInfo = function(status, response) {
604
- var selectorInstallments = document.querySelector(MPv1.selectors.installments);
605
-
606
- if (response.length > 0) {
607
-
608
- var html_option = '<option value="-1">' + MPv1.text.choose + '...</option>';
609
- payerCosts = response[0].payer_costs;
610
-
611
- // fragment.appendChild(option);
612
- for (var i = 0; i < payerCosts.length; i++) {
613
- html_option += '<option value="' + payerCosts[i].installments + '">' + (payerCosts[i].recommended_message || payerCosts[i].installments) + '</option>';
614
- }
615
-
616
- // not take the user's selection if equal
617
- if (selectorInstallments.innerHTML != html_option) {
618
- selectorInstallments.innerHTML = html_option;
619
- }
620
-
621
- selectorInstallments.removeAttribute('disabled');
622
- }
623
- }
624
-
625
-
626
- /*
627
- *
628
- *
629
- * Customer & Cards
630
- *
631
- */
632
 
633
- MPv1.cardsHandler = function() {
634
-
635
- var cardSelector = document.querySelector(MPv1.selectors.paymentMethodSelector);
636
- var type_checkout = cardSelector[cardSelector.options.selectedIndex].getAttribute("type_checkout");
637
- var amount = MPv1.getAmount();
638
 
 
639
 
640
- if (MPv1.customer_and_card.default) {
 
 
 
 
 
 
641
 
642
- if (cardSelector &&
643
- cardSelector[cardSelector.options.selectedIndex].value != "-1" &&
644
- type_checkout == "customer_and_card") {
 
 
 
645
 
646
- document.querySelector(MPv1.selectors.paymentMethodId).value = cardSelector[cardSelector.options.selectedIndex].getAttribute('payment_method_id');
647
 
648
- MPv1.clearOptions();
649
 
650
- MPv1.customer_and_card.status = true;
 
 
 
651
 
652
- var _bin = cardSelector[cardSelector.options.selectedIndex].getAttribute("first_six_digits");
 
 
653
 
654
- Mercadopago.getPaymentMethod({
655
- "bin": _bin
656
- }, MPv1.setPaymentMethodInfo);
 
 
 
 
 
657
 
658
- } else {
659
- document.querySelector(MPv1.selectors.paymentMethodId).value = cardSelector.value != -1 ? cardSelector.value : "";
660
- MPv1.customer_and_card.status = false;
661
- MPv1.resetBackgroundCard();
662
- MPv1.guessingPaymentMethod({
663
- type: "keyup"
664
- });
665
- }
666
 
667
- MPv1.setForm();
668
- }
669
- }
670
 
671
- /*
672
- * Payment Methods
673
- *
674
- */
675
 
676
- MPv1.getPaymentMethods = function() {
677
- var fragment = document.createDocumentFragment();
678
- var paymentMethodsSelector = document.querySelector(MPv1.selectors.paymentMethodSelector)
679
- var mainPaymentMethodSelector = document.querySelector(MPv1.selectors.paymentMethodSelector)
680
 
681
- //set loading
682
- mainPaymentMethodSelector.style.background = "url(" + MPv1.paths.loading + ") 95% 50% no-repeat #fff";
 
683
 
684
- //if customer and card
685
- if (MPv1.customer_and_card.status) {
686
- paymentMethodsSelector = document.querySelector(MPv1.selectors.pmListOtherCards)
 
 
687
 
688
- //clean payment methods
689
- paymentMethodsSelector.innerHTML = "";
690
- } else {
691
- paymentMethodsSelector.innerHTML = "";
692
- option = new Option(MPv1.text.choose + "...", '-1');
693
- fragment.appendChild(option);
694
- }
 
 
 
695
 
696
- Mercadopago.getAllPaymentMethods(function(code, payment_methods) {
697
 
698
- for (var x = 0; x < payment_methods.length; x++) {
699
- var pm = payment_methods[x];
 
 
 
700
 
701
- if ((pm.payment_type_id == "credit_card" ||
702
- pm.payment_type_id == "debit_card" ||
703
- pm.payment_type_id == "prepaid_card") &&
704
- pm.status == "active") {
705
 
706
- option = new Option(pm.name, pm.id);
707
- option.setAttribute("type_checkout", "custom");
708
- fragment.appendChild(option);
709
 
710
- } //end if
711
 
712
- } //end for
713
 
714
- paymentMethodsSelector.appendChild(fragment);
715
- mainPaymentMethodSelector.style.background = "#fff";
716
- });
717
- }
718
 
719
- /*
720
- *
721
- * Functions related to Create Tokens
722
- *
723
- */
724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
725
 
726
- MPv1.createTokenByEvent = function() {
 
 
 
727
 
728
- var $inputs = MPv1.getForm().querySelectorAll('[data-checkout]');
729
- var $inputs_to_create_token = MPv1.getInputsToCreateToken();
730
 
731
- console.log("createTokenByEvent", $inputs_to_create_token);
732
 
733
- for (var x = 0; x < $inputs.length; x++) {
734
- var element = $inputs[x];
735
 
736
- //add events only in the required fields
737
- if ($inputs_to_create_token.indexOf(element.getAttribute("data-checkout")) > -1) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
738
 
739
- var event = "focusout";
740
 
741
- if (element.nodeName == "SELECT") {
742
- event = "change";
743
- }
744
 
745
- MPv1.addListenerEvent(element, event, MPv1.validateInputsCreateToken);
 
 
 
746
 
747
- //for firefox
748
- MPv1.addListenerEvent(element, "blur", MPv1.validateInputsCreateToken);
749
 
750
- if (MPv1.create_token_on.keyup) {
751
- MPv1.addListenerEvent(element, "keyup", MPv1.validateInputsCreateToken);
752
- }
753
 
754
- if (MPv1.create_token_on.paste) {
755
- MPv1.addListenerEvent(element, "paste", MPv1.validateInputsCreateToken);
756
- }
757
 
758
- }
759
- }
760
- }
761
 
762
- MPv1.createTokenBySubmit = function() {
763
- addListenerEvent(document.querySelector(MPv1.selectors.form), 'submit', MPv1.doPay);
764
- }
765
 
766
- var doSubmit = false;
 
767
 
768
- MPv1.doPay = function(event) {
769
- event.preventDefault();
770
- if (!doSubmit) {
771
- MPv1.createToken();
772
- return false;
773
- }
774
- }
775
 
 
776
 
777
- MPv1.validateInputsCreateToken = function() {
778
- var valid_to_create_token = true;
779
- var $inputs = MPv1.getForm().querySelectorAll('[data-checkout]');
780
- var $inputs_to_create_token = MPv1.getInputsToCreateToken();
 
 
 
781
 
782
- for (var x = 0; x < $inputs.length; x++) {
783
- var element = $inputs[x];
784
 
785
- //check is a input to create token
786
- if ($inputs_to_create_token.indexOf(element.getAttribute("data-checkout")) > -1) {
787
- if (element.value == -1 || element.value == "") {
788
- valid_to_create_token = false;
789
- } //end if check values
790
- } //end if check data-checkout
791
- } //end for
792
 
793
- if (valid_to_create_token) {
794
- MPv1.createToken();
795
- }
796
- }
797
 
798
- MPv1.createToken = function() {
799
- MPv1.hideErrors();
800
 
801
- //show loading
802
- document.querySelector(MPv1.selectors.box_loading).style.background = "url(" + MPv1.paths.loading + ") 0 50% no-repeat #fff";
803
 
804
- //form
805
- var $form = MPv1.getForm();
806
 
807
- Mercadopago.createToken($form, MPv1.sdkResponseHandler);
 
 
 
 
808
 
809
- return false;
810
- }
 
811
 
812
- MPv1.sdkResponseHandler = function(status, response) {
813
- //hide loading
814
- document.querySelector(MPv1.selectors.box_loading).style.background = "";
 
 
 
 
 
 
 
815
 
816
- if (status != 200 && status != 201) {
817
- MPv1.showErrors(response);
818
- } else {
819
- var token = document.querySelector(MPv1.selectors.token);
820
- token.value = response.id;
821
 
822
- if (MPv1.add_truncated_card) {
823
- var card = MPv1.truncateCard(response);
824
- document.querySelector(MPv1.selectors.cardTruncated).value = card;
825
- }
826
 
827
- if (!MPv1.create_token_on.event) {
828
- doSubmit = true;
829
- btn = document.querySelector(MPv1.selectors.form);
830
- btn.submit();
831
- }
832
- }
833
- }
834
-
835
- /*
836
- *
837
- *
838
- * useful functions
839
- *
840
- */
841
 
 
 
842
 
843
- MPv1.resetBackgroundCard = function() {
844
- document.querySelector(MPv1.selectors.paymentMethodSelector).style.background = "no-repeat #fff";
845
- document.querySelector(MPv1.selectors.cardNumber).style.background = "no-repeat #fff";
846
- }
847
-
848
-
849
- MPv1.setForm = function() {
850
- if (MPv1.customer_and_card.status) {
851
- document.querySelector(MPv1.selectors.form).style.display = 'none';
852
- document.querySelector(MPv1.selectors.mpSecurityCodeCustomerAndCard).removeAttribute('style');
853
- } else {
854
- document.querySelector(MPv1.selectors.mpSecurityCodeCustomerAndCard).style.display = 'none';
855
- document.querySelector(MPv1.selectors.form).removeAttribute('style');
856
- }
857
-
858
- Mercadopago.clearSession();
859
-
860
- if (MPv1.create_token_on.event) {
861
- MPv1.createTokenByEvent();
862
- MPv1.validateInputsCreateToken();
863
- }
864
-
865
- document.querySelector(MPv1.selectors.CustomerAndCard).value = MPv1.customer_and_card.status;
866
- }
867
-
868
- MPv1.getForm = function() {
869
- if (MPv1.customer_and_card.status) {
870
- return document.querySelector(MPv1.selectors.formCustomerAndCard);
871
- } else {
872
- return document.querySelector(MPv1.selectors.form);
873
- }
874
- }
875
-
876
- MPv1.getInputsToCreateToken = function() {
877
- if (MPv1.customer_and_card.status) {
878
- return MPv1.inputs_to_create_token_customer_and_card;
879
- } else {
880
- return MPv1.inputs_to_create_token;
881
- }
882
- }
883
-
884
- MPv1.truncateCard = function(response_card_token) {
885
- var first_six_digits;
886
- var last_four_digits;
887
-
888
- if (MPv1.customer_and_card.status) {
889
- var cardSelector = document.querySelector(MPv1.selectors.paymentMethodSelector);
890
- first_six_digits = cardSelector[cardSelector.options.selectedIndex].getAttribute("first_six_digits").match(/.{1,4}/g)
891
- last_four_digits = cardSelector[cardSelector.options.selectedIndex].getAttribute("last_four_digits")
892
- } else {
893
- first_six_digits = response_card_token.first_six_digits.match(/.{1,4}/g)
894
- last_four_digits = response_card_token.last_four_digits
895
- }
896
 
897
- var card = first_six_digits[0] + " " + first_six_digits[1] + "** **** " + last_four_digits;
898
- return card;
899
 
900
- }
901
 
902
- MPv1.getAmount = function() {
903
- return document.querySelector(MPv1.selectors.amount).value;
904
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
905
 
906
- /*
907
- *
908
- *
909
- * Show errors
910
- *
911
- */
912
 
913
- MPv1.showErrors = function(response) {
914
- var $form = MPv1.getForm();
915
 
916
- for (var x = 0; x < response.cause.length; x++) {
917
- var error = response.cause[x];
918
- var $span = $form.querySelector('#mp-error-' + error.code);
919
- var $input = $form.querySelector($span.getAttribute("data-main"));
920
 
921
- $span.style.display = 'inline-block';
922
- $input.classList.add("mp-error-input");
923
 
924
- }
 
 
925
 
926
- return;
927
- }
 
 
 
 
 
 
 
928
 
929
- MPv1.hideErrors = function() {
930
 
931
- for (var x = 0; x < document.querySelectorAll('[data-checkout]').length; x++) {
932
- var $field = document.querySelectorAll('[data-checkout]')[x];
933
- $field.classList.remove("mp-error-input");
934
 
935
- } //end for
936
 
937
- for (var x = 0; x < document.querySelectorAll('.mp-error').length; x++) {
938
- var $span = document.querySelectorAll('.mp-error')[x];
939
- $span.style.display = 'none';
940
 
941
- }
 
 
942
 
943
- return;
944
- }
 
 
 
945
 
946
- /*
947
- *
948
- * Add events to guessing
949
- *
950
- */
951
 
 
952
 
953
- MPv1.addListenerEvent = function(el, eventName, handler) {
954
- if (el.addEventListener) {
955
- el.addEventListener(eventName, handler);
956
- } else {
957
- el.attachEvent('on' + eventName, function() {
958
- handler.call(el);
959
- });
960
- }
961
- };
962
 
963
- MPv1.addListenerEvent(document.querySelector(MPv1.selectors.cardNumber), 'keyup', MPv1.guessingPaymentMethod);
964
- MPv1.addListenerEvent(document.querySelector(MPv1.selectors.cardNumber), 'keyup', MPv1.clearOptions);
965
- MPv1.addListenerEvent(document.querySelector(MPv1.selectors.cardNumber), 'change', MPv1.guessingPaymentMethod);
966
 
 
 
967
 
968
- // MPv1.cardsHandler();
969
 
 
 
970
 
 
971
 
 
 
972
 
973
- /*
974
- *
975
- *
976
- * Initialization function
977
- *
978
- */
 
 
 
 
 
 
 
 
 
 
 
979
 
980
- MPv1.Initialize = function(site_id, public_key, coupon_mode, discount_action_url) {
981
 
982
- //sets
983
- MPv1.site_id = site_id
984
- MPv1.public_key = public_key
985
- MPv1.coupon_of_discounts.default = coupon_mode
986
- MPv1.coupon_of_discounts.discount_action_url = discount_action_url
987
 
988
- Mercadopago.setPublishableKey(MPv1.public_key);
 
 
 
 
 
989
 
990
- // flow coupon of discounts
991
- if (MPv1.coupon_of_discounts.default) {
992
- MPv1.addListenerEvent(document.querySelector(MPv1.selectors.applyCoupon), 'click', MPv1.checkCouponEligibility);
 
993
  } else {
994
- document.querySelector(MPv1.selectors.formCoupon).style.display = 'none';
 
995
  }
996
 
997
- //flow: customer & cards
998
- var selectorPmCustomerAndCards = document.querySelector(MPv1.selectors.pmCustomerAndCards);
999
- if (MPv1.customer_and_card.default && selectorPmCustomerAndCards.childElementCount > 0) {
1000
- MPv1.addListenerEvent(document.querySelector(MPv1.selectors.paymentMethodSelector), 'change', MPv1.cardsHandler);
1001
- MPv1.cardsHandler();
1002
- } else {
1003
- //if customer & cards is disabled
1004
- //or customer does not have cards
1005
- MPv1.customer_and_card.status = false;
1006
- document.querySelector(MPv1.selectors.formCustomerAndCard).style.display = 'none';
1007
- }
1008
-
1009
- if (MPv1.create_token_on.event) {
1010
  MPv1.createTokenByEvent();
1011
- } else {
1012
- MPv1.createTokenBySubmit()
1013
- }
1014
 
1015
- //flow: MLM
1016
- if (MPv1.site_id != "MLM") {
1017
- Mercadopago.getIdentificationTypes();
1018
- }
1019
 
1020
- if (MPv1.site_id == "MLM") {
 
 
 
 
 
 
1021
 
1022
- //hide documento for mex
1023
- document.querySelector(MPv1.selectors.mpDoc).style.display = 'none';
1024
- // document.querySelector(MPv1.selectors.mpPaymentMethodSelector).removeAttribute('style');
1025
-
1026
- // I've added this trying to fix paymentMethodSelector that not appear... by mhama
1027
- document.querySelector(MPv1.selectors.formCustomerAndCard).removeAttribute('style');
1028
- document.querySelector(MPv1.selectors.formCustomerAndCard).style.padding = "36px 36px 16px 36px";
1029
- document.querySelector(MPv1.selectors.mpSecurityCodeCustomerAndCard).style.display = 'none';
1030
 
1031
- //removing not used fields for this country
1032
- MPv1.inputs_to_create_token.splice(MPv1.inputs_to_create_token.indexOf("docType"), 1);
1033
- MPv1.inputs_to_create_token.splice(MPv1.inputs_to_create_token.indexOf("docNumber"), 1);
1034
 
1035
- MPv1.addListenerEvent(document.querySelector(MPv1.selectors.paymentMethodSelector), 'change', MPv1.changePaymetMethodSelector);
 
1036
 
1037
- //get payment methods and populate selector
1038
- MPv1.getPaymentMethods();
1039
- }
 
 
 
 
 
 
 
1040
 
1041
- //flow: MLB AND MCO
1042
- if (MPv1.site_id == "MLB") {
1043
 
1044
- document.querySelector(MPv1.selectors.mpDocType).style.display = 'none';
1045
- document.querySelector(MPv1.selectors.mpIssuer).style.display = 'none';
1046
- //ajust css
1047
- document.querySelector(MPv1.selectors.docNumber).classList.remove("mp-col-75");
1048
- document.querySelector(MPv1.selectors.docNumber).classList.add("mp-col-100");
1049
 
1050
- } else if (MPv1.site_id == "MCO") {
1051
- document.querySelector(MPv1.selectors.mpIssuer).style.display = 'none';
1052
- }
1053
 
1054
- if (MPv1.debug) {
1055
- document.querySelector(MPv1.selectors.utilities_fields).style.display = 'inline-block';
1056
- console.log(MPv1);
1057
- }
 
1058
 
1059
- document.querySelector(MPv1.selectors.site_id).value = MPv1.site_id;
 
1060
 
1061
- //set form for basic ou customer & cards
1062
- // MPv1.setForm();
 
 
1063
 
1064
- return;
1065
- }
 
1066
 
 
 
1067
 
1068
- this.MPv1 = MPv1;
 
 
 
 
 
 
 
 
 
 
1069
 
1070
- }).call();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1071
 
1072
  // === Instantiation
1073
 
1074
- var mercadopago_site_id = '<?php echo $site_id; ?>';
1075
- var mercadopago_public_key = '<?php echo $public_key; ?>';
1076
- var mercadopago_coupon_mode = '<?php echo $coupon_mode; ?>';
1077
- var mercadopago_discount_action_url = '<?php echo $discount_action_url; ?>';
1078
-
1079
- MPv1.text.choose = '<?php echo $form_labels["form"]["label_choose"]; ?>';
1080
- MPv1.text.other_bank = '<?php echo $form_labels["form"]["label_other_bank"]; ?>';
1081
- MPv1.text.discount_info1 = '<?php echo $form_labels["form"]["discount_info1"]; ?>';
1082
- MPv1.text.discount_info2 = '<?php echo $form_labels["form"]["discount_info2"]; ?>';
1083
- MPv1.text.discount_info3 = '<?php echo $form_labels["form"]["discount_info3"]; ?>';
1084
- MPv1.text.discount_info4 = '<?php echo $form_labels["form"]["discount_info4"]; ?>';
1085
- MPv1.text.discount_info5 = '<?php echo $form_labels["form"]["discount_info5"]; ?>';
1086
- MPv1.text.discount_info6 = '<?php echo $form_labels["form"]["discount_info6"]; ?>';
1087
- MPv1.text.apply = '<?php echo $form_labels["form"]["apply"]; ?>';
1088
- MPv1.text.remove = '<?php echo $form_labels["form"]["remove"]; ?>';
1089
- MPv1.text.coupon_empty = '<?php echo $form_labels["form"]["coupon_empty"]; ?>';
1090
- MPv1.paths.loading = '<?php echo ( $images_path . "loading.gif" ); ?>';
1091
- MPv1.paths.check = '<?php echo ( $images_path . "check.png" ); ?>';
1092
- MPv1.paths.error = '<?php echo ( $images_path . "error.png" ); ?>';
1093
-
1094
- // overriding this function to give form padding attribute
1095
- MPv1.setForm = function() {
1096
- if (MPv1.customer_and_card.status) {
1097
- document.querySelector(MPv1.selectors.form).style.display = 'none';
1098
- document.querySelector(MPv1.selectors.mpSecurityCodeCustomerAndCard).removeAttribute('style');
1099
- } else {
1100
- document.querySelector(MPv1.selectors.mpSecurityCodeCustomerAndCard).style.display = 'none';
1101
- document.querySelector(MPv1.selectors.form).removeAttribute('style');
1102
- document.querySelector(MPv1.selectors.form).style.padding = '0px 36px 0px 36px';
1103
- }
1104
- Mercadopago.clearSession();
1105
- if (MPv1.create_token_on.event) {
1106
- MPv1.createTokenByEvent();
1107
- MPv1.validateInputsCreateToken();
1108
- }
1109
- document.querySelector(MPv1.selectors.CustomerAndCard).value = MPv1.customer_and_card.status;
1110
- }
1111
-
1112
- MPv1.getAmount = function() {
1113
- return document.querySelector(MPv1.selectors.amount).value - document.querySelector(MPv1.selectors.discount).value;
1114
- }
1115
-
1116
- MPv1.getAmountWithoutDiscount = function() {
1117
- return document.querySelector(MPv1.selectors.amount).value;
1118
- }
1119
-
1120
- MPv1.showErrors = function(response) {
1121
- var $form = MPv1.getForm();
1122
- for (var x = 0; x < response.cause.length; x++) {
1123
- var error = response.cause[x];
1124
- var $span = $form.querySelector('#mp-error-' + error.code);
1125
- var $input = $form.querySelector($span.getAttribute("data-main"));
1126
- $span.style.display = 'inline-block';
1127
- $input.classList.add("mp-error-input");
1128
- }
1129
- return;
1130
- }
1131
- MPv1.Initialize(
1132
- mercadopago_site_id,
1133
- mercadopago_public_key,
1134
- mercadopago_coupon_mode == 'yes',
1135
- mercadopago_discount_action_url);
 
 
 
 
 
1136
 
1137
  </script>
1
  <?php
2
+
3
  /**
4
  * Part of Woo Mercado Pago Module
5
  * Author - Mercado Pago
6
  * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
7
+ * Copyright - Copyright(c) MercadoPago [https://www.mercadopago.com]
8
+ * License - https://www.gnu.org/licenses/gpl.html GPL version 2 or higher
9
  */
10
 
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
  exit;
13
  }
14
+
15
  ?>
16
 
17
+ <div width="100%" style="margin:1px; padding:36px 36px 16px 36px; background:white;">
18
+ <img class="logo" src="<?php echo ($images_path . 'mplogo.png'); ?>" width="156" height="40"/>
19
+ <?php if ( ! empty( $banner_path ) ) : ?>
20
+ <img class="mp-creditcard-banner" src="<?php echo $banner_path;?>" width="312" height="40"/>
21
+ <?php endif; ?>
22
  </div>
23
+ <fieldset style="background:white;">
24
+
25
+ <div class="mp-box-inputs mp-line" id="mercadopago-form-coupon"
26
+ style="padding:0px 12px 16px 12px;">
27
+ <label for="couponCodeLabel">
28
+ <?php echo $form_labels['form']['coupon_of_discounts']; ?>
29
+ </label>
30
+ <div class="mp-box-inputs mp-col-65">
31
+ <input type="text" id="couponCode" name="mercadopago_custom[coupon_code]"
32
+ autocomplete="off" maxlength="24"/>
33
+ </div>
34
+ <div class="mp-box-inputs mp-col-10">
35
+ <div id="mp-separete-date"></div>
36
+ </div>
37
+ <div class="mp-box-inputs mp-col-25">
38
+ <input type="button" class="button" id="applyCoupon"
39
+ value="<?php echo $form_labels['form']['apply']; ?>">
40
+ </div>
41
+ <div class="mp-box-inputs mp-col-100 mp-box-message">
42
+ <span class="mp-discount" id="mpCouponApplyed" ></span>
43
+ <span class="mp-error" id="mpCouponError" ></span>
44
+ </div>
45
+ </div>
46
 
47
  <!-- payment method -->
48
+ <div id="mercadopago-form-customer-and-card" style="padding:0px 12px 0px 12px;">
49
  <div class="mp-box-inputs mp-line">
50
+ <label for="paymentMethodIdSelector">
51
+ <?php echo $form_labels['form']['payment_method']; ?> <em>*</em>
52
+ </label>
53
+ <select id="paymentMethodSelector" name="mercadopago_custom[paymentMethodSelector]"
54
+ data-checkout="cardId">
55
+ <optgroup label=<?php echo $form_labels['form']['your_card']; ?>
56
+ id="payment-methods-for-customer-and-cards">
57
+ <?php foreach ($customer_cards as $card) : ?>
58
+ <option value=<?php echo $card['id']; ?>
59
+ first_six_digits=<?php echo $card['first_six_digits']; ?>
60
+ last_four_digits=<?php echo $card['last_four_digits']; ?>
61
+ security_code_length=<?php echo $card['security_code']['length']; ?>
62
+ type_checkout='customer_and_card'
63
+ payment_method_id=<?php echo $card['payment_method']['id']; ?>>
64
+ <?php echo ucfirst($card['payment_method']['name']); ?>
65
+ <?php echo $form_labels['form']['ended_in']; ?>
66
+ <?php echo $card['last_four_digits']; ?>
67
+ </option>
68
+ <?php endforeach; ?>
69
+ </optgroup>
70
+ <optgroup label="<?php echo $form_labels['form']['other_cards']; ?>"
71
+ id="payment-methods-list-other-cards">
72
+ <option value="-1"><?php echo $form_labels['form']['other_card']; ?></option>
73
+ </optgroup>
74
+ </select>
75
+ </div>
76
+ <div class="mp-box-inputs mp-line" id="mp-securityCode-customer-and-card">
77
+ <div class="mp-box-inputs mp-col-45">
78
+ <label for="customer-and-card-securityCode">
79
+ <?php echo $form_labels['form']['security_code']; ?> <em>*</em>
80
+ </label>
81
+ <input type="text" id="customer-and-card-securityCode" data-checkout="securityCode"
82
+ autocomplete="off" maxlength="4" style="padding: 8px;
83
+ background: url(<?php echo ($images_path . 'cvv.png'); ?>) 98% 50% no-repeat;"/>
84
+ <span class="mp-error" id="mp-error-224" data-main="#customer-and-card-securityCode">
85
+ <?php echo $form_labels['error']['224']; ?>
86
+ </span>
87
+ <span class="mp-error" id="mp-error-E302" data-main="#customer-and-card-securityCode">
88
+ <?php echo $form_labels['error']['E302']; ?>
89
+ </span>
90
+ <span class="mp-error" id="mp-error-E203" data-main="#customer-and-card-securityCode">
91
+ <?php echo $form_labels['error']['E203']; ?>
92
+ </span>
93
+ </div>
94
+ </div>
95
  </div> <!-- end mercadopago-form-osc -->
96
 
97
+ <div id="mercadopago-form" style="padding:0px 12px 0px 12px;">
98
  <!-- Card Number -->
99
+ <div class="mp-box-inputs mp-col-100">
100
+ <label for="cardNumber">
101
+ <?php echo $form_labels['form']['credit_card_number']; ?> <em>*</em>
102
+ </label>
103
+ <input type="text" id="cardNumber" data-checkout="cardNumber" autocomplete="off"
104
+ maxlength="19"/>
105
+ <span class="mp-error" id="mp-error-205" data-main="#cardNumber">
106
+ <?php echo $form_labels['error']['205']; ?>
107
+ </span>
108
+ <span class="mp-error" id="mp-error-E301" data-main="#cardNumber">
109
+ <?php echo $form_labels['error']['E301']; ?>
110
+ </span>
111
+ </div>
112
+ <!-- Expiry Date -->
113
+ <div class="mp-box-inputs mp-line">
114
+ <div class="mp-box-inputs mp-col-45">
115
+ <label for="cardExpirationMonth">
116
+ <?php echo $form_labels['form']['expiration_month']; ?> <em>*</em>
117
+ </label>
118
+ <select id="cardExpirationMonth" data-checkout="cardExpirationMonth"
119
+ name="mercadopago_custom[cardExpirationMonth]">
120
  <option value="-1"> <?php echo $form_labels['form']['month']; ?> </option>
121
+ <?php for ($x=1; $x<=12; $x++) : ?>
122
+ <option value="<?php echo $x; ?>"> <?php echo $x; ?></option>
123
+ <?php endfor; ?>
124
+ </select>
125
+ </div>
126
+ <div class="mp-box-inputs mp-col-10">
127
+ <div id="mp-separete-date"> / </div>
128
+ </div>
 
 
129
  <div class="mp-box-inputs mp-col-45">
130
+ <label for="cardExpirationYear">
131
+ <?php echo $form_labels['form']['expiration_year']; ?> <em>*</em>
132
+ </label>
133
+ <select id="cardExpirationYear" data-checkout="cardExpirationYear"
134
+ name="mercadopago_custom[cardExpirationYear]">
135
+ <option value="-1"> <?php echo $form_labels['form']['year']; ?> </option>
136
+ <?php for ($x=date("Y"); $x<= date("Y") + 10; $x++) : ?>
137
+ <option value="<?php echo $x; ?>"> <?php echo $x; ?> </option>
138
+ <?php endfor; ?>
139
+ </select>
140
+ </div>
141
+ <span class="mp-error" id="mp-error-208" data-main="#cardExpirationMonth">
142
+ <?php echo $form_labels['error']['208']; ?>
143
+ </span>
144
  <span class="mp-error" id="mp-error-209" data-main="#cardExpirationYear"> </span>
145
+ <span class="mp-error" id="mp-error-325" data-main="#cardExpirationMonth">
146
+ <?php echo $form_labels['error']['325']; ?>
147
+ </span>
148
  <span class="mp-error" id="mp-error-326" data-main="#cardExpirationYear"> </span>
149
  </div>
150
  <!-- Card Holder Name -->
151
+ <div class="mp-box-inputs mp-col-100">
152
+ <label for="cardholderName">
153
+ <?php echo $form_labels['form']['card_holder_name']; ?> <em>*</em>
154
+ </label>
155
+ <input type="text" id="cardholderName" name="mercadopago_custom[cardholderName]"
156
+ data-checkout="cardholderName" autocomplete="off" />
157
+ <span class="mp-error" id="mp-error-221" data-main="#cardholderName">
158
+ <?php echo $form_labels['error']['221']; ?>
159
+ </span>
160
+ <span class="mp-error" id="mp-error-316" data-main="#cardholderName">
161
+ <?php echo $form_labels['error']['316']; ?>
162
+ </span>
163
+ </div>
164
+ <!-- CVV -->
165
+ <div class="mp-box-inputs mp-line">
166
+ <div class="mp-box-inputs mp-col-45">
167
+ <label for="securityCode">
168
+ <?php echo $form_labels['form']['security_code']; ?> <em>*</em>
169
+ </label>
170
+ <input type="text" id="securityCode" data-checkout="securityCode"
171
+ autocomplete="off" maxlength="4" style="padding: 8px;
172
+ background: url(<?php echo ($images_path . 'cvv.png'); ?>) 98% 50% no-repeat;" />
173
+ <span class="mp-error" id="mp-error-224" data-main="#securityCode">
174
+ <?php echo $form_labels['error']['224']; ?>
175
+ </span>
176
+ <span class="mp-error" id="mp-error-E302" data-main="#securityCode">
177
+ <?php echo $form_labels['error']['E302']; ?>
178
+ </span>
179
+ </div>
180
+ </div>
181
+ <!-- Document Type -->
182
  <div class="mp-box-inputs mp-col-100 mp-doc">
183
+ <div class="mp-box-inputs mp-col-35 mp-docType">
184
+ <label for="docType">
185
+ <?php echo $form_labels['form']['document_type']; ?> <em>*</em>
186
+ </label>
187
+ <select id="docType" data-checkout="docType"
188
+ name="mercadopago_custom[docType]"></select>
189
+ <span class="mp-error" id="mp-error-212" data-main="#docType">
190
+ <?php echo $form_labels['error']['212']; ?>
191
+ </span>
192
+ <span class="mp-error" id="mp-error-322" data-main="#docType">
193
+ <?php echo $form_labels['error']['322']; ?>
194
+ </span>
195
+ </div>
196
+ <div class="mp-box-inputs mp-col-65 mp-docNumber">
197
+ <label for="docNumber">
198
+ <?php echo $form_labels['form']['document_number']; ?> <em>*</em>
199
+ </label>
200
+ <input type="text" id="docNumber" data-checkout="docNumber"
201
+ name="mercadopago_custom[docNumber]" autocomplete="off" />
202
+ <span class="mp-error" id="mp-error-214" data-main="#docNumber">
203
+ <?php echo $form_labels['error']['214']; ?>
204
+ </span>
205
+ <span class="mp-error" id="mp-error-324" data-main="#docNumber">
206
+ <?php echo $form_labels['error']['324']; ?>
207
+ </span>
208
+ </div>
209
+ </div>
210
+ <!-- Issuer -->
211
  <div class="mp-box-inputs mp-col-100 mp-issuer">
212
+ <label for="issuer">
213
+ <?php echo $form_labels['form']['issuer']; ?> <em>*</em>
214
+ </label>
215
+ <select id="issuer" data-checkout="issuer" name="mercadopago_custom[issuer]"></select>
216
+ <span class="mp-error" id="mp-error-220" data-main="#issuer">
217
+ <?php echo $form_labels['error']['220']; ?>
218
+ </span>
219
+ </div>
220
  </div> <!-- end #mercadopago-form -->
221
 
222
+ <div id="mp-box-installments" class="mp-box-inputs mp-line">
223
+ <div class="form-row" >
224
+ <div id="mp-box-installments-selector" class="form-col-8" style="padding:0px 12 0px 12;">
225
+ <label for="installments">
226
+ <?php echo $form_labels['form']['installments']; ?>
227
+ <?php if ($is_currency_conversion > 0) :
228
+ echo "(" . $form_labels['form']['payment_converted'] . " " .
229
+ $woocommerce_currency . " " . $form_labels['form']['to'] . " " .
230
+ $account_currency . ")";
231
+ endif; ?> <em>*</em>
232
+ </label>
233
+ <select id="installments" data-checkout="installments" class="form-control-mine"
234
+ name="mercadopago_custom[installments]" style="width: 100%;"></select>
235
+ </div>
236
+ <div id="mp-box-input-tax-cft" class="form-col-4" style="padding:0px 12 0px 12;">
237
+ <div id="mp-box-input-tax-tea"><div id="mp-tax-tea-text"></div></div>
238
+ <div id="mp-tax-cft-text"></div>
239
+ </div>
240
+ </div>
241
+ </div>
242
+
243
+ <div class="mp-box-inputs mp-line" style="padding:0px 12px 0px 12px;">
244
  <!-- NOT DELETE LOADING-->
245
  <div class="mp-box-inputs mp-col-25">
246
+ <div id="mp-box-loading"></div>
247
  </div>
248
+ </div>
249
+
250
+ <div class="mp-box-inputs mp-col-100" id="mercadopago-utilities"
251
+ style="padding:0px 12px 0px 12px;">
252
+ <input type="hidden" id="site_id" name="mercadopago_custom[site_id]"/>
253
  <input type="hidden" id="amount" value='<?php echo $amount; ?>' name="mercadopago_custom[amount]"/>
254
  <input type="hidden" id="campaign_id" name="mercadopago_custom[campaign_id]"/>
255
  <input type="hidden" id="campaign" name="mercadopago_custom[campaign]"/>
259
  <input type="hidden" id="cardTruncated" name="mercadopago_custom[cardTruncated]"/>
260
  <input type="hidden" id="CustomerAndCard" name="mercadopago_custom[CustomerAndCard]"/>
261
  <input type="hidden" id="CustomerId" value='<?php echo $customerId; ?>' name="mercadopago_custom[CustomerId]"/>
262
+ </div>
263
 
264
  </fieldset>
265
 
266
  <script type="text/javascript">
267
+
268
+ ( function() {
269
+
270
+ var MPv1 = {
271
+ debug: true,
272
+ add_truncated_card: true,
273
+ site_id: "",
274
+ public_key: "",
275
+ coupon_of_discounts: {
276
+ discount_action_url: "",
277
+ payer_email: "",
278
  default: true,
279
  status: false
280
+ },
281
+ customer_and_card: {
282
+ default: true,
283
+ status: true
284
+ },
285
+ create_token_on: {
286
+ event: true, //if true create token on event, if false create on click and ignore others
287
+ keyup: false,
288
+ paste: true
289
+ },
290
+ inputs_to_create_discount: [
 
291
  "couponCode",
292
  "applyCoupon"
293
  ],
294
+ inputs_to_create_token: [
295
+ "cardNumber",
296
+ "cardExpirationMonth",
297
+ "cardExpirationYear",
298
+ "cardholderName",
299
+ "securityCode",
300
+ "docType",
301
+ "docNumber"
302
+ ],
303
+ inputs_to_create_token_customer_and_card: [
304
+ "paymentMethodSelector",
305
+ "securityCode"
306
+ ],
307
+ selectors: {
308
+ // coupom
309
+ couponCode: "#couponCode",
 
 
 
310
  applyCoupon: "#applyCoupon",
311
  mpCouponApplyed: "#mpCouponApplyed",
312
  mpCouponError: "#mpCouponError",
313
+ campaign_id: "#campaign_id",
314
+ campaign: "#campaign",
315
+ discount: "#discount",
316
+ // customer cards
317
+ paymentMethodSelector: "#paymentMethodSelector",
318
+ pmCustomerAndCards: "#payment-methods-for-customer-and-cards",
319
+ pmListOtherCards: "#payment-methods-list-other-cards",
320
+ // card data
321
+ mpSecurityCodeCustomerAndCard: "#mp-securityCode-customer-and-card",
322
+ cardNumber: "#cardNumber",
323
+ cardExpirationMonth: "#cardExpirationMonth",
324
+ cardExpirationYear: "#cardExpirationYear",
325
+ cardholderName: "#cardholderName",
326
+ securityCode: "#securityCode",
327
+ docType: "#docType",
328
+ docNumber: "#docNumber",
329
+ issuer: "#issuer",
330
+ installments: "#installments",
331
+ // document
332
+ mpDoc: ".mp-doc",
333
+ mpIssuer: ".mp-issuer",
334
+ mpDocType: ".mp-docType",
335
+ mpDocNumber: ".mp-docNumber",
336
+ // payment method and checkout
337
+ paymentMethodId: "#paymentMethodId",
338
+ amount: "#amount",
339
+ token: "#token",
340
+ cardTruncated: "#cardTruncated",
341
+ site_id: "#site_id",
342
+ CustomerAndCard: '#CustomerAndCard',
343
+ box_loading: "#mp-box-loading",
344
+ submit: "#submit",
345
+ // tax resolution AG 51/2017
346
+ boxInstallments: '#mp-box-installments',
347
+ boxInstallmentsSelector: '#mp-box-installments-selector',
348
+ taxCFT: '#mp-box-input-tax-cft',
349
+ taxTEA: '#mp-box-input-tax-tea',
350
+ taxTextCFT: '#mp-tax-cft-text',
351
+ taxTextTEA: '#mp-tax-tea-text',
352
+ // form
353
+ form: '#mercadopago-form',
354
+ formCoupon: '#mercadopago-form-coupon',
355
+ formCustomerAndCard: '#mercadopago-form-customer-and-card',
356
+ utilities_fields: "#mercadopago-utilities"
357
+ },
358
+ text: {
359
+ choose: "Choose",
360
+ other_bank: "Other Bank",
361
+ discount_info1: "You will save",
362
+ discount_info2: "with discount from",
363
+ discount_info3: "Total of your purchase:",
364
+ discount_info4: "Total of your purchase with discount:",
365
+ discount_info5: "*Uppon payment approval",
366
+ discount_info6: "Terms and Conditions of Use",
367
+ coupon_empty: "Please, inform your coupon code",
368
+ apply: "Apply",
369
+ remove: "Remove"
370
+ },
371
+ paths: {
372
+ loading: "images/loading.gif",
373
+ check: "images/check.png",
374
+ error: "images/error.png"
375
+ }
376
+ }
377
+
378
+ // === Coupon of Discounts
379
+
380
+ MPv1.currencyIdToCurrency = function ( currency_id ) {
381
+ if ( currency_id == "ARS" ) {
382
+ return "$";
383
+ } else if ( currency_id == "BRL" ) {
384
+ return "R$";
385
+ } else if ( currency_id == "COP" ) {
386
+ return "$";
387
+ } else if ( currency_id == "CLP" ) {
388
+ return "$";
389
+ } else if ( currency_id == "MXN" ) {
390
+ return "$";
391
+ } else if ( currency_id == "VEF" ) {
392
+ return "Bs";
393
+ } else if ( currency_id == "PEN" ) {
394
+ return "S/";
395
+ } else if ( currency_id == "UYU" ) {
396
+ return "$U";
397
+ } else {
398
+ return "$";
399
+ }
400
+ }
401
 
402
+ MPv1.checkCouponEligibility = function () {
403
+ if ( document.querySelector( MPv1.selectors.couponCode).value == "" ) {
404
+ // Coupon code is empty.
405
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display = "none";
406
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display = "block";
407
+ document.querySelector( MPv1.selectors.mpCouponError ).innerHTML = MPv1.text.coupon_empty;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
  MPv1.coupon_of_discounts.status = false;
409
+ document.querySelector( MPv1.selectors.couponCode ).style.background = null;
410
+ document.querySelector( MPv1.selectors.applyCoupon ).value = MPv1.text.apply;
411
+ document.querySelector( MPv1.selectors.discount ).value = 0;
412
  MPv1.cardsHandler();
413
+ } else if ( MPv1.coupon_of_discounts.status ) {
414
+ // We already have a coupon set, so we remove it.
415
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display = "none";
416
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display = "none";
417
  MPv1.coupon_of_discounts.status = false;
418
+ document.querySelector( MPv1.selectors.applyCoupon ).style.background = null;
419
+ document.querySelector( MPv1.selectors.applyCoupon ).value = MPv1.text.apply;
420
+ document.querySelector( MPv1.selectors.couponCode ).value = "";
421
+ document.querySelector( MPv1.selectors.couponCode ).style.background = null;
422
+ document.querySelector( MPv1.selectors.discount ).value = 0;
423
+ MPv1.cardsHandler();
424
+ } else {
425
+ // Set loading.
426
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display = "none";
427
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display = "none";
428
+ document.querySelector( MPv1.selectors.couponCode ).style.background = "url(" + MPv1.paths.loading + ") 98% 50% no-repeat #fff";
429
+ document.querySelector( MPv1.selectors.applyCoupon ).disabled = true;
430
+
431
+ // Check if there are params in the url.
432
+ var url = MPv1.coupon_of_discounts.discount_action_url;
433
+ var sp = "?";
434
+ if ( url.indexOf( "?" ) >= 0 ) {
435
+ sp = "&";
436
+ }
437
+ url += sp + "site_id=" + MPv1.site_id;
438
+ url += "&coupon_id=" + document.querySelector( MPv1.selectors.couponCode ).value;
439
+ url += "&amount=" + document.querySelector( MPv1.selectors.amount ).value;
440
+ url += "&payer=" + MPv1.coupon_of_discounts.payer_email;
441
+ //url += "&payer=" + document.getElementById( "billing_email" ).value;
442
+
443
+ MPv1.AJAX({
444
+ url: url,
445
+ method : "GET",
446
+ timeout : 5000,
447
+ error: function() {
448
+ // Request failed.
449
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display = "none";
450
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display = "none";
451
+ MPv1.coupon_of_discounts.status = false;
452
+ document.querySelector( MPv1.selectors.applyCoupon ).style.background = null;
453
+ document.querySelector( MPv1.selectors.applyCoupon ).value = MPv1.text.apply;
454
+ document.querySelector( MPv1.selectors.couponCode ).value = "";
455
+ document.querySelector( MPv1.selectors.couponCode ).style.background = null;
456
+ document.querySelector( MPv1.selectors.discount ).value = 0;
457
+ MPv1.cardsHandler();
458
+ },
459
+ success : function ( status, response ) {
460
+ if ( response.status == 200 ) {
461
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display =
462
+ "block";
463
+ document.querySelector( MPv1.selectors.discount ).value =
464
+ response.response.coupon_amount;
465
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).innerHTML =
466
+ //"<div style='border-style: solid; border-width:thin; " +
467
+ //"border-color: #009EE3; padding: 8px 8px 8px 8px; margin-top: 4px;'>" +
468
+ MPv1.text.discount_info1 + " <strong>" +
469
+ MPv1.currencyIdToCurrency( response.response.currency_id ) + " " +
470
+ Math.round( response.response.coupon_amount * 100 ) / 100 +
471
+ "</strong> " + MPv1.text.discount_info2 + " " +
472
+ response.response.name + ".<br>" + MPv1.text.discount_info3 + " <strong>" +
473
+ MPv1.currencyIdToCurrency( response.response.currency_id ) + " " +
474
+ Math.round( MPv1.getAmountWithoutDiscount() * 100 ) / 100 +
475
+ "</strong><br>" + MPv1.text.discount_info4 + " <strong>" +
476
+ MPv1.currencyIdToCurrency( response.response.currency_id ) + " " +
477
+ Math.round( MPv1.getAmount() * 100 ) / 100 + "*</strong><br>" +
478
+ "<i>" + MPv1.text.discount_info5 + "</i><br>" +
479
+ "<a href='https://api.mercadolibre.com/campaigns/" +
480
+ response.response.id +
481
+ "/terms_and_conditions?format_type=html' target='_blank'>" +
482
+ MPv1.text.discount_info6 + "</a>";
483
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display =
484
+ "none";
485
+ MPv1.coupon_of_discounts.status = true;
486
+ document.querySelector( MPv1.selectors.couponCode ).style.background =
487
+ null;
488
+ document.querySelector( MPv1.selectors.couponCode ).style.background =
489
+ "url(" + MPv1.paths.check + ") 98% 50% no-repeat #fff";
490
+ document.querySelector( MPv1.selectors.applyCoupon ).value =
491
+ MPv1.text.remove;
492
+ MPv1.cardsHandler();
493
+ document.querySelector( MPv1.selectors.campaign_id ).value =
494
+ response.response.id;
495
+ document.querySelector( MPv1.selectors.campaign ).value =
496
+ response.response.name;
497
+ } else if ( response.status == 400 || response.status == 404 ) {
498
+ document.querySelector( MPv1.selectors.mpCouponApplyed ).style.display = "none";
499
+ document.querySelector( MPv1.selectors.mpCouponError ).style.display = "block";
500
+ document.querySelector( MPv1.selectors.mpCouponError ).innerHTML = response.response.message;
501
  MPv1.coupon_of_discounts.status = false;
502
+ document.querySelector( MPv1.selectors.couponCode ).style.background = null;
503
+ document.querySelector( MPv1.selectors.couponCode ).style.background = "url(" + MPv1.paths.error + ") 98% 50% no-repeat #fff";
504
+ document.querySelector( MPv1.selectors.applyCoupon ).value = MPv1.text.apply;
505
+ document.querySelector( MPv1.selectors.discount ).value = 0;
506
+ MPv1.cardsHandler();
 
507
  }
508
+ document.querySelector( MPv1.selectors.applyCoupon ).disabled = false;
509
+ }
510
+ });
511
+ }
512
+ }
513
+
514
+ MPv1.getBin = function() {
515
+
516
+ var cardSelector = document.querySelector( MPv1.selectors.paymentMethodSelector );
517
+
518
+ if (cardSelector && cardSelector[cardSelector.options.selectedIndex].value != "-1") {
519
+ return cardSelector[cardSelector.options.selectedIndex]
520
+ .getAttribute( "first_six_digits" );
521
+ }
522
+
523
+ var ccNumber = document.querySelector( MPv1.selectors.cardNumber );
524
+ return ccNumber.value.replace( /[ .-]/g, "" ).slice( 0, 6 );
525
+
526
+ }
527
+
528
+ MPv1.clearOptions = function() {
529
+
530
+ var bin = MPv1.getBin();
531
+
532
+ if ( bin.length == 0 ) {
533
+
534
+ MPv1.hideIssuer();
535
+
536
+ var selectorInstallments = document.querySelector( MPv1.selectors.installments ),
537
+ fragment = document.createDocumentFragment(),
538
+ option = new Option( MPv1.text.choose + "...", "-1" );
539
+
540
+ selectorInstallments.options.length = 0;
541
+ fragment.appendChild( option );
542
+ selectorInstallments.appendChild( fragment );
543
+ selectorInstallments.setAttribute( "disabled", "disabled" );
544
+
545
+ }
546
+
547
+ }
548
+
549
+ MPv1.guessingPaymentMethod = function( event ) {
550
+
551
+ var bin = MPv1.getBin();
552
+ var amount = MPv1.getAmount();
553
+
554
+ if ( event.type == "keyup" ) {
555
+ if ( bin != null && bin.length == 6 ) {
556
+ Mercadopago.getPaymentMethod( {
557
+ "bin": bin
558
+ }, MPv1.setPaymentMethodInfo );
559
+ }
560
+ } else {
561
+ setTimeout( function() {
562
+ if ( bin.length >= 6 ) {
563
+ Mercadopago.getPaymentMethod( {
564
+ "bin": bin
565
+ }, MPv1.setPaymentMethodInfo );
566
+ }
567
+ }, 100 );
568
+ }
569
+
570
+ };
571
+
572
+ MPv1.setPaymentMethodInfo = function( status, response ) {
573
+
574
+ if ( status == 200 ) {
575
+
576
+ if ( MPv1.site_id != "MLM" ) {
577
+ // Guessing...
578
+ document.querySelector( MPv1.selectors.paymentMethodId ).value = response[0].id;
579
+ if ( MPv1.customer_and_card.status ) {
580
+ document.querySelector( MPv1.selectors.paymentMethodSelector )
581
+ .style.background = "url(" + response[0].secure_thumbnail + ") 95% 50% no-repeat #fff";
582
+ } else {
583
+ document.querySelector( MPv1.selectors.cardNumber ).style.background = "url(" +
584
+ response[0].secure_thumbnail + ") 98% 50% no-repeat #fff";
585
+ }
586
+ }
587
+
588
+ // Check if the security code (ex: Tarshop) is required.
589
+ var cardConfiguration = response[0].settings;
590
+ var bin = MPv1.getBin();
591
+ var amount = MPv1.getAmount();
592
+
593
+ Mercadopago.getInstallments(
594
+ { "bin": bin, "amount": amount },
595
+ MPv1.setInstallmentInfo
596
+ );
597
+
598
+ // Check if the issuer is necessary to pay.
599
+ var issuerMandatory = false, additionalInfo = response[0].additional_info_needed;
600
+
601
+ for ( var i=0; i<additionalInfo.length; i++ ) {
602
+ if ( additionalInfo[i] == "issuer_id" ) {
603
+ issuerMandatory = true;
604
  }
605
  };
606
+
607
+ if ( issuerMandatory && MPv1.site_id != "MLM" ) {
608
+ var payment_method_id = response[0].id;
609
+ MPv1.getIssuersPaymentMethod( payment_method_id );
610
+ } else {
611
+ MPv1.hideIssuer();
612
+ }
613
+
614
  }
615
+
616
+ }
617
+
618
+ MPv1.changePaymetMethodSelector = function() {
619
+ var payment_method_id =
620
+ document.querySelector( MPv1.selectors.paymentMethodSelector ).value;
621
+ MPv1.getIssuersPaymentMethod( payment_method_id );
622
  }
623
 
624
+ // === Issuers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
 
626
+ MPv1.getIssuersPaymentMethod = function( payment_method_id ) {
 
 
 
 
627
 
628
+ var amount = MPv1.getAmount();
629
 
630
+ // flow: MLM mercadopagocard
631
+ if ( payment_method_id == "mercadopagocard" ) {
632
+ Mercadopago.getInstallments(
633
+ { "payment_method_id": payment_method_id, "amount": amount },
634
+ MPv1.setInstallmentInfo
635
+ );
636
+ }
637
 
638
+ Mercadopago.getIssuers( payment_method_id, MPv1.showCardIssuers );
639
+ MPv1.addListenerEvent(
640
+ document.querySelector( MPv1.selectors.issuer ),
641
+ "change",
642
+ MPv1.setInstallmentsByIssuerId
643
+ );
644
 
645
+ }
646
 
647
+ MPv1.showCardIssuers = function( status, issuers ) {
648
 
649
+ // If the API does not return any bank.
650
+ if ( issuers.length > 0 ) {
651
+ var issuersSelector = document.querySelector( MPv1.selectors.issuer );
652
+ var fragment = document.createDocumentFragment();
653
 
654
+ issuersSelector.options.length = 0;
655
+ var option = new Option( MPv1.text.choose + "...", "-1" );
656
+ fragment.appendChild( option );
657
 
658
+ for ( var i=0; i<issuers.length; i++ ) {
659
+ if ( issuers[i].name != "default" ) {
660
+ option = new Option( issuers[i].name, issuers[i].id );
661
+ } else {
662
+ option = new Option( "Otro", issuers[i].id );
663
+ }
664
+ fragment.appendChild( option );
665
+ }
666
 
667
+ issuersSelector.appendChild( fragment );
668
+ issuersSelector.removeAttribute( "disabled" );
669
+ } else {
670
+ MPv1.hideIssuer();
671
+ }
 
 
 
672
 
673
+ }
 
 
674
 
675
+ MPv1.setInstallmentsByIssuerId = function( status, response ) {
 
 
 
676
 
677
+ var issuerId = document.querySelector( MPv1.selectors.issuer ).value;
678
+ var amount = MPv1.getAmount();
 
 
679
 
680
+ if ( issuerId === "-1" ) {
681
+ return;
682
+ }
683
 
684
+ var params_installments = {
685
+ "bin": MPv1.getBin(),
686
+ "amount": amount,
687
+ "issuer_id": issuerId
688
+ }
689
 
690
+ if ( MPv1.site_id == "MLM" ) {
691
+ params_installments = {
692
+ "payment_method_id": document.querySelector(
693
+ MPv1.selectors.paymentMethodSelector
694
+ ).value,
695
+ "amount": amount,
696
+ "issuer_id": issuerId
697
+ }
698
+ }
699
+ Mercadopago.getInstallments( params_installments, MPv1.setInstallmentInfo );
700
 
701
+ }
702
 
703
+ MPv1.hideIssuer = function() {
704
+ var $issuer = document.querySelector( MPv1.selectors.issuer );
705
+ var opt = document.createElement( "option" );
706
+ opt.value = "-1";
707
+ opt.innerHTML = MPv1.text.other_bank;
708
 
709
+ $issuer.innerHTML = "";
710
+ $issuer.appendChild( opt );
711
+ $issuer.setAttribute( "disabled", "disabled" );
712
+ }
713
 
714
+ // === Installments
 
 
715
 
716
+ MPv1.setInstallmentInfo = function( status, response ) {
717
 
718
+ var selectorInstallments = document.querySelector( MPv1.selectors.installments );
719
 
720
+ if ( response.length > 0 ) {
 
 
 
721
 
722
+ var html_option = "<option value='-1'>" + MPv1.text.choose + "...</option>";
723
+ payerCosts = response[0].payer_costs;
 
 
 
724
 
725
+ // fragment.appendChild(option);
726
+ for ( var i=0; i<payerCosts.length; i++) {
727
+ /*html_option += "<option value='" + payerCosts[i].installments + "'>" +
728
+ ( payerCosts[i].recommended_message || payerCosts[i].installments ) +
729
+ "</option>";*/
730
+ // Resolution 51/2017
731
+ var dataInput = "";
732
+ if ( MPv1.site_id == "MLA" ) {
733
+ var tax = payerCosts[i].labels;
734
+ if ( tax.length > 0 ) {
735
+ for ( var l=0; l<tax.length; l++ ) {
736
+ if ( tax[l].indexOf( "CFT_" ) !== -1 ) {
737
+ dataInput = "data-tax='" + tax[l] + "'";
738
+ }
739
+ }
740
+ }
741
+ }
742
+ html_option += "<option value='" + payerCosts[i].installments + "' " + dataInput + ">" +
743
+ (payerCosts[i].recommended_message || payerCosts[i].installments) +
744
+ "</option>";
745
+ }
746
 
747
+ // Not take the user's selection if equal.
748
+ if ( selectorInstallments.innerHTML != html_option ) {
749
+ selectorInstallments.innerHTML = html_option;
750
+ }
751
 
752
+ selectorInstallments.removeAttribute( "disabled" );
753
+ MPv1.showTaxes();
754
 
755
+ }
756
 
757
+ }
 
758
 
759
+ MPv1.showTaxes = function() {
760
+ var selectorIsntallments = document.querySelector( MPv1.selectors.installments );
761
+ var tax = selectorIsntallments.options[selectorIsntallments.selectedIndex].getAttribute( "data-tax" );
762
+ var cft = "";
763
+ var tea = "";
764
+ if ( tax != null ) {
765
+ var tax_split = tax.split( "|" );
766
+ cft = tax_split[0].replace( "_", " ");
767
+ tea = tax_split[1].replace( "_", " ");
768
+ if ( cft == "CFT 0,00%" && tea == "TEA 0,00%" ) {
769
+ cft = "";
770
+ tea = "";
771
+ }
772
+ }
773
+ document.querySelector( MPv1.selectors.taxTextCFT ).innerHTML = cft;
774
+ document.querySelector( MPv1.selectors.taxTextTEA ).innerHTML = tea;
775
+ }
776
 
777
+ // === Customer & Cards
778
 
779
+ MPv1.cardsHandler = function() {
 
 
780
 
781
+ var cardSelector = document.querySelector( MPv1.selectors.paymentMethodSelector );
782
+ var type_checkout =
783
+ cardSelector[cardSelector.options.selectedIndex].getAttribute( "type_checkout" );
784
+ var amount = MPv1.getAmount();
785
 
786
+ if ( MPv1.customer_and_card.default ) {
 
787
 
788
+ if ( cardSelector &&
789
+ cardSelector[cardSelector.options.selectedIndex].value != "-1" &&
790
+ type_checkout == "customer_and_card" ) {
791
 
792
+ document.querySelector( MPv1.selectors.paymentMethodId )
793
+ .value = cardSelector[cardSelector.options.selectedIndex]
794
+ .getAttribute( "payment_method_id" );
795
 
796
+ MPv1.clearOptions();
 
 
797
 
798
+ MPv1.customer_and_card.status = true;
 
 
799
 
800
+ var _bin = cardSelector[cardSelector.options.selectedIndex]
801
+ .getAttribute( "first_six_digits" );
802
 
803
+ Mercadopago.getPaymentMethod(
804
+ { "bin": _bin },
805
+ MPv1.setPaymentMethodInfo
806
+ );
 
 
 
807
 
808
+ } else {
809
 
810
+ document.querySelector( MPv1.selectors.paymentMethodId )
811
+ .value = cardSelector.value != -1 ? cardSelector.value : "";
812
+ MPv1.customer_and_card.status = false;
813
+ MPv1.resetBackgroundCard();
814
+ MPv1.guessingPaymentMethod(
815
+ { type: "keyup" }
816
+ );
817
 
818
+ }
 
819
 
820
+ MPv1.setForm();
 
 
 
 
 
 
821
 
822
+ }
 
 
 
823
 
824
+ }
 
825
 
826
+ // === Payment Methods
 
827
 
828
+ MPv1.getPaymentMethods = function() {
 
829
 
830
+ var fragment = document.createDocumentFragment();
831
+ var paymentMethodsSelector =
832
+ document.querySelector( MPv1.selectors.paymentMethodSelector )
833
+ var mainPaymentMethodSelector =
834
+ document.querySelector( MPv1.selectors.paymentMethodSelector )
835
 
836
+ // Set loading.
837
+ mainPaymentMethodSelector.style.background =
838
+ "url(" + MPv1.paths.loading + ") 95% 50% no-repeat #fff";
839
 
840
+ // If customer and card.
841
+ if ( MPv1.customer_and_card.status ) {
842
+ paymentMethodsSelector = document.querySelector( MPv1.selectors.pmListOtherCards )
843
+ // Clean payment methods.
844
+ paymentMethodsSelector.innerHTML = "";
845
+ } else {
846
+ paymentMethodsSelector.innerHTML = "";
847
+ option = new Option( MPv1.text.choose + "...", "-1" );
848
+ fragment.appendChild( option );
849
+ }
850
 
851
+ Mercadopago.getAllPaymentMethods( function( code, payment_methods ) {
 
 
 
 
852
 
853
+ for ( var x=0; x < payment_methods.length; x++ ) {
 
 
 
854
 
855
+ var pm = payment_methods[x];
 
 
 
 
 
 
 
 
 
 
 
 
 
856
 
857
+ if ( ( pm.payment_type_id == "credit_card" || pm.payment_type_id == "debit_card" ||
858
+ pm.payment_type_id == "prepaid_card" ) && pm.status == "active" ) {
859
 
860
+ option = new Option( pm.name, pm.id );
861
+ option.setAttribute( "type_checkout", "custom" );
862
+ fragment.appendChild( option );
863
+
864
+ } // end if
865
+
866
+ } // end for
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
867
 
868
+ paymentMethodsSelector.appendChild( fragment );
869
+ mainPaymentMethodSelector.style.background = "#fff";
870
 
871
+ } );
872
 
873
+ }
874
+
875
+ // === Functions related to Create Tokens
876
+
877
+ MPv1.createTokenByEvent = function() {
878
+
879
+ var $inputs = MPv1.getForm().querySelectorAll( "[data-checkout]" );
880
+ var $inputs_to_create_token = MPv1.getInputsToCreateToken();
881
+
882
+ for (var x=0; x<$inputs.length; x++) {
883
+
884
+ var element = $inputs[x];
885
+
886
+ // Add events only in the required fields.
887
+ if ( $inputs_to_create_token
888
+ .indexOf( element.getAttribute( "data-checkout" ) ) > -1 ) {
889
+
890
+ var event = "focusout";
891
+
892
+ if ( element.nodeName == "SELECT" ) {
893
+ event = "change";
894
+ }
895
+
896
+ MPv1.addListenerEvent( element, event, MPv1.validateInputsCreateToken );
897
+
898
+ // For firefox.
899
+ MPv1.addListenerEvent( element, "blur", MPv1.validateInputsCreateToken );
900
+
901
+ if ( MPv1.create_token_on.keyup ) {
902
+ MPv1.addListenerEvent(element, "keyup", MPv1.validateInputsCreateToken );
903
+ }
904
 
905
+ if ( MPv1.create_token_on.paste ) {
906
+ MPv1.addListenerEvent(element, "paste", MPv1.validateInputsCreateToken );
907
+ }
 
 
 
908
 
909
+ }
 
910
 
911
+ }
 
 
 
912
 
913
+ }
 
914
 
915
+ MPv1.createTokenBySubmit = function() {
916
+ MPv1.addListenerEvent( document.querySelector( MPv1.selectors.form ), "submit", MPv1.doPay );
917
+ }
918
 
919
+ var doSubmit = false;
920
+
921
+ MPv1.doPay = function( event ) {
922
+ event.preventDefault();
923
+ if ( ! doSubmit ) {
924
+ MPv1.createToken();
925
+ return false;
926
+ }
927
+ }
928
 
929
+ MPv1.validateInputsCreateToken = function() {
930
 
931
+ var valid_to_create_token = true;
932
+ var $inputs = MPv1.getForm().querySelectorAll( "[data-checkout]" );
933
+ var $inputs_to_create_token = MPv1.getInputsToCreateToken();
934
 
935
+ for (var x=0; x<$inputs.length; x++) {
936
 
937
+ var element = $inputs[x];
 
 
938
 
939
+ // Check is a input to create token.
940
+ if ( $inputs_to_create_token
941
+ .indexOf( element.getAttribute( "data-checkout" ) ) > -1 ) {
942
 
943
+ if ( element.value == -1 || element.value == "" ) {
944
+ valid_to_create_token = false;
945
+ } // end if check values
946
+ } // end if check data-checkout
947
+ } // end for
948
 
949
+ if ( valid_to_create_token ) {
950
+ MPv1.createToken();
951
+ }
 
 
952
 
953
+ }
954
 
955
+ MPv1.createToken = function() {
956
+ MPv1.hideErrors();
 
 
 
 
 
 
 
957
 
958
+ // Show loading.
959
+ document.querySelector( MPv1.selectors.box_loading ).style.background =
960
+ "url(" + MPv1.paths.loading + ") 0 50% no-repeat #fff";
961
 
962
+ // Form.
963
+ var $form = MPv1.getForm();
964
 
965
+ Mercadopago.createToken( $form, MPv1.sdkResponseHandler );
966
 
967
+ return false;
968
+ }
969
 
970
+ MPv1.sdkResponseHandler = function( status, response ) {
971
 
972
+ // Hide loading.
973
+ document.querySelector( MPv1.selectors.box_loading ).style.background = "";
974
 
975
+ if ( status != 200 && status != 201 ) {
976
+ MPv1.showErrors( response );
977
+ } else {
978
+ var token = document.querySelector( MPv1.selectors.token );
979
+ token.value = response.id;
980
+
981
+ if ( MPv1.add_truncated_card ) {
982
+ var card = MPv1.truncateCard( response );
983
+ document.querySelector( MPv1.selectors.cardTruncated ).value = card;
984
+ }
985
+
986
+ if ( ! MPv1.create_token_on.event ) {
987
+ doSubmit = true;
988
+ btn = document.querySelector( MPv1.selectors.form );
989
+ btn.submit();
990
+ }
991
+ }
992
 
993
+ }
994
 
995
+ // === Useful functions
 
 
 
 
996
 
997
+ MPv1.resetBackgroundCard = function() {
998
+ document.querySelector( MPv1.selectors.paymentMethodSelector ).style.background =
999
+ "no-repeat #fff";
1000
+ document.querySelector( MPv1.selectors.cardNumber ).style.background =
1001
+ "no-repeat #fff";
1002
+ }
1003
 
1004
+ MPv1.setForm = function() {
1005
+ if ( MPv1.customer_and_card.status ) {
1006
+ document.querySelector( MPv1.selectors.formDiv ).style.display = "none";
1007
+ document.querySelector( MPv1.selectors.mpSecurityCodeCustomerAndCard ).removeAttribute( "style" );
1008
  } else {
1009
+ document.querySelector( MPv1.selectors.mpSecurityCodeCustomerAndCard ).style.display = "none";
1010
+ document.querySelector( MPv1.selectors.formDiv ).removeAttribute( "style" );
1011
  }
1012
 
1013
+ Mercadopago.clearSession();
1014
+
1015
+ if ( MPv1.create_token_on.event ) {
 
 
 
 
 
 
 
 
 
 
1016
  MPv1.createTokenByEvent();
1017
+ MPv1.validateInputsCreateToken();
1018
+ }
 
1019
 
1020
+ document.querySelector( MPv1.selectors.CustomerAndCard ).value =
1021
+ MPv1.customer_and_card.status;
1022
+ }
 
1023
 
1024
+ MPv1.getForm = function() {
1025
+ if ( MPv1.customer_and_card.status ) {
1026
+ return document.querySelector( MPv1.selectors.formCustomerAndCard );
1027
+ } else {
1028
+ return document.querySelector( MPv1.selectors.form );
1029
+ }
1030
+ }
1031
 
1032
+ MPv1.getInputsToCreateToken = function() {
1033
+ if ( MPv1.customer_and_card.status ) {
1034
+ return MPv1.inputs_to_create_token_customer_and_card;
1035
+ } else {
1036
+ return MPv1.inputs_to_create_token;
1037
+ }
1038
+ }
 
1039
 
1040
+ MPv1.truncateCard = function( response_card_token ) {
 
 
1041
 
1042
+ var first_six_digits;
1043
+ var last_four_digits;
1044
 
1045
+ if ( MPv1.customer_and_card.status ) {
1046
+ var cardSelector = document.querySelector( MPv1.selectors.paymentMethodSelector );
1047
+ first_six_digits = cardSelector[cardSelector.options.selectedIndex]
1048
+ .getAttribute( "first_six_digits" ).match( /.{1,4}/g )
1049
+ last_four_digits = cardSelector[cardSelector.options.selectedIndex]
1050
+ .getAttribute( "last_four_digits" )
1051
+ } else {
1052
+ first_six_digits = response_card_token.first_six_digits.match( /.{1,4}/g )
1053
+ last_four_digits = response_card_token.last_four_digits
1054
+ }
1055
 
1056
+ var card = first_six_digits[0] + " " +
1057
+ first_six_digits[1] + "** **** " + last_four_digits;
1058
 
1059
+ return card;
 
 
 
 
1060
 
1061
+ }
 
 
1062
 
1063
+ MPv1.getAmount = function() {
1064
+ return document.querySelector( MPv1.selectors.amount ).value;
1065
+ }
1066
+
1067
+ // === Show errors
1068
 
1069
+ MPv1.showErrors = function( response ) {
1070
+ var $form = MPv1.getForm();
1071
 
1072
+ for ( var x=0; x<response.cause.length; x++ ) {
1073
+ var error = response.cause[x];
1074
+ var $span = $form.querySelector( "#mp-error-" + error.code );
1075
+ var $input = $form.querySelector( $span.getAttribute( "data-main" ) );
1076
 
1077
+ $span.style.display = "inline-block";
1078
+ $input.classList.add( "mp-error-input" );
1079
+ }
1080
 
1081
+ return;
1082
+ }
1083
 
1084
+ MPv1.hideErrors = function() {
1085
+
1086
+ for ( var x = 0; x < document.querySelectorAll( "[data-checkout]" ).length; x++ ) {
1087
+ var $field = document.querySelectorAll( "[data-checkout]" )[x];
1088
+ $field.classList.remove( "mp-error-input" );
1089
+ } // end for
1090
+
1091
+ for ( var x = 0; x < document.querySelectorAll( ".mp-error" ).length; x++ ) {
1092
+ var $span = document.querySelectorAll( ".mp-error" )[x];
1093
+ $span.style.display = "none";
1094
+ }
1095
 
1096
+ return;
1097
+
1098
+ }
1099
+
1100
+ // === Add events to guessing
1101
+
1102
+ MPv1.addListenerEvent = function( el, eventName, handler ) {
1103
+ if ( el.addEventListener ) {
1104
+ el.addEventListener( eventName, handler );
1105
+ } else {
1106
+ el.attachEvent( "on" + eventName, function() {
1107
+ handler.call( el );
1108
+ });
1109
+ }
1110
+ };
1111
+
1112
+ MPv1.addListenerEvent(
1113
+ document.querySelector( MPv1.selectors.cardNumber ),
1114
+ "keyup", MPv1.guessingPaymentMethod
1115
+ );
1116
+ MPv1.addListenerEvent(
1117
+ document.querySelector( MPv1.selectors.cardNumber ),
1118
+ "keyup", MPv1.clearOptions
1119
+ );
1120
+ MPv1.addListenerEvent(
1121
+ document.querySelector( MPv1.selectors.cardNumber),
1122
+ "change", MPv1.guessingPaymentMethod
1123
+ );
1124
+
1125
+ /*
1126
+ *
1127
+ * Utilities
1128
+ *
1129
+ */
1130
+
1131
+ MPv1.referer = (function () {
1132
+ var referer = window.location.protocol + "//" +
1133
+ window.location.hostname + ( window.location.port ? ":" + window.location.port: "" );
1134
+ return referer;
1135
+ })();
1136
+
1137
+ MPv1.AJAX = function( options ) {
1138
+ var useXDomain = !!window.XDomainRequest;
1139
+ var req = useXDomain ? new XDomainRequest() : new XMLHttpRequest()
1140
+ var data;
1141
+ options.url += ( options.url.indexOf( "?" ) >= 0 ? "&" : "?" ) + "referer=" + escape( MPv1.referer );
1142
+ options.requestedMethod = options.method;
1143
+ if ( useXDomain && options.method == "PUT" ) {
1144
+ options.method = "POST";
1145
+ options.url += "&_method=PUT";
1146
+ }
1147
+ req.open( options.method, options.url, true );
1148
+ req.timeout = options.timeout || 1000;
1149
+ if ( window.XDomainRequest ) {
1150
+ req.onload = function() {
1151
+ data = JSON.parse( req.responseText );
1152
+ if ( typeof options.success === "function" ) {
1153
+ options.success( options.requestedMethod === "POST" ? 201 : 200, data );
1154
+ }
1155
+ };
1156
+ req.onerror = req.ontimeout = function() {
1157
+ if ( typeof options.error === "function" ) {
1158
+ options.error( 400, {
1159
+ user_agent:window.navigator.userAgent, error : "bad_request", cause:[]
1160
+ });
1161
+ }
1162
+ };
1163
+ req.onprogress = function() {};
1164
+ } else {
1165
+ req.setRequestHeader( "Accept", "application/json" );
1166
+ if ( options.contentType ) {
1167
+ req.setRequestHeader( "Content-Type", options.contentType );
1168
+ } else {
1169
+ req.setRequestHeader( "Content-Type", "application/json" );
1170
+ }
1171
+ req.onreadystatechange = function() {
1172
+ if ( this.readyState === 4 ) {
1173
+ if ( this.status >= 200 && this.status < 400 ) {
1174
+ // Success!
1175
+ data = JSON.parse( this.responseText );
1176
+ if ( typeof options.success === "function" ) {
1177
+ options.success( this.status, data );
1178
+ }
1179
+ } else if ( this.status >= 400 ) {
1180
+ data = JSON.parse( this.responseText );
1181
+ if ( typeof options.error === "function" ) {
1182
+ options.error( this.status, data );
1183
+ }
1184
+ } else if ( typeof options.error === "function" ) {
1185
+ options.error( 503, {} );
1186
+ }
1187
+ }
1188
+ };
1189
+ }
1190
+ if ( options.method === "GET" || options.data == null || options.data == undefined ) {
1191
+ req.send();
1192
+ } else {
1193
+ req.send( JSON.stringify( options.data ) );
1194
+ }
1195
+ }
1196
+
1197
+ // === Initialization function
1198
+
1199
+ MPv1.Initialize = function( site_id, public_key, coupon_mode, discount_action_url, payer_email ) {
1200
+
1201
+ // Sets
1202
+ MPv1.site_id = site_id;
1203
+ MPv1.public_key = public_key;
1204
+ MPv1.coupon_of_discounts.default = coupon_mode;
1205
+ MPv1.coupon_of_discounts.discount_action_url = discount_action_url;
1206
+ MPv1.coupon_of_discounts.payer_email = payer_email;
1207
+
1208
+ Mercadopago.setPublishableKey( MPv1.public_key );
1209
+
1210
+ // flow coupon of discounts
1211
+ if ( MPv1.coupon_of_discounts.default ) {
1212
+ MPv1.addListenerEvent(
1213
+ document.querySelector( MPv1.selectors.applyCoupon ),
1214
+ "click", MPv1.checkCouponEligibility
1215
+ );
1216
+ } else {
1217
+ document.querySelector( MPv1.selectors.formCoupon ).style.display = "none";
1218
+ }
1219
+
1220
+ // Flow: customer & cards.
1221
+ var selectorPmCustomerAndCards = document.querySelector( MPv1.selectors.pmCustomerAndCards );
1222
+ if ( MPv1.customer_and_card.default && selectorPmCustomerAndCards.childElementCount > 0 ) {
1223
+ MPv1.addListenerEvent(
1224
+ document.querySelector( MPv1.selectors.paymentMethodSelector ),
1225
+ "change", MPv1.cardsHandler
1226
+ );
1227
+ MPv1.cardsHandler();
1228
+ } else {
1229
+ // If customer & cards is disabled or customer does not have cards.
1230
+ MPv1.customer_and_card.status = false;
1231
+ document.querySelector( MPv1.selectors.formCustomerAndCard ).style.display = "none";
1232
+ }
1233
+
1234
+ if ( MPv1.create_token_on.event ) {
1235
+ MPv1.createTokenByEvent();
1236
+ } else {
1237
+ MPv1.createTokenBySubmit()
1238
+ }
1239
+
1240
+ // flow: MLM
1241
+ if ( MPv1.site_id != "MLM" ) {
1242
+ Mercadopago.getIdentificationTypes();
1243
+ }
1244
+
1245
+ if ( MPv1.site_id == "MLM" ) {
1246
+
1247
+ // Hide documento for mex.
1248
+ document.querySelector( MPv1.selectors.mpDoc ).style.display = "none";
1249
+
1250
+ document.querySelector( MPv1.selectors.formCustomerAndCard ).removeAttribute( 'style' );
1251
+ document.querySelector( MPv1.selectors.formCustomerAndCard ).style.padding = "36px 36px 16px 36px";
1252
+ document.querySelector( MPv1.selectors.mpSecurityCodeCustomerAndCard ).style.display = "none";
1253
+
1254
+ // Removing not used fields for this country.
1255
+ MPv1.inputs_to_create_token.splice(
1256
+ MPv1.inputs_to_create_token.indexOf( "docType" ),
1257
+ 1 );
1258
+ MPv1.inputs_to_create_token.splice(
1259
+ MPv1.inputs_to_create_token.indexOf( "docNumber" ),
1260
+ 1 );
1261
+
1262
+ MPv1.addListenerEvent(
1263
+ document.querySelector( MPv1.selectors.paymentMethodSelector ),
1264
+ "change",
1265
+ MPv1.changePaymetMethodSelector
1266
+ );
1267
+
1268
+ // Get payment methods and populate selector.
1269
+ MPv1.getPaymentMethods();
1270
+
1271
+ }
1272
+
1273
+ // flow: MLB AND MCO
1274
+ if ( MPv1.site_id == "MLB" ) {
1275
+
1276
+ document.querySelector( MPv1.selectors.mpDocType ).style.display = "none";
1277
+ document.querySelector( MPv1.selectors.mpIssuer ).style.display = "none";
1278
+ // Adjust css.
1279
+ document.querySelector( MPv1.selectors.docNumber ).classList.remove( "mp-col-75" );
1280
+ document.querySelector( MPv1.selectors.docNumber ).classList.add( "mp-col-100" );
1281
+
1282
+ } else if ( MPv1.site_id == "MCO" ) {
1283
+ document.querySelector( MPv1.selectors.mpIssuer ).style.display = "none";
1284
+ } else if ( MPv1.site_id == "MLA" ) {
1285
+ document.querySelector( MPv1.selectors.boxInstallmentsSelector ).classList.remove( "mp-col-100" );
1286
+ document.querySelector( MPv1.selectors.boxInstallmentsSelector ).classList.add( "mp-col-70" );
1287
+ document.querySelector( MPv1.selectors.taxCFT ).style.display = "block";
1288
+ document.querySelector( MPv1.selectors.taxTEA ).style.display = "block";
1289
+ MPv1.addListenerEvent( document.querySelector( MPv1.selectors.installments ), "change", MPv1.showTaxes );
1290
+ }
1291
+
1292
+ if ( MPv1.debug ) {
1293
+ document.querySelector( MPv1.selectors.utilities_fields ).style.display = "inline-block";
1294
+ }
1295
+
1296
+ document.querySelector( MPv1.selectors.site_id ).value = MPv1.site_id;
1297
+
1298
+ return;
1299
+
1300
+ }
1301
+
1302
+ this.MPv1 = MPv1;
1303
+
1304
+ } ).call();
1305
 
1306
  // === Instantiation
1307
 
1308
+ var mercadopago_site_id = "<?php echo $site_id; ?>";
1309
+ var mercadopago_public_key = "<?php echo $public_key; ?>";
1310
+ var mercadopago_payer_email = "<?php echo $payer_email; ?>";
1311
+ var mercadopago_coupon_mode = "<?php echo $coupon_mode; ?>";
1312
+ var mercadopago_discount_action_url = "<?php echo $discount_action_url; ?>";
1313
+
1314
+ MPv1.text.choose = "<?php echo $form_labels['form']['label_choose']; ?>";
1315
+ MPv1.text.other_bank = "<?php echo $form_labels['form']['label_other_bank']; ?>";
1316
+ MPv1.text.discount_info1 = "<?php echo $form_labels['form']['discount_info1']; ?>";
1317
+ MPv1.text.discount_info2 = "<?php echo $form_labels['form']['discount_info2']; ?>";
1318
+ MPv1.text.discount_info3 = "<?php echo $form_labels['form']['discount_info3']; ?>";
1319
+ MPv1.text.discount_info4 = "<?php echo $form_labels['form']['discount_info4']; ?>";
1320
+ MPv1.text.discount_info5 = "<?php echo $form_labels['form']['discount_info5']; ?>";
1321
+ MPv1.text.discount_info6 = "<?php echo $form_labels['form']['discount_info6']; ?>";
1322
+ MPv1.text.apply = "<?php echo $form_labels['form']['apply']; ?>";
1323
+ MPv1.text.remove = "<?php echo $form_labels['form']['remove']; ?>";
1324
+ MPv1.text.coupon_empty = "<?php echo $form_labels['form']['coupon_empty']; ?>";
1325
+ MPv1.paths.loading = "<?php echo ( $images_path . 'loading.gif' ); ?>";
1326
+ MPv1.paths.check = "<?php echo ( $images_path . 'check.png' ); ?>";
1327
+ MPv1.paths.error = "<?php echo ( $images_path . 'error.png' ); ?>";
1328
+
1329
+ // Overriding this function to give form padding attribute.
1330
+ MPv1.setForm = function() {
1331
+ if ( MPv1.customer_and_card.status ) {
1332
+ document.querySelector( MPv1.selectors.form ).style.display = "none";
1333
+ document.querySelector( MPv1.selectors.mpSecurityCodeCustomerAndCard ).removeAttribute( "style" );
1334
+ } else {
1335
+ document.querySelector( MPv1.selectors.mpSecurityCodeCustomerAndCard ).style.display = "none";
1336
+ document.querySelector( MPv1.selectors.form ).removeAttribute( "style" );
1337
+ document.querySelector( MPv1.selectors.form ).style.padding = "0px 12px 0px 12px";
1338
+ }
1339
+ Mercadopago.clearSession();
1340
+ if ( MPv1.create_token_on.event ) {
1341
+ MPv1.createTokenByEvent();
1342
+ MPv1.validateInputsCreateToken();
1343
+ }
1344
+ document.querySelector( MPv1.selectors.CustomerAndCard ).value =
1345
+ MPv1.customer_and_card.status;
1346
+ }
1347
+
1348
+ MPv1.getAmount = function() {
1349
+ return document.querySelector( MPv1.selectors.amount )
1350
+ .value - document.querySelector( MPv1.selectors.discount ).value;
1351
+ }
1352
+
1353
+ MPv1.getAmountWithoutDiscount = function() {
1354
+ return document.querySelector( MPv1.selectors.amount ).value;
1355
+ }
1356
+
1357
+ MPv1.showErrors = function( response ) {
1358
+ var $form = MPv1.getForm();
1359
+ for ( var x=0; x<response.cause.length; x++ ) {
1360
+ var error = response.cause[x];
1361
+ var $span = $form.querySelector( "#mp-error-" + error.code );
1362
+ var $input = $form.querySelector( $span.getAttribute( "data-main" ) );
1363
+ $span.style.display = "inline-block";
1364
+ $input.classList.add( "mp-error-input" );
1365
+ }
1366
+ return;
1367
+ }
1368
+ MPv1.Initialize(
1369
+ mercadopago_site_id,
1370
+ mercadopago_public_key,
1371
+ mercadopago_coupon_mode == "yes",
1372
+ mercadopago_discount_action_url,
1373
+ mercadopago_payer_email
1374
+ );
1375
 
1376
  </script>
templates/ticket/ticket-form.php CHANGED
@@ -1,348 +1,659 @@
1
  <?php
 
2
  /**
3
  * Part of Woo Mercado Pago Module
4
  * Author - Mercado Pago
5
  * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
6
- * Copyright - Copyright(c) MercadoPago [http://www.mercadopago.com]
7
- * License - http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
8
  */
9
-
10
  if ( ! defined( 'ABSPATH' ) ) {
11
  exit;
12
  }
 
13
  ?>
14
 
15
- <div width="100%" style="margin:1px; padding:36px 36px 16px 36px; background:white; ">
16
- <img class="logo" src="<?php echo ( $images_path . 'mplogo.png' ); ?>" width="156" height="40" />
17
- <?php if ( count( $payment_methods ) > 1 ) { ?>
18
- <img class="logo" src="<?php echo ( $images_path . 'boleto.png' ); ?>" width="90" height="40" style="float:right;"/>
19
- <?php } else { ?>
20
- <?php foreach ( $payment_methods as $payment ) { ?>
21
- <img class="logo" src="<?php echo $payment[ 'thumbnail' ]; ?>" width="90" height="40" style="float:right;"/>
22
- <?php } ?>
23
- <?php } ?>
 
 
24
  </div>
25
- <fieldset id="mercadopago-form" style="background:white; ">
26
-
27
- <div class="mp-box-inputs mp-line" id="mercadopago-form-coupon-ticket" style="padding:0px 36px 16px 36px;">
28
- <label for="couponCodeLabel"><?php echo $form_labels['form']['coupon_of_discounts']; ?></label>
29
- <div class="mp-box-inputs mp-col-65">
30
- <input type="text" id="couponCodeTicket" name="mercadopago_ticket[coupon_code]" autocomplete="off" maxlength="24" />
31
- <span class="mp-discount" id="mpCouponApplyedTicket" ></span>
32
- <span class="mp-error" id="mpCouponErrorTicket" ></span>
33
- </div>
34
- <div class="mp-box-inputs mp-col-10">
35
- <div id="mp-separete-date"></div>
36
- </div>
37
- <div class="mp-box-inputs mp-col-25">
38
- <input type="button" class="button" id="applyCouponTicket" value="<?php echo $form_labels['form']['apply']; ?>" >
39
- </div>
40
- </div>
41
-
42
- <div style="padding:0px 36px 0px 36px;">
43
- <p>
44
- <?php if ( count( $payment_methods ) > 1 ) { ?>
45
- <?php echo $form_labels[ 'form' ][ 'issuer_selection' ] ?>
46
- <?php } ?>
47
- <?php echo $form_labels[ 'form' ][ 'payment_instructions' ] ?>
48
- <br />
49
- <?php echo $form_labels[ 'form' ][ 'ticket_note' ] ?>
50
- <?php if ($is_currency_conversion > 0) { ?>
51
- <?php echo " (" . $form_labels['form']['payment_converted'] . " " . $woocommerce_currency . " " . $form_labels['form']['to'] . " " . $account_currency . ")"; ?>
52
- <?php } ?>
53
- </p>
54
- <?php if ( count( $payment_methods ) > 1 ) { ?>
55
- <div class="mp-box-inputs mp-col-100">
56
- <!--<select id="paymentMethodId" name="mercadopago_ticket[paymentMethodId]">
57
- <option value="-1"> <?php /*echo $form_labels[ 'form' ][ 'label_choose' ] . " ...";*/ ?> </option>-->
58
- <?php $atFirst = true; ?>
59
- <?php foreach ( $payment_methods as $payment ) { ?>
60
- <!--<option value="<?php /*echo $payment[ 'id' ];*/ ?>"> <?php /*echo $payment[ 'name' ];*/ ?></option>-->
61
- <div class="mp-box-inputs mp-line">
62
- <div id="paymentMethodId" class="mp-box-inputs mp-col-5">
63
- <input type="radio" class="input-radio" name="mercadopago_ticket[paymentMethodId]"
64
- style="height:16px; width:16px;" value="<?php echo $payment[ 'id' ]; ?>"
65
- <?php if ( $atFirst ) { ?> checked="checked" } <?php } ?> />
66
- </div>
67
- <div class="mp-box-inputs mp-col-45">
68
- <label>
69
- <img src="<?php echo $payment[ 'thumbnail' ]; ?>" alt="<?php echo $payment[ 'name' ]; ?>" />
70
- &nbsp;(<?php echo $payment[ 'name' ]; ?>)
71
- </label>
72
- </div>
73
- </div>
74
- <?php $atFirst = false; ?>
75
- <?php } ?>
76
- <!--</select>-->
77
  </div>
78
- <?php } else { ?>
79
- <div class="mp-box-inputs mp-col-100" style="display:none;">
80
- <select id="paymentMethodId" name="mercadopago_ticket[paymentMethodId]">
81
- <?php foreach ( $payment_methods as $payment ) { ?>
82
- <option value="<?php echo $payment[ 'id' ]; ?>"
83
- style="padding: 8px; background: url( 'http://img.mlstatic.com/org-img/MP3/API/logos/bapropagos.gif' ); ?> ) 98% 50% no-repeat;"> <?php echo $payment[ 'name' ]; ?></option>
84
- <?php } ?>
85
- </select>
 
 
 
 
 
86
  </div>
87
- <?php } ?>
88
-
89
- <div class="mp-box-inputs mp-line">
90
- <!-- <div class="mp-box-inputs mp-col-50">
91
- <input type="submit" value="Pay" id="submit"/>
92
- </div> -->
93
- <div class="mp-box-inputs mp-col-25">
94
- <div id="mp-box-loading">
95
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  </div>
97
  </div>
98
 
99
- <!-- utilities -->
100
- <div class="mp-box-inputs mp-col-100" id="mercadopago-utilities">
101
- <input type="hidden" id="public_key" value="<?php echo $public_key; ?>" name="mercadopago_ticket[amount]"/>
102
- <input type="hidden" id="site_id" value="<?php echo $site_id; ?>" name="mercadopago_ticket[site_id]"/>
103
- <input type="hidden" id="amountTicket" value="<?php echo $amount; ?>" name="mercadopago_ticket[amount]"/>
104
- <input type="hidden" id="campaign_idTicket" name="mercadopago_ticket[campaign_id]"/>
105
- <input type="hidden" id="campaignTicket" name="mercadopago_ticket[campaign]"/>
106
- <input type="hidden" id="discountTicket" name="mercadopago_ticket[discount]"/>
107
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
 
109
  </div>
110
  </fieldset>
111
 
112
  <script type="text/javascript">
113
-
114
- (function() {
115
 
116
- var MPv1Ticket = {
117
- site_id: '',
118
- coupon_of_discounts: {
119
- discount_action_url: '',
 
 
 
120
  default: true,
121
  status: false
122
- },
123
-
124
- inputs_to_create_discount: [
125
  "couponCodeTicket",
126
  "applyCouponTicket"
127
  ],
128
-
129
- selectors: {
130
- couponCode: "#couponCodeTicket",
 
 
 
 
 
 
 
 
 
 
131
  applyCoupon: "#applyCouponTicket",
132
  mpCouponApplyed: "#mpCouponApplyedTicket",
133
  mpCouponError: "#mpCouponErrorTicket",
134
-
135
- paymentMethodId: "#paymentMethodId",
136
- amount: "#amountTicket",
137
  campaign_id: "#campaign_idTicket",
138
- campaign: "#campaignTicket",
139
- discount: "#discountTicket",
140
-
141
- formCoupon: '#mercadopago-form-coupon-ticket'
142
- },
143
- text: {
144
- discount_info1: "You will save",
145
- discount_info2: "with discount from",
146
- discount_info3: "Total of your purchase:",
147
- discount_info4: "Total of your purchase with discount:",
148
- discount_info5: "*Uppon payment approval",
149
- discount_info6: "Terms and Conditions of Use",
150
- coupon_empty: "Please, inform your coupon code",
151
- apply: "Apply",
152
- remove: "Remove"
153
- },
154
- paths: {
155
- loading: "images/loading.gif",
156
- check: "images/check.png",
157
- error: "images/error.png"
158
- }
159
- }
160
-
161
- /*
162
- * Coupon of Discounts
163
- */
164
-
165
- MPv1Ticket.currencyIdToCurrency = function (currency_id) {
166
- if ( currency_id == 'ARS' ) {
167
- return '$';
168
- } else if ( currency_id == 'BRL' ) {
169
- return 'R$';
170
- } else if ( currency_id == 'COP' ) {
171
- return '$';
172
- } else if ( currency_id == 'CLP' ) {
173
- return '$';
174
- } else if ( currency_id == 'MXN' ) {
175
- return '$';
176
- } else if ( currency_id == 'VEF' ) {
177
- return 'Bs';
178
- } else if ( currency_id == 'PEN' ) {
179
- return 'S/';
180
- } else {
181
- return '$';
182
- }
183
- }
184
-
185
- MPv1Ticket.checkCouponEligibility = function () {
186
- if ( document.querySelector(MPv1Ticket.selectors.couponCode).value == "" ) {
187
- // coupon code is empty
188
- document.querySelector(MPv1Ticket.selectors.mpCouponApplyed).style.display = 'none';
189
- document.querySelector(MPv1Ticket.selectors.mpCouponError).style.display = 'block';
190
- document.querySelector(MPv1Ticket.selectors.mpCouponError).innerHTML = MPv1Ticket.text.coupon_empty;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  MPv1Ticket.coupon_of_discounts.status = false;
192
- document.querySelector(MPv1Ticket.selectors.couponCode).style.background = null;
193
- document.querySelector(MPv1Ticket.selectors.applyCoupon).value = MPv1Ticket.text.apply;
194
- document.querySelector(MPv1.selectors.discount).value = 0;
195
- //MPv1.cardsHandler();
196
- } else if ( MPv1Ticket.coupon_of_discounts.status ) {
197
- // we already have a coupon set, so we remove it
198
- document.querySelector(MPv1Ticket.selectors.mpCouponApplyed).style.display = 'none';
199
- document.querySelector(MPv1Ticket.selectors.mpCouponError).style.display = 'none';
200
  MPv1Ticket.coupon_of_discounts.status = false;
201
- document.querySelector(MPv1Ticket.selectors.applyCoupon).style.background = null;
202
- document.querySelector(MPv1Ticket.selectors.applyCoupon).value = MPv1Ticket.text.apply;
203
- document.querySelector(MPv1Ticket.selectors.couponCode).value = "";
204
- document.querySelector(MPv1Ticket.selectors.couponCode).style.background = null;
205
- document.querySelector(MPv1.selectors.discount).value = 0;
206
- //MPv1.cardsHandler();
207
- } else {
208
- // set loading
209
- document.querySelector(MPv1Ticket.selectors.mpCouponApplyed).style.display = 'none';
210
- document.querySelector(MPv1Ticket.selectors.mpCouponError).style.display = 'none';
211
- document.querySelector(MPv1Ticket.selectors.couponCode).style.background = "url("+MPv1Ticket.paths.loading+") 98% 50% no-repeat #fff";
212
- document.querySelector(MPv1Ticket.selectors.applyCoupon).disabled = true;
213
- var request = new XMLHttpRequest();
214
- request.open(
215
- 'GET',
216
- MPv1Ticket.coupon_of_discounts.discount_action_url +
217
- "&coupon_id=" + document.querySelector(MPv1Ticket.selectors.couponCode).value +
218
- "&amount=" + document.querySelector(MPv1Ticket.selectors.amount).value +
219
- "&payer=" + document.getElementById("billing_email").value,
220
- true
221
- );
222
- request.onreadystatechange = function() {
223
- if (request.readyState == 4) {
224
- if (request.status == 200) {
225
- var response = JSON.parse(request.responseText);
226
- if (response.status == 200) {
227
- document.querySelector(MPv1Ticket.selectors.mpCouponApplyed).style.display = 'block';
228
- document.querySelector(MPv1Ticket.selectors.discount).value = response.response.coupon_amount;
229
- document.querySelector(MPv1Ticket.selectors.mpCouponApplyed).innerHTML =
230
- "<div style='border-style: solid; border-width:thin; border-color: #009EE3; padding: 8px 8px 8px 8px; margin-top: 4px;'>" +
231
- MPv1Ticket.text.discount_info1 + " <strong>" + MPv1Ticket.currencyIdToCurrency(response.response.currency_id) + " " +
232
- Math.round(response.response.coupon_amount*100)/100 + "</strong> " + MPv1Ticket.text.discount_info2 + " " + response.response.name + ".<br>" +
233
- MPv1Ticket.text.discount_info3 + " <strong>" + MPv1Ticket.currencyIdToCurrency(response.response.currency_id) +
234
- " " + Math.round(MPv1Ticket.getAmountWithoutDiscount()*100)/100 + "</strong><br>" +
235
- MPv1Ticket.text.discount_info4 + " <strong>" + MPv1Ticket.currencyIdToCurrency(response.response.currency_id) +
236
- " " + Math.round(MPv1Ticket.getAmount()*100)/100 + "*</strong><br>" +
237
- "<i>" + MPv1Ticket.text.discount_info5 + "</i><br>" +
238
- "<a href='https://api.mercadolibre.com/campaigns/" + response.response.id + "/terms_and_conditions?format_type=html' target='_blank'>" +
239
- MPv1Ticket.text.discount_info6 + "</a></div>";
240
- document.querySelector(MPv1Ticket.selectors.mpCouponError).style.display = 'none';
241
- MPv1Ticket.coupon_of_discounts.status = true;
242
- document.querySelector(MPv1Ticket.selectors.couponCode).style.background = null;
243
- document.querySelector(MPv1Ticket.selectors.couponCode).style.background = "url("+MPv1Ticket.paths.check+") 98% 50% no-repeat #fff";
244
- document.querySelector(MPv1Ticket.selectors.applyCoupon).value = MPv1Ticket.text.remove;
245
- //MPv1.cardsHandler();
246
- document.querySelector(MPv1Ticket.selectors.campaign_id).value = response.response.id;
247
- document.querySelector(MPv1Ticket.selectors.campaign).value = response.response.name;
248
- } else if (response.status == 400 || response.status == 404) {
249
- document.querySelector(MPv1Ticket.selectors.mpCouponApplyed).style.display = 'none';
250
- document.querySelector(MPv1Ticket.selectors.mpCouponError).style.display = 'block';
251
- document.querySelector(MPv1Ticket.selectors.mpCouponError).innerHTML = response.response.message;
252
- MPv1Ticket.coupon_of_discounts.status = false;
253
- document.querySelector(MPv1Ticket.selectors.couponCode).style.background = null;
254
- document.querySelector(MPv1Ticket.selectors.couponCode).style.background = "url("+MPv1Ticket.paths.error+") 98% 50% no-repeat #fff";
255
- document.querySelector(MPv1Ticket.selectors.applyCoupon).value = MPv1Ticket.text.apply;
256
- document.querySelector(MPv1.selectors.discount).value = 0;
257
- //MPv1.cardsHandler();
258
- }
259
- } else {
260
- // request failed
261
- document.querySelector(MPv1Ticket.selectors.mpCouponApplyed).style.display = 'none';
262
- document.querySelector(MPv1Ticket.selectors.mpCouponError).style.display = 'none';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  MPv1Ticket.coupon_of_discounts.status = false;
264
- document.querySelector(MPv1Ticket.selectors.applyCoupon).style.background = null;
265
- document.querySelector(MPv1Ticket.selectors.applyCoupon).value = MPv1Ticket.text.apply;
266
- document.querySelector(MPv1Ticket.selectors.couponCode).value = "";
267
- document.querySelector(MPv1Ticket.selectors.couponCode).style.background = null;
268
- document.querySelector(MPv1.selectors.discount).value = 0;
269
- //MPv1.cardsHandler();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  }
271
- document.querySelector(MPv1Ticket.selectors.applyCoupon).disabled = false;
272
  }
273
  };
274
- request.send(null);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  }
276
  }
277
 
278
- /*
279
- *
280
- *
281
- * Initialization function
282
- *
283
- */
284
-
285
- MPv1Ticket.addListenerEvent = function(el, eventName, handler) {
286
- if (el.addEventListener) {
287
- el.addEventListener(eventName, handler);
288
- } else {
289
- el.attachEvent('on' + eventName, function() {
290
- handler.call(el);
291
- });
292
- }
293
- };
294
-
295
- MPv1Ticket.Initialize = function(site_id, coupon_mode, discount_action_url) {
296
-
297
- //sets
298
- MPv1Ticket.site_id = site_id
299
- MPv1Ticket.coupon_of_discounts.default = coupon_mode
300
- MPv1Ticket.coupon_of_discounts.discount_action_url = discount_action_url
301
-
302
- // flow coupon of discounts
303
- if (MPv1Ticket.coupon_of_discounts.default) {
304
- MPv1Ticket.addListenerEvent(document.querySelector(MPv1Ticket.selectors.applyCoupon), 'click', MPv1Ticket.checkCouponEligibility);
305
  } else {
306
- document.querySelector(MPv1Ticket.selectors.formCoupon).style.display = 'none';
307
  }
 
308
 
309
- return;
310
- }
 
 
 
 
 
 
 
 
 
 
 
311
 
312
- this.MPv1Ticket = MPv1Ticket;
313
 
314
- }).call();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
 
316
  // === Instantiation
317
 
318
- var mercadopago_site_id = '<?php echo $site_id; ?>';
319
- var mercadopago_coupon_mode = '<?php echo $coupon_mode; ?>';
320
- var mercadopago_discount_action_url = '<?php echo $discount_action_url; ?>';
321
-
322
- MPv1Ticket.text.discount_info1 = '<?php echo $form_labels["form"]["discount_info1"]; ?>';
323
- MPv1Ticket.text.discount_info2 = '<?php echo $form_labels["form"]["discount_info2"]; ?>';
324
- MPv1Ticket.text.discount_info3 = '<?php echo $form_labels["form"]["discount_info3"]; ?>';
325
- MPv1Ticket.text.discount_info4 = '<?php echo $form_labels["form"]["discount_info4"]; ?>';
326
- MPv1Ticket.text.discount_info5 = '<?php echo $form_labels["form"]["discount_info5"]; ?>';
327
- MPv1Ticket.text.discount_info6 = '<?php echo $form_labels["form"]["discount_info6"]; ?>';
328
- MPv1Ticket.text.apply = '<?php echo $form_labels["form"]["apply"]; ?>';
329
- MPv1Ticket.text.remove = '<?php echo $form_labels["form"]["remove"]; ?>';
330
- MPv1Ticket.text.coupon_empty = '<?php echo $form_labels["form"]["coupon_empty"]; ?>';
331
- MPv1Ticket.paths.loading = '<?php echo ( $images_path . "loading.gif" ); ?>';
332
- MPv1Ticket.paths.check = '<?php echo ( $images_path . "check.png" ); ?>';
333
- MPv1Ticket.paths.error = '<?php echo ( $images_path . "error.png" ); ?>';
334
-
335
- MPv1Ticket.getAmount = function() {
336
- return document.querySelector(MPv1Ticket.selectors.amount).value - document.querySelector(MPv1Ticket.selectors.discount).value;
337
- }
338
-
339
- MPv1Ticket.getAmountWithoutDiscount = function() {
340
- return document.querySelector(MPv1Ticket.selectors.amount).value;
341
- }
342
-
343
- MPv1Ticket.Initialize(
344
- mercadopago_site_id,
345
- mercadopago_coupon_mode == 'yes',
346
- mercadopago_discount_action_url);
 
 
 
 
347
 
348
  </script>
1
  <?php
2
+
3
  /**
4
  * Part of Woo Mercado Pago Module
5
  * Author - Mercado Pago
6
  * Developer - Marcelo Tomio Hama / marcelo.hama@mercadolivre.com
7
+ * Copyright - Copyright(c) MercadoPago [https://www.mercadopago.com]
8
+ * License - https://www.gnu.org/licenses/gpl.html GPL version 2 or higher
9
  */
10
+
11
  if ( ! defined( 'ABSPATH' ) ) {
12
  exit;
13
  }
14
+
15
  ?>
16
 
17
+ <div width="100%" style="margin:1px; padding:36px 36px 16px 36px; background:white;">
18
+ <img class="logo" src="<?php echo ($images_path . 'mplogo.png'); ?>" width="156" height="40" />
19
+ <?php if ( count( $payment_methods ) > 1 ) : ?>
20
+ <img class="logo" src="<?php echo ($images_path . 'boleto.png'); ?>"
21
+ width="90" height="40" style="float:right;"/>
22
+ <?php else : ?>
23
+ <?php foreach ( $payment_methods as $payment ) : ?>
24
+ <img class="logo" src="<?php echo $payment['secure_thumbnail']; ?>" width="90" height="40"
25
+ style="float:right;"/>
26
+ <?php endforeach; ?>
27
+ <?php endif; ?>
28
  </div>
29
+
30
+ <fieldset id="mercadopago-form" style="background:white;">
31
+
32
+ <!-- coupom -->
33
+ <div class="mp-box-inputs mp-line form-row" id="mercadopago-form-coupon-ticket" style="margin-bottom: 16px;" >
34
+ <div class="form-col-8">
35
+ <label for="couponCodeLabel"><?php echo $form_labels['form']['coupon_of_discounts']; ?></label>
36
+ <input type="text" id="couponCodeTicket" name="mercadopago_ticket[coupon_code]"
37
+ autocomplete="off" maxlength="24" style="margin-bottom: 8px;"/>
38
+ <span class="mp-discount" id="mpCouponApplyedTicket" ></span>
39
+ <span class="mp-error" id="mpCouponErrorTicket" ></span>
40
+ </div>
41
+ <div class="form-col-4">
42
+ <label >&nbsp;</label>
43
+ <input type="button" class="button" id="applyCouponTicket" value="<?php echo $form_labels['form']['apply']; ?>">
44
+ </div>
45
+ </div>
46
+
47
+ <!-- payment method -->
48
+ <div id="mercadopago-form-ticket" class="mp-box-inputs mp-line">
49
+ <div id="form-ticket">
50
+ <div class="form-row">
51
+ <div class="form-col-4">
52
+ <label for="firstname"><?php echo $form_labels["form"]["name"]; ?><em class="obrigatorio"> *</em></label>
53
+ <input type="text" value="<?php echo $form_labels['febraban']['firstname']; ?>" data-checkout="firstname"
54
+ id="firstname" class="form-control-mine" name="mercadopago_ticket[firstname]">
55
+ <span class="erro_febraban" data-main="#firstname" id="error_firstname"><?php echo $form_labels["error"]["FEB001"]; ?></span>
56
+ </div>
57
+ <div class="form-col-4">
58
+ <label for="lastname"><?php echo $form_labels["form"]["surname"]; ?><em class="obrigatorio"> *</em></label>
59
+ <input type="text" value="<?php echo $form_labels['febraban']['lastname']; ?>" data-checkout="lastname"
60
+ id="lastname" class="form-control-mine" name="mercadopago_ticket[lastname]">
61
+ <span class="erro_febraban" data-main="#lastname" id="error_lastname"><?php echo $form_labels["error"]["FEB002"]; ?></span>
62
+ </div>
63
+ <div class="form-col-4">
64
+ <label for="docNumber"><?php echo $form_labels["form"]["docNumber"]; ?><em class="obrigatorio"> *</em></label>
65
+ <input type="text" value="<?php echo $form_labels['febraban']['docNumber']; ?>" data-checkout="docNumber"
66
+ id="docNumber" class="form-control-mine" name="mercadopago_ticket[docNumber]" maxlength="11">
67
+ <span class="erro_febraban" data-main="#docNumber" id="error_docNumber"><?php echo $form_labels["error"]["FEB003"]; ?></span>
68
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
69
  </div>
70
+ <div class="form-row">
71
+ <div class="form-col-8">
72
+ <label for="address"><?php echo $form_labels["form"]["address"]; ?><em class="obrigatorio"> *</em></label>
73
+ <input type="text" value="<?php echo $form_labels['febraban']['address']; ?>" data-checkout="address"
74
+ id="address" class="form-control-mine" name="mercadopago_ticket[address]">
75
+ <span class="erro_febraban" data-main="#address" id="error_address"><?php echo $form_labels["error"]["FEB004"]; ?></span>
76
+ </div>
77
+ <div class="form-col-4">
78
+ <label for="number"><?php echo $form_labels["form"]["number"]; ?><em class="obrigatorio"> *</em></label>
79
+ <input type="text" value="<?php echo $form_labels['febraban']['number']; ?>" data-checkout="number"
80
+ id="number" class="form-control-mine" name="mercadopago_ticket[number]">
81
+ <span class="erro_febraban" data-main="#number" id="error_number"><?php echo $form_labels["error"]["FEB005"]; ?></span>
82
+ </div>
83
  </div>
84
+ <div class="form-row">
85
+ <div class="form-col-4">
86
+ <label for="city"><?php echo $form_labels["form"]["city"]; ?><em class="obrigatorio"> *</em></label>
87
+ <input type="text" value="<?php echo $form_labels['febraban']['city']; ?>" data-checkout="city"
88
+ id="city" class="form-control-mine" name="mercadopago_ticket[city]">
89
+ <span class="erro_febraban" data-main="#city" id="error_city"><?php echo $form_labels["error"]["FEB006"]; ?></span>
90
+ </div>
91
+ <div class="form-col-4">
92
+ <label for="state"><?php echo $form_labels["form"]["state"]; ?><em class="obrigatorio"> *</em></label>
93
+ <select name="mercadopago_ticket[state]" id="state" data-checkout="state" class="form-control-mine" style="width: 100%;">
94
+ <option value="" <?php if ($form_labels["febraban"]["state"] == "") {echo 'selected="selected"';} ?>><?php echo $form_labels["form"]["label_choose"]; ?></option>
95
+ <option value="AC" <?php if ($form_labels["febraban"]['state'] == "AC") {echo 'selected="selected"';} ?>>Acre</option>
96
+ <option value="AL" <?php if ($form_labels["febraban"]["state"] == "AL") {echo 'selected="selected"';} ?>>Alagoas</option>
97
+ <option value="AP" <?php if ($form_labels["febraban"]["state"] == "AP") {echo 'selected="selected"';} ?>>Amapá</option>
98
+ <option value="AM" <?php if ($form_labels["febraban"]["state"] == "AM") {echo 'selected="selected"';} ?>>Amazonas</option>
99
+ <option value="BA" <?php if ($form_labels["febraban"]["state"] == "BA") {echo 'selected="selected"';} ?>>Bahia</option>
100
+ <option value="CE" <?php if ($form_labels["febraban"]["state"] == "CE") {echo 'selected="selected"';} ?>>Ceará</option>
101
+ <option value="DF" <?php if ($form_labels["febraban"]["state"] == "DF") {echo 'selected="selected"';} ?>>Distrito Federal</option>
102
+ <option value="ES" <?php if ($form_labels["febraban"]["state"] == "ES") {echo 'selected="selected"';} ?>>Espírito Santo</option>
103
+ <option value="GO" <?php if ($form_labels["febraban"]["state"] == "GO") {echo 'selected="selected"';} ?>>Goiás</option>
104
+ <option value="MA" <?php if ($form_labels["febraban"]["state"] == "MA") {echo 'selected="selected"';} ?>>Maranhão</option>
105
+ <option value="MT" <?php if ($form_labels["febraban"]["state"] == "MT") {echo 'selected="selected"';} ?>>Mato Grosso</option>
106
+ <option value="MS" <?php if ($form_labels["febraban"]["state"] == "MS") {echo 'selected="selected"';} ?>>Mato Grosso do Sul</option>
107
+ <option value="MG" <?php if ($form_labels["febraban"]["state"] == "MG") {echo 'selected="selected"';} ?>>Minas Gerais</option>
108
+ <option value="PA" <?php if ($form_labels["febraban"]["state"] == "PA") {echo 'selected="selected"';} ?>>Pará</option>
109
+ <option value="PB" <?php if ($form_labels["febraban"]["state"] == "PB") {echo 'selected="selected"';} ?>>Paraíba</option>
110
+ <option value="PR" <?php if ($form_labels["febraban"]["state"] == "PR") {echo 'selected="selected"';} ?>>Paraná</option>
111
+ <option value="PE" <?php if ($form_labels["febraban"]["state"] == "PE") {echo 'selected="selected"';} ?>>Pernambuco</option>
112
+ <option value="PI" <?php if ($form_labels["febraban"]["state"] == "PI") {echo 'selected="selected"';} ?>>Piauí</option>
113
+ <option value="RJ" <?php if ($form_labels["febraban"]["state"] == "RJ") {echo 'selected="selected"';} ?>>Rio de Janeiro</option>
114
+ <option value="RN" <?php if ($form_labels["febraban"]["state"] == "RN") {echo 'selected="selected"';} ?>>Rio Grande do Norte</option>
115
+ <option value="RS" <?php if ($form_labels["febraban"]["state"] == "RS") {echo 'selected="selected"';} ?>>Rio Grande do Sul</option>
116
+ <option value="RO" <?php if ($form_labels["febraban"]["state"] == "RO") {echo 'selected="selected"';} ?>>Rondônia</option>
117
+ <option value="RA" <?php if ($form_labels["febraban"]["state"] == "RA") {echo 'selected="selected"';} ?>>Roraima</option>
118
+ <option value="SC" <?php if ($form_labels["febraban"]["state"] == "SC") {echo 'selected="selected"';} ?>>Santa Catarina</option>
119
+ <option value="SP" <?php if ($form_labels["febraban"]["state"] == "SP") {echo 'selected="selected"';} ?>>São Paulo</option>
120
+ <option value="SE" <?php if ($form_labels["febraban"]["state"] == "SE") {echo 'selected="selected"';} ?>>Sergipe</option>
121
+ <option value="TO" <?php if ($form_labels["febraban"]["state"] == "TO") {echo 'selected="selected"';} ?>>Tocantins</option>
122
+ </select>
123
+ <span class="erro_febraban" data-main="#state" id="error_state"><?php echo $form_labels["error"]["FEB007"]; ?></span>
124
+ </div>
125
+ <div class="form-col-4">
126
+ <label for="zipcode"><?php echo $form_labels["form"]["zipcode"]; ?><em class="obrigatorio"> *</em></label>
127
+ <input type="text" value="<?php echo $form_labels['febraban']['zipcode']; ?>" data-checkout="zipcode"
128
+ id="zipcode" class="form-control-mine" name="mercadopago_ticket[zipcode]"
129
+ onkeydown="return (event.which >= 48 && event.which <= 57) || event.which == 8 || event.which == 46">
130
+ <span class="erro_febraban" data-main="#zipcode" id="error_zipcode"><?php echo $form_labels["error"]["FEB008"]; ?></span>
131
+ </div>
132
+ </div>
133
+ <div class="form-col-12">
134
+ <label>
135
+ <span class="mensagem-febraban"><em class="obrigatorio">* </em><?php echo $form_labels["form"]["febraban_rules"]; ?></span>
136
+ </label>
137
  </div>
138
  </div>
139
 
140
+ <div style="padding:0px 36px 0px 36px; margin-left: -32px; margin-right: -32px;">
141
+ <p>
142
+ <?php
143
+ if ( count( $payment_methods ) > 1 ) :
144
+ echo $form_labels['form']['issuer_selection'];
145
+ endif;
146
+ echo $form_labels['form']['payment_instructions'];
147
+ ?>&nbsp;<?php
148
+ echo $form_labels['form']['ticket_note'];
149
+ if ( $is_currency_conversion > 0 ) :
150
+ echo " (" . $form_labels['form']['payment_converted'] . " " .
151
+ $woocommerce_currency . " " . $form_labels['form']['to'] . " " .
152
+ $account_currency . ")";
153
+ endif;
154
+ ?>
155
+ </p>
156
+ <?php if ( count( $payment_methods ) > 1 ) : ?>
157
+ <div class="mp-box-inputs mp-col-100" >
158
+ <?php $atFirst = true; ?>
159
+ <?php foreach ( $payment_methods as $payment ) : ?>
160
+ <div class="mp-box-inputs mp-line">
161
+ <div id="paymentMethodId" class="mp-box-inputs mp-col-5">
162
+ <input type="radio" class="input-radio" name="mercadopago_ticket[paymentMethodId]"
163
+ style="display: block; height:16px; width:16px;" value="<?php echo $payment['id']; ?>"
164
+ <?php if ( $atFirst ) : ?> checked="checked" <?php endif; ?> />
165
+ </div>
166
+ <div class="mp-box-inputs mp-col-75">
167
+ <label>
168
+ &nbsp;
169
+ <img src="<?php echo $payment['secure_thumbnail']; ?>"
170
+ alt="<?php echo $payment['name']; ?>" />
171
+ &nbsp;
172
+ <?php echo $payment['name']; ?>
173
+ </label>
174
+ </div>
175
+ </div>
176
+ <?php $atFirst = false; ?>
177
+ <?php endforeach; ?>
178
+ </div>
179
+ <?php else : ?>
180
+ <div class="mp-box-inputs mp-col-100" style="display:none;">
181
+ <select id="paymentMethodId" name="mercadopago_ticket[paymentMethodId]">
182
+ <?php foreach ( $payment_methods as $payment ) : ?>
183
+ <option value="<?php echo $payment['id']; ?>" style="padding: 8px;
184
+ background: url('https://img.mlstatic.com/org-img/MP3/API/logos/bapropagos.gif')
185
+ 98% 50% no-repeat;"> <?php echo $payment['name']; ?>
186
+ </option>
187
+ <?php endforeach; ?>
188
+ </select>
189
+ </div>
190
+ <?php endif; ?>
191
+
192
+ <div class="mp-box-inputs mp-line">
193
+ <div class="mp-box-inputs mp-col-25">
194
+ <div id="mp-box-loading">
195
+ </div>
196
+ </div>
197
+ </div>
198
+
199
+ <!-- utilities -->
200
+ <div class="mp-box-inputs mp-col-100" id="mercadopago-utilities">
201
+ <input type="hidden" id="site_id" value="<?php echo $site_id; ?>" name="mercadopago_ticket[site_id]"/>
202
+ <input type="hidden" id="amountTicket" value="<?php echo $amount; ?>" name="mercadopago_ticket[amount]"/>
203
+ <input type="hidden" id="campaign_idTicket" name="mercadopago_ticket[campaign_id]"/>
204
+ <input type="hidden" id="campaignTicket" name="mercadopago_ticket[campaign]"/>
205
+ <input type="hidden" id="discountTicket" name="mercadopago_ticket[discount]"/>
206
+ </div>
207
 
208
+ </div>
209
  </div>
210
  </fieldset>
211
 
212
  <script type="text/javascript">
 
 
213
 
214
+ ( function() {
215
+
216
+ var MPv1Ticket = {
217
+ site_id: "",
218
+ coupon_of_discounts: {
219
+ discount_action_url: "",
220
+ payer_email: "",
221
  default: true,
222
  status: false
223
+ },
224
+ inputs_to_create_discount: [
 
225
  "couponCodeTicket",
226
  "applyCouponTicket"
227
  ],
228
+ inputs_to_validate_ticket: [
229
+ "firstname",
230
+ "lastname",
231
+ "docNumber",
232
+ "address",
233
+ "number",
234
+ "city",
235
+ "state",
236
+ "zipcode"
237
+ ],
238
+ selectors: {
239
+ // coupom
240
+ couponCode: "#couponCodeTicket",
241
  applyCoupon: "#applyCouponTicket",
242
  mpCouponApplyed: "#mpCouponApplyedTicket",
243
  mpCouponError: "#mpCouponErrorTicket",
 
 
 
244
  campaign_id: "#campaign_idTicket",
245
+ campaign: "#campaignTicket",
246
+ discount: "#discountTicket",
247
+ // payment method and checkout
248
+ paymentMethodId: "#paymentMethodId",
249
+ amount: "#amountTicket",
250
+ // febraban
251
+ firstname: "#febrabanFirstname",
252
+ lastname: "#febrabanLastname",
253
+ docNumber: "#febrabanDocNumber",
254
+ address: "#febrabanAddress",
255
+ number: "#febrabanNumber",
256
+ city: "#febrabanCity",
257
+ state: "#febrabanState",
258
+ zipcode: "#febrabanZipcode",
259
+ // form
260
+ formCoupon: '#mercadopago-form-coupon-ticket',
261
+ formTicket: '#form-ticket',
262
+ box_loading: "#mp-box-loading",
263
+ submit: "#btnSubmit",
264
+ form: "#mercadopago-form-ticket"
265
+ },
266
+ text: {
267
+ discount_info1: "You will save",
268
+ discount_info2: "with discount from",
269
+ discount_info3: "Total of your purchase:",
270
+ discount_info4: "Total of your purchase with discount:",
271
+ discount_info5: "*Uppon payment approval",
272
+ discount_info6: "Terms and Conditions of Use",
273
+ coupon_empty: "Please, inform your coupon code",
274
+ apply: "Apply",
275
+ remove: "Remove"
276
+ },
277
+ paths: {
278
+ loading: "images/loading.gif",
279
+ check: "images/check.png",
280
+ error: "images/error.png"
281
+ }
282
+ }
283
+
284
+ // === Coupon of Discounts
285
+
286
+ MPv1Ticket.currencyIdToCurrency = function ( currency_id ) {
287
+ if ( currency_id == "ARS" ) {
288
+ return "$";
289
+ } else if ( currency_id == "BRL" ) {
290
+ return "R$";
291
+ } else if ( currency_id == "COP" ) {
292
+ return "$";
293
+ } else if ( currency_id == "CLP" ) {
294
+ return "$";
295
+ } else if ( currency_id == "MXN" ) {
296
+ return "$";
297
+ } else if ( currency_id == "VEF" ) {
298
+ return "Bs";
299
+ } else if ( currency_id == "PEN" ) {
300
+ return "S/";
301
+ } else if ( currency_id == "UYU" ) {
302
+ return "$U";
303
+ } else {
304
+ return "$";
305
+ }
306
+ }
307
+
308
+ MPv1Ticket.checkCouponEligibility = function () {
309
+ if ( document.querySelector( MPv1Ticket.selectors.couponCode ).value == "" ) {
310
+ // Coupon code is empty.
311
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display = "none";
312
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display = "block";
313
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).innerHTML = MPv1Ticket.text.coupon_empty;
314
  MPv1Ticket.coupon_of_discounts.status = false;
315
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background = null;
316
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).value = MPv1Ticket.text.apply;
317
+ document.querySelector( MPv1Ticket.selectors.discount ).value = 0;
318
+ // --- No cards handler ---
319
+ } else if ( MPv1Ticket.coupon_of_discounts.status ) {
320
+ // We already have a coupon set, so we remove it.
321
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display = "none";
322
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display = "none";
323
  MPv1Ticket.coupon_of_discounts.status = false;
324
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).style.background = null;
325
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).value = MPv1Ticket.text.apply;
326
+ document.querySelector( MPv1Ticket.selectors.couponCode ).value = "";
327
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background = null;
328
+ document.querySelector( MPv1Ticket.selectors.discount ).value = 0;
329
+ // --- No cards handler ---
330
+ } else {
331
+ // Set loading.
332
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display = "none";
333
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display = "none";
334
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background = "url(" + MPv1Ticket.paths.loading + ") 98% 50% no-repeat #fff";
335
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).disabled = true;
336
+
337
+ // Check if there are params in the url.
338
+ var url = MPv1Ticket.coupon_of_discounts.discount_action_url;
339
+ var sp = "?";
340
+ if ( url.indexOf( "?" ) >= 0 ) {
341
+ sp = "&";
342
+ }
343
+ url += sp + "site_id=" + MPv1Ticket.site_id;
344
+ url += "&coupon_id=" + document.querySelector( MPv1Ticket.selectors.couponCode ).value;
345
+ url += "&amount=" + document.querySelector( MPv1Ticket.selectors.amount ).value;
346
+ url += "&payer=" + MPv1Ticket.coupon_of_discounts.payer_email;
347
+ //url += "&payer=" + document.getElementById( "billing_email" ).value;
348
+
349
+ MPv1Ticket.AJAX({
350
+ url: url,
351
+ method : "GET",
352
+ timeout : 5000,
353
+ error: function() {
354
+ // Request failed.
355
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display = "none";
356
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display = "none";
357
+ MPv1Ticket.coupon_of_discounts.status = false;
358
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).style.background = null;
359
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).value = MPv1Ticket.text.apply;
360
+ document.querySelector( MPv1Ticket.selectors.couponCode ).value = "";
361
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background = null;
362
+ document.querySelector( MPv1Ticket.selectors.discount ).value = 0;
363
+ // --- No cards handler ---
364
+ },
365
+ success : function ( status, response ) {
366
+ if ( response.status == 200 ) {
367
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display =
368
+ "block";
369
+ document.querySelector( MPv1Ticket.selectors.discount ).value =
370
+ response.response.coupon_amount;
371
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).innerHTML =
372
+ //"<div style='border-style: solid; border-width:thin; " +
373
+ //"border-color: #009EE3; padding: 8px 8px 8px 8px; margin-top: 4px;'>" +
374
+ MPv1Ticket.text.discount_info1 + " <strong>" +
375
+ MPv1Ticket.currencyIdToCurrency( response.response.currency_id ) + " " +
376
+ Math.round( response.response.coupon_amount * 100 ) / 100 +
377
+ "</strong> " + MPv1Ticket.text.discount_info2 + " " +
378
+ response.response.name + ".<br>" + MPv1Ticket.text.discount_info3 + " <strong>" +
379
+ MPv1Ticket.currencyIdToCurrency( response.response.currency_id ) + " " +
380
+ Math.round( MPv1Ticket.getAmountWithoutDiscount() * 100 ) / 100 +
381
+ "</strong><br>" + MPv1Ticket.text.discount_info4 + " <strong>" +
382
+ MPv1Ticket.currencyIdToCurrency( response.response.currency_id ) + " " +
383
+ Math.round( MPv1Ticket.getAmount() * 100 ) / 100 + "*</strong><br>" +
384
+ "<i>" + MPv1Ticket.text.discount_info5 + "</i><br>" +
385
+ "<a href='https://api.mercadolibre.com/campaigns/" +
386
+ response.response.id +
387
+ "/terms_and_conditions?format_type=html' target='_blank'>" +
388
+ MPv1Ticket.text.discount_info6 + "</a>";
389
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display =
390
+ "none";
391
+ MPv1Ticket.coupon_of_discounts.status = true;
392
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background =
393
+ null;
394
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background =
395
+ "url(" + MPv1Ticket.paths.check + ") 98% 50% no-repeat #fff";
396
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).value =
397
+ MPv1Ticket.text.remove;
398
+ // --- No cards handler ---
399
+ document.querySelector( MPv1Ticket.selectors.campaign_id ).value =
400
+ response.response.id;
401
+ document.querySelector( MPv1Ticket.selectors.campaign ).value =
402
+ response.response.name;
403
+ } else if ( response.status == 400 || response.status == 404 ) {
404
+ document.querySelector( MPv1Ticket.selectors.mpCouponApplyed ).style.display = "none";
405
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).style.display = "block";
406
+ document.querySelector( MPv1Ticket.selectors.mpCouponError ).innerHTML = response.response.message;
407
  MPv1Ticket.coupon_of_discounts.status = false;
408
+ document.querySelector(MPv1Ticket.selectors.couponCode).style.background = null;
409
+ document.querySelector( MPv1Ticket.selectors.couponCode ).style.background = "url(" + MPv1Ticket.paths.error + ") 98% 50% no-repeat #fff";
410
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).value = MPv1Ticket.text.apply;
411
+ document.querySelector( MPv1Ticket.selectors.discount ).value = 0;
412
+ // --- No cards handler ---
413
+ }
414
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ).disabled = false;
415
+ }
416
+ });
417
+ }
418
+ }
419
+
420
+ // === Initialization function
421
+
422
+ MPv1Ticket.addListenerEvent = function( el, eventName, handler ) {
423
+ if ( el.addEventListener ) {
424
+ el.addEventListener( eventName, handler );
425
+ } else {
426
+ el.attachEvent( "on" + eventName, function() {
427
+ handler.call( el );
428
+ } );
429
+ }
430
+ };
431
+
432
+ /*
433
+ *
434
+ * Utilities
435
+ *
436
+ */
437
+
438
+ MPv1Ticket.referer = (function () {
439
+ var referer = window.location.protocol + "//" +
440
+ window.location.hostname + ( window.location.port ? ":" + window.location.port: "" );
441
+ return referer;
442
+ })();
443
+
444
+ MPv1Ticket.AJAX = function( options ) {
445
+ var useXDomain = !!window.XDomainRequest;
446
+ var req = useXDomain ? new XDomainRequest() : new XMLHttpRequest()
447
+ var data;
448
+ options.url += ( options.url.indexOf( "?" ) >= 0 ? "&" : "?" ) + "referer=" + escape( MPv1Ticket.referer );
449
+ options.requestedMethod = options.method;
450
+ if ( useXDomain && options.method == "PUT" ) {
451
+ options.method = "POST";
452
+ options.url += "&_method=PUT";
453
+ }
454
+ req.open( options.method, options.url, true );
455
+ req.timeout = options.timeout || 1000;
456
+ if ( window.XDomainRequest ) {
457
+ req.onload = function() {
458
+ data = JSON.parse( req.responseText );
459
+ if ( typeof options.success === "function" ) {
460
+ options.success( options.requestedMethod === "POST" ? 201 : 200, data );
461
+ }
462
+ };
463
+ req.onerror = req.ontimeout = function() {
464
+ if ( typeof options.error === "function" ) {
465
+ options.error( 400, {
466
+ user_agent:window.navigator.userAgent, error : "bad_request", cause:[]
467
+ });
468
+ }
469
+ };
470
+ req.onprogress = function() {};
471
+ } else {
472
+ req.setRequestHeader( "Accept", "application/json" );
473
+ if ( options.contentType ) {
474
+ req.setRequestHeader( "Content-Type", options.contentType );
475
+ } else {
476
+ req.setRequestHeader( "Content-Type", "application/json" );
477
+ }
478
+ req.onreadystatechange = function() {
479
+ if ( this.readyState === 4 ) {
480
+ if ( this.status >= 200 && this.status < 400 ) {
481
+ // Success!
482
+ data = JSON.parse( this.responseText );
483
+ if ( typeof options.success === "function" ) {
484
+ options.success( this.status, data );
485
+ }
486
+ } else if ( this.status >= 400 ) {
487
+ data = JSON.parse( this.responseText );
488
+ if ( typeof options.error === "function" ) {
489
+ options.error( this.status, data );
490
+ }
491
+ } else if ( typeof options.error === "function" ) {
492
+ options.error( 503, {} );
493
  }
 
494
  }
495
  };
496
+ }
497
+ if ( options.method === "GET" || options.data == null || options.data == undefined ) {
498
+ req.send();
499
+ } else {
500
+ req.send( JSON.stringify( options.data ) );
501
+ }
502
+ }
503
+
504
+ // Form validation
505
+
506
+ var doSubmitTicket = false;
507
+
508
+ MPv1Ticket.doPay = function(febraban) {
509
+ if(!doSubmitTicket){
510
+ doSubmitTicket=true;
511
+ document.querySelector(MPv1Ticket.selectors.box_loading).style.background = "url("+MPv1Ticket.paths.loading+") 0 50% no-repeat #fff";
512
+ btn = document.querySelector(MPv1Ticket.selectors.form);
513
+ btn.submit();
514
  }
515
  }
516
 
517
+ MPv1Ticket.validateInputsTicket = function(event) {
518
+ event.preventDefault();
519
+ MPv1Ticket.hideErrors();
520
+ var valid_to_ticket = true;
521
+ var $inputs = MPv1Ticket.getForm().querySelectorAll("[data-checkout]");
522
+ var $inputs_to_validate_ticket = MPv1Ticket.inputs_to_validate_ticket;
523
+ var febraban = [];
524
+ var arr = [];
525
+ for (var x = 0; x < $inputs.length; x++) {
526
+ var element = $inputs[x];
527
+ if($inputs_to_validate_ticket.indexOf(element.getAttribute("data-checkout")) > -1){
528
+ if (element.value == -1 || element.value == "") {
529
+ arr.push(element.id);
530
+ valid_to_ticket = false;
531
+ } else {
532
+ febraban[element.id] = element.value;
533
+ }
534
+ }
535
+ }
536
+ if (!valid_to_ticket) {
537
+ MPv1Ticket.showErrors(arr);
 
 
 
 
 
 
538
  } else {
539
+ MPv1Ticket.doPay(febraban);
540
  }
541
+ }
542
 
543
+ MPv1Ticket.getForm = function(){
544
+ return document.querySelector(MPv1Ticket.selectors.form);
545
+ }
546
+
547
+ MPv1Ticket.addListenerEvent = function(el, eventName, handler){
548
+ if (el.addEventListener) {
549
+ el.addEventListener(eventName, handler);
550
+ } else {
551
+ el.attachEvent("on" + eventName, function(){
552
+ handler.call(el);
553
+ });
554
+ }
555
+ };
556
 
557
+ // Show/hide errors.
558
 
559
+ MPv1Ticket.showErrors = function(fields){
560
+ var $form = MPv1Ticket.getForm();
561
+ for(var x = 0; x < fields.length; x++){
562
+ var f = fields[x];
563
+ var $span = $form.querySelector("#error_" + f);
564
+ var $input = $form.querySelector($span.getAttribute("data-main"));
565
+ $span.style.display = "inline-block";
566
+ $input.classList.add("mp-error-input");
567
+ }
568
+ return;
569
+ }
570
+
571
+ MPv1Ticket.hideErrors = function(){
572
+ for(var x = 0; x < document.querySelectorAll("[data-checkout]").length; x++){
573
+ var $field = document.querySelectorAll("[data-checkout]")[x];
574
+ $field.classList.remove("mp-error-input");
575
+ } //end for
576
+ for(var x = 0; x < document.querySelectorAll(".erro_febraban").length; x++){
577
+ var $span = document.querySelectorAll(".erro_febraban")[x];
578
+ $span.style.display = "none";
579
+ }
580
+ return;
581
+ }
582
+
583
+ // ===
584
+
585
+ MPv1Ticket.Initialize = function( site_id, coupon_mode, discount_action_url, payer_email ) {
586
+
587
+ // Sets.
588
+ MPv1Ticket.site_id = site_id;
589
+ MPv1Ticket.coupon_of_discounts.default = coupon_mode;
590
+ MPv1Ticket.coupon_of_discounts.discount_action_url = discount_action_url;
591
+ MPv1Ticket.coupon_of_discounts.payer_email = payer_email;
592
+
593
+ // Flow coupon of discounts.
594
+ if ( MPv1Ticket.coupon_of_discounts.default ) {
595
+ MPv1Ticket.addListenerEvent(
596
+ document.querySelector( MPv1Ticket.selectors.applyCoupon ),
597
+ "click",
598
+ MPv1Ticket.checkCouponEligibility
599
+ );
600
+ } else {
601
+ document.querySelector( MPv1Ticket.selectors.formCoupon ).style.display = "none";
602
+ }
603
+
604
+ // flow: MLB
605
+ if (MPv1Ticket.site_id != "MLB") {
606
+ document.querySelector(MPv1Ticket.selectors.formTicket).style.display = "none";
607
+ } else {
608
+ MPv1Ticket.addListenerEvent(
609
+ document.querySelector(MPv1Ticket.selectors.form),
610
+ "submit",
611
+ MPv1Ticket.validateInputsTicket
612
+ );
613
+ }
614
+
615
+ return;
616
+
617
+ }
618
+
619
+ this.MPv1Ticket = MPv1Ticket;
620
+
621
+ } ).call();
622
 
623
  // === Instantiation
624
 
625
+ var mercadopago_site_id = "<?php echo $site_id; ?>";
626
+ var mercadopago_payer_email = "<?php echo $payer_email; ?>";
627
+ var mercadopago_coupon_mode = "<?php echo $coupon_mode; ?>";
628
+ var mercadopago_discount_action_url = "<?php echo $discount_action_url; ?>";
629
+
630
+ MPv1Ticket.text.discount_info1 = "<?php echo $form_labels['form']['discount_info1']; ?>";
631
+ MPv1Ticket.text.discount_info2 = "<?php echo $form_labels['form']['discount_info2']; ?>";
632
+ MPv1Ticket.text.discount_info3 = "<?php echo $form_labels['form']['discount_info3']; ?>";
633
+ MPv1Ticket.text.discount_info4 = "<?php echo $form_labels['form']['discount_info4']; ?>";
634
+ MPv1Ticket.text.discount_info5 = "<?php echo $form_labels['form']['discount_info5']; ?>";
635
+ MPv1Ticket.text.discount_info6 = "<?php echo $form_labels['form']['discount_info6']; ?>";
636
+ MPv1Ticket.text.apply = "<?php echo $form_labels['form']['apply']; ?>";
637
+ MPv1Ticket.text.remove = "<?php echo $form_labels['form']['remove']; ?>";
638
+ MPv1Ticket.text.coupon_empty = "<?php echo $form_labels['form']['coupon_empty']; ?>";
639
+ MPv1Ticket.paths.loading = "<?php echo ( $images_path . 'loading.gif' ); ?>";
640
+ MPv1Ticket.paths.check = "<?php echo ( $images_path . 'check.png' ); ?>";
641
+ MPv1Ticket.paths.error = "<?php echo ( $images_path . 'error.png' ); ?>";
642
+
643
+ MPv1Ticket.getAmount = function() {
644
+ return document.querySelector( MPv1Ticket.selectors.amount )
645
+ .value - document.querySelector( MPv1Ticket.selectors.discount ).value;
646
+ }
647
+
648
+ MPv1Ticket.getAmountWithoutDiscount = function() {
649
+ return document.querySelector( MPv1Ticket.selectors.amount ).value;
650
+ }
651
+
652
+ MPv1Ticket.Initialize(
653
+ mercadopago_site_id,
654
+ mercadopago_coupon_mode == "yes",
655
+ mercadopago_discount_action_url,
656
+ mercadopago_payer_email
657
+ );
658
 
659
  </script>