Metadata-Version: 2.4
Name: triangle-api
Version: 0.1.4
Summary: Unofficial Python wrapper for Canadian Tire Triangle Mastercard API
Home-page: https://github.com/diogobas/triangle-api
Author: Diogo Bastos
Author-email: seu-email@exemplo.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: playwright>=1.40.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# Triangle Mastercard API (Unofficial) 🇨🇦

[![Python Version](https://img.shields.io/badge/python-3.8%2B-blue)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/diogobas/triangle-api/graphs/commit-activity)

A Python wrapper for the private **Triangle Mastercard (Canadian Tire Financial Services)** API.

This project reverse engineers the official web portal to extract balance, limit, and transaction information, allowing you to integrate your financial data into your own apps, bots, or spreadsheets.

---

## ⚠️ Legal Notice (Disclaimer)

**This project is not affiliated with, maintained, authorized, endorsed, or sponsored by Canadian Tire Financial Services (CTFS) or any of its affiliates.**

This is independent software for educational and personal use. Using automation to access banking accounts may violate the institution's Terms of Service. Use responsibly and at your own risk.

---

## ✨ Features

- [x] **Automated Authentication**: Performs login with Playwright while handling bot protection.
- [x] **MFA Support**: Detects and prompts for SMS/Security code input in the terminal.
- [x] **Session Persistence**: Stores cookies locally to avoid frequent logins and reduce blocking risk.
- [x] **Account Summary**: Current balance, available credit, total limit, and due date.
- [ ] **Transaction History**: (In development)
- [ ] **Triangle Rewards**: Canadian Tire Money balance (In development)

---

## 🚀 Installation

1. Clone the repository:

```bash
git clone https://github.com/diogobas/triangle-api.git
cd triangle-api
```

2. Install dependencies: `pip install -r requirements.txt`

3. Install the browser required by Playwright: `playwright install chromium`

## 💻 Usage Example

```python
from triangle_api.client import TriangleClient
import os

# Using environment variables is recommended for security
USER = "your_email@example.com"
PASSWORD = "your_secret_password"

# Instantiate the client
client = TriangleClient(username=USER, password=PASSWORD)

# Log in (opens browser on first run, uses cookies on next runs)
# headless=False lets you watch browser activity
data = client.login(headless=True)

print(f"Current Balance: $ {client.get_balance()}")
print(f"Available Credit: $ {data.get('availableCreditAmt')}")
```

## 🔒 Security and Persistence

To avoid raising suspicion from multiple logins, this wrapper uses
Playwright's `storage_state` feature.

- After the first successful login, an `auth_state.json` file is created.
- On subsequent runs, the script tries to use these cookies to access the
  Dashboard directly.
- Important: Never commit `auth_state.json` to GitHub (it should already be in
  `.gitignore`).

## 🛠️ Development

If you want to contribute by mapping new endpoints (such as transactions or
offers), follow these steps:

1. Log in to the CTFS website with Inspect mode (F12) open.
2. Filter by XHR/Fetch calls.
3. Look for endpoints such as `retrieveTransactions` or `retrieveLoyalty`.
4. Map the response JSON in the `TriangleClient` class.
