finished up new link flow updates. Still need to implement secondary get_auth_token flow.
This commit is contained in:
parent
5b6c7bde1d
commit
e942f1a76e
@ -3,6 +3,8 @@ from django.conf import settings
|
||||
import os
|
||||
import datetime
|
||||
|
||||
import plaid
|
||||
from plaid.api import plaid_api
|
||||
from plaid.model.link_token_create_request import LinkTokenCreateRequest
|
||||
from plaid.model.link_token_create_request_user import LinkTokenCreateRequestUser
|
||||
from plaid.model.products import Products
|
||||
@ -20,7 +22,7 @@ def format_error(e):
|
||||
|
||||
class Connection(AbstractConnectionClient):
|
||||
|
||||
def __init__(self, credentials):
|
||||
def __init__(self, credentials, account_id=None):
|
||||
self.credentials = credentials.dict()
|
||||
|
||||
# Fill in your Plaid API keys -
|
||||
@ -28,7 +30,7 @@ class Connection(AbstractConnectionClient):
|
||||
self.PLAID_CLIENT_ID = settings.PLAID_CLIENT_ID
|
||||
self.PLAID_SECRET = settings.PLAID_SECRET
|
||||
self.PLAID_PUBLIC_KEY = settings.PLAID_PUBLIC_KEY
|
||||
# Use 'sandbox' to test with Plaid's Sandbox environment (username: user_good,
|
||||
# Use 'sandbox' to test with Plaid's Sandbox environment (usplaid-python==9.2.0ername: user_good,
|
||||
# password: pass_good)
|
||||
# Use `development` to test with live users and credentials and `production`
|
||||
# to go live
|
||||
@ -42,17 +44,26 @@ class Connection(AbstractConnectionClient):
|
||||
# will be able to select institutions from.
|
||||
self.PLAID_COUNTRY_CODES = settings.PLAID_COUNTRY_CODES
|
||||
|
||||
client_user_id = user.id
|
||||
configuration = plaid.Configuration(
|
||||
host=self.PLAID_ENV,
|
||||
api_key={
|
||||
'clientId': self.PLAID_CLIENT_ID,
|
||||
'secret': self.PLAID_SECRET,
|
||||
}
|
||||
)
|
||||
api_client = plaid.ApiClient(configuration)
|
||||
client = plaid_api.PlaidApi(api_client)
|
||||
|
||||
# Create a link_token for the given user
|
||||
request = LinkTokenCreateRequest(
|
||||
products=[Products("auth")],
|
||||
client_name="Qrtr Plaid",
|
||||
country_codes=[CountryCode('US')],
|
||||
redirect_uri='https://domainname.com/oauth-page.html',
|
||||
#redirect_uri='https://domainname.com/oauth-page.html',
|
||||
language='en',
|
||||
webhook='https://webhook.example.com',
|
||||
user=LinkTokenCreateRequestUser(
|
||||
client_user_id=client_user_id
|
||||
client_user_id=account_id
|
||||
)
|
||||
)
|
||||
response = client.link_token_create(request)
|
||||
|
||||
@ -37,14 +37,14 @@ class ConnectionViewSet(viewsets.ModelViewSet):
|
||||
def authenticate(self, request):
|
||||
print(request.data)
|
||||
print(request.data.keys())
|
||||
public_token = request.data.get("public_token")
|
||||
# public_token = request.data.get("public_token")
|
||||
name = request.data.get("name", "dummyName")
|
||||
account_id = request.data.get("account")
|
||||
print(f"Account ID Detected: {account_id}")
|
||||
if public_token is None:
|
||||
return Response(
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
data="ERROR: missing public_token")
|
||||
# if public_token is None:
|
||||
# return Response(
|
||||
# status=status.HTTP_400_BAD_REQUEST,
|
||||
# data="ERROR: missing public_token")
|
||||
if account_id is None:
|
||||
return Response(
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
@ -63,10 +63,10 @@ class ConnectionViewSet(viewsets.ModelViewSet):
|
||||
print(f"Account Found: {accounts[0]}")
|
||||
account = accounts[0]
|
||||
print(request)
|
||||
plaid_conn = importlib.import_module(f"connection.connections.plaid_client")
|
||||
plaid_conn = importlib.import_module(f"connection.connections.plaid_client_v2")
|
||||
conn_type = ConnectionType.objects.get(name="Plaid")
|
||||
try:
|
||||
plaid_client = plaid_conn.Connection(request.data)
|
||||
plaid_client = plaid_conn.Connection(request.data, account_id=account_id)
|
||||
except ValueError:
|
||||
return Response(status=status.HTTP_503,
|
||||
data="ERROR: Invalid public_token")
|
||||
@ -83,7 +83,7 @@ class ConnectionViewSet(viewsets.ModelViewSet):
|
||||
})
|
||||
conn.credentials = plaid_client.credentials
|
||||
conn.save()
|
||||
return Response(plaid_client.get_accounts())
|
||||
return Response(plaid_client.credentials)
|
||||
|
||||
@action(detail=False, methods=['post'], url_path='plaid-webhook',
|
||||
permission_classes=[AllowAny])
|
||||
|
||||
@ -16,8 +16,8 @@ djangorestframework-simplejwt==4.6.0
|
||||
drf-yasg==1.20.0
|
||||
idna==2.10
|
||||
oauthlib==3.1.0
|
||||
plaid-python==9.2.0
|
||||
psycopg2==2.8.6
|
||||
plaid_python==14.0.0
|
||||
psycopg2-binary==2.8.6
|
||||
pycparser==2.20
|
||||
PyJWT==2.1.0
|
||||
python3-openid==3.2.0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user