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$1Replace 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 ![]()
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)

