Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure request defaults are passed to GoogleAPI #307

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
23 changes: 16 additions & 7 deletions lib/googleAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ 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) {
verbose.log(NAME, 'Setting request defaults:', { requestDefaults: inConfig.requestDefaults });
request = request.defaults(inConfig.requestDefaults);
}
}

/**
Expand Down Expand Up @@ -93,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 });
}
Expand Down Expand Up @@ -154,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);
}
Expand All @@ -170,11 +179,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,
Expand Down