admin: cancel a pending order, refund a paid one

There was no way to take an order back: staff could only edit the
status by hand, and turning 'paid' into 'failed' left the credits,
heart days or subscription days the order had given. Two OrderAdmin
actions now do it:
- cancel a pending order (a payment that does arrive later still counts);
- refund a paid order, after a confirmation page: takes back the pack's
  unspent credits (never below zero), its heart days, or the plan's
  subscription days, and undoes the referrer's commission.
The money itself is returned in the Zarinpal / Bazaar panel; the action
says so. Status is read-only in the order form. Steps in
docs/operations.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-02 22:37:30 +03:30
parent 4700ccbf91
commit d7d168e82f
10 changed files with 401 additions and 4 deletions

View File

@@ -6,7 +6,11 @@ class Order(models.Model):
تنها اپی که واقعاً پول جابه‌جا می‌کنه. عمداً از Subscription جدا شده
چون منطق و ریسکش فرق داره (درگاه، retry، idempotency).
"""
STATUS_CHOICES = [('pending', 'در انتظار'), ('paid', 'پرداخت‌شده'), ('failed', 'ناموفق')]
# «لغوشده» و «بازپرداخت‌شده» فقط از پنلِ ادمین (actionهای OrderAdmin) گذاشته می‌شوند، از ۲۰۲۶-۱۰-۰۲.
STATUS_CHOICES = [
('pending', 'در انتظار'), ('paid', 'پرداخت‌شده'), ('failed', 'ناموفق'),
('canceled', 'لغوشده'), ('refunded', 'بازپرداخت‌شده'),
]
# 'gateway' و 'bazaar' منطق و صحت‌سنجیِ کاملاً متفاوتی دارن (webhook در
# برابرِ verifyِ سرور-به-سرور با access_token)؛ برای همین provider جداست