from payments.models import MpesaCallback
from django.utils import timezone
from datetime import timedelta

# Check recent callbacks for 4086675
print("=" * 70)
print("Recent M-Pesa Callbacks for Shortcode 4086675")
print("=" * 70)

recent_callbacks = MpesaCallback.objects.filter(
    raw_data__BusinessShortCode='4086675'
).order_by('-created_at')[:10]

if recent_callbacks.exists():
    for callback in recent_callbacks:
        print(f"\nCallback ID: {callback.id}")
        print(f"Type: {callback.callback_type}")
        print(f"Created: {callback.created_at}")
        print(f"Shortcode: {callback.raw_data.get('BusinessShortCode')}")
        print(f"Amount: {callback.raw_data.get('TransAmount')}")
        print(f"TransID: {callback.raw_data.get('TransID')}")
        print("-" * 70)
else:
    print("\nNo callbacks found for shortcode 4086675")
    print("\nTo test which URL is registered:")
    print("1. Make a small test payment to paybill 4086675")
    print("2. Check /payments/callbacks/ to see which endpoint received it")
    print("3. Or contact Safaricom support to confirm the registered URLs")
