def login(): try: # Log call and get params: logger = logging.getLogger('app') logger.debug('\n/login') params = json.loads(request.data) logger.debug(params) username = params['username'] password = params['password'] logger.debug('Executing ... ') # Data base and paybook logic: db_user = _DB.User(username, password) logger.debug('DB authentication ... ') if db_user.login(): id_user = db_user.get_id_user() logger.debug('Id user: '******'Invalid username or password', 400).get_response() except paybook_sdk.Error as error: login_response = error.get_json() return login_response
def catalogues(): try: # Log call and get params: logger = logging.getLogger('app') logger.debug('\n/catalogues') logger.debug(request.args) token = request.args.get('token') is_test = request.args.get('is_test') if is_test == 'true': is_test = True else: is_test = False logger.debug('Token: ' + token) logger.debug('Test: ' + str(is_test)) logger.debug('Executing ... ') # Paybook logic: session = paybook_sdk.Session(token=token) sites = paybook_sdk.Catalogues.get_sites(session=session, is_test=is_test) catalogs_response = [] for site in sites: catalogs_response.append(site.get_json()) logger.debug('Catalogues: ' + str(len(catalogs_response))) logger.debug('Sending response ... ') catalogs_response = _Utilities.Success( catalogs_response).get_response() except paybook_sdk.Error as error: catalogs_response = _Utilities.Error(error.message, error.code).get_response() return catalogs_response
def transactions(): try: logger = logging.getLogger('app') logger.debug('\n/transactions') token = request.args.get('token') id_account = request.args.get('id_account') logger.debug(token) logger.debug(id_account) id_site = request.args.get('id_site') id_account = request.args.get('id_account') if id_site == 'null': id_site = None if id_account == 'null': id_account = None logger.debug('Executing ... ') session = paybook_sdk.Session(token=token) transactions = paybook_sdk.Transaction.get(session=session) transactions_response = [] for transaction in transactions: transactions_response.append(transaction.get_json()) logger.debug('Transactions: ' + str(len(transactions_response))) logger.debug('Sending response ... ') transactions_response = _Utilities.Success({ 'transactions': transactions_response }).get_response() except paybook_sdk.Error as error: transactions_response = _Utilities.Error(error.message, error.code).get_response() return transactions_response
def twofa(): try: logger = logging.getLogger('app') logger.debug('\n/twofa') params = json.loads(request.data) logger.debug(params) token = params['token'] id_credential = params['id_credential'] credentials_twofa = params['twofa'] twofa_key = params['twofa_key'] twofa_value = params['twofa_value'] logger.debug('Executing ... ') session = paybook_sdk.Session(token=token) credentials = None credentials_list = paybook_sdk.Credentials.get(session=session) for c in credentials_list: if c.id_credential == id_credential: credentials = c credentials.twofa = credentials_twofa credentials.twofa_config = {'name': twofa_key} #End of twofa_config twofa_set = credentials.set_twofa(session=session, twofa_value=twofa_value) logger.debug('Towfa value set: ' + str(twofa_set)) logger.debug('Sending response ... ') twofa_response = _Utilities.Success(twofa_set).get_response() except paybook_sdk.Error as error: twofa_response = _Utilities.Error(error.message, error.code).get_response() return twofa_response
def credentials(): try: # Log call and get params: logger = logging.getLogger('app') logger.debug('\n/credentials') params = json.loads(request.data) logger.debug(params) token = params['token'] id_site = params['id_site'] if 'id_site' in params else None credentials = params['credentials'] logger.debug('Executing ... ') # Paybook logic: session = paybook_sdk.Session(token=token) logger.debug('Creating credentials ... ') logger.debug(credentials) credentials = paybook_sdk.Credentials(session=session, id_site=id_site, credentials=credentials) logger.debug('Id credential: ' + credentials.id_credential) logger.debug('Twofa: ' + credentials.twofa) logger.debug( "curl -X POST -d '{\"twofa_key\":\"token\",\"token\":\"4f3e7fe982f18898f970e4805b4774a3\",\"twofa\":\"" + credentials.twofa + "\",\"twofa_value\":\"test\",\"id_credential\":\"" + credentials.id_credential + "\"}' http://localhost:5000/twofa --header \"Content-Type:application/json\"" ) logger.debug('Sending response ... ') credentials_response = _Utilities.Success( credentials.get_json()).get_response() except paybook_sdk.Error as error: credentials_response = _Utilities.Error(error.message, error.code).get_response() return credentials_response
def accounts(): try: logger = logging.getLogger('app') logger.debug('\n/accounts') token = request.args.get('token') id_site = request.args.get('id_site') logger.debug(token) logger.debug(id_site) if id_site == 'null': id_site = None options = {} if id_site is not None: logger.debug('Filtering by id_site ' + id_site + ' ... ') options['id_site'] = id_site logger.debug('Executing ... ') session = paybook_sdk.Session(token=token) accounts = paybook_sdk.Account.get(session=session, options=options) accounts_response = [] for account in accounts: accounts_response.append(account.get_json()) logger.info('Accounts: ' + str(len(accounts_response))) logger.debug('Sending response ... ') accounts_response = _Utilities.Success( accounts_response).get_response() except paybook_sdk.Error as error: accounts_response = _Utilities.Error(error.message, error.code).get_response() return accounts_response
def transactions(): try: logger = logging.getLogger('app') logger.debug('\n/transactions') token = request.args.get('token') id_account = request.args.get('id_account') logger.debug(token) logger.debug(id_account) id_site = request.args.get('id_site') id_account = request.args.get('id_account') skip = request.args.get('skip') limit = request.args.get('limit') if id_site == 'null': id_site = None if id_account == 'null': id_account = None if skip == 'null': skip = None if limit == 'null': limit = None logger.debug('Executing ... ') session = paybook_sdk.Session(token=token) options = {} if id_site is not None: logger.debug('Filtering by id_site ' + id_site + ' ... ') options['id_site'] = id_site if id_account is not None: logger.debug('Filtering by id_account ' + id_account + ' ... ') options['id_account'] = id_account if skip is not None: logger.debug('Skiping ' + skip + ' ... ') options['skip'] = skip if limit is not None: logger.debug('Adding limit ' + limit + ' ... ') options['limit'] = limit transactions = paybook_sdk.Transaction.get(session=session, options=options) transactions_response = [] for transaction in transactions: transactions_response.append(transaction.get_json()) logger.debug('Transactions: ' + str(len(transactions_response))) logger.debug('Sending response ... ') transactions_response = _Utilities.Success({ 'transactions': transactions_response }).get_response() except paybook_sdk.Error as error: transactions_response = _Utilities.Error(error.message, error.code).get_response() return transactions_response
def delete_credentials(): try: logger = logging.getLogger('app') logger.debug('\n/credentials') params = json.loads(request.data) logger.debug(params) token = params['token'] id_credential = params['id_credential'] logger.debug('Executing ... ') session = paybook_sdk.Session(token=token) credentials_deleted = paybook_sdk.Credentials.delete( session=session, id_credential=id_credential) logger.debug('Sending response ... ') delete_response = _Utilities.Success( credentials_deleted).get_response() except paybook_sdk.Error as error: delete_response = _Utilities.Error(error.message, error.code).get_response() return delete_response
def get_credentials(): try: logger = logging.getLogger('app') logger.debug('\n/credentials') token = request.args.get('token') logger.debug('Token: ' + token) logger.debug('Executing ... ') session = paybook_sdk.Session(token=token) credentials_list = paybook_sdk.Credentials.get(session=session) site_organizations = paybook_sdk.Catalogues.get_site_organizations( session=session) test_site_organizations = paybook_sdk.Catalogues.get_site_organizations( session=session, is_test=True) site_organizations = site_organizations + test_site_organizations data_by_id_site_organization = {} for site_organization in site_organizations: data_by_id_site_organization[ site_organization.id_site_organization] = { 'avatar': site_organization.avatar, 'name': site_organization.name } #End of data_by_id_site_organization[site_organization.id_site_organization] credentials_response = [] for credentials in credentials_list: credentials_json = credentials.get_json() credentials_json['avatar'] = data_by_id_site_organization[ credentials_json['id_site_organization']]['avatar'] credentials_json['name'] = data_by_id_site_organization[ credentials_json['id_site_organization']]['name'] credentials_response.append(credentials_json) logger.debug('Credentials: ' + str(len(credentials_response))) logger.debug('Sending response ... ') credentials_response = _Utilities.Success( credentials_response).get_response() except paybook_sdk.Error as error: credentials_response = _Utilities.Error(error.message, error.code).get_response() return credentials_response
step = 0 print str(step) + '. Inicializar SDK con API KEY correcta:' paybook_sdk.Paybook(PAYBOOK_API_KEY) print INDENT + 'ok' step += 1 print str( step ) + '. Crear un usuario a partir de id_user (consultar usuario existente)' session_user = paybook_sdk.User(id_user=ID_USER) print INDENT + 'username: '******' id_user: '******'. Crear una sesión para el usuario del paso 8' session = paybook_sdk.Session(session_user) print INDENT + 'token: ' + str(session.token) step += 1 print str(step) + '. Verificar la sesión (debe ser valida)' session_verified = session.verify() print INDENT + 'verified: ' + str(session_verified) step += 1 print str(step) + '. Consultar la lista de transacciones del usuario' transactions = paybook_sdk.Transaction.get(session=session) print INDENT + 'transactions_count: ' + str(len(transactions)) step += 1 except paybook_sdk.Error as error: print INDENT + 'error: ' + str(error.code) + ' ' + error.message
# -*- coding: utf-8 -*- YOUR_API_KEY = 'YOUR_API_KEY' BANK_USERNAME = '******' BANK_PASSWORD = '******' import time import sys import paybook.sdk as paybook_sdk try: paybook_sdk.Paybook(YOUR_API_KEY) user_list = paybook_sdk.User.get() user = user_list[0] print user.name + ' ' + user.id_user session = paybook_sdk.Session(user=user) print session.token bank_site = None sites = paybook_sdk.Catalogues.get_sites(session=session) for site in sites: print 'Bank site: ' + site.name + ' ' + site.id_site if site.name == 'SuperNET Particulares': bank_site = site CREDENTIALS = { 'username': BANK_USERNAME, 'password': BANK_PASSWORD } #End of CREDENTIALS bank_credentials = paybook_sdk.Credentials( session=session, id_site='572930c4784806060f8b456b', credentials=CREDENTIALS) print 'Esperando validacion de credenciales ... ' status_102_or_401 = None
# -*- coding: utf-8 -*- YOUR_API_KEY = 'YOUR_API_KEY' RFC = 'YOUR_RFC' CIEC = 'YOUR_CIEC' import time import sys import paybook.sdk as paybook try: paybook.Paybook(YOUR_API_KEY) user = paybook.User(name='MY_USER') my_users = paybook.User.get() for user in my_users: print user.name session = paybook.Session(user) print 'Session token: ' + session.token session_verified = session.verify() print 'Session verified: ' + str(session_verified) sat_site = None sites = paybook.Catalogues.get_sites(session=session) for site in sites: print site.name.encode('utf-8') if site.name == 'CIEC': sat_site = site print 'SAT site: ' + sat_site.id_site + ' ' + sat_site.id_site credentials_data = {'rfc': RFC, 'password': CIEC} sat_credentials = paybook.Credentials(session=session, id_site=sat_site.id_site, credentials=credentials_data) print sat_credentials.username sat_sync_completed = False while not sat_sync_completed:
def create(self, user): return paybook_sdk.Session(user=user)