Skip to content

Commit

Permalink
fixes after last pr merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dotpot committed Mar 8, 2021
1 parent 76424d4 commit 73b5767
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions inapppy/errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class InAppPyError(Exception):
""" Base class for all errors """

pass


Expand Down
40 changes: 20 additions & 20 deletions inapppy/googleplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
import datetime
import json
import os
from typing import Union

import httplib2
import rsa

from typing import Union

from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from oauth2client.service_account import ServiceAccountCredentials

from inapppy.errors import GoogleError, InAppPyValidationError, InAppPyError
from inapppy.errors import GoogleError, InAppPyError, InAppPyValidationError


def make_pem(public_key: str) -> str:
value = (public_key[i: i + 64] for i in range(0, len(public_key), 64)) # noqa: E203
value = (public_key[i : i + 64] for i in range(0, len(public_key), 64)) # noqa: E203
return "\n".join(("-----BEGIN PUBLIC KEY-----", "\n".join(value), "-----END PUBLIC KEY-----"))


Expand Down Expand Up @@ -99,7 +97,7 @@ def __repr__(self):

class GooglePlayVerifier:
DEFAULT_AUTH_SCOPE = "https://www.googleapis.com/auth/androidpublisher"

def __init__(self, bundle_id: str, play_console_credentials: Union[str, dict], http_timeout: int = 15) -> None:
"""
Arguments:
Expand Down Expand Up @@ -138,8 +136,10 @@ def _create_credentials(play_console_credentials: Union[str, dict], scope_str: s
# If dict, assume parsed json
if isinstance(play_console_credentials, dict):
return ServiceAccountCredentials.from_json_keyfile_dict(play_console_credentials, scope_str)
raise InAppPyError(f"Unknown play console credentials format: {repr(play_console_credentials)}, "
"expected 'dict' or 'str' types")
raise InAppPyError(
f"Unknown play console credentials format: {repr(play_console_credentials)}, "
"expected 'dict' or 'str' types"
)

def _authorize(self):
http = httplib2.Http(timeout=self.http_timeout)
Expand All @@ -149,12 +149,13 @@ def _authorize(self):

def check_purchase_subscription(self, purchase_token: str, product_sku: str, service) -> dict:
try:
return (
service.purchases()
.subscriptions()
.get(packageName=self.bundle_id, subscriptionId=product_sku, token=purchase_token)
.execute(http=self.http)
purchases = service.purchases()
subscriptions = purchases.subscriptions()
subscriptions_get = subscriptions.get(
packageName=self.bundle_id, subscriptionId=product_sku, token=purchase_token
)
result = subscriptions_get.execute(http=self.http)
return result
except HttpError as e:
if e.resp.status == 400:
raise GoogleError(e.resp.reason, repr(e))
Expand All @@ -163,12 +164,11 @@ def check_purchase_subscription(self, purchase_token: str, product_sku: str, ser

def check_purchase_product(self, purchase_token: str, product_sku: str, service) -> dict:
try:
return (
service.purchases()
.products()
.get(packageName=self.bundle_id, productId=product_sku, token=purchase_token)
.execute(http=self.http)
)
purchases = service.purchases()
products = purchases.products()
products_get = products.get(packageName=self.bundle_id, productId=product_sku, token=purchase_token)
result = products_get.execute(http=self.http)
return result
except HttpError as e:
if e.resp.status == 400:
raise GoogleError(e.resp.reason, repr(e))
Expand Down Expand Up @@ -199,7 +199,7 @@ def verify(self, purchase_token: str, product_sku: str, is_subscription: bool =
return result

def verify_with_result(
self, purchase_token: str, product_sku: str, is_subscription: bool = False
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."""
Expand Down

0 comments on commit 73b5767

Please sign in to comment.