コード例 #1
0
def process_incoming_transaction(incoming_transaction: dict) -> dict:
    transaction = Transaction()
    try:
        external_tx = StpTransaction(**incoming_transaction)  # type: ignore
        transaction = external_tx.transform()
        if CLABES_BLOCKED:
            clabes = CLABES_BLOCKED.split(',')
            if transaction.cuenta_beneficiario in clabes or (
                    transaction.cuenta_ordenante in clabes):
                capture_message('Transacción retenida')
                raise Exception
        transaction.confirm_callback_transaction()
        transaction.save()
        r = incoming_transaction
        r['estado'] = Estado.convert_to_stp_state(transaction.estado)
    except (NotUniqueError, TypeError) as e:
        r = dict(estado='LIQUIDACION')
        capture_exception(e)
    except Exception as e:
        r = dict(estado='LIQUIDACION')
        transaction.estado = Estado.error
        transaction.events.append(Event(type=EventType.error, metadata=str(e)))
        transaction.save()
        capture_exception(e)
    return r
コード例 #2
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