def process_subscription_result(state, user, user_id, plan): if user_id != session['user_id']: logger.error("The user id returned by the payment processor \ is different from the session's one") if state == "success": logger.debug("User %s successfully subscribed to %s" % (user_id, plan)) session['is_authorized'] = True user.is_authorized = True user.save() return next_on() elif state == "cancel": logger.info("User %s canceled from %s" % (user_id, plan)) return redirect("/")
def payment(user): # Process the trial period time_done = mtime.now() - session['subscribed'] time_to_do = timedelta(weeks=config.payment_grace_time) time_remaining = time_to_do - time_done if time_done > time_to_do: logger.debug("Autorizing user %s" % user.id) url = "%s/%s/%s/" % (config.recurly_subscribe_url, config.recurly_subscription_plan, user.id) if user.email: url = url + user.email + "?email=" + user.email return render_template("auth.html", subscribeUrl=url) else: # Authorize the user for this session only. Please, do NOT sync this # attribute to the db. remaining = mtime.pretty_date_future(mtime.now() + time_remaining) session['is_authorized'] = True session['free_trial_remaining'] = remaining logger.debug("User %s has been graced. Remaining time %s." % ( user.id, time_remaining)) return next_on()
def auth(): try: if not is_identified(): return to("id") # We are here because the user has been identified but NOT authorized. user = get_user() if not user: user = create_user() # If our user is already authorized to use the service, skip the # authorization and let's go. if is_authorized(): logger.debug("User %s is authorized." % user.id) return next_on() else: logger.debug("User %s is NOT authorized." % user.id) # Render the payment page. return payment(user) except Exception, exception: logger.critical("Exception: %s" % exception) logger.debug(traceback.format_exc()) return error_page(exception)