Skip to content

Commit

Permalink
23618 - Handling feedback for EFT Refunds (#1769)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-barraza authored Oct 8, 2024
1 parent b72aaec commit 726b002
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 18 deletions.
8 changes: 5 additions & 3 deletions pay-api/src/pay_api/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,11 @@ class EFTShortnameStatus(Enum):
class EFTShortnameRefundStatus(Enum):
"""EFT Short name refund statuses."""

APPROVED = "APPROVED"
PENDING_APPROVAL = "PENDING_APPROVAL"
DECLINED = "DECLINED"
APPROVED = 'APPROVED'
PENDING_APPROVAL = 'PENDING_APPROVAL'
DECLINED = 'DECLINED'
COMPLETED = 'COMPLETED'
ERRORED = 'ERRORED'


class EFTPaymentActions(Enum):
Expand Down
8 changes: 4 additions & 4 deletions pay-queue/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pay-queue/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ itsdangerous = "^2.1.2"
protobuf = "4.25.3"
launchdarkly-server-sdk = "^8.2.1"
cachecontrol = "^0.14.0"
pay-api = {git = "https://github.com/seeker25/sbc-pay.git", subdirectory = "pay-api", branch = "19163"}
pay-api = {git = "https://github.com/bcgov/sbc-pay.git", subdirectory = "pay-api", rev = "28731edaf70d6626d9bc122bf6cae3c1590788c5"}
pg8000 = "^1.30.5"


Expand Down
26 changes: 24 additions & 2 deletions pay-queue/src/pay_queue/services/cgi_reconciliations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from flask import current_app
from pay_api.models import DistributionCode as DistributionCodeModel
from pay_api.models import EFTRefund as EFTRefundModel
from pay_api.models import EjvFile as EjvFileModel
from pay_api.models import EjvHeader as EjvHeaderModel
from pay_api.models import EjvLink as EjvLinkModel
Expand All @@ -34,8 +35,8 @@
from pay_api.services import gcp_queue_publisher
from pay_api.services.gcp_queue_publisher import QueueMessage
from pay_api.utils.enums import (
DisbursementStatus, EjvFileType, EJVLinkType, InvoiceReferenceStatus, InvoiceStatus, PaymentMethod, PaymentStatus,
PaymentSystem, QueueSources, RoutingSlipStatus)
DisbursementStatus, EFTShortnameRefundStatus, EjvFileType, EJVLinkType, InvoiceReferenceStatus, InvoiceStatus,
PaymentMethod, PaymentStatus, PaymentSystem, QueueSources, RoutingSlipStatus)
from sbc_common_components.utils.enums import QueueMessageTypes
from sentry_sdk import capture_message

Expand Down Expand Up @@ -407,6 +408,8 @@ def _process_ap_header(line, ejv_file: EjvFileModel) -> bool:
has_errors = False
if ejv_file.file_type == EjvFileType.REFUND.value:
has_errors = _process_ap_header_routing_slips(line)
elif ejv_file.file_type == EjvFileType.EFT_REFUND.value:
has_errors = _process_ap_header_eft(line)
else:
has_errors = _process_ap_header_non_gov_disbursement(line, ejv_file)
return has_errors
Expand All @@ -431,6 +434,25 @@ def _process_ap_header_routing_slips(line) -> bool:
return has_errors


def _process_ap_header_eft(line) -> bool:
has_errors = False
eft_refund_id = line[19:69].strip()
eft_refund = EFTRefundModel.find_by_id(eft_refund_id)
ap_header_return_code = line[414:418].strip()
ap_header_error_message = line[418:568].strip()
if _get_disbursement_status(ap_header_return_code) == DisbursementStatus.ERRORED.value:
has_errors = True
eft_refund.status = EFTShortnameRefundStatus.ERRORED.value
eft_refund.disbursement_status_code = DisbursementStatus.ERRORED.value
capture_message(f'EFT Refund failed for {eft_refund_id}, reason : {ap_header_error_message}', level='error')
else:
eft_refund.status = EFTShortnameRefundStatus.COMPLETED.value
eft_refund.disbursement_status_code = DisbursementStatus.COMPLETED.value
eft_refund.disbursement_date = datetime.now(tz=timezone.utc)
eft_refund.save()
return has_errors


def _process_ap_header_non_gov_disbursement(line, ejv_file: EjvFileModel) -> bool:
has_errors = False
invoice_id = line[19:69].strip()
Expand Down
40 changes: 36 additions & 4 deletions pay-queue/tests/integration/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from datetime import datetime, timezone

from pay_api.models import (
CfsAccount, DistributionCode, Invoice, InvoiceReference, Payment, PaymentAccount, PaymentLineItem,
PaymentTransaction, Receipt, Refund, RoutingSlip, Statement, StatementInvoices, StatementSettings)
CfsAccount, DistributionCode, EFTRefund, EFTShortnames, Invoice, InvoiceReference, Payment, PaymentAccount,
PaymentLineItem, PaymentTransaction, Receipt, Refund, RoutingSlip, Statement, StatementInvoices, StatementSettings)
from pay_api.utils.enums import (
CfsAccountStatus, InvoiceReferenceStatus, InvoiceStatus, LineItemStatus, PaymentMethod, PaymentStatus,
PaymentSystem, RoutingSlipStatus, TransactionStatus)
CfsAccountStatus, DisbursementStatus, EFTShortnameRefundStatus, EFTShortnameType, InvoiceReferenceStatus,
InvoiceStatus, LineItemStatus, PaymentMethod, PaymentStatus, PaymentSystem, RoutingSlipStatus, TransactionStatus)


def factory_premium_payment_account(bcol_user_id='PB25020', bcol_account_id='1234567890', auth_account_id='1234'):
Expand Down Expand Up @@ -155,6 +155,38 @@ def factory_payment_transaction(payment_id: int):
transaction_start_time=datetime.now()).save()


def factory_create_eft_shortname(short_name: str, short_name_type: str = EFTShortnameType.EFT.value):
"""Return Factory."""
short_name = EFTShortnames(
short_name=short_name,
type=short_name_type
).save()
return short_name


def factory_create_eft_refund(
cas_supplier_number: str = '1234',
comment: str = 'Test Comment',
refund_amount: float = 100.0,
refund_email: str = '[email protected]',
short_name_id: int = 1,
status: str = EFTShortnameRefundStatus.APPROVED.value,
disbursement_status_code: str = DisbursementStatus.ACKNOWLEDGED.value
):
"""Return Factory."""
eft_refund = EFTRefund(
cas_supplier_number=cas_supplier_number,
comment=comment,
disbursement_status_code=disbursement_status_code,
refund_amount=refund_amount,
refund_email=refund_email,
short_name_id=short_name_id,
status=status,
created_on=datetime.now(tz=timezone.utc)
).save()
return eft_refund


def factory_create_eft_account(auth_account_id='1234', status=CfsAccountStatus.ACTIVE.value,
cfs_account='1234'):
"""Return Factory."""
Expand Down
Loading

0 comments on commit 726b002

Please sign in to comment.