Skip to main content

OnePay Python SDK

The official Python SDK for the OnePay payment gateway. Built for Python backend developers with full type safety, sync and async support, and a clean Pythonic API.

PyPI version Python versions License: MIT

Installation

# pip
pip install onepay

# uv
uv add onepay

# conda (after conda-forge feedstock is available)
conda install -c conda-forge onepay

Quick Start

from onepay import OnePay

client = OnePay(
    app_id="YOUR_APP_ID",
    hash_salt="YOUR_HASH_SALT",
    app_token="YOUR_APP_TOKEN",
)

# Create a checkout session
result = client.checkout.create(
    amount=1000.00,
    currency="LKR",
    reference="ORDER-123",
    customer_first_name="Amila",
    customer_last_name="Perera",
    customer_phone_number="+94771234567",
    customer_email="amila@store.lk",
    transaction_redirect_url="https://store.lk/thank-you",
)

# Redirect your customer to this URL
print(result.redirect_url)

# Store this for later verification
print(result.ipg_transaction_id)

Features

  • Checkout & Payments : Create transactions, verify payment status
  • Items Management : CRUD for line items attached to transactions
  • Payment Links : Generate shareable payment URLs
  • Card on File : Customer management, card tokenization, automated charging
  • Refunds : Full and partial refund support
  • Payouts : Transaction lookup and paginated settlement reports
  • Webhooks : Framework-agnostic callback parsing
  • Subscriptions : Experimental subscription billing support
  • Sync & Async : Both OnePay and AsyncOnePay clients
  • Type Safe : Full type annotations, Pydantic models, PEP 561 compliant

Authentication

The SDK supports environment variables as fallback for credentials:

export ONEPAY_APP_ID="your_app_id"
export ONEPAY_HASH_SALT="your_hash_salt"
export ONEPAY_APP_TOKEN="your_app_token"
export ONEPAY_API_KEY="your_api_key"           # For payment links
export ONEPAY_ACCESS_TOKEN="your_access_token" # For customers/cards
from onepay import OnePay

# Credentials auto-loaded from environment
client = OnePay()

Usage Examples

Verify Transaction Status

status = client.transactions.get_status(onepay_transaction_id="WQBV118E584C83CBA50C6")
if status.data and status.data.status:
    print(f"Payment confirmed: {status.data.amount} {status.data.currency}")

Item Management

# Create an item
item = client.items.create(
    name="Pro Plan",
    description="Monthly subscription",
    price=2500.00,
    currency="LKR",
)
print(item.item_id)

# List all items
items = client.items.list()
link = client.payment_links.create(
    amount="5000.00",
    currency="LKR",
    reference_number="INV-001",
    customer_first_name="Kasun",
    customer_last_name="Silva",
    customer_email="kasun@example.com",
    customer_phone_number="+94771234567",
    description="Invoice #001",
    expiration_date="2026-12-31",
)
print(link.data.link_url)  # Share this URL with your customer

Card on File (Automated Charging)

# Create a customer and get card-entry URL
customer = client.customers.create(
    first_name="Nimal",
    last_name="Perera",
    email="nimal@example.com",
    phone_number="+94771234567",
    address="123 Colombo Rd",
    redirect_url="https://store.lk/card-saved",
)
# Redirect customer to: customer.data.redirect_url

# After customer saves their card, charge it
charge = client.cards.charge(
    customer_id="cus_907fa39a",
    token_id="tok_12345678",
    amount="1000.00",
    currency="LKR",
)

Refunds

# Full refund
refund = client.refunds.create(
    onepay_transaction_id="ONP2026072800001",
    refund_reason="REQUESTED_BY_CUSTOMER",
    refund_note="Customer requested refund",
)

# Partial refund
refund = client.refunds.create(
    onepay_transaction_id="ONP2026072800001",
    refund_reason="OTHER",
    is_partially=True,
    amount=500.00,
)

Payout Reconciliation

# Single transaction lookup
payout = client.payouts.get_transaction(onepay_transaction_id="WQBV118E584C83CBA50C6")
print(f"Settled: LKR {payout.data.settlement_amount}")

# Iterate all transactions in a date range (auto-paginated)
for txn in client.payouts.list_transactions(
    start_date="2026-04-01",
    end_date="2026-04-28",
):
    print(f"{txn.onepay_transaction_id}: {txn.settlement_amount}")

Webhook Handling

from onepay import Webhook

# In your webhook endpoint (framework-agnostic)
event = Webhook.parse(request.body)
if event.is_success:
    print(f"Payment {event.transaction_id} succeeded!")

Async Usage

from onepay import AsyncOnePay


async def process_payment():
    async with AsyncOnePay(
        app_id="...",
        hash_salt="...",
        app_token="...",
    ) as client:
        # Create a checkout session
        result = await client.checkout.create(
            amount=1000.00,
            currency="LKR",
            reference="ORDER-123",
            customer_first_name="Amila",
            customer_last_name="Perera",
            customer_phone_number="+94771234567",
            customer_email="amila@store.lk",
            transaction_redirect_url="https://store.lk/thank-you",
        )

        # Async iterator for paginated endpoints
        async for txn in client.payouts.list_transactions(
            start_date="2026-04-01",
            end_date="2026-04-28",
        ):
            print(f"{txn.onepay_transaction_id}: {txn.settlement_amount}")

        return result.redirect_url

Error Handling

from onepay import OnePay, OnePayError, AuthenticationError, RateLimitError

client = OnePay(...)

try:
    result = client.checkout.create(...)
except AuthenticationError:
    print("Check your credentials")
except RateLimitError as e:
    print(f"Rate limited. Retry after: {e.retry_after}s")
except OnePayError as e:
    print(f"OnePay error: {e.message}")

Configuration

Parameter Type Default Description
app_id str "" Your OnePay App ID
hash_salt str "" Your hash salt (secret)
app_token str "" App token for Items, Refunds, Payouts
api_key str "" Company API key for Payment Links
access_token str "" Access token for Customers/Cards
base_url str "https://api.onepay.lk" API base URL
timeout float 30.0 Request timeout in seconds
max_retries int 3 Max retry attempts for 429/5xx errors
debug bool False Enable debug logging

Development

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Type checking
mypy src/onepay --strict

# Linting
ruff check src/ tests/

License

MIT : see LICENSE.

Metadata

Release files for onepay 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for onepay 0.1.2
File Size Uploaded Provenance Actions
onepay-0.1.2.tar.gz 227.4 kB Without provenance Details for onepay-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for onepay 0.1.2
File Interpreter ABI Platform Actions
onepay-0.1.2-py3-none-any.whl Python 3 none any Details for onepay-0.1.2-py3-none-any.whl

Total release size: 262.0 kB

Release files / onepay-0.1.2.tar.gz

Download URL onepay-0.1.2.tar.gz
Size 227.4 kB
Tags Source
SHA-256 checksum
How to use checksums
23d87f43dde87110e756c1257c05954b2159c025c0e7cf7d44a889ee4f6e3e26
BLAKE2b-256 checksum
How to use checksums
dbc57f6b64912ac7a82fa262eeb3c7cdc41eaebff47e07f7dc5c6b0e0a4c9587
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / onepay-0.1.2-py3-none-any.whl

Download URL onepay-0.1.2-py3-none-any.whl
Size 34.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0cf194c724b8fc5b6ae67047b804387c4da98c2974afaed4cbee3c7196a40f15
BLAKE2b-256 checksum
How to use checksums
b02369ee144185af6bf351d4cd9fd220a47a08efb5ee9fe9bfa75a2cec19bb98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for onepay 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page