Metadata-Version: 2.4
Name: transfi-sdk
Version: 0.1.0
Summary: Python SDK for the TransFi Payment API
License: MIT
Keywords: transfi,payments,sdk,api
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: httpx>=0.27.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-httpx>=0.30; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: ruff; extra == "dev"

# python-sdk

Python SDK for the [TransFi](https://checkout-dashboard.transfi.com) Payment API.

## Installation

```bash
pip install transfi-sdk
```

## Quick start

```python
from transfi import TransFiPaymentAPI, TransFiError
from transfi.types import PaymentInvoiceRequest, Individual, ProductDetails

api = TransFiPaymentAPI(
    public_key="YOUR_PUBLIC_KEY",
    secret_key="YOUR_SECRET_KEY",
)

request = PaymentInvoiceRequest(
    payment_link_id="LINK_ID",
    amount="100",
    currency="USD",
    product_details=ProductDetails(
        name="Premium Plan",
        description="Monthly subscription",
    ),
    individual=Individual(
        first_name="John",
        last_name="Doe",
        email="john@example.com",
        phone="1234567890",
        phone_code="+1",
        country="US",
    ),
    success_redirect_url="https://example.com/success",
    failure_redirect_url="https://example.com/failure",
    customer_order_id="order-001",
)

try:
    payment_url = api.create_payment_invoice(request)
    print("Checkout URL:", payment_url)
except TransFiError as e:
    print("API Error   :", e)
    print("Status Code :", e.status_code)
    print("Response    :", e.response_data)
```

You can also pass a plain `dict` instead of the dataclass if you prefer (keys match the JSON API: camelCase):

```python
payment_url = api.create_payment_invoice({
    "paymentLinkId": "LINK_ID",
    "amount": "100",
    "currency": "USD",
    "productDetails": {
        "name": "Premium Plan",
        "description": "Monthly subscription",
    },
    "individual": {
        "firstName": "John",
        "lastName": "Doe",
        "email": "john@example.com",
        "phone": "1234567890",
        "phoneCode": "+1",
        "country": "US",
    },
    "successRedirectUrl": "https://example.com/success",
    "failureRedirectUrl": "https://example.com/failure",
    "customerOrderId": "order-001",
})
```

## Context manager

```python
with TransFiPaymentAPI(public_key="...", secret_key="...") as api:
    url = api.create_payment_invoice(request)
```

## Types reference

| Python class | Fields |
|---|---|
| `PaymentInvoiceRequest` | `payment_link_id`, `amount`, `currency`, `success_redirect_url`, `failure_redirect_url`, `product_details?`, `individual?`, `customer_order_id?` |
| `ProductDetails` | `name`, `description?`, `image_url?` |
| `Individual` | `first_name`, `last_name`, `email`, `phone?`, `phone_code?`, `country?`, `address?` |
| `Address` | `city?`, `state?`, `street?`, `postal_code?` |
