- payment/providers.py: ZarinpalProvider / BazaarProvider with one interface (check_plan, sku_for, payment_url, purchase_extras, discount_blocker, reconcile_user); provider_for / provider_for_method pick one; unknown fails. create_order, purchase view, discount redeem and reconcile_user_orders use it instead of scattered ifs. - subscription.0015: Bazaar SKU 10342 on the one-month plan (owner: "probably the monthly one"). - config/health: the Bazaar check no longer swallows its exception without a log. 982 tests green. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.6 KiB
Python
33 lines
1.6 KiB
Python
"""
|
||
`10342` → اشتراکِ یکماهه (۲۰۲۶-۱۰-۱۲، به گفتهی مالک «احتمالاً همان یکماهه»؛ پیشخان را خودمان ندیدهایم).
|
||
بازار آن را زیرِ com.tadrisino.math.app میشناسد؛ نوعش (اشتراکی یا تکخرید) را API بدونِ خریدِ واقعی نمیگوید.
|
||
اگر اشتباه بود: «Bazaar sku» همان پلن را در ادمین خالی کنید. همان قاعدهی 0014: دقیقاً یک پلنِ فروشیِ ۳۰ روزه.
|
||
"""
|
||
from django.core.cache import cache
|
||
from django.db import migrations
|
||
|
||
SKU = '10342'
|
||
|
||
|
||
def forward(apps, schema_editor):
|
||
Plan = apps.get_model('subscription', 'Plan')
|
||
if Plan.objects.filter(bazaar_sku=SKU).exists():
|
||
return
|
||
plans = list(Plan.objects.filter(kind='subscription', on_sale=True, duration_days=30))
|
||
if len(plans) != 1:
|
||
raise RuntimeError(f'SKUِ بازار {SKU}: باید دقیقاً یک اشتراکِ فروشیِ ۳۰ روزه باشد، {len(plans)} تا پیدا شد.')
|
||
if not plans[0].bazaar_sku:
|
||
plans[0].bazaar_sku = SKU
|
||
plans[0].save(update_fields=['bazaar_sku'])
|
||
cache.delete('subscription:plans:v3') # مثلِ 0014: سیگنالِ post_save در migration نمیآید
|
||
|
||
|
||
def backward(apps, schema_editor):
|
||
apps.get_model('subscription', 'Plan').objects.filter(bazaar_sku=SKU).update(bazaar_sku='')
|
||
cache.delete('subscription:plans:v3')
|
||
|
||
|
||
class Migration(migrations.Migration):
|
||
dependencies = [('subscription', '0014_bazaar_skus_2026_10')]
|
||
operations = [migrations.RunPython(forward, backward)]
|