News:

Looking for documentation? Take a look on our wiki

Main Menu

Order confirmation email sent before PayPal payment processed

Started by davidm, May 01, 2008, 12:57:41 PM

Previous topic - Next topic

davidm

I am using Joomla 1.5 and VirtueMart 1.1. I have VirtueMart set to "Silent Account Creation" and PayPal as a single Payment Method.

The shopper goes through the checkout process and, on confirming the order on the last checkout page, is correctly redirected to the PayPal site. However, it seems that order confirmation emails are sent (both to the shopper and the store owner) before the payment is made. These emails appear to be sent as soon as the shopper is redirected to the PayPal site.

I would really like to change this so that the order confirmation emails are only sent if the payment is successful. Does anyone know how I can get it working like that or what the problem might be?

I think I am going to have big problems with user confusion, order management and stock management unless I can find a solution to this.

Thanks

willowtree

not sure if its changed in 1.1, but in 1.0 the order is set to pending before paypal payment is processed, and only set to confirmed when the payment is processed by paypal.

there are other posts about this on the forum somewhere,

hth
Please add your VM and Joomla Version to your signature to make it easier to help you:

Most of my code posted in the forum is for VirtueMart 1.0  -  not for 1.1

davidm

Thanks hth for the quick response - that was very helpful. I found the following 1.0 discussions:

http://forum.virtuemart.net/index.php?topic=22819.0
http://forum.virtuemart.net/index.php?topic=17490.0
http://forum.virtuemart.net/index.php?topic=19236.0

These have helped me understand why Virtuemart handles pending transactions the way it does, but I think some challenges remain:

1. When the "No Account Creation" problem (http://forum.virtuemart.net/index.php?topic=39156.0) is fixed, I would really like to use that setting. If no account has been created for the user, it doesn't make sense to send a pending email with a link because the shopper doesn't have an account to use to complete their order. If they didn't complete their PayPal payment and still want to purchase then they will need to start again.

2. In my experience, most ecommerce sites only send a confirmation when the purchase has been made. Shoppers may miss the pending status and get confused.

3. In the case where there are items for sale with very limited stock, 'purchases' made without payment remove the item from stock even though the items are not actually sold.

In order to help with these issues whilst still allowing confirmation pending emails for those that like them, my suggestions would be to:

a) have a configuration option making it possible to either enable or disable order confirmation emails when the order is in a pending state (confirmation orders on completion should, of course, be sent)

and

b) have an optional background process that performs housekeeping on old pending orders. At its simplest, this could just delete pending orders that are older than x minutes. Or a more advanced solution might (optionally) first send an email to shoppers about pending orders older than y minutes giving them z days to complete their order before it is deleted.

Whilst not essential, I think these changes might help me and others who have had difficulty with the way pending orders are handled. Overall though, I must say that I think VirtueMart is fantastic. I am not being critical - Virtuemart is great software and I really appreciate all the work that has been put into 1.1.  Thanks!

Bob Bloom

As a wonderful client referred to this thread, I wanted to add my two cents.

When you click the order confirmation in checkout, function add( &$d ) is processed in /administrator/components/com_virtuemart/ps_checkout.php. It's description, ripped from the source code, is "This is the main function which stores the order information in the database".

The "INSERT" statement which sticks the new order into the database is different in VM 1.1. However, the result is the same. Here's the field values, verbatim from the source code:

// Collect all fields and values to store them!
$fields = array(
'user_id' => $auth["user_id"],
'vendor_id' => $ps_vendor_id,
'order_number' => $order_number,
'user_info_id' =>  $d["ship_to_info_id"],
'ship_method_id' => @urldecode($d["shipping_rate_id"]),
'order_total' => $order_total,
'order_subtotal' => $order_subtotal,
'order_tax' => $order_tax,
'order_tax_details' => serialize($order_tax_details),
'order_shipping' => $order_shipping,
'order_shipping_tax' => $order_shipping_tax,
'order_discount' => $payment_discount,
'coupon_discount' => $coupon_discount,
'coupon_code' => @$_SESSION['coupon_code'],
'order_currency' => $GLOBALS['product_currency'],
***SEE THIS ONE!!** --> 'order_status' => 'P',
'cdate' => $timestamp,
'mdate' => $timestamp,
'customer_note' => htmlspecialchars(strip_tags($d['customer_note']), ENT_QUOTES ),
'ip_address' => $ip
);


What is hard-coded: 'order_status' => 'P', That is, order status = pending.

Then, if you keep scrolling down, near the end of the function:
// Send the e-mail confirmation messages
$this->email_receipt($order_id);



So, an email is sent out to your customer with order = pending.

If you want to suppress the "pending" email completely, and deny me my hourly fee, then change $this->email_receipt($order_id); to //$this->email_receipt($order_id);

-Bob



Bob Bloom
freelance Joomla speshitpillt
http://southlasalle.com

davidm


chac416


chac416

Quote from: willowtree on May 01, 2008, 13:07:08 PM
not sure if its changed in 1.1, but in 1.0 the order is set to pending before paypal payment is processed, and only set to confirmed when the payment is processed by paypal.
there are other posts about this on the forum somewhere,
hth
Ok, is it possible to take off the pending part of the paypal process.
I do not want the order to be put on pending.
either complete transaction or nothing.
how to?  help anyone?

chac416

Hmmmm, I did a smarter change I guess...
Maybe you guys can test it more to see if it works well....
instead of commenting out the email_receipt, just make it run when the order is confirmed.
So i did this:


if ( $order_status == "C" ) {
  $this->email_receipt($order_id);
}


Then I tried with Paypal, and it did not send out an email with a pending status. it was recorded in the database as a pending order thou which is fine. it won't create confusion for the customer.

now i still need to test if it does send out a confirmation order when confirmed...

if anyone tries it then let me know how it goes... thanks

----
Quote from: Bob Bloom on May 05, 2008, 22:04:07 PM
As a wonderful client referred to this thread, I wanted to add my two cents.
When you click the order confirmation in checkout, function add( &$d ) is processed in /administrator/components/com_virtuemart/ps_checkout.php. It's description, ripped from the source code, is "This is the main function which stores the order information in the database".
The "INSERT" statement which sticks the new order into the database is different in VM 1.1. However, the result is the same. Here's the field values, verbatim from the source code:
// Collect all fields and values to store them!
$fields = array(
'user_id' => $auth["user_id"],
'vendor_id' => $ps_vendor_id,
'order_number' => $order_number,
'user_info_id' =>  $d["ship_to_info_id"],
'ship_method_id' => @urldecode($d["shipping_rate_id"]),
'order_total' => $order_total,
'order_subtotal' => $order_subtotal,
'order_tax' => $order_tax,
'order_tax_details' => serialize($order_tax_details),
'order_shipping' => $order_shipping,
'order_shipping_tax' => $order_shipping_tax,
'order_discount' => $payment_discount,
'coupon_discount' => $coupon_discount,
'coupon_code' => @$_SESSION['coupon_code'],
'order_currency' => $GLOBALS['product_currency'],
***SEE THIS ONE!!** --> 'order_status' => 'P',
'cdate' => $timestamp,
'mdate' => $timestamp,
'customer_note' => htmlspecialchars(strip_tags($d['customer_note']), ENT_QUOTES ),
'ip_address' => $ip
);

What is hard-coded: 'order_status' => 'P', That is, order status = pending.
Then, if you keep scrolling down, near the end of the function:
// Send the e-mail confirmation messages
$this->email_receipt($order_id);

So, an email is sent out to your customer with order = pending.
If you want to suppress the "pending" email completely, and deny me my hourly fee, then change $this->email_receipt($order_id); to //$this->email_receipt($order_id);
-Bob

draftvader

Just launched our store and I was talking to the first customer as he ordered.  He received the "pending" e-mail (as I have done in testing) before making any payment.  He commented that this could be confusing.

So, I guess what I am trying to say is that I am with everybody else here and would love a tested solution to this problem.

Many thanks for the GREAT system though!!!

bulabula

I commented out that line and it works great. My customers now get the Purchase Order (which I changed to Purchase Receipt in english.php) after they have paid on Paypal and come back to the site and at the same time they get a separate email that says "the status of your order has been changed: confirmed".

mccosha

Hey, great post - helped a lot !
How would I go about making the word "PENDING"  RED and in larger font ?
It will make it easier to emphasize it to the customer... I don't want to turn the email off, but it has caused some confusion though...

Joomla 1.5 VM 1.1

Thanks

Ariane

sunmade

Where exactly do you comment out the code?  I don't seem to have /administrator/components/com_virtuemart/ps_checkout.php  and am only using paypal as my method of payment.  Thanks in advance!

Quote from: Bob Bloom on May 05, 2008, 22:04:07 PM
As a wonderful client referred to this thread, I wanted to add my two cents.
When you click the order confirmation in checkout, function add( &$d ) is processed in /administrator/components/com_virtuemart/ps_checkout.php. It's description, ripped from the source code, is "This is the main function which stores the order information in the database".
The "INSERT" statement which sticks the new order into the database is different in VM 1.1. However, the result is the same. Here's the field values, verbatim from the source code:
// Collect all fields and values to store them!
$fields = array(
'user_id' => $auth["user_id"],
'vendor_id' => $ps_vendor_id,
'order_number' => $order_number,
'user_info_id' =>  $d["ship_to_info_id"],
'ship_method_id' => @urldecode($d["shipping_rate_id"]),
'order_total' => $order_total,
'order_subtotal' => $order_subtotal,
'order_tax' => $order_tax,
'order_tax_details' => serialize($order_tax_details),
'order_shipping' => $order_shipping,
'order_shipping_tax' => $order_shipping_tax,
'order_discount' => $payment_discount,
'coupon_discount' => $coupon_discount,
'coupon_code' => @$_SESSION['coupon_code'],
'order_currency' => $GLOBALS['product_currency'],
***SEE THIS ONE!!** --> 'order_status' => 'P',
'cdate' => $timestamp,
'mdate' => $timestamp,
'customer_note' => htmlspecialchars(strip_tags($d['customer_note']), ENT_QUOTES ),
'ip_address' => $ip
);

What is hard-coded: 'order_status' => 'P', That is, order status = pending.
Then, if you keep scrolling down, near the end of the function:
// Send the e-mail confirmation messages
$this->email_receipt($order_id);

So, an email is sent out to your customer with order = pending.
If you want to suppress the "pending" email completely, and deny me my hourly fee, then change $this->email_receipt($order_id); to //$this->email_receipt($order_id);
-Bob

willowtree

try

/administrator/components/com_virtuemart/classes/ps_checkout.php
Please add your VM and Joomla Version to your signature to make it easier to help you:

Most of my code posted in the forum is for VirtueMart 1.0  -  not for 1.1

winmonaye

I am testing with paypal standard with sandbox and comment out the "$this->email_receipt($order_id);" but still sending out email after redirected to paypal.

And one more thing is, even thought i could comment out this, when change to confirm, only status change notification is send out, not whole confirmation order detail, right?

This is very confusing and please help if someone know work around.

Thank you,

MikeUK

#14
.
Important note: please be careful with Bob Bloom's fix above. It will disable email confirmations for all payment methods. The customer will then receive an email after the Paypal transaction saying 'Order status changed'. This will make no sense as they have not received an order.


Quote from: chac416 on June 13, 2008, 18:43:05 PM
Hmmmm, I did a smarter change I guess...
Maybe you guys can test it more to see if it works well....
instead of commenting out the email_receipt, just make it run when the order is confirmed.
So i did this:

if ( $order_status == "C" ) {
  $this->email_receipt($order_id);
}

No, that won't work. This stage is too early in the process - this is before being forwarded to PayPal, so the order can never be confirmed at this point.

Quote from: chac416 on June 13, 2008, 18:03:15 PM
Quote from: willowtree on May 01, 2008, 13:07:08 PM
not sure if its changed in 1.1, but in 1.0 the order is set to pending before paypal payment is processed, and only set to confirmed when the payment is processed by paypal.
there are other posts about this on the forum somewhere,
hth
Ok, is it possible to take off the pending part of the paypal process.
I do not want the order to be put on pending.
either complete transaction or nothing.
how to?  help anyone?

That has giving me an idea. You might be on to something. Perhaps orders should start with a  status like 'Pending' for Cash on Delivery orders, and 'Awaiting Payment' for Paypal orders, with the paypal transaction returning 'confirmed', 'failed' or 'cancelled'. Pending would then be used for Cash on Deliver orders, etc only.

That way, with the sending emails before the Paypal transaction, at least the email would be an order confirmation with 'Awaiting Payment', then after a successul transaction the customer would recieve the 'changing order status' email saying 'Confirmed' (or 'failed', 'cancelled'). I think this would make much more sense to the customer. It then frees up Pending to mean what it should - that the order has been confirmed by the customer but there is still asction due (the customer pays later).

Any thoughts on this? Obviously it would mean changing the database and selecting the initial order status with a condition depending on if it is paypal or other payment method.

FYI, I'm not keen on the idea of the order confirmation being sent after the Paypal transaction (there was fix for this in another thread). I tried it but if the transaction hits any problem the customer is sent no record at all. With the above, the customer can return to view the order and click on the 'pay by paypal' button within the order details.
Get answers faster:
    [li]
Search forum. You might find answer[/li]
[li]Use existing threads. Keep Q + A consolidated[/li]
[li]Troubleshooting? See http://forum.virtuemart.net/index.php?topic=60033.0[/li]
[li]For admin user manual - http://virtuemart.net/documentation/User_Manual/index.html[/li]
[li]For coding (developer manual) - http://virtuemart.net/documentation/Developer_Manual/index.html[/li][/list]

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