Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
RedditGifts gold controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsimpson63 committed Feb 27, 2013
1 parent 6ce383e commit a4e0aa0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions r2/example.ini
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions r2/r2/config/routing.py
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions r2/r2/controllers/__init__.py
Expand Up @@ -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())
58 changes: 57 additions & 1 deletion r2/r2/controllers/ipn.py
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit a4e0aa0

Please sign in to comment.