calculateCardInstallment function is a utility for calculating installment payments for card transactions with interest rates. This function computes both the individual installment price and the total price including interest, using compound interest calculation methods commonly used in credit card payment plans.ts
import { calculateCardInstallment } from "@arkyn/shared";
cashPrice (required)numbernumberInstallments (required)numberfees (optional)numberInstallments is 1, no interest is charged.number0.0349 (3.49%)totalPrice: The total price to be paid including all interest, rounded to two decimal places.installmentPrice: The price of each individual installment, rounded to two decimal places.{ totalPrice: number; installmentPrice: number }typescript
import { calculateCardInstallment } from "@arkyn/shared";const result = calculateCardInstallment({cashPrice: 1000,numberInstallments: 12,});console.log(result);// Output: { totalPrice: 1202.64, installmentPrice: 100.22 }
numberInstallments is less than or equal to 0. The error message is "Number of installments must be greater than 0".fees is less than 0. The error message is "Fees must be greater than or equal to 0".fees) is equal to 0 or the number of installments (numberInstallments) is equal to 1, no interest will be charged. In these cases, the cash price is simply divided by the number of installments.PMT = PV × (i × (1 + i)^n) / ((1 + i)^n - 1), where PMT is the installment payment, PV is the present value (cash price), i is the interest rate, and n is the number of installments.