Updated plaid libraries to 9.2.0
This commit is contained in:
parent
2555b43809
commit
7172ec9f0d
@ -1,6 +1,10 @@
|
|||||||
from .abstract import AbstractConnectionClient
|
from .abstract import AbstractConnectionClient
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import plaid
|
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 os
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
@ -39,15 +43,26 @@ class Connection(AbstractConnectionClient):
|
|||||||
# PLAID_COUNTRY_CODES is a comma-separated list of countries for which users
|
# PLAID_COUNTRY_CODES is a comma-separated list of countries for which users
|
||||||
# will be able to select institutions from.
|
# will be able to select institutions from.
|
||||||
self.PLAID_COUNTRY_CODES = settings.PLAID_COUNTRY_CODES
|
self.PLAID_COUNTRY_CODES = settings.PLAID_COUNTRY_CODES
|
||||||
self.client = plaid.Client(
|
|
||||||
client_id=self.PLAID_CLIENT_ID,
|
configuration = plaid.Configuration(
|
||||||
secret=self.PLAID_SECRET,
|
host=self.PLAID_ENV,
|
||||||
environment=self.PLAID_ENV,
|
api_key={
|
||||||
public_key=self.PLAID_PUBLIC_KEY,
|
'clientId': self.PLAID_CLIENT_ID,
|
||||||
# api_version='2019-05-29',
|
'secret': self.PLAID_SECRET,
|
||||||
api_version='2020-09-14',
|
}
|
||||||
#webhook='https://qrtr-services.herokuapp.com/connection/plaid-webhook/'
|
)
|
||||||
)
|
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')
|
public_key = self.credentials.get('public_token')
|
||||||
auth_token = self.credentials.get('auth_token')
|
auth_token = self.credentials.get('auth_token')
|
||||||
if not auth_token and public_key:
|
if not auth_token and public_key:
|
||||||
@ -66,8 +81,11 @@ class Connection(AbstractConnectionClient):
|
|||||||
|
|
||||||
def get_auth_token(self, public_token):
|
def get_auth_token(self, public_token):
|
||||||
try:
|
try:
|
||||||
exchange_response = self.client.Item.public_token.exchange(
|
exchange_request = ItemPublicTokenExchangeRequest(
|
||||||
public_token)
|
public_token=public_token
|
||||||
|
)
|
||||||
|
exchange_response = self.client.item_public_token_exchange(
|
||||||
|
exchange_request)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error Occurred")
|
print("Error Occurred")
|
||||||
print(e)
|
print(e)
|
||||||
@ -82,7 +100,8 @@ class Connection(AbstractConnectionClient):
|
|||||||
if not auth_token:
|
if not auth_token:
|
||||||
raise Exception("Missing Auth Token")
|
raise Exception("Missing Auth Token")
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
accounts = None
|
accounts = None
|
||||||
@ -103,8 +122,13 @@ class Connection(AbstractConnectionClient):
|
|||||||
if not end_date:
|
if not end_date:
|
||||||
end_date = '{:%Y-%m-%d}'.format(datetime.datetime.now())
|
end_date = '{:%Y-%m-%d}'.format(datetime.datetime.now())
|
||||||
try:
|
try:
|
||||||
transactions_resp = self.client.Transactions.get(
|
transactions_req = TransactionsGetRequest(
|
||||||
auth_token, start_date, end_date)
|
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:
|
except plaid.errors.PlaidError as e:
|
||||||
return format_error(e)
|
return format_error(e)
|
||||||
return transactions_resp.get("transactions")
|
return transactions_resp.get("transactions")
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import dj_database_url
|
import dj_database_url
|
||||||
|
import plaid
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_CONNECTION = dj_database_url.parse(os.environ.get("DATABASE_URL"))
|
DEFAULT_CONNECTION = dj_database_url.parse(os.environ.get("DATABASE_URL"))
|
||||||
@ -17,8 +18,12 @@ DEBUG = True
|
|||||||
|
|
||||||
ALLOWED_HOSTS = ['*']
|
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_PRODUCTS = os.environ.get("PLAID_PRODUCTS")
|
||||||
PLAID_ENV = os.environ.get("PLAID_ENV")
|
|
||||||
PLAID_PUBLIC_KEY = os.environ.get("PLAID_PUBLIC_KEY")
|
PLAID_PUBLIC_KEY = os.environ.get("PLAID_PUBLIC_KEY")
|
||||||
PLAID_SECRET = os.environ.get("PLAID_SECRET")
|
PLAID_SECRET = os.environ.get("PLAID_SECRET")
|
||||||
PLAID_CLIENT_ID = os.environ.get("PLAID_CLIENT_ID")
|
PLAID_CLIENT_ID = os.environ.get("PLAID_CLIENT_ID")
|
||||||
|
|||||||
@ -15,7 +15,7 @@ djangorestframework==3.12.4
|
|||||||
djangorestframework-simplejwt==4.6.0
|
djangorestframework-simplejwt==4.6.0
|
||||||
idna==2.10
|
idna==2.10
|
||||||
oauthlib==3.1.0
|
oauthlib==3.1.0
|
||||||
plaid-python==3.0.0
|
plaid-python==9.2.0
|
||||||
psycopg2==2.8.6
|
psycopg2==2.8.6
|
||||||
pycparser==2.20
|
pycparser==2.20
|
||||||
PyJWT==2.1.0
|
PyJWT==2.1.0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user