Pular para conteúdo

Criando uma cobrança PIX

Você pode criar, consultar e simular pagamentos via Pix diretamente pelo SDK da AbacatePay.


1. Criando um Pix QR Code

Você pode criar um Pix QR Code informando o valor, dados do cliente e uma descrição opcional.

from abacatepay import AbacatePay

client = AbacatePay("<sua chave de API>")
ONE_MINUTE = 60

pix_qr = client.pixQrCode.create(
    amount=500_00,  # (1)
    description="Assinatura mensal",
    expires_in=ONE_MINUTE,  # (2)
    customer={  # (3)
        "name": "Maria Silva",
        "email": "maria@email.com",
        "cellphone": "(11) 90000-0000",
        "tax_id": "123.456.789-00"
    }
)

print(pix_qr.status)
  1. O valor é em centavos (ex: 500_00 = R$ 500,00).
  2. O campo expires_in é opcional (em segundos). Ex: 600 = 10 minutos.
  3. Você pode passar o cliente como dict ou CustomerMetadata.

Referência para o método create

Create a new Pix QR Code.

Parameters:

Name Type Description Default
amount int

The amount to be paid in cents.

required
expires_in int

The expiration time in seconds. Defaults to None.

required
description str

A description for the Pix QR Code. Defaults to None.

required
customer CustomerMetadata | dict

Customer information. Defaults to None.

required

Returns: PixQrCode: The created Pix QR Code object.

Source code in abacatepay/pixQrCode/client.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def create(self, data: Union[PixQrCodeIn, dict], **kwargs) -> PixQrCode:
  """
  Create a new Pix QR Code.

  Args:
      amount (int): The amount to be paid in cents.
      expires_in (int, optional): The expiration time in seconds. Defaults to None.
      description (str, optional): A description for the Pix QR Code. Defaults to None.
      customer (CustomerMetadata | dict, optional): Customer information. Defaults to None.
  Returns:
      PixQrCode: The created Pix QR Code object.
  """
  json_data = prepare_data(data or kwargs, PixQrCodeIn)
  logger.debug('Creating Pix QR Code: %s', json_data)

  response = self._request(
      f"{BASE_URL}/pixQrCode/create",
      method="POST",
      json=json_data,
  )
  logger.debug('Pix QR Code created successfully: %s', response.json())
  return PixQrCode.model_validate(response.json()["data"])
O objeto PixQrCode

Bases: BaseModel

Source code in abacatepay/pixQrCode/models.py
 6
 7
 8
 9
10
11
12
13
14
15
16
class PixQrCode(BaseModel):
  id: str = Field(..., description="Unique identifier of the Pix QRCode.", example="pix_char_123456")
  amount: int = Field(..., description="Amount to be paid.", example=100)
  status: PIX_QR_CODE_STATUS = Field(..., description="Information about the status of the Pix QRCode. Options: PENDING, EXPIRED, CANCELLED, PAID, REFUNDED", example="PENDING")
  dev_mode: bool = Field(..., description="Environment in which the Pix QRCode was created.", example=True, validation_alias="devMode")
  brcode: str = Field(..., description="Copy-and-paste code of the Pix QRCode.", example="00020101021226950014br.gov.bcb.pix", validation_alias="brCode")
  brcode_base64: str = Field(..., description="Base64 image of the Pix QRCode.", example="data:image/png;base64,iVBORw0KGgoAAA", validation_alias="brCodeBase64")
  platform_fee: int = Field(..., description="Platform fees.", example=80, validation_alias="platformFee")
  created_at: str = Field(..., description="Creation date of the Pix QRCode.", example="2025-03-24T21:50:20.772Z", validation_alias="createdAt")
  updated_at: str = Field(..., description="Update date of the Pix QRCode.", example="2025-03-24T21:50:20.772Z", validation_alias="updatedAt")
  expires_at: str = Field(..., description="Expiration date of the Pix QRCode.", example="2025-03-25T21:50:20.772Z", validation_alias="expiresAt")

2. Consultando o status do Pix

Após criar um Pix QR Code, você pode acompanhar seu status (se foi pago, expirado, etc).

status = client.pixQrCode.check(pix_qr.id)
print(status.status)
# > "PAID" ou "PENDING" ou "EXPIRED"

3. Simulando um pagamento (ambiente de testes)

Se estiver usando o ambiente sandbox, você pode simular um pagamento:

simulado = client.pixQrCode.simulate(pix_qr.id)
print(simulado.status)
# > "PAID"

Você também pode enviar metadados para simular o pagamento:

pix_status = client.pixQrCode.simulate(
    id=pix_qr.id,
    metadata={"origin": "test-script"}
)
print(pix_status.status)
O objeto PixStatus

Bases: BaseModel

Source code in abacatepay/pixQrCode/models.py
18
19
20
class PixStatus(BaseModel):
  status: PIX_QR_CODE_STATUS = Field(..., description="Information about the status of the Pix QRCode. Options: PENDING, EXPIRED, CANCELLED, PAID, REFUNDED", example="PENDING")
  expires_at: str = Field(None, description="Expiration date of the Pix QRCode.", example="2025-03-25T21:50:20.772Z")

Pronto! Agora você já pode gerar e gerenciar pagamentos via Pix de forma prática com a AbacatePay 🚀