Skip to content

Commit

Permalink
Adds tests and fixes issues in ApiMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
alexxmattei committed Oct 29, 2024
1 parent 7cfb74c commit 5b065f2
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 9 deletions.
25 changes: 18 additions & 7 deletions MangoPay/ApiVirtualAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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');
}
}
2 changes: 1 addition & 1 deletion MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions MangoPay/MangoPayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ class MangoPayApi
*/
public $Repudiations;

/**
* Provides VirtualAccount methods
* @var ApiVirtualAccounts
*/
public $VirtualAccounts;

/**
* @var LoggerInterface
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion MangoPay/VirtualAccountAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MangoPay;

class VirtualAccountAddress
class VirtualAccountAddress extends Libraries\Dto
{
/**
* @var string
Expand Down
16 changes: 16 additions & 0 deletions MangoPay/VirtualAccountAvailabilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace MangoPay;

class VirtualAccountAvailabilities
{
/**
* * @var VirtualAccountAvailability[]
*/
public $Collection;

/**
* * @var VirtualAccountAvailability[]
*/
public $UserOwned;
}
24 changes: 24 additions & 0 deletions MangoPay/VirtualAccountAvailability.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace MangoPay;

class VirtualAccountAvailability
{
/**
* ISO 3166-1 alpha-2 format is expected
* * @var string
*/
public $Country;

/**
* Whether international bank wires can be made to this account
* @var Boolean
*/
public $Available;

/**
* List of currencies supported by the account
* @var CurrencyIso[]
* */
public $Currencies;
}
69 changes: 69 additions & 0 deletions tests/Cases/VirtualAccountsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace MangoPay\Tests\Cases;

use MangoPay\VirtualAccount;
use MangoPay\Wallet;
use function PHPUnit\Framework\assertNotTrue;

/**
* Tests basic methods for Virtual Accounts
*/
class VirtualAccountsTest extends Base
{
/**
* @var \MangoPay\VirtualAccount
*/
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);

$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);
}
}

0 comments on commit 5b065f2

Please sign in to comment.