def donate_value(message):
try:
valor = float(message.text.replace(',', '.'))
access_token = get_access_token()
body = {
'calendario': {
'expiracao': 3600
},
'devedor': {
'cpf': '12345678909',
'nome': 'Zhou Xinyu'
},
'valor': {
'original': f'{valor:.2f}'
},
'chave': '472d809f-633a',
'solicitacaoPagador': 'Cobrança dos serviços prestados.'
}
response = efi.pix_create_immediate_charge(body=body, access_token=access_token)
print(response)
if 'loc' in response and 'id' in response['loc']:
loc_id = response['loc']['id']
qrcode_response = requests.get(f'host/v2/loc/{loc_id}/qrcode', headers={'Authorization': f'Bearer {access_token}'}).json()
print(qrcode_response)
if 'qrcode' in qrcode_response and 'imagemQrcode' in qrcode_response:
# Enviar o código do QR no chat
client.send_message(cid, f'Código PIX: {qrcode_response["qrcode"]}')
image_data = base64.b64decode(qrcode_response['imagemQrcode'].replace('data:image/png;base64,', ''))
img = Image.open(BytesIO(image_data))
img_path = 'qrCodeImage.png'
img.save(img_path, 'PNG')
with open(img_path, 'rb') as photo:
client.send_photo(cid, photo)
except Exception as e:
print(f'Erro: {str(e)}')
try:
valor = float(message.text.replace(',', '.'))
access_token = get_access_token()
body = {
'calendario': {
'expiracao': 3600
},
'devedor': {
'cpf': '12345678909',
'nome': 'Zhou Xinyu'
},
'valor': {
'original': f'{valor:.2f}'
},
'chave': '472d809f-633a',
'solicitacaoPagador': 'Cobrança dos serviços prestados.'
}
response = efi.pix_create_immediate_charge(body=body, access_token=access_token)
print(response)
if 'loc' in response and 'id' in response['loc']:
loc_id = response['loc']['id']
qrcode_response = requests.get(f'host/v2/loc/{loc_id}/qrcode', headers={'Authorization': f'Bearer {access_token}'}).json()
print(qrcode_response)
if 'qrcode' in qrcode_response and 'imagemQrcode' in qrcode_response:
# Enviar o código do QR no chat
client.send_message(cid, f'Código PIX: {qrcode_response["qrcode"]}')
image_data = base64.b64decode(qrcode_response['imagemQrcode'].replace('data:image/png;base64,', ''))
img = Image.open(BytesIO(image_data))
img_path = 'qrCodeImage.png'
img.save(img_path, 'PNG')
with open(img_path, 'rb') as photo:
client.send_photo(cid, photo)
except Exception as e:
print(f'Erro: {str(e)}')