From 3b649d6a4dcb0203a26fa47e90e945c3a089095f Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Tue, 22 Nov 2022 12:26:26 +0200 Subject: [PATCH 1/6] added Deposits methods --- MangoPay/ApiDeposits.php | 40 ++++++ MangoPay/ApiPayIns.php | 10 ++ MangoPay/CancelDeposit.php | 21 +++ .../CreateCardPreAuthorizedDepositPayIn.php | 49 +++++++ MangoPay/CreateDeposit.php | 72 ++++++++++ MangoPay/Deposit.php | 135 ++++++++++++++++++ MangoPay/DepositStatus.php | 14 ++ MangoPay/Libraries/ApiBase.php | 6 +- MangoPay/MangoPayApi.php | 7 + MangoPay/PayinsLinked.php | 19 +++ 10 files changed, 372 insertions(+), 1 deletion(-) create mode 100644 MangoPay/ApiDeposits.php create mode 100644 MangoPay/CancelDeposit.php create mode 100644 MangoPay/CreateCardPreAuthorizedDepositPayIn.php create mode 100644 MangoPay/CreateDeposit.php create mode 100644 MangoPay/Deposit.php create mode 100644 MangoPay/DepositStatus.php create mode 100644 MangoPay/PayinsLinked.php diff --git a/MangoPay/ApiDeposits.php b/MangoPay/ApiDeposits.php new file mode 100644 index 00000000..ad3b5a21 --- /dev/null +++ b/MangoPay/ApiDeposits.php @@ -0,0 +1,40 @@ +CreateObject('deposits_create', $deposit, '\MangoPay\Deposit'); + } + + /** + * Get Deposit + * @param string $depositId Deposit identifier + * @return Deposit Deposit object returned from API + */ + public function Get($depositId) + { + return $this->GetObject('deposits_get', '\MangoPay\Deposit', $depositId); + } + + /** + * Cancel Deposit + * @param string $depositId Deposit identifier + * @param CancelDeposit $dto Cancel deposit body + * @return Deposit Deposit object returned from API + */ + public function Cancel($depositId, CancelDeposit $dto) + { + return $this->SaveObject('deposits_cancel', $dto, '\MangoPay\Deposit', $depositId); + } +} diff --git a/MangoPay/ApiPayIns.php b/MangoPay/ApiPayIns.php index a674ab39..63dfd990 100644 --- a/MangoPay/ApiPayIns.php +++ b/MangoPay/ApiPayIns.php @@ -133,4 +133,14 @@ public function GetExtendedCardView($payInId) { return $this->GetObject('get_extended_card_view', '\MangoPay\PayInWebExtendedView', $payInId); } + + /** + * Create Card PreAuthorized Deposit PayIn + * @param CreateCardPreAuthorizedDepositPayIn $payIn PayIn object to create + * @return PayIn Deposit object returned from API + */ + public function CreateCardPreAuthorizedDepositPayIn(CreateCardPreAuthorizedDepositPayIn $payIn) + { + return $this->CreateObject('payins_create_card_pre_authorized_deposit', $payIn, '\MangoPay\PayIn'); + } } diff --git a/MangoPay/CancelDeposit.php b/MangoPay/CancelDeposit.php new file mode 100644 index 00000000..ebeec063 --- /dev/null +++ b/MangoPay/CancelDeposit.php @@ -0,0 +1,21 @@ + ['/recurringpayinregistrations/%s', RequestType::GET], 'payins_recurring_registration_put' => ['/recurringpayinregistrations/%s', RequestType::PUT], 'payins_recurring_card_direct' => ['/payins/recurring/card/direct', RequestType::POST], + 'payins_create_card_pre_authorized_deposit' => ['/payins/deposit-preauthorized/direct/full-capture', RequestType::POST], 'repudiation_get' => ['/repudiations/%s', RequestType::GET], @@ -204,8 +205,11 @@ protected function getLogger() 'transactions_get_for_bank_account' => ['/bankaccounts/%s/transactions', RequestType::GET], 'country_authorization_get' => ['/countries/%s/authorizations', RequestType::GET], - 'country_authorization_all' => ['/countries/authorizations', RequestType::GET] + 'country_authorization_all' => ['/countries/authorizations', RequestType::GET], + 'deposits_create' => ['/deposit-preauthorizations/card/direct', RequestType::POST], + 'deposits_get' => ['/deposit-preauthorizations/%s', RequestType::GET], + 'deposits_cancel' => ['/deposit-preauthorizations/%s', RequestType::PUT] ]; /** diff --git a/MangoPay/MangoPayApi.php b/MangoPay/MangoPayApi.php index 1f93fa3c..844c4b17 100644 --- a/MangoPay/MangoPayApi.php +++ b/MangoPay/MangoPayApi.php @@ -191,6 +191,12 @@ class MangoPayApi */ public $Regulatory; + /** + * Provides Deposit methods + * @var ApiDeposits + */ + public $Deposits; + /** * Constructor */ @@ -226,6 +232,7 @@ public function __construct() $this->BankAccounts = new ApiBankAccounts($this); $this->Repudiations = new ApiRepudiations($this); $this->Regulatory = new ApiRegulatory($this); + $this->Deposits = new ApiDeposits($this); // Setting default NullLogger $this->logger = new NullLogger(); diff --git a/MangoPay/PayinsLinked.php b/MangoPay/PayinsLinked.php new file mode 100644 index 00000000..86aa9071 --- /dev/null +++ b/MangoPay/PayinsLinked.php @@ -0,0 +1,19 @@ + Date: Wed, 23 Nov 2022 12:33:46 +0200 Subject: [PATCH 2/6] added hooks --- MangoPay/EventType.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MangoPay/EventType.php b/MangoPay/EventType.php index 540ae541..263d12ac 100644 --- a/MangoPay/EventType.php +++ b/MangoPay/EventType.php @@ -74,4 +74,13 @@ class EventType const InstantPayoutSucceeded = "INSTANT_PAYOUT_SUCCEEDED"; const InstantPayoutFallbacked = "INSTANT_PAYOUT_FALLBACKED"; + + const DepositPreAuthorizationCreated = "DEPOSIT_PREAUTHORIZATION_CREATED"; + const DepositPreAuthorizationFailed = "DEPOSIT_PREAUTHORIZATION_FAILED"; + const DepositPreAuthorizationPaymentWaiting = "DEPOSIT_PREAUTHORIZATION_PAYMENT_WAITING"; + const DepositPreAuthorizationPaymentExpired = "DEPOSIT_PREAUTHORIZATION_PAYMENT_EXPIRED"; + const DepositPreAuthorizationPaymentCancelRequest = "DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCEL_REQUEST"; + const DepositPreAuthorizationPaymentCanceled = "DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCELED"; + const DepositPreAuthorizationPaymentValidated = "DEPOSIT_PREAUTHORIZATION_PAYMENT_VALIDATED"; + } From 37ed184d55a457da42d0cff46fb21b6748334ed4 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Wed, 23 Nov 2022 18:15:16 +0200 Subject: [PATCH 3/6] added test for Create Deposit --- MangoPay/CreateDeposit.php | 8 ++-- MangoPay/Deposit.php | 8 ++-- tests/Cases/Base.php | 84 ++++++++++++++++++++++++++++++++----- tests/Cases/DepositTest.php | 23 ++++++++++ 4 files changed, 105 insertions(+), 18 deletions(-) create mode 100644 tests/Cases/DepositTest.php diff --git a/MangoPay/CreateDeposit.php b/MangoPay/CreateDeposit.php index 10603279..d9baa57c 100644 --- a/MangoPay/CreateDeposit.php +++ b/MangoPay/CreateDeposit.php @@ -46,12 +46,12 @@ class CreateDeposit extends Libraries\Dto public $BrowserInfo; /** - * @var Address + * @var Billing */ public $Billing; /** - * @var Address + * @var Shipping */ public $Shipping; @@ -64,8 +64,8 @@ public function GetSubObjects() $subObjects = parent::GetSubObjects(); $subObjects['DebitedFunds'] = '\MangoPay\Money'; $subObjects['BrowserInfo'] = '\MangoPay\BrowserInfo'; - $subObjects['Billing'] = '\MangoPay\Address'; - $subObjects['Shipping'] = '\MangoPay\Address'; + $subObjects['Billing'] = '\MangoPay\Billing'; + $subObjects['Shipping'] = '\MangoPay\Shipping'; return $subObjects; } diff --git a/MangoPay/Deposit.php b/MangoPay/Deposit.php index f1a5de83..287d29ad 100644 --- a/MangoPay/Deposit.php +++ b/MangoPay/Deposit.php @@ -98,12 +98,12 @@ class Deposit extends Libraries\EntityBase public $BrowserInfo; /** - * @var Address + * @var Billing */ public $Billing; /** - * @var Address + * @var Shipping */ public $Shipping; @@ -127,8 +127,8 @@ public function GetSubObjects() $subObjects['PayinsLinked'] = '\MangoPay\PayinsLinked'; $subObjects['DebitedFunds'] = '\MangoPay\Money'; $subObjects['BrowserInfo'] = '\MangoPay\BrowserInfo'; - $subObjects['Billing'] = '\MangoPay\Address'; - $subObjects['Shipping'] = '\MangoPay\Address'; + $subObjects['Billing'] = '\MangoPay\Billing'; + $subObjects['Shipping'] = '\MangoPay\Shipping'; return $subObjects; } diff --git a/tests/Cases/Base.php b/tests/Cases/Base.php index 47f926d9..604f0f6d 100644 --- a/tests/Cases/Base.php +++ b/tests/Cases/Base.php @@ -2,15 +2,17 @@ namespace MangoPay\Tests\Cases; +use MangoPay\Address; use MangoPay\BankAccount; use MangoPay\BankAccountDetailsIBAN; +use MangoPay\Billing; use MangoPay\Birthplace; use MangoPay\BrowserInfo; -use MangoPay\Libraries\Logs; +use MangoPay\CreateDeposit; +use MangoPay\Money; use MangoPay\Tests\Mocks\MockStorageStrategy; use MangoPay\Ubo; use PHPUnit\Framework\TestCase; -use Psr\Log\NullLogger; set_time_limit(0); @@ -151,11 +153,11 @@ protected function buildJohn() /** * Creates new address - * @return \MangoPay\Address + * @return Address */ protected function getNewAddress() { - $result = new \MangoPay\Address(); + $result = new Address(); $result->AddressLine1 = 'Address line 1'; $result->AddressLine2 = 'Address line 2'; @@ -525,6 +527,33 @@ protected function getPaylineCorrectRegistrationData($cardRegistration) return $response; } + protected function getCardRegistrationForDeposit() + { + $cardRegistration = $this->getJohnsCardRegistration(); + + $data = 'data=' . $cardRegistration->PreregistrationData . + '&accessKeyRef=' . $cardRegistration->AccessKey . + '&cardNumber=4970105181818183' . + '&cardExpirationDate=1224' . + '&cardCvx=123'; + + $curlHandle = curl_init($cardRegistration->CardRegistrationURL); + curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curlHandle, CURLOPT_POST, true); + curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $data); + $response = curl_exec($curlHandle); + if ($response === false && curl_errno($curlHandle) != 0) { + throw new \Exception('cURL error: ' . curl_error($curlHandle)); + } + + curl_close($curlHandle); + + $cardRegistration->RegistrationData = $response; + + return $this->_api->CardRegistrations->Update($cardRegistration); + } + /** * Creates mandate belonging to John * @return \MangoPay\Mandate @@ -669,13 +698,13 @@ protected function getNewPayInCardDirect($userId = null) $payIn->ExecutionDetails->SecureModeReturnURL = 'http://test.com'; $payIn->ExecutionDetails->Culture = 'FR'; - $address = new \MangoPay\Address(); + $address = new Address(); $address->AddressLine1 = 'Main Street no 5'; $address->City = 'Paris'; $address->Country = 'FR'; $address->PostalCode = '68400'; $address->Region = 'Europe'; - $billing = new \MangoPay\Billing(); + $billing = new Billing(); $billing->FirstName = 'John'; $billing->LastName = 'Doe'; $billing->Address = $address; @@ -726,13 +755,13 @@ protected function getNewPayInCardDirect3DSecure($userId = null) $payIn->ExecutionDetails->SecureModeReturnURL = 'http://test.com'; $payIn->ExecutionDetails->Culture = 'FR'; - $address = new \MangoPay\Address(); + $address = new Address(); $address->AddressLine1 = 'Main Street no 5'; $address->City = 'Paris'; $address->Country = 'FR'; $address->PostalCode = '68400'; $address->Region = 'Europe'; - $billing = new \MangoPay\Billing(); + $billing = new Billing(); $billing->FirstName = 'John'; $billing->LastName = 'Doe'; $billing->Address = $address; @@ -861,13 +890,13 @@ protected function getJohnsCardPreAuthorization($idempotencyKey = null) $cardPreAuthorization->IpAddress = "2001:0620:0000:0000:0211:24FF:FE80:C12C"; $cardPreAuthorization->BrowserInfo = $this->getBrowserInfo(); - $address = new \MangoPay\Address(); + $address = new Address(); $address->AddressLine1 = 'Main Street no 5'; $address->City = 'Paris'; $address->Country = 'FR'; $address->PostalCode = '68400'; $address->Region = 'Europe'; - $billing = new \MangoPay\Billing(); + $billing = new Billing(); $billing->FirstName = 'John'; $billing->LastName = 'Doe'; $billing->Address = $address; @@ -1238,4 +1267,39 @@ protected function getBrowserInfo() return $browserInfo; } + + protected function getNewDeposit($cardId, $authorId) + { + $deposit = new CreateDeposit(); + + $deposit->AuthorId = $authorId; + $deposit->CardId = $cardId; + + $deposit->DebitedFunds = new Money(); + $deposit->DebitedFunds->Currency = 'EUR'; + $deposit->DebitedFunds->Amount = 1000; + + $deposit->SecureModeReturnURL = "http://mangopay-sandbox-test.com"; + $deposit->StatementDescriptor = "lorem"; + $deposit->Culture = "FR"; + $deposit->IpAddress = "2001:0620:0000:0000:0211:24FF:FE80:C12C"; + $deposit->BrowserInfo = $this->getBrowserInfo(); + + $address = new Address(); + $address->AddressLine1 = 'Main Street no 5'; + $address->City = 'Paris'; + $address->Country = 'FR'; + $address->PostalCode = '68400'; + $address->Region = 'Europe'; + + $billing = new Billing(); + $billing->FirstName = 'John'; + $billing->LastName = 'Doe'; + $billing->Address = $address; + + $deposit->Billing = $billing; + $deposit->Shipping = $billing; + + return $deposit; + } } diff --git a/tests/Cases/DepositTest.php b/tests/Cases/DepositTest.php new file mode 100644 index 00000000..3fe19e92 --- /dev/null +++ b/tests/Cases/DepositTest.php @@ -0,0 +1,23 @@ +getCardRegistrationForDeposit(); + $user = $this->getJohn(); + + $deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id)); + + $this->assertNotNull($deposit); + } +} From 1559e6908d97fc465fbb55a6bbac2dbb7c39f1e7 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Thu, 24 Nov 2022 16:12:50 +0200 Subject: [PATCH 4/6] added more tests --- tests/Cases/DepositTest.php | 36 ++++++++++++++++++++++++++++++++++++ tests/Cases/PayInsTest.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/tests/Cases/DepositTest.php b/tests/Cases/DepositTest.php index 3fe19e92..747eaf55 100644 --- a/tests/Cases/DepositTest.php +++ b/tests/Cases/DepositTest.php @@ -2,6 +2,8 @@ namespace MangoPay\Tests\Cases; +use MangoPay\CancelDeposit; + /** * Tests basic methods for disputes */ @@ -20,4 +22,38 @@ public function test_Deposits_Create() $this->assertNotNull($deposit); } + + /** + * @throws \Exception + */ + public function test_Deposits_Get() + { + $cardRegistration = $this->getCardRegistrationForDeposit(); + $user = $this->getJohn(); + + $deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id)); + $fetchedDeposit = $this->_api->Deposits->Get($deposit->Id); + + $this->assertEquals($deposit->Id, $fetchedDeposit->Id); + } + +// /** +// * @throws \Exception +// */ +// public function test_Deposits_Cancel() +// { +// $cardRegistration = $this->getCardRegistrationForDeposit(); +// $user = $this->getJohn(); +// +// $deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id)); +// +// $dto = new CancelDeposit(); +// $dto->PaymentStatus = "CANCELED"; +// +// $this->_api->Deposits->Cancel($deposit->Id, $dto); +// +// $fetchedDeposit = $this->_api->Deposits->Get($deposit->Id); +// +// $this->assertEquals("CANCELED", $fetchedDeposit->PaymentStatus); +// } } diff --git a/tests/Cases/PayInsTest.php b/tests/Cases/PayInsTest.php index f55a43f5..ad34c69a 100644 --- a/tests/Cases/PayInsTest.php +++ b/tests/Cases/PayInsTest.php @@ -5,6 +5,7 @@ use MangoPay\AVSResult; use MangoPay\BankingAlias; use MangoPay\BrowserInfo; +use MangoPay\CreateCardPreAuthorizedDepositPayIn; use MangoPay\CurrencyIso; use MangoPay\DebitedBankAccount; use MangoPay\Libraries\Exception; @@ -693,4 +694,37 @@ public function test_ExampleOf3DSecureV2_1() $this->assertEquals($payIn->ExecutionDetails->Requested3DSVersion, "V2_1"); $this->assertEquals($payIn->ExecutionDetails->Applied3DSVersion, "V2_1"); } + +// /** +// * @throws \Exception +// */ +// public function test_CreateCardPreAuthorizedDepositPayIn() { +// $cardRegistration = $this->getCardRegistrationForDeposit(); +// $user = $this->getJohn(); +// $wallet = $this->getJohnsWallet(); +// +// $deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id)); +// +// $dto = new CreateCardPreAuthorizedDepositPayIn(); +// $dto->DepositId = $deposit->Id; +// $dto->AuthorId = $user->Id; +// $dto->CreditedWalletId = $wallet->Id; +// +// $debitedFunds = new Money(); +// $debitedFunds->Amount = 500; +// $debitedFunds->Currency = "EUR"; +// +// $fees = new Money(); +// $fees->Amount = 0; +// $fees->Currency = "EUR"; +// +// $dto->DebitedFunds = $debitedFunds; +// $dto->Fees = $fees; +// +// $payIn = $this->_api->PayIns->CreateCardPreAuthorizedDepositPayIn($dto); +// print_r($payIn); +// +// $this->assertNotNull($payIn); +// $this->assertEquals("SUCCEEDED", $payIn->Status); +// } } From 5f56fad692ce6b4c6841dc7451658fdddf9371b6 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Thu, 24 Nov 2022 16:18:15 +0200 Subject: [PATCH 5/6] fixed linter --- MangoPay/EventType.php | 1 - tests/Cases/DepositTest.php | 4 ---- 2 files changed, 5 deletions(-) diff --git a/MangoPay/EventType.php b/MangoPay/EventType.php index 263d12ac..c941241d 100644 --- a/MangoPay/EventType.php +++ b/MangoPay/EventType.php @@ -82,5 +82,4 @@ class EventType const DepositPreAuthorizationPaymentCancelRequest = "DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCEL_REQUEST"; const DepositPreAuthorizationPaymentCanceled = "DEPOSIT_PREAUTHORIZATION_PAYMENT_CANCELED"; const DepositPreAuthorizationPaymentValidated = "DEPOSIT_PREAUTHORIZATION_PAYMENT_VALIDATED"; - } diff --git a/tests/Cases/DepositTest.php b/tests/Cases/DepositTest.php index 747eaf55..ebe29247 100644 --- a/tests/Cases/DepositTest.php +++ b/tests/Cases/DepositTest.php @@ -2,14 +2,11 @@ namespace MangoPay\Tests\Cases; -use MangoPay\CancelDeposit; - /** * Tests basic methods for disputes */ class DepositTest extends Base { - /** * @throws \Exception */ @@ -36,7 +33,6 @@ public function test_Deposits_Get() $this->assertEquals($deposit->Id, $fetchedDeposit->Id); } - // /** // * @throws \Exception // */ From 3deea227048fc4727fecf646e023d4ad584bbc6e Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Thu, 24 Nov 2022 16:42:01 +0200 Subject: [PATCH 6/6] fixed tests --- tests/Cases/Base.php | 8 ++++++-- tests/Cases/DepositTest.php | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/Cases/Base.php b/tests/Cases/Base.php index 604f0f6d..c46309dc 100644 --- a/tests/Cases/Base.php +++ b/tests/Cases/Base.php @@ -527,9 +527,13 @@ protected function getPaylineCorrectRegistrationData($cardRegistration) return $response; } - protected function getCardRegistrationForDeposit() + protected function getCardRegistrationForDeposit($userId) { - $cardRegistration = $this->getJohnsCardRegistration(); + $cardRegistration = new \MangoPay\CardRegistration(); + $cardRegistration->UserId = $userId; + $cardRegistration->Currency = 'EUR'; + + $cardRegistration = $this->_api->CardRegistrations->Create($cardRegistration); $data = 'data=' . $cardRegistration->PreregistrationData . '&accessKeyRef=' . $cardRegistration->AccessKey . diff --git a/tests/Cases/DepositTest.php b/tests/Cases/DepositTest.php index ebe29247..32ce2c0e 100644 --- a/tests/Cases/DepositTest.php +++ b/tests/Cases/DepositTest.php @@ -12,8 +12,8 @@ class DepositTest extends Base */ public function test_Deposits_Create() { - $cardRegistration = $this->getCardRegistrationForDeposit(); $user = $this->getJohn(); + $cardRegistration = $this->getCardRegistrationForDeposit($user->Id); $deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id)); @@ -25,8 +25,8 @@ public function test_Deposits_Create() */ public function test_Deposits_Get() { - $cardRegistration = $this->getCardRegistrationForDeposit(); $user = $this->getJohn(); + $cardRegistration = $this->getCardRegistrationForDeposit($user->Id); $deposit = $this->_api->Deposits->Create($this->getNewDeposit($cardRegistration->CardId, $user->Id)); $fetchedDeposit = $this->_api->Deposits->Get($deposit->Id);