Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* *** WHMCS JSON API Sample Code *** */
- /* If you scroll to the bottom you will find this:
- createAccount(); - Create the user account
- getDetails(); - Pulls his ID
- AddOrder(); - Add the order
- 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();
- exit;
- */
- class somethingSpecialForYou {
- private $createResponse;
- private $detailsResponse;
- private $orderResponse;
- function createAccount() {
- $url = "https://mysite.com/api.php"; # URL to WHMCS API file goes here
- $username = "apiadmin"; # Admin username goes here
- $password = "somepw"; # Admin password goes here
- $postfields = array();
- $postfields["username"] = $username;
- $postfields["password"] = md5($password);
- $postfields["action"] = "addclient";
- $postfields["responsetype"] = "json";
- $postfields["firstname"] = 'Test';
- $postfields["lastname"] = 'Lastname';
- $postfields["password2"] = 'peido';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 30);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
- curl_setopt($ch, CURLOPT_CAINFO, "/home/usweb/public_html/cacert.pem");
- $jsondata = curl_exec($ch);
- if (curl_error($ch)) die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
- curl_close($ch);
- $this->createResponse = json_decode($jsondata); # Decode JSON String
- }
- function getDetails() {
- $url = "https://mysite.com/api.php"; # URL to WHMCS API file goes here
- $username = "apiadmin"; # Admin username goes here
- $password = "somepw"; # Admin password goes here
- $postfields = array();
- $postfields["username"] = $username;
- $postfields["password"] = md5($password);
- $postfields["action"] = "getclientsdetails";
- $postfields["stats"] = true;
- $postfields["responsetype"] = "json";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 30);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
- curl_setopt($ch, CURLOPT_CAINFO, "/home/usweb/public_html/cacert.pem");
- $jsondata2 = curl_exec($ch);
- if (curl_error($ch)) die("Connection Error: ".curl_errno($ch2).' - '.curl_error($ch));
- curl_close($ch);
- $this->detailsResponse = json_decode($jsondata); # Decode JSON String
- }
- function AddOrder() {
- $url = "https://mysite.com/api.php"; # URL to WHMCS API file goes here
- $username = "apiadmin"; # Admin username goes here
- $password = "somepw"; # Admin password goes here
- $postfields = array();
- $postfields["username"] = $username;
- $postfields["password"] = md5($password);
- $postfields["action"] = "addorder";
- $postfields["responsetype"] = "json";
- $postfields["clientid"] = 'XX'; /* Should be dynamic, from getDetails(); */
- $postfields["pid"] = "22";
- $postfields["domain"] = 'www.somedomain.com';
- $postfields["billingcycle"] = "monthly";
- $postfields["domaintype"] = "register";
- $postfields["regperiod"] = "1";
- $postfields["paymentmethod"] = "pagseguro";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 30);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
- curl_setopt($ch, CURLOPT_CAINFO, "/home/usweb/public_html/cacert.pem");
- $jsondata = curl_exec($ch);
- if (curl_error($ch)) die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
- curl_close($ch);
- $this->orderResponse = json_decode($jsondata); # Decode JSON String
- print_r($this->orderResponse);
- }
- }
- $special = new somethingSpecialForYou();
- $special->createAccount();
- $special->getDetails();
- $special->AddOrder();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment