# Receive Webhook Requests

### Use the default route

{% hint style="warning" %}
You must enable `inbox.uses_default_inbox_route` (set it to **true**)
{% endhint %}

Laravel Inbox Process ships the `/inbox/{topic}` route for you, so basically you can use this route to register with your 3rd-party service.

To add a custom Request for your specific topic (eg: `stripe`), first, you need to create a **FormRequest** and extend the `AbstractInboxProcess`.

Additionally, if you want to transform a bit of the payload, you can override the `AbstractInboxProcess@getInboxPayload` method.

```php
class StripeInvoiceCreatedWebhookRequest extends AbstractInboxRequest
{
    public function getInboxExternalId(): string | null
    {
        return 'stripe_invoice_created-' . $this->input('id');
    }
}
```

{% hint style="info" %}
From **v1.1.1+**: you can add **authorize** and **rules** method to validate the request.
{% endhint %}

Then register it to Inbox Process:

```php
// AppServiceProvider.php
use ShipSaasInboxProcess\InboxProcessSetup;

public function boot(): void
{
    //...
    InboxProcessSetup::addRequest('stripe', new StripeInvoiceCreatedWebhookRequest());
}
```

Lastly, if you wish to have a specific response for your services, you can use `addResponse`

```php
// AppServiceProvider.php
use ShipSaasInboxProcess\InboxProcessSetup;

// AppServiceProvider@boot
InboxProcessSetup::addResponse('stripe', function (StripeInvoiceCreatedWebhookRequest $request) {
    // return a response object here
    
    return new JsonResponse();
});
```

### Use your own route

Laravel Inbox Process ships the `appendInboxMsg($topic, $uniqueId, $payload)` function for manual usage.

Simply invoke the function. The msg will be appended to the table and ready to be resolved under background work.

```php
public function webhook(WebhookRequest $request): JsonResponse
{
    appendInboxMsg(
        'currency-cloud',
        $request->getId(),
        $request->all()
    );
    
    return new JsonResponse();
}
```

{% hint style="warning" %}
Note: if there is any **duplicated message**, the `appendInboxMsg` will throw an Error.

If you need to know if duplicated record happens, check out the logic inside the InboxController.php
{% endhint %}
