flole/ds-ipn

该软件包最新版本(dev-master)没有可用的许可信息。

dev-master 2017-07-08 16:47 UTC

This package is not auto-updated.

Last update: 2023-10-06 15:44:22 UTC


README

Digistore IPN 文档:https://doc.digistore24.com/technics/technical-access-to-the-system/ipn/further-information-about-the-digistore24-ipn-interface/?lang=en

简短描述

此库将帮助您在应用程序中实现 Digistore IPN。您需要一个日志记录器、sha 密码和请求数据。

入门

为了使用此库,您需要创建一个“DigistoreIpn”实例,并注入以下内容

  1. 第一个参数必须是一个 monolog 接口的实例(例如,Monolog 实例)。

  2. 第二个参数必须是一个字符串,它是您在 Digsitore 后端输入的密码,用于生成 sha512 签名。

  3. 第三个参数必须是一个数组,它是 digistore 的原始请求数据(例如 $_GET)。

    New DigistoreIpn(new NullLogger(), 'password', $requestData)

添加事件处理器

根据 digistore 事件,您需要执行操作。为了做到这一点,请添加一个事件处理器。事件处理器必须实现 EventHandlerInterface。

// Your event handler
class OnPaymentEventHandler implements EventHandlerInterface
{

    public function handle(array $requestData)
    {
        //The stuff you want to do e.g. create user
    }

}

$ipn = new DigistoreIpn(new NullLogger, 'my_password', $_GET);
$ipn->addEventHandler(DigistoreEvents::EVENT_ON_PAYMENT, new OnPaymentEventHandler());

调用 “->handle()” 来处理 digistore 数据和事件

$ipn->handle();

使用自定义验证器

默认验证器是“Sha512Authenticator”,用于通过 digistore 发送的 sha 签名验证请求。建议使用默认设置。一个重要的注意事项是,如果请求不被允许,将抛出 AccessDeniedException 异常。

如果您想设置自定义验证器,请参见以下内容

//You custom authenticator
class MyAuthenticator implements DigistoreAuthenticatorInterface
{

    public function auth(string $shaSign, array $requestData)
    {
        //Your logic to validate that the request is allowed
    }

}

$ipn = new DigistoreIpn(new NullLogger, 'my_password', $_GET);
$ipn->setAuthenticator(new MyAuthenticator());

使用自定义请求数据验证器

默认的 StandardRequestDataValidator 将检查以下内容

  • order_id
  • product_id
  • email
  • event
  • sha_sign

是否在请求中,如果缺少这些键之一,将抛出 MissingDataException 异常。

使用自定义验证器

class MyDataValidator impements RequestDataValidatorInterface
{

    public function validate(array $data) : bool
    {
        //Perform your custom validation logic
    }

}

$ipn = new DigistoreIpn(new NullLogger, 'my_password', $_GET);
$ipn->setDataValidator(new MyDataValidator());

开发

  1. 克隆此仓库
  2. 运行 "docker-composer exec app bash"
  3. 运行 "cd /srv/app"。现在您已进入容器中的项目根目录
  4. 在新的分支中添加您的代码,并添加单元测试