neyric/mangopay-bundle

Symfony 的 MangoPay 插件包

安装: 930

依赖项: 0

建议者: 0

安全: 0

星星: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

v1.2.0 2021-01-08 11:16 UTC

This package is auto-updated.

Last update: 2024-09-08 19:48:41 UTC


README

MangoPay 提供的 Symfony 插件包,在官方的 MangoPay PHP SDK 的基础上增加额外服务

  • 提供访问 API 的服务,以更好地集成到 Symfony 中
  • 添加有用的命令
  • Webhook 处理器(HTTP 控制器)+ Webhook 事件

要求

  • Php 7.1
  • Symfony 4.4

安装

$ composer require neyric/mangopay-bundle

在您的应用程序中加载插件包

$bundles = [
    // ...
    new \Neyric\MangoPayBundle\NeyricMangoPayBundle(),
];

配置

该插件包(特别是 MangoPayService),期望以下 3 个环境变量被定义

访问 MangoPay API

配置完成后,您可以使用 Symfony 依赖注入从 SDK 访问 API

use Neyric\MangoPayBundle\Service\MangoPayService; 

class MyService
{
    public function __construct(MangoPayService $mangoPayService)
    {
        $this->mangoPayService = $mangoPayService;
    }

    public function someMethod()
    {
        // You can access the public `api` property, which is the
        // configured instance of MangoPay\MangoPayApi 
        $hooks = $this->mangoPayService->api->Hooks->GetAll();
    }
}

Symfony 命令

显示已安装钩子的列表

php bin/console neyric_mangopay:hooks:list

显示速率限制(执行 1 个 API 调用)

php bin/console neyric_mangopay:ratelimits

使用 Webhook 处理器

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

neyric_mangopay:
    path: /mangopay_webook/hook_handler # Customizable url
    controller: Neyric\MangoPayBundle\Controller\HookController::hookHandlerAction

然后使用 Mangopay 控制台注册您想要的 Webhook

创建一个订阅者

use Neyric\MangoPayBundle\Event\MangoPayHookEvent;

class MySubscriber implements EventSubscriberInterface
{
    
    public function onMangopayKycSucceeded(MangoPayHookEvent $event)
    {
        // ...
    }

    public function onMangopayUboDeclarationValidated(MangoPayHookEvent $event)
    {
        // ...
    }

    public static function getSubscribedEvents()
    {
        return [
            'MANGOPAY_KYC_SUCCEEDED' => ['onMangopayKycSucceeded', 1],
            'MANGOPAY_UBO_DECLARATION_VALIDATED' => ['onMangopayUboDeclarationValidated', 1],
        ];
    }
}

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

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

许可证

neyric/mangopay-bundle 在 MIT 许可证下分发,请参阅 LICENSE 文件

联系方式

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