3

So here's the thing - I have a node.js backend server for my Android App. I am using the Google Play billing library, and using the backend to verify the purchase as google Docs recommend.

Now, all the other answers out there regarding this error seem to refer to a consistent problem.

My backend SOMETIMES verifies, and SOMETIMES comes back with this as an error, indicating that in fact, my service account IS linked (as shows up in my consoles).

I tried two different 3rd party libraries, and I have the same issue. Sometimes one will respond with verification success, while the other will say my account is not linked. Sometimes they are both negative, sometimes both positive.

It seems inconsistent.

var platform = 'google';
        var payment = {
            receipt: purchaseToken, // always required  ... this is google play purchaseToken
            productId: subID,  // my subscription sku id
            packageName: 'com.xxxxxx', // my package name
            keyObject: key,  // my JSON file
            subscription: true, // optional, if google play subscription

        };



   var promise2 = iap.verifyPayment(platform, payment, function (error, response) {
        /* your code */
        if (error) {
            console.log('error with iap, ' , error);
            return true;
        } else {
            console.log('success with iap, response is: ', response);
            return true;
        }
    });

I also tried with a different library, got same results:

var receipt = {
            packageName: "com.xxxx",
            productId: subID,  // sku subscription id
            purchaseToken: purchaseToken // my purchase token
            };

            var promise = verifier.verifySub(receipt, function cb(err, response) {
                if (err) {
                    console.log('within err, was there a response? : ', response); 
                console.log('there was an error validating the subscription: ', err);
                //console.log(err);
                return true;
                } else {
                console.log('sucessfully validated the subscription');
                // More Subscription info available in “response”
                console.log('response is: ', response    );
                return true;
                }
               });


// return promises later.

Any else experience this issue?

Jeff Padgett
  • 2,380
  • 22
  • 34

1 Answers1

12

TLDR; Create a new product ID.

I eventually found the answer. The problem was not with my code, or with permissions in the Google Developer Console OR the Google Play Console. Everything was set up correctly except for one thing.

Previously, before setting up Test License Accounts in Google Play Console, I had made an actual Subscription purchase with real money on my productID "X".

Then, after adding the same google account that bought the subscription as a test user, I continued to test results on the same subscription, productID "X".

Even though I had cancelled the REAL purchase, the actual expiration date was not for another month.

Therefore, I believe sometimes Google was getting confused when I would buy/cancel the purchase - confusing the test subscription with the real subscription.

Creating a new Product ID, and only using that, solved my problem, and purchases are verified consistently.

Jeff Padgett
  • 2,380
  • 22
  • 34
  • Thanks, I lost a couple of days as well. Glad it helped! – Jeff Padgett Sep 26 '18 at 15:36
  • Creating a new Product worked. Another day lost here... Thanks Google! – Doru Pîrvu Sep 27 '18 at 13:24
  • Only lost 15 minutes because of this answer <3 (though I don't think I ever made a real purchase - creating a new ID just worked, maybe because I hadn't linked my service account when creating the original ones?) – dan674 Jul 30 '19 at 14:22
  • This was helpful, but I didn't even need to create a new product ID. In my case just making a trivial edit to the product description was enough to fix it. – Tyler V Dec 01 '20 at 15:14