Cleanup, added docs & RC 2
This commit is contained in:
parent
21e67b0298
commit
3ee95398c4
@ -25,11 +25,19 @@ class Application
|
||||
self::$container = $app->getContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dependency injection container
|
||||
* @return Slim\Container
|
||||
*/
|
||||
public static function getContainer()
|
||||
{
|
||||
return self::$container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Slim application object
|
||||
* @return Slim\App;
|
||||
*/
|
||||
public static function getApplication()
|
||||
{
|
||||
return self::$app;
|
||||
|
@ -35,13 +35,12 @@ class Handler
|
||||
* - amount
|
||||
* - description
|
||||
* - returnUrl
|
||||
* - sha1
|
||||
* - hash
|
||||
*/
|
||||
$this->post('/transactionRequest', function ($request, $response, $args) {
|
||||
$parsedBody = $request->getParsedBody();
|
||||
|
||||
if (isset($parsedBody['clientId']) && isset($parsedBody['transactionId']) && isset($parsedBody['amount']) && isset($parsedBody['description']) && isset($parsedBody['returnUrl']) && isset($parsedBody['hash'])) {
|
||||
// Correct request
|
||||
try {
|
||||
$client = new Client($parsedBody['clientId']);
|
||||
$clientSecret = $client->getClientSecret();
|
||||
@ -112,13 +111,12 @@ class Handler
|
||||
* Requires the following POST arguments:
|
||||
* - clientId
|
||||
* - transactionId
|
||||
* - sha1
|
||||
* - hash
|
||||
*/
|
||||
$this->post('/statusRequest', function ($request, $response, $args) {
|
||||
$parsedBody = $request->getParsedBody();
|
||||
|
||||
if (isset($parsedBody['clientId']) && isset($parsedBody['transactionId']) && isset($parsedBody['hash'])) {
|
||||
// Correct request
|
||||
try {
|
||||
$client = new Client($parsedBody['clientId']);
|
||||
$clientSecret = $client->getClientSecret();
|
||||
|
@ -18,6 +18,12 @@ use Inforbank\Application;
|
||||
|
||||
class Authorization
|
||||
{
|
||||
/**
|
||||
* Login user
|
||||
* @param $rekeningnr
|
||||
* @param $passcode
|
||||
* @return boolean
|
||||
*/
|
||||
public function login($rekeningnr, $passcode)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
@ -42,16 +48,27 @@ class Authorization
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current user id
|
||||
* @return any
|
||||
*/
|
||||
public function getUserID()
|
||||
{
|
||||
return $_SESSION['userid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the current user is authenticated
|
||||
* @return boolean
|
||||
*/
|
||||
public function isUserAuthenticated()
|
||||
{
|
||||
return $this->getUserID() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user session data
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
unset($_SESSION['userid']);
|
||||
|
@ -19,6 +19,9 @@ use Inforbank\Application\Helper\Redirect;
|
||||
|
||||
class Middleware
|
||||
{
|
||||
/**
|
||||
* Middleware (https://www.slimframework.com/docs/concepts/middleware.html) om te checken of de gebruiker is ingelogd
|
||||
*/
|
||||
public function __invoke($request, $response, $next)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
|
@ -18,6 +18,10 @@ use Inforbank\Application;
|
||||
|
||||
class Berichten
|
||||
{
|
||||
/**
|
||||
* Get all messages for a user
|
||||
* @return array
|
||||
*/
|
||||
public static function getUserBerichten()
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
@ -46,6 +50,12 @@ class Berichten
|
||||
return $berichtArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send new message
|
||||
* @param int $user Klantid
|
||||
* @param string $afzender String name of the sender
|
||||
* @param string $bericht Message
|
||||
*/
|
||||
public static function newBericht($user, $afzender, $bericht)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
|
@ -16,7 +16,7 @@ namespace Inforbank\Application\Helper;
|
||||
|
||||
class IBAN
|
||||
{
|
||||
private function wordToNumbers($word)
|
||||
private static function wordToNumbers($word)
|
||||
{
|
||||
$newword = "";
|
||||
$wordarray = str_split($word);
|
||||
@ -30,7 +30,7 @@ class IBAN
|
||||
return $newword;
|
||||
}
|
||||
|
||||
private function getCheckDigits($bignum)
|
||||
private static function getCheckDigits($bignum)
|
||||
{
|
||||
//Modulo staartdeling
|
||||
$modulo97 = (int)substr($bignum, 0, 6);
|
||||
@ -48,7 +48,7 @@ class IBAN
|
||||
return $checkdigits;
|
||||
}
|
||||
|
||||
public function isValidIBAN($iban)
|
||||
public static function isValidIBAN($iban)
|
||||
{
|
||||
$iban = str_replace(" ", "", $iban);
|
||||
$landcode = substr($iban, 0, 2);
|
||||
@ -56,38 +56,38 @@ class IBAN
|
||||
$identificatie = substr($iban, 4);
|
||||
$identificatie .= $landcode;
|
||||
$identificatie .= "00";
|
||||
$nummer = $this->wordToNumbers($identificatie);
|
||||
return $controle == $this->getCheckDigits($nummer);
|
||||
$nummer = self::wordToNumbers($identificatie);
|
||||
return $controle == self::getCheckDigits($nummer);
|
||||
}
|
||||
|
||||
public function getRekeningNummer($iban)
|
||||
public static function getRekeningNummer($iban)
|
||||
{
|
||||
return substr(str_replace(" ", "", $iban), 8);
|
||||
}
|
||||
|
||||
public function getBank($iban)
|
||||
public static function getBank($iban)
|
||||
{
|
||||
return substr(str_replace(" ", "", $iban), 4, 4);
|
||||
}
|
||||
|
||||
public function getLand($iban)
|
||||
public static function getLand($iban)
|
||||
{
|
||||
return substr(str_replace(" ", "", $iban), 0, 2);
|
||||
}
|
||||
|
||||
public function getIBAN($rekeningnr)
|
||||
public static function getIBAN($rekeningnr)
|
||||
{
|
||||
$landcode = "NL"; // NL in vertaling
|
||||
$landnumber = $this->wordToNumbers($landcode);
|
||||
$landnumber = self::wordToNumbers($landcode);
|
||||
|
||||
|
||||
$bankcode = "INFO";
|
||||
$banknumber = $this->wordToNumbers($bankcode);
|
||||
$banknumber = self::wordToNumbers($bankcode);
|
||||
|
||||
$rekeningnr = str_pad($rekeningnr, 10, 0, STR_PAD_LEFT);
|
||||
|
||||
$bignum = $banknumber . $rekeningnr . $landnumber . "00";
|
||||
$checkdigits = $this->getCheckDigits($bignum);
|
||||
$checkdigits = self::getCheckDigits($bignum);
|
||||
|
||||
$rekeningnrarr = str_split($rekeningnr, 4);
|
||||
return $landcode.$checkdigits." ".$bankcode." ".$rekeningnrarr[0]." ".$rekeningnrarr[1]." ".$rekeningnrarr[2];
|
||||
|
@ -16,6 +16,9 @@ namespace Inforbank\Application\Helper\Idob;
|
||||
|
||||
use Inforbank\Application;
|
||||
|
||||
/**
|
||||
* Used for client authentication in IDOB
|
||||
*/
|
||||
class Client
|
||||
{
|
||||
private $client;
|
||||
|
@ -18,6 +18,14 @@ use Inforbank\Application;
|
||||
|
||||
class Transactie
|
||||
{
|
||||
/**
|
||||
* Create IDOB transaction
|
||||
* @param string $reference Reference passed by the client (webshop)
|
||||
* @param string $clientId Client identifier
|
||||
* @param double $amount Transaction amount
|
||||
* @param string $description Description for the user
|
||||
* @return int Transaction identifier
|
||||
*/
|
||||
public static function createTransactie($reference, $clientId, $amount, $description)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
@ -33,6 +41,11 @@ class Transactie
|
||||
return $trans['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get IDOB transaction data
|
||||
* @param int $id Transaction identifier
|
||||
* @return array
|
||||
*/
|
||||
public static function getTransactie($id)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
@ -54,6 +67,11 @@ class Transactie
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the IDOB transaction status
|
||||
* @param int $id Transaction identifier
|
||||
* @param int $status Status: 1 for pending, 2 for paid, 3 for unknown
|
||||
*/
|
||||
public static function setTransactionStatus($id, $status)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
|
@ -18,6 +18,10 @@ use Inforbank\Application;
|
||||
|
||||
class Klant
|
||||
{
|
||||
/**
|
||||
* Get current user data
|
||||
* @return array
|
||||
*/
|
||||
public static function getCurrentUser()
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
|
@ -101,7 +101,7 @@ class Overboekingen
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Maak een nieuwe overboeking aan
|
||||
* @param IBAN $van De rekening waar het bedrag vanaf wordt gehaald
|
||||
* @param IBAN $naar De rekening waar het bedrag bijkomt
|
||||
* @param double $bedrag Het bedrag
|
||||
@ -115,15 +115,15 @@ class Overboekingen
|
||||
//error: rekening is niet van klant
|
||||
Overboekingen::error(Overboekingen::$EIGENAAR);
|
||||
}
|
||||
$ibanHelper = new IBAN();
|
||||
if (!$ibanHelper->isValidIBAN($naar)) {
|
||||
|
||||
if (!IBAN::isValidIBAN($naar)) {
|
||||
//error: ongeldige iban
|
||||
throw new Exception("De IBAN van de ontvanger is ongeldig.", Overboekingen::$IBAN);
|
||||
} elseif (!($ibanHelper->getLand($naar) == "NL" && $ibanHelper->getBank($naar) === "INFO")) {
|
||||
} elseif (!(IBAN::getLand($naar) == "NL" && IBAN::getBank($naar) === "INFO")) {
|
||||
//error: andere bank
|
||||
Overboekingen::error(Overboekingen::$BANK);
|
||||
}
|
||||
$naarRekeningnr = $ibanHelper->getRekeningNummer($naar);
|
||||
$naarRekeningnr = IBAN::getRekeningNummer($naar);
|
||||
|
||||
//Controleer of de rekening bestaat
|
||||
$db = Application::getContainer()->db;
|
||||
@ -180,7 +180,7 @@ class Overboekingen
|
||||
]);
|
||||
//Stuur bericht bij laag saldo
|
||||
if ($vanRekening['saldo'] - $bedragvalue < 20) {
|
||||
Berichten::newBericht(Application::getContainer()->auth->getUserID(), "Bank", "U heeft een laag saldo op uw rekening: " . $ibanHelper->getIBAN($vanRekening['nr']) . ".<br/>Uw huidige saldo is " . money_format('%(#1n', $vanRekening['saldo'] - $bedragvalue) . ".");
|
||||
Berichten::newBericht(Application::getContainer()->auth->getUserID(), "Bank", "U heeft een laag saldo op uw rekening: " . IBAN::getIBAN($vanRekening['nr']) . ".<br/>Uw huidige saldo is " . money_format('%(#1n', $vanRekening['saldo'] - $bedragvalue) . ".");
|
||||
}
|
||||
//In de database worden de getallen met 10 cijfers voor de komma opgeslagen
|
||||
//Als het saldo te hoog wordt heb je een probleem
|
||||
|
@ -16,6 +16,13 @@ namespace Inforbank\Application\Helper;
|
||||
|
||||
class Redirect
|
||||
{
|
||||
/**
|
||||
* Create a new redirect to the given path
|
||||
* @param Request $request
|
||||
* @param Response $response
|
||||
* @param string $path
|
||||
* @return Response object
|
||||
*/
|
||||
public static function create($request, $response, $path)
|
||||
{
|
||||
$basePath = $request->getUri()->getBaseUrl();
|
||||
|
@ -21,13 +21,16 @@ class Rekeningen
|
||||
public static $BETAALREKENING = 1;
|
||||
public static $SPAARREKENING = 2;
|
||||
|
||||
/**
|
||||
* Return the current user bank accounts
|
||||
* @return array
|
||||
*/
|
||||
public static function getCurrentUserRekeningen()
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
$user = $container->auth->getUserID();
|
||||
|
||||
$db = $container->db;
|
||||
$ibanhelper = new IBAN;
|
||||
|
||||
$rekeningen = $db->rekeningen->where('klantid', $user);
|
||||
|
||||
@ -37,7 +40,7 @@ class Rekeningen
|
||||
$type = $db->types->where('id', $rekening['typeid'])[$rekening['typeid']];
|
||||
|
||||
$returnArray[] = array(
|
||||
"iban" => $ibanhelper->getIBAN($rekening['rekeningnr']),
|
||||
"iban" => IBAN::getIBAN($rekening['rekeningnr']),
|
||||
"nr" => $rekening['rekeningnr'],
|
||||
"saldo" => (double) $rekening['saldo'],
|
||||
"naam" => $type['rekeningnaam'],
|
||||
@ -48,6 +51,11 @@ class Rekeningen
|
||||
return $returnArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current user is the owner of this bank account
|
||||
* @param string $iban
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isEigenRekeningIBAN($iban)
|
||||
{
|
||||
$rekeningen = Rekeningen::getCurrentUserRekeningen();
|
||||
@ -62,6 +70,11 @@ class Rekeningen
|
||||
return $vanRekening;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current user is the owner of this bank account
|
||||
* @param string $nr Internal bank account number
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isEigenRekeningnr($nr)
|
||||
{
|
||||
$rekeningen = Rekeningen::getCurrentUserRekeningen();
|
||||
|
@ -5,10 +5,12 @@ namespace Inforbank\Application\Helper;
|
||||
use Exception;
|
||||
use Inforbank\Application;
|
||||
|
||||
class Statistieken {
|
||||
class Statistieken
|
||||
{
|
||||
public static $EIGENAAR = 1;
|
||||
|
||||
public static function getSaldoverloop($dagen, $rekeningNummer){
|
||||
public static function getSaldoverloop($dagen, $rekeningNummer)
|
||||
{
|
||||
if (!Rekeningen::isEigenRekeningnr($rekeningNummer)) {
|
||||
throw new Exception("Dit is niet uw eigen rekening", Statistieken::$EIGENAAR);
|
||||
}
|
||||
|
@ -75,10 +75,9 @@ class Idob
|
||||
/**
|
||||
* All set to pay!
|
||||
*/
|
||||
$ibanhelper = new IBAN();
|
||||
|
||||
// Do overboeking
|
||||
Overboekingen::createOverboeking($ibanhelper->getIBAN($van), $ibanhelper->getIBAN($rekening), $transactie['amount'], "Betaling aan " . $naam . " voor transactie " . $transactie['reference'], "id");
|
||||
Overboekingen::createOverboeking(IBAN::getIBAN($van), IBAN::getIBAN($rekening), $transactie['amount'], "Betaling aan " . $naam . " voor transactie " . $transactie['reference'], "id");
|
||||
|
||||
// Do Status update
|
||||
Transactie::setTransactionStatus($transactie['transactieId'], 2);
|
||||
|
@ -44,8 +44,7 @@ class Overboeking
|
||||
$omschrijving = $post['omschrijving'];
|
||||
|
||||
try {
|
||||
$ibanhelper = new IBAN();
|
||||
Overboekingen::createOverboeking($ibanhelper->getIBAN($van), $naar, $bedrag, $omschrijving, "bg");
|
||||
Overboekingen::createOverboeking(IBAN::getIBAN($van), $naar, $bedrag, $omschrijving, "bg");
|
||||
return Redirect::create($request, $response, "/rekeningen/$van?geslaagd=1");
|
||||
} catch (Exception $e) {
|
||||
return Redirect::create($request, $response, "/overboeking?error=" . $e->getCode() . "");
|
||||
|
@ -26,8 +26,6 @@ class Transacties
|
||||
{
|
||||
$app->get('/rekeningen/{rekeningnummer}', function ($request, $response, $args) {
|
||||
$rekeningen = Rekeningen::getCurrentUserRekeningen();
|
||||
|
||||
$ibanhelper = new IBAN;
|
||||
$rekening = $rekening = Rekeningen::isEigenRekeningnr($args['rekeningnummer']);
|
||||
$rekeningnr = $args['rekeningnummer'];
|
||||
if (!$rekening) {
|
||||
@ -45,8 +43,8 @@ class Transacties
|
||||
|
||||
foreach ($transacties as $transactie) {
|
||||
$returnArray[] = array(
|
||||
"van" => $ibanhelper->getIBAN($transactie['van']),
|
||||
"naar" => $ibanhelper->getIBAN($transactie['naar']),
|
||||
"van" => IBAN::getIBAN($transactie['van']),
|
||||
"naar" => IBAN::getIBAN($transactie['naar']),
|
||||
"bedrag" => $transactie['bedrag'],
|
||||
"type" => $transactie['type'],
|
||||
"omschrijving" => $transactie['omschrijving'],
|
||||
|
@ -14,6 +14,9 @@
|
||||
|
||||
namespace Inforbank;
|
||||
|
||||
/**
|
||||
* Proxy class om de limitaties van de sgni.nl webserver te omzeilen. Het is mogelijk om de site te bezoeken via zowel /login als /index.php/login op een goed geconfigureerde webserver, maar als de /index.php/login url wordt gebruikt is de onderstaande static file proxy nodig.
|
||||
*/
|
||||
class Proxy
|
||||
{
|
||||
public static $route;
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
return [
|
||||
'settings' => [
|
||||
'displayErrorDetails' => true, // set to false in production
|
||||
'addContentLengthHeader' => false, // Allow the web server to send the content-length header
|
||||
'displayErrorDetails' => true,
|
||||
'addContentLengthHeader' => false,
|
||||
|
||||
// Renderer settings
|
||||
'renderer' => [
|
||||
|
Reference in New Issue
Block a user