Skip to content

Commit

Permalink
Add in section for EFT CREATED -> to be returned as COMPLETED (bcgov#…
Browse files Browse the repository at this point in the history
  • Loading branch information
seeker25 authored Aug 6, 2024
1 parent 6cc23b9 commit b28e74a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
6 changes: 6 additions & 0 deletions pay-api/src/pay_api/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -298,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') \
Expand Down
19 changes: 19 additions & 0 deletions pay-api/tests/unit/services/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = factory_payment()
payment_account.save()
payment.save()
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)
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['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()
Expand Down
16 changes: 8 additions & 8 deletions pay-api/tests/unit/services/test_payment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.CREATED.value


def test_patch_online_banking_payment_to_direct_pay(session, public_user_mock):
Expand All @@ -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')

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit b28e74a

Please sign in to comment.