Hi, I am processing payment from a financial service provider. It is independent of my Wix’s website setup. However, once the payment is done, the payment website send the user back to Wix using POST method. But I am getting a 403 error. I guess I have to create a POST endpoint that when activated, redirects the user to the page I want.
How can I create a endpoint for the payment website to redirect to once it is done. It must be POST.
This is the response I got from my payment provider:
redirection url only should be on server site language i.e java,php, python, java script etc,
Right now, I have set it to www. thecaninecompany. in/order-success. But since it is a static web page, I am getting 403 error. I need something like www. thecaninecompany. in/payment-response.js, accepting POST response, which we will then redirect to the above url.
It’s not so easy to understand from your description what’s going on there.
Did the 3rd party ask you to provide a URL for the final post response? What is in the post response body?
The user clicks a button on my website and I send the user to my payment service provider.
The payment is done by the user and I have set an URL to redirect the user to once the payment has been completed.
Now, my payment service provided actually makes a POST request to the URL I have provided. I think they send some response but that’s irrelevant. I don’t need any action based on the response.
The payment company said that the “redirection url only should be on server site language i.e java,php, python, java script etc,” like xyz. com/abc.js which accepts the POST request.
So after receiving the response, I want to redirect my user to www. thecaninecompany. in/order-success.
In simple term, once the payment is done, the payment provider makes a POST request to my provided URL, and I expect my provided URL to redirect to www. thecaninecompany. in/order-success since I can not directly input this address for 403 error because this page expects a GET request.
Thank you!
@jonatandor35 Hi, yes I’ve tried it. Im getting a 403 error. The payment service provider specifically said I have to give an endpoint that accepts POST request. What’s your suggestion regarding this?
@thecaninecompanyin Sorry. I really don’t think I understand what’s going on there. Maybe they asked you to return a final page URL after the post? Maybe it’s like a form submit that can just open any webpage? Or maybe I’m just missing something.
@jonatandor35 Please let me try it this way:
I need a end point on my wix website something like thecaninecompany .in/abc which accepts a POST request from any client and then when a request is made it run some functions.
J.D. is right, you should use http-functions. And you will prob. have to return a 200/ok if all is well. Returning nothing can lead to awkward results, it depends on implementation.
EDIT: look at the provider’s docs. I have worked with interfaces where they expected the strangest things, like always returning a 200/ok, but if error, the error was expected to be included inside the returned (200/ok) object.
@jonatandor35 I just made some changes and it is working now, but not fully.
I was using wix-location so that’s why I was getting a 404 error (found it in the website log). I removed the wix-location code, and it is working now.
Now, since I cannot use Wix Location, I was wondering how can I redirect the user? I tried setting a location element in header to the URL I want the user to redirect to, but it is not working.
In simple terms, I have a function abc and I want the function to redirect the user to another web page on my website. How is this possible?
@thecaninecompanyin if you’re talking about redirecting from a webpage and not about post requests to the backend, you can either create a router page and redirect or use wix-location.
If you’re talking about post request to the backend it’s obviously irrelevant.
Hi, this is the function in my backend. It is being called perfectly. I need to redirect the user when the task is done. In the function, I have mentioned a comment line saying when I need to redirect the user. The link to redirect is also mentioned in line #7 with location:.
Should I try to implement router logic?
import { ok, notFound, serverError, badRequest } from 'wix-http-functions';
import wixData from 'wix-data';
export function post_myResponse(request) {
const response = {
"status" : 301,
"headers": {
"Content-Type": "application/json",
"Location" : "https://www. thecaninecompany. in/order-success"
}
};
const today = new Date();
let currentTimestamp = today.toLocaleDateString() + " " + today.toLocaleTimeString();
let toInsert = {
"response" : request.headers,
"timestamp" : currentTimestamp
};
wixData.insert("OrderResponse", toInsert);
//Redirect user now
return ok(response);
}
I don’t think that can work. You do things in the backend, but you can’t open the browser and redirect to a page.
You can use wix-router to redirect from a certain URL to another, but not with http post request.
@jonatandor35 I tried working with wiz-router but I am facing the basic problem. It accepts a GET request only. And, my payment service provider makes a POST request. So, with router, I am getting a 403 error.
Can I do something like this:
Use the Http function (which is working). And, in the response body, either do one of the following:
Use an iframe and run a script inside to redirect the user.
Show a small button which when clicked redirects the user to my URL.
I am not sure how can I integrate the button or the iframe inside the response body. Is it possible?
@thecaninecompanyin since the http-functions.js is a backend file, I don’t think you can do either of these.
I’ll ask again: if you provide them a URL of a regular webpage. are you sure it doesn’t work? Have you tried it?
If the answer is negative then the solution to your question is beyond my knowledge (I’m not even sure I fully understand the situation), and you should ask one of the experts.