diff --git a/CHANGELOG.md b/CHANGELOG.md index bd3cbd8ad..da567e3c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [5.7.6] - 2022-04-19 + +### Changed Bug fixes +- Adjusted IPN notification to recognize discount coupon +- Added coupon information in order details +- Changed default value of checkout ticket date_expiration + ## [5.7.5] - 2022-03-31 ### Changed Bug fixes diff --git a/changelog.log b/changelog.log index 48009e55c..5fd333682 100644 --- a/changelog.log +++ b/changelog.log @@ -1,6 +1,11 @@ CHANGELOG: == Changelog == -== Changelog == += v5.7.6 (19/04/2022) = +* Bug fixes +- Adjusted IPN notification to recognize discount coupon +- Added coupon information in order details +- Changed default value of checkout ticket date_expiration + = v5.7.5 (31/03/2022) = * Bug fixes - Instance a non-static class to call a method (Fatal error on PHP 8) diff --git a/includes/module/config/class-wc-woomercadopago-constants.php b/includes/module/config/class-wc-woomercadopago-constants.php index 85564eaac..b627d980a 100644 --- a/includes/module/config/class-wc-woomercadopago-constants.php +++ b/includes/module/config/class-wc-woomercadopago-constants.php @@ -21,9 +21,10 @@ class WC_WooMercadoPago_Constants { const PRODUCT_ID_DESKTOP = 'BT7OF5FEOO6G01NJK3QG'; const PRODUCT_ID_MOBILE = 'BT7OFH09QS3001K5A0H0'; const PLATAFORM_ID = 'bo2hnr2ic4p001kbgpt0'; - const VERSION = '5.7.5'; + const VERSION = '5.7.6'; const MIN_PHP = 5.6; const API_MP_BASE_URL = 'https://api.mercadopago.com'; + const DATE_EXPIRATION = 3; const PAYMENT_GATEWAYS = array( 'WC_WooMercadoPago_Basic_Gateway', 'WC_WooMercadoPago_Custom_Gateway', diff --git a/includes/module/preference/class-wc-woomercadopago-preference-ticket.php b/includes/module/preference/class-wc-woomercadopago-preference-ticket.php index f16b95f49..49e7d16b6 100644 --- a/includes/module/preference/class-wc-woomercadopago-preference-ticket.php +++ b/includes/module/preference/class-wc-woomercadopago-preference-ticket.php @@ -30,7 +30,7 @@ public function __construct( $payment, $order, $ticket_checkout ) { $helper = new WC_WooMercadoPago_Composite_Id_Helper(); $id = $ticket_checkout['paymentMethodId']; - $date_expiration = $payment->get_option_mp( 'date_expiration', '' ) . ' days'; + $date_expiration = $payment->get_option( 'date_expiration', WC_WooMercadoPago_Constants::DATE_EXPIRATION ) . ' days'; $this->preference = $this->make_commum_preference(); $this->preference['payment_method_id'] = $helper->getPaymentMethodId($id); $this->preference['date_of_expiration'] = $this->get_date_of_expiration( $date_expiration ); diff --git a/includes/module/sdk/lib/class-mp.php b/includes/module/sdk/lib/class-mp.php index cf19f02f0..b16766dcb 100755 --- a/includes/module/sdk/lib/class-mp.php +++ b/includes/module/sdk/lib/class-mp.php @@ -171,6 +171,20 @@ public function get_access_token() { * @throws WC_WooMercadoPago_Exception Search Payment V1 Exception. */ public function search_payment_v1( $id, $token = null ) { + $key = sprintf( '%s%s', __FUNCTION__, $id ); + + $cache = $this->get_cache_response( $key ); + + if ( ! empty( $cache ) ) { + $this->debug_mode_log( + 'mercadopago_requests', + __FUNCTION__, + __( 'Response from cache', 'woocommerce-mercadopago' ) + ); + + return $cache; + } + $request = array( 'uri' => '/v1/payments/' . $id, 'headers' => array( diff --git a/includes/notification/class-wc-woomercadopago-notification-ipn.php b/includes/notification/class-wc-woomercadopago-notification-ipn.php index 0a9b7ba25..5acc27696 100644 --- a/includes/notification/class-wc-woomercadopago-notification-ipn.php +++ b/includes/notification/class-wc-woomercadopago-notification-ipn.php @@ -91,16 +91,19 @@ public function successful_request( $data ) { public function process_status_mp_business( $data, $order ) { $status = 'pending'; $payments = $data['payments']; - if ( 1 === count( $payments ) ) { - // If we have only one payment, just set status as its status. - $status = $payments[0]['status']; - } elseif ( count( $payments ) > 1 ) { - // However, if we have multiple payments, the overall payment have some rules. + + if ( is_array($payments) ) { + $total = $data['shipping_cost'] + $data['total_amount']; $total_paid = 0.00; $total_refund = 0.00; - $total = $data['shipping_cost'] + $data['total_amount']; // Grab some information... foreach ( $data['payments'] as $payment ) { + $coupon_mp = $this->get_payment_info($payment['id']); + + if ( $coupon_mp > 0 ) { + $total_paid += (float) $coupon_mp; + } + if ( 'approved' === $payment['status'] ) { // Get the total paid amount, considering only approved incomings. $total_paid += (float) $payment['total_paid_amount']; @@ -109,6 +112,7 @@ public function process_status_mp_business( $data, $order ) { $total_refund += (float) $payment['amount_refunded']; } } + if ( $total_paid >= $total ) { $status = 'approved'; } elseif ( $total_refund >= $total ) { @@ -133,12 +137,14 @@ public function process_status_mp_business( $data, $order ) { if ( ! empty( $data['payments'] ) ) { $payment_ids = array(); foreach ( $data['payments'] as $payment ) { + $coupon_mp = $this->get_payment_info($payment['id']); $payment_ids[] = $payment['id']; $order->update_meta_data( 'Mercado Pago - Payment ' . $payment['id'], '[Date ' . gmdate( 'Y-m-d H:i:s', strtotime( $payment['date_created'] ) ) . ']/[Amount ' . $payment['transaction_amount'] . ']/[Paid ' . $payment['total_paid_amount'] . + ']/[Coupon ' . $coupon_mp . ']/[Refund ' . $payment['amount_refunded'] . ']' ); } @@ -162,6 +168,7 @@ public function process_status_mp_business( $data, $order ) { if ( ! empty( $data['payments'] ) ) { $payment_ids = array(); foreach ( $data['payments'] as $payment ) { + $coupon_mp = $this->get_payment_info($payment['id']); $payment_ids[] = $payment['id']; update_post_meta( $order->id, @@ -169,6 +176,7 @@ public function process_status_mp_business( $data, $order ) { '[Date ' . gmdate( 'Y-m-d H:i:s', strtotime( $payment['date_created'] ) ) . ']/[Amount ' . $payment['transaction_amount'] . ']/[Paid ' . $payment['total_paid_amount'] . + ']/[Coupon ' . $coupon_mp . ']/[Refund ' . $payment['amount_refunded'] . ']' ); } @@ -179,4 +187,10 @@ public function process_status_mp_business( $data, $order ) { } return $status; } + public function get_payment_info( $id ) { + $payment_info = $this->mp->search_payment_v1($id); + $coupon_amount = (float) $payment_info['response']['coupon_amount']; + + return $coupon_amount; + } } diff --git a/includes/notification/class-wc-woomercadopago-notification-webhook.php b/includes/notification/class-wc-woomercadopago-notification-webhook.php index 51489a743..502a71434 100644 --- a/includes/notification/class-wc-woomercadopago-notification-webhook.php +++ b/includes/notification/class-wc-woomercadopago-notification-webhook.php @@ -143,9 +143,10 @@ public function check_and_save_customer_card( $checkout_info ) { * @return mixed|string */ public function process_status_mp_business( $data, $order ) { - $status = isset( $data['status'] ) ? $data['status'] : 'pending'; - $total_paid = isset( $data['transaction_details']['total_paid_amount'] ) ? $data['transaction_details']['total_paid_amount'] : 0.00; - $total_refund = isset( $data['transaction_amount_refunded'] ) ? $data['transaction_amount_refunded'] : 0.00; + $status = isset( $data['status'] ) ? $data['status'] : 'pending'; + $total_paid = isset( $data['transaction_details']['total_paid_amount'] ) ? $data['transaction_details']['total_paid_amount'] : 0.00; + $total_refund = isset( $data['transaction_amount_refunded'] ) ? $data['transaction_amount_refunded'] : 0.00; + $coupon_amount = isset( $data['coupon_amount'] ) ? $data['coupon_amount'] : 0.00; // WooCommerce 3.0 or later. if ( method_exists( $order, 'update_meta_data' ) ) { // Updates the type of gateway. @@ -164,6 +165,7 @@ public function process_status_mp_business( $data, $order ) { '[Date ' . gmdate( 'Y-m-d H:i:s', strtotime( $data['date_created'] ) ) . ']/[Amount ' . $data['transaction_amount'] . ']/[Paid ' . $total_paid . + ']/[Coupon ' . $coupon_amount . ']/[Refund ' . $total_refund . ']' ); $order->update_meta_data( '_Mercado_Pago_Payment_IDs', $data['id'] ); @@ -186,6 +188,7 @@ public function process_status_mp_business( $data, $order ) { '[Date ' . gmdate( 'Y-m-d H:i:s', strtotime( $data['date_created'] ) ) . ']/[Amount ' . $data['transaction_amount'] . ']/[Paid ' . $total_paid . + ']/[Coupon ' . $coupon_amount . ']/[Refund ' . $total_refund . ']' ); update_post_meta( $order->id, '_Mercado_Pago_Payment_IDs', $data['id'] ); diff --git a/includes/payments/class-wc-woomercadopago-ticket-gateway.php b/includes/payments/class-wc-woomercadopago-ticket-gateway.php index 4df9d0cd6..e671ec686 100755 --- a/includes/payments/class-wc-woomercadopago-ticket-gateway.php +++ b/includes/payments/class-wc-woomercadopago-ticket-gateway.php @@ -41,7 +41,7 @@ public function __construct() { $this->method_description = $this->description; $this->coupon_mode = $this->get_option( 'coupon_mode', 'no' ); $this->stock_reduce_mode = $this->get_option( 'stock_reduce_mode', 'no' ); - $this->date_expiration = (int) $this->get_option( 'date_expiration', 3 ); + $this->date_expiration = (int) $this->get_option( 'date_expiration', WC_WooMercadoPago_Constants::DATE_EXPIRATION ); $this->type_payments = $this->get_option( 'type_payments', 'no' ); $this->payment_type = 'ticket'; $this->checkout_type = 'custom'; @@ -247,7 +247,7 @@ public function field_date_expiration() { 'title' => __( 'Payment Due', 'woocommerce-mercadopago' ), 'type' => 'number', 'description' => __( 'In how many days will cash payments expire.', 'woocommerce-mercadopago' ), - 'default' => '', + 'default' => WC_WooMercadoPago_Constants::DATE_EXPIRATION, ); } diff --git a/package.json b/package.json index fd1f826a3..51024835a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "pot": "node -e 'require(\"./main.js\").generatePotFiles()'", "lint": "jshint" }, - "version": "5.7.5", + "version": "5.7.6", "repository": { "type": "git", "url": "https://github.com/mercadopago/cart-woocommerce" diff --git a/readme.txt b/readme.txt index b3836ccde..5a16e2a09 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: ecommerce, mercadopago, woocommerce Requires at least: 4.9.10 Tested up to: 5.9 Requires PHP: 5.6 -Stable tag: 5.7.5 +Stable tag: 5.7.6 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -133,6 +133,12 @@ Set up both the plugin and the checkouts you want to activate on your payment av Check out our official documentation for more information on the specific fields to configure. == Changelog == += v5.7.6 (19/04/2022) = +* Bug fixes +- Adjusted IPN notification to recognize discount coupon +- Added coupon information in order details +- Changed default value of checkout ticket date_expiration + = v5.7.5 (31/03/2022) = * Bug fixes - Instance a non-static class to call a method (Fatal error on PHP 8) diff --git a/woocommerce-mercadopago.php b/woocommerce-mercadopago.php index 42a2b46a3..24f0b64a5 100644 --- a/woocommerce-mercadopago.php +++ b/woocommerce-mercadopago.php @@ -3,7 +3,7 @@ * Plugin Name: Mercado Pago payments for WooCommerce * Plugin URI: https://github.com/mercadopago/cart-woocommerce * Description: Configure the payment options and accept payments with cards, ticket and money of Mercado Pago account. - * Version: 5.7.5 + * Version: 5.7.6 * Author: Mercado Pago * Author URI: https://developers.mercadopago.com/ * Text Domain: woocommerce-mercadopago