定制 esign/laravel-unleash-webhook-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

esign/laravel-unleash-webhook-client

最新稳定版本:1.0.0

Composer 安装命令:

composer require esign/laravel-unleash-webhook-client

包简介

Receive Unleash webhooks within a Laravel application

README 文档

README

Latest Version on Packagist Total Downloads GitHub Actions

This package builds on top of Spatie's Laravel Webhook Client package to provide handling of Unleash webhooks in Laravel applications.

Installation

You can install the package via composer:

composer require esign/laravel-unleash-webhook-client

Configuration

You may follow the steps under the configuration section of Spatie's Laravel Webhook Client package.

You can find the WEBHOOK_CLIENT_SECRET in the website's configuration section of Unleash.
To set up a webhook, register a new webhook under the Webhooks section for the desired module.
Set the webhook URL to the route you have configured in your Laravel application, for example: Route::webhooks('unleash-webhook');

Processing webhooks

To process the webhook, extend the Esign\UnleashWebhookClient\Jobs\ProcessUnleashWebhookJob job in your application.
You can use its getWebhookEntries method to extract the relevant data from the webhook payload and process it as needed.

namespace App\Jobs;

use App\Models\Redirect;
use App\Models\Translation;
use Esign\UnleashWebhookClient\Jobs\ProcessUnleashWebhookJob as BaseProcessUnleashWebhookJob;

class ProcessUnleashWebhookJob extends BaseProcessUnleashWebhookJob
{
    public function handle(): void
    {
        foreach ($this->getWebhookEntries() as $webhookEntry) {
            match ($webhookEntry->table) {
                (new Translation)->getTable() => $this->handleTranslationsWebhook($webhookEntry),
                (new Redirect)->getTable() => $this->handleRedirectsWebhook($webhookEntry),
                default => null,
            };
        }
    }

    protected function handleTranslationsWebhook(WebhookEntry $webhookEntry): void
    {
        // Handle the translation webhook entry
    }

    protected function handleRedirectsWebhook(WebhookEntry $webhookEntry): void
    {
        // Handle the redirects webhook entry
    }
}

Mocking Unleash Webhooks in Tests

This package provides a MocksUnleashWebhooks trait to simplify testing Unleash webhook integrations in your Laravel application. The trait allows you to easily send signed webhook requests using fixture files or custom payloads.

use Esign\UnleashWebhookClient\Testing\MocksUnleashWebhooks;

class ExampleTest extends TestCase
{
    use MocksUnleashWebhooks;

    #[Test]
    public function it_can_process_unleash_webhooks(): void
    {
        $responseA = $this->makeUnleashWebhookRequest(['example' => 'data']);
        $responseB = $this->makeUnleashWebhookRequestFromFixture('example-webhook.json');

        $responseA->assertOk();
        $responseB->assertOk();
    }
}

By default, fixture files are expected to be located in the tests/Fixtures/UnleashWebhooks/ directory. You may provide a custom path for the fixture files using the usingUnleashWebhookFixturePath(?string $path) method.

Running Tests

composer test

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 245
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-01