Please download sample code (PHP) from here first.
Files :
First, add following script on the head of the PHP script for initializing settings
<?php
include_once "definitions.php";
include_once "subscription.php";
$sub = new Subscription();
$AppId = "APP_000000";
$Password = "";
$SubscriberId ="tel:94771234567";
You can use following code in any script. But you need to get the masked user address (like “tel:B%3C4P+QB59sTSmJbLNMvHJC3VyqatcWavD6kWPkPy3GtLbSE5Nyv4PC6JZOaHsE1hver”) from the ideamart side, in a real case.
$SubscriberId ="tel:94771234567";
// Register new user
$sub->RegisterUser($AppId,$Password,$SubscriberId);
You can use following code in any script. But you need to get user address (like “tel:B%3C4P+QB59sTSmJbLNMvHJC3VyqatcWavD6kWPkPy3GtLbSE5Nyv4PC6JZOaHsE1hver”) from the ideamart side, in a real case.
$SubscriberId ="tel:94771234567";
// Unregister new user
$sub->UnregisterUser($AppId,$Password,$SubscriberId);
Use following code, you can get the number of active subscribers
(Please note that this function gives only the count of active users. On ideamart, PENDING CHARGE status doesn’t count as an active user. So actual subscriber base may be higher than this value)
//Get subscription base size
$baseSize = $sub->getBaseSize($AppId,$Password);
Use following code. status can be one of following
// Get user registration status
$status = $sub->getStatus($AppId,$Password,$SubscriberId);
When user registering or unregistering from your app, ideamart send a notification to your app. You need to give the URL of this script to “Subscription Notification URL” in subscription API configurations.
<?php
include_once 'log.php';
$array = json_decode(file_get_contents('php://input'), true);
$applicationId =$array['applicationId'];
$frequency= $array['frequency'];
$status= $array['status'];
$address= $array['subscriberId'];
$version= $array['version'];
$timeStamp= $array['timeStamp'];
logFile("");
logFile("***********************************************");
logFile("address :$address");
logFile("frequency :$frequency");
logFile("status :$status");
logFile("timestamp :$timeStamp");
if($status=="REGISTERED") {
// Do something
}else if($status=="UNREGISTERED") {
// Do something
}
?>