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.

Usage

FastAPI example

from fastapi import FastAPI, Request, Header, HTTPException
from paddle_webhook_verification.handler 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_verification.handler 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_verification.handler 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)

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.0.tar.gz.

File metadata

File hashes

Hashes for paddle_webhook_signature_verifier-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5cfebc9d7a9623a042d82effcd5fe0f177605b90badda7f5e87cbeed9d1d1a46
MD5 0a7baa1eea4aeae494fbb0e297f77281
BLAKE2b-256 3b262d81944c39e943c36401a0400ca2ba197e6247fe3fcd4e995ac487031287

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for paddle_webhook_signature_verifier-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b10147e1283f0f49fb9208c3f0a7a02eaad3639341d19d34fdc1e0f936215db
MD5 671fda09450e669868bfc934249b3337
BLAKE2b-256 76fc3304aba0b324fa6b45f2ea6215518be427509d2688a187b23b64fab2bd0b

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