Example #1
0
 function _execute()
 {
     $app = JFactory::getApplication();
     $task = $app->input->get('task', '', 'string');
     if ($task == 'addextra') {
         $this->_bindId();
     } else {
         $this->_setId();
         if ($task == 'addextrapayment') {
             // empty session
             $this->_emptySession();
             $membership = $this->getMembership();
             $extra = $this->getExtra();
             $paymentplugin = $app->input->get('payment', 'none', 'cmd');
             // calculate the total price
             $total = $extra->price;
             $user = JFactory::getUser();
             $user_id = $user->get('id');
             $row = JTable::getInstance('Transaction', 'RSMembershipTable');
             $row->user_id = $user_id;
             $row->user_email = $user->get('email');
             $this->_data = new stdClass();
             $this->_data->username = $user->get('username');
             $this->_data->name = $user->get('name');
             $this->_data->email = $user->get('email');
             $this->_data->fields = RSMembershipHelper::getUserFields($user->get('id'));
             $membership_fields = RSMembershipHelper::getTransactionMembershipFields($user->get('id'), $membership->last_transaction_id);
             if (count($membership_fields)) {
                 $this->_data->membership_fields = $membership_fields;
             }
             $row->user_data = serialize($this->_data);
             $row->type = 'addextra';
             $params = array();
             $params[] = 'id=' . $this->_id;
             $params[] = 'membership_id=' . $membership->id;
             $params[] = 'extras=' . $extra->id;
             $row->params = implode(';', $params);
             // params, membership, extras etc
             $row->date = JFactory::getDate()->toSql();
             $row->ip = $_SERVER['REMOTE_ADDR'];
             $row->price = $total;
             $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
             $delay = false;
             $args = array('plugin' => $paymentplugin, 'data' => &$this->_data, 'extras' => array(), 'membership' => $membership, 'transaction' => &$row, 'html' => &$this->_html);
             $returns = $app->triggerEvent('onMembershipPayment', $args);
             // PHP 5.4 fix...
             if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
                 foreach ($returns as $value) {
                     if ($value) {
                         $this->_html = $value;
                     }
                 }
             }
             $properties = $row->getProperties();
             $returns = $app->triggerEvent('delayTransactionStoring', array(array('plugin' => $paymentplugin, 'properties' => &$properties, 'delay' => &$delay)));
             // PHP 5.4 fix...
             if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
                 foreach ($returns as $value) {
                     if ($value) {
                         $delay = true;
                     }
                 }
             }
             // 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) {
                     $app->redirect(JRoute::_(RSMembershipRoute::ThankYou(), false));
                 }
             }
         }
     }
 }