Mercadopago with React Native. How to implement it?

495 views Asked by At

I really dont understand why I am trying to reproduce the example of: https://github.com/BlackBoxVision/react-native-mercadopago-px

and doesnt work.... For example, the code below in the console.log gives "undefined"

const getPreferenceId = async (payer, ...items) => {
        const response = await fetch(
            `https://api.mercadopago.com/checkout/preferences?access_token=TESTIDTESTIDTESTID`,
            {
              method: 'POST',
              body: JSON.stringify({
                items,
                payer: {
                  email: payer,
                },
              }),
            }
        );
    
      const preference = await response.json();
      
      console.log(preference)

      return preference.id;
    };

getPreferenceId([email protected],[{
                  title: 'Dummy Item Title',
                  description: 'Dummy Item Description',
                  quantity: 1,
                  currency_id: 'ARS',
                  unit_price: 10.0,
                }])
1

There are 1 answers

0
Rômulo Bourget Novas On

The e-mail your using to call your function is not a string and is being dealt as a variable with undefined value. ...

Try this..

getPreferenceId("[email protected]",[{
                  title: 'Dummy Item Title',
                  description: 'Dummy Item Description',
                  quantity: 1,
                  currency_id: 'ARS',
                  unit_price: 10.0,
                }])