Http-functions - get_myFunction, ending with http 404 error

I am calling my payment gateway API for payment processing and than receiving below url in return:

https://www.quickdelivery.co.nz/_functions/payStation?ms=Quick-Delivery2020-06-10T05%3A45%3A17.798Z&ti=0140482787-01&am=100&ec=0&em=Transaction+successful

I have setup " https://www.quickdelivery.co.nz/_functions/payStation " as my endpoint in http-functions.js

import { ok, notFound, serverError } from ‘wix-http-functions’;
import { created, badRequest } from ‘wix-http-functions’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
import * as CryptoJS from ‘public/crypto-js.js’

export function get_payStation(request) {
let returnoptions = request.split(“&”);
let ms = returnoptions[0];
let ti = returnoptions[1];
let am = returnoptions[2];
let ec = returnoptions[3];
let em = returnoptions[4];
console.log(returnoptions)
console.log(request.value)
console.log(“we are in paystation repsonse”)
let paymentgwyid = “PayStation”

let options = {
“method”: “get”,
“headers”: {
“Content-Type”: “application/json”
}

};
return request.body.text()
.then((body) => {
console.log(“Body returned from paystation”, body)

if (ec === 0) {
wixLocation.to(‘https://www.quickdelivery.co.nz/thankyou’)
} else {
wixLocation.to(‘https://www.quickdelivery.co.nz/error’)
}
})
}

I am able to successfully make the payment at my payment gateway site and while returning it is failing with http 404 error. Please let me know, if I am doing something wrong here?

You will need to check with the service provider to determine what the problem is.

@yisrael-wix , thanks for your reply.

If I provide a web page details instead of http end point than it is working fine.

e.g. rather than the end point, if I provide a dynamic return address to my service provider as " https://www.quickdelivery.co.nz/thankyou ". it will route me to webpage with below url :

https://www.quickdelivery.co.nz/thankyou?ms=Quick-Delivery2020-06-10T07%3A33%3A47.521Z&ti=0140489508-01&am=100&ec=0&em=Transaction+successful

Below is my client side code snippet:

import wixWindow from 'wix-window';
import wixData from "wix-data";
import { local, session, memory } from 'wix-storage';
import { autocomplete } from 'backend/gmapsapi';
import { details } from 'backend/gmapsapi';
import { reverse } from 'backend/gmapsapi';
import { distance } from 'backend/gmapapi';
import wixBookings from 'wix-bookings';
import { payStation } from "backend/paystation";
import wixLocation from 'wix-location';


$w.onReady(function () {
 //TODO: write your page related code here...

});
let paystationresp = wixLocation.query;
console.log ("Paystation return URL", paystationresp);
export function paystation_click(event) {
 //Add your code for this event here: 

 let amount = 1 * 100;
 let dt = new Date();
 let merchatref = "Quick-Delivery" + dt.toISOString()
 var d = Date.now();
 var unix = Number(d) / 1000;
 var time = Math.round(unix); //get the current time in seconds
 let pstnBody = "paystation=_empty" +
 "&pstn_nr=t" +
 "&pstn_pi=617051" +
 "&pstn_gi=DEVELOPMENT" +
 "&pstn_ms=" + merchatref +
 "&pstn_am=" + amount +
 "&pstn_rf=JSON" +
 "&pstn_cu=NZD" +
  "&pstn_du=https://www.quickdelivery.co.nz/thankyou";
 let pstnurl = generateHMACUrl(pstnBody) + "&pstn_du=https://www.quickdelivery.co.nz/thankyou";
    console.log("PSTN STRING",pstnBody)
    console.log("Unique Pstn_MS value", merchatref)
    console.log("Unix timestamp",time)
    payStation(pstnBody,pstnurl)
        .then((response) => {
            console.log("response form paystation API", response)
            response = JSON.parse(response);
            console.log("response form paystation API after parsing", response)
 var pstranID = null;
            pstranID = response.InitiationRequestResponse.PaystationTransactionID;
            console.log("Paystation transaction id", pstranID)
 if (pstranID.length !== 0) {
 //if (response.InitiationRequestResponse.PaystationTransactionID.length !== 0) {
                console.log("Positive response from Paystation");
 let url = response.InitiationRequestResponse.DigitalOrder
                console.log("PAYSTATION URL", url)
                wixLocation.to(url);

 //  let spliturl = url.split( ? );

            } else {
                console.log("failed test")
            }
 // let retpst = psReturn.toString();
 // console.log("we are calling paystation")
 // console.log(retpst)
        })
 //payStation(merchatref, amount).then(function (resp) {

}

@erramanece The wix-location.to() API is only available in the frontend, and will not work in backend code.

@yisrael-wix Thanks.

Any other way to open a webpage from backend?

@yisrael-wix , but it is still failing with 404, even after removing wix-location.to()

@erramanece For some reason your server code is unable to find the requested service. You’ll need to carefully debug your http-functions.

As far as opening a webpage from the backend, it can’t be done. However, you can have your backend payStation ( pstnBody , pstnurl ) function return something like true (for success). Then, when payStation () returns, you can call wixLocation.to() in the frontend.

@yisrael-wix Yes. I am not able to figure out till now. :frowning: