opspay
v1.0.0
Published
Advanced monetization and marketing system
Maintainers
Readme
OpsPay
OpsPay is an advanced, professional, and secure monetization and marketing system for Node.js applications. It is designed to be easily integrated into Discord bots, Telegram bots, WhatsApp bots, and web applications.
Features
- Credit System: Manage user balances with atomic transactions.
- Payment Adapters: Built-in support for Stripe and PayPal.
- Bot Integration: Middleware to easily generate payment links and gate commands.
- Security: Strict input validation using Zod.
- TypeScript: Fully typed for professional development.
Installation
npm install opspayUsage
1. Initialize the System
import { CreditManager, TransactionLedger, StripeAdapter, BotMiddleware } from 'opspay';
// Initialize Core
const ledger = new TransactionLedger();
const creditManager = new CreditManager(ledger);
// Initialize Payment Adapter
const stripeAdapter = new StripeAdapter('sk_test_...');
// Initialize Bot Middleware
const botMiddleware = new BotMiddleware(creditManager, stripeAdapter);2. Manage Credits
// Add credits
creditManager.addCredits('user-123', 1000, 'Bonus credits');
// Deduct credits
try {
creditManager.deductCredits('user-123', 500, 'Premium Feature');
console.log('Feature activated!');
} catch (error) {
console.error('Insufficient funds');
}3. Accept Payments
// Generate a payment link for a user
const link = await botMiddleware.generatePaymentLink(
'user-123',
1000, // Amount in cents ($10.00)
'usd',
'1000 Credits Pack'
);
console.log(link);4. Gate Commands
// Execute a command only if the user pays/has credits
try {
await botMiddleware.enforcePayment('user-123', 100, async () => {
// Your command logic here
console.log('Command executed!');
});
} catch (e) {
console.log('Please recharge your account.');
}Security
OpsPay uses zod for runtime validation of all transaction and payment requests to ensure data integrity.
License
MIT
