/** * Record sales on InfusionSoft */ private function _infusion_sales($product, $plan, $email, $first_name, $last_name, $affiliate_id, $paid_amount = NULL) { // Add or Get buyer from InfusionSoft require_once app_path() . "/libraries/infusionsoft/isdk.php"; // Add InfusionSoft Library $isapp = new iSDK(); // Create Connection if ($isapp->cfgCon("comissionTracker")) { // find contact by email $contacts = $isapp->findByEmail($email, array('Id', 'Email')); // If contact found if (!empty($contacts[0]['Id'])) { $contact_id = $contacts[0]['Id']; } else { // Create new contact $contactData = array('Email' => $email, 'FirstName' => $first_name, 'LastName' => $last_name); $contact_id = $isapp->addCon($contactData); } // Sets current date $currentDate = date("d-m-Y"); $oDate = $isapp->infuDate($currentDate); // Creates blank order $newOrder = $isapp->blankOrder($contact_id, "{$product->name} - {$plan->name} ({$contact_id})", $oDate, NULL, $affiliate_id); // Add Order Item - Product ID // type = 4 or 9 (Product or Subscription) $infusion_product_type = $product->type == 1 ? 4 : 9; if ($paid_amount === NULL or $paid_amount === '') { $paid_amount = $plan->price; } $orderPrice = $paid_amount; //$paid_amount ? $paid_amount : $plan->price; $orderPrice = floatval(round($orderPrice, 2)); $result = $isapp->addOrderItem($newOrder, $plan->infusion_id, $infusion_product_type, $orderPrice, 1, "Sales Made From DK Solution", "Generated Through API"); // Add Manual Payment - since CC charged with Stripe $payment = $isapp->manualPmt($newOrder, $orderPrice, $oDate, "Credit Card", "Payment via DK Solution", false); //credit // Add Affiliate in our database if ($affiliate_id) { // Get Affiliate $affiliate = Affiliate::find($affiliate_id); if (!$affiliate or empty($affiliate->email)) { $affData = $isapp->dsFind('Affiliate', 1, 0, 'Id', $affiliate_id, array('AffName', 'ContactId')); } if (!$affiliate) { $affName = !empty($affData[0]['AffName']) ? $affData[0]['AffName'] : NULL; // Save Affiliate name $affiliate = new Affiliate(); $affiliate->id = $affiliate_id; $affiliate->name = $affName; $affiliate->save(); } if ($affiliate and empty($affiliate->email)) { $affContactId = !empty($affData[0]['ContactId']) ? $affData[0]['ContactId'] : NULL; if ($affContactId) { $affContactData = $isapp->dsFind('Contact', 1, 0, 'Id', $affContactId, array('Email')); $affEmail = !empty($affContactData[0]['Email']) ? $affContactData[0]['Email'] : NULL; $affiliate->email = $affEmail; $affiliate->save(); } } // Send Commission Email to Affiliate if ($affiliate->email) { // Get earned commission $from = strtotime("midnight", time()); $to = strtotime("tomorrow", time()) - 1; $start = date('Ymd\\TH:i:s', $from); $finish = date('Ymd\\TH:i:s', $to); $commissions = $isapp->affCommissions($affiliate->id, $start, $finish); if (!empty($commissions) and is_array($commissions)) { foreach ($commissions as $commission) { if ($commission['InvoiceId'] == $newOrder) { $AffEarnedCommission = $commission['AmtEarned']; } } } // Send email to Affiliate if (!empty($AffEarnedCommission)) { $this->_send_email_commission($product->name, $plan->name, $affiliate->email, $affiliate->name, $AffEarnedCommission); } } } return $newOrder; } else { // Error // echo "Connection Failed"; return FALSE; } }
public function getTest() { //require_once app_path() . DIRECTORY_SEPARATOR . ""; require_once app_path() . "/libraries/infusionsoft/isdk.php"; $isapp = new iSDK(); // Get Affiliate ID from Cookie $affiliate_id = Cookie::get('_dks_isa'); // Create Connection if ($isapp->cfgCon("comissionTracker")) { // find contact by email $contacts = $isapp->findByEmail('*****@*****.**', array('Id', 'Email')); // If contact found if (!empty($contacts[0]['Id'])) { $contact_id = $contacts[0]['Id']; } else { // Create new contact $contactData = array('Email' => '*****@*****.**'); $contact_id = $isapp->addCon($contactData); } echo $contact_id; echo "<br><br>"; // Testing Order Through Invoice //Sets current date $currentDate = date("d-m-Y"); $oDate = $isapp->infuDate($currentDate); echo "date set<br/>"; //Creates blank order $newOrder = $isapp->blankOrder($contact_id, "New Order for Contact {$contact_id}", $oDate, NULL, $affiliate_id); echo "newOrder=" . $newOrder . "<br/>"; //$newOrder = 710; // Add Order Item - Product ID // type = 4 or 9 (Product or Subscription) $result = $isapp->addOrderItem($newOrder, 24, 4, 50.0, 1, "Sale Made From API", "Generated Through API"); echo "item added<br/>"; //print_r($result); // Add Manual Payment - since CC charged with Stripe $payment = $isapp->manualPmt($newOrder, 50.0, $oDate, "credit", "Order done through API / Stripe", false); print_r($payment); } else { echo "Connection Failed"; } //$affiliate_id = Cookie::get('_dks_isa'); //echo "hi " . app_path(); }
require_once "../../src/isdk.php"; //build our application object $app = new iSDK(); //connect to the API - change demo to be whatever your connectionName is! if ($app->cfgCon("demo")) { //action set Id number to run on the posted contact $actionId = 123; //grab our posted contact fields $contact = array('Email' => $_POST['Contact0Email'], 'FirstName' => $_POST['Contact0FirstName'], 'LastName' => $_POST['Contact0LastName']); //grab the returnURL $returnURL = $_POST['returnURL']; //dup check on email if it exists. if (!empty($contact['Email'])) { //check for existing contact; $returnFields = array('Id'); $dups = $app->findByEmail($contact['Email'], $returnFields); if (!empty($dups)) { //update contact $app->updateCon($dups[0]['Id'], $contact); //run an action set on the contact $app->runAS($dups[0]['Id'], $actionId); } else { //Add new contact $newCon = $app->addCon($contact); //run an action set on the contact $app->runAS($newCon, $actionId); } //Send them to the success page header('location: ' . $returnURL); } else { //Let them know how it is ;)
// Connected to Infusionsoft - Run Your Code Below //echo 'Connected to Infusionsoft<br>'; $data = ubobjectToArray(json_decode($_REQUEST['data_json'])); $first_name = $data['first_name'][0]; $last_name = $data['last_name'][0]; $email = $data['email'][0]; $AffiliateId = $data['ref'][0]; $IPAddress = $data['ip_address'][0]; $time_submitted = $data['time_submitted'][0]; $Source = $data['page_url'][0]; $DateSet = $data['date_submitted'][0].' '.$time_submitted; $DateSet = date('Y-m-d H:i:s', strtotime($DateSet)); $DateExpires = date('Y-m-d H:i:s', strtotime($data['date_submitted'][0].' +1 year')); sleep(2); $returnFields = array('Id',); $contact = $app->findByEmail($email, $returnFields); $ContactId = $contact[0]['Id']; $ContactId; $data = array( 'DateExpires' => $DateExpires, 'DateSet' => $DateSet, 'IPAddress' => $IPAddress, 'Info' => 'From API Unbounce', 'ContactId' => $ContactId, 'AffiliateId' => $AffiliateId, 'Type' => 2, 'Source' => $Source ); $success = $app->dsAdd("Referral", $data); //print_r($success); exit;
function NotifyCompleteProfile($email) { //this is used for appylying a infusionsoft group (tag) for customers who complete their profile. //auth.php will access this function require_once 'isdk.php'; $app = new iSDK(); if ($app->cfgCon("mps")) { //Check if the email is existing in infusionsoft $returnFields = array('Id'); $data = $app->findByEmail($email, $returnFields); if (isset($data[0])) { //If Existing, update it. $contactId = $data[0]['Id']; $app->grpAssign($contactId, 314); return true; } else { //do nothing return false; } } }
$contact->PostalCode2 = $order[29]; $contact->Phone2 = $order[30]; } else { $contact->_ShippingCompany = $order[12]; $contact->_ShippingFirstName = $order[10]; $contact->_ShippingLastName = $order[11]; $contact->Address2Street1 = $order[13]; $contact->Address2Street2 = $order[14]; $contact->City2 = $order[15]; $contact->_County2 = $order[16]; $contact->Country2 = $order[17]; $contact->PostalCode2 = $order[18]; $contact->Phone2 = $order[19]; } if ($order[9] > '') { $test = $app->findByEmail($contact->Email, array('Id')); if ($test[0]['Id'] < 1) { $contact->save(); $d = $app->dsQuery('Contact', 1, 0, array('AccountId' => $order[0]), array('Id')); $eml->optIn($contact->Email, 'API Import of existing EKM Powershop customers.'); $app->grpAssign($d[0]['Id'], $t2[0]['Id']); $app->grpAssign($d[0]['Id'], 123); // G4LOrdersDates } } } } } $found = false; /* * this is the end of the section that handles updating contacts with dup check
//*================= //* WISHLIST //*================= if ($membership === 'mojoleadmastery') { $wishlist = new wlmapiclass('http://www.mojoleadmastery.com/', '5ae8c42d96a15001cfd6b70de330b70b'); } else { if (!is_object($wishlist)) { die('Invalid membership program specified.'); } } $wishlist->return_format = 'php'; //*=============================== //* GET USER INFORMATION FROM IS //*=============================== $fields2 = array('Id', 'FirstName', 'LastName'); $IS_DATA2 = $infusion->findByEmail($email, $returnFields); print_r($IS_DATA2); $fields = array('FirstName', 'LastName', 'Email', 'Phone1', 'Company', 'Username', 'Password', '_WishListId', '_WishListLevels'); $IS_DATA = $infusion->loadCon((int) $contact_id, $fields); //*============================================== //* POST TO WISHLIST //*============================================== //ADD if ($action === 'add') { //CHECK FOR INVALID USERNAME if ($IS_DATA['Username'] == '') { //EMAIL DEFAULT $IS_DATA['Username'] = $IS_DATA['Email']; //UPDATE INFUSIONSOFT $data['Username'] = $IS_DATA['Email']; }