Updated plaid libraries to 9.2.0

This commit is contained in:
DJ Gillespie 2022-04-07 16:53:12 -06:00
parent 2555b43809
commit 7172ec9f0d
3 changed files with 45 additions and 16 deletions

View File

@ -1,6 +1,10 @@
from .abstract import AbstractConnectionClient
from django.conf import settings
import plaid
from plaid.api import plaid_api
from plaid.model.item_public_token_exchange_request import ItemPublicTokenExchangeRequest
from plaid.model.transactions_get_request import TransactionsGetRequest
from plaid.model.accounts_get_request import AccountsGetRequest
import os
import datetime
@ -39,15 +43,26 @@ class Connection(AbstractConnectionClient):
# PLAID_COUNTRY_CODES is a comma-separated list of countries for which users
# will be able to select institutions from.
self.PLAID_COUNTRY_CODES = settings.PLAID_COUNTRY_CODES
self.client = plaid.Client(
client_id=self.PLAID_CLIENT_ID,
secret=self.PLAID_SECRET,
environment=self.PLAID_ENV,
public_key=self.PLAID_PUBLIC_KEY,
# api_version='2019-05-29',
api_version='2020-09-14',
#webhook='https://qrtr-services.herokuapp.com/connection/plaid-webhook/'
configuration = plaid.Configuration(
host=self.PLAID_ENV,
api_key={
'clientId': self.PLAID_CLIENT_ID,
'secret': self.PLAID_SECRET,
}
)
api_client = plaid.ApiClient(configuration)
self.client = plaid_api.PlaidApi(api_client)
# self.client = plaid.Client(
# client_id=self.PLAID_CLIENT_ID,
# secret=self.PLAID_SECRET,
# environment=self.PLAID_ENV,
# public_key=self.PLAID_PUBLIC_KEY,
# # api_version='2019-05-29',
# api_version='2020-09-14',
# #webhook='https://qrtr-services.herokuapp.com/connection/plaid-webhook/'
# )
public_key = self.credentials.get('public_token')
auth_token = self.credentials.get('auth_token')
if not auth_token and public_key:
@ -66,8 +81,11 @@ class Connection(AbstractConnectionClient):
def get_auth_token(self, public_token):
try:
exchange_response = self.client.Item.public_token.exchange(
public_token)
exchange_request = ItemPublicTokenExchangeRequest(
public_token=public_token
)
exchange_response = self.client.item_public_token_exchange(
exchange_request)
except Exception as e:
print("Error Occurred")
print(e)
@ -82,7 +100,8 @@ class Connection(AbstractConnectionClient):
if not auth_token:
raise Exception("Missing Auth Token")
try:
accounts = self.client.Accounts.get(auth_token)
acc_request = AccountsGetRequest(access_token=auth_token)
accounts = self.client.accounts_get(acc_request).to_dict()
except Exception as e:
print(e)
accounts = None
@ -103,8 +122,13 @@ class Connection(AbstractConnectionClient):
if not end_date:
end_date = '{:%Y-%m-%d}'.format(datetime.datetime.now())
try:
transactions_resp = self.client.Transactions.get(
auth_token, start_date, end_date)
transactions_req = TransactionsGetRequest(
access_token=auth_token,
start_date=start_date,
end_date=end_date
)
transactions_resp = self.client.transactions_get(
transactions_req)
except plaid.errors.PlaidError as e:
return format_error(e)
return transactions_resp.get("transactions")

View File

@ -1,5 +1,6 @@
import os
import dj_database_url
import plaid
DEFAULT_CONNECTION = dj_database_url.parse(os.environ.get("DATABASE_URL"))
@ -17,8 +18,12 @@ DEBUG = True
ALLOWED_HOSTS = ['*']
plaid_envs = {'sandbox': plaid.Environment.Sandbox,
'development': plaid.Environment.Development,
'production': plaid.Environment.Production
}
PLAID_ENV = plaid_envs.get(os.environ.get("PLAID_ENV"), plaid_envs['sandbox'])
PLAID_PRODUCTS = os.environ.get("PLAID_PRODUCTS")
PLAID_ENV = os.environ.get("PLAID_ENV")
PLAID_PUBLIC_KEY = os.environ.get("PLAID_PUBLIC_KEY")
PLAID_SECRET = os.environ.get("PLAID_SECRET")
PLAID_CLIENT_ID = os.environ.get("PLAID_CLIENT_ID")

View File

@ -15,7 +15,7 @@ djangorestframework==3.12.4
djangorestframework-simplejwt==4.6.0
idna==2.10
oauthlib==3.1.0
plaid-python==3.0.0
plaid-python==9.2.0
psycopg2==2.8.6
pycparser==2.20
PyJWT==2.1.0