I have a really simple e-commerce in my website. It’s just a shopping cart, a table named “orders” and a integration with a payment gateway. The gateway is doing well, since when I click on “buy”, it redirects to gateway’s https website and everything is done there.
My question is: this gateway returns a status code to my website. I need to configure some urls, for example http://www.mysite.com/get-return.php, http://www.mysite.com/get-error.php and http://www.mysite.com/get-receipt.php
Problem is I’m using WordPress, so I can’t just point to a php file in my themes folder. I need to, somehow, add some logic using add_action before any headers are sent(probably I’m going to use the init hook), and make my plugin do all the implementation that http://www.mysite.com/get-return.php would do.
Is it possible to detect using add_action and the init hook, which url was being called so I could implement logic in a plugin supposing http://www.mysite.com/get-return.php exists, and don’t return a 404 to it’s caller?
You can detect the URL being called from any PHP file (whether it is being run directly or being included in another file) using
$_SERVER['REQUEST_URI']. This will give you the URL before any sort of rewriting was applied. Just a note, it won’t include the domain as part of the URL, just the path (ie,/get-return.php).