Strapi.js: I have struggle with creating custom controller to user registration

As I can understand for Strapi v4 you cant do that. Intead of you can try patch plugin instance directly

export default (plugin) => {


  plugin.controllers.user.register = async (ctx) => {
    const {
      username,
      email,
      password,
      payment
    } = ctx.request.body;

    // Create the user with the provided username, email, and password
    const user = await strapi.plugins['users-permissions'].services.user.create({
      username,
      email,
      password
    });

    // Create the payment with the provided payment details
    await strapi.service('api::payment.payment')
      .create({
        data: {
          ...payment,
          user: user.id,
        },

      });

    // Add the payment entry to the user
    // await strapi.plugins['users-permissions'].services.user.update({ id: user.id }, { payment: paymentEntry.id});
    var result = sanitizeEntity(user, {
      model: strapi.getModel('plugin::users-permissions.user')
    })
    return result;
  };

  plugin.routes["content-api"].routes.push({
    method: 'POST',
    path: '/auth/local/register',
    handler: 'auth.register',
    config: {
      auth: false,
    },
  });

  return plugin;
};

Thanks for the great comunity Strapi — русскоговорящее сообщество

Cheers!