How to use subscription API on ideamart platform


Please download sample code (PHP) from here.



Files :


  1. subscription.php  This file includes all the functions related to subscription API
  2. notification.php   This script collects the subscription notifications, which send to the app from ideamart (or simulator)
  3. definitions.php    This file contains Ideamart API endpoint data
  4. log.php                 That helps to record activities.







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";





How to register a user?


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.




$SubscriberId ="tel:94771234567";
// Register new user
$sub->RegisterUser($AppId,$Password,$SubscriberId);



How to unregister a user?


You can use following code in any script. But you need to get user address (like "tel:94771234567") from the ideamart side.




$SubscriberId ="tel:94771234567";
// Unregister new user
$sub->UnregisterUser($AppId,$Password,$SubscriberId);




Need to know how many users currently registered on your app?


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);




Are you need to check the status of your subscriber?


Use following code. status can be one of following

REGISTERED
UNREGISTERED
PENDING CHARGE
TEMPORARY_BLOCKED
BLOCKED




// Get user registration status
$status = $sub->getStatus($AppId,$Password,$SubscriberId);  




Subscription Notifications


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
}

?>






3 comments :

  1. වටිනා කියන ලිපියක් බොහොම ස්තුත්යි නුවන්

    ReplyDelete
  2. can you upload the database file also. Thanks.

    ReplyDelete