Skip to content

Instantly share code, notes, and snippets.

@ponnamkarthik
Created September 21, 2019 15:03
Show Gist options
  • Save ponnamkarthik/d50cd1baa18304a19298ba4ba6ac8b1f to your computer and use it in GitHub Desktop.
Save ponnamkarthik/d50cd1baa18304a19298ba4ba6ac8b1f to your computer and use it in GitHub Desktop.
NodeJS ServerSide Google Play Purchase Validation
var Verifier = require('google-play-billing-validator')
var options = {
"key": "Private Key Here",
"email": "service account email",
}
var verifier = new Verifier(options);
// this is the tings you need to change
let receipt = {
packageName: "app package name", // app packagename
productId: "sub/product id", // product or sub id
purchaseToken: "purchase token" // purchase token
};
let promiseData = verifier.verifySub(receipt)
promiseData.then(function (response) {
console.log(response);
// Yay! Purchase is valid
// See response structure below
/*
Response Data
*
*
{ isSuccessful: true, errorMessage: null, payload: { kind:
'androidpublisher#subscriptionPurchase', startTimeMillis: '1559996454334',
expiryTimeMillis: '1559997588984', autoRenewing: true, priceCurrencyCode: 'MYR',
priceAmountMicros: '20990000', countryCode: 'MY', developerPayload: '',
paymentState: 1, orderId: 'GPA.3303-7376-1225-04672..1', purchaseType: 0,
acknowledgementState: 1 } }
*/
// Perform success operation
})
.catch(function (error) {
console.log("-------------------- Error ----------")
console.log(response);
// Purchase is not valid or API error
// See possible error messages below
})
@ponnamkarthik
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment