Exemplo n.º 1
0
    def generate_boleto(self, service, order):
        with transaction.atomic():
            stored_boleto = super(CecredBoletoBehaviorComponent, self).generate_boleto(service, order)

            from python_boleto.cecred import CecredBoleto
            boleto_data = self.get_context_data(service, order)
            boleto_data['num_sequencial'] = self.next_sequence()

            boleto_cecred = CecredBoleto(**boleto_data)

            # gera e salva a linha digitavel e o codigo de barras
            stored_boleto.number_line = boleto_cecred.linha_digitavel
            stored_boleto.bar_code = boleto_cecred.codigo_barras
            stored_boleto.nosso_numero = boleto_cecred.nosso_numero
            stored_boleto.info = boleto_cecred.__dict__
            stored_boleto.full_clean()
            stored_boleto.save(update_fields=['nosso_numero', 'number_line', 'bar_code', 'info'])

            try:
                boleto_cecred.validate()
            except Exception as exc:
                logger.exception("O boleto gerado não é valido: {0}".format(exc))
                order.add_log_entry((_("O boleto gerado não é válido: {0}")).format(str(exc)), kind=LogEntryKind.ERROR)

            return stored_boleto
Exemplo n.º 2
0
    def generate_boleto(self, service, order):
        with transaction.atomic():
            stored_boleto = super(CecredBoletoBehaviorComponent,
                                  self).generate_boleto(service, order)

            from python_boleto.cecred import CecredBoleto
            boleto_data = self.get_context_data(service, order)
            boleto_data['num_sequencial'] = self.next_sequence()

            boleto_cecred = CecredBoleto(**boleto_data)

            # gera e salva a linha digitavel e o codigo de barras
            stored_boleto.number_line = boleto_cecred.linha_digitavel
            stored_boleto.bar_code = boleto_cecred.codigo_barras
            stored_boleto.nosso_numero = boleto_cecred.nosso_numero
            stored_boleto.info = boleto_cecred.__dict__
            stored_boleto.full_clean()
            stored_boleto.save(update_fields=[
                'nosso_numero', 'number_line', 'bar_code', 'info'
            ])

            try:
                boleto_cecred.validate()
            except Exception as exc:
                logger.exception(
                    "O boleto gerado não é valido: {0}".format(exc))
                order.add_log_entry(
                    (_("O boleto gerado não é válido: {0}")).format(str(exc)),
                    kind=LogEntryKind.ERROR)

            return stored_boleto
Exemplo n.º 3
0
    def html(self):
        """ Retrieves the rendered HTML for the StoredBoleto """

        html = ''

        # se for CECRED..
        if self.bank_service == BankService.CECRED:
            from python_boleto.cecred import CecredBoleto
            boleto = CecredBoleto(**self.info)
            boleto.validate()
            html = boleto.export_html()

        return html
Exemplo n.º 4
0
    def html(self):
        """ Retrieves the rendered HTML for the StoredBoleto """

        html = ''

        # se for CECRED..
        if self.bank_service == BankService.CECRED:
            from python_boleto.cecred import CecredBoleto
            boleto = CecredBoleto(**self.info)
            boleto.validate()
            html = boleto.export_html()

        return html
Exemplo n.º 5
0
def test_validate():
    cecred = CecredBoleto()
    cecred.num_sequencial = 1
    cecred.vencimento = datetime.date.today()

    with pytest.raises(ValueError) as excinfo:
        cecred.validate()
    assert "convenio" in str(excinfo)

    cecred.convenio = '123'
    cecred.validate()
Exemplo n.º 6
0
def test_linha_digitavel():
    # Dados obtidos do boleto do manual da Cecred
    cecred = CecredBoleto()
    cecred.vencimento = datetime.date(2015, 5, 25)
    cecred.valor_documento = Decimal(1.00)
    cecred.convenio = '010120'
    cecred.conta_corrente = '03571572'
    cecred.num_sequencial = 1
    cecred.carteira = '1'
    assert cecred.linha_digitavel == "08590.10126 00357.157205 00000.001016 3 64390000000100"
Exemplo n.º 7
0
def test_validate():
    cecred = CecredBoleto()
    cecred.num_sequencial = 1
    cecred.vencimento = datetime.date.today()

    with pytest.raises(ValueError) as excinfo:
        cecred.validate()
    assert "convenio" in str(excinfo)

    cecred.convenio = '123'
    cecred.validate()
Exemplo n.º 8
0
def test_codigo_barras():
    # Dados obtidos do boleto do manual da Cecred
    # Lido representação do código de barras através da imagem
    cecred = CecredBoleto()
    cecred.vencimento = datetime.date(2015, 5, 25)
    cecred.valor_documento = Decimal(1.00)
    cecred.convenio = '010120'
    cecred.conta_corrente = '03571572'
    cecred.num_sequencial = 1
    cecred.carteira = '1'
    assert cecred.codigo_barras == "08593643900000001000101200357157200000000101"
    assert cecred.codigo_barras_dv == "3"
Exemplo n.º 9
0
def test_linha_digitavel():
    # Dados obtidos do boleto do manual da Cecred
    cecred = CecredBoleto()
    cecred.vencimento = datetime.date(2015, 5, 25)
    cecred.valor_documento = Decimal(1.00)
    cecred.convenio = '010120'
    cecred.conta_corrente = '03571572'
    cecred.num_sequencial = 1
    cecred.carteira = '1'
    assert cecred.linha_digitavel == "08590.10126 00357.157205 00000.001016 3 64390000000100"
Exemplo n.º 10
0
def test_codigo_barras():
    # Dados obtidos do boleto do manual da Cecred
    # Lido representação do código de barras através da imagem
    cecred = CecredBoleto()
    cecred.vencimento = datetime.date(2015, 5, 25)
    cecred.valor_documento = Decimal(1.00)
    cecred.convenio = '010120'
    cecred.conta_corrente = '03571572'
    cecred.num_sequencial = 1
    cecred.carteira = '1'
    assert cecred.codigo_barras == "08593643900000001000101200357157200000000101"
    assert cecred.codigo_barras_dv == "3"
Exemplo n.º 11
0
def test_fator_vencimento():
    cecred = CecredBoleto()

    # dentro do primeiro intervalo
    cecred.vencimento = datetime.date(2000, 7, 3)
    assert cecred.fator_vencimento == 1000
    cecred.vencimento = datetime.date(2000, 7, 4)
    assert cecred.fator_vencimento == 1001
    cecred.vencimento = datetime.date(2025, 2, 21)
    assert cecred.fator_vencimento == 9999

    # dentro do segundo intervalo
    cecred.vencimento = datetime.date(2025, 2, 22)
    assert cecred.fator_vencimento == 1000
    cecred.vencimento = datetime.date(2025, 2, 23)
    assert cecred.fator_vencimento == 1001

    # data muito baixa
    cecred.vencimento = datetime.date(1, 1, 1)
    assert cecred.fator_vencimento == 0

    # data muito alta
    cecred.vencimento = datetime.date(8978, 1, 1)
    assert cecred.fator_vencimento == 9999
Exemplo n.º 12
0
def test_fator_vencimento():
    cecred = CecredBoleto()

    # dentro do primeiro intervalo
    cecred.vencimento = datetime.date(2000, 7, 3)
    assert cecred.fator_vencimento == 1000
    cecred.vencimento = datetime.date(2000, 7, 4)
    assert cecred.fator_vencimento == 1001
    cecred.vencimento = datetime.date(2025, 2, 21)
    assert cecred.fator_vencimento == 9999

    # dentro do segundo intervalo
    cecred.vencimento = datetime.date(2025, 2, 22)
    assert cecred.fator_vencimento == 1000
    cecred.vencimento = datetime.date(2025, 2, 23)
    assert cecred.fator_vencimento == 1001

    # data muito baixa
    cecred.vencimento = datetime.date(1, 1, 1)
    assert cecred.fator_vencimento == 0

    # data muito alta
    cecred.vencimento = datetime.date(8978, 1, 1)
    assert cecred.fator_vencimento == 9999
Exemplo n.º 13
0
def test_boleto_cecred_success():
    """
    Usuário faz a compra e seleciona boleto como forma de pagamento (3 vezes seguidas)
    Boleto CECRED configurado
    """

    initialize()

    # Create methods
    shipping_method = get_default_shipping_method()
    processor = get_payment_provider()
    assert isinstance(processor, BoletoPaymentProcessor)
    choices = processor.get_service_choices()
    assert len(choices) == 1

    payment_method = processor.create_service(
        BankService.CECRED.value,
        identifier="cecred",
        shop=get_default_shop(),
        name="boleto cecred",
        enabled=True,
        tax_class=get_default_tax_class())

    # Configura de acordo
    behavior_component = payment_method.behavior_components.first()
    behavior_component.local_pagamento = "a simple test"
    behavior_component.cedente = "a simple user"
    behavior_component.prazo_vencimento = 4
    behavior_component.instrucoes = ["line1", "line2"]
    behavior_component.especie_doc = DocumentType.DM
    behavior_component.layout = 'v06'
    behavior_component.agencia = '123431'
    behavior_component.conta = '6427364732'
    behavior_component.convenio = '123456'
    behavior_component.carteira = '12'
    behavior_component.save()


    for ix in range(3):

        c = SmartClient()
        default_product = get_default_product()

        basket_path = reverse("shuup:basket")
        add_to_basket_resp = c.post(basket_path, data={
            "command": "add",
            "product_id": default_product.pk,
            "quantity": 1,
            "supplier": get_default_supplier().pk
        })
        assert add_to_basket_resp.status_code < 400


        # Resolve paths
        addresses_path = reverse("shuup:checkout", kwargs={"phase": "addresses"})
        methods_path = reverse("shuup:checkout", kwargs={"phase": "methods"})
        confirm_path = reverse("shuup:checkout", kwargs={"phase": "confirm"})


        # Phase: Addresses
        addresses_soup = c.soup(addresses_path)
        inputs = fill_address_inputs(addresses_soup, with_company=False)
        response = c.post(addresses_path, data=inputs)
        assert response.status_code == 302, "Address phase should redirect forth"
        assert response.url.endswith(methods_path)

        # Phase: Methods
        assert Order.objects.filter(payment_method=payment_method).count() == ix
        response = c.post(
            methods_path,
            data={
                "payment_method": payment_method.pk,
                "shipping_method": shipping_method.pk
            }
        )

        assert response.status_code == 302, "Methods phase should redirect forth"
        assert response.url.endswith(confirm_path)
        response = c.get(confirm_path)
        assert response.status_code == 200

        # Phase: Confirm
        assert Order.objects.count() == ix
        confirm_soup = c.soup(confirm_path)
        response = c.post(confirm_path, data=extract_form_fields(confirm_soup))
        assert response.status_code == 302, "Confirm should redirect forth"

        assert Order.objects.count() == ix+1
        order = Order.objects.filter(payment_method=payment_method).first()
        assert order.payment_status == PaymentStatus.NOT_PAID

        process_payment_path = reverse("shuup:order_process_payment", kwargs={"pk": order.pk, "key": order.key})
        process_payment_return_path = reverse("shuup:order_process_payment_return",kwargs={"pk": order.pk, "key": order.key})
        order_complete_path = reverse("shuup:order_complete",kwargs={"pk": order.pk, "key": order.key})

        assert response.url.endswith(process_payment_path), ("Confirm should have redirected to payment page")

        response = c.get(process_payment_path)
        assert response.status_code == 302, "Payment page should redirect forth"
        assert response.url.endswith(process_payment_return_path)

        response = c.get(process_payment_return_path)
        assert response.status_code == 302, "Payment return should redirect forth"
        assert response.url.endswith(order_complete_path)

        order.refresh_from_db()
        assert order.payment_status == PaymentStatus.NOT_PAID

        from python_boleto.cecred import CecredBoleto
        bcecred = CecredBoleto(**order.boleto.info)
        bcecred.validate()
        assert len(order.boleto.html) > 0

        # "visualiza o boleto"
        view_boleto_path = reverse("shuup:view_boleto", kwargs={"order_pk": order.pk, "order_key": order.key})
        response = c.get(view_boleto_path)
        assert HttpResponse(order.boleto.html).content == response.content
Exemplo n.º 14
0
def test_nosso_numero():
    cecred = CecredBoleto()
    cecred.num_sequencial = 342
    cecred.conta_corrente = '7891'
    assert cecred.nosso_numero == "00007891000000342"
Exemplo n.º 15
0
def test_instantiate():
    cecred = CecredBoleto(**{'convenio': '123'})
    assert cecred.convenio == '123'
Exemplo n.º 16
0
def test_nosso_numero():
    cecred = CecredBoleto()
    cecred.num_sequencial = 342
    cecred.conta_corrente = '7891'
    assert cecred.nosso_numero == "00007891000000342"