Commit dae6c2ed authored by Célande Adrien's avatar Célande Adrien Committed by ntome

[ing] handle new recipient errors

I handle new recipient errors.
Now the website return a 400 error with its errors.
So the handle_error pages are useless.
parent c654eec8
......@@ -30,9 +30,7 @@ from weboob.browser.pages import LoggedPage, JsonPage
from weboob.browser.elements import method, DictElement, ItemElement
from weboob.browser.filters.json import Dict
from weboob.browser.filters.standard import Env, Field, Date
from weboob.capabilities.bank import (
Recipient, RecipientInvalidIban, RecipientInvalidOTP,
)
from weboob.capabilities.bank import Recipient
class TransferINGVirtKeyboard(SimpleVirtualKeyboard):
......@@ -168,13 +166,6 @@ class AddRecipientPage(LoggedPage, JsonPage):
rcpt = self.doc
return rcpt['accountHolderName'] == recipient.label and rcpt['iban'] == recipient.iban
def handle_error(self):
if 'error' in self.doc:
if self.doc['error']['code'] == 'EXTERNAL_ACCOUNT.IBAN_NOT_FRENCH':
# not using the bank message because it is too generic
raise RecipientInvalidIban(message="L'IBAN doit correpondre à celui d'une banque domiciliée en France.")
assert False, 'Recipient error not handled'
class OtpChannelsPage(LoggedPage, JsonPage):
def get_sms_info(self):
......@@ -186,10 +177,4 @@ class OtpChannelsPage(LoggedPage, JsonPage):
class ConfirmOtpPage(LoggedPage, JsonPage):
def handle_error(self):
if 'error' in self.doc:
error_code = self.doc['error']['code']
if error_code == 'SCA.WRONG_OTP_ATTEMPT':
raise RecipientInvalidOTP(message=self.doc['error']['message'])
assert False, 'Recipient OTP error not handled'
pass
......@@ -30,7 +30,7 @@ from weboob.browser.exceptions import ClientError
from weboob.capabilities.bank import (
TransferBankError, TransferInvalidAmount,
AddRecipientStep, RecipientInvalidOTP,
AddRecipientTimeout, AddRecipientBankError,
AddRecipientTimeout, AddRecipientBankError, RecipientInvalidIban,
)
from weboob.tools.capabilities.bank.transactions import FrenchTransaction
from weboob.tools.value import Value
......@@ -436,23 +436,38 @@ class IngAPIBrowser(LoginBrowser, StatesMixin):
raise AddRecipientStep(recipient, Value('code', label='Veuillez saisir le code temporaire envoyé par SMS'))
def handle_recipient_error(self, r):
# The bank gives an error message when an error occures.
# But sometimes the message is not relevant.
# So I may replace it by nothing or by a custom message.
# The exception to raise can be coupled with:
# * Nothing: empty message
# * None: message of the bank
# * String: custom message
RECIPIENT_ERROR = {
'SENSITIVE_OPERATION.SENSITIVE_OPERATION_NOT_FOUND': (AddRecipientTimeout,),
'SENSITIVE_OPERATION.EXPIRED_TEMPORARY_CODE': (AddRecipientTimeout, None),
'EXTERNAL_ACCOUNT.EXTERNAL_ACCOUNT_ALREADY_EXISTS': (AddRecipientBankError, None),
'EXTERNAL_ACCOUNT.ACCOUNT_RESTRICTION': (AddRecipientBankError, None),
'EXTERNAL_ACCOUNT.EXTERNAL_ACCOUNT_IS_INTERNAL_ACCOUT': (AddRecipientBankError, None), # nice spelling
'EXTERNAL_ACCOUNT.IBAN_NOT_FRENCH': (RecipientInvalidIban, "L'IBAN doit correpondre à celui d'une banque domiciliée en France."),
'SCA.WRONG_OTP_ATTEMPT': (RecipientInvalidOTP, None),
'INPUT_INVALID': (AssertionError, None), # invalid request
}
error_page = r.response.json()
if 'error' in error_page:
error = error_page['error']
# the error message may seem generic
# but after testing multiple cases
# it is the only time that it appears
if error['code'] == 'SENSITIVE_OPERATION.SENSITIVE_OPERATION_NOT_FOUND':
raise AddRecipientTimeout()
elif error['code'] in (
'EXTERNAL_ACCOUNT.EXTERNAL_ACCOUNT_ALREADY_EXISTS',
# not allowed to add a recipient
'EXTERNAL_ACCOUNT.ACCOUNT_RESTRICTION',
):
raise AddRecipientBankError(message=error['message'])
error_exception = RECIPIENT_ERROR.get(error['code'])
if error_exception:
if len(error_exception) == 1:
raise error_exception[0]()
elif error_exception[1] is None:
raise error_exception[0](message=error['message'])
else:
raise error_exception[0](message=error_exception[1])
assert False, 'Recipient error not handled'
assert False, 'Recipient error "%s" not handled' % error['code']
@need_login
def end_sms_recipient(self, recipient, code):
......@@ -477,8 +492,6 @@ class IngAPIBrowser(LoginBrowser, StatesMixin):
self.handle_recipient_error(e)
raise
self.page.handle_error()
@need_login
@need_to_be_on_website('api')
def new_recipient(self, recipient, **params):
......@@ -507,8 +520,6 @@ class IngAPIBrowser(LoginBrowser, StatesMixin):
self.handle_recipient_error(e)
raise
self.page.handle_error()
assert self.page.check_recipient(recipient), "The recipients don't match."
self.add_recipient_info = self.page.doc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment