Error with Paypal Auto-Return URL

@clavaque I worked on this issue some more tonight and developed a workaround that is currently working for me, insert at line 105 of s2member/src/includes/classes/paypal-return-in.inc.php:

sleep(3);
wp_redirect( home_url( preg_replace( '`(&do_not_cache=[0-9]{5}){2,}`', '&do_not_cache=' . rand(10000,99999), $_SERVER["REQUEST_URI"] . '&do_not_cache=' . rand(10000,99999) ) ) );
exit;

Not an ideal solution but seems to work after a few redirects, which are aren’t visible to anyone. You actually stay on PayPal’s “Please Wait…” screen until s2Member gets a good response from PayPal.

I would have posted the zipped PHP file but my account is too new to allow file uploads.

Anyways, there seems to be a timing issue with PayPal having the subscription finalized before s2Member requests subscription details.

3 Likes

Nice Josh! Thanks for the hack. :slight_smile:

I’m sorry I haven’t gotten back to this one yet. Juggling a bunch of things at the moment, but making good progress too.

1 Like

Sorry for a stupid question - does the added code need indenting?
Or is it ok like this http://oi64.tinypic.com/bgpoyg.jpg

(EDIT - Thats as it appears in cPanels code editor)

What you have is just fine, no indenting required.

1 Like

Hi Josh,

Thank you for posting this. I tested it first in Microsoft Edge, and it hung there for a while and finally timed out saying it couldn’t reach the page. Tried the same thing in Chrome, and that timed out saying “too many redirects”, but then it jumped to the success page a few seconds later. This site is not live yet, and I’ve been testing with the Paypal Sandbox. Is it safe to assume there is no difference from the live site (regarding this error)?

Thanks again,
-Ben

I couldn’t say whether or not this issue exists on the PayPal sandbox. I’m only working in a live environment since that is where my client’s issue has been occurring. I would suggest leaving my code snippet out and generate s2Member debug logs while using the PayPal sandbox and live APIs and see what the auto-return responses look like, then go from there.

If you think the sandbox may need even more time to ready a proper auto-return response you can up the number of sleep seconds – Chrome seems to have a redirect limit of 20; 20 x 3 = 60 seconds + network & script execution time; if those ~60 seconds isn’t enough time then you will get the behavior you experienced.

PayPal sandbox is broken, years ago, never use it. Set amount to $0.01 and test on life environment. Then cancel your tests, if you wish.

1 Like

Josh, I agree with Krum that the PayPal sandbox is not the best for testing, sadly. Do live transactions, even if they’re cents. Here’s an old video I made on that:

I have made several tests these days, and still haven’t managed to reproduce this error, so it’s being quite difficult to troubleshoot. I’m not giving up, though.

In the meantime, there was a tip shared in a separate thread related to this error, that seems to have prevented the error from happening for him, so I’m quoting it here for you guys to try in the meantime. Hopefully it’ll work for you too.

Quick question for my troubleshooting: do you get that error with every purchase, or only some? Is it when paying logged into a PayPal account, or when paying with a card without logging into PayPal, or both? I’m just trying to find more factors that may be playing a part in this… If you have any new details from any new times the error message is shown, please let me know, it may hold a clue. Thank you! :slight_smile:

I cannot find the “Auto-Return Page Template (optional customizations)” under “PayPal Options > PayPal PDT/Auto-Return…”

Its just not there to be customised

You can find it here:

Click on the optional customizations link to expand that block of text.

Christian, it not there… when I go in to paypal pdt/auto return integration all I have is :

More Information (click here)
Quick Tip: In addition to the default Auto-Return/PDT configuration inside your PayPal account, the Auto-Return URL is also set on a per-transaction basis from within the special PayPal Button Code that s2Member provides you with. In other words, if you have multiple sites operating on one PayPal account, that’s OK. s2Member sets the Auto-Return URL (dynamically) for each transaction. The result is that the Auto-Return URL configured from within your PayPal account becomes the default, which is then overwritten on a per-transaction basis by the s2Member software.

my paypal pdt identity token is there along with the auto return url, however the section at the bottom Auto Return page template (optional customisation) is just not there.

its probably an s2member PRO feature… I’m running the free one at the moment

You are absolutely right. I had not looked at the Framework alone for so long, that I missed it. Yes, it’s a Pro feature.

The documentation there even starts by saying “With s2Member Pro installed, you have…” lol. I just opened the box to take the screenshot and didn’t read. Sorry about that.

no worries. What if we were disable the auto return to website feature… Would this be possible?

that error is a real turn off for paying customers… right now I wouldn’t even mind if the auto return directed to somebody else’s website…lol… but that error frightens customers to question their purchase.

So basically… when paypal is done taking payment, it tells s2member its done, but s2member is not ready tell the customer (because it is still processing the info) that they have successfully paid so they can register… this is what I think the issue is in plain English.

It had never occured to me, I haven’t tested it myself. s2Member would still get the IPN from PayPal, which would trigger the signup email, if I’m not mistaken. The user would need to click the link at PayPal to come back, it wouldn’t happen by itself, and then he may not get a cookie set to signup with the paid access right then, but the signup link he gets by email would be fine.

I’ll go do a test with this now, to verify the behavior. Feel free to test it yourself, not just for the behavior, but to see what you get in the logs for the transaction. The user wouldn’t see the error message, that I’m pretty sure of. I’ll be back in a mooment after trying removing the auto-return URL from my setup.

Yeah, that error should not be there at all when the custom value is the correct one…

so where exactly should I disable the auto return feature? in paypal? or is there a particular area in s2member i need to go to to disable it?