Hey folks, I’m stuck with a weird issue on my React and Django site hosted on Render. When I try to start a PayPal payment, I’m getting a 404 error. I’ve double-checked everything:
- Django URL mapping looks good
- No syntax errors in React
- Sending the right data to the backend
- Forward slash is there
- Using PayPal Sandbox mode
- Client ID and Secret are in Render’s environment variables
- No CORS issues
- Frontend URL is in allowed origins
- REACT_BASE_URL is correct in settings.py and views.py
I’m pretty sure the 404 happens right when I hit the ‘Pay with PayPal’ button. It’s like something’s blocking the request.
Here’s a simplified version of my backend code:
@api_view(['POST'])
def start_payment(request):
if request.method == 'POST' and request.user.is_authenticated:
cart_id = request.data.get('cart_id')
if not cart_id:
return Response({'error': 'No cart ID'}, status=400)
try:
cart = Cart.objects.get(cart_id=cart_id)
except Cart.DoesNotExist:
return Response({'error': 'Cart not found'}, status=404)
# Calculate total with tax
total = calculate_total(cart)
# Set up PayPal payment
payment = set_up_paypal_payment(total, cart)
if payment.create():
return Response({'paymentUrl': get_approval_url(payment)}, status=201)
return Response({'error': payment.error}, status=400)
Any ideas what could be causing this? I’m totally stumped!