JCCIDC
AI Systems Architect · Automation Strategist
← BACK TO CASE STUDIES

Payment Automation Architecture

Python · Discord.py · PayPal API · n8n · SQLite · nginx · systemd · 2025

Overview

A production Discord bot (The Concierge) that automates the entire subscription lifecycle: PayPal payment processing, tiered access provisioning, Discord role management, and marketplace API synchronization. When a user subscribes via PayPal, their Discord roles update automatically, they gain access to the correct tier of products, and the marketplace API reflects the change — all without manual intervention.

Architecture

User subscribes via PayPal
        |
PayPal Webhook (BILLING.SUBSCRIPTION.ACTIVATED)
        |
n8n Webhook Server (port 8080)
        |
    +---+---+
    |       |
Discord   SQLite
Role      Record
Assignment Storage
    |       |
    +---+---+
        |
Marketplace API Sync
(script access, serial management)

Tier System

Tier Discord Role Access Level PayPal Plan
Elite Elite role Base scripts Monthly subscription
Legendary Legendary role + Advanced scripts Monthly subscription
Titan Titan role + Premium content Monthly subscription
Warlord Warlord role Full access Monthly subscription

Event Handling

The bot handles the full PayPal subscription lifecycle:

  • BILLING.SUBSCRIPTION.ACTIVATED — Assign tier role, grant script access, log to audit channel
  • BILLING.SUBSCRIPTION.CANCELLED — Revoke role, remove access, DM user with resubscribe info
  • PAYMENT.SALE.COMPLETED — Confirm recurring payment, update last-payment timestamp
  • BILLING.SUBSCRIPTION.PAYMENT.FAILED — DM reminder, flag account, log warning

Cross-Service Synchronization

The bot doesn't just manage Discord — it keeps three systems in sync:

  • Discord — Role assignment/revocation based on tier
  • SQLite — User records, subscription status, serial numbers, webhook history
  • Marketplace API — Script access control, serial registration, metadata sync

Slash Commands

  • /subscribe — Initiates PayPal subscription flow
  • /status — Shows current tier and subscription details
  • /scripts — Lists accessible scripts for current tier
  • /publisher info/set-bio/set-url/set-icon — Publisher profile management

Key Design Decisions

  • n8n as webhook router — PayPal webhooks hit n8n first, which validates and routes to the bot. This decouples payment processing from the Discord bot's lifecycle.
  • SQLite over PostgreSQL — Single-server deployment doesn't need a separate database service. SQLite with WAL mode handles concurrent reads fine.
  • Audit logging — Every role change, payment event, and access modification logs to a dedicated Discord channel. Full trail for support cases.

Infrastructure

  • VPS deployment with systemd service management
  • nginx reverse proxy for webhook endpoint (shop.jccidc.com)
  • Database backups on schedule
  • Health check endpoints
PythonDiscord.pyPayPal APIn8nSQLitenginxsystemd