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

# Credit payments

> Customer credit eligibility, credit payment flow, and how credit lines are handled during order submission.

Credit payments allow customers with a configured credit limit to pay on credit. The system checks eligibility in real time and filters credit lines from the fiscal payment pipeline.

## Prerequisites

* Customer assigned to the order with `creditLimit > 0` in Odoo
* Order mode is not `return` (credit is unavailable for refunds)

## Eligibility check

The credit button appears in the payment screen when:

1. The order has a `partnerId` (customer assigned)
2. The customer's `creditLimit` is greater than zero
3. The order mode is not `return`

When the user taps the credit button, the frontend calls the credit-check API to verify eligibility server-side before adding a credit payment line.

## API endpoint

<Card>
  **POST** `/pos-api/v1/customers/credit-check`
</Card>

Checks whether a customer is eligible for credit payment at the requested amount.

### Request

```json theme={null}
{
  "partner_id": 42,
  "amount": 1500.00
}
```

### Response

```json theme={null}
{
  "eligible": true,
  "credit_limit": 5000.00,
  "current_balance": 1200.00,
  "available_credit": 3800.00
}
```

## Payment flow

<Steps>
  <Step title="Select customer">
    Assign a customer with credit limit to the order via the customer select button.
  </Step>

  <Step title="Open payment screen">
    The credit button appears alongside standard payment methods if the customer is eligible.
  </Step>

  <Step title="Tap credit">
    Calls `/pos-api/v1/customers/credit-check` to verify eligibility. If approved, a payment line is added with `isCredit: true`.
  </Step>

  <Step title="Complete payment">
    Credit lines can cover part or all of the balance. Mix with cash/card as needed.
  </Step>

  <Step title="Order submission">
    Credit lines are **filtered out** from `statement_ids` before sending to Odoo. Only non-credit payment lines create journal entries.
  </Step>
</Steps>

## Implementation details

### PaymentLine.isCredit

The `PaymentLine` type in `types.ts` includes an `isCredit?: boolean` flag. During order submission, lines with `isCredit: true` are excluded:

```typescript theme={null}
const cashPayments = payments.filter((line) => !line.isCredit);
```

### Customer model

The `Customer` interface in `domain/customers/models.ts` includes `creditLimit?: number`, populated from the bootstrap `partners` array and customer API responses.

## Source files

```
src/domain/customers/creditApi.ts       # Credit check API client
src/domain/customers/models.ts          # Customer model with creditLimit
src/features/sales/components/payment/
├── credit-payment.ts                   # Eligibility logic
└── types.ts                            # PaymentLine with isCredit flag
src/features/sales/screens/PaymentScreen.tsx  # Credit button rendering
src/features/sales/screens/CartScreen.tsx     # Credit line filtering on submit
```
