janunger / aqbanking-php

A wrapper to use AqBanking CLI from a PHP context
MIT License
13 stars 14 forks source link

Regex-pattern for amount validation seems not appropriate #1

Closed sauladam closed 10 years ago

sauladam commented 10 years ago

I encountered an issue with the validation of the MoneyElement in the renderMoneyElement()-function (ContextXmlRenderer.php)

if (!preg_match('/^(?P<amount>(-){0,1}\d+)\/100$/', $valueString, $matches)) {
    throw new \RuntimeException('Unexpected input');
}

The pattern '6789/100' is not always given, it can also be '6789/10' or just '6789'. There may be even more variants, but these are the ones I came across that are not matching the pattern.

Unfortunately I could not find out which patterns exactly can occur and when they occur.

One quick patch might be to check if there is a slash, and if so, if there is a multiple of 10 after the slash and then to 'normalize' the value to 'value/100'. So that '32/10' would be normalized to '320/100' and '3' would be normalized to '300/100'.

janunger commented 10 years ago

@sauladam I implemented a renderer in https://github.com/janunger/aqbanking-php/releases/tag/v0.1.1 that normalizes the value. Please let me know if this fixes your issue.

Just out of curiosity: Which bank keeps the account in your case? What's the currency of the account? I'm only dealing with german banks and Euro, so I haven't come across anything else than 100 as a divisor so far.

sauladam commented 10 years ago

@janunger Yep, this fixes it perfectly!

This issue occured with data from the Hypovereinsbank Essen, so it's a German bank, and the account is also held in Euro. It's the first and only bank I've queried through the FinTS-API so far.

Keep up the great work, this is a really helpful and nicely coded library!