From bd1d422b173c06d12ee1fec7ac5b7c97cee44946 Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 23 Aug 2019 17:02:10 +0300 Subject: [PATCH 1/5] #340 added support for users emoney multiperiod changed getobject to support varargs arguments --- MangoPay/ApiBankingAliases.php | 2 +- MangoPay/ApiCardPreAuthorizations.php | 2 +- MangoPay/ApiCardRegistrations.php | 7 +- MangoPay/ApiCards.php | 2 +- MangoPay/ApiClients.php | 101 ++++----- MangoPay/ApiDisputeDocuments.php | 4 +- MangoPay/ApiDisputes.php | 44 ++-- MangoPay/ApiHooks.php | 7 +- MangoPay/ApiKycDocuments.php | 7 +- MangoPay/ApiMandates.php | 11 +- MangoPay/ApiPayIns.php | 5 +- MangoPay/ApiPayOuts.php | 9 +- MangoPay/ApiRefunds.php | 3 +- MangoPay/ApiReports.php | 3 +- MangoPay/ApiRepudiations.php | 2 +- MangoPay/ApiResponses.php | 5 +- MangoPay/ApiTransfers.php | 7 +- MangoPay/ApiUboDeclarations.php | 4 +- MangoPay/ApiUsers.php | 18 +- MangoPay/ApiWallets.php | 6 +- MangoPay/Libraries/ApiBase.php | 300 +++++++++++++------------- composer.json | 2 +- tests/cases/UsersTest.php | 7 +- 23 files changed, 289 insertions(+), 269 deletions(-) diff --git a/MangoPay/ApiBankingAliases.php b/MangoPay/ApiBankingAliases.php index 9d0505cb..9fd877bb 100644 --- a/MangoPay/ApiBankingAliases.php +++ b/MangoPay/ApiBankingAliases.php @@ -13,7 +13,7 @@ class ApiBankingAliases extends Libraries\ApiBase */ public function Get($bankingAliasId) { - $response = $this->GetObject('banking_aliases_get', $bankingAliasId); + $response = $this->GetObject('banking_aliases_get', null, $bankingAliasId); return $this->GetBankingAliasResponse($response); } diff --git a/MangoPay/ApiCardPreAuthorizations.php b/MangoPay/ApiCardPreAuthorizations.php index 6e7db6cc..746ab284 100644 --- a/MangoPay/ApiCardPreAuthorizations.php +++ b/MangoPay/ApiCardPreAuthorizations.php @@ -23,7 +23,7 @@ public function Create($cardPreAuthorization, $idempotencyKey = null) */ public function Get($cardPreAuthorizationId) { - return $this->GetObject('preauthorization_get', $cardPreAuthorizationId, '\MangoPay\CardPreAuthorization'); + return $this->GetObject('preauthorization_get', '\MangoPay\CardPreAuthorization', $cardPreAuthorizationId); } /** diff --git a/MangoPay/ApiCardRegistrations.php b/MangoPay/ApiCardRegistrations.php index ef8d56dc..e45ab7c0 100644 --- a/MangoPay/ApiCardRegistrations.php +++ b/MangoPay/ApiCardRegistrations.php @@ -1,4 +1,5 @@ CreateObject('cardregistration_create', $cardRegistration, '\MangoPay\CardRegistration', null, null, $idempotencyKey); } - + /** * Get card registration * @param string $cardRegistrationId Card Registration identifier @@ -23,9 +24,9 @@ public function Create($cardRegistration, $idempotencyKey = null) */ public function Get($cardRegistrationId) { - return $this->GetObject('cardregistration_get', $cardRegistrationId, '\MangoPay\CardRegistration'); + return $this->GetObject('cardregistration_get', '\MangoPay\CardRegistration', $cardRegistrationId); } - + /** * Update card registration * @param \MangoPay\CardRegistration $cardRegistration Card registration object to save diff --git a/MangoPay/ApiCards.php b/MangoPay/ApiCards.php index e4dc40bb..21e294f7 100644 --- a/MangoPay/ApiCards.php +++ b/MangoPay/ApiCards.php @@ -14,7 +14,7 @@ class ApiCards extends Libraries\ApiBase */ public function Get($cardId) { - return $this->GetObject('card_get', $cardId, '\MangoPay\Card'); + return $this->GetObject('card_get', '\MangoPay\Card', $cardId); } /** diff --git a/MangoPay/ApiClients.php b/MangoPay/ApiClients.php index 80f8d616..bce88ef3 100644 --- a/MangoPay/ApiClients.php +++ b/MangoPay/ApiClients.php @@ -1,4 +1,5 @@ GetObject('client_get', null, '\MangoPay\Client'); + return $this->GetObject('client_get', '\MangoPay\Client'); } - + /** * Save client * @param Client $client Client object to save @@ -23,18 +24,18 @@ public function Get() */ public function Update($client) { - if (!is_null($client->HeadquartersAddress) + if (!is_null($client->HeadquartersAddress) && is_a($client->HeadquartersAddress, "MangoPay\Address") && $client->HeadquartersAddress->CanBeNull()) { - $client->HeadquartersAddress = null; + $client->HeadquartersAddress = null; } - + return $this->SaveObject('client_save', $client, '\MangoPay\Client'); } - + /** * Upload a logo for client. - * Only GIF, PNG, JPG, JPEG, BMP, PDF and DOC formats are accepted, + * 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 */ @@ -48,10 +49,10 @@ public function UploadLogo($logoUpload, $idempotencyKey = null) } } } - + /** * Upload a logo for client from file. - * Only GIF, PNG, JPG, JPEG, BMP, PDF and DOC formats are accepted, + * Only GIF, PNG, JPG, JPEG, BMP, PDF and DOC formats are accepted, * and file must be less than about 7MB * @param string $file Path of file with logo * @throws \MangoPay\Libraries\Exception @@ -62,109 +63,109 @@ public function UploadLogoFromFile($file, $idempotencyKey = null) if (is_array($file)) { $filePath = $file['tmp_name']; } - + if (empty($filePath)) { throw new \MangoPay\Libraries\Exception('Path of file cannot be empty'); } - + if (!file_exists($filePath)) { throw new \MangoPay\Libraries\Exception('File not exist'); } - + $logoUpload = new \MangoPay\ClientLogoUpload(); $logoUpload->File = base64_encode(file_get_contents($filePath)); - + if (empty($logoUpload->File)) { throw new \MangoPay\Libraries\Exception('Content of the file cannot be empty'); } - + $this->UploadLogo($logoUpload, $idempotencyKey); } - + /** - * View your client wallets. To see your fees or credit wallets + * View your client wallets. To see your fees or credit wallets * for each currency set second $fundsType parameter. - * + * * @param \MangoPay\FundsType $fundsType FundsType enum * @param \MangoPay\Sorting $sorting Sorting object - * + * * @return \MangoPay\Wallet[] List with your client wallets */ public function GetWallets($fundsType = null, $sorting = null) { $pagination = new \MangoPay\Pagination(); - if (is_null($fundsType)){ + if (is_null($fundsType)) { return $this->GetList('client_wallets', $pagination, '\MangoPay\Wallet', null, null, $sorting); - } else if ($fundsType == FundsType::FEES){ + } else if ($fundsType == FundsType::FEES) { return $this->GetList('client_wallets_fees', $pagination, '\MangoPay\Wallet', null, null, $sorting); - } else if ($fundsType == FundsType::CREDIT){ + } else if ($fundsType == FundsType::CREDIT) { return $this->GetList('client_wallets_credit', $pagination, '\MangoPay\Wallet', null, null, $sorting); } - - throw new \MangoPay\Libraries\Exception('\MangoPay\FundsType object has wrong value and cannot get wallets'); + + throw new \MangoPay\Libraries\Exception('\MangoPay\FundsType object has wrong value and cannot get wallets'); } - + /** * View one of your client wallets (fees or credit) with a particular currency. - * + * * @param \MangoPay\FundsType $fundsType FundsType enum * @param \MangoPay\CurrencyIso $currencyIso CurrencyIso enum * * @return \MangoPay\Wallet Wallet (fees or credit) with a particular currency */ public function GetWallet($fundsType, $currencyIso) - { - if (is_null($fundsType)){ + { + if (is_null($fundsType)) { throw new \MangoPay\Libraries\Exception( - 'First parameter in function GetWallet in class ApiClients is required.'); + 'First parameter in function GetWallet in class ApiClients is required.'); } - - if (is_null($currencyIso)){ + + if (is_null($currencyIso)) { throw new \MangoPay\Libraries\Exception( - 'Second parameter in function GetWallet in class ApiClients is required.'); + 'Second parameter in function GetWallet in class ApiClients is required.'); } - + $methodKey = null; - if ($fundsType == FundsType::FEES){ + if ($fundsType == FundsType::FEES) { $methodKey = 'client_wallets_fees_currency'; - } else if ($fundsType == FundsType::CREDIT){ + } else if ($fundsType == FundsType::CREDIT) { $methodKey = 'client_wallets_credit_currency'; } else { - throw new \MangoPay\Libraries\Exception('\MangoPay\FundsType object has wrong value and cannot get wallets'); + throw new \MangoPay\Libraries\Exception('\MangoPay\FundsType object has wrong value and cannot get wallets'); } - - return $this->GetObject($methodKey, $currencyIso, '\MangoPay\Wallet'); + + return $this->GetObject($methodKey, '\MangoPay\Wallet', $currencyIso); } - + /** * View the transactions linked to your client wallets (fees and credit) - * + * * @param \MangoPay\FundsType $fundsType FundsType enum * @param \MangoPay\CurrencyIso $currencyIso CurrencyIso enum * @param \MangoPay\Pagination $pagination Pagination object * @param \MangoPay\FilterTransactions $filter Object to filter data - * + * * @return \MangoPay\Transaction[] Transactions linked to your client wallets (fees and credit) */ public function GetWalletTransactions($fundsType = null, $currencyIso = null, & $pagination = null, $filter = null) { - if (is_null($fundsType)){ + if (is_null($fundsType)) { $methodKey = 'client_wallets_transactions'; - } else if ($fundsType == FundsType::FEES){ + } else if ($fundsType == FundsType::FEES) { $methodKey = 'client_wallets_transactions_fees_currency'; - } else if ($fundsType == FundsType::CREDIT){ + } else if ($fundsType == FundsType::CREDIT) { $methodKey = 'client_wallets_transactions_credit_currency'; } else { throw new \MangoPay\Libraries\Exception( - '\MangoPay\FundsType object has wrong value.'); + '\MangoPay\FundsType object has wrong value.'); } - - if (!is_null($fundsType) && is_null($currencyIso)){ - throw new \MangoPay\Libraries\Exception( - 'If FundsType is defined the second parameter (currency) is required.'); + + if (!is_null($fundsType) && is_null($currencyIso)) { + throw new \MangoPay\Libraries\Exception( + 'If FundsType is defined the second parameter (currency) is required.'); } - + return $this->GetList($methodKey, $pagination, '\MangoPay\Transaction', $currencyIso, $filter, null); } } diff --git a/MangoPay/ApiDisputeDocuments.php b/MangoPay/ApiDisputeDocuments.php index dc666c04..ab5523ed 100644 --- a/MangoPay/ApiDisputeDocuments.php +++ b/MangoPay/ApiDisputeDocuments.php @@ -1,9 +1,11 @@ GetObject('disputes_document_get', $documentId, 'MangoPay\DisputeDocument'); + return $this->GetObject('disputes_document_get', 'MangoPay\DisputeDocument', $documentId); } /** diff --git a/MangoPay/ApiDisputes.php b/MangoPay/ApiDisputes.php index b842ffba..30ac43a9 100644 --- a/MangoPay/ApiDisputes.php +++ b/MangoPay/ApiDisputes.php @@ -1,16 +1,18 @@ GetObject('disputes_get', $disputeId, '\MangoPay\Dispute'); + return $this->GetObject('disputes_get', '\MangoPay\Dispute', $disputeId); } - + /** * Get all disputes * @param \MangoPay\Pagination $pagination Pagination object @@ -32,8 +34,8 @@ public function GetAll(& $pagination = null, $sorting = null, $filter = null) { return $this->GetList('disputes_all', $pagination, '\MangoPay\Dispute', null, $filter, $sorting); } - - /** + + /** * List Disputes that need settling * @param \MangoPay\Pagination $pagination Pagination object * @param \MangoPay\Sorting $sorting Object to sorting data @@ -43,7 +45,7 @@ public function GetPendingSettlements(& $pagination = null, $sorting = null) { return $this->GetList('disputes_pendingsettlement', $pagination, '\MangoPay\Dispute', null, null, $sorting); } - + /** * Updates dispute's tag * @param \MangoPay\Dispute Dispute object to update @@ -79,7 +81,7 @@ public function ResubmitDispute($disputeId) $dispute->Id = $disputeId; return $this->SaveObject('disputes_save_contest_funds', $dispute, '\MangoPay\Dispute'); } - + /** * Close dispute * @param string $disputeId Dispute identifier @@ -133,7 +135,7 @@ public function GetDisputesForUser($userId, & $pagination = null, $sorting = nul { return $this->GetList('disputes_get_for_user', $pagination, 'MangoPay\Dispute', $userId, $filter, $sorting); } - + /** * Gets repudiation * @param string $repudiationId Repudiation identifier @@ -141,9 +143,9 @@ public function GetDisputesForUser($userId, & $pagination = null, $sorting = nul */ public function GetRepudiation($repudiationId) { - return $this->GetObject('disputes_repudiation_get', $repudiationId, 'MangoPay\Repudiation'); + return $this->GetObject('disputes_repudiation_get', 'MangoPay\Repudiation', $repudiationId); } - + /** * Creates settlement transfer * @param \MangoPay\SettlementTransfer $settlementTransfer Settlement transfer @@ -154,7 +156,7 @@ public function CreateSettlementTransfer($settlementTransfer, $repudiationId, $i { return $this->CreateObject('disputes_repudiation_create_settlement', $settlementTransfer, '\MangoPay\Transfer', $repudiationId, null, $idempotencyKey); } - + /** * Gets settlement transfer * @param string $settlementTransferId Settlement transfer identifier @@ -162,7 +164,7 @@ public function CreateSettlementTransfer($settlementTransfer, $repudiationId, $i */ public function GetSettlementTransfer($settlementTransferId) { - return $this->GetObject('disputes_repudiation_get_settlement', $settlementTransferId, '\MangoPay\SettlementTransfer'); + return $this->GetObject('disputes_repudiation_get_settlement', '\MangoPay\SettlementTransfer', $settlementTransferId); } /** @@ -178,7 +180,7 @@ public function GetDocumentsForDispute($disputeId, & $pagination = null, $sortin { return $this->GetList('disputes_document_get_for_dispute', $pagination, 'MangoPay\DisputeDocument', $disputeId, $filter, $sorting); } - + /** * Update dispute document * @param string $disputeId Dispute identifier @@ -189,7 +191,7 @@ public function UpdateDisputeDocument($disputeId, $disputeDocument) { return $this->SaveObject('disputes_document_save', $disputeDocument, '\MangoPay\DisputeDocument', $disputeId); } - + /** * Creates document for dispute * @param string $disputeId Dispute identifier @@ -200,7 +202,7 @@ public function CreateDisputeDocument($disputeId, $disputeDocument, $idempotency { return $this->CreateObject('disputes_document_create', $disputeDocument, '\MangoPay\DisputeDocument', $disputeId, null, $idempotencyKey); } - + /** * Creates document's page for dispute * @param string $disputeId Dispute identifier @@ -217,7 +219,7 @@ public function CreateDisputeDocumentPage($disputeId, $disputeDocumentId, $dispu } } } - + /** * Creates document's page for dispute from file * @param string $disputeId Dispute identifier @@ -231,22 +233,22 @@ public function CreateDisputeDocumentPageFromFile($disputeId, $disputeDocumentId if (is_array($file)) { $filePath = $file['tmp_name']; } - + if (empty($filePath)) { throw new \MangoPay\Libraries\Exception('Path of file cannot be empty'); } - + if (!file_exists($filePath)) { throw new \MangoPay\Libraries\Exception('File not exist'); } - + $disputeDocumentPage = new \MangoPay\DisputeDocumentPage(); $disputeDocumentPage->File = base64_encode(file_get_contents($filePath)); - + if (empty($disputeDocumentPage->File)) { throw new \MangoPay\Libraries\Exception('Content of the file cannot be empty'); } - + $this->CreateDisputeDocumentPage($disputeId, $disputeDocumentId, $disputeDocumentPage, $idempotencyKey); } } diff --git a/MangoPay/ApiHooks.php b/MangoPay/ApiHooks.php index 6e305de5..12e92680 100644 --- a/MangoPay/ApiHooks.php +++ b/MangoPay/ApiHooks.php @@ -1,4 +1,5 @@ CreateObject('hooks_create', $hook, '\MangoPay\Hook', null, null, $idempotencyKey); } - + /** * Get hook * @param string $hookId Hook identifier @@ -24,9 +25,9 @@ public function Create($hook, $idempotencyKey = null) */ public function Get($hookId) { - return $this->GetObject('hooks_get', $hookId, '\MangoPay\Hook'); + return $this->GetObject('hooks_get', '\MangoPay\Hook', $hookId); } - + /** * Save hook * @param \MangoPay\Hook $hook Hook object to save diff --git a/MangoPay/ApiKycDocuments.php b/MangoPay/ApiKycDocuments.php index dd81dc44..64a060b2 100644 --- a/MangoPay/ApiKycDocuments.php +++ b/MangoPay/ApiKycDocuments.php @@ -1,4 +1,5 @@ GetList('kyc_documents_all', $pagination, '\MangoPay\KycDocument', null, $filter, $sorting); } - - /** + + /** * Get KYC document * @param string $kycDocumentId Document identifier * @return \MangoPay\KycDocument Document returned from API */ public function Get($kycDocumentId) { - return $this->GetObject('kyc_documents_get_alt', $kycDocumentId, '\MangoPay\KycDocument'); + return $this->GetObject('kyc_documents_get_alt', '\MangoPay\KycDocument', $kycDocumentId); } diff --git a/MangoPay/ApiMandates.php b/MangoPay/ApiMandates.php index b88009ea..cb9d8647 100644 --- a/MangoPay/ApiMandates.php +++ b/MangoPay/ApiMandates.php @@ -1,4 +1,5 @@ CreateObject('mandates_create', $mandate, '\MangoPay\Mandate', null, null, $idempotencyKey); } - + /** * Get mandate * @param string $mandateId Mandate identifier @@ -23,9 +24,9 @@ public function Create($mandate, $idempotencyKey = null) */ public function Get($mandateId) { - return $this->GetObject('mandates_get', $mandateId, '\MangoPay\Mandate'); + return $this->GetObject('mandates_get', '\MangoPay\Mandate', $mandateId); } - + /** * Cancel mandate * @param string $mandateId Id of mandate object to cancel @@ -35,10 +36,10 @@ public function Cancel($mandateId) { $mandate = new \MangoPay\Mandate(); $mandate->Id = $mandateId; - + return $this->SaveObject('mandates_save', $mandate, '\MangoPay\Mandate'); } - + /** * Get all mandates * @param \MangoPay\Pagination $pagination Pagination object diff --git a/MangoPay/ApiPayIns.php b/MangoPay/ApiPayIns.php index 8e74445c..85777b94 100644 --- a/MangoPay/ApiPayIns.php +++ b/MangoPay/ApiPayIns.php @@ -1,4 +1,5 @@ GetObject('payins_get', $payInId, '\MangoPay\PayIn'); + return $this->GetObject('payins_get', '\MangoPay\PayIn', $payInId); } /** @@ -80,6 +81,6 @@ private function GetExecutionKey($payIn) */ public function GetExtendedCardView($payInId) { - return $this->GetObject('get_extended_card_view', $payInId, '\MangoPay\PayInWebExtendedView'); + return $this->GetObject('get_extended_card_view', '\MangoPay\PayInWebExtendedView', $payInId); } } diff --git a/MangoPay/ApiPayOuts.php b/MangoPay/ApiPayOuts.php index 9991a9db..539bf754 100644 --- a/MangoPay/ApiPayOuts.php +++ b/MangoPay/ApiPayOuts.php @@ -1,4 +1,5 @@ GetPaymentKey($payOut); return $this->CreateObject('payouts_' . $paymentKey . '_create', $payOut, '\MangoPay\PayOut', null, null, $idempotencyKey); } - + /** * Get pay-out object * @param string $payOutId PayOut identifier @@ -24,7 +25,7 @@ public function Create($payOut, $idempotencyKey = null) */ public function Get($payOutId) { - return $this->GetObject('payouts_get', $payOutId, '\MangoPay\PayOut'); + return $this->GetObject('payouts_get', '\MangoPay\PayOut', $payOutId); } /** @@ -39,13 +40,13 @@ public function GetRefunds($payOutId, & $pagination = null, $filter = null, $sor { return $this->GetList('refunds_get_for_payout', $pagination, '\MangoPay\Refund', $payOutId, $filter, $sorting); } - + private function GetPaymentKey($payOut) { if (!isset($payOut->MeanOfPaymentDetails) || !is_object($payOut->MeanOfPaymentDetails)) { throw new Libraries\Exception('Mean of payment is not defined or it is not object type'); } - + $className = str_replace('MangoPay\\PayOutPaymentDetails', '', get_class($payOut->MeanOfPaymentDetails)); return strtolower($className); } diff --git a/MangoPay/ApiRefunds.php b/MangoPay/ApiRefunds.php index b860aa40..69434394 100644 --- a/MangoPay/ApiRefunds.php +++ b/MangoPay/ApiRefunds.php @@ -1,4 +1,5 @@ GetObject('refunds_get', $refundId, '\MangoPay\Refund'); + return $this->GetObject('refunds_get', '\MangoPay\Refund', $refundId); } } diff --git a/MangoPay/ApiReports.php b/MangoPay/ApiReports.php index e231eded..33bf1ea4 100644 --- a/MangoPay/ApiReports.php +++ b/MangoPay/ApiReports.php @@ -1,4 +1,5 @@ GetObject('reports_get', $reportRequestId, '\MangoPay\ReportRequest'); + return $this->GetObject('reports_get', '\MangoPay\ReportRequest', $reportRequestId); } /** diff --git a/MangoPay/ApiRepudiations.php b/MangoPay/ApiRepudiations.php index 7fec2d37..fa367819 100644 --- a/MangoPay/ApiRepudiations.php +++ b/MangoPay/ApiRepudiations.php @@ -12,7 +12,7 @@ class ApiRepudiations extends Libraries\ApiBase */ public function Get($repudiationId) { - return $this->GetObject('repudiation_get', $repudiationId, '\MangoPay\Repudiation'); + return $this->GetObject('repudiation_get', '\MangoPay\Repudiation', $repudiationId); } /** diff --git a/MangoPay/ApiResponses.php b/MangoPay/ApiResponses.php index 92e383a7..108371ab 100644 --- a/MangoPay/ApiResponses.php +++ b/MangoPay/ApiResponses.php @@ -1,4 +1,5 @@ GetObject('responses_get', $idempotencyKey, 'MangoPay\Response'); + $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)) return $response; - + $response->Resource = $this->CastResponseToEntity($response->Resource, $className); return $response; } diff --git a/MangoPay/ApiTransfers.php b/MangoPay/ApiTransfers.php index d3c06d78..2cad41d3 100644 --- a/MangoPay/ApiTransfers.php +++ b/MangoPay/ApiTransfers.php @@ -1,4 +1,5 @@ CreateObject('transfers_create', $transfer, '\MangoPay\Transfer', null, null, $idempotencyKey); } - + /** * Get transfer * @param string $transferId Transfer identifier @@ -23,9 +24,9 @@ public function Create($transfer, $idempotencyKey = null) */ public function Get($transferId) { - return $this->GetObject('transfers_get', $transferId, '\MangoPay\Transfer'); + return $this->GetObject('transfers_get', '\MangoPay\Transfer', $transferId); } - + /** * Create refund for transfer object * @param string $transferId Transfer identifier diff --git a/MangoPay/ApiUboDeclarations.php b/MangoPay/ApiUboDeclarations.php index ac46bd76..b11dcadd 100644 --- a/MangoPay/ApiUboDeclarations.php +++ b/MangoPay/ApiUboDeclarations.php @@ -30,7 +30,7 @@ public function GetAll($userId, $pagination = null, $sorting = null) */ public function Get($userId, $uboDeclarationId) { - return $this->GetObject('ubo_declaration_get', $userId, '\MangoPay\UboDeclaration', $uboDeclarationId); + return $this->GetObject('ubo_declaration_get', '\MangoPay\UboDeclaration', $userId, $uboDeclarationId); } /** @@ -66,7 +66,7 @@ public function UpdateUbo($userId, $uboDeclarationId, $ubo) */ public function GetUbo($userId, $uboDeclarationId, $uboId) { - return $this->GetObject('ubo_get', $userId, '\MangoPay\Ubo', $uboDeclarationId, $uboId); + return $this->GetObject('ubo_get', '\MangoPay\Ubo', $userId, $uboDeclarationId, $uboId); } /** diff --git a/MangoPay/ApiUsers.php b/MangoPay/ApiUsers.php index 5dde82e8..06097ddd 100644 --- a/MangoPay/ApiUsers.php +++ b/MangoPay/ApiUsers.php @@ -54,7 +54,7 @@ public function GetAll(& $pagination = null, $sorting = null) */ public function Get($userId) { - $response = $this->GetObject('users_get', $userId); + $response = $this->GetObject('users_get', null, $userId); return $this->GetUserResponse($response); } @@ -65,7 +65,7 @@ public function Get($userId) */ public function GetNatural($userId) { - $response = $this->GetObject('users_getnaturals', $userId); + $response = $this->GetObject('users_getnaturals', null, $userId); return $this->GetUserResponse($response); } @@ -76,7 +76,7 @@ public function GetNatural($userId) */ public function GetLegal($userId) { - $response = $this->GetObject('users_getlegals', $userId); + $response = $this->GetObject('users_getlegals', null, $userId); return $this->GetUserResponse($response); } @@ -151,7 +151,7 @@ public function GetBankAccounts($userId, & $pagination = null, $sorting = null, */ public function GetBankAccount($userId, $bankAccountId) { - return $this->GetObject('users_getbankaccount', $userId, 'MangoPay\BankAccount', $bankAccountId); + return $this->GetObject('users_getbankaccount', 'MangoPay\BankAccount', $userId, $bankAccountId); } /** @@ -239,7 +239,7 @@ public function GetKycDocuments($userId, & $pagination = null, $sorting = null, */ public function GetKycDocument($userId, $kycDocumentId) { - return $this->GetObject('kyc_documents_get', $userId, '\MangoPay\KycDocument', $kycDocumentId); + return $this->GetObject('kyc_documents_get', '\MangoPay\KycDocument', $userId, $kycDocumentId); } /** @@ -337,11 +337,15 @@ public function CreateKycPageFromFile($userId, $kycDocumentId, $filePath, $idemp /** * Get user EMoney * @param string $userId User Id + * @param $year + * @param $month * @return \MangoPay\EMoney EMoney obhect returned from API + * @throws Libraries\Exception */ - public function GetEMoney($userId) + public function GetEMoney($userId, $year, $month) { - return $this->GetObject('users_getemoney', $userId, '\MangoPay\EMoney'); + $methodKey = $month == null ? 'users_getemoney_year' : 'users_getemoney_month'; + return $this->GetObject($methodKey, '\MangoPay\EMoney', $userId, $year, $month); } /** diff --git a/MangoPay/ApiWallets.php b/MangoPay/ApiWallets.php index b7e24cb2..d983feff 100644 --- a/MangoPay/ApiWallets.php +++ b/MangoPay/ApiWallets.php @@ -15,7 +15,7 @@ public function Create($wallet, $idempotencyKey = null) { return $this->CreateObject('wallets_create', $wallet, '\MangoPay\Wallet', null, null, $idempotencyKey); } - + /** * Get wallet * @param string $walletId Wallet identifier @@ -23,9 +23,9 @@ public function Create($wallet, $idempotencyKey = null) */ public function Get($walletId) { - return $this->GetObject('wallets_get', $walletId, '\MangoPay\Wallet'); + return $this->GetObject('wallets_get', '\MangoPay\Wallet', $walletId); } - + /** * Save wallet * @param Wallet $wallet Wallet object to save diff --git a/MangoPay/Libraries/ApiBase.php b/MangoPay/Libraries/ApiBase.php index 3b098a03..390ed675 100644 --- a/MangoPay/Libraries/ApiBase.php +++ b/MangoPay/Libraries/ApiBase.php @@ -1,4 +1,5 @@ array( '/clients/', RequestType::POST ), - 'authentication_oauth' => array( '/oauth/token', RequestType::POST ), + 'authentication_base' => array('/clients/', RequestType::POST), + 'authentication_oauth' => array('/oauth/token', RequestType::POST), - 'responses_get' => array( '/responses/%s', RequestType::GET), + 'responses_get' => array('/responses/%s', RequestType::GET), - 'events_all' => array( '/events', RequestType::GET ), + 'events_all' => array('/events', RequestType::GET), - 'hooks_create' => array( '/hooks', RequestType::POST ), - 'hooks_all' => array( '/hooks', RequestType::GET ), - 'hooks_get' => array( '/hooks/%s', RequestType::GET ), - 'hooks_save' => array( '/hooks/%s', RequestType::PUT ), + 'hooks_create' => array('/hooks', RequestType::POST), + 'hooks_all' => array('/hooks', RequestType::GET), + 'hooks_get' => array('/hooks/%s', RequestType::GET), + 'hooks_save' => array('/hooks/%s', RequestType::PUT), - 'cardregistration_create' => array( '/cardregistrations', RequestType::POST ), - 'cardregistration_get' => array( '/cardregistrations/%s', RequestType::GET ), - 'cardregistration_save' => array( '/cardregistrations/%s', RequestType::PUT ), + 'cardregistration_create' => array('/cardregistrations', RequestType::POST), + 'cardregistration_get' => array('/cardregistrations/%s', RequestType::GET), + 'cardregistration_save' => array('/cardregistrations/%s', RequestType::PUT), - 'preauthorization_create' => array( '/preauthorizations/card/direct', RequestType::POST ), - 'preauthorization_get' => array( '/preauthorizations/%s', RequestType::GET ), - 'preauthorizations_get_for_card' => array( '/cards/%s/preauthorizations', RequestType::GET ), - 'preauthorizations_get_for_user' => array( '/users/%s/preauthorizations', RequestType::GET ), - 'preauthorization_save' => array( '/preauthorizations/%s', RequestType::PUT ), + 'preauthorization_create' => array('/preauthorizations/card/direct', RequestType::POST), + 'preauthorization_get' => array('/preauthorizations/%s', RequestType::GET), + 'preauthorizations_get_for_card' => array('/cards/%s/preauthorizations', RequestType::GET), + 'preauthorizations_get_for_user' => array('/users/%s/preauthorizations', RequestType::GET), + 'preauthorization_save' => array('/preauthorizations/%s', RequestType::PUT), - 'card_get' => array( '/cards/%s', RequestType::GET ), - 'cards_get_by_fingerprint' => array('/cards/fingerprints/%s', RequestType::GET ), - 'card_save' => array( '/cards/%s', RequestType::PUT ), + 'card_get' => array('/cards/%s', RequestType::GET), + 'cards_get_by_fingerprint' => array('/cards/fingerprints/%s', RequestType::GET), + 'card_save' => array('/cards/%s', RequestType::PUT), // pay ins URLs - 'payins_card-web_create' => array( '/payins/card/web/', RequestType::POST ), - 'payins_card-direct_create' => array( '/payins/card/direct/', RequestType::POST ), - 'payins_preauthorized-direct_create' => array( '/payins/preauthorized/direct/', RequestType::POST ), - 'payins_bankwire-direct_create' => array( '/payins/bankwire/direct/', RequestType::POST ), - 'payins_directdebit-web_create' => array( '/payins/directdebit/web', RequestType::POST ), - 'payins_directdebit-direct_create' => array( '/payins/directdebit/direct', RequestType::POST ), - 'payins_paypal-web_create' => array( '/payins/paypal/web', RequestType::POST ), - 'payins_get' => array( '/payins/%s', RequestType::GET ), - 'payins_createrefunds' => array( '/payins/%s/refunds', RequestType::POST ), + 'payins_card-web_create' => array('/payins/card/web/', RequestType::POST), + 'payins_card-direct_create' => array('/payins/card/direct/', RequestType::POST), + 'payins_preauthorized-direct_create' => array('/payins/preauthorized/direct/', RequestType::POST), + 'payins_bankwire-direct_create' => array('/payins/bankwire/direct/', RequestType::POST), + 'payins_directdebit-web_create' => array('/payins/directdebit/web', RequestType::POST), + 'payins_directdebit-direct_create' => array('/payins/directdebit/direct', RequestType::POST), + 'payins_paypal-web_create' => array('/payins/paypal/web', RequestType::POST), + 'payins_get' => array('/payins/%s', RequestType::GET), + 'payins_createrefunds' => array('/payins/%s/refunds', RequestType::POST), 'repudiation_get' => array('/repudiations/%s', RequestType::GET), - 'get_extended_card_view' => array( '/payins/card/web/%s/extended', RequestType::GET ), - - 'payouts_bankwire_create' => array( '/payouts/bankwire/', RequestType::POST ), - 'payouts_get' => array( '/payouts/%s', RequestType::GET ), - - 'refunds_get' => array( '/refunds/%s', RequestType::GET ), - 'refunds_get_for_repudiation' => array( '/repudiations/%s/refunds', RequestType::GET ), - 'refunds_get_for_transfer' => array( '/transfers/%s/refunds', RequestType::GET ), - 'refunds_get_for_payin' => array( '/payins/%s/refunds', RequestType::GET ), - 'refunds_get_for_payout' => array( '/payouts/%s/refunds', RequestType::GET ), - - 'transfers_create' => array( '/transfers', RequestType::POST ), - 'transfers_get' => array( '/transfers/%s', RequestType::GET ), - 'transfers_createrefunds' => array( '/transfers/%s/refunds', RequestType::POST ), - - 'users_createnaturals' => array( '/users/natural', RequestType::POST ), - 'users_createlegals' => array( '/users/legal', RequestType::POST ), - - 'users_createbankaccounts_iban' => array( '/users/%s/bankaccounts/iban', RequestType::POST ), - 'users_createbankaccounts_gb' => array( '/users/%s/bankaccounts/gb', RequestType::POST ), - 'users_createbankaccounts_us' => array( '/users/%s/bankaccounts/us', RequestType::POST ), - 'users_createbankaccounts_ca' => array( '/users/%s/bankaccounts/ca', RequestType::POST ), - 'users_createbankaccounts_other' => array( '/users/%s/bankaccounts/other', RequestType::POST ), - - 'users_all' => array( '/users', RequestType::GET ), - 'users_allwallets' => array( '/users/%s/wallets', RequestType::GET ), - 'users_allbankaccount' => array( '/users/%s/bankaccounts', RequestType::GET ), - 'users_allcards' => array( '/users/%s/cards', RequestType::GET ), - 'users_alltransactions' => array( '/users/%s/transactions', RequestType::GET ), - 'users_allkycdocuments' => array( '/users/%s/KYC/documents', RequestType::GET ), - 'users_allmandates' => array( '/users/%s/mandates', RequestType::GET ), - 'users_allbankaccount_mandates' => array( '/users/%s/bankaccounts/%s/mandates', RequestType::GET ), - 'users_get' => array( '/users/%s', RequestType::GET ), - 'users_getnaturals' => array( '/users/natural/%s', RequestType::GET ), - 'users_getlegals' => array( '/users/legal/%s', RequestType::GET ), - 'users_getbankaccount' => array( '/users/%s/bankaccounts/%s', RequestType::GET ), - 'users_savenaturals' => array( '/users/natural/%s', RequestType::PUT ), - 'users_savelegals' => array( '/users/legal/%s', RequestType::PUT ), - 'users_getemoney' => array( '/users/%s/emoney', RequestType::GET ), - - 'bankaccounts_save' => array( '/users/%s/bankaccounts/%s', RequestType::PUT ), - - 'wallets_create' => array( '/wallets', RequestType::POST ), - 'wallets_alltransactions' => array( '/wallets/%s/transactions', RequestType::GET ), - 'wallets_get' => array( '/wallets/%s', RequestType::GET ), - 'wallets_save' => array( '/wallets/%s', RequestType::PUT ), - - 'kyc_documents_create' => array( '/users/%s/KYC/documents/', RequestType::POST ), - 'kyc_documents_get' => array( '/users/%s/KYC/documents/%s', RequestType::GET ), - 'kyc_documents_save' => array( '/users/%s/KYC/documents/%s', RequestType::PUT ), - 'kyc_page_create' => array( '/users/%s/KYC/documents/%s/pages', RequestType::POST ), - 'kyc_documents_all' => array( '/KYC/documents', RequestType::GET ), - 'kyc_documents_get_alt' => array( '/KYC/documents/%s', RequestType::GET ), - 'kyc_documents_create_consult' => array( '/KYC/documents/%s/consult', RequestType::POST ), - - 'disputes_get' => array( '/disputes/%s', RequestType::GET), - 'disputes_save_tag' => array( '/disputes/%s', RequestType::PUT), - 'disputes_save_contest_funds' => array( '/disputes/%s/submit', RequestType::PUT), - 'dispute_save_close' => array( '/disputes/%s/close', RequestType::PUT), - - 'disputes_get_transactions' => array( '/disputes/%s/transactions', RequestType::GET), - - 'disputes_all' => array( '/disputes', RequestType::GET), - 'disputes_get_for_wallet' => array( '/wallets/%s/disputes', RequestType::GET), - 'disputes_get_for_user' => array( '/users/%s/disputes', RequestType::GET), - - 'disputes_document_create' => array( '/disputes/%s/documents', RequestType::POST), - 'disputes_document_page_create' => array( '/disputes/%s/documents/%s/pages', RequestType::POST), - 'disputes_document_save' => array( '/disputes/%s/documents/%s', RequestType::PUT), - 'disputes_document_get' => array( '/dispute-documents/%s', RequestType::GET), - 'disputes_document_get_for_dispute' => array( '/disputes/%s/documents', RequestType::GET), - 'disputes_document_all' => array( '/dispute-documents', RequestType::GET), - 'disputes_document_create_consult' => array( '/dispute-documents/%s/consult', RequestType::POST), - - 'disputes_repudiation_get' => array( '/repudiations/%s', RequestType::GET), - - 'disputes_repudiation_create_settlement' => array( '/repudiations/%s/settlementtransfer', RequestType::POST), - 'disputes_repudiation_get_settlement' => array( '/settlements/%s', RequestType::GET), - 'disputes_pendingsettlement' => array('/disputes/pendingsettlement' , RequestType::GET), - - 'mandates_create' => array( '/mandates/directdebit/web', RequestType::POST ), - 'mandates_save' => array( '/mandates/%s/cancel', RequestType::PUT ), - 'mandates_get' => array( '/mandates/%s', RequestType::GET ), - 'mandates_all' => array( '/mandates', RequestType::GET ), - - 'client_get' => array( '/clients', RequestType::GET ), - 'client_save' => array( '/clients', RequestType::PUT ), - 'client_upload_logo' => array( '/clients/logo', RequestType::PUT ), - 'client_wallets' => array( '/clients/wallets', RequestType::GET ), - 'client_wallets_fees' => array( '/clients/wallets/fees', RequestType::GET ), - 'client_wallets_fees_currency' => array( '/clients/wallets/fees/%s', RequestType::GET ), - 'client_wallets_credit' => array( '/clients/wallets/credit', RequestType::GET ), - 'client_wallets_credit_currency' => array( '/clients/wallets/credit/%s', RequestType::GET ), - 'client_wallets_transactions' => array( '/clients/transactions', RequestType::GET ), - 'client_wallets_transactions_fees_currency' => array( '/clients/wallets/fees/%s/transactions', RequestType::GET ), - 'client_wallets_transactions_credit_currency' => array( '/clients/wallets/credit/%s/transactions', RequestType::GET ), - - 'banking_aliases_iban_create' => array( '/wallets/%s/bankingaliases/iban', RequestType::POST ), - 'banking_aliases_get' => array( '/bankingaliases/%s', RequestType::GET ), - 'banking_aliases_update' => array( '/bankingaliases/%s', RequestType::PUT ), - 'banking_aliases_all' => array( '/wallets/%s/bankingaliases', RequestType::GET ), - - 'reports_transactions_create' => array( '/reports/transactions', RequestType::POST ), - 'reports_wallets_create' => array( '/reports/wallets', RequestType::POST ), - 'reports_all' => array( '/reports', RequestType::GET ), - 'reports_get' => array( '/reports/%s', RequestType::GET ), + 'get_extended_card_view' => array('/payins/card/web/%s/extended', RequestType::GET), + + 'payouts_bankwire_create' => array('/payouts/bankwire/', RequestType::POST), + 'payouts_get' => array('/payouts/%s', RequestType::GET), + + 'refunds_get' => array('/refunds/%s', RequestType::GET), + 'refunds_get_for_repudiation' => array('/repudiations/%s/refunds', RequestType::GET), + 'refunds_get_for_transfer' => array('/transfers/%s/refunds', RequestType::GET), + 'refunds_get_for_payin' => array('/payins/%s/refunds', RequestType::GET), + 'refunds_get_for_payout' => array('/payouts/%s/refunds', RequestType::GET), + + 'transfers_create' => array('/transfers', RequestType::POST), + 'transfers_get' => array('/transfers/%s', RequestType::GET), + 'transfers_createrefunds' => array('/transfers/%s/refunds', RequestType::POST), + + 'users_createnaturals' => array('/users/natural', RequestType::POST), + 'users_createlegals' => array('/users/legal', RequestType::POST), + + 'users_createbankaccounts_iban' => array('/users/%s/bankaccounts/iban', RequestType::POST), + 'users_createbankaccounts_gb' => array('/users/%s/bankaccounts/gb', RequestType::POST), + 'users_createbankaccounts_us' => array('/users/%s/bankaccounts/us', RequestType::POST), + 'users_createbankaccounts_ca' => array('/users/%s/bankaccounts/ca', RequestType::POST), + 'users_createbankaccounts_other' => array('/users/%s/bankaccounts/other', RequestType::POST), + + 'users_all' => array('/users', RequestType::GET), + 'users_allwallets' => array('/users/%s/wallets', RequestType::GET), + 'users_allbankaccount' => array('/users/%s/bankaccounts', RequestType::GET), + 'users_allcards' => array('/users/%s/cards', RequestType::GET), + 'users_alltransactions' => array('/users/%s/transactions', RequestType::GET), + 'users_allkycdocuments' => array('/users/%s/KYC/documents', RequestType::GET), + 'users_allmandates' => array('/users/%s/mandates', RequestType::GET), + 'users_allbankaccount_mandates' => array('/users/%s/bankaccounts/%s/mandates', RequestType::GET), + 'users_get' => array('/users/%s', RequestType::GET), + 'users_getnaturals' => array('/users/natural/%s', RequestType::GET), + 'users_getlegals' => array('/users/legal/%s', RequestType::GET), + 'users_getbankaccount' => array('/users/%s/bankaccounts/%s', RequestType::GET), + 'users_savenaturals' => array('/users/natural/%s', RequestType::PUT), + 'users_savelegals' => array('/users/legal/%s', RequestType::PUT), + 'users_getemoney_year' => array('/users/%s/emoney/%s', RequestType::GET), + 'users_getemoney_month' => array('/users/%s/emoney/%s/%s', RequestType::GET), + + 'bankaccounts_save' => array('/users/%s/bankaccounts/%s', RequestType::PUT), + + 'wallets_create' => array('/wallets', RequestType::POST), + 'wallets_alltransactions' => array('/wallets/%s/transactions', RequestType::GET), + 'wallets_get' => array('/wallets/%s', RequestType::GET), + 'wallets_save' => array('/wallets/%s', RequestType::PUT), + + 'kyc_documents_create' => array('/users/%s/KYC/documents/', RequestType::POST), + 'kyc_documents_get' => array('/users/%s/KYC/documents/%s', RequestType::GET), + 'kyc_documents_save' => array('/users/%s/KYC/documents/%s', RequestType::PUT), + 'kyc_page_create' => array('/users/%s/KYC/documents/%s/pages', RequestType::POST), + 'kyc_documents_all' => array('/KYC/documents', RequestType::GET), + 'kyc_documents_get_alt' => array('/KYC/documents/%s', RequestType::GET), + 'kyc_documents_create_consult' => array('/KYC/documents/%s/consult', RequestType::POST), + + 'disputes_get' => array('/disputes/%s', RequestType::GET), + 'disputes_save_tag' => array('/disputes/%s', RequestType::PUT), + 'disputes_save_contest_funds' => array('/disputes/%s/submit', RequestType::PUT), + 'dispute_save_close' => array('/disputes/%s/close', RequestType::PUT), + + 'disputes_get_transactions' => array('/disputes/%s/transactions', RequestType::GET), + + 'disputes_all' => array('/disputes', RequestType::GET), + 'disputes_get_for_wallet' => array('/wallets/%s/disputes', RequestType::GET), + 'disputes_get_for_user' => array('/users/%s/disputes', RequestType::GET), + + 'disputes_document_create' => array('/disputes/%s/documents', RequestType::POST), + 'disputes_document_page_create' => array('/disputes/%s/documents/%s/pages', RequestType::POST), + 'disputes_document_save' => array('/disputes/%s/documents/%s', RequestType::PUT), + 'disputes_document_get' => array('/dispute-documents/%s', RequestType::GET), + 'disputes_document_get_for_dispute' => array('/disputes/%s/documents', RequestType::GET), + 'disputes_document_all' => array('/dispute-documents', RequestType::GET), + 'disputes_document_create_consult' => array('/dispute-documents/%s/consult', RequestType::POST), + + 'disputes_repudiation_get' => array('/repudiations/%s', RequestType::GET), + + 'disputes_repudiation_create_settlement' => array('/repudiations/%s/settlementtransfer', RequestType::POST), + 'disputes_repudiation_get_settlement' => array('/settlements/%s', RequestType::GET), + 'disputes_pendingsettlement' => array('/disputes/pendingsettlement', RequestType::GET), + + 'mandates_create' => array('/mandates/directdebit/web', RequestType::POST), + 'mandates_save' => array('/mandates/%s/cancel', RequestType::PUT), + 'mandates_get' => array('/mandates/%s', RequestType::GET), + 'mandates_all' => array('/mandates', RequestType::GET), + + 'client_get' => array('/clients', RequestType::GET), + 'client_save' => array('/clients', RequestType::PUT), + 'client_upload_logo' => array('/clients/logo', RequestType::PUT), + 'client_wallets' => array('/clients/wallets', RequestType::GET), + 'client_wallets_fees' => array('/clients/wallets/fees', RequestType::GET), + 'client_wallets_fees_currency' => array('/clients/wallets/fees/%s', RequestType::GET), + 'client_wallets_credit' => array('/clients/wallets/credit', RequestType::GET), + 'client_wallets_credit_currency' => array('/clients/wallets/credit/%s', RequestType::GET), + 'client_wallets_transactions' => array('/clients/transactions', RequestType::GET), + 'client_wallets_transactions_fees_currency' => array('/clients/wallets/fees/%s/transactions', RequestType::GET), + 'client_wallets_transactions_credit_currency' => array('/clients/wallets/credit/%s/transactions', RequestType::GET), + + 'banking_aliases_iban_create' => array('/wallets/%s/bankingaliases/iban', RequestType::POST), + 'banking_aliases_get' => array('/bankingaliases/%s', RequestType::GET), + 'banking_aliases_update' => array('/bankingaliases/%s', RequestType::PUT), + 'banking_aliases_all' => array('/wallets/%s/bankingaliases', RequestType::GET), + + 'reports_transactions_create' => array('/reports/transactions', RequestType::POST), + 'reports_wallets_create' => array('/reports/wallets', RequestType::POST), + 'reports_all' => array('/reports', RequestType::GET), + 'reports_get' => array('/reports/%s', RequestType::GET), 'ubo_declaration_create' => array('/users/%s/kyc/ubodeclarations', RequestType::POST), 'ubo_declaration_all' => array('/users/%s/kyc/ubodeclarations', RequestType::GET), @@ -179,9 +181,9 @@ protected function getLogger() 'ubo_update' => array('/users/%s/kyc/ubodeclarations/%s/ubos/%s', RequestType::PUT), 'ubo_get' => array('/users/%s/kyc/ubodeclarations/%s/ubos/%s', RequestType::GET), - 'transactions_get_for_mandate' => array( '/mandates/%s/transactions', RequestType::GET ), - 'transactions_get_for_card' => array( '/cards/%s/transactions', RequestType::GET ), - 'transactions_get_for_bank_account' => array( '/bankaccounts/%s/transactions', RequestType::GET ) + 'transactions_get_for_mandate' => array('/mandates/%s/transactions', RequestType::GET), + 'transactions_get_for_card' => array('/cards/%s/transactions', RequestType::GET), + 'transactions_get_for_bank_account' => array('/bankaccounts/%s/transactions', RequestType::GET) ); @@ -236,7 +238,7 @@ protected function CreateObject($methodKey, $entity, $responseClassName = null, if (!is_null($entity)) { $requestData = $this->BuildRequestData($entity); } - + if (is_null($requestData) && $responseClassName == '\MangoPay\UboDeclaration') { $requestData = ""; } @@ -254,27 +256,20 @@ protected function CreateObject($methodKey, $entity, $responseClassName = null, /** * Get entity object from API * @param string $methodKey Key with request data - * @param string $entityId Entity identifier * @param object $responseClassName Name of entity class from response - * @param int $secondEntityId Entity identifier for second entity - * @param int $thirdEntityId Entity identifier for third entity + * @param array $params path variable in urls * @return object Response data + * @throws Exception */ - protected function GetObject($methodKey, $entityId, $responseClassName = null, $secondEntityId = null, $thirdEntityId = null) + protected function GetObject($methodKey, $responseClassName, ...$params) { - if ($thirdEntityId === null) { - $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId, $secondEntityId); - } else { - $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId, $secondEntityId, $thirdEntityId); - } - + $urlMethod = vsprintf($this->GetRequestUrl($methodKey), $params); $rest = new RestTool(true, $this->_root); $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey)); if (!is_null($responseClassName)) { return $this->CastResponseToEntity($response, $responseClassName); } - return $response; } @@ -328,7 +323,7 @@ protected function GetList($methodKey, & $pagination, $responseClassName = null, protected function SaveObject($methodKey, $entity, $responseClassName = null, $secondEntityId = null, $thirdEntityId = null) { $entityId = null; - if (isset($entity->Id)){ + if (isset($entity->Id)) { $entityId = $entity->Id; } @@ -488,7 +483,7 @@ protected function BuildRequestData($entity) private function CanReadSubRequestData($entity, $propertyName) { if (get_class($entity) == 'MangoPay\PayIn' && - ($propertyName == 'PaymentDetails' || $propertyName == 'ExecutionDetails')) { + ($propertyName == 'PaymentDetails' || $propertyName == 'ExecutionDetails')) { return true; } @@ -503,7 +498,8 @@ private function CanReadSubRequestData($entity, $propertyName) return false; } - protected function GetObjectForIdempotencyUrl($url){ + protected function GetObjectForIdempotencyUrl($url) + { if (is_null($url) || empty($url)) return null; diff --git a/composer.json b/composer.json index bcd1376d..273bc79c 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "minimum-stability": "stable", "license": "MIT", "require": { - "php": ">=5.4.0", + "php": ">=5.6.0", "ext-curl": "*", "ext-openssl": "*", "psr/log": "^1.0" diff --git a/tests/cases/UsersTest.php b/tests/cases/UsersTest.php index 1014424a..d5adf8a5 100644 --- a/tests/cases/UsersTest.php +++ b/tests/cases/UsersTest.php @@ -28,7 +28,12 @@ function test_Users_CreateLegal() function test_Users_GetEMoney() { $john = $this->getJohn(); - $ret = $this->_api->Users->GetEMoney($john->Id); + $year = 2019; + $month = 4; + $ret = $this->_api->Users->GetEMoney($john->Id, $year, null); + $this->assertSame($john->Id, $ret->UserId); + + $ret = $this->_api->Users->GetEMoney($john->Id, $year, $month); $this->assertSame($john->Id, $ret->UserId); } From b776ae7065df9ab4b0566611555533e01b2c5379 Mon Sep 17 00:00:00 2001 From: Mihai Moiseanu Date: Tue, 10 Sep 2019 20:25:44 +0300 Subject: [PATCH 2/5] revert php version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 273bc79c..bcd1376d 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "minimum-stability": "stable", "license": "MIT", "require": { - "php": ">=5.6.0", + "php": ">=5.4.0", "ext-curl": "*", "ext-openssl": "*", "psr/log": "^1.0" From 51b9d90f01c09dce3767cbca73980b1913e3a490 Mon Sep 17 00:00:00 2001 From: Mihai Moiseanu Date: Tue, 10 Sep 2019 20:35:57 +0300 Subject: [PATCH 3/5] fix failing tests --- tests/cases/CardPreAuthorizationsTest.php | 2 +- tests/cases/PayInsTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cases/CardPreAuthorizationsTest.php b/tests/cases/CardPreAuthorizationsTest.php index 823b3757..5fddb93d 100644 --- a/tests/cases/CardPreAuthorizationsTest.php +++ b/tests/cases/CardPreAuthorizationsTest.php @@ -19,7 +19,7 @@ function test_CardPreAuthorization_Create() $this->assertSame(\MangoPay\CardPreAuthorizationPaymentStatus::Waiting, $cardPreAuthorization->PaymentStatus); $this->assertSame('DIRECT', $cardPreAuthorization->ExecutionType); $this->assertNull($cardPreAuthorization->PayInId); - $this->assertSame(AVSResult::FULL_MATCH, $cardPreAuthorization->SecurityInfo->AVSResult); + $this->assertSame(AVSResult::NO_CHECK, $cardPreAuthorization->SecurityInfo->AVSResult); } function test_CardPreAuthorization_Get() diff --git a/tests/cases/PayInsTest.php b/tests/cases/PayInsTest.php index 05d828cb..093c94a6 100644 --- a/tests/cases/PayInsTest.php +++ b/tests/cases/PayInsTest.php @@ -79,7 +79,7 @@ function test_PayIns_Get_CardDirect() $this->assertInstanceOf('\MangoPay\PayInExecutionDetailsDirect', $payIn->ExecutionDetails); $this->assertIdenticalInputProps($payIn, $getPayIn); $this->assertNotNull($getPayIn->PaymentDetails->CardId); - $this->assertEquals(AVSResult::FULL_MATCH, $getPayIn->ExecutionDetails->SecurityInfo->AVSResult); + $this->assertEquals(AVSResult::NO_CHECK, $getPayIn->ExecutionDetails->SecurityInfo->AVSResult); } function test_PayIns_CreateRefund_CardDirect() From 6a0871cd645d1e255f7ab9d98660f87d9c94b305 Mon Sep 17 00:00:00 2001 From: Mihai Moiseanu Date: Wed, 11 Sep 2019 10:05:16 +0300 Subject: [PATCH 4/5] remove variable arguments to make sdk compatible with php<5.6 --- MangoPay/Libraries/ApiBase.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/MangoPay/Libraries/ApiBase.php b/MangoPay/Libraries/ApiBase.php index 96aab02f..035331d9 100644 --- a/MangoPay/Libraries/ApiBase.php +++ b/MangoPay/Libraries/ApiBase.php @@ -59,7 +59,7 @@ protected function getLogger() 'payins_bankwire-direct_create' => array('/payins/bankwire/direct/', RequestType::POST), 'payins_directdebit-web_create' => array('/payins/directdebit/web', RequestType::POST), 'payins_directdebit-direct_create' => array('/payins/directdebit/direct', RequestType::POST), - 'payins_directdebitdirect-direct_create' => array( '/payins/directdebit/direct', RequestType::POST ), + 'payins_directdebitdirect-direct_create' => array('/payins/directdebit/direct', RequestType::POST), 'payins_paypal-web_create' => array('/payins/paypal/web', RequestType::POST), 'payins_get' => array('/payins/%s', RequestType::GET), 'payins_createrefunds' => array('/payins/%s/refunds', RequestType::POST), @@ -262,9 +262,17 @@ protected function CreateObject($methodKey, $entity, $responseClassName = null, * @return object Response data * @throws Exception */ - protected function GetObject($methodKey, $responseClassName, ...$params) + protected function GetObject($methodKey, $responseClassName, $firstEntityId = null, $secondEntityId = null, $thirdEntityId = null) { - $urlMethod = vsprintf($this->GetRequestUrl($methodKey), $params); + if (!is_null($thirdEntityId)) { + $urlMethod = sprintf($this->GetRequestUrl($methodKey), $firstEntityId, $secondEntityId, $thirdEntityId); + } else if (!is_null($secondEntityId)) { + $urlMethod = sprintf($this->GetRequestUrl($methodKey), $firstEntityId, $secondEntityId); + } else if (!is_null($firstEntityId)) { + $urlMethod = sprintf($this->GetRequestUrl($methodKey), $firstEntityId); + } else { + $urlMethod = sprintf($this->GetRequestUrl($methodKey)); + } $rest = new RestTool(true, $this->_root); $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey)); From c86023dd160a76999ef1e598d428d126fd31f9c0 Mon Sep 17 00:00:00 2001 From: Mihai Moiseanu Date: Wed, 11 Sep 2019 11:19:57 +0300 Subject: [PATCH 5/5] remove sprintf when you get only the method --- MangoPay/Libraries/ApiBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MangoPay/Libraries/ApiBase.php b/MangoPay/Libraries/ApiBase.php index 035331d9..370d92b7 100644 --- a/MangoPay/Libraries/ApiBase.php +++ b/MangoPay/Libraries/ApiBase.php @@ -271,7 +271,7 @@ protected function GetObject($methodKey, $responseClassName, $firstEntityId = nu } else if (!is_null($firstEntityId)) { $urlMethod = sprintf($this->GetRequestUrl($methodKey), $firstEntityId); } else { - $urlMethod = sprintf($this->GetRequestUrl($methodKey)); + $urlMethod = $this->GetRequestUrl($methodKey); } $rest = new RestTool(true, $this->_root); $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey));