该包最新版本(v1.0.0)没有提供许可信息。

Mindbox SDK for PHP

v1.0.0 2024-07-04 05:15 UTC

This package is auto-updated.

Last update: 2024-09-04 05:52:01 UTC


README

PHP库,用于简化您的PHP应用程序与Mindbox API的交互。您可以在此处了解Mindbox API的完整文档:这里

入门

依赖关系

安装

您可以通过两种方式安装Mindbox SDK:使用Composer或下载存档。第一种方式更受欢迎,因为它可以通过一个命令更新库。

Composer(推荐方式)

您可以使用以下命令通过依赖关系管理器Composer安装Mindbox PHP SDK

composer require mindbox/sdk

为了将Mindbox PHP SDK安装到PHP版本>=5.6且<7.3的项目中,需要使用版本1.0.7。为此,请执行以下命令

composer require "mindbox/sdk:^1.0.7"

手动安装

  1. 下载存档,其中包含项目的源代码(包括依赖项)。
  2. 将其解压到您的项目目录中。
  3. 在您的脚本开头连接类自动加载器
require_once __DIR__ . '/path/to/mindboxSDK/vendor/autoload.php';

使用

SDK配置的必选参数

  • {logsDir} - 日志目录
  • {endpointId} - 网站或移动应用程序等的唯一标识符。您需要向Mindbox经理确认此值。
  • {secretKey} - 与endpointId对应的秘密密钥。您需要向Mindbox经理确认此值。
  • {domainZone} - 发送请求的Mindbox API域名

可选参数

  • {timeout} - HTTP请求连接超时时间(以秒为单位),可选。默认为5秒。
  • {httpClient} - 发送请求的方式("curl", "stream"),可选。默认为curl,如果已安装ext-curl扩展,否则为stream。

SDK初始化

$logger = new \Mindbox\Loggers\MindboxFileLogger('{logsDir}');

$mindbox = new \Mindbox\Mindbox([
    'endpointId' => '{endpointId}',
    'secretKey' => '{secretKey}',
    'domainZone' => '{domainZone}',
    //'timeout' => '{timeout}',
    //'httpClient' => '{httpClient}',
], $logger);

有关配置和初始化SDK的详细信息,请参阅这里

使用辅助器执行标准操作

为了执行标准操作,Mindbox实现了一组辅助器,简化了请求的执行。以下是一个使用辅助器发送消费者授权请求到Mindbox的简单示例

$logger = new \Mindbox\Loggers\MindboxFileLogger('{logsDir}');

$mindbox = new \Mindbox\Mindbox([
    'endpointId' => '{endpointId}',
    'secretKey' => '{secretKey}',
    'domainZone' => '{domainZone}',
], $logger);

$customer = new \Mindbox\DTO\CustomerRequestDTO();
$customer->setEmail('test@test.ru');
$customer->setMobilePhone('77777777777');
$customer->setId('mindboxId', '1028');

try {
    $response = $mindbox->customer()
        ->authorize($customer, 'Website.AuthorizeCustomer')
        ->sendRequest();
    
    $requestBody = $response->getRequest()->getBody();
    $responseBody = $response->getBody();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();
    return;
}

有关使用SDK辅助器的详细信息,请参阅这里

用于发送任意请求的通用方法

对于没有实现辅助器的请求,您可以使用通用方法执行

$logger = new \Mindbox\Loggers\MindboxFileLogger('{logsDir}');

$mindbox = new \Mindbox\Mindbox([
    'endpointId' => '{endpointId}',
    'secretKey' => '{secretKey}',
    'domainZone' => '{domainZone}',
], $logger);

$operation = new \Mindbox\DTO\OperationDTO();

$customer = new \Mindbox\DTO\CustomerRequestDTO();
$customer->setEmail('test@test.ru');
$customer->setMobilePhone('77777777777');
$customer->setId('mindboxId', '1028');

$operation->setCustomer($customer);

try {
    $response = $mindbox->getClientV3()
        ->prepareRequest('POST', 'Website.AuthorizeCustomer', $operation, '', [], false)
        ->sendRequest();
    $requestBody = $response->getRequest()->getBody();
    $responseBody = $response->getBody();
} catch (\Mindbox\Exceptions\MindboxClientException $e) {
    echo $e->getMessage();
}

有关使用SDK通用方法的详细信息,请参阅这里

文档

有关库的详细文档,请访问此链接