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

[Bug] Check parsed JSON receipt if it contains the purchaseToken field for Google Play #319

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

emersonhsieh
Copy link

@emersonhsieh emersonhsieh commented Jun 15, 2020

Currently, to determine if the platform type of the receipt is Google Play, there are two cases:

  • If the receipt passed into iap.validate is an object, then the code checks if receipt.signature or receipt.purchaseToken exists.
  • If the receipt passed into iap.validate is a string, then the code first parses the receipt into an object (called parsed), then it is supposed to check if parsed.signature or parsed.purchaseToken exists.

However, for the second condition the code never checks parsed.purchaseToken, instead checking whether receipt.purchaseToken exists twice.

As a result, when a Google Play receipt string that uses service account for validation is passed into iap.validate, the package interprets it as an Amazon receipt since the receipt will not contain parsed.signature. It only contains parsed.purchaseToken, which is never checked.

@emersonhsieh emersonhsieh changed the title [Bug] Check parsed JSON receipt if it contains the purchaseToken field [Bug] Check parsed JSON receipt if it contains the purchaseToken field for Google Play receipts Jun 15, 2020
@emersonhsieh emersonhsieh changed the title [Bug] Check parsed JSON receipt if it contains the purchaseToken field for Google Play receipts [Bug] Check parsed JSON receipt if it contains the purchaseToken field for Google Play Jun 15, 2020
@nwparker
Copy link

Also ran into this, please consider merging

@dylangolow
Copy link

I also ran into this, please merge!

@timeisgolden
Copy link

timeisgolden commented Dec 11, 2020

Hello, I used google play service to validate receipt, but I got the following error.
https://appstore-sdk.amazon.com/version/2.0/verify/developer/%7BdeveloperSecret%7D/user/ undefined /purchaseToken/ undefined

{"error":{},"status":498,"message":"Invalid Purchase Token"}
the code I did is the below.
const receipt = {
"purchaseToken":"...",
"packageName":"...",
"subscription":false,
"productId":"..."
}
const item: any = await iap.validate(JSON.stringify(receipt));
I got the receipt from google,
it's weird, why I got invalid purchase token,
plz help me.
Thanks and best regards

@dylangolow
Copy link

Just so anyone following this sees, I was able to get around this by using the client email and private key option for google instead without any errors. Of course, it would still be nice to use a public key instead of this option, and the docs don't necessarily guide anyone to do this, but it works!

@timeisgolden
Copy link

timeisgolden commented Dec 11, 2020

Just so anyone following this sees, I was able to get around this by using the client email and private key option for google instead without any errors. Of course, it would still be nice to use a public key instead of this option, and the docs don't necessarily guide anyone to do this, but it works!

Thanks for your reply, I solved the problem by removing JSON.stringify().
this was my fault to add JSON.stringify() in iap.validate().
That worked for now.
Best Regards

gierschv added a commit to FlatIO/in-app-purchase that referenced this pull request Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants