Payment events: one central payment_result row for every path (callback, reconcile, Bazaar, renewal, 100% code), discount_applied, no duplicate order_created; Bazaar token never stored

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 14:44:50 +03:30
parent 8d8665edf3
commit 44ad2eabf3
4 changed files with 50 additions and 5 deletions

View File

@@ -177,7 +177,6 @@ class ZarinpalCallbackView(APIView):
)
new_status = 'paid' if result.is_valid else 'failed'
gateway_ref_id = result.ref_id
events.record('verify_result', order=order, valid=bool(result.is_valid), ref_id=gateway_ref_id)
with transaction.atomic():
locked_order = get_object_or_404(Order.objects.select_for_update(), pk=order.pk)
@@ -316,7 +315,6 @@ class BazaarVerifyPurchaseView(APIView):
# apply_order_payment_result سفارش را از نو می‌خواند و همان را عوض می‌کند؛ این نمونه هنوز
# وضعیتِ پیش از پرداخت را دارد. بدونِ این، پاسخ «pending» بود درحالی‌که سفارش «paid» شده بود.
order.refresh_from_db(fields=['status'])
events.record('bazaar_verify', order=order, valid=bool(result.is_valid), status=order.status)
data = {'orderId': str(order.id), 'status': order.status, 'valid': result.is_valid}
return Response(BazaarVerifyResponseSerializer(data).data)