mangopay / php-sdk-v2
MANGOPAY 的 PHP SDK
Requires
- php: >=5.6
- ext-curl: *
- ext-json: *
- ext-openssl: *
- psr/log: ^1.0|^2.0|^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.18
- phpunit/phpunit: >=5.7.27 <10
- dev-master
- 3.31.0
- 3.30.0
- 3.29.3
- 3.29.2
- 3.29.1
- 3.29.0
- 3.28.0
- 3.27.0
- 3.26.0
- 3.25.0
- 3.24.1
- 3.24.0
- 3.23.0
- 3.22.1
- 3.22.0
- 3.21.0
- 3.20.1
- 3.20.0
- 3.19.0
- 3.18.1
- 3.18.0
- 3.17.0
- 3.16.2
- 3.16.1
- 3.16.0
- 3.15.0
- 3.14.1
- 3.14.0
- 3.13.0
- 3.12.0
- 3.11.0
- 3.10.1
- 3.10.0
- 3.9.0
- v3.8.0
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.0
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.6
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.0
- 2.13.2
- 2.13.1
- 2.13.0
- 2.12.2
- 2.12.1
- 2.12.0
- 2.11.0
- 2.10.1
- 2.10.0
- 2.9.2
- 2.9.1
- 2.9.0
- 2.8.1
- 2.8.0
- v2.7.1
- v2.7.0
- 2.6.4
- 2.6.3
- 2.6.1
- 2.6.0
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.4
- 2.4.3
- 2.4.2
- v2.4.1
- v2.4
- v2.3
- v2.2
- v2.1
- v2.0
- v1.7
- v1.6
- v1.5
- v1.4.3
- dev-feature/card-holder-name
- dev-feature/new-pay-pal-parameters
- dev-improvement/github_actions
- dev-feature/conversions
- dev-feature/quoted_conversion
- dev-feature/conversions_quote
- dev-feature/configuration_for_UK
- dev-feature/add_fees_param
- dev-bugfix/fix_typo_in_conversion_endpoint
- dev-feature/bin_metadata_endpoint
- dev-feature/integrate-the-format-of-user-data
- dev-feature/get_card_validation
- dev-feature/implement_cardinfo
- dev-improvement/add_parameter_to_ideal_endpoint
- dev-feature/handle-partial-refund
- dev-improvement/add-reference-to-paypal
- dev-feature/ideal-and-giropay-mops
- dev-feature/spot-fx-endpoints
- dev-bugfix/linter-3.22.0
- dev-rel/3.22.0
- dev-improvement/mbway-paypal-execution-type
- dev-feature/paypal-v2
- dev-bugfix/linter-error
- dev-feature/mbway-payin
- dev-feature/dispute-closed-date
- dev-bugfix/auth
- dev-feature/partnership
- dev-feature/deposits
- dev-bugfix/failing-tests
- dev-feature/country-authorizations
- dev-feature/free-cycles
- dev-revert-558-feature/UserCategory
- dev-feature/UserCategory
- dev-feature/UsersTermsAndConditions
- dev-feature/payout_features
- dev-feature/update_logger
- dev-feature/RecurringPaymentNewFields
- dev-feature/payconiq_payments
- dev-bugfix/PayOutBankWireFix
- dev-feature/update_recurring_payments
- dev-feature/NewEventTypePreAuth
- dev-feature/name_improving_rate_limits
- dev-feature/change_ibans
- dev-feature/Requested3DSVersion
- dev-feature/add_userId_in_ubodeclaration
- dev-bugfix/payin_api_correlation
- dev-feature/addnamesinshippingandbilling
- dev-feature/PayoutModeRequested
- dev-bugfix/RegulatoryDeserializeError
- dev-bugfix/RestToolParamFix
- dev-feature/browserinfo-ip-address-regulatory-shipping
- dev-feature/new_secure_mode
- dev-feature/new-hooks
- dev-feature/user-block-status
- dev-fix/remove-testing-versions
- dev-feature/client-fees-wallet
- dev-feature/pre-authorization-transactions
- dev-bugfix/issue_420
- dev-fix/travis-tests
- dev-test-ci
- dev-release
- dev-feature/card-validity
- dev-feature/remaining-funds
- dev-feature/change_user_agent_format
- dev-feature/tls12
- dev-feature/add_kyc_status_out_of_date
- dev-bugfix/resttool/fix
- dev-feature/add_remaining_funds_field_in_preauthorization_object
- dev-feature/multicapture
- dev-feature/add_card_validity_support
- dev-bugfix/ubodeclaration/create-ubo
- dev-add_new_enum_values_for_eventType
- dev-issue/multi-currency-usage-is-not-authorized
- dev-feature/user_kyc_regular
- dev-add-account-number-support-for-payins
- dev-feature/PaypalPayinsCulturePropertyPaypal
- dev-add-google-pay-support
- dev-mickaelpois-disputetestfix
This package is auto-updated.
Last update: 2024-08-30 13:55:30 UTC
README
MangopaySDK 是一个 PHP 客户端库,用于与 Mangopay REST API 交互。
兼容性说明
- 自 SDK 的 v2.1 版本起,您必须使用 API 的至少 v2.01 版本(有关所需更改的更多信息,请参阅 此处)
- 如果在 SDK 更新(尤其是更新到 SDK 的 v2.0 版本)后遇到身份验证和/或临时令牌文件问题,您可能需要只需删除您的临时文件(您通过
$api->Config->TemporaryFolder
指定)- 这允许它在下次需要时正确再生
要求
要使用此 SDK,您将需要(至少)
- PHP 5.6 或更高版本
- cURL(包括在标准 PHP 发行版中启用)
- OpenSSL(包括在标准 PHP 发行版中启用)
- psr/log v1.0
- 您不需要使用 Composer,但强烈建议您这样做(特别是对于处理 PSR Log 库的依赖项)
使用 Composer 安装
您可以使用 Composer 将 Mangopay SDK 库作为项目中的依赖项(这是首选技术)。如果您尚未安装 Composer,请按照 这些安装说明 进行操作。仓库中包含 composer.json 文件,并且它已从 Packagist 引用。
使用 Composer 进行安装既简单又可靠
步骤 1 - 通过执行以下命令将 Mangopay SDK 添加为依赖项
you@yourhost:/path/to/your-project$ composer require mangopay/php-sdk-v2
步骤 2 - 使用 Composer 更新您的依赖项
you@yourhost:/path/to/your-project$ composer update
步骤 3 - 最后,务必在您的项目中包含自动加载器
require_once '/path/to/your-project/vendor/autoload.php';
库已添加到您的依赖项中,并准备好使用。
不使用 Composer 的安装
该项目试图遵守 PSR-4 规范,以便从文件路径自动加载类。命名空间前缀为 MangoPay\
,基本目录为 /path/to/your-project/
。
如果您不使用 PSR-4 或 Composer,则安装与下载库并将其存储在项目可包含的任何位置一样简单(但请记住包含所需的库依赖项)
require_once '/path/to/your-project/MangoPay/Autoloader.php';
或者,您可以从 发布页面(查找 mangopay2-php-sdk-[RELEASE_NAME].zip
文件)下载整个包(即包含所有必需依赖项的包)。解压缩您下载的 zip 文件,并在项目中包含自动加载器
require_once '/path/to/your-project/mangopay2-php-sdk/vendor/autoload.php';
许可
MangopaySDK 在 MIT 许可证下分发,请参阅 LICENSE 文件。
单元测试
测试放在 /path/to/your-project/tests/
下。/tests/suites/all.php
套件运行所有测试。您也可以使用 /tests/cases/*.php
中的任何测试用例来运行单个测试用例。
联系方式
使用GitHub上的问题跟踪器报告错误或建议功能。
账户创建
您可以通过在Mangopay网站上注册来获取一个免费的沙箱账户或申请一个生产账户(请注意,验证您的生产账户涉及多个步骤,因此请提前考虑,以便在实际上线之前完成)。
配置
使用上述注册过程提供的凭证信息,您应将$api->Config->ClientId
设置为您的Mangopay ClientId,并将$api->Config->ClientPassword
设置为您的Mangopay APIKey。
您还需要在$api->Config->TemporaryFolder
中设置一个文件夹路径,该SDK需要存储临时文件。此路径应位于您的www文件夹之外。可以是/tmp/
、/var/tmp/
或任何PHP可以写入的其他位置。您必须为沙箱和生产环境使用不同的文件夹。
$api->Config->BaseUrl
默认设置为沙箱环境。要启用生产环境,请将其设置为https://api.mangopay.com
。
require_once '/path/to/your-project/vendor/autoload.php'; $api = new MangoPay\MangoPayApi(); // configuration $api->Config->ClientId = 'your-client-id'; $api->Config->ClientPassword = 'your-client-password'; $api->Config->TemporaryFolder = '/some/path/'; //$api->Config->BaseUrl = 'https://api.mangopay.com';//uncomment this to use the production environment //uncomment any of the following to use a custom value (these are all entirely optional) //$api->Config->CurlResponseTimeout = 20;//The cURL response timeout in seconds (its 30 by default) //$api->Config->CurlConnectionTimeout = 60;//The cURL connection timeout in seconds (its 80 by default) //$api->Config->CertificatesFilePath = ''; //Absolute path to file holding one or more certificates to verify the peer with (if empty, there won't be any verification of the peer's certificate) // call some API methods... try { $users = $api->Users->GetAll(); } catch(MangoPay\Libraries\ResponseException $e) { // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails() } catch(MangoPay\Libraries\Exception $e) { // handle/log the exception $e->GetMessage() }
示例用法
require_once '/path/to/your-project/vendor/autoload.php'; $api = new MangoPay\MangoPayApi(); // configuration $api->Config->ClientId = 'your-client-id'; $api->Config->ClientPassword = 'your-client-password'; $api->Config->TemporaryFolder = '/some/path/'; // get some user by id try { $john = $api->Users->Get($someId); } catch(MangoPay\Libraries\ResponseException $e) { // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails() } catch(MangoPay\Libraries\Exception $e) { // handle/log the exception $e->GetMessage() } // change and update some of his data $john->LastName .= " - CHANGED"; try { $api->Users->Update($john); } catch(MangoPay\Libraries\ResponseException $e) { // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails() } catch(MangoPay\Libraries\Exception $e) { // handle/log the exception $e->GetMessage() } // get all users (with pagination) $pagination = new MangoPay\Pagination(1, 8); // get 1st page, 8 items per page try { $users = $api->Users->GetAll($pagination); } catch(MangoPay\Libraries\ResponseException $e) { // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails() } catch(MangoPay\Libraries\Exception $e) { // handle/log the exception $e->GetMessage() } // get his bank accounts $pagination = new MangoPay\Pagination(2, 10); // get 2nd page, 10 items per page try { $accounts = $api->Users->GetBankAccounts($john->Id, $pagination); } catch(MangoPay\Libraries\ResponseException $e) { // handle/log the response exception with code $e->GetCode(), message $e->GetMessage() and error(s) $e->GetErrorDetails() } catch(MangoPay\Libraries\Exception $e) { // handle/log the exception $e->GetMessage() }
在Symfony项目中使用Composer的示例用法
您可以在Symfony项目中将Mangopay功能集成到Service中。
MangoPayService.php
<?php namespace Path\To\Service; use MangoPay; class MangoPayService { private $mangoPayApi; public function __construct() { $this->mangoPayApi = new MangoPay\MangoPayApi(); $this->mangoPayApi->Config->ClientId = 'your-client-id'; $this->mangoPayApi->Config->ClientPassword = 'your-client-password'; $this->mangoPayApi->Config->TemporaryFolder = '/some/path/'; //$this->mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com'; } /** * Create Mangopay User * @return MangopPayUser $mangoUser */ public function getMangoUser() { $mangoUser = new \MangoPay\UserNatural(); $mangoUser->PersonType = "NATURAL"; $mangoUser->FirstName = 'John'; $mangoUser->LastName = 'Doe'; $mangoUser->Birthday = 1409735187; $mangoUser->Nationality = "FR"; $mangoUser->CountryOfResidence = "FR"; $mangoUser->Email = 'john.doe@mail.com'; //Send the request $mangoUser = $this->mangoPayApi->Users->Create($mangoUser); return $mangoUser; } }
日志记录
Mangopay使用PSR3 LoggerInterface。您可以向API提供自己的记录器。以下是一个展示Monolog集成的示例
use Monolog\Logger; use Monolog\Handler\StreamHandler; ... $logger = new Logger('sample-logger'); $logger->pushHandler(new StreamHandler($logConfig['path'], Logger::DEBUG)); $this->mangoPayApi = new MangoPay\MangoPayApi(); $this->mangoPayApi->setLogger($logger);
验证速率限制状态
根据API文档(https://docs.mangopay.com/guide/rate-limiting),Mangopay提供了一种验证API调用次数、剩余次数以及计数器何时重置的方法。因此,有4组速率限制可用
- 过去15分钟
- 过去30分钟
- 过去60分钟
- 过去24小时
此信息可从MangoPayApi实例中获取,如下例所示
<?php namespace Path\To\Service; use MangoPay; class MangoPayService { /** * @var MangoPay\MangoPayApi */ private $mangoPayApi; public function __construct() { $this->mangoPayApi = new MangoPay\MangoPayApi(); $this->mangoPayApi->Config->ClientId = 'your-client-id'; $this->mangoPayApi->Config->ClientPassword = 'your-client-password'; $this->mangoPayApi->Config->TemporaryFolder = '/some/path/'; //$this->mangoPayApi->Config->BaseUrl = 'https://api.sandbox.mangopay.com'; } public function verifyRateLimits() { // This is an array of 4 RateLimit objects. $rateLimits = $this->mangoPayApi->RateLimits; print "\nThere were " . $rateLimits[0]->CallsMade . " calls made in the last 15 minutes"; print "\nYou can do " . $rateLimits[0]->CallsRemaining . " more calls in the next 15 minutes"; print "\nThe 60 minutes counter will reset at " . date("Y-m-d\TH:i:s\Z", $rateLimits[0]->ResetTimeTimestamp); print "\nThere were " . $rateLimits[2]->CallsMade . " calls made in the last 60 minutes"; print "\nYou can do " . $rateLimits[2]->CallsRemaining . " more calls in the next 60 minutes"; print "\nThe 60 minutes counter will reset at " . date("Y-m-d\TH:i:s\Z", $rateLimits[2]->ResetTimeTimestamp); } }