voltrue2 / in-app-purchase

A Node.js module for in-App-Purchase for iOS, Android, Amazon and Windows.
http://iap.gracenode.org
Other
1.05k stars 289 forks source link

Unity iAP google subscription validation failure #306

Closed bilalsha closed 4 years ago

bilalsha commented 4 years ago

my Android receipts seem to be detected as Amazon purchases. I don't even have Amazon set up in the config section.

Here is my iap.config with real values removed:

const config = { verbose: true, test: true, requestDefaults: { //apple settings appleExcludeOldTransactions: true, applePassword: 'secret', googleServiceAccount: { clientEmail: 'email, privateKey:'key', }, googleRefToken: 'token', googleClientID: 'id', googleClientSecret: secret', // Configurations all platforms test: true, // For Apple and Googl Play to force Sandbox validation only verbose: true, // Output debug logs to stdout stream }, }

Here is the code for validation:

const validatePurchase = async (receipt, clientName) => { iap.config(config); await iap.setup(); if (clientName === 'ios') { const validatedData = const validatedData = iap.validate(googleRecepit);; return validatedData; } else if (clientName === 'android') { const googleRecepit = { data: { packageName: 'name', productId: 'id', purchaseToken: receipt, subscription: true, }, }; const validatedData = iap.validate(googleRecepit); console.log(validatedData ${validatedData}); return validatedData; } };

error I got on google play store recepit

[1583388783017][VERBOSE] test mode? true [1583388783018][VERBOSE] test mode? true [1583388783021][VERBOSE] Validate: https://appstore-sdk.amazon.com/version/2.0/verify/developer/{developerSecret}/user/undefined/purchaseToken/undefined { data: { packageName: 'name', productId: 'id', purchaseToken: 'token', subscription: true } } [1583388784450][VERBOSE] Validation failed: { status: 498, message: 'Invalid Purchase Token' } { error: {}, status: 498, message: 'Invalid Purchase Token' } Error: Invalid Purchase Token

ramirobg94 commented 4 years ago

+1 i have the same problem here it looks related with https://github.com/voltrue2/in-app-purchase/issues/219

bilalsha commented 4 years ago

The issue is with the config. we need to put google or any account info in config object instead of requestDefaults. In documentation it is confusing as it look like that we need to put it in requestDefaults until we scroll from and saw that we need to put info in config object

const config = { // Configurations all platforms test: process.env.APPLE_IAP_TEST == 'true' ? true : false, // For Apple and Googl Play to force Sandbox validation only verbose: process.env.APPLE_IAP_VERBOSE, // Output debug logs to stdout stream //apple settings appleExcludeOldTransactions: true, applePassword: process.env.APPLE_IAP_SECRET, //google setting googleServiceAccount: { clientEmail: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL, privateKey: privateKey, }, };

mifi commented 4 years ago

I had the same issue. Turns out if you call validate with an object, and the object does not contain purchaseToken or signature, then it defaults to amazon. May have been better to throw an error in that case.

See https://github.com/voltrue2/in-app-purchase/blob/e966ee1348bd4f67581779abeec59c4bbc2b2ebc/index.js#L72