saksh-wallet

3.0.1 • Public • Published

saksh-wallet

saksh-wallet is a Node.js library for managing user wallets, including functionalities for crediting, debiting, and converting currencies, as well as retrieving balances and transaction reports.

Installation

Install the package via npm:

npm install saksh-wallet

Features

saksh-wallet Package Features

User Management

  • Set Admin: Designate a user as an admin.
  • Set Limit: Configure wallet limits.
  • Get Balance: Retrieve the balance of a user in a specific currency.
  • Get Balance Summary: Obtain a summary of a user's balance.

Transaction Management

  • Credit: Add funds to a user's wallet.
  • Debit: Deduct funds from a user's wallet.
  • Transfer Funds: Transfer funds between users.
  • Get Transaction Report: Generate a report of a user's transactions.
  • Reverse Transaction: Reverse a specific transaction.
  • Reverse Multiple Transactions: Reverse multiple transactions at once.

Budget Management

  • Set Budget: Define a budget for a user.
  • Adjust Budget: Modify an existing budget.
  • Check Budget: Verify if a budget allows for a specific amount.
  • Get Budget Status: Retrieve the status of a user's budget.

Recurring Payments

  • Create Recurring Payment: Set up a recurring payment.
  • Update Recurring Payment: Modify an existing recurring payment.
  • Delete Recurring Payment: Remove a recurring payment.
  • Process Due Payments: Process all due recurring payments.

Standard Reporting

  • Get Monthly Transaction Report: Generate a monthly transaction report.
  • Get Daily Transaction Report: Generate a daily transaction report.
  • Get Yearly Transaction Report: Generate a yearly transaction report.
  • Get Transactions by Category: Retrieve transactions by category.
  • Get Spending Summary: Obtain a summary of spending over a period.
  • Get Transaction Count: Count the number of transactions.
  • Get Average Transaction Amount: Calculate the average transaction amount.
  • Get Largest Transaction: Identify the largest transaction.
  • Get Smallest Transaction: Identify the smallest transaction.
  • Get Transactions by Payment Method: Retrieve transactions by payment method.
  • Get Balance by Currency: Obtain the balance by currency.
  • Get All Users Balance by Currency: Retrieve the balance of all users by currency.
  • Get All Users Balance by Category: Retrieve the balance of all users by category.
  • Get All Users Balance at Date: Retrieve the balance of all users at a specific date.

AI-Enhanced Reporting

  • Set Gemini AI Key: Configure the Gemini AI key and initialize OpenAI.
  • Generate Report Summary: Create a summary of transactions using AI.
  • Handle User Query: Generate and execute a MongoDB query based on a user's query using AI.
  • Generate Comprehensive Report: Produce a detailed report based on a prompt and user ID using AI.

You can download saksh-wallet [ https://www.npmjs.com/package/saksh-wallet ] class and use in your node js package

npm i saksh-wallet

here is a complete use of this class. how to use the SakshWallet class, including user management, transaction management, budget management, recurring payments, standard reporting, and AI-enhanced reporting functionalities.

Full Example

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

async function fullExample() {
    // User Management
    const adminUserId = 'admin123';
    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);

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

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

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

    const transactionReport = await wallet.sakshGetTransactionReport(userId);
    console.log('Transaction Report:', transactionReport);

    const reversedTransaction = await wallet.sakshReverseTransaction(creditTransaction._id, null);
    console.log('Reversed Transaction:', reversedTransaction);

    const reversedMultipleTransactions = await wallet.sakshReverseMultipleTransactions([debitTransaction._id, transferTransaction._id]);
    console.log('Reversed Multiple Transactions:', reversedMultipleTransactions);

    // Budget Management
    const budget = await wallet.sakshSetBudget(userId, 'Food', 500, 'Monthly');
    console.log('Budget Set:', budget);

    const adjustedBudget = await wallet.sakshAdjustBudget(userId, 'Food', 600);
    console.log('Budget Adjusted:', adjustedBudget);

    const isBudgetAllowed = await wallet.sakshCheckBudget(userId, 'Food', 50);
    console.log('Is Budget Allowed:', isBudgetAllowed);

    const budgetStatus = await wallet.sakshGetBudgetStatus(userId, 'Food');
    console.log('Budget Status:', budgetStatus);

    // Recurring Payments
    const recurringPayment = await wallet.sakshCreateRecurringPayment(userId, 'user456', 100, 'USD', 'Subscription', 'ref126', 'Monthly');
    console.log('Recurring Payment Created:', recurringPayment);

    const updatedRecurringPayment = await wallet.sakshUpdateRecurringPayment(recurringPayment._id, { amount: 120 });
    console.log('Recurring Payment Updated:', updatedRecurringPayment);

    const deletedRecurringPayment = await wallet.sakshDeleteRecurringPayment(recurringPayment._id);
    console.log('Recurring Payment Deleted:', deletedRecurringPayment);

    await wallet.sakshProcessDuePayments();
    console.log('Due Payments Processed.');

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

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

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

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

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

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

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

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

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

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

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

    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);

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

    // AI Reporting
    const geminiAIKey = 'your-gemini-ai-key';
    const aiModel = 'text-davinci-003';
    const maxTokens = 150;
    await wallet.sakshGeminiAIKey(geminiAIKey, aiModel, maxTokens);
    console.log('AI key set successfully.');

    const aiReportSummary = await wallet.sakshGenerateReportSummary(transactionsByCategory);
    console.log('AI Report Summary:', aiReportSummary);

    const userQueryResult = await wallet.sakshHandleUserQuery('Show me all transactions for user123 in August 2024');
    console.log('User Query Result:', userQueryResult);

    const aiReport = await wallet.sakshGenerateReport('Generate a monthly transaction report for user123 for August 2024', userId);
    console.log('AI Generated Report:', aiReport);
}

fullExample().catch(console.error);

Explanation

  • User Management:

    • Set an admin user.
    • Set a limit for the wallet.
    • Get the balance and balance summary for a user.
  • Transaction Management:

    • Credit and debit transactions.
    • Transfer funds between users.
    • Get a transaction report.
    • Reverse transactions.
  • Budget Management:

    • Set and adjust budgets.
    • Check if a budget allows for a specific amount.
    • Get the status of a budget.
  • Recurring Payments:

    • Create, update, and delete recurring payments.
    • Process due payments.
  • Standard Reporting:

    • Generate various types of transaction reports (monthly, daily, yearly).
    • Get transactions by category, spending summary, transaction count, average transaction amount, largest and smallest transactions, transactions by payment method, balance by currency, and all users' balance by currency and category.
  • AI Reporting:

    • Set the Gemini AI key.
    • Generate a report summary using AI.
    • Handle user queries using AI.
    • Generate comprehensive reports using AI.

This example covers all the methods provided by the SakshWallet class, demonstrating how to use each functionality. Let me know if you need any further adjustments or additional information!

handle recuring payment

create a file worker.js and paste following code and run


const cron = require('node-cron');
const mongoose = require('mongoose');
const SakshWallet = require('saksh-wallet');

// Connect to MongoDB
mongoose.connect('mongodb://localhost:27017/sakshwallet', {
useNewUrlParser: true,
useUnifiedTopology: true
});

const wallet = new SakshWallet();

// Schedule the cron job to run every minute
cron.schedule('* * * * *', async () => {
await wallet.sakshProcessDuePayments();
});


License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

SUPPORT

susheel2339 @ gmail.com

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 3.0.1
    13
    • latest

Version History

Package Sidebar

Install

npm i saksh-wallet

Weekly Downloads

57

Version

3.0.1

License

MIT

Unpacked Size

65.4 kB

Total Files

20

Last publish

Collaborators

  • susheelhbti