Skip to content
Open
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
19 changes: 10 additions & 9 deletions lib/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ module.exports.validatePurchase = function (dPubkey, receipt, cb) {
receipt.data = receipt.receipt;
}

if (!receipt.data || !receipt.signature) {
var tokenMap = {
clientId: googleTokenMap.clientID,
clientSecret: googleTokenMap.clientSecret,
refreshToken: googleTokenMap.refreshToken
};

if (!receipt.data || !(receipt.signature || (tokenMap.clientId && tokenMap.clientSecret && tokenMap.refreshToken))) {
verbose.log(NAME, 'Failed: missing receipt content');
return cb(new Error('missing receipt data:\n' + JSON.stringify(receipt)), {
status: constants.VALIDATION.FAILURE,
Expand All @@ -174,11 +180,6 @@ module.exports.validatePurchase = function (dPubkey, receipt, cb) {
}

var pubkey = publicKeyMap.live;
var tokenMap = {
clientId: googleTokenMap.clientID,
clientSecret: googleTokenMap.clientSecret,
refreshToken: googleTokenMap.refreshToken
};

// override pubkey to allow dynamically fed public key to validate
if (typeof dPubkey === 'string') {
Expand Down Expand Up @@ -283,20 +284,20 @@ function isSubscription(receipt) {
if (typeof receipt === 'string') {
try {
receipt = JSON.parse(receipt);
return receipt.data && receipt.data.autoRenewing !== undefined;
return receipt.isSubscription || (receipt.data && receipt.data.autoRenewing !== undefined);
} catch (error) {
return false;
}
}
if (typeof receipt.data === 'string') {
try {
receipt.data = JSON.parse(receipt.data);
return receipt.data && receipt.data.autoRenewing !== undefined;
return receipt.isSubscription || (receipt.data && receipt.data.autoRenewing !== undefined);
} catch (error) {
return false;
}
}
return receipt.data && receipt.data.autoRenewing !== undefined;
return receipt.isSubscription || (receipt.data && receipt.data.autoRenewing !== undefined);
}

function validateProduct(receipt, tokenMap, cb) {
Expand Down