Implement stripe in strapi v4 null pay(SOLVED)

Good morning, could someone help me implement stripe with strapi v4, I leave you the code, what I require is that the order be registered with their respective fields, but it tells me null or if you know of a manual to implement stripe in strapi v4, I can tell you I would appreciate it because it is a bit urgent, thank you very much in advance, greetings, I leave screenshots


config in strapi backend controllers/order.js

const { createCoreController } = require("@strapi/strapi").factories;

const stripe = require(“stripe”)( “sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx”);

module.exports = createCoreController(“api::order.order”, ({ strapi }) => ({

async create(ctx) {

const { token, products, idUser, addressShipping } = ctx.request.body;

let totalPayment = 0;

products.forEach((product) => {

  totalPayment = totalPayment + product.attributes.price;

});

// const stripeAmount = Math.floor(totalPayment * 100);

const charge = await stripe.charges.create({

  amount: stripeAmount,

  currency: "usd",

  source: token.id,

  description: `ID usuario: ${idUser}`,

});

const createOrder = [];

for await (const product of products) {

  const datos = {

    data: {

      game: product.id,

      user: idUser,

      totalPayment,

      idPayment: charge.id,

      addressShipping,

    },

  };

  const validData = await strapi.service("api::order.order").create({

    datos,

  });

  const entry = await strapi.query("order").create(validData);

  createOrder.push(entry);

  const sanitizedEntity = await this.sanitizeOutput(createOrder, ctx);

  return this.transformResponse(sanitizedEntity);

}

},

}));
######################################################
in my front end API FUNCTION
######################################################
export async function paymentCardApi(token, products, idUser, address, logout) {

try {

const addressShipping = address;

delete addressShipping.user;

delete addressShipping.createdAT;

const url = `${BASE_PATH}/api/orders`;

const params = {

  method: "POST",

  headers: {

    "Content-Type": "application/json",

  },

  body: JSON.stringify({

    data: { token, products, idUser, addressShipping },

  }),

};

const result = await authFetch(url, params, logout);

return result;

} catch (error) {

console.log(error);

}

}
######################################################
formPay front end get data push in function
######################################################


const response = await paymentCardApi(

    result.token,

    products.attributes,

    auth.idUser,

    addressArray,

    logout

  );

my payload client send apifunction result


I don’t know what else to do, I hope someone can help me since I’m new to the world of backend with stripe, greetings

SOLVED:
I had several errors, the first one was in question of the documentation since I wanted to implement it as if it were v3 when in v4 it is very different. I read the documentation and did several tests at the end, I will leave my pro code if someone works for him and I want to implement it in some project I could
#########################################################################
“use strict”;

/**

  • order controller

*/

#########################################################################
#########################################################################

module.exports = createCoreController(“api::order.order”, ({ strapi }) => ({

async create(ctx, { files } = {}) {

const ctxData = ctx.request.body;

const dataUser = ctx.state.user;

const {

  data: { token, game, user, addressShipping },

} = ctxData;

let Payment = 0;

let gameId = 0;

game.forEach((product) => {

  Payment =

    Payment +

    product.attributes.price -

    Math.floor(product.attributes.price * product.attributes?.discount) /

      100;

  gameId = product.id;

});

// let gametitle = "";

// let gameId2 = 0;

// let gamePrice = 0;

// let gameDiscount = 0;

// gameId2 = products.id;

//   gamePrice = products.attributes.price;

//   gameDiscount = products.attributes.discount;

let gameData2 = game.map(function (products) {

  return `

  Nombre del Producto: ${products.attributes.title},

  Precio normal: ${products.attributes.price},  

  Descuento: %${products.attributes.discount},

  Precio final: ${

    products.attributes.price -

    (products.attributes.price * products.attributes.discount) / 100

  }; `;

});

const totalPayment = Math.floor(Payment * 100);

const idusuario = JSON.stringify(ctxData.data.user);

const charge = await stripe.charges.create({

  amount: totalPayment,

  currency: "usd",

  source: token.id,

  description: `ID usuario: ${idusuario}, Username: ${

    dataUser.username

  }, Nombre Completo: ${" " + dataUser.name + "," + dataUser.lastname},

  Orden:

   ${gameData2}

  Precio Total de la orden: $ ${Payment.toFixed(2)} usd

  `,

});

console.log(charge );

let createOrder = [];

for await (const product of game) {

  const datos = {

    data: {

      game: product.id,

      user: idusuario,

      totalPayment: Payment.toFixed(2),

      idPayment: charge.id,

      adressesShipping: addressShipping,

    },

  };

  const validData = await strapi.service("api::order.order").create(datos);

  createOrder.push(validData);

}

const sanitizedEntity = await this.sanitizeOutput(createOrder, ctx);

// console.log(sanitizedEntity);

return this.transformResponse(sanitizedEntity);

},

}));