Mercadopago Checkout Javascript Mobile

1

I have the implementation made for desktop and it works correctly in modal mode

 function openCheckout() {
            $MPC.openCheckout({
                url: "{{mp_preference.response.sandbox_init_point}}",
                mode: "modal",
                onreturn: checkoutReturn
            });
        }

The problem is that in mobile, although it works, instead of opening a modal, it redirects me to the paid market site ... on desktop you close the modal and it executes: onReturn

function checkoutReturn(json) {
            var mp_pago_id = json.collection_id;
            if (json.collection_status == 'approved') {
                notificar('Pago acreditado');
                guardaPaymentId(mp_pago_id);
            } else if (json.collection_status == 'pending') {
                notificar('El usuario no completó el pago');
                guardaPaymentId(mp_pago_id);
            } else if (json.collection_status == 'in_process') {
                notificar('El pago está siendo revisado');
                guardaPaymentId(mp_pago_id);
            } else if (json.collection_status == 'rejected') {
                notificar('El pago fué rechazado, el usuario puede intentar nuevamente el pago');
            } else if (json.collection_status == null) {
                notificar('El usuario no completó el proceso de pago, no se ha generado ningún pago');
            }
        }

In mobile it does not run because it goes away from the screen where it was, I do not know if it's a bug or something else I have to add in mobile to work.

Greetings!

    
asked by GDedieu 18.09.2017 в 21:42
source

1 answer

0

By default, the basic checkout of javascript for mobile redirects to the page of mercadopago for a matter of screen size. A possible solution for this is to configure the preferences of the object, defining a backurl and redirecting it. Code example:

$mp = $this->mpObject();
            $out = array();
            $url_compra = base_url("perfil-pedido/" . $compra->getId());
            foreach ($compra->getRenglones() as $cada_renglon) {
                $array_renglon["title"] = $cada_renglon->getProducto()->getNombre();
                $array_renglon["quantity"] = $cada_renglon->getCantidad();
                $array_renglon["currency_id"] = "ARS";
                $array_renglon["unit_price"] = $cada_renglon->getPrecio();
                $out["items"][] = $array_renglon;
            }
            $out["back_urls"] = array("success" => $url_compra . '?e=' . MP_ESTADO_SUCCESS, "failure" => $url_compra . '?e=' . MP_ESTADO_REJECTED, "pending" => $url_compra . '?e=' . MP_ESTADO_PENDING);
            $out["auto_return"] = "approved";
            $out["merchant_order_id"] = $compra->getId();
    
answered by 20.09.2017 в 19:45