protected function prepareSubscription() { if (!isset($_POST['Subscription'])) { new \Error(4, 'Subscription'); } $subs = json_decode($_POST['Subscription'], true); //var_dump($subs); if ($subs['DepartCity'] == NULL || $subs['ArriveCity'] == NULL || $subs['StartDate'] == NULL || $subs['EndDate'] == NULL) { new \Error(4, array('DepartCity', 'ArriveCity', 'StartDate', 'EndDate')); } $tiSubs = new \Subscription(); $tiSubs->attributes = $subs; $subs_adp = $tiSubs->search(); if ($subs_adp->itemCount) { $this->_subs = $subs_adp->getData()[0]; $this->_subs->Count = $this->_subs->Count + 1; } else { /* $lowestPrice = new \D_LowestPrice; $tiSubs->CurrentPrice = (int)$lowestPrice->searchFlight($tiSubs); */ $this->_subs = $tiSubs; } try { if (!$this->_subs->save()) { new \Error(5, null, json_encode($this->_subs->getErrors())); } } catch (Exception $e) { new \Error(5, NULL, $e->getMessage()); } }
public function displaySubscriptions($tab, $user, $ui) { $db = JFactory::getDBO(); include_once JPATH_SITE . '/components/com_acctexp/acctexp.class.php'; $dateFormat = $this->params->get('dateFormat', "m/d/Y"); $meta_user = new metaUser($user->id); $html_return = '' . '<table class="aeceventlog_table" style="border-collapse: collapse">' . '<tr class="aeceventlog_row_header">' . '<th width="30%" class="text-center">Plan</th>' . '<th width="10%" class="text-center">Primary</th>' . '<th width="10%" class="text-center">Status</th>' . '<th width="10%" class="text-center">Started</th>' . '<th width="20%" class="text-center">Ends</th>' . '</tr>'; $subscriptions = $meta_user->getAllSubscriptions(); $subscr_info = $this->getAllCurrentSubscriptionsInfoComplete($user->id); foreach ($subscriptions as $i => $subscriptionid) { $subscription = new Subscription(); $subscription->load($subscriptionid); $plan_name = $subscr_info[$i]->name == '' ? "Excluded" : $subscr_info[$i]->name; $html_return .= '<tr>' . '<td width="30%" class="text-center">' . $plan_name . '</td>' . '<td width="10%" class="text-center">' . ($subscription->primary ? "Yes" : "No") . '</td>' . '<td width="10%" class="text-center">' . $this->getIconHtml($subscription->status) . ' ' . $subscription->status . '</td>' . '<td width="10%" class="text-center">' . date($dateFormat, strtotime($subscription->signup_date)) . '</td>'; $html_return .= '<td width="10%" class="text-center">'; if (!empty($subscription->lifetime)) { $html_return .= JText::_('AEC_ISLIFETIME'); } else { if ($subscription->recurring && in_array($subscription->status, array('Active', 'Trial'))) { $html_return .= JText::_('AEC_WILLRENEW') . ': ' . date($dateFormat, strtotime($subscription->expiration)); } else { $html_return .= date($dateFormat, strtotime($subscription->expiration)); } } $html_return .= '</td></tr>'; } $html_return .= '</table>'; return $html_return; }
/** * Check stripe data. * * @access public * @return void */ public function run() { $paymentGateway = Payment_gateways::findOneActiveBySlug('stripe'); if ($paymentGateway->exists()) { \Stripe\Stripe::setApiKey($paymentGateway->getFieldValue('apiKey')); $subscriptions = new Subscription(); $allSubscriptions = $subscriptions->where('status', Subscription::STATUS_ACTIVE)->get(); /* @var Subscription $_subscription */ foreach ($allSubscriptions as $_subscription) { $end = DateTime::createFromFormat('Y-m-d', $_subscription->end_date); if ($end->getTimestamp() > strtotime('now')) { $paymentTransaction = $_subscription->payment_transaction->get(); if ($paymentTransaction->system == 'stripe') { $user = new User($_subscription->user_id); try { $customer = \Stripe\Customer::retrieve($user->stripe_id); $subscription = $customer->subscriptions->retrieve($paymentTransaction->payment_id); } catch (Exception $e) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . $e->getMessage()); } if (!isset($subscription) || $subscription->status != 'active') { $_subscription->deactivate(); $_subscription->save(); } } } } log_message('CRON_SUCCESS', __FUNCTION__); } }
/** * Fetch subscriptions that should be disallowed by a block */ function get_blocked_subs() { $query = "SELECT subscription.* " . "FROM subscription " . "INNER JOIN profile_block " . "ON blocker=subscribed " . "AND blocked=subscriber"; $subscription = new Subscription(); $subscription->query($query); return $subscription; }
protected function body() { if (!$this->userHasPrivileges(User::groupsJoinPrivate, User::groupsJoinPublic, User::groupsRequest)) { return false; } if (!$this->isInputValid(array('id' => 'isIndex'))) { return false; } $groupId = $this->getParams('id'); /** * @var $group \Group */ $group = Repositories::findEntity(Repositories::Group, $groupId); // Calculate privileges of the user $user = User::instance(); $canJoinPrivate = User::instance()->hasPrivileges(User::groupsJoinPrivate); $groupIsPrivate = $group->getType() == \Group::TYPE_PRIVATE; $hasSufficientPrivileges = $groupIsPrivate && ($canJoinPrivate || $user->hasPrivileges(User::groupsRequest)) || !$groupIsPrivate && $user->hasPrivileges(User::groupsJoinPublic); if (!$hasSufficientPrivileges) { return $this->death(StringID::InsufficientPrivileges); } $status = $canJoinPrivate || !$groupIsPrivate ? \Subscription::STATUS_SUBSCRIBED : \Subscription::STATUS_REQUESTED; // Put into database $subscription = new \Subscription(); $subscription->setGroup($group); $subscription->setUser(User::instance()->getEntity()); $subscription->setStatus($status); Repositories::persistAndFlush($subscription); return true; }
/** * The function sends emails with new articles to subscribers. * * @access public */ public function send() { $Subscription = new Subscription(); foreach ($Subscription->findList() as $Subscription) { $Sent = new Article_Sent(); $Sent->MailerId = $this->Id; $Sent->Email = $Subscription->Email; $Email = new Email_Article($Subscription); $Email->setArticles($this->getArticles()); if ($Email->send()) { $Sent->Result = 1; } else { $Sent->Result = 0; } $Sent->saveNew(); } foreach ($this->getArticles() as $Article) { $Article = $Article->findItem(array('Id = ' . $Article->Id)); if ($Article) { $Article->InSubscription = 0; $Article->save(); } } $this->SentAt = time(); $this->save(); }
/** * Check stripe data. * * @access public * @return void */ public function run() { try { $paymentGateway = Payment_gateways::findOneActiveBySlug('stripe'); if ($paymentGateway->exists()) { \Stripe\Stripe::setApiKey($paymentGateway->getFieldValue('apiKey')); $subscriptions = new Subscription(); $allSubscriptions = $subscriptions->get(); /* @var Subscription $_subscription */ foreach ($allSubscriptions as $_subscription) { if ($_subscription->end_date <= strtotime('now')) { $paymentTransaction = $_subscription->payment_transaction->get(); if ($paymentTransaction->system == 'stripe') { $user = new User($_subscription->user_id); $customer = \Stripe\Customer::retrieve($user->stripe_id); $subscription = $customer->subscriptions->retrieve($paymentTransaction->payment_id); if ($subscription->status == 'active') { $date = new DateTime(); $date->setTimestamp($subscription->current_period_end); $_subscription->end_date = $date->format('Y-m-d'); $_subscription->activate(); $_subscription->save(); } } } } log_message('CRON_SUCCESS', __FUNCTION__); } else { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'No Stripe Api key.'); } } catch (Exception $e) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . $e->getMessage()); } }
function destroy($args, $apidata) { parent::handle($args); if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) { $this->clientError(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']); return; } $id = $apidata['api_arg']; # We can't subscribe to a remote person, but we can unsub $other = $this->get_profile($id); $user = $apidata['user']; $sub = new Subscription(); $sub->subscriber = $user->id; $sub->subscribed = $other->id; if ($sub->find(true)) { $sub->query('BEGIN'); $sub->delete(); $sub->query('COMMIT'); } else { $this->clientError(_('You are not friends with the specified user.'), 403, $apidata['content-type']); return; } $type = $apidata['content-type']; $this->init_document($type); $this->show_profile($other, $type); $this->end_document($type); }
public function executeSubscription(sfWebRequest $request) { $params = $request->getParameter('email'); $form = new SubscriptionForm(); if ($request->isMethod('post')) { $email = $params; try { if (empty($obj)) { $obj = new Subscription(); $obj->setEmail($email)->save(); } } catch (Exception $e) { } $contacts = UserPeer::getAllContact(); $backEmail = $contacts->getEmail(); $message = "E-mail: " . $email . "<br/>"; // почта, на которую придет письмо $mail_to = $backEmail; // тема письма $subject = "Новый подписчик"; // заголовок письма $headers = "Content-type: text/html; charset=utf-8\r\n"; // кодировка письма // отправляем письмо mail($mail_to, $subject, $message, $headers); } $this->form = $form; }
public function create($data, $save = true) { $sbc = new Subscription($this, $data); if ($save) { $sbc->save(); } return $sbc; }
/** * Display subscriptions of user */ public function index() { $subscription = new Subscription(); $subscriptions = $subscription->getUserSubscriptions($this->c_user->id, true); CssJs::getInst()->add_css('dev/admin.css')->c_js('settings/subscriptions', 'index'); $this->template->set('subscriptions', $subscriptions); $this->template->set('active_subscription', $this->c_user->getLastSubscription()); $this->template->render(); }
protected function sendAll($IDs) { $sub = new Subscription(); foreach ($IDs as $ID) { if (!$ID) { continue; } echo "{$ID} sent to " . $sub->send_bulk($ID) . " email(s)\n"; } }
public function onSuccess(Course $course) { $this->em->persist($course); $subscription = new Subscription(); $user = $this->container->get('security.context')->getToken()->getUser(); $subscription->setUser($user); $subscription->setCourse($course); $this->em->persist($subscription); $this->em->flush(); $this->get('session')->setFlash('notice', 'Your Course is created! & Subscription OK !'); }
private function subscriptionDetailsFromRow($row) { $subscription = new Subscription(); $subscription->storeId = $row['storeId']; $subscription->pss_sp_id = $row['pss_sp_id']; $subscription->sp_plan_name = $row['sp_plan_name']; $subscription->sp_caption = $row['sp_caption']; $subscription->sp_description = $row['sp_description']; $subscription->sp_jed_id = $row['sp_jed_id']; $subscription->unsetValues(array('storeId', 'created_on', 'updated_on', 'created_by', 'updated_by')); return $subscription; }
/** * 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; }
function getSubscribers() { $subs = array(); $sub = new Subscription(); $sub->subscribed = $this->user->id; if ($sub->find()) { while ($sub->fetch()) { if ($sub->subscriber != $this->user->id) { $subs[] = clone $sub; } } } return $subs; }
public function actionIndex() { $subscription = Subscription::model()->findAll(); $data = UserSubscription::model()->getListUserSub(); $dataProvider = new CActiveDataProvider('Subscription'); $this->render('index', array('subscription' => $subscription, 'data' => $data, 'dataProvider' => $dataProvider)); }
public function unload() { $subscriptions = \Subscription::all(); $columns = ["email", "created_at"]; $firstRow = ["Email", "Дата создания"]; return $this->unloadToCsv($subscriptions, ['columns' => $columns, 'firstRow' => $firstRow]); }
public function loadModel($id) { if (($model = Subscription::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
public function subscribe() { $eventId = Utils::lookupEventId(trim(Input::get('event'))); if (!$eventId) { return Response::json('', 500); } $subscription = Subscription::where('account_id', '=', Auth::user()->account_id)->where('event_id', '=', $eventId)->first(); if (!$subscription) { $subscription = new Subscription(); $subscription->account_id = Auth::user()->account_id; $subscription->event_id = $eventId; } $subscription->target_url = trim(Input::get('target_url')); $subscription->save(); return Response::json('{"id":' . $subscription->id . '}', 201); }
public function __construct($publicationId, $userId) { $this->m_dbObject = Subscription::GetSubscriptions($publicationId, $userId); if (count($this->m_dbObject) == 0) { $this->m_dbObject = array(); } }
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); }
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')))); } }
public function updateEventsTable() { $events = EventModel::all(); foreach ($events as $event) { $count = Subscription::findEventCount($event->id); EventModel::fixEventCounts($event->id, $count); } }
public function subscriptions() { $datas = array(); foreach (Subscription::TotalPerMonth()->get() as $item) { $datas[$item->period] = $item->total; } return View::make('stats.subscriptions', array('datas' => $datas)); }
public function delete($id) { if (Subscription::destroy($id)) { return Redirect::route('subscription_list')->with('mSuccess', 'Cet abonnement a bien été supprimé'); } else { return Redirect::route('subscription_list')->with('mError', 'Impossible de supprimer cet abonnement'); } }
public function save() { $body = ['format' => $this->format, 'tenant' => $this->tenant, 'url' => $this->url, 'secret' => $this->secret, 'events' => $this->events]; if ($this->basicAuth) { $body['auth'] = $this->basicAuth; } if ($this->legacy) { $body['legacy'] = $this->legacy; } $response = $this->client->send('POST', '/subscribers/' . $this->subscriberId . '/subscriptions', $body); $subscription = new Subscription($response['id'], $response['subscriber_id'], $response['tenant'], $response['format'], $response['url']); $subscription->setUsesBasicAuth($response['uses_basic_auth']); if ($response['legacy']) { $subscription->setLegacyPayload($response['legacy']['payload']); } return $subscription; }
function subs_unsubscribe_to($user, $other) { try { Subscription::cancel($user->getProfile(), $other); return true; } catch (Exception $e) { return $e->getMessage(); } }
/** * Complete a pending subscription, as we've got approval of some sort. * * @return Subscription */ public function complete() { $subscriber = Profile::staticGet('id', $this->subscriber); $subscribed = Profile::staticGet('id', $this->subscribed); $sub = Subscription::start($subscriber, $subscribed, Subscription::FORCE); if ($sub) { $this->delete(); } return $sub; }
/** * Check paypal data. If acccount expired - block it * * @access public * @return void */ public function run() { try { $subscriptions = new Subscription(); $allSubscriptions = $subscriptions->get(); foreach ($allSubscriptions as $_subscription) { if ($_subscription->end_date <= strtotime('now')) { $user = new User($_subscription->user_id); if ($user->id != null) { $user->active = false; $user->save(); } } } log_message('CRON_SUCCESS', __FUNCTION__); } catch (Exception $e) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . $e->getMessage()); } }