Files
fetcherpay-python/examples/webhook_verification.py
2026-02-19 12:17:09 -05:00

42 lines
941 B
Python

"""
FetcherPay Python SDK - Webhook Verification Example
"""
import json
from fetcherpay import FetcherPay
# Initialize client
client = FetcherPay(
api_key='sandbox',
environment='sandbox'
)
# Example webhook payload
payload = json.dumps({
'id': 'evt_123',
'type': 'payment.settled',
'created_at': '2026-02-18T20:00:00Z',
'data': {
'id': 'pay_456',
'status': 'settled',
'amount': 10000
}
})
# Your webhook secret from the dashboard
webhook_secret = 'whsec_your_secret_here'
# Simulate receiving a webhook
signature = 'sha256=...' # From X-FetcherPay-Signature header
# Verify the signature
is_valid = client.verify_webhook_signature(payload, signature, webhook_secret)
if is_valid:
print('✅ Webhook signature verified')
# Process the webhook event
event = json.loads(payload)
print(f'Event type: {event["type"]}')
else:
print('❌ Invalid webhook signature')