Skip to main content

Record invoice finance repayments

Record the repayment of money owed to the lender for an invoice financing loan in the SMB's accounting software

Once the borrower's customer has paid for the goods or services they purchased, the financed invoice is ready to be reconciled in the accounting software.

To reflect that programmatically, perform these steps:

  1. Create a transfer from the borrower's bank account to the lender's to account for the advance amount plus fees and/or interest.

  2. To record interest or fees, create a direct cost against the lender's bank account.

  3. Create bank feed transactions to represent the transfer and direct cost in the lender's bank account.

To perform these operations, you will need the following properties:

Create transfer

Once the SMB's customer pays the invoice, use the Create transfer endpoint to record the advance and the fees/interest for the loan. This transfer should be made from borrowersBankAccount.id to lendersBankAccountId.

The repayment amount is calculated as:

repaymentAmount = advanceAmount + feeAndInterestAmount

Store repaymentAmount and repaymentDate in your application for use later on.

codatLending.loanWriteback.transfers.create({
accountingTransfer: {
date: repaymentDate,
from: {
accountRef: {
id: borrowersBankAccount.id,
},
amount: repaymentAmount,
currency: borrowersBankAccount.currency,
},
to: {
accountRef: {
id: lendersBankAccountId,
},
amount: repaymentAmount,
currency: borrowersBankAccount.currency,
},
},
companyId: companyId,
connectionId: connectionId,
}).then((res: CreateTransferResponse) => {
if (res.statusCode == 200) {
// handle response
}
});

Create direct cost

Check the Get create direct cost model, then use the Create direct cost endpoint to capture the amount of fees or interest (feeAndInterestAmount) incurred by the borrower. The direct cost is charged to the lender’s bank account to ensure the account balances to zero once the finance invoice repayment is complete.

codatLending.loanWriteback.directCosts.create({
accountingDirectCost: {
contactRef: {
dataType: "suppliers",
id: supplier.id,
},
currency: borrowersBankAccount.currency,
issueDate: repaymentDate,
lineItems: [
{
accountRef: {
id: expenseAccount.id,
},
description: "Fees and/or interest",
quantity: 1,
taxAmount: 0,
unitAmount: feeAndInterestAmount,
},
],
paymentAllocations: [
{
allocation: {
totalAmount: feeAndInterestAmount,
},
payment: {
accountRef: {
id: lendersBankAccountId,
},
},
},
],
taxAmount: 0.0,
totalAmount: feeAndInterestAmount,
},
companyId: companyId,
connectionId: connectionId,
}).then((res: CreateDirectCostResponse) => {
if (res.statusCode == 200) {
// handle response
}
});

Create bank feed transactions

Finally, use the Create bank account transactions endpoint again to deposit the total amount (including the repayment, fees, and any interest) into the lender's bank account. You will need the previously stored values for this operation.

codatLending.loanWriteback.bankTransactions.create({
accountingCreateBankTransactions: {
accountId: lendersBankAccountId, // Lender's virtual bank account ID you would have stored from the configuration step
transactions: [
{
id: transactionId, // Unique identifier for this bank transaction
amount: feeAndInterestAmount,
date: repaymentDate,
description: description, // Include a reference to supplier and direct cost
},
{
id: transactionId, // Unique identifier for this bank transaction
amount: advanceAmount,
date: repaymentDate,
description: description, // Include a reference to transfer
}
],
},
accountId: lendersBankAccountId,
companyId: companyId,
connectionId: connectionId,
}).then((res: CreateBankTransactionsResponse) => {
if (res.statusCode == 200) {
// handle response
}
});

At the end of this 3-stage process, your borrower will have the loan writeback reflected correctly in their accounting software. This saves them time on reconciliation and makes sure they (and you!) have clarity on the state of the loan.

Recap

In this guide, you have learned:

  • What is loan writeback and what it's used for.
  • How to map and configure the loan writeback solution.
  • How to perform the necessary postings using Codat's endpoints.


Was this page useful?
👏
👍
🤔
👎
😭