diff --git a/README.md b/README.md deleted file mode 100644 index 915e86f..0000000 --- a/README.md +++ /dev/null @@ -1,94 +0,0 @@ -# Node.js Google Play Validator (In-app purchases and Subscriptions) - -Npm module for Node.js to validate In-app purchases and Subscriptions on your backend - -## Install - -Install using npm -```javascript -npm i google-play-billing-validator -``` - -## Usage (Set-up) - -1. Go to [Developer Console](https://play.google.com/apps/publish/ "Developer Console") -1. Settings (in the left side menu) -1. Select API access -1. Link your Google Cloud Project to your developer account (If you have not created one yet, go to [Google API Console](https://console.developers.google.com/iam-admin/projects "API Console") and create one then come back here and link it ) -1. In Google API Console, in the left side menu click on service account -1. Then create a service account (Don't forget to save private key) -1. Go back to Developer Console, and grand asses to the newly created account (the permission has to be **View financial data**) -1. All done - -## Usage - -- Get Verifier -```javascript -var Verifier = require('google-play-billing-validator'); -``` -- Add your private key and service account email -```javascript -var options = { - email: 'INSERT SERVICE ACCOUNT EMAIL HERE', - "key": "INSERT YOUR PRIVATE KEY HERE", -}; -``` -- Create verifier object -```javascript -var verifier = new Verifier(options); -``` - -#### *Somewhere in your code, where you need to validate purchase or subscription** - -##### Create a receipt object - -```javascript - var receipt = { - packageName: "YOUR APP PKG", - productId: "sku / subscribtion id", - purchaseToken: "token" - }; -``` -##### Validate In-app purchase - -```javascript -verifier.verifyINAPP(receipt, function cb(err, response) { - if (err) { - console.log("there was an error validating the receipt"); - //console.log(err); - }else { - console.log("sucessfully validated the receipt"); - } -}); -``` - -##### Validate Subscribtion - -```javascript -verifier.verifySub(receipt, function cb(err, response) { - if (err) { - console.log("there was an error validating the receipt"); - //console.log(err); - }else { - console.log("sucessfully validated the receipt"); - // More Subscribtion info avalible in response variable - // Response schema is: - /* - { - "kind": "androidpublisher#subscriptionPurchase", - "startTimeMillis": "long", - "expiryTimeMillis": "long", - "autoRenewing": boolean - } - */ - } -}); -``` - -### Links -[GitHub](https://github.com/Deishelon/google-play-billing-validator "GitHub") -[npmjs](https://www.npmjs.com/package/google-play-billing-validator "npmjs") - - -### Credits -[google-play-purchase-validator](https://www.npmjs.com/package/google-play-purchase-validator "google-play-purchase-validator") - Forked from here, at the moment of writing supported only Subscriptions, used old v2 google API schema. Moved to v3, Added In-App purchases diff --git a/readme.md b/readme.md deleted file mode 100644 index 85e8637..0000000 --- a/readme.md +++ /dev/null @@ -1,191 +0,0 @@ -# Node.js Google Play Validator (In-app purchases and Subscriptions) - -Or How to check if in-app purchase/subscription is valid? - -## Tutorial - -In-depth tutorial on medium: [How to check if in-app purchase / subscription is valid?](https://medium.com/androidhub/how-to-validate-in-app-purchase-subscription-on-your-node-js-backend-a2b823470034) - -## Install - -Install using npm - -```javascript -npm i google-play-billing-validator -``` - -## Usage (Set-up) - -1. Go to [Developer Console](https://play.google.com/apps/publish/ "Developer Console") -2. Settings (in the left side menu) -3. Select API access -4. Link your Google Cloud Project to your developer account (If you have not created one yet, go to [Google API Console](https://console.developers.google.com/iam-admin/projects "API Console") and create one then come back here and link it ) -5. In Google API Console, in the left side menu click on service account -6. Then create a service account (Don't forget to save private key) -7. Go back to Developer Console, and grand asses to the newly created account (the permission has to be **View financial data**) -8. All done - -## Usage - -- Get Verifier - -```javascript -var Verifier = require('google-play-billing-validator'); -``` - -- Add your private key and service account email - -```javascript -var options = { - "email": 'INSERT SERVICE ACCOUNT EMAIL HERE', - "key": "INSERT YOUR PRIVATE KEY HERE", -}; -``` - -- Create verifier object - -```javascript -var verifier = new Verifier(options); -``` - -#### \*Somewhere in your code, where you need to validate purchase or subscription\*\* - -##### Create a receipt object - -```javascript - let receipt = { - packageName: "your app package name", - productId: "sku / subscription id", - purchaseToken: "purchase token" - }; -``` - -##### Validate In-app purchase - -```javascript -let promiseData = verifier.verifyINAPP(receipt) - -promiseData.then(function(response) { - // Yay! Purchase is valid - // See response structure below -}) -.then(function(response) { - // Here for example you can chain your work if purchase is valid - // eg. add coins to the user profile, etc - // If you are new to promises API - // Awesome docs: https://developers.google.com/web/fundamentals/primers/promises -}) -.catch(function(error) { - // Purchase is not valid or API error - // See possible error messages below -}) -``` - -##### Validate Subscription - -```javascript -let promiseData = verifier.verifySub(receipt) - -promiseData.then(function(response) { - // Yay! Subscription is valid - // See response structure below -}) -.then(function(response) { - // Here for example you can chain your work if subscription is valid - // eg. add coins to the user profile, etc - // If you are new to promises API - // Awesome docs: https://developers.google.com/web/fundamentals/primers/promises -}) -.catch(function(error) { - // Subscription is not valid or API error - // See possible error messages below -}) -``` - -##### Successful Response (In-app) -[ -Purchases.products @ Google Documentation](https://developers.google.com/android-publisher/api-ref/purchases/products#resource) - -```javascript -{ - "isSuccessful": boolean , - "errorMessage": null / string, - "payload": { - "kind": "androidpublisher#productPurchase", - "purchaseTimeMillis": long, - "purchaseState": integer, - "consumptionState": integer, - "developerPayload": string, - "orderId": string, - "purchaseType": integer - } -} -``` - -##### Successful Response (Subscription) -[Purchases.subscriptions @ Google Documentation](https://developers.google.com/android-publisher/api-ref/purchases/subscriptions#resource) - -```javascript -{ - "isSuccessful": boolean , - "errorMessage": null / string, - "payload": { - { - "kind": "androidpublisher#subscriptionPurchase", - "startTimeMillis": long, - "expiryTimeMillis": long, - "autoRenewing": boolean, - "priceCurrencyCode": string, - "priceAmountMicros": long, - "countryCode": string, - "developerPayload": string, - "paymentState": integer, - "cancelReason": integer, - "userCancellationTimeMillis": long, - "cancelSurveyResult": { - "cancelSurveyReason": integer, - "userInputCancelReason": string - }, - "orderId": string, - "linkedPurchaseToken": string, - "purchaseType": integer, - "profileName": string, - "emailAddress": string, - "givenName": string, - "familyName": string, - "profileId": string - } - } -} -``` - -##### Failed Response - -```javascript -{ - "isSuccessful": false, - "errorMessage": "The purchase token does not match the product ID." -} -``` - - "Wrong productId (sku)" -> "The purchase token does not match the product ID." - "Wrong purchase token" -> "The purchase token was not found." - "Wrong package name" -> "No application was found for the given package name." - - "Wrong service email" -> "Not a valid email or user ID." - "Wrong key" -> "Invalid JWT Signature." - "Wrong service account permissions" -> "The current user has insufficient permissions to perform the requested operation." - -## Migration from v1 to v2 - -v1 was a callback based, where v2 is fully promise based. -If you are unfamiliar with promises, read [this](https://developers.google.com/web/fundamentals/primers/promises) - -The migration is very simple: -1\. Remove the callback parameter to `verifyINAPP()` and/or `verifySub()` functions -2\. See example usage (above) - -### Links - -[GitHub](https://github.com/Deishelon/google-play-billing-validator "GitHub") -[npmjs](https://www.npmjs.com/package/google-play-billing-validator "npmjs")