Jump to content
Sign in to follow this  
devosc

[Contribution]Paypal IPN - Devosc

Recommended Posts

Hi Patrick,

 

The changes and their locations etc are detailed clearly in the install docs, I suspect the problem is that shortcuts have been taken and also provided, the latter not as clearly as the actual install docs and a couple of ommissions in regard to upgrading.

 

The edits you mention below replace existing code and are not isolated additions, so their location do matter, see the install docs, the changes have been highlighted.

 

Those changes are in regard to the account_history_info and invoice synchronization which may or may not be used, depending on your preference, but if you do then you have to accomodate for this if the orders table is ever reset, e.g. increment the auto index to be greater than the previous order_id's.

 

Another possibilty is to restore the entire osC shopping cart with the order, but this is a bit more involved to implement.

 

I'll look out for your change list, thanks it will help.


"Any fool can know. The point is to understand." -- Albert Einstein

Share this post


Link to post
Share on other sites

riiiiiiiiiiiiiggggggggggggggggggggggggggghhhhhhhhhhhttttttttttt

 

I guess that means : YES you have to put that piece of code back in

 

[i am dutch so your technical english explanation kind of swirls in front of my eyes]

 

If i am correct then this should be the complete good guide i made then.

 

WIll you put it in your final update, then i won't have to upload it, since it is your contribution in the firts place of course.

 

 

----------------------------------------------------------------------------------------------

 

 

Update steps when updating from the 2.4 version:

 

 

application top already had: *** [REMOVE THIS]

 

// begin PayPal_Shopping_Cart_IPN

require_once DIR_WS_MODULES . 'payment/paypal/functions.php';

paypal_check_order_status();

// end PayPal_Shopping_Cart_IPN

 

 

now new in that page: [PUT INSTEAD OF ABOVE CODE]

// begin PayPal_Shopping_Cart_IPN

paypal_order::check_order_status(true);

// end PayPal_Shopping_Cart_IPN

 

 

 

in classes/order.php

 

already had: *** [and needs to stay there too!]

 

// begin PayPal_Shopping_Cart_IPN

$order_total_query = tep_db_query("select text, value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (

 

int)$order_id . "' and class = 'ot_total'");

// end PayPal_Shopping_Cart_IPN

 

 

 

now new in that page: [PUT BELOW ABOVE CODE]

//begin PayPal_Shopping_Cart_IPN

$shipping_method_query = tep_db_query("select title, value from " . TABLE_ORDERS_TOTAL . " where orders_id = '"

 

. (int)$order_id . "' and class = 'ot_shipping'");

//end PayPal_Shopping_Cart_IPN

 

 

in admin orders.php

 

already had: *** [REMOVE THIS]

 

//begin PayPal_Shopping_Cart_IPN

if (strtolower($oInfo->payment_method) == 'paypal') {

require_once(DIR_FS_CATALOG_MODULES . 'payment/paypal/database_tables.php');

$paypal_payment_status_query = tep_db_query("select p.payment_status from " . TABLE_PAYPAL . " p left join " .

 

TABLE_ORDERS . " o on p.paypal_ipn_id = o.paypal_ipn_id where o.orders_id ='" . $oInfo->orders_id . "'");

$paypal_payment_status = tep_db_fetch_array($paypal_payment_status_query);

//quick work around for unkown order status id

$paypal_payment_status_value = (tep_not_null($paypal_payment_status['payment_status'])) ? $paypal_payment_status[

 

'payment_status'] : $oInfo->orders_status_name ;

$contents[] = array('text' => 'Payment Status:' . ' ' . $paypal_payment_status_value );

}

//end PayPal_shopping_Cart_IPN

 

 

 

now new in that page: [PUT INSTEAD OF ABOVE CODE]

 

//begin PayPal_Shopping_Cart_IPN

if (strtolower($oInfo->payment_method) == 'paypal') {

include_once(DIR_FS_CATALOG_MODULES . 'payment/paypal/database_tables.inc.php');

$paypal_payment_status_query = tep_db_query("select p.payment_status from " . TABLE_PAYPAL . " p left join " .

 

TABLE_ORDERS . " o on p.paypal_ipn_id = o.paypal_ipn_id where o.orders_id ='" . $oInfo->orders_id . "'");

$paypal_payment_status = tep_db_fetch_array($paypal_payment_status_query);

//quick work around for unkown order status id

$paypal_payment_status_value = (tep_not_null($paypal_payment_status['payment_status'])) ? $paypal_payment_status[

 

'payment_status'] : $oInfo->orders_status_name ;

$contents[] = array('text' => TABLE_HEADING_PAYMENT_STATUS . ': ' . $paypal_payment_status_value );

}

//end PayPal_shopping_Cart_IPN

 

 

 

 

in admin/includes/functions/general.php

 

already had: *** [REMOVE THIS]

 

//begin PayPal_Shopping_Cart_IPN

$ipn_query = tep_db_query("select paypal_ipn_id from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'

 

");

if (tep_db_num_rows($ipn_query)) { // this is a paypal ipn order

$ipn_order = tep_db_fetch_array($ipn_query);

$paypal_ipn_id = $ipn_order['paypal_ipn_id'];

tep_db_query("delete from " . TABLE_PAYPAL . " where paypal_ipn_id = '" . (int)$paypal_ipn_id . "'");

tep_db_query("delete from " . TABLE_PAYPAL_PAYMENT_STATUS_HISTORY . " where paypal_ipn_id = '" . (int)$paypal_ipn_id

 

. "'");

}

//end PayPal_Shopping_Cart_IPN

 

 

now new in that page: [PUT INSTEAD OF ABOVE CODE]

 

//begin PayPal_Shopping_Cart_IPN

$ipn_query = tep_db_query("select paypal_ipn_id from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'

 

");

if (tep_db_num_rows($ipn_query)) { // this is a paypal ipn order

include_once(DIR_FS_CATALOG_MODULES . 'payment/paypal/database_tables.inc.php');

$ipn_order = tep_db_fetch_array($ipn_query);

$paypal_ipn_id = $ipn_order['paypal_ipn_id'];

tep_db_query("delete from " . TABLE_PAYPAL . " where paypal_ipn_id = '" . (int)$paypal_ipn_id . "'");

tep_db_query("delete from " . TABLE_PAYPAL_PAYMENT_STATUS_HISTORY . " where paypal_ipn_id = '" . (int)$paypal_ipn_id

 

. "'");

}

//end PayPal_Shopping_Cart_IPN

 

 

 

 

 

 

in

admin/orders.php

 

was in 2.4 & 2.5

include DIR_FS_CATALOG_MODULES . 'payment/paypal/admin_orders.inc.php';

 

 

changed to :

include(DIR_FS_CATALOG_MODULES . 'payment/paypal/admin/orders.inc.php');

 

 

 

Also change in:

admin/includes/languages/english/orders.php

 

add:

define('TABLE_HEADING_PAYMENT_STATUS','Payment Status');

 

 

-------------------------------------------------------------------------------------------

 

There the all done :)

Edited by PVK

Share this post


Link to post
Share on other sites

Hi Patrick, thanks. I will bookmark your post.

 

:D v2.6 has just been uploaded, by copying over the existing contrib files will bring you up to date.

 

Regards,

Greg.


"Any fool can know. The point is to understand." -- Albert Einstein

Share this post


Link to post
Share on other sites

Gee I take a few hours to think and viola a new version :D (Havent read the posts since late afternoon yeasterday)

 

I will load it but so far 2.5 seemed to have worked without any problems. Anyway Greg I was thinking more about our discussion and will have some more to say after I work out a few things. But on the topic I no longer will delete an order imideiately on failure.. since there is no need to now with the ability to pay for "abandoned" orders in the account section. I will however work out a way to leave the shoping cart available if an order fails so that the customer can remove items from it to lower the total amount then try paying again, or for that matter add to it if they chose to.

Share this post


Link to post
Share on other sites

Haven't had time to think it all through but an suggestion might be to change in catalog/ipn.php:

      tep_db_query("update " . TABLE_ORDERS . " set paypal_ipn_id = '" . (int)$ipn->id() . "' where orders_id = '" . (int)$orders_id . "'");
     tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$order->customer['id'] . "'");
     tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$order->customer['id'] . "'");
     if ($ipn->key['payment_status'] == 'Completed' && $ipn->valid_payment() ) {
       include(DIR_WS_MODULES . 'payment/paypal/catalog/checkout_update.inc.php');
     }

To:

      tep_db_query("update " . TABLE_ORDERS . " set paypal_ipn_id = '" . (int)$ipn->id() . "' where orders_id = '" . (int)$orders_id . "'");
     if (($ipn->key['payment_status'] == 'Completed' || $ipn->key['payment_status'] == 'Pending' ) && $ipn->valid_payment() ) {
       tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$order->customer['id'] . "'");
       tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$order->customer['id'] . "'");
       if ($ipn->key['payment_status'] == 'Completed') {
         include(DIR_WS_MODULES . 'payment/paypal/catalog/checkout_update.inc.php');
       }
     }

 

And then in paypal/classes/paypal_order.class.php

Change:

      $orders_session_query = tep_db_query("select paypal_ipn_id from " . TABLE_ORDERS . " where orders_id ='" . (int)$paypal_order->orders_id . "'");
     $orders_session_check = tep_db_fetch_array($orders_session_query);
     if ($orders_session_check['paypal_ipn_id'] > 0 ) {

To:

      $orders_session_query = tep_db_query("select o.paypal_ipn_id, pp.payment_status  from " . TABLE_ORDERS . " o left join " . TABLE_PAYPAL . " pp on pp.paypal_ipn_id = o.paypal_ipn_id where o.orders_id ='" . (int)$paypal_order->orders_id . "'");
     $orders_session_check = tep_db_fetch_array($orders_session_query);
     $payment_status = $orders_session_check['payment_status'];
     if ($orders_session_check['paypal_ipn_id'] > 0 && ( $payment_status == 'Completed' || $payment_status == 'Pending' ) ) {

 

This will delete the products (and reset the cart in the latter) only when the payment is either completed or pending and when it is a valid payment.

 

The ipn will still be stored even if not completed or pending or a valid payment, the latter possibly needs more thought but the order will only be updated when the payment is Completed, eg. customer notified and stock levels updated.

 

This way, maybe confusingly, the customer could amend the shopping cart and or resume the payment via their account_history_info, but the latter would not be editable like the actual cart.


"Any fool can know. The point is to understand." -- Albert Einstein

Share this post


Link to post
Share on other sites
Hello,

I have upgraded to 2.5a but I have problem after the checkout page.

It show this:

Fatal error: Call to a member function on a non-object in /home/imoasis/public_html/catalog/includes/sts_display_output.php on line 243

 

I am using STS and it seems that this problem is about the latest change

in the checkout_success.php

 

I have noticed that 2.5a use this phase:

paypal_order::reset_checkout_cart_session();

 

while 2.4 use this phase:

paypal_reset_checkout_cart_session();

 

So can anyone help me to solve this problem?

 

Mark

I have found this few sentences in checkout_splash.inc.php :

 

<?php

//since this script file is called via the main osC checkout_process.php

//the main osCommerce catalog/includes/application_top.php script has already been included

//so for compatibility for those using STS etc we'll include the original osC application_bottom.php

require(DIR_WS_INCLUDES . 'application_bottom.php');

?>

 

So maybe the problem is due to this?

But I still don't understand how to make it compatible with STS.

Hope someone can help with this.

 

Many thanks

Mark:

 

Im not certain, since I dont use the STS (I use BTS instead) but you may need to check to see if paypal_order is realy registered in the session as it should be in checkout_process.inc.php, otherwise you might try globaling it on the top of your checkout_sucess page but even that may not work since checkou_success is redirected to from paypal, which is why paypal_order was registered in the session in the first place, to make it available on return from paypal. Anyway hope this helps you a bit.

 

 

 

 

Greg Ill see what I can bodge together based on your hints, and thanks again.

Share this post


Link to post
Share on other sites

Ok I just upgraded to 2.6 and my orders.php is fixed now but I still have problems with the contribution. First, when I try to set the domain to sandbox.paypal.com the server can't be found when I try to test. And so when I use the internal test everything goes through but the order status still stays at "Pending PayPal Notification" even though it said "payment status: complete" Also when I get the debug message after the test, it says that the paypal total is different when it is exactly the same as the order total.

 

 

 

------------------------------------------------------

Validate Total Transaction Amount

------------------------------------------------------

Incorrect Total

PayPal: $49.00

Session: $49.00

 

 

Thanks,

Eric

Share this post


Link to post
Share on other sites

Hi Greg

 

is there anything new between 2.6 and 2.5a with the changes communicated in this forum? do I need to do all new?

 

Best

Kai

Share this post


Link to post
Share on other sites

Ok I just installed 2.6 I installed 2.3 but never tested it (not production yet) so I just deleted the Paypal Module Files from 2.3 and Uploaded the 2.6

 

then I went and Redid the install, Line by line, like I was doing it Fresh..

 

First thing, Nothing shows up in the "paypal IPN" table after going to paypal (before payment in processed) -- is there suppose to be?

 

Next, when using the Test Page. I click test and a Blank Page Appears. (first time I had the Tid wrong and it gave me a Invaid test and sent me an email) but when I enter the correct info, nothing...

 

Finally, I set up a $1 (the standard test I do with all Payment modules) and sent myself a $1 payment, Paypal processed it fine, I clicked continue (auto returned is not enabled on my account right now) and got the osc Sucess page, but again Nothing....

 

what did I miss? is there a Function from 2.3 that I did not remove that could cuase this problem.... I have looked at every file 3-4 times now, I am not getting any errors, but the sessions are not being cleared either as I can Log in after payment is processed and the cart is still full....

Share this post


Link to post
Share on other sites
is there anything new between 2.6 and 2.5a with the changes communicated in this forum? do I need to do all new?

Kai,

 

I you have covered all the changes Greg and others discussed sounds like you dont need to go to 2.6 but if you have not best to just copy in the contrib files from the misc directory of the 2.6 contrib. I myself had no problems with 2.5a but copied in the 2.6 files just to be on the safeside, and it only takes a few moment unless you make changes to Gregs contrib files.

Share this post


Link to post
Share on other sites

Mike,

 

Information will only go to the paypal table after you hit the submit button on the test page. The fact that nothing is in there also has to do with the shopping cart not being cleared. Sounds to me like what would happen if paypal ipn payment failed. Check your settings in the paypal module setup under admin/modules/payment/paypal, make sure that your email addresses in there match what you gave paypal when you signed up, I had mine wrong after reinstalling it yesterday and had failures when testing.

Share this post


Link to post
Share on other sites

Mike,

It sounds as if you are not receiving back the ipn information from paypal. Time to check some settings for your paypal acount.

 

Under profile/website payment preferences on your paypal account make sure that minimaly

 

Auto Return is ON

 

and

 

Payment Data Transfer is ON

 

If they are not set the ipn will not return information to you.

Share this post


Link to post
Share on other sites
Mike,

It sounds as if you are not receiving back the ipn information from paypal. Time to check some settings for your paypal acount.

 

Under profile/website payment preferences on your paypal account make sure that minimaly

 

Auto Return is ON

 

and

 

Payment Data Transfer is ON

 

If they are not set the ipn will not return information to you.

that does not explain why the Interal Test Page Fails to work also

 

all I get is a Blank Page, Unless I purposely induce an error, and then I get as "error" message.....

Share this post


Link to post
Share on other sites

Greg,

 

Thanks for the catalog edits in the misc folder.

 

I have a couple of things to work out with the STS but I was playing with a fresh install.

 

On a clean july 2003 install I get to the paypal processing screen if there are no attributes selected, If I select an attribute or a default one or anything with an attribulte I get the following error.

 

1054 - Unknown column 'products_options_id' in 'field list'

 

insert into orders_products_attributes (orders_id, orders_products_id, products_options_id, products_options, products_options_values_id, products_options_values, options_values_price, price_prefix) values ('4', '4', '3', 'Model', '8', 'PS/2', '0.0000', '+')

 

[TEP STOP]


I'm not a coder just a splicer.

Share this post


Link to post
Share on other sites

If I can recall ' Payment Data Transfer is ON' doesn't need to be set this is a different service not related to IPN.

 

Try in near the top of catalog/includes/modules/payment/paypal/application_top.inc.php, uncommenting the error_reporting line and comment out the error_reporting(0) line below that one. This should then allow you to see if any errors are internally occuring.

 

RI Downlink, see step one of the install docs, there are three 'alterations' that need to be performed via phpMyAdmin.


"Any fool can know. The point is to understand." -- Albert Einstein

Share this post


Link to post
Share on other sites
If I can recall ' Payment Data Transfer is ON' doesn't need to be set this is a different service not related to IPN.

 

Try in near the top of catalog/includes/modules/payment/paypal/application_top.inc.php, uncommenting the error_reporting line and comment out the error_reporting(0) line below that one. This should then allow you to see if any errors are internally occuring.

 

RI Downlink, see step one of the install docs, there are three 'alterations' that need to be performed via phpMyAdmin.

where is the error reporting done?

 

Also, I was assume the "Transaction id" was referring to the oSC order id, but I just noticed there is a "Trans IS" filed in the paypal Area just above the Trans Sig field

 

But there is nothing in it,

Share this post


Link to post
Share on other sites

The error_reporting is a php thing which displays the errors in your browser.

 

From the IPN Test Panel Instructions the Custom field must now be completed with the txn_signature. The transation ID will be completed once the IPN has been received, the trxn_signature will then dissappear.


"Any fool can know. The point is to understand." -- Albert Einstein

Share this post


Link to post
Share on other sites
The error_reporting is a php thing which displays the errors in your browser.

 

From the IPN Test Panel Instructions the Custom field must now be completed with the txn_signature. The transation ID will be completed once the IPN has been received, the trxn_signature will then dissappear.

lol, I know what error reporting IS,

 

I wanted to know where it is outputed, i.e the cart, the Test script, or both

 

I may not be a php master, but I am not a newbie either

 

normally I dont have these problem, or if I do I can figure them out my self, this is the first time I ever had to post a question,

 

This As me baffed mainly because I am not getting any errors, so I dont even know where to start

Share this post


Link to post
Share on other sites

Not sure? There is not output buffering or anything happening to the error reporting so it is as standard, When you click the 'Test IPN' button you either now receive a proper result (osCommerce logo) or plain screen with any error messages.

 

Have you performed the three mysql alterations from step one of the docs?


"Any fool can know. The point is to understand." -- Albert Einstein

Share this post


Link to post
Share on other sites
Not sure? There is not output buffering or anything happening to the error reporting so it is as standard, When you click the 'Test IPN' button you either now receive a proper result (osCommerce logo) or plain screen with any error messages.

 

Have you performed the three mysql alterations from step one of the docs?

yes all the alterations have been made

 

if you want I can pm you with the url to my development site and you can see the "nothing" i see in the test

 

 

I am stumped......

 

the Test screen outputs just (ipn.php)

 

 

<html><body></body></html>  

that is....

 

I dont know where to look now

 

thank for you help btw

Edited by The_ancient

Share this post


Link to post
Share on other sites

well son of a bitch, on a whim I did a test in IE and it worked Fine....

 

What is in Firefox that would cause it not to work? uniless is a cache problem but I dont think so.. I will check though

Share this post


Link to post
Share on other sites

well i just ran a "fake" order in IE and it still does not update it after you go through paypal

 

so I then manually set the IPN url in paypal to the ipn.php page and nothing change...

 

it has to be something I am doing, since no one else has this problem, but I dont have a clue what it could be

Share this post


Link to post
Share on other sites
Ok I just upgraded to 2.6 and my orders.php is fixed now but I still have problems with the contribution. First, when I try to set the domain to sandbox.paypal.com the server can't be found when I try to test. And so when I use the internal test everything goes through but the order status still stays at "Pending PayPal Notification" even though it said "payment status: complete" Also when I get the debug message after the test, it says that the paypal total is different when it is exactly the same as the order total.

 

 

 

------------------------------------------------------

Validate Total Transaction Amount

------------------------------------------------------

Incorrect Total

PayPal: $49.00

Session: $49.00

 

 

Thanks,

Eric

Ok I got this fixed. But is there an alternative to sandbox.paypal.com because it still doesnt work.

 

 

Eric

Share this post


Link to post
Share on other sites

Ok. I finally got the sandbox thing to work. the correct URL is www.sandbox.paypal.com and not sandbox.paypal.com I ran an order through and paid for it through the sandbox but I am getting an error when I get back to my site. The file is /checkout_success.php?action=success and the error is:

 

Fatal error: Call to undefined function: paypal_reset_checkout_cart_session() in /var/www/html/checkout_success.php on line 32

 

How can i fix this? Is anyone else having the same problem?

 

 

Thanks,

Eric

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×