action)) { $options = new \Fhp\Options\FinTsOptions(); $options->productName = $request->productName; $options->productVersion = $request->productVersion; $options->url = $request->url; $options->bankCode = $request->bankCode; $credentials = \Fhp\Options\Credentials::create($request->username, $request->pin); $persistedInstance = $persistedAction = null; function handleRequest(\stdClass $request, \Fhp\FinTs $fints) { global $persistedAction; switch ($request->action) { case 'getTanModes': return array_map(function ($mode) { return [ 'id' => $mode->getId(), 'name' => $mode->getName(), 'isDecoupled' => $mode->isDecoupled(), 'needsTanMedium' => $mode->needsTanMedium(), ]; }, array_values($fints->getTanModes())); case 'getTanMedia': return array_map(function ($medium) { return ['name' => $medium->getName(), 'phoneNumber' => $medium->getPhoneNumber()]; }, $fints->getTanMedia(intval($request->tanmode))); case 'login': $fints->selectTanMode(intval($request->tanmode), $request->tanmedium ?? null); $login = $fints->login(); if ($login->needsTan()) { $tanRequest = $login->getTanRequest(); $persistedAction = serialize($login); return ['result' => 'needsTan', 'challenge' => $tanRequest->getChallenge()]; } return ['result' => 'success']; case 'submitTan': $fints->submitTan(unserialize($persistedAction), $request->tan); $persistedAction = null; return ['result' => 'success']; case 'checkDecoupledSubmission': if ($fints->checkDecoupledSubmission(unserialize($persistedAction))) { $persistedAction = null; return ['result' => 'success']; } else { // IMPORTANT: If you pull this example code apart in your real application code, remember that after // calling checkDecoupledSubmission(), you need to call $fints->persist() again, just like this // example code will do after we return from handleRequest() here. return ['result' => 'ongoing']; } case 'getBalances': $getAccounts = \Fhp\Action\GetSEPAAccounts::create(); $fints->execute($getAccounts); if ($getAccounts->needsTan()) { throw new \Fhp\UnsupportedException( "This simple example code does not support strong authentication on GetSEPAAccounts calls. " . "But in your real application, you can do so analogously to how login() is handled above." ); } $getBalances = \Fhp\Action\GetBalance::create($getAccounts->getAccounts()[0], true); $fints->execute($getBalances); if ($getAccounts->needsTan()) { throw new \Fhp\UnsupportedException( "This simple example code does not support strong authentication on GetBalance calls. " . "But in your real application, you can do so analogously to how login() is handled above." ); } $balances = []; foreach ($getBalances->getBalances() as $balance) { $sdo = $balance->getGebuchterSaldo(); $balances[$balance->getAccountInfo()->getAccountNumber()] = $sdo->getAmount() . ' ' . $sdo->getCurrency(); } return $balances; case 'logout': $fints->close(); return ['result' => 'success']; default: throw new \InvalidArgumentException("Unknown action $request->action"); } } $sessionfile = __DIR__ . "/session_$request->sessionid.data"; if (file_exists($sessionfile)) { list($persistedInstance, $persistedAction) = unserialize(file_get_contents($sessionfile)); } $fints = \Fhp\FinTs::new($options, $credentials, $persistedInstance); $response = handleRequest($request, $fints); file_put_contents($sessionfile, serialize([$fints->persist(), $persistedAction])); header('Content-Type: application/json'); echo json_encode($response); return; } ?> phpFinTS Beispielanwendung

phpFinTS Beispielanwendung

Diese Beispielanwendung meldet sich im Onlinebanking an und holt die aktuellen Kontostände ab.

HINWEIS: Wenn sich Bank oder Benutzer ändern, sollte diese Seite erst neu geladen werden!

Registrierungsnummer:
Produktversion:
Bank URL:
Bankleitzahl:
Benutzerkennung:
Passwort/PIN: