From 5d09d96cf2907a53a505bc995493cf6fc01b79a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danyi=20D=C3=A1vid?= Date: Sun, 8 Jul 2018 22:40:28 +0200 Subject: [PATCH] * SZEP card transaction log check bumped to last 7 days * account_id and transation parameter form changes in KOIN --- src/App/Service/KoinService.php | 46 +++++++++++++++++++++----- src/App/Service/SZEPManagerService.php | 2 +- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/App/Service/KoinService.php b/src/App/Service/KoinService.php index 27a1eb3..3465e7a 100644 --- a/src/App/Service/KoinService.php +++ b/src/App/Service/KoinService.php @@ -38,6 +38,11 @@ class KoinService */ private $httpClient; + /** + * @var string + */ + private $accountId; + /** * @var string */ @@ -285,6 +290,7 @@ class KoinService $body = $httpResponse->getBody(); $this->getCsrfToken($body); + $this->getAccountId($body); $httpResponse = $this->httpClient ->post(self::BASE_URI . "/site/login", [ @@ -306,9 +312,9 @@ class KoinService $documentXpath = $this->getCsrfToken($htmlData); /** @var \DOMNodeList $expenseOptionElements */ - $expenseOptionElements = $documentXpath->query('//select[@id="transactioncreate-category_id"]/optgroup[@label="Kiadás"]/option'); + $expenseOptionElements = $documentXpath->query('//select[@id="transaction-category_id"]/optgroup[@label="Kiadás"]/option'); /** @var \DOMNodeList $incomeOptionElements */ - $incomeOptionElements = $documentXpath->query('//select[@id="transactioncreate-category_id"]/optgroup[@label="Bevétel"]/option'); + $incomeOptionElements = $documentXpath->query('//select[@id="transaction-category_id"]/optgroup[@label="Bevétel"]/option'); /** @var \DOMElement $element */ foreach ($expenseOptionElements as $element) { @@ -347,6 +353,29 @@ class KoinService return $documentXpath; } + /** + * Parse account:id from html + * + * @param $html + * @return \DOMXPath + */ + private function getAccountId($html): \DOMXPath + { + $xmlErrorHandling = libxml_use_internal_errors(TRUE); + $domDocument = new \DOMDocument(); + $domDocument->loadHTML($html); + libxml_clear_errors(); + libxml_use_internal_errors($xmlErrorHandling); + + $documentXpath = new \DOMXPath($domDocument); + /** @var \DOMElement $accountIdElement */ + $accountIdElement = $documentXpath->query('//input[@id="transaction-account_id"]')->item(0); + + $this->csrfParam = $accountIdElement->getAttribute("value"); + + return $documentXpath; + } + /** * @param string $amount * @param string $currency @@ -361,12 +390,13 @@ class KoinService ->post(self::BASE_URI . "/main/save-transaction", [ 'form_params' => [ $this->csrfParam => $this->csrfToken, - 'TransactionCreate[category_id]' => $category, - 'TransactionCreate[value]' => $amount, - 'TransactionCreate[currency]' => $currency, - 'TransactionCreate[imgKey]' => "", - 'TransactionCreate[tagData]' => $tags, - 'TransactionCreate[date]' => $date, + 'Transaction[account_id]' => $this->accountId, + 'Transaction[category_id]' => $category, + 'Transaction[value]' => $amount, + 'Transaction[currency]' => $currency, + 'Transaction[imgKey]' => "", + 'Transaction[tagData]' => $tags, + 'Transaction[date]' => $date, ], ]); diff --git a/src/App/Service/SZEPManagerService.php b/src/App/Service/SZEPManagerService.php index 2bbcbe9..63aeba2 100644 --- a/src/App/Service/SZEPManagerService.php +++ b/src/App/Service/SZEPManagerService.php @@ -82,7 +82,7 @@ class SZEPManagerService openssl_public_encrypt($this->config['szep.key'], $cryptCardKey, $certificate, OPENSSL_PKCS1_PADDING); $endDate = new \DateTimeImmutable(); - $startDate = $endDate->sub(new \DateInterval('P4D')); + $startDate = $endDate->sub(new \DateInterval('P7D')); $gueryTemplate = file_get_contents(self::TEMPLATE_QUERY_CARD); $query = sprintf($gueryTemplate,