From 8dfba9da16fbef45986db46d0082db94f633e9a6 Mon Sep 17 00:00:00 2001 From: Guillaume Risbourg Date: Thu, 20 Feb 2020 14:31:54 +0100 Subject: [PATCH] [caissedepargne] Handle CloudCard for transfers CloudCard (aka Secur'Pass) is a method that asks for an AppValidation when adding new recipients or making transfer when not on the Caisse d'Epargne application. --- modules/caissedepargne/browser.py | 51 ++++++++++++++++++++----------- modules/caissedepargne/module.py | 4 +-- modules/caissedepargne/pages.py | 4 ++- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/modules/caissedepargne/browser.py b/modules/caissedepargne/browser.py index b5fc691bab..f78625f0fd 100644 --- a/modules/caissedepargne/browser.py +++ b/modules/caissedepargne/browser.py @@ -1512,16 +1512,21 @@ def init_transfer(self, account, recipient, transfer): if self.validation_option.is_here(): self.get_auth_mechanisms_validation_info() - if self.otp_validation['type'] == 'CLOUDCARD': - raise AuthMethodNotImplemented() - - raise TransferStep( - transfer, - Value( - 'otp_sms', - label='Veuillez renseigner le mot de passe unique qui vous a été envoyé par SMS dans le champ réponse.' + if self.otp_validation['type'] == 'SMS': + self.is_send_sms = True + raise TransferStep( + transfer, + Value( + 'otp_sms', + label='Veuillez renseigner le mot de passe unique qui vous a été envoyé par SMS dans le champ réponse.' + ) + ) + elif self.otp_validation['type'] == 'CLOUDCARD': + self.is_app_validation = True + raise AppValidation( + resource=transfer, + message="Veuillez valider le transfert sur votre application mobile.", ) - ) if 'netpro' in self.url: return self.page.create_transfer(account, recipient, transfer) @@ -1530,15 +1535,27 @@ def init_transfer(self, account, recipient, transfer): return self.page.update_transfer(transfer, account, recipient) @need_login - def otp_sms_continue_transfer(self, transfer, **params): - self.is_send_sms = False - assert 'otp_sms' in params, 'OTP SMS is missing' + def otp_validation_continue_transfer(self, transfer, **params): + assert ( + 'resume' in params + or 'otp_sms' in params + ), 'otp_sms or resume is missing' + + if 'resume' in params: + self.is_app_validation = False + + self.do_authentication_validation( + authentication_method='CLOUDCARD', + feature='transfer', + ) + elif 'otp_sms' in params: + self.is_send_sms = False - self.do_authentication_validation( - authentication_method='SMS', - feature='transfer', - otp_sms=params['otp_sms'] - ) + self.do_authentication_validation( + authentication_method='SMS', + feature='transfer', + otp_sms=params['otp_sms'] + ) if self.transfer.is_here(): self.page.continue_transfer(transfer.account_label, transfer.recipient_label, transfer.label) diff --git a/modules/caissedepargne/module.py b/modules/caissedepargne/module.py index 7259ea226f..b8c0dcad4e 100644 --- a/modules/caissedepargne/module.py +++ b/modules/caissedepargne/module.py @@ -115,8 +115,8 @@ def iter_transfer_recipients(self, origin_account): return self.browser.iter_recipients(origin_account) def init_transfer(self, transfer, **params): - if 'otp_sms' in params: - return self.browser.otp_sms_continue_transfer(transfer, **params) + if 'otp_sms' in params or 'resume' in params: + return self.browser.otp_validation_continue_transfer(transfer, **params) self.logger.info('Going to do a new transfer') transfer.label = re.sub(r"[^0-9A-Z/?:().,'+ -]+", '', transfer.label.upper()) diff --git a/modules/caissedepargne/pages.py b/modules/caissedepargne/pages.py index 8434003cbe..c48fefb1f1 100644 --- a/modules/caissedepargne/pages.py +++ b/modules/caissedepargne/pages.py @@ -47,6 +47,7 @@ Transfer, TransferBankError, TransferInvalidOTP, Recipient, AddRecipientBankError, RecipientInvalidOTP, Emitter, EmitterNumberType, AddRecipientError, + TransferError, ) from weboob.capabilities.wealth import Investment from weboob.capabilities.bill import DocumentTypes, Subscription, Document @@ -188,8 +189,9 @@ def login_errors(self, error): def transfer_errors(self, error): if error == 'FAILED_AUTHENTICATION': - # For the moment, only otp sms is handled raise TransferInvalidOTP(message="Le code SMS que vous avez renseigné n'est pas valide") + elif error == 'AUTHENTICATION_CANCELED': + raise TransferError(message="Le virement a été annulée via l'application mobile.") def recipient_errors(self, error): if error == 'FAILED_AUTHENTICATION': -- GitLab