/**
  * Create a Spreedly subscription.
  * 
  * @param int $accountId The primary key from the Cart66 accounts table associated with this subscription
  * @param int $subscriptionId The id of the spreedly subscription plan
  * @param mixed $paymentMethod Either 'on-file' or a SpreedlyCreditCard object
  */
 public function createSpreedlySubscription($accountId, $subscriptionId, $productId, $paymentMethod = 'on-file')
 {
     $subscriptionCreated = false;
     if (is_numeric($accountId) && $accountId > 0) {
         if (!$this->loadByAccountId($accountId)) {
             $this->accountId = $accountId;
         }
         $subscriber = new SpreedlySubscriber();
         $subscriber->hydrate($this->_getSpreedlySubscriberDataArray());
         $subscription = new SpreedlySubscription($subscriptionId);
         if ('free_trial' == strtolower((string) $subscription->planType)) {
             $subscriberData = $subscriber->toArray(true);
             // prune the empty data
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Creating a new subscriber before assigning free trial. " . print_r($subscriberData, true));
             $subscriber->create($subscriberData);
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Preparing to assign free trial plan ({$subscriptionId}) to new subscriber: " . print_r($subscriber->toArray(), true));
             $subscriber->assignFreeTrialPlan($subscriptionId);
         } else {
             $invoice = new SpreedlyInvoice();
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Creating a Spreedly invoice for subscription id: {$subscriptionId}");
             $invoice->create($subscriber, $subscriptionId);
             $invoice->pay($paymentMethod);
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Spreedly invoice has been created and paid.");
         }
         $this->productId = $productId;
         $this->save();
     }
 }