Skip to content

Commit

Permalink
Merge branch 'master' into fix/php-related-issues
Browse files Browse the repository at this point in the history
# Conflicts:
#	MangoPay/Libraries/ApiBase.php
  • Loading branch information
mralaminahamed committed Dec 4, 2024
2 parents 0268830 + 6c9b625 commit beac573
Show file tree
Hide file tree
Showing 32 changed files with 546 additions and 15 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
## [3.32.2] - 2024-11-28
### Updated

Added all relevant `EVENT_TYPE_CHOICES` for virtual accounts:

- `VIRTUAL_ACCOUNT_ACTIVE`
- `VIRTUAL_ACCOUNT_BLOCKED`
- `VIRTUAL_ACCOUNT_CLOSED`
- `VIRTUAL_ACCOUNT_FAILED`

## [3.32.1] - 2024-11-12
### Fixed

- https://github.com/Mangopay/mangopay2-php-sdk/pull/643 Fixed PHP doc blocks.
- https://github.com/Mangopay/mangopay2-php-sdk/pull/654 Fixed idempotency response to return the error object.
- #656 Update `bankAccountId` parameter to accept alphanumerical IDs.

Thanks for you contribution [@williamdes](https://github.com/williamdes)

## [3.32.0] - 2024-10-30
### Added

New endpoints for The Virtual Account object:
- [Create a Virtual Account]()
- [Deactivate a Virtual Account]()
- [View a Virtual Account]()
- [List Virtual Accounts for a Wallet]()
- [View Client Availabilities]()

## [3.31.0] - 2024-07-30
### Added

Expand Down
2 changes: 1 addition & 1 deletion MangoPay/ApiCards.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function Update($card)
* Gets a Card's PreAuthorizations
* @param int $cardId ID of the Card for which to retrieve PreAuthorizations
* @param \MangoPay\Pagination $pagination Pagination object
* @param \MangoPay\FilterPreAuthorizations filter Filtering object
* @param \MangoPay\FilterPreAuthorizations $filter Filtering object
* @param \MangoPay\Sorting $sorting Sorting object
* @return \MangoPay\CardPreAuthorization[] List of the Card's PreAuthorizations
*/
Expand Down
3 changes: 2 additions & 1 deletion MangoPay/ApiClients.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public function Update($client)
* Upload a logo for client.
* Only GIF, PNG, JPG, JPEG, BMP, PDF and DOC formats are accepted,
* and file must be less than about 7MB
* @param \MangoPay\ClientLogoUpload $logo ClientLogoUpload object
* @param \MangoPay\ClientLogoUpload $logoUpload ClientLogoUpload object
* @param string|null $idempotencyKey
*/
public function UploadLogo($logoUpload, $idempotencyKey = null)
{
Expand Down
2 changes: 1 addition & 1 deletion MangoPay/ApiDisputes.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function GetPendingSettlements(& $pagination = null, $sorting = null)

/**
* Updates dispute's tag
* @param \MangoPay\Dispute Dispute object to update
* @param \MangoPay\Dispute $dispute Dispute object to update
* @return \MangoPay\Dispute Transfer instance returned from API
*/
public function Update($dispute)
Expand Down
2 changes: 1 addition & 1 deletion MangoPay/ApiPayOuts.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function GetBankwire($payOutId)
* Returns a list of Refunds pertaining to a certain PayOut.
* @param string $payOutId ID of the PayOut for which to retrieve Refunds
* @param \MangoPay\Pagination $pagination Pagination object
* @param \MangoPay\FilterRefunds filter Filtering object
* @param \MangoPay\FilterRefunds $filter Filtering object
* @param \MangoPay\Sorting $sorting Sorting object
* @return \MangoPay\Refund[] List of Refunds for the PayOut
*/
Expand Down
14 changes: 11 additions & 3 deletions MangoPay/ApiResponses.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ class ApiResponses extends Libraries\ApiBase
public function Get($idempotencyKey)
{
$response = $this->GetObject('responses_get', 'MangoPay\Response', $idempotencyKey);
$className = $this->GetObjectForIdempotencyUrl($response->RequestURL);
if (is_null($className) || empty($className) || is_null($response->Resource) || empty($response->Resource)) {

// Same logic as RestTool::CheckResponseCode
if ($response->StatusCode >= 200 && $response->StatusCode <= 299) {
// Target the class to use from the SDK
$className = $this->GetObjectForIdempotencyUrl($response->RequestURL);
if (is_null($className) || empty($className) || is_null($response->Resource) || empty($response->Resource)) {
return $response;
}

$response->Resource = $this->CastResponseToEntity($response->Resource, $className);
return $response;
}

$response->Resource = $this->CastResponseToEntity($response->Resource, $className);
$response->Resource = $this->CastResponseToError($response->Resource);
return $response;
}
}
4 changes: 2 additions & 2 deletions MangoPay/ApiUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function GetBankAccounts($userId, & $pagination = null, $sorting = null,
/**
* Get bank account for user
* @param string $userId User Id
* @param int $bankAccountId Bank account Id
* @param string $bankAccountId Bank account Id
*
* @return \MangoPay\BankAccount Entity of bank account object
*/
Expand Down Expand Up @@ -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)
Expand Down
56 changes: 56 additions & 0 deletions MangoPay/ApiVirtualAccounts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace MangoPay;

class ApiVirtualAccounts extends Libraries\ApiBase
{
/**
* Create new Virtual Account
* @param String $walletId
* @param VirtualAccount $virtualAccount
* @return \MangoPay\VirtualAccount Virtual Account object returned from API
*/
public function Create($virtualAccount, $walletId, $idempotencyKey = null)
{
return $this->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');
}
}
6 changes: 5 additions & 1 deletion MangoPay/BankingAliasOTHER.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@
class BankingAliasOTHER extends BankingAlias
{
/**
* @var Type
* Type
* @var string
*/
public $Type;

/**
* Account Number
* @var string
*/
public $AccountNumber;

/**
* BIC
* @var string
*/
public $BIC;

/**
* Country
* @var string
*/
public $Country;
}
4 changes: 4 additions & 0 deletions MangoPay/EventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ class EventType
const CardValidationCreated = "CARD_VALIDATION_CREATED";
const CardValidationFailed= "CARD_VALIDATION_FAILED";
const CardValidationSucceeded = "CARD_VALIDATION_SUCCEEDED";
const VirtualAccountActive = "VIRTUAL_ACCOUNT_ACTIVE";
const VirtualAccountBlocked = "VIRTUAL_ACCOUNT_BLOCKED";
const VirtualAccountClosed = "VIRTUAL_ACCOUNT_CLOSED";
const VirtualAccountFailed = "VIRTUAL_ACCOUNT_FAILED";
}
16 changes: 16 additions & 0 deletions MangoPay/InternationalAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace MangoPay;

class InternationalAccount extends Libraries\Dto
{
/**
* @var string
*/
public $Iban;

/**
* @var string
*/
public $Bic;
}
18 changes: 18 additions & 0 deletions MangoPay/InternationalAccountDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace MangoPay;

class InternationalAccountDetails extends Libraries\Dto
{
/**
* Information about the address associated with the international IBAN account.
* @var VirtualAccountAddress
*/
public $Address;

/**
* The IBAN and BIC of the account.
* @var InternationalAccount
*/
public $Account;
}
45 changes: 44 additions & 1 deletion MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,18 @@ protected function getLogger()
'get_conversion' => ['/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]
];

/**
* Constructor
* @param \MangoPay\MangoPayApi Root/parent instance that holds the OAuthToken and Configuration instance
* Root/parent instance that holds the OAuthToken and Configuration instance
* @param \MangoPay\MangoPayApi $root
*/
public function __construct($root)
{
Expand Down Expand Up @@ -430,6 +437,41 @@ protected function ExecutePostRequest($methodKey, $entity, $responseClassName, $
return $response;
}

/**
* Cast response object to an error object
* @param object $response Object from API response
* @return Error The error
*/
protected function CastResponseToError($response)
{
// This logic is similar to RestTool::CheckResponseCode
$error = new Error();

$map = [
'Message',
'Id',
'Type',
'Date',
'Errors',
];

foreach ($map as $val) {
$error->{$val} = property_exists($response, $val) ? $response->{$val} : null;
}

if (property_exists($response, 'errors')) {
$error->Errors = $response->errors;
}

if (is_array($error->Errors)) {
foreach ($error->Errors as $key => $val) {
$error->Message .= sprintf(' %s error: %s', $key, $val);
}
}

return $error;
}

/**
* Cast response object to entity object
* @param object $response Object from API response
Expand Down Expand Up @@ -615,6 +657,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',
Expand Down
3 changes: 2 additions & 1 deletion MangoPay/Libraries/AuthenticationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class AuthenticationHelper

/**
* Constructor
* @param \MangoPay\MangoPayApi Root/parent instance that holds the OAuth token and Configuration instance
* Root/parent instance that holds the OAuthToken and Configuration instance
* @param \MangoPay\MangoPayApi $root
*/
public function __construct($root)
{
Expand Down
2 changes: 1 addition & 1 deletion MangoPay/Libraries/RestTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class RestTool
{
const VERSION = '3.31.0';
const VERSION = '3.32.2';

/**
* Root/parent instance that holds the OAuthToken and Configuration instance
Expand Down
3 changes: 2 additions & 1 deletion MangoPay/Libraries/UrlTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class UrlTool

/**
* Constructor
* @param \MangoPay\MangoPayApi Root/parent instance that holds the OAuthToken and Configuration instance
* Root/parent instance that holds the OAuthToken and Configuration instance
* @param \MangoPay\MangoPayApi $root
*/
public function __construct($root)
{
Expand Down
18 changes: 18 additions & 0 deletions MangoPay/LocalAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace MangoPay;

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;
}
18 changes: 18 additions & 0 deletions MangoPay/LocalAccountDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace MangoPay;

class LocalAccountDetails extends Libraries\Dto
{
/**
* Information about the address associated with the local IBAN account.
* @var VirtualAccountAddress
*/
public $Address;

/**
* Information about the address associated with the local IBAN account.
* @var LocalAccount
*/
public $Account;
}
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
Loading

0 comments on commit beac573

Please sign in to comment.