From 5b065f2f0a51fd20087fce28b96d50035e4d2dbe Mon Sep 17 00:00:00 2001 From: alexandrumatei Date: Tue, 29 Oct 2024 10:17:03 +0200 Subject: [PATCH] Adds tests and fixes issues in ApiMethods --- MangoPay/ApiVirtualAccounts.php | 25 +++++--- MangoPay/Libraries/ApiBase.php | 2 +- MangoPay/MangoPayApi.php | 6 ++ MangoPay/VirtualAccountAddress.php | 2 +- MangoPay/VirtualAccountAvailabilities.php | 16 ++++++ MangoPay/VirtualAccountAvailability.php | 24 ++++++++ tests/Cases/VirtualAccountsTest.php | 69 +++++++++++++++++++++++ 7 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 MangoPay/VirtualAccountAvailabilities.php create mode 100644 MangoPay/VirtualAccountAvailability.php create mode 100644 tests/Cases/VirtualAccountsTest.php diff --git a/MangoPay/ApiVirtualAccounts.php b/MangoPay/ApiVirtualAccounts.php index 59355c7d..a64eae3a 100644 --- a/MangoPay/ApiVirtualAccounts.php +++ b/MangoPay/ApiVirtualAccounts.php @@ -7,11 +7,12 @@ class ApiVirtualAccounts extends Libraries\ApiBase /** * Create new Virtual Account * @param String $walletId - * @return \MangoPay\VirtualAccount Wallet object returned from API + * @param VirtualAccount $virtualAccount + * @return \MangoPay\VirtualAccount Virtual Account object returned from API */ - public function Create($walletId, $idempotencyKey = null) + public function Create($virtualAccount, $walletId, $idempotencyKey = null) { - return $this->CreateObject('virtual_account_create', $walletId, '\MangoPay\VirtualAccount', null, null, $idempotencyKey); + return $this->CreateObject('virtual_account_create', $virtualAccount, '\MangoPay\VirtualAccount', $walletId, $idempotencyKey); } /** @@ -29,16 +30,26 @@ public function Get($walletId, $virtualAccountId) * @param string $walletId * @return \MangoPay\VirtualAccount[] */ - public function GetAll($walletId) + public function GetAll($walletId, $pagination = null, $sorting = null) { - return $this->GetList('virtual_account_get_all', $pagination, '\MangoPay\VirtualAccount', $walletId); + return $this->GetList('virtual_account_get_all', $pagination, '\MangoPay\VirtualAccount', $walletId, $sorting); } - public function Deactivate($walletId, $idempotencyKey = null) + /** + * @param string $walletId + * @param string $virtualAccountId + * @return \MangoPay\VirtualAccount + */ + public function Deactivate($virtualAccount, $walletId, $virtualAccountId) { + return $this->SaveObject('virtual_account_deactivate', $virtualAccount, '\MangoPay\VirtualAccount', $walletId, $virtualAccountId); } - public function GetAvailabilities($walletId, $idempotencyKey = null) + /** + * @return \MangoPay\VirtualAccountAvailabilities + */ + public function GetAvailabilities() { + return $this->GetObject('virtual_account_get_availabilities','\MangoPay\VirtualAccountAvailabilities'); } } \ No newline at end of file diff --git a/MangoPay/Libraries/ApiBase.php b/MangoPay/Libraries/ApiBase.php index 77389e64..8e848897 100644 --- a/MangoPay/Libraries/ApiBase.php +++ b/MangoPay/Libraries/ApiBase.php @@ -621,7 +621,7 @@ protected function GetObjectForIdempotencyUrl($url) 'users_createbankaccounts_us' => '\MangoPay\BankAccount', 'users_createbankaccounts_ca' => '\MangoPay\BankAccount', 'users_createbankaccounts_other' => '\MangoPay\BankAccount', - 'virtual_accounts_create' => '\MangoPay\VirtualAccount', + 'virtual_account_create' => '\MangoPay\VirtualAccount', 'kyc_documents_create' => '\MangoPay\KycDocument', 'kyc_page_create' => '', 'wallets_create' => '\MangoPay\Wallet', diff --git a/MangoPay/MangoPayApi.php b/MangoPay/MangoPayApi.php index d2f588ec..0d78b9c4 100644 --- a/MangoPay/MangoPayApi.php +++ b/MangoPay/MangoPayApi.php @@ -169,6 +169,11 @@ class MangoPayApi */ public $Repudiations; + /** + * Provides VirtualAccount methods + * @var ApiVirtualAccounts + */ + public $VirtualAccounts; /** * @var LoggerInterface @@ -240,6 +245,7 @@ public function __construct() $this->Regulatory = new ApiRegulatory($this); $this->Deposits = new ApiDeposits($this); $this->Conversions = new ApiConversions($this); + $this->VirtualAccounts = new ApiVirtualAccounts($this); // Setting default NullLogger $this->logger = new NullLogger(); diff --git a/MangoPay/VirtualAccountAddress.php b/MangoPay/VirtualAccountAddress.php index bf12a92a..91e8a06e 100644 --- a/MangoPay/VirtualAccountAddress.php +++ b/MangoPay/VirtualAccountAddress.php @@ -2,7 +2,7 @@ namespace MangoPay; -class VirtualAccountAddress +class VirtualAccountAddress extends Libraries\Dto { /** * @var string diff --git a/MangoPay/VirtualAccountAvailabilities.php b/MangoPay/VirtualAccountAvailabilities.php new file mode 100644 index 00000000..f4a074c3 --- /dev/null +++ b/MangoPay/VirtualAccountAvailabilities.php @@ -0,0 +1,16 @@ +getJohnsWallet(); + $virtualAccount = new VirtualAccount(); + $virtualAccount->Country = "FR"; + $virtualAccount->VirtualAccountPurpose = "Collection"; + $virtualAccount->Tag = "create virtual account tag"; + + self::$johnsVirtualAccount = $this->_api->VirtualAccounts->Create($virtualAccount, $wallet->Id); + + $this->assertNotNull(self::$johnsVirtualAccount); + $this->assertEquals(self::$johnsVirtualAccount->WalletId, $wallet->Id); + } + + public function test_VirtualAccount_Get() + { + $wallet = $this->getJohnsWallet(); + + $virtualAccounts = $this->_api->VirtualAccounts->GetAll($wallet->Id); + + $this->assertNotNull($virtualAccounts); + $this->assertTrue(is_array($virtualAccounts), 'Expected an array'); + } + + public function test_VirtualAccount_GetAll() + { + $wallet = $this->getJohnsWallet(); + + $virtualAccounts = $this->_api->VirtualAccounts->GetAll($wallet->Id); + + $this->assertNotNull($virtualAccounts); + $this->assertTrue(is_array($virtualAccounts), 'Expected an array'); + } + + public function test_VirtualAccount_Get_Availabilities() + { + $virtualAccountAvailabilities = $this->_api->VirtualAccounts->GetAvailabilities(); + + $this->assertNotNull($virtualAccountAvailabilities); + $this->assertTrue(is_array($virtualAccountAvailabilities->Collection), 'Expected an array'); + $this->assertTrue(is_array($virtualAccountAvailabilities->UserOwned), 'Expected an array'); + } + + public function test_VirtualAccount_Deactivate() + { + $wallet = $this->getJohnsWallet(); + self::$johnsVirtualAccount->Active = false; + $deactivatedVirtualAccount = $this->_api->VirtualAccounts->Deactivate(self::$johnsVirtualAccount, $wallet->Id, self::$johnsVirtualAccount->Id); + + $this->assertNotTrue($deactivatedVirtualAccount->Active); + } +} \ No newline at end of file