Ejemplo n.º 1
0
 public function getItem($pk = null)
 {
     $id = $pk ? $pk : $this->getState($this->getName() . '.id');
     // $item = parent::getItem($id);
     // if transaction is made and user is not created
     $transaction = JTable::getInstance('Transaction', 'RSMembershipTable');
     $transaction->load($id);
     /// get the user data
     $data = $transaction->user_data ? (object) unserialize($transaction->user_data) : (object) array();
     if (!$transaction->user_id) {
         $user = (object) array('id' => 0, 'username' => isset($data->username) && !empty($data->username) ? $data->username : JText::_('COM_RSMEMBERSHIP_SUBSCRIBERNAME_EMPTY'), 'name' => isset($data->name) ? $data->name : '', 'email' => $transaction->user_email);
     } else {
         $user = JFactory::getUser($transaction->user_id);
     }
     $params = RSMembershipHelper::parseParams($transaction->params);
     $membership_id = 0;
     if (isset($params['membership_id'])) {
         $membership_id = $params['membership_id'];
     }
     if (isset($params['to_id'])) {
         $membership_id = $params['to_id'];
     }
     $membership_info = array();
     if ($membership_id) {
         if ($membership_fields = RSMembership::getCustomMembershipFields($membership_id)) {
             $selected = isset($data->membership_fields) ? $data->membership_fields : array();
             foreach ($membership_fields as $field) {
                 $membership_info[] = RSMembershipHelper::showCustomField($field, $selected, false, false, 'membership');
             }
         }
     }
     $item = (object) array('user_id' => $user->id, 'username' => $user->username, 'email' => $user->email, 'name' => $user->name, 'transaction' => $id, 'transaction_data' => $transaction, 'membership_info' => $membership_info);
     return $item;
 }
Ejemplo n.º 2
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     // get parameters
     $params = clone $app->getParams('com_rsmembership');
     $pathway = $app->getPathway();
     $pathway->addItem(JText::_('COM_RSMEMBERSHIP_RENEW'), '');
     // get the logged user
     $this->user = JFactory::getUser();
     // get the current layout
     $layout = $this->getLayout();
     if ($layout == 'default') {
         $this->payments = RSMembership::getPlugins();
         // get the encoded return url
         $this->return = base64_encode(JURI::getInstance());
         $this->data = $this->get('data');
         // get the membership
         $this->membership = $this->get('membership');
         $this->membershipterms = $this->get('membershipterms');
         $this->fields = RSMembershipHelper::getFields(true);
         $this->fields_validation = RSMembershipHelper::getFieldsValidation($this->membership->id);
         $this->membership_fields = RSMembershipHelper::getMembershipFields($this->membership->id, true, $this->user->id, true, $this->membership->last_transaction_id);
     } elseif ($layout == 'payment') {
         $this->html = $this->get('html');
     }
     // get the extras
     $this->extras = $this->get('extras');
     $this->cid = $this->get('cid');
     $this->config = $this->get('config');
     $this->params = $params;
     $this->token = JHTML::_('form.token');
     $this->currency = RSMembershipHelper::getConfig('currency');
     parent::display();
 }
Ejemplo n.º 3
0
 function display($tpl = null)
 {
     $mainframe =& JFactory::getApplication();
     // get parameters
     $params = clone $mainframe->getParams('com_rsmembership');
     $pathway =& $mainframe->getPathway();
     $pathway->addItem(JText::_('RSM_RENEW'), '');
     // token
     $token = JHTML::_('form.token');
     // get the current layout
     $layout = $this->getLayout();
     if ($layout == 'default') {
         $this->assign('payments', RSMembership::getPlugins());
         // get the encoded return url
         $return = base64_encode(JRequest::getURI());
         $this->assignRef('return', $return);
         $data = $this->get('data');
         $this->assignRef('data', $data);
         // get the membership
         $membership = $this->get('membership');
         $this->assignRef('membership', $membership);
         $this->assignRef('fields', RSMembershipHelper::getFields(false));
     } elseif ($layout == 'payment') {
         $this->assignRef('html', $this->get('html'));
     }
     // get the extra
     $this->assignRef('extra', $this->get('extra'));
     $this->assignRef('cid', $this->get('cid'));
     $this->assignRef('config', $this->get('config'));
     $this->assignRef('params', $params);
     $this->assignRef('user', $this->get('user'));
     $this->assignRef('token', $token);
     $this->assign('currency', RSMembershipHelper::getConfig('currency'));
     parent::display();
 }
Ejemplo n.º 4
0
 public function getItem($pk = null)
 {
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $item = parent::getItem();
     $query->select('*')->from($db->qn('#__rsmembership_extra_value_shared'))->where($db->qn('extra_value_id') . ' = ' . $db->q($item->id))->order($db->qn('ordering') . ' ASC');
     $db->setQuery($query);
     $item->shared = $db->loadObjectList();
     foreach ($item->shared as $s => $shared) {
         switch ($shared->type) {
             default:
                 $instances = RSMembership::getSharedContentPlugins();
                 foreach ($instances as $instance) {
                     if (method_exists($instance, 'showUserFriendlyParams')) {
                         $instance->showUserFriendlyParams($shared);
                     }
                 }
                 $item->shared[$s] = $shared;
                 break;
             case 'article':
                 $query->clear();
                 $query->select($db->qn('title'))->from($db->qn('#__content'))->where($db->qn('id') . ' = ' . $db->q((int) $shared->params));
                 $db->setQuery($query);
                 $item->shared[$s]->params = $db->loadResult();
                 break;
             case 'module':
                 $query->clear();
                 $query->select($db->qn('title') . ', ' . $db->qn('module'))->from($db->qn('#__modules'))->where($db->qn('id') . ' = ' . $db->q((int) $shared->params));
                 $db->setQuery($query);
                 $module = $db->loadObject();
                 $item->shared[$s]->params = '(' . $module->module . ') ' . $module->title;
                 break;
             case 'menu':
                 $query->clear();
                 $query->select($db->qn('title', 'name') . ', ' . $db->qn('menutype'))->from($db->qn('#__menu'))->where($db->qn('id') . ' = ' . $db->q((int) $shared->params));
                 $db->setQuery($query);
                 $menu = $db->loadObject();
                 $item->shared[$s]->params = '(' . $menu->menutype . ') ' . $menu->name;
                 break;
             case 'section':
                 $query->clear();
                 $query->select($db->qn('title'))->from($db->qn('#__sections'))->where($db->qn('id') . ' = ' . $db->q((int) $shared->params));
                 $db->setQuery($query);
                 $item->shared[$s]->params = $db->loadResult();
                 break;
             case 'category':
                 $query->clear();
                 $query->select($db->qn('title'))->from($db->qn('#__categories'))->where($db->qn('id') . ' = ' . $db->q((int) $shared->params));
                 $db->setQuery($query);
                 $item->shared[$s]->params = $db->loadResult();
                 break;
         }
     }
     jimport('joomla.html.pagination');
     $item->sharedPagination = new JPagination(count($item->shared), 0, 0);
     return $item;
 }
Ejemplo n.º 5
0
 function getLimitations()
 {
     $plugins = RSMembership::getPlugins();
     $return = array();
     foreach ($plugins as $paymentplugin => $plugin) {
         $return[$paymentplugin] = '';
     }
     return $return;
 }
Ejemplo n.º 6
0
 protected function addOurPayments()
 {
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $query->select('*')->from($db->qn('#__rsmembership_payments'))->where($db->qn('published') . ' = ' . $db->q('1'))->order($db->qn('ordering') . ' ASC');
     $db->setQuery($query);
     $payments = $db->loadObjectList();
     foreach ($payments as $payment) {
         RSMembership::addPlugin($this->getTranslation($payment->name), 'rsmembershipwire' . $payment->id);
     }
 }
Ejemplo n.º 7
0
 protected function getPlaceholders($type)
 {
     $placeholders = array();
     switch ($type) {
         case 'thankyou':
             $placeholders = array('{membership}', '{extras}', '{email}', '{name}', '{username}', '{continue}', '{price}', '{coupon}', '{payment}', '{transaction_id}');
             break;
         case 'admin_email_new':
         case 'admin_email_renew':
         case 'admin_email_addextra':
         case 'user_email_new':
         case 'user_email_renew':
         case 'user_email_addextra':
             $placeholders = array('{membership}', '{extras}', '{email}', '{name}', '{username}', '{price}', '{coupon}', '{payment}', '{transaction_id}');
             break;
         case 'admin_email_upgrade':
         case 'user_email_upgrade':
             $placeholders = array('{membership}', '{membership_from}', '{extras}', '{email}', '{name}', '{username}', '{price}', '{coupon}', '{payment}', '{transaction_id}');
             break;
         case 'admin_email_expire':
         case 'user_email_expire':
             $placeholders = array('{membership}', '{membership_end}', '{extras}', '{email}', '{name}', '{username}', '{interval}');
             break;
         case 'admin_email_denied':
         case 'user_email_denied':
             $placeholders = array('{membership}', '{email}', '{username}', '{name}', '{price}', '{coupon}', '{payment}', '{transaction_id}');
             break;
         case 'admin_email_approved':
         case 'user_email_approved':
             $placeholders = array('{membership}', '{price}', '{extras}', '{email}', '{username}', '{name}', '{membership_start}', '{membership_end}', '{transaction_id}', '{transaction_hash}');
             break;
     }
     // Get cached custom fields
     static $fields = array();
     static $membership_fields = array();
     if (!$fields) {
         $fields = RSMembership::getCustomFields();
     }
     if (!$membership_fields) {
         $membership_fields = RSMembership::getCustomMembershipFields($this->item->id);
     }
     // Add custom fields
     foreach ($fields as $field) {
         $placeholders[] = '{' . $field->name . '}';
     }
     // Add membership fields
     foreach ($membership_fields as $membership_field) {
         $placeholders[] = '{' . $membership_field->name . '}';
     }
     return implode(', ', $placeholders);
 }
Ejemplo n.º 8
0
 public function save($data)
 {
     $jinput = JFactory::getApplication()->input;
     $user_id = $jinput->get('id', 0, 'int');
     $user_data = $jinput->get('u', array(), 'array');
     $fields = $jinput->get('rsm_fields', array(), 'post');
     $ourtable = $this->getTable();
     RSMembership::createUserData((int) $user_id, $fields);
     $user = JFactory::getUser($user_id);
     $user->bind($user_data);
     $user->save();
     $this->_id = $user->get('id');
     return true;
 }
Ejemplo n.º 9
0
 function plgSystemRSMembershipWire(&$subject, $config)
 {
     parent::__construct($subject, $config);
     jimport('joomla.html.parameter');
     $this->_plugin =& JPluginHelper::getPlugin('system', 'rsmembershipwire');
     $this->_params = new JParameter($this->_plugin->params);
     if (!$this->canRun()) {
         return;
     }
     $db =& JFactory::getDBO();
     $db->setQuery("SELECT * FROM #__rsmembership_payments ORDER BY `ordering`");
     $payments = $db->loadObjectList();
     foreach ($payments as $payment) {
         RSMembership::addPlugin($payment->name, 'rsmembershipwire' . $payment->id);
     }
 }
Ejemplo n.º 10
0
 public function display($tpl = null)
 {
     require_once JPATH_COMPONENT . '/helpers/rsmembership.php';
     $this->items = $this->get('Items');
     $this->pagination = $this->get('Pagination');
     $this->state = $this->get('State');
     $this->customFields = RSMembership::getCustomFields(array('showinsubscribers' => 1));
     $this->totalItems = $this->get('TotalItems');
     $this->addToolbar();
     $this->filterbar = $this->get('FilterBar');
     $this->sidebar = $this->get('SideBar');
     $document = JFactory::getDocument();
     $document->addScript('components/com_rsmembership/assets/js/export.js');
     $document->addScriptDeclaration("function rsmem_get_lang(id) {\r\n\t\t\tswitch (id)\r\n\t\t\t{\r\n\t\t\t\tdefault: return id;\r\n\t\t\t\tcase 'COM_RSMEMBERSHIP_EXPORT_NO_DATA': return '" . JText::_('COM_RSMEMBERSHIP_EXPORT_NO_DATA', true) . "'; break;\t\r\n\t\t\t}\r\n\t\t}");
     parent::display($tpl);
 }
Ejemplo n.º 11
0
 function onAfterInitialise()
 {
     if (class_exists('RSMembershipHelper')) {
         $this->loadLanguage('plg_system_rsmembership');
         $db = JFactory::getDBO();
         $date = JFactory::getDate();
         $date = $date->toUnix();
         if (RSMembershipHelper::getConfig('last_check') + RSMembershipHelper::getConfig('interval') * 60 > $date) {
             return;
         }
         $db->setQuery("UPDATE #__rsmembership_configuration SET value='" . $date . "' WHERE name='last_check' LIMIT 1");
         $db->query();
         $offset = RSMembershipHelper::getConfig('delete_pending_after');
         if ($offset < 1) {
             $offset = 1;
         }
         $offset = $offset * 3600;
         $db->setQuery("DELETE FROM #__rsmembership_transactions WHERE `status`='pending' AND `date` < '" . ($date - $offset) . "'");
         $db->query();
         // Limit 10 so we don't overload the server
         $db->setQuery("SELECT mu.id, m.gid_enable, m.gid_expire, m.disable_expired_account, mu.user_id FROM #__rsmembership_membership_users mu LEFT JOIN #__rsmembership_memberships m ON (mu.membership_id=m.id) WHERE  mu.`status`='0' AND mu.`membership_end` > 0 AND mu.`membership_end` < '" . $date . "' LIMIT 10");
         $updates = $db->loadObjectList();
         $to_update = array();
         foreach ($updates as $update) {
             $to_update[] = $update->id;
             if ($update->gid_enable) {
                 RSMembership::updateGid($update->user_id, $update->gid_expire);
             }
             if ($update->disable_expired_account) {
                 RSMembership::disableUser($update->user_id);
             }
         }
         if (!empty($to_update)) {
             $db->setQuery("UPDATE #__rsmembership_membership_users SET `status`='2' WHERE `id` IN (" . implode(',', $to_update) . ")");
             $db->query();
         }
         RSMembershipHelper::checkShared();
         RSMembershipHelper::sendExpirationEmails();
     }
 }
Ejemplo n.º 12
0
Archivo: user.php Proyecto: JozefAB/qk
 function _bindData($verbose = true)
 {
     $return = true;
     $rsm_fields = JFactory::getApplication()->input->get('rsm_fields', array(), 'array');
     if (empty($rsm_fields)) {
         return false;
     }
     $fields = RSMembership::getCustomFields(array('published' => 1, 'required' => 1));
     foreach ($fields as $field) {
         if ($field->required && empty($rsm_fields[$field->name]) || !empty($rsm_fields[$field->name]) && $field->rule && is_callable('RSMembershipValidation', $field->rule) && !call_user_func(array('RSMembershipValidation', $field->rule), $rsm_fields[$field->name])) {
             $validation_message = JText::_($field->validation);
             if (empty($validation_message)) {
                 $validation_message = JText::sprintf('COM_RSMEMBERSHIP_VALIDATION_DEFAULT_ERROR', JText::_($field->label));
             }
             if ($verbose) {
                 JError::raiseWarning(500, $validation_message);
             }
             $return = false;
         }
     }
     return $return;
 }
Ejemplo n.º 13
0
 function display($tpl = null)
 {
     $app = JFactory::getApplication();
     // get parameters
     $params = clone $app->getParams('com_rsmembership');
     $pathway = $app->getPathway();
     $pathway->addItem(JText::_('COM_RSMEMBERSHIP_UPGRADE'), '');
     // token
     $token = JHTML::_('form.token');
     // get the logged user
     $this->user = JFactory::getUser();
     // the new membership id
     $this->cid = $this->get('cid');
     // get the current layout
     $layout = $this->getLayout();
     if ($layout == 'default') {
         $this->payments = RSMembership::getPlugins();
         // get the encoded return url
         $this->return = base64_encode(JURI::getInstance());
         $this->data = $this->get('data');
         // get the upgrade
         $this->upgrade = $this->get('upgrade');
         // price
         $this->total = RSMembershipHelper::getPriceFormat($this->upgrade->price);
         $this->fields = RSMembershipHelper::getFields(true);
         $this->fields_validation = RSMembershipHelper::getFieldsValidation($this->upgrade->membership_to_id);
         $this->membership_fields = RSMembershipHelper::getMembershipFields($this->upgrade->membership_to_id, true, $this->user->id, true);
         $this->membershipterms = $this->get('membershipterms');
     } elseif ($layout == 'payment') {
         $this->html = $this->get('html');
     }
     $this->config = RSMembershipHelper::getConfig();
     $this->params = $params;
     $this->token = $token;
     $this->currency = RSMembershipHelper::getConfig('currency');
     parent::display();
 }
Ejemplo n.º 14
0
 public function getItem($pk = null)
 {
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $item = parent::getItem($pk);
     $item->period_values[] = $item->period_type;
     $item->period_values[] = $item->period;
     $item->trial_period_values[] = $item->trial_period_type;
     $item->trial_period_values[] = $item->trial_period;
     $item->fixed_expiry_values[] = $item->fixed_day;
     $item->fixed_expiry_values[] = $item->fixed_month;
     $item->fixed_expiry_values[] = $item->fixed_year;
     $item->fixed_expiry_values[] = $item->fixed_expiry;
     $item->thumb_resize = $item->thumb_w;
     $query->select($db->qn('extra_id'))->from($db->qn('#__rsmembership_membership_extras'))->where($db->qn('membership_id') . ' = ' . $db->q($item->id));
     $db->setQuery($query);
     $item->extras = $db->loadColumn();
     $instances = RSMembership::getSharedContentPlugins();
     $query->clear();
     $query->select('*')->from($db->qn('#__rsmembership_membership_shared'))->where($db->qn('membership_id') . ' = ' . $db->q($item->id))->order($db->qn('ordering') . ' ASC');
     $db->setQuery($query);
     $item->shared = $db->loadObjectList();
     foreach ($item->shared as $s => $shared) {
         switch ($shared->type) {
             default:
                 foreach ($instances as $instance) {
                     if (method_exists($instance, 'showUserFriendlyParams')) {
                         $instance->showUserFriendlyParams($shared);
                     }
                 }
                 $item->shared[$s] = $shared;
                 break;
             case 'article':
                 $query->clear();
                 $query->select('title')->from($db->qn('#__content'))->where($db->qn('id') . ' = ' . $db->q($shared->params));
                 $db->setQuery($query);
                 $item->shared[$s]->params = $db->loadResult();
                 break;
             case 'category':
                 $query->clear();
                 $query->select('title')->from($db->qn('#__categories'))->where($db->qn('id') . ' = ' . $db->q($shared->params));
                 $db->setQuery($query);
                 $item->shared[$s]->params = $db->loadResult();
                 break;
             case 'module':
                 $query->clear();
                 $query->select($db->qn('title') . ', ' . $db->qn('module'))->from($db->qn('#__modules'))->where($db->qn('id') . ' = ' . $db->q($shared->params));
                 $db->execute();
                 $module = $db->loadObject();
                 $item->shared[$s]->params = '(' . $module->module . ') ' . $module->title;
                 break;
             case 'menu':
                 $query->clear();
                 $query->select($db->qn('title', 'name') . ', ' . $db->qn('menutype'))->from($db->qn('#__menu'))->where($db->qn('id') . ' = ' . $db->q($shared->params));
                 $db->setQuery($query);
                 $menu = $db->loadObject();
                 $item->shared[$s]->params = '(' . $menu->menutype . ') ' . $menu->name;
                 break;
         }
     }
     jimport('joomla.html.pagination');
     $item->sharedPagination = new JPagination(count($item->shared), 0, 0);
     // attachments
     $query->clear();
     $query->select('*')->from($db->qn('#__rsmembership_membership_attachments'))->where($db->qn('membership_id') . ' = ' . $db->q($item->id))->order($db->qn('ordering') . ' ASC');
     $db->setQuery($query);
     $attachments = $db->loadObjectList();
     $this->attachments = array();
     $this->attachmentsPagination = null;
     foreach ($attachments as $attachment) {
         $this->attachments[$attachment->email_type][] = $attachment;
     }
     foreach ($this->attachments as $email_type => $attachments) {
         $this->attachmentsPagination[$email_type] = new JPagination(count($attachments), 0, 0);
     }
     return $item;
 }
Ejemplo n.º 15
0
 public function getSideBar()
 {
     require_once JPATH_COMPONENT . '/helpers/toolbar.php';
     // Transaction Types filter
     $options['filter_type'] = $this->getState($this->context . '.filter.filter_type');
     $options['transaction_types'] = array(JHtml::_('select.option', '', JText::_('COM_RSMEMBERSHIP_TRANSACTION_ALL_TYPES')), JHtml::_('select.option', 'new', JText::_('COM_RSMEMBERSHIP_TRANSACTION_NEW')), JHtml::_('select.option', 'renew', JText::_('COM_RSMEMBERSHIP_TRANSACTION_RENEW')), JHtml::_('select.option', 'upgrade', JText::_('COM_RSMEMBERSHIP_TRANSACTION_UPGRADE')), JHtml::_('select.option', 'addextra', JText::_('COM_RSMEMBERSHIP_TRANSACTION_ADDEXTRA')));
     // Gateway filter
     $options['filter_gateway'] = $this->getState($this->context . '.filter.filter_gateway');
     $options['gateways'] = array(JHtml::_('select.option', '', JText::_('COM_RSMEMBERSHIP_TRANSACTION_ALL_GATEWAYS')), JHtml::_('select.option', 'No Gateway', JText::_('COM_RSMEMBERSHIP_NO_GATEWAY')));
     $gateways = RSMembership::getPlugins();
     foreach ($gateways as $plugin => $name) {
         if ($name == 'Credit Card') {
             $name = 'Authorize.Net';
         }
         $options['gateways'][] = JHtml::_('select.option', $name, $name);
     }
     // Status filter
     $options['filter_status'] = $this->getState($this->context . '.filter.filter_status');
     $statuses = array('pending', 'completed', 'denied');
     $options['statuses'] = array(JHtml::_('select.option', '', JText::_('COM_RSMEMBERSHIP_TRANSACTION_ALL_STATUSES')));
     foreach ($statuses as $status) {
         $options['statuses'][] = JHtml::_('select.option', $status, JText::_('COM_RSMEMBERSHIP_TRANSACTION_STATUS_' . $status));
     }
     RSMembershipToolbarHelper::addFilter(JText::_('COM_RSMEMBERSHIP_SELECT_STATUS'), 'filter_status', JHtml::_('select.options', $options['statuses'], 'value', 'text', $options['filter_status'], true));
     RSMembershipToolbarHelper::addFilter(JText::_('COM_RSMEMBERSHIP_SELECT_GATEWAY'), 'filter_gateway', JHtml::_('select.options', $options['gateways'], 'value', 'text', $options['filter_gateway'], false));
     RSMembershipToolbarHelper::addFilter(JText::_('COM_RSMEMBERSHIP_SELECT_TYPE'), 'filter_type', JHtml::_('select.options', $options['transaction_types'], 'value', 'text', $options['filter_type'], false));
     // Custom filters
     // Date from
     $options['date_from'] = $this->getState($this->context . '.filter.date_from');
     RSMembershipToolbarHelper::addFilter(JText::_('COM_RSMEMBERSHIP_FROM'), 'date_from', $options['date_from'], 'calendar');
     // Date to
     $options['date_to'] = $this->getState($this->context . '.filter.date_to');
     RSMembershipToolbarHelper::addFilter(JText::_('COM_RSMEMBERSHIP_TO'), 'date_to', $options['date_to'], 'calendar');
     // Calendar buttons
     $options['calendar_btn'] = array('from_btn' => 'date_from', 'to_btn' => 'date_to', 'filter_desc' => JText::_('COM_RSMEMBERSHIP_FILTER_DESC'));
     RSMembershipToolbarHelper::addFilter(JText::_('COM_RSMEMBERSHIP_FILTER'), JText::_('COM_RSMEMBERSHIP_FILTER_DESC'), $options['calendar_btn'], 'calendar_btn');
     return RSMembershipToolbarHelper::render();
 }
Ejemplo n.º 16
0
 function _execute()
 {
     $mainframe =& JFactory::getApplication();
     $option = 'com_rsmembership';
     $task = JRequest::getVar('task', '');
     if ($task == 'subscribe') {
         $this->_bindId();
         $this->_bindExtras();
     } else {
         // get the already bound items
         if ($task == 'validatesubscribe') {
             $this->_bindData(false);
         }
         $this->_setId();
         $this->_setExtras();
         $this->_setData();
         if ($task == 'payment') {
             // empty session
             $this->_emptySession();
             $extras = $this->getExtras();
             $membership = $this->getMembership();
             $paymentplugin = JRequest::getCmd('payment', 'none');
             // calculate the total price
             $total = 0;
             $total += $membership->price;
             foreach ($extras as $extra) {
                 $total += $extra->price;
             }
             $user =& JFactory::getUser();
             if (!$user->get('guest')) {
                 $user_id = $user->get('id');
                 RSMembership::createUserData($user_id, @$this->_data->fields);
             } else {
                 if (RSMembershipHelper::getConfig('create_user_instantly')) {
                     $user_id = RSMembership::createUser($this->_data->email, $this->_data);
                 } else {
                     $user_id = 0;
                 }
             }
             $row =& JTable::getInstance('RSMembership_Transactions', 'Table');
             $row->user_id = $user_id;
             $row->user_email = $this->_data->email;
             $data = new stdClass();
             $data->name = $this->_data->name;
             $data->username = isset($this->_data->username) ? $this->_data->username : '';
             if (isset($this->_data->password)) {
                 $data->password = $this->_data->password;
             }
             $data->fields = $this->_data->fields;
             $row->user_data = serialize($data);
             $row->type = 'new';
             $params = array();
             $params[] = 'membership_id=' . $membership->id;
             if (is_array($this->_extras) && !empty($this->_extras)) {
                 $params[] = 'extras=' . implode(',', $this->_extras);
             }
             $row->params = implode(';', $params);
             // params, membership, extras etc
             $date = JFactory::getDate();
             $row->date = $date->toUnix();
             $row->ip = $_SERVER['REMOTE_ADDR'];
             $row->price = $total;
             $row->coupon = $this->getCoupon();
             $row->currency = RSMembershipHelper::getConfig('currency');
             $row->hash = '';
             $row->gateway = $paymentplugin == 'none' ? 'No Gateway' : RSMembership::getPlugin($paymentplugin);
             $row->status = 'pending';
             $this->_html = '';
             // trigger the payment plugin
             $paymentpluginClass = $paymentplugin;
             if (preg_match('#rsmembershipwire([0-9]+)#', $paymentplugin, $match)) {
                 $paymentpluginClass = 'rsmembershipwire';
             }
             $className = 'plgSystem' . $paymentpluginClass;
             $delay = false;
             if (class_exists($className)) {
                 $dispatcher =& JDispatcher::getInstance();
                 $plugin = new $className($dispatcher, array());
                 $args = array('plugin' => $paymentplugin, 'data' => &$this->_data, 'extras' => $extras, 'membership' => $membership, 'transaction' => &$row);
                 if (method_exists($plugin, 'onMembershipPayment')) {
                     $this->_html = call_user_func_array(array($plugin, 'onMembershipPayment'), $args);
                 }
                 if (method_exists($plugin, 'hasDelayTransactionStoring')) {
                     $delay = $plugin->hasDelayTransactionStoring();
                     if (method_exists($plugin, 'delayTransactionStoring')) {
                         $plugin->delayTransactionStoring($row->getProperties());
                     }
                 }
             }
             // plugin can delay the transaction storing
             if (!$delay) {
                 // store the transaction
                 $row->store();
                 // store the transaction id
                 $this->transaction_id = $row->id;
                 // finalize the transaction (send emails)
                 RSMembership::finalize($this->transaction_id);
                 // approve the transaction
                 if ($row->status == 'completed' || $row->price == 0 && $membership->activation != 0) {
                     RSMembership::approve($this->transaction_id, true);
                 }
                 if ($row->price == 0) {
                     $mainframe->redirect(JRoute::_('index.php?option=com_rsmembership&task=thankyou', false));
                 }
             }
         }
     }
 }
Ejemplo n.º 17
0
 public function sendNotification($pks)
 {
     require_once JPATH_ADMINISTRATOR . '/components/com_rsmembership/helpers/rsmembership.php';
     // Get custom fields
     $db = JFactory::getDBO();
     $table = $this->getTable();
     $query = $db->getQuery(true);
     $pks = (array) $pks;
     foreach ($pks as $i => $pk) {
         if ($table->load($pk)) {
             // Load specific membership
             $query->select('*')->from($db->qn('#__rsmembership_memberships'))->where('(' . $db->qn('user_email_from_addr') . ' != ' . $db->q('') . ' OR ' . $db->qn('user_email_use_global') . ' = ' . $db->q(1) . ')')->where($db->qn('published') . ' = ' . $db->q(1))->where($db->qn('id') . ' = ' . $db->q($table->membership_id));
             $db->setQuery($query);
             $memberships = $db->loadObjectList();
             $sent = RSMembership::sendNotifications($memberships, array($pk), true);
             $query->clear();
             return $sent;
         }
     }
     $this->cleanCache();
     return true;
 }
Ejemplo n.º 18
0
 function display($tpl = null)
 {
     $mainframe =& JFactory::getApplication();
     // get parameters
     $params = clone $mainframe->getParams('com_rsmembership');
     // get the membership
     $membership = $this->get('membership');
     // check if the membership exists
     if (empty($membership->id)) {
         JError::raiseWarning(500, JText::_('RSM_MEMBERSHIP_NOT_EXIST'));
         $mainframe->redirect(JRoute::_('index.php?option=com_rsmembership', false));
     }
     if (!$membership->published || $membership->stock == -1) {
         JError::raiseWarning(500, JText::_('RSM_MEMBERSHIP_NOT_PUBLISHED'));
         $mainframe->redirect(JRoute::_('index.php?option=com_rsmembership', false));
     }
     $pathway =& $mainframe->getPathway();
     $pathway->addItem($membership->name, JRoute::_('index.php?option=com_rsmembership&view=membership&cid=' . $membership->id . ':' . JFilterOutput::stringURLSafe($membership->name)));
     $pathway->addItem(JText::_('RSM_SUBSCRIBE'), '');
     // get the extras
     $extras = $this->get('extras');
     // check if the user is logged in
     $user =& JFactory::getUser();
     $logged = $user->get('guest') ? false : true;
     $show_login = RSMembershipHelper::getConfig('show_login');
     // token
     $token = JHTML::_('form.token');
     // get the current task
     $task = JRequest::getVar('task', '');
     $choose_username = RSMembershipHelper::getConfig('choose_username');
     $choose_password = RSMembershipHelper::getConfig('choose_password');
     // get the current layout
     $layout = $this->getLayout();
     if ($layout == 'default') {
         // get the encoded return url
         $return = base64_encode(JRequest::getURI());
         $this->assignRef('return', $return);
         $this->assign('choose_username', $choose_username);
         $this->assign('choose_password', $choose_password);
         $muser = $this->get('user');
         $data = $this->get('data');
         if ($task == 'back' || $task == 'validatesubscribe') {
             $this->assignRef('data', $data);
         }
         $this->assignRef('fields_validation', RSMembershipHelper::getFieldsValidation());
         $this->assignRef('fields', RSMembershipHelper::getFields());
         $this->assign('use_captcha', $this->get('usecaptcha'));
         $this->assign('use_builtin', $this->get('usebuiltin'));
         $this->assign('use_recaptcha', $this->get('userecaptcha'));
         if ($this->get('userecaptcha')) {
             if (!class_exists('JReCAPTCHA')) {
                 require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_rsmembership' . DS . 'helpers' . DS . 'recaptcha' . DS . 'recaptchalib.php';
             }
             $this->assign('show_recaptcha', JReCAPTCHA::getHTML($this->get('recaptchaerror')));
         }
         $this->assign('has_coupons', $this->get('hasCoupons'));
     } elseif ($layout == 'preview') {
         $this->assign('choose_username', $choose_username);
         $this->assign('choose_password', $choose_password);
         $this->assignRef('fields', RSMembershipHelper::getFields(false));
         $this->assign('payments', RSMembership::getPlugins());
         $data = $this->get('data');
         $this->assignRef('data', $data);
     } elseif ($layout == 'payment') {
         $this->assignRef('html', $this->get('html'));
     }
     $this->assignRef('config', $this->get('config'));
     $this->assignRef('params', $params);
     $this->assignRef('membership', $membership);
     $this->assignRef('membershipterms', $this->get('membershipterms'));
     $this->assignRef('extras', $extras);
     $this->assignRef('logged', $logged);
     $this->assignRef('show_login', $show_login);
     $this->assignRef('user', $user);
     $this->assignRef('muser', $muser);
     $this->assignRef('token', $token);
     $this->assign('currency', RSMembershipHelper::getConfig('currency'));
     $this->assign('one_page_checkout', RSMembershipHelper::getConfig('one_page_checkout'));
     if ($this->one_page_checkout) {
         $this->assign('payments', RSMembership::getPlugins());
     }
     $total = 0;
     $total += $membership->price;
     if ($extras) {
         foreach ($extras as $extra) {
             $total += $extra->price;
         }
     }
     $this->assign('total', $total);
     parent::display();
 }
 function onAfterRoute()
 {
     $app =& JFactory::getApplication();
     if ($app->isAdmin()) {
         return;
     }
     if (JRequest::getVar('authorizepayment')) {
         return $this->onPaymentNotification();
     }
     $option = JRequest::getVar('option');
     $task = JRequest::getCmd('plugin_task');
     $membership_id = JRequest::getInt('membership_id');
     if ($option == 'com_rsmembership' && $task == 'authorize') {
         @ob_end_clean();
         $db =& JFactory::getDBO();
         $db->setQuery("SELECT * FROM #__rsmembership_memberships WHERE `id`='" . $membership_id . "'");
         $membership = $db->loadObject();
         JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_rsmembership' . DS . 'tables');
         $row =& JTable::getInstance('RSMembership_Transactions', 'Table');
         $transaction = $this->getDelayedTransaction();
         if (empty($transaction)) {
             $app->enqueueMessage('RSM_SESSION_EXPIRED', 'error');
             echo 'RSM_SESSION_END';
             die;
         }
         $row->bind($transaction);
         $row->store();
         $row->price += $this->_getTax($row->price);
         $row->price = $this->_convertNumber($row->price);
         $transaction['id'] = $row->id;
         $this->delayTransactionStoring($transaction);
         $description = $this->_params->get('message_type') ? $membership->name : JText::sprintf('RSM_MEMBERSHIP_PURCHASE_ON', date(RSMembershipHelper::getConfig('date_format'), $row->date));
         $post_url = $this->_params->get('mode') ? "https://secure.authorize.net/gateway/transact.dll" : "https://test.authorize.net/gateway/transact.dll";
         $is_recurring = $membership->recurring && $membership->period > 0 && $row->type == 'new';
         $cc_number = JRequest::getCmd('cc_number', '', 'post');
         $cc_expiration = substr(JRequest::getCmd('cc_exp_mm', '', 'post'), 0, 2) . '-' . JRequest::getInt('cc_exp_yy', 0, 'post');
         $cc_fname = JRequest::getVar('cc_fname', '', 'post');
         $cc_lname = JRequest::getVar('cc_lname', '', 'post');
         $post_values = array("x_login" => $this->_params->get('x_login'), "x_tran_key" => $this->_params->get('x_tran_key'), "x_version" => "3.1", "x_delim_data" => "TRUE", "x_delim_char" => "|", "x_relay_response" => "FALSE", "x_type" => "AUTH_CAPTURE", "x_method" => "CC", "x_card_num" => $cc_number, "x_exp_date" => $cc_expiration, "x_card_code" => JRequest::getVar('csc_number', '', 'post'), "x_amount" => $row->price, "x_currency_code" => RSMembershipHelper::getConfig('currency'), "x_invoice_num" => md5($row->id . ' ' . $this->_params->get('x_login') . ' ' . $this->_params->get('x_tran_key')), "x_description" => $description, "x_first_name" => $cc_fname, "x_last_name" => $cc_lname, "x_email" => $row->get('user_email'), "x_address" => '', "x_state" => '', "x_zip" => '');
         $string = '';
         foreach ($post_values as $key => $value) {
             $string .= "{$key}=" . urlencode($value) . "&";
         }
         $string = rtrim($string, "& ");
         unset($post_values);
         if (!function_exists('curl_init')) {
             echo JHTML::image('plugins/system/' . $this->joomla16prefix . 'rsmembershipauthorize/images/error.png', 'Error', array('id' => 'rsm_warning')) . ' ' . JText::_('RSM_AUTHORIZE_CURL_ERROR');
         } else {
             $request = curl_init($post_url);
             curl_setopt($request, CURLOPT_HEADER, 0);
             curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($request, CURLOPT_POSTFIELDS, $string);
             curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE);
             $response = curl_exec($request);
             curl_close($request);
             // close curl object
             // This line takes the response and breaks it into an array using the specified delimiting character
             $response = explode('|', $response);
             if ($response[0] == 1) {
                 if (!$is_recurring) {
                     $this->emptyDelayedTransaction();
                     $row->hash = $response[6];
                     $row->store();
                     RSMembership::finalize($row->get('id'));
                     RSMembership::approve($row->get('id'));
                 } else {
                     list($length, $unit) = $this->_getAuthorizeLength($membership);
                     $date =& JFactory::getDate();
                     $startDate = date('Y-m-d', strtotime("+{$length} {$unit}", $date->toUnix()));
                     $extra_total = 0;
                     $params = RSMembershipHelper::parseParams($row->params);
                     if (!empty($params['extras'])) {
                         $db->setQuery("SELECT SUM(`price`) FROM #__rsmembership_extra_values WHERE `id` IN (" . implode(',', $params['extras']) . ")");
                         $extra_total = $db->loadResult();
                     }
                     $amount = $membership->use_renewal_price ? $membership->renewal_price : $membership->price;
                     $amount += $extra_total;
                     $amount += $this->_getTax($amount);
                     $trialOccurrences = $membership->use_trial_period ? 1 : 0;
                     $trialAmount = $membership->use_trial_period ? $membership->trial_price : 0;
                     $trialAmount += $extra_total;
                     $trialAmount += $this->_getTax($trialAmount);
                     $content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" . "<ARBCreateSubscriptionRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\">" . "<merchantAuthentication>" . "<name>" . $this->_params->get('x_login') . "</name>" . "<transactionKey>" . $this->_params->get('x_tran_key') . "</transactionKey>" . "</merchantAuthentication>" . "<refId>" . $row->id . "</refId>" . "<subscription>" . "<name>" . htmlentities($description, ENT_COMPAT, 'UTF-8') . "</name>" . "<paymentSchedule>" . "<interval>" . "<length>" . $length . "</length>" . "<unit>" . $unit . "</unit>" . "</interval>" . "<startDate>" . $startDate . "</startDate>" . "<totalOccurrences>9999</totalOccurrences>" . "<trialOccurrences>" . $trialOccurrences . "</trialOccurrences>" . "</paymentSchedule>" . "<amount>" . $amount . "</amount>" . "<trialAmount>" . $trialAmount . "</trialAmount>" . "<payment>" . "<creditCard>" . "<cardNumber>" . $cc_number . "</cardNumber>" . "<expirationDate>" . $cc_expiration . "</expirationDate>" . "</creditCard>" . "</payment>" . "<billTo>" . "<firstName>" . $cc_fname . "</firstName>" . "<lastName>" . $cc_lname . "</lastName>" . "</billTo>" . "</subscription>" . "</ARBCreateSubscriptionRequest>";
                     $post_url = $this->_params->get('mode') ? "https://api.authorize.net/xml/v1/request.api" : "https://apitest.authorize.net/xml/v1/request.api";
                     $ch = curl_init();
                     curl_setopt($ch, CURLOPT_URL, $post_url);
                     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
                     curl_setopt($ch, CURLOPT_HEADER, 1);
                     curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
                     curl_setopt($ch, CURLOPT_POST, 1);
                     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                     $response = curl_exec($ch);
                     if ($response) {
                         list($refId, $resultCode, $code, $text, $subscriptionId) = $this->_parseReturn($response);
                         if ($resultCode == 1) {
                             $this->emptyDelayedTransaction();
                             $row->custom = $subscriptionId;
                             $row->store();
                             RSMembership::finalize($row->get('id'));
                             RSMembership::approve($row->get('id'));
                         } else {
                             $image = $resultCode == 4 ? 'warning' : 'error';
                             if (!$text) {
                                 $text = explode("\r\n\r\n", $response, 2);
                                 $text = strip_tags($text[1]);
                             }
                             echo JHTML::image('plugins/system/' . $this->joomla16prefix . 'rsmembershipauthorize/images/' . $image . '.png', 'Information', array('id' => 'rsm_warning')) . ' ' . htmlentities($text, ENT_COMPAT, 'UTF-8');
                             die;
                         }
                     } else {
                         echo JHTML::image('plugins/system/' . $this->joomla16prefix . 'rsmembershipauthorize/images/error.png', 'Error') . ' ' . JText::_('RSM_AUTHORIZE_GENERAL_ERROR');
                         die;
                     }
                 }
                 echo 'RSM_AUTHORIZE_OK';
             } else {
                 $image = $response[0] == 4 ? 'warning' : 'error';
                 echo JHTML::image('plugins/system/' . $this->joomla16prefix . 'rsmembershipauthorize/images/' . $image . '.png', 'Information', array('id' => 'rsm_warning')) . ' ' . htmlentities($response[3], ENT_COMPAT, 'UTF-8');
             }
         }
         die;
     }
 }
Ejemplo n.º 20
0
 public function deny()
 {
     // Check for request forgeries
     JSession::checkToken() or jexit('Invalid Token');
     // Get the selected items
     $cid = JFactory::getApplication()->input->get('cid', array(), 'array');
     // Force array elements to be integers
     JArrayHelper::toInteger($cid, array(0));
     $msg = '';
     // No items are selected
     if (!is_array($cid) || count($cid) < 1) {
         JError::raiseWarning(500, JText::_('JERROR_NO_ITEMS_SELECTED'));
     } else {
         $user = JFactory::getUser();
         $user_id = $user->get('username');
         $total = 0;
         foreach ($cid as $id) {
             RSMembership::saveTransactionLog('Manually denied by ' . $user_id, $id);
             if (RSMembership::deny($id)) {
                 $total++;
             }
         }
         $msg = JText::sprintf('COM_RSMEMBERSHIP_TRANSACTIONS_DENIED', $total);
         // Clean the cache, if any
         $cache = JFactory::getCache('com_rsmembership');
         $cache->clean();
     }
     $this->setRedirect(JRoute::_('index.php?option=com_rsmembership&view=transactions', false), $msg);
 }
Ejemplo n.º 21
0
 public function idevCheckConnection()
 {
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $idev_url = JFactory::getApplication()->input->get('idev_url', '', 'string');
     if (!empty($idev_url)) {
         if (strlen($idev_url) > 5) {
             $idev_url = rtrim($idev_url, '/');
             $idev_url .= '/';
         }
         $config = RSMembershipConfig::getInstance();
         $config->set('idev_url', $idev_url);
     }
     $result = RSMembership::updateIdev(array('idev_saleamt' => 1.0, 'idev_ordernum' => 'test', 'ip_address' => '127.0.0.1'));
     if (!$result['success']) {
         JError::raiseWarning(500, JText::sprintf('COM_RSMEMBERSHIP_IDEV_COULD_NOT_CONNECT', $result['url'], !empty($result['error']) ? $result['error'] : JText::_('COM_RSMEMBERSHIP_UNKNOWN'), $result['code']));
         return false;
     }
     return true;
 }
Ejemplo n.º 22
0
 function idevCheckConnection()
 {
     $post = JRequest::get('post');
     if (isset($post['idev_url'])) {
         if (strlen($post['idev_url']) > 5) {
             $post['idev_url'] = rtrim($post['idev_url'], '/');
             $post['idev_url'] .= '/';
         }
         $this->_db->setQuery("UPDATE #__rsmembership_configuration SET `value`='" . $this->_db->getEscaped($post['idev_url']) . "' WHERE `name`='idev_url' LIMIT 1");
         $this->_db->query();
     }
     RSMembershipHelper::readConfig(true);
     $result = RSMembership::updateIdev(array('idev_saleamt' => 1.0, 'idev_ordernum' => 'test', 'ip_address' => '127.0.0.1'));
     if (!$result['success']) {
         JError::raiseWarning(500, JText::sprintf('RSM_IDEV_COULD_NOT_CONNECT', $result['url'], !empty($result['error']) ? $result['error'] : JText::_('RSM_UNKNOWN'), $result['code']));
         return false;
     }
     return true;
 }
Ejemplo n.º 23
0
 function save()
 {
     $user = JFactory::getUser();
     $fields = JRequest::getVar('rsm_fields', array(), 'post');
     RSMembership::createUserData($user->get('id'), $fields);
 }
Ejemplo n.º 24
0
Archivo: share.php Proyecto: JozefAB/qk
 public function getSortColumn()
 {
     $sortColumn = JFactory::getApplication()->input->get('filter_order', 'ordering', 'string');
     if ($this->_isPlugin()) {
         $instances = RSMembership::getSharedContentPlugins();
         foreach ($instances as $instance) {
             if (method_exists($instance, 'getSortColumn')) {
                 $instance->getSortColumn($this->getShareType(), $sortColumn);
             }
         }
     }
     return $sortColumn;
 }
Ejemplo n.º 25
0
 protected function sendExpirationEmails()
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $date = JFactory::getDate();
     $config = RSMembershipConfig::getInstance();
     // Check the last time this has been run
     $now = $date->toUnix();
     if ($now < $config->get('expire_last_run') + $config->get('expire_check_in') * 60) {
         return;
     }
     // update config value for last time the expiration emails were sent
     $config->set('expire_last_run', $now);
     // Get expiration intervals and memberships
     // Performance check - if no emails can be sent, no need to grab the membership
     $query->select('*')->from($db->qn('#__rsmembership_memberships'))->where('(' . $db->qn('user_email_from_addr') . ' != ' . $db->q('') . ' OR ' . $db->qn('user_email_use_global') . ' = ' . $db->q(1) . ')')->where($db->qn('published') . ' = ' . $db->q(1));
     $db->setQuery($query);
     $memberships = $db->loadObjectList();
     if ($memberships) {
         RSMembership::sendNotifications($memberships, null, false);
     }
 }
Ejemplo n.º 26
0
 protected function onPaymentNotification()
 {
     if (!$this->canRun()) {
         return;
     }
     ob_end_clean();
     $name = $this->getTranslation($this->params->get('payment_name', 'PayPal'));
     require_once JPATH_ADMINISTRATOR . '/components/com_rsmembership/helpers/adapters/input.php';
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $jinput = RSInput::create();
     $log = array();
     $req = $this->_buildPostData();
     $this->addLog("IPN received: {$req}");
     // post back to PayPal system to validate
     $url = $this->params->get('mode') ? 'https://www.paypal.com/cgi-bin/webscr' : 'https://www.sandbox.paypal.com/cgi-bin/webscr';
     $only_completed = (int) $this->params->get('only_completed', 0);
     if (!extension_loaded('curl') || !function_exists('curl_exec') || !is_callable('curl_exec')) {
         $this->addLog('[err] cURL is not installed or executable, cannot connect back to PayPal for validation!');
         $this->finish();
     }
     $this->addLog("Connecting to {$url} to verify if PayPal response is valid.");
     require_once JPATH_ADMINISTRATOR . '/components/com_rsmembership/helpers/version.php';
     $version = (string) new RSMembershipVersion();
     $website = JUri::root();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www.paypal.com'));
     curl_setopt($ch, CURLOPT_USERAGENT, "RSMembership!/{$version} ({$website})");
     $res = curl_exec($ch);
     $errstr = curl_error($ch);
     curl_close($ch);
     if ($errstr) {
         $this->addLog('[err] cURL reported error: ' . $errstr);
         $this->finish();
     }
     // assign posted variables to local variables
     $item_name = $jinput->get('item_name', '', 'none');
     $item_number = $jinput->get('item_number', '', 'none');
     $payment_status = $jinput->get('payment_status', '', 'none');
     $payment_amount = $jinput->get('mc_gross', '', 'none');
     $payment_currency = $jinput->get('mc_currency', '', 'none');
     $txn_id = $jinput->get('txn_id', '', 'none');
     $txn_type = $jinput->get('txn_type', '', 'none');
     $receiver_email = $jinput->get('receiver_email', '', 'none');
     $payer_email = $jinput->get('payer_email', '', 'none');
     $custom = $jinput->get('custom', 0, 'none');
     // try to get the transaction id based on the custom hash
     $transaction_id = $this->getTransactionId($custom);
     // Do not deny the transaction for now.
     $deny = false;
     $this->addLog("Transaction ID is '{$transaction_id}', based on '{$custom}'.");
     if ($res) {
         $this->addLog("Successfully connected to {$url}. Response is {$res}");
         if (strcmp($res, "VERIFIED") == 0) {
             $this->addLog("Response is VERIFIED.");
             $log[] = "PayPal reported a valid transaction.";
             $log[] = "Payment status is " . (!empty($payment_status) ? $payment_status : 'empty') . ".";
             // check the payment_status is Completed
             if (!$only_completed || $only_completed && $payment_status == 'Completed') {
                 // sign up - do nothing, we use our "custom" parameter to identify the transaction
                 if ($txn_type == 'subscr_signup') {
                     $log[] = "Subscription signup has been received.";
                     // If this is a free trial, we'll need to make sure that the transaction is accepted since "subscr_payment" will be received after the trial ends
                     $mc_amount1 = $jinput->get('mc_amount1', '', 'none');
                     $subscr_id = $jinput->get('subscr_id', '', 'none');
                     if ((double) $mc_amount1 == (double) $transaction->price && $mc_amount1 == '0.00') {
                         // Emulate the variables needed below to approve the transaction
                         // No txn_id here, let's just use subscr_id so we can use something for PayPal identification.
                         $txn_id = 'Subscription ID: ' . $subscr_id;
                         $payment_amount = $mc_amount1;
                         // Load the transaction so that it can be processed below
                         $transaction = $this->getTransaction($transaction_id, 'id');
                     }
                 } elseif ($txn_type == 'subscr_payment' || $txn_type == 'recurring_payment') {
                     $log[] = "Adding new payment...";
                     // check that txn_id has not been previously processed
                     // check custom_hash from db -> if custom_hash == txn_id
                     $query->clear();
                     $query->select($db->qn('id'))->from($db->qn('#__rsmembership_transactions'))->where($db->qn('hash') . ' = ' . $db->q($txn_id))->where($db->qn('gateway') . ' = ' . $db->q($name));
                     $db->setQuery($query);
                     if (!$db->loadResult()) {
                         $transaction = $this->getTransaction($custom);
                         // check if transaction exists
                         if (!empty($transaction)) {
                             // this transaction has already been processed
                             // we need to create a new "renewal" transaction
                             if ($transaction->status == 'completed') {
                                 $log[] = "Identified this payment as recurring.";
                                 $query->clear();
                                 $query->select($db->qn('id'))->select($db->qn('user_id'))->select($db->qn('membership_id'))->from($db->qn('#__rsmembership_membership_subscribers'))->where($db->qn('from_transaction_id') . ' = ' . $db->q($transaction->id));
                                 $db->setQuery($query);
                                 $membership = $db->loadObject();
                                 if (!empty($membership)) {
                                     $user = JFactory::getUser($membership->user_id);
                                     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_rsmembership/tables');
                                     $transaction = JTable::getInstance('Transaction', 'RSMembershipTable');
                                     $transaction->user_id = $user->get('id');
                                     $transaction->user_email = $user->get('email');
                                     $transaction->type = 'renew';
                                     $params = array();
                                     $params[] = 'id=' . $membership->id;
                                     $params[] = 'membership_id=' . $membership->membership_id;
                                     $transaction->params = implode(';', $params);
                                     // params, membership, extras etc
                                     $date = JFactory::getDate();
                                     $transaction->date = $date->toSql();
                                     $transaction->ip = $_SERVER['REMOTE_ADDR'];
                                     $transaction->price = $payment_amount;
                                     $transaction->currency = RSMembershipHelper::getConfig('currency');
                                     $transaction->hash = '';
                                     $transaction->gateway = $name;
                                     $transaction->status = 'pending';
                                     // store the transaction
                                     $transaction->store();
                                     RSMembership::finalize($transaction->id);
                                     $log[] = "Successfully added the recurring transaction to the database.";
                                 } else {
                                     $log[] = "Could not identify the original transaction for this recurring payment.";
                                 }
                             }
                         } else {
                             $log[] = "Could not identify transaction with custom hash {$custom}. Stopping.";
                         }
                     } else {
                         $log[] = "The transaction {$txn_id} has already been processed. Stopping.";
                     }
                 } else {
                     // check that txn_id has not been previously processed
                     // check custom_hash from db -> if custom_hash == txn_id
                     $query->clear();
                     $query->select($db->qn('id'))->from($db->qn('#__rsmembership_transactions'))->where($db->qn('hash') . ' = ' . $db->q($txn_id))->where($db->qn('gateway') . ' = ' . $db->q($name));
                     $db->setQuery($query);
                     if (!$db->loadResult()) {
                         $query->clear();
                         $query->select('*')->from($db->qn('#__rsmembership_transactions'))->where($db->qn('custom') . ' = ' . $db->q($custom))->where($db->qn('status') . ' != ' . $db->q('completed'));
                         $db->setQuery($query);
                         $transaction = $db->loadObject();
                         // check if transaction exists
                         if (empty($transaction)) {
                             $log[] = "Could not identify transaction with custom hash {$custom}. Stopping.";
                         }
                     } else {
                         $log[] = "The transaction {$txn_id} has already been processed. Stopping.";
                     }
                 }
                 if (!empty($transaction)) {
                     $plugin_email = $this->normalize($this->params->get('email'));
                     $primary_email = $this->normalize($this->params->get('primary_email'));
                     $receiver_email = $this->normalize($receiver_email);
                     if (!$primary_email) {
                         $primary_email = $plugin_email;
                     }
                     // check that receiver_email is your Primary PayPal email
                     if ($receiver_email == $plugin_email || $receiver_email == $primary_email) {
                         // check that payment_amount/payment_currency are correct
                         // check $payment_amount == $price from $subscription_id && $payment_currency == $price from $subscription_id
                         $price = $this->_convertNumber($transaction->price);
                         $currency = $this->normalize(RSMembershipHelper::getConfig('currency'));
                         $payment_currency = $this->normalize($payment_currency);
                         if ((double) $payment_amount >= (double) $price) {
                             if ($currency == $payment_currency) {
                                 // set the hash
                                 $this->setTransactionHash($transaction->id, $txn_id);
                                 // process payment unless manual activation selected
                                 $membership_id = $this->getMembershipId($transaction->params, $transaction->type);
                                 if ($membership_id) {
                                     $query->clear()->select('activation')->from($db->qn('#__rsmembership_memberships'))->where($db->qn('id') . ' = ' . $db->q((int) $membership_id));
                                     $db->setQuery($query);
                                     $activation = $db->loadResult();
                                     if ($activation != MEMBERSHIP_ACTIVATION_MANUAL) {
                                         RSMembership::approve($transaction->id);
                                     }
                                     $activationText = 'missing';
                                     if ($activation == MEMBERSHIP_ACTIVATION_MANUAL) {
                                         $activationText = 'manual';
                                     } elseif ($activation == MEMBERSHIP_ACTIVATION_AUTO) {
                                         $activationText = 'auto';
                                     } elseif ($activation == MEMBERSHIP_ACTIVATION_INSTANT) {
                                         $activationText = 'instant';
                                     }
                                     $log[] = "Activation is {$activationText}.";
                                     $log[] = "Successfully added the payment to the database.";
                                 } else {
                                     $log[] = "The membership could not be found in the database.";
                                 }
                             } else {
                                 $log[] = "Expected a currency of {$currency}. PayPal reports this payment is made in {$payment_currency}. Stopping.";
                                 $deny = true;
                             }
                         } else {
                             $log[] = "Expected an amount of {$price} {$currency}. PayPal reports this payment is {$payment_amount} {$payment_currency}. Stopping.";
                             $deny = true;
                         }
                     } else {
                         $log[] = "Expected payment to be made to {$plugin_email}" . ($primary_email ? " or {$primary_email}" : "") . ". PayPal reports this payment is made for {$receiver_email}. Stopping.";
                         $deny = true;
                     }
                 }
             } else {
                 $log[] = "Payment status is {$payment_status}. Stopping.";
             }
         } elseif (strcmp($res, "INVALID") == 0) {
             $this->addLog("[err] Response is INVALID.");
             $log[] = "Could not verify transaction authencity. PayPal said it's invalid.";
             $log[] = "String sent to PayPal is {$req}";
             $deny = true;
             // log for manual investigation
         } else {
             $this->addLog("[err] PayPal response returned invalid data. Data is presented below:");
             $this->addLog($res);
             $this->addLog("End of data.");
             $log[] = 'PayPal response is not valid! Should be either VERIFIED or INVALID, received "' . strip_tags($res) . '"';
         }
     } else {
         $log[] = "Could not open {$url} in order to verify this transaction. Error reported is: {$errstr}";
     }
     if ($transaction_id) {
         $log[] = "String sent by PayPal is {$req}";
         RSMembership::saveTransactionLog($log, $transaction_id);
         if ($deny) {
             RSMembership::deny($transaction_id);
         }
     }
     $this->finish();
 }
Ejemplo n.º 27
0
 public function renewPaymentRedirect()
 {
     //$payment = JFactory::getApplication()->input->get('payment', 'none', 'string');
     $jinput = JFactory::getApplication()->input;
     $payment = $jinput->get('payment', 'none', 'string');
     $cid = $jinput->get('cid', 0, 'int');
     $model = $this->getModel('renew');
     $membership = $model->getMembership();
     $all_fields = RSMembership::getCustomFields();
     $membership_fields = RSMembership::getCustomMembershipFields($membership->id);
     $all_fields = array_merge($all_fields, $membership_fields);
     if (count($all_fields)) {
         $verifyFieldsMembership = $jinput->get('rsm_membership_fields', array(), 'array');
         $verifyFieldsUser = $jinput->get('rsm_fields', array(), 'array');
         $verifyFields = array_merge($verifyFieldsUser, $verifyFieldsMembership);
         $fields = $all_fields;
         foreach ($fields as $field) {
             if ($field->required && empty($verifyFields[$field->name]) || $field->rule && !empty($verifyFields[$field->name]) && is_callable('RSMembershipValidation', $field->rule) && !call_user_func(array('RSMembershipValidation', $field->rule), $verifyFields[$field->name])) {
                 $message = JText::_($field->validation);
                 if (empty($message)) {
                     $message = JText::sprintf('COM_RSMEMBERSHIP_VALIDATION_DEFAULT_ERROR', JText::_($field->label));
                 }
                 JError::raiseWarning(500, $message);
                 return $this->setRedirect(JRoute::_('index.php?option=com_rsmembership&task=renew&cid=' . $cid, false));
             }
         }
         $model->storeData(array('membership_fields' => $verifyFieldsMembership, 'custom_fields' => $verifyFieldsUser));
     }
     $this->setRedirect(JRoute::_('index.php?option=com_rsmembership&task=renewpayment&payment=' . $payment, false));
 }
Ejemplo n.º 28
0
 function getMembership()
 {
     jimport('joomla.html.pagination');
     $cid = JRequest::getVar('cid', 0);
     if (is_array($cid)) {
         $cid = $cid[0];
     }
     $cid = (int) $cid;
     $row =& JTable::getInstance('RSMembership_Memberships', 'Table');
     $row->load($cid);
     $this->_db->setQuery("SELECT `extra_id` FROM #__rsmembership_membership_extras WHERE `membership_id`='" . $cid . "'");
     $row->extras = $this->_db->loadResultArray();
     $instances = RSMembership::getSharedContentPlugins();
     $this->_db->setQuery("SELECT * FROM #__rsmembership_membership_shared WHERE `membership_id`='" . $cid . "' ORDER BY `ordering`");
     $row->shared = $this->_db->loadObjectList();
     foreach ($row->shared as $s => $shared) {
         switch ($shared->type) {
             default:
                 foreach ($instances as $instance) {
                     if (method_exists($instance, 'showUserFriendlyParams')) {
                         $instance->showUserFriendlyParams($shared);
                     }
                 }
                 $row->shared[$s] = $shared;
                 break;
             case 'article':
                 $this->_db->setQuery("SELECT `title` FROM #__content WHERE `id`='" . (int) $shared->params . "'");
                 $row->shared[$s]->params = $this->_db->loadResult();
                 break;
             case 'section':
                 $this->_db->setQuery("SELECT `title` FROM #__sections WHERE `id`='" . (int) $shared->params . "'");
                 $row->shared[$s]->params = $this->_db->loadResult();
                 break;
             case 'category':
                 $this->_db->setQuery("SELECT `title` FROM #__categories WHERE `id`='" . (int) $shared->params . "'");
                 $row->shared[$s]->params = $this->_db->loadResult();
                 break;
             case 'module':
                 $this->_db->setQuery("SELECT `title`, `module` FROM #__modules WHERE `id`='" . (int) $shared->params . "'");
                 $module = $this->_db->loadObject();
                 $row->shared[$s]->params = '(' . $module->module . ') ' . $module->title;
                 break;
             case 'menu':
                 if (RSMembershipHelper::isJ16()) {
                     $this->_db->setQuery("SELECT `title` AS `name`, `menutype` FROM #__menu WHERE `id`='" . (int) $shared->params . "'");
                 } else {
                     $this->_db->setQuery("SELECT `name`, `menutype` FROM #__menu WHERE `id`='" . (int) $shared->params . "'");
                 }
                 $menu = $this->_db->loadObject();
                 $row->shared[$s]->params = '(' . $menu->menutype . ') ' . $menu->name;
                 break;
         }
     }
     $row->sharedPagination = new JPagination(count($row->shared), 0, 0);
     // attachments
     $this->_db->setQuery("SELECT * FROM #__rsmembership_membership_attachments WHERE `membership_id`='" . $cid . "' ORDER BY `ordering`");
     $attachments = $this->_db->loadObjectList();
     foreach ($attachments as $attachment) {
         $this->attachments[$attachment->email_type][] = $attachment;
     }
     foreach ($this->attachments as $email_type => $attachments) {
         $this->attachmentsPagination[$email_type] = new JPagination(count($attachments), 0, 0);
     }
     return $row;
 }
Ejemplo n.º 29
0
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $pathway = $app->getPathway();
     // Assign variables
     $this->membership = $this->get('Membership');
     $this->extras = $this->get('Extras');
     $this->params = clone $app->getParams('com_rsmembership');
     $this->user = JFactory::getUser();
     $this->logged = (bool) (!$this->user->guest);
     $this->token = JHtml::_('form.token');
     // Assign config variables
     $this->config = RSMembershipHelper::getConfig();
     $this->show_login = $this->config->show_login;
     $this->choose_username = $this->config->choose_username;
     $this->choose_password = $this->config->choose_password;
     $this->currency = $this->config->currency;
     $this->one_page_checkout = $this->config->one_page_checkout;
     $this->captcha_case_sensitive = $this->config->captcha_case_sensitive;
     $this->payments = RSMembership::getPlugins();
     // Set pathway
     $pathway->addItem($this->membership->name, JRoute::_(RSMembershipRoute::Membership($this->membership->id, $app->input->getInt('Itemid'))));
     $pathway->addItem(JText::_('COM_RSMEMBERSHIP_SUBSCRIBE'), '');
     switch ($this->getLayout()) {
         default:
             // Get the encoded return url
             $this->return = base64_encode(JURI::getInstance());
             $this->data = (object) $this->get('Data');
             $this->membershipterms = $this->get('MembershipTerms');
             $this->has_coupons = $this->get('HasCoupons');
             $this->fields_validation = RSMembershipHelper::getFieldsValidation($this->membership->id);
             $this->fields = RSMembershipHelper::getFields(true);
             $this->membership_fields = RSMembershipHelper::getMembershipFields($this->membership->id);
             // Handle CAPTCHA
             $this->use_captcha = $this->get('UseCaptcha');
             $this->use_builtin = $this->get('UseBuiltin');
             $this->use_recaptcha = $this->get('UseReCaptcha');
             $this->use_recaptcha_new = $this->get('UseReCaptchaNew');
             if ($this->use_recaptcha) {
                 if (!class_exists('JReCAPTCHA')) {
                     require_once JPATH_ADMINISTRATOR . '/components/com_rsmembership/helpers/recaptcha/recaptchalib.php';
                 }
                 $this->show_recaptcha = JReCAPTCHA::getHTML($this->get('ReCaptchaError'));
             }
             if ($this->use_recaptcha_new) {
                 $doc = JFactory::getDocument();
                 if ($doc->getType() == 'html') {
                     $doc->addScript('https://www.google.com/recaptcha/api.js?hl=' . JFactory::getLanguage()->getTag());
                 }
             }
             $this->assignExtrasView();
             break;
         case 'preview':
             $this->fields = RSMembershipHelper::getFields(false);
             $this->membership_fields = RSMembershipHelper::getMembershipFields($this->membership->id, false);
             $this->data = (object) $this->get('Data');
             break;
         case 'payment':
             $this->html = $this->get('Html');
             break;
     }
     // Calculate the Total
     $this->total = $this->get('Total');
     // Do we need to display the payment options?
     $model = $this->getModel();
     $this->showPayments = $model->showPaymentOptions();
     parent::display();
 }
Ejemplo n.º 30
0
 function deny()
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     // Get the selected items
     $cid = JRequest::getVar('cid', array(0), 'post', 'array');
     $total = count($cid);
     $msg = JText::sprintf('RSM_TRANSACTIONS_DENIED', $total);
     // Force array elements to be integers
     JArrayHelper::toInteger($cid, array(0));
     $msg = '';
     // No items are selected
     if (!is_array($cid) || count($cid) < 1) {
         JError::raiseWarning(500, JText::_('SELECT ITEM'));
     } else {
         $user =& JFactory::getUser();
         $user_id = $user->get('username');
         foreach ($cid as $id) {
             RSMembership::saveTransactionLog('Manually denied by ' . $user_id, $id);
             RSMembership::deny($id);
         }
         $total = count($cid);
         $msg = JText::sprintf('RSM_TRANSACTIONS_DENIED', $total);
         // Clean the cache, if any
         $cache =& JFactory::getCache('com_rsmembership');
         $cache->clean();
     }
     $this->setRedirect('index.php?option=com_rsmembership&view=transactions', $msg);
 }