# An Online Installment Loan Module ⚠️(Deprecated)

We created a dedicated module to support selecting the terms of the online installment loan. The module in essence is a loan calculator where a customer may check the approximate monthly payment and the annual interest rate based on the cost of the shopping cart.

It is important to provide such information to a customer since the installment loan terms always vary and are based on on the agreement between the Bank of Georgia and Merchant and the terms depend on a  campaign (including the 0% installment loan) and they differ from a standard installment loan terms. All this information can be found in the Online Installment Loan Module helping support a customer in decision making.

Thus before activating the installment loan, the loan calculator is needed, which is an independent microservise and [requires integration](authentication) with a Merchant’s website. Bank of Georgia offers you a ready SDK for the loan calculator which is compatible with all devices (Desktop, Mobile, Tablet) and requires adding a ready code snipped on the website.

![Online Installment Modal](../assets/installment-modal.png)

### მაგალითი:

### Integration

To start the integration of the installment module SDK you should copy the below code into the HTML page. You should replace `{client_id}` by your client_id.

```html
<script src="https://webstatic.bog.ge/bog-sdk/bog-sdk.js?client_id={client_id}"></script>
```

---

### Displaying the Modal

You should use `BOG.Calculator.open` method for displaying the Online Installment modal.

#### Parameters

- `amount` — number, required

  A total amount of the installment loan

- `onClose` — function

  A method which is called by SDK when a customer closes the modal

- `onRequest` — function

  A method which is called by SDK after a customer chooses the terms. In such case the following arguments should be passed to the [Order Request](create-order) method:
  - `selected` - An object in which the terms chosen by a customer are passed
      - `amount` - A monthly payment amount of the installment loan
      - `month` - An installment loan duration in months
      - `discount_code` - A discount code of the installment loan
  - `successCb` - A method that should be called if you wish SDK to continue an installment loan process
  - `closeCb` - A method that should be called if you wish to close the module

- `onComplete` — function

  onComplete (optional; function) – A method which is called after SDK finishes the online installment loan process. In this case, a customer is being automatically redirected to the success page of a merchant. If you wish to not have the redirection, you should pass `false` in the `return` parameter. This method receives an object with a redirectUrl parameter.
  - `redirectUrl` - URL on which a customer should be redirected.

### There are two methods to continue the process.
1. If you wish SDK to continue the process, you should call `successCb` in the `onRequest` method [after generating](create-order) the orderId, by passing this generated `orderId` parameter. After finishing the process you should call the `onComplete` method.

2. If you need the SDK only for the calculations and you wish to continue the process yourself after a customer chooses the terms, then you should pass `false` in the `return` parameter of the `onRequest` method. In such a case SDK will not continue the process anymore. The modal remains open and you have to call the `closeCb` or the
`Bog.Calculator.close()` method if you wish to close the module.

```js
BOG.Calculator.open({
    amount: 500,
    onClose: () => {
        // Modal close callback
    },
    onRequest: (selected, successCb, closeCb) => {
        const {
          amount, month, discount_code
        } = selected;
        fetch('url-to-backend-api', {
            method: 'POST',
            body: JSON.stringify(selected)
        })
        .then(response => response.json())
        .then(data => successCb(data.orderId))
        .catch(err => closeCb());
    },
    onComplete: ({redirectUrl}) {
        return false;
    }
})
```

---

SDK also gives you the possibility to add a Bank of Georgia’s button on your website. You should

```html
<div class="bog-smart-button">
<script>
    const button = BOG.SmartButton.render(document.querySelector('.bog-smart-button'), {
        text: 'მოითხოვე სესხი',
        onClick: () => {
            // Open Installment Calculator Here
        }
    })
</script>
```
