A modern Python library for the ATH Móvil payment API
Project description
ATH Móvil Unofficial Python Library
A modern, type-safe Python library for the ATH Móvil payment platform.
Note: This is an unofficial, third-party library and is not affiliated with, endorsed by, or supported by ATH Móvil or EVERTEC. For official API documentation, see the ATH Móvil Payment Button API.
Developed with AI assistance using Claude Code (claude.ai)
Features
- Full ATH Móvil Payment Button API support
- Webhook support for real-time transaction notifications
- Simple synchronous client
- Strict type safety with mypy
- Pydantic data validation
- Automatic retries with exponential backoff
- Comprehensive error handling
Installation
pip install athm
Or with uv:
uv add athm
Quick Start
from athm import ATHMovilClient
# Note: private token is only required for processing refunds
client = ATHMovilClient(public_token="your_public_token", private_token="your_private_token")
payment = client.create_payment(
total="5.00",
phone_number="7875551234",
metadata1="Order #123",
items=[
{
"name": "Product Name",
"description": "Product Description",
"quantity": "1",
"price": "5.00",
}
],
)
# Wait for customer confirmation
client.wait_for_confirmation(payment.data.ecommerce_id)
# Authorize payment
payment_result = client.authorize_payment(payment.data.ecommerce_id)
print(f"Payment completed: {payment_result.data.reference_number}")
# Refund the payment (requires a client initialized with private token)
refund_result = client.refund_payment(
reference_number=payment_result.data.reference_number,
amount="5.00",
)
Configuration
Get your credentials from your ATH Business account settings.
client = ATHMovilClient(
public_token=os.getenv("ATHM_PUBLIC_TOKEN"),
private_token=os.getenv("ATHM_PRIVATE_TOKEN"), # Required for refunds
)
Supported Operations
- Create payments
- Check payment status
- Authorize confirmed payments
- Cancel payments
- Process full and partial refunds
- Update phone numbers
- Subscribe to webhook notifications
- Parse and validate webhook payloads
Error Handling
from athm.exceptions import ValidationError, ATHMovilError
try:
payment = client.create_payment(
total="5.00",
phone_number="7875551234", # Customer's phone number with ATH Móvil account
items=[{"name": "Test", "description": "Test", "quantity": "1", "price": "5.00"}],
)
except ValidationError as e:
print(f"Invalid data: {e}")
except ATHMovilError as e:
print(f"Error: {e}")
Context Manager
with ATHMovilClient(public_token="token") as client:
payment = client.create_payment(
total="5.00",
phone_number="7875551234", # Customer's phone number with ATH Móvil account
items=[{"name": "Test", "description": "Test", "quantity": "1", "price": "5.00"}],
)
# Client is automatically closed when exiting the context
Webhooks
Subscribe to real-time transaction notifications:
# Subscribe to webhooks (requires private token)
client = ATHMovilClient(
public_token="your_public_token",
private_token="your_private_token",
)
client.subscribe_webhook(
listener_url="https://yoursite.com/webhook",
payment_received_event=True,
refund_sent_event=True,
ecommerce_payment_received_event=True,
ecommerce_payment_cancelled_event=True,
ecommerce_payment_expired_event=True,
)
Parse incoming webhook payloads in your endpoint:
from athm.webhooks import parse_webhook, WebhookEventType, WebhookStatus
@app.post("/webhook")
async def handle_webhook(request: Request):
payload = await request.json()
event = parse_webhook(payload)
if event.status == WebhookStatus.COMPLETED:
if event.transaction_type == WebhookEventType.PAYMENT:
# Standard payment completed
print(f"Payment received: {event.reference_number} for ${event.total}")
elif event.transaction_type == WebhookEventType.ECOMMERCE:
# eCommerce payment completed
print(f"Order {event.ecommerce_id} completed: ${event.total}")
elif event.transaction_type == WebhookEventType.REFUND:
# Refund processed
print(f"Refund sent: {event.reference_number}")
elif event.status == WebhookStatus.CANCELLED:
print(f"Transaction cancelled: {event.ecommerce_id}")
elif event.status == WebhookStatus.EXPIRED:
print(f"Transaction expired: {event.ecommerce_id}")
return {"status": "ok"}
Documentation
Development
git clone https://github.com/django-athm/athm-python.git
cd athm-python
uv sync --all-extras --dev
uv run pytest
Code Quality
uv run ruff format
uv run ruff check
uv run mypy athm
Requirements
- Python 3.10+
- httpx
- pydantic
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file athm-0.4.1.tar.gz.
File metadata
- Download URL: athm-0.4.1.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81ee7273c3cf279e04e4b70ff0eb172dd83bf9cb25d25e7645914fb1f68c3160
|
|
| MD5 |
72512d1a4de06e17a58162099951d024
|
|
| BLAKE2b-256 |
6e6de87e8f0072bb072f49f20a385e03ee34608cbc86d97c0792be4d44e0a452
|
Provenance
The following attestation bundles were made for athm-0.4.1.tar.gz:
Publisher:
release.yml on django-athm/athm-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
athm-0.4.1.tar.gz -
Subject digest:
81ee7273c3cf279e04e4b70ff0eb172dd83bf9cb25d25e7645914fb1f68c3160 - Sigstore transparency entry: 757952105
- Sigstore integration time:
-
Permalink:
django-athm/athm-python@e111d11f41a342d1e8139680e213446c1d5a256a -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/django-athm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e111d11f41a342d1e8139680e213446c1d5a256a -
Trigger Event:
push
-
Statement type:
File details
Details for the file athm-0.4.1-py3-none-any.whl.
File metadata
- Download URL: athm-0.4.1-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f338cef2efb737270ad5bb2be8a1a4d2d7542cf2e1514c848f961ed7b3b94e5f
|
|
| MD5 |
72416d200dbd9e673c0eecd8065a7c6d
|
|
| BLAKE2b-256 |
255d78595e98ae77ed111b1fc1e2de40946642e249e3b59485c216d25f30e38c
|
Provenance
The following attestation bundles were made for athm-0.4.1-py3-none-any.whl:
Publisher:
release.yml on django-athm/athm-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
athm-0.4.1-py3-none-any.whl -
Subject digest:
f338cef2efb737270ad5bb2be8a1a4d2d7542cf2e1514c848f961ed7b3b94e5f - Sigstore transparency entry: 757952107
- Sigstore integration time:
-
Permalink:
django-athm/athm-python@e111d11f41a342d1e8139680e213446c1d5a256a -
Branch / Tag:
refs/tags/v0.4.1 - Owner: https://github.com/django-athm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e111d11f41a342d1e8139680e213446c1d5a256a -
Trigger Event:
push
-
Statement type: