quisui / order-basic-notification
为了确保不会错过任何销售,并跟踪订单状态,需要创建一个基本通知服务。
This package is auto-updated.
Last update: 2024-09-26 18:33:13 UTC
README
Buckhill Challenge 创建通知包 - NotificationOrderStatusUpdater
为了确保不会错过任何销售,并跟踪订单状态,需要创建一个基本通知服务。
信息
观察者模式通过事件和监听器实现。
该包定义了一个名为 OrderStatusUpdated 的事件类,其中包含将传递给监听器的数据。
该包还定义了一个名为 SendOrderStatusNotification 的监听器类,负责在订单状态更新时向 webhook 发送通知。
监听器在 EventServiceProvider 类中注册,以监听 OrderStatusUpdated 事件。
当 OrderStatusUpdated 事件被触发(通常是通过更新订单状态的代码)时,SendOrderStatusNotification 监听器被触发,并通过 webhook 发送通知。
这种实现方式允许其他开发者在不需要修改现有代码的情况下,轻松地为 OrderStatusUpdated 事件添加新的监听器,以便在订单状态更新时执行额外操作。
此方法将使此监听器在您的应用程序内部可用
src/ordernotificationprovider.php
$this->app['events']->listen( 'Quisui\OrderBasicNotification\Events\OrderStatusUpdated', 'Quisui\OrderBasicNotification\Listeners\SendOrderStatusNotification' );
安装
composer require quisui/order-basic-notification
使用
- 在任何代码部分创建一个新的 NotificationOrderStatusUpdater 对象
- 当您的对象准备就绪时
<?php
use Quisui\OrderBasicNotification\NotificationOrderStatusUpdater;
new NotificationOrderStatusUpdater(...);
?>
- 这需要一些必要的参数作为数组
<?php
$required = [
'order_uuid' => rand(0, 666),
'new_status' => 'status',
'timestamp' => 'dateTimeRequired',
'webhook_url' => 'https://webhook.site/81872e1a-5b97-4a0d-b32a-55365cc1b774',
'webhook_http_method' => 'post'
]
use Quisui\OrderBasicNotification\NotificationOrderStatusUpdater;
new NotificationOrderStatusUpdater($required);
?>
现在每次您想要消费任何 webhook URL 并发送特定信息时,您都可以使用这个基本事件监听器来发送您的信息
运行测试
- 使用 cd 命令导航到您的项目:vendor/quisui/order-basic-notification
- 现在您需要在终端中运行:../../vendor/bin/phpunit tests/OrderStatusUpdatedTest.php