Skip to main content

Welcome Emails for (Clients)

Comments

6 comments

  • cPRex Jurassic Moderator

    Hey there!  I'm not familiar with Paymenter at all, but you'll want to check two things:

    -is the email being generated by the tool
    and
    -if so, does the email show up in the Exim log in /var/log/exim_mainlog

    One of those questions should point you in the right direction.

    0
  • Outraged Hosting

    so this is my plugin code not sure if this would help but it shows how I have the setup

    <?php

    namespace App\Extensions\Servers\CPanel;

    use App\Classes\Extensions\Server;
    use App\Helpers\ExtensionHelper;
    use Illuminate\Support\Facades\Http;
    use Illuminate\Support\Str;

    class CPanel extends Server
    {
        /**
         * Get the extension metadata
         * 
         * @return array
         */
        public function getMetadata()
        {
            return [
                'display_name' => 'CPanel',
                'version' => '1.0.0',
                'author' => 'Paymenter',
                'website' => 'https://paymenter.org',
            ];
        }

        private function request($method, $endpoint, $data = [])
        {
            $host = rtrim(ExtensionHelper::getConfig('CPanel', 'host'), '/');
            $username = ExtensionHelper::getConfig('CPanel', 'username');
            $apikey = ExtensionHelper::getConfig('CPanel', 'apikey');

            // Make the API request
            $response = Http::withHeaders([ 
                'Authorization' => 'whm ' . $username . ':' . $apikey,
            ])->$method($host . '/json-api' . $endpoint, $data);

            // Debugging: Log details
            if ($response->failed()) {
                error_log('WHM API Error: ' . $response->body());
                error_log('Response Status: ' . $response->status());

                // Check if response contains meaningful error
                $errorDetails = json_decode($response->body(), true);
                if(isset($errorDetails['cpanelresult']['data']['reason'])) {
                    $errorReason = $errorDetails['cpanelresult']['data']['reason'];
                    throw new \Exception('Error while requesting API: ' . $errorReason);
                }

                throw new \Exception('Error while requesting API');
            }

            return $response;
        }

        /**
         * Get all the configuration for the extension
         * 
         * @return array
         */
        public function getConfig()
        {
            return [
                [
                    'name' => 'host',
                    'type' => 'text',
                    'friendlyName' => 'Hostname',
                    'validation' => 'url:http,https',
                    'required' => true,
                ],
                [
                    'name' => 'username',
                    'type' => 'text',
                    'friendlyName' => 'Username',
                    'required' => true,
                ],
                [
                    'name' => 'apikey',
                    'type' => 'text',
                    'friendlyName' => 'API key',
                    'required' => true,
                ],
            ];
        }

        /**
         * Get product config
         * 
         * @param array $options
         * @return array
         */
        public function getProductConfig($options)
        {
            // Get all the packages
            $response = $this->request('get', '/listpkgs');
            $packages = $response->json();
            $packageOptions = [];
            foreach ($packages['package'] as $package) {
                $packageOptions[] = [
                    'value' => $package['name'],
                    'name' => $package['name'],
                ];
            }

            return [
                [
                    'name' => 'package',
                    'type' => 'dropdown',
                    'friendlyName' => 'Package',
                    'options' => $packageOptions,
                    'required' => true,
                ],
            ];
        }

        /**
         * Get configurable options for users
         *
         * @param array $options
         * @return array
         */
        public function getUserConfig()
        {
            return [
                [
                    'name' => 'domain',
                    'type' => 'text',
                    'validation' => 'domain',
                    'friendlyName' => 'Domain',
                    'required' => true,
                ]
            ];
        }

        /**
         * Create a server
         * 
         * @param User $user
         * @param array $params
         * @param Order $order
         * @param OrderProduct $orderProduct
         * @param array $configurableOptions
         * @return bool
         */
        public function createServer($user, $params, $order, $orderProduct, $configurableOptions)
        {
            // Prefix 'outback_' and generate random string
            $prefix = 'outback_';  // Updated prefix with an underscore
            $randomString = Str::random(4); // Generate a random 4-character string
            $username = $prefix . $randomString; // Combine the prefix and random string

            // If the first character is a number, add a letter
            if (is_numeric($username[0])) {
                $username = 'a' . substr($username, 1);
            }

            // Make the API request to create account and send welcome email
            $this->request(
                'get',
                '/createacct',
                [
                    'api.version' => 2,  // Updated API version to 2
                    'username' => $username,
                    'contactemail' => $user->email,
                    'domain' => $params['config']['domain'],
                    'plan' => $params['package'],
                    'sendwelcome' => 1,  // Ensure the welcome email is sent
                ]
            );

            // Store the username for later reference
            ExtensionHelper::setOrderProductConfig('username', strtolower($username), $orderProduct->id);

            return true;
        }

        /**
         * Suspend a server
         * 
         * @param User $user
         * @param array $params
         * @param Order $order
         * @param OrderProduct $orderProduct
         * @param array $configurableOptions
         * @return bool
         */
        public function suspendServer($user, $params, $order, $orderProduct, $configurableOptions)
        {
            $this->request(
                'get',
                '/suspendacct',
                [
                    'api.version' => 2,  // Updated API version to 2
                    'user' => $params['config']['username'],
                ]
            );

            return true;
        }

        /**
         * Unsuspend a server
         * 
         * @param User $user
         * @param array $params
         * @param Order $order
         * @param OrderProduct $orderProduct
         * @param array $configurableOptions
         * @return bool
         */
        public function unsuspendServer($user, $params, $order, $orderProduct, $configurableOptions)
        {
            $this->request(
                'get',
                '/unsuspendacct',
                [
                    'api.version' => 2,  // Updated API version to 2
                    'user' => $params['config']['username'],
                ]
            );

            return true;
        }

        /**
         * Terminate a server
         * 
         * @param User $user
         * @param array $params
         * @param Order $order
         * @param OrderProduct $orderProduct
         * @param array $configurableOptions
         * @return bool
         */
        public function terminateServer($user, $params, $order, $orderProduct, $configurableOptions)
        {
            $this->request(
                'get',
                '/removeacct',
                [
                    'api.version' => 2,  // Updated API version to 2
                    'user' => $params['config']['username'],
                ]
            );

            return true;
        }
    }

     
       

    0
  • cPRex Jurassic Moderator

    No, code never really helps me as I'm not a developer.  Can you confirm the message is being generated at all and sent to Exim?

    0
  • Outraged Hosting

    so it sends it to exim but sends it to the contact email in WHM not to the clients email adress honestly but I am going to test a work around today and update you if I got it fixed or not! :)

    0
  • cPRex Jurassic Moderator

    Sounds good!

    0
  • Outraged Hosting

    Ended up just switching to WHMCS everything just works

    0

Please sign in to leave a comment.