mercadopago.preferences.create() #189
-
Hi, I'm getting an error when executing my code, it tells me that mercadopago.preferences.create() is not a function. But everything I have seen has worked that way. Could you help me? `const express = require("express"); const mercadopago = require("mercadopago"); new mercadopago.MercadoPagoConfig({ app.use(express.urlencoded({ extended: false })); app.use(express.static(path.join(__dirname, "../client"))); app.get("/", function (req, res) { app.post("/create_preference", (req, res) => { mercadopago.preferences app.get("/feedback", function (req, res) { app.listen(5500, () => { I share the complete code so that you can take a look at it |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi how are you? from const mercadopago = require(“mercadopago”);
new mercadopago.MercadoPagoConfig({
access_token:
“”,
}); to import { MercadoPagoConfig, Preference } from ‘MercadoPago’;
const client = new MercadoPagoConfig({ accessToken: ‘YOUR_AT’ }); and let preference = {
items: [
{
title: req.body.description,
unit_price: Number(req.body.price),
quantity: Number(req.body.quantity),
},
],
back_urls: {
success: “http://localhost:5500”,
failure: “http://localhost:5500”,
pending: “”,
},
auto_return: “approved”,
};
mercadopago.preferences
.create(preference)
.then(function (response) {
res.json({
id: response.body.id,
});
})
.catch(function (error) {
console.log(error);
}); to const body = {
items: [
{
title: req.body.description,
unit_price: Number(req.body.price),
quantity: Number(req.body.quantity)
},
],
back_urls: {
success: “http://localhost:5500”,
failure: “http://localhost:5500”,
pending: “”
},
auto_return: “approved”
};
preference.create({
‘body’: body
}).then((result) => console.log(result))
.catch((error) => console.log(error)); |
Beta Was this translation helpful? Give feedback.
Hi how are you?
It is likely that you have installed version 2 of the SDK and are implementing version 1.
The recommended option is to implement version 2, in your example there would be the following changes:
from
to
and