function _buildListArray(&$lists, $state) { $db = JFactory::getDbo(); $config = OSMembershipHelper::getConfig(); $sql = 'SELECT id, title FROM #__osmembership_plans WHERE published = 1 ORDER BY ordering '; $db->setQuery($sql); $options = array(); $options[] = JHtml::_('select.option', 0, JText::_('OSM_ALL_PLANS'), 'id', 'title'); $options = array_merge($options, $db->loadObjectList()); $lists['plan_id'] = JHtml::_('select.genericlist', $options, 'plan_id', ' class="inputbox" onchange="submit();" ', 'id', 'title', $state->plan_id); $options = array(); $options[] = JHtml::_('select.option', 0, JText::_('OSM_ALL_SUBSCRIPTIONS')); $options[] = JHtml::_('select.option', 1, JText::_('OSM_NEW_SUBSCRIPTION')); $options[] = JHtml::_('select.option', 2, JText::_('OSM_SUBSCRIPTION_RENEWAL')); $options[] = JHtml::_('select.option', 3, JText::_('OSM_SUBSCRIPTION_UPGRADE')); $lists['subscription_type'] = JHtml::_('select.genericlist', $options, 'subscription_type', ' class="inputbox" onchange="submit();" ', 'value', 'text', $state->subscription_type); $options = array(); $options[] = JHtml::_('select.option', -1, JText::_('OSM_ALL')); $options[] = JHtml::_('select.option', 0, JText::_('OSM_PENDING')); $options[] = JHtml::_('select.option', 1, JText::_('OSM_ACTIVE')); $options[] = JHtml::_('select.option', 2, JText::_('OSM_EXPIRED')); $options[] = JHtml::_('select.option', 3, JText::_('OSM_CANCELLED_PENDING')); $options[] = JHtml::_('select.option', 4, JText::_('OSM_CANCELLED_REFUNDED')); $lists['published'] = JHtml::_('select.genericlist', $options, 'published', ' class="inputbox" onchange="submit();" ', 'value', 'text', $state->published); $this->config = $config; return true; }
function display($tpl = null) { $db = JFactory::getDbo(); $item = $this->get('Data'); //Get list of subscription records $sql = 'SELECT a.*, b.title AS plan_title, b.lifetime_membership, b.enable_renewal, b.recurring_subscription' . ' FROM #__osmembership_subscribers AS a' . ' INNER JOIN #__osmembership_plans AS b' . ' ON a.plan_id = b.id' . ' WHERE a.profile_id=' . $item->id . ' ORDER BY a.id DESC '; $db->setQuery($sql); $items = $db->loadObjectList(); //Form fields $rowFields = OSMembershipHelper::getProfileFields(0, true, $item->language); $data = OSMembershipHelper::getProfileData($item, 0, $rowFields); $form = new RADForm($rowFields); $form->setData($data)->bindData(); //Trigger third party add-on JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); //Trigger plugins $results = $dispatcher->trigger('onProfileDisplay', array($item)); $this->item = $item; $this->config = OSMembershipHelper::getConfig(); $this->plugins = $results; $this->items = $items; $this->form = $form; parent::display($tpl); }
/** * Run when a membership activated * @param PlanOsMembership $row */ function onMembershipActive($row) { $db = JFactory::getDbo(); $config = OSMembershipHelper::getConfig(); if ($row->user_id > 0 && !$config->send_activation_email) { $user = JFactory::getUser($row->user_id); $user->set('block', 0); $user->save(true); } return true; }
function _buildListArray(&$lists, $item) { $db = JFactory::getDbo(); $config = OSMembershipHelper::getConfig(); $sql = 'SELECT id, title FROM #__osmembership_plans WHERE published = 1 ORDER BY ordering '; $db->setQuery($sql); $options = array(); $options[] = JHtml::_('select.option', 0, JText::_('OSM_ALL_PLANS'), 'id', 'title'); $options = array_merge($options, $db->loadObjectList()); $lists['plan_id'] = JHtml::_('select.genericlist', $options, 'plan_id', ' class="inputbox" ', 'id', 'title', $item->plan_id); //Subscription status $options = array(); $options[] = JHtml::_('select.option', -1, JText::_('OSM_ALL')); $options[] = JHtml::_('select.option', 0, JText::_('OSM_PENDING')); $options[] = JHtml::_('select.option', 1, JText::_('OSM_ACTIVE')); $options[] = JHtml::_('select.option', 2, JText::_('OSM_EXPIRED')); $options[] = JHtml::_('select.option', 3, JText::_('OSM_CANCELLED_PENDING')); $options[] = JHtml::_('select.option', 4, JText::_('OSM_CANCELLED_REFUNDED')); $lists['published'] = JHtml::_('select.genericlist', $options, 'published', ' class="inputbox" ', 'value', 'text', $item->published); //Get list of payment methods $sql = 'SELECT name, title FROM #__osmembership_plugins WHERE published=1 ORDER BY ordering'; $db->setQuery($sql); $options = array(); $options[] = JHtml::_('select.option', '', JText::_('OSM_PAYMENT_METHOD'), 'name', 'title'); $options = array_merge($options, $db->loadObjectList()); $lists['payment_method'] = JHtml::_('select.genericlist', $options, 'payment_method', ' class="inputbox" ', 'name', 'title', $item->payment_method); $rowFields = OSMembershipHelper::getProfileFields($item->plan_id, true, $item->language); $data = array(); if ($item->id) { $data = OSMembershipHelper::getProfileData($item, $item->plan_id, $rowFields); $setDefault = false; } else { $setDefault = true; } if (!isset($data['country']) || !$data['country']) { $data['country'] = $config->default_country; } $form = new RADForm($rowFields); $form->setData($data)->bindData($setDefault); //Custom fields processing goes here if ($item->plan_id) { $sql = 'SELECT lifetime_membership FROM #__osmembership_plans WHERE id=' . $item->plan_id; $db->setQuery($sql); $item->lifetime_membership = (int) $db->loadResult(); } else { $item->lifetime_membership = 0; } $this->config = $config; $this->form = $form; return true; }
function _buildListArray(&$lists, $state) { $config = OSMembershipHelper::getConfig(); $options = array(); $options[] = JHtml::_('select.option', -1, JText::_('OSM_ALL')); $options[] = JHtml::_('select.option', 0, JText::_('OSM_PENDING')); $options[] = JHtml::_('select.option', 1, JText::_('OSM_ACTIVE')); $options[] = JHtml::_('select.option', 2, JText::_('OSM_EXPIRED')); $options[] = JHtml::_('select.option', 3, JText::_('OSM_CANCELLED_PENDING')); $options[] = JHtml::_('select.option', 4, JText::_('OSM_CANCELLED_REFUNDED')); $lists['published'] = JHtml::_('select.genericlist', $options, 'published', ' class="inputbox" onchange="submit();" ', 'value', 'text', $state->published); $this->config = $config; return true; }
/** * Process payment * */ function processPayment($row, $data) { $Itemid = JRequest::getint('Itemid'); $config = OSMembershipHelper::getConfig(); OSMembershipHelper::sendEmails($row, $config); $db = JFactory::getDbo(); $sql = 'SELECT subscription_complete_url FROM #__osmembership_plans WHERE id=' . $row->plan_id; $db->setQuery($sql); $subscriptionCompleteURL = $db->loadResult(); if ($subscriptionCompleteURL) { JFactory::getApplication()->redirect($subscriptionCompleteURL); } else { JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_osmembership&view=complete&act=' . $row->act . '&subscription_code=' . $row->subscription_code . '&Itemid=' . $Itemid, false, false)); } }
function display($tpl = null) { $items = $this->get('Data'); //Process content plugin in the description for ($i = 0, $n = count($items); $i < $n; $i++) { $item = $items[$i]; $item->description = JHtml::_('content.prepare', $item->description); } $pagination = $this->get('Pagination'); $Itemid = JRequest::getInt('Itemid', 0); $config = OSMembershipHelper::getConfig(); $this->assignRef('config', $config); $this->assignRef('items', $items); $this->assignRef('pagination', $pagination); $this->assignRef('Itemid', $Itemid); parent::display($tpl); }
function display($tpl = null) { $db = JFactory::getDbo(); $user = JFactory::getUser(); if (!$user->id) { $return = JRoute::_('index.php?option=com_osmembership&view=renewmembership&Itemid=' . JRequest::getInt('Itemid')); JFactory::getApplication()->redirect('index.php?option=com_users&view=login&return=' . base64_encode($return), JText::_('OSM_LOGIN_TO_RENEW_MEMBERSHIP')); } $config = OSMembershipHelper::getConfig(); $Itemid = JRequest::getInt('Itemid'); $query = $db->getQuery(true); $query->select('a.*, b.username')->from('#__osmembership_subscribers AS a ')->leftJoin('#__users AS b ON a.user_id=b.id')->where('is_profile=1')->where("(a.email='{$user->email}' OR a.user_id={$user->id})"); $db->setQuery($query); $item = $db->loadObject(); if (!$item) { JFactory::getApplication()->redirect('index.php', JText::_('OSM_DONOT_HAVE_SUBSCRIPTION_RECORD_TO_RENEW')); } //Get renew and upgrade options $sql = 'SELECT DISTINCT plan_id FROM #__osmembership_subscribers WHERE profile_id=' . $item->id . ' AND (published = 1 OR published = 2)'; $db->setQuery($sql); $planIds = $db->loadColumn(); //Check to see whether the user can renew or not $canRenew = false; foreach ($planIds as $planId) { $sql = 'SELECT recurring_subscription, enable_renewal FROM #__osmembership_plans WHERE id=' . $planId; $db->setQuery($sql); $plan = $db->loadObject(); if (!$plan->recurring_subscription && $plan->enable_renewal) { $canRenew = true; break; } } if (!$canRenew) { JFactory::getApplication()->redirect('index.php', JText::_('OSM_NO_RENEW_OPTIONS_AVAILABLE')); } //Load js file to support state field dropdown JFactory::getDocument()->addScript(JUri::base(true) . '/components/com_osmembership/assets/js/paymentmethods.js'); //Need to get subscriptions information of the user $this->Itemid = $Itemid; $this->planIds = $planIds; $this->canRenew = $canRenew; $this->config = $config; parent::display($tpl); }
function display($tpl = null) { $config = OSMembershipHelper::getConfig(); $Itemid = JRequest::getInt('Itemid', 0); $item = $this->get('Data'); if (!in_array($item->access, JFactory::getUser()->getAuthorisedViewLevels())) { JFactory::getApplication()->redirect('index.php', JText::_('OSM_NOT_ALLOWED_PLAN')); } $taxRate = OSMembershipHelper::calculateTaxRate($item->id); if ($config->show_price_including_tax && $taxRate > 0) { $item->price = $item->price * (1 + $taxRate / 100); $item->trial_amount = $item->trial_amount * (1 + $taxRate / 100); } $item->short_description = JHtml::_('content.prepare', $item->short_description); $item->description = JHtml::_('content.prepare', $item->description); $this->item = $item; $this->Itemid = $Itemid; $this->config = $config; parent::display($tpl); }
function display($tpl = null) { $user = JFactory::getUser(); $config = OSMembershipHelper::getConfig(); $Itemid = JRequest::getInt('Itemid', 0); $item = $this->get('Data'); if ($item->user_id != $user->get('id')) { $app = JFactory::getApplication(); $app->redirect('index.php', JText::_('OSM_INVALID_ACTION')); } //Form $rowFields = OSMembershipHelper::getProfileFields($item->plan_id, true, $item->language); $data = OSMembershipHelper::getProfileData($item, $item->plan_id, $rowFields); $form = new RADForm($rowFields); $form->setData($data)->bindData(); $this->Itemid = $Itemid; $this->config = $config; $this->item = $item; $this->form = $form; parent::display($tpl); }
function display($tpl = null) { $user = JFactory::getUser(); $userId = $user->get('id'); if (!$userId) { $Itemid = JRequest::getInt('Itemid'); $returnUrl = JRoute::_('index.php?option=com_osmembership&view=subscriptions&Itemid=' . $Itemid); $app = JFactory::getApplication(); $url = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($returnUrl)); $app->redirect($url, JText::_('OSM_PLEASE_LOGIN')); } $config = OSMembershipHelper::getConfig(); $Itemid = JRequest::getInt('Itemid'); $items = $this->get('Data'); $pagination = $this->get('Pagination'); $this->items = $items; $this->Itemid = $Itemid; $this->config = $config; $this->pagination = $pagination; parent::display($tpl); }
function display($tpl = null) { $user = JFactory::getUser(); $db = JFactory::getDbo(); $config = OSMembershipHelper::getConfig(); $Itemid = JRequest::getInt('Itemid'); $query = $db->getQuery(true); $query->select('a.*, b.username')->from('#__osmembership_subscribers AS a ')->leftJoin('#__users AS b ON a.user_id=b.id')->where('is_profile=1')->where("(a.email='{$user->email}' OR user_id={$user->id})"); $db->setQuery($query); $item = $db->loadObject(); if (!$item) { JFactory::getApplication()->redirect('index.php', JText::_('OSM_DONOT_HAVE_SUBSCRIPTION_RECORD_TO_UPGRADE')); } // Get upgrade options $query->clear(); $query->select('DISTINCT plan_id')->from('#__osmembership_subscribers')->where('profile_id = ' . $item->id)->where('published = 1'); $db->setQuery($query); $planIds = $db->loadColumn(); $query->clear(); $query->select('*')->from('#__osmembership_upgraderules')->where('from_plan_id IN (' . implode(',', $planIds) . ')')->order('from_plan_id'); $db->setQuery($query); $upgradeRules = $db->loadObjectList(); if (!count($upgradeRules)) { JFactory::getApplication()->redirect('index.php', JText::_('OSM_NO_UPGRADE_OPTIONS_AVAILABLE')); } $query->clear(); $query->select('*')->from('#__osmembership_plans')->where('published = 1'); $db->setQuery($query); $plans = $db->loadObjectList('id'); // Load js file to support state field dropdown JFactory::getDocument()->addScript(JUri::base(true) . '/components/com_osmembership/assets/js/paymentmethods.js'); // Need to get subscriptions information of the user $this->Itemid = $Itemid; $this->planIds = $planIds; $this->upgradeRules = $upgradeRules; $this->config = $config; $this->plans = $plans; parent::display($tpl); }
function display($tpl = null) { if (!JFactory::getUser()->authorise('core.view_members', 'com_osmembership')) { JFactory::getApplication()->redirect('index.php', JText::_('OSM_NOT_ALLOW_TO_VIEW_MEMBERS')); return; } $state = $this->get('State'); $fields = OSMembershipHelper::getProfileFields($state->id, true); for ($i = 0, $n = count($fields); $i < $n; $i++) { if (!$fields[$i]->show_on_members_list) { unset($fields[$i]); } } $this->items = $this->get('Data'); $this->fieldsData = $this->get('fieldsData'); $this->fields = $fields; $this->Itemid = JFactory::getApplication()->input->getInt('Itemid'); $this->config = OSMembershipHelper::getConfig(); $this->pagination = $this->get('Pagination'); $this->state = $state; parent::display($tpl); }
function display($tpl = null) { $config = OSMembershipHelper::getConfig(); $Itemid = JRequest::getInt('Itemid'); $items = $this->get('Data'); $pagination = $this->get('Pagination'); for ($i = 0, $n = count($items); $i < $n; $i++) { $item = $items[$i]; $taxRate = OSMembershipHelper::calculateTaxRate($item->id); if ($config->show_price_including_tax && $taxRate > 0) { $item->price = $item->price * (1 + $taxRate / 100); $item->trial_amount = $item->trial_amount * (1 + $taxRate / 100); } $item->short_description = JHtml::_('content.prepare', $item->short_description); $item->description = JHtml::_('content.prepare', $item->description); } $this->pagination = $pagination; $this->items = $items; $this->Itemid = $Itemid; $this->config = $config; $this->categoryId = JRequest::getInt('id'); parent::display($tpl); }
/** * Verify recrrung payment * */ function verifyRecurringPayment() { $ret = $this->_validate(); if ($ret) { $config = OSMembershipHelper::getConfig(); $id = $this->_data['custom']; $transactionId = $this->_data['txn_id']; $amount = $this->_data['mc_gross']; $txnType = $this->_data['txn_type']; $subscrId = $this->_data['subscr_id']; if ($amount < 0) { return false; } $row = JTable::getInstance('OsMembership', 'Subscriber'); switch ($txnType) { case 'subscr_signup': $row->load($id); if (!$row->id) { return false; } $published = $row->published; if (!$published) { $row->transaction_id = $transactionId; $row->payment_date = date('Y-m-d H:i:s'); $row->published = 1; $row->store(); OSMembershipHelper::sendEmails($row, $config); JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onMembershipActive', array($row)); } break; case 'subscr_payment': $row->load($id); if (!$row->id) { return false; } $db = JFactory::getDbo(); $sql = 'SELECT * FROM #__osmembership_plans WHERE id=' . $row->plan_id; $db->setQuery($sql); $rowPlan = $db->loadObject(); $row->payment_made = $row->payment_made + 1; $row->store(); if ($rowPlan->trial_duration && $rowPlan->trial_amount == 0 || $row->payment_made > 1) { $process = true; } else { $process = false; } if ($process) { $row->id = 0; $row->created_date = JFactory::getDate()->toSql(); $row->invoice_number = 0; $price = $rowPlan->price; $maxDate = null; if ($row->user_id > 0) { $sql = 'SELECT MAX(to_date) FROM #__osmembership_subscribers WHERE user_id=' . $row->user_id . ' AND plan_id=' . $row->plan_id . ' AND published=1'; $db->setQuery($sql); $maxDate = $db->loadResult(); } if ($maxDate) { $date = JFactory::getDate($maxDate); $row->from_date = $date->add(new DateInterval('P1D'))->toSql(); } else { $date = JFactory::getDate(); $row->from_date = $date->toSql(); } $row->to_date = $date->add(new DateInterval('P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit))->toSql(); $row->act = 'renew'; $row->amount = $price; //Calculate coupon discount if ($row->coupon_id) { $sql = 'SELECT * FROM #__osmembership_coupons WHERE id=' . $row->coupon_id; $db->setQuery($sql); $coupon = $db->loadObject(); if ($coupon) { if ($coupon->coupon_type == 0) { $row->discount_amount = $price * $coupon->discount / 100; } else { $row->discount_amount = min($coupon->discount, $price); } } } else { $row->discount_amount = 0; } if ($rowPlan->tax_rate > 0) { $row->tax_amount = round(($price - $row->discount_amount) * $rowPlan->tax_rate / 100, 2); } else { $row->tax_amount = 0; } $row->gross_amount = $row->amount - $row->discount_amount + $row->tax_amount; $row->published = 1; $row->store(); $sql = "INSERT INTO #__osmembership_field_value(field_id, field_value, subscriber_id)" . " SELECT field_id,field_value, {$row->id}" . " FROM #__osmembership_field_value WHERE subscriber_id={$id}"; $db->setQuery($sql); $db->execute(); JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onMembershipActive', array($row)); OSMembershipHelper::sendEmails($row, $config); } break; } return true; } else { return false; } }
function display($tpl = null) { $db = JFactory::getDbo(); $user = JFactory::getUser(); if (!$user->id) { $return = JRoute::_('index.php?option=com_osmembership&view=profile&Itemid=' . JRequest::getInt('Itemid')); JFactory::getApplication()->redirect('index.php?option=com_users&view=login&return=' . base64_encode($return), JText::_('OSM_LOGIN_TO_EDIT_PROFILE')); } $config = OSMembershipHelper::getConfig(); $Itemid = JRequest::getInt('Itemid'); $item = $this->get('Data'); if (!$item) { $redirectURL = OSMembershipHelper::getViewUrl(array('categories', 'plans', 'plan', 'register')); if (!$redirectURL) { $redirectURL = 'index.php'; } JFactory::getApplication()->redirect('index.php', JText::_('OSM_DONOT_HAVE_SUBSCRIPTION_RECORD')); } //Get subscriptions history require_once JPATH_COMPONENT . '/models/subscriptions.php'; $model = JModelLegacy::getInstance('Subscriptions', 'OSMembershipModel'); $items = $model->getData(); //Form $rowFields = OSMembershipHelper::getProfileFields(0, true, $item->language); $data = OSMembershipHelper::getProfileData($item, 0, $rowFields); $form = new RADForm($rowFields); $form->setData($data)->bindData(); //Trigger third party add-on JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $results = $dispatcher->trigger('onProfileDisplay', array($item)); //Get renew and upgrade options, only allow renew for active or expired subscriptions $sql = 'SELECT DISTINCT plan_id FROM #__osmembership_subscribers WHERE profile_id=' . $item->id . ' AND (published = 1 OR published = 2)'; $db->setQuery($sql); $planIds = $db->loadColumn(); //Check to see whether the user can renew or not $canRenew = false; foreach ($planIds as $planId) { $sql = 'SELECT recurring_subscription, enable_renewal FROM #__osmembership_plans WHERE id=' . $planId; $db->setQuery($sql); $plan = $db->loadObject(); if (!$plan->recurring_subscription && $plan->enable_renewal) { $canRenew = true; break; } } //Load js file to support state field dropdown JFactory::getDocument()->addScript(JUri::base(true) . '/components/com_osmembership/assets/js/paymentmethods.js'); //Need to get subscriptions information of the user $plans = OSMembershipHelper::getSubscriptions($item->profile_id); $renewOptions = array(); $this->item = $item; $this->config = $config; $this->items = $items; $this->form = $form; $this->Itemid = $Itemid; $this->plugins = $results; $this->planIds = $planIds; $this->plans = $plans; $this->canRenew = $canRenew; parent::display($tpl); }
/** * Helper function to extend subscription of a user when a recurring payment happens * * @param $id * * @return bool */ public static function extendRecurringSubscription($id) { $config = OSMembershipHelper::getConfig(); $row = JTable::getInstance('OsMembership', 'Subscriber'); $row->load($id); if (!$row->id) { return false; } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('*')->from('#__osmembership_plans')->where('id = ' . (int) $row->plan_id); $db->setQuery($query); $rowPlan = $db->loadObject(); $row->payment_made = $row->payment_made + 1; $row->store(); if ($rowPlan->trial_duration && $rowPlan->trial_amount == 0 || $row->payment_made > 1) { $process = true; } else { $process = false; } if ($process) { $row->id = 0; $row->created_date = JFactory::getDate()->toSql(); $row->invoice_number = 0; $price = $rowPlan->price; $maxDate = null; if ($row->user_id > 0) { $sql = 'SELECT MAX(to_date) FROM #__osmembership_subscribers WHERE user_id=' . $row->user_id . ' AND plan_id=' . $row->plan_id . ' AND published=1'; $db->setQuery($sql); $maxDate = $db->loadResult(); } if ($maxDate) { $date = JFactory::getDate($maxDate); $row->from_date = $date->add(new DateInterval('P1D'))->toSql(); } else { $date = JFactory::getDate(); $row->from_date = $date->toSql(); } $row->to_date = $date->add(new DateInterval('P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit))->toSql(); $row->act = 'renew'; $row->amount = $price; //Calculate coupon discount if ($row->coupon_id) { $sql = 'SELECT * FROM #__osmembership_coupons WHERE id=' . $row->coupon_id; $db->setQuery($sql); $coupon = $db->loadObject(); if ($coupon) { if ($coupon->coupon_type == 0) { $row->discount_amount = $price * $coupon->discount / 100; } else { $row->discount_amount = min($coupon->discount, $price); } } } else { $row->discount_amount = 0; } if ($rowPlan->tax_rate > 0) { $row->tax_amount = round(($price - $row->discount_amount) * $rowPlan->tax_rate / 100, 2); } else { $row->tax_amount = 0; } $row->gross_amount = $row->amount - $row->discount_amount + $row->tax_amount; $row->published = 1; $row->store(); $sql = "INSERT INTO #__osmembership_field_value(field_id, field_value, subscriber_id)" . " SELECT field_id,field_value, {$row->id}" . " FROM #__osmembership_field_value WHERE subscriber_id={$id}"; $db->setQuery($sql); $db->execute(); JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onMembershipActive', array($row)); OSMembershipHelper::sendEmails($row, $config); } }
function processPayment($row, $data) { $app = JFactory::getApplication(); $Itemid = JRequest::getInt('Itemid'); $this->setCustomerFirstname($row->first_name); $this->setCustomerLastname($row->last_name); $this->setCustomerEmail($row->email); $this->setCustomerAddress($row->address); $this->setCustomerPostcode($row->zip); $this->setCustomerInvoiceDescription($data['item_name']); $this->setCustomerInvoiceRef($row->id); $this->setCardHoldersName($data['card_holder_name']); $this->setCardNumber($data['x_card_num']); $this->setCardExpiryMonth(str_pad($data['exp_month'], 2, '0', STR_PAD_LEFT)); $this->setCardExpiryYear(substr($data['exp_year'], 2, 2)); $this->setCardCVN($data['x_card_code']); $this->setTrxnNumber($row->transaction_id); $this->setTotalAmount($data['amount'] * 100); $xmlRequest = "<ewaygateway>" . "<ewayCustomerID>" . htmlentities($this->myCustomerID) . "</ewayCustomerID>" . "<ewayTotalAmount>" . htmlentities($this->myTotalAmount) . "</ewayTotalAmount>" . "<ewayCustomerFirstName>" . htmlentities($this->myCustomerFirstname) . "</ewayCustomerFirstName>" . "<ewayCustomerLastName>" . htmlentities($this->myCustomerLastname) . "</ewayCustomerLastName>" . "<ewayCustomerEmail>" . htmlentities($this->myCustomerEmail) . "</ewayCustomerEmail>" . "<ewayCustomerAddress>" . htmlentities($this->myCustomerAddress) . "</ewayCustomerAddress>" . "<ewayCustomerPostcode>" . htmlentities($this->myCustomerPostcode) . "</ewayCustomerPostcode>" . "<ewayCustomerInvoiceDescription>" . htmlentities($this->myCustomerInvoiceDescription) . "</ewayCustomerInvoiceDescription>" . "<ewayCustomerInvoiceRef>" . htmlentities($this->myCustomerInvoiceRef) . "</ewayCustomerInvoiceRef>" . "<ewayCardHoldersName>" . htmlentities($this->myCardName) . "</ewayCardHoldersName>" . "<ewayCardNumber>" . htmlentities($this->myCardNumber) . "</ewayCardNumber>" . "<ewayCardExpiryMonth>" . htmlentities($this->myCardExpiryMonth) . "</ewayCardExpiryMonth>" . "<ewayCardExpiryYear>" . htmlentities($this->myCardExpiryYear) . "</ewayCardExpiryYear>" . "<ewayTrxnNumber>" . htmlentities($this->myTrxnNumber) . "</ewayTrxnNumber>" . "<ewayOption1>" . htmlentities($this->myOption1) . "</ewayOption1>" . "<ewayOption2>" . htmlentities($this->myOption2) . "</ewayOption2>" . "<ewayOption3>" . htmlentities($this->myOption3) . "</ewayOption3>" . "<ewayCVN>" . htmlentities($this->myCardCVN) . "</ewayCVN>" . "</ewaygateway>"; /* Use CURL to execute XML POST and write output into a string */ $ch = curl_init($this->myGatewayURL); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 240); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $xmlResponse = curl_exec($ch); //exit; // Check whether the curl_exec worked. if (curl_errno($ch) == CURLE_OK) { // It worked, so setup an XML parser for the result. $this->parser = xml_parser_create(); // Disable XML tag capitalisation (Case Folding) xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, FALSE); // Define Callback functions for XML Parsing xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, "epXmlElementStart", "epXmlElementEnd"); xml_set_character_data_handler($this->parser, "epXmlData"); // Parse the XML response xml_parse($this->parser, $xmlResponse, TRUE); if (xml_get_error_code($this->parser) == XML_ERROR_NONE) { // Get the result into local variables. $this->myResultTrxnStatus = $this->xmlData['ewayTrxnStatus']; $this->myResultTrxnNumber = $this->xmlData['ewayTrxnNumber']; $this->myResultTrxnOption1 = $this->xmlData['ewayTrxnOption1']; $this->myResultTrxnOption2 = $this->xmlData['ewayTrxnOption2']; $this->myResultTrxnOption3 = $this->xmlData['ewayTrxnOption3']; $this->myResultTrxnReference = $this->xmlData['ewayTrxnReference']; $this->myResultAuthCode = $this->xmlData['ewayAuthCode']; $this->myResultReturnAmount = $this->xmlData['ewayReturnAmount']; $this->myResultTrxnError = $this->xmlData['ewayTrxnError']; $this->myError = 0; $this->myErrorMessage = ''; } else { // An XML error occured. Return the error message and number. $this->myError = xml_get_error_code($this->parser) + EWAY_XML_ERROR_OFFSET; $this->myErrorMessage = xml_error_string($myError); } // Clean up our XML parser xml_parser_free($this->parser); } else { // A CURL Error occured. Return the error message and number. (offset so we can pick the error apart) $this->myError = curl_errno($ch) + EWAY_CURL_ERROR_OFFSET; $this->myErrorMessage = curl_error($ch); } // Clean up CURL, and return any error. curl_close($ch); $result = $this->getError(); if ($result == EWAY_TRANSACTION_OK) { $config = OSMembershipHelper::getConfig(); $row->transaction_id = $this->getTrxnNumber(); $row->payment_date = date('Y-m-d H:i:s'); $row->published = 1; $row->store(); if ($row->act == 'upgrade') { OSMembershipHelper::processUpgradeMembership($row); } JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onMembershipActive', array($row)); OSMembershipHelper::sendEmails($row, $config); $db = JFactory::getDbo(); $sql = 'SELECT subscription_complete_url FROM #__osmembership_plans WHERE id=' . $row->plan_id; $db->setQuery($sql); $subscriptionCompleteURL = $db->loadResult(); if ($subscriptionCompleteURL) { $app->redirect($subscriptionCompleteURL); } else { $app->redirect(JRoute::_('index.php?option=com_osmembership&view=complete&act=' . $row->act . '&subscription_code=' . $row->subscription_code . '&Itemid=' . $Itemid, false, false)); } return true; } else { $_SESSION['reason'] = $this->myResultTrxnError; $app->redirect(JRoute::_('index.php?option=com_osmembership&view=failure&id=' . $row->id . '&Itemid=' . $Itemid, false, false)); return false; } }
*/ defined('_JEXEC') or die; error_reporting(0); if (file_exists(JPATH_ROOT . '/components/com_osmembership/osmembership.php')) { require_once JPATH_ROOT . '/components/com_osmembership/libraries/rad/bootstrap.php'; //OS Framework require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/defines.php'; require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/inflector.php'; require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/autoload.php'; $document = JFactory::getDocument(); $user = JFactory::getUser(); $db =& JFactory::getDBO(); OSMembershipHelper::loadLanguage(); $styleUrl = JURI::base(true) . '/components/com_osmembership/assets/css/style.css'; $document->addStylesheet($styleUrl, 'text/css', null, null); $config = OSMembershipHelper::getConfig(); if (@$config->load_jquery !== '0') { OSMembershipHelper::loadJQuery(); } OSMembershipHelper::loadBootstrap(true); JHtml::_('script', OSMembershipHelper::getSiteUrl() . 'components/com_osmembership/assets/js/jquery-noconflict.js', false, false); $Itemid = JRequest::getInt('Itemid'); $planIds = $params->get('plan_ids', '*'); $layout = $params->get('layout_type', 'default'); $fieldSuffix = OSMembershipHelper::getFieldSuffix(); if (!$planIds) { $planIds = '*'; } if ($planIds == '*') { $sql = 'SELECT a.*, a.title' . $fieldSuffix . ' AS title, a.description' . $fieldSuffix . ' AS description, a.short_description' . $fieldSuffix . ' AS short_description FROM #__osmembership_plans AS a WHERE a.published = 1 ORDER BY a.ordering'; } elseif (strpos($planIds, 'cat-') !== false) {
function export() { $config = OSMembershipHelper::getConfig(); $db = JFactory::getDbo(); $planId = JRequest::getInt('plan_id'); $published = JRequest::getInt('published', -1); $where = array(); if ($planId > 0) { $where[] = ' a.plan_id=' . $planId; } if ($published != -1) { $where[] = ' a.published=' . $published; } $sql = 'SELECT a.*, b.username, c.title FROM #__osmembership_subscribers AS a LEFT JOIN #__users AS b ON a.user_id = b.id LEFT JOIN #__osmembership_plans AS c ON a.plan_id = c.id '; if (count($where)) { $sql .= ' WHERE ' . implode(' AND ', $where); } $db->setQuery($sql); $rows = $db->loadObjectList(); for ($i = 0, $n = count($rows); $i < $n; $i++) { $row = $rows[$i]; switch ($row->published) { case 0: $row->subscription_status = JText::_('OSM_PENDING'); break; case 1: $row->subscription_status = JText::_('OSM_ACTIVE'); break; case 2: $row->subscription_status = JText::_('OSM_EXPIRED'); break; case 3: $row->subscription_status = JText::_('OSM_CANCELLED_PENDING'); break; case 4: $row->subscription_status = JText::_('OSM_CANCELLED_REFUNDED'); break; default: $row->subscription_status = ''; break; } } $sql = 'SELECT name, title FROM #__osmembership_plugins'; $db->setQuery($sql); $plugins = $db->loadObjectList(); $pluginTitles = array(); foreach ($plugins as $plugin) { $pluginTitles[$plugin->name] = $plugin->title; } //Get list of custom fields $sql = 'SELECT id, name, title, is_core FROM #__osmembership_fields WHERE published=1 ORDER BY ordering'; $db->setQuery($sql); $rowFields = $db->loadObjectList(); $customFieldDatas = array(); if (count($where)) { $sql = 'SELECT * FROM #__osmembership_field_value WHERE subscriber_id IN (SELECT id FROM #__osmembership_subscribers AS a WHERE ' . implode(' AND ', $where) . ')'; } else { $sql = 'SELECT * FROM #__osmembership_field_value'; } $db->setQuery($sql); $fieldDatas = $db->loadObjectList(); if (count($fieldDatas)) { foreach ($fieldDatas as $fieldData) { $customFieldDatas[$fieldData->subscriber_id][$fieldData->field_id] = $fieldData->field_value; } } if (count($rows)) { $results_arr = array(); $results_arr[] = JText::_('OSM_PLAN'); $results_arr[] = JText::_('Username'); foreach ($rowFields as $rowField) { $results_arr[] = $rowField->title; } $results_arr[] = JText::_('OSM_SUBSCRIPTION_START_DATE'); $results_arr[] = JText::_('OSM_SUBSCRIPTION_END_DATE'); $results_arr[] = JText::_('OSM_SUBSCRIPTION_STATUS'); $results_arr[] = JText::_('OSM_DISCOUNT_AMOUNT'); $results_arr[] = JText::_('OSM_TAX_AMOUNT'); $results_arr[] = JText::_('OSM_GROSS_AMOUNT'); $results_arr[] = JText::_('OSM_PAYMENT_METHOD'); $results_arr[] = JText::_('OSM_TRANSACTION_ID'); $csv_output = "\"" . implode("\",\"", $results_arr) . "\""; foreach ($rows as $r) { $results_arr = array(); $results_arr[] = $r->title; $results_arr[] = $r->username; foreach ($rowFields as $rowField) { if ($rowField->is_core) { $fieldName = $rowField->name; $results_arr[] = $r->{$fieldName}; } else { $fieldId = $rowField->id; $fieldValue = @$customFieldDatas[$r->id][$fieldId]; if (is_string($fieldValue) && is_array(json_decode($fieldValue))) { $fieldValue = implode(', ', json_decode($fieldValue)); } $results_arr[] = $fieldValue; } } $results_arr[] = JHtml::_('date', $r->from_date, $config->date_format); $results_arr[] = JHtml::_('date', $r->to_date, $config->date_format); $results_arr[] = $r->subscription_status; $results_arr[] = round($r->discount_amount, 2); $results_arr[] = round($r->tax_amount, 2); $results_arr[] = round($r->gross_amount, 2); $results_arr[] = $pluginTitles[$r->payment_method]; $results_arr[] = $r->transaction_id; $csv_output .= "\n\"" . implode("\",\"", $results_arr) . "\""; } $csv_output .= "\n"; if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) { $UserBrowser = "Opera"; } elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT'])) { $UserBrowser = "IE"; } else { $UserBrowser = ''; } $mime_type = $UserBrowser == 'IE' || $UserBrowser == 'Opera' ? 'application/octetstream' : 'application/octet-stream'; $filename = "subscribers_list"; @ob_end_clean(); ob_start(); header('Content-Type: ' . $mime_type); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); if ($UserBrowser == 'IE') { header('Content-Disposition: attachment; filename="' . $filename . '.csv"'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } else { header('Content-Disposition: attachment; filename="' . $filename . '.csv"'); header('Pragma: no-cache'); } print $csv_output; exit; } }
/** * Process Subscription * * @param array $data */ function processSubscription($data) { jimport('joomla.user.helper'); $db = JFactory::getDbo(); $row = JTable::getInstance('OsMembership', 'Subscriber'); $query = $db->getQuery(true); $config = OSMembershipHelper::getConfig(); $user = JFactory::getUser(); $userId = $user->get('id'); $nullDate = $db->getNullDate(); $fieldSuffix = OSMembershipHelper::getFieldSuffix(); if (!$userId && $config->registration_integration) { //Store user account into Joomla users database if ($config->create_account_when_membership_active !== '1') { $userId = OSMembershipHelper::saveRegistration($data); } else { //Encrypt the password and store into #__osmembership_subscribers table and create the account layout $privateKey = md5(JFactory::getConfig()->get('secret')); $key = new JCryptKey('simple', $privateKey, $privateKey); $crypt = new JCrypt(new JCryptCipherSimple(), $key); $data['user_password'] = $crypt->encrypt($data['password1']); } } $data['transaction_id'] = strtoupper(JUserHelper::genRandomPassword(16)); $row->bind($data); $row->published = 0; $row->created_date = JFactory::getDate()->toSql(); $row->user_id = $userId; while (true) { $subscriptionCode = JUserHelper::genRandomPassword(10); $query->select('COUNT(*)')->from('#__osmembership_subscribers')->where('subscription_code=' . $db->quote($subscriptionCode)); $db->setQuery($query); $total = $db->loadResult(); if (!$total) { break; } } $row->subscription_code = $subscriptionCode; $query->clear(); $query->select('id')->from('#__osmembership_subscribers')->where("is_profile=1 AND ((user_id={$userId} AND user_id>0) OR email='{$row->email}')"); $db->setQuery($query); $profileId = $db->loadResult(); if ($profileId) { $row->is_profile = 0; $row->profile_id = $profileId; } else { $row->is_profile = 1; } $row->language = JFactory::getLanguage()->getTag(); $query->clear(); $query->select('*, title' . $fieldSuffix . ' AS title')->from('#__osmembership_plans')->where('id=' . (int) $data['plan_id']); $db->setQuery($query); $rowPlan = $db->loadObject(); $rowFields = OSMembershipHelper::getProfileFields($row->plan_id, false); $form = new RADForm($rowFields); $form->setData($data)->bindData(true); $fees = OSMembershipHelper::calculateSubscriptionFee($rowPlan, $form, $data, $config, $row->payment_method); $action = $data['act']; if ($action == 'renew') { $renewOptionId = (int) $data['renew_option_id']; if ($renewOptionId == OSM_DEFAULT_RENEW_OPTION_ID) { $dateIntervalSpec = 'P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit; } else { $query->clear(); $query->select('number_days')->from('#__osmembership_renewrates')->where('id=' . (int) $data['renew_option_id']); $db->setQuery($query); $numberDays = (int) $db->loadResult(); $dateIntervalSpec = 'P' . $numberDays . 'D'; } } elseif ($action == 'upgrade') { $dateIntervalSpec = 'P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit; } else { if ($rowPlan->recurring_subscription && $rowPlan->trial_duration) { $dateIntervalSpec = 'P' . $rowPlan->trial_duration . $rowPlan->trial_duration_unit; } else { $dateIntervalSpec = 'P' . $rowPlan->subscription_length . $rowPlan->subscription_length_unit; } } $maxDate = null; if ($row->user_id > 0) { //Subscriber, user existed $query->clear(); $query->select('MAX(to_date)')->from('#__osmembership_subscribers')->where('user_id=' . $row->user_id . ' AND plan_id=' . $row->plan_id . ' AND (published=1 OR (published = 0 AND payment_method LIKE "os_offline%"))'); $db->setQuery($query); $maxDate = $db->loadResult(); } if ($maxDate) { $date = JFactory::getDate($maxDate); $row->from_date = $date->add(new DateInterval('P1D'))->toSql(); } else { $date = JFactory::getDate(); $row->from_date = $date->toSql(); } if ($rowPlan->expired_date && $rowPlan->expired_date != $nullDate) { $expiredDate = JFactory::getDate($rowPlan->expired_date); $expiredDate->setTime(0, 0, 0); $startDate = clone $date; $startDate->setTime(0, 0, 0); if ($startDate >= $expiredDate) { $date->setDate($date->year + 1, $expiredDate->month, $expiredDate->day); $row->to_date = $date->toSql(); } else { $row->to_date = $rowPlan->expired_date; } } else { if ($rowPlan->lifetime_membership) { $row->to_date = '2099-12-31 23:59:59'; } else { $row->to_date = $date->add(new DateInterval($dateIntervalSpec))->toSql(); } } $couponCode = JRequest::getVar('coupon_code', ''); $couponId = 0; if ($couponCode && $fees['coupon_valid']) { $query->clear(); $query->select('id')->from('#__osmembership_coupons')->where('code=' . $db->quote($couponCode)); $db->setQuery($query); $couponId = (int) $db->loadResult(); $query->clear(); $query->update('#__osmembership_coupons')->set('used=used+1')->where('id=' . $couponId); $db->setQuery($query); $db->execute(); } $row->amount = $fees['amount']; $row->discount_amount = $fees['discount_amount']; $row->tax_amount = $fees['tax_amount']; $row->payment_processing_fee = $fees['payment_processing_fee']; $row->coupon_id = $couponId; $row->gross_amount = $fees['gross_amount']; $row->store(); if (!$row->profile_id) { $row->profile_id = $row->id; $row->store(); } $data['amount'] = $fees['gross_amount']; //Store custom field data $form->storeData($row->id, $data); //Syncronize profile data for other records OSMembershipHelper::syncronizeProfileData($row, $data); JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterStoreSubscription', array($row)); $data['regular_price'] = $fees['regular_gross_amount']; $data['trial_amount'] = $fees['trial_gross_amount']; if ($data['amount'] > 0 || $rowPlan->recurring_subscription) { switch ($action) { case 'renew': $itemName = JText::_('OSM_PAYMENT_FOR_RENEW_SUBSCRIPTION'); $itemName = str_replace('[PLAN_TITLE]', $rowPlan->title, $itemName); break; case 'upgrade': $itemName = JText::_('OSM_PAYMENT_FOR_UPGRADE_SUBSCRIPTION'); $itemName = str_replace('[PLAN_TITLE]', $rowPlan->title, $itemName); //Get from Plan Title $query->clear(); $query->select('a.title')->from('#__osmembership_plans AS a')->innerJoin('#__osmembership_upgraderules AS b ON a.id=b.from_plan_id')->where('b.id=' . $row->upgrade_option_id); $db->setQuery($query); $fromPlanTitle = $db->loadResult(); $itemName = str_replace('[FROM_PLAN_TITLE]', $fromPlanTitle, $itemName); break; default: $itemName = JText::_('OSM_PAYMENT_FOR_SUBSCRIPTION'); $itemName = str_replace('[PLAN_TITLE]', $rowPlan->title, $itemName); break; } $data['item_name'] = $itemName; $paymentMethod = $data['payment_method']; require_once JPATH_COMPONENT . '/plugins/' . $paymentMethod . '.php'; $query->clear(); $query->select('params, support_recurring_subscription')->from('#__osmembership_plugins')->where('name=' . $db->quote($paymentMethod)); $db->setQuery($query); $plugin = $db->loadObject(); $params = $plugin->params; $supportRecurring = $plugin->support_recurring_subscription; $params = new JRegistry($params); $paymentClass = new $paymentMethod($params); if ($rowPlan->recurring_subscription && $supportRecurring) { if ($paymentMethod == 'os_authnet') { $paymentMethod = 'os_authnet_arb'; require_once JPATH_COMPONENT . '/plugins/' . $paymentMethod . '.php'; $paymentClass = new $paymentMethod($params); } $paymentClass->processRecurringPayment($row, $data); } else { $paymentClass->processPayment($row, $data); } } else { $Itemid = JRequest::getInt('Itemid'); $row->published = 1; $row->store(); if ($row->act == 'upgrade') { OSMembershipHelper::processUpgradeMembership($row); } OSMembershipHelper::sendEmails($row, $config); JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onMembershipActive', array($row)); $query->clear(); $query->select('subscription_complete_url')->from('#__osmembership_plans')->where('id=' . $row->plan_id); //Get subscription complete UR $db->setQuery($query); $subscriptionCompleteURL = $db->loadResult(); if ($subscriptionCompleteURL) { JFactory::getApplication()->redirect($subscriptionCompleteURL); } else { JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_osmembership&view=complete&act=' . $row->act . '&subscription_code=' . $row->subscription_code . '&Itemid=' . $Itemid, false)); } } }
/** * Processs payment * * @param string $data * @return unknown */ function processRecurringPayment($row, $data) { $app = JFactory::getApplication(); $db = JFactory::getDbo(); $Itemid = JRequest::getInt('Itemid'); $sql = 'SELECT * FROM #__osmembership_plans WHERE id=' . $row->plan_id; $db->setQuery($sql); $rowPlan = $db->loadObject(); $frequency = $rowPlan->subscription_length_unit; $length = $rowPlan->subscription_length; switch ($frequency) { case 'D': $unit = 'days'; break; case 'W': $unit = 'days'; break; case 'M': $unit = 'months'; break; case 'Y': $length = 12; $unit = 'months'; break; } $this->setParameter('refID', $row->subscription_code); $this->setParameter('subscrName', $row->first_name . ' ' . $row->last_name); $this->setParameter('interval_length', $length); $this->setParameter('interval_unit', $unit); $this->setParameter('expirationDate', str_pad($data['exp_month'], 2, '0', STR_PAD_LEFT) . '/' . substr($data['exp_year'], 2, 2)); $this->setParameter('cardNumber', $data['x_card_num']); $this->setParameter('firstName', $row->first_name); $this->setParameter('lastName', $row->last_name); $this->setParameter('address', $row->address); $this->setParameter('city', $row->city); $this->setParameter('state', $row->state); $this->setParameter('zip', $row->zip); $this->setParameter('amount', round($data['regular_price'], 2)); if ($rowPlan->number_payments >= 2) { $totalOccurences = $rowPlan->number_payments; } else { $totalOccurences = 9999; } $this->setParameter('totalOccurrences', $totalOccurences); if ($rowPlan->trial_duration) { $this->setParameter('trialAmount', round($data['trial_amount'], 2)); $this->setParameter('trialOccurrences', $rowPlan->trial_duration); } $this->createAccount(); if ($this->success) { $config = OSMembershipHelper::getConfig(); $row->transaction_id = $this->getSubscriberID(); $row->payment_date = date('Y-m-d H:i:s'); $row->payment_made = 1; $row->published = true; $row->store(); JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onMembershipActive', array($row)); OSMembershipHelper::sendEmails($row, $config); $db = JFactory::getDbo(); $sql = 'SELECT subscription_complete_url FROM #__osmembership_plans WHERE id=' . $row->plan_id; $db->setQuery($sql); $subscriptionCompleteURL = $db->loadResult(); if ($subscriptionCompleteURL) { $app->redirect($subscriptionCompleteURL); } else { $app->redirect(JRoute::_('index.php?option=com_osmembership&view=complete&act=' . $row->act . '&subscription_code=' . $row->subscription_code . '&Itemid=' . $Itemid, false, false)); } return true; } else { $_SESSION['reason'] = $this->text; $app->redirect(JRoute::_('index.php?option=com_osmembership&view=failure&id=' . $row->id . '&Itemid=' . $Itemid, false)); return false; } }
/** * Validate email, make sure it is valid before continue processing subscription * In Joomla, each user must have an unique email address for account registration * */ public function validate_email() { $app = JFactory::getApplication(); $db = JFactory::getDbo(); $user = JFactory::getUser(); $config = OSMembershipHelper::getConfig(); $query = $db->getQuery(true); $email = $app->input->get('fieldValue', '', 'string'); $validateId = JRequest::getVar('fieldId'); $query->select('COUNT(*)')->from('#__users')->where('email="' . $email . '"'); $db->setQuery($query); $total = $db->loadResult(); $arrayToJs = array(); $arrayToJs[0] = $validateId; if (!$total || $user->id || !$config->registration_integration) { $arrayToJs[1] = true; } else { $arrayToJs[1] = false; } echo json_encode($arrayToJs); JFactory::getApplication()->close(); }
function display($tpl = null) { $this->setLayout('default'); $db = JFactory::getDbo(); $subscriptionCode = JRequest::getVar('subscription_code'); if ($subscriptionCode) { $sql = 'SELECT id FROM #__osmembership_subscribers WHERE subscription_code="' . $subscriptionCode . '"'; $db->setQuery($sql); $id = (int) $db->loadResult(); if (!$id) { JFactory::getApplication()->redirect('index.php', JText::_('Invalid subscription code')); } } else { $id = 0; } $fieldSuffix = OSMembershipHelper::getFieldSuffix(); $sql = 'SELECT a.id, a.title' . $fieldSuffix . ' AS title, b.payment_method FROM #__osmembership_plans AS a ' . ' INNER JOIN #__osmembership_subscribers AS b ' . ' ON a.id = b.plan_id ' . ' WHERE b.id = ' . $id; $db->setQuery($sql); $subscriber = $db->loadObject(); $config = OSMembershipHelper::getConfig(); $messageObj = OSMembershipHelper::getMessages(); $sql = 'SELECT * FROM #__osmembership_subscribers WHERE id=' . $id; $db->setQuery($sql); $row = $db->loadObject(); $act = JRequest::getVar('act', ''); switch ($act) { case 'renew': if (strlen(strip_tags($messageObj->{'renew_thanks_message' . $fieldSuffix}))) { $message = $messageObj->{'renew_thanks_message' . $fieldSuffix}; } else { $message = $messageObj->renew_thanks_message; } $sql = 'SELECT to_date FROM #__osmembership_subscribers WHERE id=' . $id; $db->setQuery($sql); $toDate = $db->loadResult(); if ($toDate) { $toDate = JHtml::_('date', $toDate, $config->date_format); } else { $toDate = ''; } $message = str_replace('[END_DATE]', $toDate, $message); $message = str_replace('[PLAN_TITLE]', $subscriber->title, $message); break; case 'upgrade': if (strlen(strip_tags($messageObj->{'renew_thanks_message' . $fieldSuffix}))) { $message = $messageObj->{'upgrade_thanks_message' . $fieldSuffix}; } else { $message = $messageObj->upgrade_thanks_message; } $sql = ' SELECT c.title FROM #__osmembership_subscribers AS a ' . ' INNER JOIN #__osmembership_upgraderules AS b ' . ' ON a.upgrade_option_id=b.id ' . ' INNER JOIN #__osmembership_plans AS c ' . ' ON b.from_plan_id = c.id ' . ' WHERE a.id = ' . $id; $db->setQuery($sql); $fromPlan = $db->loadResult(); $message = str_replace('[PLAN_TITLE]', $fromPlan, $message); $message = str_replace('[TO_PLAN_TITLE]', $subscriber->title, $message); break; default: if ($subscriber->payment_method == 'os_offline') { if (strlen(strip_tags($messageObj->{'thanks_message_offline' . $fieldSuffix}))) { $message = $messageObj->{'thanks_message_offline' . $fieldSuffix}; } else { $message = $messageObj->thanks_message_offline; } } else { if (strlen(strip_tags($messageObj->{'thanks_message' . $fieldSuffix}))) { $message = $messageObj->{'thanks_message' . $fieldSuffix}; } else { $message = $messageObj->thanks_message; } } $message = str_replace('[PLAN_TITLE]', $subscriber->title, $message); $registrationDetail = OSMembershipHelper::getEmailContent($config, $row); $message = str_replace('[SUBSCRIPTION_DETAIL]', $registrationDetail, $message); break; } $subscriptionDetail = OSMembershipHelper::getEmailContent($config, $row); $message = str_replace('[SUBSCRIPTION_DETAIL]', $subscriptionDetail, $message); $replaces = OSMembershipHelper::buildTags($row, $config); $replaces['plan_title'] = $subscriber->title; foreach ($replaces as $key => $value) { $key = strtoupper($key); $message = str_replace("[{$key}]", $value, $message); } $this->message = $message; parent::display($tpl); }
function display($tpl = null) { $this->subscriptions = $this->get('Subscriptions'); $this->config = OSMembershipHelper::getConfig(); parent::display($tpl); }
/** * Get profile data of the subscriber, using for json format * */ function get_profile_data() { $config = OSMembershipHelper::getConfig(); $input = JFactory::getApplication()->input; $userId = $input->getInt('user_id', 0); $planId = $input->getInt('plan_id'); $data = array(); if ($userId && $planId) { $rowFields = OSMembershipHelper::getProfileFields($planId, true); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->clear(); $query->select('*')->from('#__osmembership_subscribers')->where('user_id=' . $userId . ' AND is_profile=1'); $db->setQuery($query); $rowProfile = $db->loadObject(); if ($rowProfile) { $data = OSMembershipHelper::getProfileData($rowProfile, $planId, $rowFields); } elseif (JPluginHelper::isEnabled('user', 'profile') && !$config->cb_integration) { $syncronizer = new RADSynchronizerJoomla(); $mappings = array(); foreach ($rowFields as $rowField) { if ($rowField->profile_field_mapping) { $mappings[$rowField->name] = $rowField->profile_field_mapping; } } $data = $syncronizer->getData($userId, $mappings); } else { // Trigger plugin to get data $mappings = array(); foreach ($rowFields as $rowField) { if ($rowField->field_mapping) { $mappings[$rowField->name] = $rowField->field_mapping; } } JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $results = $dispatcher->trigger('onGetProfileData', array($userId, $mappings)); if (count($results)) { foreach ($results as $res) { if (is_array($res) && count($res)) { $data = $res; break; } } } } } if ($userId && !isset($data['first_name'])) { //Load the name from Joomla default name $user = JFactory::getUser($userId); $name = $user->name; if ($name) { $pos = strpos($name, ' '); if ($pos !== false) { $data['first_name'] = substr($name, 0, $pos); $data['last_name'] = substr($name, $pos + 1); } else { $data['first_name'] = $name; $data['last_name'] = ''; } } } if ($userId && !isset($data['email'])) { $user = JFactory::getUser($userId); $data['email'] = $user->email; } echo json_encode($data); JFactory::getApplication()->close(); }
function display($tpl = null) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $user = JFactory::getUser(); $config = OSMembershipHelper::getConfig(); $messageObj = OSMembershipHelper::getMessages(); $fieldSuffix = OSMembershipHelper::getFieldSuffix(); JFactory::getDocument()->addScript(JUri::base(true) . '/components/com_osmembership/assets/js/paymentmethods.js'); $userId = $user->get('id'); $Itemid = JRequest::getInt('Itemid', 0); if (!$Itemid) { $Itemid = OSMembershipHelper::getItemid(); } $planId = JRequest::getInt('id', 0); // Check to see whether this is a valid form or not if (!$planId) { JFactory::getApplication()->redirect('index.php', JText::_('OSM_INVALID_MEMBERSHIP_PLAN')); } $query->select('*, title' . $fieldSuffix . ' AS title')->from('#__osmembership_plans')->where('id=' . $planId); $db->setQuery($query); $plan = $db->loadObject(); if ($plan->published == 0 || !$plan) { JFactory::getApplication()->redirect('index.php', JText::_('OSM_CANNOT_ACCESS_UNPUBLISHED_PLAN')); return; } if (!in_array($plan->access, $user->getAuthorisedViewLevels())) { JFactory::getApplication()->redirect('index.php', JText::_('OSM_NOT_ALLOWED_PLAN')); } // Check if user can subscribe to the plan if (!OSMembershipHelper::canSubscribe($plan)) { if ($config->number_days_before_renewal) { // Redirect to memberhsip profile page $app = JFactory::getApplication(); $app->enqueueMessage(JText::sprintf('OSM_COULD_NOT_RENEWAL', $config->number_days_before_renewal), 'message'); $profileItemId = OSMembershipHelperRoute::findView('profile', $Itemid); $app->redirect(JRoute::_('index.php?option=com_osmembership&view=profile&Itemid=' . $profileItemId)); } else { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('OSM_YOU_ARE_NOT_ALLOWED_TO_SIGNUP'), 'message'); $app->redirect('index.php'); } } $paymentMethod = JRequest::getVar('payment_method', os_payments::getDefautPaymentMethod(), 'post'); if (!$paymentMethod) { $paymentMethod = os_payments::getDefautPaymentMethod(); } $renewOptionId = JRequest::getInt('renew_option_id', 0); $upgradeOptionId = JRequest::getInt('upgrade_option_id', 0); if ($renewOptionId) { $action = 'renew'; } elseif ($upgradeOptionId) { $action = 'upgrade'; } else { $action = 'subscribe'; } ###############Payment Methods parameters############################### $lists['exp_month'] = JHtml::_('select.integerlist', 1, 12, 1, 'exp_month', ' id="exp_month" class="input-small" ', JRequest::getVar('exp_month', date('m'), 'post'), '%02d'); $currentYear = date('Y'); $lists['exp_year'] = JHtml::_('select.integerlist', $currentYear, $currentYear + 10, 1, 'exp_year', ' id="exp_year" class="input-small" ', JRequest::getVar('exp_year', date('Y'), 'post')); $options = array(); $cardTypes = explode(',', $config->enable_cardtypes); if (in_array('Visa', $cardTypes)) { $options[] = JHtml::_('select.option', 'Visa', JText::_('OSM_VISA_CARD')); } if (in_array('MasterCard', $cardTypes)) { $options[] = JHtml::_('select.option', 'MasterCard', JText::_('OSM_MASTER_CARD')); } if (in_array('Discover', $cardTypes)) { $options[] = JHtml::_('select.option', 'Discover', JText::_('OSM_DISCOVER')); } if (in_array('Amex', $cardTypes)) { $options[] = JHtml::_('select.option', 'Amex', JText::_('OSM_AMEX')); } $lists['card_type'] = JHtml::_('select.genericlist', $options, 'card_type', ' class="inputbox" ', 'value', 'text', JRequest::getVar('card_type', null, 'post')); $options = array(); $options[] = JHtml::_('select.option', 'CHECKING', JText::_('OSM_BANK_TYPE_CHECKING')); $options[] = JHtml::_('select.option', 'BUSINESSCHECKING', JText::_('OSM_BANK_TYPE_BUSINESSCHECKING')); $options[] = JHtml::_('select.option', 'SAVINGS', JText::_('OSM_BANK_TYPE_SAVINGS')); $lists['x_bank_acct_type'] = JHtml::_('select.genericlist', $options, 'x_bank_acct_type', ' class="inputbox" ', 'value', 'text', JRequest::getVar('x_bank_acct_type', null, 'post')); // IDEAL Mollie payment plugin support $idealEnabled = OSMembershipHelper::idealEnabled(); if ($idealEnabled) { $bankLists = OSMembershipHelper::getBankLists(); $options = array(); foreach ($bankLists as $bankId => $bankName) { $options[] = JHtml::_('select.option', $bankId, $bankName); } $lists['bank_id'] = JHtml::_('select.genericlist', $options, 'bank_id', ' class="inputbox" ', 'value', 'text', JRequest::getInt('bank_id')); } if ($plan->recurring_subscription) { $onlyRecurring = 1; } else { $onlyRecurring = 0; } if ($action == 'renew' || $action == 'upgrade') { $methods = os_payments::getPaymentMethods(true, $onlyRecurring); } else { $methods = os_payments::getPaymentMethods(true, $onlyRecurring); } if (count($methods) == 0) { JFactory::getApplication()->redirect('index.php', JText::_('OSM_NEED_TO_PUBLISH_PLUGIN')); } // Check to see if there is payment processing fee or not $showPaymentFee = false; foreach ($methods as $method) { if ($method->paymentFee) { $showPaymentFee = true; break; } } $this->showPaymentFee = $showPaymentFee; $rowFields = OSMembershipHelper::getProfileFields($planId, true, null, $action); if (isset($_POST['first_name'])) { $data = JRequest::get('post', JREQUEST_ALLOWHTML); } else { $data = array(); if ($userId) { // Check to see if this user has profile data already $query->clear(); $query->select('*')->from('#__osmembership_subscribers')->where('user_id=' . $userId . ' AND is_profile=1'); $db->setQuery($query); $rowProfile = $db->loadObject(); if ($rowProfile) { $data = OSMembershipHelper::getProfileData($rowProfile, $planId, $rowFields); } elseif (JPluginHelper::isEnabled('user', 'profile')) { $syncronizer = new RADSynchronizerJoomla(); $mappings = array(); foreach ($rowFields as $rowField) { if ($rowField->profile_field_mapping) { $mappings[$rowField->name] = $rowField->profile_field_mapping; } } $data = $syncronizer->getData($userId, $mappings); } else { // Trigger plugin to get data $mappings = array(); foreach ($rowFields as $rowField) { if ($rowField->field_mapping) { $mappings[$rowField->name] = $rowField->field_mapping; } } JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $results = $dispatcher->trigger('onGetProfileData', array($userId, $mappings)); if (count($results)) { foreach ($results as $res) { if (is_array($res) && count($res)) { $data = $res; break; } } } } } } if ($userId && !isset($data['first_name'])) { // Load the name from Joomla default name $name = $user->name; if ($name) { $pos = strpos($name, ' '); if ($pos !== false) { $data['first_name'] = substr($name, 0, $pos); $data['last_name'] = substr($name, $pos + 1); } else { $data['first_name'] = $name; $data['last_name'] = ''; } } } if ($userId && !isset($data['email'])) { $data['email'] = $user->email; } if (!isset($data['country']) || !$data['country']) { $data['country'] = $config->default_country; } $countryCode = OSMembershipHelper::getCountryCode($data['country']); // Get data $form = new RADForm($rowFields); $form->setData($data)->bindData(true); $form->prepareFormFields('calculateSubscriptionFee();'); $data['renew_option_id'] = $renewOptionId; $data['upgrade_option_id'] = $upgradeOptionId; $data['act'] = $action; $fees = OSMembershipHelper::calculateSubscriptionFee($plan, $form, $data, $config, $paymentMethod); $amount = $fees['amount']; if ($action == 'renew') { if (strlen(strip_tags($messageObj->{'subscription_renew_form_msg' . $fieldSuffix}))) { $message = $messageObj->{'subscription_renew_form_msg' . $fieldSuffix}; } else { $message = $messageObj->subscription_renew_form_msg; } if ($renewOptionId == OSM_DEFAULT_RENEW_OPTION_ID) { switch ($plan->subscription_length_unit) { case 'D': $text = $plan->subscription_length > 1 ? JText::_('OSM_DAYS') : JText::_('OSM_DAY'); break; case 'W': $text = $plan->subscription_length > 1 ? JText::_('OSM_WEEKS') : JText::_('OSM_WEEK'); break; case 'M': $text = $plan->subscription_length > 1 ? JText::_('OSM_MONTHS') : JText::_('OSM_MONTH'); break; case 'Y': $text = $plan->subscription_length > 1 ? JText::_('OSM_YEARS') : JText::_('OSM_YEAR'); break; } $message = str_replace('[NUMBER_DAYS] days', $plan->subscription_length . ' ' . $text, $message); } else { $query->clear(); $query->select('number_days')->from('#__osmembership_renewrates')->where('id=' . $renewOptionId); $db->setQuery($query); $numberDays = $db->loadResult(); $message = str_replace('[NUMBER_DAYS]', $numberDays, $message); } $message = str_replace('[PLAN_TITLE]', $plan->title, $message); $message = str_replace('[AMOUNT]', OSMembershipHelper::formatCurrency($amount, $config), $message); } elseif ($action == 'upgrade') { if (strlen(strip_tags($messageObj->{'subscription_upgrade_form_msg' . $fieldSuffix}))) { $message = $messageObj->{'subscription_upgrade_form_msg' . $fieldSuffix}; } else { $message = $messageObj->subscription_upgrade_form_msg; } $query->clear(); $query->select('b.title')->from('#__osmembership_upgraderules AS a')->innerJoin('#__osmembership_plans AS b ON a.from_plan_id=b.id')->where('a.id=' . $upgradeOptionId); $db->setQuery($query); $fromPlan = $db->loadResult(); $message = str_replace('[PLAN_TITLE]', $plan->title, $message); $message = str_replace('[AMOUNT]', OSMembershipHelper::formatCurrency($amount, $config), $message); $message = str_replace('[FROM_PLAN_TITLE]', $fromPlan, $message); } else { if (strlen(strip_tags($plan->{'subscription_form_message' . $fieldSuffix})) || strlen(strip_tags($plan->subscription_form_message))) { if (strlen(strip_tags($plan->{'subscription_form_message' . $fieldSuffix}))) { $message = $plan->{'subscription_form_message' . $fieldSuffix}; } else { $message = $plan->subscription_form_message; } } else { if (strlen(strip_tags($messageObj->{'subscription_form_msg' . $fieldSuffix}))) { $message = $messageObj->{'subscription_form_msg' . $fieldSuffix}; } else { $message = $messageObj->subscription_form_msg; } } if ($plan->recurring_subscription) { //We will first need to detect regular duration if ($plan->trial_duration) { $trialPeriorText = JText::_('OSM_TRIAL_RECURRING_SUBSCRIPTION_PERIOR'); $trialPeriorText = str_replace('[TRIAL_DURATION]', $plan->trial_duration, $trialPeriorText); switch ($plan->trial_duration_unit) { case 'D': $trialPeriorText = str_replace('[TRIAL_DURATION_UNIT]', $plan->trial_duration > 1 ? JText::_('OSM_DAYS') : JText::_('OSM_DAY'), $trialPeriorText); break; case 'W': $trialPeriorText = str_replace('[TRIAL_DURATION_UNIT]', $plan->trial_duration > 1 ? JText::_('OSM_WEEKS') : JText::_('OSM_WEEK'), $trialPeriorText); break; case 'M': $trialPeriorText = str_replace('[TRIAL_DURATION_UNIT]', $plan->trial_duration > 1 ? JText::_('OSM_MONTHS') : JText::_('OSM_MONTH'), $trialPeriorText); break; case 'Y': $trialPeriorText = str_replace('[TRIAL_DURATION_UNIT]', $plan->trial_duration > 1 ? JText::_('OSM_YEARS') : JText::_('OSM_YEAR'), $trialPeriorText); break; default: $trialPeriorText = str_replace('[TRIAL_DURATION_UNIT]', $plan->trial_duration > 1 ? JText::_('OSM_DAYS') : JText::_('OSM_DAY'), $trialPeriorText); break; } $this->trialPeriorText = $trialPeriorText; } $length = $plan->subscription_length; $regularPeriorText = JText::_('OSM_REGULAR_SUBSCRIPTION_PERIOR'); $regularPeriorText = str_replace('[REGULAR_DURATION]', $length, $regularPeriorText); switch ($plan->subscription_length_unit) { case 'D': $regularPeriorText = str_replace('[REGULAR_DURATION_UNIT]', $length > 1 ? JText::_('OSM_DAYS') : JText::_('OSM_DAY'), $regularPeriorText); break; case 'W': $regularPeriorText = str_replace('[REGULAR_DURATION_UNIT]', $length > 1 ? JText::_('OSM_WEEKS') : JText::_('OSM_WEEK'), $regularPeriorText); break; case 'M': $regularPeriorText = str_replace('[REGULAR_DURATION_UNIT]', $length > 1 ? JText::_('OSM_MONTHS') : JText::_('OSM_MONTH'), $regularPeriorText); break; case 'Y': $regularPeriorText = str_replace('[REGULAR_DURATION_UNIT]', $length > 1 ? JText::_('OSM_YEARS') : JText::_('OSM_YEAR'), $regularPeriorText); break; default: $regularPeriorText = str_replace('[REGULAR_DURATION_UNIT]', $length > 1 ? JText::_('OSM_DAYS') : JText::_('OSM_DAY'), $regularPeriorText); break; } $this->regularPeriorText = $regularPeriorText; $message = str_replace('[PLAN_TITLE]', $plan->title, $message); $message = str_replace('[AMOUNT]', OSMembershipHelper::formatCurrency($amount, $config), $message); } else { $message = str_replace('[PLAN_TITLE]', $plan->title, $message); $message = str_replace('[AMOUNT]', OSMembershipHelper::formatCurrency($amount, $config), $message); } } // Implement Joomla core recpatcha $showCaptcha = 0; if ($config->enable_captcha) { $captchaPlugin = JFactory::getApplication()->getParams()->get('captcha', JFactory::getConfig()->get('captcha')); if ($captchaPlugin) { $showCaptcha = 1; $this->captcha = JCaptcha::getInstance($captchaPlugin)->display('dynamic_recaptcha_1', 'dynamic_recaptcha_1', 'required'); } else { JFactory::getApplication()->enqueueMessage(JText::_('OSM_CAPTCHA_NOT_ACTIVATED_IN_YOUR_SITE'), 'error'); } } // Assign variables to template $this->userId = $userId; $this->paymentMethod = $paymentMethod; $this->lists = $lists; $this->Itemid = $Itemid; $this->config = $config; $this->plan = $plan; $this->methods = $methods; $this->idealEnabled = $idealEnabled; $this->action = $action; $this->renewOptionId = $renewOptionId; $this->upgradeOptionId = $upgradeOptionId; $this->message = $message; $this->form = $form; $this->fees = $fees; $this->showCaptcha = $showCaptcha; $this->countryBaseTax = (int) OSMembershipHelper::isCountryBaseTax(); $this->taxRate = OSMembershipHelper::calculateTaxRate($planId); $this->countryCode = $countryCode; parent::display($tpl); }
/** * Process payment with the posted data * * @param array $data array * @return void */ function processPayment($row, $data) { $mainframe = JFactory::getApplication(); $Itemid = JRequest::getInt('Itemid'); $data['x_description'] = $data['item_name']; $data['x_exp_date'] = str_pad($data['exp_month'], 2, '0', STR_PAD_LEFT) . '/' . substr($data['exp_year'], 2, 2); $data['amount'] = round($data['amount'], 2); $retries = 1; $testing = $this->mode ? "FALSE" : "TRUE"; $cc_num = $this->_ccNumber($data["x_card_num"]); //Set more parameters for the payment gateway to user $authnetValues = array("x_test_request" => $testing, "x_card_num" => $data['x_card_num'], "x_exp_date" => $data['x_exp_date'], "x_card_code" => $data['x_card_code'], "x_description" => $data['x_description'], "x_amount" => $data['amount'], "x_first_name" => $data['first_name'], "x_last_name" => $data['last_name'], "x_address" => $data['address'], "x_city" => $data['city'], "x_state" => $data['state'], "x_phone" => $data['phone'], "x_zip" => $data['zip'], "x_company" => $data['organization'], "x_email" => $data['email'], "x_country" => $data['country'], "x_ship_to_first_name" => $data['first_name'], "x_ship_to_last_name" => $data['last_name'], "x_ship_to_address" => $data['address'], "x_ship_to_city" => $data['city'], "x_ship_to_state" => $data['state'], "x_ship_to_country" => $data['country'], "x_ship_to_zip" => $data['zip'], "x_ship_to_phone" => $data['phone'], "x_ship_to_email" => $data['email'], "cc_number" => $cc_num, "cc_expdate" => $data['x_exp_date'], "cc_emailid" => $data['email']); foreach ($authnetValues as $key => $value) { $this->setParameter($key, $value); } $this->_prepareParameters(); $ch = curl_init($this->url); $count = 0; while ($count < $retries) { curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($this->fields, "& ")); //Uncomment this line if you get no response from payment gateway curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //If you are using goodaddy hosting, please uncomment the two below lines //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128"); $this->response = curl_exec($ch); $this->_parseResults(); if ($this->getResultResponseFull() == "Approved") { $this->approved = true; $this->declined = false; $this->error = false; break; } else { if ($this->getResultResponseFull() == "Declined") { $this->approved = false; $this->declined = true; $this->error = false; break; } } $count++; } curl_close($ch); if ($this->approved) { $config = OSMembershipHelper::getConfig(); $row->transaction_id = $this->getTransactionID(); $row->payment_date = date('Y-m-d H:i:s'); $row->published = 1; $row->store(); if ($row->act == 'upgrade') { OSMembershipHelper::processUpgradeMembership($row); } JPluginHelper::importPlugin('osmembership'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onMembershipActive', array($row)); OSMembershipHelper::sendEmails($row, $config); $db = JFactory::getDbo(); $sql = 'SELECT subscription_complete_url FROM #__osmembership_plans WHERE id=' . $row->plan_id; $db->setQuery($sql); $subscriptionCompleteURL = $db->loadResult(); if ($subscriptionCompleteURL) { $mainframe->redirect($subscriptionCompleteURL); } else { $mainframe->redirect(JRoute::_('index.php?option=com_osmembership&view=complete&act=' . $row->act . '&subscription_code=' . $row->subscription_code . '&Itemid=' . $Itemid, false, false)); } return true; } else { $_SESSION['reason'] = $this->getResponseText(); $mainframe->redirect(JRoute::_('index.php?option=com_osmembership&view=failure&id=' . $row->id . '&Itemid=' . $Itemid, false, false)); return false; } }
/** * Replace callback function * * @param array $matches */ function displayPlans($matches) { require_once JPATH_ROOT . '/components/com_osmembership/libraries/rad/bootstrap.php'; //OS Framework require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/defines.php'; require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/inflector.php'; require_once JPATH_ROOT . '/administrator/components/com_osmembership/libraries/autoload.php'; $document = JFactory::getDocument(); $user = JFactory::getUser(); $db = JFactory::getDBO(); $config = OSMembershipHelper::getConfig(); if (@$config->load_jquery !== '0') { OSMembershipHelper::loadJQuery(); } OSMembershipHelper::loadBootstrap(true); JHtml::_('script', OSMembershipHelper::getSiteUrl() . 'components/com_osmembership/assets/js/jquery-noconflict.js', false, false); OSMembershipHelper::loadLanguage(); $styleUrl = JURI::base(true) . '/components/com_osmembership/assets/css/style.css'; $document->addStylesheet($styleUrl, 'text/css', null, null); OSMembershipHelper::loadBootstrap(false); $Itemid = OSMembershipHelper::getItemid(); $planIds = $matches[1]; $fieldSuffix = OSMembershipHelper::getFieldSuffix(); $layout = $this->params->get('layout_type', 'default'); if ($planIds == '*') { $sql = 'SELECT a.*, a.title' . $fieldSuffix . ' AS title, a.description' . $fieldSuffix . ' AS description, a.short_description' . $fieldSuffix . ' AS short_description FROM #__osmembership_plans AS a WHERE a.published = 1 ORDER BY a.ordering'; } elseif (strpos($planIds, 'cat-') !== false) { $catId = (int) substr($planIds, 4); $sql = 'SELECT a.*, a.title' . $fieldSuffix . ' AS title, a.description' . $fieldSuffix . ' AS description, a.short_description' . $fieldSuffix . ' AS short_description FROM #__osmembership_plans AS a WHERE a.published = 1 AND a.category_id=' . $catId . ' ORDER BY a.ordering'; } else { $sql = 'SELECT a.*, a.title' . $fieldSuffix . ' AS title, a.description' . $fieldSuffix . ' AS description, a.short_description' . $fieldSuffix . ' AS short_description FROM #__osmembership_plans AS a WHERE a.published = 1 AND a.id IN (' . $planIds . ') ORDER BY a.ordering'; } $db->setQuery($sql); $rows = $db->loadObjectList(); if ($user->id) { for ($i = 0, $n = count($rows); $i < $n; $i++) { $row = $rows[$i]; $taxRate = OSMembershipHelper::calculateTaxRate($row->id); if ($config->show_price_including_tax && $taxRate > 0) { $row->price = $row->price * (1 + $taxRate / 100); $row->trial_amount = $row->trial_amount * (1 + $taxRate / 100); } if (!$row->enable_renewal) { $sql = 'SELECT COUNT(*) FROM #__osmembership_subscribers WHERE (email="' . $user->email . '" OR user_id=' . $user->id . ') AND plan_id=' . $row->id . ' AND published != 0 '; $db->setQuery($sql); $total = (int) $db->loadResult(); if ($total) { $row->disable_subscribe = 1; } } } } elseif ($config->show_price_including_tax) { for ($i = 0, $n = count($rows); $i < $n; $i++) { $row = $rows[$i]; $taxRate = OSMembershipHelper::getPlanTaxRate($row->id); if ($taxRate > 0) { $row->price = $row->price * (1 + $taxRate / 100); $row->trial_amount = $row->trial_amount * (1 + $taxRate / 100); } } } if ($layout == 'default') { return '<div class="osm-container row-fluid clearfix">' . OSMembershipHelperHtml::loadCommonLayout('common/default_plans.php', array('items' => $rows, 'config' => $config, 'Itemid' => $Itemid)) . '</div>'; } else { return '<div class="osm-container row-fluid clearfix">' . OSMembershipHelperHtml::loadCommonLayout('common/columns_plans.php', array('items' => $rows, 'config' => $config, 'Itemid' => $Itemid)) . '</div>'; } }