diff --git a/README.md b/README.md
index 4f22b63..e45d0cc 100644
--- a/README.md
+++ b/README.md
@@ -4,15 +4,93 @@
> PHP banklink library to easily integrate Baltic banklinks.
-**NB!** This library **IS NOT** production ready!
-
## Composer
composer require renekorss/Banklink
+## Supported providers
+
+Provider | Payment | Authentication
+---------------- | ------------------- | -------------
+Danskebank | :white_check_mark: | :white_check_mark:
+Krediidipank | :white_check_mark: | :white_check_mark:
+LHV | :white_check_mark: | :white_check_mark:
+SEB | :white_check_mark: | :white_check_mark:
+Swedbank | :white_check_mark: | :white_check_mark:
+Nordea (coming) | :x: | :x:
+Estcard (coming) | :x: | not supported
+
## How to use?
-TODO
+> **SECURITY WARNING**
+
+> Never keep your private and public keys in publicly accessible folder. Instead place keys **under** root folder (usually `public_html` or `www`).
+
+> If you store keys as strings in database, then they should be accessible only over HTTPS protocol.
+
+### Payment
+
+````php
+getPaymentRequest(123453, 150, 'Test makse', 'EST');
+?>
+
+
+
+````
+
+### Authentication
+
+````php
+getAuthRequest();
+?>
+
+
+
+````
## Tasks
@@ -26,7 +104,3 @@ You can test your banklink with
## License
Licensed under [MIT](LICENSE)
-
-## Credits
-
-This library is based on outdated [Inoryy/Banklink](https://github.com/Inoryy/Banklink).
diff --git a/composer.json b/composer.json
index 36c8cd2..6196214 100644
--- a/composer.json
+++ b/composer.json
@@ -1,5 +1,5 @@
{
- "name": "renekorss/Banklink",
+ "name": "renekorss/banklink",
"description": "PHP banklink library to easily integrate Baltic banklinks.",
"license": "MIT",
"authors": [
@@ -9,7 +9,11 @@
}
],
"minimum-stability": "dev",
- "require": {},
+ "require": {
+ "php": ">=5.4",
+ "ext-mbstring": "*",
+ "lib-openssl": "*"
+ },
"require-dev": {
"phpunit/phpunit": "4.8.*",
"phpdocumentor/phpdocumentor": "dev-master",
diff --git a/src/Danskebank.php b/src/Danskebank.php
index c291c8f..1f71895 100644
--- a/src/Danskebank.php
+++ b/src/Danskebank.php
@@ -47,12 +47,22 @@ public function __construct(iPizza $protocol, $debug = false, $requestUrl = null
parent::__construct($protocol, $debug, $requestUrl);
}
+ /**
+ * Override encoding field
+ */
+
+ protected function getEncodingField(){
+ return 'VK_ENCODING';
+ }
+
/**
* Danskebank uses UTF-8
*
* @return array Array of additional fields to send to bank
*/
protected function getAdditionalFields(){
- return array();
+ return array(
+ 'VK_ENCODING' => $this->requestEncoding
+ );
}
}
diff --git a/src/LHV.php b/src/LHV.php
index 6d9e3ee..a924123 100644
--- a/src/LHV.php
+++ b/src/LHV.php
@@ -54,7 +54,7 @@ public function __construct(iPizza $protocol, $debug = false, $requestUrl = null
*/
protected function getEncodingField(){
- return 'VK_CHARSET';
+ return 'VK_ENCODING';
}
/**
@@ -64,7 +64,7 @@ protected function getEncodingField(){
*/
protected function getAdditionalFields(){
return array(
- 'VK_CHARSET' => $this->requestEncoding
+ 'VK_ENCODING' => $this->requestEncoding
);
}
}
diff --git a/src/Nordea.php b/src/Nordea.php
index 879aaf9..751b391 100644
--- a/src/Nordea.php
+++ b/src/Nordea.php
@@ -18,9 +18,11 @@
*
* For more information, please visit: http://www.nordea.ee/sitemod/upload/root/content/nordea_ee_ee/eeee_corporate/eeee_co_igapaevapangandus_pr/epangandus/e-makse_teh_kirj.pdf
*
+ * Coverage ignore, since SOLO protocol is not supported yet
+ *
* @author Rene Korss
*/
-
+// @codeCoverageIgnoreStart
class Nordea extends Banklink{
/**
@@ -50,3 +52,4 @@ public function __construct(Solo $protocol, $debug = false, $requestUrl = null){
parent::__construct($protocol, $debug, $requestUrl);
}
}
+// @codeCoverageIgnoreEnd
diff --git a/src/Protocol/iPizza.php b/src/Protocol/iPizza.php
index 6520982..ceaa3c8 100644
--- a/src/Protocol/iPizza.php
+++ b/src/Protocol/iPizza.php
@@ -237,7 +237,7 @@ public function handleResponse(array $response, $encoding = 'UTF-8'){
if(in_array($service, Services::getAuthenticationResponseServices())){
return $this->handleAuthResponse($response, $success);
}
- }
+ } // @codeCoverageIgnore
/**
diff --git a/tests/DanskebankTest.php b/tests/DanskebankTest.php
new file mode 100644
index 0000000..83e4711
--- /dev/null
+++ b/tests/DanskebankTest.php
@@ -0,0 +1,19 @@
+
+ */
+
+class DanskebankTest extends SEBTest{
+
+ protected $bankClass = "RKD\Banklink\Danskebank";
+
+ protected $requestUrl = "https://www2.danskebank.ee/ibank/pizza/pizza";
+ protected $testRequestUrl = "http://localhost:8080/banklink/sampo-common";
+
+}
diff --git a/tests/KrediidipankTest.php b/tests/KrediidipankTest.php
new file mode 100644
index 0000000..7426d2a
--- /dev/null
+++ b/tests/KrediidipankTest.php
@@ -0,0 +1,19 @@
+
+ */
+
+class KrediidipankTest extends SEBTest{
+
+ protected $bankClass = "RKD\Banklink\Krediidipank";
+
+ protected $requestUrl = "https://i-pank.krediidipank.ee/teller/maksa";
+ protected $testRequestUrl = "http://localhost:8080/banklink/krediidipank-common";
+
+}
diff --git a/tests/LHVTest.php b/tests/LHVTest.php
new file mode 100644
index 0000000..b500548
--- /dev/null
+++ b/tests/LHVTest.php
@@ -0,0 +1,19 @@
+
+ */
+
+class LHVTest extends SEBTest{
+
+ protected $bankClass = "RKD\Banklink\LHV";
+
+ protected $requestUrl = "https://www.lhv.ee/banklink";
+ protected $testRequestUrl = "http://localhost:8080/banklink/lhv-common";
+
+}
diff --git a/tests/Protocol/iPizzaTest.php b/tests/Protocol/iPizzaTest.php
index 0f779d4..34ed6c3 100644
--- a/tests/Protocol/iPizzaTest.php
+++ b/tests/Protocol/iPizzaTest.php
@@ -315,14 +315,15 @@ public function testHandleAuthResponseSuccess(){
public function testHandleAuthResponseError(){
$responseData = array(
- 'VK_SERVICE' => '3013',
+ 'VK_SERVICE' => '3012',
'VK_VERSION' => '008',
+ 'VK_USER' => '',
'VK_DATETIME' => '2015-10-12T08:47:15+0300',
'VK_SND_ID' => 'uid100010',
'VK_REC_ID' => 'EYP',
'VK_RID' => 'random-rid',
'VK_NONCE' => 'random-nonce',
- 'VK_USER_NAME' => 'Error here',
+ 'VK_USER_NAME' => 'Tõõger Leõpäöld',
'VK_USER_ID' => '37602294565',
'VK_COUNTRY' => 'EE',
'VK_OTHER' => '',
diff --git a/tests/SEBTest.php b/tests/SEBTest.php
index 61b99f0..321cd00 100644
--- a/tests/SEBTest.php
+++ b/tests/SEBTest.php
@@ -6,6 +6,7 @@
use RKD\Banklink\Protocol\iPizza;
use RKD\Banklink\Response\PaymentResponse;
use RKD\Banklink\Request\PaymentRequest;
+use RKD\Banklink\Request\AuthRequest;
/**
* Test suite for SEB banklink
@@ -15,6 +16,11 @@
class SEBTest extends \PHPUnit_Framework_TestCase{
+ protected $bankClass = "RKD\Banklink\SEB";
+
+ protected $requestUrl = "https://www.seb.ee/cgi-bin/unet3.sh/un3min.r";
+ protected $testRequestUrl = "http://localhost:8080/banklink/seb-common";
+
private $protocol;
private $seb;
@@ -33,7 +39,7 @@ class SEBTest extends \PHPUnit_Framework_TestCase{
private $datetime;
private $expectedData;
- private $requestUrl;
+ private $customRequestUrl;
/**
* Set test data
@@ -57,17 +63,17 @@ public function setUp(){
// From ENV variable
$this->datetime = getenv('TEST_DATETIME');
- $this->requestUrl = 'http://example.com';
+ $this->customRequestUrl = 'http://example.com';
$this->protocol = new iPizza(
$this->sellerId,
__DIR__.'/keys/iPizza/private_key.pem',
'',
__DIR__.'/keys/iPizza/public_key.pem',
- $this->requestUrl
+ $this->customRequestUrl
);
- $this->seb = new Banklink\SEB($this->protocol);
+ $this->seb = new $this->bankClass($this->protocol);
$this->expectedData = array(
'VK_SERVICE' => '1012',
@@ -78,8 +84,8 @@ public function setUp(){
'VK_CURR' => $this->currency,
'VK_REF' => ProtocolHelper::calculateReference($this->orderId),
'VK_MSG' => $this->message,
- 'VK_RETURN' => $this->requestUrl,
- 'VK_CANCEL' => $this->requestUrl,
+ 'VK_RETURN' => $this->customRequestUrl,
+ 'VK_CANCEL' => $this->customRequestUrl,
'VK_LANG' => $this->language,
'VK_MAC' => 'PmAB256IR1FzTKZHNn5LBPso/KyLAhNcTOMq82lhpYn0mXKYtVtpNkolQxyETnTcIn1TcYOmekJEATe86Bz2MRljEQqllkaIl7bNuLCtuBPtAOYWNLmQHoop+5QSiguJEmEV+JJU3w4BApjWcsHA5HYlYze+3L09UO6na0lB/Zs=',
'VK_DATETIME' => $this->datetime,
@@ -101,7 +107,7 @@ public function testGetPaymentRequestService1012(){
$this->assertEquals($this->expectedData, $request->getRequestData());
// Production env url
- $this->assertEquals('https://www.seb.ee/cgi-bin/unet3.sh/un3min.r', $request->getRequestUrl());
+ $this->assertEquals($this->requestUrl, $request->getRequestUrl());
}
/**
@@ -117,12 +123,12 @@ public function testGetPaymentRequestService1011(){
__DIR__.'/keys/iPizza/private_key.pem',
'',
__DIR__.'/keys/iPizza/public_key.pem',
- $this->requestUrl,
+ $this->customRequestUrl,
$this->sellerName,
$this->sellerAccount
);
- $this->seb = new Banklink\SEB($this->protocol, true);
+ $this->seb = new $this->bankClass($this->protocol, true);
// New expected values
$this->expectedData['VK_SERVICE'] = '1011';
@@ -138,7 +144,7 @@ public function testGetPaymentRequestService1011(){
$this->assertEquals($this->expectedData, $request->getRequestData());
// Test env url
- $this->assertEquals('http://localhost:8080/banklink/seb-common', $request->getRequestUrl());
+ $this->assertEquals($this->testRequestUrl, $request->getRequestUrl());
// Get HTML
$this->assertContains('getRequestInputs());
@@ -205,13 +211,84 @@ public function testHandlePaymentResponseError(){
$this->assertFalse($response->wasSuccessful());
}
+ /**
+ * Test authentication request data
+ * Test service 4011
+ */
+
+ public function testGetAuthRequest4011(){
+
+ $expectedData = array(
+ 'VK_SERVICE' => '4011',
+ 'VK_VERSION' => '008',
+ 'VK_SND_ID' => 'id2000',
+ 'VK_RETURN' => 'http://example.com',
+ 'VK_DATETIME' => '2015-09-29T15:00:00+0300',
+ 'VK_RID' => '',
+ 'VK_LANG' => 'EST',
+ 'VK_REPLY' => '3012',
+ 'VK_ENCODING' => 'UTF-8',
+ 'VK_MAC' => 'tCzsgSP0NVlNDvzsPnDZpwfPDwlrWoLFOUDSJ80sYDMbPsXBiid0M8xKT9ep0KVmj8BBUwWOGGjENSkaNXcZKAoqw0h1V1J7Hxuy1/gnIgkAkiY1OQftMYNuyrmKj1xVP4JGH3kp4ZEiyXJ0ySj/VGW4P1Vyv2oMUVHN+vDqHR0=',
+ );
+
+ $request = $this->seb->getAuthRequest();
+
+ $this->assertInstanceOf('RKD\Banklink\Request\AuthRequest', $request);
+ $this->assertEquals($expectedData, $request->getRequestData());
+
+ // Test env url
+ $this->assertEquals($this->requestUrl, $request->getRequestUrl());
+
+ // Get HTML
+ $this->assertContains('getRequestInputs());
+ }
+
+ /**
+ * Test authentication request data
+ * Test service 4012
+ */
+
+ public function testGetAuthRequest4012(){
+
+ $expectedData = array(
+ 'VK_SERVICE' => '4012',
+ 'VK_VERSION' => '008',
+ 'VK_SND_ID' => 'id2000',
+ 'VK_REC_ID' => 'bank-id',
+ 'VK_NONCE' => 'random-nonce',
+ 'VK_RETURN' => 'http://example.com',
+ 'VK_DATETIME' => $this->datetime,
+ 'VK_RID' => 'random-rid',
+ 'VK_LANG' => 'EST',
+ 'VK_ENCODING' => 'UTF-8',
+ 'VK_MAC' => 'MtmH+8VgmKhw/Q6kO4EZdgNMP9ZWhCXfO0OHUgyHd74ofhdkvhLnzSWxqHZgWv9lCo3ZSrZ1mHJEf1rezBod7QQDcPmMVHl9iijJug2oySgT27Re89oytVN3Zlzmko9LFEaE8JIYnvxN4B9mc/bWfW0hvHSyBehpWdlVO5HIO+c=',
+ );
+
+ $request = $this->seb->getAuthRequest('bank-id', 'random-nonce', 'random-rid');
+
+ $this->assertInstanceOf('RKD\Banklink\Request\AuthRequest', $request);
+ $this->assertEquals($expectedData, $request->getRequestData());
+
+ // Test env url
+ $this->assertEquals($this->requestUrl, $request->getRequestUrl());
+
+ // Get HTML
+ $this->assertContains('getRequestInputs());
+
+ // Get same data again, already exists
+ $request = $this->seb->getAuthRequest('bank-id', 'random-nonce', 'random-rid');
+
+ $this->assertInstanceOf('RKD\Banklink\Request\AuthRequest', $request);
+ $this->assertEquals($expectedData, $request->getRequestData());
+ }
+
/**
* Test custom request url
*/
public function testCustomRequestUrl(){
- $this->seb = new Banklink\SEB($this->protocol, false, 'http://google.com');
+ $this->seb = new $this->bankClass($this->protocol, false, 'http://google.com');
$request = $this->seb->getPaymentRequest($this->orderId, $this->amount, $this->message, $this->language, $this->currency, $this->timezone);
diff --git a/tests/SwedbankTest.php b/tests/SwedbankTest.php
index 639d0a4..cb6e884 100644
--- a/tests/SwedbankTest.php
+++ b/tests/SwedbankTest.php
@@ -1,11 +1,7 @@
*/
-class SwedbankTest extends \PHPUnit_Framework_TestCase{
+class SwedbankTest extends SEBTest{
- private $protocol;
- private $swedbank;
+ protected $bankClass = "RKD\Banklink\Swedbank";
- private $sellerId;
- private $sellerName;
- private $sellerAccount;
-
- private $senderName;
-
- private $orderId;
- private $amount;
- private $message;
- private $language;
- private $currency;
- private $timezone;
- private $datetime;
- private $expectedData;
-
- private $requestUrl;
-
- /**
- * Set test data
- */
-
- public function setUp(){
-
- $this->sellerId = 'id2000';
- $this->sellerName = 'Ülo Pääsuke';
- $this->sellerAccount = '1010342342354345435';
-
- $this->senderName = 'Toomas Jäär';
-
- $this->orderId = 100;
- $this->amount = 10.00;
- $this->message = 'First payment';
- $this->language = 'EST';
- $this->currency = 'EUR';
- $this->timezone = 'Europe/Tallinn';
-
- // From ENV variable
- $this->datetime = getenv('TEST_DATETIME');
-
- $this->requestUrl = 'http://example.com';
-
- $this->protocol = new iPizza(
- $this->sellerId,
- __DIR__.'/keys/iPizza/private_key.pem',
- '',
- __DIR__.'/keys/iPizza/public_key.pem',
- $this->requestUrl,
- '',
- '',
- true
- );
-
- $this->swedbank = new Banklink\Swedbank($this->protocol);
-
- $this->expectedData = array(
- 'VK_SERVICE' => '1012',
- 'VK_VERSION' => '008',
- 'VK_SND_ID' => $this->sellerId,
- 'VK_STAMP' => $this->orderId,
- 'VK_AMOUNT' => $this->amount,
- 'VK_CURR' => $this->currency,
- 'VK_REF' => ProtocolHelper::calculateReference($this->orderId),
- 'VK_MSG' => $this->message,
- 'VK_RETURN' => $this->requestUrl,
- 'VK_CANCEL' => $this->requestUrl,
- 'VK_LANG' => $this->language,
- 'VK_MAC' => 'PmAB256IR1FzTKZHNn5LBPso/KyLAhNcTOMq82lhpYn0mXKYtVtpNkolQxyETnTcIn1TcYOmekJEATe86Bz2MRljEQqllkaIl7bNuLCtuBPtAOYWNLmQHoop+5QSiguJEmEV+JJU3w4BApjWcsHA5HYlYze+3L09UO6na0lB/Zs=',
- 'VK_DATETIME' => $this->datetime,
- 'VK_ENCODING' => 'UTF-8'
- );
- }
-
- /**
- * Test for correctly generated request data for service 1012
- */
-
- public function testGetPaymentRequestService1012(){
-
- // Test service 1012
- $request = $this->swedbank->getPaymentRequest($this->orderId, $this->amount, $this->message, $this->language, $this->currency, $this->timezone);
-
- // Instance of PaymentRequest and data is same
- $this->assertInstanceOf('RKD\Banklink\Request\PaymentRequest', $request);
- $this->assertEquals($this->expectedData, $request->getRequestData());
-
- // Production env url
- $this->assertEquals('https://www.swedbank.ee/banklink', $request->getRequestUrl());
- }
-
- /**
- * Test for correctly generated request data for service 1011
- * Test debug url
- */
-
- public function testGetPaymentRequestService1011(){
-
- // Test service 1011
- $this->protocol = new iPizza(
- $this->sellerId,
- __DIR__.'/keys/iPizza/private_key.pem',
- '',
- __DIR__.'/keys/iPizza/public_key.pem',
- $this->requestUrl,
- $this->sellerName,
- $this->sellerAccount
- );
-
- $this->swedbank = new Banklink\Swedbank($this->protocol, true);
-
- // New expected values
- $this->expectedData['VK_SERVICE'] = '1011';
- $this->expectedData['VK_ACC'] = $this->sellerAccount;
- $this->expectedData['VK_NAME'] = $this->sellerName;
- $this->expectedData['VK_MAC'] = 'PuJTjADqHeArALfzTo2ZsynckTOVRFZMnOnbv9tv30KrF2a9m/yJuRn9vcd3JuaSjgzKoS7DRSouDgXAe6GNLZnduhXZrYx5JtVMmnlgooQ+/pJqO6ZOzwsEjaXooTLCCnKA5P9zWoxXpe8Al4IC9pj7jLNFG3dCeG9XO5uRZEs=';
- $this->expectedData['VK_DATETIME'] = $this->datetime;
-
- $request = $this->swedbank->getPaymentRequest($this->orderId, $this->amount, $this->message, $this->language, $this->currency, $this->timezone);
-
- // Instance of PaymentRequest and data is same
- $this->assertInstanceOf('RKD\Banklink\Request\PaymentRequest', $request);
- $this->assertEquals($this->expectedData, $request->getRequestData());
-
- // Test env url
- $this->assertEquals('http://localhost:8080/banklink/swedbank-common', $request->getRequestUrl());
-
- // Get HTML
- $this->assertContains('getRequestInputs());
-
- }
-
- /**
- * Test successful payment response
- */
-
- public function testHandlePaymentResponseSuccess(){
- $responseData = array(
- 'VK_SERVICE' => '1111',
- 'VK_VERSION' => '008',
- 'VK_SND_ID' => $this->senderName,
- 'VK_REC_ID' => $this->sellerId,
- 'VK_STAMP' => $this->orderId,
- 'VK_T_NO' => 100,
- 'VK_AMOUNT' => $this->amount,
- 'VK_CURR' => $this->currency,
- 'VK_REC_ACC' => $this->sellerAccount,
- 'VK_REC_NAME' => $this->sellerName,
- 'VK_SND_ACC' => '101032423434543',
- 'VK_SND_NAME' => 'Mart Mets',
- 'VK_REF' => $this->orderId,
- 'VK_MSG' => $this->message,
- 'VK_MAC' => 'Sp0VzYSPyZviiCewmwbtqny8cYRcnYU4Noh0cwxOYoZ5IpQwHuolNbFI+1Kkuk5n6cWs2X48IYYOUMRi9VTqdsfSN7z5jpUwEwjLsCMDUDdro421Je7eXXkEkbZlEcgY8wtR5H+OO955aqxDdZeS0dkuuxTN70Z9Esv5feXYxsw=',
- 'VK_T_DATETIME' => $this->datetime,
- 'VK_ENCODING' => 'UTF-8'
- );
-
- $response = $this->swedbank->handleResponse($responseData);
-
- $this->assertInstanceOf('RKD\Banklink\Response\PaymentResponse', $response);
- $this->assertEquals(PaymentResponse::STATUS_SUCCESS, $response->getStatus());
-
- // This is valid response
- $this->assertTrue($response->wasSuccessful());
- }
-
- /**
- * Test failed payment response
- */
-
- public function testHandlePaymentResponseError(){
- $responseData = array(
- 'VK_SERVICE' => '1911',
- 'VK_VERSION' => '008',
- 'VK_SND_ID' => $this->senderName,
- 'VK_REC_ID' => $this->sellerId,
- 'VK_STAMP' => $this->orderId,
- 'VK_REF' => $this->orderId,
- 'VK_MSG' => $this->message,
- 'VK_MAC' => 'o4rju0oEwITuIheUdtDjp2njKhBzvQv8RjKg+rdCB+fwGiUS8zpXzr0I+wj0vl13h+ACGAR1LO9gR2+IG1yq+AJdQdVszJIbeA1jcg1GFtl1xyLN8LXYfubHHUB/7EWwiEGZKcHrNp3pAsADlLwySQLRWatheMLPqRRk2FX96Ko=',
- 'VK_DATETIME' => $this->datetime,
- );
-
- $response = $this->swedbank->handleResponse($responseData);
-
- $this->assertInstanceOf('RKD\Banklink\Response\PaymentResponse', $response);
- $this->assertEquals(PaymentResponse::STATUS_ERROR, $response->getStatus());
-
- // This is not valid response, so validation should fail
- $this->assertFalse($response->wasSuccessful());
- }
+ protected $requestUrl = "https://www.swedbank.ee/banklink";
+ protected $testRequestUrl = "http://localhost:8080/banklink/swedbank-common";
}