{"_id":"google-play-billing","_rev":"1-864004cb7a94300610d9abc1eea73952","name":"google-play-billing","description":"Server side for (Node.js) solution to validate Google Play Purchases and Subscriptions","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"google-play-billing","version":"1.0.0","keywords":["google","play","validator","purchase","subscription","valid"],"author":{"name":"Deishelon"},"license":"ISC","_id":"google-play-billing@1.0.0","maintainers":[{"name":"kaetram","email":"admin@kaetram.com"}],"homepage":"https://github.com/Veradictus/google-play-billing-validator#readme","bugs":{"url":"https://github.com/Veradictus/google-play-billing-validator/issues"},"dist":{"shasum":"9bbcbe75f6a69b57f2302b4b1dd1f2f0466c7fa4","tarball":"https://registry.npmjs.org/google-play-billing/-/google-play-billing-1.0.0.tgz","fileCount":6,"integrity":"sha512-l7m1EiJsgd51zyUajMeo8H1ZjWEFmc1eV/qaKad4Zhey8iJZL2yRsCIE0GGEaUVC09FgQniO3DwwRCtvpq5nHw==","signatures":[{"sig":"MEYCIQCgFTaxv3RS7YyPAL05SR26uZJacashQHHlqjl0mei3UAIhAJ6GBkgFSakp6jc1lFFJrC7it4w5nx4jZeL7AP0d5ciO","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":12301},"main":"index.js","types":"index.d.ts","gitHead":"657b7a500ab757207744e68d7222ce47c3919a4e","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"kaetram","email":"admin@kaetram.com"},"repository":{"url":"git+https://github.com/Veradictus/google-play-billing-validator.git","type":"git"},"_npmVersion":"10.5.2","description":"Server side for (Node.js) solution to validate Google Play Purchases and Subscriptions","directories":{},"_nodeVersion":"20.13.1","dependencies":{"google-oauth-jwt":"^0.1.6"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/google-play-billing_1.0.0_1718702433323_0.6198348681055619","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"google-play-billing","version":"1.0.1","description":"Server side for (Node.js) solution to validate Google Play Purchases and Subscriptions","main":"index.js","types":"index.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["google","play","validator","purchase","subscription","valid"],"dependencies":{"google-oauth-jwt":"^0.1.6"},"repository":{"type":"git","url":"git+https://github.com/Veradictus/google-play-billing-validator.git"},"author":{"name":"Deishelon"},"license":"ISC","_id":"google-play-billing@1.0.1","gitHead":"d8ac687d376b3605e633ff3cefa1202a0bba9031","bugs":{"url":"https://github.com/Veradictus/google-play-billing-validator/issues"},"homepage":"https://github.com/Veradictus/google-play-billing-validator#readme","_nodeVersion":"20.13.1","_npmVersion":"10.5.2","dist":{"integrity":"sha512-mO/k0jLshsEpqwoAU1tjTtsAuqHkKDzn2cFHpFo0/PyRzWiFIDcNcMQMtFCSB1bXHTfw6ODLxHpW9ZeInTcxjQ==","shasum":"a2bbe9ba9c64aaf70ba1d35553b1efab28d8186d","tarball":"https://registry.npmjs.org/google-play-billing/-/google-play-billing-1.0.1.tgz","fileCount":6,"unpackedSize":12321,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGfYC+db4HZNN0YjytH77TRHGZawBBYcgZF6b74v7xv9AiEA37ud54T1LrwBxqTJQr+SfatsU2i6qXSfJxli9E0AhDE="}]},"_npmUser":{"name":"kaetram","email":"admin@kaetram.com"},"directories":{},"maintainers":[{"name":"kaetram","email":"admin@kaetram.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/google-play-billing_1.0.1_1718731666868_0.75784708220097"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-18T09:20:33.322Z","modified":"2024-06-18T17:27:47.237Z","1.0.0":"2024-06-18T09:20:33.477Z","1.0.1":"2024-06-18T17:27:47.034Z"},"maintainers":[{"name":"kaetram","email":"admin@kaetram.com"}],"author":{"name":"Deishelon"},"repository":{"type":"git","url":"git+https://github.com/Veradictus/google-play-billing-validator.git"},"keywords":["google","play","validator","purchase","subscription","valid"],"license":"ISC","homepage":"https://github.com/Veradictus/google-play-billing-validator#readme","bugs":{"url":"https://github.com/Veradictus/google-play-billing-validator/issues"},"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: <String>` to the `receipt` object\neg:\n```javascript\nlet receipt = {\n  packageName: \"<packageName>\",\n  productId: \"<productId>\",\n  purchaseToken: \"<purchaseToken>\",\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)\" -> \"The purchase token does not match the product ID.\"\n    \"Wrong purchase token\" -> \"The purchase token was not found.\"\n    \"Wrong package name\" -> \"No application was found for the given package name.\"\n\n    \"Wrong service email\" -> \"Not a valid email or user ID.\"\n    \"Wrong key\" -> \"Invalid JWT Signature.\"\n    \"Wrong service account permissions\" -> \"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","readmeFilename":"README.md"}