From 4c1514fe8ee4f03d3225d76c8c85ccceb0576829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pu=C5=9Blecki?= Date: Fri, 17 Apr 2015 14:55:36 +0200 Subject: [PATCH] Apply PSR-4 specification --- .../ApiCardPreAuthorizations.php | 2 +- .../ApiCardRegistrations.php | 68 +- .../apiCards.inc => MangoPay/ApiCards.php | 102 +-- .../apiEvents.inc => MangoPay/ApiEvents.php | 2 +- .../apiHooks.inc => MangoPay/ApiHooks.php | 2 +- .../ApiKycDocuments.php | 2 +- .../apiPayIns.inc => MangoPay/ApiPayIns.php | 136 ++-- .../apiPayOuts.inc => MangoPay/ApiPayOuts.php | 4 +- .../apiRefunds.inc => MangoPay/ApiRefunds.php | 32 +- .../ApiTransfers.php | 72 +- .../apiUsers.inc => MangoPay/ApiUsers.php | 569 +++++++------- .../apiWallets.inc => MangoPay/ApiWallets.php | 2 +- MangoPay/Autoloader.php | 30 + .../BankAccount.php | 2 +- .../BankAccountDetails.php | 0 .../BankAccountDetailsCA.php | 2 +- .../BankAccountDetailsGB.php | 2 +- .../BankAccountDetailsIBAN.php | 2 +- .../BankAccountDetailsOTHER.php | 2 +- .../BankAccountDetailsUS.php | 2 +- .../entities/card.inc => MangoPay/Card.php | 110 +-- .../CardPreAuthorization.php | 2 +- .../CardRegistration.php | 166 ++-- MangoPay/CardValidity.php | 8 + .../client.inc => MangoPay/Client.php | 2 +- .../entities/event.inc => MangoPay/Event.php | 2 +- .../tools/enums.inc => MangoPay/EventType.php | 50 -- .../filterBase.inc => MangoPay/FilterBase.php | 2 +- .../FilterEvents.php | 0 .../FilterTransactions.php | 0 .../entities/hook.inc => MangoPay/Hook.php | 2 +- .../KeyValueArray.php | 0 .../KycDocument.php | 2 +- MangoPay/KycDocumentStatus.php | 12 + MangoPay/KycDocumentType.php | 13 + .../kycPage.inc => MangoPay/KycPage.php | 2 +- .../Libraries/ApiBase.php | 718 +++++++++--------- .../Libraries/ApiClients.php | 58 +- .../Libraries/ApiOAuth.php | 58 +- .../Libraries/AuthenticationHelper.php | 136 ++-- .../Libraries/AuthorizationTokenManager.php | 110 +-- .../Libraries/Configuration.php | 2 +- .../Libraries/DefaultStorageStrategy.php | 136 ++-- .../dto.inc => MangoPay/Libraries/Dto.php | 2 +- .../Libraries/EntityBase.php | 2 +- .../error.inc => MangoPay/Libraries/Error.php | 2 +- .../Libraries/Exception.php | 2 +- .../Libraries/IStorageStrategy.php | 38 +- .../logs.inc => MangoPay/Libraries/Logs.php | 2 +- .../Libraries/OAuthToken.php | 92 +-- MangoPay/Libraries/RequestType.php | 12 + .../Libraries/ResponseException.php | 2 +- .../Libraries/RestTool.php | 581 +++++++------- .../Libraries/UrlTool.php | 2 +- .../MangoPayApi.php | 279 ++++--- .../types/money.inc => MangoPay/Money.php | 2 +- .../pagination.inc => MangoPay/Pagination.php | 2 +- .../entities/payIn.inc => MangoPay/PayIn.php | 146 ++-- .../PayInExecutionDetails.php | 0 .../PayInExecutionDetailsDirect.php | 64 +- .../PayInExecutionDetailsWeb.php | 138 ++-- .../PayInPaymentDetails.php | 0 .../PayInPaymentDetailsBankWire.php | 2 +- .../PayInPaymentDetailsCard.php | 40 +- .../PayInPaymentDetailsDirectDebit.php | 2 +- .../PayInPaymentDetailsPreAuthorized.php | 2 +- .../PayInTemplateURLOptions.php | 2 +- .../payOut.inc => MangoPay/PayOut.php | 0 .../PayOutPaymentDetails.php | 0 .../PayOutPaymentDetailsBankWire.php | 2 +- MangoPay/PersonType.php | 10 + .../refund.inc => MangoPay/Refund.php | 102 +-- .../RefundReasonDetails.php | 2 +- MangoPay/SortDirection.php | 7 + .../tools/sorting.inc => MangoPay/Sorting.php | 5 +- .../TemporaryImmediatePayIn.php | 0 .../TemporaryPaymentCard.php | 2 +- .../Transaction.php | 2 +- .../transfer.inc => MangoPay/Transfer.php | 0 .../entities/user.inc => MangoPay/User.php | 6 +- .../userLegal.inc => MangoPay/UserLegal.php | 0 .../UserNatural.php | 0 .../wallet.inc => MangoPay/Wallet.php | 2 +- MangoPaySDK/common/common.inc | 41 - README.md | 13 +- composer.json | 4 +- demos/api/form.php | 22 +- demos/api/htmlHelper.php | 7 +- demos/api/menu.php | 4 +- demos/clients_create.php | 16 +- demos/paymentDirect/non_js.php | 2 +- demos/paymentDirect/payment.php | 4 +- demos/paymentDirect/with_js.php | 2 +- demos/users_all.php | 18 +- demos/users_create.php | 18 +- demos/users_get.php | 20 +- demos/workflow/inc/config.php | 2 +- demos/workflow/inc/mockStorage.php | 6 +- demos/workflow/index.php | 12 +- tests/cases/base.php | 6 +- tests/cases/clients.php | 2 +- tests/cases/configurations.php | 2 +- tests/cases/tokens.php | 2 +- tests/cases/users.php | 10 +- tests/mocks/mockStorageStrategy.php | 6 +- 105 files changed, 2209 insertions(+), 2192 deletions(-) rename MangoPaySDK/tools/apiCardPreAuthorizations.inc => MangoPay/ApiCardPreAuthorizations.php (95%) rename MangoPaySDK/tools/apiCardRegistrations.inc => MangoPay/ApiCardRegistrations.php (94%) rename MangoPaySDK/tools/apiCards.inc => MangoPay/ApiCards.php (95%) rename MangoPaySDK/tools/apiEvents.inc => MangoPay/ApiEvents.php (92%) rename MangoPaySDK/tools/apiHooks.inc => MangoPay/ApiHooks.php (96%) rename MangoPaySDK/tools/apiKycDocuments.inc => MangoPay/ApiKycDocuments.php (91%) rename MangoPaySDK/tools/apiPayIns.inc => MangoPay/ApiPayIns.php (89%) rename MangoPaySDK/tools/apiPayOuts.inc => MangoPay/ApiPayOuts.php (87%) rename MangoPaySDK/tools/apiRefunds.inc => MangoPay/ApiRefunds.php (87%) rename MangoPaySDK/tools/apiTransfers.inc => MangoPay/ApiTransfers.php (93%) rename MangoPaySDK/tools/apiUsers.inc => MangoPay/ApiUsers.php (89%) rename MangoPaySDK/tools/apiWallets.inc => MangoPay/ApiWallets.php (97%) create mode 100644 MangoPay/Autoloader.php rename MangoPaySDK/entities/bankAccount.inc => MangoPay/BankAccount.php (96%) rename MangoPaySDK/types/bankAccountDetails.inc => MangoPay/BankAccountDetails.php (100%) rename MangoPaySDK/types/bankAccountDetailsCA.inc => MangoPay/BankAccountDetailsCA.php (84%) rename MangoPaySDK/types/bankAccountDetailsGB.inc => MangoPay/BankAccountDetailsGB.php (77%) rename MangoPaySDK/types/bankAccountDetailsIBAN.inc => MangoPay/BankAccountDetailsIBAN.php (75%) rename MangoPaySDK/types/bankAccountDetailsOTHER.inc => MangoPay/BankAccountDetailsOTHER.php (85%) rename MangoPaySDK/types/bankAccountDetailsUS.inc => MangoPay/BankAccountDetailsUS.php (76%) rename MangoPaySDK/entities/card.inc => MangoPay/Card.php (88%) rename MangoPaySDK/entities/cardPreAuthorization.inc => MangoPay/CardPreAuthorization.php (98%) rename MangoPaySDK/entities/cardRegistration.inc => MangoPay/CardRegistration.php (92%) create mode 100644 MangoPay/CardValidity.php rename MangoPaySDK/entities/client.inc => MangoPay/Client.php (90%) rename MangoPaySDK/entities/event.inc => MangoPay/Event.php (89%) rename MangoPaySDK/tools/enums.inc => MangoPay/EventType.php (56%) rename MangoPaySDK/tools/filterBase.inc => MangoPay/FilterBase.php (90%) rename MangoPaySDK/tools/filterEvents.inc => MangoPay/FilterEvents.php (100%) rename MangoPaySDK/tools/filterTransactions.inc => MangoPay/FilterTransactions.php (100%) rename MangoPaySDK/entities/hook.inc => MangoPay/Hook.php (91%) rename MangoPaySDK/types/keyValueArray.inc => MangoPay/KeyValueArray.php (100%) rename MangoPaySDK/entities/kycDocument.inc => MangoPay/KycDocument.php (91%) create mode 100644 MangoPay/KycDocumentStatus.php create mode 100644 MangoPay/KycDocumentType.php rename MangoPaySDK/entities/kycPage.inc => MangoPay/KycPage.php (80%) rename MangoPaySDK/tools/apiBase.inc => MangoPay/Libraries/ApiBase.php (97%) rename MangoPaySDK/tools/apiClients.inc => MangoPay/Libraries/ApiClients.php (95%) rename MangoPaySDK/tools/apiOAuth.inc => MangoPay/Libraries/ApiOAuth.php (87%) rename MangoPaySDK/tools/authenticationHelper.inc => MangoPay/Libraries/AuthenticationHelper.php (85%) rename MangoPaySDK/tools/authorizationTokenManager.inc => MangoPay/Libraries/AuthorizationTokenManager.php (88%) rename MangoPaySDK/types/configuration.inc => MangoPay/Libraries/Configuration.php (97%) rename MangoPaySDK/tools/defaultStorageStrategy.inc => MangoPay/Libraries/DefaultStorageStrategy.php (76%) rename MangoPaySDK/types/dto.inc => MangoPay/Libraries/Dto.php (96%) rename MangoPaySDK/entities/entityBase.inc => MangoPay/Libraries/EntityBase.php (96%) rename MangoPaySDK/types/error.inc => MangoPay/Libraries/Error.php (91%) rename MangoPaySDK/types/exceptions/exception.inc => MangoPay/Libraries/Exception.php (60%) rename MangoPaySDK/tools/iStorageStrategy.inc => MangoPay/Libraries/IStorageStrategy.php (57%) rename MangoPaySDK/tools/logs.inc => MangoPay/Libraries/Logs.php (90%) rename MangoPaySDK/types/oAuthToken.inc => MangoPay/Libraries/OAuthToken.php (91%) create mode 100644 MangoPay/Libraries/RequestType.php rename MangoPaySDK/types/exceptions/responseException.inc => MangoPay/Libraries/ResponseException.php (98%) rename MangoPaySDK/tools/restTool.inc => MangoPay/Libraries/RestTool.php (95%) rename MangoPaySDK/tools/urlTool.inc => MangoPay/Libraries/UrlTool.php (98%) rename MangoPaySDK/mangoPayApi.inc => MangoPay/MangoPayApi.php (87%) rename MangoPaySDK/types/money.inc => MangoPay/Money.php (89%) rename MangoPaySDK/types/pagination.inc => MangoPay/Pagination.php (96%) rename MangoPaySDK/entities/payIn.inc => MangoPay/PayIn.php (96%) rename MangoPaySDK/types/payInExecutionDetails.inc => MangoPay/PayInExecutionDetails.php (100%) rename MangoPaySDK/types/payInExecutionDetailsDirect.inc => MangoPay/PayInExecutionDetailsDirect.php (81%) rename MangoPaySDK/types/payInExecutionDetailsWeb.inc => MangoPay/PayInExecutionDetailsWeb.php (90%) rename MangoPaySDK/types/payInPaymentDetails.inc => MangoPay/PayInPaymentDetails.php (100%) rename MangoPaySDK/types/payInPaymentDetailsBankWire.inc => MangoPay/PayInPaymentDetailsBankWire.php (90%) rename MangoPaySDK/types/payInPaymentDetailsCard.inc => MangoPay/PayInPaymentDetailsCard.php (74%) rename MangoPaySDK/types/payInPaymentDetailsDirectDebit.inc => MangoPay/PayInPaymentDetailsDirectDebit.php (70%) rename MangoPaySDK/types/payInPaymentDetailsPreAuthorized.inc => MangoPay/PayInPaymentDetailsPreAuthorized.php (69%) rename MangoPaySDK/types/payInTemplateURLOptions.inc => MangoPay/PayInTemplateURLOptions.php (75%) rename MangoPaySDK/entities/payOut.inc => MangoPay/PayOut.php (100%) rename MangoPaySDK/types/payOutPaymentDetails.inc => MangoPay/PayOutPaymentDetails.php (100%) rename MangoPaySDK/types/payOutPaymentDetailsBankWire.inc => MangoPay/PayOutPaymentDetailsBankWire.php (78%) create mode 100644 MangoPay/PersonType.php rename MangoPaySDK/entities/refund.inc => MangoPay/Refund.php (95%) rename MangoPaySDK/types/refundReasonDetails.inc => MangoPay/RefundReasonDetails.php (86%) create mode 100644 MangoPay/SortDirection.php rename MangoPaySDK/tools/sorting.inc => MangoPay/Sorting.php (95%) rename MangoPaySDK/entities/temporaryImmediatePayIn.inc => MangoPay/TemporaryImmediatePayIn.php (100%) rename MangoPaySDK/entities/temporaryPaymentCard.inc => MangoPay/TemporaryPaymentCard.php (92%) rename MangoPaySDK/entities/transaction.inc => MangoPay/Transaction.php (97%) rename MangoPaySDK/entities/transfer.inc => MangoPay/Transfer.php (100%) rename MangoPaySDK/entities/user.inc => MangoPay/User.php (93%) rename MangoPaySDK/entities/userLegal.inc => MangoPay/UserLegal.php (100%) rename MangoPaySDK/entities/userNatural.inc => MangoPay/UserNatural.php (100%) rename MangoPaySDK/entities/wallet.inc => MangoPay/Wallet.php (95%) delete mode 100644 MangoPaySDK/common/common.inc diff --git a/MangoPaySDK/tools/apiCardPreAuthorizations.inc b/MangoPay/ApiCardPreAuthorizations.php similarity index 95% rename from MangoPaySDK/tools/apiCardPreAuthorizations.inc rename to MangoPay/ApiCardPreAuthorizations.php index 9f82eda9..29f612af 100644 --- a/MangoPaySDK/tools/apiCardPreAuthorizations.inc +++ b/MangoPay/ApiCardPreAuthorizations.php @@ -4,7 +4,7 @@ /** * Class to management MangoPay API for pre-authorization process */ -class ApiCardPreAuthorizations extends ApiBase { +class ApiCardPreAuthorizations extends Libraries\ApiBase { /** * Create new pre-authorization object diff --git a/MangoPaySDK/tools/apiCardRegistrations.inc b/MangoPay/ApiCardRegistrations.php similarity index 94% rename from MangoPaySDK/tools/apiCardRegistrations.inc rename to MangoPay/ApiCardRegistrations.php index 4d23226c..78bd8fd8 100644 --- a/MangoPaySDK/tools/apiCardRegistrations.inc +++ b/MangoPay/ApiCardRegistrations.php @@ -1,35 +1,35 @@ -CreateObject('cardregistration_create', $cardRegistration, '\MangoPay\CardRegistration'); - } - - /** - * Get card registration - * @param int $cardRegistrationId Card Registration identifier - * @return \MangoPay\CardRegistration Card registration object returned from API - */ - public function Get($cardRegistrationId) { - return $this->GetObject('cardregistration_get', $cardRegistrationId, '\MangoPay\CardRegistration'); - } - - /** - * Update card registration - * @param \MangoPay\CardRegistration $cardRegistration Card registration object to save - * @return \MangoPay\CardRegistration Card registration object returned from API - */ - public function Update($cardRegistration) { - return $this->SaveObject('cardregistration_save', $cardRegistration, '\MangoPay\CardRegistration'); - } +CreateObject('cardregistration_create', $cardRegistration, '\MangoPay\CardRegistration'); + } + + /** + * Get card registration + * @param int $cardRegistrationId Card Registration identifier + * @return \MangoPay\CardRegistration Card registration object returned from API + */ + public function Get($cardRegistrationId) { + return $this->GetObject('cardregistration_get', $cardRegistrationId, '\MangoPay\CardRegistration'); + } + + /** + * Update card registration + * @param \MangoPay\CardRegistration $cardRegistration Card registration object to save + * @return \MangoPay\CardRegistration Card registration object returned from API + */ + public function Update($cardRegistration) { + return $this->SaveObject('cardregistration_save', $cardRegistration, '\MangoPay\CardRegistration'); + } } \ No newline at end of file diff --git a/MangoPaySDK/tools/apiCards.inc b/MangoPay/ApiCards.php similarity index 95% rename from MangoPaySDK/tools/apiCards.inc rename to MangoPay/ApiCards.php index 6e2a346e..d3653296 100644 --- a/MangoPaySDK/tools/apiCards.inc +++ b/MangoPay/ApiCards.php @@ -1,52 +1,52 @@ -GetObject('card_get', $cardId, '\MangoPay\Card'); - } - - /** - * Update card - * @param \MangoPay\Card $card Card object to save - * @return \MangoPay\Card Card object returned from API - */ - public function Update($card) { - return $this->SaveObject('card_save', $card, '\MangoPay\Card'); - } - - /** - * WARNING!! - * It's temporary entity and it will be removed in the future. - * Please, contact with support before using these features or if you have any questions. - * - * Create new temporary payment card - * @param \MangoPay\TemporaryPaymentCard $paymentCard Payment card object to create - * @return \MangoPay\TemporaryPaymentCard Card registration object returned from API - */ - public function CreateTemporaryPaymentCard($paymentCard) { - return $this->CreateObject('temp_paymentcards_create', $paymentCard, '\MangoPay\TemporaryPaymentCard'); - } - - /** - * WARNING!! - * It's temporary entity and it will be removed in the future. - * Please, contact with support before using these features or if you have any questions. - * - * Get temporary payment card - * @param string $paymentCardId Card identifier - * @return \MangoPay\TemporaryPaymentCard object returned from API - */ - public function GetTemporaryPaymentCard($paymentCardId) { - return $this->GetObject('temp_paymentcards_get', $paymentCardId, '\MangoPay\TemporaryPaymentCard'); - } +GetObject('card_get', $cardId, '\MangoPay\Card'); + } + + /** + * Update card + * @param \MangoPay\Card $card Card object to save + * @return \MangoPay\Card Card object returned from API + */ + public function Update($card) { + return $this->SaveObject('card_save', $card, '\MangoPay\Card'); + } + + /** + * WARNING!! + * It's temporary entity and it will be removed in the future. + * Please, contact with support before using these features or if you have any questions. + * + * Create new temporary payment card + * @param \MangoPay\TemporaryPaymentCard $paymentCard Payment card object to create + * @return \MangoPay\TemporaryPaymentCard Card registration object returned from API + */ + public function CreateTemporaryPaymentCard($paymentCard) { + return $this->CreateObject('temp_paymentcards_create', $paymentCard, '\MangoPay\TemporaryPaymentCard'); + } + + /** + * WARNING!! + * It's temporary entity and it will be removed in the future. + * Please, contact with support before using these features or if you have any questions. + * + * Get temporary payment card + * @param string $paymentCardId Card identifier + * @return \MangoPay\TemporaryPaymentCard object returned from API + */ + public function GetTemporaryPaymentCard($paymentCardId) { + return $this->GetObject('temp_paymentcards_get', $paymentCardId, '\MangoPay\TemporaryPaymentCard'); + } } \ No newline at end of file diff --git a/MangoPaySDK/tools/apiEvents.inc b/MangoPay/ApiEvents.php similarity index 92% rename from MangoPaySDK/tools/apiEvents.inc rename to MangoPay/ApiEvents.php index 3d23fdfd..28c26a42 100644 --- a/MangoPaySDK/tools/apiEvents.inc +++ b/MangoPay/ApiEvents.php @@ -4,7 +4,7 @@ /** * Class to management MangoPay API for cards */ -class ApiEvents extends ApiBase { +class ApiEvents extends Libraries\ApiBase { /** * Get events diff --git a/MangoPaySDK/tools/apiHooks.inc b/MangoPay/ApiHooks.php similarity index 96% rename from MangoPaySDK/tools/apiHooks.inc rename to MangoPay/ApiHooks.php index c08e4d54..2954be49 100644 --- a/MangoPaySDK/tools/apiHooks.inc +++ b/MangoPay/ApiHooks.php @@ -4,7 +4,7 @@ /** * Class to management MangoPay API for hooks and notifications */ -class ApiHooks extends ApiBase { +class ApiHooks extends Libraries\ApiBase { /** * Create new hook diff --git a/MangoPaySDK/tools/apiKycDocuments.inc b/MangoPay/ApiKycDocuments.php similarity index 91% rename from MangoPaySDK/tools/apiKycDocuments.inc rename to MangoPay/ApiKycDocuments.php index 8bcfa5ae..b80811fc 100644 --- a/MangoPaySDK/tools/apiKycDocuments.inc +++ b/MangoPay/ApiKycDocuments.php @@ -4,7 +4,7 @@ /** * Class to management MangoPay API for KYC document list */ -class ApiKycDocuments extends ApiBase { +class ApiKycDocuments extends Libraries\ApiBase { /** * Get all KYC documents diff --git a/MangoPaySDK/tools/apiPayIns.inc b/MangoPay/ApiPayIns.php similarity index 89% rename from MangoPaySDK/tools/apiPayIns.inc rename to MangoPay/ApiPayIns.php index 90bf9972..04256ec5 100644 --- a/MangoPaySDK/tools/apiPayIns.inc +++ b/MangoPay/ApiPayIns.php @@ -1,69 +1,69 @@ -GetPaymentKey($payIn); - $executionKey = $this->GetExecutionKey($payIn); - return $this->CreateObject('payins_' . $paymentKey . '-' . $executionKey . '_create', $payIn, '\MangoPay\PayIn'); - } - - /** - * Get pay-in object - * @param $payInId Pay-in identifier - * @return \MangoPay\PayIn Object returned from API - */ - public function Get($payInId) { - return $this->GetObject('payins_get', $payInId, '\MangoPay\PayIn'); - } - - /** - * Create refund for pay-in object - * @param type $payInId Pay-in identifier - * @param \MangoPay\Refund $refund Refund object to create - * @return \MangoPay\Refund Object returned by REST API - */ - public function CreateRefund($payInId, $refund) { - return $this->CreateObject('payins_createrefunds', $refund, '\MangoPay\Refund', $payInId); - } - - /** - * WARNING!! - * It's temporary entity and it will be removed in the future. - * Please, contact with support before using these features or if you have any questions. - * - * Create new temporary immediate pay-in - * @param \MangoPay\TemporaryImmediatePayIn $immediatePayIn Immediate pay-in object to create - * @return \MangoPay\TemporaryImmediatePayIn Immediate pay-in object returned from API - */ - public function CreateTemporaryImmediatePayIn($immediatePayIn) { - return $this->CreateObject('temp_immediatepayins_create', $immediatePayIn, '\MangoPay\TemporaryImmediatePayIn'); - } - - private function GetPaymentKey($payIn) { - - if (!isset($payIn->PaymentDetails) || !is_object($payIn->PaymentDetails)) - throw new Exception ('Payment is not defined or it is not object type'); - - $className = str_replace('MangoPay\\PayInPaymentDetails', '', get_class($payIn->PaymentDetails)); - return strtolower($className); - } - - private function GetExecutionKey($payIn) { - - if (!isset($payIn->ExecutionDetails) || !is_object($payIn->ExecutionDetails)) - throw new Exception ('Execution is not defined or it is not object type'); - - $className = str_replace('MangoPay\\PayInExecutionDetails', '', get_class($payIn->ExecutionDetails)); - return strtolower($className); - } +GetPaymentKey($payIn); + $executionKey = $this->GetExecutionKey($payIn); + return $this->CreateObject('payins_' . $paymentKey . '-' . $executionKey . '_create', $payIn, '\MangoPay\PayIn'); + } + + /** + * Get pay-in object + * @param $payInId Pay-in identifier + * @return \MangoPay\PayIn Object returned from API + */ + public function Get($payInId) { + return $this->GetObject('payins_get', $payInId, '\MangoPay\PayIn'); + } + + /** + * Create refund for pay-in object + * @param type $payInId Pay-in identifier + * @param \MangoPay\Refund $refund Refund object to create + * @return \MangoPay\Refund Object returned by REST API + */ + public function CreateRefund($payInId, $refund) { + return $this->CreateObject('payins_createrefunds', $refund, '\MangoPay\Refund', $payInId); + } + + /** + * WARNING!! + * It's temporary entity and it will be removed in the future. + * Please, contact with support before using these features or if you have any questions. + * + * Create new temporary immediate pay-in + * @param \MangoPay\TemporaryImmediatePayIn $immediatePayIn Immediate pay-in object to create + * @return \MangoPay\TemporaryImmediatePayIn Immediate pay-in object returned from API + */ + public function CreateTemporaryImmediatePayIn($immediatePayIn) { + return $this->CreateObject('temp_immediatepayins_create', $immediatePayIn, '\MangoPay\TemporaryImmediatePayIn'); + } + + private function GetPaymentKey($payIn) { + + if (!isset($payIn->PaymentDetails) || !is_object($payIn->PaymentDetails)) + throw new Libraries\Exception ('Payment is not defined or it is not object type'); + + $className = str_replace('MangoPay\\PayInPaymentDetails', '', get_class($payIn->PaymentDetails)); + return strtolower($className); + } + + private function GetExecutionKey($payIn) { + + if (!isset($payIn->ExecutionDetails) || !is_object($payIn->ExecutionDetails)) + throw new Libraries\Exception ('Execution is not defined or it is not object type'); + + $className = str_replace('MangoPay\\PayInExecutionDetails', '', get_class($payIn->ExecutionDetails)); + return strtolower($className); + } } \ No newline at end of file diff --git a/MangoPaySDK/tools/apiPayOuts.inc b/MangoPay/ApiPayOuts.php similarity index 87% rename from MangoPaySDK/tools/apiPayOuts.inc rename to MangoPay/ApiPayOuts.php index 4abb7d50..c6ea18e3 100644 --- a/MangoPaySDK/tools/apiPayOuts.inc +++ b/MangoPay/ApiPayOuts.php @@ -4,7 +4,7 @@ /** * Class to management MangoPay API for pay-outs */ -class ApiPayOuts extends ApiBase { +class ApiPayOuts extends Libraries\ApiBase { /** * Create new pay-out @@ -28,7 +28,7 @@ public function Get($payOutId) { private function GetPaymentKey($payOut) { if (!isset($payOut->MeanOfPaymentDetails) || !is_object($payOut->MeanOfPaymentDetails)) - throw new Exception('Mean of payment is not defined or it is not object type'); + 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/MangoPaySDK/tools/apiRefunds.inc b/MangoPay/ApiRefunds.php similarity index 87% rename from MangoPaySDK/tools/apiRefunds.inc rename to MangoPay/ApiRefunds.php index 4d5d7a81..49e9b1bc 100644 --- a/MangoPaySDK/tools/apiRefunds.inc +++ b/MangoPay/ApiRefunds.php @@ -1,17 +1,17 @@ -GetObject('refunds_get', $refundId, '\MangoPay\Refund'); - } +GetObject('refunds_get', $refundId, '\MangoPay\Refund'); + } } \ No newline at end of file diff --git a/MangoPaySDK/tools/apiTransfers.inc b/MangoPay/ApiTransfers.php similarity index 93% rename from MangoPaySDK/tools/apiTransfers.inc rename to MangoPay/ApiTransfers.php index 2959ffb1..e65eaaae 100644 --- a/MangoPaySDK/tools/apiTransfers.inc +++ b/MangoPay/ApiTransfers.php @@ -1,36 +1,36 @@ -CreateObject('transfers_create', $transfer, '\MangoPay\Transfer'); - } - - /** - * Get transfer - * @param type $transferId Transfer identifier - * @return \MangoPay\Transfer Transfer object returned from API - */ - public function Get($transfer) { - return $this->GetObject('transfers_get', $transfer, '\MangoPay\Transfer'); - } - - /** - * Create refund for transfer object - * @param type $transferId Transfer identifier - * @param \MangoPay\Refund $refund Refund object to create - * @return \MangoPay\Refund Object returned by REST API - */ - public function CreateRefund($transferId, $refund) { - return $this->CreateObject('transfers_createrefunds', $refund, '\MangoPay\Refund', $transferId); - } -} +CreateObject('transfers_create', $transfer, '\MangoPay\Transfer'); + } + + /** + * Get transfer + * @param type $transferId Transfer identifier + * @return \MangoPay\Transfer Transfer object returned from API + */ + public function Get($transfer) { + return $this->GetObject('transfers_get', $transfer, '\MangoPay\Transfer'); + } + + /** + * Create refund for transfer object + * @param type $transferId Transfer identifier + * @param \MangoPay\Refund $refund Refund object to create + * @return \MangoPay\Refund Object returned by REST API + */ + public function CreateRefund($transferId, $refund) { + return $this->CreateObject('transfers_createrefunds', $refund, '\MangoPay\Refund', $transferId); + } +} diff --git a/MangoPaySDK/tools/apiUsers.inc b/MangoPay/ApiUsers.php similarity index 89% rename from MangoPaySDK/tools/apiUsers.inc rename to MangoPay/ApiUsers.php index e7002106..84a13cbf 100644 --- a/MangoPaySDK/tools/apiUsers.inc +++ b/MangoPay/ApiUsers.php @@ -1,284 +1,285 @@ -CreateObject($methodKey, $user); - return $this->GetUserResponse($response); - } - - /** - * Get all users - * @param \MangoPay\Pagination $pagination Pagination object - * @param \MangoPay\Sorting $sorting Object to sorting data - * @return array Array with users - */ - public function GetAll(& $pagination = null, $sorting = null) { - $usersList = $this->GetList('users_all', $pagination, null, null, null, $sorting); - - $users = array(); - if (is_array($usersList)) { - foreach ($usersList as $user) { - array_push($users, $this->GetUserResponse($user)); - } - } - return $users; - } - - /** - * Get natural or legal user by ID - * @param Int/GUID $userId User identifier - * @return UserLegal/UserNatural User object returned from API - */ - public function Get($userId) { - - $response = $this->GetObject('users_get', $userId); - return $this->GetUserResponse($response); - } - - /** - * Get natural user by ID - * @param Int/GUID $userId User identifier - * @return UserLegal/UserNatural User object returned from API - */ - public function GetNatural($userId) { - - $response = $this->GetObject('users_getnaturals', $userId); - return $this->GetUserResponse($response); - } - - /** - * Get legal user by ID - * @param Int/GUID $userId User identifier - * @return UserLegal/UserNatural User object returned from API - */ - public function GetLegal($userId) { - - $response = $this->GetObject('users_getlegals', $userId); - return $this->GetUserResponse($response); - } - - /** - * Save user - * @param UserLegal/UserNatural $user - * @return UserLegal/UserNatural User object returned from API - */ - public function Update($user) { - - $className = get_class($user); - if ($className == 'MangoPay\UserNatural') - $methodKey = 'users_savenaturals'; - elseif ($className == 'MangoPay\UserLegal') - $methodKey = 'users_savelegals'; - else - throw new Exception('Wrong entity class for user'); - - $response = $this->SaveObject($methodKey, $user); - return $this->GetUserResponse($response); - } - - /** - * Create bank account for user - * @param int $userId User Id - * @param \MangoPay\BankAccount $bankAccount Entity of bank account object - * @return \MangoPay\BankAccount Create bank account object - */ - public function CreateBankAccount($userId, $bankAccount) { - $type = $this->GetBankAccountType($bankAccount); - return $this->CreateObject('users_createbankaccounts_' . $type, $bankAccount, '\MangoPay\BankAccount', $userId); - } - - /** - * Get all bank accounts for user - * @param int $userId User Id - * @param \MangoPay\Pagination $pagination Pagination object - * @param \MangoPay\Sorting $sorting Object to sorting data - * - * @return array Array with bank account entities - */ - public function GetBankAccounts($userId, & $pagination = null, $sorting = null) { - return $this->GetList('users_allbankaccount', $pagination, 'MangoPay\BankAccount', $userId, null, $sorting); - } - - /** - * Get bank account for user - * @param int $userId User Id - * @param int $bankAccountId Bank account Id - * - * @return \MangoPay\BankAccount Entity of bank account object - */ - public function GetBankAccount($userId, $bankAccountId) { - return $this->GetObject('users_getbankaccount', $userId, 'MangoPay\BankAccount', $bankAccountId); - } - - /** - * Get all wallets for user - * @param int $userId User Id - * @param \MangoPay\Pagination $pagination Pagination object - * @param \MangoPay\Sorting $sorting Object to sorting data - * - * @return \MangoPay\Wallet[] Array with objects returned from API - */ - public function GetWallets($userId, & $pagination = null, $sorting = null) { - return $this->GetList('users_allwallets', $pagination, 'MangoPay\Wallet', $userId, null, $sorting); - } - - /** - * Get all transactions for user - * @param int $userId User Id - * @param \MangoPay\Pagination $pagination Pagination object - * @param \MangoPay\FilterTransactions $filter Object to filter data - * @param \MangoPay\Sorting $sorting Object to sorting data - * - * @return \MangoPay\Transaction[] Transactions for user returned from API - */ - public function GetTransactions($userId, & $pagination = null, $filter = null, $sorting = null) { - return $this->GetList('users_alltransactions', $pagination, '\MangoPay\Transaction', $userId, $filter, $sorting); - } - - /** - * Get all cards for user - * @param int $userId User Id - * @param \MangoPay\Pagination $pagination Pagination object - * @param \MangoPay\Sorting $sorting Object to sorting data - * - * @return \MangoPay\Card[] Cards for user returned from API - */ - public function GetCards($userId, & $pagination = null, $sorting = null) { - return $this->GetList('users_allcards', $pagination, '\MangoPay\Card', $userId, null, $sorting); - } - - /** - * Create new KYC document - * @param int $userId User Id - * @param \MangoPay\KycDocument $kycDocument - * @return \MangoPay\KycDocument Document returned from API - */ - public function CreateKycDocument($userId, $kycDocument) { - return $this->CreateObject('kyc_documents_create', $kycDocument, '\MangoPay\KycDocument', $userId); - } - - /** - * Get all KYC documents for user - * @param int $userId User Id - * @param \MangoPay\Pagination $pagination Pagination object - * @param \MangoPay\Sorting $sorting Object to sorting data - * - * @return array Array with KYC documents entities - */ - public function GetKycDocuments($userId, & $pagination = null, $sorting = null) { - return $this->GetList('users_allkycdocuments', $pagination, 'MangoPay\KycDocument', $userId, null, $sorting); - } - - /** - * Get KYC document - * @param int $userId User Id - * @param string $kycDocumentId Document identifier - * @return \MangoPay\KycDocument Document returned from API - */ - public function GetKycDocument($userId, $kycDocumentId) { - return $this->GetObject('kyc_documents_get', $userId, '\MangoPay\KycDocument', $kycDocumentId); - } - - /** - * Save KYC document - * @param int $userId User Id - * @param \MangoPay\KycDocument $kycDocument Document to save - * @return \MangoPay\KycDocument Document returned from API - */ - public function UpdateKycDocument($userId, $kycDocument) { - return $this->SaveObject('kyc_documents_save', $kycDocument, '\MangoPay\KycDocument', $userId); - } - - /** - * Create page for Kyc document - * @param int $userId User Id - * @param \MangoPay\KycPage $page Kyc - */ - public function CreateKycPage($userId, $kycDocumentId, $kycPage) { - - try{ - $this->CreateObject('kyc_page_create', $kycPage, null, $userId, $kycDocumentId); - } catch (\MangoPay\ResponseException $exc) { - if ($exc->getCode() != 204) - throw $exc; - } - } - - /** - * Create page for Kyc document from file - * @param int $userId User Id - * @param \MangoPay\KycPage $page Kyc - */ - public function CreateKycPageFromFile($userId, $kycDocumentId, $file) { - - $filePath = $file; - if (is_array($file)) { - $filePath = $file['tmp_name']; - } - - if (empty($filePath)) - throw new \MangoPay\Exception('Path of file cannot be empty'); - - if (!file_exists($filePath)) - throw new \MangoPay\Exception('File not exist'); - - $kycPage = new \MangoPay\KycPage(); - $kycPage->File = base64_encode(file_get_contents($filePath)); - - if (empty($kycPage->File)) - throw new \MangoPay\Exception('Content of the file cannot be empty'); - - $this->CreateKycPage($userId, $kycDocumentId, $kycPage); - } - - /** - * Get correct user object - * @param object $response Response from API - * @return UserLegal/UserNatural User object returned from API - * @throws \MangoPay\Exception If occur unexpected response from API - */ - private function GetUserResponse($response) { - - if (isset($response->PersonType)) { - - switch ($response->PersonType) { - case PersonType::Natural: - return $this->CastResponseToEntity($response, '\MangoPay\UserNatural'); - case PersonType::Legal: - return $this->CastResponseToEntity($response, '\MangoPay\UserLegal'); - default: - throw new Exception('Unexpected response. Wrong PersonType value'); - } - } else { - throw new Exception('Unexpected response. Missing PersonType property'); - } - } - - private function GetBankAccountType($bankAccount) { - - if (!isset($bankAccount->Details) || !is_object($bankAccount->Details)) - throw new Exception ('Details is not defined or it is not object type'); - - $className = str_replace('MangoPay\\BankAccountDetails', '', get_class($bankAccount->Details)); - return strtolower($className); - } -} +CreateObject($methodKey, $user); + return $this->GetUserResponse($response); + } + + /** + * Get all users + * @param \MangoPay\Pagination $pagination Pagination object + * @param \MangoPay\Sorting $sorting Object to sorting data + * @return array Array with users + */ + public function GetAll(& $pagination = null, $sorting = null) { + $usersList = $this->GetList('users_all', $pagination, null, null, null, $sorting); + + $users = array(); + if (is_array($usersList)) { + foreach ($usersList as $user) { + array_push($users, $this->GetUserResponse($user)); + } + } + return $users; + } + + /** + * Get natural or legal user by ID + * @param Int/GUID $userId User identifier + * @return UserLegal/UserNatural User object returned from API + */ + public function Get($userId) { + + $response = $this->GetObject('users_get', $userId); + return $this->GetUserResponse($response); + } + + /** + * Get natural user by ID + * @param Int/GUID $userId User identifier + * @return UserLegal/UserNatural User object returned from API + */ + public function GetNatural($userId) { + + $response = $this->GetObject('users_getnaturals', $userId); + return $this->GetUserResponse($response); + } + + /** + * Get legal user by ID + * @param Int/GUID $userId User identifier + * @return UserLegal/UserNatural User object returned from API + */ + public function GetLegal($userId) { + + $response = $this->GetObject('users_getlegals', $userId); + return $this->GetUserResponse($response); + } + + /** + * Save user + * @param UserLegal/UserNatural $user + * @return UserLegal/UserNatural User object returned from API + */ + public function Update($user) { + + $className = get_class($user); + if ($className == 'MangoPay\UserNatural') + $methodKey = 'users_savenaturals'; + elseif ($className == 'MangoPay\UserLegal') + $methodKey = 'users_savelegals'; + else + throw new Libraries\Exception('Wrong entity class for user'); + + $response = $this->SaveObject($methodKey, $user); + return $this->GetUserResponse($response); + } + + /** + * Create bank account for user + * @param int $userId User Id + * @param \MangoPay\BankAccount $bankAccount Entity of bank account object + * @return \MangoPay\BankAccount Create bank account object + */ + public function CreateBankAccount($userId, $bankAccount) { + $type = $this->GetBankAccountType($bankAccount); + return $this->CreateObject('users_createbankaccounts_' . $type, $bankAccount, '\MangoPay\BankAccount', $userId); + } + + /** + * Get all bank accounts for user + * @param int $userId User Id + * @param \MangoPay\Pagination $pagination Pagination object + * @param \MangoPay\Sorting $sorting Object to sorting data + * + * @return array Array with bank account entities + */ + public function GetBankAccounts($userId, & $pagination = null, $sorting = null) { + return $this->GetList('users_allbankaccount', $pagination, 'MangoPay\BankAccount', $userId, null, $sorting); + } + + /** + * Get bank account for user + * @param int $userId User Id + * @param int $bankAccountId Bank account Id + * + * @return \MangoPay\BankAccount Entity of bank account object + */ + public function GetBankAccount($userId, $bankAccountId) { + return $this->GetObject('users_getbankaccount', $userId, 'MangoPay\BankAccount', $bankAccountId); + } + + /** + * Get all wallets for user + * @param int $userId User Id + * @param \MangoPay\Pagination $pagination Pagination object + * @param \MangoPay\Sorting $sorting Object to sorting data + * + * @return \MangoPay\Wallet[] Array with objects returned from API + */ + public function GetWallets($userId, & $pagination = null, $sorting = null) { + return $this->GetList('users_allwallets', $pagination, 'MangoPay\Wallet', $userId, null, $sorting); + } + + /** + * Get all transactions for user + * @param int $userId User Id + * @param \MangoPay\Pagination $pagination Pagination object + * @param \MangoPay\FilterTransactions $filter Object to filter data + * @param \MangoPay\Sorting $sorting Object to sorting data + * + * @return \MangoPay\Transaction[] Transactions for user returned from API + */ + public function GetTransactions($userId, & $pagination = null, $filter = null, $sorting = null) { + return $this->GetList('users_alltransactions', $pagination, '\MangoPay\Transaction', $userId, $filter, $sorting); + } + + /** + * Get all cards for user + * @param int $userId User Id + * @param \MangoPay\Pagination $pagination Pagination object + * @param \MangoPay\Sorting $sorting Object to sorting data + * + * @return \MangoPay\Card[] Cards for user returned from API + */ + public function GetCards($userId, & $pagination = null, $sorting = null) { + return $this->GetList('users_allcards', $pagination, '\MangoPay\Card', $userId, null, $sorting); + } + + /** + * Create new KYC document + * @param int $userId User Id + * @param \MangoPay\KycDocument $kycDocument + * @return \MangoPay\KycDocument Document returned from API + */ + public function CreateKycDocument($userId, $kycDocument) { + return $this->CreateObject('kyc_documents_create', $kycDocument, '\MangoPay\KycDocument', $userId); + } + + /** + * Get all KYC documents for user + * @param int $userId User Id + * @param \MangoPay\Pagination $pagination Pagination object + * @param \MangoPay\Sorting $sorting Object to sorting data + * + * @return array Array with KYC documents entities + */ + public function GetKycDocuments($userId, & $pagination = null, $sorting = null) { + return $this->GetList('users_allkycdocuments', $pagination, 'MangoPay\KycDocument', $userId, null, $sorting); + } + + /** + * Get KYC document + * @param int $userId User Id + * @param string $kycDocumentId Document identifier + * @return \MangoPay\KycDocument Document returned from API + */ + public function GetKycDocument($userId, $kycDocumentId) { + return $this->GetObject('kyc_documents_get', $userId, '\MangoPay\KycDocument', $kycDocumentId); + } + + /** + * Save KYC document + * @param int $userId User Id + * @param \MangoPay\KycDocument $kycDocument Document to save + * @return \MangoPay\KycDocument Document returned from API + */ + public function UpdateKycDocument($userId, $kycDocument) { + return $this->SaveObject('kyc_documents_save', $kycDocument, '\MangoPay\KycDocument', $userId); + } + + /** + * Create page for Kyc document + * @param int $userId User Id + * @param \MangoPay\KycPage $page Kyc + */ + public function CreateKycPage($userId, $kycDocumentId, $kycPage) { + + try{ + $this->CreateObject('kyc_page_create', $kycPage, null, $userId, $kycDocumentId); + } catch (\MangoPay\Libraries\ResponseException $exc) { + if ($exc->getCode() != 204) + throw $exc; + } + } + + /** + * Create page for Kyc document from file + * @param int $userId User Id + * @param \MangoPay\KycPage $page Kyc + */ + public function CreateKycPageFromFile($userId, $kycDocumentId, $file) { + + $filePath = $file; + 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'); + + $kycPage = new \MangoPay\KycPage(); + $kycPage->File = base64_encode(file_get_contents($filePath)); + + if (empty($kycPage->File)) + throw new \MangoPay\Libraries\Exception('Content of the file cannot be empty'); + + $this->CreateKycPage($userId, $kycDocumentId, $kycPage); + } + + /** + * Get correct user object + * @param object $response Response from API + * @return UserLegal/UserNatural User object returned from API + * @throws \MangoPay\Libraries\Exception If occur unexpected response from API + */ + private function GetUserResponse($response) { + + if (isset($response->PersonType)) { + + switch ($response->PersonType) { + case PersonType::Natural: + return $this->CastResponseToEntity($response, '\MangoPay\UserNatural'); + case PersonType::Legal: + return $this->CastResponseToEntity($response, '\MangoPay\UserLegal'); + default: + throw new Libraries\Exception('Unexpected response. Wrong PersonType value'); + } + } else { + throw new Libraries\Exception('Unexpected response. Missing PersonType property'); + } + } + + private function GetBankAccountType($bankAccount) { + + if (!isset($bankAccount->Details) || !is_object($bankAccount->Details)) { + throw new Libraries\Exception ('Details is not defined or it is not object type'); + } + + $className = str_replace('MangoPay\\BankAccountDetails', '', get_class($bankAccount->Details)); + return strtolower($className); + } +} diff --git a/MangoPaySDK/tools/apiWallets.inc b/MangoPay/ApiWallets.php similarity index 97% rename from MangoPaySDK/tools/apiWallets.inc rename to MangoPay/ApiWallets.php index fa95878d..23e7bed7 100644 --- a/MangoPaySDK/tools/apiWallets.inc +++ b/MangoPay/ApiWallets.php @@ -4,7 +4,7 @@ /** * Class to management MangoPay API for wallets */ -class ApiWallets extends ApiBase { +class ApiWallets extends Libraries\ApiBase { /** * Create new wallet diff --git a/MangoPay/Autoloader.php b/MangoPay/Autoloader.php new file mode 100644 index 00000000..2bba93e0 --- /dev/null +++ b/MangoPay/Autoloader.php @@ -0,0 +1,30 @@ + array( '/api/clients/', RequestType::POST ), - 'authentication_oauth' => array( '/oauth/token ', RequestType::POST ), - - '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 ), - - '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 ), - 'preauthorization_save' => array( '/preauthorizations/%s', RequestType::PUT ), - - 'card_get' => array( '/cards/%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_get' => array( '/payins/%s', RequestType::GET ), - 'payins_createrefunds' => array( '/payins/%s/refunds', RequestType::POST ), - - 'payouts_bankwire_create' => array( '/payouts/bankwire/', RequestType::POST ), - 'payouts_get' => array( '/payouts/%s', RequestType::GET ), - - 'refunds_get' => array( '/refunds/%s', 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_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 ), - - '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 ), - - // These are temporary functions and WILL be removed in the future. - // Please, contact with support before using these features or if you have any questions. - 'temp_paymentcards_create' => array( '/temp/paymentcards', RequestType::POST ), - 'temp_paymentcards_get' => array( '/temp/paymentcards/%s', RequestType::GET ), - 'temp_immediatepayins_create' => array( '/temp/immediate-payins', RequestType::POST ) - ); - - /** - * Constructor - * @param \MangoPay\MangoPayApi Root/parent instance that holds the OAuthToken and Configuration instance - */ - function __construct($root) { - $this->_root = $root; - } - - /** - * Get URL for REST Mango Pay API - * @param string $key Key with data - * @return string - */ - protected function GetRequestUrl($key){ - return $this->_methods[$key][0]; - } - - /** - * Get request type for REST Mango Pay API - * @param string $key Key with data - * @return RequestType - */ - protected function GetRequestType($key){ - return $this->_methods[$key][1]; - } - - /** - * Create object in API - * @param string $methodKey Key with request data - * @param object $entity Entity object - * @param object $responseClassName Name of entity class from response - * @param int $entityId Entity identifier - * @return object Response data - */ - protected function CreateObject($methodKey, $entity, $responseClassName = null, $entityId = null, $subEntityId = null) { - - if (is_null($entityId)) - $urlMethod = $this->GetRequestUrl($methodKey); - elseif (is_null($subEntityId)) - $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId); - else - $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId, $subEntityId); - - $requestData = null; - if (!is_null($entity)) - $requestData = $this->BuildRequestData($entity); - - $rest = new RestTool(true, $this->_root); - $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey), $requestData); - - if (!is_null($responseClassName)) - return $this->CastResponseToEntity($response, $responseClassName); - - return $response; - } - - /** - * Get entity object from API - * @param string $methodKey Key with request data - * @param int $entityId Entity identifier - * @param object $responseClassName Name of entity class from response - * @param int $secondEntityId Entity identifier for second entity - * @return object Response data - */ - protected function GetObject($methodKey, $entityId, $responseClassName = null, $secondEntityId = null) { - - $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId, $secondEntityId); - - $rest = new RestTool(true, $this->_root); - $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey)); - - if (!is_null($responseClassName)) - return $this->CastResponseToEntity($response, $responseClassName); - - return $response; - } - - /** - * Get lst with entities object from API - * @param string $methodKey Key with request data - * @param \MangoPay\Pagination $pagination Pagination object - * @param object $responseClassName Name of entity class from response - * @param int $entityId Entity identifier - * @param object $filter Object to filter data - * @return object Response data - */ - protected function GetList($methodKey, & $pagination, $responseClassName = null, $entityId = null, $filter = null, $sorting = null) { - - $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId); - - if (is_null($pagination) || !is_object($pagination) || get_class($pagination) != 'MangoPay\Pagination') { - $pagination = new Pagination(); - } - - $rest = new RestTool(true, $this->_root); - $additionalUrlParams = array(); - if (!is_null($filter)) - $additionalUrlParams["filter"] = $filter; - if (!is_null($sorting)){ - if (!is_a($sorting, "\MangoPay\Sorting")) - throw new Exception('Wrong type of sorting object'); - - $additionalUrlParams["sort"] = $sorting->GetSortParameter(); - } - - $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey), null, $pagination, $additionalUrlParams); - - if (!is_null($responseClassName)) - return $this->CastResponseToEntity($response, $responseClassName); - - return $response; - } - - /** - * Save object in API - * @param string $methodKey Key with request data - * @param object $entity Entity object to save - * @param object $responseClassName Name of entity class from response - * @return object Response data - */ - protected function SaveObject($methodKey, $entity, $responseClassName = null, $secondEntityId = null) { - - if (is_null($secondEntityId)) - $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entity->Id); - else - $urlMethod = sprintf($this->GetRequestUrl($methodKey), $secondEntityId, $entity->Id); - - $requestData = $this->BuildRequestData($entity); - - $rest = new RestTool(true, $this->_root); - $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey), $requestData); - - if (!is_null($responseClassName)) - return $this->CastResponseToEntity($response, $responseClassName); - - return $response; - } - - /** - * Cast response object to entity object - * @param object $response Object from API response - * @param string $entityClassName Name of entity class to cast - * @return \MangoPay\$entityClassName Return entity object - */ - protected function CastResponseToEntity($response, $entityClassName, $asDependentObject = false) - { - if (is_array($response)) { - - $list = array(); - foreach ($response as $responseObject) { - array_push($list, $this->CastResponseToEntity($responseObject, $entityClassName)); - } - - return $list; - } - - if (is_string($entityClassName)) { - $entity = new $entityClassName(); - } else { - throw new Exception('Cannot cast response to entity object. Wrong entity class name'); - } - - $responseReflection = new \ReflectionObject($response); - $entityReflection = new \ReflectionObject($entity); - $responseProperties = $responseReflection->getProperties(); - - $subObjects = $entity->GetSubObjects(); - $dependsObjects = $entity->GetDependsObjects(); - - foreach ($responseProperties as $responseProperty) { - - $responseProperty->setAccessible(true); - - $name = $responseProperty->getName(); - $value = $responseProperty->getValue($response); - - if ($entityReflection->hasProperty($name)) { - - $entityProperty = $entityReflection->getProperty($name); - $entityProperty->setAccessible(true); - - // is sub object? - if (isset($subObjects[$name])) { - if (is_null($value)) - $object = null; - else - $object = $this->CastResponseToEntity($value, $subObjects[$name]); - - $entityProperty->setValue($entity, $object); - } else { - $entityProperty->setValue($entity, $value); - } - - // has dependent object? - if (isset($dependsObjects[$name])) { - $dependsObject = $dependsObjects[$name]; - $entityDependProperty = $entityReflection->getProperty($dependsObject['_property_name']); - $entityDependProperty->setAccessible(true); - $entityDependProperty->setValue($entity, $this->CastResponseToEntity($response, $dependsObject[$value], true)); - } - } else { - if ($asDependentObject || !empty($dependsObjects)) { - continue; - } - else { - /* UNCOMMENT THE LINE BELOW TO ENABLE RESTRICTIVE REFLECTION MODE */ - //throw new Exception('Cannot cast response to entity object. Missing property ' . $name .' in entity ' . $entityClassName); - - continue; - } - } - } - - return $entity; - } - - /** - * Get array with request data - * @param object $entity Entity object to send as request data - * @return array - */ - protected function BuildRequestData($entity) { - - $entityProperties = get_object_vars($entity); - $blackList = $entity->GetReadOnlyProperties(); - $requestData = array(); - foreach ($entityProperties as $propertyName => $propertyValue) { - - if (in_array($propertyName, $blackList)) - continue; - - if ($this->CanReadSubRequestData($entity, $propertyName)) { - $subRequestData = $this->BuildRequestData($propertyValue); - foreach ($subRequestData as $key => $value) { - $requestData[$key] = $value; - } - } else { - if (isset($propertyValue)) - $requestData[$propertyName] = $propertyValue; - } - } - - return $requestData; - } - - private function CanReadSubRequestData($entity, $propertyName) { - if (get_class($entity) == 'MangoPay\PayIn' && - ($propertyName == 'PaymentDetails' || $propertyName == 'ExecutionDetails')) { - return true; - } - - if (get_class($entity) == 'MangoPay\PayOut' && $propertyName == 'MeanOfPaymentDetails') { - return true; - } - - if (get_class($entity) == 'MangoPay\BankAccount' && $propertyName == 'Details' ) { - return true; - } - - return false; - } + array( '/api/clients/', RequestType::POST ), + 'authentication_oauth' => array( '/oauth/token ', RequestType::POST ), + + '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 ), + + '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 ), + 'preauthorization_save' => array( '/preauthorizations/%s', RequestType::PUT ), + + 'card_get' => array( '/cards/%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_get' => array( '/payins/%s', RequestType::GET ), + 'payins_createrefunds' => array( '/payins/%s/refunds', RequestType::POST ), + + 'payouts_bankwire_create' => array( '/payouts/bankwire/', RequestType::POST ), + 'payouts_get' => array( '/payouts/%s', RequestType::GET ), + + 'refunds_get' => array( '/refunds/%s', 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_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 ), + + '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 ), + + // These are temporary functions and WILL be removed in the future. + // Please, contact with support before using these features or if you have any questions. + 'temp_paymentcards_create' => array( '/temp/paymentcards', RequestType::POST ), + 'temp_paymentcards_get' => array( '/temp/paymentcards/%s', RequestType::GET ), + 'temp_immediatepayins_create' => array( '/temp/immediate-payins', RequestType::POST ) + ); + + /** + * Constructor + * @param \MangoPay\MangoPayApi Root/parent instance that holds the OAuthToken and Configuration instance + */ + function __construct($root) { + $this->_root = $root; + } + + /** + * Get URL for REST Mango Pay API + * @param string $key Key with data + * @return string + */ + protected function GetRequestUrl($key){ + return $this->_methods[$key][0]; + } + + /** + * Get request type for REST Mango Pay API + * @param string $key Key with data + * @return RequestType + */ + protected function GetRequestType($key){ + return $this->_methods[$key][1]; + } + + /** + * Create object in API + * @param string $methodKey Key with request data + * @param object $entity Entity object + * @param object $responseClassName Name of entity class from response + * @param int $entityId Entity identifier + * @return object Response data + */ + protected function CreateObject($methodKey, $entity, $responseClassName = null, $entityId = null, $subEntityId = null) { + + if (is_null($entityId)) + $urlMethod = $this->GetRequestUrl($methodKey); + elseif (is_null($subEntityId)) + $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId); + else + $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId, $subEntityId); + + $requestData = null; + if (!is_null($entity)) + $requestData = $this->BuildRequestData($entity); + + $rest = new RestTool(true, $this->_root); + $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey), $requestData); + + if (!is_null($responseClassName)) + return $this->CastResponseToEntity($response, $responseClassName); + + return $response; + } + + /** + * Get entity object from API + * @param string $methodKey Key with request data + * @param int $entityId Entity identifier + * @param object $responseClassName Name of entity class from response + * @param int $secondEntityId Entity identifier for second entity + * @return object Response data + */ + protected function GetObject($methodKey, $entityId, $responseClassName = null, $secondEntityId = null) { + + $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId, $secondEntityId); + + $rest = new RestTool(true, $this->_root); + $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey)); + + if (!is_null($responseClassName)) + return $this->CastResponseToEntity($response, $responseClassName); + + return $response; + } + + /** + * Get lst with entities object from API + * @param string $methodKey Key with request data + * @param \MangoPay\Pagination $pagination Pagination object + * @param object $responseClassName Name of entity class from response + * @param int $entityId Entity identifier + * @param object $filter Object to filter data + * @return object Response data + */ + protected function GetList($methodKey, & $pagination, $responseClassName = null, $entityId = null, $filter = null, $sorting = null) { + + $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entityId); + + if (is_null($pagination) || !is_object($pagination) || get_class($pagination) != 'MangoPay\Pagination') { + $pagination = new \MangoPay\Pagination(); + } + + $rest = new RestTool(true, $this->_root); + $additionalUrlParams = array(); + if (!is_null($filter)) + $additionalUrlParams["filter"] = $filter; + if (!is_null($sorting)){ + if (!is_a($sorting, "\MangoPay\Sorting")) + throw new Exception('Wrong type of sorting object'); + + $additionalUrlParams["sort"] = $sorting->GetSortParameter(); + } + + $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey), null, $pagination, $additionalUrlParams); + + if (!is_null($responseClassName)) + return $this->CastResponseToEntity($response, $responseClassName); + + return $response; + } + + /** + * Save object in API + * @param string $methodKey Key with request data + * @param object $entity Entity object to save + * @param object $responseClassName Name of entity class from response + * @return object Response data + */ + protected function SaveObject($methodKey, $entity, $responseClassName = null, $secondEntityId = null) { + + if (is_null($secondEntityId)) + $urlMethod = sprintf($this->GetRequestUrl($methodKey), $entity->Id); + else + $urlMethod = sprintf($this->GetRequestUrl($methodKey), $secondEntityId, $entity->Id); + + $requestData = $this->BuildRequestData($entity); + + $rest = new RestTool(true, $this->_root); + $response = $rest->Request($urlMethod, $this->GetRequestType($methodKey), $requestData); + + if (!is_null($responseClassName)) + return $this->CastResponseToEntity($response, $responseClassName); + + return $response; + } + + /** + * Cast response object to entity object + * @param object $response Object from API response + * @param string $entityClassName Name of entity class to cast + * @return \MangoPay\$entityClassName Return entity object + */ + protected function CastResponseToEntity($response, $entityClassName, $asDependentObject = false) + { + if (is_array($response)) { + + $list = array(); + foreach ($response as $responseObject) { + array_push($list, $this->CastResponseToEntity($responseObject, $entityClassName)); + } + + return $list; + } + + if (is_string($entityClassName)) { + $entity = new $entityClassName(); + } else { + throw new Exception('Cannot cast response to entity object. Wrong entity class name'); + } + + $responseReflection = new \ReflectionObject($response); + $entityReflection = new \ReflectionObject($entity); + $responseProperties = $responseReflection->getProperties(); + + $subObjects = $entity->GetSubObjects(); + $dependsObjects = $entity->GetDependsObjects(); + + foreach ($responseProperties as $responseProperty) { + + $responseProperty->setAccessible(true); + + $name = $responseProperty->getName(); + $value = $responseProperty->getValue($response); + + if ($entityReflection->hasProperty($name)) { + + $entityProperty = $entityReflection->getProperty($name); + $entityProperty->setAccessible(true); + + // is sub object? + if (isset($subObjects[$name])) { + if (is_null($value)) + $object = null; + else + $object = $this->CastResponseToEntity($value, $subObjects[$name]); + + $entityProperty->setValue($entity, $object); + } else { + $entityProperty->setValue($entity, $value); + } + + // has dependent object? + if (isset($dependsObjects[$name])) { + $dependsObject = $dependsObjects[$name]; + $entityDependProperty = $entityReflection->getProperty($dependsObject['_property_name']); + $entityDependProperty->setAccessible(true); + $entityDependProperty->setValue($entity, $this->CastResponseToEntity($response, $dependsObject[$value], true)); + } + } else { + if ($asDependentObject || !empty($dependsObjects)) { + continue; + } + else { + /* UNCOMMENT THE LINE BELOW TO ENABLE RESTRICTIVE REFLECTION MODE */ + //throw new Exception('Cannot cast response to entity object. Missing property ' . $name .' in entity ' . $entityClassName); + + continue; + } + } + } + + return $entity; + } + + /** + * Get array with request data + * @param object $entity Entity object to send as request data + * @return array + */ + protected function BuildRequestData($entity) { + + $entityProperties = get_object_vars($entity); + $blackList = $entity->GetReadOnlyProperties(); + $requestData = array(); + foreach ($entityProperties as $propertyName => $propertyValue) { + + if (in_array($propertyName, $blackList)) + continue; + + if ($this->CanReadSubRequestData($entity, $propertyName)) { + $subRequestData = $this->BuildRequestData($propertyValue); + foreach ($subRequestData as $key => $value) { + $requestData[$key] = $value; + } + } else { + if (isset($propertyValue)) + $requestData[$propertyName] = $propertyValue; + } + } + + return $requestData; + } + + private function CanReadSubRequestData($entity, $propertyName) { + if (get_class($entity) == 'MangoPay\PayIn' && + ($propertyName == 'PaymentDetails' || $propertyName == 'ExecutionDetails')) { + return true; + } + + if (get_class($entity) == 'MangoPay\PayOut' && $propertyName == 'MeanOfPaymentDetails') { + return true; + } + + if (get_class($entity) == 'MangoPay\BankAccount' && $propertyName == 'Details' ) { + return true; + } + + return false; + } } \ No newline at end of file diff --git a/MangoPaySDK/tools/apiClients.inc b/MangoPay/Libraries/ApiClients.php similarity index 95% rename from MangoPaySDK/tools/apiClients.inc rename to MangoPay/Libraries/ApiClients.php index 727505b9..1b4081c7 100644 --- a/MangoPaySDK/tools/apiClients.inc +++ b/MangoPay/Libraries/ApiClients.php @@ -1,30 +1,30 @@ -GetRequestUrl('authentication_base'); - $requestType = $this->GetRequestType('authentication_base'); - $requestData = array( - 'ClientId' => $clientId, - 'Name' => $clientName, - 'Email' => $clientEmail, - ); - - $rest = new RestTool(false, $this->_root); - $response = $rest->Request($urlMethod, $requestType, $requestData); - return $this->CastResponseToEntity($response, '\MangoPay\Client'); - } +GetRequestUrl('authentication_base'); + $requestType = $this->GetRequestType('authentication_base'); + $requestData = array( + 'ClientId' => $clientId, + 'Name' => $clientName, + 'Email' => $clientEmail, + ); + + $rest = new RestTool(false, $this->_root); + $response = $rest->Request($urlMethod, $requestType, $requestData); + return $this->CastResponseToEntity($response, '\MangoPay\Client'); + } } \ No newline at end of file diff --git a/MangoPaySDK/tools/apiOAuth.inc b/MangoPay/Libraries/ApiOAuth.php similarity index 87% rename from MangoPaySDK/tools/apiOAuth.inc rename to MangoPay/Libraries/ApiOAuth.php index 99f22130..0180b284 100644 --- a/MangoPaySDK/tools/apiOAuth.inc +++ b/MangoPay/Libraries/ApiOAuth.php @@ -1,30 +1,30 @@ -GetRequestUrl('authentication_oauth'); - $requestType = $this->GetRequestType('authentication_oauth'); - $requestData = array( - 'grant_type' => 'client_credentials' - ); - - $rest = new RestTool(false, $this->_root); - $authHlp = new AuthenticationHelper($this->_root); - - $urlDetails = parse_url($this->_root->Config->BaseUrl); - $rest->AddRequestHttpHeader('Host: ' . @$urlDetails['host']); - $rest->AddRequestHttpHeader('Authorization: Basic ' . $authHlp->GetHttpHeaderBasicKey()); - $rest->AddRequestHttpHeader('Content-Type: application/x-www-form-urlencoded'); - $response = $rest->Request($urlMethod, $requestType, $requestData); - return $this->CastResponseToEntity($response, '\MangoPay\OAuthToken'); - } +GetRequestUrl('authentication_oauth'); + $requestType = $this->GetRequestType('authentication_oauth'); + $requestData = array( + 'grant_type' => 'client_credentials' + ); + + $rest = new RestTool(false, $this->_root); + $authHlp = new AuthenticationHelper($this->_root); + + $urlDetails = parse_url($this->_root->Config->BaseUrl); + $rest->AddRequestHttpHeader('Host: ' . @$urlDetails['host']); + $rest->AddRequestHttpHeader('Authorization: Basic ' . $authHlp->GetHttpHeaderBasicKey()); + $rest->AddRequestHttpHeader('Content-Type: application/x-www-form-urlencoded'); + $response = $rest->Request($urlMethod, $requestType, $requestData); + return $this->CastResponseToEntity($response, '\MangoPay\Libraries\OAuthToken'); + } } \ No newline at end of file diff --git a/MangoPaySDK/tools/authenticationHelper.inc b/MangoPay/Libraries/AuthenticationHelper.php similarity index 85% rename from MangoPaySDK/tools/authenticationHelper.inc rename to MangoPay/Libraries/AuthenticationHelper.php index 8903de8b..0466a5a3 100644 --- a/MangoPaySDK/tools/authenticationHelper.inc +++ b/MangoPay/Libraries/AuthenticationHelper.php @@ -1,69 +1,69 @@ -_root = $root; - } - - /** - * Get HTTP header value with authorization string - * @return string Authorization string - */ - public function GetHttpHeaderKey(){ - return $this->GetHttpHeaderStrong(); - } - - /** - * Get basic key for HTTP header - * @return string - * @throws \MangoPay\Exception If MangoPay_ClientId or MangoPay_ClientPassword is not defined - */ - public function GetHttpHeaderBasicKey() { - if (is_null($this->_root->Config->ClientId) || strlen($this->_root->Config->ClientId) == 0) - throw new Exception ('MangoPayApi.Config.ClientId is not set.'); - - if (is_null($this->_root->Config->ClientPassword) || strlen($this->_root->Config->ClientPassword) == 0) - throw new Exception ('MangoPayApi.Config.ClientPassword is not set.'); - - $signature = $this->_root->Config->ClientId . ':' . $this->_root->Config->ClientPassword; - return base64_encode($signature); - } - - /** - * Get HTTP header value with authorization string for basic authentication - * - * @return string Value for HTTP header with authentication string - * @throws \MangoPay\Exception If required constants are not defined. - */ - private function GetHttpHeaderBasic() { - - return 'Authorization: Basic ' . $this->GetHttpHeaderBasicKey(); - } - - /** - * Get HTTP header value with authorization string for strong authentication - * - * @return string Value for HTTP header with authentication string - * @throws \MangoPay\Exception If OAuth token is not created (or is invalid) for strong authentication. - */ - private function GetHttpHeaderStrong() { - $token = $this->_root->OAuthTokenManager->GetToken(); - - if (is_null($token) || !isset($token->access_token) || !isset($token->token_type)) - throw new Exception ('OAuth token is not created (or is invalid) for strong authentication'); - - return 'Authorization: ' . $token->token_type . ' ' . $token->access_token; - } +_root = $root; + } + + /** + * Get HTTP header value with authorization string + * @return string Authorization string + */ + public function GetHttpHeaderKey(){ + return $this->GetHttpHeaderStrong(); + } + + /** + * Get basic key for HTTP header + * @return string + * @throws \MangoPay\Libraries\Exception If MangoPay_ClientId or MangoPay_ClientPassword is not defined + */ + public function GetHttpHeaderBasicKey() { + if (is_null($this->_root->Config->ClientId) || strlen($this->_root->Config->ClientId) == 0) + throw new Exception ('MangoPayApi.Config.ClientId is not set.'); + + if (is_null($this->_root->Config->ClientPassword) || strlen($this->_root->Config->ClientPassword) == 0) + throw new Exception ('MangoPayApi.Config.ClientPassword is not set.'); + + $signature = $this->_root->Config->ClientId . ':' . $this->_root->Config->ClientPassword; + return base64_encode($signature); + } + + /** + * Get HTTP header value with authorization string for basic authentication + * + * @return string Value for HTTP header with authentication string + * @throws \MangoPay\Libraries\Exception If required constants are not defined. + */ + private function GetHttpHeaderBasic() { + + return 'Authorization: Basic ' . $this->GetHttpHeaderBasicKey(); + } + + /** + * Get HTTP header value with authorization string for strong authentication + * + * @return string Value for HTTP header with authentication string + * @throws \MangoPay\Libraries\Exception If OAuth token is not created (or is invalid) for strong authentication. + */ + private function GetHttpHeaderStrong() { + $token = $this->_root->OAuthTokenManager->GetToken(); + + if (is_null($token) || !isset($token->access_token) || !isset($token->token_type)) + throw new Exception ('OAuth token is not created (or is invalid) for strong authentication'); + + return 'Authorization: ' . $token->token_type . ' ' . $token->access_token; + } } \ No newline at end of file diff --git a/MangoPaySDK/tools/authorizationTokenManager.inc b/MangoPay/Libraries/AuthorizationTokenManager.php similarity index 88% rename from MangoPaySDK/tools/authorizationTokenManager.inc rename to MangoPay/Libraries/AuthorizationTokenManager.php index 71176916..04e53af0 100644 --- a/MangoPaySDK/tools/authorizationTokenManager.inc +++ b/MangoPay/Libraries/AuthorizationTokenManager.php @@ -1,56 +1,56 @@ -_root = $root; - - $this->RegisterCustomStorageStrategy(new DefaultStorageStrategy($this->_root->Config)); - } - - /** - * Gets the current authorization token. - * In the very first call, this method creates a new token before returning. - * If currently stored token is expired, this method creates a new one. - * @return \MangoPay\OAuthToken Valid OAuthToken instance. - */ - public function GetToken() { - $token = $this->_storageStrategy->get(); - - if (is_null($token) || $token->IsExpired()) { - $this->storeToken($this->_root->AuthenticationManager->createToken()); - } - - return $this->_storageStrategy->get(); - } - - /** - * Stores authorization token passed as an argument in the underlying - * storage strategy implementation. - * @param \MangoPay\OAuthToken $token Token instance to be stored. - */ - public function StoreToken($token) { - $this->_storageStrategy->Store($token); - } - - /** - * Registers custom storage strategy implementation. - * By default, the DefaultStorageStrategy instance is used. - * There is no need to explicitly call this method until some more complex - * storage implementation is needed. - * @param \MangoPay\IStorageStrategy $customStorageStrategy IStorageStrategy interface implementation. - */ - public function RegisterCustomStorageStrategy($customStorageStrategy) { - $this->_storageStrategy = $customStorageStrategy; - } +_root = $root; + + $this->RegisterCustomStorageStrategy(new DefaultStorageStrategy($this->_root->Config)); + } + + /** + * Gets the current authorization token. + * In the very first call, this method creates a new token before returning. + * If currently stored token is expired, this method creates a new one. + * @return \MangoPay\Libraries\OAuthToken Valid OAuthToken instance. + */ + public function GetToken() { + $token = $this->_storageStrategy->get(); + + if (is_null($token) || $token->IsExpired()) { + $this->storeToken($this->_root->AuthenticationManager->createToken()); + } + + return $this->_storageStrategy->get(); + } + + /** + * Stores authorization token passed as an argument in the underlying + * storage strategy implementation. + * @param \MangoPay\Libraries\OAuthToken $token Token instance to be stored. + */ + public function StoreToken($token) { + $this->_storageStrategy->Store($token); + } + + /** + * Registers custom storage strategy implementation. + * By default, the DefaultStorageStrategy instance is used. + * There is no need to explicitly call this method until some more complex + * storage implementation is needed. + * @param \MangoPay\IStorageStrategy $customStorageStrategy IStorageStrategy interface implementation. + */ + public function RegisterCustomStorageStrategy($customStorageStrategy) { + $this->_storageStrategy = $customStorageStrategy; + } } \ No newline at end of file diff --git a/MangoPaySDK/types/configuration.inc b/MangoPay/Libraries/Configuration.php similarity index 97% rename from MangoPaySDK/types/configuration.inc rename to MangoPay/Libraries/Configuration.php index 56abb9f2..79f4adf3 100644 --- a/MangoPaySDK/types/configuration.inc +++ b/MangoPay/Libraries/Configuration.php @@ -1,5 +1,5 @@ '; - private $_fileName = 'MangoPaySdkStorage.tmp.php'; - private $_config; - - function __construct($config) { - $this->_config = $config; - } - - /** - * Gets the current authorization token. - * @return \MangoPay\OAuthToken Currently stored token instance or null. - */ - public function Get() { - - $filename = $this->GetPathToFile(); - if (!file_exists($filename)) - return null; - - $data = file_get_contents($filename); - if ($data === false) - return null; - - $serialized = str_replace($this->_prefixContent, '', $data); - return unserialize($serialized); - } - - /** - * Stores authorization token passed as an argument. - * @param \MangoPay\OAuthToken $token Token instance to be stored. - */ - public function Store($token) { - - if (!is_writable($this->GetPathToTemporaryFolder())) - throw new \MangoPay\Exception('Cannot create or write to file ' . $this->GetPathToTemporaryFolder()); - - $serialized = serialize($token); - $result = file_put_contents($this->GetPathToFile(), $this->_prefixContent . $serialized, LOCK_EX); - if ($result === false) - throw new \MangoPay\Exception('Cannot put token to file'); - } - - /** - * Get path to storage file - * @return string - */ - private function GetPathToFile() { - return $this->GetPathToTemporaryFolder() . DIRECTORY_SEPARATOR . $this->_fileName; - } - - /** - * Get path to temporary folder - * @return string - */ - private function GetPathToTemporaryFolder() { - - if (is_null($this->_config->TemporaryFolder)) - throw new \MangoPay\Exception('Path to temporary folder is not defined'); - - return $this->_config->TemporaryFolder; - } +'; + private $_fileName = 'MangoPaySdkStorage.tmp.php'; + private $_config; + + function __construct($config) { + $this->_config = $config; + } + + /** + * Gets the current authorization token. + * @return \MangoPay\Libraries\OAuthToken Currently stored token instance or null. + */ + public function Get() { + + $filename = $this->GetPathToFile(); + if (!file_exists($filename)) + return null; + + $data = file_get_contents($filename); + if ($data === false) + return null; + + $serialized = str_replace($this->_prefixContent, '', $data); + return unserialize($serialized); + } + + /** + * Stores authorization token passed as an argument. + * @param \MangoPay\Libraries\OAuthToken $token Token instance to be stored. + */ + public function Store($token) { + + if (!is_writable($this->GetPathToTemporaryFolder())) + throw new \MangoPay\Libraries\Exception('Cannot create or write to file ' . $this->GetPathToTemporaryFolder()); + + $serialized = serialize($token); + $result = file_put_contents($this->GetPathToFile(), $this->_prefixContent . $serialized, LOCK_EX); + if ($result === false) + throw new \MangoPay\Libraries\Exception('Cannot put token to file'); + } + + /** + * Get path to storage file + * @return string + */ + private function GetPathToFile() { + return $this->GetPathToTemporaryFolder() . DIRECTORY_SEPARATOR . $this->_fileName; + } + + /** + * Get path to temporary folder + * @return string + */ + private function GetPathToTemporaryFolder() { + + if (is_null($this->_config->TemporaryFolder)) + throw new \MangoPay\Libraries\Exception('Path to temporary folder is not defined'); + + return $this->_config->TemporaryFolder; + } } \ No newline at end of file diff --git a/MangoPaySDK/types/dto.inc b/MangoPay/Libraries/Dto.php similarity index 96% rename from MangoPaySDK/types/dto.inc rename to MangoPay/Libraries/Dto.php index b6466443..11e495f0 100644 --- a/MangoPaySDK/types/dto.inc +++ b/MangoPay/Libraries/Dto.php @@ -1,6 +1,6 @@ create_time = time() - 5; - } - - /** - * Check that current tokens are expire and return true if yes - * @return bool - */ - public function IsExpired() { - return (time() >= ($this->create_time + $this->expires_in)); - } +create_time = time() - 5; + } + + /** + * Check that current tokens are expire and return true if yes + * @return bool + */ + public function IsExpired() { + return (time() >= ($this->create_time + $this->expires_in)); + } } \ No newline at end of file diff --git a/MangoPay/Libraries/RequestType.php b/MangoPay/Libraries/RequestType.php new file mode 100644 index 00000000..58cdbc5a --- /dev/null +++ b/MangoPay/Libraries/RequestType.php @@ -0,0 +1,12 @@ +_authRequired = $authRequired; - $this->_root = $root; - } - - public function AddRequestHttpHeader($httpHeader) { - - if (is_null($this->_requestHttpHeaders)) - $this->_requestHttpHeaders = array(); - - array_push($this->_requestHttpHeaders, $httpHeader); - } - - /** - * Call request to MangoPay API - * @param string $urlMethod Type of method in REST API - * @param \MangoPay\RequestType $requestType Type of request - * @param array $requestData Data to send in request - * @param \MangoPay\Pagination $pagination Pagination object - * @param array Array with additional parameters to URL. Expected keys: "sort" and "filter" - * @return object Response data - */ - public function Request($urlMethod, $requestType, $requestData = null, & $pagination = null, $additionalUrlParams = null) { - - $this->_requestType = $requestType; - $this->_requestData = $requestData; - - $logClass = $this->_root->Config->LogClass; - if ($this->_root->Config->DebugMode) - $logClass::Debug('++++++++++++++++++++++ New reguest ++++++++++++++++++++++', ''); - - $this->BuildRequest($urlMethod, $pagination, $additionalUrlParams); - $responseResult = $this->RunRequest(); - - if(!is_null($pagination)){ - $pagination = $this->_pagination; - } - - return $responseResult; - } - - /** - * Execute request and check response - * @return object Response data - * @throws Exception If cURL has error - */ - private function RunRequest() { - - $result = curl_exec($this->_curlHandle); - if ($result === false && curl_errno($this->_curlHandle) != 0) - throw new Exception('cURL error: ' . curl_error($this->_curlHandle)); - - $this->_responseCode = (int)curl_getinfo($this->_curlHandle, CURLINFO_HTTP_CODE); - - curl_close($this->_curlHandle); - - $logClass = $this->_root->Config->LogClass; - if ($this->_root->Config->DebugMode) - $logClass::Debug('Response JSON', $result); - - $response = json_decode($result); - - if ($this->_root->Config->DebugMode) - $logClass::Debug('Response object', $response); - - $this->CheckResponseCode($response); - - return $response; - } - - /** - * Prepare all parameter to request - * @param String $urlMethod Type of method in REST API - * @throws Exception If some parameters are not set - */ - private function BuildRequest($urlMethod, $pagination, $additionalUrlParams = null) { - - $urlTool = new UrlTool($this->_root); - $restUrl = $urlTool->GetRestUrl($urlMethod, $this->_authRequired, $pagination, $additionalUrlParams); - - $this->_requestUrl = $urlTool->GetFullUrl($restUrl); - $logClass = $this->_root->Config->LogClass; - if ($this->_root->Config->DebugMode) - $logClass::Debug('FullUrl', $this->_requestUrl); - - $this->_curlHandle = curl_init($this->_requestUrl); - if ($this->_curlHandle === false) - throw new Exception('Cannot initialize cURL session'); - - curl_setopt($this->_curlHandle, CURLOPT_RETURNTRANSFER, true); - - if ($this->_root->Config->CertificatesFilePath == '') - curl_setopt($this->_curlHandle, CURLOPT_SSL_VERIFYPEER, false); - else { - curl_setopt($this->_curlHandle, CURLOPT_SSL_VERIFYPEER, true); - curl_setopt($this->_curlHandle, CURLOPT_CAINFO, $this->_root->Config->CertificatesFilePath); - } - - if (!is_null($pagination)) { - curl_setopt($this->_curlHandle, CURLOPT_HEADERFUNCTION, array(&$this, 'ReadResponseHeader')); - $this->_pagination = $pagination; - } - - switch ($this->_requestType) { - case RequestType::POST: - curl_setopt($this->_curlHandle, CURLOPT_POST, true); - break; - case RequestType::PUT: - curl_setopt($this->_curlHandle, CURLOPT_CUSTOMREQUEST, 'PUT'); - break; - case RequestType::DELETE: - curl_setopt($this->_curlHandle, CURLOPT_CUSTOMREQUEST, "DELETE"); - break; - } - - if ($this->_root->Config->DebugMode) - $logClass::Debug('RequestType', $this->_requestType); - - $httpHeaders = $this->GetHttpHeaders(); - curl_setopt($this->_curlHandle, CURLOPT_HTTPHEADER, $httpHeaders); - if ($this->_root->Config->DebugMode) - $logClass::Debug('HTTP Headers', $httpHeaders); - - if (!is_null($this->_requestData)) { - - if ($this->_root->Config->DebugMode) - $logClass::Debug('RequestData object', $this->_requestData); - - // encode to json if needed - if (in_array(self::$_JSON_HEADER, $httpHeaders)) { - $this->_requestData = json_encode($this->_requestData); - if ($this->_root->Config->DebugMode) - $logClass::Debug('RequestData JSON', $this->_requestData); - } - - curl_setopt($this->_curlHandle, CURLOPT_POSTFIELDS, $this->_requestData); - } - } - - /** - * Callback to read response headers - * @param resource $handle cURL handle - * @param string $header Header from response - * @return int Length of header - */ - private function ReadResponseHeader($handle, $header) { - - $logClass = $this->_root->Config->LogClass; - if ($this->_root->Config->DebugMode) - $logClass::Debug('Response headers', $header); - - if (strpos($header, 'X-Number-Of-Pages:') !== false) { - $this->_pagination->TotalPages = (int)trim(str_replace('X-Number-Of-Pages:', '', $header)); - } - - if (strpos($header, 'X-Number-Of-Items:') !== false) { - $this->_pagination->TotalItems = (int)trim(str_replace('X-Number-Of-Items:', '', $header)); - } - - if (strpos($header, 'Link: ') !== false) { - - $strLinks = trim(str_replace('Link:', '', $header)); - $arrayLinks = explode(',', $strLinks); - if ($arrayLinks !== false) { - $this->_pagination->Links = array(); - foreach ($arrayLinks as $link) { - - $tmp = str_replace(array('<"', '">', ' rel="', '"'), '', $link); - $oneLink = explode(';', $tmp); - if (is_array($oneLink) && isset($oneLink[0]) && isset($oneLink[1])) - $this->_pagination->Links[$oneLink[1]] = $oneLink[0]; - } - } - } - - return strlen($header); - } - - /** - * Get HTTP header to use in request - * @return array Array with HTTP headers - */ - private function GetHttpHeaders(){ - // return if already created... - if (!is_null($this->_requestHttpHeaders)) - return $this->_requestHttpHeaders; - - // ...or initialize with default headers - $this->_requestHttpHeaders = array(); - - // content type - array_push($this->_requestHttpHeaders, self::$_JSON_HEADER); - - // Authentication http header - if ($this->_authRequired) { - $authHlp = new AuthenticationHelper($this->_root); - array_push($this->_requestHttpHeaders, $authHlp->GetHttpHeaderKey()); - } - - return $this->_requestHttpHeaders; - } - - /** - * Check response code - * @param object $response Response from REST API - * @throws ResponseException If response code not OK - */ - private function CheckResponseCode($response){ - - if ($this->_responseCode != 200) { - - if (isset($response) && is_object($response) && isset($response->Message)) { - - $error = new Error(); - $error->Message = $response->Message; - $error->Errors = property_exists($response, 'Errors') - ? $response->Errors - : property_exists($response, 'errors') ? $response->errors : null; - throw new ResponseException($this->_requestUrl, $this->_responseCode, $error); - - } else - throw new ResponseException($this->_requestUrl, $this->_responseCode); - } - } +_authRequired = $authRequired; + $this->_root = $root; + } + + public function AddRequestHttpHeader($httpHeader) { + + if (is_null($this->_requestHttpHeaders)) + $this->_requestHttpHeaders = array(); + + array_push($this->_requestHttpHeaders, $httpHeader); + } + + /** + * Call request to MangoPay API + * @param string $urlMethod Type of method in REST API + * @param \MangoPay\RequestType $requestType Type of request + * @param array $requestData Data to send in request + * @param \MangoPay\Pagination $pagination Pagination object + * @param array Array with additional parameters to URL. Expected keys: "sort" and "filter" + * @return object Response data + */ + public function Request($urlMethod, $requestType, $requestData = null, & $pagination = null, $additionalUrlParams = null) { + + $this->_requestType = $requestType; + $this->_requestData = $requestData; + + $logClass = $this->_root->Config->LogClass; + if ($this->_root->Config->DebugMode) + $logClass::Debug('++++++++++++++++++++++ New reguest ++++++++++++++++++++++', ''); + + $this->BuildRequest($urlMethod, $pagination, $additionalUrlParams); + $responseResult = $this->RunRequest(); + + if(!is_null($pagination)){ + $pagination = $this->_pagination; + } + + return $responseResult; + } + + /** + * Execute request and check response + * @return object Response data + * @throws Exception If cURL has error + */ + private function RunRequest() { + + $result = curl_exec($this->_curlHandle); + if ($result === false && curl_errno($this->_curlHandle) != 0) + throw new Exception('cURL error: ' . curl_error($this->_curlHandle)); + + $this->_responseCode = (int)curl_getinfo($this->_curlHandle, CURLINFO_HTTP_CODE); + + curl_close($this->_curlHandle); + + $logClass = $this->_root->Config->LogClass; + if ($this->_root->Config->DebugMode) + $logClass::Debug('Response JSON', $result); + + $response = json_decode($result); + + if ($this->_root->Config->DebugMode) + $logClass::Debug('Response object', $response); + + $this->CheckResponseCode($response); + + return $response; + } + + /** + * Prepare all parameter to request + * @param String $urlMethod Type of method in REST API + * @throws Exception If some parameters are not set + */ + private function BuildRequest($urlMethod, $pagination, $additionalUrlParams = null) { + + $urlTool = new UrlTool($this->_root); + $restUrl = $urlTool->GetRestUrl($urlMethod, $this->_authRequired, $pagination, $additionalUrlParams); + + $this->_requestUrl = $urlTool->GetFullUrl($restUrl); + $logClass = $this->_root->Config->LogClass; + if ($this->_root->Config->DebugMode) { + $logClass::Debug('FullUrl', $this->_requestUrl); + } + + $this->_curlHandle = curl_init($this->_requestUrl); + if ($this->_curlHandle === false){ + throw new Exception('Cannot initialize cURL session'); + } + + curl_setopt($this->_curlHandle, CURLOPT_RETURNTRANSFER, true); + + if ($this->_root->Config->CertificatesFilePath == '') + curl_setopt($this->_curlHandle, CURLOPT_SSL_VERIFYPEER, false); + else { + curl_setopt($this->_curlHandle, CURLOPT_SSL_VERIFYPEER, true); + curl_setopt($this->_curlHandle, CURLOPT_CAINFO, $this->_root->Config->CertificatesFilePath); + } + + if (!is_null($pagination)) { + curl_setopt($this->_curlHandle, CURLOPT_HEADERFUNCTION, array(&$this, 'ReadResponseHeader')); + $this->_pagination = $pagination; + } + + switch ($this->_requestType) { + case RequestType::POST: + curl_setopt($this->_curlHandle, CURLOPT_POST, true); + break; + case RequestType::PUT: + curl_setopt($this->_curlHandle, CURLOPT_CUSTOMREQUEST, 'PUT'); + break; + case RequestType::DELETE: + curl_setopt($this->_curlHandle, CURLOPT_CUSTOMREQUEST, "DELETE"); + break; + } + + if ($this->_root->Config->DebugMode) + $logClass::Debug('RequestType', $this->_requestType); + + $httpHeaders = $this->GetHttpHeaders(); + curl_setopt($this->_curlHandle, CURLOPT_HTTPHEADER, $httpHeaders); + if ($this->_root->Config->DebugMode) + $logClass::Debug('HTTP Headers', $httpHeaders); + + if (!is_null($this->_requestData)) { + + if ($this->_root->Config->DebugMode) + $logClass::Debug('RequestData object', $this->_requestData); + + // encode to json if needed + if (in_array(self::$_JSON_HEADER, $httpHeaders)) { + $this->_requestData = json_encode($this->_requestData); + if ($this->_root->Config->DebugMode) + $logClass::Debug('RequestData JSON', $this->_requestData); + } + + curl_setopt($this->_curlHandle, CURLOPT_POSTFIELDS, $this->_requestData); + } + } + + /** + * Callback to read response headers + * @param resource $handle cURL handle + * @param string $header Header from response + * @return int Length of header + */ + private function ReadResponseHeader($handle, $header) { + + $logClass = $this->_root->Config->LogClass; + if ($this->_root->Config->DebugMode) + $logClass::Debug('Response headers', $header); + + if (strpos($header, 'X-Number-Of-Pages:') !== false) { + $this->_pagination->TotalPages = (int)trim(str_replace('X-Number-Of-Pages:', '', $header)); + } + + if (strpos($header, 'X-Number-Of-Items:') !== false) { + $this->_pagination->TotalItems = (int)trim(str_replace('X-Number-Of-Items:', '', $header)); + } + + if (strpos($header, 'Link: ') !== false) { + + $strLinks = trim(str_replace('Link:', '', $header)); + $arrayLinks = explode(',', $strLinks); + if ($arrayLinks !== false) { + $this->_pagination->Links = array(); + foreach ($arrayLinks as $link) { + + $tmp = str_replace(array('<"', '">', ' rel="', '"'), '', $link); + $oneLink = explode(';', $tmp); + if (is_array($oneLink) && isset($oneLink[0]) && isset($oneLink[1])) + $this->_pagination->Links[$oneLink[1]] = $oneLink[0]; + } + } + } + + return strlen($header); + } + + /** + * Get HTTP header to use in request + * @return array Array with HTTP headers + */ + private function GetHttpHeaders(){ + // return if already created... + if (!is_null($this->_requestHttpHeaders)) + return $this->_requestHttpHeaders; + + // ...or initialize with default headers + $this->_requestHttpHeaders = array(); + + // content type + array_push($this->_requestHttpHeaders, self::$_JSON_HEADER); + + // Authentication http header + if ($this->_authRequired) { + $authHlp = new AuthenticationHelper($this->_root); + array_push($this->_requestHttpHeaders, $authHlp->GetHttpHeaderKey()); + } + + return $this->_requestHttpHeaders; + } + + /** + * Check response code + * @param object $response Response from REST API + * @throws ResponseException If response code not OK + */ + private function CheckResponseCode($response){ + + if ($this->_responseCode != 200) { + + if (isset($response) && is_object($response) && isset($response->Message)) { + + $error = new Error(); + $error->Message = $response->Message; + $error->Errors = property_exists($response, 'Errors') + ? $response->Errors + : property_exists($response, 'errors') ? $response->errors : null; + throw new ResponseException($this->_requestUrl, $this->_responseCode, $error); + + } else { + throw new ResponseException($this->_requestUrl, $this->_responseCode); + } + } + } } \ No newline at end of file diff --git a/MangoPaySDK/tools/urlTool.inc b/MangoPay/Libraries/UrlTool.php similarity index 98% rename from MangoPaySDK/tools/urlTool.inc rename to MangoPay/Libraries/UrlTool.php index bba57fff..e57fda95 100644 --- a/MangoPaySDK/tools/urlTool.inc +++ b/MangoPay/Libraries/UrlTool.php @@ -1,5 +1,5 @@ Config = new Configuration(); - $this->OAuthTokenManager = new AuthorizationTokenManager($this); - - // API managers - $this->AuthenticationManager = new ApiOAuth($this); - $this->Clients = new ApiClients($this); - $this->Users = new ApiUsers($this); - $this->Wallets = new ApiWallets($this); - $this->Transfers = new ApiTransfers($this); - $this->PayIns = new ApiPayIns($this); - $this->PayOuts = new ApiPayOuts($this); - $this->Refunds = new ApiRefunds($this); - $this->CardRegistrations = new ApiCardRegistrations($this); - $this->Cards = new ApiCards($this); - $this->Events = new ApiEvents($this); - $this->Hooks = new ApiHooks($this); - $this->CardPreAuthorizations = new ApiCardPreAuthorizations($this); - $this->KycDocuments = new ApiKycDocuments($this); - } +Config = new Libraries\Configuration(); + $this->OAuthTokenManager = new Libraries\AuthorizationTokenManager($this); + + // API managers + $this->AuthenticationManager = new Libraries\ApiOAuth($this); + $this->Clients = new Libraries\ApiClients($this); + $this->Users = new ApiUsers($this); + $this->Wallets = new ApiWallets($this); + $this->Transfers = new ApiTransfers($this); + $this->PayIns = new ApiPayIns($this); + $this->PayOuts = new ApiPayOuts($this); + $this->Refunds = new ApiRefunds($this); + $this->CardRegistrations = new ApiCardRegistrations($this); + $this->Cards = new ApiCards($this); + $this->Events = new ApiEvents($this); + $this->Hooks = new ApiHooks($this); + $this->CardPreAuthorizations = new ApiCardPreAuthorizations($this); + $this->KycDocuments = new ApiKycDocuments($this); + } } \ No newline at end of file diff --git a/MangoPaySDK/types/money.inc b/MangoPay/Money.php similarity index 89% rename from MangoPaySDK/types/money.inc rename to MangoPay/Money.php index 621bb773..667c2f75 100644 --- a/MangoPaySDK/types/money.inc +++ b/MangoPay/Money.php @@ -5,7 +5,7 @@ /** * Class represents money value with currency */ -class Money extends Dto { +class Money extends Libraries\Dto { /** * Text with currency code with ISO 4217 standard diff --git a/MangoPaySDK/types/pagination.inc b/MangoPay/Pagination.php similarity index 96% rename from MangoPaySDK/types/pagination.inc rename to MangoPay/Pagination.php index cb63788e..8a74f5ab 100644 --- a/MangoPaySDK/types/pagination.inc +++ b/MangoPay/Pagination.php @@ -5,7 +5,7 @@ /** * Class represents pagination information */ -class Pagination extends Dto { +class Pagination extends Libraries\Dto { /** * Page number diff --git a/MangoPaySDK/entities/payIn.inc b/MangoPay/PayIn.php similarity index 96% rename from MangoPaySDK/entities/payIn.inc rename to MangoPay/PayIn.php index 0f163220..54607414 100644 --- a/MangoPaySDK/entities/payIn.inc +++ b/MangoPay/PayIn.php @@ -1,73 +1,73 @@ - array( - '_property_name' => 'PaymentDetails', - 'CARD' => '\MangoPay\PayInPaymentDetailsCard', - 'PREAUTHORIZED' => '\MangoPay\PayInPaymentDetailsPreAuthorized', - 'BANK_WIRE' => '\MangoPay\PayInPaymentDetailsBankWire', - 'DIRECT_DEBIT' => '\MangoPay\PayInPaymentDetailsDirectDebit', - // ...and more in future... - ), - 'ExecutionType' => array( - '_property_name' => 'ExecutionDetails', - 'WEB' => '\MangoPay\PayInExecutionDetailsWeb', - 'DIRECT' => '\MangoPay\PayInExecutionDetailsDirect', - // ...and more in future... - ) - ); - } - - /** - * Get array with read-only properties - * @return array - */ - public function GetReadOnlyProperties() { - $properties = parent::GetReadOnlyProperties(); - array_push( $properties, 'PaymentType' ); - array_push( $properties, 'ExecutionType' ); - - return $properties; - } -} + array( + '_property_name' => 'PaymentDetails', + 'CARD' => '\MangoPay\PayInPaymentDetailsCard', + 'PREAUTHORIZED' => '\MangoPay\PayInPaymentDetailsPreAuthorized', + 'BANK_WIRE' => '\MangoPay\PayInPaymentDetailsBankWire', + 'DIRECT_DEBIT' => '\MangoPay\PayInPaymentDetailsDirectDebit', + // ...and more in future... + ), + 'ExecutionType' => array( + '_property_name' => 'ExecutionDetails', + 'WEB' => '\MangoPay\PayInExecutionDetailsWeb', + 'DIRECT' => '\MangoPay\PayInExecutionDetailsDirect', + // ...and more in future... + ) + ); + } + + /** + * Get array with read-only properties + * @return array + */ + public function GetReadOnlyProperties() { + $properties = parent::GetReadOnlyProperties(); + array_push( $properties, 'PaymentType' ); + array_push( $properties, 'ExecutionType' ); + + return $properties; + } +} diff --git a/MangoPaySDK/types/payInExecutionDetails.inc b/MangoPay/PayInExecutionDetails.php similarity index 100% rename from MangoPaySDK/types/payInExecutionDetails.inc rename to MangoPay/PayInExecutionDetails.php diff --git a/MangoPaySDK/types/payInExecutionDetailsDirect.inc b/MangoPay/PayInExecutionDetailsDirect.php similarity index 81% rename from MangoPaySDK/types/payInExecutionDetailsDirect.inc rename to MangoPay/PayInExecutionDetailsDirect.php index 4e5e788d..1b5d35b4 100644 --- a/MangoPaySDK/types/payInExecutionDetailsDirect.inc +++ b/MangoPay/PayInExecutionDetailsDirect.php @@ -1,32 +1,32 @@ - '\MangoPay\PayInTemplateURLOptions' - ); - } + '\MangoPay\PayInTemplateURLOptions' + ); + } } \ No newline at end of file diff --git a/MangoPaySDK/types/payInPaymentDetails.inc b/MangoPay/PayInPaymentDetails.php similarity index 100% rename from MangoPaySDK/types/payInPaymentDetails.inc rename to MangoPay/PayInPaymentDetails.php diff --git a/MangoPaySDK/types/payInPaymentDetailsBankWire.inc b/MangoPay/PayInPaymentDetailsBankWire.php similarity index 90% rename from MangoPaySDK/types/payInPaymentDetailsBankWire.inc rename to MangoPay/PayInPaymentDetailsBankWire.php index 9a83480e..0707587f 100644 --- a/MangoPaySDK/types/payInPaymentDetailsBankWire.inc +++ b/MangoPay/PayInPaymentDetailsBankWire.php @@ -4,7 +4,7 @@ /** * Class represents BankWire type for mean of payment in PayIn entity */ -class PayInPaymentDetailsBankWire extends Dto implements PayInPaymentDetails { +class PayInPaymentDetailsBankWire extends Libraries\Dto implements PayInPaymentDetails { /** * Declared debited funds diff --git a/MangoPaySDK/types/payInPaymentDetailsCard.inc b/MangoPay/PayInPaymentDetailsCard.php similarity index 74% rename from MangoPaySDK/types/payInPaymentDetailsCard.inc rename to MangoPay/PayInPaymentDetailsCard.php index 1be4794e..062d8ae1 100644 --- a/MangoPaySDK/types/payInPaymentDetailsCard.inc +++ b/MangoPay/PayInPaymentDetailsCard.php @@ -1,20 +1,20 @@ -_sortFields as $key => $value) { - if (!empty($sortValues)) + if (!empty($sortValues)){ $sortValues .= self::SortFieldSeparator; - + } + $sortValues .= $key . ":" . $value; } diff --git a/MangoPaySDK/entities/temporaryImmediatePayIn.inc b/MangoPay/TemporaryImmediatePayIn.php similarity index 100% rename from MangoPaySDK/entities/temporaryImmediatePayIn.inc rename to MangoPay/TemporaryImmediatePayIn.php diff --git a/MangoPaySDK/entities/temporaryPaymentCard.inc b/MangoPay/TemporaryPaymentCard.php similarity index 92% rename from MangoPaySDK/entities/temporaryPaymentCard.inc rename to MangoPay/TemporaryPaymentCard.php index 35ff1a78..ae6f9500 100644 --- a/MangoPaySDK/entities/temporaryPaymentCard.inc +++ b/MangoPay/TemporaryPaymentCard.php @@ -8,7 +8,7 @@ * * Temporary Payment Card entity. */ -class TemporaryPaymentCard extends EntityBase { +class TemporaryPaymentCard extends Libraries\EntityBase { /** * User Id diff --git a/MangoPaySDK/entities/transaction.inc b/MangoPay/Transaction.php similarity index 97% rename from MangoPaySDK/entities/transaction.inc rename to MangoPay/Transaction.php index 3567124b..7810b0bb 100644 --- a/MangoPaySDK/entities/transaction.inc +++ b/MangoPay/Transaction.php @@ -5,7 +5,7 @@ * Transaction entity. * Base class for: PayIn, PayOut, Transfer. */ -class Transaction extends EntityBase { +class Transaction extends Libraries\EntityBase { /** * Author Id diff --git a/MangoPaySDK/entities/transfer.inc b/MangoPay/Transfer.php similarity index 100% rename from MangoPaySDK/entities/transfer.inc rename to MangoPay/Transfer.php diff --git a/MangoPaySDK/entities/user.inc b/MangoPay/User.php similarity index 93% rename from MangoPaySDK/entities/user.inc rename to MangoPay/User.php index 4b30f038..06151e3a 100644 --- a/MangoPaySDK/entities/user.inc +++ b/MangoPay/User.php @@ -5,7 +5,7 @@ /** * User entity */ -abstract class User extends EntityBase { +abstract class User extends Libraries\EntityBase { /** * Type of user @@ -18,7 +18,7 @@ abstract class User extends EntityBase { * @var String */ public $Email; - + /** * KYC Level (LIGHT or REGULAR) * @var String @@ -43,4 +43,4 @@ public function GetReadOnlyProperties() { return $properties; } -} +} \ No newline at end of file diff --git a/MangoPaySDK/entities/userLegal.inc b/MangoPay/UserLegal.php similarity index 100% rename from MangoPaySDK/entities/userLegal.inc rename to MangoPay/UserLegal.php diff --git a/MangoPaySDK/entities/userNatural.inc b/MangoPay/UserNatural.php similarity index 100% rename from MangoPaySDK/entities/userNatural.inc rename to MangoPay/UserNatural.php diff --git a/MangoPaySDK/entities/wallet.inc b/MangoPay/Wallet.php similarity index 95% rename from MangoPaySDK/entities/wallet.inc rename to MangoPay/Wallet.php index 4c4867c8..df99e5a5 100644 --- a/MangoPaySDK/entities/wallet.inc +++ b/MangoPay/Wallet.php @@ -4,7 +4,7 @@ /** * Wallet entity */ -class Wallet extends EntityBase { +class Wallet extends Libraries\EntityBase { /** * Array with owners identities diff --git a/MangoPaySDK/common/common.inc b/MangoPaySDK/common/common.inc deleted file mode 100644 index c08b3fde..00000000 --- a/MangoPaySDK/common/common.inc +++ /dev/null @@ -1,41 +0,0 @@ -Clients->Create( @@ -83,7 +86,7 @@ It could be `/tmp/` or `/var/tmp/` or any other location that PHP can write to. `$api->Config->BaseUrl` is set to sandbox environment by default. To enable production environment, set it to `https://api.mangopay.com`. - require_once '{your-installation-dir}/MangoPaySDK/mangoPayApi.inc'; + require_once '{your-installation-dir}/MangoPay/Autoloader.php'; $api = new MangoPay\MangoPayApi(); // configuration @@ -99,7 +102,7 @@ environment, set it to `https://api.mangopay.com`. Sample usage ------------------------------------------------- - require_once '{your-installation-dir}/MangoPaySDK/mangoPayApi.inc'; + require_once '{your-installation-dir}/MangoPay/Autoloader.php'; $api = new MangoPay\MangoPayApi(); // configuration diff --git a/composer.json b/composer.json index 7e191900..7b8347bf 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "minimum-stability": "stable", "license": "MIT", "autoload": { - "classmap": ["MangoPaySDK/mangoPayApi.inc"], - "files": ["MangoPaySDK/common/common.inc"] + "psr-4": { "MangoPay\\": "" }, + "files": ["MangoPay/Autoloader.php"] } } \ No newline at end of file diff --git a/demos/api/form.php b/demos/api/form.php index 0f56836d..add1bffc 100644 --- a/demos/api/form.php +++ b/demos/api/form.php @@ -1,6 +1,7 @@ AddField($sortFieldName, $sortDirection); } @@ -68,9 +72,9 @@ $apiResult = $api->$subApiName->GetAll($pagination); print '
';print_r($pagination);print '
'; - if (isset($sorting)) - print '
Sort: ';print_r($_POST["_sort_"]);print '
'; - + if (isset($sorting)) { + print '
Sort: ';print_r($sorting);print '
'; + } break; case 'CreateSubEntity': $entity = HtmlHelper::getEntity($subEntityName); @@ -119,7 +123,7 @@ print '
';print_r($apiResult);print '
'; - } catch (\MangoPay\ResponseException $e) { + } catch (\MangoPay\Libraries\ResponseException $e) { echo '
\MangoPay\ResponseException: Code: ' . $e->getCode(); echo '
Message: ' . $e->getMessage(); @@ -129,7 +133,7 @@ echo '

Details: '; print_r($details); echo '
'; - } catch (\MangoPay\Exception $e) { + } catch (\MangoPay\Libraries\Exception $e) { echo '
\MangoPay\Exception: ' . $e->getMessage() . '
'; diff --git a/demos/api/htmlHelper.php b/demos/api/htmlHelper.php index 6acbcd46..df20d35d 100644 --- a/demos/api/htmlHelper.php +++ b/demos/api/htmlHelper.php @@ -197,7 +197,12 @@ public static function renderSort(){ echo ''; echo 'Sort:'; - echo ''; + echo ''; + + echo ' '; } public static function getEntity($entityName, $entityId = 0, $returnNullIfNoPropertyTouched = false, $prefix = '') { diff --git a/demos/api/menu.php b/demos/api/menu.php index 4bb01fd8..43bb02cf 100644 --- a/demos/api/menu.php +++ b/demos/api/menu.php @@ -6,7 +6,7 @@ 'Create natural user' => 'UserNatural_Users_Create', 'Create legal user' => 'UserLegal_Users_Create', 'Get user' => 'User_Users_Get', - 'Get all users' => 'User_Users_All', + 'Get all users' => 'User_Users_All___$Sort', 'Save natural user' => 'UserNatural_Users_Save', 'Save legal user' => 'UserLegal_Users_Save', 'Save legal user' => 'UserLegal_Users_Save', @@ -67,7 +67,7 @@ 'List cards for user' => 'User_Users_ListSubEntity_GetCards__$Sort', ), 'Event' => array( - 'List events' => 'Event_Events_All__FilterEvents', + 'List events' => 'Event_Events_All__FilterEvents__$Sort', ), 'Hooks' => array( 'Create hook' => 'Hook_Hooks_Create', diff --git a/demos/clients_create.php b/demos/clients_create.php index fd9ca07a..2c2a7c94 100644 --- a/demos/clients_create.php +++ b/demos/clients_create.php @@ -1,6 +1,6 @@ Clients->Create($testUniqueClientId, 'Test Client Name', 'test.email@sample.org'); // display result on screen - MangoPay\Logs::Debug('CREATED CLIENT', $client); + MangoPay\Libraries\Logs::Debug('CREATED CLIENT', $client); -} catch (MangoPay\ResponseException $e) { +} catch (MangoPay\Libraries\ResponseException $e) { - MangoPay\Logs::Debug('MangoPay\ResponseException Code', $e->GetCode()); - MangoPay\Logs::Debug('Message', $e->GetMessage()); - MangoPay\Logs::Debug('Details', $e->GetErrorDetails()); + MangoPay\Libraries\Logs::Debug('MangoPay\ResponseException Code', $e->GetCode()); + MangoPay\Libraries\Logs::Debug('Message', $e->GetMessage()); + MangoPay\Libraries\Logs::Debug('Details', $e->GetErrorDetails()); -} catch (MangoPay\Exception $e) { +} catch (MangoPay\Libraries\Exception $e) { - MangoPay\Logs::Debug('MangoPay\Exception Message', $e->GetMessage()); + MangoPay\Libraries\Logs::Debug('MangoPay\Exception Message', $e->GetMessage()); } \ No newline at end of file diff --git a/demos/paymentDirect/non_js.php b/demos/paymentDirect/non_js.php index d4895a8f..b48d5d73 100644 --- a/demos/paymentDirect/non_js.php +++ b/demos/paymentDirect/non_js.php @@ -1,7 +1,7 @@ '; } -} catch (\MangoPay\ResponseException $e) { +} catch (\MangoPay\Libraries\ResponseException $e) { print '
' .'\MangoPay\ResponseException: Code: ' diff --git a/demos/paymentDirect/with_js.php b/demos/paymentDirect/with_js.php index 6e26d846..fdd98c13 100644 --- a/demos/paymentDirect/with_js.php +++ b/demos/paymentDirect/with_js.php @@ -1,7 +1,7 @@ Users->GetAll($pagination); // display result on screen - MangoPay\Logs::Debug('PAGINATION OBJECT', $pagination); - MangoPay\Logs::Debug('LIST WITH USERS', $users); + MangoPay\Libraries\Logs::Debug('PAGINATION OBJECT', $pagination); + MangoPay\Libraries\Logs::Debug('LIST WITH USERS', $users); -} catch (MangoPay\ResponseException $e) { +} catch (MangoPay\Libraries\ResponseException $e) { - MangoPay\Logs::Debug('MangoPay\ResponseException Code', $e->GetCode()); - MangoPay\Logs::Debug('Message', $e->GetMessage()); - MangoPay\Logs::Debug('Details', $e->GetErrorDetails()); + MangoPay\Libraries\Logs::Debug('MangoPay\ResponseException Code', $e->GetCode()); + MangoPay\Libraries\Logs::Debug('Message', $e->GetMessage()); + MangoPay\Libraries\Logs::Debug('Details', $e->GetErrorDetails()); -} catch (MangoPay\Exception $e) { +} catch (MangoPay\Libraries\Exception $e) { - MangoPay\Logs::Debug('MangoPay\Exception Message', $e->GetMessage()); + MangoPay\Libraries\Logs::Debug('MangoPay\Exception Message', $e->GetMessage()); } \ No newline at end of file diff --git a/demos/users_create.php b/demos/users_create.php index 4a4173d7..9db72382 100644 --- a/demos/users_create.php +++ b/demos/users_create.php @@ -1,6 +1,6 @@ CountryOfResidence = "ZA"; $naturalUserResult = $api->Users->Create($naturalUser); // display result - MangoPay\Logs::Debug('CREATED NATURAL USER', $naturalUserResult); + MangoPay\Libraries\Logs::Debug('CREATED NATURAL USER', $naturalUserResult); // CREATE LEGAL USER $legalUser = new MangoPay\UserLegal(); @@ -34,17 +34,17 @@ $legalUser->LegalRepresentativeCountryOfResidence = "ZA"; $legalUserResult = $api->Users->Create($legalUser); // display result - MangoPay\Logs::Debug('CREATED LEGAL USER', $legalUserResult); + MangoPay\Libraries\Logs::Debug('CREATED LEGAL USER', $legalUserResult); -} catch (MangoPay\ResponseException $e) { +} catch (MangoPay\Libraries\ResponseException $e) { - MangoPay\Logs::Debug('MangoPay\ResponseException Code', $e->GetCode()); - MangoPay\Logs::Debug('Message', $e->GetMessage()); - MangoPay\Logs::Debug('Details', $e->GetErrorDetails()); + MangoPay\Libraries\Logs::Debug('MangoPay\ResponseException Code', $e->GetCode()); + MangoPay\Libraries\Logs::Debug('Message', $e->GetMessage()); + MangoPay\Libraries\Logs::Debug('Details', $e->GetErrorDetails()); -} catch (MangoPay\Exception $e) { +} catch (MangoPay\Libraries\Exception $e) { - MangoPay\Logs::Debug('MangoPay\Exception Message', $e->GetMessage()); + MangoPay\Libraries\Logs::Debug('MangoPay\Exception Message', $e->GetMessage()); } diff --git a/demos/users_get.php b/demos/users_get.php index cae338df..91b76a43 100644 --- a/demos/users_get.php +++ b/demos/users_get.php @@ -1,6 +1,6 @@ Users->GetNatural(4991600); // display result on screen - MangoPay\Logs::Debug('READ NATURAL USER', $naturalUserResult); + MangoPay\Libraries\Logs::Debug('READ NATURAL USER', $naturalUserResult); // GET LEGAL USER: GET /users/legal/4991601 $legalUserResult = $api->Users->GetLegal(4991601); // display result on screen - MangoPay\Logs::Debug('READ LEGAL USER', $legalUserResult); + MangoPay\Libraries\Logs::Debug('READ LEGAL USER', $legalUserResult); // GET NATURAL USER GET /users/4991600 $userResult = $api->Users->Get(4991600); // display result on screen - MangoPay\Logs::Debug('READ USER', $userResult); + MangoPay\Libraries\Logs::Debug('READ USER', $userResult); -} catch (MangoPay\ResponseException $e) { +} catch (MangoPay\Libraries\ResponseException $e) { - MangoPay\Logs::Debug('MangoPay\ResponseException Code', $e->GetCode()); - MangoPay\Logs::Debug('Message', $e->GetMessage()); - MangoPay\Logs::Debug('Details', $e->GetErrorDetails()); + MangoPay\Libraries\Logs::Debug('MangoPay\ResponseException Code', $e->GetCode()); + MangoPay\Libraries\Logs::Debug('Message', $e->GetMessage()); + MangoPay\Libraries\Logs::Debug('Details', $e->GetErrorDetails()); -} catch (MangoPay\Exception $e) { +} catch (MangoPay\Libraries\Exception $e) { - MangoPay\Logs::Debug('MangoPay\Exception Message', $e->GetMessage()); + MangoPay\Libraries\Logs::Debug('MangoPay\Exception Message', $e->GetMessage()); } \ No newline at end of file diff --git a/demos/workflow/inc/config.php b/demos/workflow/inc/config.php index 5e2c405b..2d89f461 100644 --- a/demos/workflow/inc/config.php +++ b/demos/workflow/inc/config.php @@ -1,5 +1,5 @@ GetCode()); - MangoPay\Logs::Debug('Message', $e->GetMessage()); - MangoPay\Logs::Debug('Details', $e->GetErrorDetails()); + MangoPay\Libraries\Logs::Debug('MangoPay\ResponseException Code', $e->GetCode()); + MangoPay\Libraries\Logs::Debug('Message', $e->GetMessage()); + MangoPay\Libraries\Logs::Debug('Details', $e->GetErrorDetails()); - } catch (MangoPay\Exception $e) { + } catch (MangoPay\Libraries\Exception $e) { $apiError = true; - MangoPay\Logs::Debug('MangoPay\Exception Message', $e->GetMessage()); + MangoPay\Libraries\Logs::Debug('MangoPay\Exception Message', $e->GetMessage()); } ?> diff --git a/tests/cases/base.php b/tests/cases/base.php index d95d7b07..1a2182b1 100644 --- a/tests/cases/base.php +++ b/tests/cases/base.php @@ -3,7 +3,7 @@ namespace MangoPay\Tests; require_once '../simpletest/autorun.php'; -require_once '../../MangoPaySDK/mangoPayApi.inc'; +require_once '../../MangoPay/Autoloader.php'; require_once '../mocks/mockStorageStrategy.php'; set_time_limit(0); @@ -601,8 +601,8 @@ protected function getJohnHook() { * but ONLY FOR INPUT PROPERTIES, i.e. properties that are accepted by Create methods: * IGNORES SYSTEM PROPERTIES set by the Mango API (Id, CreationDate etc). * - * @param \MangoPay\EntityBase $entity1 - * @param \MangoPay\EntityBase $entity2 + * @param \MangoPay\Libraries\EntityBase $entity1 + * @param \MangoPay\Libraries\EntityBase $entity2 */ protected function assertIdenticalInputProps($entity1, $entity2) { diff --git a/tests/cases/clients.php b/tests/cases/clients.php index c6963984..b0c0c60e 100644 --- a/tests/cases/clients.php +++ b/tests/cases/clients.php @@ -16,7 +16,7 @@ function test_ClientsCreateClient() { function test_Clients_TryCreateInvalidClient() { // invalid id - $this->expectException('MangoPay\ResponseException'); + $this->expectException('MangoPay\Libraries\ResponseException'); $client = $this->_api->Clients->create("0", "test", "test@o2.pl"); $this->assertTrue($client == null); } diff --git a/tests/cases/configurations.php b/tests/cases/configurations.php index 268e8d70..5108082d 100644 --- a/tests/cases/configurations.php +++ b/tests/cases/configurations.php @@ -11,7 +11,7 @@ function test_confInConstruct() { $this->_api->Config->ClientId = "test_asd"; $this->_api->Config->ClientPassword = "00000"; - $this->expectException('MangoPay\ResponseException'); + $this->expectException('MangoPay\Libraries\ResponseException'); $this->_api->Users->GetAll(); } } diff --git a/tests/cases/tokens.php b/tests/cases/tokens.php index 69d4639b..515fe085 100644 --- a/tests/cases/tokens.php +++ b/tests/cases/tokens.php @@ -15,7 +15,7 @@ function test_forceToken() { } function test_storeToken() { - $token = new \MangoPay\OAuthToken(); + $token = new \MangoPay\Libraries\OAuthToken(); $token->access_token = 'access test'; $token->token_type = 'type test'; $token->expires_in = 500; diff --git a/tests/cases/users.php b/tests/cases/users.php index 9705e4fe..0824664a 100644 --- a/tests/cases/users.php +++ b/tests/cases/users.php @@ -302,7 +302,7 @@ function test_Users_CreateKycDocument_TestAll(){ foreach ($aKycDocTypes as $kycDoc) { try{ $this->CreateKycDocument_TestOne($kycDoc[0], $kycDoc[1]); - } catch (\MangoPay\Exception $exc){ + } catch (\MangoPay\Libraries\Exception $exc){ $message = 'Error (Code: ' . $exc->getCode() . ', ' . $exc->getMessage() . ') ' @@ -349,7 +349,7 @@ function test_Users_CreateKycPage_EmptyFileString(){ $this->_api->Users->CreateKycPage($user->Id, $kycDocument->Id, $kycPage); $this->fail('Expected ResponseException when empty file string'); - } catch (\MangoPay\ResponseException $exc) { + } catch (\MangoPay\Libraries\ResponseException $exc) { $this->assertIdentical($exc->getCode(), 500); } @@ -365,7 +365,7 @@ function test_Users_CreateKycPage_WrongFileString(){ $this->_api->Users->CreateKycPage($user->Id, $kycDocument->Id, $kycPage); $this->fail('Expected ResponseException when wrong value for file string'); - } catch (\MangoPay\ResponseException $exc) { + } catch (\MangoPay\Libraries\ResponseException $exc) { $this->assertIdentical($exc->getCode(), 500); } @@ -472,7 +472,7 @@ function test_Users_CreateKycPage_EmptyFilePath() { try{ $this->_api->Users->CreateKycPageFromFile($user->Id, $kycDocument->Id, ''); - } catch (\MangoPay\Exception $exc) { + } catch (\MangoPay\Libraries\Exception $exc) { $this->assertIdentical($exc->getMessage(), 'Path of file cannot be empty'); } @@ -487,7 +487,7 @@ function test_Users_CreateKycPage_WrongFilePath() { try{ $this->_api->Users->CreateKycPageFromFile($user->Id, $kycDocument->Id, 'notExistFileName.tmp'); - } catch (\MangoPay\Exception $exc) { + } catch (\MangoPay\Libraries\Exception $exc) { $this->assertIdentical($exc->getMessage(), 'File not exist'); } diff --git a/tests/mocks/mockStorageStrategy.php b/tests/mocks/mockStorageStrategy.php index ff4f2017..9eaf82fb 100644 --- a/tests/mocks/mockStorageStrategy.php +++ b/tests/mocks/mockStorageStrategy.php @@ -4,13 +4,13 @@ /** * Storage strategy implementation for tests */ -class MockStorageStrategy implements \MangoPay\IStorageStrategy { +class MockStorageStrategy implements \MangoPay\Libraries\IStorageStrategy { private static $_oAuthToken = null; /** * Gets the current authorization token. - * @return \MangoPay\OAuthToken Currently stored token instance or null. + * @return \MangoPay\Libraries\OAuthToken Currently stored token instance or null. */ public function Get() { return self::$_oAuthToken; @@ -18,7 +18,7 @@ public function Get() { /** * Stores authorization token passed as an argument. - * @param \MangoPay\OAuthToken $token Token instance to be stored. + * @param \MangoPay\Libraries\OAuthToken $token Token instance to be stored. */ public function Store($token) { self::$_oAuthToken = $token;