Mercado Pago, back_urls format

1

How about, thanks for your time, I'm trying to integrate a very basic shopping cart with MercadoPago. But I receive the following error:

Fatal error: Uncaught exception 'MercadoPagoException' with message 'back_urls invalid. Wrong format'

I am using the library for PHP with the following code

$mp = new MP('xxxxxxxx','xxxxxxxxxxx'); 
            $mp->sandbox_mode(true);


            $preference_data = array(
                "items" => array(
                    array(
                        "title" => "Multicolor kite",
                        "description" => "Multicolor kite - prueba",
                        "quantity" => 1,
                        "currency_id" => "ARS", 
                        "unit_price" => 1.00
                    )
                ),
                "payer" => array(
                    array(
                        "name" => "Pepe Argento",
                        "email" => "[email protected]"
                    )
                ),
                "external_reference" => "230688",
                "auto_return" => "approved",
                "back_urls" => array(
                    array(
                        "success" => "http://cualquierpagina.com"
                    )
                )
            );

            $preference = $mp->create_preference($preference_data);

            echo $preference['response']['sandbox_init_point'];

then I take the string that returns in $ preference ['response'] ['sandbox_init_point']; and I put it on a button.

If I remove the back_url and the auto_return, it sends it perfect, it takes the data and it seems to work all right. But if you do not send me the error mentioned above, in my opinion it should be something of format, but no matter how you put the page, it continues to bounce.

What is wrong? Could someone give me a hand with the subject?

Somewhere I read that the sandbox did not work, and that everything had to be done in real mode with test users, the truth is that I read the documentation of how to make a test user and I did not understand where or how.

Thank you for your time and attention.

    
asked by OTANO 05.10.2017 в 01:14
source

1 answer

0

An array is left over, instead of this:

"back_urls" => array(
    array(
        "success" => "http://cualquierpagina.com"
    )
)

It should be:

"back_urls" => array(
    "success" => "http://cualquierpagina.com"
)

It is true that the sandbox no longer works and now we have to handle test users. I pass the code to create them, so you do not suffer what I suffered xD:

    $mp = new MP($client_id, $client_secret);
    $access_token = $mp->get_access_token();

    // Argentina: id "MLA".
    $data = array('site_id' => 'MLA');

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_URL,"https://api.mercadolibre.com/users/test_user?access_token=$access_token");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

    // Respuesta en formato json
    $response = curl_exec($ch);

    $user = json_decode($response, true);

You'll have to create two and use one as a buyer and another as a seller. Then login to MercadoPago with the email and password of the selling user and obtain the values client_id and client_secret in order to connect to the api and execute the transactions.

In the answer, the user data will appear something like:

array(
    'id'          => '123456789',
    'nickname'    => 'XXXXXXXXX',
    'password'    => 'XXXXXXXXX',
    'site_status' => 'active',
    'email'       => 'XXXXXXXXX'
)

Several months ago I used this code and I suppose it will still work, although with MercadoPago you never know ... ^ _ ^

    
answered by 05.10.2017 / 04:07
source