Deishelon / google-play-billing-validator

Npm module for Node.js to validate In-app purchases and Subscriptions on your backend
https://medium.com/androidhub/how-to-validate-in-app-purchase-subscription-on-your-node-js-backend-a2b823470034
90 stars 32 forks source link

Method: purchases.subscriptionsv2.get #30

Open abhishekgoyaldev opened 12 months ago

abhishekgoyaldev commented 12 months ago

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch google-play-billing-validator@2.1.3 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/google-play-billing-validator/index.js b/node_modules/google-play-billing-validator/index.js
index ccc86bf..6a149ae 100644
--- a/node_modules/google-play-billing-validator/index.js
+++ b/node_modules/google-play-billing-validator/index.js
@@ -34,7 +34,7 @@ Verifier.prototype.verifySub = function (receipt) {
   this.options.body = "";
   this.options.json = false;

-  let urlPattern = "https://www.googleapis.com/androidpublisher/v3/applications/%s/purchases/subscriptions/%s/tokens/%s";
+  let urlPattern = "https://androidpublisher.googleapis.com/androidpublisher/v3/applications/%s/purchases/subscriptionsv2/tokens/%s";
   if ("developerPayload" in receipt) {
     urlPattern += ":acknowledge";
     this.options.body = {
@@ -43,7 +43,7 @@ Verifier.prototype.verifySub = function (receipt) {
     this.options.method = 'post';
     this.options.json = true;
   }
-  let finalUrl = util.format(urlPattern, encodeURIComponent(receipt.packageName), encodeURIComponent(receipt.productId), encodeURIComponent(receipt.purchaseToken));
+  let finalUrl = util.format(urlPattern, encodeURIComponent(receipt.packageName), encodeURIComponent(receipt.purchaseToken));

   return this.verify(finalUrl)
 };

This issue body was partially generated by patch-package.

abhishekgoyaldev commented 12 months ago
diff --git a/node_modules/google-play-billing-validator/index.js b/node_modules/google-play-billing-validator/index.js
index ccc86bf..47f2d44 100644
--- a/node_modules/google-play-billing-validator/index.js
+++ b/node_modules/google-play-billing-validator/index.js
@@ -34,16 +34,20 @@ Verifier.prototype.verifySub = function (receipt) {
   this.options.body = "";
   this.options.json = false;

-  let urlPattern = "https://www.googleapis.com/androidpublisher/v3/applications/%s/purchases/subscriptions/%s/tokens/%s";
+  let urlPattern = "https://androidpublisher.googleapis.com/androidpublisher/v3/applications/%s/purchases/subscriptionsv2/tokens/%s";
+  let finalUrl = ""
   if ("developerPayload" in receipt) {
+    urlPattern = "https://androidpublisher.googleapis.com/androidpublisher/v3/applications/%s/purchases/subscriptions/%s/tokens/%s";
     urlPattern += ":acknowledge";
     this.options.body = {
       "developerPayload": receipt.developerPayload
     }
     this.options.method = 'post';
     this.options.json = true;
+    finalUrl = util.format(urlPattern, encodeURIComponent(receipt.packageName), encodeURIComponent(receipt.productId), encodeURIComponent(receipt.purchaseToken));
+  }else{
+    finalUrl = util.format(urlPattern, encodeURIComponent(receipt.packageName), encodeURIComponent(receipt.purchaseToken));
   }
-  let finalUrl = util.format(urlPattern, encodeURIComponent(receipt.packageName), encodeURIComponent(receipt.productId), encodeURIComponent(receipt.purchaseToken));

   return this.verify(finalUrl)
 };

This issue body was partially generated by patch-package.

sgwanlee commented 6 months ago

@abhishekgoyaldev it works perfect!