1

Topic: Free SMS billing mod-tutorial (credits, account upgrade)

Following mod-tutorial is about how to integrate SMS billing for account credits with Fortumo.com SMS gateway provider. The great thing about Fortumo is that they give you atleast 50% revenue on "Advanced SMS services", no monthly fees, free setup and the following mod-tutorial is about Advanced SMS service.

This is Free mod-tutorial, only thing I ask is to add date24.ee as invitation code while creating account on Fortumo.com, You will get instantly 5 EURos on your Fortumo account.

First of all, check does Fortumo support country where you want enable SMS billing.
Currently  (08.02.2010) there are supported 33 countries:

Northern Europe
Estonia, Latvia, Lithuania, Finland, Sweden, Norway, Denmark

Central and Eastern Europe
Romania, Poland, Serbia, Bosnia and Herzogovina, Belarus, Russia, Croatia, Ukraine, Czech Republic, Slovakia, Slovenia, Bulgaria

Western Europe
Germany, United Kingdom, France, Portugal, Switzerland, Belgium, Netherlands, Ireland

Asia Pacific
Indonesia, Malaysia, China, Taiwan, Australia, Hong Kong


First of all create account in Fortumo.com

After account creation click on top menu "New service", check Advanced in "Premium SMS-connectivity" section click START

Now select countries where you are going to start SMS billing.

After you have selected countr(y)(ies), select service price from (cheap, average, expensive).

Now select keyword(s) for text messages (keyword should be short and easily remembered, for example CREDIT)

After you have price and keyword(s) selected click "NEXT"

On the next page you will see "Which web address will the received requests be forwarded to?"
Enter there Your website URL eg. www.yourdomain.com/sms-billing - we will change this later.
Change Character encoding to UTF-8

Click "NEXT"

Now confirm all needed checkboxes and click "NEXT" on the next page do the same.
On preview page you will see info about service that you are creating, if everything is OK click "YES".

Voila, congrats you have successfully created SMS billing service.

Ok, now to cool part, coding.

Go to Dashboard and click on your created service. You will see stats and info about service, leave it open, we will need Secret code from there.

Open VLD's .htaccess file and add right after RewriteEngine on

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^fortumo/credits/[b]unique_hash_here[/b]/?$ /vendor/fortumo/credits.php$1

Replace unique_hash_here with some random string, you can even put MD5 hash there.

Now open your service in Fortumo.com  and click Edit and replace previously added URL (www.yourdomain.com/sms-billing) with new one.
www.yourdomain.com/fortumo/credits/unique_hash_here/ click Save


Now create under root folder vendor and under that folder fortumo create there new file called credits.php
your file should be like VLDRootFolder/vendor/fortumo/credits.php
open it and copy/paste there following code:

<?php

  // check that the request comes from Fortumo servers, if they change You will be notified by fortumo.com
  if (!in_array($_SERVER['REMOTE_ADDR'], array('81.20.151.38', '81.20.148.122', '209.20.83.207')))
  {
    die("Error: Unknown IP");
  }  
  
  // how many credits to add?
  $credits = 250;
  
  /** NB! Response messages should be less than 140 characters! **/
  
  /** set success message response, will be sent to users mobile
   * Do not change %s and %d in message strings
   * %s - username
   * %d - credits amount
   * \n - newline
  */
  $successMessage = "Hello %s!\n" . 
                    "We added to your account %d credits.\n" . 
                    "We wish you hot dates!\nwww.date24.ee";
                    
  // set error message response, will be sent to user mobile                
  $errorMessage   = "Hello! Credits purchase failed.\n" .
                    "Maybe you wrote your username wrong.\n" . 
                    "Please contact with us at www.date24.ee.";
  // check the signature
  $secret = array('unique_secret_code_from_fortumo_com');
  
  // function for checking signature
  function check_signature($params_array = array(), $secrets = array()) 
  {
    ksort($params_array);
    $str = null;
    foreach ($params_array as $k => $v) {
      if($k != 'sig') {
        $str .= $k . '=' . $v;
      }
    }
    $signatures = array();
    foreach ($secrets as $secret) {
         $signatures[] = md5($str . $secret);
    }
    return in_array($params_array['sig'], $signatures);
  }
  
  // check is valid request
  if(!empty($secret) && !check_signature($_GET, $secret))
  {
    die("Error: Invalid signature");
  }
  
  $username = trim(mb_strtolower(htmlspecialchars(strip_tags($_GET['message'])), 'UTF-8'));
  
  require_once('../../includes/config.php');
  
  // create mysql connection
  $conn = mysql_connect($conf['db_hostname'], $conf['db_username'], $conf['db_password']);
  $db   = mysql_select_db($conf['db_name'], $conn);
  
  // select user by username
  $q = mysql_query("SELECT u.member_id, u.username FROM vld_members u WHERE UCASE(u.username) = '" . strtoupper($username) . "' LIMIT 1", $db);
  $dbResult = mysql_fetch_assoc($q);
  
  $message = null;
  
  if (isset($dbResult['member_id']) && $dbResult['member_id'] > 0)
  {
    // update user credits
    $creditResults =  mysql_query("UPDATE vld_members SET totalcredits = (totalcredits + '" . (int)$credits . "') WHERE member_id = '" . (int)$dbResult['member_id'] . "' LIMIT 1", $conn);
    if (mysql_affected_rows($conn) > 0) 
    {
      $message = sprintf($successMessage, $dbResult['username'], $credits);
    } else {
      $message = $errorMessage;
    }
  } else {
    $message = $errorMessage;
  }
   
  header('Content-Type: text/plain; charset=utf-8');
  echo $message;
  exit;
?>

Change in code unique_secret_code_from_fortumo_com with you services Secret.

Change $successMessage and $errorMessage variables
Save file.

Now upload .htaccess and vendor folder to your dating site.
Go to Fortumo.com againt, open your service and click Test tab - insert your admin account username and click Submit
You will get response from your script, if everything is ok you will see success message, otherwise error message.

Hopefully this mod will help you easily to earn more revenue from your users.

So, what are you waiting for? Go and register Your Fortumo.com account smile

Edit: Create page with information to users how they can add credits to their account, remember to follow fortumo rules.

Last edited by FredL (2010-02-09 13:04:16)

2

Re: Free SMS billing mod-tutorial (credits, account upgrade)

If you want to create membership SMS billing let me know here, I will update this post.

3

Re: Free SMS billing mod-tutorial (credits, account upgrade)

Nice. Too bad it is not available in Spain. Cheers.

4

Re: Free SMS billing mod-tutorial (credits, account upgrade)

please can you create sms billing for membership and if possibile one for featured members. :-) thanks fredl

5

Re: Free SMS billing mod-tutorial (credits, account upgrade)

great stuff, will try that tommorow!

6

Re: Free SMS billing mod-tutorial (credits, account upgrade)

i get some errors when testing the script out!

[19-Feb-2010 01:50:42] PHP Warning:  mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/pspsc2/public_html/girlslovegirls/vendor/fortumo/credits.php on line 63
[19-Feb-2010 01:50:42] PHP Warning:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/pspsc2/public_html/girlslovegirls/vendor/fortumo/credits.php on line 64

My line 63&64 are

  $q = mysql_query("SELECT u.member_id, u.username FROM vld_members u WHERE UCASE(u.username) = '" . strtoupper($username) . "' LIMIT 1", $db);
  $dbResult = mysql_fetch_assoc($q);

any help would be very appriciated

7

Re: Free SMS billing mod-tutorial (credits, account upgrade)

Huoh. I was away for a while from internet. Now back.

Jan. As i replied to your e-mail, please check that path to your config.php is right.

You can debug if you change connection and database querys like this:
If you will get error, paste it here.

  
// create mysql connection
  $conn = mysql_connect($conf['db_hostname'], $conf['db_username'], $conf['db_password']) || die(mysql_error());
  $db   = mysql_select_db($conf['db_name'], $conn) || die(mysql_error());

facelush.

How would like this thing to work? Member sends SMS and he/she will be automatically added to member group or marked as featured member?

8

Re: Free SMS billing mod-tutorial (credits, account upgrade)

FredL wrote:

Huoh. I was away for a while from internet. Now back.

Jan. As i replied to your e-mail, please check that path to your config.php is right.

You can debug if you change connection and database querys like this:
If you will get error, paste it here.

  
// create mysql connection
  $conn = mysql_connect($conf['db_hostname'], $conf['db_username'], $conf['db_password']) || die(mysql_error());
  $db   = mysql_select_db($conf['db_name'], $conn) || die(mysql_error());

facelush.

How would like this thing to work? Member sends SMS and he/she will be automatically added to member group or marked as featured member?

hi , i succesfully got this running.
i use it for buying credits and for upgrading membership

no big succes yet but i believe in it when i promote it heavy on my site!

thanks for the guide FredL

9

Re: Free SMS billing mod-tutorial (credits, account upgrade)

is it me or fortume doesent work for USA for example ?

10

Re: Free SMS billing mod-tutorial (credits, account upgrade)

You can create account if you are in US. But currently you can't run SMS services in US, check my first post to see which countries are currently supported by fortumo.

11

Re: Free SMS billing mod-tutorial (credits, account upgrade)

i get same error as jan.claeys
no clue how to fix it

12

Re: Free SMS billing mod-tutorial (credits, account upgrade)

can you add php script for membership?

13

Re: Free SMS billing mod-tutorial (credits, account upgrade)

I would like integrate this system SMS premium in my Vldpersonals FredL.

Something update?

14

Re: Free SMS billing mod-tutorial (credits, account upgrade)

Hi

Now i have VLD Personals 2.6

As you see here probably the is some discussion about some older versions
Well as you can find on this image .... there is something different

there is not anymore vendor folder.....

PunBB bbcode test

PunBB bbcode test

Is possible to update your info where do i have to put this code

15

Re: Free SMS billing mod-tutorial (credits, account upgrade)

I`m going to give it a try today:)

I have not failed. I've just found 10,000 ways that won't work