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

Remove signature requirement & add isSubscription to receipt #142

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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