Overview
The Webhook class provides a secure, type-safe way to handle webhook events from Paystack. It automatically verifies webhook signatures, parses event payloads, and routes events to registered handlers.Key Features
- Automatic signature verification using HMAC SHA-512
- Type-safe event handlers with full TypeScript support
- Event-driven architecture with chainable
.on()method - Platform-agnostic works with Express, Next.js, Hono, and more
- Zod validation for runtime type safety
Methods
on
Registers a handler function for a specific webhook event. This method is chainable, allowing you to register multiple handlers at once.Parameters
Returns
Returns the Webhook instance for chaining.process
Processes an incoming webhook request by verifying the signature, parsing the payload, and dispatching it to the appropriate handler.Parameters
x-paystack-signature header from the webhook requestReturns
Returns a Promise that resolves to the parsed webhook payload if successful.Throws
Error("Missing 'x-paystack-signature' header")- If the signature header is missingError("Invalid webhook signature")- If the signature verification failsError("Failed to parse webhook payload")- If the payload doesn’t match the expected schema
Supported Events
The SDK supports all Paystack webhook events with full TypeScript types:Charge Events
charge.success
charge.success
reference- Transaction referenceamount- Amount in kobocustomer- Customer details (email, name, etc.)authorization- Card/payment authorization detailsmetadata- Custom metadata
charge.dispute.create
charge.dispute.create
id- Dispute IDtransaction- Full transaction detailscustomer- Customer detailsstatus- Dispute status
charge.dispute.remind
charge.dispute.remind
charge.dispute.resolve
charge.dispute.resolve
Transfer Events
transfer.success
transfer.success
reference- Transfer referenceamount- Transfer amountrecipient- Recipient detailsstatus- Transfer status
transfer.failed
transfer.failed
transfer.reversed
transfer.reversed
Subscription Events
subscription.create
subscription.create
subscription_code- Unique subscription codeplan- Plan detailscustomer- Customer detailsauthorization- Payment authorization
subscription.disable
subscription.disable
subscription.not_renew
subscription.not_renew
subscription.expiring_cards
subscription.expiring_cards
Invoice Events
invoice.create
invoice.create
invoice.update
invoice.update
invoice.payment_failed
invoice.payment_failed
Refund Events
refund.pending
refund.pending
refund.processing
refund.processing
refund.processed
refund.processed
refund.failed
refund.failed
Other Events
dedicatedaccount.assign.success
dedicatedaccount.assign.success
dedicatedaccount.assign.failed
dedicatedaccount.assign.failed
customeridentification.success
customeridentification.success
customeridentification.failed
customeridentification.failed
paymentrequest.pending
paymentrequest.pending
paymentrequest.success
paymentrequest.success
Security
Signature Verification
The SDK automatically verifies webhook signatures using HMAC SHA-512. This ensures that webhooks are genuinely from Paystack and haven’t been tampered with.Best Practices
Always use the raw request body
Always use the raw request body
Use environment variables for secrets
Use environment variables for secrets
Implement idempotency
Implement idempotency
Return 200 quickly
Return 200 quickly
Error Handling
Handle webhook processing errors gracefully:Testing Webhooks
Using Paystack Test Mode
- Use your test secret key to initialize the SDK
- Make a test transaction on your staging/test environment
- Paystack will send webhooks to your configured endpoint

