Customizing the package | laravel-webhook-client-rust | Spatie       

 SPATIE  

  Laravel Webhook Client Rust 
==============================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-webhook-client-rust](https://spatie.be/docs/laravel-webhook-client-rust/v1)  Customizing the package

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-webhook-client-rust/v1) 

  Customizing the package    
- [ Introduction ](https://spatie.be/docs/laravel-webhook-client-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-webhook-client-rust/v1/support-us)
- [ Installation and setup ](https://spatie.be/docs/laravel-webhook-client-rust/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-webhook-client-rust/v1/usage)
- [ Customizing the package ](https://spatie.be/docs/laravel-webhook-client-rust/v1/customizing-the-package)
- [ Storing attachments ](https://spatie.be/docs/laravel-webhook-client-rust/v1/attachments)
- [ Testing ](https://spatie.be/docs/laravel-webhook-client-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/laravel-webhook-client-rust/v1/changelog)

 Customizing the package
=======================

###  On this page 

1. [ Creating your own signature validator ](#content-creating-your-own-signature-validator)
2. [ Creating your own webhook profile ](#content-creating-your-own-webhook-profile)
3. [ Creating your own webhook response ](#content-creating-your-own-webhook-response)
4. [ Using your own WebhookCall model ](#content-using-your-own-webhookcall-model)
5. [ Creating your own ProcessWebhookJob ](#content-creating-your-own-processwebhookjob)

Creating your own signature validator
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Implement `SignatureValidator` and assign it to `config.signature_validator`. The validator receives the original Laravel request and the endpoint configuration. Return `Ok(false)` for invalid credentials, and an error for operational failures.

```
use laravel::http::Request;
use spatie_laravel_webhook_client::{Error, SignatureValidator, WebhookConfig};

struct MyValidator;
impl SignatureValidator for MyValidator {
    fn is_valid(&self, request: &Request, config: &WebhookConfig) -> Result<bool, Error> {
        // Replace with your sender's constant-time signature verification.
        spatie_laravel_webhook_client::DefaultSignatureValidator.is_valid(request, config)
    }
}
let mut config = WebhookConfig::new("payments", "secret");
config.signature_validator = std::sync::Arc::new(MyValidator);
```

Creating your own webhook profile
-----------------------------------------------------------------------------------------------------------------------------------------------------------

Implement the async `WebhookProfile::should_process(&self, &Request) -> Result<bool, Error>` method using `#[async_trait::async_trait]`. A profile can query the database, read the payload with `request.json` or `request.parse`, and decide which event types to process. Assign it to `config.webhook_profile`. Authenticate in the signature validator; the profile decides whether to do work after authentication.

Creating your own webhook response
--------------------------------------------------------------------------------------------------------------------------------------------------------------

Implement `RespondsToWebhook::respond_to_valid_webhook(&self, &Request, &WebhookConfig) -> Result<Response, Error>` and assign it to `config.webhook_response`. Return Laravel's native `Response`, including your status, body and headers. The response applies both to processed calls and profile-ignored calls. Errors bypass it.

Using your own WebhookCall model
--------------------------------------------------------------------------------------------------------------------------------------------------------

Implement `WebhookCallModel` for your storage type. Its associated `Call` can be your own Laravel model, including extra columns and methods. It does not have to be the package's `WebhookCall`.

- `store_webhook` receives the request, endpoint settings and attachments. It owns payload extraction, header selection and persistence.
- `save_exception` persists or clears dispatch errors on your call type.
- `Call` is passed unchanged to `ProcessWebhookJob<Call>`.

Pass your model to `WebhookProcessor::new`. Implement your own pruning alongside your storage model. The supplied migration and pruning command apply only to the default `webhook_calls` table.

The default `DatabaseWebhookCallModel` uses Laravel's database connection and query builder. Read stored calls with `WebhookCall::find` or `laravel::db::table("webhook_calls").get::<WebhookCall>()`. Header names are case-insensitive; repeated values remain separate. `StoreHeaders::None` is the default, `Only(vec![...])` selects names, and `All` retains every header. Avoid persisting authorization credentials unnecessarily.

Creating your own ProcessWebhookJob
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

Implement the async `ProcessWebhookJob<YourCall>` trait with `async_trait`, or wrap a function that creates your native Laravel job in `QueuedJob::new`. The trait's `dispatch` method enqueues work; it is not a replacement worker loop. Your job controls business logic, retry limits, timeouts and middleware. Use `.on_connection("webhooks").on_queue("payments")` on `QueuedJob` to override the native job defaults, or implement a dispatcher that uses Laravel's pending dispatch builder directly.

Use database constraints and transactions for idempotent business updates. Webhook providers and queues can deliver an event more than once; a profile lookup alone cannot make duplicate processing atomic.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
