mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 15:58:06 -05:00
RedditGifts gold controller.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -35,7 +35,7 @@ from sqlalchemy.exc import IntegrityError
|
||||
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 @@ class CoinbaseController(GoldPaymentController):
|
||||
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user