estoy integrando mercadoPago en php, cuando intento recibir las notificaciones ipn no puedo acceder a la external_ref, esta la requiero utilizarla en un metodo el problema es que estoy siguiendo la documentación oficial pero no esta funcionando, este es mi código cuando hago el pago:
require __DIR__ . '/vendor/autoload.php'; MercadoPago\SDK::setAccessToken(access_token); $preference = new MercadoPago\Preference(); $item = new MercadoPago\Item(); $item->id = "0000"; $item->title = "Producto"; $item->quantity = 1; $item->unit_price = 20; $preference->items = array($item); $preference->external_reference = $token_preventa; $preference->back_urls = ['success' => 'https://www.google.com', 'pending' => "https://www.google.com", "failure" => "https://www.google.com"]; $preference->notification_url = notification_url; $preference->save(); $url = $preference->init_point;
Y este es mi código cuando recibo la notificacion IPN
<?phpheader('Content-Type: application/json');echo json_encode(['HTTP/1.1 200 OK'], 200);require __DIR__ . '/vendor/autoload.php';include_once("./config.php");include_once("./dal.php");MercadoPago\SDK::setAccessToken(access_token);$merchant_order = null;switch ($_GET["topic"]) { case "payment": $payment = MercadoPago\Payment::find_by_id($_GET["id"]); $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 itemsif ($paid_amount >= $merchant_order->total_amount) { if (count($merchant_order->shipments) > 0) { if ($merchant_order->shipments[0]->status == "ready_to_ship") { $s="insert into tbl(notificacion) values ('ready_to_ship');"; $a_cosa= create($s); } } else {// print_r("Totally paid. Release your item."); $external_ref = $payment->external_reference; change_stauts_payment($external_ref); $s="insert into tbl(notificacion) values ('Se pagó| $external_ref1| ".$_GET["id"]." ');"; $a_cosa= create($s); }} else { $s="insert into tbl(notificacion) values ('no se pagó');"; $a_cosa= create($s);}?>
Utilizo las senetencias sql para saber que si esta llegando la notificacón de mercadoPago, si funcionan ya que me inserta datos. pero el id lo tiene vacío.Mi accessToken esta definido como una constante en otro archivo php.¿Como puedo saber el id de la notificación o por que no me están mandando nada con el id?