From 840f827b45f9bfc33169339992440eb8ab407730 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sun, 19 Apr 2020 23:13:43 +0200 Subject: [PATCH] Handle the case "Restore Purchase" on another account --- app/api/views/apple.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/api/views/apple.py b/app/api/views/apple.py index 5ed51f18..34490978 100644 --- a/app/api/views/apple.py +++ b/app/api/views/apple.py @@ -269,7 +269,7 @@ def verify_receipt(receipt_data, user) -> Optional[AppleSubscription]: if apple_sub: LOG.d( - "Create new AppleSubscription for user %s, expired at %s, plan %s", + "Update AppleSubscription for user %s, expired at %s, plan %s", user, expires_date, plan, @@ -279,6 +279,11 @@ def verify_receipt(receipt_data, user) -> Optional[AppleSubscription]: apple_sub.original_transaction_id = original_transaction_id apple_sub.plan = plan else: + # the same original_transaction_id has been used on another account + if AppleSubscription.get_by(original_transaction_id=original_transaction_id): + LOG.error("Same Apple Sub has been used before, current user %s", user) + return None + LOG.d( "Create new AppleSubscription for user %s, expired at %s, plan %s", user,