daily pastebin goal
8%
SHARE
TWEET

Customer Value With OfficeAutopilot

darrenscrawford Jul 15th, 2013 527 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Get the variables from the URL
  4.         $contact_id (oap contact id)
  5.         $purchases (current # of products purchased)
  6.         $lastAmt (last purchase amount)
  7.         $lifevalue (lifetime value amount)
  8.  
  9. Add 1 to the number of purchases
  10. Update the contact record with the new total # of purchases
  11.  
  12. Version: 0.1
  13. Last update: July 15, 2013
  14.  
  15.  
  16. Setup your PING URL Like this:
  17. http://yourdomain.com/lifetimevalue.php?contact_id=[contact_id]&purchases=[Number of Purchases]&last_amount=[Last Charge Amount]&lifevalue=[Lifetime Value]
  18. http://screencast.com/t/F4LJuJ5vPeg
  19. */
  20.  
  21.  
  22.  
  23.  
  24. //GET variables from URL
  25. $contact_id = $_GET["contact_id"];
  26. $purchases = $_GET["purchases"];
  27. $last_amount = $_GET["last_amount"];
  28.         $last_amount = substr($last_amount, 1);
  29. $lifevalue = $_GET["lifevalue"];
  30.         $lifevalue = substr($lifevalue, 1);
  31.  
  32.  
  33. //Do math - add one to current number of purchases
  34. $purchases=$purchases+1;
  35. $lifevalue = $lifevalue + $last_amount;
  36. $avgTrans = $lifevalue/$purchases; // do a calc to tally the average transaction value
  37.  
  38.  
  39. /* For testing outputs only...
  40. echo "Contact ID: ".$contact_id;
  41. echo "<br/>";
  42. echo "purchases: ".$purchases;
  43. echo "<br/>";
  44. echo "LTV: ".$lifevalue;
  45. echo "<br/>";
  46. echo "avg transaction: ".$avgTrans;
  47. echo "<br/>";
  48. */
  49.  
  50. $data = <<<STRING
  51. //You must pass the contact ID as an argument to indicate which contact is being updated
  52. <contact id="$contact_id">
  53. <Group_Tag name="Buying Cycles">
  54. <field name="Number of Purchases">$purchases</field>
  55. <field name="Lifetime Value">$lifevalue</field>
  56. <field name="Average Transaction Value">$avgTrans</field>
  57. </Group_Tag>
  58. </contact>
  59. STRING;
  60.  
  61. $data = urlencode(urlencode($data));
  62.  
  63. // Replace the strings with your API credentials located in Admin > OfficeAutoPilot API Instructions and Key Manager
  64. $appid = "XXXXX";
  65. $key = "XXXXX";
  66.  
  67. $reqType= "update";
  68. $postargs = "appid=".$appid."&key=".$key."&return_id=1&reqType=".$reqType. "&data=" . $data;
  69. $request = "https://api.moon-ray.com/cdata.php";
  70.  
  71. $session = curl_init($request);
  72. curl_setopt ($session, CURLOPT_POST, true);
  73. curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
  74. curl_setopt($session, CURLOPT_HEADER, false);
  75. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  76. $response = curl_exec($session);
  77. curl_close($session);
  78. header("Content-Type: text/xml");
  79. echo $response;
  80.  
  81. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top