Пример #1
0
 /**
  * Method to process recurring subscription
  *
  */
 public function process_recurring_subscription()
 {
     $mainframe = JFactory::getApplication();
     $model =& $this->getModel('jms');
     $post = JRequest::get('post');
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $sid = JRequest::getInt('sid');
     $coupon = JRequest::getVar('coupon', '', 'default', 'string');
     // If subscription id is null, user can't purchase it
     if (!$sid) {
         $msg = JText::_('COM_JMS_CAN_NOT_PURCHASE');
         $url = 'index.php?option=com_jms&view=form&Itemid=' . JRequest::getInt('Itemid');
         $mainframe->enqueueMessage($msg, 'Error');
         $this->setRedirect($url);
         return;
     }
     // If users are not login, they can't purchase subscription
     if (!$user->get('id')) {
         $msg = JText::_('COM_JMS_YOU_MUST_LOGIN_TO_PURCHASE');
         $url = JRoute::_('index.php?option=com_jms&view=form&Itemid=' . JRequest::getInt('Itemid'));
         $mainframe->enqueueMessage($msg, 'Error');
         $this->setRedirect($url);
         return;
     }
     // Get subscription information
     $plan = $model->getPlan($sid);
     // As default, order amount is equal subscription price
     $post['price'] = $plan->price;
     // Re-calculate order amount based on discount, if user have already purchase this subscription, then they will be discounted
     if ($plan->discount > 0) {
         $post['price'] = round($post['price'] - $post['price'] * ($plan->discount / 100), 2);
     }
     $post['plan_id'] = $sid;
     $post['item_name'] = $mainframe->getCfg('sitename') . ' :: ' . $plan->name;
     $post['order_quantity'] = 1;
     if ($coupon && $post['price'] > 0) {
         $this->_validateCoupon($coupon);
         if (!$this->_couponExists) {
             JError::raiseNotice(100, JText::_('COM_JMS_COUPON_NOT_EXISTS'));
             parent::display();
             return;
         } else {
             if (!$this->_couponValid) {
                 JError::raiseNotice(100, JText::_('COM_JMS_COUPON_NOT_VALID'));
                 JError::raiseNotice(100, $this->_couponError);
                 parent::display();
                 return;
             } else {
                 $post['price'] = $this->_applyCoupon($coupon, $post['price']);
             }
         }
     }
     // Process Subscription
     if ($post['price'] == 0.0) {
         $model->processSubscription($post);
     } else {
         $model->processRecurringSubscription($post);
     }
     $paymentMethod = $post['payment_method'];
     if ($paymentMethod == 'iwl_authnet') {
         $this->display();
     }
 }
 /**
  * constructor
  *
  * @param string $pluginFile
  * @param string $pluginName
  */
 public function __construct($pluginFile, $pluginName = '')
 {
     parent::__construct($pluginFile, $pluginName = '');
     add_filter('contextual_help', array($this, 'contextualHelp'), 10, 3);
 }