Need help with PayPal URLs |
[eluser]Akinzekeel[/eluser]
I'm having a problem with the URLs that PayPal uses. It's the first time that I use PayPal with CodeIgniter, and until now everything's looking good - I turned the PayPal API into a CI library. The problem is when PayPal is linking back to my page - either because you successfully logged in to PayPal or if you clicked the "Cancel" button. PayPal is always appending a query string to my URLs which either results in a "URL contains disallowed characters" or a "Page not found" error. Example: http://example.com/order/paypal/?token=AB-1234567890ABCDEF Here's what I tried out already: - Set query-strings to ENABLED in the CI config -> seems to work but the rest of the page looks ugly because it's a mix of segment and query based URLs - Add a RewriteRule to the .htaccess -> I couldn't get this working at all - Use the URI routing features -> couldn't get this working either Does anyone have some expirience with PayPal and CodeIgniter? How did you handle this URL problem?
[eluser]Akinzekeel[/eluser]
Well I actually found a dirty workaround for this problem, however I haven't posted it here because I am still hoping that someone will come up with a better solution. Anyway, here's how I did it: 1. In your .htaccess, add an exception for "paypal" (i.e. any URL starting with paypal will not get rewritten to index.php). Example: Code: RewriteCond $1 !^(index\.php|res|robots\.txt|paypal) Code: // paypal.php Code: // paypal_cancel.php The segment-based URL in the first-line is the URL of your "success" (=paypal.php) or "cancel" (=paypal_cancel.php) page. 3. In your CI script which uses paypal, define the success and cancel URL like http://example.com/paypal.php which would then result in http://example.com/paypal.php?token=ABCD-1234567890 which will ultimately be redirected to http://example.com/order/paypal/ABCD-1234567890
[eluser]zbrox[/eluser]
I managed to do with mod_rewrite. Here is what you can try. RewriteCond %{QUERY_STRING} ^token=(.*)&PayerID;=(.*) [NC] RewriteRule ^<YOUR RETURN URL> <YOUR RETURN URL>/%1/%2? [R,NE,L]
[eluser]Akinzekeel[/eluser]
Looks promising, but how exactly does this solve the above URL problem? I'd just like to know that before changing anything in my code.
[eluser]zbrox[/eluser]
Since mod_rewrite gets the request before Codeigniter it can "translate" the url to be more codeigniter-ish With these two lines everything that paypal returns to www.yourdomain.com/custom_paypal_return_address?token=blabla&payerid=100 will be a request to www.yourdomain.com/custom_paypal_return_address/blabla/100 So you now how a first segment which is a token, and a second one which is the payer ID and no querystring tinkering.
[eluser]Akinzekeel[/eluser]
Thanks for the explanation but I was actually referring to the PayPal lib. How does the PayPal lib solve this problem? It doesn't seem to be mentioned in its user guide.
[eluser]Mat-Moo[/eluser]
Which library are you using? The ipn one is easy and data gets posted, so easy to get in CI with no url issues. |
Welcome Guest, Not a member yet? Register Sign In |