ivan-grebnev / mindbox-sdk-php8
此包的最新版本(2.0.3)没有提供许可信息。
Mindbox SDK for PHP
2.0.3
2022-07-11 07:41 UTC
Requires (Dev)
- mikey179/vfsstream: *
- phpunit/phpunit: >=5
- squizlabs/php_codesniffer: >=3.4
Suggests
- ext-curl: *
- dev-master
- v2.2.0.x-dev
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.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-MaximBurcev-patch-2
- dev-MBM-319
- dev-MBM-318
- dev-renovate/configure
- 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-11 12:05:38 UTC
README
PHP库,简化您的PHP应用程序与Mindbox API的交互。有关Mindbox API的完整文档,请参阅此处。
入门
依赖项
- PHP版本5.6或更高版本
- psr/log
- ext-json
- ext-simplexml
- ext-libxml
- ext-curl(可选)
安装
您可以通过两种方式安装Mindbox SDK:使用Composer或下载存档。第一种方式更受欢迎,因为它允许您通过一个命令更新库。
Composer(推荐方式)
您可以使用以下命令通过依赖关系管理器Composer安装Mindbox PHP SDK:
composer require mindbox/sdk
手动安装
- 下载包含项目源代码(包括依赖项)的存档此处。
- 将其解压到您的项目目录中。
- 在您的脚本开头连接类自动加载器
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通用方法的详细信息,请参阅此处。
文档
有关库的详细文档可通过链接访问。