-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2372, 23508 - redirect to direct pay, API and UI updates #282
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,18 +70,22 @@ def create_invoice(document_access_request: DocumentAccessRequest, user_jwt: Jwt | |
header, business_json) | ||
|
||
if payment_response.status_code in (HTTPStatus.OK, HTTPStatus.CREATED): | ||
payment_completion_date = datetime.utcnow() | ||
is_pad = payment_response.json().get('paymentMethod') == 'PAD' | ||
today_utc = datetime.utcnow() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, pycharm shows the same ! |
||
if is_pad: | ||
document_access_request.status = DocumentAccessRequest.Status.PAID | ||
document_access_request.payment_completion_date = today_utc | ||
else: | ||
document_access_request.status = DocumentAccessRequest.Status.CREATED | ||
|
||
pid = payment_response.json().get('id') | ||
document_access_request.payment_token = pid | ||
document_access_request.payment_status_code = payment_response.json().get('statusCode', '') | ||
document_access_request.payment_completion_date = payment_completion_date | ||
validity_in_days = current_app.config.get('DOCUMENT_REQUEST_VALIDITY_DURATION', 14) | ||
document_access_request.expiry_date = payment_completion_date + relativedelta(days=validity_in_days) | ||
document_access_request.status = DocumentAccessRequest.Status.PAID | ||
document_access_request.expiry_date = today_utc + relativedelta(days=validity_in_days) | ||
document_access_request.save() | ||
return {'isPaymentActionRequired': payment_response.json().get('isPaymentActionRequired', | ||
False)}, HTTPStatus.CREATED | ||
|
||
if payment_response.status_code == HTTPStatus.BAD_REQUEST: | ||
# Set payment error type used to retrieve error messages from pay-api | ||
error_type = payment_response.json().get('type') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,10 +37,6 @@ def validate_document_access_request(document_access_request_json: dict, account | |
if not account_org: | ||
validation_errors.append({'error': 'Invalid Account'}) | ||
|
||
if account_org.get('orgType') != 'PREMIUM': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woohoo! |
||
validation_errors.append({ | ||
'error': 'Document Access Request can be created only by a premium account user'}) | ||
|
||
documents = document_access_request_json.get('documentAccessRequest', {}).get('documents', []) | ||
if not documents: | ||
validation_errors.append({'error': 'Document list must contain atleast one document type'}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"_links": { | ||
"collection": "/api/v1/payment-requests?invoice_id=41861", | ||
"self": "/api/v1/payment-requests/41861" | ||
}, | ||
"businessIdentifier": "FM1000026", | ||
"corpTypeCode": "BUS", | ||
"createdBy": "BCSC/ZGCBNHM6U7FPRXI7AJT6KFF7GSKY43TA", | ||
"createdName": "BCREG2 Ayisha FIFTY", | ||
"createdOn": "2024-10-25T21:19:17+00:00", | ||
"details": [ | ||
{ | ||
"label": "Registration Number: ", | ||
"value": "FM1000026" | ||
} | ||
], | ||
"id": 41861, | ||
"isPaymentActionRequired": true, | ||
"lineItems": [ | ||
{ | ||
"description": "Business Summary", | ||
"filingFees": 7.0, | ||
"futureEffectiveFees": 0.0, | ||
"gst": 0.0, | ||
"id": 44464, | ||
"priorityFees": 0.0, | ||
"pst": 0.0, | ||
"quantity": 1, | ||
"serviceFees": 1.5, | ||
"statusCode": "ACTIVE", | ||
"total": 8.5, | ||
"waivedBy": null, | ||
"waivedFees": 0.0 | ||
} | ||
], | ||
"overdueDate": "2024-12-15T08:00:00+00:00", | ||
"paid": 0.0, | ||
"paymentAccount": { | ||
"accountId": "3137", | ||
"accountName": "Kial Dev 3 (BTR test account) - Public search access", | ||
"billable": true, | ||
"branchName": "Public search access" | ||
}, | ||
"paymentMethod": "DIRECT_PAY", | ||
"references": [ | ||
{ | ||
"createdOn": "2024-10-25T21:19:17+00:00", | ||
"id": 34456, | ||
"invoiceNumber": "REGUT00041861", | ||
"statusCode": "ACTIVE" | ||
} | ||
], | ||
"refund": 0.0, | ||
"serviceFees": 1.5, | ||
"statusCode": "CREATED", | ||
"total": 8.5 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"_links": { | ||
"collection": "/api/v1/payment-requests?invoice_id=41863", | ||
"self": "/api/v1/payment-requests/41863" | ||
}, | ||
"businessIdentifier": "FM1000026", | ||
"corpTypeCode": "BUS", | ||
"createdBy": "BCSC/ZGCBNHM6U7FPRXI7AJT6KFF7GSKY43TA", | ||
"createdName": "BCREG2 Ayisha FIFTY", | ||
"createdOn": "2024-10-25T21:22:37+00:00", | ||
"details": [ | ||
{ | ||
"label": "Registration Number: ", | ||
"value": "FM1000026" | ||
} | ||
], | ||
"id": 41863, | ||
"isPaymentActionRequired": false, | ||
"lineItems": [ | ||
{ | ||
"description": "Business Summary", | ||
"filingFees": 7.0, | ||
"futureEffectiveFees": 0.0, | ||
"gst": 0.0, | ||
"id": 44466, | ||
"priorityFees": 0.0, | ||
"pst": 0.0, | ||
"quantity": 1, | ||
"serviceFees": 1.5, | ||
"statusCode": "ACTIVE", | ||
"total": 7.0, | ||
"waivedBy": null, | ||
"waivedFees": 0.0 | ||
} | ||
], | ||
"overdueDate": "2024-12-15T08:00:00+00:00", | ||
"paid": 0.0, | ||
"paymentAccount": { | ||
"accountId": "3101", | ||
"accountName": "Kial Dev 2 (BTR test account)-Director search access", | ||
"billable": true, | ||
"branchName": "Director search access" | ||
}, | ||
"paymentMethod": "PAD", | ||
"refund": 0.0, | ||
"serviceFees": 1.5, | ||
"statusCode": "APPROVED", | ||
"total": 8.5 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,14 @@ | |
from datetime import datetime | ||
from http import HTTPStatus | ||
|
||
import pytest | ||
from flask import current_app, g | ||
|
||
from search_api.models import DocumentAccessRequest, User | ||
from search_api.request_handlers.document_access_request_handler import create_invoice, save_request | ||
|
||
|
||
DOCUMENT_ACCESS_REQUEST_TEMPLATE = { | ||
"documentAccessRequest":{ | ||
"documentAccessRequest": { | ||
"documents": [ | ||
{ | ||
"type": "BUSINESS_SUMMARY_FILING_HISTORY" | ||
|
@@ -33,9 +33,10 @@ | |
} | ||
} | ||
|
||
|
||
def test_save_request(client, session, jwt, mocker): | ||
"""Assert that request can be saved.""" | ||
g.jwt_oidc_token_info={} | ||
g.jwt_oidc_token_info = {} | ||
user = User(username='username', firstname='firstname', lastname='lastname', sub='sub', iss='iss', idp_userid='123') | ||
user.save() | ||
mocker.patch('search_api.models.User.get_or_create_user_by_jwt', return_value=user) | ||
|
@@ -45,7 +46,10 @@ def test_save_request(client, session, jwt, mocker): | |
assert document_access_request.submitter.firstname == user.firstname | ||
|
||
|
||
def test_create_invoice(client, session, jwt, mocker): | ||
@pytest.mark.parametrize('test_name,mock_response,is_payment_completion_date_expected', [ | ||
('test_pad_invoice', {'id': 123, 'paymentMethod': 'PAD'}, True), | ||
('test_pad_invoice', {'id': 123, 'paymentMethod': 'DIRECT_PAY'}, False)]) | ||
def test_create_invoice(client, session, jwt, mocker, test_name, mock_response, is_payment_completion_date_expected): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
"""Assert that access request is updated with payment details.""" | ||
document_access_request = DocumentAccessRequest( | ||
business_identifier='CP1234567', | ||
|
@@ -64,18 +68,22 @@ def test_create_invoice(client, session, jwt, mocker): | |
} | ||
} | ||
|
||
mock_response = MockResponse({'id': 123},HTTPStatus.CREATED) | ||
mock_payment_response = MockResponse(mock_response, HTTPStatus.CREATED) | ||
mocker.patch('search_api.request_handlers.document_access_request_handler.create_payment', | ||
return_value=mock_response) | ||
return_value=mock_payment_response) | ||
mocker.patch('search_api.request_handlers.document_access_request_handler.get_role', | ||
return_value='basic') | ||
|
||
business_json = {'identifier': 'BC1234567', 'legalType': 'BC', 'legalName': 'Test - 1234567'} | ||
create_invoice(document_access_request, jwt, request_json, business_json) | ||
|
||
document_access_request = DocumentAccessRequest.find_by_id(document_access_request.id) | ||
|
||
assert document_access_request.payment_token | ||
assert document_access_request.payment_completion_date | ||
if is_payment_completion_date_expected: | ||
assert document_access_request.payment_completion_date | ||
else: | ||
assert not document_access_request.payment_completion_date | ||
assert document_access_request.expiry_date | ||
|
||
|
||
|
@@ -95,7 +103,7 @@ def test_create_invoice_failure(client, session, jwt, mocker): | |
'documentAccessRequest': document_access_request | ||
} | ||
|
||
mock_response = MockResponse({'type': 'BAD_REQUEST'},HTTPStatus.BAD_REQUEST) | ||
mock_response = MockResponse({'type': 'BAD_REQUEST'}, HTTPStatus.BAD_REQUEST) | ||
mocker.patch('search_api.request_handlers.document_access_request_handler.create_payment', | ||
return_value=mock_response) | ||
mocker.patch('search_api.request_handlers.document_access_request_handler.get_role', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum DocumentAccessRequestPaymentStatus { | ||
CREATED = 'CREATED', | ||
PAID = 'PAID' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you just add a comment here that this is the 'invoice id' from the pay db