From 295595a39776e74a6abf844584369156ce76ffdb Mon Sep 17 00:00:00 2001 From: bsimpson63 Date: Tue, 22 May 2012 00:05:09 -0400 Subject: [PATCH] Only look up account by subscr_id when hardcache is empty. --- r2/r2/controllers/ipn.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/r2/r2/controllers/ipn.py b/r2/r2/controllers/ipn.py index 3b99de3fa8..0e6b199403 100644 --- a/r2/r2/controllers/ipn.py +++ b/r2/r2/controllers/ipn.py @@ -25,6 +25,13 @@ def get_blob(code): g.hardcache.set(key, blob, 86400 * 30) return key, blob +def has_blob(custom): + if not custom: + return False + + blob = g.hardcache.get('payment_blob-%s' % custom) + return bool(blob) + def dump_parameters(parameters): for k, v in parameters.iteritems(): g.log.info("IPN: %r = %r" % (k, v)) @@ -110,14 +117,20 @@ def verify_ipn(parameters): raise ValueError("Invalid IPN response: %r" % status) -def existing_subscription(subscr_id, paying_id): +def existing_subscription(subscr_id, paying_id, custom): if subscr_id is None: return None account_id = accountid_from_paypalsubscription(subscr_id) + if not account_id and has_blob(custom): + # New subscription contains the user info in hardcache + return None + should_set_subscriber = False if account_id is None: + # Payment from legacy subscription (subscr_id not set), fall back + # to guessing the user from the paying_id account_id = account_by_payingid(paying_id) should_set_subscriber = True if account_id is None: @@ -396,7 +409,7 @@ def POST_ipn(self, paypal_secret, payment_status, txn_id, paying_id, months, days = months_and_days_from_pennies(pennies) # Special case: autorenewal payment - existing = existing_subscription(subscr_id, paying_id) + existing = existing_subscription(subscr_id, paying_id, custom) if existing: if existing != "deleted account": create_claimed_gold ("P" + txn_id, payer_email, paying_id, @@ -407,9 +420,6 @@ def POST_ipn(self, paypal_secret, payment_status, txn_id, paying_id, g.log.info("Just applied IPN renewal for %s, %d days" % (existing.name, days)) return "Ok" - elif subscr_id: - g.log.warning("IPN subscription %s is not associated with anyone" - % subscr_id) # More sanity checks that all non-autorenewals should pass: