> ## 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.

# Payment method

> How the account holder enrolls a card or a bank-account mandate with Fintoc during contracting, picks the billing period and confirms the method that starts the signing pipeline — without any charge.

> [!NOTE]
>
> The payment step **never charges** the customer. It enrolls a payment
> instrument for later billing and records which one this contract uses.

Only the account holder (`account_member`) goes through this step. Later
company administrators skip it.

## Flow

```mermaid theme={null}
sequenceDiagram
    actor C as Account holder
    participant P as Portal wizard
    participant B as Contract backend
    participant F as Fintoc

    P->>B: PATCH /contract/{id}/payment (CARD, and PAC if none is usable, prefetched when the step opens)
    B->>F: Start enrollment
    B-->>P: Fintoc checkout URL
    C->>P: Pick monthly or annual
    P->>B: PATCH /contract/{id}/payment/period
    C->>P: Add card or bank account
    P->>F: Customer completes checkout
    F-->>P: Back to the wizard (?enrollment=…&resumed=payment)
    F->>B: Webhook: instrument attached
    B-->>P: contract.payment_method.enrollment.success (realtime)
    C->>P: Confirm
    P->>B: PATCH /contract/{id}/payment/confirm
    B-->>P: stage SIGNATURE, documents preparing
    B->>B: Start the signing pipeline (after the response)
```

## Steps

**1. Billing period**

`PATCH /api/v3/contract/{id}/payment/period` stores `monthly` or `annual`
while the customer is still choosing. It does not open Fintoc or confirm
anything; it also lets the backend start preparing the documents early.

**2. Start enrollment**

`PATCH /api/v3/contract/{id}/payment` with `method` (`CARD`, the
default, or `PAC`) and optionally `period` and `locale` starts a Fintoc
enrollment and answers the checkout URL plus the
enrollment id. The portal calls it as soon as the payment step opens and
keeps the URL, so pressing the button only redirects. The payment method
it returns is a placeholder until Fintoc confirms it.

**3. Return from Fintoc**

The portal sends its `locale`, so Fintoc returns the customer straight to
the wizard (`/{locale}/contract/{id}?enrollment=…&resumed=payment`). The
return does not finish the enrollment itself. Callers that send no
`locale` return through the bridge page `/gateway/fintoc/enrollment/finish`.

**4. Activation by webhook**

Fintoc's webhook (`POST /api/v3/integration/fintoc/webhook`) attaches the
instrument, makes it the account's favorite and publishes
`contract.payment_method.enrollment.success`, so every open tab shows the
new method.

**5. Confirm**

`PATCH /api/v3/contract/{id}/payment/confirm` with `period` (and
optionally `payment_method_id`) records the chosen method and period and
answers `stage: SIGNATURE` with the documents in preparation. The signing
pipeline starts right after the response.

## Changing the method or period

* Confirming again with the same method and period changes nothing.
* Confirming with a different method or period, while no customer has signed,
  discards the unsigned documents and starts the pipeline again with the new
  values.
* Once any customer has signed, payment can no longer change. The usual answer
  is `409 unsupported-status`, because the contract is no longer in `draft`,
  `pending_signature` or `in_signature`; `409 customer-already-signed`
  appears while the contract is still in `pending_signature` or
  `in_signature`.

An account holds at most one usable bank-account mandate (active or pending);
a revoked or expired mandate does not block a new one.

## What happens if the customer leaves

If the customer abandons the wizard and the account has no other contracted
service, the Fintoc payment methods on the account are revoked. See
[Flows — Exceptions](https://docs.bbrands.io/digital-contracting/flows.md#exceptions).

## Errors

| Code | HTTP | Meaning |
| - | - | - |
| `summary-not-accepted` | `409` | The summary step is not done yet |
| `invalid-stage` | `409` | The contract is not at the payment step |
| `pac-already-enrolled` | `409` | The account already has a usable bank-account mandate |
| `payment-method-required` | `409` | There is no enrolled method to confirm |
| `invalid-payment-method` | `409` | The method does not belong to the account or cannot be used |
| `signer-tax-id-missing` | `409` | The account has no tax id to enroll with Fintoc |
| `customer-already-signed` | `409` | A customer already signed; payment is locked |
| `unsupported-status` | `409` | The contract is no longer in `draft`, `pending_signature` or `in_signature`; payment is locked |
| — | `409` | The contract is no longer in `draft` and the payment was not confirmed |
| `payment-return-deprecated` | `410` | `POST …/payment/return` belongs to the previous gateway and is no longer used |

## Data

Payment methods live in the payment domain; see
[Payment method](https://docs.bbrands.io/schemas/payment/payment-method.md),
[Payment method company](https://docs.bbrands.io/schemas/payment/payment-method-company.md) and
[Payment method mandate](https://docs.bbrands.io/schemas/payment/payment-method-mandate.md).

## Code

| Concern | Path |
| - | - |
| Payment step routes | `app/api/v3/contract/[document_id]/payment/` |
| Payment service | `lib/endpoint/contract-payment/` |
| Fintoc enrollment | `lib/endpoint/payment-method-enrollment/providers/fintoc/` |
| Fintoc webhook | `app/api/v3/integration/fintoc/webhook/` |
| Portal step | `frontend/portal-customer/app/components/digital-contract/steps/payment-step.tsx` |
| Fintoc bridge for callers without `locale` | `frontend/portal-customer/app/gateway/fintoc/enrollment/finish/` |


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