Skip to content

mchestr/plefi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PleFi

Integrate Stripe payments with Plex servers for subscription-based access!

license last-commit repo-top-language repo-language-count

_Built with:_

Go Stripe Plex Docker


πŸ”— Table of Contents

I. πŸ“ Overview II. πŸ‘Ύ Features III. πŸ“ Project Structure IV. πŸš€ Getting Started V. πŸ”§ Configuration VI. πŸ“‘ API Endpoints VII. πŸ”° Contributing VIII. πŸŽ— License


πŸ“ Overview

PleFi is a service that integrates Stripe payment processing with Plex media server, enabling subscription-based access management for Plex servers. It provides user authentication, payment handling, and subscription management to automate Plex server access control.


πŸ‘Ύ Features

Feature Summary
πŸ” Authentication
  • Plex user authentication using OAuth
  • Secure session management with encryption
πŸ’³ Payments
  • Stripe subscription management and payment processing
  • Configurable subscription plans
πŸ”„ Webhooks
  • Webhook support for Stripe events
  • Automated user access management based on subscription status
πŸ› οΈ Configuration
  • Hierarchical configuration system with environment variables
  • Development and production modes
πŸ”Œ API
  • RESTful endpoints for authentication and payment flows
  • Health check endpoints for monitoring

πŸ“ Project Structure

plefi
β”œβ”€β”€ internal/                # Backend application code
β”‚   β”œβ”€β”€ config/              # Configuration files and setup
β”‚   β”‚   β”œβ”€β”€ config.go
β”‚   β”‚   β”œβ”€β”€ default.yaml
β”‚   β”‚   └── development.yaml
β”‚   β”œβ”€β”€ controllers/         # Request handlers
β”‚   β”‚   β”œβ”€β”€ controller.go
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   └── controller.go
β”‚   β”‚   β”œβ”€β”€ plex/
β”‚   β”‚   β”‚   └── controller.go
β”‚   β”‚   └── stripe/
β”‚   β”‚       └── controller.go
β”‚   β”œβ”€β”€ model/               # Data models
β”‚   β”‚   └── user_info.go
β”‚   β”œβ”€β”€ services/            # Service implementations
β”‚   β”‚   β”œβ”€β”€ services.go
β”‚   β”‚   └── plex.go
β”‚   β”œβ”€β”€ views/               # HTML templates
β”‚   β”‚   β”œβ”€β”€ index.tmpl
β”‚   β”‚   β”œβ”€β”€ stripe_success.tmpl
β”‚   β”‚   └── stripe_cancel.tmpl
β”‚   β”œβ”€β”€ router.go            # Route definitions
β”‚   └── main.go              # Application entry point
β”œβ”€β”€ go.mod                   # Go module definition
β”œβ”€β”€ go.sum                   # Go dependency checksums
β”œβ”€β”€ Dockerfile               # Container definition
β”œβ”€β”€ .env                     # Environment variables (not in git)
β”œβ”€β”€ .gitignore               # Git ignore rules
β”œβ”€β”€ frontend/                # React frontend application
β”‚   β”œβ”€β”€ public/              # Static assets & index.html
β”‚   β”œβ”€β”€ src/                 # React source code (pages, components, styles)
β”‚   β”œβ”€β”€ webpack.config.js    # Frontend build configuration
β”‚   β”œβ”€β”€ package.json         # Frontend dependencies & scripts
β”‚   └── ...                  # other frontend files
└── README.md                # Project documentation

πŸ“‚ Project Index

PleFi/
__root__
server.go Server initialization with graceful shutdown
Dockerfile Container definition for building and running the PleFi application
go.mod Go module definition specifying dependencies
go.sum Go dependency checksums ensuring consistent builds
api/
config/
config.go Configuration initialization and management from files and environment variables
default.yaml Default configuration values for all environments
development.yaml Development-specific configuration settings
controllers/
controller.go Main application controller handling common functionality
api/
controller.go API controller implementation for general endpoints
plex/
controller.go Plex controller handling OAuth authentication
stripe/
controller.go Stripe controller for payment processing and webhooks
services/
services.go Service container for dependency injection
plex.go Plex service for interacting with Plex API
views/
index.tmpl Main landing page template
stripe_success.tmpl Subscription success page
stripe_cancel.tmpl Subscription cancellation page
model/
user_info.go User information model
router.go
router.go Route definitions
main.go
main.go Application entry point that initializes configuration, services, and the HTTP server
frontend/
public/ Static assets & index.html
src/ React source code (pages, components, styles)
webpack.config.js Frontend build configuration
package.json Frontend dependencies & scripts

πŸš€ Getting Started

β˜‘οΈ Prerequisites

Before getting started with PleFi, ensure your runtime environment meets the following requirements:

  • Go 1.24 or higher
  • Node.js 16+
  • npm or Yarn
  • Stripe account with webhook setup
  • Plex account and server (optional for development)

βš™οΈ Installation

  1. Clone the repository:

    ❯ git clone https://github.com/mchestr/plefi.git
    ❯ cd plefi
  2. Install backend dependencies:

    ❯ go mod download
  3. Create a .env file in the project root with your configuration:

    ❯ cat > .env << EOL
    PLEFI_STRIPE__SECRET_KEY="sk_test_your_stripe_secret_key"
    PLEFI_STRIPE__WEBHOOK_SECRET="whsec_your_stripe_webhook_secret"
    PLEFI_STRIPE__DEFAULT_PRICE_ID="price_your_default_price_id"
    
    PLEFI_PLEX__CLIENT_ID="your_plex_client_id"
    PLEFI_PLEX__PRODUCT="Your Plex Server Name"
    
    PLEFI_SERVER__HOSTNAME="your-server-hostname.com"
    PLEFI_SERVER__SESSION_SECRET="generate_a_random_secret_key"
    PLEFI_SERVER__MODE="development"
    EOL
  4. Install frontend dependencies:

    ❯ cd frontend
    ❯ npm install
  5. Return to the root:

    ❯ cd ..

πŸ€– Usage

Run frontend in development mode:

❯ cd frontend
❯ npm run start

Run backend locally:

❯ go run api/main.go

Run backend in development mode:

❯ go run api/main.go -e development

Using Docker:

❯ docker build -t plefi .
❯ docker run -p 8080:8080 --env-file .env plefi

πŸ”§ Configuration

PleFi uses a hierarchical configuration system:

  1. Default values
  2. Configuration files in api/config/ directory
  3. Environment variables (prefixed with PLEFI_)

Environment Variables Reference

Server Configuration
  • PLEFI_SERVER__MODE - Server mode (debug, release)
  • PLEFI_SERVER__ADDRESS - Server bind address (default: :8080)
  • PLEFI_SERVER__HOSTNAME - Server hostname for callbacks
  • PLEFI_SERVER__SESSION_SECRET - Secret for session encryption
  • PLEFI_SERVER__TRUSTED_PROXIES - Comma-separated list of trusted proxy IPs
Stripe Configuration
  • PLEFI_STRIPE__SECRET_KEY - Stripe API secret key
  • PLEFI_STRIPE__WEBHOOK_SECRET - Stripe webhook signing secret
  • PLEFI_STRIPE__DEFAULT_PRICE_ID - Default subscription price ID
Plex Configuration
  • PLEFI_PLEX__CLIENT_ID - Plex client identifier
  • PLEFI_PLEX__PRODUCT - Plex product name
Logging Configuration
  • PLEFI_LOG__LEVEL - Logging level (debug, info, warn, error)
  • PLEFI_LOG__FORMAT - Logging format (json, text)

πŸ“‘ API Endpoints

Application
  • GET / - Landing page
  • GET /health - Health check endpoint
Plex Authentication
  • GET /plex/auth - Initiate Plex authentication
  • GET /plex/callback - Plex authentication callback
Stripe
  • POST /stripe/webhook - Stripe webhook endpoint for subscription events
  • GET /stripe/checkout - Create a Stripe checkout session for subscription
  • GET /stripe/success - Handle successful subscription checkout
  • GET /stripe/cancel - Handle cancelled subscription checkout

πŸ”° Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request
Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your GitHub account.
  2. Clone Locally: Clone the forked repository to your local machine.
    git clone https://github.com/yourusername/plefi.git
  3. Create a New Branch: Always work on a new branch.
    git checkout -b feature/amazing-feature
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message.
    git commit -m 'Add amazing feature'
  6. Push to GitHub: Push the changes to your forked repository.
    git push origin feature/amazing-feature
  7. Submit a Pull Request: Create a PR against the original project repository.

πŸŽ— License

See the LICENSE file for details.


About

Plex Subscriptions Management

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages