Exemple #1
0
 def load(self, institution, account, days=90):
     args = {
         'id': institution.get('fid'),
         'org': institution.get('org'),
         'url': institution.get('url'),
         'username': self._dec(institution.get('username')),
         'password': self._dec(institution.get('password')),
         'client_args': {
             'ofx_version': institution.get('version')
         },
     }
     if institution.get('cid'):
         args['client_args']['id'] = institution.get('cid')
     if institution.get('app'):
         args['client_args']['app_id'] = institution.get('app')
     if institution.get('app_version'):
         args['client_args']['app_version'] = institution.get('app_version')
     if account.get("type") == "CREDIT":
         acct = CreditCardAccount(institution=Institution(**args),
                                  number=self._dec(account.get('number')))
     else:
         acct = BankAccount(routing_number=institution.get("routing"),
                            account_type=account.get("type"),
                            institution=Institution(**args),
                            number=self._dec(account.get('number')))
     return acct.transactions(days=days)
Exemple #2
0
    def add_bank(self, id=None, username=None, password=None):

        cherrypy.response.headers['Content-Type'] = 'application/json'
        cherrypy.response.status = 200

        result = {'status': 'ok', 'message': ''}
        if id and username and password:
            bank = OFXHome.lookup(id)
            i = Institution(id=bank['fid'],
                            org=bank['org'],
                            url=bank['url'],
                            broker_id=bank['brokerid'],
                            description=bank['name'],
                            username=username,
                            password=password)
            try:
                i.authenticate()
            except Exception as e:
                result['status'] = 'error'
                result[
                    'message'] = 'unable to log into bank with those credentials'

            for a in i.accounts():
                GlobalConfig.add_account(a)
            GlobalConfig.save()
        else:
            result['status'] = 'error'
            result['message'] = 'id, username, and password are all required'

        ret = json.dumps(result)
        cherrypy.response.body = ret
        if result['status'] == 'error':
            cherrypy.response.status = 400
        return ret
Exemple #3
0
    def testClientDefaultsPreserved(self):
        i = Institution(id="1", org="org", url="http://example.com", username="******", password="******")

        c = Client(institution=i)
        ic = i.client()

        self.assertEqual(c.id, ic.id)
        self.assertEqual(c.app_id, ic.app_id)
        self.assertEqual(c.app_version, ic.app_version)
        self.assertEqual(c.ofx_version, ic.ofx_version)
Exemple #4
0
    def testClientDefaultsPreserved(self):
        i = Institution(id='1',
                        org='org',
                        url='http://example.com',
                        username='******',
                        password='******')

        c = Client(institution=i)
        ic = i.client()

        self.assertEqual(c.id, ic.id)
        self.assertEqual(c.app_id, ic.app_id)
        self.assertEqual(c.app_version, ic.app_version)
        self.assertEqual(c.ofx_version, ic.ofx_version)
 def testFromConfig3(self):
     i = Institution.from_config({
         'id': '623',
     })
     self.assertEquals(i.id,'623')
     self.assertEquals(i.username,None)
     self.assertEquals(i.description,'Scottrade, Inc.')
Exemple #6
0
 def setUp(self):
     institution = Institution(id='1',
                               org='Example',
                               url='http://example.com',
                               username='******',
                               password='******')
     self.institution = institution
Exemple #7
0
    def testFieldsRemainUnsecure(self):
        if not ofxclient.config.KEYRING_AVAILABLE:
            return

        c = OfxConfig(file_name=self.temp_file.name)
        i = Institution(
                id='1',
                org='org',
                url='url',
                username='******',
                password='******'
        )
        a = CreditCardAccount(institution=i, number='12345')
        c.add_account(a)

        # pretend the user put their password in there in the clear on purpose
        c.parser.remove_option(a.local_id(), 'institution.password')
        c.parser.set(a.local_id(), 'institution.password', 'pass')
        c.save()

        c = OfxConfig(file_name=self.temp_file.name)
        self.assertTrue(
            c.parser.is_secure_option(a.local_id(), 'institution.username')
        )
        self.assertFalse(
            c.parser.is_secure_option(a.local_id(), 'institution.password')
        )
Exemple #8
0
    def testClientSomeOverride(self):
        i = Institution(
            id="1",
            org="org",
            url="http://example.com",
            username="******",
            password="******",
            client_args={"app_id": "capp_id"},
        )

        c = Client(institution=i)
        ic = i.client()
        self.assertEqual(ic.app_id, "capp_id", "overridden app_id")
        self.assertNotEqual(ic.app_id, c.app_id, "overridden app_id")
        self.assertEqual(ic.id, c.id, "default id")
        self.assertEqual(ic.app_version, c.app_version, "default app version")
        self.assertEqual(ic.ofx_version, c.ofx_version, "default ofx version")
Exemple #9
0
    def testClientSomeOverride(self):
        i = Institution(id='1',
                        org='org',
                        url='http://example.com',
                        username='******',
                        password='******',
                        client_args={
                            'app_id': 'capp_id',
                        })

        c = Client(institution=i)
        ic = i.client()
        self.assertEqual(ic.app_id, 'capp_id', 'overridden app_id')
        self.assertNotEqual(ic.app_id, c.app_id, 'overridden app_id')
        self.assertEqual(ic.id, c.id, 'default id')
        self.assertEqual(ic.app_version, c.app_version, 'default app version')
        self.assertEqual(ic.ofx_version, c.ofx_version, 'default ofx version')
 def testFromConfig1(self):
     i = Institution.from_config({
         'id': '623',
         'username': '******',
         'description': 'my account' 
     })
     self.assertEquals(i.id,'623')
     self.assertEquals(i.username,'bob')
     self.assertEquals(i.description,'my account')
Exemple #11
0
    def testClientAllOverride(self):
        i = Institution(id='1',
                        org='org',
                        url='http://example.com',
                        username='******',
                        password='******',
                        client_args={
                            'id': 'cid',
                            'app_id': 'capp_id',
                            'app_version': 'capp_version',
                            'ofx_version': 'cofx_version'
                        })

        c = i.client()
        self.assertEqual(c.id, 'cid')
        self.assertEqual(c.app_id, 'capp_id')
        self.assertEqual(c.app_version, 'capp_version')
        self.assertEqual(c.ofx_version, 'cofx_version')
Exemple #12
0
    def testClientAllOverride(self):
        i = Institution(
            id="1",
            org="org",
            url="http://example.com",
            username="******",
            password="******",
            client_args={
                "id": "cid",
                "app_id": "capp_id",
                "app_version": "capp_version",
                "ofx_version": "cofx_version",
            },
        )

        c = i.client()
        self.assertEqual(c.id, "cid")
        self.assertEqual(c.app_id, "capp_id")
        self.assertEqual(c.app_version, "capp_version")
        self.assertEqual(c.ofx_version, "cofx_version")
Exemple #13
0
def listTransactions(kvstore_url, days, fi_id, fi_org, url, ofx_version, domain):
    """
    Get SimpleFIN-style list of accounts and transactions.
    """
    username = getValue(kvstore_url, 'username', 'Account/Username?')
    password = getValue(kvstore_url, 'password', 'Password/PIN?')

    inst = Institution(
        id=fi_id,
        org=fi_org,
        url=url,
        username=username,
        password=password,
        client_args={
            'ofx_version': ofx_version,
        })
    accounts = inst.accounts()
    return ofxToDict(accounts, days=days,
        domain=domain,
        id_getter=partial(getID, kvstore_url))
Exemple #14
0
def _init_ofx():
    global ACCT
    if ACCT is None:
        inst = Institution(
            id='211371120',
            org='DI',
            url='https://ofxdi.diginsite.com/cmr/cmr.ofx',
            description=u'Cambridge Savings Bank',
            username=secrets.OFX_USERNAME,
            password=secrets.OFX_PASSWORD,
            client_args={
                'id': 'eb1c23b1102c4fe78f7e17f9685c3c89',
            },
        )
        for account in inst.accounts():
            if account.number_masked() == u'***8059':
                ACCT = account
                break
        else:
            print "Couldn't find joint account."
            sys.exit(1)
Exemple #15
0
    def testAddAccount(self):
        c = OfxConfig(file_name=self.temp_file.name)

        i = Institution(id='1',
                        org='org',
                        url='url',
                        username='******',
                        password='******')
        a = CreditCardAccount(institution=i, number='12345')

        c.add_account(a)
        self.assertEqual(len(c.accounts()), 1)
        self.assertEqual(c.account(a.local_id()).local_id(), a.local_id())
Exemple #16
0
    def add_bank(self,id=None,username=None,password=None):

        cherrypy.response.headers['Content-Type'] = 'application/json'
        cherrypy.response.status = 200

        result = {
            'status': 'ok',
            'message': ''
        }
        if id and username and password:
            bank = OFXHome.lookup(id)
            i = Institution(
                    id = bank['fid'],
                    org = bank['org'],
                    url = bank['url'],
                    broker_id = bank['brokerid'],
                    description = bank['name'],
                    username = username,
                    password = password
            )
            try:
                i.authenticate()
            except Exception as e:
                result['status'] = 'error'
                result['message'] = 'unable to log into bank with those credentials'

            for a in i.accounts():
                GlobalConfig.add_account(a)
            GlobalConfig.save()
        else:
            result['status'] = 'error'
            result['message'] = 'id, username, and password are all required'

        ret = json.dumps(result)
        cherrypy.response.body = ret
        if result['status'] == 'error':
            cherrypy.response.status = 400
        return ret
Exemple #17
0
    def testFieldsSecured(self):
        if not ofxclient.config.KEYRING_AVAILABLE:
            return

        c = OfxConfig(file_name=self.temp_file.name)

        i = Institution(id='1',
                        org='org',
                        url='url',
                        username='******',
                        password='******')
        a = CreditCardAccount(institution=i, number='12345')
        c.add_account(a)

        self.assertTrue(
            c.parser.is_secure_option(a.local_id(), 'institution.username'))
        self.assertTrue(
            c.parser.is_secure_option(a.local_id(), 'institution.password'))
Exemple #18
0
    def testResecuredAfterEncryptAccount(self):
        if not ofxclient.config.KEYRING_AVAILABLE:
            return

        c = OfxConfig(file_name=self.temp_file.name)
        i = Institution(
                id='1',
                org='org',
                url='url',
                username='******',
                password='******'
        )
        a1 = CreditCardAccount(institution=i, number='12345')
        c.add_account(a1)
        a2 = CreditCardAccount(institution=i, number='67890')
        c.add_account(a2)

        # pretend the user put their password in there in the clear on purpose
        # to fix something... and then wants it to be resecured later on
        c.parser.remove_option(a1.local_id(), 'institution.password')
        c.parser.set(a1.local_id(), 'institution.password', 'pass')
        c.save()

        c = OfxConfig(file_name=self.temp_file.name)
        self.assertEqual(len(c.accounts()), 2)
        self.assertEqual(len(c.encrypted_accounts()), 1)
        self.assertEqual(len(c.unencrypted_accounts()), 1)
        self.assertTrue(
            c.parser.is_secure_option(a1.local_id(), 'institution.username')
        )
        self.assertFalse(
            c.parser.is_secure_option(a1.local_id(), 'institution.password')
        )

        c.encrypt_account(a1.local_id())
        self.assertEqual(len(c.accounts()), 2)
        self.assertEqual(len(c.encrypted_accounts()), 2)
        self.assertEqual(len(c.unencrypted_accounts()), 0)
        self.assertTrue(
            c.parser.is_secure_option(a1.local_id(), 'institution.username')
        )
        self.assertTrue(
            c.parser.is_secure_option(a1.local_id(), 'institution.password')
        )
Exemple #19
0
    def testLoadFromFile(self):
        c = OfxConfig(file_name=self.temp_file.name)
        i = Institution(id='1',
                        org='org',
                        url='url',
                        username='******',
                        password='******')
        a = CreditCardAccount(institution=i, number='12345')
        c.add_account(a)
        c.save()

        c = OfxConfig(file_name=self.temp_file.name)
        got = c.account(a.local_id())
        self.assertEqual(len(c.accounts()), 1)
        self.assertEqual(got.local_id(), a.local_id())
        self.assertEqual(got.number, a.number)
        self.assertEqual(got.institution.local_id(), a.institution.local_id())
        self.assertEqual(got.institution.id, a.institution.id)
        self.assertEqual(got.institution.org, a.institution.org)
        self.assertEqual(got.institution.url, a.institution.url)
        self.assertEqual(got.institution.username, a.institution.username)
        self.assertEqual(got.institution.password, a.institution.password)
from bottle import *
from ofxclient import Institution

app = Bottle(__name__)

@app.post('/transactions')
def download()
    params = json.loads(request.params.dict.keys()[0])
    account = params['account']
    password = params['password']
    days = params['days']
    
    inst = Institution(
            id = '54324',
            org = 'America First Credit Union',
            url = 'https://ofx.americafirst.com',
            username = '',
            password = ''
    )
    
    accounts = inst.accounts()[0]
    download  = a.download(days=days)
    
    return download
    

if __name__ == '__main__':
    port = int(os.environ.get('PORT', 8000))
    debug(mode=True)
    logging.basicConfig(level=logging.DEBUG)
    app.run(host='0.0.0.0', port=port, reloader=True)
Exemple #21
0
from ofxclient import Institution

inst = Institution(
    id='3101',
    org='AMEX',
    url=
    'https://online.americanexpress.com/myca/ofxdl/desktop/desktopDownload.do?request_type=nl_ofxdownload',
    username='******',
    password='******')

accounts = inst.accounts()
for a in accounts:
    # a StringIO wrapped string of the raw OFX download
    download = a.download(days=5)
    print download.read()

    # an ofxparse.Statement object
    statement = a.statement(days=5)
    print statement.balance
Exemple #22
0
def _get_institution(institution_key):
    return Institution(id=config[institution_key]['id'],
                       org=config[institution_key]['org'],
                       url=config[institution_key]['url'],
                       username=config[institution_key]['username'],
                       password=config[institution_key]['password'])
 def testList(self):
     settings = Settings.banks()
     institutions = Institution.list()
     self.assertEquals( len(settings), len(institutions) )