UNPKG

saksh-wallet

Version:

A Node.js library for managing user wallets, including functionalities for crediting, debiting, and converting currencies, as well as retrieving balances and transaction reports.

59 lines (48 loc) 1.82 kB
const mongoose = require('mongoose'); const SakshWallet = require('../SakshWallet'); var str = "mongodb+srv://susheel2339:iJQcnYKE1jRG591G@susheel2339.wmx2d.mongodb.net/b2"; // Connect to MongoDB mongoose.connect(str, { useNewUrlParser: true, useUnifiedTopology: true }); const wallet = new SakshWallet(); // Listen for events wallet.recurringPayments.on('recurringPaymentCreated', (payment) => { console.log('Recurring payment created:', payment); }); wallet.recurringPayments.on('recurringPaymentUpdated', (payment) => { console.log('Recurring payment updated:', payment); }); wallet.recurringPayments.on('recurringPaymentDeleted', (payment) => { console.log('Recurring payment deleted:', payment); }); async function main() { try { // Create a recurring payment const payment = await wallet.sakshCreateRecurringPayment( 'user1', // userId 'user2', // toUserId 100, // amount 'USD', // currency 'Monthly subscription', // description 'REF123', // referenceNumber 'monthly' // interval ); console.log('Created Recurring Payment:', payment); // Update the recurring payment const updatedPayment = await wallet.sakshUpdateRecurringPayment(payment._id, { amount: 150 }); console.log('Updated Recurring Payment:', updatedPayment); // Delete the recurring payment await wallet.sakshDeleteRecurringPayment(payment._id); console.log('Deleted Recurring Payment:', payment._id); } catch (error) { console.error('Error:', error); } finally { // Close the MongoDB connection mongoose.connection.close(); } } main();