Move gold prices to configuration parameters.

This commit is contained in:
Max Goodman
2012-11-05 16:44:39 -08:00
parent 4bf2c0e886
commit 440cb664ac
9 changed files with 68 additions and 18 deletions

View File

@@ -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 File

@@ -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 File

@@ -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 = {

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 File

@@ -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 @@
<%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 File

@@ -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>