Skip to main content

Typed Python client + webhook verification for the PaymentHub API.

Project description

paymenthub (Python SDK)

Typed Python client + webhook verification for the PaymentHub API. Models are generated from PaymentHub's published OpenAPI spec with datamodel-code-generator, so responses are validated pydantic models.

Sandbox-only portfolio project.

Install

pip install paymenthub

Quickstart

from paymenthub import PaymentHubClient, PaymentCreate

with PaymentHubClient(api_key="sk_test_…") as ph:
    # One-call sandbox bootstrap (test-mode keys only):
    demo = ph.seed_sandbox()  # -> SandboxSeedResponse(api_key, merchant_id, sample_payment_ids)

    payment = ph.create_payment(PaymentCreate(
        amount_minor=1500,
        currency="USD",
        success_url="https://example.com/success",
        cancel_url="https://example.com/cancel",
    ))
    print(payment.checkout_url)

    detail = ph.get_payment(payment.id)

PaymentHubClient defaults to the hosted gateway; pass base_url= to point elsewhere, or http_client= to inject a custom/mocked httpx.Client.

Webhook verification

Verify the raw request body server-side (don't re-serialize):

from paymenthub import verify_webhook

ok = verify_webhook(
    provider="stripe",        # or "paymob"
    payload=raw_body,         # str | bytes
    signature=request.headers["x-paymenthub-signature"],
    secret=WEBHOOK_SECRET,
)
  • Stripe-style (verify_stripe_signature): t=<unix>,v1=<hex> header; HMAC-SHA256 over f"{t}.{body}" with a replay tolerance (default 5 min).
  • Paymob-style (verify_paymob_hmac): raw HMAC-SHA256 hex digest over the body.

All comparisons use hmac.compare_digest (constant-time).

Development

uv run --extra dev ruff check .
uv run --extra dev mypy src
uv run --extra dev pytest
uv build

Models live in src/paymenthub/_models.py, generated from the vendored openapi.json:

uv run --with datamodel-code-generator datamodel-codegen \
  --input openapi.json --input-file-type openapi \
  --output src/paymenthub/_models.py \
  --output-model-type pydantic_v2.BaseModel \
  --target-python-version 3.10 --use-standard-collections --use-union-operator

Refresh openapi.json from the backend and re-run when the API changes.

Releasing

release.yml publishes to PyPI on a v* tag (or a repository_dispatch from the backend) via Trusted Publishing (OIDC) — no token stored. It runs the test suite and completes a sandbox payment against prod before publishing. Configure a PyPI trusted publisher for this repo + workflow, and add a PAYMENTHUB_TEST_KEY repo secret for the smoke test.

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

paymenthub-0.1.0.tar.gz (89.5 kB view details)

Uploaded Source

Built Distribution

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

paymenthub-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file paymenthub-0.1.0.tar.gz.

File metadata

  • Download URL: paymenthub-0.1.0.tar.gz
  • Upload date:
  • Size: 89.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for paymenthub-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f6ab1dcd08aaf51b0073c5442e9221cc86f8dc2149e3d70953184edcbc3ac1ad
MD5 a78bd56e266f3160d0ec2768dd721993
BLAKE2b-256 314942995a498bb7c3e9fe116080e8ecb0ad4d40cc6cd5e82dfbcf6c9295c9a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for paymenthub-0.1.0.tar.gz:

Publisher: release.yml on ahmeddmohamed-noon/paymenthub-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file paymenthub-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: paymenthub-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for paymenthub-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 935a821869870511975c4b67a183032785a8020f47da63fae75822fdf8646b0a
MD5 5d058118e0f08aac696eb1699cbd43bb
BLAKE2b-256 9261c68bac2360908cb060d5efb1a099417943ed4901eb9391b9f0476227c3b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for paymenthub-0.1.0-py3-none-any.whl:

Publisher: release.yml on ahmeddmohamed-noon/paymenthub-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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