Savings application
Build a savings application with the Blnk Ledger.
A savings application empowers users to effectively manage and grow their savings through automated and manual contributions. This guide will assist you in building a comprehensive savings platform using the Blnk Ledger.
We’ll learn about:
- Defining and creating your ledger structure
- Savings account creation
- Funding account
- Scheduled transactions for savings
- Calculating & crediting interest
- Best Practices (with Inflight)
1. Ledger structure
In this example, we’ll use Blnk ledger to build a detailed savings app with interest. Each user will have their own savings account, and we’ll use the scheduling feature to apply interest regularly.
In this guide, we’ll use the following structure:
- Savings Ledger: Contains all savings accounts for users.
The ledger structure is flexible and can be customized based on your specific needs. For instance, you could group by types of transactions (e.g., real estate, freelance work), or use a combination of both.
See also
Creating a savings ledger
View your ledgers in your terminal:
Always store the ledger_id
in your database. You’ll need it for future operations related to this ledger.
2. Balance (savings account) creation
Blnk uses the concept of ledger balances to manage accounts/balances in a ledger. In this example, we’ll create savings accounts for Alice.
See also
Creating a savings account for User Alice
View your balances in your terminal:
The balance_id
is crucial. Always store this in your database and associate it with the customer. You’ll use this ID for all future transactions involving this loyalty point account.
3. Funding account
Customers can fund their savings accounts. We’ll use the Inflight feature to manage funding transactions.
See also
Funding Alice’s escrow account
The transaction should be committed after the payment has been verified from the external payment partner.
4. Scheduled transactions for savings
We’ll use the scheduled_for
transaction feature to schedule regular deposits into the savings accounts.
Scheduling a monthly deposit for Alice
To schedule a monthly deposit, you can use a recurring task scheduler like cron in combination with the Blnk API. Below is an example of how you can achieve this using Node.js and the node-cron
package.
Install the required package
Create a script to handle scheduled deposits
Run the script
This script schedules a monthly deposit for Alice and Bob on the 1st day of every month. You can adjust the dayOfMonth parameter to change the day when the deposit should be made.
View your transactions in your terminal:
5. Calculating & crediting interest
We’ll calculate interest periodically and credit it to the savings accounts.
Example: Crediting monthly interest
You can set up a similar cron job for calculating and crediting interest. Below is an example script for crediting monthly interest.
Create a script to handle interest calculation and crediting
Running the script
This script calculates and credits monthly interest to Alice on the 1st day of every month.
See also
Managing side effects with Inflight
A deep-dive guide into how to implement Inflight in your application.
Best practices (with Inflight)
- Balance Checks: Ensure the source balance has enough funds to complete the transaction. Prevent the source balance from having a balance lower than the amount in its
inflight_debit_balance
. - Available Balance Calculation: In your application, calculate the available balance to prevent users from accessing funds that are held in Inflight transactions. This can be done as follows:
- Error Handling: Implement robust error handling in your Inflight process. If a commit or void operation fails, you may need to retry or escalate to manual intervention.
- Customer Communication: Implement a system to notify customers about the status of their transactions, especially when they’re held in inflight.
- Reconciliation: Regularly reconcile your internal records with Blnk’s transaction logs to ensure accuracy. Pay special attention to Inflight transactions. Blnk v1 will support reconciliation features built into the ledger, which can aid in this process.
- Webhook Authentication: In a production environment, implement a mechanism to verify that webhooks are genuinely from your payment provider. This helps in maintaining the integrity and security of your transaction processing.
- Idempotency: Ensure your webhook handler is idempotent. Providers may send the same webhook multiple times, so your system should handle duplicate notifications gracefully.
- Monitoring: Set up monitoring and alerting for your webhook endpoint and inflight transactions. This can help you quickly identify and respond to any issues in the payment verification process.
Need help?
We are very happy to help you make the most of Blnk, regardless of whether it is your first time or you are switching from another tool.
To ask questions or discuss issues, please join our Discord community.
Manage your Blnk Ledger and explore advanced features (access control & collaboration, anomaly detection, secure storage & file management, etc.) in one dashboard.
Was this page helpful?