Skip to content

Webhook Event Processing

This guide explains how to receive and process webhook events from external services using the Open PaaS Platform. Follow these steps to configure webhook endpoints, validate incoming requests, and handle event processing effectively.


Before You Begin

Make sure you have the following:

  • Access to Open PaaS Platform with webhook processing permissions
  • External service configured to send webhooks to your endpoints
  • HTTPS endpoint URL for receiving webhooks (required for production)
  • Python 3.x and the Open PaaS Platform SDK installed
  • Webhook signing secrets from your external service
  • Familiarity with Create Your First Connector

Create a Webhook Processor

  1. Initialize the Webhook Client: Set up the Open PaaS Platform client to handle webhook processing:

    from openpaas_sdk import OpenPaaSClient, WebhookProcessor
    
    # Initialize the platform client
    client = OpenPaaSClient(api_key="your_api_key")
    
  2. Configure Webhook Endpoints: Create a webhook processor with your endpoint configuration and security settings:

    # Create webhook processor for payment events
    payment_webhook = WebhookProcessor(
        name="payment_processor",
        service="stripe",
        config={
            "endpoint_url": "https://yourapp.com/webhooks/payments",
            "signing_secret": "whsec_your_webhook_secret",
            "supported_events": ["payment_succeeded", "payment_failed"],
            "verify_signature": True
        }
    )
    
  3. Define Event Handlers: Create handlers for different webhook events that your application needs to process:

    # Handle successful payments
    @payment_webhook.on_event("payment_succeeded")
    def handle_payment_success(event_data):
        customer_id = event_data["customer_id"]
        amount = event_data["amount"]
    
        # Update customer record
        client.update_customer(customer_id, {"payment_status": "paid"})
    
        # Trigger fulfillment workflow
        client.trigger_workflow("order_fulfillment", {
            "customer_id": customer_id,
            "amount": amount
        })
    
        return {"status": "processed"}
    
    # Handle failed payments
    @payment_webhook.on_event("payment_failed")
    def handle_payment_failure(event_data):
        customer_id = event_data["customer_id"]
        error_message = event_data["error_message"]
    
        # Update customer record with failure
        client.update_customer(customer_id, {
            "payment_status": "failed",
            "last_error": error_message
        })
    
        # Send notification
        client.send_notification(customer_id, {
            "type": "payment_failed",
            "message": "Payment processing failed. Please try again."
        })
    
        return {"status": "processed"}
    
  4. Start the Webhook Processor: Activate the webhook processor to begin receiving and processing events:

    # Start processing webhooks
    payment_webhook.start()
    
    print("Webhook processor started and listening for events...")
    
  5. Test Your Webhook Setup: Verify that your webhook processor is working correctly with test events:

    # Test with a sample webhook payload
    test_payload = {
        "event_type": "payment_succeeded",
        "customer_id": "cust_12345",
        "amount": 2500,
        "currency": "usd"
    }
    
    # Process test event
    result = payment_webhook.process_test_event(test_payload)
    print(f"Test result: {result}")
    

Troubleshooting

If you encounter any issues with webhook processing, refer to the Troubleshooting Guide.

See Also