Jump to content
Sign in to follow this  
devosc

PayPal_Shopping_Cart_IPN

Recommended Posts

Okay, one last thing - this is what I have in /catalog/ipn.php, does it look right?

 

 

<?php

/*

$Id: ipn.php,v 1.0 2003/12/31 19:41:45 gregbaboolal@yahoo.com Exp $

 

Released under the GNU General Public License

*/

 

if ( strcmp(phpversion(),'4.0.6') <= 0 ) {

$_GET = $HTTP_GET_VARS;

$_POST = $HTTP_POST_VARS;

$_SERVER = $HTTP_SERVER_VARS;

}

 

unset($_GET,$HTTP_GET_VARS,$HTTP_POST_VARS);

 

//Continue the session

$HTTP_POST_VARS['osCsid'] = $_POST['custom'];

//Start up osC

require_once('includes/application_top.php');

 

require_once 'includes/classes/paypal/ipn.php';

$ipn = new paypal_ipn(MODULE_PAYMENT_PAYPAL_IPN_DEBUG_EMAIL,$_POST,tep_session_name(),MODULE_PAYMENT_PAYPAL_IPN_DEBUG);

unset($_POST,$HTTP_POST_VARS);

 

//post back to PayPal system to validate

//For a sample VALID IPN view PayPal's source page prior to returning checkout_success.php

//If the IPN is not valid then don't do anything, set 'paypal_debug' to non-zero if

//you want to investigate these occurances.

if(!$ipn->authenticate('www.paypal.com') && !MODULE_PAYMENT_PAYPAL_IPN_DEBUG_TEST) exit;

 

//Check that the receiver_email is your Primary PayPal email

if (!$ipn->validate_receiver_email(MODULE_PAYMENT_PAYPAL_ID,MODULE_PAYMENT_PAYPAL_BUSINE

SS_ID) && !MODULE_PAYMENT_PAYPAL_IPN_DEBUG_TEST) exit;

 

//Check the payment_status is Completed

if ( $ipn->key['payment_status'] != 'Completed' && !MODULE_PAYMENT_PAYPAL_IPN_DEBUG_TEST) exit;

 

//Check that txn_id has not been previously processed

//This will register/store the IPN transaction if it is not a duplicate

//NOTE: This disable notifications on refunds/reversals(?) with same transaction id's

if (!$ipn->unique_txn_id() && !MODULE_PAYMENT_PAYPAL_IPN_DEBUG_TEST) exit;

 

//Process payment

if ( $ipn->txn_type() == 'web_accept' || $ipn->txn_type() == 'cart') {

//Looks like you're in business!

include_once 'includes/classes/paypal/cart.php';

$ipn_cart = new paypal_ipn_cart();

//check that payment_amount/payment_currency are correct

if ($ipn_cart->valid_payment($ipn,$cart,$currency) ) { //needs work

$description = "This payment was sent by customer {$ipn->key['first_name']} {$ipn->key['last_name']} via the osCommerce / PayPal Shopping Cart";

if (MODULE_PAYMENT_PAYPAL_IPN_DEBUG) $ipn->send_email('cart',"You have received a payment of ".number_format($ipn->key['mc_gross'],2)." ".$ipn->key['mc_currency']."\r\n\r\n$description\r\n\r\n");

unset($description);

$ipn->insert_ipn_txn();

$ipn_cart->process_transaction($order,$language,$ipn->get_paypal_ipn_id());

} else {

if (MODULE_PAYMENT_PAYPAL_IPN_DEBUG) $ipn->send_email('cart',"COULD NOT PROCESS: You have received a payment of ".number_format($ipn->key['mc_gross'],2)." ".$ipn->key['mc_currency']."\r\n\r\n");

}

} else if ($ipn->txn_type() == 'send_money') {

//Just to keep you informed

$description = "This payment was sent by someone from the PayPal website, using the Send Money tab";

if (MODULE_PAYMENT_PAYPAL_IPN_DEBUG) $ipn->send_email('send_money',"You have received a payment of ".number_format($ipn->key['mc_gross'],2)." ".$ipn->key['mc_currency']."\r\n\r\n$description\r\n\r\n");

unset($description);

} else if ($ipn->txn_type() == 'reversal') {

//Easier to let you decide what to do about a refund!

$description = "This means the transaction was reversed. If payment_status is Completed, ".

"then a reversal to a transaction has occurred, and money has been transferred from your ".

"account back to the customer. If it is Canceled, then a previous reversal has been reversed, ".

"and the money has been returned to your account.";

if (MODULE_PAYMENT_PAYPAL_IPN_DEBUG) $ipn->send_email('reversal',"A payment of ".number_format($ipn->key['mc_gross'],2)." ".$ipn->key['mc_currency']." has been reversed.\r\n\r\n$description\r\n\r\n");

unset($description);

} else {

if (MODULE_PAYMENT_PAYPAL_IPN_DEBUG) $ipn->send_email("unkown","A transaction may have occured please check your PayPal Account\r\n");

}

if (MODULE_PAYMENT_PAYPAL_IPN_DEBUG_TEST) {

echo $ipn->debug_info();

}

?>

Share this post


Link to post
Share on other sites

Hi, greg, regrad to my previous problem, it's done, it's just the directory had to be changed in order to get it work....(duh...I don' t know why... ;) :( ...one of those weird things happen and you just don't know why.... :lol: )

 

 

anyhow...now i am trying to check everything if it's working properly or not!!!

 

Thank you again :D


OS-commerce is great, but with other magical contributions, that is just so "COOL"!

Share this post


Link to post
Share on other sites

Hi C,

 

That ipn.php file looks original :P

 

Ok as a test, back up the original catalog/ipn.php file. Now copy and paste the code below and save it as /catalog/ipn.php (i.e to replace it).

Now go to that file in your browser:

http://crazearcade.com/catalog/ipn.php

 

You will now see some stuff on the screen.

You should also get 2 'TEST' emails saying 'TEST'.

 

Make sure the email address in the code below is correct.

 

Let me know whats happeing, i.e emails etc, maybe leave the file on your server, and I'll go and have a look.

 

<?php
if ( strcmp(phpversion(),'4.0.6') <= 0 ) {
$_GET = $HTTP_GET_VARS;
$_POST = $HTTP_POST_VARS;
$_SERVER = $HTTP_SERVER_VARS;
}

unset($_GET,$HTTP_GET_VARS,$HTTP_POST_VARS);

//Continue the session
$HTTP_POST_VARS['osCsid'] = $_POST['custom'];
//Start up osC
require_once('includes/application_top.php');

require_once 'includes/classes/paypal/ipn.php';
$ipn = new paypal_ipn('sales@crazearcade.com',$_POST,tep_session_name(),2);

$ipn->send_email('TEST','TESTING EMAIL');
mail("sales@crazearcade.com", "PHP TEST", "TESTING\r\n");
echo $ipn->debug_info();
phpinfo();
?>


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

Share this post


Link to post
Share on other sites

edit again....never mind sorry....

Edited by markchiu

OS-commerce is great, but with other magical contributions, that is just so "COOL"!

Share this post


Link to post
Share on other sites

:P ....sorry to post two non-sense post.....but embarrased to ask this...how do i make a test or any necessary checkings to make sure this contribution works on my site??? :lol:

 

 

thank you ....i just have lack of knowledge on how ipn works..... :(


OS-commerce is great, but with other magical contributions, that is just so "COOL"!

Share this post


Link to post
Share on other sites

Mark,

 

You could just set it to

http://host86.ipowerweb.com/~yadyshop/catalog/ipn.php

 

But I just checked it out and it seems that you have a redirect going on which is screwing up everything. Make things simple. Use your domain name. You only need SSL for customer login and purchase. I suspect now this why you might be having trouble with some of the other modules.

 

Basically when you go to

http://host86.ipowerweb.com/~yadyshop/catalog/ipn.php

it should just load a blank page, but there something going on, i think, in application_top, that is causing a redirect, hence PayPal will never successfully be able to send an IPN.


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

Share this post


Link to post
Share on other sites

Hi C,

 

In that code:

mail("sales@crazearcade.com", "PHP TEST", "TESTING\r\n");

Is the in built PHP mail function, out of interest do you get any emails when an order is placed at your store?


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

Share this post


Link to post
Share on other sites

C,

 

If you want to receive emails when an order occurs put your email address in the send extra emails field in osC admin/My Store.

 

If the above mail function doesn't work for you not sure what to suggest, maybe it is your PHP config settings. I suppose we could try and use the osC tep_mail function, I didn't need it at the time but it might solve your problem. But this would still leave the real issue of your not receiving PayPal's IPNs. Dunno at the moment, would have to think and/or test your system.


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

Share this post


Link to post
Share on other sites

Greg,

 

Thanks, the mod worked fine, and now IPN's are appearing in OSC. Only problem now is when I click on complete in Paypal to return to the shop I get the following:

 

Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site14/fst/var/www/html/catalog/includes/classes/paypal/ipn.php:235) in /home/virtual/site14/fst/var/www/html/catalog/includes/functions/general.php on line 29

 

Thanks

 

Duncan

Share this post


Link to post
Share on other sites
C,

 

If you want to receive emails when an order occurs put your email address in the send extra emails field in osC admin/My Store.

 

If the above mail function doesn't work for you not sure what to suggest, maybe it is your PHP config settings. I suppose we could try and use the osC tep_mail function, I didn't need it at the time but it might solve your problem. But this would still leave the real issue of your not receiving PayPal's IPNs. Dunno at the moment, would have to think and/or test your system.

I put my email address in that field, still no go...

 

Is there anyway I could put a note on the paypal page, just telling people to hit continue or their order won't be processed...

 

I really need to fix this -_-

 

Thanks for all your help....

Share this post


Link to post
Share on other sites

Hi Duncan,

 

Sounds like you may have v1.4, which had a spurious print statement when recalling paypal_ipn_id.

 

I would suggest that you upgrade to v1.5. You should be able to get away with just copying over the paypal related files (i.e not the language,filenames,database_tables files) - I would do this also in the osC admin side too.

 

v1.5 is a slightly improved version but of the same functionality as v1.4, alternatively you could suggest remove that line:

print "{$this->_paypal_ipn_id}<br>";

in function get_id().

 

I am presuming this to be the problem if not open /catalog/includes/classes/paypal/ipn.php and let me know whats occuring at line 235.


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

Share this post


Link to post
Share on other sites

Hi, greg, I have changed my whole directory..so basically i don't need to set up a redirect......please check it for me..if you still feel i have a redirect.......

 

anyhow...after i have done the moving file......also i go to the url that you said

 

 

http://www.yadyshop.com/ipn.php.....

 

 

yes..it loads up the blank page...but it keeps reloading....don't know why...yet, i have taken out all the redirect pages..... :( ;) ...can you help me??


OS-commerce is great, but with other magical contributions, that is just so "COOL"!

Share this post


Link to post
Share on other sites

Mark,

 

When loading that page in the url, it seems to keep reloading and trying to insert/append a new osC session id. I thought it was a redirect but when I looked at the url after 3 or 4 reloads, there were about 4 different osC session ids, check it and see. I don't really know why that is occuring, maybe a osC admin config setting or module contribution?


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

Share this post


Link to post
Share on other sites
Hi All,

 

When ready, you might like to try and further secure the /catalog/ipn.php file by restricting it's access to paypal only, this can be acheived by:

<Files ipn.php>
Order deny,allow
Deny from all
Allow from notify.paypal.com
</Files>

I quickly tested it and it did seem to work ok, the above would need to be put in your /catalog/.htaccess file.

 

Note if you're running any tests then you will need to coment out the above.

 

I suppose one could just as easily use the Apache Limit directive but I don't have time to test all possibilities.

 

Give a shout if the above is not allowing your IPNs to be registered, it should. In either case, as in the readme.txt file, you could allows rename catalog/ipn.php to something obscure and possibly not have to worry about the above suggestion, but remember to update your PayPal profile if you do.

 

you should then see an Acees Forbidden Msg when you type in that /catalog/ipn.php in your browser etc.

If your site has SSL you can also set your PayPal IPN profile to use https://www.yourdomain.com/catalog/ipn.php


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

Share this post


Link to post
Share on other sites

Hi, greg, the following is my admin configure.php file.....I have no idea, don't know where it goes wrong..i can't find it myself......

 

my site root is like all the files are right under public_html...so there is no

 

/public_html/catalog/all the files----This one is wrong

/public_html/all the files---this one is correct

 

 

<?php

/*

? osCommerce, Open Source E-Commerce Solutions

? http://www.oscommerce.com

 

? Copyright ? 2003 osCommerce

 

? Released under the GNU General Public License

*/

 

// Define the webserver and path parameters

// * DIR_FS_* = Filesystem directories (local/physical)

// * DIR_WS_* = Webserver directories (virtual/URL)

? define('HTTP_SERVER', 'http://www.yadyshop.com'); // eg, http://localhost - should not be empty for productive servers

define('HTTP_CATALOG_SERVER', 'http://www.yadyshop.com');

define('HTTPS_CATALOG_SERVER', 'https://host86.ipowerweb.com/~yadyshop');

define('ENABLE_SSL_CATALOG', 'true'); // secure webserver for catalog module

define('DIR_FS_DOCUMENT_ROOT', '/home/yadyshop/public_html'); // where the pages are located on the server

define('DIR_WS_ADMIN', '/admin/'); // absolute path required

define('DIR_FS_ADMIN', DIR_FS_DOCUMENT_ROOT . DIR_WS_ADMIN);

define('DIR_WS_CATALOG', '/'); // absolute path required

define('DIR_FS_CATALOG', DIR_FS_DOCUMENT_ROOT . DIR_WS_CATALOG);

define('DIR_WS_IMAGES', 'images/');

define('DIR_WS_ICONS', DIR_WS_IMAGES . 'icons/');

define('DIR_WS_CATALOG_IMAGES', DIR_WS_CATALOG . 'images/');

define('DIR_WS_INCLUDES', 'includes/');

define('DIR_WS_BOXES', DIR_WS_INCLUDES . 'boxes/');

define('DIR_WS_FUNCTIONS', DIR_WS_INCLUDES . 'functions/');

define('DIR_WS_CLASSES', DIR_WS_INCLUDES . 'classes/');

define('DIR_WS_MODULES', DIR_WS_INCLUDES . 'modules/');

define('DIR_WS_LANGUAGES', DIR_WS_INCLUDES . 'languages/');

define('DIR_WS_CATALOG_LANGUAGES', DIR_WS_CATALOG . 'includes/languages/');

define('DIR_FS_CATALOG_LANGUAGES', DIR_FS_CATALOG . 'includes/languages/');

define('DIR_FS_CATALOG_IMAGES', DIR_FS_CATALOG . 'images/');

define('DIR_FS_CATALOG_MODULES', DIR_FS_CATALOG . 'includes/modules/');

define('DIR_FS_BACKUP', DIR_FS_ADMIN . 'backups/');

 

 

 

// define our database connection

? define('DB_SERVER', 'localhost'); // eg, localhost - should not be empty for productive servers

? define('DB_SERVER_USERNAME', '');

? define('DB_SERVER_PASSWORD', '');

? define('DB_DATABASE', '');

? define('USE_PCONNECT', ''); // use persisstent connections?

? define('STORE_SESSIONS', ''); // leave empty '' for default handler or set to 'mysql'

?>

 

The setting like this so far doesn't cost any problem...no i am not saying anything else.....but just say that I don't know which setting caused the forever looping stuff.........yet..I checked again..I found I have 6 sids....... :( :o :unsure: :blink:

 

 

edited:forgot to ask this, but would it cause a major effect on my paypal ipn??? What should i do if i can't fix??? :(

Edited by markchiu

OS-commerce is great, but with other magical contributions, that is just so "COOL"!

Share this post


Link to post
Share on other sites

Mark,

 

Firstly which configure file do you think is used by 'catalog/ipn.php', i.e in which directroy is it located?

 

The problem is occuring, possibly to something in your catalog/includes/application_top.php file, but this might only be because of another contribution installed. But then again, why is this problem only occuring with ipn.php and not 'index.php', something is peculiar here.

 

Look in the readme file and find my email address. Email me your catalog/includes/configure.php file and catalog/includes/application_top.php file. Please don't post here.

 

I can not promise because I'm busy on other stuff, but I will quickly have a look, but the problem might not even be there, but we can try.

 

Greg.


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

Share this post


Link to post
Share on other sites

Greg, could you please post step by step on how to make a paypal ipn test???

 

 

About the help, i am really appreciated!!

Edited by markchiu

OS-commerce is great, but with other magical contributions, that is just so "COOL"!

Share this post


Link to post
Share on other sites

:) you seemed to have followed the email correctly.

 

Look back in the thread I have explained step by step what to do.

 

Why don't you make a 'real' trial purchase first. Create a $0.01 product and buy it, before hitting the continue button in PayPal, go to osC admin and look for the order/IPN. Put something in the memo fields so that you can identify it.

 

Give it go. If you want to try the test go ahead but you have to explain which bit of my previous instructions you don't understand. I guarantee if you start step by step you'll figure it out.

 

I just went to your site, check your email, you should have one saying saying unkown something or another - transaction?


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

Share this post


Link to post
Share on other sites

yes....but why do i receive those (6 in total)?????!!! WHAT HAPPENED?!!!!! :(


OS-commerce is great, but with other magical contributions, that is just so "COOL"!

Share this post


Link to post
Share on other sites

:rolleyes: Well it's better than getting none at all!

 

Ok you seem ok, you can set the email notification to 1.

 

BUT DO WHAT I SAID IN THE EMAIL FIRST :P . before you get too :)

 

It also wouldn't hurt to have read those emails, they are sent to help you!


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

Share this post


Link to post
Share on other sites

Hello

 

I have installed several ver. 1.5 and I have two problems:

 

1. In the Admin/Modules/Payment/Paypal menu on the left there's no radio button to set picture off - instead there's an empty text field. Please find a part of my menu below:

mneu.jpg

 

2. This problem has been described earlier but the explanation has become a mess of answers and new questions. Is it possible to give a short consistent answer? I got two mails from paypal with this message for each payment:

 

An HTTP Error occurred during authentication curl= socket=tcp:// domain=www.paypal.com port=80

 

Thanks in advance and thanks for the improvements this contribution gives (when I got it to work...)

 

Cornelius


dog1.jpg Who let the dog out ?!!! Newer trust a smiling dog!

Share this post


Link to post
Share on other sites

[1] How did you install the /catalog/includes/modules/payment/paypal.php module? Did you copy the file from the contribution files, or have you tried to cut and paste individual lines of code? Unistall/remove the PayPal module in osC admin. Copy over the file correctly. Now install the PayPal module.

 

[2]

Others have had this problem too;

Replace the existing authenticate($domain) function in /catalog/includes/classes/paypal/ipn.php with the following code:

  function get_paypal_response() {
   $paypal_response = file('http://www.paypal.com/cgi-bin/webscr?'.$this->_response_string);
   return $paypal_response[0];
 }

 function authenticate($domain) {
   $paypal_response = $this->get_paypal_response();
   if (strstr($paypal_response,'VERIFIED')) {
     if($this->_debug >1 ) $this->send_email('VERIFIED',"Connection Type\r\ncurl=$curl_flag socket=$socket domain=$domain port=$port\r\n#####################\r\n".$paypal_response."\r\n\r\n");
     return true;
   } else if (strstr($paypal_response,'INVALID')) {
     // log for manual investigation
     if($this->_debug > 1) $this->send_email('INVALID',"Connection Type\r\ncurl=$curl_flag socket=$socket domain=$domain port=$port\r\n#####################\r\n".$paypal_response."\r\n\r\n");
     return false;
   } else {
     if($this->_debug) $this->send_email('unkown verification occurrence',"Connection Type\r\ncurl=$curl_flag socket=$socket domain=$domain port=$port\r\n#####################\r\n".$paypal_response."\r\n\r\n");
     return false;
   }
 }

Hopefully this will get you on track.

Greg.

Greg.


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

Share this post


Link to post
Share on other sites

Hello Greg

 

My problems with the menu is solved - thanks. I must have forgot to uninstall between the installation of two versions.

 

Question no. 2:

 

I'm very new to this. Could you please explain like this:

 

find XXXXXXX

 

replace with this: your code

 

I want to be sure I do it right the first time

 

Thanks.


dog1.jpg Who let the dog out ?!!! Newer trust a smiling dog!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×