public function testCreateUpdateListCancel()
 {
     $planID = 'gold-' . self::generateRandomString(20);
     self::retrieveOrCreatePlan($planID);
     $customer = self::createTestCustomer();
     $sub = Subscription::create(array('plan' => $planID, 'customer' => $customer->id));
     $this->assertSame($sub->status, 'active');
     $this->assertSame($sub->plan->id, $planID);
     $sub->quantity = 2;
     $sub->save();
     $sub = Subscription::retrieve($sub->id);
     $this->assertSame($sub->status, 'active');
     $this->assertSame($sub->plan->id, $planID);
     $this->assertSame($sub->quantity, 2);
     // Update the quantity parameter one more time
     $sub = Subscription::update($sub->id, array("quantity" => 3));
     $this->assertSame($sub->status, 'active');
     $this->assertSame($sub->plan->id, $planID);
     $this->assertSame($sub->quantity, 3);
     $subs = Subscription::all(array('customer' => $customer->id, 'plan' => $planID, 'limit' => 3));
     $this->assertSame(get_class($subs->data[0]), 'Stripe\\Subscription');
     $sub->cancel(array('at_period_end' => true));
     $sub = Subscription::retrieve($sub->id);
     $this->assertSame($sub->status, 'active');
     $this->assertTrue($sub->cancel_at_period_end);
 }
 function create()
 {
     if ($_POST) {
         unset($_POST['send']);
         unset($_POST['_wysihtml5_mode']);
         /*$next_payment = human_to_unix($_POST['issue_date'].' 00:00');
         		$next_payment = strtotime($_POST['frequency'], $next_payment);
         		
         		$_POST['next_payment'] = date("Y-m-d", $next_payment);*/
         $_POST['next_payment'] = $_POST['issue_date'];
         $subscription = Subscription::create($_POST);
         $new_subscription_reference = $_POST['reference'] + 1;
         $subscription_reference = Setting::first();
         $subscription_reference->update_attributes(array('subscription_reference' => $new_subscription_reference));
         if (!$subscription) {
             $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_create_subscription_error'));
         } else {
             $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_create_subscription_success'));
         }
         redirect('subscriptions');
     } else {
         $this->view_data['next_reference'] = Subscription::last();
         $this->view_data['companies'] = Company::find('all', array('conditions' => array('inactive=?', '0')));
         $this->theme_view = 'modal';
         $this->view_data['title'] = $this->lang->line('application_create_subscription');
         $this->view_data['form_action'] = 'subscriptions/create';
         $this->content_view = 'subscriptions/_subscription';
     }
 }
 public function run()
 {
     $faker = Faker\Factory::create();
     DB::table('subscriptions')->truncate();
     for ($i = 0; $i < 60; $i++) {
         Subscription::create(array('user_id' => $faker->randomNumber(1, 20), 'service_id' => $faker->randomNumber(1, 1), 'option_id' => $faker->randomNumber(1, 4), 'billing_cycle_id' => $faker->randomNumber(1, 4), 'expire_date' => $faker->dateTimeThisYear, 'status' => $faker->randomElement(array('Active', 'Stopped', 'Inactive', 'Cancelled'))));
     }
 }
Ejemplo n.º 4
0
 public function testAll()
 {
     $planID = 'gold-' . self::randomString();
     self::retrieveOrCreatePlan($planID);
     $customer = self::createTestCustomer();
     $sub = Subscription::create(array('customer' => $customer->id, 'plan' => $planID));
     $planID_2 = 'gold-2-' . self::randomString();
     self::retrieveOrCreatePlan($planID_2);
     $sub_2 = Subscription::create(array('customer' => $customer->id, 'plan' => $planID_2));
     $subs = Subscription::all(array('limit' => 2, 'offset' => 0));
     $this->assertSame(2, count($subs['data']));
 }
 /**
  * Performs the action; returns true on success, false on error.
  *
  * @param $p_context - the current context object
  * @return bool
  */
 public function takeAction(CampContext &$p_context)
 {
     $p_context->default_url->reset_parameter('f_' . $this->m_name);
     $p_context->url->reset_parameter('f_' . $this->m_name);
     if (PEAR::isError($this->m_error)) {
         return false;
     }
     $auth = Zend_Auth::getInstance();
     $user = new User($p_context->user->identifier);
     if ($user->getUserId() != $auth->getIdentity() || $user->getUserId() == 0) {
         $this->m_error = new PEAR_Error('You must be logged in to create or edit your subscription.', ACTION_EDIT_SUBSCRIPTION_ERR_NO_USER);
         return false;
     }
     $subscriptions = Subscription::GetSubscriptions($p_context->publication->identifier, $user->getUserId());
     if (count($subscriptions) == 0) {
         $subscription = new Subscription();
         $created = $subscription->create(array('IdUser' => $user->getUserId(), 'IdPublication' => $p_context->publication->identifier, 'Active' => 'Y', 'Type' => $this->m_subscriptionType == 'trial' ? 'T' : 'P'));
         if (!$created) {
             $this->m_error = new PEAR_Error('Internal error (code 1)', ACTION_EDIT_SUBSCRIPTION_ERR_INTERNAL);
             exit(1);
         }
     } else {
         $subscription = $subscriptions[0];
     }
     $publication = new Publication($p_context->publication->identifier);
     $subscriptionDays = $this->computeSubscriptionDays($publication, $p_context->publication->subscription_time);
     $startDate = new Date();
     $columns = array('StartDate' => $startDate->getDate(), 'Days' => $subscriptionDays, 'PaidDays' => $this->m_subscriptionType == 'trial' ? $subscriptionDays : 0, 'NoticeSent' => 'N');
     if ($this->m_properties['subs_by_type'] == 'publication') {
         $sectionsList = Section::GetUniqueSections($p_context->publication->identifier);
         foreach ($sectionsList as $section) {
             $this->m_sections[] = $section['id'];
         }
     }
     foreach ($this->m_languages as $languageId) {
         foreach ($this->m_sections as $sectionNumber) {
             $subsSection = new SubscriptionSection($subscription->getSubscriptionId(), $sectionNumber, $languageId);
             $subsSection->create($columns);
         }
     }
     $fields = array('SubsType', 'tx_subs', 'nos', 'unitcost', 'unitcostalllang', 'f_substype', 'cb_subs', 'subs_all_languages', 'suma', 'tpl', 'subscription_language');
     foreach (CampRequest::GetInput() as $field => $value) {
         if (strncmp('tx_subs', $field, strlen('tx_subs')) == 0) {
             $fields[] = $field;
         }
     }
     foreach ($fields as $fieldName) {
         $p_context->default_url->reset_parameter($fieldName);
         $p_context->url->reset_parameter($fieldName);
     }
     $this->m_error = ACTION_OK;
     return true;
 }
 public static function handleEndpointRequest(Endpoint $Endpoint)
 {
     $Subscription = $Endpoint->getSubscription($GLOBALS['Session']->Person);
     if (!$Subscription && ($_SERVER['REQUEST_METHOD'] == 'POST' || $_SERVER['REQUEST_METHOD'] == 'PUT')) {
         $Subscription = Subscription::create(['EndpointID' => $Endpoint->ID, 'PersonID' => $GLOBALS['Session']->PersonID], true);
         return static::respond('subscriptionCreated', ['data' => $Subscription, 'success' => true]);
     } elseif ($Subscription && $_SERVER['REQUEST_METHOD'] == 'DELETE') {
         $Subscription->destroy();
         $Subscription = null;
         return static::respond('subscriptionDeleted', ['data' => $Subscription, 'success' => true]);
     }
     return static::respond('subscription', ['data' => $Subscription]);
 }
Ejemplo n.º 7
0
 public function testCreateUpdateListCancelWithItems()
 {
     $planID = 'gold-' . self::generateRandomString(20);
     self::retrieveOrCreatePlan($planID);
     $customer = self::createTestCustomer();
     $sub = Subscription::create(array('customer' => $customer->id, 'items' => array(array('plan' => $planID))));
     $this->assertSame(count($sub->items->data), 1);
     $this->assertSame($sub->items->data[0]->plan->id, $planID);
     $sub = Subscription::update($sub->id, array('items' => array(array('plan' => $planID))));
     $this->assertSame(count($sub->items->data), 2);
     $this->assertSame($sub->items->data[0]->plan->id, $planID);
     $this->assertSame($sub->items->data[1]->plan->id, $planID);
 }
Ejemplo n.º 8
0
 public function testCreateUpdateRetrieveListCancel()
 {
     $planID = 'gold-' . self::generateRandomString(20);
     self::retrieveOrCreatePlan($planID);
     $customer = self::createTestCustomer();
     $sub = Subscription::create(array('plan' => $planID, 'customer' => $customer->id));
     $subItem = SubscriptionItem::create(array('plan' => $planID, 'subscription' => $sub->id));
     $this->assertSame($subItem->plan->id, $planID);
     $subItem->quantity = 2;
     $subItem->save();
     $subItem = SubscriptionItem::retrieve($subItem->id);
     $this->assertSame($subItem->quantity, 2);
     // Update the quantity parameter one more time
     $subItem = SubscriptionItem::update($subItem->id, array('quantity' => 3));
     $this->assertSame($subItem->quantity, 3);
     $subItems = SubscriptionItem::all(array('subscription' => $sub->id, 'limit' => 3));
     $this->assertSame(get_class($subItems->data[0]), 'Stripe\\SubscriptionItem');
     $this->assertSame(2, count($subItems->data));
     $subItem->delete();
     $this->assertTrue($subItem->deleted);
 }
Ejemplo n.º 9
0
 try {
     new Subscription($email);
     $created = true;
 } catch (Exception $e) {
     $created = false;
 }
 /**
  * Checks if the e-mail already exists.
  */
 if ($created) {
     $tpl->showError($lang['already_exists']);
 }
 /**
  * Adds the subscription to the database.
  */
 $subscription = Subscription::create($email);
 /**
  * Checks if the subscription was created correctly.
  */
 if ($subscription) {
     /**
      * Sets the template's variables.
      */
     $tpl->assign('page_title', $lang['subscription_added']);
     $tpl->assign('email', $email);
     /**
      * Shows the success message.
      */
     $tpl->display('subscription_added.html');
 } else {
     /**
Ejemplo n.º 10
0
 function do_main()
 {
     $iSubscriptionType = SubscriptionEvent::subTypes('Folder');
     if (Subscription::exists($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType)) {
         $_SESSION['KTErrorMessage'][] = _kt("You are already subscribed to this folder");
     } else {
         $oSubscription = new Subscription($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType);
         $res = $oSubscription->create();
         if ($res) {
             $_SESSION['KTInfoMessage'][] = _kt("You have been subscribed to this folder");
         } else {
             $_SESSION['KTErrorMessage'][] = _kt("There was a problem subscribing you to this folder");
         }
     }
     controllerRedirect('browse', 'fFolderId=' . $this->oFolder->getId());
     exit(0);
 }
Ejemplo n.º 11
0
 public function subscribe($user_id)
 {
     $validator = Validator::make(array('id' => $user_id), array('id' => 'numeric'));
     if ($validator->fails()) {
         return $this->respondInsufficientPrivileges($validator->messages()->all());
     }
     $category_id = Input::get('category_id');
     if (Subscription::where('category_id', '=', $category_id)->first()) {
         return $this->respondInsufficientPrivileges('Already subscribed');
     }
     if ($category_id) {
         $subscription = Subscription::create(array('user_id' => $user_id, 'category_id' => $category_id));
         return $this->respond(array('user_id' => $user_id, 'category_id' => $category_id, 'id' => $subscription['id']));
     }
     return $this->respondNotFound();
 }
Ejemplo n.º 12
0
 /**
  * Subscribes the user to the document
  *
  * @author KnowledgeTree Team
  * @access public
  * @return boolean|object $result SUCCESS Boolean result of operation | FAILURE - a pear error object
  */
 public function subscribe()
 {
     if ($this->isSubscribed()) {
         return TRUE;
     }
     $subscriptionType = SubscriptionEvent::subTypes('Document');
     $user = $this->ktapi->get_user();
     $document = $this->document;
     $subscription = new Subscription($user->getId(), $document->getId(), $subscriptionType);
     $result = $subscription->create();
     if (PEAR::isError($result)) {
         return $result->getMessage();
     }
     if ($result) {
         return $result;
     }
     return $_SESSION['errorMessage'];
 }
Ejemplo n.º 13
0
}
$subsType = 'T';
if ($f_subscription_type != "T") {
	$subsType = 'P';
}

if ($f_publication_id <= 0) {
	camp_html_display_error("Unable to create the subscription: please select a publication.",
		"/$ADMIN/users/subscriptions/add.php?f_user_id=$f_user_id");
	exit;
}

$subscription = new Subscription();
$created = $subscription->create(array(
	'IdUser' => $f_user_id,
	'IdPublication' => $f_publication_id,
	'Active' => $f_subscription_active,
	'Type' => $subsType));

if (!$created) {
	$errorMsgs[] = getGS('The subscription could not be added.')
				.' '.getGS("Please check if there isn't another subscription to the same publication.");
} else {
        $logtext = getGS('Subscription added for user #$1 (Publication: $2, Active: $3, Type: $4)',
			 $f_user_id, $f_publication_id, $f_subscription_active, $subsType);
        Log::Message($logtext, null, 181);
}

if ($created && ($f_add_sections_now == 'Y')) {
	$columns = array('StartDate' => $f_subscription_start_date,
			  'Days' => $f_subscription_days,
Ejemplo n.º 14
0
 public function testCustomerSubscriptionAllRetrieve()
 {
     $planID = 'gold-' . self::randomString();
     self::retrieveOrCreatePlan($planID);
     $customer = self::createTestCustomer();
     $subscription = Subscription::create(array('customer' => $customer->id, 'plan' => $planID));
     $planID_2 = 'gold-2-' . self::randomString();
     self::retrieveOrCreatePlan($planID_2);
     $subscription_2 = Subscription::create(array('customer' => $customer->id, 'plan' => $planID_2));
     $customerRetrive = Customer::retrieve($customer->id);
     $subscriptions = $customerRetrive->subscriptions->all();
     $this->assertSame($subscription_2->id, $subscriptions['data'][0]->id);
     $this->assertSame($subscription->id, $subscriptions['data'][1]->id);
     $this->assertSame(2, count($subscriptions['data']));
     $this->assertSame($customer->id, $subscriptions['data'][0]->customer);
     $this->assertSame($planID_2, $subscriptions['data'][0]->plan->id);
     $subscriptionRetrieve = $customerRetrive->subscriptions->retrieve($subscription->id);
     $this->assertSame($subscription->id, $subscriptionRetrieve->id);
     $this->assertSame($planID, $subscriptionRetrieve->plan->id);
 }