Skip to main content

A Python package for verifying Paddle webhook signature

Project description

Paddle webhook signature verifier for Python

A Python package for verifying Paddle webhook signatures. Official Paddle SDKs are only available for PHP and Node.js. This packagage helps server side verification of Paddle webhook signatures if you are using a Python based backend framework like Django, Flask, FastAPI, etc.

Installation

pip install paddle-webhook-signature-verifier

Usage

FastAPI example

from fastapi import FastAPI, Request, Header, HTTPException
from paddle_webhook_signature_verifier import WebhookHandler

app = FastAPI()
handler = WebhookHandler(secret_key=b'your_secret_key')

@app.post("/webhook")
async def webhook(request: Request, paddle_signature: str = Header(None)):
    try:
        body_bytes = await request.body()
        handler.verify_paddle_signature(paddle_signature, body_bytes)
        return {"status": "ok"}
    except ValueError as e:
        raise HTTPException(status_code=400, detail=str(e))

Flask example

from flask import Flask, request, abort
from paddle_webhook_signature_verifier import WebhookHandler

app = Flask(__name__)
handler = WebhookHandler(secret_key=b'your_secret_key')

@app.route("/webhook", methods=["POST"])
def webhook():
    try:
        paddle_signature = request.headers.get("Paddle-Signature")
        body_bytes = request.get_data()
        handler.verify_paddle_signature(paddle_signature, body_bytes)
        return {"status": "ok"}, 200
    except ValueError as e:
        abort(400, description=str(e))

Django example

from django.http import JsonResponse
from paddle_webhook_signature_verifier import WebhookHandler

handler = WebhookHandler(secret_key=b'your_secret_key')

def webhook(request):
    try:
        paddle_signature = request.headers.get("Paddle-Signature")
        body_bytes = request.body
        handler.verify_paddle_signature(paddle_signature, body_bytes)
        return JsonResponse({"status": "ok"})
    except ValueError as e:
        return JsonResponse({"error": str(e)}, status=400)

Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your improvements.

License

This project is licensed under the MIT License. See the LICENSE file for more details

Contact

For any questions or suggestions, feel free to open an issue or contact the maintainer at aneesh.arora.aa@gmail.com

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

Built Distribution

File details

Details for the file paddle_webhook_signature_verifier-1.0.2.tar.gz.

File metadata

File hashes

Hashes for paddle_webhook_signature_verifier-1.0.2.tar.gz
Algorithm Hash digest
SHA256 0ffc2d2d95bf8a611c7acff358ba7ee9a02b302f0c78dc1abcd67b9c0f43bd6d
MD5 9085cc35c436259ff0d719c2b985ef6e
BLAKE2b-256 474d4c31370af194dc8a4eae5c42f56f5f040e77ca8c144c3dbb6faca293af07

See more details on using hashes here.

File details

Details for the file paddle_webhook_signature_verifier-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for paddle_webhook_signature_verifier-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 441a9d94db13a421555e0f598d699ae267b26b6b2cacbe91d268d87d686954e4
MD5 6847ef81130fccfec68c586e80dcd95e
BLAKE2b-256 09a8e7959b4ce983bc85811c1ed6b045665ad3cd47b3561fc474540b128080a2

See more details on using hashes here.

Supported by

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