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..52cc790d --- /dev/null +++ b/MangoPay/ApiVirtualAccounts.php @@ -0,0 +1,56 @@ +CreateObject('virtual_account_create', $virtualAccount, '\MangoPay\VirtualAccount', $walletId, $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, $pagination = null, $sorting = null) + { + return $this->GetList('virtual_account_get_all', $pagination, '\MangoPay\VirtualAccount', $walletId, $sorting); + } + + /** + * @param string $walletId + * @param string $virtualAccountId + * @return \MangoPay\VirtualAccount + */ + public function Deactivate($walletId, $virtualAccountId) + { + $empty_object = new VirtualAccount(); + return $this->SaveObject('virtual_account_deactivate', $empty_object, '\MangoPay\VirtualAccount', $walletId, $virtualAccountId); + } + + /** + * @return \MangoPay\VirtualAccountAvailabilities + */ + public function GetAvailabilities() + { + return $this->GetObject('virtual_account_get_availabilities', '\MangoPay\VirtualAccountAvailabilities'); + } +} diff --git a/MangoPay/InternationalAccount.php b/MangoPay/InternationalAccount.php new file mode 100644 index 00000000..d1f1f39f --- /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_account_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..d9ed4a24 --- /dev/null +++ b/MangoPay/LocalAccount.php @@ -0,0 +1,18 @@ +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/VirtualAccount.php b/MangoPay/VirtualAccount.php new file mode 100644 index 00000000..2a9c125f --- /dev/null +++ b/MangoPay/VirtualAccount.php @@ -0,0 +1,76 @@ +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 new file mode 100644 index 00000000..43eacb8b --- /dev/null +++ b/tests/Cases/VirtualAccountsTest.php @@ -0,0 +1,67 @@ +getNewVirtualAccount(); + $wallet = $this -> getJohnsWallet(); + + $this->assertNotNull($virtualAccount); + $this->assertEquals($virtualAccount->WalletId, $wallet->Id); + } + + public function test_VirtualAccount_Get() + { + $virtualAccount = $this->getNewVirtualAccount(); + $wallet = $this -> getJohnsWallet(); + $fetchedVirtualAccount = $this->_api->VirtualAccounts->Get($wallet->Id, $virtualAccount->Id); + + $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() + { + $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() + { + $virtualAccount = $this->getNewVirtualAccount(); + $wallet = $this->getJohnsWallet(); + $deactivatedVirtualAccount = $this->_api->VirtualAccounts->Deactivate($wallet->Id, $virtualAccount->Id); + + $this->assertNotTrue($deactivatedVirtualAccount->Active); + $this->assertEquals('CLOSED', $deactivatedVirtualAccount->Status); + } +}