How to Set Up a Cron Job for Ratals Recurring Subscriptions

Rob Cuppett Author: Rob Cuppett

If you are using Ratals to sell inventory items with recurring billing, it is important to set up a cron job to process subscriptions automatically. This ensures that recurring charges are handled on time, orders are created, and customers are billed correctly without manual intervention.

It is important to note that PayPal recurring billing is handled internally by PayPal and does not require this cron job. This script is specifically used for payment gateways such as Authorize.net, where users can store cards and manage recurring billing through your Ratals system.

If you have an Authorize.net account and have enabled saved cards and recurring inventory items, this cron job is required to ensure subscriptions are processed correctly.

The cron script checks your subscriptions table and handles billing automatically when a subscription reaches its next billing date. It then updates the next billing cycle, creates an order in both the admin area and customer account, and sends an order confirmation email to the customer.

If tax, VAT, or shipping rules were applied when the subscription was created, those values are stored in the subscription record and reused when the recurring charge is processed to ensure consistency across billing cycles.

If a payment fails, the system will check your subscription_settings table, or the equivalent settings in the admin area under Customers > Subscriptions > Subscription Settings, to determine how many retry attempts should be made before the subscription is marked as failed and potentially canceled.

The script responsible for processing recurring subscriptions is located at:

/admin/commerce/subscriptions/run-subscriptions.php

You will need to create a cron job that runs this file on a schedule.

Example path for your cron job:

/path/to/your/ratals/installation/admin/commerce/subscriptions/run-subscriptions.php

How often you run this cron depends on your business volume. If you have a low number of subscriptions, running it once per day is usually sufficient. However, if you process a higher volume of recurring orders, you may want to run it more frequently such as every hour.

This script checks both the date and time of each subscription, not just the day. This means it will only process subscriptions when the exact billing datetime has been reached or passed.

Once a subscription is processed, the system automatically:

  • Charges the customer (Authorize.net - more gateways coming soon)
  • Updates the next billing date
  • Creates an order in the admin system
  • Creates an order in the customer account
  • Sends an order confirmation email to the customer

This ensures both the customer and the admin have full visibility of recurring transactions and fulfillment requirements.

Setting Up The Cron Job Via Control Panel

  1. Log into your cPanel account.
  2. Find and open Cron Jobs.
  3. Under "Add New Cron Job", choose how often you want it to run.
  4. For low volume subscriptions, set it to run once per day.
  5. For higher volume stores, consider every hour.
  6. In the command field, enter the path to your script:
    /usr/local/bin/php /path/to/your/ratals/installation/admin/commerce/subscriptions/run-subscriptions.php
  7. The PHP path may vary depending on your server configuration. Some servers use /usr/bin/php, while others (such as cPanel-based environments) use /usr/local/bin/php. Always confirm the correct PHP binary path on your server before setting up your cron job.
  8. Save the cron job.

Once added, cPanel will automatically execute the script based on your schedule.

In cPanel, you also have the option to enter an email address for cron job notifications. If enabled, cPanel will send a notification each time the cron job runs.

Additionally, when the subscription script runs, it can output or email details of each processed subscription, including the subscription ID, gateway response and billed amount. This is useful for monitoring recurring billing activity and maintaining an audit trail of all processed charges.

This feature is optional but recommended if you want greater visibility into subscription processing and confirmation that recurring charges are running as expected.

Setting Up The Cron Job Via SSH

If you have SSH access, you can create a cron job directly from the server. This is often more flexible and reliable for larger systems.

  1. Connect to your server via SSH.
  2. Open the cron editor:
    crontab -e
  3. Add a new cron entry. For example, to run every hour:
    0 * * * * /usr/local/bin/php /path/to/your/ratals/installation/admin/commerce/subscriptions/run-subscriptions.php
  4. Save and exit the editor.

Once saved, the system will automatically run the subscription processor based on the schedule you defined.

Just like cPanel, SSH cron jobs depend on the correct PHP path, which may vary between servers. Always confirm whether your system uses /usr/bin/php or /usr/local/bin/php before finalizing your cron command.

Why This Cron Job Is Required

Setting up this cron job is essential if you are using recurring inventory items or subscription-based billing in Ratals with Authorize.net. Without it, subscriptions will not be processed automatically, meaning customers will not be charged and orders will not be created.

By configuring this correctly, you ensure that your system runs in the background, billing customers on time, generating orders, and keeping both admin and customer accounts fully up to date without manual intervention.

Rob Cuppett
About the Author
Rob Cuppett is the founder and lead engineer behind Ratals, bringing over 20 years of experience in digital marketing, software development, and business automation. He shares expert tutorials, practical guides, and insights to help business owners optimize, customize, and fully leverage software solutions to grow their businesses efficiently.
0 Comments
Post a New Comment
This site uses cookies to deliver its services and to analyze traffic. Learn more on our Cookie Policy and Privacy Policy.