buenas tardes, mi cuestión es que al integrar las preferencias de mercado pago todo funciona bien, pero el payer, que seria la información del cliente solo se esta guardando el correo, la información del cliente la estoy trayendo desde un formulario en mi sitio web y los datos llegan correctamente a mi servidor, pero solo se guarda el correo en la información del payer al momento de hacer el pago.
este es mi código en el servidor.
const mercadopago = require("mercadopago");const router = require("express").Router();require('dotenv').config();mercadopago.configure({ access_token: KEY});router.get("/", () => { console.log("hello");});router.post("/", (req, res) => { console.log(req.body.items); const products = []; const infoUser = JSON.parse(req.body.infoUser) const { nombre, correo, telefono, ciudad, barrio, postal, direccion } = req.body const options = {nombre, correo, telefono, ciudad, barrio, postal, direccion} console.log(req.body) JSON.parse(req.body.items).map((el) => { const { description, idProduct, title, quantityProduct, img, price } = el; let nuevoProducto = { description, id: idProduct, // picture_url: `../../../shupycommerce/images/${img}`, title, quantity: parseInt(quantityProduct), currency_id: "COP", unit_price: parseInt(price) / parseInt(quantityProduct), }; products.push(nuevoProducto); }); console.log(products) let preference = { items: products, external_reference: infoUser !== null ? JSON.stringify(infoUser.id) : "null", payer: { // Aqui guardo la informacion del cliente, lo que seria el payer id: infoUser !== null ? JSON.stringify(infoUser.id) : "0", phone: { area_code: "57", number: parseInt(telefono) }, address: { street_name: JSON.stringify(options), street_number: 123, zip_code: `${postal}` }, email: infoUser !== null ? infoUser.email : `${correo}`, identification: { number: "1099377508", type: "C.C" }, first_name: infoUser !== null ? infoUser.name : `${nombre}`, }, back_urls: { success: `${process.env.CORS_URL}/success`, failure: `${process.env.CORS_URL}`, pending: `${process.env.CORS_URL}/success` }, default_payment_method_id: null, default_installments: null }; let payment = { items: products, external_reference: infoUser !== null ? JSON.stringify(infoUser.id) : "null", payer: { id: infoUser !== null ? JSON.stringify(infoUser.id) : "0", phone: { area_code: "57", number: parseInt(telefono) }, address: { street_name: `${ciudad}, ${barrio}, ${direccion}`, street_number: 123, zip_code: `${postal}` }, email: infoUser !== null ? infoUser.email : `${correo}`, identification: { number: "1099377508", type: "C.C" }, first_name: infoUser !== null ? infoUser.name : `${nombre}`, }, } mercadopago.payment.create(payment) .then((response) => { console.log(response.body) }) .catch(error => { console.log(error) }) mercadopago.preferences .create(preference) .then(function (response) { console.log(response.body); res.redirect(response.body.init_point); }) .catch(function (error) { console.log(error); });});module.exports = router;
y todo funciona correctamente, pero no se si el ese objeto payer lo debo poner dentro de la preferencia o no, al hacer el pago y consultarlo con postman. este es el resultado del payer.
payer: { entity_type: null, identification: { number: null, type: null }, phone: { number: null, extension: null, area_code: null }, operator_id: null, last_name: null, id: "241246756", type: null, first_name: null, email: "xd@gmail.com" }