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

Invalid Purchase Token #349

Open
desmeit opened this issue Aug 6, 2021 · 3 comments
Open

Invalid Purchase Token #349

desmeit opened this issue Aug 6, 2021 · 3 comments

Comments

@desmeit
Copy link

desmeit commented Aug 6, 2021

I try to validate with firebase cloud functions. Apple is working well but with Android I get an error. This is my functions code:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const iap = require("in-app-purchase");
admin.initializeApp(functions.config().firebase);

exports.validateReceipt = functions.https.onCall(async (data, context) => {
  const test = data.test;
  iap.config({
    appleExcludeOldTransactions: true,
    applePassword: "XXX",
    googleServiceAccount: {
      clientEmail: "XXX@api-project-XXX.iam.gserviceaccount.com",
      // eslint-disable-next-line max-len
      privateKey: "-----BEGIN PRIVATE KEY-----XXX----END PRIVATE KEY-----\n",
    },
    test: test, // For Apple and Googl Play to force Sandbox
    verbose: true, // Output debug logs to stdout stream
  });
  const receipt = data.receipt;
  await iap.setup();
  const validationResponse = await iap.validate(receipt);
  const purchaseData = iap.getPurchaseData(validationResponse);

  return {response: purchaseData};
});

this is my receipt at flutter:

var receipt = json.encode({
                'purchaseToken': 'XXX',
               'packageName': 'com.XXX.app',
                'productId': 'XXX',
                'subscription': false,
});

I get the following error: Unhandled error

<Amazon> Validation failed: { status: 498, message: 'Invalid Purchase Token

and it seems to check the receipt against Amazon and not against Google. What am I doing wrong?
#219 was not helping.

@tgreco
Copy link

tgreco commented Sep 14, 2021

I'm having the same issue.

@desmeit
Copy link
Author

desmeit commented Sep 15, 2021

The issue comes when something is wrong with the JSON.

@henriqueArrazao
Copy link

I'm not sure what the type the json.encode returns but I guess It's returning a string. Try to remove it and maintain only the object, without the json.encode()

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

No branches or pull requests

3 participants