Skip to content

Commit

Permalink
Add missing tests, fix bugs and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
renekorss committed Oct 12, 2015
1 parent cbff608 commit 5ca5da7
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 224 deletions.
88 changes: 81 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
require __DIR__ . '/vendor/autoload.php';

use RKD\Banklink;

// Init protocol
$protocol = new Banklink\Protocol\iPizza(
'uid100010', // seller ID (VK_SND_ID)
__DIR__ . '/../keys/seb_user_key.pem', // private key
'', // private key password, leave empty, if not needed
__DIR__ . '/../keys/seb_bank_cert.pem', // public key
'http://localhost/banklink/SEB.php' // return url
);

// Init banklink
// set second argument to true, if in debug mode
$seb = new Banklink\SEB($protocol);

// Set payment data and get payment request object
$request = $seb->getPaymentRequest(123453, 150, 'Test makse', 'EST');
?>

<form method="POST" action="<?php echo $request->getRequestUrl(); ?>">
<?php echo $request->getRequestInputs(); ?>
<input type="submit" value="Pay with SEB!" />
</form>

````

### Authentication

````php
<?php
require __DIR__ . '/vendor/autoload.php';

use RKD\Banklink;

// Init protocol
$protocol = new Banklink\Protocol\iPizza(
'uid100010', // seller ID (SND ID)
__DIR__ . '/../keys/seb_user_key.pem', // private key
'', // private key password, leave empty, if not needed
__DIR__ . '/../keys/seb_bank_cert.pem', // public key
'http://localhost/banklink/SEB.php' // return url
);

// Init banklink
// set second argument to true, if in debug mode
$seb = new Banklink\SEB($protocol);

// Get auth request object
$request = $seb->getAuthRequest();
?>

<form method="POST" action="<?php echo $request->getRequestUrl(); ?>">
<?php echo $request->getRequestInputs(); ?>
<input type="submit" value="Authenticate with SEB!" />
</form>

````

## Tasks

Expand All @@ -26,7 +104,3 @@ You can test your banklink with <a href="http://pangalink.net/" target="_blank">
## License

Licensed under [MIT](LICENSE)

## Credits

This library is based on outdated [Inoryy/Banklink](https://github.com/Inoryy/Banklink).
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "renekorss/Banklink",
"name": "renekorss/banklink",
"description": "PHP banklink library to easily integrate Baltic banklinks.",
"license": "MIT",
"authors": [
Expand All @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion src/Danskebank.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
4 changes: 2 additions & 2 deletions src/LHV.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(iPizza $protocol, $debug = false, $requestUrl = null
*/

protected function getEncodingField(){
return 'VK_CHARSET';
return 'VK_ENCODING';
}

/**
Expand All @@ -64,7 +64,7 @@ protected function getEncodingField(){
*/
protected function getAdditionalFields(){
return array(
'VK_CHARSET' => $this->requestEncoding
'VK_ENCODING' => $this->requestEncoding
);
}
}
5 changes: 4 additions & 1 deletion src/Nordea.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <rene.korss@gmail.com>
*/

// @codeCoverageIgnoreStart
class Nordea extends Banklink{

/**
Expand Down Expand Up @@ -50,3 +52,4 @@ public function __construct(Solo $protocol, $debug = false, $requestUrl = null){
parent::__construct($protocol, $debug, $requestUrl);
}
}
// @codeCoverageIgnoreEnd
2 changes: 1 addition & 1 deletion src/Protocol/iPizza.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function handleResponse(array $response, $encoding = 'UTF-8'){
if(in_array($service, Services::getAuthenticationResponseServices())){
return $this->handleAuthResponse($response, $success);
}
}
} // @codeCoverageIgnore


/**
Expand Down
19 changes: 19 additions & 0 deletions tests/DanskebankTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace RKD\Banklink;

include_once 'SEBTest.php';

/**
* Test suite for Danskebank banklink
*
* @author Rene Korss <rene.korss@gmail.com>
*/

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";

}
19 changes: 19 additions & 0 deletions tests/KrediidipankTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace RKD\Banklink;

include_once 'SEBTest.php';

/**
* Test suite for Krediidipank banklink
*
* @author Rene Korss <rene.korss@gmail.com>
*/

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";

}
19 changes: 19 additions & 0 deletions tests/LHVTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace RKD\Banklink;

include_once 'SEBTest.php';

/**
* Test suite for LHV banklink
*
* @author Rene Korss <rene.korss@gmail.com>
*/

class LHVTest extends SEBTest{

protected $bankClass = "RKD\Banklink\LHV";

protected $requestUrl = "https://www.lhv.ee/banklink";
protected $testRequestUrl = "http://localhost:8080/banklink/lhv-common";

}
5 changes: 3 additions & 2 deletions tests/Protocol/iPizzaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down
Loading

0 comments on commit 5ca5da7

Please sign in to comment.