Node.JS Code Examples
Authorisation String
// Get current time in GMT.
const date = new Date();
const utcDate = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
// Create timestamp in 'YYYYMMDDHHmmss' format. E.g. 20190812055213
const timestamp = format(utcDate, 'YYYYMMDDHHmmss')
// Concatenate the values for channels, currencies, total and your timestamp in that order.
const bookingVars = {
channels: 2,
currencies: 'USD',
total: 9999,
timestamp: timestamp
}
let string = []
for (const key in bookingVars) {
string.push(bookingVars[key])
}
string = string.join('&')
// SHA256 the string.
const encode = crypto.createHash('sha256').update(string).digest('hex')
// Fetch your channel secret and concatenate to string.
const { CHANNEL_SECRET } = process.env
const authString = crypto.createHash('sha256').update(
Buffer.concat([
new Buffer(encode),
new Buffer(CHANNEL_SECRET)
])
).digest('hex')
// Concatenate with timestamp.
const appAuthString = authString + timestamp;