Handling Deposits & Payouts
Learn how to manage and track deposits and payouts with Blnk.
Overview
In this tutorial, you’ll learn how to implement deposits and payouts using the Blnk Ledger. You’ll explore and apply a variety of workflows to handle deposits and payouts seamlessly. This includes:
- Understanding how to set up your ledger for effective tracking of deposits and payouts in your system.
- Designing flexible workflows to accommodate various scenarios.
- Ensuring reliable and accurate transaction processing for your users.
For this tutorial, we’ll use the Blnk TypeScript SDK for the implementation. If you prefer, you can also refer to the API reference for details on the available endpoints.
Prerequisites
Before starting, ensure you have:
- A running Blnk server instance (e.g. at
http://localhost:5001
). - An API key for Blnk (replace
YOUR_API_KEY
in the code examples). Required for authenticated requests. - The Blnk CLI installed or a connected Blnk Cloud workspace to view your ledger data.
To prepare for the rest of this tutorial, read our Building a Wallet with Blnk tutorial if you haven’t already.
This resource will walk you through creating ledger balances for accounts in Blnk, which are essential for implementing deposits, withdrawals, and other financial operations covered later in this tutorial.
Handling deposits
When using Blnk to manage deposits, you can track the sources of your deposits—such as Stripe, Acme Bank, or others—directly in your ledger, enabling more detailed and accurate reporting.
As illustrated in the map below, each source can be assigned to an internal balance, which will be reflected as the value of the source
field in your transaction request. Fees (1% of the deposit amount, capped at $5) are deducted and tracked separately.
From our map, we can verify:
- The source of the deposit, for example, @AcmeBank if it originates from Acme Bank.
- That the customer receives funds after the fees have been dededucted.
- The deposit fees are tracked using the
@Fees
balance.
Deposits with fee processing
When recording a deposit with fee processing, we’ll use the Multiple Destinations feature to distribute the incoming funds between the customer’s balance and the fees balance.
We’ll also apply inflight
to validate the deposits against predefined business rules before finalizing the transaction.
When you apply inflight
to a multiple destinations transaction, all associated transactions—distributing funds to both destinations—are also placed in an inflight
state until the commit or void is executed.
Verifying deposits based on business rules
Next, we’ll develop functions to process deposits according to the following business rules. In this tutorial, we’ll implement checks for two rules:
-
If the balance is blocked or frozen, the deposit should be voided.
-
If the deposit amount exceeds 1 million USD, it should remain in an
inflight
state, and a notification should be sent for further investigation.
Rule 1: Check if balance is blocked or frozen
Rule 2: Check amount rule
Read more: How to Use Hooks to Trigger Notifications →
Putting it all together
Refunding deposits
To process refunds in your ledger and reverse a deposit:
Handling payouts
Payouts function similarly to deposits but in reverse.
The Customer Balance
serves as the source, while the Payout Destination
and @Fees
act as the destinations. Include @Fees
if the customer incurs fees for payment processing.
From our map, we can verify:
- The destination of the withdrawal.
- That the customer receives funds after the fees have been deducted.
- The deposit fees are tracked using the
@Fees
balance.
Path 1: Successful payouts
Here, the payout was successfully completed by your payout provider:
Commit based on feedback from payout provider
How multiple destinations work
When using Multiple Destinations in a transaction (like in our tutorial), Blnk automatically generates a separate transaction record for each distribution. These individual records are linked together with the parent_transaction
parameter.
This structure organizes and connects all parts of a multi-destination transaction efficiently.
A standout feature of this system is how actions on the parent_transaction
affect the entire group:
- Committing the
parent_transaction
automatically commits all associated distributions, confirming the full distribution. - Voiding the
parent_transaction
automatically voids all distributions, canceling the entire distribution in one step.
This unified approach simplifies managing complex transactions involving multiple recipients.
Path 2: Failed payouts
The payout is pending, but a failure message was received from the provider, resulting in the transaction being voided:
Path 2: Successful payout but reversed
The payout was initially successful, with confirmation received from the provider, but the funds were reversed by the provider due to an inability to settle the transaction:
Conclusion
You now have a basic deposits and payouts system powered by Blnk Ledger. It efficiently processes transactions while ensuring accurate records.
The system is flexible and can be expanded with features like:
- Automated handling of failed transactions
- Custom withdrawal limits and approval workflows
- Support for multiple funding sources
- Real-time transaction monitoring and alerts
With Blnk’s transaction system, you can track and manage all money movements, building a solid foundation for your financial operations.
Can’t find your use case?
If you’re searching for a specific tutorial that isn’t included here, you’re welcome to contribute to our documentation by sharing your expertise or requesting a new tutorial in our Discord community.
We’re always thrilled to expand our resources with the help of our developer community!