From 7cfb74c88b6d70ad4486297fe68e93a89ccc4cea Mon Sep 17 00:00:00 2001 From: alexandrumatei Date: Tue, 22 Oct 2024 20:30:12 +0300 Subject: [PATCH 1/5] Adds VirtualAccount Object, ApiService and Create, Get, GetAll Endpoints --- MangoPay/ApiUsers.php | 2 +- MangoPay/ApiVirtualAccounts.php | 44 +++++++++++++ MangoPay/InternationalAccount.php | 16 +++++ MangoPay/InternationalAccountDetails.php | 18 ++++++ MangoPay/Libraries/ApiBase.php | 7 +++ MangoPay/LocalAccount.php | 16 +++++ MangoPay/LocalAccountDetails.php | 18 ++++++ MangoPay/VirtualAccount.php | 78 ++++++++++++++++++++++++ MangoPay/VirtualAccountAddress.php | 32 ++++++++++ MangoPay/VirtualAccountCapabilities.php | 24 ++++++++ MangoPay/VirtualAccountOwner.php | 9 +++ MangoPay/VirtualAccountPurpose.php | 9 +++ MangoPay/VirtualAccountStatus.php | 15 +++++ 13 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 MangoPay/ApiVirtualAccounts.php create mode 100644 MangoPay/InternationalAccount.php create mode 100644 MangoPay/InternationalAccountDetails.php create mode 100644 MangoPay/LocalAccount.php create mode 100644 MangoPay/LocalAccountDetails.php create mode 100644 MangoPay/VirtualAccount.php create mode 100644 MangoPay/VirtualAccountAddress.php create mode 100644 MangoPay/VirtualAccountCapabilities.php create mode 100644 MangoPay/VirtualAccountOwner.php create mode 100644 MangoPay/VirtualAccountPurpose.php create mode 100644 MangoPay/VirtualAccountStatus.php diff --git a/MangoPay/ApiUsers.php b/MangoPay/ApiUsers.php index dab35f49..bf96bb32 100644 --- a/MangoPay/ApiUsers.php +++ b/MangoPay/ApiUsers.php @@ -337,7 +337,7 @@ public function CreateKycPageFromFile($userId, $kycDocumentId, $filePath, $idemp * @param string $userId User Id * @param $year * @param $month - * @return \MangoPay\EMoney EMoney obhect returned from API + * @return \MangoPay\EMoney EMoney object returned from API * @throws Libraries\Exception */ public function GetEMoney($userId, $year = null, $month = null) diff --git a/MangoPay/ApiVirtualAccounts.php b/MangoPay/ApiVirtualAccounts.php new file mode 100644 index 00000000..59355c7d --- /dev/null +++ b/MangoPay/ApiVirtualAccounts.php @@ -0,0 +1,44 @@ +CreateObject('virtual_account_create', $walletId, '\MangoPay\VirtualAccount', null, null, $idempotencyKey); + } + + /** + * @param string $walletId + * @param string $virtualAccountId + * @return \MangoPay\VirtualAccount + */ + public function Get($walletId, $virtualAccountId) + { + return $this->GetObject('virtual_account_get', '\MangoPay\VirtualAccount', $walletId, $virtualAccountId); + } + + /** + * @param \MangoPay\Pagination $pagination Pagination object + * @param string $walletId + * @return \MangoPay\VirtualAccount[] + */ + public function GetAll($walletId) + { + return $this->GetList('virtual_account_get_all', $pagination, '\MangoPay\VirtualAccount', $walletId); + } + + public function Deactivate($walletId, $idempotencyKey = null) + { + } + + public function GetAvailabilities($walletId, $idempotencyKey = null) + { + } +} \ No newline at end of file diff --git a/MangoPay/InternationalAccount.php b/MangoPay/InternationalAccount.php new file mode 100644 index 00000000..cf18cfab --- /dev/null +++ b/MangoPay/InternationalAccount.php @@ -0,0 +1,16 @@ + ['/conversions/%s', RequestType::GET], 'create_conversion_quote' => ['/conversions/quote', RequestType::POST], 'get_conversion_quote' => ['/conversions/quote/%s', RequestType::GET], + + 'virtual_account_create' => ['/wallets/%s/virtual-accounts', RequestType::POST], + 'virtual_account_deactivate' => ['/wallets/%s/virtual-accounts/%s', RequestType::PUT], + 'virtual_account_get' => ['/wallets/%s/virtual-accounts/%s', RequestType::GET], + 'virtual_account_get_all' => ['/wallets/%s/virtual-accounts', RequestType::GET], + 'virtual_account_get_availabilities' => ['/virtual-accounts/availability', RequestType::GET] ]; /** @@ -615,6 +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', 'kyc_documents_create' => '\MangoPay\KycDocument', 'kyc_page_create' => '', 'wallets_create' => '\MangoPay\Wallet', diff --git a/MangoPay/LocalAccount.php b/MangoPay/LocalAccount.php new file mode 100644 index 00000000..c8c03660 --- /dev/null +++ b/MangoPay/LocalAccount.php @@ -0,0 +1,16 @@ + Date: Tue, 29 Oct 2024 10:17:03 +0200 Subject: [PATCH 2/5] 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 From 374664fd08a90c523711688c1ce804a078938f2b Mon Sep 17 00:00:00 2001 From: alexandrumatei Date: Tue, 29 Oct 2024 13:48:05 +0200 Subject: [PATCH 3/5] Marks Availability classes as corresponding entities and implements GetSubObjects() method --- MangoPay/VirtualAccountAvailabilities.php | 16 +++++++++++++++- MangoPay/VirtualAccountAvailability.php | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/MangoPay/VirtualAccountAvailabilities.php b/MangoPay/VirtualAccountAvailabilities.php index f4a074c3..80da0195 100644 --- a/MangoPay/VirtualAccountAvailabilities.php +++ b/MangoPay/VirtualAccountAvailabilities.php @@ -2,7 +2,7 @@ namespace MangoPay; -class VirtualAccountAvailabilities +class VirtualAccountAvailabilities extends Libraries\EntityBase { /** * * @var VirtualAccountAvailability[] @@ -13,4 +13,18 @@ class VirtualAccountAvailabilities * * @var VirtualAccountAvailability[] */ public $UserOwned; + + /** + * Get array with mapping which property is object and what type of object + * @return array + */ + public function GetSubObjects() + { + $subObjects = parent::GetSubObjects(); + + $subObjects['Collection'] = '\MangoPay\VirtualAccountAvailability'; + $subObjects['UserOwned'] = '\MangoPay\VirtualAccountAvailability'; + + return $subObjects; + } } \ No newline at end of file diff --git a/MangoPay/VirtualAccountAvailability.php b/MangoPay/VirtualAccountAvailability.php index e4c42f7b..db2f7f2b 100644 --- a/MangoPay/VirtualAccountAvailability.php +++ b/MangoPay/VirtualAccountAvailability.php @@ -2,7 +2,7 @@ namespace MangoPay; -class VirtualAccountAvailability +class VirtualAccountAvailability extends Libraries\EntityBase { /** * ISO 3166-1 alpha-2 format is expected @@ -21,4 +21,17 @@ class VirtualAccountAvailability * @var CurrencyIso[] * */ public $Currencies; + + /** + * Get array with mapping which property is object and what type of object + * @return array + */ + public function GetSubObjects() + { + $subObjects = parent::GetSubObjects(); + + $subObjects['Currencies'] = '\MangoPay\CurrencyIso'; + + return $subObjects; + } } \ No newline at end of file From a4a3d22c522aed13bca9ac56c5c1d0afce47d926 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Wed, 30 Oct 2024 20:00:12 +0200 Subject: [PATCH 4/5] updated tests and models --- MangoPay/ApiVirtualAccounts.php | 9 ++++--- MangoPay/InternationalAccount.php | 4 +-- MangoPay/InternationalAccountDetails.php | 4 +-- MangoPay/LocalAccount.php | 6 +++-- MangoPay/LocalAccountDetails.php | 4 +-- MangoPay/VirtualAccount.php | 4 +-- MangoPay/VirtualAccountAddress.php | 3 +-- MangoPay/VirtualAccountAvailabilities.php | 18 ++----------- MangoPay/VirtualAccountAvailability.php | 15 +---------- MangoPay/VirtualAccountCapabilities.php | 8 +++--- MangoPay/VirtualAccountOwner.php | 2 +- MangoPay/VirtualAccountPurpose.php | 2 +- tests/Cases/Base.php | 17 ++++++++++++ tests/Cases/VirtualAccountsTest.php | 32 +++++++++++------------ 14 files changed, 58 insertions(+), 70 deletions(-) diff --git a/MangoPay/ApiVirtualAccounts.php b/MangoPay/ApiVirtualAccounts.php index a64eae3a..a6f5e01d 100644 --- a/MangoPay/ApiVirtualAccounts.php +++ b/MangoPay/ApiVirtualAccounts.php @@ -40,9 +40,10 @@ public function GetAll($walletId, $pagination = null, $sorting = null) * @param string $virtualAccountId * @return \MangoPay\VirtualAccount */ - public function Deactivate($virtualAccount, $walletId, $virtualAccountId) + public function Deactivate($walletId, $virtualAccountId) { - return $this->SaveObject('virtual_account_deactivate', $virtualAccount, '\MangoPay\VirtualAccount', $walletId, $virtualAccountId); + $empty_object = ""; + return $this->SaveObject('virtual_account_deactivate', $empty_object, '\MangoPay\VirtualAccount', $walletId, $virtualAccountId); } /** @@ -50,6 +51,6 @@ public function Deactivate($virtualAccount, $walletId, $virtualAccountId) */ public function GetAvailabilities() { - return $this->GetObject('virtual_account_get_availabilities','\MangoPay\VirtualAccountAvailabilities'); + return $this->GetObject('virtual_account_get_availabilities', '\MangoPay\VirtualAccountAvailabilities'); } -} \ No newline at end of file +} diff --git a/MangoPay/InternationalAccount.php b/MangoPay/InternationalAccount.php index cf18cfab..d1f1f39f 100644 --- a/MangoPay/InternationalAccount.php +++ b/MangoPay/InternationalAccount.php @@ -2,7 +2,7 @@ namespace MangoPay; -class InternationalAccount +class InternationalAccount extends Libraries\Dto { /** * @var string @@ -13,4 +13,4 @@ class InternationalAccount * @var string */ public $Bic; -} \ No newline at end of file +} diff --git a/MangoPay/InternationalAccountDetails.php b/MangoPay/InternationalAccountDetails.php index 168dd40a..f0951ff8 100644 --- a/MangoPay/InternationalAccountDetails.php +++ b/MangoPay/InternationalAccountDetails.php @@ -2,7 +2,7 @@ namespace MangoPay; -class InternationalAccountDetails +class InternationalAccountDetails extends Libraries\Dto { /** * Information about the address associated with the international IBAN account. @@ -15,4 +15,4 @@ class InternationalAccountDetails * @var InternationalAccount */ public $Account; -} \ No newline at end of file +} diff --git a/MangoPay/LocalAccount.php b/MangoPay/LocalAccount.php index c8c03660..d9ed4a24 100644 --- a/MangoPay/LocalAccount.php +++ b/MangoPay/LocalAccount.php @@ -2,15 +2,17 @@ namespace MangoPay; -class LocalAccount +class LocalAccount extends Libraries\Dto { /** * The account number of the account + * @var string */ public $AccountNumber; /** * The sort code of the account. + * @var string */ public $SortCode; -} \ No newline at end of file +} diff --git a/MangoPay/LocalAccountDetails.php b/MangoPay/LocalAccountDetails.php index 55d066a0..e0e51611 100644 --- a/MangoPay/LocalAccountDetails.php +++ b/MangoPay/LocalAccountDetails.php @@ -2,7 +2,7 @@ namespace MangoPay; -class LocalAccountDetails +class LocalAccountDetails extends Libraries\Dto { /** * Information about the address associated with the local IBAN account. @@ -15,4 +15,4 @@ class LocalAccountDetails * @var LocalAccount */ public $Account; -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccount.php b/MangoPay/VirtualAccount.php index f84f9e18..2a9c125f 100644 --- a/MangoPay/VirtualAccount.php +++ b/MangoPay/VirtualAccount.php @@ -73,6 +73,4 @@ class VirtualAccount extends Libraries\EntityBase * @var \MangoPay\VirtualAccountCapabilities */ public $Capabilities; - - -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountAddress.php b/MangoPay/VirtualAccountAddress.php index 91e8a06e..b409e31e 100644 --- a/MangoPay/VirtualAccountAddress.php +++ b/MangoPay/VirtualAccountAddress.php @@ -28,5 +28,4 @@ class VirtualAccountAddress extends Libraries\Dto * @var string */ public $Country; - -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountAvailabilities.php b/MangoPay/VirtualAccountAvailabilities.php index 80da0195..60bb2b74 100644 --- a/MangoPay/VirtualAccountAvailabilities.php +++ b/MangoPay/VirtualAccountAvailabilities.php @@ -2,7 +2,7 @@ namespace MangoPay; -class VirtualAccountAvailabilities extends Libraries\EntityBase +class VirtualAccountAvailabilities extends Libraries\Dto { /** * * @var VirtualAccountAvailability[] @@ -13,18 +13,4 @@ class VirtualAccountAvailabilities extends Libraries\EntityBase * * @var VirtualAccountAvailability[] */ public $UserOwned; - - /** - * Get array with mapping which property is object and what type of object - * @return array - */ - public function GetSubObjects() - { - $subObjects = parent::GetSubObjects(); - - $subObjects['Collection'] = '\MangoPay\VirtualAccountAvailability'; - $subObjects['UserOwned'] = '\MangoPay\VirtualAccountAvailability'; - - return $subObjects; - } -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountAvailability.php b/MangoPay/VirtualAccountAvailability.php index db2f7f2b..667871a5 100644 --- a/MangoPay/VirtualAccountAvailability.php +++ b/MangoPay/VirtualAccountAvailability.php @@ -21,17 +21,4 @@ class VirtualAccountAvailability extends Libraries\EntityBase * @var CurrencyIso[] * */ public $Currencies; - - /** - * Get array with mapping which property is object and what type of object - * @return array - */ - public function GetSubObjects() - { - $subObjects = parent::GetSubObjects(); - - $subObjects['Currencies'] = '\MangoPay\CurrencyIso'; - - return $subObjects; - } -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountCapabilities.php b/MangoPay/VirtualAccountCapabilities.php index f0835a0c..bc34ec8c 100644 --- a/MangoPay/VirtualAccountCapabilities.php +++ b/MangoPay/VirtualAccountCapabilities.php @@ -2,17 +2,17 @@ namespace MangoPay; -class VirtualAccountCapabilities +class VirtualAccountCapabilities extends Libraries\Dto { /** * Whether local bank wires can be made to this account. - * @var Boolean + * @var bool */ public $LocalPayInAvailable; /** * Whether international bank wires can be made to this account - * @var Boolean + * @var bool */ public $InternationalPayInAvailable; @@ -21,4 +21,4 @@ class VirtualAccountCapabilities * @var CurrencyIso[] */ public $Currencies; -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountOwner.php b/MangoPay/VirtualAccountOwner.php index 1a6f673f..3c8d7de5 100644 --- a/MangoPay/VirtualAccountOwner.php +++ b/MangoPay/VirtualAccountOwner.php @@ -6,4 +6,4 @@ class VirtualAccountOwner { const Collection = "COLLECTION"; const UserOwned = "USER_OWNED"; -} \ No newline at end of file +} diff --git a/MangoPay/VirtualAccountPurpose.php b/MangoPay/VirtualAccountPurpose.php index b952a235..b53cf3fe 100644 --- a/MangoPay/VirtualAccountPurpose.php +++ b/MangoPay/VirtualAccountPurpose.php @@ -6,4 +6,4 @@ class VirtualAccountPurpose { const Collection = "COLLECTION"; const UserOwned = "USER_OWNED"; -} \ No newline at end of file +} diff --git a/tests/Cases/Base.php b/tests/Cases/Base.php index 976b4f36..cecf46bb 100644 --- a/tests/Cases/Base.php +++ b/tests/Cases/Base.php @@ -14,6 +14,7 @@ use MangoPay\ShippingPreference; use MangoPay\Tests\Mocks\MockStorageStrategy; use MangoPay\Ubo; +use MangoPay\VirtualAccount; use PHPUnit\Framework\TestCase; set_time_limit(0); @@ -52,6 +53,7 @@ abstract class Base extends TestCase * @var \MangoPay\Wallet */ public static $JohnsWallet; + public static $johnsVirtualAccount; /** * Test Kyc Document belonging to John * @var \MangoPay\KycDocument @@ -259,6 +261,21 @@ protected function getJohnsWallet() return self::$JohnsWallet; } + protected function getNewVirtualAccount() + { + if (self::$johnsVirtualAccount === null) { + $wallet = $this->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); + } + + return self::$johnsVirtualAccount; + } + /** * Creates Pay-In Card Web object * @return \MangoPay\PayIn diff --git a/tests/Cases/VirtualAccountsTest.php b/tests/Cases/VirtualAccountsTest.php index ad33f94a..43eacb8b 100644 --- a/tests/Cases/VirtualAccountsTest.php +++ b/tests/Cases/VirtualAccountsTest.php @@ -17,36 +17,33 @@ class VirtualAccountsTest extends Base public static $johnsVirtualAccount; public function test_VirtualAccount_Create() { - $wallet = $this->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); + $virtualAccount = $this->getNewVirtualAccount(); + $wallet = $this -> getJohnsWallet(); - $this->assertNotNull(self::$johnsVirtualAccount); - $this->assertEquals(self::$johnsVirtualAccount->WalletId, $wallet->Id); + $this->assertNotNull($virtualAccount); + $this->assertEquals($virtualAccount->WalletId, $wallet->Id); } public function test_VirtualAccount_Get() { - $wallet = $this->getJohnsWallet(); + $virtualAccount = $this->getNewVirtualAccount(); + $wallet = $this -> getJohnsWallet(); + $fetchedVirtualAccount = $this->_api->VirtualAccounts->Get($wallet->Id, $virtualAccount->Id); - $virtualAccounts = $this->_api->VirtualAccounts->GetAll($wallet->Id); - - $this->assertNotNull($virtualAccounts); - $this->assertTrue(is_array($virtualAccounts), 'Expected an array'); + $this->assertNotNull($fetchedVirtualAccount); + $this->assertEquals($fetchedVirtualAccount->Id, $virtualAccount->Id); } public function test_VirtualAccount_GetAll() { + $this->getNewVirtualAccount(); $wallet = $this->getJohnsWallet(); $virtualAccounts = $this->_api->VirtualAccounts->GetAll($wallet->Id); $this->assertNotNull($virtualAccounts); $this->assertTrue(is_array($virtualAccounts), 'Expected an array'); + $this->assertEquals(1, sizeof($virtualAccounts)); } public function test_VirtualAccount_Get_Availabilities() @@ -60,10 +57,11 @@ public function test_VirtualAccount_Get_Availabilities() public function test_VirtualAccount_Deactivate() { + $virtualAccount = $this->getNewVirtualAccount(); $wallet = $this->getJohnsWallet(); - self::$johnsVirtualAccount->Active = false; - $deactivatedVirtualAccount = $this->_api->VirtualAccounts->Deactivate(self::$johnsVirtualAccount, $wallet->Id, self::$johnsVirtualAccount->Id); + $deactivatedVirtualAccount = $this->_api->VirtualAccounts->Deactivate($wallet->Id, $virtualAccount->Id); $this->assertNotTrue($deactivatedVirtualAccount->Active); + $this->assertEquals('CLOSED', $deactivatedVirtualAccount->Status); } -} \ No newline at end of file +} From 7e0f8a44a8ac49ca594f60e4be3cab455f281347 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Wed, 30 Oct 2024 20:07:53 +0200 Subject: [PATCH 5/5] fixed test --- MangoPay/ApiVirtualAccounts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MangoPay/ApiVirtualAccounts.php b/MangoPay/ApiVirtualAccounts.php index a6f5e01d..52cc790d 100644 --- a/MangoPay/ApiVirtualAccounts.php +++ b/MangoPay/ApiVirtualAccounts.php @@ -42,7 +42,7 @@ public function GetAll($walletId, $pagination = null, $sorting = null) */ public function Deactivate($walletId, $virtualAccountId) { - $empty_object = ""; + $empty_object = new VirtualAccount(); return $this->SaveObject('virtual_account_deactivate', $empty_object, '\MangoPay\VirtualAccount', $walletId, $virtualAccountId); }