# Request Schema

```typescript
type WebhookRequest = {
  reason:
    | "SubscriptionCreated"
    | "SubscriptionCancelled"
    | "SubscriptionEnded"
    | "Payment"
    | "PaymentFailure"
    | "DynamicPaymentRequestRejected";
  link: string;
  version: "v1";
  home: "https://debitllama.com";
};
```

### reason

You can receive a webhook request for the following reasons

1. SubscriptionCreated - A new subscription was approved for one of your items
2. SubscriptionCancelled - An existing subscription was cancelled
3. Payment - A successful payment
4. PaymentFailure - Payment failed, could be due to missing relayer or account balance!
5. DynamicPaymentRequestRejected - The Request to make a direct debit with a custom amount was rejected during relaying. Payment can't be processed.

### link

A link to the payment intent using APIV1

```
https://debitllama.com/api/v1/payment_intents/[paymentIntent]
```

You can fetch the details of the payment intent using the link via GET request

{% content-ref url="/pages/fmvGMsYsiynKkZHGruYW" %}
[/api/v1/payment\_intents/\[slug\]](/debitllama/rest-api-v1/api-v1-payment_intents-slug.md)
{% endcontent-ref %}

### version and home

The version and home keys store meta data  The API version and the URL of the service.

### Example Webhook code

```typescript
Deno.serve(async (req) => {
  const wr: WebhookRequest = await req.json();
  
  //You can fetch the Payment Intent details using the link
  const piRes = await fetch(wr.link, { method: "GET" });
  const paymentIntent : PaymentIntent_ApiV1 = await piRes.json();

  switch (wr.reason) {
    //Add your Business Logic
    case "SubscriptionCreated":
      break;
    case "SubscriptionCancelled":
      break;
    case "SubscriptionEnded":
      break;
    case "Payment":
      break;
    case "PaymentFailure":
      break;
    case "DynamicPaymentRequestRejected":
      break;
    default:
      break;
  }

  return new Response(
    null,
    { status: 200, headers: { "Content-Type": "application/json" } },
  );
});

```


---

# Agent Instructions: 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:

```
GET https://debitllama.gitbook.io/debitllama/rest-api-v1/configuring-webhooks/request-schema.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
