diff --git a/r2/example.ini b/r2/example.ini index f71fb6754..fc76bd111 100644 --- a/r2/example.ini +++ b/r2/example.ini @@ -420,6 +420,10 @@ media_domain = localhost # Embedly API Key embedly_api_key = +# -- prices -- +gold_month_price = 3.99 +gold_year_price = 29.99 + # -- limits -- # rate limiter duration (minutes) RATELIMIT = 10 diff --git a/r2/r2/controllers/ipn.py b/r2/r2/controllers/ipn.py index e9b46af4e..3fc00ea00 100644 --- a/r2/r2/controllers/ipn.py +++ b/r2/r2/controllers/ipn.py @@ -191,11 +191,12 @@ def existing_subscription(subscr_id, paying_id, custom): return account def months_and_days_from_pennies(pennies): - if pennies >= 2999: - months = 12 * (pennies / 2999) - days = 366 * (pennies / 2999) + if pennies >= g.gold_year_price.pennies: + years = pennies / g.gold_year_price.pennies + months = 12 * years + days = 366 * years else: - months = pennies / 399 + months = pennies / g.gold_month_price.pennies days = 31 * months return (months, days) diff --git a/r2/r2/lib/app_globals.py b/r2/r2/lib/app_globals.py index 8caf9770e..cfdd2d04c 100755 --- a/r2/r2/lib/app_globals.py +++ b/r2/r2/lib/app_globals.py @@ -42,6 +42,7 @@ from r2.lib.lock import make_lock_factory from r2.lib.manager import db_manager from r2.lib.stats import Stats, CacheStats, StatsCollectingConnectionPool from r2.lib.plugin import PluginLoader +from r2.lib.utils import config_gold_price from r2.config import queues @@ -180,6 +181,11 @@ class Globals(object): 'QUORUM': CL_QUORUM }, }, + + config_gold_price: [ + 'gold_month_price', + 'gold_year_price', + ], } live_config_spec = { diff --git a/r2/r2/lib/configparse.py b/r2/r2/lib/configparse.py index 43a556bf3..cf6103f42 100644 --- a/r2/r2/lib/configparse.py +++ b/r2/r2/lib/configparse.py @@ -54,6 +54,7 @@ class ConfigValue(object): def to_iter(v, delim = ','): return (x.strip() for x in v.split(delim) if x) + class ConfigValueParser(dict): def __init__(self, raw_data): dict.__init__(self, raw_data) diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 7f03840f2..8ed94e1b9 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -1725,9 +1725,9 @@ class GoldPayment(Templated): pay_from_creddits = False if period == "monthly" or 1 <= months < 12: - price = 3.99 + price = g.gold_month_price.decimal else: - price = 29.99 + price = g.gold_year_price.decimal if c.user_is_admin: user_creddits = 50 @@ -3772,4 +3772,9 @@ class InterestBar(Templated): Templated.__init__(self) class GoldInfoPage(BoringPage): - pass + def __init__(self, *args, **kwargs): + self.prices = { + "gold_month_price": g.gold_month_price, + "gold_year_price": g.gold_year_price, + } + BoringPage.__init__(self, *args, **kwargs) diff --git a/r2/r2/lib/utils/utils.py b/r2/r2/lib/utils/utils.py index 14fee7571..d0db662c6 100644 --- a/r2/r2/lib/utils/utils.py +++ b/r2/r2/lib/utils/utils.py @@ -31,6 +31,7 @@ import signal from copy import deepcopy import cPickle as pickle import re, math, random +from decimal import Decimal from BeautifulSoup import BeautifulSoup, SoupStrainer @@ -1410,3 +1411,34 @@ def simple_traceback(): )) for filename, line_number, function_name, text in stack_trace) + + +class GoldPrice(object): + """Simple price math / formatting type. + + Prices are assumed to be USD at the moment. + + """ + def __init__(self, decimal): + self.decimal = Decimal(decimal) + + def __mul__(self, other): + return type(self)(self.decimal * other) + + def __div__(self, other): + return type(self)(self.decimal / other) + + def __str__(self): + return "$%s" % self.decimal.quantize(Decimal("1.00")) + + def __repr__(self): + return "%s(%s)" % (type(self).__name__, self) + + @property + def pennies(self): + return int(self.decimal * 100) + + +def config_gold_price(v, key=None, data=None): + return GoldPrice(v) + diff --git a/r2/r2/models/gold.py b/r2/r2/models/gold.py index 231cc2a58..405b1be7d 100644 --- a/r2/r2/models/gold.py +++ b/r2/r2/models/gold.py @@ -312,14 +312,14 @@ def process_google_transaction(trans_id): pennies = int(float(auth.find("order-total").contents[0])*100) if is_creddits: secret = "cr_" - if pennies >= 2999: - days = 12 * 31 * int(pennies / 2999) + if pennies >= g.gold_year_price.pennies: + days = 12 * 31 * int(pennies / g.gold_year_price.pennies) else: - days = 31 * int(pennies / 399) - elif pennies == 2999: + days = 31 * int(pennies / g.gold_month_price.pennies) + elif pennies == g.gold_year_price.pennies: secret = "ys_" days = 366 - elif pennies == 399: + elif pennies == g.gold_month_price.pennies: secret = "m_" days = 31 else: diff --git a/r2/r2/templates/gold.html b/r2/r2/templates/gold.html index c79cb794a..8bcd733fd 100644 --- a/r2/r2/templates/gold.html +++ b/r2/r2/templates/gold.html @@ -67,12 +67,12 @@ @@ -100,9 +100,10 @@ <%self:goldsec goldtype="autorenew"> <%utils:round_field title="${'Monthly or yearly?'}"> - ${radio_type("period", "monthly", _("$3.99 / month"), "", False)}
- ${radio_type("period", "yearly", _("$29.99 / year (which works out to just $2.50 / month!)"), - "", True)}
+ ${radio_type("period", "monthly", _("%s / month") % g.gold_month_price, "", False)}
+ ${radio_type("period", "yearly", _("%s / year (which works out to just %s / month!)") + % (g.gold_year_price, g.gold_year_price / 12), + "", True)}
diff --git a/r2/r2/templates/goldinfopage.html b/r2/r2/templates/goldinfopage.html index 6fe99e580..a4a7198b6 100644 --- a/r2/r2/templates/goldinfopage.html +++ b/r2/r2/templates/goldinfopage.html @@ -99,7 +99,7 @@