Skip to content

Commit

Permalink
Merge pull request #618 from Mangopay/feature/integrate-the-format-of…
Browse files Browse the repository at this point in the history
…-user-data

feature/ Integrate Validate the format of User data endpoint
  • Loading branch information
iulian03 authored Feb 13, 2024
2 parents 9f8ecb5 + 628b1f3 commit 2274e3f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
11 changes: 11 additions & 0 deletions MangoPay/ApiUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,15 @@ public function GetRegulatory($userId)
{
return $this->GetObject('users_block_status_regulatory', 'MangoPay\UserBlockStatus', $userId);
}

/**
* This call allows you to check the validity of the format
* of a piece of user data, and to retrieve the validation rules applied to it.
* @param $companyNumberDetails
* @return \MangoPay\CompanyNumberDetails
*/
public function ValidateTheFormatOfUserData($companyNumberDetails)
{
return $this->ExecutePostRequest('validate_the_format_of_user_data', $companyNumberDetails, '\MangoPay\CompanyNumberDetails');
}
}
29 changes: 29 additions & 0 deletions MangoPay/CompanyNumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace MangoPay;

class CompanyNumber extends Libraries\EntityBase
{
/**
* Information about the registration number of a legal entity.
* @var string
*/
public $CompanyNumber;

/**
* The country of the registration of the legal entity, against which the company number format is validated.
* @var string
*/
public $CountryCode;

/**
* @var bool
*/
public $IsValid;

/**
* Validation rules applied for a given country
* @var array
*/
public $ValidationRules;
}
12 changes: 12 additions & 0 deletions MangoPay/CompanyNumberDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace MangoPay;

class CompanyNumberDetails extends Libraries\EntityBase
{
/**
* Company number details
* @var object
*/
public $CompanyNumber;
}
13 changes: 10 additions & 3 deletions MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ protected function getLogger()
'users_block_status' => ['/users/%s/blockStatus', RequestType::GET],
'users_block_status_regulatory' => ['/users/%s/Regulatory', RequestType::GET],

'validate_the_format_of_user_data' => ['/users/data-formats/validation', RequestType::POST],

'bankaccounts_save' => ['/users/%s/bankaccounts/%s', RequestType::PUT],

'wallets_create' => ['/wallets', RequestType::POST],
Expand Down Expand Up @@ -331,7 +333,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, $clientIdRequired = true)
protected function GetList($methodKey, &$pagination, $responseClassName = null, $entityId = null, $filter = null, $sorting = null, $secondEntityId = null, $clientIdRequired = true)
{
$urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId, $secondEntityId);

Expand Down Expand Up @@ -403,9 +405,14 @@ protected function SaveObject($methodKey, $entity, $responseClassName = null, $s
* @param $entityId Entity identifier
* @return object Response data
*/
protected function ExecutePostRequest($methodKey, $entity, $responseClassName, $entityId)
protected function ExecutePostRequest($methodKey, $entity, $responseClassName, $entityId = null)
{
$urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId);
if ($entityId != null) {
$urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId);
} else {
$urlMethod = $this->GetRequestUrl($methodKey);
}

$requestData = $this->BuildRequestData($entity);

$rest = new RestTool($this->_root, true);
Expand Down
17 changes: 17 additions & 0 deletions tests/Cases/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,4 +769,21 @@ public function test_user_natural_terms_and_conditions()
$this->assertTrue($accepted->TermsAndConditionsAccepted);
$this->assertNotNull($accepted->TermsAndConditionsAcceptedDate);
}

public function test_validate_the_format_of_user_data()
{
$companyNumberDetails = new \MangoPay\CompanyNumberDetails();
$companyNumber = new \MangoPay\CompanyNumber();
$companyNumber->CompanyNumber = 'AB123456';
$companyNumber->CountryCode = 'IT';
$companyNumberDetails->CompanyNumber = $companyNumber;

$validatedCompanyNumber = $this->_api-> Users->ValidateTheFormatOfUserData($companyNumberDetails);

$this->assertNotNull($validatedCompanyNumber);
$this->assertNotNull($validatedCompanyNumber->CompanyNumber->CompanyNumber);
$this->assertNotNull($validatedCompanyNumber->CompanyNumber->CountryCode);
$this->assertTrue($validatedCompanyNumber->CompanyNumber->IsValid);
$this->assertNotEmpty($validatedCompanyNumber->CompanyNumber->ValidationRules);
}
}

0 comments on commit 2274e3f

Please sign in to comment.