Skip to content

Commit

Permalink
Merge pull request #416 from PluginAndPartners/release/5.7.6
Browse files Browse the repository at this point in the history
Release/5.7.6
  • Loading branch information
katelucena-meli authored Apr 20, 2022
2 parents b206f46 + 1976b20 commit 1511dc5
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion changelog.log
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 2 additions & 1 deletion includes/module/config/class-wc-woomercadopago-constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
14 changes: 14 additions & 0 deletions includes/module/sdk/lib/class-mp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 20 additions & 6 deletions includes/notification/class-wc-woomercadopago-notification-ipn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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 ) {
Expand All @@ -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'] . ']'
);
}
Expand All @@ -162,13 +168,15 @@ 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,
'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'] . ']'
);
}
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'] );
Expand All @@ -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'] );
Expand Down
4 changes: 2 additions & 2 deletions includes/payments/class-wc-woomercadopago-ticket-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -133,6 +133,12 @@ Set up both the plugin and the checkouts you want to activate on your payment av
Check out our <a href="https://www.mercadopago.com.br/developers/pt/plugins_sdks/plugins/official/woo-commerce/">official documentation</a> 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)
Expand Down
2 changes: 1 addition & 1 deletion woocommerce-mercadopago.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1511dc5

Please sign in to comment.