IPN paid market does not notify

Asked

Viewed 346 times

-2

Good night.

I am using the code suggested by the MP to be the basis of my IPN implementation.

I’ve done all the integration tests and

MercadoPago\SDK::setAccessToken("ENV_ACCESS_TOKEN");

$merchant_order = null;

switch($_GET["topic"]) {
    case "payment":
        $payment = MercadoPago\Payment::find_by_id($_GET["id"]);
        // Get the payment and the corresponding merchant_order reported by the IPN.
        $merchant_order = MercadoPago\MerchantOrder::find_by_id($payment->order->id);
        break;
    case "merchant_order":
        $merchant_order = MercadoPago\MerchantOrder::find_by_id($_GET["id"]);
        break;
}

$paid_amount = 0;
foreach ($merchant_order->payments as $payment) {   
    if ($payment['status'] == 'approved'){
        $paid_amount += $payment['transaction_amount'];
    }
}

// If the payment's transaction amount is equal (or bigger) than the merchant_order's amount you can release your items
if($paid_amount >= $merchant_order->total_amount){
    if (count($merchant_order->shipments)>0) { // The merchant_order has shipments
        if($merchant_order->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.");
}

From what I understand the code, in this section below, I can get the status of the payment, only it comes empty with real purchases

$paid_amount = 0;
foreach ($merchant_order->payments as $payment) {   
    $status = $payment['status'];
    if ($payment['status'] == 'approved'){
        $paid_amount += $payment['transaction_amount'];
    }
}

Cole Adm, why did you close my question? That question you pointed out to me, when I looked, there was no answer and the same person answered the same thing...

1 answer

-1

Speak, brother, will you? My system was also returning error 500 on some payments. I’ve tested every snippet of code now and found a solution... What I did was remove the following line:

$merchant_order = MercadoPago\MerchantOrder::find_by_id($_GET["id"]);

after that, it’s working normally.

  • Hey, buddy, great. Thanks for the tip, I’ll test it tomorrow

  • test there, man and give me a feedback... because if it helps you too, it’s bug in the API. I’m still in sandbox mode, but I don’t think it’s going to happen anymore.

  • Anything we do a report there to the MP

  • But next, from what I understand, she’s the one who picks up the payment status, like you did to get it?

  • In mine here, the code line that receives the order status is this: $payment = Mercadopago Payment::find_by_id($_GET["id"]); Then I check the status to be able to update in my database: if ($payment->status == 'Approved'){ print_r("Payment has been approved!") ...

  • I’ll test it then brother... I’ll give you an idea

  • Or, you know ? Ahahah

  • $paid_amount = 0; $status = $payment->status; if ($payment->status == 'Approved'){ $paid_amount += $payment['transaction_amount']; } that in theory would work?

  • Man, this thing don’t work right... sure it’s the right comeback? like... this is the return of the order, I need to get the return in case there is a new payment order

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.