# Credit Preview

CreditPreviews are used to preview a credit operation before creating it.

You can simulate the installment schedule, the IOF tax amount, the disbursed amount and the effective interest rates of a Credit Note without persisting anything. Previews are computed on the fly and are not saved.

### The CreditPreview object

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `type` | STRING | Type of the credit preview. Options: "credit-note". |
| `credit` | OBJECT | CreditNotePreview object with the simulation parameters and, in the response, the computed results. Its "type" defines the amortization schedule: "sac" (constant amortization), "price" (fixed installments), "american" (periodic interest and principal at maturity), "bullet" (principal and interest at maturity) or "custom" (you provide the invoices and the rates are computed). Input fields: "taxId", "scheduled" (disbursement datetime), "nominalInterest" (% per year), "initialDue" (first installment due datetime), "count" (number of installments), "initialAmount" (installment amount in cents), "interval" ("day", "week", "month", "quarter", "semester" or "year" - default "month"), "nominalAmount" or "amount" (in cents), "rebateAmount" and, for the "custom" type, "invoices" as {"amount", "due"} objects. Computed fields returned: "amount" (net disbursed amount), "taxAmount" (IOF), "interest" (effective rate, % per year), "nominalInterest", "count", "initialDue", "initialAmount" and the full "invoices" schedule. |

### Create Credit Previews

`POST /v2/credit-preview`

Create credit previews to simulate credit notes before actually creating them. You can create up to 100 previews in a single request.

For the "sac" and "price" types, provide exactly one of "count" or "initialAmount" - the other one is computed. For every preview type - sac, price, american, bullet or custom - provide exactly one of "nominalAmount" or "amount"; the other value, along with taxAmount and the interest rates, is computed from the invoice schedule.

**Parameters**

| Name | Required | Description |
| --- | --- | --- |
| `type` | REQUIRED | Type of the credit preview. Options: "credit-note". |
| `credit` | REQUIRED | CreditNotePreview object with the simulation parameters. Required fields by credit type: "sac" and "price" take "nominalInterest", "scheduled", "initialDue", "taxId" and one of "count" or "initialAmount"; "american" takes "nominalInterest", "scheduled", "initialDue", "count" and "taxId"; "bullet" takes "nominalInterest", "scheduled", "initialDue" and "taxId"; "custom" takes "scheduled", "taxId" and "invoices". Optional fields: "nominalAmount" or "amount" (exactly one of them is required, "custom" included), "rebateAmount" and "interval". |

**Request**

```python
import starkinfra

previews = starkinfra.creditpreview.create([
    starkinfra.CreditPreview(
        type="credit-note",
        credit=starkinfra.creditpreview.CreditNotePreview(
            type="sac",
            nominal_amount=100000,
            nominal_interest=15.0,
            scheduled="2022-06-28",
            initial_due="2022-07-28",
            count=12,
            tax_id="012.345.678-90"
        )
    )
])

for preview in previews:
    print(preview)
```

**Response**

```python
CreditPreview(
    type=credit-note,
    credit=CreditNotePreview(
        type=sac,
        nominal_amount=100000,
        rebate_amount=0,
        tax_amount=1126,
        amount=98874,
        interest=17.34,
        nominal_interest=15.0,
        scheduled=2022-06-28T00:00:00.000000+00:00,
        initial_due=2022-07-28T00:00:00.000000+00:00,
        initial_amount=9583,
        count=12,
        invoices=[Invoice(amount=9583, due=2022-07-28), ..., Invoice(amount=8438, due=2023-06-28)]
    )
)
```

## Available Languages

Code samples on this page are in Python. The same content is available with samples in:

- [Python](https://docs.starkinfra.com/api/v2/credit-preview-python.md)
- [Node.js](https://docs.starkinfra.com/api/v2/credit-preview-node.md)
- [PHP](https://docs.starkinfra.com/api/v2/credit-preview-php.md)
- [Java](https://docs.starkinfra.com/api/v2/credit-preview-java.md)
- [Ruby](https://docs.starkinfra.com/api/v2/credit-preview-ruby.md)
- [Elixir](https://docs.starkinfra.com/api/v2/credit-preview-elixir.md)
- [.NET](https://docs.starkinfra.com/api/v2/credit-preview-dotnet.md)
- [Go](https://docs.starkinfra.com/api/v2/credit-preview-go.md)
- [Clojure](https://docs.starkinfra.com/api/v2/credit-preview-clojure.md)
- [cURL](https://docs.starkinfra.com/api/v2/credit-preview-curl.md)
