> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jaantonio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Behavior

> How Stamping moves a CargoWise document from source capture to a verified fiscal result and file delivery.

Stamping follows one durable path. The document kind changes the fiscal decision, but not the need
to preserve the source, verify the result, and keep issuance separate from delivery.

## The complete path

<Steps>
  <Step title="CargoWise sends the source">
    CargoWise outbound sends accounting XML to Lambda ingress. Lambda authenticates the workspace
    and accepts supported income, payment, and credit shapes.
  </Step>

  <Step title="Lambda saves the evidence">
    Lambda stores the source, document identity, and first work request together. Accepted work
    therefore has a durable source that later processing and recovery can use.
  </Step>

  <Step title="Lambda prepares the fiscal intent">
    Lambda reads CargoWise amounts, match lines, dates, currencies, exchange-rate evidence, parent
    relationships, and transaction fields. It turns those facts into one versioned fiscal intent.
  </Step>

  <Step title="Lambda reconciles the document">
    Lambda checks totals, taxes, parents, PUE or PPD evidence, installments, balances, currency
    conversion, and the enabled route. A healthy missing or unstamped parent moves the document to
    **Waiting for parent invoice**.
  </Step>

  <Step title="Facturapi works with SAT">
    Lambda sends an eligible request to Facturapi. Facturapi applies its CFDI and SAT validations,
    then submits the operation to SAT.
  </Step>

  <Step title="Lambda verifies and stores the result">
    Lambda verifies the returned UUID, totals, payment complement, or cancellation result. It stores
    the XML, PDF, integrity evidence, and the file-design snapshot used for that attempt.
  </Step>

  <Step title="Lambda returns the files">
    Lambda outbound assigns each file to the correct CargoWise DocManager module and document type,
    then sends it to CargoWise inbound. A delivery retry never repeats the stamp.
  </Step>
</Steps>

## Main decisions

| Source document                     | Main decision                                                  |
| ----------------------------------- | -------------------------------------------------------------- |
| Income invoice                      | Whether the invoice is PUE or PPD                              |
| Payment receipt                     | Which complete set of eligible PPD parents belongs in the REP  |
| Credit note                         | Whether to issue a Tipo E credit or cancel a full-value parent |
| Paired payment reversal             | Whether an original payment CFDI exists to cancel              |
| Existing Government Number          | Record the external stamp without issuing another CFDI         |
| Missing or unsafe required evidence | Stop, wait for a healthy parent, or open a failure             |

The detailed rules live with the document they affect: [Income invoices](/stamping/income-invoices),
[Payments](/stamping/payments), and
[Credits and cancellations](/stamping/credits-and-cancellations).

## Ownership

| Owner     | Responsibility                                                                                                                       |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| CargoWise | Accounting truth, including amounts, match lines, exchange-rate evidence, transaction fields, and source relationships               |
| Lambda    | Source mapping, reconciliation, route selection, durable work, result verification, storage, workspace behavior, and Lambda outbound |
| Facturapi | CFDI payload validation, SAT catalogs, certificate readiness, issuance, cancellation submission, and provider files                  |
| SAT       | Legal issuance and cancellation state                                                                                                |

Lambda uses CargoWise facts and surfaces Facturapi or SAT errors. It does not invent accounting
facts or duplicate vendor fiscal rules.

## Independent results

| Result   | Question                                           |
| -------- | -------------------------------------------------- |
| Fiscal   | Was the CFDI issued or cancelled?                  |
| Files    | Are the immutable XML and PDF stored?              |
| Delivery | Did CargoWise inbound receive every required file? |

If delivery fails after issuance, the SAT UUID and stored files still exist. The next step belongs
to delivery [Recovery](/stamping/recovery), not a new issuance.

## Accepted work

Lambda ingress accepts a document after its source and first work request are durable. CargoWise
treats that push as delivered. A document that remains **Received** or **Processing** is already
inside Lambda and should be followed in the [Workspace](/stamping/workspace).
