nemiah / phpFinTS

PHP library to communicate with FinTS/HBCI servers
MIT License
130 stars 39 forks source link

Extension of browser.php with TAN query #413

Closed ben2603 closed 1 month ago

ben2603 commented 1 year ago

Hi all,

I would like to use phpFinTS to retrieve transactions in order to process them automatically. To do so, I added a call for retrieving transactions to the example file browser.php, which works great so far. However, both of my two banks do not ask for a TAN, so I have no way of testing the whole thing in connection with entering a TAN.

Due to the lack of test options on my side, I would like to ask you whether you could help me and make the query compatible with a TAN request. This should work with chipTAN and photoTAN as well as with a decoupled confirmation. Could you please extend the file browser.php so that the transaction query works with all TAN options? The whole thing can be kept pretty quick & dirty - I can make it look nice myself afterwards. ;-)

I would be very happy if you could send me an offer for these modifications: ben_2603@gmx.de

Here is my extension of browser.php to include the transaction query, which I basically took over from the example statementOfAccount.php:

case 'getStatementOfAccount':
     $getSepaAccounts = \Fhp\Action\GetSEPAAccounts::create();
     $fints->execute($getSepaAccounts); // needsTan()?
     $oneAccount = false;
     foreach ($getSepaAccounts->getAccounts() as $accountID => $accountDetails) {
           if ($accountDetails->getIban() == 'DExxxxxxxxxxxxxxxxxxx') {
                $oneAccount = $getSepaAccounts->getAccounts()[$accountID];
           }
     }
     if ($oneAccount === false)
           return 'account wasn\'t found';
     $from = new \DateTime('2023-07-01');
     $to = new \DateTime();
     $getStatement = \Fhp\Action\GetStatementOfAccount::create($oneAccount, $from, $to);
     $fints->execute($getStatement); // needsTan()?
     $soa = $getStatement->getStatement();
     $transactions = [];
     foreach ($soa->getStatements() as $statement) {
           foreach ($statement->getTransactions() as $transaction) {
                $transactions[] = ['date' => $transaction->getBookingDate()->format('Y-m-d'),
                                   'amount' => ($transaction->getCreditDebit() == \Fhp\Model\StatementOfAccount\Transaction::CD_DEBIT ? '-' : '').$transaction->getAmount(),
                                   'name' => $transaction->getName(),
                                   'description' => $transaction->getMainDescription(),
                                   'canceled' => $transaction->isStorno()
                                  ];
           }
     }
     return $transactions;

Best,

Ben

lukas-staab commented 1 year ago

It should be quite close to the implementation at the login. After you execute the action you can check with $action->needsTan() if a TAN is needed, if yes persist action and fints and ask the User for TAN if not check the results as above.

You usually should be able to debug this yourself. The banks should force you for a TAN if your Query Time for Statements is long enough. Most of the time > 3 Months you need a TAN.

Edit: iirc: the GetAccounts Action should not (never?) need a TAN. StatementsOfAccount sometimes, see above.

ben2603 commented 1 year ago

Thank you very much for your support!

I've added $action->needsTan() now and think it should work. In fact, my own bank never asks for a TAN when retrieving transactions, not even if I request a long period of time. But I'll test with friends' accounts to see if the TAN prompt works with them.

Thanks again for your help!