From 8bd9e527a47aecf43aff7a4bfcdbc0bea14ed7a6 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Mon, 29 Aug 2022 13:26:14 +0300 Subject: [PATCH 1/2] added Regulatory API --- MangoPay/ApiRegulatory.php | 32 +++++++++++++++++++ MangoPay/CountryAuthorization.php | 44 +++++++++++++++++++++++++++ MangoPay/CountryAuthorizationData.php | 27 ++++++++++++++++ MangoPay/Libraries/ApiBase.php | 13 +++++--- MangoPay/Libraries/RestTool.php | 12 ++++++-- MangoPay/MangoPayApi.php | 7 +++++ tests/Cases/RegulatoryTest.php | 43 ++++++++++++++++++++++++++ 7 files changed, 171 insertions(+), 7 deletions(-) create mode 100644 MangoPay/ApiRegulatory.php create mode 100644 MangoPay/CountryAuthorization.php create mode 100644 MangoPay/CountryAuthorizationData.php create mode 100644 tests/Cases/RegulatoryTest.php diff --git a/MangoPay/ApiRegulatory.php b/MangoPay/ApiRegulatory.php new file mode 100644 index 00000000..5a93df04 --- /dev/null +++ b/MangoPay/ApiRegulatory.php @@ -0,0 +1,32 @@ +GetObject('country_authorization_get', '\MangoPay\CountryAuthorization', $countryCode, null, null, false); + } + + /** + * Get all countries authorizations + * @param \MangoPay\Pagination $pagination + * @param \MangoPay\Sorting $sorting + * @return \MangoPay\CountryAuthorization[] + * @throws Libraries\Exception + */ + public function GetAllCountryAuthorizations(& $pagination = null, $sorting = null) + { + return $this->GetList('country_authorization_all', $pagination, 'MangoPay\CountryAuthorization', null, null, $sorting, null, false); + } +} \ No newline at end of file diff --git a/MangoPay/CountryAuthorization.php b/MangoPay/CountryAuthorization.php new file mode 100644 index 00000000..83a808c1 --- /dev/null +++ b/MangoPay/CountryAuthorization.php @@ -0,0 +1,44 @@ + '\MangoPay\CountryAuthorizationData' + ]; + } +} diff --git a/MangoPay/CountryAuthorizationData.php b/MangoPay/CountryAuthorizationData.php new file mode 100644 index 00000000..e00c7596 --- /dev/null +++ b/MangoPay/CountryAuthorizationData.php @@ -0,0 +1,27 @@ + ['/mandates/%s/transactions', RequestType::GET], 'transactions_get_for_card' => ['/cards/%s/transactions', RequestType::GET], - 'transactions_get_for_bank_account' => ['/bankaccounts/%s/transactions', RequestType::GET] + 'transactions_get_for_bank_account' => ['/bankaccounts/%s/transactions', RequestType::GET], + + 'country_authorization_get' => ['/countries/%s/authorizations', RequestType::GET], + 'country_authorization_all' => ['/countries/authorizations', RequestType::GET] ]; @@ -278,7 +281,7 @@ protected function CreateObject($methodKey, $entity, $responseClassName = null, * @return object Response data * @throws Exception */ - protected function GetObject($methodKey, $responseClassName, $firstEntityId = null, $secondEntityId = null, $thirdEntityId = null) + protected function GetObject($methodKey, $responseClassName, $firstEntityId = null, $secondEntityId = null, $thirdEntityId = null, $clientIdRequired = true) { if (!is_null($thirdEntityId)) { $urlMethod = sprintf($this->GetRequestUrl($methodKey), $firstEntityId, $secondEntityId, $thirdEntityId); @@ -289,7 +292,7 @@ protected function GetObject($methodKey, $responseClassName, $firstEntityId = nu } else { $urlMethod = $this->GetRequestUrl($methodKey); } - $rest = new RestTool($this->_root, true); + $rest = new RestTool($this->_root, true, $clientIdRequired); $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey)); if (!is_null($responseClassName)) { @@ -308,7 +311,7 @@ protected function GetObject($methodKey, $responseClassName, $firstEntityId = nu * @param \MangoPay\Sorting $sorting Object to sorting data * @return object[] Response data */ - protected function GetList($methodKey, & $pagination, $responseClassName = null, $entityId = null, $filter = null, $sorting = null, $secondEntityId = null) + protected function GetList($methodKey, & $pagination, $responseClassName = null, $entityId = null, $filter = null, $sorting = null, $secondEntityId = null, $clientIdRequired = true) { $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId, $secondEntityId); @@ -316,7 +319,7 @@ protected function GetList($methodKey, & $pagination, $responseClassName = null, $pagination = new \MangoPay\Pagination(); } - $rest = new RestTool($this->_root, true); + $rest = new RestTool($this->_root, true, $clientIdRequired); $additionalUrlParams = []; if (!is_null($filter)) { $additionalUrlParams["filter"] = $filter; diff --git a/MangoPay/Libraries/RestTool.php b/MangoPay/Libraries/RestTool.php index 0c9caa1c..6c252263 100644 --- a/MangoPay/Libraries/RestTool.php +++ b/MangoPay/Libraries/RestTool.php @@ -29,6 +29,12 @@ class RestTool */ private $_requestHttpHeaders; + /** + * Variable to flag if the request path should contain the clientId or not + * @var bool + */ + private $_clientIdRequired; + /** * Return HTTP header to send with request * @return array @@ -97,10 +103,12 @@ public function GetRequestUrl() * Constructor * @param MangoPayApi $root Root/parent instance that holds the OAuthToken and Configuration instance * @param bool $authRequired Variable to flag that in request the authentication data are required + * @param bool $clientIdRequired Variable to flag if the request path should contain the clientId or not */ - public function __construct($root, $authRequired = true) + public function __construct($root, $authRequired = true, $clientIdRequired = true) { $this->_authRequired = $authRequired; + $this->_clientIdRequired = $clientIdRequired; $this->_root = $root; $this->logger = $root->getLogger(); } @@ -169,7 +177,7 @@ public function Request($urlMethod, $requestType, $requestData = null, $idempote private function BuildRequest($urlMethod, $pagination, $additionalUrlParams = null, $idempotencyKey = null) { $urlTool = new UrlTool($this->_root); - $restUrl = $urlTool->GetRestUrl($urlMethod, $this->_authRequired, $pagination, $additionalUrlParams); + $restUrl = $urlTool->GetRestUrl($urlMethod, $this->_clientIdRequired, $pagination, $additionalUrlParams); $this->_requestUrl = $urlTool->GetFullUrl($restUrl); $logClass = $this->_root->Config->LogClass; $this->logger->debug('FullUrl : ' . $this->_requestUrl); diff --git a/MangoPay/MangoPayApi.php b/MangoPay/MangoPayApi.php index d26a4d59..1f93fa3c 100644 --- a/MangoPay/MangoPayApi.php +++ b/MangoPay/MangoPayApi.php @@ -185,6 +185,12 @@ class MangoPayApi */ public $RateLimits; + /** + * Provides Regulatory methods + * @var ApiRegulatory + */ + public $Regulatory; + /** * Constructor */ @@ -219,6 +225,7 @@ public function __construct() $this->UboDeclarations = new ApiUboDeclarations($this); $this->BankAccounts = new ApiBankAccounts($this); $this->Repudiations = new ApiRepudiations($this); + $this->Regulatory = new ApiRegulatory($this); // Setting default NullLogger $this->logger = new NullLogger(); diff --git a/tests/Cases/RegulatoryTest.php b/tests/Cases/RegulatoryTest.php new file mode 100644 index 00000000..a557fff0 --- /dev/null +++ b/tests/Cases/RegulatoryTest.php @@ -0,0 +1,43 @@ +_api->Regulatory->GetCountryAuthorizations("FR"); + + $this->assertNotNull($countryAuthorizations); + $this->assertNotNull($countryAuthorizations->CountryCode); + $this->assertNotNull($countryAuthorizations->CountryName); + $this->assertNotNull($countryAuthorizations->LastUpdate); + $this->assertNotNull($countryAuthorizations->Authorization); + + $this->assertNotNull($countryAuthorizations->Authorization->BlockBankAccountCreation); + $this->assertNotNull($countryAuthorizations->Authorization->BlockPayout); + $this->assertNotNull($countryAuthorizations->Authorization->BlockUserCreation); + } + + public function test_getAllCountriesAuthorizations() + { + $countryAuthorizations = $this->_api->Regulatory->GetAllCountryAuthorizations(); + + $this->assertNotNull($countryAuthorizations); + $this->assertTrue(count($countryAuthorizations) > 0); + + foreach ($countryAuthorizations as $authorization) { + $this->assertNotNull($authorization->CountryCode); + $this->assertNotNull($authorization->CountryName); + $this->assertNotNull($authorization->LastUpdate); + $this->assertNotNull($authorization->Authorization); + + $this->assertNotNull($authorization->Authorization->BlockBankAccountCreation); + $this->assertNotNull($authorization->Authorization->BlockPayout); + $this->assertNotNull($authorization->Authorization->BlockUserCreation); + } + } +} From dbb3623bd1a556073c697a6cd0f03f4d2f213f69 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Mon, 29 Aug 2022 17:06:26 +0300 Subject: [PATCH 2/2] fixed linter --- MangoPay/ApiPayOuts.php | 10 ++++++++-- MangoPay/ApiRegulatory.php | 2 +- MangoPay/InstantPayout.php | 2 +- MangoPay/PayOutEligibilityRequest.php | 2 +- MangoPay/PayOutEligibilityResponse.php | 1 - 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/MangoPay/ApiPayOuts.php b/MangoPay/ApiPayOuts.php index 0a4639db..c0edfcb6 100644 --- a/MangoPay/ApiPayOuts.php +++ b/MangoPay/ApiPayOuts.php @@ -26,8 +26,14 @@ public function Create($payOut, $idempotencyKey = null) */ public function CheckInstantPayoutEligibility($payOutEligibility, $idempotencyKey = null) { - return $this->CreateObject('payouts_check_eligibility', $payOutEligibility, - '\MangoPay\PayOutEligibilityResponse', null, null, $idempotencyKey); + return $this->CreateObject( + 'payouts_check_eligibility', + $payOutEligibility, + '\MangoPay\PayOutEligibilityResponse', + null, + null, + $idempotencyKey + ); } /** diff --git a/MangoPay/ApiRegulatory.php b/MangoPay/ApiRegulatory.php index 5a93df04..ef1895e4 100644 --- a/MangoPay/ApiRegulatory.php +++ b/MangoPay/ApiRegulatory.php @@ -29,4 +29,4 @@ public function GetAllCountryAuthorizations(& $pagination = null, $sorting = nul { return $this->GetList('country_authorization_all', $pagination, 'MangoPay\CountryAuthorization', null, null, $sorting, null, false); } -} \ No newline at end of file +} diff --git a/MangoPay/InstantPayout.php b/MangoPay/InstantPayout.php index 134ba1e1..cc63c722 100644 --- a/MangoPay/InstantPayout.php +++ b/MangoPay/InstantPayout.php @@ -13,4 +13,4 @@ class InstantPayout * @var FallbackReason */ public $UnreachableReason; -} \ No newline at end of file +} diff --git a/MangoPay/PayOutEligibilityRequest.php b/MangoPay/PayOutEligibilityRequest.php index 532abb6f..32b6fcbc 100644 --- a/MangoPay/PayOutEligibilityRequest.php +++ b/MangoPay/PayOutEligibilityRequest.php @@ -50,4 +50,4 @@ class PayOutEligibilityRequest extends Dto * @var string */ public $PayoutModeRequested; -} \ No newline at end of file +} diff --git a/MangoPay/PayOutEligibilityResponse.php b/MangoPay/PayOutEligibilityResponse.php index 572bec01..0c809500 100644 --- a/MangoPay/PayOutEligibilityResponse.php +++ b/MangoPay/PayOutEligibilityResponse.php @@ -11,4 +11,3 @@ class PayOutEligibilityResponse extends Dto */ public $InstantPayout; } -