Пример #1
0
def create_orden():
    transaction = Transaction()
    try:
        external_transaction = StpTransaction(**request.json)
        transaction = external_transaction.transform()
        if CLABES_BLOCKED:
            clabes = CLABES_BLOCKED.split(',')
            if transaction.cuenta_beneficiario in clabes:
                capture_message('Transacción retenida')
                raise Exception

        previous_trx = Transaction.objects(
            clave_rastreo=transaction.clave_rastreo,
            cuenta_ordenante=transaction.cuenta_ordenante,
            cuenta_beneficiario=transaction.cuenta_beneficiario,
            monto=transaction.monto)
        assert len(previous_trx) == 0

        transaction.confirm_callback_transaction()
        transaction.save()

        r = request.json
        r['estado'] = Estado.convert_to_stp_state(transaction.estado)
    except Exception as exc:
        r = dict(estado='LIQUIDACION')
        transaction.estado = Estado.error
        transaction.save()
        capture_exception(exc)
    return 201, r
Пример #2
0
def get_orders():
    estado = request.args.get('estado', default=None, type=str)
    prefix_ordenante = request.args.get('prefix_ordenante',
                                        default=None,
                                        type=str)
    prefix_beneficiario = request.args.get('prefix_beneficiario',
                                           default=None,
                                           type=str)
    query = dict()
    if estado:
        query['estado'] = estado
    if prefix_ordenante:
        query['cuenta_ordenante__startswith'] = prefix_ordenante
    if prefix_beneficiario:
        query['cuenta_beneficiario__startswith'] = prefix_beneficiario

    transactions = Transaction.objects(**query).order_by('-created_at')
    return 200, transactions
Пример #3
0
def test_create_orden_duplicated(client, default_income_transaction):
    resp = client.post('/ordenes', json=default_income_transaction)
    transaction = Transaction.objects.order_by('-created_at').first()
    assert transaction.estado is Estado.succeeded
    assert resp.status_code == 201
    assert resp.json['estado'] == 'LIQUIDACION'

    default_income_transaction['Clave'] = 2456304
    resp = client.post('/ordenes', json=default_income_transaction)
    transactions = Transaction.objects(
        clave_rastreo=default_income_transaction['ClaveRastreo']).order_by(
            '-created_at')
    assert len(transactions) == 1
    assert transactions[0].stp_id == 2456303
    assert transactions[0].estado is Estado.succeeded
    assert resp.status_code == 201
    assert resp.json['estado'] == 'LIQUIDACION'
    for t in transactions:
        t.delete()