Ir para o conteúdo

tempest_fastapi_sdk.integrations.payment.settlement

Confirmar um Pix no provedor antes de liberar qualquer coisa.

« Integrações e pagamentos


confirm_pix_payment async

confirm_pix_payment(
    provider: PixProvider, charge_id: str, *, reference: str, amount_cents: int
) -> PixPaymentConfirmation

Re-read a charge and check it pays this order, in full.

Pass the charge id the service stored when it opened the charge, not the one a webhook delivery names: the delivery is only the trigger to look, so a forged or replayed one can at most make the service ask the provider about a charge it already owns.

The amount must match exactly. A charge that settled for another amount — a different charge, or one whose value the provider adjusted — is a decision for the service, not something to release silently at the wrong price.

Nothing is written. Release the order under :func:~tempest_fastapi_sdk.wallet.claim_once when this returns :attr:PixPaymentConfirmation.paid, so the same paid charge confirmed twice — a webhook retry, a reconciliation sweep — releases once.

Parameters:

Name Type Description Default
provider PixProvider

Any provider that implements the contract.

required
charge_id str

The stored :attr:~tempest_fastapi_sdk.integrations.payment.base.PixCharge.provider_charge_id.

required
reference str

The order's reference, sent as :attr:~tempest_fastapi_sdk.integrations.payment.base.PixChargeRequest.reference when the charge was created.

required
amount_cents int

What the order costs, in cents.

required

Returns:

Name Type Description
PixPaymentConfirmation PixPaymentConfirmation

The outcome and the charge as read.

Raises:

Type Description
Exception

Whatever the provider's get_pix_charge raises (timeout, unknown charge) propagates: an unanswered question is not a "no", and the caller must not treat it as one.

PixPaymentConfirmation

Bases: _EnumSafeSchema

The result of re-reading a charge against what the order expects.

Attributes:

Name Type Description
outcome PixConfirmationOutcomeEnum

Which check decided the result.

charge PixCharge

The charge as the provider reported it on this read — not the copy that arrived in the webhook.

expected_reference str

The order reference the charge had to carry.

expected_amount_cents int

The amount, in cents, the charge had to carry.

paid property

paid: bool

Whether the confirmation authorizes releasing the order.

Returns:

Name Type Description
bool bool

True only for :attr:PixConfirmationOutcomeEnum.PAID.

PixConfirmationOutcomeEnum

Bases: BaseStrEnum

Why a re-read charge does or does not authorize releasing an order.

The checks run in this order, and the first one that fails names the outcome: a charge for another order is reported as :attr:REFERENCE_MISMATCH even if it is also unpaid.

Attributes:

Name Type Description
PAID str

The charge belongs to the order, is paid, and carries the order's amount. The only outcome that authorizes release.

REFERENCE_MISMATCH str

The charge's reference is not the order's — the stored charge id points at someone else's charge.

NOT_PAID str

The provider does not report the charge as :attr:~tempest_fastapi_sdk.integrations.payment.base.PaymentStatusEnum.PAID. The current status is in :attr:PixPaymentConfirmation.charge.

AMOUNT_MISMATCH str

Paid, but not the amount the order costs.