コード例 #1
0
 /**
  * Add an Infusionsoft_App to the app pool (If necessary) and set it as the default app.
  * @param Infusionsoft_App $app
  * @param null $appKey
  * @return Infusionsoft_App The Infusionsoft_App added as the default
  */
 public static function setDefaultApp(Infusionsoft_App $app, $appKey = null)
 {
     $existingApp = self::getApp($app->getHostname());
     $app = $existingApp == null ? self::addApp($app, $appKey) : $existingApp;
     if (self::$apps['default'] != $app) {
         self::$apps['default'] = $app;
     }
     return self::$apps['default'];
 }
コード例 #2
0
 public function __construct(Infusionsoft_Generated_Base $object, array $conditions = array(), $ttl = 300, $limit = 1000, $page = 0, $returnFields = false, Infusionsoft_App $app = null)
 {
     $this->object = $object;
     $this->conditions = $conditions;
     $this->limit = $limit;
     $this->page = $page;
     $this->returnFields = $returnFields;
     $this->app = $app;
     $this->app_name = $app == null ? Infusionsoft_AppPool::getApp()->getHostname() : $app->getHostname();
     parent::__construct('objects_' . $this->object->getTable() . '_' . $this->app_name . '_' . md5(http_build_query($conditions) . $this->limit . $this->page . ($returnFields ? http_build_query($returnFields) : '') . $this->app_name), 600, dirname(__FILE__) . '/cache/');
 }
コード例 #3
0
 public function __construct(Infusionsoft_Generated_Base $object, array $conditions = array(), $ttl = 300, $limit = 1000, $page = 0, $returnFields = false, Infusionsoft_App $app = null)
 {
     $this->object = $object;
     $this->conditions = $conditions;
     $this->limit = $limit;
     $this->page = $page;
     $this->returnFields = $returnFields;
     $this->app = $app;
     $this->app_name = $app == null ? Infusionsoft_AppPool::getApp()->getHostname() : $app->getHostname();
     $directory = dirname(__FILE__) . '/cache';
     // SmartCache class checks the Cache engine being used and shortens the "directory" if it is being used as the key in a caching system instead of as a file-name in a file-based cache.
     parent::__construct('objects_' . $this->object->getTable() . '_' . $this->app_name . '_' . md5(http_build_query($conditions) . $this->limit . $this->page . ($returnFields ? http_build_query($returnFields) : '') . $this->app_name), 600, $directory);
 }
コード例 #4
0
 public function query($params)
 {
     list($table, $limit, $page, $queryData, $returnFields) = $params;
     $this->createTableIfNotExists($table);
     $results = array();
     foreach ($this->tables[$table] as $row) {
         $include = true;
         foreach ($queryData as $fieldName => $fieldValue) {
             if ((!isset($row[$fieldName]) || !$this->emulateMySqlLike($fieldValue, $row[$fieldName])) && !(!isset($row[$fieldName]) && $fieldValue == '~null~')) {
                 $include = false;
             }
         }
         if ($include) {
             foreach ($row as $field => $value) {
                 if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/", $value)) {
                     $row[$field] = Infusionsoft_App::formatDate($value);
                 }
             }
             $results[] = $row;
         }
     }
     $resultPages = array();
     $pageNumber = 0;
     foreach ($results as $result) {
         $resultPages[$pageNumber][] = $result;
         if (count($resultPages[$pageNumber]) == $limit) {
             $pageNumber++;
         }
     }
     if (!array_key_exists($page, $resultPages)) {
         return array();
     }
     return $resultPages[$page];
 }
コード例 #5
0
 public static function processAuthenticationScopeAndCode($scope, $code)
 {
     $parts = explode("|", $scope);
     $scope = array_shift($parts);
     $appDomain = array_shift($parts);
     $response = static::getToken($code);
     if (isset($response['error'])) {
         throw new Exception($response['error_description']);
     }
     /** @var Infusionsoft_App $app */
     $app = Infusionsoft_AppPool::getApp($appDomain);
     if ($app == null) {
         $app = new Infusionsoft_App($appDomain);
     }
     $app->updateAndSaveTokens($response['access_token'], $response['refresh_token'], $response['expires_in']);
     return true;
 }
コード例 #6
0
 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;
 }