Skip to content

feat: Add PaymentHistoryEntry model and get_payment_history method - #20

Merged
danieyal merged 3 commits into
masterfrom
danieyal/04072026-1
Jul 4, 2026
Merged

feat: Add PaymentHistoryEntry model and get_payment_history method#20
danieyal merged 3 commits into
masterfrom
danieyal/04072026-1

Conversation

@danieyal

@danieyal danieyal commented Jul 4, 2026

Copy link
Copy Markdown
Owner

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 PaymentHistoryEntry model, updating the client to retrieve payment history, and enhancing date parsing to handle Microsoft JSON date formats.

Payment history support

  • Added a new PaymentHistoryEntry model to represent entries from the GetAccountBillPayHistoryV4 endpoint, with parsing and validation for all relevant fields.
  • Implemented the get_payment_history method in client.py to fetch and return payment and bill history entries using the new model.

Date parsing improvements

  • Enhanced the parse_api_date function to support Microsoft JSON date formats (e.g., /Date(1782921600000)/), ensuring compatibility with all API date representations. [1] [2]

Imports and exports

  • Updated imports and __all__ in __init__.py and client.py to include PaymentHistoryEntry. [1] [2] [3]

Documentation and clarification

  • Clarified the docstring for BillHistoryEntry to specify that it represents bills issued, not payments.

Copilot AI review requested due to automatic review settings July 4, 2026 04:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_date to handle Microsoft JSON /Date(ms)/ date formats in addition to existing date formats.
  • Added a PaymentHistoryEntry Pydantic model for GetAccountBillPayHistoryV4 responses.
  • Implemented MyTNBClient.get_payment_history and exported PaymentHistoryEntry from 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 thread src/mytnb/models.py
Comment thread src/mytnb/client/client.py
Comment thread src/mytnb/models.py
Comment thread src/mytnb/client/client.py
Copilot AI review requested due to automatic review settings July 4, 2026 04:22
@danieyal
danieyal merged commit 18589a3 into master Jul 4, 2026
7 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread src/mytnb/models.py
Comment on lines +15 to +16
# Microsoft JSON date format: /Date(1782921600000)/
_MS_DATE_RE = re.compile(r"/Date\((\d+)\)/")
Comment thread src/mytnb/models.py
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 thread src/mytnb/models.py
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(),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants