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.2.0.tar.gz (89.8 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.2.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for paymenthub-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8d18b4cc2ce4a26c9dbd4b7e662a24e0834f62722891758af042b3dc9fae8af7
MD5 653c18f997bc97e5770a35047a7f1ab7
BLAKE2b-256 fc81117343c63b2d40ee80870a20afd2c4fff123aa7620cb16487350720882d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for paymenthub-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: paymenthub-0.2.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4d702e7c67c2254cf32172268fd8659e459c52844bfe1f7af6b8e8d7e431ecc
MD5 90a728ad331ea90e2cc2a5d8e7ae146d
BLAKE2b-256 23ad15ff001f6ba11c1f76ed7228f685c3c7449f2b9ffa403f82ef79133e8954

See more details on using hashes here.

Provenance

The following attestation bundles were made for paymenthub-0.2.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