Welcome Guest, Not a member yet? Register   Sign In
Need help with PayPal URLs
#1

[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?
#2

[eluser]zbrox[/eluser]
Just to chime in, I am having the same difficulties.
#3

[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)
2. Create two new files in the root directory (where your index.php is located) called "paypal.php" and "paypal_cancel.php" and insert the following PHP code:
Code:
// paypal.php
$url = $_SERVER["SERVER_NAME"].'/order/paypal/'.$_GET['token'];
header("Cache-Control: max-age=0, must-revalidate");
header("Location: http://$url", TRUE, 301);

Code:
// paypal_cancel.php
$url = $_SERVER["SERVER_NAME"].'/order/cart/'.$_GET['token'];
header("Cache-Control: max-age=0, must-revalidate");
header("Location: http://$url", TRUE, 301);

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
#4

[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]
#5

[eluser]InsiteFX[/eluser]
Search the forums for PayPal lib.

InsiteFX
#6

[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.
#7

[eluser]zbrox[/eluser]
Since mod_rewrite gets the request before Codeigniter it can "translate" the url to be more codeigniter-ish Smile
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. Smile
#8

[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.
#9

[eluser]zbrox[/eluser]
Sorry, my bad Smile
#10

[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.




Theme © iAndrew 2016 - Forum software by © MyBB