Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Kulsekar4 committed Nov 21, 2024
1 parent 29553eb commit 6256308
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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)

0 comments on commit 6256308

Please sign in to comment.