* SZEP balance implemented web,cli

* xml tidy
* small code cleanup
This commit is contained in:
Danyi Dávid 2020-01-29 20:36:53 +01:00
parent e1482ced6d
commit f97ed69ce7
10 changed files with 164 additions and 12 deletions

View File

@ -8,6 +8,7 @@ return [
App\Command\PeriodicSZEPCommand::class => App\Command\PeriodicSZEPCommandFactory::class,
App\Command\DebugCommand::class => App\Command\DebugCommandFactory::class,
App\Command\PendingCommand::class => App\Command\PendingCommandFactory::class,
App\Command\SZEPBalanceCommand::class => App\Command\SZEPBalanceCommandFactory::class,
],
],
'console' => [
@ -16,6 +17,7 @@ return [
App\Command\PeriodicSZEPCommand::class,
App\Command\DebugCommand::class,
App\Command\PendingCommand::class,
App\Command\SZEPBalanceCommand::class,
],
],
];

View File

@ -35,5 +35,6 @@ use Zend\Expressive\MiddlewareFactory;
return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void {
$app->get('/', App\Action\HomePageAction::class, 'home');
$app->get('/list', App\Action\PingAction::class, 'api.list');
$app->get('/szep/balance', App\Action\SZEPBalanceAction::class, 'api.szep.balance');
$app->post('/store/{direction:sent|received}/{hashKey}', App\Action\StoreAction::class, 'api.store');
};

View File

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?><StartWorkflow>
<TemplateName>BANKKARTYASZAMLAEGYENLEGLEKERDEZES</TemplateName><Variables>
<isClientCode>BANKKARTYASUGYFEL</isClientCode>
<isIdentificationData>%s</isIdentificationData>
<isSecretData>%s</isSecretData>
<isStartDate>%s</isStartDate>
<isEndDate>%s</isEndDate>
</Variables></StartWorkflow>
<?xml version="1.0" encoding="UTF-8"?>
<StartWorkflow>
<TemplateName>BANKKARTYASZAMLAEGYENLEGLEKERDEZES</TemplateName>
<Variables>
<isClientCode>BANKKARTYASUGYFEL</isClientCode>
<isIdentificationData>%s</isIdentificationData>
<isSecretData>%s</isSecretData>
<isStartDate>%s</isStartDate>
<isEndDate>%s</isEndDate>
</Variables>
</StartWorkflow>

View File

@ -1,6 +1,5 @@
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace App\Action;
use App\Response\JsonCorsResponse;
use App\Service\SZEPManagerService;
use Exception;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class SZEPBalanceAction extends AbstractAction
{
private $SZEPManagerService;
public function __construct(SZEPManagerService $SZEPManagerService)
{
$this->SZEPManagerService = $SZEPManagerService;
}
/**
* @param ServerRequestInterface $request
* @return ResponseInterface
* @throws Exception
*/
public function create(ServerRequestInterface $request): ResponseInterface
{
return new JsonCorsResponse($this->SZEPManagerService->pollBalance());
}
}

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace App\Action;
use App\Service\SZEPManagerService;
use Interop\Container\ContainerInterface;
class SZEPBalanceFactory
{
public function __invoke(ContainerInterface $container)
{
$SZEPManagerService = $container->get(SZEPManagerService::class);
return new SZEPBalanceAction($SZEPManagerService);
}
}

View File

@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Service\SZEPManagerService;
use Exception;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SZEPBalanceCommand extends Command
{
/**
* @var SZEPManagerService
*/
private $szepManager;
public function __construct(SZEPManagerService $szepManager)
{
$this->szepManager = $szepManager;
parent::__construct();
}
protected function configure()
{
$this->setName('szep:balance')
->setDescription('Show current balance');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|void|null
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$balance = $this->szepManager->pollBalance();
$table = new Table($output);
$table
->setHeaders(['Étkezés', 'Szabadidő', 'Szállás'])
->addRow($balance)
->render();
}
}

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Service\SZEPManagerService;
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class SZEPBalanceCommandFactory
{
/**
* @param ContainerInterface $container
* @return SZEPBalanceCommand
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container): SZEPBalanceCommand
{
/** @var SZEPManagerService $szepManager */
$szepManager = $container->get(SZEPManagerService::class);
return new SZEPBalanceCommand($szepManager);
}
}

View File

@ -44,6 +44,7 @@ class ConfigProvider
'factories' => [
Action\HomePageAction::class => Action\HomePageFactory::class,
Action\StoreAction::class => Action\StoreFactory::class,
Action\SZEPBalanceAction::class => Action\SZEPBalanceFactory::class,
Service\SmsStoreService::class => Service\SmsStoreServiceFactory::class,
Service\KoinService::class => Service\KoinServiceFactory::class,

View File

@ -25,7 +25,7 @@ class SZEPManagerService
const CERTIFICATE_WEB_PATH = "https://www.otpbankdirekt.hu/homebank/mobilalkalmazas/certificate";
const CERTIFICATE_CACHED_PATH = "data/cache/SZEP_cert.pem";
const SOAP_ENDPOINT = "https://www.otpbankdirekt.hu/mwaccesspublic/mwaccess";
const SOAP_ENDPOINT = "https://www.otpbankdirekt.hu/mwaccesspublic1984/mwaccess";
const POCKET_FOOD = 'Vendéglátás';
const POCKET_SPORT = 'Szabadidő';
@ -71,6 +71,17 @@ class SZEPManagerService
$this->koinService = $koinService;
}
/**
* @throws Exception
*/
public function pollBalance(): ?array
{
if (null !== ($pollResult = $this->getRecentXml())) {
return $this->parseBalance($pollResult);
}
return null;
}
/**
* @throws ORMException
* @throws OptimisticLockException
@ -121,6 +132,19 @@ class SZEPManagerService
return base64_decode($returnElement->textContent);
}
private function parseBalance(string $resultXml): array
{
$domDocument = new DOMDocument();
$domDocument->loadXML($resultXml);
$documentXpath = new DOMXPath($domDocument);
return [
'vendeglatas' => intval($documentXpath->query('/answer/szamla_osszeg7')->item(0)->textContent),
'szabadido' => intval($documentXpath->query('/answer/szamla_osszeg8')->item(0)->textContent),
'szallashely' => intval($documentXpath->query('/answer/szamla_osszeg9')->item(0)->textContent),
];
}
/**
* Parse the decoded payload
* @param string $resultXml
@ -135,12 +159,11 @@ class SZEPManagerService
$domDocument->loadXML($resultXml);
$documentXpath = new DOMXPath($domDocument);
/** @var DOMElement[] $returnElements */
/** @var DOMElement[] $recordElements */
$recordElements = $documentXpath->query('/answer/resultset/record');
$newRecords = [];
/** @var DOMElement $element */
foreach ($recordElements as $element) {
$date = trim($documentXpath->query('./datum', $element)->item(0)->textContent);
$amount = trim($documentXpath->query('./osszeg', $element)->item(0)->textContent);