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

# 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/<slug>/

subscribe.html

Subscribe to a plan (payment method selection)

/example/subscription/<id>/

subscription_detail.html

Subscription detail with management actions

/example/change-plan/<id>/

change_plan.html

Change subscription plan

/example/payments/

payment_history.html

Payment history list

/example/payments/<id>/

payment_detail.html

Payment detail with VA/QR info

/example/invoices/

invoice_list.html

Invoice list

/example/invoices/<id>/

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/<id>/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:

{% load subscription_tags %}

{% has_active_subscription user as has_sub %}
{% if has_sub %}
  <p>You have an active subscription!</p>
{% endif %}

{% get_user_subscription user as subscription %}
{% if subscription %}
  <p>Plan: {{ subscription.plan.name }}</p>
{% 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:

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:

python manage.py setup_periodic_tasks