Skip to main content

A Python library for seamlessly integrating the SecurePay payment platform API.

Project description

securepay-api

A Python library for seamlessly integrating the SecurePay payment platform API.

Gives Python developers a clean, typed, fully documented interface - no need to read raw API docs or wire up HTTP calls manually.


Features

  • ✅ Fully typed with Pydantic v2 models — request validation + IDE autocomplete
  • httpx-powered HTTP with automatic auth header injection on every request
  • ✅ UUID-based X-Request-ID tracing per request
  • ✅ Automatic retry with exponential back-off via tenacity
  • ✅ Structured logging (staging only, auto-disabled in production)
  • SecurePayException hierarchy for clean, specific error handling
  • ✅ Context manager support (with SecurePayApi(...) as client:)
  • ✅ Staging and production environment presets

Installation

pip install securepay-api

Quick Start

from securepay import SecurePayApi, SecurePayConfig

client = SecurePayApi(
    api_key="SP-PK-xxxx",
    config=SecurePayConfig.staging(enable_logging=True),  # Development
    # config=SecurePayConfig.production(),               # Production
)

Direct Debit — Full Example

from datetime import date
from securepay import (
    SecurePayApi, SecurePayConfig,
    BankAccount, CreateMandateRequest, DebitFrequency,
    InitiateDebitRequest, MandateStatus, UpdateMandateRequest,
)

client = SecurePayApi(api_key="SP-PK-xxxx", config=SecurePayConfig.staging())

# POST — Create a mandate
mandate = client.direct_debit.create_mandate(
    CreateMandateRequest(
        customer_name="Ada Obi",
        customer_email="ada@example.com",
        customer_phone="+2348012345678",
        bank_account=BankAccount(
            account_number="0123456789",
            bank_code="058",
            account_name="Ada Obi",
        ),
        amount=5000.00,
        frequency=DebitFrequency.MONTHLY,
        start_date=date(2025, 8, 1),
    )
)
print(mandate.mandate_id)  # mnd_abc123

# GET — Fetch mandate
fetched = client.direct_debit.get_mandate(mandate.mandate_id)

# GET — List mandates
mandates = client.direct_debit.list_mandates(page=1, page_size=20)

# PUT — Update mandate
updated = client.direct_debit.update_mandate(
    mandate.mandate_id,
    UpdateMandateRequest(amount=7500.00),
)

# PATCH — Suspend mandate
client.direct_debit.patch_mandate_status(
    mandate.mandate_id,
    status=MandateStatus.SUSPENDED,
    reason="Customer requested pause.",
)

# POST — Initiate a collection
collection = client.direct_debit.initiate_collection(
    mandate.mandate_id,
    InitiateDebitRequest(amount=5000.00, narration="August subscription"),
)

# DELETE — Cancel mandate
client.direct_debit.cancel_mandate(mandate.mandate_id)

Error Handling

from securepay import (
    SecurePayException,
    SecurePayUnauthorizedError,
    SecurePayValidationError,
    SecurePayNotFoundError,
    SecurePayNetworkError,
)

try:
    mandate = client.direct_debit.get_mandate("mnd_xyz")
except SecurePayUnauthorizedError:
    print("Invalid API key")
except SecurePayNotFoundError:
    print("Mandate not found")
except SecurePayValidationError as e:
    print(f"Bad request: {e.message}")
except SecurePayNetworkError:
    print("No internet connection")
except SecurePayException as e:
    print(f"Unexpected error: {e}")

Configuration

Option Type Default Description
base_url str Staging URL API base URL
timeout float 30.0 Request timeout in seconds
max_retries int 3 Max retry attempts
enable_logging bool False Log requests/responses
enable_retry bool True Auto-retry on transient errors

API Coverage

Section Status
Direct Debit
Transfers
Checkout
Key Management

Development

# Clone and set up
git clone https://github.com/seniorman-dev/securepay_python
cd securepay_python
python -m venv .venv
source .venv/bin/activate       # Windows: .venv\Scripts\activate
pip install -e ".[dev]"

# Run tests
pytest

# Lint
ruff check .

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

securepay_api-0.0.1.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

securepay_api-0.0.1-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file securepay_api-0.0.1.tar.gz.

File metadata

  • Download URL: securepay_api-0.0.1.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for securepay_api-0.0.1.tar.gz
Algorithm Hash digest
SHA256 acb8d1f2a47f345d85b55c2d609af74d4c9306816468bbf68a78c317929bf1bc
MD5 0586e556a24f04584319a372da4cf610
BLAKE2b-256 678cd7b9e78b6724f97a780cd08affde39212841cd753d4d30166846594237bf

See more details on using hashes here.

File details

Details for the file securepay_api-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: securepay_api-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for securepay_api-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6e6655c92f42e03db1d13f7610be65554baf5be040c24b0c0c260cadb01e3014
MD5 1358460ece7530d847da722a438c2f60
BLAKE2b-256 7ebcb004cb50288141cffd5bc0d4a0d231851e3b4c69c58bc6adfa5c6c94d334

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page