hi
I have data posted to my http-functions,js and I inserted into my collection, and this collection has fields “encryptedpaymentId”. I used this field to create a dynamic page , that have name ,amount,txnid ,TxnMessage , and this Dyanmic page works fine Shows all feilds after successful payment, but I can open this page manually, But I want to redirect to this Dynamic page after inserting data through http-function.js file , Is there any way to send user to this dynamic page after inserting data.
import {ok, badRequest} from 'wix-http-functions';
//import wixLocation from 'wix-location
import {created, serverError} from 'wix-http-functions';
import wixData from 'wix-data';
const serializeToJSON=str=>
str.split('&')
.map(x => x.split('='))
.reduce((acc, [key, value]) => ({
...acc,
[key]: isNaN(value) ? value : Number(value)
}), {})
export async function post_addpayments(request) {
let options = {
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"key":"----"
}
};
return request.body.text()
.then( (body) => {
var str = body.toString()
var lp = str.slice(9,str.length)
var lolo =decodeURIComponent(lp)
var opo = serializeToJSON(lolo)
let recordInsert = {
"title": opo.encryptedPaymentId,
// http//mydomain/status/{opo.encryptedPaymentId} I want to redirect to this dynamic page after inserting data to collection, but I cant redirect as
wix-Location is not supported on backend code
//
"firstname": opo.firstname,
"amount": opo.amount,
"phone": opo.phone,
"txnid": opo.txnid,
"addedon": opo.addedon,
"hash" : opo.hash,
"txnMessage" : opo.txnMessage,
"txnStatus" : opo.txnStatus
}
return wixData.insert("paymentrecords", recordInsert);
} )
.then( (results) => {
options.body = results
return created(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}
If you are using http functions, then that means that the user isn’t even on a page of the site - they are posting remotely via your exposed API. That means there isn’t really isn’t anywhere to where they can redirect.
I can post payment details to wix page “https;//mywixdomain/mywixPage” (but it says 403 forbidden) , if wix page receives posted payment details .then is there any way to insert that data into my collection other than http-function or I can use send data to httpfunction file through my wix page and then redirect to my Dynamic Payment Success page (““https;//mywixdomain/mywixSuccessPage/{encryptedPaymentId }””) which uses collection data , On wix page wixLocation is Supported so I can redirect it to my Dynamic success Page
I used above method that you mentioned , before for generate pdf on button click ,it works fine .
But in above Scenario , Payment page (extermal page ) posted variables to Surl and furl , and that surl is my wix page “https;//mywixdomain/mywixPage” and after successfull payment it redirect it wix page “https;//mywixdomain/mywixPage” , but wix page returns 403 forbidden , I checked this page console and network and it is recieving posted variables , But I can’t find any way to use this posted variables , on my wix page code , http-functions can recieve the request(recieve posted variables ) that is why i was using http-function.js for inserting posted variables in my collection , for that my surl is “https;//mywixdomain/_functions/addpaydetails” but after successfull payment it redirected to “https;//mywixdomain/_functions/addpaydetails” which is not a page .