def test_get_order(): transaction = Transaction( concepto_pago='PRUEBA', institucion_ordenante='646', cuenta_beneficiario='072691004495711499', institucion_beneficiaria='072', monto=1020, nombre_beneficiario='Ricardo Sánchez Castillo de la Mancha S.A. de CV', nombre_ordenante='Ricardo Sánchez Castillo de la Mancha S.A. de CV', cuenta_ordenante='646180157000000004', rfc_curp_ordenante='ND', speid_id='speid_id', ) order = transaction.get_order() assert order.fechaOperacion is None assert order.institucionOperante == transaction.institucion_ordenante assert order.institucionContraparte == transaction.institucion_beneficiaria assert transaction.clave_rastreo == order.claveRastreo assert transaction.tipo_cuenta_beneficiario == order.tipoCuentaBeneficiario assert transaction.rfc_curp_beneficiario == order.rfcCurpBeneficiario assert transaction.referencia_numerica == order.referenciaNumerica assert transaction.empresa == order.empresa assert order.nombreBeneficiario == 'Ricardo Sánchez Castillo de la Mancha' assert order.nombreOrdenante == 'Ricardo Sánchez Castillo de la Mancha' assert len(order.nombreBeneficiario) == 37 assert len(order.nombreOrdenante) == 37
def execute(order_val): # Get version version = 0 if "version" in order_val: version = order_val['version'] transaction = Transaction() try: input = factory.create(version, **order_val) transaction = input.transform() if not clabe.validate_clabe(transaction.cuenta_beneficiario) and ( not luhnmod10.valid(transaction.cuenta_beneficiario)): raise MalformedOrderException() except (MalformedOrderException, TypeError, ValueError): transaction.set_state(Estado.error) transaction.save() raise MalformedOrderException() try: prev_trx = Transaction.objects.get(speid_id=transaction.speid_id) transaction = prev_trx transaction.events.append(Event(type=EventType.retry)) except DoesNotExist: transaction.events.append(Event(type=EventType.created)) pass if transaction.monto > MAX_AMOUNT: transaction.events.append(Event(type=EventType.error)) transaction.save() raise MalformedOrderException() order = transaction.get_order() transaction.save() # Send order to STP order.monto = order.monto / 100 res = order.registra() if res is not None and res.id > 0: transaction.stp_id = res.id transaction.events.append( Event(type=EventType.completed, metadata=str(res))) else: transaction.events.append( Event(type=EventType.error, metadata=str(res))) transaction.save()