Skip to content
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

FYLE-employee_id_fix_for_mastercard #28

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [0.17.0]

### Changed

- Updated CDF parser to use employee id when masking account number

## [0.16.0]

### Changed
Expand Down
14 changes: 9 additions & 5 deletions card_data_parsers/parsers/cdf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __get_amount(amount, exponent):
return amount

@staticmethod
def __extract_transaction_fields(root: ElementTree, account_number, nickname, default_values):
def __extract_transaction_fields(root: ElementTree, account_number, nickname, default_values, use_employee_id_mask_for_account_number):
txn = CDFTransaction(**default_values)

txn.account_number = account_number
Expand Down Expand Up @@ -127,6 +127,10 @@ def __extract_transaction_fields(root: ElementTree, account_number, nickname, de
ftrxn, 'MasterCardFinancialTransactionId').text
txn.external_id = generate_external_id(external_id)

if use_employee_id_mask_for_account_number:
employee_id = CDFParser.__get_element_by_tag(
ftrxn, 'EmployeeId').text
txn.account_number = str(employee_id) + str(txn.account_number)
return txn

@staticmethod
Expand Down Expand Up @@ -260,7 +264,7 @@ def __extract_nickname(account):
return nickname

@staticmethod
def __extract_transactions(root, account_number_mask_begin, account_number_mask_end, default_values, mandatory_fields):
def __extract_transactions(root, account_number_mask_begin, account_number_mask_end, default_values, mandatory_fields, use_employee_id_mask_for_account_number):
txns = []
issuer_entity = CDFParser.__get_element_by_tag(root, 'IssuerEntity')
if issuer_entity is None:
Expand Down Expand Up @@ -289,7 +293,7 @@ def __extract_transactions(root, account_number_mask_begin, account_number_mask_

for transaction in financial_transaction_entities:
txn = CDFParser.__extract_transaction_fields(
transaction, account_number, nickname, default_values)
transaction, account_number, nickname, default_values, use_employee_id_mask_for_account_number)

lodging_transaction_entities = CDFParser.__get_elements_by_tag(
transaction, 'LodgingSummaryAddendumEntity')
Expand Down Expand Up @@ -318,7 +322,7 @@ def __extract_transactions(root, account_number_mask_begin, account_number_mask_
return txns

@staticmethod
def parse(file_obj, account_number_mask_begin=None, account_number_mask_end=None, default_values={}, mandatory_fields=[]) -> List[CDFTransaction]:
def parse(file_obj, account_number_mask_begin=None, account_number_mask_end=None, default_values={}, mandatory_fields=[], use_employee_id_mask_for_account_number=False) -> List[CDFTransaction]:
root: ElementTree = ET.parse(file_obj).getroot()
if root is None:
return None
Expand All @@ -327,4 +331,4 @@ def parse(file_obj, account_number_mask_begin=None, account_number_mask_end=None
return None

return CDFParser.__extract_transactions(
root, account_number_mask_begin, account_number_mask_end, default_values, mandatory_fields)
root, account_number_mask_begin, account_number_mask_end, default_values, mandatory_fields, use_employee_id_mask_for_account_number)
Loading