Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

275
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!