Skip to content

Commit

Permalink
Merge pull request #567 from Mangopay/feature/country-authorizations
Browse files Browse the repository at this point in the history
added Regulatory API
  • Loading branch information
iulian03 authored Sep 7, 2022
2 parents 4888fd8 + dbb3623 commit d01d4cd
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 12 deletions.
10 changes: 8 additions & 2 deletions MangoPay/ApiPayOuts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

/**
Expand Down
32 changes: 32 additions & 0 deletions MangoPay/ApiRegulatory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace MangoPay;

/**
* Class to management MangoPay API for regulatory endpoints
*/
class ApiRegulatory extends Libraries\ApiBase
{
/**
* Get country authorizations by country code
* @param string $countryCode
* @return \MangoPay\CountryAuthorization
* @throws Libraries\Exception
*/
public function GetCountryAuthorizations($countryCode)
{
return $this->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);
}
}
44 changes: 44 additions & 0 deletions MangoPay/CountryAuthorization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace MangoPay;

/**
* Repudiation entity
*/
class CountryAuthorization extends Libraries\EntityBase
{
/**
* The code of the country in the ISO 3166-1 alpha-2 format.
* @var string
*/
public $CountryCode;

/**
* Name of the country
* @var string
*/
public $CountryName;

/**
* Information about the country’s restrictions.
* @var CountryAuthorizationData
*/
public $Authorization;

/**
* Date and time when at least one of the authorizations has been last updated.
* @var string
*/
public $LastUpdate;

/**
* Get array with mapping which property is object and what type of object
* @return array
*/
public function GetSubObjects()
{
return [
'Authorization' => '\MangoPay\CountryAuthorizationData'
];
}
}
27 changes: 27 additions & 0 deletions MangoPay/CountryAuthorizationData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace MangoPay;

/**
* Repudiation entity
*/
class CountryAuthorizationData extends Libraries\EntityBase
{
/**
* Whether or not user creation is possible based on the user’s country of residence.
* @var boolean
*/
public $BlockUserCreation;

/**
* Whether or not bank account creation is possible based on the bank’s country of domiciliation.
* @var boolean
*/
public $BlockBankAccountCreation;

/**
* Whether or not payout creation is possible based on the bank’s country of domiciliation.
* @var boolean
*/
public $BlockPayout;
}
2 changes: 1 addition & 1 deletion MangoPay/InstantPayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ class InstantPayout
* @var FallbackReason
*/
public $UnreachableReason;
}
}
13 changes: 8 additions & 5 deletions MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ protected function getLogger()

'transactions_get_for_mandate' => ['/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]

];

Expand Down Expand Up @@ -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);
Expand All @@ -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)) {
Expand All @@ -308,15 +311,15 @@ 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);

if (is_null($pagination) || !is_object($pagination) || get_class($pagination) != 'MangoPay\Pagination') {
$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;
Expand Down
12 changes: 10 additions & 2 deletions MangoPay/Libraries/RestTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions MangoPay/MangoPayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ class MangoPayApi
*/
public $RateLimits;

/**
* Provides Regulatory methods
* @var ApiRegulatory
*/
public $Regulatory;

/**
* Constructor
*/
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion MangoPay/PayOutEligibilityRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ class PayOutEligibilityRequest extends Dto
* @var string
*/
public $PayoutModeRequested;
}
}
1 change: 0 additions & 1 deletion MangoPay/PayOutEligibilityResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ class PayOutEligibilityResponse extends Dto
*/
public $InstantPayout;
}

43 changes: 43 additions & 0 deletions tests/Cases/RegulatoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace MangoPay\Tests\Cases;

/**
* Tests basic methods for report requests
*/
class RegulatoryTest extends Base
{
public function test_getCountryAuthorizations()
{
$countryAuthorizations = $this->_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);
}
}
}

0 comments on commit d01d4cd

Please sign in to comment.