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

PW-911 Create ConnectedTerminals request into PHP Library #108

Merged
merged 2 commits into from
Jun 21, 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
18 changes: 15 additions & 3 deletions src/Adyen/Service/PosPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ class PosPayment extends \Adyen\ApiKeyAuthenticatedService
*/
protected $runTenderAsync;

/**
* @var
*/
/**
* @var
*/
protected $txType;

/**
* @var ResourceModel\Payment\ConnectedTerminals
*/
protected $connectedTerminals;

/**
* PosPayment constructor.
*
Expand All @@ -30,6 +35,7 @@ public function __construct(\Adyen\Client $client)
parent::__construct($client);
$this->runTenderSync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, false);
$this->runTenderAsync = new \Adyen\Service\ResourceModel\Payment\TerminalCloudAPI($this, true);
$this->connectedTerminals = new \Adyen\Service\ResourceModel\Payment\ConnectedTerminals($this);
}

/**
Expand Down Expand Up @@ -65,4 +71,10 @@ public function getServiceId($request)
}
return null;
}

public function getConnectedTerminals($params)
{
$result = $this->connectedTerminals->request($params);
return $result;
}
}
22 changes: 22 additions & 0 deletions src/Adyen/Service/ResourceModel/Payment/ConnectedTerminals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Adyen\Service\ResourceModel\Payment;

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

/**
* ConnectedTerminals constructor.
*
* @param $service
*/
public function __construct($service)
{
$this->endpoint = $service->getClient()->getConfig()->get('endpointTerminalCloud') . '/connectedTerminals';
parent::__construct($service, $this->endpoint);
}
}
40 changes: 40 additions & 0 deletions tests/MockTest/PosPaymentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Adyen\MockTest;

use Monolog\Handler\StreamHandler;

class PosPaymentTest extends TestCaseMock
{
/**
* @param $jsonFile Json file location
* @param $httpStatus expected http status code
* @dataProvider resultSuccessGetConnectedTerminals
*/
public function testGetConnectedTerminalsSuccess($jsonFile, $httpStatus)
{
// create client
$client = $this->createMockClient($jsonFile, $httpStatus);

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

$json = '{
"merchantAccount": "PME_POS"
}';

$params = json_decode($json, true);

$result = $service->getConnectedTerminals($params);
var_dump($result);

$this->assertArrayHasKey('uniqueTerminalIds', $result);
}

public static function resultSuccessGetConnectedTerminals()
{
return array(
array('tests/Resources/Payment/connected-terminals.json', 200)
);
}
}
41 changes: 41 additions & 0 deletions tests/PosPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class PosPaymentTest extends TestCase

public function testCreatePosPaymentSuccess()
{
if (empty($this->settings['POIID']) || $this->settings['POIID'] = 'UNIQUETERMINALID') {
$this->skipTest("Skipped the test. Configure your POIID in the config");
}

// initialize client
$client = $this->createTerminalCloudAPIClient();

Expand Down Expand Up @@ -69,6 +73,11 @@ public function testCreatePosPaymentSuccess()

public function testCreatePosPaymentDeclined()
{

if (empty($this->settings['POIID']) || $this->settings['POIID'] = 'UNIQUETERMINALID') {
$this->skipTest("Skipped the test. Configure your POIID in the config");
}

// initialize client
$client = $this->createTerminalCloudAPIClient();

Expand Down Expand Up @@ -129,6 +138,10 @@ public function testCreatePosPaymentDeclined()

public function testCreatePosEMVRefundSuccess()
{
if (empty($this->settings['POIID']) || $this->settings['POIID'] = 'UNIQUETERMINALID') {
$this->skipTest("Skipped the test. Configure your POIID in the config");
}

// initialize client
$client = $this->createTerminalCloudAPIClient();

Expand Down Expand Up @@ -193,6 +206,10 @@ public function testCreatePosEMVRefundSuccess()
*/
public function testPosPaymentFailTimeout()
{
if (empty($this->settings['POIID']) || $this->settings['POIID'] = 'UNIQUETERMINALID') {
$this->skipTest("Skipped the test. Configure your POIID in the config");
}

// initialize client
$client = $this->createTerminalCloudAPIClient();
$client->setTimeout(1);
Expand Down Expand Up @@ -251,4 +268,28 @@ public function testPosPaymentFailTimeout()

}

public function testGetConnectedTerminals()
{
// initialize client
$client = $this->createTerminalCloudAPIClient();

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

//Construct request
$json = '{
"merchantAccount": "' . $this->settings['merchantAccount'] . '"
}';

$params = json_decode($json, true); //Create associative array for passing along

try {
$result = $service->getConnectedTerminals($params);
} catch (\Exception $e) {
$this->validateApiPermission($e);
}

$this->assertTrue(isset($result['uniqueTerminalIds']));
}

}
9 changes: 9 additions & 0 deletions tests/Resources/Payment/connected-terminals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"uniqueTerminalIds" : [
"MX915-284251016",
"MX925-260390740",
"V400m-324688136",
"V400m-324688178",
"V400m-324688181"
]
}
16 changes: 8 additions & 8 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ protected function createTerminalCloudAPIClient()
// load settings from .ini file
$settings = $this->settings;

if(!isset($settings['x-api-key']) || !isset($settings['POIID']) || $settings['x-api-key'] == 'YOUR X-API KEY' || $settings['POIID'] == 'UNIQUETERMINALID'){
$this->skipTest("Skipped the test. Configure your x-api-key and POIID in the config");
if(!empty($settings['x-api-key']) || $settings['x-api-key'] == 'YOUR X-API KEY'){
$this->skipTest("Skipped the test. Configure your x-api-key in the config");
}else{

$client = new \Adyen\Client();
Expand All @@ -192,7 +192,7 @@ protected function createClientWithMerchantAccount()
// load settings from .ini file
$settings = $this->settings;

if(!isset($settings['merchantAccount']) || $settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') {
if(!empty($settings['merchantAccount']) || $settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') {
$this->skipTest("Skipped the test. Configure your MerchantAccount in the config");
return null;
}
Expand All @@ -208,7 +208,7 @@ protected function createCheckoutAPIClient()
// load settings from .ini file
$settings = $this->settings;

if(!isset($settings['x-api-key']) || $settings['x-api-key'] == 'YOUR X-API KEY'){
if(!empty($settings['x-api-key']) || $settings['x-api-key'] == 'YOUR X-API KEY'){
$this->skipTest("Skipped the test. Configure your x-api-key");
}else{
$client->setXApiKey($settings['x-api-key']);
Expand All @@ -220,7 +220,7 @@ protected function getMerchantAccount()
{
$settings = $this->settings;

if(!isset($settings['merchantAccount']) || $settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') {
if(!empty($settings['merchantAccount']) || $settings['merchantAccount'] == 'YOUR MERCHANTACCOUNT') {
return null;
}

Expand All @@ -231,7 +231,7 @@ protected function getSkinCode()
{
$settings = $this->settings;

if(!isset($settings['skinCode']) || $settings['skinCode'] == 'YOUR SKIN CODE') {
if(!empty($settings['skinCode']) || $settings['skinCode'] == 'YOUR SKIN CODE') {
return null;
}

Expand All @@ -242,7 +242,7 @@ protected function getHmacSignature()
{
$settings = $this->settings;

if(!isset($settings['hmacSignature'])|| $settings['hmacSignature'] == 'YOUR HMAC SIGNATURE') {
if(!empty($settings['hmacSignature'])|| $settings['hmacSignature'] == 'YOUR HMAC SIGNATURE') {
return null;
}

Expand All @@ -253,7 +253,7 @@ protected function getPOIID()
{
$settings = $this->settings;

if(!isset($settings['POIID']) || $settings['POIID'] == 'MODEL-SERIALNUMBER') {
if(!empty($settings['POIID']) || $settings['POIID'] == 'MODEL-SERIALNUMBER') {
return null;
}

Expand Down