mindbox / sdk
此包的最新版本(1.1.5)没有提供许可信息。
Mindbox SDK for PHP
1.1.5
2024-04-26 08:12 UTC
Requires (Dev)
Suggests
- ext-curl: *
- dev-master
- v2.2.0.x-dev
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.0.3
- 0.0.2
- 0.0.1
- 0.0.0
- dev-MBM-393
- dev-cdp/kiyakov/newAuthScheme
- dev-renovate/configure
- dev-MBM-353
- dev-fix-readme-links
- dev-MBM-333
- dev-add-action-php74
- dev-MaximBurcev-patch-2
- dev-MBM-319
- dev-MBM-318
- dev-MaximBurcev-patch-1
- dev-MBM-299
- dev-MBM-259
- dev-release/2.4.2
- dev-MBM-149
- dev-MBM-144
- dev-MBM-33
- dev-MBM-83
- dev-MBM-88
- dev-MBM-72
- dev-MBM-8
- dev-MB-750
- dev-fix/booleanValuesInXML
- dev-test/parseResponseCode
- dev-test/parseRawHeaders
- dev-hotfix/RawHeadersParse
This package is auto-updated.
Last update: 2024-09-26 09:13:23 UTC
README
PHP库,用于简化您的PHP应用程序与Mindbox API的交互。有关Mindbox API的完整文档,请参阅此处。
入门
依赖关系
- PHP版本7.3或更高版本
- psr/log
- ext-json
- ext-simplexml
- ext-libxml
- ext-curl(可选)
安装
您可以通过两种方式安装Mindbox SDK:使用Composer或下载存档。首选第一种方式,因为它允许您通过一个命令更新库。
Composer(推荐方式)
您可以使用以下命令使用依赖管理器Composer安装Mindbox PHP SDK:
composer require mindbox/sdk
对于在PHP版本>=5.6且<7.3运行的项目的Mindbox PHP SDK安装,需要使用版本1.0.7。为此,请执行以下命令:
composer require "mindbox/sdk:^1.0.7"
手动安装
- 下载存档,包含项目源代码(包括依赖项)。
- 将存档解压到您的项目目录。
- 在您的脚本开头连接类自动加载器
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通用方法的详细信息,请参阅此处。
文档
有关库的详细文档可通过此链接访问。