Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
Strapi how to extra api in controller

I have completed a shopping cart and can pay to stripe, but I want to be able to know who bought it, so I want to add a feature that allows me to see the user in the strapi backend

I hope to know how to combine those that two functions.

I have tried their functions separately I will work for the different page

../controllers/order.js

const stripe = require('stripe')('xxxvxx');
const { parseMultipartData, sanitizeEntity } = require('strapi-utils');
    module.exports = {
      create: async ctx => {
        const {
          address,
          amount,
          product,
          token,
    
        } = ctx.request.body;
        
        
        // Charge the customer
        try {    
    
             // stripe charge
             
             await stripe.customers
              .create({
                email: ctx.state.user.email,
                source: token
              })
              .then((customer) => {
                return stripe.charges.create({
                    // Transform cents to dollars.
                    amount: amount * 100,
                    currency: 'usd',
                    description: `Order ${new Date()} by ${ctx.state.user.id}`,
                    customer: customer.id
            
                  });
              });
        
          
    
          // Register the order in the database
          try {
            const order = await strapi.services.order.create({
              user: ctx.state.user.id,
              address,
              amount,
              product,
            });
            
            
            //email
            
             if (order.id){
              
              await strapi.plugins['email'].services.email.send({
                to: ctx.state.user.email,
                subject: 'Thank you for your purchase',
                text: `
               
                    usd${order.amount} is charged from your credit card on Stripe.
                    usd${order.address} is charged from your credit card on Stripe.
    
                  
                `,
              });
              
              
             }
            
    
            return order;
          } catch (err) {
            console.log(err)
          }
        } catch (err) {
            console.log(err)
    
        }
        
      }
      
    };

Want to combine it

    async create(ctx) {
        let entity;
        if (ctx.is('multipart')) {
          const { data, files } = parseMultipartData(ctx);
          data.users_permissions_user = ctx.state.user.id;
          entity = await strapi.services.about.create(data, { files });
        } else {
          ctx.request.body.users_permissions_user = ctx.state.user.id;
          entity = await strapi.services.about.create(ctx.request.body);
        } 
    return sanitizeEntity(entity, { model: strapi.models.about });
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

In the new strapi

user => users_permissions_user

the answer is // Register the order in the database

user: ctx.state.user.id,

try

users_permissions_user: ctx.state.user.id,
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda