Error 500 when I add mercadopago on my site PHP: 500 internal server error

0

I have that problem. When I try to add mercadopago sdk to my site it does not let me, error 500 comes out.

This is the code I have:

            include_once('./mercadopago/lib/mercadopago.php');

            $mp = new MP($id, $secret);

            $preference_data = array(
                "items" => array(
                    array(
                        "title" => $name,
                        "quantity" => 1,
                        "currency_id" => "VEF",
                        "unit_price" => $price
                    )
                )
            );

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

But there is an error in the last line, in which the create_preference () is called. Well when I put that comment line runs the normal site but when it is not in comment shows error 500 and I do not know what it can be :( Please help! Thank you!

    
asked by Jonathan 30.05.2018 в 23:59
source

2 answers

0

In the documentation you can see that in the preference you have to define several values:

        "title" => "Test",       //string
        "quantity" => 1,         //integer
        "currency_id" => "USD",  //string
        "unit_price" => 10.4     //float

in the case of "unit_price" you are defining $price that does not contain a value type float , which is incorrect.

So you can do a casting

"unit_price" => (float) $price

or even to get the floating value of the variable use floatval () :

"unit_price" => floatval($price)
    
answered by 01.06.2018 в 20:22
-1

I already solved! Erra that was missing to force the: $price change it by (float) $price I did that and it was resolved.

    
answered by 01.06.2018 в 04:47