-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...
Hey, buddy, great. Thanks for the tip, I’ll test it tomorrow
– gabrielfalieri
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.
– Deison R.
Anything we do a report there to the MP
– gabrielfalieri
But next, from what I understand, she’s the one who picks up the payment status, like you did to get it?
– gabrielfalieri
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!") ...
– Deison R.
I’ll test it then brother... I’ll give you an idea
– gabrielfalieri
Or, you know ? Ahahah
– gabrielfalieri
$paid_amount = 0; $status = $payment->status; if ($payment->status == 'Approved'){ $paid_amount += $payment['transaction_amount']; } that in theory would work?
– gabrielfalieri
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
– gabrielfalieri