QRTR-78 finalizing plaid auth flow.
This commit is contained in:
parent
5be69de69b
commit
6b053346d4
@ -45,11 +45,12 @@ class Connection(AbstractConnectionClient):
|
|||||||
environment=self.PLAID_ENV,
|
environment=self.PLAID_ENV,
|
||||||
api_version='2019-05-29')
|
api_version='2019-05-29')
|
||||||
print("Getting Public Key")
|
print("Getting Public Key")
|
||||||
public_key = self.credentials.get('public_key')
|
public_key = self.credentials.get('public_token')
|
||||||
print("Retrieving auth token")
|
print("Retrieving auth token")
|
||||||
if not self.credentials.get('auth_token') and public_key:
|
if not self.credentials.get('auth_token') and public_key:
|
||||||
self.credentials['auth_token'] = self.get_auth_token(public_key)
|
self.credentials['auth_token'] = self.get_auth_token(public_key)
|
||||||
print("Plaid Connection successful")
|
print("Plaid Connection successful")
|
||||||
|
print(self.credentials)
|
||||||
|
|
||||||
def get_auth_token(self, public_token):
|
def get_auth_token(self, public_token):
|
||||||
try:
|
try:
|
||||||
@ -61,6 +62,18 @@ class Connection(AbstractConnectionClient):
|
|||||||
return format_error(e)
|
return format_error(e)
|
||||||
access_token = exchange_response['access_token']
|
access_token = exchange_response['access_token']
|
||||||
return access_token
|
return access_token
|
||||||
|
|
||||||
|
def get_accounts(self, auth_token=None):
|
||||||
|
if not auth_token:
|
||||||
|
auth_token = self.credentials.get('auth_token')
|
||||||
|
if not auth_token:
|
||||||
|
raise Exception("Missing Auth Token")
|
||||||
|
try:
|
||||||
|
accounts = self.client.Accounts.get(auth_token)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
accounts = None
|
||||||
|
return accounts
|
||||||
|
|
||||||
def get_transactions(
|
def get_transactions(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@ -4,8 +4,11 @@ from rest_framework.response import Response
|
|||||||
from .models import Connection, ConnectionType
|
from .models import Connection, ConnectionType
|
||||||
from .serializers import ConnectionSerializer
|
from .serializers import ConnectionSerializer
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
from rest_framework.decorators import permission_classes
|
||||||
from qrtr_account.models import Account
|
from qrtr_account.models import Account
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
import importlib
|
import importlib
|
||||||
|
import json
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
@ -13,6 +16,7 @@ import importlib
|
|||||||
class ConnectionViewSet(viewsets.ModelViewSet):
|
class ConnectionViewSet(viewsets.ModelViewSet):
|
||||||
"""API endpoint that allows connections to be seen or created
|
"""API endpoint that allows connections to be seen or created
|
||||||
"""
|
"""
|
||||||
|
# permission_classes = [IsAuthenticated]
|
||||||
queryset = Connection.objects.all()
|
queryset = Connection.objects.all()
|
||||||
serializer_class = ConnectionSerializer
|
serializer_class = ConnectionSerializer
|
||||||
# Make connections somewhat immutable from the users perspective
|
# Make connections somewhat immutable from the users perspective
|
||||||
@ -47,10 +51,17 @@ class ConnectionViewSet(viewsets.ModelViewSet):
|
|||||||
print(request)
|
print(request)
|
||||||
plaid = importlib.import_module(f"connection.connections.plaid_client")
|
plaid = importlib.import_module(f"connection.connections.plaid_client")
|
||||||
conn_type = ConnectionType.objects.get(name="Plaid")
|
conn_type = ConnectionType.objects.get(name="Plaid")
|
||||||
conn = Connection.objects.create(name=name, type=conn_type,
|
conn, created = Connection.objects \
|
||||||
credentials=request.data,
|
.get_or_create(name=name, type=conn_type,
|
||||||
account=account)
|
defaults={
|
||||||
|
"credentials": request.data,
|
||||||
|
"account": account
|
||||||
|
})
|
||||||
plaid_client = plaid.Connection(request.data)
|
plaid_client = plaid.Connection(request.data)
|
||||||
conn.credentials = plaid_client.credentials
|
conn.credentials = plaid_client.credentials
|
||||||
conn.save()
|
conn.save()
|
||||||
return Response(200)
|
return Response(plaid_client.get_accounts())
|
||||||
|
|
||||||
|
@action(detail=True, methods=['get'], url_path='accounts')
|
||||||
|
def get_accounts(self):
|
||||||
|
pass
|
||||||
Loading…
Reference in New Issue
Block a user