Hi
I have a problem with the POST method for receiving data after the transaction. I use Tpay online bank for payments, and it gives notification as POST array parameters to the server.
But when I use this code:
export function put_myFunction(request) {
let options = {
"headers": {
"Content-Type": "application/json"
}
};
// get the request body
return request.body.json()
.then( (body) => {
// update the item in a collection
return wixData.update("myCollection", body);
} )
.then( (results) => {
options.body = {
"inserted": results
};
return ok(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}
I get this error from Tpay:
{"ERROR":{"name":"JsonSyntaxError","errorGroup":"User"}}
Tpay has some code example on PHP:
// Check IP address and POST parameters
$ipTable = array('195.149.229.109', '148.251.96.163', '178.32.201.77',
'46.248.167.59', '46.29.19.106', '176.119.38.175');
if (in_array($_SERVER['REMOTE_ADDR'], $ipTable) && !empty($_POST)) {
$sellerID = $_POST['id'];
$transactionStatus = $_POST['tr_status'];
...
$md5sum = $_POST['md5sum'];
// check transaction status
if ($transactionStatus=='TRUE' && $error=='none') {
/* Stuff */
if ($allOk) {
/* Stuff */
echo 'TRUE';
} else {
echo 'FALSE - ...'; // describe your error
}
} else {
// Transaction processed with error but handled by merchant system
echo 'TRUE';
}
} else {
echo 'FALSE - Invalid request';
}
I guess the problem might be because Tpay sends Array instead of Json, but I can’t find any example on Corvid to process it. I will be thankful for any help.