diff --git a/api/namex/resources/payment/payment.py b/api/namex/resources/payment/payment.py index c64fcc4d4..ba6a37de9 100644 --- a/api/namex/resources/payment/payment.py +++ b/api/namex/resources/payment/payment.py @@ -14,7 +14,7 @@ from namex.models import State, User from namex.resources.name_requests.abstract_nr_resource import AbstractNameRequestResource from namex.services import EventRecorder -from namex.services.name_request.name_request_state import get_nr_state_actions, display_reapply_action +from namex.services.name_request.name_request_state import get_nr_state_actions, is_reapplication_eligible from namex.services.name_request.utils import get_active_payment, has_active_payment from namex.services.payment.exceptions import PaymentServiceError, SBCPaymentError, SBCPaymentException from namex.services.payment.models import PaymentRequest @@ -196,8 +196,9 @@ def handle_payment_response(payment_action, payment_response, payment, nr_id, nr timedelta(hours=NAME_REQUEST_EXTENSION_PAD_HOURS) < datetime.utcnow(): msg = f'Extend NR for payment.id={payment.id} nr_model.state{nr_model.stateCd}, nr_model.expires:{nr_model.expirationDate}' current_app.logger.debug(msg) - expiry_days = int(nr_svc.get_expiry_days(nr_model)) - nr_model.expirationDate = nr_svc.create_expiry_date(nr_model.expirationDate, expiry_days) + if is_reapplication_eligible(nr_model.expirationDate): + expiry_days = int(nr_svc.get_expiry_days(nr_model)) + nr_model.expirationDate = nr_svc.create_expiry_date(nr_model.expirationDate, expiry_days) payment.payment_completion_date = datetime.utcnow() nr_model.save_to_db() @@ -406,7 +407,7 @@ def post(self, nr_id, payment_action=NameRequestActions.CREATE.value): if existing_payment: # if we already have a payment record, we can request existing payment status and return it # get the payment status from Pay API - if payment_action == PaymentDAO.PaymentActions.REAPPLY.value and display_reapply_action(nr_model): + if payment_action == PaymentDAO.PaymentActions.REAPPLY.value and is_reapplication_eligible(nr_model.expirationDate): # skip valid cases of REAPPLY, as these potentially can have more than a single instance pass else: diff --git a/api/namex/services/__init__.py b/api/namex/services/__init__.py index 7e5a486a0..efe6d58f7 100644 --- a/api/namex/services/__init__.py +++ b/api/namex/services/__init__.py @@ -3,4 +3,5 @@ from .exceptions import ServicesError from .messages import MessageServices from .audit_trail import EventRecorder +from .name_request.name_request_state import is_reapplication_eligible diff --git a/api/namex/services/name_request/name_request_state.py b/api/namex/services/name_request/name_request_state.py index 4ceecca03..cb2c51c8d 100644 --- a/api/namex/services/name_request/name_request_state.py +++ b/api/namex/services/name_request/name_request_state.py @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from flask_restx.fields import Boolean from namex.constants import \ @@ -76,18 +76,24 @@ def display_reapply_action(nr_model=None) -> Boolean: """Logic for displaying the renew button.""" try: if nr_model and nr_model.stateCd in (State.CONDITIONAL, State.APPROVED): - if nr_model.expirationDate and not nr_model.is_expired and not nr_model.has_consumed_name: - todays_date = datetime.utcnow().date() - expiry_date = nr_model.expirationDate.date() - - delta = expiry_date - todays_date - if delta.days <= 14: - return True + if nr_model.is_expired or nr_model.has_consumed_name: + return False + return is_reapplication_eligible(nr_model.expirationDate) return False except Exception as err: raise NameRequestActionError(err) +def is_reapplication_eligible(expiration_date) -> Boolean: + if expiration_date: + todays_date = datetime.now(timezone.utc).date() + expiry_date = expiration_date.date() + + delta = expiry_date - todays_date + return delta.days <= 14 + return False + + def display_resubmit_action(nr_model=None) -> Boolean: """Logic for displaying the resubmit button.""" try: diff --git a/services/namex-pay/src/namex_pay/version.py b/services/namex-pay/src/namex_pay/version.py index 5a223e27d..523440a91 100644 --- a/services/namex-pay/src/namex_pay/version.py +++ b/services/namex-pay/src/namex_pay/version.py @@ -22,4 +22,4 @@ Development release segment: .devN """ -__version__ = '0.1.4' # pylint: disable=invalid-name +__version__ = '0.1.5' # pylint: disable=invalid-name diff --git a/services/namex-pay/src/namex_pay/worker.py b/services/namex-pay/src/namex_pay/worker.py index eecc25b3d..20d2a82c5 100644 --- a/services/namex-pay/src/namex_pay/worker.py +++ b/services/namex-pay/src/namex_pay/worker.py @@ -38,7 +38,7 @@ from flask import Flask from namex import nro from namex.models import db, Event, Payment, Request as RequestDAO, State, User # noqa:I001; import orders -from namex.services import EventRecorder, queue # noqa:I005; +from namex.services import EventRecorder, queue, is_reapplication_eligible # noqa:I005; from queue_common.messages import create_cloud_event_msg # noqa:I005 from queue_common.service import QueueServiceManager from queue_common.service_utils import QueueException, logger @@ -131,7 +131,9 @@ async def update_payment_record(payment: Payment) -> Optional[Payment]: logger.debug(msg) capture_message(msg) raise QueueException(msg) - nr.expirationDate = nr.expirationDate + timedelta(days=NAME_REQUEST_LIFESPAN_DAYS) + if is_reapplication_eligible(nr.expriationDate): + # to avoid duplicate expiration date calculated + nr.expirationDate = nr.expirationDate + timedelta(days=NAME_REQUEST_LIFESPAN_DAYS) payment.payment_completion_date = datetime.utcnow() payment.payment_status_code = State.COMPLETED