Permalink
Browse files

RedditGifts gold controller.

  • Loading branch information...
1 parent 6ce383e commit a4e0aa022fdd32b42606987101da49bcaf78d870 @bsimpson63 bsimpson63 committed Feb 20, 2013
Showing with 62 additions and 1 deletion.
  1. +2 −0 r2/example.ini
  2. +2 −0 r2/r2/config/routing.py
  3. +1 −0 r2/r2/controllers/__init__.py
  4. +57 −1 r2/r2/controllers/ipn.py
View
@@ -93,6 +93,8 @@ COINBASE_BUTTONID_ONETIME_1YR =
COINBASE_BUTTONID_ONETIME_2YR =
COINBASE_BUTTONID_ONETIME_3YR =
+RG_SECRET =
+
# -- feature toggles --
disable_ads = false
disable_captcha = false
View
@@ -266,6 +266,8 @@ def make_map():
action='goldwebhook')
mc('/api/coinbasewebhook/gold/:secret', controller='coinbase',
action='goldwebhook')
+ mc('/api/rgwebhook/gold/:secret', controller='redditgifts',
+ action='goldwebhook')
mc('/api/ipn/:secret', controller='ipn', action='ipn')
mc('/ipn/:secret', controller='ipn', action='ipn')
mc('/api/:action/:url_user', controller='api',
@@ -84,5 +84,6 @@ def load_controllers():
from ipn import IpnController
from ipn import StripeController
from ipn import CoinbaseController
+ from ipn import RedditGiftsController
_reddit_controllers.update((name.lower(), obj) for name, obj in locals().iteritems())
View
@@ -35,7 +35,7 @@
import stripe
from r2.controllers.reddit_base import RedditController
-from r2.lib.filters import _force_unicode
+from r2.lib.filters import _force_unicode, _force_utf8
from r2.lib.log import log_text
from r2.lib.strings import strings
from r2.lib.utils import randstr, tup
@@ -788,6 +788,62 @@ def process_response(cls):
return status, passthrough, transaction_id, pennies, months
+class RedditGiftsController(GoldPaymentController):
+ """Handle notifications of gold purchases from reddit gifts.
+
+ Payment is handled by reddit gifts. Once an order is complete they can hit
+ this route to apply gold to a user's account.
+
+ The post should include data in the form:
+ {
+ 'transaction_id', transaction_id,
+ 'goldtype': goldtype,
+ 'buyer': buyer name,
+ 'pennies': pennies,
+ 'months': months,
+ ['recipient': recipient name,]
+ ['giftmessage': message,]
+ ['signed': bool,]
+ }
+
+ """
+
+ name = 'redditgifts'
+ webhook_secret = g.RG_SECRET
+ event_type_mappings = {'succeeded': 'succeeded'}
+
+ def process_response(self):
+ data = request.POST
+
+ transaction_id = 'RG%s' % data['transaction_id']
+ pennies = int(data['pennies'])
+ months = int(data['months'])
+ status = 'succeeded'
+
+ buyer_name = data['buyer']
+ goldtype = data['goldtype']
+
+ buyer = Account._by_name(buyer_name)
+
+ blob = {
+ 'goldtype': goldtype,
+ 'account_id': buyer._id,
+ 'account_name': buyer.name,
+ 'status': 'initialized',
+ }
+
+ if goldtype == 'gift':
+ blob['recipient'] = data['recipient']
+ giftmessage = data.get('giftmessage', None)
+ blob['giftmessage'] = _force_utf8(giftmessage)
+ signed = data.get('signed')
+ blob['signed'] = True if signed == 'True' else False
+
+ passthrough = generate_blob(blob)
+
+ return status, passthrough, transaction_id, pennies, months
+
+
class GoldException(Exception): pass

0 comments on commit a4e0aa0

Please sign in to comment.