Example #1
0
    def get(self, request, *args, **kwargs):
        self.object = self.get_object()

        if 'code' in request.GET:
            redirect_url = request.build_absolute_uri(
                reverse('brambling_dwolla_connect'))
            api_type = request.GET['api']
            dwolla_prep(api_type)
            redirect_url = dwolla_redirect_url(
                self.object,
                api_type,
                request,
                next_url=request.GET.get('next_url'))
            oauth_tokens = oauth.get(request.GET['code'],
                                     redirect=redirect_url)
            if 'access_token' in oauth_tokens:
                token = oauth_tokens['access_token']

                # Now get account info.
                account_info = accounts.full(token)

                try:
                    account = DwollaAccount.objects.get(
                        api_type=api_type, user_id=account_info['Id'])
                except DwollaAccount.DoesNotExist:
                    account = DwollaAccount(api_type=api_type,
                                            user_id=account_info['Id'])

                account.set_tokens(oauth_tokens)

                account.save()
                if self.object.get_dwolla_account(api_type) != account:
                    if api_type == LIVE:
                        self.object.dwolla_account = account
                    else:
                        self.object.dwolla_test_account = account
                    self.object.save()
                messages.success(request, "Dwolla account connected!")
            elif 'error_description' in oauth_tokens:
                messages.error(request, oauth_tokens['error_description'])
            else:
                messages.error(request,
                               "Unknown error during dwolla connection.")
        elif 'error_description' in request.GET:
            messages.error(request, request.GET['error_description'])
        else:
            messages.error(request, "Unknown error during dwolla connection.")

        return HttpResponseRedirect(self.get_success_url())
    def get(self, request, *args, **kwargs):
        self.object = self.get_object()
        redirect_url = self.object.get_dwolla_connect_url()
        api_type = request.GET['api']
        if 'code' in request.GET:
            qs = request.GET.copy()
            del qs['code']
            if qs:
                redirect_url += "?" + "&".join([k + "=" + v
                                                for k, v in qs.iteritems()])
            dwolla_prep(api_type)
            oauth_tokens = oauth.get(request.GET['code'],
                                     redirect=request.build_absolute_uri(redirect_url))
            if 'access_token' in oauth_tokens:
                token = oauth_tokens['access_token']

                # Now get account info.
                account_info = accounts.full(token)

                if api_type == LIVE:
                    self.object.dwolla_user_id = account_info['Id']
                else:
                    self.object.dwolla_test_user_id = account_info['Id']

                dwolla_set_tokens(self.object, api_type, oauth_tokens)

                self.object.save()
                messages.success(request, "Dwolla account connected!")
            elif 'error_description' in oauth_tokens:
                messages.error(request, oauth_tokens['error_description'])
            else:
                messages.error(request, "Unknown error during dwolla connection.")
        elif 'error_description' in request.GET:
            messages.error(request, request.GET['error_description'])
        else:
            messages.error(request, "Unknown error during dwolla connection.")

        return HttpResponseRedirect(self.get_success_url())
Example #3
0
constants.client_id = "zbDwIC0dWCVU7cQtfvGwVwVjvxwQfjaTgkVi+FZOmKqPBzK5JG"
constants.client_secret = "ckmgwJz9h/fZ09unyXxpupCyrmAMe0bnUiMHF/0+SDaR9RHe99"
constants.access_token = "aK6DdCVlIsR1hKvTbp8VCwnvci8cwaTLlW9edtbHJVmKoopnoe"

# Example 1: Get basic information for a user via
# their Dwolla ID

print(accounts.basic('812-202-3784'))
# Return: {u'Latitude': 0, u'Id': u'812-202-3784', u'Longitude': 0, u'Name': u'David Stancu'}


# Example 2: Get full account information for
# the user associated with the current OAuth token

print(accounts.full())
# Return: 
# {u'City': u'New York', u'Name': u'David Stancu', u'Longitude': 0, u'State': u'NY', u'Latitude': 0, u'Type': u'Personal', u'Id': u'812-202-3784'}


# Example 3: Get the balance of the account for
# the user associated with the current OAuth token

print(accounts.balance())
# Return:
# 21.97


# Example 4: Get users near a certain geographical
# location
Example #4
0
constants.client_id = "zbDwIC0dWCVU7cQtfvGwVwVjvxwQfjaTgkVi+FZOmKqPBzK5JG"
constants.client_secret = "ckmgwJz9h/fZ09unyXxpupCyrmAMe0bnUiMHF/0+SDaR9RHe99"
constants.access_token = "aK6DdCVlIsR1hKvTbp8VCwnvci8cwaTLlW9edtbHJVmKoopnoe"

# Example 1: Get basic information for a user via
# their Dwolla ID

print accounts.basic('812-202-3784')
# Return: {u'Latitude': 0, u'Id': u'812-202-3784', u'Longitude': 0, u'Name': u'David Stancu'}


# Example 2: Get full account information for
# the user associated with the current OAuth token

print accounts.full()
# Return: 
# {u'City': u'New York', u'Name': u'David Stancu', u'Longitude': 0, u'State': u'NY', u'Latitude': 0, u'Type': u'Personal', u'Id': u'812-202-3784'}


# Example 3: Get the balance of the account for
# the user associated with the current OAuth token

print accounts.balance()
# Return:
# 21.97


# Example 4: Get users near a certain geographical
# location
Example #5
0
 def testfull(self):
     accounts.full(alternate_token='AN OAUTH TOKEN', dwollaparse='dwolla')
     accounts.r._get.assert_any_call('/users', {}, {'alternate_token':'AN OAUTH TOKEN', 'dwollaparse':'dwolla'})
Example #6
0
 def testfull(self):
     accounts.full(alternate_token='AN OAUTH TOKEN', dwollaparse='dwolla')
     accounts.r._get.assert_any_call('/users', {}, {
         'alternate_token': 'AN OAUTH TOKEN',
         'dwollaparse': 'dwolla'
     })
Example #7
0
constants.sandbox = False

constants.client_id = "zbDwIC0dWCVU7cQtfvGwVwVjvxwQfjaTgkVi+FZOmKqPBzK5JG"
constants.client_secret = "ckmgwJz9h/fZ09unyXxpupCyrmAMe0bnUiMHF/0+SDaR9RHe99"
constants.access_token = "aK6DdCVlIsR1hKvTbp8VCwnvci8cwaTLlW9edtbHJVmKoopnoe"

# Example 1: Get basic information for a user via
# their Dwolla ID

print(accounts.basic('812-202-3784'))
# Return: {u'Latitude': 0, u'Id': u'812-202-3784', u'Longitude': 0, u'Name': u'David Stancu'}

# Example 2: Get full account information for
# the user associated with the current OAuth token

print(accounts.full())
# Return:
# {u'City': u'New York', u'Name': u'David Stancu', u'Longitude': 0, u'State': u'NY', u'Latitude': 0, u'Type': u'Personal', u'Id': u'812-202-3784'}

# Example 3: Get the balance of the account for
# the user associated with the current OAuth token

print(accounts.balance())
# Return:
# 21.97

# Example 4: Get users near a certain geographical
# location

print(accounts.nearby(40.7127, 74.0059))
# Return:
 def testfull(self):
     accounts.full()
     accounts.r._get.assert_any_call('/users', {'oauth_token': 'AN OAUTH TOKEN'}, dwollaparse='dwolla')