DEV Community

Susheel kumar
Susheel kumar

Posted on

Comprehensive Wallet Management with SakshWallet

Introduction

In today's digital age, managing a digital wallet is essential for both individuals and businesses. It involves various tasks such as user management, transaction handling, and generating insightful reports. In this blog post, we will explore how to efficiently utilize the SakshWallet npm package to streamline these tasks.

Setting Up

To get started, you need to install the SakshWallet package. Open your terminal and run the following command:

npm install saksh-wallet
Enter fullscreen mode Exit fullscreen mode

Importing and Initializing the Wallet

Once the package is installed, you can import the SakshWallet class and create an instance of it. Here’s how to do it:

const SakshWallet = require('saksh-wallet');

async function fullExample() {
    const adminUserId = 'admin123';
    const wallet = new SakshWallet();
Enter fullscreen mode Exit fullscreen mode

User Management

Managing users is a crucial aspect of any digital wallet. With SakshWallet, you can easily set an admin user and manage limits:

    // Set Admin User
    await wallet.sakshSetAdmin(adminUserId);
    console.log('Admin set successfully.');

    const userId = 'user123';
    await wallet.sakshSetLimit(false);
    console.log('Limit set successfully.');

    const balance = await wallet.sakshGetBalance(userId, 'USD');
    console.log('User Balance:', balance);

    const balanceSummary = await wallet.sakshGetBalanceSummary(userId);
    console.log('Balance Summary:', balanceSummary);
Enter fullscreen mode Exit fullscreen mode

Transaction Management

SakshWallet allows you to handle various types of transactions, including credits, debits, and fund transfers:

    // Credit Transaction
    const creditTransaction = await wallet.sakshCredit(userId, 100, 'USD', 'Salary', 'ref123', 'Income');
    console.log('Credit Transaction:', creditTransaction);

    // Debit Transaction
    const debitTransaction = await wallet.sakshDebit(userId, 50, 'USD', 'Grocery Shopping', 'ref124', 'Expense');
    console.log('Debit Transaction:', debitTransaction);

    // Fund Transfer
    const transferTransaction = await wallet.sakshTransferFunds(userId, 'user456', 20, 'USD', 'Gift', 'ref125', 'Transfer');
    console.log('Transfer Transaction:', transferTransaction);

    // Transaction Report
    const transactionReport = await wallet.sakshGetTransactionReport(userId);
    console.log('Transaction Report:', transactionReport);
Enter fullscreen mode Exit fullscreen mode

Standard Reporting

Generating reports is vital for analyzing transactions and balances. With SakshWallet, you can create various reports effortlessly:

    // Monthly Report
    const monthlyReport = await wallet.sakshGetMonthlyTransactionReport(userId, 2024, 8);
    console.log('Monthly Transaction Report:', monthlyReport);

    // Daily Report
    const dailyReport = await wallet.sakshGetDailyTransactionReport(userId, new Date('2024-08-15'));
    console.log('Daily Transaction Report:', dailyReport);

    // Yearly Report
    const yearlyReport = await wallet.sakshGetYearlyTransactionReport(userId, 2024);
    console.log('Yearly Transaction Report:', yearlyReport);

    // Transactions by Category
    const transactionsByCategory = await wallet.sakshGetTransactionsByCategory(userId, 'Food');
    console.log('Transactions by Category:', transactionsByCategory);

    // Spending Summary
    const spendingSummary = await wallet.sakshGetSpendingSummary(userId, new Date('2024-08-01'), new Date('2024-08-31'));
    console.log('Spending Summary:', spendingSummary);

    // Transaction Count
    const transactionCount = await wallet.sakshGetTransactionCount(userId);
    console.log('Transaction Count:', transactionCount);

    // Average Transaction Amount
    const averageTransactionAmount = await wallet.sakshGetAverageTransactionAmount(userId, new Date('2024-08-01'), new Date('2024-08-31'));
    console.log('Average Transaction Amount:', averageTransactionAmount);

    // Largest and Smallest Transactions
    const largestTransaction = await wallet.sakshGetLargestTransaction(userId);
    console.log('Largest Transaction:', largestTransaction);

    const smallestTransaction = await wallet.sakshGetSmallestTransaction(userId);
    console.log('Smallest Transaction:', smallestTransaction);

    // Transactions by Payment Method
    const transactionsByPaymentMethod = await wallet.sakshGetTransactionsByPaymentMethod(userId, 'Credit Card');
    console.log('Transactions by Payment Method:', transactionsByPaymentMethod);

    // Balance by Currency
    const balanceByCurrency = await wallet.sakshGetBalanceByCurrency(userId);
    console.log('Balance by Currency:', balanceByCurrency);

    // All Users Balance by Currency and Category
    const allUsersBalanceByCurrency = await wallet.sakshGetAllUsersBalanceByCurrency();
    console.log('All Users Balance by Currency:', allUsersBalanceByCurrency);

    const allUsersBalanceByCategory = await wallet.sakshGetAllUsersBalanceByCategory();
    console.log('All Users Balance by Category:', allUsersBalanceByCategory);

    // All Users Balance at a Specific Date
    const allUsersBalanceAtDate = await wallet.sakshGetAllUsersBalanceAtDate(new Date('2024-08-31'));
    console.log('All Users Balance at Date:', allUsersBalanceAtDate);
}

fullExample().catch(console.error);
Enter fullscreen mode Exit fullscreen mode

Conclusion

The SakshWallet package offers a comprehensive solution for managing digital wallets, handling transactions, and generating detailed reports. By leveraging its capabilities, you can efficiently manage user accounts, track transactions, and gain valuable insights into financial activities.

Feel free to implement these features in your projects and enhance your digital wallet management experience! If you have any questions or need further assistance, don’t hesitate to reach out.

Top comments (0)