Пример #1
0
 def get_initial(self):
     if self.request.method == "GET":
         tokens = self.get_token()
         access_token = tokens['access_token']
         refresh_token = tokens['refresh_token']
         dwolla_id = DwollaUser(access_token).get_account_info()['Id']
         funding_sources = DwollaUser(access_token).get_funding_sources()
         choices = [(source['Id'], source['Name'])
                    for source in funding_sources]
         # choices.extend([('', 'Dwolla Account Balance')])
         self.request.session['dwolla_funds_source_choices'] = choices
         return {
             "pin": "",
             "token": access_token,
             "refresh_token": refresh_token,
             "dwolla_id": dwolla_id
         }
     else:
         return super(OAuthConfirmationView, self).get_initial()
Пример #2
0
def send_funds(token,
               dwolla_account,
               amount,
               pin,
               notes=None,
               funds_source=None,
               metadata={}):
    dwolla_user = DwollaUser(token)
    tid = dwolla_user.send_funds(amount,
                                 dwolla_account,
                                 pin,
                                 notes=notes,
                                 funds_source=funds_source,
                                 metadata=metadata)
    return tid
Пример #3
0
 def clean(self):
     warning_message = (
         'You have chosen your Dwolla balance for you funding '
         'source and the balance is less than $1.00.  Be sure '
         'to fund the account balance immediately so we can '
         'process payment for your subscriptions on the first '
         'of next month.')
     cleaned_data = super(PinForm, self).clean()
     data = cleaned_data['pin']
     token = cleaned_data['token']
     funds_source = cleaned_data['funds_source']
     if not data.isdigit():
         self.add_error('pin', "The PIN must only contain numbers")
     else:
         bogus_funds_source = "Devote.IO bogus funds source request to verify user pin"
         notes = "Verifying PIN via invalid funds source"
         try:
             send_funds(token,
                        DWOLLA_ACCOUNT['user_id'],
                        0.01,
                        data,
                        notes,
                        funds_source=bogus_funds_source)
         except DwollaAPIError as e:
             """ If error is invalid funding, then the PIN verified
             This is a hack because Dwolla doesn't have
             an API call to verify a PIN
             """
             if e.message == 'Invalid account PIN':
                 self.add_error('pin', e.message)
             elif "Invalid funding source provided" in e.message:
                 if funds_source == "Balance" and \
                    DwollaUser(token).get_funding_source("Balance")["Balance"] < 1:
                     messages.warning(self.request,
                                      warning_message,
                                      extra_tags='sticky')
             else:
                 raise
Пример #4
0
# Include the Dwolla REST Client
from dwolla import DwollaUser

# Include any required keys
import _keys

# Instantiate a new Dwolla User client
# And, Seed a previously generated access token
DwollaUser = DwollaUser(_keys.token)
'''
    EXAMPLE 1:
      Get transaction statistics for the
      user with the given OAuth token
'''
stats = DwollaUser.get_transaction_stats()
print stats
'''
    EXAMPLE 2:
      Get a list of recent transactions for 
      the user with the given OAuth token
'''
transactions = DwollaUser.get_transaction_list()
print transactions
'''
    EXAMPLE 3:
      Get detailed information for the transaction
      specified with transaction_id
'''
transaction_id = transactions[0]['Id']
transaction = DwollaUser.get_transaction(transaction_id)
print transaction
Пример #5
0
'''
Dwolla makes it easy to send money to anyone who's connected to the internet. In this example know Dwolla by sending money 
to your email address. 
'''

email = '*****@*****.**'  # Your email ID

# Dwolla REST Client
from dwolla import DwollaUser

Dwolla = DwollaUser('OAUTH_TOKEN')

transaction = Dwolla.send_funds(0.01, email, 'PIN', dest_type='Email')

print('Transaction ID: %s' % transaction)
Пример #6
0
def found_item():
    item = str(request.values.get('Body', None))
    number = format(request.values.get('From', None))
    
    message = ""
    if internet: 
        db = mongo.db
        number_obj = db.numbers.find_one({'Number': number})
    active_hunt = None
    if number_obj != None: 
        active_hunt = number_obj['activehunt']	
    
    #User starts a hunt
    if active_hunt == None:
    	#Checks whether 'item' (a hunt name) is a valid huntname
    	active_hunt = db.hunts.find_one({'huntname':item})
    	if active_hunt == None:
    	    #hunt is not valid
	    message = message + "Hunt ("+item+") not found."
	    resp = twilio.twiml.Response()
	    resp.message(message)
	    return str(resp)
	else:
            if internet:
                #hunt is valid, so add a number to numbers database
                db.numbers.insert({"Number": number, "activehunt": active_hunt, "cluenumber": 0})
                clues = json.loads(active_hunt['clues'])
                message = message + "You have registed for " + active_hunt['huntname'] + ". Clue:" + clues[0]
                resp = twilio.twiml.Response()
                #update participants
                participants = active_hunt['participants']
                db.hunts.update({'_id':active_hunt['_id']},{'$set':{'participants':participants+1}},upsert=False, multi=False)
                resp.message(message)
                return str(resp)	    
            else:
                return "no internet"
    #number is registered with a hunt
    user = db.numbers.find_one({'Number':number})
    keys = json.loads(active_hunt['keys'])
    clues = json.loads(active_hunt['clues'])
    index = user['cluenumber']    

    if item == keys[index]:
    	#Correct answer
    	index = index + 1
        message = "Congrats! You found " + item + ". "
        #update cluenumber
        db.numbers.update({'_id':user['_id']},{'$set':{'cluenumber':index}},upsert=False, multi=False)
        if index >= len(keys):
            #You're done. Remove number from database
            active_hunt = db.hunts.find_one({'huntname':user['activehunt']['huntname']})
            left = active_hunt['prize']
            reward = active_hunt['reward']
            if left>=reward:
                db.numbers.update({'_id':active_hunt['_id']},{'$set':{'prize':left-reward}},upsert=False, multi=False)
                person = db.users.find_one({'Email':active_hunt['Email']})
                DU = DwollaUser(person['token'])
                DU.send_funds(active_hunt['reward'], user['Number'][2:], person['pin'], dest_type="Phone")
                message = message + "Congratulations! You have won $("+str(active_hunt['reward'])+")!"
                resp = twilio.twiml.Response()
                resp.message(message)
                return str(resp)
            else:
                message = message + "Congratulations! You have won. However, all the rewards have already been plundered. :'("
                resp = twilio.twiml.Response()
                resp.message(message)
                return str(resp)
                
            if internet:
                db.numbers.remove({'Number':number})
        else:
            message = message + "Clue:" + clues[index]
            resp = twilio.twiml.Response()
            resp.message(message)    
    else:
        message = "Sorry (" + item+") is not the right answer."   
        resp = twilio.twiml.Response()
        resp.message(message)
    return str(resp)