Guest User

Untitled

a guest
Jul 7th, 2014
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.49 KB | None | 0 0
  1. <?php
  2.  /* *** WHMCS JSON API Sample Code *** */
  3.  
  4. /* If you scroll to the bottom you will find this:
  5.  
  6. createAccount(); - Create the user account
  7. getDetails(); - Pulls his ID
  8. AddOrder(); - Add the order
  9.  
  10. The problem is in AddOrder(), because I don't know how to make this $postfields["clientid"] = 'XX'; dynamic, where XX is the ID that's stored on getDetails();
  11.  
  12. exit;
  13.  
  14. */
  15.  
  16.  
  17. class somethingSpecialForYou {
  18.  
  19.     private $createResponse;
  20.     private $detailsResponse;
  21.     private $orderResponse;
  22.  
  23.     function createAccount() {
  24.        
  25.          $url = "https://mysite.com/api.php"; # URL to WHMCS API file goes here
  26.          $username = "apiadmin"; # Admin username goes here
  27.          $password = "somepw"; # Admin password goes here
  28.        
  29.          $postfields = array();
  30.          $postfields["username"] = $username;
  31.          $postfields["password"] = md5($password);
  32.          $postfields["action"] = "addclient";
  33.          $postfields["responsetype"] = "json";
  34.        
  35.          $postfields["firstname"] = 'Test';
  36.          $postfields["lastname"] = 'Lastname';
  37.          $postfields["email"] = '[email protected]';
  38.          $postfields["password2"] = 'peido';
  39.  
  40.          $ch = curl_init();
  41.          curl_setopt($ch, CURLOPT_URL, $url);
  42.          curl_setopt($ch, CURLOPT_POST, 1);
  43.          curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  44.          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  45.          curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  46.          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
  47.          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
  48.          curl_setopt($ch, CURLOPT_CAINFO, "/home/usweb/public_html/cacert.pem");
  49.          $jsondata = curl_exec($ch);
  50.          if (curl_error($ch)) die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
  51.          curl_close($ch);
  52.          
  53.          $this->createResponse = json_decode($jsondata); # Decode JSON String
  54.     }
  55.  
  56.     function getDetails() {
  57.        
  58.          $url = "https://mysite.com/api.php"; # URL to WHMCS API file goes here
  59.          $username = "apiadmin"; # Admin username goes here
  60.          $password = "somepw"; # Admin password goes here
  61.          
  62.          $postfields = array();
  63.          $postfields["username"] = $username;
  64.          $postfields["password"] = md5($password);
  65.          $postfields["action"] = "getclientsdetails";
  66.        
  67.          $postfields["email"] = '[email protected]'; /* Pulls the client ID based on his e-mail */
  68.          $postfields["stats"] = true;
  69.          $postfields["responsetype"] = "json";
  70.  
  71.          $ch = curl_init();
  72.          curl_setopt($ch, CURLOPT_URL, $url);
  73.          curl_setopt($ch, CURLOPT_POST, 1);
  74.          curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  75.          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  76.          curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  77.          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
  78.          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
  79.          curl_setopt($ch, CURLOPT_CAINFO, "/home/usweb/public_html/cacert.pem");
  80.          $jsondata2 = curl_exec($ch);
  81.          if (curl_error($ch)) die("Connection Error: ".curl_errno($ch2).' - '.curl_error($ch));
  82.          curl_close($ch);
  83.          
  84.          $this->detailsResponse = json_decode($jsondata); # Decode JSON String
  85.     }
  86.  
  87.     function AddOrder() {
  88.        
  89.          $url = "https://mysite.com/api.php"; # URL to WHMCS API file goes here
  90.          $username = "apiadmin"; # Admin username goes here
  91.          $password = "somepw"; # Admin password goes here
  92.          
  93.          $postfields = array();
  94.          $postfields["username"] = $username;
  95.          $postfields["password"] = md5($password);
  96.          $postfields["action"] = "addorder";
  97.          $postfields["responsetype"] = "json";
  98.        
  99.  
  100.          $postfields["clientid"] = 'XX'; /* Should be dynamic, from getDetails(); */
  101.          $postfields["pid"] = "22";
  102.          $postfields["domain"] = 'www.somedomain.com';
  103.          $postfields["billingcycle"] = "monthly";
  104.          $postfields["domaintype"] = "register";
  105.          $postfields["regperiod"] = "1";
  106.          $postfields["paymentmethod"] = "pagseguro";
  107.  
  108.          $ch = curl_init();
  109.          curl_setopt($ch, CURLOPT_URL, $url);
  110.          curl_setopt($ch, CURLOPT_POST, 1);
  111.          curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  112.          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  113.          curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  114.          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
  115.          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
  116.          curl_setopt($ch, CURLOPT_CAINFO, "/home/usweb/public_html/cacert.pem");
  117.          $jsondata = curl_exec($ch);
  118.          if (curl_error($ch)) die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
  119.          curl_close($ch);
  120.          
  121.          $this->orderResponse = json_decode($jsondata); # Decode JSON String
  122.         print_r($this->orderResponse);
  123.  
  124.     }
  125. }
  126.  
  127.     $special = new somethingSpecialForYou();
  128.     $special->createAccount();
  129.     $special->getDetails();
  130.     $special->AddOrder();
  131.  
  132.      
  133.  ?>
Advertisement
Add Comment
Please, Sign In to add comment