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

# Process Flow

This guide details the complete customer journey for digital lending, from application to disbursement and withdrawal.

<Note>
  The flow covers **Application**, **Offer**, **Acceptance**, **Disbursement**, **Withdrawal**, and **Repayment**.
</Note>

### Phase 1: Loan Application

#### 1.1 Product Selection & Eligibility

The customer starts by viewing available loan products and answering eligibility questions.

```mermaid theme={null}
sequenceDiagram
    participant Customer
    participant App
    participant API
    participant LoanService

    Customer->>App: View Loan Products
    App->>API: GET /list-products
    API-->>App: Return Products List
    Customer->>App: Select Product
    App->>API: GET /loan-eligibility-questions/{id}
    API-->>App: Return Dynamic Questions
    Customer->>App: Answer Questions
    Note right of Customer: Enter BVN, Phone, Income, Country
    Customer->>App: Submit Application
    App->>API: POST /request-loan
    API-->>App: Application Submitted
```

<CardGroup cols={2}>
  <Card title="List Products" href="/api/lending/list-products">
    View available loan products
  </Card>

  <Card title="Get Questions" href="/api/lending/loan-eligibility-questions">
    View dynamic eligibility questions
  </Card>
</CardGroup>

#### Application Steps

<Steps>
  <Step title="Select Product">
    Customer views the list of available loan products and selects one.
  </Step>

  <Step title="Check Eligibility">
    System returns dynamic eligibility questions based on the selected product.
  </Step>

  <Step title="Submit Details">
    Customer provides answers along with key details:

    * **Employment Status**
    * **BVN**
    * **Phone Number**
    * **Monthly Income**
    * **Country**
  </Step>
</Steps>

### Phase 2: Processing & Offer

#### 2.1 Status & Offer Generation

After submission, the application undergoes review (manual or automated).

```mermaid theme={null}
sequenceDiagram
    participant Customer
    participant App
    participant API
    participant Admin

    Customer->>App: Check Status
    App->>API: GET /get-loan-history/{id}
    API-->>App: Return Application Status
    
    rect rgb(240, 248, 255)
    Note over API, Admin: Internal Processing
    Admin->>Admin: Review Application
    Admin->>API: Approve & Make Offer
    end

    Customer->>App: View Offer
    App->>API: GET /get-loan-offer
    API-->>App: Return Offer Details
```

<CardGroup cols={2}>
  <Card title="Check History" href="/api/lending/get-loan-history">
    View loan history
  </Card>

  <Card title="Get Offer" href="/api/lending/get-loan-offer">
    View loan offer
  </Card>
</CardGroup>

### Phase 3: Acceptance

#### 3.1 Accept or Reject Offer

The customer reviews the loan offer and terms.

<Steps>
  <Step title="Review Offer">
    Customer sees the approved amount (which may be less than or equal to requested).
  </Step>

  <Step title="Accept/Reject">
    Customer proceeds to accept or reject the loan offer.
  </Step>

  <Step title="Terms Agreement">
    If accepting, customer accepts the specific loan terms.
  </Step>
</Steps>

<CardGroup cols={3}>
  <Card title="Accept Offer" href="/api/lending/accept-loan-offer">
    Accept loan offer
  </Card>

  <Card title="Reject Offer" href="/api/lending/reject-loan-offer">
    Reject loan offer
  </Card>

  <Card title="Accept Terms" href="/api/lending/accept-loan-terms">
    Accept loan terms
  </Card>
</CardGroup>

### Phase 4: Disbursement & Wallet

#### 4.1 Wallet Creation

Once the loan is disbursed by the admin:

1. A **wallet account** is automatically created for the customer.
2. The loan amount is credited to this wallet.
3. The customer can view their total approved loans.

<Card title="Get Total Loan" href="/api/lending/get-total-loan">
  View total approved loans
</Card>

### Phase 5: Withdrawal

#### 5.1 Add Bank Account

To withdraw funds, the customer must first add a valid bank account.

```mermaid theme={null}
sequenceDiagram
    participant Customer
    participant App
    participant API
    participant BankService

    Customer->>App: Select "Add Bank"
    App->>API: GET /get-available-banks
    API-->>App: List of Banks
    Customer->>App: Select Bank & Enter Account No
    App->>API: GET /verify-bank-account/{code}/{number}
    API->>BankService: Verify Details
    BankService-->>API: Return Customer Name
    API-->>App: Verification Success
    Customer->>App: Confirm Add
    App->>API: Add to Customer Accounts
```

<CardGroup cols={2}>
  <Card title="Get Banks" href="/api/lending/get-available-banks">
    View available banks
  </Card>

  <Card title="Verify Account" href="/api/lending/verify-bank-account">
    Verify bank account
  </Card>
</CardGroup>

#### 5.2 Withdraw Funds

The customer transfers funds from their wallet to their bank account.

<Note>
  A processing fee (e.g., 10 Naira) is applied to withdrawals.
</Note>

1. **Select Source**: Choose the DISBURSED loan/wallet.
2. **Select Destination**: Choose a saved customer bank account.
3. **Enter Details**: Input amount and optional narration.
4. **Confirm**: Send funds.

<Card title="List Bank Accounts" href="/api/lending/list-customer-bank-accounts">
  View customer bank accounts
</Card>

#### 5.3 Track Transfers

Customers can view the history and status of their transfers.

<CardGroup cols={2}>
  <Card title="Transfer History" href="/api/lending/transfer-history">
    View transfer history
  </Card>

  <Card title="Manage Loans" href="/api/lending/manage-loans">
    Manage loans
  </Card>
</CardGroup>

### Phase 6: Repayment

After loan disbursement, customers need to make repayments according to their loan schedule. The system supports both partial repayments and full payoff.

#### 6.1 View Repayment Information

Customers can view their pending repayments and get detailed repayment instructions.

```mermaid theme={null}
sequenceDiagram
    participant Customer
    participant App
    participant API
    participant LoanService

    Customer->>App: Check Repayments
    App->>API: GET /pending-repayments/{user-id}
    API->>LoanService: Fetch Pending Repayments
    LoanService-->>API: Return Repayments
    API-->>App: List of Pending Repayments
    
    Customer->>App: Get Instructions
    App->>API: GET /repayment-instructions/{loan-application-id}
    API->>LoanService: Fetch Instructions
    LoanService-->>API: Return Instructions
    API-->>App: Bank Account & Reference
    App-->>Customer: Display Instructions
```

<CardGroup cols={2}>
  <Card title="Pending Repayments" href="/api/lending/pending-repayments">
    View pending repayments
  </Card>

  <Card title="Repayment Instructions" href="/api/lending/repayment-instructions">
    Get repayment instructions
  </Card>
</CardGroup>

#### 6.2 Make Repayment

Customers can make partial repayments or pay off the entire loan.

**Partial Repayment**:

1. Customer makes a bank transfer to the provided account with repayment reference
2. Customer records the repayment via API: `POST /repay-loan/{user-id}`
3. System records repayment with status `PENDING_VERIFICATION`
4. System verifies payment and updates loan balance

**Full Payoff**:

1. Customer initiates payoff: `POST /payoff-loan`
2. System calculates total balance (principal + accrued interest)
3. Customer makes payment and records it
4. System verifies and closes the loan

<CardGroup cols={2}>
  <Card title="Repay Loan" href="/api/lending/repay-loan">
    Make partial repayment
  </Card>

  <Card title="Payoff Loan" href="/api/lending/payoff-loan">
    Pay off entire loan
  </Card>
</CardGroup>

#### 6.3 Track Repayment History

Customers can view their complete repayment history and loan details.

<CardGroup cols={2}>
  <Card title="List Repayments" href="/api/lending/list-customer-repayments">
    View repayment history
  </Card>

  <Card title="Loan Details" href="/api/lending/loan-details-with-payment-history">
    View loan with payment history
  </Card>
</CardGroup>

<Card title="Complete Repayment Flow" href="/lending/repayment-flow">
  See detailed repayment flow documentation with diagrams and examples.
</Card>

<Note>
  Some loans may use third-party collection services. In such cases, manual repayments via API may not be allowed. Always check the loan's repayment collection configuration.
</Note>
