def test_ResourceNotFound_categories_with_suppressed_error(): Client.config({'suppress_http_errors': True}) client = Client('test_id', 'test_secret') response = client.category('pnc') assert response.status_code == 404 assert ( json.loads(response.content)['message'] == 'unable to find category' )
def test_ResourceNotFound_categories_with_suppressed_error(): Client.config({'suppress_http_errors': True}) client = Client('test_id', 'test_secret') response = client.category('pnc') assert response.status_code == 404 assert ( to_json(response)['message'] == 'unable to find category' )
def get_plaid_client(): Client.config({ 'url': settings.PLAID_API_URL }) return Client( client_id=settings.PLAID_CLIENT_ID, secret=settings.PLAID_CLIENT_SECRET )
def get_response(): client = Client(client_id='test_id', secret='test_secret', access_token='usertoken') client.config({'url':'https://tartan.plaid.com'}) account_type = 'ins_100088' user = '******' pwd = 'plaid_good' response = client.connect(account_type, { 'username': user, 'password': pwd }) response = client.connect_step(account_type, 'tomato') return response.json() # This is a dict
def _get_plaid_client(passphrase, access_token = None): f = open('plaid.gpg', 'r') plaid_config_data_gpg = f.read() f.close() crypter_util = crypt.Crypt() plaid_config_data = crypter_util.decrypt(plaid_config_data_gpg, passphrase) plaid_config = json.loads(plaid_config_data) Client.config({ 'url': plaid_config['plaidendpoint'] }) return Client(client_id=plaid_config['client'], secret=plaid_config['secret'], access_token=access_token)
def exchangeLinkTokenForAccount(self, user, public_token): Client.config({ 'url': 'https://tartan.plaid.com' }) print('creating client') self.client = Client(client_id=PlaidAPI.client_id, secret=PlaidAPI.secret) print('getting response') response = self.client.exchange_token(public_token) print('response') print(response) access_token = self.client.access_token print("Access token {0}".format(access_token)) ##create account and store in db plaiduser = PlaidUserToken() # is there a good constructor syntax? plaiduser.user = user plaiduser.access_token = access_token plaiduser.status = 'new' plaiduser.status_text = "Created {0}".format(timezone.now()) plaiduser.save() print('saved') return plaiduser
from plaid import Client from petra.config import config Client.config({ 'url': 'https://tartan.plaid.com' }) client = Client( client_id=config['PLAID']['CLIENT_ID'], secret=config['PLAID']['SECRET'], )
class PlaidClient: """ A wrapper class around the Plaid API client. """ def __init__(self, access_token=None): """ Initializes an instance. NOTE: we don't use the Lazy pattern here because the Plaid Client caches access tokens between method calls. """ self._client = Client( client_id=current_app.config['PLAID_CLIENT_ID'], secret=current_app.config['PLAID_SECRET'], access_token=access_token ) self._client.config({ 'url': current_app.config['PLAID_URL'] }) def get_transactions( self, start: datetime.datetime=datetime.datetime.utcnow() - datetime.timedelta(days=30), end: datetime.datetime=datetime.datetime.utcnow(), pending=False, account_id=None ): """ Retrieves transactions from the institution specified by the stored access token. Args: start: The start date for the transaction history set. Default one month before today. end: The end date for the transaction history set. Default today. pending: Whether or not to fetch pending transactions. account_id: If not None, will fetch transactions only from this account id. Returns: TODO, a dictionary for now. Raises: TODO """ options = { 'pending': pending, 'gte': start.isoformat(), 'end': end.isoformat(), 'account': account_id } response = self._client.connect_get(options) return self._process_transactions(response) def delete_user(self): """ Deletes the user associated with this client from Plaid's cache. They will have to log in again next time. """ response = self._client.connect_delete() if not response.ok: raise exceptions.BadRequest('TODO: SOMETHING F****D UP') def exchange_token(self, public_token): """ Exchanges the public_token returned by the Plaid Link module for a complete Plaid access token. """ response = self._client.exchange_token(public_token) if not response.ok: raise exceptions.BadRequest('TODO: SOMETHING F****D UP') return response.json()['access_token'] def _process_transactions(self, response): """ Processes a response with data containing transactions from Plaid to be in a specific format. Args: response: A response from plaid.Client. Returns: TODO Raises: TODO """ if not response.ok: raise exceptions.BadRequest('TODO: SOMETHING F****D UP') response_json = response.json() transactions = [ { '_id': transaction['_id'], '_account': transaction['_account'], 'date': self._process_transaction_date(transaction['date']), 'amount': transaction['amount'], 'name': self._process_transaction_name(transaction['name']), 'pending': transaction['pending'] } for transaction in response_json['transactions'] ] return transactions @staticmethod def _process_transaction_name(name): """ Prettify the names of transactions. TODO: Should we do this at all, or send whatever we get from Plaid? """ return titlecase(name) @staticmethod def _process_transaction_date(date): """Converts `date` from YYYY-MM-DD to epoch time.""" return datetime.datetime.strptime(date, '%Y-%m-%d')
import os, json from plaid import Client from plaid import errors as plaid_errors plaid_client_id = os.getenv('plaid_client_id', '') plaid_secret = os.getenv('plaid_secret', '') plaid_access_token = os.getenv('plaid_access_token', '') Client.config({ 'url': 'https://api.plaid.com', 'suppress_http_errors': True, }) client = Client(client_id=plaid_client_id, secret=plaid_secret, access_token=plaid_access_token) response = client.balance() balance = json.loads(response.content) response = client.connect_get() transactions = json.loads(response.content) print balance
class plaid(): account_type = 'chase' name = '' password = '' client = Client(client_id='57cccae6cfbf49f67b01fd5a', secret='2c13981884395fc691fda11148ed67') plaid_results = '' def __init__(self): print "created plaid object" Client.config({'url': 'https://tartan.plaid.com'}) def answer_mfa(data): print "answer_mfa" if data['type'] == 'questions': # Ask your user for the answer to the question[s]. # Although questions is a list, there is only ever a # single element in this list, at present return answer_question([q['question'] for q in data['mfa']]) elif data['type'] == 'list': return answer_list(data['mfa']) elif data['type'] == 'selection': return answer_selections(data['mfa']) else: raise Exception('Unknown mfa type from Plaid') def answer_question(questions): print "answer_question" # We have magically inferred the answer # so we respond immediately # In the real world, we would present questions[0] # to our user and submit their response answer = 'dogs' return client.connect_step(account_type, answer) def answer_list(devices): print "answer_list" print devices[1] # You should specify the device to which the passcode is sent. # The available devices are present in the devices list dog = client.connect_step( 'chase', None, options={'send_method': { 'mask': 'xxx-xxx-9793' }}) answer = raw_input("Please enter something: ") cat = client.connect_step(account_type, answer) print cat print cat.content # print dog # print type(dog) # new =dog.content # print new # print type(new) # token=new.access_token # print token return dog def answer_selections(selections): print "answer_selections" # We have magically inferred the answers # so we respond immediately # In the real world, we would present the selection # questions and choices to our user and submit their responses # in a JSON-encoded array with answers provided # in the same order as the given questions answer = json.dumps(['Yes', 'No']) return client.connect_step(account_type, answer) def use_token(self, username): obj = SQLConnection() token = obj.get_plaid_token(username) self.client = Client(client_id='57cccae6cfbf49f67b01fd5a', secret='2c13981884395fc691fda11148ed67', access_token=token) response = self.client.connect_get(token) self.plaid_results = response.content return response.content def create_user_plaid(self, username, account_type, bank_username, bank_password): try: response = self.client.connect(account_type, { 'username': bank_username, 'password': bank_password }) d = json.loads(response.content) access_token = d["access_token"] print access_token except plaid_errors.PlaidError, e: print e else:
from django.conf import settings from main.models import PlaidUser import logging from plaid import Client as PlaidClient logger = logging.getLogger('main.plaid') PlaidClient.config({'url': settings.PLAID_DEVELOPMENT_URL}) client_id = settings.PLAID_CLIENT_ID public_key = settings.PLAID_PUBLIC_KEY secret = settings.PLAID_SECRET def create_access_token(django_user, public_token): client = PlaidClient(client_id=client_id, secret=secret) resp = client.exchange_token(public_token) if resp.status_code != 200: logger.error( "Unable to exchange public token for access token for user {0}". format(django_user)) return None # else "client.access_token" should now be populated with # a valid access_token for making authenticated requests # Get the plaid user for this django user; make one if nec. if not getattr(django_user, 'plaid_user', False): plaid_user = PlaidUser(user=django_user) plaid_user.save() plaid_user = django_user.plaid_user