Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move gold prices to configuration parameters.

  • Loading branch information...
commit 440cb664ac111f6903cc6ea0556ead8bbc3b6ca5 1 parent 4bf2c0e
Max Goodman authored
View
4 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
View
9 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)
View
6 r2/r2/lib/app_globals.py
@@ -42,6 +42,7 @@
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 = {
View
1  r2/r2/lib/configparse.py
@@ -54,6 +54,7 @@ def choice(v, key, data):
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)
View
11 r2/r2/lib/pages/pages.py
@@ -1725,9 +1725,9 @@ def __init__(self, goldtype, period, months, signed,
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 @@ def __init__(self, has_subscribed):
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)
View
32 r2/r2/lib/utils/utils.py
@@ -31,6 +31,7 @@
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)
+
View
10 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:
View
11 r2/r2/templates/gold.html
@@ -67,12 +67,12 @@
<select name="months" class="gold-dropdown">
%for i in range(1, 8):
<option value="${i}">
- ${unsafe(Score.somethings(i, what))}: $${"%0.2f" % (3.99 * i)}
+ ${unsafe(Score.somethings(i, what))}: ${g.gold_month_price * i}
</option>
%endfor
%for i in range(1, 4):
<option value="${i * 12}" ${"SELECTED" if i == 1 else ""}>
- ${unsafe(Score.somethings(i * 12, what))} &#32; (special price!): $${"%0.2f" % (29.99 * i)}
+ ${unsafe(Score.somethings(i * 12, what))} &#32; (special price!): ${g.gold_year_price * i}
</option>
%endfor
</select>
@@ -100,9 +100,10 @@ <h1 class="goldgift">
<%self:goldsec goldtype="autorenew">
<%utils:round_field title="${'Monthly or yearly?'}">
- ${radio_type("period", "monthly", _("$3.99 / month"), "", False)}<br/>
- ${radio_type("period", "yearly", _("$29.99 / year (which works out to just $2.50 / month!)"),
- "", True)}<br/>
+ ${radio_type("period", "monthly", _("%s / month") % g.gold_month_price, "", False)}<br/>
+ ${radio_type("period", "yearly", _("%s / year (which works out to just %s / month!)")
+ % (g.gold_year_price, g.gold_year_price / 12),
+ "", True)}<br/>
<button type="submit" class="btn gold-button">${_("subscribe")}</button>
<span class="status"></span>
</%utils:round_field>
View
2  r2/r2/templates/goldinfopage.html
@@ -99,7 +99,7 @@
</section>
<footer>
<h1>${_('become a member today.')}</h1>
- <p>${_('reddit gold is $3.99 / month, or $29.99 for a year.')}</p>
+ <p>${_('reddit gold is %(gold_month_price)s / month, or %(gold_year_price)s for a year.') % thing.prices}</p>
<a class="buy-gold-button" href="/gold">${_('buy reddit gold')}</a>
</footer>
</section>
Please sign in to comment.
Something went wrong with that request. Please try again.