Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differentiate unavailability from failed validation #236

Open
benji101 opened this issue Jan 10, 2019 · 4 comments
Open

Differentiate unavailability from failed validation #236

benji101 opened this issue Jan 10, 2019 · 4 comments

Comments

@benji101
Copy link

First, thanks for this library, it's a lot of good work!

Maybe I'm missing something (I'm new to Node.js), but I'm trying to split between 3 cases that can happen when trying to validate a Google Play subscription:

  • Subscription is valid
  • Subscription is not valid (subscription canceled, expired or possibly someone hacking)
  • Subscription could not be verified (Google down or other error)

Regarding this, I have two questions:

  • does .isValidated() only return true if the subscription is valid (meaning the subscription is active and the purchaseToken was valid)?
  • I seem to fall in the "error catch" both if Google API is not available or if the purchase token doesn't exist. How to differentiate the two cases if I don't want the same behavior?

Here is the snippet I'm using, and I'd like to know how to tweak it to get the behavior I want.

iap.setup()
    .then(() => {
        iap.validate(receipt)
          .then( function (response) {
              if (iap.isValidated(response)) {
              // subscription is valid
              } else {
              // Subscription is not valid (subscription canceled or expired)?
           }
      })
      .catch( function (error) {
      // failed to validate the receipt...
     // Google unavailable or hack? 
     });
})
.catch((error) => {
  // error...
  // Google unavailable or hack? 
});

Thanks again for the great work!

@voltrue2
Copy link
Owner

voltrue2 commented Jan 10, 2019 via email

@benji101
Copy link
Author

benji101 commented Jan 11, 2019

Ok, but my main question is still: How to differentiate a server error (for example, a 503 error) from an error because the purchase token doesn't exist (404 error from google). If I understand correctly, both error will cause the function .validate() to throw, so how can I differentiate them in the catch block? Is there a simple way to get the response code from the catch block?

@voltrue2
Copy link
Owner

Hello,

I missed the question there. Sorry about that.
At the moment, you cannot really tell them apart from expected error to HTTP error such as 503 etc...

@sardon
Copy link

sardon commented May 17, 2019

+1 !!

I agree that this is a desirable feature - it would allow to distinguish a system failure from a hacking attempt.

If a system failure, you may want to grant entitlements (depending on your use case), if hacking attempt you don't want to grant entitlements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants