From 5058392768dcc2871fb4025cea54651fa4c50e70 Mon Sep 17 00:00:00 2001 From: Silviana Ghita <> Date: Thu, 9 Nov 2023 17:14:36 +0200 Subject: [PATCH 1/3] Integrated Validate the format of User data endpoint --- MangoPay/ApiUsers.php | 11 +++++++++++ MangoPay/CompanyNumber.php | 30 ++++++++++++++++++++++++++++++ MangoPay/Libraries/ApiBase.php | 13 ++++++++++--- tests/Cases/UsersTest.php | 14 ++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 MangoPay/CompanyNumber.php diff --git a/MangoPay/ApiUsers.php b/MangoPay/ApiUsers.php index b423c265..17b90cdd 100644 --- a/MangoPay/ApiUsers.php +++ b/MangoPay/ApiUsers.php @@ -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 $companyNumber + * @return \MangoPay\CompanyNumber + */ + public function ValidateTheFormatOfUserData($companyNumber) + { + return $this->ExecutePostRequest('validate_the_format_of_user_data', $companyNumber, '\MangoPay\CompanyNumber'); + } } diff --git a/MangoPay/CompanyNumber.php b/MangoPay/CompanyNumber.php new file mode 100644 index 00000000..f6bdf859 --- /dev/null +++ b/MangoPay/CompanyNumber.php @@ -0,0 +1,30 @@ + ['/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], @@ -328,7 +330,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); @@ -400,9 +402,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); diff --git a/tests/Cases/UsersTest.php b/tests/Cases/UsersTest.php index bbf35292..e35cb2b4 100644 --- a/tests/Cases/UsersTest.php +++ b/tests/Cases/UsersTest.php @@ -769,4 +769,18 @@ 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(){ + $companyNumber = new \MangoPay\CompanyNumber(); + $companyNumber->CompanyNumber = 'LU12345678'; + $companyNumber->CountryCode = 'FR'; + + $validatedCompanyNumber = $this->_api-> Users->ValidateTheFormatOfUserData($companyNumber); + + $this->assertNotNull($validatedCompanyNumber); + $this->assertNotNull($validatedCompanyNumber->CompanyNumber); + $this->assertNotNull($validatedCompanyNumber->CountryCode); + $this->assertSame('true', $validatedCompanyNumber->IsValid); + $this->assertNotEmpty($validatedCompanyNumber->ValidationRules); + } } From f6edd8b6fe7b168a36527dd1a2911fe4ca692297 Mon Sep 17 00:00:00 2001 From: Silviana Ghita <> Date: Fri, 10 Nov 2023 16:57:34 +0200 Subject: [PATCH 2/3] Fixed request --- MangoPay/ApiUsers.php | 8 ++++---- MangoPay/CompanyNumberDetails.php | 12 ++++++++++++ tests/Cases/UsersTest.php | 16 +++++++++------- 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 MangoPay/CompanyNumberDetails.php diff --git a/MangoPay/ApiUsers.php b/MangoPay/ApiUsers.php index 17b90cdd..dab35f49 100644 --- a/MangoPay/ApiUsers.php +++ b/MangoPay/ApiUsers.php @@ -428,11 +428,11 @@ public function GetRegulatory($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 $companyNumber - * @return \MangoPay\CompanyNumber + * @param $companyNumberDetails + * @return \MangoPay\CompanyNumberDetails */ - public function ValidateTheFormatOfUserData($companyNumber) + public function ValidateTheFormatOfUserData($companyNumberDetails) { - return $this->ExecutePostRequest('validate_the_format_of_user_data', $companyNumber, '\MangoPay\CompanyNumber'); + return $this->ExecutePostRequest('validate_the_format_of_user_data', $companyNumberDetails, '\MangoPay\CompanyNumberDetails'); } } diff --git a/MangoPay/CompanyNumberDetails.php b/MangoPay/CompanyNumberDetails.php new file mode 100644 index 00000000..d5a50826 --- /dev/null +++ b/MangoPay/CompanyNumberDetails.php @@ -0,0 +1,12 @@ +CompanyNumber = 'LU12345678'; - $companyNumber->CountryCode = 'FR'; + $companyNumber->CompanyNumber = 'AB123456'; + $companyNumber->CountryCode = 'IT'; + $companyNumberDetails->CompanyNumber = $companyNumber; - $validatedCompanyNumber = $this->_api-> Users->ValidateTheFormatOfUserData($companyNumber); + $validatedCompanyNumber = $this->_api-> Users->ValidateTheFormatOfUserData($companyNumberDetails); $this->assertNotNull($validatedCompanyNumber); - $this->assertNotNull($validatedCompanyNumber->CompanyNumber); - $this->assertNotNull($validatedCompanyNumber->CountryCode); - $this->assertSame('true', $validatedCompanyNumber->IsValid); - $this->assertNotEmpty($validatedCompanyNumber->ValidationRules); + $this->assertNotNull($validatedCompanyNumber->CompanyNumber->CompanyNumber); + $this->assertNotNull($validatedCompanyNumber->CompanyNumber->CountryCode); + $this->assertTrue($validatedCompanyNumber->CompanyNumber->IsValid); + $this->assertNotEmpty($validatedCompanyNumber->CompanyNumber->ValidationRules); } } From 628b1f3f3b1f899c362be3129434587b0a8c3a17 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Tue, 13 Feb 2024 09:53:08 +0200 Subject: [PATCH 3/3] lint fix --- MangoPay/ApiInstantConversion.php | 15 +++++++++------ MangoPay/CompanyNumber.php | 3 +-- MangoPay/CompanyNumberDetails.php | 2 +- MangoPay/ConversionRate.php | 2 +- MangoPay/InstantConversion.php | 2 +- MangoPay/PayInPaymentDetailsGiropay.php | 2 +- MangoPay/PayInPaymentDetailsIdeal.php | 2 +- tests/Cases/InstantConversionTest.php | 5 +++-- tests/Cases/UsersTest.php | 3 ++- 9 files changed, 20 insertions(+), 16 deletions(-) diff --git a/MangoPay/ApiInstantConversion.php b/MangoPay/ApiInstantConversion.php index 4bef5b6b..b0263635 100644 --- a/MangoPay/ApiInstantConversion.php +++ b/MangoPay/ApiInstantConversion.php @@ -15,16 +15,18 @@ class ApiInstantConversion extends Libraries\ApiBase * @param string $creditedCurrency The buy currency – the currency of the wallet to be credited. * @return \MangoPay\ConversionRate object returned from API */ - public function GetConversionRate($debitedCurrency, $creditedCurrency){ - return $this->GetObject('get_conversion_rate', '\MangoPay\ConversionRate', $debitedCurrency, $creditedCurrency); - } + public function GetConversionRate($debitedCurrency, $creditedCurrency) + { + return $this->GetObject('get_conversion_rate', '\MangoPay\ConversionRate', $debitedCurrency, $creditedCurrency); + } /** * This endpoint allows the platform to move funds between two * wallets of different currencies instantaneously. * @return \MangoPay\InstantConversion object returned from API */ - public function CreateInstantConversion($instantConversion){ + public function CreateInstantConversion($instantConversion) + { return $this->CreateObject('create_instant_conversion', $instantConversion, '\MangoPay\InstantConversion'); } @@ -34,7 +36,8 @@ public function CreateInstantConversion($instantConversion){ * @param string $id The unique identifier of the conversion. * @return \MangoPay\InstantConversion object returned from API */ - public function GetInstantConversion($id){ + public function GetInstantConversion($id) + { return $this->GetObject('get_instant_conversion', '\MangoPay\InstantConversion', $id); } -} \ No newline at end of file +} diff --git a/MangoPay/CompanyNumber.php b/MangoPay/CompanyNumber.php index f6bdf859..ce515202 100644 --- a/MangoPay/CompanyNumber.php +++ b/MangoPay/CompanyNumber.php @@ -26,5 +26,4 @@ class CompanyNumber extends Libraries\EntityBase * @var array */ public $ValidationRules; - -} \ No newline at end of file +} diff --git a/MangoPay/CompanyNumberDetails.php b/MangoPay/CompanyNumberDetails.php index d5a50826..22fe130b 100644 --- a/MangoPay/CompanyNumberDetails.php +++ b/MangoPay/CompanyNumberDetails.php @@ -9,4 +9,4 @@ class CompanyNumberDetails extends Libraries\EntityBase * @var object */ public $CompanyNumber; -} \ No newline at end of file +} diff --git a/MangoPay/ConversionRate.php b/MangoPay/ConversionRate.php index f667d1db..4963a74a 100644 --- a/MangoPay/ConversionRate.php +++ b/MangoPay/ConversionRate.php @@ -31,4 +31,4 @@ class ConversionRate extends Libraries\EntityBase * @var string */ public $MarketRate; -} \ No newline at end of file +} diff --git a/MangoPay/InstantConversion.php b/MangoPay/InstantConversion.php index 4b07e447..781b78c2 100644 --- a/MangoPay/InstantConversion.php +++ b/MangoPay/InstantConversion.php @@ -83,4 +83,4 @@ class InstantConversion extends Libraries\EntityBase * @var int */ public $ExecutionDate; -} \ No newline at end of file +} diff --git a/MangoPay/PayInPaymentDetailsGiropay.php b/MangoPay/PayInPaymentDetailsGiropay.php index 97ec8878..22faccf1 100644 --- a/MangoPay/PayInPaymentDetailsGiropay.php +++ b/MangoPay/PayInPaymentDetailsGiropay.php @@ -13,4 +13,4 @@ class PayInPaymentDetailsGiropay extends Libraries\Dto implements PayInPaymentDe * @var string */ public $StatementDescriptor; -} \ No newline at end of file +} diff --git a/MangoPay/PayInPaymentDetailsIdeal.php b/MangoPay/PayInPaymentDetailsIdeal.php index 0712feda..aed8b494 100644 --- a/MangoPay/PayInPaymentDetailsIdeal.php +++ b/MangoPay/PayInPaymentDetailsIdeal.php @@ -26,4 +26,4 @@ class PayInPaymentDetailsIdeal extends Libraries\Dto implements PayInPaymentDeta * @var string */ public $StatementDescriptor; -} \ No newline at end of file +} diff --git a/tests/Cases/InstantConversionTest.php b/tests/Cases/InstantConversionTest.php index 8bfdfbdb..78638a95 100644 --- a/tests/Cases/InstantConversionTest.php +++ b/tests/Cases/InstantConversionTest.php @@ -40,7 +40,8 @@ public function test_getInstantConversion() $this->assertSame(TransactionType::Conversion, $returnedInstantConversion->Type); } - private function createInstantConversion() { + private function createInstantConversion() + { $john = $this->getJohn(); $creditedWallet = new \MangoPay\Wallet(); $creditedWallet->Owners = [$john->Id]; @@ -69,4 +70,4 @@ private function createInstantConversion() { return $this->_api->InstantConversion->CreateInstantConversion($instantConversion); } -} \ No newline at end of file +} diff --git a/tests/Cases/UsersTest.php b/tests/Cases/UsersTest.php index d4a61ad4..a819f7e2 100644 --- a/tests/Cases/UsersTest.php +++ b/tests/Cases/UsersTest.php @@ -770,7 +770,8 @@ public function test_user_natural_terms_and_conditions() $this->assertNotNull($accepted->TermsAndConditionsAcceptedDate); } - public function test_validate_the_format_of_user_data(){ + public function test_validate_the_format_of_user_data() + { $companyNumberDetails = new \MangoPay\CompanyNumberDetails(); $companyNumber = new \MangoPay\CompanyNumber(); $companyNumber->CompanyNumber = 'AB123456';