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

Release/0.8.1 #209

Merged
merged 10 commits into from
Dec 19, 2023
8 changes: 7 additions & 1 deletion common/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@

CURRENCY_LIST = ("NCG", "CRYSTAL", "GARAGE")

AVATAR_BOUND_TICKER = ("RUNE_GOLDENLEAF",)
AVATAR_BOUND_TICKER = (
"RUNE_GOLDENLEAF",
"SOULSTONE_1001", # D:CC Blackcat
"SOULSTONE_1002", # Red Dongle
"SOULSTONE_1003", # Valkyrie of Light
"SOULSTONE_1004", # Lil' Fenrir
)
34 changes: 21 additions & 13 deletions iap/api/purchase.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import os
import time
from datetime import datetime
from typing import Tuple, List, Dict, Optional, Annotated
from uuid import UUID
Expand Down Expand Up @@ -44,7 +45,10 @@ def validate_apple(tx_id: str) -> Tuple[bool, str, Optional[ApplePurchaseSchema]
}
resp = requests.get(settings.APPLE_VALIDATION_URL.format(transactionId=tx_id), headers=headers)
if resp.status_code != 200:
return False, f"Purchase state of this receipt is not valid: {resp.text}", None
time.sleep(1)
resp = requests.get(settings.APPLE_VALIDATION_URL.format(transactionId=tx_id), headers=headers)
if resp.status_code != 200:
return False, f"Purchase state of this receipt is not valid: {resp.text}", None
try:
data = jwt.decode(resp.json()["signedTransactionInfo"], options={"verify_signature": False})
logger.debug(data)
Expand All @@ -55,17 +59,21 @@ def validate_apple(tx_id: str) -> Tuple[bool, str, Optional[ApplePurchaseSchema]
return True, "", schema


def validate_google(sku: str, token: str) -> Tuple[bool, str, GooglePurchaseSchema]:
def validate_google(sku: str, token: str) -> Tuple[bool, str, Optional[GooglePurchaseSchema]]:
client = get_google_client(settings.GOOGLE_CREDENTIAL)
resp = GooglePurchaseSchema(
**(client.purchases().products()
.get(packageName=settings.GOOGLE_PACKAGE_NAME, productId=sku, token=token)
.execute())
)
msg = ""
if resp.purchaseState != GooglePurchaseState.PURCHASED:
return False, f"Purchase state of this receipt is not valid: {resp.purchaseState.name}", resp
return True, msg, resp
try:
resp = GooglePurchaseSchema(
**(client.purchases().products()
.get(packageName=settings.GOOGLE_PACKAGE_NAME, productId=sku, token=token)
.execute())
)
if resp.purchaseState != GooglePurchaseState.PURCHASED:
return False, f"Purchase state of this receipt is not valid: {resp.purchaseState.name}", resp
return True, "", resp

except Exception as e:
logger.warning(e)
return False, f"Error occurred validating google receipt: {e}", None


def consume_google(sku: str, token: str):
Expand Down Expand Up @@ -212,8 +220,7 @@ def request_product(receipt_data: ReceiptSchema, sess=Depends(session)):
## Test
elif receipt_data.store == Store.TEST:
if os.environ.get("STAGE") == "mainnet":
receipt.status = ReceiptStatus.INVALID
success, msg = False, f"{receipt.store} is not validatable store."
success, msg = False, f"{receipt.store} is not allowed."
else:
success, msg = True, "This is test"
## INVALID
Expand All @@ -222,6 +229,7 @@ def request_product(receipt_data: ReceiptSchema, sess=Depends(session)):
success, msg = False, f"{receipt.store} is not validatable store."

if not success:
receipt.msg = msg
receipt.status = ReceiptStatus.INVALID
raise_error(sess, receipt, ValueError(f"Receipt validation failed: {msg}"))

Expand Down