Skip to content

Commit

Permalink
changes for zero dollar routing slip payments (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
saravanpa-aot authored Oct 25, 2021
1 parent 87fbe9b commit 7c56699
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pay-api/src/pay_api/services/internal_pay_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ def create_invoice(self, payment_account: PaymentAccount, line_items: [PaymentLi
"""Return a static invoice number."""
current_app.logger.debug('<create_invoice')
routing_slip = None
is_zero_dollar_invoice = invoice.total == 0
if routing_slip_number := invoice.routing_slip:
routing_slip = RoutingSlipModel.find_by_number(routing_slip_number)
InternalPayService._validate_routing_slip(routing_slip, invoice)
if routing_slip is not None:
if not is_zero_dollar_invoice and routing_slip is not None:
line_item_models: List[PaymentLineItemModel] = []
for line_item in line_items:
line_item_models.append(PaymentLineItemModel.find_by_id(line_item.id))
Expand Down
25 changes: 25 additions & 0 deletions pay-api/tests/unit/api/test_payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,31 @@ def test_payment_creation_with_routing_slip(session, client, jwt, app):
assert schema_utils.validate(rv.json, 'invoice')[0]


def test_zero_dollar_payment_creation_with_existing_routing_slip(client, jwt):
"""Assert that the endpoint returns 201."""
claims = get_claims(roles=[Role.FAS_CREATE.value, Role.FAS_SEARCH.value, Role.STAFF.value, 'make_payment'])
token = jwt.create_jwt(claims, token_header)
headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}
payload = get_routing_slip_request()
rv = client.post('/api/v1/fas/routing-slips', data=json.dumps(payload), headers=headers)
assert rv.status_code == 201
rs_number = rv.json.get('number')

data = get_zero_dollar_payment_request()
data['accountInfo'] = {'routingSlip': rs_number}

rv = client.post('/api/v1/payment-requests', data=json.dumps(data), headers=headers)
assert rv.status_code == 201
assert rv.json.get('_links') is not None
total = rv.json.get('total')
rv = client.post('/api/v1/fas/routing-slips/queries', data=json.dumps({'routingSlipNumber': rs_number}),
headers=headers)

items = rv.json.get('items')

assert items[0].get('remainingAmount') == payload.get('payments')[0].get('paidAmount') - total


@pytest.mark.parametrize('payment_requests', [
get_payment_request(),
get_payment_request_without_bn()
Expand Down
30 changes: 27 additions & 3 deletions pay-api/tests/unit/services/test_payment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
Test-Suite to ensure that the FeeSchedule Service is working as expected.
"""

from unittest.mock import patch
from unittest.mock import Mock, patch

import pytest
from requests import Response
from requests.exceptions import ConnectionError, ConnectTimeout, HTTPError

from pay_api.exceptions import BusinessException, ServiceUnavailableException
from pay_api.models import FeeSchedule, Invoice, Payment, PaymentAccount
from pay_api.services import CFSService
from pay_api.services.payment_service import PaymentService
from pay_api.utils.enums import InvoiceStatus, PaymentMethod, PaymentStatus
from tests.utilities.base_test import (
factory_invoice, factory_invoice_reference, factory_payment, factory_payment_account, factory_payment_line_item,
factory_payment_transaction, get_auth_basic_user, get_auth_premium_user, get_payment_request,
factory_payment_transaction, factory_routing_slip, get_auth_basic_user, get_auth_premium_user, get_payment_request,
get_payment_request_with_payment_method, get_payment_request_with_service_fees, get_zero_dollar_payment_request)


Expand Down Expand Up @@ -123,6 +124,29 @@ def test_create_zero_dollar_payment_record(session, public_user_mock):
assert payment_response.get('status_code') == 'COMPLETED'


def test_create_payment_record_with_rs(session, public_user_mock):
"""Assert that the payment records are created and completed."""
payment_account = factory_payment_account()
payment_account.save()
rs = factory_routing_slip(payment_account_id=payment_account.id, total=1000, remaining_amount=1000)
rs.save()
cfs_response = Mock(spec=Response)
cfs_response.json.return_value = {'invoice_number': 'abcde', }
cfs_response.status_code = 200

request = get_payment_request()
request['accountInfo'] = {'routingSlip': rs.number}
with patch.object(CFSService, 'create_account_invoice', return_value=cfs_response) as mock_post:
PaymentService.create_invoice(request, get_auth_basic_user())
mock_post.assert_called()

request = get_zero_dollar_payment_request()
request['accountInfo'] = {'routingSlip': rs.number}
with patch.object(CFSService, 'create_account_invoice', return_value=cfs_response) as mock_post:
PaymentService.create_invoice(request, get_auth_basic_user())
mock_post.assert_not_called()


def test_delete_payment(session, auth_mock, public_user_mock):
"""Assert that the payment records are soft deleted."""
payment_account = factory_payment_account()
Expand Down

0 comments on commit 7c56699

Please sign in to comment.