News:

Support the VirtueMart project and become a member

Main Menu

Order Status remains Pending/not Confirmed from Pay Pal, HELP PLEASE!?!

Started by musicianx2, November 08, 2009, 04:35:14 AM

Previous topic - Next topic

musicianx2

Hello,

I am running Joomla 1.5.14 and Virtuemart 1.1.4. The order status does not change from pending to confirmed upon payment completion of a successful paypal transaction in my back end, and therefore no confirmation email is sent. However, I know that the confirmation email itself works for I have tested it with the item total at zero, and that works fine. Also, I am receiving purchase orders on both the seller and buyer ends, so the only thing missing is the confirmation of the order and the resultant confirmation email. I am currently testing in the Paypal sandbox.

My Payment Method Configuration is:

Testmode: NO
Order Status for successful transactions: Confirmed
Order Status for Pending Payments: Pending
Accept only verified buyers: Yes
Order Status for failed transactions: Cancelled
Yes

In Paypal:

Instant Payment Notification(IPN)
Notification URL: http://www.mydomain.com/administrator/components/com_virtuemart/notify.php
Message delivery    Enabled

Website Payment Preferences
Auto Return: On
Return URL: http://www.mydomain.com/administrator/components/com_virtuemart/notify.php
Payment Data Transfer: On

I know this is a frequent issue as I have been doggedly searching the forums all day every day for a week now trying to figure this out, but my brain is fried.. I've looked at and tried many ideas, but still can't figure it out. Does anyone know how to fix this. Am I missing something? Please advise. ???

musicianx2

Here also is my Payment Extra Info:

<?php

/** Read current Configuration ***/
include_once(CLASSPATH ."payment/ps_paypal_conf.cfg.php");   
include_once(CLASSPATH ."payment/ps_paypal_conf.php");

$db_conf = new ps_DB;
$ps_paypal_conf = new ps_paypal_conf();
$NOTIFY_DEBUG = false;

$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
$return_url = SECUREURL ."index.php?option=com_virtuemart&page=checkout.result_confirmation&order_number=";
$notify_url = SECUREURL ."administrator/components/com_virtuemart/notify_gen_transaction.php";
$cancel_return = SECUREURL ."index.php?option=com_virtuemart&page=checkout.result_confirmation&cancel=1";

//$_SESSION["payement_transid"] ="";
$transid = $_SESSION["payement_transid"];
$order_number = $_SESSION["payement_order_number"]; 

//Calc total for paypal
$paypal_total = $total-$discount_total;
if ($auth["show_price_including_tax"] == 0) $paypal_total += $tax_total;

$_SESSION['total_amount'] = round( $paypal_total, 2);
$_SESSION['shipping_amount'] = sprintf("%.2f", $shipping_total);


//Create URL string to save all Request parameters
$requests = JRequest::get();
$confirmurl="";
foreach( $requests as $name => $value ) {
    $confirmurl .= $name . "=" . $value . "&";
}
if(!empty($zone_qty)) $confirmurl .= "&zone_qty=$zone_qty";


//If transaction has already been confirm then User payed and hit back button => Clean up session and redirect to thankyou
if($ps_paypal_conf->payement_is_confirmed($transid, $db_conf)){
         if ($NOTIFY_DEBUG) echo "payement is confirmed";
        //Order has been confirmed so clean up and reload modified SESSION from database
        $order_number = $ps_paypal_conf->cleanup_session($transid, $db_conf);
        // Redirect to thankyou page
        if ($NOTIFY_DEBUG) echo "should redirect to $return_url . $order_number";
        vmRedirect( $return_url . $order_number);
       
}elseif (!(empty($transid))){
        //User Came back to checkout without having payed, simply update session data in DB
        $sql = "SELECT * from #__vm_orders_temp WHERE id='".$transid."'";
        $db_conf->query($sql);
        if(!$db_conf->next_record()){
            //Transaction is not in DB at all, something is wrnog clean up ...
            $ps_paypal_conf->cleanup_session_vars();
            $transid = "";
            $_SESSION['total_amount'] = round( $paypal_total, 2);
            $_SESSION['shipping_amount'] = sprintf("%.2f", $shipping_total);
        }else{
            if ($NOTIFY_DEBUG) echo "TransID not empty updating DB transid = $transid";
            $sessioncontent=base64_encode(serialize($_SESSION));     
            $sql = "UPDATE #__vm_orders_temp SET urlpost='".addslashes($confirmurl)."', urlerror='".addslashes($errorurl)."', sessioncontent='".addslashes($sessioncontent)."' , modifiedtime=NOW() WHERE id='".$transid."'";
            $db_conf->query($sql);
        }
       
}

if (empty($transid)){
    //First time on Checkout page save temporary transaction information   
     
    //Get Order Number using default checkout function
    include_once(CLASSPATH ."ps_checkout.php");   
    $ps_checkout = new ps_checkout();
    $order_number = $ps_checkout->get_order_number();
    if ($NOTIFY_DEBUG) echo "New ORDER NUMBER  = $order_number";
   
    // Add order Number to session value before saving to db
    $_SESSION["payement_order_number"]=$order_number ; 
    $sessioncontent=base64_encode(serialize($_SESSION));   
     
    //Save temporary transaction data to DB
    $sql = "INSERT INTO #__vm_orders_temp (`status`,`urlpost`,`urlerror`,`createdtime`,`modifiedtime`, `sessioncontent`, `order_number` , `user_id`) VALUES
   ('0','".addslashes($confirmurl)."','".addslashes($errorurl)."',NOW(),NOW(),'".addslashes($sessioncontent)."','".$order_number."','".$my->id. "')";
    $db_conf->query($sql);
   
    $_SESSION["payement_transid"] = $transid = $db_conf->last_insert_id();
}

if ($NOTIFY_DEBUG) print $_SESSION["payement_order_number"];



//Get coutry code
$db1 = new ps_DB();
$q = "SELECT country_2_code FROM #__vm_country WHERE country_3_code='".$user->country."' ORDER BY country_2_code ASC";
$db1->query($q);

//Get user infos
$dbbt = new ps_DB;
$q = "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbbt->query($q);

//**** START FORM CREATION *****//


if (GENERATE_TRANSACTION_ON_CONFIRMATION == 1) {
    //Form for including directly into checkout.index form
    //Defines all input variables off form
    $post_variables = Array(
        "cmd" => "_ext-enter",
        "redirect_cmd" => "_xclick",
        "upload" => "1",
        "business" => PAYPAL_EMAIL,
        "receiver_email" => PAYPAL_EMAIL,
        "item_name" => $VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_LBL').": ". $vendor_name,
        "order_id" => $transid,
        "invoice" => $order_number,
        "amount" => round( $paypal_total, 2),
        "shipping" => sprintf("%.2f", $shipping_total),
        "currency_code" => (!empty($_SESSION['product_currency']))? $_SESSION['product_currency'] : $_SESSION['vendor_currency'],

        "address_override" => "1",
        "first_name" => $dbbt->f('first_name'),
        "last_name" => $dbbt->f('last_name'),
        "address1" => $dbbt->f('address_1'),
        "address2" => $dbbt->f('address_2'),
        "zip" => $dbbt->f('zip'),
        "city" => $dbbt->f('city'),
        "state" => $dbbt->f('state'),
        "country" => $db1->f('country_2_code'),
        "email" => $dbbt->f('user_email'),
        "night_phone_b" => $dbbt->f('phone_1'),
        "cpp_header_image" => $vendor_image_url,

        "return" => $return_url . $order_number,
        "notify_url" => $notify_url,
        "cancel_return" => $cancel_return,
        "undefined_quantity" => "0",

        "test_ipn" => PAYPAL_DEBUG,
        "pal" => "NRUBJXESJTY24",
        "no_shipping" => "1",
        "no_note" => "1"
    );
}else{
//Form for using when Transaction already saved
    $tax_total = $db->f("order_tax") + $db->f("order_shipping_tax");
    $discount_total = $db->f("coupon_discount") + $db->f("order_discount");
    //Defines all input variables off form
    $post_variables = Array(
        "cmd" => "_xclick",
        "business" => PAYPAL_EMAIL,
        "receiver_email" => PAYPAL_EMAIL,
        "item_name" => $VM_LANG->_PHPSHOP_ORDER_PRINT_PO_NUMBER.": ". $db->f("order_id"),
        "order_id" => $db->f("order_id"),
        "invoice" => $db->f("order_number"),
        "amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total, 2),
        "shipping" => sprintf("%.2f", $db->f("order_shipping")),
        "currency_code" => $_SESSION['vendor_currency'],
        "first_name" => $dbbt->f('first_name'),
        "last_name" => $dbbt->f('last_name'),
        "address_street" => $dbbt->f('address_1'),
        "address_zip" => $dbbt->f('zip'),
        "address_city" => $dbbt->f('city'),
        "address_state" => $dbbt->f('state'),
        "address_country" => $dbbt->f('country'),
        "image_url" => $vendor_image_url,
        "return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
        "notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
        "cancel_return" => SECUREURL ."index.php",
        "undefined_quantity" => "0",
        "test_ipn" => PAYPAL_DEBUG,
        "pal" => "NRUBJXESJTY24",
        "no_shipping" => "1",
        "no_note" => "1"
    );
}

//OLD WAY OF DOING chekout..... If in thankyou page then Transaction was already confirmed and we redirect to PAYPAL
if( $page == "checkout.thankyou" ) {
    $query_string = "?";
    foreach( $post_variables as $name => $value ) {
        $query_string .= $name. "=" . urlencode($value) ."&";
    }
    vmRedirect( $url . $query_string );
} elseif ($page=="checkout.index" )  {
    // Generate The form for the checkout button
    ?>
    <script type="text/javascript">
        var VIRTUEMART_URL="administrator/components/com_virtuemart/notify_gen_transaction.php";
        var VIRTUEMART_REQ_VAL ="save_transaction=1&transid=<?php echo $transid?>";
        var immoxmlhttp;
        var nb_tries=0;
        var max_tries=3;
       
        <?php if (GENERATE_TRANSACTION_ON_CONFIRMATION == 1) echo 'remove_original_submit_button();'; ?>
       
        function remove_original_submit_button(){                       
            document.adminForm.formSubmit.style.display="none";
            //document.getElementsByName("formSubmit")[1].style.display = "none";
        }
       
        function myXmlHttpReq(){
            if (window.XMLHttpRequest){
                var req = new XMLHttpRequest(); 
            }else if (window.ActiveXObject){
                var req = new ActiveXObject("Microsoft.XMLHTTP");
            }
            return req;
        }             
       
        function sendReq(){
            immoxmlhttp = new myXmlHttpReq();
            immoxmlhttp.onreadystatechange = processCommentReqChange;
            immoxmlhttp.open("POST", VIRTUEMART_URL, true);
            immoxmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            immoxmlhttp.send(VIRTUEMART_REQ_VAL);
            setLoadingImg();
        }
       
        function setLoadingImg(){                           
            img_req='<img src="images/stories/spin.gif">';
            ldimgdiv=document.getElementById("loadimgdivid");
            ldimgdiv.innerHTML=img_req;
        }
       
        function validateAndSentForm(){
            if(submit_order( document.adminForm )){
               VIRTUEMART_REQ_VAL += "&customernote=" + document.adminForm.customer_note.value;
               sendReq();
               return true;
            }
            else
                return false;
        }
       
        function processCommentReqChange(){
            if (immoxmlhttp.readyState == 4){
                 try{
                    // only if "OK"
                    if (immoxmlhttp.status == 200){
                       //alert(immoxmlhttp.responseText);
                        var r=immoxmlhttp.responseText;
                       var haserror=r.substring(r.indexOf("<error>"),r.indexOf("</error>")).replace("<error>","");
                        if(haserror==1){
                            errmsg= r.substring(r.indexOf("<errormsg>"),r.indexOf("</errormsg>")).replace("<errormsg>","");
                            alert(errmsg);
                        }
                        else{
                            //we submit the form
                            //document.forms[2].submit();
                            //postform=document.getElementById("postfinanceformid");
                           
                          /*$transid = r.substring(r.indexOf("<errormsg>"),r.indexOf("</errormsg>")).replace("<errormsg>","");
                          $form=document.getElementById("payment_method_form");
                          $form.order_id.value=$transid;
                          $form.invoice.value=$transid;
                            */
                            document.getElementById("payment_method_form").submit();
                            //postform.submit();
                        }
                    }else{
                        if(nb_tries >= max_tries){
                            //Send an error message
                            ldimgdiv=document.getElementById("loadimgdivid"); 
                            ldimgdiv.innerHTML += ' Connection lost, retrying connection ... <br>';
                            nb_tries=0;   
                        }else{
                            nb_tries++;
                        }
                        setTimeout('sendReq()', 3000);
                    }
                }catch(E){
                    alert(E);
                    if(nb_tries >= max_tries){
                        ldimgdiv=document.getElementById("loadimgdivid");
                        ldimgdiv.innerHTML="Connection lost, retrying connection ...";   
                        nb_tries=0;   
                    }else{
                        nb_tries++;
                    }
                        setTimeout('sendReq()', 3000);
                }
            }
        }
                   
    </script>
       
    <?php   
    // Close the Checkout Form, which was opened in the first checkout template using the variable $basket_html
    echo '</form>';

    if (GENERATE_TRANSACTION_ON_CONFIRMATION == 1){
        echo '<form action="'.$url.'" method="post" id="payment_method_form">';
        echo '<div align="center" id="loadimgdivid"><input type="button" name="confirmbutton" value="'.$VM_LANG->_('PHPSHOP_ORDER_CONFIRM_MNU').'" onclick="return( validateAndSentForm());" class="button" style="align:middle;"></div>';
        //echo '<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" onclick="return( validateAndSentForm()) alt="Click to pay with PayPal - it is fast, free and secure!" />';
        //<div id="loadimgdivid"><input type="button" name="confirmbutton" value="Confirmer" onclick="return( validateAndSentForm() );" style="text-align:middle;width:115px;height:15px;cursor:pointer;border:none;font-weight:bold;color:#b9298b;font-size:10px;font-family:inherit;background: url('{TEMPLATEPATH}/images/bouton.png') no-repeat top right transparent;margin-top:10px;"></div>
        foreach( $post_variables as $name => $value ) {
            echo '<input type="hidden" name="'.$name.'" value="'.htmlspecialchars($value).'" />
            ';
        }
        echo '</form>';
    }
}   
//**** END  FORM CREATION *****//



?>

If there are any errors or alterations that will make this work please let me know. Thank you.

Scar

I don't know why you have all that in your extra info. What I see is that you are using the sandbox url even though you are not in testmode. You should definitely read this post: http://forum.virtuemart.net/index.php?topic=39584.0

stinga

G'day,

there seems to be a lot of stuff in there, do you know what it does? I have not read it.

It looks like you are using the sandbox.

When you place an order and pay with PayPal, where do you get sent after you have confirmed in PayPal.

notify.php is the script that changes the order status, what you have posted is the code that *sends* data to paypal.
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4


InternalWealth

I had a 6 week long issue with this and finally found my answer picking up Paypal Payments Pro from My Joomla Extensions.

Huge relief!  Works perfectly.  Just make sure you have the right credentials set and that you have the right Payments Pro package installed (US, CAN, or UK).  If you have a US Paypal Websites Payments Pro account and use the CAN or UK package... it won't work- and vice-versa.

I have a whole Pay-Per-View system set up through Virtuemart that relies on getting that 'Confirmed' switch to happen, so needless to say, this was an absolutely necessary requirement.

kreativeone

I have noticed the same, the status doesn't change so I've started to debug. I created new "Order Status Types" under VM=>Administration=>Add Order Status Types just for PayPal. For example, I created "PayPal Pending", "PayPal Confirmed" and "PayPal Cancelled" then I changed the defaults for each type respectively on the "Configuration" tab for the PayPal payment method.

I'm working in the PayPal Sandbox and I do get responses back and I do get status changes to the new order status types. My test customer gets the original order acknowledgement AND gets the status change email which comes as part of the IPN notification back to my site.

So adding new order status types forces the notify script to change the status which generates the second email to the customer.

I haven't figured out why I don't get confirmed statuses back (only pending)... still working on some debugging techniques.
========
Joomla 1.5.14 / VirtueMart 1.1.4

stinga

G'day,

I gave up with sandbox, I could not get it to work properly.
I just assumed that if I get the data to paypal correctly it will get the data back to me.

I have sprinkled...

file_put_contents('/tmp/recoverycddisk', __FILE__.":".__LINE__." (".$db->f('order_id').") paypal status is ".$payment_status."\n", FILE_APPEND);

To search out what paypal does when it sends data back. Various output line and doing tcpdump to see what paypal contacts us, makes it all good!
I now have it working correctly for payments, just need to get refunds working!
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

Laurelle

Hello,

Has anyone found the problem yet?

I have a Joomla 1.5.15 and VM 1.1.4 site using PayPal and it always has the payment set to Pending, even though when you come back to the website from PayPal the site says that the order was confirmed. But if you then look at your invoice, it shows Pending and in the backend the order status is Pending.

I have another Joomla 1.5.15 and VM 1.1.4 site using PayPal Pro Canada from joomlaextensions.com. It has the same problem the order status is always Pending.

I have another site that is Joomla 1.5.14 and VM 1.1.3 and it works fine, status is updated as it should be.

So, I am wondering if there was a bug introduced in VM 1.1.4 that is causing this problem.

Yes, I have triple check that I have setup the status for sucessfully transactions to be Confirmed.

I have compared the PayPal Payment Extra Info fields from the working 1.1.3 site to the 1.1.4 site and they are the same. I have compared the /administrator/components/com_virtuemart/classes/payments/ps_paypal.php and ps_paypal.cfg.php files. The ps_paypal.php file is the same and the only different in the ps_paypal.cfg.php file is the email address. I have compared the notify.php files and they are the same except for the debug setup lines 263 to 266, so that shouldn't make a difference.

I have requested help from joomlaextensions.com on their PayPal Pro extension, but did not get any resolution. They tried to find the problem, but then gave up.

We need to go live with the PayPal site today, but this is going to cause a big problem if not transaction order status are updated.

Thanks for any help on this.



stinga

G'day,

I will say it again just make sure it is clear...

In a stock JVM install...
The status is not updated when you return to your shop from paypal.
notify.php is the script that is called by paypal and notify.php sets the status.

You are going to need to put some debug messages in notify.php or find out if paypal is calling notify.php.

I think there are time when paypal returns you to your shop, your shop says' Thanks for the money" but pp has not called notify.php yet.
You then wait a bit and eventually pp does call notify.php and your status is updated.

Is your status ever updated?
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

Laurelle

Hi,

With the PayPal Pro PayPal returns the status of the order right away and VM needs to update the status of the order then, not wait for notify.php to be called because PayPal won't be calling notify.php since it already has told VM that the status is confirmed. After hours of going through the myjoomlaextensions.php code and fixing a bunch of bugs I finally found that the enable_processor field in the payment_method table for PayPal Pro was not set to Y, so the confirmation was not getting updated by VM. Once I finally found that this field needed to be set to Y and set it, the confirmation started to work.

I don't know if this is also the case for normal PayPal, but I didn't find anything in the code to indicate that the status gets updated right after the call, so notify.php is probably what updates the status.


Now that I have Pro working I need to figure out how to get Express working with it. The files that myjoomlaextensions.com provides don't work, but I am having trouble debugging them, as my debug messages aren't showing up, I just get the white page with wrong credit card number message.

Cheers.

stinga

G'day,

I had not realised that PP and PPPro work differently. I wonder what the advantages are. I wonder if PPPro can be used in the UK. More work...
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

Laurelle

Hi,

Yes, PayPal and PayPal Pro are different and you have to have a PayPal Pro payment gateway for virtuemart. That is where the problem lies, getting the payment gateway working with Virtuemart. And yes, there is PayPal Pro for the UK.

Just and FYI on forum ettique: You have hijacked this forum post to learn about PayPal Pro when it is supposed to be about solving Pro issues. You should have started a different forum post to ask about Pro.

Cheers.

stinga

Err, no I have not done hijacking, I was helping the OP out, I believe you hijacked this post first. You brought up PPPro first. :-)
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

webuser

hi guys I also posted something in another similar thread at http://forum.virtuemart.net/index.php?topic=48421.0 sorry if double posting is bad but man these forums are pretty crazy. I am having the same issue as everyone else (status is not being updated to confirmed on an order paid via paypal) however its only happening ocasionally. I use Joomla 1.59, VM1.1.3, server running suPHP permissions all good, paypal account verified, just seems to happen randomly. Any suggestions?
http://www.webcircle.com.au - Gold Coast Web Design
http://awebsitedesigner.com.au - Website Design