Payment Callback (Webhook)
Receive real-time notifications when payment status changes. Webhooks are the primary way to stay updated on order status and automatically fulfill customer orders.
Overview
MugglePay sends webhook events to notify your application whenever an order status changes. This is the ONLY backend mechanism you need to track payment status and automatically fulfill orders.
Use Cases
Webhooks enable you to:
Update customer records when subscription payments succeed
Send confirmation emails after successful payments
Log accounting entries when transfers are completed
Update inventory when orders are paid
Activate services immediately upon payment confirmation
Webhook Configuration
Setting Up Your Endpoint
Provide callback URL in your Create Order request
Ensure endpoint is public and accessible from the internet
Handle POST requests with JSON payloads
Return HTTP 200 to acknowledge receipt
Authentication
Webhooks are authenticated using the merchant_token field you provide in the Create Order request. This prevents fraudulent callback attempts.
Request Details
HTTP Method
Method: POST
Content-Type: application/json
Authentication: Token-based (from Create Order)
Response Requirement
Your webhook endpoint must return HTTP 200 with this JSON response:
Webhook Payload Structure
order_id
string
MugglePay's internal order identifier
merchant_order_id
string
Your custom order ID from Create Order
status
string
Current payment status (NEW, PENDING, PAID, etc.)
price_amount
string
Original price set by merchant (e.g., "29.99")
price_currency
string
Currency for pricing (e.g., "USD")
pay_amount
string
Actual amount paid by customer
pay_currency
string
Currency used for payment
created_at
string
ISO 8601 timestamp of order creation
created_at_t
number
Unix timestamp (epoch) of order creation
merchant_token
string
Your custom merchant_token for webhook validation
meta
object
Additional payment information (optional)
Code Examples
Node.js/Express Example
Python/Flask Example
PHP Example
Sample Webhook Payload
Retry Mechanism
MugglePay automatically retries failed webhook deliveries using exponential backoff:
1st
1 minute
1 minute
2nd
2 minutes
3 minutes
3rd
4 minutes
7 minutes
4th
8 minutes
15 minutes
5th
16 minutes
31 minutes
6th
32 minutes
63 minutes
7th
64 minutes
2 hours 7 minutes
8th
128 minutes
4 hours 15 minutes
9th
256 minutes
8 hours 31 minutes
Continues
Doubles
Up to 3 days
Important: Always return HTTP 200 to prevent unnecessary retries.
Security Best Practices
✅ Do's
Validate webhook tokens to prevent fraud
Use HTTPS for all webhook endpoints
Implement idempotency to handle duplicate webhooks
Log all webhook events for debugging
Return HTTP 200 even on processing errors
❌ Don'ts
Don't ignore webhook validation
Don't expose webhook endpoints without authentication
Don't return error codes that trigger retries
Don't process webhooks synchronously for long operations
Testing Webhooks
Local Development
Use tools like ngrok to expose local endpoints
Test with small amounts in sandbox mode
Verify webhook delivery and processing
Manual Testing
Use the Merchant Portal
Click "Trigger Payment Callback" button for testing
Monitor webhook delivery in your logs
Troubleshooting
Common Issues
Webhook Not Receiving
Check endpoint accessibility: Ensure your URL is publicly accessible
Verify callback_url: Confirm it's correctly set in Create Order
Check firewall settings: Ensure incoming POST requests are allowed
Test manually: Use Merchant Portal to trigger test callbacks
Webhook Processing Errors
Validate merchant token: Ensure webhook merchant_token matches your expected value
Check payload structure: Verify all required fields are present
Handle errors gracefully: Return 200 even when processing fails
Monitor logs: Check for specific error messages
Duplicate Webhooks
Implement idempotency: Process each webhook only once
Check order_id: Use unique identifiers to prevent duplicates
Database constraints: Add unique constraints on order processing
Related Documentation
Create Order - Set up webhook endpoints
Order Status - Understand status values
Authentication - Secure your webhooks
Getting Started - Complete integration guide
Next Steps
Implement webhook endpoint following the examples above
Test webhook delivery with small test orders
Add order fulfillment logic for PAID status
Monitor webhook processing in production
Set up alerting for webhook failures
Last updated