PDA

View Full Version : Paypal_ipn and stock levels



MindTwist
10-03-2007, 01:08 PM
Ok, I am aware that when using the paypal_ipn module, the order gets added to the DB before the customer goes to Paypal web site, but stock level doesn't go down *YET* on the purchased items.

Then payment is done, customer is redirected to checkout_process.php, and stock gets sutracted, emails get sent, etc.

Problem comes when the customer does not return to the store for whatever reason, that the item will be sold but stock won't be sutracted... I hope this won't be a big deal, and that most people will go back to the store after doing the payment.

---

Ok, I went too fast. Checking out paypal_ipn.php I see that stock gets sutracted from there, AND emails also get sent from there, on function confirmation() which I suppose is called from checkout_process.php. I wouldn't even have noticed if it wasn't because I had modified the emails that get sent from checkout_process.php so the subject would be "EMAIL_TEXT_SUBJECT (# order number)" instead of just "EMAIL_TEXT_SUBJECT", and I noticed that my test purchases did not have the order number on the subject.

Wonder why they would be sending the email from there, instead of leting checkout_process.php handle it...?


I would say I am not even asking for anything on this post. What was the answer...? Oh well.

MindTwist
10-04-2007, 12:01 AM
I guess there is a small bug/glitch on paypal_ipn.php , since it is using its own code to email the customer after the purchase is finished, it does not have a small change that "purchase without account" added on checkout_process.php, which makes the email received by the customer NOT have a link to an invoice.

Since the customer has not created an account, he can not access an invoice on the store, but customers who purchase without account AND pay with paypal_ipn will get the link on their email.

So the following code should be done on /includes/modules/payment/paypal_ipn.php on line 523:


// lets start with the email confirmation
$email_order = STORE_NAME . "\n" .
EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" .
EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL', false) . "\n" .
EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
Replace with:


// lets start with the email confirmation
$email_order = STORE_NAME . "\n" .
EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n";
// IF ADDED: PWA - Add test for PWA - no display of invoice URL if PWA customer
if (!tep_session_is_registered('noaccount')) {
$email_order .= EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL', false) . "\n";
}
$email_order .= EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
For code clean up, the following changes could also be made on /checkout_process.php on line 288:


// lets start with the email confirmation
// LINE ADDED: PWA - Add test for PWA - no display of invoice URL if PWA customer
if (!tep_session_is_registered('noaccount')) {
$email_order = STORE_NAME . "\n" .
EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n" .
EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $insert_id, 'SSL', false) . "\n" .
EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
if ($order->info['comments']) {
$email_order .= tep_db_output($order->info['comments']) . "\n\n";
}
$email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
EMAIL_SEPARATOR . "\n" .
$products_ordered .
EMAIL_SEPARATOR . "\n";
} else {
$email_order = STORE_NAME . "\n" .
EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n" .
EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
if ($order->info['comments']) {
$email_order .= tep_db_output($order->info['comments']) . "\n\n";
}
$email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
EMAIL_SEPARATOR . "\n" .
$products_ordered .
EMAIL_SEPARATOR . "\n";
}
Replace with:


// lets start with the email confirmation
$email_order = STORE_NAME . "\n" .
EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n";
// IF ADDED: PWA - Add test for PWA - no display of invoice URL if PWA customer
if (!tep_session_is_registered('noaccount')) {
$email_order .= EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $insert_id, 'SSL', false) . "\n";
}
$email_order .= EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
if ($order->info['comments']) {
$email_order .= tep_db_output($order->info['comments']) . "\n\n";
}
$email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
EMAIL_SEPARATOR . "\n" .
$products_ordered .
EMAIL_SEPARATOR . "\n";
Anyway, if anyone could give me a good reason why on earth when a purchase is paid with paypal_ipn the order email gets sent from paypal_ipn.php instead of from checkout_process.php , I would like to hear.

MindTwist
10-04-2007, 12:12 AM
OPS... Micheal please edit my typo on the issue summary I opened on the bugtracker... payed=paid :shifty:

235: Purchases done by customer without account get an invoice link on order email if payed with paypal_ipn - Bug Tracker - open source Commerce Maximized :: osCMax (http://bugtrack.oscmax.com/view.php?id=235)