feat: Add PaymentHistoryEntry model and get_payment_history method - #20
Merged
Conversation
… retrieve payment history
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class support for retrieving and parsing payment history entries from the myTNB legacy API, complementing the existing bill-history functionality. This introduces a new typed model for the mixed bill/payment history endpoint and broadens date parsing to support Microsoft JSON date strings returned by some API fields.
Changes:
- Enhanced
parse_api_dateto handle Microsoft JSON/Date(ms)/date formats in addition to existing date formats. - Added a
PaymentHistoryEntryPydantic model forGetAccountBillPayHistoryV4responses. - Implemented
MyTNBClient.get_payment_historyand exportedPaymentHistoryEntryfrom the package.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/mytnb/models.py |
Adds Microsoft JSON date parsing support and introduces PaymentHistoryEntry for payment/bill history payloads. |
src/mytnb/client/client.py |
Adds get_payment_history to call GetAccountBillPayHistoryV4 and parse results into PaymentHistoryEntry models. |
src/mytnb/__init__.py |
Exports PaymentHistoryEntry at the package top level. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+15
to
+16
| # Microsoft JSON date format: /Date(1782921600000)/ | ||
| _MS_DATE_RE = re.compile(r"/Date\((\d+)\)/") |
Comment on lines
+34
to
+39
| try: | ||
| return datetime.fromtimestamp( | ||
| int(ms_match.group(1)) / 1000, tz=timezone.utc | ||
| ).date() | ||
| except (ValueError, OSError): | ||
| return None |
Comment on lines
+479
to
+505
| class PaymentHistoryEntry(BaseModel): | ||
| """A single payment-or-bill entry from GetAccountBillPayHistoryV4. | ||
|
|
||
| Raw shape: | ||
| {"BillOrPaymentDate":"15/01/2026","HistoryType":"Payment","Amount":"100.50",…} | ||
| """ | ||
|
|
||
| date: Optional[date_cls] = Field(default=None, alias="BillOrPaymentDate") | ||
| history_type: str = Field(default="", alias="HistoryType") | ||
| date_and_history_type: str = Field(default="", alias="DateAndHistoryType") | ||
| amount: Optional[float] = Field(default=None, alias="Amount") | ||
| reference_number: str = Field(default="", alias="DetailedInfoNumber") | ||
| paid_via: str = Field(default="", alias="PaidVia") | ||
| history_type_text: str = Field(default="", alias="HistoryTypeText") | ||
| is_payment_pending: bool = Field(default=False, alias="IsPaymentPending") | ||
|
|
||
| model_config = {"populate_by_name": True, "extra": "ignore"} | ||
|
|
||
| @field_validator("date", mode="before") | ||
| @classmethod | ||
| def _parse_date(cls, v: Any) -> Optional[date_cls]: | ||
| return parse_api_date(v) | ||
|
|
||
| @field_validator("amount", mode="before") | ||
| @classmethod | ||
| def _parse_amount(cls, v: Any) -> Optional[float]: | ||
| return _parse_optional_float(v) |
| is_owner: bool = True, | ||
| is_owner: bool | None = None, | ||
| ) -> list[BillHistoryEntry]: | ||
| """Get bill payment history as typed models (most recent first).""" |
Comment on lines
+323
to
+328
| data = { | ||
| "contractAccount": acc_no, | ||
| "isOwnedAccount": owner, | ||
| "accountType": account_type, | ||
| "usrInf": self._legacy_transport.base_user_info(), | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for retrieving and parsing payment history entries from the myTNB API, in addition to the existing bill history functionality. The main changes include introducing a new
PaymentHistoryEntrymodel, updating the client to retrieve payment history, and enhancing date parsing to handle Microsoft JSON date formats.Payment history support
PaymentHistoryEntrymodel to represent entries from theGetAccountBillPayHistoryV4endpoint, with parsing and validation for all relevant fields.get_payment_historymethod inclient.pyto fetch and return payment and bill history entries using the new model.Date parsing improvements
parse_api_datefunction to support Microsoft JSON date formats (e.g.,/Date(1782921600000)/), ensuring compatibility with all API date representations. [1] [2]Imports and exports
__all__in__init__.pyandclient.pyto includePaymentHistoryEntry. [1] [2] [3]Documentation and clarification
BillHistoryEntryto specify that it represents bills issued, not payments.