Skip to content

Commit

Permalink
11899 - CSO total and service fee fix (#919)
Browse files Browse the repository at this point in the history
* 11899 CSO total and service fee fix

* comment fix

* linting fix

* linting fix

* Quantity bug fix for test

* test fix

* test fix

* Update payment_line_item.py

* Update payment_line_item.py

* Update line_item.json

* added unit tests

* added unit tests

* added unit tests

* added unit tests

* added unit tests

* added unit tests
  • Loading branch information
ritvick authored May 3, 2022
1 parent 97c909e commit 6f5d3c9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/schemas/schemas/line_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
},
"total": {
"$id": "#/properties/line_items/items/properties/total",
"type": "integer",
"type": "number",
"title": "Line Total",
"default": 0,
"examples": [
Expand Down
4 changes: 4 additions & 0 deletions pay-api/src/pay_api/services/fee_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ def find_by_corp_type_and_filing_type( # pylint: disable=too-many-arguments
# Set transaction fees
fee_schedule.service_fees = FeeSchedule.calculate_service_fees(fee_schedule_dao, account_fee)

# Special case for CSO partner type which is different from normal flow
if fee_schedule.corp_type_code == 'CSO' and fee_schedule.quantity:
fee_schedule.service_fees = fee_schedule.service_fees * fee_schedule.quantity

if kwargs.get('is_priority') and fee_schedule_dao.priority_fee and apply_filing_fees:
fee_schedule.priority_fee = fee_schedule_dao.priority_fee.amount
if kwargs.get('is_future_effective') and fee_schedule_dao.future_effective_fee and apply_filing_fees:
Expand Down
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/services/payment_line_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def create(invoice_id: int, fee: FeeSchedule, **kwargs):
user: UserContext = kwargs['user']
p = PaymentLineItem()
p.invoice_id = invoice_id
p.total = fee.total_excluding_service_fees
p.total = fee.total
p.fee_schedule_id = fee.fee_schedule_id
p.description = fee.description
p.filing_fees = fee.fee_amount
Expand Down
18 changes: 16 additions & 2 deletions pay-api/tests/unit/api/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
from pay_api.utils.enums import CfsAccountStatus, PaymentMethod, Role
from tests.utilities.base_test import (
get_basic_account_payload, get_claims, get_gov_account_payload, get_gov_account_payload_with_no_revenue_account,
get_pad_account_payload, get_payment_request, get_payment_request_with_service_fees, get_premium_account_payload,
get_unlinked_pad_account_payload, token_header)
get_pad_account_payload, get_payment_request, get_payment_request_for_cso, get_payment_request_with_service_fees,
get_premium_account_payload, get_unlinked_pad_account_payload, token_header)


fake = Faker()
Expand Down Expand Up @@ -101,6 +101,20 @@ def test_account_purchase_history_with_service_account(session, client, jwt, app
assert rv.json.get('items')[0]['corpTypeCode'] == 'CSO'


def test_payment_request_for_cso_with_service_account(session, client, jwt, app):
"""Assert Service charge is calculated based on quantity."""
quantity = 2
token = jwt.create_jwt(get_claims(roles=[Role.SYSTEM.value], product_code='CSO'), token_header)
headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}
rv = client.post('/api/v1/payment-requests',
data=json.dumps(get_payment_request_for_cso(quantity)),
headers=headers)
rv2 = client.get('/api/v1/fees/CSO/CSBVFEE', headers=headers)
assert rv2.status_code == 200
assert rv.status_code == 201
assert rv.json.get('lineItems')[0]['serviceFees'] == rv2.json.get('serviceFees') * quantity


def test_account_purchase_history_invalid_request(session, client, jwt, app):
"""Assert that the endpoint returns 400."""
token = jwt.create_jwt(get_claims(), token_header)
Expand Down
23 changes: 23 additions & 0 deletions pay-api/tests/utilities/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,29 @@ def get_payment_request_with_service_fees(business_identifier: str = 'CP0001234'
}


def get_payment_request_for_cso(csbfile_quantity: int = 2):
"""Return a payment request object for cso."""
return {
'filingInfo': {
'filingIdentifier': '34522',
'folioNumber': '22',
'filingTypes': [{
'filingTypeCode': 'CSBVFEE',
'quantity': csbfile_quantity
}]
},
'businessInfo': {
'businessIdentifier': 'business_indentifier',
'businessName': 'business_name',
'corpType': 'CSO'
},
'details': [{
'label': 'A Label',
'value': 'A value'
}]
}


def get_payment_request_with_folio_number(business_identifier: str = 'CP0001234', folio_number: str = '1234567890'):
"""Return a payment request object."""
return {
Expand Down

0 comments on commit 6f5d3c9

Please sign in to comment.