Does anymore knows how I can make https request from within firebase functions.https.onRequest? I have written the code shown below but It keeps throwing an error:
Error: getaddrinfo ENOTFOUND test.oppwa.com test.oppwa.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
My code is as follow:
exports.MyTestFunction = functions.https.onRequest((req, res) => {
var path = '/v1/checkouts';
var data = querystring.stringify({
'authentication.userId' : '8a8294174b7ecb28014b9699220015cc',
'authentication.password' : 'sy6KJsT8',
'authentication.entityId' : '8a8294174b7ecb28014b9699220015ca',
'amount' : '92.00',
'currency' : 'EUR',
'paymentType' : 'DB',
'shopperResultUrl' : 'my.app://custom/url',
'notificationUrl' : 'http://www.example.com/notify'
});
var options = {
port: 443,
hostname: 'test.oppwa.com',
path: path,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': data.length
}
};
var postRequest = http.request(options, function(res){
console.log('statusCode: ', res.statusCode);
console.log('headers: ', res.headers);
res.setEncoding('utf8');
res.on('data', function (chunk) {
jsonRes = JSON.parse(chunk);
console.log('Data Response 1: ', jsonRes);
return callback(jsonRes);
});
res.on('error', (error)=> {
console.error('ERROR: ', error)
});
});
postRequest.write(data);
postRequest.end();
}