public function retorno() { if (isset($_REQUEST['id'])) { $id = $_REQUEST['id']; $client_id = $this->config->get('mercadopago2_client_id'); $client_secret = $this->config->get('mercadopago2_client_secret'); $checkdata = new Shop($client_id, $client_secret); $dados = $checkdata->GetStatus($id); $order_id = $dados['collection']['external_reference']; $order_status = $dados['collection']['status']; $this->load->model('checkout/order'); $order = $this->model_checkout_order->getOrder($order_id); if ($order['order_status_id'] == '0') { $this->model_checkout_order->confirm($order_id, $this->config->get('mercadopago_order_status_id')); } switch ($order_status) { case 'approved': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_completed')); break; case 'pending': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_pending')); break; case 'in_process': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_process')); break; case 'reject': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_rejected')); break; case 'refunded': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_refunded')); break; case 'cancelled': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_cancelled')); break; case 'in_metiation': $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_in_mediation')); break; default: $this->model_checkout_order->update($order_id, $this->config->get('mercadopago2_order_status_id_pending')); } } }
function mp_retorno() { if (isset($_REQUEST['id']) && isset($_REQUEST['topic'])) { $id = $_REQUEST['id']; $client_id = get_option('mercadopago_client_id'); $client_secret = get_option('mercadopago_client_secret'); $checkdata = new Shop($client_id, $client_secret); $dados = $checkdata->GetStatus($id); $order_id = $dados['collection']['external_reference']; $order_status = $dados['collection']['status']; $mp_id = $dados['collection']['order_id']; switch ($order_status) { case 'approved': $purchase_log_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET transactid = " . $mp_id . ", processed = 3, notes = 'Payment Approved by MercadoPago' WHERE `sessionid`= '" . $order_id . "' LIMIT 1"; break; case 'pending': case 'in_process': $purchase_log_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET transactid = " . $mp_id . ", processed = 2, notes = 'Order received, wait for payment confirmation' WHERE `sessionid`= '" . $order_id . "' LIMIT 1"; break; case 'reject': $purchase_log_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET transactid = " . $mp_id . ", processed = 6, notes = 'Payment declined by MercadoPago, contact the client and ask to do a new order' WHERE `sessionid`= '" . $order_id . "' LIMIT 1"; break; case 'refunded': $purchase_log_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET transactid = " . $mp_id . ", processed = 6, notes = 'Payment refunded by MercadoPago' WHERE `sessionid`= '" . $order_id . "' LIMIT 1"; break; case 'cancelled': $purchase_log_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET transactid = " . $mp_id . ", processed = 6, notes = 'Payment canceled by MercadoPago' WHERE `sessionid`= '" . $order_id . "' LIMIT 1"; break; case 'in_metiation': $purchase_log_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET transactid = " . $mp_id . ", processed = 6, notes = 'This orders has a mediation in MercadoPago' WHERE `sessionid`= '" . $order_id . "' LIMIT 1"; break; default: $purchase_log_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET transactid = " . $mp_id . ", processed = 2, notes = 'Order received, wait for payment confirmation' WHERE `sessionid`= '" . $order_id . "' LIMIT 1"; } $purchase_log = $wpdb->get_results($purchase_log_sql, ARRAY_A); } }