The current toISOString() javascript function does not supply the correct format that is required for the auth/payment flow header "request-time" field. How do I implement the correct format for my API request in JavaScript?
The current toISOString() javascript function does not supply the correct format that is required for the auth/payment flow header "request-time" field. How do I implement the correct format for my API request in JavaScript?
You can use the this function that transforms the date to the correct format for your use.
function dateToLocalISO(date) {
const off = date.getTimezoneOffset()
const absoff = Math.abs(off)
return (new Date(date.getTime() - off*60*1000).toISOString().substr(0,23) +
(off > 0 ? '-' : '+') +
Math.floor(absoff / 60).toFixed(0).padStart(2,'0') + ':' +
(absoff % 60).toString().padStart(2,'0'))
}
If you are using javascript to make the requests to the backend server you can also make use of the luxon npm package
import {DateTime} from 'luxon';
const requestTime = DateTime.local().toISO();
It will provide it in the correct ISO format. Luxon Documentation on toISO