GoogleVerificationResult: how to interpret `is_canceled` and separate different cases?
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