eoneopay / webhooks
v0.20.6
2019-10-30 23:44 UTC
Requires
- php: >=7.3
- ext-json: *
- ext-mbstring: *
- doctrine/orm: ^2.6.3
- eoneopay/externals: ^1.0
- eoneopay/utils: ^0.2
- guzzlehttp/guzzle: ^6.0.0
Requires (Dev)
- eoneopay/standards: ^0.1
- laravel/lumen-framework: ^5.5
- mockery/mockery: ^1.0
- phpmd/phpmd: ^2.6
- phpstan/phpstan: ^0.11
- phpstan/phpstan-phpunit: ^0.11.0
- phpstan/phpstan-strict-rules: ^0.11.0
- phpunit/phpunit: ^8.0
- roave/security-advisories: dev-master
- sebastian/phpcpd: ^4.0
- squizlabs/php_codesniffer: 3.*
- symfony/security: ^4.3
Provides
- dev-master
- v0.20.6
- v0.20.5
- v0.20.4
- v0.20.3
- v0.20.2
- v0.20.1
- v0.20.0
- v0.10.10
- v0.10.9
- v0.10.8
- v0.10.7
- v0.10.6
- v0.10.5
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.2
- v0.9.1
- v0.9.0
- dev-development
- dev-feature/fix-activity-repository
- dev-feature/PYMT-1253-transaction-by-continuum
- dev-feature/add-event-to-payload
- dev-fix/event-dispatcher-binding
This package is auto-updated.
Last update: 2019-11-11 00:22:50 UTC
README
此库添加了对创建活动的支持,这些活动随后作为webhooks触发给活动的订阅者。
安装
使用 Composer 在您的项目中安装此包
composer require eoneopay/webhooks
使用
将 \EoneoPay\Webhooks\Activities\Interface\ActivityFactoryInterface
服务注入到需要创建活动的应用程序中。此接口上的发送方法接受一个 ActivityDataInterface
实现来表示要创建的特定活动。
对于您在应用程序中触发的每种不同活动,您需要创建一个实现 ActivityDataInterface
的类。
操作原理
ActivityFactoryInterface
接收一个ActivityDataInterface
实例- 然后工厂将调用
PayloadManager
来为ActivityDataInterface
构建有效负载 - 工厂将有效负载和
ActivityDataInterface
保存为新ActivityInterface
实体。 - 最后,工厂将分派一个 ActivityCreatedEvent
- 然后工厂将调用
- 监听器将在异步队列工作器内部接收事件并调用
WebhookManager#processActivity
- WebhookManager 将解析活动的任何订阅
- 然后为每个订阅创建一个新的 WebhookRequest
- 并分派一个新的 WebhookRequestCreatedEvent。
- 另一个监听器将接受此事件并调用
RequestProcessor#process
- 这将构建一个 PSR7 请求
- 发送请求
- 将结果记录为 WebhookResponse
集成
Laravel
要将包集成到您的 Laravel 或 Lumen,您需要注册以下服务提供者
\EoneoPay\Webhooks\Bridge\Laravel\Providers\WebhookServiceProvider
\EoneoPay\Webhooks\Bridge\Laravel\Providers\WebhookEventServiceProvider
此库的任何实现都需要
- 实现并绑定一个服务用于接口
EoneoPay\Webhooks\Subscription\Interfaces\SubscriptionResolverInterface
- 实现一个服务用于接口
EoneoPay\Webhooks\Payload\Interfaces\PayloadBuilderInterface
- 示例
interface WebHookPayloadBuilderInterface extends PayloadBuilderInterface { ... } final class PayloadBuilder implements WebHookPayloadBuilderInterface { ... }
- 绑定并标记服务用于接口
YourNamespace\WebHookPayloadBuilderInterface
$this->app->bind(WebHookPayloadBuilderInterface::class, PayloadBuilder::class); $this->app->tag([WebHookPayloadBuilderInterface::class], ['webhooks_payload_builders']);
- 将
EoneoPay\Externals\Bridge\Laravel\ORM\ResolveTargetEntityExtension
添加到config/doctrine.php
中的extensions
键下 - 修改
config/doctrine.php
以添加以下更改到配置中
<?php declare(strict_types=1); use EoneoPay\Externals\Bridge\LaravelDoctrine\Extensions\ResolveTargetEntityExtension; use EoneoPay\Webhooks\Models\ActivityInterface; use EoneoPay\Webhooks\Models\WebhookRequestInterface; use EoneoPay\Webhooks\Models\WebhookResponseInterface; use EoneoPay\Webhooks\Bridge\Doctrine\Entities\Activity; use EoneoPay\Webhooks\Bridge\Doctrine\Entities\Lifecycle\Request; use EoneoPay\Webhooks\Bridge\Doctrine\Entities\Lifecycle\Response; return [ 'managers' => [ 'default' => [ // ... 'namespaces' => [ // ... // Add the Webhooks Entities to the namespace mappings 'Eoneopay\\Webhooks\\Bridge\\Doctrine\\Entities' ], 'paths' => [ // ... // Add the Webhooks filepath to the Entity Manager \base_path('vendor/eoneopay/webhooks/src/Bridge/Doctrine/Entities') ] // ... ] ], // ... 'extensions' => [ // ... // Add the ResolveTargetEntityExtension to Doctrine ResolveTargetEntityExtension::class ], // ... 'replacements' => [ // Add replacements so Doctrine can look up entities by interface ActivityInterface::class => Activity::class, WebhookRequestInterface::class => Request::class, WebhookResponseInterface::class => Response::class ] ];