Skip to content

Commit

Permalink
25372 - Support $1.50/$1.00 service fees with $0 base fee in DIRECT_P…
Browse files Browse the repository at this point in the history
…AY (#1879)
  • Loading branch information
Jxio authored Jan 27, 2025
1 parent 06d4efe commit 108b915
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
12 changes: 6 additions & 6 deletions pay-api/src/pay_api/services/direct_pay_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ def _create_revenue_string(invoice) -> str:
payment_line_items = PaymentLineItemModel.find_by_invoice_ids([invoice.id])
index: int = 0
revenue_item = []
for payment_line_item in payment_line_items:
if payment_line_item.total == 0:
continue

for payment_line_item in payment_line_items:
distribution_code: DistributionCodeModel = DistributionCodeModel.find_by_id(
payment_line_item.fee_distribution_id
)

index = index + 1
revenue_string = DirectPayService._get_gl_coding(distribution_code, payment_line_item.total)
if payment_line_item.total > 0:
index = index + 1
revenue_string = DirectPayService._get_gl_coding(distribution_code, payment_line_item.total)

revenue_item.append(f"{index}:{revenue_string}")

revenue_item.append(f"{index}:{revenue_string}")
if payment_line_item.service_fees is not None and payment_line_item.service_fees > 0:
index = index + 1
service_fee: DistributionCodeModel = DistributionCodeModel.find_by_id(
Expand Down
43 changes: 28 additions & 15 deletions pay-api/tests/unit/services/test_direct_pay_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def test_get_payment_system_url(session, public_user_mock):
assert expected_hash_str == url_param_dict["hashValue"]


def test_get_payment_system_url_service_fees(session, public_user_mock):
@pytest.mark.parametrize(
"base_fee, service_fee, expected_revenue_strs", [(None, 100, 2), (Decimal("0.00"), Decimal("1.50"), 1)]
)
def test_get_payment_system_url_service_fees(session, public_user_mock, base_fee, service_fee, expected_revenue_strs):
"""Assert that the url returned is correct."""
today = current_local_time().strftime(PAYBC_DATE_FORMAT)
payment_account = factory_payment_account()
Expand All @@ -117,16 +120,18 @@ def test_get_payment_system_url_service_fees(session, public_user_mock):
# update the existing gl code with new values
distribution_code_svc.save_or_update(distribution_code_payload, distribution_code.distribution_code_id)

service_fee = 100
line = factory_payment_line_item(
invoice.id,
fee_schedule_id=fee_schedule.fee_schedule_id,
total=base_fee if base_fee is not None else Decimal("10.00"),
filing_fees=base_fee if base_fee is not None else Decimal("10.00"),
service_fees=service_fee,
)
line.save()
direct_pay_service = DirectPayService()
payment_response_url = direct_pay_service.get_payment_system_url_for_invoice(invoice, invoice_ref, "google.com")
url_param_dict = dict(urllib.parse.parse_qsl(urllib.parse.urlsplit(payment_response_url).query))

assert url_param_dict["trnDate"] == today
assert url_param_dict["glDate"] == today
assert url_param_dict["description"] == "Direct_Sale"
Expand All @@ -135,23 +140,33 @@ def test_get_payment_system_url_service_fees(session, public_user_mock):
assert url_param_dict["trnAmount"] == str(invoice.total)
assert url_param_dict["paymentMethod"] == "CC"
assert url_param_dict["redirectUri"] == "google.com"
revenue_str = (
f"1:{distribution_code_payload['client']}."
f"{distribution_code_payload['responsibilityCentre']}."
f"{distribution_code_payload['serviceLine']}."
f"{distribution_code_payload['stob']}."
f"{distribution_code_payload['projectCode']}."
f"000000.0000:10.00"
)

# Generate revenue strings based on base fee and service fee
revenue_strs = []
if base_fee is None or base_fee > 0:
revenue_str = (
f"1:{distribution_code_payload['client']}."
f"{distribution_code_payload['responsibilityCentre']}."
f"{distribution_code_payload['serviceLine']}."
f"{distribution_code_payload['stob']}."
f"{distribution_code_payload['projectCode']}."
f"000000.0000:10.00"
)
revenue_strs.append(revenue_str)

revenue_str_service_fee = (
f"2:{distribution_code_payload['client']}."
f"{len(revenue_strs) + 1}:{distribution_code_payload['client']}."
f"{distribution_code_payload['responsibilityCentre']}."
f"{distribution_code_payload['serviceLine']}."
f"{distribution_code_payload['stob']}."
f"{distribution_code_payload['projectCode']}."
f"000000.0000:{format(service_fee, DECIMAL_PRECISION)}"
)
assert url_param_dict["revenue"] == f"{revenue_str}|{revenue_str_service_fee}"
revenue_strs.append(revenue_str_service_fee)

assert url_param_dict["revenue"] == "|".join(revenue_strs)
assert len(url_param_dict["revenue"].split("|")) == expected_revenue_strs

urlstring = (
f"trnDate={today}&pbcRefNumber={current_app.config.get('PAYBC_DIRECT_PAY_REF_NUMBER')}&"
f"glDate={today}&description=Direct_Sale&"
Expand All @@ -160,11 +175,9 @@ def test_get_payment_system_url_service_fees(session, public_user_mock):
f"paymentMethod=CC&"
f"redirectUri=google.com&"
f"currency=CAD&"
f"revenue={revenue_str}|"
f"{revenue_str_service_fee}"
f"revenue={url_param_dict['revenue']}"
)
expected_hash_str = HashingService.encode(urlstring)

assert expected_hash_str == url_param_dict["hashValue"]


Expand Down

0 comments on commit 108b915

Please sign in to comment.