user-credits
@user-credits is an open-source library designed to simplify the implementation of pay-as-you-go features in back-end services or microservices. It provides a flexible, technology-agnostic solution for managing user credits and token-based payments, suitable for subscription-based services, digital marketplaces, and e-commerce platforms.
Purpose: The library abstracts real-world currency into tokens, enabling flexible pricing models and supporting pre-paid workflows (with post-pay features planned for version 2). It integrates with payment gateways like Stripe and offers tools for managing offers, orders, subscriptions, and credit tracking.
Key Features:
- Token Abstraction: Tokens abstract currency for flexible pricing.
- Combined Offers: Create bundled offers with varying quotas.
- Real-Time Credit Tracking: Monitor user token balances and consumption.
- Payment Integration: Seamlessly integrates with payment gateways (e.g., Stripe).
- Flexible Offers and Subscriptions: Customize pricing, discounts, and durations.
- Offer Group Logic: Manage multiple subscriptions with shared expiry logic.
- Multi-Currency Support: Display orders and prices in multiple currencies.
Architecture:
- Declarative Interfaces: Define core concepts and abstractions.
- Technology-Agnostic Logic: Implements order creation, offer management, and payment operations.
- Implementation Layer: Supports database abstraction (e.g., Mongoose with MongoDB) and payment platform integration, managed via Inversion of Control (IoC) with Awilix.
Target Audience: Developers building pay-as-you-go systems, subscription services, or token-based payment solutions in back-end environments. The library is framework-agnostic and does not have specific Svelte support mentioned.
Usage: Core interfaces include IService for user credit management (e.g., loading offers, creating orders, checking subscriptions) and IPaymentClient for payment processing (e.g., executing payments, handling webhooks). A getting started guide is available on Medium and dev.to <i class="fa-solid fa-up-right