PHP API Affiliate Program Example

  1. <?php 
  2. require_once('sendsms_api.php');
  3. /*
  4. * Affiliate program example
  5. * 1.) Get dialing code for an ipadress
  6. * 2.) Create a new user
  7. * 3.) Set dialling code
  8. */
  9. //setting user data
  10. $SendsmsApi new SendsmsApi();
  11.  
  12. //specify your username and password
  13. $SendsmsApi->setUsername("username");
  14. $SendsmsApi->setPassword("password");
  15. $userdata =array(
  16. "email"=>"testuser@test.com",
  17. "cellphone_number"=>"0799939999",
  18. "default_dialling_code"=>"27");
  19. //setting a promo code
  20. //you will be provided with this code 
  21. $promotion_code "abcdefg";
  22.  
  23. //Get user ip address
  24. $ip $_SERVER['REMOTE_ADDR'];
  25.  
  26. //attempt to get country information
  27. $result         $SendsmsApi->get_affiliate_country_info($ip);
  28. if($SendsmsApi->ok($result)){
  29.   if(count($result['details']12){
  30.       //unable to get country information
  31.       //se we are going to use the default prefix we set above
  32.       $dialling_code $userdata["default_dialling_code"];
  33.   else{
  34.        $dialling_code $result['details']['dialling_code'];
  35.   }
  36. }
  37.  
  38. $msg $SendsmsApi->affiliate_register_user($userdata['email']$dialling_code$userdata['cellphone_number'],$ip );
  39. if($SendsmsApi->ok($msg)) {
  40.   //new user has been created
  41.   if$promotion_code !== ""){
  42.       $result $SendsmsApi->affiliate_set_promotion_code($msg['details']['user_id']$promotion_code);
  43.       if($SendsmsApi->ok($result)) {
  44.       //Promotion code saved
  45.       else {
  46.           echo $result['details']['Error'];
  47.       }
  48.   }
  49.   //handle these values in any manner you see fit
  50.   echo "New user created: " "<br />"
  51.   echo $msg['details']['message']."<br />";
  52.   echo $msg['details']['username']."<br />";
  53.   echo $msg['details']['password']."<br />";
  54. else{
  55. //Displaying error messages
  56.   foreach($msg['details']['ErrorMessages'as $key=>$value){
  57.       echo $value."\r\n";
  58.   }
  59. }
  60. ?>