diff --git a/config/autoload/cli.global.php b/config/autoload/cli.global.php index a01aed0..7012da6 100644 --- a/config/autoload/cli.global.php +++ b/config/autoload/cli.global.php @@ -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, ], ], ]; diff --git a/config/routes.php b/config/routes.php index c9ac947..44b938e 100644 --- a/config/routes.php +++ b/config/routes.php @@ -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'); }; diff --git a/data/soap-xmls/SZEP_queryCard.xml b/data/soap-xmls/SZEP_queryCard.xml index 260abd1..b30a0aa 100644 --- a/data/soap-xmls/SZEP_queryCard.xml +++ b/data/soap-xmls/SZEP_queryCard.xml @@ -1,8 +1,11 @@ - -BANKKARTYASZAMLAEGYENLEGLEKERDEZES -BANKKARTYASUGYFEL -%s -%s -%s -%s - \ No newline at end of file + + + BANKKARTYASZAMLAEGYENLEGLEKERDEZES + + BANKKARTYASUGYFEL + %s + %s + %s + %s + + \ No newline at end of file diff --git a/data/soap-xmls/SZEP_startWorkflowSynch.xml b/data/soap-xmls/SZEP_startWorkflowSynch.xml index ab15cee..ea15ddd 100644 --- a/data/soap-xmls/SZEP_startWorkflowSynch.xml +++ b/data/soap-xmls/SZEP_startWorkflowSynch.xml @@ -1,6 +1,5 @@ diff --git a/src/App/Action/SZEPBalanceAction.php b/src/App/Action/SZEPBalanceAction.php new file mode 100644 index 0000000..398331b --- /dev/null +++ b/src/App/Action/SZEPBalanceAction.php @@ -0,0 +1,31 @@ +SZEPManagerService = $SZEPManagerService; + } + + /** + * @param ServerRequestInterface $request + * @return ResponseInterface + * @throws Exception + */ + public function create(ServerRequestInterface $request): ResponseInterface + { + return new JsonCorsResponse($this->SZEPManagerService->pollBalance()); + } +} diff --git a/src/App/Action/SZEPBalanceFactory.php b/src/App/Action/SZEPBalanceFactory.php new file mode 100644 index 0000000..29c83a8 --- /dev/null +++ b/src/App/Action/SZEPBalanceFactory.php @@ -0,0 +1,17 @@ +get(SZEPManagerService::class); + return new SZEPBalanceAction($SZEPManagerService); + } +} diff --git a/src/App/Command/SZEPBalanceCommand.php b/src/App/Command/SZEPBalanceCommand.php new file mode 100644 index 0000000..43e3e70 --- /dev/null +++ b/src/App/Command/SZEPBalanceCommand.php @@ -0,0 +1,49 @@ +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(); + } +} diff --git a/src/App/Command/SZEPBalanceCommandFactory.php b/src/App/Command/SZEPBalanceCommandFactory.php new file mode 100644 index 0000000..1787063 --- /dev/null +++ b/src/App/Command/SZEPBalanceCommandFactory.php @@ -0,0 +1,26 @@ +get(SZEPManagerService::class); + return new SZEPBalanceCommand($szepManager); + } +} diff --git a/src/App/ConfigProvider.php b/src/App/ConfigProvider.php index 0b94e83..048b979 100644 --- a/src/App/ConfigProvider.php +++ b/src/App/ConfigProvider.php @@ -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, diff --git a/src/App/Service/SZEPManagerService.php b/src/App/Service/SZEPManagerService.php index 8062503..da098ca 100644 --- a/src/App/Service/SZEPManagerService.php +++ b/src/App/Service/SZEPManagerService.php @@ -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);