Inheritance: extends Infusionsoft_DataServiceBase
 public function __set($name, $value)
 {
     if ($name == 'OrderId') {
         $invoices = Infusionsoft_DataService::query(new Infusionsoft_Invoice(), array('JobId' => $value));
         $invoice = array_shift($invoices);
         $this->InvoiceId = $invoice->Id;
     } else {
         parent::__set($name, $value);
     }
 }
 public static function getSavedSearchIdFromName($savedSearchName)
 {
     $results = Infusionsoft_DataService::query(new Infusionsoft_SavedFilter(), array('FilterName' => $savedSearchName));
     if (count($results) > 0) {
         return array_shift($results);
     } else {
         return false;
     }
 }
 public function delete($app = null)
 {
     if ($this->Id > 0) {
         $result = Infusionsoft_DataService::delete($this, $this->Id, $app);
         Infusionsoft_SdkEventManager::dispatch(new Infusionsoft_SdkEvent($this, array('result' => $result)), 'DataObject.Deleted');
     } else {
         throw new Infusionsoft_Exception("Trying to delete a blank contact");
     }
     return $result;
 }
 public static function contactSearch($search)
 {
     $contacts = array();
     if (strpos($search, " ") !== false) {
         $searchParts = explode(" ", $search);
         $criteria = array('FirstName' => $searchParts[0], 'LastName' => $searchParts[1]);
         $contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), $criteria, 100);
         if (count($contacts) == 0) {
             $criteria['LastName'] = $searchParts[1] . '%';
             $contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), $criteria, 100);
         }
         if (count($contacts) == 0) {
             $criteria['FirstName'] = $searchParts[0] . '%';
             $criteria['LastName'] = $searchParts[1];
             $contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), $criteria, 100);
         }
         if (count($contacts) == 0) {
             $criteria['FirstName'] = $searchParts[0] . '%';
             $criteria['LastName'] = $searchParts[1] . '%';
             $contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), $criteria, 100);
         }
     }
     //Search By Email
     if (strpos($search, '@') !== false || count($contacts) == 0) {
         $criteria = array('Email' => $search);
         $contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), $criteria, 100);
         if (count($contacts) == 0) {
             $criteria['Email'] = $search . '%';
             $contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), $criteria, 100);
         }
     }
     if (strpos($search, "-") !== false && strpos($search, '@') == false || count($contacts) == 0) {
         $criteria = array();
         $criteria['Phone1'] = '%' . $search . '%';
         $contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), $criteria, 100);
     }
     if (count($contacts) == 0) {
         $criteria = array();
         $criteria['FirstName'] = $search;
         $contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), $criteria, 100);
     }
     if (count($contacts) == 0) {
         $criteria = array();
         $criteria['LastName'] = $search;
         $contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), $criteria, 100);
     }
     if (count($contacts) == 0) {
         $criteria = array();
         $criteria['FirstName'] = $search . '%';
         $contacts = Infusionsoft_DataService::query(new Infusionsoft_Contact(), $criteria, 100);
     }
     return $contacts;
 }
 /**
  * Copy an existing RecurringOrder to a new date and mark the old one as Inactive.
  * @param int $orderId The ID of the RecurringOrder to replicate
  * @param string $newStartDate String date of when to start the new RecurringOrder
  * @param string $nextBillDate Optional, string date of when to set the NextBillingDate on the new RecurringOrder
  * @return bool|Infusionsoft_RecurringOrder The newly created RecurringOrder object, or false if there was a problem.
  */
 public static function rescheduleRecurringOrder($orderId, $newStartDate, $nextBillDate = null)
 {
     // Attempt to load the order
     $order = Infusionsoft_DataService::query(new Infusionsoft_RecurringOrder(), array('Id' => $orderId));
     $order = array_shift($order);
     if (count($order) == 0) {
         return false;
     }
     // Create a new recurring order based on existing data
     $newOrder = new Infusionsoft_RecurringOrder();
     foreach ($order->getFields() as $field) {
         $newOrder->{$field} = $order->{$field};
     }
     $startDate = date('Ymd\\TH:i:s', strtotime($newStartDate));
     $nextBillDate = date('Ymd\\TH:i:s', strtotime($nextBillDate == null ? $newStartDate : $nextBillDate));
     // Use an optional next bill date, otherwise use the start date
     $newOrder->Id = null;
     $newOrder->StartDate = $startDate;
     $newOrder->Status = 'Active';
     $newOrder->ReasonStopped = 'This order will stop billing on the billing end date.';
     $newOrder->LastBillDate = '';
     $newOrder->PaidThruDate = '';
     //NextBillDate is set farther down
     // We will look for properly named custom fields to automatically update references
     if (in_array('_OriginalSubscriptionId', $order->getFields())) {
         $newOrder->_OriginalSubscriptionId = strval($order->Id);
     }
     $newOrder->save();
     // Wanted to limit to one save operation.  Id is required for next custom field.
     if (in_array('_NewSubscriptionId', $order->getFields())) {
         $order->_NewSubscriptionId = strval($newOrder->Id);
     }
     // The new subscription has been saved.  Make API call to change next bill date
     try {
         Infusionsoft_InvoiceService::updateJobRecurringNextBillDate($newOrder->Id, $nextBillDate);
     } catch (Exception $e) {
         CakeLog::write('error', "Problem updating next billing date on subscription.  Id: {$newOrder->Id}, Date: {$startDate}, Error: " . $e->getMessage());
     }
     // Attempt to create invoices for the subscription
     try {
         Infusionsoft_InvoiceService::createInvoiceForRecurring($newOrder->Id);
     } catch (Exception $e) {
         CakeLog::write('error', "Problem creating invoices for new subscription. Id: {$newOrder->Id}, Error: " . $e->getMessage());
     }
     // Mark original subscription as inactive
     $order->Status = 'Inactive';
     $order->ReasonStopped = "Subscription updated on " . date('m/d/Y') . " to new subscription. ID: {$newOrder->Id}";
     $order->save();
     return new Infusionsoft_RecurringOrder($newOrder->Id);
 }
 public static function queryWithOrderBy($object, $queryData, $orderByField = null, $ascending = true, $limit = 1000, $page = 0, $returnFields = false, Infusionsoft_App $app = null)
 {
     if (PHP_INT_SIZE < 8) {
         throw new Exception("This version oh php is not 64 bit it is " . PHP_INT_SIZE * 8 . ' bit.  ContactGroupAssign cannot be synced unless running on a 64bit version of php.');
     }
     Infusionsoft_ContactGroupAssign::removeField('Id');
     if (is_array($returnFields) && in_array('Id', $returnFields)) {
         unset($returnFields[array_search('Id', $returnFields)]);
         $returnFields[] = 'ContactId';
         $returnFields[] = 'GroupId';
         $returnFields = array_values($returnFields);
     }
     $results = Infusionsoft_DataService::queryWithOrderBy($object, $queryData, $orderByField, $ascending, $limit, $page, $returnFields, $app);
     Infusionsoft_ContactGroupAssign::addCustomField('Id');
     self::addCompoundKeyToResults($results);
     if ($orderByField == 'ContactId' && $ascending && count($results) > 0) {
         if ($page > 0) {
             self::removeRecordsForContactsAlreadyProcessed(self::$lastProcessedContactId, $results);
         }
         $lastRecordOfResultSet = end($results);
         $lastContactId = $lastRecordOfResultSet->ContactId;
         self::$lastProcessedContactId = $lastContactId;
         $foundLastRecordForLastContact = false;
         $extraPages = 1;
         while (!$foundLastRecordForLastContact && count($results) > 0) {
             Infusionsoft_ContactGroupAssign::removeField('Id');
             $extraResults = Infusionsoft_DataService::queryWithOrderBy($object, $queryData, $orderByField, $ascending, $limit, $page + $extraPages, $returnFields, $app);
             Infusionsoft_ContactGroupAssign::addCustomField('Id');
             self::addCompoundKeyToResults($extraResults);
             foreach ($extraResults as $extraResult) {
                 //If somehow, between calls, a lot of tags are applied, and our "last" contact gets pushed down to the second page, we need to not break because of new contacts higher up on the page.
                 if ($extraResult->ContactId <= $lastContactId) {
                     $results[] = $extraResult;
                 } else {
                     $foundLastRecordForLastContact = true;
                     break;
                 }
             }
             if (count($extraResults) == 0) {
                 $foundLastRecordForLastContact = true;
             }
             $extraPages++;
         }
         return $results;
     }
     /** @var Infusionsoft_ContactGroupAssign $result */
     return $results;
 }
 public static function getCustomField(Infusionsoft_Generated_Base $object, $name, Infusionsoft_App $app = null)
 {
     if (strpos($name, '_') === 0) {
         $name = substr($name, 1, strlen($name) - 1);
     }
     if (!property_exists($object, 'customFieldFormId')) {
         throw new Infusionsoft_Exception(get_class($object) . ' does not have Custom Fields.');
     }
     $dataFormField = new Infusionsoft_DataFormField();
     if ($object->getAppPoolAppKey() != null) {
         $dataFormField->setAppPoolAppKey($object->getAppPoolAppKey());
     }
     $conditions = array('FormId' => $object->customFieldFormId, 'Name' => $name);
     $out = parent::query(new Infusionsoft_DataFormField(), $conditions);
     return array_pop($out);
 }
 public static function queryWithOrderBy($object, $queryData, $orderByField, $ascending = true, $limit = 1000, $month = 0, $returnFields = false, Infusionsoft_App $app = null)
 {
     //Set a hard date for earliest_month_to_query so that we don't get into infinite loops trying to find commissions in the 1700's (this happens when you sync an empty application)
     if ($month == 0) {
         $firstOrder = Infusionsoft_DataService::queryWithOrderBy(new Infusionsoft_Job(), array('Id' => '%'), 'Id', true, 1);
         if (!empty($firstOrder)) {
             self::$earliest_month_to_query = $firstOrder[0]->DateCreated;
         }
     }
     if (empty(self::$earliest_month_to_query)) {
         self::$earliest_month_to_query = '2013-01-01';
     }
     //Calculate beginning of this month
     $startDate = date('Y-m-01 00:00:00', strtotime(" - {$month} months"));
     $startDate = date(Infusionsoft_Service::apiDateFormat, strtotime($startDate));
     $endDate = date('Y-m-t 23:59:59', strtotime($startDate));
     $endDate = date(Infusionsoft_Service::apiDateFormat, strtotime($endDate));
     //get an array of all affiliates
     $affiliates = self::$affiliates_cache;
     if (empty($affiliates)) {
         $page = 0;
         do {
             $affiliatesPage = Infusionsoft_DataService::query(new Infusionsoft_Affiliate(), array('Id' => '%'), 1000, $page, array('Id'), $app);
             $page += 1;
             $affiliates = array_merge($affiliates, $affiliatesPage);
         } while (sizeof($affiliatesPage) >= 1000);
     }
     //Now get all of the commissions from each one
     $objects = array();
     while (count($objects) < $limit && $startDate >= self::$earliest_month_to_query) {
         foreach ($affiliates as $affiliate) {
             if (get_class($object) == 'Infusionsoft_Commission') {
                 $objects = array_merge($objects, Infusionsoft_APIAffiliateService::affCommissions($affiliate->Id, $startDate, $endDate, $app));
             } elseif (get_class($object) == 'Infusionsoft_Clawback') {
                 $objects = array_merge($objects, Infusionsoft_APIAffiliateService::affClawbacks($affiliate->Id, $startDate, $endDate, $app));
             }
         }
         $startDate = date('Y-m-d', strtotime($startDate . '- 1 month'));
         $endDate = date('Y-m-t 23:59:59', strtotime($startDate));
         $startDate = date(Infusionsoft_Service::apiDateFormat, strtotime($startDate));
         $endDate = date(Infusionsoft_Service::apiDateFormat, strtotime($endDate));
     }
     self::$orderByField = $orderByField;
     usort($objects, array('Infusionsoft_AffiliateDataService', 'sortCommissions'));
     return $objects;
 }
 public static function getSubscriptionFromOrder($orderId)
 {
     try {
         $order = new Infusionsoft_Job($orderId);
         if (!empty($order->JobRecurringId)) {
             return new Infusionsoft_RecurringOrder($order->JobRecurringId);
         } else {
             $subscription = Infusionsoft_DataService::query(new Infusionsoft_RecurringOrder(), array('OriginatingOrderId' => $orderId));
             if (!empty($subscription)) {
                 return $subscription[0];
             } else {
                 return false;
             }
         }
     } catch (Exception $e) {
         CakeLog::write('error', 'getSusbscriptionIdForOrder failed to get the Order! orderId: ' . $orderId);
         return false;
     }
 }
 public function save($app = null)
 {
     if ($this->Id == '') {
         $invoices = Infusionsoft_DataService::query(new Infusionsoft_Invoice(), array('JobId' => $this->OrderId), 1000, 0, false, $app);
         if (count($invoices) == 0) {
             throw new Infusionsoft_Exception("Could not get invoice for order: " . $this->OrderId . " while creating adding an order item.");
         }
         /** @var Infusionsoft_Invoice $invoice */
         $invoice = array_shift($invoices);
         $result = Infusionsoft_InvoiceService::addOrderItem($invoice->Id, $this->ProductId, $this->ItemType, $this->PPU, $this->Qty, $this->ItemDescription, $this->Notes, $app);
         if (!$result) {
             throw new Infusionsoft_Exception("Couldn't save orderitem: " . json_encode($this->toArray()));
         }
         //Infusionsoft doesn't always use consecutive Ids, but it is very very very rare that the id won't be consecutive if a new record is inserted very quickly after the previous, so even though this isn't ideal, it's what we are doing.
         $newestOrderItems = Infusionsoft_DataService::queryWithOrderBy(new Infusionsoft_OrderItem(), array('OrderId' => $this->OrderId), 'Id', false, 1);
         $newestOrderItem = array_shift($newestOrderItems);
         $this->Id = $newestOrderItem->Id;
     }
     $result = parent::save($app);
     return $result;
 }
 public static function getContactListWhoHaveATagInCategory($categoryName)
 {
     $categories = Infusionsoft_DataService::query(new Infusionsoft_ContactGroupCategory(), array('CategoryName' => $categoryName));
     if (count($categories) > 0) {
         $category = array_shift($categories);
     } else {
         throw new Exception("Tag Category: " . $categoryName . " doesn't exist.");
     }
     $tags = Infusionsoft_DataService::query(new Infusionsoft_ContactGroup(), array('GroupCategoryId' => $category->Id));
     $contactList = array();
     foreach ($tags as $tag) {
         /** @var Infusionsoft_ContactGroup $tag */
         Infusionsoft_ContactGroupAssign::addCustomField("Contact.FirstName");
         Infusionsoft_ContactGroupAssign::addCustomField("Contact.LastName");
         $contacts = Infusionsoft_DataService::query(new Infusionsoft_ContactGroupAssign(), array('GroupId' => $tag->Id));
         foreach ($contacts as $contact) {
             /** @var Infusionsoft_ContactGroupAssign $contact */
             if (!isset($contactList[$contact->ContactId])) {
                 $contactList[$contact->ContactId] = $contact->__get('Contact.FirstName') . ' ' . $contact->__get('Contact.LastName');
             }
         }
     }
     return $contactList;
 }
    <input type="submit">
    <input type="hidden" name="go">
</form>

<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $dayDelta = $_GET['dayDelta'];
    if ($dayDelta < 0) {
        $start = $dayDelta;
        $end = 0;
    } else {
        $start = 0;
        $end = $dayDelta;
    }
    $startDate = $_GET['startDate'];
    $dateField = $_GET['dateField'];
    $contacts = array();
    for ($i = $start; $i <= $end; $i++) {
        $date = date('Y-m-d', strtotime($startDate) + $i * 24 * 60 * 60);
        $newContacts = Infusionsoft_DataService::queryWithOrderBy(new Infusionsoft_Contact(), array($dateField => $date . '%'), $dateField, false);
        echo 'Found ' . count($newContacts) . ' where ' . $dateField . ' is ' . $date . '<br/>';
        $contacts = array_merge($contacts, $newContacts);
    }
    var_dump($contacts);
}
?>
</body>
</html>
<form>
            table: <input type="text" name="table" value="<?php 
if (isset($_REQUEST['table'])) {
    echo htmlspecialchars($_REQUEST['table']);
}
?>
"><br/>
            id: <input type="text" name="id" value="<?php 
if (isset($_REQUEST['id'])) {
    echo htmlspecialchars($_REQUEST['id']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_DataService::delete($_REQUEST['table'], $_REQUEST['id']);
    var_dump($out);
}
<form>
            table: <input type="text" name="table" value="<?php 
if (isset($_REQUEST['table'])) {
    echo htmlspecialchars($_REQUEST['table']);
}
?>
"><br/>
            values: <input type="text" name="values" value="<?php 
if (isset($_REQUEST['values'])) {
    echo htmlspecialchars($_REQUEST['values']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_DataService::add($_REQUEST['table'], $_REQUEST['values']);
    var_dump($out);
}
<h1>Testing GetAppSetting</h1>
<pre>
<?php 
$out = Infusionsoft_DataService::getAppSetting('Product', 'trackcpu');
echo didItWorkNotEmpty($out);
?>
</pre>

<h1>Testing addCustomField</h1>
<pre>
No Test Written Yet
</pre>

<h1>Testing updateCustomField</h1>
<pre>
No Test Written Yet
</pre>

<h1>Testing getAppointmentICal</h1>
<pre>
No Test Written Yet
</pre>

<h1>Testing getAllCustomFields</h1>

<pre>
    <?php 
echo print_r(Infusionsoft_DataService::getCustomFields(new Infusionsoft_Contact()), true);
?>
</pre>
<form>
            table: <input type="text" name="table" value="<?php 
if (isset($_REQUEST['table'])) {
    echo htmlspecialchars($_REQUEST['table']);
}
?>
"><br/>
            id: <input type="text" name="id" value="<?php 
if (isset($_REQUEST['id'])) {
    echo htmlspecialchars($_REQUEST['id']);
}
?>
"><br/>
            selectedFields: <input type="text" name="selectedFields" value="<?php 
if (isset($_REQUEST['selectedFields'])) {
    echo htmlspecialchars($_REQUEST['selectedFields']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_DataService::load($_REQUEST['table'], $_REQUEST['id'], $_REQUEST['selectedFields']);
    var_dump($out);
}
 public static function getCustomFields($object, $app = null)
 {
     $fields = Infusionsoft_DataService::query(new Infusionsoft_DataFormField(), array('FormId' => $object->customFieldFormId), 1000, 0, false, $app);
     $returnData = array();
     foreach ($fields as $field) {
         $field->Name = '_' . $field->Name;
         $returnData[$field->Name] = array($field);
     }
     $fields = $returnData;
     return $fields;
 }
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $object = "Infusionsoft_" . $_REQUEST['table'];
    $object = new $object();
    $searchData = array($_REQUEST['searchFieldName'] => $_REQUEST['searchFieldData']);
    if ($_REQUEST['queryFieldData'] !== '') {
        $queryData = array($_REQUEST['queryFieldName'] => $_REQUEST['queryFieldData']);
    } else {
        $queryData = array();
    }
    if ($_REQUEST['limit'] == '') {
        $limit = 1000;
    } else {
        $limit = $_REQUEST['limit'];
    }
    if ($_REQUEST['page'] == '') {
        $page = 0;
    } else {
        $page = $_REQUEST['page'];
    }
    if ($_REQUEST['selectedFields'] == '') {
        $returnFields = false;
    } else {
        $returnFields = $_REQUEST['selectedFields'];
    }
    $out = Infusionsoft_DataService::search($object, $searchData, $queryData, $limit, $page, $returnFields);
    var_dump($out);
}
}
?>
"><br/>
            fieldName: <input type="text" name="fieldName" value="<?php 
if (isset($_REQUEST['fieldName'])) {
    echo htmlspecialchars($_REQUEST['fieldName']);
}
?>
"><br/>
            fieldValue: <input type="text" name="fieldValue" value="<?php 
if (isset($_REQUEST['fieldValue'])) {
    echo htmlspecialchars($_REQUEST['fieldValue']);
}
?>
"><br/>
            selectedFields: <input type="text" name="selectedFields" value="<?php 
if (isset($_REQUEST['selectedFields'])) {
    echo htmlspecialchars($_REQUEST['selectedFields']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_DataService::findByField($_REQUEST['table'], $_REQUEST['limit'], $_REQUEST['page'], $_REQUEST['fieldName'], $_REQUEST['fieldValue'], $_REQUEST['selectedFields']);
    var_dump($out);
}
<?php

include '../infusionsoft.php';
$linkedContactTypes = Infusionsoft_DataService::query(new Infusionsoft_LinkedContactType(), array('Id' => '%'));
var_dump($linkedContactTypes);
$firstType = array_shift($linkedContactTypes);
$contactA = new Infusionsoft_Contact(68665);
$contactB = new Infusionsoft_Contact(68667);
Infusionsoft_ContactService::linkContacts($contactA->Id, $contactB->Id, $firstType->Id);
//What happens with an Invalid Link...
$out = Infusionsoft_ContactService::linkContacts($contactA->Id, 12039875, $firstType->Id);
var_dump($out);
//What happens with an Invalid Link...
$out = Infusionsoft_ContactService::linkContacts($contactA->Id, 12039875, $firstType->Id);
var_dump($out);
//
//$linkedContacts = Infusionsoft_DataService::query(new Infusionsoft_LinkedContact(), array('Id' => '%'));
//
//var_dump($linkedContacts);
$linkedContacts = Infusionsoft_ContactService::listLinkedContacts($contactB->Id);
var_dump($linkedContacts);
Beispiel #21
0
 * 			client, Ian Ashland of Ashland Chemicals.
 * 
 * Inputs : All input is extracted via .csv file reads
 * 
 * Outputs: All output will be found in the form of resulting data being
 * 			imported into the appropriate Infusionsoft app.
 * 
******************************************************************************/
// Include required support files
include_once 'EKMConfig.php';
require_once 'Infusionsoft/infusionsoft.php';
require_once 'src/isdk.php';
// Instantiate all required objects
$thisapp = new iSDK();
$thisapp->cfgCon($appname, $appkey);
$data = new Infusionsoft_DataService();
/*$order=new Infusionsoft_Job();

$order->JobTitle='This is a test order';
$order->ContactId=50005;
$order->ShipCity='Phoenix';
$order->ShipFirstName='Joe';
$order->ShipLastName='Blow';
$order->ShipPhone='6026168008';
$order->ShipState='AZ';
$order->ShipStreet1='3825 W Anthem Way #3151';
$order->ShipZip='85086';
$order->save();*/
/*
//$order=$thisapp->blankOrder(50005,'This is a test order',$thisapp->infuDate('20151111'),0,0);
$order=$thisapp->dsAdd('Job',array('ContactId'=>50005,'JobTitle'=>'This is a test order'));
 public static function chargeInvoiceArbitraryAmountUsingPayPlan($invoiceId, $cardId, $amount, $merchantAccountId, $paymentNotes = 'API Arbitrary Payment')
 {
     $result = false;
     //Get Invoice info so we can set the temporary PayPlan to match the amount we want to charge
     $invoice = new Infusionsoft_Invoice($invoiceId);
     if ($amount + $invoice->TotalPaid <= $invoice->InvoiceTotal) {
         $temporaryFirstPayment = $amount + $invoice->TotalPaid;
     } else {
         $temporaryFirstPayment = $invoice->InvoiceTotal - $invoice->TotalPaid;
     }
     //Get current PayPlan info so we can set it back after taking the payment
     $payPlan = Infusionsoft_DataService::query(new Infusionsoft_PayPlan(), array('InvoiceId' => $invoiceId));
     if (!empty($payPlan)) {
         $payPlan = reset($payPlan);
         /**
          * @var Infusionsoft_PayPlan $payPlan
          */
         $payPlanItems = Infusionsoft_DataService::queryWithOrderBy(new Infusionsoft_PayPlanItem(), array('PayPlanId' => $payPlan->Id), 'DateDue', true);
         $payPlanStartDate = $payPlan->StartDate;
         $payPlanFirstPaymentAmount = $payPlan->FirstPayAmt;
         $numberOfPayments = count($payPlanItems) - 1;
         $payPlanItemDueDate1 = null;
         $daysBetweenPayments = 1;
         foreach ($payPlanItems as $index => $payPlanItem) {
             if ($index == 0) {
                 continue;
             }
             /**
              * @var Infusionsoft_PayPlanItem $payPlanItem
              */
             if ($payPlanItemDueDate1 == null) {
                 $payPlanItemDueDate1 = $payPlanItem->DateDue;
             } else {
                 $daysBetweenPayments = round((strtotime($payPlanItem->DateDue) - strtotime($payPlanItemDueDate1)) / 60 / 60 / 24);
                 break;
             }
         }
         if ($payPlanItemDueDate1 == null) {
             $payPlanItemDueDate1 = $payPlanStartDate;
         }
     } else {
         //If there is no PayPlan, then just set the order to the default of all due up front
         CakeLog::write('warning', 'PayPlan not found for InvoiceId: ' . $invoiceId . ' PayPlan will be set to the default');
         $payPlanFirstPaymentAmount = $invoice->InvoiceTotal;
         $payPlanStartDate = $invoice->DateCreated;
         $numberOfPayments = 0;
         $payPlanItemDueDate1 = $invoice->DateCreated;
         $daysBetweenPayments = 1;
     }
     try {
         Infusionsoft_InvoiceService::addPaymentPlan($invoiceId, 0, $cardId, $merchantAccountId, 1, 1, $temporaryFirstPayment, Infusionsoft_App::formatDate(date('Y-m-d')), Infusionsoft_App::formatDate(date('Y-m-d', strtotime(' + 1 day'))), 1, 1);
         $result = Infusionsoft_InvoiceService::chargeInvoice($invoiceId, $paymentNotes, $cardId, $merchantAccountId, false);
     } catch (Exception $e) {
         CakeLog::write('error', 'Failed to charge invoice arbitrary amount! InvoiceId: ' . $invoiceId . ' Infusionsoft error: ' . $e->getMessage());
     }
     try {
         Infusionsoft_InvoiceService::addPaymentPlan($invoiceId, 0, $cardId, $merchantAccountId, 1, 3, $payPlanFirstPaymentAmount, $payPlanStartDate, $payPlanItemDueDate1, $numberOfPayments, $daysBetweenPayments);
     } catch (Exception $e) {
         CakeLog::write('error', 'Failed to reset payment plan after chargeInvoiceArbitraryAmount! InvoiceId: ' . $invoiceId . ' PayPlan Details: ' . json_encode(compact('payPlanFirstPaymentAmount', 'payPlanStartDate', 'payPlanItemDueDate1', 'numberOfPayments', 'daysBetweenPayments')));
     }
     return $result;
 }
    $searchData = array($_REQUEST['searchFieldName'] => $_REQUEST['searchFieldData']);
    if ($_REQUEST['queryFieldData'] !== '') {
        $queryData = array($_REQUEST['queryFieldName'] => $_REQUEST['queryFieldData']);
    } else {
        $queryData = array();
    }
    if ($_REQUEST['ascending'] == "false") {
        $ascending = false;
    } elseif ($_REQUEST['ascending'] == "true") {
        $ascending = true;
    } else {
        $ascending = true;
    }
    if ($_REQUEST['limit'] == '') {
        $limit = 1000;
    } else {
        $limit = $_REQUEST['limit'];
    }
    if ($_REQUEST['page'] == '') {
        $page = 0;
    } else {
        $page = $_REQUEST['page'];
    }
    if ($_REQUEST['selectedFields'] == '') {
        $returnFields = false;
    } else {
        $returnFields = $_REQUEST['selectedFields'];
    }
    $out = Infusionsoft_DataService::searchWithOrderBy($object, $_REQUEST['orderBy'], $searchData, $queryData, $ascending, $limit, $page, $returnFields);
    var_dump($out);
}
include 'object_editor_all_tables.php';
include '../tests/testUtils.php';
?>
Depending upon the number of purchases, emails, tags, and follow-up sequences this contact has, this may take a while (even as long as 5 minutes).<br/><?php 
renderLoadForm();
if (!empty($_GET['Id'])) {
    $contact = new Infusionsoft_Contact($_GET['Id']);
    $orders = Infusionsoft_DataService::query(new Infusionsoft_Job(), array('ContactId' => $contact->Id));
    $order_items = array();
    $invoices = array();
    foreach ($orders as $order) {
        $order_items[$order->Id] = Infusionsoft_DataService::query(new Infusionsoft_OrderItem(), array('OrderId' => $order->Id));
        $invoices[$order->Id] = Infusionsoft_DataService::query(new Infusionsoft_Invoice(), array('JobId' => $order->Id));
        if (is_array($invoices[$order->Id]) && count($invoices[$order->Id]) > 0) {
            $invoice_items[$order->Id] = Infusionsoft_DataService::query(new Infusionsoft_InvoiceItem(), array('InvoiceId' => $invoices[$order->Id][0]->Id));
            $invoice_payments[$order->Id] = Infusionsoft_DataService::query(new Infusionsoft_InvoicePayment(), array('InvoiceId' => $invoices[$order->Id][0]->Id));
            if (count($invoice_payments[$order->Id] > 0)) {
                foreach ($invoice_payments[$order->Id] as $invoice_payment) {
                    $invoice_payment_payments[$invoice_payment->Id] = new Infusionsoft_Payment($invoice_payment->PaymentId);
                }
            }
        }
    }
    ?>
<h1>Contact</h1><?php 
    dumpObject($contact);
    foreach ($orders as $order) {
        ?>
<h1>Order</h1><?php 
        dumpObject($order, 1);
        ?>
function getInvoicesForContact($contactId)
{
    $invoices = Infusionsoft_DataService::findByField(new Infusionsoft_Invoice(), 'ContactId', $contactId);
    return $invoices;
}
<?php

include "../infusionsoft.php";
include 'testUtils.php';
$out = Infusionsoft_DataService::findByField(new Infusionsoft_CProgram(), 'Id', '1', '1', '0', array('Id'));
var_dump($out);
    echo $table;
    ?>
"><?php 
    echo $table;
    ?>
</option><?php 
}
?>
    </select><br/>
    <input type="submit"/>
</form>
<?php 
if (isset($_GET['object'])) {
    $class_name = "Infusionsoft_" . $_GET['object'];
    $object = new $class_name();
    $objects = Infusionsoft_DataService::query(new $class_name(), array('Id' => '%'));
    ?>
        <table>
            <thead>
                <tr>
                    <?php 
    foreach ($object->getFields() as $field) {
        ?>
<th><?php 
        echo $field;
        ?>
</th><?php 
    }
    ?>
                </tr>
            </thead>
<form>
            CChargeId: <input type="text" name="cChargeId" value="<?php 
if (isset($_REQUEST['cChargeId'])) {
    echo htmlspecialchars($_REQUEST['cChargeId']);
}
?>
"><br/>
    <input type="submit">
    <input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_DataService::query(new Infusionsoft_Payment(), array('ChargeId' => $_REQUEST['cChargeId']), 'Id');
    var_dump($out);
}
<form>
            username: <input type="text" name="username" value="<?php 
if (isset($_REQUEST['username'])) {
    echo htmlspecialchars($_REQUEST['username']);
}
?>
"><br/>
            passwordHash: <input type="text" name="passwordHash" value="<?php 
if (isset($_REQUEST['passwordHash'])) {
    echo htmlspecialchars($_REQUEST['passwordHash']);
}
?>
"><br/>
    <input type="submit">
<input type="hidden" name="go">
</form>
<?php 
include '../infusionsoft.php';
include 'testUtils.php';
if (isset($_REQUEST['go'])) {
    $out = Infusionsoft_DataService::authenticateUser($_REQUEST['username'], $_REQUEST['passwordHash']);
    var_dump($out);
}
 public function getDataFromSource()
 {
     $data = Infusionsoft_DataService::query($this->object, $this->conditions, $this->limit, $this->page, $this->returnFields, $this->app);
     return $data;
 }