.. _troubleshooting: =============================================================================== Troubleshooting Guide =============================================================================== Solutions to common issues when using dj-payfast. Quick Diagnosis =============== Use this flowchart to quickly identify your issue: .. code-block:: text Can't install dj-payfast? └─> See: Installation Issues Payment not creating? └─> See: Payment Creation Issues Can't reach PayFast? └─> See: Payment Processing Issues Webhook not firing? └─> See: Webhook Issues Signature errors? └─> See: Security/Signature Issues Database errors? └─> See: Database Issues Installation Issues =================== Issue: pip install fails ------------------------- **Symptoms**: .. code-block:: bash ERROR: Could not find a version that satisfies the requirement dj-payfast **Solutions**: 1. **Update pip**: .. code-block:: bash python -m pip install --upgrade pip 2. **Check Python version**: .. code-block:: bash python --version # Must be 3.8+ 3. **Use specific version**: .. code-block:: bash pip install dj-payfast==0.1.8 4. **Install from GitHub**: .. code-block:: bash pip install git+https://github.com/carrington-dev/dj-payfast.git Issue: Import error after installation --------------------------------------- **Symptoms**: .. code-block:: python ImportError: No module named 'payfast' **Solutions**: 1. **Verify installation**: .. code-block:: bash pip list | grep dj-payfast 2. **Check virtual environment**: .. code-block:: bash which python # Should be in your project's venv 3. **Add to INSTALLED_APPS**: .. code-block:: python # settings.py INSTALLED_APPS = [ # ... 'payfast', # Add this ] 4. **Run migrations**: .. code-block:: bash python manage.py migrate Payment Creation Issues ======================== Issue: Payment form not displaying ----------------------------------- **Symptoms**: Blank page or missing form **Solutions**: 1. **Check template exists**: .. code-block:: python # Verify template path 'payfast/checkout.html' 2. **Check context data**: .. code-block:: python def checkout_view(request): # Ensure you're passing these return render(request, 'payfast/checkout.html', { 'form': form, 'payment': payment, }) 3. **Debug template**: .. code-block:: django {# In template #} {{ form.errors }} {{ payment }} Issue: Missing required fields ------------------------------- **Symptoms**: .. code-block:: text IntegrityError: NOT NULL constraint failed **Solution**: Ensure all required fields are provided: .. code-block:: python # Required fields payment = PayFastPayment.objects.create( m_payment_id=str(uuid.uuid4()), # Required & unique amount=99.99, # Required item_name='Product Name', # Required email_address='user@example.com', # Required ) Issue: Duplicate payment_id error ---------------------------------- **Symptoms**: .. code-block:: text IntegrityError: UNIQUE constraint failed: payfast_payfastpayment.m_payment_id **Solutions**: 1. **Generate unique IDs**: .. code-block:: python import uuid m_payment_id = str(uuid.uuid4()) # Or timestamp-based: from django.utils import timezone m_payment_id = f"{user.id}_{int(timezone.now().timestamp())}" 2. **Check for existing payment**: .. code-block:: python if PayFastPayment.objects.filter(m_payment_id=payment_id).exists(): # Reuse existing payment payment = PayFastPayment.objects.get(m_payment_id=payment_id) else: # Create new payment payment = PayFastPayment.objects.create(...) Payment Processing Issues ========================== Issue: Can't reach PayFast --------------------------- **Symptoms**: Connection timeout or error **Solutions**: 1. **Check internet connection**: .. code-block:: bash ping sandbox.payfast.co.za 2. **Verify PAYFAST_TEST_MODE**: .. code-block:: python # settings.py PAYFAST_TEST_MODE = True # For sandbox # False for production 3. **Check firewall**: Ensure outbound HTTPS (port 443) is allowed Issue: Redirect not working ---------------------------- **Symptoms**: Form submits but nothing happens **Solutions**: 1. **Check form action URL**: .. code-block:: html