[WHMCS] sell in multiple currencies for the same client

So recently I ran into this weird scenario where I had to sell Product A in USD and Product B in EUR for the same client on XSL.TEL because in current WHMCS currency system the client can choose 1 currency at registration and have to create new account using new email to buy a product with another currency.

The Idea

Basically I will use my licensed WHMCS installation to work with multiple databases based on client cookie I set through a small php script and then redirect coming client to requested WHMCS page.

Pros

  • With this solution you can share your current clients with sub installations through DB Views (or you can spread your clients over multi databases)  .
  • Ability to run unlimited numbers of WHMCS script licenses on same installation (testing, developing, etc…) .
  • You can have multi-currency / multi-language installations .
  • You can run cron for every new system you create.

Cons

  • Reply-to-answer ticket feature via pipe is lost because you can’t pass parameter to pipe.php file. (however it is possible through pop3 import feature).
  • Paypal IPN won’t work on sub installations (it send IPN to main installation only).
  • It may not work with a few modules .I didn’t test everything.
  • you can login to one system per browser for both admin/client .
  • Enabling WHMCS auto data retention removed my clients data when I did the optional step of merging both system clients data .

Let’s get to work

You will need to create new database with our main whmcs db in this tutorial its called eudb_name Below steps assumes that you already have installed WHMCS and don’t have any data on it .

Edit your configuration.php as follows (don’t forget to change database name, database usernames, db user passwords) .

 //======= BEGIN of configuration.php content 
<?php
$license = 'YOURLICENSE';
$db_host = 'localhost';
$cc_encryption_hash = 'some_random_chars_here';
switch($_COOKIE['clientbase']) {
    case "us":
        $db_username = 'usdb_usr';
        $db_password = 'usdb_password';
        $db_name = 'usdb_name';
        $mysql_charset = 'utf8';
        $attachments_dir = "/path/to/us/attachments";
        $downloads_dir = "/path/to/us/downloads/";
        $templates_compiledir = "/path/to/us/templates_c/";
        break;
    case "eu":
        $db_username = 'eudb_usr';
        $db_password = 'eudb_password';
        $db_name = 'eudb_name';
        $mysql_charset = 'utf8';
        $attachments_dir = "/path/to/eu/attachments";
        $downloads_dir = "/path/to/eu/downloads/";
        $templates_compiledir = "/path/to/eu/templates_c/";
        break;
   // if no cookie is set then we pass default us db to our client
    default:
        $db_username = 'usdb_usr';
        $db_password = 'usdb_password';
        $db_name = 'usdb_name';
        $mysql_charset = 'utf8';
        $attachments_dir = "/path/to/us/attachments";
        $downloads_dir = "/path/to/us/downloads/";
        $templates_compiledir = "/path/to/us/templates_c/";
        break;
}
 //======= END of configuration.php content 

US DB

In your public html folder create a new folder and let’s call it “us” and create .htaccess and index.php files and edit them as follows

#======= BEGIN of .htaccess content 
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?uri=$1 [QSA,PT,L]
#======= END of .htaccess edit 
//======= BEGIN of index.php content 
<?php
setcookie("clientbase", "us",NULL, "/", "xsl.tel", 1, 1);
$args = $_REQUEST;
unset($args['uri']);
$newArgs= array();
foreach($args as $key => $value) {
    $newArgs[] = "{$key}={$value}";
}
$queryargs = implode('&',$newArgs);
header("Location: https://my.xsl.tel/{$_GET['uri']}?{$queryargs}");
//======= END of index.php content 

Make sure to change domain in cookie you set and the url of your whmcs installation

EU DB

Create another folder and let’s call it “eu” for our EUR currency create same files in our US DB example except change index.php as follows (just change cookie value from us to eu so our configuration.php serve eudb_name)

//======= BEGIN of index.php content 
<?php
setcookie("clientbase", "eu",NULL, "/", "xsl.tel", 1, 1);
$args = $_REQUEST;
unset($args['uri']);
$newArgs= array();
foreach($args as $key => $value) {
    $newArgs[] = "{$key}={$value}";
}
$queryargs = implode('&',$newArgs);
header("Location: https://my.xsl.tel/{$_GET['uri']}?{$queryargs}");
//======= END of index.php content 

MySQL

You have to mysqldump/export your current whmcs database (usdb_name) in this tutorial and import it on your (eudb_name) or whatever your new db_name.
Try to change whmcs.domain/eu/ (WHMCS Company Name to something different to see if it differs from whmcs.domain/us/) .
If everything works as expected continue to setting up cron jobs for new systems.

Cron Jobs

Looks like we can’t pass cookie through command line so we will run cron through wget using this command  (don’t forget to change domain)

 #======= BEGIN of System cron job 
*/5     *     *     *     *     wget -O /dev/null https://my.xsl.tel/us/crons/cron.php > /dev/null 2>&1
*/5     *     *     *     *     wget -O /dev/null https://my.xsl.tel/eu/crons/cron.php > /dev/null 2>&1
 #======= END of  System  cron job 
# Only use if you want to use pop3 import feature to import tickets to your sub-systems   
#======= BEGIN of POP3 Ticket Import cron job 
*/5     *     *     *     *     wget -O /dev/null https://my.xsl.tel/us/crons/pop.php > /dev/null 2>&1
*/5     *     *     *     *     wget -O /dev/null https://my.xsl.tel/eu/crons/pop.php > /dev/null 2>&1
#======= END of   POP3 Ticket Import  cron job 

For security reasons you may want to restrict accessing /crons/ folder from your server IP only to avoid bots bombing your cron.php with requests so create .htaccess file with following directives

 #======= BEGIN of .htaccess content 
Order Allow,Deny 
Allow from IP-OF-SERVER 127.0.0.1
 #======= END of .htaccess content 

Login to our new /eu/ whmcs admin panel and change currency to EUR and WHMCS system url to corresponding folders we created above and you are done.

Merge Clients/Contacts

Optional Step merging clients & contacts of main usdb_name and eudb_name RUN this query in mysql as root/permitted user for both databases

#======= BEGIN of MySQL Clients merge 
DROP TABLE eudb_name.tblclients;
CREATE VIEW eudb_name.tblclients AS SELECT * FROM usdb_name.tblclients;
DROP TABLE eudb_name.tblcontacts;
CREATE VIEW eudb_name.tblcontacts AS SELECT * FROM usdb_name.tblcontacts;
#======= END of MySQL Clients merge 

Leave a comment

Your email address will not be published. Required fields are marked *