diff --git a/tests/Cases/Base.php b/tests/Cases/Base.php index f21f1339..5495f4d3 100644 --- a/tests/Cases/Base.php +++ b/tests/Cases/Base.php @@ -5,6 +5,7 @@ use MangoPay\BankAccount; use MangoPay\BankAccountDetailsIBAN; use MangoPay\Birthplace; +use MangoPay\BrowserInfo; use MangoPay\Libraries\Logs; use MangoPay\Tests\Mocks\MockStorageStrategy; use MangoPay\Ubo; @@ -359,7 +360,7 @@ protected function getJohnsWalletWithMoneyAndCardId($amount = 1000) $cardRegistration->Currency = 'EUR'; $cardRegistration = $this->_api->CardRegistrations->Create($cardRegistration); - $cardRegistration->RegistrationData = $this->getPaylineCorrectRegistartionData3DSecure($cardRegistration); + $cardRegistration->RegistrationData = $this->getPaylineCorrectRegistrationData3DSecure($cardRegistration); $cardRegistration = $this->_api->CardRegistrations->Update($cardRegistration); $card = $this->_api->Cards->Get($cardRegistration->CardId); @@ -414,7 +415,7 @@ protected function getJohnsWalletWithMoney($amount = 1000) $cardRegistration->Currency = 'EUR'; $cardRegistration = $this->_api->CardRegistrations->Create($cardRegistration); - $cardRegistration->RegistrationData = $this->getPaylineCorrectRegistartionData($cardRegistration); + $cardRegistration->RegistrationData = $this->getPaylineCorrectRegistrationData($cardRegistration); $cardRegistration = $this->_api->CardRegistrations->Update($cardRegistration); $card = $this->_api->Cards->Get($cardRegistration->CardId); @@ -449,7 +450,7 @@ protected function getJohnsWalletWithMoney($amount = 1000) * @param \MangoPay\CardRegistration $cardRegistration * @return string */ - protected function getPaylineCorrectRegistartionData3DSecure($cardRegistration) + protected function getPaylineCorrectRegistrationData3DSecure($cardRegistration) { /* @@ -481,7 +482,7 @@ protected function getPaylineCorrectRegistartionData3DSecure($cardRegistration) * @param \MangoPay\CardRegistration $cardRegistration * @return string */ - protected function getPaylineCorrectRegistartionData($cardRegistration) + protected function getPaylineCorrectRegistrationData($cardRegistration) { /* @@ -627,7 +628,7 @@ protected function getNewPayInCardDirect($userId = null) $cardRegistration->UserId = $userId; $cardRegistration->Currency = 'EUR'; $cardRegistration = $this->_api->CardRegistrations->Create($cardRegistration); - $cardRegistration->RegistrationData = $this->getPaylineCorrectRegistartionData($cardRegistration); + $cardRegistration->RegistrationData = $this->getPaylineCorrectRegistrationData($cardRegistration); $cardRegistration = $this->_api->CardRegistrations->Update($cardRegistration); $card = $this->_api->Cards->Get($cardRegistration->CardId); @@ -667,6 +668,73 @@ protected function getNewPayInCardDirect($userId = null) return $this->_api->PayIns->Create($payIn); } + /** + * Creates Pay-In Card Direct object + * @return \MangoPay\PayIn + */ + protected function getNewPayInCardDirect3DSecure($userId = null) + { + $wallet = $this->getJohnsWalletWithMoney(); + if (is_null($userId)) { + $user = $this->getJohn(); + $userId = $user->Id; + } + + $cardRegistration = new \MangoPay\CardRegistration(); + $cardRegistration->UserId = $userId; + $cardRegistration->Currency = 'EUR'; + $cardRegistration = $this->_api->CardRegistrations->Create($cardRegistration); + $cardRegistration->RegistrationData = $this->getPaylineCorrectRegistrationData3DSecure($cardRegistration); + $cardRegistration = $this->_api->CardRegistrations->Update($cardRegistration); + + $card = $this->_api->Cards->Get($cardRegistration->CardId); + + // create pay-in CARD DIRECT + $payIn = new \MangoPay\PayIn(); + $payIn->CreditedWalletId = $wallet->Id; + $payIn->AuthorId = $userId; + $payIn->DebitedFunds = new \MangoPay\Money(); + $payIn->DebitedFunds->Amount = 1000; + $payIn->DebitedFunds->Currency = 'EUR'; + $payIn->Fees = new \MangoPay\Money(); + $payIn->Fees->Amount = 0; + $payIn->Fees->Currency = 'EUR'; + // payment type as CARD + $payIn->PaymentDetails = new \MangoPay\PayInPaymentDetailsCard(); + $payIn->PaymentDetails->CardId = $card->Id; + $payIn->PaymentDetails->IpAddress = "2001:0620:0000:0000:0211:24FF:FE80:C12C"; + $browserInfo = new BrowserInfo(); + $browserInfo->AcceptHeader = "text/html, application/xhtml+xml, application/xml;q=0.9, /;q=0.8"; + $browserInfo->JavaEnabled = true; + $browserInfo->Language = "FR-FR"; + $browserInfo->ColorDepth = 4; + $browserInfo->ScreenHeight = 1800; + $browserInfo->ScreenWidth = 400; + $browserInfo->JavascriptEnabled = true; + $browserInfo->TimeZoneOffset = "+60"; + $browserInfo->UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"; + $payIn->PaymentDetails->BrowserInfo = $browserInfo; + // execution type as DIRECT + $payIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsDirect(); + $payIn->ExecutionDetails->SecureModeReturnURL = 'http://test.com'; + $payIn->ExecutionDetails->Culture = 'FR'; + + $address = new \MangoPay\Address(); + $address->AddressLine1 = 'Main Street no 5'; + $address->City = 'Paris'; + $address->Country = 'FR'; + $address->PostalCode = '68400'; + $address->Region = 'Europe'; + $billing = new \MangoPay\Billing(); + $billing->FirstName = 'John'; + $billing->LastName = 'Doe'; + $billing->Address = $address; + $payIn->ExecutionDetails->Billing = $billing; + $payIn->ExecutionDetails->Requested3DSVersion = "V2_1"; + + return $this->_api->PayIns->Create($payIn); + } + /** * Creates Pay-Out Bank Wire object * @return \MangoPay\Transfer @@ -772,7 +840,7 @@ protected function getJohnsCardPreAuthorization($idempotencyKey = null) $cardRegistration->Currency = 'EUR'; $newCardRegistration = $this->_api->CardRegistrations->Create($cardRegistration); - $registrationData = $this->getPaylineCorrectRegistartionData($newCardRegistration); + $registrationData = $this->getPaylineCorrectRegistrationData($newCardRegistration); $newCardRegistration->RegistrationData = $registrationData; $getCardRegistration = $this->_api->CardRegistrations->Update($newCardRegistration); diff --git a/tests/Cases/CardRegistrationsTest.php b/tests/Cases/CardRegistrationsTest.php index 656b6441..2a46b21e 100644 --- a/tests/Cases/CardRegistrationsTest.php +++ b/tests/Cases/CardRegistrationsTest.php @@ -34,7 +34,7 @@ public function test_CardRegistrations_Get() public function test_CardRegistrations_Update() { $cardRegistration = $this->getJohnsCardRegistration(); - $registrationData = $this->getPaylineCorrectRegistartionData($cardRegistration); + $registrationData = $this->getPaylineCorrectRegistrationData($cardRegistration); $cardRegistration->RegistrationData = $registrationData; $getCardRegistration = $this->_api->CardRegistrations->Update($cardRegistration); diff --git a/tests/Cases/IdempotencyTest.php b/tests/Cases/IdempotencyTest.php index df7760e7..cafd9098 100644 --- a/tests/Cases/IdempotencyTest.php +++ b/tests/Cases/IdempotencyTest.php @@ -150,7 +150,7 @@ public function test_GetIdempotencyKey_PayinsCardDirectCreate() $cardRegistration->UserId = $userId; $cardRegistration->Currency = 'EUR'; $cardRegistration = $this->_api->CardRegistrations->Create($cardRegistration); - $cardRegistration->RegistrationData = $this->getPaylineCorrectRegistartionData($cardRegistration); + $cardRegistration->RegistrationData = $this->getPaylineCorrectRegistrationData($cardRegistration); $cardRegistration = $this->_api->CardRegistrations->Update($cardRegistration); $card = $this->_api->Cards->Get($cardRegistration->CardId); $payIn = new \MangoPay\PayIn(); diff --git a/tests/Cases/PayInsTest.php b/tests/Cases/PayInsTest.php index d6a0e60c..87b133e5 100644 --- a/tests/Cases/PayInsTest.php +++ b/tests/Cases/PayInsTest.php @@ -606,4 +606,31 @@ public function test_PayIns_Google_Pay_Create() $this->assertEquals(1, $createPayIn->Fees->Amount); $this->assertEquals("EUR", $createPayIn->Fees->Currency); } + + + public function test_ExampleOf3DSecureV2_1() + { + $johnWallet = $this->getJohnsWalletWithMoney(); + $beforeWallet = $this->_api->Wallets->Get($johnWallet->Id); + + $payIn = $this->getNewPayInCardDirect3DSecure(); + $wallet = $this->_api->Wallets->Get($johnWallet->Id); + $user = $this->getJohn(); + + $this->assertTrue($payIn->Id > 0); + $this->assertEquals($wallet->Id, $payIn->CreditedWalletId); + $this->assertEquals(\MangoPay\PayInPaymentType::Card, $payIn->PaymentType); + $this->assertInstanceOf('\MangoPay\PayInPaymentDetailsCard', $payIn->PaymentDetails); + $this->assertEquals(\MangoPay\PayInExecutionType::Direct, $payIn->ExecutionType); + $this->assertInstanceOf('\MangoPay\PayInExecutionDetailsDirect', $payIn->ExecutionDetails); + $this->assertInstanceOf('\MangoPay\Money', $payIn->DebitedFunds); + $this->assertInstanceOf('\MangoPay\Money', $payIn->CreditedFunds); + $this->assertInstanceOf('\MangoPay\Money', $payIn->Fees); + $this->assertEquals($user->Id, $payIn->AuthorId); + $this->assertEquals($wallet->Balance->Amount, $beforeWallet->Balance->Amount + $payIn->CreditedFunds->Amount); + $this->assertEquals(PayInStatus::Succeeded, $payIn->Status); + $this->assertEquals('PAYIN', $payIn->Type); + $this->assertEquals($payIn->ExecutionDetails->Requested3DSVersion, "V2_1"); + $this->assertEquals($payIn->ExecutionDetails->Applied3DSVersion, "V2_1"); + } }