开发者

How to create a “return” url for a payment gateway?

开发者 https://www.devze.com 2023-01-26 13:36 出处:网络
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\"

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 st开发者_如何学Goatus code to my website. I need to configure some urls, for example www.mysite.com/get-return.php, www.mysite.com/get-error.php and 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 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 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).


My question is: this gateway returns a status code to my website. I need to configure some urls, for example www.mysite.com/get-return.php, www.mysite.com/get-error.php and www.mysite.com/get-receipt.php

You can still do this in by following way

you can create a php file in you theme folder as a template file. which will contain following code at the top

<?php
/*
Template Name: Some name
*/
//your dynamic stuff here
?>

It will create a template for you and you can use this file as

create one page from the admin site of wordpress and assign this template to that page.

and whenever you hit the paramalink of this page it will execute your template file from your theme folder.

Thanks.

0

精彩评论

暂无评论...
验证码 换一张
取 消