Exemplo n.º 1
0
 def on_load(self):
     MyHTMLPage.on_load(self)
     error = CleanText(
         u'//span[@class="app_erreur"] | //p[@class="warning"] | //p[contains(text(), "Votre virement n\'a pas pu être enregistré")]'
     )(self.doc)
     if error and not u'Votre demande de virement a été enregistrée le' in error:
         raise TransferBankError(message=error)
Exemplo n.º 2
0
    def handle_response(self, account, recipient, amount, reason):
        # handle error
        error_msg = CleanText('//div[@id="blocErreur"]')(self.doc)
        if error_msg:
            raise TransferBankError(message=error_msg)

        account_txt = CleanText('//form//h3[contains(text(), "débiter")]//following::span[1]', replace=[(' ', '')])(self.doc)
        recipient_txt = CleanText('//form//h3[contains(text(), "créditer")]//following::span[1]', replace=[(' ', '')])(self.doc)

        assert account.id in account_txt or ''.join(account.label.split()) == account_txt, 'Something went wrong'
        assert recipient.id in recipient_txt or ''.join(recipient.label.split()) == recipient_txt, 'Something went wrong'

        amount_element = self.doc.xpath('//h3[contains(text(), "Montant du virement")]//following::span[@class="price"]')[0]
        r_amount = CleanDecimal.French('.')(amount_element)
        exec_date = Date(CleanText('//h3[contains(text(), "virement")]//following::span[@class="date"]'), dayfirst=True)(self.doc)
        currency = FrenchTransaction.Currency('.')(amount_element)

        transfer = Transfer()
        transfer.currency = currency
        transfer.amount = r_amount
        transfer.account_iban = account.iban
        transfer.recipient_iban = recipient.iban
        transfer.account_id = account.id
        transfer.recipient_id = recipient.id
        transfer.exec_date = exec_date
        transfer.label = reason
        transfer.account_label = account.label
        transfer.recipient_label = recipient.label
        transfer.account_balance = account.balance
        return transfer
Exemplo n.º 3
0
    def on_load(self):
        error_msg = '//p[@id="messErreur"]/span'
        if self.doc.xpath(error_msg):
            raise TransferBankError(message=CleanText(error_msg)(self.doc))

        confirm_transfer_xpath = '//h2[contains(text(), "Virement enregistr")]'
        assert self.doc.xpath(confirm_transfer_xpath)
Exemplo n.º 4
0
    def on_load(self):
        super(RegisterTransferPage, self).on_load()

        error_xpath = '//span[@class="erreur_phrase"]'
        if self.doc.xpath(error_xpath):
            error_msg = CleanText(error_xpath)(self.doc)
            raise TransferBankError(message=error_msg)
Exemplo n.º 5
0
    def check_error(self):
        # this is for transfer error, it's not a `AddRecipientBankError` but a `TransferBankError`

        msg = CleanText('//tr[@bgcolor="#C74545"]', default='')(
            self.doc)  # there is no id, class or anything...
        if msg:
            raise TransferBankError(message=msg)
Exemplo n.º 6
0
 def on_load(self):
     super(TransferPage, self).on_load()
     # warning: the "service indisponible" message (not catched here) is not a real BrowserUnavailable
     err = CleanText('//form//div[has-class("blc-choix-erreur")]//p',
                     default='')(self.doc)
     if err:
         raise TransferBankError(message=err)
Exemplo n.º 7
0
 def on_load(self):
     excluded_errors = [
         u"Vous n'avez pas la possibilité d'accéder à cette fonction. Veuillez prendre contact avec votre Conseiller.",
         u"Aucun compte de la liste n'est autorisé à la passation d'ordres de virement.",
     ]
     error_msg = CleanText('//span[@class="error_msg"]')(self.doc)
     if error_msg and error_msg not in excluded_errors:
         raise TransferBankError(error_msg)
Exemplo n.º 8
0
 def on_load(self):
     # This aims to track input errors.
     script_error = CleanText(
         u"//script[contains(text(), 'if (\"true\"===\"true\")')]")(
             self.doc)
     if script_error:
         raise TransferBankError(CleanText().filter(
             html2text(
                 re.search(u'\.html\("(.*?)"\)', script_error).group(1))))
Exemplo n.º 9
0
 def on_load(self):
     if self.doc.get('exception') and not self.doc.get('debitAccountOwner'):
         if Dict('exception/type')(self.doc) == 1:
             # technical error
             assert False, 'Error with code %s occured during init_transfer: %s' % \
                 (Dict('exception/code')(self.doc), Dict('exception/message')(self.doc))
         elif Dict('exception/type')(self.doc) == 2:
             # user error
             raise TransferBankError(message=Dict('exception/message')(self.doc))
Exemplo n.º 10
0
    def execute_transfer(self, transfer, **kwargs):
        assert self.transfer_confirm.is_here()
        self.page.submit()

        assert self.transfer_sent.is_here()
        transfer_error = self.page.get_transfer_error()
        if transfer_error:
            raise TransferBankError(transfer_error)

        # the last page contains no info, return the last transfer object from init_transfer
        return transfer
Exemplo n.º 11
0
 def on_load(self):
     if Dict('commun/statut')(self.doc).upper() == 'NOK':
         if self.doc['commun'].get('action'):
             raise TransferBankError(
                 message=Dict('commun/action')(self.doc))
         elif self.doc['commun'].get('raison') in ('err_tech', 'err_is'):
             # on SG website, there is unavalaible message 'Le service est momentanément indisponible.'
             raise BrowserUnavailable()
         else:
             assert False, 'Something went wrong, transfer is not created: %s' % self.doc[
                 'commun'].get('raison')
Exemplo n.º 12
0
    def init_transfer(self, account, recipient, transfer):
        self.transfer_dates.go()
        if not self.page.is_date_valid(transfer.exec_date):
            raise TransferBankError(
                message=
                "La date d'exécution du virement est invalide. Elle doit correspondre aux horaires et aux dates d'ouvertures d'agence."
            )

        # update account and recipient info
        recipient = find_object(self.iter_recipients(account),
                                iban=recipient.iban,
                                error=RecipientNotFound)

        data = [
            ('an_codeAction', 'C'),
            ('an_referenceSiOrdre', ''),
            ('cl_compteEmetteur_intitule', account._account_title),
            ('cl_compteEmetteur_libelle', account.label),
            ('an_compteEmetteur_iban', account.iban),
            ('cl_compteEmetteur_ibanFormate', account._formatted_iban),
            ('an_compteEmetteur_bic', account._bic),
            ('b64_compteEmetteur_idPrestation', account._id_service),
            ('an_guichetGestionnaire', account._manage_counter),
            ('an_codeProduit', account._product_code),
            ('an_codeSousProduit', account._underproduct_code),
            ('n_soldeComptableVeilleMontant',
             int(account.balance * (10**account._decimal_code))),
            ('n_soldeComptableVeilleCodeDecimalisation',
             account._decimal_code),
            ('an_soldeComptableVeilleDevise', account._currency_code),
            ('n_ordreMontantValeur',
             int(transfer.amount * (10**account._decimal_code))),
            ('n_ordreMontantCodeDecimalisation', account._decimal_code),
            ('an_ordreMontantCodeDevise', account._currency_code),
            ('cl_dateExecution', transfer.exec_date.strftime('%d/%m/%Y')),
            ('cl_ordreLibelle', transfer.label),
            ('an_beneficiaireCodeAction', 'C'),
            ('cl_beneficiaireRefSiCoordonnee', recipient._ref),
            ('cl_beneficiaireCompteLibelle', recipient.label),
            ('cl_beneficiaireCompteIntitule', recipient._account_title),
            ('cl_beneficiaireCompteIbanFormate', recipient._formatted_iban),
            ('an_beneficiaireCompteIban', recipient.iban),
            ('cl_beneficiaireCompteBic', recipient._bic),
            ('cl_beneficiaireDateCreation', recipient._created_date),
            ('cl_beneficiaireCodeOrigine', recipient._code_origin),
            ('cl_beneficiaireAdressePays', recipient.iban[:2]),
            ('an_indicateurIntraAbonnement', 'false'),
            ('cl_reference', ' '),
            ('cl_motif', transfer.label),
        ]
        # WARNING: this save transfer information on user account
        self.init_transfer_page.go(data=data)
        return self.page.handle_response(account, recipient, transfer.amount,
                                         transfer.label, transfer.exec_date)
Exemplo n.º 13
0
    def handle_transfer_errors(self, r):
        error_page = r.response.json()
        assert 'error' in error_page, "Something went wrong, transfer is not created"

        error = error_page['error']
        error_msg = error['message']

        if error['code'] == 'TRANSFER.INVALID_AMOUNT_MINIMUM':
            raise TransferInvalidAmount(message=error_msg)
        elif error['code'] == 'INPUT_INVALID' and len(error['values']):
            for value in error['values']:
                error_msg = '%s %s %s.' % (error_msg, value, error['values'][value])

        raise TransferBankError(message=error_msg)
Exemplo n.º 14
0
    def handle_response(self, transfer):
        summary_filter = CleanText(
            '//div[contains(@class, "bloc-recapitulatif")]//p'
        )

        # handle error
        if "Votre virement n'a pas pu" in summary_filter(self.doc):
            raise TransferBankError(message=summary_filter(self.doc))

        transfer_id = Regexp(summary_filter, r'référence n° (\d+)', default=None)(self.doc)
        # not always available
        if transfer_id and not transfer.id:
            transfer.id = transfer_id
        else:
            # TODO handle transfer with sms code.
            if 'veuillez saisir votre code de validation' in CleanText('//div[@class="bloc Tmargin"]')(self.doc):
                raise NotImplementedError()

        # WARNING: At this point, the transfer was made.
        # The following code is made to retrieve the transfer execution date,
        # so there is no falsy data.
        # But the bp website is unstable with changing layout and messages.
        # One of the goals here is for the code not to crash to avoid the user thinking
        # that the transfer was not made while it was.

        old_date = transfer.exec_date
        # the date was modified because on a weekend
        if 'date correspondant à un week-end' in summary_filter(self.doc):
            transfer.exec_date = Date(Regexp(
                summary_filter,
                r'jour ouvré suivant \((\d{2}/\d{2}/\d{4})\)',
                default=''
            ), dayfirst=True, default=NotAvailable)(self.doc)
            self.logger.warning('The transfer execution date changed from %s to %s' % (old_date.strftime('%Y-%m-%d'), transfer.exec_date.strftime('%Y-%m-%d')))
        # made today
        elif 'date du jour de ce virement' in summary_filter(self.doc):
            # there are several regexp for transfer date:
            # Date ([\d\/]+)|le ([\d\/]+)|suivant \(([\d\/]+)\)
            # be more passive to avoid impulsive reaction from user
            transfer.exec_date = Date(Regexp(
                summary_filter,
                r' (\d{2}/\d{2}/\d{4})',
                default=''
            ), dayfirst=True, default=NotAvailable)(self.doc)
        # else: using the same date because the website does not give one

        if empty(transfer.exec_date):
            transfer.exec_date = old_date

        return transfer
Exemplo n.º 15
0
    def on_load(self):
        errors_msg = (
            CleanText(
                '//form[@id="SaisieVirementForm"]/p[has-class("error")]/label')
            (self.doc),
            CleanText(
                '//div[@id="error" and @class="erreur_texte"]/p[contains(text(), "n\'est pas autorisé")]'
            )(self.doc),
        )
        for error in errors_msg:
            if error:
                raise TransferBankError(error)

        other_error_msg = self.doc.xpath(
            '//div[@id="error" and @class="erreur_texte"]')
        assert not other_error_msg, 'Error "other_error_msg" is not handled yet'
Exemplo n.º 16
0
 def check_errors(self):
     if not 'data' in self.doc:
         raise TransferBankError(message=self.doc['message'])
Exemplo n.º 17
0
 def on_load(self):
     error = CleanText(
         '//span[@id="MM_LblMessagePopinError"]/p | //div[h2[contains(text(), "Erreur de saisie")]]/p[1] | //span[@class="error"]/strong'
     )(self.doc)
     if error:
         raise TransferBankError(message=error)
Exemplo n.º 18
0
 def check_transfer_exec(self):
     error_msg = Dict('messageErreur')(self.doc)
     if error_msg:
         raise TransferBankError(message=error_msg)
     return Dict('page')(self.doc)
Exemplo n.º 19
0
 def on_load(self):
     msg = CleanText('//li')(self.doc)
     if msg:
         raise TransferBankError(message=msg)