Invoices

An invoice is a document that provides details about a transaction, including information about the merchant, customer, and the monetary exchange. The customer-facing version of an invoice is often referred to as a bill. This page provides an in-depth understanding of invoice functionality within the Stax API, including their lifecycle, structure, and common use cases.

Statuses

Invoice statuses in the Stax platform are automatically managed by system operations and cannot be manually modified through API requests. Actions such as creating, sending, viewing, and making payments impact the current status of an invoice. However, certain functionalities, such as reverting statuses after refunds, require careful implementation to ensure accurate status tracking.

Status Transitions Overview

DRAFTSENT: After sending the invoice via email.

DRAFTVIEWED: If a customer views an invoice sent via a different email method.

DRAFTPAID / PARTIALLY PAID / ATTEMPTED: When payments are processed directly.

Any status → DELETED: When the invoice is deleted.

invoice lifecycle  diagram

Invoice Operations Diagram


StatusDescription
DRAFTThe invoice has been created but has not yet been sent or viewed by the customer. It is in a preliminary state.
SENTThe invoice has been sent via email, and the sent_at timestamp is recorded.
VIEWEDThe customer has viewed the invoice, with the viewed_at timestamp indicating when this occurred.
PAIDOne or more payments have been successfully applied to the invoice, covering the total amount.
PARTIALLY APPLIEDA payment was made for less than the total invoice amount, and it was successful.
ATTEMPTEDA payment attempt was made for the invoice but failed.
DELETEDThe invoice has a deleted_at date, indicating that it has been deleted.

Note: Status transitions such as refunds or voids are automatically managed. Ensure your integration accounts for these updates when handling payments or deletions.


Invoice Structure

Understanding the structure of an invoice is critical for developers to handle API responses effectively. Below are the key fields in an invoice:

FieldDescription
idUnique identifier for the invoice.
customer_idLinks the invoice to a specific customer.
itemsList of items or services billed in the invoice.
totalTotal amount due for the invoice.
taxesAny applicable taxes included in the invoice.
memoOptional note for the customer, often used to provide additional context.
sent_atTimestamp when the invoice was sent via email or SMS.
viewed_atTimestamp when the invoice was viewed by the customer.
paid_atTimestamp when the invoice was fully paid.
deleted_atTimestamp when the invoice was soft-deleted.

Common Use Cases

Creating an Invoice

When you create an invoice using the POST /invoice endpoint, the invoice is initially assigned a status of DRAFT. This means the invoice has not yet been sent or viewed.

Sending an Invoice via Email

If the invoice belongs to a customer with an email, you can send it using the PUT /invoice/{id}/send/email endpoint. This action will:

  • Update the invoice status to SENT.
  • Record the current timestamp in the sent_at field.

Invoice Viewed by Customer

The VIEWED status is assigned when a customer opens the invoice email or views the invoice through the link provided. This status will have a viewed_at timestamp to indicate when the invoice was viewed.

Note: The SENT and VIEWED statuses are only applicable if the merchant uses the Stax email solution or UI to send invoices. If an API integrator manages the email process themselves, the invoice may go directly from DRAFT to VIEWED or even directly to PAID.

Handling Refunds and Voids

  • Refunds: If a payment linked to an invoice is refunded (fully or partially), the invoice's status will revert to reflect the updated payment total.
  • Voids: Voiding a payment linked to an invoice will revert the status and make the invoice eligible for a new payment attempt.

Deleted Status

The DELETED status can branch from any other status. This indicates the invoice has been soft-deleted, meaning it is inaccessible but still exists in the database for reference or restoration.


Best Practices

Unique Identifiers: Use a UUID or unique identifier for each invoice to avoid conflicts during creation and updates.

Tracking Payments: Link transactions to invoices via the invoice_id field for complete payment tracking.

Error Handling: Implement robust error handling for scenarios like invalid customer details, failed payments, or incorrect invoice IDs.

Customization: Leverage hosted invoice pages to allow tipping, partial payments, or displaying memos to customers.


Troubleshooting

IssuePossible CauseSolution
Invoice not transitioning from DRAFT to SENTEmail sending process failed or email is invalid.Verify email format and API request parameters.
404 Not Found when retrieving an invoice.Invoice ID is invalid or invoice was deleted.Double-check the invoice ID and status.
Payments not applied to the invoice.Payment is not linked to the invoice.Ensure the payment is associated with the correct invoice_id.