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. //specify your username and password

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

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

  14. $userdata =array(

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

  16. "cellphone_number"=>"0799939999",

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

  18. //setting a promo code

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

  20. $promotion_code = "abcdefg";

  21. //Get user ip address

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

  23. //attempt to get country information

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

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

  26. if(count($result['details']) < 12){

  27. //unable to get country information

  28. //se we are going to use the default prefix we set above

  29. $dialling_code = $userdata["default_dialling_code"];

  30. } else{

  31. $dialling_code = $result['details']['dialling_code'];

  32. }

  33. $msg = $PanaceaApi->affiliate_register_user($userdata['email'], $dialling_code, $userdata['cellphone_number'],$ip );

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

  35. //new user has been created

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

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

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

  39. //Promotion code saved

  40. } else {

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

  42. }

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

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

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

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

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

  48. } else{

  49. //Displaying error messages

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

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

  52. }

  53. }

  54. ?>