Created
September 21, 2019 15:03
-
-
Save ponnamkarthik/d50cd1baa18304a19298ba4ba6ac8b1f to your computer and use it in GitHub Desktop.
NodeJS ServerSide Google Play Purchase Validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.npmjs.com/package/google-play-billing-validator