コード例 #1
0
ファイル: upgrade.php プロジェクト: JozefAB/qk
 function _execute()
 {
     $app = JFactory::getApplication();
     $task = $app->input->get('task', '', 'cmd');
     if ($task == 'upgrade') {
         $this->_bindId();
     } else {
         $this->_setId();
         if ($task == 'upgradepayment') {
             // empty session
             $this->_emptySession();
             $extras = array();
             $upgrade = $this->getUpgrade();
             $membership = $this->getMembership($upgrade->membership_to_id);
             $paymentplugin = $app->input->get('payment', 'none', 'cmd');
             // calculate the total price
             $total = $upgrade->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');
             $membership_data = $this->getSentData();
             if (isset($membership_data['custom_fields'])) {
                 $this->_data->fields = $membership_data['custom_fields'];
             }
             if ($membership_data['to_id'] == $upgrade->membership_to_id) {
                 if (isset($membership_data['custom_fields'])) {
                     $this->_data->membership_fields = $membership_data['membership_fields'];
                 }
             }
             $row->user_data = serialize($this->_data);
             $row->type = 'upgrade';
             $params = array();
             $params[] = 'id=' . $this->_id;
             $params[] = 'from_id=' . $upgrade->membership_from_id;
             $params[] = 'to_id=' . $upgrade->membership_to_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' => $extras, '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;
                     }
                 }
             }
             // trigger the payment plugin
             // 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::_('index.php?option=com_rsmembership&task=thankyou', false));
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: subscribe.php プロジェクト: atikahmed/joomla-probid
 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));
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: subscribe.php プロジェクト: JozefAB/qk
 public function saveTransaction($paymentPlugin)
 {
     // Empty the session, no point in keeping it.
     $this->clearData();
     // Empty the HTML variable.
     $this->html = '';
     // Get some data.
     $extras = $this->getExtras();
     $membership = $this->getMembership();
     $total = $this->getTotal();
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     // Asign the user.
     $userId = 0;
     if ($user->guest) {
         // Create the user instantly if this option is enabled.
         if (RSMembershipHelper::getConfig('create_user_instantly')) {
             $userId = RSMembership::createUser($this->data->email, $this->data);
         }
     } else {
         // Grab logged in user's ID.
         $userId = $user->id;
         // Update user's custom fields.
         RSMembership::createUserData($userId, $this->data->fields);
     }
     // Create user data object.
     $newData = (object) array('name' => $this->data->name, 'username' => isset($this->data->username) ? $this->data->username : '', 'fields' => $this->data->fields, 'membership_fields' => $this->data->membership_fields);
     if (!empty($this->data->password)) {
         $newData->password = $this->data->password;
     }
     // Create transaction params array.
     $params = array('membership_id=' . $membership->id);
     if ($this->extras) {
         $params[] = 'extras=' . implode(',', $this->extras);
     }
     $params = implode(';', $params);
     // Create the JTable object.
     $row = JTable::getInstance('Transaction', 'RSMembershipTable');
     $row->bind(array('user_id' => $userId, 'user_email' => $this->data->email, 'user_data' => serialize($newData), 'type' => 'new', 'params' => $params, 'date' => JFactory::getDate()->toSql(), 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'price' => $total, 'coupon' => $this->data->coupon, 'currency' => RSMembershipHelper::getConfig('currency'), 'gateway' => $paymentPlugin == 'none' ? 'No Gateway' : RSMembership::getPlugin($paymentPlugin), 'status' => 'pending'));
     // Trigger the payment plugin
     $delay = false;
     $args = array('plugin' => $paymentPlugin, 'data' => &$this->data, 'extras' => $extras, '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();
         // Finalize the transaction (send emails)
         RSMembership::finalize($row->id);
         // Approve the transaction
         if ($row->status == 'completed' || !$this->showPaymentOptions() && $membership->activation != MEMBERSHIP_ACTIVATION_MANUAL || $membership->activation == MEMBERSHIP_ACTIVATION_INSTANT) {
             RSMembership::approve($row->id, true);
         }
     }
     return $row;
 }