How to support changes in MercadoPay Notifications with Wordpress [closed]

-6

Like many, I received the notification via email:

  

"Changes in your integration, we suggest that you get in touch with your technical team to evaluate if this change may affect you This migration could be transparent for you, but we need you to do some checks to ensure the proper functioning of your integration. "

When reading between to modify the notifications of payment in my own account of mercadopago (Topics). But when you try to check the checkbox merchant_order , as your information requires it, mark it as mandatory to indicate the URL for notifications.

In my specific case I am using WordPress and the MercadoPago plugin . I understand that when an update comes up, it will contain those changes.

Should I modify the Topics manually ( link ) or the plugin is responsible only for adjusting this change?? And if so, what should I indicate in the input Url para notificación: ?

    
asked by Mariano 22.07.2017 в 00:23
source

1 answer

1

As indicated by the documentation associated with this change: link

The changes correspond to the way in which payments are notified, if in your code the payment ids are being used to validate if a payment is credited then this could cause your site to fail.

Summary

+---------+--------------------------------------------+------------------------+------------------------+
| Intento |                Descripción                 |     Version Actual     |     Nueva Version      |
+---------+--------------------------------------------+------------------------+------------------------+
|       1 | Cliente intenta realizar un                | payment_id: 1223456742 | payment_id: 1239084567 |
|         | pago con su tarjeta de crédito.            | status=rejected        | status=rejected        |
|         | La transacción es rechazada                |                        |                        |
|         | por fondos insuficientes.                  |                        |   

|       2 | Tu cliente vuelve a intentar con Rapipago. | payment_id: 1223456742 | payment_id: 5432123343 |
|         |                                            | status=pending         | status=pending         |

|       2 | Tu cliente va a Rapipago                   | payment_id: 1223456742 | payment_id: 5432123343 |
|         | y completa el pago.                        | status=approved        | status=approved        |
+---------+--------------------------------------------+------------------------+------------------------+

A PHP code snippet to process the IPN would be

<?php
require_once "mercadopago.php";

$mp = new MP("3964826791704277", "TcLhELCaYEFzm522gJxua6tBRf0VbSMd");

if (!isset($_GET["id"], $_GET["topic"]) || !ctype_digit($_GET["id"])) {
    http_response_code(400);
    return;
}

// Get the payment and the corresponding merchant_order reported by the IPN.
if($_GET["topic"] == 'payment'){
    $payment_info = $mp->get("/collections/notifications/" . $_GET["id"]);
    $merchant_order_info = $mp->get("/merchant_orders/" . $payment_info["response"]["collection"]["merchant_order_id"]);
// Get the merchant_order reported by the IPN.
} else if($_GET["topic"] == 'merchant_order'){
    $merchant_order_info = $mp->get("/merchant_orders/" . $_GET["id"]);
}

if ($merchant_order_info["status"] == 200) {
    // If the payment's transaction amount is equal (or bigger) than the merchant_order's amount you can release your items 
    $paid_amount = 0;

    foreach ($merchant_order_info["response"]["payments"] as  $payment) {
        if ($payment['status'] == 'approved'){
            $paid_amount += $payment['transaction_amount'];
        }   
    }

    if($paid_amount >= $merchant_order_info["response"]["total_amount"]){
        if(count($merchant_order_info["response"]["shipments"]) > 0) { // The merchant_order has shipments
            if($merchant_order_info["response"]["shipments"][0]["status"] == "ready_to_ship"){
                print_r("Totally paid. Print the label and release your item.");
            }
        } else { // The merchant_order don't has any shipments
            print_r("Totally paid. Release your item.");
        }
    } else {
        print_r("Not paid yet. Do not release your item.");
    }
}
?>
  

If you use any eCommerce plugin / module / extension supported by   MercadoPago ( link ), the   latest version of each plugin / module / extension available before   September should have support for this change so only   you should do an update.

    
answered by 22.07.2017 в 00:39