/**
  * Return an array of enabled spreedly subscriptions
  * 
  * @return array
  */
 public static function getSubscriptions()
 {
     if (empty(self::$_subscriptionPlans)) {
         $result = SpreedlyCommon::curlRequest("/subscription_plans.xml", "get");
         if ($result->code == '200') {
             $subscriptions = array();
             $plans = new SimpleXmlElement($result->response);
             foreach ($plans as $plan) {
                 $subscription = new SpreedlySubscription();
                 $subscription->setData($plan);
                 /// Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Spreedly subscription enabled: " . $subscription->enabled);
                 if ('true' == (string) $subscription->enabled) {
                     $subscriptions[] = $subscription;
                 }
             }
             self::$_subscriptionPlans = $subscriptions;
         } else {
             throw new SpreedlyException('Spreedly Subscription: Unable to retrieve remote list of subscriptions', 66003);
         }
     }
     return self::$_subscriptionPlans;
 }
Beispiel #2
0
 public static function productsPage()
 {
     $data = array();
     $subscriptions = array('0' => 'None');
     if (class_exists('SpreedlySubscription')) {
         $spreedlySubscriptions = SpreedlySubscription::getSubscriptions();
         foreach ($spreedlySubscriptions as $s) {
             $subs[(int) $s->id] = (string) $s->name;
         }
         if (count($subs)) {
             asort($subs);
             foreach ($subs as $id => $name) {
                 $subscriptions[$id] = $name;
             }
         }
     } else {
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Not loading Spreedly data because Spreedly class has not been loaded");
     }
     $data['subscriptions'] = $subscriptions;
     $view = Cart66Common::getView('admin/products.php', $data);
     echo $view;
 }
 public function getSubscriptionAmount()
 {
     $amount = 0;
     if ($subId = $this->getSpreedlySubscriptionId()) {
         $subscription = new SpreedlySubscription();
         $subscription->load($subId);
         if (!$subscription->hasFreeTrial()) {
             $amount = (double) $subscription->amount;
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Subscription amount for subscription id: {$subId} = " . $subscription->amount);
         }
     }
     return $amount;
 }
Beispiel #4
0
 public function drawFeatureLevelMetaBox($post)
 {
     if (CART66_PRO) {
         $plans = array();
         $featureLevels = array();
         $data = array();
         // Load feature levels defined in Spreedly if available
         if (class_exists('SpreedlySubscription')) {
             $sub = new SpreedlySubscription();
             $subs = $sub->getSubscriptions();
             foreach ($subs as $s) {
                 // $plans[] = array('feature_level' => (string)$s->featureLevel, 'name' => (string)$s->name);
                 $plans[(string) $s->name] = (string) $s->featureLevel;
                 $featureLevels[] = (string) $s->featureLevel;
             }
         }
         // Load feature levels defined in PayPal subscriptions
         $sub = new Cart66PayPalSubscription();
         $subs = $sub->getSubscriptionPlans();
         foreach ($subs as $s) {
             $plans[$s->name] = $s->featureLevel;
             $featureLevels[] = $s->featureLevel;
         }
         // Load feature levels defined in Membership products
         foreach (Cart66Product::getMembershipProducts() as $membership) {
             $plans[$membership->name] = $membership->featureLevel;
             $featureLevels[] = $membership->featureLevel;
         }
         // Put unique feature levels in alphabetical order
         if (count($featureLevels)) {
             $featureLevels = array_unique($featureLevels);
             sort($featureLevels);
             $savedPlanCsv = get_post_meta($post->ID, '_cart66_subscription', true);
             $savedFeatureLevels = empty($savedPlanCsv) ? array() : explode(',', $savedPlanCsv);
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Cart66 Saved Plans: {$savedPlanCsv} -- " . print_r($savedFeatureLevels, true));
             $data = array('featureLevels' => $featureLevels, 'plans' => $plans, 'saved_feature_levels' => $savedFeatureLevels);
         }
         $box = Cart66Common::getView('pro/views/feature-level-meta-box.php', $data);
         echo $box;
     }
 }
 /**
  * Return a description of the subscription rate such as $10 / 1 month
  * 
  * @return string
  */
 public function getSubscriptionPriceSummary()
 {
     $desc = '';
     if ($this->isSpreedlySubscription()) {
         $subscription = new SpreedlySubscription();
         $subscription->load($this->spreedlySubscriptionId);
         $desc = $subscription->getPriceDescription();
     }
     return $desc;
 }