Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,12 @@ import uuid
|
|
| 5 |
import os
|
| 6 |
from dotenv import load_dotenv, dotenv_values
|
| 7 |
from datetime import datetime, date
|
| 8 |
-
import
|
| 9 |
-
from plaid import
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
import stripe
|
| 11 |
|
| 12 |
# Set page config
|
|
@@ -165,37 +169,42 @@ class CitibankService:
|
|
| 165 |
# Plaid Service Class
|
| 166 |
class PlaidService:
|
| 167 |
def __init__(self, client_id, secret, environment):
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
| 173 |
)
|
|
|
|
|
|
|
| 174 |
|
| 175 |
def create_link_token(self):
|
| 176 |
-
|
| 177 |
-
'
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
'
|
| 181 |
-
'
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
response = self.client.LinkToken.create(configs)
|
| 186 |
-
return response['link_token']
|
| 187 |
|
| 188 |
def exchange_public_token(self, public_token):
|
| 189 |
-
response = self.client.
|
| 190 |
-
return response
|
| 191 |
|
| 192 |
def get_accounts(self, access_token):
|
| 193 |
-
response = self.client.
|
| 194 |
-
return response
|
| 195 |
|
| 196 |
def get_transactions(self, access_token, start_date, end_date):
|
| 197 |
-
response = self.client.
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
# Main application logic
|
| 201 |
|
|
|
|
| 5 |
import os
|
| 6 |
from dotenv import load_dotenv, dotenv_values
|
| 7 |
from datetime import datetime, date
|
| 8 |
+
from plaid.model.products import Products
|
| 9 |
+
from plaid.model.country_code import CountryCode
|
| 10 |
+
from plaid.model.link_token_create_request import LinkTokenCreateRequest
|
| 11 |
+
from plaid.configuration import Configuration
|
| 12 |
+
from plaid.api_client import ApiClient
|
| 13 |
+
from plaid.api.plaid_api import PlaidApi
|
| 14 |
import stripe
|
| 15 |
|
| 16 |
# Set page config
|
|
|
|
| 169 |
# Plaid Service Class
|
| 170 |
class PlaidService:
|
| 171 |
def __init__(self, client_id, secret, environment):
|
| 172 |
+
configuration = Configuration(
|
| 173 |
+
host=f"https://{environment}.plaid.com",
|
| 174 |
+
api_key={
|
| 175 |
+
'clientId': client_id,
|
| 176 |
+
'secret': secret,
|
| 177 |
+
}
|
| 178 |
)
|
| 179 |
+
api_client = ApiClient(configuration)
|
| 180 |
+
self.client = PlaidApi(api_client)
|
| 181 |
|
| 182 |
def create_link_token(self):
|
| 183 |
+
request = LinkTokenCreateRequest(
|
| 184 |
+
products=[Products('auth')],
|
| 185 |
+
client_name='TransactPro',
|
| 186 |
+
country_codes=[CountryCode('US')],
|
| 187 |
+
user={'client_user_id': str(uuid.uuid4())},
|
| 188 |
+
language='en'
|
| 189 |
+
)
|
| 190 |
+
response = self.client.link_token_create(request)
|
| 191 |
+
return response.link_token
|
|
|
|
|
|
|
| 192 |
|
| 193 |
def exchange_public_token(self, public_token):
|
| 194 |
+
response = self.client.item_public_token_exchange({'public_token': public_token})
|
| 195 |
+
return response.access_token
|
| 196 |
|
| 197 |
def get_accounts(self, access_token):
|
| 198 |
+
response = self.client.accounts_get({'access_token': access_token})
|
| 199 |
+
return response.accounts
|
| 200 |
|
| 201 |
def get_transactions(self, access_token, start_date, end_date):
|
| 202 |
+
response = self.client.transactions_get({
|
| 203 |
+
'access_token': access_token,
|
| 204 |
+
'start_date': start_date,
|
| 205 |
+
'end_date': end_date
|
| 206 |
+
})
|
| 207 |
+
return response.transactions
|
| 208 |
|
| 209 |
# Main application logic
|
| 210 |
|