Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to valid purchase express server using google-play-purchase-validator

I want integrating Google Play in-app billing to my unity project that already get payLoad json. I have a Node.js server and want to get value of the Google Play purchase response for server side verification.

My list product on Google Play Developer Console was create productId but i got error:

[Error: The subscription purchase token does not match the subscription ID.]

In my index.js file of my node server I have a segment like this:

var Verifier = require('google-play-purchase-validator');
var options = {
    email: '#############[email protected]',
    key: '-----BEGIN PRIVATE KEY-----##some private key##-----END PRIVATE KEY-----',
    keyFile: './Google Play Android Developer-############.json'
};
var verifier = new Verifier(options);
var receipt = {
    packageName:"com.natekgames.######",
    productId:"com.natekgames.######.diamond_48",
    purchaseToken:"ihfeaepjoppolibmeknoghmo.AO-J1OxbHPDa8QLVAU3OqvIa-ZgaAGWhrBhs8DyCEfFbbdTCH8ecvEXQlZtjkqaowPXujb0Osn_aOWBPMT0OpTMcivoQalEtOZmMhS2lDA7oH868NjZP2LgdE9ODafujNM7O9QQr3-hq"
};
verifier.verify(receipt, function cb(err, response){
    if(err){
        console.log("there was an error validating the receipt");
        console.log(err);
    }
    console.log("sucessfully validated the receipt");
    res.send(response);
});
like image 992
kodos Avatar asked Feb 24 '17 08:02

kodos


People also ask

How do you verify In-app Purchases on Google?

On your Android phone or tablet, say "Hey Google, open Assistant settings." Or, go to Assistant settings. Payments. Turn Pay through your Assistant on or off. Turn Confirm with fingerprint or face and Confirm with Voice Match on or off.

What is an in-app purchase?

An in-app purchase is any additional purchase made within an app, like extra lives in a game. You can turn in-app purchases on or off on Apple and Android devices with just a few taps.


1 Answers

  1. Make sure you are calling the subscriptions endpoint for subscriptions and the purchases endpoint for in-app purchases. Don't mix them, or you'll get this error.
  2. Make sure the productId parameter is written exactly same way as it's written in Google Play Developer Console.
like image 51
Babken Vardanyan Avatar answered Oct 13 '22 23:10

Babken Vardanyan