Exemple #1
0
 /**
  * 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));
         }
     }
 }
Exemple #2
0
 /**
  * Re-calculate subscription fee when subscribers choose a fee option on subscription form
  *
  * Called by ajax request. After calculation, the system will update the fee displayed on end users on subscription sign up form
  */
 public function calculate_subscription_fee()
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $config = OSMembershipHelper::getConfig();
     $planId = JRequest::getInt('plan_id', 0);
     $query->select('*')->from('#__osmembership_plans')->where('id=' . $planId);
     $db->setQuery($query);
     $rowPlan = $db->loadObject();
     $rowFields = OSMembershipHelper::getProfileFields($planId);
     $data = JRequest::get('post', JREQUEST_ALLOWHTML);
     $form = new RADForm($rowFields);
     $form->setData($data)->bindData(true);
     $fees = OSMembershipHelper::calculateSubscriptionFee($rowPlan, $form, $data, $config, JFactory::getApplication()->input->get('payment_method', '', 'none'));
     echo json_encode($fees);
     JFactory::getApplication()->close();
 }
Exemple #3
0
 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);
 }