Skip to content

Invalid Purchase Token #349

@desmeit

Description

@desmeit

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions