Ejemplo n.º 1
0
    def transfer(self, account, to, amount, reason=None):
        if self.is_new_website:
            raise NotImplementedError()
        # access the transfer page
        self.transfert.go(subbank=self.currentSubBank)

        # fill the form
        form = self.page.get_form(xpath="//form[@id='P:F']")
        try:
            form['data_input_indiceCompteADebiter'] = self.page.get_from_account_index(account)
            form['data_input_indiceCompteACrediter'] = self.page.get_to_account_index(to)
        except ValueError as e:
            raise TransferError(e.message)
        form['[t:dbt%3adouble;]data_input_montant_value_0_'] = '%s' % str(amount).replace('.', ',')
        if reason is not None:
            form['[t:dbt%3astring;x(27)]data_input_libelleCompteDebite'] = reason
            form['[t:dbt%3astring;x(31)]data_input_motifCompteCredite'] = reason
        del form['_FID_GoCancel']
        del form['_FID_DoValidate']
        form['_FID_DoValidate.x'] = str(randint(3, 125))
        form['_FID_DoValidate.y'] = str(randint(3, 22))
        form.submit()

        # look for known errors
        content = self.page.get_unicode_content()
        insufficient_amount_message =     u'Le montant du virement doit être positif, veuillez le modifier'
        maximum_allowed_balance_message = u'Montant maximum autorisé au débit pour ce compte'

        if insufficient_amount_message in content:
            raise TransferError('The amount you tried to transfer is too low.')

        if maximum_allowed_balance_message in content:
            raise TransferError('The maximum allowed balance for the target account has been / would be reached.')

        # look for the known "all right" message
        ready_for_transfer_message = u'Confirmer un virement entre vos comptes'
        if ready_for_transfer_message not in content:
            raise TransferError('The expected message "%s" was not found.' % ready_for_transfer_message)

        # submit the confirmation form
        form = self.page.get_form(xpath="//form[@id='P:F']")
        del form['_FID_DoConfirm']
        form['_FID_DoConfirm.x'] = str(randint(3, 125))
        form['_FID_DoConfirm.y'] = str(randint(3, 22))
        submit_date = datetime.now()
        form.submit()

        # look for the known "everything went well" message
        content = self.page.get_unicode_content()
        transfer_ok_message = u'Votre virement a été exécuté'
        if transfer_ok_message not in content:
            raise TransferError('The expected message "%s" was not found.' % transfer_ok_message)

        # We now have to return a Transfer object
        transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
        transfer.amount = amount
        transfer.origin = account
        transfer.recipient = to
        transfer.date = submit_date
        return transfer
Ejemplo n.º 2
0
    def transfer(self, account, to, amount, reason=None):
        # access the transfer page
        parameters = 'RAZ=ALL&Cat=6&PERM=N&CHX=A'
        page = self.transfert.go(subbank=self.currentSubBank, parameters=parameters)

        # fill the form
        form = self.page.get_form(name='FormVirUniSaiCpt')
        form['IDB'] = account[-1]
        form['ICR'] = to[-1]
        form['MTTVIR'] = '%s' % str(amount).replace('.', ',')
        if reason is not None:
            form['LIBDBT'] = reason
            form['LIBCRT'] = reason
        page = form.submit()

        # look for known errors
        content = page.response.text
        insufficient_amount_message     = u'Montant insuffisant.'
        maximum_allowed_balance_message = u'Solde maximum autorisé dépassé.'

        if insufficient_amount_message in content:
            raise TransferError('The amount you tried to transfer is too low.')

        if maximum_allowed_balance_message in content:
            raise TransferError('The maximum allowed balance for the target account has been / would be reached.')

        # look for the known "all right" message
        ready_for_transfer_message = u'Confirmez un virement entre vos comptes'
        if ready_for_transfer_message in content:
            raise TransferError('The expected message "%s" was not found.' % ready_for_transfer_message)

        # submit the confirmation form
        form = page.get_form(name='FormVirUniCnf')
        submit_date = datetime.now()
        page = form.submit()

        # look for the known "everything went well" message
        content = page.response.text
        transfer_ok_message = u'Votre virement a été exécuté ce jour'
        if not transfer_ok_message in content:
            raise TransferError('The expected message "%s" was not found.' % transfer_ok_message)

        # We now have to return a Transfer object
        transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
        transfer.amount = amount
        transfer.origin = account
        transfer.recipient = to
        transfer.date = submit_date
        return transfer
Ejemplo n.º 3
0
    def transfer(self, account, to, amount, reason=None):
        # access the transfer page
        transfert_url = 'WI_VPLV_VirUniSaiCpt.asp?RAZ=ALL&Cat=6&PERM=N&CHX=A'
        self.location('https://%s/%s/fr/banque/%s' % (self.DOMAIN, self.currentSubBank, transfert_url))

        # fill the form
        self.select_form(name='FormVirUniSaiCpt')
        self['IDB'] = [account[-1]]
        self['ICR'] = [to[-1]]
        self['MTTVIR'] = '%s' % str(amount).replace('.', ',')
        if reason != None:
            self['LIBDBT'] = reason
            self['LIBCRT'] = reason
        self.submit()

        # look for known errors
        content = unicode(self.response().get_data(), self.ENCODING)
        insufficient_amount_message     = u'Montant insuffisant.'
        maximum_allowed_balance_message = u'Solde maximum autorisé dépassé.'

        if content.find(insufficient_amount_message) != -1:
            raise TransferError('The amount you tried to transfer is too low.')

        if content.find(maximum_allowed_balance_message) != -1:
            raise TransferError('The maximum allowed balance for the target account has been / would be reached.')

        # look for the known "all right" message
        ready_for_transfer_message = u'Confirmez un virement entre vos comptes'
        if not content.find(ready_for_transfer_message):
            raise TransferError('The expected message "%s" was not found.' % ready_for_transfer_message)

        # submit the confirmation form
        self.select_form(name='FormVirUniCnf')
        submit_date = datetime.now()
        self.submit()

        # look for the known "everything went well" message
        content = unicode(self.response().get_data(), self.ENCODING)
        transfer_ok_message = u'Votre virement a été exécuté ce jour'
        if not content.find(transfer_ok_message):
            raise TransferError('The expected message "%s" was not found.' % transfer_ok_message)

        # We now have to return a Transfer object
        transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
        transfer.amount = amount
        transfer.origin = account
        transfer.recipient = to
        transfer.date = submit_date
        return transfer
Ejemplo n.º 4
0
 def recap(self):
     if len(self.document.xpath('//p[@class="alert alert-success"]')) == 0:
         raise BrokenPageError('Unable to find confirmation')
     div = self.document.find(
             '//div[@class="encadre transfert-validation"]')
     transfer = Transfer(0)
     transfer.amount = Decimal(FrenchTransaction.clean_amount(
         div.xpath('.//label[@id="confirmtransferAmount"]')[0].text))
     transfer.origin = div.xpath(
             './/span[@id="confirmfromAccount"]')[0].text
     transfer.recipient = div.xpath(
             './/span[@id="confirmtoAccount"]')[0].text
     transfer.reason = unicode(
             div.xpath('.//span[@id="confirmtransferMotive"]')[0].text)
     return transfer
Ejemplo n.º 5
0
    def transfer(self, from_id, to_id, amount, reason=None):
        if not self.is_on_page(pages.TransferPage):
            self.location('/NS_VIRDF')

        self.page.transfer(from_id, to_id, amount, reason)

        if not self.is_on_page(pages.TransferCompletePage):
            raise TransferError('An error occured during transfer')

        transfer = Transfer(self.page.get_id())
        transfer.amount = amount
        transfer.origin = from_id
        transfer.recipient = to_id
        transfer.date = datetime.now()
        return transfer
Ejemplo n.º 6
0
    def make_transfer(self, from_account, to_account, amount):
        self.location('https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virement/virementSafran_aiguillage/init-saisieComptes.ea')
        self.page.set_accouts(from_account, to_account)

        #TODO: Check
        self.page.complete_transfer(amount)

        self.page.confirm()

        id_transfer = self.page.get_transfer_id()
        transfer = Transfer(id_transfer)
        transfer.amount = amount
        transfer.origin = from_account.label
        transfer.recipient = to_account.label
        transfer.date = datetime.now()
        return transfer
Ejemplo n.º 7
0
    def transfer(self, account, to, amount, reason=None):
        if self.is_new_website:
            raise NotImplementedError()
        # access the transfer page
        self.transfert.go(subbank=self.currentSubBank)

        # fill the form
        form = self.page.get_form(xpath="//form[@id='P:F']")
        try:
            form['data_input_indiceCompteADebiter'] = self.page.get_from_account_index(account)
            form['data_input_indiceCompteACrediter'] = self.page.get_to_account_index(to)
        except ValueError as e:
            raise TransferError(e.message)
        form['[t:dbt%3adouble;]data_input_montant_value_0_'] = '%s' % str(amount).replace('.', ',')
        if reason is not None:
            form['[t:dbt%3astring;x(27)]data_input_libelleCompteDebite'] = reason
            form['[t:dbt%3astring;x(31)]data_input_motifCompteCredite'] = reason
        del form['_FID_GoCancel']
        del form['_FID_DoValidate']
        form['_FID_DoValidate.x'] = str(randint(3, 125))
        form['_FID_DoValidate.y'] = str(randint(3, 22))
        form.submit()

        # look for known errors
        content = self.page.get_unicode_content()
        insufficient_amount_message =     u'Le montant du virement doit être positif, veuillez le modifier'
        maximum_allowed_balance_message = u'Montant maximum autorisé au débit pour ce compte'

        if insufficient_amount_message in content:
            raise TransferError('The amount you tried to transfer is too low.')

        if maximum_allowed_balance_message in content:
            raise TransferError('The maximum allowed balance for the target account has been / would be reached.')

        # look for the known "all right" message
        ready_for_transfer_message = u'Confirmer un virement entre vos comptes'
        if ready_for_transfer_message not in content:
            raise TransferError('The expected message "%s" was not found.' % ready_for_transfer_message)

        # submit the confirmation form
        form = self.page.get_form(xpath="//form[@id='P:F']")
        del form['_FID_DoConfirm']
        form['_FID_DoConfirm.x'] = str(randint(3, 125))
        form['_FID_DoConfirm.y'] = str(randint(3, 22))
        submit_date = datetime.now()
        form.submit()

        # look for the known "everything went well" message
        content = self.page.get_unicode_content()
        transfer_ok_message = u'Votre virement a été exécuté'
        if transfer_ok_message not in content:
            raise TransferError('The expected message "%s" was not found.' % transfer_ok_message)

        # We now have to return a Transfer object
        transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
        transfer.amount = amount
        transfer.origin = account
        transfer.recipient = to
        transfer.date = submit_date
        return transfer
Ejemplo n.º 8
0
 def recap(self):
     div = self.document.find('//div[@class="content recap"]')
     transfer = Transfer(0)
     transfer.amount = Decimal(FrenchTransaction.clean_amount(div.xpath('.//span[@id="confirmtransferAmount"]')[0].text))
     transfer.origin = div.xpath('.//span[@id="confirmfromAccount"]')[0].text
     transfer.recipient = div.xpath('.//span[@id="confirmtoAccount"]')[0].text
     transfer.reason = div.xpath('.//span[@id="confirmtransferMotive"]')[0].text
     return transfer
Ejemplo n.º 9
0
    def transfer(self, from_id, to_id, amount, reason=None):
        if not self.is_on_page(TransferPage):
            self.location('/NS_VIRDF')

        # Need to clean HTML before parse it
        html = self.response().get_data().replace("<!input", "<input")
        response = mechanize.make_response(
        html, [("Content-Type", "text/html")],
        "https://client.hellobank.fr/NS_VIRDF", 200, "OK")
        self.set_response(response)

        accounts = self.page.get_accounts()
        self.page.transfer(from_id, to_id, amount, reason)

        if not self.is_on_page(TransferCompletePage):
            raise TransferError('An error occured during transfer')

        transfer = Transfer(self.page.get_id())
        transfer.amount = amount
        transfer.origin = accounts[from_id].label
        transfer.recipient = accounts[to_id].label
        transfer.date = datetime.now()
        return transfer
Ejemplo n.º 10
0
    def transfer(self, account, to, amount, reason=None):
        # access the transfer page
        transfert_url = 'WI_VPLV_VirUniSaiCpt.asp?RAZ=ALL&Cat=6&PERM=N&CHX=A'
        self.location('https://%s/%s/fr/banque/%s' %
                      (self.DOMAIN, self.currentSubBank, transfert_url))

        # fill the form
        self.select_form(name='FormVirUniSaiCpt')
        self['IDB'] = [account[-1]]
        self['ICR'] = [to[-1]]
        self['MTTVIR'] = '%s' % str(amount).replace('.', ',')
        if reason != None:
            self['LIBDBT'] = reason
            self['LIBCRT'] = reason
        self.submit()

        # look for known errors
        content = unicode(self.response().get_data(), self.ENCODING)
        insufficient_amount_message = u'Montant insuffisant.'
        maximum_allowed_balance_message = u'Solde maximum autorisé dépassé.'

        if content.find(insufficient_amount_message) != -1:
            raise TransferError('The amount you tried to transfer is too low.')

        if content.find(maximum_allowed_balance_message) != -1:
            raise TransferError(
                'The maximum allowed balance for the target account has been / would be reached.'
            )

        # look for the known "all right" message
        ready_for_transfer_message = u'Confirmez un virement entre vos comptes'
        if not content.find(ready_for_transfer_message):
            raise TransferError('The expected message "%s" was not found.' %
                                ready_for_transfer_message)

        # submit the confirmation form
        self.select_form(name='FormVirUniCnf')
        submit_date = datetime.now()
        self.submit()

        # look for the known "everything went well" message
        content = unicode(self.response().get_data(), self.ENCODING)
        transfer_ok_message = u'Votre virement a été exécuté ce jour'
        if not content.find(transfer_ok_message):
            raise TransferError('The expected message "%s" was not found.' %
                                transfer_ok_message)

        # We now have to return a Transfer object
        transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
        transfer.amount = amount
        transfer.origin = account
        transfer.recipient = to
        transfer.date = submit_date
        return transfer
Ejemplo n.º 11
0
    def transfer(self, account, to, amount, reason=None):
        # access the transfer page
        parameters = 'RAZ=ALL&Cat=6&PERM=N&CHX=A'
        page = self.transfert.go(subbank=self.currentSubBank,
                                 parameters=parameters)

        # fill the form
        form = self.page.get_form(name='FormVirUniSaiCpt')
        form['IDB'] = account[-1]
        form['ICR'] = to[-1]
        form['MTTVIR'] = '%s' % str(amount).replace('.', ',')
        if reason is not None:
            form['LIBDBT'] = reason
            form['LIBCRT'] = reason
        page = form.submit()

        # look for known errors
        content = page.response.text
        insufficient_amount_message = u'Montant insuffisant.'
        maximum_allowed_balance_message = u'Solde maximum autorisé dépassé.'

        if insufficient_amount_message in content:
            raise TransferError('The amount you tried to transfer is too low.')

        if maximum_allowed_balance_message in content:
            raise TransferError(
                'The maximum allowed balance for the target account has been / would be reached.'
            )

        # look for the known "all right" message
        ready_for_transfer_message = u'Confirmez un virement entre vos comptes'
        if ready_for_transfer_message in content:
            raise TransferError('The expected message "%s" was not found.' %
                                ready_for_transfer_message)

        # submit the confirmation form
        form = page.get_form(name='FormVirUniCnf')
        submit_date = datetime.now()
        page = form.submit()

        # look for the known "everything went well" message
        content = page.response.text
        transfer_ok_message = u'Votre virement a été exécuté ce jour'
        if transfer_ok_message not in content:
            raise TransferError('The expected message "%s" was not found.' %
                                transfer_ok_message)

        # We now have to return a Transfer object
        transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
        transfer.amount = amount
        transfer.origin = account
        transfer.recipient = to
        transfer.date = submit_date
        return transfer
Ejemplo n.º 12
0
 def recap(self):
     if len(self.document.xpath('//p[@class="alert alert-success"]')) == 0:
         raise BrokenPageError('Unable to find confirmation')
     div = self.document.find(
             '//div[@class="encadre transfert-validation"]')
     transfer = Transfer(0)
     transfer.amount = Decimal(FrenchTransaction.clean_amount(
         div.xpath('.//label[@id="confirmtransferAmount"]')[0].text))
     transfer.origin = div.xpath(
             './/span[@id="confirmfromAccount"]')[0].text
     transfer.recipient = div.xpath(
             './/span[@id="confirmtoAccount"]')[0].text
     transfer.reason = unicode(
             div.xpath('.//span[@id="confirmtransferMotive"]')[0].text)
     return transfer
Ejemplo n.º 13
0
    def transfer(self, from_id, to_id, amount, reason=None):
        if not self.is_on_page(TransferPage):
            self.location('/NS_VIRDF')

        accounts = self.page.get_accounts()
        self.page.transfer(from_id, to_id, amount, reason)

        if not self.is_on_page(TransferCompletePage):
            raise TransferError('An error occured during transfer')

        transfer = Transfer(self.page.get_id())
        transfer.amount = amount
        transfer.origin = accounts[from_id].label
        transfer.recipient = accounts[to_id].label
        transfer.date = datetime.now()
        return transfer
Ejemplo n.º 14
0
    def make_transfer(self, from_account, to_account, amount):
        self.location(
            'https://voscomptesenligne.labanquepostale.fr/voscomptes/canalXHTML/virement/virementSafran_aiguillage/init-saisieComptes.ea'
        )
        self.page.set_accouts(from_account, to_account)

        #TODO: Check
        self.page.complete_transfer(amount)

        self.page.confirm()

        id_transfer = self.page.get_transfer_id()
        transfer = Transfer(id_transfer)
        transfer.amount = amount
        transfer.origin = from_account.label
        transfer.recipient = to_account.label
        transfer.date = datetime.now()
        return transfer
Ejemplo n.º 15
0
    def transfer(self, from_id, to_id, amount, reason=None):
        if not self.is_on_page(TransferPage):
            self.location('/NS_VIRDF')

        # Need to clean HTML before parse it
        html = self.response().get_data().replace("<!input", "<input")
        response = mechanize.make_response(
            html, [("Content-Type", "text/html")],
            "https://client.hellobank.fr/NS_VIRDF", 200, "OK")
        self.set_response(response)

        accounts = self.page.get_accounts()
        self.page.transfer(from_id, to_id, amount, reason)

        if not self.is_on_page(TransferCompletePage):
            raise TransferError('An error occured during transfer')

        transfer = Transfer(self.page.get_id())
        transfer.amount = amount
        transfer.origin = accounts[from_id].label
        transfer.recipient = accounts[to_id].label
        transfer.date = datetime.now()
        return transfer
Ejemplo n.º 16
0
    def handle_response(self, account, recipient, amount, reason):
        account_txt = CleanText(
            '//form//dl/dt[span[contains(text(), "biter")]]/following::dd[1]',
            replace=[(' ', '')])(self.doc)
        recipient_txt = CleanText(
            '//form//dl/dt[span[contains(text(), "diter")]]/following::dd[1]',
            replace=[(' ', '')])(self.doc)
        try:
            assert account.id in account_txt or ''.join(
                account.label.split()) == account_txt
            assert recipient.id in recipient_txt or ''.join(
                recipient.label.split()) == recipient_txt
        except AssertionError:
            raise TransferError('Something went wrong')
        r_amount = CleanDecimal(
            '//form//dl/dt[span[contains(text(), "Montant")]]/following::dd[1]',
            replace_dots=True)(self.doc)
        exec_date = Date(CleanText(
            '//form//dl/dt[span[contains(text(), "Date")]]/following::dd[1]'),
                         dayfirst=True)(self.doc)
        currency = FrenchTransaction.Currency(
            '//form//dl/dt[span[contains(text(), "Montant")]]/following::dd[1]'
        )(self.doc)

        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
Ejemplo n.º 17
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
Ejemplo n.º 18
0
    def handle_response(self, transfer):
        t = Transfer()
        t._space = transfer._space
        t._operation = transfer._operation
        t._token = transfer._token
        t._connection_id = transfer._connection_id

        t.label = Dict('transferComplementaryInformations1')(self.doc)
        t.exec_date = Date(Dict('dateVirement'), dayfirst=True)(self.doc)
        t.amount = CleanDecimal(Dict('amount'))(self.doc)
        t.currency = Dict('currencyCode')(self.doc)

        t.account_id = Dict('currentDebitAccountNumber')(self.doc)
        t.account_iban = Dict('currentDebitIbanCode')(self.doc)
        t.account_label = Dict('typeCompte')(self.doc)

        t.recipient_label = CleanText(Dict('currentCreditAccountName'))(self.doc)
        t.recipient_id = t.recipient_iban = Dict('currentCreditIbanCode')(self.doc)

        # Internal transfer
        if not Dict('isExternalTransfer')(self.doc):
            t.recipient_id = Dict('currentCreditAccountNumber')(self.doc)

        return t
Ejemplo n.º 19
0
    def handle_response(self, account, recipient, amount, reason):
        tables_xpath = '//table[@id="table-confVrt" or @id="table-confDestinataire"]'

        # Summary is divided into 2 tables, we have to concat them
        # col_heads is a list of all header of the 2 tables (order is important)
        self.col_heads = [CleanText('.')(head) for head in self.doc.xpath(tables_xpath + '//td[@class="libColumn"]')]
        # col_contents is a list of all content of the 2 tables (order is important)
        self.col_contents = [CleanText('.')(content) for content in self.doc.xpath(tables_xpath + '//td[@class="contentColumn"]')]

        transfer = Transfer()

        transfer.currency = Currency().filter(self.get_element_by_name('Montant'))
        transfer.amount = CleanDecimal().filter(self.get_element_by_name('Montant'))

        date = Regexp(pattern=r'(\d+/\d+/\d+)').filter(self.get_element_by_name('Date du virement'))
        transfer.exec_date = Date(dayfirst=True).filter(date)

        account_label_id = self.get_element_by_name(u'Compte à débiter')
        transfer.account_id = (Regexp(pattern=r'(\d+)').filter(account_label_id))
        transfer.account_label = Regexp(pattern=r'([\w \.]+)').filter(account_label_id)
        # account iban is not in the summary page
        transfer.account_iban = account.iban

        transfer.recipient_id = recipient.id
        transfer.recipient_iban = self.get_element_by_name('IBAN').replace(' ', '')
        transfer.recipient_label = self.get_element_by_name(u'Nom du bénéficiaire')
        transfer.label = CleanText('//table[@id="table-confLibelle"]//p')(self.doc)

        return transfer
Ejemplo n.º 20
0
    def handle_response(self, account, recipient, amount, reason):
        self.check_errors()
        transfer_data = self.doc['data']['validationVirement']

        self.abort_if_unknown(transfer_data)

        if 'idBeneficiaire' in transfer_data and transfer_data['idBeneficiaire'] is not None:
            assert transfer_data['idBeneficiaire'] == recipient._transfer_id
        elif transfer_data.get('ibanCompteCrediteur'):
            assert transfer_data['ibanCompteCrediteur'] == recipient.iban

        transfer = Transfer()
        transfer.currency = transfer_data['devise']
        transfer.amount = Decimal(transfer_data['montantEuros'])
        transfer.account_iban = transfer_data['ibanCompteDebiteur']
        transfer.account_id = account.id
        try:
            transfer.recipient_iban = transfer_data['ibanCompteCrediteur'] or recipient.iban
        except KeyError:
            # In last version, json contains a key 'idBeneficiaire' containing:
            # "idBeneficiaire" : "00003##00001####FR7610278123456789028070101",
            transfer.recipient_id = transfer_data['idBeneficiaire']
            transfer.recipient_iban = transfer.recipient_id.split('#')[-1] or recipient.iban
        else:
            transfer.recipient_id = recipient.id
        transfer.exec_date = parse_french_date(transfer_data['dateExecution']).date()
        transfer.fees = Decimal(transfer_data.get('montantFrais', '0'))
        transfer.label = transfer_data['motifVirement']

        transfer.account_label = account.label
        transfer.recipient_label = recipient.label
        transfer.id = transfer_data['reference']
        # This is true if a transfer with the same metadata has already been done recently
        transfer._doublon = transfer_data['doublon']
        transfer.account_balance = account.balance

        return transfer
Ejemplo n.º 21
0
    def handle_response(self, account, recipient, amount, reason):
        self.check_errors()
        transfer_data = self.doc['data']['validationVirement']

        self.abort_if_unknown(transfer_data)

        if transfer_data['idBeneficiaire'] is not None:
            assert transfer_data['idBeneficiaire'] == recipient.id

        exec_date = Date(transfer_data['dateExecution']).date()
        today = datetime.today().date()
        if transfer_data['typeOperation'] == '1':
            assert exec_date == today
        else:
            assert exec_date > today

        transfer = Transfer()
        transfer.currency = transfer_data['devise']
        transfer.amount = Decimal(transfer_data['montantEuros'])
        transfer.account_iban = transfer_data['ibanCompteDebiteur']
        transfer.recipient_iban = transfer_data[
            'ibanCompteCrediteur'] or recipient.iban
        transfer.account_id = account.id
        transfer.recipient_id = recipient.id
        transfer.exec_date = exec_date
        transfer.fees = Decimal(transfer_data['montantFrais'])
        transfer.label = transfer_data['motifVirement']

        transfer.account_label = account.label
        transfer.recipient_label = recipient.label
        transfer.id = transfer_data['reference']
        # This is true if a transfer with the same metadata has already been done recently
        transfer._doublon = transfer_data['doublon']
        transfer.account_balance = account.balance

        return transfer
Ejemplo n.º 22
0
    def handle_response(self, account, recipient, amount, label, exec_date):
        summary_xpath = '//div[@id="as_verifVirement.do_"]//ul'

        transfer = Transfer()

        transfer_data = {
            account.id: CleanText(
                summary_xpath + '/li[contains(text(), "Compte à débiter")]'
            )(self.doc),
            recipient.id: CleanText(
                summary_xpath + '/li[contains(text(), "Compte à créditer")]', replace=[(' ', '')]
            )(self.doc),
            recipient._recipient_name: CleanText(
                summary_xpath + '/li[contains(text(), "Nom du bénéficiaire")]'
            )(self.doc),
            label: CleanText(summary_xpath + '/li[contains(text(), "Motif")]')(self.doc),
        }
        self.check_transfer_data(transfer_data)

        transfer.account_id = account.id
        transfer.account_label = account.label
        transfer.account_iban = account.iban

        transfer.recipient_id = recipient.id
        transfer.recipient_label = recipient.label
        transfer.recipient_iban = recipient.iban

        transfer.label = label
        transfer.currency = Currency(summary_xpath + '/li[contains(text(), "Montant")]')(self.doc)
        transfer.amount = CleanDecimal(
            Regexp(CleanText(summary_xpath + '/li[contains(text(), "Montant")]'), r'((\d+)\.?(\d+)?)')
        )(self.doc)
        transfer.exec_date = Date(Regexp(CleanText(
            summary_xpath + '/li[contains(text(), "Date de virement")]'
        ), r'(\d+/\d+/\d+)'), dayfirst=True)(self.doc)

        return transfer
Ejemplo n.º 23
0
    def _build_transfer(self, line):
        if self.interactive:
            id_from, id_to, amount, reason, exec_date = self.parse_command_args(line, 5, 0)
        else:
            id_from, id_to, amount, reason, exec_date = self.parse_command_args(line, 5, 3)

        missing = not bool(id_from and id_to and amount)

        if id_from:
            account = self.get_object(id_from, 'get_account', [])
            id_from = account.id
            if not account:
                print('Error: account %s not found' % id_from, file=self.stderr)
                return
        else:
            with self.use_cmd_formatter('list'):
                self.do_ls('')
            id_from = self.ask('Transfer money from account', default='')
            if not id_from:
                return
            id_from, backend = self.parse_id(id_from)

            account = find_object(self.objects, fullid='%s@%s' % (id_from, backend))
            if not account:
                return
            id_from = account.id

        if id_to:
            id_to, backend_name_to = self.parse_id(id_to)
            if account.backend != backend_name_to:
                print("Transfer between different backends is not implemented", file=self.stderr)
                return
            rcpts = self.do('iter_transfer_recipients', id_from, backends=account.backend)
            rcpt = find_object(rcpts, id=id_to)
        else:
            with self.use_cmd_formatter('recipients'):
                self.do_recipients(account.fullid)
            id_to = self.ask('Transfer money to recipient', default='')
            if not id_to:
                return
            id_to, backend = self.parse_id(id_to)

            rcpt = find_object(self.objects, fullid='%s@%s' % (id_to, backend))
            if not rcpt:
                return

        if not amount:
            amount = self.ask('Amount to transfer', default='', regexp=r'\d+(?:\.\d*)?')
        try:
            amount = Decimal(amount)
        except (TypeError, ValueError, InvalidOperation):
            print('Error: please give a decimal amount to transfer', file=self.stderr)
            return
        if amount <= 0:
            print('Error: transfer amount must be strictly positive', file=self.stderr)
            return

        if missing:
            reason = self.ask('Label of the transfer (seen by the recipient)', default='')
            exec_date = self.ask('Execution date of the transfer (YYYY-MM-DD format, empty for today)', default='')

        today = datetime.date.today()
        if exec_date:
            try:
                exec_date = datetime.datetime.strptime(exec_date, '%Y-%m-%d').date()
            except ValueError:
                print('Error: execution date must be valid and in YYYY-MM-DD format', file=self.stderr)
                return
            if exec_date < today:
                print('Error: execution date cannot be in the past', file=self.stderr)
                return
        else:
            exec_date = today

        transfer = Transfer()
        transfer.backend = account.backend
        transfer.account_id = account.id
        transfer.account_label = account.label
        transfer.account_iban = account.iban
        transfer.recipient_id = id_to
        if rcpt:
            # Try to find the recipient label. It can be missing from
            # recipients list, for example for banks which allow transfers to
            # arbitrary recipients.
            transfer.recipient_label = rcpt.label
            transfer.recipient_iban = rcpt.iban
        transfer.amount = amount
        transfer.label = reason or u''
        transfer.exec_date = exec_date

        return transfer
Ejemplo n.º 24
0
 def create_transfer(self, account, recipient, transfer):
     transfer = Transfer()
     transfer.currency = FrenchTransaction.Currency(
         './/tr[td[contains(text(), "Montant")]]/td[not(@class)] | \
                                                     .//tr[th[contains(text(), "Montant")]]/td[not(@class)]'
     )(self.doc)
     transfer.amount = CleanDecimal(
         './/tr[td[contains(text(), "Montant")]]/td[not(@class)] | \
                                     .//tr[th[contains(text(), "Montant")]]/td[not(@class)]',
         replace_dots=True)(self.doc)
     transfer.account_iban = account.iban
     transfer.recipient_iban = Upper(Regexp(CleanText(u'.//tr[th[contains(text(), "Compte à créditer")]]/td[not(@class)]'), '(\w+)$'))(self.doc) \
                               if recipient.category == u'Externe' else recipient.iban
     transfer.account_id = unicode(account.id)
     transfer.recipient_id = unicode(recipient.id)
     transfer.exec_date = Date(CleanText(
         './/tr[th[contains(text(), "En date du")]]/td[not(@class)]'),
                               dayfirst=True)(self.doc)
     transfer.label = CleanText(
         u'.//tr[td[contains(text(), "Motif de l\'opération")]]/td[not(@class)] | \
                                  .//tr[td[contains(text(), "Libellé")]]/td[not(@class)]'
     )(self.doc)
     transfer.account_label = account.label
     transfer.recipient_label = recipient.label
     transfer._account = account
     transfer._recipient = recipient
     transfer.account_balance = account.balance
     return transfer
Ejemplo n.º 25
0
    def handle_response(self, origin, recipient, amount, reason, exec_date):
        account_data = Dict('donnees/detailOrdre/compteEmetteur')(self.doc)
        recipient_data = Dict('donnees/listOperations/0/compteBeneficiaire')(
            self.doc)
        transfer_data = Dict('donnees/detailOrdre')(self.doc)

        transfer = Transfer()
        transfer._b64_id_transfer = Dict('idOrdre')(transfer_data)

        transfer.account_id = origin.id
        transfer.account_label = Dict('libelleCompte')(account_data)
        transfer.account_iban = Dict('ibanCompte')(account_data)
        transfer.account_balance = origin.balance

        transfer.recipient_id = recipient.id
        transfer.recipient_label = Dict('libelleCompte')(recipient_data)
        transfer.recipient_iban = Dict('ibanCompte')(recipient_data)

        transfer.currency = Dict('montantTotalOrdre/codeDevise')(transfer_data)
        transfer.amount = CleanDecimal(
            Eval(lambda x, y: x * (10**-y),
                 Dict('montantTotalOrdre/valeurMontant'),
                 Dict('montantTotalOrdre/codeDecimalisation')))(transfer_data)
        transfer.exec_date = Date(Dict('dateExecution'),
                                  dayfirst=True)(transfer_data)
        transfer.label = Dict('libelleClientOrdre')(transfer_data)

        return transfer
Ejemplo n.º 26
0
 def create_transfer(self, account, recipient, transfer):
     transfer = Transfer()
     transfer.currency = FrenchTransaction.Currency(
         './/td[@headers="virement montant"]')(self.doc)
     transfer.amount = CleanDecimal('.//td[@headers="virement montant"]',
                                    replace_dots=True)(self.doc)
     transfer.account_iban = CleanText('//td[@headers="emetteur IBAN"]',
                                       replace=[(' ', '')])(self.doc)
     transfer.recipient_iban = CleanText(
         '//td[@headers="beneficiaire IBAN"]',
         replace=[(' ', '')])(self.doc)
     transfer.account_id = account.id
     transfer.recipient_id = recipient.id
     transfer.exec_date = Date(CleanText('.//td[@headers="virement date"]'),
                               dayfirst=True)(self.doc)
     transfer.label = CleanText('.//td[@headers="virement motif"]')(
         self.doc)
     transfer.account_label = account.label
     transfer.recipient_label = recipient.label
     transfer._account = account
     transfer._recipient = recipient
     transfer.account_balance = account.balance
     return transfer
Ejemplo n.º 27
0
    def recap(self, origin, recipient, transfer):
        error = CleanText(u'//div[@id="transfer_form:moveMoneyDetailsBody"]//span[@class="error"]', default=None)(self.doc) or \
                CleanText(u'//p[contains(text(), "Nous sommes désolés. Le solde de votre compte ne doit pas être inférieur au montant de votre découvert autorisé. Veuillez saisir un montant inférieur.")]', default=None)(self.doc)
        if error:
           raise TransferInvalidAmount(error)

        t = Transfer()
        t.label = transfer.label
        assert transfer.amount == CleanDecimal('//div[@id="transferSummary"]/div[@id="virementLabel"]\
        //label[@class="digits positive"]', replace_dots=True)(self.doc)
        t.amount = transfer.amount
        t.currency = FrenchTransaction.Currency('//div[@id="transferSummary"]/div[@id="virementLabel"]\
        //label[@class="digits positive"]')(self.doc)

        assert origin.label == CleanText('//div[@id="transferSummary"]/div[has-class("debit")]//span[@class="title"]')(self.doc)
        assert origin.balance == CleanDecimal('//div[@id="transferSummary"]/div[has-class("debit")]\
        //label[@class="digits positive"]', replace_dots=True)(self.doc)
        t.account_balance = origin.balance
        t.account_label = origin.label
        t.account_iban = origin.iban
        t.account_id = origin.id

        assert recipient.label == CleanText('//div[@id="transferSummary"]/div[has-class("credit")]//span[@class="title"]')(self.doc)
        t.recipient_label = recipient.label
        t.recipient_iban = recipient.iban
        t.recipient_id = recipient.id

        t.exec_date = parse_french_date(CleanText('//p[has-class("exec-date")]', children=False,
                replace=[('le', ''), (u'exécuté', ''), ('demain', ''), ('(', ''), (')', '')])(self.doc)).date()
        return t
Ejemplo n.º 28
0
    def handle_response(self, origin, recipient, amount, reason, exec_date):
        account_data = Dict('donnees/detailOrdre/compteEmetteur')(self.doc)
        recipient_data = Dict('donnees/listOperations/0/compteBeneficiaire')(self.doc)
        transfer_data = Dict('donnees/detailOrdre')(self.doc)

        transfer = Transfer()
        transfer._b64_id_transfer = Dict('idOrdre')(transfer_data)

        transfer.account_id = origin.id
        transfer.account_label = Dict('libelleCompte')(account_data)
        transfer.account_iban = Dict('ibanCompte')(account_data)
        transfer.account_balance = origin.balance

        transfer.recipient_id = recipient.id
        transfer.recipient_label = Dict('libelleCompte')(recipient_data)
        transfer.recipient_iban = Dict('ibanCompte')(recipient_data)

        transfer.currency = Dict('montantTotalOrdre/codeDevise')(transfer_data)
        transfer.amount = CleanDecimal(Eval(
            lambda x, y: x * (10 ** -y),
            Dict('montantTotalOrdre/valeurMontant'),
            Dict('montantTotalOrdre/codeDecimalisation')
        ))(transfer_data)
        transfer.exec_date = Date(Dict('dateExecution'), dayfirst=True)(transfer_data)
        transfer.label = Dict('libelleClientOrdre')(transfer_data)

        return transfer
Ejemplo n.º 29
0
    def do_transfer(self, account, to, amount, reason=None):
        """
            Transfer the given amount of money from an account to another,
            tagging the transfer with the given reason.
        """
        # access the transfer page
        transfer_page_unreachable_message = u'Could not reach the transfer page.'
        self.home()
        if not self.page.is_accounts_list():
            raise TransferError(transfer_page_unreachable_message)

        operations_url = self.page.operations_page_url()

        self.location('https://%s%s' % (self.DOMAIN, operations_url))
        transfer_url = self.page.transfer_page_url()

        abs_transfer_url = 'https://%s%s' % (self.DOMAIN, transfer_url)
        self.location(abs_transfer_url)
        if not self.page.is_transfer_page():
            raise TransferError(transfer_page_unreachable_message)

        source_accounts = self.page.get_transfer_source_accounts()
        target_accounts = self.page.get_transfer_target_accounts()

        # check that the given source account can be used
        if not account in source_accounts.values():
            raise TransferError('You cannot use account %s as a source account.' % account)

        # check that the given source account can be used
        if not to in target_accounts.values():
            raise TransferError('You cannot use account %s as a target account.' % to)

        # separate euros from cents
        amount_euros = int(amount)
        amount_cents = int((amount * 100) - (amount_euros * 100))

        # let's circumvent https://github.com/jjlee/mechanize/issues/closed#issue/17
        # using http://wwwsearch.sourceforge.net/mechanize/faq.html#usage
        adjusted_response = self.response().get_data().replace('<br/>', '<br />')
        response = mechanize.make_response(adjusted_response, [('Content-Type', 'text/html')], abs_transfer_url, 200, 'OK')
        self.set_response(response)

        # fill the form
        self.select_form(nr=0)
        self['numCompteEmetteur']     = ['%s' % self.dict_find_value(source_accounts, account)]
        self['numCompteBeneficiaire'] = ['%s' % self.dict_find_value(target_accounts, to)]
        self['montantPartieEntiere']  = '%s'   % amount_euros
        self['montantPartieDecimale'] = '%02d' % amount_cents
        if reason != None:
            self['libelle'] = reason
        self.submit()

        # look for known errors
        content = unicode(self.response().get_data(), 'utf-8')
        insufficient_amount_message     = u'Montant insuffisant.'
        maximum_allowed_balance_message = u'Solde maximum autorisé dépassé.'

        if content.find(insufficient_amount_message) != -1:
            raise TransferError('The amount you tried to transfer is too low.')

        if content.find(maximum_allowed_balance_message) != -1:
            raise TransferError('The maximum allowed balance for the target account has been / would be reached.')

        # look for the known "all right" message
        ready_for_transfer_message = u'Vous allez effectuer un virement'
        if not content.find(ready_for_transfer_message):
            raise TransferError('The expected message "%s" was not found.' % ready_for_transfer_message)

        # submit the last form
        self.select_form(nr=0)
        submit_date = datetime.now()
        self.submit()

        # look for the known "everything went well" message
        content = unicode(self.response().get_data(), 'utf-8')
        transfer_ok_message = u'Vous venez d\'effectuer un virement du compte'
        if not content.find(transfer_ok_message):
            raise TransferError('The expected message "%s" was not found.' % transfer_ok_message)

        # We now have to return a Transfer object
        # the final page does not provide any transfer id, so we'll use the submit date
        transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
        transfer.amount = amount
        transfer.origin = account
        transfer.recipient = to
        transfer.date = submit_date
        return transfer
Ejemplo n.º 30
0
    def handle_response(self, account, recipient, amount, reason):
        self.check_errors()
        transfer_data = self.doc['data']['validationVirement']

        self.abort_if_unknown(transfer_data)

        if 'idBeneficiaire' in transfer_data and transfer_data[
                'idBeneficiaire'] is not None:
            assert transfer_data['idBeneficiaire'] == recipient.id
        elif 'ibanCompteCrediteur' in transfer_data and transfer_data[
                'ibanCompteCrediteur'] is not None:
            assert transfer_data['ibanCompteCrediteur'] == recipient.iban

        exec_date = Date(transfer_data['dateExecution']).date()
        today = datetime.today().date()
        if transfer_data['typeOperation'] == '1':
            assert exec_date == today
        else:
            assert exec_date > today

        transfer = Transfer()
        transfer.currency = transfer_data['devise']
        transfer.amount = Decimal(transfer_data['montantEuros'])
        transfer.account_iban = transfer_data['ibanCompteDebiteur']
        transfer.account_id = account.id
        try:
            transfer.recipient_iban = transfer_data[
                'ibanCompteCrediteur'] or recipient.iban
        except KeyError:
            # In last version, json contains a key 'idBeneficiaire' containing:
            # "idBeneficiaire" : "00003##00001####FR7610278123456789028070101",
            transfer.recipient_id = transfer_data['idBeneficiaire']
            transfer.recipient_iban = transfer.recipient_id.split(
                '#')[-1] or recipient.iban
        else:
            transfer.recipient_id = recipient.id
        transfer.exec_date = exec_date
        transfer.fees = Decimal(transfer_data['montantFrais'])
        transfer.label = transfer_data['motifVirement']

        transfer.account_label = account.label
        transfer.recipient_label = recipient.label
        transfer.id = transfer_data['reference']
        # This is true if a transfer with the same metadata has already been done recently
        transfer._doublon = transfer_data['doublon']
        transfer.account_balance = account.balance

        return transfer
Ejemplo n.º 31
0
 def create_transfer(self, account, recipient, transfer):
     transfer = Transfer()
     transfer.currency = FrenchTransaction.Currency('.//td[@headers="virement montant"]')(self.doc)
     transfer.amount = CleanDecimal('.//td[@headers="virement montant"]', replace_dots=True)(self.doc)
     transfer.account_iban = CleanText('//td[@headers="emetteur IBAN"]', replace=[(' ', '')])(self.doc)
     transfer.recipient_iban = CleanText('//td[@headers="beneficiaire IBAN"]', replace=[(' ','')])(self.doc)
     transfer.account_id = account.id
     transfer.recipient_id = recipient.id
     transfer.exec_date = Date(CleanText('.//td[@headers="virement date"]'), dayfirst=True)(self.doc)
     transfer.label = CleanText('.//td[@headers="virement motif"]')(self.doc)
     transfer.account_label = account.label
     transfer.recipient_label = recipient.label
     transfer._account = account
     transfer._recipient = recipient
     transfer.account_balance = account.balance
     return transfer
Ejemplo n.º 32
0
    def handle_response(self, account, recipient, amount, reason):
        tables_xpath = '//table[@id="table-confVrt" or @id="table-confDestinataire"]'

        # Summary is divided into 2 tables, we have to concat them
        # col_heads is a list of all header of the 2 tables (order is important)
        self.col_heads = [
            CleanText('.')(head)
            for head in self.doc.xpath(tables_xpath +
                                       '//td[@class="libColumn"]')
        ]
        # col_contents is a list of all content of the 2 tables (order is important)
        self.col_contents = [
            CleanText('.')(content)
            for content in self.doc.xpath(tables_xpath +
                                          '//td[@class="contentColumn"]')
        ]

        transfer = Transfer()

        transfer.currency = Currency().filter(
            self.get_element_by_name('Montant'))
        transfer.amount = CleanDecimal().filter(
            self.get_element_by_name('Montant'))

        date = Regexp(pattern=r'(\d+/\d+/\d+)').filter(
            self.get_element_by_name('Date du virement'))
        transfer.exec_date = Date(dayfirst=True).filter(date)

        account_label_id = self.get_element_by_name('Compte à débiter')
        transfer.account_id = (Regexp(
            pattern=r'(\d+)').filter(account_label_id))
        transfer.account_label = Regexp(
            pattern=r'([\w \.]+)').filter(account_label_id)
        # account iban is not in the summary page
        transfer.account_iban = account.iban

        transfer.recipient_id = recipient.id
        transfer.recipient_iban = self.get_element_by_name('IBAN').replace(
            ' ', '')
        transfer.recipient_label = self.get_element_by_name(
            'Nom du bénéficiaire')
        transfer.label = CleanText('//table[@id="table-confLibelle"]//p')(
            self.doc)

        return transfer
Ejemplo n.º 33
0
    def handle_response(self, account, recipient, amount, reason, exec_date):
        transfer = Transfer()

        transfer._account = account
        transfer.account_id = self.get_id_from_response('account')
        transfer.account_iban = account.iban
        transfer.account_label = account.label
        transfer.account_balance = account.balance
        assert account._transfer_id in CleanText(
            u'//div[div[@class="libelleChoix" and contains(text(), "Compte émetteur")]] \
            //div[@class="infoCompte" and not(@title)]', replace=[(' ', '')]
        )(self.doc)

        transfer._recipient = recipient
        transfer.recipient_id = self.get_id_from_response('recipient')
        transfer.recipient_iban = recipient.iban
        transfer.recipient_label = recipient.label
        assert recipient._transfer_id in CleanText(
            u'//div[div[@class="libelleChoix" and contains(text(), "Compte destinataire")]] \
            //div[@class="infoCompte" and not(@title)]', replace=[(' ', '')]
        )(self.doc)

        transfer.currency = FrenchTransaction.Currency('//div[@class="topBox"]/div[@class="montant"]')(self.doc)
        transfer.amount = CleanDecimal('//div[@class="topBox"]/div[@class="montant"]', replace_dots=True)(self.doc)
        transfer.exec_date = Date(
            Regexp(CleanText('//div[@class="topBox"]/div[@class="date"]'), r'(\d{2}\/\d{2}\/\d{4})'),
            dayfirst=True
        )(self.doc)
        transfer.label = reason
        assert reason in CleanText('//div[@class="motif"]')(self.doc)

        return transfer
Ejemplo n.º 34
0
    def do_transfer(self, account, to, amount, reason=None):
        """
            Transfer the given amount of money from an account to another,
            tagging the transfer with the given reason.
        """
        # access the transfer page
        transfer_page_unreachable_message = u'Could not reach the transfer page.'
        self.home()
        if not self.page.is_accounts_list():
            raise TransferError(transfer_page_unreachable_message)

        operations_url = self.page.operations_page_url()

        self.location('https://%s%s' % (self.DOMAIN, operations_url))
        transfer_url = self.page.transfer_page_url()

        abs_transfer_url = 'https://%s%s' % (self.DOMAIN, transfer_url)
        self.location(abs_transfer_url)
        if not self.page.is_transfer_page():
            raise TransferError(transfer_page_unreachable_message)

        source_accounts = self.page.get_transfer_source_accounts()
        target_accounts = self.page.get_transfer_target_accounts()

        # check that the given source account can be used
        if account not in source_accounts.values():
            raise TransferError(
                'You cannot use account %s as a source account.' % account)

        # check that the given source account can be used
        if to not in target_accounts.values():
            raise TransferError(
                'You cannot use account %s as a target account.' % to)

        # separate euros from cents
        amount_euros = int(amount)
        amount_cents = int((amount * 100) - (amount_euros * 100))

        # let's circumvent https://github.com/jjlee/mechanize/issues/closed#issue/17
        # using http://wwwsearch.sourceforge.net/mechanize/faq.html#usage
        adjusted_response = self.response().get_data().replace(
            '<br/>', '<br />')
        response = mechanize.make_response(adjusted_response,
                                           [('Content-Type', 'text/html')],
                                           abs_transfer_url, 200, 'OK')
        self.set_response(response)

        # fill the form
        self.select_form(nr=0)
        self['numCompteEmetteur'] = [
            '%s' % self.dict_find_value(source_accounts, account)
        ]
        self['numCompteBeneficiaire'] = [
            '%s' % self.dict_find_value(target_accounts, to)
        ]
        self['montantPartieEntiere'] = '%s' % amount_euros
        self['montantPartieDecimale'] = '%02d' % amount_cents
        if reason is not None:
            self['libelle'] = reason
        self.submit()

        # look for known errors
        content = unicode(self.response().get_data(), 'utf-8')
        insufficient_amount_message = u'Montant insuffisant.'
        maximum_allowed_balance_message = u'Solde maximum autorisé dépassé.'

        if content.find(insufficient_amount_message) != -1:
            raise TransferError('The amount you tried to transfer is too low.')

        if content.find(maximum_allowed_balance_message) != -1:
            raise TransferError(
                'The maximum allowed balance for the target account has been / would be reached.'
            )

        # look for the known "all right" message
        ready_for_transfer_message = u'Vous allez effectuer un virement'
        if not content.find(ready_for_transfer_message):
            raise TransferError('The expected message "%s" was not found.' %
                                ready_for_transfer_message)

        # submit the last form
        self.select_form(nr=0)
        submit_date = datetime.now()
        self.submit()

        # look for the known "everything went well" message
        content = unicode(self.response().get_data(), 'utf-8')
        transfer_ok_message = u'Vous venez d\'effectuer un virement du compte'
        if not content.find(transfer_ok_message):
            raise TransferError('The expected message "%s" was not found.' %
                                transfer_ok_message)

        # We now have to return a Transfer object
        # the final page does not provide any transfer id, so we'll use the submit date
        transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
        transfer.amount = amount
        transfer.origin = account
        transfer.recipient = to
        transfer.date = submit_date
        return transfer
Ejemplo n.º 35
0
    def handle_response(self, transfer):
        t = Transfer()
        t._space = transfer._space
        t._operation = transfer._operation
        t._token = transfer._token
        t._connection_id = transfer._connection_id

        t.label = Dict('transferComplementaryInformations1')(self.doc)
        t.exec_date = Date(Dict('dateVirement'), dayfirst=True)(self.doc)
        t.amount = CleanDecimal(Dict('amount'))(self.doc)
        t.currency = Dict('currencyCode')(self.doc)

        t.account_id = Dict('currentDebitAccountNumber')(self.doc)
        t.account_iban = Dict('currentDebitIbanCode')(self.doc)
        t.account_label = Dict('typeCompte')(self.doc)

        t.recipient_label = CleanText(Dict('currentCreditAccountName'))(
            self.doc)
        t.recipient_id = t.recipient_iban = Dict('currentCreditIbanCode')(
            self.doc)

        # Internal transfer
        if not Dict('isExternalTransfer')(self.doc):
            t.recipient_id = Dict('currentCreditAccountNumber')(self.doc)

        return t
Ejemplo n.º 36
0
    def handle_response(self, account, recipient, amount, reason):
        account_txt = CleanText('//form//dl/dt[span[contains(text(), "biter")]]/following::dd[1]', replace=[(' ', '')])(self.doc)
        recipient_txt = CleanText('//form//dl/dt[span[contains(text(), "diter")]]/following::dd[1]', replace=[(' ', '')])(self.doc)
        try:
            assert account.id in account_txt or ''.join(account.label.split()) == account_txt
            assert recipient.id in recipient_txt or ''.join(recipient.label.split()) == recipient_txt
        except AssertionError:
            raise TransferError('Something went wrong')
        r_amount =  CleanDecimal('//form//dl/dt[span[contains(text(), "Montant")]]/following::dd[1]', replace_dots=True)(self.doc)
        exec_date = Date(CleanText('//form//dl/dt[span[contains(text(), "Date")]]/following::dd[1]'), dayfirst=True)(self.doc)
        currency = FrenchTransaction.Currency('//form//dl/dt[span[contains(text(), "Montant")]]/following::dd[1]')(self.doc)

        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
Ejemplo n.º 37
0
    def handle_transfer(self, account, recipient, amount, reason, exec_date):
        transfer = Transfer()
        transfer.amount = CleanDecimal(Dict('amount'))(self.doc)
        transfer.currency = Currency(Dict('codeDevise'))(self.doc)
        transfer.label = reason

        if exec_date:
            transfer.exec_date = dt.date.fromtimestamp(int(Dict('date')(self.doc))//1000)

        transfer.account_id = account.id
        transfer.account_label = CleanText(Dict('debitAccountLabel'))(self.doc)
        transfer.account_balance = CleanDecimal(Dict('debitAccountBalance'))(self.doc)

        transfer.recipient_id = recipient.id
        transfer.recipient_iban = recipient.iban
        transfer.recipient_label = CleanText(Dict('creditAccountOwner'))(self.doc)

        return transfer
Ejemplo n.º 38
0
    def do_transfer(self, line):
        """
        transfer ACCOUNT [RECIPIENT AMOUNT [REASON]]

        Make a transfer beetwen two account
        - ACCOUNT    the source account
        - RECIPIENT  the recipient
        - AMOUNT     amount to transfer
        - REASON     reason of transfer

        If you give only the ACCOUNT parameter, it lists all the
        available recipients for this account.
        """
        id_from, id_to, amount, reason = self.parse_command_args(line, 4, 1)

        account = self.get_object(id_from, 'get_account', [])
        if not account:
            print('Error: account %s not found' % id_from, file=self.stderr)
            return 1

        if not id_to:
            self.objects = []
            self.set_formatter('table')
            self.set_formatter_header(u'Available recipients')

            self.start_format()
            for recipient in self.do('iter_transfer_recipients',
                                     account.id,
                                     backends=account.backend,
                                     caps=CapBankTransfer):
                self.cached_format(recipient)
            return 0

        id_to, backend_name_to = self.parse_id(id_to)

        if account.backend != backend_name_to:
            print("Transfer between different backends is not implemented",
                  file=self.stderr)
            return 4

        try:
            amount = Decimal(amount)
        except (TypeError, ValueError, InvalidOperation):
            print('Error: please give a decimal amount to transfer',
                  file=self.stderr)
            return 2

        exec_date = datetime.date.today()

        if self.interactive:
            # Try to find the recipient label. It can be missing from
            # recipients list, for example for banks which allow transfers to
            # arbitrary recipients.
            to = id_to
            for recipient in self.do('iter_transfer_recipients',
                                     account.id,
                                     backends=account.backend,
                                     caps=CapBankTransfer):
                if recipient.id == id_to:
                    to = recipient.label
                    break

            print('Amount: %s%s' % (amount, account.currency_text))
            print('From:   %s' % account.label)
            print('To:     %s' % to)
            print('Reason: %s' % (reason or ''))
            print('Date:   %s' % exec_date)
            if not self.ask('Are you sure to do this transfer?', default=True):
                return

        self.start_format()

        transfer = Transfer()
        transfer.account_id = account.id
        transfer.recipient_id = id_to
        transfer.amount = amount
        transfer.label = reason
        transfer.exec_date = exec_date

        next(iter(self.do('transfer', transfer, backends=account.backend)))
Ejemplo n.º 39
0
    def handle_response(self, account, recipient, amount, label, exec_date):
        summary_xpath = '//div[@id="as_verifVirement.do_"]//ul'

        transfer = Transfer()

        transfer_data = {
            account.id:
            CleanText(summary_xpath +
                      '/li[contains(text(), "Compte à débiter")]')(self.doc),
            recipient.id:
            CleanText(summary_xpath +
                      '/li[contains(text(), "Compte à créditer")]',
                      replace=[(' ', '')])(self.doc),
            recipient._recipient_name:
            CleanText(summary_xpath +
                      '/li[contains(text(), "Nom du bénéficiaire")]')(
                          self.doc),
            label:
            CleanText(summary_xpath + '/li[contains(text(), "Motif")]')(
                self.doc),
        }
        self.check_transfer_data(transfer_data)

        transfer.account_id = account.id
        transfer.account_label = account.label
        transfer.account_iban = account.iban

        transfer.recipient_id = recipient.id
        transfer.recipient_label = recipient.label
        transfer.recipient_iban = recipient.iban

        transfer.label = label
        transfer.currency = Currency(summary_xpath +
                                     '/li[contains(text(), "Montant")]')(
                                         self.doc)
        transfer.amount = CleanDecimal(
            Regexp(
                CleanText(summary_xpath + '/li[contains(text(), "Montant")]'),
                r'((\d+)\.?(\d+)?)'))(self.doc)
        transfer.exec_date = Date(Regexp(
            CleanText(summary_xpath +
                      '/li[contains(text(), "Date de virement")]'),
            r'(\d+/\d+/\d+)'),
                                  dayfirst=True)(self.doc)

        return transfer
Ejemplo n.º 40
0
    def do_transfer(self, account, to, amount, reason=None):
        """
            Transfer the given amount of money from an account to another,
            tagging the transfer with the given reason.
        """

        self.selenium_start()

        # access the transfer page

        transfer_page_unreachable_message = u'Could not reach the transfer page.'
        transfer_page_processerror_message = u'Error while processing the transfer.'
        #self._browser.get(self.absurl('/'))
        self.selenium_accounts_url = self._browser.current_url
        self.selenium_transfer_url = re.sub('act=([^&=]+)',
                                            'act=Virementssepa',
                                            self.selenium_accounts_url, 1)
        self._browser.get(self.selenium_transfer_url)

        try:
            element = WebDriverWait(self._browser, 3).until(
                EC.presence_of_element_located(
                    (By.XPATH, '//*[text() ="Compte bénéficiaire :"]')))
        except:
            self.selenium_finish()
            print(transfer_page_unreachable_message)
            raise

        # separate euros from cents
        amount_euros = int(amount)
        amount_cents = int((amount * 100) - (amount_euros * 100))

        try:
            element = WebDriverWait(self._browser, 3).until(
                EC.presence_of_element_located(
                    (By.XPATH, '//*[@name ="VIR_VIR1_FR3_LE"]')))
            element = WebDriverWait(self._browser, 3).until(
                EC.presence_of_element_located(
                    (By.XPATH, '//*[@name ="VIR_VIR1_FR3_LB"]')))
        except:
            self.selenium_finish()
            print(transfer_page_processerror_message)
            raise

        for option in Select(
                self._browser.find_element_by_name('VIR_VIR1_FR3_LE')).options:
            if account in option.text:
                Select(self._browser.find_element_by_name(
                    'VIR_VIR1_FR3_LE')).select_by_visible_text(option.text)

        for option in Select(
                self._browser.find_element_by_name('VIR_VIR1_FR3_LB')).options:
            if to in option.text:
                Select(self._browser.find_element_by_name(
                    'VIR_VIR1_FR3_LB')).select_by_visible_text(option.text)
        amount1 = self._browser.find_element_by_name('T3SEF_MTT_EURO')
        self._browser.execute_script(
            "arguments[0].value = '%s';" % amount_euros, amount1)
        amount2 = self._browser.find_element_by_name('T3SEF_MTT_CENT')
        self._browser.execute_script(
            "arguments[0].value = '%02d';" % amount_cents, amount2)

        #click on first step
        self._browser.execute_script("javascript:verif('Confirmer')")

        try:
            element = WebDriverWait(self._browser, 3).until(
                EC.presence_of_element_located(
                    (By.XPATH, '//*[@name ="VICrt_CDDOOR"]')))
        except:
            self.selenium_finish()
            print(transfer_page_processerror_message)
            raise

        reason_elm = self._browser.find_element_by_name('VICrt_CDDOOR')

        if not reason is None:
            self._browser.execute_script("arguments[0].value = '%s';" % reason,
                                         reason_elm)

        submit_date = datetime.now()

        self._browser.execute_script("javascript:verif('Confirmer')")

        try:
            element = WebDriverWait(self._browser, 3).until(
                EC.presence_of_element_located(
                    (By.XPATH, '//a[text() ="Confirmer"]')))
        except:
            self.selenium_finish()
            print(transfer_page_processerror_message)
            raise

        self._browser.execute_script("javascript:verif('Confirmer')")

        try:
            element = WebDriverWait(self._browser, 3).until(
                EC.presence_of_element_located(
                    (By.XPATH, '//a[text() ="Nouveau virement"]')))
        except:
            self.selenium_finish()
            print(transfer_page_processerror_message)
            raise

        # We now have to return a Transfer object
        # the final page does not provide any transfer id, so we'll use the submit date
        transfer = Transfer(submit_date.strftime('%Y%m%d%H%M%S'))
        transfer.amount = amount
        transfer.origin = account
        transfer.recipient = to
        transfer.date = submit_date
        self.selenium_finish()
        return transfer
Ejemplo n.º 41
0
 def create_transfer(self, account, recipient, transfer):
     transfer = Transfer()
     transfer.currency = FrenchTransaction.Currency(
         './/tr[td[contains(text(), "Montant")]]/td[not(@class)] | \
                                                     .//tr[th[contains(text(), "Montant")]]/td[not(@class)]'
     )(self.doc)
     transfer.amount = CleanDecimal(
         './/tr[td[contains(text(), "Montant")]]/td[not(@class)] | \
                                     .//tr[th[contains(text(), "Montant")]]/td[not(@class)]',
         replace_dots=True)(self.doc)
     transfer.account_iban = account.iban
     if recipient.category == u'Externe':
         for word in Upper(
                 CleanText(
                     u'.//tr[th[contains(text(), "Compte à créditer")]]/td[not(@class)]'
                 ))(self.doc).split():
             if is_iban_valid(word):
                 transfer.recipient_iban = word
                 break
         else:
             raise TransferError('Unable to find IBAN (original was %s)' %
                                 recipient.iban)
     else:
         transfer.recipient_iban = recipient.iban
     transfer.account_id = unicode(account.id)
     transfer.recipient_id = unicode(recipient.id)
     transfer.exec_date = Date(CleanText(
         './/tr[th[contains(text(), "En date du")]]/td[not(@class)]'),
                               dayfirst=True)(self.doc)
     transfer.label = CleanText(
         u'.//tr[td[contains(text(), "Motif de l\'opération")]]/td[not(@class)] | \
                                  .//tr[td[contains(text(), "Libellé")]]/td[not(@class)]'
     )(self.doc)
     transfer.account_label = account.label
     transfer.recipient_label = recipient.label
     transfer._account = account
     transfer._recipient = recipient
     transfer.account_balance = account.balance
     return transfer
Ejemplo n.º 42
0
    def _build_transfer(self, line):
        if self.interactive:
            id_from, id_to, amount, reason = self.parse_command_args(
                line, 4, 0)
        else:
            id_from, id_to, amount, reason = self.parse_command_args(
                line, 4, 3)

        missing = not bool(id_from and id_to and amount)

        if id_from:
            account = self.get_object(id_from, 'get_account', [])
            id_from = account.id
            if not account:
                print('Error: account %s not found' % id_from,
                      file=self.stderr)
                return
        else:
            with self.use_cmd_formatter('list'):
                self.do_ls('')
            id_from = self.ask('Transfer money from account', default='')
            if not id_from:
                return
            id_from, backend = self.parse_id(id_from)

            account = find_object(self.objects,
                                  fullid='%s@%s' % (id_from, backend))
            if not account:
                return
            id_from = account.id

        if id_to:
            id_to, backend_name_to = self.parse_id(id_to)
            if account.backend != backend_name_to:
                print("Transfer between different backends is not implemented",
                      file=self.stderr)
                return
            rcpts = self.do('iter_transfer_recipients',
                            id_from,
                            backends=account.backend)
            rcpt = find_object(rcpts, id=id_to)
        else:
            with self.use_cmd_formatter('recipients'):
                self.do_recipients(account.fullid)
            id_to = self.ask('Transfer money to recipient', default='')
            if not id_to:
                return
            id_to, backend = self.parse_id(id_to)

            rcpt = find_object(self.objects, fullid='%s@%s' % (id_to, backend))
            if not rcpt:
                return

        if not amount:
            amount = self.ask('Amount to transfer',
                              default='',
                              regexp=r'\d+(?:\.\d*)?')
        try:
            amount = Decimal(amount)
        except (TypeError, ValueError, InvalidOperation):
            print('Error: please give a decimal amount to transfer',
                  file=self.stderr)
            return
        if amount <= 0:
            print('Error: transfer amount must be strictly positive',
                  file=self.stderr)
            return

        if missing:
            reason = self.ask('Label of the transfer (seen by the recipient)',
                              default='')

        exec_date = datetime.date.today()

        transfer = Transfer()
        transfer.backend = account.backend
        transfer.account_id = account.id
        transfer.account_label = account.label
        transfer.account_iban = account.iban
        transfer.recipient_id = id_to
        if rcpt:
            # Try to find the recipient label. It can be missing from
            # recipients list, for example for banks which allow transfers to
            # arbitrary recipients.
            transfer.recipient_label = rcpt.label
            transfer.recipient_iban = rcpt.iban
        transfer.amount = amount
        transfer.label = reason or u''
        transfer.exec_date = exec_date

        return transfer
Ejemplo n.º 43
0
 def create_transfer(self, account, recipient, transfer):
     transfer = Transfer()
     transfer.currency = FrenchTransaction.Currency('.//tr[td[contains(text(), "Montant")]]/td[not(@class)] | \
                                                     .//tr[th[contains(text(), "Montant")]]/td[not(@class)]')(self.doc)
     transfer.amount = CleanDecimal('.//tr[td[contains(text(), "Montant")]]/td[not(@class)] | \
                                     .//tr[th[contains(text(), "Montant")]]/td[not(@class)]', replace_dots=True)(self.doc)
     transfer.account_iban = account.iban
     if recipient.category == u'Externe':
         for word in Upper(CleanText(u'.//tr[th[contains(text(), "Compte à créditer")]]/td[not(@class)]'))(self.doc).split():
             if is_iban_valid(word):
                 transfer.recipient_iban = word
                 break
         else:
             raise TransferError('Unable to find IBAN (original was %s)' % recipient.iban)
     else:
         transfer.recipient_iban = recipient.iban
     transfer.account_id = unicode(account.id)
     transfer.recipient_id = unicode(recipient.id)
     transfer.exec_date = Date(CleanText('.//tr[th[contains(text(), "En date du")]]/td[not(@class)]'), dayfirst=True)(self.doc)
     transfer.label = (CleanText(u'.//tr[td[contains(text(), "Motif de l\'opération")]]/td[not(@class)]')(self.doc) or
                      CleanText(u'.//tr[td[contains(text(), "Libellé")]]/td[not(@class)]')(self.doc) or
                      CleanText(u'.//tr[th[contains(text(), "Libellé")]]/td[not(@class)]')(self.doc))
     transfer.account_label = account.label
     transfer.recipient_label = recipient.label
     transfer._account = account
     transfer._recipient = recipient
     transfer.account_balance = account.balance
     return transfer
Ejemplo n.º 44
0
    def handle_response(self, recipient):
        json_response = self.doc['donnees']

        transfer = Transfer()
        transfer.id = json_response['idVirement']
        transfer.label = json_response['motif']
        transfer.amount = CleanDecimal.French(
            (CleanText(Dict('montantToDisplay'))))(json_response)
        transfer.currency = json_response['devise']
        transfer.exec_date = Date(Dict('dateExecution'),
                                  dayfirst=True)(json_response)

        transfer.account_id = Format('%s%s', Dict('codeGuichet'),
                                     Dict('numeroCompte'))(
                                         json_response['compteEmetteur'])
        transfer.account_iban = json_response['compteEmetteur']['iban']
        transfer.account_label = json_response['compteEmetteur'][
            'libelleToDisplay']

        assert recipient._json_id == json_response['compteBeneficiaire']['id']
        transfer.recipient_id = recipient.id
        transfer.recipient_iban = json_response['compteBeneficiaire']['iban']
        transfer.recipient_label = json_response['compteBeneficiaire'][
            'libelleToDisplay']

        return transfer
Ejemplo n.º 45
0
    def recap(self, origin, recipient, transfer):
        error = CleanText(u'//div[@id="transfer_form:moveMoneyDetailsBody"]//span[@class="error"]', default=None)(self.doc) or \
                CleanText(u'//p[contains(text(), "Nous sommes désolés. Le solde de votre compte ne doit pas être inférieur au montant de votre découvert autorisé. Veuillez saisir un montant inférieur.")]', default=None)(self.doc)
        if error:
           raise TransferInvalidAmount(message=error)

        t = Transfer()
        t.label = transfer.label
        assert transfer.amount == CleanDecimal('//div[@id="transferSummary"]/div[@id="virementLabel"]\
        //label[@class="digits positive"]', replace_dots=True)(self.doc)
        t.amount = transfer.amount
        t.currency = FrenchTransaction.Currency('//div[@id="transferSummary"]/div[@id="virementLabel"]\
        //label[@class="digits positive"]')(self.doc)

        assert origin.label == CleanText('//div[@id="transferSummary"]/div[has-class("debit")]//span[@class="title"]')(self.doc)
        assert origin.balance == CleanDecimal('//div[@id="transferSummary"]/div[has-class("debit")]\
        //label[@class="digits positive"]', replace_dots=True)(self.doc)
        t.account_balance = origin.balance
        t.account_label = origin.label
        t.account_iban = origin.iban
        t.account_id = origin.id

        assert recipient.label == CleanText('//div[@id="transferSummary"]/div[has-class("credit")]//span[@class="title"]')(self.doc)
        t.recipient_label = recipient.label
        t.recipient_iban = recipient.iban
        t.recipient_id = recipient.id

        t.exec_date = parse_french_date(CleanText('//p[has-class("exec-date")]', children=False,
                replace=[('le', ''), (u'exécuté', ''), ('demain', ''), ('(', ''), (')', ''),
                ("aujourd'hui", '')])(self.doc)).date()

        return t
Ejemplo n.º 46
0
 def create_transfer(self, account, recipient, amount, reason):
     transfer = Transfer()
     transfer.currency = FrenchTransaction.Currency('//div[@class="topBox"]/div[@class="montant"]')(self.doc)
     transfer.amount = CleanDecimal('//div[@class="topBox"]/div[@class="montant"]', replace_dots=True)(self.doc)
     transfer.account_iban = account.iban
     transfer.recipient_iban = recipient.iban
     transfer.account_id = account.id
     transfer.recipient_id = recipient.id
     transfer.exec_date = date.today()
     transfer.label = reason
     transfer.account_label = account.label
     transfer.recipient_label = recipient.label
     transfer._account = account
     transfer._recipient = recipient
     transfer.account_balance = account.balance
     return transfer
Ejemplo n.º 47
0
    def handle_response(self, recipient):
        json_response = self.doc['donnees']

        transfer = Transfer()
        transfer.id = json_response['idVirement']
        transfer.label = json_response['motif']
        transfer.amount = CleanDecimal.French((CleanText(Dict('montantToDisplay'))))(json_response)
        transfer.currency = json_response['devise']
        transfer.exec_date = Date(Dict('dateExecution'), dayfirst=True)(json_response)

        transfer.account_id = Format('%s%s', Dict('codeGuichet'), Dict('numeroCompte'))(json_response['compteEmetteur'])
        transfer.account_iban = json_response['compteEmetteur']['iban']
        transfer.account_label = json_response['compteEmetteur']['libelleToDisplay']

        assert recipient._json_id == json_response['compteBeneficiaire']['id']
        transfer.recipient_id = recipient.id
        transfer.recipient_iban = json_response['compteBeneficiaire']['iban']
        transfer.recipient_label = json_response['compteBeneficiaire']['libelleToDisplay']

        return transfer
Ejemplo n.º 48
0
    def get_transfer(self):
        transfer = Transfer()

        # FIXME all will probably fail if an account has a user-chosen label with "IBAN :" or "n°"

        amount_xpath = '//fieldset//p[has-class("montant")]'
        transfer.amount = CleanDecimal.French(amount_xpath)(self.doc)
        transfer.currency = CleanCurrency(amount_xpath)(self.doc)

        if self.is_sent():
            transfer.account_id = Regexp(CleanText('//p[@class="nomarge"][span[contains(text(),'
                                                   '"Compte émetteur")]]/text()'),
                                         r'n°(\d+)')(self.doc)

            base = CleanText('//fieldset//table[.//span[contains(text(), "Compte bénéficiaire")]]'
                             '//td[contains(text(),"n°") or contains(text(),"IBAN :")]//text()', newlines=False)(self.doc)
            transfer.recipient_id = Regexp(None, r'IBAN : ([^\n]+)|n°(\d+)').filter(base)
            transfer.recipient_id = transfer.recipient_id.replace(' ', '')
            if 'IBAN' in base:
                transfer.recipient_iban = transfer.recipient_id

            transfer.exec_date = MyDate(CleanText('//p[@class="nomarge"][span[contains(text(), "Date de l\'ordre")]]/text()'))(self.doc)
        else:
            transfer.account_id = Regexp(CleanText('//fieldset[.//h3[contains(text(), "Compte émetteur")]]//p'),
                                         r'n°(\d+)')(self.doc)

            base = CleanText('//fieldset[.//h3[contains(text(), "Compte bénéficiaire")]]//text()',
                             newlines=False)(self.doc)
            transfer.recipient_id = Regexp(None, r'IBAN : ([^\n]+)|n°(\d+)').filter(base)
            transfer.recipient_id = transfer.recipient_id.replace(' ', '')
            if 'IBAN' in base:
                transfer.recipient_iban = transfer.recipient_id

            transfer.exec_date = MyDate(CleanText('//fieldset//p[span[contains(text(), "Virement unique le :")]]/text()'))(self.doc)

        transfer.label = CleanText('//fieldset//p[span[contains(text(), "Référence opération")]]')(self.doc)
        transfer.label = re.sub(r'^Référence opération(?:\s*):', '', transfer.label).strip()

        return transfer
Ejemplo n.º 49
0
    def recap(self, origin, recipient, transfer):
        t = Transfer()
        t.label = transfer.label
        assert transfer.amount == CleanDecimal('//div[@id="transferSummary"]/div[@id="virementLabel"]\
        //label[@class="digits positive"]', replace_dots=True)(self.doc)
        t.amount = transfer.amount
        t.currency = FrenchTransaction.Currency('//div[@id="transferSummary"]/div[@id="virementLabel"]\
        //label[@class="digits positive"]')(self.doc)

        assert origin.label == CleanText('//div[@id="transferSummary"]/div[has-class("debit")]//span[@class="title"]')(self.doc)
        assert origin.balance == CleanDecimal('//div[@id="transferSummary"]/div[has-class("debit")]\
        //label[@class="digits positive"]', replace_dots=True)(self.doc)
        t.account_balance = origin.balance
        t.account_label = origin.label
        t.account_iban = origin.iban
        t.account_id = origin.id

        assert recipient.label == CleanText('//div[@id="transferSummary"]/div[has-class("credit")]//span[@class="title"]')(self.doc)
        t.recipient_label = recipient.label
        t.recipient_iban = recipient.iban
        t.recipient_id = recipient.id

        t.exec_date = parse_french_date(CleanText('//p[has-class("exec-date")]', children=False,
                replace=[('le', ''), (u'exécuté', ''), ('demain', ''), ('(', ''), (')', '')])(self.doc)).date()
        return t