Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Get3dsAvailability into BinLookup directory #103

Merged
merged 14 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"Adyen\\Tests\\": "tests/"
}
}
}
}
11 changes: 11 additions & 0 deletions src/Adyen/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Client
const ENDPOINT_TEST_DIRECTORY_LOOKUP = "https://test.adyen.com/hpp/directory/v2.shtml";
const ENDPOINT_LIVE_DIRECTORY_LOOKUP = "https://live.adyen.com/hpp/directory/v2.shtml";
const API_PAYMENT_VERSION = "v40";
const API_BIN_LOOKUP_VERSION = "v40";
const API_PAYOUT_VERSION = "v30";
const API_RECURRING_VERSION = "v25";
const API_CHECKOUT_VERSION = "v41";
Expand Down Expand Up @@ -269,6 +270,16 @@ public function getApiPaymentVersion()
return self::API_PAYMENT_VERSION;
}

/**
* Get the version of the API BinLookUp endpoint
*
* @return string
*/
public function getApiBinLookupVersion()
{
return self::API_BIN_LOOKUP_VERSION;
}

/**
* Get the version of the API Payout endpoint
*
Expand Down
35 changes: 35 additions & 0 deletions src/Adyen/Service/BinLookup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Adyen\Service;

class BinLookup extends \Adyen\Service
{
/**
* @var ResourceModel\BinLookup\Get3dsAvailability
*/
protected $get3dsAvailability;

/**
* Payment constructor.
*
* @param \Adyen\Client $client
* @throws \Adyen\AdyenException
*/
public function __construct(\Adyen\Client $client)
{
parent::__construct($client);
$this->get3dsAvailability = new \Adyen\Service\ResourceModel\BinLookup\Get3dsAvailability($this);
}


/**
* @param $params
* @return mixed
* @throws \Adyen\AdyenException
*/
public function get3dsAvailability($params)
{
$result = $this->get3dsAvailability->request($params);
return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Adyen\Service\ResourceModel\BinLookup;

class Get3dsAvailability extends \Adyen\Service\AbstractResource
{
/**
* @var string
*/
protected $endpoint;

/**
* Include applicationInfo key in the request parameters
*
* @var bool
*/
protected $allowApplicationInfo = false;

/**
* Authorise constructor.
*
* @param \Adyen\Service $service
*/
public function __construct($service)
{
$this->endpoint = $service->getClient()->getConfig()->get('endpoint') . '/pal/servlet/BinLookup/' . $service->getClient()->getApiBinLookupVersion() . '/get3dsAvailability';
parent::__construct($service, $this->endpoint, $this->allowApplicationInfo);
}
}
56 changes: 56 additions & 0 deletions tests/BinLookupTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Adyen;


use Adyen\Util\Util;

class BinLookupTest extends TestCase {

public function testValid3dsCard()
{
// initialize client
$client = $this->createClient();

// initialize service
$service = new Service\BinLookup($client);

$json = '{
"cardNumber": "4111111111111111",
"merchantAccount": "' . $this->merchantAccount .'"
}';


$params = json_decode($json, true);

$result = $service->get3dsAvailability($params);


// 4111111111111111 is a valid 3ds card so the result should be true
$this->assertEquals(true, $result['threeDS2supported']);
}

public function testInvalid3dsCard()
{
// initialize client
$client = $this->createClient();

// initialize service
$service = new Service\BinLookup($client);

$json = '{
"cardNumber": "1111111111111111",
"merchantAccount": "' . $this->merchantAccount .'"
}';


$params = json_decode($json, true);

$result = $service->get3dsAvailability($params);


// 1111111111111111 is a invalid 3ds card so the result should be false
$this->assertEquals(false, $result['threeDS2supported']);
}

}