Jump to content
Mark Evans

Official PayPal IPN Support Thread

Recommended Posts

that could be the problem, regarding redirecting. if you can access your ipn.php by the url www.mymainsite.com/STORENAME/ext/modules/payment/paypal_ipn/ipn.php then try to hard code this with the parameter 'notify_url' in the paypal_ipn.php, located in STORENAME/includes/modules/payments folder.

 

 

i have just seen that the path was incorrect in includes/modules/payment/paypal_ipn.php, it was

ext/modules/payment/paypal_ipn/ipn.php

and the correct path in my shop is

ext/modules/payment/paypal/ipn.php

(without the "_ipn" in the last folder on the path).(i didnt change this, dont know if its an error on the module or if another module i installed after this did changed the text....)

 

i have just placed a test order (after correcting this) and now at least it seems to reach the script. but have another problem:

- placed an order at 15:08:05

- order updated to pending at 15:10:18 (comments: PayPal IPN Invalid [Completed])

- order updated to pending at 15:11:18 (comments: PayPal IPN Invalid [Completed])

- order updated to pending at 15:12:18 (comments: PayPal IPN Invalid [Completed])

and i have received 3 debug emails with 'paypal IPN invalid process'

 

anybody knows whats going wrong?

thanks

 

ps - the other problem im having, with sessions, is still there, but at least now it seems the script is being reached by the module :)

Share this post


Link to post
Share on other sites
Which version of this PayPal IPN module you're using?

 

it seems im using v2.3.2

from my paypal ipn settings:

 

PayPal IPN v2.3.2

Enable PayPal IPN Module

True

Gateway Server

Testing

E-Mail Address

xxxx@xxxx.com

Sort order of display.

1

Transaction Currency

Selected Currency

Payment Zone

--none--

Set Preparing Order Status

Preparing [PayPal IPN]

Set PayPal Acknowledged Order Status

Default

Set PayPal Completed Order Status

Download now available

Transaction Type

Aggregate

Move tax to total amount

True

Page Style

Debug E-Mail Address

xxxx@xxxxxx.com

cURL Proxy server

Enable Encrypted Web Payments

False

Your Private Key

Your Public Certificate

PayPals Public Certificate

Your PayPal Public Certificate ID

Working Directory

OpenSSL Location

/usr/bin/openssl

Share this post


Link to post
Share on other sites
Then the correct path for ipn.php is yourStorePath/ext/modules/payment/paypal_ipn/ipn.php

 

There is an IPN Troubleshooting section in the install guide, in the v2.3.3 package. Please read it.


Super Download Shop, PayPal Express Checkout IPN, Selling Downloads, Visual Validation (preventing robotic flood), phpBB2 Integration

 

Yes, I'm willing to help, but please ask in the right place. Think twice before trying to PM me, it might be ignored.

Share this post


Link to post
Share on other sites
Then the correct path for ipn.php is yourStorePath/ext/modules/payment/paypal_ipn/ipn.php

 

There is an IPN Troubleshooting section in the install guide, in the v2.3.3 package. Please read it.

 

thanks alex, i dont know what happened, when i install i did extract the ext folder from the zip. it seems at some point later the folder was renamed from 'paypal_ipn' to 'paypal' (by me or by another contribution, i dont remember).

anyways, its correct now and it reaches the ipn.php.

 

BUT the problem now is:

the payment is made, and 1 or 2 minutes later the order_status is updated to the Acknowledged Order Status, but with the comment "PayPal IPN Invalid [Completed]". this update is repeated 3 times, and i receive 3 debug emails with the same comment. It never udpates to the Completed Order Status, and i dont know whats causing the "invalid"

 

the debug email is:

 

$_POST:

 

payment_date=08:01:03 Dec 01, 2007 PST

txn_type=web_accept

last_name=User

residence_country=DE

item_name=XXXXXX

payment_gross=

mc_currency=EUR

business=XXXX@XXXX.com

payment_type=instant

verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AgJW714U4laZGIu5d9rBoR.6sAoS

payer_status=unverified

test_ipn=1

tax=0.00

payer_email=XXXX@XXXXXX.com

txn_id=67N81021SY400291G

quantity=1

receiver_email=XXXXX@XXXX.com

first_name=Test

invoice=66

payer_id=YQ32K7JGSNA6J

receiver_id=7KTHDA5KLW4WA

item_number=

payment_status=Completed

payment_fee=

mc_fee=2.22

shipping=0.00

mc_gross=58.00

custom=8

charset=windows-1252

notify_version=2.4

 

$_GET:

 

language=english

Share this post


Link to post
Share on other sites
Those data under $_POST: are what ipn.php received from the PayPal IPN calls, and ipn.php POST back all these data for verification. You got 'INVALID' responds because the verifications failed.

 

If your PHP is in safe mode, try turning safe mode off.

Edited by AlexStudio

Super Download Shop, PayPal Express Checkout IPN, Selling Downloads, Visual Validation (preventing robotic flood), phpBB2 Integration

 

Yes, I'm willing to help, but please ask in the right place. Think twice before trying to PM me, it might be ignored.

Share this post


Link to post
Share on other sites
Those data under $_POST: are what ipn.php received from the PayPal IPN calls, and ipn.php POST back all these data for verification. You got 'INVALID' responds because the verifications failed.

 

If your PHP is in safe mode, try turning safe mode off.

 

in admin -> tools -> server info, php safe mode is off...

what are these "verifications"? all my paypal test-users are verified (both customers and my test account as seller), does it something to do with this?

Share this post


Link to post
Share on other sites
The 'INVALID' or 'VERIFIED' responses from the IPN communications have nothing to do with the account status.

 

INVALID means that the data your ipn.php POST back didn't match the data sent by the IPN call from PayPal.

 

You received 3 INVALID responses from PayPal, which means that your server failed to send a '200 OK' response to the IPN verification message (INVALID or VERIFIED) from PayPal, so it kept calling your ipn.php script. This has nothing to do with the script, but the server itself.

Edited by AlexStudio

Super Download Shop, PayPal Express Checkout IPN, Selling Downloads, Visual Validation (preventing robotic flood), phpBB2 Integration

 

Yes, I'm willing to help, but please ask in the right place. Think twice before trying to PM me, it might be ignored.

Share this post


Link to post
Share on other sites
The 'INVALID' or 'VERIFIED' responses from the IPN communications have nothing to do with the account status.

 

INVALID means that the data your ipn.php POST back didn't match the data sent by the IPN call from PayPal.

 

You received 3 INVALID responses from PayPal, which means that your server failed to send a '200 OK' response to the IPN POST request from PayPal, so it kept calling your ipn.php script. This has nothing to do with the script, but the server itself.

 

 

ok thanks, i will try to contact my host and ask about this

Share this post


Link to post
Share on other sites
Most likely your server is blocking all outbound connections from scripts.

Super Download Shop, PayPal Express Checkout IPN, Selling Downloads, Visual Validation (preventing robotic flood), phpBB2 Integration

 

Yes, I'm willing to help, but please ask in the right place. Think twice before trying to PM me, it might be ignored.

Share this post


Link to post
Share on other sites

Alex:

After limping along with osCommerce PayPal IPN Mobule v1.1 For 2.2MS2 for years and having tried many times and failed with osCommerce PayPal IPN Mobule v2.0 For 1.2MS2 and other versions I am happy to say that I installed your v2.3.3 and it works perfectly. Since more than half of my payments are received via PayPal this is a great relief! This certainly fails to say it all but it's sincere: THANK YOU! I knew good things would happen when you became invloved.

Dennis

Share this post


Link to post
Share on other sites
The Working Directory is only used for encrypted webpayments.

 

If server error log is available, you can add debug code to ipn.php at the very top of the script, so you can find out if PayPal is able to access it or not. There are some instructions in this thread posted by Terra regarding the ipn.php debug code.

 

 

I enabled logs, and used the ipn.php code from http://forums.oscommerce.com/index.php?act...amp;pid=1052191

 

I recieved no error logs back.

 

 

But again, if I access the file myself http://www.MYSTORESITE.com/ext/modules/pay...pal_ipn/ipn.php

or http://www.MYINDEXSITE.info/MYSTORE/ext/mo...pal_ipn/ipn.php

 

I get the expected result of

PP TEST start

PP TEST PayPal is accessing the ipn file

PP TEST we have successfuly loaded application top and language file

PP TEST we are assembling the reply: cmd=_notify-validate

PP TEST PayPal server is www.sandbox.paypal.com

PP TEST option2 - curl is true

PP TEST fp is okay

PP TEST option2 we start to send string

PP TEST option2 REPLY:

PP TEST result is NOT VERIFIED

PP TEST end

 

again, this is only if I manually load the page myself.

 

NOTE: I have $parameters['notify_url'] hardcoded to

 

$parameters['notify_url'] = 'www.mystoresite.com/ext/modules/payment/paypal_ipn/ipn.php';

 

have also tried

$parameters['notify_url'] = 'www.myindexsite.info/mystore/ext/modules/payment/paypal_ipn/ipn.php';

 

 

I also have the paypal notify preferances set in the sandbox to

 

Instant Payment Notification (IPN) On

Instant Payment Notification (IPN) URL: http://www.mystoresite.com/ext/modules/pay...pal_ipn/ipn.php

 

I have also created 2 paypal sandbox accounts as I read in one post where that was the problem "profile was correct via paypal"

I'm not sure what else I can do.

Edited by tpwalker1980

Share this post


Link to post
Share on other sites
that could be the problem, regarding redirecting. if you can access your ipn.php by the url www.mymainsite.com/STORENAME/ext/modules/payment/paypal_ipn/ipn.php then try to hard code this with the parameter 'notify_url' in the paypal_ipn.php, located in STORENAME/includes/modules/payments folder.

 

Actually alex, I was already ahead of you :)

but I was forgetting to remove/install the contrib in the admin section.

So the changes I was making were not being updated.

 

I actually got error logs back now!

 

although I seem to get 1 error email per item listed in cart, (guess cuz Im doing per item)

 

 

 

$_POST:

 

mc_gross=52.90

invoice=20

address_status=confirmed

item_number1=80200

tax=0.00

item_number2=MYITEM#

payer_id=94HVTUXGCR9CY

address_street=MY ADDRESS

payment_date=19:28:40 Dec 01, 2007 PST

payment_status=Completed

charset=windows-1252

mc_tax1=0.00

address_zip=MY ZIP

mc_shipping=8.00

mc_tax2=0.00

mc_handling=0.00

first_name=Test

mc_fee=1.83

address_country_code=US

address_name=MY NAME

notify_version=2.4

custom=3

payer_status=verified

business=MYEMAIL@myemail.com

address_country=United States

num_cart_items=2

mc_handling1=0.00

mc_handling2=0.00

address_city=CITY

verify_sign=AZLwvfMjj87SX0jLZdq4lRBF9qr4AyGln0uBe8TS8nnPkXXodnmagDNk

payer_email=buyeremail@email.com

mc_shipping1=4.00

mc_shipping2=4.00

tax1=0.00

tax2=0.00

txn_id=2FE54422MR724035M

payment_type=instant

last_name=User

address_state=MI

item_name1=PRODUCT NAME

receiver_email=salesemail@email.com

item_name2=ITEM NAME

payment_fee=1.83

quantity1=1

quantity2=1

receiver_id=5H7XPMZM8WSK2

txn_type=cart

mc_gross_1=38.95

mc_currency=USD

mc_gross_2=13.95

residence_country=US

test_ipn=1

payment_gross=52.90

 

$_GET:

Share this post


Link to post
Share on other sites

I'm attempting to use the normal ipn.php file now.

this time I will remove the module from the admin section and then install it again.

will update you soon.

Share this post


Link to post
Share on other sites
I'm attempting to use the normal ipn.php file now.

this time I will remove the module from the admin section and then install it again.

will update you soon.

 

 

 

OK, using the normal ipn.php file produces no results.

BUT when I use the debug file... I see the error log and I get the PayPal IPN Invalid Process emails.

 

I get 3 PayPal IPN Invalid Process and I see 3 corresponding error logs. Again, I get none of this when using the ipn.php file from osCommerce_PayPal_IPN_v2.3.3

 

ERROR LOGS:

 PP TEST start
PP TEST PayPal is accessing the ipn file
PP TEST we have successfuly loaded application top and language file
PP TEST we are assembling the reply: cmd=_notify-validate&mc_gross=76.95&invoice=23&address_status=confirmed&payer_id=94HVTUXGCR9CY&tax=0.00&address_street=1111+street+Ave&payment_date=20%3A04%3A40+Dec+01%2C+2007+PST&payment_status=Completed&charset=windows-1252&address_zip=11111&first_name=Test&mc_fee=2.53&address_country_code=US&address_name=Travis+lastname&notify_version=2.4&custom=3&payer_status=verified&business=sales1_1196399201_biz%40site.com&address_country=United+States&address_city=CITY&quantity=1&verify_sign=AX1Q5Rz15ORQP9LTPyQNWnHeTCh6A.qH4LgJM1vbYO9luFtIYLOW008B&payer_email=buys12_1196399262_per%40mysite.com&txn_id=5J867102YC0280703&payment_type=instant&last_name=User&address_state=MI&receiver_email=sales1_1196399201_biz%40mysite.com&payment_fee=2.53&receiver_id=5H7XPMZM8WSK2&txn_type=web_accept&item_name=site.COM&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&payment_gross=76.95&shipping=8.00
PP TEST PayPal server is www.sandbox.paypal.com
PP TEST option2 - curl is true
PP TEST fp is okay
PP TEST option2 we start to send string
PP TEST option2 REPLY: 
PP TEST result is NOT VERIFIED
PP TEST start
PP TEST PayPal is accessing the ipn file
PP TEST we have successfuly loaded application top and language file
PP TEST we are assembling the reply: cmd=_notify-validate&mc_gross=76.95&invoice=23&address_status=confirmed&payer_id=94HVTUXGCR9CY&tax=0.00&address_street=1111+street+Ave&payment_date=20%3A04%3A40+Dec+01%2C+2007+PST&payment_status=Completed&charset=windows-1252&address_zip=48506&first_name=Test&mc_fee=2.53&address_country_code=US&address_name=Travis+lastname&notify_version=2.4&custom=3&payer_status=verified&business=sales1_1196399201_biz%40mysite.com&address_country=United+States&address_city=CITY&quantity=1&verify_sign=AX1Q5Rz15ORQP9LTPyQNWnHeTCh6A.qH4LgJM1vbYO9luFtIYLOW008B&payer_email=buys12_1196399262_per%40mysite.com&txn_id=5J867102YC0280703&payment_type=instant&last_name=User&address_state=MI&receiver_email=sales1_1196399201_biz%40mysite.com&payment_fee=2.53&receiver_id=5H7XPMZM8WSK2&txn_type=web_accept&item_name=mysite.COM&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&payment_gross=76.95&shipping=8.00
PP TEST PayPal server is www.sandbox.paypal.com
PP TEST option2 - curl is true
PP TEST fp is okay
PP TEST option2 we start to send string
PP TEST start
PP TEST PayPal is accessing the ipn file
PP TEST option2 REPLY: 
PP TEST result is NOT VERIFIED
PP TEST we have successfuly loaded application top and language file
PP TEST we are assembling the reply: cmd=_notify-validate&mc_gross=76.95&invoice=23&address_status=confirmed&payer_id=94HVTUXGCR9CY&tax=0.00&address_street=1111+street+Ave&payment_date=20%3A04%3A40+Dec+01%2C+2007+PST&payment_status=Completed&charset=windows-1252&address_zip=48506&first_name=Test&mc_fee=2.53&address_country_code=US&address_name=Travis+lastname&notify_version=2.4&custom=3&payer_status=verified&business=sales1_1196399201_biz%40mysite.com&address_country=United+States&address_city=city&quantity=1&verify_sign=AX1Q5Rz15ORQP9LTPyQNWnHeTCh6A.qH4LgJM1vbYO9luFtIYLOW008B&payer_email=buys12_1196399262_per%40mysite.com&txn_id=5J867102YC0280703&payment_type=instant&last_name=User&address_state=MI&receiver_email=sales1_1196399201_biz%40mysite.com&payment_fee=2.53&receiver_id=5H7XPMZM8WSK2&txn_type=web_accept&item_name=mysite.COM&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&payment_gross=76.95&shipping=8.00
PP TEST PayPal server is www.sandbox.paypal.com
PP TEST option2 - curl is true
PP TEST fp is okay
PP TEST option2 we start to send string
PP TEST option2 REPLY: 
PP TEST result is NOT VERIFIED

 

and the email I get:

$_POST:

mc_gross=76.95
invoice=23
address_status=confirmed
payer_id=94HVTUXGCR9CY
tax=0.00
address_street=1111 street Ave
payment_date=20:04:40 Dec 01, 2007 PST
payment_status=Completed
charset=windows-1252
address_zip=48506
first_name=Test
mc_fee=2.53
address_country_code=US
address_name=Travis lastname
notify_version=2.4
custom=3
payer_status=verified
business=sales1_1196399201_biz@mysite.com
address_country=United States
address_city=city
quantity=1
verify_sign=AX1Q5Rz15ORQP9LTPyQNWnHeTCh6A.qH4LgJM1vbYO9luFtIYLOW008B
payer_email=buys12_1196399262_per@mysite.com
txn_id=5J867102YC0280703
payment_type=instant
last_name=User
address_state=MI
receiver_email=sales1_1196399201_biz@ysite.com
payment_fee=2.53
receiver_id=5H7XPMZM8WSK2
txn_type=web_accept
item_name=mysite.COM
mc_currency=USD
item_number=
residence_country=US
test_ipn=1
payment_gross=76.95
shipping=8.00

$_GET:

 

 

Still don't understand why my normal ipn.php file is not producing any results.. but hopefully this helps and someone can point me in the right direction.

Share this post


Link to post
Share on other sites

Alright, Making progress...

 

 

Changed the original code found on http://forums.oscommerce.com/index.php?act...amp;pid=1052191

 

at line 100 added

 

	
// BOF add by AlexStudio
// For the poor souls on GoDaddy and the like, set the connection to go through their proxy
if (trim(MODULE_PAYMENT_PAYPAL_IPN_PROXY_SERVER) != '') {
  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  curl_setopt($ch, CURLOPT_PROXY, MODULE_PAYMENT_PAYPAL_IPN_PROXY_SERVER);
}

 

 

With this in place, this is the log I got back. This time only 1, not 3

 

PP TEST start

PP TEST PayPal is accessing the ipn file

PP TEST we have successfuly loaded application top and language file

PP TEST we are assembling the reply: cmd=_notify-validate&mc_gross=37.95&invoice=25&address_status=confirmed&payer_id=94HVTUXGCR9CY&tax=0.00&address_street=111+Streetname+Ave&payment_date=21%3A38%3A44+Dec+01%2C+2007+PST&payment_status=Completed&charset=windows-1252&address_zip=11111&first_name=Test&mc_fee=1.40&address_country_code=US&address_name=Travis+lastname&notify_version=2.4&custom=3&payer_status=verified&business=emailaddress@email.com&address_country=United+States&address_city=CITY&quantity=1&verify_sign=AiPC9BjkCyDFQXbSkoZcgqH3hpacAhdmPHIheT09GaRbOP77jgtnyp0F&payer_email=buys12_1196399262_per%40safet4you.com&txn_id=9NC76001V9243391G&payment_type=instant&last_name=User&address_state=STATE&receiver_email=emailaddy@email.com&payment_fee=1.40&receiver_id=5H7XPMZM8WSK2&txn_type=web_accept&item_name=MYSITE.com&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&payment_gross=37.95&shipping=8.00

PP TEST PayPal server is www.sandbox.paypal.com

PP TEST option2 - curl is true

PP TEST fp is okay

PP TEST option2 we start to send string

PP TEST option2 REPLY: VERIFIED

PP TEST result is VERIFIED

PP TEST order id is :25

Share this post


Link to post
Share on other sites
Alright, Making progress...

Changed the original code found on http://forums.oscommerce.com/index.php?act...amp;pid=1052191

 

at line 100 added

 

	
// BOF add by AlexStudio
// For the poor souls on GoDaddy and the like, set the connection to go through their proxy
if (trim(MODULE_PAYMENT_PAYPAL_IPN_PROXY_SERVER) != '') {
  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  curl_setopt($ch, CURLOPT_PROXY, MODULE_PAYMENT_PAYPAL_IPN_PROXY_SERVER);
}

With this in place, this is the log I got back. This time only 1, not 3

 

PP TEST start

PP TEST PayPal is accessing the ipn file

PP TEST we have successfuly loaded application top and language file

PP TEST we are assembling the reply: cmd=_notify-validate&mc_gross=37.95&invoice=25&address_status=confirmed&payer_id=94HVTUXGCR9CY&tax=0.00&address_street=111+Streetname+Ave&payment_date=21%3A38%3A44+Dec+01%2C+2007+PST&payment_status=Completed&charset=windows-1252&address_zip=11111&first_name=Test&mc_fee=1.40&address_country_code=US&address_name=Travis+lastname&notify_version=2.4&custom=3&payer_status=verified&business=emailaddress@email.com&address_country=United+States&address_city=CITY&quantity=1&verify_sign=AiPC9BjkCyDFQXbSkoZcgqH3hpacAhdmPHIheT09GaRbOP77jgtnyp0F&payer_email=buys12_1196399262_per%40safet4you.com&txn_id=9NC76001V9243391G&payment_type=instant&last_name=User&address_state=STATE&receiver_email=emailaddy@email.com&payment_fee=1.40&receiver_id=5H7XPMZM8WSK2&txn_type=web_accept&item_name=MYSITE.com&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&payment_gross=37.95&shipping=8.00

PP TEST PayPal server is www.sandbox.paypal.com

PP TEST option2 - curl is true

PP TEST fp is okay

PP TEST option2 we start to send string

PP TEST option2 REPLY: VERIFIED

PP TEST result is VERIFIED

PP TEST order id is :25

 

Status still not changing on the order in the website, and no confirmation email is being sent out by me, no stock updates.

Does appear as if though I am now getting Verified order confirmations. but something is still amiss...

Share this post


Link to post
Share on other sites
The debug file you're using is not 100% v2.3.3 updated.

 

Could you please post the entire debug code here (use [code][/code] instead, don't use [code box]) so I can modify it for you?


Super Download Shop, PayPal Express Checkout IPN, Selling Downloads, Visual Validation (preventing robotic flood), phpBB2 Integration

 

Yes, I'm willing to help, but please ask in the right place. Think twice before trying to PM me, it might be ignored.

Share this post


Link to post
Share on other sites
The debug file you're using is not 100% v2.3.3 updated.

 

Could you please post the entire debug code here (use [code][/code] instead, don't use [code box]) so I can modify it for you?

 

 

<?php
/*
 $Id: paypal_ipn.php,v 2.1.0.0 13/01/2007 16:30:21 Edith Karnitsch Exp $

 Copyright (c) 2004 osCommerce
 Released under the GNU General Public License

 Original Authors: Harald Ponce de Leon, Mark Evans 
 Updates by PandA.nl, Navyhost, Zoeticlight, David, gravyface, AlexStudio, windfjf, Monika in Germany and Terra

*/

##############################
##   THIS IS A DEBUG FILE   ##
##############################
# Check your error log for the resulting entries


error_log('PP TEST start');

error_log('PP TEST PayPal is accessing the ipn file');

 chdir('../../../../');
 require('includes/application_top.php');
 include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_PROCESS);

 error_log('PP TEST we have successfuly loaded application top and language file');

 $parameters = 'cmd=_notify-validate';

 foreach ($_POST as $key => $value) {
$parameters .= '&' . $key . '=' . urlencode(stripslashes($value));
 }

 error_log('PP TEST we are assembling the reply: ' . $parameters);

 if (MODULE_PAYMENT_PAYPAL_IPN_GATEWAY_SERVER == 'Live') {
$server = 'www.paypal.com';
 } else {
$server = 'www.sandbox.paypal.com';
 }

error_log('PP TEST PayPal server is ' . $server);

 $fsocket = false;
 $curl = false;
 $result = false;

 if ( (PHP_VERSION >= 4.3) && ($fp = @fsockopen('ssl://' . $server, 443, $errno, $errstr, 30)) ) {
 error_log('PP TEST option1 - fsocket is true, port 443');
$fsocket = true;
 } elseif (function_exists('curl_exec')) {
 error_log('PP TEST option2 - curl is true');
$curl = true;
 } elseif ($fp = @fsockopen($server, 80, $errno, $errstr, 30)) {
 error_log('PP TEST option3 - fsocket is true, port 80');
$fsocket = true;
 }

 if ( (!$fp) && ($curl != true) ){
 error_log('PP TEST ERROR: ' . $errno . ' - ' . $errstr);
  } else {
  error_log('PP TEST fp is okay');   
  }

 if ($fsocket == true) {

 error_log('PP TEST option1+3 we start to send string');

$header = 'POST /cgi-bin/webscr HTTP/1.0' . "\r\n" .
		  'Host: ' . $server . "\r\n" .
		  'Content-Type: application/x-www-form-urlencoded' . "\r\n" .
		  'Content-Length: ' . strlen($parameters) . "\r\n" .
		  'Connection: close' . "\r\n\r\n";

@fputs($fp, $header . $parameters);

$string = '';
while (!@feof($fp)) {

 error_log('PP TEST option1+3 we receive PayPal reply');	   

  $res = @fgets($fp, 1024);
  $string .= $res;

  if ( ($res == 'VERIFIED') || ($res == 'INVALID') ) {
	$result = $res;

 error_log('PP TEST option1+3 REPLY: ' . $result);		   

	break;
  }
}

@fclose($fp);
 } elseif ($curl == true) {
$ch = curl_init();

error_log('PP TEST option2 we start to send string');

	if (trim(MODULE_PAYMENT_PAYPAL_IPN_PROXY_SERVER) != '') {
  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  curl_setopt($ch, CURLOPT_PROXY, MODULE_PAYMENT_PAYPAL_IPN_PROXY_SERVER);
}

curl_setopt($ch, CURLOPT_URL, 'https://' . $server . '/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);

error_log('PP TEST option2 REPLY: ' . $result); 

curl_close($ch);
 }

 if ($result == 'VERIFIED') {

 error_log('PP TEST result is VERIFIED'); 

  error_log('PP TEST order id is :' . $_POST['invoice']); 

if (isset($_POST['invoice']) && is_numeric($_POST['invoice']) && ($_POST['invoice'] > 0)) {
  $order_query = tep_db_query("select currency, currency_value from " . TABLE_ORDERS . " where orders_id = '" . $_POST['invoice'] . "' and customers_id = '" . (int)$_POST['custom'] . "'");
  if (tep_db_num_rows($order_query) > 0) {

  error_log('PP TEST order id is okay and we start update process'); 

	$order_db = tep_db_fetch_array($order_query);

  // let's re-create the required arrays
	 require(DIR_WS_CLASSES . 'order.php');
	 $order = new order($_POST['invoice']);

	  require(DIR_WS_CLASSES . 'payment.php');
	  $payment_modules = new payment(paypal_ipn);

	// let's update the order status
	$total_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $_POST['invoice'] . "' and class = 'ot_total' limit 1");
	$total = tep_db_fetch_array($total_query);

	$comment_status = $_POST['payment_status'] . ' (' . ucfirst($_POST['payer_status']) . '; ' . $currencies->format($_POST['mc_gross'], false, $_POST['mc_currency']) . ')';

	if ($_POST['payment_status'] == 'Pending') {
	  $comment_status .= '; ' . $_POST['pending_reason'];
	} elseif ( ($_POST['payment_status'] == 'Reversed') || ($_POST['payment_status'] == 'Refunded') ) {
	  $comment_status .= '; ' . $_POST['reason_code'];
	} elseif ( ($_POST['payment_status'] == 'Completed') && (MODULE_PAYMENT_PAYPAL_IPN_SHIPPING == 'True') ) {
	  $comment_status .= ", \n" . PAYPAL_ADDRESS . ": " . $_POST['address_name'] . ", " . $_POST['address_street'] . ", " . $_POST['address_city'] . ", " . $_POST['address_zip'] . ", " . $_POST['address_state'] . ", " . $_POST['address_country'] . ", " . $_POST['address_country_code'] . ", " . $_POST['address_status'];
	} 

$order_status_id = DEFAULT_ORDERS_STATUS_ID;

// modified AlexStudio's Rounding error bug fix 
// variances of up to 0.05 on either side (plus / minus) are ignored
	if (
	 (((number_format($total['value'] * $order_db['currency_value'], $currencies->get_decimal_places($order_db['currency']))) -  $_POST['mc_gross']) <= 0.05)  
	 &&
	  (((number_format($total['value'] * $order_db['currency_value'], $currencies->get_decimal_places($order_db['currency']))) -  $_POST['mc_gross']) >= -0.05)		  
	) {

// previous validation
//		if ($_POST['mc_gross'] == number_format($total['value'] * $order_db['currency_value'], $currencies->get_decimal_places($order_db['currency']))) {

// Terra -> modified update. If payment status is "completed" than a completed order status is chosen based on the admin settings 
	  if ( (MODULE_PAYMENT_PAYPAL_IPN_COMP_ORDER_STATUS_ID > 0) && ($_POST['payment_status'] == 'Completed') ) {
		$order_status_id = MODULE_PAYMENT_PAYPAL_IPN_COMP_ORDER_STATUS_ID;
	  } elseif (MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID > 0) {
		$order_status_id = MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID;
	  } 

   }

	// Let's see what the PayPal payment status is and set the notification accordingly
	// more info: https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.html
	if ( ($_POST['payment_status'] == 'Pending') || ($_POST['payment_status'] == 'Completed')) {
	  $customer_notified = '1'; 
	  } else {
	  $customer_notified = '0'; 
	}


	tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . $order_status_id . "', last_modified = now() where orders_id = '" . $_POST['invoice'] . "'");

	$sql_data_array = array('orders_id' => $_POST['invoice'],
							'orders_status_id' => $order_status_id,
							'date_added' => 'now()',
							'customer_notified' => $customer_notified,
							'comments' => 'PayPal IPN Verified [' . $comment_status . ']');

	tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);


// If the order is completed, then we want to send the order email and update the stock
if ($_POST['payment_status'] == 'Completed') { // START STATUS == COMPLETED LOOP

// initialized for the email confirmation
 $products_ordered = '';
 $total_tax = 0;


// let's update the stock  
#######################################################
 for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { // PRODUCT LOOP STARTS HERE
// Stock Update - Joao Correia
if (STOCK_LIMITED == 'true') {
  if (DOWNLOAD_ENABLED == 'true') {
	$stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename 
						FROM " . TABLE_PRODUCTS . " p
						LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
						 ON p.products_id=pa.products_id
						LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
						 ON pa.products_attributes_id=pad.products_attributes_id
						WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
// Will work with only one option for downloadable products
// otherwise, we have to build the query dynamically with a loop
	$products_attributes = $order->products[$i]['attributes'];
	if (is_array($products_attributes)) {
	  $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
	}
	$stock_query = tep_db_query($stock_query_raw);
  } else {
	$stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
  }
  if (tep_db_num_rows($stock_query) > 0) {
	$stock_values = tep_db_fetch_array($stock_query);
// do not decrement quantities if products_attributes_filename exists
	if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
	  $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
	} else {
	  $stock_left = $stock_values['products_quantity'];
	}
	tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
	if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
	  tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
	}
  }
}

// Update products_ordered (for bestsellers list)
tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");



// Let's get all the info together for the email
$total_weight += ($order->products[$i]['qty'] * $order->products[$i]['weight']);
$total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
$total_cost += $total_products_price;

// Let's get the attributes
 $products_ordered_attributes = '';
  if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
		for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
		   $products_ordered_attributes .= "\n\t" . $order->products[$i]['attributes'][$j]['option'] . ' ' . $order->products[$i]['attributes'][$j]['value'];
		 }
  } 

// Let's format the products model	   
$products_model = '';	  
  if ( !empty($order->products[$i]['model']) ) {
	  $products_model = ' (' . $order->products[$i]['model'] . ')';
	  } 

// Let's put all the product info together into a string
  $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . $products_model . ' = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";


}		// PRODUCT LOOP ENDS HERE
#######################################################


// lets start with the email confirmation
// $order variables have been changed from checkout_process to work with the variables from the function query () instead of cart () in the order class
 $email_order = STORE_NAME . "\n" . 
			 EMAIL_SEPARATOR . "\n" . 
			 EMAIL_TEXT_ORDER_NUMBER . ' ' . $_POST['invoice'] . "\n" .
			 EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $_POST['invoice'], '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";

 for ($i=0, $n=sizeof($order->totals); $i<$n; $i++) {
 $email_order .= strip_tags($order->totals[$i]['title']) . ' ' . strip_tags($order->totals[$i]['text']) . "\n";
 }

 if ($order->content_type != 'virtual') {
$email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . 
				EMAIL_SEPARATOR . "\n" .
				tep_address_format($order->delivery['format_id'], $order->delivery,  0, '', "\n") . "\n";
 }

 $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
			  EMAIL_SEPARATOR . "\n" .
			  tep_address_format($order->billing['format_id'], $order->billing, 0, '', "\n") . "\n\n";
 if (is_object($$payment)) {
$email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . 
				EMAIL_SEPARATOR . "\n";
$payment_class = $$payment;
$email_order .= $payment_class->title . "\n\n";
if ($payment_class->email_footer) { 
  $email_order .= $payment_class->email_footer . "\n\n";
}
 }
 tep_mail($order->customer['name'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);


// send emails to other people
 if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 }

//emptying cart for everyone! by Monika in Germany
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$_POST['custom'] . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$_POST['custom'] . "'");
//end emptying cart for everyone


} // END STATUS == COMPLETED LOOP

// If the order is pending, then we want to send a notification email to the customer
if ($_POST['payment_status'] == 'Pending') { // START STATUS == PENDING LOOP

 $email_order = STORE_NAME . "\n" . 
			 EMAIL_SEPARATOR . "\n" . 
			 EMAIL_TEXT_ORDER_NUMBER . ' ' . $_POST['invoice'] . "\n" .
			 EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $_POST['invoice'], 'SSL', false) . "\n" .
			 EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n" . 
			 EMAIL_SEPARATOR . "\n" .
			 EMAIL_PAYPAL_PENDING_NOTICE . "\n\n"; 

 tep_mail($order->customer['name'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);


// send emails to other people
 if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 } 
} // END STATUS == PENDING LOOP

  }
}  else {
error_log('PP TEST order id problem - cannot verify order id'); 
}

 } else {

 error_log('PP TEST result is NOT VERIFIED'); 

if (tep_not_null(MODULE_PAYMENT_PAYPAL_IPN_DEBUG_EMAIL)) {
  $email_body = '$_POST:' . "\n\n";
  foreach ($_POST as $key => $value) {
	$email_body .= $key . '=' . $value . "\n";
  }
  $email_body .= "\n" . '$_GET:' . "\n\n";
  foreach ($_GET as $key => $value) {
	$email_body .= $key . '=' . $value . "\n";
  }

  tep_mail('', MODULE_PAYMENT_PAYPAL_IPN_DEBUG_EMAIL, 'PayPal IPN Invalid Process', $email_body, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
}

if (isset($_POST['invoice']) && is_numeric($_POST['invoice']) && ($_POST['invoice'] > 0)) {
  $check_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '" . $_POST['invoice'] . "' and customers_id = '" . (int)$_POST['custom'] . "'");
  if (tep_db_num_rows($check_query) > 0) {
	$comment_status = $_POST['payment_status'];

	if ($_POST['payment_status'] == 'Pending') {
	  $comment_status .= '; ' . $_POST['pending_reason'];
	} elseif ( ($_POST['payment_status'] == 'Reversed') || ($_POST['payment_status'] == 'Refunded') ) {
	  $comment_status .= '; ' . $_POST['reason_code'];
	}

	tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . ((MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID > 0) ? MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID : DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where orders_id = '" . $_POST['invoice'] . "'");

	$sql_data_array = array('orders_id' => $_POST['invoice'],
							'orders_status_id' => (MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID > 0) ? MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID : DEFAULT_ORDERS_STATUS_ID,
							'date_added' => 'now()',
							'customer_notified' => '0',
							'comments' => 'PayPal IPN Invalid [' . $comment_status . ']');

	tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
  }
}
 }

error_log('PP TEST end'); 

 require('includes/application_bottom.php');
?>

 

Note I also tried adding the debug code to 2.3.3 ipn.php myself, I don't think I forgot anything. But im not so sure anymore. So here is the original debug ipn.php

code provided on http://forums.oscommerce.com/index.php?act...amp;pid=1052191 with the formentioned code added on line 100 for the godaddy curlproxy fix.

Edited by tpwalker1980

Share this post


Link to post
Share on other sites
Alex:

After limping along with osCommerce PayPal IPN Mobule v1.1 For 2.2MS2 for years and having tried many times and failed with osCommerce PayPal IPN Mobule v2.0 For 1.2MS2 and other versions I am happy to say that I installed your v2.3.3 and it works perfectly. Since more than half of my payments are received via PayPal this is a great relief! This certainly fails to say it all but it's sincere: THANK YOU! I knew good things would happen when you became invloved.

Dennis

 

 

Hi,

 

Just thought I'd add my two cents worth. I'm still developing the site and I had installed v2.2 which did seem a bit cranky. So I decided to install v2.3.3. Wow! Slick or what? Still in the "Sandbox" but from what I can see this should all work just dandy! A huge thank you to all who worked on this! :thumbsup:

 

While I'm on the subject, a minor quibble. This may be a PayPal issue anyway. When I print the invoice from the PayPal (Sandbox) site, it chops off a good chunk off the right hand side. Any thoughts on this?

 

Best,

 

-Hank :)

Share this post


Link to post
Share on other sites

hi there,

 

i am using osCommerce RC1 and paypal IPN 2.2 and i am getting IPN errors when cookies are disabled. the session ID from osC generated will be submitted to paypal also, resulting in an error page (page not found) at paypal.

 

paypals login page after redirecting from my shop is correct (amount of money, etc) but after clicking "login", i will get a blank page.

 

i tested this "live", not in sandbox with two accounts. when enabling cookies in my browser, the session ID is hidden in the URL and so i don't get this error.

 

help is very much apprechiated ;-)

 

info: IPN v2.2, osC RC1, prevent spider sessios=TRUE, all other=FALSE, shop not in root directory but in /shop/, SSL deacivated, own dedicated server

 

best wishes,

marco.

(www.fussphantasie.de)

Share this post


Link to post
Share on other sites
Your error log as shown is telling you that the order id#25 does not exist in database. It's nothing to do with the IPN script. However, here is the ipn.php debug code for v2.3.3.

 

catalog/ext/modules/payment/paypal_ipn/ipn.php

<?php
/*
 $Id: ipn.php,v 2.3.0.0 10/09/2007 11:58:21 alexstudio Exp $

 Copyright (c) 2004 osCommerce
 Released under the GNU General Public License

 Original Authors: Harald Ponce de Leon, Mark Evans 
 Updates by PandA.nl, Navyhost, Zoeticlight, David, gravyface, AlexStudio, windfjf, Monika in Germany and Terra
 v2.3 updated by AlexStudio

*/
 error_log('PP TEST start'); // Debug code
 error_log('PP TEST PayPal is accessing the ipn file'); // Debug code

 chdir('../../../../');
 require('includes/application_top.php');
 include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_PROCESS);
 error_log('PP TEST we have successfuly loaded application top and language file'); // Debug code

 // BOF configuration keys fix by AlexStudio
 require(DIR_WS_CLASSES . 'payment.php');
 $payment_modules = new payment(paypal_ipn);
 // EOF configuration keys fix by AlexStudio
 error_log('PP TEST PayPal IPN module successfully loaded'); // Debug code

 $parameters = 'cmd=_notify-validate';

 foreach ($_POST as $key => $value) {
$parameters .= '&' . $key . '=' . urlencode(stripslashes($value));
 }
 error_log('PP TEST we are assembling the reply: ' . $parameters); // Debug code

 if (MODULE_PAYMENT_PAYPAL_IPN_GATEWAY_SERVER == 'Live') {
$server = 'www.paypal.com';
 } else {
$server = 'www.sandbox.paypal.com';
 }
 error_log('PP TEST PayPal server is ' . $server); // Debug code

 $fsocket = false;
 $curl = false;
 $result = false;

 if ( (PHP_VERSION >= 4.3) && ($fp = @fsockopen('ssl://' . $server, 443, $errno, $errstr, 30)) ) {
error_log('PP TEST option1 - fsocket is true, port 443'); // Debug code
$fsocket = true;
 } elseif (function_exists('curl_exec')) {
error_log('PP TEST option2 - curl is true'); // Debug code
$curl = true;
 } elseif ($fp = @fsockopen($server, 80, $errno, $errstr, 30)) {
error_log('PP TEST option3 - fsocket is true, port 80'); // Debug code
$fsocket = true;
 } else error_log('PP TEST ERROR: No connection available!! ' . $errno . ' - ' . $errstr); // Debug code

 if ($fsocket == true) {
error_log('PP TEST option1+3 we start to send string'); // Debug code
$header = 'POST /cgi-bin/webscr HTTP/1.0' . "\r\n" .
		  'Host: ' . $server . "\r\n" .
		  'Content-Type: application/x-www-form-urlencoded' . "\r\n" .
		  'Content-Length: ' . strlen($parameters) . "\r\n" .
		  'Connection: close' . "\r\n\r\n";

@fputs($fp, $header . $parameters);

$string = '';
while (!@feof($fp)) {
  error_log('PP TEST option1+3 we\'re receiving PayPal reply'); // Debug code
  $res = @fgets($fp, 1024);
  $string .= $res;

  if ( ($res == 'VERIFIED') || ($res == 'INVALID') ) {
	$result = $res;
	error_log('PP TEST option1+3 REPLY: ' . $result); // Debug code
	break;
  }
}

@fclose($fp);
 } elseif ($curl == true) {
error_log('PP TEST option2 we start to send string'); // Debug code
$ch = curl_init();

// BOF add by AlexStudio
// For the poor souls on GoDaddy and the like, set the connection to go through their proxy
if (trim(MODULE_PAYMENT_PAYPAL_IPN_PROXY_SERVER) != '') {
  error_log('PP TEST option2 proxy setting found, applying proxy setting'); // Debug code
  curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  curl_setopt($ch, CURLOPT_PROXY, MODULE_PAYMENT_PAYPAL_IPN_PROXY_SERVER);
  error_log('PP TEST option2 proxy setting: ' . MODULE_PAYMENT_PAYPAL_IPN_PROXY_SERVER); // Debug code
}
// Eof add by AlexStudio
curl_setopt($ch, CURLOPT_URL, 'https://' . $server . '/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);
error_log('PP TEST option2 REPLY: ' . $result); // Debug code

curl_close($ch);
 }

 if ($result == 'VERIFIED') {
error_log('PP TEST result is VERIFIED'); // Debug code
error_log('PP TEST order id is: ' . $_POST['invoice']); // Debug code
if (isset($_POST['invoice']) && is_numeric($_POST['invoice']) && ($_POST['invoice'] > 0)) {
  $order_query = tep_db_query("select currency, currency_value from " . TABLE_ORDERS . " where orders_id = '" . $_POST['invoice'] . "' and customers_id = '" . (int)$_POST['custom'] . "'");
  if (tep_db_num_rows($order_query) > 0) {
	error_log('PP TEST order id is okay and we start update process'); // Debug code
	$order_db = tep_db_fetch_array($order_query);

	// let's re-create the required arrays
	require(DIR_WS_CLASSES . 'order.php');
	$order = new order($_POST['invoice']);

	// let's update the order status
	$total_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $_POST['invoice'] . "' and class = 'ot_total' limit 1");
	$total = tep_db_fetch_array($total_query);

	$comment_status = 'payment status: ' . $_POST['payment_status'] . ' (' . ucfirst($_POST['payer_status']) . '; ' . $currencies->format($_POST['mc_gross'], false, $_POST['mc_currency']) . ')';

	if ($_POST['payment_status'] == 'Pending') {
	  $comment_status .= '; ' . $_POST['pending_reason'];
	} elseif ( ($_POST['payment_status'] == 'Reversed') || ($_POST['payment_status'] == 'Refunded') ) {
	  $comment_status .= '; ' . $_POST['reason_code'];
	} elseif ( ($_POST['payment_status'] == 'Completed') && (tep_not_null($_POST['address_street'])) ) {
	  $comment_status .= ", \n" . PAYPAL_ADDRESS . ": " . $_POST['address_name'] . ", " . $_POST['address_street'] . ", " . $_POST['address_city'] . ", " . $_POST['address_zip'] . ", " . $_POST['address_state'] . ", " . $_POST['address_country'] . ", " . $_POST['address_country_code'] . ", " . $_POST['address_status'];
	} 

	$order_status_id = DEFAULT_ORDERS_STATUS_ID;

// modified AlexStudio's Rounding error bug fix 
// variances of up to 0.05 on either side (plus / minus) are ignored
	if ((((number_format($total['value'] * $order_db['currency_value'], $currencies->get_decimal_places($order_db['currency']))) -  $_POST['mc_gross']) <= 0.05)  
	  &&
	  (((number_format($total['value'] * $order_db['currency_value'], $currencies->get_decimal_places($order_db['currency']))) -  $_POST['mc_gross']) >= -0.05)) {

// Terra -> modified update. If payment status is "completed" than a completed order status is chosen based on the admin settings 
	  if ( (MODULE_PAYMENT_PAYPAL_IPN_COMP_ORDER_STATUS_ID > 0) && ($_POST['payment_status'] == 'Completed') ) {
		$order_status_id = MODULE_PAYMENT_PAYPAL_IPN_COMP_ORDER_STATUS_ID;
	  } elseif (MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID > 0) {
		$order_status_id = MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID;
	  }
	}

	// Let's see what the PayPal payment status is and set the notification accordingly
	// more info: https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.html
	if ( ($_POST['payment_status'] == 'Pending') || ($_POST['payment_status'] == 'Completed')) {
	  $customer_notified = '1'; 
	} else {
	  $customer_notified = '0'; 
	}

	tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . $order_status_id . "', last_modified = now() where orders_id = '" . $_POST['invoice'] . "'");

	$sql_data_array = array('orders_id' => $_POST['invoice'],
							'orders_status_id' => $order_status_id,
							'date_added' => 'now()',
							'customer_notified' => $customer_notified,
							'comments' => 'PayPal IPN Verified [' . $comment_status . ']');

	tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);

// If the order is completed, then we want to send the order email and update the stock
	if ($_POST['payment_status'] == 'Completed') { // START STATUS == COMPLETED LOOP

// initialized for the email confirmation
	  $products_ordered = '';
	  $total_tax = 0;

// let's update the stock  
#######################################################
	  for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { // PRODUCT LOOP STARTS HERE
// Stock Update - Joao Correia
		if (STOCK_LIMITED == 'true') {
		  if (DOWNLOAD_ENABLED == 'true') {
			$stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename 
								FROM " . TABLE_PRODUCTS . " p
								LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
								ON p.products_id=pa.products_id
								LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
								ON pa.products_attributes_id=pad.products_attributes_id
								WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
// Will work with only one option for downloadable products
// otherwise, we have to build the query dynamically with a loop
			$products_attributes = $order->products[$i]['attributes'];
			if (is_array($products_attributes)) {
			  $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
			}
			$stock_query = tep_db_query($stock_query_raw);
		  } else {
			$stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
		  }
		  if (tep_db_num_rows($stock_query) > 0) {
			$stock_values = tep_db_fetch_array($stock_query);
// do not decrement quantities if products_attributes_filename exists
			if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
			  $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
			} else {
			  $stock_left = $stock_values['products_quantity'];
			}
			tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
			if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
			  tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
			}
		  }
		}

// Update products_ordered (for bestsellers list)
		tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

// Let's get all the info together for the email
		$total_weight += ($order->products[$i]['qty'] * $order->products[$i]['weight']);
		$total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
		$total_cost += $total_products_price;

// Let's get the attributes
		$products_ordered_attributes = '';
		if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
		  for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
			$products_ordered_attributes .= "\n\t" . $order->products[$i]['attributes'][$j]['option'] . ' ' . $order->products[$i]['attributes'][$j]['value'];
		  }
		} 

// Let's format the products model	   
		$products_model = '';	  
		if ( !empty($order->products[$i]['model']) ) {
		  $products_model = ' (' . $order->products[$i]['model'] . ')';
		} 

// Let's put all the product info together into a string
		$products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . $products_model . ' = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
	  }		// PRODUCT LOOP ENDS HERE
#######################################################

// lets start with the email confirmation
// BOF content type fix by AlexStudio
		$content_type = '';
		$content_count = 0;
		// BOF order comment fix
		$comment_query = tep_db_query("select comments from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '" . $_POST['invoice'] . "'");
		$comment_array = tep_db_fetch_array($comment_query);
		$comments = $comment_array['comments'];
		// EOF order comment fix

		if (DOWNLOAD_ENABLED == 'true') {
		  $content_query = tep_db_query("select * from " . TABLE_ORDERS_PRODUCTS_DOWNLOAD . " where orders_id = '" . (int)$_POST['invoice'] . "'");
		  $content_count = tep_db_num_rows($content_query);
		  if ($content_count > 0) {
			$content_type = 'virtual';
		  }
		}
		switch ($content_type) {
		  case 'virtual':
			if ($content_count != sizeof($order->products)) $content_type = 'mixed'; 
			break;
		  default:
			$content_type = 'physical';
			break;
		}
// EOF content type fix by AlexStudio
// $order variables have been changed from checkout_process to work with the variables from the function query () instead of cart () in the order class
	  $email_order = STORE_NAME . "\n" . 
					 EMAIL_SEPARATOR . "\n" . 
					 EMAIL_TEXT_ORDER_NUMBER . ' ' . $_POST['invoice'] . "\n" .
					 EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $_POST['invoice'], 'SSL', false) . "\n" .
					 EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";

	  // BOF order comment fix by AlexStudio
	  if ($comments) {
		$email_order .= $comments . "\n\n";
	  }
	  // EOF order comment fix by AlexStudio

	  $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . 
					  EMAIL_SEPARATOR . "\n" . 
					  $products_ordered . 
					  EMAIL_SEPARATOR . "\n";

	  for ($i=0, $n=sizeof($order->totals); $i<$n; $i++) {
		$email_order .= strip_tags($order->totals[$i]['title']) . ' ' . strip_tags($order->totals[$i]['text']) . "\n";
	  }

	  // BOF content type fix by AlexStudio
	  if ($content_type != 'virtual') {
	  // EOF content type fix by AlexStudio
		$email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . 
						EMAIL_SEPARATOR . "\n" .
						tep_address_format($order->delivery['format_id'], $order->delivery,  0, '', "\n") . "\n";
	  }

	  $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
					  EMAIL_SEPARATOR . "\n" .
					  tep_address_format($order->billing['format_id'], $order->billing, 0, '', "\n") . "\n\n";
	  if (is_object($$payment)) {
		$email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . 
						EMAIL_SEPARATOR . "\n";
		$payment_class = $$payment;
		$email_order .= $payment_class->title . "\n\n";
		if ($payment_class->email_footer) { 
		  $email_order .= $payment_class->email_footer . "\n\n";
		}
	  }
	  tep_mail($order->customer['name'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

// send emails to other people
	  if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
		tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
	  }
	} // END STATUS == COMPLETED LOOP

	if ($_POST['payment_status'] == 'Pending') { // START STATUS == PENDING LOOP

	  $email_order = STORE_NAME . "\n" . 
					 EMAIL_SEPARATOR . "\n" . 
					 EMAIL_TEXT_ORDER_NUMBER . ' ' . $_POST['invoice'] . "\n" .
					 EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $_POST['invoice'], 'SSL', false) . "\n" .
					 EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n" . 
					 EMAIL_SEPARATOR . "\n" .
					 EMAIL_PAYPAL_PENDING_NOTICE . "\n\n"; 

	  tep_mail($order->customer['name'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

// send emails to other people
	  if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
		tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
	  } 
	} // END STATUS == PENDING LOOP
//emptying cart for everyone! by Monika in Germany
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$_POST['custom'] . "'");
	tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$_POST['custom'] . "'");
//end emptying cart for everyone
  } else error_log('PP TEST order id: ' . $_POST['invoice'] . ' not found in database, process halted!!'); // Debug code
} else error_log('PP TEST order id problem - cannot verify order id'); // Debug code
 } else {
error_log('PP TEST result is NOT VERIFIED'); // Debug code
if (tep_not_null(MODULE_PAYMENT_PAYPAL_IPN_DEBUG_EMAIL)) {
  $email_body = '$_POST:' . "\n\n";
  foreach ($_POST as $key => $value) {
	$email_body .= $key . '=' . $value . "\n";
  }
  $email_body .= "\n" . '$_GET:' . "\n\n";
  foreach ($_GET as $key => $value) {
	$email_body .= $key . '=' . $value . "\n";
  }
  tep_mail('', MODULE_PAYMENT_PAYPAL_IPN_DEBUG_EMAIL, 'PayPal IPN Invalid Process', $email_body, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
}

if (isset($_POST['invoice']) && is_numeric($_POST['invoice']) && ($_POST['invoice'] > 0)) {
  $check_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '" . $_POST['invoice'] . "' and customers_id = '" . (int)$_POST['custom'] . "'");
  if (tep_db_num_rows($check_query) > 0) {
	$comment_status = $_POST['payment_status'];

	if ($_POST['payment_status'] == 'Pending') {
	  $comment_status .= '; ' . $_POST['pending_reason'];
	} elseif ( ($_POST['payment_status'] == 'Reversed') || ($_POST['payment_status'] == 'Refunded') ) {
	  $comment_status .= '; ' . $_POST['reason_code'];
	}

	tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . ((MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID > 0) ? MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID : DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where orders_id = '" . $_POST['invoice'] . "'");

	$sql_data_array = array('orders_id' => $_POST['invoice'],
							'orders_status_id' => (MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID > 0) ? MODULE_PAYMENT_PAYPAL_IPN_ORDER_STATUS_ID : DEFAULT_ORDERS_STATUS_ID,
							'date_added' => 'now()',
							'customer_notified' => '0',
							'comments' => 'PayPal IPN Invalid [' . $comment_status . ']');

	tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
  }
}
 }
 error_log('PP TEST end'); // Debug code
 require('includes/application_bottom.php');
?>


Super Download Shop, PayPal Express Checkout IPN, Selling Downloads, Visual Validation (preventing robotic flood), phpBB2 Integration

 

Yes, I'm willing to help, but please ask in the right place. Think twice before trying to PM me, it might be ignored.

Share this post


Link to post
Share on other sites
How about adding some text in your page header like:
We have detected that your browser does not support cookies, or has set cookies to be disabled.

 

To continue shopping online, we encourage you to enable cookies on your browser.

Quoted from stock osCommerce cookie_usage.php

Super Download Shop, PayPal Express Checkout IPN, Selling Downloads, Visual Validation (preventing robotic flood), phpBB2 Integration

 

Yes, I'm willing to help, but please ask in the right place. Think twice before trying to PM me, it might be ignored.

Share this post


Link to post
Share on other sites
Your error log as shown is telling you that the order id#25 does not exist in database. It's nothing to do with the IPN script. However, here is the ipn.php debug code for v2.3.3.

 

catalog/ext/modules/payment/paypal_ipn/ipn.php

 *removed to keep this short

 

 

Ok, using the code you provided (thank you) I am getting the same results

 

PP TEST start

PP TEST PayPal is accessing the ipn file

PP TEST we have successfuly loaded application top and language file

PP TEST PayPal IPN module successfully loaded

PP TEST we are assembling the reply: cmd=_notify-validate&mc_gross=67.90&invoice=28&address_status=confirmed&payer_id=94HVTUXGCR9CY&tax=0.00&address_street=1111+STREET+Ave&payment_date=09%3A25%3A09+Dec+02%2C+2007+PST&payment_status=Completed&charset=windows-1252&address_zip=11111&first_name=Test&mc_fee=2.27&address_country_code=US&address_name=Travis+lastname&notify_version=2.4&custom=3&payer_status=verified&business=email@addy.com&address_country=United+States&address_city=city&quantity=1&verify_sign=AwXP3w6UFMwvhGJcjzen4UK3goYhAqlO8eRsNBvRZtU3F101fPEbf7yF&payer_email=emailaddy@email.com&txn_id=89467957W3575245D&payment_type=instant&last_name=User&address_state=AA&receiver_email=emailaddy@email.com&payment_fee=2.27&receiver_id=5H7XPMZM8WSK2&txn_type=web_accept&item_name=MYSITE.COM&mc_currency=USD&item_number=&residence_country=US&test_ipn=1&payment_gross=67.90&shipping=8.00

PP TEST PayPal server is www.sandbox.paypal.com

PP TEST option2 - curl is true

PP TEST option2 we start to send string

PP TEST option2 proxy setting found, applying proxy setting

PP TEST option2 proxy setting: http://proxy.shr.secureserver.net:3128

PP TEST option2 REPLY: VERIFIED

PP TEST result is VERIFIED

PP TEST order id is: 28

 

 

I have verified that the order ID referanced does exist in my orders table within the MySQL database.

Note* I am using MySQL 5.0

 

so from what your saying.... if order ID 28 does exist in my orders table, I am having trouble processing

 

  if ($result == 'VERIFIED') {
error_log('PP TEST result is VERIFIED'); // Debug code
error_log('PP TEST order id is: ' . $_POST['invoice']); // Debug code
if (isset($_POST['invoice']) && is_numeric($_POST['invoice']) && ($_POST['invoice'] > 0)) {
  $order_query = tep_db_query("select currency, currency_value from " . TABLE_ORDERS . " where orders_id = '" . $_POST['invoice'] . "' and customers_id = '" . (int)$_POST['custom'] . "'");
  if (tep_db_num_rows($order_query) > 0) {
	error_log('PP TEST order id is okay and we start update process'); // Debug code
	$order_db = tep_db_fetch_array($order_query);

 

 

more specifically

 if (isset($_POST['invoice']) && is_numeric($_POST['invoice']) && ($_POST['invoice'] > 0)) {
  $order_query = tep_db_query("select currency, currency_value from " . TABLE_ORDERS . " where orders_id = '" . $_POST['invoice'] . "' and customers_id = '" . (int)$_POST['custom'] . "'");

I understand what is_numeric($_POST['invoice']) is for (VERIFICATION ITS A NUMBER)

and what ($_POST['invoice'] > 0) is for (MAKE SURE ITS GREATER THAN 0)

But what is (isset($_POST['invoice']) for

 

 

 

Anyhow I took

the line I think is the problem, went into mysqladmin and ran the command

 

SELECT 'currency', 'currency_value' FROM 'orders' WHERE 'orders_id' = '28' and 'customers_id' = '3'

 

and this is the response I got

SQL query: Documentation

 

SELECT 'currency', 'currency_value'

FROM 'orders'

WHERE 'orders_id' = '28'

AND 'customers_id' = '3'

LIMIT 0 , 30

 

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''orders' WHERE 'orders_id' = '28' and 'customers_id' = '3'

LIMIT 0, 30' at line 1

Share this post


Link to post
Share on other sites
Since you got the 'VERIFIED' ipn responses, your ipn.php is working fine. The rest problem you have is a MySQL 5 compatibility issue, please refer to other threads relevant to it.

Super Download Shop, PayPal Express Checkout IPN, Selling Downloads, Visual Validation (preventing robotic flood), phpBB2 Integration

 

Yes, I'm willing to help, but please ask in the right place. Think twice before trying to PM me, it might be ignored.

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

×