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

# Flows

> The twelve steps of digital contracting, the contract status lifecycle, the manual review before Maihue countersigns, and how cancel, reject, restart and recovery work.

This page walks through the journey in order. Each step names the endpoint
that drives it; the [Architecture](https://docs.bbrands.io/digital-contracting/architecture.md) page
explains the components.

## The twelve steps

**1. 1. Registration**

`POST /api/v3/auth/register/contract` creates or reuses the customer
account, writes one contract signer per signer (in signing order), reuses
the account's subscription for that business unit or creates a pending
one, creates a `draft` contract, and queues the one-time
link email for the first signer.

**2. 2. One-time link and session**

The customer opens `/{locale}/contract/{id}?action_link=…`. The portal
exchanges the link once with `POST /api/v3/contract/{id}/sessions` and
receives a contract session (an internal token for that user, scoped to
the contract's account, which the portal keeps bound to this contract; see
[Session and access](https://docs.bbrands.io/digital-contracting/session-and-access.md)) plus the
current `ContractState`.

**3. 3. Welcome**

The customer accepts the terms and privacy notice and starts the flow.
`POST /api/v3/contract/{id}/start` records when the contract was started.

**4. 4. Identity**

`PATCH /api/v3/contract/{id}/identity` verifies the RUT and the identity
card with Floid. A valid verification is reused only if it happened after
this contract started.

**5. 5. Summary**

`PATCH /api/v3/contract/{id}/summary` records the acceptance of the
contract summary and freezes it for this contract. Later company
administrators confirm the same frozen summary with
`PATCH /api/v3/contract/{id}/signer-summary`.

**6. 6. Payment method**

The account holder enrolls a card or a bank-account mandate (PAC) with
Fintoc, picks the billing period and confirms one method with
`PATCH /api/v3/contract/{id}/payment/confirm`. Nothing is charged. The
confirmation starts the signing pipeline.

**7. 7. Documents ready**

Worker A renders the contract and annex PDFs; Worker B opens the signature
group with the customer signers and Maihue's representatives. The portal
shows the documents as soon as they are ready.

**8. 8. Customer signature**

Each signer reads the documents, requests a one-time code with
`POST /api/v3/signature/{id}/signer/{signer}/otp` and signs every document
at once with `POST /api/v3/signature/{id}/signer/{signer}/sign`. Company
administrators sign one after another, in their signing order.

**9. 9. Password and portal**

Right after their own signature, the portal shows the signed documents;
when the signer continues, they create a portal password with
`PATCH /api/v3/contract/{id}/password` and are handed off to the
customer portal already signed in. A signer who already has a password
goes straight to the portal. The customer's part of the journey ends here.

**10. 10. Operations review**

When the last customer signer signs, the contract waits in
`pending_review`. Maihue operations approve or reject it with
`PATCH /api/v3/contract/{id}/review`.

**11. 11. Maihue countersignature**

Approval queues the enterprise worker, which applies the countersignature
of Maihue's representatives and seals the PDFs. The countersignature is
unattended by default; attended representatives receive an email
invitation and sign with a one-time code.

**12. 12. Activation**

Worker C stores the sealed documents as a new version, activates the
contract and the subscription, and queues the confirmation email to the
customer.

```mermaid theme={null}
sequenceDiagram
    actor C as Customer
    participant P as Portal wizard
    participant B as Contract backend
    participant W as Contract workers
    participant E as Signature engine
    actor O as Maihue operations

    C->>P: Open one-time link
    P->>B: POST /contract/{id}/sessions
    B-->>P: Contract session + ContractState
    C->>P: Identity, summary, payment method
    P->>B: PATCH /identity, /summary, /payment/confirm
    B->>W: Queue PDF generation
    W->>E: Open signature group
    C->>P: Request code and sign
    P->>B: POST /signature/{id}/signer/{signer}/otp and /sign
    B->>E: Code and signing gesture
    C->>P: Create password
    P->>B: PATCH /contract/{id}/password
    B-->>C: Customer portal, already signed in
    Note over B,O: Without the customer — contract in pending_review
    O->>B: PATCH /contract/{id}/review (approve)
    B->>W: Queue Maihue countersignature
    W->>E: Countersign and seal
    W->>W: Activate contract and subscription
    W-->>C: Confirmation email
```

## Contract statuses

```mermaid theme={null}
stateDiagram-v2
    [*] --> draft: registration
    draft --> pending_signature: payment method confirmed
    pending_signature --> in_signature: signature group opened
    in_signature --> partially_signed: a signer signed, others pending
    in_signature --> pending_review: last customer signer signed
    partially_signed --> pending_review: last customer signer signed
    in_signature --> signed: last customer signature (company_phase = first)
    partially_signed --> signed: last customer signature (company_phase = first)
    pending_review --> awaiting_enterprise_signature: operations approve
    awaiting_enterprise_signature --> signed: Maihue countersigned and sealed
    signed --> active: contract and subscription activated
    in_signature --> rejected: a signer rejects
    partially_signed --> rejected: a signer rejects
    pending_review --> cancelled: operations reject
    awaiting_enterprise_signature --> cancelled: operations reject
    draft --> cancelled: cancel or abandon
    draft --> expired: forced by an admin
    active --> [*]
```

| Status | Meaning |
| - | - |
| `draft` | Registered; the customer is completing identity, summary and payment |
| `pending_signature` | Payment method confirmed; documents are being prepared |
| `in_signature` | Signature group open; waiting for customer signers |
| `partially_signed` | At least one company administrator signed |
| `pending_review` | All customer signers signed; waiting for Maihue operations |
| `awaiting_enterprise_signature` | Approved; Maihue's countersignature is running |
| `signed` | Every party signed and the PDFs are sealed |
| `active` | Contract and subscription are live |
| `rejected` | A signer rejected the contract |
| `cancelled` | Cancelled by the customer, by an administrator or by an operations rejection |
| `expired` | Only an administrator sets it with force-status; terminal; restart is allowed |

The diagram shows the main path. Cancel and abandon are possible from any
status that is not final, not only from `draft`.

The status catalogue and its columns are in the
[Contract status schema](https://docs.bbrands.io/schemas/contract/contract-status.md).

## Operations review

With `last` workflows, the review is always a manual decision by Maihue
operations, and customer signatures alone never activate a contract.

| Decision | Allowed from | Result |
| - | - | - |
| `approve` | `pending_review` | The contract moves to `awaiting_enterprise_signature` and Maihue's countersignature is queued |
| `reject` (a reason is required) | `pending_review`, `awaiting_enterprise_signature` | The signature group and the contract are cancelled |

> [!NOTE]
>
> Each workflow defines whether Maihue signs after the customers (`last`, used
> by the seeded workflows) or before them (`first`). With `first`,
> Maihue's countersignature runs when the signature group opens and the review
> step does not apply.

## Company signers

A company contract has an ordered list of administrators. The first one is the
account holder and the only one who enrolls the payment method.

* Administrator N can request a code and sign only after administrator N−1 has
  signed; otherwise the API answers `409 prior-signer-pending`.
* When an administrator signs and the group is not complete, the next
  administrator receives their one-time link.
* Later administrators go through Welcome, Identity, Summary (confirming the
  frozen summary) and Signature, then create their own password.

## Exceptions

> [accordion] A signer rejects
>
> `POST /api/v3/signature/{id}/signer/{signer}/sign` with the `reject` action
> (optionally with a reason) marks the signer, the signature group and the contract as
> `rejected`. The portal does not offer this action: a customer who does not
> want to go on uses the **Reject** exit button, which cancels the
> registration (see the next item).

> [accordion] The customer leaves the wizard
>
> The exit button (**Reject**) is shown from the Identity step until
> Signature; it is not on Welcome or Password. It calls
> `POST /api/v3/contract/{id}/cancel` as the customer, which only the account
> holder may do: this registration is cancelled and the account stays. This
> business unit's subscription is cancelled only when no other contract of
> the same account and business unit is still not cancelled, rejected or
> expired. When the account has no other contracted service, the Fintoc
> payment methods on the account are revoked; otherwise they are kept.

> [accordion] An administrator cancels
>
> `POST /api/v3/contract/{id}/cancel` as an administrator does the same
> cleanup as the customer cancel: the contract, the signature group in
> progress, the subscription and the payment methods follow the same rules.
> Cancel works from any status that is not final; an `active`, `cancelled`,
> `rejected` or `expired` contract answers `409`.

> [accordion] Going back a step
>
> Before signing, the customer can look back from Signature to Payment or
> Summary. The portal shows those steps again on its own, without calling
> the backend. The contract only changes if the customer confirms a
> different payment method or period: the unsigned documents are discarded
> and the pipeline starts again. The API also exposes
> `POST /api/v3/contract/{id}/rewind` to move the contract back one step
> (refused once a customer has signed); the portal does not call it.

> [accordion] Restarting a contract
>
> `POST /api/v3/auth/register/contract/restart` starts a new registration for
> a `cancelled`, `rejected` or `expired` contract and reuses the account.
> It is not public: only the Odoo API key or staff holding
> `auth:register-contract-restart` can call it.

> [accordion] Lost or expired link
>
> The recovery screen offers to resend the link
> (`POST /api/v3/contract/{id}/resend-access`). The API also exposes
> `POST /api/v3/auth/contract/lookup-by-email`, which resends the portal link
> from an email and the account's identity document; no portal screen calls
> it today. Both are rate-limited and answer the same way to an unknown email.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.