Post by gary » Sat Nov 17, 2007 1:11 am

salmoon wrote: Well Gary, i find all that a bit confusing. I tried what you suggested with taking password off the directory and using SSL but this didn't work for me.

I've tried so many things now. I've tried taking ssl:// from the fsockopen lines.. and just using www. I've tried using http:// because someone said if you're coming from a http:// you need to set the url in fsock to the same. Made no difference.

I've even added the lines:
mail('myemail@mail.com', "INVALID IPN", "$res\n $req");
mail('myemail@mail.com', "VALID IPN", "$res\n $req");


to try and get some email notification if the IPN was returning valid / invalid but i didn't even get those emails. So it seems paypal just isn't communicating back to the shopping cart at all..
well I am not sure what changed it for me. I asked my hosting if fsockopen is disabled - they checked and told me - no. Perhaps they changed something - because right after that I started receiving callbacks. The only changes I made on my end - I described.

OK, I will explain simpler. The workaround to missing paypal callbacks - is to process order when user comes back to merchant from the paypal - after paying. If user does not come back - order is lost (like it is lost right now if callback does not come).

So, to process order after user returns from paypal do this:
1) copy "process" function from cod class (located in catalog/extension/payment/cod.php) to paypal class (catalog/extension/payment/paypal.php)
2) find in same paypal class "callback" function - and comment it all out (leave definition just in case - although not sure if you need it)

That should do it. Of course you will have to put notice on your confirm page - that order will not be processed if user does not come back to merchant after paying.
Last edited by gary on Sat Nov 17, 2007 1:14 am, edited 1 time in total.

New member

Posts

Joined
Sun Nov 04, 2007 11:55 pm

Post by salmoon » Sat Nov 17, 2007 1:54 am

Ah ok i get it now thanks :)

So then, without doing this should the cart update the db with the order regardless of whether the user clicks 'return to merchant' ? Is that the way it's supposed to work?

New member

Posts

Joined
Sun Oct 21, 2007 9:59 pm

Post by salmoon » Sat Nov 17, 2007 2:34 am

I just checked my raw acces logs and they're giving me this:

66.211.170.66 - - [16/NOV/2007:09:17:25 +0000] "POST /INDEX.PHP?CONTROLLER=CHECKOUT_PROCESS&ACTION=CALLBACK&PAYMENT=PAYPAL HTTP/1.0" 401 - "-" "-"



I've spoke to Paypal tech support about it and they said this:
You are receiving 401 for the reply, which is 'file
not found'. Please check the 'notify_url' variable in your button code to
make sure that the URL that is included is the exact path to the IPN
script. The problem is that we cannot find your IPN script to post to.
So the notify_url line in paypal.php is:
$ouput .= 'url->ssl('checkout_process', 'callback', array('payment' => 'paypal')) . '" />' . "\n";
Is there something wrong in that url??

Daniel?

New member

Posts

Joined
Sun Oct 21, 2007 9:59 pm

Post by salmoon » Sat Nov 17, 2007 2:52 am

Gary i just tried your suggestion and it frikken works! There's a way round the whole getting the customer to click on the return to merchant link and thats to set up "auto return" in paypal to "index.php?controller=checkout_success" so it happens automatically.

My only concern now is that this IPN stuff might suddenly start working later down the line - what will happen if it does and the function "process" is still in there. Would there be an error or a duplicate order or something?

Or is this actually safe enough to use?

New member

Posts

Joined
Sun Oct 21, 2007 9:59 pm

Post by gary » Sat Nov 17, 2007 3:04 am

salmoon wrote: I've spoke to Paypal tech support about it and they said this:
You are receiving 401 for the reply, which is 'file
not found'. Please check the 'notify_url' variable in your button code to
make sure that the URL that is included is the exact path to the IPN
script. The problem is that we cannot find your IPN script to post to.
I am wondering if password protection on the directory was having any effect on them finding the function. But you removed it and it still does not callback?
salmoon wrote: So then, without doing this should the cart update the db with the order regardless of whether the user clicks 'return to merchant' ? Is that the way it's supposed to work?
callback from paypal is sent after user pays - no matter if he returns to merchant or not
salmoon wrote: Gary i just tried your suggestion and it frikken works! There's a way round the whole getting the customer to click on the return to merchant link and thats to set up "auto return" in paypal to "index.php?controller=checkout_success" so it happens automatically.

My only concern now is that this IPN stuff might suddenly start working later down the line - what will happen if it does and the function "process" is still in there. Would there be an error or a duplicate order or something?

Or is this actually safe enough to use?
if you commented out "callback" function in paypal class - then even if paypal calls back - nothing will happen. All callback function was doing - is processing the order. Same like the "process" function that you just copied to paypal class. Only that "process" function is called at different time.

Hmm - "auto return" sounds good. Have to read about it. Do you have any details?
Last edited by gary on Sat Nov 17, 2007 3:09 am, edited 1 time in total.

New member

Posts

Joined
Sun Nov 04, 2007 11:55 pm

Post by salmoon » Sat Nov 17, 2007 3:13 am

Hmm - "auto return" sounds good. Have to read about it. Do you have any details?
Goto your paypal account > profile > "Website Payment Preferences". Auto return's at the top of the page.

Work's really nicely now. I hope we can fix the problem however so we don't have to depend on the customer coming back to the site.


Thanks so much for sharing your findings Gary.

New member

Posts

Joined
Sun Oct 21, 2007 9:59 pm

Post by gary » Sat Nov 17, 2007 3:19 am

salmoon wrote: Goto your paypal account > profile > "Website Payment Preferences". Auto return's at the top of the page.

Work's really nicely now. I hope we can fix the problem however so we don't have to depend on the customer coming back to the site.

Thanks so much for sharing your findings Gary.
no problem. Found good explanation about paypal workings here:
http://www.pdncommunity.com/pdn/board/m ... age.id=368

New member

Posts

Joined
Sun Nov 04, 2007 11:55 pm

Post by tchemis » Sat Nov 17, 2007 4:19 am

Are you guys using the current version 0.7.7? I had all the same problems with paypal you guys have been mentioning above but they were fixed when I upgraded to 0.7.7 with out any code changes.

As a side note you should setup the paypal redirect to the confirmation page in opencart on the paypal side, else paypal does not know where to send the user back to. This was also the case long ago when I messed with osCommerce.

Active Member

Posts

Joined
Tue Aug 21, 2007 9:23 am

Post by gary » Sat Nov 17, 2007 5:02 am

tchemis wrote: Are you guys using the current version 0.7.7? I had all the same problems with paypal you guys have been mentioning above but they were fixed when I upgraded to 0.7.7 with out any code changes.

As a side note you should setup the paypal redirect to the confirmation page in opencart on the paypal side, else paypal does not know where to send the user back to. This was also the case long ago when I messed with osCommerce.
I am using 0.7.7

return url is provided in code, I think. Isn't that the same as specifying it in paypal account?
$ouput .= 'url->ssl('checkout_process') . '" />' . "\n";
callback started working for me recently. However - I don't think reliance on callback is a good thing. Callback should be used to notify if payment has been received - not to process an order. What if payment is received and callback never comes? You have somebody's money - but have no idea what they ordered. And also - the product is not subtracted from stock.

New member

Posts

Joined
Sun Nov 04, 2007 11:55 pm

Post by sdghosh » Thu Dec 13, 2007 9:34 am

gary wrote:
function process_paid($order_status_id){
if ($this->data) {

//get order id 
$sql  = "select order_id from `order` where reference = '?'";
$order_id = $this->database->getRow($this->database->parse($sql, $this->reference));

$sql = "update `order` set order_status_id = '?' where order_id = '?'";
$this->database->query($this->database->parse($sql, $order_status_id, $order_id));

$sql = "update order_history set order_status_id = '?' where order_id = '?'";
$this->database->query($this->database->parse($sql, $order_status_id, $order_id));

//kill order_data
$sql = "delete from order_data where reference = '?'";
$this->database->query($this->database->parse($sql, $this->reference));
}
}

will you be kind enough to tell me which directory password did you disable? I have activated SSL in admin although I have no SSL. Please also tell me where do I have to add this piece of code?

For me too database do not get updated once a transaction is done.

thanks

Newbie

Posts

Joined
Fri Nov 16, 2007 6:26 am

Post by gary » Fri Dec 14, 2007 4:28 am

I had password protected main directory while developing.

However - I am not sure if that was what prevented paypal callback from coming in. Also - I am not sure if SSL in admin had anything to do with callback either. I did not continue testing once it started working.

The code that you quoted was more of the "vision". It will not work just by itself. The idea was to process order initially just before user was redirected to the payment gateway - and then update order status to "paid" - after callback. Then - in case you got confirmation in any other way - like paypal e-mail - you could just update order status to "paid" yourself - and not rely on callback.
However - once callback started working - I did not spend any more time developing it. So I never had working code for it.

New member

Posts

Joined
Sun Nov 04, 2007 11:55 pm

Post by Daniel » Fri Dec 14, 2007 4:48 am

I think I know what the problem is.

On the documentation provided by paypal they are using a differnt url to the one I used. I could not get the url set by paypal to work.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by gary » Fri Dec 14, 2007 5:07 am

I am not sure if that is the case. I did not change your code (or rather - I changed it - and the changed it back)  - so callback did not work - and later started working - using same exact url....

New member

Posts

Joined
Sun Nov 04, 2007 11:55 pm

Post by asif » Wed Jan 23, 2008 3:14 am

well guys...if u r just processing orders on customer returning back to ur site then it is not good...because user comes back to "return_url" page, n he can return to ur site without being processing any transaction...so u might have to process the "form" that paypal submit it to opencart's "return_url" page.

New member

Posts

Joined
Wed Jan 16, 2008 10:35 pm

Post by asif » Thu Jan 24, 2008 2:14 am

well its me again... it worked for me...n now i have even tested it on my personal machine...
lets get started...
1. (i think no body is that goof but still)if u ppl r tryin to check it on ur own systems...then first u have to change the HTTP_SERVER and HTTP_IMAGE in config.php...change localhost with ur IP address(each time when u connect if u don hav a static IP)... stop any firewall..or allow incomings/outgoing to/from port 80,443 from paypal's site or sandox.paypal site.
2. I think the problem with opencart is not of receiveing notification from paypal, the problem is in sending the same notification back to paypal for varification. I think n i m quite sure abt it bcauz when i started debuggin... paypal was constantly hitting my apache but opencart code was unable to response back...n my ISP proxy always reponded with bad HTTP request...
3. now i did small changes in method "callback" in paypal.php. these changes r based on the code from OSCommerce paypal module. In OSCommerce they try three different possibilities to connect to paypal site and one will surely work for u. as following change worked for me  :) if it doesnt work for u then try other two n u can get it from OScommerce easily...
well i only tested it on sandbox.paypal's test accounts n its working fine...

function callback() {
$req = 'cmd=_notify-validate';

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

$header  = 'POST /cgi-bin/webscr HTTP/1.0' . "\r\n";
$header .= 'Host: www.sandbox.paypal.com' . "\r\n";  /* it must be paypal.com for real accounts*/
$header .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
$header .= 'Content-Length: ' . strlen($req) . "\r\n";
$header .= 'Connection: close' . "\r\n\r\n";

if (!$this->config->get('paypal_test')) {
$fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);      /*port will be 443 here if u r using ssl*/
} else {
$fp = fsockopen('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
}

$fp1 = fopen("c:\\test.txt","w");  /* jusr for debuggin n it is getting here or not*/
fwrite($fp1,"1");
if ($fp) {
fputs($fp, $header . $req);

while (!feof($fp)) {
$res = fgets($fp, 1024);
fwrite($fp1,"\r\n" . $res);
if (strcmp($res, 'VERIFIED') == 0) {
$this->order->load($this->request->get('invoice', 'post'));
fwrite($fp1,$this->request->get('invoice', 'post'));  /*just writing invoice number to debug file*/
$this->order->process();
}
}

fclose($fp);
}
else
{
fwrite($fp1,"\r\socket creation  fail for paypal :("); /* if unable to open socket for paypal*/
}
  }
}

New member

Posts

Joined
Wed Jan 16, 2008 10:35 pm

Post by bruce » Mon Jan 28, 2008 12:51 pm

You might like to look at this. The work flow suggested does not rely on the callback.

http://www.opencart.com/contribution/in ... tion_id/33

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by asif » Tue Jan 29, 2008 2:33 am

bruce wrote: You might like to look at this. The work flow suggested does not rely on the callback.

http://www.opencart.com/contribution/in ... tion_id/33
hye bruce, thnx buddy, ur code is quite handy... but i think there is a slight mistake in it...
following code in callback() method

Code: Select all

$sql = "update `order` set `order_status_id` = '?' where `reference` = '?' and `order_status_id` = '?'";
$parsed = $this->database->parse($sql, $paidUnconfirmedStatus, $reference, $pendingStatus);
it is changing status from "Pending" to "PendingUnconfirmed", it should be changing from PendingUnconfirmed to Pending status
i think it should be...

Code: Select all

$sql = "update `order` set `order_status_id` = '?' where `reference` = '?' and `order_status_id` = '?'";
$parsed = $this->database->parse($sql, $pendingStatus, $reference, $paidUnconfirmedStatus);
change it before it get spreaded...

1. another comment is that My site started workin fine with the slight change in Header creation for Paypal "post" as i mentioned in above thread. I get paypal verification even before customer get to success page sometime... in this case, Callback() method willl not find order with this reference n hence it will fail. and when customer hits success page then it will process the order n its status will be never changed.
2. so if we have to tackle this problem, we need 1 "if-else" each in process() and callback() methods. please if u got time do us a favour...or i'll try to make it if i got time...
Last edited by asif on Tue Jan 29, 2008 3:00 am, edited 1 time in total.

New member

Posts

Joined
Wed Jan 16, 2008 10:35 pm

Post by bruce » Tue Jan 29, 2008 7:51 am

Thanks asif. I have started a new topic for this extension http://forum.opencart.com/index.php/topic,880.0.html and included your findings in the first post.

cheers

bruce

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm
Who is online

Users browsing this forum: No registered users and 1 guest