PHP API Affiliate Program Example

  1. <?php

  2. require_once('panacea_api.php');

  3. /*

  4. * Panacea Affiliate program example

  5. * 1.) Get dialing code for an ip address

  6. * 2.) Create a new user

  7. * 3.) Set dialling code

  8. */

  9. //setting user data

  10. $PanaceaApi = new PanaceaApi();

  11.  

  12. //specify your username and password

  13. $PanaceaApi->setUsername("username");

  14. $PanaceaApi->setPassword("password");

  15. $userdata =array(

  16. "email"=>"[email protected]",

  17. "cellphone_number"=>"0799939999",

  18. "default_dialling_code"=>"27");

  19. //setting a promo code

  20. //you will be provided with this code by panacea

  21. $promotion_code = "abcdefg";

  22.  

  23.  

    //Get user ip address

  24. $ip = $_SERVER['REMOTE_ADDR'];

  25.  

  26. //attempt to get country information

  27. $result = $PanaceaApi->get_affiliate_country_info($ip);

  28. if($PanaceaApi->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 = $PanaceaApi->affiliate_register_user($userdata['email'], $dialling_code, $userdata['cellphone_number'],$ip );

  39. if($PanaceaApi->ok($msg)) {

  40. //new user has been created

  41. if( $promotion_code !== ""){

  42. $result = $PanaceaApi->affiliate_set_promotion_code($msg['details']['user_id'], $promotion_code);

  43. if($PanaceaApi->ok($result)) {

  44. //Promotion code saved

  45. } else {

  46. echo $result['details']['Error']; }

  47. }

  48. //handle these values in any manner you see fit

  49. echo "New user created: " . "<br />"

  50. echo $msg['details']['message']."<br />";

  51. echo $msg['details']['username']."<br />";

  52. echo $msg['details']['password']."<br />";

  53. } else{

  54. //Displaying error messages

  55. foreach($msg['details']['ErrorMessages'] as $key=>$value){

  56. echo $value."\r\n";

  57. }

  58. }

  59. ?>