{"id":15007619,"url":"https://github.com/deishelon/google-play-billing-validator","last_synced_at":"2025-04-07T12:07:36.170Z","repository":{"id":33746400,"uuid":"136897689","full_name":"Deishelon/google-play-billing-validator","owner":"Deishelon","description":"Npm module for Node.js to validate In-app purchases and Subscriptions on your backend","archived":false,"fork":false,"pushed_at":"2022-12-08T08:09:13.000Z","size":47,"stargazers_count":90,"open_issues_count":16,"forks_count":32,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-07T12:07:29.876Z","etag":null,"topics":["android","google-play","nodejs","npmjs","purchase","subscription","verifies"],"latest_commit_sha":null,"homepage":"https://medium.com/androidhub/how-to-validate-in-app-purchase-subscription-on-your-node-js-backend-a2b823470034","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Deishelon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-11T08:35:34.000Z","updated_at":"2024-07-09T10:49:45.000Z","dependencies_parsed_at":"2023-01-15T02:19:29.014Z","dependency_job_id":null,"html_url":"https://github.com/Deishelon/google-play-billing-validator","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deishelon%2Fgoogle-play-billing-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deishelon%2Fgoogle-play-billing-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deishelon%2Fgoogle-play-billing-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deishelon%2Fgoogle-play-billing-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Deishelon","download_url":"https://codeload.github.com/Deishelon/google-play-billing-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648977,"owners_count":20972945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","google-play","nodejs","npmjs","purchase","subscription","verifies"],"created_at":"2024-09-24T19:12:33.723Z","updated_at":"2025-04-07T12:07:36.150Z","avatar_url":"https://github.com/Deishelon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js Google Play Validator (In-app purchases and Subscriptions)\n\nOr How to check if in-app purchase/subscription is valid?\n\n## Tutorial\n\nIn-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)\n\n## Install\n\nInstall using npm\n\n```javascript\nnpm i google-play-billing-validator\n```\n\n## Usage (Set-up)\n\n1.  Go to [Developer Console](https://play.google.com/apps/publish/ \"Developer Console\")\n2.  Settings (in the left side menu)\n3.  Select API access\n4.  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 )\n5.  In Google API Console, in the left side menu click on service account\n6.  Then create a service account (Don't forget to save private key)\n7.  Go back to Developer Console, and grant access to the newly created account (the permission has to be **View financial data**)\n8.  All done\n\n## Usage\n\n-   Get Verifier\n\n```javascript\nvar Verifier = require('google-play-billing-validator');\n```\n\n-   Add your private key and service account email\n\n```javascript\nvar options = {\n  \"email\": 'INSERT SERVICE ACCOUNT EMAIL HERE',\n  \"key\": \"INSERT YOUR PRIVATE KEY HERE\",\n};\n```\n\n-   Create verifier object\n\n```javascript\nvar verifier = new Verifier(options);\n```\n\n#### \\*Somewhere in your code, where you need to validate purchase or subscription\\*\\*\n\n##### Create a receipt object\n\n```javascript\nlet receipt = {\n  packageName: \"your app package name\",\n  productId: \"sku / subscription id\",\n  purchaseToken: \"purchase token\"\n};\n```\n\n##### Validate In-app purchase\n\n```javascript\nlet promiseData = verifier.verifyINAPP(receipt)\n\npromiseData.then(function(response) {\n  // Yay! Purchase is valid\n  // See response structure below\n})\n.then(function(response) {\n  // Here for example you can chain your work if purchase is valid\n  // eg. add coins to the user profile, etc\n  // If you are new to promises API\n  // Awesome docs: https://developers.google.com/web/fundamentals/primers/promises\n})\n.catch(function(error) {\n  // Purchase is not valid or API error\n  // See possible error messages below\n})\n```\n\n##### Validate Subscription\n\n```javascript\nlet promiseData = verifier.verifySub(receipt)\n\npromiseData.then(function(response) {\n  // Yay! Subscription is valid\n  // See response structure below\n})\n.then(function(response) {\n  // Here for example you can chain your work if subscription is valid\n  // eg. add coins to the user profile, etc\n  // If you are new to promises API\n  // Awesome docs: https://developers.google.com/web/fundamentals/primers/promises\n})\n.catch(function(error) {\n  // Subscription is not valid or API error\n  // See possible error messages below\n})\n```\n\n##### Acknowledge Purchase / Subscription\nTo acknowledge a purchase or a subscription, simple add `developerPayload: \u003cString\u003e` to the `receipt` object\neg:\n```javascript\nlet receipt = {\n  packageName: \"\u003cpackageName\u003e\",\n  productId: \"\u003cproductId\u003e\",\n  purchaseToken: \"\u003cpurchaseToken\u003e\",\n  developerPayload: \"YOUR PAYLOAD\"\n};\n\n```\n\nIf successful, the result will be\n```javascript\n{\n   isSuccessful:true,\n   errorMessage:null,\n   payload:{\n      code:204,\n      message:'Acknowledged Purchase Successfully'\n   }\n}\n```\n\n##### Successful Response (In-app)\n[\nPurchases.products @ Google Documentation](https://developers.google.com/android-publisher/api-ref/purchases/products#resource)\n\n```javascript\n{\n\t\"isSuccessful\": boolean ,\n\t\"errorMessage\": null / string,\n\t\"payload\": {\n\t\t\"kind\": \"androidpublisher#productPurchase\",\n\t\t\"purchaseTimeMillis\": long,\n\t\t\"purchaseState\": integer,\n\t\t\"consumptionState\": integer,\n\t\t\"developerPayload\": string,\n\t\t\"orderId\": string,\n\t\t\"purchaseType\": integer\n\t}\n}\n```\n\n##### Successful Response (Subscription)\n[Purchases.subscriptions @ Google Documentation](https://developers.google.com/android-publisher/api-ref/purchases/subscriptions#resource)\n\n```javascript\n{\n  \"isSuccessful\": boolean ,\n\t\"errorMessage\": null / string,\n\t\"payload\": {\n\t\t{\n\t\t\t\"kind\": \"androidpublisher#subscriptionPurchase\",\n\t\t\t\"startTimeMillis\": long,\n\t\t\t\"expiryTimeMillis\": long,\n\t\t\t\"autoRenewing\": boolean,\n\t\t\t\"priceCurrencyCode\": string,\n\t\t\t\"priceAmountMicros\": long,\n\t\t\t\"countryCode\": string,\n\t\t\t\"developerPayload\": string,\n\t\t\t\"paymentState\": integer,\n\t\t\t\"cancelReason\": integer,\n\t\t\t\"userCancellationTimeMillis\": long,\n\t\t\t\"cancelSurveyResult\": {\n\t\t\t\t\"cancelSurveyReason\": integer,\n\t\t\t\t\"userInputCancelReason\": string\n\t\t\t},\n\t\t\t\"orderId\": string,\n\t\t\t\"linkedPurchaseToken\": string,\n\t\t\t\"purchaseType\": integer,\n\t\t\t\"profileName\": string,\n\t\t\t\"emailAddress\": string,\n\t\t\t\"givenName\": string,\n\t\t\t\"familyName\": string,\n\t\t\t\"profileId\": string\n\t\t}\n\t}\n}\n```\n\n##### Failed Response\n\n```javascript\n{\n  \"isSuccessful\": false,\n  \"errorMessage\": \"The purchase token does not match the product ID.\"\n}\n```\n\n    \"Wrong productId (sku)\" -\u003e \"The purchase token does not match the product ID.\"\n    \"Wrong purchase token\" -\u003e \"The purchase token was not found.\"\n    \"Wrong package name\" -\u003e \"No application was found for the given package name.\"\n\n    \"Wrong service email\" -\u003e \"Not a valid email or user ID.\"\n    \"Wrong key\" -\u003e \"Invalid JWT Signature.\"\n    \"Wrong service account permissions\" -\u003e \"The current user has insufficient permissions to perform the requested operation.\"\n\n## Migration from v1 to v2\n\nv1 was a callback based, where v2 is fully promise based.\nIf you are unfamiliar with promises, read [this](https://developers.google.com/web/fundamentals/primers/promises)\n\nThe migration is very simple:\n1. Remove the callback parameter to `verifyINAPP()` and/or `verifySub()` functions\n2. Get result in a `promise`\n3. See example usage (above)\n\n### Links\n\n[GitHub](https://github.com/Deishelon/google-play-billing-validator \"GitHub\")  \n[npmjs](https://www.npmjs.com/package/google-play-billing-validator \"npmjs\")\n\n\n### Changelog\n\n##### 2.1.3\n- Allow default import syntax from TypeScript\nThanks [@unpollito](https://github.com/unpollito)\n\n##### 2.1.1\n- Fixed and improved type script support  \nThanks [@YogiBear52](https://github.com/YogiBear52)\n\n##### 2.1.0\n- Added TypeScript support\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeishelon%2Fgoogle-play-billing-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeishelon%2Fgoogle-play-billing-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeishelon%2Fgoogle-play-billing-validator/lists"}