[QRTR-88] Updated plaid_client.py to pull and store the item_id; Moved serializers and viewsets to the connection app as well.
This commit is contained in:
parent
1e80dfd7fd
commit
e49a547dae
@ -4,6 +4,7 @@ from rest_framework import serializers
|
||||
from qrtr_account.models import Account, Bank, Institution, Transaction, Slice, Rule
|
||||
from user.models import User
|
||||
from connection.models import Connection, ConnectionType
|
||||
from connection.serializers import ConnectionTypeSerializer, ConnectionSerializer
|
||||
|
||||
|
||||
class UserAccountSerializer(serializers.HyperlinkedModelSerializer):
|
||||
@ -44,26 +45,6 @@ class GroupSerializer(serializers.HyperlinkedModelSerializer):
|
||||
fields = ['url', 'name']
|
||||
|
||||
|
||||
class ConnectionTypeSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = ConnectionType
|
||||
fields = ['url', 'name', 'filename']
|
||||
extra_kwargs = {
|
||||
'name': {'read_only': True},
|
||||
'filename': {'read_only': True}
|
||||
}
|
||||
|
||||
|
||||
class ConnectionSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Connection
|
||||
fields = ['url', 'name', 'type', 'credentials']
|
||||
extra_kwargs = {
|
||||
'type': {'write_only': True},
|
||||
'credentials': {'write_only': True}
|
||||
}
|
||||
|
||||
|
||||
class BankSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Bank
|
||||
|
||||
@ -47,10 +47,15 @@ class Connection(AbstractConnectionClient):
|
||||
auth_token = self.credentials.get('auth_token')
|
||||
if not auth_token and public_key:
|
||||
print("Getting Auth Token From Public Key")
|
||||
auth_token = self.get_auth_token(public_key)
|
||||
authorization = self.get_auth_token(public_key)
|
||||
print("AUTHORIZATION:")
|
||||
print(authorization)
|
||||
auth_token = authorization.get("access_token")
|
||||
item_id = authorization.get("item_id")
|
||||
if "error" in auth_token:
|
||||
raise ValueError(f"Unable to generate Auth Token, {auth_token}")
|
||||
self.credentials['auth_token'] = auth_token
|
||||
self.credentials['item_id'] = item_id
|
||||
print("Plaid Connection successful")
|
||||
print(self.credentials)
|
||||
|
||||
@ -63,7 +68,8 @@ class Connection(AbstractConnectionClient):
|
||||
print(e)
|
||||
return format_error(e)
|
||||
access_token = exchange_response['access_token']
|
||||
return access_token
|
||||
item_id = exchange_response['item_id']
|
||||
return {"access_token":access_token, "item_id":item_id}
|
||||
|
||||
def get_accounts(self, auth_token=None):
|
||||
if not auth_token:
|
||||
|
||||
@ -1,5 +1,15 @@
|
||||
from .models import Connection
|
||||
from rest_framework import serializers
|
||||
from .models import ConnectionType, Connection
|
||||
|
||||
|
||||
class ConnectionTypeSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = ConnectionType
|
||||
fields = ['url', 'name', 'filename']
|
||||
extra_kwargs = {
|
||||
'name': {'read_only': True},
|
||||
'filename': {'read_only': True}
|
||||
}
|
||||
|
||||
|
||||
class ConnectionSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
from rest_framework import routers
|
||||
from .views import ConnectionViewSet
|
||||
from django.urls import include, path
|
||||
|
||||
ROUTER = routers.SimpleRouter()
|
||||
ROUTER.register(r'', ConnectionViewSet)
|
||||
urlpatterns = ROUTER.urls
|
||||
urlpatterns = [
|
||||
path('', include(ROUTER.urls)),
|
||||
]
|
||||
|
||||
@ -9,10 +9,17 @@ from qrtr_account.models import Account
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
import importlib
|
||||
import json
|
||||
from .serializers import ConnectionSerializer, ConnectionTypeSerializer
|
||||
from django.db import transaction
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
class ConnectionTypeViewSet(viewsets.ModelViewSet):
|
||||
queryset = ConnectionType.objects.all()
|
||||
serializer_class = ConnectionTypeSerializer
|
||||
|
||||
|
||||
class ConnectionViewSet(viewsets.ModelViewSet):
|
||||
"""API endpoint that allows connections to be seen or created
|
||||
"""
|
||||
@ -66,6 +73,7 @@ class ConnectionViewSet(viewsets.ModelViewSet):
|
||||
except Exception:
|
||||
return Response(status=status.HTTP_500,
|
||||
data="ERROR: Unable to contact Plaid")
|
||||
with transaction.atomic():
|
||||
conn, created = Connection.objects \
|
||||
.get_or_create(name=name, type=conn_type,
|
||||
defaults={
|
||||
|
||||
@ -31,11 +31,11 @@ from qrtr_account.views import (AccountViewSet,
|
||||
InstitutionViewSet,
|
||||
TransactionViewSet,
|
||||
SliceViewSet,
|
||||
ConnectionViewSet,
|
||||
ConnectionTypeViewSet,
|
||||
FacebookLogin,
|
||||
TwitterLogin)
|
||||
|
||||
from connection.views import ConnectionViewSet, ConnectionTypeViewSet
|
||||
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'users', UserViewSet)
|
||||
|
||||
0
qrtr_account/serializers.py
Normal file
0
qrtr_account/serializers.py
Normal file
@ -60,24 +60,6 @@ class TransactionViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
serializer_class = TransactionSerializer
|
||||
|
||||
|
||||
class ConnectionTypeViewSet(viewsets.ModelViewSet):
|
||||
queryset = ConnectionType.objects.all()
|
||||
serializer_class = ConnectionTypeSerializer
|
||||
|
||||
|
||||
class ConnectionViewSet(viewsets.ModelViewSet):
|
||||
"""API endpoint that allows connections to be seen or created
|
||||
"""
|
||||
queryset = Connection.objects.all()
|
||||
serializer_class = ConnectionSerializer
|
||||
# Make connections somewhat immutable from the users perspective
|
||||
http_method_names = [
|
||||
'get',
|
||||
'post',
|
||||
'delete',
|
||||
'options']
|
||||
|
||||
|
||||
class SliceViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
"""API endpoint that allows Banks to be viewed.
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user