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-Library.git
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.2.tar.gz (22.0 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.2-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: securepay_api-0.0.2.tar.gz
  • Upload date:
  • Size: 22.0 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.2.tar.gz
Algorithm Hash digest
SHA256 6685dc01db2bd918e3bde28e99d443142a78b94b77ad9f6a6a2683ce91e1d57a
MD5 55b2139b7ab9cac264dc1dec96c76c2c
BLAKE2b-256 a4ec1243180c11328e1995d115fde572efae1a396477da971099a7ed97c08431

See more details on using hashes here.

File details

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

File metadata

  • Download URL: securepay_api-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c5671039e1b99d0fd052e6d9620567c94e67f073ada29b5784ab4735b78291dc
MD5 fb385108fa7347ada4e2fbbe90def561
BLAKE2b-256 6c1e78ccc8cab757b604bf939e102c2fa473cc3c91676bc610e9912fe661bfea

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