From 1990cd875fe26da7d9456d518a2936ef2a7a0ed9 Mon Sep 17 00:00:00 2001 From: Jonathan Ohlsson Date: Thu, 12 Mar 2020 10:50:02 +0000 Subject: [PATCH 1/2] fix: make sure request defaults are passed to GoogleAPI --- lib/google.js | 4 ++-- lib/googleAPI.js | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/google.js b/lib/google.js index 57ca3d84..823cf985 100644 --- a/lib/google.js +++ b/lib/google.js @@ -109,9 +109,9 @@ module.exports.readConfig = function (configIn) { } // googleServiceAccount { client_email, private_key } from Google API service account JSON file - if (config.googleServiceAccount) { + if (configIn.googleServiceAccount) { useGoogleApi = true; - googleApi.config(config.googleServiceAccount); + googleApi.config(configIn); } }; diff --git a/lib/googleAPI.js b/lib/googleAPI.js index a6ef57a2..1c294749 100644 --- a/lib/googleAPI.js +++ b/lib/googleAPI.js @@ -28,15 +28,21 @@ module.exports = { validatePurchase: validatePurchase }; -function config(_conf) { - if (!_conf.clientEmail) { +function config(inConfig) { + var serviceAccount = inConfig.googleServiceAccount; + + if (!serviceAccount.clientEmail) { throw new Error('Google API requires client email'); } - if (!_conf.privateKey) { + if (!serviceAccount.privateKey) { throw new Error('Google API requires private key'); } - conf.clientEmail = _conf.clientEmail; - conf.privateKey = _conf.privateKey; + conf.clientEmail = serviceAccount.clientEmail; + conf.privateKey = serviceAccount.privateKey; + + if (inConfig.requestDefaults) { + request = request.defaults(inConfig.requestDefaults); + } } /** @@ -170,11 +176,11 @@ function _getValidationUrl(receipt, token) { switch (receipt.subscription) { case true: url = SUBSCR_VAL; - break; + break; case false: default: url = PRODUCT_VAL; - break; + break; } return util.format( url, From ac0f0a4d3d5a34ade966ed8f56151c0063f39caa Mon Sep 17 00:00:00 2001 From: Jonathan Ohlsson Date: Mon, 16 Mar 2020 14:32:45 +0000 Subject: [PATCH 2/2] feat: more logging information --- lib/googleAPI.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/googleAPI.js b/lib/googleAPI.js index 1c294749..25ea2932 100644 --- a/lib/googleAPI.js +++ b/lib/googleAPI.js @@ -41,6 +41,7 @@ function config(inConfig) { conf.privateKey = serviceAccount.privateKey; if (inConfig.requestDefaults) { + verbose.log(NAME, 'Setting request defaults:', { requestDefaults: inConfig.requestDefaults }); request = request.defaults(inConfig.requestDefaults); } } @@ -99,6 +100,7 @@ function validatePurchase(_googleServiceAccount, receipt, cb) { json: true }; request(params, function (error, res, body) { + verbose.log(NAME, 'Response:', { error, res: res.toJSON(), body }); if (error) { return cb(error, { status: constants.VALIDATION.FAILURE, message: body }); } @@ -160,6 +162,7 @@ function _getToken(clientEmail, privateKey, cb) { }; verbose.log(NAME, 'Get token with', clientEmail, '\n', privateKey); request(params, function (error, res, body) { + verbose.log(NAME, 'Response:', { error, res: res.toJSON(), body }); if (error) { return cb(error); }