# Loans

## Get Loan

## Get Loan

<mark style="color:blue;">`GET`</mark> `https://configure-abierta-test.herokuapp.com/api/v1/loan`

#### Query Parameters

| Name                                         | Type   | Description                   |
| -------------------------------------------- | ------ | ----------------------------- |
| id                                           | String | Loan ID                       |
| product-id<mark style="color:red;">\*</mark> | String | Product ID for loan           |
| start                                        | String | start date to fetch loan from |
| end                                          | String | end date to fetch loan to     |

{% tabs %}
{% tab title="200: OK Successfully fetched Loans" %}

```javascript
{
    "status": "success",
    "message": "Loans Retrieved",
    "data": [
        {
            "id": 12,
            "org_id": 1,
            "user_id": 23,
            "loan_request_id": 38,
            "product_name": "Jessefiled SME Loan",
            "borrower": {
                "id": 23,
                "org_id": 1,
                "firstname": "Akan",
                "lastname": "Nelson ",
                "email": "akannelson@gmail.com",
                "phone": "08092347589",
                "gender": "male",
                "password": "$2a$10$k22pN35M.oR7YELzwe/fyeiDH7LbtP/AtuSPhbC/Rh33hjEbkeGWu",
                "reference": "fDEehrq4ds5d5",
                "is_active": true,
                "created_at": "2021-10-21T08:51:43.520709Z",
                "updated_at": "2021-10-21T08:51:43.520709Z"
            },
            "disbursed": true,
            "disbursement_id": 0,
            "repayment_count": 3,
            "fully_repaid": false,
            "fully_repaid_on": "0001-01-01T00:00:00Z",
            "processing_fee": 0,
            "processing_fee_percentage": 0,
            "ref": "312hHi5",
            "duration": 3,
            "terms": {
                "approved_amount": 50000,
                "rate": 4,
                "tenure": 3,
                "tenured_in": "months",
                "rate_type": "",
                "grace_period": 0,
                "exclude_weekends": false,
                "zero_interest": false,
                "estimated_repayment": 0,
                "note": "Good to go. Authorise immediately."
            },
            "amount": 50000,
            "due_on": "2022-01-19T09:08:48.996619Z",
            "is_restructured": false,
            "approved_by": "Daniel Osineye",
            "approved_by_id": 1,
            "created_at": "2021-10-21T09:08:48.996634Z"
        },
        {
            "id": 14,
            "org_id": 1,
            "user_id": 24,
            "loan_request_id": 47,
            "product_name": "EC Personal Loan",
            "borrower": {
                "id": 24,
                "org_id": 1,
                "firstname": "Damilola",
                "lastname": "Ale",
                "email": "codenlyn@gmail.com",
                "phone": "0903 518 5172",
                "gender": "female",
                "password": "$2a$10$dl2cDJB3QqTqK3wpKiKkqu7/3QO0mCiOculYAj.mW8yFhUfm.8TOe",
                "reference": "q2.di9OdVaied",
                "is_active": true,
                "created_at": "2021-10-26T07:02:20.114638Z",
                "updated_at": "2021-10-26T07:02:20.114638Z"
            },
            "disbursed": true,
            "disbursement_id": 0,
            "repayment_count": 4,
            "fully_repaid": false,
            "fully_repaid_on": "0001-01-01T00:00:00Z",
            "processing_fee": 0,
            "processing_fee_percentage": 0,
            "ref": "wVdzV3i",
            "duration": 4,
            "terms": {
                "approved_amount": 100,
                "rate": 5,
                "tenure": 4,
                "tenured_in": "days",
                "rate_type": "",
                "grace_period": 0,
                "exclude_weekends": false,
                "zero_interest": false,
                "estimated_repayment": 0,
                "note": "done and dusted"
            },
            "amount": 100,
            "due_on": "2021-10-26T07:07:17.82965Z",
            "is_restructured": false,
            "approved_by": "Daniel Osineye",
            "approved_by_id": 1,
            "created_at": "2021-10-26T07:07:17.829668Z"
        },
        {
            "id": 13,
            "org_id": 1,
            "user_id": 1,
            "loan_request_id": 40,
            "product_name": "Helium Credit",
            "borrower": {
                "id": 1,
                "org_id": 1,
                "firstname": "Daniel",
                "lastname": "Osineye",
                "email": "daniel.osineye@gmail.com",
                "phone": "08182791196",
                "gender": "male",
                "password": "$2a$10$89pMshqzFG1veQFh9QLMwuYkrARfaQGH7veTzVjOdQDXLyzzxiGRa",
                "reference": "d-UP6isfd92iV",
                "is_active": true,
                "created_at": "2021-09-21T09:29:28.011746Z",
                "updated_at": "2021-09-21T09:29:28.011746Z"
            },
            "disbursed": true,
            "disbursement_id": 0,
            "repayment_count": 3,
            "fully_repaid": false,
            "fully_repaid_on": "0001-01-01T00:00:00Z",
            "processing_fee": 0,
            "processing_fee_percentage": 0,
            "ref": "AHajF6j",
            "duration": 3,
            "terms": {
                "approved_amount": 1000,
                "rate": 2,
                "tenure": 3,
                "tenured_in": "months",
                "rate_type": "",
                "grace_period": 0,
                "exclude_weekends": false,
                "zero_interest": false,
                "estimated_repayment": 0,
                "note": "Auto disbursement test"
            },
            "amount": 1000,
            "due_on": "2022-01-23T14:33:38.157073Z",
            "is_restructured": false,
            "approved_by": "Not Daniel",
            "approved_by_id": 3,
            "created_at": "2021-10-25T14:33:38.157089Z"
        },
        {
            "id": 15,
            "org_id": 1,
            "user_id": 24,
            "loan_request_id": 48,
            "product_name": "EC Personal Loan",
            "borrower": {
                "id": 24,
                "org_id": 1,
                "firstname": "Damilola",
                "lastname": "Ale",
                "email": "codenlyn@gmail.com",
                "phone": "0903 518 5172",
                "gender": "female",
                "password": "$2a$10$dl2cDJB3QqTqK3wpKiKkqu7/3QO0mCiOculYAj.mW8yFhUfm.8TOe",
                "reference": "q2.di9OdVaied",
                "is_active": true,
                "created_at": "2021-10-26T07:02:20.114638Z",
                "updated_at": "2021-10-26T07:02:20.114638Z"
            },
            "disbursed": true,
            "disbursement_id": 0,
            "repayment_count": 4,
            "fully_repaid": false,
            "fully_repaid_on": "0001-01-01T00:00:00Z",
            "processing_fee": 0,
            "processing_fee_percentage": 0,
            "ref": "Ep5p.DH",
            "duration": 4,
            "terms": {
                "approved_amount": 100,
                "rate": 5,
                "tenure": 4,
                "tenured_in": "days",
                "rate_type": "",
                "grace_period": 0,
                "exclude_weekends": false,
                "zero_interest": false,
                "estimated_repayment": 0,
                "note": "done"
            },
            "amount": 100,
            "due_on": "2021-10-26T07:15:05.95466Z",
            "is_restructured": false,
            "approved_by": "Not Daniel",
            "approved_by_id": 3,
            "created_at": "2021-10-26T07:15:05.954681Z"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

## Get Loan Repayment

## Get Repayment information for a specific loan

<mark style="color:blue;">`GET`</mark> `https://configure-abierta-test.herokuapp.com/api/v1/loan/{ID}/repayment`

#### Path Parameters

| Name | Type   | Description    |
| ---- | ------ | -------------- |
| ID   | String | ID of the loan |

#### Query Parameters

| Name       | Type   | Description                                    |
| ---------- | ------ | ---------------------------------------------- |
| product-id | String | Product ID of the loan                         |
| section    | String | What section to fetch : `repayment`, `metrics` |

#### Headers

| Name          | Type   | Description           |
| ------------- | ------ | --------------------- |
| Authorization | String | Bearer `YOUR_API_KEY` |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "status": "success",
    "message": "Repayments Retrieved",
    "data": [
        {
            "id": 2,
            "user_id": 0,
            "org_id": 1,
            "loan_request_id": 2,
            "is_credit_order": false,
            "credit_order_id": 0,
            "fulfilment_id": 0,
            "loan_id": 1,
            "disbursement_id": 0,
            "borrower": null,
            "amount": 270,
            "terms": {
                "approved_amount": 0,
                "rate": 0,
                "tenure": 0,
                "tenured_in": "",
                "rate_type": "",
                "grace_period": 0,
                "exclude_weekends": false,
                "zero_interest": false,
                "estimated_repayment": 0,
                "note": ""
            },
            "evolve_fee": 0,
            "status": "partialy-repaid",
            "paid": false,
            "due_on": "2021-12-30T15:31:57.341854Z",
            "repaid_on": "0001-01-01T00:00:00Z",
            "manual_repayment": true,
            "note": "",
            "channel": "cash",
            "paystack_ref": "",
            "debit_instruction_ref": "",
            "reminder": false,
            "collection_method": "manual",
            "manually_updated_by": "Daniel Osineye",
            "created_at": "2021-09-21T10:20:46.855034Z"
        },
        {
            "id": 4,
            "user_id": 0,
            "org_id": 1,
            "loan_request_id": 2,
            "is_credit_order": false,
            "credit_order_id": 0,
            "fulfilment_id": 0,
            "loan_id": 1,
            "disbursement_id": 0,
            "borrower": null,
            "amount": 270,
            "terms": {
                "approved_amount": 0,
                "rate": 0,
                "tenure": 0,
                "tenured_in": "",
                "rate_type": "",
                "grace_period": 0,
                "exclude_weekends": false,
                "zero_interest": false,
                "estimated_repayment": 0,
                "note": ""
            },
            "evolve_fee": 0,
            "status": "paid",
            "paid": true,
            "due_on": "2021-12-30T14:41:09.579934Z",
            "repaid_on": "0001-01-01T00:00:00Z",
            "manual_repayment": true,
            "note": "",
            "channel": "cash",
            "paystack_ref": "",
            "debit_instruction_ref": "",
            "reminder": false,
            "collection_method": "manual",
            "manually_updated_by": "Daniel Osineye",
            "created_at": "2021-09-21T10:20:49.439368Z"
        },
        {
            "id": 1,
            "user_id": 0,
            "org_id": 1,
            "loan_request_id": 2,
            "is_credit_order": false,
            "credit_order_id": 0,
            "fulfilment_id": 0,
            "loan_id": 1,
            "disbursement_id": 0,
            "borrower": null,
            "amount": 270,
            "terms": {
                "approved_amount": 0,
                "rate": 0,
                "tenure": 0,
                "tenured_in": "",
                "rate_type": "",
                "grace_period": 0,
                "exclude_weekends": false,
                "zero_interest": false,
                "estimated_repayment": 0,
                "note": ""
            },
            "evolve_fee": 0,
            "status": "paid",
            "paid": true,
            "due_on": "2021-12-30T14:41:28.928374Z",
            "repaid_on": "2021-09-28T20:48:11.72094Z",
            "manual_repayment": true,
            "note": "Optional note about this repayment",
            "channel": "cash",
            "paystack_ref": "",
            "debit_instruction_ref": "",
            "reminder": false,
            "collection_method": "manual",
            "manually_updated_by": "Daniel Osineye",
            "created_at": "2021-09-21T10:20:45.622606Z"
        },
        {
            "id": 3,
            "user_id": 0,
            "org_id": 1,
            "loan_request_id": 2,
            "is_credit_order": false,
            "credit_order_id": 0,
            "fulfilment_id": 0,
            "loan_id": 1,
            "disbursement_id": 0,
            "borrower": null,
            "amount": 270,
            "terms": {
                "approved_amount": 0,
                "rate": 0,
                "tenure": 0,
                "tenured_in": "",
                "rate_type": "",
                "grace_period": 0,
                "exclude_weekends": false,
                "zero_interest": false,
                "estimated_repayment": 0,
                "note": ""
            },
            "evolve_fee": 0,
            "status": "partialy-repaid",
            "paid": false,
            "due_on": "2021-12-20T10:20:45.622586Z",
            "repaid_on": "0001-01-01T00:00:00Z",
            "manual_repayment": true,
            "note": "",
            "channel": "cash",
            "paystack_ref": "",
            "debit_instruction_ref": "",
            "reminder": false,
            "collection_method": "manual",
            "manually_updated_by": "Daniel Osineye",
            "created_at": "2021-09-21T10:20:48.187451Z"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

## Get Loan Metrics

## Get Org Loan Metrics

<mark style="color:blue;">`GET`</mark> `/api/v1/loan/metrics`

#### Query Parameters

| Name                                         | Type   | Description                                                        |
| -------------------------------------------- | ------ | ------------------------------------------------------------------ |
| product-id<mark style="color:red;">\*</mark> | String | Product ID of the loan                                             |
| section<mark style="color:red;">\*</mark>    | String | specify metric section `main`, `top-insights`, `top-loan-products` |
| start                                        | String | start date to generate loan metric from `yyyy-mm-dd`               |
| end                                          | String | end date to generate loan metric to `yyyy-mm-dd`                   |

#### Headers

| Name          | Type   | Description           |
| ------------- | ------ | --------------------- |
| Authorization | String | Bearer `YOUR_API_KEY` |

{% tabs %}
{% tab title="200: OK Successfully fetched main metrics" %}

```javascript
{
    "status": "success",
    "message": "The organization main loan metrics",
    "data": {
        "total_loans": {
            "count": 15,
            "value": 175700,
            "message": "Total Loans for the organization"
        },
        "overdue_loans": {
            "count": 6,
            "value": 53700,
            "message": "Total overdue loans for the organization"
        },
        "disbursed_loans": {
            "count": 15,
            "value": 175700,
            "message": "Total disbursed loans for the organization"
        },
        "repaid_loans": {
            "count": 0,
            "value": 0,
            "message": "Total repaid loans for the organization"
        }
    }
}
```

{% endtab %}

{% tab title="200: OK Successfully fetched top-insights metrics" %}

```javascript
{
    "status": "success",
    "message": "Top Loan Insights Metrics",
    "data": {
        "total_active_borrowers": 0,
        "total_disbursed": 175700,
        "total_fully_paid_loans": 0,
        "total_unpaid_loans": 15,
        "total_penalty_fee": 0
    }
}
```

{% endtab %}

{% tab title="200: OK Successfully fetched top-loan-products metrics" %}

```javascript
{
    "status": "success",
    "message": "Top Loan Product Metrics Retrieved",
    "data": [
        {
            "product_name": "Share Wealth",
            "recovery_rate": 0,
            "user_count": 0,
            "portfolio_size": 42000,
            "repaid_count": 0,
            "repaid_value": 0,
            "overdue_count": 0,
            "overdue_value": 0
        },
        {
            "product_name": "Instacom",
            "recovery_rate": 0,
            "user_count": 0,
            "portfolio_size": 0,
            "repaid_count": 0,
            "repaid_value": 0,
            "overdue_count": 0,
            "overdue_value": 0
        },
        {
            "product_name": "EC LPO Loan",
            "recovery_rate": 0,
            "user_count": 0,
            "portfolio_size": 0,
            "repaid_count": 0,
            "repaid_value": 0,
            "overdue_count": 0,
            "overdue_value": 0
        },
        {
            "product_name": "EC Personal Loan",
            "recovery_rate": 0,
            "user_count": 0,
            "portfolio_size": 12700,
            "repaid_count": 0,
            "repaid_value": 0,
            "overdue_count": 4,
            "overdue_value": 0
        },
        {
            "product_name": "Helium Credit Tester",
            "recovery_rate": 0,
            "user_count": 0,
            "portfolio_size": 0,
            "repaid_count": 0,
            "repaid_value": 0,
            "overdue_count": 0,
            "overdue_value": 0
        },
        {
            "product_name": "CollinsDonDoMadness",
            "recovery_rate": 0,
            "user_count": 0,
            "portfolio_size": 0,
            "repaid_count": 0,
            "repaid_value": 0,
            "overdue_count": 0,
            "overdue_value": 0
        }
    ]
}
```

{% endtab %}
{% endtabs %}
