Repository navigation
UrlSolutions WHMCS Module — Bugfix Notes
Overview
This document describes three bugs found and fixed in the UrlSolutions/Pananames registrar module for WHMCS, all related to incorrect domain pricing behavior.
Bug 1 — Zero prices when TLD currency is unknown
File: hooks.php — DailyCronJob hook
Severity: Critical
Problem
When the API returned a TLD priced in a currency not present in WHMCS (Setup → Currencies), the variable $tldCurrency was set to 0. This caused a division-by-zero in the price calculation, resulting in 0 being written to the database for all price fields of that TLD.
// Before — division by zero when currency is missing
$tldCurrency = array_key_exists($tldCurrencyCode, $billing['currencies'])
? $billing['currencies'][$tldCurrencyCode]
: 0; // <-- causes division by zero below
Fix
Skip the TLD and log a warning instead of writing zero prices:
// After
$tldCurrency = $billing['currencies'][$tldCurrencyCode] ?? null;
if (!$tldCurrency) {
logActivity("UrlSolutions: unknown currency '{$tldCurrencyCode}' for TLD {$tld['tld']}, skipping.", 0);
continue;
}
Bug 2 — Unreliable currency rate lookup
File: hooks.php — DailyCronJob hook
Severity: Medium
Problem
The currencies array was built using pluck('code', 'rate') followed by array_flip. If two currencies had the same exchange rate, one would be silently lost due to key collision in array_flip, causing the affected currency to fall through to the zero-division bug above.
// Before — unreliable, loses currencies with duplicate rates
'currencies' => Capsule::table('tblcurrencies')->pluck('code', 'rate')->all(),
// then later: array_flip(...)
Fix
Use the correct argument order in pluck so the result is directly [code => rate] without needing array_flip:
// After — explicit and reliable
'currencies' => Capsule::table('tblcurrencies')->pluck('rate', 'code')->all(),
Bug 3 — msetupfee field never updated, always 0
File: hooks.php and run_prices.php
Severity: Critical (visible to end users)
Problem
The field iteration array was missing msetupfee. WHMCS (and the Lagom theme) uses msetupfee as the base price displayed in domain search results. Because it was never written, it stayed at 0.00, causing the storefront to show $0.00 /1yr for all affected TLDs regardless of actual prices being correct in other fields.
// Before — msetupfee missing, index starts at 0 with qsetupfee
foreach ([
'qsetupfee', 'ssetupfee', 'asetupfee', 'bsetupfee',
'monthly', 'quarterly', 'semiannually', 'annually', 'biennially',
] as $multiplier => $field) {
Fix
Add msetupfee as the first element (index 0, multiplier 0):
// After — msetupfee included at index 0
foreach ([
'msetupfee', // 0
'qsetupfee', // 1
'ssetupfee', // 2
'asetupfee', // 3
'bsetupfee', // 4
'monthly', // 5
'quarterly', // 6
'semiannually', // 7
'annually', // 8
'biennially', // 9
] as $multiplier => $field) {
$cost = $price + ($prices['domainrenew'] * $multiplier);
$fields[$field] = Capsule::raw("IF ({$field} = -1, -1, {$cost})");
}
Manual Price Update Script
A standalone script run_prices.php was created to force an immediate price update without waiting for the daily cron. It contains all the same fixes described above.
Usage:
/usr/bin/php8.3 /path/to/modules/registrars/urlsolutions/run_prices.php
Output example:
OK .com
OK .net
SKIP .xyz: unknown currency 'eur' (add it to WHMCS Currencies)
...
Done. Updated: 442, Skipped: 0
Important: Delete
run_prices.phpafter use — it should not be accessible via web.
Automatic Price Updates
Prices are updated automatically once per day via the DailyCronJob hook, provided:
- Enable PN Prices Loading is checked in module settings
(Setup → Products/Services → Domain Registrars → UrlSolutions → Configure) - The WHMCS main cron is configured on the server:
*/5 * * * * /usr/bin/php8.3 -q /path/to/whmcs/crons/cron.php
Price Calculation Formula
| Setting | Effect |
|---|---|
| Tax (%) | Multiplied on top of the API price: price * (1 + tax/100) |
| Min Cost ($) | If price after tax is below this value, Min Margin is added |
| Min Margin ($) | Added to price when it falls below Min Cost |
Example with Tax=50%, API register price=1.65 USD (promo):
1.65 * 1.50 = 2.475 → rounded to $2.48