Configuration
All settings are placed inside the MIDTRANS dictionary in your Django settings.py.
Full Reference
# settings.py
MIDTRANS = {
# ── Credentials (required) ──────────────────────────────────
"SERVER_KEY": "", # Midtrans Server Key
"CLIENT_KEY": "", # Midtrans Client Key (for frontend)
"MERCHANT_ID": "", # Midtrans Merchant ID
# ── Environment ─────────────────────────────────────────────
"IS_PRODUCTION": False, # True = production, False = sandbox
# ── Webhook ─────────────────────────────────────────────────
"NOTIFICATION_URL": "", # Public URL for Midtrans webhooks
# ── Payment Defaults ────────────────────────────────────────
"PAYMENT_EXPIRY_MINUTES": 1440, # 24 hours
"AUTO_CHECK_STATUS_INTERVAL": 300, # 5 minutes (Celery)
"DEFAULT_CURRENCY": "IDR",
# ── Payment Methods ─────────────────────────────────────────
"ENABLED_PAYMENT_METHODS": [
"credit_card",
"gopay",
"shopeepay",
"dana",
"qris",
"bank_transfer",
"echannel",
"cstore",
"akulaku",
"kredivo",
],
}
Settings Detail
Credentials
Setting |
Type |
Required |
Description |
|---|---|---|---|
|
|
Yes |
Your Midtrans Server Key. Used for all backend API calls. Found in Midtrans Dashboard → Settings → Access Keys. |
|
|
For CC |
Your Midtrans Client Key. Required for frontend credit card tokenization. |
|
|
Optional |
Your Midtrans Merchant ID. Used for some API calls. |
Environment
Setting |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Controls which Midtrans API server is used. |
Webhook
Setting |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
The public URL where Midtrans sends payment notifications. Must be accessible from the internet. For local development, use ngrok or cloudflared. |
Payment Defaults
Setting |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
How long before unpaid payments expire (in minutes). 1440 = 24 hours. |
|
|
|
Interval in seconds for the Celery task that checks pending payment statuses. |
|
|
|
Default currency for payments. |
Payment Methods
Setting |
Type |
Default |
Description |
|---|---|---|---|
|
|
All methods |
List of payment type strings to enable. If not set, all methods are available. |
Valid payment type strings:
Value |
Payment Method |
|---|---|
|
Credit/Debit Card (3DS) |
|
GoPay e-wallet |
|
ShopeePay e-wallet |
|
DANA e-wallet |
|
QRIS (universal QR) |
|
Virtual Account (BCA, BNI, BRI, Permata, CIMB) |
|
Mandiri Bill Payment |
|
Convenience Store (Indomaret, Alfamart) |
|
Akulaku PayLater |
|
Kredivo PayLater |
Environment Variables
We recommend using environment variables for sensitive credentials:
# .env
MIDTRANS_SERVER_KEY=SB-Mid-server-xxxxxxxxxxxxxxxxxxxx
MIDTRANS_CLIENT_KEY=SB-Mid-client-xxxxxxxxxxxx
MIDTRANS_MERCHANT_ID=G000000000
MIDTRANS_IS_PRODUCTION=False
MIDTRANS_NOTIFICATION_URL=https://your-domain.ngrok-free.app/api/midtrans/notification/
Then in settings.py:
import os
MIDTRANS = {
"SERVER_KEY": os.environ.get("MIDTRANS_SERVER_KEY", ""),
"CLIENT_KEY": os.environ.get("MIDTRANS_CLIENT_KEY", ""),
"MERCHANT_ID": os.environ.get("MIDTRANS_MERCHANT_ID", ""),
"IS_PRODUCTION": os.environ.get("MIDTRANS_IS_PRODUCTION", "False").lower() == "true",
"NOTIFICATION_URL": os.environ.get("MIDTRANS_NOTIFICATION_URL", ""),
}
Accessing Settings at Runtime
from django_midtrans import midtrans_settings
# Read any setting
server_key = midtrans_settings.SERVER_KEY
is_prod = midtrans_settings.IS_PRODUCTION
base_url = midtrans_settings.BASE_URL # Computed: sandbox or production URL
dashboard_url = midtrans_settings.DASHBOARD_URL # Computed: dashboard URL
API Base URLs
The BASE_URL is computed automatically from IS_PRODUCTION:
Environment |
API Base URL |
|---|---|
Sandbox |
|
Production |
|