RPS Posted January 28, 2008 Share Posted January 28, 2008 Someone else might make use out of what I just finished coding. The following script (inside of actionhooks.php) will run once an invoice has been paid for. A perfect example of why you would need this is if you were selling a product that contains a serial number. So you have a product created that requires a serial number of type 'Other'. You will also have a custom field named 'Serial Number' that is hidden on the order form. When client places an order, an event is triggered to run the code inside the actionhooks file. The code will verify the correct product is ordered, and that you will need to generate a serial number. Once the serial number is generated, it will update the custom field which contains that value. You can manually e-mail the client, or you can wait for WHMCS to update the API so that it will be able to e-mail using an e-mail template. (Matt says this may be done within a week or so). function actionhook_InvoicePaid($vars) { # This function runs when an invoice is fully paid and therefore the services renewed # $vars["InvoiceID"] /***************************************************************************************************************** This script is perfect if you are selling a product of type 'Other' that has a serial number associated with it. It is assumed that you connect to another script that generates the serial number, in this case, I have hard coded it. You will need to modify the $packageid == "0000000038" line to use the correct package id You will also need to modify the $serialNumber = "SERIALNUMBER567890"; to input the correct information into the custom field *****************************************************************************************************************/ // this example will insert something into a custom field when a package id is given (this example uses 0000000038 for the packageid) // this code will check to make sure the correct package is ordered // once it is verified to be correct package, it will lookup the custom field associated with the package // once the custom field name is available, it will insert something into the value of the custom field // we need invoiceid in order to do a lookup $invoiceID = $vars['InvoiceID']; // lookup relid from the invoiceid $result = mysql_query("SELECT relid FROM tblinvoiceitems WHERE type='Hosting' AND invoiceid='".$invoiceID."'"); $grab_relid = mysql_fetch_row($result); $relid = $grab_relid[0]; // lookup the packageid from the relid $result = mysql_query("SELECT packageid FROM tblhosting WHERE id='".$relid."'"); $grab_packageid = mysql_fetch_row($result); $packageid = $grab_packageid[0]; // verify package id is of the correct product type - one that should have additional action taken if($packageid == "0000000038") { // temporary serial number just for testing $serialNumber = "SERIALNUMBER567890"; // grab the fieldname from the product associated with the package id entered $result = mysql_query("SELECT fieldname FROM tblcustomfields WHERE relid='".$packageid."'"); $grab_fieldname = mysql_fetch_row($result); $fieldName = $grab_fieldname[0]; // now we need to find the custom field id number since we know the name of the custom field // this will cause an error if there are more than 1 custom fields with the same name // suggestions for additional error handling here are welcome // note: id on tblcustomfields = fieldid on tblcustomfieldsvalues $result = mysql_query("SELECT id FROM tblcustomfields WHERE fieldname='".$fieldName."'"); $grab_customfieldid = mysql_fetch_row($result); $customfieldid = $grab_customfieldid[0]; // now we have the custom field id, the relid (which was looked up earlier based on the invoice), and then the serial number, // we can insert this into the table to associate the serial number with the product purchased mysql_query("INSERT INTO tblcustomfieldsvalues (fieldid, relid, value) VALUES('".$customfieldid."', '".$relid."', '".$serialNumber."') "); // call WHMCS API to send client e-mail // send out e-mail to say the test worked, comment this out when you are done testing $mydate = date ( 'l, F d Y g:i A',time()+240 ); // where to send e-mail to $to = 'enter-your-email-here@domain.com'; // e-mail subject $subject = "The Test Worked!"; // e-mail message $message = "Hello,\r\n" ."Details are below:\r\n" ."-----------------------------------------\r\n" ."Invoice ID: $invoiceID\r\n" ."Relid: $relid\r\n" ."Package ID: $packageid\r\n" ."Custom Field Name for Package ID: $fieldName\r\n" ."Date: $mydate\r\n"; $headers = "From: $SSL Certificate <$noreply@example.com>\n" ."Reply-To: noreply@example.com\n" ."X-Mailer: PHP/".phpversion(); mail( $to, $subject, $message, $headers ); } } 0 Quote Link to comment Share on other sites More sharing options...
amol.karande Posted February 4, 2008 Share Posted February 4, 2008 As you have deal with actionhooks please tell me that can I run any action such as connecting to other site because on order completion I want to run some api which is at different website as action hooks dont have any event related to it so ho could i achieve it please guide me thank you 0 Quote Link to comment Share on other sites More sharing options...
RPS Posted February 4, 2008 Author Share Posted February 4, 2008 Just put the php code under the appropriate spot within the file.... 0 Quote Link to comment Share on other sites More sharing options...
amol.karande Posted February 7, 2008 Share Posted February 7, 2008 Just put the php code under the appropriate spot within the file.... thank you I am able to run actionhooks as per my requirment.but one more issue I have to clear I want to access custom fields as their is table for custom fields how I supposed to go in order to get custom fields of specific client. Can you guide me on that Thank you 0 Quote Link to comment Share on other sites More sharing options...
Nick Posted February 8, 2008 Share Posted February 8, 2008 Your two options are to: 1) Learn PHP. 2) Pay someone else to come up with something for you. 0 Quote Link to comment Share on other sites More sharing options...
RPS Posted February 8, 2008 Author Share Posted February 8, 2008 thank you I am able to run actionhooks as per my requirment.but one more issue I have to clear I want to access custom fields as their is table for custom fields how I supposed to go in order to get custom fields of specific client. Can you guide me on that Thank you - Read my first post, my code does this... 0 Quote Link to comment Share on other sites More sharing options...
amol.karande Posted February 11, 2008 Share Posted February 11, 2008 Thank you sir I have done with issue with custom fields access and I am in last stage of my applications first part. thank you:) 0 Quote Link to comment Share on other sites More sharing options...
altomarketing Posted July 28, 2011 Share Posted July 28, 2011 Why the email i receive is in blank ? shows as : Hello, Details are below: ----------------------------------------- Invoice ID: Relid: Package ID: Custom Field Name for Package ID: Date: Thursday, July 28 2011 11:18 AM All other works like charm. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted July 28, 2011 Share Posted July 28, 2011 This thread is like 3 years old, who knows if it even still works anymore. 0 Quote Link to comment Share on other sites More sharing options...
Nimitz1061 Posted September 6, 2011 Share Posted September 6, 2011 This thread is like 3 years old, who knows if it even still works anymore. It seems pretty likely that it would work - if all the prerequisites are met. One good reason it would not work is mismatch for the package id. if($packageid == "0000000038") Another might be case sensitivity in the variable passed. Docs for this hook indicate that 'invoiceid' is passed, not 'InvoiceID'. David 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.