def get_accounts(django_user): plaid_user = getattr(django_user, 'plaid_user', False) if not plaid_user: logger.error("There is no Plaid user corresponding to user {0}".format( django_user)) return None # else access_token = getattr(plaid_user, 'access_token', False) if not access_token: logger.error("User {0} has a Plaid User but no access token".format( django_user)) return None # else client = PlaidClient(client_id=client_id, secret=secret, access_token=access_token) resp = client.auth_get() if resp.status_code != 200: logger.error("Unable to retrieve client accounts for user {0}".format( django_user)) return None # else return resp.json()['accounts']
def load_statements_line_from_plaid( self, id_plaid='584f8ac239361943b6a40c2f', id_secret='2eb94d1cfb298020b6d4c1e396eb75', access_token='test_bofa'): # get transactions _logger.warning('\n\n\n Respuesta1: \n \n\n\n') client = Client(client_id=id_plaid, secret=id_secret, access_token='test_bofa') #PARA DELIMITAR CON FECFA response = client.connect_get(opts={'gte':'2014-06-01'}).json() response = client.connect_get().json() accounts = client.auth_get().json() #transactions = response.json() _logger.info('\n\n\n transaccion: \n %s \n\n\n' % response['transactions'][0]) _logger.info('\n\n\n Numero de Cuenta: \n %s \n\n\n' % accounts['accounts'][2]['numbers']['account']) _logger.info('\n\n\n id de la cuenta: \n %s \n\n\n' % accounts['accounts'][2]['_id']) _logger.info('\n\n\n id de la Cuenta en la transaccion: \n %s \n\n\n' % response['transactions'][0]['_account']) _logger.info('\n\n\n Monto de la transaccion: \n %s \n\n\n' % response['transactions'][0]['amount']) _logger.info('\n\n\n fecha de la transaccion: \n %s \n\n\n' % response['transactions'][0]['date']) _logger.info( '\n\n\n nombre del partner que realiza transaccion: \n %s \n\n\n' % response['transactions'][0]['name']) #for account in accounts['accounts']: values = [] for resp in response['transactions']: values.append((0, 0, { 'name': resp['name'], 'ref': resp['_id'], 'amount': resp['amount'], 'date': resp['date'] })) #OBSOLETO #new_id = self.env['account.bank.statement'].create({'name':"Prueba5", 'journal_id':6, 'line_ids': [(0,0,{'name': 'pruebaline', 'ref': '00002-line', 'amount': 100})]}) #new_id = self.env['account.bank.statement'].create({'name':"Prueba5", 'journal_id':6, 'line_ids': [(0,0,{'name': response['transactions'][0]['name'], # 'ref': response['transactions'][0]['_id'], # 'amount': response['transactions'][0]['amount'], # 'date': response['transactions'][0]['date'] # })]}) # new_id = self.env['account.bank.statement'].create({ 'name': "Prueba5", 'journal_id': 6, 'line_ids': values }) return True
def test_get_auth(): client = Client('test_id', 'test_secret', access_token='test_bofa') response = client.auth_get() assert response.status_code == 200