Author Topic: Order confirmation email sent before PayPal payment processed  (Read 88819 times)

angek

  • Beginner
  • *
  • Posts: 20
    • joomlaextensions.com.au
Re: Order confirmation email sent before PayPal payment processed
« Reply #30 on: January 23, 2009, 04:02:44 am »
OK, I have to admit that I haven't read EVERY post in this particular topic, but I read enough to know that many of you are having the same issue that I am in trying to prevent a "Pending" order email from going to the customer.
Well, I THINK I've got it somewhat figured out for VM 1.1.2 (and ONLY this version) but I've got to head out for a bit.  I'll try and get back on here tonight to post what I did. It basically requires two changes to the ps_checkout.php file.
It is currently hardcoded, however, I think I should easily be able to turn it into a configurable option on the backend... maybe in the template configuration controls?

are you referring to the email_receipt() function in the ps_checkout.php file?
In the email_receipt function there are a number of calls to vmMail (for plain text emails and for html emails) which could be wrapped in conditional statements to check the order_status before sending the email. Specifically the following:

around line 2041 you should have this block of code:
Code: [Select]
if (ORDER_MAIL_HTML == '0') {

$msg = $shopper_header . $shopper_message . $shopper_footer;

// Mail receipt to the shopper
vmMail( $from_email, $mosConfig_fromname, $shopper_email, $shopper_subject, $msg, "" );

$msg = $vendor_header . $shopper_message . $vendor_footer;

// Mail receipt to the vendor
vmMail($from_email, $mosConfig_fromname, $vendor_email, $vendor_subject, $msg, "" );

}
Now change it to:
Code: [Select]
if (ORDER_MAIL_HTML == '0') {

$msg = $shopper_header . $shopper_message . $shopper_footer;

// Mail receipt to the shopper
        if (strtolower($order_status) != 'pending'){
    vmMail( $from_email, $mosConfig_fromname, $shopper_email, $shopper_subject, $msg, "" );
        }
$msg = $vendor_header . $shopper_message . $vendor_footer;

// Mail receipt to the vendor
vmMail($from_email, $mosConfig_fromname, $vendor_email, $vendor_subject, $msg, "" );

}


then on line 2160 you should have these 2 lines of code:

Code: [Select]
$shopper_mail = vmMail( $from_email, $mosConfig_fromname, $shopper_email, $shopper_subject, $shopper_mail_Body, $shopper_mail_AltBody, true, null, null, $EmbeddedImages);

$vendor_mail = vmMail( $shopper_email, $shopper_name, $vendor_email, $vendor_subject, $vendor_mail_Body, $vendor_mail_AltBody, true, null, null, $EmbeddedImages);

change it to:
Code: [Select]
if (strtolower($order_status) != 'pending'){
    $shopper_mail = vmMail( $from_email, $mosConfig_fromname, $shopper_email, $shopper_subject, $shopper_mail_Body, $shopper_mail_AltBody, true, null, null, $EmbeddedImages);
}

$vendor_mail = vmMail( $shopper_email, $shopper_name, $vendor_email, $vendor_subject, $vendor_mail_Body, $vendor_mail_AltBody, true, null, null, $EmbeddedImages);

This should prevent the email confirmation going out to customers when their order status is pending while still allowing the store owner to still receive the pending order emails.

I haven't tested this properly so if someone would like to give it a go and report back their findings then I'd be happy to code up some configurable options rather than having everything hardcoded.

By the way I'm using virtuemart 1.1.3 on Joomla 1.0.15 but should be the same for vm 1.1.3 for Joomla 1.5.x

Frederik

  • Beginner
  • *
  • Posts: 9
Re: Order confirmation email sent before PayPal payment processed
« Reply #31 on: January 23, 2009, 10:38:49 am »
Very nice. I don't have the time today but I'll test it first thing tomorrow and get back to you. Can't wait... Thanks a lot :-)

Frederik

  • Beginner
  • *
  • Posts: 9
Re: Order confirmation email sent before PayPal payment processed
« Reply #32 on: January 23, 2009, 17:15:30 pm »
I have implemented the changes and the customer is now receiving a confirmation mail and no pending mail. That is a huge leap forward 8)

There is still some minor issues as I see it:

The confirmed mail the customer is receiving is just saying "status has changed". The customer isn't receiving the order details and the link to the order details as it was in the pending mail.

Also the text doesn't make sense as the confirmation mail is the first mail the customer is receiving. I take that it is an easy fix which I probably can do myself.

The shop is only receiving a pending mail and no confirmation mail. Personally I would much rather have the confirmed mail as a shop owner instead of the pending mail.

The VM page telling "the order is confirmed" before the payment is done, needs to be changed as it is saying: "a mail has been sent to...." I would change the overall message to something like: "a new payment window has been opened..." and so on and nothing about the order is confirmed which I find a bit confusing

I am using VM 1.1.3 and Joomla! 1.5.9

Very nice work Angek :)


MikeUK

  • Global Moderator
  • Hero Member
  • *
  • Posts: 1343
Re: Order confirmation email sent before PayPal payment processed
« Reply #33 on: January 23, 2009, 21:46:03 pm »
I might be wrong, but I think a potential problem here is that this bit of code isn't used after confirmation. So it won't send a pending email, nor a confirmation email. The status change email is a separate process I think.
Get answers faster:

I can build your online shop, setup or customize Virtuemart or help your existing shop maximize its potential. Email / PM for info

Frederik

  • Beginner
  • *
  • Posts: 9
Re: Order confirmation email sent before PayPal payment processed
« Reply #34 on: January 26, 2009, 14:40:30 pm »
I don't think I ever received a confirmation mail - just the pending mail and the status change mail.

I have spend hours to try and figure out where the code for the pending mail is produced and if it could be reused for a confirmation mail with no luck. Is there somebody that can lead me in the right direction? Does a documentation for the checkout procedure exist?

MikeUK

  • Global Moderator
  • Hero Member
  • *
  • Posts: 1343
Re: Order confirmation email sent before PayPal payment processed
« Reply #35 on: January 26, 2009, 14:50:38 pm »
Sorry, yes, forget the confirmation email bit. If that was there, it would be problem solved!

The pending email is sent from ps_checkout.... a line point to a function called email_receipt I think.

The thing is, I believe that by the time the order is confirmed, it doesn't go back here.
Get answers faster:

I can build your online shop, setup or customize Virtuemart or help your existing shop maximize its potential. Email / PM for info

Frederik

  • Beginner
  • *
  • Posts: 9
Re: Order confirmation email sent before PayPal payment processed
« Reply #36 on: January 26, 2009, 15:02:15 pm »
Where exactly does the status change? Not in the ps_checkout or..?

angek

  • Beginner
  • *
  • Posts: 20
    • joomlaextensions.com.au
Re: Order confirmation email sent before PayPal payment processed
« Reply #37 on: January 27, 2009, 02:19:45 am »
I have implemented the changes and the customer is now receiving a confirmation mail and no pending mail. That is a huge leap forward 8)
There is still some minor issues as I see it:
The confirmed mail the customer is receiving is just saying "status has changed". The customer isn't receiving the order details and the link to the order details as it was in the pending mail.
Also the text doesn't make sense as the confirmation mail is the first mail the customer is receiving. I take that it is an easy fix which I probably can do myself.
The shop is only receiving a pending mail and no confirmation mail. Personally I would much rather have the confirmed mail as a shop owner instead of the pending mail.
The VM page telling "the order is confirmed" before the payment is done, needs to be changed as it is saying: "a mail has been sent to...." I would change the overall message to something like: "a new payment window has been opened..." and so on and nothing about the order is confirmed which I find a bit confusing
I am using VM 1.1.3 and Joomla! 1.5.9
Very nice work Angek :)

thanks for the feedback. I've got some free time over the next couple of days so I'm going to try and sort out the confirmation email and text and post back.

angek

  • Beginner
  • *
  • Posts: 20
    • joomlaextensions.com.au
Re: Order confirmation email sent before PayPal payment processed
« Reply #38 on: January 28, 2009, 02:04:47 am »
I don't think I ever received a confirmation mail - just the pending mail and the status change mail.
I have spend hours to try and figure out where the code for the pending mail is produced and if it could be reused for a confirmation mail with no luck. Is there somebody that can lead me in the right direction? Does a documentation for the checkout procedure exist?
I too have never seen a confirmation email or at least not a confirmation email as I would have expected. The confirmation email only indicates that the order status has changed and nothing more. Ideally it should resemble the purchase order  but renamed to invoice or something similar.
What I've been able to figure out is as follows:
order is placed and the checkout process begins. We go through all the steps until we reach the final step where we click the "confirm order" button. This process adds the order to the database, sends the purchase order to the customer and shop owner then redirects to paypal for payment.
The payment is processed and the notify.php script is executed which handles the response POST info from paypal.
Code: [Select]
require_once ( CLASSPATH . 'ps_order.php' );
$ps_order= new ps_order;
$ps_order->order_status_update($d);
$mailsubject = "PayPal IPN txn on your site";
$mailbody = "Hello,\n\n";
$mailbody .= "a PayPal transaction for you has been made on your website!\n";
$mailbody .= "-----------------------------------------------------------\n";
$mailbody .= "Transaction ID: $txn_id\n";
$mailbody .= "Payer Email: $payer_email\n";
$mailbody .= "Order ID: $order_id\n";
$mailbody .= "Payment Status returned by PayPal: $payment_status\n";
$mailbody .= "Order Status Code: ".$d['order_status'];
vmMail($mosConfig_mailfrom, $mosConfig_fromname, $debug_email_address, $mailsubject, $mailbody );
In the notify.php script there's a call to order_status_update() function which is defined in the ps_order.php script. The order status should be updated to "Completed", stocklevels checked and updated if required and so forth.
Finally notify_customer() is called and an email is sent to the customer informing them that their order has been updated from "Pending" to "Completed".
If this logic is correct (please correct me if it's not) then we need
to do a couple of things to get this all working the way we want:
1. disable the email alert when the order is initially confirmed (final stage of the check out process).
2. modify the notify.php script so that it sends out a "final" confirmation email to the user and shop owner. (this is the pending email rehashed to remove all the "pending" phrases and changing "purchase order" to "invoice or something similar). or modify the checkout.result.php script (which is the return url as defined in the extra payment info section of the paypal configuration
Code: [Select]
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),) to send the confirmed email (invoice) to the customer and shop owner.
The other thing I have found is that under test conditions the IPN stuff doesn't work (www.eliteweaver.co.uk/testing/ipntest.php no longer exists - I can't seem to get to it :( so order statuses are not being updated on successful test transactions.)
Am I right in my assumptions and the process flow? If so would the solution I have proposed work without affecting anything else?

angek

  • Beginner
  • *
  • Posts: 20
    • joomlaextensions.com.au
Re: Order confirmation email sent before PayPal payment processed
« Reply #39 on: January 28, 2009, 04:02:42 am »
I've started coding the changes I mentioned in my post above but I need help with something. If anyone has a live site that uses paypal as the payment method can they please verify that the order_status is automatically updated from "Pending" to "Confirmed" once a successful payment has been made and that 2 emails are sent one being the purchase order and the other the status changed confirmation so that I can get the conditional statements correct please.

cinos

  • Jr. Member
  • **
  • Posts: 85
Re: Order confirmation email sent before PayPal payment processed
« Reply #40 on: January 29, 2009, 15:27:16 pm »
I have only tested my site on the paypal sandbox, but I can tell you that that is indeed what happens. I can't think of a reason why it would be any different for the live site. :)

Though the confirmation email is sent first and then the email regarding the status change is sent once notify.php is updated (payment successful).

angek

  • Beginner
  • *
  • Posts: 20
    • joomlaextensions.com.au
Re: Order confirmation email sent before PayPal payment processed
« Reply #41 on: January 29, 2009, 20:37:56 pm »
Thanks for the info. I should have finished coding up the changes by close of business today and will post a patch file. Given that I'm somewhat new to vm I may have missed something so all feedback would be greatly appreciated.

angek

  • Beginner
  • *
  • Posts: 20
    • joomlaextensions.com.au
Re: Order confirmation email sent before PayPal payment processed
« Reply #42 on: January 30, 2009, 00:22:22 am »
guys, here's a brief doc outlining the proposed patch that I'm creating. I'm in the process of testing the patch file and will post it here once I'm done.

[attachment deleted by admin]

tantan

  • Beginner
  • *
  • Posts: 14
Re: Order confirmation email sent before PayPal payment processed
« Reply #43 on: January 30, 2009, 02:31:25 am »
Angek,

Many thanks, great job ...


angek

  • Beginner
  • *
  • Posts: 20
    • joomlaextensions.com.au
Re: Order confirmation email sent before PayPal payment processed
« Reply #44 on: January 30, 2009, 02:54:51 am »
dont thank me yet ;)

VirtueMart Forum

Re: Order confirmation email sent before PayPal payment processed
« Reply #44 on: January 30, 2009, 02:54:51 am »