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