Skip to content
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
36 changes: 0 additions & 36 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ public function getName(): string
public function getDefaultParameters(): array
{
return [
'certificatePath' => '',
'certificatePassword' => '',
'testMode' => false,
'clientIP' => '',
'language' => 'EN'
];
}
Expand All @@ -97,14 +94,6 @@ public function setCertificatePassword($value): self
return $this->setParameter('certificatePassword', $value);
}

/**
* @return string
*/
public function getCertificatePassword(): string
{
return $this->getParameter('certificatePassword');
}

/**
* @param string $value
* @return $this
Expand All @@ -114,14 +103,6 @@ public function setCertificatePath($value): self
return $this->setParameter('certificatePath', $value);
}

/**
* @return string
*/
public function getCertificatePath(): string
{
return $this->getParameter('certificatePath');
}

/**
* @return string
*/
Expand All @@ -139,23 +120,6 @@ public function setLanguage($value)
return $this->setParameter('language', $value);
}

/**
* @return string
*/
public function getClientIP(): string
{
return $this->getParameter('clientIP');
}

/**
* @param $value
* @return $this
*/
public function setClientIP($value)
{
return $this->setParameter('clientIP', $value);
}

/**
* Execute SMS transaction
* @param array $options
Expand Down
22 changes: 21 additions & 1 deletion src/Requests/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Omnipay\FirstDataLatvia\Requests;

use Omnipay\Common\Message\AbstractRequest as CommonAbstractRequest;
use Omnipay\Common\Exception\RuntimeException;
use Omnipay\FirstDataLatvia\Gateway;
use Omnipay\FirstDataLatvia\Responses\AbstractResponse;
use Omnipay\Common\Http\ClientInterface;
Expand Down Expand Up @@ -103,7 +104,7 @@ protected function getServerEndpoint(): string
*/
public function sendData($data): AbstractResponse
{
$this->validate('certificatePath', 'certificatePassword');
$this->validateCertificate();

$requestMethod = 'POST';
$requestUrl = $this->getServerEndpoint();
Expand All @@ -127,6 +128,25 @@ public function sendData($data): AbstractResponse
return $responseObj;
}

/**
* @throws \Omnipay\Common\Exception\RuntimeException
*/
protected function validateCertificate()
{
$this->validate('certificatePath', 'certificatePassword');

# check if certificate exists
if (!file_exists($this->getCertificatePath())) {
throw new RuntimeException('Unexisting certificate ' . $this->getCertificatePath());
}

// test certificate parse with supplied password
$pkeyid = openssl_pkey_get_private('file://' . $this->getCertificatePath(), $this->getCertificatePassword());
if (!$pkeyid) {
throw new RuntimeException('Unable to load certificate ' . $this->getCertificatePath());
}
}

/**
* @param $response
* @return array
Expand Down
36 changes: 34 additions & 2 deletions tests/Messages/AbstractRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public function testSendDataValidateCertificatePassword()

public function testSendData()
{
$this->request->setCertificatePath("x");
$this->request->setCertificatePassword("y");
$this->request->setCertificatePath('tests/Fixtures/keystore.pem');
$this->request->setCertificatePassword('XXXX');
$this->request->setTestMode(false);

// send request to firstdata
Expand All @@ -82,6 +82,38 @@ public function testSendData()
$this->assertSame($postData, $sentPostData);
}

public function testSendDataMissingConfiguration()
{
$this->expectException(\Omnipay\Common\Exception\InvalidRequestException::class);
$this->expectExceptionMessage('The certificatePath parameter is required');

$this->request->sendData(array('some_data' => 'x'));
}

public function testSendDatatUnexistingCertificate()
{
// initiate new unconfigured gateway
$this->request->setCertificatePath('tests/Fixtures/unexisting.pem');
$this->request->setCertificatePassword('XXXX');

$this->expectException(\Omnipay\Common\Exception\RuntimeException::class);
$this->expectExceptionMessage('Unexisting certificate tests/Fixtures/unexisting.pem');

$this->request->sendData(array('some_data' => 'x'));
}

public function testSendDataInvalidCertificate()
{
$this->request->setCertificatePath('tests/Fixtures/keystore.pem');
// set wrong password
$this->request->setCertificatePassword('wrong-password');

$this->expectException(\Omnipay\Common\Exception\RuntimeException::class);
$this->expectExceptionMessage('Unable to load certificate tests/Fixtures/keystore.pem');

$this->request->sendData(array('some_data' => 'x'));
}

public function testParseResponse()
{
$this->assertEquals(array("asd" => "1", "xccx" => "3"), $this->request::parseResponse("asd: 1\nxccx: 3\n"));
Expand Down