WC_MercadoPago_Gateway

MercadoPago payment method.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-mercadopago-gateway.php  
  1. class WC_MercadoPago_Gateway extends WC_Payment_Gateway { 
  2.  
  3. /** 
  4. * Constructor for the gateway. 
  5. */ 
  6. public function __construct() { 
  7.  
  8. // Standards. 
  9. $this->id = 'mercadopago'; 
  10. $this->icon = apply_filters( 'woocommerce_mercadopago_icon', plugins_url( 'images/mercadopago.png', plugin_dir_path( __FILE__ ) ) ); 
  11. $this->has_fields = false; 
  12. $this->method_title = __( 'MercadoPago', 'woocommerce-mercadopago' ); 
  13.  
  14. // API URLs. 
  15. $this->payment_url = 'https://api.mercadolibre.com/checkout/preferences?access_token='; 
  16. $this->ipn_url = 'https://api.mercadolibre.com/collections/notifications/'; 
  17. $this->sandbox_ipn_url = 'https://api.mercadolibre.com/sandbox/collections/notifications/'; 
  18. $this->oauth_token = 'https://api.mercadolibre.com/oauth/token'; 
  19.  
  20. // Load the form fields. 
  21. $this->init_form_fields(); 
  22.  
  23. // Load the settings. 
  24. $this->init_settings(); 
  25.  
  26. // Define user set variables. 
  27. $this->title = $this->get_option( 'title' ); 
  28. $this->description = $this->get_option( 'description' ); 
  29. $this->client_id = $this->get_option( 'client_id' ); 
  30. $this->client_secret = $this->get_option( 'client_secret' ); 
  31. $this->invoice_prefix = $this->get_option( 'invoice_prefix', 'WC-' ); 
  32. $this->method = $this->get_option( 'method', 'modal' ); 
  33. $this->sandbox = $this->get_option( 'sandbox', 'no' ); 
  34. $this->debug = $this->get_option( 'debug' ); 
  35.  
  36. // Actions. 
  37. add_action( 'woocommerce_api_wc_mercadopago_gateway', array( $this, 'check_ipn_response' ) ); 
  38. add_action( 'valid_mercadopago_ipn_request', array( $this, 'successful_request' ) ); 
  39. add_action( 'woocommerce_receipt_' . $this->id, array( $this, 'receipt_page' ) ); 
  40. add_action( 'wp_head', array( $this, 'css' ) ); 
  41. add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); 
  42.  
  43. // Checks if client_id is not empty. 
  44. if ( empty( $this->client_id ) ) { 
  45. add_action( 'admin_notices', array( $this, 'client_id_missing_message' ) ); 
  46.  
  47. // Checks if client_secret is not empty. 
  48. if ( empty( $this->client_secret ) ) { 
  49. add_action( 'admin_notices', array( $this, 'client_secret_missing_message' ) ); 
  50.  
  51. // Checks that the currency is supported 
  52. if ( ! $this->using_supported_currency() ) { 
  53. add_action( 'admin_notices', array( $this, 'currency_not_supported_message' ) ); 
  54.  
  55. // Active logs. 
  56. if ( 'yes' == $this->debug ) { 
  57. if ( class_exists( 'WC_Logger' ) ) { 
  58. $this->log = new WC_Logger(); 
  59. } else { 
  60. $this->log = WC_MercadoPago::woocommerce_instance()->logger(); 
  61.  
  62. /** 
  63. * Returns a bool that indicates if currency is amongst the supported ones. 
  64. * @return bool 
  65. */ 
  66. protected function using_supported_currency() { 
  67. return in_array( get_woocommerce_currency(), array( 'ARS', 'BRL', 'COP', 'MXN', 'USD', 'VEF' ) ); 
  68.  
  69. /** 
  70. * Returns a value indicating the the Gateway is available or not. It's called 
  71. * automatically by WooCommerce before allowing customers to use the gateway 
  72. * for payment. 
  73. * @return bool 
  74. */ 
  75. public function is_available() { 
  76. // Test if is valid for use. 
  77. $available = ( 'yes' == $this->settings['enabled'] ) && 
  78. ! empty( $this->client_id ) && 
  79. ! empty( $this->client_secret ) && 
  80. $this->using_supported_currency(); 
  81.  
  82. return $available; 
  83.  
  84. /** 
  85. * Initialise Gateway Settings Form Fields. 
  86. */ 
  87. public function init_form_fields() { 
  88.  
  89. $api_secret_locale = sprintf( 
  90. '<a href="https://www.mercadopago.com/mla/herramientas/aplicaciones" target="_blank">%s</a>, <a href="https://www.mercadopago.com/mlb/ferramentas/aplicacoes" target="_blank">%s</a>, <a href="https://www.mercadopago.com/mco/ferramentas/aplicacoes" target="_blank">%s</a>, <a href="https://www.mercadopago.com/mlm/herramientas/aplicaciones" target="_blank">%s</a>, <a href="https://www.mercadopago.com/mlv/herramientas/aplicaciones" target="_blank">%s</a> %s <a href="https://www.mercadopago.com/mlc/herramientas/aplicaciones" target="_blank">%s</a>',  
  91. __( 'Argentine', 'woocommerce-mercadopago' ),  
  92. __( 'Brazil', 'woocommerce-mercadopago' ),  
  93. __( 'Colombia', 'woocommerce-mercadopago' ),  
  94. __( 'Mexico', 'woocommerce-mercadopago' ),  
  95. __( 'Venezuela', 'woocommerce-mercadopago' ),  
  96. __( 'or', 'woocommerce-mercadopago' ),  
  97. __( 'Chile', 'woocommerce-mercadopago' ) 
  98. ); 
  99.  
  100. $this->form_fields = array( 
  101. 'enabled' => array( 
  102. 'title' => __( 'Enable/Disable', 'woocommerce-mercadopago' ),  
  103. 'type' => 'checkbox',  
  104. 'label' => __( 'Enable MercadoPago standard', 'woocommerce-mercadopago' ),  
  105. 'default' => 'yes' 
  106. ),  
  107. 'title' => array( 
  108. 'title' => __( 'Title', 'woocommerce-mercadopago' ),  
  109. 'type' => 'text',  
  110. 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-mercadopago' ),  
  111. 'desc_tip' => true,  
  112. 'default' => __( 'MercadoPago', 'woocommerce-mercadopago' ) 
  113. ),  
  114. 'description' => array( 
  115. 'title' => __( 'Description', 'woocommerce-mercadopago' ),  
  116. 'type' => 'textarea',  
  117. 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-mercadopago' ),  
  118. 'default' => __( 'Pay via MercadoPago', 'woocommerce-mercadopago' ) 
  119. ),  
  120. 'client_id' => array( 
  121. 'title' => __( 'MercadoPago Client_id', 'woocommerce-mercadopago' ),  
  122. 'type' => 'text',  
  123. 'description' => __( 'Please enter your MercadoPago Client_id.', 'woocommerce-mercadopago' ) . ' ' . sprintf( __( 'You can to get this information in MercadoPago from %s.', 'woocommerce-mercadopago' ), $api_secret_locale ),  
  124. 'default' => '' 
  125. ),  
  126. 'client_secret' => array( 
  127. 'title' => __( 'MercadoPago Client_secret', 'woocommerce-mercadopago' ),  
  128. 'type' => 'text',  
  129. 'description' => __( 'Please enter your MercadoPago Client_secret.', 'woocommerce-mercadopago' ) . ' ' . sprintf( __( 'You can to get this information in MercadoPago from %s.', 'woocommerce-mercadopago' ), $api_secret_locale ),  
  130. 'default' => '' 
  131. ),  
  132. 'invoice_prefix' => array( 
  133. 'title' => __( 'Invoice Prefix', 'woocommerce-mercadopago' ),  
  134. 'type' => 'text',  
  135. 'description' => __( 'Please enter a prefix for your invoice numbers. If you use your MercadoPago account for multiple stores ensure this prefix is unqiue as MercadoPago will not allow orders with the same invoice number.', 'woocommerce-mercadopago' ),  
  136. 'desc_tip' => true,  
  137. 'default' => 'WC-' 
  138. ),  
  139. 'method' => array( 
  140. 'title' => __( 'Integration method', 'woocommerce-mercadopago' ),  
  141. 'type' => 'select',  
  142. 'description' => __( 'Choose how the customer will interact with the MercadoPago. Modal Window (Inside your store) Redirect (Client goes to MercadoPago).', 'woocommerce-mercadopago' ),  
  143. 'desc_tip' => true,  
  144. 'default' => 'modal',  
  145. 'options' => array( 
  146. 'modal' => __( 'Modal Window', 'woocommerce-mercadopago' ),  
  147. 'redirect' => __( 'Redirect', 'woocommerce-mercadopago' ),  
  148. ),  
  149. 'testing' => array( 
  150. 'title' => __( 'Gateway Testing', 'woocommerce-mercadopago' ),  
  151. 'type' => 'title',  
  152. 'description' => '',  
  153. ),  
  154. 'sandbox' => array( 
  155. 'title' => __( 'MercadoPago Sandbox', 'woocommerce-mercadopago' ),  
  156. 'type' => 'checkbox',  
  157. 'label' => __( 'Enable MercadoPago sandbox', 'woocommerce-mercadopago' ),  
  158. 'default' => 'no',  
  159. 'description' => __( 'MercadoPago sandbox can be used to test payments.', 'woocommerce-mercadopago' ),  
  160. ),  
  161. 'debug' => array( 
  162. 'title' => __( 'Debug Log', 'woocommerce-mercadopago' ),  
  163. 'type' => 'checkbox',  
  164. 'label' => __( 'Enable logging', 'woocommerce-mercadopago' ),  
  165. 'default' => 'no',  
  166. 'description' => sprintf( __( 'Log MercadoPago events, such as API requests, inside %s', 'woocommerce-mercadopago' ), '<code>woocommerce/logs/' . $this->id . '-' . sanitize_file_name( wp_hash( $this->id ) ) . '.txt</code>' ),  
  167. ); 
  168.  
  169. /** 
  170. * Get order cancel URL. 
  171. * @param WC_Order $order 
  172. * @return string 
  173. */ 
  174. protected function get_order_cancel_url( $order ) { 
  175. if ( method_exists( $order, 'get_cancel_order_url_raw' ) ) { 
  176. return $order->get_cancel_order_url_raw(); 
  177.  
  178. return str_replace( array( '&', '&' ), '&', $order->get_cancel_order_url() ); 
  179.  
  180. /** 
  181. * Generate the payment arguments. 
  182. * @param WC_Order $order Order data. 
  183. * @return array Payment arguments. 
  184. */ 
  185. public function get_payment_args( $order ) { 
  186. $args = array( 
  187. 'back_urls' => array( 
  188. 'success' => $this->get_return_url( $order ),  
  189. 'failure' => $this->get_order_cancel_url( $order ),  
  190. 'pending' => $this->get_return_url( $order ),  
  191. ),  
  192. 'payer' => array( 
  193. 'name' => $order->billing_first_name,  
  194. 'surname' => $order->billing_last_name,  
  195. 'email' => $order->billing_email 
  196. ),  
  197. 'external_reference' => $this->invoice_prefix . $order->id,  
  198. 'items' => array( 
  199. array( 
  200. 'quantity' => 1,  
  201. 'unit_price' => (float) $order->order_total,  
  202. 'currency_id' => get_woocommerce_currency(),  
  203. // 'picture_url' => 'https://www.mercadopago.com/org-img/MP3/home/logomp3.gif' 
  204. ),  
  205. 'notification_url' => str_replace( 'https:', 'http:', WC()->api_request_url( 'WC_MercadoPago_Gateway' ) ),  
  206. ); 
  207.  
  208. // Cart Contents. 
  209. $item_names = array(); 
  210.  
  211. if ( sizeof( $order->get_items() ) > 0 ) { 
  212. foreach ( $order->get_items() as $item ) { 
  213. if ( $item['qty'] ) { 
  214. $item_names[] = $item['name'] . ' x ' . $item['qty']; 
  215.  
  216. $args['items'][0]['title'] = sprintf( __( 'Order %s', 'woocommerce-mercadopago' ), $order->get_order_number() ) . ' - ' . implode( ', ', $item_names ); 
  217.  
  218. // Shipping Cost item. 
  219. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) { 
  220. $shipping_total = $order->get_total_shipping(); 
  221. } else { 
  222. $shipping_total = $order->get_shipping(); 
  223.  
  224. if ( $shipping_total > 0 ) { 
  225. $args['items'][0]['title'] .= ', ' . __( 'Shipping via', 'woocommerce-mercadopago' ) . ' ' . ucwords( $order->shipping_method_title ); 
  226.  
  227. $args = apply_filters( 'woocommerce_mercadopago_args', $args, $order ); 
  228.  
  229. return $args; 
  230.  
  231. /** 
  232. * Generate the MercadoPago payment url. 
  233. * @param object $order Order Object. 
  234. * @return string MercadoPago payment url. 
  235. */ 
  236. protected function get_mercadopago_url( $order ) { 
  237.  
  238. $args = json_encode( $this->get_payment_args( $order ) ); 
  239.  
  240. if ( 'yes' == $this->debug ) { 
  241. $this->log->add( $this->id, 'Payment arguments for order ' . $order->get_order_number() . ': ' . print_r( $this->get_payment_args( $order ), true ) ); 
  242.  
  243. $url = $this->payment_url . $this->get_client_credentials(); 
  244.  
  245. $params = array( 
  246. 'body' => $args,  
  247. 'sslverify' => false,  
  248. 'timeout' => 60,  
  249. 'headers' => array( 
  250. 'Accept' => 'application/json',  
  251. 'Content-Type' => 'application/json;charset=UTF-8' 
  252. ); 
  253.  
  254. $response = wp_remote_post( $url, $params ); 
  255.  
  256. if ( ! is_wp_error( $response ) && $response['response']['code'] == 201 && ( strcmp( $response['response']['message'], 'Created' ) == 0 ) ) { 
  257. $checkout_info = json_decode( $response['body'] ); 
  258.  
  259. if ( 'yes' == $this->debug ) { 
  260. $this->log->add( $this->id, 'Payment link generated with success from MercadoPago' ); 
  261.  
  262. if ( 'yes' == $this->sandbox ) { 
  263. return esc_url( $checkout_info->sandbox_init_point ); 
  264. } else { 
  265. return esc_url( $checkout_info->init_point ); 
  266.  
  267. } else { 
  268. if ( 'yes' == $this->debug ) { 
  269. $this->log->add( $this->id, 'Generate payment error response: ' . print_r( $response, true ) ); 
  270.  
  271. return false; 
  272.  
  273. /** 
  274. * Generate the form. 
  275. * @param int $order_id Order ID. 
  276. * @return string Payment form. 
  277. */ 
  278. public function generate_form( $order_id ) { 
  279.  
  280. $order = new WC_Order( $order_id ); 
  281. $url = $this->get_mercadopago_url( $order ); 
  282.  
  283. if ( $url ) { 
  284.  
  285. // Display checkout. 
  286. $html = '<p>' . __( 'Thank you for your order, please click the button below to pay with MercadoPago.', 'woocommerce-mercadopago' ) . '</p>'; 
  287.  
  288. $html .= '<a id="submit-payment" href="' . esc_url( $url ) . '" name="MP-Checkout" class="button alt" mp-mode="modal">' . __( 'Pay via MercadoPago', 'woocommerce-mercadopago' ) . '</a> <a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">' . __( 'Cancel order & restore cart', 'woocommerce-mercadopago' ) . '</a>'; 
  289.  
  290. // Add MercadoPago JS. 
  291. $html .= '<script type="text/javascript" src="//secure.mlstatic.com/mptools/render.js"></script>'; 
  292. $html .= '<script type="text/javascript">(function() { $MPC.openCheckout({ url: "' . esc_url( $url ) . '", mode: "modal" }); })();</script>'; 
  293.  
  294. return $html; 
  295. } else { 
  296. // Display message if a problem occurs. 
  297. $html = '<p>' . __( 'An error has occurred while processing your payment, please try again. Or contact us for assistance.', 'woocommerce-mercadopago' ) . '</p>'; 
  298.  
  299. $html .= '<a class="button cancel" href="' . esc_url( $order->get_cancel_order_url() ) . '">' . __( 'Click to try again', 'woocommerce-mercadopago' ) . '</a>'; 
  300.  
  301. return $html; 
  302.  
  303. /** 
  304. * Fix MercadoPago CSS. 
  305. * @return string Styles. 
  306. */ 
  307. public function css() { 
  308. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) { 
  309. $page_id = wc_get_page_id( 'checkout' ); 
  310. } else { 
  311. $page_id = woocommerce_get_page_id( 'checkout' ); 
  312.  
  313. if ( is_page( $page_id ) ) { 
  314. echo '<style type="text/css">#MP-Checkout-dialog { z-index: 9999999999 !important; }</style>' . PHP_EOL; 
  315.  
  316. /** 
  317. * Process the payment and return the result. 
  318. * @param int $order_id Order ID. 
  319. * @return array Redirect. 
  320. */ 
  321. public function process_payment( $order_id ) { 
  322.  
  323. $order = new WC_Order( $order_id ); 
  324.  
  325. // Redirect or modal window integration. 
  326. if ( 'redirect' == $this->method ) { 
  327. return array( 
  328. 'result' => 'success',  
  329. 'redirect' => $this->get_mercadopago_url( $order ) 
  330. ); 
  331. } else { 
  332. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) { 
  333. return array( 
  334. 'result' => 'success',  
  335. 'redirect' => $order->get_checkout_payment_url( true ) 
  336. ); 
  337. } else { 
  338. return array( 
  339. 'result' => 'success',  
  340. 'redirect' => add_query_arg( 'order', $order->id, add_query_arg( 'key', $order->order_key, get_permalink( woocommerce_get_page_id( 'pay' ) ) ) ) 
  341. ); 
  342.  
  343. /** 
  344. * Output for the order received page. 
  345. */ 
  346. public function receipt_page( $order ) { 
  347. echo $this->generate_form( $order ); 
  348.  
  349. /** 
  350. * Get cliente token. 
  351. * @return mixed Sucesse return the token and error return null. 
  352. */ 
  353. protected function get_client_credentials() { 
  354. if ( 'yes' == $this->debug ) { 
  355. $this->log->add( $this->id, 'Getting client credentials...' ); 
  356.  
  357. // Set postdata. 
  358. $postdata = 'grant_type=client_credentials'; 
  359. $postdata .= '&client_id=' . $this->client_id; 
  360. $postdata .= '&client_secret=' . $this->client_secret; 
  361.  
  362. // Built wp_remote_post params. 
  363. $params = array( 
  364. 'body' => $postdata,  
  365. 'sslverify' => false,  
  366. 'timeout' => 60,  
  367. 'headers' => array( 
  368. 'Accept' => 'application/json',  
  369. 'Content-Type' => 'application/x-www-form-urlencoded' 
  370. ); 
  371.  
  372. $response = wp_remote_post( $this->oauth_token, $params ); 
  373.  
  374. // Check to see if the request was valid and return the token. 
  375. if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && ( strcmp( $response['response']['message'], 'OK' ) == 0 ) ) { 
  376.  
  377. $token = json_decode( $response['body'] ); 
  378.  
  379. if ( 'yes' == $this->debug ) { 
  380. $this->log->add( $this->id, 'Received valid response from MercadoPago' ); 
  381.  
  382. return $token->access_token; 
  383. } else { 
  384. if ( 'yes' == $this->debug ) { 
  385. $this->log->add( $this->id, 'Received invalid response from MercadoPago. Error response: ' . print_r( $response, true ) ); 
  386.  
  387. return null; 
  388.  
  389. /** 
  390. * Check IPN. 
  391. * @param array $data MercadoPago post data. 
  392. * @return mixed False or posted response. 
  393. */ 
  394. public function check_ipn_request_is_valid( $data ) { 
  395.  
  396. if ( ! isset( $data['id'] ) ) { 
  397. return false; 
  398.  
  399. if ( 'yes' == $this->debug ) { 
  400. $this->log->add( $this->id, 'Checking IPN request...' ); 
  401.  
  402. if ( 'yes' == $this->sandbox ) { 
  403. $ipn_url = $this->sandbox_ipn_url; 
  404. } else { 
  405. $ipn_url = $this->ipn_url; 
  406.  
  407. $url = $ipn_url . $data['id'] . '?access_token=' . $this->get_client_credentials(); 
  408.  
  409. // Send back post vars. 
  410. $params = array( 
  411. 'sslverify' => false,  
  412. 'timeout' => 60,  
  413. 'headers' => array( 
  414. 'Accept' => 'application/json',  
  415. 'Content-Type' => 'application/json;charset=UTF-8' 
  416. ); 
  417.  
  418. // GET a response. 
  419. $response = wp_remote_get( $url, $params ); 
  420.  
  421. if ( 'yes' == $this->debug ) { 
  422. $this->log->add( $this->id, 'IPN Response: ' . print_r( $response, true ) ); 
  423.  
  424. // Check to see if the request was valid. 
  425. if ( ! is_wp_error( $response ) && 200 == $response['response']['code'] ) { 
  426.  
  427. $body = json_decode( $response['body'] ); 
  428.  
  429. if ( 'yes' == $this->debug ) { 
  430. $this->log->add( $this->id, 'Received valid IPN response from MercadoPago' ); 
  431.  
  432. return $body; 
  433. } else { 
  434. if ( 'yes' == $this->debug ) { 
  435. $this->log->add( $this->id, 'Received invalid IPN response from MercadoPago.' ); 
  436.  
  437. return false; 
  438.  
  439. /** 
  440. * Check API Response. 
  441. */ 
  442. public function check_ipn_response() { 
  443. @ob_clean(); 
  444.  
  445. $data = $this->check_ipn_request_is_valid( $_GET ); 
  446.  
  447. if ( $data ) { 
  448. header( 'HTTP/1.1 200 OK' ); 
  449. do_action( 'valid_mercadopago_ipn_request', $data ); 
  450. } else { 
  451. wp_die( __( 'Missing notification params.', 'woocommerce-mercadopago' ), __( 'MercadoPago Notification Handler', 'woocommerce-mercadopago' ), array( 'response' => 200 ) ); 
  452.  
  453. /** 
  454. * Successful Payment! 
  455. * @param array $posted MercadoPago post data. 
  456. */ 
  457. public function successful_request( $posted ) { 
  458.  
  459. $data = $posted->collection; 
  460. $order_key = $data->external_reference; 
  461.  
  462. if ( ! empty( $order_key ) ) { 
  463. $order_id = (int) str_replace( $this->invoice_prefix, '', $order_key ); 
  464.  
  465. $order = new WC_Order( $order_id ); 
  466.  
  467. // Checks whether the invoice number matches the order. 
  468. // If true processes the payment. 
  469. if ( $order->id === $order_id ) { 
  470.  
  471. if ( 'yes' == $this->debug ) { 
  472. $this->log->add( $this->id, 'Payment status from order ' . $order->get_order_number() . ': ' . $data->status ); 
  473.  
  474. switch ( $data->status ) { 
  475. case 'approved': 
  476.  
  477. // Order details. 
  478. if ( ! empty( $data->id ) ) { 
  479. update_post_meta( 
  480. $order_id,  
  481. __( 'MercadoPago Transaction ID', 'woocommerce-mercadopago' ),  
  482. $data->id 
  483. ); 
  484. if ( ! empty( $data->payer->email ) ) { 
  485. update_post_meta( 
  486. $order_id,  
  487. __( 'Payer email', 'woocommerce-mercadopago' ),  
  488. $data->payer->email 
  489. ); 
  490. if ( ! empty( $data->payment_type ) ) { 
  491. update_post_meta( 
  492. $order_id,  
  493. __( 'Payment type', 'woocommerce-mercadopago' ),  
  494. $data->payment_type 
  495. ); 
  496.  
  497. // Payment completed. 
  498. $order->add_order_note( __( 'MercadoPago: Payment approved.', 'woocommerce-mercadopago' ) ); 
  499. $order->payment_complete(); 
  500.  
  501. break; 
  502. case 'pending': 
  503. $order->add_order_note( __( 'MercadoPago: The user has not completed the payment process yet.', 'woocommerce-mercadopago' ) ); 
  504.  
  505. break; 
  506. case 'in_process': 
  507. $order->update_status( 'on-hold', __( 'MercadoPago: Payment under review.', 'woocommerce-mercadopago' ) ); 
  508.  
  509. break; 
  510. case 'rejected': 
  511. $order->add_order_note( __( 'MercadoPago: The payment was declined. The user can try again.', 'woocommerce-mercadopago' ) ); 
  512.  
  513. break; 
  514. case 'refunded': 
  515. $order->update_status( 'refunded', __( 'MercadoPago: The payment was returned to the user.', 'woocommerce-mercadopago' ) ); 
  516.  
  517. break; 
  518. case 'cancelled': 
  519. $order->update_status( 'cancelled', __( 'MercadoPago: Payment canceled.', 'woocommerce-mercadopago' ) ); 
  520.  
  521. break; 
  522. case 'in_mediation': 
  523. $order->add_order_note( __( 'MercadoPago: It started a dispute for payment.', 'woocommerce-mercadopago' ) ); 
  524.  
  525. break; 
  526.  
  527. default: 
  528. // No action xD. 
  529. break; 
  530.  
  531. /** 
  532. * Gets the admin url. 
  533. * @return string 
  534. */ 
  535. protected function admin_url() { 
  536. if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.1', '>=' ) ) { 
  537. return admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_mercadopago_gateway' ); 
  538.  
  539. return admin_url( 'admin.php?page=woocommerce_settings&tab=payment_gateways§ion=WC_MercadoPago_Gateway' ); 
  540.  
  541. /** 
  542. * Adds error message when not configured the client_id. 
  543. * @return string Error Mensage. 
  544. */ 
  545. public function client_id_missing_message() { 
  546. echo '<div class="error"><p><strong>' . __( 'MercadoPago Disabled', 'woocommerce-mercadopago' ) . '</strong>: ' . sprintf( __( 'You should inform your Client_id. %s', 'woocommerce-mercadopago' ), '<a href="' . $this->admin_url() . '">' . __( 'Click here to configure!', 'woocommerce-mercadopago' ) . '</a>' ) . '</p></div>'; 
  547.  
  548. /** 
  549. * Adds error message when not configured the client_secret. 
  550. * @return string Error Mensage. 
  551. */ 
  552. public function client_secret_missing_message() { 
  553. echo '<div class="error"><p><strong>' . __( 'MercadoPago Disabled', 'woocommerce-mercadopago' ) . '</strong>: ' . sprintf( __( 'You should inform your Client_secret. %s', 'woocommerce-mercadopago' ), '<a href="' . $this->admin_url() . '">' . __( 'Click here to configure!', 'woocommerce-mercadopago' ) . '</a>' ) . '</p></div>'; 
  554.  
  555. /** 
  556. * Adds error message when an unsupported currency is used. 
  557. * @return string 
  558. */ 
  559. public function currency_not_supported_message() { 
  560. echo '<div class="error"><p><strong>' . __( 'MercadoPago Disabled', 'woocommerce-mercadopago' ) . '</strong>: ' . sprintf( __( 'Currency <code>%s</code> is not supported. Please make sure that you use one of the following supported currencies: ARS, BRL, COP, MXN, USD or VEF.', 'woocommerce-mercadopago' ), get_woocommerce_currency() ) . '</p></div>';