Constants
The django_midtrans.constants module defines all enumeration constants used throughout the package. Each class contains string constants and a CHOICES list compatible with Django model field choices.
PaymentType
Payment method identifiers sent to Midtrans.
Constant |
Value |
Label |
|---|---|---|
|
|
Credit Card |
|
|
GoPay |
|
|
ShopeePay |
|
|
QRIS |
|
|
OVO |
|
|
DANA |
|
|
Bank Transfer |
|
|
Mandiri Bill |
|
|
Convenience Store |
|
|
Akulaku |
|
|
Kredivo |
from django_midtrans.constants import PaymentType
payment_type = PaymentType.BANK_TRANSFER # "bank_transfer"
BankType
Bank identifiers for Virtual Account (bank transfer) payments.
Constant |
Value |
Label |
|---|---|---|
|
|
BCA |
|
|
BNI |
|
|
BRI |
|
|
Permata |
|
|
CIMB |
from django_midtrans.constants import BankType
bank = BankType.BCA # "bca"
TransactionStatus
Midtrans transaction lifecycle statuses.
Constant |
Value |
Label |
Description |
|---|---|---|---|
|
|
Pending |
Waiting for customer payment. |
|
|
Capture |
Credit card captured (success for CC). |
|
|
Settlement |
Payment settled (final success). |
|
|
Deny |
Payment denied by bank or fraud check. |
|
|
Cancel |
Payment cancelled. |
|
|
Expire |
Payment expired (customer didn’t pay in time). |
|
|
Refund |
Full refund issued. |
|
|
Partial Refund |
Partial refund issued. |
|
|
Authorize |
Credit card authorized (pre-auth). |
|
|
Failure |
Transaction failed. |
Status Groups
TransactionStatus.SUCCESS_STATUSES # ["capture", "settlement"]
TransactionStatus.FAILED_STATUSES # ["deny", "cancel", "expire", "failure"]
TransactionStatus.FINAL_STATUSES # ["settlement", "deny", "cancel", "expire", "refund", "failure"]
FraudStatus
Midtrans fraud detection result.
Constant |
Value |
Label |
Description |
|---|---|---|---|
|
|
Accept |
Transaction accepted. |
|
|
Challenge |
Flagged for manual review. |
|
|
Deny |
Denied by fraud detection. |
InvoiceStatus
Invoice lifecycle statuses.
Constant |
Value |
Label |
|---|---|---|
|
|
Draft |
|
|
Sent |
|
|
Paid |
|
|
Overdue |
|
|
Void |
|
|
Partial |
SubscriptionStatus
Subscription lifecycle statuses.
Constant |
Value |
Label |
|---|---|---|
|
|
Active |
|
|
Inactive |
|
|
Disabled |
|
|
Cancelled |
NotificationStatus
Internal processing status for webhook notifications.
Constant |
Value |
Label |
Description |
|---|---|---|---|
|
|
Received |
Notification received but not yet processed. |
|
|
Processed |
Successfully processed and payment updated. |
|
|
Failed |
Processing failed (see error_message). |
|
|
Duplicate |
Duplicate notification (already processed). |
|
|
Invalid Signature |
Signature verification failed. |
Usage with Django Models
All constants include a CHOICES list for use with Django model choices parameter:
from django.db import models
from django_midtrans.constants import PaymentType, TransactionStatus
class Order(models.Model):
payment_type = models.CharField(
max_length=30,
choices=PaymentType.CHOICES,
)
status = models.CharField(
max_length=30,
choices=TransactionStatus.CHOICES,
default=TransactionStatus.PENDING,
)