jbrown Posted January 1, 2014 Share Posted January 1, 2014 I have read the API docs, and I have a few clients that use a custom script to add and remove accounts from their profile. One of my hosting companies adds and removes accounts between 50 - 100 times per week. How this is done is by using a custom script I have created to enter and remove orders from our old billing system by entering the domain name. So if this hosting company would like to add a product, pretty simple, this is what I am doing: $data["username"] = "xxxxxx"; $data["password"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $data['action'] = 'addorder'; $data['clientid'] = '66'; $data["pid"] = "6"; $data["domain"] = $domain; $data["priceoverride"] = '4'; $data["billingcycle"] = "monthly"; $data["customfields"] = base64_encode(serialize(array("1"=>"Google", "Domain Name"=>$domain))); $data["regperiod"] = "1"; $data["paymentmethod"] = "mailin"; $data["noemail"] = "true"; $data["noinvoiceemail"] = "true"; $data["noinvoice"] = "true"; $create = whmcsapi($data); if ($create["result"]=="success"){ $postfields["username"] = "slapiuser"; $postfields["password"] = "e3548a9b2b839959a61d78579cbe3a18"; $postfields["action"] = 'acceptorder'; $postfields["orderid"] = $create['orderid']; $postfields["sendemail"] = false; $activate = whmcsapi($postfields); if ($results['result'] == 'success'){ echo "Adding account was successful"; } } } I do realize that it is putting the domain in 2 areas (the domain field and the custom field) this will change eventually. This works great, it will add a new account to their order and work just fine. Where the problem comes into play is when they need to remove that account, the deleteorder API call needs the order number, I have a paste of the array that is being returned from WHMCS with the getorders here: /http://pastebin.com/6CqYuGzu How do I get the order number for the domain they are trying to remove so I can use the deleteorder API command to remove the specific order? Any suggestions? Thanks, Jeff 0 Quote Link to comment Share on other sites More sharing options...
jbrown Posted January 2, 2014 Author Share Posted January 2, 2014 Since this post took a couple of days to get posted, I have actually resolved this issue on my own. I will give my example in case anyone else would like to do this. if ($action == 'delete'){ $data["username"] = "xxxxxxx"; $data["password"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $data['action'] = 'getorders'; $data['userid'] = '66'; $array = whmcsapi_xml($data); $orderID = getOrderID($domain, $array); $data["username"] = "xxxxxxx"; $data["password"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $data['action'] = 'deleteorder'; $data['orderid'] = $orderID; $result = whmcsapi($data); if ($result['result'] == 'success'){ echo "Deleting account was successful"; } } elseif ($action == 'add'){ $data["username"] = "xxxxxxx"; $data["password"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $data['action'] = 'addorder'; $data['clientid'] = '66'; $data["pid"] = "6"; $data["domain"] = $domain; $data["priceoverride"] = '4'; $data["billingcycle"] = "monthly"; $data["customfields"] = base64_encode(serialize(array("1"=>"Google", "Domain Name"=>$domain))); $data["regperiod"] = "1"; $data["paymentmethod"] = "mailin"; $data["noemail"] = "true"; $data["noinvoiceemail"] = "true"; $data["noinvoice"] = "true"; $create = whmcsapi($data); if ($create["result"]=="success"){ $data["username"] = "xxxxxxx"; $data["password"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $postfields["action"] = 'acceptorder'; $postfields["orderid"] = $create['orderid']; $postfields["sendemail"] = false; $activate = whmcsapi($postfields); if ($results['result'] == 'success'){ echo "Adding account was successful"; } } } The Add is pretty straight forward. In the add section it will first Add the account, then if it is successful, it will auto accept the account. The Delete is a little more complicated. The only way I could figure out how to do it was to create a function to parse through all of the array. function getOrderID($searchfor, $input_array){ foreach($input_array['WHMCSAPI']['ORDERS'] as $orderskey => $ordersvalue){ foreach($ordersvalue as $orderkey => $ordervalue){ if(preg_match("/LINEITEMS[1-9]*/i", $orderkey, $match)){ foreach($ordervalue as $key => $value){ if($value['DOMAIN'] == $searchfor){ $orderid = $input_array['WHMCSAPI']['ORDERS'][$orderskey]['ID']."<br />"; } } } } } if(isset($orderid)){ return $orderid; }else{ return "Domain not found"; } } How I am using is it like this: $orderID = getOrderID($domain, $array); $orderID will return the order number with the matched domain from the array. I am using the 3 functions WHMCS had provided in their API module: whmcsapi, whmcsapi_xml, whmcsapi_xml_parser The whmcsapi is used for the Add Account The whmcsapi_xml and whmcsapi_xml_parser is used for the Delete account. Maybe when I redo there account system I may clean up this code a little more and use XML entirely. But for now, I am not a very good XML person. The only problem now is this... This is the ONLY customer I have that is billed on the 15th of every month. I cannot find a way to charge just this customer once a month for any account that was added for that month. If anyone has any suggestions, I would appreciate it. Thanks, Jeff 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.