Jump to content

using module commands


Recommended Posts

hello,

I have a product lets say it is 3 day free trial.  i want to create a hook that runs module command renew xxx times.  so i make the trial 6,9,12 day trials.  my module only allows 3 days that is why i want to create a hook that renews on module create.  just can't figure out how to get renew to work.

Link to comment
Share on other sites

<?php

use WHMCS\Database\Capsule;

add_hook('AfterModuleCreate', 1, function($vars) {
    // Get the service ID and product ID
    $serviceId = $vars['serviceid'];
    $productId = $vars['pid'];

    // Check if the product matches the target product ID (e.g., 3-day free trial product)
    $targetProductId = 123; // Replace with your trial product's ID

    if ($productId == $targetProductId) {
        // Define how many renew cycles you want (e.g., 2 renews = 3 + 3 + 3 days = 9 days total)
        $renewCycles = 2;

        for ($i = 0; $i < $renewCycles; $i++) {
            try {
                // Trigger the ModuleRenew command
                localAPI('ModuleRenew', [
                    'serviceid' => $serviceId,
                ]);
                logActivity("Renewal successful for Service ID: {$serviceId} (Cycle: " . ($i + 1) . ").");
            } catch (Exception $e) {
                logActivity("Renewal failed for Service ID: {$serviceId} (Cycle: " . ($i + 1) . "): " . $e->getMessage());
            }
        }
    }
});

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated