# Example Application The project includes a full-featured example application demonstrating all `subscriptions` package capabilities. The example app uses server-side rendered templates with **Tailwind CSS** and **Alpine.js**. ## Running the Example ```bash # Clone and setup git clone https://github.com/danangharissetiawan/django-subscription-midtrans.git cd django-subscription-midtrans python -m venv .venv && source .venv/bin/activate pip install -r requirements.txt # Configure cp .env.example .env # Edit .env with your Midtrans sandbox keys # Initialize python manage.py migrate python manage.py seed_plans python manage.py setup_periodic_tasks python manage.py createsuperuser # Run redis-server # Terminal 1 python manage.py runserver # Terminal 2 celery -A config worker -l info # Terminal 3 celery -A config beat -l info --scheduler django_celery_beat.schedulers:DatabaseScheduler # Terminal 4 ``` Visit `http://localhost:8000/example/` to see the application. ## Pages | URL | Template | Description | |-----|----------|-------------| | `/example/` | `landing.html` | Landing page with plan cards | | `/example/login/` | `login.html` | User login | | `/example/register/` | `register.html` | User registration | | `/example/dashboard/` | `dashboard.html` | User dashboard with subscription status | | `/example/subscribe//` | `subscribe.html` | Subscribe to a plan (payment method selection) | | `/example/subscription//` | `subscription_detail.html` | Subscription detail with management actions | | `/example/change-plan//` | `change_plan.html` | Change subscription plan | | `/example/payments/` | `payment_history.html` | Payment history list | | `/example/payments//` | `payment_detail.html` | Payment detail with VA/QR info | | `/example/invoices/` | `invoice_list.html` | Invoice list | | `/example/invoices//` | `invoice_detail.html` | Invoice detail | | `/example/wallet/` | `wallet.html` | Wallet balance and transactions | | `/example/topup/` | `topup.html` | Top-up wallet (amount + payment method) | | `/example/topup//payment/` | `topup_payment.html` | Top-up payment details | | `/example/notifications/` | `notification_list.html` | Notification list | | `/example/webhook-simulator/` | `webhook_simulator.html` | Test webhook notifications | | `/example/api-info/` | `api_info.html` | API documentation reference | ## Template Tags The example includes custom template tags for subscription checks: ```html {% load subscription_tags %} {% has_active_subscription user as has_sub %} {% if has_sub %}

You have an active subscription!

{% endif %} {% get_user_subscription user as subscription %} {% if subscription %}

Plan: {{ subscription.plan.name }}

{% endif %} ``` ## Example Views The example app views demonstrate both template-based and API-based workflows: - **Landing page** — Fetches plans from the API - **Subscribe** — Creates subscription via `SubscriptionService` - **Dashboard** — Shows active subscription, recent payments, wallet balance - **Wallet top-up** — Creates top-up via `WalletService` - **Webhook simulator** — Sends test payloads to the webhook endpoint ## Management Commands ### `seed_plans` Creates sample subscription plans: ```bash python manage.py seed_plans ``` Creates three plans: Basic (IDR 49,000/month), Professional (IDR 149,000/month), Enterprise (IDR 499,000/month) with feature sets. ### `setup_periodic_tasks` Registers all Celery periodic tasks in Django Celery Beat: ```bash python manage.py setup_periodic_tasks ```