> For the complete documentation index, see [llms.txt](https://docs.hyperswitch.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hyperswitch.io/integrations/prism/node/event-service/handle.md).

# Handle

## Overview

The `handle` method processes raw webhook payloads from payment processors. It verifies webhook signatures, parses the event data, and returns a normalized response with the event type and associated payment details.

**Business Use Case:** When Stripe sends a webhook notification that a payment succeeded, you need to verify it's authentic and update your order status. This method handles verification and parsing.

## Purpose

| Challenge              | Solution                                        |
| ---------------------- | ----------------------------------------------- |
| Signature verification | Automatically verifies webhook authenticity     |
| Multiple formats       | Normalizes Stripe, Adyen into consistent format |
| Security               | Validates secrets before processing             |

## Request Fields

| Field             | Type          | Required | Description                      |
| ----------------- | ------------- | -------- | -------------------------------- |
| `merchantEventId` | string        | Yes      | Your unique event reference      |
| `payload`         | string/object | Yes      | Raw webhook body                 |
| `headers`         | object        | Yes      | HTTP headers including signature |
| `webhookSecret`   | string        | Yes      | Webhook signing secret           |

## Response Fields

| Field            | Type    | Description                                    |
| ---------------- | ------- | ---------------------------------------------- |
| `eventType`      | string  | Type: payment.captured, refund.succeeded, etc. |
| `eventResponse`  | object  | Payment/refund/dispute details                 |
| `sourceVerified` | boolean | Whether signature was verified                 |
| `eventStatus`    | string  | COMPLETE, INCOMPLETE                           |

## Example

### SDK Setup

```javascript
const { EventClient } = require('hyperswitch-prism');

const eventClient = new EventClient({
    connector: 'stripe',
    apiKey: 'YOUR_API_KEY'
});
```

### Express.js Webhook Handler

```javascript
app.post('/webhooks/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
    const request = {
        merchantEventId: `evt_${Date.now()}`,
        payload: req.body,
        headers: req.headers,
        webhookSecret: process.env.STRIPE_WEBHOOK_SECRET
    };

    try {
        const response = await eventClient.handle(request);

        if (response.eventType === 'payment.captured') {
            await fulfillOrder(response.eventResponse.paymentsResponse.merchantTransactionId);
        } else if (response.eventType === 'refund.succeeded') {
            await updateRefundStatus(response.eventResponse.refundsResponse);
        }

        res.json({ received: true });
    } catch (error) {
        res.status(400).json({ error: error.message });
    }
});
```

### Response

```javascript
{
    eventType: "payment.captured",
    eventResponse: {
        paymentsResponse: {
            merchantTransactionId: "txn_order_001",
            connectorTransactionId: "pi_3Oxxx...",
            status: "CAPTURED"
        }
    },
    sourceVerified: true,
    eventStatus: "COMPLETE"
}
```

## Event Types

| Event Type           | Description                    |
| -------------------- | ------------------------------ |
| `payment.authorized` | Payment authorized, funds held |
| `payment.captured`   | Payment completed              |
| `payment.failed`     | Payment declined               |
| `refund.succeeded`   | Refund processed               |
| `dispute.created`    | New chargeback received        |

## Next Steps

* [Payment Service](/integrations/prism/node/payment-service.md) - Process payment events
* [Refund Service](/integrations/prism/node/refund-service.md) - Process refund events
* [Dispute Service](/integrations/prism/node/dispute-service.md) - Process dispute events


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.hyperswitch.io/integrations/prism/node/event-service/handle.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
