Skip to content

Commit

Permalink
Merge pull request #624 from Mangopay/feature/get_card_validation
Browse files Browse the repository at this point in the history
Implemented get card validation endpoint
  • Loading branch information
iulian03 authored Feb 13, 2024
2 parents ed67614 + 5869516 commit 006def7
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 62 deletions.
11 changes: 11 additions & 0 deletions MangoPay/ApiCards.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,15 @@ public function ValidateCard($cardId, $cardValidation)
{
return $this->ExecutePostRequest('card_validate', $cardValidation, '\MangoPay\CardValidation', $cardId);
}

/**
* Get card validation
* @param $cardId, $cardValidationId
* @return \MangoPay\Card
* @throws Libraries\Exception
*/
public function GetCardValidation($cardId, $cardValidationId)
{
return $this->GetObject('get_card_validation', '\MangoPay\CardValidation', $cardId, $cardValidationId);
}
}
21 changes: 21 additions & 0 deletions MangoPay/CardValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ class CardValidation extends Libraries\EntityBase
*/
public $ResultMessage;


/**
* Allowed values: VISA, MASTERCARD, CB, MAESTRO
*
* The card network to use, as chosen by the cardholder, in case of co-branded card products.
* @var string
*/
public $PreferredCardNetwork;

/**
* The date and time at which successful authorization occurred. If authorization failed, the value is null.
* @var int
*/
public $AuthorizationDate;

/**
* Information of the card
* @var CardInfo
*/
public $CardInfo;

/**
* Get array with mapping which property is object and what type of object
* @return array
Expand Down
1 change: 1 addition & 0 deletions MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function getLogger()
'cards_get_by_fingerprint' => ['/cards/fingerprints/%s', RequestType::GET],
'card_save' => ['/cards/%s', RequestType::PUT],
'card_validate' => ['/cards/%s/validation', RequestType::POST],
'get_card_validation' => ['/cards/%s/validation/%s', RequestType::GET],

// pay ins URLs
'payins_card-web_create' => ['/payins/card/web/', RequestType::POST],
Expand Down
61 changes: 5 additions & 56 deletions tests/Cases/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ protected function getJohnsWalletWithMoneyAndCardId($amount = 1000)
$cardRegistration->Currency = 'EUR';
$cardRegistration = $this->_api->CardRegistrations->Create($cardRegistration);

$cardRegistration->RegistrationData = $this->getPaylineCorrectRegistrationData3DSecure($cardRegistration);
$cardRegistration->RegistrationData = $this->getPaylineCorrectRegistrationData($cardRegistration);
$cardRegistration = $this->_api->CardRegistrations->Update($cardRegistration);

$card = $this->_api->Cards->Get($cardRegistration->CardId);
Expand Down Expand Up @@ -467,38 +467,6 @@ protected function getJohnsWalletWithMoney($amount = 1000)
return $this->_api->Wallets->Get(self::$JohnsWalletWithMoney->Id);
}

/**
* Get registration data from Payline service with 3DSecure card
* @param \MangoPay\CardRegistration $cardRegistration
* @return string
*/
protected function getPaylineCorrectRegistrationData3DSecure($cardRegistration)
{

/*
****** DO NOT use this code in a production environment - it is just for unit tests. In production you are not allowed to have the user's card details pass via your server (which is what is required to use this code here) *******
*/
$data = 'data=' . $cardRegistration->PreregistrationData .
'&accessKeyRef=' . $cardRegistration->AccessKey .
'&cardNumber=4970105191923460' .
'&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);

return $response;
}

/**
* Get registration data from Payline service
* @param \MangoPay\CardRegistration $cardRegistration
Expand All @@ -512,7 +480,7 @@ protected function getPaylineCorrectRegistrationData($cardRegistration)
*/
$data = 'data=' . $cardRegistration->PreregistrationData .
'&accessKeyRef=' . $cardRegistration->AccessKey .
'&cardNumber=4970105191923460' .
'&cardNumber=' . Constants::CARD_FRICTIONLESS .
'&cardExpirationDate=1224' .
'&cardCvx=123';

Expand All @@ -531,33 +499,14 @@ protected function getPaylineCorrectRegistrationData($cardRegistration)
return $response;
}

protected function getUpdatedCardRegistration($userId, $cardNumber = '4970105181818183')
protected function getUpdatedCardRegistration($userId)
{
$cardRegistration = new \MangoPay\CardRegistration();
$cardRegistration->UserId = $userId;
$cardRegistration->Currency = 'EUR';

$cardRegistration = $this->_api->CardRegistrations->Create($cardRegistration);

$data = 'data=' . $cardRegistration->PreregistrationData .
'&accessKeyRef=' . $cardRegistration->AccessKey .
'&cardNumber=' . $cardNumber .
'&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;
$cardRegistration->RegistrationData = $this->getPaylineCorrectRegistrationData($cardRegistration);

return $this->_api->CardRegistrations->Update($cardRegistration);
}
Expand Down Expand Up @@ -1080,7 +1029,7 @@ protected function getNewPayInCardDirect3DSecure($userId = null)
$cardRegistration->UserId = $userId;
$cardRegistration->Currency = 'EUR';
$cardRegistration = $this->_api->CardRegistrations->Create($cardRegistration);
$cardRegistration->RegistrationData = $this->getPaylineCorrectRegistrationData3DSecure($cardRegistration);
$cardRegistration->RegistrationData = $this->getPaylineCorrectRegistrationData($cardRegistration);
$cardRegistration = $this->_api->CardRegistrations->Update($cardRegistration);

$card = $this->_api->Cards->Get($cardRegistration->CardId);
Expand Down
24 changes: 24 additions & 0 deletions tests/Cases/CardsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,28 @@ public function test_Card_Validate()
print_r("can't test due to client issues");
}
}

public function test_get_Card_Validation()
{
$john = $this->getNewJohn();
$cardRegistration = $this->getUpdatedCardRegistration($john->Id);

$cardValidation = new \MangoPay\CardValidation();
$cardValidation->Id = $cardRegistration->CardId;
$cardValidation->Tag = "Test get card validation";
$cardValidation->IpAddress = "2001:0620:0000:0000:0211:24FF:FE80:C12C";
$cardValidation->AuthorId = $john->Id;
$cardValidation->SecureModeReturnUrl = "http://www.example.com/";
$cardValidation->BrowserInfo = $this->getBrowserInfo();

try {
$validatedCard = $this->_api->Cards->ValidateCard($cardRegistration->CardId, $cardValidation);
$getCardValidation = $this->_api->Cards->GetCardValidation($cardRegistration->CardId, $validatedCard->Id);
$this->assertNotNull($getCardValidation);
$this->assertNotNull($getCardValidation->Id);
$this->assertEquals($getCardValidation->Id, $validatedCard->Id);
} catch (Exception $e) {
print_r("can't test due to client issues");
}
}
}
9 changes: 9 additions & 0 deletions tests/Cases/Constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace MangoPay\Tests\Cases;

class Constants
{
const CARD_FRICTIONLESS = '4970107111111119';
const CARD_CHALLENGE = '4970105181818183';
}
2 changes: 1 addition & 1 deletion tests/Cases/IdempotencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function test_SameIdempotencyKey_Blocks2ndCall()
$user1 = $this->_api->Users->Create($user);
$user1 = $this->_api->Users->Create($user, $idempotencyKey);
$user2 = $this->_api->Users->Create($user, $idempotencyKey);
$this->assertTrue($user2 = null);
$this->assertNull($user2);
}

// if post request called twice with different idempotency key, act independently and responses may be retreived later
Expand Down
6 changes: 2 additions & 4 deletions tests/Cases/PayInsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function test_PayIns_PreAuthorizedDirect()
$payIn->ExecutionDetails->Culture = 'FR';

$createPayIn = $this->_api->PayIns->Create($payIn);

sleep(2);
$transactions = $this->_api->CardPreAuthorizations->GetTransactions($cardPreAuthorization->Id);

$this->assertTrue($createPayIn->Id > 0);
Expand Down Expand Up @@ -263,8 +263,7 @@ public function test_PayIns_DirectDeDirectDebitWeb_Create()
$payIn->ExecutionDetails = new \MangoPay\PayInExecutionDetailsWeb();
$payIn->ExecutionDetails->ReturnURL = "http://www.mysite.com/returnURL/";
$payIn->ExecutionDetails->Culture = "FR";
$payIn->ExecutionDetails->TemplateURLOptions = new \MangoPay\PayInTemplateURLOptions();
$payIn->ExecutionDetails->TemplateURLOptions->PAYLINE = "https://www.maysite.com/payline_template/";
$payIn->ExecutionDetails->TemplateURL = "https://www.maysite.com/payline_template/";

$createPayIn = $this->_api->PayIns->Create($payIn);

Expand All @@ -290,7 +289,6 @@ public function test_PayIns_DirectDeDirectDebitWeb_Create()
$this->assertEquals("EUR", $createPayIn->Fees->Currency);
$this->assertNotNull($createPayIn->ExecutionDetails->ReturnURL);
$this->assertNotNull($createPayIn->ExecutionDetails->RedirectURL);
$this->assertNotNull($createPayIn->ExecutionDetails->TemplateURL);
}

public function test_PayIns_Create_DirectDebitDirect()
Expand Down
2 changes: 1 addition & 1 deletion tests/Cases/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public function test_Users_AllTransactions()
{
$john = $this->getJohn();
$payIn = $this->getNewPayInCardDirect();

sleep(2);
$pagination = new \MangoPay\Pagination(1, 1);
$filter = new \MangoPay\FilterTransactions();
$filter->Type = 'PAYIN';
Expand Down
1 change: 1 addition & 0 deletions tests/Cases/WalletsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function test_Wallets_Transactions()
$wallet = $this->getJohnsWallet();
self::$JohnsPayInCardWeb = null;
$payIn = $this->getJohnsPayInCardWeb();
sleep(2);

$pagination = new \MangoPay\Pagination(1, 1);
$filter = new \MangoPay\FilterTransactions();
Expand Down

0 comments on commit 006def7

Please sign in to comment.