Exemple #1
0
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
Exemple #2
0
def signup():
    try:
        # Log call and get params:
        logger = logging.getLogger('app')
        logger.debug('\n/signup')
        params = json.loads(request.data)
        logger.debug(params)
        username = params['username']
        password = params['password']
        logger.debug('Executing ... ')
        # Data base and paybook logic:
        signup_response = {
            'sdk_message': 'User already exists'
        }  #End of signup_response
        db_user = _DB.User(
            username,
            password)  # This is the app user (stored in app's data base)
        user_exist = db_user.do_i_exist()
        logger.debug('User exist: ' + str(user_exist))
        if not user_exist:
            logger.debug('Singning up user ... ')
            pb_user = paybook_sdk.User(
                name=username
            )  # This is the paybook user (stored in paybook's data base)
            signup_response = pb_user.get_json()
            db_user.set_id_user(signup_response['id_user'])
            db_user.save()
            signup_response['sdk_message'] = 'User signed up'
        logger.debug('Sending response ... ')
        signup_response = _Utilities.Success(signup_response).get_response()
    except paybook_sdk.Error as error:
        signup_response = error.get_json()
    return signup_response
Exemple #3
0
try:
    INDENT = '   '
    PAYBOOK_API_KEY = 'YOUR_API_KEY'
    ID_USER = '******'

    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)
Exemple #4
0
 def create(self, name):
     return paybook_sdk.User(name=name)
Exemple #5
0
    step += 1

    print str(step) + '. Inicializar SDK con API KEY correcta:'
    paybook_sdk.Paybook(PAYBOOK_API_KEY)
    print INDENT + 'ok'
    step += 1

    print '\n -> USERS ENDPOINTS \n'

    print str(step) + '. Consultar la lista de usuarios: '
    user_list = paybook_sdk.User.get()
    print INDENT + 'users: ' + str(len(user_list))
    step += 1

    print str(step) + '. Crear un usuario nuevo: '
    user = paybook_sdk.User(name=USERNAME)
    print INDENT + 'username: '******' id_user: '******'. Consultar lista de usuarios (debe haber uno más que en el paso 1): '
    user_list = paybook_sdk.User.get()
    print INDENT + 'users: ' + str(len(user_list))
    step += 1

    print str(step) + '. Borrar al usuario: '
    deleted = paybook_sdk.User.delete(id_user=user.id_user)
    print INDENT + 'deleted: ' + str(deleted)
    step += 1
Exemple #6
0
# -​*- 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: