Example #1
0
function process_authorize($subscription, $item_id, $proc)
{
    global $Itemid, $JLMS_DB, $JLMS_CONFIG;
    $params2 = new JLMSParameters($proc->params);
    $orderNumber = $item_id;
    //$params2->get( 'x_invoice_num' );
    $orderDescr = $params2->get('x_description');
    if (!$subscription->sub_name && count($subscription->subscriptions) && (strpos($params2->get('x_description'), '[sub]') !== false || strpos($params2->get('x_description'), '[SUB]') !== false)) {
        $subscr_ids = implode(',', $subscription->subscriptions);
        $query = "SELECT id, sub_name FROM #__lms_subscriptions WHERE id IN ({$subscr_ids})";
        $JLMS_DB->SetQuery($query);
        $subs_names_list_db = $JLMS_DB->LoadObjectList();
        //create item name from list of all subscriptions separated by comma, ordered as in cart
        $subs_names_list = array();
        foreach ($subscription->subscriptions as $cart_sub_id) {
            foreach ($subs_names_list_db as $subname_item) {
                if ($subname_item->id == $cart_sub_id) {
                    $subs_names_list[] = $subname_item->sub_name;
                    break;
                }
            }
        }
        $subscription->sub_name = implode(', ', $subs_names_list);
    }
    $orderDescr = str_replace('[SUB]', $subscription->sub_name, $orderDescr);
    $orderDescr = str_replace('[sub]', $subscription->sub_name, $orderDescr);
    $a = new authorizenet_class();
    //if ($params2->get('x_test_request') == "TRUE") $a->gateway_url = 'https://test.authorize.net/gateway/transact.dll';
    $a->add_field('x_login', $params2->get('x_login'));
    $a->add_field('x_tran_key', $params2->get('x_tran_key'));
    $a->add_field('x_invoice_num', $orderNumber);
    $a->add_field('x_description', $orderDescr);
    $a->add_field('x_version', '3.1');
    $a->add_field('x_type', 'AUTH_CAPTURE');
    $a->add_field('x_test_request', $params2->get('x_test_request'));
    $a->add_field('x_relay_response', 'FALSE');
    $a->add_field('x_delim_data', 'TRUE');
    $a->add_field('x_delim_char', '|');
    $a->add_field('x_encap_char', '');
    $a->add_field('x_email_customer', $params2->get('x_email_customer'));
    $a->add_field('x_merchant_email', $params2->get('x_merchant_email'));
    $query = "SELECT user_id FROM `#__lms_payments` WHERE id = {$item_id}";
    $JLMS_DB->setQuery($query);
    $user_id_of_payment = $JLMS_DB->LoadResult();
    $user_id_of_payment = intval($user_id_of_payment);
    $a->add_field('x_first_name', mosGetParam($_POST, 'x_first_name', ''));
    $a->add_field('x_last_name', mosGetParam($_POST, 'x_last_name', ''));
    $a->add_field('x_cust_id', $user_id_of_payment);
    $a->add_field('x_address', mosGetParam($_POST, 'x_address', ''));
    $a->add_field('x_city', mosGetParam($_POST, 'x_city', ''));
    $a->add_field('x_state', mosGetParam($_POST, 'x_state', ''));
    $a->add_field('x_zip', mosGetParam($_POST, 'x_zip', ''));
    $a->add_field('x_country', mosGetParam($_POST, 'x_country', ''));
    $a->add_field('x_email', mosGetParam($_POST, 'x_email', ''));
    $a->add_field('x_phone', mosGetParam($_POST, 'x_phone', ''));
    $a->add_field('x_method', 'CC');
    $a->add_field('x_card_num', mosGetParam($_POST, 'x_card_num', ''));
    $a->add_field('x_amount', number_format($subscription->price + $subscription->tax_amount, 2, '.', ''));
    $a->add_field('x_currency_code', $JLMS_CONFIG->get('jlms_cur_code'));
    $a->add_field('x_exp_date', mosGetParam($_POST, 'card_expirationMonth', '') . mosGetParam($_POST, 'card_expirationYear', ''));
    $a->add_field('x_card_code', mosGetParam($_POST, 'x_card_code', ''));
    switch ($a->process()) {
        case 1:
            // Successs
            //$payment_amount = ($subscription->price + $subscription->tax_amount);
            $payment_currency = $JLMS_CONFIG->get('jlms_cur_code');
            $txn_id = $a->response['Transaction ID'];
            require_once _JOOMLMS_FRONT_HOME . '/includes/joomla_lms.subscription.lib.php';
            //if (!jlms_check_payment_transaction(($payment_amount - $subscription->tax_amount), $item_id)) { die('Invalid payment amount'); }
            $payment_date = date('Y-m-d H:i:s');
            $query = "SELECT status FROM `#__lms_payments` WHERE id = {$item_id} ";
            $JLMS_DB->setQuery($query);
            $prev_payment = $JLMS_DB->LoadResult();
            jlms_update_payment($item_id, $txn_id, 'Completed', $payment_date, $subscription->tax_amount);
            if ($prev_payment == 'Completed') {
            } else {
                jlms_register_new_user($item_id);
                //TODO: generate invoice only if enabled
                JLMS_CART_generateinvoice($item_id, $params2);
            }
            setcookie('joomlalms_cart_contents', '', time() - 3600, '/');
            /*SoulPowerUniversity_MOD*/
            /*
            mail_notification($subscription);
            */
            /*SoulPowerUniversity_MOD*/
            if ($params2->get('return_url') == '') {
                $query = "SELECT b.course_id FROM `#__lms_payments` as a, `#__lms_subscriptions_courses` as b WHERE a.id = {$item_id} AND a.sub_id = b.sub_id ";
                $JLMS_DB->setQuery($query);
                $courses = $JLMS_DB->loadObjectList();
                if (count($courses) == 1) {
                    JLMSRedirect(sefRelToAbs("index.php?option=com_joomla_lms&task=details_course&id=" . $courses[0]->course_id . "&Itemid=" . $Itemid), $params2->get('success_message'));
                } else {
                    JLMSRedirect(sefRelToAbs("index.php?option=com_joomla_lms&Itemid={$Itemid}"), $params2->get('success_message'));
                }
            } else {
                JLMSRedirect($params2->get('return_url'));
            }
            break;
        case 2:
            // Declined
            $error_text = str_replace(array("\r\n", "\r", "\n"), '\\n', $a->get_response_reason_text());
            echo "<script> alert(\"" . addslashes($error_text) . "\"); window.history.go(-1); </script>\n";
            exit;
            break;
        case 3:
            // Error
            $error_text = str_replace(array("\r\n", "\r", "\n"), '\\n', $a->get_response_reason_text());
            echo "<script> alert(\"" . addslashes($error_text) . "\"); window.history.go(-1); </script>\n";
            exit;
            break;
    }
}
Example #2
0
 function validate_recurrent_subscription($proc)
 {
     global $Itemid, $JLMS_CONFIG, $JLMS_DB;
     $params = new JLMSParameters($proc->params);
     // post back to PayPal system to validate
     /*
     foreach ($_POST as $key=>$value) $postdata.=$key."=".urlencode($value)."&";	
     $server_url2 = str_replace('https://','',str_replace('/cgi-bin/webscr','', $params->get( 'server_url' ) ));
     $curl = curl_init('https://'.$server_url2.'/cgi-bin/webscr');
     curl_setopt ($curl, CURLOPT_HEADER, 0);
     curl_setopt ($curl, CURLOPT_POST, 1);
     curl_setopt ($curl, CURLOPT_POSTFIELDS, $postdata);
     curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
     //curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 1);  
     $response = curl_exec ($curl);  	
     curl_close ($curl);
     */
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     // post back to PayPal system to validate
     $server_url2 = str_replace('https://', '', str_replace('/cgi-bin/webscr', '', $params->get('server_url')));
     $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
     $header .= "Host: " . $server_url2 . "\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
     $fp = fsockopen($server_url2, 80, $errno, $errstr, 30);
     $verifed = false;
     if (!$fp) {
         die;
     } else {
         fputs($fp, $header . $req);
         while (!feof($fp)) {
             $res_pp = fgets($fp, 1024);
             if (strcmp($res_pp, "VERIFIED") == 0) {
                 $verifed = true;
             }
         }
         fclose($fp);
     }
     if (!$verifed) {
         die;
     }
     //if ($response != "VERIFIED") die("You should not do that ...");
     //mosMail( '*****@*****.**', 'LMS Trial', '*****@*****.**', 'Paypal', $server_url2, false, NULL, NULL );
     // assign posted variables to local variables
     // assign posted variables to local variables
     $item_name = mosGetParam($_POST, 'item_name', 0);
     $item_number = mosGetParam($_POST, 'item_number', '');
     $payment_status = mosGetParam($_POST, 'payment_status', '');
     $payment_amount = mosGetParam($_POST, 'mc_gross', '');
     $payment_currency = mosGetParam($_POST, 'mc_currency', '');
     $txn_id = mosGetParam($_POST, 'txn_id', '');
     $receiver_email = mosGetParam($_POST, 'receiver_email', '');
     $business = mosGetParam($_POST, 'business', '');
     $payer_email = mosGetParam($_POST, 'payer_email', '');
     $payment_date = mosGetParam($_POST, 'payment_date', '');
     $subscr_date = mosGetParam($_POST, 'subscr_date', '');
     $mc_gross = mosGetParam($_POST, 'mc_gross', '');
     //amount
     $mc_fee = mosGetParam($_POST, 'mc_fee', '');
     $txn_type = mosGetParam($_POST, 'txn_type', '');
     $subscr_id = mosGetParam($_POST, 'subscr_id', '');
     $subscr_date = mosGetParam($_POST, 'subscr_date', '');
     $recurring = mosGetParam($_POST, 'recurring', '');
     $recur_times = mosGetParam($_POST, 'recur_times', '');
     $reattempt = mosGetParam($_POST, 'reattempt', '');
     $period1 = mosGetParam($_POST, 'period1', '');
     $period2 = mosGetParam($_POST, 'period2', '');
     $period3 = mosGetParam($_POST, 'period3', '');
     $amount1 = mosGetParam($_POST, 'amount1', '');
     $amount2 = mosGetParam($_POST, 'amount2', '');
     $amount3 = mosGetParam($_POST, 'amount3', '');
     $mc_amount1 = mosGetParam($_POST, 'mc_amount1', '');
     $mc_amount2 = mosGetParam($_POST, 'mc_amount2', '');
     $mc_amount3 = mosGetParam($_POST, 'mc_amount3', '');
     $tax_amount = isset($_POST['option_selection1']) ? $_POST['option_selection1'] : 0;
     $tax_paypal = isset($_POST['tax']) ? $_POST['tax'] : 0;
     if ($JLMS_CONFIG->get('debug_mode', false)) {
         jimport('joomla.error.log');
         $log =& JLog::getInstance('payments.log');
         ob_start();
         var_dump($_REQUEST);
         $content = ob_get_contents();
         ob_end_clean();
         $entry['COMMENT'] = $content;
         $log->addEntry($entry);
     }
     require_once _JOOMLMS_FRONT_HOME . '/includes/joomla_lms.subscription.lib.php';
     if ($receiver_email != $params->get('business_email') && $business != $params->get('business_email')) {
         die;
     }
     if ($payment_currency != $JLMS_CONFIG->get('jlms_cur_code')) {
         die;
     }
     // new subscription
     if ($txn_type == 'subscr_signup') {
         $query = "SELECT * FROM #__lms_payments_checksum WHERE payment_id = " . $item_number;
         $JLMS_DB->setQuery($query);
         $checksum = $JLMS_DB->loadObject();
         if (!$checksum->a1 && $checksum->p1 || !$checksum->a2 && $checksum->p2) {
             $query = "SELECT * FROM `#__lms_payments` WHERE id = {$item_number}";
             $JLMS_DB->setQuery($query);
             $payment_info = $JLMS_DB->loadObject();
             $subscr_date_obj = JFactory::getDate($subscr_date);
             $subscr_date_mysql = $subscr_date_obj->toMySQL();
             jlms_update_payment($item_number, $txn_id, 'Completed', $subscr_date_mysql, $tax_amount + $tax_paypal, $tax_paypal, $isReccuring = true);
             jlms_register_new_user($item_number);
             if ($checksum->a2) {
                 $next_amount = $checksum->a2;
             } else {
                 if ($checksum->a3) {
                     $next_amount = $checksum->a3;
                 }
             }
             if ($next_amount) {
                 $parent_id = $payment_info->parent_id ? $payment_info->parent_id : $payment_info->id;
                 $query = "INSERT INTO `#__lms_payments` SET txn_id = '', status = 'Pending', tax_amount = '{$tax_amount}', tax2_amount = '{$tax2_amount}', date ='" . JLMS_gmdate() . "', parent_id = '{$parent_id}', amount = '{$next_amount}', cur_code = '{$payment_info->cur_code}', user_id = {$payment_info->user_id}, payment_type = '{$payment_info->payment_type}', sub_id = '{$payment_info->sub_id}', proc_id = '{$payment_info->proc_id}', processor = '{$payment_info->processor}'";
                 $JLMS_DB->setQuery($query);
                 $JLMS_DB->query();
             }
         }
         //get plan_id
         /*$query = "SELECT status FROM `#__lms_payments` WHERE id = $item_number ";
         		$JLMS_DB->setQuery($query);
         		$prev_payment = $JLMS_DB->LoadResult();
         		*/
         //jlms_update_payment( $item_number, $txn_id, 'Completed', $payment_date, $tax_amount, 0, $isReccuring = false );
         //jlms_register_new_user( $item_number );
     } else {
         if ($txn_type == 'subscr_payment') {
             //mosMail( '*****@*****.**', 'LMS Trial', '*****@*****.**', 'Paypal', $payment_status, false, NULL, NULL );
             //if ( $payment_status != 'Completed' ) { die; }
             if ($txn_id) {
                 $query = "SELECT count(1) FROM `#__lms_payments` WHERE txn_id = " . $JLMS_DB->quote($txn_id);
                 $JLMS_DB->setQuery($query);
                 $txt_id_exists = $JLMS_DB->loadResult();
                 if ($txt_id_exists) {
                     die;
                 }
             }
             $query = "SELECT p.id, p.name, p.description, p.published, p.p1, p.t1, p.p2, p.t2, p.p3, p.t3, s.a1, s.a2, s.a3, p.sra, p.src, p.srt, p.params" . "\n FROM #__lms_payment_items pi," . "\n #__lms_subscriptions s," . "\n #__lms_plans_subscriptions ps," . "\n #__lms_plans p" . "\n WHERE pi.payment_id=" . $item_number . "\n AND pi.item_id=s.id" . "\n AND ps.subscr_id=s.id" . "\n AND p.id=ps.plan_id";
             $JLMS_DB->setQuery($query);
             $plan = $JLMS_DB->loadObject();
             if (empty($plan)) {
                 die;
             }
             // checking if subscription data exists
             $query = "SELECT * FROM #__lms_payments_checksum WHERE payment_id = " . $item_number;
             $JLMS_DB->setQuery($query);
             $checksum = $JLMS_DB->loadObject();
             if (empty($checksum)) {
                 die;
             }
             $query = "SELECT * FROM `#__lms_payments` WHERE (id = {$item_number} OR parent_id = {$item_number}) AND status != 'Completed' AND amount = '" . ($mc_gross - $tax_paypal) . "' ORDER BY id DESC LIMIT 1";
             $JLMS_DB->setQuery($query);
             $payment_info = $JLMS_DB->loadObject();
             if (empty($payment_info)) {
                 die;
             }
             jlms_update_payment($payment_info->id, $txn_id, $payment_status, $payment_date, $tax_amount + $tax_paypal, $tax_paypal, $isReccuring = true);
             if ($payment_status == 'Completed' && $checksum->a3) {
                 $next_amount = 0;
                 if (!$payment_info->parent_id && $checksum->a2) {
                     $next_amount = $checksum->a2;
                 } else {
                     $next_amount = $checksum->a3;
                 }
                 if ($next_amount) {
                     $parent_id = $payment_info->parent_id ? $payment_info->parent_id : $payment_info->id;
                     $query = "INSERT INTO `#__lms_payments` SET txn_id = '', status = 'Pending', tax_amount = '{$tax_amount}', tax2_amount = '{$tax2_amount}', date ='" . JLMS_gmdate() . "', parent_id = '{$parent_id}', amount = '{$next_amount}', cur_code = '{$payment_info->cur_code}', user_id = {$payment_info->user_id}, payment_type = '{$payment_info->payment_type}', sub_id = '{$payment_info->sub_id}', proc_id = '{$payment_info->proc_id}', processor = '{$payment_info->processor}'";
                     $JLMS_DB->setQuery($query);
                     $JLMS_DB->query();
                 }
                 jlms_register_new_user($item_number);
             }
             $user_id = $payment_info->user_id;
         } else {
             if ($txn_type == 'subscr_cancel' || $txn_type == 'subscr_eot') {
                 if ($txn_type == 'subscr_cancel') {
                     $query = "SELECT *  FROM `#__lms_payments` WHERE (id = {$item_number} OR parent_id = {$item_number}) AND status != 'Completed' ORDER BY id DESC LIMIT 1";
                     $JLMS_DB->setQuery($query);
                     $payment_info = $JLMS_DB->loadObject();
                     if (is_object($payment_info)) {
                         $query = "UPDATE `#__lms_payments` SET status = 'Canceled' WHERE id = " . $JLMS_DB->quote($payment_info->id);
                         $JLMS_DB->setQuery($query);
                         $JLMS_DB->Query();
                     }
                 }
                 jlms_register_new_user($item_number, 1);
             }
         }
     }
     if ($payment_info->id) {
         return $payment_info->id;
     } else {
         return $item_number;
     }
     //}
     //fclose ($fp);
     //}
 }
Example #3
0
    function validate_callback($proc)
    {
        global $JLMS_DB, $Itemid, $JLMS_CONFIG, $JLMS_DB;
        $params = new JLMSParameters($proc->params);
        // assign posted variables to local variables
        $payment_status = $_REQUEST['transStatus'];
        $payment_amount = $_REQUEST['authAmount'];
        $payment_currency = $_REQUEST['authCurrency'];
        $txn_id = $_REQUEST['transId'];
        $payment_date = date("Y-m-d H:i:s", mktime());
        $order = $_REQUEST['MC_order'];
        $tax_amount = $_REQUEST['MC_tax'];
        $user_id = $_REQUEST['MC_user'];
        $callback_pw = @$_REQUEST['callbackPW'];
        if ($payment_status != 'Y') {
            die('Invalid transaction status');
        }
        if ($callback_pw != $params->get('callback_pw')) {
            die('Invalid callback password');
        }
        // check that txn_id has not been previously processed
        $query = "SELECT id FROM `#__lms_payments` WHERE txn_id='" . $txn_id . "'  ";
        $JLMS_DB->setQuery($query);
        $res = $JLMS_DB->query();
        if (mysql_num_rows($res)) {
            die;
        }
        // check that payment_currency is correct
        if ($payment_currency != $JLMS_CONFIG->get('jlms_cur_code')) {
            die;
        }
        require_once _JOOMLMS_FRONT_HOME . '/includes/joomla_lms.subscription.lib.php';
        if ($payment_status == 'Y') {
            if (!jlms_check_payment_transaction($payment_amount - $tax_amount, $order)) {
                die('Invalid payment amount');
            }
            $query = "SELECT status FROM `#__lms_payments` WHERE id = {$order} ";
            $JLMS_DB->setQuery($query);
            $prev_payment = $JLMS_DB->LoadResult();
            jlms_update_payment($order, $txn_id, 'Completed', $payment_date);
            if ($prev_payment == 'Completed') {
            } else {
                jlms_register_new_user($order);
            }
            ?>
		Thanks for your payment, you were successfully added to the course.
<?php 
        } elseif ($payment_status == 'C') {
            jlms_update_payment($order, $txn_id, 'Pending', $payment_date);
            ?>
		Your payment status is still 'pending'. You will be added to the course as soon as your payment is confirmed.
<?php 
        }
    }
Example #4
0
 function validate_callback($proc)
 {
     global $Itemid, $JLMS_CONFIG, $JLMS_DB;
     $params = new JLMSParameters($proc->params);
     if (!isset($_REQUEST["x_invoice_num"]) || empty($_REQUEST["x_invoice_num"])) {
         echo "Order ID is not set or empty!";
     } else {
         if ($_REQUEST['x_Login'] != $params->get('x_login', '')) {
             die('Invalid account number.');
         }
         // demo transaction
         if (isset($_REQUEST['demo']) && $_REQUEST['demo'] == "Y" && !$params->get('demo', '')) {
             die('Demo mode is switched off.');
         }
         $order_number = mosGetParam($_REQUEST, "x_invoice_num");
         $compare_string = $params->get('x_secret') . $params->get('x_login') . $_REQUEST['order_number'] . $_REQUEST['x_amount'];
         $payment_date = date("Y-m-d H:i:s", mktime());
         $compare_hash1 = strtoupper(md5($compare_string));
         $compare_hash2 = $_REQUEST['x_MD5_Hash'];
         if ($compare_hash1 != $compare_hash2 && !$params->get('demo')) {
             die('Invalid secret hash.');
         }
         if ($_REQUEST['x_response_code'] == '1' && $_REQUEST['x_2checked'] == 'Y') {
             $payment_amount = $_REQUEST['x_amount'];
             $tax_amount = $_REQUEST['tax_amount'];
             $txn_id = $_REQUEST['x_trans_id'];
             if ($params->get('demo')) {
                 $txn_id .= ' - demo mode';
             }
             $payment_date = date("Y-m-d H:i:s");
             $order_id = $_REQUEST['custom'];
             $user_id = $_REQUEST['userid'];
             $payment_currency = $JLMS_CONFIG->get('jlms_cur_code');
             require_once _JOOMLMS_FRONT_HOME . '/includes/joomla_lms.subscription.lib.php';
             if (!jlms_check_payment_transaction($payment_amount - $tax_amount, $order_id)) {
                 die('Invalid payment amount');
             }
             $query = "SELECT status FROM `#__lms_payments` WHERE id = {$order_id} ";
             $JLMS_DB->setQuery($query);
             $prev_payment = $JLMS_DB->LoadResult();
             jlms_update_payment($order_id, $txn_id, 'Completed', $payment_date);
             if ($prev_payment == 'Completed') {
             } else {
                 jlms_register_new_user($order_id);
             }
         }
         if ($params->get('return_url') == '') {
             JLMSRedirect($JLMS_CONFIG->get('live_site'));
         } else {
             JLMSRedirect($params->get('return_url'));
         }
     }
 }