Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Coinbase payments for reddit gold.

  • Loading branch information...
commit e301b34cdae7b15e8b1459c50e831fb5e777c74e 1 parent 3d51107
@bsimpson63 bsimpson63 authored
View
16 r2/example.ini
@@ -77,6 +77,22 @@ STRIPE_WEBHOOK_SECRET =
STRIPE_PUBLIC_KEY =
STRIPE_SECRET_KEY =
+COINBASE_WEBHOOK_SECRET =
+COINBASE_BUTTONID_ONETIME_1MO =
+COINBASE_BUTTONID_ONETIME_2MO =
+COINBASE_BUTTONID_ONETIME_3MO =
+COINBASE_BUTTONID_ONETIME_4MO =
+COINBASE_BUTTONID_ONETIME_5MO =
+COINBASE_BUTTONID_ONETIME_6MO =
+COINBASE_BUTTONID_ONETIME_7MO =
+COINBASE_BUTTONID_ONETIME_8MO =
+COINBASE_BUTTONID_ONETIME_9MO =
+COINBASE_BUTTONID_ONETIME_10MO =
+COINBASE_BUTTONID_ONETIME_11MO =
+COINBASE_BUTTONID_ONETIME_1YR =
+COINBASE_BUTTONID_ONETIME_2YR =
+COINBASE_BUTTONID_ONETIME_3YR =
+
# -- feature toggles --
disable_ads = false
disable_captcha = false
View
2  r2/r2/config/routing.py
@@ -264,6 +264,8 @@ def make_map():
mc('/api/stripecharge/gold', controller='stripe', action='goldcharge')
mc('/api/stripewebhook/gold/:secret', controller='stripe',
action='goldwebhook')
+ mc('/api/coinbasewebhook/gold/:secret', controller='coinbase',
+ action='goldwebhook')
mc('/api/ipn/:secret', controller='ipn', action='ipn')
mc('/ipn/:secret', controller='ipn', action='ipn')
mc('/api/:action/:url_user', controller='api',
View
1  r2/r2/controllers/__init__.py
@@ -82,5 +82,6 @@ def load_controllers():
from redirect import RedirectController
from ipn import IpnController
from ipn import StripeController
+ from ipn import CoinbaseController
_reddit_controllers.update((name.lower(), obj) for name, obj in locals().iteritems())
View
7 r2/r2/controllers/front.py
@@ -1041,7 +1041,7 @@ def GET_rules(self):
).render()
@validate(vendor=VOneOf("v", ("claimed-gold", "claimed-creddits",
- "paypal", "google-checkout"),
+ "paypal", "google-checkout", "coinbase"),
default="claimed-gold"))
def GET_goldthanks(self, vendor):
vendor_url = None
@@ -1062,6 +1062,11 @@ def GET_goldthanks(self, vendor):
elif vendor == "google-checkout":
claim_msg = vendor_claim_msg
vendor_url = "https://wallet.google.com/manage"
+ elif vendor == "coinbase":
+ claim_msg = _("thanks for buying reddit gold! your transaction is "
+ "being processed. if you have any questions please "
+ "email us at %(gold_email)s")
+ claim_msg = claim_msg % {'gold_email': g.goldthanks_email}
else:
abort(404)
View
20 r2/r2/controllers/ipn.py
@@ -765,6 +765,26 @@ def POST_goldcharge(self, form, jquery, token, passthrough, pennies, months):
send_system_message(c.user, subject, msg)
+class CoinbaseController(GoldPaymentController):
+ name = 'coinbase'
+ webhook_secret = g.COINBASE_WEBHOOK_SECRET
+ event_type_mappings = {
+ 'completed': 'succeeded',
+ 'cancelled': 'cancelled',
+ }
+
+ @classmethod
+ def process_response(cls):
+ event_dict = json.loads(request.body)
+ g.log.debug('event_dict: %s' % event_dict)
+ order = event_dict['order']
+ transaction_id = 'C%s' % order['id']
+ status = order['status'] # new/completed/cancelled
+ pennies = int(order['total_native']['cents'])
+ passthrough = order['custom']
+ return status, passthrough, transaction_id, pennies
+
+
class GoldException(Exception): pass
View
12 r2/r2/lib/pages/pages.py
@@ -1860,15 +1860,20 @@ def __init__(self, goldtype, period, months, signed,
quantity = None
google_id = None
stripe_key = None
+ coinbase_button_id = None
elif goldtype == "onetime":
if months < 12:
paypal_buttonid = g.PAYPAL_BUTTONID_ONETIME_BYMONTH
quantity = months
+ coinbase_name = 'COINBASE_BUTTONID_ONETIME_%sMO' % quantity
+ coinbase_button_id = getattr(g, coinbase_name, None)
else:
paypal_buttonid = g.PAYPAL_BUTTONID_ONETIME_BYYEAR
quantity = months / 12
months = quantity * 12
+ coinbase_name = 'COINBASE_BUTTONID_ONETIME_%sYR' % quantity
+ coinbase_button_id = getattr(g, coinbase_name, None)
summary = strings.gold_summary_onetime % dict(user=c.user.name,
amount=Score.somethings(months, "month"))
@@ -1880,9 +1885,13 @@ def __init__(self, goldtype, period, months, signed,
if months < 12:
paypal_buttonid = g.PAYPAL_BUTTONID_CREDDITS_BYMONTH
quantity = months
+ coinbase_name = 'COINBASE_BUTTONID_ONETIME_%sMO' % quantity
+ coinbase_button_id = getattr(g, coinbase_name, None)
else:
paypal_buttonid = g.PAYPAL_BUTTONID_CREDDITS_BYYEAR
quantity = months / 12
+ coinbase_name = 'COINBASE_BUTTONID_ONETIME_%sYR' % quantity
+ coinbase_button_id = getattr(g, coinbase_name, None)
if goldtype == "creddits":
summary = strings.gold_summary_creddits % dict(
@@ -1927,7 +1936,8 @@ def __init__(self, goldtype, period, months, signed,
google_id=google_id,
comment=comment, clone_template=clone_template,
paypal_buttonid=paypal_buttonid,
- stripe_key=stripe_key)
+ stripe_key=stripe_key,
+ coinbase_button_id=coinbase_button_id)
class CreditGild(Templated):
View
1  r2/r2/public/static/css/reddit.css
@@ -5337,6 +5337,7 @@ body:not(.gold) .allminus-link {
border: 1px solid #E1B000;
background-color: #fffdcc;
color: #6a4d00;
+ width: 510px;
}
.gold-form .note {
View
4 r2/r2/public/static/js/gold.js
@@ -44,7 +44,8 @@ r.gold = {
var form = $('.gold-form.cloneable:first').clone(),
authorName = $link.thing().find('.entry .author:first').text(),
message = r.strings.gold_summary_comment_gift.replace('%(recipient)s', authorName),
- passthroughs = form.find('.passthrough')
+ passthroughs = form.find('.passthrough'),
+ cbBaseUrl = form.find('[name="cbbaseurl"]').val()
form.removeClass('cloneable')
.attr('id', formId)
@@ -65,6 +66,7 @@ r.gold = {
form.removeClass('working')
passthroughs.val(token)
form.find('.stripe-gold').on('click', function() { window.open('/gold/creditgild/' + token) })
+ form.find('.coinbase-gold').on('click', function() { window.open(cbBaseUrl + "?c=" + token) })
form.find('button').removeAttr('disabled').removeClass('disabled')
})
View
14 r2/r2/templates/goldpayment.html
@@ -61,6 +61,10 @@
${self.paypal_button()}
%endif
+ %if thing.coinbase_button_id:
+ ${self.coinbase_button()}
+ %endif
+
%if thing.stripe_key:
${self.stripe_button()}
%endif
@@ -224,6 +228,16 @@
</form>
</%def>
+<%def name="coinbase_button()">
+ <button class="btn coinbase-gold gold-button gold-checkout"
+ data-vendor="coinbase"
+ %if not thing.clone_template:
+ onclick="window.open('https://coinbase.com/checkouts/${thing.coinbase_button_id}?c=${thing.passthrough}')"
+ %endif
+ >${_('Bitcoin')}</button>
+ <input type="hidden" name="cbbaseurl" value="https://coinbase.com/checkouts/${thing.coinbase_button_id}">
+</%def>
+
% if not thing.clone_template:
<script src="//checkout.google.com/files/digital/ga_post.js"
type="text/javascript"></script>
Please sign in to comment.
Something went wrong with that request. Please try again.