Menu
Libraries |
Category

user-credits-core

Purpose and Functionality

UserCredits 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. The library currently focuses on pre-paid workflows, with plans to introduce post-pay flows in future versions.

Key Features

  • Token Abstraction: Abstracts real-world currency into tokens for flexible pricing models.
  • Combined Offers: Create bundled offers with varying quotas, similar to mobile service packages.
  • Real-Time Credit Tracking: Monitor user token balances and consumption in real time.
  • Payment Integration: Seamlessly integrates with payment gateways like Stripe.
  • Flexible Offers and Subscriptions: Customize pricing, discounts, and durations using offer.overridingKey and weight options.
  • Offer Group Logic: Manage multiple subscriptions within related offer groups, with combined expiry dates for overlapping subscriptions.
  • Multi-Currency Support: Display orders and prices in multiple currencies for global audiences.

Architecture

UserCredits employs a modular, layered architecture:

  1. Declarative Interfaces: Core interfaces define project concepts and abstractions.
  2. Technology-Agnostic Logic: Implements logic for orders, offers, and payments without tying to specific technologies.
  3. Implementation Layer: Supports interchangeable database and payment platform integrations, currently using Mongoose with MongoDB and Stripe.

Inversion of Control (IoC) with Awilix manages dependencies, providing a unified facade interface that simplifies developer interactions.

Target Audience

Developers building back-end services or microservices requiring pay-as-you-go functionality, including subscription models, token-based payments, and credit management. The library is framework-agnostic and does not specifically mention Svelte support.

Core Interfaces

  • IService: Manages user credits, offers, and subscriptions, with methods for loading offers, creating orders, checking subscriptions, and consuming tokens.
  • IPaymentClient: Abstracts payment processing operations, including payment execution, balance checks, and webhook handling.

Getting Started

For detailed guidance on offers, orders, and payments, refer to the [explanation guides](fa-solid fa-up-right-from-square) and [blog series](fa-solid fa-up-right-from-square). A core package is available at [@user-

Comments