neyric/yousign-bundle

Symfony 的 Yousign Bundle

安装量 15,997

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 2

开放问题: 2

类型:symfony-bundle

v0.0.7 2021-10-16 21:02 UTC

This package is auto-updated.

Last update: 2024-09-17 03:31:46 UTC


README

Yousign 提供的 Symfony Bundle。

  • 提供服务以访问 API,以实现更好的 Symfony 集成
  • Webhook 处理程序(HTTP 控制器)+ Webhook 事件

要求

  • Php >= 7.1
  • Symfony 4.4 或 5+

安装

$ composer require neyric/yousign-bundle

在您的应用程序中加载 Bundle

$bundles = [
    // ...
    new \Neyric\YousignBundle\NeyricYousignBundle(),
];

配置

该 Bundle(特别是 YousignApiClient)期望定义以下 2 个环境变量

使用 webhook 处理程序

首先,在您的 routes.yaml 文件中设置路由

neyric_yousign:
    path: /yousign_webook/hook_handler # Customizable url
    controller: Neyric\YousignBundle\Controller\YousignController::webhookHandlerAction

创建一个订阅者

use Neyric\YousignBundle\Event\WebhookEvent;

class MySubscriber implements EventSubscriberInterface
{
    
    public function onYousignWebhook(WebhookEvent $event)
    {
        $headers = $event->getHeaders();

        if (array_key_exists('x-my-custom-header', $headers)) {
            // ...
        }

        // ...
    }

    public static function getSubscribedEvents()
    {
        return [
            WebhookEvent::class => ['onYousignWebhook'],
        ];
    }
}

最终,使用 kernel.event_subscriber 标签声明服务

    App\Subscriber\MySubscriber:
        class: App\Subscriber\MySubscriber
        tags:
            - { name: kernel.event_subscriber }

准备本地隧道

使用本地隧道可以节省您大量时间,因为您可以在本地进行测试。推荐选择 ngrok。Ngrok 是一种将我们的本地服务器隧道到网络上的工具,使我们的本地 webhook 处理程序可用于电子邮件提供商的 webhook。

许可证

neyric/yousign-bundle 采用 MIT 许可证发行,请参阅 LICENSE 文件

联系方式

使用 GitHub 上的问题跟踪器报告错误或建议功能。