0

I have this piece of code:

<?php
require_once ('mercadopago.php');

$monto = $_POST['amount'];

$mp = new MP('XXXX', 'XXXXXXXXXXX');

$preference_data = array(
    "items" => array(
       array(
           "title" => "item",
           "quantity" => 1,
           "currency_id" => "usd",
           "unit_price" => HERE
       )
    )
);

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

?>

and I need to make the variable $monto that i define from a post send before to give its value to "Unit_price" where it says "HERE". I tried just writting $monto, but it didnt work.

there is some how i can do this? thanks u and sorry for my english. its not pretty good.

1
  • "unit_price" => $monto Why you asking again the same question? Commented Jun 11, 2014 at 7:15

2 Answers 2

2

you can just use the variable, like:

//check if your POST data is not empty and assign some default value in case its empty
$monto = (!empty($_POST['amount'])) ? $_POST['amount'] : 0; //0 is default value
$preference_data = array(
    "items" => array(
       array(
           "title" => "item",
           "quantity" => 1,
           "currency_id" => "usd",
           "unit_price" => $monto
       )
    )
);
Sign up to request clarification or add additional context in comments.

2 Comments

the post data is not empty, and writte just $monto it doesnt work. maybe its because im using smarty templates?
@user3128221 what do you see when you var_dump($preference_data); ..? and pls clarify your question, as you dont seem to mention anything regarding smarty in your question...!
0
<?php
$preference_data = array(
    "items" => array(
        array(
            "title" => "RosquinhaPvP - NickDoPlayer - VIP",
            "quantity" => 1,
            "currency_id" => "BRL",
            "unit_price" => doubleval($monto)
        )
    )
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.