Skip to main content

Payments

Payments represent charge attempts associated with invoices. Each payment tracks the status, method, gateway used, and provider response.

Payment Statuses​

pending β†’ processing β†’ succeeded β†’ refunded
↓ ↓
failed partially_refunded
↓
canceled
StatusDescription
pendingAwaiting processing
processingSent to gateway, awaiting response
succeededConfirmed as paid
failedDeclined by gateway or error
canceledManually canceled
partialPartial payment received
refundedFully refunded
partially_refundedPartially refunded

Payment Flow​

1. Automatic Charge (charge_automatically)​

Invoice finalized
β†’ Applies credits automatically
β†’ If credits cover everything: invoice = paid
β†’ If not:
β†’ Gets default payment method
β†’ Processes payment via gateway
β†’ Card: immediate response
β†’ Boleto/PIX: awaits gateway webhook
β†’ Success: invoice = paid
β†’ Failure: schedules retry (dunning)

2. Manual Payment​

The operator or customer initiates payment via the dashboard or portal.

Processing a Payment​

When processing, the system:

  1. Validates that the invoice is open
  2. Determines the payment method (provided, saved, or default)
  3. Gets the organization's gateway for the payment type
  4. Creates a payment record with an idempotency key
  5. Sends the charge to the gateway
  6. Updates the payment with the response

Idempotency​

Each payment has a unique idempotency key. Duplicate requests return the existing result without reprocessing.

Special Scenarios​

Partial Payment​

  • The received amount is less than the total
  • The invoice remains open with the balance updated
  • The customer can pay the remaining amount with another payment

Overpayment​

When the paid amount exceeds the invoice balance:

  1. The invoice amount is applied normally
  2. The surplus becomes a credit automatically on the customer's account
  3. The credit is of type adjustment with description "Overpayment credit on invoice {number}"
  4. The credit will be automatically applied to future invoices

Already Paid Invoice​

If the invoice was already paid when the payment is processed, the full amount becomes a credit on the customer's account.

Operations​

Cancel Payment​

Only pending payments can be canceled. For boleto/PIX, the cancellation is sent to the gateway.

Refund​

succeeded or partially_refunded payments can be refunded:

  • Full refund: Status changes to refunded
  • Partial refund: Status changes to partially_refunded
  • The request is sent to the gateway when available

Retry​

failed payments can be retried. A new payment is created with the same amount, invoice, and method.

Screenshots​

Payment list​

The /dashboard/payments screen aggregates all payments received, with filters by status, method, gateway, customer and period. Each row shows the related invoice, amount, gateway fee, net amount and response message.

List of payments with filters by gateway and method

Payment detail​

The /dashboard/payments/[id] page shows the complete record: gateway, transaction at the provider, settled invoice, method (with the card's last 4 digits or the boleto's bank), attempt history, refunds and webhooks received.

Payment detail with gateway, method and history