Skip to content

Commit

Permalink
MPSDK-893: Test for 3DSVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
SoloJr committed Oct 23, 2021
1 parent 090fd4f commit 862ea06
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 8 deletions.
80 changes: 74 additions & 6 deletions tests/Cases/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -449,7 +450,7 @@ protected function getJohnsWalletWithMoney($amount = 1000)
* @param \MangoPay\CardRegistration $cardRegistration
* @return string
*/
protected function getPaylineCorrectRegistartionData3DSecure($cardRegistration)
protected function getPaylineCorrectRegistrationData3DSecure($cardRegistration)
{

/*
Expand Down Expand Up @@ -481,7 +482,7 @@ protected function getPaylineCorrectRegistartionData3DSecure($cardRegistration)
* @param \MangoPay\CardRegistration $cardRegistration
* @return string
*/
protected function getPaylineCorrectRegistartionData($cardRegistration)
protected function getPaylineCorrectRegistrationData($cardRegistration)
{

/*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/Cases/CardRegistrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/Cases/IdempotencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 27 additions & 0 deletions tests/Cases/PayInsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 862ea06

Please sign in to comment.