From 97508109977ec5e515b9e38d1f01c38b5ad16047 Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Thu, 17 Oct 2024 08:43:41 -0700 Subject: [PATCH 01/12] Statuses fix --- jobs/payment-jobs/templates/eft_approved.html | 5 +++++ jobs/payment-jobs/templates/eft_declined.html | 7 +++++++ pay-api/src/pay_api/dtos/eft_shortname.py | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 jobs/payment-jobs/templates/eft_approved.html create mode 100644 jobs/payment-jobs/templates/eft_declined.html diff --git a/jobs/payment-jobs/templates/eft_approved.html b/jobs/payment-jobs/templates/eft_approved.html new file mode 100644 index 000000000..059215fac --- /dev/null +++ b/jobs/payment-jobs/templates/eft_approved.html @@ -0,0 +1,5 @@ +# Refund Request Approved for Short Name {{ shortName }} + +The refund request of ${{ unsettledAmount }} for short name: {{ shortName }} is now approved. + +[Log in to view detail]({{ shortNameDetailUrl }}) diff --git a/jobs/payment-jobs/templates/eft_declined.html b/jobs/payment-jobs/templates/eft_declined.html new file mode 100644 index 000000000..672e88168 --- /dev/null +++ b/jobs/payment-jobs/templates/eft_declined.html @@ -0,0 +1,7 @@ +# Refund Request Declined for Short Name {{ shortName }} + +The refund request of ${{ unsettledAmount }} for short name: {{ shortName }} is declined with the following message: + +{{ declineReason }} + +[Log in to view detail]({{ shortNameDetailUrl }}) diff --git a/pay-api/src/pay_api/dtos/eft_shortname.py b/pay-api/src/pay_api/dtos/eft_shortname.py index d5456c30c..68bf5aeff 100644 --- a/pay-api/src/pay_api/dtos/eft_shortname.py +++ b/pay-api/src/pay_api/dtos/eft_shortname.py @@ -75,6 +75,6 @@ class EFTShortNameRefundGetRequest: @classmethod def from_dict(cls, data: dict): """Convert from request json to EFTShortNameRefundDTO.""" - input_string = data.get("status", "") + input_string = data.get("statuses", "") statuses = input_string.split(",") if input_string else [] return EFTShortNameRefundGetRequest(statuses=statuses) From f4451c25bdde65dbcf08536f4c64ef547f32c039 Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 08:17:37 -0700 Subject: [PATCH 02/12] passing short name id to find refunds --- jobs/payment-jobs/templates/eft_approved.html | 5 ----- jobs/payment-jobs/templates/eft_declined.html | 7 ------- pay-api/src/pay_api/dtos/eft_shortname.py | 6 +++++- pay-api/src/pay_api/models/eft_refund.py | 4 +++- pay-api/src/pay_api/services/eft_refund.py | 2 +- 5 files changed, 9 insertions(+), 15 deletions(-) delete mode 100644 jobs/payment-jobs/templates/eft_approved.html delete mode 100644 jobs/payment-jobs/templates/eft_declined.html diff --git a/jobs/payment-jobs/templates/eft_approved.html b/jobs/payment-jobs/templates/eft_approved.html deleted file mode 100644 index 059215fac..000000000 --- a/jobs/payment-jobs/templates/eft_approved.html +++ /dev/null @@ -1,5 +0,0 @@ -# Refund Request Approved for Short Name {{ shortName }} - -The refund request of ${{ unsettledAmount }} for short name: {{ shortName }} is now approved. - -[Log in to view detail]({{ shortNameDetailUrl }}) diff --git a/jobs/payment-jobs/templates/eft_declined.html b/jobs/payment-jobs/templates/eft_declined.html deleted file mode 100644 index 672e88168..000000000 --- a/jobs/payment-jobs/templates/eft_declined.html +++ /dev/null @@ -1,7 +0,0 @@ -# Refund Request Declined for Short Name {{ shortName }} - -The refund request of ${{ unsettledAmount }} for short name: {{ shortName }} is declined with the following message: - -{{ declineReason }} - -[Log in to view detail]({{ shortNameDetailUrl }}) diff --git a/pay-api/src/pay_api/dtos/eft_shortname.py b/pay-api/src/pay_api/dtos/eft_shortname.py index 68bf5aeff..2a0156836 100644 --- a/pay-api/src/pay_api/dtos/eft_shortname.py +++ b/pay-api/src/pay_api/dtos/eft_shortname.py @@ -71,10 +71,14 @@ class EFTShortNameRefundGetRequest: """EFT Short name refund DTO.""" statuses: List[str] + short_name_id: int = None @classmethod def from_dict(cls, data: dict): """Convert from request json to EFTShortNameRefundDTO.""" input_string = data.get("statuses", "") + short_name_id = None + if data.get("shortNameId", None) is not None: + short_name_id = int(data.get("shortNameId", None)) statuses = input_string.split(",") if input_string else [] - return EFTShortNameRefundGetRequest(statuses=statuses) + return EFTShortNameRefundGetRequest(statuses=statuses, short_name_id=short_name_id) diff --git a/pay-api/src/pay_api/models/eft_refund.py b/pay-api/src/pay_api/models/eft_refund.py index d3fa6d7c5..82d5e0e2e 100644 --- a/pay-api/src/pay_api/models/eft_refund.py +++ b/pay-api/src/pay_api/models/eft_refund.py @@ -73,9 +73,11 @@ class EFTRefund(Audit): status = db.Column(db.String(25), nullable=True) @classmethod - def find_refunds(cls, statuses: List[str]): + def find_refunds(cls, statuses: List[str], short_name_id: int = None): """Return all refunds by status.""" query = cls.query if statuses: query = cls.query.filter(EFTRefund.status.in_(statuses)) + if short_name_id: + query = cls.query.filter(EFTRefund.short_name_id == short_name_id) return query.all() diff --git a/pay-api/src/pay_api/services/eft_refund.py b/pay-api/src/pay_api/services/eft_refund.py index 1a2cf583f..0ca26c0c2 100644 --- a/pay-api/src/pay_api/services/eft_refund.py +++ b/pay-api/src/pay_api/services/eft_refund.py @@ -80,7 +80,7 @@ def create_shortname_refund(request: dict, **kwargs): @staticmethod def get_shortname_refunds(data: EFTShortNameRefundGetRequest): """Get all refunds.""" - refunds = EFTRefundModel.find_refunds(data.statuses) + refunds = EFTRefundModel.find_refunds(data.statuses, data.short_name_id) return [refund.to_dict() for refund in refunds] @staticmethod From 29606c06b01fb882ff7e0390fff40e41ad6ea0e0 Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 08:35:31 -0700 Subject: [PATCH 03/12] test fix --- pay-api/tests/unit/api/test_eft_short_names.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pay-api/tests/unit/api/test_eft_short_names.py b/pay-api/tests/unit/api/test_eft_short_names.py index 725311951..e51f20caf 100755 --- a/pay-api/tests/unit/api/test_eft_short_names.py +++ b/pay-api/tests/unit/api/test_eft_short_names.py @@ -1071,12 +1071,12 @@ def test_post_shortname_refund_invalid_request(client, mocker, jwt): [ ("", "get_all", 3), ( - f"?status={EFTShortnameRefundStatus.APPROVED.value},{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", + f"?statuses={EFTShortnameRefundStatus.APPROVED.value},{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", "status_filter_multiple", 2, ), ( - f"?status={EFTShortnameRefundStatus.DECLINED.value}", + f"?statuses={EFTShortnameRefundStatus.DECLINED.value}", "status_filter_rejected", 1, ), From 4477923c0e3fcbc3c5e4bade115957f83f2ffa31 Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 09:04:08 -0700 Subject: [PATCH 04/12] Adding test cases for short_name_id --- .../tests/unit/api/test_eft_short_names.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pay-api/tests/unit/api/test_eft_short_names.py b/pay-api/tests/unit/api/test_eft_short_names.py index e51f20caf..f73d11c97 100755 --- a/pay-api/tests/unit/api/test_eft_short_names.py +++ b/pay-api/tests/unit/api/test_eft_short_names.py @@ -1067,24 +1067,35 @@ def test_post_shortname_refund_invalid_request(client, mocker, jwt): @pytest.mark.parametrize( - "query_string, test_name, count", + "query_string_factory, test_name, count", [ - ("", "get_all", 3), + (lambda short_id: "", "get_all", 3), ( - f"?statuses={EFTShortnameRefundStatus.APPROVED.value},{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", + lambda short_id: f"?short_name_id={short_id}&statuses={EFTShortnameRefundStatus.APPROVED.value},{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", + "short_name_id_status_filter_multiple", + 2, + ), + ( + lambda short_id: f"?short_name_id={short_id}&statuses={EFTShortnameRefundStatus.DECLINED.value}", + "short_name_id_status_filter_rejected", + 1, + ), + ( + lambda short_id: f"?statuses={EFTShortnameRefundStatus.APPROVED.value},{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", "status_filter_multiple", 2, ), ( - f"?statuses={EFTShortnameRefundStatus.DECLINED.value}", + lambda short_id: f"?statuses={EFTShortnameRefundStatus.DECLINED.value}", "status_filter_rejected", 1, ), ], ) -def test_get_shortname_refund(session, client, jwt, query_string, test_name, count): +def test_get_shortname_refund(session, client, jwt, query_string_factory, test_name, count): """Test get short name refund.""" short_name = factory_eft_shortname("TEST_SHORTNAME").save() + query_string = query_string_factory(short_name.id) factory_eft_refund(short_name_id=short_name.id, status=EFTShortnameRefundStatus.APPROVED.value) factory_eft_refund( short_name_id=short_name.id, From 84f43e2d9c0c1cbb100297d342dc1d0f8f1f8d3c Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 12:04:15 -0700 Subject: [PATCH 05/12] serializing --- pay-api/src/pay_api/dtos/eft_shortname.py | 8 ++++---- pay-api/src/pay_api/utils/converter.py | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pay-api/src/pay_api/dtos/eft_shortname.py b/pay-api/src/pay_api/dtos/eft_shortname.py index 2a0156836..8a68a9075 100644 --- a/pay-api/src/pay_api/dtos/eft_shortname.py +++ b/pay-api/src/pay_api/dtos/eft_shortname.py @@ -12,6 +12,7 @@ from attrs import define +from pay_api.utils.converter import Converter from pay_api.utils.serializable import Serializable @@ -67,7 +68,7 @@ class EFTShortNameRefundPatchRequest(Serializable): @define -class EFTShortNameRefundGetRequest: +class EFTShortNameRefundGetRequest(): """EFT Short name refund DTO.""" statuses: List[str] @@ -76,9 +77,8 @@ class EFTShortNameRefundGetRequest: @classmethod def from_dict(cls, data: dict): """Convert from request json to EFTShortNameRefundDTO.""" + converter = Converter() + short_name_id = converter.convert_to_int(data.get("shortNameId")) input_string = data.get("statuses", "") - short_name_id = None - if data.get("shortNameId", None) is not None: - short_name_id = int(data.get("shortNameId", None)) statuses = input_string.split(",") if input_string else [] return EFTShortNameRefundGetRequest(statuses=statuses, short_name_id=short_name_id) diff --git a/pay-api/src/pay_api/utils/converter.py b/pay-api/src/pay_api/utils/converter.py index d389efc71..d7a240575 100644 --- a/pay-api/src/pay_api/utils/converter.py +++ b/pay-api/src/pay_api/utils/converter.py @@ -97,3 +97,8 @@ def remove_nones(data: Dict[Any, Any]) -> Dict[str, Any]: elif val is not None: new_data[key] = val return new_data + + @staticmethod + def convert_to_int(value): + """Convert to int if not None.""" + return int(value) if value is not None else None From 96f2f661f4b3e543f6a4802683b89e3598b47436 Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 12:09:36 -0700 Subject: [PATCH 06/12] Serializable --- pay-api/src/pay_api/dtos/eft_shortname.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pay-api/src/pay_api/dtos/eft_shortname.py b/pay-api/src/pay_api/dtos/eft_shortname.py index 8a68a9075..cf2733db1 100644 --- a/pay-api/src/pay_api/dtos/eft_shortname.py +++ b/pay-api/src/pay_api/dtos/eft_shortname.py @@ -68,7 +68,7 @@ class EFTShortNameRefundPatchRequest(Serializable): @define -class EFTShortNameRefundGetRequest(): +class EFTShortNameRefundGetRequest(Serializable): """EFT Short name refund DTO.""" statuses: List[str] From 0b7e8b609ed6f8bfba94e79caf187019221027ab Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 12:15:01 -0700 Subject: [PATCH 07/12] linting --- pay-api/tests/unit/api/test_eft_short_names.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pay-api/tests/unit/api/test_eft_short_names.py b/pay-api/tests/unit/api/test_eft_short_names.py index f73d11c97..b01ca6b93 100755 --- a/pay-api/tests/unit/api/test_eft_short_names.py +++ b/pay-api/tests/unit/api/test_eft_short_names.py @@ -1071,7 +1071,8 @@ def test_post_shortname_refund_invalid_request(client, mocker, jwt): [ (lambda short_id: "", "get_all", 3), ( - lambda short_id: f"?short_name_id={short_id}&statuses={EFTShortnameRefundStatus.APPROVED.value},{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", + lambda short_id: f"?short_name_id={short_id}&statuses={EFTShortnameRefundStatus.APPROVED.value}," \ + f"{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", "short_name_id_status_filter_multiple", 2, ), @@ -1081,7 +1082,8 @@ def test_post_shortname_refund_invalid_request(client, mocker, jwt): 1, ), ( - lambda short_id: f"?statuses={EFTShortnameRefundStatus.APPROVED.value},{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", + lambda short_id: f"?statuses={EFTShortnameRefundStatus.APPROVED.value}," \ + f"{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", "status_filter_multiple", 2, ), From e7834f78c60169739cf0849a7f6a89a7f2ed10f2 Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 12:16:24 -0700 Subject: [PATCH 08/12] linting --- pay-api/tests/unit/api/test_eft_short_names.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pay-api/tests/unit/api/test_eft_short_names.py b/pay-api/tests/unit/api/test_eft_short_names.py index b01ca6b93..345d5bb46 100755 --- a/pay-api/tests/unit/api/test_eft_short_names.py +++ b/pay-api/tests/unit/api/test_eft_short_names.py @@ -1071,8 +1071,8 @@ def test_post_shortname_refund_invalid_request(client, mocker, jwt): [ (lambda short_id: "", "get_all", 3), ( - lambda short_id: f"?short_name_id={short_id}&statuses={EFTShortnameRefundStatus.APPROVED.value}," \ - f"{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", + lambda short_id: f"?short_name_id={short_id}&statuses={EFTShortnameRefundStatus.APPROVED.value}," + f"{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", "short_name_id_status_filter_multiple", 2, ), @@ -1082,8 +1082,8 @@ def test_post_shortname_refund_invalid_request(client, mocker, jwt): 1, ), ( - lambda short_id: f"?statuses={EFTShortnameRefundStatus.APPROVED.value}," \ - f"{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", + lambda short_id: f"?statuses={EFTShortnameRefundStatus.APPROVED.value}," + f"{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", "status_filter_multiple", 2, ), From 60954c2457de1b5a17f071edbc23d9b877425d17 Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 12:16:45 -0700 Subject: [PATCH 09/12] lint --- pay-api/tests/unit/api/test_eft_short_names.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pay-api/tests/unit/api/test_eft_short_names.py b/pay-api/tests/unit/api/test_eft_short_names.py index 345d5bb46..0590360d1 100755 --- a/pay-api/tests/unit/api/test_eft_short_names.py +++ b/pay-api/tests/unit/api/test_eft_short_names.py @@ -1082,7 +1082,7 @@ def test_post_shortname_refund_invalid_request(client, mocker, jwt): 1, ), ( - lambda short_id: f"?statuses={EFTShortnameRefundStatus.APPROVED.value}," + lambda short_id: f"?statuses={EFTShortnameRefundStatus.APPROVED.value}," f"{EFTShortnameRefundStatus.PENDING_APPROVAL.value}", "status_filter_multiple", 2, From e03881b6b7e1127a4f3a1fce1a7cd71eb236e986 Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 12:40:43 -0700 Subject: [PATCH 10/12] fixes --- pay-api/src/pay_api/dtos/eft_shortname.py | 11 ++++------- pay-api/src/pay_api/utils/converter.py | 5 ----- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/pay-api/src/pay_api/dtos/eft_shortname.py b/pay-api/src/pay_api/dtos/eft_shortname.py index cf2733db1..69ea4af7a 100644 --- a/pay-api/src/pay_api/dtos/eft_shortname.py +++ b/pay-api/src/pay_api/dtos/eft_shortname.py @@ -12,7 +12,6 @@ from attrs import define -from pay_api.utils.converter import Converter from pay_api.utils.serializable import Serializable @@ -71,14 +70,12 @@ class EFTShortNameRefundPatchRequest(Serializable): class EFTShortNameRefundGetRequest(Serializable): """EFT Short name refund DTO.""" - statuses: List[str] + statuses: str = None short_name_id: int = None @classmethod def from_dict(cls, data: dict): """Convert from request json to EFTShortNameRefundDTO.""" - converter = Converter() - short_name_id = converter.convert_to_int(data.get("shortNameId")) - input_string = data.get("statuses", "") - statuses = input_string.split(",") if input_string else [] - return EFTShortNameRefundGetRequest(statuses=statuses, short_name_id=short_name_id) + dto = super().from_dict(data) + dto.statuses = dto.statuses.split(",") if dto.statuses else [] + return EFTShortNameRefundGetRequest(statuses=dto.statuses, short_name_id=dto.short_name_id) diff --git a/pay-api/src/pay_api/utils/converter.py b/pay-api/src/pay_api/utils/converter.py index d7a240575..d389efc71 100644 --- a/pay-api/src/pay_api/utils/converter.py +++ b/pay-api/src/pay_api/utils/converter.py @@ -97,8 +97,3 @@ def remove_nones(data: Dict[Any, Any]) -> Dict[str, Any]: elif val is not None: new_data[key] = val return new_data - - @staticmethod - def convert_to_int(value): - """Convert to int if not None.""" - return int(value) if value is not None else None From a6032113cec2857b7973ccf5cf297d20455abe75 Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 12:43:30 -0700 Subject: [PATCH 11/12] lint --- pay-api/src/pay_api/dtos/eft_shortname.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pay-api/src/pay_api/dtos/eft_shortname.py b/pay-api/src/pay_api/dtos/eft_shortname.py index 69ea4af7a..fa13bc0a5 100644 --- a/pay-api/src/pay_api/dtos/eft_shortname.py +++ b/pay-api/src/pay_api/dtos/eft_shortname.py @@ -8,7 +8,6 @@ """ from decimal import Decimal -from typing import List from attrs import define From fc5b70344acc35d13f3eff99f4f7b751dddd41c2 Mon Sep 17 00:00:00 2001 From: Rodrigo Barraza Date: Fri, 18 Oct 2024 12:45:55 -0700 Subject: [PATCH 12/12] returning data transfer object --- pay-api/src/pay_api/dtos/eft_shortname.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pay-api/src/pay_api/dtos/eft_shortname.py b/pay-api/src/pay_api/dtos/eft_shortname.py index fa13bc0a5..7fb439d86 100644 --- a/pay-api/src/pay_api/dtos/eft_shortname.py +++ b/pay-api/src/pay_api/dtos/eft_shortname.py @@ -77,4 +77,4 @@ def from_dict(cls, data: dict): """Convert from request json to EFTShortNameRefundDTO.""" dto = super().from_dict(data) dto.statuses = dto.statuses.split(",") if dto.statuses else [] - return EFTShortNameRefundGetRequest(statuses=dto.statuses, short_name_id=dto.short_name_id) + return dto