Finalized IDOB + small changes concerning redirects
parent
d982b97455
commit
fe9d31a076
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Informatica Eindproject D4p
|
||||
* 6in3, Stedelijk Gymnasium Nijmegen
|
||||
* Docent: Hans de Wolf
|
||||
*
|
||||
* ==================
|
||||
*
|
||||
* Daniel Boutros,
|
||||
* Christiaan Goossens,
|
||||
* Jelmer Hinssen
|
||||
*/
|
||||
|
||||
namespace Inforbank\Application\Helper\Idob;
|
||||
|
||||
use Inforbank\Application;
|
||||
|
||||
class Client
|
||||
{
|
||||
private $client;
|
||||
|
||||
public function __construct($id)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
$db = $container->db;
|
||||
|
||||
$this->client = $db->idobc->where("clientId", $id)->limit(1)->fetch();
|
||||
|
||||
if (!$this->client) {
|
||||
throw new \Exception("There is no client with this id");
|
||||
}
|
||||
}
|
||||
|
||||
public function getClientSecret()
|
||||
{
|
||||
return $this->client['clientSecret'];
|
||||
}
|
||||
|
||||
public function getClientRedirectURI()
|
||||
{
|
||||
return $this->client['redirectUri'];
|
||||
}
|
||||
|
||||
public function getClientName()
|
||||
{
|
||||
return $this->client['naam'];
|
||||
}
|
||||
|
||||
public function getClientRekening()
|
||||
{
|
||||
return $this->client['rekeningnr'];
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Informatica Eindproject D4p
|
||||
* 6in3, Stedelijk Gymnasium Nijmegen
|
||||
* Docent: Hans de Wolf
|
||||
*
|
||||
* ==================
|
||||
*
|
||||
* Daniel Boutros,
|
||||
* Christiaan Goossens,
|
||||
* Jelmer Hinssen
|
||||
*/
|
||||
|
||||
namespace Inforbank\Application\Helper\Idob;
|
||||
|
||||
use Inforbank\Application;
|
||||
|
||||
class Transactie
|
||||
{
|
||||
public static function createTransactie($reference, $clientId, $amount, $description)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
$db = $container->db;
|
||||
|
||||
$trans = $db->idobt->insert([
|
||||
"reference" => $reference,
|
||||
"clientId" => $clientId,
|
||||
"amount" => $amount,
|
||||
"description" => $description,
|
||||
"status" => 1
|
||||
]);
|
||||
return $trans['id'];
|
||||
}
|
||||
|
||||
public static function getTransactie($id)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
$db = $container->db;
|
||||
|
||||
$transactie = $db->idobt->where("transactieId", $id)->limit(1)->fetch();
|
||||
|
||||
if (!$transactie) {
|
||||
throw new \Exception("Transaction not found");
|
||||
}
|
||||
|
||||
return array(
|
||||
"transactieId" => $transactie['transactieId'],
|
||||
"reference" => $transactie['reference'],
|
||||
"clientId" => $transactie['clientId'],
|
||||
"amount" => (double) $transactie['amount'],
|
||||
"description" => $transactie['description'],
|
||||
"status" => (int) $transactie['status']
|
||||
);
|
||||
}
|
||||
|
||||
public static function setTransactionStatus($id, $status)
|
||||
{
|
||||
$container = Application::getContainer();
|
||||
$db = $container->db;
|
||||
|
||||
$transactie = $db->idobt->where("transactieId", $id)->limit(1);
|
||||
if (!$transactie) {
|
||||
throw new \Exception("Transaction not found");
|
||||
}
|
||||
|
||||
$transactie->update(array(
|
||||
"status" => $status
|
||||
));
|
||||
|
||||
if (!$transactie) {
|
||||
throw new \Exception("Failed to update status");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Informatica Eindproject D4p
|
||||
* 6in3, Stedelijk Gymnasium Nijmegen
|
||||
* Docent: Hans de Wolf
|
||||
*
|
||||
* ==================
|
||||
*
|
||||
* Daniel Boutros,
|
||||
* Christiaan Goossens,
|
||||
* Jelmer Hinssen
|
||||
*/
|
||||
|
||||
namespace Inforbank\Application;
|
||||
|
||||
use \Slim\App;
|
||||
use Inforbank\Application\Auth\Middleware;
|
||||
use Inforbank\Application\Helper\Header;
|
||||
use Inforbank\Application\Helper\Idob\Transactie;
|
||||
use Inforbank\Application\Helper\Idob\Client;
|
||||
use Inforbank\Application\Helper\Rekeningen;
|
||||
use Inforbank\Application\Helper\Berichten;
|
||||
use Inforbank\Application\Helper\Overboekingen;
|
||||
use Inforbank\Application\Helper\Redirect;
|
||||
use Inforbank\Application\Helper\IBAN;
|
||||
|
||||
class Idob
|
||||
{
|
||||
public function __construct(App $app)
|
||||
{
|
||||
/**
|
||||
* Create the API route group
|
||||
*/
|
||||
$app->group('/idob', function () {
|
||||
$this->get('/betalen', function ($request, $response, $args) {
|
||||
$query = $request->getQueryParams();
|
||||
$rekeningen = Rekeningen::getCurrentUserRekeningen();
|
||||
|
||||
try {
|
||||
$transactie = Transactie::getTransactie($query['trxid']);
|
||||
$client = new Client($transactie['clientId']);
|
||||
$naam = $client->getClientName();
|
||||
} catch (\Exception $e) {
|
||||
$transactie = false;
|
||||
}
|
||||
|
||||
return $this->renderer->render($response, 'idob.phtml', [
|
||||
'header' => Header::getHeaderData(),
|
||||
'transactie' => $transactie,
|
||||
'webwinkel' => $naam,
|
||||
'rekeningen' => $rekeningen
|
||||
]);
|
||||
});
|
||||
|
||||
$this->get('/mislukt', function ($request, $response, $args) {
|
||||
return $this->renderer->render($response, 'idobmislukt.phtml', [
|
||||
'header' => Header::getHeaderData()
|
||||
]);
|
||||
});
|
||||
|
||||
$this->post('/betalen', function ($request, $response, $args) {
|
||||
$query = $request->getQueryParams();
|
||||
$post = $request->getParsedBody();
|
||||
$van = $post['van'];
|
||||
|
||||
try {
|
||||
$transactie = Transactie::getTransactie($query['trxid']);
|
||||
$client = new Client($transactie['clientId']);
|
||||
$redirectUri = $client->getClientRedirectURI();
|
||||
$rekening = $client->getClientRekening();
|
||||
$naam = $client->getClientName();
|
||||
|
||||
try {
|
||||
/**
|
||||
* 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");
|
||||
|
||||
// Do Status update
|
||||
Transactie::setTransactionStatus($transactie['transactieId'], 2);
|
||||
|
||||
// Do bericht
|
||||
Berichten::newBericht($this->auth->getUserID(), $naam, "Betaling met transactiereferentie " . $transactie['reference'] . " gelukt.");
|
||||
|
||||
$response = $response->withStatus(302);
|
||||
$response = $response->withHeader('Location', $redirectUri . "?trxid=".$transactie['transactieId']);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
$response = $response->withStatus(302);
|
||||
$response = $response->withHeader('Location', $redirectUri . "?error=".$e->getMessage());
|
||||
return $response;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return Redirect::create($request, $response, "/idob/mislukt");
|
||||
}
|
||||
});
|
||||
})->add(new Middleware());
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
<?php include '__header.phtml'; ?>
|
||||
|
||||
<h2 class="page-header">Betalen via Inforbank Direct Online Betalen</h2>
|
||||
|
||||
<?php if (!$transactie) {
|
||||
?>
|
||||
<div class="alert alert-danger" role="alert"><b>Fout!</b> Deze transactie bestaat niet.</div>
|
||||
<?php
|
||||
|
||||
} else {
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Transactie</div>
|
||||
<div class="panel-body">
|
||||
<b>Transactiereferentie</b>
|
||||
<p><?php echo $transactie['reference']; ?></p>
|
||||
<br/>
|
||||
<b>Ontvangende partij:</b>
|
||||
<p><?php echo $webwinkel; ?></p>
|
||||
<br/>
|
||||
<b>Te betalen:</b>
|
||||
<h3><?php echo money_format('%(#1n', $transactie['amount']); ?></h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Omschrijving</div>
|
||||
<div class="panel-body">
|
||||
<?php echo $transactie['description']; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<form class="form-horizontal" method="post" action="">
|
||||
<div class="form-group">
|
||||
<label for="van" class="col-sm-2 control-label">Betalen met</label>
|
||||
<div class="col-sm-10">
|
||||
<select name="van" class="form-control">
|
||||
<?php
|
||||
foreach ($rekeningen as $rekening) {
|
||||
echo "<option value=" . $rekening['nr'] . ">" . $rekening['iban'] . "</option>\n";
|
||||
} ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10"><br/>
|
||||
<p>Door het klikken op "Accepteren" hieronder, accepteert u de betaling en zal er <b><?php echo money_format('%(#1n', $transactie['amount']); ?></b> worden overgemaakt aan <b><?php echo $webwinkel; ?></b> ter betaling van het order met de transactierefrentie <b><?php echo $transactie['reference']; ?></b>.<br/><br/>Ga alleen verder als u zeker weet dat deze gegevens kloppen. U kunt ook de omschrijving van de transactie bekijken. Na de betaling wordt u teruggestuurd naar de webshop.
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<button type="submit" class="btn btn-default">Accepteren</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
} ?>
|
||||
|
||||
<?php include '__footer.phtml'; ?>
|
@ -0,0 +1,5 @@
|
||||
<?php include '__header.phtml'; ?>
|
||||
|
||||
<div class="alert alert-danger" role="alert"><b>Oeps!</b> De betaling via Inforbank Direct Online Betalen is mislukt. We konden je niet terugsturen naar de webshop. Sorry.</div>
|
||||
|
||||
<?php include '__footer.phtml'; ?>
|
Reference in New Issue