Skip to content

Commit fe2285e

Browse files
committed
Merge branch 'feat/update-project'
2 parents 473aa89 + 79d6e8d commit fe2285e

8 files changed

Lines changed: 371 additions & 118 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Python Pix
33

44
[![pypi](https://img.shields.io/pypi/v/pypix.svg)](https://pypi.org/project/pypix/)
55
[![Build Status](https://travis-ci.com/dyohan9/python-pix.svg?branch=master)](https://travis-ci.com/dyohan9/python-pix)
6-
[![Python Version](https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8-blue.svg)](https://www.python.org/)
6+
[![Python Version](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue.svg)](https://www.python.org/)
77
[![License GPL-3.0](https://img.shields.io/badge/license-%20GPL--3.0-yellow.svg)](https://github.com/bothub-it/bothub-engine/blob/master/LICENSE)
88

99

@@ -18,11 +18,11 @@ You can install using [pip](https://pip.pypa.io/en/stable/):
1818

1919
### Supported Python Versions
2020

21-
Python \>= 3.6
21+
Python >= 3.9
2222

2323
### Deprecated Python Versions
2424

25-
Python == 2.7. Python 2.7 support will be removed on January 1, 2020.
25+
Python < 3.9
2626

2727
Current Maintainers
2828
-------------------

examples/example_python39.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Exemplo de uso da biblioteca pypix com Python 3.9+
5+
Demonstra as funcionalidades principais da biblioteca com recursos modernos do Python
6+
"""
7+
from pypix import Pix
8+
from dataclasses import dataclass
9+
from typing import Optional
10+
11+
12+
@dataclass
13+
class PixPayment:
14+
"""Classe de exemplo usando dataclass do Python 3.7+"""
15+
key: str
16+
description: Optional[str] = None
17+
amount: Optional[float] = None
18+
merchant_name: str = ""
19+
merchant_city: str = ""
20+
txid: Optional[str] = None
21+
22+
23+
def create_pix_from_dataclass(payment: PixPayment) -> Pix:
24+
"""Cria um objeto Pix a partir de um dataclass"""
25+
pix = Pix()
26+
pix.set_pixkey(payment.key)
27+
28+
if payment.description:
29+
pix.set_description(payment.description)
30+
31+
if payment.amount is not None:
32+
pix.set_amount(payment.amount)
33+
34+
pix.set_merchant_name(payment.merchant_name)
35+
pix.set_merchant_city(payment.merchant_city)
36+
37+
if payment.txid:
38+
pix.set_txid(payment.txid)
39+
40+
return pix
41+
42+
43+
def main():
44+
"""Função principal"""
45+
# Exemplo usando dataclass (recurso do Python 3.7+)
46+
payment = PixPayment(
47+
key="10000000000",
48+
description="Pagamento via Python 3.9+",
49+
amount=150.75,
50+
merchant_name="EMPRESA MODERNA LTDA",
51+
merchant_city="SAO PAULO",
52+
txid="Cafe"
53+
)
54+
55+
pix = create_pix_from_dataclass(payment)
56+
print("QR Code Pix (usando dataclass):")
57+
print(pix)
58+
print("\n")
59+
60+
# Exemplo com type hints (melhorado no Python 3.9+)
61+
print("Exemplo com caracteres especiais (serão sanitizados):")
62+
pix2 = Pix()
63+
pix2.set_pixkey("12345678910")
64+
pix2.set_description("Café & Açaí") # Caracteres especiais serão sanitizados
65+
pix2.set_amount(25.99)
66+
pix2.set_merchant_name("João da Silva")
67+
pix2.set_merchant_city("FLORIANÓPOLIS")
68+
pix2.set_txid("cafe2023")
69+
print(pix2)
70+
71+
# Demonstração de arredondamento correto
72+
print("\nDemonstração de arredondamento:")
73+
pix3 = Pix()
74+
pix3.set_pixkey("11122233344")
75+
pix3.set_merchant_name("TESTE ARREDONDAMENTO")
76+
pix3.set_merchant_city("BRASILIA")
77+
78+
# Valores com diferentes casas decimais
79+
values = [10.555, 99.995, 0.001, 0.009]
80+
for value in values:
81+
pix3.set_amount(value)
82+
print(f"Original: {value} -> Formatado: {pix3.amount}")
83+
84+
85+
if __name__ == "__main__":
86+
main()

examples/sample.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from pypix import Pix
22

3+
# Exemplo similar ao do Bradesco
34
pix = Pix()
4-
pix.set_pixkey('12345678910')
5-
pix.set_description('Pagamento')
6-
pix.set_amount(500.00)
7-
pix.set_merchant_name('Daniel Yohan')
8-
pix.set_merchant_city('MACEIO')
9-
pix.set_txid('Aquele Lanche')
5+
pix.set_pixkey('08888888888')
6+
pix.set_description('Mensagem ao pagador')
7+
pix.set_amount(10.00)
8+
pix.set_merchant_name('Nome')
9+
pix.set_merchant_city('Cidade')
10+
pix.set_txid('Identificador')
11+
print("QR Code Pix:")
1012
print(pix)
13+
print("\n")

0 commit comments

Comments
 (0)