1
0
helpix/test_api.py
2024-12-02 13:56:28 -03:00

55 lines
1.5 KiB
Python

import requests
from dotenv import load_dotenv
from os import getenv
# Load environment variables from .env file
load_dotenv()
url = "https://sandbox.openfinance.celcoin.dev/v5/token"
data = {
"client_id": getenv("CLIENT_ID"),
"grant_type": "client_credentials",
"client_secret": getenv("CLIENT_SECRET"),
}
response = requests.post(url, data=data)
token = response.json()["access_token"]
print("token:", token)
url = "https://sandbox.openfinance.celcoin.dev/pix/v1/payment/endToEnd"
payload = { "dpp": "2024-11-12" }
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": "Bearer " + token
}
response = requests.post(url, json=payload, headers=headers)
e2ee = response.json()["body"]["endToEndId"]
print("e2e:", e2ee)
# alternate DICT method for obtaining e2ee
url = "https://sandbox.openfinance.celcoin.dev/pix/v1/dict/v2/key"
payload = {
"payerId": "13935893000370",
"key": "93981962-9505-474d-9899-dcb0be3d40c4"
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": "Bearer " + token
}
#response = requests.post(url, json=payload, headers=headers)
#print(response.text)
url = "https://sandbox.openfinance.celcoin.dev/pix/v1/payment"
payload = { "initiationType": "DICT" }
# headers = {
# "accept": "application/json",
# "content-type": "application/json",
# "authorization": "Bearer $beare"
# }
# response = requests.post(url, json=payload, headers=headers)
# print(response.text)