spatie / laravel-webhook-client

Receive webhooks in Laravel apps
https://freek.dev/1383-sending-and-receiving-webhooks-in-laravel-apps
MIT License
1k stars 147 forks source link

Webhook Model can't be overridden #201

Closed gogl92 closed 7 months ago

gogl92 commented 11 months ago

When trying to use this package with MongoDB I tried to override the model WebhookCall as stated in the documentation, but I face issues because of the return types

This issue is being thrown while trying to implement Laravel Stripe Webhooks but this is the root cause

[2023-12-11 01:54:30] local.ERROR: Spatie\StripeWebhooks\ProcessStripeWebhookJob::__construct():
Argument #1 ($webhookCall) must be of type Spatie\WebhookClient\Models\WebhookCall, App\Models\WebhookCall given, called in /var/www/html/vendor/spatie/laravel-webhook-client/src/WebhookProcessor.php on line 54 {"exception":"[object] (TypeError(code: 0): Spatie\\StripeWebhooks\\ProcessStripeWebhookJob::__construct(): Argument #1 ($webhookCall) must be of type Spatie\\WebhookClient\\Models\\WebhookCall, App\\Models\\WebhookCall given, called in /var/www/html/vendor/spatie/laravel-webhook-client/src/WebhookProcessor.php on line 54 at /var/www/html/vendor/spatie/laravel-stripe-webhooks/src/ProcessStripeWebhookJob.php:11)

So I think that the way to solve this issue is to have an Interface that the model use will implement, and the extension validates that this models are instances of this class, it will work as a contract (WebhookCallContract?) and the return types needed will use this instead of the model.

Methods can be added to this class if needed like:

storeWebhook();
headersToStore();
headerBag();
...

This way we allow the package to be more extendable.

gogl92 commented 11 months ago

I can create a pull request to solve this issue

spatie-bot commented 7 months ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

paul-hellomolly commented 4 months ago

Can we reopen this issue? I'm also having trouble using a different model that extends the WebhookCall.