From a25095c666a2cc75bcd71689292fc7698386902c Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Tue, 6 Aug 2024 16:06:06 -0700 Subject: [PATCH 1/5] Add in section for EFT CREATED -> to be returned as COMPLETED --- pay-api/src/pay_api/models/invoice.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pay-api/src/pay_api/models/invoice.py b/pay-api/src/pay_api/models/invoice.py index 68d9df85a..d8dacce9a 100644 --- a/pay-api/src/pay_api/models/invoice.py +++ b/pay-api/src/pay_api/models/invoice.py @@ -257,6 +257,11 @@ def _clean_up(self, data, many): # pylint: disable=unused-argument if data.get('status_code') == InvoiceStatus.PAID.value: data['status_code'] = PaymentStatus.COMPLETED.value + # Backwards compatibility - Important for ESRA, marking the invoice as COMPLETED. + if data.get('status_code') == InvoiceStatus.CREATED.value and \ + data.get('payment_method') == PaymentMethod.EFT.value: + data['status_code'] = PaymentStatus.COMPLETED.value + return data From 68386db141d48603fa556983a1867414473f48df Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Tue, 6 Aug 2024 16:14:53 -0700 Subject: [PATCH 2/5] Unit test + small comment --- pay-api/src/pay_api/models/invoice.py | 1 + pay-api/tests/unit/services/test_invoice.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pay-api/src/pay_api/models/invoice.py b/pay-api/src/pay_api/models/invoice.py index d8dacce9a..4add15096 100644 --- a/pay-api/src/pay_api/models/invoice.py +++ b/pay-api/src/pay_api/models/invoice.py @@ -303,6 +303,7 @@ def from_row(cls, row): https://www.attrs.org/en/stable/init.html """ # Similar to _clean_up in InvoiceSchema. + # In the future may need to add a mapping from EFT Status: CREATED -> COMPLETED status_code = PaymentStatus.COMPLETED.value if row.invoice_status_code == InvoiceStatus.PAID.value \ else row.invoice_status_code business_identifier = None if row.business_identifier and row.business_identifier.startswith('T') \ diff --git a/pay-api/tests/unit/services/test_invoice.py b/pay-api/tests/unit/services/test_invoice.py index 1c97a686e..d9012c263 100644 --- a/pay-api/tests/unit/services/test_invoice.py +++ b/pay-api/tests/unit/services/test_invoice.py @@ -22,10 +22,29 @@ from pay_api.exceptions import BusinessException from pay_api.models import FeeSchedule from pay_api.services.invoice import Invoice as Invoice_service +from pay_api.utils.enums import PaymentMethod, PaymentStatus from tests.utilities.base_test import ( factory_invoice, factory_payment, factory_payment_account, factory_payment_line_item) +def test_invoice_eft_created_return_completed(session): + """Assert that the invoice is saved to the table.""" + payment_account = factory_payment_account(payment_method_code='EFT') + payment = factory_payment() + payment_account.save() + payment.save() + i = factory_invoice(payment_account=payment_account) + i.save() + fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') + line = factory_payment_line_item(i.id, fee_schedule_id=fee_schedule.fee_schedule_id) + line.save() + invoice = Invoice_service.find_by_id(i.id, skip_auth_check=True).asdict() + + assert invoice is not None + assert invoice.payment_method == PaymentMethod.EFT.value + assert invoice.invoice_status_code == PaymentStatus.COMPLETED.value + + def test_invoice_saved_from_new(session): """Assert that the invoice is saved to the table.""" payment_account = factory_payment_account() From d1820c667a12c84e0e9b78ceda2a727f5c522acb Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Tue, 6 Aug 2024 16:23:59 -0700 Subject: [PATCH 3/5] small unit test fixes --- pay-api/tests/unit/services/test_invoice.py | 2 +- .../tests/unit/services/test_payment_service.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pay-api/tests/unit/services/test_invoice.py b/pay-api/tests/unit/services/test_invoice.py index d9012c263..d615f7940 100644 --- a/pay-api/tests/unit/services/test_invoice.py +++ b/pay-api/tests/unit/services/test_invoice.py @@ -41,7 +41,7 @@ def test_invoice_eft_created_return_completed(session): invoice = Invoice_service.find_by_id(i.id, skip_auth_check=True).asdict() assert invoice is not None - assert invoice.payment_method == PaymentMethod.EFT.value + assert invoice.payment_method_code == PaymentMethod.EFT.value assert invoice.invoice_status_code == PaymentStatus.COMPLETED.value diff --git a/pay-api/tests/unit/services/test_payment_service.py b/pay-api/tests/unit/services/test_payment_service.py index be9483799..fba745bb6 100644 --- a/pay-api/tests/unit/services/test_payment_service.py +++ b/pay-api/tests/unit/services/test_payment_service.py @@ -260,8 +260,8 @@ def test_create_pad_payment(session, public_user_mock): business_identifier='CP0002000'), get_auth_premium_user()) assert payment_response is not None - assert payment_response.get('payment_method') == 'PAD' - assert payment_response.get('status_code') == 'APPROVED' + assert payment_response.get('payment_method') == PaymentMethod.PAD.value + assert payment_response.get('status_code') == InvoiceStatus.APPROVED.value def test_create_online_banking_payment(session, public_user_mock): @@ -273,8 +273,8 @@ def test_create_online_banking_payment(session, public_user_mock): business_identifier='CP0002000'), get_auth_premium_user()) assert payment_response is not None - assert payment_response.get('payment_method') == 'ONLINE_BANKING' - assert payment_response.get('status_code') == 'CREATED' + assert payment_response.get('payment_method') == PaymentMethod.ONLINE_BANKING.value + assert payment_response.get('status_code') == PaymentStatus.COMPLETED.value def test_patch_online_banking_payment_to_direct_pay(session, public_user_mock): @@ -286,8 +286,8 @@ def test_patch_online_banking_payment_to_direct_pay(session, public_user_mock): business_identifier='CP0002000'), get_auth_premium_user()) assert payment_response is not None - assert payment_response.get('payment_method') == 'ONLINE_BANKING' - assert payment_response.get('status_code') == 'CREATED' + assert payment_response.get('payment_method') == PaymentMethod.ONLINE_BANKING.value + assert payment_response.get('status_code') == PaymentStatus.CREATED.value invoice_id = payment_response.get('id') @@ -330,7 +330,7 @@ def test_create_eft_payment(session, public_user_mock): get_auth_premium_user()) assert payment_response is not None assert payment_response.get('payment_method') == PaymentMethod.EFT.value - assert payment_response.get('status_code') == 'CREATED' + assert payment_response.get('status_code') == PaymentStatus.COMPLETED.value def test_create_eft_payment_ff_disabled(session, public_user_mock): @@ -358,7 +358,7 @@ def test_create_wire_payment(session, public_user_mock): get_auth_premium_user()) assert payment_response is not None assert payment_response.get('payment_method') == PaymentMethod.WIRE.value - assert payment_response.get('status_code') == 'CREATED' + assert payment_response.get('status_code') == PaymentStatus.CREATED.value def test_internal_rs_back_active(session, public_user_mock): From daca6c62bba99f33f0cca0c51cf75d1536640181 Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Tue, 6 Aug 2024 16:37:18 -0700 Subject: [PATCH 4/5] unit test fixes --- pay-api/tests/unit/services/test_invoice.py | 4 ++-- pay-api/tests/unit/services/test_payment_service.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pay-api/tests/unit/services/test_invoice.py b/pay-api/tests/unit/services/test_invoice.py index d615f7940..a4c8d08d6 100644 --- a/pay-api/tests/unit/services/test_invoice.py +++ b/pay-api/tests/unit/services/test_invoice.py @@ -41,8 +41,8 @@ def test_invoice_eft_created_return_completed(session): invoice = Invoice_service.find_by_id(i.id, skip_auth_check=True).asdict() assert invoice is not None - assert invoice.payment_method_code == PaymentMethod.EFT.value - assert invoice.invoice_status_code == PaymentStatus.COMPLETED.value + assert invoice['payment_method'] == PaymentMethod.EFT.value + assert invoice['status_code'] == PaymentStatus.COMPLETED.value def test_invoice_saved_from_new(session): diff --git a/pay-api/tests/unit/services/test_payment_service.py b/pay-api/tests/unit/services/test_payment_service.py index fba745bb6..e2e08ba1c 100644 --- a/pay-api/tests/unit/services/test_payment_service.py +++ b/pay-api/tests/unit/services/test_payment_service.py @@ -274,7 +274,7 @@ def test_create_online_banking_payment(session, public_user_mock): get_auth_premium_user()) assert payment_response is not None assert payment_response.get('payment_method') == PaymentMethod.ONLINE_BANKING.value - assert payment_response.get('status_code') == PaymentStatus.COMPLETED.value + assert payment_response.get('status_code') == PaymentStatus.CREATED.value def test_patch_online_banking_payment_to_direct_pay(session, public_user_mock): From 4207db1c61552764ad9ec284efdf4523f8e9d042 Mon Sep 17 00:00:00 2001 From: Travis Semple Date: Tue, 6 Aug 2024 16:39:04 -0700 Subject: [PATCH 5/5] tweak --- pay-api/tests/unit/services/test_invoice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pay-api/tests/unit/services/test_invoice.py b/pay-api/tests/unit/services/test_invoice.py index a4c8d08d6..814c5c4d5 100644 --- a/pay-api/tests/unit/services/test_invoice.py +++ b/pay-api/tests/unit/services/test_invoice.py @@ -29,11 +29,11 @@ def test_invoice_eft_created_return_completed(session): """Assert that the invoice is saved to the table.""" - payment_account = factory_payment_account(payment_method_code='EFT') + payment_account = factory_payment_account() payment = factory_payment() payment_account.save() payment.save() - i = factory_invoice(payment_account=payment_account) + i = factory_invoice(payment_account=payment_account, payment_method_code=PaymentMethod.EFT.value) i.save() fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN') line = factory_payment_line_item(i.id, fee_schedule_id=fee_schedule.fee_schedule_id)