Skip to content

Commit

Permalink
first approach
Browse files Browse the repository at this point in the history
  • Loading branch information
rogelioLpz committed Nov 4, 2023
1 parent 3c8c204 commit 87d9d62
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions speid/models/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class Transaction(Document, BaseModel):
'+stp_id',
'+speid_id',
'+clave_rastreo',
['+fecha_operacion', '+tipo'],
# The Unique-Sparse index skips over any document that is missing
# the indexed field (null values)
{'fields': ['+compound_key'], 'unique': True, 'sparse': True},
Expand Down
54 changes: 38 additions & 16 deletions speid/tasks/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_prior_business_day,
)
from stpmex.exc import EmptyResultsError, InvalidFutureDateError
from stpmex.resources import Orden

from speid.helpers import callback_helper
from speid.helpers.transaction_helper import (
Expand Down Expand Up @@ -168,21 +169,42 @@ def check_deposits_status(deposit: Dict) -> None:

for fecha_operacion in fechas_operacion:
try:
recibida = (
stpmex_client.ordenes_v2.consulta_clave_rastreo_recibida(
clave_rastreo=req.clave_rastreo,
fecha_operacion=fecha_operacion,
)
)
apply_stp_deposit(req.clave_rastreo, fecha_operacion)
except (InvalidFutureDateError, EmptyResultsError):
continue
else:
if (
recibida.tipoPago in REFUNDS_PAYMENTS_TYPES
or recibida.estado not in STP_VALID_DEPOSITS_STATUSES
):
return

stp_request = stp_model_to_dict(recibida)
process_incoming_transaction(stp_request)
return
return


def apply_stp_deposit(clave_rastreo, fecha_operacion) -> None:
"""Busca una transaccion en el API de STP y la aplica si no existe"""
recibida = stpmex_client.ordenes_v2.consulta_clave_rastreo_recibida(
clave_rastreo=clave_rastreo,
fecha_operacion=fecha_operacion,
)
if (
recibida.tipoPago in REFUNDS_PAYMENTS_TYPES
or recibida.estado not in STP_VALID_DEPOSITS_STATUSES
):
return
stp_request = stp_model_to_dict(recibida)
process_incoming_transaction(stp_request)


def get_deposits(fecha_operacion) -> List[Orden]:
# Todo: leer de stp la lista de depositos de hoy
...


@celery.task
def apply_missing_deposits() -> List[str]:
"""Consulta los depositos de un día y aplica los no abonados"""
fecha_operacion = dt.date.today() # Todo: Usar la correcta
stp_deposits = get_deposits(fecha_operacion)
transactions = Transaction.objects(
tipo=TipoTransaccion.deposito, fecha_operacion=fecha_operacion
)
claves = [t.clave_rastreo for t in transactions]
missing = [d for d in stp_deposits if d.claveRastreo not in claves]
for orden in missing:
apply_stp_deposit(orden.claveRastreo, fecha_operacion)
return [m.claveRastreo for m in missing]

0 comments on commit 87d9d62

Please sign in to comment.