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

GoogleVerificationResult: how to interpret is_canceled and separate different cases? #66

Open
vartagg opened this issue Jul 8, 2020 · 0 comments
Labels

Comments

@vartagg
Copy link

vartagg commented Jul 8, 2020

Description

There is a method in GooglePlayVerifier class:

    def verify_with_result(
        self, purchase_token: str, product_sku: str, is_subscription: bool = False
    ) -> GoogleVerificationResult:
        """Verifies by returning verification result instead of raising an error,
        basically it's and better alternative to verify method."""
        service = build("androidpublisher", "v3", http=self.http)
        verification_result = GoogleVerificationResult({}, False, False)

        if is_subscription:
            result = self.check_purchase_subscription(purchase_token, product_sku, service)
            verification_result.raw_response = result

            cancel_reason = int(result.get("cancelReason", 0))
            if cancel_reason != 0:
                verification_result.is_canceled = True

            ms_timestamp = result.get("expiryTimeMillis", 0)
            if self._ms_timestamp_expired(ms_timestamp):
                verification_result.is_expired = True
        else:
            result = self.check_purchase_product(purchase_token, product_sku, service)
            verification_result.raw_response = result

            purchase_state = int(result.get("purchaseState", 1))
            if purchase_state != 0:
                verification_result.is_canceled = True

        return verification_result

According to publisher docs, Google uses code 0 as a valid code of cancellation in property cancelReason. It means, that this code indicates, that subscription was canceled (by user). On the other hand, code 0 in this method used as a value of variable, which means, that the subscription is not canceled.

The question is, how to interpret GoogleVerificationResult.is_canceled (what does this attribute mean)? And how to separate the cases, when:

  • subscription was not cancelled
  • subscription canceled by user? (with code 0)

Expected Behavior

is_canceled means, that subscription is canceled (by user or not)

Actual Behavior

is_canceled means, that subscription was canceled, but not by user

Possible Fix

It depends on the meaning of the is_canceled attribute. Maybe some comment would be useful, if everything works as expected. Or, If it is a bug, then as a possible fix: change the condition check (don't use value 0 as indicator, because this value is reserved by Google).

Your Environment

  • Version used: 2.4.4
  • Operating System and version: Docker python:3.7.4-buster
@vartagg vartagg added the bug label Jul 8, 2020
@vartagg vartagg changed the title GoogleVerificationResult: how to interpret is_canceled and separate multiple cases? GoogleVerificationResult: how to interpret is_canceled and separate different cases? Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant